diff --git a/src/codec/packet/packet.rs b/src/codec/packet/packet.rs index 3981a9b..f12c99c 100644 --- a/src/codec/packet/packet.rs +++ b/src/codec/packet/packet.rs @@ -147,13 +147,16 @@ impl Packet { } #[inline] - pub fn duration(&self) -> i64 { - self.0.duration as i64 + pub fn duration(&self) -> Option { + 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) { + self.0.duration = value.unwrap_or(AV_NOPTS_VALUE); } #[inline] diff --git a/src/codec/parameters.rs b/src/codec/parameters.rs index a50c3cf..aa59a8d 100644 --- a/src/codec/parameters.rs +++ b/src/codec/parameters.rs @@ -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 { diff --git a/src/format/context/common.rs b/src/format/context/common.rs index a221c50..70c8587 100644 --- a/src/format/context/common.rs +++ b/src/format/context/common.rs @@ -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 { + unsafe { + match (*self.as_ptr()).duration { + AV_NOPTS_VALUE => None, + value => Some(value), + } + } } #[inline] diff --git a/src/format/stream/stream.rs b/src/format/stream/stream.rs index f3548e0..dd3824f 100644 --- a/src/format/stream/stream.rs +++ b/src/format/stream/stream.rs @@ -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 { + 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 { + unsafe { + match (*self.as_ptr()).duration { + AV_NOPTS_VALUE => None, + value => Some(value), + } + } } pub fn frames(&self) -> i64 {