]> git.parisson.com Git - timeside.git/commitdiff
timeside/encoder/mp3.py: use gstutils
authorPaul Brossier <piem@piem.org>
Thu, 27 Sep 2012 15:33:46 +0000 (09:33 -0600)
committerPaul Brossier <piem@piem.org>
Thu, 27 Sep 2012 15:33:46 +0000 (09:33 -0600)
timeside/encoder/mp3.py

index c1455e47ca62697f522dfa7ada14bac6c382cc57..f100b5bac2e9a631a3916cfc13f208d4f2019fb2 100644 (file)
@@ -27,7 +27,7 @@ from timeside.encoder.gstutils import *
 
 import mutagen
 
-class Mp3Encoder(Processor):
+class Mp3Encoder(GstEncoder):
     """ gstreamer-based mp3 encoder """
     implements(IEncoder)
 
@@ -46,10 +46,8 @@ class Mp3Encoder(Processor):
         
     @interfacedoc
     def setup(self, channels=None, samplerate=None, nframes=None):
-        self.channels = channels
         super(Mp3Encoder, self).setup(channels, samplerate, nframes)
-        #TODO: open file for writing
-        # the output data format we want        
+
         self.pipe = '''appsrc name=src
                   ! audioconvert 
                   ! lamemp3enc target=quality quality=2 encoding-engine-quality=standard ! id3v2mux 
@@ -64,21 +62,8 @@ class Mp3Encoder(Processor):
             self.pipe += '! filesink location=%s async=False sync=False ' % self.filename
         else:
             self.pipe += '! queue ! appsink name=app sync=False '
-            
-        self.pipeline = gst.parse_launch(self.pipe)
-        # store a pointer to appsrc in our encoder object
-        self.src = self.pipeline.get_by_name('src')
-        # store a pointer to appsink in our encoder object
-        self.app = self.pipeline.get_by_name('app')
-        
-        srccaps = gst.Caps("""audio/x-raw-float,
-            endianness=(int)1234,
-            channels=(int)%s,
-            width=(int)32,
-            rate=(int)%d""" % (int(channels), int(samplerate)))
-        self.src.set_property("caps", srccaps)
-        
-        self.pipeline.set_state(gst.STATE_PLAYING)
+
+        self.start_pipeline(channels, samplerate)
     
     @staticmethod
     @interfacedoc
@@ -124,17 +109,6 @@ class Mp3Encoder(Processor):
             id3.save()
         except:
             raise IOError('EncoderError: cannot write tags')
-    
-    @interfacedoc
-    def process(self, frames, eod=False):
-        self.eod = eod
-        buf = numpy_array_to_gst_buffer(frames)
-        self.src.emit('push-buffer', buf)
-        if self.streaming:
-            self.chunk = self.app.emit('pull-buffer')
-        if self.eod and self.metadata and self.filename:
-            self.write_metadata()
-        return frames, eod
         
 class Mp3EncoderSubprocess(object):
     """MP3 encoder in a subprocess pipe"""
@@ -260,4 +234,3 @@ class Mp3EncoderSubprocess(object):
         stream = self.core_process(command, source)
         for __chunk in stream:
             yield __chunk
-