summaryrefslogtreecommitdiffstats
path: root/k9decmpeg/k9decodethread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'k9decmpeg/k9decodethread.cpp')
-rw-r--r--k9decmpeg/k9decodethread.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/k9decmpeg/k9decodethread.cpp b/k9decmpeg/k9decodethread.cpp
new file mode 100644
index 0000000..a7e5498
--- /dev/null
+++ b/k9decmpeg/k9decodethread.cpp
@@ -0,0 +1,105 @@
+//
+// C++ Implementation: k9decodethread
+//
+// Description:
+//
+//
+// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2006
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include "k9decodethread.h"
+
+k9DecodeThread::k9DecodeThread()
+{
+ m_decoder=new kDecMPEG2(this);
+ noData=FALSE;
+}
+
+
+k9DecodeThread::~k9DecodeThread()
+{
+ delete m_decoder;
+}
+
+void k9DecodeThread::clear() {
+ m_fifo.clear();
+ wDataRead.wakeAll();
+ wDataReady.wakeAll();
+
+}
+
+void k9DecodeThread::addData(uchar *data,uint size) {
+ while (1) {
+ if (m_fifo.freespace()>=size) {
+ m_fifo.enqueue(data,size);
+ wDataReady.wakeAll();
+ break;
+ } else
+ wDataRead.wait();
+ }
+}
+
+
+int k9DecodeThread::readData(uchar * data,uint size) {
+ uint size2=size;
+ uint32_t readSize=0,s=0;
+
+ while (1) {
+ // is there data in the buffer?
+ if (m_fifo.count() >0) {
+ // s= size of data that we will read (maximum = size)
+ s=(m_fifo.count()) <size2 ? (m_fifo.count()) : size2;
+ // increments the number of readen bytes
+ readSize+=s;
+ // decrements the number of max bytes to read
+ size2-=s;
+ //moves bytes from buffer to output
+ m_fifo.dequeue(data,s);
+ //moves the position of output buffer to receive next bytes
+ data+=s;
+ //there's now free space in input buffer, we can wake the injection thread
+ wDataRead.wakeAll();
+ }
+ // break the loop if injection thread terminated or we got what we want (size bytes)
+ // oterwise, we're waiting for datas
+ if(noData || (m_fifo.count() >=size2)) {
+ break;
+ } else
+ wDataReady.wait();
+ }
+ // if there's datas in input buffer and we did not get all what we wanted, we take them.
+ s= (m_fifo.count()) <size2 ? (m_fifo.count()) : size2;
+ readSize+=s;
+ if (s>0 )
+ m_fifo.dequeue(data,s);
+
+ wDataRead.wakeAll();
+ return readSize;
+}
+
+void k9DecodeThread::setNoData() {
+ noData=true;
+ wDataRead.wakeAll();
+ wDataReady.wakeAll();
+}
+
+void k9DecodeThread::sleepms(int _ms) {
+ msleep(_ms);
+}
+
+void k9DecodeThread::run() {
+ noData=FALSE;
+ m_decoder->start();
+ while (1) {
+ int count=2048;
+ uchar buffer[count];
+ uint32_t size=readData(buffer,count);
+ if (size==0)
+ break;
+ m_decoder->decode(buffer ,buffer+size,0);
+ }
+ m_decoder->stop();
+
+}