Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GStreamer pipeline hangs on gst_element_get_state

Tags:

c++

c

gstreamer

I have following very basic code using GStreamer library (GStreamer v1.8.1 on Xubuntu 16.04 if it important)

#include <gst/gst.h>

int main(int argc, char *argv[])
{
    gst_init(&argc, &argv);

    const gchar* pd =
        "filesrc location=some.mp4 ! qtdemux name=d "
        "d.video_0 ! fakesink "
        "d.audio_0 ! fakesink ";

    GError* error = nullptr;
    GstElement *pipeline = gst_parse_launch(pd, &error);

    GstState state; GstState pending;
    switch(gst_element_set_state(pipeline, GST_STATE_PAUSED)) {
        case GST_STATE_CHANGE_FAILURE:
        case GST_STATE_CHANGE_NO_PREROLL:
            return -1;
        case GST_STATE_CHANGE_ASYNC: {
            gst_element_get_state(pipeline, &state, &pending, GST_CLOCK_TIME_NONE);
        }
        case GST_STATE_CHANGE_SUCCESS:
            break;
    }

    GMainLoop* loop = g_main_loop_new(nullptr, false);
    g_main_loop_run(loop);

    gst_object_unref(pipeline);

    return 0;
}

The problem is when I try run this code it hangs on

gst_element_get_state(pipeline, &state, &pending, GST_CLOCK_TIME_NONE);

The question is - why it hangs? Especially if take into account, if I remove d.audio_0 ! fakesink from pipeline description it doesn't hang.

like image 451
RSATom Avatar asked Oct 26 '25 01:10

RSATom


2 Answers

It is good practice to always add queues (or a multiqueue) after elements that produces multiple output branches in the pipeline e.g. demuxers.

The reason is that sinks will block waiting for other sinks to receive the first buffer (preroll). With a single thread, as your code, it will block the only thread available to push data into the sinks. A single thread is going from the demuxers to both sinks, once 1 blocks the there is no way for data to arrive on the second sink.

Using queues will spawn new threads and each sink will have a dedicated one.

like image 114
thiagoss Avatar answered Oct 27 '25 14:10

thiagoss


That's quite an old thread but it probably hangs because you have an infinite timeout (GST_CLOCK_TIME_NONE).

like image 37
Gaël Porté Avatar answered Oct 27 '25 16:10

Gaël Porté



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!