From 6492988da2d819c9e0953ec71876488e2e35580e Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 15 Nov 2019 19:59:19 +0100 Subject: [PATCH] core: improve SeekIndex functionality --- nihav-core/src/demuxers/mod.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/nihav-core/src/demuxers/mod.rs b/nihav-core/src/demuxers/mod.rs index 6499132..0883782 100644 --- a/nihav-core/src/demuxers/mod.rs +++ b/nihav-core/src/demuxers/mod.rs @@ -207,9 +207,13 @@ pub struct SeekIndex { impl SeekIndex { pub fn new() -> Self { Self::default() } - pub fn add_stream(&mut self, id: u32) { - if self.stream_id_to_index(id).is_none() { + pub fn add_stream(&mut self, id: u32) -> usize { + let ret = self.stream_id_to_index(id); + if ret.is_none() { self.seek_info.push(StreamSeekInfo::new(id)); + self.seek_info.len() - 1 + } else { + ret.unwrap() } } pub fn stream_id_to_index(&self, id: u32) -> Option { @@ -228,6 +232,14 @@ impl SeekIndex { } None } + pub fn add_entry(&mut self, id: u32, entry: SeekEntry) { + let mut idx = self.stream_id_to_index(id); + if idx.is_none() { + idx = Some(self.add_stream(id)); + } + self.seek_info[idx.unwrap()].add_entry(entry); + self.seek_info[idx.unwrap()].filled = true; + } pub fn find_pos(&self, time: u64) -> Option { let mut cand = None; for str in self.seek_info.iter() { -- 2.39.5