From: Thomas Fillon Date: Fri, 14 Feb 2014 10:06:39 +0000 (+0100) Subject: Put MainloopThread in gstutils X-Git-Tag: 0.5.4~6^2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=8b7f1ff4ce8b5bafdc7d7cdf2f0ac66158495656;p=timeside.git Put MainloopThread in gstutils --- diff --git a/timeside/decoder/file.py b/timeside/decoder/file.py index 7af59df..3a9483a 100644 --- a/timeside/decoder/file.py +++ b/timeside/decoder/file.py @@ -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() diff --git a/timeside/decoder/live.py b/timeside/decoder/live.py index e5c355f..fdb596b 100644 --- a/timeside/decoder/live.py +++ b/timeside/decoder/live.py @@ -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() diff --git a/timeside/encoder/core.py b/timeside/encoder/core.py index f89acc3..db34c41 100644 --- a/timeside/encoder/core.py +++ b/timeside/encoder/core.py @@ -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() diff --git a/timeside/tools/gstutils.py b/timeside/tools/gstutils.py index c5605f4..2722085 100644 --- a/timeside/tools/gstutils.py +++ b/timeside/tools/gstutils.py @@ -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()