Catch ofGstUtils errors


#1

Hello,

I am using video grabber on Linux with USB camera which in a PCB factor ( something like this ).
Sometimes when the webcam is unplugged or the wire become lose, I get some ofGstUtils error, like:

[ error ] ofGstUtils: gstHandleMessage(): embedded video playback halted for plugin, module video_source reported: Internal data flow error.
[ error ] ofGstUtils: gstHandleMessage(): embedded video playback halted for plugin, module video_source reported: Cannot identify device ‘/dev/video0’.

Usually when this happens, my application crashes and I would like to avoid that.
Is there a way to get to know when there are problem with ofGstUtils? I would like to re-initialise the camera if possible or at least send a message to the user to notify him that something wrong happened.

Thanks


#2

Is this crashing inside ofGstUtils or somwhere in your application? if it’s in ofGstUtils it would be really useful if you could open an issue with a stacktrace so we can fix it.

In any case with the gstreamer video grabber there’s a way to plug a listener to be notified about any changes in the pipeline:

auto grabber = videoGrabber.getGrabber<ofGstVideoGrabber>();
auto videoUtils = grabber->getGstVideoUtils();
videoUtils->setSinkListener(this);

Then make your ofApp or whatever class you are starting the video from, implement ofGstAppSink and it’s on_message method:

class ofApp: public ofBaseApp, public ofGstAppSink{
    ...
    bool on_message(GstMessage* msg){
        switch (GST_MESSAGE_TYPE (msg)) {
              case GST_MESSAGE_ERROR: {
                    // an error has occurred
                   break;
              }
              default: 
                  break;
        }
        return true;
    }
}

#3

Thanks for your answer arturo!

In the meantime I was trying some things on my side and it seems that in itself ofGstUtils is not crashing. I guess it’s how I use it in my application that makes it crash.

Great tip to have a listener for changes in the pipeline. It seems that’s what I was looking for.
I will test this out and come back if have more problems.

Cheers! :slight_smile: