1

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).

user1315621
  • 3,044
  • 9
  • 42
  • 86

1 Answers1

0

Looks like you can rely on string comparison as according to this and your special case resource error "gst-resource-error.... (9)" is not going to change in future (unless maybe in major release)

Gst.ResourceError.READ (9) – used when the resource can't be read from.

Consider handling it by categories, so:

elif t == Gst.MessageType.ERROR:
    err, debug = message.parse_error()
    if str(err).startswith("gst-resource-error-quark"):
        # resource errors from 1 to 16
        if str(err).endswith("(9)"):
            handle_read_error()
    elif str(err).startswith("gst-stream-error-quark"):
        # stream errors from 1 to 14
        if str(err).endswith("(1)"):
            # handle general stream error
AlonS
  • 683
  • 2
  • 8
  • 16