ffmpeg_next_crossfix/codec/decoder/
video.rs1use std::ops::{Deref, DerefMut};
2
3use ffi::*;
4use libc::c_int;
5
6use super::{slice, Opened};
7use codec::Context;
8use color;
9use frame;
10use util::chroma;
11use util::format;
12use {packet, Error, FieldOrder, Rational};
13
14pub struct Video(pub Opened);
15
16impl 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 )]
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
42 pub fn width(&self) -> u32 {
43 unsafe { (*self.as_ptr()).width as u32 }
44 }
45
46 pub fn height(&self) -> u32 {
47 unsafe { (*self.as_ptr()).height as u32 }
48 }
49
50 pub fn format(&self) -> format::Pixel {
51 unsafe { format::Pixel::from((*self.as_ptr()).pix_fmt) }
52 }
53
54 pub fn has_b_frames(&self) -> bool {
55 unsafe { (*self.as_ptr()).has_b_frames != 0 }
56 }
57
58 pub fn aspect_ratio(&self) -> Rational {
59 unsafe { Rational::from((*self.as_ptr()).sample_aspect_ratio) }
60 }
61
62 pub fn color_space(&self) -> color::Space {
63 unsafe { color::Space::from((*self.as_ptr()).colorspace) }
64 }
65
66 pub fn color_range(&self) -> color::Range {
67 unsafe { color::Range::from((*self.as_ptr()).color_range) }
68 }
69
70 pub fn color_primaries(&self) -> color::Primaries {
71 unsafe { color::Primaries::from((*self.as_ptr()).color_primaries) }
72 }
73
74 pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
75 unsafe { color::TransferCharacteristic::from((*self.as_ptr()).color_trc) }
76 }
77
78 pub fn chroma_location(&self) -> chroma::Location {
79 unsafe { chroma::Location::from((*self.as_ptr()).chroma_sample_location) }
80 }
81
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
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
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
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
106 pub fn references(&self) -> usize {
107 unsafe { (*self.as_ptr()).refs as usize }
108 }
109
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 pub fn intra_dc_precision(&self) -> u8 {
120 unsafe { (*self.as_ptr()).intra_dc_precision as u8 }
121 }
122
123 pub fn max_bit_rate(&self) -> usize {
124 unsafe { (*self.as_ptr()).rc_max_rate as usize }
125 }
126}
127
128impl Deref for Video {
129 type Target = Opened;
130
131 fn deref(&self) -> &<Self as Deref>::Target {
132 &self.0
133 }
134}
135
136impl DerefMut for Video {
137 fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
138 &mut self.0
139 }
140}
141
142impl AsRef<Context> for Video {
143 fn as_ref(&self) -> &Context {
144 self
145 }
146}
147
148impl AsMut<Context> for Video {
149 fn as_mut(&mut self) -> &mut Context {
150 &mut self.0
151 }
152}