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
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())
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
""" 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)
""" 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
""" 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)
""" 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)
""" 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)
""" 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):