]> git.parisson.com Git - timeside.git/commitdiff
timeside/encoder/: factorise init function, raise IOError when trying to encode to...
authorPaul Brossier <piem@piem.org>
Mon, 28 Jan 2013 02:24:26 +0000 (20:24 -0600)
committerPaul Brossier <piem@piem.org>
Mon, 28 Jan 2013 02:24:26 +0000 (20:24 -0600)
tests/testencoding.py
timeside/encoder/core.py
timeside/encoder/flac.py
timeside/encoder/m4a.py
timeside/encoder/mp3.py
timeside/encoder/ogg.py
timeside/encoder/wav.py
timeside/encoder/webm.py

index e63138ebc6b45542146335fb221a921dcf0b8231..56ab7fa63a442c5ac8b9bf3d14d6d93e2f69987b 100644 (file)
@@ -5,7 +5,7 @@ from unit_timeside import *
 import os.path
 
 class TestEncoding(TestCase):
-    "Test the low level streaming features"
+    "Test encoding features"
 
     def setUp(self):
         self.samplerate, self.channels, self.blocksize = 44100, 1, 1024
@@ -74,37 +74,91 @@ class TestEncoding(TestCase):
             print commands.getoutput('sndfile-info ' + self.sink)
 
         self.assertEquals(written_frames, total_frames)
-        self.tmpfile.close()
+        if hasattr(self, 'tmpfile'): self.tmpfile.close()
 
 class TestEncodingLongBlock(TestEncoding):
+    "Test encoding features with longer blocksize"
 
     def setUp(self):
         super(TestEncodingLongBlock, self).setUp()
         self.blocksize *= 8
 
 class TestEncodingShortBlock(TestEncoding):
+    "Test encoding features with short blocksize"
 
     def setUp(self):
         super(TestEncodingShortBlock, self).setUp()
         self.blocksize = 64
 
 class TestEncodingLowSamplerate(TestEncoding):
+    "Test encoding features with low samplerate"
 
     def setUp(self):
         super(TestEncodingLowSamplerate, self).setUp()
         self.samplerate = 8000
 
 class TestEncodingHighSamplerate(TestEncoding):
+    "Test encoding features with high samplerate"
 
     def setUp(self):
         super(TestEncodingHighSamplerate, self).setUp()
         self.samplerate = 192000
 
 class TestEncodingStereo(TestEncoding):
+    "Test encoding features with stereo"
 
     def setUp(self):
         super(TestEncodingStereo, self).setUp()
         self.channels = 2
 
+class TestEncodingToDevNull(TestEncoding):
+    "Test encoding features with /dev/null"
+
+    def setUp(self):
+        self.samplerate, self.channels, self.blocksize = 44100, 1, 1024
+        self.sink = '/dev/null'
+
+class TestEncodingToDirectory(TestEncoding):
+    "Test encoding features to a directory"
+
+    def setUp(self):
+        self.samplerate, self.channels, self.blocksize = 44100, 1, 1024
+        import tempfile
+        self.sink = tempfile.mkdtemp()
+
+    def testWav(self):
+        "Test wav encoding"
+        from timeside.encoder.wav import WavEncoder
+        self.assertRaises(IOError,WavEncoder,self.sink)
+
+    def testVorbis(self):
+        "Test vorbis encoding"
+        from timeside.encoder.ogg import VorbisEncoder
+        self.assertRaises(IOError,VorbisEncoder,self.sink)
+
+    def testMp3(self):
+        "Test mp3 encoding"
+        from timeside.encoder.mp3 import Mp3Encoder
+        self.assertRaises(IOError,Mp3Encoder,self.sink)
+
+    def testAac(self):
+        "Test aac encoding"
+        from timeside.encoder.m4a import AacEncoder
+        self.assertRaises(IOError,AacEncoder,self.sink)
+
+    def testFlac(self):
+        "Test flac encoding"
+        from timeside.encoder.flac import FlacEncoder
+        self.assertRaises(IOError,FlacEncoder,self.sink)
+
+    def testWebm(self):
+        "Test webm encoding"
+        from timeside.encoder.webm import WebMEncoder
+        self.assertRaises(IOError,WebMEncoder,self.sink)
+
+    def tearDown(self):
+        from os import rmdir
+        rmdir(self.sink)
+
 if __name__ == '__main__':
     unittest.main(testRunner=TestRunner())
index d6560843402ae7a6e3b4d1be937ccd9d782758e2..7718143c0ebb1deb0a011516fc7ba9ecaaaed8d4 100644 (file)
@@ -26,6 +26,22 @@ from timeside.tools import *
 
 class GstEncoder(Processor):
 
+    def __init__(self, output, streaming = False):
+        if isinstance(output, basestring):
+            import os.path
+            if os.path.isdir(output):
+                raise IOError("Encoder output must be a file, not a directory")
+            self.filename = output
+        else:
+            self.filename = None
+        self.streaming = streaming
+
+        if not self.filename and not self.streaming:
+            raise Exception('Must give an output')
+
+        self.eod = False
+        self.metadata = None
+
     def release(self):
         pass
 
index e9c488f3438a3809b1faa27f8c6e6f87fdf53897..e35dfaae651bf70118784917b32da031080e708d 100644 (file)
@@ -29,18 +29,6 @@ class FlacEncoder(GstEncoder):
     """ gstreamer-based FLAC encoder """
     implements(IEncoder)
 
-    def __init__(self, output,  streaming=False):
-        if isinstance(output, basestring):
-            self.filename = output
-        else:
-            self.filename = None
-        self.streaming = streaming
-
-        if not self.filename and not self.streaming:
-            raise Exception('Must give an output')
-
-        self.eod = False
-
     @interfacedoc
     def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
         super(FlacEncoder, self).setup(channels, samplerate, blocksize, totalframes)
index 311456761d98a75626b84c36d835fc6bc67a20ea..b0c65ecfccf2f4017b598350fb765984eea78f14 100644 (file)
@@ -29,11 +29,9 @@ class AacEncoder(GstEncoder):
     """ gstreamer-based AAC encoder """
     implements(IEncoder)
 
-    def __init__(self, output):
-        self.file = None
-        if isinstance(output, basestring):
-            self.filename = output
-        else:
+    def __init__(self, output, streaming = False):
+        super(AacEncoder, self).__init__(output, streaming)
+        if self.streaming:
             raise Exception("Streaming not supported")
 
     @interfacedoc
index f2ce3d9ef4f6c3322a974bb928a31378ccf7d821..3056d47ea9562c9f8c0dab85aebf3cd37a2e13ac 100644 (file)
@@ -35,19 +35,6 @@ class Mp3Encoder(GstEncoder):
     """ gstreamer-based mp3 encoder """
     implements(IEncoder)
 
-    def __init__(self, output, streaming=False):
-        if isinstance(output, basestring):
-            self.filename = output
-        else:
-            self.filename = None
-
-        self.streaming = streaming
-        if not self.filename and not self.streaming:
-            raise Exception('Must give an output')
-
-        self.metadata = None
-        self.eod = False
-
     @interfacedoc
     def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
         super(Mp3Encoder, self).setup(channels, samplerate, blocksize, totalframes)
index f222c4e2820283f5d3d4a1dddba266bbb73874a0..b834e15f665f72da97070e0774e10f035c475f3b 100644 (file)
@@ -28,18 +28,6 @@ class VorbisEncoder(GstEncoder):
     """ gstreamer-based vorbis encoder """
     implements(IEncoder)
 
-    def __init__(self, output,  streaming=False):
-        if isinstance(output, basestring):
-            self.filename = output
-        else:
-            self.filename = None
-        self.streaming = streaming
-
-        if not self.filename and not self.streaming:
-            raise Exception('Must give an output')
-
-        self.eod = False
-
     @interfacedoc
     def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
         super(VorbisEncoder, self).setup(channels, samplerate, blocksize, totalframes)
index e898d8a37ac41b22d2f18d789213fa763c5f6ae4..32666e78a8142747be891fcb798fb90779f7cd8a 100644 (file)
@@ -30,18 +30,6 @@ class WavEncoder(GstEncoder):
     """ gstreamer-based encoder """
     implements(IEncoder)
 
-    def __init__(self, output,  streaming=False):
-        if isinstance(output, basestring):
-            self.filename = output
-        else:
-            self.filename = None
-        self.streaming = streaming
-
-        if not self.filename and not self.streaming:
-            raise Exception('Must give an output')
-
-        self.eod = False
-
     @interfacedoc
     def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
         super(WavEncoder, self).setup(channels, samplerate, blocksize, totalframes)
index d228e9b91fba5e228f89980407b0382595278506..3b1dd60a64b101036f29d4f4e37d261d4807e0f9 100644 (file)
@@ -29,18 +29,9 @@ class WebMEncoder(GstEncoder):
     """ gstreamer-based webm encoder and muxer """
     implements(IEncoder)
 
-    def __init__(self, output,  streaming=False, video=False):
-        if isinstance(output, basestring):
-            self.filename = output
-        else:
-            self.filename = None
-        self.streaming = streaming
-
-        if not self.filename and not self.streaming:
-            raise Exception('Must give an output')
-
+    def __init__(self, output, streaming = False):
+        super(WebMEncoder, self).__init__(output, streaming)
         self.video = False
-        self.eod = False
 
     @interfacedoc
     def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):