From d516e9023ab8ee0894341c70c8c6a75a33e9959e Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 15 Nov 2012 22:49:44 +0100 Subject: [PATCH] Store active appsrc and refuse data when it is not set. We use the new source flag and the about to finish flags to set and unset the current appsrc. In emit data we now return false if the appsrc is not set. Also note that we need to use b'' for Gstreamer properties as it can't convert unicode to the correct type. I also added the signal disconnect code for about to finish. --- mopidy/audio/actor.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/mopidy/audio/actor.py b/mopidy/audio/actor.py index a17033ed..a23c4c43 100644 --- a/mopidy/audio/actor.py +++ b/mopidy/audio/actor.py @@ -42,8 +42,10 @@ class Audio(pykka.ThreadingActor): self._mixer = None self._mixer_track = None self._software_mixing = False + self._appsrc = None self._notify_source_signal_id = None + self._about_to_finish_id = None self._message_signal_id = None def on_start(self): @@ -67,9 +69,14 @@ class Audio(pykka.ThreadingActor): fakesink = gst.element_factory_make('fakesink') self._playbin.set_property('video-sink', fakesink) + self._about_to_finish_id = self._playbin.connect( + 'about-to-finish', self._on_about_to_finish) self._notify_source_signal_id = self._playbin.connect( 'notify::source', self._on_new_source) + def _on_about_to_finish(self, element): + self._appsrc = None + def _on_new_source(self, element, pad): uri = element.get_property('uri') if not uri or not uri.startswith('appsrc://'): @@ -82,8 +89,13 @@ class Audio(pykka.ThreadingActor): b'rate=(int)44100') source = element.get_property('source') source.set_property('caps', default_caps) + source.set_property('format', b'time') # Gstreamer does not like unicode + + self._appsrc = source def _teardown_playbin(self): + if self._about_to_finish_id: + self._playbin.disconnect(self._about_to_finish_id) if self._notify_source_signal_id: self._playbin.disconnect(self._notify_source_signal_id) self._playbin.set_state(gst.STATE_NULL) @@ -237,8 +249,9 @@ class Audio(pykka.ThreadingActor): :type buffer_: :class:`gst.Buffer` :rtype: boolean """ - source = self._playbin.get_property('source') - return source.emit('push-buffer', buffer_) == gst.FLOW_OK + if not self._appsrc: + return False + return self._appsrc.emit('push-buffer', buffer_) == gst.FLOW_OK def emit_end_of_stream(self): """