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