From 1cf69f6feeea426dc1cb72d199011b8a05028e79 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 16 Mar 2020 23:11:29 +0000 Subject: [PATCH] 21 CWFs --- stream.cc | 104 ++++++++++++++++++++++++++++++++++-------------------- stream.h | 3 +- tcp.cc | 2 +- tcp.h | 2 +- vdr.cc | 12 +++---- 5 files changed, 74 insertions(+), 49 deletions(-) diff --git a/stream.cc b/stream.cc index 64049c5..e3d94df 100644 --- a/stream.cc +++ b/stream.cc @@ -1,5 +1,6 @@ /* Copyright 2005-2006 Mark Calderbank + Copyright 2020 Chris Tallon This file is part of VOMP. @@ -14,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #include @@ -32,13 +32,16 @@ Stream::~Stream() void Stream::shutdown() { if (initted) free(outbuf); + initted = 0; } int Stream::init(DrainTarget* tdt, int bufsize) { - outbuf = (UCHAR*)malloc(bufsize); + outbuf = static_cast(malloc(bufsize)); + if (!outbuf) return 0; + draintarget = tdt; bufferSize = bufsize; initted = 1; @@ -55,50 +58,59 @@ void Stream::flush() if (draintarget) draintarget->ResetTimeOffsets(); } -int Stream::put(const UCHAR* inbuf, int len, UCHAR type,unsigned int index) +int Stream::put(const UCHAR* inbuf, int len, UCHAR type, unsigned int index) { int ret = 0; + if (!draintarget) return 0; + MediaPacket newPacket; newPacket.length = len; newPacket.pos_buffer = 0; newPacket.type = type; - newPacket.pts=0; - newPacket.dts=0; - newPacket.synched=false; - newPacket.index=index; - newPacket.disconti=false; - newPacket.presentation_time=0; - - if (type!=MPTYPE_MPEG_AUDIO_LAYER3) {//no PES + newPacket.pts = 0; + newPacket.dts = 0; + newPacket.synched = false; + newPacket.index = index; + newPacket.disconti = false; + newPacket.presentation_time = 0; + + if (type != MPTYPE_MPEG_AUDIO_LAYER3) //no PES + { //Extract the pts... - bool hasdts=false; - if ((inbuf[7] & 0x80) && len>14 ) { - newPacket.synched=true; - newPacket.pts=((ULLONG)(inbuf[9] & 0x0E) << 29 ) | - ( (ULLONG)(inbuf[10]) << 22 ) | - ( (ULLONG)(inbuf[11] & 0xFE) << 14 ) | - ( (ULLONG)(inbuf[12]) << 7 ) | - ( (ULLONG)(inbuf[13] & 0xFE) >> 1 ); - if ((inbuf[7] & 0x40) && len>19) { - newPacket.dts=((ULLONG)(inbuf[14] & 0x0E) << 29 ) | - ( (ULLONG)(inbuf[15]) << 22 ) | - ( (ULLONG)(inbuf[16] & 0xFE) << 14 ) | - ( (ULLONG)(inbuf[17]) << 7 ) | - ( (ULLONG)(inbuf[18] & 0xFE) >> 1 ); - hasdts=true; - } - //ok we have the pts now convert it to a continously time code in 100ns units - if (hasdts && draintarget->dtsTimefix()) newPacket.presentation_time=(ULLONG)(newPacket.dts*10000LL/90LL); - else newPacket.presentation_time=(ULLONG)(newPacket.pts*10000LL/90LL); - - //newPacket.presentation_time-=draintarget->SetStartOffset((ULLONG)(newPacket.pts*10000LL/90LL),&newPacket.disconti); - newPacket.presentation_time-=draintarget->SetStartOffset((ULLONG)(newPacket.pts*10000LL/90LL),&newPacket.disconti); + bool hasdts = false; + + if ((inbuf[7] & 0x80) && len > 14 ) + { + newPacket.synched = true; + newPacket.pts = ( static_cast(inbuf[9] & 0x0E) << 29 ) | + ( static_cast(inbuf[10]) << 22 ) | + ( static_cast(inbuf[11] & 0xFE) << 14 ) | + ( static_cast(inbuf[12]) << 7 ) | + ( static_cast(inbuf[13] & 0xFE) >> 1 ); + + if ((inbuf[7] & 0x40) && len > 19) + { + newPacket.dts = ( static_cast(inbuf[14] & 0x0E) << 29 ) | + ( static_cast(inbuf[15]) << 22 ) | + ( static_cast(inbuf[16] & 0xFE) << 14 ) | + ( static_cast(inbuf[17]) << 7 ) | + ( static_cast(inbuf[18] & 0xFE) >> 1 ); + hasdts = true; + } + + //ok we have the pts now convert it to a continously time code in 100ns units + if (hasdts && draintarget->dtsTimefix()) newPacket.presentation_time = static_cast(newPacket.dts * 10000LL / 90LL); + else newPacket.presentation_time = static_cast(newPacket.pts * 10000LL / 90LL); + + //newPacket.presentation_time-=draintarget->SetStartOffset(static_cast(newPacket.pts*10000LL/90LL),&newPacket.disconti); + newPacket.presentation_time -= draintarget->SetStartOffset(static_cast(newPacket.pts * 10000LL / 90LL), &newPacket.disconti); } } mutex.lock(); int front, back; + if (mediapackets.empty()) { back = 0; front = bufferSize; @@ -107,8 +119,10 @@ int Stream::put(const UCHAR* inbuf, int len, UCHAR type,unsigned int index) { front = mediapackets.front().pos_buffer; back = mediapackets.back().pos_buffer + mediapackets.back().length; + if (back == bufferSize) back = 0; } + mutex.unlock(); if (back <= front) @@ -135,34 +149,46 @@ int Stream::put(const UCHAR* inbuf, int len, UCHAR type,unsigned int index) mutex.lock(); mediapackets.push_back(newPacket); mutex.unlock(); - } else { - // Log::getInstance()->log("Stream", Log::DEBUG, "We are full %d!",bufferSize); + } + else + { + // Log::getInstance()->log("Stream", Log::DEBUG, "We are full %d!",bufferSize); } return ret; } -bool Stream::drain(bool * dataavail) +bool Stream::drain(bool* dataavail) { bool ret = false; + if (dataavail) *dataavail = false; + if (draintarget->DrainTargetBufferFull()) return false; //We are full, no need to do something else + mutex.lock(); UINT listlength = mediapackets.size(); + if (listlength != 0) { draintarget->PrepareMediaSample(mediapackets, cur_packet_pos); mutex.unlock(); + if (dataavail && draintarget->DrainTargetReady()) *dataavail = true; + UINT consumed = draintarget->DeliverMediaSample(outbuf, &cur_packet_pos); mutex.lock(); + if (consumed != 0) ret = true; + if (consumed > listlength) consumed = listlength; - while (consumed--) + + while (consumed--) { - mediapackets.pop_front(); + mediapackets.pop_front(); } } + mutex.unlock(); return ret; } diff --git a/stream.h b/stream.h index 301138f..b9ab4cf 100644 --- a/stream.h +++ b/stream.h @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef STREAM_H diff --git a/tcp.cc b/tcp.cc index be2133a..40f1f95 100644 --- a/tcp.cc +++ b/tcp.cc @@ -53,7 +53,7 @@ void TCP::disableTimeout() timeoutEnabled = 0; } -void TCP::getMAC(char* dest) +void TCP::getMAC(UCHAR* dest) { #ifndef WIN32 struct ifreq ifr; diff --git a/tcp.h b/tcp.h index f053752..ceacc3c 100644 --- a/tcp.h +++ b/tcp.h @@ -63,7 +63,7 @@ class TCP static void dump(unsigned char* data, ULONG size); - void getMAC(char* dest); // copies 6 MAC bytes to dest + void getMAC(UCHAR* dest); // copies 6 MAC bytes to dest void setReceiveWindow(size_t rxBufferSize); private: diff --git a/vdr.cc b/vdr.cc index bb97ca4..8fda12f 100644 --- a/vdr.cc +++ b/vdr.cc @@ -120,7 +120,7 @@ VDR::VDR() if (instance) return; instance = this; - TEMP_SINGLE_VDR_PR = NULL; + TEMP_SINGLE_VDR_PR = NULL; // FIXME what is this #ifdef VOMP_MEDIAPLAYER providerId=MPROVIDERID_VDR; subRange=MPROVIDERRANGE_VDR; @@ -590,7 +590,7 @@ VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp) edMutex.lock(); - if ((ULONG)tcp->sendData(vrp->getPtr(), vrp->getLen()) != vrp->getLen()) + if (static_cast(tcp->sendData(vrp->getPtr(), vrp->getLen())) != vrp->getLen()) { edMutex.unlock(); edUnregister(&vdrpr); @@ -625,7 +625,7 @@ bool VDR::sendKA(ULONG timeStamp) buffer[pos++]=(ul>>16)&0xff; buffer[pos++]=(ul>>8)&0xff; buffer[pos++]=ul &0xff; - if ((ULONG)tcp->sendData(buffer, 8) != 8) return false; + if (static_cast(tcp->sendData(buffer, 8)) != 8) return false; return true; } @@ -687,9 +687,9 @@ int VDR::doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigne VDR_RequestPacket vrp; if (!vrp.init(VDR_LOGIN, true, 6)) return 0; - char* mactemp[6]; - tcp->getMAC((char*)mactemp); - if (!vrp.copyin((UCHAR*)mactemp, 6)) return 0; + UCHAR mactemp[6]; + tcp->getMAC(mactemp); + if (!vrp.copyin(mactemp, 6)) return 0; VDR_ResponsePacket* vresp = RequestResponse(&vrp); if (vresp->noResponse()) { delete vresp; return 0; } -- 2.39.5