1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2023 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! Wrappers around MPEG2 `VABuffer` types.

use crate::bindings;

/// Wrapper over the `picture_coding_extension` bindgen field in `VAPictureParameterBufferMPEG2`.
pub struct MPEG2PictureCodingExtension(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1);

impl MPEG2PictureCodingExtension {
    /// Creates the bindgen field.
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        intra_dc_precision: u32,
        picture_structure: u32,
        top_field_first: u32,
        frame_pred_frame_dct: u32,
        concealment_motion_vectors: u32,
        q_scale_type: u32,
        intra_vlc_format: u32,
        alternate_scan: u32,
        repeat_first_field: u32,
        progressive_frame: u32,
        is_first_field: u32,
    ) -> Self {
        let _bitfield_1 =
            bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1::new_bitfield_1(
                intra_dc_precision,
                picture_structure,
                top_field_first,
                frame_pred_frame_dct,
                concealment_motion_vectors,
                q_scale_type,
                intra_vlc_format,
                alternate_scan,
                repeat_first_field,
                progressive_frame,
                is_first_field,
            );

        Self(bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 {
            bits: bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1__bindgen_ty_1 {
                _bitfield_align_1: Default::default(),
                _bitfield_1,
                __bindgen_padding_0: Default::default(),
            },
        })
    }

    /// Returns the inner FFI type. Useful for testing purposes.
    pub fn inner(&mut self) -> &bindings::_VAPictureParameterBufferMPEG2__bindgen_ty_1 {
        &self.0
    }
}

/// Wrapper over the `PictureParameterBufferMPEG2` FFI type.
pub struct PictureParameterBufferMPEG2(Box<bindings::VAPictureParameterBufferMPEG2>);

impl PictureParameterBufferMPEG2 {
    /// Creates the wrapper.
    pub fn new(
        horizontal_size: u16,
        vertical_size: u16,
        forward_reference_picture: bindings::VASurfaceID,
        backward_reference_picture: bindings::VASurfaceID,
        picture_coding_type: i32,
        f_code: i32,
        picture_coding_extension: &MPEG2PictureCodingExtension,
    ) -> Self {
        let picture_coding_extension = picture_coding_extension.0;

        Self(Box::new(bindings::VAPictureParameterBufferMPEG2 {
            horizontal_size,
            vertical_size,
            forward_reference_picture,
            backward_reference_picture,
            picture_coding_type,
            f_code,
            picture_coding_extension,
            va_reserved: Default::default(),
        }))
    }

    pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAPictureParameterBufferMPEG2 {
        self.0.as_mut()
    }

    /// Returns the inner FFI type. Useful for testing purposes.
    pub fn inner(&mut self) -> &bindings::VAPictureParameterBufferMPEG2 {
        self.0.as_ref()
    }
}

/// Wrapper over the `VASliceParameterBufferMPEG2` FFI type.
pub struct SliceParameterBufferMPEG2(Box<bindings::VASliceParameterBufferMPEG2>);

impl SliceParameterBufferMPEG2 {
    /// Creates the wrapper.
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        slice_data_size: u32,
        slice_data_offset: u32,
        slice_data_flag: u32,
        macroblock_offset: u32,
        slice_horizontal_position: u32,
        slice_vertical_position: u32,
        quantiser_scale_code: i32,
        intra_slice_flag: i32,
    ) -> Self {
        Self(Box::new(bindings::VASliceParameterBufferMPEG2 {
            slice_data_size,
            slice_data_offset,
            slice_data_flag,
            macroblock_offset,
            slice_horizontal_position,
            slice_vertical_position,
            quantiser_scale_code,
            intra_slice_flag,
            va_reserved: Default::default(),
        }))
    }

    pub(crate) fn inner_mut(&mut self) -> &mut bindings::VASliceParameterBufferMPEG2 {
        self.0.as_mut()
    }

    /// Returns the inner FFI type. Useful for testing purposes.
    pub fn inner(&self) -> &bindings::VASliceParameterBufferMPEG2 {
        self.0.as_ref()
    }
}

/// Wrapper over the `VAIQMatrixBufferMPEG2` FFI type.
pub struct IQMatrixBufferMPEG2(Box<bindings::VAIQMatrixBufferMPEG2>);

impl IQMatrixBufferMPEG2 {
    /// Creates the wrapper.
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        load_intra_quantiser_matrix: i32,
        load_non_intra_quantiser_matrix: i32,
        load_chroma_intra_quantiser_matrix: i32,
        load_chroma_non_intra_quantiser_matrix: i32,
        intra_quantiser_matrix: [u8; 64usize],
        non_intra_quantiser_matrix: [u8; 64usize],
        chroma_intra_quantiser_matrix: [u8; 64usize],
        chroma_non_intra_quantiser_matrix: [u8; 64usize],
    ) -> Self {
        Self(Box::new(bindings::VAIQMatrixBufferMPEG2 {
            load_intra_quantiser_matrix,
            load_non_intra_quantiser_matrix,
            load_chroma_intra_quantiser_matrix,
            load_chroma_non_intra_quantiser_matrix,
            intra_quantiser_matrix,
            non_intra_quantiser_matrix,
            chroma_intra_quantiser_matrix,
            chroma_non_intra_quantiser_matrix,
            va_reserved: Default::default(),
        }))
    }

    pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAIQMatrixBufferMPEG2 {
        self.0.as_mut()
    }

    /// Returns the inner FFI type. Useful for testing purposes.
    pub fn inner(&self) -> &bindings::VAIQMatrixBufferMPEG2 {
        self.0.as_ref()
    }
}