Catch Gstreamer errors in Python?

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

Catch Gstreamer errors in Python?

Séb
Hi all,

I'm using Gstreamer 1.0 within Python (running on Windows 7).

I was wondering if it's possible to "catch" Gstreamer errors in my Python code. I tried a few things but wasn't successful. Sorry if it's a silly question but I have not found any working tip on the net...

More specifically, if I build a pipeline with a "filesrc" element looking for a file that does not exist, my code will run forever without any notice. I tried to look at the bus, but I don't get any other message than "state_changed" (no error appears in the bus). The only way I can see that there's actually a problem is by setting the environment variable GST_DEBUG to 3, in which case a "No Such File" message is printed out by GStreamer.

So, at this point, the only way I see would be to set the environment variable to 3 (which probably slows down GStreamer) and intercept the stdout... but I don't think that's a really neat solution. Is there a "good" way to catch these errors?

Thanks,
Seb.

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Catch Gstreamer errors in Python?

Vinod Kesti
EOS should be handled to close the pipeline.
If you share the application code it will he easy to find out the issue.
Reply | Threaded
Open this post in threaded view
|

Re: Catch Gstreamer errors in Python?

Arjen Veenhuizen
This should get you going:

def _installBusListener(self):
	self.bus = self.elementPipeline.get_bus()
	self.bus.add_signal_watch()
	self.bus.enable_sync_message_emission()
	self.bus.connect('message', self._cbBusMessage)
	self.bus.connect('message::eos', self._cbEos)

def _cbEos(self, argElement, argInfo):
	if argInfo and (argInfo.type == Gst.MessageType.EOS ):
		print "End of stream (EOS) received. Stopping pipeline."
		self.bus.remove_signal_watch()
		# clean-up/close your program.
	return Gst.PadProbeReturn.OK

def _cbBusMessage(self, argGstElement, argGstMessageInstance):
	gstStructureInstance = argGstMessageInstance.get_structure()
	if(gstStructureInstance == None):
		return Gst.PadProbeReturn.OK
	messageName = gstStructureInstance.get_name()
	messageType = argGstMessageInstance.type
	if(messageType == Gst.MessageType.ERROR):
		gErrorInstance, debugString = Gst.Message.parse_error(argGstMessageInstance)
		if(gErrorInstance.code == 3):
			if(gErrorInstance.message.find("Resource not found") > -1):
				pass # handle file not found error

As you can see, I use string matching and error code matching to figure out what went wrong. Perhaps there is a more elegant way of doing this but I am unaware of that.
Reply | Threaded
Open this post in threaded view
|

Re: Catch Gstreamer errors in Python?

Séb
Hey Arjen,

Sorry for the delay I was on holiday.

Thanks for your bit of code, it was very useful indeed!
Even though it's not as (Python-wise) integrated as one could wish, it will still help a lot in handling errors.

Seb



De : Arjen Veenhuizen <[hidden email]>
À : [hidden email]
Envoyé le : Dimanche 20 août 2017 10h02
Objet : Re: Catch Gstreamer errors in Python?

This should get you going:



As you can see, I use string matching and error code matching to figure out
what went wrong. Perhaps there is a more elegant way of doing this but I am
unaware of that.



--
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list



_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel