From 952cb18da0cea101d5faa4591069b269b6dd146e Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Thu, 28 Nov 2013 17:40:44 +0100 Subject: [PATCH] Encoder: implement abstract IEncoder interface for GstEncoder base class --- timeside/encoder/core.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/timeside/encoder/core.py b/timeside/encoder/core.py index b3c9580..09ce3e3 100644 --- a/timeside/encoder/core.py +++ b/timeside/encoder/core.py @@ -20,14 +20,18 @@ from timeside.core import Processor, implements, interfacedoc +from timeside.component import implements, abstract from timeside.api import IEncoder from timeside.tools import * from gst import _gst as gst + class GstEncoder(Processor): + implements(IEncoder) + abstract() - def __init__(self, output, streaming = False, overwrite = False): + def __init__(self, output, streaming=False, overwrite=False): super(GstEncoder, self).__init__() @@ -52,6 +56,7 @@ class GstEncoder(Processor): self.metadata = None self.num_samples = 0 + @interfacedoc def release(self): if hasattr(self, 'eod') and hasattr(self, 'mainloopthread'): self.end_cond.acquire() @@ -121,16 +126,24 @@ class GstEncoder(Processor): self.end_cond.notify() self.end_cond.release() + @interfacedoc def process(self, frames, eod=False): self.eod = eod if eod: self.num_samples += frames.shape[0] else: self.num_samples += self.blocksize() - buf = numpy_array_to_gst_buffer(frames, self.blocksize(),self.num_samples, self.samplerate()) + buf = numpy_array_to_gst_buffer(frames, frames.shape[0],self.num_samples, self.samplerate()) 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 + + +if __name__ == "__main__": + # Run doctest from __main__ and unittest from test_analyzer_preprocessors + from tests import test_encoding, test_transcoding + from tests.unit_timeside import runTestModule + runTestModule('__main__', test_encoding, test_transcoding) \ No newline at end of file -- 2.39.5