// // C++ Implementation: k9decodethread // // Description: // // // Author: Jean-Michel PETIT , (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)) { 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()) 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(); }