mirror of
https://github.com/encounter/rust-ffmpeg-zmwangx.git
synced 2026-07-10 21:18:40 -07:00
refactor: use Rational::non_zero instead of manual comparisons
This commit is contained in:
+2
-16
@@ -136,26 +136,12 @@ impl Context {
|
||||
}
|
||||
|
||||
pub fn frame_rate(&self) -> Option<Rational> {
|
||||
unsafe {
|
||||
let fr = Rational::from((*self.as_ptr()).framerate);
|
||||
if fr == Rational(0, 1) {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(fr)
|
||||
}
|
||||
}
|
||||
unsafe { Rational::from((*self.as_ptr()).framerate).non_zero() }
|
||||
}
|
||||
|
||||
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).framerate = value.into().into();
|
||||
}
|
||||
else {
|
||||
(*self.as_mut_ptr()).framerate.num = 0;
|
||||
(*self.as_mut_ptr()).framerate.den = 1;
|
||||
}
|
||||
(*self.as_mut_ptr()).framerate = value.map(Into::into).unwrap_or(Rational::ZERO).into();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,16 +82,7 @@ impl Opened {
|
||||
}
|
||||
|
||||
pub fn frame_rate(&self) -> Option<Rational> {
|
||||
unsafe {
|
||||
let value = (*self.as_ptr()).framerate;
|
||||
|
||||
if value == (AVRational { num: 0, den: 1 }) {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Rational::from(value))
|
||||
}
|
||||
}
|
||||
unsafe { Rational::from((*self.as_ptr()).framerate).non_zero() }
|
||||
}
|
||||
|
||||
pub fn flush(&mut self) {
|
||||
|
||||
+2
-7
@@ -61,14 +61,9 @@ impl Iterator for RateIter {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if (*self.ptr).num == 0 && (*self.ptr).den == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let rate = (*self.ptr).into();
|
||||
let rate = Rational::from(*self.ptr).non_zero();
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(rate)
|
||||
rate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,12 +107,7 @@ impl<'a> Stream<'a> {
|
||||
ptr::null_mut(),
|
||||
));
|
||||
|
||||
if r == Rational(0, 1) {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(r)
|
||||
}
|
||||
r.non_zero()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user