}
}
- fn seek(&mut self, time: u64, seek_index: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, time: NATimePoint, seek_index: &SeekIndex) -> DemuxerResult<()> {
let ret = seek_index.find_pos(time);
if ret.is_none() {
return Err(DemuxerError::SeekError);
Err(DemuxerError::EOF)
}
- fn seek(&mut self, time: u64, seek_index: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, time: NATimePoint, seek_index: &SeekIndex) -> DemuxerResult<()> {
let ret = seek_index.find_pos(time);
if ret.is_none() {
return Err(DemuxerError::SeekError);
}
}
- fn seek(&mut self, time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
if self.block_size != 0 && self.avg_bytes != 0 {
- let seek_dst = u64::from(self.avg_bytes) * time / 1000;
- let seek_off = seek_dst / (self.block_size as u64) * (self.block_size as u64);
+ let seek_off = match time {
+ NATimePoint::Milliseconds(ms) => {
+ let seek_dst = u64::from(self.avg_bytes) * ms / 1000;
+ seek_dst / (self.block_size as u64) * (self.block_size as u64)
+ },
+ NATimePoint::PTS(pts) => (self.block_size as u64) * pts,
+ NATimePoint::None => return Ok(()),
+ };
self.src.seek(SeekFrom::Start(self.data_pos + seek_off))?;
Ok(())
} else {
/// 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.
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 {
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; }
}
}
}
- /// 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);
}
}
}
- fn seek(&mut self, _time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
}
}
}
- fn seek(&mut self, _time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
}
}
}
- fn seek(&mut self, _time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
}
Ok(pkt)
}
- fn seek(&mut self, _time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
}
Ok(pkt)
}
- fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
let ret = seek_idx.find_pos(time);
if ret.is_none() {
return Err(DemuxerError::SeekError);
Ok(pkt)
}
- fn seek(&mut self, time: u64, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
- if time == 0 {
+ fn seek(&mut self, time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
+ let seek_to_start = match time {
+ NATimePoint::Milliseconds(0) => true,
+ NATimePoint::PTS(0) => true,
+ _ => false,
+ };
+ if seek_to_start {
let start = self.start;
self.src.seek(SeekFrom::Start(start))?;
self.cur_frame = 0;
}
#[allow(unused_variables)]
- fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
self.queued_pkts.clear();
let ret = seek_idx.find_pos(time);
if ret.is_none() {
}
#[allow(unused_variables)]
- fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
Err(NotImplemented)
}
}
}
#[allow(unused_variables)]
- fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
Err(NotImplemented)
}
}
}
}
}
- fn seek(&mut self, _time: u64, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
+ fn seek(&mut self, _time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
Err(DemuxerError::NotPossible)
}
}