GStreamer:如何连接动态垫

use*_*326 6 callback gstreamer

我正在尝试使用GStreamer从文件中播放MP4视频.我已设法使用playbin2播放该文件,并使用以下命令提示符:

gst-launch filesrc location=bbb.mp4 ! decodebin2 ! autovideosink
Run Code Online (Sandbox Code Playgroud)

我期待将来我需要创建更复杂的管道,以及为什么我试图"编程"管道.在我的程序中,我试图复制上面的管道,但是我有一个问题,我怀疑与将decodebin2的动态或"有时"源板连接到autovideo接收器有关.我使用这些元素只是为了让事情尽可能简单.

static void on_new_decoded_pad(GstElement* object,
                           GstPad* arg0,
                           gboolean arg1,
                           gpointer user_data)
{
    // dynamically connect decoderbin2 src pad to autovideosink sink pad
}

static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
    // handle bus messages
}

int main(int argc, char *argv[])
{
    GMainLoop *loop;
    GstElement *pipeline, *source, *decodebin, *videosink;
    GstBus *bus;

    gst_init (&argc, &argv);
    loop = g_main_loop_new (NULL, FALSE);

    pipeline  = gst_pipeline_new ("pipeline");
    source    = gst_element_factory_make("filesrc",       "source");
    decodebin = gst_element_factory_make("decodebin2",    "decodebin");
    videosink = gst_element_factory_make("autovideosink", "videosink");

    /* check elements were created successfully */
    if (!pipeline || !source || !decodebin || !videosink) {
        // Failed to create element. Exit Program
        return -1;
    }

    /* apply properties to elements before adding to pipeline */
    gchar * filename = "bbb.mp4";
    g_object_set(G_OBJECT(source), "location", filename, NULL);

    /* add a message handler */
    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    gst_bus_add_watch (bus, bus_call, loop);
    gst_object_unref (bus);

    /* add elements to pipeline (and bin if necessary) before linking them */
    gst_bin_add_many(GST_BIN (pipeline),
                     source,
                     decodebin,
                     videosink,
                     NULL);

    gst_element_link_pads(source, "src", decodebin, "sink");

    /* decodebins src pad is a sometimes pad - it gets created dynamically */
    g_signal_connect(decodebin, "new-decoded-pad", G_CALLBACK(on_new_decoded_pad),   videosink);

    /* run pipeline */
    gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);

    g_main_loop_run(loop);

    gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL);
    gst_object_unref (pipeline);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我运行这个程序时,我期望发生的是通过回调函数调用on_new_decoded_pa​​d,该函数在行中设置:

g_signal_connect(decodebin, "new-decoded-pad", G_CALLBACK(on_new_decoded_pad), videosink);
Run Code Online (Sandbox Code Playgroud)

并允许我适当地连接垫.但它永远不会被称为.实际上程序似乎完全通过然后退出(主循环什么都不做).

如果有人可以指出我在回调方面做错了什么,或者解释还有什么需要做,以便本例使用提供的元素播放mp4,我真的很感激.

问候.

use*_*326 6

on_new_decoded_pa​​d是折旧使用"pad-added"而不是.

我还有一个与decodebin2相关的问题,你可以在这里找到:GStreamer force decodebin2输出类型