|
1 | 1 | use std::ffi::CString;
|
2 | 2 | use std::mem;
|
3 |
| -use std::ops::{Deref, DerefMut}; |
| 3 | +use std::ops::{Bound, Deref, DerefMut, RangeBounds}; |
4 | 4 |
|
5 | 5 | use super::common::Context;
|
6 | 6 | use super::destructor;
|
7 | 7 | use crate::ffi::*;
|
8 |
| -use crate::util::range::Range; |
9 | 8 | #[cfg(not(feature = "ffmpeg_5_0"))]
|
10 | 9 | use crate::Codec;
|
11 | 10 | use crate::{format, Error, Packet, Stream};
|
@@ -117,16 +116,21 @@ impl Input {
|
117 | 116 | }
|
118 | 117 | }
|
119 | 118 |
|
120 |
| - pub fn seek<R: Range<i64>>(&mut self, ts: i64, range: R) -> Result<(), Error> { |
| 119 | + pub fn seek<R: RangeBounds<i64>>(&mut self, ts: i64, range: R) -> Result<(), Error> { |
121 | 120 | unsafe {
|
122 |
| - match avformat_seek_file( |
123 |
| - self.as_mut_ptr(), |
124 |
| - -1, |
125 |
| - range.start().cloned().unwrap_or(i64::MIN), |
126 |
| - ts, |
127 |
| - range.end().cloned().unwrap_or(i64::MAX), |
128 |
| - 0, |
129 |
| - ) { |
| 121 | + let start = match range.start_bound().cloned() { |
| 122 | + Bound::Included(i) => i, |
| 123 | + Bound::Excluded(i) => i.saturating_add(1), |
| 124 | + Bound::Unbounded => i64::MIN, |
| 125 | + }; |
| 126 | + |
| 127 | + let end = match range.end_bound().cloned() { |
| 128 | + Bound::Included(i) => i, |
| 129 | + Bound::Excluded(i) => i.saturating_sub(1), |
| 130 | + Bound::Unbounded => i64::MAX, |
| 131 | + }; |
| 132 | + |
| 133 | + match avformat_seek_file(self.as_mut_ptr(), -1, start, ts, end, 0) { |
130 | 134 | s if s >= 0 => Ok(()),
|
131 | 135 | e => Err(Error::from(e)),
|
132 | 136 | }
|
|
0 commit comments