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")
def gstreamer_info(): other = [] other.append(f"Python wrapper: python-gi {gi.__version__}") found_elements = [] missing_elements = [] for name, status in _gstreamer_check_elements(): if status: found_elements.append(name) else: missing_elements.append(name) other.append("Relevant elements:") other.append(" Found:") for element in found_elements: other.append(f" {element}") if not found_elements: other.append(" none") other.append(" Not found:") for element in missing_elements: other.append(f" {element}") if not missing_elements: other.append(" none") return { "name": "GStreamer", "version": ".".join(map(str, Gst.version())), "path": os.path.dirname(gi.__file__), "other": "\n".join(other), }
def gstreamer_info(): other = [] other.append('Python wrapper: python-gi %s' % gi.__version__) found_elements = [] missing_elements = [] for name, status in _gstreamer_check_elements(): if status: found_elements.append(name) else: missing_elements.append(name) other.append('Relevant elements:') other.append(' Found:') for element in found_elements: other.append(' %s' % element) if not found_elements: other.append(' none') other.append(' Not found:') for element in missing_elements: other.append(' %s' % element) if not missing_elements: other.append(' none') return { 'name': 'GStreamer', 'version': '.'.join(map(str, Gst.version())), 'path': os.path.dirname(gi.__file__), 'other': '\n'.join(other), }
def test_gstreamer_info(self): result = deps.gstreamer_info() assert "GStreamer" == result["name"] assert ".".join(map(str, Gst.version())) == result["version"] assert "gi" in result["path"] assert "__init__.py" not in result["path"] assert "Python wrapper: python-gi" in result["other"] assert gi.__version__ in result["other"] assert "Relevant elements:" in result["other"]
def test_gstreamer_info(self): result = deps.gstreamer_info() self.assertEqual('GStreamer', result['name']) self.assertEqual('.'.join(map(str, Gst.version())), result['version']) self.assertIn('gi', result['path']) self.assertNotIn('__init__.py', result['path']) self.assertIn('Python wrapper: python-gi', result['other']) self.assertIn(gi.__version__, result['other']) self.assertIn('Relevant elements:', result['other'])
def test_gstreamer_info(self): result = deps.gstreamer_info() self.assertEqual('GStreamer', result['name']) self.assertEqual( '.'.join(map(str, Gst.version())), result['version']) self.assertIn('gi', result['path']) self.assertNotIn('__init__.py', result['path']) self.assertIn('Python wrapper: python-gi', result['other']) self.assertIn(gi.__version__, result['other']) self.assertIn('Relevant elements:', result['other'])
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')
def add_output(self, description): # XXX This only works for pipelines not in use until #790 gets done. try: output = Gst.parse_bin_from_description(description, ghost_unlinked_pads=True) except GObject.GError as ex: logger.error('Failed to create audio output "%s": %s', description, ex) raise exceptions.AudioException(bytes(ex)) self._add(output) logger.info('Audio output set to "%s"', description)
def add_output(self, description): # XXX This only works for pipelines not in use until #790 gets done. try: output = Gst.parse_bin_from_description( description, ghost_unlinked_pads=True) except GObject.GError as ex: logger.error( 'Failed to create audio output "%s": %s', description, ex) raise exceptions.AudioException(bytes(ex)) self._add(output) logger.info('Audio output set to "%s"', description)
timeout = timeout_ms - (int(time.time() * 1000) - start) raise exceptions.ScannerError('Timeout after %dms' % timeout_ms) if __name__ == '__main__': import os import sys from mopidy.internal import path logging.basicConfig(format='%(asctime)-15s %(levelname)s %(message)s', level=log.TRACE_LOG_LEVEL) scanner = Scanner(5000) for uri in sys.argv[1:]: if not Gst.uri_is_valid(uri): uri = path.path_to_uri(os.path.abspath(uri)) try: result = scanner.scan(uri) for key in ('uri', 'mime', 'duration', 'playable', 'seekable'): print('%-20s %s' % (key, getattr(result, key))) print('tags') for tag, value in result.tags.items(): line = '%-20s %s' % (tag, value) if len(line) > 77: line = line[:77] + '...' print(line) except exceptions.ScannerError as error: print('%s: %s' % (uri, error))
timeout = timeout_ms - (int(time.time() * 1000) - start) # workaround for https://bugzilla.gnome.org/show_bug.cgi?id=763553: # if we got what we want then stop playing (and wait for ASYNC_DONE) if tags and duration is not None: pipeline.set_state(Gst.State.PAUSED) raise exceptions.ScannerError('Timeout after %dms' % timeout_ms) if __name__ == '__main__': import os import sys from mopidy.internal import path scanner = Scanner(5000) for uri in sys.argv[1:]: if not Gst.uri_is_valid(uri): uri = path.path_to_uri(os.path.abspath(uri)) try: result = scanner.scan(uri) for key in ('uri', 'mime', 'duration', 'playable', 'seekable'): print('%-20s %s' % (key, getattr(result, key))) print('tags') for tag, value in result.tags.items(): print('%-20s %s' % (tag, value)) except exceptions.ScannerError as error: print('%s: %s' % (uri, error))
def calculate_duration(num_samples, sample_rate): """Determine duration of samples using GStreamer helper for precise math.""" return Gst.util_uint64_scale(num_samples, Gst.SECOND, sample_rate)