diff --git a/examples/transcode-audio.rs b/examples/transcode-audio.rs index 6a25910..4486284 100644 --- a/examples/transcode-audio.rs +++ b/examples/transcode-audio.rs @@ -15,10 +15,13 @@ fn filter(spec: &str, decoder: &codec::decoder::Audio, encoder: &codec::encoder: try!(filter.add(&filter::find("abuffer").unwrap(), "in", &args)); try!(filter.add(&filter::find("abuffersink").unwrap(), "out", "")); - filter.get("out").unwrap() - .set_sample_format(encoder.format()) - .set_channel_layout(encoder.channel_layout()) - .set_sample_rate(encoder.rate()); + { + 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()); + } try!(try!(try!(filter.output("in", 0)).input("out", 0)).parse(spec)); try!(filter.validate()); @@ -58,12 +61,12 @@ fn transcoder>(ictx: &mut format::context::Input, octx: &mut form encoder.set_flags(ffmpeg::codec::flag::GLOBAL_HEADER); } - encoder.set_rate(decoder.rate() as i32) - .set_channel_layout(channel_layout) - .set_channels(channel_layout.channels()) - .set_format(codec.formats().expect("unknown supported formats").next().unwrap()) - .set_bit_rate(decoder.bit_rate()) - .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)); @@ -119,9 +122,9 @@ fn main() { 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) - .rescale_ts(in_time_base, out_time_base) - .write_interleaved(&mut octx).unwrap(); + encoded.set_stream(0); + encoded.rescale_ts(in_time_base, out_time_base); + encoded.write_interleaved(&mut octx).unwrap(); } } } @@ -132,16 +135,16 @@ fn main() { 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) - .rescale_ts(in_time_base, out_time_base) - .write_interleaved(&mut octx).unwrap(); + 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) - .rescale_ts(in_time_base, out_time_base) - .write_interleaved(&mut octx).unwrap(); + encoded.set_stream(0); + encoded.rescale_ts(in_time_base, out_time_base); + encoded.write_interleaved(&mut octx).unwrap(); } octx.write_trailer().unwrap(); diff --git a/src/codec/context.rs b/src/codec/context.rs index 4474d2b..549e264 100644 --- a/src/codec/context.rs +++ b/src/codec/context.rs @@ -62,12 +62,10 @@ impl Context { } } - pub fn set_flags(&mut self, value: Flags) -> &mut Self { + pub fn set_flags(&mut self, value: Flags) { unsafe { (*self.as_mut_ptr()).flags = value.bits() as c_int; } - - self } pub fn id(&self) -> Id { @@ -88,14 +86,12 @@ impl Context { } } - pub fn set_threading(&mut self, config: threading::Config) -> &mut Self { + 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 }; } - - self } pub fn threading(&self) -> threading::Config { diff --git a/src/codec/decoder/audio.rs b/src/codec/decoder/audio.rs index 55ebd66..66872be 100644 --- a/src/codec/decoder/audio.rs +++ b/src/codec/decoder/audio.rs @@ -64,20 +64,16 @@ impl Audio { } } - pub fn set_channel_layout(&mut self, value: ChannelLayout) -> &mut Self { + pub fn set_channel_layout(&mut self, value: ChannelLayout) { unsafe { (*self.as_mut_ptr()).channel_layout = value.bits(); } - - self } - pub fn request_channel_layout(&mut self, value: ChannelLayout) -> &mut Self { + pub fn request_channel_layout(&mut self, value: ChannelLayout) { unsafe { (*self.as_mut_ptr()).request_channel_layout = value.bits(); } - - self } pub fn audio_service(&mut self) -> AudioService { diff --git a/src/codec/decoder/video.rs b/src/codec/decoder/video.rs index af196b2..e075534 100644 --- a/src/codec/decoder/video.rs +++ b/src/codec/decoder/video.rs @@ -84,36 +84,28 @@ impl Video { } } - pub fn set_slice_count(&mut self, value: usize) -> &mut Self { + pub fn set_slice_count(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).slice_count = value as c_int; } - - self } - pub fn set_slice_flags(&mut self, value: slice::Flags) -> &mut Self { + pub fn set_slice_flags(&mut self, value: slice::Flags) { unsafe { (*self.as_mut_ptr()).slice_flags = value.bits(); } - - self } - pub fn skip_top(&mut self, value: usize) -> &mut Self { + pub fn skip_top(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).skip_top = value as c_int; } - - self } - pub fn skip_bottom(&mut self, value: usize) -> &mut Self { + pub fn skip_bottom(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).skip_bottom = value as c_int; } - - self } pub fn references(&self) -> usize { @@ -122,12 +114,10 @@ impl Video { } } - pub fn set_field_order(&mut self, value: FieldOrder) -> &mut Self { + pub fn set_field_order(&mut self, value: FieldOrder) { unsafe { (*self.as_mut_ptr()).field_order = value.into(); } - - self } // intra_matrix diff --git a/src/codec/encoder/audio.rs b/src/codec/encoder/audio.rs index fdaba2e..1e2f417 100644 --- a/src/codec/encoder/audio.rs +++ b/src/codec/encoder/audio.rs @@ -54,12 +54,10 @@ impl Audio { } } - pub fn set_rate(&mut self, rate: i32) -> &mut Self { + pub fn set_rate(&mut self, rate: i32) { unsafe { (*self.as_mut_ptr()).sample_rate = rate; } - - self } pub fn rate(&self) -> u32 { @@ -68,12 +66,10 @@ impl Audio { } } - pub fn set_format(&mut self, value: format::Sample) -> &mut Self { + pub fn set_format(&mut self, value: format::Sample) { unsafe { (*self.as_mut_ptr()).sample_fmt = value.into(); } - - self } pub fn format(&self) -> format::Sample { @@ -82,12 +78,10 @@ impl Audio { } } - pub fn set_channel_layout(&mut self, value: ChannelLayout) -> &mut Self { + pub fn set_channel_layout(&mut self, value: ChannelLayout) { unsafe { (*self.as_mut_ptr()).channel_layout = value.bits(); } - - self } pub fn channel_layout(&self) -> ChannelLayout { @@ -96,12 +90,10 @@ impl Audio { } } - pub fn set_channels(&mut self, value: i32) -> &mut Self { + pub fn set_channels(&mut self, value: i32) { unsafe { (*self.as_mut_ptr()).channels = value; } - - self } pub fn channels(&self) -> u16 { diff --git a/src/codec/encoder/encoder.rs b/src/codec/encoder/encoder.rs index e64db8c..d64dc79 100644 --- a/src/codec/encoder/encoder.rs +++ b/src/codec/encoder/encoder.rs @@ -68,39 +68,31 @@ impl Encoder { } } - pub fn set_bit_rate(&mut self, value: usize) -> &mut Self { + pub fn set_bit_rate(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).bit_rate = value as c_int; } - - self } - pub fn set_max_bit_rate(&mut self, value: usize) -> &mut Self { + pub fn set_max_bit_rate(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).rc_max_rate = value as c_int; } - - self } - pub fn set_tolerance(&mut self, value: usize) -> &mut Self { + pub fn set_tolerance(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).bit_rate_tolerance = value as c_int; } - - self } - pub fn set_quality(&mut self, value: usize) -> &mut Self { + pub fn set_quality(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).global_quality = value as c_int; } - - self } - pub fn set_compression(&mut self, value: Option) -> &mut Self { + pub fn set_compression(&mut self, value: Option) { unsafe { if let Some(value) = value { (*self.as_mut_ptr()).compression_level = value as c_int; @@ -109,19 +101,15 @@ impl Encoder { (*self.as_mut_ptr()).compression_level = -1; } } - - self } - pub fn set_time_base>(&mut self, value: R) -> &mut Self { + pub fn set_time_base>(&mut self, value: R) { unsafe { (*self.as_mut_ptr()).time_base = value.into().into(); } - - self } - pub fn set_frame_rate>(&mut self, value: Option) -> &mut Self { + pub fn set_frame_rate>(&mut self, value: Option) { unsafe { if let Some(value) = value { (*self.as_mut_ptr()).framerate = value.into().into(); @@ -131,8 +119,6 @@ impl Encoder { (*self.as_mut_ptr()).framerate.den = 1; } } - - self } } diff --git a/src/codec/encoder/video.rs b/src/codec/encoder/video.rs index b14f112..6fcd0cb 100644 --- a/src/codec/encoder/video.rs +++ b/src/codec/encoder/video.rs @@ -58,12 +58,10 @@ impl Video { } #[inline] - pub fn set_width(&mut self, value: u32) -> &mut Self { + pub fn set_width(&mut self, value: u32) { unsafe { (*self.as_mut_ptr()).width = value as c_int; } - - self } #[inline] @@ -74,12 +72,10 @@ impl Video { } #[inline] - pub fn set_height(&mut self, value: u32) -> &mut Self { + pub fn set_height(&mut self, value: u32) { unsafe { (*self.as_mut_ptr()).height = value as c_int; } - - self } #[inline] @@ -90,21 +86,17 @@ impl Video { } #[inline] - pub fn set_gop(&mut self, value: u32) -> &mut Self { + pub fn set_gop(&mut self, value: u32) { unsafe { (*self.as_mut_ptr()).gop_size = value as c_int; } - - self } #[inline] - pub fn set_format(&mut self, value: format::Pixel) -> &mut Self { + pub fn set_format(&mut self, value: format::Pixel) { unsafe { (*self.as_mut_ptr()).pix_fmt = value.into(); } - - self } #[inline] @@ -115,223 +107,175 @@ impl Video { } #[inline] - pub fn set_motion_estimation(&mut self, value: MotionEstimation) -> &mut Self { + pub fn set_motion_estimation(&mut self, value: MotionEstimation) { unsafe { (*self.as_mut_ptr()).me_method = value.into(); } - - self } #[inline] - pub fn set_max_b_frames(&mut self, value: usize) -> &mut Self { + pub fn set_max_b_frames(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).max_b_frames = value as c_int; } - - self } #[inline] - pub fn set_b_quant_factor(&mut self, value: f32) -> &mut Self { + pub fn set_b_quant_factor(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).b_quant_factor = value as c_float; } - - self } #[inline] - pub fn set_b_quant_offset(&mut self, value: f32) -> &mut Self { + pub fn set_b_quant_offset(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).b_quant_offset = value as c_float; } - - self } #[inline] - pub fn set_i_quant_factor(&mut self, value: f32) -> &mut Self { + pub fn set_i_quant_factor(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).i_quant_factor = value as c_float; } - - self } #[inline] - pub fn set_i_quant_offset(&mut self, value: f32) -> &mut Self { + pub fn set_i_quant_offset(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).i_quant_offset = value as c_float; } - - self } #[inline] - pub fn set_lumi_masking(&mut self, value: f32) -> &mut Self { + pub fn set_lumi_masking(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).lumi_masking = value as c_float; } - - self } #[inline] - pub fn set_temporal_cplx_masking(&mut self, value: f32) -> &mut Self { + pub fn set_temporal_cplx_masking(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).temporal_cplx_masking = value as c_float; } - - self } #[inline] - pub fn set_spatial_cplx_masking(&mut self, value: f32) -> &mut Self { + pub fn set_spatial_cplx_masking(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).spatial_cplx_masking = value as c_float; } - - self } #[inline] - pub fn set_p_masking(&mut self, value: f32) -> &mut Self { + pub fn set_p_masking(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).p_masking = value as c_float; } - - self } #[inline] - pub fn set_dark_masking(&mut self, value: f32) -> &mut Self { + pub fn set_dark_masking(&mut self, value: f32) { unsafe { (*self.as_mut_ptr()).dark_masking = value as c_float; } - - self } #[inline] - pub fn set_prediction(&mut self, value: Prediction) -> &mut Self { + pub fn set_prediction(&mut self, value: Prediction) { unsafe { (*self.as_mut_ptr()).prediction_method = value.into(); } - - self } #[inline] - pub fn set_aspect_ratio>(&mut self, value: R) -> &mut Self { + pub fn set_aspect_ratio>(&mut self, value: R) { unsafe { (*self.as_mut_ptr()).sample_aspect_ratio = value.into().into(); } - - self } #[inline] - pub fn set_me_comparison(&mut self, value: Comparison) -> &mut Self { + pub fn set_me_comparison(&mut self, value: Comparison) { unsafe { (*self.as_mut_ptr()).me_cmp = value.into(); } - - self } #[inline] - pub fn set_me_sub_comparison(&mut self, value: Comparison) -> &mut Self { + pub fn set_me_sub_comparison(&mut self, value: Comparison) { unsafe { (*self.as_mut_ptr()).me_sub_cmp = value.into(); } - - self } #[inline] - pub fn set_mb_comparison(&mut self, value: Comparison) -> &mut Self { + pub fn set_mb_comparison(&mut self, value: Comparison) { unsafe { (*self.as_mut_ptr()).mb_cmp = value.into(); } - - self } #[inline] - pub fn set_ildct_comparison(&mut self, value: Comparison) -> &mut Self { + pub fn set_ildct_comparison(&mut self, value: Comparison) { unsafe { (*self.as_mut_ptr()).ildct_cmp = value.into(); } - - self } #[inline] - pub fn set_dia_size(&mut self, value: usize) -> &mut Self { + pub fn set_dia_size(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).dia_size = value as c_int; } - - self } #[inline] - pub fn set_last_predictors(&mut self, value: usize) -> &mut Self { + pub fn set_last_predictors(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).last_predictor_count = value as c_int; } - - self } #[inline] - pub fn set_pre_me(&mut self, value: MotionEstimation) -> &mut Self { + pub fn set_pre_me(&mut self, value: MotionEstimation) { unsafe { (*self.as_mut_ptr()).pre_me = value.into(); } - - self } #[inline] - pub fn set_me_pre_comparison(&mut self, value: Comparison) -> &mut Self { + pub fn set_me_pre_comparison(&mut self, value: Comparison) { unsafe { (*self.as_mut_ptr()).me_pre_cmp = value.into(); } - - self } #[inline] - pub fn set_pre_dia_size(&mut self, value: usize) -> &mut Self { + pub fn set_pre_dia_size(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).pre_dia_size = value as c_int; } - - self } #[inline] - pub fn set_me_subpel_quality(&mut self, value: usize) -> &mut Self { + pub fn set_me_subpel_quality(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).me_subpel_quality = value as c_int; } - - self } #[inline] - pub fn set_me_range(&mut self, value: usize) -> &mut Self { + pub fn set_me_range(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).me_range = value as c_int; } - - self } #[inline] - pub fn set_intra_quant_bias(&mut self, value: Option) -> &mut Self { + 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; @@ -340,12 +284,10 @@ impl Video { (*self.as_mut_ptr()).intra_quant_bias = FF_DEFAULT_QUANT_BIAS; } } - - self } #[inline] - pub fn set_inter_quant_bias(&mut self, value: Option) -> &mut Self { + 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; @@ -354,44 +296,55 @@ impl Video { (*self.as_mut_ptr()).inter_quant_bias = FF_DEFAULT_QUANT_BIAS; } } - - self } #[inline] - pub fn set_mb_decision(&mut self, value: Decision) -> &mut Self { + pub fn set_mb_decision(&mut self, value: Decision) { unsafe { (*self.as_mut_ptr()).mb_decision = value.into(); } - - self } #[inline] - pub fn set_intra_dc_precision(&mut self, value: u8) -> &mut Self { - unsafe { - (*self.as_mut_ptr()).intra_dc_precision = value as c_int; - } - - self - } - - #[inline] - pub fn set_mb_lmin(&mut self, value: i32) -> &mut Self { + pub fn set_mb_lmin(&mut self, value: i32) { unsafe { (*self.as_mut_ptr()).mb_lmin = value as c_int; } - - self } #[inline] - pub fn set_mb_lmax(&mut self, value: i32) -> &mut Self { + pub fn set_mb_lmax(&mut self, value: i32) { unsafe { (*self.as_mut_ptr()).mb_lmax = value as c_int; } + } - self + #[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_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_global_quality(&mut self, value: i32) { + unsafe { + (*self.as_mut_ptr()).global_quality = value as c_int; + } } } @@ -458,3 +411,10 @@ impl Deref for Encoder { &self.0 } } + +impl DerefMut for Encoder { + #[inline] + fn deref_mut(&mut self) -> &mut ::Target { + &mut self.0 + } +} diff --git a/src/codec/packet/mod.rs b/src/codec/packet/mod.rs index 6ef1365..08a217a 100644 --- a/src/codec/packet/mod.rs +++ b/src/codec/packet/mod.rs @@ -83,15 +83,13 @@ impl Packet { } #[inline] - pub fn rescale_ts(&mut self, source: S, destination: D) -> &mut Self + 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()); } - - self } #[inline] @@ -100,10 +98,8 @@ impl Packet { } #[inline] - pub fn set_flags(&mut self, value: Flags) -> &mut Self { + pub fn set_flags(&mut self, value: Flags) { self.0.flags = value.bits(); - - self } #[inline] @@ -122,10 +118,8 @@ impl Packet { } #[inline] - pub fn set_stream(&mut self, index: usize) -> &mut Self { + pub fn set_stream(&mut self, index: usize) { self.0.stream_index = index as c_int; - - self } #[inline] diff --git a/src/codec/subtitle/mod.rs b/src/codec/subtitle/mod.rs index e79ffc7..b26c87b 100644 --- a/src/codec/subtitle/mod.rs +++ b/src/codec/subtitle/mod.rs @@ -69,30 +69,24 @@ impl Subtitle { } } - pub fn set_pts(&mut self, value: Option) -> &mut Self { + pub fn set_pts(&mut self, value: Option) { self.0.pts = value.unwrap_or(AV_NOPTS_VALUE); - - self } pub fn start(&self) -> u32 { self.0.start_display_time as u32 } - pub fn set_start(&mut self, value: u32) -> &mut Self { + pub fn set_start(&mut self, value: u32) { self.0.start_display_time = value as uint32_t; - - self } pub fn end(&self) -> u32 { self.0.end_display_time as u32 } - pub fn set_end(&mut self, value: u32) -> &mut Self { + pub fn set_end(&mut self, value: u32) { self.0.end_display_time = value as uint32_t; - - self } pub fn rects(&self) -> RectIter { diff --git a/src/filter/context/context.rs b/src/filter/context/context.rs index fefa4df..b9ec709 100644 --- a/src/filter/context/context.rs +++ b/src/filter/context/context.rs @@ -38,28 +38,20 @@ impl<'a> Context<'a> { } } - pub fn set_pixel_format(&mut self, value: format::Pixel) -> &mut Self { + pub fn set_pixel_format(&mut self, value: format::Pixel) { let _ = option::Settable::set::(self, "pix_fmts", &value.into()); - - self } - pub fn set_sample_format(&mut self, value: format::Sample) -> &mut Self { + pub fn set_sample_format(&mut self, value: format::Sample) { let _ = option::Settable::set::(self, "sample_fmts", &value.into()); - - self } - pub fn set_sample_rate(&mut self, value: u32) -> &mut Self { + pub fn set_sample_rate(&mut self, value: u32) { let _ = option::Settable::set(self, "sample_rates", &(value as i64)); - - self } - pub fn set_channel_layout(&mut self, value: ChannelLayout) -> &mut Self { + pub fn set_channel_layout(&mut self, value: ChannelLayout) { let _ = option::Settable::set(self, "channel_layouts", &value.bits()); - - self } } diff --git a/src/filter/context/sink.rs b/src/filter/context/sink.rs index 3c21063..1720413 100644 --- a/src/filter/context/sink.rs +++ b/src/filter/context/sink.rs @@ -32,11 +32,9 @@ impl<'a> Sink<'a> { } } - pub fn set_frame_size(&mut self, value: u32) -> &mut Self { + pub fn set_frame_size(&mut self, value: u32) { unsafe { av_buffersink_set_frame_size(self.ctx.as_mut_ptr(), value); } - - self } } diff --git a/src/format/context/output.rs b/src/format/context/output.rs index f134341..dc1e4cc 100644 --- a/src/format/context/output.rs +++ b/src/format/context/output.rs @@ -83,12 +83,10 @@ impl Output { } } - pub fn set_metadata(&mut self, dictionary: Dictionary) -> &mut Self { + pub fn set_metadata(&mut self, dictionary: Dictionary) { unsafe { (*self.as_mut_ptr()).metadata = dictionary.disown(); } - - self } } diff --git a/src/format/stream/stream_mut.rs b/src/format/stream/stream_mut.rs index da7e101..bbce344 100644 --- a/src/format/stream/stream_mut.rs +++ b/src/format/stream/stream_mut.rs @@ -29,20 +29,16 @@ impl<'a> StreamMut<'a> { } impl<'a> StreamMut<'a> { - pub fn set_time_base>(&mut self, value: R) -> &mut Self { + pub fn set_time_base>(&mut self, value: R) { unsafe { (*self.as_mut_ptr()).time_base = value.into().into(); } - - self } - pub fn set_rate>(&mut self, value: R) -> &mut Self { + pub fn set_rate>(&mut self, value: R) { unsafe { av_stream_set_r_frame_rate(self.as_mut_ptr(), value.into().into()); } - - self } } diff --git a/src/util/frame/audio.rs b/src/util/frame/audio.rs index 039ae9e..0875b63 100644 --- a/src/util/frame/audio.rs +++ b/src/util/frame/audio.rs @@ -19,9 +19,9 @@ impl Audio { #[inline] pub unsafe fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) { - self.set_format(format) - .set_samples(samples) - .set_channel_layout(layout); + self.set_format(format); + self.set_samples(samples); + self.set_channel_layout(layout); av_frame_get_buffer(self.as_mut_ptr(), 0); } @@ -58,12 +58,10 @@ impl Audio { } #[inline] - pub fn set_format(&mut self, value: format::Sample) -> &mut Self { + pub fn set_format(&mut self, value: format::Sample) { unsafe { (*self.as_mut_ptr()).format = mem::transmute::(value.into()); } - - self } #[inline] @@ -74,12 +72,10 @@ impl Audio { } #[inline] - pub fn set_channel_layout(&mut self, value: ChannelLayout) -> &mut Self { + pub fn set_channel_layout(&mut self, value: ChannelLayout) { unsafe { av_frame_set_channel_layout(self.as_mut_ptr(), value.bits() as int64_t); } - - self } #[inline] @@ -90,12 +86,10 @@ impl Audio { } #[inline] - pub fn set_channels(&mut self, value: u16) -> &mut Self { + pub fn set_channels(&mut self, value: u16) { unsafe { av_frame_set_channels(self.as_mut_ptr(), value as c_int); } - - self } #[inline] @@ -106,12 +100,10 @@ impl Audio { } #[inline] - pub fn set_rate(&mut self, value: u32) -> &mut Self { + pub fn set_rate(&mut self, value: u32) { unsafe { av_frame_set_sample_rate(self.as_mut_ptr(), value as c_int); } - - self } #[inline] @@ -122,12 +114,10 @@ impl Audio { } #[inline] - pub fn set_samples(&mut self, value: usize) -> &mut Self { + pub fn set_samples(&mut self, value: usize) { unsafe { (*self.as_mut_ptr()).nb_samples = value as c_int; } - - self } #[inline] diff --git a/src/util/frame/mod.rs b/src/util/frame/mod.rs index 933a5be..ff71331 100644 --- a/src/util/frame/mod.rs +++ b/src/util/frame/mod.rs @@ -89,14 +89,14 @@ impl Frame { } } - pub fn set_pts(&mut self, value: Option) -> &mut Self { + #[inline] + pub fn set_pts(&mut self, value: Option) { unsafe { (*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE); } - - self } + #[inline] pub fn timestamp(&self) -> Option { unsafe { match av_frame_get_best_effort_timestamp(self.as_ptr()) { @@ -106,32 +106,35 @@ impl Frame { } } + #[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 metadata(&self) -> DictionaryRef { unsafe { DictionaryRef::wrap(av_frame_get_metadata(self.as_ptr())) } } - pub fn set_metadata(&mut self, value: Dictionary) -> &mut Self { + #[inline] + pub fn set_metadata(&mut self, value: Dictionary) { unsafe { av_frame_set_metadata(self.as_mut_ptr(), value.disown()); } - - self } + #[inline] pub fn side_data(&self, kind: side_data::Type) -> Option { unsafe { let ptr = av_frame_get_side_data(self.as_ptr(), kind.into()); diff --git a/src/util/frame/video.rs b/src/util/frame/video.rs index ad3bc5c..d4b5142 100644 --- a/src/util/frame/video.rs +++ b/src/util/frame/video.rs @@ -22,9 +22,9 @@ impl Video { #[inline] pub unsafe fn alloc(&mut self, format: format::Pixel, width: u32, height: u32) { - self.set_format(format) - .set_width(width) - .set_height(height); + self.set_format(format); + self.set_width(width); + self.set_height(height); av_frame_get_buffer(self.as_mut_ptr(), 32); } @@ -61,12 +61,10 @@ impl Video { } #[inline] - pub fn set_format(&mut self, value: format::Pixel) -> &mut Self { + pub fn set_format(&mut self, value: format::Pixel) { unsafe { (*self.as_mut_ptr()).format = mem::transmute::(value.into()); } - - self } #[inline] @@ -77,12 +75,10 @@ impl Video { } #[inline] - pub fn set_kind(&mut self, value: picture::Type) -> &mut Self { + pub fn set_kind(&mut self, value: picture::Type) { unsafe { (*self.as_mut_ptr()).pict_type = value.into(); } - - self } #[inline] @@ -114,12 +110,10 @@ impl Video { } #[inline] - pub fn set_width(&mut self, value: u32) -> &mut Self { + pub fn set_width(&mut self, value: u32) { unsafe { (*self.as_mut_ptr()).width = value as c_int; } - - self } #[inline] @@ -130,12 +124,10 @@ impl Video { } #[inline] - pub fn set_height(&mut self, value: u32) -> &mut Self { + pub fn set_height(&mut self, value: u32) { unsafe { (*self.as_mut_ptr()).height = value as c_int; } - - self } #[inline] @@ -146,12 +138,10 @@ impl Video { } #[inline] - pub fn set_color_space(&mut self, value: color::Space) -> &mut Self { + pub fn set_color_space(&mut self, value: color::Space) { unsafe { av_frame_set_colorspace(self.as_mut_ptr(), value.into()); } - - self } #[inline] @@ -162,12 +152,10 @@ impl Video { } #[inline] - pub fn set_color_range(&mut self, value: color::Range) -> &mut Self { + pub fn set_color_range(&mut self, value: color::Range) { unsafe { av_frame_set_color_range(self.as_mut_ptr(), value.into()); } - - self } #[inline] @@ -178,12 +166,10 @@ impl Video { } #[inline] - pub fn set_color_primaries(&mut self, value: color::Primaries) -> &mut Self { + pub fn set_color_primaries(&mut self, value: color::Primaries) { unsafe { (*self.as_mut_ptr()).color_primaries = value.into(); } - - self } #[inline] @@ -194,12 +180,10 @@ impl Video { } #[inline] - pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) -> &mut Self { + pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) { unsafe { (*self.as_mut_ptr()).color_trc = value.into(); } - - self } #[inline]