fix: make sure everything that can be AV_NOPTS_VALUE is an Option<T>

This commit is contained in:
meh
2021-03-20 20:49:52 +01:00
parent 40dc584f94
commit ab0a6e44cd
4 changed files with 53 additions and 10 deletions
+7 -4
View File
@@ -147,13 +147,16 @@ impl Packet {
}
#[inline]
pub fn duration(&self) -> i64 {
self.0.duration as i64
pub fn duration(&self) -> Option<i64> {
match self.0.duration as i64 {
AV_NOPTS_VALUE => None,
value => Some(value),
}
}
#[inline]
pub fn set_duration(&mut self, value: i64) {
self.0.duration = value;
pub fn set_duration(&mut self, value: Option<i64>) {
self.0.duration = value.unwrap_or(AV_NOPTS_VALUE);
}
#[inline]
+25
View File
@@ -38,9 +38,34 @@ impl Parameters {
unsafe { media::Type::from((*self.as_ptr()).codec_type) }
}
pub fn set_medium(&mut self, value: media::Type) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).codec_type = value.into();
}
self
}
pub fn id(&self) -> Id {
unsafe { Id::from((*self.as_ptr()).codec_id) }
}
pub fn set_id(&mut self, value: Id) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).codec_id = value.into();
}
self
}
pub fn tag(&self) -> u32 {
unsafe { (*self.as_ptr()).codec_tag }
}
pub fn set_tag(&mut self, value: u32) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).codec_tag = value;
}
self
}
}
impl Default for Parameters {
+7 -2
View File
@@ -79,8 +79,13 @@ impl Context {
unsafe { (*self.as_ptr()).bit_rate }
}
pub fn duration(&self) -> i64 {
unsafe { (*self.as_ptr()).duration }
pub fn duration(&self) -> Option<i64> {
unsafe {
match (*self.as_ptr()).duration {
AV_NOPTS_VALUE => None,
value => Some(value),
}
}
}
#[inline]
+14 -4
View File
@@ -54,12 +54,22 @@ impl<'a> Stream<'a> {
unsafe { Rational::from((*self.as_ptr()).time_base) }
}
pub fn start_time(&self) -> i64 {
unsafe { (*self.as_ptr()).start_time }
pub fn start_time(&self) -> Option<i64> {
unsafe {
match (*self.as_ptr()).start_time {
AV_NOPTS_VALUE => None,
value => Some(value),
}
}
}
pub fn duration(&self) -> i64 {
unsafe { (*self.as_ptr()).duration }
pub fn duration(&self) -> Option<i64> {
unsafe {
match (*self.as_ptr()).duration {
AV_NOPTS_VALUE => None,
value => Some(value),
}
}
}
pub fn frames(&self) -> i64 {