1 use std::ops::{Deref, DerefMut}; 2 3 use ffi::*; 4 use libc::c_int; 5 6 use super::{slice, Opened}; 7 use codec::Context; 8 use color; 9 use frame; 10 use util::chroma; 11 use util::format; 12 use {packet, Error, FieldOrder, Rational}; 13 14 pub struct Video(pub Opened); 15 16 impl Video { 17 #[deprecated( 18 since = "4.4.0", 19 note = "Underlying API avcodec_decode_video2 has been deprecated since FFmpeg 3.1; \ 20 consider switching to send_packet() and receive_frame()" 21 )] decode<P: packet::Ref>( &mut self, packet: &P, out: &mut frame::Video, ) -> Result<bool, Error>22 pub fn decode<P: packet::Ref>( 23 &mut self, 24 packet: &P, 25 out: &mut frame::Video, 26 ) -> Result<bool, Error> { 27 unsafe { 28 let mut got: c_int = 0; 29 30 match avcodec_decode_video2( 31 self.as_mut_ptr(), 32 out.as_mut_ptr(), 33 &mut got, 34 packet.as_ptr(), 35 ) { 36 e if e < 0 => Err(Error::from(e)), 37 _ => Ok(got != 0), 38 } 39 } 40 } 41 width(&self) -> u3242 pub fn width(&self) -> u32 { 43 unsafe { (*self.as_ptr()).width as u32 } 44 } 45 height(&self) -> u3246 pub fn height(&self) -> u32 { 47 unsafe { (*self.as_ptr()).height as u32 } 48 } 49 format(&self) -> format::Pixel50 pub fn format(&self) -> format::Pixel { 51 unsafe { format::Pixel::from((*self.as_ptr()).pix_fmt) } 52 } 53 has_b_frames(&self) -> bool54 pub fn has_b_frames(&self) -> bool { 55 unsafe { (*self.as_ptr()).has_b_frames != 0 } 56 } 57 aspect_ratio(&self) -> Rational58 pub fn aspect_ratio(&self) -> Rational { 59 unsafe { Rational::from((*self.as_ptr()).sample_aspect_ratio) } 60 } 61 color_space(&self) -> color::Space62 pub fn color_space(&self) -> color::Space { 63 unsafe { color::Space::from((*self.as_ptr()).colorspace) } 64 } 65 color_range(&self) -> color::Range66 pub fn color_range(&self) -> color::Range { 67 unsafe { color::Range::from((*self.as_ptr()).color_range) } 68 } 69 color_primaries(&self) -> color::Primaries70 pub fn color_primaries(&self) -> color::Primaries { 71 unsafe { color::Primaries::from((*self.as_ptr()).color_primaries) } 72 } 73 color_transfer_characteristic(&self) -> color::TransferCharacteristic74 pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic { 75 unsafe { color::TransferCharacteristic::from((*self.as_ptr()).color_trc) } 76 } 77 chroma_location(&self) -> chroma::Location78 pub fn chroma_location(&self) -> chroma::Location { 79 unsafe { chroma::Location::from((*self.as_ptr()).chroma_sample_location) } 80 } 81 set_slice_count(&mut self, value: usize)82 pub fn set_slice_count(&mut self, value: usize) { 83 unsafe { 84 (*self.as_mut_ptr()).slice_count = value as c_int; 85 } 86 } 87 set_slice_flags(&mut self, value: slice::Flags)88 pub fn set_slice_flags(&mut self, value: slice::Flags) { 89 unsafe { 90 (*self.as_mut_ptr()).slice_flags = value.bits(); 91 } 92 } 93 skip_top(&mut self, value: usize)94 pub fn skip_top(&mut self, value: usize) { 95 unsafe { 96 (*self.as_mut_ptr()).skip_top = value as c_int; 97 } 98 } 99 skip_bottom(&mut self, value: usize)100 pub fn skip_bottom(&mut self, value: usize) { 101 unsafe { 102 (*self.as_mut_ptr()).skip_bottom = value as c_int; 103 } 104 } 105 references(&self) -> usize106 pub fn references(&self) -> usize { 107 unsafe { (*self.as_ptr()).refs as usize } 108 } 109 set_field_order(&mut self, value: FieldOrder)110 pub fn set_field_order(&mut self, value: FieldOrder) { 111 unsafe { 112 (*self.as_mut_ptr()).field_order = value.into(); 113 } 114 } 115 116 // intra_matrix 117 // inter_matrix 118 intra_dc_precision(&self) -> u8119 pub fn intra_dc_precision(&self) -> u8 { 120 unsafe { (*self.as_ptr()).intra_dc_precision as u8 } 121 } 122 max_bit_rate(&self) -> usize123 pub fn max_bit_rate(&self) -> usize { 124 unsafe { (*self.as_ptr()).rc_max_rate as usize } 125 } 126 } 127 128 impl Deref for Video { 129 type Target = Opened; 130 deref(&self) -> &<Self as Deref>::Target131 fn deref(&self) -> &<Self as Deref>::Target { 132 &self.0 133 } 134 } 135 136 impl DerefMut for Video { deref_mut(&mut self) -> &mut <Self as Deref>::Target137 fn deref_mut(&mut self) -> &mut <Self as Deref>::Target { 138 &mut self.0 139 } 140 } 141 142 impl AsRef<Context> for Video { as_ref(&self) -> &Context143 fn as_ref(&self) -> &Context { 144 self 145 } 146 } 147 148 impl AsMut<Context> for Video { as_mut(&mut self) -> &mut Context149 fn as_mut(&mut self) -> &mut Context { 150 &mut self.0 151 } 152 } 153