From 0bcd4550b85580d02599d84b312251d930d1802f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadas=20Barzd=C5=BEius?= Date: Tue, 10 Apr 2018 17:06:42 +0300 Subject: [PATCH] *: format code with rustfmt and fix clippy suggestions * Add avformat_close_input call to clean up AVFormantContext * Format code with rustfmt * Fix clippy lint double_parens * Fix clippy lint deref_addrof * Fix clippy lint identity_conversion * Fix clippy lint match_ref_pats * Fix clippy lint cast_lossless * Fix clippy lint cmp_null * Fix clippy lint clone_on_ref_ptr * Fix clippy lint map_clone * Fix clippy lint needless_borrow * Fix clippy lint needless_pass_by_value * Fix clippy lints for examples * Fix clippy lint unused_io_amount * Fix clippy lint new_without_default * Ignore inline_always clippy lint * Add vim temp files to .gitignore --- .gitignore | 6 + build.rs | 14 +- examples/chapters.rs | 84 +- examples/codec-info.rs | 187 +- examples/metadata.rs | 150 +- examples/transcode-audio.rs | 276 ++- src/codec/audio.rs | 187 +- src/codec/audio_service.rs | 74 +- src/codec/capabilities.rs | 38 +- src/codec/codec.rs | 193 +- src/codec/compliance.rs | 50 +- src/codec/context.rs | 217 +- src/codec/debug.rs | 42 +- src/codec/decoder/audio.rs | 181 +- src/codec/decoder/check.rs | 22 +- src/codec/decoder/conceal.rs | 12 +- src/codec/decoder/decoder.rs | 213 +- src/codec/decoder/mod.rs | 42 +- src/codec/decoder/opened.rs | 144 +- src/codec/decoder/slice.rs | 12 +- src/codec/decoder/subtitle.rs | 59 +- src/codec/decoder/video.rs | 227 +- src/codec/discard.rs | 60 +- src/codec/encoder/audio.rs | 286 +-- src/codec/encoder/comparison.rs | 116 +- src/codec/encoder/decision.rs | 38 +- src/codec/encoder/encoder.rs | 206 +- src/codec/encoder/mod.rs | 42 +- src/codec/encoder/motion_estimation.rs | 78 +- src/codec/encoder/prediction.rs | 38 +- src/codec/encoder/subtitle.rs | 147 +- src/codec/encoder/video.rs | 786 +++--- src/codec/field_order.rs | 54 +- src/codec/flag.rs | 43 +- src/codec/id.rs | 2748 ++++++++++----------- src/codec/mod.rs | 16 +- src/codec/packet/borrow.rs | 66 +- src/codec/packet/flag.rs | 10 +- src/codec/packet/mod.rs | 2 +- src/codec/packet/packet.rs | 474 ++-- src/codec/packet/side_data.rs | 205 +- src/codec/packet/traits.rs | 4 +- src/codec/parameters.rs | 114 +- src/codec/picture.rs | 295 ++- src/codec/profile.rs | 554 +++-- src/codec/subtitle/flag.rs | 8 +- src/codec/subtitle/mod.rs | 264 +- src/codec/subtitle/rect.rs | 196 +- src/codec/subtitle/rect_mut.rs | 228 +- src/codec/threading.rs | 83 +- src/codec/traits.rs | 134 +- src/codec/video.rs | 118 +- src/device/extensions.rs | 99 +- src/device/input.rs | 58 +- src/device/mod.rs | 65 +- src/device/output.rs | 58 +- src/filter/context/context.rs | 83 +- src/filter/context/sink.rs | 58 +- src/filter/context/source.rs | 44 +- src/filter/filter.rs | 141 +- src/filter/flag.rs | 18 +- src/filter/graph.rs | 319 +-- src/filter/mod.rs | 55 +- src/filter/pad.rs | 58 +- src/format/chapter/chapter.rs | 77 +- src/format/chapter/chapter_mut.rs | 108 +- src/format/context/common.rs | 495 ++-- src/format/context/destructor.rs | 43 +- src/format/context/input.rs | 268 +- src/format/context/mod.rs | 60 +- src/format/context/output.rs | 256 +- src/format/format/flag.rs | 43 +- src/format/format/input.rs | 82 +- src/format/format/iter.rs | 89 +- src/format/format/mod.rs | 54 +- src/format/format/output.rs | 114 +- src/format/mod.rs | 432 ++-- src/format/network.rs | 12 +- src/format/stream/disposition.rs | 34 +- src/format/stream/stream.rs | 204 +- src/format/stream/stream_mut.rs | 84 +- src/lib.rs | 75 +- src/software/mod.rs | 44 +- src/software/resampling/context.rs | 222 +- src/software/resampling/delay.rs | 31 +- src/software/resampling/dither.rs | 88 +- src/software/resampling/engine.rs | 30 +- src/software/resampling/extensions.rs | 46 +- src/software/resampling/filter.rs | 36 +- src/software/resampling/flag.rs | 8 +- src/software/resampling/mod.rs | 12 +- src/software/scaling/color_space.rs | 56 +- src/software/scaling/context.rs | 238 +- src/software/scaling/extensions.rs | 113 +- src/software/scaling/filter.rs | 143 +- src/software/scaling/flag.rs | 48 +- src/software/scaling/mod.rs | 12 +- src/software/scaling/support.rs | 14 +- src/software/scaling/vector.rs | 194 +- src/util/channel_layout.rs | 134 +- src/util/chroma/location.rs | 62 +- src/util/color/primaries.rs | 104 +- src/util/color/range.rs | 38 +- src/util/color/space.rs | 124 +- src/util/color/transfer_characteristic.rs | 134 +- src/util/dictionary/immutable.rs | 72 +- src/util/dictionary/iter.rs | 53 +- src/util/dictionary/mutable.rs | 60 +- src/util/dictionary/owned.rs | 146 +- src/util/error.rs | 446 ++-- src/util/format/pixel.rs | 1614 ++++++------ src/util/format/sample.rs | 314 +-- src/util/frame/audio.rs | 706 +++--- src/util/frame/flag.rs | 8 +- src/util/frame/mod.rs | 270 +- src/util/frame/side_data.rs | 197 +- src/util/frame/video.rs | 659 +++-- src/util/interrupt.rs | 12 +- src/util/mathematics/rescale.rs | 59 +- src/util/mathematics/rounding.rs | 60 +- src/util/media.rs | 60 +- src/util/mod.rs | 32 +- src/util/option/mod.rs | 134 +- src/util/option/traits.rs | 214 +- src/util/picture.rs | 70 +- src/util/range.rs | 38 +- src/util/rational.rs | 266 +- src/util/time.rs | 26 +- 128 files changed, 10643 insertions(+), 10233 deletions(-) diff --git a/.gitignore b/.gitignore index a9d37c5..a35f901 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ +# Rust files target Cargo.lock + +# Vim temporary files +*.swp +*.swo +*.swn diff --git a/build.rs b/build.rs index 800df76..a85e15c 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,12 @@ use std::env; fn main() { - for (name, _value) in env::vars() { - if name.starts_with("DEP_FFMPEG_") { - println!(r#"cargo:rustc-cfg=feature="{}""#, - name["DEP_FFMPEG_".len() .. name.len()].to_lowercase()); - } - } + for (name, _value) in env::vars() { + if name.starts_with("DEP_FFMPEG_") { + println!( + r#"cargo:rustc-cfg=feature="{}""#, + name["DEP_FFMPEG_".len()..name.len()].to_lowercase() + ); + } + } } diff --git a/examples/chapters.rs b/examples/chapters.rs index 97aa643..02e6478 100644 --- a/examples/chapters.rs +++ b/examples/chapters.rs @@ -3,50 +3,58 @@ extern crate ffmpeg; use std::env; fn main() { - ffmpeg::init().unwrap(); + ffmpeg::init().unwrap(); - match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) { - Ok(ictx) => { - println!("Nb chapters: {}", ictx.nb_chapters()); + match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) { + Ok(ictx) => { + println!("Nb chapters: {}", ictx.nb_chapters()); - for chapter in ictx.chapters() { - println!("chapter id {}:", chapter.id()); - println!("\ttime_base: {}", chapter.time_base()); - println!("\tstart: {}", chapter.start()); - println!("\tend: {}", chapter.end()); + for chapter in ictx.chapters() { + println!("chapter id {}:", chapter.id()); + println!("\ttime_base: {}", chapter.time_base()); + println!("\tstart: {}", chapter.start()); + println!("\tend: {}", chapter.end()); - for (k, v) in chapter.metadata().iter() { - println!("\t{}: {}", k, v); - } - } + for (k, v) in chapter.metadata().iter() { + println!("\t{}: {}", k, v); + } + } - let mut octx = ffmpeg::format::output(&"test.mkv".to_owned()).expect(&format!("Couldn't open test file")); + let mut octx = + ffmpeg::format::output(&"test.mkv".to_owned()).expect("Couldn't open test file"); - for chapter in ictx.chapters() { - let title = match chapter.metadata().get("title") { - Some(title) => String::from(title), - None => String::new(), - }; + for chapter in ictx.chapters() { + let title = match chapter.metadata().get("title") { + Some(title) => String::from(title), + None => String::new(), + }; - match octx.add_chapter(chapter.id(), chapter.time_base(), chapter.start(), chapter.end(), &title) { - Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()), - Err(error) => println!("Error adding chapter with id: {} - {}", chapter.id(), error), - } - } + match octx.add_chapter( + chapter.id(), + chapter.time_base(), + chapter.start(), + chapter.end(), + &title, + ) { + Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()), + Err(error) => { + println!("Error adding chapter with id: {} - {}", chapter.id(), error) + } + } + } - println!("\nOuput: nb chapters: {}", octx.nb_chapters()); - for chapter in octx.chapters() { - println!("chapter id {}:", chapter.id()); - println!("\ttime_base: {}", chapter.time_base()); - println!("\tstart: {}", chapter.start()); - println!("\tend: {}", chapter.end()); - for (k, v) in chapter.metadata().iter() { - println!("\t{}: {}", k, v); - } - } - } + println!("\nOuput: nb chapters: {}", octx.nb_chapters()); + for chapter in octx.chapters() { + println!("chapter id {}:", chapter.id()); + println!("\ttime_base: {}", chapter.time_base()); + println!("\tstart: {}", chapter.start()); + println!("\tend: {}", chapter.end()); + for (k, v) in chapter.metadata().iter() { + println!("\t{}: {}", k, v); + } + } + } - Err(error) => - println!("error: {}", error) - } + Err(error) => println!("error: {}", error), + } } diff --git a/examples/codec-info.rs b/examples/codec-info.rs index eaaa813..82877ca 100644 --- a/examples/codec-info.rs +++ b/examples/codec-info.rs @@ -3,119 +3,108 @@ extern crate ffmpeg; use std::env; fn main() { - ffmpeg::init().unwrap(); + ffmpeg::init().unwrap(); - for arg in env::args().skip(1) { - if let Some(codec) = ffmpeg::decoder::find_by_name(&arg) { - println!("type: decoder"); - println!("\t id: {:?}", codec.id()); - println!("\t name: {}", codec.name()); - println!("\t description: {}", codec.description()); - println!("\t medium: {:?}", codec.medium()); - println!("\t capabilities: {:?}", codec.capabilities()); + for arg in env::args().skip(1) { + if let Some(codec) = ffmpeg::decoder::find_by_name(&arg) { + println!("type: decoder"); + println!("\t id: {:?}", codec.id()); + println!("\t name: {}", codec.name()); + println!("\t description: {}", codec.description()); + println!("\t medium: {:?}", codec.medium()); + println!("\t capabilities: {:?}", codec.capabilities()); - if let Some(profiles) = codec.profiles() { - println!("\t profiles: {:?}", profiles.collect::>()); - } - else { - println!("\t profiles: none"); - } + if let Some(profiles) = codec.profiles() { + println!("\t profiles: {:?}", profiles.collect::>()); + } else { + println!("\t profiles: none"); + } - if let Ok(video) = codec.video() { - if let Some(rates) = video.rates() { - println!("\t rates: {:?}", rates.collect::>()); - } - else { - println!("\t rates: any"); - } + if let Ok(video) = codec.video() { + if let Some(rates) = video.rates() { + println!("\t rates: {:?}", rates.collect::>()); + } else { + println!("\t rates: any"); + } - if let Some(formats) = video.formats() { - println!("\t formats: {:?}", formats.collect::>()); - } - else { - println!("\t formats: any"); - } - } + if let Some(formats) = video.formats() { + println!("\t formats: {:?}", formats.collect::>()); + } else { + println!("\t formats: any"); + } + } - if let Ok(audio) = codec.audio() { - if let Some(rates) = audio.rates() { - println!("\t rates: {:?}", rates.collect::>()); - } - else { - println!("\t rates: any"); - } + if let Ok(audio) = codec.audio() { + if let Some(rates) = audio.rates() { + println!("\t rates: {:?}", rates.collect::>()); + } else { + println!("\t rates: any"); + } - if let Some(formats) = audio.formats() { - println!("\t formats: {:?}", formats.collect::>()); - } - else { - println!("\t formats: any"); - } + if let Some(formats) = audio.formats() { + println!("\t formats: {:?}", formats.collect::>()); + } else { + println!("\t formats: any"); + } - if let Some(layouts) = audio.channel_layouts() { - println!("\t channel_layouts: {:?}", layouts.collect::>()); - } - else { - println!("\t channel_layouts: any"); - } - } + if let Some(layouts) = audio.channel_layouts() { + println!("\t channel_layouts: {:?}", layouts.collect::>()); + } else { + println!("\t channel_layouts: any"); + } + } - println!("\t max_lowres: {:?}", codec.max_lowres()); - } + println!("\t max_lowres: {:?}", codec.max_lowres()); + } - if let Some(codec) = ffmpeg::encoder::find_by_name(&arg) { - println!(""); - println!("type: encoder"); - println!("\t id: {:?}", codec.id()); - println!("\t name: {}", codec.name()); - println!("\t description: {}", codec.description()); - println!("\t medium: {:?}", codec.medium()); - println!("\t capabilities: {:?}", codec.capabilities()); + if let Some(codec) = ffmpeg::encoder::find_by_name(&arg) { + println!(); + println!("type: encoder"); + println!("\t id: {:?}", codec.id()); + println!("\t name: {}", codec.name()); + println!("\t description: {}", codec.description()); + println!("\t medium: {:?}", codec.medium()); + println!("\t capabilities: {:?}", codec.capabilities()); - if let Some(profiles) = codec.profiles() { - println!("\t profiles: {:?}", profiles.collect::>()); - } + if let Some(profiles) = codec.profiles() { + println!("\t profiles: {:?}", profiles.collect::>()); + } - if let Ok(video) = codec.video() { - if let Some(rates) = video.rates() { - println!("\t rates: {:?}", rates.collect::>()); - } - else { - println!("\t rates: any"); - } + if let Ok(video) = codec.video() { + if let Some(rates) = video.rates() { + println!("\t rates: {:?}", rates.collect::>()); + } else { + println!("\t rates: any"); + } - if let Some(formats) = video.formats() { - println!("\t formats: {:?}", formats.collect::>()); - } - else { - println!("\t formats: any"); - } - } + if let Some(formats) = video.formats() { + println!("\t formats: {:?}", formats.collect::>()); + } else { + println!("\t formats: any"); + } + } - if let Ok(audio) = codec.audio() { - if let Some(rates) = audio.rates() { - println!("\t rates: {:?}", rates.collect::>()); - } - else { - println!("\t rates: any"); - } + if let Ok(audio) = codec.audio() { + if let Some(rates) = audio.rates() { + println!("\t rates: {:?}", rates.collect::>()); + } else { + println!("\t rates: any"); + } - if let Some(formats) = audio.formats() { - println!("\t formats: {:?}", formats.collect::>()); - } - else { - println!("\t formats: any"); - } + if let Some(formats) = audio.formats() { + println!("\t formats: {:?}", formats.collect::>()); + } else { + println!("\t formats: any"); + } - if let Some(layouts) = audio.channel_layouts() { - println!("\t channel_layouts: {:?}", layouts.collect::>()); - } - else { - println!("\t channel_layouts: any"); - } - } + if let Some(layouts) = audio.channel_layouts() { + println!("\t channel_layouts: {:?}", layouts.collect::>()); + } else { + println!("\t channel_layouts: any"); + } + } - println!("\t max_lowres: {:?}", codec.max_lowres()); - } - } + println!("\t max_lowres: {:?}", codec.max_lowres()); + } + } } diff --git a/examples/metadata.rs b/examples/metadata.rs index 711d78e..1f8c884 100644 --- a/examples/metadata.rs +++ b/examples/metadata.rs @@ -3,81 +3,87 @@ extern crate ffmpeg; use std::env; fn main() { - ffmpeg::init().unwrap(); + ffmpeg::init().unwrap(); - match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) { - Ok(context) => { - for (k, v) in context.metadata().iter() { - println!("{}: {}", k, v); - } - - if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) { - println!("Best video stream index: {}", stream.index()); - } - - if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) { - println!("Best audio stream index: {}", stream.index()); - } - - if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) { - println!("Best subtitle stream index: {}", stream.index()); - } + match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) { + Ok(context) => { + for (k, v) in context.metadata().iter() { + println!("{}: {}", k, v); + } - println!("duration (seconds): {:.2}", context.duration() as f64 / ffmpeg::ffi::AV_TIME_BASE as f64); + if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) { + println!("Best video stream index: {}", stream.index()); + } - for stream in context.streams() { - println!("stream index {}:", stream.index()); - println!("\ttime_base: {}", stream.time_base()); - println!("\tstart_time: {}", stream.start_time()); - println!("\tduration (stream timebase): {}", stream.duration()); - println!("\tduration (seconds): {:.2}", stream.duration() as f64 * f64::from(stream.time_base())); - println!("\tframes: {}", stream.frames()); - println!("\tdisposition: {:?}", stream.disposition()); - println!("\tdiscard: {:?}", stream.discard()); - println!("\trate: {}", stream.rate()); - - let codec = stream.codec(); - println!("\tmedium: {:?}", codec.medium()); - println!("\tid: {:?}", codec.id()); - - if codec.medium() == ffmpeg::media::Type::Video { - if let Ok(video) = codec.decoder().video() { - println!("\tbit_rate: {}", video.bit_rate()); - println!("\tmax_rate: {}", video.max_bit_rate()); - println!("\tdelay: {}", video.delay()); - println!("\tvideo.width: {}", video.width()); - println!("\tvideo.height: {}", video.height()); - println!("\tvideo.format: {:?}", video.format()); - println!("\tvideo.has_b_frames: {}", video.has_b_frames()); - println!("\tvideo.aspect_ratio: {}", video.aspect_ratio()); - println!("\tvideo.color_space: {:?}", video.color_space()); - println!("\tvideo.color_range: {:?}", video.color_range()); - println!("\tvideo.color_primaries: {:?}", video.color_primaries()); - println!("\tvideo.color_transfer_characteristic: {:?}", video.color_transfer_characteristic()); - println!("\tvideo.chroma_location: {:?}", video.chroma_location()); - println!("\tvideo.references: {}", video.references()); - println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision()); - } - } - else if codec.medium() == ffmpeg::media::Type::Audio { - if let Ok(audio) = codec.decoder().audio() { - println!("\tbit_rate: {}", audio.bit_rate()); - println!("\tmax_rate: {}", audio.max_bit_rate()); - println!("\tdelay: {}", audio.delay()); - println!("\taudio.rate: {}", audio.rate()); - println!("\taudio.channels: {}", audio.channels()); - println!("\taudio.format: {:?}", audio.format()); - println!("\taudio.frames: {}", audio.frames()); - println!("\taudio.align: {}", audio.align()); - println!("\taudio.channel_layout: {:?}", audio.channel_layout()); - println!("\taudio.frame_start: {:?}", audio.frame_start()); - } - } - } + if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) { + println!("Best audio stream index: {}", stream.index()); + } - } + if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) { + println!("Best subtitle stream index: {}", stream.index()); + } - Err(error) => - println!("error: {}", error) - } + println!( + "duration (seconds): {:.2}", + context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE) + ); + + for stream in context.streams() { + println!("stream index {}:", stream.index()); + println!("\ttime_base: {}", stream.time_base()); + println!("\tstart_time: {}", stream.start_time()); + println!("\tduration (stream timebase): {}", stream.duration()); + println!( + "\tduration (seconds): {:.2}", + stream.duration() as f64 * f64::from(stream.time_base()) + ); + println!("\tframes: {}", stream.frames()); + println!("\tdisposition: {:?}", stream.disposition()); + println!("\tdiscard: {:?}", stream.discard()); + println!("\trate: {}", stream.rate()); + + let codec = stream.codec(); + println!("\tmedium: {:?}", codec.medium()); + println!("\tid: {:?}", codec.id()); + + if codec.medium() == ffmpeg::media::Type::Video { + if let Ok(video) = codec.decoder().video() { + println!("\tbit_rate: {}", video.bit_rate()); + println!("\tmax_rate: {}", video.max_bit_rate()); + println!("\tdelay: {}", video.delay()); + println!("\tvideo.width: {}", video.width()); + println!("\tvideo.height: {}", video.height()); + println!("\tvideo.format: {:?}", video.format()); + println!("\tvideo.has_b_frames: {}", video.has_b_frames()); + println!("\tvideo.aspect_ratio: {}", video.aspect_ratio()); + println!("\tvideo.color_space: {:?}", video.color_space()); + println!("\tvideo.color_range: {:?}", video.color_range()); + println!("\tvideo.color_primaries: {:?}", video.color_primaries()); + println!( + "\tvideo.color_transfer_characteristic: {:?}", + video.color_transfer_characteristic() + ); + println!("\tvideo.chroma_location: {:?}", video.chroma_location()); + println!("\tvideo.references: {}", video.references()); + println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision()); + } + } else if codec.medium() == ffmpeg::media::Type::Audio { + if let Ok(audio) = codec.decoder().audio() { + println!("\tbit_rate: {}", audio.bit_rate()); + println!("\tmax_rate: {}", audio.max_bit_rate()); + println!("\tdelay: {}", audio.delay()); + println!("\taudio.rate: {}", audio.rate()); + println!("\taudio.channels: {}", audio.channels()); + println!("\taudio.format: {:?}", audio.format()); + println!("\taudio.frames: {}", audio.frames()); + println!("\taudio.align: {}", audio.align()); + println!("\taudio.channel_layout: {:?}", audio.channel_layout()); + println!("\taudio.frame_start: {:?}", audio.frame_start()); + } + } + } + } + + Err(error) => println!("error: {}", error), + } } diff --git a/examples/transcode-audio.rs b/examples/transcode-audio.rs index 71e3a3b..0d416a1 100644 --- a/examples/transcode-audio.rs +++ b/examples/transcode-audio.rs @@ -3,87 +3,121 @@ extern crate ffmpeg; use std::env; use std::path::Path; -use ffmpeg::{format, codec, frame, media, filter}; +use ffmpeg::{codec, filter, format, frame, media}; use ffmpeg::{rescale, Rescale}; -fn filter(spec: &str, decoder: &codec::decoder::Audio, encoder: &codec::encoder::Audio) -> Result { - let mut filter = filter::Graph::new(); +fn filter( + spec: &str, + decoder: &codec::decoder::Audio, + encoder: &codec::encoder::Audio, +) -> Result { + let mut filter = filter::Graph::new(); - let args = format!("time_base={}:sample_rate={}:sample_fmt={}:channel_layout=0x{:x}", - decoder.time_base(), decoder.rate(), decoder.format().name(), decoder.channel_layout().bits()); + let args = format!( + "time_base={}:sample_rate={}:sample_fmt={}:channel_layout=0x{:x}", + decoder.time_base(), + decoder.rate(), + decoder.format().name(), + decoder.channel_layout().bits() + ); - try!(filter.add(&filter::find("abuffer").unwrap(), "in", &args)); - try!(filter.add(&filter::find("abuffersink").unwrap(), "out", "")); + filter.add(&filter::find("abuffer").unwrap(), "in", &args)?; + filter.add(&filter::find("abuffersink").unwrap(), "out", "")?; - { - let mut out = filter.get("out").unwrap(); + { + let mut out = filter.get("out").unwrap(); - out.set_sample_format(encoder.format()); - out.set_channel_layout(encoder.channel_layout()); - out.set_sample_rate(encoder.rate()); - } + out.set_sample_format(encoder.format()); + out.set_channel_layout(encoder.channel_layout()); + out.set_sample_rate(encoder.rate()); + } - try!(try!(try!(filter.output("in", 0)).input("out", 0)).parse(spec)); - try!(filter.validate()); + filter.output("in", 0)?.input("out", 0)?.parse(spec)?; + filter.validate()?; - println!("{}", filter.dump()); + println!("{}", filter.dump()); - if let Some(codec) = encoder.codec() { - if !codec.capabilities().contains(ffmpeg::codec::capabilities::VARIABLE_FRAME_SIZE) { - filter.get("out").unwrap().sink().set_frame_size(encoder.frame_size()); - } - } + if let Some(codec) = encoder.codec() { + if !codec + .capabilities() + .contains(ffmpeg::codec::capabilities::VARIABLE_FRAME_SIZE) + { + filter + .get("out") + .unwrap() + .sink() + .set_frame_size(encoder.frame_size()); + } + } - Ok(filter) + Ok(filter) } struct Transcoder { - stream: usize, - filter: filter::Graph, - decoder: codec::decoder::Audio, - encoder: codec::encoder::Audio, + stream: usize, + filter: filter::Graph, + decoder: codec::decoder::Audio, + encoder: codec::encoder::Audio, } -fn transcoder>(ictx: &mut format::context::Input, octx: &mut format::context::Output, path: &P, filter_spec: &str) -> Result { - let input = ictx.streams().best(media::Type::Audio).expect("could not find best audio stream"); - let mut decoder = try!(input.codec().decoder().audio()); - let codec = try!(ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio)).expect("failed to find encoder").audio()); - let global = octx.format().flags().contains(ffmpeg::format::flag::GLOBAL_HEADER); +fn transcoder>( + ictx: &mut format::context::Input, + octx: &mut format::context::Output, + path: &P, + filter_spec: &str, +) -> Result { + let input = ictx.streams() + .best(media::Type::Audio) + .expect("could not find best audio stream"); + let mut decoder = input.codec().decoder().audio()?; + let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio)) + .expect("failed to find encoder") + .audio()?; + let global = octx.format() + .flags() + .contains(ffmpeg::format::flag::GLOBAL_HEADER); - try!(decoder.set_parameters(input.parameters())); + decoder.set_parameters(input.parameters())?; - let mut output = try!(octx.add_stream(codec)); - let mut encoder = try!(output.codec().encoder().audio()); + let mut output = octx.add_stream(codec)?; + let mut encoder = output.codec().encoder().audio()?; - let channel_layout = codec.channel_layouts() - .map(|cls| cls.best(decoder.channel_layout().channels())) - .unwrap_or(ffmpeg::channel_layout::STEREO); + let channel_layout = codec + .channel_layouts() + .map(|cls| cls.best(decoder.channel_layout().channels())) + .unwrap_or(ffmpeg::channel_layout::STEREO); - if global { - encoder.set_flags(ffmpeg::codec::flag::GLOBAL_HEADER); - } + if global { + encoder.set_flags(ffmpeg::codec::flag::GLOBAL_HEADER); + } - encoder.set_rate(decoder.rate() as i32); - encoder.set_channel_layout(channel_layout); - encoder.set_channels(channel_layout.channels()); - encoder.set_format(codec.formats().expect("unknown supported formats").next().unwrap()); - encoder.set_bit_rate(decoder.bit_rate()); - encoder.set_max_bit_rate(decoder.max_bit_rate()); + encoder.set_rate(decoder.rate() as i32); + encoder.set_channel_layout(channel_layout); + encoder.set_channels(channel_layout.channels()); + encoder.set_format( + codec + .formats() + .expect("unknown supported formats") + .next() + .unwrap(), + ); + encoder.set_bit_rate(decoder.bit_rate()); + encoder.set_max_bit_rate(decoder.max_bit_rate()); - encoder.set_time_base((1, decoder.rate() as i32)); - output.set_time_base((1, decoder.rate() as i32)); + encoder.set_time_base((1, decoder.rate() as i32)); + output.set_time_base((1, decoder.rate() as i32)); - let encoder = try!(encoder.open_as(codec)); - output.set_parameters(&encoder); + let encoder = encoder.open_as(codec)?; + output.set_parameters(&encoder); - let filter = try!(filter(filter_spec, &decoder, &encoder)); + let filter = filter(filter_spec, &decoder, &encoder)?; - Ok(Transcoder { - stream: input.index(), - filter: filter, - decoder: decoder, - encoder: encoder, - }) + Ok(Transcoder { + stream: input.index(), + filter: filter, + decoder: decoder, + encoder: encoder, + }) } // Transcode the `best` audio stream of the input file into a the output file while applying a @@ -98,70 +132,94 @@ fn transcoder>(ictx: &mut format::context::Input, octx: &mut form // Example 3: Seek to a specified position (in seconds) // transcode-audio in.mp3 out.mp3 anull 30 fn main() { - ffmpeg::init().unwrap(); + ffmpeg::init().unwrap(); - let input = env::args().nth(1).expect("missing input"); - let output = env::args().nth(2).expect("missing output"); - let filter = env::args().nth(3).unwrap_or("anull".to_owned()); - let seek = env::args().nth(4).and_then(|s| s.parse::().ok()); + let input = env::args().nth(1).expect("missing input"); + let output = env::args().nth(2).expect("missing output"); + let filter = env::args().nth(3).unwrap_or_else(|| "anull".to_owned()); + let seek = env::args().nth(4).and_then(|s| s.parse::().ok()); - let mut ictx = format::input(&input).unwrap(); - let mut octx = format::output(&output).unwrap(); - let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap(); + let mut ictx = format::input(&input).unwrap(); + let mut octx = format::output(&output).unwrap(); + let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap(); - if let Some(position) = seek { - // If the position was given in seconds, rescale it to ffmpegs base timebase. - let position = position.rescale((1, 1), rescale::TIME_BASE); - // If this seek was embedded in the transcoding loop, a call of `flush()` - // for every opened buffer after the successful seek would be advisable. - ictx.seek(position, ..position).unwrap(); - } + if let Some(position) = seek { + // If the position was given in seconds, rescale it to ffmpegs base timebase. + let position = position.rescale((1, 1), rescale::TIME_BASE); + // If this seek was embedded in the transcoding loop, a call of `flush()` + // for every opened buffer after the successful seek would be advisable. + ictx.seek(position, ..position).unwrap(); + } - octx.set_metadata(ictx.metadata().to_owned()); - octx.write_header().unwrap(); + octx.set_metadata(ictx.metadata().to_owned()); + octx.write_header().unwrap(); - let in_time_base = transcoder.decoder.time_base(); - let out_time_base = octx.stream(0).unwrap().time_base(); + let in_time_base = transcoder.decoder.time_base(); + let out_time_base = octx.stream(0).unwrap().time_base(); - let mut decoded = frame::Audio::empty(); - let mut encoded = ffmpeg::Packet::empty(); + let mut decoded = frame::Audio::empty(); + let mut encoded = ffmpeg::Packet::empty(); - for (stream, mut packet) in ictx.packets() { - if stream.index() == transcoder.stream { - packet.rescale_ts(stream.time_base(), in_time_base); + for (stream, mut packet) in ictx.packets() { + if stream.index() == transcoder.stream { + packet.rescale_ts(stream.time_base(), in_time_base); - if let Ok(true) = transcoder.decoder.decode(&packet, &mut decoded) { - let timestamp = decoded.timestamp(); - decoded.set_pts(timestamp); + if let Ok(true) = transcoder.decoder.decode(&packet, &mut decoded) { + let timestamp = decoded.timestamp(); + decoded.set_pts(timestamp); - transcoder.filter.get("in").unwrap().source().add(&decoded).unwrap(); + transcoder + .filter + .get("in") + .unwrap() + .source() + .add(&decoded) + .unwrap(); - while let Ok(..) = transcoder.filter.get("out").unwrap().sink().frame(&mut decoded) { - if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) { - encoded.set_stream(0); - encoded.rescale_ts(in_time_base, out_time_base); - encoded.write_interleaved(&mut octx).unwrap(); - } - } - } - } - } + while let Ok(..) = transcoder + .filter + .get("out") + .unwrap() + .sink() + .frame(&mut decoded) + { + if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) { + encoded.set_stream(0); + encoded.rescale_ts(in_time_base, out_time_base); + encoded.write_interleaved(&mut octx).unwrap(); + } + } + } + } + } - transcoder.filter.get("in").unwrap().source().flush().unwrap(); + transcoder + .filter + .get("in") + .unwrap() + .source() + .flush() + .unwrap(); - while let Ok(..) = transcoder.filter.get("out").unwrap().sink().frame(&mut decoded) { - if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) { - encoded.set_stream(0); - encoded.rescale_ts(in_time_base, out_time_base); - encoded.write_interleaved(&mut octx).unwrap(); - } - } + while let Ok(..) = transcoder + .filter + .get("out") + .unwrap() + .sink() + .frame(&mut decoded) + { + if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) { + encoded.set_stream(0); + encoded.rescale_ts(in_time_base, out_time_base); + encoded.write_interleaved(&mut octx).unwrap(); + } + } - if let Ok(true) = transcoder.encoder.flush(&mut encoded) { - encoded.set_stream(0); - encoded.rescale_ts(in_time_base, out_time_base); - encoded.write_interleaved(&mut octx).unwrap(); - } + if let Ok(true) = transcoder.encoder.flush(&mut encoded) { + encoded.set_stream(0); + encoded.rescale_ts(in_time_base, out_time_base); + encoded.write_interleaved(&mut octx).unwrap(); + } - octx.write_trailer().unwrap(); + octx.write_trailer().unwrap(); } diff --git a/src/codec/audio.rs b/src/codec/audio.rs index 71aefae..f2f5fdd 100644 --- a/src/codec/audio.rs +++ b/src/codec/audio.rs @@ -1,152 +1,149 @@ use std::ops::Deref; -use {ChannelLayout, format}; use super::codec::Codec; use ffi::*; +use {format, ChannelLayout}; #[derive(PartialEq, Eq, Copy, Clone)] pub struct Audio { - codec: Codec, + codec: Codec, } impl Audio { - pub unsafe fn new(codec: Codec) -> Audio { - Audio { - codec: codec, - } - } + pub unsafe fn new(codec: Codec) -> Audio { + Audio { codec: codec } + } } impl Audio { - pub fn rates(&self) -> Option { - unsafe { - if (*self.as_ptr()).supported_samplerates.is_null() { - None - } - else { - Some(RateIter::new((*self.codec.as_ptr()).supported_samplerates)) - } - } - } + pub fn rates(&self) -> Option { + unsafe { + if (*self.as_ptr()).supported_samplerates.is_null() { + None + } else { + Some(RateIter::new((*self.codec.as_ptr()).supported_samplerates)) + } + } + } - pub fn formats(&self) -> Option { - unsafe { - if (*self.codec.as_ptr()).sample_fmts.is_null() { - None - } - else { - Some(FormatIter::new((*self.codec.as_ptr()).sample_fmts)) - } - } - } + pub fn formats(&self) -> Option { + unsafe { + 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) -> Option { - unsafe { - if (*self.codec.as_ptr()).channel_layouts.is_null() { - None - } - else { - Some(ChannelLayoutIter::new((*self.codec.as_ptr()).channel_layouts)) - } - } - } + pub fn channel_layouts(&self) -> Option { + unsafe { + if (*self.codec.as_ptr()).channel_layouts.is_null() { + None + } else { + Some(ChannelLayoutIter::new( + (*self.codec.as_ptr()).channel_layouts, + )) + } + } + } } impl Deref for Audio { - type Target = Codec; + type Target = Codec; - fn deref(&self) -> &Self::Target { - &self.codec - } + fn deref(&self) -> &Self::Target { + &self.codec + } } pub struct RateIter { - ptr: *const i32, + ptr: *const i32, } impl RateIter { - pub fn new(ptr: *const i32) -> Self { - RateIter { ptr: ptr } - } + pub fn new(ptr: *const i32) -> Self { + RateIter { ptr: ptr } + } } impl Iterator for RateIter { - type Item = i32; + type Item = i32; - fn next(&mut self) -> Option<::Item> { - unsafe { - if *self.ptr == 0 { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if *self.ptr == 0 { + return None; + } - let rate = *self.ptr; - self.ptr = self.ptr.offset(1); + let rate = *self.ptr; + self.ptr = self.ptr.offset(1); - Some(rate) - } - } + Some(rate) + } + } } pub struct FormatIter { - ptr: *const AVSampleFormat, + ptr: *const AVSampleFormat, } impl FormatIter { - pub fn new(ptr: *const AVSampleFormat) -> Self { - FormatIter { ptr: ptr } - } + pub fn new(ptr: *const AVSampleFormat) -> Self { + FormatIter { ptr: ptr } + } } impl Iterator for FormatIter { - type Item = format::Sample; + type Item = format::Sample; - fn next(&mut self) -> Option<::Item> { - unsafe { - if *self.ptr == AVSampleFormat::AV_SAMPLE_FMT_NONE { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if *self.ptr == AVSampleFormat::AV_SAMPLE_FMT_NONE { + return None; + } - let format = (*self.ptr).into(); - self.ptr = self.ptr.offset(1); + let format = (*self.ptr).into(); + self.ptr = self.ptr.offset(1); - Some(format) - } - } + Some(format) + } + } } pub struct ChannelLayoutIter { - ptr: *const u64, + ptr: *const u64, } impl ChannelLayoutIter { - pub fn new(ptr: *const u64) -> Self { - ChannelLayoutIter { ptr: ptr } - } + pub fn new(ptr: *const u64) -> Self { + ChannelLayoutIter { ptr: ptr } + } - pub fn best(self, max: i32) -> ChannelLayout { - self.fold(::channel_layout::MONO, |acc, cur| - if cur.channels() > acc.channels() && cur.channels() <= max { - cur - } - else { - acc - }) - } + pub fn best(self, max: i32) -> ChannelLayout { + self.fold(::channel_layout::MONO, |acc, cur| { + if cur.channels() > acc.channels() && cur.channels() <= max { + cur + } else { + acc + } + }) + } } impl Iterator for ChannelLayoutIter { - type Item = ChannelLayout; + type Item = ChannelLayout; - fn next(&mut self) -> Option<::Item> { - unsafe { - if *self.ptr == 0 { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if *self.ptr == 0 { + return None; + } - let layout = ChannelLayout::from_bits_truncate(*self.ptr); - self.ptr = self.ptr.offset(1); + let layout = ChannelLayout::from_bits_truncate(*self.ptr); + self.ptr = self.ptr.offset(1); - Some(layout) - } - } + Some(layout) + } + } } diff --git a/src/codec/audio_service.rs b/src/codec/audio_service.rs index a02caa0..e1ca3eb 100644 --- a/src/codec/audio_service.rs +++ b/src/codec/audio_service.rs @@ -1,48 +1,48 @@ -use ffi::*; use ffi::AVAudioServiceType::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum AudioService { - Main, - Effects, - VisuallyImpaired, - HearingImpaired, - Dialogue, - Commentary, - Emergency, - VoiceOver, - Karaoke, + Main, + Effects, + VisuallyImpaired, + HearingImpaired, + Dialogue, + Commentary, + Emergency, + VoiceOver, + Karaoke, } impl From for AudioService { - fn from(value: AVAudioServiceType) -> Self { - match value { - AV_AUDIO_SERVICE_TYPE_MAIN => AudioService::Main, - AV_AUDIO_SERVICE_TYPE_EFFECTS => AudioService::Effects, - AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED => AudioService::VisuallyImpaired, - AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED => AudioService::HearingImpaired, - AV_AUDIO_SERVICE_TYPE_DIALOGUE => AudioService::Dialogue, - AV_AUDIO_SERVICE_TYPE_COMMENTARY => AudioService::Commentary, - AV_AUDIO_SERVICE_TYPE_EMERGENCY => AudioService::Emergency, - AV_AUDIO_SERVICE_TYPE_VOICE_OVER => AudioService::VoiceOver, - AV_AUDIO_SERVICE_TYPE_KARAOKE => AudioService::Karaoke, - AV_AUDIO_SERVICE_TYPE_NB => AudioService::Main - } - } + fn from(value: AVAudioServiceType) -> Self { + match value { + AV_AUDIO_SERVICE_TYPE_MAIN => AudioService::Main, + AV_AUDIO_SERVICE_TYPE_EFFECTS => AudioService::Effects, + AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED => AudioService::VisuallyImpaired, + AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED => AudioService::HearingImpaired, + AV_AUDIO_SERVICE_TYPE_DIALOGUE => AudioService::Dialogue, + AV_AUDIO_SERVICE_TYPE_COMMENTARY => AudioService::Commentary, + AV_AUDIO_SERVICE_TYPE_EMERGENCY => AudioService::Emergency, + AV_AUDIO_SERVICE_TYPE_VOICE_OVER => AudioService::VoiceOver, + AV_AUDIO_SERVICE_TYPE_KARAOKE => AudioService::Karaoke, + AV_AUDIO_SERVICE_TYPE_NB => AudioService::Main, + } + } } impl Into for AudioService { - fn into(self) -> AVAudioServiceType { - match self { - AudioService::Main => AV_AUDIO_SERVICE_TYPE_MAIN, - AudioService::Effects => AV_AUDIO_SERVICE_TYPE_EFFECTS, - AudioService::VisuallyImpaired => AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED, - AudioService::HearingImpaired => AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED, - AudioService::Dialogue => AV_AUDIO_SERVICE_TYPE_DIALOGUE, - AudioService::Commentary => AV_AUDIO_SERVICE_TYPE_COMMENTARY, - AudioService::Emergency => AV_AUDIO_SERVICE_TYPE_EMERGENCY, - AudioService::VoiceOver => AV_AUDIO_SERVICE_TYPE_VOICE_OVER, - AudioService::Karaoke => AV_AUDIO_SERVICE_TYPE_KARAOKE - } - } + fn into(self) -> AVAudioServiceType { + match self { + AudioService::Main => AV_AUDIO_SERVICE_TYPE_MAIN, + AudioService::Effects => AV_AUDIO_SERVICE_TYPE_EFFECTS, + AudioService::VisuallyImpaired => AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED, + AudioService::HearingImpaired => AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED, + AudioService::Dialogue => AV_AUDIO_SERVICE_TYPE_DIALOGUE, + AudioService::Commentary => AV_AUDIO_SERVICE_TYPE_COMMENTARY, + AudioService::Emergency => AV_AUDIO_SERVICE_TYPE_EMERGENCY, + AudioService::VoiceOver => AV_AUDIO_SERVICE_TYPE_VOICE_OVER, + AudioService::Karaoke => AV_AUDIO_SERVICE_TYPE_KARAOKE, + } + } } diff --git a/src/codec/capabilities.rs b/src/codec/capabilities.rs index dfa47ea..2a752de 100644 --- a/src/codec/capabilities.rs +++ b/src/codec/capabilities.rs @@ -1,23 +1,23 @@ -use libc::c_uint; use ffi::*; +use libc::c_uint; bitflags! { - pub struct Capabilities: c_uint { - const DRAW_HORIZ_BAND = AV_CODEC_CAP_DRAW_HORIZ_BAND; - const DR1 = AV_CODEC_CAP_DR1; - const TRUNCATED = AV_CODEC_CAP_TRUNCATED; - const DELAY = AV_CODEC_CAP_DELAY; - const SMALL_LAST_FRAME = AV_CODEC_CAP_SMALL_LAST_FRAME; - const HWACCEL_VDPAU = AV_CODEC_CAP_HWACCEL_VDPAU; - const SUBFRAMES = AV_CODEC_CAP_SUBFRAMES; - const EXPERIMENTAL = AV_CODEC_CAP_EXPERIMENTAL; - const CHANNEL_CONF = AV_CODEC_CAP_CHANNEL_CONF; - const FRAME_THREADS = AV_CODEC_CAP_FRAME_THREADS; - const SLICE_THREADS = AV_CODEC_CAP_SLICE_THREADS; - const PARAM_CHANGE = AV_CODEC_CAP_PARAM_CHANGE; - const AUTO_THREADS = AV_CODEC_CAP_AUTO_THREADS; - const VARIABLE_FRAME_SIZE = AV_CODEC_CAP_VARIABLE_FRAME_SIZE; - const INTRA_ONLY = AV_CODEC_CAP_INTRA_ONLY; - const LOSSLESS = AV_CODEC_CAP_LOSSLESS; - } + pub struct Capabilities: c_uint { + const DRAW_HORIZ_BAND = AV_CODEC_CAP_DRAW_HORIZ_BAND; + const DR1 = AV_CODEC_CAP_DR1; + const TRUNCATED = AV_CODEC_CAP_TRUNCATED; + const DELAY = AV_CODEC_CAP_DELAY; + const SMALL_LAST_FRAME = AV_CODEC_CAP_SMALL_LAST_FRAME; + const HWACCEL_VDPAU = AV_CODEC_CAP_HWACCEL_VDPAU; + const SUBFRAMES = AV_CODEC_CAP_SUBFRAMES; + const EXPERIMENTAL = AV_CODEC_CAP_EXPERIMENTAL; + const CHANNEL_CONF = AV_CODEC_CAP_CHANNEL_CONF; + const FRAME_THREADS = AV_CODEC_CAP_FRAME_THREADS; + const SLICE_THREADS = AV_CODEC_CAP_SLICE_THREADS; + const PARAM_CHANGE = AV_CODEC_CAP_PARAM_CHANGE; + const AUTO_THREADS = AV_CODEC_CAP_AUTO_THREADS; + const VARIABLE_FRAME_SIZE = AV_CODEC_CAP_VARIABLE_FRAME_SIZE; + const INTRA_ONLY = AV_CODEC_CAP_INTRA_ONLY; + const LOSSLESS = AV_CODEC_CAP_LOSSLESS; + } } diff --git a/src/codec/codec.rs b/src/codec/codec.rs index c9f02ff..f733524 100644 --- a/src/codec/codec.rs +++ b/src/codec/codec.rs @@ -1,147 +1,128 @@ use std::ffi::CStr; use std::str::from_utf8_unchecked; +use super::{Audio, Capabilities, Id, Profile, Video}; use ffi::*; -use super::{Id, Video, Audio, Capabilities, Profile}; -use ::{Error, media}; +use {media, Error}; #[derive(PartialEq, Eq, Copy, Clone)] pub struct Codec { - ptr: *mut AVCodec, + ptr: *mut AVCodec, } -unsafe impl Send for Codec { } -unsafe impl Sync for Codec { } +unsafe impl Send for Codec {} +unsafe impl Sync for Codec {} impl Codec { - pub unsafe fn wrap(ptr: *mut AVCodec) -> Self { - Codec { ptr: ptr } - } + pub unsafe fn wrap(ptr: *mut AVCodec) -> Self { + Codec { ptr: ptr } + } - pub unsafe fn as_ptr(&self) -> *const AVCodec { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVCodec { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodec { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodec { + self.ptr + } } impl Codec { - pub fn is_encoder(&self) -> bool { - unsafe { - av_codec_is_encoder(self.as_ptr()) != 0 - } - } + pub fn is_encoder(&self) -> bool { + unsafe { av_codec_is_encoder(self.as_ptr()) != 0 } + } - pub fn is_decoder(&self) -> bool { - unsafe { - av_codec_is_decoder(self.as_ptr()) != 0 - } - } + pub fn is_decoder(&self) -> bool { + unsafe { av_codec_is_decoder(self.as_ptr()) != 0 } + } - pub fn name(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) - } - } + pub fn name(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) } + } - pub fn description(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) - } - } + pub fn description(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) } + } - pub fn medium(&self) -> media::Type { - unsafe { - media::Type::from((*self.as_ptr()).type_) - } - } + pub fn medium(&self) -> media::Type { + unsafe { media::Type::from((*self.as_ptr()).type_) } + } - pub fn id(&self) -> Id { - unsafe { - Id::from((*self.as_ptr()).id) - } - } + pub fn id(&self) -> Id { + unsafe { Id::from((*self.as_ptr()).id) } + } - pub fn is_video(&self) -> bool { - self.medium() == media::Type::Video - } + 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)) - } - else { - Err(Error::InvalidData) - } - } - } + pub fn video(self) -> Result { + unsafe { + if self.medium() == media::Type::Video { + Ok(Video::new(self)) + } else { + Err(Error::InvalidData) + } + } + } - pub fn is_audio(&self) -> bool { - self.medium() == media::Type::Audio - } + 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)) - } - else { - Err(Error::InvalidData) - } - } - } + pub fn audio(self) -> Result { + unsafe { + if self.medium() == media::Type::Audio { + Ok(Audio::new(self)) + } else { + Err(Error::InvalidData) + } + } + } - pub fn max_lowres(&self) -> i32 { - unsafe { - av_codec_get_max_lowres(self.as_ptr()) - } - } + pub fn max_lowres(&self) -> i32 { + unsafe { av_codec_get_max_lowres(self.as_ptr()) } + } - pub fn capabilities(&self) -> Capabilities { - unsafe { - Capabilities::from_bits_truncate((*self.as_ptr()).capabilities as u32) - } - } + pub fn capabilities(&self) -> Capabilities { + unsafe { Capabilities::from_bits_truncate((*self.as_ptr()).capabilities as u32) } + } - pub fn profiles(&self) -> Option { - unsafe { - if (*self.as_ptr()).profiles.is_null() { - None - } - else { - Some(ProfileIter::new(self.id(), (*self.as_ptr()).profiles)) - } - } - } + pub fn profiles(&self) -> Option { + unsafe { + if (*self.as_ptr()).profiles.is_null() { + None + } else { + Some(ProfileIter::new(self.id(), (*self.as_ptr()).profiles)) + } + } + } } pub struct ProfileIter { - id: Id, - ptr: *const AVProfile, + id: Id, + ptr: *const AVProfile, } impl ProfileIter { - pub fn new(id: Id, ptr: *const AVProfile) -> Self { - ProfileIter { id: id, ptr: ptr } - } + pub fn new(id: Id, ptr: *const AVProfile) -> Self { + ProfileIter { id: id, ptr: ptr } + } } impl Iterator for ProfileIter { - type Item = Profile; + type Item = Profile; - fn next(&mut self) -> Option<::Item> { - unsafe { - if (*self.ptr).profile == FF_PROFILE_UNKNOWN { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if (*self.ptr).profile == FF_PROFILE_UNKNOWN { + return None; + } - let profile = Profile::from((self.id, (*self.ptr).profile)); - self.ptr = self.ptr.offset(1); + let profile = Profile::from((self.id, (*self.ptr).profile)); + self.ptr = self.ptr.offset(1); - Some(profile) - } - } + Some(profile) + } + } } diff --git a/src/codec/compliance.rs b/src/codec/compliance.rs index 70ec498..e6f1ec3 100644 --- a/src/codec/compliance.rs +++ b/src/codec/compliance.rs @@ -1,37 +1,37 @@ -use libc::c_int; use ffi::*; +use libc::c_int; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Compliance { - VeryStrict, - Strict, - Normal, - Unofficial, - Experimental, + VeryStrict, + Strict, + Normal, + Unofficial, + Experimental, } impl From for Compliance { - fn from(value: c_int) -> Self { - match value { - FF_COMPLIANCE_VERY_STRICT => Compliance::VeryStrict, - FF_COMPLIANCE_STRICT => Compliance::Strict, - FF_COMPLIANCE_NORMAL => Compliance::Normal, - FF_COMPLIANCE_UNOFFICIAL => Compliance::Unofficial, - FF_COMPLIANCE_EXPERIMENTAL => Compliance::Experimental, + fn from(value: c_int) -> Self { + match value { + FF_COMPLIANCE_VERY_STRICT => Compliance::VeryStrict, + FF_COMPLIANCE_STRICT => Compliance::Strict, + FF_COMPLIANCE_NORMAL => Compliance::Normal, + FF_COMPLIANCE_UNOFFICIAL => Compliance::Unofficial, + FF_COMPLIANCE_EXPERIMENTAL => Compliance::Experimental, - _ => Compliance::Normal - } - } + _ => Compliance::Normal, + } + } } impl Into for Compliance { - fn into(self) -> c_int { - match self { - Compliance::VeryStrict => FF_COMPLIANCE_VERY_STRICT, - Compliance::Strict => FF_COMPLIANCE_STRICT, - Compliance::Normal => FF_COMPLIANCE_NORMAL, - Compliance::Unofficial => FF_COMPLIANCE_UNOFFICIAL, - Compliance::Experimental => FF_COMPLIANCE_EXPERIMENTAL - } - } + fn into(self) -> c_int { + match self { + Compliance::VeryStrict => FF_COMPLIANCE_VERY_STRICT, + Compliance::Strict => FF_COMPLIANCE_STRICT, + Compliance::Normal => FF_COMPLIANCE_NORMAL, + Compliance::Unofficial => FF_COMPLIANCE_UNOFFICIAL, + Compliance::Experimental => FF_COMPLIANCE_EXPERIMENTAL, + } + } } diff --git a/src/codec/context.rs b/src/codec/context.rs index 98de7f4..d30dd82 100644 --- a/src/codec/context.rs +++ b/src/codec/context.rs @@ -1,142 +1,149 @@ use std::ptr; use std::rc::Rc; -use libc::c_int; -use ffi::*; -use ::media; -use ::{Codec, Error}; -use super::{Flags, Id, Debug, Compliance, threading, Parameters}; use super::decoder::Decoder; use super::encoder::Encoder; +use super::{threading, Compliance, Debug, Flags, Id, Parameters}; +use ffi::*; +use libc::c_int; +use media; +use {Codec, Error}; pub struct Context { - ptr: *mut AVCodecContext, - owner: Option>, + ptr: *mut AVCodecContext, + owner: Option>, } -unsafe impl Send for Context { } +unsafe impl Send for Context {} impl Context { - pub unsafe fn wrap(ptr: *mut AVCodecContext, owner: Option>) -> Self { - Context { ptr: ptr, owner: owner } - } + pub unsafe fn wrap(ptr: *mut AVCodecContext, owner: Option>) -> Self { + Context { + ptr: ptr, + owner: owner, + } + } - pub unsafe fn as_ptr(&self) -> *const AVCodecContext { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVCodecContext { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecContext { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecContext { + self.ptr + } } impl Context { - pub fn new() -> Self { - unsafe { - Context { ptr: avcodec_alloc_context3(ptr::null()), owner: None } - } - } + pub fn new() -> Self { + unsafe { + Context { + ptr: avcodec_alloc_context3(ptr::null()), + owner: None, + } + } + } - pub fn decoder(self) -> Decoder { - Decoder(self) - } + pub fn decoder(self) -> Decoder { + Decoder(self) + } - pub fn encoder(self) -> Encoder { - Encoder(self) - } + pub fn encoder(self) -> Encoder { + Encoder(self) + } - pub fn codec(&self) -> Option { - unsafe { - if (*self.as_ptr()).codec.is_null() { - None - } - else { - Some(Codec::wrap((*self.as_ptr()).codec as *mut _)) - } - } - } + pub fn codec(&self) -> Option { + unsafe { + if (*self.as_ptr()).codec.is_null() { + None + } else { + Some(Codec::wrap((*self.as_ptr()).codec as *mut _)) + } + } + } - pub fn medium(&self) -> media::Type { - unsafe { - media::Type::from((*self.as_ptr()).codec_type) - } - } + pub fn medium(&self) -> media::Type { + unsafe { media::Type::from((*self.as_ptr()).codec_type) } + } - pub fn set_flags(&mut self, value: Flags) { - unsafe { - (*self.as_mut_ptr()).flags = value.bits() as c_int; - } - } + pub fn set_flags(&mut self, value: Flags) { + unsafe { + (*self.as_mut_ptr()).flags = value.bits() as c_int; + } + } - pub fn id(&self) -> Id { - unsafe { - Id::from((*self.as_ptr()).codec_id) - } - } + pub fn id(&self) -> Id { + unsafe { Id::from((*self.as_ptr()).codec_id) } + } - pub fn compliance(&mut self, value: Compliance) { - unsafe { - (*self.as_mut_ptr()).strict_std_compliance = value.into(); - } - } + pub fn compliance(&mut self, value: Compliance) { + unsafe { + (*self.as_mut_ptr()).strict_std_compliance = value.into(); + } + } - pub fn debug(&mut self, value: Debug) { - unsafe { - (*self.as_mut_ptr()).debug = value.bits(); - } - } + pub fn debug(&mut self, value: Debug) { + unsafe { + (*self.as_mut_ptr()).debug = value.bits(); + } + } - pub fn set_threading(&mut self, config: threading::Config) { - unsafe { - (*self.as_mut_ptr()).thread_type = config.kind.into(); - (*self.as_mut_ptr()).thread_count = config.count as c_int; - (*self.as_mut_ptr()).thread_safe_callbacks = if config.safe { 1 } else { 0 }; - } - } + pub fn set_threading(&mut self, config: threading::Config) { + unsafe { + (*self.as_mut_ptr()).thread_type = config.kind.into(); + (*self.as_mut_ptr()).thread_count = config.count as c_int; + (*self.as_mut_ptr()).thread_safe_callbacks = if config.safe { 1 } else { 0 }; + } + } - pub fn threading(&self) -> threading::Config { - unsafe { - threading::Config { - kind: threading::Type::from((*self.as_ptr()).active_thread_type), - count: (*self.as_ptr()).thread_count as usize, - safe: (*self.as_ptr()).thread_safe_callbacks != 0, - } - } - } + pub fn threading(&self) -> threading::Config { + unsafe { + threading::Config { + kind: threading::Type::from((*self.as_ptr()).active_thread_type), + count: (*self.as_ptr()).thread_count as usize, + safe: (*self.as_ptr()).thread_safe_callbacks != 0, + } + } + } - pub fn set_parameters>(&mut self, parameters: P) -> Result<(), Error> { - let parameters = parameters.into(); + pub fn set_parameters>(&mut self, parameters: P) -> Result<(), Error> { + let parameters = parameters.into(); - unsafe { - match avcodec_parameters_to_context(self.as_mut_ptr(), parameters.as_ptr()) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(()), - } - } - } + unsafe { + match avcodec_parameters_to_context(self.as_mut_ptr(), parameters.as_ptr()) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(()), + } + } + } +} + +impl Default for Context { + fn default() -> Self { + Self::new() + } } impl Drop for Context { - fn drop(&mut self) { - unsafe { - if self.owner.is_none() { - avcodec_free_context(&mut self.as_mut_ptr()); - } - } - } + fn drop(&mut self) { + unsafe { + if self.owner.is_none() { + avcodec_free_context(&mut self.as_mut_ptr()); + } + } + } } impl Clone for Context { - fn clone(&self) -> Self { - let mut ctx = Context::new(); - ctx.clone_from(self); + fn clone(&self) -> Self { + let mut ctx = Context::new(); + ctx.clone_from(self); - ctx - } + ctx + } - fn clone_from(&mut self, source: &Self) { - unsafe { - avcodec_copy_context(self.as_mut_ptr(), source.as_ptr()); - } - } + fn clone_from(&mut self, source: &Self) { + unsafe { + avcodec_copy_context(self.as_mut_ptr(), source.as_ptr()); + } + } } diff --git a/src/codec/debug.rs b/src/codec/debug.rs index c5cf935..1b45c74 100644 --- a/src/codec/debug.rs +++ b/src/codec/debug.rs @@ -1,25 +1,25 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Debug: c_int { - const PICT_INFO = FF_DEBUG_PICT_INFO; - const RC = FF_DEBUG_RC; - const BITSTREAM = FF_DEBUG_BITSTREAM; - const MB_TYPE = FF_DEBUG_MB_TYPE; - const QP = FF_DEBUG_QP; - const MV = FF_DEBUG_MV; - const DCT_COEFF = FF_DEBUG_DCT_COEFF; - const SKIP = FF_DEBUG_SKIP; - const STARTCODE = FF_DEBUG_STARTCODE; - const PTS = FF_DEBUG_PTS; - const ER = FF_DEBUG_ER; - const MMCO = FF_DEBUG_MMCO; - const BUGS = FF_DEBUG_BUGS; - const VIS_QP = FF_DEBUG_VIS_QP; - const VIS_MB_TYPE = FF_DEBUG_VIS_MB_TYPE; - const BUFFERS = FF_DEBUG_BUFFERS; - const THREADS = FF_DEBUG_THREADS; - const NOMC = FF_DEBUG_NOMC; - } + pub struct Debug: c_int { + const PICT_INFO = FF_DEBUG_PICT_INFO; + const RC = FF_DEBUG_RC; + const BITSTREAM = FF_DEBUG_BITSTREAM; + const MB_TYPE = FF_DEBUG_MB_TYPE; + const QP = FF_DEBUG_QP; + const MV = FF_DEBUG_MV; + const DCT_COEFF = FF_DEBUG_DCT_COEFF; + const SKIP = FF_DEBUG_SKIP; + const STARTCODE = FF_DEBUG_STARTCODE; + const PTS = FF_DEBUG_PTS; + const ER = FF_DEBUG_ER; + const MMCO = FF_DEBUG_MMCO; + const BUGS = FF_DEBUG_BUGS; + const VIS_QP = FF_DEBUG_VIS_QP; + const VIS_MB_TYPE = FF_DEBUG_VIS_MB_TYPE; + const BUFFERS = FF_DEBUG_BUFFERS; + const THREADS = FF_DEBUG_THREADS; + const NOMC = FF_DEBUG_NOMC; + } } diff --git a/src/codec/decoder/audio.rs b/src/codec/decoder/audio.rs index e040d1c..70358bd 100644 --- a/src/codec/decoder/audio.rs +++ b/src/codec/decoder/audio.rs @@ -1,132 +1,123 @@ use std::ops::{Deref, DerefMut}; -use libc::c_int; use ffi::*; +use libc::c_int; use super::Opened; -use ::{packet, Error, AudioService, ChannelLayout}; -use ::frame; -use ::util::format; -use ::codec::Context; +use codec::Context; +use frame; +use util::format; +use {packet, AudioService, ChannelLayout, Error}; pub struct Audio(pub Opened); impl Audio { - pub fn decode(&mut self, packet: &P, out: &mut frame::Audio) -> Result { - unsafe { - let mut got: c_int = 0; + pub fn decode( + &mut self, + packet: &P, + out: &mut frame::Audio, + ) -> Result { + unsafe { + let mut got: c_int = 0; - match avcodec_decode_audio4(self.as_mut_ptr(), out.as_mut_ptr(), &mut got, packet.as_ptr()) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0) - } - } - } + match avcodec_decode_audio4( + self.as_mut_ptr(), + out.as_mut_ptr(), + &mut got, + packet.as_ptr(), + ) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(got != 0), + } + } + } - pub fn rate(&self) -> u32 { - unsafe { - (*self.as_ptr()).sample_rate as u32 - } - } + pub fn rate(&self) -> u32 { + unsafe { (*self.as_ptr()).sample_rate as u32 } + } - pub fn channels(&self) -> u16 { - unsafe { - (*self.as_ptr()).channels as u16 - } - } + pub fn channels(&self) -> u16 { + unsafe { (*self.as_ptr()).channels as u16 } + } - pub fn format(&self) -> format::Sample { - unsafe { - format::Sample::from((*self.as_ptr()).sample_fmt) - } - } + pub fn format(&self) -> format::Sample { + unsafe { format::Sample::from((*self.as_ptr()).sample_fmt) } + } - pub fn request_format(&mut self, value: format::Sample) { - unsafe { - (*self.as_mut_ptr()).request_sample_fmt = value.into(); - } - } + pub fn request_format(&mut self, value: format::Sample) { + unsafe { + (*self.as_mut_ptr()).request_sample_fmt = value.into(); + } + } - pub fn frames(&self) -> usize { - unsafe { - (*self.as_ptr()).frame_number as usize - } - } + pub fn frames(&self) -> usize { + unsafe { (*self.as_ptr()).frame_number as usize } + } - pub fn align(&self) -> usize { - unsafe { - (*self.as_ptr()).block_align as usize - } - } + pub fn align(&self) -> usize { + unsafe { (*self.as_ptr()).block_align as usize } + } - pub fn channel_layout(&self) -> ChannelLayout { - unsafe { - ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) - } - } + pub fn channel_layout(&self) -> ChannelLayout { + unsafe { ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) } + } - pub fn set_channel_layout(&mut self, value: ChannelLayout) { - unsafe { - (*self.as_mut_ptr()).channel_layout = value.bits(); - } - } + pub fn set_channel_layout(&mut self, value: ChannelLayout) { + unsafe { + (*self.as_mut_ptr()).channel_layout = value.bits(); + } + } - pub fn request_channel_layout(&mut self, value: ChannelLayout) { - unsafe { - (*self.as_mut_ptr()).request_channel_layout = value.bits(); - } - } + pub fn request_channel_layout(&mut self, value: ChannelLayout) { + unsafe { + (*self.as_mut_ptr()).request_channel_layout = value.bits(); + } + } - pub fn audio_service(&mut self) -> AudioService { - unsafe { - AudioService::from((*self.as_mut_ptr()).audio_service_type) - } - } + pub fn audio_service(&mut self) -> AudioService { + unsafe { AudioService::from((*self.as_mut_ptr()).audio_service_type) } + } - pub fn max_bit_rate(&self) -> usize { - unsafe { - (*self.as_ptr()).rc_max_rate as usize - } - } + pub fn max_bit_rate(&self) -> usize { + unsafe { (*self.as_ptr()).rc_max_rate as usize } + } - pub fn frame_size(&self) -> u32 { - unsafe { - (*self.as_ptr()).frame_size as u32 - } - } + pub fn frame_size(&self) -> u32 { + unsafe { (*self.as_ptr()).frame_size as u32 } + } - pub fn frame_start(&self) -> Option { - unsafe { - match (*self.as_ptr()).timecode_frame_start { - -1 => None, - n => Some(n as usize) - } - } - } + pub fn frame_start(&self) -> Option { + unsafe { + match (*self.as_ptr()).timecode_frame_start { + -1 => None, + n => Some(n as usize), + } + } + } } impl Deref for Audio { - type Target = Opened; + type Target = Opened; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Audio { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Audio { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Audio { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } diff --git a/src/codec/decoder/check.rs b/src/codec/decoder/check.rs index 3a89068..aae10ee 100644 --- a/src/codec/decoder/check.rs +++ b/src/codec/decoder/check.rs @@ -1,16 +1,16 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Check: c_int { - const CRC = AV_EF_CRCCHECK; - const BISTREAM = AV_EF_BITSTREAM; - const BUFFER = AV_EF_BUFFER; - const EXPLODE = AV_EF_EXPLODE; + pub struct Check: c_int { + const CRC = AV_EF_CRCCHECK; + const BISTREAM = AV_EF_BITSTREAM; + const BUFFER = AV_EF_BUFFER; + const EXPLODE = AV_EF_EXPLODE; - const IGNORE_ERROR = AV_EF_IGNORE_ERR; - const CAREFUL = AV_EF_CAREFUL; - const COMPLIANT = AV_EF_COMPLIANT; - const AGGRESSIVE = AV_EF_AGGRESSIVE; - } + const IGNORE_ERROR = AV_EF_IGNORE_ERR; + const CAREFUL = AV_EF_CAREFUL; + const COMPLIANT = AV_EF_COMPLIANT; + const AGGRESSIVE = AV_EF_AGGRESSIVE; + } } diff --git a/src/codec/decoder/conceal.rs b/src/codec/decoder/conceal.rs index d867faf..7d59918 100644 --- a/src/codec/decoder/conceal.rs +++ b/src/codec/decoder/conceal.rs @@ -1,10 +1,10 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Conceal: c_int { - const GUESS_MVS = FF_EC_GUESS_MVS; - const DEBLOCK = FF_EC_DEBLOCK; - const FAVOR_INTER = FF_EC_FAVOR_INTER; - } + pub struct Conceal: c_int { + const GUESS_MVS = FF_EC_GUESS_MVS; + const DEBLOCK = FF_EC_DEBLOCK; + const FAVOR_INTER = FF_EC_FAVOR_INTER; + } } diff --git a/src/codec/decoder/decoder.rs b/src/codec/decoder/decoder.rs index 417c96d..6990ab7 100644 --- a/src/codec/decoder/decoder.rs +++ b/src/codec/decoder/decoder.rs @@ -1,142 +1,139 @@ -use std::ptr; use std::ops::{Deref, DerefMut}; +use std::ptr; +use super::{Audio, Check, Conceal, Opened, Subtitle, Video}; +use codec::{traits, Context}; use ffi::*; -use codec::{Context, traits}; -use super::{Opened, Video, Audio, Subtitle, Conceal, Check}; -use ::{Error, Discard, Rational, Dictionary}; +use {Dictionary, Discard, Error, Rational}; pub struct Decoder(pub Context); impl Decoder { - pub fn open(mut self) -> Result { - unsafe { - match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) { - 0 => Ok(Opened(self)), - e => Err(Error::from(e)) - } - } - } + pub fn open(mut self) -> Result { + unsafe { + match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) { + 0 => Ok(Opened(self)), + e => Err(Error::from(e)), + } + } + } - pub fn open_as(mut self, codec: D) -> Result { - unsafe { - if let Some(codec) = codec.decoder() { - match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) { - 0 => Ok(Opened(self)), - e => Err(Error::from(e)) - } - } - else { - Err(Error::DecoderNotFound) - } - } - } + pub fn open_as(mut self, codec: D) -> Result { + unsafe { + if let Some(codec) = codec.decoder() { + match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) { + 0 => Ok(Opened(self)), + e => Err(Error::from(e)), + } + } else { + Err(Error::DecoderNotFound) + } + } + } - pub fn open_as_with(mut self, codec: D, options: Dictionary) -> Result { - unsafe { - if let Some(codec) = codec.decoder() { - let mut opts = options.disown(); - let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts); + pub fn open_as_with( + mut self, + codec: D, + options: Dictionary, + ) -> Result { + unsafe { + if let Some(codec) = codec.decoder() { + let mut opts = options.disown(); + let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => Ok(Opened(self)), - e => Err(Error::from(e)) - } - } - else { - Err(Error::DecoderNotFound) - } - } - } + match res { + 0 => Ok(Opened(self)), + e => Err(Error::from(e)), + } + } else { + Err(Error::DecoderNotFound) + } + } + } - pub fn video(self) -> Result { - if let Some(codec) = super::find(self.id()) { - self.open_as(codec).and_then(|o| o.video()) - } - else { - Err(Error::DecoderNotFound) - } - } + pub fn video(self) -> Result { + if let Some(codec) = super::find(self.id()) { + self.open_as(codec).and_then(|o| o.video()) + } else { + Err(Error::DecoderNotFound) + } + } - pub fn audio(self) -> Result { - if let Some(codec) = super::find(self.id()) { - self.open_as(codec).and_then(|o| o.audio()) - } - else { - Err(Error::DecoderNotFound) - } - } + pub fn audio(self) -> Result { + if let Some(codec) = super::find(self.id()) { + self.open_as(codec).and_then(|o| o.audio()) + } else { + Err(Error::DecoderNotFound) + } + } - pub fn subtitle(self) -> Result { - if let Some(codec) = super::find(self.id()) { - self.open_as(codec).and_then(|o| o.subtitle()) - } - else { - Err(Error::DecoderNotFound) - } - } + pub fn subtitle(self) -> Result { + if let Some(codec) = super::find(self.id()) { + self.open_as(codec).and_then(|o| o.subtitle()) + } else { + Err(Error::DecoderNotFound) + } + } - pub fn conceal(&mut self, value: Conceal) { - unsafe { - (*self.as_mut_ptr()).error_concealment = value.bits(); - } - } + pub fn conceal(&mut self, value: Conceal) { + unsafe { + (*self.as_mut_ptr()).error_concealment = value.bits(); + } + } - pub fn check(&mut self, value: Check) { - unsafe { - (*self.as_mut_ptr()).err_recognition = value.bits(); - } - } + pub fn check(&mut self, value: Check) { + unsafe { + (*self.as_mut_ptr()).err_recognition = value.bits(); + } + } - pub fn skip_loop_filter(&mut self, value: Discard) { - unsafe { - (*self.as_mut_ptr()).skip_loop_filter = value.into(); - } - } + pub fn skip_loop_filter(&mut self, value: Discard) { + unsafe { + (*self.as_mut_ptr()).skip_loop_filter = value.into(); + } + } - pub fn skip_idct(&mut self, value: Discard) { - unsafe { - (*self.as_mut_ptr()).skip_idct = value.into(); - } - } + pub fn skip_idct(&mut self, value: Discard) { + unsafe { + (*self.as_mut_ptr()).skip_idct = value.into(); + } + } - pub fn skip_frame(&mut self, value: Discard) { - unsafe { - (*self.as_mut_ptr()).skip_frame = value.into(); - } - } + pub fn skip_frame(&mut self, value: Discard) { + unsafe { + (*self.as_mut_ptr()).skip_frame = value.into(); + } + } - pub fn time_base(&self) -> Rational { - unsafe { - Rational::from((*self.as_ptr()).time_base) - } - } + pub fn time_base(&self) -> Rational { + unsafe { Rational::from((*self.as_ptr()).time_base) } + } } impl Deref for Decoder { - type Target = Context; + type Target = Context; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Decoder { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Decoder { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Decoder { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } diff --git a/src/codec/decoder/mod.rs b/src/codec/decoder/mod.rs index c3decba..c942ba9 100644 --- a/src/codec/decoder/mod.rs +++ b/src/codec/decoder/mod.rs @@ -23,38 +23,36 @@ pub use self::opened::Opened; use std::ffi::CString; -use ffi::*; use codec::Context; -use ::Codec; use codec::Id; +use ffi::*; +use Codec; pub fn new() -> Decoder { - Context::new().decoder() + Context::new().decoder() } pub fn find(id: Id) -> Option { - unsafe { - let ptr = avcodec_find_decoder(id.into()); + unsafe { + let ptr = avcodec_find_decoder(id.into()); - if ptr.is_null() { - None - } - else { - Some(Codec::wrap(ptr)) - } - } + if ptr.is_null() { + None + } else { + Some(Codec::wrap(ptr)) + } + } } pub fn find_by_name(name: &str) -> Option { - unsafe { - let name = CString::new(name).unwrap(); - let ptr = avcodec_find_decoder_by_name(name.as_ptr()); + unsafe { + let name = CString::new(name).unwrap(); + let ptr = avcodec_find_decoder_by_name(name.as_ptr()); - if ptr.is_null() { - None - } - else { - Some(Codec::wrap(ptr)) - } - } + if ptr.is_null() { + None + } else { + Some(Codec::wrap(ptr)) + } + } } diff --git a/src/codec/decoder/opened.rs b/src/codec/decoder/opened.rs index e58f519..d1cf5d6 100644 --- a/src/codec/decoder/opened.rs +++ b/src/codec/decoder/opened.rs @@ -1,109 +1,99 @@ use std::ops::{Deref, DerefMut}; +use super::{Audio, Decoder, Subtitle, Video}; +use codec::{Context, Profile}; use ffi::*; -use super::{Video, Audio, Subtitle, Decoder}; -use ::codec::{Profile, Context}; -use ::{Error, Rational}; -use ::media; +use media; +use {Error, Rational}; pub struct Opened(pub Decoder); impl Opened { - pub fn video(self) -> Result { - if self.medium() == media::Type::Video { - Ok(Video(self)) - } - else { - Err(Error::InvalidData) - } - } + pub fn video(self) -> Result { + if self.medium() == media::Type::Video { + Ok(Video(self)) + } else { + Err(Error::InvalidData) + } + } - pub fn audio(self) -> Result { - if self.medium() == media::Type::Audio { - Ok(Audio(self)) - } - else { - Err(Error::InvalidData) - } - } + pub fn audio(self) -> Result { + if self.medium() == media::Type::Audio { + Ok(Audio(self)) + } else { + Err(Error::InvalidData) + } + } - pub fn subtitle(self) -> Result { - if self.medium() == media::Type::Subtitle { - Ok(Subtitle(self)) - } - else { - Err(Error::InvalidData) - } - } + pub fn subtitle(self) -> Result { + if self.medium() == media::Type::Subtitle { + Ok(Subtitle(self)) + } else { + Err(Error::InvalidData) + } + } - pub fn bit_rate(&self) -> usize { - unsafe { - (*self.as_ptr()).bit_rate as usize - } - } + pub fn bit_rate(&self) -> usize { + unsafe { (*self.as_ptr()).bit_rate as usize } + } - pub fn delay(&self) -> usize { - unsafe { - (*self.as_ptr()).delay as usize - } - } + pub fn delay(&self) -> usize { + unsafe { (*self.as_ptr()).delay as usize } + } - pub fn profile(&self) -> Profile { - unsafe { - Profile::from((self.id(), (*self.as_ptr()).profile)) - } - } + pub fn profile(&self) -> Profile { + unsafe { Profile::from((self.id(), (*self.as_ptr()).profile)) } + } - pub fn frame_rate(&self) -> Option { - unsafe { - let value = (*self.as_ptr()).framerate; + pub fn frame_rate(&self) -> Option { + unsafe { + let value = (*self.as_ptr()).framerate; - if value == (AVRational { num: 0, den: 1 }) { - None - } - else { - Some(Rational::from(value)) - } - } - } + if value == (AVRational { num: 0, den: 1 }) { + None + } else { + Some(Rational::from(value)) + } + } + } - pub fn flush(&mut self) { - unsafe { - avcodec_flush_buffers(self.as_mut_ptr()); - } - } + pub fn flush(&mut self) { + unsafe { + avcodec_flush_buffers(self.as_mut_ptr()); + } + } } impl Drop for Opened { - fn drop(&mut self) { - unsafe { - avcodec_close(self.as_mut_ptr()); - } - } + fn drop(&mut self) { + unsafe { + avcodec_close(self.as_mut_ptr()); + } + } } impl Deref for Opened { - type Target = Decoder; + type Target = Decoder; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Opened { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Opened { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Opened { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } diff --git a/src/codec/decoder/slice.rs b/src/codec/decoder/slice.rs index 687cbcf..7e0c0dd 100644 --- a/src/codec/decoder/slice.rs +++ b/src/codec/decoder/slice.rs @@ -1,10 +1,10 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Flags: c_int { - const CODED_ORDER = SLICE_FLAG_CODED_ORDER; - const ALLOW_FIELD = SLICE_FLAG_ALLOW_FIELD; - const ALLOW_PLANE = SLICE_FLAG_ALLOW_PLANE; - } + pub struct Flags: c_int { + const CODED_ORDER = SLICE_FLAG_CODED_ORDER; + const ALLOW_FIELD = SLICE_FLAG_ALLOW_FIELD; + const ALLOW_PLANE = SLICE_FLAG_ALLOW_PLANE; + } } diff --git a/src/codec/decoder/subtitle.rs b/src/codec/decoder/subtitle.rs index ad82297..1ccae82 100644 --- a/src/codec/decoder/subtitle.rs +++ b/src/codec/decoder/subtitle.rs @@ -1,49 +1,58 @@ use std::ops::{Deref, DerefMut}; -use libc::c_int; use ffi::*; +use libc::c_int; use super::Opened; -use ::{packet, Error}; -use ::codec::Context; +use codec::Context; +use {packet, Error}; pub struct Subtitle(pub Opened); impl Subtitle { - pub fn decode(&mut self, packet: &P, out: &mut ::Subtitle) -> Result { - unsafe { - let mut got: c_int = 0; + pub fn decode( + &mut self, + packet: &P, + out: &mut ::Subtitle, + ) -> Result { + unsafe { + let mut got: c_int = 0; - match avcodec_decode_subtitle2(self.as_mut_ptr(), out.as_mut_ptr(), &mut got, packet.as_ptr() as *mut _) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0) - } - } - } + match avcodec_decode_subtitle2( + self.as_mut_ptr(), + out.as_mut_ptr(), + &mut got, + packet.as_ptr() as *mut _, + ) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(got != 0), + } + } + } } impl Deref for Subtitle { - type Target = Opened; + type Target = Opened; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Subtitle { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Subtitle { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Subtitle { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } diff --git a/src/codec/decoder/video.rs b/src/codec/decoder/video.rs index 8c624f5..5bf3308 100644 --- a/src/codec/decoder/video.rs +++ b/src/codec/decoder/video.rs @@ -1,164 +1,147 @@ use std::ops::{Deref, DerefMut}; -use libc::c_int; use ffi::*; +use libc::c_int; -use super::{Opened, slice}; -use ::{packet, Error, Rational, FieldOrder}; -use ::frame; -use ::util::format; -use ::util::chroma; -use ::color; -use ::codec::Context; +use super::{slice, Opened}; +use codec::Context; +use color; +use frame; +use util::chroma; +use util::format; +use {packet, Error, FieldOrder, Rational}; pub struct Video(pub Opened); impl Video { - pub fn decode(&mut self, packet: &P, out: &mut frame::Video) -> Result { - unsafe { - let mut got: c_int = 0; + pub fn decode( + &mut self, + packet: &P, + out: &mut frame::Video, + ) -> Result { + unsafe { + let mut got: c_int = 0; - match avcodec_decode_video2(self.as_mut_ptr(), out.as_mut_ptr(), &mut got, packet.as_ptr()) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0) - } - } - } + match avcodec_decode_video2( + self.as_mut_ptr(), + out.as_mut_ptr(), + &mut got, + packet.as_ptr(), + ) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(got != 0), + } + } + } - pub fn width(&self) -> u32 { - unsafe { - (*self.as_ptr()).width as u32 - } - } + pub fn width(&self) -> u32 { + unsafe { (*self.as_ptr()).width as u32 } + } - pub fn height(&self) -> u32 { - unsafe { - (*self.as_ptr()).height as u32 - } - } + pub fn height(&self) -> u32 { + unsafe { (*self.as_ptr()).height as u32 } + } - pub fn format(&self) -> format::Pixel { - unsafe { - format::Pixel::from((*self.as_ptr()).pix_fmt) - } - } + pub fn format(&self) -> format::Pixel { + unsafe { format::Pixel::from((*self.as_ptr()).pix_fmt) } + } - pub fn has_b_frames(&self) -> bool { - unsafe { - (*self.as_ptr()).has_b_frames != 0 - } - } + pub fn has_b_frames(&self) -> bool { + unsafe { (*self.as_ptr()).has_b_frames != 0 } + } - pub fn aspect_ratio(&self) -> Rational { - unsafe { - Rational::from((*self.as_ptr()).sample_aspect_ratio) - } - } + pub fn aspect_ratio(&self) -> Rational { + unsafe { Rational::from((*self.as_ptr()).sample_aspect_ratio) } + } - pub fn color_space(&self) -> color::Space { - unsafe { - color::Space::from((*self.as_ptr()).colorspace) - } - } + pub fn color_space(&self) -> color::Space { + unsafe { color::Space::from((*self.as_ptr()).colorspace) } + } - pub fn color_range(&self) -> color::Range { - unsafe { - color::Range::from((*self.as_ptr()).color_range) - } - } + pub fn color_range(&self) -> color::Range { + unsafe { color::Range::from((*self.as_ptr()).color_range) } + } - pub fn color_primaries(&self) -> color::Primaries { - unsafe { - color::Primaries::from((*self.as_ptr()).color_primaries) - } - } + pub fn color_primaries(&self) -> color::Primaries { + unsafe { color::Primaries::from((*self.as_ptr()).color_primaries) } + } - pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic { - unsafe { - color::TransferCharacteristic::from((*self.as_ptr()).color_trc) - } - } + pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic { + unsafe { color::TransferCharacteristic::from((*self.as_ptr()).color_trc) } + } - pub fn chroma_location(&self) -> chroma::Location { - unsafe { - chroma::Location::from((*self.as_ptr()).chroma_sample_location) - } - } + pub fn chroma_location(&self) -> chroma::Location { + unsafe { chroma::Location::from((*self.as_ptr()).chroma_sample_location) } + } - pub fn set_slice_count(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).slice_count = value as c_int; - } - } + pub fn set_slice_count(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).slice_count = value as c_int; + } + } - pub fn set_slice_flags(&mut self, value: slice::Flags) { - unsafe { - (*self.as_mut_ptr()).slice_flags = value.bits(); - } - } + pub fn set_slice_flags(&mut self, value: slice::Flags) { + unsafe { + (*self.as_mut_ptr()).slice_flags = value.bits(); + } + } - pub fn skip_top(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).skip_top = value as c_int; - } - } + pub fn skip_top(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).skip_top = value as c_int; + } + } - pub fn skip_bottom(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).skip_bottom = value as c_int; - } - } + pub fn skip_bottom(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).skip_bottom = value as c_int; + } + } - pub fn references(&self) -> usize { - unsafe { - (*self.as_ptr()).refs as usize - } - } + pub fn references(&self) -> usize { + unsafe { (*self.as_ptr()).refs as usize } + } - pub fn set_field_order(&mut self, value: FieldOrder) { - unsafe { - (*self.as_mut_ptr()).field_order = value.into(); - } - } + pub fn set_field_order(&mut self, value: FieldOrder) { + unsafe { + (*self.as_mut_ptr()).field_order = value.into(); + } + } - // intra_matrix - // inter_matrix + // intra_matrix + // inter_matrix - pub fn intra_dc_precision(&self) -> u8 { - unsafe { - (*self.as_ptr()).intra_dc_precision as u8 - } - } + pub fn intra_dc_precision(&self) -> u8 { + unsafe { (*self.as_ptr()).intra_dc_precision as u8 } + } - pub fn max_bit_rate(&self) -> usize { - unsafe { - (*self.as_ptr()).rc_max_rate as usize - } - } + pub fn max_bit_rate(&self) -> usize { + unsafe { (*self.as_ptr()).rc_max_rate as usize } + } } impl Deref for Video { - type Target = Opened; + type Target = Opened; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Video { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Video { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Video { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } diff --git a/src/codec/discard.rs b/src/codec/discard.rs index 8edae76..4fb97fa 100644 --- a/src/codec/discard.rs +++ b/src/codec/discard.rs @@ -1,41 +1,41 @@ -use ffi::*; use ffi::AVDiscard::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Discard { - None, - Default, - NonReference, - Bidirectional, - NonIntra, - NonKey, - All, + None, + Default, + NonReference, + Bidirectional, + NonIntra, + NonKey, + All, } impl From for Discard { - fn from(value: AVDiscard) -> Self { - match value { - AVDISCARD_NONE => Discard::None, - AVDISCARD_DEFAULT => Discard::Default, - AVDISCARD_NONREF => Discard::NonReference, - AVDISCARD_BIDIR => Discard::Bidirectional, - AVDISCARD_NONINTRA => Discard::NonIntra, - AVDISCARD_NONKEY => Discard::NonKey, - AVDISCARD_ALL => Discard::All - } - } + fn from(value: AVDiscard) -> Self { + match value { + AVDISCARD_NONE => Discard::None, + AVDISCARD_DEFAULT => Discard::Default, + AVDISCARD_NONREF => Discard::NonReference, + AVDISCARD_BIDIR => Discard::Bidirectional, + AVDISCARD_NONINTRA => Discard::NonIntra, + AVDISCARD_NONKEY => Discard::NonKey, + AVDISCARD_ALL => Discard::All, + } + } } impl Into for Discard { - fn into(self) -> AVDiscard { - match self { - Discard::None => AVDISCARD_NONE, - Discard::Default => AVDISCARD_DEFAULT, - Discard::NonReference => AVDISCARD_NONREF, - Discard::Bidirectional => AVDISCARD_BIDIR, - Discard::NonIntra => AVDISCARD_NONINTRA, - Discard::NonKey => AVDISCARD_NONKEY, - Discard::All => AVDISCARD_ALL - } - } + fn into(self) -> AVDiscard { + match self { + Discard::None => AVDISCARD_NONE, + Discard::Default => AVDISCARD_DEFAULT, + Discard::NonReference => AVDISCARD_NONREF, + Discard::Bidirectional => AVDISCARD_BIDIR, + Discard::NonIntra => AVDISCARD_NONINTRA, + Discard::NonKey => AVDISCARD_NONKEY, + Discard::All => AVDISCARD_ALL, + } + } } diff --git a/src/codec/encoder/audio.rs b/src/codec/encoder/audio.rs index 9be35db..8e07a59 100644 --- a/src/codec/encoder/audio.rs +++ b/src/codec/encoder/audio.rs @@ -1,200 +1,206 @@ use std::ops::{Deref, DerefMut}; use std::ptr; -use libc::c_int; use ffi::*; +use libc::c_int; use super::Encoder as Super; -use ::{packet, Error, Dictionary, ChannelLayout, frame}; -use ::util::format; use codec::{traits, Context}; +use util::format; +use {frame, packet, ChannelLayout, Dictionary, Error}; pub struct Audio(pub Super); impl Audio { - pub fn open(mut self) -> Result { - unsafe { - match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - } + pub fn open(mut self) -> Result { + unsafe { + match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } + } - pub fn open_as(mut self, codec: E) -> Result { - unsafe { - if let Some(codec) = codec.encoder() { - match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - else { - Err(Error::EncoderNotFound) - } - } - } + pub fn open_as(mut self, codec: E) -> Result { + unsafe { + if let Some(codec) = codec.encoder() { + match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } else { + Err(Error::EncoderNotFound) + } + } + } - pub fn open_with(mut self, options: Dictionary) -> Result { - unsafe { - let mut opts = options.disown(); - let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts); + pub fn open_with(mut self, options: Dictionary) -> Result { + unsafe { + let mut opts = options.disown(); + let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - } + match res { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } + } - pub fn open_as_with(mut self, codec: E, options: Dictionary) -> Result { - unsafe { - if let Some(codec) = codec.encoder() { - let mut opts = options.disown(); - let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts); + pub fn open_as_with( + mut self, + codec: E, + options: Dictionary, + ) -> Result { + unsafe { + if let Some(codec) = codec.encoder() { + let mut opts = options.disown(); + let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - else { - Err(Error::EncoderNotFound) - } - } - } + match res { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } else { + Err(Error::EncoderNotFound) + } + } + } - pub fn set_rate(&mut self, rate: i32) { - unsafe { - (*self.as_mut_ptr()).sample_rate = rate; - } - } + pub fn set_rate(&mut self, rate: i32) { + unsafe { + (*self.as_mut_ptr()).sample_rate = rate; + } + } - pub fn rate(&self) -> u32 { - unsafe { - (*self.as_ptr()).sample_rate as u32 - } - } + pub fn rate(&self) -> u32 { + unsafe { (*self.as_ptr()).sample_rate as u32 } + } - pub fn set_format(&mut self, value: format::Sample) { - unsafe { - (*self.as_mut_ptr()).sample_fmt = value.into(); - } - } + pub fn set_format(&mut self, value: format::Sample) { + unsafe { + (*self.as_mut_ptr()).sample_fmt = value.into(); + } + } - pub fn format(&self) -> format::Sample { - unsafe { - format::Sample::from((*self.as_ptr()).sample_fmt) - } - } + pub fn format(&self) -> format::Sample { + unsafe { format::Sample::from((*self.as_ptr()).sample_fmt) } + } - pub fn set_channel_layout(&mut self, value: ChannelLayout) { - unsafe { - (*self.as_mut_ptr()).channel_layout = value.bits(); - } - } + pub fn set_channel_layout(&mut self, value: ChannelLayout) { + unsafe { + (*self.as_mut_ptr()).channel_layout = value.bits(); + } + } - pub fn channel_layout(&self) -> ChannelLayout { - unsafe { - ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) - } - } + pub fn channel_layout(&self) -> ChannelLayout { + unsafe { ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) } + } - pub fn set_channels(&mut self, value: i32) { - unsafe { - (*self.as_mut_ptr()).channels = value; - } - } + pub fn set_channels(&mut self, value: i32) { + unsafe { + (*self.as_mut_ptr()).channels = value; + } + } - pub fn channels(&self) -> u16 { - unsafe { - (*self.as_ptr()).channels as u16 - } - } + pub fn channels(&self) -> u16 { + unsafe { (*self.as_ptr()).channels as u16 } + } } impl Deref for Audio { - type Target = Super; + type Target = Super; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Audio { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Audio { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Audio { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } pub struct Encoder(pub Audio); impl Encoder { - pub fn encode(&mut self, frame: &frame::Audio, out: &mut P) -> Result { - unsafe { - if self.format() != frame.format() { - return Err(Error::InvalidData); - } + pub fn encode( + &mut self, + frame: &frame::Audio, + out: &mut P, + ) -> Result { + unsafe { + if self.format() != frame.format() { + return Err(Error::InvalidData); + } - let mut got: c_int = 0; + let mut got: c_int = 0; - match avcodec_encode_audio2(self.0.as_mut_ptr(), out.as_mut_ptr(), frame.as_ptr(), &mut got) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0) - } - } - } + match avcodec_encode_audio2( + self.0.as_mut_ptr(), + out.as_mut_ptr(), + frame.as_ptr(), + &mut got, + ) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(got != 0), + } + } + } - pub fn flush(&mut self, out: &mut P) -> Result { - unsafe { - let mut got: c_int = 0; + pub fn flush(&mut self, out: &mut P) -> Result { + unsafe { + let mut got: c_int = 0; - match avcodec_encode_audio2(self.0.as_mut_ptr(), out.as_mut_ptr(), ptr::null(), &mut got) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0) - } - } - } + match avcodec_encode_audio2( + self.0.as_mut_ptr(), + out.as_mut_ptr(), + ptr::null(), + &mut got, + ) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(got != 0), + } + } + } - pub fn frame_size(&self) -> u32 { - unsafe { - (*self.as_ptr()).frame_size as u32 - } - } + pub fn frame_size(&self) -> u32 { + unsafe { (*self.as_ptr()).frame_size as u32 } + } } impl Deref for Encoder { - type Target = Audio; + type Target = Audio; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl AsRef for Encoder { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Encoder { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } diff --git a/src/codec/encoder/comparison.rs b/src/codec/encoder/comparison.rs index 9ce46b2..503fd06 100644 --- a/src/codec/encoder/comparison.rs +++ b/src/codec/encoder/comparison.rs @@ -1,70 +1,70 @@ -use libc::c_int; use ffi::*; +use libc::c_int; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Comparison { - SAD, - SSE, - SATD, - DCT, - PSNR, - BIT, - RD, - ZERO, - VSAD, - VSSE, - NSSE, - W53, - W97, - DCTMAX, - DCT264, - CHROMA, + SAD, + SSE, + SATD, + DCT, + PSNR, + BIT, + RD, + ZERO, + VSAD, + VSSE, + NSSE, + W53, + W97, + DCTMAX, + DCT264, + CHROMA, } impl From for Comparison { - fn from(value: c_int) -> Comparison { - match value { - FF_CMP_SAD => Comparison::SAD, - FF_CMP_SSE => Comparison::SSE, - FF_CMP_SATD => Comparison::SATD, - FF_CMP_DCT => Comparison::DCT, - FF_CMP_PSNR => Comparison::PSNR, - FF_CMP_BIT => Comparison::BIT, - FF_CMP_RD => Comparison::RD, - FF_CMP_ZERO => Comparison::ZERO, - FF_CMP_VSAD => Comparison::VSAD, - FF_CMP_VSSE => Comparison::VSSE, - FF_CMP_NSSE => Comparison::NSSE, - FF_CMP_W53 => Comparison::W53, - FF_CMP_W97 => Comparison::W97, - FF_CMP_DCTMAX => Comparison::DCTMAX, - FF_CMP_DCT264 => Comparison::DCT264, - FF_CMP_CHROMA => Comparison::CHROMA, + fn from(value: c_int) -> Comparison { + match value { + FF_CMP_SAD => Comparison::SAD, + FF_CMP_SSE => Comparison::SSE, + FF_CMP_SATD => Comparison::SATD, + FF_CMP_DCT => Comparison::DCT, + FF_CMP_PSNR => Comparison::PSNR, + FF_CMP_BIT => Comparison::BIT, + FF_CMP_RD => Comparison::RD, + FF_CMP_ZERO => Comparison::ZERO, + FF_CMP_VSAD => Comparison::VSAD, + FF_CMP_VSSE => Comparison::VSSE, + FF_CMP_NSSE => Comparison::NSSE, + FF_CMP_W53 => Comparison::W53, + FF_CMP_W97 => Comparison::W97, + FF_CMP_DCTMAX => Comparison::DCTMAX, + FF_CMP_DCT264 => Comparison::DCT264, + FF_CMP_CHROMA => Comparison::CHROMA, - _ => Comparison::ZERO, - } - } + _ => Comparison::ZERO, + } + } } impl Into for Comparison { - fn into(self) -> c_int { - match self { - Comparison::SAD => FF_CMP_SAD, - Comparison::SSE => FF_CMP_SSE, - Comparison::SATD => FF_CMP_SATD, - Comparison::DCT => FF_CMP_DCT, - Comparison::PSNR => FF_CMP_PSNR, - Comparison::BIT => FF_CMP_BIT, - Comparison::RD => FF_CMP_RD, - Comparison::ZERO => FF_CMP_ZERO, - Comparison::VSAD => FF_CMP_VSAD, - Comparison::VSSE => FF_CMP_VSSE, - Comparison::NSSE => FF_CMP_NSSE, - Comparison::W53 => FF_CMP_W53, - Comparison::W97 => FF_CMP_W97, - Comparison::DCTMAX => FF_CMP_DCTMAX, - Comparison::DCT264 => FF_CMP_DCT264, - Comparison::CHROMA => FF_CMP_CHROMA, - } - } + fn into(self) -> c_int { + match self { + Comparison::SAD => FF_CMP_SAD, + Comparison::SSE => FF_CMP_SSE, + Comparison::SATD => FF_CMP_SATD, + Comparison::DCT => FF_CMP_DCT, + Comparison::PSNR => FF_CMP_PSNR, + Comparison::BIT => FF_CMP_BIT, + Comparison::RD => FF_CMP_RD, + Comparison::ZERO => FF_CMP_ZERO, + Comparison::VSAD => FF_CMP_VSAD, + Comparison::VSSE => FF_CMP_VSSE, + Comparison::NSSE => FF_CMP_NSSE, + Comparison::W53 => FF_CMP_W53, + Comparison::W97 => FF_CMP_W97, + Comparison::DCTMAX => FF_CMP_DCTMAX, + Comparison::DCT264 => FF_CMP_DCT264, + Comparison::CHROMA => FF_CMP_CHROMA, + } + } } diff --git a/src/codec/encoder/decision.rs b/src/codec/encoder/decision.rs index d4384cb..cb8c903 100644 --- a/src/codec/encoder/decision.rs +++ b/src/codec/encoder/decision.rs @@ -1,31 +1,31 @@ -use libc::c_int; use ffi::*; +use libc::c_int; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Decision { - Simple, - Bits, - RateDistortion, + Simple, + Bits, + RateDistortion, } impl From for Decision { - fn from(value: c_int) -> Decision { - match value { - FF_MB_DECISION_SIMPLE => Decision::Simple, - FF_MB_DECISION_BITS => Decision::Bits, - FF_MB_DECISION_RD => Decision::RateDistortion, + fn from(value: c_int) -> Decision { + match value { + FF_MB_DECISION_SIMPLE => Decision::Simple, + FF_MB_DECISION_BITS => Decision::Bits, + FF_MB_DECISION_RD => Decision::RateDistortion, - _ => Decision::Simple, - } - } + _ => Decision::Simple, + } + } } impl Into for Decision { - fn into(self) -> c_int { - match self { - Decision::Simple => FF_MB_DECISION_SIMPLE, - Decision::Bits => FF_MB_DECISION_BITS, - Decision::RateDistortion => FF_MB_DECISION_RD, - } - } + fn into(self) -> c_int { + match self { + Decision::Simple => FF_MB_DECISION_SIMPLE, + Decision::Bits => FF_MB_DECISION_BITS, + Decision::RateDistortion => FF_MB_DECISION_RD, + } + } } diff --git a/src/codec/encoder/encoder.rs b/src/codec/encoder/encoder.rs index b4c2a11..edcd527 100644 --- a/src/codec/encoder/encoder.rs +++ b/src/codec/encoder/encoder.rs @@ -1,149 +1,135 @@ use std::ops::{Deref, DerefMut}; -use libc::{c_int, int64_t}; +use super::{audio, subtitle, video}; use codec::Context; -use ::{Error, Rational, media}; -use super::{video, audio, subtitle}; +use libc::{c_int, int64_t}; +use {media, Error, Rational}; pub struct Encoder(pub Context); impl Encoder { - pub fn video(mut self) -> Result { - match self.medium() { - media::Type::Unknown => { - unsafe { - (*self.as_mut_ptr()).codec_type = media::Type::Video.into(); - } + pub fn video(mut self) -> Result { + match self.medium() { + media::Type::Unknown => { + unsafe { + (*self.as_mut_ptr()).codec_type = media::Type::Video.into(); + } - Ok(video::Video(self)) - } + Ok(video::Video(self)) + } - media::Type::Video => { - Ok(video::Video(self)) - } + media::Type::Video => Ok(video::Video(self)), - _ => { - Err(Error::InvalidData) - } - } - } + _ => Err(Error::InvalidData), + } + } - pub fn audio(mut self) -> Result { - match self.medium() { - media::Type::Unknown => { - unsafe { - (*self.as_mut_ptr()).codec_type = media::Type::Audio.into(); - } + pub fn audio(mut self) -> Result { + match self.medium() { + media::Type::Unknown => { + unsafe { + (*self.as_mut_ptr()).codec_type = media::Type::Audio.into(); + } - Ok(audio::Audio(self)) - } + Ok(audio::Audio(self)) + } - media::Type::Audio => { - Ok(audio::Audio(self)) - } + media::Type::Audio => Ok(audio::Audio(self)), - _ => { - Err(Error::InvalidData) - } - } - } + _ => Err(Error::InvalidData), + } + } - pub fn subtitle(mut self) -> Result { - match self.medium() { - media::Type::Unknown => { - unsafe { - (*self.as_mut_ptr()).codec_type = media::Type::Subtitle.into(); - } + pub fn subtitle(mut self) -> Result { + match self.medium() { + media::Type::Unknown => { + unsafe { + (*self.as_mut_ptr()).codec_type = media::Type::Subtitle.into(); + } - Ok(subtitle::Subtitle(self)) - } + Ok(subtitle::Subtitle(self)) + } - media::Type::Subtitle => { - Ok(subtitle::Subtitle(self)) - } + media::Type::Subtitle => Ok(subtitle::Subtitle(self)), - _ => { - Err(Error::InvalidData) - } - } - } + _ => Err(Error::InvalidData), + } + } - pub fn set_bit_rate(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).bit_rate = value as int64_t; - } - } + pub fn set_bit_rate(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).bit_rate = value as int64_t; + } + } - pub fn set_max_bit_rate(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).rc_max_rate = value as int64_t; - } - } + pub fn set_max_bit_rate(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).rc_max_rate = value as int64_t; + } + } - pub fn set_tolerance(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).bit_rate_tolerance = value as c_int; - } - } + pub fn set_tolerance(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).bit_rate_tolerance = value as c_int; + } + } - pub fn set_quality(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).global_quality = value as c_int; - } - } + pub fn set_quality(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).global_quality = value as c_int; + } + } - pub fn set_compression(&mut self, value: Option) { - unsafe { - if let Some(value) = value { - (*self.as_mut_ptr()).compression_level = value as c_int; - } - else { - (*self.as_mut_ptr()).compression_level = -1; - } - } - } + pub fn set_compression(&mut self, value: Option) { + unsafe { + if let Some(value) = value { + (*self.as_mut_ptr()).compression_level = value as c_int; + } else { + (*self.as_mut_ptr()).compression_level = -1; + } + } + } - pub fn set_time_base>(&mut self, value: R) { - unsafe { - (*self.as_mut_ptr()).time_base = value.into().into(); - } - } + pub fn set_time_base>(&mut self, value: R) { + unsafe { + (*self.as_mut_ptr()).time_base = value.into().into(); + } + } - pub fn set_frame_rate>(&mut self, value: Option) { - 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; - } - } - } + pub fn set_frame_rate>(&mut self, value: Option) { + 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; + } + } + } } impl Deref for Encoder { - type Target = Context; + type Target = Context; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Encoder { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Encoder { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Encoder { - fn as_mut(&mut self) -> &mut Context { - &mut *self - } + fn as_mut(&mut self) -> &mut Context { + &mut *self + } } diff --git a/src/codec/encoder/mod.rs b/src/codec/encoder/mod.rs index b3178ff..7d934a6 100644 --- a/src/codec/encoder/mod.rs +++ b/src/codec/encoder/mod.rs @@ -24,38 +24,36 @@ pub use self::decision::Decision; use std::ffi::CString; -use ffi::*; use codec::Context; -use ::Codec; use codec::Id; +use ffi::*; +use Codec; pub fn new() -> Encoder { - Context::new().encoder() + Context::new().encoder() } pub fn find(id: Id) -> Option { - unsafe { - let ptr = avcodec_find_encoder(id.into()); + unsafe { + let ptr = avcodec_find_encoder(id.into()); - if ptr.is_null() { - None - } - else { - Some(Codec::wrap(ptr)) - } - } + if ptr.is_null() { + None + } else { + Some(Codec::wrap(ptr)) + } + } } pub fn find_by_name(name: &str) -> Option { - unsafe { - let name = CString::new(name).unwrap(); - let ptr = avcodec_find_encoder_by_name(name.as_ptr()); + unsafe { + let name = CString::new(name).unwrap(); + let ptr = avcodec_find_encoder_by_name(name.as_ptr()); - if ptr.is_null() { - None - } - else { - Some(Codec::wrap(ptr)) - } - } + if ptr.is_null() { + None + } else { + Some(Codec::wrap(ptr)) + } + } } diff --git a/src/codec/encoder/motion_estimation.rs b/src/codec/encoder/motion_estimation.rs index 7fc47fe..6cd67b3 100644 --- a/src/codec/encoder/motion_estimation.rs +++ b/src/codec/encoder/motion_estimation.rs @@ -2,50 +2,50 @@ use libc::c_int; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum MotionEstimation { - Zero, - Full, - Log, - Phods, - Epzs, - X1, - Hex, - Umh, - Iter, - Tesa, + Zero, + Full, + Log, + Phods, + Epzs, + X1, + Hex, + Umh, + Iter, + Tesa, } impl From for MotionEstimation { - fn from(value: c_int) -> MotionEstimation { - match value { - 1 => MotionEstimation::Zero, - 2 => MotionEstimation::Full, - 3 => MotionEstimation::Log, - 4 => MotionEstimation::Phods, - 5 => MotionEstimation::Epzs, - 6 => MotionEstimation::X1, - 7 => MotionEstimation::Hex, - 8 => MotionEstimation::Umh, - 9 => MotionEstimation::Iter, - 10 => MotionEstimation::Tesa, + fn from(value: c_int) -> MotionEstimation { + match value { + 1 => MotionEstimation::Zero, + 2 => MotionEstimation::Full, + 3 => MotionEstimation::Log, + 4 => MotionEstimation::Phods, + 5 => MotionEstimation::Epzs, + 6 => MotionEstimation::X1, + 7 => MotionEstimation::Hex, + 8 => MotionEstimation::Umh, + 9 => MotionEstimation::Iter, + 10 => MotionEstimation::Tesa, - _ => MotionEstimation::Zero - } - } + _ => MotionEstimation::Zero, + } + } } impl Into for MotionEstimation { - fn into(self) -> c_int { - match self { - MotionEstimation::Zero => 1, - MotionEstimation::Full => 2, - MotionEstimation::Log => 3, - MotionEstimation::Phods => 4, - MotionEstimation::Epzs => 5, - MotionEstimation::X1 => 6, - MotionEstimation::Hex => 7, - MotionEstimation::Umh => 8, - MotionEstimation::Iter => 9, - MotionEstimation::Tesa => 10 - } - } + fn into(self) -> c_int { + match self { + MotionEstimation::Zero => 1, + MotionEstimation::Full => 2, + MotionEstimation::Log => 3, + MotionEstimation::Phods => 4, + MotionEstimation::Epzs => 5, + MotionEstimation::X1 => 6, + MotionEstimation::Hex => 7, + MotionEstimation::Umh => 8, + MotionEstimation::Iter => 9, + MotionEstimation::Tesa => 10, + } + } } diff --git a/src/codec/encoder/prediction.rs b/src/codec/encoder/prediction.rs index 0f895aa..3b22777 100644 --- a/src/codec/encoder/prediction.rs +++ b/src/codec/encoder/prediction.rs @@ -1,31 +1,31 @@ -use libc::c_int; use ffi::*; +use libc::c_int; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Prediction { - Left, - Plane, - Median, + Left, + Plane, + Median, } impl From for Prediction { - fn from(value: c_int) -> Prediction { - match value { - FF_PRED_LEFT => Prediction::Left, - FF_PRED_PLANE => Prediction::Plane, - FF_PRED_MEDIAN => Prediction::Median, + fn from(value: c_int) -> Prediction { + match value { + FF_PRED_LEFT => Prediction::Left, + FF_PRED_PLANE => Prediction::Plane, + FF_PRED_MEDIAN => Prediction::Median, - _ => Prediction::Left - } - } + _ => Prediction::Left, + } + } } impl Into for Prediction { - fn into(self) -> c_int { - match self { - Prediction::Left => FF_PRED_LEFT, - Prediction::Plane => FF_PRED_PLANE, - Prediction::Median => FF_PRED_MEDIAN, - } - } + fn into(self) -> c_int { + match self { + Prediction::Left => FF_PRED_LEFT, + Prediction::Plane => FF_PRED_PLANE, + Prediction::Median => FF_PRED_MEDIAN, + } + } } diff --git a/src/codec/encoder/subtitle.rs b/src/codec/encoder/subtitle.rs index 429e06f..33ac17c 100644 --- a/src/codec/encoder/subtitle.rs +++ b/src/codec/encoder/subtitle.rs @@ -1,114 +1,121 @@ use std::ops::{Deref, DerefMut}; use std::ptr; -use libc::c_int; use ffi::*; +use libc::c_int; use super::Encoder as Super; -use ::{Error, Dictionary}; use codec::{traits, Context}; +use {Dictionary, Error}; pub struct Subtitle(pub Super); impl Subtitle { - pub fn open(mut self) -> Result { - unsafe { - match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - } + pub fn open(mut self) -> Result { + unsafe { + match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } + } - pub fn open_as(mut self, codec: E) -> Result { - unsafe { - if let Some(codec) = codec.encoder() { - match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - else { - Err(Error::EncoderNotFound) - } - } - } + pub fn open_as(mut self, codec: E) -> Result { + unsafe { + if let Some(codec) = codec.encoder() { + match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } else { + Err(Error::EncoderNotFound) + } + } + } - pub fn open_as_with(mut self, codec: E, options: Dictionary) -> Result { - unsafe { - if let Some(codec) = codec.encoder() { - let mut opts = options.disown(); - let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts); + pub fn open_as_with( + mut self, + codec: E, + options: Dictionary, + ) -> Result { + unsafe { + if let Some(codec) = codec.encoder() { + let mut opts = options.disown(); + let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - else { - Err(Error::EncoderNotFound) - } - } - } + match res { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } else { + Err(Error::EncoderNotFound) + } + } + } } impl Deref for Subtitle { - type Target = Super; + type Target = Super; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Subtitle { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Subtitle { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Subtitle { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } pub struct Encoder(pub Subtitle); impl Encoder { - pub fn encode(&mut self, subtitle: &::Subtitle, out: &mut [u8]) -> Result { - unsafe { - match avcodec_encode_subtitle(self.0.as_mut_ptr(), out.as_mut_ptr(), out.len() as c_int, subtitle.as_ptr()) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(true) - } - } - } + pub fn encode(&mut self, subtitle: &::Subtitle, out: &mut [u8]) -> Result { + unsafe { + match avcodec_encode_subtitle( + self.0.as_mut_ptr(), + out.as_mut_ptr(), + out.len() as c_int, + subtitle.as_ptr(), + ) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(true), + } + } + } } impl Deref for Encoder { - type Target = Subtitle; + type Target = Subtitle; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl AsRef for Encoder { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Encoder { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } diff --git a/src/codec/encoder/video.rs b/src/codec/encoder/video.rs index 596b8a6..a21aaa1 100644 --- a/src/codec/encoder/video.rs +++ b/src/codec/encoder/video.rs @@ -1,490 +1,494 @@ use std::ops::{Deref, DerefMut}; use std::ptr; -use libc::{c_int, c_float}; use ffi::*; +use libc::{c_float, c_int}; use super::Encoder as Super; -use super::{MotionEstimation, Prediction, Comparison, Decision}; -use ::{color, packet, Error, Rational, Dictionary, frame, format}; +use super::{Comparison, Decision, MotionEstimation, Prediction}; use codec::{traits, Context}; +use {color, format, frame, packet, Dictionary, Error, Rational}; pub struct Video(pub Super); impl Video { - #[inline] - pub fn open(mut self) -> Result { - unsafe { - match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - } + #[inline] + pub fn open(mut self) -> Result { + unsafe { + match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } + } - #[inline] - pub fn open_as(mut self, codec: E) -> Result { - unsafe { - if let Some(codec) = codec.encoder() { - match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - else { - Err(Error::EncoderNotFound) - } - } - } + #[inline] + pub fn open_as(mut self, codec: E) -> Result { + unsafe { + if let Some(codec) = codec.encoder() { + match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } else { + Err(Error::EncoderNotFound) + } + } + } - #[inline] - pub fn open_with(mut self, options: Dictionary) -> Result { - unsafe { - let mut opts = options.disown(); - let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts); + #[inline] + pub fn open_with(mut self, options: Dictionary) -> Result { + unsafe { + let mut opts = options.disown(); + let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - } + match res { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } + } - #[inline] - pub fn open_as_with(mut self, codec: E, options: Dictionary) -> Result { - unsafe { - if let Some(codec) = codec.encoder() { - let mut opts = options.disown(); - let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts); + #[inline] + pub fn open_as_with( + mut self, + codec: E, + options: Dictionary, + ) -> Result { + unsafe { + if let Some(codec) = codec.encoder() { + let mut opts = options.disown(); + let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => Ok(Encoder(self)), - e => Err(Error::from(e)) - } - } - else { - Err(Error::EncoderNotFound) - } - } - } + match res { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } else { + Err(Error::EncoderNotFound) + } + } + } - #[inline] - pub fn set_width(&mut self, value: u32) { - unsafe { - (*self.as_mut_ptr()).width = value as c_int; - } - } + #[inline] + pub fn set_width(&mut self, value: u32) { + unsafe { + (*self.as_mut_ptr()).width = value as c_int; + } + } - #[inline] - pub fn width(&self) -> u32 { - unsafe { - (*self.as_ptr()).width as u32 - } - } + #[inline] + pub fn width(&self) -> u32 { + unsafe { (*self.as_ptr()).width as u32 } + } - #[inline] - pub fn set_height(&mut self, value: u32) { - unsafe { - (*self.as_mut_ptr()).height = value as c_int; - } - } + #[inline] + pub fn set_height(&mut self, value: u32) { + unsafe { + (*self.as_mut_ptr()).height = value as c_int; + } + } - #[inline] - pub fn height(&self) -> u32 { - unsafe { - (*self.as_ptr()).height as u32 - } - } + #[inline] + pub fn height(&self) -> u32 { + unsafe { (*self.as_ptr()).height as u32 } + } - #[inline] - pub fn set_gop(&mut self, value: u32) { - unsafe { - (*self.as_mut_ptr()).gop_size = value as c_int; - } - } + #[inline] + pub fn set_gop(&mut self, value: u32) { + unsafe { + (*self.as_mut_ptr()).gop_size = value as c_int; + } + } - #[inline] - pub fn set_format(&mut self, value: format::Pixel) { - unsafe { - (*self.as_mut_ptr()).pix_fmt = value.into(); - } - } + #[inline] + pub fn set_format(&mut self, value: format::Pixel) { + unsafe { + (*self.as_mut_ptr()).pix_fmt = value.into(); + } + } - #[inline] - pub fn format(&self) -> format::Pixel { - unsafe { - format::Pixel::from((*self.as_ptr()).pix_fmt) - } - } + #[inline] + pub fn format(&self) -> format::Pixel { + unsafe { format::Pixel::from((*self.as_ptr()).pix_fmt) } + } - #[inline] - #[cfg(feature = "ff_api_motion_est")] - pub fn set_motion_estimation(&mut self, value: MotionEstimation) { - unsafe { - (*self.as_mut_ptr()).me_method = value.into(); - } - } + #[inline] + #[cfg(feature = "ff_api_motion_est")] + pub fn set_motion_estimation(&mut self, value: MotionEstimation) { + unsafe { + (*self.as_mut_ptr()).me_method = value.into(); + } + } - #[inline] - pub fn set_max_b_frames(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).max_b_frames = value as c_int; - } - } + #[inline] + pub fn set_max_b_frames(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).max_b_frames = value as c_int; + } + } - #[inline] - pub fn set_b_quant_factor(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).b_quant_factor = value as c_float; - } - } + #[inline] + pub fn set_b_quant_factor(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).b_quant_factor = value as c_float; + } + } - #[inline] - pub fn set_b_quant_offset(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).b_quant_offset = value as c_float; - } - } + #[inline] + pub fn set_b_quant_offset(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).b_quant_offset = value as c_float; + } + } - #[inline] - pub fn set_i_quant_factor(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).i_quant_factor = value as c_float; - } - } + #[inline] + pub fn set_i_quant_factor(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).i_quant_factor = value as c_float; + } + } - #[inline] - pub fn set_i_quant_offset(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).i_quant_offset = value as c_float; - } - } + #[inline] + pub fn set_i_quant_offset(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).i_quant_offset = value as c_float; + } + } - #[inline] - pub fn set_lumi_masking(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).lumi_masking = value as c_float; - } - } + #[inline] + pub fn set_lumi_masking(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).lumi_masking = value as c_float; + } + } - #[inline] - pub fn set_temporal_cplx_masking(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).temporal_cplx_masking = value as c_float; - } - } + #[inline] + pub fn set_temporal_cplx_masking(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).temporal_cplx_masking = value as c_float; + } + } - #[inline] - pub fn set_spatial_cplx_masking(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).spatial_cplx_masking = value as c_float; - } - } + #[inline] + pub fn set_spatial_cplx_masking(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).spatial_cplx_masking = value as c_float; + } + } - #[inline] - pub fn set_p_masking(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).p_masking = value as c_float; - } - } + #[inline] + pub fn set_p_masking(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).p_masking = value as c_float; + } + } - #[inline] - pub fn set_dark_masking(&mut self, value: f32) { - unsafe { - (*self.as_mut_ptr()).dark_masking = value as c_float; - } - } + #[inline] + pub fn set_dark_masking(&mut self, value: f32) { + unsafe { + (*self.as_mut_ptr()).dark_masking = value as c_float; + } + } - #[inline] - pub fn set_prediction(&mut self, value: Prediction) { - unsafe { - (*self.as_mut_ptr()).prediction_method = value.into(); - } - } + #[inline] + pub fn set_prediction(&mut self, value: Prediction) { + unsafe { + (*self.as_mut_ptr()).prediction_method = value.into(); + } + } - #[inline] - pub fn set_aspect_ratio>(&mut self, value: R) { - unsafe { - (*self.as_mut_ptr()).sample_aspect_ratio = value.into().into(); - } - } + #[inline] + pub fn set_aspect_ratio>(&mut self, value: R) { + unsafe { + (*self.as_mut_ptr()).sample_aspect_ratio = value.into().into(); + } + } - #[inline] - pub fn set_me_comparison(&mut self, value: Comparison) { - unsafe { - (*self.as_mut_ptr()).me_cmp = value.into(); - } - } + #[inline] + pub fn set_me_comparison(&mut self, value: Comparison) { + unsafe { + (*self.as_mut_ptr()).me_cmp = value.into(); + } + } - #[inline] - pub fn set_me_sub_comparison(&mut self, value: Comparison) { - unsafe { - (*self.as_mut_ptr()).me_sub_cmp = value.into(); - } - } + #[inline] + pub fn set_me_sub_comparison(&mut self, value: Comparison) { + unsafe { + (*self.as_mut_ptr()).me_sub_cmp = value.into(); + } + } - #[inline] - pub fn set_mb_comparison(&mut self, value: Comparison) { - unsafe { - (*self.as_mut_ptr()).mb_cmp = value.into(); - } - } + #[inline] + pub fn set_mb_comparison(&mut self, value: Comparison) { + unsafe { + (*self.as_mut_ptr()).mb_cmp = value.into(); + } + } - #[inline] - pub fn set_ildct_comparison(&mut self, value: Comparison) { - unsafe { - (*self.as_mut_ptr()).ildct_cmp = value.into(); - } - } + #[inline] + pub fn set_ildct_comparison(&mut self, value: Comparison) { + unsafe { + (*self.as_mut_ptr()).ildct_cmp = value.into(); + } + } - #[inline] - pub fn set_dia_size(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).dia_size = value as c_int; - } - } + #[inline] + pub fn set_dia_size(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).dia_size = value as c_int; + } + } - #[inline] - pub fn set_last_predictors(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).last_predictor_count = value as c_int; - } - } + #[inline] + pub fn set_last_predictors(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).last_predictor_count = value as c_int; + } + } - #[inline] - pub fn set_pre_me(&mut self, value: MotionEstimation) { - unsafe { - (*self.as_mut_ptr()).pre_me = value.into(); - } - } + #[inline] + pub fn set_pre_me(&mut self, value: MotionEstimation) { + unsafe { + (*self.as_mut_ptr()).pre_me = value.into(); + } + } - #[inline] - pub fn set_me_pre_comparison(&mut self, value: Comparison) { - unsafe { - (*self.as_mut_ptr()).me_pre_cmp = value.into(); - } - } + #[inline] + pub fn set_me_pre_comparison(&mut self, value: Comparison) { + unsafe { + (*self.as_mut_ptr()).me_pre_cmp = value.into(); + } + } - #[inline] - pub fn set_pre_dia_size(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).pre_dia_size = value as c_int; - } - } + #[inline] + pub fn set_pre_dia_size(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).pre_dia_size = value as c_int; + } + } - #[inline] - pub fn set_me_subpel_quality(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).me_subpel_quality = value as c_int; - } - } + #[inline] + pub fn set_me_subpel_quality(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).me_subpel_quality = value as c_int; + } + } - #[inline] - pub fn set_me_range(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).me_range = value as c_int; - } - } + #[inline] + pub fn set_me_range(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).me_range = value as c_int; + } + } - #[inline] - #[cfg(feature = "ff_api_quant_bias")] - pub fn set_intra_quant_bias(&mut self, value: Option) { - unsafe { - if let Some(value) = value { - (*self.as_mut_ptr()).intra_quant_bias = value as c_int; - } - else { - (*self.as_mut_ptr()).intra_quant_bias = FF_DEFAULT_QUANT_BIAS; - } - } - } + #[inline] + #[cfg(feature = "ff_api_quant_bias")] + pub fn set_intra_quant_bias(&mut self, value: Option) { + unsafe { + if let Some(value) = value { + (*self.as_mut_ptr()).intra_quant_bias = value as c_int; + } else { + (*self.as_mut_ptr()).intra_quant_bias = FF_DEFAULT_QUANT_BIAS; + } + } + } - #[inline] - #[cfg(feature = "ff_api_quant_bias")] - pub fn set_inter_quant_bias(&mut self, value: Option) { - unsafe { - if let Some(value) = value { - (*self.as_mut_ptr()).inter_quant_bias = value as c_int; - } - else { - (*self.as_mut_ptr()).inter_quant_bias = FF_DEFAULT_QUANT_BIAS; - } - } - } + #[inline] + #[cfg(feature = "ff_api_quant_bias")] + pub fn set_inter_quant_bias(&mut self, value: Option) { + unsafe { + if let Some(value) = value { + (*self.as_mut_ptr()).inter_quant_bias = value as c_int; + } else { + (*self.as_mut_ptr()).inter_quant_bias = FF_DEFAULT_QUANT_BIAS; + } + } + } - #[inline] - pub fn set_mb_decision(&mut self, value: Decision) { - unsafe { - (*self.as_mut_ptr()).mb_decision = value.into(); - } - } + #[inline] + pub fn set_mb_decision(&mut self, value: Decision) { + unsafe { + (*self.as_mut_ptr()).mb_decision = value.into(); + } + } - #[inline] - pub fn set_mb_lmin(&mut self, value: i32) { - unsafe { - (*self.as_mut_ptr()).mb_lmin = value as c_int; - } - } + #[inline] + pub fn set_mb_lmin(&mut self, value: i32) { + unsafe { + (*self.as_mut_ptr()).mb_lmin = value as c_int; + } + } - #[inline] - pub fn set_mb_lmax(&mut self, value: i32) { - unsafe { - (*self.as_mut_ptr()).mb_lmax = value as c_int; - } - } + #[inline] + pub fn set_mb_lmax(&mut self, value: i32) { + unsafe { + (*self.as_mut_ptr()).mb_lmax = value as c_int; + } + } - #[inline] - pub fn set_intra_dc_precision(&mut self, value: u8) { - unsafe { - (*self.as_mut_ptr()).intra_dc_precision = value as c_int; - } - } + #[inline] + pub fn set_intra_dc_precision(&mut self, value: u8) { + unsafe { + (*self.as_mut_ptr()).intra_dc_precision = i32::from(value); + } + } - #[inline] - pub fn set_qmin(&mut self, value: i32) { - unsafe { - (*self.as_mut_ptr()).qmin = value as c_int; - } - } + #[inline] + pub fn set_qmin(&mut self, value: i32) { + unsafe { + (*self.as_mut_ptr()).qmin = value as c_int; + } + } - #[inline] - pub fn set_qmax(&mut self, value: i32) { - unsafe { - (*self.as_mut_ptr()).qmax = value as c_int; - } - } + #[inline] + pub fn set_qmax(&mut self, value: i32) { + unsafe { + (*self.as_mut_ptr()).qmax = value as c_int; + } + } - #[inline] - pub fn set_global_quality(&mut self, value: i32) { - unsafe { - (*self.as_mut_ptr()).global_quality = value as c_int; - } - } + #[inline] + pub fn set_global_quality(&mut self, value: i32) { + unsafe { + (*self.as_mut_ptr()).global_quality = value as c_int; + } + } - #[inline] - pub fn set_colorspace(&mut self, value: color::Space) { - unsafe { - (*self.as_mut_ptr()).colorspace = value.into(); - } - } + #[inline] + pub fn set_colorspace(&mut self, value: color::Space) { + unsafe { + (*self.as_mut_ptr()).colorspace = value.into(); + } + } - #[inline] - pub fn colorspace(&self) -> color::Space { - unsafe { - (*self.as_ptr()).colorspace.into() - } - } + #[inline] + pub fn colorspace(&self) -> color::Space { + unsafe { (*self.as_ptr()).colorspace.into() } + } - #[inline] - pub fn set_color_range(&mut self, value: color::Range) { - unsafe { - (*self.as_mut_ptr()).color_range = value.into(); - } - } + #[inline] + pub fn set_color_range(&mut self, value: color::Range) { + unsafe { + (*self.as_mut_ptr()).color_range = value.into(); + } + } - #[inline] - pub fn color_range(&self) -> color::Range { - unsafe { - (*self.as_ptr()).color_range.into() - } - } + #[inline] + pub fn color_range(&self) -> color::Range { + unsafe { (*self.as_ptr()).color_range.into() } + } } impl Deref for Video { - type Target = Super; + type Target = Super; - #[inline(always)] - fn deref(&self) -> &::Target { - &self.0 - } + #[inline(always)] + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Video { - #[inline(always)] - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + #[inline(always)] + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Video { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Video { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } pub struct Encoder(pub Video); impl Encoder { - #[inline] - pub fn encode(&mut self, frame: &frame::Video, out: &mut P) -> Result { - unsafe { - if self.format() != frame.format() || self.width() != frame.width() || self.height() != frame.height() { - return Err(Error::InvalidData); - } + #[inline] + pub fn encode( + &mut self, + frame: &frame::Video, + out: &mut P, + ) -> Result { + unsafe { + if self.format() != frame.format() || self.width() != frame.width() + || self.height() != frame.height() + { + return Err(Error::InvalidData); + } - let mut got: c_int = 0; + let mut got: c_int = 0; - match avcodec_encode_video2(self.0.as_mut_ptr(), out.as_mut_ptr(), frame.as_ptr(), &mut got) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0) - } - } - } + match avcodec_encode_video2( + self.0.as_mut_ptr(), + out.as_mut_ptr(), + frame.as_ptr(), + &mut got, + ) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(got != 0), + } + } + } - #[inline] - pub fn flush(&mut self, out: &mut P) -> Result { - unsafe { - let mut got: c_int = 0; + #[inline] + pub fn flush(&mut self, out: &mut P) -> Result { + unsafe { + let mut got: c_int = 0; - match avcodec_encode_video2(self.0.as_mut_ptr(), out.as_mut_ptr(), ptr::null(), &mut got) { - e if e < 0 => Err(Error::from(e)), - _ => Ok(got != 0) - } - } - } + match avcodec_encode_video2( + self.0.as_mut_ptr(), + out.as_mut_ptr(), + ptr::null(), + &mut got, + ) { + e if e < 0 => Err(Error::from(e)), + _ => Ok(got != 0), + } + } + } - #[inline] - pub fn frame_size(&self) -> u32 { - unsafe { - (*self.as_ptr()).frame_size as u32 - } - } + #[inline] + pub fn frame_size(&self) -> u32 { + unsafe { (*self.as_ptr()).frame_size as u32 } + } } impl Deref for Encoder { - type Target = Video; + type Target = Video; - #[inline] - fn deref(&self) -> &::Target { - &self.0 - } + #[inline] + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Encoder { - #[inline] - fn deref_mut(&mut self) -> &mut ::Target { - &mut self.0 - } + #[inline] + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl AsRef for Encoder { - fn as_ref(&self) -> &Context { - &self - } + fn as_ref(&self) -> &Context { + self + } } impl AsMut for Encoder { - fn as_mut(&mut self) -> &mut Context { - &mut self.0 - } + fn as_mut(&mut self) -> &mut Context { + &mut self.0 + } } diff --git a/src/codec/field_order.rs b/src/codec/field_order.rs index da1f820..46dff81 100644 --- a/src/codec/field_order.rs +++ b/src/codec/field_order.rs @@ -1,38 +1,38 @@ -use ffi::*; use ffi::AVFieldOrder::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum FieldOrder { - Unknown, - Progressive, - TT, - BB, - TB, - BT, + Unknown, + Progressive, + TT, + BB, + TB, + BT, } impl From for FieldOrder { - fn from(value: AVFieldOrder) -> Self { - match value { - AV_FIELD_UNKNOWN => FieldOrder::Unknown, - AV_FIELD_PROGRESSIVE => FieldOrder::Progressive, - AV_FIELD_TT => FieldOrder::TT, - AV_FIELD_BB => FieldOrder::BB, - AV_FIELD_TB => FieldOrder::TB, - AV_FIELD_BT => FieldOrder::BT - } - } + fn from(value: AVFieldOrder) -> Self { + match value { + AV_FIELD_UNKNOWN => FieldOrder::Unknown, + AV_FIELD_PROGRESSIVE => FieldOrder::Progressive, + AV_FIELD_TT => FieldOrder::TT, + AV_FIELD_BB => FieldOrder::BB, + AV_FIELD_TB => FieldOrder::TB, + AV_FIELD_BT => FieldOrder::BT, + } + } } impl Into for FieldOrder { - fn into(self) -> AVFieldOrder { - match self { - FieldOrder::Unknown => AV_FIELD_UNKNOWN, - FieldOrder::Progressive => AV_FIELD_PROGRESSIVE, - FieldOrder::TT => AV_FIELD_TT, - FieldOrder::BB => AV_FIELD_BB, - FieldOrder::TB => AV_FIELD_TB, - FieldOrder::BT => AV_FIELD_BT - } - } + fn into(self) -> AVFieldOrder { + match self { + FieldOrder::Unknown => AV_FIELD_UNKNOWN, + FieldOrder::Progressive => AV_FIELD_PROGRESSIVE, + FieldOrder::TT => AV_FIELD_TT, + FieldOrder::BB => AV_FIELD_BB, + FieldOrder::TB => AV_FIELD_TB, + FieldOrder::BT => AV_FIELD_BT, + } + } } diff --git a/src/codec/flag.rs b/src/codec/flag.rs index a87752a..186f5f6 100644 --- a/src/codec/flag.rs +++ b/src/codec/flag.rs @@ -1,26 +1,25 @@ -use libc::c_uint; use ffi::*; +use libc::c_uint; bitflags! { - pub struct Flags: c_uint { - const UNALIGNED = AV_CODEC_FLAG_UNALIGNED; - const QSCALE = AV_CODEC_FLAG_QSCALE; - const _4MV = AV_CODEC_FLAG_4MV; - const OUTPUT_CORRUPT = AV_CODEC_FLAG_OUTPUT_CORRUPT; - const QPEL = AV_CODEC_FLAG_QPEL; - const PASS1 = AV_CODEC_FLAG_PASS1; - const PASS2 = AV_CODEC_FLAG_PASS2; - const GRAY = AV_CODEC_FLAG_GRAY; - const PSNR = AV_CODEC_FLAG_PSNR; - const TRUNCATED = AV_CODEC_FLAG_TRUNCATED; - const INTERLACED_DCT = AV_CODEC_FLAG_INTERLACED_DCT; - const LOW_DELAY = AV_CODEC_FLAG_LOW_DELAY; - const GLOBAL_HEADER = AV_CODEC_FLAG_GLOBAL_HEADER; - const BITEXACT = AV_CODEC_FLAG_BITEXACT; - const AC_PRED = AV_CODEC_FLAG_AC_PRED; - const LOOP_FILTER = AV_CODEC_FLAG_LOOP_FILTER; - const INTERLACED_ME = AV_CODEC_FLAG_INTERLACED_ME; - const CLOSED_GOP = AV_CODEC_FLAG_CLOSED_GOP; - } + pub struct Flags: c_uint { + const UNALIGNED = AV_CODEC_FLAG_UNALIGNED; + const QSCALE = AV_CODEC_FLAG_QSCALE; + const _4MV = AV_CODEC_FLAG_4MV; + const OUTPUT_CORRUPT = AV_CODEC_FLAG_OUTPUT_CORRUPT; + const QPEL = AV_CODEC_FLAG_QPEL; + const PASS1 = AV_CODEC_FLAG_PASS1; + const PASS2 = AV_CODEC_FLAG_PASS2; + const GRAY = AV_CODEC_FLAG_GRAY; + const PSNR = AV_CODEC_FLAG_PSNR; + const TRUNCATED = AV_CODEC_FLAG_TRUNCATED; + const INTERLACED_DCT = AV_CODEC_FLAG_INTERLACED_DCT; + const LOW_DELAY = AV_CODEC_FLAG_LOW_DELAY; + const GLOBAL_HEADER = AV_CODEC_FLAG_GLOBAL_HEADER; + const BITEXACT = AV_CODEC_FLAG_BITEXACT; + const AC_PRED = AV_CODEC_FLAG_AC_PRED; + const LOOP_FILTER = AV_CODEC_FLAG_LOOP_FILTER; + const INTERLACED_ME = AV_CODEC_FLAG_INTERLACED_ME; + const CLOSED_GOP = AV_CODEC_FLAG_CLOSED_GOP; + } } - diff --git a/src/codec/id.rs b/src/codec/id.rs index 3c669f6..28e923b 100644 --- a/src/codec/id.rs +++ b/src/codec/id.rs @@ -1,1454 +1,1450 @@ use std::ffi::CStr; use std::str::from_utf8_unchecked; -use ffi::*; use ffi::AVCodecID::*; -use ::util::media; +use ffi::*; +use util::media; #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Id { - None, + None, - // video codecs - MPEG1VIDEO, - MPEG2VIDEO, - #[cfg(feature = "ff_api_xvmc")] - MPEG2VIDEO_XVMC, - H261, - H263, - RV10, - RV20, - MJPEG, - MJPEGB, - LJPEG, - SP5X, - JPEGLS, - MPEG4, - RAWVIDEO, - MSMPEG4V1, - MSMPEG4V2, - MSMPEG4V3, - WMV1, - WMV2, - H263P, - H263I, - FLV1, - SVQ1, - SVQ3, - DVVIDEO, - HUFFYUV, - CYUV, - H264, - INDEO3, - VP3, - THEORA, - ASV1, - ASV2, - FFV1, - XM4, - VCR1, - CLJR, - MDEC, - ROQ, - INTERPLAY_VIDEO, - XAN_WC3, - XAN_WC4, - RPZA, - CINEPAK, - WS_VQA, - MSRLE, - MSVIDEO1, - IDCIN, - BPS8, - SMC, - FLIC, - TRUEMOTION1, - VMDVIDEO, - MSZH, - ZLIB, - QTRLE, - TSCC, - ULTI, - QDRAW, - VIXL, - QPEG, - PNG, - PPM, - PBM, - PGM, - PGMYUV, - PAM, - FFVHUFF, - RV30, - RV40, - VC1, - WMV3, - LOCO, - WNV1, - AASC, - INDEO2, - FRAPS, - TRUEMOTION2, - BMP, - CSCD, - MMVIDEO, - ZMBV, - AVS, - SMACKVIDEO, - NUV, - KMVC, - FLASHSV, - CAVS, - JPEG2000, - VMNC, - VP5, - VP6, - VP6F, - TARGA, - DSICINVIDEO, - TIERTEXSEQVIDEO, - TIFF, - GIF, - DXA, - DNXHD, - THP, - SGI, - C93, - BETHSOFTVID, - PTX, - TXD, - VP6A, - AMV, - VB, - PCX, - SUNRAST, - INDEO4, - INDEO5, - MIMIC, - RL2, - ESCAPE124, - DIRAC, - BFI, - CMV, - MOTIONPIXELS, - TGV, - TGQ, - TQI, - AURA, - AURA2, - V210X, - TMV, - V210, - DPX, - MAD, - FRWU, - FLASHSV2, - CDGRAPHICS, - R210, - ANM, - BINKVIDEO, - IFF_ILBM, - IFF_BYTERUN1, - KGV1, - YOP, - VP8, - PICTOR, - ANSI, - A64_MULTI, - A64_MULTI5, - R10K, - MXPEG, - LAGARITH, - PRORES, - JV, - DFA, - WMV3IMAGE, - VC1IMAGE, - UTVIDEO, - BMV_VIDEO, - VBLE, - DXTORY, - V410, - XWD, - CDXL, - XBM, - ZEROCODEC, - MSS1, - MSA1, - TSCC2, - MTS2, - CLLC, - MSS2, - VP9, - AIC, - ESCAPE130, - G2M, - WEBP, - HNM4_VIDEO, - HEVC, - H265, - FIC, - ALIAS_PIX, - BRENDER_PIX, - PAF_VIDEO, - EXR, - VP7, - SANM, - SGIRLE, - MVC1, - MVC2, - HQX, - TDSC, - HQ_HQA, - HAP, - DDS, - DXV, - SCREENPRESSO, - RSCC, + // video codecs + MPEG1VIDEO, + MPEG2VIDEO, + #[cfg(feature = "ff_api_xvmc")] + MPEG2VIDEO_XVMC, + H261, + H263, + RV10, + RV20, + MJPEG, + MJPEGB, + LJPEG, + SP5X, + JPEGLS, + MPEG4, + RAWVIDEO, + MSMPEG4V1, + MSMPEG4V2, + MSMPEG4V3, + WMV1, + WMV2, + H263P, + H263I, + FLV1, + SVQ1, + SVQ3, + DVVIDEO, + HUFFYUV, + CYUV, + H264, + INDEO3, + VP3, + THEORA, + ASV1, + ASV2, + FFV1, + XM4, + VCR1, + CLJR, + MDEC, + ROQ, + INTERPLAY_VIDEO, + XAN_WC3, + XAN_WC4, + RPZA, + CINEPAK, + WS_VQA, + MSRLE, + MSVIDEO1, + IDCIN, + BPS8, + SMC, + FLIC, + TRUEMOTION1, + VMDVIDEO, + MSZH, + ZLIB, + QTRLE, + TSCC, + ULTI, + QDRAW, + VIXL, + QPEG, + PNG, + PPM, + PBM, + PGM, + PGMYUV, + PAM, + FFVHUFF, + RV30, + RV40, + VC1, + WMV3, + LOCO, + WNV1, + AASC, + INDEO2, + FRAPS, + TRUEMOTION2, + BMP, + CSCD, + MMVIDEO, + ZMBV, + AVS, + SMACKVIDEO, + NUV, + KMVC, + FLASHSV, + CAVS, + JPEG2000, + VMNC, + VP5, + VP6, + VP6F, + TARGA, + DSICINVIDEO, + TIERTEXSEQVIDEO, + TIFF, + GIF, + DXA, + DNXHD, + THP, + SGI, + C93, + BETHSOFTVID, + PTX, + TXD, + VP6A, + AMV, + VB, + PCX, + SUNRAST, + INDEO4, + INDEO5, + MIMIC, + RL2, + ESCAPE124, + DIRAC, + BFI, + CMV, + MOTIONPIXELS, + TGV, + TGQ, + TQI, + AURA, + AURA2, + V210X, + TMV, + V210, + DPX, + MAD, + FRWU, + FLASHSV2, + CDGRAPHICS, + R210, + ANM, + BINKVIDEO, + IFF_ILBM, + IFF_BYTERUN1, + KGV1, + YOP, + VP8, + PICTOR, + ANSI, + A64_MULTI, + A64_MULTI5, + R10K, + MXPEG, + LAGARITH, + PRORES, + JV, + DFA, + WMV3IMAGE, + VC1IMAGE, + UTVIDEO, + BMV_VIDEO, + VBLE, + DXTORY, + V410, + XWD, + CDXL, + XBM, + ZEROCODEC, + MSS1, + MSA1, + TSCC2, + MTS2, + CLLC, + MSS2, + VP9, + AIC, + ESCAPE130, + G2M, + WEBP, + HNM4_VIDEO, + HEVC, + H265, + FIC, + ALIAS_PIX, + BRENDER_PIX, + PAF_VIDEO, + EXR, + VP7, + SANM, + SGIRLE, + MVC1, + MVC2, + HQX, + TDSC, + HQ_HQA, + HAP, + DDS, + DXV, + SCREENPRESSO, + RSCC, - Y41P, - AVRP, - V012, - AVUI, - AYUV, - TARGA_Y216, - V308, - V408, - YUV4, - AVRN, - CPIA, - XFACE, - SNOW, - SMVJPEG, - APNG, - DAALA, - CFHD, - TRUEMOTION2RT, - M101, - MAGICYUV, - SHEERVIDEO, - YLC, + Y41P, + AVRP, + V012, + AVUI, + AYUV, + TARGA_Y216, + V308, + V408, + YUV4, + AVRN, + CPIA, + XFACE, + SNOW, + SMVJPEG, + APNG, + DAALA, + CFHD, + TRUEMOTION2RT, + M101, + MAGICYUV, + SHEERVIDEO, + YLC, - // various PCM "codecs" - PCM_S16LE, - PCM_S16BE, - PCM_U16LE, - PCM_U16BE, - PCM_S8, - PCM_U8, - PCM_MULAW, - PCM_ALAW, - PCM_S32LE, - PCM_S32BE, - PCM_U32LE, - PCM_U32BE, - PCM_S24LE, - PCM_S24BE, - PCM_U24LE, - PCM_U24BE, - PCM_S24DAUD, - PCM_ZORK, - PCM_S16LE_PLANAR, - PCM_DVD, - PCM_F32BE, - PCM_F32LE, - PCM_F64BE, - PCM_F64LE, - PCM_BLURAY, - PCM_LXF, - S302M, - PCM_S8_PLANAR, - PCM_S24LE_PLANAR, - PCM_S32LE_PLANAR, - PCM_S16BE_PLANAR, + // various PCM "codecs" + PCM_S16LE, + PCM_S16BE, + PCM_U16LE, + PCM_U16BE, + PCM_S8, + PCM_U8, + PCM_MULAW, + PCM_ALAW, + PCM_S32LE, + PCM_S32BE, + PCM_U32LE, + PCM_U32BE, + PCM_S24LE, + PCM_S24BE, + PCM_U24LE, + PCM_U24BE, + PCM_S24DAUD, + PCM_ZORK, + PCM_S16LE_PLANAR, + PCM_DVD, + PCM_F32BE, + PCM_F32LE, + PCM_F64BE, + PCM_F64LE, + PCM_BLURAY, + PCM_LXF, + S302M, + PCM_S8_PLANAR, + PCM_S24LE_PLANAR, + PCM_S32LE_PLANAR, + PCM_S16BE_PLANAR, - PCM_S64LE, - PCM_S64BE, + PCM_S64LE, + PCM_S64BE, - // various ADPCM codecs - ADPCM_IMA_QT, - ADPCM_IMA_WAV, - ADPCM_IMA_DK3, - ADPCM_IMA_DK4, - ADPCM_IMA_WS, - ADPCM_IMA_SMJPEG, - ADPCM_MS, - ADPCM_4XM, - ADPCM_XA, - ADPCM_ADX, - ADPCM_EA, - ADPCM_G726, - ADPCM_CT, - ADPCM_SWF, - ADPCM_YAMAHA, - ADPCM_SBPRO_4, - ADPCM_SBPRO_3, - ADPCM_SBPRO_2, - ADPCM_THP, - ADPCM_IMA_AMV, - ADPCM_EA_R1, - ADPCM_EA_R3, - ADPCM_EA_R2, - ADPCM_IMA_EA_SEAD, - ADPCM_IMA_EA_EACS, - ADPCM_EA_XAS, - ADPCM_EA_MAXIS_XA, - ADPCM_IMA_ISS, - ADPCM_G722, - ADPCM_IMA_APC, - ADPCM_VIMA, - VIMA, + // various ADPCM codecs + ADPCM_IMA_QT, + ADPCM_IMA_WAV, + ADPCM_IMA_DK3, + ADPCM_IMA_DK4, + ADPCM_IMA_WS, + ADPCM_IMA_SMJPEG, + ADPCM_MS, + ADPCM_4XM, + ADPCM_XA, + ADPCM_ADX, + ADPCM_EA, + ADPCM_G726, + ADPCM_CT, + ADPCM_SWF, + ADPCM_YAMAHA, + ADPCM_SBPRO_4, + ADPCM_SBPRO_3, + ADPCM_SBPRO_2, + ADPCM_THP, + ADPCM_IMA_AMV, + ADPCM_EA_R1, + ADPCM_EA_R3, + ADPCM_EA_R2, + ADPCM_IMA_EA_SEAD, + ADPCM_IMA_EA_EACS, + ADPCM_EA_XAS, + ADPCM_EA_MAXIS_XA, + ADPCM_IMA_ISS, + ADPCM_G722, + ADPCM_IMA_APC, + ADPCM_VIMA, + VIMA, - ADPCM_AFC, - ADPCM_IMA_OKI, - ADPCM_DTK, - ADPCM_IMA_RAD, - ADPCM_G726LE, - ADPCM_THP_LE, - ADPCM_PSX, - ADPCM_AICA, - ADPCM_IMA_DAT4, - ADPCM_MTAF, + ADPCM_AFC, + ADPCM_IMA_OKI, + ADPCM_DTK, + ADPCM_IMA_RAD, + ADPCM_G726LE, + ADPCM_THP_LE, + ADPCM_PSX, + ADPCM_AICA, + ADPCM_IMA_DAT4, + ADPCM_MTAF, - // AMR - AMR_NB, - AMR_WB, + // AMR + AMR_NB, + AMR_WB, - // RealAudio codecs - RA_144, - RA_288, + // RealAudio codecs + RA_144, + RA_288, - // various DPCM codecs - ROQ_DPCM, - INTERPLAY_DPCM, - XAN_DPCM, - SOL_DPCM, + // various DPCM codecs + ROQ_DPCM, + INTERPLAY_DPCM, + XAN_DPCM, + SOL_DPCM, - SDX2_DPCM, + SDX2_DPCM, - // audio codecs - MP2, - MP3, - AAC, - AC3, - DTS, - VORBIS, - DVAUDIO, - WMAV1, - WMAV2, - MACE3, - MACE6, - VMDAUDIO, - FLAC, - MP3ADU, - MP3ON4, - SHORTEN, - ALAC, - WESTWOOD_SND1, - GSM, - QDM2, - COOK, - TRUESPEECH, - TTA, - SMACKAUDIO, - QCELP, - WAVPACK, - DSICINAUDIO, - IMC, - MUSEPACK7, - MLP, - GSM_MS, - ATRAC3, - #[cfg(feature = "ff_api_voxware")] - VOXWARE, - APE, - NELLYMOSER, - MUSEPACK8, - SPEEX, - WMAVOICE, - WMAPRO, - WMALOSSLESS, - ATRAC3P, - EAC3, - SIPR, - MP1, - TWINVQ, - TRUEHD, - MP4ALS, - ATRAC1, - BINKAUDIO_RDFT, - BINKAUDIO_DCT, - AAC_LATM, - QDMC, - CELT, - G723_1, - G729, - SVX_EXP8, - SVX_FIB8, - BMV_AUDIO, - RALF, - IAC, - ILBC, - OPUS, - COMFORT_NOISE, - TAK, - METASOUND, - PAF_AUDIO, - ON2AVC, - DSS_SP, + // audio codecs + MP2, + MP3, + AAC, + AC3, + DTS, + VORBIS, + DVAUDIO, + WMAV1, + WMAV2, + MACE3, + MACE6, + VMDAUDIO, + FLAC, + MP3ADU, + MP3ON4, + SHORTEN, + ALAC, + WESTWOOD_SND1, + GSM, + QDM2, + COOK, + TRUESPEECH, + TTA, + SMACKAUDIO, + QCELP, + WAVPACK, + DSICINAUDIO, + IMC, + MUSEPACK7, + MLP, + GSM_MS, + ATRAC3, + #[cfg(feature = "ff_api_voxware")] + VOXWARE, + APE, + NELLYMOSER, + MUSEPACK8, + SPEEX, + WMAVOICE, + WMAPRO, + WMALOSSLESS, + ATRAC3P, + EAC3, + SIPR, + MP1, + TWINVQ, + TRUEHD, + MP4ALS, + ATRAC1, + BINKAUDIO_RDFT, + BINKAUDIO_DCT, + AAC_LATM, + QDMC, + CELT, + G723_1, + G729, + SVX_EXP8, + SVX_FIB8, + BMV_AUDIO, + RALF, + IAC, + ILBC, + OPUS, + COMFORT_NOISE, + TAK, + METASOUND, + PAF_AUDIO, + ON2AVC, + DSS_SP, - FFWAVESYNTH, - SONIC, - SONIC_LS, - EVRC, - SMV, - DSD_LSBF, - DSD_MSBF, - DSD_LSBF_PLANAR, - DSD_MSBF_PLANAR, - _4GV, - INTERPLAY_ACM, - XMA1, - XMA2, - DST, + FFWAVESYNTH, + SONIC, + SONIC_LS, + EVRC, + SMV, + DSD_LSBF, + DSD_MSBF, + DSD_LSBF_PLANAR, + DSD_MSBF_PLANAR, + _4GV, + INTERPLAY_ACM, + XMA1, + XMA2, + DST, - // subtitle codecs - DVD_SUBTITLE, - DVB_SUBTITLE, - TEXT, - XSUB, - SSA, - MOV_TEXT, - HDMV_PGS_SUBTITLE, - DVB_TELETEXT, - SRT, + // subtitle codecs + DVD_SUBTITLE, + DVB_SUBTITLE, + TEXT, + XSUB, + SSA, + MOV_TEXT, + HDMV_PGS_SUBTITLE, + DVB_TELETEXT, + SRT, - MICRODVD, - EIA_608, - JACOSUB, - SAMI, - REALTEXT, - STL, - SUBVIEWER1, - SUBVIEWER, - SUBRIP, - WEBVTT, - MPL2, - VPLAYER, - PJS, - ASS, - HDMV_TEXT_SUBTITLE, + MICRODVD, + EIA_608, + JACOSUB, + SAMI, + REALTEXT, + STL, + SUBVIEWER1, + SUBVIEWER, + SUBRIP, + WEBVTT, + MPL2, + VPLAYER, + PJS, + ASS, + HDMV_TEXT_SUBTITLE, - // other specific kind of codecs (generally used for attachments) - TTF, + // other specific kind of codecs (generally used for attachments) + TTF, - SCTE_35, - BINTEXT, - XBIN, - IDF, - OTF, - SMPTE_KLV, - DVD_NAV, - TIMED_ID3, - BIN_DATA, + SCTE_35, + BINTEXT, + XBIN, + IDF, + OTF, + SMPTE_KLV, + DVD_NAV, + TIMED_ID3, + BIN_DATA, - PROBE, + PROBE, - MPEG2TS, - MPEG4SYSTEMS, - FFMETADATA, - WRAPPED_AVFRAME, + MPEG2TS, + MPEG4SYSTEMS, + FFMETADATA, + WRAPPED_AVFRAME, - PSD, - PIXLET, - SPEEDHQ, - CLEARVIDEO, - FMVC, - SCPR, - XPM, - AV1, - PCM_F16LE, - PCM_F24LE, - ATRAC3AL, - ATRAC3PAL, + PSD, + PIXLET, + SPEEDHQ, + CLEARVIDEO, + FMVC, + SCPR, + XPM, + AV1, + PCM_F16LE, + PCM_F24LE, + ATRAC3AL, + ATRAC3PAL, - BITPACKED, - MSCC, - SRGC, - SVG, - GDV, - FITS, - GREMLIN_DPCM, - DOLBY_E, + BITPACKED, + MSCC, + SRGC, + SVG, + GDV, + FITS, + GREMLIN_DPCM, + DOLBY_E, } impl Id { - pub fn medium(&self) -> media::Type { - unsafe { - media::Type::from(avcodec_get_type((*self).into())) - } - } + pub fn medium(&self) -> media::Type { + unsafe { media::Type::from(avcodec_get_type((*self).into())) } + } - pub fn name(&self) -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avcodec_get_name((*self).into())).to_bytes()) - } - } + pub fn name(&self) -> &'static str { + unsafe { from_utf8_unchecked(CStr::from_ptr(avcodec_get_name((*self).into())).to_bytes()) } + } } impl From for Id { - fn from(value: AVCodecID) -> Self { - match value { - AV_CODEC_ID_NONE => Id::None, + fn from(value: AVCodecID) -> Self { + match value { + AV_CODEC_ID_NONE => Id::None, - /* video codecs */ - AV_CODEC_ID_MPEG1VIDEO => Id::MPEG1VIDEO, - AV_CODEC_ID_MPEG2VIDEO => Id::MPEG2VIDEO, - #[cfg(feature = "ff_api_xvmc")] - AV_CODEC_ID_MPEG2VIDEO_XVMC => Id::MPEG2VIDEO_XVMC, - AV_CODEC_ID_H261 => Id::H261, - AV_CODEC_ID_H263 => Id::H263, - AV_CODEC_ID_RV10 => Id::RV10, - AV_CODEC_ID_RV20 => Id::RV20, - AV_CODEC_ID_MJPEG => Id::MJPEG, - AV_CODEC_ID_MJPEGB => Id::MJPEGB, - AV_CODEC_ID_LJPEG => Id::LJPEG, - AV_CODEC_ID_SP5X => Id::SP5X, - AV_CODEC_ID_JPEGLS => Id::JPEGLS, - AV_CODEC_ID_MPEG4 => Id::MPEG4, - AV_CODEC_ID_RAWVIDEO => Id::RAWVIDEO, - AV_CODEC_ID_MSMPEG4V1 => Id::MSMPEG4V1, - AV_CODEC_ID_MSMPEG4V2 => Id::MSMPEG4V2, - AV_CODEC_ID_MSMPEG4V3 => Id::MSMPEG4V3, - AV_CODEC_ID_WMV1 => Id::WMV1, - AV_CODEC_ID_WMV2 => Id::WMV2, - AV_CODEC_ID_H263P => Id::H263P, - AV_CODEC_ID_H263I => Id::H263I, - AV_CODEC_ID_FLV1 => Id::FLV1, - AV_CODEC_ID_SVQ1 => Id::SVQ1, - AV_CODEC_ID_SVQ3 => Id::SVQ3, - AV_CODEC_ID_DVVIDEO => Id::DVVIDEO, - AV_CODEC_ID_HUFFYUV => Id::HUFFYUV, - AV_CODEC_ID_CYUV => Id::CYUV, - AV_CODEC_ID_H264 => Id::H264, - AV_CODEC_ID_INDEO3 => Id::INDEO3, - AV_CODEC_ID_VP3 => Id::VP3, - AV_CODEC_ID_THEORA => Id::THEORA, - AV_CODEC_ID_ASV1 => Id::ASV1, - AV_CODEC_ID_ASV2 => Id::ASV2, - AV_CODEC_ID_FFV1 => Id::FFV1, - AV_CODEC_ID_4XM => Id::XM4, - AV_CODEC_ID_VCR1 => Id::VCR1, - AV_CODEC_ID_CLJR => Id::CLJR, - AV_CODEC_ID_MDEC => Id::MDEC, - AV_CODEC_ID_ROQ => Id::ROQ, - AV_CODEC_ID_INTERPLAY_VIDEO => Id::INTERPLAY_VIDEO, - AV_CODEC_ID_XAN_WC3 => Id::XAN_WC3, - AV_CODEC_ID_XAN_WC4 => Id::XAN_WC4, - AV_CODEC_ID_RPZA => Id::RPZA, - AV_CODEC_ID_CINEPAK => Id::CINEPAK, - AV_CODEC_ID_WS_VQA => Id::WS_VQA, - AV_CODEC_ID_MSRLE => Id::MSRLE, - AV_CODEC_ID_MSVIDEO1 => Id::MSVIDEO1, - AV_CODEC_ID_IDCIN => Id::IDCIN, - AV_CODEC_ID_8BPS => Id::BPS8, - AV_CODEC_ID_SMC => Id::SMC, - AV_CODEC_ID_FLIC => Id::FLIC, - AV_CODEC_ID_TRUEMOTION1 => Id::TRUEMOTION1, - AV_CODEC_ID_VMDVIDEO => Id::VMDVIDEO, - AV_CODEC_ID_MSZH => Id::MSZH, - AV_CODEC_ID_ZLIB => Id::ZLIB, - AV_CODEC_ID_QTRLE => Id::QTRLE, - AV_CODEC_ID_TSCC => Id::TSCC, - AV_CODEC_ID_ULTI => Id::ULTI, - AV_CODEC_ID_QDRAW => Id::QDRAW, - AV_CODEC_ID_VIXL => Id::VIXL, - AV_CODEC_ID_QPEG => Id::QPEG, - AV_CODEC_ID_PNG => Id::PNG, - AV_CODEC_ID_PPM => Id::PPM, - AV_CODEC_ID_PBM => Id::PBM, - AV_CODEC_ID_PGM => Id::PGM, - AV_CODEC_ID_PGMYUV => Id::PGMYUV, - AV_CODEC_ID_PAM => Id::PAM, - AV_CODEC_ID_FFVHUFF => Id::FFVHUFF, - AV_CODEC_ID_RV30 => Id::RV30, - AV_CODEC_ID_RV40 => Id::RV40, - AV_CODEC_ID_VC1 => Id::VC1, - AV_CODEC_ID_WMV3 => Id::WMV3, - AV_CODEC_ID_LOCO => Id::LOCO, - AV_CODEC_ID_WNV1 => Id::WNV1, - AV_CODEC_ID_AASC => Id::AASC, - AV_CODEC_ID_INDEO2 => Id::INDEO2, - AV_CODEC_ID_FRAPS => Id::FRAPS, - AV_CODEC_ID_TRUEMOTION2 => Id::TRUEMOTION2, - AV_CODEC_ID_BMP => Id::BMP, - AV_CODEC_ID_CSCD => Id::CSCD, - AV_CODEC_ID_MMVIDEO => Id::MMVIDEO, - AV_CODEC_ID_ZMBV => Id::ZMBV, - AV_CODEC_ID_AVS => Id::AVS, - AV_CODEC_ID_SMACKVIDEO => Id::SMACKVIDEO, - AV_CODEC_ID_NUV => Id::NUV, - AV_CODEC_ID_KMVC => Id::KMVC, - AV_CODEC_ID_FLASHSV => Id::FLASHSV, - AV_CODEC_ID_CAVS => Id::CAVS, - AV_CODEC_ID_JPEG2000 => Id::JPEG2000, - AV_CODEC_ID_VMNC => Id::VMNC, - AV_CODEC_ID_VP5 => Id::VP5, - AV_CODEC_ID_VP6 => Id::VP6, - AV_CODEC_ID_VP6F => Id::VP6F, - AV_CODEC_ID_TARGA => Id::TARGA, - AV_CODEC_ID_DSICINVIDEO => Id::DSICINVIDEO, - AV_CODEC_ID_TIERTEXSEQVIDEO => Id::TIERTEXSEQVIDEO, - AV_CODEC_ID_TIFF => Id::TIFF, - AV_CODEC_ID_GIF => Id::GIF, - AV_CODEC_ID_DXA => Id::DXA, - AV_CODEC_ID_DNXHD => Id::DNXHD, - AV_CODEC_ID_THP => Id::THP, - AV_CODEC_ID_SGI => Id::SGI, - AV_CODEC_ID_C93 => Id::C93, - AV_CODEC_ID_BETHSOFTVID => Id::BETHSOFTVID, - AV_CODEC_ID_PTX => Id::PTX, - AV_CODEC_ID_TXD => Id::TXD, - AV_CODEC_ID_VP6A => Id::VP6A, - AV_CODEC_ID_AMV => Id::AMV, - AV_CODEC_ID_VB => Id::VB, - AV_CODEC_ID_PCX => Id::PCX, - AV_CODEC_ID_SUNRAST => Id::SUNRAST, - AV_CODEC_ID_INDEO4 => Id::INDEO4, - AV_CODEC_ID_INDEO5 => Id::INDEO5, - AV_CODEC_ID_MIMIC => Id::MIMIC, - AV_CODEC_ID_RL2 => Id::RL2, - AV_CODEC_ID_ESCAPE124 => Id::ESCAPE124, - AV_CODEC_ID_DIRAC => Id::DIRAC, - AV_CODEC_ID_BFI => Id::BFI, - AV_CODEC_ID_CMV => Id::CMV, - AV_CODEC_ID_MOTIONPIXELS => Id::MOTIONPIXELS, - AV_CODEC_ID_TGV => Id::TGV, - AV_CODEC_ID_TGQ => Id::TGQ, - AV_CODEC_ID_TQI => Id::TQI, - AV_CODEC_ID_AURA => Id::AURA, - AV_CODEC_ID_AURA2 => Id::AURA2, - AV_CODEC_ID_V210X => Id::V210X, - AV_CODEC_ID_TMV => Id::TMV, - AV_CODEC_ID_V210 => Id::V210, - AV_CODEC_ID_DPX => Id::DPX, - AV_CODEC_ID_MAD => Id::MAD, - AV_CODEC_ID_FRWU => Id::FRWU, - AV_CODEC_ID_FLASHSV2 => Id::FLASHSV2, - AV_CODEC_ID_CDGRAPHICS => Id::CDGRAPHICS, - AV_CODEC_ID_R210 => Id::R210, - AV_CODEC_ID_ANM => Id::ANM, - AV_CODEC_ID_BINKVIDEO => Id::BINKVIDEO, - AV_CODEC_ID_IFF_ILBM => Id::IFF_ILBM, - AV_CODEC_ID_KGV1 => Id::KGV1, - AV_CODEC_ID_YOP => Id::YOP, - AV_CODEC_ID_VP8 => Id::VP8, - AV_CODEC_ID_PICTOR => Id::PICTOR, - AV_CODEC_ID_ANSI => Id::ANSI, - AV_CODEC_ID_A64_MULTI => Id::A64_MULTI, - AV_CODEC_ID_A64_MULTI5 => Id::A64_MULTI5, - AV_CODEC_ID_R10K => Id::R10K, - AV_CODEC_ID_MXPEG => Id::MXPEG, - AV_CODEC_ID_LAGARITH => Id::LAGARITH, - AV_CODEC_ID_PRORES => Id::PRORES, - AV_CODEC_ID_JV => Id::JV, - AV_CODEC_ID_DFA => Id::DFA, - AV_CODEC_ID_WMV3IMAGE => Id::WMV3IMAGE, - AV_CODEC_ID_VC1IMAGE => Id::VC1IMAGE, - AV_CODEC_ID_UTVIDEO => Id::UTVIDEO, - AV_CODEC_ID_BMV_VIDEO => Id::BMV_VIDEO, - AV_CODEC_ID_VBLE => Id::VBLE, - AV_CODEC_ID_DXTORY => Id::DXTORY, - AV_CODEC_ID_V410 => Id::V410, - AV_CODEC_ID_XWD => Id::XWD, - AV_CODEC_ID_CDXL => Id::CDXL, - AV_CODEC_ID_XBM => Id::XBM, - AV_CODEC_ID_ZEROCODEC => Id::ZEROCODEC, - AV_CODEC_ID_MSS1 => Id::MSS1, - AV_CODEC_ID_MSA1 => Id::MSA1, - AV_CODEC_ID_TSCC2 => Id::TSCC2, - AV_CODEC_ID_MTS2 => Id::MTS2, - AV_CODEC_ID_CLLC => Id::CLLC, - AV_CODEC_ID_MSS2 => Id::MSS2, - AV_CODEC_ID_VP9 => Id::VP9, - AV_CODEC_ID_AIC => Id::AIC, - AV_CODEC_ID_ESCAPE130 => Id::ESCAPE130, - AV_CODEC_ID_G2M => Id::G2M, - AV_CODEC_ID_WEBP => Id::WEBP, - AV_CODEC_ID_HNM4_VIDEO => Id::HNM4_VIDEO, - AV_CODEC_ID_HEVC => Id::HEVC, - AV_CODEC_ID_FIC => Id::FIC, - AV_CODEC_ID_ALIAS_PIX => Id::ALIAS_PIX, - AV_CODEC_ID_BRENDER_PIX => Id::BRENDER_PIX, - AV_CODEC_ID_PAF_VIDEO => Id::PAF_VIDEO, - AV_CODEC_ID_EXR => Id::EXR, - AV_CODEC_ID_VP7 => Id::VP7, - AV_CODEC_ID_SANM => Id::SANM, - AV_CODEC_ID_SGIRLE => Id::SGIRLE, - AV_CODEC_ID_MVC1 => Id::MVC1, - AV_CODEC_ID_MVC2 => Id::MVC2, - AV_CODEC_ID_HQX => Id::HQX, - AV_CODEC_ID_TDSC => Id::TDSC, - AV_CODEC_ID_HQ_HQA => Id::HQ_HQA, - AV_CODEC_ID_HAP => Id::HAP, - AV_CODEC_ID_DDS => Id::DDS, - AV_CODEC_ID_DXV => Id::DXV, - AV_CODEC_ID_SCREENPRESSO => Id::SCREENPRESSO, - AV_CODEC_ID_RSCC => Id::RSCC, + /* video codecs */ + AV_CODEC_ID_MPEG1VIDEO => Id::MPEG1VIDEO, + AV_CODEC_ID_MPEG2VIDEO => Id::MPEG2VIDEO, + #[cfg(feature = "ff_api_xvmc")] + AV_CODEC_ID_MPEG2VIDEO_XVMC => Id::MPEG2VIDEO_XVMC, + AV_CODEC_ID_H261 => Id::H261, + AV_CODEC_ID_H263 => Id::H263, + AV_CODEC_ID_RV10 => Id::RV10, + AV_CODEC_ID_RV20 => Id::RV20, + AV_CODEC_ID_MJPEG => Id::MJPEG, + AV_CODEC_ID_MJPEGB => Id::MJPEGB, + AV_CODEC_ID_LJPEG => Id::LJPEG, + AV_CODEC_ID_SP5X => Id::SP5X, + AV_CODEC_ID_JPEGLS => Id::JPEGLS, + AV_CODEC_ID_MPEG4 => Id::MPEG4, + AV_CODEC_ID_RAWVIDEO => Id::RAWVIDEO, + AV_CODEC_ID_MSMPEG4V1 => Id::MSMPEG4V1, + AV_CODEC_ID_MSMPEG4V2 => Id::MSMPEG4V2, + AV_CODEC_ID_MSMPEG4V3 => Id::MSMPEG4V3, + AV_CODEC_ID_WMV1 => Id::WMV1, + AV_CODEC_ID_WMV2 => Id::WMV2, + AV_CODEC_ID_H263P => Id::H263P, + AV_CODEC_ID_H263I => Id::H263I, + AV_CODEC_ID_FLV1 => Id::FLV1, + AV_CODEC_ID_SVQ1 => Id::SVQ1, + AV_CODEC_ID_SVQ3 => Id::SVQ3, + AV_CODEC_ID_DVVIDEO => Id::DVVIDEO, + AV_CODEC_ID_HUFFYUV => Id::HUFFYUV, + AV_CODEC_ID_CYUV => Id::CYUV, + AV_CODEC_ID_H264 => Id::H264, + AV_CODEC_ID_INDEO3 => Id::INDEO3, + AV_CODEC_ID_VP3 => Id::VP3, + AV_CODEC_ID_THEORA => Id::THEORA, + AV_CODEC_ID_ASV1 => Id::ASV1, + AV_CODEC_ID_ASV2 => Id::ASV2, + AV_CODEC_ID_FFV1 => Id::FFV1, + AV_CODEC_ID_4XM => Id::XM4, + AV_CODEC_ID_VCR1 => Id::VCR1, + AV_CODEC_ID_CLJR => Id::CLJR, + AV_CODEC_ID_MDEC => Id::MDEC, + AV_CODEC_ID_ROQ => Id::ROQ, + AV_CODEC_ID_INTERPLAY_VIDEO => Id::INTERPLAY_VIDEO, + AV_CODEC_ID_XAN_WC3 => Id::XAN_WC3, + AV_CODEC_ID_XAN_WC4 => Id::XAN_WC4, + AV_CODEC_ID_RPZA => Id::RPZA, + AV_CODEC_ID_CINEPAK => Id::CINEPAK, + AV_CODEC_ID_WS_VQA => Id::WS_VQA, + AV_CODEC_ID_MSRLE => Id::MSRLE, + AV_CODEC_ID_MSVIDEO1 => Id::MSVIDEO1, + AV_CODEC_ID_IDCIN => Id::IDCIN, + AV_CODEC_ID_8BPS => Id::BPS8, + AV_CODEC_ID_SMC => Id::SMC, + AV_CODEC_ID_FLIC => Id::FLIC, + AV_CODEC_ID_TRUEMOTION1 => Id::TRUEMOTION1, + AV_CODEC_ID_VMDVIDEO => Id::VMDVIDEO, + AV_CODEC_ID_MSZH => Id::MSZH, + AV_CODEC_ID_ZLIB => Id::ZLIB, + AV_CODEC_ID_QTRLE => Id::QTRLE, + AV_CODEC_ID_TSCC => Id::TSCC, + AV_CODEC_ID_ULTI => Id::ULTI, + AV_CODEC_ID_QDRAW => Id::QDRAW, + AV_CODEC_ID_VIXL => Id::VIXL, + AV_CODEC_ID_QPEG => Id::QPEG, + AV_CODEC_ID_PNG => Id::PNG, + AV_CODEC_ID_PPM => Id::PPM, + AV_CODEC_ID_PBM => Id::PBM, + AV_CODEC_ID_PGM => Id::PGM, + AV_CODEC_ID_PGMYUV => Id::PGMYUV, + AV_CODEC_ID_PAM => Id::PAM, + AV_CODEC_ID_FFVHUFF => Id::FFVHUFF, + AV_CODEC_ID_RV30 => Id::RV30, + AV_CODEC_ID_RV40 => Id::RV40, + AV_CODEC_ID_VC1 => Id::VC1, + AV_CODEC_ID_WMV3 => Id::WMV3, + AV_CODEC_ID_LOCO => Id::LOCO, + AV_CODEC_ID_WNV1 => Id::WNV1, + AV_CODEC_ID_AASC => Id::AASC, + AV_CODEC_ID_INDEO2 => Id::INDEO2, + AV_CODEC_ID_FRAPS => Id::FRAPS, + AV_CODEC_ID_TRUEMOTION2 => Id::TRUEMOTION2, + AV_CODEC_ID_BMP => Id::BMP, + AV_CODEC_ID_CSCD => Id::CSCD, + AV_CODEC_ID_MMVIDEO => Id::MMVIDEO, + AV_CODEC_ID_ZMBV => Id::ZMBV, + AV_CODEC_ID_AVS => Id::AVS, + AV_CODEC_ID_SMACKVIDEO => Id::SMACKVIDEO, + AV_CODEC_ID_NUV => Id::NUV, + AV_CODEC_ID_KMVC => Id::KMVC, + AV_CODEC_ID_FLASHSV => Id::FLASHSV, + AV_CODEC_ID_CAVS => Id::CAVS, + AV_CODEC_ID_JPEG2000 => Id::JPEG2000, + AV_CODEC_ID_VMNC => Id::VMNC, + AV_CODEC_ID_VP5 => Id::VP5, + AV_CODEC_ID_VP6 => Id::VP6, + AV_CODEC_ID_VP6F => Id::VP6F, + AV_CODEC_ID_TARGA => Id::TARGA, + AV_CODEC_ID_DSICINVIDEO => Id::DSICINVIDEO, + AV_CODEC_ID_TIERTEXSEQVIDEO => Id::TIERTEXSEQVIDEO, + AV_CODEC_ID_TIFF => Id::TIFF, + AV_CODEC_ID_GIF => Id::GIF, + AV_CODEC_ID_DXA => Id::DXA, + AV_CODEC_ID_DNXHD => Id::DNXHD, + AV_CODEC_ID_THP => Id::THP, + AV_CODEC_ID_SGI => Id::SGI, + AV_CODEC_ID_C93 => Id::C93, + AV_CODEC_ID_BETHSOFTVID => Id::BETHSOFTVID, + AV_CODEC_ID_PTX => Id::PTX, + AV_CODEC_ID_TXD => Id::TXD, + AV_CODEC_ID_VP6A => Id::VP6A, + AV_CODEC_ID_AMV => Id::AMV, + AV_CODEC_ID_VB => Id::VB, + AV_CODEC_ID_PCX => Id::PCX, + AV_CODEC_ID_SUNRAST => Id::SUNRAST, + AV_CODEC_ID_INDEO4 => Id::INDEO4, + AV_CODEC_ID_INDEO5 => Id::INDEO5, + AV_CODEC_ID_MIMIC => Id::MIMIC, + AV_CODEC_ID_RL2 => Id::RL2, + AV_CODEC_ID_ESCAPE124 => Id::ESCAPE124, + AV_CODEC_ID_DIRAC => Id::DIRAC, + AV_CODEC_ID_BFI => Id::BFI, + AV_CODEC_ID_CMV => Id::CMV, + AV_CODEC_ID_MOTIONPIXELS => Id::MOTIONPIXELS, + AV_CODEC_ID_TGV => Id::TGV, + AV_CODEC_ID_TGQ => Id::TGQ, + AV_CODEC_ID_TQI => Id::TQI, + AV_CODEC_ID_AURA => Id::AURA, + AV_CODEC_ID_AURA2 => Id::AURA2, + AV_CODEC_ID_V210X => Id::V210X, + AV_CODEC_ID_TMV => Id::TMV, + AV_CODEC_ID_V210 => Id::V210, + AV_CODEC_ID_DPX => Id::DPX, + AV_CODEC_ID_MAD => Id::MAD, + AV_CODEC_ID_FRWU => Id::FRWU, + AV_CODEC_ID_FLASHSV2 => Id::FLASHSV2, + AV_CODEC_ID_CDGRAPHICS => Id::CDGRAPHICS, + AV_CODEC_ID_R210 => Id::R210, + AV_CODEC_ID_ANM => Id::ANM, + AV_CODEC_ID_BINKVIDEO => Id::BINKVIDEO, + AV_CODEC_ID_IFF_ILBM => Id::IFF_ILBM, + AV_CODEC_ID_KGV1 => Id::KGV1, + AV_CODEC_ID_YOP => Id::YOP, + AV_CODEC_ID_VP8 => Id::VP8, + AV_CODEC_ID_PICTOR => Id::PICTOR, + AV_CODEC_ID_ANSI => Id::ANSI, + AV_CODEC_ID_A64_MULTI => Id::A64_MULTI, + AV_CODEC_ID_A64_MULTI5 => Id::A64_MULTI5, + AV_CODEC_ID_R10K => Id::R10K, + AV_CODEC_ID_MXPEG => Id::MXPEG, + AV_CODEC_ID_LAGARITH => Id::LAGARITH, + AV_CODEC_ID_PRORES => Id::PRORES, + AV_CODEC_ID_JV => Id::JV, + AV_CODEC_ID_DFA => Id::DFA, + AV_CODEC_ID_WMV3IMAGE => Id::WMV3IMAGE, + AV_CODEC_ID_VC1IMAGE => Id::VC1IMAGE, + AV_CODEC_ID_UTVIDEO => Id::UTVIDEO, + AV_CODEC_ID_BMV_VIDEO => Id::BMV_VIDEO, + AV_CODEC_ID_VBLE => Id::VBLE, + AV_CODEC_ID_DXTORY => Id::DXTORY, + AV_CODEC_ID_V410 => Id::V410, + AV_CODEC_ID_XWD => Id::XWD, + AV_CODEC_ID_CDXL => Id::CDXL, + AV_CODEC_ID_XBM => Id::XBM, + AV_CODEC_ID_ZEROCODEC => Id::ZEROCODEC, + AV_CODEC_ID_MSS1 => Id::MSS1, + AV_CODEC_ID_MSA1 => Id::MSA1, + AV_CODEC_ID_TSCC2 => Id::TSCC2, + AV_CODEC_ID_MTS2 => Id::MTS2, + AV_CODEC_ID_CLLC => Id::CLLC, + AV_CODEC_ID_MSS2 => Id::MSS2, + AV_CODEC_ID_VP9 => Id::VP9, + AV_CODEC_ID_AIC => Id::AIC, + AV_CODEC_ID_ESCAPE130 => Id::ESCAPE130, + AV_CODEC_ID_G2M => Id::G2M, + AV_CODEC_ID_WEBP => Id::WEBP, + AV_CODEC_ID_HNM4_VIDEO => Id::HNM4_VIDEO, + AV_CODEC_ID_HEVC => Id::HEVC, + AV_CODEC_ID_FIC => Id::FIC, + AV_CODEC_ID_ALIAS_PIX => Id::ALIAS_PIX, + AV_CODEC_ID_BRENDER_PIX => Id::BRENDER_PIX, + AV_CODEC_ID_PAF_VIDEO => Id::PAF_VIDEO, + AV_CODEC_ID_EXR => Id::EXR, + AV_CODEC_ID_VP7 => Id::VP7, + AV_CODEC_ID_SANM => Id::SANM, + AV_CODEC_ID_SGIRLE => Id::SGIRLE, + AV_CODEC_ID_MVC1 => Id::MVC1, + AV_CODEC_ID_MVC2 => Id::MVC2, + AV_CODEC_ID_HQX => Id::HQX, + AV_CODEC_ID_TDSC => Id::TDSC, + AV_CODEC_ID_HQ_HQA => Id::HQ_HQA, + AV_CODEC_ID_HAP => Id::HAP, + AV_CODEC_ID_DDS => Id::DDS, + AV_CODEC_ID_DXV => Id::DXV, + AV_CODEC_ID_SCREENPRESSO => Id::SCREENPRESSO, + AV_CODEC_ID_RSCC => Id::RSCC, - AV_CODEC_ID_Y41P => Id::Y41P, - AV_CODEC_ID_AVRP => Id::AVRP, - AV_CODEC_ID_012V => Id::V012, - AV_CODEC_ID_AVUI => Id::AVUI, - AV_CODEC_ID_AYUV => Id::AYUV, - AV_CODEC_ID_TARGA_Y216 => Id::TARGA_Y216, - AV_CODEC_ID_V308 => Id::V308, - AV_CODEC_ID_V408 => Id::V408, - AV_CODEC_ID_YUV4 => Id::YUV4, - AV_CODEC_ID_AVRN => Id::AVRN, - AV_CODEC_ID_CPIA => Id::CPIA, - AV_CODEC_ID_XFACE => Id::XFACE, - AV_CODEC_ID_SNOW => Id::SNOW, - AV_CODEC_ID_SMVJPEG => Id::SMVJPEG, - AV_CODEC_ID_APNG => Id::APNG, - AV_CODEC_ID_DAALA => Id::DAALA, - AV_CODEC_ID_CFHD => Id::CFHD, - AV_CODEC_ID_TRUEMOTION2RT => Id::TRUEMOTION2RT, - AV_CODEC_ID_M101 => Id::M101, - AV_CODEC_ID_MAGICYUV => Id::MAGICYUV, - AV_CODEC_ID_SHEERVIDEO => Id::SHEERVIDEO, - AV_CODEC_ID_YLC => Id::YLC, + AV_CODEC_ID_Y41P => Id::Y41P, + AV_CODEC_ID_AVRP => Id::AVRP, + AV_CODEC_ID_012V => Id::V012, + AV_CODEC_ID_AVUI => Id::AVUI, + AV_CODEC_ID_AYUV => Id::AYUV, + AV_CODEC_ID_TARGA_Y216 => Id::TARGA_Y216, + AV_CODEC_ID_V308 => Id::V308, + AV_CODEC_ID_V408 => Id::V408, + AV_CODEC_ID_YUV4 => Id::YUV4, + AV_CODEC_ID_AVRN => Id::AVRN, + AV_CODEC_ID_CPIA => Id::CPIA, + AV_CODEC_ID_XFACE => Id::XFACE, + AV_CODEC_ID_SNOW => Id::SNOW, + AV_CODEC_ID_SMVJPEG => Id::SMVJPEG, + AV_CODEC_ID_APNG => Id::APNG, + AV_CODEC_ID_DAALA => Id::DAALA, + AV_CODEC_ID_CFHD => Id::CFHD, + AV_CODEC_ID_TRUEMOTION2RT => Id::TRUEMOTION2RT, + AV_CODEC_ID_M101 => Id::M101, + AV_CODEC_ID_MAGICYUV => Id::MAGICYUV, + AV_CODEC_ID_SHEERVIDEO => Id::SHEERVIDEO, + AV_CODEC_ID_YLC => Id::YLC, - /* various PCM "codecs" */ - AV_CODEC_ID_PCM_S16LE => Id::PCM_S16LE, - AV_CODEC_ID_PCM_S16BE => Id::PCM_S16BE, - AV_CODEC_ID_PCM_U16LE => Id::PCM_U16LE, - AV_CODEC_ID_PCM_U16BE => Id::PCM_U16BE, - AV_CODEC_ID_PCM_S8 => Id::PCM_S8, - AV_CODEC_ID_PCM_U8 => Id::PCM_U8, - AV_CODEC_ID_PCM_MULAW => Id::PCM_MULAW, - AV_CODEC_ID_PCM_ALAW => Id::PCM_ALAW, - AV_CODEC_ID_PCM_S32LE => Id::PCM_S32LE, - AV_CODEC_ID_PCM_S32BE => Id::PCM_S32BE, - AV_CODEC_ID_PCM_U32LE => Id::PCM_U32LE, - AV_CODEC_ID_PCM_U32BE => Id::PCM_U32BE, - AV_CODEC_ID_PCM_S24LE => Id::PCM_S24LE, - AV_CODEC_ID_PCM_S24BE => Id::PCM_S24BE, - AV_CODEC_ID_PCM_U24LE => Id::PCM_U24LE, - AV_CODEC_ID_PCM_U24BE => Id::PCM_U24BE, - AV_CODEC_ID_PCM_S24DAUD => Id::PCM_S24DAUD, - AV_CODEC_ID_PCM_ZORK => Id::PCM_ZORK, - AV_CODEC_ID_PCM_S16LE_PLANAR => Id::PCM_S16LE_PLANAR, - AV_CODEC_ID_PCM_DVD => Id::PCM_DVD, - AV_CODEC_ID_PCM_F32BE => Id::PCM_F32BE, - AV_CODEC_ID_PCM_F32LE => Id::PCM_F32LE, - AV_CODEC_ID_PCM_F64BE => Id::PCM_F64BE, - AV_CODEC_ID_PCM_F64LE => Id::PCM_F64LE, - AV_CODEC_ID_PCM_BLURAY => Id::PCM_BLURAY, - AV_CODEC_ID_PCM_LXF => Id::PCM_LXF, - AV_CODEC_ID_S302M => Id::S302M, - AV_CODEC_ID_PCM_S8_PLANAR => Id::PCM_S8_PLANAR, - AV_CODEC_ID_PCM_S24LE_PLANAR => Id::PCM_S24LE_PLANAR, - AV_CODEC_ID_PCM_S32LE_PLANAR => Id::PCM_S32LE_PLANAR, - AV_CODEC_ID_PCM_S16BE_PLANAR => Id::PCM_S16BE_PLANAR, + /* various PCM "codecs" */ + AV_CODEC_ID_PCM_S16LE => Id::PCM_S16LE, + AV_CODEC_ID_PCM_S16BE => Id::PCM_S16BE, + AV_CODEC_ID_PCM_U16LE => Id::PCM_U16LE, + AV_CODEC_ID_PCM_U16BE => Id::PCM_U16BE, + AV_CODEC_ID_PCM_S8 => Id::PCM_S8, + AV_CODEC_ID_PCM_U8 => Id::PCM_U8, + AV_CODEC_ID_PCM_MULAW => Id::PCM_MULAW, + AV_CODEC_ID_PCM_ALAW => Id::PCM_ALAW, + AV_CODEC_ID_PCM_S32LE => Id::PCM_S32LE, + AV_CODEC_ID_PCM_S32BE => Id::PCM_S32BE, + AV_CODEC_ID_PCM_U32LE => Id::PCM_U32LE, + AV_CODEC_ID_PCM_U32BE => Id::PCM_U32BE, + AV_CODEC_ID_PCM_S24LE => Id::PCM_S24LE, + AV_CODEC_ID_PCM_S24BE => Id::PCM_S24BE, + AV_CODEC_ID_PCM_U24LE => Id::PCM_U24LE, + AV_CODEC_ID_PCM_U24BE => Id::PCM_U24BE, + AV_CODEC_ID_PCM_S24DAUD => Id::PCM_S24DAUD, + AV_CODEC_ID_PCM_ZORK => Id::PCM_ZORK, + AV_CODEC_ID_PCM_S16LE_PLANAR => Id::PCM_S16LE_PLANAR, + AV_CODEC_ID_PCM_DVD => Id::PCM_DVD, + AV_CODEC_ID_PCM_F32BE => Id::PCM_F32BE, + AV_CODEC_ID_PCM_F32LE => Id::PCM_F32LE, + AV_CODEC_ID_PCM_F64BE => Id::PCM_F64BE, + AV_CODEC_ID_PCM_F64LE => Id::PCM_F64LE, + AV_CODEC_ID_PCM_BLURAY => Id::PCM_BLURAY, + AV_CODEC_ID_PCM_LXF => Id::PCM_LXF, + AV_CODEC_ID_S302M => Id::S302M, + AV_CODEC_ID_PCM_S8_PLANAR => Id::PCM_S8_PLANAR, + AV_CODEC_ID_PCM_S24LE_PLANAR => Id::PCM_S24LE_PLANAR, + AV_CODEC_ID_PCM_S32LE_PLANAR => Id::PCM_S32LE_PLANAR, + AV_CODEC_ID_PCM_S16BE_PLANAR => Id::PCM_S16BE_PLANAR, - AV_CODEC_ID_PCM_S64LE => Id::PCM_S64LE, - AV_CODEC_ID_PCM_S64BE => Id::PCM_S64BE, + AV_CODEC_ID_PCM_S64LE => Id::PCM_S64LE, + AV_CODEC_ID_PCM_S64BE => Id::PCM_S64BE, - /* various ADPCM codecs */ - AV_CODEC_ID_ADPCM_IMA_QT => Id::ADPCM_IMA_QT, - AV_CODEC_ID_ADPCM_IMA_WAV => Id::ADPCM_IMA_WAV, - AV_CODEC_ID_ADPCM_IMA_DK3 => Id::ADPCM_IMA_DK3, - AV_CODEC_ID_ADPCM_IMA_DK4 => Id::ADPCM_IMA_DK4, - AV_CODEC_ID_ADPCM_IMA_WS => Id::ADPCM_IMA_WS, - AV_CODEC_ID_ADPCM_IMA_SMJPEG => Id::ADPCM_IMA_SMJPEG, - AV_CODEC_ID_ADPCM_MS => Id::ADPCM_MS, - AV_CODEC_ID_ADPCM_4XM => Id::ADPCM_4XM, - AV_CODEC_ID_ADPCM_XA => Id::ADPCM_XA, - AV_CODEC_ID_ADPCM_ADX => Id::ADPCM_ADX, - AV_CODEC_ID_ADPCM_EA => Id::ADPCM_EA, - AV_CODEC_ID_ADPCM_G726 => Id::ADPCM_G726, - AV_CODEC_ID_ADPCM_CT => Id::ADPCM_CT, - AV_CODEC_ID_ADPCM_SWF => Id::ADPCM_SWF, - AV_CODEC_ID_ADPCM_YAMAHA => Id::ADPCM_YAMAHA, - AV_CODEC_ID_ADPCM_SBPRO_4 => Id::ADPCM_SBPRO_4, - AV_CODEC_ID_ADPCM_SBPRO_3 => Id::ADPCM_SBPRO_3, - AV_CODEC_ID_ADPCM_SBPRO_2 => Id::ADPCM_SBPRO_2, - AV_CODEC_ID_ADPCM_THP => Id::ADPCM_THP, - AV_CODEC_ID_ADPCM_IMA_AMV => Id::ADPCM_IMA_AMV, - AV_CODEC_ID_ADPCM_EA_R1 => Id::ADPCM_EA_R1, - AV_CODEC_ID_ADPCM_EA_R3 => Id::ADPCM_EA_R3, - AV_CODEC_ID_ADPCM_EA_R2 => Id::ADPCM_EA_R2, - AV_CODEC_ID_ADPCM_IMA_EA_SEAD => Id::ADPCM_IMA_EA_SEAD, - AV_CODEC_ID_ADPCM_IMA_EA_EACS => Id::ADPCM_IMA_EA_EACS, - AV_CODEC_ID_ADPCM_EA_XAS => Id::ADPCM_EA_XAS, - AV_CODEC_ID_ADPCM_EA_MAXIS_XA => Id::ADPCM_EA_MAXIS_XA, - AV_CODEC_ID_ADPCM_IMA_ISS => Id::ADPCM_IMA_ISS, - AV_CODEC_ID_ADPCM_G722 => Id::ADPCM_G722, - AV_CODEC_ID_ADPCM_IMA_APC => Id::ADPCM_IMA_APC, - AV_CODEC_ID_ADPCM_VIMA => Id::ADPCM_VIMA, + /* various ADPCM codecs */ + AV_CODEC_ID_ADPCM_IMA_QT => Id::ADPCM_IMA_QT, + AV_CODEC_ID_ADPCM_IMA_WAV => Id::ADPCM_IMA_WAV, + AV_CODEC_ID_ADPCM_IMA_DK3 => Id::ADPCM_IMA_DK3, + AV_CODEC_ID_ADPCM_IMA_DK4 => Id::ADPCM_IMA_DK4, + AV_CODEC_ID_ADPCM_IMA_WS => Id::ADPCM_IMA_WS, + AV_CODEC_ID_ADPCM_IMA_SMJPEG => Id::ADPCM_IMA_SMJPEG, + AV_CODEC_ID_ADPCM_MS => Id::ADPCM_MS, + AV_CODEC_ID_ADPCM_4XM => Id::ADPCM_4XM, + AV_CODEC_ID_ADPCM_XA => Id::ADPCM_XA, + AV_CODEC_ID_ADPCM_ADX => Id::ADPCM_ADX, + AV_CODEC_ID_ADPCM_EA => Id::ADPCM_EA, + AV_CODEC_ID_ADPCM_G726 => Id::ADPCM_G726, + AV_CODEC_ID_ADPCM_CT => Id::ADPCM_CT, + AV_CODEC_ID_ADPCM_SWF => Id::ADPCM_SWF, + AV_CODEC_ID_ADPCM_YAMAHA => Id::ADPCM_YAMAHA, + AV_CODEC_ID_ADPCM_SBPRO_4 => Id::ADPCM_SBPRO_4, + AV_CODEC_ID_ADPCM_SBPRO_3 => Id::ADPCM_SBPRO_3, + AV_CODEC_ID_ADPCM_SBPRO_2 => Id::ADPCM_SBPRO_2, + AV_CODEC_ID_ADPCM_THP => Id::ADPCM_THP, + AV_CODEC_ID_ADPCM_IMA_AMV => Id::ADPCM_IMA_AMV, + AV_CODEC_ID_ADPCM_EA_R1 => Id::ADPCM_EA_R1, + AV_CODEC_ID_ADPCM_EA_R3 => Id::ADPCM_EA_R3, + AV_CODEC_ID_ADPCM_EA_R2 => Id::ADPCM_EA_R2, + AV_CODEC_ID_ADPCM_IMA_EA_SEAD => Id::ADPCM_IMA_EA_SEAD, + AV_CODEC_ID_ADPCM_IMA_EA_EACS => Id::ADPCM_IMA_EA_EACS, + AV_CODEC_ID_ADPCM_EA_XAS => Id::ADPCM_EA_XAS, + AV_CODEC_ID_ADPCM_EA_MAXIS_XA => Id::ADPCM_EA_MAXIS_XA, + AV_CODEC_ID_ADPCM_IMA_ISS => Id::ADPCM_IMA_ISS, + AV_CODEC_ID_ADPCM_G722 => Id::ADPCM_G722, + AV_CODEC_ID_ADPCM_IMA_APC => Id::ADPCM_IMA_APC, + AV_CODEC_ID_ADPCM_VIMA => Id::ADPCM_VIMA, - AV_CODEC_ID_ADPCM_AFC => Id::ADPCM_AFC, - AV_CODEC_ID_ADPCM_IMA_OKI => Id::ADPCM_IMA_OKI, - AV_CODEC_ID_ADPCM_DTK => Id::ADPCM_DTK, - AV_CODEC_ID_ADPCM_IMA_RAD => Id::ADPCM_IMA_RAD, - AV_CODEC_ID_ADPCM_G726LE => Id::ADPCM_G726LE, - AV_CODEC_ID_ADPCM_THP_LE => Id::ADPCM_THP_LE, - AV_CODEC_ID_ADPCM_PSX => Id::ADPCM_PSX, - AV_CODEC_ID_ADPCM_AICA => Id::ADPCM_AICA, - AV_CODEC_ID_ADPCM_IMA_DAT4 => Id::ADPCM_IMA_DAT4, - AV_CODEC_ID_ADPCM_MTAF => Id::ADPCM_MTAF, + AV_CODEC_ID_ADPCM_AFC => Id::ADPCM_AFC, + AV_CODEC_ID_ADPCM_IMA_OKI => Id::ADPCM_IMA_OKI, + AV_CODEC_ID_ADPCM_DTK => Id::ADPCM_DTK, + AV_CODEC_ID_ADPCM_IMA_RAD => Id::ADPCM_IMA_RAD, + AV_CODEC_ID_ADPCM_G726LE => Id::ADPCM_G726LE, + AV_CODEC_ID_ADPCM_THP_LE => Id::ADPCM_THP_LE, + AV_CODEC_ID_ADPCM_PSX => Id::ADPCM_PSX, + AV_CODEC_ID_ADPCM_AICA => Id::ADPCM_AICA, + AV_CODEC_ID_ADPCM_IMA_DAT4 => Id::ADPCM_IMA_DAT4, + AV_CODEC_ID_ADPCM_MTAF => Id::ADPCM_MTAF, - /* AMR */ - AV_CODEC_ID_AMR_NB => Id::AMR_NB, - AV_CODEC_ID_AMR_WB => Id::AMR_WB, + /* AMR */ + AV_CODEC_ID_AMR_NB => Id::AMR_NB, + AV_CODEC_ID_AMR_WB => Id::AMR_WB, - /* RealAudio codecs*/ - AV_CODEC_ID_RA_144 => Id::RA_144, - AV_CODEC_ID_RA_288 => Id::RA_288, + /* RealAudio codecs*/ + AV_CODEC_ID_RA_144 => Id::RA_144, + AV_CODEC_ID_RA_288 => Id::RA_288, - /* various DPCM codecs */ - AV_CODEC_ID_ROQ_DPCM => Id::ROQ_DPCM, - AV_CODEC_ID_INTERPLAY_DPCM => Id::INTERPLAY_DPCM, - AV_CODEC_ID_XAN_DPCM => Id::XAN_DPCM, - AV_CODEC_ID_SOL_DPCM => Id::SOL_DPCM, + /* various DPCM codecs */ + AV_CODEC_ID_ROQ_DPCM => Id::ROQ_DPCM, + AV_CODEC_ID_INTERPLAY_DPCM => Id::INTERPLAY_DPCM, + AV_CODEC_ID_XAN_DPCM => Id::XAN_DPCM, + AV_CODEC_ID_SOL_DPCM => Id::SOL_DPCM, - AV_CODEC_ID_SDX2_DPCM => Id::SDX2_DPCM, + AV_CODEC_ID_SDX2_DPCM => Id::SDX2_DPCM, - /* audio codecs */ - AV_CODEC_ID_MP2 => Id::MP2, - AV_CODEC_ID_MP3 => Id::MP3, - AV_CODEC_ID_AAC => Id::AAC, - AV_CODEC_ID_AC3 => Id::AC3, - AV_CODEC_ID_DTS => Id::DTS, - AV_CODEC_ID_VORBIS => Id::VORBIS, - AV_CODEC_ID_DVAUDIO => Id::DVAUDIO, - AV_CODEC_ID_WMAV1 => Id::WMAV1, - AV_CODEC_ID_WMAV2 => Id::WMAV2, - AV_CODEC_ID_MACE3 => Id::MACE3, - AV_CODEC_ID_MACE6 => Id::MACE6, - AV_CODEC_ID_VMDAUDIO => Id::VMDAUDIO, - AV_CODEC_ID_FLAC => Id::FLAC, - AV_CODEC_ID_MP3ADU => Id::MP3ADU, - AV_CODEC_ID_MP3ON4 => Id::MP3ON4, - AV_CODEC_ID_SHORTEN => Id::SHORTEN, - AV_CODEC_ID_ALAC => Id::ALAC, - AV_CODEC_ID_WESTWOOD_SND1 => Id::WESTWOOD_SND1, - AV_CODEC_ID_GSM => Id::GSM, - AV_CODEC_ID_QDM2 => Id::QDM2, - AV_CODEC_ID_COOK => Id::COOK, - AV_CODEC_ID_TRUESPEECH => Id::TRUESPEECH, - AV_CODEC_ID_TTA => Id::TTA, - AV_CODEC_ID_SMACKAUDIO => Id::SMACKAUDIO, - AV_CODEC_ID_QCELP => Id::QCELP, - AV_CODEC_ID_WAVPACK => Id::WAVPACK, - AV_CODEC_ID_DSICINAUDIO => Id::DSICINAUDIO, - AV_CODEC_ID_IMC => Id::IMC, - AV_CODEC_ID_MUSEPACK7 => Id::MUSEPACK7, - AV_CODEC_ID_MLP => Id::MLP, - AV_CODEC_ID_GSM_MS => Id::GSM_MS, - AV_CODEC_ID_ATRAC3 => Id::ATRAC3, - #[cfg(feature = "ff_api_voxware")] - AV_CODEC_ID_VOXWARE => Id::VOXWARE, - AV_CODEC_ID_APE => Id::APE, - AV_CODEC_ID_NELLYMOSER => Id::NELLYMOSER, - AV_CODEC_ID_MUSEPACK8 => Id::MUSEPACK8, - AV_CODEC_ID_SPEEX => Id::SPEEX, - AV_CODEC_ID_WMAVOICE => Id::WMAVOICE, - AV_CODEC_ID_WMAPRO => Id::WMAPRO, - AV_CODEC_ID_WMALOSSLESS => Id::WMALOSSLESS, - AV_CODEC_ID_ATRAC3P => Id::ATRAC3P, - AV_CODEC_ID_EAC3 => Id::EAC3, - AV_CODEC_ID_SIPR => Id::SIPR, - AV_CODEC_ID_MP1 => Id::MP1, - AV_CODEC_ID_TWINVQ => Id::TWINVQ, - AV_CODEC_ID_TRUEHD => Id::TRUEHD, - AV_CODEC_ID_MP4ALS => Id::MP4ALS, - AV_CODEC_ID_ATRAC1 => Id::ATRAC1, - AV_CODEC_ID_BINKAUDIO_RDFT => Id::BINKAUDIO_RDFT, - AV_CODEC_ID_BINKAUDIO_DCT => Id::BINKAUDIO_DCT, - AV_CODEC_ID_AAC_LATM => Id::AAC_LATM, - AV_CODEC_ID_QDMC => Id::QDMC, - AV_CODEC_ID_CELT => Id::CELT, - AV_CODEC_ID_G723_1 => Id::G723_1, - AV_CODEC_ID_G729 => Id::G729, - AV_CODEC_ID_8SVX_EXP => Id::SVX_EXP8, - AV_CODEC_ID_8SVX_FIB => Id::SVX_FIB8, - AV_CODEC_ID_BMV_AUDIO => Id::BMV_AUDIO, - AV_CODEC_ID_RALF => Id::RALF, - AV_CODEC_ID_IAC => Id::IAC, - AV_CODEC_ID_ILBC => Id::ILBC, - AV_CODEC_ID_OPUS => Id::OPUS, - AV_CODEC_ID_COMFORT_NOISE => Id::COMFORT_NOISE, - AV_CODEC_ID_TAK => Id::TAK, - AV_CODEC_ID_METASOUND => Id::METASOUND, - AV_CODEC_ID_PAF_AUDIO => Id::PAF_AUDIO, - AV_CODEC_ID_ON2AVC => Id::ON2AVC, - AV_CODEC_ID_DSS_SP => Id::DSS_SP, + /* audio codecs */ + AV_CODEC_ID_MP2 => Id::MP2, + AV_CODEC_ID_MP3 => Id::MP3, + AV_CODEC_ID_AAC => Id::AAC, + AV_CODEC_ID_AC3 => Id::AC3, + AV_CODEC_ID_DTS => Id::DTS, + AV_CODEC_ID_VORBIS => Id::VORBIS, + AV_CODEC_ID_DVAUDIO => Id::DVAUDIO, + AV_CODEC_ID_WMAV1 => Id::WMAV1, + AV_CODEC_ID_WMAV2 => Id::WMAV2, + AV_CODEC_ID_MACE3 => Id::MACE3, + AV_CODEC_ID_MACE6 => Id::MACE6, + AV_CODEC_ID_VMDAUDIO => Id::VMDAUDIO, + AV_CODEC_ID_FLAC => Id::FLAC, + AV_CODEC_ID_MP3ADU => Id::MP3ADU, + AV_CODEC_ID_MP3ON4 => Id::MP3ON4, + AV_CODEC_ID_SHORTEN => Id::SHORTEN, + AV_CODEC_ID_ALAC => Id::ALAC, + AV_CODEC_ID_WESTWOOD_SND1 => Id::WESTWOOD_SND1, + AV_CODEC_ID_GSM => Id::GSM, + AV_CODEC_ID_QDM2 => Id::QDM2, + AV_CODEC_ID_COOK => Id::COOK, + AV_CODEC_ID_TRUESPEECH => Id::TRUESPEECH, + AV_CODEC_ID_TTA => Id::TTA, + AV_CODEC_ID_SMACKAUDIO => Id::SMACKAUDIO, + AV_CODEC_ID_QCELP => Id::QCELP, + AV_CODEC_ID_WAVPACK => Id::WAVPACK, + AV_CODEC_ID_DSICINAUDIO => Id::DSICINAUDIO, + AV_CODEC_ID_IMC => Id::IMC, + AV_CODEC_ID_MUSEPACK7 => Id::MUSEPACK7, + AV_CODEC_ID_MLP => Id::MLP, + AV_CODEC_ID_GSM_MS => Id::GSM_MS, + AV_CODEC_ID_ATRAC3 => Id::ATRAC3, + #[cfg(feature = "ff_api_voxware")] + AV_CODEC_ID_VOXWARE => Id::VOXWARE, + AV_CODEC_ID_APE => Id::APE, + AV_CODEC_ID_NELLYMOSER => Id::NELLYMOSER, + AV_CODEC_ID_MUSEPACK8 => Id::MUSEPACK8, + AV_CODEC_ID_SPEEX => Id::SPEEX, + AV_CODEC_ID_WMAVOICE => Id::WMAVOICE, + AV_CODEC_ID_WMAPRO => Id::WMAPRO, + AV_CODEC_ID_WMALOSSLESS => Id::WMALOSSLESS, + AV_CODEC_ID_ATRAC3P => Id::ATRAC3P, + AV_CODEC_ID_EAC3 => Id::EAC3, + AV_CODEC_ID_SIPR => Id::SIPR, + AV_CODEC_ID_MP1 => Id::MP1, + AV_CODEC_ID_TWINVQ => Id::TWINVQ, + AV_CODEC_ID_TRUEHD => Id::TRUEHD, + AV_CODEC_ID_MP4ALS => Id::MP4ALS, + AV_CODEC_ID_ATRAC1 => Id::ATRAC1, + AV_CODEC_ID_BINKAUDIO_RDFT => Id::BINKAUDIO_RDFT, + AV_CODEC_ID_BINKAUDIO_DCT => Id::BINKAUDIO_DCT, + AV_CODEC_ID_AAC_LATM => Id::AAC_LATM, + AV_CODEC_ID_QDMC => Id::QDMC, + AV_CODEC_ID_CELT => Id::CELT, + AV_CODEC_ID_G723_1 => Id::G723_1, + AV_CODEC_ID_G729 => Id::G729, + AV_CODEC_ID_8SVX_EXP => Id::SVX_EXP8, + AV_CODEC_ID_8SVX_FIB => Id::SVX_FIB8, + AV_CODEC_ID_BMV_AUDIO => Id::BMV_AUDIO, + AV_CODEC_ID_RALF => Id::RALF, + AV_CODEC_ID_IAC => Id::IAC, + AV_CODEC_ID_ILBC => Id::ILBC, + AV_CODEC_ID_OPUS => Id::OPUS, + AV_CODEC_ID_COMFORT_NOISE => Id::COMFORT_NOISE, + AV_CODEC_ID_TAK => Id::TAK, + AV_CODEC_ID_METASOUND => Id::METASOUND, + AV_CODEC_ID_PAF_AUDIO => Id::PAF_AUDIO, + AV_CODEC_ID_ON2AVC => Id::ON2AVC, + AV_CODEC_ID_DSS_SP => Id::DSS_SP, - AV_CODEC_ID_FFWAVESYNTH => Id::FFWAVESYNTH, - AV_CODEC_ID_SONIC => Id::SONIC, - AV_CODEC_ID_SONIC_LS => Id::SONIC_LS, - AV_CODEC_ID_EVRC => Id::EVRC, - AV_CODEC_ID_SMV => Id::SMV, - AV_CODEC_ID_DSD_LSBF => Id::DSD_LSBF, - AV_CODEC_ID_DSD_MSBF => Id::DSD_MSBF, - AV_CODEC_ID_DSD_LSBF_PLANAR => Id::DSD_LSBF_PLANAR, - AV_CODEC_ID_DSD_MSBF_PLANAR => Id::DSD_MSBF_PLANAR, - AV_CODEC_ID_4GV => Id::_4GV, - AV_CODEC_ID_INTERPLAY_ACM => Id::INTERPLAY_ACM, - AV_CODEC_ID_XMA1 => Id::XMA1, - AV_CODEC_ID_XMA2 => Id::XMA2, - AV_CODEC_ID_DST => Id::DST, + AV_CODEC_ID_FFWAVESYNTH => Id::FFWAVESYNTH, + AV_CODEC_ID_SONIC => Id::SONIC, + AV_CODEC_ID_SONIC_LS => Id::SONIC_LS, + AV_CODEC_ID_EVRC => Id::EVRC, + AV_CODEC_ID_SMV => Id::SMV, + AV_CODEC_ID_DSD_LSBF => Id::DSD_LSBF, + AV_CODEC_ID_DSD_MSBF => Id::DSD_MSBF, + AV_CODEC_ID_DSD_LSBF_PLANAR => Id::DSD_LSBF_PLANAR, + AV_CODEC_ID_DSD_MSBF_PLANAR => Id::DSD_MSBF_PLANAR, + AV_CODEC_ID_4GV => Id::_4GV, + AV_CODEC_ID_INTERPLAY_ACM => Id::INTERPLAY_ACM, + AV_CODEC_ID_XMA1 => Id::XMA1, + AV_CODEC_ID_XMA2 => Id::XMA2, + AV_CODEC_ID_DST => Id::DST, - /* subtitle codecs */ - AV_CODEC_ID_DVD_SUBTITLE => Id::DVD_SUBTITLE, - AV_CODEC_ID_DVB_SUBTITLE => Id::DVB_SUBTITLE, - AV_CODEC_ID_TEXT => Id::TEXT, - AV_CODEC_ID_XSUB => Id::XSUB, - AV_CODEC_ID_SSA => Id::SSA, - AV_CODEC_ID_MOV_TEXT => Id::MOV_TEXT, - AV_CODEC_ID_HDMV_PGS_SUBTITLE => Id::HDMV_PGS_SUBTITLE, - AV_CODEC_ID_DVB_TELETEXT => Id::DVB_TELETEXT, - AV_CODEC_ID_SRT => Id::SRT, + /* subtitle codecs */ + AV_CODEC_ID_DVD_SUBTITLE => Id::DVD_SUBTITLE, + AV_CODEC_ID_DVB_SUBTITLE => Id::DVB_SUBTITLE, + AV_CODEC_ID_TEXT => Id::TEXT, + AV_CODEC_ID_XSUB => Id::XSUB, + AV_CODEC_ID_SSA => Id::SSA, + AV_CODEC_ID_MOV_TEXT => Id::MOV_TEXT, + AV_CODEC_ID_HDMV_PGS_SUBTITLE => Id::HDMV_PGS_SUBTITLE, + AV_CODEC_ID_DVB_TELETEXT => Id::DVB_TELETEXT, + AV_CODEC_ID_SRT => Id::SRT, - AV_CODEC_ID_MICRODVD => Id::MICRODVD, - AV_CODEC_ID_EIA_608 => Id::EIA_608, - AV_CODEC_ID_JACOSUB => Id::JACOSUB, - AV_CODEC_ID_SAMI => Id::SAMI, - AV_CODEC_ID_REALTEXT => Id::REALTEXT, - AV_CODEC_ID_STL => Id::STL, - AV_CODEC_ID_SUBVIEWER1 => Id::SUBVIEWER1, - AV_CODEC_ID_SUBVIEWER => Id::SUBVIEWER, - AV_CODEC_ID_SUBRIP => Id::SUBRIP, - AV_CODEC_ID_WEBVTT => Id::WEBVTT, - AV_CODEC_ID_MPL2 => Id::MPL2, - AV_CODEC_ID_VPLAYER => Id::VPLAYER, - AV_CODEC_ID_PJS => Id::PJS, - AV_CODEC_ID_ASS => Id::ASS, - AV_CODEC_ID_HDMV_TEXT_SUBTITLE => Id::HDMV_TEXT_SUBTITLE, + AV_CODEC_ID_MICRODVD => Id::MICRODVD, + AV_CODEC_ID_EIA_608 => Id::EIA_608, + AV_CODEC_ID_JACOSUB => Id::JACOSUB, + AV_CODEC_ID_SAMI => Id::SAMI, + AV_CODEC_ID_REALTEXT => Id::REALTEXT, + AV_CODEC_ID_STL => Id::STL, + AV_CODEC_ID_SUBVIEWER1 => Id::SUBVIEWER1, + AV_CODEC_ID_SUBVIEWER => Id::SUBVIEWER, + AV_CODEC_ID_SUBRIP => Id::SUBRIP, + AV_CODEC_ID_WEBVTT => Id::WEBVTT, + AV_CODEC_ID_MPL2 => Id::MPL2, + AV_CODEC_ID_VPLAYER => Id::VPLAYER, + AV_CODEC_ID_PJS => Id::PJS, + AV_CODEC_ID_ASS => Id::ASS, + AV_CODEC_ID_HDMV_TEXT_SUBTITLE => Id::HDMV_TEXT_SUBTITLE, - /* other specific kind of codecs (generally used for attachments) */ - AV_CODEC_ID_TTF => Id::TTF, + /* other specific kind of codecs (generally used for attachments) */ + AV_CODEC_ID_TTF => Id::TTF, - AV_CODEC_ID_SCTE_35 => Id::SCTE_35, - AV_CODEC_ID_BINTEXT => Id::BINTEXT, - AV_CODEC_ID_XBIN => Id::XBIN, - AV_CODEC_ID_IDF => Id::IDF, - AV_CODEC_ID_OTF => Id::OTF, - AV_CODEC_ID_SMPTE_KLV => Id::SMPTE_KLV, - AV_CODEC_ID_DVD_NAV => Id::DVD_NAV, - AV_CODEC_ID_TIMED_ID3 => Id::TIMED_ID3, - AV_CODEC_ID_BIN_DATA => Id::BIN_DATA, + AV_CODEC_ID_SCTE_35 => Id::SCTE_35, + AV_CODEC_ID_BINTEXT => Id::BINTEXT, + AV_CODEC_ID_XBIN => Id::XBIN, + AV_CODEC_ID_IDF => Id::IDF, + AV_CODEC_ID_OTF => Id::OTF, + AV_CODEC_ID_SMPTE_KLV => Id::SMPTE_KLV, + AV_CODEC_ID_DVD_NAV => Id::DVD_NAV, + AV_CODEC_ID_TIMED_ID3 => Id::TIMED_ID3, + AV_CODEC_ID_BIN_DATA => Id::BIN_DATA, - AV_CODEC_ID_PROBE => Id::PROBE, + AV_CODEC_ID_PROBE => Id::PROBE, - AV_CODEC_ID_MPEG2TS => Id::MPEG2TS, - AV_CODEC_ID_MPEG4SYSTEMS => Id::MPEG4SYSTEMS, - AV_CODEC_ID_FFMETADATA => Id::FFMETADATA, - AV_CODEC_ID_WRAPPED_AVFRAME => Id::WRAPPED_AVFRAME, - AV_CODEC_ID_PSD => Id::PSD, - AV_CODEC_ID_PIXLET => Id::PIXLET, - AV_CODEC_ID_SPEEDHQ => Id::SPEEDHQ, - AV_CODEC_ID_CLEARVIDEO => Id::CLEARVIDEO, - AV_CODEC_ID_FMVC => Id::FMVC, - AV_CODEC_ID_SCPR => Id::SCPR, - AV_CODEC_ID_XPM => Id::XPM, - AV_CODEC_ID_AV1 => Id::AV1, - AV_CODEC_ID_PCM_F16LE => Id::PCM_F16LE, - AV_CODEC_ID_PCM_F24LE => Id::PCM_F24LE, - AV_CODEC_ID_ATRAC3AL => Id::ATRAC3AL, - AV_CODEC_ID_ATRAC3PAL => Id::ATRAC3PAL, + AV_CODEC_ID_MPEG2TS => Id::MPEG2TS, + AV_CODEC_ID_MPEG4SYSTEMS => Id::MPEG4SYSTEMS, + AV_CODEC_ID_FFMETADATA => Id::FFMETADATA, + AV_CODEC_ID_WRAPPED_AVFRAME => Id::WRAPPED_AVFRAME, + AV_CODEC_ID_PSD => Id::PSD, + AV_CODEC_ID_PIXLET => Id::PIXLET, + AV_CODEC_ID_SPEEDHQ => Id::SPEEDHQ, + AV_CODEC_ID_CLEARVIDEO => Id::CLEARVIDEO, + AV_CODEC_ID_FMVC => Id::FMVC, + AV_CODEC_ID_SCPR => Id::SCPR, + AV_CODEC_ID_XPM => Id::XPM, + AV_CODEC_ID_AV1 => Id::AV1, + AV_CODEC_ID_PCM_F16LE => Id::PCM_F16LE, + AV_CODEC_ID_PCM_F24LE => Id::PCM_F24LE, + AV_CODEC_ID_ATRAC3AL => Id::ATRAC3AL, + AV_CODEC_ID_ATRAC3PAL => Id::ATRAC3PAL, - AV_CODEC_ID_BITPACKED => Id::BITPACKED, - AV_CODEC_ID_MSCC => Id::MSCC, - AV_CODEC_ID_SRGC => Id::SRGC, - AV_CODEC_ID_SVG => Id::SVG, - AV_CODEC_ID_GDV => Id::GDV, - AV_CODEC_ID_FITS => Id::FITS, - AV_CODEC_ID_GREMLIN_DPCM => Id::GREMLIN_DPCM, - AV_CODEC_ID_DOLBY_E => Id::DOLBY_E, - } - } + AV_CODEC_ID_BITPACKED => Id::BITPACKED, + AV_CODEC_ID_MSCC => Id::MSCC, + AV_CODEC_ID_SRGC => Id::SRGC, + AV_CODEC_ID_SVG => Id::SVG, + AV_CODEC_ID_GDV => Id::GDV, + AV_CODEC_ID_FITS => Id::FITS, + AV_CODEC_ID_GREMLIN_DPCM => Id::GREMLIN_DPCM, + AV_CODEC_ID_DOLBY_E => Id::DOLBY_E, + } + } } impl Into for Id { - fn into(self) -> AVCodecID { - match self { - Id::None => AV_CODEC_ID_NONE, + fn into(self) -> AVCodecID { + match self { + Id::None => AV_CODEC_ID_NONE, - /* video codecs */ - Id::MPEG1VIDEO => AV_CODEC_ID_MPEG1VIDEO, - Id::MPEG2VIDEO => AV_CODEC_ID_MPEG2VIDEO, - #[cfg(feature = "ff_api_xvmc")] - Id::MPEG2VIDEO_XVMC => AV_CODEC_ID_MPEG2VIDEO_XVMC, - Id::H261 => AV_CODEC_ID_H261, - Id::H263 => AV_CODEC_ID_H263, - Id::RV10 => AV_CODEC_ID_RV10, - Id::RV20 => AV_CODEC_ID_RV20, - Id::MJPEG => AV_CODEC_ID_MJPEG, - Id::MJPEGB => AV_CODEC_ID_MJPEGB, - Id::LJPEG => AV_CODEC_ID_LJPEG, - Id::SP5X => AV_CODEC_ID_SP5X, - Id::JPEGLS => AV_CODEC_ID_JPEGLS, - Id::MPEG4 => AV_CODEC_ID_MPEG4, - Id::RAWVIDEO => AV_CODEC_ID_RAWVIDEO, - Id::MSMPEG4V1 => AV_CODEC_ID_MSMPEG4V1, - Id::MSMPEG4V2 => AV_CODEC_ID_MSMPEG4V2, - Id::MSMPEG4V3 => AV_CODEC_ID_MSMPEG4V3, - Id::WMV1 => AV_CODEC_ID_WMV1, - Id::WMV2 => AV_CODEC_ID_WMV2, - Id::H263P => AV_CODEC_ID_H263P, - Id::H263I => AV_CODEC_ID_H263I, - Id::FLV1 => AV_CODEC_ID_FLV1, - Id::SVQ1 => AV_CODEC_ID_SVQ1, - Id::SVQ3 => AV_CODEC_ID_SVQ3, - Id::DVVIDEO => AV_CODEC_ID_DVVIDEO, - Id::HUFFYUV => AV_CODEC_ID_HUFFYUV, - Id::CYUV => AV_CODEC_ID_CYUV, - Id::H264 => AV_CODEC_ID_H264, - Id::INDEO3 => AV_CODEC_ID_INDEO3, - Id::VP3 => AV_CODEC_ID_VP3, - Id::THEORA => AV_CODEC_ID_THEORA, - Id::ASV1 => AV_CODEC_ID_ASV1, - Id::ASV2 => AV_CODEC_ID_ASV2, - Id::FFV1 => AV_CODEC_ID_FFV1, - Id::XM4 => AV_CODEC_ID_4XM, - Id::VCR1 => AV_CODEC_ID_VCR1, - Id::CLJR => AV_CODEC_ID_CLJR, - Id::MDEC => AV_CODEC_ID_MDEC, - Id::ROQ => AV_CODEC_ID_ROQ, - Id::INTERPLAY_VIDEO => AV_CODEC_ID_INTERPLAY_VIDEO, - Id::XAN_WC3 => AV_CODEC_ID_XAN_WC3, - Id::XAN_WC4 => AV_CODEC_ID_XAN_WC4, - Id::RPZA => AV_CODEC_ID_RPZA, - Id::CINEPAK => AV_CODEC_ID_CINEPAK, - Id::WS_VQA => AV_CODEC_ID_WS_VQA, - Id::MSRLE => AV_CODEC_ID_MSRLE, - Id::MSVIDEO1 => AV_CODEC_ID_MSVIDEO1, - Id::IDCIN => AV_CODEC_ID_IDCIN, - Id::BPS8 => AV_CODEC_ID_8BPS, - Id::SMC => AV_CODEC_ID_SMC, - Id::FLIC => AV_CODEC_ID_FLIC, - Id::TRUEMOTION1 => AV_CODEC_ID_TRUEMOTION1, - Id::VMDVIDEO => AV_CODEC_ID_VMDVIDEO, - Id::MSZH => AV_CODEC_ID_MSZH, - Id::ZLIB => AV_CODEC_ID_ZLIB, - Id::QTRLE => AV_CODEC_ID_QTRLE, - Id::TSCC => AV_CODEC_ID_TSCC, - Id::ULTI => AV_CODEC_ID_ULTI, - Id::QDRAW => AV_CODEC_ID_QDRAW, - Id::VIXL => AV_CODEC_ID_VIXL, - Id::QPEG => AV_CODEC_ID_QPEG, - Id::PNG => AV_CODEC_ID_PNG, - Id::PPM => AV_CODEC_ID_PPM, - Id::PBM => AV_CODEC_ID_PBM, - Id::PGM => AV_CODEC_ID_PGM, - Id::PGMYUV => AV_CODEC_ID_PGMYUV, - Id::PAM => AV_CODEC_ID_PAM, - Id::FFVHUFF => AV_CODEC_ID_FFVHUFF, - Id::RV30 => AV_CODEC_ID_RV30, - Id::RV40 => AV_CODEC_ID_RV40, - Id::VC1 => AV_CODEC_ID_VC1, - Id::WMV3 => AV_CODEC_ID_WMV3, - Id::LOCO => AV_CODEC_ID_LOCO, - Id::WNV1 => AV_CODEC_ID_WNV1, - Id::AASC => AV_CODEC_ID_AASC, - Id::INDEO2 => AV_CODEC_ID_INDEO2, - Id::FRAPS => AV_CODEC_ID_FRAPS, - Id::TRUEMOTION2 => AV_CODEC_ID_TRUEMOTION2, - Id::BMP => AV_CODEC_ID_BMP, - Id::CSCD => AV_CODEC_ID_CSCD, - Id::MMVIDEO => AV_CODEC_ID_MMVIDEO, - Id::ZMBV => AV_CODEC_ID_ZMBV, - Id::AVS => AV_CODEC_ID_AVS, - Id::SMACKVIDEO => AV_CODEC_ID_SMACKVIDEO, - Id::NUV => AV_CODEC_ID_NUV, - Id::KMVC => AV_CODEC_ID_KMVC, - Id::FLASHSV => AV_CODEC_ID_FLASHSV, - Id::CAVS => AV_CODEC_ID_CAVS, - Id::JPEG2000 => AV_CODEC_ID_JPEG2000, - Id::VMNC => AV_CODEC_ID_VMNC, - Id::VP5 => AV_CODEC_ID_VP5, - Id::VP6 => AV_CODEC_ID_VP6, - Id::VP6F => AV_CODEC_ID_VP6F, - Id::TARGA => AV_CODEC_ID_TARGA, - Id::DSICINVIDEO => AV_CODEC_ID_DSICINVIDEO, - Id::TIERTEXSEQVIDEO => AV_CODEC_ID_TIERTEXSEQVIDEO, - Id::TIFF => AV_CODEC_ID_TIFF, - Id::GIF => AV_CODEC_ID_GIF, - Id::DXA => AV_CODEC_ID_DXA, - Id::DNXHD => AV_CODEC_ID_DNXHD, - Id::THP => AV_CODEC_ID_THP, - Id::SGI => AV_CODEC_ID_SGI, - Id::C93 => AV_CODEC_ID_C93, - Id::BETHSOFTVID => AV_CODEC_ID_BETHSOFTVID, - Id::PTX => AV_CODEC_ID_PTX, - Id::TXD => AV_CODEC_ID_TXD, - Id::VP6A => AV_CODEC_ID_VP6A, - Id::AMV => AV_CODEC_ID_AMV, - Id::VB => AV_CODEC_ID_VB, - Id::PCX => AV_CODEC_ID_PCX, - Id::SUNRAST => AV_CODEC_ID_SUNRAST, - Id::INDEO4 => AV_CODEC_ID_INDEO4, - Id::INDEO5 => AV_CODEC_ID_INDEO5, - Id::MIMIC => AV_CODEC_ID_MIMIC, - Id::RL2 => AV_CODEC_ID_RL2, - Id::ESCAPE124 => AV_CODEC_ID_ESCAPE124, - Id::DIRAC => AV_CODEC_ID_DIRAC, - Id::BFI => AV_CODEC_ID_BFI, - Id::CMV => AV_CODEC_ID_CMV, - Id::MOTIONPIXELS => AV_CODEC_ID_MOTIONPIXELS, - Id::TGV => AV_CODEC_ID_TGV, - Id::TGQ => AV_CODEC_ID_TGQ, - Id::TQI => AV_CODEC_ID_TQI, - Id::AURA => AV_CODEC_ID_AURA, - Id::AURA2 => AV_CODEC_ID_AURA2, - Id::V210X => AV_CODEC_ID_V210X, - Id::TMV => AV_CODEC_ID_TMV, - Id::V210 => AV_CODEC_ID_V210, - Id::DPX => AV_CODEC_ID_DPX, - Id::MAD => AV_CODEC_ID_MAD, - Id::FRWU => AV_CODEC_ID_FRWU, - Id::FLASHSV2 => AV_CODEC_ID_FLASHSV2, - Id::CDGRAPHICS => AV_CODEC_ID_CDGRAPHICS, - Id::R210 => AV_CODEC_ID_R210, - Id::ANM => AV_CODEC_ID_ANM, - Id::BINKVIDEO => AV_CODEC_ID_BINKVIDEO, - Id::IFF_ILBM => AV_CODEC_ID_IFF_ILBM, - Id::IFF_BYTERUN1 => AV_CODEC_ID_IFF_ILBM, - Id::KGV1 => AV_CODEC_ID_KGV1, - Id::YOP => AV_CODEC_ID_YOP, - Id::VP8 => AV_CODEC_ID_VP8, - Id::PICTOR => AV_CODEC_ID_PICTOR, - Id::ANSI => AV_CODEC_ID_ANSI, - Id::A64_MULTI => AV_CODEC_ID_A64_MULTI, - Id::A64_MULTI5 => AV_CODEC_ID_A64_MULTI5, - Id::R10K => AV_CODEC_ID_R10K, - Id::MXPEG => AV_CODEC_ID_MXPEG, - Id::LAGARITH => AV_CODEC_ID_LAGARITH, - Id::PRORES => AV_CODEC_ID_PRORES, - Id::JV => AV_CODEC_ID_JV, - Id::DFA => AV_CODEC_ID_DFA, - Id::WMV3IMAGE => AV_CODEC_ID_WMV3IMAGE, - Id::VC1IMAGE => AV_CODEC_ID_VC1IMAGE, - Id::UTVIDEO => AV_CODEC_ID_UTVIDEO, - Id::BMV_VIDEO => AV_CODEC_ID_BMV_VIDEO, - Id::VBLE => AV_CODEC_ID_VBLE, - Id::DXTORY => AV_CODEC_ID_DXTORY, - Id::V410 => AV_CODEC_ID_V410, - Id::XWD => AV_CODEC_ID_XWD, - Id::CDXL => AV_CODEC_ID_CDXL, - Id::XBM => AV_CODEC_ID_XBM, - Id::ZEROCODEC => AV_CODEC_ID_ZEROCODEC, - Id::MSS1 => AV_CODEC_ID_MSS1, - Id::MSA1 => AV_CODEC_ID_MSA1, - Id::TSCC2 => AV_CODEC_ID_TSCC2, - Id::MTS2 => AV_CODEC_ID_MTS2, - Id::CLLC => AV_CODEC_ID_CLLC, - Id::MSS2 => AV_CODEC_ID_MSS2, - Id::VP9 => AV_CODEC_ID_VP9, - Id::AIC => AV_CODEC_ID_AIC, - Id::ESCAPE130 => AV_CODEC_ID_ESCAPE130, - Id::G2M => AV_CODEC_ID_G2M, - Id::WEBP => AV_CODEC_ID_WEBP, - Id::HNM4_VIDEO => AV_CODEC_ID_HNM4_VIDEO, - Id::HEVC => AV_CODEC_ID_HEVC, - Id::H265 => AV_CODEC_ID_HEVC, - Id::FIC => AV_CODEC_ID_FIC, - Id::ALIAS_PIX => AV_CODEC_ID_ALIAS_PIX, - Id::BRENDER_PIX => AV_CODEC_ID_BRENDER_PIX, - Id::PAF_VIDEO => AV_CODEC_ID_PAF_VIDEO, - Id::EXR => AV_CODEC_ID_EXR, - Id::VP7 => AV_CODEC_ID_VP7, - Id::SANM => AV_CODEC_ID_SANM, - Id::SGIRLE => AV_CODEC_ID_SGIRLE, - Id::MVC1 => AV_CODEC_ID_MVC1, - Id::MVC2 => AV_CODEC_ID_MVC2, - Id::HQX => AV_CODEC_ID_HQX, - Id::TDSC => AV_CODEC_ID_TDSC, - Id::HQ_HQA => AV_CODEC_ID_HQ_HQA, - Id::HAP => AV_CODEC_ID_HAP, - Id::DDS => AV_CODEC_ID_DDS, - Id::DXV => AV_CODEC_ID_DXV, - Id::SCREENPRESSO => AV_CODEC_ID_SCREENPRESSO, - Id::RSCC => AV_CODEC_ID_RSCC, + /* video codecs */ + Id::MPEG1VIDEO => AV_CODEC_ID_MPEG1VIDEO, + Id::MPEG2VIDEO => AV_CODEC_ID_MPEG2VIDEO, + #[cfg(feature = "ff_api_xvmc")] + Id::MPEG2VIDEO_XVMC => AV_CODEC_ID_MPEG2VIDEO_XVMC, + Id::H261 => AV_CODEC_ID_H261, + Id::H263 => AV_CODEC_ID_H263, + Id::RV10 => AV_CODEC_ID_RV10, + Id::RV20 => AV_CODEC_ID_RV20, + Id::MJPEG => AV_CODEC_ID_MJPEG, + Id::MJPEGB => AV_CODEC_ID_MJPEGB, + Id::LJPEG => AV_CODEC_ID_LJPEG, + Id::SP5X => AV_CODEC_ID_SP5X, + Id::JPEGLS => AV_CODEC_ID_JPEGLS, + Id::MPEG4 => AV_CODEC_ID_MPEG4, + Id::RAWVIDEO => AV_CODEC_ID_RAWVIDEO, + Id::MSMPEG4V1 => AV_CODEC_ID_MSMPEG4V1, + Id::MSMPEG4V2 => AV_CODEC_ID_MSMPEG4V2, + Id::MSMPEG4V3 => AV_CODEC_ID_MSMPEG4V3, + Id::WMV1 => AV_CODEC_ID_WMV1, + Id::WMV2 => AV_CODEC_ID_WMV2, + Id::H263P => AV_CODEC_ID_H263P, + Id::H263I => AV_CODEC_ID_H263I, + Id::FLV1 => AV_CODEC_ID_FLV1, + Id::SVQ1 => AV_CODEC_ID_SVQ1, + Id::SVQ3 => AV_CODEC_ID_SVQ3, + Id::DVVIDEO => AV_CODEC_ID_DVVIDEO, + Id::HUFFYUV => AV_CODEC_ID_HUFFYUV, + Id::CYUV => AV_CODEC_ID_CYUV, + Id::H264 => AV_CODEC_ID_H264, + Id::INDEO3 => AV_CODEC_ID_INDEO3, + Id::VP3 => AV_CODEC_ID_VP3, + Id::THEORA => AV_CODEC_ID_THEORA, + Id::ASV1 => AV_CODEC_ID_ASV1, + Id::ASV2 => AV_CODEC_ID_ASV2, + Id::FFV1 => AV_CODEC_ID_FFV1, + Id::XM4 => AV_CODEC_ID_4XM, + Id::VCR1 => AV_CODEC_ID_VCR1, + Id::CLJR => AV_CODEC_ID_CLJR, + Id::MDEC => AV_CODEC_ID_MDEC, + Id::ROQ => AV_CODEC_ID_ROQ, + Id::INTERPLAY_VIDEO => AV_CODEC_ID_INTERPLAY_VIDEO, + Id::XAN_WC3 => AV_CODEC_ID_XAN_WC3, + Id::XAN_WC4 => AV_CODEC_ID_XAN_WC4, + Id::RPZA => AV_CODEC_ID_RPZA, + Id::CINEPAK => AV_CODEC_ID_CINEPAK, + Id::WS_VQA => AV_CODEC_ID_WS_VQA, + Id::MSRLE => AV_CODEC_ID_MSRLE, + Id::MSVIDEO1 => AV_CODEC_ID_MSVIDEO1, + Id::IDCIN => AV_CODEC_ID_IDCIN, + Id::BPS8 => AV_CODEC_ID_8BPS, + Id::SMC => AV_CODEC_ID_SMC, + Id::FLIC => AV_CODEC_ID_FLIC, + Id::TRUEMOTION1 => AV_CODEC_ID_TRUEMOTION1, + Id::VMDVIDEO => AV_CODEC_ID_VMDVIDEO, + Id::MSZH => AV_CODEC_ID_MSZH, + Id::ZLIB => AV_CODEC_ID_ZLIB, + Id::QTRLE => AV_CODEC_ID_QTRLE, + Id::TSCC => AV_CODEC_ID_TSCC, + Id::ULTI => AV_CODEC_ID_ULTI, + Id::QDRAW => AV_CODEC_ID_QDRAW, + Id::VIXL => AV_CODEC_ID_VIXL, + Id::QPEG => AV_CODEC_ID_QPEG, + Id::PNG => AV_CODEC_ID_PNG, + Id::PPM => AV_CODEC_ID_PPM, + Id::PBM => AV_CODEC_ID_PBM, + Id::PGM => AV_CODEC_ID_PGM, + Id::PGMYUV => AV_CODEC_ID_PGMYUV, + Id::PAM => AV_CODEC_ID_PAM, + Id::FFVHUFF => AV_CODEC_ID_FFVHUFF, + Id::RV30 => AV_CODEC_ID_RV30, + Id::RV40 => AV_CODEC_ID_RV40, + Id::VC1 => AV_CODEC_ID_VC1, + Id::WMV3 => AV_CODEC_ID_WMV3, + Id::LOCO => AV_CODEC_ID_LOCO, + Id::WNV1 => AV_CODEC_ID_WNV1, + Id::AASC => AV_CODEC_ID_AASC, + Id::INDEO2 => AV_CODEC_ID_INDEO2, + Id::FRAPS => AV_CODEC_ID_FRAPS, + Id::TRUEMOTION2 => AV_CODEC_ID_TRUEMOTION2, + Id::BMP => AV_CODEC_ID_BMP, + Id::CSCD => AV_CODEC_ID_CSCD, + Id::MMVIDEO => AV_CODEC_ID_MMVIDEO, + Id::ZMBV => AV_CODEC_ID_ZMBV, + Id::AVS => AV_CODEC_ID_AVS, + Id::SMACKVIDEO => AV_CODEC_ID_SMACKVIDEO, + Id::NUV => AV_CODEC_ID_NUV, + Id::KMVC => AV_CODEC_ID_KMVC, + Id::FLASHSV => AV_CODEC_ID_FLASHSV, + Id::CAVS => AV_CODEC_ID_CAVS, + Id::JPEG2000 => AV_CODEC_ID_JPEG2000, + Id::VMNC => AV_CODEC_ID_VMNC, + Id::VP5 => AV_CODEC_ID_VP5, + Id::VP6 => AV_CODEC_ID_VP6, + Id::VP6F => AV_CODEC_ID_VP6F, + Id::TARGA => AV_CODEC_ID_TARGA, + Id::DSICINVIDEO => AV_CODEC_ID_DSICINVIDEO, + Id::TIERTEXSEQVIDEO => AV_CODEC_ID_TIERTEXSEQVIDEO, + Id::TIFF => AV_CODEC_ID_TIFF, + Id::GIF => AV_CODEC_ID_GIF, + Id::DXA => AV_CODEC_ID_DXA, + Id::DNXHD => AV_CODEC_ID_DNXHD, + Id::THP => AV_CODEC_ID_THP, + Id::SGI => AV_CODEC_ID_SGI, + Id::C93 => AV_CODEC_ID_C93, + Id::BETHSOFTVID => AV_CODEC_ID_BETHSOFTVID, + Id::PTX => AV_CODEC_ID_PTX, + Id::TXD => AV_CODEC_ID_TXD, + Id::VP6A => AV_CODEC_ID_VP6A, + Id::AMV => AV_CODEC_ID_AMV, + Id::VB => AV_CODEC_ID_VB, + Id::PCX => AV_CODEC_ID_PCX, + Id::SUNRAST => AV_CODEC_ID_SUNRAST, + Id::INDEO4 => AV_CODEC_ID_INDEO4, + Id::INDEO5 => AV_CODEC_ID_INDEO5, + Id::MIMIC => AV_CODEC_ID_MIMIC, + Id::RL2 => AV_CODEC_ID_RL2, + Id::ESCAPE124 => AV_CODEC_ID_ESCAPE124, + Id::DIRAC => AV_CODEC_ID_DIRAC, + Id::BFI => AV_CODEC_ID_BFI, + Id::CMV => AV_CODEC_ID_CMV, + Id::MOTIONPIXELS => AV_CODEC_ID_MOTIONPIXELS, + Id::TGV => AV_CODEC_ID_TGV, + Id::TGQ => AV_CODEC_ID_TGQ, + Id::TQI => AV_CODEC_ID_TQI, + Id::AURA => AV_CODEC_ID_AURA, + Id::AURA2 => AV_CODEC_ID_AURA2, + Id::V210X => AV_CODEC_ID_V210X, + Id::TMV => AV_CODEC_ID_TMV, + Id::V210 => AV_CODEC_ID_V210, + Id::DPX => AV_CODEC_ID_DPX, + Id::MAD => AV_CODEC_ID_MAD, + Id::FRWU => AV_CODEC_ID_FRWU, + Id::FLASHSV2 => AV_CODEC_ID_FLASHSV2, + Id::CDGRAPHICS => AV_CODEC_ID_CDGRAPHICS, + Id::R210 => AV_CODEC_ID_R210, + Id::ANM => AV_CODEC_ID_ANM, + Id::BINKVIDEO => AV_CODEC_ID_BINKVIDEO, + Id::IFF_ILBM => AV_CODEC_ID_IFF_ILBM, + Id::IFF_BYTERUN1 => AV_CODEC_ID_IFF_ILBM, + Id::KGV1 => AV_CODEC_ID_KGV1, + Id::YOP => AV_CODEC_ID_YOP, + Id::VP8 => AV_CODEC_ID_VP8, + Id::PICTOR => AV_CODEC_ID_PICTOR, + Id::ANSI => AV_CODEC_ID_ANSI, + Id::A64_MULTI => AV_CODEC_ID_A64_MULTI, + Id::A64_MULTI5 => AV_CODEC_ID_A64_MULTI5, + Id::R10K => AV_CODEC_ID_R10K, + Id::MXPEG => AV_CODEC_ID_MXPEG, + Id::LAGARITH => AV_CODEC_ID_LAGARITH, + Id::PRORES => AV_CODEC_ID_PRORES, + Id::JV => AV_CODEC_ID_JV, + Id::DFA => AV_CODEC_ID_DFA, + Id::WMV3IMAGE => AV_CODEC_ID_WMV3IMAGE, + Id::VC1IMAGE => AV_CODEC_ID_VC1IMAGE, + Id::UTVIDEO => AV_CODEC_ID_UTVIDEO, + Id::BMV_VIDEO => AV_CODEC_ID_BMV_VIDEO, + Id::VBLE => AV_CODEC_ID_VBLE, + Id::DXTORY => AV_CODEC_ID_DXTORY, + Id::V410 => AV_CODEC_ID_V410, + Id::XWD => AV_CODEC_ID_XWD, + Id::CDXL => AV_CODEC_ID_CDXL, + Id::XBM => AV_CODEC_ID_XBM, + Id::ZEROCODEC => AV_CODEC_ID_ZEROCODEC, + Id::MSS1 => AV_CODEC_ID_MSS1, + Id::MSA1 => AV_CODEC_ID_MSA1, + Id::TSCC2 => AV_CODEC_ID_TSCC2, + Id::MTS2 => AV_CODEC_ID_MTS2, + Id::CLLC => AV_CODEC_ID_CLLC, + Id::MSS2 => AV_CODEC_ID_MSS2, + Id::VP9 => AV_CODEC_ID_VP9, + Id::AIC => AV_CODEC_ID_AIC, + Id::ESCAPE130 => AV_CODEC_ID_ESCAPE130, + Id::G2M => AV_CODEC_ID_G2M, + Id::WEBP => AV_CODEC_ID_WEBP, + Id::HNM4_VIDEO => AV_CODEC_ID_HNM4_VIDEO, + Id::HEVC => AV_CODEC_ID_HEVC, + Id::H265 => AV_CODEC_ID_HEVC, + Id::FIC => AV_CODEC_ID_FIC, + Id::ALIAS_PIX => AV_CODEC_ID_ALIAS_PIX, + Id::BRENDER_PIX => AV_CODEC_ID_BRENDER_PIX, + Id::PAF_VIDEO => AV_CODEC_ID_PAF_VIDEO, + Id::EXR => AV_CODEC_ID_EXR, + Id::VP7 => AV_CODEC_ID_VP7, + Id::SANM => AV_CODEC_ID_SANM, + Id::SGIRLE => AV_CODEC_ID_SGIRLE, + Id::MVC1 => AV_CODEC_ID_MVC1, + Id::MVC2 => AV_CODEC_ID_MVC2, + Id::HQX => AV_CODEC_ID_HQX, + Id::TDSC => AV_CODEC_ID_TDSC, + Id::HQ_HQA => AV_CODEC_ID_HQ_HQA, + Id::HAP => AV_CODEC_ID_HAP, + Id::DDS => AV_CODEC_ID_DDS, + Id::DXV => AV_CODEC_ID_DXV, + Id::SCREENPRESSO => AV_CODEC_ID_SCREENPRESSO, + Id::RSCC => AV_CODEC_ID_RSCC, - Id::Y41P => AV_CODEC_ID_Y41P, - Id::AVRP => AV_CODEC_ID_AVRP, - Id::V012 => AV_CODEC_ID_012V, - Id::AVUI => AV_CODEC_ID_AVUI, - Id::AYUV => AV_CODEC_ID_AYUV, - Id::TARGA_Y216 => AV_CODEC_ID_TARGA_Y216, - Id::V308 => AV_CODEC_ID_V308, - Id::V408 => AV_CODEC_ID_V408, - Id::YUV4 => AV_CODEC_ID_YUV4, - Id::AVRN => AV_CODEC_ID_AVRN, - Id::CPIA => AV_CODEC_ID_CPIA, - Id::XFACE => AV_CODEC_ID_XFACE, - Id::SNOW => AV_CODEC_ID_SNOW, - Id::SMVJPEG => AV_CODEC_ID_SMVJPEG, - Id::APNG => AV_CODEC_ID_APNG, - Id::DAALA => AV_CODEC_ID_DAALA, - Id::CFHD => AV_CODEC_ID_CFHD, - Id::TRUEMOTION2RT => AV_CODEC_ID_TRUEMOTION2RT, - Id::M101 => AV_CODEC_ID_M101, - Id::MAGICYUV => AV_CODEC_ID_MAGICYUV, - Id::SHEERVIDEO => AV_CODEC_ID_SHEERVIDEO, - Id::YLC => AV_CODEC_ID_YLC, + Id::Y41P => AV_CODEC_ID_Y41P, + Id::AVRP => AV_CODEC_ID_AVRP, + Id::V012 => AV_CODEC_ID_012V, + Id::AVUI => AV_CODEC_ID_AVUI, + Id::AYUV => AV_CODEC_ID_AYUV, + Id::TARGA_Y216 => AV_CODEC_ID_TARGA_Y216, + Id::V308 => AV_CODEC_ID_V308, + Id::V408 => AV_CODEC_ID_V408, + Id::YUV4 => AV_CODEC_ID_YUV4, + Id::AVRN => AV_CODEC_ID_AVRN, + Id::CPIA => AV_CODEC_ID_CPIA, + Id::XFACE => AV_CODEC_ID_XFACE, + Id::SNOW => AV_CODEC_ID_SNOW, + Id::SMVJPEG => AV_CODEC_ID_SMVJPEG, + Id::APNG => AV_CODEC_ID_APNG, + Id::DAALA => AV_CODEC_ID_DAALA, + Id::CFHD => AV_CODEC_ID_CFHD, + Id::TRUEMOTION2RT => AV_CODEC_ID_TRUEMOTION2RT, + Id::M101 => AV_CODEC_ID_M101, + Id::MAGICYUV => AV_CODEC_ID_MAGICYUV, + Id::SHEERVIDEO => AV_CODEC_ID_SHEERVIDEO, + Id::YLC => AV_CODEC_ID_YLC, - /* various PCM "codecs" */ - Id::PCM_S16LE => AV_CODEC_ID_PCM_S16LE, - Id::PCM_S16BE => AV_CODEC_ID_PCM_S16BE, - Id::PCM_U16LE => AV_CODEC_ID_PCM_U16LE, - Id::PCM_U16BE => AV_CODEC_ID_PCM_U16BE, - Id::PCM_S8 => AV_CODEC_ID_PCM_S8, - Id::PCM_U8 => AV_CODEC_ID_PCM_U8, - Id::PCM_MULAW => AV_CODEC_ID_PCM_MULAW, - Id::PCM_ALAW => AV_CODEC_ID_PCM_ALAW, - Id::PCM_S32LE => AV_CODEC_ID_PCM_S32LE, - Id::PCM_S32BE => AV_CODEC_ID_PCM_S32BE, - Id::PCM_U32LE => AV_CODEC_ID_PCM_U32LE, - Id::PCM_U32BE => AV_CODEC_ID_PCM_U32BE, - Id::PCM_S24LE => AV_CODEC_ID_PCM_S24LE, - Id::PCM_S24BE => AV_CODEC_ID_PCM_S24BE, - Id::PCM_U24LE => AV_CODEC_ID_PCM_U24LE, - Id::PCM_U24BE => AV_CODEC_ID_PCM_U24BE, - Id::PCM_S24DAUD => AV_CODEC_ID_PCM_S24DAUD, - Id::PCM_ZORK => AV_CODEC_ID_PCM_ZORK, - Id::PCM_S16LE_PLANAR => AV_CODEC_ID_PCM_S16LE_PLANAR, - Id::PCM_DVD => AV_CODEC_ID_PCM_DVD, - Id::PCM_F32BE => AV_CODEC_ID_PCM_F32BE, - Id::PCM_F32LE => AV_CODEC_ID_PCM_F32LE, - Id::PCM_F64BE => AV_CODEC_ID_PCM_F64BE, - Id::PCM_F64LE => AV_CODEC_ID_PCM_F64LE, - Id::PCM_BLURAY => AV_CODEC_ID_PCM_BLURAY, - Id::PCM_LXF => AV_CODEC_ID_PCM_LXF, - Id::S302M => AV_CODEC_ID_S302M, - Id::PCM_S8_PLANAR => AV_CODEC_ID_PCM_S8_PLANAR, - Id::PCM_S24LE_PLANAR => AV_CODEC_ID_PCM_S24LE_PLANAR, - Id::PCM_S32LE_PLANAR => AV_CODEC_ID_PCM_S32LE_PLANAR, - Id::PCM_S16BE_PLANAR => AV_CODEC_ID_PCM_S16BE_PLANAR, + /* various PCM "codecs" */ + Id::PCM_S16LE => AV_CODEC_ID_PCM_S16LE, + Id::PCM_S16BE => AV_CODEC_ID_PCM_S16BE, + Id::PCM_U16LE => AV_CODEC_ID_PCM_U16LE, + Id::PCM_U16BE => AV_CODEC_ID_PCM_U16BE, + Id::PCM_S8 => AV_CODEC_ID_PCM_S8, + Id::PCM_U8 => AV_CODEC_ID_PCM_U8, + Id::PCM_MULAW => AV_CODEC_ID_PCM_MULAW, + Id::PCM_ALAW => AV_CODEC_ID_PCM_ALAW, + Id::PCM_S32LE => AV_CODEC_ID_PCM_S32LE, + Id::PCM_S32BE => AV_CODEC_ID_PCM_S32BE, + Id::PCM_U32LE => AV_CODEC_ID_PCM_U32LE, + Id::PCM_U32BE => AV_CODEC_ID_PCM_U32BE, + Id::PCM_S24LE => AV_CODEC_ID_PCM_S24LE, + Id::PCM_S24BE => AV_CODEC_ID_PCM_S24BE, + Id::PCM_U24LE => AV_CODEC_ID_PCM_U24LE, + Id::PCM_U24BE => AV_CODEC_ID_PCM_U24BE, + Id::PCM_S24DAUD => AV_CODEC_ID_PCM_S24DAUD, + Id::PCM_ZORK => AV_CODEC_ID_PCM_ZORK, + Id::PCM_S16LE_PLANAR => AV_CODEC_ID_PCM_S16LE_PLANAR, + Id::PCM_DVD => AV_CODEC_ID_PCM_DVD, + Id::PCM_F32BE => AV_CODEC_ID_PCM_F32BE, + Id::PCM_F32LE => AV_CODEC_ID_PCM_F32LE, + Id::PCM_F64BE => AV_CODEC_ID_PCM_F64BE, + Id::PCM_F64LE => AV_CODEC_ID_PCM_F64LE, + Id::PCM_BLURAY => AV_CODEC_ID_PCM_BLURAY, + Id::PCM_LXF => AV_CODEC_ID_PCM_LXF, + Id::S302M => AV_CODEC_ID_S302M, + Id::PCM_S8_PLANAR => AV_CODEC_ID_PCM_S8_PLANAR, + Id::PCM_S24LE_PLANAR => AV_CODEC_ID_PCM_S24LE_PLANAR, + Id::PCM_S32LE_PLANAR => AV_CODEC_ID_PCM_S32LE_PLANAR, + Id::PCM_S16BE_PLANAR => AV_CODEC_ID_PCM_S16BE_PLANAR, - Id::PCM_S64LE => AV_CODEC_ID_PCM_S64LE, - Id::PCM_S64BE => AV_CODEC_ID_PCM_S64BE, + Id::PCM_S64LE => AV_CODEC_ID_PCM_S64LE, + Id::PCM_S64BE => AV_CODEC_ID_PCM_S64BE, - /* various ADPCM codecs */ - Id::ADPCM_IMA_QT => AV_CODEC_ID_ADPCM_IMA_QT, - Id::ADPCM_IMA_WAV => AV_CODEC_ID_ADPCM_IMA_WAV, - Id::ADPCM_IMA_DK3 => AV_CODEC_ID_ADPCM_IMA_DK3, - Id::ADPCM_IMA_DK4 => AV_CODEC_ID_ADPCM_IMA_DK4, - Id::ADPCM_IMA_WS => AV_CODEC_ID_ADPCM_IMA_WS, - Id::ADPCM_IMA_SMJPEG => AV_CODEC_ID_ADPCM_IMA_SMJPEG, - Id::ADPCM_MS => AV_CODEC_ID_ADPCM_MS, - Id::ADPCM_4XM => AV_CODEC_ID_ADPCM_4XM, - Id::ADPCM_XA => AV_CODEC_ID_ADPCM_XA, - Id::ADPCM_ADX => AV_CODEC_ID_ADPCM_ADX, - Id::ADPCM_EA => AV_CODEC_ID_ADPCM_EA, - Id::ADPCM_G726 => AV_CODEC_ID_ADPCM_G726, - Id::ADPCM_CT => AV_CODEC_ID_ADPCM_CT, - Id::ADPCM_SWF => AV_CODEC_ID_ADPCM_SWF, - Id::ADPCM_YAMAHA => AV_CODEC_ID_ADPCM_YAMAHA, - Id::ADPCM_SBPRO_4 => AV_CODEC_ID_ADPCM_SBPRO_4, - Id::ADPCM_SBPRO_3 => AV_CODEC_ID_ADPCM_SBPRO_3, - Id::ADPCM_SBPRO_2 => AV_CODEC_ID_ADPCM_SBPRO_2, - Id::ADPCM_THP => AV_CODEC_ID_ADPCM_THP, - Id::ADPCM_IMA_AMV => AV_CODEC_ID_ADPCM_IMA_AMV, - Id::ADPCM_EA_R1 => AV_CODEC_ID_ADPCM_EA_R1, - Id::ADPCM_EA_R3 => AV_CODEC_ID_ADPCM_EA_R3, - Id::ADPCM_EA_R2 => AV_CODEC_ID_ADPCM_EA_R2, - Id::ADPCM_IMA_EA_SEAD => AV_CODEC_ID_ADPCM_IMA_EA_SEAD, - Id::ADPCM_IMA_EA_EACS => AV_CODEC_ID_ADPCM_IMA_EA_EACS, - Id::ADPCM_EA_XAS => AV_CODEC_ID_ADPCM_EA_XAS, - Id::ADPCM_EA_MAXIS_XA => AV_CODEC_ID_ADPCM_EA_MAXIS_XA, - Id::ADPCM_IMA_ISS => AV_CODEC_ID_ADPCM_IMA_ISS, - Id::ADPCM_G722 => AV_CODEC_ID_ADPCM_G722, - Id::ADPCM_IMA_APC => AV_CODEC_ID_ADPCM_IMA_APC, - Id::ADPCM_VIMA => AV_CODEC_ID_ADPCM_VIMA, - Id::VIMA => AV_CODEC_ID_VIMA, + /* various ADPCM codecs */ + Id::ADPCM_IMA_QT => AV_CODEC_ID_ADPCM_IMA_QT, + Id::ADPCM_IMA_WAV => AV_CODEC_ID_ADPCM_IMA_WAV, + Id::ADPCM_IMA_DK3 => AV_CODEC_ID_ADPCM_IMA_DK3, + Id::ADPCM_IMA_DK4 => AV_CODEC_ID_ADPCM_IMA_DK4, + Id::ADPCM_IMA_WS => AV_CODEC_ID_ADPCM_IMA_WS, + Id::ADPCM_IMA_SMJPEG => AV_CODEC_ID_ADPCM_IMA_SMJPEG, + Id::ADPCM_MS => AV_CODEC_ID_ADPCM_MS, + Id::ADPCM_4XM => AV_CODEC_ID_ADPCM_4XM, + Id::ADPCM_XA => AV_CODEC_ID_ADPCM_XA, + Id::ADPCM_ADX => AV_CODEC_ID_ADPCM_ADX, + Id::ADPCM_EA => AV_CODEC_ID_ADPCM_EA, + Id::ADPCM_G726 => AV_CODEC_ID_ADPCM_G726, + Id::ADPCM_CT => AV_CODEC_ID_ADPCM_CT, + Id::ADPCM_SWF => AV_CODEC_ID_ADPCM_SWF, + Id::ADPCM_YAMAHA => AV_CODEC_ID_ADPCM_YAMAHA, + Id::ADPCM_SBPRO_4 => AV_CODEC_ID_ADPCM_SBPRO_4, + Id::ADPCM_SBPRO_3 => AV_CODEC_ID_ADPCM_SBPRO_3, + Id::ADPCM_SBPRO_2 => AV_CODEC_ID_ADPCM_SBPRO_2, + Id::ADPCM_THP => AV_CODEC_ID_ADPCM_THP, + Id::ADPCM_IMA_AMV => AV_CODEC_ID_ADPCM_IMA_AMV, + Id::ADPCM_EA_R1 => AV_CODEC_ID_ADPCM_EA_R1, + Id::ADPCM_EA_R3 => AV_CODEC_ID_ADPCM_EA_R3, + Id::ADPCM_EA_R2 => AV_CODEC_ID_ADPCM_EA_R2, + Id::ADPCM_IMA_EA_SEAD => AV_CODEC_ID_ADPCM_IMA_EA_SEAD, + Id::ADPCM_IMA_EA_EACS => AV_CODEC_ID_ADPCM_IMA_EA_EACS, + Id::ADPCM_EA_XAS => AV_CODEC_ID_ADPCM_EA_XAS, + Id::ADPCM_EA_MAXIS_XA => AV_CODEC_ID_ADPCM_EA_MAXIS_XA, + Id::ADPCM_IMA_ISS => AV_CODEC_ID_ADPCM_IMA_ISS, + Id::ADPCM_G722 => AV_CODEC_ID_ADPCM_G722, + Id::ADPCM_IMA_APC => AV_CODEC_ID_ADPCM_IMA_APC, + Id::ADPCM_VIMA => AV_CODEC_ID_ADPCM_VIMA, + Id::VIMA => AV_CODEC_ID_VIMA, - Id::ADPCM_AFC => AV_CODEC_ID_ADPCM_AFC, - Id::ADPCM_IMA_OKI => AV_CODEC_ID_ADPCM_IMA_OKI, - Id::ADPCM_DTK => AV_CODEC_ID_ADPCM_DTK, - Id::ADPCM_IMA_RAD => AV_CODEC_ID_ADPCM_IMA_RAD, - Id::ADPCM_G726LE => AV_CODEC_ID_ADPCM_G726LE, - Id::ADPCM_THP_LE => AV_CODEC_ID_ADPCM_THP_LE, - Id::ADPCM_PSX => AV_CODEC_ID_ADPCM_PSX, - Id::ADPCM_AICA => AV_CODEC_ID_ADPCM_AICA, - Id::ADPCM_IMA_DAT4 => AV_CODEC_ID_ADPCM_IMA_DAT4, - Id::ADPCM_MTAF => AV_CODEC_ID_ADPCM_MTAF, + Id::ADPCM_AFC => AV_CODEC_ID_ADPCM_AFC, + Id::ADPCM_IMA_OKI => AV_CODEC_ID_ADPCM_IMA_OKI, + Id::ADPCM_DTK => AV_CODEC_ID_ADPCM_DTK, + Id::ADPCM_IMA_RAD => AV_CODEC_ID_ADPCM_IMA_RAD, + Id::ADPCM_G726LE => AV_CODEC_ID_ADPCM_G726LE, + Id::ADPCM_THP_LE => AV_CODEC_ID_ADPCM_THP_LE, + Id::ADPCM_PSX => AV_CODEC_ID_ADPCM_PSX, + Id::ADPCM_AICA => AV_CODEC_ID_ADPCM_AICA, + Id::ADPCM_IMA_DAT4 => AV_CODEC_ID_ADPCM_IMA_DAT4, + Id::ADPCM_MTAF => AV_CODEC_ID_ADPCM_MTAF, - /* AMR */ - Id::AMR_NB => AV_CODEC_ID_AMR_NB, - Id::AMR_WB => AV_CODEC_ID_AMR_WB, + /* AMR */ + Id::AMR_NB => AV_CODEC_ID_AMR_NB, + Id::AMR_WB => AV_CODEC_ID_AMR_WB, - /* RealAudio codecs*/ - Id::RA_144 => AV_CODEC_ID_RA_144, - Id::RA_288 => AV_CODEC_ID_RA_288, + /* RealAudio codecs*/ + Id::RA_144 => AV_CODEC_ID_RA_144, + Id::RA_288 => AV_CODEC_ID_RA_288, - /* various DPCM codecs */ - Id::ROQ_DPCM => AV_CODEC_ID_ROQ_DPCM, - Id::INTERPLAY_DPCM => AV_CODEC_ID_INTERPLAY_DPCM, - Id::XAN_DPCM => AV_CODEC_ID_XAN_DPCM, - Id::SOL_DPCM => AV_CODEC_ID_SOL_DPCM, + /* various DPCM codecs */ + Id::ROQ_DPCM => AV_CODEC_ID_ROQ_DPCM, + Id::INTERPLAY_DPCM => AV_CODEC_ID_INTERPLAY_DPCM, + Id::XAN_DPCM => AV_CODEC_ID_XAN_DPCM, + Id::SOL_DPCM => AV_CODEC_ID_SOL_DPCM, - Id::SDX2_DPCM => AV_CODEC_ID_SDX2_DPCM, + Id::SDX2_DPCM => AV_CODEC_ID_SDX2_DPCM, - /* audio codecs */ - Id::MP2 => AV_CODEC_ID_MP2, - Id::MP3 => AV_CODEC_ID_MP3, - Id::AAC => AV_CODEC_ID_AAC, - Id::AC3 => AV_CODEC_ID_AC3, - Id::DTS => AV_CODEC_ID_DTS, - Id::VORBIS => AV_CODEC_ID_VORBIS, - Id::DVAUDIO => AV_CODEC_ID_DVAUDIO, - Id::WMAV1 => AV_CODEC_ID_WMAV1, - Id::WMAV2 => AV_CODEC_ID_WMAV2, - Id::MACE3 => AV_CODEC_ID_MACE3, - Id::MACE6 => AV_CODEC_ID_MACE6, - Id::VMDAUDIO => AV_CODEC_ID_VMDAUDIO, - Id::FLAC => AV_CODEC_ID_FLAC, - Id::MP3ADU => AV_CODEC_ID_MP3ADU, - Id::MP3ON4 => AV_CODEC_ID_MP3ON4, - Id::SHORTEN => AV_CODEC_ID_SHORTEN, - Id::ALAC => AV_CODEC_ID_ALAC, - Id::WESTWOOD_SND1 => AV_CODEC_ID_WESTWOOD_SND1, - Id::GSM => AV_CODEC_ID_GSM, - Id::QDM2 => AV_CODEC_ID_QDM2, - Id::COOK => AV_CODEC_ID_COOK, - Id::TRUESPEECH => AV_CODEC_ID_TRUESPEECH, - Id::TTA => AV_CODEC_ID_TTA, - Id::SMACKAUDIO => AV_CODEC_ID_SMACKAUDIO, - Id::QCELP => AV_CODEC_ID_QCELP, - Id::WAVPACK => AV_CODEC_ID_WAVPACK, - Id::DSICINAUDIO => AV_CODEC_ID_DSICINAUDIO, - Id::IMC => AV_CODEC_ID_IMC, - Id::MUSEPACK7 => AV_CODEC_ID_MUSEPACK7, - Id::MLP => AV_CODEC_ID_MLP, - Id::GSM_MS => AV_CODEC_ID_GSM_MS, - Id::ATRAC3 => AV_CODEC_ID_ATRAC3, - #[cfg(feature = "ff_api_voxware")] - Id::VOXWARE => AV_CODEC_ID_VOXWARE, - Id::APE => AV_CODEC_ID_APE, - Id::NELLYMOSER => AV_CODEC_ID_NELLYMOSER, - Id::MUSEPACK8 => AV_CODEC_ID_MUSEPACK8, - Id::SPEEX => AV_CODEC_ID_SPEEX, - Id::WMAVOICE => AV_CODEC_ID_WMAVOICE, - Id::WMAPRO => AV_CODEC_ID_WMAPRO, - Id::WMALOSSLESS => AV_CODEC_ID_WMALOSSLESS, - Id::ATRAC3P => AV_CODEC_ID_ATRAC3P, - Id::EAC3 => AV_CODEC_ID_EAC3, - Id::SIPR => AV_CODEC_ID_SIPR, - Id::MP1 => AV_CODEC_ID_MP1, - Id::TWINVQ => AV_CODEC_ID_TWINVQ, - Id::TRUEHD => AV_CODEC_ID_TRUEHD, - Id::MP4ALS => AV_CODEC_ID_MP4ALS, - Id::ATRAC1 => AV_CODEC_ID_ATRAC1, - Id::BINKAUDIO_RDFT => AV_CODEC_ID_BINKAUDIO_RDFT, - Id::BINKAUDIO_DCT => AV_CODEC_ID_BINKAUDIO_DCT, - Id::AAC_LATM => AV_CODEC_ID_AAC_LATM, - Id::QDMC => AV_CODEC_ID_QDMC, - Id::CELT => AV_CODEC_ID_CELT, - Id::G723_1 => AV_CODEC_ID_G723_1, - Id::G729 => AV_CODEC_ID_G729, - Id::SVX_EXP8 => AV_CODEC_ID_8SVX_EXP, - Id::SVX_FIB8 => AV_CODEC_ID_8SVX_FIB, - Id::BMV_AUDIO => AV_CODEC_ID_BMV_AUDIO, - Id::RALF => AV_CODEC_ID_RALF, - Id::IAC => AV_CODEC_ID_IAC, - Id::ILBC => AV_CODEC_ID_ILBC, - Id::OPUS => AV_CODEC_ID_OPUS, - Id::COMFORT_NOISE => AV_CODEC_ID_COMFORT_NOISE, - Id::TAK => AV_CODEC_ID_TAK, - Id::METASOUND => AV_CODEC_ID_METASOUND, - Id::PAF_AUDIO => AV_CODEC_ID_PAF_AUDIO, - Id::ON2AVC => AV_CODEC_ID_ON2AVC, - Id::DSS_SP => AV_CODEC_ID_DSS_SP, + /* audio codecs */ + Id::MP2 => AV_CODEC_ID_MP2, + Id::MP3 => AV_CODEC_ID_MP3, + Id::AAC => AV_CODEC_ID_AAC, + Id::AC3 => AV_CODEC_ID_AC3, + Id::DTS => AV_CODEC_ID_DTS, + Id::VORBIS => AV_CODEC_ID_VORBIS, + Id::DVAUDIO => AV_CODEC_ID_DVAUDIO, + Id::WMAV1 => AV_CODEC_ID_WMAV1, + Id::WMAV2 => AV_CODEC_ID_WMAV2, + Id::MACE3 => AV_CODEC_ID_MACE3, + Id::MACE6 => AV_CODEC_ID_MACE6, + Id::VMDAUDIO => AV_CODEC_ID_VMDAUDIO, + Id::FLAC => AV_CODEC_ID_FLAC, + Id::MP3ADU => AV_CODEC_ID_MP3ADU, + Id::MP3ON4 => AV_CODEC_ID_MP3ON4, + Id::SHORTEN => AV_CODEC_ID_SHORTEN, + Id::ALAC => AV_CODEC_ID_ALAC, + Id::WESTWOOD_SND1 => AV_CODEC_ID_WESTWOOD_SND1, + Id::GSM => AV_CODEC_ID_GSM, + Id::QDM2 => AV_CODEC_ID_QDM2, + Id::COOK => AV_CODEC_ID_COOK, + Id::TRUESPEECH => AV_CODEC_ID_TRUESPEECH, + Id::TTA => AV_CODEC_ID_TTA, + Id::SMACKAUDIO => AV_CODEC_ID_SMACKAUDIO, + Id::QCELP => AV_CODEC_ID_QCELP, + Id::WAVPACK => AV_CODEC_ID_WAVPACK, + Id::DSICINAUDIO => AV_CODEC_ID_DSICINAUDIO, + Id::IMC => AV_CODEC_ID_IMC, + Id::MUSEPACK7 => AV_CODEC_ID_MUSEPACK7, + Id::MLP => AV_CODEC_ID_MLP, + Id::GSM_MS => AV_CODEC_ID_GSM_MS, + Id::ATRAC3 => AV_CODEC_ID_ATRAC3, + #[cfg(feature = "ff_api_voxware")] + Id::VOXWARE => AV_CODEC_ID_VOXWARE, + Id::APE => AV_CODEC_ID_APE, + Id::NELLYMOSER => AV_CODEC_ID_NELLYMOSER, + Id::MUSEPACK8 => AV_CODEC_ID_MUSEPACK8, + Id::SPEEX => AV_CODEC_ID_SPEEX, + Id::WMAVOICE => AV_CODEC_ID_WMAVOICE, + Id::WMAPRO => AV_CODEC_ID_WMAPRO, + Id::WMALOSSLESS => AV_CODEC_ID_WMALOSSLESS, + Id::ATRAC3P => AV_CODEC_ID_ATRAC3P, + Id::EAC3 => AV_CODEC_ID_EAC3, + Id::SIPR => AV_CODEC_ID_SIPR, + Id::MP1 => AV_CODEC_ID_MP1, + Id::TWINVQ => AV_CODEC_ID_TWINVQ, + Id::TRUEHD => AV_CODEC_ID_TRUEHD, + Id::MP4ALS => AV_CODEC_ID_MP4ALS, + Id::ATRAC1 => AV_CODEC_ID_ATRAC1, + Id::BINKAUDIO_RDFT => AV_CODEC_ID_BINKAUDIO_RDFT, + Id::BINKAUDIO_DCT => AV_CODEC_ID_BINKAUDIO_DCT, + Id::AAC_LATM => AV_CODEC_ID_AAC_LATM, + Id::QDMC => AV_CODEC_ID_QDMC, + Id::CELT => AV_CODEC_ID_CELT, + Id::G723_1 => AV_CODEC_ID_G723_1, + Id::G729 => AV_CODEC_ID_G729, + Id::SVX_EXP8 => AV_CODEC_ID_8SVX_EXP, + Id::SVX_FIB8 => AV_CODEC_ID_8SVX_FIB, + Id::BMV_AUDIO => AV_CODEC_ID_BMV_AUDIO, + Id::RALF => AV_CODEC_ID_RALF, + Id::IAC => AV_CODEC_ID_IAC, + Id::ILBC => AV_CODEC_ID_ILBC, + Id::OPUS => AV_CODEC_ID_OPUS, + Id::COMFORT_NOISE => AV_CODEC_ID_COMFORT_NOISE, + Id::TAK => AV_CODEC_ID_TAK, + Id::METASOUND => AV_CODEC_ID_METASOUND, + Id::PAF_AUDIO => AV_CODEC_ID_PAF_AUDIO, + Id::ON2AVC => AV_CODEC_ID_ON2AVC, + Id::DSS_SP => AV_CODEC_ID_DSS_SP, - Id::FFWAVESYNTH => AV_CODEC_ID_FFWAVESYNTH, - Id::SONIC => AV_CODEC_ID_SONIC, - Id::SONIC_LS => AV_CODEC_ID_SONIC_LS, - Id::EVRC => AV_CODEC_ID_EVRC, - Id::SMV => AV_CODEC_ID_SMV, - Id::DSD_LSBF => AV_CODEC_ID_DSD_LSBF, - Id::DSD_MSBF => AV_CODEC_ID_DSD_MSBF, - Id::DSD_LSBF_PLANAR => AV_CODEC_ID_DSD_LSBF_PLANAR, - Id::DSD_MSBF_PLANAR => AV_CODEC_ID_DSD_MSBF_PLANAR, - Id::_4GV => AV_CODEC_ID_4GV, - Id::INTERPLAY_ACM => AV_CODEC_ID_INTERPLAY_ACM, - Id::XMA1 => AV_CODEC_ID_XMA1, - Id::XMA2 => AV_CODEC_ID_XMA2, - Id::DST => AV_CODEC_ID_DST, + Id::FFWAVESYNTH => AV_CODEC_ID_FFWAVESYNTH, + Id::SONIC => AV_CODEC_ID_SONIC, + Id::SONIC_LS => AV_CODEC_ID_SONIC_LS, + Id::EVRC => AV_CODEC_ID_EVRC, + Id::SMV => AV_CODEC_ID_SMV, + Id::DSD_LSBF => AV_CODEC_ID_DSD_LSBF, + Id::DSD_MSBF => AV_CODEC_ID_DSD_MSBF, + Id::DSD_LSBF_PLANAR => AV_CODEC_ID_DSD_LSBF_PLANAR, + Id::DSD_MSBF_PLANAR => AV_CODEC_ID_DSD_MSBF_PLANAR, + Id::_4GV => AV_CODEC_ID_4GV, + Id::INTERPLAY_ACM => AV_CODEC_ID_INTERPLAY_ACM, + Id::XMA1 => AV_CODEC_ID_XMA1, + Id::XMA2 => AV_CODEC_ID_XMA2, + Id::DST => AV_CODEC_ID_DST, - /* subtitle codecs */ - Id::DVD_SUBTITLE => AV_CODEC_ID_DVD_SUBTITLE, - Id::DVB_SUBTITLE => AV_CODEC_ID_DVB_SUBTITLE, - Id::TEXT => AV_CODEC_ID_TEXT, - Id::XSUB => AV_CODEC_ID_XSUB, - Id::SSA => AV_CODEC_ID_SSA, - Id::MOV_TEXT => AV_CODEC_ID_MOV_TEXT, - Id::HDMV_PGS_SUBTITLE => AV_CODEC_ID_HDMV_PGS_SUBTITLE, - Id::DVB_TELETEXT => AV_CODEC_ID_DVB_TELETEXT, - Id::SRT => AV_CODEC_ID_SRT, + /* subtitle codecs */ + Id::DVD_SUBTITLE => AV_CODEC_ID_DVD_SUBTITLE, + Id::DVB_SUBTITLE => AV_CODEC_ID_DVB_SUBTITLE, + Id::TEXT => AV_CODEC_ID_TEXT, + Id::XSUB => AV_CODEC_ID_XSUB, + Id::SSA => AV_CODEC_ID_SSA, + Id::MOV_TEXT => AV_CODEC_ID_MOV_TEXT, + Id::HDMV_PGS_SUBTITLE => AV_CODEC_ID_HDMV_PGS_SUBTITLE, + Id::DVB_TELETEXT => AV_CODEC_ID_DVB_TELETEXT, + Id::SRT => AV_CODEC_ID_SRT, - Id::MICRODVD => AV_CODEC_ID_MICRODVD, - Id::EIA_608 => AV_CODEC_ID_EIA_608, - Id::JACOSUB => AV_CODEC_ID_JACOSUB, - Id::SAMI => AV_CODEC_ID_SAMI, - Id::REALTEXT => AV_CODEC_ID_REALTEXT, - Id::STL => AV_CODEC_ID_STL, - Id::SUBVIEWER1 => AV_CODEC_ID_SUBVIEWER1, - Id::SUBVIEWER => AV_CODEC_ID_SUBVIEWER, - Id::SUBRIP => AV_CODEC_ID_SUBRIP, - Id::WEBVTT => AV_CODEC_ID_WEBVTT, - Id::MPL2 => AV_CODEC_ID_MPL2, - Id::VPLAYER => AV_CODEC_ID_VPLAYER, - Id::PJS => AV_CODEC_ID_PJS, - Id::ASS => AV_CODEC_ID_ASS, - Id::HDMV_TEXT_SUBTITLE => AV_CODEC_ID_HDMV_TEXT_SUBTITLE, + Id::MICRODVD => AV_CODEC_ID_MICRODVD, + Id::EIA_608 => AV_CODEC_ID_EIA_608, + Id::JACOSUB => AV_CODEC_ID_JACOSUB, + Id::SAMI => AV_CODEC_ID_SAMI, + Id::REALTEXT => AV_CODEC_ID_REALTEXT, + Id::STL => AV_CODEC_ID_STL, + Id::SUBVIEWER1 => AV_CODEC_ID_SUBVIEWER1, + Id::SUBVIEWER => AV_CODEC_ID_SUBVIEWER, + Id::SUBRIP => AV_CODEC_ID_SUBRIP, + Id::WEBVTT => AV_CODEC_ID_WEBVTT, + Id::MPL2 => AV_CODEC_ID_MPL2, + Id::VPLAYER => AV_CODEC_ID_VPLAYER, + Id::PJS => AV_CODEC_ID_PJS, + Id::ASS => AV_CODEC_ID_ASS, + Id::HDMV_TEXT_SUBTITLE => AV_CODEC_ID_HDMV_TEXT_SUBTITLE, - /* other specific kind of codecs (generally used for attachments) */ - Id::TTF => AV_CODEC_ID_TTF, + /* other specific kind of codecs (generally used for attachments) */ + Id::TTF => AV_CODEC_ID_TTF, - Id::SCTE_35 => AV_CODEC_ID_SCTE_35, - Id::BINTEXT => AV_CODEC_ID_BINTEXT, - Id::XBIN => AV_CODEC_ID_XBIN, - Id::IDF => AV_CODEC_ID_IDF, - Id::OTF => AV_CODEC_ID_OTF, - Id::SMPTE_KLV => AV_CODEC_ID_SMPTE_KLV, - Id::DVD_NAV => AV_CODEC_ID_DVD_NAV, - Id::TIMED_ID3 => AV_CODEC_ID_TIMED_ID3, - Id::BIN_DATA => AV_CODEC_ID_BIN_DATA, + Id::SCTE_35 => AV_CODEC_ID_SCTE_35, + Id::BINTEXT => AV_CODEC_ID_BINTEXT, + Id::XBIN => AV_CODEC_ID_XBIN, + Id::IDF => AV_CODEC_ID_IDF, + Id::OTF => AV_CODEC_ID_OTF, + Id::SMPTE_KLV => AV_CODEC_ID_SMPTE_KLV, + Id::DVD_NAV => AV_CODEC_ID_DVD_NAV, + Id::TIMED_ID3 => AV_CODEC_ID_TIMED_ID3, + Id::BIN_DATA => AV_CODEC_ID_BIN_DATA, - Id::PROBE => AV_CODEC_ID_PROBE, + Id::PROBE => AV_CODEC_ID_PROBE, - Id::MPEG2TS => AV_CODEC_ID_MPEG2TS, - Id::MPEG4SYSTEMS => AV_CODEC_ID_MPEG4SYSTEMS, - Id::FFMETADATA => AV_CODEC_ID_FFMETADATA, - Id::WRAPPED_AVFRAME => AV_CODEC_ID_WRAPPED_AVFRAME, + Id::MPEG2TS => AV_CODEC_ID_MPEG2TS, + Id::MPEG4SYSTEMS => AV_CODEC_ID_MPEG4SYSTEMS, + Id::FFMETADATA => AV_CODEC_ID_FFMETADATA, + Id::WRAPPED_AVFRAME => AV_CODEC_ID_WRAPPED_AVFRAME, - Id::PSD => AV_CODEC_ID_PSD, - Id::PIXLET => AV_CODEC_ID_PIXLET, - Id::SPEEDHQ => AV_CODEC_ID_SPEEDHQ, - Id::FMVC => AV_CODEC_ID_FMVC, - Id::CLEARVIDEO => AV_CODEC_ID_CLEARVIDEO, - Id::SCPR => AV_CODEC_ID_SCPR, - Id::XPM => AV_CODEC_ID_XPM, - Id::AV1 => AV_CODEC_ID_AV1, - Id::PCM_F16LE => AV_CODEC_ID_PCM_F16LE, - Id::PCM_F24LE => AV_CODEC_ID_PCM_F24LE, - Id::ATRAC3AL => AV_CODEC_ID_ATRAC3AL, - Id::ATRAC3PAL => AV_CODEC_ID_ATRAC3PAL, + Id::PSD => AV_CODEC_ID_PSD, + Id::PIXLET => AV_CODEC_ID_PIXLET, + Id::SPEEDHQ => AV_CODEC_ID_SPEEDHQ, + Id::FMVC => AV_CODEC_ID_FMVC, + Id::CLEARVIDEO => AV_CODEC_ID_CLEARVIDEO, + Id::SCPR => AV_CODEC_ID_SCPR, + Id::XPM => AV_CODEC_ID_XPM, + Id::AV1 => AV_CODEC_ID_AV1, + Id::PCM_F16LE => AV_CODEC_ID_PCM_F16LE, + Id::PCM_F24LE => AV_CODEC_ID_PCM_F24LE, + Id::ATRAC3AL => AV_CODEC_ID_ATRAC3AL, + Id::ATRAC3PAL => AV_CODEC_ID_ATRAC3PAL, - Id::BITPACKED => AV_CODEC_ID_BITPACKED, - Id::MSCC => AV_CODEC_ID_MSCC, - Id::SRGC => AV_CODEC_ID_SRGC, - Id::SVG => AV_CODEC_ID_SVG, - Id::GDV => AV_CODEC_ID_GDV, - Id::FITS => AV_CODEC_ID_FITS, - Id::GREMLIN_DPCM => AV_CODEC_ID_GREMLIN_DPCM, - Id::DOLBY_E => AV_CODEC_ID_DOLBY_E, - } - } + Id::BITPACKED => AV_CODEC_ID_BITPACKED, + Id::MSCC => AV_CODEC_ID_MSCC, + Id::SRGC => AV_CODEC_ID_SRGC, + Id::SVG => AV_CODEC_ID_SVG, + Id::GDV => AV_CODEC_ID_GDV, + Id::FITS => AV_CODEC_ID_FITS, + Id::GREMLIN_DPCM => AV_CODEC_ID_GREMLIN_DPCM, + Id::DOLBY_E => AV_CODEC_ID_DOLBY_E, + } + } } diff --git a/src/codec/mod.rs b/src/codec/mod.rs index b17dc36..e7da376 100644 --- a/src/codec/mod.rs +++ b/src/codec/mod.rs @@ -29,8 +29,8 @@ pub use self::video::Video; pub mod audio; pub use self::audio::Audio; -pub mod field_order; pub mod audio_service; +pub mod field_order; pub mod compliance; pub use self::compliance::Compliance; @@ -43,8 +43,8 @@ pub use self::profile::Profile; pub mod threading; -pub mod encoder; pub mod decoder; +pub mod encoder; pub mod traits; use std::ffi::CStr; @@ -53,19 +53,13 @@ use std::str::from_utf8_unchecked; use ffi::*; pub fn version() -> u32 { - unsafe { - avcodec_version() - } + unsafe { avcodec_version() } } pub fn configuration() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avcodec_configuration()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avcodec_configuration()).to_bytes()) } } pub fn license() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avcodec_license()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avcodec_license()).to_bytes()) } } diff --git a/src/codec/packet/borrow.rs b/src/codec/packet/borrow.rs index 02f0ec4..65c5386 100644 --- a/src/codec/packet/borrow.rs +++ b/src/codec/packet/borrow.rs @@ -1,54 +1,54 @@ use std::mem; use std::ptr; -use libc::c_int; -use ffi::*; use super::Ref; +use ffi::*; +use libc::c_int; pub struct Borrow<'a> { - packet: AVPacket, - data: &'a [u8], + packet: AVPacket, + data: &'a [u8], } impl<'a> Borrow<'a> { - pub fn new(data: &[u8]) -> Borrow { - unsafe { - let mut packet: AVPacket = mem::zeroed(); + pub fn new(data: &[u8]) -> Borrow { + unsafe { + let mut packet: AVPacket = mem::zeroed(); - packet.data = data.as_ptr() as *mut _; - packet.size = data.len() as c_int; + packet.data = data.as_ptr() as *mut _; + packet.size = data.len() as c_int; - Borrow { - packet: packet, - data: data, - } - } - } + Borrow { + packet: packet, + data: data, + } + } + } - #[inline] - pub fn size(&self) -> usize { - self.packet.size as usize - } + #[inline] + pub fn size(&self) -> usize { + self.packet.size as usize + } - #[inline] - pub fn data(&self) -> Option<&[u8]> { - Some(self.data) - } + #[inline] + pub fn data(&self) -> Option<&[u8]> { + Some(self.data) + } } impl<'a> Ref for Borrow<'a> { - fn as_ptr(&self) -> *const AVPacket { - &self.packet - } + fn as_ptr(&self) -> *const AVPacket { + &self.packet + } } impl<'a> Drop for Borrow<'a> { - fn drop(&mut self) { - unsafe { - self.packet.data = ptr::null_mut(); - self.packet.size = 0; + fn drop(&mut self) { + unsafe { + self.packet.data = ptr::null_mut(); + self.packet.size = 0; - av_free_packet(&mut self.packet); - } - } + av_free_packet(&mut self.packet); + } + } } diff --git a/src/codec/packet/flag.rs b/src/codec/packet/flag.rs index 45ccff4..dcbcfa5 100644 --- a/src/codec/packet/flag.rs +++ b/src/codec/packet/flag.rs @@ -1,9 +1,9 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Flags: c_int { - const KEY = AV_PKT_FLAG_KEY; - const CORRUPT = AV_PKT_FLAG_CORRUPT; - } + pub struct Flags: c_int { + const KEY = AV_PKT_FLAG_KEY; + const CORRUPT = AV_PKT_FLAG_CORRUPT; + } } diff --git a/src/codec/packet/mod.rs b/src/codec/packet/mod.rs index 4e1ce3b..1e46e59 100644 --- a/src/codec/packet/mod.rs +++ b/src/codec/packet/mod.rs @@ -1,5 +1,5 @@ pub mod traits; -pub use self::traits::{Ref, Mut}; +pub use self::traits::{Mut, Ref}; pub mod packet; pub use self::packet::Packet; diff --git a/src/codec/packet/packet.rs b/src/codec/packet/packet.rs index b21695d..a63bf9c 100644 --- a/src/codec/packet/packet.rs +++ b/src/codec/packet/packet.rs @@ -2,308 +2,316 @@ use std::marker::PhantomData; use std::mem; use std::slice; -use libc::c_int; +use super::{flag, Borrow, Flags, Mut, Ref, SideData}; use ffi::*; -use ::{Error, Rational, format}; -use super::{flag, Flags, SideData, Ref, Mut, Borrow}; +use libc::c_int; +use {format, Error, Rational}; pub struct Packet(AVPacket); -unsafe impl Send for Packet { } -unsafe impl Sync for Packet { } +unsafe impl Send for Packet {} +unsafe impl Sync for Packet {} impl Packet { - #[inline(always)] - pub unsafe fn is_empty(&self) -> bool { - self.0.size == 0 - } + #[inline(always)] + pub unsafe fn is_empty(&self) -> bool { + self.0.size == 0 + } } impl Packet { - #[inline] - pub fn empty() -> Self { - unsafe { - let mut pkt: AVPacket = mem::zeroed(); + #[inline] + pub fn empty() -> Self { + unsafe { + let mut pkt: AVPacket = mem::zeroed(); - av_init_packet(&mut pkt); + av_init_packet(&mut pkt); - Packet(pkt) - } - } + Packet(pkt) + } + } - #[inline] - pub fn new(size: usize) -> Self { - unsafe { - let mut pkt: AVPacket = mem::zeroed(); + #[inline] + pub fn new(size: usize) -> Self { + unsafe { + let mut pkt: AVPacket = mem::zeroed(); - av_init_packet(&mut pkt); - av_new_packet(&mut pkt, size as c_int); + av_init_packet(&mut pkt); + av_new_packet(&mut pkt, size as c_int); - Packet(pkt) - } - } + Packet(pkt) + } + } - #[inline] - pub fn copy(data: &[u8]) -> Self { - use std::io::Write; + #[inline] + pub fn copy(data: &[u8]) -> Self { + use std::io::Write; - let mut packet = Packet::new(data.len()); - packet.data_mut().unwrap().write(data).unwrap(); + let mut packet = Packet::new(data.len()); + packet.data_mut().unwrap().write_all(data).unwrap(); - packet - } + packet + } - #[inline] - pub fn borrow(data: &[u8]) -> Borrow { - Borrow::new(data) - } + #[inline] + pub fn borrow(data: &[u8]) -> Borrow { + Borrow::new(data) + } - #[inline] - pub fn shrink(&mut self, size: usize) { - unsafe { - av_shrink_packet(&mut self.0, size as c_int); - } - } + #[inline] + pub fn shrink(&mut self, size: usize) { + unsafe { + av_shrink_packet(&mut self.0, size as c_int); + } + } - #[inline] - pub fn grow(&mut self, size: usize) { - unsafe { - av_grow_packet(&mut self.0, size as c_int); - } - } + #[inline] + pub fn grow(&mut self, size: usize) { + unsafe { + av_grow_packet(&mut self.0, size as c_int); + } + } - #[inline] - pub fn rescale_ts(&mut self, source: S, destination: D) - where S: Into, - D: Into - { - unsafe { - av_packet_rescale_ts(self.as_mut_ptr(), source.into().into(), destination.into().into()); - } - } + #[inline] + pub fn rescale_ts(&mut self, source: S, destination: D) + where + S: Into, + D: Into, + { + unsafe { + av_packet_rescale_ts( + self.as_mut_ptr(), + source.into().into(), + destination.into().into(), + ); + } + } - #[inline] - pub fn flags(&self) -> Flags { - Flags::from_bits_truncate(self.0.flags) - } + #[inline] + pub fn flags(&self) -> Flags { + Flags::from_bits_truncate(self.0.flags) + } - #[inline] - pub fn set_flags(&mut self, value: Flags) { - self.0.flags = value.bits(); - } + #[inline] + pub fn set_flags(&mut self, value: Flags) { + self.0.flags = value.bits(); + } - #[inline] - pub fn is_key(&self) -> bool { - self.flags().contains(flag::KEY) - } + #[inline] + pub fn is_key(&self) -> bool { + self.flags().contains(flag::KEY) + } - #[inline] - pub fn is_corrupt(&self) -> bool { - self.flags().contains(flag::CORRUPT) - } + #[inline] + pub fn is_corrupt(&self) -> bool { + self.flags().contains(flag::CORRUPT) + } - #[inline] - pub fn stream(&self) -> usize { - self.0.stream_index as usize - } + #[inline] + pub fn stream(&self) -> usize { + self.0.stream_index as usize + } - #[inline] - pub fn set_stream(&mut self, index: usize) { - self.0.stream_index = index as c_int; - } + #[inline] + pub fn set_stream(&mut self, index: usize) { + self.0.stream_index = index as c_int; + } - #[inline] - pub fn pts(&self) -> Option { - match self.0.pts { - AV_NOPTS_VALUE => None, - pts => Some(pts as i64), - } - } + #[inline] + pub fn pts(&self) -> Option { + match self.0.pts { + AV_NOPTS_VALUE => None, + pts => Some(pts as i64), + } + } - #[inline] - pub fn set_pts(&mut self, value: Option) { - unsafe { - (*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE); - } - } + #[inline] + pub fn set_pts(&mut self, value: Option) { + unsafe { + (*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE); + } + } - #[inline] - pub fn dts(&self) -> Option { - match self.0.dts { - AV_NOPTS_VALUE => None, - dts => Some(dts as i64), - } - } + #[inline] + pub fn dts(&self) -> Option { + match self.0.dts { + AV_NOPTS_VALUE => None, + dts => Some(dts as i64), + } + } - #[inline] - pub fn set_dts(&mut self, value: Option) { - unsafe { - (*self.as_mut_ptr()).dts = value.unwrap_or(AV_NOPTS_VALUE); - } - } + #[inline] + pub fn set_dts(&mut self, value: Option) { + unsafe { + (*self.as_mut_ptr()).dts = value.unwrap_or(AV_NOPTS_VALUE); + } + } - #[inline] - pub fn size(&self) -> usize { - self.0.size as usize - } + #[inline] + pub fn size(&self) -> usize { + self.0.size as usize + } - #[inline] - pub fn duration(&self) -> i64 { - self.0.duration as i64 - } + #[inline] + pub fn duration(&self) -> i64 { + self.0.duration as i64 + } - #[inline] - pub fn position(&self) -> isize { - self.0.pos as isize - } + #[inline] + pub fn position(&self) -> isize { + self.0.pos as isize + } - #[inline] - pub fn convergence(&self) -> isize { - self.0.convergence_duration as isize - } + #[inline] + pub fn convergence(&self) -> isize { + self.0.convergence_duration as isize + } - #[inline] - pub fn side_data(&self) -> SideDataIter { - SideDataIter::new(&self.0) - } + #[inline] + pub fn side_data(&self) -> SideDataIter { + SideDataIter::new(&self.0) + } - #[inline] - pub fn data(&self) -> Option<&[u8]> { - unsafe { - if self.0.data.is_null() { - None - } - else { - Some(slice::from_raw_parts(self.0.data, self.0.size as usize)) - } - } - } + #[inline] + pub fn data(&self) -> Option<&[u8]> { + unsafe { + if self.0.data.is_null() { + None + } else { + Some(slice::from_raw_parts(self.0.data, self.0.size as usize)) + } + } + } - #[inline] - pub fn data_mut(&mut self) -> Option<&mut [u8]> { - unsafe { - if self.0.data.is_null() { - None - } - else { - Some(slice::from_raw_parts_mut(self.0.data, self.0.size as usize)) - } - } - } + #[inline] + pub fn data_mut(&mut self) -> Option<&mut [u8]> { + unsafe { + if self.0.data.is_null() { + None + } else { + Some(slice::from_raw_parts_mut(self.0.data, self.0.size as usize)) + } + } + } - #[inline] - pub fn read(&mut self, format: &mut format::context::Input) -> Result<(), Error> { - unsafe { - match av_read_frame(format.as_mut_ptr(), self.as_mut_ptr()) { - 0 => Ok(()), - e => Err(Error::from(e)) - } - } - } + #[inline] + pub fn read(&mut self, format: &mut format::context::Input) -> Result<(), Error> { + unsafe { + match av_read_frame(format.as_mut_ptr(), self.as_mut_ptr()) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - #[inline] - pub fn write(&self, format: &mut format::context::Output) -> Result { - unsafe { - if self.is_empty() { - return Err(Error::InvalidData); - } + #[inline] + pub fn write(&self, format: &mut format::context::Output) -> Result { + unsafe { + if self.is_empty() { + return Err(Error::InvalidData); + } - match av_write_frame(format.as_mut_ptr(), self.as_ptr() as *mut _) { - 1 => Ok(true), - 0 => Ok(false), - e => Err(Error::from(e)) - } - } - } + match av_write_frame(format.as_mut_ptr(), self.as_ptr() as *mut _) { + 1 => Ok(true), + 0 => Ok(false), + e => Err(Error::from(e)), + } + } + } - #[inline] - pub fn write_interleaved(&self, format: &mut format::context::Output) -> Result { - unsafe { - if self.is_empty() { - return Err(Error::InvalidData); - } + #[inline] + pub fn write_interleaved(&self, format: &mut format::context::Output) -> Result { + unsafe { + if self.is_empty() { + return Err(Error::InvalidData); + } - match av_interleaved_write_frame(format.as_mut_ptr(), self.as_ptr() as *mut _) { - 1 => Ok(true), - 0 => Ok(false), - e => Err(Error::from(e)) - } - } - } + match av_interleaved_write_frame(format.as_mut_ptr(), self.as_ptr() as *mut _) { + 1 => Ok(true), + 0 => Ok(false), + e => Err(Error::from(e)), + } + } + } } impl Ref for Packet { - fn as_ptr(&self) -> *const AVPacket { - &self.0 - } + fn as_ptr(&self) -> *const AVPacket { + &self.0 + } } impl Mut for Packet { - fn as_mut_ptr(&mut self) -> *mut AVPacket { - &mut self.0 - } + fn as_mut_ptr(&mut self) -> *mut AVPacket { + &mut self.0 + } } impl Clone for Packet { - #[inline] - fn clone(&self) -> Self { - let mut pkt = Packet::empty(); - pkt.clone_from(self); + #[inline] + fn clone(&self) -> Self { + let mut pkt = Packet::empty(); + pkt.clone_from(self); - pkt - } + pkt + } - #[inline] - fn clone_from(&mut self, source: &Self) { - unsafe { - av_copy_packet(&mut self.0, &source.0); - } - } + #[inline] + fn clone_from(&mut self, source: &Self) { + unsafe { + av_copy_packet(&mut self.0, &source.0); + } + } } impl Drop for Packet { - fn drop(&mut self) { - unsafe { - av_packet_unref(&mut self.0); - } - } + fn drop(&mut self) { + unsafe { + av_packet_unref(&mut self.0); + } + } } pub struct SideDataIter<'a> { - ptr: *const AVPacket, - cur: c_int, + ptr: *const AVPacket, + cur: c_int, - _marker: PhantomData<&'a Packet>, + _marker: PhantomData<&'a Packet>, } impl<'a> SideDataIter<'a> { - pub fn new(ptr: *const AVPacket) -> Self { - SideDataIter { ptr: ptr, cur: 0, _marker: PhantomData } - } + pub fn new(ptr: *const AVPacket) -> Self { + SideDataIter { + ptr: ptr, + cur: 0, + _marker: PhantomData, + } + } } impl<'a> Iterator for SideDataIter<'a> { - type Item = SideData<'a>; + type Item = SideData<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.cur >= (*self.ptr).side_data_elems { - None - } - else { - self.cur += 1; - Some(SideData::wrap((*self.ptr).side_data.offset((self.cur - 1) as isize))) - } - } - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.cur >= (*self.ptr).side_data_elems { + None + } else { + self.cur += 1; + Some(SideData::wrap( + (*self.ptr).side_data.offset((self.cur - 1) as isize), + )) + } + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.ptr).side_data_elems as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.ptr).side_data_elems as usize; - (length - self.cur as usize, Some(length - self.cur as usize)) - } - } + (length - self.cur as usize, Some(length - self.cur as usize)) + } + } } -impl<'a> ExactSizeIterator for SideDataIter<'a> { } +impl<'a> ExactSizeIterator for SideDataIter<'a> {} diff --git a/src/codec/packet/side_data.rs b/src/codec/packet/side_data.rs index 0a081ea..6dd5cb5 100644 --- a/src/codec/packet/side_data.rs +++ b/src/codec/packet/side_data.rs @@ -1,132 +1,131 @@ use std::marker::PhantomData; use std::slice; -use ffi::*; -use ffi::AVPacketSideDataType::*; use super::Packet; +use ffi::AVPacketSideDataType::*; +use ffi::*; #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Type { - Palette, - NewExtraData, - ParamChange, - H263MbInfo, - ReplayGain, - DisplayMatrix, - Stereo3d, - AudioServiceType, - QualityStats, - FallbackTrack, - CBPProperties, - SkipSamples, - JpDualMono, - StringsMetadata, - SubtitlePosition, - MatroskaBlockAdditional, - WebVTTIdentifier, - WebVTTSettings, - MetadataUpdate, - MPEGTSStreamID, - MasteringDisplayMetadata, - DataSpherical, - DataNb, + Palette, + NewExtraData, + ParamChange, + H263MbInfo, + ReplayGain, + DisplayMatrix, + Stereo3d, + AudioServiceType, + QualityStats, + FallbackTrack, + CBPProperties, + SkipSamples, + JpDualMono, + StringsMetadata, + SubtitlePosition, + MatroskaBlockAdditional, + WebVTTIdentifier, + WebVTTSettings, + MetadataUpdate, + MPEGTSStreamID, + MasteringDisplayMetadata, + DataSpherical, + DataNb, - ContentLightLevel, - A53CC, + ContentLightLevel, + A53CC, } impl From for Type { - fn from(value: AVPacketSideDataType) -> Self { - match value { - AV_PKT_DATA_PALETTE => Type::Palette, - AV_PKT_DATA_NEW_EXTRADATA => Type::NewExtraData, - AV_PKT_DATA_PARAM_CHANGE => Type::ParamChange, - AV_PKT_DATA_H263_MB_INFO => Type::H263MbInfo, - AV_PKT_DATA_REPLAYGAIN => Type::ReplayGain, - AV_PKT_DATA_DISPLAYMATRIX => Type::DisplayMatrix, - AV_PKT_DATA_STEREO3D => Type::Stereo3d, - AV_PKT_DATA_AUDIO_SERVICE_TYPE => Type::AudioServiceType, - AV_PKT_DATA_QUALITY_STATS => Type::QualityStats, - AV_PKT_DATA_FALLBACK_TRACK => Type::FallbackTrack, - AV_PKT_DATA_CPB_PROPERTIES => Type::CBPProperties, - AV_PKT_DATA_SKIP_SAMPLES => Type::SkipSamples, - AV_PKT_DATA_JP_DUALMONO => Type::JpDualMono, - AV_PKT_DATA_STRINGS_METADATA => Type::StringsMetadata, - AV_PKT_DATA_SUBTITLE_POSITION => Type::SubtitlePosition, - AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL => Type::MatroskaBlockAdditional, - AV_PKT_DATA_WEBVTT_IDENTIFIER => Type::WebVTTIdentifier, - AV_PKT_DATA_WEBVTT_SETTINGS => Type::WebVTTSettings, - AV_PKT_DATA_METADATA_UPDATE => Type::MetadataUpdate, - AV_PKT_DATA_MPEGTS_STREAM_ID => Type::MPEGTSStreamID, - AV_PKT_DATA_MASTERING_DISPLAY_METADATA => Type::MasteringDisplayMetadata, - AV_PKT_DATA_SPHERICAL => Type::DataSpherical, - AV_PKT_DATA_NB => Type::DataNb, + fn from(value: AVPacketSideDataType) -> Self { + match value { + AV_PKT_DATA_PALETTE => Type::Palette, + AV_PKT_DATA_NEW_EXTRADATA => Type::NewExtraData, + AV_PKT_DATA_PARAM_CHANGE => Type::ParamChange, + AV_PKT_DATA_H263_MB_INFO => Type::H263MbInfo, + AV_PKT_DATA_REPLAYGAIN => Type::ReplayGain, + AV_PKT_DATA_DISPLAYMATRIX => Type::DisplayMatrix, + AV_PKT_DATA_STEREO3D => Type::Stereo3d, + AV_PKT_DATA_AUDIO_SERVICE_TYPE => Type::AudioServiceType, + AV_PKT_DATA_QUALITY_STATS => Type::QualityStats, + AV_PKT_DATA_FALLBACK_TRACK => Type::FallbackTrack, + AV_PKT_DATA_CPB_PROPERTIES => Type::CBPProperties, + AV_PKT_DATA_SKIP_SAMPLES => Type::SkipSamples, + AV_PKT_DATA_JP_DUALMONO => Type::JpDualMono, + AV_PKT_DATA_STRINGS_METADATA => Type::StringsMetadata, + AV_PKT_DATA_SUBTITLE_POSITION => Type::SubtitlePosition, + AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL => Type::MatroskaBlockAdditional, + AV_PKT_DATA_WEBVTT_IDENTIFIER => Type::WebVTTIdentifier, + AV_PKT_DATA_WEBVTT_SETTINGS => Type::WebVTTSettings, + AV_PKT_DATA_METADATA_UPDATE => Type::MetadataUpdate, + AV_PKT_DATA_MPEGTS_STREAM_ID => Type::MPEGTSStreamID, + AV_PKT_DATA_MASTERING_DISPLAY_METADATA => Type::MasteringDisplayMetadata, + AV_PKT_DATA_SPHERICAL => Type::DataSpherical, + AV_PKT_DATA_NB => Type::DataNb, - AV_PKT_DATA_CONTENT_LIGHT_LEVEL => Type::ContentLightLevel, - AV_PKT_DATA_A53_CC => Type::A53CC, - } - } + AV_PKT_DATA_CONTENT_LIGHT_LEVEL => Type::ContentLightLevel, + AV_PKT_DATA_A53_CC => Type::A53CC, + } + } } impl Into for Type { - fn into(self) -> AVPacketSideDataType { - match self { - Type::Palette => AV_PKT_DATA_PALETTE, - Type::NewExtraData => AV_PKT_DATA_NEW_EXTRADATA, - Type::ParamChange => AV_PKT_DATA_PARAM_CHANGE, - Type::H263MbInfo => AV_PKT_DATA_H263_MB_INFO, - Type::ReplayGain => AV_PKT_DATA_REPLAYGAIN, - Type::DisplayMatrix => AV_PKT_DATA_DISPLAYMATRIX, - Type::Stereo3d => AV_PKT_DATA_STEREO3D, - Type::AudioServiceType => AV_PKT_DATA_AUDIO_SERVICE_TYPE, - Type::QualityStats => AV_PKT_DATA_QUALITY_STATS, - Type::FallbackTrack => AV_PKT_DATA_FALLBACK_TRACK, - Type::CBPProperties => AV_PKT_DATA_CPB_PROPERTIES, - Type::SkipSamples => AV_PKT_DATA_SKIP_SAMPLES, - Type::JpDualMono => AV_PKT_DATA_JP_DUALMONO, - Type::StringsMetadata => AV_PKT_DATA_STRINGS_METADATA, - Type::SubtitlePosition => AV_PKT_DATA_SUBTITLE_POSITION, - Type::MatroskaBlockAdditional => AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, - Type::WebVTTIdentifier => AV_PKT_DATA_WEBVTT_IDENTIFIER, - Type::WebVTTSettings => AV_PKT_DATA_WEBVTT_SETTINGS, - Type::MetadataUpdate => AV_PKT_DATA_METADATA_UPDATE, - Type::MPEGTSStreamID => AV_PKT_DATA_MPEGTS_STREAM_ID, - Type::MasteringDisplayMetadata => AV_PKT_DATA_MASTERING_DISPLAY_METADATA, - Type::DataSpherical => AV_PKT_DATA_SPHERICAL, - Type::DataNb => AV_PKT_DATA_NB, + fn into(self) -> AVPacketSideDataType { + match self { + Type::Palette => AV_PKT_DATA_PALETTE, + Type::NewExtraData => AV_PKT_DATA_NEW_EXTRADATA, + Type::ParamChange => AV_PKT_DATA_PARAM_CHANGE, + Type::H263MbInfo => AV_PKT_DATA_H263_MB_INFO, + Type::ReplayGain => AV_PKT_DATA_REPLAYGAIN, + Type::DisplayMatrix => AV_PKT_DATA_DISPLAYMATRIX, + Type::Stereo3d => AV_PKT_DATA_STEREO3D, + Type::AudioServiceType => AV_PKT_DATA_AUDIO_SERVICE_TYPE, + Type::QualityStats => AV_PKT_DATA_QUALITY_STATS, + Type::FallbackTrack => AV_PKT_DATA_FALLBACK_TRACK, + Type::CBPProperties => AV_PKT_DATA_CPB_PROPERTIES, + Type::SkipSamples => AV_PKT_DATA_SKIP_SAMPLES, + Type::JpDualMono => AV_PKT_DATA_JP_DUALMONO, + Type::StringsMetadata => AV_PKT_DATA_STRINGS_METADATA, + Type::SubtitlePosition => AV_PKT_DATA_SUBTITLE_POSITION, + Type::MatroskaBlockAdditional => AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, + Type::WebVTTIdentifier => AV_PKT_DATA_WEBVTT_IDENTIFIER, + Type::WebVTTSettings => AV_PKT_DATA_WEBVTT_SETTINGS, + Type::MetadataUpdate => AV_PKT_DATA_METADATA_UPDATE, + Type::MPEGTSStreamID => AV_PKT_DATA_MPEGTS_STREAM_ID, + Type::MasteringDisplayMetadata => AV_PKT_DATA_MASTERING_DISPLAY_METADATA, + Type::DataSpherical => AV_PKT_DATA_SPHERICAL, + Type::DataNb => AV_PKT_DATA_NB, - Type::ContentLightLevel => AV_PKT_DATA_CONTENT_LIGHT_LEVEL, - Type::A53CC => AV_PKT_DATA_A53_CC, - } - } + Type::ContentLightLevel => AV_PKT_DATA_CONTENT_LIGHT_LEVEL, + Type::A53CC => AV_PKT_DATA_A53_CC, + } + } } pub struct SideData<'a> { - ptr: *mut AVPacketSideData, + ptr: *mut AVPacketSideData, - _marker: PhantomData<&'a Packet> + _marker: PhantomData<&'a Packet>, } impl<'a> SideData<'a> { - pub unsafe fn wrap(ptr: *mut AVPacketSideData) -> Self { - SideData { ptr: ptr, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *mut AVPacketSideData) -> Self { + SideData { + ptr: ptr, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVPacketSideData { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVPacketSideData { + self.ptr as *const _ + } } impl<'a> SideData<'a> { - pub fn kind(&self) -> Type { - unsafe { - Type::from((*self.as_ptr()).type_) - } - } + pub fn kind(&self) -> Type { + unsafe { Type::from((*self.as_ptr()).type_) } + } - pub fn data(&self) -> &[u8] { - unsafe { - slice::from_raw_parts((*self.as_ptr()).data, (*self.as_ptr()).size as usize) - } - } + pub fn data(&self) -> &[u8] { + unsafe { slice::from_raw_parts((*self.as_ptr()).data, (*self.as_ptr()).size as usize) } + } } diff --git a/src/codec/packet/traits.rs b/src/codec/packet/traits.rs index affe3bc..fb266df 100644 --- a/src/codec/packet/traits.rs +++ b/src/codec/packet/traits.rs @@ -1,9 +1,9 @@ use ffi::*; pub trait Ref { - fn as_ptr(&self) -> *const AVPacket; + fn as_ptr(&self) -> *const AVPacket; } pub trait Mut { - fn as_mut_ptr(&mut self) -> *mut AVPacket; + fn as_mut_ptr(&mut self) -> *mut AVPacket; } diff --git a/src/codec/parameters.rs b/src/codec/parameters.rs index d79bcc9..2ce5b9d 100644 --- a/src/codec/parameters.rs +++ b/src/codec/parameters.rs @@ -1,82 +1,90 @@ use std::rc::Rc; +use super::{Context, Id}; use ffi::*; use media; -use super::{Id, Context}; pub struct Parameters { - ptr: *mut AVCodecParameters, - owner: Option>, + ptr: *mut AVCodecParameters, + owner: Option>, } -unsafe impl Send for Parameters { } +unsafe impl Send for Parameters {} impl Parameters { - pub unsafe fn wrap(ptr: *mut AVCodecParameters, owner: Option>) -> Self { - Parameters { ptr: ptr, owner: owner } - } + pub unsafe fn wrap(ptr: *mut AVCodecParameters, owner: Option>) -> Self { + Parameters { + ptr: ptr, + owner: owner, + } + } - pub unsafe fn as_ptr(&self) -> *const AVCodecParameters { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVCodecParameters { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecParameters { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecParameters { + self.ptr + } } impl Parameters { - pub fn new() -> Self { - unsafe { - Parameters { ptr: avcodec_parameters_alloc(), owner: None } - } - } + pub fn new() -> Self { + unsafe { + Parameters { + ptr: avcodec_parameters_alloc(), + owner: None, + } + } + } - pub fn medium(&self) -> media::Type { - unsafe { - media::Type::from((*self.as_ptr()).codec_type) - } - } + pub fn medium(&self) -> media::Type { + unsafe { media::Type::from((*self.as_ptr()).codec_type) } + } - pub fn id(&self) -> Id { - unsafe { - Id::from((*self.as_ptr()).codec_id) - } - } + pub fn id(&self) -> Id { + unsafe { Id::from((*self.as_ptr()).codec_id) } + } +} + +impl Default for Parameters { + fn default() -> Self { + Self::new() + } } impl Drop for Parameters { - fn drop(&mut self) { - unsafe { - if self.owner.is_none() { - avcodec_parameters_free(&mut self.as_mut_ptr()); - } - } - } + fn drop(&mut self) { + unsafe { + if self.owner.is_none() { + avcodec_parameters_free(&mut self.as_mut_ptr()); + } + } + } } impl Clone for Parameters { - fn clone(&self) -> Self { - let mut ctx = Parameters::new(); - ctx.clone_from(self); + fn clone(&self) -> Self { + let mut ctx = Parameters::new(); + ctx.clone_from(self); - ctx - } + ctx + } - fn clone_from(&mut self, source: &Self) { - unsafe { - avcodec_parameters_copy(self.as_mut_ptr(), source.as_ptr()); - } - } + fn clone_from(&mut self, source: &Self) { + unsafe { + avcodec_parameters_copy(self.as_mut_ptr(), source.as_ptr()); + } + } } impl> From for Parameters { - fn from(context: C) -> Parameters { - let mut parameters = Parameters::new(); - let context = context.as_ref(); - unsafe { - avcodec_parameters_from_context(parameters.as_mut_ptr(), context.as_ptr()); - } - parameters - } + fn from(context: C) -> Parameters { + let mut parameters = Parameters::new(); + let context = context.as_ref(); + unsafe { + avcodec_parameters_from_context(parameters.as_mut_ptr(), context.as_ptr()); + } + parameters + } } diff --git a/src/codec/picture.rs b/src/codec/picture.rs index e30913b..d7ae322 100644 --- a/src/codec/picture.rs +++ b/src/codec/picture.rs @@ -1,166 +1,219 @@ +use std::marker::PhantomData; use std::mem; use std::slice; -use std::marker::PhantomData; -use libc::{c_int, size_t}; use ffi::*; -use ::format; -use ::Error; +use format; +use libc::{c_int, size_t}; +use Error; pub struct Picture<'a> { - ptr: *mut AVPicture, + ptr: *mut AVPicture, - format: format::Pixel, - width: u32, - height: u32, + format: format::Pixel, + width: u32, + height: u32, - _own: bool, - _marker: PhantomData<&'a ()>, + _own: bool, + _marker: PhantomData<&'a ()>, } impl<'a> Picture<'a> { - pub unsafe fn wrap(ptr: *mut AVPicture, format: format::Pixel, width: u32, height: u32) -> Self { - Picture { - ptr: ptr, + pub unsafe fn wrap( + ptr: *mut AVPicture, + format: format::Pixel, + width: u32, + height: u32, + ) -> Self { + Picture { + ptr: ptr, - format: format, - width: width, - height: height, + format: format, + width: width, + height: height, - _own: false, - _marker: PhantomData - } - } + _own: false, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVPicture { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVPicture { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVPicture { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVPicture { + self.ptr + } } impl<'a> Picture<'a> { - pub fn size(format: format::Pixel, width: u32, height: u32) -> Result { - unsafe { - match avpicture_get_size(format.into(), width as c_int, height as c_int) { - v if v >= 0 => Ok(v as usize), - e => Err(Error::from(e)) - } - } - } + pub fn size(format: format::Pixel, width: u32, height: u32) -> Result { + unsafe { + match avpicture_get_size(format.into(), width as c_int, height as c_int) { + v if v >= 0 => Ok(v as usize), + e => Err(Error::from(e)), + } + } + } - pub fn new(format: format::Pixel, width: u32, height: u32) -> Result { - unsafe { - let ptr = av_malloc(mem::size_of::() as size_t) as *mut AVPicture; + pub fn new(format: format::Pixel, width: u32, height: u32) -> Result { + unsafe { + let ptr = av_malloc(mem::size_of::() as size_t) as *mut AVPicture; - match avpicture_alloc(ptr, format.into(), width as c_int, height as c_int) { - 0 => Ok(Picture { - ptr: ptr, + match avpicture_alloc(ptr, format.into(), width as c_int, height as c_int) { + 0 => Ok(Picture { + ptr: ptr, - format: format, - width: width, - height: height, + format: format, + width: width, + height: height, - _own: true, - _marker: PhantomData - }), + _own: true, + _marker: PhantomData, + }), - e => Err(Error::from(e)) - } - } - } + e => Err(Error::from(e)), + } + } + } - pub fn format(&self) -> format::Pixel { - self.format - } + pub fn format(&self) -> format::Pixel { + self.format + } - pub fn width(&self) -> u32 { - self.width - } + pub fn width(&self) -> u32 { + self.width + } - pub fn height(&self) -> u32 { - self.height - } + pub fn height(&self) -> u32 { + self.height + } - pub fn layout(&self, out: &mut [u8]) -> Result { - unsafe { - match avpicture_layout(self.ptr, self.format.into(), self.width as c_int, self.height as c_int, out.as_mut_ptr(), out.len() as c_int) { - s if s >= 0 => Ok(s as usize), - e => Err(Error::from(e)) - } - } - } + pub fn layout(&self, out: &mut [u8]) -> Result { + unsafe { + match avpicture_layout( + self.ptr, + self.format.into(), + self.width as c_int, + self.height as c_int, + out.as_mut_ptr(), + out.len() as c_int, + ) { + s if s >= 0 => Ok(s as usize), + e => Err(Error::from(e)), + } + } + } - pub fn layout_as(&self, format: format::Pixel, width: u32, height: u32, out: &mut [u8]) -> Result { - unsafe { - match avpicture_layout(self.as_ptr(), format.into(), width as c_int, height as c_int, out.as_mut_ptr(), out.len() as c_int) { - s if s >= 0 => Ok(s as usize), - e => Err(Error::from(e)) - } - } - } + pub fn layout_as( + &self, + format: format::Pixel, + width: u32, + height: u32, + out: &mut [u8], + ) -> Result { + unsafe { + match avpicture_layout( + self.as_ptr(), + format.into(), + width as c_int, + height as c_int, + out.as_mut_ptr(), + out.len() as c_int, + ) { + s if s >= 0 => Ok(s as usize), + e => Err(Error::from(e)), + } + } + } - pub fn crop(&self, source: &mut Picture, top: u32, left: u32) -> Result<(), Error> { - if self.format != source.format { - return Err(Error::Bug); - } + pub fn crop(&self, source: &mut Picture, top: u32, left: u32) -> Result<(), Error> { + if self.format != source.format { + return Err(Error::Bug); + } - unsafe { - match av_picture_crop(source.as_mut_ptr(), self.as_ptr(), self.format.into(), top as c_int, left as c_int) { - 0 => Ok(()), - e => Err(Error::from(e)) - } - } - } + unsafe { + match av_picture_crop( + source.as_mut_ptr(), + self.as_ptr(), + self.format.into(), + top as c_int, + left as c_int, + ) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn data(&self) -> Vec<&[u8]> { - let mut result = Vec::new(); + pub fn data(&self) -> Vec<&[u8]> { + let mut result = Vec::new(); - unsafe { - for (i, length) in (*self.as_ptr()).linesize.iter().take_while(|l| **l > 0).enumerate() { - result.push(slice::from_raw_parts((*self.as_ptr()).data[i], (*length as usize) * (self.height as usize))) - } - } + unsafe { + for (i, length) in (*self.as_ptr()) + .linesize + .iter() + .take_while(|l| **l > 0) + .enumerate() + { + result.push(slice::from_raw_parts( + (*self.as_ptr()).data[i], + (*length as usize) * (self.height as usize), + )) + } + } - result - } + result + } - pub fn data_mut(&mut self) -> Vec<&mut [u8]> { - let mut result = Vec::new(); + pub fn data_mut(&mut self) -> Vec<&mut [u8]> { + let mut result = Vec::new(); - unsafe { - for (i, length) in (*self.as_ptr()).linesize.iter().take_while(|l| **l > 0).enumerate() { - result.push(slice::from_raw_parts_mut((*self.as_ptr()).data[i], (*length as usize) * (self.height as usize))) - } - } + unsafe { + for (i, length) in (*self.as_ptr()) + .linesize + .iter() + .take_while(|l| **l > 0) + .enumerate() + { + result.push(slice::from_raw_parts_mut( + (*self.as_ptr()).data[i], + (*length as usize) * (self.height as usize), + )) + } + } - result - } + result + } } impl<'a> Clone for Picture<'a> { - fn clone(&self) -> Self { - let mut pic = Picture::new(self.format, self.width, self.height).unwrap(); - pic.clone_from(self); + fn clone(&self) -> Self { + let mut pic = Picture::new(self.format, self.width, self.height).unwrap(); + pic.clone_from(self); - pic - } + pic + } - fn clone_from(&mut self, source: &Self) { - unsafe { - av_picture_copy(self.as_mut_ptr(), source.as_ptr(), source.format.into(), source.width as c_int, source.height as c_int); - } - } + fn clone_from(&mut self, source: &Self) { + unsafe { + av_picture_copy( + self.as_mut_ptr(), + source.as_ptr(), + source.format.into(), + source.width as c_int, + source.height as c_int, + ); + } + } } impl<'a> Drop for Picture<'a> { - fn drop(&mut self) { - if self._own { - unsafe { - av_free(self.as_mut_ptr() as *mut _); - } - } - } + fn drop(&mut self) { + if self._own { + unsafe { + av_free(self.as_mut_ptr() as *mut _); + } + } + } } diff --git a/src/codec/profile.rs b/src/codec/profile.rs index b54fb34..c76b86c 100644 --- a/src/codec/profile.rs +++ b/src/codec/profile.rs @@ -1,357 +1,377 @@ -use libc::c_int; -use ffi::*; use super::Id; +use ffi::*; +use libc::c_int; #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Profile { - Unknown, - Reserved, + Unknown, + Reserved, - AAC(AAC), - MPEG2(MPEG2), - DTS(DTS), - H264(H264), - VC1(VC1), - MPEG4(MPEG4), - JPEG2000(JPEG2000), - HEVC(HEVC), - VP9(VP9), + AAC(AAC), + MPEG2(MPEG2), + DTS(DTS), + H264(H264), + VC1(VC1), + MPEG4(MPEG4), + JPEG2000(JPEG2000), + HEVC(HEVC), + VP9(VP9), } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum AAC { - Main, - Low, - SSR, - LTP, - HE, - HEv2, - LD, - ELD, + Main, + Low, + SSR, + LTP, + HE, + HEv2, + LD, + ELD, - MPEG2Low, - MPEG2HE, + MPEG2Low, + MPEG2HE, } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum DTS { - Default, - ES, - _96_24, - HD_HRA, - HD_MA, - Express, + Default, + ES, + _96_24, + HD_HRA, + HD_MA, + Express, } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum MPEG2 { - _422, - High, - SS, - SNRScalable, - Main, - Simple, + _422, + High, + SS, + SNRScalable, + Main, + Simple, } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum H264 { - Constrained, - Intra, - Baseline, - ConstrainedBaseline, - Main, - Extended, - High, - High10, - High10Intra, - High422, - High422Intra, - High444, - High444Predictive, - High444Intra, - CAVLC444, + Constrained, + Intra, + Baseline, + ConstrainedBaseline, + Main, + Extended, + High, + High10, + High10Intra, + High422, + High422Intra, + High444, + High444Predictive, + High444Intra, + CAVLC444, } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum VC1 { - Simple, - Main, - Complex, - Advanced, + Simple, + Main, + Complex, + Advanced, } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum MPEG4 { - Simple, - SimpleScalable, - Core, - Main, - NBit, - ScalableTexture, - SimpleFaceAnimation, - BasicAnimatedTexture, - Hybrid, - AdvancedRealTime, - CoreScalable, - AdvancedCoding, - AdvancedCore, - AdvancedScalableTexture, - SimpleStudio, - AdvancedSimple, + Simple, + SimpleScalable, + Core, + Main, + NBit, + ScalableTexture, + SimpleFaceAnimation, + BasicAnimatedTexture, + Hybrid, + AdvancedRealTime, + CoreScalable, + AdvancedCoding, + AdvancedCore, + AdvancedScalableTexture, + SimpleStudio, + AdvancedSimple, } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum JPEG2000 { - CStreamRestriction0, - CStreamRestriction1, - CStreamNoRestriction, - DCinema2K, - DCinema4K, + CStreamRestriction0, + CStreamRestriction1, + CStreamNoRestriction, + DCinema2K, + DCinema4K, } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum HEVC { - Main, - Main10, - MainStillPicture, - Rext, + Main, + Main10, + MainStillPicture, + Rext, } #[allow(non_camel_case_types)] #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum VP9 { - _0, - _1, - _2, - _3, + _0, + _1, + _2, + _3, } impl From<(Id, c_int)> for Profile { - fn from((id, value): (Id, c_int)) -> Profile { - if value == FF_PROFILE_UNKNOWN { - return Profile::Unknown; - } + fn from((id, value): (Id, c_int)) -> Profile { + if value == FF_PROFILE_UNKNOWN { + return Profile::Unknown; + } - if value == FF_PROFILE_RESERVED { - return Profile::Reserved; - } + if value == FF_PROFILE_RESERVED { + return Profile::Reserved; + } - match id { - Id::AAC => match value { - FF_PROFILE_AAC_MAIN => Profile::AAC(AAC::Main), - FF_PROFILE_AAC_LOW => Profile::AAC(AAC::Low), - FF_PROFILE_AAC_SSR => Profile::AAC(AAC::SSR), - FF_PROFILE_AAC_LTP => Profile::AAC(AAC::LTP), - FF_PROFILE_AAC_HE => Profile::AAC(AAC::HE), - FF_PROFILE_AAC_HE_V2 => Profile::AAC(AAC::HEv2), - FF_PROFILE_AAC_LD => Profile::AAC(AAC::LD), - FF_PROFILE_AAC_ELD => Profile::AAC(AAC::ELD), + match id { + Id::AAC => match value { + FF_PROFILE_AAC_MAIN => Profile::AAC(AAC::Main), + FF_PROFILE_AAC_LOW => Profile::AAC(AAC::Low), + FF_PROFILE_AAC_SSR => Profile::AAC(AAC::SSR), + FF_PROFILE_AAC_LTP => Profile::AAC(AAC::LTP), + FF_PROFILE_AAC_HE => Profile::AAC(AAC::HE), + FF_PROFILE_AAC_HE_V2 => Profile::AAC(AAC::HEv2), + FF_PROFILE_AAC_LD => Profile::AAC(AAC::LD), + FF_PROFILE_AAC_ELD => Profile::AAC(AAC::ELD), - FF_PROFILE_MPEG2_AAC_LOW => Profile::AAC(AAC::MPEG2Low), - FF_PROFILE_MPEG2_AAC_HE => Profile::AAC(AAC::MPEG2HE), + FF_PROFILE_MPEG2_AAC_LOW => Profile::AAC(AAC::MPEG2Low), + FF_PROFILE_MPEG2_AAC_HE => Profile::AAC(AAC::MPEG2HE), - _ => Profile::Unknown - }, + _ => Profile::Unknown, + }, - Id::DTS => match value { - FF_PROFILE_DTS => Profile::DTS(DTS::Default), - FF_PROFILE_DTS_ES => Profile::DTS(DTS::ES), - FF_PROFILE_DTS_96_24 => Profile::DTS(DTS::_96_24), - FF_PROFILE_DTS_HD_HRA => Profile::DTS(DTS::HD_HRA), - FF_PROFILE_DTS_HD_MA => Profile::DTS(DTS::HD_MA), - FF_PROFILE_DTS_EXPRESS => Profile::DTS(DTS::Express), + Id::DTS => match value { + FF_PROFILE_DTS => Profile::DTS(DTS::Default), + FF_PROFILE_DTS_ES => Profile::DTS(DTS::ES), + FF_PROFILE_DTS_96_24 => Profile::DTS(DTS::_96_24), + FF_PROFILE_DTS_HD_HRA => Profile::DTS(DTS::HD_HRA), + FF_PROFILE_DTS_HD_MA => Profile::DTS(DTS::HD_MA), + FF_PROFILE_DTS_EXPRESS => Profile::DTS(DTS::Express), - _ => Profile::Unknown, - }, + _ => Profile::Unknown, + }, - Id::MPEG2VIDEO => match value { - FF_PROFILE_MPEG2_422 => Profile::MPEG2(MPEG2::_422), - FF_PROFILE_MPEG2_HIGH => Profile::MPEG2(MPEG2::High), - FF_PROFILE_MPEG2_SS => Profile::MPEG2(MPEG2::SS), - FF_PROFILE_MPEG2_SNR_SCALABLE => Profile::MPEG2(MPEG2::SNRScalable), - FF_PROFILE_MPEG2_MAIN => Profile::MPEG2(MPEG2::Main), - FF_PROFILE_MPEG2_SIMPLE => Profile::MPEG2(MPEG2::Simple), + Id::MPEG2VIDEO => match value { + FF_PROFILE_MPEG2_422 => Profile::MPEG2(MPEG2::_422), + FF_PROFILE_MPEG2_HIGH => Profile::MPEG2(MPEG2::High), + FF_PROFILE_MPEG2_SS => Profile::MPEG2(MPEG2::SS), + FF_PROFILE_MPEG2_SNR_SCALABLE => Profile::MPEG2(MPEG2::SNRScalable), + FF_PROFILE_MPEG2_MAIN => Profile::MPEG2(MPEG2::Main), + FF_PROFILE_MPEG2_SIMPLE => Profile::MPEG2(MPEG2::Simple), - _ => Profile::Unknown, - }, + _ => Profile::Unknown, + }, - Id::H264 => match value { - FF_PROFILE_H264_CONSTRAINED => Profile::H264(H264::Constrained), - FF_PROFILE_H264_INTRA => Profile::H264(H264::Intra), - FF_PROFILE_H264_BASELINE => Profile::H264(H264::Baseline), - FF_PROFILE_H264_CONSTRAINED_BASELINE => Profile::H264(H264::ConstrainedBaseline), - FF_PROFILE_H264_MAIN => Profile::H264(H264::Main), - FF_PROFILE_H264_EXTENDED => Profile::H264(H264::Extended), - FF_PROFILE_H264_HIGH => Profile::H264(H264::High), - FF_PROFILE_H264_HIGH_10 => Profile::H264(H264::High10), - FF_PROFILE_H264_HIGH_10_INTRA => Profile::H264(H264::High10Intra), - FF_PROFILE_H264_HIGH_422 => Profile::H264(H264::High422), - FF_PROFILE_H264_HIGH_422_INTRA => Profile::H264(H264::High422Intra), - FF_PROFILE_H264_HIGH_444 => Profile::H264(H264::High444), - FF_PROFILE_H264_HIGH_444_PREDICTIVE => Profile::H264(H264::High444Predictive), - FF_PROFILE_H264_HIGH_444_INTRA => Profile::H264(H264::High444Intra), - FF_PROFILE_H264_CAVLC_444 => Profile::H264(H264::CAVLC444), + Id::H264 => match value { + FF_PROFILE_H264_CONSTRAINED => Profile::H264(H264::Constrained), + FF_PROFILE_H264_INTRA => Profile::H264(H264::Intra), + FF_PROFILE_H264_BASELINE => Profile::H264(H264::Baseline), + FF_PROFILE_H264_CONSTRAINED_BASELINE => Profile::H264(H264::ConstrainedBaseline), + FF_PROFILE_H264_MAIN => Profile::H264(H264::Main), + FF_PROFILE_H264_EXTENDED => Profile::H264(H264::Extended), + FF_PROFILE_H264_HIGH => Profile::H264(H264::High), + FF_PROFILE_H264_HIGH_10 => Profile::H264(H264::High10), + FF_PROFILE_H264_HIGH_10_INTRA => Profile::H264(H264::High10Intra), + FF_PROFILE_H264_HIGH_422 => Profile::H264(H264::High422), + FF_PROFILE_H264_HIGH_422_INTRA => Profile::H264(H264::High422Intra), + FF_PROFILE_H264_HIGH_444 => Profile::H264(H264::High444), + FF_PROFILE_H264_HIGH_444_PREDICTIVE => Profile::H264(H264::High444Predictive), + FF_PROFILE_H264_HIGH_444_INTRA => Profile::H264(H264::High444Intra), + FF_PROFILE_H264_CAVLC_444 => Profile::H264(H264::CAVLC444), - _ => Profile::Unknown, - }, + _ => Profile::Unknown, + }, - Id::VC1 => match value { - FF_PROFILE_VC1_SIMPLE => Profile::VC1(VC1::Simple), - FF_PROFILE_VC1_MAIN => Profile::VC1(VC1::Main), - FF_PROFILE_VC1_COMPLEX => Profile::VC1(VC1::Complex), - FF_PROFILE_VC1_ADVANCED => Profile::VC1(VC1::Advanced), + Id::VC1 => match value { + FF_PROFILE_VC1_SIMPLE => Profile::VC1(VC1::Simple), + FF_PROFILE_VC1_MAIN => Profile::VC1(VC1::Main), + FF_PROFILE_VC1_COMPLEX => Profile::VC1(VC1::Complex), + FF_PROFILE_VC1_ADVANCED => Profile::VC1(VC1::Advanced), - _ => Profile::Unknown, - }, + _ => Profile::Unknown, + }, - Id::MPEG4 => match value { - FF_PROFILE_MPEG4_SIMPLE => Profile::MPEG4(MPEG4::Simple), - FF_PROFILE_MPEG4_SIMPLE_SCALABLE => Profile::MPEG4(MPEG4::SimpleScalable), - FF_PROFILE_MPEG4_CORE => Profile::MPEG4(MPEG4::Core), - FF_PROFILE_MPEG4_MAIN => Profile::MPEG4(MPEG4::Main), - FF_PROFILE_MPEG4_N_BIT => Profile::MPEG4(MPEG4::NBit), - FF_PROFILE_MPEG4_SCALABLE_TEXTURE => Profile::MPEG4(MPEG4::ScalableTexture), - FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION => Profile::MPEG4(MPEG4::SimpleFaceAnimation), - FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE => Profile::MPEG4(MPEG4::BasicAnimatedTexture), - FF_PROFILE_MPEG4_HYBRID => Profile::MPEG4(MPEG4::Hybrid), - FF_PROFILE_MPEG4_ADVANCED_REAL_TIME => Profile::MPEG4(MPEG4::AdvancedRealTime), - FF_PROFILE_MPEG4_CORE_SCALABLE => Profile::MPEG4(MPEG4::CoreScalable), - FF_PROFILE_MPEG4_ADVANCED_CODING => Profile::MPEG4(MPEG4::AdvancedCoding), - FF_PROFILE_MPEG4_ADVANCED_CORE => Profile::MPEG4(MPEG4::AdvancedCore), - FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE => Profile::MPEG4(MPEG4::AdvancedScalableTexture), - FF_PROFILE_MPEG4_SIMPLE_STUDIO => Profile::MPEG4(MPEG4::SimpleStudio), - FF_PROFILE_MPEG4_ADVANCED_SIMPLE => Profile::MPEG4(MPEG4::AdvancedSimple), + Id::MPEG4 => match value { + FF_PROFILE_MPEG4_SIMPLE => Profile::MPEG4(MPEG4::Simple), + FF_PROFILE_MPEG4_SIMPLE_SCALABLE => Profile::MPEG4(MPEG4::SimpleScalable), + FF_PROFILE_MPEG4_CORE => Profile::MPEG4(MPEG4::Core), + FF_PROFILE_MPEG4_MAIN => Profile::MPEG4(MPEG4::Main), + FF_PROFILE_MPEG4_N_BIT => Profile::MPEG4(MPEG4::NBit), + FF_PROFILE_MPEG4_SCALABLE_TEXTURE => Profile::MPEG4(MPEG4::ScalableTexture), + FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION => { + Profile::MPEG4(MPEG4::SimpleFaceAnimation) + } + FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE => { + Profile::MPEG4(MPEG4::BasicAnimatedTexture) + } + FF_PROFILE_MPEG4_HYBRID => Profile::MPEG4(MPEG4::Hybrid), + FF_PROFILE_MPEG4_ADVANCED_REAL_TIME => Profile::MPEG4(MPEG4::AdvancedRealTime), + FF_PROFILE_MPEG4_CORE_SCALABLE => Profile::MPEG4(MPEG4::CoreScalable), + FF_PROFILE_MPEG4_ADVANCED_CODING => Profile::MPEG4(MPEG4::AdvancedCoding), + FF_PROFILE_MPEG4_ADVANCED_CORE => Profile::MPEG4(MPEG4::AdvancedCore), + FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE => { + Profile::MPEG4(MPEG4::AdvancedScalableTexture) + } + FF_PROFILE_MPEG4_SIMPLE_STUDIO => Profile::MPEG4(MPEG4::SimpleStudio), + FF_PROFILE_MPEG4_ADVANCED_SIMPLE => Profile::MPEG4(MPEG4::AdvancedSimple), - _ => Profile::Unknown, - }, + _ => Profile::Unknown, + }, - Id::JPEG2000 => match value { - FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 => Profile::JPEG2000(JPEG2000::CStreamRestriction0), - FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 => Profile::JPEG2000(JPEG2000::CStreamRestriction1), - FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION => Profile::JPEG2000(JPEG2000::CStreamNoRestriction), - FF_PROFILE_JPEG2000_DCINEMA_2K => Profile::JPEG2000(JPEG2000::DCinema2K), - FF_PROFILE_JPEG2000_DCINEMA_4K => Profile::JPEG2000(JPEG2000::DCinema4K), + Id::JPEG2000 => match value { + FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 => { + Profile::JPEG2000(JPEG2000::CStreamRestriction0) + } + FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 => { + Profile::JPEG2000(JPEG2000::CStreamRestriction1) + } + FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION => { + Profile::JPEG2000(JPEG2000::CStreamNoRestriction) + } + FF_PROFILE_JPEG2000_DCINEMA_2K => Profile::JPEG2000(JPEG2000::DCinema2K), + FF_PROFILE_JPEG2000_DCINEMA_4K => Profile::JPEG2000(JPEG2000::DCinema4K), - _ => Profile::Unknown, - }, + _ => Profile::Unknown, + }, - Id::HEVC => match value { - FF_PROFILE_HEVC_MAIN => Profile::HEVC(HEVC::Main), - FF_PROFILE_HEVC_MAIN_10 => Profile::HEVC(HEVC::Main10), - FF_PROFILE_HEVC_MAIN_STILL_PICTURE => Profile::HEVC(HEVC::MainStillPicture), - FF_PROFILE_HEVC_REXT => Profile::HEVC(HEVC::Rext), + Id::HEVC => match value { + FF_PROFILE_HEVC_MAIN => Profile::HEVC(HEVC::Main), + FF_PROFILE_HEVC_MAIN_10 => Profile::HEVC(HEVC::Main10), + FF_PROFILE_HEVC_MAIN_STILL_PICTURE => Profile::HEVC(HEVC::MainStillPicture), + FF_PROFILE_HEVC_REXT => Profile::HEVC(HEVC::Rext), - _ => Profile::Unknown, - }, + _ => Profile::Unknown, + }, - Id::VP9 => match value { - FF_PROFILE_VP9_0 => Profile::VP9(VP9::_0), - FF_PROFILE_VP9_1 => Profile::VP9(VP9::_1), - FF_PROFILE_VP9_2 => Profile::VP9(VP9::_2), - FF_PROFILE_VP9_3 => Profile::VP9(VP9::_3), + Id::VP9 => match value { + FF_PROFILE_VP9_0 => Profile::VP9(VP9::_0), + FF_PROFILE_VP9_1 => Profile::VP9(VP9::_1), + FF_PROFILE_VP9_2 => Profile::VP9(VP9::_2), + FF_PROFILE_VP9_3 => Profile::VP9(VP9::_3), - _ => Profile::Unknown, - }, + _ => Profile::Unknown, + }, - _ => Profile::Unknown - } - } + _ => Profile::Unknown, + } + } } impl Into for Profile { - fn into(self) -> c_int { - match self { - Profile::Unknown => FF_PROFILE_UNKNOWN, - Profile::Reserved => FF_PROFILE_RESERVED, + fn into(self) -> c_int { + match self { + Profile::Unknown => FF_PROFILE_UNKNOWN, + Profile::Reserved => FF_PROFILE_RESERVED, - Profile::AAC(AAC::Main) => FF_PROFILE_AAC_MAIN, - Profile::AAC(AAC::Low) => FF_PROFILE_AAC_LOW, - Profile::AAC(AAC::SSR) => FF_PROFILE_AAC_SSR, - Profile::AAC(AAC::LTP) => FF_PROFILE_AAC_LTP, - Profile::AAC(AAC::HE) => FF_PROFILE_AAC_HE, - Profile::AAC(AAC::HEv2) => FF_PROFILE_AAC_HE_V2, - Profile::AAC(AAC::LD) => FF_PROFILE_AAC_LD, - Profile::AAC(AAC::ELD) => FF_PROFILE_AAC_ELD, + Profile::AAC(AAC::Main) => FF_PROFILE_AAC_MAIN, + Profile::AAC(AAC::Low) => FF_PROFILE_AAC_LOW, + Profile::AAC(AAC::SSR) => FF_PROFILE_AAC_SSR, + Profile::AAC(AAC::LTP) => FF_PROFILE_AAC_LTP, + Profile::AAC(AAC::HE) => FF_PROFILE_AAC_HE, + Profile::AAC(AAC::HEv2) => FF_PROFILE_AAC_HE_V2, + Profile::AAC(AAC::LD) => FF_PROFILE_AAC_LD, + Profile::AAC(AAC::ELD) => FF_PROFILE_AAC_ELD, - Profile::AAC(AAC::MPEG2Low) => FF_PROFILE_MPEG2_AAC_LOW, - Profile::AAC(AAC::MPEG2HE) => FF_PROFILE_MPEG2_AAC_HE, + Profile::AAC(AAC::MPEG2Low) => FF_PROFILE_MPEG2_AAC_LOW, + Profile::AAC(AAC::MPEG2HE) => FF_PROFILE_MPEG2_AAC_HE, - Profile::DTS(DTS::Default) => FF_PROFILE_DTS, - Profile::DTS(DTS::ES) => FF_PROFILE_DTS_ES, - Profile::DTS(DTS::_96_24) => FF_PROFILE_DTS_96_24, - Profile::DTS(DTS::HD_HRA) => FF_PROFILE_DTS_HD_HRA, - Profile::DTS(DTS::HD_MA) => FF_PROFILE_DTS_HD_MA, - Profile::DTS(DTS::Express) => FF_PROFILE_DTS_EXPRESS, + Profile::DTS(DTS::Default) => FF_PROFILE_DTS, + Profile::DTS(DTS::ES) => FF_PROFILE_DTS_ES, + Profile::DTS(DTS::_96_24) => FF_PROFILE_DTS_96_24, + Profile::DTS(DTS::HD_HRA) => FF_PROFILE_DTS_HD_HRA, + Profile::DTS(DTS::HD_MA) => FF_PROFILE_DTS_HD_MA, + Profile::DTS(DTS::Express) => FF_PROFILE_DTS_EXPRESS, - Profile::MPEG2(MPEG2::_422) => FF_PROFILE_MPEG2_422, - Profile::MPEG2(MPEG2::High) => FF_PROFILE_MPEG2_HIGH, - Profile::MPEG2(MPEG2::SS) => FF_PROFILE_MPEG2_SS, - Profile::MPEG2(MPEG2::SNRScalable) => FF_PROFILE_MPEG2_SNR_SCALABLE, - Profile::MPEG2(MPEG2::Main) => FF_PROFILE_MPEG2_MAIN, - Profile::MPEG2(MPEG2::Simple) => FF_PROFILE_MPEG2_SIMPLE, + Profile::MPEG2(MPEG2::_422) => FF_PROFILE_MPEG2_422, + Profile::MPEG2(MPEG2::High) => FF_PROFILE_MPEG2_HIGH, + Profile::MPEG2(MPEG2::SS) => FF_PROFILE_MPEG2_SS, + Profile::MPEG2(MPEG2::SNRScalable) => FF_PROFILE_MPEG2_SNR_SCALABLE, + Profile::MPEG2(MPEG2::Main) => FF_PROFILE_MPEG2_MAIN, + Profile::MPEG2(MPEG2::Simple) => FF_PROFILE_MPEG2_SIMPLE, - Profile::H264(H264::Constrained) => FF_PROFILE_H264_CONSTRAINED, - Profile::H264(H264::Intra) => FF_PROFILE_H264_INTRA, - Profile::H264(H264::Baseline) => FF_PROFILE_H264_BASELINE, - Profile::H264(H264::ConstrainedBaseline) => FF_PROFILE_H264_CONSTRAINED_BASELINE, - Profile::H264(H264::Main) => FF_PROFILE_H264_MAIN, - Profile::H264(H264::Extended) => FF_PROFILE_H264_EXTENDED, - Profile::H264(H264::High) => FF_PROFILE_H264_HIGH, - Profile::H264(H264::High10) => FF_PROFILE_H264_HIGH_10, - Profile::H264(H264::High10Intra) => FF_PROFILE_H264_HIGH_10_INTRA, - Profile::H264(H264::High422) => FF_PROFILE_H264_HIGH_422, - Profile::H264(H264::High422Intra) => FF_PROFILE_H264_HIGH_422_INTRA, - Profile::H264(H264::High444) => FF_PROFILE_H264_HIGH_444, - Profile::H264(H264::High444Predictive) => FF_PROFILE_H264_HIGH_444_PREDICTIVE, - Profile::H264(H264::High444Intra) => FF_PROFILE_H264_HIGH_444_INTRA, - Profile::H264(H264::CAVLC444) => FF_PROFILE_H264_CAVLC_444, + Profile::H264(H264::Constrained) => FF_PROFILE_H264_CONSTRAINED, + Profile::H264(H264::Intra) => FF_PROFILE_H264_INTRA, + Profile::H264(H264::Baseline) => FF_PROFILE_H264_BASELINE, + Profile::H264(H264::ConstrainedBaseline) => FF_PROFILE_H264_CONSTRAINED_BASELINE, + Profile::H264(H264::Main) => FF_PROFILE_H264_MAIN, + Profile::H264(H264::Extended) => FF_PROFILE_H264_EXTENDED, + Profile::H264(H264::High) => FF_PROFILE_H264_HIGH, + Profile::H264(H264::High10) => FF_PROFILE_H264_HIGH_10, + Profile::H264(H264::High10Intra) => FF_PROFILE_H264_HIGH_10_INTRA, + Profile::H264(H264::High422) => FF_PROFILE_H264_HIGH_422, + Profile::H264(H264::High422Intra) => FF_PROFILE_H264_HIGH_422_INTRA, + Profile::H264(H264::High444) => FF_PROFILE_H264_HIGH_444, + Profile::H264(H264::High444Predictive) => FF_PROFILE_H264_HIGH_444_PREDICTIVE, + Profile::H264(H264::High444Intra) => FF_PROFILE_H264_HIGH_444_INTRA, + Profile::H264(H264::CAVLC444) => FF_PROFILE_H264_CAVLC_444, - Profile::VC1(VC1::Simple) => FF_PROFILE_VC1_SIMPLE, - Profile::VC1(VC1::Main) => FF_PROFILE_VC1_MAIN, - Profile::VC1(VC1::Complex) => FF_PROFILE_VC1_COMPLEX, - Profile::VC1(VC1::Advanced) => FF_PROFILE_VC1_ADVANCED, + Profile::VC1(VC1::Simple) => FF_PROFILE_VC1_SIMPLE, + Profile::VC1(VC1::Main) => FF_PROFILE_VC1_MAIN, + Profile::VC1(VC1::Complex) => FF_PROFILE_VC1_COMPLEX, + Profile::VC1(VC1::Advanced) => FF_PROFILE_VC1_ADVANCED, - Profile::MPEG4(MPEG4::Simple) => FF_PROFILE_MPEG4_SIMPLE, - Profile::MPEG4(MPEG4::SimpleScalable) => FF_PROFILE_MPEG4_SIMPLE_SCALABLE, - Profile::MPEG4(MPEG4::Core) => FF_PROFILE_MPEG4_CORE, - Profile::MPEG4(MPEG4::Main) => FF_PROFILE_MPEG4_MAIN, - Profile::MPEG4(MPEG4::NBit) => FF_PROFILE_MPEG4_N_BIT, - Profile::MPEG4(MPEG4::ScalableTexture) => FF_PROFILE_MPEG4_SCALABLE_TEXTURE, - Profile::MPEG4(MPEG4::SimpleFaceAnimation) => FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION, - Profile::MPEG4(MPEG4::BasicAnimatedTexture) => FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE, - Profile::MPEG4(MPEG4::Hybrid) => FF_PROFILE_MPEG4_HYBRID, - Profile::MPEG4(MPEG4::AdvancedRealTime) => FF_PROFILE_MPEG4_ADVANCED_REAL_TIME, - Profile::MPEG4(MPEG4::CoreScalable) => FF_PROFILE_MPEG4_CORE_SCALABLE, - Profile::MPEG4(MPEG4::AdvancedCoding) => FF_PROFILE_MPEG4_ADVANCED_CODING, - Profile::MPEG4(MPEG4::AdvancedCore) => FF_PROFILE_MPEG4_ADVANCED_CORE, - Profile::MPEG4(MPEG4::AdvancedScalableTexture) => FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE, - Profile::MPEG4(MPEG4::SimpleStudio) => FF_PROFILE_MPEG4_SIMPLE_STUDIO, - Profile::MPEG4(MPEG4::AdvancedSimple) => FF_PROFILE_MPEG4_ADVANCED_SIMPLE, + Profile::MPEG4(MPEG4::Simple) => FF_PROFILE_MPEG4_SIMPLE, + Profile::MPEG4(MPEG4::SimpleScalable) => FF_PROFILE_MPEG4_SIMPLE_SCALABLE, + Profile::MPEG4(MPEG4::Core) => FF_PROFILE_MPEG4_CORE, + Profile::MPEG4(MPEG4::Main) => FF_PROFILE_MPEG4_MAIN, + Profile::MPEG4(MPEG4::NBit) => FF_PROFILE_MPEG4_N_BIT, + Profile::MPEG4(MPEG4::ScalableTexture) => FF_PROFILE_MPEG4_SCALABLE_TEXTURE, + Profile::MPEG4(MPEG4::SimpleFaceAnimation) => FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION, + Profile::MPEG4(MPEG4::BasicAnimatedTexture) => FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE, + Profile::MPEG4(MPEG4::Hybrid) => FF_PROFILE_MPEG4_HYBRID, + Profile::MPEG4(MPEG4::AdvancedRealTime) => FF_PROFILE_MPEG4_ADVANCED_REAL_TIME, + Profile::MPEG4(MPEG4::CoreScalable) => FF_PROFILE_MPEG4_CORE_SCALABLE, + Profile::MPEG4(MPEG4::AdvancedCoding) => FF_PROFILE_MPEG4_ADVANCED_CODING, + Profile::MPEG4(MPEG4::AdvancedCore) => FF_PROFILE_MPEG4_ADVANCED_CORE, + Profile::MPEG4(MPEG4::AdvancedScalableTexture) => { + FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE + } + Profile::MPEG4(MPEG4::SimpleStudio) => FF_PROFILE_MPEG4_SIMPLE_STUDIO, + Profile::MPEG4(MPEG4::AdvancedSimple) => FF_PROFILE_MPEG4_ADVANCED_SIMPLE, - Profile::JPEG2000(JPEG2000::CStreamRestriction0) => FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0, - Profile::JPEG2000(JPEG2000::CStreamRestriction1) => FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1, - Profile::JPEG2000(JPEG2000::CStreamNoRestriction) => FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION, - Profile::JPEG2000(JPEG2000::DCinema2K) => FF_PROFILE_JPEG2000_DCINEMA_2K, - Profile::JPEG2000(JPEG2000::DCinema4K) => FF_PROFILE_JPEG2000_DCINEMA_4K, + Profile::JPEG2000(JPEG2000::CStreamRestriction0) => { + FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 + } + Profile::JPEG2000(JPEG2000::CStreamRestriction1) => { + FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 + } + Profile::JPEG2000(JPEG2000::CStreamNoRestriction) => { + FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION + } + Profile::JPEG2000(JPEG2000::DCinema2K) => FF_PROFILE_JPEG2000_DCINEMA_2K, + Profile::JPEG2000(JPEG2000::DCinema4K) => FF_PROFILE_JPEG2000_DCINEMA_4K, - Profile::HEVC(HEVC::Main) => FF_PROFILE_HEVC_MAIN, - Profile::HEVC(HEVC::Main10) => FF_PROFILE_HEVC_MAIN_10, - Profile::HEVC(HEVC::MainStillPicture) => FF_PROFILE_HEVC_MAIN_STILL_PICTURE, - Profile::HEVC(HEVC::Rext) => FF_PROFILE_HEVC_REXT, + Profile::HEVC(HEVC::Main) => FF_PROFILE_HEVC_MAIN, + Profile::HEVC(HEVC::Main10) => FF_PROFILE_HEVC_MAIN_10, + Profile::HEVC(HEVC::MainStillPicture) => FF_PROFILE_HEVC_MAIN_STILL_PICTURE, + Profile::HEVC(HEVC::Rext) => FF_PROFILE_HEVC_REXT, - Profile::VP9(VP9::_0) => FF_PROFILE_VP9_0, - Profile::VP9(VP9::_1) => FF_PROFILE_VP9_1, - Profile::VP9(VP9::_2) => FF_PROFILE_VP9_2, - Profile::VP9(VP9::_3) => FF_PROFILE_VP9_3, - } - } + Profile::VP9(VP9::_0) => FF_PROFILE_VP9_0, + Profile::VP9(VP9::_1) => FF_PROFILE_VP9_1, + Profile::VP9(VP9::_2) => FF_PROFILE_VP9_2, + Profile::VP9(VP9::_3) => FF_PROFILE_VP9_3, + } + } } diff --git a/src/codec/subtitle/flag.rs b/src/codec/subtitle/flag.rs index ecdaa0e..cd8b624 100644 --- a/src/codec/subtitle/flag.rs +++ b/src/codec/subtitle/flag.rs @@ -1,8 +1,8 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Flags: c_int { - const FORCED = AV_SUBTITLE_FLAG_FORCED; - } + pub struct Flags: c_int { + const FORCED = AV_SUBTITLE_FLAG_FORCED; + } } diff --git a/src/codec/subtitle/mod.rs b/src/codec/subtitle/mod.rs index 28212b0..7d697c4 100644 --- a/src/codec/subtitle/mod.rs +++ b/src/codec/subtitle/mod.rs @@ -2,193 +2,209 @@ pub mod flag; pub use self::flag::Flags; mod rect; -pub use self::rect::{Rect, Bitmap, Text, Ass}; +pub use self::rect::{Ass, Bitmap, Rect, Text}; mod rect_mut; -pub use self::rect_mut::{RectMut, BitmapMut, TextMut, AssMut}; +pub use self::rect_mut::{AssMut, BitmapMut, RectMut, TextMut}; use std::marker::PhantomData; use std::mem; -use libc::{c_uint, uint32_t, size_t}; -use ffi::*; use ffi::AVSubtitleType::*; +use ffi::*; +use libc::{c_uint, size_t, uint32_t}; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Type { - None, - Bitmap, - Text, - Ass, + None, + Bitmap, + Text, + Ass, } impl From for Type { - fn from(value: AVSubtitleType) -> Type { - match value { - SUBTITLE_NONE => Type::None, - SUBTITLE_BITMAP => Type::Bitmap, - SUBTITLE_TEXT => Type::Text, - SUBTITLE_ASS => Type::Ass - } - } + fn from(value: AVSubtitleType) -> Type { + match value { + SUBTITLE_NONE => Type::None, + SUBTITLE_BITMAP => Type::Bitmap, + SUBTITLE_TEXT => Type::Text, + SUBTITLE_ASS => Type::Ass, + } + } } impl Into for Type { - fn into(self) -> AVSubtitleType { - match self { - Type::None => SUBTITLE_NONE, - Type::Bitmap => SUBTITLE_BITMAP, - Type::Text => SUBTITLE_TEXT, - Type::Ass => SUBTITLE_ASS - } - } + fn into(self) -> AVSubtitleType { + match self { + Type::None => SUBTITLE_NONE, + Type::Bitmap => SUBTITLE_BITMAP, + Type::Text => SUBTITLE_TEXT, + Type::Ass => SUBTITLE_ASS, + } + } } pub struct Subtitle(AVSubtitle); impl Subtitle { - pub unsafe fn as_ptr(&self) -> *const AVSubtitle { - &self.0 - } + pub unsafe fn as_ptr(&self) -> *const AVSubtitle { + &self.0 + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitle { - &mut self.0 - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitle { + &mut self.0 + } } impl Subtitle { - pub fn new() -> Self { - unsafe { - Subtitle(mem::zeroed()) - } - } + pub fn new() -> Self { + unsafe { Subtitle(mem::zeroed()) } + } - pub fn pts(&self) -> Option { - match self.0.pts { - AV_NOPTS_VALUE => None, - pts => Some(pts) - } - } + pub fn pts(&self) -> Option { + match self.0.pts { + AV_NOPTS_VALUE => None, + pts => Some(pts), + } + } - pub fn set_pts(&mut self, value: Option) { - self.0.pts = value.unwrap_or(AV_NOPTS_VALUE); - } + pub fn set_pts(&mut self, value: Option) { + self.0.pts = value.unwrap_or(AV_NOPTS_VALUE); + } - pub fn start(&self) -> u32 { - self.0.start_display_time as u32 - } + pub fn start(&self) -> u32 { + self.0.start_display_time as u32 + } - pub fn set_start(&mut self, value: u32) { - self.0.start_display_time = value as uint32_t; - } + pub fn set_start(&mut self, value: u32) { + self.0.start_display_time = value as uint32_t; + } - pub fn end(&self) -> u32 { - self.0.end_display_time as u32 - } + pub fn end(&self) -> u32 { + self.0.end_display_time as u32 + } - pub fn set_end(&mut self, value: u32) { - self.0.end_display_time = value as uint32_t; - } + pub fn set_end(&mut self, value: u32) { + self.0.end_display_time = value as uint32_t; + } - pub fn rects(&self) -> RectIter { - RectIter::new(&self.0) - } + pub fn rects(&self) -> RectIter { + RectIter::new(&self.0) + } - pub fn rects_mut(&mut self) -> RectMutIter { - RectMutIter::new(&mut self.0) - } + pub fn rects_mut(&mut self) -> RectMutIter { + RectMutIter::new(&mut self.0) + } - pub fn add_rect(&mut self, kind: Type) -> RectMut { - unsafe { - self.0.num_rects += 1; - self.0.rects = av_realloc(self.0.rects as *mut _, - (mem::size_of::<*const AVSubtitleRect>() * self.0.num_rects as usize) as size_t) - as *mut _; + pub fn add_rect(&mut self, kind: Type) -> RectMut { + unsafe { + self.0.num_rects += 1; + self.0.rects = av_realloc( + self.0.rects as *mut _, + (mem::size_of::<*const AVSubtitleRect>() * self.0.num_rects as usize) as size_t, + ) as *mut _; - let rect = av_mallocz(mem::size_of::() as size_t) as *mut AVSubtitleRect; - (*rect).type_ = kind.into(); + let rect = + av_mallocz(mem::size_of::() as size_t) as *mut AVSubtitleRect; + (*rect).type_ = kind.into(); - *self.0.rects.offset((self.0.num_rects - 1) as isize) = rect; + *self.0.rects.offset((self.0.num_rects - 1) as isize) = rect; - RectMut::wrap(rect) - } - } + RectMut::wrap(rect) + } + } +} + +impl Default for Subtitle { + fn default() -> Self { + Self::new() + } } pub struct RectIter<'a> { - ptr: *const AVSubtitle, - cur: c_uint, + ptr: *const AVSubtitle, + cur: c_uint, - _marker: PhantomData<&'a Subtitle>, + _marker: PhantomData<&'a Subtitle>, } impl<'a> RectIter<'a> { - pub fn new(ptr: *const AVSubtitle) -> Self { - RectIter { ptr: ptr, cur: 0, _marker: PhantomData } - } + pub fn new(ptr: *const AVSubtitle) -> Self { + RectIter { + ptr: ptr, + cur: 0, + _marker: PhantomData, + } + } } impl<'a> Iterator for RectIter<'a> { - type Item = Rect<'a>; + type Item = Rect<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.cur >= (*self.ptr).num_rects { - None - } - else { - self.cur += 1; - Some(Rect::wrap(*(*self.ptr).rects.offset((self.cur - 1) as isize))) - } - } - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.cur >= (*self.ptr).num_rects { + None + } else { + self.cur += 1; + Some(Rect::wrap(*(*self.ptr) + .rects + .offset((self.cur - 1) as isize))) + } + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.ptr).num_rects as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.ptr).num_rects as usize; - (length - self.cur as usize, Some(length - self.cur as usize)) - } - } + (length - self.cur as usize, Some(length - self.cur as usize)) + } + } } -impl<'a> ExactSizeIterator for RectIter<'a> { } +impl<'a> ExactSizeIterator for RectIter<'a> {} pub struct RectMutIter<'a> { - ptr: *mut AVSubtitle, - cur: c_uint, + ptr: *mut AVSubtitle, + cur: c_uint, - _marker: PhantomData<&'a Subtitle>, + _marker: PhantomData<&'a Subtitle>, } impl<'a> RectMutIter<'a> { - pub fn new(ptr: *mut AVSubtitle) -> Self { - RectMutIter { ptr: ptr, cur: 0, _marker: PhantomData } - } + pub fn new(ptr: *mut AVSubtitle) -> Self { + RectMutIter { + ptr: ptr, + cur: 0, + _marker: PhantomData, + } + } } impl<'a> Iterator for RectMutIter<'a> { - type Item = RectMut<'a>; + type Item = RectMut<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.cur >= (*self.ptr).num_rects { - None - } - else { - self.cur += 1; - Some(RectMut::wrap(*(*self.ptr).rects.offset((self.cur - 1) as isize))) - } - } - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.cur >= (*self.ptr).num_rects { + None + } else { + self.cur += 1; + Some(RectMut::wrap(*(*self.ptr) + .rects + .offset((self.cur - 1) as isize))) + } + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.ptr).num_rects as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.ptr).num_rects as usize; - (length - self.cur as usize, Some(length - self.cur as usize)) - } - } + (length - self.cur as usize, Some(length - self.cur as usize)) + } + } } -impl<'a> ExactSizeIterator for RectMutIter<'a> { } +impl<'a> ExactSizeIterator for RectMutIter<'a> {} diff --git a/src/codec/subtitle/rect.rs b/src/codec/subtitle/rect.rs index cc054b4..0abafdc 100644 --- a/src/codec/subtitle/rect.rs +++ b/src/codec/subtitle/rect.rs @@ -1,150 +1,150 @@ -use std::marker::PhantomData; use std::ffi::CStr; +use std::marker::PhantomData; use std::str::from_utf8_unchecked; +use super::{Flags, Type}; use ffi::*; -use super::{Type, Flags}; -use ::{format, Picture}; +use {format, Picture}; pub enum Rect<'a> { - None(*const AVSubtitleRect), - Bitmap(Bitmap<'a>), - Text(Text<'a>), - Ass(Ass<'a>), + None(*const AVSubtitleRect), + Bitmap(Bitmap<'a>), + Text(Text<'a>), + Ass(Ass<'a>), } impl<'a> Rect<'a> { - pub unsafe fn wrap(ptr: *const AVSubtitleRect) -> Self { - match Type::from((*ptr).type_) { - Type::None => Rect::None(ptr), - Type::Bitmap => Rect::Bitmap(Bitmap::wrap(ptr)), - Type::Text => Rect::Text(Text::wrap(ptr)), - Type::Ass => Rect::Ass(Ass::wrap(ptr)) - } - } + pub unsafe fn wrap(ptr: *const AVSubtitleRect) -> Self { + match Type::from((*ptr).type_) { + Type::None => Rect::None(ptr), + Type::Bitmap => Rect::Bitmap(Bitmap::wrap(ptr)), + Type::Text => Rect::Text(Text::wrap(ptr)), + Type::Ass => Rect::Ass(Ass::wrap(ptr)), + } + } - pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { - match self { - &Rect::None(ptr) => ptr, - &Rect::Bitmap(ref b) => b.as_ptr(), - &Rect::Text(ref t) => t.as_ptr(), - &Rect::Ass(ref a) => a.as_ptr() - } - } + pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { + match *self { + Rect::None(ptr) => ptr, + Rect::Bitmap(ref b) => b.as_ptr(), + Rect::Text(ref t) => t.as_ptr(), + Rect::Ass(ref a) => a.as_ptr(), + } + } } impl<'a> Rect<'a> { - pub fn flags(&self) -> Flags { - unsafe { - Flags::from_bits_truncate(match self { - &Rect::None(ptr) => (*ptr).flags, - &Rect::Bitmap(ref b) => (*b.as_ptr()).flags, - &Rect::Text(ref t) => (*t.as_ptr()).flags, - &Rect::Ass(ref a) => (*a.as_ptr()).flags - }) - } - } + pub fn flags(&self) -> Flags { + unsafe { + Flags::from_bits_truncate(match *self { + Rect::None(ptr) => (*ptr).flags, + Rect::Bitmap(ref b) => (*b.as_ptr()).flags, + Rect::Text(ref t) => (*t.as_ptr()).flags, + Rect::Ass(ref a) => (*a.as_ptr()).flags, + }) + } + } } pub struct Bitmap<'a> { - ptr: *const AVSubtitleRect, + ptr: *const AVSubtitleRect, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Bitmap<'a> { - pub unsafe fn wrap(ptr: *const AVSubtitleRect) -> Self { - Bitmap { ptr: ptr, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *const AVSubtitleRect) -> Self { + Bitmap { + ptr: ptr, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { - self.ptr - } + pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { + self.ptr + } } impl<'a> Bitmap<'a> { - pub fn x(&self) -> usize { - unsafe { - (*self.as_ptr()).x as usize - } - } + pub fn x(&self) -> usize { + unsafe { (*self.as_ptr()).x as usize } + } - pub fn y(&self) -> usize { - unsafe { - (*self.as_ptr()).y as usize - } - } + pub fn y(&self) -> usize { + unsafe { (*self.as_ptr()).y as usize } + } - pub fn width(&self) -> u32 { - unsafe { - (*self.as_ptr()).w as u32 - } - } + pub fn width(&self) -> u32 { + unsafe { (*self.as_ptr()).w as u32 } + } - pub fn height(&self) -> u32 { - unsafe { - (*self.as_ptr()).h as u32 - } - } + pub fn height(&self) -> u32 { + unsafe { (*self.as_ptr()).h as u32 } + } - pub fn colors(&self) -> usize { - unsafe { - (*self.as_ptr()).nb_colors as usize - } - } + pub fn colors(&self) -> usize { + unsafe { (*self.as_ptr()).nb_colors as usize } + } - // XXX: must split Picture and PictureMut - pub fn picture(&self, format: format::Pixel) -> Picture<'a> { - unsafe { - Picture::wrap(&(*self.as_ptr()).pict as *const _ as *mut _, format, (*self.as_ptr()).w as u32, (*self.as_ptr()).h as u32) - } - } + // XXX: must split Picture and PictureMut + pub fn picture(&self, format: format::Pixel) -> Picture<'a> { + unsafe { + Picture::wrap( + &(*self.as_ptr()).pict as *const _ as *mut _, + format, + (*self.as_ptr()).w as u32, + (*self.as_ptr()).h as u32, + ) + } + } } pub struct Text<'a> { - ptr: *const AVSubtitleRect, + ptr: *const AVSubtitleRect, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Text<'a> { - pub unsafe fn wrap(ptr: *const AVSubtitleRect) -> Self { - Text { ptr: ptr, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *const AVSubtitleRect) -> Self { + Text { + ptr: ptr, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { - self.ptr - } + pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { + self.ptr + } } impl<'a> Text<'a> { - pub fn get(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).text).to_bytes()) - } - } + pub fn get(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).text).to_bytes()) } + } } pub struct Ass<'a> { - ptr: *const AVSubtitleRect, + ptr: *const AVSubtitleRect, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Ass<'a> { - pub unsafe fn wrap(ptr: *const AVSubtitleRect) -> Self { - Ass { ptr: ptr, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *const AVSubtitleRect) -> Self { + Ass { + ptr: ptr, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { - self.ptr - } + pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { + self.ptr + } } impl<'a> Ass<'a> { - pub fn get(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).ass).to_bytes()) - } - } + pub fn get(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).ass).to_bytes()) } + } } diff --git a/src/codec/subtitle/rect_mut.rs b/src/codec/subtitle/rect_mut.rs index cde09dc..76ed5d2 100644 --- a/src/codec/subtitle/rect_mut.rs +++ b/src/codec/subtitle/rect_mut.rs @@ -1,173 +1,179 @@ -use std::ops::Deref; use std::ffi::CString; +use std::ops::Deref; -use libc::c_int; +use super::{Ass, Bitmap, Flags, Text, Type}; use ffi::*; -use super::{Type, Flags, Bitmap, Text, Ass}; +use libc::c_int; pub enum RectMut<'a> { - None(*mut AVSubtitleRect), - Bitmap(BitmapMut<'a>), - Text(TextMut<'a>), - Ass(AssMut<'a>), + None(*mut AVSubtitleRect), + Bitmap(BitmapMut<'a>), + Text(TextMut<'a>), + Ass(AssMut<'a>), } impl<'a> RectMut<'a> { - pub unsafe fn wrap(ptr: *mut AVSubtitleRect) -> Self { - match Type::from((*ptr).type_) { - Type::None => RectMut::None(ptr), - Type::Bitmap => RectMut::Bitmap(BitmapMut::wrap(ptr)), - Type::Text => RectMut::Text(TextMut::wrap(ptr)), - Type::Ass => RectMut::Ass(AssMut::wrap(ptr)) - } - } + pub unsafe fn wrap(ptr: *mut AVSubtitleRect) -> Self { + match Type::from((*ptr).type_) { + Type::None => RectMut::None(ptr), + Type::Bitmap => RectMut::Bitmap(BitmapMut::wrap(ptr)), + Type::Text => RectMut::Text(TextMut::wrap(ptr)), + Type::Ass => RectMut::Ass(AssMut::wrap(ptr)), + } + } - pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { - match self { - &RectMut::None(ptr) => ptr as *const _, - &RectMut::Bitmap(ref b) => b.as_ptr(), - &RectMut::Text(ref t) => t.as_ptr(), - &RectMut::Ass(ref a) => a.as_ptr() - } - } + pub unsafe fn as_ptr(&self) -> *const AVSubtitleRect { + match *self { + RectMut::None(ptr) => ptr as *const _, + RectMut::Bitmap(ref b) => b.as_ptr(), + RectMut::Text(ref t) => t.as_ptr(), + RectMut::Ass(ref a) => a.as_ptr(), + } + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitleRect { - match self { - &mut RectMut::None(ptr) => ptr, - &mut RectMut::Bitmap(ref mut b) => b.as_mut_ptr(), - &mut RectMut::Text(ref mut t) => t.as_mut_ptr(), - &mut RectMut::Ass(ref mut a) => a.as_mut_ptr() - } - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitleRect { + match *self { + RectMut::None(ptr) => ptr, + RectMut::Bitmap(ref mut b) => b.as_mut_ptr(), + RectMut::Text(ref mut t) => t.as_mut_ptr(), + RectMut::Ass(ref mut a) => a.as_mut_ptr(), + } + } } impl<'a> RectMut<'a> { - pub fn flags(&self) -> Flags { - unsafe { - Flags::from_bits_truncate(match self { - &RectMut::None(ptr) => (*ptr).flags, - &RectMut::Bitmap(ref b) => (*b.as_ptr()).flags, - &RectMut::Text(ref t) => (*t.as_ptr()).flags, - &RectMut::Ass(ref a) => (*a.as_ptr()).flags - }) - } - } + pub fn flags(&self) -> Flags { + unsafe { + Flags::from_bits_truncate(match *self { + RectMut::None(ptr) => (*ptr).flags, + RectMut::Bitmap(ref b) => (*b.as_ptr()).flags, + RectMut::Text(ref t) => (*t.as_ptr()).flags, + RectMut::Ass(ref a) => (*a.as_ptr()).flags, + }) + } + } } pub struct BitmapMut<'a> { - immutable: Bitmap<'a>, + immutable: Bitmap<'a>, } impl<'a> BitmapMut<'a> { - pub unsafe fn wrap(ptr: *mut AVSubtitleRect) -> Self { - BitmapMut { immutable: Bitmap::wrap(ptr as *const _) } - } + pub unsafe fn wrap(ptr: *mut AVSubtitleRect) -> Self { + BitmapMut { + immutable: Bitmap::wrap(ptr as *const _), + } + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitleRect { - self.as_ptr() as *mut _ - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitleRect { + self.as_ptr() as *mut _ + } } impl<'a> BitmapMut<'a> { - pub fn set_x(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).x = value as c_int; - } - } + pub fn set_x(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).x = value as c_int; + } + } - pub fn set_y(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).y = value as c_int; - } - } + pub fn set_y(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).y = value as c_int; + } + } - pub fn set_width(&mut self, value: u32) { - unsafe { - (*self.as_mut_ptr()).w = value as c_int; - } - } + pub fn set_width(&mut self, value: u32) { + unsafe { + (*self.as_mut_ptr()).w = value as c_int; + } + } - pub fn set_height(&mut self, value: u32) { - unsafe { - (*self.as_mut_ptr()).h = value as c_int; - } - } + pub fn set_height(&mut self, value: u32) { + unsafe { + (*self.as_mut_ptr()).h = value as c_int; + } + } - pub fn set_colors(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).nb_colors = value as c_int; - } - } + pub fn set_colors(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).nb_colors = value as c_int; + } + } } impl<'a> Deref for BitmapMut<'a> { - type Target = Bitmap<'a>; + type Target = Bitmap<'a>; - fn deref(&self) -> &Self::Target { - &self.immutable - } + fn deref(&self) -> &Self::Target { + &self.immutable + } } pub struct TextMut<'a> { - immutable: Text<'a>, + immutable: Text<'a>, } impl<'a> TextMut<'a> { - pub unsafe fn wrap(ptr: *mut AVSubtitleRect) -> Self { - TextMut { immutable: Text::wrap(ptr as *const _) } - } + pub unsafe fn wrap(ptr: *mut AVSubtitleRect) -> Self { + TextMut { + immutable: Text::wrap(ptr as *const _), + } + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitleRect { - self.as_ptr() as *mut _ - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitleRect { + self.as_ptr() as *mut _ + } } impl<'a> TextMut<'a> { - pub fn set(&mut self, value: &str) { - let value = CString::new(value).unwrap(); + pub fn set(&mut self, value: &str) { + let value = CString::new(value).unwrap(); - unsafe { - (*self.as_mut_ptr()).text = av_strdup(value.as_ptr()); - } - } + unsafe { + (*self.as_mut_ptr()).text = av_strdup(value.as_ptr()); + } + } } impl<'a> Deref for TextMut<'a> { - type Target = Text<'a>; + type Target = Text<'a>; - fn deref(&self) -> &Self::Target { - &self.immutable - } + fn deref(&self) -> &Self::Target { + &self.immutable + } } pub struct AssMut<'a> { - immutable: Ass<'a>, + immutable: Ass<'a>, } impl<'a> AssMut<'a> { - pub unsafe fn wrap(ptr: *mut AVSubtitleRect) -> Self { - AssMut { immutable: Ass::wrap(ptr) } - } + pub unsafe fn wrap(ptr: *mut AVSubtitleRect) -> Self { + AssMut { + immutable: Ass::wrap(ptr), + } + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitleRect { - self.as_ptr() as *mut _ - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVSubtitleRect { + self.as_ptr() as *mut _ + } } impl<'a> AssMut<'a> { - pub fn set(&mut self, value: &str) { - let value = CString::new(value).unwrap(); + pub fn set(&mut self, value: &str) { + let value = CString::new(value).unwrap(); - unsafe { - (*self.as_mut_ptr()).ass = av_strdup(value.as_ptr()); - } - } + unsafe { + (*self.as_mut_ptr()).ass = av_strdup(value.as_ptr()); + } + } } impl<'a> Deref for AssMut<'a> { - type Target = Ass<'a>; + type Target = Ass<'a>; - fn deref(&self) -> &Self::Target { - &self.immutable - } + fn deref(&self) -> &Self::Target { + &self.immutable + } } diff --git a/src/codec/threading.rs b/src/codec/threading.rs index d7e01ed..4c3069d 100644 --- a/src/codec/threading.rs +++ b/src/codec/threading.rs @@ -1,61 +1,70 @@ -use libc::c_int; use ffi::*; +use libc::c_int; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub struct Config { - pub kind: Type, - pub count: usize, - pub safe: bool, + pub kind: Type, + pub count: usize, + pub safe: bool, } impl Config { - pub fn kind(value: Type) -> Self { - Config { kind: value, .. Default::default() } - } + pub fn kind(value: Type) -> Self { + Config { + kind: value, + ..Default::default() + } + } - pub fn count(value: usize) -> Self { - Config { count: value, .. Default::default() } - } + pub fn count(value: usize) -> Self { + Config { + count: value, + ..Default::default() + } + } - pub fn safe(value: bool) -> Self { - Config { safe: value, .. Default::default() } - } + pub fn safe(value: bool) -> Self { + Config { + safe: value, + ..Default::default() + } + } } impl Default for Config { - fn default() -> Self { - Config { - kind: Type::None, - count: 0, - safe: false, - } - } + fn default() -> Self { + Config { + kind: Type::None, + count: 0, + safe: false, + } + } } #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Type { - None, - Frame, - Slice, + None, + Frame, + Slice, } impl From for Type { - fn from(value: c_int) -> Type { - match value { - FF_THREAD_FRAME => Type::Frame, - FF_THREAD_SLICE => Type::Slice, + fn from(value: c_int) -> Type { + match value { + FF_THREAD_FRAME => Type::Frame, + FF_THREAD_SLICE => Type::Slice, - _ => Type::None, - } - } + _ => Type::None, + } + } } impl Into for Type { - fn into(self) -> c_int { - match self { - Type::None => 0, - Type::Frame => FF_THREAD_FRAME, - Type::Slice => FF_THREAD_SLICE - } - } + fn into(self) -> c_int { + match self { + Type::None => 0, + Type::Frame => FF_THREAD_FRAME, + Type::Slice => FF_THREAD_SLICE, + } + } } diff --git a/src/codec/traits.rs b/src/codec/traits.rs index b750cea..d6df325 100644 --- a/src/codec/traits.rs +++ b/src/codec/traits.rs @@ -1,113 +1,107 @@ -use ::Codec; -use codec::{Id, Audio, Video}; use super::{decoder, encoder}; +use codec::{Audio, Id, Video}; +use Codec; pub trait Decoder { - fn decoder(self) -> Option; + fn decoder(self) -> Option; } impl<'a> Decoder for &'a str { - fn decoder(self) -> Option { - decoder::find_by_name(self) - } + fn decoder(self) -> Option { + decoder::find_by_name(self) + } } impl Decoder for Id { - fn decoder(self) -> Option { - decoder::find(self) - } + fn decoder(self) -> Option { + decoder::find(self) + } } impl Decoder for Codec { - fn decoder(self) -> Option { - if self.is_decoder() { - Some(self) - } - else { - None - } - } + fn decoder(self) -> Option { + if self.is_decoder() { + Some(self) + } else { + None + } + } } impl Decoder for Option { - fn decoder(self) -> Option { - self.and_then(|c| c.decoder()) - } + fn decoder(self) -> Option { + self.and_then(|c| c.decoder()) + } } impl Decoder for Audio { - fn decoder(self) -> Option { - if self.is_decoder() { - Some(*&*self) - } - else { - None - } - } + fn decoder(self) -> Option { + if self.is_decoder() { + Some(*self) + } else { + None + } + } } impl Decoder for Video { - fn decoder(self) -> Option { - if self.is_decoder() { - Some(*&*self) - } - else { - None - } - } + fn decoder(self) -> Option { + if self.is_decoder() { + Some(*self) + } else { + None + } + } } pub trait Encoder { - fn encoder(self) -> Option; + fn encoder(self) -> Option; } impl<'a> Encoder for &'a str { - fn encoder(self) -> Option { - encoder::find_by_name(self) - } + fn encoder(self) -> Option { + encoder::find_by_name(self) + } } impl Encoder for Id { - fn encoder(self) -> Option { - encoder::find(self) - } + fn encoder(self) -> Option { + encoder::find(self) + } } impl Encoder for Codec { - fn encoder(self) -> Option { - if self.is_encoder() { - Some(self) - } - else { - None - } - } + fn encoder(self) -> Option { + if self.is_encoder() { + Some(self) + } else { + None + } + } } impl Encoder for Option { - fn encoder(self) -> Option { - self.and_then(|c| c.encoder()) - } + fn encoder(self) -> Option { + self.and_then(|c| c.encoder()) + } } impl Encoder for Audio { - fn encoder(self) -> Option { - if self.is_encoder() { - Some(*&*self) - } - else { - None - } - } + fn encoder(self) -> Option { + if self.is_encoder() { + Some(*self) + } else { + None + } + } } impl Encoder for Video { - fn encoder(self) -> Option { - if self.is_encoder() { - Some(*&*self) - } - else { - None - } - } + fn encoder(self) -> Option { + if self.is_encoder() { + Some(*self) + } else { + None + } + } } diff --git a/src/codec/video.rs b/src/codec/video.rs index 102d386..8e9eb95 100644 --- a/src/codec/video.rs +++ b/src/codec/video.rs @@ -1,104 +1,100 @@ use std::ops::Deref; -use {Rational, format}; use super::codec::Codec; use ffi::*; +use {format, Rational}; #[derive(PartialEq, Eq, Copy, Clone)] pub struct Video { - codec: Codec, + codec: Codec, } impl Video { - pub unsafe fn new(codec: Codec) -> Video { - Video { - codec: codec, - } - } + pub unsafe fn new(codec: Codec) -> Video { + Video { codec: codec } + } } impl Video { - pub fn rates(&self) -> Option { - unsafe { - if (*self.codec.as_ptr()).supported_framerates.is_null() { - None - } - else { - Some(RateIter::new((*self.codec.as_ptr()).supported_framerates)) - } - } - } + pub fn rates(&self) -> Option { + unsafe { + if (*self.codec.as_ptr()).supported_framerates.is_null() { + None + } else { + Some(RateIter::new((*self.codec.as_ptr()).supported_framerates)) + } + } + } - pub fn formats(&self) -> Option { - unsafe { - if (*self.codec.as_ptr()).pix_fmts.is_null() { - None - } - else { - Some(FormatIter::new((*self.codec.as_ptr()).pix_fmts)) - } - } - } + pub fn formats(&self) -> Option { + unsafe { + if (*self.codec.as_ptr()).pix_fmts.is_null() { + None + } else { + Some(FormatIter::new((*self.codec.as_ptr()).pix_fmts)) + } + } + } } impl Deref for Video { - type Target = Codec; + type Target = Codec; - fn deref(&self) -> &Self::Target { - &self.codec - } + fn deref(&self) -> &Self::Target { + &self.codec + } } pub struct RateIter { - ptr: *const AVRational, + ptr: *const AVRational, } impl RateIter { - pub fn new(ptr: *const AVRational) -> Self { - RateIter { ptr: ptr } - } + pub fn new(ptr: *const AVRational) -> Self { + RateIter { ptr: ptr } + } } impl Iterator for RateIter { - type Item = Rational; + type Item = Rational; - fn next(&mut self) -> Option<::Item> { - unsafe { - if (*self.ptr).num == 0 && (*self.ptr).den == 0 { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if (*self.ptr).num == 0 && (*self.ptr).den == 0 { + return None; + } - let rate = (*self.ptr).into(); - self.ptr = self.ptr.offset(1); + let rate = (*self.ptr).into(); + self.ptr = self.ptr.offset(1); - Some(rate) - } - } + Some(rate) + } + } } pub struct FormatIter { - ptr: *const AVPixelFormat, + ptr: *const AVPixelFormat, } impl FormatIter { - pub fn new(ptr: *const AVPixelFormat) -> Self { - FormatIter { ptr: ptr } - } + pub fn new(ptr: *const AVPixelFormat) -> Self { + FormatIter { ptr: ptr } + } } impl Iterator for FormatIter { - type Item = format::Pixel; + type Item = format::Pixel; - fn next(&mut self) -> Option<::Item> { - unsafe { - if *self.ptr == AVPixelFormat::AV_PIX_FMT_NONE { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if *self.ptr == AVPixelFormat::AV_PIX_FMT_NONE { + return None; + } - let format = (*self.ptr).into(); - self.ptr = self.ptr.offset(1); + let format = (*self.ptr).into(); + self.ptr = self.ptr.offset(1); - Some(format) - } - } + Some(format) + } + } } diff --git a/src/device/extensions.rs b/src/device/extensions.rs index 850aa04..4da0364 100644 --- a/src/device/extensions.rs +++ b/src/device/extensions.rs @@ -1,79 +1,78 @@ -use std::ptr; use std::marker::PhantomData; +use std::ptr; +use device; use ffi::*; -use ::Error; -use ::format::context::common::Context; -use ::device; +use format::context::common::Context; use libc::c_int; +use Error; impl Context { - pub fn devices(&self) -> Result { - unsafe { - DeviceIter::wrap(self.as_ptr()) - } - } + pub fn devices(&self) -> Result { + unsafe { DeviceIter::wrap(self.as_ptr()) } + } } pub struct DeviceIter<'a> { - ptr: *mut AVDeviceInfoList, - cur: c_int, + ptr: *mut AVDeviceInfoList, + cur: c_int, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> DeviceIter<'a> { - pub unsafe fn wrap(ctx: *const AVFormatContext) -> Result { - let mut ptr: *mut AVDeviceInfoList = ptr::null_mut(); + pub unsafe fn wrap(ctx: *const AVFormatContext) -> Result { + let mut ptr: *mut AVDeviceInfoList = ptr::null_mut(); - match avdevice_list_devices(ctx as *mut _, &mut ptr) { - n if n < 0 => - Err(Error::from(n)), + match avdevice_list_devices(ctx as *mut _, &mut ptr) { + n if n < 0 => Err(Error::from(n)), - _ => - Ok(DeviceIter { ptr: ptr, cur: 0, _marker: PhantomData }) - } - } + _ => Ok(DeviceIter { + ptr: ptr, + cur: 0, + _marker: PhantomData, + }), + } + } } impl<'a> DeviceIter<'a> { - pub fn default(&self) -> usize { - unsafe { - (*self.ptr).default_device as usize - } - } + pub fn default(&self) -> usize { + unsafe { (*self.ptr).default_device as usize } + } } impl<'a> Drop for DeviceIter<'a> { - fn drop(&mut self) { - unsafe { - avdevice_free_list_devices(&mut self.ptr); - } - } + fn drop(&mut self) { + unsafe { + avdevice_free_list_devices(&mut self.ptr); + } + } } impl<'a> Iterator for DeviceIter<'a> { - type Item = device::Info<'a>; + type Item = device::Info<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.cur >= (*self.ptr).nb_devices { - None - } - else { - self.cur += 1; - Some(device::Info::wrap(*(*self.ptr).devices.offset((self.cur - 1) as isize))) - } - } - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.cur >= (*self.ptr).nb_devices { + None + } else { + self.cur += 1; + Some(device::Info::wrap(*(*self.ptr) + .devices + .offset((self.cur - 1) as isize))) + } + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.ptr).nb_devices as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.ptr).nb_devices as usize; - (length - self.cur as usize, Some(length - self.cur as usize)) - } - } + (length - self.cur as usize, Some(length - self.cur as usize)) + } + } } -impl<'a> ExactSizeIterator for DeviceIter<'a> { } +impl<'a> ExactSizeIterator for DeviceIter<'a> {} diff --git a/src/device/input.rs b/src/device/input.rs index 43e4fdf..548d237 100644 --- a/src/device/input.rs +++ b/src/device/input.rs @@ -1,55 +1,53 @@ use std::ptr; use ffi::*; -use ::format; -use ::Format; +use format; +use Format; pub struct AudioIter(*mut AVInputFormat); impl Iterator for AudioIter { - type Item = Format; + type Item = Format; - fn next(&mut self) -> Option<::Item> { - unsafe { - let ptr = av_input_audio_device_next(self.0); + fn next(&mut self) -> Option<::Item> { + unsafe { + let ptr = av_input_audio_device_next(self.0); - if ptr.is_null() && !self.0.is_null() { - None - } - else { - self.0 = ptr; + if ptr.is_null() && !self.0.is_null() { + None + } else { + self.0 = ptr; - Some(Format::Input(format::Input::wrap(ptr))) - } - } - } + Some(Format::Input(format::Input::wrap(ptr))) + } + } + } } pub fn audio() -> AudioIter { - AudioIter(ptr::null_mut()) + AudioIter(ptr::null_mut()) } pub struct VideoIter(*mut AVInputFormat); impl Iterator for VideoIter { - type Item = Format; + type Item = Format; - fn next(&mut self) -> Option<::Item> { - unsafe { - let ptr = av_input_video_device_next(self.0); + fn next(&mut self) -> Option<::Item> { + unsafe { + let ptr = av_input_video_device_next(self.0); - if ptr.is_null() && !self.0.is_null() { - None - } - else { - self.0 = ptr; + if ptr.is_null() && !self.0.is_null() { + None + } else { + self.0 = ptr; - Some(Format::Input(format::Input::wrap(ptr))) - } - } - } + Some(Format::Input(format::Input::wrap(ptr))) + } + } + } } pub fn video() -> VideoIter { - VideoIter(ptr::null_mut()) + VideoIter(ptr::null_mut()) } diff --git a/src/device/mod.rs b/src/device/mod.rs index 5c349fd..792bcd5 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -1,67 +1,62 @@ +pub mod extensions; pub mod input; pub mod output; -pub mod extensions; use std::ffi::CStr; -use std::str::from_utf8_unchecked; use std::marker::PhantomData; +use std::str::from_utf8_unchecked; use ffi::*; pub struct Info<'a> { - ptr: *mut AVDeviceInfo, + ptr: *mut AVDeviceInfo, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Info<'a> { - pub unsafe fn wrap(ptr: *mut AVDeviceInfo) -> Self { - Info { ptr: ptr, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *mut AVDeviceInfo) -> Self { + Info { + ptr: ptr, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVDeviceInfo { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVDeviceInfo { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVDeviceInfo { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVDeviceInfo { + self.ptr + } } impl<'a> Info<'a> { - pub fn name(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).device_name).to_bytes()) - } - } + pub fn name(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).device_name).to_bytes()) } + } - pub fn description(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).device_description).to_bytes()) - } - } + pub fn description(&self) -> &str { + unsafe { + from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).device_description).to_bytes()) + } + } } pub fn register_all() { - unsafe { - avdevice_register_all(); - } + unsafe { + avdevice_register_all(); + } } pub fn version() -> u32 { - unsafe { - avdevice_version() - } + unsafe { avdevice_version() } } pub fn configuration() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avdevice_configuration()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avdevice_configuration()).to_bytes()) } } pub fn license() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avdevice_license()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avdevice_license()).to_bytes()) } } diff --git a/src/device/output.rs b/src/device/output.rs index b0553bf..995fef8 100644 --- a/src/device/output.rs +++ b/src/device/output.rs @@ -1,55 +1,53 @@ use std::ptr; use ffi::*; -use ::format; -use ::Format; +use format; +use Format; pub struct AudioIter(*mut AVOutputFormat); impl Iterator for AudioIter { - type Item = Format; + type Item = Format; - fn next(&mut self) -> Option<::Item> { - unsafe { - let ptr = av_output_audio_device_next(self.0); + fn next(&mut self) -> Option<::Item> { + unsafe { + let ptr = av_output_audio_device_next(self.0); - if ptr.is_null() && !self.0.is_null() { - None - } - else { - self.0 = ptr; + if ptr.is_null() && !self.0.is_null() { + None + } else { + self.0 = ptr; - Some(Format::Output(format::Output::wrap(ptr))) - } - } - } + Some(Format::Output(format::Output::wrap(ptr))) + } + } + } } pub fn audio() -> AudioIter { - AudioIter(ptr::null_mut()) + AudioIter(ptr::null_mut()) } pub struct VideoIter(*mut AVOutputFormat); impl Iterator for VideoIter { - type Item = Format; + type Item = Format; - fn next(&mut self) -> Option<::Item> { - unsafe { - let ptr = av_output_video_device_next(self.0); + fn next(&mut self) -> Option<::Item> { + unsafe { + let ptr = av_output_video_device_next(self.0); - if ptr.is_null() && !self.0.is_null() { - None - } - else { - self.0 = ptr; + if ptr.is_null() && !self.0.is_null() { + None + } else { + self.0 = ptr; - Some(Format::Output(format::Output::wrap(ptr))) - } - } - } + Some(Format::Output(format::Output::wrap(ptr))) + } + } + } } pub fn video() -> VideoIter { - VideoIter(ptr::null_mut()) + VideoIter(ptr::null_mut()) } diff --git a/src/filter/context/context.rs b/src/filter/context/context.rs index b9ec709..d2145df 100644 --- a/src/filter/context/context.rs +++ b/src/filter/context/context.rs @@ -1,68 +1,67 @@ use std::marker::PhantomData; +use super::{Sink, Source}; use ffi::*; use libc::c_void; -use ::{option, format, ChannelLayout}; -use super::{Source, Sink}; +use {format, option, ChannelLayout}; pub struct Context<'a> { - ptr: *mut AVFilterContext, + ptr: *mut AVFilterContext, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Context<'a> { - pub unsafe fn wrap(ptr: *mut AVFilterContext) -> Self { - Context { ptr: ptr, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *mut AVFilterContext) -> Self { + Context { + ptr: ptr, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVFilterContext { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVFilterContext { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterContext { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterContext { + self.ptr + } } impl<'a> Context<'a> { - pub fn source(&'a mut self) -> Source<'a> { - unsafe { - Source::wrap(self) - } - } + pub fn source(&'a mut self) -> Source<'a> { + unsafe { Source::wrap(self) } + } - pub fn sink(&'a mut self) -> Sink<'a> { - unsafe { - Sink::wrap(self) - } - } + pub fn sink(&'a mut self) -> Sink<'a> { + unsafe { Sink::wrap(self) } + } - pub fn set_pixel_format(&mut self, value: format::Pixel) { - let _ = option::Settable::set::(self, "pix_fmts", &value.into()); - } + pub fn set_pixel_format(&mut self, value: format::Pixel) { + let _ = option::Settable::set::(self, "pix_fmts", &value.into()); + } - pub fn set_sample_format(&mut self, value: format::Sample) { - let _ = option::Settable::set::(self, "sample_fmts", &value.into()); - } + pub fn set_sample_format(&mut self, value: format::Sample) { + let _ = option::Settable::set::(self, "sample_fmts", &value.into()); + } - pub fn set_sample_rate(&mut self, value: u32) { - let _ = option::Settable::set(self, "sample_rates", &(value as i64)); - } + pub fn set_sample_rate(&mut self, value: u32) { + let _ = option::Settable::set(self, "sample_rates", &i64::from(value)); + } - pub fn set_channel_layout(&mut self, value: ChannelLayout) { - let _ = option::Settable::set(self, "channel_layouts", &value.bits()); - } + pub fn set_channel_layout(&mut self, value: ChannelLayout) { + let _ = option::Settable::set(self, "channel_layouts", &value.bits()); + } } unsafe impl<'a> option::Target for Context<'a> { - fn as_ptr(&self) -> *const c_void { - self.ptr as *const _ - } + fn as_ptr(&self) -> *const c_void { + self.ptr as *const _ + } - fn as_mut_ptr(&mut self) -> *mut c_void { - self.ptr as *mut _ - } + fn as_mut_ptr(&mut self) -> *mut c_void { + self.ptr as *mut _ + } } -impl<'a> option::Settable for Context<'a> { } +impl<'a> option::Settable for Context<'a> {} diff --git a/src/filter/context/sink.rs b/src/filter/context/sink.rs index 1720413..1a79b93 100644 --- a/src/filter/context/sink.rs +++ b/src/filter/context/sink.rs @@ -1,40 +1,44 @@ +use super::Context; use ffi::*; use libc::c_int; -use ::{Frame, Error}; -use super::Context; +use {Error, Frame}; pub struct Sink<'a> { - ctx: &'a mut Context<'a>, + ctx: &'a mut Context<'a>, } impl<'a> Sink<'a> { - pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Sink<'b> { - Sink { ctx: ctx } - } + pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Sink<'b> { + Sink { ctx: ctx } + } } impl<'a> Sink<'a> { - pub fn frame(&mut self, frame: &mut Frame) -> Result<(), Error> { - unsafe { - match av_buffersink_get_frame(self.ctx.as_mut_ptr(), frame.as_mut_ptr()) { - n if n >= 0 => Ok(()), - e => Err(Error::from(e)), - } - } - } + pub fn frame(&mut self, frame: &mut Frame) -> Result<(), Error> { + unsafe { + match av_buffersink_get_frame(self.ctx.as_mut_ptr(), frame.as_mut_ptr()) { + n if n >= 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn samples(&mut self, frame: &mut Frame, samples: usize) -> Result<(), Error> { - unsafe { - match av_buffersink_get_samples(self.ctx.as_mut_ptr(), frame.as_mut_ptr(), samples as c_int) { - n if n >= 0 => Ok(()), - e => Err(Error::from(e)), - } - } - } + pub fn samples(&mut self, frame: &mut Frame, samples: usize) -> Result<(), Error> { + unsafe { + match av_buffersink_get_samples( + self.ctx.as_mut_ptr(), + frame.as_mut_ptr(), + samples as c_int, + ) { + n if n >= 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn set_frame_size(&mut self, value: u32) { - unsafe { - av_buffersink_set_frame_size(self.ctx.as_mut_ptr(), value); - } - } + pub fn set_frame_size(&mut self, value: u32) { + unsafe { + av_buffersink_set_frame_size(self.ctx.as_mut_ptr(), value); + } + } } diff --git a/src/filter/context/source.rs b/src/filter/context/source.rs index 23f1edf..1b934f5 100644 --- a/src/filter/context/source.rs +++ b/src/filter/context/source.rs @@ -1,38 +1,34 @@ use std::ptr; -use ffi::*; -use ::{Error, Frame}; use super::Context; +use ffi::*; +use {Error, Frame}; pub struct Source<'a> { - ctx: &'a mut Context<'a>, + ctx: &'a mut Context<'a>, } impl<'a> Source<'a> { - pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Source<'b> { - Source { ctx: ctx } - } + pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Source<'b> { + Source { ctx: ctx } + } } impl<'a> Source<'a> { - pub fn failed_requests(&self) -> usize { - unsafe { - av_buffersrc_get_nb_failed_requests(self.ctx.as_ptr() as *mut _) as usize - } - } + pub fn failed_requests(&self) -> usize { + unsafe { av_buffersrc_get_nb_failed_requests(self.ctx.as_ptr() as *mut _) as usize } + } - pub fn add(&mut self, frame: &Frame) -> Result<(), Error> { - unsafe { - match av_buffersrc_add_frame(self.ctx.as_mut_ptr(), frame.as_ptr() as *mut _) { - 0 => Ok(()), - e => Err(Error::from(e)), - } - } - } + pub fn add(&mut self, frame: &Frame) -> Result<(), Error> { + unsafe { + match av_buffersrc_add_frame(self.ctx.as_mut_ptr(), frame.as_ptr() as *mut _) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn flush(&mut self) -> Result<(), Error> { - unsafe { - self.add(&Frame::wrap(ptr::null_mut())) - } - } + pub fn flush(&mut self) -> Result<(), Error> { + unsafe { self.add(&Frame::wrap(ptr::null_mut())) } + } } diff --git a/src/filter/filter.rs b/src/filter/filter.rs index d1b33fb..fa0ff92 100644 --- a/src/filter/filter.rs +++ b/src/filter/filter.rs @@ -1,107 +1,104 @@ use std::ffi::CStr; -use std::str::from_utf8_unchecked; use std::marker::PhantomData; +use std::str::from_utf8_unchecked; +use super::{Flags, Pad}; use ffi::*; -use super::{Pad, Flags}; pub struct Filter { - ptr: *mut AVFilter, + ptr: *mut AVFilter, } impl Filter { - pub unsafe fn wrap(ptr: *mut AVFilter) -> Self { - Filter { ptr: ptr } - } + pub unsafe fn wrap(ptr: *mut AVFilter) -> Self { + Filter { ptr: ptr } + } - pub unsafe fn as_ptr(&self) -> *const AVFilter { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVFilter { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilter { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilter { + self.ptr + } } impl Filter { - pub fn name(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) - } - } + pub fn name(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) } + } - pub fn description(&self) -> Option<&str> { - unsafe { - let ptr = (*self.as_ptr()).description; + pub fn description(&self) -> Option<&str> { + unsafe { + let ptr = (*self.as_ptr()).description; - if ptr.is_null() { - None - } - else { - Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) - } - } - } + if ptr.is_null() { + None + } else { + Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) + } + } + } - pub fn inputs(&self) -> Option { - unsafe { - let ptr = (*self.as_ptr()).inputs; + pub fn inputs(&self) -> Option { + unsafe { + let ptr = (*self.as_ptr()).inputs; - if ptr.is_null() { - None - } - else { - Some(PadIter::new((*self.as_ptr()).inputs)) - } - } - } + if ptr.is_null() { + None + } else { + Some(PadIter::new((*self.as_ptr()).inputs)) + } + } + } - pub fn outputs(&self) -> Option { - unsafe { - let ptr = (*self.as_ptr()).outputs; + pub fn outputs(&self) -> Option { + unsafe { + let ptr = (*self.as_ptr()).outputs; - if ptr.is_null() { - None - } - else { - Some(PadIter::new((*self.as_ptr()).outputs)) - } - } - } + if ptr.is_null() { + None + } else { + Some(PadIter::new((*self.as_ptr()).outputs)) + } + } + } - pub fn flags(&self) -> Flags { - unsafe { - Flags::from_bits_truncate((*self.as_ptr()).flags) - } - } + pub fn flags(&self) -> Flags { + unsafe { Flags::from_bits_truncate((*self.as_ptr()).flags) } + } } pub struct PadIter<'a> { - ptr: *const AVFilterPad, - cur: isize, + ptr: *const AVFilterPad, + cur: isize, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> PadIter<'a> { - pub fn new(ptr: *const AVFilterPad) -> Self { - PadIter { ptr: ptr, cur: 0, _marker: PhantomData } - } + pub fn new(ptr: *const AVFilterPad) -> Self { + PadIter { + ptr: ptr, + cur: 0, + _marker: PhantomData, + } + } } impl<'a> Iterator for PadIter<'a> { - type Item = Pad<'a>; + type Item = Pad<'a>; - fn next(&mut self) -> Option { - unsafe { - if self.cur >= avfilter_pad_count(self.ptr) as isize { - return None; - } + fn next(&mut self) -> Option { + unsafe { + if self.cur >= avfilter_pad_count(self.ptr) as isize { + return None; + } - let pad = Pad::wrap(self.ptr.offset(self.cur)); - self.cur += 1; + let pad = Pad::wrap(self.ptr.offset(self.cur)); + self.cur += 1; - Some(pad) - } - } + Some(pad) + } + } } diff --git a/src/filter/flag.rs b/src/filter/flag.rs index 8b1b776..0ffc2fe 100644 --- a/src/filter/flag.rs +++ b/src/filter/flag.rs @@ -1,13 +1,13 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Flags: c_int { - const DYNAMIC_INPUTS = AVFILTER_FLAG_DYNAMIC_INPUTS; - const DYNAMIC_OUTPUTS = AVFILTER_FLAG_DYNAMIC_OUTPUTS; - const SLICE_THREADS = AVFILTER_FLAG_SLICE_THREADS; - const SUPPORT_TIMELINE_GENERIC = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC; - const SUPPORT_TIMELINE_INTERNAL = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL; - const SUPPORT_TIMELINE = AVFILTER_FLAG_SUPPORT_TIMELINE; - } + pub struct Flags: c_int { + const DYNAMIC_INPUTS = AVFILTER_FLAG_DYNAMIC_INPUTS; + const DYNAMIC_OUTPUTS = AVFILTER_FLAG_DYNAMIC_OUTPUTS; + const SLICE_THREADS = AVFILTER_FLAG_SLICE_THREADS; + const SUPPORT_TIMELINE_GENERIC = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC; + const SUPPORT_TIMELINE_INTERNAL = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL; + const SUPPORT_TIMELINE = AVFILTER_FLAG_SUPPORT_TIMELINE; + } } diff --git a/src/filter/graph.rs b/src/filter/graph.rs index 744a0ea..c2ae441 100644 --- a/src/filter/graph.rs +++ b/src/filter/graph.rs @@ -1,205 +1,224 @@ +use std::ffi::{CStr, CString}; use std::ptr; -use std::ffi::{CString, CStr}; use std::str::from_utf8_unchecked; +use super::{Context, Filter}; use ffi::*; use libc::c_int; -use ::Error; -use super::{Context, Filter}; +use Error; pub struct Graph { - ptr: *mut AVFilterGraph, + ptr: *mut AVFilterGraph, } -unsafe impl Send for Graph { } -unsafe impl Sync for Graph { } +unsafe impl Send for Graph {} +unsafe impl Sync for Graph {} impl Graph { - pub unsafe fn wrap(ptr: *mut AVFilterGraph) -> Self { - Graph { ptr: ptr } - } + pub unsafe fn wrap(ptr: *mut AVFilterGraph) -> Self { + Graph { ptr: ptr } + } - pub unsafe fn as_ptr(&self) -> *const AVFilterGraph { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVFilterGraph { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterGraph { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterGraph { + self.ptr + } } impl Graph { - pub fn new() -> Self { - unsafe { - let ptr = avfilter_graph_alloc(); + pub fn new() -> Self { + unsafe { + let ptr = avfilter_graph_alloc(); - if ptr.is_null() { - panic!("out of memory"); - } + if ptr.is_null() { + panic!("out of memory"); + } - Graph::wrap(ptr) - } - } + Graph::wrap(ptr) + } + } - pub fn validate(&mut self) -> Result<(), Error> { - unsafe { - match avfilter_graph_config(self.as_mut_ptr(), ptr::null_mut()) { - 0 => Ok(()), - e => Err(Error::from(e)) - } - } - } + pub fn validate(&mut self) -> Result<(), Error> { + unsafe { + match avfilter_graph_config(self.as_mut_ptr(), ptr::null_mut()) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn add<'a, 'b>(&'a mut self, filter: &Filter, name: &str, args: &str) -> Result, Error> where 'a: 'b { - unsafe { - let name = CString::new(name).unwrap(); - let args = CString::new(args).unwrap(); - let mut context = ptr::null_mut(); + pub fn add<'a, 'b>( + &'a mut self, + filter: &Filter, + name: &str, + args: &str, + ) -> Result, Error> + where + 'a: 'b, + { + unsafe { + let name = CString::new(name).unwrap(); + let args = CString::new(args).unwrap(); + let mut context = ptr::null_mut(); - match avfilter_graph_create_filter(&mut context as *mut *mut AVFilterContext, - filter.as_ptr(), - name.as_ptr(), - args.as_ptr(), - ptr::null_mut(), - self.as_mut_ptr()) - { - n if n >= 0 => Ok(Context::wrap(context)), - e => Err(Error::from(e)), - } - } - } + match avfilter_graph_create_filter( + &mut context as *mut *mut AVFilterContext, + filter.as_ptr(), + name.as_ptr(), + args.as_ptr(), + ptr::null_mut(), + self.as_mut_ptr(), + ) { + n if n >= 0 => Ok(Context::wrap(context)), + e => Err(Error::from(e)), + } + } + } - pub fn get<'a, 'b>(&'b mut self, name: &str) -> Option> where 'a: 'b { - unsafe { - let name = CString::new(name).unwrap(); - let ptr = avfilter_graph_get_filter(self.as_mut_ptr(), name.as_ptr()); + pub fn get<'a, 'b>(&'b mut self, name: &str) -> Option> + where + 'a: 'b, + { + unsafe { + let name = CString::new(name).unwrap(); + let ptr = avfilter_graph_get_filter(self.as_mut_ptr(), name.as_ptr()); - if ptr.is_null() { - None - } - else { - Some(Context::wrap(ptr)) - } - } - } + if ptr.is_null() { + None + } else { + Some(Context::wrap(ptr)) + } + } + } - pub fn dump(&self) -> String { - unsafe { - let ptr = avfilter_graph_dump(self.as_ptr() as *mut _, ptr::null()); - let cstr = from_utf8_unchecked(CStr::from_ptr((ptr)).to_bytes()); - let string = cstr.to_owned(); + pub fn dump(&self) -> String { + unsafe { + let ptr = avfilter_graph_dump(self.as_ptr() as *mut _, ptr::null()); + let cstr = from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()); + let string = cstr.to_owned(); - av_free(ptr as *mut _); + av_free(ptr as *mut _); - string - } - } + string + } + } - pub fn input(&mut self, name: &str, pad: usize) -> Result { - Parser::new(self).input(name, pad) - } + pub fn input(&mut self, name: &str, pad: usize) -> Result { + Parser::new(self).input(name, pad) + } - pub fn output(&mut self, name: &str, pad: usize) -> Result { - Parser::new(self).output(name, pad) - } + pub fn output(&mut self, name: &str, pad: usize) -> Result { + Parser::new(self).output(name, pad) + } - pub fn parse(&mut self, spec: &str) -> Result<(), Error> { - Parser::new(self).parse(spec) - } + pub fn parse(&mut self, spec: &str) -> Result<(), Error> { + Parser::new(self).parse(spec) + } } impl Drop for Graph { - fn drop(&mut self) { - unsafe { - avfilter_graph_free(&mut self.as_mut_ptr()); - } - } + fn drop(&mut self) { + unsafe { + avfilter_graph_free(&mut self.as_mut_ptr()); + } + } } pub struct Parser<'a> { - graph: &'a mut Graph, - inputs: *mut AVFilterInOut, - outputs: *mut AVFilterInOut, + graph: &'a mut Graph, + inputs: *mut AVFilterInOut, + outputs: *mut AVFilterInOut, } impl<'a> Parser<'a> { - pub fn new(graph: &mut Graph) -> Parser { - Parser { - graph: graph, - inputs: ptr::null_mut(), - outputs: ptr::null_mut(), - } - } + pub fn new(graph: &mut Graph) -> Parser { + Parser { + graph: graph, + inputs: ptr::null_mut(), + outputs: ptr::null_mut(), + } + } - pub fn input(mut self, name: &str, pad: usize) -> Result { - unsafe { - let mut context = try!(self.graph.get(name).ok_or(Error::InvalidData)); - let input = avfilter_inout_alloc(); + pub fn input(mut self, name: &str, pad: usize) -> Result { + unsafe { + let mut context = self.graph.get(name).ok_or(Error::InvalidData)?; + let input = avfilter_inout_alloc(); - if input.is_null() { - panic!("out of memory"); - } + if input.is_null() { + panic!("out of memory"); + } - let name = CString::new(name).unwrap(); + let name = CString::new(name).unwrap(); - (*input).name = av_strdup(name.as_ptr()); - (*input).filter_ctx = context.as_mut_ptr(); - (*input).pad_idx = pad as c_int; - (*input).next = ptr::null_mut(); + (*input).name = av_strdup(name.as_ptr()); + (*input).filter_ctx = context.as_mut_ptr(); + (*input).pad_idx = pad as c_int; + (*input).next = ptr::null_mut(); - if self.inputs.is_null() { - self.inputs = input; - } - else { - (*self.inputs).next = input; - } - } + if self.inputs.is_null() { + self.inputs = input; + } else { + (*self.inputs).next = input; + } + } - Ok(self) - } + Ok(self) + } - pub fn output(mut self, name: &str, pad: usize) -> Result { - unsafe { - let mut context = try!(self.graph.get(name).ok_or(Error::InvalidData)); - let output = avfilter_inout_alloc(); + pub fn output(mut self, name: &str, pad: usize) -> Result { + unsafe { + let mut context = self.graph.get(name).ok_or(Error::InvalidData)?; + let output = avfilter_inout_alloc(); - if output.is_null() { - panic!("out of memory"); - } + if output.is_null() { + panic!("out of memory"); + } - let name = CString::new(name).unwrap(); + let name = CString::new(name).unwrap(); - (*output).name = av_strdup(name.as_ptr()); - (*output).filter_ctx = context.as_mut_ptr(); - (*output).pad_idx = pad as c_int; - (*output).next = ptr::null_mut(); + (*output).name = av_strdup(name.as_ptr()); + (*output).filter_ctx = context.as_mut_ptr(); + (*output).pad_idx = pad as c_int; + (*output).next = ptr::null_mut(); - if self.outputs.is_null() { - self.outputs = output; - } - else { - (*self.outputs).next = output; - } - } + if self.outputs.is_null() { + self.outputs = output; + } else { + (*self.outputs).next = output; + } + } - Ok(self) - } + Ok(self) + } - pub fn parse(mut self, spec: &str) -> Result<(), Error> { - unsafe { - let spec = CString::new(spec).unwrap(); + pub fn parse(mut self, spec: &str) -> Result<(), Error> { + unsafe { + let spec = CString::new(spec).unwrap(); - let result = avfilter_graph_parse_ptr(self.graph.as_mut_ptr(), - spec.as_ptr(), &mut self.inputs, &mut self.outputs, - ptr::null_mut()); + let result = avfilter_graph_parse_ptr( + self.graph.as_mut_ptr(), + spec.as_ptr(), + &mut self.inputs, + &mut self.outputs, + ptr::null_mut(), + ); - avfilter_inout_free(&mut self.inputs); - avfilter_inout_free(&mut self.outputs); + avfilter_inout_free(&mut self.inputs); + avfilter_inout_free(&mut self.outputs); - match result { - n if n >= 0 => Ok(()), - e => Err(Error::from(e)) - } - } - } + match result { + n if n >= 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } +} + +impl Default for Graph { + fn default() -> Self { + Self::new() + } } diff --git a/src/filter/mod.rs b/src/filter/mod.rs index 0a56824..bcb5aea 100644 --- a/src/filter/mod.rs +++ b/src/filter/mod.rs @@ -8,60 +8,53 @@ pub mod filter; pub use self::filter::Filter; pub mod context; -pub use self::context::{Context, Source, Sink}; +pub use self::context::{Context, Sink, Source}; pub mod graph; pub use self::graph::Graph; -use std::ffi::{CString, CStr}; +use std::ffi::{CStr, CString}; use std::str::from_utf8_unchecked; use ffi::*; -use ::Error; +use Error; pub fn register_all() { - unsafe { - avfilter_register_all(); - } + unsafe { + avfilter_register_all(); + } } pub fn register(filter: &Filter) -> Result<(), Error> { - unsafe { - match avfilter_register(filter.as_ptr() as *mut _) { - 0 => Ok(()), - _ => Err(Error::InvalidData), - } - } + unsafe { + match avfilter_register(filter.as_ptr() as *mut _) { + 0 => Ok(()), + _ => Err(Error::InvalidData), + } + } } pub fn version() -> u32 { - unsafe { - avfilter_version() - } + unsafe { avfilter_version() } } pub fn configuration() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avfilter_configuration()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avfilter_configuration()).to_bytes()) } } pub fn license() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avfilter_license()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avfilter_license()).to_bytes()) } } pub fn find(name: &str) -> Option { - unsafe { - let name = CString::new(name).unwrap(); - let ptr = avfilter_get_by_name(name.as_ptr()); + unsafe { + let name = CString::new(name).unwrap(); + let ptr = avfilter_get_by_name(name.as_ptr()); - if ptr.is_null() { - None - } - else { - Some(Filter::wrap(ptr)) - } - } + if ptr.is_null() { + None + } else { + Some(Filter::wrap(ptr)) + } + } } diff --git a/src/filter/pad.rs b/src/filter/pad.rs index bdd20a2..8491228 100644 --- a/src/filter/pad.rs +++ b/src/filter/pad.rs @@ -1,47 +1,47 @@ use std::ffi::CStr; -use std::str::from_utf8_unchecked; use std::marker::PhantomData; +use std::str::from_utf8_unchecked; use ffi::*; -use ::media; +use media; pub struct Pad<'a> { - ptr: *const AVFilterPad, + ptr: *const AVFilterPad, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Pad<'a> { - pub unsafe fn wrap(ptr: *const AVFilterPad) -> Self { - Pad { ptr: ptr, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *const AVFilterPad) -> Self { + Pad { + ptr: ptr, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVFilterPad { - self.ptr - } + pub unsafe fn as_ptr(&self) -> *const AVFilterPad { + self.ptr + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterPad { - self.ptr as *mut _ - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterPad { + self.ptr as *mut _ + } } impl<'a> Pad<'a> { - pub fn name(&self) -> Option<&str> { - unsafe { - let ptr = avfilter_pad_get_name(self.ptr, 0); + pub fn name(&self) -> Option<&str> { + unsafe { + let ptr = avfilter_pad_get_name(self.ptr, 0); - if ptr.is_null() { - None - } - else { - Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) - } - } - } + if ptr.is_null() { + None + } else { + Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) + } + } + } - pub fn medium(&self) -> media::Type { - unsafe { - media::Type::from(avfilter_pad_get_type(self.ptr, 0)) - } - } + pub fn medium(&self) -> media::Type { + unsafe { media::Type::from(avfilter_pad_get_type(self.ptr, 0)) } + } } diff --git a/src/format/chapter/chapter.rs b/src/format/chapter/chapter.rs index ad1dc0d..7d30ff4 100644 --- a/src/format/chapter/chapter.rs +++ b/src/format/chapter/chapter.rs @@ -1,65 +1,58 @@ use ffi::*; -use ::{Rational, DictionaryRef}; +use {DictionaryRef, Rational}; use format::context::common::Context; // WARNING: index refers to the offset in the chapters array (starting from 0) // it is not necessarly equal to the id (which may start at 1) pub struct Chapter<'a> { - context: &'a Context, - index: usize, + context: &'a Context, + index: usize, } impl<'a> Chapter<'a> { - pub unsafe fn wrap(context: &Context, index: usize) -> Chapter { - Chapter { context: context, index: index } - } + pub unsafe fn wrap(context: &Context, index: usize) -> Chapter { + Chapter { + context: context, + index: index, + } + } - pub unsafe fn as_ptr(&self) -> *const AVChapter { - *(*self.context.as_ptr()).chapters.offset(self.index as isize) - } + pub unsafe fn as_ptr(&self) -> *const AVChapter { + *(*self.context.as_ptr()) + .chapters + .offset(self.index as isize) + } } impl<'a> Chapter<'a> { - pub fn index(&self) -> usize { - self.index - } + pub fn index(&self) -> usize { + self.index + } - pub fn id(&self) -> i32 { - unsafe { - (*self.as_ptr()).id - } - } + pub fn id(&self) -> i32 { + unsafe { (*self.as_ptr()).id } + } - pub fn time_base(&self) -> Rational { - unsafe { - Rational::from((*self.as_ptr()).time_base) - } - } + pub fn time_base(&self) -> Rational { + unsafe { Rational::from((*self.as_ptr()).time_base) } + } - pub fn start(&self) -> i64 { - unsafe { - (*self.as_ptr()).start - } - } + pub fn start(&self) -> i64 { + unsafe { (*self.as_ptr()).start } + } - pub fn end(&self) -> i64 { - unsafe { - (*self.as_ptr()).end - } - } + pub fn end(&self) -> i64 { + unsafe { (*self.as_ptr()).end } + } - pub fn metadata(&self) -> DictionaryRef { - unsafe { - DictionaryRef::wrap((*self.as_ptr()).metadata) - } - } + pub fn metadata(&self) -> DictionaryRef { + unsafe { DictionaryRef::wrap((*self.as_ptr()).metadata) } + } } impl<'a> PartialEq for Chapter<'a> { - fn eq(&self, other: &Self) -> bool { - unsafe { - self.as_ptr() == other.as_ptr() - } - } + fn eq(&self, other: &Self) -> bool { + unsafe { self.as_ptr() == other.as_ptr() } + } } diff --git a/src/format/chapter/chapter_mut.rs b/src/format/chapter/chapter_mut.rs index 9b06af3..99a3a0f 100644 --- a/src/format/chapter/chapter_mut.rs +++ b/src/format/chapter/chapter_mut.rs @@ -1,81 +1,81 @@ -use std::ops::Deref; use std::mem; +use std::ops::Deref; -use ffi::*; -use ::{Rational, Dictionary, DictionaryMut}; use super::Chapter; +use ffi::*; use format::context::common::Context; +use {Dictionary, DictionaryMut, Rational}; // WARNING: index refers to the offset in the chapters array (starting from 0) // it is not necessarly equal to the id (which may start at 1) pub struct ChapterMut<'a> { - context: &'a mut Context, - index: usize, + context: &'a mut Context, + index: usize, - immutable: Chapter<'a>, + immutable: Chapter<'a>, } impl<'a> ChapterMut<'a> { - pub unsafe fn wrap(context: &mut Context, index: usize) -> ChapterMut { - ChapterMut { - context: mem::transmute_copy(&context), - index: index, + pub unsafe fn wrap(context: &mut Context, index: usize) -> ChapterMut { + ChapterMut { + context: mem::transmute_copy(&context), + index: index, - immutable: Chapter::wrap(mem::transmute_copy(&context), index) - } - } + immutable: Chapter::wrap(mem::transmute_copy(&context), index), + } + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVChapter { - *(*self.context.as_mut_ptr()).chapters.offset(self.index as isize) - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVChapter { + *(*self.context.as_mut_ptr()) + .chapters + .offset(self.index as isize) + } } impl<'a> ChapterMut<'a> { - pub fn set_id(&mut self, value: i32) { - unsafe { - (*self.as_mut_ptr()).id = value; - } - } + pub fn set_id(&mut self, value: i32) { + unsafe { + (*self.as_mut_ptr()).id = value; + } + } - pub fn set_time_base>(&mut self, value: R) { - unsafe { - (*self.as_mut_ptr()).time_base = value.into().into(); - } - } + pub fn set_time_base>(&mut self, value: R) { + unsafe { + (*self.as_mut_ptr()).time_base = value.into().into(); + } + } - pub fn set_start(&mut self, value: i64) { - unsafe { - (*self.as_mut_ptr()).start = value; - } - } + pub fn set_start(&mut self, value: i64) { + unsafe { + (*self.as_mut_ptr()).start = value; + } + } - pub fn set_end(&mut self, value: i64) { - unsafe { - (*self.as_mut_ptr()).end = value; - } - } + pub fn set_end(&mut self, value: i64) { + unsafe { + (*self.as_mut_ptr()).end = value; + } + } - pub fn set_metadata, V: AsRef>(&mut self, key: K, value: V) { - // dictionary.set() allocates the AVDictionary the first time a key/value is inserted - // so we want to update the metadata dictionary afterwards - unsafe { - let mut dictionary = Dictionary::own(self.metadata().as_mut_ptr()); - dictionary.set(key.as_ref(), value.as_ref()); - (*self.as_mut_ptr()).metadata = dictionary.disown(); - } - } + pub fn set_metadata, V: AsRef>(&mut self, key: K, value: V) { + // dictionary.set() allocates the AVDictionary the first time a key/value is inserted + // so we want to update the metadata dictionary afterwards + unsafe { + let mut dictionary = Dictionary::own(self.metadata().as_mut_ptr()); + dictionary.set(key.as_ref(), value.as_ref()); + (*self.as_mut_ptr()).metadata = dictionary.disown(); + } + } - pub fn metadata(&mut self) -> DictionaryMut { - unsafe { - DictionaryMut::wrap((*self.as_mut_ptr()).metadata) - } - } + pub fn metadata(&mut self) -> DictionaryMut { + unsafe { DictionaryMut::wrap((*self.as_mut_ptr()).metadata) } + } } impl<'a> Deref for ChapterMut<'a> { - type Target = Chapter<'a>; + type Target = Chapter<'a>; - fn deref(&self) -> &Self::Target { - &self.immutable - } + fn deref(&self) -> &Self::Target { + &self.immutable + } } diff --git a/src/format/context/common.rs b/src/format/context/common.rs index 52ded27..4f50366 100644 --- a/src/format/context/common.rs +++ b/src/format/context/common.rs @@ -1,325 +1,378 @@ -use std::rc::Rc; -use std::ptr; use std::mem; +use std::ptr; +use std::rc::Rc; +use super::destructor::{self, Destructor}; use ffi::*; use libc::{c_int, c_uint}; -use ::{media, Stream, StreamMut, Chapter, ChapterMut, DictionaryRef}; -use super::destructor::{self, Destructor}; +use {media, Chapter, ChapterMut, DictionaryRef, Stream, StreamMut}; pub struct Context { - ptr: *mut AVFormatContext, - dtor: Rc, + ptr: *mut AVFormatContext, + dtor: Rc, } -unsafe impl Send for Context { } +unsafe impl Send for Context {} impl Context { - pub unsafe fn wrap(ptr: *mut AVFormatContext, mode: destructor::Mode) -> Self { - Context { ptr: ptr, dtor: Rc::new(Destructor::new(ptr, mode)) } - } + pub unsafe fn wrap(ptr: *mut AVFormatContext, mode: destructor::Mode) -> Self { + Context { + ptr: ptr, + dtor: Rc::new(Destructor::new(ptr, mode)), + } + } - pub unsafe fn as_ptr(&self) -> *const AVFormatContext { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVFormatContext { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFormatContext { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFormatContext { + self.ptr + } - pub unsafe fn destructor(&self) -> Rc { - self.dtor.clone() - } + pub unsafe fn destructor(&self) -> Rc { + Rc::clone(&self.dtor) + } } impl Context { - pub fn stream<'a, 'b>(&'a self, index: usize) -> Option> where 'a: 'b { - unsafe { - if index >= (*self.as_ptr()).nb_streams as usize { - None - } - else { - Some(Stream::wrap(self, index)) - } - } - } + pub fn stream<'a, 'b>(&'a self, index: usize) -> Option> + where + 'a: 'b, + { + unsafe { + if index >= (*self.as_ptr()).nb_streams as usize { + None + } else { + Some(Stream::wrap(self, index)) + } + } + } - pub fn stream_mut<'a, 'b>(&'a mut self, index: usize) -> Option> where 'a: 'b { - unsafe { - if index >= (*self.as_ptr()).nb_streams as usize { - None - } - else { - Some(StreamMut::wrap(self, index)) - } - } - } + pub fn stream_mut<'a, 'b>(&'a mut self, index: usize) -> Option> + where + 'a: 'b, + { + unsafe { + if index >= (*self.as_ptr()).nb_streams as usize { + None + } else { + Some(StreamMut::wrap(self, index)) + } + } + } - pub fn streams(&self) -> StreamIter { - StreamIter::new(self) - } + pub fn streams(&self) -> StreamIter { + StreamIter::new(self) + } - pub fn streams_mut(&mut self) -> StreamIterMut { - StreamIterMut::new(self) - } + pub fn streams_mut(&mut self) -> StreamIterMut { + StreamIterMut::new(self) + } - pub fn duration(&self) -> i64 { - unsafe { - (*self.as_ptr()).duration - } - } + pub fn duration(&self) -> i64 { + unsafe { (*self.as_ptr()).duration } + } - pub fn nb_chapters(&self) -> u32 { - unsafe { - (*self.as_ptr()).nb_chapters - } - } + pub fn nb_chapters(&self) -> u32 { + unsafe { (*self.as_ptr()).nb_chapters } + } - pub fn chapter<'a, 'b>(&'a self, index: usize) -> Option> where 'a: 'b { - unsafe { - if index >= (*self.as_ptr()).nb_chapters as usize { - None - } - else { - Some(Chapter::wrap(self, index)) - } - } - } + pub fn chapter<'a, 'b>(&'a self, index: usize) -> Option> + where + 'a: 'b, + { + unsafe { + if index >= (*self.as_ptr()).nb_chapters as usize { + None + } else { + Some(Chapter::wrap(self, index)) + } + } + } - pub fn chapter_mut<'a, 'b>(&'a mut self, index: usize) -> Option> where 'a: 'b { - unsafe { - if index >= (*self.as_ptr()).nb_chapters as usize { - None - } - else { - Some(ChapterMut::wrap(self, index)) - } - } - } + pub fn chapter_mut<'a, 'b>(&'a mut self, index: usize) -> Option> + where + 'a: 'b, + { + unsafe { + if index >= (*self.as_ptr()).nb_chapters as usize { + None + } else { + Some(ChapterMut::wrap(self, index)) + } + } + } - pub fn chapters(&self) -> ChapterIter { - ChapterIter::new(self) - } + pub fn chapters(&self) -> ChapterIter { + ChapterIter::new(self) + } - pub fn chapters_mut(&mut self) -> ChapterIterMut { - ChapterIterMut::new(self) - } + pub fn chapters_mut(&mut self) -> ChapterIterMut { + ChapterIterMut::new(self) + } - pub fn metadata(&self) -> DictionaryRef { - unsafe { - DictionaryRef::wrap((*self.as_ptr()).metadata) - } - } + pub fn metadata(&self) -> DictionaryRef { + unsafe { DictionaryRef::wrap((*self.as_ptr()).metadata) } + } } pub struct Best<'a> { - context: &'a Context, + context: &'a Context, - wanted: i32, - related: i32, + wanted: i32, + related: i32, } impl<'a> Best<'a> { - pub unsafe fn new<'b, 'c: 'b>(context: &'c Context) -> Best<'b> { - Best { - context: context, + pub unsafe fn new<'b, 'c: 'b>(context: &'c Context) -> Best<'b> { + Best { + context: context, - wanted: -1, - related: -1, - } - } + wanted: -1, + related: -1, + } + } - pub fn wanted<'b>(mut self, stream: &'b Stream) -> Best<'a> where 'a: 'b { - self.wanted = stream.index() as i32; - self - } + pub fn wanted<'b>(mut self, stream: &'b Stream) -> Best<'a> + where + 'a: 'b, + { + self.wanted = stream.index() as i32; + self + } - pub fn related<'b>(mut self, stream: &'b Stream) -> Best<'a> where 'a: 'b { - self.related = stream.index() as i32; - self - } + pub fn related<'b>(mut self, stream: &'b Stream) -> Best<'a> + where + 'a: 'b, + { + self.related = stream.index() as i32; + self + } - pub fn best<'b>(self, kind: media::Type) -> Option> where 'a: 'b { - unsafe { - let mut decoder = ptr::null_mut(); - let index = av_find_best_stream(self.context.ptr, - kind.into(), self.wanted as c_int, self.related as c_int, - &mut decoder, 0); + pub fn best<'b>(self, kind: media::Type) -> Option> + where + 'a: 'b, + { + unsafe { + let mut decoder = ptr::null_mut(); + let index = av_find_best_stream( + self.context.ptr, + kind.into(), + self.wanted as c_int, + self.related as c_int, + &mut decoder, + 0, + ); - if index >= 0 && !decoder.is_null() { - Some(Stream::wrap(self.context, index as usize)) - } - else { - None - } - } - } + if index >= 0 && !decoder.is_null() { + Some(Stream::wrap(self.context, index as usize)) + } else { + None + } + } + } } pub struct StreamIter<'a> { - context: &'a Context, - current: c_uint, + context: &'a Context, + current: c_uint, } impl<'a> StreamIter<'a> { - pub fn new<'s, 'c: 's>(context: &'c Context) -> StreamIter<'s> { - StreamIter { context: context, current: 0 } - } + pub fn new<'s, 'c: 's>(context: &'c Context) -> StreamIter<'s> { + StreamIter { + context: context, + current: 0, + } + } } impl<'a> StreamIter<'a> { - pub fn wanted<'b, 'c>(&self, stream: &'b Stream) -> Best<'c> where 'a: 'b, 'a: 'c { - unsafe { - Best::new(self.context).wanted(stream) - } - } + pub fn wanted<'b, 'c>(&self, stream: &'b Stream) -> Best<'c> + where + 'a: 'b, + 'a: 'c, + { + unsafe { Best::new(self.context).wanted(stream) } + } - pub fn related<'b, 'c>(&self, stream: &'b Stream) -> Best<'c> where 'a: 'b, 'a: 'c { - unsafe { - Best::new(self.context).related(stream) - } - } + pub fn related<'b, 'c>(&self, stream: &'b Stream) -> Best<'c> + where + 'a: 'b, + 'a: 'c, + { + unsafe { Best::new(self.context).related(stream) } + } - pub fn best<'b>(&self, kind: media::Type) -> Option> where 'a: 'b { - unsafe { - Best::new(self.context).best(kind) - } - } + pub fn best<'b>(&self, kind: media::Type) -> Option> + where + 'a: 'b, + { + unsafe { Best::new(self.context).best(kind) } + } } impl<'a> Iterator for StreamIter<'a> { - type Item = Stream<'a>; + type Item = Stream<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.current >= (*self.context.as_ptr()).nb_streams { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.current >= (*self.context.as_ptr()).nb_streams { + return None; + } - self.current += 1; + self.current += 1; - Some(Stream::wrap(self.context, (self.current - 1) as usize)) - } - } + Some(Stream::wrap(self.context, (self.current - 1) as usize)) + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.context.as_ptr()).nb_streams as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.context.as_ptr()).nb_streams as usize; - (length - self.current as usize, Some(length - self.current as usize)) - } - } + ( + length - self.current as usize, + Some(length - self.current as usize), + ) + } + } } -impl<'a> ExactSizeIterator for StreamIter<'a> { } +impl<'a> ExactSizeIterator for StreamIter<'a> {} pub struct StreamIterMut<'a> { - context: &'a mut Context, - current: c_uint, + context: &'a mut Context, + current: c_uint, } impl<'a> StreamIterMut<'a> { - pub fn new<'s, 'c: 's>(context: &'c mut Context) -> StreamIterMut<'s> { - StreamIterMut { context: context, current: 0 } - } + pub fn new<'s, 'c: 's>(context: &'c mut Context) -> StreamIterMut<'s> { + StreamIterMut { + context: context, + current: 0, + } + } } impl<'a> Iterator for StreamIterMut<'a> { - type Item = StreamMut<'a>; + type Item = StreamMut<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.current >= (*self.context.as_ptr()).nb_streams { - return None - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.current >= (*self.context.as_ptr()).nb_streams { + return None; + } - self.current += 1; + self.current += 1; - Some(StreamMut::wrap(mem::transmute_copy(&self.context), (self.current - 1) as usize)) - } - } + Some(StreamMut::wrap( + mem::transmute_copy(&self.context), + (self.current - 1) as usize, + )) + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.context.as_ptr()).nb_streams as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.context.as_ptr()).nb_streams as usize; - (length - self.current as usize, Some(length - self.current as usize)) - } - } + ( + length - self.current as usize, + Some(length - self.current as usize), + ) + } + } } -impl<'a> ExactSizeIterator for StreamIterMut<'a> { } +impl<'a> ExactSizeIterator for StreamIterMut<'a> {} pub struct ChapterIter<'a> { - context: &'a Context, - current: c_uint, + context: &'a Context, + current: c_uint, } impl<'a> ChapterIter<'a> { - pub fn new<'s, 'c: 's>(context: &'c Context) -> ChapterIter<'s> { - ChapterIter { context: context, current: 0 } - } + pub fn new<'s, 'c: 's>(context: &'c Context) -> ChapterIter<'s> { + ChapterIter { + context: context, + current: 0, + } + } } impl<'a> Iterator for ChapterIter<'a> { - type Item = Chapter<'a>; + type Item = Chapter<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.current >= (*self.context.as_ptr()).nb_chapters { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.current >= (*self.context.as_ptr()).nb_chapters { + return None; + } - self.current += 1; + self.current += 1; - Some(Chapter::wrap(self.context, (self.current - 1) as usize)) - } - } + Some(Chapter::wrap(self.context, (self.current - 1) as usize)) + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.context.as_ptr()).nb_chapters as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.context.as_ptr()).nb_chapters as usize; - (length - self.current as usize, Some(length - self.current as usize)) - } - } + ( + length - self.current as usize, + Some(length - self.current as usize), + ) + } + } } -impl<'a> ExactSizeIterator for ChapterIter<'a> { } +impl<'a> ExactSizeIterator for ChapterIter<'a> {} pub struct ChapterIterMut<'a> { - context: &'a mut Context, - current: c_uint, + context: &'a mut Context, + current: c_uint, } impl<'a> ChapterIterMut<'a> { - pub fn new<'s, 'c: 's>(context: &'c mut Context) -> ChapterIterMut<'s> { - ChapterIterMut { context: context, current: 0 } - } + pub fn new<'s, 'c: 's>(context: &'c mut Context) -> ChapterIterMut<'s> { + ChapterIterMut { + context: context, + current: 0, + } + } } impl<'a> Iterator for ChapterIterMut<'a> { - type Item = ChapterMut<'a>; + type Item = ChapterMut<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.current >= (*self.context.as_ptr()).nb_chapters { - return None - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.current >= (*self.context.as_ptr()).nb_chapters { + return None; + } - self.current += 1; + self.current += 1; - Some(ChapterMut::wrap(mem::transmute_copy(&self.context), (self.current - 1) as usize)) - } - } + Some(ChapterMut::wrap( + mem::transmute_copy(&self.context), + (self.current - 1) as usize, + )) + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.context.as_ptr()).nb_chapters as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.context.as_ptr()).nb_chapters as usize; - (length - self.current as usize, Some(length - self.current as usize)) - } - } + ( + length - self.current as usize, + Some(length - self.current as usize), + ) + } + } } -impl<'a> ExactSizeIterator for ChapterIterMut<'a> { } +impl<'a> ExactSizeIterator for ChapterIterMut<'a> {} diff --git a/src/format/context/destructor.rs b/src/format/context/destructor.rs index 44fc017..cf2a885 100644 --- a/src/format/context/destructor.rs +++ b/src/format/context/destructor.rs @@ -2,36 +2,35 @@ use ffi::*; #[derive(Copy, Clone, Debug)] pub enum Mode { - Input, - Output, + Input, + Output, } pub struct Destructor { - ptr: *mut AVFormatContext, - mode: Mode, + ptr: *mut AVFormatContext, + mode: Mode, } impl Destructor { - pub unsafe fn new(ptr: *mut AVFormatContext, mode: Mode) -> Self { - Destructor { - ptr: ptr, - mode: mode, - } - } + pub unsafe fn new(ptr: *mut AVFormatContext, mode: Mode) -> Self { + Destructor { + ptr: ptr, + mode: mode, + } + } } impl Drop for Destructor { - fn drop(&mut self) { - unsafe { - match self.mode { - Mode::Input => - avformat_close_input(&mut self.ptr), + fn drop(&mut self) { + unsafe { + match self.mode { + Mode::Input => avformat_close_input(&mut self.ptr), - Mode::Output => { - avio_close((*self.ptr).pb); - avformat_free_context(self.ptr); - } - } - } - } + Mode::Output => { + avio_close((*self.ptr).pb); + avformat_free_context(self.ptr); + } + } + } + } } diff --git a/src/format/context/input.rs b/src/format/context/input.rs index 579d4f3..542455c 100644 --- a/src/format/context/input.rs +++ b/src/format/context/input.rs @@ -1,188 +1,190 @@ +use std::ffi::CString; +use std::mem; use std::ops::{Deref, DerefMut}; use std::ptr; -use std::mem; -use std::ffi::CString; -use ffi::*; -use ::{Error, Codec, Stream, Packet, format}; use super::common::Context; use super::destructor; +use ffi::*; use util::range::Range; +use {format, Codec, Error, Packet, Stream}; pub struct Input { - ptr: *mut AVFormatContext, - ctx: Context, + ptr: *mut AVFormatContext, + ctx: Context, } -unsafe impl Send for Input { } +unsafe impl Send for Input {} impl Input { - pub unsafe fn wrap(ptr: *mut AVFormatContext) -> Self { - Input { ptr: ptr, ctx: Context::wrap(ptr, destructor::Mode::Input) } - } + pub unsafe fn wrap(ptr: *mut AVFormatContext) -> Self { + Input { + ptr: ptr, + ctx: Context::wrap(ptr, destructor::Mode::Input), + } + } - pub unsafe fn as_ptr(&self) -> *const AVFormatContext { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVFormatContext { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFormatContext { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFormatContext { + self.ptr + } } impl Input { - pub fn format(&self) -> format::Input { - unsafe { - format::Input::wrap((*self.as_ptr()).iformat) - } - } + pub fn format(&self) -> format::Input { + unsafe { format::Input::wrap((*self.as_ptr()).iformat) } + } - pub fn video_codec(&self) -> Option { - unsafe { - let ptr = av_format_get_video_codec(self.as_ptr()); + pub fn video_codec(&self) -> Option { + unsafe { + let ptr = av_format_get_video_codec(self.as_ptr()); - if ptr.is_null() { - None - } - else { - Some(Codec::wrap(ptr)) - } - } - } + if ptr.is_null() { + None + } else { + Some(Codec::wrap(ptr)) + } + } + } - pub fn audio_codec(&self) -> Option { - unsafe { - let ptr = av_format_get_audio_codec(self.as_ptr()); + pub fn audio_codec(&self) -> Option { + unsafe { + let ptr = av_format_get_audio_codec(self.as_ptr()); - if ptr.is_null() { - None - } - else { - Some(Codec::wrap(ptr)) - } - } - } + if ptr.is_null() { + None + } else { + Some(Codec::wrap(ptr)) + } + } + } - pub fn subtitle_codec(&self) -> Option { - unsafe { - let ptr = av_format_get_subtitle_codec(self.as_ptr()); + pub fn subtitle_codec(&self) -> Option { + unsafe { + let ptr = av_format_get_subtitle_codec(self.as_ptr()); - if ptr.is_null() { - None - } - else { - Some(Codec::wrap(ptr)) - } - } - } + if ptr.is_null() { + None + } else { + Some(Codec::wrap(ptr)) + } + } + } - pub fn data_codec(&self) -> Option { - unsafe { - let ptr = av_format_get_data_codec(self.as_ptr()); + pub fn data_codec(&self) -> Option { + unsafe { + let ptr = av_format_get_data_codec(self.as_ptr()); - if ptr.is_null() { - None - } - else { - Some(Codec::wrap(ptr)) - } - } - } + if ptr.is_null() { + None + } else { + Some(Codec::wrap(ptr)) + } + } + } - pub fn probe_score(&self) -> i32 { - unsafe { - av_format_get_probe_score(self.as_ptr()) - } - } + pub fn probe_score(&self) -> i32 { + unsafe { av_format_get_probe_score(self.as_ptr()) } + } - pub fn packets(&mut self) -> PacketIter { - PacketIter::new(self) - } + pub fn packets(&mut self) -> PacketIter { + PacketIter::new(self) + } - pub fn pause(&mut self) -> Result<(), Error> { - unsafe { - match av_read_pause(self.as_mut_ptr()) { - 0 => Ok(()), - e => Err(Error::from(e)), - } - } - } + pub fn pause(&mut self) -> Result<(), Error> { + unsafe { + match av_read_pause(self.as_mut_ptr()) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn play(&mut self) -> Result<(), Error> { - unsafe { - match av_read_play(self.as_mut_ptr()) { - 0 => Ok(()), - e => Err(Error::from(e)), - } - } - } + pub fn play(&mut self) -> Result<(), Error> { + unsafe { + match av_read_play(self.as_mut_ptr()) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn seek>(&mut self, ts: i64, range: R) -> Result<(), Error> { - unsafe { - match avformat_seek_file(self.as_mut_ptr(), -1, - range.start().map(|v| *v).unwrap_or(i64::min_value()), ts, - range.end().map(|v| *v).unwrap_or(i64::max_value()), 0) - { - s if s >= 0 => Ok(()), - e => Err(Error::from(e)), - } - } - } + pub fn seek>(&mut self, ts: i64, range: R) -> Result<(), Error> { + unsafe { + match avformat_seek_file( + self.as_mut_ptr(), + -1, + range.start().cloned().unwrap_or(i64::min_value()), + ts, + range.end().cloned().unwrap_or(i64::max_value()), + 0, + ) { + s if s >= 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } } impl Deref for Input { - type Target = Context; + type Target = Context; - fn deref(&self) -> &Self::Target { - &self.ctx - } + fn deref(&self) -> &Self::Target { + &self.ctx + } } impl DerefMut for Input { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.ctx - } + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.ctx + } } pub struct PacketIter<'a> { - context: &'a mut Input, + context: &'a mut Input, } impl<'a> PacketIter<'a> { - pub fn new(context: &mut Input) -> PacketIter { - PacketIter { context: context } - } + pub fn new(context: &mut Input) -> PacketIter { + PacketIter { context: context } + } } impl<'a> Iterator for PacketIter<'a> { - type Item = (Stream<'a>, Packet); + type Item = (Stream<'a>, Packet); - fn next(&mut self) -> Option<::Item> { - let mut packet = Packet::empty(); + fn next(&mut self) -> Option<::Item> { + let mut packet = Packet::empty(); - loop { - match packet.read(self.context) { - Ok(..) => unsafe { - return Some(( - Stream::wrap(mem::transmute_copy(&self.context), packet.stream()), - packet)); - }, + loop { + match packet.read(self.context) { + Ok(..) => unsafe { + return Some(( + Stream::wrap(mem::transmute_copy(&self.context), packet.stream()), + packet, + )); + }, - Err(Error::Eof) => - return None, + Err(Error::Eof) => return None, - Err(..) => - () - } - } - } + Err(..) => (), + } + } + } } pub fn dump(ctx: &Input, index: i32, url: Option<&str>) { - let url = url.map(|u| CString::new(u).unwrap()); + let url = url.map(|u| CString::new(u).unwrap()); - unsafe { - av_dump_format(ctx.as_ptr() as *mut _, index, - url.map(|u| u.as_ptr()).unwrap_or(ptr::null()), 0); - } + unsafe { + av_dump_format( + ctx.as_ptr() as *mut _, + index, + url.map(|u| u.as_ptr()).unwrap_or(ptr::null()), + 0, + ); + } } diff --git a/src/format/context/mod.rs b/src/format/context/mod.rs index 512b1b0..5ef1667 100644 --- a/src/format/context/mod.rs +++ b/src/format/context/mod.rs @@ -11,44 +11,42 @@ pub use self::output::Output; pub mod common; pub enum Context { - Input(Input), - Output(Output), + Input(Input), + Output(Output), } -unsafe impl Send for Context { } +unsafe impl Send for Context {} impl Context { - pub fn is_input(&self) -> bool { - if let &Context::Input(..) = self { - true - } - else { - false - } - } + pub fn is_input(&self) -> bool { + if let Context::Input(..) = *self { + true + } else { + false + } + } - pub fn input(self) -> Input { - if let Context::Input(context) = self { - return context; - } + pub fn input(self) -> Input { + if let Context::Input(context) = self { + return context; + } - unreachable!(); - } + unreachable!(); + } - pub fn is_output(&self) -> bool { - if let &Context::Output(..) = self { - true - } - else { - false - } - } + pub fn is_output(&self) -> bool { + if let Context::Output(..) = *self { + true + } else { + false + } + } - pub fn output(self) -> Output { - if let Context::Output(context) = self { - return context; - } + pub fn output(self) -> Output { + if let Context::Output(context) = self { + return context; + } - unreachable!(); - } + unreachable!(); + } } diff --git a/src/format/context/output.rs b/src/format/context/output.rs index 906af67..4bda2a5 100644 --- a/src/format/context/output.rs +++ b/src/format/context/output.rs @@ -1,174 +1,180 @@ +use std::ffi::CString; +use std::mem::size_of; use std::ops::{Deref, DerefMut}; use std::ptr; -use std::mem::size_of; -use std::ffi::CString; use libc; -use ffi::*; -use ::{Error, StreamMut, ChapterMut, Rational, Dictionary, format}; use super::common::Context; use super::destructor; use codec::traits; +use ffi::*; +use {format, ChapterMut, Dictionary, Error, Rational, StreamMut}; pub struct Output { - ptr: *mut AVFormatContext, - ctx: Context, + ptr: *mut AVFormatContext, + ctx: Context, } -unsafe impl Send for Output { } +unsafe impl Send for Output {} impl Output { - pub unsafe fn wrap(ptr: *mut AVFormatContext) -> Self { - Output { ptr: ptr, ctx: Context::wrap(ptr, destructor::Mode::Output) } - } + pub unsafe fn wrap(ptr: *mut AVFormatContext) -> Self { + Output { + ptr: ptr, + ctx: Context::wrap(ptr, destructor::Mode::Output), + } + } - pub unsafe fn as_ptr(&self) -> *const AVFormatContext { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVFormatContext { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFormatContext { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFormatContext { + self.ptr + } } impl Output { - pub fn format(&self) -> format::Output { - unsafe { - format::Output::wrap((*self.as_ptr()).oformat) - } - } + pub fn format(&self) -> format::Output { + unsafe { format::Output::wrap((*self.as_ptr()).oformat) } + } - pub fn write_header(&mut self) -> Result<(), Error> { - unsafe { - match avformat_write_header(self.as_mut_ptr(), ptr::null_mut()) { - 0 => Ok(()), - e => Err(Error::from(e)), - } - } - } + pub fn write_header(&mut self) -> Result<(), Error> { + unsafe { + match avformat_write_header(self.as_mut_ptr(), ptr::null_mut()) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn write_header_with(&mut self, options: Dictionary) -> Result { - unsafe { - let mut opts = options.disown(); - let res = avformat_write_header(self.as_mut_ptr(), &mut opts); + pub fn write_header_with(&mut self, options: Dictionary) -> Result { + unsafe { + let mut opts = options.disown(); + let res = avformat_write_header(self.as_mut_ptr(), &mut opts); - match res { - 0 => Ok(Dictionary::own(opts)), - e => Err(Error::from(e)), - } - } - } + match res { + 0 => Ok(Dictionary::own(opts)), + e => Err(Error::from(e)), + } + } + } - pub fn write_trailer(&mut self) -> Result<(), Error> { - unsafe { - match av_write_trailer(self.as_mut_ptr()) { - 0 => Ok(()), - e => Err(Error::from(e)), - } - } - } + pub fn write_trailer(&mut self) -> Result<(), Error> { + unsafe { + match av_write_trailer(self.as_mut_ptr()) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } + } - pub fn add_stream(&mut self, codec: E) -> Result { - unsafe { - let codec = try!(codec.encoder().ok_or(Error::EncoderNotFound)); - let ptr = avformat_new_stream(self.as_mut_ptr(), codec.as_ptr()); + pub fn add_stream(&mut self, codec: E) -> Result { + unsafe { + let codec = codec.encoder().ok_or(Error::EncoderNotFound)?; + let ptr = avformat_new_stream(self.as_mut_ptr(), codec.as_ptr()); - if ptr.is_null() { - panic!("out of memory"); - } + if ptr.is_null() { + panic!("out of memory"); + } - let index = (*self.ctx.as_ptr()).nb_streams - 1; + let index = (*self.ctx.as_ptr()).nb_streams - 1; - Ok(StreamMut::wrap(&mut self.ctx, index as usize)) - } - } + Ok(StreamMut::wrap(&mut self.ctx, index as usize)) + } + } - pub fn add_chapter, S: AsRef>(&mut self, - id: i32, - time_base: R, - start: i64, - end: i64, - title: S) -> Result - { - // avpriv_new_chapter is private (libavformat/internal.h) + pub fn add_chapter, S: AsRef>( + &mut self, + id: i32, + time_base: R, + start: i64, + end: i64, + title: S, + ) -> Result { + // avpriv_new_chapter is private (libavformat/internal.h) - if start > end { - return Err(Error::InvalidData); - } + if start > end { + return Err(Error::InvalidData); + } - let mut existing = None; - for chapter in self.chapters() { - if chapter.id() == id { - existing = Some(chapter.index()); - break; - } - } + let mut existing = None; + for chapter in self.chapters() { + if chapter.id() == id { + existing = Some(chapter.index()); + break; + } + } - let index = match existing { - Some(index) => index, - None => unsafe { - let ptr = av_mallocz(size_of::()).as_mut().ok_or(Error::Bug)?; - let mut nb_chapters = (*self.as_ptr()).nb_chapters as i32; + let index = match existing { + Some(index) => index, + None => unsafe { + let ptr = av_mallocz(size_of::()) + .as_mut() + .ok_or(Error::Bug)?; + let mut nb_chapters = (*self.as_ptr()).nb_chapters as i32; - // chapters array will be freed by `avformat_free_context` - av_dynarray_add( - &mut (*self.as_mut_ptr()).chapters as *mut _ as *mut libc::c_void, - &mut nb_chapters, - ptr - ); + // chapters array will be freed by `avformat_free_context` + av_dynarray_add( + &mut (*self.as_mut_ptr()).chapters as *mut _ as *mut libc::c_void, + &mut nb_chapters, + ptr, + ); - if nb_chapters > 0 { - (*self.as_mut_ptr()).nb_chapters = nb_chapters as u32; - let index = (*self.ctx.as_ptr()).nb_chapters - 1; - index as usize - } - else { - // failed to add the chapter - av_freep(ptr); - return Err(Error::Bug); - } - }, - }; + if nb_chapters > 0 { + (*self.as_mut_ptr()).nb_chapters = nb_chapters as u32; + let index = (*self.ctx.as_ptr()).nb_chapters - 1; + index as usize + } else { + // failed to add the chapter + av_freep(ptr); + return Err(Error::Bug); + } + }, + }; - let mut chapter = self.chapter_mut(index) - .ok_or(Error::Bug)?; + let mut chapter = self.chapter_mut(index).ok_or(Error::Bug)?; - chapter.set_id(id); - chapter.set_time_base(time_base); - chapter.set_start(start); - chapter.set_end(end); - chapter.set_metadata("title", title); + chapter.set_id(id); + chapter.set_time_base(time_base); + chapter.set_start(start); + chapter.set_end(end); + chapter.set_metadata("title", title); - Ok(chapter) - } + Ok(chapter) + } - pub fn set_metadata(&mut self, dictionary: Dictionary) { - unsafe { - (*self.as_mut_ptr()).metadata = dictionary.disown(); - } - } + pub fn set_metadata(&mut self, dictionary: Dictionary) { + unsafe { + (*self.as_mut_ptr()).metadata = dictionary.disown(); + } + } } impl Deref for Output { - type Target = Context; + type Target = Context; - fn deref(&self) -> &Self::Target { - &self.ctx - } + fn deref(&self) -> &Self::Target { + &self.ctx + } } impl DerefMut for Output { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.ctx - } + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.ctx + } } pub fn dump(ctx: &Output, index: i32, url: Option<&str>) { - let url = url.map(|u| CString::new(u).unwrap()); + let url = url.map(|u| CString::new(u).unwrap()); - unsafe { - av_dump_format(ctx.as_ptr() as *mut _, index, - url.map(|u| u.as_ptr()).unwrap_or(ptr::null()), 1); - } + unsafe { + av_dump_format( + ctx.as_ptr() as *mut _, + index, + url.map(|u| u.as_ptr()).unwrap_or(ptr::null()), + 1, + ); + } } diff --git a/src/format/format/flag.rs b/src/format/format/flag.rs index 854aabb..3309d32 100644 --- a/src/format/format/flag.rs +++ b/src/format/format/flag.rs @@ -1,26 +1,25 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Flags: c_int { - const NO_FILE = AVFMT_NOFILE; - const NEED_NUMBER = AVFMT_NEEDNUMBER; - const SHOW_IDS = AVFMT_SHOW_IDS; - const RAW_PICTURE = AVFMT_RAWPICTURE; - const GLOBAL_HEADER = AVFMT_GLOBALHEADER; - const NO_TIMESTAMPS = AVFMT_NOTIMESTAMPS; - const GENERIC_INDEX = AVFMT_GENERIC_INDEX; - const TS_DISCONT = AVFMT_TS_DISCONT; - const VARIABLE_FPS = AVFMT_VARIABLE_FPS; - const NO_DIMENSIONS = AVFMT_NODIMENSIONS; - const NO_STREAMS = AVFMT_NOSTREAMS; - const NO_BINSEARCH = AVFMT_NOBINSEARCH; - const NO_GENSEARCH = AVFMT_NOGENSEARCH; - const NO_BYTE_SEEK = AVFMT_NO_BYTE_SEEK; - const ALLOW_FLUSH = AVFMT_ALLOW_FLUSH; - const TS_NONSTRICT = AVFMT_TS_NONSTRICT; - const TS_NEGATIVE = AVFMT_TS_NEGATIVE; - const SEEK_TO_PTS = AVFMT_SEEK_TO_PTS; - } + pub struct Flags: c_int { + const NO_FILE = AVFMT_NOFILE; + const NEED_NUMBER = AVFMT_NEEDNUMBER; + const SHOW_IDS = AVFMT_SHOW_IDS; + const RAW_PICTURE = AVFMT_RAWPICTURE; + const GLOBAL_HEADER = AVFMT_GLOBALHEADER; + const NO_TIMESTAMPS = AVFMT_NOTIMESTAMPS; + const GENERIC_INDEX = AVFMT_GENERIC_INDEX; + const TS_DISCONT = AVFMT_TS_DISCONT; + const VARIABLE_FPS = AVFMT_VARIABLE_FPS; + const NO_DIMENSIONS = AVFMT_NODIMENSIONS; + const NO_STREAMS = AVFMT_NOSTREAMS; + const NO_BINSEARCH = AVFMT_NOBINSEARCH; + const NO_GENSEARCH = AVFMT_NOGENSEARCH; + const NO_BYTE_SEEK = AVFMT_NO_BYTE_SEEK; + const ALLOW_FLUSH = AVFMT_ALLOW_FLUSH; + const TS_NONSTRICT = AVFMT_TS_NONSTRICT; + const TS_NEGATIVE = AVFMT_TS_NEGATIVE; + const SEEK_TO_PTS = AVFMT_SEEK_TO_PTS; + } } - diff --git a/src/format/format/input.rs b/src/format/format/input.rs index 052fb56..4184252 100644 --- a/src/format/format/input.rs +++ b/src/format/format/input.rs @@ -4,59 +4,57 @@ use std::str::from_utf8_unchecked; use ffi::*; pub struct Input { - ptr: *mut AVInputFormat, + ptr: *mut AVInputFormat, } impl Input { - pub unsafe fn wrap(ptr: *mut AVInputFormat) -> Self { - Input { ptr: ptr } - } + pub unsafe fn wrap(ptr: *mut AVInputFormat) -> Self { + Input { ptr: ptr } + } - pub unsafe fn as_ptr(&self) -> *const AVInputFormat { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVInputFormat { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVInputFormat { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVInputFormat { + self.ptr + } } impl Input { - pub fn name(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) - } - } + pub fn name(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) } + } - pub fn description(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) - } - } + pub fn description(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) } + } - pub fn extensions(&self) -> Vec<&str> { - unsafe { - let ptr = (*self.as_ptr()).extensions; + pub fn extensions(&self) -> Vec<&str> { + unsafe { + let ptr = (*self.as_ptr()).extensions; - if ptr.is_null() { - Vec::new() - } - else { - from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()).split(',').collect() - } - } - } + if ptr.is_null() { + Vec::new() + } else { + from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()) + .split(',') + .collect() + } + } + } - pub fn mime_types(&self) -> Vec<&str> { - unsafe { - let ptr = (*self.as_ptr()).mime_type; + pub fn mime_types(&self) -> Vec<&str> { + unsafe { + let ptr = (*self.as_ptr()).mime_type; - if ptr.is_null() { - Vec::new() - } - else { - from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()).split(',').collect() - } - } - } + if ptr.is_null() { + Vec::new() + } else { + from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()) + .split(',') + .collect() + } + } + } } diff --git a/src/format/format/iter.rs b/src/format/format/iter.rs index a0c3afc..f631c5f 100644 --- a/src/format/format/iter.rs +++ b/src/format/format/iter.rs @@ -1,65 +1,72 @@ use std::ptr; -use ffi::*; use super::{Format, Input, Output}; +use ffi::*; pub struct Iter { - input: *mut AVInputFormat, - output: *mut AVOutputFormat, - step: Step, + input: *mut AVInputFormat, + output: *mut AVOutputFormat, + step: Step, } enum Step { - Input, - Output, - Done, + Input, + Output, + Done, } impl Iter { - pub fn new() -> Self { - Iter { input: ptr::null_mut(), output: ptr::null_mut(), step: Step::Input } - } + pub fn new() -> Self { + Iter { + input: ptr::null_mut(), + output: ptr::null_mut(), + step: Step::Input, + } + } +} + +impl Default for Iter { + fn default() -> Self { + Self::new() + } } impl Iterator for Iter { - type Item = Format; + type Item = Format; - fn next(&mut self) -> Option<::Item> { - unsafe { - match self.step { - Step::Input => { - let ptr = av_iformat_next(self.input); + fn next(&mut self) -> Option<::Item> { + unsafe { + match self.step { + Step::Input => { + let ptr = av_iformat_next(self.input); - if ptr.is_null() && !self.input.is_null() { - self.step = Step::Output; + if ptr.is_null() && !self.input.is_null() { + self.step = Step::Output; - self.next() - } - else { - self.input = ptr; + self.next() + } else { + self.input = ptr; - Some(Format::Input(Input::wrap(ptr))) - } - } + Some(Format::Input(Input::wrap(ptr))) + } + } - Step::Output => { - let ptr = av_oformat_next(self.output); + Step::Output => { + let ptr = av_oformat_next(self.output); - if ptr.is_null() && !self.output.is_null() { - self.step = Step::Done; + if ptr.is_null() && !self.output.is_null() { + self.step = Step::Done; - self.next() - } - else { - self.output = ptr; + self.next() + } else { + self.output = ptr; - Some(Format::Output(Output::wrap(ptr))) - } - } + Some(Format::Output(Output::wrap(ptr))) + } + } - Step::Done => - None - } - } - } + Step::Done => None, + } + } + } } diff --git a/src/format/format/mod.rs b/src/format/format/mod.rs index 331c399..bad2c38 100644 --- a/src/format/format/mod.rs +++ b/src/format/format/mod.rs @@ -11,40 +11,40 @@ mod iter; pub use self::iter::Iter; pub enum Format { - Input(Input), - Output(Output), + Input(Input), + Output(Output), } impl Format { - pub fn name(&self) -> &str { - match self { - &Format::Input(ref f) => f.name(), - &Format::Output(ref f) => f.name() - } - } + pub fn name(&self) -> &str { + match *self { + Format::Input(ref f) => f.name(), + Format::Output(ref f) => f.name(), + } + } - pub fn description(&self) -> &str { - match self { - &Format::Input(ref f) => f.description(), - &Format::Output(ref f) => f.description() - } - } + pub fn description(&self) -> &str { + match *self { + Format::Input(ref f) => f.description(), + Format::Output(ref f) => f.description(), + } + } - pub fn extensions(&self) -> Vec<&str> { - match self { - &Format::Input(ref f) => f.extensions(), - &Format::Output(ref f) => f.extensions() - } - } + pub fn extensions(&self) -> Vec<&str> { + match *self { + Format::Input(ref f) => f.extensions(), + Format::Output(ref f) => f.extensions(), + } + } - pub fn mime_types(&self) -> Vec<&str> { - match self { - &Format::Input(ref f) => f.mime_types(), - &Format::Output(ref f) => f.mime_types() - } - } + pub fn mime_types(&self) -> Vec<&str> { + match *self { + Format::Input(ref f) => f.mime_types(), + Format::Output(ref f) => f.mime_types(), + } + } } pub fn list() -> Iter { - Iter::new() + Iter::new() } diff --git a/src/format/format/output.rs b/src/format/format/output.rs index a5d0038..e758ea9 100644 --- a/src/format/format/output.rs +++ b/src/format/format/output.rs @@ -1,82 +1,84 @@ use std::path::Path; -use std::ptr; use std::ffi::{CStr, CString}; +use std::ptr; use std::str::from_utf8_unchecked; +use super::Flags; use ffi::*; use {codec, media}; -use super::Flags; pub struct Output { - ptr: *mut AVOutputFormat, + ptr: *mut AVOutputFormat, } impl Output { - pub unsafe fn wrap(ptr: *mut AVOutputFormat) -> Self { - Output { ptr: ptr } - } + pub unsafe fn wrap(ptr: *mut AVOutputFormat) -> Self { + Output { ptr: ptr } + } - pub unsafe fn as_ptr(&self) -> *const AVOutputFormat { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const AVOutputFormat { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVOutputFormat { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVOutputFormat { + self.ptr + } } impl Output { - pub fn name(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) - } - } + pub fn name(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) } + } - pub fn description(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) - } - } + pub fn description(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) } + } - pub fn extensions(&self) -> Vec<&str> { - unsafe { - let ptr = (*self.as_ptr()).extensions; + pub fn extensions(&self) -> Vec<&str> { + unsafe { + let ptr = (*self.as_ptr()).extensions; - if ptr.is_null() { - Vec::new() - } - else { - from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()).split(',').collect() - } - } - } + if ptr.is_null() { + Vec::new() + } else { + from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()) + .split(',') + .collect() + } + } + } - pub fn mime_types(&self) -> Vec<&str> { - unsafe { - let ptr = (*self.as_ptr()).mime_type; + pub fn mime_types(&self) -> Vec<&str> { + unsafe { + let ptr = (*self.as_ptr()).mime_type; - if ptr.is_null() { - Vec::new() - } - else { - from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()).split(',').collect() - } - } - } + if ptr.is_null() { + Vec::new() + } else { + from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()) + .split(',') + .collect() + } + } + } - pub fn codec>(&self, path: &P, kind: media::Type) -> codec::Id { - // XXX: use to_cstring when stable - let path = CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap(); + pub fn codec>(&self, path: &P, kind: media::Type) -> codec::Id { + // XXX: use to_cstring when stable + let path = CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap(); - unsafe { - codec::Id::from(av_guess_codec(self.as_ptr() as *mut _, ptr::null(), path.as_ptr(), ptr::null(), kind.into())) - } - } + unsafe { + codec::Id::from(av_guess_codec( + self.as_ptr() as *mut _, + ptr::null(), + path.as_ptr(), + ptr::null(), + kind.into(), + )) + } + } - pub fn flags(&self) -> Flags { - unsafe { - Flags::from_bits_truncate((*self.as_ptr()).flags) - } - } + pub fn flags(&self) -> Flags { + unsafe { Flags::from_bits_truncate((*self.as_ptr()).flags) } + } } diff --git a/src/format/mod.rs b/src/format/mod.rs index 914ccb0..e9f28a6 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -1,6 +1,6 @@ -pub use ::util::format::{sample, Sample}; -pub use ::util::format::{pixel, Pixel}; -use ::util::interrupt; +pub use util::format::{pixel, Pixel}; +pub use util::format::{sample, Sample}; +use util::interrupt; pub mod stream; @@ -10,276 +10,316 @@ pub mod context; pub use self::context::Context; pub mod format; -pub use self::format::{Input, Output, list}; pub use self::format::{flag, Flags}; +pub use self::format::{list, Input, Output}; pub mod network; -use std::ptr; +use std::ffi::{CStr, CString}; use std::path::Path; -use std::ffi::{CString, CStr}; +use std::ptr; use std::str::from_utf8_unchecked; use ffi::*; -use ::{Error, Format, Dictionary}; +use {Dictionary, Error, Format}; pub fn register_all() { - unsafe { - av_register_all(); - } + unsafe { + av_register_all(); + } } pub fn register(format: &Format) { - match format { - &Format::Input(ref format) => unsafe { - av_register_input_format(format.as_ptr() as *mut _); - }, + match *format { + Format::Input(ref format) => unsafe { + av_register_input_format(format.as_ptr() as *mut _); + }, - &Format::Output(ref format) => unsafe { - av_register_output_format(format.as_ptr() as *mut _); - } - } + Format::Output(ref format) => unsafe { + av_register_output_format(format.as_ptr() as *mut _); + }, + } } pub fn version() -> u32 { - unsafe { - avformat_version() - } + unsafe { avformat_version() } } pub fn configuration() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avformat_configuration()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avformat_configuration()).to_bytes()) } } pub fn license() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avformat_license()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avformat_license()).to_bytes()) } } // XXX: use to_cstring when stable fn from_path>(path: &P) -> CString { - CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap() + CString::new(path.as_ref().as_os_str().to_str().unwrap()).unwrap() } // NOTE: this will be better with specialization or anonymous return types pub fn open>(path: &P, format: &Format) -> Result { - unsafe { - let mut ps = ptr::null_mut(); - let path = from_path(path); + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); - match format { - &Format::Input(ref format) => { - match avformat_open_input(&mut ps, path.as_ptr(), format.as_ptr() as *mut _, ptr::null_mut()) { - 0 => { - match avformat_find_stream_info(ps, ptr::null_mut()) { - r if r >= 0 => Ok(Context::Input(context::Input::wrap(ps))), - e => Err(Error::from(e)), - } - } + match *format { + Format::Input(ref format) => match avformat_open_input( + &mut ps, + path.as_ptr(), + format.as_ptr() as *mut _, + ptr::null_mut(), + ) { + 0 => match avformat_find_stream_info(ps, ptr::null_mut()) { + r if r >= 0 => Ok(Context::Input(context::Input::wrap(ps))), + e => Err(Error::from(e)), + }, - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + }, - &Format::Output(ref format) => { - match avformat_alloc_output_context2(&mut ps, format.as_ptr() as *mut _, ptr::null(), path.as_ptr()) { - 0 => { - match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { - 0 => Ok(Context::Output(context::Output::wrap(ps))), - e => Err(Error::from(e)), - } - } + Format::Output(ref format) => match avformat_alloc_output_context2( + &mut ps, + format.as_ptr() as *mut _, + ptr::null(), + path.as_ptr(), + ) { + 0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { + 0 => Ok(Context::Output(context::Output::wrap(ps))), + e => Err(Error::from(e)), + }, - e => Err(Error::from(e)) - } - } - } - } + e => Err(Error::from(e)), + }, + } + } } -pub fn open_with>(path: &P, format: &Format, options: Dictionary) -> Result { - unsafe { - let mut ps = ptr::null_mut(); - let path = from_path(path); - let mut opts = options.disown(); +pub fn open_with>( + path: &P, + format: &Format, + options: Dictionary, +) -> Result { + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); + let mut opts = options.disown(); - match format { - &Format::Input(ref format) => { - let res = avformat_open_input(&mut ps, path.as_ptr(), format.as_ptr() as *mut _, &mut opts); + match *format { + Format::Input(ref format) => { + let res = avformat_open_input( + &mut ps, + path.as_ptr(), + format.as_ptr() as *mut _, + &mut opts, + ); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => { - match avformat_find_stream_info(ps, ptr::null_mut()) { - r if r >= 0 => Ok(Context::Input(context::Input::wrap(ps))), - e => Err(Error::from(e)), - } - } + match res { + 0 => match avformat_find_stream_info(ps, ptr::null_mut()) { + r if r >= 0 => Ok(Context::Input(context::Input::wrap(ps))), + e => Err(Error::from(e)), + }, - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + } + } - &Format::Output(ref format) => { - match avformat_alloc_output_context2(&mut ps, format.as_ptr() as *mut _, ptr::null(), path.as_ptr()) { - 0 => { - match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { - 0 => Ok(Context::Output(context::Output::wrap(ps))), - e => Err(Error::from(e)), - } - } + Format::Output(ref format) => match avformat_alloc_output_context2( + &mut ps, + format.as_ptr() as *mut _, + ptr::null(), + path.as_ptr(), + ) { + 0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { + 0 => Ok(Context::Output(context::Output::wrap(ps))), + e => Err(Error::from(e)), + }, - e => Err(Error::from(e)) - } - } - } - } + e => Err(Error::from(e)), + }, + } + } } pub fn input>(path: &P) -> Result { - unsafe { - let mut ps = ptr::null_mut(); - let path = from_path(path); + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); - match avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), ptr::null_mut()) { - 0 => { - match avformat_find_stream_info(ps, ptr::null_mut()) { - r if r >= 0 => Ok(context::Input::wrap(ps)), - e => Err(Error::from(e)), - } - } + match avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), ptr::null_mut()) { + 0 => match avformat_find_stream_info(ps, ptr::null_mut()) { + r if r >= 0 => Ok(context::Input::wrap(ps)), + e => { + avformat_close_input(&mut ps); + Err(Error::from(e)) + } + }, - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + } + } } -pub fn input_with_dictionary>(path: &P, options: Dictionary) -> Result { - unsafe { - let mut ps = ptr::null_mut(); - let path = from_path(path); - let mut opts = options.disown(); - let res = avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), &mut opts); +pub fn input_with_dictionary>( + path: &P, + options: Dictionary, +) -> Result { + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); + let mut opts = options.disown(); + let res = avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), &mut opts); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => { - match avformat_find_stream_info(ps, ptr::null_mut()) { - r if r >= 0 => Ok(context::Input::wrap(ps)), - e => Err(Error::from(e)), - } - } + match res { + 0 => match avformat_find_stream_info(ps, ptr::null_mut()) { + r if r >= 0 => Ok(context::Input::wrap(ps)), + e => { + avformat_close_input(&mut ps); + Err(Error::from(e)) + } + }, - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + } + } } -pub fn input_with_interrupt, F>(path: &P, closure: F) -> Result - where F: FnMut() -> bool { - unsafe { - let mut ps = avformat_alloc_context(); - let path = from_path(path); - (*ps).interrupt_callback = interrupt::new(Box::new(closure)).interrupt; +pub fn input_with_interrupt, F>( + path: &P, + closure: F, +) -> Result +where + F: FnMut() -> bool, +{ + unsafe { + let mut ps = avformat_alloc_context(); + let path = from_path(path); + (*ps).interrupt_callback = interrupt::new(Box::new(closure)).interrupt; - match avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), ptr::null_mut()) { - 0 => { - match avformat_find_stream_info(ps, ptr::null_mut()) { - r if r >= 0 => Ok(context::Input::wrap(ps)), - e => Err(Error::from(e)), - } - } + match avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), ptr::null_mut()) { + 0 => match avformat_find_stream_info(ps, ptr::null_mut()) { + r if r >= 0 => Ok(context::Input::wrap(ps)), + e => { + avformat_close_input(&mut ps); + Err(Error::from(e)) + } + }, - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + } + } } pub fn output>(path: &P) -> Result { - unsafe { - let mut ps = ptr::null_mut(); - let path = from_path(path); + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); - match avformat_alloc_output_context2(&mut ps, ptr::null_mut(), ptr::null(), path.as_ptr()) { - 0 => { - match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { - 0 => Ok(context::Output::wrap(ps)), - e => Err(Error::from(e)) - } - } + match avformat_alloc_output_context2(&mut ps, ptr::null_mut(), ptr::null(), path.as_ptr()) { + 0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { + 0 => Ok(context::Output::wrap(ps)), + e => Err(Error::from(e)), + }, - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + } + } } -pub fn output_with>(path: &P, options: Dictionary) -> Result { - unsafe { - let mut ps = ptr::null_mut(); - let path = from_path(path); - let mut opts = options.disown(); +pub fn output_with>( + path: &P, + options: Dictionary, +) -> Result { + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); + let mut opts = options.disown(); - match avformat_alloc_output_context2(&mut ps, ptr::null_mut(), ptr::null(), path.as_ptr()) { - 0 => { - let res = avio_open2(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE, ptr::null(), &mut opts,); + match avformat_alloc_output_context2(&mut ps, ptr::null_mut(), ptr::null(), path.as_ptr()) { + 0 => { + let res = avio_open2( + &mut (*ps).pb, + path.as_ptr(), + AVIO_FLAG_WRITE, + ptr::null(), + &mut opts, + ); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => Ok(context::Output::wrap(ps)), - e => Err(Error::from(e)) - } - } + match res { + 0 => Ok(context::Output::wrap(ps)), + e => Err(Error::from(e)), + } + } - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + } + } } pub fn output_as>(path: &P, format: &str) -> Result { - unsafe { - let mut ps = ptr::null_mut(); - let path = from_path(path); - let format = CString::new(format).unwrap(); + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); + let format = CString::new(format).unwrap(); - match avformat_alloc_output_context2(&mut ps, ptr::null_mut(), format.as_ptr(), path.as_ptr()) { - 0 => { - match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { - 0 => Ok(context::Output::wrap(ps)), - e => Err(Error::from(e)) - } - } + match avformat_alloc_output_context2( + &mut ps, + ptr::null_mut(), + format.as_ptr(), + path.as_ptr(), + ) { + 0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { + 0 => Ok(context::Output::wrap(ps)), + e => Err(Error::from(e)), + }, - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + } + } } -pub fn output_as_with>(path: &P, format: &str, options: Dictionary) -> Result { - unsafe { - let mut ps = ptr::null_mut(); - let path = from_path(path); - let format = CString::new(format).unwrap(); - let mut opts = options.disown(); +pub fn output_as_with>( + path: &P, + format: &str, + options: Dictionary, +) -> Result { + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); + let format = CString::new(format).unwrap(); + let mut opts = options.disown(); - match avformat_alloc_output_context2(&mut ps, ptr::null_mut(), format.as_ptr(), path.as_ptr()) { - 0 => { - let res = avio_open2(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE, ptr::null(), &mut opts,); + match avformat_alloc_output_context2( + &mut ps, + ptr::null_mut(), + format.as_ptr(), + path.as_ptr(), + ) { + 0 => { + let res = avio_open2( + &mut (*ps).pb, + path.as_ptr(), + AVIO_FLAG_WRITE, + ptr::null(), + &mut opts, + ); - Dictionary::own(opts); + Dictionary::own(opts); - match res { - 0 => Ok(context::Output::wrap(ps)), - e => Err(Error::from(e)) - } - } + match res { + 0 => Ok(context::Output::wrap(ps)), + e => Err(Error::from(e)), + } + } - e => Err(Error::from(e)) - } - } + e => Err(Error::from(e)), + } + } } diff --git a/src/format/network.rs b/src/format/network.rs index da744eb..066cba2 100644 --- a/src/format/network.rs +++ b/src/format/network.rs @@ -1,13 +1,13 @@ use ffi::*; pub fn init() { - unsafe { - avformat_network_init(); - } + unsafe { + avformat_network_init(); + } } pub fn deinit() { - unsafe { - avformat_network_deinit(); - } + unsafe { + avformat_network_deinit(); + } } diff --git a/src/format/stream/disposition.rs b/src/format/stream/disposition.rs index 5bd0e38..37c4690 100644 --- a/src/format/stream/disposition.rs +++ b/src/format/stream/disposition.rs @@ -1,21 +1,21 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Disposition: c_int { - const DEFAULT = AV_DISPOSITION_DEFAULT; - const DUB = AV_DISPOSITION_DUB; - const ORIGINAL = AV_DISPOSITION_ORIGINAL; - const COMMENT = AV_DISPOSITION_COMMENT; - const LYRICS = AV_DISPOSITION_LYRICS; - const KARAOKE = AV_DISPOSITION_KARAOKE; - const FORCED = AV_DISPOSITION_FORCED; - const HEARING_IMPAIRED = AV_DISPOSITION_HEARING_IMPAIRED; - const VISUAL_IMPAIRED = AV_DISPOSITION_VISUAL_IMPAIRED; - const CLEAN_EFFECTS = AV_DISPOSITION_CLEAN_EFFECTS; - const ATTACHED_PIC = AV_DISPOSITION_ATTACHED_PIC; - const CAPTIONS = AV_DISPOSITION_CAPTIONS; - const DESCRIPTIONS = AV_DISPOSITION_DESCRIPTIONS; - const METADATA = AV_DISPOSITION_METADATA; - } + pub struct Disposition: c_int { + const DEFAULT = AV_DISPOSITION_DEFAULT; + const DUB = AV_DISPOSITION_DUB; + const ORIGINAL = AV_DISPOSITION_ORIGINAL; + const COMMENT = AV_DISPOSITION_COMMENT; + const LYRICS = AV_DISPOSITION_LYRICS; + const KARAOKE = AV_DISPOSITION_KARAOKE; + const FORCED = AV_DISPOSITION_FORCED; + const HEARING_IMPAIRED = AV_DISPOSITION_HEARING_IMPAIRED; + const VISUAL_IMPAIRED = AV_DISPOSITION_VISUAL_IMPAIRED; + const CLEAN_EFFECTS = AV_DISPOSITION_CLEAN_EFFECTS; + const ATTACHED_PIC = AV_DISPOSITION_ATTACHED_PIC; + const CAPTIONS = AV_DISPOSITION_CAPTIONS; + const DESCRIPTIONS = AV_DISPOSITION_DESCRIPTIONS; + const METADATA = AV_DISPOSITION_METADATA; + } } diff --git a/src/format/stream/stream.rs b/src/format/stream/stream.rs index 3b6c8c3..c6a2d84 100644 --- a/src/format/stream/stream.rs +++ b/src/format/stream/stream.rs @@ -1,153 +1,139 @@ -use libc::c_int; -use ffi::*; -use ::codec::{self, packet}; -use ::{Rational, Discard, DictionaryRef}; use super::Disposition; +use codec::{self, packet}; +use ffi::*; use format::context::common::Context; +use libc::c_int; +use {DictionaryRef, Discard, Rational}; pub struct Stream<'a> { - context: &'a Context, - index: usize, + context: &'a Context, + index: usize, } impl<'a> Stream<'a> { - pub unsafe fn wrap(context: &Context, index: usize) -> Stream { - Stream { context: context, index: index } - } + pub unsafe fn wrap(context: &Context, index: usize) -> Stream { + Stream { + context: context, + index: index, + } + } - pub unsafe fn as_ptr(&self) -> *const AVStream { - *(*self.context.as_ptr()).streams.offset(self.index as isize) - } + pub unsafe fn as_ptr(&self) -> *const AVStream { + *(*self.context.as_ptr()).streams.offset(self.index as isize) + } } impl<'a> Stream<'a> { - pub fn id(&self) -> i32 { - unsafe { - i32::from((*self.as_ptr()).id) - } - } + pub fn id(&self) -> i32 { + unsafe { (*self.as_ptr()).id } + } - pub fn codec(&self) -> codec::Context { - unsafe { - codec::Context::wrap((*self.as_ptr()).codec, Some(self.context.destructor())) - } - } + pub fn codec(&self) -> codec::Context { + unsafe { codec::Context::wrap((*self.as_ptr()).codec, Some(self.context.destructor())) } + } - pub fn parameters(&self) -> codec::Parameters { - unsafe { - codec::Parameters::wrap((*self.as_ptr()).codecpar, Some(self.context.destructor())) - } - } + pub fn parameters(&self) -> codec::Parameters { + unsafe { + codec::Parameters::wrap((*self.as_ptr()).codecpar, Some(self.context.destructor())) + } + } - pub fn index(&self) -> usize { - unsafe { - (*self.as_ptr()).index as usize - } - } + pub fn index(&self) -> usize { + unsafe { (*self.as_ptr()).index as usize } + } - pub fn time_base(&self) -> Rational { - unsafe { - Rational::from((*self.as_ptr()).time_base) - } - } + pub fn time_base(&self) -> Rational { + 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) -> i64 { + unsafe { (*self.as_ptr()).start_time } + } - pub fn duration(&self) -> i64 { - unsafe { - (*self.as_ptr()).duration - } - } + pub fn duration(&self) -> i64 { + unsafe { (*self.as_ptr()).duration } + } - pub fn frames(&self) -> i64 { - unsafe { - (*self.as_ptr()).nb_frames - } - } + pub fn frames(&self) -> i64 { + unsafe { (*self.as_ptr()).nb_frames } + } - pub fn disposition(&self) -> Disposition { - unsafe { - Disposition::from_bits_truncate((*self.as_ptr()).disposition) - } - } + pub fn disposition(&self) -> Disposition { + unsafe { Disposition::from_bits_truncate((*self.as_ptr()).disposition) } + } - pub fn discard(&self) -> Discard { - unsafe { - Discard::from((*self.as_ptr()).discard) - } - } + pub fn discard(&self) -> Discard { + unsafe { Discard::from((*self.as_ptr()).discard) } + } - pub fn side_data(&self) -> SideDataIter { - SideDataIter::new(self) - } + pub fn side_data(&self) -> SideDataIter { + SideDataIter::new(self) + } - pub fn rate(&self) -> Rational { - unsafe { - Rational::from(av_stream_get_r_frame_rate(self.as_ptr())) - } - } + pub fn rate(&self) -> Rational { + unsafe { Rational::from(av_stream_get_r_frame_rate(self.as_ptr())) } + } - pub fn avg_frame_rate(&self) -> Rational { - unsafe { - Rational::from((*self.as_ptr()).avg_frame_rate) - } - } + pub fn avg_frame_rate(&self) -> Rational { + unsafe { Rational::from((*self.as_ptr()).avg_frame_rate) } + } - pub fn metadata(&self) -> DictionaryRef { - unsafe { - DictionaryRef::wrap((*self.as_ptr()).metadata) - } - } + pub fn metadata(&self) -> DictionaryRef { + unsafe { DictionaryRef::wrap((*self.as_ptr()).metadata) } + } } impl<'a> PartialEq for Stream<'a> { - fn eq(&self, other: &Self) -> bool { - unsafe { - self.as_ptr() == other.as_ptr() - } - } + fn eq(&self, other: &Self) -> bool { + unsafe { self.as_ptr() == other.as_ptr() } + } } -impl<'a> Eq for Stream<'a> { } +impl<'a> Eq for Stream<'a> {} pub struct SideDataIter<'a> { - stream: &'a Stream<'a>, - current: c_int, + stream: &'a Stream<'a>, + current: c_int, } impl<'a> SideDataIter<'a> { - pub fn new<'sd, 's: 'sd>(stream: &'s Stream) -> SideDataIter<'sd> { - SideDataIter { stream: stream, current: 0 } - } + pub fn new<'sd, 's: 'sd>(stream: &'s Stream) -> SideDataIter<'sd> { + SideDataIter { + stream: stream, + current: 0, + } + } } impl<'a> Iterator for SideDataIter<'a> { - type Item = packet::SideData<'a>; + type Item = packet::SideData<'a>; - fn next(&mut self) -> Option<::Item> { - unsafe { - if self.current >= (*self.stream.as_ptr()).nb_side_data { - return None; - } + fn next(&mut self) -> Option<::Item> { + unsafe { + if self.current >= (*self.stream.as_ptr()).nb_side_data { + return None; + } - self.current += 1; + self.current += 1; - Some(packet::SideData::wrap( - (*self.stream.as_ptr()).side_data.offset((self.current - 1) as isize))) - } - } + Some(packet::SideData::wrap( + (*self.stream.as_ptr()) + .side_data + .offset((self.current - 1) as isize), + )) + } + } - fn size_hint(&self) -> (usize, Option) { - unsafe { - let length = (*self.stream.as_ptr()).nb_side_data as usize; + fn size_hint(&self) -> (usize, Option) { + unsafe { + let length = (*self.stream.as_ptr()).nb_side_data as usize; - (length - self.current as usize, Some(length - self.current as usize)) - } - } + ( + length - self.current as usize, + Some(length - self.current as usize), + ) + } + } } -impl<'a> ExactSizeIterator for SideDataIter<'a> { } +impl<'a> ExactSizeIterator for SideDataIter<'a> {} diff --git a/src/format/stream/stream_mut.rs b/src/format/stream/stream_mut.rs index b0d7a26..365ec7c 100644 --- a/src/format/stream/stream_mut.rs +++ b/src/format/stream/stream_mut.rs @@ -1,65 +1,67 @@ -use std::ops::Deref; use std::mem; +use std::ops::Deref; -use ffi::*; -use ::{Rational, codec}; use super::Stream; +use ffi::*; use format::context::common::Context; +use {codec, Rational}; pub struct StreamMut<'a> { - context: &'a mut Context, - index: usize, + context: &'a mut Context, + index: usize, - immutable: Stream<'a>, + immutable: Stream<'a>, } impl<'a> StreamMut<'a> { - pub unsafe fn wrap(context: &mut Context, index: usize) -> StreamMut { - StreamMut { - context: mem::transmute_copy(&context), - index: index, + pub unsafe fn wrap(context: &mut Context, index: usize) -> StreamMut { + StreamMut { + context: mem::transmute_copy(&context), + index: index, - immutable: Stream::wrap(mem::transmute_copy(&context), index) - } - } + immutable: Stream::wrap(mem::transmute_copy(&context), index), + } + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVStream { - *(*self.context.as_mut_ptr()).streams.offset(self.index as isize) - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVStream { + *(*self.context.as_mut_ptr()) + .streams + .offset(self.index as isize) + } } impl<'a> StreamMut<'a> { - pub fn set_time_base>(&mut self, value: R) { - unsafe { - (*self.as_mut_ptr()).time_base = value.into().into(); - } - } + pub fn set_time_base>(&mut self, value: R) { + unsafe { + (*self.as_mut_ptr()).time_base = value.into().into(); + } + } - pub fn set_rate>(&mut self, value: R) { - unsafe { - av_stream_set_r_frame_rate(self.as_mut_ptr(), value.into().into()); - } - } + pub fn set_rate>(&mut self, value: R) { + unsafe { + av_stream_set_r_frame_rate(self.as_mut_ptr(), value.into().into()); + } + } - pub fn set_avg_frame_rate>(&mut self, value: R) { - unsafe { - (*self.as_mut_ptr()).avg_frame_rate = value.into().into(); - } - } + pub fn set_avg_frame_rate>(&mut self, value: R) { + unsafe { + (*self.as_mut_ptr()).avg_frame_rate = value.into().into(); + } + } - pub fn set_parameters>(&mut self, parameters: P) { - let parameters = parameters.into(); + pub fn set_parameters>(&mut self, parameters: P) { + let parameters = parameters.into(); - unsafe { - avcodec_parameters_copy((*self.as_mut_ptr()).codecpar, parameters.as_ptr()); - } - } + unsafe { + avcodec_parameters_copy((*self.as_mut_ptr()).codecpar, parameters.as_ptr()); + } + } } impl<'a> Deref for StreamMut<'a> { - type Target = Stream<'a>; + type Target = Stream<'a>; - fn deref(&self) -> &Self::Target { - &self.immutable - } + fn deref(&self) -> &Self::Target { + &self.immutable + } } diff --git a/src/lib.rs b/src/lib.rs index c5190c4..4276dcd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,59 +1,62 @@ #![allow(non_camel_case_types)] +#![cfg_attr(feature = "cargo-clippy", allow(inline_always))] -extern crate libc; +#[macro_use] +extern crate bitflags; pub extern crate ffmpeg_sys as sys; -#[macro_use] extern crate bitflags; -#[cfg(feature = "image")] extern crate image; +#[cfg(feature = "image")] +extern crate image; +extern crate libc; pub use sys as ffi; #[macro_use] pub mod util; -pub use util::error::Error; +pub use util::channel_layout::{self, ChannelLayout}; +pub use util::chroma; +pub use util::color; pub use util::dictionary; +pub use util::dictionary::Mut as DictionaryMut; pub use util::dictionary::Owned as Dictionary; pub use util::dictionary::Ref as DictionaryRef; -pub use util::dictionary::Mut as DictionaryMut; -pub use util::rational::{self, Rational}; -pub use util::media; -pub use util::picture; -pub use util::color; -pub use util::chroma; -pub use util::time; +pub use util::error::Error; pub use util::frame::{self, Frame}; -pub use util::channel_layout::{self, ChannelLayout}; +pub use util::mathematics::{self, rescale, Rescale, Rounding}; +pub use util::media; pub use util::option; -pub use util::mathematics::{self, Rounding, Rescale, rescale}; +pub use util::picture; +pub use util::rational::{self, Rational}; +pub use util::time; #[cfg(feature = "format")] pub mod format; #[cfg(feature = "format")] +pub use format::chapter::{Chapter, ChapterMut}; +#[cfg(feature = "format")] pub use format::format::Format; #[cfg(feature = "format")] pub use format::stream::{Stream, StreamMut}; -#[cfg(feature = "format")] -pub use format::chapter::{Chapter, ChapterMut}; #[cfg(feature = "codec")] pub mod codec; #[cfg(feature = "codec")] -pub use codec::packet::{self, Packet}; -#[cfg(feature = "codec")] -pub use codec::subtitle::{self, Subtitle}; -#[cfg(feature = "codec")] -pub use codec::picture::Picture; -#[cfg(feature = "codec")] -pub use codec::discard::Discard; +pub use codec::audio_service::AudioService; #[cfg(feature = "codec")] pub use codec::codec::Codec; #[cfg(feature = "codec")] -pub use codec::{decoder, encoder}; +pub use codec::discard::Discard; #[cfg(feature = "codec")] pub use codec::field_order::FieldOrder; #[cfg(feature = "codec")] -pub use codec::audio_service::AudioService; +pub use codec::packet::{self, Packet}; +#[cfg(feature = "codec")] +pub use codec::picture::Picture; +#[cfg(feature = "codec")] +pub use codec::subtitle::{self, Subtitle}; #[cfg(feature = "codec")] pub use codec::threading; +#[cfg(feature = "codec")] +pub use codec::{decoder, encoder}; #[cfg(feature = "device")] pub mod device; @@ -66,38 +69,38 @@ pub use filter::Filter; pub mod software; fn init_error() { - util::error::register_all(); + util::error::register_all(); } #[cfg(feature = "format")] fn init_format() { - format::register_all(); + format::register_all(); } #[cfg(not(feature = "format"))] -fn init_format() { } +fn init_format() {} #[cfg(feature = "device")] fn init_device() { - device::register_all(); + device::register_all(); } #[cfg(not(feature = "device"))] -fn init_device() { } +fn init_device() {} #[cfg(feature = "filter")] fn init_filter() { - filter::register_all(); + filter::register_all(); } #[cfg(not(feature = "filter"))] -fn init_filter() { } +fn init_filter() {} pub fn init() -> Result<(), Error> { - init_error(); - init_format(); - init_device(); - init_filter(); + init_error(); + init_format(); + init_device(); + init_filter(); - Ok(()) + Ok(()) } diff --git a/src/software/mod.rs b/src/software/mod.rs index 470e0c5..c6c08a8 100644 --- a/src/software/mod.rs +++ b/src/software/mod.rs @@ -3,20 +3,33 @@ pub mod scaling; #[cfg(feature = "software-scaling")] #[inline] -pub fn scaler(format: ::format::Pixel, flags: scaling::Flags, - (in_width, in_height): (u32, u32), - (out_width, out_height): (u32, u32)) --> Result { - scaling::Context::get(format, in_width, in_height, format, out_width, out_height, flags) +pub fn scaler( + format: ::format::Pixel, + flags: scaling::Flags, + (in_width, in_height): (u32, u32), + (out_width, out_height): (u32, u32), +) -> Result { + scaling::Context::get( + format, in_width, in_height, format, out_width, out_height, flags, + ) } #[cfg(feature = "software-scaling")] #[inline] -pub fn converter((width, height): (u32, u32), - input: ::format::Pixel, - output: ::format::Pixel) --> Result { - scaling::Context::get(input, width, height, output, width, height, scaling::flag::FAST_BILINEAR) +pub fn converter( + (width, height): (u32, u32), + input: ::format::Pixel, + output: ::format::Pixel, +) -> Result { + scaling::Context::get( + input, + width, + height, + output, + width, + height, + scaling::flag::FAST_BILINEAR, + ) } #[cfg(feature = "software-resampling")] @@ -24,8 +37,11 @@ pub mod resampling; #[cfg(feature = "software-resampling")] #[inline] -pub fn resampler((in_format, in_layout, in_rate): (::format::Sample, ::ChannelLayout, u32), - (out_format, out_layout, out_rate): (::format::Sample, ::ChannelLayout, u32)) --> Result { - resampling::Context::get(in_format, in_layout, in_rate, out_format, out_layout, out_rate) +pub fn resampler( + (in_format, in_layout, in_rate): (::format::Sample, ::ChannelLayout, u32), + (out_format, out_layout, out_rate): (::format::Sample, ::ChannelLayout, u32), +) -> Result { + resampling::Context::get( + in_format, in_layout, in_rate, out_format, out_layout, out_rate, + ) } diff --git a/src/software/resampling/context.rs b/src/software/resampling/context.rs index f9f429d..bae2bfd 100644 --- a/src/software/resampling/context.rs +++ b/src/software/resampling/context.rs @@ -1,139 +1,153 @@ use std::ptr; -use libc::{c_int, int64_t}; -use ffi::*; -use ::util::format; -use ::{Error, ChannelLayout, frame}; use super::Delay; +use ffi::*; +use libc::{c_int, int64_t}; +use util::format; +use {frame, ChannelLayout, Error}; #[derive(Eq, PartialEq, Copy, Clone)] pub struct Definition { - pub format: format::Sample, - pub channel_layout: ChannelLayout, - pub rate: u32, + pub format: format::Sample, + pub channel_layout: ChannelLayout, + pub rate: u32, } pub struct Context { - ptr: *mut SwrContext, + ptr: *mut SwrContext, - input: Definition, - output: Definition, + input: Definition, + output: Definition, } impl Context { - #[doc(hidden)] - pub unsafe fn as_ptr(&self) -> *const SwrContext { - self.ptr as *const _ - } + #[doc(hidden)] + pub unsafe fn as_ptr(&self) -> *const SwrContext { + self.ptr as *const _ + } - #[doc(hidden)] - pub unsafe fn as_mut_ptr(&mut self) -> *mut SwrContext { - self.ptr - } + #[doc(hidden)] + pub unsafe fn as_mut_ptr(&mut self) -> *mut SwrContext { + self.ptr + } } impl Context { - /// Create a resampler with the given definitions. - pub fn get(src_format: format::Sample, src_channel_layout: ChannelLayout, src_rate: u32, - dst_format: format::Sample, dst_channel_layout: ChannelLayout, dst_rate: u32) -> Result { - unsafe { - let ptr = swr_alloc_set_opts(ptr::null_mut(), - dst_channel_layout.bits() as int64_t, dst_format.into(), dst_rate as c_int, - src_channel_layout.bits() as int64_t, src_format.into(), src_rate as c_int, - 0, ptr::null_mut()); + /// Create a resampler with the given definitions. + pub fn get( + src_format: format::Sample, + src_channel_layout: ChannelLayout, + src_rate: u32, + dst_format: format::Sample, + dst_channel_layout: ChannelLayout, + dst_rate: u32, + ) -> Result { + unsafe { + let ptr = swr_alloc_set_opts( + ptr::null_mut(), + dst_channel_layout.bits() as int64_t, + dst_format.into(), + dst_rate as c_int, + src_channel_layout.bits() as int64_t, + src_format.into(), + src_rate as c_int, + 0, + ptr::null_mut(), + ); - if ptr != ptr::null_mut() { - match swr_init(ptr) { - e if e < 0 => - Err(Error::from(e)), + if ptr.is_null() { + match swr_init(ptr) { + e if e < 0 => Err(Error::from(e)), - _ => - Ok(Context { - ptr: ptr, + _ => Ok(Context { + ptr: ptr, - input: Definition { - format: src_format, - channel_layout: src_channel_layout, - rate: src_rate, - }, + input: Definition { + format: src_format, + channel_layout: src_channel_layout, + rate: src_rate, + }, - output: Definition { - format: dst_format, - channel_layout: dst_channel_layout, - rate: dst_rate, - } - }) - } - } - else { - Err(Error::InvalidData) - } - } - } + output: Definition { + format: dst_format, + channel_layout: dst_channel_layout, + rate: dst_rate, + }, + }), + } + } else { + Err(Error::InvalidData) + } + } + } - /// Get the input definition. - pub fn input(&self) -> &Definition { - &self.input - } + /// Get the input definition. + pub fn input(&self) -> &Definition { + &self.input + } - /// Get the output definition. - pub fn output(&self) -> &Definition { - &self.output - } + /// Get the output definition. + pub fn output(&self) -> &Definition { + &self.output + } - /// Get the remaining delay. - pub fn delay(&self) -> Option { - unsafe { - match swr_get_delay(self.as_ptr() as *mut _, 1) { - 0 => None, - _ => Some(Delay::from(self)) - } - } - } + /// Get the remaining delay. + pub fn delay(&self) -> Option { + unsafe { + match swr_get_delay(self.as_ptr() as *mut _, 1) { + 0 => None, + _ => Some(Delay::from(self)), + } + } + } - /// Run the resampler from the given input to the given output. - /// - /// When there are internal frames to process it will return `Ok(Some(Delay { .. }))`. - pub fn run(&mut self, input: &frame::Audio, output: &mut frame::Audio) -> Result, Error> { - output.set_rate(self.output.rate); + /// Run the resampler from the given input to the given output. + /// + /// When there are internal frames to process it will return `Ok(Some(Delay { .. }))`. + pub fn run( + &mut self, + input: &frame::Audio, + output: &mut frame::Audio, + ) -> Result, Error> { + output.set_rate(self.output.rate); - unsafe { - if output.is_empty() { - output.alloc(self.output.format, input.samples(), self.output.channel_layout); - } + unsafe { + if output.is_empty() { + output.alloc( + self.output.format, + input.samples(), + self.output.channel_layout, + ); + } - match swr_convert_frame(self.as_mut_ptr(), output.as_mut_ptr(), input.as_ptr()) { - 0 => - Ok(self.delay()), + match swr_convert_frame(self.as_mut_ptr(), output.as_mut_ptr(), input.as_ptr()) { + 0 => Ok(self.delay()), - e => - Err(Error::from(e)) - } - } - } + e => Err(Error::from(e)), + } + } + } - /// Convert one of the remaining internal frames. - /// - /// When there are no more internal frames `Ok(None)` will be returned. - pub fn flush(&mut self, output: &mut frame::Audio) -> Result, Error> { - output.set_rate(self.output.rate); + /// Convert one of the remaining internal frames. + /// + /// When there are no more internal frames `Ok(None)` will be returned. + pub fn flush(&mut self, output: &mut frame::Audio) -> Result, Error> { + output.set_rate(self.output.rate); - unsafe { - match swr_convert_frame(self.as_mut_ptr(), output.as_mut_ptr(), ptr::null()) { - 0 => - Ok(self.delay()), + unsafe { + match swr_convert_frame(self.as_mut_ptr(), output.as_mut_ptr(), ptr::null()) { + 0 => Ok(self.delay()), - e => - Err(Error::from(e)) - } - } - } + e => Err(Error::from(e)), + } + } + } } impl Drop for Context { - fn drop(&mut self) { - unsafe { - swr_free(&mut self.as_mut_ptr()); - } - } + fn drop(&mut self) { + unsafe { + swr_free(&mut self.as_mut_ptr()); + } + } } diff --git a/src/software/resampling/delay.rs b/src/software/resampling/delay.rs index 2f50fd8..2e27bb3 100644 --- a/src/software/resampling/delay.rs +++ b/src/software/resampling/delay.rs @@ -1,24 +1,23 @@ -use libc::int64_t; -use ffi::*; use super::Context; +use ffi::*; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct Delay { - pub seconds: i64, - pub milliseconds: i64, - pub input: i64, - pub output: i64, + pub seconds: i64, + pub milliseconds: i64, + pub input: i64, + pub output: i64, } impl Delay { - pub fn from(context: &Context) -> Self { - unsafe { - Delay { - seconds: swr_get_delay(context.as_ptr() as *mut _, 1), - milliseconds: swr_get_delay(context.as_ptr() as *mut _, 1000), - input: swr_get_delay(context.as_ptr() as *mut _, context.input().rate as int64_t), - output: swr_get_delay(context.as_ptr() as *mut _, context.output().rate as int64_t), - } - } - } + pub fn from(context: &Context) -> Self { + unsafe { + Delay { + seconds: swr_get_delay(context.as_ptr() as *mut _, 1), + milliseconds: swr_get_delay(context.as_ptr() as *mut _, 1000), + input: swr_get_delay(context.as_ptr() as *mut _, i64::from(context.input().rate)), + output: swr_get_delay(context.as_ptr() as *mut _, i64::from(context.output().rate)), + } + } + } } diff --git a/src/software/resampling/dither.rs b/src/software/resampling/dither.rs index 46fffd7..728d34a 100644 --- a/src/software/resampling/dither.rs +++ b/src/software/resampling/dither.rs @@ -1,58 +1,58 @@ -use ffi::*; use ffi::SwrDitherType::*; +use ffi::*; #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Dither { - None, - Rectangular, - Triangular, - TriangularHighPass, + None, + Rectangular, + Triangular, + TriangularHighPass, - NoiseShapingLipshitz, - NoiseShapingFWeighted, - NoiseShapingModifiedEWeighted, - NoiseShapingImprovedEWeighted, - NoiseShapingShibata, - NoiseShapingLowShibata, - NoiseShapingHighShibata, + NoiseShapingLipshitz, + NoiseShapingFWeighted, + NoiseShapingModifiedEWeighted, + NoiseShapingImprovedEWeighted, + NoiseShapingShibata, + NoiseShapingLowShibata, + NoiseShapingHighShibata, } impl From for Dither { - fn from(value: SwrDitherType) -> Dither { - match value { - SWR_DITHER_NONE => Dither::None, - SWR_DITHER_RECTANGULAR => Dither::Rectangular, - SWR_DITHER_TRIANGULAR => Dither::Triangular, - SWR_DITHER_TRIANGULAR_HIGHPASS => Dither::TriangularHighPass, + fn from(value: SwrDitherType) -> Dither { + match value { + SWR_DITHER_NONE => Dither::None, + SWR_DITHER_RECTANGULAR => Dither::Rectangular, + SWR_DITHER_TRIANGULAR => Dither::Triangular, + SWR_DITHER_TRIANGULAR_HIGHPASS => Dither::TriangularHighPass, - SWR_DITHER_NS => Dither::None, - SWR_DITHER_NS_LIPSHITZ => Dither::NoiseShapingLipshitz, - SWR_DITHER_NS_F_WEIGHTED => Dither::NoiseShapingFWeighted, - SWR_DITHER_NS_MODIFIED_E_WEIGHTED => Dither::NoiseShapingModifiedEWeighted, - SWR_DITHER_NS_IMPROVED_E_WEIGHTED => Dither::NoiseShapingImprovedEWeighted, - SWR_DITHER_NS_SHIBATA => Dither::NoiseShapingShibata, - SWR_DITHER_NS_LOW_SHIBATA => Dither::NoiseShapingLowShibata, - SWR_DITHER_NS_HIGH_SHIBATA => Dither::NoiseShapingHighShibata, - SWR_DITHER_NB => Dither::None, - } - } + SWR_DITHER_NS => Dither::None, + SWR_DITHER_NS_LIPSHITZ => Dither::NoiseShapingLipshitz, + SWR_DITHER_NS_F_WEIGHTED => Dither::NoiseShapingFWeighted, + SWR_DITHER_NS_MODIFIED_E_WEIGHTED => Dither::NoiseShapingModifiedEWeighted, + SWR_DITHER_NS_IMPROVED_E_WEIGHTED => Dither::NoiseShapingImprovedEWeighted, + SWR_DITHER_NS_SHIBATA => Dither::NoiseShapingShibata, + SWR_DITHER_NS_LOW_SHIBATA => Dither::NoiseShapingLowShibata, + SWR_DITHER_NS_HIGH_SHIBATA => Dither::NoiseShapingHighShibata, + SWR_DITHER_NB => Dither::None, + } + } } impl Into for Dither { - fn into(self) -> SwrDitherType { - match self { - Dither::None => SWR_DITHER_NONE, - Dither::Rectangular => SWR_DITHER_RECTANGULAR, - Dither::Triangular => SWR_DITHER_TRIANGULAR, - Dither::TriangularHighPass => SWR_DITHER_TRIANGULAR_HIGHPASS, + fn into(self) -> SwrDitherType { + match self { + Dither::None => SWR_DITHER_NONE, + Dither::Rectangular => SWR_DITHER_RECTANGULAR, + Dither::Triangular => SWR_DITHER_TRIANGULAR, + Dither::TriangularHighPass => SWR_DITHER_TRIANGULAR_HIGHPASS, - Dither::NoiseShapingLipshitz => SWR_DITHER_NS_LIPSHITZ, - Dither::NoiseShapingFWeighted => SWR_DITHER_NS_F_WEIGHTED, - Dither::NoiseShapingModifiedEWeighted => SWR_DITHER_NS_MODIFIED_E_WEIGHTED, - Dither::NoiseShapingImprovedEWeighted => SWR_DITHER_NS_IMPROVED_E_WEIGHTED, - Dither::NoiseShapingShibata => SWR_DITHER_NS_SHIBATA, - Dither::NoiseShapingLowShibata => SWR_DITHER_NS_LOW_SHIBATA, - Dither::NoiseShapingHighShibata => SWR_DITHER_NS_HIGH_SHIBATA, - } - } + Dither::NoiseShapingLipshitz => SWR_DITHER_NS_LIPSHITZ, + Dither::NoiseShapingFWeighted => SWR_DITHER_NS_F_WEIGHTED, + Dither::NoiseShapingModifiedEWeighted => SWR_DITHER_NS_MODIFIED_E_WEIGHTED, + Dither::NoiseShapingImprovedEWeighted => SWR_DITHER_NS_IMPROVED_E_WEIGHTED, + Dither::NoiseShapingShibata => SWR_DITHER_NS_SHIBATA, + Dither::NoiseShapingLowShibata => SWR_DITHER_NS_LOW_SHIBATA, + Dither::NoiseShapingHighShibata => SWR_DITHER_NS_HIGH_SHIBATA, + } + } } diff --git a/src/software/resampling/engine.rs b/src/software/resampling/engine.rs index 30da835..65acc92 100644 --- a/src/software/resampling/engine.rs +++ b/src/software/resampling/engine.rs @@ -3,25 +3,25 @@ use sys::SwrEngine::*; #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Engine { - Software, - SoundExchange, + Software, + SoundExchange, } impl From for Engine { - fn from(value: SwrEngine) -> Engine { - match value { - SWR_ENGINE_SWR => Engine::Software, - SWR_ENGINE_SOXR => Engine::SoundExchange, - SWR_ENGINE_NB => Engine::Software, - } - } + fn from(value: SwrEngine) -> Engine { + match value { + SWR_ENGINE_SWR => Engine::Software, + SWR_ENGINE_SOXR => Engine::SoundExchange, + SWR_ENGINE_NB => Engine::Software, + } + } } impl Into for Engine { - fn into(self) -> SwrEngine { - match self { - Engine::Software => SWR_ENGINE_SWR, - Engine::SoundExchange => SWR_ENGINE_SOXR, - } - } + fn into(self) -> SwrEngine { + match self { + Engine::Software => SWR_ENGINE_SWR, + Engine::SoundExchange => SWR_ENGINE_SOXR, + } + } } diff --git a/src/software/resampling/extensions.rs b/src/software/resampling/extensions.rs index eefb1c9..69b1aec 100644 --- a/src/software/resampling/extensions.rs +++ b/src/software/resampling/extensions.rs @@ -1,19 +1,41 @@ -use util::format; -use ::{decoder, Error, ChannelLayout, frame}; use super::Context; +use util::format; +use {decoder, frame, ChannelLayout, Error}; impl frame::Audio { - #[inline] - pub fn resampler(&self, format: format::Sample, channel_layout: ChannelLayout, rate: u32) -> Result { - Context::get(self.format(), self.channel_layout(), self.rate(), - format, channel_layout, rate) - } + #[inline] + pub fn resampler( + &self, + format: format::Sample, + channel_layout: ChannelLayout, + rate: u32, + ) -> Result { + Context::get( + self.format(), + self.channel_layout(), + self.rate(), + format, + channel_layout, + rate, + ) + } } impl decoder::Audio { - #[inline] - pub fn resampler(&self, format: format::Sample, channel_layout: ChannelLayout, rate: u32) -> Result { - Context::get(self.format(), self.channel_layout(), self.rate(), - format, channel_layout, rate) - } + #[inline] + pub fn resampler( + &self, + format: format::Sample, + channel_layout: ChannelLayout, + rate: u32, + ) -> Result { + Context::get( + self.format(), + self.channel_layout(), + self.rate(), + format, + channel_layout, + rate, + ) + } } diff --git a/src/software/resampling/filter.rs b/src/software/resampling/filter.rs index 7e12295..0b2b268 100644 --- a/src/software/resampling/filter.rs +++ b/src/software/resampling/filter.rs @@ -1,29 +1,29 @@ -use ffi::*; use ffi::SwrFilterType::*; +use ffi::*; #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Filter { - Cubic, - BlackmanNuttall, - Kaiser, + Cubic, + BlackmanNuttall, + Kaiser, } impl From for Filter { - fn from(value: SwrFilterType) -> Filter { - match value { - SWR_FILTER_TYPE_CUBIC => Filter::Cubic, - SWR_FILTER_TYPE_BLACKMAN_NUTTALL => Filter::BlackmanNuttall, - SWR_FILTER_TYPE_KAISER => Filter::Kaiser, - } - } + fn from(value: SwrFilterType) -> Filter { + match value { + SWR_FILTER_TYPE_CUBIC => Filter::Cubic, + SWR_FILTER_TYPE_BLACKMAN_NUTTALL => Filter::BlackmanNuttall, + SWR_FILTER_TYPE_KAISER => Filter::Kaiser, + } + } } impl Into for Filter { - fn into(self) -> SwrFilterType { - match self { - Filter::Cubic => SWR_FILTER_TYPE_CUBIC, - Filter::BlackmanNuttall => SWR_FILTER_TYPE_BLACKMAN_NUTTALL, - Filter::Kaiser => SWR_FILTER_TYPE_KAISER, - } - } + fn into(self) -> SwrFilterType { + match self { + Filter::Cubic => SWR_FILTER_TYPE_CUBIC, + Filter::BlackmanNuttall => SWR_FILTER_TYPE_BLACKMAN_NUTTALL, + Filter::Kaiser => SWR_FILTER_TYPE_KAISER, + } + } } diff --git a/src/software/resampling/flag.rs b/src/software/resampling/flag.rs index 29a7a19..7f8f623 100644 --- a/src/software/resampling/flag.rs +++ b/src/software/resampling/flag.rs @@ -1,8 +1,8 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Flags: c_int { - const FORCE = SWR_FLAG_RESAMPLE; - } + pub struct Flags: c_int { + const FORCE = SWR_FLAG_RESAMPLE; + } } diff --git a/src/software/resampling/mod.rs b/src/software/resampling/mod.rs index cd02930..f536e4d 100644 --- a/src/software/resampling/mod.rs +++ b/src/software/resampling/mod.rs @@ -24,19 +24,13 @@ use std::str::from_utf8_unchecked; use ffi::*; pub fn version() -> u32 { - unsafe { - swresample_version() - } + unsafe { swresample_version() } } pub fn configuration() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(swresample_configuration()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(swresample_configuration()).to_bytes()) } } pub fn license() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(swresample_license()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(swresample_license()).to_bytes()) } } diff --git a/src/software/scaling/color_space.rs b/src/software/scaling/color_space.rs index 3707f92..bd34a10 100644 --- a/src/software/scaling/color_space.rs +++ b/src/software/scaling/color_space.rs @@ -1,41 +1,41 @@ -use libc::c_int; use ffi::*; +use libc::c_int; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum ColorSpace { - Default, + Default, - ITU709, - FCC, - ITU601, - ITU624, - SMPTE170M, - SMPTE240M, + ITU709, + FCC, + ITU601, + ITU624, + SMPTE170M, + SMPTE240M, } impl From for ColorSpace { - fn from(value: c_int) -> ColorSpace { - match value { - SWS_CS_ITU709 => ColorSpace::ITU709, - SWS_CS_FCC => ColorSpace::FCC, - SWS_CS_DEFAULT => ColorSpace::Default, - SWS_CS_SMPTE240M => ColorSpace::SMPTE240M, + fn from(value: c_int) -> ColorSpace { + match value { + SWS_CS_ITU709 => ColorSpace::ITU709, + SWS_CS_FCC => ColorSpace::FCC, + SWS_CS_DEFAULT => ColorSpace::Default, + SWS_CS_SMPTE240M => ColorSpace::SMPTE240M, - _ => ColorSpace::Default - } - } + _ => ColorSpace::Default, + } + } } impl Into for ColorSpace { - fn into(self) -> c_int { - match self { - ColorSpace::Default => SWS_CS_DEFAULT, - ColorSpace::ITU709 => SWS_CS_ITU709, - ColorSpace::FCC => SWS_CS_FCC, - ColorSpace::ITU601 => SWS_CS_ITU601, - ColorSpace::ITU624 => SWS_CS_ITU624, - ColorSpace::SMPTE170M => SWS_CS_SMPTE170M, - ColorSpace::SMPTE240M => SWS_CS_SMPTE240M - } - } + fn into(self) -> c_int { + match self { + ColorSpace::Default => SWS_CS_DEFAULT, + ColorSpace::ITU709 => SWS_CS_ITU709, + ColorSpace::FCC => SWS_CS_FCC, + ColorSpace::ITU601 => SWS_CS_ITU601, + ColorSpace::ITU624 => SWS_CS_ITU624, + ColorSpace::SMPTE170M => SWS_CS_SMPTE170M, + ColorSpace::SMPTE240M => SWS_CS_SMPTE240M, + } + } } diff --git a/src/software/scaling/context.rs b/src/software/scaling/context.rs index e4da466..e0aa4d7 100644 --- a/src/software/scaling/context.rs +++ b/src/software/scaling/context.rs @@ -1,135 +1,171 @@ use std::ptr; -use libc::{c_int}; -use ffi::*; -use ::{Error, frame}; -use ::util::format; use super::Flags; +use ffi::*; +use libc::c_int; +use util::format; +use {frame, Error}; #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub struct Definition { - pub format: format::Pixel, - pub width: u32, - pub height: u32, + pub format: format::Pixel, + pub width: u32, + pub height: u32, } pub struct Context { - ptr: *mut SwsContext, + ptr: *mut SwsContext, - input: Definition, - output: Definition, + input: Definition, + output: Definition, } impl Context { - #[inline(always)] - pub unsafe fn as_ptr(&self) -> *const SwsContext { - self.ptr as *const _ - } + #[inline(always)] + pub unsafe fn as_ptr(&self) -> *const SwsContext { + self.ptr as *const _ + } - #[inline(always)] - pub unsafe fn as_mut_ptr(&mut self) -> *mut SwsContext { - self.ptr - } + #[inline(always)] + pub unsafe fn as_mut_ptr(&mut self) -> *mut SwsContext { + self.ptr + } } impl Context { - pub fn get(src_format: format::Pixel, src_w: u32, src_h: u32, - dst_format: format::Pixel, dst_w: u32, dst_h: u32, - flags: Flags) -> Result { - unsafe { - let ptr = sws_getContext( - src_w as c_int, src_h as c_int, src_format.into(), - dst_w as c_int, dst_h as c_int, dst_format.into(), - flags.bits(), - ptr::null_mut(), ptr::null_mut(), ptr::null_mut()); + pub fn get( + src_format: format::Pixel, + src_w: u32, + src_h: u32, + dst_format: format::Pixel, + dst_w: u32, + dst_h: u32, + flags: Flags, + ) -> Result { + unsafe { + let ptr = sws_getContext( + src_w as c_int, + src_h as c_int, + src_format.into(), + dst_w as c_int, + dst_h as c_int, + dst_format.into(), + flags.bits(), + ptr::null_mut(), + ptr::null_mut(), + ptr::null_mut(), + ); - if ptr != ptr::null_mut() { - Ok(Context { - ptr: ptr, + if ptr.is_null() { + Ok(Context { + ptr: ptr, - input: Definition { - format: src_format, - width: src_w, - height: src_h, - }, + input: Definition { + format: src_format, + width: src_w, + height: src_h, + }, - output: Definition { - format: dst_format, - width: dst_w, - height: dst_h, - }, - }) - } - else { - Err(Error::InvalidData) - } - } - } + output: Definition { + format: dst_format, + width: dst_w, + height: dst_h, + }, + }) + } else { + Err(Error::InvalidData) + } + } + } - pub fn cached(&mut self, - src_format: format::Pixel, src_w: u32, src_h: u32, - dst_format: format::Pixel, dst_w: u32, dst_h: u32, - flags: Flags) { - self.input = Definition { - format: src_format, - width: src_w, - height: src_h, - }; + pub fn cached( + &mut self, + src_format: format::Pixel, + src_w: u32, + src_h: u32, + dst_format: format::Pixel, + dst_w: u32, + dst_h: u32, + flags: Flags, + ) { + self.input = Definition { + format: src_format, + width: src_w, + height: src_h, + }; - self.output = Definition { - format: dst_format, - width: dst_w, - height: dst_h, - }; + self.output = Definition { + format: dst_format, + width: dst_w, + height: dst_h, + }; - unsafe { - self.ptr = sws_getCachedContext(self.as_mut_ptr(), - src_w as c_int, src_h as c_int, src_format.into(), - dst_w as c_int, dst_h as c_int, dst_format.into(), - flags.bits(), ptr::null_mut(), ptr::null_mut(), ptr::null()); - } - } + unsafe { + self.ptr = sws_getCachedContext( + self.as_mut_ptr(), + src_w as c_int, + src_h as c_int, + src_format.into(), + dst_w as c_int, + dst_h as c_int, + dst_format.into(), + flags.bits(), + ptr::null_mut(), + ptr::null_mut(), + ptr::null(), + ); + } + } - #[inline] - pub fn input(&self) -> &Definition { - &self.input - } + #[inline] + pub fn input(&self) -> &Definition { + &self.input + } - #[inline] - pub fn output(&self) -> &Definition { - &self.output - } + #[inline] + pub fn output(&self) -> &Definition { + &self.output + } - pub fn run(&mut self, input: &frame::Video, output: &mut frame::Video) -> Result<(), Error> { - if input.format() != self.input.format || input.width() != self.input.width || input.height() != self.input.height { - return Err(Error::InputChanged); - } + pub fn run(&mut self, input: &frame::Video, output: &mut frame::Video) -> Result<(), Error> { + if input.format() != self.input.format || input.width() != self.input.width + || input.height() != self.input.height + { + return Err(Error::InputChanged); + } - unsafe { - if output.is_empty() { - output.alloc(self.output.format, self.output.width, self.output.height); - } - } + unsafe { + if output.is_empty() { + output.alloc(self.output.format, self.output.width, self.output.height); + } + } - if output.format() != self.output.format || output.width() != self.output.width || output.height() != self.output.height { - return Err(Error::OutputChanged); - } + if output.format() != self.output.format || output.width() != self.output.width + || output.height() != self.output.height + { + return Err(Error::OutputChanged); + } - unsafe { - sws_scale(self.as_mut_ptr(), - (*input.as_ptr()).data.as_ptr() as *const *const _, (*input.as_ptr()).linesize.as_ptr() as *const _, - 0, self.output.height as c_int, - (*output.as_mut_ptr()).data.as_ptr() as *const *const _, (*output.as_mut_ptr()).linesize.as_ptr() as *mut _); - } + unsafe { + sws_scale( + self.as_mut_ptr(), + (*input.as_ptr()).data.as_ptr() as *const *const _, + (*input.as_ptr()).linesize.as_ptr() as *const _, + 0, + self.output.height as c_int, + (*output.as_mut_ptr()).data.as_ptr() as *const *const _, + (*output.as_mut_ptr()).linesize.as_ptr() as *mut _, + ); + } - Ok(()) - } + Ok(()) + } } impl Drop for Context { - fn drop(&mut self) { - unsafe { - sws_freeContext(self.as_mut_ptr()); - } - } + fn drop(&mut self) { + unsafe { + sws_freeContext(self.as_mut_ptr()); + } + } } diff --git a/src/software/scaling/extensions.rs b/src/software/scaling/extensions.rs index 0ddc671..2079713 100644 --- a/src/software/scaling/extensions.rs +++ b/src/software/scaling/extensions.rs @@ -1,52 +1,87 @@ +use super::{flag, Context, Flags}; use util::format; -use ::{Picture, decoder, Error, frame}; -use super::{Context, Flags, flag}; +use {decoder, frame, Error, Picture}; impl<'a> Picture<'a> { - #[inline] - pub fn scaler(&self, width: u32, height: u32, flags: Flags) -> Result { - Context::get(self.format(), self.width(), self.height(), - self.format(), width, height, - flags) - } + #[inline] + pub fn scaler(&self, width: u32, height: u32, flags: Flags) -> Result { + Context::get( + self.format(), + self.width(), + self.height(), + self.format(), + width, + height, + flags, + ) + } - #[inline] - pub fn converter(&self, format: format::Pixel) -> Result { - Context::get(self.format(), self.width(), self.height(), - format, self.width(), self.height(), - flag::FAST_BILINEAR) - } + #[inline] + pub fn converter(&self, format: format::Pixel) -> Result { + Context::get( + self.format(), + self.width(), + self.height(), + format, + self.width(), + self.height(), + flag::FAST_BILINEAR, + ) + } } impl frame::Video { - #[inline] - pub fn scaler(&self, width: u32, height: u32, flags: Flags) -> Result { - Context::get(self.format(), self.width(), self.height(), - self.format(), width, height, - flags) - } + #[inline] + pub fn scaler(&self, width: u32, height: u32, flags: Flags) -> Result { + Context::get( + self.format(), + self.width(), + self.height(), + self.format(), + width, + height, + flags, + ) + } - #[inline] - pub fn converter(&self, format: format::Pixel) -> Result { - Context::get(self.format(), self.width(), self.height(), - format, self.width(), self.height(), - flag::FAST_BILINEAR) - } + #[inline] + pub fn converter(&self, format: format::Pixel) -> Result { + Context::get( + self.format(), + self.width(), + self.height(), + format, + self.width(), + self.height(), + flag::FAST_BILINEAR, + ) + } } - impl decoder::Video { - #[inline] - pub fn scaler(&self, width: u32, height: u32, flags: Flags) -> Result { - Context::get(self.format(), self.width(), self.height(), - self.format(), width, height, - flags) - } + #[inline] + pub fn scaler(&self, width: u32, height: u32, flags: Flags) -> Result { + Context::get( + self.format(), + self.width(), + self.height(), + self.format(), + width, + height, + flags, + ) + } - #[inline] - pub fn converter(&self, format: format::Pixel) -> Result { - Context::get(self.format(), self.width(), self.height(), - format, self.width(), self.height(), - flag::FAST_BILINEAR) - } + #[inline] + pub fn converter(&self, format: format::Pixel) -> Result { + Context::get( + self.format(), + self.width(), + self.height(), + format, + self.width(), + self.height(), + flag::FAST_BILINEAR, + ) + } } diff --git a/src/software/scaling/filter.rs b/src/software/scaling/filter.rs index 2be3a73..847a71b 100644 --- a/src/software/scaling/filter.rs +++ b/src/software/scaling/filter.rs @@ -1,90 +1,91 @@ -use ffi::*; use super::Vector; +use ffi::*; pub struct Filter { - ptr: *mut SwsFilter, + ptr: *mut SwsFilter, } impl Filter { - pub unsafe fn as_ptr(&self) -> *const SwsFilter { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const SwsFilter { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut SwsFilter { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut SwsFilter { + self.ptr + } } impl Filter { - pub fn get(luma_g_blur: f32, chroma_g_blur: f32, - luma_sharpen: f32, chroma_sharpen: f32, - chroma_h_shift: f32, chroma_v_shift: f32) -> Self { - unsafe { - Filter { - ptr: sws_getDefaultFilter(luma_g_blur, chroma_g_blur, - luma_sharpen, chroma_sharpen, - chroma_h_shift, chroma_v_shift, 0) - } - } - } + pub fn get( + luma_g_blur: f32, + chroma_g_blur: f32, + luma_sharpen: f32, + chroma_sharpen: f32, + chroma_h_shift: f32, + chroma_v_shift: f32, + ) -> Self { + unsafe { + Filter { + ptr: sws_getDefaultFilter( + luma_g_blur, + chroma_g_blur, + luma_sharpen, + chroma_sharpen, + chroma_h_shift, + chroma_v_shift, + 0, + ), + } + } + } - pub fn new() -> Self { - Self::get(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) - } + pub fn new() -> Self { + Self::get(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) + } - pub fn luma_horizontal(&self) -> Vector { - unsafe { - Vector::wrap((*self.as_ptr()).lumH) - } - } - - pub fn luma_horizontal_mut(&mut self) -> Vector { - unsafe { - Vector::wrap((*self.as_mut_ptr()).lumH) - } - } + pub fn luma_horizontal(&self) -> Vector { + unsafe { Vector::wrap((*self.as_ptr()).lumH) } + } - pub fn luma_vertical(&self) -> Vector { - unsafe { - Vector::wrap((*self.as_ptr()).lumV) - } - } - - pub fn luma_vertical_mut(&mut self) -> Vector { - unsafe { - Vector::wrap((*self.as_mut_ptr()).lumV) - } - } + pub fn luma_horizontal_mut(&mut self) -> Vector { + unsafe { Vector::wrap((*self.as_mut_ptr()).lumH) } + } - pub fn chroma_horizontal(&self) -> Vector { - unsafe { - Vector::wrap((*self.as_ptr()).lumV) - } - } - - pub fn chroma_horizontal_mut(&mut self) -> Vector { - unsafe { - Vector::wrap((*self.as_mut_ptr()).lumV) - } - } + pub fn luma_vertical(&self) -> Vector { + unsafe { Vector::wrap((*self.as_ptr()).lumV) } + } - pub fn chroma_vertical(&self) -> Vector { - unsafe { - Vector::wrap((*self.as_ptr()).lumV) - } - } - - pub fn chroma_vertical_mut(&mut self) -> Vector { - unsafe { - Vector::wrap((*self.as_mut_ptr()).lumV) - } - } + pub fn luma_vertical_mut(&mut self) -> Vector { + unsafe { Vector::wrap((*self.as_mut_ptr()).lumV) } + } + + pub fn chroma_horizontal(&self) -> Vector { + unsafe { Vector::wrap((*self.as_ptr()).lumV) } + } + + pub fn chroma_horizontal_mut(&mut self) -> Vector { + unsafe { Vector::wrap((*self.as_mut_ptr()).lumV) } + } + + pub fn chroma_vertical(&self) -> Vector { + unsafe { Vector::wrap((*self.as_ptr()).lumV) } + } + + pub fn chroma_vertical_mut(&mut self) -> Vector { + unsafe { Vector::wrap((*self.as_mut_ptr()).lumV) } + } +} + +impl Default for Filter { + fn default() -> Self { + Self::new() + } } impl Drop for Filter { - fn drop(&mut self) { - unsafe { - sws_freeFilter(self.as_mut_ptr()); - } - } + fn drop(&mut self) { + unsafe { + sws_freeFilter(self.as_mut_ptr()); + } + } } diff --git a/src/software/scaling/flag.rs b/src/software/scaling/flag.rs index 08d18c9..f71958f 100644 --- a/src/software/scaling/flag.rs +++ b/src/software/scaling/flag.rs @@ -1,28 +1,28 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Flags: c_int { - const FAST_BILINEAR = SWS_FAST_BILINEAR; - const BILINEAR = SWS_BILINEAR; - const BICUBIC = SWS_BICUBIC; - const X = SWS_X; - const POINT = SWS_POINT; - const AREA = SWS_AREA; - const BICUBLIN = SWS_BICUBLIN; - const GAUSS = SWS_GAUSS; - const SINC = SWS_SINC; - const LANCZOS = SWS_LANCZOS; - const SPLINE = SWS_SPLINE; - const SRC_V_CHR_DROP_MASK = SWS_SRC_V_CHR_DROP_MASK; - const SRC_V_CHR_DROP_SHIFT = SWS_SRC_V_CHR_DROP_SHIFT; - const PARAM_DEFAULT = SWS_PARAM_DEFAULT; - const PRINT_INFO = SWS_PRINT_INFO; - const FULL_CHR_H_INT = SWS_FULL_CHR_H_INT; - const FULL_CHR_H_INP = SWS_FULL_CHR_H_INP; - const DIRECT_BGR = SWS_DIRECT_BGR; - const ACCURATE_RND = SWS_ACCURATE_RND; - const BITEXACT = SWS_BITEXACT; - const ERROR_DIFFUSION = SWS_ERROR_DIFFUSION; - } + pub struct Flags: c_int { + const FAST_BILINEAR = SWS_FAST_BILINEAR; + const BILINEAR = SWS_BILINEAR; + const BICUBIC = SWS_BICUBIC; + const X = SWS_X; + const POINT = SWS_POINT; + const AREA = SWS_AREA; + const BICUBLIN = SWS_BICUBLIN; + const GAUSS = SWS_GAUSS; + const SINC = SWS_SINC; + const LANCZOS = SWS_LANCZOS; + const SPLINE = SWS_SPLINE; + const SRC_V_CHR_DROP_MASK = SWS_SRC_V_CHR_DROP_MASK; + const SRC_V_CHR_DROP_SHIFT = SWS_SRC_V_CHR_DROP_SHIFT; + const PARAM_DEFAULT = SWS_PARAM_DEFAULT; + const PRINT_INFO = SWS_PRINT_INFO; + const FULL_CHR_H_INT = SWS_FULL_CHR_H_INT; + const FULL_CHR_H_INP = SWS_FULL_CHR_H_INP; + const DIRECT_BGR = SWS_DIRECT_BGR; + const ACCURATE_RND = SWS_ACCURATE_RND; + const BITEXACT = SWS_BITEXACT; + const ERROR_DIFFUSION = SWS_ERROR_DIFFUSION; + } } diff --git a/src/software/scaling/mod.rs b/src/software/scaling/mod.rs index ef3e359..bab8d53 100644 --- a/src/software/scaling/mod.rs +++ b/src/software/scaling/mod.rs @@ -23,19 +23,13 @@ use std::str::from_utf8_unchecked; use ffi::*; pub fn version() -> u32 { - unsafe { - swscale_version() - } + unsafe { swscale_version() } } pub fn configuration() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(swscale_configuration()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(swscale_configuration()).to_bytes()) } } pub fn license() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(swscale_license()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(swscale_license()).to_bytes()) } } diff --git a/src/software/scaling/support.rs b/src/software/scaling/support.rs index bf7c254..a76fe72 100644 --- a/src/software/scaling/support.rs +++ b/src/software/scaling/support.rs @@ -1,20 +1,14 @@ use ffi::*; -use ::util::format; +use util::format; pub fn input(format: format::Pixel) -> bool { - unsafe { - sws_isSupportedInput(format.into()) != 0 - } + unsafe { sws_isSupportedInput(format.into()) != 0 } } pub fn output(format: format::Pixel) -> bool { - unsafe { - sws_isSupportedOutput(format.into()) != 0 - } + unsafe { sws_isSupportedOutput(format.into()) != 0 } } pub fn endianness_conversion(format: format::Pixel) -> bool { - unsafe { - sws_isSupportedEndiannessConversion(format.into()) != 0 - } + unsafe { sws_isSupportedEndiannessConversion(format.into()) != 0 } } diff --git a/src/software/scaling/vector.rs b/src/software/scaling/vector.rs index 474ed9a..b1e19ad 100644 --- a/src/software/scaling/vector.rs +++ b/src/software/scaling/vector.rs @@ -1,120 +1,140 @@ use std::marker::PhantomData; use std::slice; -use libc::{c_int, c_double}; use ffi::*; +use libc::{c_double, c_int}; pub struct Vector<'a> { - ptr: *mut SwsVector, + ptr: *mut SwsVector, - _own: bool, - _marker: PhantomData<&'a ()>, + _own: bool, + _marker: PhantomData<&'a ()>, } impl<'a> Vector<'a> { - pub unsafe fn wrap(ptr: *mut SwsVector) -> Self { - Vector { ptr: ptr, _own: false, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *mut SwsVector) -> Self { + Vector { + ptr: ptr, + _own: false, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const SwsVector { - self.ptr as *const _ - } + pub unsafe fn as_ptr(&self) -> *const SwsVector { + self.ptr as *const _ + } - pub unsafe fn as_mut_ptr(&mut self) -> *mut SwsVector { - self.ptr - } + pub unsafe fn as_mut_ptr(&mut self) -> *mut SwsVector { + self.ptr + } } impl<'a> Vector<'a> { - pub fn new(length: usize) -> Self { - unsafe { - Vector { ptr: sws_allocVec(length as c_int), _own: true, _marker: PhantomData } - } - } + pub fn new(length: usize) -> Self { + unsafe { + Vector { + ptr: sws_allocVec(length as c_int), + _own: true, + _marker: PhantomData, + } + } + } - pub fn gaussian(variance: f64, quality: f64) -> Self { - unsafe { - Vector { ptr: sws_getGaussianVec(variance as c_double, quality as c_double), _own: true, _marker: PhantomData } - } - } + pub fn gaussian(variance: f64, quality: f64) -> Self { + unsafe { + Vector { + ptr: sws_getGaussianVec(variance as c_double, quality as c_double), + _own: true, + _marker: PhantomData, + } + } + } - pub fn value(value: f64, length: usize) -> Self { - unsafe { - Vector { ptr: sws_getConstVec(value as c_double, length as c_int), _own: true, _marker: PhantomData } - } - } + pub fn value(value: f64, length: usize) -> Self { + unsafe { + Vector { + ptr: sws_getConstVec(value as c_double, length as c_int), + _own: true, + _marker: PhantomData, + } + } + } - pub fn identity() -> Self { - unsafe { - Vector { ptr: sws_getIdentityVec(), _own: true, _marker: PhantomData } - } - } + pub fn identity() -> Self { + unsafe { + Vector { + ptr: sws_getIdentityVec(), + _own: true, + _marker: PhantomData, + } + } + } - pub fn scale(&mut self, scalar: f64) { - unsafe { - sws_scaleVec(self.as_mut_ptr(), scalar as c_double); - } - } + pub fn scale(&mut self, scalar: f64) { + unsafe { + sws_scaleVec(self.as_mut_ptr(), scalar as c_double); + } + } - pub fn normalize(&mut self, height: f64) { - unsafe { - sws_normalizeVec(self.as_mut_ptr(), height as c_double); - } - } + pub fn normalize(&mut self, height: f64) { + unsafe { + sws_normalizeVec(self.as_mut_ptr(), height as c_double); + } + } - pub fn conv(&mut self, other: &Vector) { - unsafe { - sws_convVec(self.as_mut_ptr(), other.as_ptr() as *mut _); - } - } + pub fn conv(&mut self, other: &Vector) { + unsafe { + sws_convVec(self.as_mut_ptr(), other.as_ptr() as *mut _); + } + } - pub fn add(&mut self, other: &Vector) { - unsafe { - sws_addVec(self.as_mut_ptr(), other.as_ptr() as *mut _); - } - } + pub fn add(&mut self, other: &Vector) { + unsafe { + sws_addVec(self.as_mut_ptr(), other.as_ptr() as *mut _); + } + } - pub fn sub(&mut self, other: &Vector) { - unsafe { - sws_subVec(self.as_mut_ptr(), other.as_ptr() as *mut _); - } - } + pub fn sub(&mut self, other: &Vector) { + unsafe { + sws_subVec(self.as_mut_ptr(), other.as_ptr() as *mut _); + } + } - pub fn shift(&mut self, value: usize) { - unsafe { - sws_shiftVec(self.as_mut_ptr(), value as c_int); - } - } + pub fn shift(&mut self, value: usize) { + unsafe { + sws_shiftVec(self.as_mut_ptr(), value as c_int); + } + } - pub fn coefficients(&self) -> &[f64] { - unsafe { - slice::from_raw_parts((*self.as_ptr()).coeff, - (*self.as_ptr()).length as usize) - } - } + pub fn coefficients(&self) -> &[f64] { + unsafe { slice::from_raw_parts((*self.as_ptr()).coeff, (*self.as_ptr()).length as usize) } + } - pub fn coefficients_mut(&self) -> &[f64] { - unsafe { - slice::from_raw_parts_mut((*self.as_ptr()).coeff, - (*self.as_ptr()).length as usize) - } - } + pub fn coefficients_mut(&self) -> &[f64] { + unsafe { + slice::from_raw_parts_mut((*self.as_ptr()).coeff, (*self.as_ptr()).length as usize) + } + } } impl<'a> Clone for Vector<'a> { - fn clone(&self) -> Self { - unsafe { - Vector { ptr: sws_cloneVec(self.as_ptr() as *mut _), _own: true, _marker: PhantomData } - } - } + fn clone(&self) -> Self { + unsafe { + Vector { + ptr: sws_cloneVec(self.as_ptr() as *mut _), + _own: true, + _marker: PhantomData, + } + } + } } impl<'a> Drop for Vector<'a> { - fn drop(&mut self) { - unsafe { - if self._own { - sws_freeVec(self.as_mut_ptr()); - } - } - } + fn drop(&mut self) { + unsafe { + if self._own { + sws_freeVec(self.as_mut_ptr()); + } + } + } } diff --git a/src/util/channel_layout.rs b/src/util/channel_layout.rs index 77d7d9d..402d0b7 100644 --- a/src/util/channel_layout.rs +++ b/src/util/channel_layout.rs @@ -1,77 +1,75 @@ -use libc::c_ulonglong; use ffi::*; +use libc::c_ulonglong; bitflags! { - pub struct ChannelLayout: c_ulonglong { - const FRONT_LEFT = AV_CH_FRONT_LEFT; - const FRONT_RIGHT = AV_CH_FRONT_RIGHT; - const FRONT_CENTER = AV_CH_FRONT_CENTER; - const LOW_FREQUENCY = AV_CH_LOW_FREQUENCY; - const BACK_LEFT = AV_CH_BACK_LEFT; - const BACK_RIGHT = AV_CH_BACK_RIGHT; - const FRONT_LEFT_OF_CENTER = AV_CH_FRONT_LEFT_OF_CENTER; - const FRONT_RIGHT_OF_CENTER = AV_CH_FRONT_RIGHT_OF_CENTER; - const BACK_CENTER = AV_CH_BACK_CENTER; - const SIDE_LEFT = AV_CH_SIDE_LEFT; - const SIDE_RIGHT = AV_CH_SIDE_RIGHT; - const TOP_CENTER = AV_CH_TOP_CENTER; - const TOP_FRONT_LEFT = AV_CH_TOP_FRONT_LEFT; - const TOP_FRONT_CENTER = AV_CH_TOP_FRONT_CENTER; - const TOP_FRONT_RIGHT = AV_CH_TOP_FRONT_RIGHT; - const TOP_BACK_LEFT = AV_CH_TOP_BACK_LEFT; - const TOP_BACK_CENTER = AV_CH_TOP_BACK_CENTER; - const TOP_BACK_RIGHT = AV_CH_TOP_BACK_RIGHT; - const STEREO_LEFT = AV_CH_STEREO_LEFT; - const STEREO_RIGHT = AV_CH_STEREO_RIGHT; - const WIDE_LEFT = AV_CH_WIDE_LEFT; - const WIDE_RIGHT = AV_CH_WIDE_RIGHT; - const SURROUND_DIRECT_LEFT = AV_CH_SURROUND_DIRECT_LEFT; - const SURROUND_DIRECT_RIGHT = AV_CH_SURROUND_DIRECT_RIGHT; - const LOW_FREQUENCY_2 = AV_CH_LOW_FREQUENCY_2; - const NATIVE = AV_CH_LAYOUT_NATIVE; + pub struct ChannelLayout: c_ulonglong { + const FRONT_LEFT = AV_CH_FRONT_LEFT; + const FRONT_RIGHT = AV_CH_FRONT_RIGHT; + const FRONT_CENTER = AV_CH_FRONT_CENTER; + const LOW_FREQUENCY = AV_CH_LOW_FREQUENCY; + const BACK_LEFT = AV_CH_BACK_LEFT; + const BACK_RIGHT = AV_CH_BACK_RIGHT; + const FRONT_LEFT_OF_CENTER = AV_CH_FRONT_LEFT_OF_CENTER; + const FRONT_RIGHT_OF_CENTER = AV_CH_FRONT_RIGHT_OF_CENTER; + const BACK_CENTER = AV_CH_BACK_CENTER; + const SIDE_LEFT = AV_CH_SIDE_LEFT; + const SIDE_RIGHT = AV_CH_SIDE_RIGHT; + const TOP_CENTER = AV_CH_TOP_CENTER; + const TOP_FRONT_LEFT = AV_CH_TOP_FRONT_LEFT; + const TOP_FRONT_CENTER = AV_CH_TOP_FRONT_CENTER; + const TOP_FRONT_RIGHT = AV_CH_TOP_FRONT_RIGHT; + const TOP_BACK_LEFT = AV_CH_TOP_BACK_LEFT; + const TOP_BACK_CENTER = AV_CH_TOP_BACK_CENTER; + const TOP_BACK_RIGHT = AV_CH_TOP_BACK_RIGHT; + const STEREO_LEFT = AV_CH_STEREO_LEFT; + const STEREO_RIGHT = AV_CH_STEREO_RIGHT; + const WIDE_LEFT = AV_CH_WIDE_LEFT; + const WIDE_RIGHT = AV_CH_WIDE_RIGHT; + const SURROUND_DIRECT_LEFT = AV_CH_SURROUND_DIRECT_LEFT; + const SURROUND_DIRECT_RIGHT = AV_CH_SURROUND_DIRECT_RIGHT; + const LOW_FREQUENCY_2 = AV_CH_LOW_FREQUENCY_2; + const NATIVE = AV_CH_LAYOUT_NATIVE; - const MONO = AV_CH_LAYOUT_MONO; - const STEREO = AV_CH_LAYOUT_STEREO; - const _2POINT1 = AV_CH_LAYOUT_2POINT1; - const _2_1 = AV_CH_LAYOUT_2_1; - const SURROUND = AV_CH_LAYOUT_SURROUND; - const _3POINT1 = AV_CH_LAYOUT_3POINT1; - const _4POINT0 = AV_CH_LAYOUT_4POINT0; - const _4POINT1 = AV_CH_LAYOUT_4POINT1; - const _2_2 = AV_CH_LAYOUT_2_2; - const QUAD = AV_CH_LAYOUT_QUAD; - const _5POINT0 = AV_CH_LAYOUT_5POINT0; - const _5POINT1 = AV_CH_LAYOUT_5POINT1; - const _5POINT0_BACK = AV_CH_LAYOUT_5POINT0_BACK; - const _5POINT1_BACK = AV_CH_LAYOUT_5POINT1_BACK; - const _6POINT0 = AV_CH_LAYOUT_6POINT0; - const _6POINT0_FRONT = AV_CH_LAYOUT_6POINT0_FRONT; - const HEXAGONAL = AV_CH_LAYOUT_HEXAGONAL; - const _6POINT1 = AV_CH_LAYOUT_6POINT1; - const _6POINT1_BACK = AV_CH_LAYOUT_6POINT1_BACK; - const _6POINT1_FRONT = AV_CH_LAYOUT_6POINT1_FRONT; - const _7POINT0 = AV_CH_LAYOUT_7POINT0; - const _7POINT0_FRONT = AV_CH_LAYOUT_7POINT0_FRONT; - const _7POINT1 = AV_CH_LAYOUT_7POINT1; - const _7POINT1_WIDE = AV_CH_LAYOUT_7POINT1_WIDE; - const _7POINT1_WIDE_BACK = AV_CH_LAYOUT_7POINT1_WIDE_BACK; - const OCTAGONAL = AV_CH_LAYOUT_OCTAGONAL; - const HEXADECAGONAL = AV_CH_LAYOUT_HEXADECAGONAL; - const STEREO_DOWNMIX = AV_CH_LAYOUT_STEREO_DOWNMIX; - } + const MONO = AV_CH_LAYOUT_MONO; + const STEREO = AV_CH_LAYOUT_STEREO; + const _2POINT1 = AV_CH_LAYOUT_2POINT1; + const _2_1 = AV_CH_LAYOUT_2_1; + const SURROUND = AV_CH_LAYOUT_SURROUND; + const _3POINT1 = AV_CH_LAYOUT_3POINT1; + const _4POINT0 = AV_CH_LAYOUT_4POINT0; + const _4POINT1 = AV_CH_LAYOUT_4POINT1; + const _2_2 = AV_CH_LAYOUT_2_2; + const QUAD = AV_CH_LAYOUT_QUAD; + const _5POINT0 = AV_CH_LAYOUT_5POINT0; + const _5POINT1 = AV_CH_LAYOUT_5POINT1; + const _5POINT0_BACK = AV_CH_LAYOUT_5POINT0_BACK; + const _5POINT1_BACK = AV_CH_LAYOUT_5POINT1_BACK; + const _6POINT0 = AV_CH_LAYOUT_6POINT0; + const _6POINT0_FRONT = AV_CH_LAYOUT_6POINT0_FRONT; + const HEXAGONAL = AV_CH_LAYOUT_HEXAGONAL; + const _6POINT1 = AV_CH_LAYOUT_6POINT1; + const _6POINT1_BACK = AV_CH_LAYOUT_6POINT1_BACK; + const _6POINT1_FRONT = AV_CH_LAYOUT_6POINT1_FRONT; + const _7POINT0 = AV_CH_LAYOUT_7POINT0; + const _7POINT0_FRONT = AV_CH_LAYOUT_7POINT0_FRONT; + const _7POINT1 = AV_CH_LAYOUT_7POINT1; + const _7POINT1_WIDE = AV_CH_LAYOUT_7POINT1_WIDE; + const _7POINT1_WIDE_BACK = AV_CH_LAYOUT_7POINT1_WIDE_BACK; + const OCTAGONAL = AV_CH_LAYOUT_OCTAGONAL; + const HEXADECAGONAL = AV_CH_LAYOUT_HEXADECAGONAL; + const STEREO_DOWNMIX = AV_CH_LAYOUT_STEREO_DOWNMIX; + } } impl ChannelLayout { - #[inline] - pub fn channels(&self) -> i32 { - unsafe { - av_get_channel_layout_nb_channels(self.bits()) - } - } + #[inline] + pub fn channels(&self) -> i32 { + unsafe { av_get_channel_layout_nb_channels(self.bits()) } + } - pub fn default(number: i32) -> ChannelLayout { - unsafe { - ChannelLayout::from_bits_truncate(av_get_default_channel_layout(number) as c_ulonglong) - } - } + pub fn default(number: i32) -> ChannelLayout { + unsafe { + ChannelLayout::from_bits_truncate(av_get_default_channel_layout(number) as c_ulonglong) + } + } } diff --git a/src/util/chroma/location.rs b/src/util/chroma/location.rs index 1dc64f1..0c5e3e8 100644 --- a/src/util/chroma/location.rs +++ b/src/util/chroma/location.rs @@ -1,42 +1,42 @@ -use ffi::*; use ffi::AVChromaLocation::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Location { - Unspecified, - Left, - Center, - TopLeft, - Top, - BottomLeft, - Bottom, + Unspecified, + Left, + Center, + TopLeft, + Top, + BottomLeft, + Bottom, } impl From for Location { - fn from(value: AVChromaLocation) -> Self { - match value { - AVCHROMA_LOC_UNSPECIFIED => Location::Unspecified, - AVCHROMA_LOC_LEFT => Location::Left, - AVCHROMA_LOC_CENTER => Location::Center, - AVCHROMA_LOC_TOPLEFT => Location::TopLeft, - AVCHROMA_LOC_TOP => Location::Top, - AVCHROMA_LOC_BOTTOMLEFT => Location::BottomLeft, - AVCHROMA_LOC_BOTTOM => Location::Bottom, - AVCHROMA_LOC_NB => Location::Unspecified - } - } + fn from(value: AVChromaLocation) -> Self { + match value { + AVCHROMA_LOC_UNSPECIFIED => Location::Unspecified, + AVCHROMA_LOC_LEFT => Location::Left, + AVCHROMA_LOC_CENTER => Location::Center, + AVCHROMA_LOC_TOPLEFT => Location::TopLeft, + AVCHROMA_LOC_TOP => Location::Top, + AVCHROMA_LOC_BOTTOMLEFT => Location::BottomLeft, + AVCHROMA_LOC_BOTTOM => Location::Bottom, + AVCHROMA_LOC_NB => Location::Unspecified, + } + } } impl Into for Location { - fn into(self) -> AVChromaLocation { - match self { - Location::Unspecified => AVCHROMA_LOC_UNSPECIFIED, - Location::Left => AVCHROMA_LOC_LEFT, - Location::Center => AVCHROMA_LOC_CENTER, - Location::TopLeft => AVCHROMA_LOC_TOPLEFT, - Location::Top => AVCHROMA_LOC_TOP, - Location::BottomLeft => AVCHROMA_LOC_BOTTOMLEFT, - Location::Bottom => AVCHROMA_LOC_BOTTOM - } - } + fn into(self) -> AVChromaLocation { + match self { + Location::Unspecified => AVCHROMA_LOC_UNSPECIFIED, + Location::Left => AVCHROMA_LOC_LEFT, + Location::Center => AVCHROMA_LOC_CENTER, + Location::TopLeft => AVCHROMA_LOC_TOPLEFT, + Location::Top => AVCHROMA_LOC_TOP, + Location::BottomLeft => AVCHROMA_LOC_BOTTOMLEFT, + Location::Bottom => AVCHROMA_LOC_BOTTOM, + } + } } diff --git a/src/util/color/primaries.rs b/src/util/color/primaries.rs index d150801..a9d2655 100644 --- a/src/util/color/primaries.rs +++ b/src/util/color/primaries.rs @@ -1,69 +1,69 @@ -use ffi::*; use ffi::AVColorPrimaries::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Primaries { - Reserved0, - BT709, - Unspecified, - Reserved, - BT470M, + Reserved0, + BT709, + Unspecified, + Reserved, + BT470M, - BT470BG, - SMPTE170M, - SMPTE240M, - Film, - BT2020, + BT470BG, + SMPTE170M, + SMPTE240M, + Film, + BT2020, - SMPTE428, - SMPTE431, - SMPTE432, - JEDEC_P22, + SMPTE428, + SMPTE431, + SMPTE432, + JEDEC_P22, } impl From for Primaries { - fn from(value: AVColorPrimaries) -> Primaries { - match value { - AVCOL_PRI_RESERVED0 => Primaries::Reserved0, - AVCOL_PRI_BT709 => Primaries::BT709, - AVCOL_PRI_UNSPECIFIED => Primaries::Unspecified, - AVCOL_PRI_RESERVED => Primaries::Reserved, - AVCOL_PRI_BT470M => Primaries::BT470M, + fn from(value: AVColorPrimaries) -> Primaries { + match value { + AVCOL_PRI_RESERVED0 => Primaries::Reserved0, + AVCOL_PRI_BT709 => Primaries::BT709, + AVCOL_PRI_UNSPECIFIED => Primaries::Unspecified, + AVCOL_PRI_RESERVED => Primaries::Reserved, + AVCOL_PRI_BT470M => Primaries::BT470M, - AVCOL_PRI_BT470BG => Primaries::BT470BG, - AVCOL_PRI_SMPTE170M => Primaries::SMPTE170M, - AVCOL_PRI_SMPTE240M => Primaries::SMPTE240M, - AVCOL_PRI_FILM => Primaries::Film, - AVCOL_PRI_BT2020 => Primaries::BT2020, - AVCOL_PRI_NB => Primaries::Reserved0, + AVCOL_PRI_BT470BG => Primaries::BT470BG, + AVCOL_PRI_SMPTE170M => Primaries::SMPTE170M, + AVCOL_PRI_SMPTE240M => Primaries::SMPTE240M, + AVCOL_PRI_FILM => Primaries::Film, + AVCOL_PRI_BT2020 => Primaries::BT2020, + AVCOL_PRI_NB => Primaries::Reserved0, - AVCOL_PRI_SMPTE428 => Primaries::SMPTE428, - AVCOL_PRI_SMPTE431 => Primaries::SMPTE431, - AVCOL_PRI_SMPTE432 => Primaries::SMPTE432, - AVCOL_PRI_JEDEC_P22 => Primaries::JEDEC_P22, - } - } + AVCOL_PRI_SMPTE428 => Primaries::SMPTE428, + AVCOL_PRI_SMPTE431 => Primaries::SMPTE431, + AVCOL_PRI_SMPTE432 => Primaries::SMPTE432, + AVCOL_PRI_JEDEC_P22 => Primaries::JEDEC_P22, + } + } } impl Into for Primaries { - fn into(self) -> AVColorPrimaries { - match self { - Primaries::Reserved0 => AVCOL_PRI_RESERVED0, - Primaries::BT709 => AVCOL_PRI_BT709, - Primaries::Unspecified => AVCOL_PRI_UNSPECIFIED, - Primaries::Reserved => AVCOL_PRI_RESERVED, - Primaries::BT470M => AVCOL_PRI_BT470M, + fn into(self) -> AVColorPrimaries { + match self { + Primaries::Reserved0 => AVCOL_PRI_RESERVED0, + Primaries::BT709 => AVCOL_PRI_BT709, + Primaries::Unspecified => AVCOL_PRI_UNSPECIFIED, + Primaries::Reserved => AVCOL_PRI_RESERVED, + Primaries::BT470M => AVCOL_PRI_BT470M, - Primaries::BT470BG => AVCOL_PRI_BT470BG, - Primaries::SMPTE170M => AVCOL_PRI_SMPTE170M, - Primaries::SMPTE240M => AVCOL_PRI_SMPTE240M, - Primaries::Film => AVCOL_PRI_FILM, - Primaries::BT2020 => AVCOL_PRI_BT2020, + Primaries::BT470BG => AVCOL_PRI_BT470BG, + Primaries::SMPTE170M => AVCOL_PRI_SMPTE170M, + Primaries::SMPTE240M => AVCOL_PRI_SMPTE240M, + Primaries::Film => AVCOL_PRI_FILM, + Primaries::BT2020 => AVCOL_PRI_BT2020, - Primaries::SMPTE428 => AVCOL_PRI_SMPTE428, - Primaries::SMPTE431 => AVCOL_PRI_SMPTE431, - Primaries::SMPTE432 => AVCOL_PRI_SMPTE432, - Primaries::JEDEC_P22 => AVCOL_PRI_JEDEC_P22, - } - } + Primaries::SMPTE428 => AVCOL_PRI_SMPTE428, + Primaries::SMPTE431 => AVCOL_PRI_SMPTE431, + Primaries::SMPTE432 => AVCOL_PRI_SMPTE432, + Primaries::JEDEC_P22 => AVCOL_PRI_JEDEC_P22, + } + } } diff --git a/src/util/color/range.rs b/src/util/color/range.rs index 42e0668..6fc8aa9 100644 --- a/src/util/color/range.rs +++ b/src/util/color/range.rs @@ -1,30 +1,30 @@ -use ffi::*; use ffi::AVColorRange::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Range { - Unspecified, - MPEG, - JPEG, + Unspecified, + MPEG, + JPEG, } impl From for Range { - fn from(value: AVColorRange) -> Self { - match value { - AVCOL_RANGE_UNSPECIFIED => Range::Unspecified, - AVCOL_RANGE_MPEG => Range::MPEG, - AVCOL_RANGE_JPEG => Range::JPEG, - AVCOL_RANGE_NB => Range::Unspecified - } - } + fn from(value: AVColorRange) -> Self { + match value { + AVCOL_RANGE_UNSPECIFIED => Range::Unspecified, + AVCOL_RANGE_MPEG => Range::MPEG, + AVCOL_RANGE_JPEG => Range::JPEG, + AVCOL_RANGE_NB => Range::Unspecified, + } + } } impl Into for Range { - fn into(self) -> AVColorRange { - match self { - Range::Unspecified => AVCOL_RANGE_UNSPECIFIED, - Range::MPEG => AVCOL_RANGE_MPEG, - Range::JPEG => AVCOL_RANGE_JPEG - } - } + fn into(self) -> AVColorRange { + match self { + Range::Unspecified => AVCOL_RANGE_UNSPECIFIED, + Range::MPEG => AVCOL_RANGE_MPEG, + Range::JPEG => AVCOL_RANGE_JPEG, + } + } } diff --git a/src/util/color/space.rs b/src/util/color/space.rs index bc7eb08..33f80b3 100644 --- a/src/util/color/space.rs +++ b/src/util/color/space.rs @@ -1,82 +1,82 @@ use std::ffi::CStr; use std::str::from_utf8_unchecked; -use ffi::*; use ffi::AVColorSpace::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Space { - RGB, - BT709, - Unspecified, - Reserved, - FCC, - BT470BG, - SMPTE170M, - SMPTE240M, - YCOCG, - YCGCO, - BT2020NCL, - BT2020CL, - SMPTE2085, + RGB, + BT709, + Unspecified, + Reserved, + FCC, + BT470BG, + SMPTE170M, + SMPTE240M, + YCOCG, + YCGCO, + BT2020NCL, + BT2020CL, + SMPTE2085, - ChromaDerivedNCL, - ChromaDerivedCL, - ICTCP, + ChromaDerivedNCL, + ChromaDerivedCL, + ICTCP, } impl Space { - pub fn name(&self) -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(av_get_colorspace_name((*self).into())).to_bytes()) - } - } + pub fn name(&self) -> &'static str { + unsafe { + from_utf8_unchecked(CStr::from_ptr(av_get_colorspace_name((*self).into())).to_bytes()) + } + } } impl From for Space { - fn from(value: AVColorSpace) -> Self { - match value { - AVCOL_SPC_RGB => Space::RGB, - AVCOL_SPC_BT709 => Space::BT709, - AVCOL_SPC_UNSPECIFIED => Space::Unspecified, - AVCOL_SPC_RESERVED => Space::Reserved, - AVCOL_SPC_FCC => Space::FCC, - AVCOL_SPC_BT470BG => Space::BT470BG, - AVCOL_SPC_SMPTE170M => Space::SMPTE170M, - AVCOL_SPC_SMPTE240M => Space::SMPTE240M, - AVCOL_SPC_YCOCG => Space::YCOCG, - AVCOL_SPC_BT2020_NCL => Space::BT2020NCL, - AVCOL_SPC_BT2020_CL => Space::BT2020CL, - AVCOL_SPC_SMPTE2085 => Space::SMPTE2085, - AVCOL_SPC_NB => Space::Unspecified, + fn from(value: AVColorSpace) -> Self { + match value { + AVCOL_SPC_RGB => Space::RGB, + AVCOL_SPC_BT709 => Space::BT709, + AVCOL_SPC_UNSPECIFIED => Space::Unspecified, + AVCOL_SPC_RESERVED => Space::Reserved, + AVCOL_SPC_FCC => Space::FCC, + AVCOL_SPC_BT470BG => Space::BT470BG, + AVCOL_SPC_SMPTE170M => Space::SMPTE170M, + AVCOL_SPC_SMPTE240M => Space::SMPTE240M, + AVCOL_SPC_YCOCG => Space::YCOCG, + AVCOL_SPC_BT2020_NCL => Space::BT2020NCL, + AVCOL_SPC_BT2020_CL => Space::BT2020CL, + AVCOL_SPC_SMPTE2085 => Space::SMPTE2085, + AVCOL_SPC_NB => Space::Unspecified, - AVCOL_SPC_CHROMA_DERIVED_NCL => Space::ChromaDerivedNCL, - AVCOL_SPC_CHROMA_DERIVED_CL => Space::ChromaDerivedCL, - AVCOL_SPC_ICTCP => Space::ICTCP, - } - } + AVCOL_SPC_CHROMA_DERIVED_NCL => Space::ChromaDerivedNCL, + AVCOL_SPC_CHROMA_DERIVED_CL => Space::ChromaDerivedCL, + AVCOL_SPC_ICTCP => Space::ICTCP, + } + } } impl Into for Space { - fn into(self) -> AVColorSpace { - match self { - Space::RGB => AVCOL_SPC_RGB, - Space::BT709 => AVCOL_SPC_BT709, - Space::Unspecified => AVCOL_SPC_UNSPECIFIED, - Space::Reserved => AVCOL_SPC_RESERVED, - Space::FCC => AVCOL_SPC_FCC, - Space::BT470BG => AVCOL_SPC_BT470BG, - Space::SMPTE170M => AVCOL_SPC_SMPTE170M, - Space::SMPTE240M => AVCOL_SPC_SMPTE240M, - Space::YCOCG => AVCOL_SPC_YCOCG, - Space::YCGCO => AVCOL_SPC_YCGCO, - Space::BT2020NCL => AVCOL_SPC_BT2020_NCL, - Space::BT2020CL => AVCOL_SPC_BT2020_CL, - Space::SMPTE2085 => AVCOL_SPC_SMPTE2085, + fn into(self) -> AVColorSpace { + match self { + Space::RGB => AVCOL_SPC_RGB, + Space::BT709 => AVCOL_SPC_BT709, + Space::Unspecified => AVCOL_SPC_UNSPECIFIED, + Space::Reserved => AVCOL_SPC_RESERVED, + Space::FCC => AVCOL_SPC_FCC, + Space::BT470BG => AVCOL_SPC_BT470BG, + Space::SMPTE170M => AVCOL_SPC_SMPTE170M, + Space::SMPTE240M => AVCOL_SPC_SMPTE240M, + Space::YCOCG => AVCOL_SPC_YCOCG, + Space::YCGCO => AVCOL_SPC_YCGCO, + Space::BT2020NCL => AVCOL_SPC_BT2020_NCL, + Space::BT2020CL => AVCOL_SPC_BT2020_CL, + Space::SMPTE2085 => AVCOL_SPC_SMPTE2085, - Space::ChromaDerivedNCL => AVCOL_SPC_CHROMA_DERIVED_NCL, - Space::ChromaDerivedCL => AVCOL_SPC_CHROMA_DERIVED_CL, - Space::ICTCP => AVCOL_SPC_ICTCP, - } - } + Space::ChromaDerivedNCL => AVCOL_SPC_CHROMA_DERIVED_NCL, + Space::ChromaDerivedCL => AVCOL_SPC_CHROMA_DERIVED_CL, + Space::ICTCP => AVCOL_SPC_ICTCP, + } + } } diff --git a/src/util/color/transfer_characteristic.rs b/src/util/color/transfer_characteristic.rs index 39e0c29..094a48b 100644 --- a/src/util/color/transfer_characteristic.rs +++ b/src/util/color/transfer_characteristic.rs @@ -1,78 +1,78 @@ -use ffi::*; use ffi::AVColorTransferCharacteristic::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum TransferCharacteristic { - Reserved0, - BT709, - Unspecified, - Reserved, - GAMMA22, - GAMMA28, - SMPTE170M, - SMPTE240M, - Linear, - Log, - LogSqrt, - IEC61966_2_4, - BT1361_ECG, - IEC61966_2_1, - BT2020_10, - BT2020_12, - SMPTE2084, - SMPTE428, - ARIB_STD_B67, + Reserved0, + BT709, + Unspecified, + Reserved, + GAMMA22, + GAMMA28, + SMPTE170M, + SMPTE240M, + Linear, + Log, + LogSqrt, + IEC61966_2_4, + BT1361_ECG, + IEC61966_2_1, + BT2020_10, + BT2020_12, + SMPTE2084, + SMPTE428, + ARIB_STD_B67, } impl From for TransferCharacteristic { - fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic { - match value { - AVCOL_TRC_RESERVED0 => TransferCharacteristic::Reserved0, - AVCOL_TRC_BT709 => TransferCharacteristic::BT709, - AVCOL_TRC_UNSPECIFIED => TransferCharacteristic::Unspecified, - AVCOL_TRC_RESERVED => TransferCharacteristic::Reserved, - AVCOL_TRC_GAMMA22 => TransferCharacteristic::GAMMA22, - AVCOL_TRC_GAMMA28 => TransferCharacteristic::GAMMA28, - AVCOL_TRC_SMPTE170M => TransferCharacteristic::SMPTE170M, - AVCOL_TRC_SMPTE240M => TransferCharacteristic::SMPTE240M, - AVCOL_TRC_LINEAR => TransferCharacteristic::Linear, - AVCOL_TRC_LOG => TransferCharacteristic::Log, - AVCOL_TRC_LOG_SQRT => TransferCharacteristic::LogSqrt, - AVCOL_TRC_IEC61966_2_4 => TransferCharacteristic::IEC61966_2_4, - AVCOL_TRC_BT1361_ECG => TransferCharacteristic::BT1361_ECG, - AVCOL_TRC_IEC61966_2_1 => TransferCharacteristic::IEC61966_2_1, - AVCOL_TRC_BT2020_10 => TransferCharacteristic::BT2020_10, - AVCOL_TRC_BT2020_12 => TransferCharacteristic::BT2020_12, - AVCOL_TRC_NB => TransferCharacteristic::Reserved0, - AVCOL_TRC_SMPTE2084 => TransferCharacteristic::SMPTE2084, - AVCOL_TRC_SMPTE428 => TransferCharacteristic::SMPTE428, - AVCOL_TRC_ARIB_STD_B67 => TransferCharacteristic::ARIB_STD_B67, - } - } + fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic { + match value { + AVCOL_TRC_RESERVED0 => TransferCharacteristic::Reserved0, + AVCOL_TRC_BT709 => TransferCharacteristic::BT709, + AVCOL_TRC_UNSPECIFIED => TransferCharacteristic::Unspecified, + AVCOL_TRC_RESERVED => TransferCharacteristic::Reserved, + AVCOL_TRC_GAMMA22 => TransferCharacteristic::GAMMA22, + AVCOL_TRC_GAMMA28 => TransferCharacteristic::GAMMA28, + AVCOL_TRC_SMPTE170M => TransferCharacteristic::SMPTE170M, + AVCOL_TRC_SMPTE240M => TransferCharacteristic::SMPTE240M, + AVCOL_TRC_LINEAR => TransferCharacteristic::Linear, + AVCOL_TRC_LOG => TransferCharacteristic::Log, + AVCOL_TRC_LOG_SQRT => TransferCharacteristic::LogSqrt, + AVCOL_TRC_IEC61966_2_4 => TransferCharacteristic::IEC61966_2_4, + AVCOL_TRC_BT1361_ECG => TransferCharacteristic::BT1361_ECG, + AVCOL_TRC_IEC61966_2_1 => TransferCharacteristic::IEC61966_2_1, + AVCOL_TRC_BT2020_10 => TransferCharacteristic::BT2020_10, + AVCOL_TRC_BT2020_12 => TransferCharacteristic::BT2020_12, + AVCOL_TRC_NB => TransferCharacteristic::Reserved0, + AVCOL_TRC_SMPTE2084 => TransferCharacteristic::SMPTE2084, + AVCOL_TRC_SMPTE428 => TransferCharacteristic::SMPTE428, + AVCOL_TRC_ARIB_STD_B67 => TransferCharacteristic::ARIB_STD_B67, + } + } } impl Into for TransferCharacteristic { - fn into(self) -> AVColorTransferCharacteristic { - match self { - TransferCharacteristic::Reserved0 => AVCOL_TRC_RESERVED0, - TransferCharacteristic::BT709 => AVCOL_TRC_BT709, - TransferCharacteristic::Unspecified => AVCOL_TRC_UNSPECIFIED, - TransferCharacteristic::Reserved => AVCOL_TRC_RESERVED, - TransferCharacteristic::GAMMA22 => AVCOL_TRC_GAMMA22, - TransferCharacteristic::GAMMA28 => AVCOL_TRC_GAMMA28, - TransferCharacteristic::SMPTE170M => AVCOL_TRC_SMPTE170M, - TransferCharacteristic::SMPTE240M => AVCOL_TRC_SMPTE240M, - TransferCharacteristic::Linear => AVCOL_TRC_LINEAR, - TransferCharacteristic::Log => AVCOL_TRC_LOG, - TransferCharacteristic::LogSqrt => AVCOL_TRC_LOG_SQRT, - TransferCharacteristic::IEC61966_2_4 => AVCOL_TRC_IEC61966_2_4, - TransferCharacteristic::BT1361_ECG => AVCOL_TRC_BT1361_ECG, - TransferCharacteristic::IEC61966_2_1 => AVCOL_TRC_IEC61966_2_1, - TransferCharacteristic::BT2020_10 => AVCOL_TRC_BT2020_10, - TransferCharacteristic::BT2020_12 => AVCOL_TRC_BT2020_12, - TransferCharacteristic::SMPTE2084 => AVCOL_TRC_SMPTE2084, - TransferCharacteristic::SMPTE428 => AVCOL_TRC_SMPTE428, - TransferCharacteristic::ARIB_STD_B67 => AVCOL_TRC_ARIB_STD_B67, - } - } + fn into(self) -> AVColorTransferCharacteristic { + match self { + TransferCharacteristic::Reserved0 => AVCOL_TRC_RESERVED0, + TransferCharacteristic::BT709 => AVCOL_TRC_BT709, + TransferCharacteristic::Unspecified => AVCOL_TRC_UNSPECIFIED, + TransferCharacteristic::Reserved => AVCOL_TRC_RESERVED, + TransferCharacteristic::GAMMA22 => AVCOL_TRC_GAMMA22, + TransferCharacteristic::GAMMA28 => AVCOL_TRC_GAMMA28, + TransferCharacteristic::SMPTE170M => AVCOL_TRC_SMPTE170M, + TransferCharacteristic::SMPTE240M => AVCOL_TRC_SMPTE240M, + TransferCharacteristic::Linear => AVCOL_TRC_LINEAR, + TransferCharacteristic::Log => AVCOL_TRC_LOG, + TransferCharacteristic::LogSqrt => AVCOL_TRC_LOG_SQRT, + TransferCharacteristic::IEC61966_2_4 => AVCOL_TRC_IEC61966_2_4, + TransferCharacteristic::BT1361_ECG => AVCOL_TRC_BT1361_ECG, + TransferCharacteristic::IEC61966_2_1 => AVCOL_TRC_IEC61966_2_1, + TransferCharacteristic::BT2020_10 => AVCOL_TRC_BT2020_10, + TransferCharacteristic::BT2020_12 => AVCOL_TRC_BT2020_12, + TransferCharacteristic::SMPTE2084 => AVCOL_TRC_SMPTE2084, + TransferCharacteristic::SMPTE428 => AVCOL_TRC_SMPTE428, + TransferCharacteristic::ARIB_STD_B67 => AVCOL_TRC_ARIB_STD_B67, + } + } } diff --git a/src/util/dictionary/immutable.rs b/src/util/dictionary/immutable.rs index 5293ed2..058547f 100644 --- a/src/util/dictionary/immutable.rs +++ b/src/util/dictionary/immutable.rs @@ -1,58 +1,60 @@ +use std::ffi::{CStr, CString}; use std::marker::PhantomData; use std::ptr; -use std::ffi::{CStr, CString}; use std::str::from_utf8_unchecked; -use ffi::*; use super::{Iter, Owned}; +use ffi::*; pub struct Ref<'a> { - ptr: *const AVDictionary, + ptr: *const AVDictionary, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Ref<'a> { - pub unsafe fn wrap(ptr: *const AVDictionary) -> Self { - Ref { ptr: ptr, _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *const AVDictionary) -> Self { + Ref { + ptr: ptr, + _marker: PhantomData, + } + } - pub unsafe fn as_ptr(&self) -> *const AVDictionary { - self.ptr - } + pub unsafe fn as_ptr(&self) -> *const AVDictionary { + self.ptr + } } impl<'a> Ref<'a> { - pub fn get(&'a self, key: &str) -> Option<&'a str> { - unsafe { - let key = CString::new(key).unwrap(); - let entry = av_dict_get(self.as_ptr(), key.as_ptr(), ptr::null_mut(), 0); + pub fn get(&'a self, key: &str) -> Option<&'a str> { + unsafe { + let key = CString::new(key).unwrap(); + let entry = av_dict_get(self.as_ptr(), key.as_ptr(), ptr::null_mut(), 0); - if entry.is_null() { - None - } - else { - Some(from_utf8_unchecked(CStr::from_ptr((*entry).value).to_bytes())) - } - } - } + if entry.is_null() { + None + } else { + Some(from_utf8_unchecked( + CStr::from_ptr((*entry).value).to_bytes(), + )) + } + } + } - pub fn iter(&self) -> Iter { - unsafe { - Iter::new(self.as_ptr()) - } - } + pub fn iter(&self) -> Iter { + unsafe { Iter::new(self.as_ptr()) } + } - pub fn to_owned<'b>(&self) -> Owned<'b> { - self.iter().collect() - } + pub fn to_owned<'b>(&self) -> Owned<'b> { + self.iter().collect() + } } impl<'a> IntoIterator for &'a Ref<'a> { - type Item = (&'a str, &'a str); - type IntoIter = Iter<'a>; + type Item = (&'a str, &'a str); + type IntoIter = Iter<'a>; - fn into_iter(self) -> Self::IntoIter { - self.iter() - } + fn into_iter(self) -> Self::IntoIter { + self.iter() + } } diff --git a/src/util/dictionary/iter.rs b/src/util/dictionary/iter.rs index 42fee1a..7466429 100644 --- a/src/util/dictionary/iter.rs +++ b/src/util/dictionary/iter.rs @@ -1,47 +1,46 @@ +use std::ffi::{CStr, CString}; use std::marker::PhantomData; use std::ptr; -use std::ffi::{CStr, CString}; use std::str::from_utf8_unchecked; use ffi::*; pub struct Iter<'a> { - ptr: *const AVDictionary, - cur: *mut AVDictionaryEntry, + ptr: *const AVDictionary, + cur: *mut AVDictionaryEntry, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Iter<'a> { - pub fn new(dictionary: *const AVDictionary) -> Self { - Iter { - ptr: dictionary, - cur: ptr::null_mut(), + pub fn new(dictionary: *const AVDictionary) -> Self { + Iter { + ptr: dictionary, + cur: ptr::null_mut(), - _marker: PhantomData - } - } + _marker: PhantomData, + } + } } impl<'a> Iterator for Iter<'a> { - type Item = (&'a str, &'a str); + type Item = (&'a str, &'a str); - fn next(&mut self) -> Option<::Item> { - unsafe { - let empty = CString::new("").unwrap(); - let entry = av_dict_get(self.ptr, empty.as_ptr(), self.cur, AV_DICT_IGNORE_SUFFIX); + fn next(&mut self) -> Option<::Item> { + unsafe { + let empty = CString::new("").unwrap(); + let entry = av_dict_get(self.ptr, empty.as_ptr(), self.cur, AV_DICT_IGNORE_SUFFIX); - if !entry.is_null() { - let key = from_utf8_unchecked(CStr::from_ptr((*entry).key).to_bytes()); - let val = from_utf8_unchecked(CStr::from_ptr((*entry).value).to_bytes()); + if !entry.is_null() { + let key = from_utf8_unchecked(CStr::from_ptr((*entry).key).to_bytes()); + let val = from_utf8_unchecked(CStr::from_ptr((*entry).value).to_bytes()); - self.cur = entry; + self.cur = entry; - Some((key, val)) - } - else { - None - } - } - } + Some((key, val)) + } else { + None + } + } + } } diff --git a/src/util/dictionary/mutable.rs b/src/util/dictionary/mutable.rs index e65cd75..7e345fb 100644 --- a/src/util/dictionary/mutable.rs +++ b/src/util/dictionary/mutable.rs @@ -1,48 +1,52 @@ -use std::ops::Deref; -use std::marker::PhantomData; use std::ffi::CString; +use std::marker::PhantomData; +use std::ops::Deref; -use ffi::*; use super::immutable; +use ffi::*; pub struct Ref<'a> { - ptr: *mut AVDictionary, - imm: immutable::Ref<'a>, + ptr: *mut AVDictionary, + imm: immutable::Ref<'a>, - _marker: PhantomData<&'a ()>, + _marker: PhantomData<&'a ()>, } impl<'a> Ref<'a> { - pub unsafe fn wrap(ptr: *mut AVDictionary) -> Self { - Ref { ptr: ptr, imm: immutable::Ref::wrap(ptr), _marker: PhantomData } - } + pub unsafe fn wrap(ptr: *mut AVDictionary) -> Self { + Ref { + ptr: ptr, + imm: immutable::Ref::wrap(ptr), + _marker: PhantomData, + } + } - pub unsafe fn as_mut_ptr(&self) -> *mut AVDictionary { - self.ptr - } + pub unsafe fn as_mut_ptr(&self) -> *mut AVDictionary { + self.ptr + } } impl<'a> Ref<'a> { - pub fn set(&mut self, key: &str, value: &str) { - unsafe { - let key = CString::new(key).unwrap(); - let value = CString::new(value).unwrap(); - let mut ptr = self.as_mut_ptr(); + pub fn set(&mut self, key: &str, value: &str) { + unsafe { + let key = CString::new(key).unwrap(); + let value = CString::new(value).unwrap(); + let mut ptr = self.as_mut_ptr(); - if av_dict_set(&mut ptr, key.as_ptr(), value.as_ptr(), 0) < 0 { - panic!("out of memory"); - } + if av_dict_set(&mut ptr, key.as_ptr(), value.as_ptr(), 0) < 0 { + panic!("out of memory"); + } - self.ptr = ptr; - self.imm = immutable::Ref::wrap(ptr); - } - } + self.ptr = ptr; + self.imm = immutable::Ref::wrap(ptr); + } + } } impl<'a> Deref for Ref<'a> { - type Target = immutable::Ref<'a>; + type Target = immutable::Ref<'a>; - fn deref(&self) -> &Self::Target { - &self.imm - } + fn deref(&self) -> &Self::Target { + &self.imm + } } diff --git a/src/util/dictionary/owned.rs b/src/util/dictionary/owned.rs index ff0238d..00d06ed 100644 --- a/src/util/dictionary/owned.rs +++ b/src/util/dictionary/owned.rs @@ -1,124 +1,128 @@ -use std::ops::{Deref, DerefMut}; use std::iter::FromIterator; +use std::ops::{Deref, DerefMut}; use std::ptr; -use ffi::*; use super::mutable; +use ffi::*; pub struct Owned<'a> { - inner: mutable::Ref<'a>, + inner: mutable::Ref<'a>, } impl<'a> Default for Owned<'a> { - fn default() -> Self { - Self::new() - } + fn default() -> Self { + Self::new() + } } impl<'a> Owned<'a> { - pub unsafe fn own(ptr: *mut AVDictionary) -> Self { - Owned { inner: mutable::Ref::wrap(ptr) } - } + pub unsafe fn own(ptr: *mut AVDictionary) -> Self { + Owned { + inner: mutable::Ref::wrap(ptr), + } + } - pub unsafe fn disown(mut self) -> *mut AVDictionary { - let result = self.inner.as_mut_ptr(); - self.inner = mutable::Ref::wrap(ptr::null_mut()); + pub unsafe fn disown(mut self) -> *mut AVDictionary { + let result = self.inner.as_mut_ptr(); + self.inner = mutable::Ref::wrap(ptr::null_mut()); - result - } + result + } } impl<'a> Owned<'a> { - pub fn new() -> Self { - unsafe { - Owned { inner: mutable::Ref::wrap(ptr::null_mut()) } - } - } + pub fn new() -> Self { + unsafe { + Owned { + inner: mutable::Ref::wrap(ptr::null_mut()), + } + } + } } impl<'a, 'b> FromIterator<(&'b str, &'b str)> for Owned<'a> { - fn from_iter>(iterator: T) -> Self { - let mut result = Owned::new(); + fn from_iter>(iterator: T) -> Self { + let mut result = Owned::new(); - for (key, value) in iterator { - result.set(key, value); - } + for (key, value) in iterator { + result.set(key, value); + } - result - } + result + } } impl<'a, 'b> FromIterator<&'b (&'b str, &'b str)> for Owned<'a> { - fn from_iter>(iterator: T) -> Self { - let mut result = Owned::new(); + fn from_iter>(iterator: T) -> Self { + let mut result = Owned::new(); - for &(key, value) in iterator { - result.set(key, value); - } + for &(key, value) in iterator { + result.set(key, value); + } - result - } + result + } } impl<'a> FromIterator<(String, String)> for Owned<'a> { - fn from_iter>(iterator: T) -> Self { - let mut result = Owned::new(); + fn from_iter>(iterator: T) -> Self { + let mut result = Owned::new(); - for (key, value) in iterator { - result.set(&key, &value); - } + for (key, value) in iterator { + result.set(&key, &value); + } - result - } + result + } } impl<'a, 'b> FromIterator<&'b (String, String)> for Owned<'a> { - fn from_iter>(iterator: T) -> Self { - let mut result = Owned::new(); + fn from_iter>(iterator: T) -> Self { + let mut result = Owned::new(); - for &(ref key, ref value) in iterator { - result.set(key, value); - } + for &(ref key, ref value) in iterator { + result.set(key, value); + } - result - } + result + } } impl<'a> Deref for Owned<'a> { - type Target = mutable::Ref<'a>; + type Target = mutable::Ref<'a>; - fn deref(&self) -> &Self::Target { - &self.inner - } + fn deref(&self) -> &Self::Target { + &self.inner + } } impl<'a> DerefMut for Owned<'a> { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner - } + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.inner + } } impl<'a> Clone for Owned<'a> { - fn clone(&self) -> Self { - let mut dictionary = Owned::new(); - dictionary.clone_from(self); + fn clone(&self) -> Self { + let mut dictionary = Owned::new(); + dictionary.clone_from(self); - dictionary - } + dictionary + } - fn clone_from(&mut self, source: &Self) { - unsafe { - let mut ptr = self.as_mut_ptr(); - av_dict_copy(&mut ptr, source.as_ptr(), 0); - self.inner = mutable::Ref::wrap(ptr); - } - } + fn clone_from(&mut self, source: &Self) { + unsafe { + let mut ptr = self.as_mut_ptr(); + av_dict_copy(&mut ptr, source.as_ptr(), 0); + self.inner = mutable::Ref::wrap(ptr); + } + } } impl<'a> Drop for Owned<'a> { - fn drop(&mut self) { - unsafe { - av_dict_free(&mut self.inner.as_mut_ptr()); - } - } + fn drop(&mut self) { + unsafe { + av_dict_free(&mut self.inner.as_mut_ptr()); + } + } } diff --git a/src/util/error.rs b/src/util/error.rs index 54e19b2..eb86a70 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -1,213 +1,319 @@ use std::error; -use std::io; -use std::fmt; use std::ffi::CStr; +use std::fmt; +use std::io; use std::str::from_utf8_unchecked; -use libc::c_int; use ffi::*; +use libc::c_int; #[derive(Copy, Clone)] pub enum Error { - Bug, - Bug2, - Unknown, - Experimental, - BufferTooSmall, - Eof, - Exit, - External, - InvalidData, - PatchWelcome, + Bug, + Bug2, + Unknown, + Experimental, + BufferTooSmall, + Eof, + Exit, + External, + InvalidData, + PatchWelcome, - InputChanged, - OutputChanged, + InputChanged, + OutputChanged, - BsfNotFound, - DecoderNotFound, - DemuxerNotFound, - EncoderNotFound, - OptionNotFound, - MuxerNotFound, - FilterNotFound, - ProtocolNotFound, - StreamNotFound, + BsfNotFound, + DecoderNotFound, + DemuxerNotFound, + EncoderNotFound, + OptionNotFound, + MuxerNotFound, + FilterNotFound, + ProtocolNotFound, + StreamNotFound, - HttpBadRequest, - HttpUnauthorized, - HttpForbidden, - HttpNotFound, - HttpOther4xx, - HttpServerError, + HttpBadRequest, + HttpUnauthorized, + HttpForbidden, + HttpNotFound, + HttpOther4xx, + HttpServerError, } impl From for Error { - fn from(value: c_int) -> Error { - match value { - AVERROR_BSF_NOT_FOUND => Error::BsfNotFound, - AVERROR_BUG => Error::Bug, - AVERROR_BUFFER_TOO_SMALL => Error::BufferTooSmall, - AVERROR_DECODER_NOT_FOUND => Error::DecoderNotFound, - AVERROR_DEMUXER_NOT_FOUND => Error::DemuxerNotFound, - AVERROR_ENCODER_NOT_FOUND => Error::EncoderNotFound, - AVERROR_EOF => Error::Eof, - AVERROR_EXIT => Error::Exit, - AVERROR_EXTERNAL => Error::External, - AVERROR_FILTER_NOT_FOUND => Error::FilterNotFound, - AVERROR_INVALIDDATA => Error::InvalidData, - AVERROR_MUXER_NOT_FOUND => Error::MuxerNotFound, - AVERROR_OPTION_NOT_FOUND => Error::OptionNotFound, - AVERROR_PATCHWELCOME => Error::PatchWelcome, - AVERROR_PROTOCOL_NOT_FOUND => Error::ProtocolNotFound, - AVERROR_STREAM_NOT_FOUND => Error::StreamNotFound, - AVERROR_BUG2 => Error::Bug2, - AVERROR_UNKNOWN => Error::Unknown, - AVERROR_EXPERIMENTAL => Error::Experimental, - AVERROR_INPUT_CHANGED => Error::InputChanged, - AVERROR_OUTPUT_CHANGED => Error::OutputChanged, - AVERROR_HTTP_BAD_REQUEST => Error::HttpBadRequest, - AVERROR_HTTP_UNAUTHORIZED => Error::HttpUnauthorized, - AVERROR_HTTP_FORBIDDEN => Error::HttpForbidden, - AVERROR_HTTP_NOT_FOUND => Error::HttpNotFound, - AVERROR_HTTP_OTHER_4XX => Error::HttpOther4xx, - AVERROR_HTTP_SERVER_ERROR => Error::HttpServerError, + fn from(value: c_int) -> Error { + match value { + AVERROR_BSF_NOT_FOUND => Error::BsfNotFound, + AVERROR_BUG => Error::Bug, + AVERROR_BUFFER_TOO_SMALL => Error::BufferTooSmall, + AVERROR_DECODER_NOT_FOUND => Error::DecoderNotFound, + AVERROR_DEMUXER_NOT_FOUND => Error::DemuxerNotFound, + AVERROR_ENCODER_NOT_FOUND => Error::EncoderNotFound, + AVERROR_EOF => Error::Eof, + AVERROR_EXIT => Error::Exit, + AVERROR_EXTERNAL => Error::External, + AVERROR_FILTER_NOT_FOUND => Error::FilterNotFound, + AVERROR_INVALIDDATA => Error::InvalidData, + AVERROR_MUXER_NOT_FOUND => Error::MuxerNotFound, + AVERROR_OPTION_NOT_FOUND => Error::OptionNotFound, + AVERROR_PATCHWELCOME => Error::PatchWelcome, + AVERROR_PROTOCOL_NOT_FOUND => Error::ProtocolNotFound, + AVERROR_STREAM_NOT_FOUND => Error::StreamNotFound, + AVERROR_BUG2 => Error::Bug2, + AVERROR_UNKNOWN => Error::Unknown, + AVERROR_EXPERIMENTAL => Error::Experimental, + AVERROR_INPUT_CHANGED => Error::InputChanged, + AVERROR_OUTPUT_CHANGED => Error::OutputChanged, + AVERROR_HTTP_BAD_REQUEST => Error::HttpBadRequest, + AVERROR_HTTP_UNAUTHORIZED => Error::HttpUnauthorized, + AVERROR_HTTP_FORBIDDEN => Error::HttpForbidden, + AVERROR_HTTP_NOT_FOUND => Error::HttpNotFound, + AVERROR_HTTP_OTHER_4XX => Error::HttpOther4xx, + AVERROR_HTTP_SERVER_ERROR => Error::HttpServerError, - _ => Error::Unknown - } - } + _ => Error::Unknown, + } + } } impl Into for Error { - fn into(self) -> c_int { - match self { - Error::BsfNotFound => AVERROR_BSF_NOT_FOUND, - Error::Bug => AVERROR_BUG, - Error::BufferTooSmall => AVERROR_BUFFER_TOO_SMALL, - Error::DecoderNotFound => AVERROR_DECODER_NOT_FOUND, - Error::DemuxerNotFound => AVERROR_DEMUXER_NOT_FOUND, - Error::EncoderNotFound => AVERROR_ENCODER_NOT_FOUND, - Error::Eof => AVERROR_EOF, - Error::Exit => AVERROR_EXIT, - Error::External => AVERROR_EXTERNAL, - Error::FilterNotFound => AVERROR_FILTER_NOT_FOUND, - Error::InvalidData => AVERROR_INVALIDDATA, - Error::MuxerNotFound => AVERROR_MUXER_NOT_FOUND, - Error::OptionNotFound => AVERROR_OPTION_NOT_FOUND, - Error::PatchWelcome => AVERROR_PATCHWELCOME, - Error::ProtocolNotFound => AVERROR_PROTOCOL_NOT_FOUND, - Error::StreamNotFound => AVERROR_STREAM_NOT_FOUND, - Error::Bug2 => AVERROR_BUG2, - Error::Unknown => AVERROR_UNKNOWN, - Error::Experimental => AVERROR_EXPERIMENTAL, - Error::InputChanged => AVERROR_INPUT_CHANGED, - Error::OutputChanged => AVERROR_OUTPUT_CHANGED, - Error::HttpBadRequest => AVERROR_HTTP_BAD_REQUEST, - Error::HttpUnauthorized => AVERROR_HTTP_UNAUTHORIZED, - Error::HttpForbidden => AVERROR_HTTP_FORBIDDEN, - Error::HttpNotFound => AVERROR_HTTP_NOT_FOUND, - Error::HttpOther4xx => AVERROR_HTTP_OTHER_4XX, - Error::HttpServerError => AVERROR_HTTP_SERVER_ERROR, - } - } + fn into(self) -> c_int { + match self { + Error::BsfNotFound => AVERROR_BSF_NOT_FOUND, + Error::Bug => AVERROR_BUG, + Error::BufferTooSmall => AVERROR_BUFFER_TOO_SMALL, + Error::DecoderNotFound => AVERROR_DECODER_NOT_FOUND, + Error::DemuxerNotFound => AVERROR_DEMUXER_NOT_FOUND, + Error::EncoderNotFound => AVERROR_ENCODER_NOT_FOUND, + Error::Eof => AVERROR_EOF, + Error::Exit => AVERROR_EXIT, + Error::External => AVERROR_EXTERNAL, + Error::FilterNotFound => AVERROR_FILTER_NOT_FOUND, + Error::InvalidData => AVERROR_INVALIDDATA, + Error::MuxerNotFound => AVERROR_MUXER_NOT_FOUND, + Error::OptionNotFound => AVERROR_OPTION_NOT_FOUND, + Error::PatchWelcome => AVERROR_PATCHWELCOME, + Error::ProtocolNotFound => AVERROR_PROTOCOL_NOT_FOUND, + Error::StreamNotFound => AVERROR_STREAM_NOT_FOUND, + Error::Bug2 => AVERROR_BUG2, + Error::Unknown => AVERROR_UNKNOWN, + Error::Experimental => AVERROR_EXPERIMENTAL, + Error::InputChanged => AVERROR_INPUT_CHANGED, + Error::OutputChanged => AVERROR_OUTPUT_CHANGED, + Error::HttpBadRequest => AVERROR_HTTP_BAD_REQUEST, + Error::HttpUnauthorized => AVERROR_HTTP_UNAUTHORIZED, + Error::HttpForbidden => AVERROR_HTTP_FORBIDDEN, + Error::HttpNotFound => AVERROR_HTTP_NOT_FOUND, + Error::HttpOther4xx => AVERROR_HTTP_OTHER_4XX, + Error::HttpServerError => AVERROR_HTTP_SERVER_ERROR, + } + } } impl From for io::Error { - fn from(value: Error) -> io::Error { - io::Error::new(io::ErrorKind::Other, value) - } + fn from(value: Error) -> io::Error { + io::Error::new(io::ErrorKind::Other, value) + } } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - f.write_str(error::Error::description(self)) - } + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + f.write_str(error::Error::description(self)) + } } impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(f.write_str("ffmpeg::Error(")); - try!(f.write_str(&format!("{}: ", AVUNERROR((*self).into())))); - try!(fmt::Display::fmt(self, f)); - f.write_str(")") - } + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + f.write_str("ffmpeg::Error(")?; + f.write_str(&format!("{}: ", AVUNERROR((*self).into())))?; + fmt::Display::fmt(self, f)?; + f.write_str(")") + } } #[inline(always)] fn index(error: &Error) -> usize { - match error { - &Error::BsfNotFound => 0, - &Error::Bug => 1, - &Error::BufferTooSmall => 2, - &Error::DecoderNotFound => 3, - &Error::DemuxerNotFound => 4, - &Error::EncoderNotFound => 5, - &Error::Eof => 6, - &Error::Exit => 7, - &Error::External => 8, - &Error::FilterNotFound => 9, - &Error::InvalidData => 10, - &Error::MuxerNotFound => 11, - &Error::OptionNotFound => 12, - &Error::PatchWelcome => 13, - &Error::ProtocolNotFound => 14, - &Error::StreamNotFound => 15, - &Error::Bug2 => 16, - &Error::Unknown => 17, - &Error::Experimental => 18, - &Error::InputChanged => 19, - &Error::OutputChanged => 20, - &Error::HttpBadRequest => 21, - &Error::HttpUnauthorized => 22, - &Error::HttpForbidden => 23, - &Error::HttpNotFound => 24, - &Error::HttpOther4xx => 25, - &Error::HttpServerError => 26, - } + match *error { + Error::BsfNotFound => 0, + Error::Bug => 1, + Error::BufferTooSmall => 2, + Error::DecoderNotFound => 3, + Error::DemuxerNotFound => 4, + Error::EncoderNotFound => 5, + Error::Eof => 6, + Error::Exit => 7, + Error::External => 8, + Error::FilterNotFound => 9, + Error::InvalidData => 10, + Error::MuxerNotFound => 11, + Error::OptionNotFound => 12, + Error::PatchWelcome => 13, + Error::ProtocolNotFound => 14, + Error::StreamNotFound => 15, + Error::Bug2 => 16, + Error::Unknown => 17, + Error::Experimental => 18, + Error::InputChanged => 19, + Error::OutputChanged => 20, + Error::HttpBadRequest => 21, + Error::HttpUnauthorized => 22, + Error::HttpForbidden => 23, + Error::HttpNotFound => 24, + Error::HttpOther4xx => 25, + Error::HttpServerError => 26, + } } // XXX: the length has to be synced with the number of errors -static mut STRINGS: [[i8; AV_ERROR_MAX_STRING_SIZE as usize]; 27] - = [[0i8; AV_ERROR_MAX_STRING_SIZE as usize]; 27]; +static mut STRINGS: [[i8; AV_ERROR_MAX_STRING_SIZE as usize]; 27] = + [[0i8; AV_ERROR_MAX_STRING_SIZE as usize]; 27]; pub fn register_all() { - unsafe { - av_strerror(Error::Bug.into(), STRINGS[index(&Error::Bug)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::Bug2.into(), STRINGS[index(&Error::Bug2)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::Unknown.into(), STRINGS[index(&Error::Unknown)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::Experimental.into(), STRINGS[index(&Error::Experimental)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::BufferTooSmall.into(), STRINGS[index(&Error::BufferTooSmall)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::Eof.into(), STRINGS[index(&Error::Eof)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::Exit.into(), STRINGS[index(&Error::Exit)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::External.into(), STRINGS[index(&Error::External)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::InvalidData.into(), STRINGS[index(&Error::InvalidData)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::PatchWelcome.into(), STRINGS[index(&Error::PatchWelcome)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); + unsafe { + av_strerror( + Error::Bug.into(), + STRINGS[index(&Error::Bug)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::Bug2.into(), + STRINGS[index(&Error::Bug2)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::Unknown.into(), + STRINGS[index(&Error::Unknown)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::Experimental.into(), + STRINGS[index(&Error::Experimental)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::BufferTooSmall.into(), + STRINGS[index(&Error::BufferTooSmall)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::Eof.into(), + STRINGS[index(&Error::Eof)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::Exit.into(), + STRINGS[index(&Error::Exit)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::External.into(), + STRINGS[index(&Error::External)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::InvalidData.into(), + STRINGS[index(&Error::InvalidData)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::PatchWelcome.into(), + STRINGS[index(&Error::PatchWelcome)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); - av_strerror(Error::InputChanged.into(), STRINGS[index(&Error::InputChanged)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::OutputChanged.into(), STRINGS[index(&Error::OutputChanged)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); + av_strerror( + Error::InputChanged.into(), + STRINGS[index(&Error::InputChanged)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::OutputChanged.into(), + STRINGS[index(&Error::OutputChanged)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); - av_strerror(Error::BsfNotFound.into(), STRINGS[index(&Error::BsfNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::DecoderNotFound.into(), STRINGS[index(&Error::DecoderNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::DemuxerNotFound.into(), STRINGS[index(&Error::DemuxerNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::EncoderNotFound.into(), STRINGS[index(&Error::EncoderNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::OptionNotFound.into(), STRINGS[index(&Error::OptionNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::MuxerNotFound.into(), STRINGS[index(&Error::MuxerNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::FilterNotFound.into(), STRINGS[index(&Error::FilterNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::ProtocolNotFound.into(), STRINGS[index(&Error::ProtocolNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::StreamNotFound.into(), STRINGS[index(&Error::StreamNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); + av_strerror( + Error::BsfNotFound.into(), + STRINGS[index(&Error::BsfNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::DecoderNotFound.into(), + STRINGS[index(&Error::DecoderNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::DemuxerNotFound.into(), + STRINGS[index(&Error::DemuxerNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::EncoderNotFound.into(), + STRINGS[index(&Error::EncoderNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::OptionNotFound.into(), + STRINGS[index(&Error::OptionNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::MuxerNotFound.into(), + STRINGS[index(&Error::MuxerNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::FilterNotFound.into(), + STRINGS[index(&Error::FilterNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::ProtocolNotFound.into(), + STRINGS[index(&Error::ProtocolNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::StreamNotFound.into(), + STRINGS[index(&Error::StreamNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); - av_strerror(Error::HttpBadRequest.into(), STRINGS[index(&Error::HttpBadRequest)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::HttpUnauthorized.into(), STRINGS[index(&Error::HttpUnauthorized)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::HttpForbidden.into(), STRINGS[index(&Error::HttpForbidden)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::HttpNotFound.into(), STRINGS[index(&Error::HttpNotFound)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::HttpOther4xx.into(), STRINGS[index(&Error::HttpOther4xx)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - av_strerror(Error::HttpServerError.into(), STRINGS[index(&Error::HttpServerError)].as_mut_ptr(), AV_ERROR_MAX_STRING_SIZE); - } + av_strerror( + Error::HttpBadRequest.into(), + STRINGS[index(&Error::HttpBadRequest)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::HttpUnauthorized.into(), + STRINGS[index(&Error::HttpUnauthorized)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::HttpForbidden.into(), + STRINGS[index(&Error::HttpForbidden)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::HttpNotFound.into(), + STRINGS[index(&Error::HttpNotFound)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::HttpOther4xx.into(), + STRINGS[index(&Error::HttpOther4xx)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + av_strerror( + Error::HttpServerError.into(), + STRINGS[index(&Error::HttpServerError)].as_mut_ptr(), + AV_ERROR_MAX_STRING_SIZE, + ); + } } impl error::Error for Error { - fn description(&self) -> &str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(STRINGS[index(self)].as_ptr()).to_bytes()) - } - } + fn description(&self) -> &str { + unsafe { from_utf8_unchecked(CStr::from_ptr(STRINGS[index(self)].as_ptr()).to_bytes()) } + } } diff --git a/src/util/format/pixel.rs b/src/util/format/pixel.rs index f90b6d6..c415f36 100644 --- a/src/util/format/pixel.rs +++ b/src/util/format/pixel.rs @@ -1,964 +1,956 @@ use std::error; use std::ffi::{CStr, CString, NulError}; use std::fmt; -use std::str::{FromStr, from_utf8_unchecked}; +use std::str::{from_utf8_unchecked, FromStr}; -use ffi::*; use ffi::AVPixelFormat::*; +use ffi::*; #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Pixel { - None, + None, - YUV420P, - YUYV422, - RGB24, - BGR24, - YUV422P, - YUV444P, - YUV410P, - YUV411P, - GRAY8, - MonoWhite, - MonoBlack, - PAL8, - YUVJ420P, - YUVJ422P, - YUVJ444P, - #[cfg(feature = "ff_api_xvmc")] - XVMC_MPEG2_MC, - #[cfg(feature = "ff_api_xvmc")] - XVMC_MPEG2_IDCT, - UYVY422, - UYYVYY411, - BGR8, - BGR4, - BGR4_BYTE, - RGB8, - RGB4, - RGB4_BYTE, - NV12, - NV21, + YUV420P, + YUYV422, + RGB24, + BGR24, + YUV422P, + YUV444P, + YUV410P, + YUV411P, + GRAY8, + MonoWhite, + MonoBlack, + PAL8, + YUVJ420P, + YUVJ422P, + YUVJ444P, + #[cfg(feature = "ff_api_xvmc")] + XVMC_MPEG2_MC, + #[cfg(feature = "ff_api_xvmc")] + XVMC_MPEG2_IDCT, + UYVY422, + UYYVYY411, + BGR8, + BGR4, + BGR4_BYTE, + RGB8, + RGB4, + RGB4_BYTE, + NV12, + NV21, - ARGB, - RGBA, - ABGR, - BGRA, + ARGB, + RGBA, + ABGR, + BGRA, - GRAY16BE, - GRAY16LE, - YUV440P, - YUVJ440P, - YUVA420P, - #[cfg(feature = "ff_api_vdpau")] - VDPAU_H264, - #[cfg(feature = "ff_api_vdpau")] - VDPAU_MPEG1, - #[cfg(feature = "ff_api_vdpau")] - VDPAU_MPEG2, - #[cfg(feature = "ff_api_vdpau")] - VDPAU_WMV3, - #[cfg(feature = "ff_api_vdpau")] - VDPAU_VC1, - RGB48BE, - RGB48LE, + GRAY16BE, + GRAY16LE, + YUV440P, + YUVJ440P, + YUVA420P, + #[cfg(feature = "ff_api_vdpau")] + VDPAU_H264, + #[cfg(feature = "ff_api_vdpau")] + VDPAU_MPEG1, + #[cfg(feature = "ff_api_vdpau")] + VDPAU_MPEG2, + #[cfg(feature = "ff_api_vdpau")] + VDPAU_WMV3, + #[cfg(feature = "ff_api_vdpau")] + VDPAU_VC1, + RGB48BE, + RGB48LE, - RGB565BE, - RGB565LE, - RGB555BE, - RGB555LE, + RGB565BE, + RGB565LE, + RGB555BE, + RGB555LE, - BGR565BE, - BGR565LE, - BGR555BE, - BGR555LE, + BGR565BE, + BGR565LE, + BGR555BE, + BGR555LE, - #[cfg(feature = "ff_api_vaapi")] - VAAPI_MOCO, - #[cfg(feature = "ff_api_vaapi")] - VAAPI_IDCT, - #[cfg(feature = "ff_api_vaapi")] - VAAPI_VLD, - #[cfg(not(feature = "ff_api_vaapi"))] - VAAPI, + #[cfg(feature = "ff_api_vaapi")] + VAAPI_MOCO, + #[cfg(feature = "ff_api_vaapi")] + VAAPI_IDCT, + #[cfg(feature = "ff_api_vaapi")] + VAAPI_VLD, + #[cfg(not(feature = "ff_api_vaapi"))] + VAAPI, - YUV420P16LE, - YUV420P16BE, - YUV422P16LE, - YUV422P16BE, - YUV444P16LE, - YUV444P16BE, - #[cfg(feature = "ff_api_vdpau")] - VDPAU_MPEG4, - DXVA2_VLD, + YUV420P16LE, + YUV420P16BE, + YUV422P16LE, + YUV422P16BE, + YUV444P16LE, + YUV444P16BE, + #[cfg(feature = "ff_api_vdpau")] + VDPAU_MPEG4, + DXVA2_VLD, - RGB444LE, - RGB444BE, - BGR444LE, - BGR444BE, - YA8, + RGB444LE, + RGB444BE, + BGR444LE, + BGR444BE, + YA8, - BGR48BE, - BGR48LE, + BGR48BE, + BGR48LE, - YUV420P9BE, - YUV420P9LE, - YUV420P10BE, - YUV420P10LE, - YUV422P10BE, - YUV422P10LE, - YUV444P9BE, - YUV444P9LE, - YUV444P10BE, - YUV444P10LE, - YUV422P9BE, - YUV422P9LE, - VDA_VLD, + YUV420P9BE, + YUV420P9LE, + YUV420P10BE, + YUV420P10LE, + YUV422P10BE, + YUV422P10LE, + YUV444P9BE, + YUV444P9LE, + YUV444P10BE, + YUV444P10LE, + YUV422P9BE, + YUV422P9LE, + VDA_VLD, - GBRP, - GBRP9BE, - GBRP9LE, - GBRP10BE, - GBRP10LE, - GBRP16BE, - GBRP16LE, + GBRP, + GBRP9BE, + GBRP9LE, + GBRP10BE, + GBRP10LE, + GBRP16BE, + GBRP16LE, - YUVA420P9BE, - YUVA420P9LE, - YUVA422P9BE, - YUVA422P9LE, - YUVA444P9BE, - YUVA444P9LE, - YUVA420P10BE, - YUVA420P10LE, - YUVA422P10BE, - YUVA422P10LE, - YUVA444P10BE, - YUVA444P10LE, - YUVA420P16BE, - YUVA420P16LE, - YUVA422P16BE, - YUVA422P16LE, - YUVA444P16BE, - YUVA444P16LE, + YUVA420P9BE, + YUVA420P9LE, + YUVA422P9BE, + YUVA422P9LE, + YUVA444P9BE, + YUVA444P9LE, + YUVA420P10BE, + YUVA420P10LE, + YUVA422P10BE, + YUVA422P10LE, + YUVA444P10BE, + YUVA444P10LE, + YUVA420P16BE, + YUVA420P16LE, + YUVA422P16BE, + YUVA422P16LE, + YUVA444P16BE, + YUVA444P16LE, - VDPAU, + VDPAU, - XYZ12LE, - XYZ12BE, - NV16, - NV20LE, - NV20BE, + XYZ12LE, + XYZ12BE, + NV16, + NV20LE, + NV20BE, - RGBA64BE, - RGBA64LE, - BGRA64BE, - BGRA64LE, + RGBA64BE, + RGBA64LE, + BGRA64BE, + BGRA64LE, - YVYU422, + YVYU422, - VDA, + VDA, - YA16BE, - YA16LE, + YA16BE, + YA16LE, - QSV, - MMAL, + QSV, + MMAL, - D3D11VA_VLD, + D3D11VA_VLD, - CUDA, + CUDA, - ZRGB, - RGBZ, - ZBGR, - BGRZ, - YUVA444P, - YUVA422P, + ZRGB, + RGBZ, + ZBGR, + BGRZ, + YUVA444P, + YUVA422P, - YUV420P12BE, - YUV420P12LE, - YUV420P14BE, - YUV420P14LE, - YUV422P12BE, - YUV422P12LE, - YUV422P14BE, - YUV422P14LE, - YUV444P12BE, - YUV444P12LE, - YUV444P14BE, - YUV444P14LE, - GBRP12BE, - GBRP12LE, - GBRP14BE, - GBRP14LE, - GBRAP, - GBRAP16BE, - GBRAP16LE, - YUVJ411P, + YUV420P12BE, + YUV420P12LE, + YUV420P14BE, + YUV420P14LE, + YUV422P12BE, + YUV422P12LE, + YUV422P14BE, + YUV422P14LE, + YUV444P12BE, + YUV444P12LE, + YUV444P14BE, + YUV444P14LE, + GBRP12BE, + GBRP12LE, + GBRP14BE, + GBRP14LE, + GBRAP, + GBRAP16BE, + GBRAP16LE, + YUVJ411P, - BAYER_BGGR8, - BAYER_RGGB8, - BAYER_GBRG8, - BAYER_GRBG8, - BAYER_BGGR16LE, - BAYER_BGGR16BE, - BAYER_RGGB16LE, - BAYER_RGGB16BE, - BAYER_GBRG16LE, - BAYER_GBRG16BE, - BAYER_GRBG16LE, - BAYER_GRBG16BE, + BAYER_BGGR8, + BAYER_RGGB8, + BAYER_GBRG8, + BAYER_GRBG8, + BAYER_BGGR16LE, + BAYER_BGGR16BE, + BAYER_RGGB16LE, + BAYER_RGGB16BE, + BAYER_GBRG16LE, + BAYER_GBRG16BE, + BAYER_GRBG16LE, + BAYER_GRBG16BE, - YUV440P10LE, - YUV440P10BE, - YUV440P12LE, - YUV440P12BE, - AYUV64LE, - AYUV64BE, + YUV440P10LE, + YUV440P10BE, + YUV440P12LE, + YUV440P12BE, + AYUV64LE, + AYUV64BE, - VIDEOTOOLBOX, + VIDEOTOOLBOX, - // --- defaults - #[cfg(feature = "ff_api_xvmc")] - XVMC, - Y400A, - GRAY8A, - GBR24P, + // --- defaults + #[cfg(feature = "ff_api_xvmc")] + XVMC, + Y400A, + GRAY8A, + GBR24P, - RGB32, - RGB32_1, - BGR32, - BGR32_1, - ZRGB32, - ZBGR32, + RGB32, + RGB32_1, + BGR32, + BGR32_1, + ZRGB32, + ZBGR32, - GRAY16, - YA16, - RGB48, - RGB565, - RGB555, - RGB444, - BGR48, - BGR565, - BGR555, - BGR444, + GRAY16, + YA16, + RGB48, + RGB565, + RGB555, + RGB444, + BGR48, + BGR565, + BGR555, + BGR444, - YUV420P9, - YUV422P9, - YUV444P9, - YUV420P10, - YUV422P10, - YUV440P10, - YUV444P10, - YUV420P12, - YUV422P12, - YUV440P12, - YUV444P12, - YUV420P14, - YUV422P14, - YUV444P14, - YUV420P16, - YUV422P16, - YUV444P16, + YUV420P9, + YUV422P9, + YUV444P9, + YUV420P10, + YUV422P10, + YUV440P10, + YUV444P10, + YUV420P12, + YUV422P12, + YUV440P12, + YUV444P12, + YUV420P14, + YUV422P14, + YUV444P14, + YUV420P16, + YUV422P16, + YUV444P16, - GBRP9, - GBRP10, - GBRP12, - GBRP14, - GBRP16, - GBRAP16, + GBRP9, + GBRP10, + GBRP12, + GBRP14, + GBRP16, + GBRAP16, - BAYER_BGGR16, - BAYER_RGGB16, - BAYER_GBRG16, - BAYER_GRBG16, + BAYER_BGGR16, + BAYER_RGGB16, + BAYER_GBRG16, + BAYER_GRBG16, - YUVA420P9, - YUVA422P9, - YUVA444P9, - YUVA420P10, - YUVA422P10, - YUVA444P10, - YUVA420P16, - YUVA422P16, - YUVA444P16, + YUVA420P9, + YUVA422P9, + YUVA444P9, + YUVA420P10, + YUVA422P10, + YUVA444P10, + YUVA420P16, + YUVA422P16, + YUVA444P16, - XYZ12, - NV20, - AYUV64, + XYZ12, + NV20, + AYUV64, - P010LE, - P010BE, - GBRAP12BE, - GBRAP12LE, - GBRAP10LE, - GBRAP10BE, - MEDIACODEC, - GRAY12BE, - GRAY12LE, - GRAY10BE, - GRAY10LE, - P016LE, - P016BE, + P010LE, + P010BE, + GBRAP12BE, + GBRAP12LE, + GBRAP10LE, + GBRAP10BE, + MEDIACODEC, + GRAY12BE, + GRAY12LE, + GRAY10BE, + GRAY10LE, + P016LE, + P016BE, - D3D11, - GRAY9BE, - GRAY9LE, - GBRPF32BE, - GBRPF32LE, - GBRAPF32BE, - GBRAPF32LE, - DRM_PRIME, + D3D11, + GRAY9BE, + GRAY9LE, + GBRPF32BE, + GBRPF32LE, + GBRAPF32BE, + GBRAPF32LE, + DRM_PRIME, } #[derive(Clone, Copy, PartialEq, Eq)] pub struct Descriptor { - ptr: *const AVPixFmtDescriptor, + ptr: *const AVPixFmtDescriptor, } unsafe impl Send for Descriptor {} unsafe impl Sync for Descriptor {} impl Pixel { - pub fn descriptor(self) -> Option { - unsafe { - let ptr = av_pix_fmt_desc_get(self.into()); + pub fn descriptor(self) -> Option { + unsafe { + let ptr = av_pix_fmt_desc_get(self.into()); - ptr.as_ref().map(|ptr| Descriptor { ptr }) - } - } + ptr.as_ref().map(|ptr| Descriptor { ptr }) + } + } } impl Descriptor { - pub fn as_ptr(self) -> *const AVPixFmtDescriptor { - self.ptr - } + pub fn as_ptr(self) -> *const AVPixFmtDescriptor { + self.ptr + } - pub fn name(self) -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) - } - } + pub fn name(self) -> &'static str { + unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) } + } - pub fn nb_components(self) -> u8 { - unsafe { - (*self.as_ptr()).nb_components - } - } + pub fn nb_components(self) -> u8 { + unsafe { (*self.as_ptr()).nb_components } + } - pub fn log2_chroma_w(self) -> u8 { - unsafe { - (*self.as_ptr()).log2_chroma_w - } - } + pub fn log2_chroma_w(self) -> u8 { + unsafe { (*self.as_ptr()).log2_chroma_w } + } - pub fn log2_chroma_h(self) -> u8 { - unsafe { - (*self.as_ptr()).log2_chroma_h - } - } + pub fn log2_chroma_h(self) -> u8 { + unsafe { (*self.as_ptr()).log2_chroma_h } + } } impl From for Pixel { - #[inline] - fn from(value: AVPixelFormat) -> Self { - match value { - AV_PIX_FMT_NONE => Pixel::None, + #[inline] + fn from(value: AVPixelFormat) -> Self { + match value { + AV_PIX_FMT_NONE => Pixel::None, - AV_PIX_FMT_YUV420P => Pixel::YUV420P, - AV_PIX_FMT_YUYV422 => Pixel::YUYV422, - AV_PIX_FMT_RGB24 => Pixel::RGB24, - AV_PIX_FMT_BGR24 => Pixel::BGR24, - AV_PIX_FMT_YUV422P => Pixel::YUV422P, - AV_PIX_FMT_YUV444P => Pixel::YUV444P, - AV_PIX_FMT_YUV410P => Pixel::YUV410P, - AV_PIX_FMT_YUV411P => Pixel::YUV411P, - AV_PIX_FMT_GRAY8 => Pixel::GRAY8, - AV_PIX_FMT_MONOWHITE => Pixel::MonoWhite, - AV_PIX_FMT_MONOBLACK => Pixel::MonoBlack, - AV_PIX_FMT_PAL8 => Pixel::PAL8, - AV_PIX_FMT_YUVJ420P => Pixel::YUVJ420P, - AV_PIX_FMT_YUVJ422P => Pixel::YUVJ422P, - AV_PIX_FMT_YUVJ444P => Pixel::YUVJ444P, - #[cfg(feature = "ff_api_xvmc")] - AV_PIX_FMT_XVMC_MPEG2_MC => Pixel::XVMC_MPEG2_MC, - #[cfg(feature = "ff_api_xvmc")] - AV_PIX_FMT_XVMC_MPEG2_IDCT => Pixel::XVMC_MPEG2_IDCT, - AV_PIX_FMT_UYVY422 => Pixel::UYVY422, - AV_PIX_FMT_UYYVYY411 => Pixel::UYYVYY411, - AV_PIX_FMT_BGR8 => Pixel::BGR8, - AV_PIX_FMT_BGR4 => Pixel::BGR4, - AV_PIX_FMT_BGR4_BYTE => Pixel::BGR4_BYTE, - AV_PIX_FMT_RGB8 => Pixel::RGB8, - AV_PIX_FMT_RGB4 => Pixel::RGB4, - AV_PIX_FMT_RGB4_BYTE => Pixel::RGB4_BYTE, - AV_PIX_FMT_NV12 => Pixel::NV12, - AV_PIX_FMT_NV21 => Pixel::NV21, + AV_PIX_FMT_YUV420P => Pixel::YUV420P, + AV_PIX_FMT_YUYV422 => Pixel::YUYV422, + AV_PIX_FMT_RGB24 => Pixel::RGB24, + AV_PIX_FMT_BGR24 => Pixel::BGR24, + AV_PIX_FMT_YUV422P => Pixel::YUV422P, + AV_PIX_FMT_YUV444P => Pixel::YUV444P, + AV_PIX_FMT_YUV410P => Pixel::YUV410P, + AV_PIX_FMT_YUV411P => Pixel::YUV411P, + AV_PIX_FMT_GRAY8 => Pixel::GRAY8, + AV_PIX_FMT_MONOWHITE => Pixel::MonoWhite, + AV_PIX_FMT_MONOBLACK => Pixel::MonoBlack, + AV_PIX_FMT_PAL8 => Pixel::PAL8, + AV_PIX_FMT_YUVJ420P => Pixel::YUVJ420P, + AV_PIX_FMT_YUVJ422P => Pixel::YUVJ422P, + AV_PIX_FMT_YUVJ444P => Pixel::YUVJ444P, + #[cfg(feature = "ff_api_xvmc")] + AV_PIX_FMT_XVMC_MPEG2_MC => Pixel::XVMC_MPEG2_MC, + #[cfg(feature = "ff_api_xvmc")] + AV_PIX_FMT_XVMC_MPEG2_IDCT => Pixel::XVMC_MPEG2_IDCT, + AV_PIX_FMT_UYVY422 => Pixel::UYVY422, + AV_PIX_FMT_UYYVYY411 => Pixel::UYYVYY411, + AV_PIX_FMT_BGR8 => Pixel::BGR8, + AV_PIX_FMT_BGR4 => Pixel::BGR4, + AV_PIX_FMT_BGR4_BYTE => Pixel::BGR4_BYTE, + AV_PIX_FMT_RGB8 => Pixel::RGB8, + AV_PIX_FMT_RGB4 => Pixel::RGB4, + AV_PIX_FMT_RGB4_BYTE => Pixel::RGB4_BYTE, + AV_PIX_FMT_NV12 => Pixel::NV12, + AV_PIX_FMT_NV21 => Pixel::NV21, - AV_PIX_FMT_ARGB => Pixel::ARGB, - AV_PIX_FMT_RGBA => Pixel::RGBA, - AV_PIX_FMT_ABGR => Pixel::ABGR, - AV_PIX_FMT_BGRA => Pixel::BGRA, + AV_PIX_FMT_ARGB => Pixel::ARGB, + AV_PIX_FMT_RGBA => Pixel::RGBA, + AV_PIX_FMT_ABGR => Pixel::ABGR, + AV_PIX_FMT_BGRA => Pixel::BGRA, - AV_PIX_FMT_GRAY16BE => Pixel::GRAY16BE, - AV_PIX_FMT_GRAY16LE => Pixel::GRAY16LE, - AV_PIX_FMT_YUV440P => Pixel::YUV440P, - AV_PIX_FMT_YUVJ440P => Pixel::YUVJ440P, - AV_PIX_FMT_YUVA420P => Pixel::YUVA420P, - #[cfg(feature = "ff_api_vdpau")] - AV_PIX_FMT_VDPAU_H264 => Pixel::VDPAU_H264, - #[cfg(feature = "ff_api_vdpau")] - AV_PIX_FMT_VDPAU_MPEG1 => Pixel::VDPAU_MPEG1, - #[cfg(feature = "ff_api_vdpau")] - AV_PIX_FMT_VDPAU_MPEG2 => Pixel::VDPAU_MPEG2, - #[cfg(feature = "ff_api_vdpau")] - AV_PIX_FMT_VDPAU_WMV3 => Pixel::VDPAU_WMV3, - #[cfg(feature = "ff_api_vdpau")] - AV_PIX_FMT_VDPAU_VC1 => Pixel::VDPAU_VC1, - AV_PIX_FMT_RGB48BE => Pixel::RGB48BE, - AV_PIX_FMT_RGB48LE => Pixel::RGB48LE, + AV_PIX_FMT_GRAY16BE => Pixel::GRAY16BE, + AV_PIX_FMT_GRAY16LE => Pixel::GRAY16LE, + AV_PIX_FMT_YUV440P => Pixel::YUV440P, + AV_PIX_FMT_YUVJ440P => Pixel::YUVJ440P, + AV_PIX_FMT_YUVA420P => Pixel::YUVA420P, + #[cfg(feature = "ff_api_vdpau")] + AV_PIX_FMT_VDPAU_H264 => Pixel::VDPAU_H264, + #[cfg(feature = "ff_api_vdpau")] + AV_PIX_FMT_VDPAU_MPEG1 => Pixel::VDPAU_MPEG1, + #[cfg(feature = "ff_api_vdpau")] + AV_PIX_FMT_VDPAU_MPEG2 => Pixel::VDPAU_MPEG2, + #[cfg(feature = "ff_api_vdpau")] + AV_PIX_FMT_VDPAU_WMV3 => Pixel::VDPAU_WMV3, + #[cfg(feature = "ff_api_vdpau")] + AV_PIX_FMT_VDPAU_VC1 => Pixel::VDPAU_VC1, + AV_PIX_FMT_RGB48BE => Pixel::RGB48BE, + AV_PIX_FMT_RGB48LE => Pixel::RGB48LE, - AV_PIX_FMT_RGB565BE => Pixel::RGB565BE, - AV_PIX_FMT_RGB565LE => Pixel::RGB565LE, - AV_PIX_FMT_RGB555BE => Pixel::RGB555BE, - AV_PIX_FMT_RGB555LE => Pixel::RGB555LE, + AV_PIX_FMT_RGB565BE => Pixel::RGB565BE, + AV_PIX_FMT_RGB565LE => Pixel::RGB565LE, + AV_PIX_FMT_RGB555BE => Pixel::RGB555BE, + AV_PIX_FMT_RGB555LE => Pixel::RGB555LE, - AV_PIX_FMT_BGR565BE => Pixel::BGR565BE, - AV_PIX_FMT_BGR565LE => Pixel::BGR565LE, - AV_PIX_FMT_BGR555BE => Pixel::BGR555BE, - AV_PIX_FMT_BGR555LE => Pixel::BGR555LE, + AV_PIX_FMT_BGR565BE => Pixel::BGR565BE, + AV_PIX_FMT_BGR565LE => Pixel::BGR565LE, + AV_PIX_FMT_BGR555BE => Pixel::BGR555BE, + AV_PIX_FMT_BGR555LE => Pixel::BGR555LE, - #[cfg(feature = "ff_api_vaapi")] - AV_PIX_FMT_VAAPI_MOCO => Pixel::VAAPI_MOCO, - #[cfg(feature = "ff_api_vaapi")] - AV_PIX_FMT_VAAPI_IDCT => Pixel::VAAPI_IDCT, - #[cfg(feature = "ff_api_vaapi")] - AV_PIX_FMT_VAAPI_VLD => Pixel::VAAPI_VLD, + #[cfg(feature = "ff_api_vaapi")] + AV_PIX_FMT_VAAPI_MOCO => Pixel::VAAPI_MOCO, + #[cfg(feature = "ff_api_vaapi")] + AV_PIX_FMT_VAAPI_IDCT => Pixel::VAAPI_IDCT, + #[cfg(feature = "ff_api_vaapi")] + AV_PIX_FMT_VAAPI_VLD => Pixel::VAAPI_VLD, - AV_PIX_FMT_YUV420P16LE => Pixel::YUV420P16LE, - AV_PIX_FMT_YUV420P16BE => Pixel::YUV420P16BE, - AV_PIX_FMT_YUV422P16LE => Pixel::YUV422P16LE, - AV_PIX_FMT_YUV422P16BE => Pixel::YUV422P16BE, - AV_PIX_FMT_YUV444P16LE => Pixel::YUV444P16LE, - AV_PIX_FMT_YUV444P16BE => Pixel::YUV444P16BE, - #[cfg(feature = "ff_api_vdpau")] - AV_PIX_FMT_VDPAU_MPEG4 => Pixel::VDPAU_MPEG4, - AV_PIX_FMT_DXVA2_VLD => Pixel::DXVA2_VLD, + AV_PIX_FMT_YUV420P16LE => Pixel::YUV420P16LE, + AV_PIX_FMT_YUV420P16BE => Pixel::YUV420P16BE, + AV_PIX_FMT_YUV422P16LE => Pixel::YUV422P16LE, + AV_PIX_FMT_YUV422P16BE => Pixel::YUV422P16BE, + AV_PIX_FMT_YUV444P16LE => Pixel::YUV444P16LE, + AV_PIX_FMT_YUV444P16BE => Pixel::YUV444P16BE, + #[cfg(feature = "ff_api_vdpau")] + AV_PIX_FMT_VDPAU_MPEG4 => Pixel::VDPAU_MPEG4, + AV_PIX_FMT_DXVA2_VLD => Pixel::DXVA2_VLD, - AV_PIX_FMT_RGB444LE => Pixel::RGB444LE, - AV_PIX_FMT_RGB444BE => Pixel::RGB444BE, - AV_PIX_FMT_BGR444LE => Pixel::BGR444LE, - AV_PIX_FMT_BGR444BE => Pixel::BGR444BE, - AV_PIX_FMT_YA8 => Pixel::YA8, + AV_PIX_FMT_RGB444LE => Pixel::RGB444LE, + AV_PIX_FMT_RGB444BE => Pixel::RGB444BE, + AV_PIX_FMT_BGR444LE => Pixel::BGR444LE, + AV_PIX_FMT_BGR444BE => Pixel::BGR444BE, + AV_PIX_FMT_YA8 => Pixel::YA8, - AV_PIX_FMT_BGR48BE => Pixel::BGR48BE, - AV_PIX_FMT_BGR48LE => Pixel::BGR48LE, + AV_PIX_FMT_BGR48BE => Pixel::BGR48BE, + AV_PIX_FMT_BGR48LE => Pixel::BGR48LE, - AV_PIX_FMT_YUV420P9BE => Pixel::YUV420P9BE, - AV_PIX_FMT_YUV420P9LE => Pixel::YUV420P9LE, - AV_PIX_FMT_YUV420P10BE => Pixel::YUV420P10BE, - AV_PIX_FMT_YUV420P10LE => Pixel::YUV420P10LE, - AV_PIX_FMT_YUV422P10BE => Pixel::YUV422P10BE, - AV_PIX_FMT_YUV422P10LE => Pixel::YUV422P10LE, - AV_PIX_FMT_YUV444P9BE => Pixel::YUV444P9BE, - AV_PIX_FMT_YUV444P9LE => Pixel::YUV444P9LE, - AV_PIX_FMT_YUV444P10BE => Pixel::YUV444P10BE, - AV_PIX_FMT_YUV444P10LE => Pixel::YUV444P10LE, - AV_PIX_FMT_YUV422P9BE => Pixel::YUV422P9BE, - AV_PIX_FMT_YUV422P9LE => Pixel::YUV422P9LE, - AV_PIX_FMT_VDA_VLD => Pixel::VDA_VLD, + AV_PIX_FMT_YUV420P9BE => Pixel::YUV420P9BE, + AV_PIX_FMT_YUV420P9LE => Pixel::YUV420P9LE, + AV_PIX_FMT_YUV420P10BE => Pixel::YUV420P10BE, + AV_PIX_FMT_YUV420P10LE => Pixel::YUV420P10LE, + AV_PIX_FMT_YUV422P10BE => Pixel::YUV422P10BE, + AV_PIX_FMT_YUV422P10LE => Pixel::YUV422P10LE, + AV_PIX_FMT_YUV444P9BE => Pixel::YUV444P9BE, + AV_PIX_FMT_YUV444P9LE => Pixel::YUV444P9LE, + AV_PIX_FMT_YUV444P10BE => Pixel::YUV444P10BE, + AV_PIX_FMT_YUV444P10LE => Pixel::YUV444P10LE, + AV_PIX_FMT_YUV422P9BE => Pixel::YUV422P9BE, + AV_PIX_FMT_YUV422P9LE => Pixel::YUV422P9LE, + AV_PIX_FMT_VDA_VLD => Pixel::VDA_VLD, - AV_PIX_FMT_GBRP => Pixel::GBRP, - AV_PIX_FMT_GBRP9BE => Pixel::GBRP9BE, - AV_PIX_FMT_GBRP9LE => Pixel::GBRP9LE, - AV_PIX_FMT_GBRP10BE => Pixel::GBRP10BE, - AV_PIX_FMT_GBRP10LE => Pixel::GBRP10LE, - AV_PIX_FMT_GBRP16BE => Pixel::GBRP16BE, - AV_PIX_FMT_GBRP16LE => Pixel::GBRP16LE, + AV_PIX_FMT_GBRP => Pixel::GBRP, + AV_PIX_FMT_GBRP9BE => Pixel::GBRP9BE, + AV_PIX_FMT_GBRP9LE => Pixel::GBRP9LE, + AV_PIX_FMT_GBRP10BE => Pixel::GBRP10BE, + AV_PIX_FMT_GBRP10LE => Pixel::GBRP10LE, + AV_PIX_FMT_GBRP16BE => Pixel::GBRP16BE, + AV_PIX_FMT_GBRP16LE => Pixel::GBRP16LE, - AV_PIX_FMT_YUVA420P9BE => Pixel::YUVA420P9BE, - AV_PIX_FMT_YUVA420P9LE => Pixel::YUVA420P9LE, - AV_PIX_FMT_YUVA422P9BE => Pixel::YUVA422P9BE, - AV_PIX_FMT_YUVA422P9LE => Pixel::YUVA422P9LE, - AV_PIX_FMT_YUVA444P9BE => Pixel::YUVA444P9BE, - AV_PIX_FMT_YUVA444P9LE => Pixel::YUVA444P9LE, - AV_PIX_FMT_YUVA420P10BE => Pixel::YUVA420P10BE, - AV_PIX_FMT_YUVA420P10LE => Pixel::YUVA420P10LE, - AV_PIX_FMT_YUVA422P10BE => Pixel::YUVA422P10BE, - AV_PIX_FMT_YUVA422P10LE => Pixel::YUVA422P10LE, - AV_PIX_FMT_YUVA444P10BE => Pixel::YUVA444P10BE, - AV_PIX_FMT_YUVA444P10LE => Pixel::YUVA444P10LE, - AV_PIX_FMT_YUVA420P16BE => Pixel::YUVA420P16BE, - AV_PIX_FMT_YUVA420P16LE => Pixel::YUVA420P16LE, - AV_PIX_FMT_YUVA422P16BE => Pixel::YUVA422P16BE, - AV_PIX_FMT_YUVA422P16LE => Pixel::YUVA422P16LE, - AV_PIX_FMT_YUVA444P16BE => Pixel::YUVA444P16BE, - AV_PIX_FMT_YUVA444P16LE => Pixel::YUVA444P16LE, + AV_PIX_FMT_YUVA420P9BE => Pixel::YUVA420P9BE, + AV_PIX_FMT_YUVA420P9LE => Pixel::YUVA420P9LE, + AV_PIX_FMT_YUVA422P9BE => Pixel::YUVA422P9BE, + AV_PIX_FMT_YUVA422P9LE => Pixel::YUVA422P9LE, + AV_PIX_FMT_YUVA444P9BE => Pixel::YUVA444P9BE, + AV_PIX_FMT_YUVA444P9LE => Pixel::YUVA444P9LE, + AV_PIX_FMT_YUVA420P10BE => Pixel::YUVA420P10BE, + AV_PIX_FMT_YUVA420P10LE => Pixel::YUVA420P10LE, + AV_PIX_FMT_YUVA422P10BE => Pixel::YUVA422P10BE, + AV_PIX_FMT_YUVA422P10LE => Pixel::YUVA422P10LE, + AV_PIX_FMT_YUVA444P10BE => Pixel::YUVA444P10BE, + AV_PIX_FMT_YUVA444P10LE => Pixel::YUVA444P10LE, + AV_PIX_FMT_YUVA420P16BE => Pixel::YUVA420P16BE, + AV_PIX_FMT_YUVA420P16LE => Pixel::YUVA420P16LE, + AV_PIX_FMT_YUVA422P16BE => Pixel::YUVA422P16BE, + AV_PIX_FMT_YUVA422P16LE => Pixel::YUVA422P16LE, + AV_PIX_FMT_YUVA444P16BE => Pixel::YUVA444P16BE, + AV_PIX_FMT_YUVA444P16LE => Pixel::YUVA444P16LE, - AV_PIX_FMT_VDPAU => Pixel::VDPAU, + AV_PIX_FMT_VDPAU => Pixel::VDPAU, - AV_PIX_FMT_XYZ12LE => Pixel::XYZ12LE, - AV_PIX_FMT_XYZ12BE => Pixel::XYZ12BE, - AV_PIX_FMT_NV16 => Pixel::NV16, - AV_PIX_FMT_NV20LE => Pixel::NV20LE, - AV_PIX_FMT_NV20BE => Pixel::NV20BE, + AV_PIX_FMT_XYZ12LE => Pixel::XYZ12LE, + AV_PIX_FMT_XYZ12BE => Pixel::XYZ12BE, + AV_PIX_FMT_NV16 => Pixel::NV16, + AV_PIX_FMT_NV20LE => Pixel::NV20LE, + AV_PIX_FMT_NV20BE => Pixel::NV20BE, - AV_PIX_FMT_RGBA64BE => Pixel::RGBA64BE, - AV_PIX_FMT_RGBA64LE => Pixel::RGBA64LE, - AV_PIX_FMT_BGRA64BE => Pixel::BGRA64BE, - AV_PIX_FMT_BGRA64LE => Pixel::BGRA64LE, + AV_PIX_FMT_RGBA64BE => Pixel::RGBA64BE, + AV_PIX_FMT_RGBA64LE => Pixel::RGBA64LE, + AV_PIX_FMT_BGRA64BE => Pixel::BGRA64BE, + AV_PIX_FMT_BGRA64LE => Pixel::BGRA64LE, - AV_PIX_FMT_YVYU422 => Pixel::YVYU422, + AV_PIX_FMT_YVYU422 => Pixel::YVYU422, - AV_PIX_FMT_VDA => Pixel::VDA, + AV_PIX_FMT_VDA => Pixel::VDA, - AV_PIX_FMT_YA16BE => Pixel::YA16BE, - AV_PIX_FMT_YA16LE => Pixel::YA16LE, + AV_PIX_FMT_YA16BE => Pixel::YA16BE, + AV_PIX_FMT_YA16LE => Pixel::YA16LE, - AV_PIX_FMT_QSV => Pixel::QSV, - AV_PIX_FMT_MMAL => Pixel::MMAL, + AV_PIX_FMT_QSV => Pixel::QSV, + AV_PIX_FMT_MMAL => Pixel::MMAL, - AV_PIX_FMT_D3D11VA_VLD => Pixel::D3D11VA_VLD, + AV_PIX_FMT_D3D11VA_VLD => Pixel::D3D11VA_VLD, - AV_PIX_FMT_CUDA => Pixel::CUDA, + AV_PIX_FMT_CUDA => Pixel::CUDA, - AV_PIX_FMT_0RGB => Pixel::ZRGB, - AV_PIX_FMT_RGB0 => Pixel::RGBZ, - AV_PIX_FMT_0BGR => Pixel::ZBGR, - AV_PIX_FMT_BGR0 => Pixel::BGRZ, - AV_PIX_FMT_YUVA444P => Pixel::YUVA444P, - AV_PIX_FMT_YUVA422P => Pixel::YUVA422P, + AV_PIX_FMT_0RGB => Pixel::ZRGB, + AV_PIX_FMT_RGB0 => Pixel::RGBZ, + AV_PIX_FMT_0BGR => Pixel::ZBGR, + AV_PIX_FMT_BGR0 => Pixel::BGRZ, + AV_PIX_FMT_YUVA444P => Pixel::YUVA444P, + AV_PIX_FMT_YUVA422P => Pixel::YUVA422P, - AV_PIX_FMT_YUV420P12BE => Pixel::YUV420P12BE, - AV_PIX_FMT_YUV420P12LE => Pixel::YUV420P12LE, - AV_PIX_FMT_YUV420P14BE => Pixel::YUV420P14BE, - AV_PIX_FMT_YUV420P14LE => Pixel::YUV420P14LE, - AV_PIX_FMT_YUV422P12BE => Pixel::YUV422P12BE, - AV_PIX_FMT_YUV422P12LE => Pixel::YUV422P12LE, - AV_PIX_FMT_YUV422P14BE => Pixel::YUV422P14BE, - AV_PIX_FMT_YUV422P14LE => Pixel::YUV422P14LE, - AV_PIX_FMT_YUV444P12BE => Pixel::YUV444P12BE, - AV_PIX_FMT_YUV444P12LE => Pixel::YUV444P12LE, - AV_PIX_FMT_YUV444P14BE => Pixel::YUV444P14BE, - AV_PIX_FMT_YUV444P14LE => Pixel::YUV444P14LE, - AV_PIX_FMT_GBRP12BE => Pixel::GBRP12BE, - AV_PIX_FMT_GBRP12LE => Pixel::GBRP12LE, - AV_PIX_FMT_GBRP14BE => Pixel::GBRP14BE, - AV_PIX_FMT_GBRP14LE => Pixel::GBRP14LE, - AV_PIX_FMT_GBRAP => Pixel::GBRAP, - AV_PIX_FMT_GBRAP16BE => Pixel::GBRAP16BE, - AV_PIX_FMT_GBRAP16LE => Pixel::GBRAP16LE, - AV_PIX_FMT_YUVJ411P => Pixel::YUVJ411P, + AV_PIX_FMT_YUV420P12BE => Pixel::YUV420P12BE, + AV_PIX_FMT_YUV420P12LE => Pixel::YUV420P12LE, + AV_PIX_FMT_YUV420P14BE => Pixel::YUV420P14BE, + AV_PIX_FMT_YUV420P14LE => Pixel::YUV420P14LE, + AV_PIX_FMT_YUV422P12BE => Pixel::YUV422P12BE, + AV_PIX_FMT_YUV422P12LE => Pixel::YUV422P12LE, + AV_PIX_FMT_YUV422P14BE => Pixel::YUV422P14BE, + AV_PIX_FMT_YUV422P14LE => Pixel::YUV422P14LE, + AV_PIX_FMT_YUV444P12BE => Pixel::YUV444P12BE, + AV_PIX_FMT_YUV444P12LE => Pixel::YUV444P12LE, + AV_PIX_FMT_YUV444P14BE => Pixel::YUV444P14BE, + AV_PIX_FMT_YUV444P14LE => Pixel::YUV444P14LE, + AV_PIX_FMT_GBRP12BE => Pixel::GBRP12BE, + AV_PIX_FMT_GBRP12LE => Pixel::GBRP12LE, + AV_PIX_FMT_GBRP14BE => Pixel::GBRP14BE, + AV_PIX_FMT_GBRP14LE => Pixel::GBRP14LE, + AV_PIX_FMT_GBRAP => Pixel::GBRAP, + AV_PIX_FMT_GBRAP16BE => Pixel::GBRAP16BE, + AV_PIX_FMT_GBRAP16LE => Pixel::GBRAP16LE, + AV_PIX_FMT_YUVJ411P => Pixel::YUVJ411P, - AV_PIX_FMT_BAYER_BGGR8 => Pixel::BAYER_BGGR8, - AV_PIX_FMT_BAYER_RGGB8 => Pixel::BAYER_RGGB8, - AV_PIX_FMT_BAYER_GBRG8 => Pixel::BAYER_GBRG8, - AV_PIX_FMT_BAYER_GRBG8 => Pixel::BAYER_GRBG8, - AV_PIX_FMT_BAYER_BGGR16LE => Pixel::BAYER_BGGR16LE, - AV_PIX_FMT_BAYER_BGGR16BE => Pixel::BAYER_BGGR16BE, - AV_PIX_FMT_BAYER_RGGB16LE => Pixel::BAYER_RGGB16LE, - AV_PIX_FMT_BAYER_RGGB16BE => Pixel::BAYER_RGGB16BE, - AV_PIX_FMT_BAYER_GBRG16LE => Pixel::BAYER_GBRG16LE, - AV_PIX_FMT_BAYER_GBRG16BE => Pixel::BAYER_GBRG16BE, - AV_PIX_FMT_BAYER_GRBG16LE => Pixel::BAYER_GRBG16LE, - AV_PIX_FMT_BAYER_GRBG16BE => Pixel::BAYER_GRBG16BE, + AV_PIX_FMT_BAYER_BGGR8 => Pixel::BAYER_BGGR8, + AV_PIX_FMT_BAYER_RGGB8 => Pixel::BAYER_RGGB8, + AV_PIX_FMT_BAYER_GBRG8 => Pixel::BAYER_GBRG8, + AV_PIX_FMT_BAYER_GRBG8 => Pixel::BAYER_GRBG8, + AV_PIX_FMT_BAYER_BGGR16LE => Pixel::BAYER_BGGR16LE, + AV_PIX_FMT_BAYER_BGGR16BE => Pixel::BAYER_BGGR16BE, + AV_PIX_FMT_BAYER_RGGB16LE => Pixel::BAYER_RGGB16LE, + AV_PIX_FMT_BAYER_RGGB16BE => Pixel::BAYER_RGGB16BE, + AV_PIX_FMT_BAYER_GBRG16LE => Pixel::BAYER_GBRG16LE, + AV_PIX_FMT_BAYER_GBRG16BE => Pixel::BAYER_GBRG16BE, + AV_PIX_FMT_BAYER_GRBG16LE => Pixel::BAYER_GRBG16LE, + AV_PIX_FMT_BAYER_GRBG16BE => Pixel::BAYER_GRBG16BE, - AV_PIX_FMT_YUV440P10LE => Pixel::YUV440P10LE, - AV_PIX_FMT_YUV440P10BE => Pixel::YUV440P10BE, - AV_PIX_FMT_YUV440P12LE => Pixel::YUV440P12LE, - AV_PIX_FMT_YUV440P12BE => Pixel::YUV440P12BE, - AV_PIX_FMT_AYUV64LE => Pixel::AYUV64LE, - AV_PIX_FMT_AYUV64BE => Pixel::AYUV64BE, + AV_PIX_FMT_YUV440P10LE => Pixel::YUV440P10LE, + AV_PIX_FMT_YUV440P10BE => Pixel::YUV440P10BE, + AV_PIX_FMT_YUV440P12LE => Pixel::YUV440P12LE, + AV_PIX_FMT_YUV440P12BE => Pixel::YUV440P12BE, + AV_PIX_FMT_AYUV64LE => Pixel::AYUV64LE, + AV_PIX_FMT_AYUV64BE => Pixel::AYUV64BE, - AV_PIX_FMT_VIDEOTOOLBOX => Pixel::VIDEOTOOLBOX, + AV_PIX_FMT_VIDEOTOOLBOX => Pixel::VIDEOTOOLBOX, - AV_PIX_FMT_P010LE => Pixel::P010LE, - AV_PIX_FMT_P010BE => Pixel::P010BE, - AV_PIX_FMT_GBRAP12BE => Pixel::GBRAP12BE, - AV_PIX_FMT_GBRAP12LE => Pixel::GBRAP12LE, - AV_PIX_FMT_GBRAP10LE => Pixel::GBRAP10LE, - AV_PIX_FMT_GBRAP10BE => Pixel::GBRAP10BE, - AV_PIX_FMT_MEDIACODEC => Pixel::MEDIACODEC, - AV_PIX_FMT_GRAY12BE => Pixel::GRAY12BE, - AV_PIX_FMT_GRAY12LE => Pixel::GRAY12LE, - AV_PIX_FMT_GRAY10BE => Pixel::GRAY10BE, - AV_PIX_FMT_GRAY10LE => Pixel::GRAY10LE, - AV_PIX_FMT_P016LE => Pixel::P016LE, - AV_PIX_FMT_P016BE => Pixel::P016BE, + AV_PIX_FMT_P010LE => Pixel::P010LE, + AV_PIX_FMT_P010BE => Pixel::P010BE, + AV_PIX_FMT_GBRAP12BE => Pixel::GBRAP12BE, + AV_PIX_FMT_GBRAP12LE => Pixel::GBRAP12LE, + AV_PIX_FMT_GBRAP10LE => Pixel::GBRAP10LE, + AV_PIX_FMT_GBRAP10BE => Pixel::GBRAP10BE, + AV_PIX_FMT_MEDIACODEC => Pixel::MEDIACODEC, + AV_PIX_FMT_GRAY12BE => Pixel::GRAY12BE, + AV_PIX_FMT_GRAY12LE => Pixel::GRAY12LE, + AV_PIX_FMT_GRAY10BE => Pixel::GRAY10BE, + AV_PIX_FMT_GRAY10LE => Pixel::GRAY10LE, + AV_PIX_FMT_P016LE => Pixel::P016LE, + AV_PIX_FMT_P016BE => Pixel::P016BE, - AV_PIX_FMT_NB => Pixel::None, + AV_PIX_FMT_NB => Pixel::None, - AV_PIX_FMT_D3D11 => Pixel::D3D11, - AV_PIX_FMT_GRAY9BE => Pixel::GRAY9BE, - AV_PIX_FMT_GRAY9LE => Pixel::GRAY9LE, - AV_PIX_FMT_GBRPF32BE => Pixel::GBRPF32BE, - AV_PIX_FMT_GBRPF32LE => Pixel::GBRPF32LE, - AV_PIX_FMT_GBRAPF32BE => Pixel::GBRAPF32BE, - AV_PIX_FMT_GBRAPF32LE => Pixel::GBRAPF32LE, - AV_PIX_FMT_DRM_PRIME => Pixel::DRM_PRIME, - } - } + AV_PIX_FMT_D3D11 => Pixel::D3D11, + AV_PIX_FMT_GRAY9BE => Pixel::GRAY9BE, + AV_PIX_FMT_GRAY9LE => Pixel::GRAY9LE, + AV_PIX_FMT_GBRPF32BE => Pixel::GBRPF32BE, + AV_PIX_FMT_GBRPF32LE => Pixel::GBRPF32LE, + AV_PIX_FMT_GBRAPF32BE => Pixel::GBRAPF32BE, + AV_PIX_FMT_GBRAPF32LE => Pixel::GBRAPF32LE, + AV_PIX_FMT_DRM_PRIME => Pixel::DRM_PRIME, + } + } } impl Into for Pixel { - #[inline] - fn into(self) -> AVPixelFormat { - match self { - Pixel::None => AV_PIX_FMT_NONE, + #[inline] + fn into(self) -> AVPixelFormat { + match self { + Pixel::None => AV_PIX_FMT_NONE, - Pixel::YUV420P => AV_PIX_FMT_YUV420P, - Pixel::YUYV422 => AV_PIX_FMT_YUYV422, - Pixel::RGB24 => AV_PIX_FMT_RGB24, - Pixel::BGR24 => AV_PIX_FMT_BGR24, - Pixel::YUV422P => AV_PIX_FMT_YUV422P, - Pixel::YUV444P => AV_PIX_FMT_YUV444P, - Pixel::YUV410P => AV_PIX_FMT_YUV410P, - Pixel::YUV411P => AV_PIX_FMT_YUV411P, - Pixel::GRAY8 => AV_PIX_FMT_GRAY8, - Pixel::MonoWhite => AV_PIX_FMT_MONOWHITE, - Pixel::MonoBlack => AV_PIX_FMT_MONOBLACK, - Pixel::PAL8 => AV_PIX_FMT_PAL8, - Pixel::YUVJ420P => AV_PIX_FMT_YUVJ420P, - Pixel::YUVJ422P => AV_PIX_FMT_YUVJ422P, - Pixel::YUVJ444P => AV_PIX_FMT_YUVJ444P, - #[cfg(feature = "ff_api_xvmc")] - Pixel::XVMC_MPEG2_MC => AV_PIX_FMT_XVMC_MPEG2_MC, - #[cfg(feature = "ff_api_xvmc")] - Pixel::XVMC_MPEG2_IDCT => AV_PIX_FMT_XVMC_MPEG2_IDCT, - Pixel::UYVY422 => AV_PIX_FMT_UYVY422, - Pixel::UYYVYY411 => AV_PIX_FMT_UYYVYY411, - Pixel::BGR8 => AV_PIX_FMT_BGR8, - Pixel::BGR4 => AV_PIX_FMT_BGR4, - Pixel::BGR4_BYTE => AV_PIX_FMT_BGR4_BYTE, - Pixel::RGB8 => AV_PIX_FMT_RGB8, - Pixel::RGB4 => AV_PIX_FMT_RGB4, - Pixel::RGB4_BYTE => AV_PIX_FMT_RGB4_BYTE, - Pixel::NV12 => AV_PIX_FMT_NV12, - Pixel::NV21 => AV_PIX_FMT_NV21, + Pixel::YUV420P => AV_PIX_FMT_YUV420P, + Pixel::YUYV422 => AV_PIX_FMT_YUYV422, + Pixel::RGB24 => AV_PIX_FMT_RGB24, + Pixel::BGR24 => AV_PIX_FMT_BGR24, + Pixel::YUV422P => AV_PIX_FMT_YUV422P, + Pixel::YUV444P => AV_PIX_FMT_YUV444P, + Pixel::YUV410P => AV_PIX_FMT_YUV410P, + Pixel::YUV411P => AV_PIX_FMT_YUV411P, + Pixel::GRAY8 => AV_PIX_FMT_GRAY8, + Pixel::MonoWhite => AV_PIX_FMT_MONOWHITE, + Pixel::MonoBlack => AV_PIX_FMT_MONOBLACK, + Pixel::PAL8 => AV_PIX_FMT_PAL8, + Pixel::YUVJ420P => AV_PIX_FMT_YUVJ420P, + Pixel::YUVJ422P => AV_PIX_FMT_YUVJ422P, + Pixel::YUVJ444P => AV_PIX_FMT_YUVJ444P, + #[cfg(feature = "ff_api_xvmc")] + Pixel::XVMC_MPEG2_MC => AV_PIX_FMT_XVMC_MPEG2_MC, + #[cfg(feature = "ff_api_xvmc")] + Pixel::XVMC_MPEG2_IDCT => AV_PIX_FMT_XVMC_MPEG2_IDCT, + Pixel::UYVY422 => AV_PIX_FMT_UYVY422, + Pixel::UYYVYY411 => AV_PIX_FMT_UYYVYY411, + Pixel::BGR8 => AV_PIX_FMT_BGR8, + Pixel::BGR4 => AV_PIX_FMT_BGR4, + Pixel::BGR4_BYTE => AV_PIX_FMT_BGR4_BYTE, + Pixel::RGB8 => AV_PIX_FMT_RGB8, + Pixel::RGB4 => AV_PIX_FMT_RGB4, + Pixel::RGB4_BYTE => AV_PIX_FMT_RGB4_BYTE, + Pixel::NV12 => AV_PIX_FMT_NV12, + Pixel::NV21 => AV_PIX_FMT_NV21, - Pixel::ARGB => AV_PIX_FMT_ARGB, - Pixel::RGBA => AV_PIX_FMT_RGBA, - Pixel::ABGR => AV_PIX_FMT_ABGR, - Pixel::BGRA => AV_PIX_FMT_BGRA, + Pixel::ARGB => AV_PIX_FMT_ARGB, + Pixel::RGBA => AV_PIX_FMT_RGBA, + Pixel::ABGR => AV_PIX_FMT_ABGR, + Pixel::BGRA => AV_PIX_FMT_BGRA, - Pixel::GRAY16BE => AV_PIX_FMT_GRAY16BE, - Pixel::GRAY16LE => AV_PIX_FMT_GRAY16LE, - Pixel::YUV440P => AV_PIX_FMT_YUV440P, - Pixel::YUVJ440P => AV_PIX_FMT_YUVJ440P, - Pixel::YUVA420P => AV_PIX_FMT_YUVA420P, - #[cfg(feature = "ff_api_vdpau")] - Pixel::VDPAU_H264 => AV_PIX_FMT_VDPAU_H264, - #[cfg(feature = "ff_api_vdpau")] - Pixel::VDPAU_MPEG1 => AV_PIX_FMT_VDPAU_MPEG1, - #[cfg(feature = "ff_api_vdpau")] - Pixel::VDPAU_MPEG2 => AV_PIX_FMT_VDPAU_MPEG2, - #[cfg(feature = "ff_api_vdpau")] - Pixel::VDPAU_WMV3 => AV_PIX_FMT_VDPAU_WMV3, - #[cfg(feature = "ff_api_vdpau")] - Pixel::VDPAU_VC1 => AV_PIX_FMT_VDPAU_VC1, - Pixel::RGB48BE => AV_PIX_FMT_RGB48BE, - Pixel::RGB48LE => AV_PIX_FMT_RGB48LE, + Pixel::GRAY16BE => AV_PIX_FMT_GRAY16BE, + Pixel::GRAY16LE => AV_PIX_FMT_GRAY16LE, + Pixel::YUV440P => AV_PIX_FMT_YUV440P, + Pixel::YUVJ440P => AV_PIX_FMT_YUVJ440P, + Pixel::YUVA420P => AV_PIX_FMT_YUVA420P, + #[cfg(feature = "ff_api_vdpau")] + Pixel::VDPAU_H264 => AV_PIX_FMT_VDPAU_H264, + #[cfg(feature = "ff_api_vdpau")] + Pixel::VDPAU_MPEG1 => AV_PIX_FMT_VDPAU_MPEG1, + #[cfg(feature = "ff_api_vdpau")] + Pixel::VDPAU_MPEG2 => AV_PIX_FMT_VDPAU_MPEG2, + #[cfg(feature = "ff_api_vdpau")] + Pixel::VDPAU_WMV3 => AV_PIX_FMT_VDPAU_WMV3, + #[cfg(feature = "ff_api_vdpau")] + Pixel::VDPAU_VC1 => AV_PIX_FMT_VDPAU_VC1, + Pixel::RGB48BE => AV_PIX_FMT_RGB48BE, + Pixel::RGB48LE => AV_PIX_FMT_RGB48LE, - Pixel::RGB565BE => AV_PIX_FMT_RGB565BE, - Pixel::RGB565LE => AV_PIX_FMT_RGB565LE, - Pixel::RGB555BE => AV_PIX_FMT_RGB555BE, - Pixel::RGB555LE => AV_PIX_FMT_RGB555LE, + Pixel::RGB565BE => AV_PIX_FMT_RGB565BE, + Pixel::RGB565LE => AV_PIX_FMT_RGB565LE, + Pixel::RGB555BE => AV_PIX_FMT_RGB555BE, + Pixel::RGB555LE => AV_PIX_FMT_RGB555LE, - Pixel::BGR565BE => AV_PIX_FMT_BGR565BE, - Pixel::BGR565LE => AV_PIX_FMT_BGR565LE, - Pixel::BGR555BE => AV_PIX_FMT_BGR555BE, - Pixel::BGR555LE => AV_PIX_FMT_BGR555LE, + Pixel::BGR565BE => AV_PIX_FMT_BGR565BE, + Pixel::BGR565LE => AV_PIX_FMT_BGR565LE, + Pixel::BGR555BE => AV_PIX_FMT_BGR555BE, + Pixel::BGR555LE => AV_PIX_FMT_BGR555LE, - #[cfg(feature = "ff_api_vaapi")] - Pixel::VAAPI_MOCO => AV_PIX_FMT_VAAPI_MOCO, - #[cfg(feature = "ff_api_vaapi")] - Pixel::VAAPI_IDCT => AV_PIX_FMT_VAAPI_IDCT, - #[cfg(feature = "ff_api_vaapi")] - Pixel::VAAPI_VLD => AV_PIX_FMT_VAAPI_VLD, - #[cfg(not(feature = "ff_api_vaapi"))] - Pixel::VAAPI => AV_PIX_FMT_VAAPI, + #[cfg(feature = "ff_api_vaapi")] + Pixel::VAAPI_MOCO => AV_PIX_FMT_VAAPI_MOCO, + #[cfg(feature = "ff_api_vaapi")] + Pixel::VAAPI_IDCT => AV_PIX_FMT_VAAPI_IDCT, + #[cfg(feature = "ff_api_vaapi")] + Pixel::VAAPI_VLD => AV_PIX_FMT_VAAPI_VLD, + #[cfg(not(feature = "ff_api_vaapi"))] + Pixel::VAAPI => AV_PIX_FMT_VAAPI, - Pixel::YUV420P16LE => AV_PIX_FMT_YUV420P16LE, - Pixel::YUV420P16BE => AV_PIX_FMT_YUV420P16BE, - Pixel::YUV422P16LE => AV_PIX_FMT_YUV422P16LE, - Pixel::YUV422P16BE => AV_PIX_FMT_YUV422P16BE, - Pixel::YUV444P16LE => AV_PIX_FMT_YUV444P16LE, - Pixel::YUV444P16BE => AV_PIX_FMT_YUV444P16BE, - #[cfg(feature = "ff_api_vdpau")] - Pixel::VDPAU_MPEG4 => AV_PIX_FMT_VDPAU_MPEG4, - Pixel::DXVA2_VLD => AV_PIX_FMT_DXVA2_VLD, + Pixel::YUV420P16LE => AV_PIX_FMT_YUV420P16LE, + Pixel::YUV420P16BE => AV_PIX_FMT_YUV420P16BE, + Pixel::YUV422P16LE => AV_PIX_FMT_YUV422P16LE, + Pixel::YUV422P16BE => AV_PIX_FMT_YUV422P16BE, + Pixel::YUV444P16LE => AV_PIX_FMT_YUV444P16LE, + Pixel::YUV444P16BE => AV_PIX_FMT_YUV444P16BE, + #[cfg(feature = "ff_api_vdpau")] + Pixel::VDPAU_MPEG4 => AV_PIX_FMT_VDPAU_MPEG4, + Pixel::DXVA2_VLD => AV_PIX_FMT_DXVA2_VLD, - Pixel::RGB444LE => AV_PIX_FMT_RGB444LE, - Pixel::RGB444BE => AV_PIX_FMT_RGB444BE, - Pixel::BGR444LE => AV_PIX_FMT_BGR444LE, - Pixel::BGR444BE => AV_PIX_FMT_BGR444BE, - Pixel::YA8 => AV_PIX_FMT_YA8, + Pixel::RGB444LE => AV_PIX_FMT_RGB444LE, + Pixel::RGB444BE => AV_PIX_FMT_RGB444BE, + Pixel::BGR444LE => AV_PIX_FMT_BGR444LE, + Pixel::BGR444BE => AV_PIX_FMT_BGR444BE, + Pixel::YA8 => AV_PIX_FMT_YA8, - Pixel::BGR48BE => AV_PIX_FMT_BGR48BE, - Pixel::BGR48LE => AV_PIX_FMT_BGR48LE, + Pixel::BGR48BE => AV_PIX_FMT_BGR48BE, + Pixel::BGR48LE => AV_PIX_FMT_BGR48LE, - Pixel::YUV420P9BE => AV_PIX_FMT_YUV420P9BE, - Pixel::YUV420P9LE => AV_PIX_FMT_YUV420P9LE, - Pixel::YUV420P10BE => AV_PIX_FMT_YUV420P10BE, - Pixel::YUV420P10LE => AV_PIX_FMT_YUV420P10LE, - Pixel::YUV422P10BE => AV_PIX_FMT_YUV422P10BE, - Pixel::YUV422P10LE => AV_PIX_FMT_YUV422P10LE, - Pixel::YUV444P9BE => AV_PIX_FMT_YUV444P9BE, - Pixel::YUV444P9LE => AV_PIX_FMT_YUV444P9LE, - Pixel::YUV444P10BE => AV_PIX_FMT_YUV444P10BE, - Pixel::YUV444P10LE => AV_PIX_FMT_YUV444P10LE, - Pixel::YUV422P9BE => AV_PIX_FMT_YUV422P9BE, - Pixel::YUV422P9LE => AV_PIX_FMT_YUV422P9LE, - Pixel::VDA_VLD => AV_PIX_FMT_VDA_VLD, + Pixel::YUV420P9BE => AV_PIX_FMT_YUV420P9BE, + Pixel::YUV420P9LE => AV_PIX_FMT_YUV420P9LE, + Pixel::YUV420P10BE => AV_PIX_FMT_YUV420P10BE, + Pixel::YUV420P10LE => AV_PIX_FMT_YUV420P10LE, + Pixel::YUV422P10BE => AV_PIX_FMT_YUV422P10BE, + Pixel::YUV422P10LE => AV_PIX_FMT_YUV422P10LE, + Pixel::YUV444P9BE => AV_PIX_FMT_YUV444P9BE, + Pixel::YUV444P9LE => AV_PIX_FMT_YUV444P9LE, + Pixel::YUV444P10BE => AV_PIX_FMT_YUV444P10BE, + Pixel::YUV444P10LE => AV_PIX_FMT_YUV444P10LE, + Pixel::YUV422P9BE => AV_PIX_FMT_YUV422P9BE, + Pixel::YUV422P9LE => AV_PIX_FMT_YUV422P9LE, + Pixel::VDA_VLD => AV_PIX_FMT_VDA_VLD, - Pixel::GBRP => AV_PIX_FMT_GBRP, - Pixel::GBRP9BE => AV_PIX_FMT_GBRP9BE, - Pixel::GBRP9LE => AV_PIX_FMT_GBRP9LE, - Pixel::GBRP10BE => AV_PIX_FMT_GBRP10BE, - Pixel::GBRP10LE => AV_PIX_FMT_GBRP10LE, - Pixel::GBRP16BE => AV_PIX_FMT_GBRP16BE, - Pixel::GBRP16LE => AV_PIX_FMT_GBRP16LE, + Pixel::GBRP => AV_PIX_FMT_GBRP, + Pixel::GBRP9BE => AV_PIX_FMT_GBRP9BE, + Pixel::GBRP9LE => AV_PIX_FMT_GBRP9LE, + Pixel::GBRP10BE => AV_PIX_FMT_GBRP10BE, + Pixel::GBRP10LE => AV_PIX_FMT_GBRP10LE, + Pixel::GBRP16BE => AV_PIX_FMT_GBRP16BE, + Pixel::GBRP16LE => AV_PIX_FMT_GBRP16LE, - Pixel::YUVA420P9BE => AV_PIX_FMT_YUVA420P9BE, - Pixel::YUVA420P9LE => AV_PIX_FMT_YUVA420P9LE, - Pixel::YUVA422P9BE => AV_PIX_FMT_YUVA422P9BE, - Pixel::YUVA422P9LE => AV_PIX_FMT_YUVA422P9LE, - Pixel::YUVA444P9BE => AV_PIX_FMT_YUVA444P9BE, - Pixel::YUVA444P9LE => AV_PIX_FMT_YUVA444P9LE, - Pixel::YUVA420P10BE => AV_PIX_FMT_YUVA420P10BE, - Pixel::YUVA420P10LE => AV_PIX_FMT_YUVA420P10LE, - Pixel::YUVA422P10BE => AV_PIX_FMT_YUVA422P10BE, - Pixel::YUVA422P10LE => AV_PIX_FMT_YUVA422P10LE, - Pixel::YUVA444P10BE => AV_PIX_FMT_YUVA444P10BE, - Pixel::YUVA444P10LE => AV_PIX_FMT_YUVA444P10LE, - Pixel::YUVA420P16BE => AV_PIX_FMT_YUVA420P16BE, - Pixel::YUVA420P16LE => AV_PIX_FMT_YUVA420P16LE, - Pixel::YUVA422P16BE => AV_PIX_FMT_YUVA422P16BE, - Pixel::YUVA422P16LE => AV_PIX_FMT_YUVA422P16LE, - Pixel::YUVA444P16BE => AV_PIX_FMT_YUVA444P16BE, - Pixel::YUVA444P16LE => AV_PIX_FMT_YUVA444P16LE, + Pixel::YUVA420P9BE => AV_PIX_FMT_YUVA420P9BE, + Pixel::YUVA420P9LE => AV_PIX_FMT_YUVA420P9LE, + Pixel::YUVA422P9BE => AV_PIX_FMT_YUVA422P9BE, + Pixel::YUVA422P9LE => AV_PIX_FMT_YUVA422P9LE, + Pixel::YUVA444P9BE => AV_PIX_FMT_YUVA444P9BE, + Pixel::YUVA444P9LE => AV_PIX_FMT_YUVA444P9LE, + Pixel::YUVA420P10BE => AV_PIX_FMT_YUVA420P10BE, + Pixel::YUVA420P10LE => AV_PIX_FMT_YUVA420P10LE, + Pixel::YUVA422P10BE => AV_PIX_FMT_YUVA422P10BE, + Pixel::YUVA422P10LE => AV_PIX_FMT_YUVA422P10LE, + Pixel::YUVA444P10BE => AV_PIX_FMT_YUVA444P10BE, + Pixel::YUVA444P10LE => AV_PIX_FMT_YUVA444P10LE, + Pixel::YUVA420P16BE => AV_PIX_FMT_YUVA420P16BE, + Pixel::YUVA420P16LE => AV_PIX_FMT_YUVA420P16LE, + Pixel::YUVA422P16BE => AV_PIX_FMT_YUVA422P16BE, + Pixel::YUVA422P16LE => AV_PIX_FMT_YUVA422P16LE, + Pixel::YUVA444P16BE => AV_PIX_FMT_YUVA444P16BE, + Pixel::YUVA444P16LE => AV_PIX_FMT_YUVA444P16LE, - Pixel::VDPAU => AV_PIX_FMT_VDPAU, + Pixel::VDPAU => AV_PIX_FMT_VDPAU, - Pixel::XYZ12LE => AV_PIX_FMT_XYZ12LE, - Pixel::XYZ12BE => AV_PIX_FMT_XYZ12BE, - Pixel::NV16 => AV_PIX_FMT_NV16, - Pixel::NV20LE => AV_PIX_FMT_NV20LE, - Pixel::NV20BE => AV_PIX_FMT_NV20BE, + Pixel::XYZ12LE => AV_PIX_FMT_XYZ12LE, + Pixel::XYZ12BE => AV_PIX_FMT_XYZ12BE, + Pixel::NV16 => AV_PIX_FMT_NV16, + Pixel::NV20LE => AV_PIX_FMT_NV20LE, + Pixel::NV20BE => AV_PIX_FMT_NV20BE, - Pixel::RGBA64BE => AV_PIX_FMT_RGBA64BE, - Pixel::RGBA64LE => AV_PIX_FMT_RGBA64LE, - Pixel::BGRA64BE => AV_PIX_FMT_BGRA64BE, - Pixel::BGRA64LE => AV_PIX_FMT_BGRA64LE, + Pixel::RGBA64BE => AV_PIX_FMT_RGBA64BE, + Pixel::RGBA64LE => AV_PIX_FMT_RGBA64LE, + Pixel::BGRA64BE => AV_PIX_FMT_BGRA64BE, + Pixel::BGRA64LE => AV_PIX_FMT_BGRA64LE, - Pixel::YVYU422 => AV_PIX_FMT_YVYU422, + Pixel::YVYU422 => AV_PIX_FMT_YVYU422, - Pixel::VDA => AV_PIX_FMT_VDA, + Pixel::VDA => AV_PIX_FMT_VDA, - Pixel::YA16BE => AV_PIX_FMT_YA16BE, - Pixel::YA16LE => AV_PIX_FMT_YA16LE, + Pixel::YA16BE => AV_PIX_FMT_YA16BE, + Pixel::YA16LE => AV_PIX_FMT_YA16LE, - Pixel::QSV => AV_PIX_FMT_QSV, - Pixel::MMAL => AV_PIX_FMT_MMAL, + Pixel::QSV => AV_PIX_FMT_QSV, + Pixel::MMAL => AV_PIX_FMT_MMAL, - Pixel::D3D11VA_VLD => AV_PIX_FMT_D3D11VA_VLD, + Pixel::D3D11VA_VLD => AV_PIX_FMT_D3D11VA_VLD, - Pixel::CUDA => AV_PIX_FMT_CUDA, + Pixel::CUDA => AV_PIX_FMT_CUDA, - Pixel::ZRGB => AV_PIX_FMT_0RGB, - Pixel::RGBZ => AV_PIX_FMT_RGB0, - Pixel::ZBGR => AV_PIX_FMT_0BGR, - Pixel::BGRZ => AV_PIX_FMT_BGR0, - Pixel::YUVA444P => AV_PIX_FMT_YUVA444P, - Pixel::YUVA422P => AV_PIX_FMT_YUVA422P, + Pixel::ZRGB => AV_PIX_FMT_0RGB, + Pixel::RGBZ => AV_PIX_FMT_RGB0, + Pixel::ZBGR => AV_PIX_FMT_0BGR, + Pixel::BGRZ => AV_PIX_FMT_BGR0, + Pixel::YUVA444P => AV_PIX_FMT_YUVA444P, + Pixel::YUVA422P => AV_PIX_FMT_YUVA422P, - Pixel::YUV420P12BE => AV_PIX_FMT_YUV420P12BE, - Pixel::YUV420P12LE => AV_PIX_FMT_YUV420P12LE, - Pixel::YUV420P14BE => AV_PIX_FMT_YUV420P14BE, - Pixel::YUV420P14LE => AV_PIX_FMT_YUV420P14LE, - Pixel::YUV422P12BE => AV_PIX_FMT_YUV422P12BE, - Pixel::YUV422P12LE => AV_PIX_FMT_YUV422P12LE, - Pixel::YUV422P14BE => AV_PIX_FMT_YUV422P14BE, - Pixel::YUV422P14LE => AV_PIX_FMT_YUV422P14LE, - Pixel::YUV444P12BE => AV_PIX_FMT_YUV444P12BE, - Pixel::YUV444P12LE => AV_PIX_FMT_YUV444P12LE, - Pixel::YUV444P14BE => AV_PIX_FMT_YUV444P14BE, - Pixel::YUV444P14LE => AV_PIX_FMT_YUV444P14LE, - Pixel::GBRP12BE => AV_PIX_FMT_GBRP12BE, - Pixel::GBRP12LE => AV_PIX_FMT_GBRP12LE, - Pixel::GBRP14BE => AV_PIX_FMT_GBRP14BE, - Pixel::GBRP14LE => AV_PIX_FMT_GBRP14LE, - Pixel::GBRAP => AV_PIX_FMT_GBRAP, - Pixel::GBRAP16BE => AV_PIX_FMT_GBRAP16BE, - Pixel::GBRAP16LE => AV_PIX_FMT_GBRAP16LE, - Pixel::YUVJ411P => AV_PIX_FMT_YUVJ411P, + Pixel::YUV420P12BE => AV_PIX_FMT_YUV420P12BE, + Pixel::YUV420P12LE => AV_PIX_FMT_YUV420P12LE, + Pixel::YUV420P14BE => AV_PIX_FMT_YUV420P14BE, + Pixel::YUV420P14LE => AV_PIX_FMT_YUV420P14LE, + Pixel::YUV422P12BE => AV_PIX_FMT_YUV422P12BE, + Pixel::YUV422P12LE => AV_PIX_FMT_YUV422P12LE, + Pixel::YUV422P14BE => AV_PIX_FMT_YUV422P14BE, + Pixel::YUV422P14LE => AV_PIX_FMT_YUV422P14LE, + Pixel::YUV444P12BE => AV_PIX_FMT_YUV444P12BE, + Pixel::YUV444P12LE => AV_PIX_FMT_YUV444P12LE, + Pixel::YUV444P14BE => AV_PIX_FMT_YUV444P14BE, + Pixel::YUV444P14LE => AV_PIX_FMT_YUV444P14LE, + Pixel::GBRP12BE => AV_PIX_FMT_GBRP12BE, + Pixel::GBRP12LE => AV_PIX_FMT_GBRP12LE, + Pixel::GBRP14BE => AV_PIX_FMT_GBRP14BE, + Pixel::GBRP14LE => AV_PIX_FMT_GBRP14LE, + Pixel::GBRAP => AV_PIX_FMT_GBRAP, + Pixel::GBRAP16BE => AV_PIX_FMT_GBRAP16BE, + Pixel::GBRAP16LE => AV_PIX_FMT_GBRAP16LE, + Pixel::YUVJ411P => AV_PIX_FMT_YUVJ411P, - Pixel::BAYER_BGGR8 => AV_PIX_FMT_BAYER_BGGR8, - Pixel::BAYER_RGGB8 => AV_PIX_FMT_BAYER_RGGB8, - Pixel::BAYER_GBRG8 => AV_PIX_FMT_BAYER_GBRG8, - Pixel::BAYER_GRBG8 => AV_PIX_FMT_BAYER_GRBG8, - Pixel::BAYER_BGGR16LE => AV_PIX_FMT_BAYER_BGGR16LE, - Pixel::BAYER_BGGR16BE => AV_PIX_FMT_BAYER_BGGR16BE, - Pixel::BAYER_RGGB16LE => AV_PIX_FMT_BAYER_RGGB16LE, - Pixel::BAYER_RGGB16BE => AV_PIX_FMT_BAYER_RGGB16BE, - Pixel::BAYER_GBRG16LE => AV_PIX_FMT_BAYER_GBRG16LE, - Pixel::BAYER_GBRG16BE => AV_PIX_FMT_BAYER_GBRG16BE, - Pixel::BAYER_GRBG16LE => AV_PIX_FMT_BAYER_GRBG16LE, - Pixel::BAYER_GRBG16BE => AV_PIX_FMT_BAYER_GRBG16BE, + Pixel::BAYER_BGGR8 => AV_PIX_FMT_BAYER_BGGR8, + Pixel::BAYER_RGGB8 => AV_PIX_FMT_BAYER_RGGB8, + Pixel::BAYER_GBRG8 => AV_PIX_FMT_BAYER_GBRG8, + Pixel::BAYER_GRBG8 => AV_PIX_FMT_BAYER_GRBG8, + Pixel::BAYER_BGGR16LE => AV_PIX_FMT_BAYER_BGGR16LE, + Pixel::BAYER_BGGR16BE => AV_PIX_FMT_BAYER_BGGR16BE, + Pixel::BAYER_RGGB16LE => AV_PIX_FMT_BAYER_RGGB16LE, + Pixel::BAYER_RGGB16BE => AV_PIX_FMT_BAYER_RGGB16BE, + Pixel::BAYER_GBRG16LE => AV_PIX_FMT_BAYER_GBRG16LE, + Pixel::BAYER_GBRG16BE => AV_PIX_FMT_BAYER_GBRG16BE, + Pixel::BAYER_GRBG16LE => AV_PIX_FMT_BAYER_GRBG16LE, + Pixel::BAYER_GRBG16BE => AV_PIX_FMT_BAYER_GRBG16BE, - Pixel::YUV440P10LE => AV_PIX_FMT_YUV440P10LE, - Pixel::YUV440P10BE => AV_PIX_FMT_YUV440P10BE, - Pixel::YUV440P12LE => AV_PIX_FMT_YUV440P12LE, - Pixel::YUV440P12BE => AV_PIX_FMT_YUV440P12BE, - Pixel::AYUV64LE => AV_PIX_FMT_AYUV64LE, - Pixel::AYUV64BE => AV_PIX_FMT_AYUV64BE, + Pixel::YUV440P10LE => AV_PIX_FMT_YUV440P10LE, + Pixel::YUV440P10BE => AV_PIX_FMT_YUV440P10BE, + Pixel::YUV440P12LE => AV_PIX_FMT_YUV440P12LE, + Pixel::YUV440P12BE => AV_PIX_FMT_YUV440P12BE, + Pixel::AYUV64LE => AV_PIX_FMT_AYUV64LE, + Pixel::AYUV64BE => AV_PIX_FMT_AYUV64BE, - Pixel::VIDEOTOOLBOX => AV_PIX_FMT_VIDEOTOOLBOX, + Pixel::VIDEOTOOLBOX => AV_PIX_FMT_VIDEOTOOLBOX, - // --- defaults - Pixel::XVMC => AV_PIX_FMT_XVMC, - Pixel::Y400A => AV_PIX_FMT_Y400A, - Pixel::GRAY8A => AV_PIX_FMT_GRAY8A, - Pixel::GBR24P => AV_PIX_FMT_GBR24P, + // --- defaults + Pixel::XVMC => AV_PIX_FMT_XVMC, + Pixel::Y400A => AV_PIX_FMT_Y400A, + Pixel::GRAY8A => AV_PIX_FMT_GRAY8A, + Pixel::GBR24P => AV_PIX_FMT_GBR24P, - Pixel::RGB32 => AV_PIX_FMT_RGB32, - Pixel::RGB32_1 => AV_PIX_FMT_RGB32_1, - Pixel::BGR32 => AV_PIX_FMT_BGR32, - Pixel::BGR32_1 => AV_PIX_FMT_BGR32_1, - Pixel::ZRGB32 => AV_PIX_FMT_0RGB32, - Pixel::ZBGR32 => AV_PIX_FMT_0BGR32, + Pixel::RGB32 => AV_PIX_FMT_RGB32, + Pixel::RGB32_1 => AV_PIX_FMT_RGB32_1, + Pixel::BGR32 => AV_PIX_FMT_BGR32, + Pixel::BGR32_1 => AV_PIX_FMT_BGR32_1, + Pixel::ZRGB32 => AV_PIX_FMT_0RGB32, + Pixel::ZBGR32 => AV_PIX_FMT_0BGR32, - Pixel::GRAY16 => AV_PIX_FMT_GRAY16, - Pixel::YA16 => AV_PIX_FMT_YA16, - Pixel::RGB48 => AV_PIX_FMT_RGB48, - Pixel::RGB565 => AV_PIX_FMT_RGB565, - Pixel::RGB555 => AV_PIX_FMT_RGB555, - Pixel::RGB444 => AV_PIX_FMT_RGB444, - Pixel::BGR48 => AV_PIX_FMT_BGR48, - Pixel::BGR565 => AV_PIX_FMT_BGR565, - Pixel::BGR555 => AV_PIX_FMT_BGR555, - Pixel::BGR444 => AV_PIX_FMT_BGR444, + Pixel::GRAY16 => AV_PIX_FMT_GRAY16, + Pixel::YA16 => AV_PIX_FMT_YA16, + Pixel::RGB48 => AV_PIX_FMT_RGB48, + Pixel::RGB565 => AV_PIX_FMT_RGB565, + Pixel::RGB555 => AV_PIX_FMT_RGB555, + Pixel::RGB444 => AV_PIX_FMT_RGB444, + Pixel::BGR48 => AV_PIX_FMT_BGR48, + Pixel::BGR565 => AV_PIX_FMT_BGR565, + Pixel::BGR555 => AV_PIX_FMT_BGR555, + Pixel::BGR444 => AV_PIX_FMT_BGR444, - Pixel::YUV420P9 => AV_PIX_FMT_YUV420P9, - Pixel::YUV422P9 => AV_PIX_FMT_YUV422P9, - Pixel::YUV444P9 => AV_PIX_FMT_YUV444P9, - Pixel::YUV420P10 => AV_PIX_FMT_YUV420P10, - Pixel::YUV422P10 => AV_PIX_FMT_YUV422P10, - Pixel::YUV440P10 => AV_PIX_FMT_YUV440P10, - Pixel::YUV444P10 => AV_PIX_FMT_YUV444P10, - Pixel::YUV420P12 => AV_PIX_FMT_YUV420P12, - Pixel::YUV422P12 => AV_PIX_FMT_YUV422P12, - Pixel::YUV440P12 => AV_PIX_FMT_YUV440P12, - Pixel::YUV444P12 => AV_PIX_FMT_YUV444P12, - Pixel::YUV420P14 => AV_PIX_FMT_YUV420P14, - Pixel::YUV422P14 => AV_PIX_FMT_YUV422P14, - Pixel::YUV444P14 => AV_PIX_FMT_YUV444P14, - Pixel::YUV420P16 => AV_PIX_FMT_YUV420P16, - Pixel::YUV422P16 => AV_PIX_FMT_YUV422P16, - Pixel::YUV444P16 => AV_PIX_FMT_YUV444P16, + Pixel::YUV420P9 => AV_PIX_FMT_YUV420P9, + Pixel::YUV422P9 => AV_PIX_FMT_YUV422P9, + Pixel::YUV444P9 => AV_PIX_FMT_YUV444P9, + Pixel::YUV420P10 => AV_PIX_FMT_YUV420P10, + Pixel::YUV422P10 => AV_PIX_FMT_YUV422P10, + Pixel::YUV440P10 => AV_PIX_FMT_YUV440P10, + Pixel::YUV444P10 => AV_PIX_FMT_YUV444P10, + Pixel::YUV420P12 => AV_PIX_FMT_YUV420P12, + Pixel::YUV422P12 => AV_PIX_FMT_YUV422P12, + Pixel::YUV440P12 => AV_PIX_FMT_YUV440P12, + Pixel::YUV444P12 => AV_PIX_FMT_YUV444P12, + Pixel::YUV420P14 => AV_PIX_FMT_YUV420P14, + Pixel::YUV422P14 => AV_PIX_FMT_YUV422P14, + Pixel::YUV444P14 => AV_PIX_FMT_YUV444P14, + Pixel::YUV420P16 => AV_PIX_FMT_YUV420P16, + Pixel::YUV422P16 => AV_PIX_FMT_YUV422P16, + Pixel::YUV444P16 => AV_PIX_FMT_YUV444P16, - Pixel::GBRP9 => AV_PIX_FMT_GBRP9, - Pixel::GBRP10 => AV_PIX_FMT_GBRP10, - Pixel::GBRP12 => AV_PIX_FMT_GBRP12, - Pixel::GBRP14 => AV_PIX_FMT_GBRP14, - Pixel::GBRP16 => AV_PIX_FMT_GBRP16, - Pixel::GBRAP16 => AV_PIX_FMT_GBRAP16, + Pixel::GBRP9 => AV_PIX_FMT_GBRP9, + Pixel::GBRP10 => AV_PIX_FMT_GBRP10, + Pixel::GBRP12 => AV_PIX_FMT_GBRP12, + Pixel::GBRP14 => AV_PIX_FMT_GBRP14, + Pixel::GBRP16 => AV_PIX_FMT_GBRP16, + Pixel::GBRAP16 => AV_PIX_FMT_GBRAP16, - Pixel::BAYER_BGGR16 => AV_PIX_FMT_BAYER_BGGR16, - Pixel::BAYER_RGGB16 => AV_PIX_FMT_BAYER_RGGB16, - Pixel::BAYER_GBRG16 => AV_PIX_FMT_BAYER_GBRG16, - Pixel::BAYER_GRBG16 => AV_PIX_FMT_BAYER_GRBG16, + Pixel::BAYER_BGGR16 => AV_PIX_FMT_BAYER_BGGR16, + Pixel::BAYER_RGGB16 => AV_PIX_FMT_BAYER_RGGB16, + Pixel::BAYER_GBRG16 => AV_PIX_FMT_BAYER_GBRG16, + Pixel::BAYER_GRBG16 => AV_PIX_FMT_BAYER_GRBG16, - Pixel::YUVA420P9 => AV_PIX_FMT_YUVA420P9, - Pixel::YUVA422P9 => AV_PIX_FMT_YUVA422P9, - Pixel::YUVA444P9 => AV_PIX_FMT_YUVA444P9, - Pixel::YUVA420P10 => AV_PIX_FMT_YUVA420P10, - Pixel::YUVA422P10 => AV_PIX_FMT_YUVA422P10, - Pixel::YUVA444P10 => AV_PIX_FMT_YUVA444P10, - Pixel::YUVA420P16 => AV_PIX_FMT_YUVA420P16, - Pixel::YUVA422P16 => AV_PIX_FMT_YUVA422P16, - Pixel::YUVA444P16 => AV_PIX_FMT_YUVA444P16, + Pixel::YUVA420P9 => AV_PIX_FMT_YUVA420P9, + Pixel::YUVA422P9 => AV_PIX_FMT_YUVA422P9, + Pixel::YUVA444P9 => AV_PIX_FMT_YUVA444P9, + Pixel::YUVA420P10 => AV_PIX_FMT_YUVA420P10, + Pixel::YUVA422P10 => AV_PIX_FMT_YUVA422P10, + Pixel::YUVA444P10 => AV_PIX_FMT_YUVA444P10, + Pixel::YUVA420P16 => AV_PIX_FMT_YUVA420P16, + Pixel::YUVA422P16 => AV_PIX_FMT_YUVA422P16, + Pixel::YUVA444P16 => AV_PIX_FMT_YUVA444P16, - Pixel::XYZ12 => AV_PIX_FMT_XYZ12, - Pixel::NV20 => AV_PIX_FMT_NV20, - Pixel::AYUV64 => AV_PIX_FMT_AYUV64, + Pixel::XYZ12 => AV_PIX_FMT_XYZ12, + Pixel::NV20 => AV_PIX_FMT_NV20, + Pixel::AYUV64 => AV_PIX_FMT_AYUV64, - Pixel::P010LE => AV_PIX_FMT_P010LE, - Pixel::P010BE => AV_PIX_FMT_P010BE, - Pixel::GBRAP12BE => AV_PIX_FMT_GBRAP12BE, - Pixel::GBRAP12LE => AV_PIX_FMT_GBRAP12LE, - Pixel::GBRAP10LE => AV_PIX_FMT_GBRAP10LE, - Pixel::GBRAP10BE => AV_PIX_FMT_GBRAP10BE, - Pixel::MEDIACODEC => AV_PIX_FMT_MEDIACODEC, - Pixel::GRAY12BE => AV_PIX_FMT_GRAY12BE, - Pixel::GRAY12LE => AV_PIX_FMT_GRAY12LE, - Pixel::GRAY10BE => AV_PIX_FMT_GRAY10BE, - Pixel::GRAY10LE => AV_PIX_FMT_GRAY10LE, - Pixel::P016LE => AV_PIX_FMT_P016LE, - Pixel::P016BE => AV_PIX_FMT_P016BE, + Pixel::P010LE => AV_PIX_FMT_P010LE, + Pixel::P010BE => AV_PIX_FMT_P010BE, + Pixel::GBRAP12BE => AV_PIX_FMT_GBRAP12BE, + Pixel::GBRAP12LE => AV_PIX_FMT_GBRAP12LE, + Pixel::GBRAP10LE => AV_PIX_FMT_GBRAP10LE, + Pixel::GBRAP10BE => AV_PIX_FMT_GBRAP10BE, + Pixel::MEDIACODEC => AV_PIX_FMT_MEDIACODEC, + Pixel::GRAY12BE => AV_PIX_FMT_GRAY12BE, + Pixel::GRAY12LE => AV_PIX_FMT_GRAY12LE, + Pixel::GRAY10BE => AV_PIX_FMT_GRAY10BE, + Pixel::GRAY10LE => AV_PIX_FMT_GRAY10LE, + Pixel::P016LE => AV_PIX_FMT_P016LE, + Pixel::P016BE => AV_PIX_FMT_P016BE, - Pixel::D3D11 => AV_PIX_FMT_D3D11, - Pixel::GRAY9BE => AV_PIX_FMT_GRAY9BE, - Pixel::GRAY9LE => AV_PIX_FMT_GRAY9LE, - Pixel::GBRPF32BE => AV_PIX_FMT_GBRPF32BE, - Pixel::GBRPF32LE => AV_PIX_FMT_GBRPF32LE, - Pixel::GBRAPF32BE => AV_PIX_FMT_GBRAPF32BE, - Pixel::GBRAPF32LE => AV_PIX_FMT_GBRAPF32LE, - Pixel::DRM_PRIME => AV_PIX_FMT_DRM_PRIME, - } - } + Pixel::D3D11 => AV_PIX_FMT_D3D11, + Pixel::GRAY9BE => AV_PIX_FMT_GRAY9BE, + Pixel::GRAY9LE => AV_PIX_FMT_GRAY9LE, + Pixel::GBRPF32BE => AV_PIX_FMT_GBRPF32BE, + Pixel::GBRPF32LE => AV_PIX_FMT_GBRPF32LE, + Pixel::GBRAPF32BE => AV_PIX_FMT_GBRAPF32BE, + Pixel::GBRAPF32LE => AV_PIX_FMT_GBRAPF32LE, + Pixel::DRM_PRIME => AV_PIX_FMT_DRM_PRIME, + } + } } #[derive(Debug)] pub enum ParsePixelError { - NulError(NulError), - UnknownFormat, + NulError(NulError), + UnknownFormat, } impl fmt::Display for ParsePixelError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - ParsePixelError::NulError(ref e) => e.fmt(f), - ParsePixelError::UnknownFormat => write!(f, "unknown pixel format") - } - } + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + ParsePixelError::NulError(ref e) => e.fmt(f), + ParsePixelError::UnknownFormat => write!(f, "unknown pixel format"), + } + } } impl error::Error for ParsePixelError { - fn description(&self) -> &str { - match *self { - ParsePixelError::NulError(ref e) => e.description(), - ParsePixelError::UnknownFormat => "unknown pixel format" - } - } + fn description(&self) -> &str { + match *self { + ParsePixelError::NulError(ref e) => e.description(), + ParsePixelError::UnknownFormat => "unknown pixel format", + } + } - fn cause(&self) -> Option<&error::Error> { - match *self { - ParsePixelError::NulError(ref e) => Some(e), - ParsePixelError::UnknownFormat => None - } - } + fn cause(&self) -> Option<&error::Error> { + match *self { + ParsePixelError::NulError(ref e) => Some(e), + ParsePixelError::UnknownFormat => None, + } + } } impl From for ParsePixelError { - fn from(x: NulError) -> ParsePixelError { - ParsePixelError::NulError(x) - } + fn from(x: NulError) -> ParsePixelError { + ParsePixelError::NulError(x) + } } impl FromStr for Pixel { - type Err = ParsePixelError; + type Err = ParsePixelError; - #[inline(always)] - fn from_str(s: &str) -> Result { - let cstring = CString::new(s)?; - let format = unsafe { av_get_pix_fmt(cstring.as_ptr()) }.into(); + #[inline(always)] + fn from_str(s: &str) -> Result { + let cstring = CString::new(s)?; + let format = unsafe { av_get_pix_fmt(cstring.as_ptr()) }.into(); - if format == Pixel::None { - Err(ParsePixelError::UnknownFormat) - } else { - Ok(format) - } - } + if format == Pixel::None { + Err(ParsePixelError::UnknownFormat) + } else { + Ok(format) + } + } } diff --git a/src/util/format/sample.rs b/src/util/format/sample.rs index e5e1378..c16bae5 100644 --- a/src/util/format/sample.rs +++ b/src/util/format/sample.rs @@ -1,216 +1,224 @@ use std::ffi::{CStr, CString}; -use std::str::from_utf8_unchecked; +use std::mem; use std::ops::Index; use std::ptr; use std::slice; -use std::mem; +use std::str::from_utf8_unchecked; -use libc::{c_int, uint8_t}; -use ffi::*; use ffi::AVSampleFormat::*; +use ffi::*; +use libc::{c_int, uint8_t}; #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Sample { - None, + None, - U8(Type), - I16(Type), - I32(Type), - I64(Type), - F32(Type), - F64(Type), + U8(Type), + I16(Type), + I32(Type), + I64(Type), + F32(Type), + F64(Type), } #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Type { - Packed, - Planar, + Packed, + Planar, } impl Sample { - #[inline] - pub fn name(&self) -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(av_get_sample_fmt_name((*self).into())).to_bytes()) - } - } + #[inline] + pub fn name(&self) -> &'static str { + unsafe { + from_utf8_unchecked(CStr::from_ptr(av_get_sample_fmt_name((*self).into())).to_bytes()) + } + } - #[inline] - pub fn packed(&self) -> Self { - unsafe { - Sample::from(av_get_packed_sample_fmt((*self).into())) - } - } + #[inline] + pub fn packed(&self) -> Self { + unsafe { Sample::from(av_get_packed_sample_fmt((*self).into())) } + } - #[inline] - pub fn planar(&self) -> Self { - unsafe { - Sample::from(av_get_planar_sample_fmt((*self).into())) - } - } + #[inline] + pub fn planar(&self) -> Self { + unsafe { Sample::from(av_get_planar_sample_fmt((*self).into())) } + } - #[inline] - pub fn is_planar(&self) -> bool { - unsafe { - av_sample_fmt_is_planar((*self).into()) == 1 - } - } + #[inline] + pub fn is_planar(&self) -> bool { + unsafe { av_sample_fmt_is_planar((*self).into()) == 1 } + } - #[inline] - pub fn is_packed(&self) -> bool { - !self.is_planar() - } + #[inline] + pub fn is_packed(&self) -> bool { + !self.is_planar() + } - #[inline] - pub fn bytes(&self) -> usize { - unsafe { - av_get_bytes_per_sample((*self).into()) as usize - } - } + #[inline] + pub fn bytes(&self) -> usize { + unsafe { av_get_bytes_per_sample((*self).into()) as usize } + } - #[inline] - pub fn buffer(&self, channels: u16, samples: usize, align: bool) -> Buffer { - Buffer::new(*self, channels, samples, align) - } + #[inline] + pub fn buffer(&self, channels: u16, samples: usize, align: bool) -> Buffer { + Buffer::new(*self, channels, samples, align) + } } impl From for Sample { - #[inline] - fn from(value: AVSampleFormat) -> Self { - match value { - AV_SAMPLE_FMT_NONE => Sample::None, + #[inline] + fn from(value: AVSampleFormat) -> Self { + match value { + AV_SAMPLE_FMT_NONE => Sample::None, - AV_SAMPLE_FMT_U8 => Sample::U8(Type::Packed), - AV_SAMPLE_FMT_S16 => Sample::I16(Type::Packed), - AV_SAMPLE_FMT_S32 => Sample::I32(Type::Packed), - AV_SAMPLE_FMT_S64 => Sample::I64(Type::Packed), - AV_SAMPLE_FMT_FLT => Sample::F32(Type::Packed), - AV_SAMPLE_FMT_DBL => Sample::F64(Type::Packed), + AV_SAMPLE_FMT_U8 => Sample::U8(Type::Packed), + AV_SAMPLE_FMT_S16 => Sample::I16(Type::Packed), + AV_SAMPLE_FMT_S32 => Sample::I32(Type::Packed), + AV_SAMPLE_FMT_S64 => Sample::I64(Type::Packed), + AV_SAMPLE_FMT_FLT => Sample::F32(Type::Packed), + AV_SAMPLE_FMT_DBL => Sample::F64(Type::Packed), - AV_SAMPLE_FMT_U8P => Sample::U8(Type::Planar), - AV_SAMPLE_FMT_S16P => Sample::I16(Type::Planar), - AV_SAMPLE_FMT_S32P => Sample::I32(Type::Planar), - AV_SAMPLE_FMT_S64P => Sample::I64(Type::Planar), - AV_SAMPLE_FMT_FLTP => Sample::F32(Type::Planar), - AV_SAMPLE_FMT_DBLP => Sample::F64(Type::Planar), + AV_SAMPLE_FMT_U8P => Sample::U8(Type::Planar), + AV_SAMPLE_FMT_S16P => Sample::I16(Type::Planar), + AV_SAMPLE_FMT_S32P => Sample::I32(Type::Planar), + AV_SAMPLE_FMT_S64P => Sample::I64(Type::Planar), + AV_SAMPLE_FMT_FLTP => Sample::F32(Type::Planar), + AV_SAMPLE_FMT_DBLP => Sample::F64(Type::Planar), - AV_SAMPLE_FMT_NB => Sample::None - } - } + AV_SAMPLE_FMT_NB => Sample::None, + } + } } impl From<&'static str> for Sample { - #[inline] - fn from(value: &'static str) -> Self { - unsafe { - let value = CString::new(value).unwrap(); + #[inline] + fn from(value: &'static str) -> Self { + unsafe { + let value = CString::new(value).unwrap(); - Sample::from(av_get_sample_fmt(value.as_ptr())) - } - } + Sample::from(av_get_sample_fmt(value.as_ptr())) + } + } } impl Into for Sample { - #[inline] - fn into(self) -> AVSampleFormat { - match self { - Sample::None => AV_SAMPLE_FMT_NONE, + #[inline] + fn into(self) -> AVSampleFormat { + match self { + Sample::None => AV_SAMPLE_FMT_NONE, - Sample::U8(Type::Packed) => AV_SAMPLE_FMT_U8, - Sample::I16(Type::Packed) => AV_SAMPLE_FMT_S16, - Sample::I32(Type::Packed) => AV_SAMPLE_FMT_S32, - Sample::I64(Type::Packed) => AV_SAMPLE_FMT_S64, - Sample::F32(Type::Packed) => AV_SAMPLE_FMT_FLT, - Sample::F64(Type::Packed) => AV_SAMPLE_FMT_DBL, + Sample::U8(Type::Packed) => AV_SAMPLE_FMT_U8, + Sample::I16(Type::Packed) => AV_SAMPLE_FMT_S16, + Sample::I32(Type::Packed) => AV_SAMPLE_FMT_S32, + Sample::I64(Type::Packed) => AV_SAMPLE_FMT_S64, + Sample::F32(Type::Packed) => AV_SAMPLE_FMT_FLT, + Sample::F64(Type::Packed) => AV_SAMPLE_FMT_DBL, - Sample::U8(Type::Planar) => AV_SAMPLE_FMT_U8P, - Sample::I16(Type::Planar) => AV_SAMPLE_FMT_S16P, - Sample::I32(Type::Planar) => AV_SAMPLE_FMT_S32P, - Sample::I64(Type::Planar) => AV_SAMPLE_FMT_S64P, - Sample::F32(Type::Planar) => AV_SAMPLE_FMT_FLTP, - Sample::F64(Type::Planar) => AV_SAMPLE_FMT_DBLP, - } - } + Sample::U8(Type::Planar) => AV_SAMPLE_FMT_U8P, + Sample::I16(Type::Planar) => AV_SAMPLE_FMT_S16P, + Sample::I32(Type::Planar) => AV_SAMPLE_FMT_S32P, + Sample::I64(Type::Planar) => AV_SAMPLE_FMT_S64P, + Sample::F32(Type::Planar) => AV_SAMPLE_FMT_FLTP, + Sample::F64(Type::Planar) => AV_SAMPLE_FMT_DBLP, + } + } } pub struct Buffer { - pub format: Sample, - pub channels: u16, - pub samples: usize, - pub align: bool, + pub format: Sample, + pub channels: u16, + pub samples: usize, + pub align: bool, - buffer: *mut *mut uint8_t, - size: c_int, + buffer: *mut *mut uint8_t, + size: c_int, } impl Buffer { - #[inline] - pub fn size(format: Sample, channels: u16, samples: usize, align: bool) -> usize { - unsafe { - av_samples_get_buffer_size(ptr::null_mut(), channels as c_int, samples as c_int, format.into(), !align as c_int) as usize - } - } + #[inline] + pub fn size(format: Sample, channels: u16, samples: usize, align: bool) -> usize { + unsafe { + av_samples_get_buffer_size( + ptr::null_mut(), + i32::from(channels), + samples as c_int, + format.into(), + !align as c_int, + ) as usize + } + } - #[inline] - pub fn new(format: Sample, channels: u16, samples: usize, align: bool) -> Self { - unsafe { - let mut buf = Buffer { - format: format, - channels: channels, - samples: samples, - align: align, + #[inline] + pub fn new(format: Sample, channels: u16, samples: usize, align: bool) -> Self { + unsafe { + let mut buf = Buffer { + format: format, + channels: channels, + samples: samples, + align: align, - buffer: ptr::null_mut(), - size: 0, - }; + buffer: ptr::null_mut(), + size: 0, + }; - av_samples_alloc_array_and_samples(&mut buf.buffer, &mut buf.size, - channels as c_int, samples as c_int, - format.into(), !align as c_int); + av_samples_alloc_array_and_samples( + &mut buf.buffer, + &mut buf.size, + i32::from(channels), + samples as c_int, + format.into(), + !align as c_int, + ); - buf - } - } + buf + } + } } impl Index for Buffer { - type Output = [u8]; + type Output = [u8]; - #[inline] - fn index(&self, index: usize) -> &[u8] { - if index >= self.samples { - panic!("out of bounds"); - } + #[inline] + fn index(&self, index: usize) -> &[u8] { + if index >= self.samples { + panic!("out of bounds"); + } - unsafe { - slice::from_raw_parts(*self.buffer.offset(index as isize), - self.size as usize) - } - } + unsafe { slice::from_raw_parts(*self.buffer.offset(index as isize), self.size as usize) } + } } impl Clone for Buffer { - #[inline] - fn clone(&self) -> Self { - let mut buf = Buffer::new(self.format, self.channels, self.samples, self.align); - buf.clone_from(self); + #[inline] + fn clone(&self) -> Self { + let mut buf = Buffer::new(self.format, self.channels, self.samples, self.align); + buf.clone_from(self); - buf - } + buf + } - #[inline] - fn clone_from(&mut self, source: &Self) { - unsafe { - av_samples_copy(self.buffer, mem::transmute(source.buffer), 0, 0, source.samples as c_int, source.channels as c_int, source.format.into()); - } - } + #[inline] + fn clone_from(&mut self, source: &Self) { + unsafe { + av_samples_copy( + self.buffer, + mem::transmute(source.buffer), + 0, + 0, + source.samples as c_int, + i32::from(source.channels), + source.format.into(), + ); + } + } } impl Drop for Buffer { - #[inline] - fn drop(&mut self) { - unsafe { - av_freep(mem::transmute(self.buffer)); - } - } + #[inline] + fn drop(&mut self) { + unsafe { + av_freep(mem::transmute(self.buffer)); + } + } } diff --git a/src/util/frame/audio.rs b/src/util/frame/audio.rs index b7aad61..92a335f 100644 --- a/src/util/frame/audio.rs +++ b/src/util/frame/audio.rs @@ -1,525 +1,515 @@ use std::mem; -use std::slice; use std::ops::{Deref, DerefMut}; +use std::slice; -use libc::{c_int, int64_t, c_ulonglong}; -use ffi::*; -use ::ChannelLayout; -use ::util::format; use super::Frame; +use ffi::*; +use libc::{c_int, c_ulonglong, int64_t}; +use util::format; +use ChannelLayout; #[derive(PartialEq, Eq)] pub struct Audio(Frame); impl Audio { - #[inline(always)] - pub unsafe fn wrap(ptr: *mut AVFrame) -> Self { - Audio(Frame::wrap(ptr)) - } + #[inline(always)] + pub unsafe fn wrap(ptr: *mut AVFrame) -> Self { + Audio(Frame::wrap(ptr)) + } - #[inline] - pub unsafe fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) { - self.set_format(format); - self.set_samples(samples); - self.set_channel_layout(layout); + #[inline] + pub unsafe fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) { + self.set_format(format); + self.set_samples(samples); + self.set_channel_layout(layout); - av_frame_get_buffer(self.as_mut_ptr(), 0); - } + av_frame_get_buffer(self.as_mut_ptr(), 0); + } } impl Audio { - #[inline(always)] - pub fn empty() -> Self { - unsafe { - Audio(Frame::empty()) - } - } + #[inline(always)] + pub fn empty() -> Self { + unsafe { Audio(Frame::empty()) } + } - #[inline] - pub fn new(format: format::Sample, samples: usize, layout: ChannelLayout) -> Self { - unsafe { - let mut frame = Audio::empty(); - frame.alloc(format, samples, layout); + #[inline] + pub fn new(format: format::Sample, samples: usize, layout: ChannelLayout) -> Self { + unsafe { + let mut frame = Audio::empty(); + frame.alloc(format, samples, layout); - frame - } - } + frame + } + } - #[inline] - pub fn format(&self) -> format::Sample { - unsafe { - if (*self.as_ptr()).format == -1 { - format::Sample::None - } - else { - format::Sample::from(mem::transmute::<_, AVSampleFormat>(((*self.as_ptr()).format))) - } - } - } + #[inline] + pub fn format(&self) -> format::Sample { + unsafe { + if (*self.as_ptr()).format == -1 { + format::Sample::None + } else { + format::Sample::from(mem::transmute::<_, AVSampleFormat>((*self.as_ptr()).format)) + } + } + } - #[inline] - pub fn set_format(&mut self, value: format::Sample) { - unsafe { - (*self.as_mut_ptr()).format = mem::transmute::(value.into()); - } - } + #[inline] + pub fn set_format(&mut self, value: format::Sample) { + unsafe { + (*self.as_mut_ptr()).format = mem::transmute::(value.into()); + } + } - #[inline] - pub fn channel_layout(&self) -> ChannelLayout { - unsafe { - ChannelLayout::from_bits_truncate(av_frame_get_channel_layout(self.as_ptr()) as c_ulonglong) - } - } + #[inline] + pub fn channel_layout(&self) -> ChannelLayout { + unsafe { + ChannelLayout::from_bits_truncate(av_frame_get_channel_layout(self.as_ptr()) as c_ulonglong) + } + } - #[inline] - pub fn set_channel_layout(&mut self, value: ChannelLayout) { - unsafe { - av_frame_set_channel_layout(self.as_mut_ptr(), value.bits() as int64_t); - } - } + #[inline] + pub fn set_channel_layout(&mut self, value: ChannelLayout) { + unsafe { + av_frame_set_channel_layout(self.as_mut_ptr(), value.bits() as int64_t); + } + } - #[inline] - pub fn channels(&self) -> u16 { - unsafe { - av_frame_get_channels(self.as_ptr()) as u16 - } - } + #[inline] + pub fn channels(&self) -> u16 { + unsafe { av_frame_get_channels(self.as_ptr()) as u16 } + } - #[inline] - pub fn set_channels(&mut self, value: u16) { - unsafe { - av_frame_set_channels(self.as_mut_ptr(), value as c_int); - } - } + #[inline] + pub fn set_channels(&mut self, value: u16) { + unsafe { + av_frame_set_channels(self.as_mut_ptr(), i32::from(value)); + } + } - #[inline] - pub fn rate(&self) -> u32 { - unsafe { - av_frame_get_sample_rate(self.as_ptr()) as u32 - } - } + #[inline] + pub fn rate(&self) -> u32 { + unsafe { av_frame_get_sample_rate(self.as_ptr()) as u32 } + } - #[inline] - pub fn set_rate(&mut self, value: u32) { - unsafe { - av_frame_set_sample_rate(self.as_mut_ptr(), value as c_int); - } - } + #[inline] + pub fn set_rate(&mut self, value: u32) { + unsafe { + av_frame_set_sample_rate(self.as_mut_ptr(), value as c_int); + } + } - #[inline] - pub fn samples(&self) -> usize { - unsafe { - (*self.as_ptr()).nb_samples as usize - } - } + #[inline] + pub fn samples(&self) -> usize { + unsafe { (*self.as_ptr()).nb_samples as usize } + } - #[inline] - pub fn set_samples(&mut self, value: usize) { - unsafe { - (*self.as_mut_ptr()).nb_samples = value as c_int; - } - } + #[inline] + pub fn set_samples(&mut self, value: usize) { + unsafe { + (*self.as_mut_ptr()).nb_samples = value as c_int; + } + } - #[inline] - pub fn is_planar(&self) -> bool { - self.format().is_planar() - } + #[inline] + pub fn is_planar(&self) -> bool { + self.format().is_planar() + } - #[inline] - pub fn is_packed(&self) -> bool { - self.format().is_packed() - } + #[inline] + pub fn is_packed(&self) -> bool { + self.format().is_packed() + } - #[inline] - pub fn planes(&self) -> usize { - unsafe { - if (*self.as_ptr()).linesize[0] == 0 { - return 0; - } - } + #[inline] + pub fn planes(&self) -> usize { + unsafe { + if (*self.as_ptr()).linesize[0] == 0 { + return 0; + } + } - if self.is_packed() { - 1 - } - else { - self.channels() as usize - } - } + if self.is_packed() { + 1 + } else { + self.channels() as usize + } + } - #[inline] - pub fn plane(&self, index: usize) -> &[T] { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn plane(&self, index: usize) -> &[T] { + if index >= self.planes() { + panic!("out of bounds"); + } - if !::is_valid(self.format(), self.channels()) { - panic!("unsupported type"); - } + if !::is_valid(self.format(), self.channels()) { + panic!("unsupported type"); + } - unsafe { - slice::from_raw_parts(mem::transmute((*self.as_ptr()).data[index]), - self.samples()) - } - } + unsafe { + slice::from_raw_parts(mem::transmute((*self.as_ptr()).data[index]), self.samples()) + } + } - #[inline] - pub fn plane_mut(&mut self, index: usize) -> &mut [T] { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn plane_mut(&mut self, index: usize) -> &mut [T] { + if index >= self.planes() { + panic!("out of bounds"); + } - if !::is_valid(self.format(), self.channels()) { - panic!("unsupported type"); - } + if !::is_valid(self.format(), self.channels()) { + panic!("unsupported type"); + } - unsafe { - slice::from_raw_parts_mut(mem::transmute((*self.as_mut_ptr()).data[index]), - self.samples()) - } - } + unsafe { + slice::from_raw_parts_mut( + mem::transmute((*self.as_mut_ptr()).data[index]), + self.samples(), + ) + } + } - #[inline] - pub fn data(&self, index: usize) -> &[u8] { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn data(&self, index: usize) -> &[u8] { + if index >= self.planes() { + panic!("out of bounds"); + } - unsafe { - slice::from_raw_parts((*self.as_ptr()).data[index], - (*self.as_ptr()).linesize[index] as usize) - } - } + unsafe { + slice::from_raw_parts( + (*self.as_ptr()).data[index], + (*self.as_ptr()).linesize[index] as usize, + ) + } + } - #[inline] - pub fn data_mut(&mut self, index: usize) -> &mut [u8] { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn data_mut(&mut self, index: usize) -> &mut [u8] { + if index >= self.planes() { + panic!("out of bounds"); + } - unsafe { - slice::from_raw_parts_mut((*self.as_mut_ptr()).data[index], - (*self.as_ptr()).linesize[index] as usize) - } - } + unsafe { + slice::from_raw_parts_mut( + (*self.as_mut_ptr()).data[index], + (*self.as_ptr()).linesize[index] as usize, + ) + } + } } impl Deref for Audio { - type Target = Frame; + type Target = Frame; - fn deref(&self) -> &::Target { - &self.0 - } + fn deref(&self) -> &::Target { + &self.0 + } } impl DerefMut for Audio { - fn deref_mut(&mut self) -> &mut::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } } impl ::std::fmt::Debug for Audio { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { - try!(f.write_str("ffmpeg::frame::Audio { ")); - try!(f.write_str(&format!("format: {:?}, ", self.format()))); - try!(f.write_str(&format!("channels: {:?}, ", self.channels()))); - try!(f.write_str(&format!("rate: {:?}, ", self.rate()))); - try!(f.write_str(&format!("samples: {:?} ", self.samples()))); - f.write_str("}") - } + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { + f.write_str("ffmpeg::frame::Audio { ")?; + f.write_str(&format!("format: {:?}, ", self.format()))?; + f.write_str(&format!("channels: {:?}, ", self.channels()))?; + f.write_str(&format!("rate: {:?}, ", self.rate()))?; + f.write_str(&format!("samples: {:?} ", self.samples()))?; + f.write_str("}") + } } impl Clone for Audio { - fn clone(&self) -> Self { - let mut cloned = Audio::new(self.format(), self.samples(), self.channel_layout()); - cloned.clone_from(self); + fn clone(&self) -> Self { + let mut cloned = Audio::new(self.format(), self.samples(), self.channel_layout()); + cloned.clone_from(self); - cloned - } + cloned + } - fn clone_from(&mut self, source: &Self) { - unsafe { - av_frame_copy(self.as_mut_ptr(), source.as_ptr()); - av_frame_copy_props(self.as_mut_ptr(), source.as_ptr()); - } - } + fn clone_from(&mut self, source: &Self) { + unsafe { + av_frame_copy(self.as_mut_ptr(), source.as_ptr()); + av_frame_copy_props(self.as_mut_ptr(), source.as_ptr()); + } + } } impl From for Audio { - fn from(frame: Frame) -> Self { - Audio(frame) - } + fn from(frame: Frame) -> Self { + Audio(frame) + } } pub unsafe trait Sample { - fn is_valid(format: format::Sample, channels: u16) -> bool; + fn is_valid(format: format::Sample, channels: u16) -> bool; } unsafe impl Sample for u8 { - #[inline(always)] - fn is_valid(format: format::Sample, _channels: u16) -> bool { - if let format::Sample::U8(..) = format { - true - } - else { - false - } - } + #[inline(always)] + fn is_valid(format: format::Sample, _channels: u16) -> bool { + if let format::Sample::U8(..) = format { + true + } else { + false + } + } } unsafe impl Sample for (u8, u8) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 2 && format == format::Sample::U8(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 2 && format == format::Sample::U8(format::sample::Type::Packed) + } } unsafe impl Sample for (u8, u8, u8) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 3 && format == format::Sample::U8(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 3 && format == format::Sample::U8(format::sample::Type::Packed) + } } unsafe impl Sample for (u8, u8, u8, u8) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 4 && format == format::Sample::U8(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 4 && format == format::Sample::U8(format::sample::Type::Packed) + } } unsafe impl Sample for (u8, u8, u8, u8, u8) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 5 && format == format::Sample::U8(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 5 && format == format::Sample::U8(format::sample::Type::Packed) + } } unsafe impl Sample for (u8, u8, u8, u8, u8, u8) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 6 && format == format::Sample::U8(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 6 && format == format::Sample::U8(format::sample::Type::Packed) + } } unsafe impl Sample for (u8, u8, u8, u8, u8, u8, u8) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 7 && format == format::Sample::U8(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 7 && format == format::Sample::U8(format::sample::Type::Packed) + } } unsafe impl Sample for i16 { - #[inline(always)] - fn is_valid(format: format::Sample, _channels: u16) -> bool { - if let format::Sample::I16(..) = format { - true - } - else { - false - } - } + #[inline(always)] + fn is_valid(format: format::Sample, _channels: u16) -> bool { + if let format::Sample::I16(..) = format { + true + } else { + false + } + } } unsafe impl Sample for (i16, i16) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 2 && format == format::Sample::I16(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 2 && format == format::Sample::I16(format::sample::Type::Packed) + } } unsafe impl Sample for (i16, i16, i16) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 3 && format == format::Sample::I16(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 3 && format == format::Sample::I16(format::sample::Type::Packed) + } } unsafe impl Sample for (i16, i16, i16, i16) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 4 && format == format::Sample::I16(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 4 && format == format::Sample::I16(format::sample::Type::Packed) + } } unsafe impl Sample for (i16, i16, i16, i16, i16) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 5 && format == format::Sample::I16(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 5 && format == format::Sample::I16(format::sample::Type::Packed) + } } unsafe impl Sample for (i16, i16, i16, i16, i16, i16) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 6 && format == format::Sample::I16(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 6 && format == format::Sample::I16(format::sample::Type::Packed) + } } unsafe impl Sample for (i16, i16, i16, i16, i16, i16, i16) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 7 && format == format::Sample::I16(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 7 && format == format::Sample::I16(format::sample::Type::Packed) + } } unsafe impl Sample for i32 { - #[inline(always)] - fn is_valid(format: format::Sample, _channels: u16) -> bool { - if let format::Sample::I32(..) = format { - true - } - else { - false - } - } + #[inline(always)] + fn is_valid(format: format::Sample, _channels: u16) -> bool { + if let format::Sample::I32(..) = format { + true + } else { + false + } + } } unsafe impl Sample for (i32, i32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 2 && format == format::Sample::I32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 2 && format == format::Sample::I32(format::sample::Type::Packed) + } } unsafe impl Sample for (i32, i32, i32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 3 && format == format::Sample::I32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 3 && format == format::Sample::I32(format::sample::Type::Packed) + } } unsafe impl Sample for (i32, i32, i32, i32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 4 && format == format::Sample::I32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 4 && format == format::Sample::I32(format::sample::Type::Packed) + } } unsafe impl Sample for (i32, i32, i32, i32, i32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 5 && format == format::Sample::I32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 5 && format == format::Sample::I32(format::sample::Type::Packed) + } } unsafe impl Sample for (i32, i32, i32, i32, i32, i32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 6 && format == format::Sample::I32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 6 && format == format::Sample::I32(format::sample::Type::Packed) + } } unsafe impl Sample for (i32, i32, i32, i32, i32, i32, i32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 7 && format == format::Sample::I32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 7 && format == format::Sample::I32(format::sample::Type::Packed) + } } unsafe impl Sample for f32 { - #[inline(always)] - fn is_valid(format: format::Sample, _channels: u16) -> bool { - if let format::Sample::F32(..) = format { - true - } - else { - false - } - } + #[inline(always)] + fn is_valid(format: format::Sample, _channels: u16) -> bool { + if let format::Sample::F32(..) = format { + true + } else { + false + } + } } unsafe impl Sample for (f32, f32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 2 && format == format::Sample::F32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 2 && format == format::Sample::F32(format::sample::Type::Packed) + } } unsafe impl Sample for (f32, f32, f32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 3 && format == format::Sample::F32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 3 && format == format::Sample::F32(format::sample::Type::Packed) + } } unsafe impl Sample for (f32, f32, f32, f32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 4 && format == format::Sample::F32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 4 && format == format::Sample::F32(format::sample::Type::Packed) + } } unsafe impl Sample for (f32, f32, f32, f32, f32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 5 && format == format::Sample::F32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 5 && format == format::Sample::F32(format::sample::Type::Packed) + } } unsafe impl Sample for (f32, f32, f32, f32, f32, f32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 6 && format == format::Sample::F32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 6 && format == format::Sample::F32(format::sample::Type::Packed) + } } unsafe impl Sample for (f32, f32, f32, f32, f32, f32, f32) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 7 && format == format::Sample::F32(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 7 && format == format::Sample::F32(format::sample::Type::Packed) + } } unsafe impl Sample for f64 { - #[inline(always)] - fn is_valid(format: format::Sample, _channels: u16) -> bool { - if let format::Sample::F64(..) = format { - true - } - else { - false - } - } + #[inline(always)] + fn is_valid(format: format::Sample, _channels: u16) -> bool { + if let format::Sample::F64(..) = format { + true + } else { + false + } + } } unsafe impl Sample for (f64, f64) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 2 && format == format::Sample::F64(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 2 && format == format::Sample::F64(format::sample::Type::Packed) + } } unsafe impl Sample for (f64, f64, f64) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 3 && format == format::Sample::F64(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 3 && format == format::Sample::F64(format::sample::Type::Packed) + } } unsafe impl Sample for (f64, f64, f64, f64) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 4 && format == format::Sample::F64(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 4 && format == format::Sample::F64(format::sample::Type::Packed) + } } unsafe impl Sample for (f64, f64, f64, f64, f64) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 5 && format == format::Sample::F64(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 5 && format == format::Sample::F64(format::sample::Type::Packed) + } } unsafe impl Sample for (f64, f64, f64, f64, f64, f64) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 6 && format == format::Sample::F64(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 6 && format == format::Sample::F64(format::sample::Type::Packed) + } } unsafe impl Sample for (f64, f64, f64, f64, f64, f64, f64) { - #[inline(always)] - fn is_valid(format: format::Sample, channels: u16) -> bool { - channels == 7 && format == format::Sample::F64(format::sample::Type::Packed) - } + #[inline(always)] + fn is_valid(format: format::Sample, channels: u16) -> bool { + channels == 7 && format == format::Sample::F64(format::sample::Type::Packed) + } } diff --git a/src/util/frame/flag.rs b/src/util/frame/flag.rs index a1cc67e..b14510f 100644 --- a/src/util/frame/flag.rs +++ b/src/util/frame/flag.rs @@ -1,8 +1,8 @@ -use libc::c_int; use ffi::*; +use libc::c_int; bitflags! { - pub struct Flags: c_int { - const CORRUPT = AV_FRAME_FLAG_CORRUPT; - } + pub struct Flags: c_int { + const CORRUPT = AV_FRAME_FLAG_CORRUPT; + } } diff --git a/src/util/frame/mod.rs b/src/util/frame/mod.rs index 8b60909..4c3eaca 100644 --- a/src/util/frame/mod.rs +++ b/src/util/frame/mod.rs @@ -10,180 +10,176 @@ pub use self::audio::Audio; pub mod flag; pub use self::flag::Flags; -use libc::c_int; use ffi::*; -use ::{Dictionary, DictionaryRef}; +use libc::c_int; +use {Dictionary, DictionaryRef}; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct Packet { - pub duration: i64, - pub position: i64, - pub size: usize, + pub duration: i64, + pub position: i64, + pub size: usize, - pub pts: i64, - pub dts: i64, + pub pts: i64, + pub dts: i64, } #[derive(PartialEq, Eq)] pub struct Frame { - ptr: *mut AVFrame, + ptr: *mut AVFrame, - _own: bool, + _own: bool, } -unsafe impl Send for Frame { } -unsafe impl Sync for Frame { } +unsafe impl Send for Frame {} +unsafe impl Sync for Frame {} impl Frame { - #[inline(always)] - pub unsafe fn wrap(ptr: *mut AVFrame) -> Self { - Frame { ptr: ptr, _own: false } - } + #[inline(always)] + pub unsafe fn wrap(ptr: *mut AVFrame) -> Self { + Frame { + ptr: ptr, + _own: false, + } + } - #[inline(always)] - pub unsafe fn empty() -> Self { - Frame { ptr: av_frame_alloc(), _own: true } - } + #[inline(always)] + pub unsafe fn empty() -> Self { + Frame { + ptr: av_frame_alloc(), + _own: true, + } + } - #[inline(always)] - pub unsafe fn as_ptr(&self) -> *const AVFrame { - self.ptr as *const _ - } + #[inline(always)] + pub unsafe fn as_ptr(&self) -> *const AVFrame { + self.ptr as *const _ + } - #[inline(always)] - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrame { - self.ptr - } + #[inline(always)] + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrame { + self.ptr + } - #[inline(always)] - pub unsafe fn is_empty(&self) -> bool { - (*self.as_ptr()).data[0].is_null() - } + #[inline(always)] + pub unsafe fn is_empty(&self) -> bool { + (*self.as_ptr()).data[0].is_null() + } } impl Frame { - #[inline] - pub fn is_key(&self) -> bool { - unsafe { - (*self.as_ptr()).key_frame == 1 - } - } + #[inline] + pub fn is_key(&self) -> bool { + unsafe { (*self.as_ptr()).key_frame == 1 } + } - #[inline] - pub fn is_corrupt(&self) -> bool { - self.flags().contains(flag::CORRUPT) - } + #[inline] + pub fn is_corrupt(&self) -> bool { + self.flags().contains(flag::CORRUPT) + } - #[inline] - pub fn packet(&self) -> Packet { - unsafe { - Packet { - duration: av_frame_get_pkt_duration(self.as_ptr()) as i64, - position: av_frame_get_pkt_pos(self.as_ptr()) as i64, - size: av_frame_get_pkt_size(self.as_ptr()) as usize, + #[inline] + pub fn packet(&self) -> Packet { + unsafe { + Packet { + duration: av_frame_get_pkt_duration(self.as_ptr()) as i64, + position: av_frame_get_pkt_pos(self.as_ptr()) as i64, + size: av_frame_get_pkt_size(self.as_ptr()) as usize, - pts: (*self.as_ptr()).pkt_pts, - dts: (*self.as_ptr()).pkt_dts, - } - } - } + pts: (*self.as_ptr()).pkt_pts, + dts: (*self.as_ptr()).pkt_dts, + } + } + } - #[inline] - pub fn pts(&self) -> Option { - unsafe { - match (*self.as_ptr()).pts { - AV_NOPTS_VALUE => None, - pts => Some(pts as i64), - } - } - } + #[inline] + pub fn pts(&self) -> Option { + unsafe { + match (*self.as_ptr()).pts { + AV_NOPTS_VALUE => None, + pts => Some(pts as i64), + } + } + } - #[inline] - pub fn set_pts(&mut self, value: Option) { - unsafe { - (*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE); - } - } + #[inline] + pub fn set_pts(&mut self, value: Option) { + unsafe { + (*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE); + } + } - #[inline] - pub fn timestamp(&self) -> Option { - unsafe { - match av_frame_get_best_effort_timestamp(self.as_ptr()) { - AV_NOPTS_VALUE => None, - t => Some(t as i64) - } - } - } + #[inline] + pub fn timestamp(&self) -> Option { + unsafe { + match av_frame_get_best_effort_timestamp(self.as_ptr()) { + AV_NOPTS_VALUE => None, + t => Some(t as i64), + } + } + } - #[inline] - pub fn quality(&self) -> usize { - unsafe { - (*self.as_ptr()).quality as usize - } - } + #[inline] + pub fn quality(&self) -> usize { + unsafe { (*self.as_ptr()).quality as usize } + } - #[inline] - pub fn flags(&self) -> Flags { - unsafe { - Flags::from_bits_truncate((*self.as_ptr()).flags) - } - } + #[inline] + pub fn flags(&self) -> Flags { + unsafe { Flags::from_bits_truncate((*self.as_ptr()).flags) } + } - #[inline] - pub fn metadata(&self) -> DictionaryRef { - unsafe { - DictionaryRef::wrap(av_frame_get_metadata(self.as_ptr())) - } - } + #[inline] + pub fn metadata(&self) -> DictionaryRef { + unsafe { DictionaryRef::wrap(av_frame_get_metadata(self.as_ptr())) } + } - #[inline] - pub fn set_metadata(&mut self, value: Dictionary) { - unsafe { - av_frame_set_metadata(self.as_mut_ptr(), value.disown()); - } - } + #[inline] + pub fn set_metadata(&mut self, value: Dictionary) { + unsafe { + av_frame_set_metadata(self.as_mut_ptr(), value.disown()); + } + } - #[inline] - pub fn side_data(&self, kind: side_data::Type) -> Option { - unsafe { - let ptr = av_frame_get_side_data(self.as_ptr(), kind.into()); + #[inline] + pub fn side_data(&self, kind: side_data::Type) -> Option { + unsafe { + let ptr = av_frame_get_side_data(self.as_ptr(), kind.into()); - if ptr.is_null() { - None - } - else { - Some(SideData::wrap(ptr)) - } - } - } + if ptr.is_null() { + None + } else { + Some(SideData::wrap(ptr)) + } + } + } - #[inline] - pub fn new_side_data(&mut self, kind: side_data::Type, size: usize) -> Option { - unsafe { - let ptr = av_frame_new_side_data(self.as_mut_ptr(), kind.into(), size as c_int); + #[inline] + pub fn new_side_data(&mut self, kind: side_data::Type, size: usize) -> Option { + unsafe { + let ptr = av_frame_new_side_data(self.as_mut_ptr(), kind.into(), size as c_int); - if ptr.is_null() { - None - } - else { - Some(SideData::wrap(ptr)) - } - } - } + if ptr.is_null() { + None + } else { + Some(SideData::wrap(ptr)) + } + } + } - #[inline] - pub fn remove_side_data(&mut self, kind: side_data::Type) { - unsafe { - av_frame_remove_side_data(self.as_mut_ptr(), kind.into()); - } - } + #[inline] + pub fn remove_side_data(&mut self, kind: side_data::Type) { + unsafe { + av_frame_remove_side_data(self.as_mut_ptr(), kind.into()); + } + } } impl Drop for Frame { - #[inline] - fn drop(&mut self) { - unsafe { - av_frame_free(&mut self.as_mut_ptr()); - } - } + #[inline] + fn drop(&mut self) { + unsafe { + av_frame_free(&mut self.as_mut_ptr()); + } + } } diff --git a/src/util/frame/side_data.rs b/src/util/frame/side_data.rs index 662622f..acc5024 100644 --- a/src/util/frame/side_data.rs +++ b/src/util/frame/side_data.rs @@ -1,135 +1,132 @@ +use std::ffi::CStr; use std::marker::PhantomData; use std::slice; -use std::ffi::CStr; use std::str::from_utf8_unchecked; -use ffi::*; -use ffi::AVFrameSideDataType::*; use super::Frame; -use ::DictionaryRef; +use ffi::AVFrameSideDataType::*; +use ffi::*; +use DictionaryRef; #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Type { - PanScan, - A53CC, - Stereo3D, - MatrixEncoding, - DownMixInfo, - ReplayGain, - DisplayMatrix, - AFD, - MotionVectors, - SkipSamples, - AudioServiceType, - MasteringDisplayMetadata, - GOPTimecode, - Spherical, + PanScan, + A53CC, + Stereo3D, + MatrixEncoding, + DownMixInfo, + ReplayGain, + DisplayMatrix, + AFD, + MotionVectors, + SkipSamples, + AudioServiceType, + MasteringDisplayMetadata, + GOPTimecode, + Spherical, - ContentLightLevel, - IccProfile, + ContentLightLevel, + IccProfile, } impl Type { - #[inline] - pub fn name(&self) -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(av_frame_side_data_name((*self).into())).to_bytes()) - } - } + #[inline] + pub fn name(&self) -> &'static str { + unsafe { + from_utf8_unchecked(CStr::from_ptr(av_frame_side_data_name((*self).into())).to_bytes()) + } + } } impl From for Type { - #[inline(always)] - fn from(value: AVFrameSideDataType) -> Self { - match value { - AV_FRAME_DATA_PANSCAN => Type::PanScan, - AV_FRAME_DATA_A53_CC => Type::A53CC, - AV_FRAME_DATA_STEREO3D => Type::Stereo3D, - AV_FRAME_DATA_MATRIXENCODING => Type::MatrixEncoding, - AV_FRAME_DATA_DOWNMIX_INFO => Type::DownMixInfo, - AV_FRAME_DATA_REPLAYGAIN => Type::ReplayGain, - AV_FRAME_DATA_DISPLAYMATRIX => Type::DisplayMatrix, - AV_FRAME_DATA_AFD => Type::AFD, - AV_FRAME_DATA_MOTION_VECTORS => Type::MotionVectors, - AV_FRAME_DATA_SKIP_SAMPLES => Type::SkipSamples, - AV_FRAME_DATA_AUDIO_SERVICE_TYPE => Type::AudioServiceType, - AV_FRAME_DATA_MASTERING_DISPLAY_METADATA => Type::MasteringDisplayMetadata, - AV_FRAME_DATA_GOP_TIMECODE => Type::GOPTimecode, - AV_FRAME_DATA_SPHERICAL => Type::Spherical, + #[inline(always)] + fn from(value: AVFrameSideDataType) -> Self { + match value { + AV_FRAME_DATA_PANSCAN => Type::PanScan, + AV_FRAME_DATA_A53_CC => Type::A53CC, + AV_FRAME_DATA_STEREO3D => Type::Stereo3D, + AV_FRAME_DATA_MATRIXENCODING => Type::MatrixEncoding, + AV_FRAME_DATA_DOWNMIX_INFO => Type::DownMixInfo, + AV_FRAME_DATA_REPLAYGAIN => Type::ReplayGain, + AV_FRAME_DATA_DISPLAYMATRIX => Type::DisplayMatrix, + AV_FRAME_DATA_AFD => Type::AFD, + AV_FRAME_DATA_MOTION_VECTORS => Type::MotionVectors, + AV_FRAME_DATA_SKIP_SAMPLES => Type::SkipSamples, + AV_FRAME_DATA_AUDIO_SERVICE_TYPE => Type::AudioServiceType, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA => Type::MasteringDisplayMetadata, + AV_FRAME_DATA_GOP_TIMECODE => Type::GOPTimecode, + AV_FRAME_DATA_SPHERICAL => Type::Spherical, - AV_FRAME_DATA_CONTENT_LIGHT_LEVEL => Type::ContentLightLevel, - AV_FRAME_DATA_ICC_PROFILE => Type::IccProfile, - } - } + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL => Type::ContentLightLevel, + AV_FRAME_DATA_ICC_PROFILE => Type::IccProfile, + } + } } impl Into for Type { - #[inline(always)] - fn into(self) -> AVFrameSideDataType { - match self { - Type::PanScan => AV_FRAME_DATA_PANSCAN, - Type::A53CC => AV_FRAME_DATA_A53_CC, - Type::Stereo3D => AV_FRAME_DATA_STEREO3D, - Type::MatrixEncoding => AV_FRAME_DATA_MATRIXENCODING, - Type::DownMixInfo => AV_FRAME_DATA_DOWNMIX_INFO, - Type::ReplayGain => AV_FRAME_DATA_REPLAYGAIN, - Type::DisplayMatrix => AV_FRAME_DATA_DISPLAYMATRIX, - Type::AFD => AV_FRAME_DATA_AFD, - Type::MotionVectors => AV_FRAME_DATA_MOTION_VECTORS, - Type::SkipSamples => AV_FRAME_DATA_SKIP_SAMPLES, - Type::AudioServiceType => AV_FRAME_DATA_AUDIO_SERVICE_TYPE, - Type::MasteringDisplayMetadata => AV_FRAME_DATA_MASTERING_DISPLAY_METADATA, - Type::GOPTimecode => AV_FRAME_DATA_GOP_TIMECODE, - Type::Spherical => AV_FRAME_DATA_SPHERICAL, + #[inline(always)] + fn into(self) -> AVFrameSideDataType { + match self { + Type::PanScan => AV_FRAME_DATA_PANSCAN, + Type::A53CC => AV_FRAME_DATA_A53_CC, + Type::Stereo3D => AV_FRAME_DATA_STEREO3D, + Type::MatrixEncoding => AV_FRAME_DATA_MATRIXENCODING, + Type::DownMixInfo => AV_FRAME_DATA_DOWNMIX_INFO, + Type::ReplayGain => AV_FRAME_DATA_REPLAYGAIN, + Type::DisplayMatrix => AV_FRAME_DATA_DISPLAYMATRIX, + Type::AFD => AV_FRAME_DATA_AFD, + Type::MotionVectors => AV_FRAME_DATA_MOTION_VECTORS, + Type::SkipSamples => AV_FRAME_DATA_SKIP_SAMPLES, + Type::AudioServiceType => AV_FRAME_DATA_AUDIO_SERVICE_TYPE, + Type::MasteringDisplayMetadata => AV_FRAME_DATA_MASTERING_DISPLAY_METADATA, + Type::GOPTimecode => AV_FRAME_DATA_GOP_TIMECODE, + Type::Spherical => AV_FRAME_DATA_SPHERICAL, - Type::ContentLightLevel => AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, - Type::IccProfile => AV_FRAME_DATA_ICC_PROFILE, - } - } + Type::ContentLightLevel => AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, + Type::IccProfile => AV_FRAME_DATA_ICC_PROFILE, + } + } } pub struct SideData<'a> { - ptr: *mut AVFrameSideData, + ptr: *mut AVFrameSideData, - _marker: PhantomData<&'a Frame>, + _marker: PhantomData<&'a Frame>, } impl<'a> SideData<'a> { - #[inline(always)] - pub unsafe fn wrap(ptr: *mut AVFrameSideData) -> Self { - SideData { ptr: ptr, _marker: PhantomData } - } + #[inline(always)] + pub unsafe fn wrap(ptr: *mut AVFrameSideData) -> Self { + SideData { + ptr: ptr, + _marker: PhantomData, + } + } - #[inline(always)] - pub unsafe fn as_ptr(&self) -> *const AVFrameSideData { - self.ptr as *const _ - } + #[inline(always)] + pub unsafe fn as_ptr(&self) -> *const AVFrameSideData { + self.ptr as *const _ + } - #[inline(always)] - pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrameSideData { - self.ptr - } + #[inline(always)] + pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrameSideData { + self.ptr + } } impl<'a> SideData<'a> { - #[inline] - pub fn kind(&self) -> Type { - unsafe { - Type::from((*self.as_ptr()).type_) - } - } + #[inline] + pub fn kind(&self) -> Type { + unsafe { Type::from((*self.as_ptr()).type_) } + } - #[inline] - pub fn data(&self) -> &[u8] { - unsafe { - slice::from_raw_parts((*self.as_ptr()).data, (*self.as_ptr()).size as usize) - } - } + #[inline] + pub fn data(&self) -> &[u8] { + unsafe { slice::from_raw_parts((*self.as_ptr()).data, (*self.as_ptr()).size as usize) } + } - #[inline] - pub fn metadata(&self) -> DictionaryRef { - unsafe { - DictionaryRef::wrap((*self.as_ptr()).metadata) - } - } + #[inline] + pub fn metadata(&self) -> DictionaryRef { + unsafe { DictionaryRef::wrap((*self.as_ptr()).metadata) } + } } diff --git a/src/util/frame/video.rs b/src/util/frame/video.rs index 7117a80..d62b41c 100644 --- a/src/util/frame/video.rs +++ b/src/util/frame/video.rs @@ -1,448 +1,417 @@ use std::mem; -use std::slice; use std::ops::{Deref, DerefMut}; +use std::slice; -use libc::c_int; -use ffi::*; -use ::Rational; -use ::util::format; -use ::util::chroma; -use ::picture; -use ::color; use super::Frame; +use color; +use ffi::*; +use libc::c_int; +use picture; +use util::chroma; +use util::format; +use Rational; #[derive(PartialEq, Eq)] pub struct Video(Frame); impl Video { - #[inline(always)] - pub unsafe fn wrap(ptr: *mut AVFrame) -> Self { - Video(Frame::wrap(ptr)) - } + #[inline(always)] + pub unsafe fn wrap(ptr: *mut AVFrame) -> Self { + Video(Frame::wrap(ptr)) + } - #[inline] - pub unsafe fn alloc(&mut self, format: format::Pixel, width: u32, height: u32) { - self.set_format(format); - self.set_width(width); - self.set_height(height); + #[inline] + pub unsafe fn alloc(&mut self, format: format::Pixel, width: u32, height: u32) { + self.set_format(format); + self.set_width(width); + self.set_height(height); - av_frame_get_buffer(self.as_mut_ptr(), 32); - } + av_frame_get_buffer(self.as_mut_ptr(), 32); + } } impl Video { - #[inline(always)] - pub fn empty() -> Self { - unsafe { - Video(Frame::empty()) - } - } + #[inline(always)] + pub fn empty() -> Self { + unsafe { Video(Frame::empty()) } + } - #[inline] - pub fn new(format: format::Pixel, width: u32, height: u32) -> Self { - unsafe { - let mut frame = Video::empty(); - frame.alloc(format, width, height); + #[inline] + pub fn new(format: format::Pixel, width: u32, height: u32) -> Self { + unsafe { + let mut frame = Video::empty(); + frame.alloc(format, width, height); - frame - } - } + frame + } + } - #[inline] - pub fn format(&self) -> format::Pixel { - unsafe { - if (*self.as_ptr()).format == -1 { - format::Pixel::None - } - else { - format::Pixel::from(mem::transmute::<_, AVPixelFormat>(((*self.as_ptr()).format))) - } - } - } + #[inline] + pub fn format(&self) -> format::Pixel { + unsafe { + if (*self.as_ptr()).format == -1 { + format::Pixel::None + } else { + format::Pixel::from(mem::transmute::<_, AVPixelFormat>((*self.as_ptr()).format)) + } + } + } - #[inline] - pub fn set_format(&mut self, value: format::Pixel) { - unsafe { - (*self.as_mut_ptr()).format = mem::transmute::(value.into()); - } - } + #[inline] + pub fn set_format(&mut self, value: format::Pixel) { + unsafe { + (*self.as_mut_ptr()).format = mem::transmute::(value.into()); + } + } - #[inline] - pub fn kind(&self) -> picture::Type { - unsafe { - picture::Type::from((*self.as_ptr()).pict_type) - } - } + #[inline] + pub fn kind(&self) -> picture::Type { + unsafe { picture::Type::from((*self.as_ptr()).pict_type) } + } - #[inline] - pub fn set_kind(&mut self, value: picture::Type) { - unsafe { - (*self.as_mut_ptr()).pict_type = value.into(); - } - } + #[inline] + pub fn set_kind(&mut self, value: picture::Type) { + unsafe { + (*self.as_mut_ptr()).pict_type = value.into(); + } + } - #[inline] - pub fn is_interlaced(&self) -> bool { - unsafe { - (*self.as_ptr()).interlaced_frame != 0 - } - } + #[inline] + pub fn is_interlaced(&self) -> bool { + unsafe { (*self.as_ptr()).interlaced_frame != 0 } + } - #[inline] - pub fn is_top_first(&self) -> bool { - unsafe { - (*self.as_ptr()).top_field_first != 0 - } - } + #[inline] + pub fn is_top_first(&self) -> bool { + unsafe { (*self.as_ptr()).top_field_first != 0 } + } - #[inline] - pub fn has_palette_changed(&self) -> bool { - unsafe { - (*self.as_ptr()).palette_has_changed != 0 - } - } + #[inline] + pub fn has_palette_changed(&self) -> bool { + unsafe { (*self.as_ptr()).palette_has_changed != 0 } + } - #[inline] - pub fn width(&self) -> u32 { - unsafe { - (*self.as_ptr()).width as u32 - } - } + #[inline] + pub fn width(&self) -> u32 { + unsafe { (*self.as_ptr()).width as u32 } + } - #[inline] - pub fn set_width(&mut self, value: u32) { - unsafe { - (*self.as_mut_ptr()).width = value as c_int; - } - } + #[inline] + pub fn set_width(&mut self, value: u32) { + unsafe { + (*self.as_mut_ptr()).width = value as c_int; + } + } - #[inline] - pub fn height(&self) -> u32 { - unsafe { - (*self.as_ptr()).height as u32 - } - } + #[inline] + pub fn height(&self) -> u32 { + unsafe { (*self.as_ptr()).height as u32 } + } - #[inline] - pub fn set_height(&mut self, value: u32) { - unsafe { - (*self.as_mut_ptr()).height = value as c_int; - } - } + #[inline] + pub fn set_height(&mut self, value: u32) { + unsafe { + (*self.as_mut_ptr()).height = value as c_int; + } + } - #[inline] - pub fn color_space(&self) -> color::Space { - unsafe { - color::Space::from(av_frame_get_colorspace(self.as_ptr())) - } - } + #[inline] + pub fn color_space(&self) -> color::Space { + unsafe { color::Space::from(av_frame_get_colorspace(self.as_ptr())) } + } - #[inline] - pub fn set_color_space(&mut self, value: color::Space) { - unsafe { - av_frame_set_colorspace(self.as_mut_ptr(), value.into()); - } - } + #[inline] + pub fn set_color_space(&mut self, value: color::Space) { + unsafe { + av_frame_set_colorspace(self.as_mut_ptr(), value.into()); + } + } - #[inline] - pub fn color_range(&self) -> color::Range { - unsafe { - color::Range::from(av_frame_get_color_range(self.as_ptr())) - } - } + #[inline] + pub fn color_range(&self) -> color::Range { + unsafe { color::Range::from(av_frame_get_color_range(self.as_ptr())) } + } - #[inline] - pub fn set_color_range(&mut self, value: color::Range) { - unsafe { - av_frame_set_color_range(self.as_mut_ptr(), value.into()); - } - } + #[inline] + pub fn set_color_range(&mut self, value: color::Range) { + unsafe { + av_frame_set_color_range(self.as_mut_ptr(), value.into()); + } + } - #[inline] - pub fn color_primaries(&self) -> color::Primaries { - unsafe { - color::Primaries::from((*self.as_ptr()).color_primaries) - } - } + #[inline] + pub fn color_primaries(&self) -> color::Primaries { + unsafe { color::Primaries::from((*self.as_ptr()).color_primaries) } + } - #[inline] - pub fn set_color_primaries(&mut self, value: color::Primaries) { - unsafe { - (*self.as_mut_ptr()).color_primaries = value.into(); - } - } + #[inline] + pub fn set_color_primaries(&mut self, value: color::Primaries) { + unsafe { + (*self.as_mut_ptr()).color_primaries = value.into(); + } + } - #[inline] - pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic { - unsafe { - color::TransferCharacteristic::from((*self.as_ptr()).color_trc) - } - } + #[inline] + pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic { + unsafe { color::TransferCharacteristic::from((*self.as_ptr()).color_trc) } + } - #[inline] - pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) { - unsafe { - (*self.as_mut_ptr()).color_trc = value.into(); - } - } + #[inline] + pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) { + unsafe { + (*self.as_mut_ptr()).color_trc = value.into(); + } + } - #[inline] - pub fn chroma_location(&self) -> chroma::Location { - unsafe { - chroma::Location::from((*self.as_ptr()).chroma_location) - } - } + #[inline] + pub fn chroma_location(&self) -> chroma::Location { + unsafe { chroma::Location::from((*self.as_ptr()).chroma_location) } + } - #[inline] - pub fn aspect_ratio(&self) -> Rational { - unsafe { - Rational::from((*self.as_ptr()).sample_aspect_ratio) - } - } + #[inline] + pub fn aspect_ratio(&self) -> Rational { + unsafe { Rational::from((*self.as_ptr()).sample_aspect_ratio) } + } - #[inline] - pub fn coded_number(&self) -> usize { - unsafe { - (*self.as_ptr()).coded_picture_number as usize - } - } + #[inline] + pub fn coded_number(&self) -> usize { + unsafe { (*self.as_ptr()).coded_picture_number as usize } + } - #[inline] - pub fn display_number(&self) -> usize { - unsafe { - (*self.as_ptr()).display_picture_number as usize - } - } + #[inline] + pub fn display_number(&self) -> usize { + unsafe { (*self.as_ptr()).display_picture_number as usize } + } - #[inline] - pub fn repeat(&self) -> f64 { - unsafe { - (*self.as_ptr()).repeat_pict as f64 - } - } + #[inline] + pub fn repeat(&self) -> f64 { + unsafe { f64::from((*self.as_ptr()).repeat_pict) } + } - #[inline] - pub fn stride(&self, index: usize) -> usize { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn stride(&self, index: usize) -> usize { + if index >= self.planes() { + panic!("out of bounds"); + } - unsafe { - (*self.as_ptr()).linesize[index] as usize - } - } + unsafe { (*self.as_ptr()).linesize[index] as usize } + } - #[inline] - pub fn planes(&self) -> usize { - for i in 0 .. 8 { - unsafe { - if (*self.as_ptr()).linesize[i] == 0 { - return i; - } - } - } + #[inline] + pub fn planes(&self) -> usize { + for i in 0..8 { + unsafe { + if (*self.as_ptr()).linesize[i] == 0 { + return i; + } + } + } - 8 - } + 8 + } - #[inline] - pub fn plane_width(&self, index: usize) -> u32 { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn plane_width(&self, index: usize) -> u32 { + if index >= self.planes() { + panic!("out of bounds"); + } - // Logic taken from image_get_linesize(). - if index != 1 && index != 2 { - return self.width(); - } + // Logic taken from image_get_linesize(). + if index != 1 && index != 2 { + return self.width(); + } - if let Some(desc) = self.format().descriptor() { - let s = desc.log2_chroma_w(); - (self.width() + (1 << s) - 1) >> s - } - else { - self.width() - } - } + if let Some(desc) = self.format().descriptor() { + let s = desc.log2_chroma_w(); + (self.width() + (1 << s) - 1) >> s + } else { + self.width() + } + } - #[inline] - pub fn plane_height(&self, index: usize) -> u32 { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn plane_height(&self, index: usize) -> u32 { + if index >= self.planes() { + panic!("out of bounds"); + } - // Logic taken from av_image_fill_pointers(). - if index != 1 && index != 2 { - return self.height(); - } + // Logic taken from av_image_fill_pointers(). + if index != 1 && index != 2 { + return self.height(); + } - if let Some(desc) = self.format().descriptor() { - let s = desc.log2_chroma_h(); - (self.height() + (1 << s) - 1) >> s - } - else { - self.height() - } - } + if let Some(desc) = self.format().descriptor() { + let s = desc.log2_chroma_h(); + (self.height() + (1 << s) - 1) >> s + } else { + self.height() + } + } - #[inline] - pub fn plane(&self, index: usize) -> &[T] { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn plane(&self, index: usize) -> &[T] { + if index >= self.planes() { + panic!("out of bounds"); + } - if !::is_valid(self.format()) { - panic!("unsupported type"); - } + if !::is_valid(self.format()) { + panic!("unsupported type"); + } - unsafe { - slice::from_raw_parts( - mem::transmute((*self.as_ptr()).data[index]), - self.stride(index) * self.plane_height(index) as usize / mem::size_of::()) - } - } + unsafe { + slice::from_raw_parts( + mem::transmute((*self.as_ptr()).data[index]), + self.stride(index) * self.plane_height(index) as usize / mem::size_of::(), + ) + } + } - #[inline] - pub fn plane_mut(&mut self, index: usize) -> &mut [T] { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn plane_mut(&mut self, index: usize) -> &mut [T] { + if index >= self.planes() { + panic!("out of bounds"); + } - if !::is_valid(self.format()) { - panic!("unsupported type"); - } + if !::is_valid(self.format()) { + panic!("unsupported type"); + } - unsafe { - slice::from_raw_parts_mut( - mem::transmute((*self.as_mut_ptr()).data[index]), - self.stride(index) * self.plane_height(index) as usize / mem::size_of::()) - } - } + unsafe { + slice::from_raw_parts_mut( + mem::transmute((*self.as_mut_ptr()).data[index]), + self.stride(index) * self.plane_height(index) as usize / mem::size_of::(), + ) + } + } - #[inline] - pub fn data(&self, index: usize) -> &[u8] { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn data(&self, index: usize) -> &[u8] { + if index >= self.planes() { + panic!("out of bounds"); + } - unsafe { - slice::from_raw_parts((*self.as_ptr()).data[index], - self.stride(index) * self.plane_height(index) as usize) - } - } + unsafe { + slice::from_raw_parts( + (*self.as_ptr()).data[index], + self.stride(index) * self.plane_height(index) as usize, + ) + } + } - #[inline] - pub fn data_mut(&mut self, index: usize) -> &mut [u8] { - if index >= self.planes() { - panic!("out of bounds"); - } + #[inline] + pub fn data_mut(&mut self, index: usize) -> &mut [u8] { + if index >= self.planes() { + panic!("out of bounds"); + } - unsafe { - slice::from_raw_parts_mut((*self.as_mut_ptr()).data[index], - self.stride(index) * self.plane_height(index) as usize) - } - } + unsafe { + slice::from_raw_parts_mut( + (*self.as_mut_ptr()).data[index], + self.stride(index) * self.plane_height(index) as usize, + ) + } + } } impl Deref for Video { - type Target = Frame; + type Target = Frame; - #[inline] - fn deref(&self) -> &Frame { - &self.0 - } + #[inline] + fn deref(&self) -> &Frame { + &self.0 + } } impl DerefMut for Video { - #[inline] - fn deref_mut(&mut self) -> &mut Frame { - &mut self.0 - } + #[inline] + fn deref_mut(&mut self) -> &mut Frame { + &mut self.0 + } } impl Clone for Video { - #[inline] - fn clone(&self) -> Self { - let mut cloned = Video::new(self.format(), self.width(), self.height()); - cloned.clone_from(self); + #[inline] + fn clone(&self) -> Self { + let mut cloned = Video::new(self.format(), self.width(), self.height()); + cloned.clone_from(self); - cloned - } + cloned + } - #[inline] - fn clone_from(&mut self, source: &Self) { - unsafe { - av_frame_copy(self.as_mut_ptr(), source.as_ptr()); - av_frame_copy_props(self.as_mut_ptr(), source.as_ptr()); - } - } + #[inline] + fn clone_from(&mut self, source: &Self) { + unsafe { + av_frame_copy(self.as_mut_ptr(), source.as_ptr()); + av_frame_copy_props(self.as_mut_ptr(), source.as_ptr()); + } + } } impl From for Video { - #[inline] - fn from(frame: Frame) -> Self { - Video(frame) - } + #[inline] + fn from(frame: Frame) -> Self { + Video(frame) + } } pub unsafe trait Component { - fn is_valid(format: format::Pixel) -> bool; + fn is_valid(format: format::Pixel) -> bool; } #[cfg(feature = "image")] unsafe impl Component for ::image::Luma { - #[inline(always)] - fn is_valid(format: format::Pixel) -> bool { - format == format::Pixel::GRAY8 - } + #[inline(always)] + fn is_valid(format: format::Pixel) -> bool { + format == format::Pixel::GRAY8 + } } #[cfg(feature = "image")] unsafe impl Component for ::image::Rgb { - #[inline(always)] - fn is_valid(format: format::Pixel) -> bool { - format == format::Pixel::RGB24 - } + #[inline(always)] + fn is_valid(format: format::Pixel) -> bool { + format == format::Pixel::RGB24 + } } #[cfg(feature = "image")] unsafe impl Component for ::image::Rgba { - #[inline(always)] - fn is_valid(format: format::Pixel) -> bool { - format == format::Pixel::RGBA - } + #[inline(always)] + fn is_valid(format: format::Pixel) -> bool { + format == format::Pixel::RGBA + } } unsafe impl Component for [u8; 3] { - #[inline(always)] - fn is_valid(format: format::Pixel) -> bool { - format == format::Pixel::RGB24 || format == format::Pixel::BGR24 - } + #[inline(always)] + fn is_valid(format: format::Pixel) -> bool { + format == format::Pixel::RGB24 || format == format::Pixel::BGR24 + } } unsafe impl Component for (u8, u8, u8) { - #[inline(always)] - fn is_valid(format: format::Pixel) -> bool { - format == format::Pixel::RGB24 || format == format::Pixel::BGR24 - } + #[inline(always)] + fn is_valid(format: format::Pixel) -> bool { + format == format::Pixel::RGB24 || format == format::Pixel::BGR24 + } } unsafe impl Component for [u8; 4] { - #[inline(always)] - fn is_valid(format: format::Pixel) -> bool { - format == format::Pixel::RGBA || format == format::Pixel::BGRA || - format == format::Pixel::ARGB || format == format::Pixel::ABGR || - format == format::Pixel::RGBZ || format == format::Pixel::BGRZ || - format == format::Pixel::ZRGB || format == format::Pixel::ZBGR - } + #[inline(always)] + fn is_valid(format: format::Pixel) -> bool { + format == format::Pixel::RGBA || format == format::Pixel::BGRA + || format == format::Pixel::ARGB || format == format::Pixel::ABGR + || format == format::Pixel::RGBZ || format == format::Pixel::BGRZ + || format == format::Pixel::ZRGB || format == format::Pixel::ZBGR + } } unsafe impl Component for (u8, u8, u8, u8) { - #[inline(always)] - fn is_valid(format: format::Pixel) -> bool { - format == format::Pixel::RGBA || format == format::Pixel::BGRA || - format == format::Pixel::ARGB || format == format::Pixel::ABGR || - format == format::Pixel::RGBZ || format == format::Pixel::BGRZ || - format == format::Pixel::ZRGB || format == format::Pixel::ZBGR - } + #[inline(always)] + fn is_valid(format: format::Pixel) -> bool { + format == format::Pixel::RGBA || format == format::Pixel::BGRA + || format == format::Pixel::ARGB || format == format::Pixel::ABGR + || format == format::Pixel::RGBZ || format == format::Pixel::BGRZ + || format == format::Pixel::ZRGB || format == format::Pixel::ZBGR + } } diff --git a/src/util/interrupt.rs b/src/util/interrupt.rs index a417507..219b9ff 100644 --- a/src/util/interrupt.rs +++ b/src/util/interrupt.rs @@ -2,14 +2,15 @@ use std::panic; use std::process; use ffi::*; -use libc::{c_void, c_int}; +use libc::{c_int, c_void}; pub struct Interrupt { pub interrupt: AVIOInterruptCB, } extern "C" fn callback(opaque: *mut c_void) -> c_int - where F: FnMut() -> bool +where + F: FnMut() -> bool, { match panic::catch_unwind(|| (unsafe { &mut *(opaque as *mut F) })()) { Ok(ret) => ret as c_int, @@ -18,11 +19,14 @@ extern "C" fn callback(opaque: *mut c_void) -> c_int } pub fn new(opaque: Box) -> Interrupt - where F: FnMut() -> bool +where + F: FnMut() -> bool, { let interrupt_cb = AVIOInterruptCB { callback: Some(callback::), opaque: Box::into_raw(opaque) as *mut c_void, }; - Interrupt { interrupt: interrupt_cb } + Interrupt { + interrupt: interrupt_cb, + } } diff --git a/src/util/mathematics/rescale.rs b/src/util/mathematics/rescale.rs index 96dd107..5c4a8be 100644 --- a/src/util/mathematics/rescale.rs +++ b/src/util/mathematics/rescale.rs @@ -1,34 +1,47 @@ use ffi::*; -use ::{Rational, Rounding}; +use {Rational, Rounding}; pub const TIME_BASE: Rational = Rational(AV_TIME_BASE_Q.num, AV_TIME_BASE_Q.den); pub trait Rescale { - fn rescale(&self, source: S, destination: D) -> i64 - where S: Into, - D: Into; + fn rescale(&self, source: S, destination: D) -> i64 + where + S: Into, + D: Into; - fn rescale_with(&self, source: S, destination: D, rounding: Rounding) -> i64 - where S: Into, - D: Into; + fn rescale_with(&self, source: S, destination: D, rounding: Rounding) -> i64 + where + S: Into, + D: Into; } impl + Clone> Rescale for T { - fn rescale(&self, source: S, destination: D) -> i64 - where S: Into, - D: Into - { - unsafe { - av_rescale_q(self.clone().into(), source.into().into(), destination.into().into()).into() - } - } + fn rescale(&self, source: S, destination: D) -> i64 + where + S: Into, + D: Into, + { + unsafe { + av_rescale_q( + self.clone().into(), + source.into().into(), + destination.into().into(), + ) + } + } - fn rescale_with(&self, source: S, destination: D, rounding: Rounding) -> i64 - where S: Into, - D: Into - { - unsafe { - av_rescale_q_rnd(self.clone().into(), source.into().into(), destination.into().into(), rounding.into()).into() - } - } + fn rescale_with(&self, source: S, destination: D, rounding: Rounding) -> i64 + where + S: Into, + D: Into, + { + unsafe { + av_rescale_q_rnd( + self.clone().into(), + source.into().into(), + destination.into().into(), + rounding.into(), + ) + } + } } diff --git a/src/util/mathematics/rounding.rs b/src/util/mathematics/rounding.rs index 1c34808..6ed17da 100644 --- a/src/util/mathematics/rounding.rs +++ b/src/util/mathematics/rounding.rs @@ -1,42 +1,40 @@ -use ffi::*; use ffi::AVRounding::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Rounding { - Zero, - Infinity, - Down, - Up, - NearInfinity, - PassMinMax, + Zero, + Infinity, + Down, + Up, + NearInfinity, + PassMinMax, } impl From for Rounding { - #[inline(always)] - fn from(value: AVRounding) -> Self { - match value { - AV_ROUND_ZERO => Rounding::Zero, - AV_ROUND_INF => Rounding::Infinity, - AV_ROUND_DOWN => Rounding::Down, - AV_ROUND_UP => Rounding::Up, - AV_ROUND_NEAR_INF => Rounding::NearInfinity, - AV_ROUND_PASS_MINMAX => Rounding::PassMinMax, - } - } + #[inline(always)] + fn from(value: AVRounding) -> Self { + match value { + AV_ROUND_ZERO => Rounding::Zero, + AV_ROUND_INF => Rounding::Infinity, + AV_ROUND_DOWN => Rounding::Down, + AV_ROUND_UP => Rounding::Up, + AV_ROUND_NEAR_INF => Rounding::NearInfinity, + AV_ROUND_PASS_MINMAX => Rounding::PassMinMax, + } + } } impl Into for Rounding { - #[inline(always)] - fn into(self) -> AVRounding { - match self { - Rounding::Zero => AV_ROUND_ZERO, - Rounding::Infinity => AV_ROUND_INF, - Rounding::Down => AV_ROUND_DOWN, - Rounding::Up => AV_ROUND_UP, - Rounding::NearInfinity => AV_ROUND_NEAR_INF, - Rounding::PassMinMax => AV_ROUND_PASS_MINMAX, - } - } + #[inline(always)] + fn into(self) -> AVRounding { + match self { + Rounding::Zero => AV_ROUND_ZERO, + Rounding::Infinity => AV_ROUND_INF, + Rounding::Down => AV_ROUND_DOWN, + Rounding::Up => AV_ROUND_UP, + Rounding::NearInfinity => AV_ROUND_NEAR_INF, + Rounding::PassMinMax => AV_ROUND_PASS_MINMAX, + } + } } - - diff --git a/src/util/media.rs b/src/util/media.rs index b574248..b57f5df 100644 --- a/src/util/media.rs +++ b/src/util/media.rs @@ -1,41 +1,41 @@ -use ffi::*; use ffi::AVMediaType::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Type { - Unknown, - Video, - Audio, - Data, - Subtitle, - Attachment, + Unknown, + Video, + Audio, + Data, + Subtitle, + Attachment, } impl From for Type { - #[inline(always)] - fn from(value: AVMediaType) -> Self { - match value { - AVMEDIA_TYPE_UNKNOWN => Type::Unknown, - AVMEDIA_TYPE_VIDEO => Type::Video, - AVMEDIA_TYPE_AUDIO => Type::Audio, - AVMEDIA_TYPE_DATA => Type::Data, - AVMEDIA_TYPE_SUBTITLE => Type::Subtitle, - AVMEDIA_TYPE_ATTACHMENT => Type::Attachment, - AVMEDIA_TYPE_NB => Type::Unknown, - } - } + #[inline(always)] + fn from(value: AVMediaType) -> Self { + match value { + AVMEDIA_TYPE_UNKNOWN => Type::Unknown, + AVMEDIA_TYPE_VIDEO => Type::Video, + AVMEDIA_TYPE_AUDIO => Type::Audio, + AVMEDIA_TYPE_DATA => Type::Data, + AVMEDIA_TYPE_SUBTITLE => Type::Subtitle, + AVMEDIA_TYPE_ATTACHMENT => Type::Attachment, + AVMEDIA_TYPE_NB => Type::Unknown, + } + } } impl Into for Type { - #[inline(always)] - fn into(self) -> AVMediaType { - match self { - Type::Unknown => AVMEDIA_TYPE_UNKNOWN, - Type::Video => AVMEDIA_TYPE_VIDEO, - Type::Audio => AVMEDIA_TYPE_AUDIO, - Type::Data => AVMEDIA_TYPE_DATA, - Type::Subtitle => AVMEDIA_TYPE_SUBTITLE, - Type::Attachment => AVMEDIA_TYPE_ATTACHMENT, - } - } + #[inline(always)] + fn into(self) -> AVMediaType { + match self { + Type::Unknown => AVMEDIA_TYPE_UNKNOWN, + Type::Video => AVMEDIA_TYPE_VIDEO, + Type::Audio => AVMEDIA_TYPE_AUDIO, + Type::Data => AVMEDIA_TYPE_DATA, + Type::Subtitle => AVMEDIA_TYPE_SUBTITLE, + Type::Attachment => AVMEDIA_TYPE_ATTACHMENT, + } + } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 09c841d..1a50077 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,19 +1,19 @@ #[macro_use] pub mod dictionary; -pub mod error; -pub mod rational; -pub mod media; -pub mod picture; +pub mod channel_layout; +pub mod chroma; pub mod color; +pub mod error; pub mod format; pub mod frame; -pub mod chroma; -pub mod time; -pub mod channel_layout; -pub mod option; -pub mod range; -pub mod mathematics; pub mod interrupt; +pub mod mathematics; +pub mod media; +pub mod option; +pub mod picture; +pub mod range; +pub mod rational; +pub mod time; use std::ffi::CStr; use std::str::from_utf8_unchecked; @@ -22,21 +22,15 @@ use ffi::*; #[inline(always)] pub fn version() -> u32 { - unsafe { - avutil_version() - } + unsafe { avutil_version() } } #[inline(always)] pub fn configuration() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avutil_configuration()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avutil_configuration()).to_bytes()) } } #[inline(always)] pub fn license() -> &'static str { - unsafe { - from_utf8_unchecked(CStr::from_ptr(avutil_license()).to_bytes()) - } + unsafe { from_utf8_unchecked(CStr::from_ptr(avutil_license()).to_bytes()) } } diff --git a/src/util/option/mod.rs b/src/util/option/mod.rs index 6f76fd9..c42a24b 100644 --- a/src/util/option/mod.rs +++ b/src/util/option/mod.rs @@ -1,83 +1,83 @@ mod traits; -pub use self::traits::{Target, Settable, Gettable, Iterable}; +pub use self::traits::{Gettable, Iterable, Settable, Target}; -use ffi::*; use ffi::AVOptionType::*; +use ffi::*; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub enum Type { - Flags, - Int, - Int64, - Double, - Float, - String, - Rational, - Binary, - Dictionary, - Constant, + Flags, + Int, + Int64, + Double, + Float, + String, + Rational, + Binary, + Dictionary, + Constant, - ImageSize, - PixelFormat, - SampleFormat, - VideoRate, - Duration, - Color, - ChannelLayout, - c_ulong, - bool, + ImageSize, + PixelFormat, + SampleFormat, + VideoRate, + Duration, + Color, + ChannelLayout, + c_ulong, + bool, } impl From for Type { - fn from(value: AVOptionType) -> Self { - match value { - AV_OPT_TYPE_FLAGS => Type::Flags, - AV_OPT_TYPE_INT => Type::Int, - AV_OPT_TYPE_INT64 => Type::Int64, - AV_OPT_TYPE_DOUBLE => Type::Double, - AV_OPT_TYPE_FLOAT => Type::Float, - AV_OPT_TYPE_STRING => Type::String, - AV_OPT_TYPE_RATIONAL => Type::Rational, - AV_OPT_TYPE_BINARY => Type::Binary, - AV_OPT_TYPE_DICT => Type::Dictionary, - AV_OPT_TYPE_CONST => Type::Constant, - AV_OPT_TYPE_UINT64 => Type::c_ulong, - AV_OPT_TYPE_BOOL => Type::bool, + fn from(value: AVOptionType) -> Self { + match value { + AV_OPT_TYPE_FLAGS => Type::Flags, + AV_OPT_TYPE_INT => Type::Int, + AV_OPT_TYPE_INT64 => Type::Int64, + AV_OPT_TYPE_DOUBLE => Type::Double, + AV_OPT_TYPE_FLOAT => Type::Float, + AV_OPT_TYPE_STRING => Type::String, + AV_OPT_TYPE_RATIONAL => Type::Rational, + AV_OPT_TYPE_BINARY => Type::Binary, + AV_OPT_TYPE_DICT => Type::Dictionary, + AV_OPT_TYPE_CONST => Type::Constant, + AV_OPT_TYPE_UINT64 => Type::c_ulong, + AV_OPT_TYPE_BOOL => Type::bool, - AV_OPT_TYPE_IMAGE_SIZE => Type::ImageSize, - AV_OPT_TYPE_PIXEL_FMT => Type::PixelFormat, - AV_OPT_TYPE_SAMPLE_FMT => Type::SampleFormat, - AV_OPT_TYPE_VIDEO_RATE => Type::VideoRate, - AV_OPT_TYPE_DURATION => Type::Duration, - AV_OPT_TYPE_COLOR => Type::Color, - AV_OPT_TYPE_CHANNEL_LAYOUT => Type::ChannelLayout, - } - } + AV_OPT_TYPE_IMAGE_SIZE => Type::ImageSize, + AV_OPT_TYPE_PIXEL_FMT => Type::PixelFormat, + AV_OPT_TYPE_SAMPLE_FMT => Type::SampleFormat, + AV_OPT_TYPE_VIDEO_RATE => Type::VideoRate, + AV_OPT_TYPE_DURATION => Type::Duration, + AV_OPT_TYPE_COLOR => Type::Color, + AV_OPT_TYPE_CHANNEL_LAYOUT => Type::ChannelLayout, + } + } } impl Into for Type { - fn into(self) -> AVOptionType { - match self { - Type::Flags => AV_OPT_TYPE_FLAGS, - Type::Int => AV_OPT_TYPE_INT, - Type::Int64 => AV_OPT_TYPE_INT64, - Type::Double => AV_OPT_TYPE_DOUBLE, - Type::Float => AV_OPT_TYPE_FLOAT, - Type::String => AV_OPT_TYPE_STRING, - Type::Rational => AV_OPT_TYPE_RATIONAL, - Type::Binary => AV_OPT_TYPE_BINARY, - Type::Dictionary => AV_OPT_TYPE_DICT, - Type::Constant => AV_OPT_TYPE_CONST, - Type::c_ulong => AV_OPT_TYPE_UINT64, - Type::bool => AV_OPT_TYPE_BOOL, + fn into(self) -> AVOptionType { + match self { + Type::Flags => AV_OPT_TYPE_FLAGS, + Type::Int => AV_OPT_TYPE_INT, + Type::Int64 => AV_OPT_TYPE_INT64, + Type::Double => AV_OPT_TYPE_DOUBLE, + Type::Float => AV_OPT_TYPE_FLOAT, + Type::String => AV_OPT_TYPE_STRING, + Type::Rational => AV_OPT_TYPE_RATIONAL, + Type::Binary => AV_OPT_TYPE_BINARY, + Type::Dictionary => AV_OPT_TYPE_DICT, + Type::Constant => AV_OPT_TYPE_CONST, + Type::c_ulong => AV_OPT_TYPE_UINT64, + Type::bool => AV_OPT_TYPE_BOOL, - Type::ImageSize => AV_OPT_TYPE_IMAGE_SIZE, - Type::PixelFormat => AV_OPT_TYPE_PIXEL_FMT, - Type::SampleFormat => AV_OPT_TYPE_SAMPLE_FMT, - Type::VideoRate => AV_OPT_TYPE_VIDEO_RATE, - Type::Duration => AV_OPT_TYPE_DURATION, - Type::Color => AV_OPT_TYPE_COLOR, - Type::ChannelLayout => AV_OPT_TYPE_CHANNEL_LAYOUT, - } - } + Type::ImageSize => AV_OPT_TYPE_IMAGE_SIZE, + Type::PixelFormat => AV_OPT_TYPE_PIXEL_FMT, + Type::SampleFormat => AV_OPT_TYPE_SAMPLE_FMT, + Type::VideoRate => AV_OPT_TYPE_VIDEO_RATE, + Type::Duration => AV_OPT_TYPE_DURATION, + Type::Color => AV_OPT_TYPE_COLOR, + Type::ChannelLayout => AV_OPT_TYPE_CHANNEL_LAYOUT, + } + } } diff --git a/src/util/option/traits.rs b/src/util/option/traits.rs index 309eacd..80c43c2 100644 --- a/src/util/option/traits.rs +++ b/src/util/option/traits.rs @@ -1,133 +1,149 @@ //! NOTE: this will be much better once specialization comes -use std::mem; use std::ffi::CString; +use std::mem; use ffi::*; -use libc::{c_void, c_int, int64_t}; -use ::{Error, Rational, ChannelLayout}; +use libc::{c_int, c_void, int64_t}; use util::format; +use {ChannelLayout, Error, Rational}; macro_rules! check { - ($expr:expr) => ( - match $expr { - 0 => Ok(()), - e => Err(Error::from(e)), - } - ) + ($expr:expr) => { + match $expr { + 0 => Ok(()), + e => Err(Error::from(e)), + } + }; } pub unsafe trait Target { - fn as_ptr(&self) -> *const c_void; - fn as_mut_ptr(&mut self) -> *mut c_void; + fn as_ptr(&self) -> *const c_void; + fn as_mut_ptr(&mut self) -> *mut c_void; } pub trait Settable: Target { - fn set(&mut self, name: &str, value: &T) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); + fn set(&mut self, name: &str, value: &T) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); - check!(av_opt_set_bin(self.as_mut_ptr(), - name.as_ptr(), - value as *const _ as *const _, mem::size_of::() as c_int, - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set_bin( + self.as_mut_ptr(), + name.as_ptr(), + value as *const _ as *const _, + mem::size_of::() as c_int, + AV_OPT_SEARCH_CHILDREN + )) + } + } - fn set_str(&mut self, name: &str, value: &str) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); - let value = CString::new(value).unwrap(); + fn set_str(&mut self, name: &str, value: &str) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); + let value = CString::new(value).unwrap(); - check!(av_opt_set(self.as_mut_ptr(), - name.as_ptr(), - value.as_ptr(), - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set( + self.as_mut_ptr(), + name.as_ptr(), + value.as_ptr(), + AV_OPT_SEARCH_CHILDREN + )) + } + } - fn set_int(&mut self, name: &str, value: i64) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); + fn set_int(&mut self, name: &str, value: i64) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); - check!(av_opt_set_int(self.as_mut_ptr(), - name.as_ptr(), - value as int64_t, - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set_int( + self.as_mut_ptr(), + name.as_ptr(), + value as int64_t, + AV_OPT_SEARCH_CHILDREN + )) + } + } - fn set_double(&mut self, name: &str, value: f64) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); + fn set_double(&mut self, name: &str, value: f64) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); - check!(av_opt_set_double(self.as_mut_ptr(), - name.as_ptr(), - value, - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set_double( + self.as_mut_ptr(), + name.as_ptr(), + value, + AV_OPT_SEARCH_CHILDREN + )) + } + } - fn set_rational>(&mut self, name: &str, value: T) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); + fn set_rational>(&mut self, name: &str, value: T) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); - check!(av_opt_set_q(self.as_mut_ptr(), - name.as_ptr(), - value.into().into(), - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set_q( + self.as_mut_ptr(), + name.as_ptr(), + value.into().into(), + AV_OPT_SEARCH_CHILDREN + )) + } + } - fn set_image_size(&mut self, name: &str, w: u32, h: u32) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); + fn set_image_size(&mut self, name: &str, w: u32, h: u32) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); - check!(av_opt_set_image_size(self.as_mut_ptr(), - name.as_ptr(), - w as c_int, h as c_int, - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set_image_size( + self.as_mut_ptr(), + name.as_ptr(), + w as c_int, + h as c_int, + AV_OPT_SEARCH_CHILDREN + )) + } + } - fn set_pixel_format(&mut self, name: &str, format: format::Pixel) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); + fn set_pixel_format(&mut self, name: &str, format: format::Pixel) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); - check!(av_opt_set_pixel_fmt(self.as_mut_ptr(), - name.as_ptr(), - format.into(), - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set_pixel_fmt( + self.as_mut_ptr(), + name.as_ptr(), + format.into(), + AV_OPT_SEARCH_CHILDREN + )) + } + } - fn set_sample_format(&mut self, name: &str, format: format::Sample) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); + fn set_sample_format(&mut self, name: &str, format: format::Sample) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); - check!(av_opt_set_sample_fmt(self.as_mut_ptr(), - name.as_ptr(), - format.into(), - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set_sample_fmt( + self.as_mut_ptr(), + name.as_ptr(), + format.into(), + AV_OPT_SEARCH_CHILDREN + )) + } + } - fn set_channel_layout(&mut self, name: &str, layout: ChannelLayout) -> Result<(), Error> { - unsafe { - let name = CString::new(name).unwrap(); + fn set_channel_layout(&mut self, name: &str, layout: ChannelLayout) -> Result<(), Error> { + unsafe { + let name = CString::new(name).unwrap(); - check!(av_opt_set_channel_layout(self.as_mut_ptr(), - name.as_ptr(), - layout.bits() as int64_t, - AV_OPT_SEARCH_CHILDREN)) - } - } + check!(av_opt_set_channel_layout( + self.as_mut_ptr(), + name.as_ptr(), + layout.bits() as int64_t, + AV_OPT_SEARCH_CHILDREN + )) + } + } } -pub trait Gettable: Target { +pub trait Gettable: Target {} -} - -pub trait Iterable: Target { - -} +pub trait Iterable: Target {} diff --git a/src/util/picture.rs b/src/util/picture.rs index 5c60e6f..69aa99f 100644 --- a/src/util/picture.rs +++ b/src/util/picture.rs @@ -1,46 +1,46 @@ -use ffi::*; use ffi::AVPictureType::*; +use ffi::*; #[derive(Eq, PartialEq, Clone, Copy, Debug)] pub enum Type { - None, - I, - P, - B, - S, - SI, - SP, - BI + None, + I, + P, + B, + S, + SI, + SP, + BI, } impl From for Type { - #[inline(always)] - fn from(value: AVPictureType) -> Type { - match value { - AV_PICTURE_TYPE_NONE => Type::None, - AV_PICTURE_TYPE_I => Type::I, - AV_PICTURE_TYPE_P => Type::P, - AV_PICTURE_TYPE_B => Type::B, - AV_PICTURE_TYPE_S => Type::S, - AV_PICTURE_TYPE_SI => Type::SI, - AV_PICTURE_TYPE_SP => Type::SP, - AV_PICTURE_TYPE_BI => Type::BI - } - } + #[inline(always)] + fn from(value: AVPictureType) -> Type { + match value { + AV_PICTURE_TYPE_NONE => Type::None, + AV_PICTURE_TYPE_I => Type::I, + AV_PICTURE_TYPE_P => Type::P, + AV_PICTURE_TYPE_B => Type::B, + AV_PICTURE_TYPE_S => Type::S, + AV_PICTURE_TYPE_SI => Type::SI, + AV_PICTURE_TYPE_SP => Type::SP, + AV_PICTURE_TYPE_BI => Type::BI, + } + } } impl Into for Type { - #[inline(always)] - fn into(self) -> AVPictureType { - match self { - Type::None => AV_PICTURE_TYPE_NONE, - Type::I => AV_PICTURE_TYPE_I, - Type::P => AV_PICTURE_TYPE_P, - Type::B => AV_PICTURE_TYPE_B, - Type::S => AV_PICTURE_TYPE_S, - Type::SI => AV_PICTURE_TYPE_SI, - Type::SP => AV_PICTURE_TYPE_SP, - Type::BI => AV_PICTURE_TYPE_BI - } - } + #[inline(always)] + fn into(self) -> AVPictureType { + match self { + Type::None => AV_PICTURE_TYPE_NONE, + Type::I => AV_PICTURE_TYPE_I, + Type::P => AV_PICTURE_TYPE_P, + Type::B => AV_PICTURE_TYPE_B, + Type::S => AV_PICTURE_TYPE_S, + Type::SI => AV_PICTURE_TYPE_SI, + Type::SP => AV_PICTURE_TYPE_SP, + Type::BI => AV_PICTURE_TYPE_BI, + } + } } diff --git a/src/util/range.rs b/src/util/range.rs index 9c5e5f0..1449383 100644 --- a/src/util/range.rs +++ b/src/util/range.rs @@ -1,35 +1,35 @@ use std::ops; pub trait Range { - fn start(&self) -> Option<&T> { - None - } + fn start(&self) -> Option<&T> { + None + } - fn end(&self) -> Option<&T> { - None - } + fn end(&self) -> Option<&T> { + None + } } impl Range for ops::Range { - fn start(&self) -> Option<&T> { - Some(&self.start) - } + fn start(&self) -> Option<&T> { + Some(&self.start) + } - fn end(&self) -> Option<&T> { - Some(&self.end) - } + fn end(&self) -> Option<&T> { + Some(&self.end) + } } impl Range for ops::RangeTo { - fn end(&self) -> Option<&T> { - Some(&self.end) - } + fn end(&self) -> Option<&T> { + Some(&self.end) + } } impl Range for ops::RangeFrom { - fn start(&self) -> Option<&T> { - Some(&self.start) - } + fn start(&self) -> Option<&T> { + Some(&self.start) + } } -impl Range for ops::RangeFull { } +impl Range for ops::RangeFull {} diff --git a/src/util/rational.rs b/src/util/rational.rs index 638592b..6fe82b8 100644 --- a/src/util/rational.rs +++ b/src/util/rational.rs @@ -1,208 +1,202 @@ use std::cmp::Ordering; -use std::ops::{Add, Sub, Mul, Div}; use std::fmt; +use std::ops::{Add, Div, Mul, Sub}; -use libc::{c_int, int64_t}; use ffi::*; +use libc::c_int; #[derive(Copy, Clone)] pub struct Rational(pub i32, pub i32); impl Rational { - #[inline] - pub fn new(numerator: i32, denominator: i32) -> Self { - Rational(numerator, denominator) - } + #[inline] + pub fn new(numerator: i32, denominator: i32) -> Self { + Rational(numerator, denominator) + } - #[inline] - pub fn numerator(&self) -> i32 { - self.0 - } + #[inline] + pub fn numerator(&self) -> i32 { + self.0 + } - #[inline] - pub fn denominator(&self) -> i32 { - self.1 - } + #[inline] + pub fn denominator(&self) -> i32 { + self.1 + } - #[inline] - pub fn reduce(&self) -> Rational { - match self.reduce_with_limit(i32::max_value()) { - Ok(r) => r, - Err(r) => r, - } - } + #[inline] + pub fn reduce(&self) -> Rational { + match self.reduce_with_limit(i32::max_value()) { + Ok(r) => r, + Err(r) => r, + } + } - #[inline] - pub fn reduce_with_limit(&self, max: i32) -> Result { - unsafe { - let mut dst_num: c_int = 0; - let mut dst_den: c_int = 0; + #[inline] + pub fn reduce_with_limit(&self, max: i32) -> Result { + unsafe { + let mut dst_num: c_int = 0; + let mut dst_den: c_int = 0; - let exact = av_reduce(&mut dst_num, &mut dst_den, - self.numerator() as int64_t, self.denominator() as int64_t, - max as int64_t); + let exact = av_reduce( + &mut dst_num, + &mut dst_den, + i64::from(self.numerator()), + i64::from(self.denominator()), + i64::from(max), + ); - if exact == 1 { - Ok(Rational(dst_num, dst_den)) - } - else { - Err(Rational(dst_num, dst_den)) - } - } - } + if exact == 1 { + Ok(Rational(dst_num, dst_den)) + } else { + Err(Rational(dst_num, dst_den)) + } + } + } - #[inline] - pub fn invert(&self) -> Rational { - unsafe { - Rational::from(av_inv_q((*self).into())) - } - } + #[inline] + pub fn invert(&self) -> Rational { + unsafe { Rational::from(av_inv_q((*self).into())) } + } } impl From for Rational { - #[inline] - fn from(value: AVRational) -> Rational { - Rational(value.num, value.den) - } + #[inline] + fn from(value: AVRational) -> Rational { + Rational(value.num, value.den) + } } impl Into for Rational { - #[inline] - fn into(self) -> AVRational { - AVRational { num: self.0, den: self.1 } - } + #[inline] + fn into(self) -> AVRational { + AVRational { + num: self.0, + den: self.1, + } + } } impl From for Rational { - #[inline] - fn from(value: f64) -> Rational { - unsafe { - Rational::from(av_d2q(value, c_int::max_value())) - } - } + #[inline] + fn from(value: f64) -> Rational { + unsafe { Rational::from(av_d2q(value, c_int::max_value())) } + } } impl From for f64 { - #[inline] - fn from(value: Rational) -> f64 { - unsafe { - av_q2d(value.into()) - } - } + #[inline] + fn from(value: Rational) -> f64 { + unsafe { av_q2d(value.into()) } + } } impl From for u32 { - #[inline] - fn from(value: Rational) -> u32 { - unsafe { - av_q2intfloat(value.into()) - } - } + #[inline] + fn from(value: Rational) -> u32 { + unsafe { av_q2intfloat(value.into()) } + } } impl From<(i32, i32)> for Rational { - fn from((num, den): (i32, i32)) -> Rational { - Rational::new(num, den) - } + fn from((num, den): (i32, i32)) -> Rational { + Rational::new(num, den) + } } impl PartialEq for Rational { - fn eq(&self, other: &Rational) -> bool { - if self.0 == other.0 && self.1 == other.1 { - return true; - } + fn eq(&self, other: &Rational) -> bool { + if self.0 == other.0 && self.1 == other.1 { + return true; + } - let a = self.reduce(); - let b = other.reduce(); + let a = self.reduce(); + let b = other.reduce(); - if a.0 == b.0 && a.1 == b.1 { - return true; - } + if a.0 == b.0 && a.1 == b.1 { + return true; + } - false - } + false + } } -impl Eq for Rational { } +impl Eq for Rational {} impl PartialOrd for Rational { - #[inline] - fn partial_cmp(&self, other: &Self) -> Option { - unsafe { - match av_cmp_q((*self).into(), (*other).into()) { - 0 => Some(Ordering::Equal), - 1 => Some(Ordering::Greater), - -1 => Some(Ordering::Less), + #[inline] + fn partial_cmp(&self, other: &Self) -> Option { + unsafe { + match av_cmp_q((*self).into(), (*other).into()) { + 0 => Some(Ordering::Equal), + 1 => Some(Ordering::Greater), + -1 => Some(Ordering::Less), - _ => None - } - } - } + _ => None, + } + } + } } impl Add for Rational { - type Output = Rational; + type Output = Rational; - #[inline] - fn add(self, other: Rational) -> Rational { - unsafe { - Rational::from(av_add_q(self.into(), other.into())) - } - } + #[inline] + fn add(self, other: Rational) -> Rational { + unsafe { Rational::from(av_add_q(self.into(), other.into())) } + } } impl Sub for Rational { - type Output = Rational; + type Output = Rational; - #[inline] - fn sub(self, other: Rational) -> Rational { - unsafe { - Rational::from(av_sub_q(self.into(), other.into())) - } - } + #[inline] + fn sub(self, other: Rational) -> Rational { + unsafe { Rational::from(av_sub_q(self.into(), other.into())) } + } } impl Mul for Rational { - type Output = Rational; + type Output = Rational; - #[inline] - fn mul(self, other: Rational) -> Rational { - unsafe { - Rational::from(av_mul_q(self.into(), other.into())) - } - } + #[inline] + fn mul(self, other: Rational) -> Rational { + unsafe { Rational::from(av_mul_q(self.into(), other.into())) } + } } impl Div for Rational { - type Output = Rational; + type Output = Rational; - #[inline] - fn div(self, other: Rational) -> Rational { - unsafe { - Rational::from(av_div_q(self.into(), other.into())) - } - } + #[inline] + fn div(self, other: Rational) -> Rational { + unsafe { Rational::from(av_div_q(self.into(), other.into())) } + } } impl fmt::Display for Rational { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - f.write_str(&format!("{}/{}", self.numerator(), self.denominator())) - } + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + f.write_str(&format!("{}/{}", self.numerator(), self.denominator())) + } } impl fmt::Debug for Rational { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - f.write_str(&format!("Rational({}/{})", self.numerator(), self.denominator())) - } + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + f.write_str(&format!( + "Rational({}/{})", + self.numerator(), + self.denominator() + )) + } } #[inline] pub fn nearer(q: Rational, q1: Rational, q2: Rational) -> Ordering { - unsafe { - match av_nearer_q(q.into(), q1.into(), q2.into()) { - 1 => Ordering::Greater, - -1 => Ordering::Less, - _ => Ordering::Equal, - } - } + unsafe { + match av_nearer_q(q.into(), q1.into(), q2.into()) { + 1 => Ordering::Greater, + -1 => Ordering::Less, + _ => Ordering::Equal, + } + } } diff --git a/src/util/time.rs b/src/util/time.rs index 12039c4..373a5ea 100644 --- a/src/util/time.rs +++ b/src/util/time.rs @@ -1,33 +1,27 @@ use ffi::*; -use ::Error; +use Error; #[inline(always)] pub fn current() -> i64 { - unsafe { - av_gettime() as i64 - } + unsafe { av_gettime() as i64 } } #[inline(always)] pub fn relative() -> i64 { - unsafe { - av_gettime_relative() as i64 - } + unsafe { av_gettime_relative() as i64 } } #[inline(always)] pub fn is_monotonic() -> bool { - unsafe { - av_gettime_relative_is_monotonic() != 0 - } + unsafe { av_gettime_relative_is_monotonic() != 0 } } #[inline(always)] pub fn sleep(usec: u32) -> Result<(), Error> { - unsafe { - match av_usleep(usec) { - 0 => Ok(()), - e => Err(Error::from(e)) - } - } + unsafe { + match av_usleep(usec) { + 0 => Ok(()), + e => Err(Error::from(e)), + } + } }