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