void CMpegSplitterFile::SearchPrograms(__int64 start, __int64 stop) { if (m_type != mpeg_ts) { return; } Seek(start); stop = min(stop, GetLength()); while (GetPos() < stop) { tshdr h; if (!Read(h)) { continue; } UpdatePrograms(h); Seek(h.next); } }
HRESULT CMpegSplitterFile::SearchStreams(__int64 start, __int64 stop) { Seek(start); stop = min(stop, GetLength()); while(GetPos() < stop) { BYTE b; if(m_type == ps || m_type == es) { if(!NextMpegStartCode(b)) continue; if(b == 0xba) // program stream header { pshdr h; if(!Read(h)) continue; } else if(b == 0xbb) // program stream system header { pssyshdr h; if(!Read(h)) continue; } #if (EVO_SUPPORT == 0) else if(b >= 0xbd && b < 0xf0) // pes packet #else else if((b >= 0xbd && b < 0xf0) || (b == 0xfd)) // pes packet #endif { peshdr h; if(!Read(h, b)) continue; if(h.type == mpeg2 && h.scrambling) {ASSERT(0); return E_FAIL;} if(h.fpts) { if(m_rtMin == _I64_MAX) {m_rtMin = h.pts; m_posMin = GetPos();} if(m_rtMin < h.pts && m_rtMax < h.pts) {m_rtMax = h.pts; m_posMax = GetPos();} /* int rate = 10000000i64 * (m_posMax - m_posMin) / (m_rtMax - m_rtMin); if(m_rate == 0) m_rate = rate; TRACE(_T("rate = %d (%d), (h.pts = %I64d)\n"), rate, rate - m_rate, h.pts); m_rate = rate; */ } __int64 pos = GetPos(); AddStream(0, b, h.len); if(h.len) Seek(pos + h.len); } } else if(m_type == ts) { trhdr h; if(!Read(h)) continue; // if(h.scrambling) {ASSERT(0); return E_FAIL;} __int64 pos = GetPos(); if(h.payload && h.payloadstart) { UpdatePrograms(h); } if(h.payload && ISVALIDPID(h.pid)) { peshdr h2; if(h.payloadstart && NextMpegStartCode(b, 4) && Read(h2, b)) // pes packet { if(h2.type == mpeg2 && h2.scrambling) { ASSERT(0); return E_FAIL; } if(h2.fpts) { if(m_rtMin == _I64_MAX) {m_rtMin = h2.pts; m_posMin = GetPos();} if(m_rtMin < h2.pts && m_rtMax < h2.pts) {m_rtMax = h2.pts; m_posMax = GetPos();} } } else { b = 0; } AddStream(h.pid, b, DWORD(h.bytes - (GetPos() - pos))); } Seek(h.next); } else if(m_type == pva) { pvahdr h; if(!Read(h)) continue; if(h.fpts) { if(m_rtMin == _I64_MAX) {m_rtMin = h.pts; m_posMin = GetPos();} if(m_rtMin < h.pts && m_rtMax < h.pts) {m_rtMax = h.pts; m_posMax = GetPos();} } __int64 pos = GetPos(); if(h.streamid == 1) AddStream(h.streamid, 0xe0, h.length); else if(h.streamid == 2) AddStream(h.streamid, 0xc0, h.length); if(h.length) Seek(pos + h.length); } }