ffmpeg_the_third/codec/decoder/
video.rs1use std::ops::{Deref, DerefMut};
2
3use libc::c_int;
4
5use super::{slice, Opened};
6use crate::codec::Context;
7use crate::color;
8use crate::util::chroma;
9use crate::util::format;
10use crate::{FieldOrder, Rational};
11
12pub struct Video(pub Opened);
13
14impl Video {
15 pub fn width(&self) -> u32 {
16 unsafe { (*self.as_ptr()).width as u32 }
17 }
18
19 pub fn height(&self) -> u32 {
20 unsafe { (*self.as_ptr()).height as u32 }
21 }
22
23 pub fn format(&self) -> format::Pixel {
24 unsafe { format::Pixel::from((*self.as_ptr()).pix_fmt) }
25 }
26
27 pub fn has_b_frames(&self) -> bool {
28 unsafe { (*self.as_ptr()).has_b_frames != 0 }
29 }
30
31 pub fn aspect_ratio(&self) -> Rational {
32 unsafe { Rational::from((*self.as_ptr()).sample_aspect_ratio) }
33 }
34
35 pub fn color_space(&self) -> color::Space {
36 unsafe { color::Space::from((*self.as_ptr()).colorspace) }
37 }
38
39 pub fn color_range(&self) -> color::Range {
40 unsafe { color::Range::from((*self.as_ptr()).color_range) }
41 }
42
43 pub fn color_primaries(&self) -> color::Primaries {
44 unsafe { color::Primaries::from((*self.as_ptr()).color_primaries) }
45 }
46
47 pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
48 unsafe { color::TransferCharacteristic::from((*self.as_ptr()).color_trc) }
49 }
50
51 pub fn chroma_location(&self) -> chroma::Location {
52 unsafe { chroma::Location::from((*self.as_ptr()).chroma_sample_location) }
53 }
54
55 #[cfg(not(feature = "ffmpeg_7_0"))]
56 pub fn set_slice_count(&mut self, value: usize) {
57 unsafe {
58 (*self.as_mut_ptr()).slice_count = value as c_int;
59 }
60 }
61
62 pub fn set_slice_flags(&mut self, value: slice::Flags) {
63 unsafe {
64 (*self.as_mut_ptr()).slice_flags = value.bits();
65 }
66 }
67
68 pub fn skip_top(&mut self, value: usize) {
69 unsafe {
70 (*self.as_mut_ptr()).skip_top = value as c_int;
71 }
72 }
73
74 pub fn skip_bottom(&mut self, value: usize) {
75 unsafe {
76 (*self.as_mut_ptr()).skip_bottom = value as c_int;
77 }
78 }
79
80 pub fn references(&self) -> usize {
81 unsafe { (*self.as_ptr()).refs as usize }
82 }
83
84 pub fn set_field_order(&mut self, value: FieldOrder) {
85 unsafe {
86 (*self.as_mut_ptr()).field_order = value.into();
87 }
88 }
89
90 pub fn intra_dc_precision(&self) -> u8 {
94 unsafe { (*self.as_ptr()).intra_dc_precision as u8 }
95 }
96
97 pub fn max_bit_rate(&self) -> usize {
98 unsafe { (*self.as_ptr()).rc_max_rate as usize }
99 }
100}
101
102impl Deref for Video {
103 type Target = Opened;
104
105 fn deref(&self) -> &<Self as Deref>::Target {
106 &self.0
107 }
108}
109
110impl DerefMut for Video {
111 fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
112 &mut self.0
113 }
114}
115
116impl AsRef<Context> for Video {
117 fn as_ref(&self) -> &Context {
118 self
119 }
120}
121
122impl AsMut<Context> for Video {
123 fn as_mut(&mut self) -> &mut Context {
124 &mut self.0
125 }
126}