From: Paul Brossier Date: Mon, 3 Feb 2014 15:39:23 +0000 (-0300) Subject: timeside/decoder/file.py: use uridecodebin typefind for mime_type X-Git-Tag: 0.5.4~15^2~2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=2b5122586544f1de3c7a72cd8dee6e930e6c91b3;p=timeside.git timeside/decoder/file.py: use uridecodebin typefind for mime_type --- diff --git a/tests/test_decoding.py b/tests/test_decoding.py index c5459d0..02bedff 100755 --- a/tests/test_decoding.py +++ b/tests/test_decoding.py @@ -56,7 +56,7 @@ class TestDecoding(unittest.TestCase): "Test flac decoding" self.source = os.path.join(os.path.dirname(__file__), "samples/sweep.flac") - self.expected_mime_type = 'audio/flac' + self.expected_mime_type = 'audio/x-flac' def testOgg(self): "Test ogg decoding" @@ -64,7 +64,7 @@ class TestDecoding(unittest.TestCase): "samples/sweep.ogg") self.expected_totalframes = 352832 - self.expected_mime_type = 'audio/ogg' + self.expected_mime_type = 'application/ogg' self.test_exact_duration = False def testMp3(self): diff --git a/timeside/decoder/file.py b/timeside/decoder/file.py index 4ecfdb8..131c2df 100644 --- a/timeside/decoder/file.py +++ b/timeside/decoder/file.py @@ -71,6 +71,8 @@ class FileDecoder(Decoder): self.uri = get_uri(uri) self.uri_total_duration = get_media_uri_info(self.uri)['duration'] + self.mimetype = None + def setup(self, channels=None, samplerate=None, blocksize=None): self.eod = False @@ -148,6 +150,12 @@ class FileDecoder(Decoder): rate=(int)%s""" % (caps_channels, caps_samplerate)) self.src = self.pipeline.get_by_name('src') + if not self.is_segment: + self.src.connect("autoplug-continue", self._autoplug_cb) + else: + uridecodebin = self.src.get_by_name('internal-uridecodebin') + uridecodebin.connect("autoplug-continue", self._autoplug_cb) + self.conv = self.pipeline.get_by_name('audioconvert') self.conv.get_pad("sink").connect("notify::caps", self._notify_caps_cb) @@ -194,6 +202,13 @@ class FileDecoder(Decoder): else: raise IOError('no known audio stream found') + def _autoplug_cb(self, src, arg0, arg1): + # use the autoplug-continue callback from uridecodebin + # to get the mimetype string + if not self.mimetype: + self.mimetype = arg1.to_string().split(',')[0] + return True + def _notify_caps_cb(self, pad, args): self.discovered_cond.acquire() @@ -233,8 +248,6 @@ class FileDecoder(Decoder): self.input_width = caps[0]["width"] else: self.input_width = caps[0]["depth"] - import mimetypes - self.mimetype = mimetypes.guess_type(self.uri)[0] self.discovered = True self.discovered_cond.notify()