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 void DemuxerTS::flush()
65 havechannelinfo=false;
67 vPacket.init(PESTYPE_VID0);
71 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
75 aPacket.init(PESTYPE_AUD0);
78 subPacket.init(PESTYPE_PRIVATE_1);
79 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
86 // doubledframerate=false;
90 int DemuxerTS::scan(UCHAR *buf, int len)
95 return PESTYPE_PRIVATE_1;
102 void DemuxerTS::setVID(int p_vID)
105 vPacket.init(PESTYPE_VID0);
109 void DemuxerTS::setAID(int p_aID, int type, int streamtype)
113 astreamtype = streamtype;
117 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
118 setAudioStream(PESTYPE_SUBSTREAM_AC30);
122 aPacket.init(PESTYPE_AUD0);
123 setAudioStream(PESTYPE_AUD0);
129 void DemuxerTS::setSubID(int p_subID)
132 subPacket.init(PESTYPE_PRIVATE_1);
137 void DemuxerTS::setTID(int p_tID)
140 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
148 int DemuxerTS::findPTS(UCHAR* buf, int len, ULLONG* dest)
152 while (len >= TS_SIZE)
154 if (*buf != TS_SIG) {buf++;len--; continue;}
156 //Pattern scanning won't work for ts
159 int datalen = TS_SIZE - 4;
160 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
161 UCHAR payload = buf[1] & 0x40;
163 if (buf[3] & 0x20) // Adaptation field is present
164 datalen -= (buf[4] + 1);
166 UCHAR* curbuf =buf+ (TS_SIZE - datalen);
170 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
171 int pmtpid = (*(curbuf+11)<< 8) | *(curbuf+12);
172 if ((pmtpid >> 13) != 0x07)
174 Log::getInstance()->log("findPTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(curbuf+11),*(curbuf+12), (pmtpid >> 13));
178 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
182 } else if (pid == PMTPID) { //PMT
183 int sectionlength = ((*(curbuf+2) << 8) & 0x0F ) | *(buf+3);
184 //sectionlength += 4; //include header but subtract crc in the end...
185 int p = 13; //skip fixed part of pmt
186 while ( p < sectionlength) {
187 int streamtype = *(curbuf+p);
189 int foundpid = (*(curbuf+p)<< 8) | *(curbuf+p+1);
190 p += 2; //skip ES Pid
191 int eslength = ((*(curbuf+p) << 8) & 0x0F ) | *(curbuf+p+1);
192 p += 2; //skip ES length
193 if ((foundpid >> 13) != 0x07)
195 Log::getInstance()->log("findPTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
199 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
201 if (streamtype==3 || streamtype ==4) {
205 p += eslength; //skip es descriptor
207 } else if (pid == scanaid) {
208 // UINT framelength = ((UINT)curbuf[4] << 8) | curbuf[5]; UNUSED?
210 if ( curbuf[7] & 0x80 ) // PTS_DTS_flags indicate that PTS is present
212 *dest = ( (ULLONG)(curbuf[9] & 0x0E) << 29 ) |
213 ( (ULLONG)(curbuf[10]) << 22 ) |
214 ( (ULLONG)(curbuf[11] & 0xFE) << 14 ) |
215 ( (ULLONG)(curbuf[12]) << 7 ) |
216 ( (ULLONG)(curbuf[13] & 0xFE) >> 1 );
228 void DemuxerTS::setFrameNum(ULONG frame)
230 frameCounting = true;
233 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setFrameNum %d", frame);
236 void DemuxerTS::setPacketNum(ULONG npacket)
238 packetCounting = true;
239 packetNumber = npacket;
240 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setPacketNum %d", npacket);
243 int DemuxerTS::put(UCHAR* buf, int len)
245 int ret = 0; // return number of bytes consumed
247 bool misaligned_mess=false;
250 if (len >= TS_SIZE + 1 - partPacket)
251 { // Remainder of partial packet is available, plus one
252 memcpy(store+partPacket, buf, TS_SIZE - partPacket);
253 ret += TS_SIZE - partPacket;
254 buf += TS_SIZE - partPacket;
255 len -= TS_SIZE - partPacket;
256 partPacket = TS_SIZE;
258 { // Packet is properly terminated
259 int rc = processTS(store);
261 partPacket = 0; // Successfully processed
263 return ret; // Try again later.
266 { // Packet not terminated. Find another candidate, and shift store
267 if (!misaligned_mess) {
268 Log::getInstance()->log("TS Demuxer", Log::ERR, "TS Misaligned!A");
269 misaligned_mess=true; // do not alarm more than once
272 while (search < partPacket && store[search] != TS_SIG)
274 partPacket -= search;
275 if (partPacket) memcpy(store, store+search, partPacket);
279 { // Still don't have complete packet. Consume what we do have.
280 memcpy(store+partPacket, buf, len);
287 // Position ourselves at a candidate TS packet
288 while (len > 0 && *buf != TS_SIG)
290 if (!misaligned_mess) {
291 Log::getInstance()->log("TS Demuxer", Log::ERR, "TS Misaligned!B");
292 misaligned_mess=true; // do not alarm more than once
299 if (len < TS_SIZE + 1)
300 { // Not enough data. Store what we have.
301 memcpy(store, buf, len);
307 if (buf[TS_SIZE] != TS_SIG)
308 { // Not terminated correctly.
310 while (len > 0 && *buf != TS_SIG)
317 int rc = processTS(buf);
319 { // Successfully processed
320 buf += TS_SIZE; ret += TS_SIZE; len -= TS_SIZE;
323 { // Processing failed.
332 int DemuxerTS::processTS(UCHAR* buf)
334 int datalen = TS_SIZE - 4;
336 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
337 UCHAR payload = buf[1] & 0x40;
340 if (buf[3] & 0x20) // Adaptation field is present
341 datalen -= (buf[4] + 1);
342 if (datalen < 0) // Error in stream TODO log this
344 if (datalen == 0) // Null packet
346 // if (!(buf[3] &0x10)) return 1; // no payload
347 buf += (TS_SIZE - datalen);
352 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
353 int pmtpid = (*(buf+11)<< 8) | *(buf+12);
354 if ((pmtpid >> 13) != 0x07)
356 Log::getInstance()->log("ProcessTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(buf+11),*(buf+12), (pmtpid >> 13));
360 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
367 int sectionlength = ((*(buf+2) << 8) & 0x0F ) | *(buf+3);
368 //sectionlength += 4; //include header but subtract crc in the end...
369 int p = 13; //skip fixed part of pmt
370 Channel new_channelinfo;
371 new_channelinfo.numAPids=0;
372 new_channelinfo.numDPids=0;
373 new_channelinfo.numSPids=0;
374 new_channelinfo.number=0;
375 new_channelinfo.type=VDR::RADIO;
376 new_channelinfo.name=NULL;
377 new_channelinfo.tpid=0xFFFFF; //unused, check this
378 new_channelinfo.vpid=0xFFFFF; //unused, check this
379 new_channelinfo.index=0;
381 new_channelinfo.apids.clear();
382 new_channelinfo.dpids.clear();
383 new_channelinfo.spids.clear();
385 while ( p < sectionlength) {
386 int streamtype = *(buf+p);
388 int foundpid = (*(buf+p)<< 8) | *(buf+p+1);
389 p += 2; //skip ES Pid
390 int eslength = ((*(buf+p) << 8) & 0x0F ) | *(buf+p+1);
391 p += 2; //skip ES length
392 if ((foundpid >> 13) != 0x07)
394 Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
398 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
402 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDPID is %x %x", foundpid,streamtype);
405 case 0x1B: //MPEG 4 for future use
408 if (foundpid != getVID())
410 new_channelinfo.type=VDR::VIDEO;
411 new_channelinfo.vstreamtype=streamtype;
412 new_channelinfo.vpid=foundpid;
413 if (streamtype==0x1b) h264=true;
416 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "Set video PID to %x", foundpid);
418 case 0x0F: //AAC ADTS packaging
419 case 0x11: // LATM packaging
423 newapid.pid = foundpid;
425 newapid.type=streamtype;
428 while (pos< eslength && nolang) {
429 switch (buf[p+pos]) {
431 newapid.desc[0]=buf[p+pos+2];
432 newapid.desc[1]=buf[p+pos+3];
433 newapid.desc[2]=buf[p+pos+4];
436 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDLANG is %s", newapid.desc);
443 new_channelinfo.apids.push_back(newapid);
444 new_channelinfo.numAPids++;
445 if (getAID() == 0 && Audio::getInstance()->streamTypeSupported(streamtype)) { //set unset AID to first audio pid that reports itself
446 setAID(foundpid,0,streamtype);
447 Log::getInstance()->log("ProcessTS", Log::DEBUG, "Set audio PID to %x", foundpid);
451 case 6: { //Private Data
453 newapid.pid = foundpid;
454 newapid.desc[0]=0; //set it in player
460 while (pos< eslength && (notfound || nolang)) {
461 switch (buf[p+pos]) {
462 case 0x7A: // Enhanced Ac3 Desriptor
463 case 0x6A: {//Ac3 descriptor
464 newapid.type=buf[p+pos];
469 case 0x59: {//SubtitlingDescriptor
471 newapid.type=buf[p+pos];
472 newapid.desc[0]=buf[p+pos+2];
473 newapid.desc[1]=buf[p+pos+3];
474 newapid.desc[2]=buf[p+pos+4];
476 newapid.data1=(buf[p+pos+5]<<8) |(buf[p+pos+6]);
477 newapid.data2=(buf[p+pos+7]<<8) |(buf[p+pos+8]);
478 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDSUB is %s", newapid.desc);
483 newapid.desc[0]=buf[p+pos+2];
484 newapid.desc[1]=buf[p+pos+3];
485 newapid.desc[2]=buf[p+pos+4];
488 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDLANG is %s", newapid.desc);
492 new_channelinfo.tpid=foundpid;
499 new_channelinfo.dpids.push_back(newapid);
500 new_channelinfo.numDPids++;
501 } else if (type==2) {
502 new_channelinfo.spids.push_back(newapid);
503 new_channelinfo.numSPids++;
507 default://TODO how about subtitles and second audio pids
512 p += eslength; //skip es descriptor
516 bool audioPIDpresent=false; //Check if pids chnages
518 for (i=0;i<channelinfo.numAPids;i++) {
519 if (aID == (int)channelinfo.apids[i].pid) {
520 audioPIDpresent=true;
523 for (i=0;i<channelinfo.numDPids && (! audioPIDpresent);i++) {
524 if (aID == (int)channelinfo.dpids[i].pid) {
525 audioPIDpresent=true;
528 if (! audioPIDpresent) {
530 if (channelinfo.numAPids>0) {
532 while (j<channelinfo.numAPids && !found) {
533 if (Audio::getInstance()->streamTypeSupported(channelinfo.apids[j].type)) {
535 setAID(channelinfo.apids[j].pid,0,channelinfo.apids[j].type);
541 if (channelinfo.numDPids>0 && !found) {
543 while (j<channelinfo.numDPids && !found) {
544 if (Audio::getInstance()->streamTypeSupported(channelinfo.dpids[j].type)) {
546 setAID(channelinfo.dpids[j].pid,1,channelinfo.dpids[j].type);
553 channelinfo=new_channelinfo;
556 havechannelinfo=true;
570 parseTSPacketDetails(vPacket);
573 rc = submitPacket(vPacket);
583 parseTSPacketDetails(aPacket);
586 rc = submitPacket(aPacket);
596 parseTSPacketDetails(subPacket);
599 rc = submitPacket(subPacket);
603 if (isteletextdecoded && pid == tID)
609 parseTSPacketDetails(tPacket);
612 rc = submitPacket(tPacket);
616 if (rc == 0) return 0;
621 vPacket.init(PESTYPE_VID0);
622 buf += 6; datalen -= 6;
629 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
633 aPacket.init(PESTYPE_AUD0);
636 buf += 6; datalen -= 6;
640 subPacket.init(PESTYPE_PRIVATE_1);
641 subLength = (buf[4] << 8) + buf[5];
642 buf += 6; datalen -= 6;
644 if (isteletextdecoded && pid == tID)
646 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
647 buf += 6; datalen -= 6;
651 if ( (pid == vID && vActive) ||
652 (pid == aID && aActive) ||
653 (pid == tID && tActive) ||
654 (pid == subID && subActive) )
656 PESPacket* packet = NULL;
657 if (pid == vID) packet = &vPacket;
658 if (pid == aID) packet = &aPacket;
662 if (pid == tID) packet = &tPacket;
665 if (packet->write(buf, datalen) == 0)
666 { // Writing to packet failed. It has overflowed.
669 parseTSPacketDetails(*packet);
672 if (submitPacket(*packet) == 0) return 0;
675 packet->write((UCHAR*)"\200\000\000", 3);
676 packet->write(buf, datalen);
681 if (pid == subID && subActive && subPacket.getLength() == subLength)
683 parsePacketDetails(subPacket);
684 Log::getInstance()->log("DEMUXERTS", Log::DEBUG, "SUBMITTING A SUBTITLE PACKET %d %x", subLength, subPacket.getSubstream());
685 submitPacket(subPacket);
692 ULONG DemuxerTS::getPacketNum()
697 ULONG DemuxerTS::getFrameNumFromPTS(ULLONG pts)
699 ULLONG difference = (1LL<<33);
701 int total = 0, actual = 0;
702 if (pts==0) return 0; //we are in startup
703 pts_map_mutex.Lock();
704 PTSMap::iterator iter = pts_map.begin();
705 while (iter != pts_map.end())
708 //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts1 %lld pts2 %lld", pts, iter->pts);
709 if (PTSDifference(iter->pts, pts) < PTS_ALLOWANCE)
712 ref_frame = iter->frame;
716 ULLONG newdiff = PTSDifference(pts, iter->pts);
717 if (newdiff < difference)
719 difference = newdiff;
720 ref_frame = iter->frame;
725 if (total > 1 && actual == 1) // We are using the most recent PTS ref.
726 { // Delete the rest.
727 iter = pts_map.begin(); iter++;
728 pts_map.erase(iter, pts_map.end());
730 pts_map_mutex.Unlock();
732 //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts %lld deleted %d difference %lld", pts, total,difference);
734 if (difference == (1LL<<33))
735 return 0; // We cannot make sense of the pts
737 return ref_frame + difference * fps / 90000;
741 void DemuxerTS::parseTSPacketDetails(PESPacket &packet) // Only important stuff for paket counting reminas
743 parsePacketDetails(packet);
744 if (packetCounting && packet.getPacketType() >= PESTYPE_AUD0 &&
745 packet.getPacketType() <= PESTYPE_AUDMAX)
749 UINT pictsinpacket=packet.countPictureHeaders(h264);
752 /* if (!doubledframerate)
754 numpicts=pictsinpacket;
758 numpicts=(pictsinpacket+framereserve)>>1;
759 framereserve=(pictsinpacket+framereserve)%2;
763 if (frameCounting && numpicts &&
764 packet.getPacketType() >= PESTYPE_VID0 &&
765 packet.getPacketType() <= PESTYPE_VIDMAX)
767 frameNumber+=numpicts;
768 ULONG frame_num = frameNumber;
769 if ((h264 || packet.findSeqHeader(h264) > 1) && packet.hasPTS())
772 pts_map_mutex.Lock();
775 me.pts = packet.getPTS();
776 me.frame = frame_num;
777 pts_map_mutex.Unlock();
778 pts_map_mutex.Lock();
779 pts_map.push_front(me);
781 me = pts_map.front();
782 pts_map_mutex.Unlock();
784 //UINT fps = Video::getInstance()->getFPS();
786 // if (doubledframerate) tfps*=2.;
787 long long pts_expected = me.pts + 90000LL*((long long)(((double)(frame_num - me.frame)) / tfps));
789 while (pts_expected < 0) pts_expected += (1LL<<33);
790 while (pts_expected > (1LL<<33)) pts_expected -= (1LL<<33);
792 // this was a workaround for a vdr bug, now fixed, for older recordings deleter the index file
795 if (!doubledframerate
796 &&(abs((long long)PTSDistance(pts_expected, packet.getPTS())-1800) <= 1
797 || abs((long long)PTSDistance(pts_expected, packet.getPTS())-1501) <= 1)) {
798 doubledframerate=true; //Detected p50 or p60
801 if (PTSDistance(pts_expected, packet.getPTS()) > PTS_JUMP_MARGIN) // PTS jump!
803 me.pts = packet.getPTS();
804 me.frame = frame_num;
805 pts_map_mutex.Lock();
806 pts_map.push_front(me);
807 pts_map_mutex.Unlock();
814 bool DemuxerTS::scanForVideo(UCHAR* buf, UINT len, bool &ish264)
818 while (len >= TS_SIZE)
820 if (*buf != TS_SIG) {buf++;len--; continue;}
822 //Pattern scanning won't work for ts
825 int datalen = TS_SIZE - 4;
826 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
827 UCHAR payload = buf[1] & 0x40;
829 if (buf[3] & 0x20) // Adaptation field is present
830 datalen -= (buf[4] + 1);
832 UCHAR* curbuf =buf+ (TS_SIZE - datalen);
835 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
836 int pmtpid = (*(curbuf+11)<< 8) | *(curbuf+12);
837 if ((pmtpid >> 13) != 0x07)
839 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(curbuf+11),*(curbuf+12), (pmtpid >> 13));
843 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
845 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "PMT pid%02x",pmtpid );
848 } else if (pid == pmtpidy) { //PMT
849 int sectionlength = ((*(curbuf+2) << 8) & 0x0F ) | *(buf+3);
850 //sectionlength += 4; //include header but subtract crc in the end...
851 int p = 13; //skip fixed part of pmt
852 while ( p < sectionlength) {
853 int streamtype = *(curbuf+p);
855 int foundpid = (*(curbuf+p)<< 8) | *(curbuf+p+1);
856 p += 2; //skip ES Pid
857 int eslength = ((*(curbuf+p) << 8) & 0x0F ) | *(curbuf+p+1);
858 p += 2; //skip ES length
859 if ((foundpid >> 13) != 0x07)
861 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
865 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
866 // int pos=0; UNUSED?
867 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Pid found %02x type %02x",foundpid ,streamtype);
868 if (streamtype==1 || streamtype ==2) {
870 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Found Mpeg2 Video");
873 if (streamtype==0x1b) {
875 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Found h264 Video");
879 p += eslength; //skip es descriptor
892 UINT DemuxerTS::stripAudio(UCHAR* buf, UINT len) //it has to be adapted
894 //This function strips all TS Headers and non video payload
899 while (readpos < len ) {
900 if (buf[readpos] != TS_SIG) {readpos++; continue;}
901 UINT oldreadpos=readpos;
903 int datalen = TS_SIZE - 4;
904 int pid = ( (buf[readpos+1] & 0x1F) << 8 ) | buf[readpos+2];
905 UCHAR payload = buf[readpos+1] & 0x40;
906 if (buf[readpos+3] & 0x20) { // Adaptation field is present
907 datalen -= (buf[readpos+4] + 1);
909 if (datalen < 0) {// Error in stream TODO log this
912 if (datalen == 0) {// Null packet
913 readpos=oldreadpos+TS_SIZE;
916 readpos += (TS_SIZE - datalen);
917 UINT towrite=min(datalen,len-readpos);
921 parsePacketDetails(destpaket);
922 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
923 writepos+=destpaket.getSize();
925 destpaket.init(PESTYPE_VID0);
926 readpos += 6; towrite -= 6;
931 if (!destpaket.write(buf+readpos,towrite)) {
932 parsePacketDetails(destpaket);
933 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
934 writepos+=destpaket.getSize();
935 destpaket.truncate();
936 destpaket.write((UCHAR*)"\200\000\000", 3);
937 destpaket.write(buf+readpos,towrite);
945 readpos=oldreadpos+TS_SIZE;
947 parsePacketDetails(destpaket);
948 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
949 writepos+=destpaket.getSize();