diff --git a/src/codec/audio.rs b/src/codec/audio.rs index 5c15c95..a32aef1 100644 --- a/src/codec/audio.rs +++ b/src/codec/audio.rs @@ -1,23 +1,22 @@ use std::ops::Deref; -use std::marker::PhantomData; use {ChannelLayout, format}; use super::codec::Codec; use ffi::*; -pub struct Audio<'a> { - codec: &'a Codec<'a>, +pub struct Audio { + codec: Codec, } -impl<'a> Audio<'a> { - pub unsafe fn new<'b>(codec: &'b Codec) -> Audio<'b> { +impl Audio { + pub unsafe fn new(codec: Codec) -> Audio { Audio { codec: codec, } } } -impl<'a> Audio<'a> { +impl Audio { pub fn rates(&self) -> Option { unsafe { if (*self.as_ptr()).supported_samplerates.is_null() { @@ -52,27 +51,25 @@ impl<'a> Audio<'a> { } } -impl<'a> Deref for Audio<'a> { - type Target = Codec<'a>; +impl Deref for Audio { + type Target = Codec; fn deref(&self) -> &Self::Target { - self.codec + &self.codec } } -pub struct RateIter<'a> { +pub struct RateIter { ptr: *const i32, - - _marker: PhantomData<&'a ()>, } -impl<'a> RateIter<'a> { +impl RateIter { pub fn new(ptr: *const i32) -> Self { - RateIter { ptr: ptr, _marker: PhantomData } + RateIter { ptr: ptr } } } -impl<'a> Iterator for RateIter<'a> { +impl Iterator for RateIter { type Item = i32; fn next(&mut self) -> Option<::Item> { @@ -89,19 +86,17 @@ impl<'a> Iterator for RateIter<'a> { } } -pub struct FormatIter<'a> { +pub struct FormatIter { ptr: *const AVSampleFormat, - - _marker: PhantomData<&'a ()>, } -impl<'a> FormatIter<'a> { +impl FormatIter { pub fn new(ptr: *const AVSampleFormat) -> Self { - FormatIter { ptr: ptr, _marker: PhantomData } + FormatIter { ptr: ptr } } } -impl<'a> Iterator for FormatIter<'a> { +impl Iterator for FormatIter { type Item = format::Sample; fn next(&mut self) -> Option<::Item> { @@ -118,19 +113,17 @@ impl<'a> Iterator for FormatIter<'a> { } } -pub struct ChannelLayoutIter<'a> { +pub struct ChannelLayoutIter { ptr: *const u64, - - _marker: PhantomData<&'a ()>, } -impl<'a> ChannelLayoutIter<'a> { +impl ChannelLayoutIter { pub fn new(ptr: *const u64) -> Self { - ChannelLayoutIter { ptr: ptr, _marker: PhantomData } + ChannelLayoutIter { ptr: ptr } } } -impl<'a> Iterator for ChannelLayoutIter<'a> { +impl Iterator for ChannelLayoutIter { type Item = ChannelLayout; fn next(&mut self) -> Option<::Item> { diff --git a/src/codec/codec.rs b/src/codec/codec.rs index da49104..e433bd3 100644 --- a/src/codec/codec.rs +++ b/src/codec/codec.rs @@ -1,4 +1,3 @@ -use std::marker::PhantomData; use std::ffi::CStr; use std::str::from_utf8_unchecked; @@ -6,15 +5,17 @@ use ffi::*; use super::{Id, Video, Audio, Capabilities, Profile}; use ::{Error, media}; -pub struct Codec<'a> { +#[derive(PartialEq, Eq, Copy, Clone)] +pub struct Codec { ptr: *mut AVCodec, - - _marker: PhantomData<&'a ()>, } -impl<'a> Codec<'a> { +unsafe impl Send for Codec { } +unsafe impl Sync for Codec { } + +impl Codec { pub unsafe fn wrap(ptr: *mut AVCodec) -> Self { - Codec { ptr: ptr, _marker: PhantomData } + Codec { ptr: ptr } } pub unsafe fn as_ptr(&self) -> *const AVCodec { @@ -26,7 +27,7 @@ impl<'a> Codec<'a> { } } -impl<'a> Codec<'a> { +impl Codec { pub fn is_encoder(&self) -> bool { unsafe { av_codec_is_encoder(self.as_ptr()) != 0 @@ -63,7 +64,11 @@ impl<'a> Codec<'a> { } } - pub fn video(&self) -> Result { + pub fn is_video(&self) -> bool { + self.medium() == media::Type::Video + } + + pub fn video(self) -> Result { unsafe { if self.medium() == media::Type::Video { Ok(Video::new(self)) @@ -74,7 +79,11 @@ impl<'a> Codec<'a> { } } - pub fn audio(&self) -> Result { + pub fn is_audio(&self) -> bool { + self.medium() == media::Type::Audio + } + + pub fn audio(self) -> Result { unsafe { if self.medium() == media::Type::Audio { Ok(Audio::new(self)) @@ -109,20 +118,18 @@ impl<'a> Codec<'a> { } } -pub struct ProfileIter<'a> { +pub struct ProfileIter { id: Id, ptr: *const AVProfile, - - _marker: PhantomData<&'a ()>, } -impl<'a> ProfileIter<'a> { +impl ProfileIter { pub fn new(id: Id, ptr: *const AVProfile) -> Self { - ProfileIter { id: id, ptr: ptr, _marker: PhantomData } + ProfileIter { id: id, ptr: ptr } } } -impl<'a> Iterator for ProfileIter<'a> { +impl Iterator for ProfileIter { type Item = Profile; fn next(&mut self) -> Option<::Item> { diff --git a/src/codec/decoder/mod.rs b/src/codec/decoder/mod.rs index 4fc4f33..88603aa 100644 --- a/src/codec/decoder/mod.rs +++ b/src/codec/decoder/mod.rs @@ -138,7 +138,7 @@ impl DerefMut for Decoder { } } -pub fn find(id: Id) -> Option> { +pub fn find(id: Id) -> Option { unsafe { let ptr = avcodec_find_decoder(id.into()); @@ -151,7 +151,7 @@ pub fn find(id: Id) -> Option> { } } -pub fn find_by_name(name: &str) -> Option> { +pub fn find_by_name(name: &str) -> Option { unsafe { let ptr = avcodec_find_decoder_by_name(CString::new(name).unwrap().as_ptr()); diff --git a/src/codec/encoder/mod.rs b/src/codec/encoder/mod.rs index f3efa9e..120fddf 100644 --- a/src/codec/encoder/mod.rs +++ b/src/codec/encoder/mod.rs @@ -114,7 +114,7 @@ impl DerefMut for Encoder { } } -pub fn find(id: Id) -> Option> { +pub fn find(id: Id) -> Option { unsafe { let ptr = avcodec_find_encoder(id.into()); @@ -127,7 +127,7 @@ pub fn find(id: Id) -> Option> { } } -pub fn find_by_name(name: &str) -> Option> { +pub fn find_by_name(name: &str) -> Option { unsafe { let ptr = avcodec_find_encoder_by_name(CString::new(name).unwrap().as_ptr()); diff --git a/src/codec/video.rs b/src/codec/video.rs index ae05add..7a3a321 100644 --- a/src/codec/video.rs +++ b/src/codec/video.rs @@ -1,23 +1,22 @@ -use std::marker::PhantomData; use std::ops::Deref; use {Rational, format}; use super::codec::Codec; use ffi::*; -pub struct Video<'a> { - codec: &'a Codec<'a>, +pub struct Video { + codec: Codec, } -impl<'a> Video<'a> { - pub unsafe fn new<'b>(codec: &'b Codec) -> Video<'b> { +impl Video { + pub unsafe fn new(codec: Codec) -> Video { Video { codec: codec, } } } -impl<'a> Video<'a> { +impl Video { pub fn rates(&self) -> Option { unsafe { if (*self.codec.as_ptr()).supported_framerates.is_null() { @@ -41,27 +40,25 @@ impl<'a> Video<'a> { } } -impl<'a> Deref for Video<'a> { - type Target = Codec<'a>; +impl Deref for Video { + type Target = Codec; fn deref(&self) -> &Self::Target { - self.codec + &self.codec } } -pub struct RateIter<'a> { +pub struct RateIter { ptr: *const AVRational, - - _marker: PhantomData<&'a ()>, } -impl<'a> RateIter<'a> { +impl RateIter { pub fn new(ptr: *const AVRational) -> Self { - RateIter { ptr: ptr, _marker: PhantomData } + RateIter { ptr: ptr } } } -impl<'a> Iterator for RateIter<'a> { +impl Iterator for RateIter { type Item = Rational; fn next(&mut self) -> Option<::Item> { @@ -78,19 +75,17 @@ impl<'a> Iterator for RateIter<'a> { } } -pub struct FormatIter<'a> { +pub struct FormatIter { ptr: *const AVPixelFormat, - - _marker: PhantomData<&'a ()>, } -impl<'a> FormatIter<'a> { +impl FormatIter { pub fn new(ptr: *const AVPixelFormat) -> Self { - FormatIter { ptr: ptr, _marker: PhantomData } + FormatIter { ptr: ptr } } } -impl<'a> Iterator for FormatIter<'a> { +impl Iterator for FormatIter { type Item = format::Pixel; fn next(&mut self) -> Option<::Item> {