简体   繁体   English

"GStreamer 管道在 gst_element_get_state 上挂起"

[英]GStreamer pipeline hangs on gst_element_get_state

I have following very basic code using GStreamer library (GStreamer v1.8.1 on Xubuntu 16.04 if it important)我使用 GStreamer 库遵循非常基本的代码(如果重要的话,Xubuntu 16.04 上的 GStreamer v1.8.1)

#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;
}

It is good practice to always add queues (or a multiqueue) after elements that produces multiple output branches in the pipeline eg 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. 单个线程从解复用器进入两个接收器,一旦1个阻塞,数据无法到达第二个接收器。

Using queues will spawn new threads and each sink will have a dedicated one. 使用队列将产生新线程,每个接收器将具有专用线程。

这是一个相当古老的线程,但它可能会挂起,因为您有无限超时(GST_CLOCK_TIME_NONE)。

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM