Beispiel #1
0
 def on_new_segment(self, update, rate, format_, start, stop, position):
     gst_logger.debug('Got new-segment event: update=%s rate=%s format=%s '
                      'start=%s stop=%s position=%s', update, rate,
                      format_.value_name, start, stop, position)
     position_ms = position // gst.MSECOND
     logger.debug('Audio event: position_changed(position=%s)', position_ms)
     AudioListener.send('position_changed', position=position_ms)
Beispiel #2
0
    def _on_playbin_state_changed(self, old_state, new_state, pending_state):
        if new_state == gst.STATE_READY and pending_state == gst.STATE_NULL:
            # XXX: We're not called on the last state change when going down to
            # NULL, so we rewrite the second to last call to get the expected
            # behavior.
            new_state = gst.STATE_NULL
            pending_state = gst.STATE_VOID_PENDING

        if pending_state != gst.STATE_VOID_PENDING:
            return  # Ignore intermediate state changes

        if new_state == gst.STATE_READY:
            return  # Ignore READY state as it's GStreamer specific

        new_state = _GST_STATE_MAPPING[new_state]
        old_state, self.state = self.state, new_state

        target_state = _GST_STATE_MAPPING[self._target_state]
        if target_state == new_state:
            target_state = None

        logger.debug(
            'Triggering event: state_changed(old_state=%s, new_state=%s, '
            'target_state=%s)', old_state, new_state, target_state)
        AudioListener.send('state_changed',
                           old_state=old_state,
                           new_state=new_state,
                           target_state=target_state)
Beispiel #3
0
    def _on_playbin_state_changed(self, old_state, new_state, pending_state):
        if new_state == gst.STATE_READY and pending_state == gst.STATE_NULL:
            # XXX: We're not called on the last state change when going down to
            # NULL, so we rewrite the second to last call to get the expected
            # behavior.
            new_state = gst.STATE_NULL
            pending_state = gst.STATE_VOID_PENDING

        if pending_state != gst.STATE_VOID_PENDING:
            return  # Ignore intermediate state changes

        if new_state == gst.STATE_READY:
            return  # Ignore READY state as it's GStreamer specific

        new_state = _GST_STATE_MAPPING[new_state]
        old_state, self.state = self.state, new_state

        target_state = _GST_STATE_MAPPING[self._target_state]
        if target_state == new_state:
            target_state = None

        logger.debug(
            'Triggering event: state_changed(old_state=%s, new_state=%s, '
            'target_state=%s)', old_state, new_state, target_state)
        AudioListener.send('state_changed', old_state=old_state,
                           new_state=new_state, target_state=target_state)
Beispiel #4
0
 def on_new_segment(self, update, rate, format_, start, stop, position):
     gst_logger.debug(
         'Got new-segment event: update=%s rate=%s format=%s '
         'start=%s stop=%s position=%s', update, rate, format_.value_name,
         start, stop, position)
     position_ms = position // gst.MSECOND
     logger.debug('Audio event: position_changed(position=%s)', position_ms)
     AudioListener.send('position_changed', position=position_ms)
Beispiel #5
0
    def on_playbin_state_changed(self, old_state, new_state, pending_state):
        gst_logger.debug(
            "Got STATE_CHANGED bus message: old=%s new=%s pending=%s",
            old_state.value_name,
            new_state.value_name,
            pending_state.value_name,
        )

        if new_state == Gst.State.READY and pending_state == Gst.State.NULL:
            # XXX: We're not called on the last state change when going down to
            # NULL, so we rewrite the second to last call to get the expected
            # behavior.
            new_state = Gst.State.NULL
            pending_state = Gst.State.VOID_PENDING

        if pending_state != Gst.State.VOID_PENDING:
            return  # Ignore intermediate state changes

        if new_state == Gst.State.READY:
            return  # Ignore READY state as it's GStreamer specific

        new_state = _GST_STATE_MAPPING[new_state]
        old_state, self._audio.state = self._audio.state, new_state

        target_state = _GST_STATE_MAPPING.get(self._audio._target_state)
        if target_state is None:
            # XXX: Workaround for #1430, to be fixed properly by #1222.
            logger.warn("Race condition happened. See #1222 and #1430.")
            return
        if target_state == new_state:
            target_state = None

        logger.debug(
            "Audio event: state_changed(old_state=%s, new_state=%s, "
            "target_state=%s)",
            old_state,
            new_state,
            target_state,
        )
        AudioListener.send(
            "state_changed",
            old_state=old_state,
            new_state=new_state,
            target_state=target_state,
        )
        if new_state == PlaybackState.STOPPED:
            logger.debug("Audio event: stream_changed(uri=None)")
            AudioListener.send("stream_changed", uri=None)

        if "GST_DEBUG_DUMP_DOT_DIR" in os.environ:
            Gst.debug_bin_to_dot_file(self._audio._playbin,
                                      Gst.DebugGraphDetails.ALL, "mopidy")
Beispiel #6
0
    def on_stream_start(self):
        gst_logger.debug('Got STREAM_START bus message')
        uri = self._audio._pending_uri
        logger.debug('Audio event: stream_changed(uri=%r)', uri)
        AudioListener.send('stream_changed', uri=uri)

        # Emit any postponed tags that we got after about-to-finish.
        tags, self._audio._pending_tags = self._audio._pending_tags, None
        self._audio._tags = tags

        if tags:
            logger.debug('Audio event: tags_changed(tags=%r)', tags.keys())
            AudioListener.send('tags_changed', tags=tags.keys())
Beispiel #7
0
    def on_stream_start(self):
        gst_logger.debug('Got STREAM_START bus message')
        uri = self._audio._pending_uri
        logger.debug('Audio event: stream_changed(uri=%r)', uri)
        AudioListener.send('stream_changed', uri=uri)

        # Emit any postponed tags that we got after about-to-finish.
        tags, self._audio._pending_tags = self._audio._pending_tags, None
        self._audio._tags = tags

        if tags:
            logger.debug('Audio event: tags_changed(tags=%r)', tags.keys())
            AudioListener.send('tags_changed', tags=tags.keys())
Beispiel #8
0
 def on_segment(self, segment):
     gst_logger.debug(
         'Got SEGMENT pad event: '
         'rate=%(rate)s format=%(format)s start=%(start)s stop=%(stop)s '
         'position=%(position)s', {
             'rate': segment.rate,
             'format': Gst.Format.get_name(segment.format),
             'start': segment.start,
             'stop': segment.stop,
             'position': segment.position
         })
     position_ms = segment.position // Gst.MSECOND
     logger.debug('Audio event: position_changed(position=%r)', position_ms)
     AudioListener.send('position_changed', position=position_ms)
Beispiel #9
0
 def on_segment(self, segment):
     gst_logger.debug(
         'Got SEGMENT pad event: '
         'rate=%(rate)s format=%(format)s start=%(start)s stop=%(stop)s '
         'position=%(position)s', {
             'rate': segment.rate,
             'format': Gst.Format.get_name(segment.format),
             'start': segment.start,
             'stop': segment.stop,
             'position': segment.position
         })
     position_ms = segment.position // Gst.MSECOND
     logger.debug('Audio event: position_changed(position=%r)', position_ms)
     AudioListener.send('position_changed', position=position_ms)
Beispiel #10
0
 def on_segment(self, segment):
     gst_logger.debug(
         "Got SEGMENT pad event: "
         "rate=%(rate)s format=%(format)s start=%(start)s stop=%(stop)s "
         "position=%(position)s",
         {
             "rate": segment.rate,
             "format": Gst.Format.get_name(segment.format),
             "start": segment.start,
             "stop": segment.stop,
             "position": segment.position,
         },
     )
     position_ms = segment.position // Gst.MSECOND
     logger.debug("Audio event: position_changed(position=%r)", position_ms)
     AudioListener.send("position_changed", position=position_ms)
Beispiel #11
0
    def on_stream_start(self):
        gst_logger.debug("Got STREAM_START bus message")
        uri = self._audio._pending_uri
        logger.debug("Audio event: stream_changed(uri=%r)", uri)
        AudioListener.send("stream_changed", uri=uri)

        # Emit any postponed tags that we got after about-to-finish.
        tags, self._audio._pending_tags = self._audio._pending_tags, None
        self._audio._tags = tags or {}

        if tags:
            logger.debug("Audio event: tags_changed(tags=%r)", tags.keys())
            AudioListener.send("tags_changed", tags=tags.keys())

        if self._audio._pending_metadata:
            self._audio._playbin.send_event(self._audio._pending_metadata)
            self._audio._pending_metadata = None
Beispiel #12
0
    def on_playbin_state_changed(self, old_state, new_state, pending_state):
        gst_logger.debug(
            "Got state-changed message: old=%s new=%s pending=%s",
            old_state.value_name,
            new_state.value_name,
            pending_state.value_name,
        )

        if new_state == gst.STATE_READY and pending_state == gst.STATE_NULL:
            # XXX: We're not called on the last state change when going down to
            # NULL, so we rewrite the second to last call to get the expected
            # behavior.
            new_state = gst.STATE_NULL
            pending_state = gst.STATE_VOID_PENDING

        if pending_state != gst.STATE_VOID_PENDING:
            return  # Ignore intermediate state changes

        if new_state == gst.STATE_READY:
            return  # Ignore READY state as it's GStreamer specific

        new_state = _GST_STATE_MAPPING[new_state]
        old_state, self._audio.state = self._audio.state, new_state

        target_state = _GST_STATE_MAPPING[self._audio._target_state]
        if target_state == new_state:
            target_state = None

        logger.debug(
            "Audio event: state_changed(old_state=%s, new_state=%s, " "target_state=%s)",
            old_state,
            new_state,
            target_state,
        )
        AudioListener.send("state_changed", old_state=old_state, new_state=new_state, target_state=target_state)
        if new_state == PlaybackState.STOPPED:
            logger.debug("Audio event: stream_changed(uri=None)")
            AudioListener.send("stream_changed", uri=None)

        if "GST_DEBUG_DUMP_DOT_DIR" in os.environ:
            gst.DEBUG_BIN_TO_DOT_FILE(self._audio._playbin, gst.DEBUG_GRAPH_SHOW_ALL, "mopidy")
Beispiel #13
0
    def on_playbin_state_changed(self, old_state, new_state, pending_state):
        gst_logger.debug(
            'Got STATE_CHANGED bus message: old=%s new=%s pending=%s',
            old_state.value_name, new_state.value_name,
            pending_state.value_name)

        if new_state == Gst.State.READY and pending_state == Gst.State.NULL:
            # XXX: We're not called on the last state change when going down to
            # NULL, so we rewrite the second to last call to get the expected
            # behavior.
            new_state = Gst.State.NULL
            pending_state = Gst.State.VOID_PENDING

        if pending_state != Gst.State.VOID_PENDING:
            return  # Ignore intermediate state changes

        if new_state == Gst.State.READY:
            return  # Ignore READY state as it's GStreamer specific

        new_state = _GST_STATE_MAPPING[new_state]
        old_state, self._audio.state = self._audio.state, new_state

        target_state = _GST_STATE_MAPPING.get(self._audio._target_state)
        if target_state is None:
            # XXX: Workaround for #1430, to be fixed properly by #1222.
            logger.debug('Race condition happened. See #1222 and #1430.')
            return
        if target_state == new_state:
            target_state = None

        logger.debug('Audio event: state_changed(old_state=%s, new_state=%s, '
                     'target_state=%s)', old_state, new_state, target_state)
        AudioListener.send('state_changed', old_state=old_state,
                           new_state=new_state, target_state=target_state)
        if new_state == PlaybackState.STOPPED:
            logger.debug('Audio event: stream_changed(uri=None)')
            AudioListener.send('stream_changed', uri=None)

        if 'GST_DEBUG_DUMP_DOT_DIR' in os.environ:
            Gst.debug_bin_to_dot_file(
                self._audio._playbin, Gst.DebugGraphDetails.ALL, 'mopidy')
Beispiel #14
0
    def on_tag(self, taglist):
        tags = tags_lib.convert_taglist(taglist)
        gst_logger.debug('Got TAG bus message: tags=%r', dict(tags))

        # Postpone emitting tags until stream start.
        if self._audio._pending_tags is not None:
            self._audio._pending_tags.update(tags)
            return

        # TODO: Add proper tests for only emitting changed tags.
        unique = object()
        changed = []
        for key, value in tags.items():
            # Update any tags that changed, and store changed keys.
            if self._audio._tags.get(key, unique) != value:
                self._audio._tags[key] = value
                changed.append(key)

        if changed:
            logger.debug('Audio event: tags_changed(tags=%r)', changed)
            AudioListener.send('tags_changed', tags=changed)
Beispiel #15
0
    def on_tag(self, taglist):
        tags = tags_lib.convert_taglist(taglist)
        gst_logger.debug('Got TAG bus message: tags=%r', dict(tags))

        # Postpone emitting tags until stream start.
        if self._audio._pending_tags is not None:
            self._audio._pending_tags.update(tags)
            return

        # TODO: Add proper tests for only emitting changed tags.
        unique = object()
        changed = []
        for key, value in tags.items():
            # Update any tags that changed, and store changed keys.
            if self._audio._tags.get(key, unique) != value:
                self._audio._tags[key] = value
                changed.append(key)

        if changed:
            logger.debug('Audio event: tags_changed(tags=%r)', changed)
            AudioListener.send('tags_changed', tags=changed)
Beispiel #16
0
    def on_playbin_state_changed(self, old_state, new_state, pending_state):
        gst_logger.debug('Got state-changed message: old=%s new=%s pending=%s',
                         old_state.value_name, new_state.value_name,
                         pending_state.value_name)

        if new_state == gst.STATE_READY and pending_state == gst.STATE_NULL:
            # XXX: We're not called on the last state change when going down to
            # NULL, so we rewrite the second to last call to get the expected
            # behavior.
            new_state = gst.STATE_NULL
            pending_state = gst.STATE_VOID_PENDING

        if pending_state != gst.STATE_VOID_PENDING:
            return  # Ignore intermediate state changes

        if new_state == gst.STATE_READY:
            return  # Ignore READY state as it's GStreamer specific

        new_state = _GST_STATE_MAPPING[new_state]
        old_state, self._audio.state = self._audio.state, new_state

        target_state = _GST_STATE_MAPPING[self._audio._target_state]
        if target_state == new_state:
            target_state = None

        logger.debug(
            'Audio event: state_changed(old_state=%s, new_state=%s, '
            'target_state=%s)', old_state, new_state, target_state)
        AudioListener.send('state_changed',
                           old_state=old_state,
                           new_state=new_state,
                           target_state=target_state)
        if new_state == PlaybackState.STOPPED:
            logger.debug('Audio event: stream_changed(uri=None)')
            AudioListener.send('stream_changed', uri=None)

        if 'GST_DEBUG_DUMP_DOT_DIR' in os.environ:
            gst.DEBUG_BIN_TO_DOT_FILE(self._audio._playbin,
                                      gst.DEBUG_GRAPH_SHOW_ALL, 'mopidy')
Beispiel #17
0
 def on_stream_start(self):
     gst_logger.debug('Got STREAM_START bus message')
     uri = self._audio._pending_uri
     logger.debug('Audio event: stream_changed(uri=%r)', uri)
     AudioListener.send('stream_changed', uri=uri)
Beispiel #18
0
 def on_tag(self, taglist):
     tags = utils.convert_taglist(taglist)
     self._audio._tags.update(tags)
     logger.debug('Audio event: tags_changed(tags=%r)', tags.keys())
     AudioListener.send('tags_changed', tags=tags.keys())
Beispiel #19
0
 def on_end_of_stream(self):
     gst_logger.debug('Got EOS (end of stream) bus message.')
     logger.debug('Audio event: reached_end_of_stream()')
     self._audio._tags = {}
     AudioListener.send('reached_end_of_stream')
Beispiel #20
0
 def on_tag(self, taglist):
     tags = tags_lib.convert_taglist(taglist)
     gst_logger.debug('Got TAG bus message: tags=%r', dict(tags))
     self._audio._tags.update(tags)
     logger.debug('Audio event: tags_changed(tags=%r)', tags.keys())
     AudioListener.send('tags_changed', tags=tags.keys())
Beispiel #21
0
 def on_stream_changed(self, uri):
     gst_logger.debug('Got stream-changed message: uri=%s', uri)
     logger.debug('Audio event: stream_changed(uri=%s)', uri)
     AudioListener.send('stream_changed', uri=uri)
Beispiel #22
0
 def on_stream_changed(self, uri):
     gst_logger.debug("Got stream-changed message: uri=%s", uri)
     logger.debug("Audio event: stream_changed(uri=%s)", uri)
     AudioListener.send("stream_changed", uri=uri)
Beispiel #23
0
 def on_tag(self, taglist):
     tags = utils.convert_taglist(taglist)
     self._audio._tags.update(tags)
     logger.debug('Audio event: tags_changed(tags=%r)', tags.keys())
     AudioListener.send('tags_changed', tags=tags.keys())
Beispiel #24
0
 def _on_end_of_stream(self):
     logger.debug('Triggering reached_end_of_stream event')
     AudioListener.send('reached_end_of_stream')
Beispiel #25
0
 def on_end_of_stream(self):
     gst_logger.debug("Got end-of-stream message.")
     logger.debug("Audio event: reached_end_of_stream()")
     self._audio._tags = {}
     AudioListener.send("reached_end_of_stream")
Beispiel #26
0
 def on_stream_changed(self, uri):
     gst_logger.debug('Got stream-changed message: uri=%s', uri)
     logger.debug('Audio event: stream_changed(uri=%s)', uri)
     AudioListener.send('stream_changed', uri=uri)
Beispiel #27
0
 def on_end_of_stream(self):
     gst_logger.debug("Got EOS (end of stream) bus message.")
     logger.debug("Audio event: reached_end_of_stream()")
     self._audio._tags = {}
     AudioListener.send("reached_end_of_stream")
Beispiel #28
0
 def _on_end_of_stream(self):
     logger.debug('Triggering reached_end_of_stream event')
     AudioListener.send('reached_end_of_stream')
Beispiel #29
0
 def on_end_of_stream(self):
     gst_logger.debug('Got end-of-stream message.')
     logger.debug('Audio event: reached_end_of_stream()')
     self._audio._tags = {}
     AudioListener.send('reached_end_of_stream')