GStreamer:如何连接动态焊盘 [英] GStreamer: how to connect dynamic pads

查看:313
本文介绍了GStreamer:如何连接动态焊盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用GStreamer从一个文件播放MP4视频。我已经设法使用播放文件使用playbin2和从命令提示符使用:

  gst-launch filesrc location = bbb.mp4!解码bin2! autovideosink 

我期望未来我需要创建更复杂的管道,试图编程管道。在我的程序中,我试图复制上面的管道,但我有一个问题,我怀疑是关于连接decodebin2的动态或有时源pad到自动视频接收器。我使用这些元素只是为了让事情尽可能简单。

  static void on_new_decoded_pa​​d(GstElement * object,
GstPad * arg0,
gboolean arg1,
gpointer user_data)
{
//动态连接decoderbin2 src pad到autovideosink sink pad
}

static gboolean bus_call(GstBus * bus,GstMessage * msg,gpointer data)
{
//处理总线消息
}

int main(int argc,char * argv [])
{
GMainLop * 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元素已成功创建* /
if(!pipeline ||!source ||!decodebin ||!videosink){
//无法创建元素。退出程序
return -1;
}

/ *在添加到管道之前向元素应用属性* /
gchar * filename =bbb.mp4;
g_object_set(G_OBJECT(source),location,filename,NULL);

/ *添加消息处理程序* /
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
gst_bus_add_watch(bus,bus_call,loop);
gst_object_unref(bus);

/ *在链接之前向管道中添加元素(如果有必要,还有bin)* /
gst_bin_add_many(GST_BIN(pipeline),
source,
decodebin,
videosink,
NULL);

gst_element_link_pads(源,src,decodebin,sink);

/ * decodebins src pad是一个有时候的pad - 它被动态创建* /
g_signal_connect(decodebin,new-decoded-pad,G_CALLBACK(on_new_decoded_pa​​d),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;
}

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

  g_signal_connect(decodebin,new-decoded-pad ,G_CALLBACK(on_new_decoded_pa​​d),videosink); 

,并允许我适当地连接这些焊盘。但它从来没有被调用。事实上,程序似乎完全通过,然后就退出了(主循环什么都不做)。



我真的很感激,如果有人可以指出我的'关于回调或者解释什么需要做什么,为了这个例子使用提供的元素播放mp4。



回答。

on_new_decoded_pa​​d是贬值使用pad-added。



与decodebin2有关的问题,您可以在这里找到: GStreamer force decodebin2输出类型


I'm trying to use GStreamer to play MP4 video from a file. I have managed to play the file using playbin2 and from the command prompt using:

gst-launch filesrc location=bbb.mp4 ! decodebin2 ! autovideosink

I am expecting in the future that I will need to create more complicated pipelines and hence why I'm attempting to 'program' the pipeline. In my program I am attempting to replicate the pipeline above, however I have an issue which I suspect is related to connecting the dynamic or "sometimes" source pad of decodebin2 to the autovideo sink. I am using these elements only to keep things as simple as possible.

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

What I expect to happen when I run this program, is for the on_new_decoded_pad to get called via a call back function, which is set in the line:

g_signal_connect(decodebin, "new-decoded-pad", G_CALLBACK(on_new_decoded_pad), videosink);

and would allow me to connect the pads appropriately. But it never gets called. In fact the program seems to pass through entirely and then just exit (the main loop does nothing).

I'd really appreciate it if someone could point out what I've done wrong with regards to the callback or explain what else needs to be done in order for this example to play mp4 using the provided elements.

Regards.

解决方案

on_new_decoded_pad is depreciated use "pad-added" instead.

I still have an issue relating to decodebin2 which you can find here: GStreamer force decodebin2 output type

这篇关于GStreamer:如何连接动态焊盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆