1 /*
2 * EVC helper functions for muxers
3 * Copyright (c) 2022 Dawid Kozinski <d.kozinski@samsung.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
28
29 // @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.1
30 enum {
36 };
37
38 // @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.3
40 uint8_t
array_completeness;
// when equal to 1 indicates that all NAL units of the given type are in the following array
41 uint8_t
NAL_unit_type;
// indicates the type of the NAL units in the following array
42 uint16_t
numNalus;
// indicates the number of NAL units of the indicated type
43 uint16_t *
nalUnitLength;
// indicates the length in bytes of the NAL unit
44 uint8_t **
nalUnit;
// contains an SPS, PPS, APS or a SEI NAL unit, as specified in ISO/IEC 23094-1
46
47 /**
48 * @brief Specifies the decoder configuration information for ISO/IEC 23094-1 video content.
49 * @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.2
50 * Carriage of network abstraction layer (NAL) unit structured video in the ISO base media file format
51 */
67
72
78
79 // @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
81 {
83 unsigned sps_seq_parameter_set_id;
85
88
92
94
97
98 // the Baseline profile is indicated by profile_idc eqal to 0
99 // the Main profile is indicated by profile_idc eqal to 1
101
103
106
107 // 0 - monochrome
108 // 1 - 4:2:0
109 // 2 - 4:2:2
110 // 3 - 4:4:4
114
117
120 // EVCDecoderConfigurationRecord can't store values > 7. Limit it to bit depth 14.
123
124 return 0;
125 }
126
127 // @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.3
129 uint8_t nal_type, int ps_array_completeness,
131 {
133 uint16_t numNalus =
array->numNalus;
134
138
142
143 array->nalUnit [numNalus] = (uint8_t *)nal_buf;
144 array->nalUnitLength[numNalus] = nal_size;
145 array->NAL_unit_type = nal_type;
147
148 /*
149 * When the sample entry name is 'evc1', the default and mandatory value of
150 * array_completeness is 1 for arrays of all types of parameter sets, and 0
151 * for all other arrays.
152 */
154 array->array_completeness = ps_array_completeness;
155
156 return 0;
157 }
158
160 {
164 }
165
167 {
173 }
174 }
175
177 {
178 uint16_t sps_count;
179
206
207 if(
array->numNalus == 0)
208 continue;
209
211 i,
array->array_completeness);
216 for (
unsigned j = 0; j <
array->numNalus; j++)
218 "nalUnitLength[%u][%u]: %"PRIu16"\n",
219 i, j,
array->nalUnitLength[j]);
220 }
221
222 /*
223 * We need at least one SPS.
224 */
228
229 /* unsigned int(8) configurationVersion = 1; */
231
232 /* unsigned int(8) profile_idc */
234
235 /* unsigned int(8) level_idc */
237
238 /* unsigned int(32) toolset_idc_h */
240
241 /* unsigned int(32) toolset_idc_l */
243
244 /*
245 * unsigned int(2) chroma_format_idc;
246 * unsigned int(3) bit_depth_luma_minus8;
247 * unsigned int(3) bit_depth_chroma_minus8;
248 */
252
253 /* unsigned int(16) pic_width_in_luma_samples; */
255
256 /* unsigned int(16) pic_height_in_luma_samples; */
258
259 /*
260 * unsigned int(6) reserved = '000000'b;
261 * unsigned int(2) lengthSizeMinusOne;
262 */
264
265 /* unsigned int(8) numOfArrays; */
267
270
271 if (!
array->numNalus)
272 continue;
273
274 /*
275 * bit(1) array_completeness;
276 * unsigned int(1) reserved = 0;
277 * unsigned int(6) NAL_unit_type;
278 */
280 array->NAL_unit_type & 0x3f);
281
282 /* unsigned int(16) numNalus; */
284
285 for (
unsigned j = 0; j <
array->numNalus; j++) {
286 /* unsigned int(16) nalUnitLength; */
288
289 /* bit(8*nalUnitLength) nalUnit; */
291 array->nalUnitLength[j]);
292 }
293 }
294
295 return 0;
296 }
297
299 int size,
int ps_array_completeness)
300 {
302 int nalu_type;
303 size_t nalu_size;
304 int bytes_to_read =
size;
305 unsigned array_index;
306
308
310 /* We can't write a valid evcC from the provided data */
312 }
else if (*
data == 1) {
313 /* Data is already evcC-formatted */
315 return 0;
316 }
317
319
322 if (nalu_size == 0) break;
323
326
327 if (bytes_to_read < nalu_size) break;
328
332 goto end;
333 }
334
335 // @see ISO/IEC 14496-15:2021 Coding of audio-visual objects - Part 15: section 12.3.3.3
336 // NAL_unit_type indicates the type of the NAL units in the following array (which shall be all of that type);
337 // - it takes a value as defined in ISO/IEC 23094-1;
338 // - it is restricted to take one of the values indicating a SPS, PPS, APS, or SEI NAL unit.
339 switch (nalu_type) {
342 break;
345 break;
348 break;
351 break;
352 default:
353 array_index = -1;
354 break;
355 }
356
361
363
365 goto end;
368
372 goto end;
373 }
374 }
375
377 bytes_to_read -= nalu_size;
378 }
379
381
382 end:
385 }