/*
Copyright 2005-2006 Mark Calderbank
+ Copyright 2020 Chris Tallon
This file is part of VOMP.
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 <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
void Stream::shutdown()
{
if (initted) free(outbuf);
+
initted = 0;
}
int Stream::init(DrainTarget* tdt, int bufsize)
{
- outbuf = (UCHAR*)malloc(bufsize);
+ outbuf = static_cast<UCHAR*>(malloc(bufsize));
+
if (!outbuf) return 0;
+
draintarget = tdt;
bufferSize = bufsize;
initted = 1;
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<ULLONG>(inbuf[9] & 0x0E) << 29 ) |
+ ( static_cast<ULLONG>(inbuf[10]) << 22 ) |
+ ( static_cast<ULLONG>(inbuf[11] & 0xFE) << 14 ) |
+ ( static_cast<ULLONG>(inbuf[12]) << 7 ) |
+ ( static_cast<ULLONG>(inbuf[13] & 0xFE) >> 1 );
+
+ if ((inbuf[7] & 0x40) && len > 19)
+ {
+ newPacket.dts = ( static_cast<ULLONG>(inbuf[14] & 0x0E) << 29 ) |
+ ( static_cast<ULLONG>(inbuf[15]) << 22 ) |
+ ( static_cast<ULLONG>(inbuf[16] & 0xFE) << 14 ) |
+ ( static_cast<ULLONG>(inbuf[17]) << 7 ) |
+ ( static_cast<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 = static_cast<ULLONG>(newPacket.dts * 10000LL / 90LL);
+ else newPacket.presentation_time = static_cast<ULLONG>(newPacket.pts * 10000LL / 90LL);
+
+ //newPacket.presentation_time-=draintarget->SetStartOffset(static_cast<ULLONG>(newPacket.pts*10000LL/90LL),&newPacket.disconti);
+ newPacket.presentation_time -= draintarget->SetStartOffset(static_cast<ULLONG>(newPacket.pts * 10000LL / 90LL), &newPacket.disconti);
}
}
mutex.lock();
int front, back;
+
if (mediapackets.empty())
{
back = 0; front = bufferSize;
{
front = mediapackets.front().pos_buffer;
back = mediapackets.back().pos_buffer + mediapackets.back().length;
+
if (back == bufferSize) back = 0;
}
+
mutex.unlock();
if (back <= front)
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;
}
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;
edMutex.lock();
- if ((ULONG)tcp->sendData(vrp->getPtr(), vrp->getLen()) != vrp->getLen())
+ if (static_cast<ULONG>(tcp->sendData(vrp->getPtr(), vrp->getLen())) != vrp->getLen())
{
edMutex.unlock();
edUnregister(&vdrpr);
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<ULONG>(tcp->sendData(buffer, 8)) != 8) return false;
return true;
}
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; }