Esempio n. 1
0
File: bus.py Progetto: 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
Esempio n. 2
0
 def on_message(self, _, message: Gst.Message):
     """Handles messages from the stream"""
     if message.type == Gst.MessageType.EOS:
         # Handle End of Stream
         self.quit()
     elif message.type == Gst.MessageType.ERROR:
         err, debug = message.parse_error()
         logging.error(err, debug)
     elif message.type == Gst.MessageType.WARNING:
         err, debug = message.parse_warning()
         logging.warning(err, debug)
     return True
Esempio n. 3
0
def on_message(_: Gst.Bus, message: Gst.Message, loop: GObject.MainLoop):
    message_type = message.type
    if message_type == Gst.MessageType.EOS:
        print("End of stream")
        loop.quit()

    elif message_type == Gst.MessageType.ERROR:
        err, debug = message.parse_error()
        print(err, debug)
        loop.quit()

    return True
Esempio n. 4
0
    def msg_handler(self, _bus: Gst.Bus, msg: Gst.Message) -> None:
        """Handle pipeline messages"""

        if msg.type == Gst.MessageType.EOS:
            print('End of stream, exiting', file=sys.stderr)
            self.quit()
        elif msg.type == Gst.MessageType.ERROR:
            print('Fatal error:', msg.parse_error(), file=sys.stderr)
            self.quit()
        elif msg.type == Gst.MessageType.CLOCK_LOST:
            print('Clock lost, resetting', file=sys.stderr)
            self._element.set_state(Gst.State.PAUSED)
            self._element.set_state(Gst.State.PLAYING)
Esempio n. 5
0
 def on_message(self, bus: Gst.Bus, message: Gst.Message):
     """Handles messages from the stream"""
     if message.type == Gst.MessageType.EOS:
         # Handle End of Stream
         self.EOS.set()
         self.quit()
     elif message.type == Gst.MessageType.ERROR:
         err, debug = message.parse_error()
         print(err, debug)
     elif message.type == Gst.MessageType.WARNING:
         err, debug = message.parse_warning()
         print(err, debug)
     return True
Esempio n. 6
0
def __on_gst_message(bus, message: Gst.Message):
    """
    Handle messages from gst.
    """
    global __speed
    global __set_speed

    t = message.type
    if t == Gst.MessageType.BUFFERING:
        if (message.percentage < 100):
            __player.set_state(Gst.State.PAUSED)
            log.info("Buffering…")
        else:
            __player.set_state(Gst.State.PLAYING)
            log.info("Buffering finished.")
    elif t == Gst.MessageType.EOS:
        next_track()
    elif t == Gst.MessageType.ERROR:
        error, debug_msg = message.parse_error()

        if error.code == Gst.ResourceError.NOT_FOUND:
            stop()
            unload()
            emit_event("stop")

            log.warning("gst: Resource not found. Stopping player.")
            reporter.warning("player",
                             "gst: Resource not found. Stopping player.")
            return

        err, debug = message.parse_error()
        log.error(err)
        log.debug(debug)
        reporter.error("player", err)
        emit_event("error", err)
    elif t == Gst.MessageType.STATE_CHANGED:
        state = get_gst_player_state()
        if state == Gst.State.PLAYING or state == Gst.State.PAUSED:
            auto_jump()
Esempio n. 7
0
def on_message(bus: Gst.Bus, message:Gst.Message, loop: GLib.MainLoop):
    mtype = message.type
    if mtype == Gst.MessageType.EOS:
        print('End Of Stream')
        loop.quit()
    elif mtype == Gst.MessageType.ERROR:
        err, debug = message.parse_error()
        print(err, debug)
        loop.quit()
    elif mtype == Gst.MessageType.WARNING:
        err, debug = message.parse_warning()
        print(err, debug)
    
    return True
def bus_call(bus: Gst.Bus, message: Gst.Message, loop: GLib.MainLoop):
    t = message.type
    if t == Gst.MessageType.EOS:
        sys.stdout.write("End-of-stream\n")
        loop.quit()
    elif t == Gst.MessageType.ERROR:
        err, debug = message.parse_error()
        sys.stderr.write("Error: %s: %s\n" % (err, debug))
        loop.quit()
    elif t == Gst.MessageType.WARNING:
        # Handle warnings
        err, debug = message.parse_warning()
        sys.stderr.write("Warning: %s: %s\n" % (err, debug))
    return True
Esempio n. 9
0
    def on_error(self, bus: Gst.Bus, message: Gst.Message) -> None:
        """
        Handler for `error` messages
        By default it will parse the error message,
        log to `error` and append to `self.errors`
        """
        err, debug = message.parse_error()
        logger.error("Error received from element %s:%s on %s",
                     message.src.get_name(), err.message, bus)
        if debug is not None:
            logger.error("Debugging information: %s", debug)

        self.teardown()
        self.events.error.set()
def on_message(bus: Gst.Bus, message: Gst.Message, loop: GObject.MainLoop):
    mtype = message.type
    """
        Gstreamer Message Types and how to parse
        https://lazka.github.io/pgi-docs/Gst-1.0/flags.html#Gst.MessageType
    """
    if mtype == Gst.MessageType.EOS:
        print("End of stream")
        loop.quit()

    elif mtype == Gst.MessageType.ERROR:
        err, debug = message.parse_error()
        print(err, debug)
        loop.quit()
    elif mtype == Gst.MessageType.WARNING:
        err, debug = message.parse_warning()
        print(err, debug)

    return True
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
Esempio n. 12
0
 def on_error(self, bus: Gst.Bus, message: Gst.Message):
     err, debug = message.parse_error()
     self.log.error("Gstreamer.%s: Error %s: %s. ", self, err, debug)
     self._shutdown_pipeline()