FFmpeg
cbs_av1_syntax_template.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
20  AV1RawOBUHeader *current)
21 {
22  int err;
23 
24  HEADER("OBU header");
25 
26  fc(1, obu_forbidden_bit, 0, 0);
27 
28  fc(4, obu_type, 0, AV1_OBU_PADDING);
29  flag(obu_extension_flag);
30  flag(obu_has_size_field);
31 
32  fc(1, obu_reserved_1bit, 0, 0);
33 
34  if (current->obu_extension_flag) {
35  fb(3, temporal_id);
36  fb(2, spatial_id);
37  fc(3, extension_header_reserved_3bits, 0, 0);
38  }
39 
40  return 0;
41 }
42 
43 static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw, int nb_bits)
44 {
45  int err;
46 
47  av_assert0(nb_bits > 0);
48 
49  fixed(1, trailing_one_bit, 1);
50  --nb_bits;
51 
52  while (nb_bits > 0) {
53  fixed(1, trailing_zero_bit, 0);
54  --nb_bits;
55  }
56 
57  return 0;
58 }
59 
61 {
62  int err;
63 
64  while (byte_alignment(rw) != 0)
65  fixed(1, zero_bit, 0);
66 
67  return 0;
68 }
69 
71  AV1RawColorConfig *current, int seq_profile)
72 {
74  int err;
75 
76  flag(high_bitdepth);
77 
78  if (seq_profile == FF_PROFILE_AV1_PROFESSIONAL &&
79  current->high_bitdepth) {
80  flag(twelve_bit);
81  priv->bit_depth = current->twelve_bit ? 12 : 10;
82  } else {
83  priv->bit_depth = current->high_bitdepth ? 10 : 8;
84  }
85 
86  if (seq_profile == FF_PROFILE_AV1_HIGH)
87  infer(mono_chrome, 0);
88  else
89  flag(mono_chrome);
90  priv->num_planes = current->mono_chrome ? 1 : 3;
91 
92  flag(color_description_present_flag);
93  if (current->color_description_present_flag) {
94  fb(8, color_primaries);
96  fb(8, matrix_coefficients);
97  } else {
100  infer(matrix_coefficients, AVCOL_SPC_UNSPECIFIED);
101  }
102 
103  if (current->mono_chrome) {
104  flag(color_range);
105 
106  infer(subsampling_x, 1);
107  infer(subsampling_y, 1);
108  infer(chroma_sample_position, AV1_CSP_UNKNOWN);
109  infer(separate_uv_delta_q, 0);
110 
111  } else if (current->color_primaries == AVCOL_PRI_BT709 &&
112  current->transfer_characteristics == AVCOL_TRC_IEC61966_2_1 &&
113  current->matrix_coefficients == AVCOL_SPC_RGB) {
114  infer(color_range, 1);
115  infer(subsampling_x, 0);
116  infer(subsampling_y, 0);
117  flag(separate_uv_delta_q);
118 
119  } else {
120  flag(color_range);
121 
122  if (seq_profile == FF_PROFILE_AV1_MAIN) {
123  infer(subsampling_x, 1);
124  infer(subsampling_y, 1);
125  } else if (seq_profile == FF_PROFILE_AV1_HIGH) {
126  infer(subsampling_x, 0);
127  infer(subsampling_y, 0);
128  } else {
129  if (priv->bit_depth == 12) {
130  fb(1, subsampling_x);
131  if (current->subsampling_x)
132  fb(1, subsampling_y);
133  else
134  infer(subsampling_y, 0);
135  } else {
136  infer(subsampling_x, 1);
137  infer(subsampling_y, 0);
138  }
139  }
140  if (current->subsampling_x && current->subsampling_y) {
141  fc(2, chroma_sample_position, AV1_CSP_UNKNOWN,
143  }
144 
145  flag(separate_uv_delta_q);
146  }
147 
148  return 0;
149 }
150 
152  AV1RawTimingInfo *current)
153 {
154  int err;
155 
156  fc(32, num_units_in_display_tick, 1, MAX_UINT_BITS(32));
157  fc(32, time_scale, 1, MAX_UINT_BITS(32));
158 
159  flag(equal_picture_interval);
160  if (current->equal_picture_interval)
161  uvlc(num_ticks_per_picture_minus_1, 0, MAX_UINT_BITS(32) - 1);
162 
163  return 0;
164 }
165 
167  AV1RawDecoderModelInfo *current)
168 {
169  int err;
170 
171  fb(5, buffer_delay_length_minus_1);
172  fb(32, num_units_in_decoding_tick);
173  fb(5, buffer_removal_time_length_minus_1);
174  fb(5, frame_presentation_time_length_minus_1);
175 
176  return 0;
177 }
178 
180  AV1RawSequenceHeader *current)
181 {
182  int i, err;
183 
184  HEADER("Sequence Header");
185 
186  fc(3, seq_profile, FF_PROFILE_AV1_MAIN,
188  flag(still_picture);
189  flag(reduced_still_picture_header);
190 
191  if (current->reduced_still_picture_header) {
192  infer(timing_info_present_flag, 0);
193  infer(decoder_model_info_present_flag, 0);
194  infer(initial_display_delay_present_flag, 0);
195  infer(operating_points_cnt_minus_1, 0);
196  infer(operating_point_idc[0], 0);
197 
198  fb(5, seq_level_idx[0]);
199 
200  infer(seq_tier[0], 0);
201  infer(decoder_model_present_for_this_op[0], 0);
202  infer(initial_display_delay_present_for_this_op[0], 0);
203 
204  } else {
205  flag(timing_info_present_flag);
206  if (current->timing_info_present_flag) {
207  CHECK(FUNC(timing_info)(ctx, rw, &current->timing_info));
208 
209  flag(decoder_model_info_present_flag);
210  if (current->decoder_model_info_present_flag) {
212  (ctx, rw, &current->decoder_model_info));
213  }
214  } else {
215  infer(decoder_model_info_present_flag, 0);
216  }
217 
218  flag(initial_display_delay_present_flag);
219 
220  fb(5, operating_points_cnt_minus_1);
221  for (i = 0; i <= current->operating_points_cnt_minus_1; i++) {
222  fbs(12, operating_point_idc[i], 1, i);
223  fbs(5, seq_level_idx[i], 1, i);
224 
225  if (current->seq_level_idx[i] > 7)
226  flags(seq_tier[i], 1, i);
227  else
228  infer(seq_tier[i], 0);
229 
230  if (current->decoder_model_info_present_flag) {
231  flags(decoder_model_present_for_this_op[i], 1, i);
232  if (current->decoder_model_present_for_this_op[i]) {
233  int n = current->decoder_model_info.buffer_delay_length_minus_1 + 1;
234  fbs(n, decoder_buffer_delay[i], 1, i);
235  fbs(n, encoder_buffer_delay[i], 1, i);
236  flags(low_delay_mode_flag[i], 1, i);
237  }
238  } else {
239  infer(decoder_model_present_for_this_op[i], 0);
240  }
241 
242  if (current->initial_display_delay_present_flag) {
243  flags(initial_display_delay_present_for_this_op[i], 1, i);
244  if (current->initial_display_delay_present_for_this_op[i])
245  fbs(4, initial_display_delay_minus_1[i], 1, i);
246  }
247  }
248  }
249 
250  fb(4, frame_width_bits_minus_1);
251  fb(4, frame_height_bits_minus_1);
252 
253  fb(current->frame_width_bits_minus_1 + 1, max_frame_width_minus_1);
254  fb(current->frame_height_bits_minus_1 + 1, max_frame_height_minus_1);
255 
256  if (current->reduced_still_picture_header)
257  infer(frame_id_numbers_present_flag, 0);
258  else
259  flag(frame_id_numbers_present_flag);
260  if (current->frame_id_numbers_present_flag) {
261  fb(4, delta_frame_id_length_minus_2);
262  fb(3, additional_frame_id_length_minus_1);
263  }
264 
265  flag(use_128x128_superblock);
266  flag(enable_filter_intra);
267  flag(enable_intra_edge_filter);
268 
269  if (current->reduced_still_picture_header) {
270  infer(enable_interintra_compound, 0);
271  infer(enable_masked_compound, 0);
272  infer(enable_warped_motion, 0);
273  infer(enable_dual_filter, 0);
274  infer(enable_order_hint, 0);
275  infer(enable_jnt_comp, 0);
276  infer(enable_ref_frame_mvs, 0);
277 
278  infer(seq_force_screen_content_tools,
280  infer(seq_force_integer_mv,
282  } else {
283  flag(enable_interintra_compound);
284  flag(enable_masked_compound);
285  flag(enable_warped_motion);
286  flag(enable_dual_filter);
287 
288  flag(enable_order_hint);
289  if (current->enable_order_hint) {
290  flag(enable_jnt_comp);
291  flag(enable_ref_frame_mvs);
292  } else {
293  infer(enable_jnt_comp, 0);
294  infer(enable_ref_frame_mvs, 0);
295  }
296 
297  flag(seq_choose_screen_content_tools);
298  if (current->seq_choose_screen_content_tools)
299  infer(seq_force_screen_content_tools,
301  else
302  fb(1, seq_force_screen_content_tools);
303  if (current->seq_force_screen_content_tools > 0) {
304  flag(seq_choose_integer_mv);
305  if (current->seq_choose_integer_mv)
306  infer(seq_force_integer_mv,
308  else
309  fb(1, seq_force_integer_mv);
310  } else {
311  infer(seq_force_integer_mv, AV1_SELECT_INTEGER_MV);
312  }
313 
314  if (current->enable_order_hint)
315  fb(3, order_hint_bits_minus_1);
316  }
317 
318  flag(enable_superres);
319  flag(enable_cdef);
320  flag(enable_restoration);
321 
322  CHECK(FUNC(color_config)(ctx, rw, &current->color_config,
323  current->seq_profile));
324 
325  flag(film_grain_params_present);
326 
327  return 0;
328 }
329 
331 {
333 
334  HEADER("Temporal Delimiter");
335 
336  priv->seen_frame_header = 0;
337 
338  return 0;
339 }
340 
342  AV1RawFrameHeader *current)
343 {
345  const AV1RawSequenceHeader *seq = priv->sequence_header;
346  static const uint8_t ref_frame_list[AV1_NUM_REF_FRAMES - 2] = {
349  };
350  int8_t ref_frame_idx[AV1_REFS_PER_FRAME], used_frame[AV1_NUM_REF_FRAMES];
351  int8_t shifted_order_hints[AV1_NUM_REF_FRAMES];
352  int cur_frame_hint, latest_order_hint, earliest_order_hint, ref;
353  int i, j;
354 
355  for (i = 0; i < AV1_REFS_PER_FRAME; i++)
356  ref_frame_idx[i] = -1;
357  ref_frame_idx[AV1_REF_FRAME_LAST - AV1_REF_FRAME_LAST] = current->last_frame_idx;
358  ref_frame_idx[AV1_REF_FRAME_GOLDEN - AV1_REF_FRAME_LAST] = current->golden_frame_idx;
359 
360  for (i = 0; i < AV1_NUM_REF_FRAMES; i++)
361  used_frame[i] = 0;
362  used_frame[current->last_frame_idx] = 1;
363  used_frame[current->golden_frame_idx] = 1;
364 
365  cur_frame_hint = 1 << (seq->order_hint_bits_minus_1);
366  for (i = 0; i < AV1_NUM_REF_FRAMES; i++)
367  shifted_order_hints[i] = cur_frame_hint +
369  priv->order_hint);
370 
371  latest_order_hint = shifted_order_hints[current->last_frame_idx];
372  earliest_order_hint = shifted_order_hints[current->golden_frame_idx];
373 
374  ref = -1;
375  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
376  int hint = shifted_order_hints[i];
377  if (!used_frame[i] && hint >= cur_frame_hint &&
378  (ref < 0 || hint >= latest_order_hint)) {
379  ref = i;
380  latest_order_hint = hint;
381  }
382  }
383  if (ref >= 0) {
384  ref_frame_idx[AV1_REF_FRAME_ALTREF - AV1_REF_FRAME_LAST] = ref;
385  used_frame[ref] = 1;
386  }
387 
388  ref = -1;
389  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
390  int hint = shifted_order_hints[i];
391  if (!used_frame[i] && hint >= cur_frame_hint &&
392  (ref < 0 || hint < earliest_order_hint)) {
393  ref = i;
394  earliest_order_hint = hint;
395  }
396  }
397  if (ref >= 0) {
398  ref_frame_idx[AV1_REF_FRAME_BWDREF - AV1_REF_FRAME_LAST] = ref;
399  used_frame[ref] = 1;
400  }
401 
402  ref = -1;
403  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
404  int hint = shifted_order_hints[i];
405  if (!used_frame[i] && hint >= cur_frame_hint &&
406  (ref < 0 || hint < earliest_order_hint)) {
407  ref = i;
408  earliest_order_hint = hint;
409  }
410  }
411  if (ref >= 0) {
412  ref_frame_idx[AV1_REF_FRAME_ALTREF2 - AV1_REF_FRAME_LAST] = ref;
413  used_frame[ref] = 1;
414  }
415 
416  for (i = 0; i < AV1_REFS_PER_FRAME - 2; i++) {
417  int ref_frame = ref_frame_list[i];
418  if (ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] < 0 ) {
419  ref = -1;
420  for (j = 0; j < AV1_NUM_REF_FRAMES; j++) {
421  int hint = shifted_order_hints[j];
422  if (!used_frame[j] && hint < cur_frame_hint &&
423  (ref < 0 || hint >= latest_order_hint)) {
424  ref = j;
425  latest_order_hint = hint;
426  }
427  }
428  if (ref >= 0) {
429  ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] = ref;
430  used_frame[ref] = 1;
431  }
432  }
433  }
434 
435  ref = -1;
436  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
437  int hint = shifted_order_hints[i];
438  if (ref < 0 || hint < earliest_order_hint) {
439  ref = i;
440  earliest_order_hint = hint;
441  }
442  }
443  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
444  if (ref_frame_idx[i] < 0)
445  ref_frame_idx[i] = ref;
446  infer(ref_frame_idx[i], ref_frame_idx[i]);
447  }
448 
449  return 0;
450 }
451 
453  AV1RawFrameHeader *current)
454 {
456  const AV1RawSequenceHeader *seq = priv->sequence_header;
457  int denom, err;
458 
459  if (seq->enable_superres)
460  flag(use_superres);
461  else
462  infer(use_superres, 0);
463 
464  if (current->use_superres) {
465  fb(3, coded_denom);
466  denom = current->coded_denom + AV1_SUPERRES_DENOM_MIN;
467  } else {
468  denom = AV1_SUPERRES_NUM;
469  }
470 
471  priv->upscaled_width = priv->frame_width;
472  priv->frame_width = (priv->upscaled_width * AV1_SUPERRES_NUM +
473  denom / 2) / denom;
474 
475  return 0;
476 }
477 
479  AV1RawFrameHeader *current)
480 {
482  const AV1RawSequenceHeader *seq = priv->sequence_header;
483  int err;
484 
485  if (current->frame_size_override_flag) {
486  fb(seq->frame_width_bits_minus_1 + 1, frame_width_minus_1);
487  fb(seq->frame_height_bits_minus_1 + 1, frame_height_minus_1);
488 
489  priv->frame_width = current->frame_width_minus_1 + 1;
490  priv->frame_height = current->frame_height_minus_1 + 1;
491  } else {
492  priv->frame_width = seq->max_frame_width_minus_1 + 1;
493  priv->frame_height = seq->max_frame_height_minus_1 + 1;
494  }
495 
496  CHECK(FUNC(superres_params)(ctx, rw, current));
497 
498  return 0;
499 }
500 
502  AV1RawFrameHeader *current)
503 {
505  int err;
506 
507  flag(render_and_frame_size_different);
508 
509  if (current->render_and_frame_size_different) {
510  fb(16, render_width_minus_1);
511  fb(16, render_height_minus_1);
512 
513  priv->render_width = current->render_width_minus_1 + 1;
514  priv->render_height = current->render_height_minus_1 + 1;
515  } else {
516  priv->render_width = priv->upscaled_width;
517  priv->render_height = priv->frame_height;
518  }
519 
520  return 0;
521 }
522 
524  AV1RawFrameHeader *current)
525 {
527  int i, err;
528 
529  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
530  flags(found_ref[i], 1, i);
531  if (current->found_ref[i]) {
533  &priv->ref[current->ref_frame_idx[i]];
534 
535  if (!ref->valid) {
536  av_log(ctx->log_ctx, AV_LOG_ERROR,
537  "Missing reference frame needed for frame size "
538  "(ref = %d, ref_frame_idx = %d).\n",
539  i, current->ref_frame_idx[i]);
540  return AVERROR_INVALIDDATA;
541  }
542 
543  priv->upscaled_width = ref->upscaled_width;
544  priv->frame_width = priv->upscaled_width;
545  priv->frame_height = ref->frame_height;
546  priv->render_width = ref->render_width;
547  priv->render_height = ref->render_height;
548  break;
549  }
550  }
551 
552  if (i >= AV1_REFS_PER_FRAME) {
553  CHECK(FUNC(frame_size)(ctx, rw, current));
554  CHECK(FUNC(render_size)(ctx, rw, current));
555  } else {
556  CHECK(FUNC(superres_params)(ctx, rw, current));
557  }
558 
559  return 0;
560 }
561 
563  AV1RawFrameHeader *current)
564 {
565  int err;
566 
567  flag(is_filter_switchable);
568  if (current->is_filter_switchable)
571  else
573 
574  return 0;
575 }
576 
578  AV1RawFrameHeader *current)
579 {
581  const AV1RawSequenceHeader *seq = priv->sequence_header;
582  int mi_cols, mi_rows, sb_cols, sb_rows, sb_shift, sb_size;
583  int max_tile_width_sb, max_tile_height_sb, max_tile_area_sb;
584  int min_log2_tile_cols, max_log2_tile_cols, max_log2_tile_rows;
585  int min_log2_tiles, min_log2_tile_rows;
586  int i, err;
587 
588  mi_cols = 2 * ((priv->frame_width + 7) >> 3);
589  mi_rows = 2 * ((priv->frame_height + 7) >> 3);
590 
591  sb_cols = seq->use_128x128_superblock ? ((mi_cols + 31) >> 5)
592  : ((mi_cols + 15) >> 4);
593  sb_rows = seq->use_128x128_superblock ? ((mi_rows + 31) >> 5)
594  : ((mi_rows + 15) >> 4);
595 
596  sb_shift = seq->use_128x128_superblock ? 5 : 4;
597  sb_size = sb_shift + 2;
598 
599  max_tile_width_sb = AV1_MAX_TILE_WIDTH >> sb_size;
600  max_tile_area_sb = AV1_MAX_TILE_AREA >> (2 * sb_size);
601 
602  min_log2_tile_cols = cbs_av1_tile_log2(max_tile_width_sb, sb_cols);
603  max_log2_tile_cols = cbs_av1_tile_log2(1, FFMIN(sb_cols, AV1_MAX_TILE_COLS));
604  max_log2_tile_rows = cbs_av1_tile_log2(1, FFMIN(sb_rows, AV1_MAX_TILE_ROWS));
605  min_log2_tiles = FFMAX(min_log2_tile_cols,
606  cbs_av1_tile_log2(max_tile_area_sb, sb_rows * sb_cols));
607 
608  flag(uniform_tile_spacing_flag);
609 
610  if (current->uniform_tile_spacing_flag) {
611  int tile_width_sb, tile_height_sb;
612 
613  increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols);
614 
615  tile_width_sb = (sb_cols + (1 << current->tile_cols_log2) - 1) >>
616  current->tile_cols_log2;
617  current->tile_cols = (sb_cols + tile_width_sb - 1) / tile_width_sb;
618 
619  min_log2_tile_rows = FFMAX(min_log2_tiles - current->tile_cols_log2, 0);
620 
621  increment(tile_rows_log2, min_log2_tile_rows, max_log2_tile_rows);
622 
623  tile_height_sb = (sb_rows + (1 << current->tile_rows_log2) - 1) >>
624  current->tile_rows_log2;
625  current->tile_rows = (sb_rows + tile_height_sb - 1) / tile_height_sb;
626 
627  } else {
628  int widest_tile_sb, start_sb, size_sb, max_width, max_height;
629 
630  widest_tile_sb = 0;
631 
632  start_sb = 0;
633  for (i = 0; start_sb < sb_cols && i < AV1_MAX_TILE_COLS; i++) {
634  max_width = FFMIN(sb_cols - start_sb, max_tile_width_sb);
635  ns(max_width, width_in_sbs_minus_1[i], 1, i);
636  size_sb = current->width_in_sbs_minus_1[i] + 1;
637  widest_tile_sb = FFMAX(size_sb, widest_tile_sb);
638  start_sb += size_sb;
639  }
640  current->tile_cols_log2 = cbs_av1_tile_log2(1, i);
641  current->tile_cols = i;
642 
643  if (min_log2_tiles > 0)
644  max_tile_area_sb = (sb_rows * sb_cols) >> (min_log2_tiles + 1);
645  else
646  max_tile_area_sb = sb_rows * sb_cols;
647  max_tile_height_sb = FFMAX(max_tile_area_sb / widest_tile_sb, 1);
648 
649  start_sb = 0;
650  for (i = 0; start_sb < sb_rows && i < AV1_MAX_TILE_ROWS; i++) {
651  max_height = FFMIN(sb_rows - start_sb, max_tile_height_sb);
652  ns(max_height, height_in_sbs_minus_1[i], 1, i);
653  size_sb = current->height_in_sbs_minus_1[i] + 1;
654  start_sb += size_sb;
655  }
656  current->tile_rows_log2 = cbs_av1_tile_log2(1, i);
657  current->tile_rows = i;
658  }
659 
660  if (current->tile_cols_log2 > 0 ||
661  current->tile_rows_log2 > 0) {
662  fb(current->tile_cols_log2 + current->tile_rows_log2,
663  context_update_tile_id);
664  fb(2, tile_size_bytes_minus1);
665  } else {
666  infer(context_update_tile_id, 0);
667  }
668 
669  priv->tile_cols = current->tile_cols;
670  priv->tile_rows = current->tile_rows;
671 
672  return 0;
673 }
674 
676  AV1RawFrameHeader *current)
677 {
679  const AV1RawSequenceHeader *seq = priv->sequence_header;
680  int err;
681 
682  fb(8, base_q_idx);
683 
684  delta_q(delta_q_y_dc);
685 
686  if (priv->num_planes > 1) {
688  flag(diff_uv_delta);
689  else
690  infer(diff_uv_delta, 0);
691 
692  delta_q(delta_q_u_dc);
693  delta_q(delta_q_u_ac);
694 
695  if (current->diff_uv_delta) {
696  delta_q(delta_q_v_dc);
697  delta_q(delta_q_v_ac);
698  } else {
699  infer(delta_q_v_dc, current->delta_q_u_dc);
700  infer(delta_q_v_ac, current->delta_q_u_ac);
701  }
702  } else {
703  infer(delta_q_u_dc, 0);
704  infer(delta_q_u_ac, 0);
705  infer(delta_q_v_dc, 0);
706  infer(delta_q_v_ac, 0);
707  }
708 
709  flag(using_qmatrix);
710  if (current->using_qmatrix) {
711  fb(4, qm_y);
712  fb(4, qm_u);
714  fb(4, qm_v);
715  else
716  infer(qm_v, current->qm_u);
717  }
718 
719  return 0;
720 }
721 
723  AV1RawFrameHeader *current)
724 {
725  static const uint8_t bits[AV1_SEG_LVL_MAX] = { 8, 6, 6, 6, 6, 3, 0, 0 };
726  static const uint8_t sign[AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 };
727  int i, j, err;
728 
729  flag(segmentation_enabled);
730 
731  if (current->segmentation_enabled) {
732  if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
733  infer(segmentation_update_map, 1);
734  infer(segmentation_temporal_update, 0);
735  infer(segmentation_update_data, 1);
736  } else {
737  flag(segmentation_update_map);
738  if (current->segmentation_update_map)
739  flag(segmentation_temporal_update);
740  else
741  infer(segmentation_temporal_update, 0);
742  flag(segmentation_update_data);
743  }
744 
745  if (current->segmentation_update_data) {
746  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
747  for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
748  flags(feature_enabled[i][j], 2, i, j);
749 
750  if (current->feature_enabled[i][j] && bits[j] > 0) {
751  if (sign[j])
752  sus(1 + bits[j], feature_value[i][j], 2, i, j);
753  else
754  fbs(bits[j], feature_value[i][j], 2, i, j);
755  } else {
756  infer(feature_value[i][j], 0);
757  }
758  }
759  }
760  }
761  } else {
762  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
763  for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
764  infer(feature_enabled[i][j], 0);
765  infer(feature_value[i][j], 0);
766  }
767  }
768  }
769 
770  return 0;
771 }
772 
774  AV1RawFrameHeader *current)
775 {
776  int err;
777 
778  if (current->base_q_idx > 0)
779  flag(delta_q_present);
780  else
781  infer(delta_q_present, 0);
782 
783  if (current->delta_q_present)
784  fb(2, delta_q_res);
785 
786  return 0;
787 }
788 
790  AV1RawFrameHeader *current)
791 {
792  int err;
793 
794  if (current->delta_q_present) {
795  if (!current->allow_intrabc)
796  flag(delta_lf_present);
797  else
798  infer(delta_lf_present, 0);
799  if (current->delta_lf_present) {
800  fb(2, delta_lf_res);
801  flag(delta_lf_multi);
802  } else {
803  infer(delta_lf_res, 0);
804  infer(delta_lf_multi, 0);
805  }
806  } else {
807  infer(delta_lf_present, 0);
808  infer(delta_lf_res, 0);
809  infer(delta_lf_multi, 0);
810  }
811 
812  return 0;
813 }
814 
816  AV1RawFrameHeader *current)
817 {
819  int i, err;
820 
821  if (priv->coded_lossless || current->allow_intrabc) {
822  infer(loop_filter_level[0], 0);
823  infer(loop_filter_level[1], 0);
824  infer(loop_filter_ref_deltas[AV1_REF_FRAME_INTRA], 1);
825  infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST], 0);
826  infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST2], 0);
827  infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST3], 0);
828  infer(loop_filter_ref_deltas[AV1_REF_FRAME_BWDREF], 0);
829  infer(loop_filter_ref_deltas[AV1_REF_FRAME_GOLDEN], -1);
830  infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF], -1);
831  infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF2], -1);
832  for (i = 0; i < 2; i++)
833  infer(loop_filter_mode_deltas[i], 0);
834  return 0;
835  }
836 
837  fb(6, loop_filter_level[0]);
838  fb(6, loop_filter_level[1]);
839 
840  if (priv->num_planes > 1) {
841  if (current->loop_filter_level[0] ||
842  current->loop_filter_level[1]) {
843  fb(6, loop_filter_level[2]);
844  fb(6, loop_filter_level[3]);
845  }
846  }
847 
848  fb(3, loop_filter_sharpness);
849 
850  flag(loop_filter_delta_enabled);
851  if (current->loop_filter_delta_enabled) {
852  flag(loop_filter_delta_update);
853  if (current->loop_filter_delta_update) {
854  for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) {
855  flags(update_ref_delta[i], 1, i);
856  if (current->update_ref_delta[i])
857  sus(1 + 6, loop_filter_ref_deltas[i], 1, i);
858  }
859  for (i = 0; i < 2; i++) {
860  flags(update_mode_delta[i], 1, i);
861  if (current->update_mode_delta[i])
862  sus(1 + 6, loop_filter_mode_deltas[i], 1, i);
863  }
864  }
865  }
866 
867  return 0;
868 }
869 
871  AV1RawFrameHeader *current)
872 {
874  const AV1RawSequenceHeader *seq = priv->sequence_header;
875  int i, err;
876 
877  if (priv->coded_lossless || current->allow_intrabc ||
878  !seq->enable_cdef) {
879  infer(cdef_damping_minus_3, 0);
880  infer(cdef_bits, 0);
881  infer(cdef_y_pri_strength[0], 0);
882  infer(cdef_y_sec_strength[0], 0);
883  infer(cdef_uv_pri_strength[0], 0);
884  infer(cdef_uv_sec_strength[0], 0);
885 
886  return 0;
887  }
888 
889  fb(2, cdef_damping_minus_3);
890  fb(2, cdef_bits);
891 
892  for (i = 0; i < (1 << current->cdef_bits); i++) {
893  fbs(4, cdef_y_pri_strength[i], 1, i);
894  fbs(2, cdef_y_sec_strength[i], 1, i);
895 
896  if (priv->num_planes > 1) {
897  fbs(4, cdef_uv_pri_strength[i], 1, i);
898  fbs(2, cdef_uv_sec_strength[i], 1, i);
899  }
900  }
901 
902  return 0;
903 }
904 
906  AV1RawFrameHeader *current)
907 {
909  const AV1RawSequenceHeader *seq = priv->sequence_header;
910  int uses_lr, uses_chroma_lr;
911  int i, err;
912 
913  if (priv->all_lossless || current->allow_intrabc ||
914  !seq->enable_restoration) {
915  return 0;
916  }
917 
918  uses_lr = uses_chroma_lr = 0;
919  for (i = 0; i < priv->num_planes; i++) {
920  fbs(2, lr_type[i], 1, i);
921 
922  if (current->lr_type[i] != 0) {
923  uses_lr = 1;
924  if (i > 0)
925  uses_chroma_lr = 1;
926  }
927  }
928 
929  if (uses_lr) {
930  if (seq->use_128x128_superblock)
931  increment(lr_unit_shift, 1, 2);
932  else
933  increment(lr_unit_shift, 0, 2);
934 
935  if(seq->color_config.subsampling_x &&
936  seq->color_config.subsampling_y && uses_chroma_lr) {
937  fb(1, lr_uv_shift);
938  } else {
939  infer(lr_uv_shift, 0);
940  }
941  }
942 
943  return 0;
944 }
945 
947  AV1RawFrameHeader *current)
948 {
950  int err;
951 
952  if (priv->coded_lossless)
953  infer(tx_mode, 0);
954  else
955  increment(tx_mode, 1, 2);
956 
957  return 0;
958 }
959 
961  AV1RawFrameHeader *current)
962 {
963  int err;
964 
965  if (current->frame_type == AV1_FRAME_INTRA_ONLY ||
966  current->frame_type == AV1_FRAME_KEY)
967  infer(reference_select, 0);
968  else
969  flag(reference_select);
970 
971  return 0;
972 }
973 
975  AV1RawFrameHeader *current)
976 {
978  const AV1RawSequenceHeader *seq = priv->sequence_header;
979  int skip_mode_allowed;
980  int err;
981 
982  if (current->frame_type == AV1_FRAME_KEY ||
983  current->frame_type == AV1_FRAME_INTRA_ONLY ||
984  !current->reference_select || !seq->enable_order_hint) {
985  skip_mode_allowed = 0;
986  } else {
987  int forward_idx, backward_idx;
988  int forward_hint, backward_hint;
989  int ref_hint, dist, i;
990 
991  forward_idx = -1;
992  backward_idx = -1;
993  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
994  ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint;
995  dist = cbs_av1_get_relative_dist(seq, ref_hint,
996  priv->order_hint);
997  if (dist < 0) {
998  if (forward_idx < 0 ||
999  cbs_av1_get_relative_dist(seq, ref_hint,
1000  forward_hint) > 0) {
1001  forward_idx = i;
1002  forward_hint = ref_hint;
1003  }
1004  } else if (dist > 0) {
1005  if (backward_idx < 0 ||
1006  cbs_av1_get_relative_dist(seq, ref_hint,
1007  backward_hint) < 0) {
1008  backward_idx = i;
1009  backward_hint = ref_hint;
1010  }
1011  }
1012  }
1013 
1014  if (forward_idx < 0) {
1015  skip_mode_allowed = 0;
1016  } else if (backward_idx >= 0) {
1017  skip_mode_allowed = 1;
1018  // Frames for skip mode are forward_idx and backward_idx.
1019  } else {
1020  int second_forward_idx;
1021  int second_forward_hint;
1022 
1023  second_forward_idx = -1;
1024  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1025  ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint;
1026  if (cbs_av1_get_relative_dist(seq, ref_hint,
1027  forward_hint) < 0) {
1028  if (second_forward_idx < 0 ||
1029  cbs_av1_get_relative_dist(seq, ref_hint,
1030  second_forward_hint) > 0) {
1031  second_forward_idx = i;
1032  second_forward_hint = ref_hint;
1033  }
1034  }
1035  }
1036 
1037  if (second_forward_idx < 0) {
1038  skip_mode_allowed = 0;
1039  } else {
1040  skip_mode_allowed = 1;
1041  // Frames for skip mode are forward_idx and second_forward_idx.
1042  }
1043  }
1044  }
1045 
1046  if (skip_mode_allowed)
1047  flag(skip_mode_present);
1048  else
1049  infer(skip_mode_present, 0);
1050 
1051  return 0;
1052 }
1053 
1055  AV1RawFrameHeader *current,
1056  int type, int ref, int idx)
1057 {
1058  uint32_t abs_bits, prec_bits, num_syms;
1059  int err;
1060 
1061  if (idx < 2) {
1063  abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS - !current->allow_high_precision_mv;
1064  prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS - !current->allow_high_precision_mv;
1065  } else {
1066  abs_bits = AV1_GM_ABS_TRANS_BITS;
1067  prec_bits = AV1_GM_TRANS_PREC_BITS;
1068  }
1069  } else {
1070  abs_bits = AV1_GM_ABS_ALPHA_BITS;
1071  prec_bits = AV1_GM_ALPHA_PREC_BITS;
1072  }
1073 
1074  num_syms = 2 * (1 << abs_bits) + 1;
1075  subexp(gm_params[ref][idx], num_syms, 2, ref, idx);
1076 
1077  // Actual gm_params value is not reconstructed here.
1078  (void)prec_bits;
1079 
1080  return 0;
1081 }
1082 
1084  AV1RawFrameHeader *current)
1085 {
1086  int ref, type;
1087  int err;
1088 
1089  if (current->frame_type == AV1_FRAME_KEY ||
1090  current->frame_type == AV1_FRAME_INTRA_ONLY)
1091  return 0;
1092 
1094  flags(is_global[ref], 1, ref);
1095  if (current->is_global[ref]) {
1096  flags(is_rot_zoom[ref], 1, ref);
1097  if (current->is_rot_zoom[ref]) {
1099  } else {
1100  flags(is_translation[ref], 1, ref);
1101  type = current->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
1103  }
1104  } else {
1106  }
1107 
1108  if (type >= AV1_WARP_MODEL_ROTZOOM) {
1109  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 2));
1110  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 3));
1111  if (type == AV1_WARP_MODEL_AFFINE) {
1112  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 4));
1113  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 5));
1114  } else {
1115  // gm_params[ref][4] = -gm_params[ref][3]
1116  // gm_params[ref][5] = gm_params[ref][2]
1117  }
1118  }
1120  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 0));
1121  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 1));
1122  }
1123  }
1124 
1125  return 0;
1126 }
1127 
1129  AV1RawFrameHeader *current)
1130 {
1132  const AV1RawSequenceHeader *seq = priv->sequence_header;
1133  int num_pos_luma, num_pos_chroma;
1134  int i, err;
1135 
1136  if (!seq->film_grain_params_present ||
1137  (!current->show_frame && !current->showable_frame))
1138  return 0;
1139 
1140  flag(apply_grain);
1141 
1142  if (!current->apply_grain)
1143  return 0;
1144 
1145  fb(16, grain_seed);
1146 
1147  if (current->frame_type == AV1_FRAME_INTER)
1148  flag(update_grain);
1149  else
1150  infer(update_grain, 1);
1151 
1152  if (!current->update_grain) {
1153  fb(3, film_grain_params_ref_idx);
1154  return 0;
1155  }
1156 
1157  fc(4, num_y_points, 0, 14);
1158  for (i = 0; i < current->num_y_points; i++) {
1159  fcs(8, point_y_value[i],
1160  i ? current->point_y_value[i - 1] + 1 : 0,
1161  MAX_UINT_BITS(8) - (current->num_y_points - i - 1),
1162  1, i);
1163  fbs(8, point_y_scaling[i], 1, i);
1164  }
1165 
1166  if (seq->color_config.mono_chrome)
1167  infer(chroma_scaling_from_luma, 0);
1168  else
1169  flag(chroma_scaling_from_luma);
1170 
1171  if (seq->color_config.mono_chrome ||
1172  current->chroma_scaling_from_luma ||
1173  (seq->color_config.subsampling_x == 1 &&
1174  seq->color_config.subsampling_y == 1 &&
1175  current->num_y_points == 0)) {
1176  infer(num_cb_points, 0);
1177  infer(num_cr_points, 0);
1178  } else {
1179  fc(4, num_cb_points, 0, 10);
1180  for (i = 0; i < current->num_cb_points; i++) {
1181  fcs(8, point_cb_value[i],
1182  i ? current->point_cb_value[i - 1] + 1 : 0,
1183  MAX_UINT_BITS(8) - (current->num_cb_points - i - 1),
1184  1, i);
1185  fbs(8, point_cb_scaling[i], 1, i);
1186  }
1187  fc(4, num_cr_points, 0, 10);
1188  for (i = 0; i < current->num_cr_points; i++) {
1189  fcs(8, point_cr_value[i],
1190  i ? current->point_cr_value[i - 1] + 1 : 0,
1191  MAX_UINT_BITS(8) - (current->num_cr_points - i - 1),
1192  1, i);
1193  fbs(8, point_cr_scaling[i], 1, i);
1194  }
1195  }
1196 
1197  fb(2, grain_scaling_minus_8);
1198  fb(2, ar_coeff_lag);
1199  num_pos_luma = 2 * current->ar_coeff_lag * (current->ar_coeff_lag + 1);
1200  if (current->num_y_points) {
1201  num_pos_chroma = num_pos_luma + 1;
1202  for (i = 0; i < num_pos_luma; i++)
1203  fbs(8, ar_coeffs_y_plus_128[i], 1, i);
1204  } else {
1205  num_pos_chroma = num_pos_luma;
1206  }
1207  if (current->chroma_scaling_from_luma || current->num_cb_points) {
1208  for (i = 0; i < num_pos_chroma; i++)
1209  fbs(8, ar_coeffs_cb_plus_128[i], 1, i);
1210  }
1211  if (current->chroma_scaling_from_luma || current->num_cr_points) {
1212  for (i = 0; i < num_pos_chroma; i++)
1213  fbs(8, ar_coeffs_cr_plus_128[i], 1, i);
1214  }
1215  fb(2, ar_coeff_shift_minus_6);
1216  fb(2, grain_scale_shift);
1217  if (current->num_cb_points) {
1218  fb(8, cb_mult);
1219  fb(8, cb_luma_mult);
1220  fb(9, cb_offset);
1221  }
1222  if (current->num_cr_points) {
1223  fb(8, cr_mult);
1224  fb(8, cr_luma_mult);
1225  fb(9, cr_offset);
1226  }
1227 
1228  flag(overlap_flag);
1229  flag(clip_to_restricted_range);
1230 
1231  return 0;
1232 }
1233 
1235  AV1RawFrameHeader *current)
1236 {
1238  const AV1RawSequenceHeader *seq;
1239  int id_len, diff_len, all_frames, frame_is_intra, order_hint_bits;
1240  int i, err;
1241 
1242  if (!priv->sequence_header) {
1243  av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: "
1244  "unable to decode frame header.\n");
1245  return AVERROR_INVALIDDATA;
1246  }
1247  seq = priv->sequence_header;
1248 
1249  id_len = seq->additional_frame_id_length_minus_1 +
1251  all_frames = (1 << AV1_NUM_REF_FRAMES) - 1;
1252 
1253  if (seq->reduced_still_picture_header) {
1254  infer(show_existing_frame, 0);
1256  infer(show_frame, 1);
1257  infer(showable_frame, 0);
1258  frame_is_intra = 1;
1259 
1260  } else {
1261  flag(show_existing_frame);
1262 
1263  if (current->show_existing_frame) {
1265 
1266  fb(3, frame_to_show_map_idx);
1267  ref = &priv->ref[current->frame_to_show_map_idx];
1268 
1272  frame_presentation_time);
1273  }
1274 
1276  fb(id_len, display_frame_id);
1277 
1278  infer(frame_type, ref->frame_type);
1279  if (current->frame_type == AV1_FRAME_KEY) {
1280  infer(refresh_frame_flags, all_frames);
1281 
1282  // Section 7.21
1283  infer(current_frame_id, ref->frame_id);
1284  priv->upscaled_width = ref->upscaled_width;
1285  priv->frame_width = ref->frame_width;
1286  priv->frame_height = ref->frame_height;
1287  priv->render_width = ref->render_width;
1288  priv->render_height = ref->render_height;
1289  priv->bit_depth = ref->bit_depth;
1290  priv->order_hint = ref->order_hint;
1291  } else
1292  infer(refresh_frame_flags, 0);
1293 
1294  // Section 7.20
1295  goto update_refs;
1296  }
1297 
1298  fb(2, frame_type);
1299  frame_is_intra = (current->frame_type == AV1_FRAME_INTRA_ONLY ||
1300  current->frame_type == AV1_FRAME_KEY);
1301 
1302  flag(show_frame);
1303  if (current->show_frame &&
1307  frame_presentation_time);
1308  }
1309  if (current->show_frame)
1310  infer(showable_frame, current->frame_type != AV1_FRAME_KEY);
1311  else
1312  flag(showable_frame);
1313 
1314  if (current->frame_type == AV1_FRAME_SWITCH ||
1315  (current->frame_type == AV1_FRAME_KEY && current->show_frame))
1316  infer(error_resilient_mode, 1);
1317  else
1318  flag(error_resilient_mode);
1319  }
1320 
1321  if (current->frame_type == AV1_FRAME_KEY && current->show_frame) {
1322  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1323  priv->ref[i].valid = 0;
1324  priv->ref[i].order_hint = 0;
1325  }
1326  }
1327 
1328  flag(disable_cdf_update);
1329 
1330  if (seq->seq_force_screen_content_tools ==
1332  flag(allow_screen_content_tools);
1333  } else {
1334  infer(allow_screen_content_tools,
1336  }
1337  if (current->allow_screen_content_tools) {
1339  flag(force_integer_mv);
1340  else
1341  infer(force_integer_mv, seq->seq_force_integer_mv);
1342  } else {
1343  infer(force_integer_mv, 0);
1344  }
1345 
1346  if (seq->frame_id_numbers_present_flag) {
1347  fb(id_len, current_frame_id);
1348 
1349  diff_len = seq->delta_frame_id_length_minus_2 + 2;
1350  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1351  if (current->current_frame_id > (1 << diff_len)) {
1352  if (priv->ref[i].frame_id > current->current_frame_id ||
1353  priv->ref[i].frame_id < (current->current_frame_id -
1354  (1 << diff_len)))
1355  priv->ref[i].valid = 0;
1356  } else {
1357  if (priv->ref[i].frame_id > current->current_frame_id &&
1358  priv->ref[i].frame_id < ((1 << id_len) +
1359  current->current_frame_id -
1360  (1 << diff_len)))
1361  priv->ref[i].valid = 0;
1362  }
1363  }
1364  } else {
1365  infer(current_frame_id, 0);
1366  }
1367 
1368  if (current->frame_type == AV1_FRAME_SWITCH)
1369  infer(frame_size_override_flag, 1);
1370  else if(seq->reduced_still_picture_header)
1371  infer(frame_size_override_flag, 0);
1372  else
1373  flag(frame_size_override_flag);
1374 
1375  order_hint_bits =
1376  seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0;
1377  if (order_hint_bits > 0)
1378  fb(order_hint_bits, order_hint);
1379  else
1380  infer(order_hint, 0);
1381  priv->order_hint = current->order_hint;
1382 
1383  if (frame_is_intra || current->error_resilient_mode)
1384  infer(primary_ref_frame, AV1_PRIMARY_REF_NONE);
1385  else
1386  fb(3, primary_ref_frame);
1387 
1389  flag(buffer_removal_time_present_flag);
1390  if (current->buffer_removal_time_present_flag) {
1391  for (i = 0; i <= seq->operating_points_cnt_minus_1; i++) {
1393  int op_pt_idc = seq->operating_point_idc[i];
1394  int in_temporal_layer = (op_pt_idc >> priv->temporal_id ) & 1;
1395  int in_spatial_layer = (op_pt_idc >> (priv->spatial_id + 8)) & 1;
1396  if (seq->operating_point_idc[i] == 0 ||
1397  (in_temporal_layer && in_spatial_layer)) {
1399  buffer_removal_time[i], 1, i);
1400  }
1401  }
1402  }
1403  }
1404  }
1405 
1406  if (current->frame_type == AV1_FRAME_SWITCH ||
1407  (current->frame_type == AV1_FRAME_KEY && current->show_frame))
1408  infer(refresh_frame_flags, all_frames);
1409  else
1410  fb(8, refresh_frame_flags);
1411 
1412  if (!frame_is_intra || current->refresh_frame_flags != all_frames) {
1413  if (current->error_resilient_mode && seq->enable_order_hint) {
1414  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1415  fbs(order_hint_bits, ref_order_hint[i], 1, i);
1416  if (current->ref_order_hint[i] != priv->ref[i].order_hint)
1417  priv->ref[i].valid = 0;
1418  }
1419  }
1420  }
1421 
1422  if (current->frame_type == AV1_FRAME_KEY ||
1423  current->frame_type == AV1_FRAME_INTRA_ONLY) {
1424  CHECK(FUNC(frame_size)(ctx, rw, current));
1425  CHECK(FUNC(render_size)(ctx, rw, current));
1426 
1427  if (current->allow_screen_content_tools &&
1428  priv->upscaled_width == priv->frame_width)
1429  flag(allow_intrabc);
1430  else
1431  infer(allow_intrabc, 0);
1432 
1433  } else {
1434  if (!seq->enable_order_hint) {
1435  infer(frame_refs_short_signaling, 0);
1436  } else {
1437  flag(frame_refs_short_signaling);
1438  if (current->frame_refs_short_signaling) {
1439  fb(3, last_frame_idx);
1440  fb(3, golden_frame_idx);
1441  CHECK(FUNC(set_frame_refs)(ctx, rw, current));
1442  }
1443  }
1444 
1445  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1446  if (!current->frame_refs_short_signaling)
1447  fbs(3, ref_frame_idx[i], 1, i);
1448  if (seq->frame_id_numbers_present_flag) {
1450  delta_frame_id_minus1[i], 1, i);
1451  }
1452  }
1453 
1454  if (current->frame_size_override_flag &&
1455  !current->error_resilient_mode) {
1456  CHECK(FUNC(frame_size_with_refs)(ctx, rw, current));
1457  } else {
1458  CHECK(FUNC(frame_size)(ctx, rw, current));
1459  CHECK(FUNC(render_size)(ctx, rw, current));
1460  }
1461 
1462  if (current->force_integer_mv)
1463  infer(allow_high_precision_mv, 0);
1464  else
1465  flag(allow_high_precision_mv);
1466 
1467  CHECK(FUNC(interpolation_filter)(ctx, rw, current));
1468 
1469  flag(is_motion_mode_switchable);
1470 
1471  if (current->error_resilient_mode ||
1472  !seq->enable_ref_frame_mvs)
1473  infer(use_ref_frame_mvs, 0);
1474  else
1475  flag(use_ref_frame_mvs);
1476 
1477  infer(allow_intrabc, 0);
1478  }
1479 
1480  if (!frame_is_intra) {
1481  // Derive reference frame sign biases.
1482  }
1483 
1484  if (seq->reduced_still_picture_header || current->disable_cdf_update)
1485  infer(disable_frame_end_update_cdf, 1);
1486  else
1487  flag(disable_frame_end_update_cdf);
1488 
1489  if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
1490  // Init non-coeff CDFs.
1491  // Setup past independence.
1492  } else {
1493  // Load CDF tables from previous frame.
1494  // Load params from previous frame.
1495  }
1496 
1497  if (current->use_ref_frame_mvs) {
1498  // Perform motion field estimation process.
1499  }
1500 
1501  CHECK(FUNC(tile_info)(ctx, rw, current));
1502 
1503  CHECK(FUNC(quantization_params)(ctx, rw, current));
1504 
1505  CHECK(FUNC(segmentation_params)(ctx, rw, current));
1506 
1507  CHECK(FUNC(delta_q_params)(ctx, rw, current));
1508 
1509  CHECK(FUNC(delta_lf_params)(ctx, rw, current));
1510 
1511  // Init coeff CDFs / load previous segments.
1512 
1513  priv->coded_lossless = 1;
1514  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
1515  int qindex;
1516  if (current->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
1517  qindex = (current->base_q_idx +
1518  current->feature_value[i][AV1_SEG_LVL_ALT_Q]);
1519  } else {
1520  qindex = current->base_q_idx;
1521  }
1522  qindex = av_clip_uintp2(qindex, 8);
1523 
1524  if (qindex || current->delta_q_y_dc ||
1525  current->delta_q_u_ac || current->delta_q_u_dc ||
1526  current->delta_q_v_ac || current->delta_q_v_dc) {
1527  priv->coded_lossless = 0;
1528  }
1529  }
1530  priv->all_lossless = priv->coded_lossless &&
1531  priv->frame_width == priv->upscaled_width;
1532 
1533  CHECK(FUNC(loop_filter_params)(ctx, rw, current));
1534 
1535  CHECK(FUNC(cdef_params)(ctx, rw, current));
1536 
1537  CHECK(FUNC(lr_params)(ctx, rw, current));
1538 
1539  CHECK(FUNC(read_tx_mode)(ctx, rw, current));
1540 
1541  CHECK(FUNC(frame_reference_mode)(ctx, rw, current));
1542 
1543  CHECK(FUNC(skip_mode_params)(ctx, rw, current));
1544 
1545  if (frame_is_intra || current->error_resilient_mode ||
1546  !seq->enable_warped_motion)
1547  infer(allow_warped_motion, 0);
1548  else
1549  flag(allow_warped_motion);
1550 
1551  flag(reduced_tx_set);
1552 
1553  CHECK(FUNC(global_motion_params)(ctx, rw, current));
1554 
1555  CHECK(FUNC(film_grain_params)(ctx, rw, current));
1556 
1557  av_log(ctx->log_ctx, AV_LOG_DEBUG, "Frame %d: size %dx%d "
1558  "upscaled %d render %dx%d subsample %dx%d "
1559  "bitdepth %d tiles %dx%d.\n", priv->order_hint,
1560  priv->frame_width, priv->frame_height, priv->upscaled_width,
1561  priv->render_width, priv->render_height,
1562  seq->color_config.subsampling_x + 1,
1563  seq->color_config.subsampling_y + 1, priv->bit_depth,
1564  priv->tile_rows, priv->tile_cols);
1565 
1566 update_refs:
1567  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1568  if (current->refresh_frame_flags & (1 << i)) {
1569  priv->ref[i] = (AV1ReferenceFrameState) {
1570  .valid = 1,
1571  .frame_id = current->current_frame_id,
1572  .upscaled_width = priv->upscaled_width,
1573  .frame_width = priv->frame_width,
1574  .frame_height = priv->frame_height,
1575  .render_width = priv->render_width,
1576  .render_height = priv->render_height,
1577  .frame_type = current->frame_type,
1578  .subsampling_x = seq->color_config.subsampling_x,
1579  .subsampling_y = seq->color_config.subsampling_y,
1580  .bit_depth = priv->bit_depth,
1581  .order_hint = priv->order_hint,
1582  };
1583  }
1584  }
1585 
1586  return 0;
1587 }
1588 
1590  AV1RawFrameHeader *current, int redundant,
1591  AVBufferRef *rw_buffer_ref)
1592 {
1594  int start_pos, fh_bits, fh_bytes, err;
1595  uint8_t *fh_start;
1596 
1597  if (priv->seen_frame_header) {
1598  if (!redundant) {
1599  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid repeated "
1600  "frame header OBU.\n");
1601  return AVERROR_INVALIDDATA;
1602  } else {
1603  GetBitContext fh;
1604  size_t i, b;
1605  uint32_t val;
1606 
1607  HEADER("Redundant Frame Header");
1608 
1609  av_assert0(priv->frame_header_ref && priv->frame_header);
1610 
1611  init_get_bits(&fh, priv->frame_header,
1612  priv->frame_header_size);
1613  for (i = 0; i < priv->frame_header_size; i += 8) {
1614  b = FFMIN(priv->frame_header_size - i, 8);
1615  val = get_bits(&fh, b);
1616  xf(b, frame_header_copy[i],
1617  val, val, val, 1, i / 8);
1618  }
1619  }
1620  } else {
1621  if (redundant)
1622  HEADER("Redundant Frame Header (used as Frame Header)");
1623  else
1624  HEADER("Frame Header");
1625 
1626 #ifdef READ
1627  start_pos = get_bits_count(rw);
1628 #else
1629  start_pos = put_bits_count(rw);
1630 #endif
1631 
1632  CHECK(FUNC(uncompressed_header)(ctx, rw, current));
1633 
1634  if (current->show_existing_frame) {
1635  priv->seen_frame_header = 0;
1636  } else {
1637  priv->seen_frame_header = 1;
1638 
1640 
1641 #ifdef READ
1642  fh_bits = get_bits_count(rw) - start_pos;
1643  fh_start = (uint8_t*)rw->buffer + start_pos / 8;
1644 #else
1645  // Need to flush the bitwriter so that we can copy its output,
1646  // but use a copy so we don't affect the caller's structure.
1647  {
1648  PutBitContext tmp = *rw;
1649  flush_put_bits(&tmp);
1650  }
1651 
1652  fh_bits = put_bits_count(rw) - start_pos;
1653  fh_start = rw->buf + start_pos / 8;
1654 #endif
1655  fh_bytes = (fh_bits + 7) / 8;
1656 
1657  priv->frame_header_size = fh_bits;
1658 
1659  if (rw_buffer_ref) {
1660  priv->frame_header_ref = av_buffer_ref(rw_buffer_ref);
1661  if (!priv->frame_header_ref)
1662  return AVERROR(ENOMEM);
1663  priv->frame_header = fh_start;
1664  } else {
1665  priv->frame_header_ref =
1667  if (!priv->frame_header_ref)
1668  return AVERROR(ENOMEM);
1669  priv->frame_header = priv->frame_header_ref->data;
1670  memcpy(priv->frame_header, fh_start, fh_bytes);
1671  }
1672  }
1673  }
1674 
1675  return 0;
1676 }
1677 
1679  AV1RawTileGroup *current)
1680 {
1682  int num_tiles, tile_bits;
1683  int err;
1684 
1685  HEADER("Tile Group");
1686 
1687  num_tiles = priv->tile_cols * priv->tile_rows;
1688  if (num_tiles > 1)
1689  flag(tile_start_and_end_present_flag);
1690  else
1691  infer(tile_start_and_end_present_flag, 0);
1692 
1693  if (num_tiles == 1 || !current->tile_start_and_end_present_flag) {
1694  infer(tg_start, 0);
1695  infer(tg_end, num_tiles - 1);
1696  } else {
1697  tile_bits = cbs_av1_tile_log2(1, priv->tile_cols) +
1698  cbs_av1_tile_log2(1, priv->tile_rows);
1699  fb(tile_bits, tg_start);
1700  fb(tile_bits, tg_end);
1701  }
1702 
1703  CHECK(FUNC(byte_alignment)(ctx, rw));
1704 
1705  // Reset header for next frame.
1706  if (current->tg_end == num_tiles - 1)
1707  priv->seen_frame_header = 0;
1708 
1709  // Tile data follows.
1710 
1711  return 0;
1712 }
1713 
1715  AV1RawFrame *current,
1716  AVBufferRef *rw_buffer_ref)
1717 {
1718  int err;
1719 
1720  CHECK(FUNC(frame_header_obu)(ctx, rw, &current->header,
1721  0, rw_buffer_ref));
1722 
1723  CHECK(FUNC(byte_alignment)(ctx, rw));
1724 
1725  CHECK(FUNC(tile_group_obu)(ctx, rw, &current->tile_group));
1726 
1727  return 0;
1728 }
1729 
1731  AV1RawTileList *current)
1732 {
1733  int err;
1734 
1735  fb(8, output_frame_width_in_tiles_minus_1);
1736  fb(8, output_frame_height_in_tiles_minus_1);
1737 
1738  fb(16, tile_count_minus_1);
1739 
1740  // Tile data follows.
1741 
1742  return 0;
1743 }
1744 
1746  AV1RawMetadataHDRCLL *current)
1747 {
1748  int err;
1749 
1750  fb(16, max_cll);
1751  fb(16, max_fall);
1752 
1753  return 0;
1754 }
1755 
1757  AV1RawMetadataHDRMDCV *current)
1758 {
1759  int err, i;
1760 
1761  for (i = 0; i < 3; i++) {
1762  fbs(16, primary_chromaticity_x[i], 1, i);
1763  fbs(16, primary_chromaticity_y[i], 1, i);
1764  }
1765 
1766  fb(16, white_point_chromaticity_x);
1767  fb(16, white_point_chromaticity_y);
1768 
1769  fc(32, luminance_max, 1, MAX_UINT_BITS(32));
1770  // luminance_min must be lower than luminance_max. Convert luminance_max from
1771  // 24.8 fixed point to 18.14 fixed point in order to compare them.
1772  fc(32, luminance_min, 0, FFMIN(((uint64_t)current->luminance_max << 6) - 1,
1773  MAX_UINT_BITS(32)));
1774 
1775  return 0;
1776 }
1777 
1779  AV1RawMetadataScalability *current)
1780 {
1782  const AV1RawSequenceHeader *seq;
1783  int err, i, j;
1784 
1785  if (!priv->sequence_header) {
1786  av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: "
1787  "unable to parse scalability metadata.\n");
1788  return AVERROR_INVALIDDATA;
1789  }
1790  seq = priv->sequence_header;
1791 
1792  fb(2, spatial_layers_cnt_minus_1);
1793  flag(spatial_layer_dimensions_present_flag);
1794  flag(spatial_layer_description_present_flag);
1795  flag(temporal_group_description_present_flag);
1796  fc(3, scalability_structure_reserved_3bits, 0, 0);
1797  if (current->spatial_layer_dimensions_present_flag) {
1798  for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) {
1799  fcs(16, spatial_layer_max_width[i],
1800  0, seq->max_frame_width_minus_1 + 1, 1, i);
1801  fcs(16, spatial_layer_max_height[i],
1802  0, seq->max_frame_height_minus_1 + 1, 1, i);
1803  }
1804  }
1805  if (current->spatial_layer_description_present_flag) {
1806  for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++)
1807  fbs(8, spatial_layer_ref_id[i], 1, i);
1808  }
1809  if (current->temporal_group_description_present_flag) {
1810  fb(8, temporal_group_size);
1811  for (i = 0; i < current->temporal_group_size; i++) {
1812  fbs(3, temporal_group_temporal_id[i], 1, i);
1813  flags(temporal_group_temporal_switching_up_point_flag[i], 1, i);
1814  flags(temporal_group_spatial_switching_up_point_flag[i], 1, i);
1815  fbs(3, temporal_group_ref_cnt[i], 1, i);
1816  for (j = 0; j < current->temporal_group_ref_cnt[i]; j++) {
1817  fbs(8, temporal_group_ref_pic_diff[i][j], 2, i, j);
1818  }
1819  }
1820  }
1821 
1822  return 0;
1823 }
1824 
1826  AV1RawMetadataScalability *current)
1827 {
1828  int err;
1829 
1830  fb(8, scalability_mode_idc);
1831 
1832  if (current->scalability_mode_idc == AV1_SCALABILITY_SS)
1833  CHECK(FUNC(scalability_structure)(ctx, rw, current));
1834 
1835  return 0;
1836 }
1837 
1839  AV1RawMetadataITUTT35 *current)
1840 {
1841  int err;
1842  size_t i;
1843 
1844  fb(8, itu_t_t35_country_code);
1845  if (current->itu_t_t35_country_code == 0xff)
1846  fb(8, itu_t_t35_country_code_extension_byte);
1847 
1848 #ifdef READ
1849  // The payload runs up to the start of the trailing bits, but there might
1850  // be arbitrarily many trailing zeroes so we need to read through twice.
1851  current->payload_size = cbs_av1_get_payload_bytes_left(rw);
1852 
1853  current->payload_ref = av_buffer_alloc(current->payload_size);
1854  if (!current->payload_ref)
1855  return AVERROR(ENOMEM);
1856  current->payload = current->payload_ref->data;
1857 #endif
1858 
1859  for (i = 0; i < current->payload_size; i++)
1860  xf(8, itu_t_t35_payload_bytes[i], current->payload[i],
1861  0x00, 0xff, 1, i);
1862 
1863  return 0;
1864 }
1865 
1867  AV1RawMetadataTimecode *current)
1868 {
1869  int err;
1870 
1871  fb(5, counting_type);
1872  flag(full_timestamp_flag);
1873  flag(discontinuity_flag);
1874  flag(cnt_dropped_flag);
1875  fb(9, n_frames);
1876 
1877  if (current->full_timestamp_flag) {
1878  fc(6, seconds_value, 0, 59);
1879  fc(6, minutes_value, 0, 59);
1880  fc(5, hours_value, 0, 23);
1881  } else {
1882  flag(seconds_flag);
1883  if (current->seconds_flag) {
1884  fc(6, seconds_value, 0, 59);
1885  flag(minutes_flag);
1886  if (current->minutes_flag) {
1887  fc(6, minutes_value, 0, 59);
1888  flag(hours_flag);
1889  if (current->hours_flag)
1890  fc(5, hours_value, 0, 23);
1891  }
1892  }
1893  }
1894 
1895  fb(5, time_offset_length);
1896  if (current->time_offset_length > 0)
1897  fb(current->time_offset_length, time_offset_value);
1898  else
1899  infer(time_offset_length, 0);
1900 
1901  return 0;
1902 }
1903 
1905  AV1RawMetadata *current)
1906 {
1907  int err;
1908 
1909  leb128(metadata_type);
1910 
1911  switch (current->metadata_type) {
1913  CHECK(FUNC(metadata_hdr_cll)(ctx, rw, &current->metadata.hdr_cll));
1914  break;
1916  CHECK(FUNC(metadata_hdr_mdcv)(ctx, rw, &current->metadata.hdr_mdcv));
1917  break;
1919  CHECK(FUNC(metadata_scalability)(ctx, rw, &current->metadata.scalability));
1920  break;
1922  CHECK(FUNC(metadata_itut_t35)(ctx, rw, &current->metadata.itut_t35));
1923  break;
1925  CHECK(FUNC(metadata_timecode)(ctx, rw, &current->metadata.timecode));
1926  break;
1927  default:
1928  // Unknown metadata type.
1929  return AVERROR_PATCHWELCOME;
1930  }
1931 
1932  return 0;
1933 }
1934 
1936  AV1RawPadding *current)
1937 {
1938  int i, err;
1939 
1940  HEADER("Padding");
1941 
1942 #ifdef READ
1943  // The payload runs up to the start of the trailing bits, but there might
1944  // be arbitrarily many trailing zeroes so we need to read through twice.
1945  current->payload_size = cbs_av1_get_payload_bytes_left(rw);
1946 
1947  current->payload_ref = av_buffer_alloc(current->payload_size);
1948  if (!current->payload_ref)
1949  return AVERROR(ENOMEM);
1950  current->payload = current->payload_ref->data;
1951 #endif
1952 
1953  for (i = 0; i < current->payload_size; i++)
1954  xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i);
1955 
1956  return 0;
1957 }
AV1RawSequenceHeader::seq_force_integer_mv
uint8_t seq_force_integer_mv
Definition: cbs_av1.h:120
AV1_REFS_PER_FRAME
@ AV1_REFS_PER_FRAME
Definition: av1.h:84
tile_list_obu
static int FUNC() tile_list_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawTileList *current)
Definition: cbs_av1_syntax_template.c:1730
uncompressed_header
static int FUNC() uncompressed_header(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:1234
av_buffer_alloc
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:67
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
CodedBitstreamAV1Context::seen_frame_header
int seen_frame_header
Definition: cbs_av1.h:422
CodedBitstreamAV1Context::tile_cols
int tile_cols
Definition: cbs_av1.h:442
AV1RawSequenceHeader
Definition: cbs_av1.h:73
segmentation_params
static int FUNC() segmentation_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:722
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:89
subexp
#define subexp(name, max, subs,...)
Definition: cbs_av1.c:697
superres_params
static int FUNC() superres_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:452
AV1RawSequenceHeader::operating_point_idc
uint16_t operating_point_idc[AV1_MAX_OPERATING_POINTS]
Definition: cbs_av1.h:86
AV1RawPadding
Definition: cbs_av1.h:380
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
HEADER
#define HEADER(name)
Definition: cbs_av1.c:537
infer
#define infer(name, value)
Definition: cbs_av1.c:713
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
AV1_REF_FRAME_INTRA
@ AV1_REF_FRAME_INTRA
Definition: av1.h:61
sus
#define sus(width, name, subs,...)
Definition: cbs_av1.c:567
AV1_MAX_TILE_ROWS
@ AV1_MAX_TILE_ROWS
Definition: av1.h:80
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:168
CodedBitstreamAV1Context::frame_header_ref
AVBufferRef * frame_header_ref
Definition: cbs_av1.h:423
b
#define b
Definition: input.c:41
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:483
AV1RawSequenceHeader::timing_info
AV1RawTimingInfo timing_info
Definition: cbs_av1.h:83
AV1_SELECT_INTEGER_MV
@ AV1_SELECT_INTEGER_MV
Definition: av1.h:98
AV1RawSequenceHeader::frame_id_numbers_present_flag
uint8_t frame_id_numbers_present_flag
Definition: cbs_av1.h:101
CodedBitstreamAV1Context::frame_header_size
size_t frame_header_size
Definition: cbs_av1.h:425
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:510
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:555
quantization_params
static int FUNC() quantization_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:675
AV1RawSequenceHeader::decoder_model_info
AV1RawDecoderModelInfo decoder_model_info
Definition: cbs_av1.h:84
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
AV1ReferenceFrameState::order_hint
int order_hint
Definition: cbs_av1.h:415
AV1_GM_TRANS_ONLY_PREC_BITS
@ AV1_GM_TRANS_ONLY_PREC_BITS
Definition: av1.h:108
AV1RawColorConfig::subsampling_y
uint8_t subsampling_y
Definition: cbs_av1.h:53
AV1_WARP_MODEL_ROTZOOM
@ AV1_WARP_MODEL_ROTZOOM
Definition: av1.h:115
AV1RawColorConfig::separate_uv_delta_q
uint8_t separate_uv_delta_q
Definition: cbs_av1.h:55
tile_info
static int FUNC() tile_info(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:577
metadata_itut_t35
static int FUNC() metadata_itut_t35(CodedBitstreamContext *ctx, RWContext *rw, AV1RawMetadataITUTT35 *current)
Definition: cbs_av1_syntax_template.c:1838
AV1RawColorConfig
Definition: cbs_av1.h:41
AV1RawFrame
Definition: cbs_av1.h:299
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
AV1RawSequenceHeader::film_grain_params_present
uint8_t film_grain_params_present
Definition: cbs_av1.h:130
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:494
CHECK
CHECK(-1) CHECK(-2) }} }} CHECK(1) CHECK(2) }} }} } if(diff0+diff1 > 0) temp -
metadata_scalability
static int FUNC() metadata_scalability(CodedBitstreamContext *ctx, RWContext *rw, AV1RawMetadataScalability *current)
Definition: cbs_av1_syntax_template.c:1825
AV1_FRAME_SWITCH
@ AV1_FRAME_SWITCH
Definition: av1.h:56
AV1RawSequenceHeader::enable_ref_frame_mvs
uint8_t enable_ref_frame_mvs
Definition: cbs_av1.h:115
AV1_MAX_TILE_AREA
@ AV1_MAX_TILE_AREA
Definition: av1.h:79
read_tx_mode
static int FUNC() read_tx_mode(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:946
obu_header
static int FUNC() obu_header(CodedBitstreamContext *ctx, RWContext *rw, AV1RawOBUHeader *current)
Definition: cbs_av1_syntax_template.c:19
GetBitContext
Definition: get_bits.h:61
AV1RawSequenceHeader::decoder_model_present_for_this_op
uint8_t decoder_model_present_for_this_op[AV1_MAX_OPERATING_POINTS]
Definition: cbs_av1.h:89
scalability_structure
static int FUNC() scalability_structure(CodedBitstreamContext *ctx, RWContext *rw, AV1RawMetadataScalability *current)
Definition: cbs_av1_syntax_template.c:1778
AV1RawTileList
Definition: cbs_av1.h:304
AV1ReferenceFrameState::frame_id
int frame_id
Definition: cbs_av1.h:405
val
static double val(void *priv, double ch)
Definition: aeval.c:76
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
AV1RawSequenceHeader::delta_frame_id_length_minus_2
uint8_t delta_frame_id_length_minus_2
Definition: cbs_av1.h:102
global_motion_params
static int FUNC() global_motion_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:1083
AV1RawMetadataHDRMDCV
Definition: cbs_av1.h:317
skip_mode_params
static int FUNC() skip_mode_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:974
AV1ReferenceFrameState::valid
int valid
Definition: cbs_av1.h:404
AV1RawDecoderModelInfo::frame_presentation_time_length_minus_1
uint8_t frame_presentation_time_length_minus_1
Definition: cbs_av1.h:70
show_frame
static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, AVFormatContext *fmt_ctx)
Definition: ffprobe.c:2128
AV1_WARP_MODEL_AFFINE
@ AV1_WARP_MODEL_AFFINE
Definition: av1.h:116
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVFormatContext::metadata
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1575
AV1_GM_ABS_TRANS_BITS
@ AV1_GM_ABS_TRANS_BITS
Definition: av1.h:109
AV1_CSP_UNKNOWN
@ AV1_CSP_UNKNOWN
Definition: av1.h:125
interpolation_filter
static int FUNC() interpolation_filter(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:562
frame_size_with_refs
static int FUNC() frame_size_with_refs(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:523
CodedBitstreamAV1Context::frame_height
int frame_height
Definition: cbs_av1.h:434
AV1_PRIMARY_REF_NONE
@ AV1_PRIMARY_REF_NONE
Definition: av1.h:86
CodedBitstreamAV1Context::upscaled_width
int upscaled_width
Definition: cbs_av1.h:435
color_config
static int FUNC() color_config(CodedBitstreamContext *ctx, RWContext *rw, AV1RawColorConfig *current, int seq_profile)
Definition: cbs_av1_syntax_template.c:70
AV1_REF_FRAME_GOLDEN
@ AV1_REF_FRAME_GOLDEN
Definition: av1.h:65
bits
uint8_t bits
Definition: vp3data.h:202
AV1RawDecoderModelInfo
Definition: cbs_av1.h:66
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV1_GM_ALPHA_PREC_BITS
@ AV1_GM_ALPHA_PREC_BITS
Definition: av1.h:106
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV1_METADATA_TYPE_SCALABILITY
@ AV1_METADATA_TYPE_SCALABILITY
Definition: av1.h:46
AV1_METADATA_TYPE_HDR_MDCV
@ AV1_METADATA_TYPE_HDR_MDCV
Definition: av1.h:45
color_range
color_range
Definition: vf_selectivecolor.c:44
AV1_GM_ABS_ALPHA_BITS
@ AV1_GM_ABS_ALPHA_BITS
Definition: av1.h:105
MAX_UINT_BITS
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:98
AV1RawMetadataHDRCLL
Definition: cbs_av1.h:312
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:458
AV1_REF_FRAME_ALTREF
@ AV1_REF_FRAME_ALTREF
Definition: av1.h:68
PutBitContext
Definition: put_bits.h:35
AV1_MAX_SEGMENTS
@ AV1_MAX_SEGMENTS
Definition: av1.h:88
AV1_WARP_MODEL_TRANSLATION
@ AV1_WARP_MODEL_TRANSLATION
Definition: av1.h:114
AV1_SUPERRES_DENOM_MIN
@ AV1_SUPERRES_DENOM_MIN
Definition: av1.h:101
frame_size
static int FUNC() frame_size(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:478
leb128
#define leb128(name)
Definition: cbs_av1.c:709
AV1RawMetadata
Definition: cbs_av1.h:369
AV1_REF_FRAME_LAST
@ AV1_REF_FRAME_LAST
Definition: av1.h:62
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
AV1RawTimingInfo
Definition: cbs_av1.h:58
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:125
AV1RawMetadataScalability
Definition: cbs_av1.h:326
AV1RawFrameHeader
Definition: cbs_av1.h:133
fbs
#define fbs(width, name, subs,...)
Definition: cbs_av1.c:561
cbs_av1_get_payload_bytes_left
static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
Definition: cbs_av1.c:525
lr_params
static int FUNC() lr_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:905
AV1_GM_TRANS_PREC_BITS
@ AV1_GM_TRANS_PREC_BITS
Definition: av1.h:110
metadata_hdr_mdcv
static int FUNC() metadata_hdr_mdcv(CodedBitstreamContext *ctx, RWContext *rw, AV1RawMetadataHDRMDCV *current)
Definition: cbs_av1_syntax_template.c:1756
decoder_model_info
static int FUNC() decoder_model_info(CodedBitstreamContext *ctx, RWContext *rw, AV1RawDecoderModelInfo *current)
Definition: cbs_av1_syntax_template.c:166
delta_q
#define delta_q(name)
Definition: cbs_av1.c:703
delta_lf_params
static int FUNC() delta_lf_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:789
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:457
metadata_timecode
static int FUNC() metadata_timecode(CodedBitstreamContext *ctx, RWContext *rw, AV1RawMetadataTimecode *current)
Definition: cbs_av1_syntax_template.c:1866
AV1_METADATA_TYPE_ITUT_T35
@ AV1_METADATA_TYPE_ITUT_T35
Definition: av1.h:47
CodedBitstreamAV1Context::render_width
int render_width
Definition: cbs_av1.h:436
AV1_METADATA_TYPE_HDR_CLL
@ AV1_METADATA_TYPE_HDR_CLL
Definition: av1.h:44
sequence_header_obu
static int FUNC() sequence_header_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawSequenceHeader *current)
Definition: cbs_av1_syntax_template.c:179
AV1_MAX_TILE_COLS
@ AV1_MAX_TILE_COLS
Definition: av1.h:81
loop_filter_params
static int FUNC() loop_filter_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:815
AV1_INTERPOLATION_FILTER_SWITCHABLE
@ AV1_INTERPOLATION_FILTER_SWITCHABLE
Definition: av1.h:103
AV1RawSequenceHeader::seq_force_screen_content_tools
uint8_t seq_force_screen_content_tools
Definition: cbs_av1.h:118
render_size
static int FUNC() render_size(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:501
AV1RawSequenceHeader::max_frame_height_minus_1
uint16_t max_frame_height_minus_1
Definition: cbs_av1.h:99
frame_header_obu
static int FUNC() frame_header_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current, int redundant, AVBufferRef *rw_buffer_ref)
Definition: cbs_av1_syntax_template.c:1589
AV1_SELECT_SCREEN_CONTENT_TOOLS
@ AV1_SELECT_SCREEN_CONTENT_TOOLS
Definition: av1.h:97
FF_PROFILE_AV1_MAIN
#define FF_PROFILE_AV1_MAIN
Definition: avcodec.h:1952
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
AV1_TOTAL_REFS_PER_FRAME
@ AV1_TOTAL_REFS_PER_FRAME
Definition: av1.h:85
frame_reference_mode
static int FUNC() frame_reference_mode(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:960
fcs
#define fcs(width, name, range_min, range_max, subs,...)
Definition: cbs_av1.c:563
AV1RawSequenceHeader::use_128x128_superblock
uint8_t use_128x128_superblock
Definition: cbs_av1.h:105
CodedBitstreamAV1Context::tile_rows
int tile_rows
Definition: cbs_av1.h:443
AV1RawSequenceHeader::frame_height_bits_minus_1
uint8_t frame_height_bits_minus_1
Definition: cbs_av1.h:97
CodedBitstreamAV1Context::frame_header
uint8_t * frame_header
Definition: cbs_av1.h:424
transfer_characteristics
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
Definition: vf_colorspace.c:176
frame_obu
static int FUNC() frame_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrame *current, AVBufferRef *rw_buffer_ref)
Definition: cbs_av1_syntax_template.c:1714
AV1_GM_ABS_TRANS_ONLY_BITS
@ AV1_GM_ABS_TRANS_ONLY_BITS
Definition: av1.h:107
AV1_REF_FRAME_LAST2
@ AV1_REF_FRAME_LAST2
Definition: av1.h:63
AV1ReferenceFrameState
Definition: cbs_av1.h:403
AV1_FRAME_INTRA_ONLY
@ AV1_FRAME_INTRA_ONLY
Definition: av1.h:55
AV1_FRAME_KEY
@ AV1_FRAME_KEY
Definition: av1.h:53
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
AV1_SCALABILITY_SS
@ AV1_SCALABILITY_SS
Definition: av1.h:146
ns
#define ns(max_value, name, subs,...)
Definition: cbs_av1.c:686
metadata_hdr_cll
static int FUNC() metadata_hdr_cll(CodedBitstreamContext *ctx, RWContext *rw, AV1RawMetadataHDRCLL *current)
Definition: cbs_av1_syntax_template.c:1745
CodedBitstreamAV1Context::frame_width
int frame_width
Definition: cbs_av1.h:433
CodedBitstreamAV1Context::order_hint
int order_hint
Definition: cbs_av1.h:432
AV1_NUM_REF_FRAMES
@ AV1_NUM_REF_FRAMES
Definition: av1.h:83
flag
#define flag(name)
Definition: cbs_av1.c:557
cbs_av1_tile_log2
static int cbs_av1_tile_log2(int blksize, int target)
Definition: cbs_av1.c:506
CodedBitstreamAV1Context::spatial_id
int spatial_id
Definition: cbs_av1.h:428
CodedBitstreamAV1Context::coded_lossless
int coded_lossless
Definition: cbs_av1.h:440
AV1_OBU_PADDING
@ AV1_OBU_PADDING
Definition: av1.h:39
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
put_bits_count
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:67
frame_type
frame_type
Definition: jpeg2000_parser.c:31
AV1RawSequenceHeader::enable_superres
uint8_t enable_superres
Definition: cbs_av1.h:124
CodedBitstreamAV1Context::bit_depth
int bit_depth
Definition: cbs_av1.h:431
increment
#define increment(name, min, max)
Definition: cbs_av1.c:692
AV1RawTimingInfo::equal_picture_interval
uint8_t equal_picture_interval
Definition: cbs_av1.h:62
fb
#define fb(width, name)
Definition: cbs_av1.c:553
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:668
uint8_t
uint8_t
Definition: audio_convert.c:194
AV1RawSequenceHeader::max_frame_width_minus_1
uint16_t max_frame_width_minus_1
Definition: cbs_av1.h:98
AV1RawSequenceHeader::color_config
AV1RawColorConfig color_config
Definition: cbs_av1.h:128
AV1_SEG_LVL_MAX
@ AV1_SEG_LVL_MAX
Definition: av1.h:89
film_grain_params
static int FUNC() film_grain_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:1128
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:512
AV1RawSequenceHeader::enable_order_hint
uint8_t enable_order_hint
Definition: cbs_av1.h:113
FF_PROFILE_AV1_PROFESSIONAL
#define FF_PROFILE_AV1_PROFESSIONAL
Definition: avcodec.h:1954
byte_alignment
static int FUNC() byte_alignment(CodedBitstreamContext *ctx, RWContext *rw)
Definition: cbs_av1_syntax_template.c:60
tile_group_obu
static int FUNC() tile_group_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawTileGroup *current)
Definition: cbs_av1_syntax_template.c:1678
AV1RawColorConfig::subsampling_x
uint8_t subsampling_x
Definition: cbs_av1.h:52
AV1RawDecoderModelInfo::buffer_removal_time_length_minus_1
uint8_t buffer_removal_time_length_minus_1
Definition: cbs_av1.h:69
AV1_MAX_TILE_WIDTH
@ AV1_MAX_TILE_WIDTH
Definition: av1.h:78
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:215
cbs_av1_get_relative_dist
static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
Definition: cbs_av1.c:513
CodedBitstreamAV1Context::all_lossless
int all_lossless
Definition: cbs_av1.h:441
AV1RawMetadataITUTT35
Definition: cbs_av1.h:344
AV1RawSequenceHeader::frame_width_bits_minus_1
uint8_t frame_width_bits_minus_1
Definition: cbs_av1.h:96
AV1RawSequenceHeader::enable_warped_motion
uint8_t enable_warped_motion
Definition: cbs_av1.h:110
CodedBitstreamAV1Context::ref
AV1ReferenceFrameState * ref
Definition: cbs_av1.h:445
CodedBitstreamAV1Context::sequence_header
AV1RawSequenceHeader * sequence_header
Definition: cbs_av1.h:419
CodedBitstreamAV1Context::render_height
int render_height
Definition: cbs_av1.h:437
FUNC
#define FUNC(a)
Definition: bit_depth_template.c:104
AV1RawColorConfig::mono_chrome
uint8_t mono_chrome
Definition: cbs_av1.h:44
AV1_REF_FRAME_ALTREF2
@ AV1_REF_FRAME_ALTREF2
Definition: av1.h:67
set_frame_refs
static int FUNC() set_frame_refs(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:341
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AV1_REF_FRAME_LAST3
@ AV1_REF_FRAME_LAST3
Definition: av1.h:64
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
CodedBitstreamAV1Context::num_planes
int num_planes
Definition: cbs_av1.h:439
AV1RawSequenceHeader::order_hint_bits_minus_1
uint8_t order_hint_bits_minus_1
Definition: cbs_av1.h:122
AV1RawMetadataTimecode
Definition: cbs_av1.h:353
uvlc
#define uvlc(name, range_min, range_max)
Definition: cbs_av1.c:681
AV1RawTileGroup
Definition: cbs_av1.h:291
cdef_params
static int FUNC() cdef_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:870
global_motion_param
static int FUNC() global_motion_param(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current, int type, int ref, int idx)
Definition: cbs_av1_syntax_template.c:1054
temporal_delimiter_obu
static int FUNC() temporal_delimiter_obu(CodedBitstreamContext *ctx, RWContext *rw)
Definition: cbs_av1_syntax_template.c:330
trailing_bits
static int FUNC() trailing_bits(CodedBitstreamContext *ctx, RWContext *rw, int nb_bits)
Definition: cbs_av1_syntax_template.c:43
padding_obu
static int FUNC() padding_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawPadding *current)
Definition: cbs_av1_syntax_template.c:1935
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:81
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:101
AV1RawSequenceHeader::enable_restoration
uint8_t enable_restoration
Definition: cbs_av1.h:126
update_refs
static void update_refs(VP8Context *s)
Definition: vp8.c:466
timing_info
static int FUNC() timing_info(CodedBitstreamContext *ctx, RWContext *rw, AV1RawTimingInfo *current)
Definition: cbs_av1_syntax_template.c:151
AV1RawSequenceHeader::operating_points_cnt_minus_1
uint8_t operating_points_cnt_minus_1
Definition: cbs_av1.h:81
AV1RawSequenceHeader::additional_frame_id_length_minus_1
uint8_t additional_frame_id_length_minus_1
Definition: cbs_av1.h:103
AV1RawSequenceHeader::enable_cdef
uint8_t enable_cdef
Definition: cbs_av1.h:125
AV1RawSequenceHeader::reduced_still_picture_header
uint8_t reduced_still_picture_header
Definition: cbs_av1.h:76
fixed
#define fixed(width, name, value)
Definition: cbs_av1.c:570
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AV1_WARP_MODEL_IDENTITY
@ AV1_WARP_MODEL_IDENTITY
Definition: av1.h:113
AV1_SEG_LVL_ALT_Q
@ AV1_SEG_LVL_ALT_Q
Definition: av1.h:91
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
FF_PROFILE_AV1_HIGH
#define FF_PROFILE_AV1_HIGH
Definition: avcodec.h:1953
AV1_FRAME_INTER
@ AV1_FRAME_INTER
Definition: av1.h:54
RWContext
#define RWContext
Definition: cbs_av1.c:666
AV1RawOBUHeader
Definition: cbs_av1.h:29
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1363
color_primaries
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
Definition: vf_colorspace.c:209
delta_q_params
static int FUNC() delta_q_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
Definition: cbs_av1_syntax_template.c:773
AV1_METADATA_TYPE_TIMECODE
@ AV1_METADATA_TYPE_TIMECODE
Definition: av1.h:48
AV1_REF_FRAME_BWDREF
@ AV1_REF_FRAME_BWDREF
Definition: av1.h:66
metadata_obu
static int FUNC() metadata_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawMetadata *current)
Definition: cbs_av1_syntax_template.c:1904
AV1_SUPERRES_NUM
@ AV1_SUPERRES_NUM
Definition: av1.h:100
AV1RawSequenceHeader::decoder_model_info_present_flag
uint8_t decoder_model_info_present_flag
Definition: cbs_av1.h:79
CodedBitstreamAV1Context::temporal_id
int temporal_id
Definition: cbs_av1.h:427
CodedBitstreamAV1Context
Definition: cbs_av1.h:418
AV1_CSP_COLOCATED
@ AV1_CSP_COLOCATED
Definition: av1.h:127