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, bool slivetv)
113 astreamtype = streamtype;
118 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
119 setAudioStream(PESTYPE_SUBSTREAM_AC30);
123 aPacket.init(PESTYPE_AUD0);
124 setAudioStream(PESTYPE_AUD0);
130 void DemuxerTS::setSubID(int p_subID)
133 subPacket.init(PESTYPE_PRIVATE_1);
138 void DemuxerTS::setTID(int p_tID)
141 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
149 int DemuxerTS::findPTS(UCHAR* buf, int len, ULLONG* dest)
153 while (len >= TS_SIZE)
155 if (*buf != TS_SIG) {buf++;len--; continue;}
157 //Pattern scanning won't work for ts
160 int datalen = TS_SIZE - 4;
161 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
162 UCHAR payload = buf[1] & 0x40;
164 if (buf[3] & 0x20) // Adaptation field is present
165 datalen -= (buf[4] + 1);
167 UCHAR* curbuf =buf+ (TS_SIZE - datalen);
171 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
172 int pmtpid = (*(curbuf+11)<< 8) | *(curbuf+12);
173 if ((pmtpid >> 13) != 0x07)
175 Log::getInstance()->log("findPTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(curbuf+11),*(curbuf+12), (pmtpid >> 13));
179 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
183 } else if (pid == PMTPID) { //PMT
184 int sectionlength = ((*(curbuf+2) << 8) & 0x0F ) | *(buf+3);
185 //sectionlength += 4; //include header but subtract crc in the end...
186 int p = 13; //skip fixed part of pmt
187 while ( p < sectionlength) {
188 int streamtype = *(curbuf+p);
190 int foundpid = (*(curbuf+p)<< 8) | *(curbuf+p+1);
191 p += 2; //skip ES Pid
192 int eslength = ((*(curbuf+p) << 8) & 0x0F ) | *(curbuf+p+1);
193 p += 2; //skip ES length
194 if ((foundpid >> 13) != 0x07)
196 Log::getInstance()->log("findPTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
200 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
202 if (streamtype==3 || streamtype ==4) {
206 p += eslength; //skip es descriptor
208 } else if (pid == scanaid) {
209 // UINT framelength = ((UINT)curbuf[4] << 8) | curbuf[5]; UNUSED?
211 if ( curbuf[7] & 0x80 ) // PTS_DTS_flags indicate that PTS is present
213 *dest = ( (ULLONG)(curbuf[9] & 0x0E) << 29 ) |
214 ( (ULLONG)(curbuf[10]) << 22 ) |
215 ( (ULLONG)(curbuf[11] & 0xFE) << 14 ) |
216 ( (ULLONG)(curbuf[12]) << 7 ) |
217 ( (ULLONG)(curbuf[13] & 0xFE) >> 1 );
229 void DemuxerTS::setFrameNum(ULONG frame)
231 frameCounting = true;
234 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setFrameNum %d", frame);
237 void DemuxerTS::setPacketNum(ULONG npacket)
239 packetCounting = true;
240 packetNumber = npacket;
241 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "setPacketNum %d", npacket);
244 int DemuxerTS::put(UCHAR* buf, int len)
246 int ret = 0; // return number of bytes consumed
248 bool misaligned_mess=false;
251 if (len >= TS_SIZE + 1 - partPacket)
252 { // Remainder of partial packet is available, plus one
253 memcpy(store+partPacket, buf, TS_SIZE - partPacket);
254 ret += TS_SIZE - partPacket;
255 buf += TS_SIZE - partPacket;
256 len -= TS_SIZE - partPacket;
257 partPacket = TS_SIZE;
259 { // Packet is properly terminated
260 int rc = processTS(store);
262 partPacket = 0; // Successfully processed
264 return ret; // Try again later.
267 { // Packet not terminated. Find another candidate, and shift store
268 if (!misaligned_mess) {
269 Log::getInstance()->log("TS Demuxer", Log::ERR, "TS Misaligned!A");
270 misaligned_mess=true; // do not alarm more than once
273 while (search < partPacket && store[search] != TS_SIG)
275 partPacket -= search;
276 if (partPacket) memcpy(store, store+search, partPacket);
280 { // Still don't have complete packet. Consume what we do have.
281 memcpy(store+partPacket, buf, len);
288 // Position ourselves at a candidate TS packet
289 while (len > 0 && *buf != TS_SIG)
291 if (!misaligned_mess) {
292 Log::getInstance()->log("TS Demuxer", Log::ERR, "TS Misaligned!B");
293 misaligned_mess=true; // do not alarm more than once
300 if (len < TS_SIZE + 1)
301 { // Not enough data. Store what we have.
302 memcpy(store, buf, len);
308 if (buf[TS_SIZE] != TS_SIG)
309 { // Not terminated correctly.
311 while (len > 0 && *buf != TS_SIG)
318 int rc = processTS(buf);
320 { // Successfully processed
321 buf += TS_SIZE; ret += TS_SIZE; len -= TS_SIZE;
324 { // Processing failed.
333 int DemuxerTS::processTS(UCHAR* buf)
335 int datalen = TS_SIZE - 4;
337 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
338 UCHAR payload = buf[1] & 0x40;
341 if (buf[3] & 0x20) // Adaptation field is present
342 datalen -= (buf[4] + 1);
343 if (datalen < 0) // Error in stream TODO log this
345 if (datalen == 0) // Null packet
347 // if (!(buf[3] &0x10)) return 1; // no payload
348 buf += (TS_SIZE - datalen);
353 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
354 int pmtpid = (*(buf+11)<< 8) | *(buf+12);
355 if ((pmtpid >> 13) != 0x07)
357 Log::getInstance()->log("ProcessTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(buf+11),*(buf+12), (pmtpid >> 13));
361 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
368 int sectionlength = ((*(buf+2) << 8) & 0x0F ) | *(buf+3);
369 //sectionlength += 4; //include header but subtract crc in the end...
370 int p = 13; //skip fixed part of pmt
371 Channel new_channelinfo;
372 new_channelinfo.numAPids=0;
373 new_channelinfo.numDPids=0;
374 new_channelinfo.numSPids=0;
375 new_channelinfo.number=0;
376 new_channelinfo.type=VDR::RADIO;
377 new_channelinfo.name=NULL;
378 new_channelinfo.tpid=0xFFFFF; //unused, check this
379 new_channelinfo.vpid=0xFFFFF; //unused, check this
380 new_channelinfo.index=0;
382 new_channelinfo.apids.clear();
383 new_channelinfo.dpids.clear();
384 new_channelinfo.spids.clear();
386 while ( p < sectionlength) {
387 int streamtype = *(buf+p);
389 int foundpid = (*(buf+p)<< 8) | *(buf+p+1);
390 p += 2; //skip ES Pid
391 int eslength = ((*(buf+p) << 8) & 0x0F ) | *(buf+p+1);
392 p += 2; //skip ES length
393 if ((foundpid >> 13) != 0x07)
395 Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
399 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
403 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDPID is %x %x", foundpid,streamtype);
406 case 0x1B: //MPEG 4 for future use
409 if (foundpid != getVID())
411 new_channelinfo.type=VDR::VIDEO;
412 new_channelinfo.vstreamtype=streamtype;
413 new_channelinfo.vpid=foundpid;
414 if (streamtype==0x1b) h264=true;
417 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "Set video PID to %x", foundpid);
419 case 0x0F: //AAC ADTS packaging
420 case 0x11: // LATM packaging
424 newapid.pid = foundpid;
426 newapid.type=streamtype;
429 while (pos< eslength && nolang) {
430 switch (buf[p+pos]) {
432 newapid.desc[0]=buf[p+pos+2];
433 newapid.desc[1]=buf[p+pos+3];
434 newapid.desc[2]=buf[p+pos+4];
437 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDLANG is %s", newapid.desc);
444 new_channelinfo.apids.push_back(newapid);
445 new_channelinfo.numAPids++;
446 if (getAID() == 0 && Audio::getInstance()->streamTypeSupported(streamtype)) { //set unset AID to first audio pid that reports itself
447 setAID(foundpid,0,streamtype,false);
448 Log::getInstance()->log("ProcessTS", Log::DEBUG, "Set audio PID to %x", foundpid);
452 case 6: { //Private Data
454 newapid.pid = foundpid;
455 newapid.desc[0]=0; //set it in player
461 while (pos< eslength && (notfound || nolang)) {
462 switch (buf[p+pos]) {
463 case 0x7A: // Enhanced Ac3 Desriptor
464 case 0x6A: {//Ac3 descriptor
465 newapid.type=buf[p+pos];
470 case 0x59: {//SubtitlingDescriptor
472 newapid.type=buf[p+pos];
473 newapid.desc[0]=buf[p+pos+2];
474 newapid.desc[1]=buf[p+pos+3];
475 newapid.desc[2]=buf[p+pos+4];
477 newapid.data1=(buf[p+pos+5]<<8) |(buf[p+pos+6]);
478 newapid.data2=(buf[p+pos+7]<<8) |(buf[p+pos+8]);
479 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDSUB is %s", newapid.desc);
484 newapid.desc[0]=buf[p+pos+2];
485 newapid.desc[1]=buf[p+pos+3];
486 newapid.desc[2]=buf[p+pos+4];
489 // Log::getInstance()->log("ProcessTS", Log::DEBUG, "FOUNDLANG is %s", newapid.desc);
493 new_channelinfo.tpid=foundpid;
500 new_channelinfo.dpids.push_back(newapid);
501 new_channelinfo.numDPids++;
502 } else if (type==2) {
503 new_channelinfo.spids.push_back(newapid);
504 new_channelinfo.numSPids++;
508 default://TODO how about subtitles and second audio pids
513 p += eslength; //skip es descriptor
517 bool audioPIDpresent=false; //Check if pids chnages
519 for (i=0;i<channelinfo.numAPids;i++) {
520 if (aID == (int)channelinfo.apids[i].pid) {
521 audioPIDpresent=true;
524 for (i=0;i<channelinfo.numDPids && (! audioPIDpresent);i++) {
525 if (aID == (int)channelinfo.dpids[i].pid) {
526 audioPIDpresent=true;
529 if (! audioPIDpresent) {
531 if (channelinfo.numAPids>0) {
533 while (j<channelinfo.numAPids && !found) {
534 if (Audio::getInstance()->streamTypeSupported(channelinfo.apids[j].type)) {
536 setAID(channelinfo.apids[j].pid,0,channelinfo.apids[j].type,false);
542 if (channelinfo.numDPids>0 && !found) {
544 while (j<channelinfo.numDPids && !found) {
545 if (Audio::getInstance()->streamTypeSupported(channelinfo.dpids[j].type)) {
547 setAID(channelinfo.dpids[j].pid,1,channelinfo.dpids[j].type,false);
554 channelinfo=new_channelinfo;
557 havechannelinfo=true;
571 parseTSPacketDetails(vPacket);
574 rc = submitPacket(vPacket);
584 parseTSPacketDetails(aPacket);
587 rc = submitPacket(aPacket);
597 parseTSPacketDetails(subPacket);
600 rc = submitPacket(subPacket);
604 if (isteletextdecoded && pid == tID)
610 parseTSPacketDetails(tPacket);
613 rc = submitPacket(tPacket);
617 if (rc == 0) return 0;
622 vPacket.init(PESTYPE_VID0);
623 buf += 6; datalen -= 6;
630 aPacket.init(PESTYPE_PRIVATE_1, PESTYPE_SUBSTREAM_AC30);
634 aPacket.init(PESTYPE_AUD0);
637 buf += 6; datalen -= 6;
641 subPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_DVBSUBTITLE0);
642 subLength = (buf[4] << 8) + buf[5];
643 buf += 6; datalen -= 6;
645 if (isteletextdecoded && pid == tID)
647 tPacket.init(PESTYPE_PRIVATE_1,PESTYPE_SUBSTREAM_TELETEXTMAX);
648 buf += 6; datalen -= 6;
652 if ( (pid == vID && vActive) ||
653 (pid == aID && aActive) ||
654 (pid == tID && tActive) ||
655 (pid == subID && subActive) )
657 PESPacket* packet = NULL;
658 if (pid == vID) packet = &vPacket;
659 if (pid == aID) packet = &aPacket;
663 if (pid == tID) packet = &tPacket;
666 if (packet->write(buf, datalen) == 0)
667 { // Writing to packet failed. It has overflowed.
670 parseTSPacketDetails(*packet);
673 if (submitPacket(*packet) == 0) return 0;
676 packet->write((UCHAR*)"\200\000\000", 3);
677 packet->write(buf, datalen);
682 if (pid == subID && subActive && subPacket.getLength() == subLength)
684 parsePacketDetails(subPacket);
685 Log::getInstance()->log("DEMUXERTS", Log::DEBUG, "SUBMITTING A SUBTITLE PACKET %d %x", subLength, subPacket.getSubstream());
686 submitPacket(subPacket);
693 ULONG DemuxerTS::getPacketNum()
698 ULONG DemuxerTS::getFrameNumFromPTS(ULLONG pts)
700 ULLONG difference = (1LL<<33);
702 int total = 0, actual = 0;
703 if (pts==0) return 0; //we are in startup
704 pts_map_mutex.Lock();
705 PTSMap::iterator iter = pts_map.begin();
706 while (iter != pts_map.end())
709 //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts1 %lld pts2 %lld", pts, iter->pts);
710 if (PTSDifference(iter->pts, pts) < PTS_ALLOWANCE)
713 ref_frame = iter->frame;
717 ULLONG newdiff = PTSDifference(pts, iter->pts);
718 if (newdiff < difference)
720 difference = newdiff;
721 ref_frame = iter->frame;
726 if (total > 1 && actual == 1) // We are using the most recent PTS ref.
727 { // Delete the rest.
728 iter = pts_map.begin(); iter++;
729 pts_map.erase(iter, pts_map.end());
731 pts_map_mutex.Unlock();
733 //Log::getInstance()->log("DemuxerTS", Log::DEBUG, "getFrameNumfromPTS pts %lld deleted %d difference %lld", pts, total,difference);
735 if (difference == (1LL<<33))
736 return 0; // We cannot make sense of the pts
738 return ref_frame + difference * fps / 90000;
742 void DemuxerTS::parseTSPacketDetails(PESPacket &packet) // Only important stuff for paket counting reminas
744 parsePacketDetails(packet);
745 if (packetCounting && packet.getPacketType() >= PESTYPE_AUD0 &&
746 packet.getPacketType() <= PESTYPE_AUDMAX)
750 UINT pictsinpacket=packet.countPictureHeaders(h264);
753 /* if (!doubledframerate)
755 numpicts=pictsinpacket;
759 numpicts=(pictsinpacket+framereserve)>>1;
760 framereserve=(pictsinpacket+framereserve)%2;
764 if (frameCounting && numpicts &&
765 packet.getPacketType() >= PESTYPE_VID0 &&
766 packet.getPacketType() <= PESTYPE_VIDMAX)
768 frameNumber+=numpicts;
769 ULONG frame_num = frameNumber;
770 if ((h264 || packet.findSeqHeader(h264) > 1) && packet.hasPTS())
773 pts_map_mutex.Lock();
776 me.pts = packet.getPTS();
777 me.frame = frame_num;
778 pts_map_mutex.Unlock();
779 pts_map_mutex.Lock();
780 pts_map.push_front(me);
782 me = pts_map.front();
783 pts_map_mutex.Unlock();
785 //UINT fps = Video::getInstance()->getFPS();
787 // if (doubledframerate) tfps*=2.;
788 long long pts_expected = me.pts + 90000LL*((long long)(((double)(frame_num - me.frame)) / tfps));
790 while (pts_expected < 0) pts_expected += (1LL<<33);
791 while (pts_expected > (1LL<<33)) pts_expected -= (1LL<<33);
793 // this was a workaround for a vdr bug, now fixed, for older recordings deleter the index file
796 if (!doubledframerate
797 &&(abs((long long)PTSDistance(pts_expected, packet.getPTS())-1800) <= 1
798 || abs((long long)PTSDistance(pts_expected, packet.getPTS())-1501) <= 1)) {
799 doubledframerate=true; //Detected p50 or p60
802 if (PTSDistance(pts_expected, packet.getPTS()) > PTS_JUMP_MARGIN) // PTS jump!
804 me.pts = packet.getPTS();
805 me.frame = frame_num;
806 pts_map_mutex.Lock();
807 pts_map.push_front(me);
808 pts_map_mutex.Unlock();
815 bool DemuxerTS::scanForVideo(UCHAR* buf, UINT len, bool &ish264)
819 while (len >= TS_SIZE)
821 if (*buf != TS_SIG) {buf++;len--; continue;}
823 //Pattern scanning won't work for ts
826 int datalen = TS_SIZE - 4;
827 int pid = ( (buf[1] & 0x1F) << 8 ) | buf[2];
828 UCHAR payload = buf[1] & 0x40;
830 if (buf[3] & 0x20) // Adaptation field is present
831 datalen -= (buf[4] + 1);
833 UCHAR* curbuf =buf+ (TS_SIZE - datalen);
836 if (pid == 0x00) {//PAT, only take first program number, ignore the rest
837 int pmtpid = (*(curbuf+11)<< 8) | *(curbuf+12);
838 if ((pmtpid >> 13) != 0x07)
840 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "PMTPID=%02x %02x TRAILING 111 not set but %x", *(curbuf+11),*(curbuf+12), (pmtpid >> 13));
844 pmtpid = pmtpid & 0x1FFF; //clear upper 3 bits
846 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "PMT pid%02x",pmtpid );
849 } else if (pid == pmtpidy) { //PMT
850 int sectionlength = ((*(curbuf+2) << 8) & 0x0F ) | *(buf+3);
851 //sectionlength += 4; //include header but subtract crc in the end...
852 int p = 13; //skip fixed part of pmt
853 while ( p < sectionlength) {
854 int streamtype = *(curbuf+p);
856 int foundpid = (*(curbuf+p)<< 8) | *(curbuf+p+1);
857 p += 2; //skip ES Pid
858 int eslength = ((*(curbuf+p) << 8) & 0x0F ) | *(curbuf+p+1);
859 p += 2; //skip ES length
860 if ((foundpid >> 13) != 0x07)
862 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "FOUNDPID=%02x %02x TRAILING 111 not set but %x", *(buf+p),*(buf+p+1), (foundpid >> 13));
866 foundpid = foundpid & 0x1FFF; //clear upper 3 bits
867 // int pos=0; UNUSED?
868 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Pid found %02x type %02x",foundpid ,streamtype);
869 if (streamtype==1 || streamtype ==2) {
871 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Found Mpeg2 Video");
874 if (streamtype==0x1b) {
876 Log::getInstance()->log("DemuxerTS", Log::DEBUG, "Found h264 Video");
880 p += eslength; //skip es descriptor
893 UINT DemuxerTS::stripAudio(UCHAR* buf, UINT len) //it has to be adapted
895 //This function strips all TS Headers and non video payload
900 while (readpos < len ) {
901 if (buf[readpos] != TS_SIG) {readpos++; continue;}
902 UINT oldreadpos=readpos;
904 int datalen = TS_SIZE - 4;
905 int pid = ( (buf[readpos+1] & 0x1F) << 8 ) | buf[readpos+2];
906 UCHAR payload = buf[readpos+1] & 0x40;
907 if (buf[readpos+3] & 0x20) { // Adaptation field is present
908 datalen -= (buf[readpos+4] + 1);
910 if (datalen < 0) {// Error in stream TODO log this
913 if (datalen == 0) {// Null packet
914 readpos=oldreadpos+TS_SIZE;
917 readpos += (TS_SIZE - datalen);
918 UINT towrite=min(datalen,len-readpos);
922 parsePacketDetails(destpaket);
923 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
924 writepos+=destpaket.getSize();
926 destpaket.init(PESTYPE_VID0);
927 readpos += 6; towrite -= 6;
932 if (!destpaket.write(buf+readpos,towrite)) {
933 parsePacketDetails(destpaket);
934 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
935 writepos+=destpaket.getSize();
936 destpaket.truncate();
937 destpaket.write((UCHAR*)"\200\000\000", 3);
938 destpaket.write(buf+readpos,towrite);
946 readpos=oldreadpos+TS_SIZE;
948 parsePacketDetails(destpaket);
949 memcpy(buf+writepos,destpaket.getData(),destpaket.getSize());
950 writepos+=destpaket.getSize();