forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB8c7bf80Tahinli3 months ago114 commits

enc_misc.rs337 lines, 10.0 KiBHistoryRawDownload
1// Copyright 2024 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Wrappers around `VAEncMisc*` types.
6
7use crate::bindings;
8
9#[repr(C)]
10#[derive(Default)]
11pub struct MiscEncParamBuffer<T> {
12 hdr: bindings::VAEncMiscParameterBuffer,
13 value: T,
14}
15
16impl<T> MiscEncParamBuffer<T> {
17 fn new(type_: bindings::VAEncMiscParameterType::Type, value: T) -> Self {
18 Self {
19 hdr: bindings::_VAEncMiscParameterBuffer {
20 type_,
21 data: Default::default(),
22 },
23 value,
24 }
25 }
26
27 fn new_boxed(type_: bindings::VAEncMiscParameterType::Type, value: T) -> Box<Self> {
28 Box::new(Self::new(type_, value))
29 }
30}
31
32#[derive(Default)]
33pub struct EncMiscParameterFrameRate(
34 Box<MiscEncParamBuffer<bindings::VAEncMiscParameterFrameRate>>,
35);
36
37impl EncMiscParameterFrameRate {
38 pub fn new(framerate: u32, temporal_id: u32) -> Self {
39 let _bitfield_1 =
40 bindings::_VAEncMiscParameterFrameRate__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
41 temporal_id,
42 Default::default(),
43 );
44
45 Self(MiscEncParamBuffer::new_boxed(
46 bindings::VAEncMiscParameterType::VAEncMiscParameterTypeFrameRate,
47 bindings::_VAEncMiscParameterFrameRate {
48 framerate,
49 framerate_flags: bindings::_VAEncMiscParameterFrameRate__bindgen_ty_1 {
50 bits: bindings::_VAEncMiscParameterFrameRate__bindgen_ty_1__bindgen_ty_1 {
51 _bitfield_align_1: Default::default(),
52 _bitfield_1,
53 },
54 },
55 ..Default::default()
56 },
57 ))
58 }
59
60 pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterFrameRate> {
61 &self.0
62 }
63
64 pub(crate) fn inner_mut(
65 &mut self,
66 ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterFrameRate> {
67 &mut self.0
68 }
69}
70
71#[derive(Default)]
72pub struct RcFlags(bindings::_VAEncMiscParameterRateControl__bindgen_ty_1);
73
74impl RcFlags {
75 pub fn new(
76 reset: u32,
77 disable_frame_skip: u32,
78 disable_bit_stuffing: u32,
79 mb_rate_control: u32,
80 temporal_id: u32,
81 cfs_i_frames: u32,
82 enable_parallel_brc: u32,
83 enable_dynamic_scaling: u32,
84 frame_tolerance_mode: u32,
85 ) -> Self {
86 let _bitfield_1 =
87 bindings::_VAEncMiscParameterRateControl__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
88 reset,
89 disable_frame_skip,
90 disable_bit_stuffing,
91 mb_rate_control,
92 temporal_id,
93 cfs_i_frames,
94 enable_parallel_brc,
95 enable_dynamic_scaling,
96 frame_tolerance_mode,
97 Default::default(),
98 );
99
100 Self(bindings::_VAEncMiscParameterRateControl__bindgen_ty_1 {
101 bits: bindings::_VAEncMiscParameterRateControl__bindgen_ty_1__bindgen_ty_1 {
102 _bitfield_align_1: Default::default(),
103 _bitfield_1,
104 },
105 })
106 }
107}
108
109#[derive(Default)]
110pub struct EncMiscParameterRateControl(
111 Box<MiscEncParamBuffer<bindings::VAEncMiscParameterRateControl>>,
112);
113
114impl EncMiscParameterRateControl {
115 pub fn new(
116 bits_per_second: u32,
117 target_percentage: u32,
118 window_size: u32,
119 initial_qp: u32,
120 min_qp: u32,
121 basic_unit_size: u32,
122 rc_flags: RcFlags,
123 icq_quality_factor: u32,
124 max_qp: u32,
125 quality_factor: u32,
126 target_frame_size: u32,
127 ) -> Self {
128 Self(MiscEncParamBuffer::new_boxed(
129 bindings::VAEncMiscParameterType::VAEncMiscParameterTypeRateControl,
130 bindings::VAEncMiscParameterRateControl {
131 bits_per_second,
132 target_percentage,
133 window_size,
134 initial_qp,
135 min_qp,
136 basic_unit_size,
137 rc_flags: rc_flags.0,
138 ICQ_quality_factor: icq_quality_factor,
139 max_qp,
140 quality_factor,
141 target_frame_size,
142 ..Default::default()
143 },
144 ))
145 }
146
147 pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterRateControl> {
148 &self.0
149 }
150
151 pub(crate) fn inner_mut(
152 &mut self,
153 ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterRateControl> {
154 &mut self.0
155 }
156}
157
158#[derive(Default)]
159pub struct EncMiscParameterMaxSliceSize(
160 Box<MiscEncParamBuffer<bindings::VAEncMiscParameterMaxSliceSize>>,
161);
162
163impl EncMiscParameterMaxSliceSize {
164 pub fn new(max_slice_size: u32) -> Self {
165 Self(MiscEncParamBuffer::new_boxed(
166 bindings::VAEncMiscParameterType::VAEncMiscParameterTypeMaxFrameSize,
167 bindings::VAEncMiscParameterMaxSliceSize {
168 max_slice_size,
169 ..Default::default()
170 },
171 ))
172 }
173
174 pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterMaxSliceSize> {
175 &self.0
176 }
177
178 pub(crate) fn inner_mut(
179 &mut self,
180 ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterMaxSliceSize> {
181 &mut self.0
182 }
183}
184
185#[derive(Default)]
186pub struct EncMiscParameterBufferMaxFrameSize(
187 Box<MiscEncParamBuffer<bindings::VAEncMiscParameterBufferMaxFrameSize>>,
188);
189
190impl EncMiscParameterBufferMaxFrameSize {
191 pub fn new(max_frame_size: u32) -> Self {
192 Self(MiscEncParamBuffer::new_boxed(
193 bindings::VAEncMiscParameterType::VAEncMiscParameterTypeMaxFrameSize,
194 bindings::VAEncMiscParameterBufferMaxFrameSize {
195 type_: bindings::VAEncMiscParameterType::VAEncMiscParameterTypeMaxFrameSize,
196 max_frame_size,
197 ..Default::default()
198 },
199 ))
200 }
201
202 pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterBufferMaxFrameSize> {
203 &self.0
204 }
205
206 pub(crate) fn inner_mut(
207 &mut self,
208 ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterBufferMaxFrameSize> {
209 &mut self.0
210 }
211}
212
213#[derive(Default)]
214pub struct EncMiscParameterSkipFrame(
215 Box<MiscEncParamBuffer<bindings::VAEncMiscParameterSkipFrame>>,
216);
217
218impl EncMiscParameterSkipFrame {
219 pub fn new(skip_frame_flag: u8, num_skip_frames: u8, size_skip_frames: u32) -> Self {
220 Self(MiscEncParamBuffer::new_boxed(
221 bindings::VAEncMiscParameterType::VAEncMiscParameterTypeSkipFrame,
222 bindings::VAEncMiscParameterSkipFrame {
223 skip_frame_flag,
224 num_skip_frames,
225 size_skip_frames,
226 ..Default::default()
227 },
228 ))
229 }
230
231 pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterSkipFrame> {
232 &self.0
233 }
234
235 pub(crate) fn inner_mut(
236 &mut self,
237 ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterSkipFrame> {
238 &mut self.0
239 }
240}
241
242#[derive(Default)]
243pub struct EncMiscParameterHRD(Box<MiscEncParamBuffer<bindings::VAEncMiscParameterHRD>>);
244
245impl EncMiscParameterHRD {
246 pub fn new(initial_buffer_fullness: u32, buffer_size: u32) -> Self {
247 Self(MiscEncParamBuffer::new_boxed(
248 bindings::VAEncMiscParameterType::VAEncMiscParameterTypeHRD,
249 bindings::VAEncMiscParameterHRD {
250 initial_buffer_fullness,
251 buffer_size,
252 ..Default::default()
253 },
254 ))
255 }
256
257 pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterHRD> {
258 &self.0
259 }
260
261 pub(crate) fn inner_mut(&mut self) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterHRD> {
262 &mut self.0
263 }
264}
265
266#[derive(Default)]
267pub struct EncMiscParameterBufferQualityLevel(
268 Box<MiscEncParamBuffer<bindings::VAEncMiscParameterBufferQualityLevel>>,
269);
270
271impl EncMiscParameterBufferQualityLevel {
272 pub fn new(quality_level: u32) -> Self {
273 Self(MiscEncParamBuffer::new_boxed(
274 bindings::VAEncMiscParameterType::VAEncMiscParameterTypeQualityLevel,
275 bindings::VAEncMiscParameterBufferQualityLevel {
276 quality_level,
277 ..Default::default()
278 },
279 ))
280 }
281
282 pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterBufferQualityLevel> {
283 &self.0
284 }
285
286 pub(crate) fn inner_mut(
287 &mut self,
288 ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterBufferQualityLevel> {
289 &mut self.0
290 }
291}
292
293#[derive(Default)]
294pub struct EncMiscParameterQuantization(
295 Box<MiscEncParamBuffer<bindings::VAEncMiscParameterQuantization>>,
296);
297
298impl EncMiscParameterQuantization {
299 pub fn new(
300 disable_trellis: bool,
301 enable_trellis_i: bool,
302 enable_trellis_p: bool,
303 enable_trellis_b: bool,
304 ) -> Self {
305 let _bitfield_1 =
306 bindings::_VAEncMiscParameterQuantization__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
307 disable_trellis as u32,
308 enable_trellis_i as u32,
309 enable_trellis_p as u32,
310 enable_trellis_b as u32,
311 Default::default(),
312 );
313
314 Self(MiscEncParamBuffer::new_boxed(
315 bindings::VAEncMiscParameterType::VAEncMiscParameterTypeQuantization,
316 bindings::VAEncMiscParameterQuantization {
317 quantization_flags: bindings::_VAEncMiscParameterQuantization__bindgen_ty_1 {
318 bits: bindings::_VAEncMiscParameterQuantization__bindgen_ty_1__bindgen_ty_1 {
319 _bitfield_align_1: Default::default(),
320 _bitfield_1,
321 },
322 },
323 ..Default::default()
324 },
325 ))
326 }
327
328 pub fn inner(&self) -> &MiscEncParamBuffer<bindings::VAEncMiscParameterQuantization> {
329 &self.0
330 }
331
332 pub(crate) fn inner_mut(
333 &mut self,
334 ) -> &mut MiscEncParamBuffer<bindings::VAEncMiscParameterQuantization> {
335 &mut self.0
336 }
337}