How to check if my pipeline is actually grabbing something

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How to check if my pipeline is actually grabbing something

Arnoussh
Hi all,

I create my pipeline and play it like bellow. I would like to know if there is a way to check if my pipeline is grabbing something ? I would like to create my pipeline and start to grab something and when I am sure there is something incomming, display it on my sotfware in order to not have my user waiting some second after clicking on the button "start streaming". I don't know if it clear.

thanks in advance

 m_pipeline = gst_parse_launch("udpsrc name=source !rtpjitterbuffer !rtph264depay !h264parse !avdec_h264 !autovideoconvert !d3dvideosink name=mysink sync=false", &error);
    if (!m_pipeline) {
        g_print("Parse error: %s\n", error->message);
        exit(1);
    }

    source = gst_bin_get_by_name(GST_BIN(m_pipeline), "source");
    g_object_set(G_OBJECT(source), "caps", caps, NULL);
    g_object_set(G_OBJECT(source), "port", m_port, NULL);

    gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
Reply | Threaded
Open this post in threaded view
|

Re: How to check if my pipeline is actually grabbing something

Marianna S. Buschle
Add a buffer probe?

pad = gst_element_get_static_pad(elem, "src");
gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, (GstPadProbeCallback) buffer_out_cb, pipe, NULL);
gst_object_unref(pad);


GstPadProbeReturn
buffer_out_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data)
{
        GstElement *pipe = (GstElement *)user_data;

        //do whatever

        //remove the probe if you don't need it anymore, otherwise return GST_PAD_PROBE_OK
        return GST_PAD_PROBE_REMOVE;
}
Reply | Threaded
Open this post in threaded view
|

Re: How to check if my pipeline is actually grabbing something

Arnoussh
I am not sure to understand how to use that in my code. Which element in your code give me the information that pipeline is recieving frame?
Reply | Threaded
Open this post in threaded view
|

Re: How to check if my pipeline is actually grabbing something

Marianna S. Buschle
Something like:

m_pipeline = gst_parse_launch("udpsrc name=source !rtpjitterbuffer !rtph264depay !h264parse !avdec_h264 !autovideoconvert !d3dvideosink name=mysink sync=false", &error);
    if (!m_pipeline) {
        g_print("Parse error: %s\n", error->message);
        exit(1);
    }

    source = gst_bin_get_by_name(GST_BIN(m_pipeline), "source");
    g_object_set(G_OBJECT(source), "caps", caps, NULL);
    g_object_set(G_OBJECT(source), "port", m_port, NULL);

    pad = gst_element_get_static_pad(source, "src");
    gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, (GstPadProbeCallback) buffer_out_cb, pipe, NULL);
    gst_object_unref(pad);

    gst_element_set_state(m_pipeline, GST_STATE_PLAYING);


GstPadProbeReturn
buffer_out_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data)
{
        GstElement *pipe = (GstElement *)user_data;

        printf("Got buffer\n");

        //remove the probe if you don't need it anymore, otherwise return GST_PAD_PROBE_OK
        return GST_PAD_PROBE_REMOVE;
}

In this way when the first buffer comes out of 'udpsrc' the 'buffer_out_cb' callback will be called, and inside there you can start whatever you need in your application.

And if you use GST_PAD_PROBE_REMOVE  the probe will be removed and 'buffer_out_cb' won't be called anymore.
If you instead return  GST_PAD_PROBE_OK then 'buffer_out_cb' will be called every time a buffer comes out of the 'udpsrc'.

Alternatively you could attach the probe to 'avdec_h264' so you know you have a decoded buffer ready to show...
Reply | Threaded
Open this post in threaded view
|

Re: How to check if my pipeline is actually grabbing something

Arnoussh
Thank you very much it works perfectly:)
Reply | Threaded
Open this post in threaded view
|

Re: How to check if my pipeline is actually grabbing something

Arnoussh
When I grab the first frame the callback function buffer_out_cb is calling succefuly. But in this function I can have acces to all the variable of my code. How in my main can I have the information the this function have been called ?

Reply | Threaded
Open this post in threaded view
|

Re: How to check if my pipeline is actually grabbing something

Marianna S. Buschle
You can pass whatever you need using the 'gpointer user_data' of the callback.

Right now it is just passing a pointer to the pipeline, but you can change to pass a pointer to whatever variable you need.
Reply | Threaded
Open this post in threaded view
|

Re: How to check if my pipeline is actually grabbing something

Arnoussh
Thank you now I understand. But can I modify the value of the gpointer user_data in the callback ? Very simple example : passing and integer (ready) initialized to 0 in the gpointer user_data of the callback and change is value to 1. So in my main, I juste have to check when the interger ready change to 1 I can be sure that the callback function was called.
Reply | Threaded
Open this post in threaded view
|

Re: How to check if my pipeline is actually grabbing something

Arnoussh
I succeeded to pass a pointer in the callback function in order to have the information in my main that my stream is grabbing buffer.

Thank you for your help, I really appriciate :)