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