GstRTSPSrc dynamic pad iteration problem

Orkun orkun.kasapoglu at gmail.com
Thu Dec 24 06:55:47 PST 2015


Hello,

I'm trying to get ip cam streams and saving png images in some period and
I'm also doing it on command line with "gst-launch1.0 rtspsrc
location=usr:pw@<ip>/cam/realmonitor... ! rtph264depay ! h264parse !
omxh264dec ! videorate ! video/x-raw,framerate=1/1 ! pngenc ! multifilesink
location=/home/pi/im_%03d.png". I'm also created all elements and pipeline
and linked them with a for loop without rtspsrc->rtph264depay and videorate
-> filter -> pngenc and before that for loop linked rtspsrc to rtph264depay
with a callback as what ADM 1.6.2 page 30 subject 8.1.1 says. The link was
created for first time but then it's not linking. I've created "pad-removed"
callback too but it didn't make sense. Here is "pad-added" callback:

*static gboolean padAdded = FALSE;
static void rtspsrc_pad_added_callback(GstElement* e, GstPad *pad, gpointer
data)
{
    gchar *name;
    GstCaps *caps;
    gchar *desc;
    GstElement *depayloader;

    //if (padAdded == FALSE) {
    name = gst_pad_get_name(pad);
    g_print("New pad %s was created", name);
    
    caps = gst_pad_get_pad_template_caps(pad);
    desc = gst_caps_to_string(caps);
    g_print("\n%s\n", desc);
    g_free(desc);
    
    depayloader = GST_ELEMENT(data);

    if (gst_element_link_pads(e, name, depayloader, "sink") == FALSE)
    {
        g_print("'rtspsrc' and 'rtph264depay' did not linked\nProgram
ending...\n");
        exit(0);
    }
    else
    {
        g_print("'rtspsrc' and 'rtph264depay' linked\n");
    }
    //padAdded = TRUE;
    //}
    //else
    //{
        //g_print("Pad and link also created\n");
    //}
}

static void rtspsrc_pad_added_callback(GstElement* e, GstPad *pad, gpointer
data)
{
    gchar *name;
    GstCaps *caps;
    gchar *desc;
    GstElement *depayloader;

    //if (padAdded == TRUE) {
    name = gst_pad_get_name(pad);
    g_print("Pad %s will be removed");

    caps = gst_pad_get_pad_template_caps(pad);
    
    desc = gst_caps_to_string(caps);
    g_print("\n%s\n", desc);
    g_free(desc);

    depayloader = GST_ELEMENT(data);

    gst_element_unlink_pads(e, name, depayloader, "sink");
    //padAdded = FALSE;
    //}
    //else
    //{
        //g_print("Pad and link also removed\n");
    //}
}  *

I'm thiking that the sometimes pad has been created when the packet is
available then removed and when new packet is available it's been created
again and continue with the same process. Here is the bus callback ouput:

*
...
...
bus cb msg: state-changed
bus cb msg: stream-status
New pad recv_rtp_src_0_4294952720_96 was created...

application/x-rtp; application/x-rdt

'rtspsrc' and 'rtph264depay' linked
bus cb msg: state-changed
bus cb msg: state-changed
bus cb msg: state-changed
bus cb msg: state-changed
bus cb msg: stream-status
bus cb msg: state-changed
bus cb msg: state-changed
bus cb msg: stream-status
New pad recv_rtp_src_1_4294936198_8 was created...

application/x-rtp; application/x-rdt

'rtspsrc' and 'rtph264depay' did not linked
Program ending...
*

then I added commented lines in callback functions so this was caused an
internal error:

*
New pad recv_rtp_src_0_4294952720_96 was created

application/x-rtp; application/x-rdt
'rtspsrc' and 'rtph264depay' linked
bus cb msg: state-changed
bus cb msg: state-changed
bus cb msg: state-changed
Pad and link also created
bus cb msg: state-changed
bus cb msg: stream-status
bus cb msg: state-changed
bus cb msg: state-changed
bus cb msg: stream-status
bus cb msg: stream-status
bus cb msg: stream-status
bus cb msg: error
! Error: Internal data stream error.
! Debug: gstomxvideodec.c(1586): gst_omx_video_dec_loop ():
/GstPipeline:my_pipe/GstOMXH264Dec-omxh264:decoder:
stream stopped, reason not-negotiated
Pad recv_rtp_src_0_4294952720_96 will be removed

application/x-rtp; application/x-rdt

Pad and link also removed
*

Here is my main and add with filter function;

*
gboolean link_with_filter(GstElement *src, GstElement *dst)
{
    gboolean linkOk;
    GstCaps *caps;
    caps = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING,
"RGB",
                "width", G_TYPE_INT, 1280,
                "height", G_TYPE_INT, 720,
                "framerate", G_TYPE_FRACTION, 1, 1,
                NULL);
    if (caps == NULL)
    {
        g_print("'caps' NULL);
        return -1;
    }

    linkOk = gst_element_link_filtered(src, dst, caps);
    gst_unref_caps(caps);
    return linkOk;
}

int main(int argc, char *argv[])
{
    GstElement *pipeline;
    GstElement *rtspsrc;
    GstElement *rtph264depay;
    GstElement *h264parse;
    GstElement *omxh264dec;
    GstElement *videorate;
    GstElement *pngenc;
    GstElement *multifilesink;
    GstBus *bus;
    GMainLoop *mLoop = NULL;

    gst_init(&argc, &argv);

    mLoop = g_main_loop_new(NULL, FALSE);
    if (mLoop == NULL)
    {
        g_print("'mLoop' NULL!\n);
        return -1;
    }
    rtspsrc = gst_element_factory_make("rtspsrc", "source");
    rtph264depay = gst_element_factory_make("rtspsrc", "depay");
    h264parse = gst_element_factory_make("rtspsrc", "parse");
    omxh264dec = gst_element_factory_make("rtspsrc", "decoder");
    videorate = gst_element_factory_make("rtspsrc", "rate");
    pngenc = gst_element_factory_make("rtspsrc", "encoder");
    multifilesink = gst_element_factory_make("rtspsrc", "sink");
    
    // check the element pointers for NULL

    pipeline = gst_pipeline_new("my_pipe");
    if (pipeline == NULL)
    {
        g_print("'pipeline' NULL");
        return -1;
    }

    gst_bin_add_many(GST_BIN(pipeline), rtspsrc, rtph264depay, h264parse,
omxh264dec, videorate, pngenc, multifilesink, NULL);

    g_signal_connect(rtspsrc, "pad-added",
G_CALLBACK(rtspsrc_pad_added_callback), rtph264depay);
    g_signal_connect(rtspsrc, "pad-added",
G_CALLBACK(rtspsrc_pad_removed_callback), rtph264depay);

    gst_element_link_pads(rtph264depay, "src", h264parse, "sink");
    gst_element_link_pads(h264parse, "src", omxh264dec, "sink");
    gst_element_link_pads(omxh264dec, "src", videorate, "sink");
    gst_element_link_pads(pngenc, "src", multifilesink, "sink");

    if (link_with_filter(videorate, pngenc) == FALSE)
    {
        g_print("'videorate' and 'pngenc' did not link with filter\n");
        return -1;
    }

    g_object_set(G_OBJECT(rtspsrc), "location", argv[1], NULL);
    g_object_set(G_OBJECT(multifilesink), "location", argv[2], NULL);

    bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    gst_bus_add_watch(bus, bus_callback_function, mLoop);
    gst_object_unref(bus);

    gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);

    g_main_loop_run(mLoop);

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

    return 0;
}
*

I googled and look internet but didn't find anything.
Thanks.

Orkun.



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/GstRTSPSrc-dynamic-pad-iteration-problem-tp4675018.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list