FFmpeg
vvc_parser.c
Go to the documentation of this file.
1 /*
2  * H.266 / VVC parser
3  *
4  * Copyright (C) 2021 Nuo Mi <nuomi2021@gmail.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/mem.h"
24 #include "cbs.h"
25 #include "cbs_h266.h"
26 #include "parser.h"
27 
28 #define START_CODE 0x000001 ///< start_code_prefix_one_3bytes
29 #define IS_IDR(nut) (nut == VVC_IDR_W_RADL || nut == VVC_IDR_N_LP)
30 #define IS_H266_SLICE(nut) (nut <= VVC_RASL_NUT || (nut >= VVC_IDR_W_RADL && nut <= VVC_GDR_NUT))
31 
32 typedef struct PuInfo {
33  const H266RawPPS *pps;
34  const H266RawSPS *sps;
37  int pic_type;
38 } PuInfo;
39 
40 typedef struct AuDetector {
41  uint8_t prev_layer_id;
43  int prev_poc;
44 } AuDetector;
45 
46 typedef struct VVCParserContext {
49 
51 
54 
56 
59 
60 static const enum AVPixelFormat pix_fmts_8bit[] = {
63 };
64 
65 static const enum AVPixelFormat pix_fmts_10bit[] = {
68 };
69 
70 static int get_format(const H266RawSPS *sps)
71 {
72  switch (sps->sps_bitdepth_minus8) {
73  case 0:
74  return pix_fmts_8bit[sps->sps_chroma_format_idc];
75  case 2:
76  return pix_fmts_10bit[sps->sps_chroma_format_idc];
77  }
78  return AV_PIX_FMT_NONE;
79 }
80 
81 /**
82  * Find the end of the current frame in the bitstream.
83  * @return the position of the first byte of the next frame, or END_NOT_FOUND
84  */
85 static int find_frame_end(AVCodecParserContext *s, const uint8_t *buf,
86  int buf_size)
87 {
88  VVCParserContext *ctx = s->priv_data;
89  ParseContext *pc = &ctx->pc;
90  int i;
91 
92  for (i = 0; i < buf_size; i++) {
93  int nut, code_len;
94 
95  pc->state64 = (pc->state64 << 8) | buf[i];
96 
97  if (((pc->state64 >> 3 * 8) & 0xFFFFFF) != START_CODE)
98  continue;
99 
100  code_len = ((pc->state64 >> 3 * 8) & 0xFFFFFFFF) == 0x01 ? 4 : 3;
101 
102  nut = (pc->state64 >> (8 + 3)) & 0x1F;
103  // 7.4.2.4.3 and 7.4.2.4.4
104  if ((nut >= VVC_OPI_NUT && nut <= VVC_PREFIX_APS_NUT &&
105  nut != VVC_PH_NUT) || nut == VVC_AUD_NUT
106  || (nut == VVC_PREFIX_SEI_NUT && !pc->frame_start_found)
107  || nut == VVC_RSV_NVCL_26 || nut == VVC_UNSPEC_28
108  || nut == VVC_UNSPEC_29) {
109  if (pc->frame_start_found) {
110  pc->frame_start_found = 0;
111  return i - (code_len + 2);
112  }
113  } else if (nut == VVC_PH_NUT || IS_H266_SLICE(nut)) {
114  int sh_picture_header_in_slice_header_flag = buf[i] >> 7;
115 
116  if (nut == VVC_PH_NUT || sh_picture_header_in_slice_header_flag) {
117  if (!pc->frame_start_found) {
118  pc->frame_start_found = 1;
119  } else { // First slice of next frame found
120  pc->frame_start_found = 0;
121  return i - (code_len + 2);
122  }
123  }
124  }
125  }
126  return END_NOT_FOUND;
127 }
128 
130 {
131  int has_p = 0;
132  for (int i = 0; i < pu->nb_units; i++) {
133  CodedBitstreamUnit *unit = &pu->units[i];
134  if (IS_H266_SLICE(unit->type)) {
135  const H266RawSlice *slice = unit->content;
136  uint8_t type = slice->header.sh_slice_type;
137  if (type == VVC_SLICE_TYPE_B) {
138  return AV_PICTURE_TYPE_B;
139  }
140  if (type == VVC_SLICE_TYPE_P) {
141  has_p = 1;
142  }
143  }
144  }
145  return has_p ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
146 }
147 
149  const PuInfo *pu)
150 {
151  static const uint8_t h266_sub_width_c[] = {
152  1, 2, 2, 1
153  };
154  static const uint8_t h266_sub_height_c[] = {
155  1, 2, 1, 1
156  };
157  const H266RawSPS *sps = pu->sps;
158  const H266RawPPS *pps = pu->pps;
160 
161  s->pict_type = pu->pic_type;
162  s->format = get_format(sps);
163  s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
164 
165  s->key_frame = nal->nal_unit_type == VVC_IDR_W_RADL ||
166  nal->nal_unit_type == VVC_IDR_N_LP ||
167  nal->nal_unit_type == VVC_CRA_NUT ||
168  nal->nal_unit_type == VVC_GDR_NUT;
169 
170  s->coded_width = pps->pps_pic_width_in_luma_samples;
171  s->coded_height = pps->pps_pic_height_in_luma_samples;
172  s->width = pps->pps_pic_width_in_luma_samples -
173  (pps->pps_conf_win_left_offset + pps->pps_conf_win_right_offset) *
174  h266_sub_width_c[sps->sps_chroma_format_idc];
175  s->height = pps->pps_pic_height_in_luma_samples -
176  (pps->pps_conf_win_top_offset + pps->pps_conf_win_bottom_offset) *
177  h266_sub_height_c[sps->sps_chroma_format_idc];
178 
179  avctx->profile = sps->profile_tier_level.general_profile_idc;
180  avctx->level = sps->profile_tier_level.general_level_idc;
181 
182  avctx->colorspace = (enum AVColorSpace) sps->vui.vui_matrix_coeffs;
183  avctx->color_primaries = (enum AVColorPrimaries) sps->vui.vui_colour_primaries;
184  avctx->color_trc = (enum AVColorTransferCharacteristic) sps->vui.vui_transfer_characteristics;
185  avctx->color_range =
186  sps->vui.vui_full_range_flag ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
187 
188  avctx->has_b_frames = (sps->sps_max_sublayers_minus1 + 1) > 2 ? 2 :
189  sps->sps_max_sublayers_minus1;
190  avctx->max_b_frames = sps->sps_max_sublayers_minus1;
191 
192  if (sps->sps_ptl_dpb_hrd_params_present_flag &&
193  sps->sps_timing_hrd_params_present_flag) {
194  uint32_t num = sps->sps_general_timing_hrd_parameters.num_units_in_tick;
195  uint32_t den = sps->sps_general_timing_hrd_parameters.time_scale;
196 
197  if (num != 0 && den != 0)
198  av_reduce(&avctx->framerate.den, &avctx->framerate.num,
199  num, den, 1 << 30);
200  }
201 }
202 
203 //8.3.1 Decoding process for picture order count.
204 //VTM did not follow the spec, and it's much simpler than spec.
205 //We follow the VTM.
206 static void get_slice_poc(VVCParserContext *s, int *poc,
207  const H266RawSPS *sps,
208  const H266RawPictureHeader *ph,
209  const H266RawSliceHeader *slice, void *log_ctx)
210 {
211  int poc_msb, max_poc_lsb, poc_lsb;
212  AuDetector *d = &s->au_detector;
213  max_poc_lsb = 1 << (sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4);
214  poc_lsb = ph->ph_pic_order_cnt_lsb;
215  if (IS_IDR(slice->nal_unit_header.nal_unit_type)) {
216  if (ph->ph_poc_msb_cycle_present_flag)
217  poc_msb = ph->ph_poc_msb_cycle_val * max_poc_lsb;
218  else
219  poc_msb = 0;
220  } else {
221  int prev_poc = d->prev_tid0_poc;
222  int prev_poc_lsb = prev_poc & (max_poc_lsb - 1);
223  int prev_poc_msb = prev_poc - prev_poc_lsb;
224  if (ph->ph_poc_msb_cycle_present_flag) {
225  poc_msb = ph->ph_poc_msb_cycle_val * max_poc_lsb;
226  } else {
227  if ((poc_lsb < prev_poc_lsb) && ((prev_poc_lsb - poc_lsb) >=
228  (max_poc_lsb / 2)))
229  poc_msb = prev_poc_msb + (unsigned)max_poc_lsb;
230  else if ((poc_lsb > prev_poc_lsb) && ((poc_lsb - prev_poc_lsb) >
231  (max_poc_lsb / 2)))
232  poc_msb = prev_poc_msb - (unsigned)max_poc_lsb;
233  else
234  poc_msb = prev_poc_msb;
235  }
236  }
237 
238  *poc = poc_msb + poc_lsb;
239 }
240 
242 {
243  d->prev_layer_id = UINT8_MAX;
244  d->prev_poc = INT_MAX;
245  d->prev_tid0_poc = INT_MAX;
246 }
247 
248 static int is_au_start(VVCParserContext *s, const PuInfo *pu, void *log_ctx)
249 {
250  //7.4.2.4.3
251  AuDetector *d = &s->au_detector;
252  const H266RawSPS *sps = pu->sps;
254  const H266RawPictureHeader *ph = pu->ph;
255  const H266RawSlice *slice = pu->slice;
256  int ret, poc, nut;
257 
258  get_slice_poc(s, &poc, sps, ph, &slice->header, log_ctx);
259 
260  ret = (nal->nuh_layer_id <= d->prev_layer_id) || (poc != d->prev_poc);
261 
262  nut = nal->nal_unit_type;
263  d->prev_layer_id = nal->nuh_layer_id;
264  d->prev_poc = poc;
265  if (nal->nuh_temporal_id_plus1 == 1 &&
266  !ph->ph_non_ref_pic_flag && nut != VVC_RADL_NUT
267  && nut != VVC_RASL_NUT) {
268  d->prev_tid0_poc = poc;
269  }
270  return ret;
271 }
272 
274  const CodedBitstreamFragment *pu, void *logctx)
275 {
276  const H266RawNALUnitHeader *nal;
277  int ret;
278 
279  memset(info, 0, sizeof(*info));
280  for (int i = 0; i < pu->nb_units; i++) {
281  nal = pu->units[i].content;
282  if (!nal)
283  continue;
284  if ( nal->nal_unit_type == VVC_PH_NUT ) {
285  const H266RawPH *ph = pu->units[i].content;
286  info->ph = &ph->ph_picture_header;
287  } else if (IS_H266_SLICE(nal->nal_unit_type)) {
288  info->slice = pu->units[i].content;
289  if (info->slice->header.sh_picture_header_in_slice_header_flag)
290  info->ph = &info->slice->header.sh_picture_header;
291  if (!info->ph) {
292  av_log(logctx, AV_LOG_ERROR,
293  "can't find picture header in picture unit.\n");
295  goto error;
296  }
297  break;
298  }
299  }
300  if (!info->slice) {
301  av_log(logctx, AV_LOG_ERROR, "can't find slice in picture unit.\n");
303  goto error;
304  }
305  info->pps = h266->pps[info->ph->ph_pic_parameter_set_id];
306  if (!info->pps) {
307  av_log(logctx, AV_LOG_ERROR, "PPS id %d is not avaliable.\n",
308  info->ph->ph_pic_parameter_set_id);
310  goto error;
311  }
312  info->sps = h266->sps[info->pps->pps_seq_parameter_set_id];
313  if (!info->sps) {
314  av_log(logctx, AV_LOG_ERROR, "SPS id %d is not avaliable.\n",
315  info->pps->pps_seq_parameter_set_id);
317  goto error;
318  }
319  info->pic_type = get_pict_type(pu);
320  return 0;
321 error:
322  memset(info, 0, sizeof(*info));
323  return ret;
324 }
325 
326 static int append_au(AVPacket *pkt, const uint8_t *buf, int buf_size)
327 {
328  int offset = pkt->size;
329  int ret;
330  if ((ret = av_grow_packet(pkt, buf_size)) < 0)
331  goto end;
332  memcpy(pkt->data + offset, buf, buf_size);
333 end:
334  return ret;
335 }
336 
337 /**
338  * Parse NAL units of found picture and decode some basic information.
339  *
340  * @param s parser context.
341  * @param avctx codec context.
342  * @param buf buffer with field/frame data.
343  * @param buf_size size of the buffer.
344  * @return < 0 for error, == 0 for a complete au, > 0 is not a completed au.
345  */
346 static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
347  int buf_size, AVCodecContext *avctx)
348 {
349  VVCParserContext *ctx = s->priv_data;
350  const CodedBitstreamH266Context *h266 = ctx->cbc->priv_data;
351 
352  CodedBitstreamFragment *pu = &ctx->picture_unit;
353  int ret;
354  PuInfo info;
355 
356  if (!buf_size) {
357  if (ctx->au.size) {
358  av_packet_move_ref(&ctx->last_au, &ctx->au);
359  return 0;
360  }
361  return 1;
362  }
363 
364  if ((ret = ff_cbs_read(ctx->cbc, pu, buf, buf_size)) < 0) {
365  av_log(avctx, AV_LOG_ERROR, "Failed to parse picture unit.\n");
366  goto end;
367  }
368  if ((ret = get_pu_info(&info, h266, pu, avctx)) < 0)
369  goto end;
370  if (append_au(&ctx->au, buf, buf_size) < 0) {
371  ret = AVERROR(ENOMEM);
372  goto end;
373  }
374  if (is_au_start(ctx, &info, avctx)) {
375  set_parser_ctx(s, avctx, &info);
376  av_packet_move_ref(&ctx->last_au, &ctx->au);
377  } else {
378  ret = 1; //not a completed au
379  }
380 end:
382  return ret;
383 }
384 
385 /**
386  * Combine PU to AU
387  *
388  * @param s parser context.
389  * @param avctx codec context.
390  * @param buf buffer to a PU.
391  * @param buf_size size of the buffer.
392  * @return < 0 for error, == 0 a complete au, > 0 not a completed au.
393  */
395  const uint8_t **buf, int *buf_size)
396 {
397  VVCParserContext *ctx = s->priv_data;
398  int ret;
399 
400  ctx->cbc->log_ctx = avctx;
401 
402  av_packet_unref(&ctx->last_au);
403  ret = parse_nal_units(s, *buf, *buf_size, avctx);
404  if (ret == 0) {
405  if (ctx->last_au.size) {
406  *buf = ctx->last_au.data;
407  *buf_size = ctx->last_au.size;
408  } else {
409  ret = 1; //no output
410  }
411  }
412  ctx->cbc->log_ctx = NULL;
413  return ret;
414 }
415 
417  const uint8_t **poutbuf, int *poutbuf_size,
418  const uint8_t *buf, int buf_size)
419 {
420  int next, ret;
421  VVCParserContext *ctx = s->priv_data;
422  ParseContext *pc = &ctx->pc;
423  CodedBitstreamFragment *pu = &ctx->picture_unit;
424 
425  int is_dummy_buf = !buf_size;
426  int flush = !buf_size;
427  const uint8_t *dummy_buf = buf;
428 
429  *poutbuf = NULL;
430  *poutbuf_size = 0;
431 
432  if (avctx->extradata_size && !ctx->parsed_extradata) {
433  ctx->parsed_extradata = 1;
434 
435  ret = ff_cbs_read_extradata_from_codec(ctx->cbc, pu, avctx);
436  if (ret < 0)
437  av_log(avctx, AV_LOG_WARNING, "Failed to parse extradata.\n");
438 
440  }
441 
442  if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
443  next = buf_size;
444  } else {
445  next = find_frame_end(s, buf, buf_size);
446  if (ff_combine_frame(pc, next, &buf, &buf_size) < 0)
447  return buf_size;
448  }
449 
450  is_dummy_buf &= (dummy_buf == buf);
451 
452  if (!is_dummy_buf) {
453  ret = combine_au(s, avctx, &buf, &buf_size);
454  if (ret > 0 && flush) {
455  buf_size = 0;
456  ret = combine_au(s, avctx, &buf, &buf_size);
457  }
458  if (ret != 0)
459  return next;
460  }
461 
462  *poutbuf = buf;
463  *poutbuf_size = buf_size;
464 
465  return next;
466 }
467 
470  VVC_STSA_NUT,
471  VVC_RADL_NUT,
472  VVC_RASL_NUT,
474  VVC_IDR_N_LP,
475  VVC_CRA_NUT,
476  VVC_GDR_NUT,
477  VVC_VPS_NUT,
478  VVC_SPS_NUT,
479  VVC_PPS_NUT,
480  VVC_PH_NUT,
481  VVC_AUD_NUT,
482 };
483 
485 {
486  VVCParserContext *ctx = s->priv_data;
487  int ret;
488 
490  if (ret < 0)
491  return ret;
492  au_detector_init(&ctx->au_detector);
493 
494  ctx->cbc->decompose_unit_types = decompose_unit_types;
495  ctx->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
496 
497  return ret;
498 }
499 
501 {
502  VVCParserContext *ctx = s->priv_data;
503 
504  av_packet_unref(&ctx->au);
505  av_packet_unref(&ctx->last_au);
506  ff_cbs_fragment_free(&ctx->picture_unit);
507 
508  ff_cbs_close(&ctx->cbc);
509  av_freep(&ctx->pc.buffer);
510 }
511 
513  .codec_ids = { AV_CODEC_ID_VVC },
514  .priv_data_size = sizeof(VVCParserContext),
515  .parser_init = vvc_parser_init,
516  .parser_close = vvc_parser_close,
517  .parser_parse = vvc_parser_parse,
518 };
VVC_RADL_NUT
@ VVC_RADL_NUT
Definition: vvc.h:31
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
au_detector_init
static void au_detector_init(AuDetector *d)
Definition: vvc_parser.c:241
VVC_RASL_NUT
@ VVC_RASL_NUT
Definition: vvc.h:32
VVC_GDR_NUT
@ VVC_GDR_NUT
Definition: vvc.h:39
VVC_STSA_NUT
@ VVC_STSA_NUT
Definition: vvc.h:30
START_CODE
#define START_CODE
start_code_prefix_one_3bytes
Definition: vvc_parser.c:28
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:427
PuInfo::ph
const H266RawPictureHeader * ph
Definition: vvc_parser.c:35
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
cbs_h266.h
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:580
ff_cbs_fragment_free
av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:186
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:107
av_grow_packet
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: packet.c:121
VVCParserContext::pc
ParseContext pc
Definition: vvc_parser.c:47
ph
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Definition: cbs_h266_syntax_template.c:3003
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:678
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:686
ff_cbs_fragment_reset
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Definition: cbs.c:172
AVPacket::data
uint8_t * data
Definition: packet.h:524
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
decompose_unit_types
static const CodedBitstreamUnitType decompose_unit_types[]
Definition: vvc_parser.c:468
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
IS_IDR
#define IS_IDR(nut)
Definition: vvc_parser.c:29
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:74
cbs.h
H266RawNALUnitHeader::nuh_layer_id
uint8_t nuh_layer_id
Definition: cbs_h266.h:30
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:555
H266RawNALUnitHeader::nal_unit_type
uint8_t nal_unit_type
Definition: cbs_h266.h:31
PuInfo::sps
const H266RawSPS * sps
Definition: vvc_parser.c:34
VVC_AUD_NUT
@ VVC_AUD_NUT
Definition: vvc.h:49
vvc_parser_parse
static int vvc_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: vvc_parser.c:416
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:70
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:142
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:560
CodedBitstreamH266Context::pps
H266RawPPS * pps[VVC_MAX_PPS_COUNT]
RefStruct references.
Definition: cbs_h266.h:874
ParseContext
Definition: parser.h:28
ff_cbs_read
int ff_cbs_read(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Read a bitstream from a memory region into a fragment, then split into units and decompose.
Definition: cbs.c:325
VVC_RSV_NVCL_26
@ VVC_RSV_NVCL_26
Definition: vvc.h:55
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
VVCParserContext::au
AVPacket au
Definition: vvc_parser.c:52
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
AVRational::num
int num
Numerator.
Definition: rational.h:59
VVC_IDR_W_RADL
@ VVC_IDR_W_RADL
Definition: vvc.h:36
VVCParserContext::au_detector
AuDetector au_detector
Definition: vvc_parser.c:55
VVCParserContext::picture_unit
CodedBitstreamFragment picture_unit
Definition: vvc_parser.c:50
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:481
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:168
AV_PICTURE_STRUCTURE_FRAME
@ AV_PICTURE_STRUCTURE_FRAME
coded as frame
Definition: avcodec.h:2704
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:671
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:524
AuDetector::prev_tid0_poc
int prev_tid0_poc
Definition: vvc_parser.c:42
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:723
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
PuInfo
Definition: vvc_parser.c:32
s
#define s(width, name)
Definition: cbs_vp9.c:198
info
MIPS optimizations info
Definition: mips.txt:2
H266RawNALUnitHeader::nuh_temporal_id_plus1
uint8_t nuh_temporal_id_plus1
Definition: cbs_h266.h:32
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
VVC_UNSPEC_29
@ VVC_UNSPEC_29
Definition: vvc.h:58
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:459
H266RawSPS
Definition: cbs_h266.h:308
VVC_SLICE_TYPE_P
@ VVC_SLICE_TYPE_P
Definition: vvc.h:65
is_au_start
static int is_au_start(VVCParserContext *s, const PuInfo *pu, void *log_ctx)
Definition: vvc_parser.c:248
H266RawPPS
Definition: cbs_h266.h:496
NULL
#define NULL
Definition: coverity.c:32
H266RawPictureHeader
Definition: cbs_h266.h:674
PuInfo::pic_type
int pic_type
Definition: vvc_parser.c:37
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
VVC_PREFIX_SEI_NUT
@ VVC_PREFIX_SEI_NUT
Definition: vvc.h:52
VVC_SLICE_TYPE_B
@ VVC_SLICE_TYPE_B
Definition: vvc.h:64
VVCParserContext
Definition: vvc_parser.c:46
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
ff_vvc_parser
const AVCodecParser ff_vvc_parser
Definition: vvc_parser.c:512
ParseContext::frame_start_found
int frame_start_found
Definition: parser.h:34
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
VVC_PH_NUT
@ VVC_PH_NUT
Definition: vvc.h:48
AuDetector::prev_layer_id
uint8_t prev_layer_id
Definition: vvc_parser.c:41
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: packet.c:484
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1783
get_slice_poc
static void get_slice_poc(VVCParserContext *s, int *poc, const H266RawSPS *sps, const H266RawPictureHeader *ph, const H266RawSliceHeader *slice, void *log_ctx)
Definition: vvc_parser.c:206
parse_nal_units
static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, int buf_size, AVCodecContext *avctx)
Parse NAL units of found picture and decode some basic information.
Definition: vvc_parser.c:346
pix_fmts_10bit
static enum AVPixelFormat pix_fmts_10bit[]
Definition: vvc_parser.c:65
AVPacket::size
int size
Definition: packet.h:525
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
AVCodecParser::codec_ids
int codec_ids[7]
Definition: avcodec.h:2867
VVC_VPS_NUT
@ VVC_VPS_NUT
Definition: vvc.h:43
VVCParserContext::parsed_extradata
int parsed_extradata
Definition: vvc_parser.c:57
pix_fmts_8bit
static enum AVPixelFormat pix_fmts_8bit[]
Definition: vvc_parser.c:60
VVCParserContext::last_au
AVPacket last_au
Definition: vvc_parser.c:53
AuDetector::prev_poc
int prev_poc
Definition: vvc_parser.c:43
combine_au
static int combine_au(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **buf, int *buf_size)
Combine PU to AU.
Definition: vvc_parser.c:394
CodedBitstreamH266Context
Definition: cbs_h266.h:866
AV_CODEC_ID_VVC
@ AV_CODEC_ID_VVC
Definition: codec_id.h:250
VVC_TRAIL_NUT
@ VVC_TRAIL_NUT
Definition: vvc.h:29
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
VVC_SPS_NUT
@ VVC_SPS_NUT
Definition: vvc.h:44
ff_cbs_read_extradata_from_codec
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Definition: cbs.c:295
ff_combine_frame
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
Definition: parser.c:203
VVCParserContext::cbc
CodedBitstreamContext * cbc
Definition: vvc_parser.c:48
H266RawSliceHeader
Definition: cbs_h266.h:769
PuInfo::slice
const H266RawSlice * slice
Definition: vvc_parser.c:36
PARSER_FLAG_COMPLETE_FRAMES
#define PARSER_FLAG_COMPLETE_FRAMES
Definition: avcodec.h:2741
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
VVC_UNSPEC_28
@ VVC_UNSPEC_28
Definition: vvc.h:57
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:609
CodedBitstreamH266Context::sps
H266RawSPS * sps[VVC_MAX_SPS_COUNT]
RefStruct references.
Definition: cbs_h266.h:873
VVC_IDR_N_LP
@ VVC_IDR_N_LP
Definition: vvc.h:37
parser.h
PuInfo::pps
const H266RawPPS * pps
Definition: vvc_parser.c:33
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:669
IS_H266_SLICE
#define IS_H266_SLICE(nut)
Definition: vvc_parser.c:30
vvc_parser_init
static av_cold int vvc_parser_init(AVCodecParserContext *s)
Definition: vvc_parser.c:484
get_pict_type
static int get_pict_type(const CodedBitstreamFragment *pu)
Definition: vvc_parser.c:129
AVCodecParserContext
Definition: avcodec.h:2707
append_au
static int append_au(AVPacket *pkt, const uint8_t *buf, int buf_size)
Definition: vvc_parser.c:326
ret
ret
Definition: filter_design.txt:187
H266RawSliceHeader::sh_slice_type
uint8_t sh_slice_type
Definition: cbs_h266.h:778
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
H266RawSlice::header
H266RawSliceHeader header
Definition: cbs_h266.h:842
VVC_PPS_NUT
@ VVC_PPS_NUT
Definition: vvc.h:45
H266RawSliceHeader::nal_unit_header
H266RawNALUnitHeader nal_unit_header
Definition: cbs_h266.h:770
AVCodecContext
main external API structure.
Definition: avcodec.h:445
VVC_PREFIX_APS_NUT
@ VVC_PREFIX_APS_NUT
Definition: vvc.h:46
H266RawPH
Definition: cbs_h266.h:764
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:281
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:47
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1639
vvc_parser_close
static av_cold void vvc_parser_close(AVCodecParserContext *s)
Definition: vvc_parser.c:500
set_parser_ctx
static void set_parser_ctx(AVCodecParserContext *s, AVCodecContext *avctx, const PuInfo *pu)
Definition: vvc_parser.c:148
ParseContext::state64
uint64_t state64
contains the last 8 bytes in MSB order
Definition: parser.h:37
VVC_CRA_NUT
@ VVC_CRA_NUT
Definition: vvc.h:38
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
VVC_OPI_NUT
@ VVC_OPI_NUT
Definition: vvc.h:41
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
AVCodecContext::max_b_frames
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition: avcodec.h:795
ff_cbs_init
av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:90
END_NOT_FOUND
#define END_NOT_FOUND
Definition: parser.h:40
AVPacket
This structure stores compressed data.
Definition: packet.h:501
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AuDetector
Definition: vvc_parser.c:40
AVCodecParser
Definition: avcodec.h:2866
d
d
Definition: ffmpeg_filter.c:424
get_format
static int get_format(const H266RawSPS *sps)
Definition: vvc_parser.c:70
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
H266RawNALUnitHeader
Definition: cbs_h266.h:29
find_frame_end
static int find_frame_end(AVCodecParserContext *s, const uint8_t *buf, int buf_size)
Find the end of the current frame in the bitstream.
Definition: vvc_parser.c:85
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1283
get_pu_info
static int get_pu_info(PuInfo *info, const CodedBitstreamH266Context *h266, const CodedBitstreamFragment *pu, void *logctx)
Definition: vvc_parser.c:273
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:153
H266RawSlice
Definition: cbs_h266.h:841