Search code examples
gstreamerpad

how to check whether a sink pad of an element is receiving data or not?


I would like to know how to check whether a sink pad of an element in gstreamer is getting data or not.

When ever if it is not getting the data i would like to reset or restart the pipeline.

And can anybody tell me how to reset or restart the pipeline? and what happens when restart the pipeline? and how to know about incoming data for a pad?


Solution

  • You may want to break your post into two separate questions. As far as re-starting the pipeline, you can set the state to NULL then back to PLAYING, but I recommend restarting the entire process since so many elements fail to cleanup properly.

    To detect if buffers are coming in, you could add an identity element at the desired spot of your pipeline and register a callback on it like so. Then in your main thread verify the update time is within the desired range. Perhaps using g_timeout_add().

    void ir_data_received(GstElement* identity, GstBuffer* buf, gpointer user_data) {
        my_object *some_useful_pointer = (my_object*)user_data;
    
        //data is coming in, reset the necessary flag
    }
    
    void setup(GstElement * pipeline, my_object *some_useful_pointer) {    
        GstElement* identity = gst_bin_get_by_name(GST_BIN(pipeline), "identity");
        if(identity == NULL) {
            //error handling
        }
    
        g_signal_connect(G_OBJECT(identity), "handoff", (GCallback)data_received, some_useful_pointer);
    }
    

    Timeout check every second:

    gboolean check_status(gpointer user_data) {
        //check if data is coming in and exit system if it's not
    }
    
    g_timeout_add(1000, check_status, some_useful_pointer);