• 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 Libgav1DecoderBuffer {
119 #if defined(__cplusplus)
NumPlanesLibgav1DecoderBuffer120   LIBGAV1_PUBLIC int NumPlanes() const {
121     return (image_format == kLibgav1ImageFormatMonochrome400) ? 1 : 3;
122   }
123 #endif  // defined(__cplusplus)
124 
125   Libgav1ChromaSamplePosition chroma_sample_position;
126   Libgav1ImageFormat image_format;
127   Libgav1ColorRange color_range;
128   Libgav1ColorPrimary color_primary;
129   Libgav1TransferCharacteristics transfer_characteristics;
130   Libgav1MatrixCoefficients matrix_coefficients;
131 
132   // Image storage dimensions.
133   // NOTE: These fields are named w and h in vpx_image_t and aom_image_t.
134   // uint32_t width;  // Stored image width.
135   // uint32_t height;  // Stored image height.
136   int bitdepth;  // Stored image bitdepth.
137 
138   // Image display dimensions.
139   // NOTES:
140   // 1. These fields are named d_w and d_h in vpx_image_t and aom_image_t.
141   // 2. libvpx and libaom clients use d_w and d_h much more often than w and h.
142   // 3. These fields can just be stored for the Y plane and the clients can
143   //    calculate the values for the U and V planes if the image format or
144   //    subsampling is exposed.
145   int displayed_width[3];   // Displayed image width.
146   int displayed_height[3];  // Displayed image height.
147 
148   int stride[3];
149   uint8_t* plane[3];
150 
151   // Spatial id of this frame.
152   int spatial_id;
153   // Temporal id of this frame.
154   int temporal_id;
155 
156   // The |user_private_data| argument passed to Decoder::EnqueueFrame().
157   int64_t user_private_data;
158   // The |private_data| field of FrameBuffer. Set by the get frame buffer
159   // callback when it allocates a frame buffer.
160   void* buffer_private_data;
161 } Libgav1DecoderBuffer;
162 
163 #if defined(__cplusplus)
164 namespace libgav1 {
165 
166 using ChromaSamplePosition = Libgav1ChromaSamplePosition;
167 constexpr ChromaSamplePosition kChromaSamplePositionUnknown =
168     kLibgav1ChromaSamplePositionUnknown;
169 constexpr ChromaSamplePosition kChromaSamplePositionVertical =
170     kLibgav1ChromaSamplePositionVertical;
171 constexpr ChromaSamplePosition kChromaSamplePositionColocated =
172     kLibgav1ChromaSamplePositionColocated;
173 constexpr ChromaSamplePosition kChromaSamplePositionReserved =
174     kLibgav1ChromaSamplePositionReserved;
175 
176 using ImageFormat = Libgav1ImageFormat;
177 constexpr ImageFormat kImageFormatYuv420 = kLibgav1ImageFormatYuv420;
178 constexpr ImageFormat kImageFormatYuv422 = kLibgav1ImageFormatYuv422;
179 constexpr ImageFormat kImageFormatYuv444 = kLibgav1ImageFormatYuv444;
180 constexpr ImageFormat kImageFormatMonochrome400 =
181     kLibgav1ImageFormatMonochrome400;
182 
183 using ColorPrimary = Libgav1ColorPrimary;
184 constexpr ColorPrimary kColorPrimaryBt709 = kLibgav1ColorPrimaryBt709;
185 constexpr ColorPrimary kColorPrimaryUnspecified =
186     kLibgav1ColorPrimaryUnspecified;
187 constexpr ColorPrimary kColorPrimaryBt470M = kLibgav1ColorPrimaryBt470M;
188 constexpr ColorPrimary kColorPrimaryBt470Bg = kLibgav1ColorPrimaryBt470Bg;
189 constexpr ColorPrimary kColorPrimaryBt601 = kLibgav1ColorPrimaryBt601;
190 constexpr ColorPrimary kColorPrimarySmpte240 = kLibgav1ColorPrimarySmpte240;
191 constexpr ColorPrimary kColorPrimaryGenericFilm =
192     kLibgav1ColorPrimaryGenericFilm;
193 constexpr ColorPrimary kColorPrimaryBt2020 = kLibgav1ColorPrimaryBt2020;
194 constexpr ColorPrimary kColorPrimaryXyz = kLibgav1ColorPrimaryXyz;
195 constexpr ColorPrimary kColorPrimarySmpte431 = kLibgav1ColorPrimarySmpte431;
196 constexpr ColorPrimary kColorPrimarySmpte432 = kLibgav1ColorPrimarySmpte432;
197 constexpr ColorPrimary kColorPrimaryEbu3213 = kLibgav1ColorPrimaryEbu3213;
198 constexpr ColorPrimary kMaxColorPrimaries = kLibgav1MaxColorPrimaries;
199 
200 using TransferCharacteristics = Libgav1TransferCharacteristics;
201 constexpr TransferCharacteristics kTransferCharacteristicsBt709 =
202     kLibgav1TransferCharacteristicsBt709;
203 constexpr TransferCharacteristics kTransferCharacteristicsUnspecified =
204     kLibgav1TransferCharacteristicsUnspecified;
205 constexpr TransferCharacteristics kTransferCharacteristicsBt470M =
206     kLibgav1TransferCharacteristicsBt470M;
207 constexpr TransferCharacteristics kTransferCharacteristicsBt470Bg =
208     kLibgav1TransferCharacteristicsBt470Bg;
209 constexpr TransferCharacteristics kTransferCharacteristicsBt601 =
210     kLibgav1TransferCharacteristicsBt601;
211 constexpr TransferCharacteristics kTransferCharacteristicsSmpte240 =
212     kLibgav1TransferCharacteristicsSmpte240;
213 constexpr TransferCharacteristics kTransferCharacteristicsLinear =
214     kLibgav1TransferCharacteristicsLinear;
215 constexpr TransferCharacteristics kTransferCharacteristicsLog100 =
216     kLibgav1TransferCharacteristicsLog100;
217 constexpr TransferCharacteristics kTransferCharacteristicsLog100Sqrt10 =
218     kLibgav1TransferCharacteristicsLog100Sqrt10;
219 constexpr TransferCharacteristics kTransferCharacteristicsIec61966 =
220     kLibgav1TransferCharacteristicsIec61966;
221 constexpr TransferCharacteristics kTransferCharacteristicsBt1361 =
222     kLibgav1TransferCharacteristicsBt1361;
223 constexpr TransferCharacteristics kTransferCharacteristicsSrgb =
224     kLibgav1TransferCharacteristicsSrgb;
225 constexpr TransferCharacteristics kTransferCharacteristicsBt2020TenBit =
226     kLibgav1TransferCharacteristicsBt2020TenBit;
227 constexpr TransferCharacteristics kTransferCharacteristicsBt2020TwelveBit =
228     kLibgav1TransferCharacteristicsBt2020TwelveBit;
229 constexpr TransferCharacteristics kTransferCharacteristicsSmpte2084 =
230     kLibgav1TransferCharacteristicsSmpte2084;
231 constexpr TransferCharacteristics kTransferCharacteristicsSmpte428 =
232     kLibgav1TransferCharacteristicsSmpte428;
233 constexpr TransferCharacteristics kTransferCharacteristicsHlg =
234     kLibgav1TransferCharacteristicsHlg;
235 constexpr TransferCharacteristics kMaxTransferCharacteristics =
236     kLibgav1MaxTransferCharacteristics;
237 
238 using MatrixCoefficients = Libgav1MatrixCoefficients;
239 constexpr MatrixCoefficients kMatrixCoefficientsIdentity =
240     kLibgav1MatrixCoefficientsIdentity;
241 constexpr MatrixCoefficients kMatrixCoefficientsBt709 =
242     kLibgav1MatrixCoefficientsBt709;
243 constexpr MatrixCoefficients kMatrixCoefficientsUnspecified =
244     kLibgav1MatrixCoefficientsUnspecified;
245 constexpr MatrixCoefficients kMatrixCoefficientsFcc =
246     kLibgav1MatrixCoefficientsFcc;
247 constexpr MatrixCoefficients kMatrixCoefficientsBt470BG =
248     kLibgav1MatrixCoefficientsBt470BG;
249 constexpr MatrixCoefficients kMatrixCoefficientsBt601 =
250     kLibgav1MatrixCoefficientsBt601;
251 constexpr MatrixCoefficients kMatrixCoefficientsSmpte240 =
252     kLibgav1MatrixCoefficientsSmpte240;
253 constexpr MatrixCoefficients kMatrixCoefficientsSmpteYcgco =
254     kLibgav1MatrixCoefficientsSmpteYcgco;
255 constexpr MatrixCoefficients kMatrixCoefficientsBt2020Ncl =
256     kLibgav1MatrixCoefficientsBt2020Ncl;
257 constexpr MatrixCoefficients kMatrixCoefficientsBt2020Cl =
258     kLibgav1MatrixCoefficientsBt2020Cl;
259 constexpr MatrixCoefficients kMatrixCoefficientsSmpte2085 =
260     kLibgav1MatrixCoefficientsSmpte2085;
261 constexpr MatrixCoefficients kMatrixCoefficientsChromatNcl =
262     kLibgav1MatrixCoefficientsChromatNcl;
263 constexpr MatrixCoefficients kMatrixCoefficientsChromatCl =
264     kLibgav1MatrixCoefficientsChromatCl;
265 constexpr MatrixCoefficients kMatrixCoefficientsIctcp =
266     kLibgav1MatrixCoefficientsIctcp;
267 constexpr MatrixCoefficients kMaxMatrixCoefficients =
268     kLibgav1MaxMatrixCoefficients;
269 
270 using ColorRange = Libgav1ColorRange;
271 constexpr ColorRange kColorRangeStudio = kLibgav1ColorRangeStudio;
272 constexpr ColorRange kColorRangeFull = kLibgav1ColorRangeFull;
273 
274 using DecoderBuffer = Libgav1DecoderBuffer;
275 
276 }  // namespace libgav1
277 #endif  // defined(__cplusplus)
278 
279 #endif  // LIBGAV1_SRC_GAV1_DECODER_BUFFER_H_
280