void CTsDuration::OnTsPacket(byte* tsPacket, int bufferOffset, int bufferLength) { CTsHeader header(tsPacket); CAdaptionField field; field.Decode(header,tsPacket); if (field.Pcr.IsValid) { if (m_bSearchStart) { if ( (m_videoPid>0 && header.Pid==m_videoPid) || m_videoPid<0) { m_pid=header.Pid; m_startPcr=field.Pcr; m_bSearchStart=false; if (!m_firstStartPcr.IsValid) { m_firstStartPcr=m_startPcr; } } } if (m_bSearchEnd && m_pid==header.Pid) { m_endPcr=field.Pcr; } } }
//********************************************************* // Callback method. This method gets called via // CTsFileSeek::Seek()->OnRawData2(buffer,dwBytesRead) // tsPacket : pointer to 188 byte Transport Stream packet // // This method checks if the ts packet contains a PCR timestamp // and ifso sets the PCR timestamp in m_pcrFound; void CTsFileSeek::OnTsPacket(byte* tsPacket) { if (m_pcrFound.IsValid) return ; CTsHeader header(tsPacket); CAdaptionField field; field.Decode(header,tsPacket); if (field.Pcr.IsValid) { //got a pcr, is it the correct pid? if ( (m_seekPid>0 && (header.Pid==m_seekPid)) || (m_seekPid<0) ) { // pid is valid // did we have a pcr rollover ?? if (m_duration.FirstStartPcr() > m_duration.EndPcr()) { //pcr rollover occured. //next we need to convert the pcr into filestamp //since we are seeking from 0-duration //but the file can start with any pcr timestamp if (field.Pcr.ToClock() <=m_duration.EndPcr().ToClock()) { // pcr < endpcr (second half of the file) // pcrFound= pcr+(MAXIMUM_PCR - startpcr) // StartPcr------>(0x1ffffffff;0x1ff), (0x0,0x0)--------->EndPcr m_pcrFound=field.Pcr; double d1=m_pcrFound.ToClock(); CPcr pcr2; pcr2.PcrReferenceBase = 0x1ffffffffULL; pcr2.PcrReferenceExtension = 0x1ffULL; double start=pcr2.ToClock()- m_duration.StartPcr().ToClock(); d1+=start; m_pcrFound.FromClock(d1); } else { //PCR > endpcr (first half of the file) // pcrFound= (pcr-startpcr) m_pcrFound=field.Pcr; double d1=m_pcrFound.ToClock(); double start=m_duration.StartPcr().ToClock();//earliest pcr available in the file LogDebug(" found clock %f earliest is %f", d1, start); d1-=start; LogDebug(" after sub %f", d1); m_pcrFound.FromClock(d1); } } else { //no pcr rollover occured. //next we need to convert the pcr into filestamp //since we are seeking from 0-duration //but the file can start with any pcr timestamp // formula: pcrfound = pcr-startpcr; m_pcrFound=field.Pcr; double d1=m_pcrFound.ToClock(); double start=m_duration.StartPcr().ToClock(); //earliest pcr available in the file d1-=start; m_pcrFound.FromClock(d1); } } } }