From: Paul Brossier Date: Tue, 29 Jan 2013 03:16:50 +0000 (-0500) Subject: timeside/encoder/: add end condition to flush stream in release, raise an exception... X-Git-Tag: 0.4.3~1^2~4 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=c655f73c210d09bd6493981fdf8d31d3bdf616d4;p=timeside.git timeside/encoder/: add end condition to flush stream in release, raise an exception if an error occured --- diff --git a/timeside/encoder/core.py b/timeside/encoder/core.py index 449ae29..87165e2 100644 --- a/timeside/encoder/core.py +++ b/timeside/encoder/core.py @@ -41,11 +41,20 @@ 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 self.metadata = None def release(self): - pass + if hasattr(self, 'eod') and hasattr(self, 'mainloopthread'): + self.end_cond.acquire() + while not hasattr(self, 'end_reached'): + self.end_cond.wait() + self.end_cond.release() + if hasattr(self, 'error_msg'): + raise IOError(self.error_msg) def __del__(self): self.release() @@ -89,11 +98,21 @@ class GstEncoder(Processor): def _on_message_cb(self, bus, message): t = message.type if t == gst.MESSAGE_EOS: + self.end_cond.acquire() self.pipeline.set_state(gst.STATE_NULL) + self.mainloop.quit() + self.end_reached = True + self.end_cond.notify() + self.end_cond.release() elif t == gst.MESSAGE_ERROR: + self.end_cond.acquire() self.pipeline.set_state(gst.STATE_NULL) + self.mainloop.quit() + self.end_reached = True err, debug = message.parse_error() - print "Error: %s" % err, debug + self.error_msg = "Error: %s" % err, debug + self.end_cond.notify() + self.end_cond.release() def process(self, frames, eod=False): self.eod = eod