From 844dc257df5107c77253a7158ab60924c976d2e2 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 17 Dec 2015 22:02:56 +0100 Subject: [PATCH] audio: Don't bother creating decoders in audio scanner The decoders don't produce metadata and to the best of my knowledge we don't need the raw audio for duration calculation. But to play it safe this keeps in place the caps check in pad added to trigger 'have-audio'. --- mopidy/audio/scan.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mopidy/audio/scan.py b/mopidy/audio/scan.py index 188eb26c..c99d86ef 100644 --- a/mopidy/audio/scan.py +++ b/mopidy/audio/scan.py @@ -13,6 +13,17 @@ from mopidy import exceptions from mopidy.audio import utils from mopidy.internal import encoding +# GST_ELEMENT_FACTORY_LIST: +_DECODER = 1 << 0 +_AUDIO = 1 << 50 +_DEMUXER = 1 << 5 +_DEPAYLOADER = 1 << 8 +_PARSER = 1 << 6 + +# GST_TYPE_AUTOPLUG_SELECT_RESULT: +_SELECT_TRY = 0 +_SELECT_EXPOSE = 1 + _Result = collections.namedtuple( 'Result', ('uri', 'tags', 'duration', 'seekable', 'mime', 'playable')) @@ -85,6 +96,7 @@ def _setup_pipeline(uri, proxy_config=None): typefind.connect('have-type', _have_type, decodebin) decodebin.connect('pad-added', _pad_added, pipeline) + decodebin.connect('autoplug-select', _autoplug_select) return pipeline @@ -105,10 +117,21 @@ def _pad_added(element, pad, pipeline): pad.link(sink.get_static_pad('sink')) if pad.query_caps().is_subset(Gst.Caps.from_string('audio/x-raw')): + # Probably won't happen due to autoplug-select fix, but lets play it + # safe until we've tested more. struct = Gst.Structure.new_empty('have-audio') element.get_bus().post(Gst.Message.new_application(element, struct)) +def _autoplug_select(element, pad, caps, factory): + if factory.list_is_type(_DECODER | _AUDIO): + struct = Gst.Structure.new_empty('have-audio') + element.get_bus().post(Gst.Message.new_application(element, struct)) + if not factory.list_is_type(_DEMUXER | _DEPAYLOADER | _PARSER): + return _SELECT_EXPOSE + return _SELECT_TRY + + def _start_pipeline(pipeline): result = pipeline.set_state(Gst.State.PAUSED) if result == Gst.StateChangeReturn.NO_PREROLL: