Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pipeline to increase gstreamer performance #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,36 @@ struct gst_st2110_20_receiver_impl : gst_receiver_plugin_t
auto* source = gst_element_factory_make("udpsrc", NULL);
BST_ENFORCE(source != nullptr, "Failed creating GStreamer element udpsrc");
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), source), "Failed adding udpsrc to the pipeline");

// Set udp source params
g_object_set(G_OBJECT(source), "address", s_.primary.source_ip_address.c_str(), NULL);
g_object_set(G_OBJECT(source), "auto-multicast", TRUE, NULL);
g_object_set(G_OBJECT(source), "port", s_.primary.source_port, NULL);
g_object_set(G_OBJECT(source), "multicast-iface", s_.primary.interface_name.c_str(), NULL);

// Create and set caps for udp source
GstCaps* caps = gst_caps_from_string(
"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, "
"sampling=(string)RGB, width=(string)640, height=(string)480");
g_object_set(G_OBJECT(source), "caps", caps, NULL);

// Add pipeline rtpjitterbuffer
auto* jitter_buffer = gst_element_factory_make("rtpjitterbuffer", NULL);
BST_ENFORCE(jitter_buffer != nullptr, "Failed creating GStreamer element jitter_buffer");
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), jitter_buffer), "Failed adding jitter_buffer to the pipeline");

// Add pipeline queue1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to remove the jitter buffer.

auto* queue1 = gst_element_factory_make("queue", NULL);
BST_ENFORCE(queue1 != nullptr, "Failed creating GStreamer element queue");
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), queue1), "Failed adding queue to the pipeline");
g_object_set(queue1, "max-size-buffers", 3, NULL);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queue1 handles RTP buffers, while queue2 handles full frames. Each frame may have several thousands of packets, so I don't think it is a good idea to use the same value (3) for both.
Probably the best solution is to work based on time, for example, you could set both to 200 ms.
Also, make sure you set max-size-time, max-size-buffers and max-size-bytes. They all have defaults and we probably don't want to rely on them. If we go with my suggestion (using max-size-time), then we should set both max-size-buffers and max-size-bytes to 0, in order to disable those checks and rely only on time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode constants in a function call (3 in this case). Always define constexpr values with meaningful names and explain why you chose that value.


// Add pipeline rtp depay
auto* depay = gst_element_factory_make("rtpvrawdepay", NULL);
BST_ENFORCE(depay != nullptr, "Failed creating GStreamer element depay");
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), depay), "Failed adding depay to the pipeline");

// Add pipeline queue2
auto* queue2 = gst_element_factory_make("queue", NULL);
BST_ENFORCE(queue2 != nullptr, "Failed creating GStreamer element queue");
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), queue2), "Failed adding queue to the pipeline");
g_object_set(queue2, "max-size-buffers", 3, NULL);

// Add pipeline videoconvert
auto* videoconvert = gst_element_factory_make("videoconvert", NULL);
BST_ENFORCE(videoconvert != nullptr, "Failed creating GStreamer element converter");
Expand All @@ -77,8 +81,8 @@ struct gst_st2110_20_receiver_impl : gst_receiver_plugin_t
BST_ENFORCE(sink != nullptr, "Failed creating GStreamer element sink");
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), sink), "Failed adding sink to the pipeline");

// Link elements
BST_ENFORCE(gst_element_link_many(source, jitter_buffer, queue1, depay, videoconvert, sink, NULL),
// Link all elements together
BST_ENFORCE(gst_element_link_many(source, queue1, depay, queue2, videoconvert, sink, NULL),
"Failed linking GStreamer video pipeline");

// Setup runner
Expand All @@ -103,4 +107,4 @@ expected<gst_receiver_plugin_uptr> ossrf::gst::plugins::create_gst_st2110_20_plu
BST_CHECK(i->create_gstreamer_pipeline());

return i;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,14 @@ struct gst_st2110_20_sender_impl : gst_sender_plugin_t
// Add pipeline queue1
auto* queue1 = gst_element_factory_make("queue", NULL);
BST_ENFORCE(queue1 != nullptr, "Failed creating GStreamer element queue");
g_object_set(G_OBJECT(queue1), "max-size-buffers", 3, NULL);
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), queue1), "Failed adding queue to the pipeline");

// Add pipeline rtpvrawpay
auto* rtpvrawpay = gst_element_factory_make("rtpvrawpay", NULL);
BST_ENFORCE(rtpvrawpay != nullptr, "Failed creating GStreamer element rtpvrawpay");
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), rtpvrawpay), "Failed adding rtpvrawpay to the pipeline");

// Add pipeline queue2
auto* queue2 = gst_element_factory_make("queue", NULL);
BST_ENFORCE(queue2 != nullptr, "Failed creating GStreamer element queue");
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), queue2), "Failed adding queue to the pipeline");

// Add pipeline udpsink
auto* udpsink = gst_element_factory_make("udpsink", NULL);
BST_ENFORCE(udpsink != nullptr, "Failed creating GStreamer element udpsink");
Expand All @@ -81,7 +77,7 @@ struct gst_st2110_20_sender_impl : gst_sender_plugin_t
BST_ENFORCE(gst_bin_add(GST_BIN(pipeline), udpsink), "Failed adding udpsink to the pipeline");

// Link elements
BST_ENFORCE(gst_element_link_many(source, capsfilter, queue1, rtpvrawpay, queue2, udpsink, NULL),
BST_ENFORCE(gst_element_link_many(source, capsfilter, queue1, rtpvrawpay, udpsink, NULL),
"Failed linking GStreamer video pipeline");

// Setup runner
Expand All @@ -105,4 +101,4 @@ ossrf::gst::plugins::create_gst_st2110_20_plugin(sender_settings settings, video
BST_CHECK(i->create_gstreamer_pipeline(pattern));

return i;
}
}