diff -ru kaffeine-0.8.4.cvs.orig/kaffeine/src/input/dvb/dvbout.cpp kaffeine-0.8.4.cvs/kaffeine/src/input/dvb/dvbout.cpp --- kaffeine-0.8.4.cvs.orig/kaffeine/src/input/dvb/dvbout.cpp 2007-11-25 12:57:46.000000000 +0200 +++ kaffeine-0.8.4.cvs/kaffeine/src/input/dvb/dvbout.cpp 2007-11-26 00:35:52.000000000 +0200 @@ -19,6 +19,7 @@ */ #include +#include #include @@ -47,7 +48,6 @@ plugHandle = plug->init( chan.sid, anum, tnum, chan.fta ); } - fdPipe=0; channel = chan; thWrite = 0; rtp = 0; @@ -58,7 +58,7 @@ for ( i=0; iprocess( plugHandle, thBuf, TS_SIZE*NTS ); mutex.lock(); - if ( haveLive && fdPipe ) { - if ( beginLive ) { - beginLive = !beginLive; - start(); - } + if ( haveLive ) { if ( wDist<95 ) { memcpy( wBuf+(wWrite*TS_SIZE*NTS), thBuf, TS_SIZE*NTS ); wpatpmt = patpmt; @@ -525,40 +506,67 @@ } } - +bool DVBout::writeBytes(int fd, const unsigned char *buf, int bytes) { + int w=0; + mutex.lock(); + while (haveLive && w=0) w+=r; + else { + if ( errno != EAGAIN ) { + perror("DVBout: pipe writeBytes"); + return false; + } + usleep( 100 ); + } + mutex.lock(); + } + mutex.unlock(); + return haveLive; +} void DVBout::run() { - if ( haveLive && fdPipe ) { - while ( haveLive && fdPipe ) { - if ( wDist>0 ) { - if ( wpatpmt ) { - write( fdPipe, tspat, TS_SIZE ); - write( fdPipe, tspmt, TS_SIZE ); - wpatpmt = false; - } - write( fdPipe, wBuf+(wRead*TS_SIZE*NTS), TS_SIZE*NTS ); - --wDist; - ++wRead; - if ( wRead>99 ) - wRead = 0; - } - else - usleep( 100 ); + int fd=-1; + fprintf(stderr,"DVBout::run started\n"); + + while (haveLive && (fd=open( pipeName.ascii(), O_WRONLY | O_NONBLOCK )) == -1 ) { + if (errno!=ENXIO) { + perror("DVBout::run open pipe"); + return; } - return; + usleep ( 100 ); } + fprintf(stderr,"DVBout::run write pipe %s opened\n",pipeName.ascii()); + emit playDvb(); + fprintf(stderr,"DVBout::run signal emitted\n"); - if ( (fdPipe=open( pipeName.ascii(), O_WRONLY))<0 ) { - perror("PIPE FILE: "); - return; + mutex.lock(); + while (haveLive) { + mutex.unlock(); + if (wpatpmt) { + if (writeBytes(fd, tspat, TS_SIZE) && writeBytes(fd, tspmt, TS_SIZE) ) { + wpatpmt = false; + } else goto fail; + } + if (wDist>0) { + if ( writeBytes (fd, wBuf+(wRead*TS_SIZE*NTS), TS_SIZE*NTS ) ) { + mutex.lock(); + --wDist; + ++wRead; + if (wRead>99) wRead=0; + mutex.unlock(); + } else goto fail; + } else usleep ( 100 ); + mutex.lock(); } - fprintf(stderr,"pipe opened\n"); - emit playDvb(); + mutex.unlock(); +fail: + if(fd>=0) close(fd); + fprintf(stderr,"DVBout::run finished\n"); } - - DVBout::~DVBout() { if ( plug ) diff -ru kaffeine-0.8.4.cvs.orig/kaffeine/src/input/dvb/dvbout.h kaffeine-0.8.4.cvs/kaffeine/src/input/dvb/dvbout.h --- kaffeine-0.8.4.cvs.orig/kaffeine/src/input/dvb/dvbout.h 2007-11-25 12:57:46.000000000 +0200 +++ kaffeine-0.8.4.cvs/kaffeine/src/input/dvb/dvbout.h 2007-11-25 23:09:58.000000000 +0200 @@ -35,7 +35,7 @@ class KaffeineDvbPlugin; -class DVBout : public TQObject, public QThread +class DVBout : public TQObject, private QThread { TQ_OBJECT @@ -77,13 +77,13 @@ void writePat(); void calculateCRC( unsigned char *p_begin, unsigned char *p_end ); void renameFile( TQString &name, const TQString &ext ); + bool writeBytes(int fd, const unsigned char *buf, int bytes); int pmtpid; bool patpmt, wpatpmt; bool timeShifting; TQString pipeName; QFile outFile, liveFile; - int fdPipe; Ts2Rtp *rtp; unsigned char thBuf[188*100]; unsigned char *wBuf; @@ -92,7 +92,6 @@ unsigned char tspmt[188]; unsigned int CRC32[256]; int thWrite; - bool beginLive; bool haveRec, haveLive, instantRec, haveBroadcast; QTimer stopRecTimer, timerPatPmt; QMutex mutex;