I'd like to know the specific error type of a gstreamer error. I found this sample code:
import gi
import sys
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
def bus_call(bus, message, loop):
t = message.type
if t == Gst.MessageType.EOS:
sys.stdout.write("End-of-stream\n")
loop.quit()
elif t==Gst.MessageType.WARNING:
err, debug = message.parse_warning()
sys.stderr.write("Warning: %s: %s\n" % (err, debug))
elif t == Gst.MessageType.ERROR:
err, debug = message.parse_error()
sys.stderr.write("Error: %s: %s\n" % (err, debug))
loop.quit()
return True
In my use case, I am working with rtsp video streams. Some of them maybe be offline, and therefore the code above would output the error:
Error: gst-resource-error-quark: Could not read from resource. (9): gstrtspsrc.c(5917): gst_rtsp_src_receive_response (): /GstPipeline:pipeline0/GstBin:source-bin-00/GstURIDecodeBin:uri-decode-bin/GstRTSPSrc:source:
Suppose I want the code to call a function when this specific error happens. I could do something like:
if str(err) == "gst-resource-error-quark: Could not read from resource. (9)":
do_something()
However this seems pretty ugly because it seems to be rely on the error message which maybe might change in the future. Is there anything to say like:
if err == ErrorReadOnSource:
do_something()
I am looking for something like an unique error identifier or an errors enumeration (assuming str(err)
is not it).