From 9da33f04bbd89f18942bbafc6d135b5d3f102953 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 16 Nov 2019 09:59:40 +0100 Subject: [PATCH] allow to skip index building --- nihav-commonfmt/src/demuxers/avi.rs | 20 +++++++++++--------- nihav-core/src/demuxers/mod.rs | 4 ++++ nihav-realmedia/src/demuxers/realmedia.rs | 6 +++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/nihav-commonfmt/src/demuxers/avi.rs b/nihav-commonfmt/src/demuxers/avi.rs index 93ac060..3361806 100644 --- a/nihav-commonfmt/src/demuxers/avi.rs +++ b/nihav-commonfmt/src/demuxers/avi.rs @@ -224,16 +224,18 @@ impl<'a> AVIDemuxer<'a> { } rest_size -= csz; } - self.src.read_skip(self.movi_size)?; - while rest_size > 0 { - let ret = self.parse_chunk(strmgr, RIFFTag::Chunk(mktag!(b"idx1")), rest_size,0); - if ret.is_err() { break; } - let (csz, end) = ret.unwrap(); - if end { - let _res = parse_idx1(&mut self.src, strmgr, seek_idx, csz, self.movi_pos); - break; + if !seek_idx.skip_index { + self.src.read_skip(self.movi_size)?; + while rest_size > 0 { + let ret = self.parse_chunk(strmgr, RIFFTag::Chunk(mktag!(b"idx1")), rest_size,0); + if ret.is_err() { break; } + let (csz, end) = ret.unwrap(); + if end { + let _res = parse_idx1(&mut self.src, strmgr, seek_idx, csz, self.movi_pos); + break; + } + rest_size -= csz; } - rest_size -= csz; } if self.movi_pos != 0 { self.src.seek(SeekFrom::Start(self.movi_pos))?; diff --git a/nihav-core/src/demuxers/mod.rs b/nihav-core/src/demuxers/mod.rs index 0883782..ee2fe58 100644 --- a/nihav-core/src/demuxers/mod.rs +++ b/nihav-core/src/demuxers/mod.rs @@ -203,6 +203,7 @@ pub struct SeekIndexResult { pub struct SeekIndex { pub seek_info: Vec, pub mode: SeekIndexMode, + pub skip_index: bool, } impl SeekIndex { @@ -307,6 +308,9 @@ impl<'a> Demuxer<'a> { } } pub fn seek(&mut self, time: u64) -> DemuxerResult<()> { + if self.seek_idx.skip_index { + return Err(DemuxerError::NotPossible); + } self.dmx.seek(time, &self.seek_idx) } pub fn get_seek_index(&self) -> &SeekIndex { diff --git a/nihav-realmedia/src/demuxers/realmedia.rs b/nihav-realmedia/src/demuxers/realmedia.rs index e3d7447..fa3920a 100644 --- a/nihav-realmedia/src/demuxers/realmedia.rs +++ b/nihav-realmedia/src/demuxers/realmedia.rs @@ -1060,7 +1060,11 @@ impl<'a> RealMediaDemuxer<'a> { else if id == mktag!(b"DATA") { self.data_chunks.push((self.src.tell() - 10, size, ver)); } - else if id == mktag!(b"INDX") { self.parse_index(seek_idx, (size as usize) - 10, ver)?; } + else if id == mktag!(b"INDX") { + if !seek_idx.skip_index { + self.parse_index(seek_idx, (size as usize) - 10, ver)?; + } + } else if id == 0 { return Ok(true); } else { println!("unknown chunk type {:08X}", id); } -- 2.39.5