codec: use Option<_> in the getter API
This commit is contained in:
parent
b39d8df4ee
commit
8ed092c0c3
@ -17,16 +17,47 @@ fn main() {
|
||||
if let Some(profiles) = codec.profiles() {
|
||||
println!("\t profiles: {:?}", profiles.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t profiles: none");
|
||||
}
|
||||
|
||||
if let Ok(video) = codec.video() {
|
||||
println!("\t rates: {:?}", video.rates().collect::<Vec<_>>());
|
||||
println!("\t formats: {:?}", video.formats().collect::<Vec<_>>());
|
||||
if let Some(rates) = video.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
|
||||
if let Some(formats) = video.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(audio) = codec.audio() {
|
||||
println!("\t rates: {:?}", audio.rates().collect::<Vec<_>>());
|
||||
println!("\t formats: {:?}", audio.formats().collect::<Vec<_>>());
|
||||
println!("\t channel_layouts: {:?}", audio.channel_layouts().collect::<Vec<_>>());
|
||||
if let Some(rates) = audio.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
|
||||
if let Some(formats) = audio.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
|
||||
if let Some(layouts) = audio.channel_layouts() {
|
||||
println!("\t channel_layouts: {:?}", layouts.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t channel_layouts: any");
|
||||
}
|
||||
}
|
||||
|
||||
println!("\t max_lowres: {:?}", codec.max_lowres());
|
||||
@ -46,14 +77,42 @@ fn main() {
|
||||
}
|
||||
|
||||
if let Ok(video) = codec.video() {
|
||||
println!("\t rates: {:?}", video.rates().collect::<Vec<_>>());
|
||||
println!("\t formats: {:?}", video.formats().collect::<Vec<_>>());
|
||||
if let Some(rates) = video.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
|
||||
if let Some(formats) = video.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(audio) = codec.audio() {
|
||||
println!("\t rates: {:?}", audio.rates().collect::<Vec<_>>());
|
||||
println!("\t formats: {:?}", audio.formats().collect::<Vec<_>>());
|
||||
println!("\t channel_layouts: {:?}", audio.channel_layouts().collect::<Vec<_>>());
|
||||
if let Some(rates) = audio.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
|
||||
if let Some(formats) = audio.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
|
||||
if let Some(layouts) = audio.channel_layouts() {
|
||||
println!("\t channel_layouts: {:?}", layouts.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t channel_layouts: any");
|
||||
}
|
||||
}
|
||||
|
||||
println!("\t max_lowres: {:?}", codec.max_lowres());
|
||||
|
@ -18,21 +18,36 @@ impl<'a> Audio<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Audio<'a> {
|
||||
pub fn rates(&self) -> RateIter {
|
||||
pub fn rates(&self) -> Option<RateIter> {
|
||||
unsafe {
|
||||
RateIter::new((*self.codec.as_ptr()).supported_samplerates)
|
||||
if (*self.as_ptr()).supported_samplerates.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(RateIter::new((*self.codec.as_ptr()).supported_samplerates))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn formats(&self) -> FormatIter {
|
||||
pub fn formats(&self) -> Option<FormatIter> {
|
||||
unsafe {
|
||||
FormatIter::new((*self.codec.as_ptr()).sample_fmts)
|
||||
if (*self.codec.as_ptr()).sample_fmts.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(FormatIter::new((*self.codec.as_ptr()).sample_fmts))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channel_layouts(&self) -> ChannelLayoutIter {
|
||||
pub fn channel_layouts(&self) -> Option<ChannelLayoutIter> {
|
||||
unsafe {
|
||||
ChannelLayoutIter::new((*self.codec.as_ptr()).channel_layouts)
|
||||
if (*self.codec.as_ptr()).channel_layouts.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(ChannelLayoutIter::new((*self.codec.as_ptr()).channel_layouts))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -62,16 +77,15 @@ impl<'a> Iterator for RateIter<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if !self.ptr.is_null() && (*self.ptr) != 0 {
|
||||
if *self.ptr == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let rate = *self.ptr;
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(rate)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,16 +106,15 @@ impl<'a> Iterator for FormatIter<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if !self.ptr.is_null() && (*self.ptr) != AVSampleFormat::AV_SAMPLE_FMT_NONE {
|
||||
if *self.ptr == AVSampleFormat::AV_SAMPLE_FMT_NONE {
|
||||
return None;
|
||||
}
|
||||
|
||||
let format = (*self.ptr).into();
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(format)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,15 +135,14 @@ impl<'a> Iterator for ChannelLayoutIter<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if !self.ptr.is_null() && (*self.ptr) != 0 {
|
||||
let chl = ChannelLayout::from_bits_truncate(*self.ptr);
|
||||
if *self.ptr == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let layout = ChannelLayout::from_bits_truncate(*self.ptr);
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(chl)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
Some(layout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ impl<'a> Codec<'a> {
|
||||
pub fn profiles(&self) -> Option<ProfileIter> {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).profiles.is_null() {
|
||||
return None;
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(ProfileIter::new(self.id(), (*self.as_ptr()).profiles))
|
||||
@ -132,15 +132,14 @@ impl<'a> Iterator for ProfileIter<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if (*self.ptr).profile != FF_PROFILE_UNKNOWN && !(*self.ptr).name.is_null() {
|
||||
if (*self.ptr).profile == FF_PROFILE_UNKNOWN {
|
||||
return None;
|
||||
}
|
||||
|
||||
let profile = Profile::from((self.id, (*self.ptr).profile));
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(profile)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,25 @@ impl<'a> Video<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Video<'a> {
|
||||
pub fn rates(&self) -> RateIter {
|
||||
pub fn rates(&self) -> Option<RateIter> {
|
||||
unsafe {
|
||||
RateIter::new((*self.codec.as_ptr()).supported_framerates)
|
||||
if (*self.codec.as_ptr()).supported_framerates.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(RateIter::new((*self.codec.as_ptr()).supported_framerates))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn formats(&self) -> FormatIter {
|
||||
pub fn formats(&self) -> Option<FormatIter> {
|
||||
unsafe {
|
||||
FormatIter::new((*self.codec.as_ptr()).pix_fmts)
|
||||
if (*self.codec.as_ptr()).pix_fmts.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(FormatIter::new((*self.codec.as_ptr()).pix_fmts))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,16 +66,15 @@ impl<'a> Iterator for RateIter<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if !self.ptr.is_null() && (*self.ptr) != (AVRational { num: 0, den: 0 }) {
|
||||
if (*self.ptr).num == 0 && (*self.ptr).den == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let rate = (*self.ptr).into();
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(rate)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,15 +95,14 @@ impl<'a> Iterator for FormatIter<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if !self.ptr.is_null() && (*self.ptr) != AVPixelFormat::AV_PIX_FMT_NONE {
|
||||
if *self.ptr == AVPixelFormat::AV_PIX_FMT_NONE {
|
||||
return None;
|
||||
}
|
||||
|
||||
let format = (*self.ptr).into();
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(format)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user