diff --git a/src/format/context/input.rs b/src/format/context/input.rs index 277ab45..17fe0f2 100644 --- a/src/format/context/input.rs +++ b/src/format/context/input.rs @@ -1,11 +1,10 @@ use std::ffi::CString; use std::mem; -use std::ops::{Deref, DerefMut}; +use std::ops::{Bound, Deref, DerefMut, RangeBounds}; use super::common::Context; use super::destructor; use crate::ffi::*; -use crate::util::range::Range; #[cfg(not(feature = "ffmpeg_5_0"))] use crate::Codec; use crate::{format, Error, Packet, Stream}; @@ -117,16 +116,21 @@ impl Input { } } - pub fn seek>(&mut self, ts: i64, range: R) -> Result<(), Error> { + pub fn seek>(&mut self, ts: i64, range: R) -> Result<(), Error> { unsafe { - match avformat_seek_file( - self.as_mut_ptr(), - -1, - range.start().cloned().unwrap_or(i64::MIN), - ts, - range.end().cloned().unwrap_or(i64::MAX), - 0, - ) { + let start = match range.start_bound().cloned() { + Bound::Included(i) => i, + Bound::Excluded(i) => i.saturating_add(1), + Bound::Unbounded => i64::MIN, + }; + + let end = match range.end_bound().cloned() { + Bound::Included(i) => i, + Bound::Excluded(i) => i.saturating_sub(1), + Bound::Unbounded => i64::MAX, + }; + + match avformat_seek_file(self.as_mut_ptr(), -1, start, ts, end, 0) { s if s >= 0 => Ok(()), e => Err(Error::from(e)), } diff --git a/src/util/mod.rs b/src/util/mod.rs index 2937dde..0e1762c 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -12,7 +12,6 @@ pub mod mathematics; pub mod media; pub mod option; pub mod picture; -pub mod range; pub mod rational; pub mod time; diff --git a/src/util/range.rs b/src/util/range.rs deleted file mode 100644 index 1449383..0000000 --- a/src/util/range.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::ops; - -pub trait Range { - fn start(&self) -> Option<&T> { - None - } - - fn end(&self) -> Option<&T> { - None - } -} - -impl Range for ops::Range { - fn start(&self) -> Option<&T> { - Some(&self.start) - } - - fn end(&self) -> Option<&T> { - Some(&self.end) - } -} - -impl Range for ops::RangeTo { - fn end(&self) -> Option<&T> { - Some(&self.end) - } -} - -impl Range for ops::RangeFrom { - fn start(&self) -> Option<&T> { - Some(&self.start) - } -} - -impl Range for ops::RangeFull {}