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, see <https://www.gnu.org/licenses/>.
20 #include "demuxerts.h"
26 #define PTS_JUMP_MARGIN 10000
27 #define PTS_ALLOWANCE 90000
29 // TODO: PTS class to handle wrapping arithmetic & comparisons?
30 static ULLONG PTSDistance(ULLONG pts1, ULLONG pts2)
32 // Assume pts1, pts2 < 2^33; calculate shortest distance between
33 ULLONG ret = (pts1 > pts2) ? pts1 - pts2 : pts2 - pts1;
34 if (ret > (1LL<<32)) ret = (1LL<<33) - ret;
38 static ULLONG PTSDifference(ULLONG pts1, ULLONG pts2)
40 // Assume pts1, pts2 < 2^33; calculate pts1 - pts2
44 return (1LL<<33) + pts1 - pts2;
47 DemuxerTS::DemuxerTS(int p_vID, int p_aID, int p_subID, int p_tID)
49 vID = p_vID; vActive = false;
50 aID = p_aID; aActive = false;
51 subID = p_subID; subActive = false;
55 havechannelinfo=false;
56 //doubledframerate=false;
60 pinfo.hasaccessunit=false;
63 void DemuxerTS::flush()
67 havechannelinfo=false;
69 vPacket.init(PESTYPE_VID0);
73 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
77 aPacket.init(PESTYPE_AUD0);
80 subPacket.init(PESTYPE_PRIVATE_1);
81 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
88 // doubledframerate=false;
91 pinfo.hasaccessunit=false;
94 int DemuxerTS::scan(UCHAR* /*buf*/, int /*len*/)
99 return PESTYPE_PRIVATE_1;
106 void DemuxerTS::setVID(int p_vID)
109 vPacket.init(PESTYPE_VID0);
113 void DemuxerTS::setAID(int p_aID, int type, int streamtype, bool slivetv)
117 astreamtype = streamtype;
122 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
123 setAudioStream(PESTYPE_SUBSTREAM_AC30);
127 aPacket.init(PESTYPE_AUD0);
128 setAudioStream(PESTYPE_AUD0);
134 void DemuxerTS::setSubID(int p_subID)
137 subPacket.init(PESTYPE_PRIVATE_1);
142 void DemuxerTS::setTID(int p_tID)
145 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
153 int DemuxerTS::findPTS(UCHAR* buf, int len, ULLONG* dest)
157 while (len >= TS_SIZE)
159 if (*buf != TS_SIG) {buf++;len--; continue;}
161 //Pattern scanning won't work for ts
164 int datalen = TS_SIZE - 4;
165 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
166 UCHAR payload = buf[1] & 0x40;
168 if (buf[3] & 0x20) // Adaptation field is present
169 datalen -= (buf[4] + 1);
171 UCHAR* curbuf =buf+ (TS_SIZE - datalen);
175 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
176 int pmtpid = (*(curbuf+11)<< 8) | *(curbuf+12);
177 if ((pmtpid >> 13) != 0x07)
179 Log::getInstance()->log("findPTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(curbuf+11),*(curbuf+12), (pmtpid >> 13));
183 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
187 } else if (pid == PMTPID) { //PMT
188 int sectionlength = ((*(curbuf+2) << 8) & 0x0F ) | *(buf+3);
189 //sectionlength += 4; //include header but subtract crc in the end...
190 int p = 13; //skip fixed part of pmt
191 while ( p < sectionlength) {
192 int streamtype = *(curbuf+p);
194 int foundpid = (*(curbuf+p)<< 8) | *(curbuf+p+1);
195 p += 2; //skip ES Pid
196 int eslength = ((*(curbuf+p) << 8) & 0x0F ) | *(curbuf+p+1);
197 p += 2; //skip ES length
198 if ((foundpid >> 13) != 0x07)
200 Log::getInstance()->log("findPTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
204 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
206 if (streamtype==3 || streamtype ==4) {
210 p += eslength; //skip es descriptor
212 } else if (pid == scanaid) {
213 // UINT framelength = ((UINT)curbuf[4] << 8) | curbuf[5]; UNUSED?
215 if ( curbuf[7] & 0x80 ) // PTS_DTS_flags indicate that PTS is present
217 *dest = ( (ULLONG)(curbuf[9] & 0x0E) << 29 ) |
218 ( (ULLONG)(curbuf[10]) << 22 ) |
219 ( (ULLONG)(curbuf[11] & 0xFE) << 14 ) |
220 ( (ULLONG)(curbuf[12]) << 7 ) |
221 ( (ULLONG)(curbuf[13] & 0xFE) >> 1 );
233 void DemuxerTS::setFrameNum(ULONG frame)
235 frameCounting = true;
238 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setFrameNum %d", frame);
241 void DemuxerTS::setPacketNum(ULONG npacket)
243 packetCounting = true;
244 packetNumber = npacket;
245 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setPacketNum %d", npacket);
248 int DemuxerTS::put(UCHAR* buf, int len)
250 int ret = 0; // return number of bytes consumed
252 bool misaligned_mess=false;
255 if (len >= TS_SIZE + 1 - partPacket)
256 { // Remainder of partial packet is available, plus one
257 memcpy(store+partPacket, buf, TS_SIZE - partPacket);
258 ret += TS_SIZE - partPacket;
259 buf += TS_SIZE - partPacket;
260 len -= TS_SIZE - partPacket;
261 partPacket = TS_SIZE;
263 { // Packet is properly terminated
264 int rc = processTS(store);
266 partPacket = 0; // Successfully processed
268 return ret; // Try again later.
271 { // Packet not terminated. Find another candidate, and shift store
272 if (!misaligned_mess) {
273 Log::getInstance()->log("TS Demuxer", Log::ERR, "TS Misaligned!A");
274 misaligned_mess=true; // do not alarm more than once
277 while (search < partPacket && store[search] != TS_SIG)
279 partPacket -= search;
280 if (partPacket) memcpy(store, store+search, partPacket);
284 { // Still don't have complete packet. Consume what we do have.
285 memcpy(store+partPacket, buf, len);
292 // Position ourselves at a candidate TS packet
293 while (len > 0 && *buf != TS_SIG)
295 if (!misaligned_mess) {
296 Log::getInstance()->log("TS Demuxer", Log::ERR, "TS Misaligned!B");
297 misaligned_mess=true; // do not alarm more than once
304 if (len < TS_SIZE + 1)
305 { // Not enough data. Store what we have.
306 memcpy(store, buf, len);
312 if (buf[TS_SIZE] != TS_SIG)
313 { // Not terminated correctly.
315 while (len > 0 && *buf != TS_SIG)
322 int rc = processTS(buf);
324 { // Successfully processed
325 buf += TS_SIZE; ret += TS_SIZE; len -= TS_SIZE;
328 { // Processing failed.
337 int DemuxerTS::processTS(UCHAR* buf)
339 int datalen = TS_SIZE - 4;
341 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
342 UCHAR payload = buf[1] & 0x40;
345 if (buf[3] & 0x20) // Adaptation field is present
346 datalen -= (buf[4] + 1);
347 if (datalen < 0) // Error in stream TODO log this
349 if (datalen == 0) // Null packet
351 // if (!(buf[3] &0x10)) return 1; // no payload
352 buf += (TS_SIZE - datalen);
357 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
358 int pmtpid = (*(buf+11)<< 8) | *(buf+12);
359 if ((pmtpid >> 13) != 0x07)
361 Log::getInstance()->log("ProcessTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(buf+11),*(buf+12), (pmtpid >> 13));
365 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
372 int sectionlength = ((*(buf+2) << 8) & 0x0F ) | *(buf+3);
373 //sectionlength += 4; //include header but subtract crc in the end...
374 int p = 13; //skip fixed part of pmt
375 Channel new_channelinfo;
376 new_channelinfo.numAPids=0;
377 new_channelinfo.numDPids=0;
378 new_channelinfo.numSPids=0;
379 new_channelinfo.number=0;
380 new_channelinfo.type=VDR::RADIO;
381 new_channelinfo.name=NULL;
382 new_channelinfo.tpid=0xFFFFF; //unused, check this
383 new_channelinfo.vpid=0xFFFFF; //unused, check this
384 new_channelinfo.index=0;
386 new_channelinfo.apids.clear();
387 new_channelinfo.dpids.clear();
388 new_channelinfo.spids.clear();
390 while ( p < sectionlength) {
391 int streamtype = *(buf+p);
393 int foundpid = (*(buf+p)<< 8) | *(buf+p+1);
394 p += 2; //skip ES Pid
395 int eslength = ((*(buf+p) << 8) & 0x0F ) | *(buf+p+1);
396 p += 2; //skip ES length
397 if ((foundpid >> 13) != 0x07)
399 Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
403 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
407 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDPID is %x %x", foundpid,streamtype);
410 case 0x1B: //MPEG 4 for future use
413 if (foundpid != getVID())
415 new_channelinfo.type=VDR::VIDEO;
416 new_channelinfo.vstreamtype=streamtype;
417 new_channelinfo.vpid=foundpid;
418 if (streamtype==0x1b) h264=true;
421 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "Set video PID to %x", foundpid);
423 case 0x0F: //AAC ADTS packaging
424 case 0x11: // LATM packaging
428 newapid.pid = foundpid;
430 newapid.type=streamtype;
433 while (pos< eslength && nolang) {
434 switch (buf[p+pos]) {
436 newapid.desc[0]=buf[p+pos+2];
437 newapid.desc[1]=buf[p+pos+3];
438 newapid.desc[2]=buf[p+pos+4];
441 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDLANG is %s", newapid.desc);
448 new_channelinfo.apids.push_back(newapid);
449 new_channelinfo.numAPids++;
453 case 6: { //Private Data
455 newapid.pid = foundpid;
456 newapid.desc[0]=0; //set it in player
462 while (pos< eslength && (notfound || nolang)) {
463 switch (buf[p+pos]) {
464 case 0x7A: // Enhanced Ac3 Desriptor
465 case 0x6A: {//Ac3 descriptor
466 newapid.type=buf[p+pos];
471 case 0x59: {//SubtitlingDescriptor
473 newapid.type=buf[p+pos];
474 newapid.desc[0]=buf[p+pos+2];
475 newapid.desc[1]=buf[p+pos+3];
476 newapid.desc[2]=buf[p+pos+4];
478 newapid.data1=(buf[p+pos+5]<<8) |(buf[p+pos+6]);
479 newapid.data2=(buf[p+pos+7]<<8) |(buf[p+pos+8]);
480 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDSUB is %s", newapid.desc);
485 newapid.desc[0]=buf[p+pos+2];
486 newapid.desc[1]=buf[p+pos+3];
487 newapid.desc[2]=buf[p+pos+4];
490 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDLANG is %s", newapid.desc);
494 new_channelinfo.tpid=foundpid;
501 new_channelinfo.dpids.push_back(newapid);
502 new_channelinfo.numDPids++;
503 } else if (type==2) {
504 new_channelinfo.spids.push_back(newapid);
505 new_channelinfo.numSPids++;
509 default://TODO how about subtitles and second audio pids
514 p += eslength; //skip es descriptor
519 bool audioPIDpresent=false; //Check if pids chnages
521 for (i=0;i<channelinfo.numAPids;i++) {
522 if (aID == (int)channelinfo.apids[i].pid) {
523 audioPIDpresent=true;
526 for (i=0;i<channelinfo.numDPids && (! audioPIDpresent);i++) {
527 if (aID == (int)channelinfo.dpids[i].pid) {
528 audioPIDpresent=true;
531 if (! audioPIDpresent || getAID() == 0) {
536 Control* control = Control::getInstance();
538 if (channelinfo.numDPids > 0 && Audio::getInstance()->maysupportAc3())
541 while (j < channelinfo.numDPids)
543 int newpref = control->getLangPref(false, channelinfo.dpids[j].desc);
544 if (Audio::getInstance()->streamTypeSupported(channelinfo.dpids[j].type)
545 && (prefered < 0 || newpref < prefered))
555 if (channelinfo.numAPids > 0)
558 while (j < channelinfo.numAPids)
560 int newpref = control->getLangPref(false, channelinfo.apids[j].desc);
561 if (Audio::getInstance()->streamTypeSupported(channelinfo.apids[j].type)
562 && (prefered < 0 || newpref < prefered))
573 setAID(channelinfo.dpids[selected].pid,1,channelinfo.dpids[selected].type,false);
574 Audio::getInstance()->setStreamType(Audio::MPEG2_PES);
576 setAID(channelinfo.apids[selected].pid,0,channelinfo.apids[selected].type,false);
577 Audio::getInstance()->setStreamType(Audio::MPEG2_PES);
584 if (channelinfo.numSPids) {
586 while (j < channelinfo.numSPids)
588 int newpref = control->getLangPref(true, channelinfo.spids[j].desc);
589 if ( (prefered < 0 || newpref < prefered))
599 setSubID(channelinfo.spids[selected].pid);
604 channelinfo=new_channelinfo;
607 havechannelinfo=true;
621 parseTSPacketDetails(vPacket);
624 rc = submitPacket(vPacket);
634 parseTSPacketDetails(aPacket);
637 rc = submitPacket(aPacket);
647 parseTSPacketDetails(subPacket);
650 rc = submitPacket(subPacket);
654 if (isteletextdecoded && pid == tID)
660 parseTSPacketDetails(tPacket);
663 rc = submitPacket(tPacket);
667 if (rc == 0) return 0;
672 vPacket.init(PESTYPE_VID0);
673 buf += 6; datalen -= 6;
680 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
684 aPacket.init(PESTYPE_AUD0);
687 buf += 6; datalen -= 6;
691 subPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_DVBSUBTITLE0);
692 subLength = (buf[4] << 8) + buf[5];
693 buf += 6; datalen -= 6;
695 if (isteletextdecoded && pid == tID)
697 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
698 buf += 6; datalen -= 6;
702 if ( (pid == vID && vActive) ||
703 (pid == aID && aActive) ||
704 (pid == tID && tActive) ||
705 (pid == subID && subActive) )
707 PESPacket* packet = NULL;
708 if (pid == vID) packet = &vPacket;
709 if (pid == aID) packet = &aPacket;
713 if (pid == tID) packet = &tPacket;
716 if (packet->write(buf, datalen) == 0)
717 { // Writing to packet failed. It has overflowed.
720 parseTSPacketDetails(*packet);
723 if (submitPacket(*packet) == 0) return 0;
726 packet->write((UCHAR*)"\200\000\000", 3);
727 packet->write(buf, datalen);
732 if (pid == subID && subActive && subPacket.getLength() == subLength)
734 parsePacketDetails(subPacket);
735 //Log::getInstance()->log("DEMUXERTS", Log::DEBUG, "SUBMITTING A SUBTITLE PACKET %d %x", subLength, subPacket.getSubstream());
736 submitPacket(subPacket);
743 ULONG DemuxerTS::getPacketNum()
748 ULONG DemuxerTS::getFrameNumFromPTS(ULLONG pts)
750 ULLONG difference = (1LL<<33);
752 int total = 0, actual = 0;
753 if (pts==0) return 0; //we are in startup
754 pts_map_mutex.lock();
755 PTSMap::iterator iter = pts_map.begin();
756 while (iter != pts_map.end())
759 //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts1 %lld pts2 %lld", pts, iter->pts);
760 if (PTSDifference(iter->pts, pts) < PTS_ALLOWANCE)
763 ref_frame = iter->frame;
767 ULLONG newdiff = PTSDifference(pts, iter->pts);
768 if (newdiff < difference)
770 difference = newdiff;
771 ref_frame = iter->frame;
776 if (total > 1 && actual == 1) // We are using the most recent PTS ref.
777 { // Delete the rest.
778 iter = pts_map.begin(); iter++;
779 pts_map.erase(iter, pts_map.end());
781 pts_map_mutex.unlock();
783 //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts %lld deleted %d difference %lld", pts, total,difference);
785 if (difference == (1LL<<33))
786 return 0; // We cannot make sense of the pts
788 return ref_frame + difference * fps / 90000;
792 void DemuxerTS::parseTSPacketDetails(PESPacket &packet) // Only important stuff for paket counting reminas
794 parsePacketDetails(packet);
795 if (packetCounting && packet.getPacketType() >= PESTYPE_AUD0 &&
796 packet.getPacketType() <= PESTYPE_AUDMAX)
800 UINT pictsinpacket=packet.countPictureHeaders(h264,pinfo);
803 /* if (!doubledframerate)
805 numpicts=pictsinpacket;
809 numpicts=(pictsinpacket+framereserve)>>1;
810 framereserve=(pictsinpacket+framereserve)%2;
814 if (frameCounting && numpicts &&
815 packet.getPacketType() >= PESTYPE_VID0 &&
816 packet.getPacketType() <= PESTYPE_VIDMAX)
818 frameNumber+=numpicts;
819 ULONG frame_num = frameNumber;
820 if ((h264 || packet.findSeqHeader(h264) > 1) && packet.hasPTS())
823 pts_map_mutex.lock();
826 me.pts = packet.getPTS();
827 me.frame = frame_num;
828 pts_map_mutex.unlock();
829 pts_map_mutex.lock();
830 pts_map.push_front(me);
832 me = pts_map.front();
833 pts_map_mutex.unlock();
835 //UINT fps = Video::getInstance()->getFPS();
837 // if (doubledframerate) tfps*=2.;
838 long long pts_expected = me.pts + 90000LL*((long long)(((double)(frame_num - me.frame)) / tfps));
840 while (pts_expected < 0) pts_expected += (1LL<<33);
841 while (pts_expected > (1LL<<33)) pts_expected -= (1LL<<33);
843 // this was a workaround for a vdr bug, now fixed, for older recordings deleter the index file
846 if (!doubledframerate
847 &&(abs((long long)PTSDistance(pts_expected, packet.getPTS())-1800) <= 1
848 || abs((long long)PTSDistance(pts_expected, packet.getPTS())-1501) <= 1)) {
849 doubledframerate=true; //Detected p50 or p60
852 if (PTSDistance(pts_expected, packet.getPTS()) > PTS_JUMP_MARGIN) // PTS jump!
854 me.pts = packet.getPTS();
855 me.frame = frame_num;
856 pts_map_mutex.lock();
857 pts_map.push_front(me);
858 pts_map_mutex.unlock();
865 bool DemuxerTS::scanForVideo(UCHAR* buf, UINT len, bool &ish264)
869 while (len >= TS_SIZE)
871 if (*buf != TS_SIG) {buf++;len--; continue;}
873 //Pattern scanning won't work for ts
876 int datalen = TS_SIZE - 4;
877 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
878 UCHAR payload = buf[1] & 0x40;
880 if (buf[3] & 0x20) // Adaptation field is present
881 datalen -= (buf[4] + 1);
883 UCHAR* curbuf =buf+ (TS_SIZE - datalen);
886 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
887 int pmtpid = (*(curbuf+11)<< 8) | *(curbuf+12);
888 if ((pmtpid >> 13) != 0x07)
890 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(curbuf+11),*(curbuf+12), (pmtpid >> 13));
894 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
896 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "PMT pid%02x",pmtpid );
899 } else if (pid == pmtpidy) { //PMT
900 int sectionlength = ((*(curbuf+2) << 8) & 0x0F ) | *(buf+3);
901 //sectionlength += 4; //include header but subtract crc in the end...
902 int p = 13; //skip fixed part of pmt
903 while ( p < sectionlength) {
904 int streamtype = *(curbuf+p);
906 int foundpid = (*(curbuf+p)<< 8) | *(curbuf+p+1);
907 p += 2; //skip ES Pid
908 int eslength = ((*(curbuf+p) << 8) & 0x0F ) | *(curbuf+p+1);
909 p += 2; //skip ES length
910 if ((foundpid >> 13) != 0x07)
912 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
916 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
917 // int pos=0; UNUSED?
918 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Pid found %02x type %02x",foundpid ,streamtype);
919 if (streamtype==1 || streamtype ==2) {
921 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Found Mpeg2 Video");
924 if (streamtype==0x1b) {
926 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Found h264 Video");
930 p += eslength; //skip es descriptor
943 UINT DemuxerTS::stripAudio(UCHAR* buf, UINT len) //it has to be adapted
945 //This function strips all TS Headers and non video payload
950 while (readpos < len ) {
951 if (buf[readpos] != TS_SIG) {readpos++; continue;}
952 UINT oldreadpos=readpos;
954 int datalen = TS_SIZE - 4;
955 int pid = ( (buf[readpos+1] & 0x1F) << 8 ) | buf[readpos+2];
956 UCHAR payload = buf[readpos+1] & 0x40;
957 if (buf[readpos+3] & 0x20) { // Adaptation field is present
958 datalen -= (buf[readpos+4] + 1);
960 if (datalen < 0) {// Error in stream TODO log this
963 if (datalen == 0) {// Null packet
964 readpos=oldreadpos+TS_SIZE;
967 readpos += (TS_SIZE - datalen);
968 UINT towrite=min(datalen,len-readpos);
972 parsePacketDetails(destpaket);
973 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
974 writepos+=destpaket.getSize();
976 destpaket.init(PESTYPE_VID0);
977 readpos += 6; towrite -= 6;
982 if (!destpaket.write(buf+readpos,towrite)) {
983 parsePacketDetails(destpaket);
984 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
985 writepos+=destpaket.getSize();
986 destpaket.truncate();
987 destpaket.write((UCHAR*)"\200\000\000", 3);
988 destpaket.write(buf+readpos,towrite);
996 readpos=oldreadpos+TS_SIZE;
998 parsePacketDetails(destpaket);
999 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
1000 writepos+=destpaket.getSize();