]> git.parisson.com Git - timeside.git/commitdiff
Put MainloopThread in gstutils
authorThomas Fillon <thomas@parisson.com>
Fri, 14 Feb 2014 10:06:39 +0000 (11:06 +0100)
committerThomas Fillon <thomas@parisson.com>
Fri, 14 Feb 2014 10:06:39 +0000 (11:06 +0100)
timeside/decoder/file.py
timeside/decoder/live.py
timeside/encoder/core.py
timeside/tools/gstutils.py

index 7af59dfede4c388b661d2429629a2f71aaefb325..3a9483a7ded4c9cd1dc0bf5f9877e7e430cebff9 100644 (file)
@@ -29,7 +29,8 @@
 from __future__ import division
 
 from timeside.decoder.core import *
-
+from timeside.tools.gstutils import MainloopThread
+import threading
 
 class FileDecoder(Decoder):
     """ gstreamer-based decoder """
@@ -99,7 +100,6 @@ class FileDecoder(Decoder):
                                         given the media duration""")
 
         # a lock to wait wait for gstreamer thread to be ready
-        import threading
         self.discovered_cond = threading.Condition(threading.Lock())
         self.discovered = False
 
@@ -172,15 +172,6 @@ class FileDecoder(Decoder):
 
         self.queue = Queue.Queue(QUEUE_SIZE)
 
-        import threading
-
-        class MainloopThread(threading.Thread):
-            def __init__(self, mainloop):
-                threading.Thread.__init__(self)
-                self.mainloop = mainloop
-
-            def run(self):
-                self.mainloop.run()
         self.mainloop = gobject.MainLoop()
         self.mainloopthread = MainloopThread(self.mainloop)
         self.mainloopthread.start()
index e5c355fc6631badc9aee7e30595603bd071ea8a5..fdb596b7a1291ee8ed50a74b30a220f2beb3305c 100644 (file)
@@ -29,6 +29,7 @@
 from __future__ import division
 
 from timeside.decoder.core import *
+from timeside.tools.gstutils import MainloopThread
 
 
 class LiveDecoder(Decoder):
@@ -143,15 +144,6 @@ class LiveDecoder(Decoder):
 
         self.queue = Queue.Queue(QUEUE_SIZE)
 
-        import threading
-
-        class MainloopThread(threading.Thread):
-            def __init__(self, mainloop):
-                threading.Thread.__init__(self)
-                self.mainloop = mainloop
-
-            def run(self):
-                self.mainloop.run()
         self.mainloop = gobject.MainLoop()
         self.mainloopthread = MainloopThread(self.mainloop)
         self.mainloopthread.start()
index f89acc3798670f6efd5adfb180451a604472b0da..db34c41a8908b654473241435a3fb4833c64b406 100644 (file)
@@ -25,7 +25,7 @@
 from timeside.core import Processor, implements, interfacedoc
 from timeside.component import abstract
 from timeside.api import IEncoder
-from timeside.tools import numpy_array_to_gst_buffer
+from timeside.tools import numpy_array_to_gst_buffer, MainloopThread
 
 #from gst import _gst as gst
 import pygst
@@ -35,6 +35,8 @@ import gst
 import gobject
 gobject.threads_init()
 
+import threading
+
 # Streaming queue configuration
 QUEUE_SIZE = 10
 GST_APPSINK_MAX_BUFFERS = 10
@@ -62,7 +64,6 @@ class GstEncoder(Processor):
         if not self.filename and not self.streaming:
             raise Exception('Must give an output')
 
-        import threading
         self.end_cond = threading.Condition(threading.Lock())
 
         self.eod = False
@@ -115,15 +116,6 @@ class GstEncoder(Processor):
         self.bus.add_signal_watch()
         self.bus.connect("message", self._on_message_cb)
 
-        import threading
-
-        class MainloopThread(threading.Thread):
-            def __init__(self, mainloop):
-                threading.Thread.__init__(self)
-                self.mainloop = mainloop
-
-            def run(self):
-                self.mainloop.run()
         self.mainloop = gobject.MainLoop()
         self.mainloopthread = MainloopThread(self.mainloop)
         self.mainloopthread.start()
index c5605f4d177f7c75e688f1b54031f213cbd7062f..2722085c297ceeaef77ef5ec2ff3c7691f420ec5 100644 (file)
@@ -1,4 +1,4 @@
-from numpy import array, getbuffer, frombuffer
+from numpy import getbuffer, frombuffer
 
 import pygst
 pygst.require('0.10')
@@ -6,6 +6,8 @@ import gst
 import gobject
 gobject.threads_init()
 
+import threading
+
 
 def numpy_array_to_gst_buffer(frames, CHUNK_SIZE, num_samples, SAMPLE_RATE):
     from gst import Buffer
@@ -23,3 +25,12 @@ def gst_buffer_to_numpy_array(buf, chan):
     samples = frombuffer(buf.data, dtype='float32')
     samples.resize([len(samples)/chan, chan])
     return samples
+
+
+class MainloopThread(threading.Thread):
+    def __init__(self, mainloop):
+        threading.Thread.__init__(self)
+        self.mainloop = mainloop
+
+    def run(self):
+        self.mainloop.run()