]> git.parisson.com Git - timeside.git/commitdiff
Encoder: live AudioSink encoder, encoder that plays the audio stream through the...
authorThomas Fillon <thomas@parisson.com>
Thu, 9 Jan 2014 10:48:00 +0000 (11:48 +0100)
committerThomas Fillon <thomas@parisson.com>
Thu, 9 Jan 2014 10:48:00 +0000 (11:48 +0100)
doc/source/api/encoder/index.rst
timeside/encoder/__init__.py
timeside/encoder/audiosink.py [new file with mode: 0644]

index 6ec39f37ea33f70bdd71c61c1f0ab62664fb9186..fbe4af33da36645b59217c42da49974ae2152c93 100644 (file)
@@ -53,3 +53,10 @@ WebM encoder
 
 .. automodule:: timeside.encoder.webm
    :members:
+
+
+AudioSink encoder
+------------
+
+.. automodule:: timeside.encoder.audiosink
+   :members:
index 7b0335442a32317fed2f5b45e0facfe9d6950461..37cd6b6066d9337c2ea3484ad041ddf71ac25017 100644 (file)
@@ -6,3 +6,4 @@ from mp3 import Mp3Encoder
 from flac import FlacEncoder
 from m4a import AacEncoder
 from webm import WebMEncoder
+from audiosink import AudioSink
\ No newline at end of file
diff --git a/timeside/encoder/audiosink.py b/timeside/encoder/audiosink.py
new file mode 100644 (file)
index 0000000..f60d128
--- /dev/null
@@ -0,0 +1,103 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2007-2014 Guillaume Pellerin <yomguy@parisson.com>
+# Copyright (c) 2013-2014 Thomas Fillon <thomas.fillon@parisson.com>
+
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Thomas Fillon <thomas.fillon@parisson.com>
+
+from timeside.core import implements, interfacedoc
+from timeside.encoder.core import GstEncoder
+from timeside.api import IEncoder
+from timeside.tools import *
+
+
+class AudioSink(GstEncoder):
+    """
+    gstreamer-based Audio Sink
+
+    This encoder plays the decoded audio stream to the sound card
+
+
+    >>> import timeside
+    >>> wavfile = 'https://github.com/yomguy/timeside-samples/raw/master/samples/guitar.wav'
+    >>> d = timeside.decoder.FileDecoder(wavfile)
+    >>> e = timeside.encoder.AudioSink()
+    >>> (d|e).run() # doctest: +SKIP
+    """
+
+    implements(IEncoder)
+
+    def __init__(self, output_sink='autoaudiosink'):
+        """
+        """
+        super(GstEncoder, self).__init__()
+        self.streaming = False
+
+        self.output_sink = output_sink
+
+        import threading
+        self.end_cond = threading.Condition(threading.Lock())
+
+        self.eod = False
+        self.metadata = None
+        self.num_samples = 0
+
+    @interfacedoc
+    def setup(self, channels=None, samplerate=None, blocksize=None,
+              totalframes=None):
+        super(AudioSink, self).setup(channels, samplerate, blocksize,
+                                     totalframes)
+
+        self.pipe = ''' appsrc name=src ! audioconvert
+                        ! %s ''' % self.output_sink
+
+        self.start_pipeline(channels, samplerate)
+
+    @staticmethod
+    @interfacedoc
+    def id():
+        return "gst_audio_sink_enc"
+
+    @staticmethod
+    @interfacedoc
+    def description():
+        return "GStreamer based audio sink encoder"
+
+    @staticmethod
+    @interfacedoc
+    def format():
+        return ""
+
+    @staticmethod
+    @interfacedoc
+    def file_extension():
+        return ""
+
+    @staticmethod
+    @interfacedoc
+    def mime_type():
+        return 'audio/x-raw'
+
+    @interfacedoc
+    def set_metadata(self, metadata):
+        self.metadata = metadata
+
+
+if __name__ == "__main__":
+    import doctest
+    doctest.testmod()
\ No newline at end of file