From c93eaad7ed53e9175a5b88636c1009ca10ae7804 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 12 Mar 2015 00:16:02 +0100 Subject: [PATCH] audio: Try and reuse source when we can --- mopidy/audio/scan.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/mopidy/audio/scan.py b/mopidy/audio/scan.py index 359f31cf..87e60076 100644 --- a/mopidy/audio/scan.py +++ b/mopidy/audio/scan.py @@ -73,11 +73,21 @@ class Scanner(object): def _setup(self, uri): """Primes the pipeline for collection.""" - self._src = gst.element_make_from_uri(gst.URI_SRC, uri) - utils.setup_proxy(self._src, self._proxy_config) - self._pipe.add(self._src) - self._src.sync_state_with_parent() - self._src.link(self._decodebin) + protocol = gst.uri_get_protocol(uri) + if self._src and protocol not in self._src.get_protocols(): + self._src.unlink(self._decodebin) + self._pipe.remove(self._src) + self._src = None + + if not self._src: + self._src = gst.element_make_from_uri(gst.URI_SRC, uri) + utils.setup_proxy(self._src, self._proxy_config) + self._pipe.add(self._src) + self._src.sync_state_with_parent() + self._src.link(self._decodebin) + + self._pipe.set_state(gst.STATE_READY) + self._src.set_uri(uri) result = self._pipe.set_state(gst.STATE_PAUSED) if result == gst.STATE_CHANGE_NO_PREROLL: @@ -115,11 +125,7 @@ class Scanner(object): raise exceptions.ScannerError('Timeout after %dms' % self._timeout_ms) def _reset(self): - """Ensures we cleanup child elements.""" self._pipe.set_state(gst.STATE_NULL) - self._src.unlink(self._decodebin) - self._pipe.remove(self._src) - self._src = None def _query_duration(self): try: