]> git.parisson.com Git - timeside.git/commitdiff
mv gstutils to timeside.gstutils, mv GstEncoder to encoder.core
authoryomguy <yomguy@parisson.com>
Fri, 5 Oct 2012 22:13:41 +0000 (00:13 +0200)
committeryomguy <yomguy@parisson.com>
Fri, 5 Oct 2012 22:13:41 +0000 (00:13 +0200)
timeside/decoder/core.py
timeside/encoder/core.py
timeside/encoder/flac.py
timeside/encoder/gstutils.py [deleted file]
timeside/encoder/m4a.py
timeside/encoder/mp3.py
timeside/encoder/ogg.py
timeside/encoder/wav.py
timeside/encoder/webm.py
timeside/gstutils.py [new file with mode: 0644]

index 6e52d44ba7dec20b4f3d01cb51015e34b1b45be8..5feae444456b58e0f999d7586837f82b19634615 100644 (file)
@@ -26,7 +26,7 @@
 
 from timeside.core import Processor, implements, interfacedoc
 from timeside.api import IDecoder
-from timeside.encoder.gstutils import *
+from timeside.gstutils import *
 
 import Queue
 
index cfac24cde20b31426c538ef0ef2b20b5ce77aba1..dc2d68c3948366192485de0e4d0eae5c3d14a5e6 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 #
-# Copyright (c) 2007-2009 Guillaume Pellerin <yomguy@parisson.com>
+# Copyright (c) 2012 Paul Brossier <piem@piem.org>
 
 # This file is part of TimeSide.
 
 # You should have received a copy of the GNU General Public License
 # along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
 
-# Author: Guillaume Pellerin <yomguy@parisson.com>
+
+from timeside.core import Processor, implements, interfacedoc
+from timeside.api import IEncoder
+from timeside.gstutils import *
+
+
+class GstEncoder(Processor):
+
+    def release(self):
+        while self.bus.have_pending():
+          self.bus.pop()
+
+    def __del__(self):
+        self.release()
+
+    def start_pipeline(self, channels, samplerate):
+        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.src.set_property('emit-signals', True)
+
+        self.bus = self.pipeline.get_bus()
+        self.bus.add_signal_watch()
+        self.bus.connect("message", self.on_message)
+
+        # start pipeline
+        self.pipeline.set_state(gst.STATE_PLAYING)
+
+    def on_message(self, bus, message):
+        t = message.type
+        if t == gst.MESSAGE_EOS:
+            self.pipeline.set_state(gst.STATE_NULL)
+        elif t == gst.MESSAGE_ERROR:
+            self.pipeline.set_state(gst.STATE_NULL)
+            err, debug = message.parse_error()
+            print "Error: %s" % err, debug
+
+    def process(self, frames, eod=False):
+        self.eod = eod
+        buf = numpy_array_to_gst_buffer(frames)
+        self.src.emit('push-buffer', buf)
+        if self.eod:
+            self.src.emit('end-of-stream')
+        if self.streaming:
+            self.chunk = self.app.emit('pull-buffer')
+        return frames, eod
 
 from timeside.core import *
 import subprocess
index aec60be25474482098f25decaeb6bb261003a919..df225525d87d9fec71b67863a2edcff994a9c7fb 100644 (file)
@@ -21,7 +21,8 @@
 
 from timeside.core import Processor, implements, interfacedoc
 from timeside.api import IEncoder
-from timeside.encoder.gstutils import *
+from timeside.gstutils import *
+
 
 class FlacEncoder(GstEncoder):
     """ gstreamer-based FLAC encoder """
@@ -33,31 +34,31 @@ class FlacEncoder(GstEncoder):
         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, nframes=None):
         super(FlacEncoder, self).setup(channels, samplerate, nframes)
         # TODO open file for writing
-        # the output data format we want        
-        self.pipe = ''' appsrc name=src ! audioconvert 
+        # the output data format we want
+        self.pipe = ''' appsrc name=src ! audioconvert
                         ! flacenc '''
-                        
-        if self.filename and self.streaming:            
+
+        if self.filename and self.streaming:
             self.pipe += ''' ! tee name=t
             ! queue ! filesink location=%s
             t. ! queue ! appsink name=app sync=False
             ''' % self.filename
-            
+
         elif self.filename :
             self.pipe += '! filesink location=%s ' % self.filename
         else:
             self.pipe += '! appsink name=app sync=False '
-            
+
         self.start_pipeline(channels, samplerate)
 
     @staticmethod
diff --git a/timeside/encoder/gstutils.py b/timeside/encoder/gstutils.py
deleted file mode 100644 (file)
index 5532f02..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-from timeside.core import Processor, implements, interfacedoc
-from timeside.api import IEncoder
-
-from numpy import array, getbuffer, frombuffer
-
-import pygst
-pygst.require('0.10')
-import gst
-import gobject
-
-gobject.threads_init()
-
-def numpy_array_to_gst_buffer(frames):
-    """ gstreamer buffer to numpy array conversion """
-    buf = gst.Buffer(getbuffer(frames.astype("float32")))
-    return buf
-
-def gst_buffer_to_numpy_array(buf, chan):
-    """ gstreamer buffer to numpy array conversion """
-    samples = frombuffer(buf.data, dtype='float32')
-    samples.resize([len(samples)/chan, chan])
-    return samples
-
-class GstEncoder(Processor):
-
-    def release(self):
-        while self.bus.have_pending():
-          self.bus.pop()
-
-    def __del__(self):
-        self.release()
-
-    def start_pipeline(self, channels, samplerate):
-        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.src.set_property('emit-signals', True)
-
-        self.bus = self.pipeline.get_bus()
-        self.bus.add_signal_watch()
-        self.bus.connect("message", self.on_message)
-
-        # start pipeline
-        self.pipeline.set_state(gst.STATE_PLAYING)
-
-    def on_message(self, bus, message):
-        t = message.type
-        if t == gst.MESSAGE_EOS:
-            self.pipeline.set_state(gst.STATE_NULL)
-        elif t == gst.MESSAGE_ERROR:
-            self.pipeline.set_state(gst.STATE_NULL)
-            err, debug = message.parse_error()
-            print "Error: %s" % err, debug
-
-    def process(self, frames, eod=False):
-        self.eod = eod
-        buf = numpy_array_to_gst_buffer(frames)
-        self.src.emit('push-buffer', buf)
-        if self.eod:
-            self.src.emit('end-of-stream')
-        if self.streaming:
-            self.chunk = self.app.emit('pull-buffer')
-        return frames, eod
index 357cd4882e36c85df18c43ba1914400636a1d56f..d2c07efbcf551ca9454d29f26d54f9d12f7bf34c 100644 (file)
@@ -21,7 +21,8 @@
 
 from timeside.core import Processor, implements, interfacedoc
 from timeside.api import IEncoder
-from timeside.encoder.gstutils import *
+from timeside.gstutils import *
+
 
 class AacEncoder(GstEncoder):
     """ gstreamer-based AAC encoder """
index c59cc57dd03cb7fe3394b67dac29c38ebd83a91c..d549ee82dc16b1f980a40be4f787bb505c7172b2 100644 (file)
@@ -23,7 +23,7 @@
 
 from timeside.core import Processor, implements, interfacedoc
 from timeside.api import IEncoder
-from timeside.encoder.gstutils import *
+from timeside.gstutils import *
 
 import mutagen
 
@@ -64,7 +64,7 @@ class Mp3Encoder(GstEncoder):
             self.pipe += '! queue ! appsink name=app sync=False '
 
         self.start_pipeline(channels, samplerate)
-    
+
     @staticmethod
     @interfacedoc
     def id():
index 113eaba2328fbc84fe7d6eced9749099e2fe1375..c45c8b07fa60ff99b9f589a533e28b7943a62d58 100644 (file)
@@ -21,7 +21,7 @@
 
 from timeside.core import Processor, implements, interfacedoc
 from timeside.api import IEncoder
-from timeside.encoder.gstutils import *
+from timeside.gstutils import *
 
 class VorbisEncoder(GstEncoder):
     """ gstreamer-based vorbis encoder """
@@ -33,19 +33,19 @@ class VorbisEncoder(GstEncoder):
         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, nframes=None):
         super(VorbisEncoder, self).setup(channels, samplerate, nframes)
         # TODO open file for writing
-        # the output data format we want        
+        # the output data format we want
         self.pipe = ''' appsrc name=src
-                  ! audioconvert 
+                  ! audioconvert
                   ! vorbisenc
                   ! oggmux
                   '''
@@ -54,12 +54,12 @@ class VorbisEncoder(GstEncoder):
             ! queue ! filesink location=%s
             t. ! queue ! appsink name=app sync=False
             ''' % self.filename
-            
+
         elif self.filename :
             self.pipe += '! filesink async=True location=%s ' % self.filename
         else:
             self.pipe += '! appsink name=app sync=False '
-            
+
         # start pipeline
         self.start_pipeline(channels, samplerate)
 
index 239d23867a212056419c76f598cbc919798f71fa..d088841e891ce22de258201d63a1cd8bdeaa870b 100644 (file)
@@ -22,7 +22,8 @@
 
 from timeside.core import Processor, implements, interfacedoc
 from timeside.api import IEncoder
-from timeside.encoder.gstutils import *
+from timeside.gstutils import *
+
 
 class WavEncoder(GstEncoder):
     """ gstreamer-based encoder """
@@ -34,19 +35,19 @@ class WavEncoder(GstEncoder):
         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, nframes=None):
         super(WavEncoder, self).setup(channels, samplerate, nframes)
         # TODO open file for writing
         # the output data format we want
         self.pipe = ''' appsrc name=src
-                  ! audioconvert 
+                  ! audioconvert
                   ! wavenc
                   '''
         if self.filename and self.streaming:
@@ -54,15 +55,15 @@ class WavEncoder(GstEncoder):
             ! queue ! filesink location=%s
             t. ! queue ! appsink name=app sync=False
             ''' % self.filename
-            
+
         elif self.filename :
             self.pipe += '! filesink location=%s ' % self.filename
         else:
             self.pipe += '! appsink name=app sync=False'
-            
+
         # start pipeline
         self.start_pipeline(channels, samplerate)
-        
+
     @staticmethod
     @interfacedoc
     def id():
index c3aab8b585874720e59c8d9ef6b7ae0e95728377..a16248296e33622aa8f675be55689bc769f04d45 100644 (file)
@@ -21,7 +21,8 @@
 
 from timeside.core import Processor, implements, interfacedoc
 from timeside.api import IEncoder
-from timeside.encoder.gstutils import *
+from timeside.gstutils import *
+
 
 class WebMEncoder(GstEncoder):
     """ gstreamer-based webm encoder and muxer """
diff --git a/timeside/gstutils.py b/timeside/gstutils.py
new file mode 100644 (file)
index 0000000..5532f02
--- /dev/null
@@ -0,0 +1,72 @@
+from timeside.core import Processor, implements, interfacedoc
+from timeside.api import IEncoder
+
+from numpy import array, getbuffer, frombuffer
+
+import pygst
+pygst.require('0.10')
+import gst
+import gobject
+
+gobject.threads_init()
+
+def numpy_array_to_gst_buffer(frames):
+    """ gstreamer buffer to numpy array conversion """
+    buf = gst.Buffer(getbuffer(frames.astype("float32")))
+    return buf
+
+def gst_buffer_to_numpy_array(buf, chan):
+    """ gstreamer buffer to numpy array conversion """
+    samples = frombuffer(buf.data, dtype='float32')
+    samples.resize([len(samples)/chan, chan])
+    return samples
+
+class GstEncoder(Processor):
+
+    def release(self):
+        while self.bus.have_pending():
+          self.bus.pop()
+
+    def __del__(self):
+        self.release()
+
+    def start_pipeline(self, channels, samplerate):
+        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.src.set_property('emit-signals', True)
+
+        self.bus = self.pipeline.get_bus()
+        self.bus.add_signal_watch()
+        self.bus.connect("message", self.on_message)
+
+        # start pipeline
+        self.pipeline.set_state(gst.STATE_PLAYING)
+
+    def on_message(self, bus, message):
+        t = message.type
+        if t == gst.MESSAGE_EOS:
+            self.pipeline.set_state(gst.STATE_NULL)
+        elif t == gst.MESSAGE_ERROR:
+            self.pipeline.set_state(gst.STATE_NULL)
+            err, debug = message.parse_error()
+            print "Error: %s" % err, debug
+
+    def process(self, frames, eod=False):
+        self.eod = eod
+        buf = numpy_array_to_gst_buffer(frames)
+        self.src.emit('push-buffer', buf)
+        if self.eod:
+            self.src.emit('end-of-stream')
+        if self.streaming:
+            self.chunk = self.app.emit('pull-buffer')
+        return frames, eod