• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 typedef struct Libgav1ObuMetadataHdrCll {  // NOLINT
119   uint16_t max_cll;                        // Maximum content light level.
120   uint16_t max_fall;                       // Maximum frame-average light level.
121 } Libgav1ObuMetadataHdrCll;
122 
123 typedef struct Libgav1ObuMetadataHdrMdcv {  // NOLINT
124   uint16_t primary_chromaticity_x[3];
125   uint16_t primary_chromaticity_y[3];
126   uint16_t white_point_chromaticity_x;
127   uint16_t white_point_chromaticity_y;
128   uint32_t luminance_max;
129   uint32_t luminance_min;
130 } Libgav1ObuMetadataHdrMdcv;
131 
132 typedef struct Libgav1ObuMetadataItutT35 {  // NOLINT
133   uint8_t country_code;
134   uint8_t country_code_extension_byte;  // Valid if country_code is 0xFF.
135   uint8_t* payload_bytes;
136   int payload_size;
137 } Libgav1ObuMetadataItutT35;
138 
139 typedef struct Libgav1DecoderBuffer {
140 #if defined(__cplusplus)
NumPlanesLibgav1DecoderBuffer141   LIBGAV1_PUBLIC int NumPlanes() const {
142     return (image_format == kLibgav1ImageFormatMonochrome400) ? 1 : 3;
143   }
144 #endif  // defined(__cplusplus)
145 
146   Libgav1ChromaSamplePosition chroma_sample_position;
147   Libgav1ImageFormat image_format;
148   Libgav1ColorRange color_range;
149   Libgav1ColorPrimary color_primary;
150   Libgav1TransferCharacteristics transfer_characteristics;
151   Libgav1MatrixCoefficients matrix_coefficients;
152 
153   int bitdepth;  // Stored image bitdepth.
154 
155   // Image display dimensions in Y/U/V order.
156   int displayed_width[3];   // Displayed image width.
157   int displayed_height[3];  // Displayed image height.
158 
159   // Values are given in Y/U/V order.
160   int stride[3];      // The width in bytes of one row of the |plane| buffer.
161                       // This may include padding bytes for alignment or
162                       // internal use by the decoder.
163   uint8_t* plane[3];  // The reconstructed image plane(s).
164 
165   // Spatial id of this frame.
166   int spatial_id;
167   // Temporal id of this frame.
168   int temporal_id;
169 
170   Libgav1ObuMetadataHdrCll hdr_cll;
171   int has_hdr_cll;  // 1 if the values in hdr_cll are valid for this frame. 0
172                     // otherwise.
173 
174   Libgav1ObuMetadataHdrMdcv hdr_mdcv;
175   int has_hdr_mdcv;  // 1 if the values in hdr_mdcv are valid for this frame. 0
176                      // otherwise.
177 
178   Libgav1ObuMetadataItutT35 itut_t35;
179   int has_itut_t35;  // 1 if the values in itut_t35 are valid for this frame. 0
180                      // otherwise.
181 
182   // The |user_private_data| argument passed to Decoder::EnqueueFrame().
183   int64_t user_private_data;
184   // The |private_data| field of FrameBuffer. Set by the get frame buffer
185   // callback when it allocates a frame buffer.
186   void* buffer_private_data;
187 } Libgav1DecoderBuffer;
188 
189 #if defined(__cplusplus)
190 namespace libgav1 {
191 
192 using ChromaSamplePosition = Libgav1ChromaSamplePosition;
193 constexpr ChromaSamplePosition kChromaSamplePositionUnknown =
194     kLibgav1ChromaSamplePositionUnknown;
195 constexpr ChromaSamplePosition kChromaSamplePositionVertical =
196     kLibgav1ChromaSamplePositionVertical;
197 constexpr ChromaSamplePosition kChromaSamplePositionColocated =
198     kLibgav1ChromaSamplePositionColocated;
199 constexpr ChromaSamplePosition kChromaSamplePositionReserved =
200     kLibgav1ChromaSamplePositionReserved;
201 
202 using ImageFormat = Libgav1ImageFormat;
203 constexpr ImageFormat kImageFormatYuv420 = kLibgav1ImageFormatYuv420;
204 constexpr ImageFormat kImageFormatYuv422 = kLibgav1ImageFormatYuv422;
205 constexpr ImageFormat kImageFormatYuv444 = kLibgav1ImageFormatYuv444;
206 constexpr ImageFormat kImageFormatMonochrome400 =
207     kLibgav1ImageFormatMonochrome400;
208 
209 using ColorPrimary = Libgav1ColorPrimary;
210 constexpr ColorPrimary kColorPrimaryBt709 = kLibgav1ColorPrimaryBt709;
211 constexpr ColorPrimary kColorPrimaryUnspecified =
212     kLibgav1ColorPrimaryUnspecified;
213 constexpr ColorPrimary kColorPrimaryBt470M = kLibgav1ColorPrimaryBt470M;
214 constexpr ColorPrimary kColorPrimaryBt470Bg = kLibgav1ColorPrimaryBt470Bg;
215 constexpr ColorPrimary kColorPrimaryBt601 = kLibgav1ColorPrimaryBt601;
216 constexpr ColorPrimary kColorPrimarySmpte240 = kLibgav1ColorPrimarySmpte240;
217 constexpr ColorPrimary kColorPrimaryGenericFilm =
218     kLibgav1ColorPrimaryGenericFilm;
219 constexpr ColorPrimary kColorPrimaryBt2020 = kLibgav1ColorPrimaryBt2020;
220 constexpr ColorPrimary kColorPrimaryXyz = kLibgav1ColorPrimaryXyz;
221 constexpr ColorPrimary kColorPrimarySmpte431 = kLibgav1ColorPrimarySmpte431;
222 constexpr ColorPrimary kColorPrimarySmpte432 = kLibgav1ColorPrimarySmpte432;
223 constexpr ColorPrimary kColorPrimaryEbu3213 = kLibgav1ColorPrimaryEbu3213;
224 constexpr ColorPrimary kMaxColorPrimaries = kLibgav1MaxColorPrimaries;
225 
226 using TransferCharacteristics = Libgav1TransferCharacteristics;
227 constexpr TransferCharacteristics kTransferCharacteristicsBt709 =
228     kLibgav1TransferCharacteristicsBt709;
229 constexpr TransferCharacteristics kTransferCharacteristicsUnspecified =
230     kLibgav1TransferCharacteristicsUnspecified;
231 constexpr TransferCharacteristics kTransferCharacteristicsBt470M =
232     kLibgav1TransferCharacteristicsBt470M;
233 constexpr TransferCharacteristics kTransferCharacteristicsBt470Bg =
234     kLibgav1TransferCharacteristicsBt470Bg;
235 constexpr TransferCharacteristics kTransferCharacteristicsBt601 =
236     kLibgav1TransferCharacteristicsBt601;
237 constexpr TransferCharacteristics kTransferCharacteristicsSmpte240 =
238     kLibgav1TransferCharacteristicsSmpte240;
239 constexpr TransferCharacteristics kTransferCharacteristicsLinear =
240     kLibgav1TransferCharacteristicsLinear;
241 constexpr TransferCharacteristics kTransferCharacteristicsLog100 =
242     kLibgav1TransferCharacteristicsLog100;
243 constexpr TransferCharacteristics kTransferCharacteristicsLog100Sqrt10 =
244     kLibgav1TransferCharacteristicsLog100Sqrt10;
245 constexpr TransferCharacteristics kTransferCharacteristicsIec61966 =
246     kLibgav1TransferCharacteristicsIec61966;
247 constexpr TransferCharacteristics kTransferCharacteristicsBt1361 =
248     kLibgav1TransferCharacteristicsBt1361;
249 constexpr TransferCharacteristics kTransferCharacteristicsSrgb =
250     kLibgav1TransferCharacteristicsSrgb;
251 constexpr TransferCharacteristics kTransferCharacteristicsBt2020TenBit =
252     kLibgav1TransferCharacteristicsBt2020TenBit;
253 constexpr TransferCharacteristics kTransferCharacteristicsBt2020TwelveBit =
254     kLibgav1TransferCharacteristicsBt2020TwelveBit;
255 constexpr TransferCharacteristics kTransferCharacteristicsSmpte2084 =
256     kLibgav1TransferCharacteristicsSmpte2084;
257 constexpr TransferCharacteristics kTransferCharacteristicsSmpte428 =
258     kLibgav1TransferCharacteristicsSmpte428;
259 constexpr TransferCharacteristics kTransferCharacteristicsHlg =
260     kLibgav1TransferCharacteristicsHlg;
261 constexpr TransferCharacteristics kMaxTransferCharacteristics =
262     kLibgav1MaxTransferCharacteristics;
263 
264 using MatrixCoefficients = Libgav1MatrixCoefficients;
265 constexpr MatrixCoefficients kMatrixCoefficientsIdentity =
266     kLibgav1MatrixCoefficientsIdentity;
267 constexpr MatrixCoefficients kMatrixCoefficientsBt709 =
268     kLibgav1MatrixCoefficientsBt709;
269 constexpr MatrixCoefficients kMatrixCoefficientsUnspecified =
270     kLibgav1MatrixCoefficientsUnspecified;
271 constexpr MatrixCoefficients kMatrixCoefficientsFcc =
272     kLibgav1MatrixCoefficientsFcc;
273 constexpr MatrixCoefficients kMatrixCoefficientsBt470BG =
274     kLibgav1MatrixCoefficientsBt470BG;
275 constexpr MatrixCoefficients kMatrixCoefficientsBt601 =
276     kLibgav1MatrixCoefficientsBt601;
277 constexpr MatrixCoefficients kMatrixCoefficientsSmpte240 =
278     kLibgav1MatrixCoefficientsSmpte240;
279 constexpr MatrixCoefficients kMatrixCoefficientsSmpteYcgco =
280     kLibgav1MatrixCoefficientsSmpteYcgco;
281 constexpr MatrixCoefficients kMatrixCoefficientsBt2020Ncl =
282     kLibgav1MatrixCoefficientsBt2020Ncl;
283 constexpr MatrixCoefficients kMatrixCoefficientsBt2020Cl =
284     kLibgav1MatrixCoefficientsBt2020Cl;
285 constexpr MatrixCoefficients kMatrixCoefficientsSmpte2085 =
286     kLibgav1MatrixCoefficientsSmpte2085;
287 constexpr MatrixCoefficients kMatrixCoefficientsChromatNcl =
288     kLibgav1MatrixCoefficientsChromatNcl;
289 constexpr MatrixCoefficients kMatrixCoefficientsChromatCl =
290     kLibgav1MatrixCoefficientsChromatCl;
291 constexpr MatrixCoefficients kMatrixCoefficientsIctcp =
292     kLibgav1MatrixCoefficientsIctcp;
293 constexpr MatrixCoefficients kMaxMatrixCoefficients =
294     kLibgav1MaxMatrixCoefficients;
295 
296 using ColorRange = Libgav1ColorRange;
297 constexpr ColorRange kColorRangeStudio = kLibgav1ColorRangeStudio;
298 constexpr ColorRange kColorRangeFull = kLibgav1ColorRangeFull;
299 
300 using ObuMetadataHdrCll = Libgav1ObuMetadataHdrCll;
301 using ObuMetadataHdrMdcv = Libgav1ObuMetadataHdrMdcv;
302 using ObuMetadataItutT35 = Libgav1ObuMetadataItutT35;
303 
304 using DecoderBuffer = Libgav1DecoderBuffer;
305 
306 }  // namespace libgav1
307 #endif  // defined(__cplusplus)
308 
309 #endif  // LIBGAV1_SRC_GAV1_DECODER_BUFFER_H_
310