// // Search packet signature and return packet type //_______________________________________ uint8_t fileParser::sync(uint8_t *stream) { uint32_t val,hnt; val=0; hnt=0; // preload if((4+_off)>=_size) { printf("Dmx IO: End of file met (%"LLU" / %"LLU" seg%lu)\n",_off,_size,_nbFd); return 0; } hnt=(read8i()<<16) + (read8i()<<8) +read8i(); while((hnt!=0x00001)) { hnt<<=8; val=read8i(); hnt+=val; hnt&=0xffffff; if(_curFd==_nbFd-1) { if((4+_off)>=_size) return 0; } } *stream=read8i(); return 1; }
// // Search packet signature and return packet type //_______________________________________ uint8_t mParser::sync(uint8_t *stream) { uint32_t val,hnt; val=0; hnt=0; // preload hnt=(read8i()<<16) + (read8i()<<8) +read8i(); ; while((hnt!=0x00001)) { hnt<<=8; val=read8i(); hnt+=val; hnt&=0xffffff; if(_curFd==_nbFd-1) { if((4+_off)>=_sizeFd[_curFd]) return 0; } } *stream=read8i(); return 1; }
// // Search packet signature and return packet type //_______________________________________ uint8_t fileParser::sync(uint8_t *stream) { uint32_t val,hnt; val=0; hnt=0; // preload if((4+_off)>=_size) { printf("Dmx IO: End of file met (%" PRIu64" / %" PRIu64" seg:%u)\n",_off,_size,(unsigned int)listOfFd.size()); return 0; } hnt=(read8i()<<16) + (read8i()<<8) +read8i(); while((hnt!=0x00001)) { hnt<<=8; val=read8i(); hnt+=val; hnt&=0xffffff; if(_curFd==listOfFd.size()-1) { if((4+_off)>=_size) return 0; } } *stream=read8i(); return 1; }
// a demuxer is also a king of hi-level parser uint8_t ADM_mpegDemuxer::sync( uint8_t *stream) { uint32_t val,hnt; //uint64_t p,tail; val=0; hnt=0; // preload hnt=(read8i()<<16) + (read8i()<<8) +read8i(); if(_lastErr) { _lastErr=0; printf("\n io error , aborting sync\n"); return 0; } while((hnt!=0x00001)) { hnt<<=8; val=read8i(); hnt+=val; hnt&=0xffffff; if(_lastErr) { _lastErr=0; // check if we are near the end, if so we abort // else we continue uint64_t pos; pos=getAbsPos(); // if(_size-pos<1024) { printf("\n io error , aborting sync\n"); return 0; } printf("\n Bumped into something at %llu / %llu but going on\n",pos,_size); if(!_size) assert(0); // else we go on... hnt=(read8i()<<16) + (read8i()<<8) +read8i(); } } *stream=read8i(); return 1; }
uint8_t dmx_demuxerTS::sync( uint8_t *stream,uint64_t *abs,uint64_t *r,uint64_t *pts,uint64_t *dts) { uint32_t val,hnt; retry: *r=0; val=0; hnt=0; // preload hnt=(read8i()<<16) + (read8i()<<8) +read8i(); if(_lastErr) { _lastErr=0; printf("\n io error , aborting sync\n"); return 0; } while((hnt!=0x00001)) { hnt<<=8; val=read8i(); hnt+=val; hnt&=0xffffff; if(_lastErr) { _lastErr=0; printf("\n io error , aborting sync\n"); return 0; } } *stream=read8i(); // Case 1 : assume we are still in the same packet if(_pesBufferIndex>=4) { *abs=_pesBufferStart; *r=_pesBufferIndex-4; *pts=_pesPTS; *dts=_pesDTS; } else { // pick what is needed from oldPesStart etc... // since the beginning in the previous packet uint32_t left=4-_pesBufferIndex; if(left>_oldPesLen) { // previous Packet which len is very shoty // Ignore _pesBufferIndex=0; printf("Ignoring too short packet"); goto retry; } left=_oldPesLen-left; #if 0 printf("Next packet : %I64X Len :%lu, using previous packet %I64X len:%u as pos=%lu\n", _pesBufferStart,_pesBufferLen,_oldPesStart,_oldPesLen,_pesBufferIndex); #endif if(left>_oldPesLen) { printf("Need %lu bytes from previous packet, which len is %lu\n",left,_oldPesLen); ADM_assert(0); } *abs=_oldPesStart; *r=left; *pts=_oldPTS; *dts=_oldDTS; } return 1; }
// ****************************************************** uint8_t dmx_demuxerMSDVR::sync( uint8_t *stream,uint64_t *abs,uint64_t *r,uint64_t *pts,uint64_t *dts) { uint32_t val,hnt; *r=0; val=0; hnt=0; // preload hnt=read32i(); if(_lastErr) { _lastErr=0; printf("\n io error , aborting sync 1\n"); return 0; } val=hnt&0xff; while(((hnt&0xffffff00)!=0x100)) { hnt<<=8; val=read8i(); hnt+=val; if(_lastErr) { _lastErr=0; printf("\n io error , aborting sync 2\n"); return 0; } } *stream=val; // Case 1 : assume we are still in the same packet if(_pesBufferIndex>=4) { *abs=_pesBufferStart; *r=_pesBufferIndex-4; *pts=_pesPTS; *dts=_pesDTS; } else { // pick what is needed from oldPesStart etc... // since the beginning in the previous packet uint32_t left=4-_pesBufferIndex; left=_oldPesLen-left; #if 0 printf("Next packet : %I64X Len :%lu, using previous packet %I64X len:%u as pos=%lu\n", _pesBufferStart,_pesBufferLen,_oldPesStart,_oldPesLen,_pesBufferIndex); #endif if(left>_oldPesLen) { printf("Need %lu bytes from previous packet, which len is %lu\n",left,_oldPesLen); ADM_assert(0); } *abs=_oldPesStart; *r=left; *pts=_oldPTS; *dts=_oldDTS; } return 1; }