aboutsummaryrefslogtreecommitdiffstats
path: root/nihav-core/src
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2020-07-09 10:42:42 +0200
committerKostya Shishkov <kostya.shishkov@gmail.com>2020-07-09 10:42:42 +0200
commit24d998947d55228ec37a08cd391983c6239e3c0c (patch)
treec7c392e66ea95f35f558de9edd5a3ff8bfaede01 /nihav-core/src
parentdcabdfd2eea01174f46548a8e2166ab88d0de96b (diff)
downloadnihav-24d998947d55228ec37a08cd391983c6239e3c0c.tar.gz
use NATimePoint for seeking
Diffstat (limited to 'nihav-core/src')
-rw-r--r--nihav-core/src/demuxers/mod.rs35
1 files changed, 25 insertions, 10 deletions
diff --git a/nihav-core/src/demuxers/mod.rs b/nihav-core/src/demuxers/mod.rs
index 9a69abb..352c160 100644
--- a/nihav-core/src/demuxers/mod.rs
+++ b/nihav-core/src/demuxers/mod.rs
@@ -37,7 +37,7 @@ pub trait DemuxCore<'a>: NAOptionHandler {
/// Demuxes a packet.
fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<NAPacket>;
/// Seeks to the requested time.
- fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()>;
+ fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()>;
}
/// An auxiliary trait to make bytestream reader read packet data.
@@ -229,16 +229,31 @@ impl StreamSeekInfo {
self.entries.push(entry);
}
/// Searches for an appropriate seek position before requested time.
- pub fn find_pos(&self, time: u64) -> Option<SeekEntry> {
+ pub fn find_pos(&self, time: NATimePoint) -> Option<SeekEntry> {
+ if time == NATimePoint::None {
+ return None;
+ }
if !self.entries.is_empty() {
// todo something faster like binary search
let mut cand = None;
for entry in self.entries.iter() {
- if entry.time <= time {
- cand = Some(*entry);
- } else {
- break;
- }
+ match time {
+ NATimePoint::Milliseconds(ms) => {
+ if entry.time <= ms {
+ cand = Some(*entry);
+ } else {
+ break;
+ }
+ },
+ NATimePoint::PTS(pts) => {
+ if entry.pts <= pts {
+ cand = Some(*entry);
+ } else {
+ break;
+ }
+ },
+ NATimePoint::None => unreachable!(),
+ };
}
cand
} else {
@@ -309,7 +324,7 @@ impl SeekIndex {
self.seek_info[idx.unwrap()].filled = true;
}
/// Searches for a seek position before requested time.
- pub fn find_pos(&self, time: u64) -> Option<SeekIndexResult> {
+ pub fn find_pos(&self, time: NATimePoint) -> Option<SeekIndexResult> {
let mut cand = None;
for str in self.seek_info.iter() {
if !str.filled { continue; }
@@ -389,8 +404,8 @@ impl<'a> Demuxer<'a> {
}
}
}
- /// Seeks to the requested time (in milliseconds) if possible.
- pub fn seek(&mut self, time: u64) -> DemuxerResult<()> {
+ /// Seeks to the requested time if possible.
+ pub fn seek(&mut self, time: NATimePoint) -> DemuxerResult<()> {
if self.seek_idx.skip_index {
return Err(DemuxerError::NotPossible);
}