]> git.parisson.com Git - timeside.git/commitdiff
timeside/decoder/file.py: use uridecodebin typefind for mime_type
authorPaul Brossier <piem@piem.org>
Mon, 3 Feb 2014 15:39:23 +0000 (12:39 -0300)
committerPaul Brossier <piem@piem.org>
Mon, 3 Feb 2014 15:39:23 +0000 (12:39 -0300)
tests/test_decoding.py
timeside/decoder/file.py

index c5459d02e975329de5409446b060e4265de5dc10..02bedffa6992c2ce70e39bcee219e69625ceadad 100755 (executable)
@@ -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):
index 4ecfdb82c1eda608a4fcf2fd7f4ef1034dc17b64..131c2df4e8240c4124f86429a7a10c36527b2f9a 100644 (file)
@@ -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()