在gstreamer中动态添加和删除tee队列 [英] In gstreamer adding and removing queue of a tee dynamically

查看:1278
本文介绍了在gstreamer中动态添加和删除tee队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了gstreamer代码,用于同时进行摄像机实时流传输和录制.

I have written gstreamer code for camera live-streaming and recording at the same time.

我的管道如下所示:

                 /  [ queue1 | videosink ]           
v4l2src | tee         
                 \  [ queue2 | filesink ]        

当前,实时流式传输和文件记录正在一起工作.

Currently both live streaming and file recording is working together.

现在,我只需要使用一个队列(即queue1(实时流式队列))启动管道,过一会儿,我还需要添加记录队列并动态删除它.

Now I need to start the pipeline with only one queue i.e. queue1 (live streaming queue), After a while I need to add the recording queue and remove it dynamically too.

我的工作代码如下:

    pipeline = gst_pipeline_new ("rv_camera");

    /*Create source element. We use mfw_v4lsrc from Freescale as source */

    source= gst_element_factory_make (GSTREAMER_SOURCE,"camera-source");
    g_object_set(G_OBJECT(source),"device",camDeviceName, (char *)0);

    /*Set default properties of mfw_v4lsrc */
    g_object_set(G_OBJECT(source),"capture-width", CAMERA_CAPTURE_WIDTH,
                                  "capture-height", CAMERA_CAPTURE_HEIGHT,
                                  "sensor-width", CAMERA_SENSOR_WIDTH,
                                  "sensor-height", CAMERA_SENSOR_HEIGHT,
                                  "preview", CAMERA_PREVIEW_DISPLAY,
                                  "preview-width",CAMERA_PREVIEW_WIDTH,
                                  "preview-height",CAMERA_PREVIEW_HEIGHT,
                                  "fps-n",CAMERA_FRAMERATE,
                                  "rotate",mirror_effect,
                                  (char *)0);


    /* Tee that copies the stream to multiple outputs */
        tee = gst_element_factory_make("tee", "tee");

        /* Queue creates new thread for the stream */
        screen_queue = gst_element_factory_make("queue", "screen_queue");

    /*Create sink element. We use mfw_v4lsink from Freescale as sink. fbdevsink is not used as
      it directly writes into framebuffer which is not desired*/
    sink= gst_element_factory_make (GSTREAMER_SINK,"video-output");

    capture_queue = gst_element_factory_make("queue", "capture_queue");

    encoder = gst_element_factory_make("mfw_vpuencoder", "encoder");
    g_object_set(G_OBJECT(encoder),"codec-type",0,
                                   "mirror-direction",0,
                                    (char *)0);

    clockoverlay = gst_element_factory_make("clockoverlay", "Timestamp");
    g_object_set(G_OBJECT(clockoverlay),"time-format","%R %d-%b-%Y", (char *)0);

    avimux = gst_element_factory_make("avimux", "avimux");

    filesink = gst_element_factory_make("filesink", "file-output");
    g_object_set(G_OBJECT(filesink),"location","/KPIT/OBITS/Blackbox/OBITS-SCNLog.avi", (char *)0);



    /* Check if all elements are created or not*/
    if (!pipeline || !source || !tee || !screen_queue || !sink || !capture_queue || !clockoverlay || !encoder || !avimux || !filesink) {
        LOGERR((TEXT("GstreamerStream :: camInit: 1 One or more element(s) could not be created .... logerr\n")));
        return CAM_STATUS_INIT_FAIL;
    }

    /* we add all elements into the pipeline */
    gst_bin_add_many (GST_BIN (pipeline),source,tee,screen_queue, sink, capture_queue,clockoverlay,encoder,avimux,filesink, (char *)0);

    /* we link the elements together */
   if( gst_element_link_many( source, tee, NULL ) &&  gst_element_link_many( tee,screen_queue,sink, NULL ) &&
           gst_element_link_many( tee,capture_queue,clockoverlay,encoder,avimux,filesink, NULL ))
   {
         bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));

        /*Add watch to look for error events */
        gst_bus_add_watch(bus, process_events, this);

        gst_object_unref(bus);

        }
        gst_element_set_state (pipeline, GST_STATE_PLAYING);

请让我知道方法,我可以动态添加或删除任何队列.

Kindly let me know the way, I can add or remove any queue dynamically.

如果有人可以提供与此相关的示例代码,我们将不胜感激.

I'd appreciate your help if someone can provide sample code related to this.

推荐答案

将发球区域保持在管线中,您可以在播放期间随时从发球区域请求/释放打击垫.索取便笺本,并将新元素添加到管道中,链接它们,并将它们也设置为可播放.完成后,请断开该分支的链接,并记住将EOS发送到该分支以正确完成录制.从文件接收器收到EOS消息后,您可以关闭,删除并取消引用未链接的分支.

Keep the tee in the pipeline and you can request/release pads from the tee at any time during playback. Request the pad and add your new elements to the pipeline, link them, and set them to playing, too. When you are done, unlink this branch and remember to send EOS to it to have the recording properly finished. After you receive the EOS message from the filesink you can shutdown, remove and unref the branch you unlinked.

如果您使用的是0.10(不使用,请移至1.0),则添加后可能需要将细分事件发送到新分支.

If you are using 0.10 (don't use it, move to 1.0), then you might need to send a segment event to the new branch once you add it.

这篇关于在gstreamer中动态添加和删除tee队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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