format/context/input: add seek()
method
This commit is contained in:
parent
ef3f821c6f
commit
a736c8b438
@ -7,6 +7,7 @@ use ffi::*;
|
||||
use ::{Error, Codec, Stream, Packet, format};
|
||||
use super::common::Context;
|
||||
use super::destructor;
|
||||
use util::range::Range;
|
||||
|
||||
pub struct Input {
|
||||
ptr: *mut AVFormatContext,
|
||||
@ -115,6 +116,18 @@ impl Input {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn seek<R: Range<i64>>(&mut self, ts: i64, range: R) -> Result<(), Error> {
|
||||
unsafe {
|
||||
match avformat_seek_file(self.as_mut_ptr(), -1,
|
||||
range.start().map(|v| *v).unwrap_or(i64::min_value()), ts,
|
||||
range.end().map(|v| *v).unwrap_or(i64::max_value()), 0)
|
||||
{
|
||||
s if s >= 0 => Ok(()),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Input {
|
||||
|
@ -10,6 +10,7 @@ pub mod chroma;
|
||||
pub mod time;
|
||||
pub mod channel_layout;
|
||||
pub mod option;
|
||||
pub mod range;
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::str::from_utf8_unchecked;
|
||||
|
35
src/util/range.rs
Normal file
35
src/util/range.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use std::ops;
|
||||
|
||||
pub trait Range<T> {
|
||||
fn start(&self) -> Option<&T> {
|
||||
None
|
||||
}
|
||||
|
||||
fn end(&self) -> Option<&T> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Range<T> for ops::Range<T> {
|
||||
fn start(&self) -> Option<&T> {
|
||||
Some(&self.start)
|
||||
}
|
||||
|
||||
fn end(&self) -> Option<&T> {
|
||||
Some(&self.end)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Range<T> for ops::RangeTo<T> {
|
||||
fn end(&self) -> Option<&T> {
|
||||
Some(&self.end)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Range<T> for ops::RangeFrom<T> {
|
||||
fn start(&self) -> Option<&T> {
|
||||
Some(&self.start)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Range<T> for ops::RangeFull { }
|
Loading…
x
Reference in New Issue
Block a user