2 Copyright 2006-2008 Mark Calderbank
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "demuxerts.h"
27 #define PTS_JUMP_MARGIN 10000
28 #define PTS_ALLOWANCE 90000
30 // TODO: PTS class to handle wrapping arithmetic & comparisons?
31 static ULLONG PTSDistance(ULLONG pts1, ULLONG pts2)
33 // Assume pts1, pts2 < 2^33; calculate shortest distance between
34 ULLONG ret = (pts1 > pts2) ? pts1 - pts2 : pts2 - pts1;
35 if (ret > (1LL<<32)) ret = (1LL<<33) - ret;
39 static ULLONG PTSDifference(ULLONG pts1, ULLONG pts2)
41 // Assume pts1, pts2 < 2^33; calculate pts1 - pts2
45 return (1LL<<33) + pts1 - pts2;
48 DemuxerTS::DemuxerTS(int p_vID, int p_aID, int p_subID, int p_tID)
50 vID = p_vID; vActive = false;
51 aID = p_aID; aActive = false;
52 subID = p_subID; subActive = false;
56 havechannelinfo=false;
57 //doubledframerate=false;
61 pinfo.hasaccessunit=false;
64 void DemuxerTS::flush()
68 havechannelinfo=false;
70 vPacket.init(PESTYPE_VID0);
74 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
78 aPacket.init(PESTYPE_AUD0);
81 subPacket.init(PESTYPE_PRIVATE_1);
82 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
89 // doubledframerate=false;
92 pinfo.hasaccessunit=false;
95 int DemuxerTS::scan(UCHAR *buf, int len)
100 return PESTYPE_PRIVATE_1;
107 void DemuxerTS::setVID(int p_vID)
110 vPacket.init(PESTYPE_VID0);
114 void DemuxerTS::setAID(int p_aID, int type, int streamtype, bool slivetv)
118 astreamtype = streamtype;
123 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
124 setAudioStream(PESTYPE_SUBSTREAM_AC30);
128 aPacket.init(PESTYPE_AUD0);
129 setAudioStream(PESTYPE_AUD0);
135 void DemuxerTS::setSubID(int p_subID)
138 subPacket.init(PESTYPE_PRIVATE_1);
143 void DemuxerTS::setTID(int p_tID)
146 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
154 int DemuxerTS::findPTS(UCHAR* buf, int len, ULLONG* dest)
158 while (len >= TS_SIZE)
160 if (*buf != TS_SIG) {buf++;len--; continue;}
162 //Pattern scanning won't work for ts
165 int datalen = TS_SIZE - 4;
166 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
167 UCHAR payload = buf[1] & 0x40;
169 if (buf[3] & 0x20) // Adaptation field is present
170 datalen -= (buf[4] + 1);
172 UCHAR* curbuf =buf+ (TS_SIZE - datalen);
176 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
177 int pmtpid = (*(curbuf+11)<< 8) | *(curbuf+12);
178 if ((pmtpid >> 13) != 0x07)
180 Log::getInstance()->log("findPTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(curbuf+11),*(curbuf+12), (pmtpid >> 13));
184 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
188 } else if (pid == PMTPID) { //PMT
189 int sectionlength = ((*(curbuf+2) << 8) & 0x0F ) | *(buf+3);
190 //sectionlength += 4; //include header but subtract crc in the end...
191 int p = 13; //skip fixed part of pmt
192 while ( p < sectionlength) {
193 int streamtype = *(curbuf+p);
195 int foundpid = (*(curbuf+p)<< 8) | *(curbuf+p+1);
196 p += 2; //skip ES Pid
197 int eslength = ((*(curbuf+p) << 8) & 0x0F ) | *(curbuf+p+1);
198 p += 2; //skip ES length
199 if ((foundpid >> 13) != 0x07)
201 Log::getInstance()->log("findPTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
205 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
207 if (streamtype==3 || streamtype ==4) {
211 p += eslength; //skip es descriptor
213 } else if (pid == scanaid) {
214 // UINT framelength = ((UINT)curbuf[4] << 8) | curbuf[5]; UNUSED?
216 if ( curbuf[7] & 0x80 ) // PTS_DTS_flags indicate that PTS is present
218 *dest = ( (ULLONG)(curbuf[9] & 0x0E) << 29 ) |
219 ( (ULLONG)(curbuf[10]) << 22 ) |
220 ( (ULLONG)(curbuf[11] & 0xFE) << 14 ) |
221 ( (ULLONG)(curbuf[12]) << 7 ) |
222 ( (ULLONG)(curbuf[13] & 0xFE) >> 1 );
234 void DemuxerTS::setFrameNum(ULONG frame)
236 frameCounting = true;
239 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setFrameNum %d", frame);
242 void DemuxerTS::setPacketNum(ULONG npacket)
244 packetCounting = true;
245 packetNumber = npacket;
246 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setPacketNum %d", npacket);
249 int DemuxerTS::put(UCHAR* buf, int len)
251 int ret = 0; // return number of bytes consumed
253 bool misaligned_mess=false;
256 if (len >= TS_SIZE + 1 - partPacket)
257 { // Remainder of partial packet is available, plus one
258 memcpy(store+partPacket, buf, TS_SIZE - partPacket);
259 ret += TS_SIZE - partPacket;
260 buf += TS_SIZE - partPacket;
261 len -= TS_SIZE - partPacket;
262 partPacket = TS_SIZE;
264 { // Packet is properly terminated
265 int rc = processTS(store);
267 partPacket = 0; // Successfully processed
269 return ret; // Try again later.
272 { // Packet not terminated. Find another candidate, and shift store
273 if (!misaligned_mess) {
274 Log::getInstance()->log("TS Demuxer", Log::ERR, "TS Misaligned!A");
275 misaligned_mess=true; // do not alarm more than once
278 while (search < partPacket && store[search] != TS_SIG)
280 partPacket -= search;
281 if (partPacket) memcpy(store, store+search, partPacket);
285 { // Still don't have complete packet. Consume what we do have.
286 memcpy(store+partPacket, buf, len);
293 // Position ourselves at a candidate TS packet
294 while (len > 0 && *buf != TS_SIG)
296 if (!misaligned_mess) {
297 Log::getInstance()->log("TS Demuxer", Log::ERR, "TS Misaligned!B");
298 misaligned_mess=true; // do not alarm more than once
305 if (len < TS_SIZE + 1)
306 { // Not enough data. Store what we have.
307 memcpy(store, buf, len);
313 if (buf[TS_SIZE] != TS_SIG)
314 { // Not terminated correctly.
316 while (len > 0 && *buf != TS_SIG)
323 int rc = processTS(buf);
325 { // Successfully processed
326 buf += TS_SIZE; ret += TS_SIZE; len -= TS_SIZE;
329 { // Processing failed.
338 int DemuxerTS::processTS(UCHAR* buf)
340 int datalen = TS_SIZE - 4;
342 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
343 UCHAR payload = buf[1] & 0x40;
346 if (buf[3] & 0x20) // Adaptation field is present
347 datalen -= (buf[4] + 1);
348 if (datalen < 0) // Error in stream TODO log this
350 if (datalen == 0) // Null packet
352 // if (!(buf[3] &0x10)) return 1; // no payload
353 buf += (TS_SIZE - datalen);
358 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
359 int pmtpid = (*(buf+11)<< 8) | *(buf+12);
360 if ((pmtpid >> 13) != 0x07)
362 Log::getInstance()->log("ProcessTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(buf+11),*(buf+12), (pmtpid >> 13));
366 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
373 int sectionlength = ((*(buf+2) << 8) & 0x0F ) | *(buf+3);
374 //sectionlength += 4; //include header but subtract crc in the end...
375 int p = 13; //skip fixed part of pmt
376 Channel new_channelinfo;
377 new_channelinfo.numAPids=0;
378 new_channelinfo.numDPids=0;
379 new_channelinfo.numSPids=0;
380 new_channelinfo.number=0;
381 new_channelinfo.type=VDR::RADIO;
382 new_channelinfo.name=NULL;
383 new_channelinfo.tpid=0xFFFFF; //unused, check this
384 new_channelinfo.vpid=0xFFFFF; //unused, check this
385 new_channelinfo.index=0;
387 new_channelinfo.apids.clear();
388 new_channelinfo.dpids.clear();
389 new_channelinfo.spids.clear();
391 while ( p < sectionlength) {
392 int streamtype = *(buf+p);
394 int foundpid = (*(buf+p)<< 8) | *(buf+p+1);
395 p += 2; //skip ES Pid
396 int eslength = ((*(buf+p) << 8) & 0x0F ) | *(buf+p+1);
397 p += 2; //skip ES length
398 if ((foundpid >> 13) != 0x07)
400 Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
404 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
408 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDPID is %x %x", foundpid,streamtype);
411 case 0x1B: //MPEG 4 for future use
414 if (foundpid != getVID())
416 new_channelinfo.type=VDR::VIDEO;
417 new_channelinfo.vstreamtype=streamtype;
418 new_channelinfo.vpid=foundpid;
419 if (streamtype==0x1b) h264=true;
422 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "Set video PID to %x", foundpid);
424 case 0x0F: //AAC ADTS packaging
425 case 0x11: // LATM packaging
429 newapid.pid = foundpid;
431 newapid.type=streamtype;
434 while (pos< eslength && nolang) {
435 switch (buf[p+pos]) {
437 newapid.desc[0]=buf[p+pos+2];
438 newapid.desc[1]=buf[p+pos+3];
439 newapid.desc[2]=buf[p+pos+4];
442 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDLANG is %s", newapid.desc);
449 new_channelinfo.apids.push_back(newapid);
450 new_channelinfo.numAPids++;
454 case 6: { //Private Data
456 newapid.pid = foundpid;
457 newapid.desc[0]=0; //set it in player
463 while (pos< eslength && (notfound || nolang)) {
464 switch (buf[p+pos]) {
465 case 0x7A: // Enhanced Ac3 Desriptor
466 case 0x6A: {//Ac3 descriptor
467 newapid.type=buf[p+pos];
472 case 0x59: {//SubtitlingDescriptor
474 newapid.type=buf[p+pos];
475 newapid.desc[0]=buf[p+pos+2];
476 newapid.desc[1]=buf[p+pos+3];
477 newapid.desc[2]=buf[p+pos+4];
479 newapid.data1=(buf[p+pos+5]<<8) |(buf[p+pos+6]);
480 newapid.data2=(buf[p+pos+7]<<8) |(buf[p+pos+8]);
481 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDSUB is %s", newapid.desc);
486 newapid.desc[0]=buf[p+pos+2];
487 newapid.desc[1]=buf[p+pos+3];
488 newapid.desc[2]=buf[p+pos+4];
491 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDLANG is %s", newapid.desc);
495 new_channelinfo.tpid=foundpid;
502 new_channelinfo.dpids.push_back(newapid);
503 new_channelinfo.numDPids++;
504 } else if (type==2) {
505 new_channelinfo.spids.push_back(newapid);
506 new_channelinfo.numSPids++;
510 default://TODO how about subtitles and second audio pids
515 p += eslength; //skip es descriptor
520 bool audioPIDpresent=false; //Check if pids chnages
522 for (i=0;i<channelinfo.numAPids;i++) {
523 if (aID == (int)channelinfo.apids[i].pid) {
524 audioPIDpresent=true;
527 for (i=0;i<channelinfo.numDPids && (! audioPIDpresent);i++) {
528 if (aID == (int)channelinfo.dpids[i].pid) {
529 audioPIDpresent=true;
532 if (! audioPIDpresent || getAID() == 0) {
537 Command* command = Command::getInstance();
539 if (channelinfo.numDPids > 0 && Audio::getInstance()->maysupportAc3())
542 while (j < channelinfo.numDPids)
544 int newpref = command->getLangPref(false, channelinfo.dpids[j].desc);
545 if (Audio::getInstance()->streamTypeSupported(channelinfo.dpids[j].type)
546 && (prefered < 0 || newpref < prefered))
556 if (channelinfo.numAPids > 0)
559 while (j < channelinfo.numAPids)
561 int newpref = command->getLangPref(false, channelinfo.apids[j].desc);
562 if (Audio::getInstance()->streamTypeSupported(channelinfo.apids[j].type)
563 && (prefered < 0 || newpref < prefered))
574 setAID(channelinfo.dpids[selected].pid,1,channelinfo.dpids[selected].type,false);
575 Audio::getInstance()->setStreamType(Audio::MPEG2_PES);
577 setAID(channelinfo.apids[selected].pid,0,channelinfo.apids[selected].type,false);
578 Audio::getInstance()->setStreamType(Audio::MPEG2_PES);
585 if (channelinfo.numSPids) {
587 while (j < channelinfo.numSPids)
589 int newpref = command->getLangPref(true, channelinfo.spids[j].desc);
590 if ( (prefered < 0 || newpref < prefered))
600 setSubID(channelinfo.spids[selected].pid);
605 channelinfo=new_channelinfo;
608 havechannelinfo=true;
622 parseTSPacketDetails(vPacket);
625 rc = submitPacket(vPacket);
635 parseTSPacketDetails(aPacket);
638 rc = submitPacket(aPacket);
648 parseTSPacketDetails(subPacket);
651 rc = submitPacket(subPacket);
655 if (isteletextdecoded && pid == tID)
661 parseTSPacketDetails(tPacket);
664 rc = submitPacket(tPacket);
668 if (rc == 0) return 0;
673 vPacket.init(PESTYPE_VID0);
674 buf += 6; datalen -= 6;
681 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
685 aPacket.init(PESTYPE_AUD0);
688 buf += 6; datalen -= 6;
692 subPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_DVBSUBTITLE0);
693 subLength = (buf[4] << 8) + buf[5];
694 buf += 6; datalen -= 6;
696 if (isteletextdecoded && pid == tID)
698 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
699 buf += 6; datalen -= 6;
703 if ( (pid == vID && vActive) ||
704 (pid == aID && aActive) ||
705 (pid == tID && tActive) ||
706 (pid == subID && subActive) )
708 PESPacket* packet = NULL;
709 if (pid == vID) packet = &vPacket;
710 if (pid == aID) packet = &aPacket;
714 if (pid == tID) packet = &tPacket;
717 if (packet->write(buf, datalen) == 0)
718 { // Writing to packet failed. It has overflowed.
721 parseTSPacketDetails(*packet);
724 if (submitPacket(*packet) == 0) return 0;
727 packet->write((UCHAR*)"\200\000\000", 3);
728 packet->write(buf, datalen);
733 if (pid == subID && subActive && subPacket.getLength() == subLength)
735 parsePacketDetails(subPacket);
736 Log::getInstance()->log("DEMUXERTS", Log::DEBUG, "SUBMITTING A SUBTITLE PACKET %d %x", subLength, subPacket.getSubstream());
737 submitPacket(subPacket);
744 ULONG DemuxerTS::getPacketNum()
749 ULONG DemuxerTS::getFrameNumFromPTS(ULLONG pts)
751 ULLONG difference = (1LL<<33);
753 int total = 0, actual = 0;
754 if (pts==0) return 0; //we are in startup
755 pts_map_mutex.Lock();
756 PTSMap::iterator iter = pts_map.begin();
757 while (iter != pts_map.end())
760 //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts1 %lld pts2 %lld", pts, iter->pts);
761 if (PTSDifference(iter->pts, pts) < PTS_ALLOWANCE)
764 ref_frame = iter->frame;
768 ULLONG newdiff = PTSDifference(pts, iter->pts);
769 if (newdiff < difference)
771 difference = newdiff;
772 ref_frame = iter->frame;
777 if (total > 1 && actual == 1) // We are using the most recent PTS ref.
778 { // Delete the rest.
779 iter = pts_map.begin(); iter++;
780 pts_map.erase(iter, pts_map.end());
782 pts_map_mutex.Unlock();
784 //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts %lld deleted %d difference %lld", pts, total,difference);
786 if (difference == (1LL<<33))
787 return 0; // We cannot make sense of the pts
789 return ref_frame + difference * fps / 90000;
793 void DemuxerTS::parseTSPacketDetails(PESPacket &packet) // Only important stuff for paket counting reminas
795 parsePacketDetails(packet);
796 if (packetCounting && packet.getPacketType() >= PESTYPE_AUD0 &&
797 packet.getPacketType() <= PESTYPE_AUDMAX)
801 UINT pictsinpacket=packet.countPictureHeaders(h264,pinfo);
804 /* if (!doubledframerate)
806 numpicts=pictsinpacket;
810 numpicts=(pictsinpacket+framereserve)>>1;
811 framereserve=(pictsinpacket+framereserve)%2;
815 if (frameCounting && numpicts &&
816 packet.getPacketType() >= PESTYPE_VID0 &&
817 packet.getPacketType() <= PESTYPE_VIDMAX)
819 frameNumber+=numpicts;
820 ULONG frame_num = frameNumber;
821 if ((h264 || packet.findSeqHeader(h264) > 1) && packet.hasPTS())
824 pts_map_mutex.Lock();
827 me.pts = packet.getPTS();
828 me.frame = frame_num;
829 pts_map_mutex.Unlock();
830 pts_map_mutex.Lock();
831 pts_map.push_front(me);
833 me = pts_map.front();
834 pts_map_mutex.Unlock();
836 //UINT fps = Video::getInstance()->getFPS();
838 // if (doubledframerate) tfps*=2.;
839 long long pts_expected = me.pts + 90000LL*((long long)(((double)(frame_num - me.frame)) / tfps));
841 while (pts_expected < 0) pts_expected += (1LL<<33);
842 while (pts_expected > (1LL<<33)) pts_expected -= (1LL<<33);
844 // this was a workaround for a vdr bug, now fixed, for older recordings deleter the index file
847 if (!doubledframerate
848 &&(abs((long long)PTSDistance(pts_expected, packet.getPTS())-1800) <= 1
849 || abs((long long)PTSDistance(pts_expected, packet.getPTS())-1501) <= 1)) {
850 doubledframerate=true; //Detected p50 or p60
853 if (PTSDistance(pts_expected, packet.getPTS()) > PTS_JUMP_MARGIN) // PTS jump!
855 me.pts = packet.getPTS();
856 me.frame = frame_num;
857 pts_map_mutex.Lock();
858 pts_map.push_front(me);
859 pts_map_mutex.Unlock();
866 bool DemuxerTS::scanForVideo(UCHAR* buf, UINT len, bool &ish264)
870 while (len >= TS_SIZE)
872 if (*buf != TS_SIG) {buf++;len--; continue;}
874 //Pattern scanning won't work for ts
877 int datalen = TS_SIZE - 4;
878 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
879 UCHAR payload = buf[1] & 0x40;
881 if (buf[3] & 0x20) // Adaptation field is present
882 datalen -= (buf[4] + 1);
884 UCHAR* curbuf =buf+ (TS_SIZE - datalen);
887 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
888 int pmtpid = (*(curbuf+11)<< 8) | *(curbuf+12);
889 if ((pmtpid >> 13) != 0x07)
891 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(curbuf+11),*(curbuf+12), (pmtpid >> 13));
895 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
897 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "PMT pid%02x",pmtpid );
900 } else if (pid == pmtpidy) { //PMT
901 int sectionlength = ((*(curbuf+2) << 8) & 0x0F ) | *(buf+3);
902 //sectionlength += 4; //include header but subtract crc in the end...
903 int p = 13; //skip fixed part of pmt
904 while ( p < sectionlength) {
905 int streamtype = *(curbuf+p);
907 int foundpid = (*(curbuf+p)<< 8) | *(curbuf+p+1);
908 p += 2; //skip ES Pid
909 int eslength = ((*(curbuf+p) << 8) & 0x0F ) | *(curbuf+p+1);
910 p += 2; //skip ES length
911 if ((foundpid >> 13) != 0x07)
913 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
917 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
918 // int pos=0; UNUSED?
919 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Pid found %02x type %02x",foundpid ,streamtype);
920 if (streamtype==1 || streamtype ==2) {
922 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Found Mpeg2 Video");
925 if (streamtype==0x1b) {
927 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Found h264 Video");
931 p += eslength; //skip es descriptor
944 UINT DemuxerTS::stripAudio(UCHAR* buf, UINT len) //it has to be adapted
946 //This function strips all TS Headers and non video payload
951 while (readpos < len ) {
952 if (buf[readpos] != TS_SIG) {readpos++; continue;}
953 UINT oldreadpos=readpos;
955 int datalen = TS_SIZE - 4;
956 int pid = ( (buf[readpos+1] & 0x1F) << 8 ) | buf[readpos+2];
957 UCHAR payload = buf[readpos+1] & 0x40;
958 if (buf[readpos+3] & 0x20) { // Adaptation field is present
959 datalen -= (buf[readpos+4] + 1);
961 if (datalen < 0) {// Error in stream TODO log this
964 if (datalen == 0) {// Null packet
965 readpos=oldreadpos+TS_SIZE;
968 readpos += (TS_SIZE - datalen);
969 UINT towrite=min(datalen,len-readpos);
973 parsePacketDetails(destpaket);
974 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
975 writepos+=destpaket.getSize();
977 destpaket.init(PESTYPE_VID0);
978 readpos += 6; towrite -= 6;
983 if (!destpaket.write(buf+readpos,towrite)) {
984 parsePacketDetails(destpaket);
985 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
986 writepos+=destpaket.getSize();
987 destpaket.truncate();
988 destpaket.write((UCHAR*)"\200\000\000", 3);
989 destpaket.write(buf+readpos,towrite);
997 readpos=oldreadpos+TS_SIZE;
999 parsePacketDetails(destpaket);
1000 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
1001 writepos+=destpaket.getSize();