在 gstreamer 中动态添加和删除发球队列

In gstreamer adding and removing queue of a tee dynamically

我写了gstreamer代码,可以同时进行摄像头直播和录像。

我的管道看起来像这样:

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

目前正在同时进行直播和文件录制。

现在我只需要用一个队列启动管道,即 queue1(直播队列),过一会儿我需要添加录制队列并动态删除它。

我的工作代码如下:

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

请告诉我方法,我可以动态添加或删除任何队列。

如果有人能提供与此相关的示例代码,我将不胜感激。

将发球台保持在管道中,您可以在播放期间随时从发球台 request/release 打击垫。请求 pad 并将新元素添加到管道中,link 它们,并将它们也设置为播放。当你完成后,unlink 这个分支,记得发送 EOS 给它,以便正确完成记录。从文件接收器收到 EOS 消息后,您可以关闭、删除和取消引用您未link编辑的分支。

如果您使用的是 0.10(不使用它,移至 1.0),那么您可能需要在添加后向新分支发送段事件。