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