xref: /aosp_15_r20/external/libgav1/src/gav1/decoder_buffer.h (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1 /*
2  * Copyright 2019 The libgav1 Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBGAV1_SRC_GAV1_DECODER_BUFFER_H_
18 #define LIBGAV1_SRC_GAV1_DECODER_BUFFER_H_
19 
20 #if defined(__cplusplus)
21 #include <cstdint>
22 #else
23 #include <stdint.h>
24 #endif  // defined(__cplusplus)
25 
26 #include "gav1/symbol_visibility.h"
27 
28 // All the declarations in this file are part of the public ABI.
29 
30 // The documentation for the enum values in this file can be found in Section
31 // 6.4.2 of the AV1 spec.
32 
33 typedef enum Libgav1ChromaSamplePosition {
34   kLibgav1ChromaSamplePositionUnknown,
35   kLibgav1ChromaSamplePositionVertical,
36   kLibgav1ChromaSamplePositionColocated,
37   kLibgav1ChromaSamplePositionReserved
38 } Libgav1ChromaSamplePosition;
39 
40 typedef enum Libgav1ImageFormat {
41   kLibgav1ImageFormatYuv420,
42   kLibgav1ImageFormatYuv422,
43   kLibgav1ImageFormatYuv444,
44   kLibgav1ImageFormatMonochrome400
45 } Libgav1ImageFormat;
46 
47 typedef enum Libgav1ColorPrimary {
48   // 0 is reserved.
49   kLibgav1ColorPrimaryBt709 = 1,
50   kLibgav1ColorPrimaryUnspecified,
51   // 3 is reserved.
52   kLibgav1ColorPrimaryBt470M = 4,
53   kLibgav1ColorPrimaryBt470Bg,
54   kLibgav1ColorPrimaryBt601,
55   kLibgav1ColorPrimarySmpte240,
56   kLibgav1ColorPrimaryGenericFilm,
57   kLibgav1ColorPrimaryBt2020,
58   kLibgav1ColorPrimaryXyz,
59   kLibgav1ColorPrimarySmpte431,
60   kLibgav1ColorPrimarySmpte432,
61   // 13-21 are reserved.
62   kLibgav1ColorPrimaryEbu3213 = 22,
63   // 23-254 are reserved.
64   kLibgav1MaxColorPrimaries = 255
65 } Libgav1ColorPrimary;
66 
67 typedef enum Libgav1TransferCharacteristics {
68   // 0 is reserved.
69   kLibgav1TransferCharacteristicsBt709 = 1,
70   kLibgav1TransferCharacteristicsUnspecified,
71   // 3 is reserved.
72   kLibgav1TransferCharacteristicsBt470M = 4,
73   kLibgav1TransferCharacteristicsBt470Bg,
74   kLibgav1TransferCharacteristicsBt601,
75   kLibgav1TransferCharacteristicsSmpte240,
76   kLibgav1TransferCharacteristicsLinear,
77   kLibgav1TransferCharacteristicsLog100,
78   kLibgav1TransferCharacteristicsLog100Sqrt10,
79   kLibgav1TransferCharacteristicsIec61966,
80   kLibgav1TransferCharacteristicsBt1361,
81   kLibgav1TransferCharacteristicsSrgb,
82   kLibgav1TransferCharacteristicsBt2020TenBit,
83   kLibgav1TransferCharacteristicsBt2020TwelveBit,
84   kLibgav1TransferCharacteristicsSmpte2084,
85   kLibgav1TransferCharacteristicsSmpte428,
86   kLibgav1TransferCharacteristicsHlg,
87   // 19-254 are reserved.
88   kLibgav1MaxTransferCharacteristics = 255
89 } Libgav1TransferCharacteristics;
90 
91 typedef enum Libgav1MatrixCoefficients {
92   kLibgav1MatrixCoefficientsIdentity,
93   kLibgav1MatrixCoefficientsBt709,
94   kLibgav1MatrixCoefficientsUnspecified,
95   // 3 is reserved.
96   kLibgav1MatrixCoefficientsFcc = 4,
97   kLibgav1MatrixCoefficientsBt470BG,
98   kLibgav1MatrixCoefficientsBt601,
99   kLibgav1MatrixCoefficientsSmpte240,
100   kLibgav1MatrixCoefficientsSmpteYcgco,
101   kLibgav1MatrixCoefficientsBt2020Ncl,
102   kLibgav1MatrixCoefficientsBt2020Cl,
103   kLibgav1MatrixCoefficientsSmpte2085,
104   kLibgav1MatrixCoefficientsChromatNcl,
105   kLibgav1MatrixCoefficientsChromatCl,
106   kLibgav1MatrixCoefficientsIctcp,
107   // 15-254 are reserved.
108   kLibgav1MaxMatrixCoefficients = 255
109 } Libgav1MatrixCoefficients;
110 
111 typedef enum Libgav1ColorRange {
112   // The color ranges are scaled by value << (bitdepth - 8) for 10 and 12bit
113   // streams.
114   kLibgav1ColorRangeStudio,  // Y [16..235], UV [16..240]
115   kLibgav1ColorRangeFull     // YUV/RGB [0..255]
116 } Libgav1ColorRange;
117 
118 // Section 6.7.3.
119 typedef struct Libgav1ObuMetadataHdrCll {  // NOLINT
120   uint16_t max_cll;                        // Maximum content light level.
121   uint16_t max_fall;                       // Maximum frame-average light level.
122 } Libgav1ObuMetadataHdrCll;
123 
124 // Section 6.7.4.
125 typedef struct Libgav1ObuMetadataHdrMdcv {  // NOLINT
126   // 0.16 fixed-point X/Y chromaticity coordinate as defined by CIE 1931 in
127   // R/G/B order.
128   uint16_t primary_chromaticity_x[3];
129   uint16_t primary_chromaticity_y[3];
130   // 0.16 fixed-point X/Y chromaticity coordinate as defined by CIE 1931.
131   uint16_t white_point_chromaticity_x;
132   uint16_t white_point_chromaticity_y;
133   // 24.8 fixed-point maximum luminance, represented in candelas per square
134   // meter.
135   uint32_t luminance_max;
136   // 18.14 fixed-point minimum luminance, represented in candelas per square
137   // meter.
138   uint32_t luminance_min;
139 } Libgav1ObuMetadataHdrMdcv;
140 
141 // Section 6.7.2.
142 typedef struct Libgav1ObuMetadataItutT35 {  // NOLINT
143   uint8_t country_code;
144   uint8_t country_code_extension_byte;  // Valid if country_code is 0xFF.
145   uint8_t* payload_bytes;
146   int payload_size;
147 } Libgav1ObuMetadataItutT35;
148 
149 typedef struct Libgav1DecoderBuffer {
150 #if defined(__cplusplus)
NumPlanesLibgav1DecoderBuffer151   LIBGAV1_PUBLIC int NumPlanes() const {
152     return (image_format == kLibgav1ImageFormatMonochrome400) ? 1 : 3;
153   }
154 #endif  // defined(__cplusplus)
155 
156   Libgav1ChromaSamplePosition chroma_sample_position;
157   Libgav1ImageFormat image_format;
158   Libgav1ColorRange color_range;
159   Libgav1ColorPrimary color_primary;
160   Libgav1TransferCharacteristics transfer_characteristics;
161   Libgav1MatrixCoefficients matrix_coefficients;
162 
163   int bitdepth;  // Stored image bitdepth.
164 
165   // Image display dimensions in Y/U/V order.
166   int displayed_width[3];   // Displayed image width.
167   int displayed_height[3];  // Displayed image height.
168 
169   // Values are given in Y/U/V order.
170   int stride[3];      // The width in bytes of one row of the |plane| buffer.
171                       // This may include padding bytes for alignment or
172                       // internal use by the decoder.
173   uint8_t* plane[3];  // The reconstructed image plane(s).
174 
175   // Spatial id of this frame.
176   int spatial_id;
177   // Temporal id of this frame.
178   int temporal_id;
179 
180   Libgav1ObuMetadataHdrCll hdr_cll;
181   int has_hdr_cll;  // 1 if the values in hdr_cll are valid for this frame. 0
182                     // otherwise.
183 
184   Libgav1ObuMetadataHdrMdcv hdr_mdcv;
185   int has_hdr_mdcv;  // 1 if the values in hdr_mdcv are valid for this frame. 0
186                      // otherwise.
187 
188   Libgav1ObuMetadataItutT35 itut_t35;
189   int has_itut_t35;  // 1 if the values in itut_t35 are valid for this frame. 0
190                      // otherwise.
191 
192   // The |user_private_data| argument passed to Decoder::EnqueueFrame().
193   int64_t user_private_data;
194   // The |private_data| field of FrameBuffer. Set by the get frame buffer
195   // callback when it allocates a frame buffer.
196   void* buffer_private_data;
197 } Libgav1DecoderBuffer;
198 
199 #if defined(__cplusplus)
200 namespace libgav1 {
201 
202 using ChromaSamplePosition = Libgav1ChromaSamplePosition;
203 constexpr ChromaSamplePosition kChromaSamplePositionUnknown =
204     kLibgav1ChromaSamplePositionUnknown;
205 constexpr ChromaSamplePosition kChromaSamplePositionVertical =
206     kLibgav1ChromaSamplePositionVertical;
207 constexpr ChromaSamplePosition kChromaSamplePositionColocated =
208     kLibgav1ChromaSamplePositionColocated;
209 constexpr ChromaSamplePosition kChromaSamplePositionReserved =
210     kLibgav1ChromaSamplePositionReserved;
211 
212 using ImageFormat = Libgav1ImageFormat;
213 constexpr ImageFormat kImageFormatYuv420 = kLibgav1ImageFormatYuv420;
214 constexpr ImageFormat kImageFormatYuv422 = kLibgav1ImageFormatYuv422;
215 constexpr ImageFormat kImageFormatYuv444 = kLibgav1ImageFormatYuv444;
216 constexpr ImageFormat kImageFormatMonochrome400 =
217     kLibgav1ImageFormatMonochrome400;
218 
219 using ColorPrimary = Libgav1ColorPrimary;
220 constexpr ColorPrimary kColorPrimaryBt709 = kLibgav1ColorPrimaryBt709;
221 constexpr ColorPrimary kColorPrimaryUnspecified =
222     kLibgav1ColorPrimaryUnspecified;
223 constexpr ColorPrimary kColorPrimaryBt470M = kLibgav1ColorPrimaryBt470M;
224 constexpr ColorPrimary kColorPrimaryBt470Bg = kLibgav1ColorPrimaryBt470Bg;
225 constexpr ColorPrimary kColorPrimaryBt601 = kLibgav1ColorPrimaryBt601;
226 constexpr ColorPrimary kColorPrimarySmpte240 = kLibgav1ColorPrimarySmpte240;
227 constexpr ColorPrimary kColorPrimaryGenericFilm =
228     kLibgav1ColorPrimaryGenericFilm;
229 constexpr ColorPrimary kColorPrimaryBt2020 = kLibgav1ColorPrimaryBt2020;
230 constexpr ColorPrimary kColorPrimaryXyz = kLibgav1ColorPrimaryXyz;
231 constexpr ColorPrimary kColorPrimarySmpte431 = kLibgav1ColorPrimarySmpte431;
232 constexpr ColorPrimary kColorPrimarySmpte432 = kLibgav1ColorPrimarySmpte432;
233 constexpr ColorPrimary kColorPrimaryEbu3213 = kLibgav1ColorPrimaryEbu3213;
234 constexpr ColorPrimary kMaxColorPrimaries = kLibgav1MaxColorPrimaries;
235 
236 using TransferCharacteristics = Libgav1TransferCharacteristics;
237 constexpr TransferCharacteristics kTransferCharacteristicsBt709 =
238     kLibgav1TransferCharacteristicsBt709;
239 constexpr TransferCharacteristics kTransferCharacteristicsUnspecified =
240     kLibgav1TransferCharacteristicsUnspecified;
241 constexpr TransferCharacteristics kTransferCharacteristicsBt470M =
242     kLibgav1TransferCharacteristicsBt470M;
243 constexpr TransferCharacteristics kTransferCharacteristicsBt470Bg =
244     kLibgav1TransferCharacteristicsBt470Bg;
245 constexpr TransferCharacteristics kTransferCharacteristicsBt601 =
246     kLibgav1TransferCharacteristicsBt601;
247 constexpr TransferCharacteristics kTransferCharacteristicsSmpte240 =
248     kLibgav1TransferCharacteristicsSmpte240;
249 constexpr TransferCharacteristics kTransferCharacteristicsLinear =
250     kLibgav1TransferCharacteristicsLinear;
251 constexpr TransferCharacteristics kTransferCharacteristicsLog100 =
252     kLibgav1TransferCharacteristicsLog100;
253 constexpr TransferCharacteristics kTransferCharacteristicsLog100Sqrt10 =
254     kLibgav1TransferCharacteristicsLog100Sqrt10;
255 constexpr TransferCharacteristics kTransferCharacteristicsIec61966 =
256     kLibgav1TransferCharacteristicsIec61966;
257 constexpr TransferCharacteristics kTransferCharacteristicsBt1361 =
258     kLibgav1TransferCharacteristicsBt1361;
259 constexpr TransferCharacteristics kTransferCharacteristicsSrgb =
260     kLibgav1TransferCharacteristicsSrgb;
261 constexpr TransferCharacteristics kTransferCharacteristicsBt2020TenBit =
262     kLibgav1TransferCharacteristicsBt2020TenBit;
263 constexpr TransferCharacteristics kTransferCharacteristicsBt2020TwelveBit =
264     kLibgav1TransferCharacteristicsBt2020TwelveBit;
265 constexpr TransferCharacteristics kTransferCharacteristicsSmpte2084 =
266     kLibgav1TransferCharacteristicsSmpte2084;
267 constexpr TransferCharacteristics kTransferCharacteristicsSmpte428 =
268     kLibgav1TransferCharacteristicsSmpte428;
269 constexpr TransferCharacteristics kTransferCharacteristicsHlg =
270     kLibgav1TransferCharacteristicsHlg;
271 constexpr TransferCharacteristics kMaxTransferCharacteristics =
272     kLibgav1MaxTransferCharacteristics;
273 
274 using MatrixCoefficients = Libgav1MatrixCoefficients;
275 constexpr MatrixCoefficients kMatrixCoefficientsIdentity =
276     kLibgav1MatrixCoefficientsIdentity;
277 constexpr MatrixCoefficients kMatrixCoefficientsBt709 =
278     kLibgav1MatrixCoefficientsBt709;
279 constexpr MatrixCoefficients kMatrixCoefficientsUnspecified =
280     kLibgav1MatrixCoefficientsUnspecified;
281 constexpr MatrixCoefficients kMatrixCoefficientsFcc =
282     kLibgav1MatrixCoefficientsFcc;
283 constexpr MatrixCoefficients kMatrixCoefficientsBt470BG =
284     kLibgav1MatrixCoefficientsBt470BG;
285 constexpr MatrixCoefficients kMatrixCoefficientsBt601 =
286     kLibgav1MatrixCoefficientsBt601;
287 constexpr MatrixCoefficients kMatrixCoefficientsSmpte240 =
288     kLibgav1MatrixCoefficientsSmpte240;
289 constexpr MatrixCoefficients kMatrixCoefficientsSmpteYcgco =
290     kLibgav1MatrixCoefficientsSmpteYcgco;
291 constexpr MatrixCoefficients kMatrixCoefficientsBt2020Ncl =
292     kLibgav1MatrixCoefficientsBt2020Ncl;
293 constexpr MatrixCoefficients kMatrixCoefficientsBt2020Cl =
294     kLibgav1MatrixCoefficientsBt2020Cl;
295 constexpr MatrixCoefficients kMatrixCoefficientsSmpte2085 =
296     kLibgav1MatrixCoefficientsSmpte2085;
297 constexpr MatrixCoefficients kMatrixCoefficientsChromatNcl =
298     kLibgav1MatrixCoefficientsChromatNcl;
299 constexpr MatrixCoefficients kMatrixCoefficientsChromatCl =
300     kLibgav1MatrixCoefficientsChromatCl;
301 constexpr MatrixCoefficients kMatrixCoefficientsIctcp =
302     kLibgav1MatrixCoefficientsIctcp;
303 constexpr MatrixCoefficients kMaxMatrixCoefficients =
304     kLibgav1MaxMatrixCoefficients;
305 
306 using ColorRange = Libgav1ColorRange;
307 constexpr ColorRange kColorRangeStudio = kLibgav1ColorRangeStudio;
308 constexpr ColorRange kColorRangeFull = kLibgav1ColorRangeFull;
309 
310 using ObuMetadataHdrCll = Libgav1ObuMetadataHdrCll;
311 using ObuMetadataHdrMdcv = Libgav1ObuMetadataHdrMdcv;
312 using ObuMetadataItutT35 = Libgav1ObuMetadataItutT35;
313 
314 using DecoderBuffer = Libgav1DecoderBuffer;
315 
316 }  // namespace libgav1
317 #endif  // defined(__cplusplus)
318 
319 #endif  // LIBGAV1_SRC_GAV1_DECODER_BUFFER_H_
320