コード例 #1
0
ファイル: bus.py プロジェクト: mdegans/mce
def on_message(bus: Gst.Bus,
               message: Gst.Message,
               app,
               ) -> bool:
    """Callback for handling bus messages"""
    # TAG and DURATION_CHANGED seem to be the most common
    if message.type == Gst.MessageType.TAG:
        pass
    elif message.type == Gst.MessageType.DURATION_CHANGED:
        pass
    elif message.type == Gst.MessageType.STREAM_STATUS:
        status, owner = message.parse_stream_status()  # type: Gst.StreamStatusType, Gst.Element
        logger.debug(f"{owner.name}:status:{status.value_name}")
    elif message.type == Gst.MessageType.STATE_CHANGED:
        old, new, pending = message.parse_state_changed()  # type: Gst.State, Gst.State, Gst.State
        logger.debug(
            f"{message.src.name}:state-change:"
            f"{old.value_name}->{new.value_name}")
    elif message.type == Gst.MessageType.EOS:
        logger.debug(f"Got EOS")
        app.quit()
    elif message.type == Gst.MessageType.ERROR:
        err, errmsg = message.parse_error()  # type: GLib.Error, str
        logger.error(f'{err}: {errmsg}')
        app.quit()
    elif message.type == Gst.MessageType.WARNING:
        err, errmsg = message.parse_warning()  # type: GLib.Error, str
        logger.warning(f'{err}: {errmsg}')
    else:
        if mce.DEBUG:
            logger.debug(
                f"{message.src.name}:{Gst.MessageType.get_name(message.type)}")
    return True
コード例 #2
0
def bus_call(bus: Gst.Bus, message: Gst.Message, loop: GLib.MainLoop):
    # https://stackoverflow.com/questions/49858346/how-te-retrieve-stream-statistics-in-gstreamer
    t = message.type
    sys.stdout.write("Received message from -> %s \n" % (message.src.name))
    if t == Gst.MessageType.EOS:
        sys.stdout.write("End-of-stream\n")
    elif t == Gst.MessageType.ERROR:
        err, debug = message.parse_error()
        sys.stderr.write("Error: %s: %s\n" % (err, debug))
    elif t == Gst.MessageType.WARNING:
        # Handle warnings
        err, debug = message.parse_warning()
        sys.stderr.write("Warning: %s: %s\n" % (err, debug))
    # https://git.smart-cactus.org/ben/cam-stream/blob/0483fa5d3bb82e8a4212d7190d4541ed4d0653d5/stream.py
    elif t == Gst.MessageType.STATE_CHANGED:
        sys.stderr.write('state changed: %s\n' %
                         (message.parse_state_changed(), ))
    elif t == Gst.MessageType.STREAM_STATUS:
        sys.stderr.write('stream status: %s\n' %
                         (message.parse_stream_status(), ))
    elif t == Gst.MessageType.QOS:
        # Handle Qus
        live, running_time, stream_time, timestamp, duration = message.parse_qos(
        )
        #sys.stderr.write("Qos Message: live %r, running_time %i, stream_time %i, timestamp: %i, duration: %i \n" % (live, running_time, stream_time, timestamp, duration))
        #sys.stderr.write('qos: %s' % (message.parse_qos(),))
    elif t == Gst.MessageType.ELEMENT:
        sys.stderr.write('Element message: %s\n' %
                         (message.get_structure().to_string(), ))
    elif t == Gst.MessageType.BUFFERING:
        sys.stderr.write('Buffering message: %s\n' %
                         (message.get_structure().to_string(), ))
    elif t == Gst.MessageType.PROGRESS:
        sys.stderr.write('Progress message: %s\n' %
                         (message.get_structure().to_string(), ))
    else:
        sys.stderr.write('Bus message: %s: %s \n' % (message.timestamp, t))
        pprint(message)
    return True