dynamically change of video sources with signal watch added

Francesco Marino francescomarino84627 at gmail.com
Tue Aug 18 08:16:53 PDT 2015


Hi,
I'm having some troubles changing the source element while the pipeline is
playing. More precisely, I'm trying with a very simplified test case: src !
videoconvert ! xvimagesink, where src element switches between 2 usb
cameras in /dev/video0 and /dev/video1 (actually I also tested with only
one camera and videotestsrc but nothing changes).
Every 10 secs the switching function is called:

static gboolean switchSrcVideo (gpointer user_data)
{
    GstData_t *gstData = (GstData_t*) user_data;
    GstElement *next;

    GstBus *bus_new = NULL;

    if(gstData->bus != NULL)
    {
        gst_bus_remove_signal_watch (gstData->bus);
        gstData->bus = NULL;
    }

    if( !strcmp(GST_OBJECT_NAME (gstData->src),"camera1") )
    {
        next = gstData->v4lcamera;
    }
    else if( !strcmp(GST_OBJECT_NAME (gstData->src),"camera2"))
    {
        next = gstData->testsrc;
    }

    g_print ("Switch from ā€™%sā€™ to ā€™%sā€™..\n", GST_OBJECT_NAME
(gstData->src), GST_OBJECT_NAME (next));

    g_print("set NULL state to src..\n");
    gst_element_set_state (gstData->src, GST_STATE_NULL);

    g_print("unlink src from conv..\n");
    gst_element_unlink(gstData->src, gstData->conv);

    g_print("remove src..\n");
    gst_bin_remove (GST_BIN (gstData->pipeline), gstData->src);


    g_print("add next..\n");
    gst_bin_add (GST_BIN (gstData->pipeline), next);

    g_print("link next to conv..\n");
    gst_element_link_many ( next, gstData->conv, /*gstData->videoscale,
gstData->sink,*/ NULL);

//     g_print("add signal watch again..\n");
//     bus_new = gst_pipeline_get_bus (GST_PIPELINE (gstData->pipeline));
//     if(bus_new!=NULL)
//     {
//          gst_bus_add_signal_watch (bus_new);
//          g_signal_connect (bus_new, "message::error", G_CALLBACK
(cb_message_error), NULL);
//         gstData->bus = bus_new;
//     }

    g_print("set PLAY state to next..\n");
    gst_element_set_state (next, GST_STATE_PLAYING);

    gstData->src = next;

    g_print("..done!\n");

    return TRUE;
}

With the above code all work perfectly but, if I uncomment the signal watch
part, then only the first switch (camera1 -> camera2) is performed and,
when it attempts to switch again, the following message comes out:

[Invalid UTF-8]
Switch from \xe2\x80\x99camera2\xe2\x80\x99 to \xe2\x80\x99 at y
\x93\xe2\x80\x99..

I also noted that the problem occurs when I simply call
gst_pipeline_get_bus (GST_PIPELINE (gstData->pipeline)) keeping commented
the lines below.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20150818/52aff64c/attachment.html>


More information about the gstreamer-devel mailing list