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 == FF_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 == FF_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 == FF_PROFILE_AV1_MAIN) {
130  infer(subsampling_x, 1);
131  infer(subsampling_y, 1);
132  } else if (seq_profile == FF_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  fb(32, num_units_in_decoding_tick);
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, FF_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  int8_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] = -1;
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 
381  ref = -1;
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 
395  ref = -1;
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 
409  ref = -1;
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 ) {
426  ref = -1;
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 
442  ref = -1;
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  current->tile_cols = (sb_cols + tile_width_sb - 1) / tile_width_sb;
630 
631  min_log2_tile_rows = FFMAX(min_log2_tiles - current->tile_cols_log2, 0);
632 
633  increment(tile_rows_log2, min_log2_tile_rows, max_log2_tile_rows);
634 
635  tile_height_sb = (sb_rows + (1 << current->tile_rows_log2) - 1) >>
636  current->tile_rows_log2;
637  current->tile_rows = (sb_rows + tile_height_sb - 1) / tile_height_sb;
638 
639  for (i = 0; i < current->tile_cols - 1; i++)
640  infer(width_in_sbs_minus_1[i], tile_width_sb - 1);
641  infer(width_in_sbs_minus_1[i],
642  sb_cols - (current->tile_cols - 1) * tile_width_sb - 1);
643  for (i = 0; i < current->tile_rows - 1; i++)
644  infer(height_in_sbs_minus_1[i], tile_height_sb - 1);
645  infer(height_in_sbs_minus_1[i],
646  sb_rows - (current->tile_rows - 1) * tile_height_sb - 1);
647 
648  } else {
649  int widest_tile_sb, start_sb, size_sb, max_width, max_height;
650 
651  widest_tile_sb = 0;
652 
653  start_sb = 0;
654  for (i = 0; start_sb < sb_cols && i < AV1_MAX_TILE_COLS; i++) {
655  max_width = FFMIN(sb_cols - start_sb, max_tile_width_sb);
656  ns(max_width, width_in_sbs_minus_1[i], 1, i);
657  size_sb = current->width_in_sbs_minus_1[i] + 1;
658  widest_tile_sb = FFMAX(size_sb, widest_tile_sb);
659  start_sb += size_sb;
660  }
661  current->tile_cols_log2 = cbs_av1_tile_log2(1, i);
662  current->tile_cols = i;
663 
664  if (min_log2_tiles > 0)
665  max_tile_area_sb = (sb_rows * sb_cols) >> (min_log2_tiles + 1);
666  else
667  max_tile_area_sb = sb_rows * sb_cols;
668  max_tile_height_sb = FFMAX(max_tile_area_sb / widest_tile_sb, 1);
669 
670  start_sb = 0;
671  for (i = 0; start_sb < sb_rows && i < AV1_MAX_TILE_ROWS; i++) {
672  max_height = FFMIN(sb_rows - start_sb, max_tile_height_sb);
673  ns(max_height, height_in_sbs_minus_1[i], 1, i);
674  size_sb = current->height_in_sbs_minus_1[i] + 1;
675  start_sb += size_sb;
676  }
677  current->tile_rows_log2 = cbs_av1_tile_log2(1, i);
678  current->tile_rows = i;
679  }
680 
681  if (current->tile_cols_log2 > 0 ||
682  current->tile_rows_log2 > 0) {
683  fb(current->tile_cols_log2 + current->tile_rows_log2,
684  context_update_tile_id);
685  fb(2, tile_size_bytes_minus1);
686  } else {
687  infer(context_update_tile_id, 0);
688  }
689 
690  priv->tile_cols = current->tile_cols;
691  priv->tile_rows = current->tile_rows;
692 
693  return 0;
694 }
695 
697  AV1RawFrameHeader *current)
698 {
700  const AV1RawSequenceHeader *seq = priv->sequence_header;
701  int err;
702 
703  fb(8, base_q_idx);
704 
705  delta_q(delta_q_y_dc);
706 
707  if (priv->num_planes > 1) {
709  flag(diff_uv_delta);
710  else
711  infer(diff_uv_delta, 0);
712 
713  delta_q(delta_q_u_dc);
714  delta_q(delta_q_u_ac);
715 
716  if (current->diff_uv_delta) {
717  delta_q(delta_q_v_dc);
718  delta_q(delta_q_v_ac);
719  } else {
720  infer(delta_q_v_dc, current->delta_q_u_dc);
721  infer(delta_q_v_ac, current->delta_q_u_ac);
722  }
723  } else {
724  infer(delta_q_u_dc, 0);
725  infer(delta_q_u_ac, 0);
726  infer(delta_q_v_dc, 0);
727  infer(delta_q_v_ac, 0);
728  }
729 
730  flag(using_qmatrix);
731  if (current->using_qmatrix) {
732  fb(4, qm_y);
733  fb(4, qm_u);
735  fb(4, qm_v);
736  else
737  infer(qm_v, current->qm_u);
738  }
739 
740  return 0;
741 }
742 
744  AV1RawFrameHeader *current)
745 {
747  static const uint8_t bits[AV1_SEG_LVL_MAX] = { 8, 6, 6, 6, 6, 3, 0, 0 };
748  static const uint8_t sign[AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 };
749  static const uint8_t default_feature_enabled[AV1_SEG_LVL_MAX] = { 0 };
750  static const int16_t default_feature_value[AV1_SEG_LVL_MAX] = { 0 };
751  int i, j, err;
752 
753  flag(segmentation_enabled);
754 
755  if (current->segmentation_enabled) {
756  if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
757  infer(segmentation_update_map, 1);
758  infer(segmentation_temporal_update, 0);
759  infer(segmentation_update_data, 1);
760  } else {
761  flag(segmentation_update_map);
762  if (current->segmentation_update_map)
763  flag(segmentation_temporal_update);
764  else
765  infer(segmentation_temporal_update, 0);
766  flag(segmentation_update_data);
767  }
768 
769  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
770  const uint8_t *ref_feature_enabled;
771  const int16_t *ref_feature_value;
772 
773  if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
774  ref_feature_enabled = default_feature_enabled;
775  ref_feature_value = default_feature_value;
776  } else {
777  ref_feature_enabled =
778  priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_enabled[i];
779  ref_feature_value =
780  priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_value[i];
781  }
782 
783  for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
784  if (current->segmentation_update_data) {
785  flags(feature_enabled[i][j], 2, i, j);
786 
787  if (current->feature_enabled[i][j] && bits[j] > 0) {
788  if (sign[j])
789  sus(1 + bits[j], feature_value[i][j], 2, i, j);
790  else
791  fbs(bits[j], feature_value[i][j], 2, i, j);
792  } else {
793  infer(feature_value[i][j], 0);
794  }
795  } else {
796  infer(feature_enabled[i][j], ref_feature_enabled[j]);
797  infer(feature_value[i][j], ref_feature_value[j]);
798  }
799  }
800  }
801  } else {
802  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
803  for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
804  infer(feature_enabled[i][j], 0);
805  infer(feature_value[i][j], 0);
806  }
807  }
808  }
809 
810  return 0;
811 }
812 
814  AV1RawFrameHeader *current)
815 {
816  int err;
817 
818  if (current->base_q_idx > 0)
819  flag(delta_q_present);
820  else
821  infer(delta_q_present, 0);
822 
823  if (current->delta_q_present)
824  fb(2, delta_q_res);
825 
826  return 0;
827 }
828 
830  AV1RawFrameHeader *current)
831 {
832  int err;
833 
834  if (current->delta_q_present) {
835  if (!current->allow_intrabc)
836  flag(delta_lf_present);
837  else
838  infer(delta_lf_present, 0);
839  if (current->delta_lf_present) {
840  fb(2, delta_lf_res);
841  flag(delta_lf_multi);
842  } else {
843  infer(delta_lf_res, 0);
844  infer(delta_lf_multi, 0);
845  }
846  } else {
847  infer(delta_lf_present, 0);
848  infer(delta_lf_res, 0);
849  infer(delta_lf_multi, 0);
850  }
851 
852  return 0;
853 }
854 
856  AV1RawFrameHeader *current)
857 {
859  static const int8_t default_loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME] =
860  { 1, 0, 0, 0, -1, 0, -1, -1 };
861  static const int8_t default_loop_filter_mode_deltas[2] = { 0, 0 };
862  int i, err;
863 
864  if (priv->coded_lossless || current->allow_intrabc) {
865  infer(loop_filter_level[0], 0);
866  infer(loop_filter_level[1], 0);
867  infer(loop_filter_ref_deltas[AV1_REF_FRAME_INTRA], 1);
868  infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST], 0);
869  infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST2], 0);
870  infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST3], 0);
871  infer(loop_filter_ref_deltas[AV1_REF_FRAME_BWDREF], 0);
872  infer(loop_filter_ref_deltas[AV1_REF_FRAME_GOLDEN], -1);
873  infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF], -1);
874  infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF2], -1);
875  for (i = 0; i < 2; i++)
876  infer(loop_filter_mode_deltas[i], 0);
877  return 0;
878  }
879 
880  fb(6, loop_filter_level[0]);
881  fb(6, loop_filter_level[1]);
882 
883  if (priv->num_planes > 1) {
884  if (current->loop_filter_level[0] ||
885  current->loop_filter_level[1]) {
886  fb(6, loop_filter_level[2]);
887  fb(6, loop_filter_level[3]);
888  }
889  }
890 
891  fb(3, loop_filter_sharpness);
892 
893  flag(loop_filter_delta_enabled);
894  if (current->loop_filter_delta_enabled) {
895  const int8_t *ref_loop_filter_ref_deltas, *ref_loop_filter_mode_deltas;
896 
897  if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
898  ref_loop_filter_ref_deltas = default_loop_filter_ref_deltas;
899  ref_loop_filter_mode_deltas = default_loop_filter_mode_deltas;
900  } else {
901  ref_loop_filter_ref_deltas =
902  priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_ref_deltas;
903  ref_loop_filter_mode_deltas =
904  priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_mode_deltas;
905  }
906 
907  flag(loop_filter_delta_update);
908  for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) {
909  if (current->loop_filter_delta_update)
910  flags(update_ref_delta[i], 1, i);
911  else
912  infer(update_ref_delta[i], 0);
913  if (current->update_ref_delta[i])
914  sus(1 + 6, loop_filter_ref_deltas[i], 1, i);
915  else
916  infer(loop_filter_ref_deltas[i], ref_loop_filter_ref_deltas[i]);
917  }
918  for (i = 0; i < 2; i++) {
919  if (current->loop_filter_delta_update)
920  flags(update_mode_delta[i], 1, i);
921  else
922  infer(update_mode_delta[i], 0);
923  if (current->update_mode_delta[i])
924  sus(1 + 6, loop_filter_mode_deltas[i], 1, i);
925  else
926  infer(loop_filter_mode_deltas[i], ref_loop_filter_mode_deltas[i]);
927  }
928  } else {
929  for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++)
930  infer(loop_filter_ref_deltas[i], default_loop_filter_ref_deltas[i]);
931  for (i = 0; i < 2; i++)
932  infer(loop_filter_mode_deltas[i], default_loop_filter_mode_deltas[i]);
933  }
934 
935  return 0;
936 }
937 
939  AV1RawFrameHeader *current)
940 {
942  const AV1RawSequenceHeader *seq = priv->sequence_header;
943  int i, err;
944 
945  if (priv->coded_lossless || current->allow_intrabc ||
946  !seq->enable_cdef) {
947  infer(cdef_damping_minus_3, 0);
948  infer(cdef_bits, 0);
949  infer(cdef_y_pri_strength[0], 0);
950  infer(cdef_y_sec_strength[0], 0);
951  infer(cdef_uv_pri_strength[0], 0);
952  infer(cdef_uv_sec_strength[0], 0);
953 
954  return 0;
955  }
956 
957  fb(2, cdef_damping_minus_3);
958  fb(2, cdef_bits);
959 
960  for (i = 0; i < (1 << current->cdef_bits); i++) {
961  fbs(4, cdef_y_pri_strength[i], 1, i);
962  fbs(2, cdef_y_sec_strength[i], 1, i);
963 
964  if (priv->num_planes > 1) {
965  fbs(4, cdef_uv_pri_strength[i], 1, i);
966  fbs(2, cdef_uv_sec_strength[i], 1, i);
967  }
968  }
969 
970  return 0;
971 }
972 
974  AV1RawFrameHeader *current)
975 {
977  const AV1RawSequenceHeader *seq = priv->sequence_header;
978  int uses_lr, uses_chroma_lr;
979  int i, err;
980 
981  if (priv->all_lossless || current->allow_intrabc ||
982  !seq->enable_restoration) {
983  return 0;
984  }
985 
986  uses_lr = uses_chroma_lr = 0;
987  for (i = 0; i < priv->num_planes; i++) {
988  fbs(2, lr_type[i], 1, i);
989 
990  if (current->lr_type[i] != AV1_RESTORE_NONE) {
991  uses_lr = 1;
992  if (i > 0)
993  uses_chroma_lr = 1;
994  }
995  }
996 
997  if (uses_lr) {
998  if (seq->use_128x128_superblock)
999  increment(lr_unit_shift, 1, 2);
1000  else
1001  increment(lr_unit_shift, 0, 2);
1002 
1003  if(seq->color_config.subsampling_x &&
1004  seq->color_config.subsampling_y && uses_chroma_lr) {
1005  fb(1, lr_uv_shift);
1006  } else {
1007  infer(lr_uv_shift, 0);
1008  }
1009  }
1010 
1011  return 0;
1012 }
1013 
1015  AV1RawFrameHeader *current)
1016 {
1018  int err;
1019 
1020  if (priv->coded_lossless)
1021  infer(tx_mode, 0);
1022  else
1023  increment(tx_mode, 1, 2);
1024 
1025  return 0;
1026 }
1027 
1029  AV1RawFrameHeader *current)
1030 {
1031  int err;
1032 
1033  if (current->frame_type == AV1_FRAME_INTRA_ONLY ||
1034  current->frame_type == AV1_FRAME_KEY)
1035  infer(reference_select, 0);
1036  else
1037  flag(reference_select);
1038 
1039  return 0;
1040 }
1041 
1043  AV1RawFrameHeader *current)
1044 {
1046  const AV1RawSequenceHeader *seq = priv->sequence_header;
1047  int skip_mode_allowed;
1048  int err;
1049 
1050  if (current->frame_type == AV1_FRAME_KEY ||
1051  current->frame_type == AV1_FRAME_INTRA_ONLY ||
1052  !current->reference_select || !seq->enable_order_hint) {
1053  skip_mode_allowed = 0;
1054  } else {
1055  int forward_idx, backward_idx;
1056  int forward_hint, backward_hint;
1057  int ref_hint, dist, i;
1058 
1059  forward_idx = -1;
1060  backward_idx = -1;
1061  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1062  ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint;
1063  dist = cbs_av1_get_relative_dist(seq, ref_hint,
1064  priv->order_hint);
1065  if (dist < 0) {
1066  if (forward_idx < 0 ||
1067  cbs_av1_get_relative_dist(seq, ref_hint,
1068  forward_hint) > 0) {
1069  forward_idx = i;
1070  forward_hint = ref_hint;
1071  }
1072  } else if (dist > 0) {
1073  if (backward_idx < 0 ||
1074  cbs_av1_get_relative_dist(seq, ref_hint,
1075  backward_hint) < 0) {
1076  backward_idx = i;
1077  backward_hint = ref_hint;
1078  }
1079  }
1080  }
1081 
1082  if (forward_idx < 0) {
1083  skip_mode_allowed = 0;
1084  } else if (backward_idx >= 0) {
1085  skip_mode_allowed = 1;
1086  // Frames for skip mode are forward_idx and backward_idx.
1087  } else {
1088  int second_forward_idx;
1089  int second_forward_hint;
1090 
1091  second_forward_idx = -1;
1092  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1093  ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint;
1094  if (cbs_av1_get_relative_dist(seq, ref_hint,
1095  forward_hint) < 0) {
1096  if (second_forward_idx < 0 ||
1097  cbs_av1_get_relative_dist(seq, ref_hint,
1098  second_forward_hint) > 0) {
1099  second_forward_idx = i;
1100  second_forward_hint = ref_hint;
1101  }
1102  }
1103  }
1104 
1105  if (second_forward_idx < 0) {
1106  skip_mode_allowed = 0;
1107  } else {
1108  skip_mode_allowed = 1;
1109  // Frames for skip mode are forward_idx and second_forward_idx.
1110  }
1111  }
1112  }
1113 
1114  if (skip_mode_allowed)
1115  flag(skip_mode_present);
1116  else
1117  infer(skip_mode_present, 0);
1118 
1119  return 0;
1120 }
1121 
1123  AV1RawFrameHeader *current,
1124  int type, int ref, int idx)
1125 {
1126  uint32_t abs_bits, prec_bits, num_syms;
1127  int err;
1128 
1129  if (idx < 2) {
1131  abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS - !current->allow_high_precision_mv;
1132  prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS - !current->allow_high_precision_mv;
1133  } else {
1134  abs_bits = AV1_GM_ABS_TRANS_BITS;
1135  prec_bits = AV1_GM_TRANS_PREC_BITS;
1136  }
1137  } else {
1138  abs_bits = AV1_GM_ABS_ALPHA_BITS;
1139  prec_bits = AV1_GM_ALPHA_PREC_BITS;
1140  }
1141 
1142  num_syms = 2 * (1 << abs_bits) + 1;
1143  subexp(gm_params[ref][idx], num_syms, 2, ref, idx);
1144 
1145  // Actual gm_params value is not reconstructed here.
1146  (void)prec_bits;
1147 
1148  return 0;
1149 }
1150 
1152  AV1RawFrameHeader *current)
1153 {
1154  int ref, type;
1155  int err;
1156 
1157  if (current->frame_type == AV1_FRAME_KEY ||
1158  current->frame_type == AV1_FRAME_INTRA_ONLY)
1159  return 0;
1160 
1161  for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) {
1162  flags(is_global[ref], 1, ref);
1163  if (current->is_global[ref]) {
1164  flags(is_rot_zoom[ref], 1, ref);
1165  if (current->is_rot_zoom[ref]) {
1166  type = AV1_WARP_MODEL_ROTZOOM;
1167  } else {
1168  flags(is_translation[ref], 1, ref);
1169  type = current->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
1171  }
1172  } else {
1173  type = AV1_WARP_MODEL_IDENTITY;
1174  }
1175 
1176  if (type >= AV1_WARP_MODEL_ROTZOOM) {
1177  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 2));
1178  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 3));
1179  if (type == AV1_WARP_MODEL_AFFINE) {
1180  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 4));
1181  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 5));
1182  } else {
1183  // gm_params[ref][4] = -gm_params[ref][3]
1184  // gm_params[ref][5] = gm_params[ref][2]
1185  }
1186  }
1187  if (type >= AV1_WARP_MODEL_TRANSLATION) {
1188  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 0));
1189  CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 1));
1190  }
1191  }
1192 
1193  return 0;
1194 }
1195 
1197  AV1RawFrameHeader *current)
1198 {
1200  const AV1RawSequenceHeader *seq = priv->sequence_header;
1201  int num_pos_luma, num_pos_chroma;
1202  int i, err;
1203 
1204  if (!seq->film_grain_params_present ||
1205  (!current->show_frame && !current->showable_frame))
1206  return 0;
1207 
1208  flag(apply_grain);
1209 
1210  if (!current->apply_grain)
1211  return 0;
1212 
1213  fb(16, grain_seed);
1214 
1215  if (current->frame_type == AV1_FRAME_INTER)
1216  flag(update_grain);
1217  else
1218  infer(update_grain, 1);
1219 
1220  if (!current->update_grain) {
1221  fb(3, film_grain_params_ref_idx);
1222  return 0;
1223  }
1224 
1225  fc(4, num_y_points, 0, 14);
1226  for (i = 0; i < current->num_y_points; i++) {
1227  fcs(8, point_y_value[i],
1228  i ? current->point_y_value[i - 1] + 1 : 0,
1229  MAX_UINT_BITS(8) - (current->num_y_points - i - 1),
1230  1, i);
1231  fbs(8, point_y_scaling[i], 1, i);
1232  }
1233 
1234  if (seq->color_config.mono_chrome)
1235  infer(chroma_scaling_from_luma, 0);
1236  else
1237  flag(chroma_scaling_from_luma);
1238 
1239  if (seq->color_config.mono_chrome ||
1240  current->chroma_scaling_from_luma ||
1241  (seq->color_config.subsampling_x == 1 &&
1242  seq->color_config.subsampling_y == 1 &&
1243  current->num_y_points == 0)) {
1244  infer(num_cb_points, 0);
1245  infer(num_cr_points, 0);
1246  } else {
1247  fc(4, num_cb_points, 0, 10);
1248  for (i = 0; i < current->num_cb_points; i++) {
1249  fcs(8, point_cb_value[i],
1250  i ? current->point_cb_value[i - 1] + 1 : 0,
1251  MAX_UINT_BITS(8) - (current->num_cb_points - i - 1),
1252  1, i);
1253  fbs(8, point_cb_scaling[i], 1, i);
1254  }
1255  fc(4, num_cr_points, 0, 10);
1256  for (i = 0; i < current->num_cr_points; i++) {
1257  fcs(8, point_cr_value[i],
1258  i ? current->point_cr_value[i - 1] + 1 : 0,
1259  MAX_UINT_BITS(8) - (current->num_cr_points - i - 1),
1260  1, i);
1261  fbs(8, point_cr_scaling[i], 1, i);
1262  }
1263  }
1264 
1265  fb(2, grain_scaling_minus_8);
1266  fb(2, ar_coeff_lag);
1267  num_pos_luma = 2 * current->ar_coeff_lag * (current->ar_coeff_lag + 1);
1268  if (current->num_y_points) {
1269  num_pos_chroma = num_pos_luma + 1;
1270  for (i = 0; i < num_pos_luma; i++)
1271  fbs(8, ar_coeffs_y_plus_128[i], 1, i);
1272  } else {
1273  num_pos_chroma = num_pos_luma;
1274  }
1275  if (current->chroma_scaling_from_luma || current->num_cb_points) {
1276  for (i = 0; i < num_pos_chroma; i++)
1277  fbs(8, ar_coeffs_cb_plus_128[i], 1, i);
1278  }
1279  if (current->chroma_scaling_from_luma || current->num_cr_points) {
1280  for (i = 0; i < num_pos_chroma; i++)
1281  fbs(8, ar_coeffs_cr_plus_128[i], 1, i);
1282  }
1283  fb(2, ar_coeff_shift_minus_6);
1284  fb(2, grain_scale_shift);
1285  if (current->num_cb_points) {
1286  fb(8, cb_mult);
1287  fb(8, cb_luma_mult);
1288  fb(9, cb_offset);
1289  }
1290  if (current->num_cr_points) {
1291  fb(8, cr_mult);
1292  fb(8, cr_luma_mult);
1293  fb(9, cr_offset);
1294  }
1295 
1296  flag(overlap_flag);
1297  flag(clip_to_restricted_range);
1298 
1299  return 0;
1300 }
1301 
1303  AV1RawFrameHeader *current)
1304 {
1306  const AV1RawSequenceHeader *seq;
1307  int id_len, diff_len, all_frames, frame_is_intra, order_hint_bits;
1308  int i, err;
1309 
1310  if (!priv->sequence_header) {
1311  av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: "
1312  "unable to decode frame header.\n");
1313  return AVERROR_INVALIDDATA;
1314  }
1315  seq = priv->sequence_header;
1316 
1317  id_len = seq->additional_frame_id_length_minus_1 +
1319  all_frames = (1 << AV1_NUM_REF_FRAMES) - 1;
1320 
1321  if (seq->reduced_still_picture_header) {
1322  infer(show_existing_frame, 0);
1324  infer(show_frame, 1);
1325  infer(showable_frame, 0);
1326  frame_is_intra = 1;
1327 
1328  } else {
1329  flag(show_existing_frame);
1330 
1331  if (current->show_existing_frame) {
1333 
1334  fb(3, frame_to_show_map_idx);
1335  ref = &priv->ref[current->frame_to_show_map_idx];
1336 
1337  if (!ref->valid) {
1338  av_log(ctx->log_ctx, AV_LOG_ERROR, "Missing reference frame needed for "
1339  "show_existing_frame (frame_to_show_map_idx = %d).\n",
1340  current->frame_to_show_map_idx);
1341  return AVERROR_INVALIDDATA;
1342  }
1343 
1347  frame_presentation_time);
1348  }
1349 
1351  fb(id_len, display_frame_id);
1352 
1353  infer(frame_type, ref->frame_type);
1354  if (current->frame_type == AV1_FRAME_KEY) {
1355  infer(refresh_frame_flags, all_frames);
1356 
1357  // Section 7.21
1358  infer(current_frame_id, ref->frame_id);
1359  priv->upscaled_width = ref->upscaled_width;
1360  priv->frame_width = ref->frame_width;
1361  priv->frame_height = ref->frame_height;
1362  priv->render_width = ref->render_width;
1363  priv->render_height = ref->render_height;
1364  priv->bit_depth = ref->bit_depth;
1365  priv->order_hint = ref->order_hint;
1366  } else
1367  infer(refresh_frame_flags, 0);
1368 
1369  infer(frame_width_minus_1, ref->upscaled_width - 1);
1370  infer(frame_height_minus_1, ref->frame_height - 1);
1371  infer(render_width_minus_1, ref->render_width - 1);
1372  infer(render_height_minus_1, ref->render_height - 1);
1373 
1374  // Section 7.20
1375  goto update_refs;
1376  }
1377 
1378  fb(2, frame_type);
1379  frame_is_intra = (current->frame_type == AV1_FRAME_INTRA_ONLY ||
1380  current->frame_type == AV1_FRAME_KEY);
1381 
1382  flag(show_frame);
1383  if (current->show_frame &&
1387  frame_presentation_time);
1388  }
1389  if (current->show_frame)
1390  infer(showable_frame, current->frame_type != AV1_FRAME_KEY);
1391  else
1392  flag(showable_frame);
1393 
1394  if (current->frame_type == AV1_FRAME_SWITCH ||
1395  (current->frame_type == AV1_FRAME_KEY && current->show_frame))
1396  infer(error_resilient_mode, 1);
1397  else
1398  flag(error_resilient_mode);
1399  }
1400 
1401  if (current->frame_type == AV1_FRAME_KEY && current->show_frame) {
1402  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1403  priv->ref[i].valid = 0;
1404  priv->ref[i].order_hint = 0;
1405  }
1406  }
1407 
1408  flag(disable_cdf_update);
1409 
1410  if (seq->seq_force_screen_content_tools ==
1412  flag(allow_screen_content_tools);
1413  } else {
1414  infer(allow_screen_content_tools,
1416  }
1417  if (current->allow_screen_content_tools) {
1419  flag(force_integer_mv);
1420  else
1421  infer(force_integer_mv, seq->seq_force_integer_mv);
1422  } else {
1423  infer(force_integer_mv, 0);
1424  }
1425 
1426  if (seq->frame_id_numbers_present_flag) {
1427  fb(id_len, current_frame_id);
1428 
1429  diff_len = seq->delta_frame_id_length_minus_2 + 2;
1430  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1431  if (current->current_frame_id > (1 << diff_len)) {
1432  if (priv->ref[i].frame_id > current->current_frame_id ||
1433  priv->ref[i].frame_id < (current->current_frame_id -
1434  (1 << diff_len)))
1435  priv->ref[i].valid = 0;
1436  } else {
1437  if (priv->ref[i].frame_id > current->current_frame_id &&
1438  priv->ref[i].frame_id < ((1 << id_len) +
1439  current->current_frame_id -
1440  (1 << diff_len)))
1441  priv->ref[i].valid = 0;
1442  }
1443  }
1444  } else {
1445  infer(current_frame_id, 0);
1446  }
1447 
1448  if (current->frame_type == AV1_FRAME_SWITCH)
1449  infer(frame_size_override_flag, 1);
1450  else if(seq->reduced_still_picture_header)
1451  infer(frame_size_override_flag, 0);
1452  else
1453  flag(frame_size_override_flag);
1454 
1455  order_hint_bits =
1456  seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0;
1457  if (order_hint_bits > 0)
1458  fb(order_hint_bits, order_hint);
1459  else
1460  infer(order_hint, 0);
1461  priv->order_hint = current->order_hint;
1462 
1463  if (frame_is_intra || current->error_resilient_mode)
1464  infer(primary_ref_frame, AV1_PRIMARY_REF_NONE);
1465  else
1466  fb(3, primary_ref_frame);
1467 
1469  flag(buffer_removal_time_present_flag);
1470  if (current->buffer_removal_time_present_flag) {
1471  for (i = 0; i <= seq->operating_points_cnt_minus_1; i++) {
1472  if (seq->decoder_model_present_for_this_op[i]) {
1473  int op_pt_idc = seq->operating_point_idc[i];
1474  int in_temporal_layer = (op_pt_idc >> priv->temporal_id ) & 1;
1475  int in_spatial_layer = (op_pt_idc >> (priv->spatial_id + 8)) & 1;
1476  if (seq->operating_point_idc[i] == 0 ||
1477  (in_temporal_layer && in_spatial_layer)) {
1479  buffer_removal_time[i], 1, i);
1480  }
1481  }
1482  }
1483  }
1484  }
1485 
1486  if (current->frame_type == AV1_FRAME_SWITCH ||
1487  (current->frame_type == AV1_FRAME_KEY && current->show_frame))
1488  infer(refresh_frame_flags, all_frames);
1489  else
1490  fb(8, refresh_frame_flags);
1491 
1492  if (!frame_is_intra || current->refresh_frame_flags != all_frames) {
1493  if (seq->enable_order_hint) {
1494  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1495  if (current->error_resilient_mode)
1496  fbs(order_hint_bits, ref_order_hint[i], 1, i);
1497  else
1498  infer(ref_order_hint[i], priv->ref[i].order_hint);
1499  if (current->ref_order_hint[i] != priv->ref[i].order_hint)
1500  priv->ref[i].valid = 0;
1501  }
1502  }
1503  }
1504 
1505  if (current->frame_type == AV1_FRAME_KEY ||
1506  current->frame_type == AV1_FRAME_INTRA_ONLY) {
1507  CHECK(FUNC(frame_size)(ctx, rw, current));
1508  CHECK(FUNC(render_size)(ctx, rw, current));
1509 
1510  if (current->allow_screen_content_tools &&
1511  priv->upscaled_width == priv->frame_width)
1512  flag(allow_intrabc);
1513  else
1514  infer(allow_intrabc, 0);
1515 
1516  } else {
1517  if (!seq->enable_order_hint) {
1518  infer(frame_refs_short_signaling, 0);
1519  } else {
1520  flag(frame_refs_short_signaling);
1521  if (current->frame_refs_short_signaling) {
1522  fb(3, last_frame_idx);
1523  fb(3, golden_frame_idx);
1524  CHECK(FUNC(set_frame_refs)(ctx, rw, current));
1525  }
1526  }
1527 
1528  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1529  if (!current->frame_refs_short_signaling)
1530  fbs(3, ref_frame_idx[i], 1, i);
1531  if (seq->frame_id_numbers_present_flag) {
1533  delta_frame_id_minus1[i], 1, i);
1534  }
1535  }
1536 
1537  if (current->frame_size_override_flag &&
1538  !current->error_resilient_mode) {
1539  CHECK(FUNC(frame_size_with_refs)(ctx, rw, current));
1540  } else {
1541  CHECK(FUNC(frame_size)(ctx, rw, current));
1542  CHECK(FUNC(render_size)(ctx, rw, current));
1543  }
1544 
1545  if (current->force_integer_mv)
1546  infer(allow_high_precision_mv, 0);
1547  else
1548  flag(allow_high_precision_mv);
1549 
1550  CHECK(FUNC(interpolation_filter)(ctx, rw, current));
1551 
1552  flag(is_motion_mode_switchable);
1553 
1554  if (current->error_resilient_mode ||
1555  !seq->enable_ref_frame_mvs)
1556  infer(use_ref_frame_mvs, 0);
1557  else
1558  flag(use_ref_frame_mvs);
1559 
1560  infer(allow_intrabc, 0);
1561  }
1562 
1563  if (!frame_is_intra) {
1564  // Derive reference frame sign biases.
1565  }
1566 
1567  if (seq->reduced_still_picture_header || current->disable_cdf_update)
1568  infer(disable_frame_end_update_cdf, 1);
1569  else
1570  flag(disable_frame_end_update_cdf);
1571 
1572  if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
1573  // Init non-coeff CDFs.
1574  // Setup past independence.
1575  } else {
1576  // Load CDF tables from previous frame.
1577  // Load params from previous frame.
1578  }
1579 
1580  if (current->use_ref_frame_mvs) {
1581  // Perform motion field estimation process.
1582  }
1583 
1584  CHECK(FUNC(tile_info)(ctx, rw, current));
1585 
1586  CHECK(FUNC(quantization_params)(ctx, rw, current));
1587 
1588  CHECK(FUNC(segmentation_params)(ctx, rw, current));
1589 
1590  CHECK(FUNC(delta_q_params)(ctx, rw, current));
1591 
1592  CHECK(FUNC(delta_lf_params)(ctx, rw, current));
1593 
1594  // Init coeff CDFs / load previous segments.
1595 
1596  priv->coded_lossless = 1;
1597  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
1598  int qindex;
1599  if (current->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
1600  qindex = (current->base_q_idx +
1601  current->feature_value[i][AV1_SEG_LVL_ALT_Q]);
1602  } else {
1603  qindex = current->base_q_idx;
1604  }
1605  qindex = av_clip_uintp2(qindex, 8);
1606 
1607  if (qindex || current->delta_q_y_dc ||
1608  current->delta_q_u_ac || current->delta_q_u_dc ||
1609  current->delta_q_v_ac || current->delta_q_v_dc) {
1610  priv->coded_lossless = 0;
1611  }
1612  }
1613  priv->all_lossless = priv->coded_lossless &&
1614  priv->frame_width == priv->upscaled_width;
1615 
1616  CHECK(FUNC(loop_filter_params)(ctx, rw, current));
1617 
1618  CHECK(FUNC(cdef_params)(ctx, rw, current));
1619 
1620  CHECK(FUNC(lr_params)(ctx, rw, current));
1621 
1622  CHECK(FUNC(read_tx_mode)(ctx, rw, current));
1623 
1624  CHECK(FUNC(frame_reference_mode)(ctx, rw, current));
1625 
1626  CHECK(FUNC(skip_mode_params)(ctx, rw, current));
1627 
1628  if (frame_is_intra || current->error_resilient_mode ||
1629  !seq->enable_warped_motion)
1630  infer(allow_warped_motion, 0);
1631  else
1632  flag(allow_warped_motion);
1633 
1634  flag(reduced_tx_set);
1635 
1636  CHECK(FUNC(global_motion_params)(ctx, rw, current));
1637 
1638  CHECK(FUNC(film_grain_params)(ctx, rw, current));
1639 
1640  av_log(ctx->log_ctx, AV_LOG_DEBUG, "Frame %d: size %dx%d "
1641  "upscaled %d render %dx%d subsample %dx%d "
1642  "bitdepth %d tiles %dx%d.\n", priv->order_hint,
1643  priv->frame_width, priv->frame_height, priv->upscaled_width,
1644  priv->render_width, priv->render_height,
1645  seq->color_config.subsampling_x + 1,
1646  seq->color_config.subsampling_y + 1, priv->bit_depth,
1647  priv->tile_rows, priv->tile_cols);
1648 
1649 update_refs:
1650  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1651  if (current->refresh_frame_flags & (1 << i)) {
1652  priv->ref[i] = (AV1ReferenceFrameState) {
1653  .valid = 1,
1654  .frame_id = current->current_frame_id,
1655  .upscaled_width = priv->upscaled_width,
1656  .frame_width = priv->frame_width,
1657  .frame_height = priv->frame_height,
1658  .render_width = priv->render_width,
1659  .render_height = priv->render_height,
1660  .frame_type = current->frame_type,
1661  .subsampling_x = seq->color_config.subsampling_x,
1662  .subsampling_y = seq->color_config.subsampling_y,
1663  .bit_depth = priv->bit_depth,
1664  .order_hint = priv->order_hint,
1665  };
1666  memcpy(priv->ref[i].loop_filter_ref_deltas, current->loop_filter_ref_deltas,
1667  sizeof(current->loop_filter_ref_deltas));
1668  memcpy(priv->ref[i].loop_filter_mode_deltas, current->loop_filter_mode_deltas,
1669  sizeof(current->loop_filter_mode_deltas));
1670  memcpy(priv->ref[i].feature_enabled, current->feature_enabled,
1671  sizeof(current->feature_enabled));
1672  memcpy(priv->ref[i].feature_value, current->feature_value,
1673  sizeof(current->feature_value));
1674  }
1675  }
1676 
1677  return 0;
1678 }
1679 
1681  AV1RawFrameHeader *current, int redundant,
1682  AVBufferRef *rw_buffer_ref)
1683 {
1685  int start_pos, fh_bits, fh_bytes, err;
1686  uint8_t *fh_start;
1687 
1688  if (priv->seen_frame_header) {
1689  if (!redundant) {
1690  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid repeated "
1691  "frame header OBU.\n");
1692  return AVERROR_INVALIDDATA;
1693  } else {
1694  GetBitContext fh;
1695  size_t i, b;
1696  uint32_t val;
1697 
1698  HEADER("Redundant Frame Header");
1699 
1700  av_assert0(priv->frame_header_ref && priv->frame_header);
1701 
1702  init_get_bits(&fh, priv->frame_header,
1703  priv->frame_header_size);
1704  for (i = 0; i < priv->frame_header_size; i += 8) {
1705  b = FFMIN(priv->frame_header_size - i, 8);
1706  val = get_bits(&fh, b);
1707  xf(b, frame_header_copy[i],
1708  val, val, val, 1, i / 8);
1709  }
1710  }
1711  } else {
1712  if (redundant)
1713  HEADER("Redundant Frame Header (used as Frame Header)");
1714  else
1715  HEADER("Frame Header");
1716 
1717 #ifdef READ
1718  start_pos = get_bits_count(rw);
1719 #else
1720  start_pos = put_bits_count(rw);
1721 #endif
1722 
1723  CHECK(FUNC(uncompressed_header)(ctx, rw, current));
1724 
1725  priv->tile_num = 0;
1726 
1727  if (current->show_existing_frame) {
1728  priv->seen_frame_header = 0;
1729  } else {
1730  priv->seen_frame_header = 1;
1731 
1733 
1734 #ifdef READ
1735  fh_bits = get_bits_count(rw) - start_pos;
1736  fh_start = (uint8_t*)rw->buffer + start_pos / 8;
1737 #else
1738  // Need to flush the bitwriter so that we can copy its output,
1739  // but use a copy so we don't affect the caller's structure.
1740  {
1741  PutBitContext tmp = *rw;
1742  flush_put_bits(&tmp);
1743  }
1744 
1745  fh_bits = put_bits_count(rw) - start_pos;
1746  fh_start = rw->buf + start_pos / 8;
1747 #endif
1748  fh_bytes = (fh_bits + 7) / 8;
1749 
1750  priv->frame_header_size = fh_bits;
1751 
1752  if (rw_buffer_ref) {
1753  priv->frame_header_ref = av_buffer_ref(rw_buffer_ref);
1754  if (!priv->frame_header_ref)
1755  return AVERROR(ENOMEM);
1756  priv->frame_header = fh_start;
1757  } else {
1758  priv->frame_header_ref =
1760  if (!priv->frame_header_ref)
1761  return AVERROR(ENOMEM);
1762  priv->frame_header = priv->frame_header_ref->data;
1763  memcpy(priv->frame_header, fh_start, fh_bytes);
1764  }
1765  }
1766  }
1767 
1768  return 0;
1769 }
1770 
1772  AV1RawTileGroup *current)
1773 {
1775  int num_tiles, tile_bits;
1776  int err;
1777 
1778  HEADER("Tile Group");
1779 
1780  num_tiles = priv->tile_cols * priv->tile_rows;
1781  if (num_tiles > 1)
1782  flag(tile_start_and_end_present_flag);
1783  else
1784  infer(tile_start_and_end_present_flag, 0);
1785 
1786  if (num_tiles == 1 || !current->tile_start_and_end_present_flag) {
1787  infer(tg_start, 0);
1788  infer(tg_end, num_tiles - 1);
1789  } else {
1790  tile_bits = cbs_av1_tile_log2(1, priv->tile_cols) +
1791  cbs_av1_tile_log2(1, priv->tile_rows);
1792  fc(tile_bits, tg_start, priv->tile_num, num_tiles - 1);
1793  fc(tile_bits, tg_end, current->tg_start, num_tiles - 1);
1794  }
1795 
1796  priv->tile_num = current->tg_end + 1;
1797 
1798  CHECK(FUNC(byte_alignment)(ctx, rw));
1799 
1800  // Reset header for next frame.
1801  if (current->tg_end == num_tiles - 1)
1802  priv->seen_frame_header = 0;
1803 
1804  // Tile data follows.
1805 
1806  return 0;
1807 }
1808 
1810  AV1RawFrame *current,
1811  AVBufferRef *rw_buffer_ref)
1812 {
1813  int err;
1814 
1815  CHECK(FUNC(frame_header_obu)(ctx, rw, &current->header,
1816  0, rw_buffer_ref));
1817 
1818  CHECK(FUNC(byte_alignment)(ctx, rw));
1819 
1820  CHECK(FUNC(tile_group_obu)(ctx, rw, &current->tile_group));
1821 
1822  return 0;
1823 }
1824 
1826  AV1RawTileList *current)
1827 {
1828  int err;
1829 
1830  fb(8, output_frame_width_in_tiles_minus_1);
1831  fb(8, output_frame_height_in_tiles_minus_1);
1832 
1833  fb(16, tile_count_minus_1);
1834 
1835  // Tile data follows.
1836 
1837  return 0;
1838 }
1839 
1841  AV1RawMetadataHDRCLL *current)
1842 {
1843  int err;
1844 
1845  fb(16, max_cll);
1846  fb(16, max_fall);
1847 
1848  return 0;
1849 }
1850 
1852  AV1RawMetadataHDRMDCV *current)
1853 {
1854  int err, i;
1855 
1856  for (i = 0; i < 3; i++) {
1857  fbs(16, primary_chromaticity_x[i], 1, i);
1858  fbs(16, primary_chromaticity_y[i], 1, i);
1859  }
1860 
1861  fb(16, white_point_chromaticity_x);
1862  fb(16, white_point_chromaticity_y);
1863 
1864  fc(32, luminance_max, 1, MAX_UINT_BITS(32));
1865  // luminance_min must be lower than luminance_max. Convert luminance_max from
1866  // 24.8 fixed point to 18.14 fixed point in order to compare them.
1867  fc(32, luminance_min, 0, FFMIN(((uint64_t)current->luminance_max << 6) - 1,
1868  MAX_UINT_BITS(32)));
1869 
1870  return 0;
1871 }
1872 
1874  AV1RawMetadataScalability *current)
1875 {
1877  const AV1RawSequenceHeader *seq;
1878  int err, i, j;
1879 
1880  if (!priv->sequence_header) {
1881  av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: "
1882  "unable to parse scalability metadata.\n");
1883  return AVERROR_INVALIDDATA;
1884  }
1885  seq = priv->sequence_header;
1886 
1887  fb(2, spatial_layers_cnt_minus_1);
1888  flag(spatial_layer_dimensions_present_flag);
1889  flag(spatial_layer_description_present_flag);
1890  flag(temporal_group_description_present_flag);
1891  fc(3, scalability_structure_reserved_3bits, 0, 0);
1892  if (current->spatial_layer_dimensions_present_flag) {
1893  for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) {
1894  fcs(16, spatial_layer_max_width[i],
1895  0, seq->max_frame_width_minus_1 + 1, 1, i);
1896  fcs(16, spatial_layer_max_height[i],
1897  0, seq->max_frame_height_minus_1 + 1, 1, i);
1898  }
1899  }
1900  if (current->spatial_layer_description_present_flag) {
1901  for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++)
1902  fbs(8, spatial_layer_ref_id[i], 1, i);
1903  }
1904  if (current->temporal_group_description_present_flag) {
1905  fb(8, temporal_group_size);
1906  for (i = 0; i < current->temporal_group_size; i++) {
1907  fbs(3, temporal_group_temporal_id[i], 1, i);
1908  flags(temporal_group_temporal_switching_up_point_flag[i], 1, i);
1909  flags(temporal_group_spatial_switching_up_point_flag[i], 1, i);
1910  fbs(3, temporal_group_ref_cnt[i], 1, i);
1911  for (j = 0; j < current->temporal_group_ref_cnt[i]; j++) {
1912  fbs(8, temporal_group_ref_pic_diff[i][j], 2, i, j);
1913  }
1914  }
1915  }
1916 
1917  return 0;
1918 }
1919 
1921  AV1RawMetadataScalability *current)
1922 {
1923  int err;
1924 
1925  fb(8, scalability_mode_idc);
1926 
1927  if (current->scalability_mode_idc == AV1_SCALABILITY_SS)
1928  CHECK(FUNC(scalability_structure)(ctx, rw, current));
1929 
1930  return 0;
1931 }
1932 
1934  AV1RawMetadataITUTT35 *current)
1935 {
1936  int err;
1937  size_t i;
1938 
1939  fb(8, itu_t_t35_country_code);
1940  if (current->itu_t_t35_country_code == 0xff)
1941  fb(8, itu_t_t35_country_code_extension_byte);
1942 
1943 #ifdef READ
1944  // The payload runs up to the start of the trailing bits, but there might
1945  // be arbitrarily many trailing zeroes so we need to read through twice.
1946  current->payload_size = cbs_av1_get_payload_bytes_left(rw);
1947 
1948  current->payload_ref = av_buffer_alloc(current->payload_size);
1949  if (!current->payload_ref)
1950  return AVERROR(ENOMEM);
1951  current->payload = current->payload_ref->data;
1952 #endif
1953 
1954  for (i = 0; i < current->payload_size; i++)
1955  xf(8, itu_t_t35_payload_bytes[i], current->payload[i],
1956  0x00, 0xff, 1, i);
1957 
1958  return 0;
1959 }
1960 
1962  AV1RawMetadataTimecode *current)
1963 {
1964  int err;
1965 
1966  fb(5, counting_type);
1967  flag(full_timestamp_flag);
1968  flag(discontinuity_flag);
1969  flag(cnt_dropped_flag);
1970  fb(9, n_frames);
1971 
1972  if (current->full_timestamp_flag) {
1973  fc(6, seconds_value, 0, 59);
1974  fc(6, minutes_value, 0, 59);
1975  fc(5, hours_value, 0, 23);
1976  } else {
1977  flag(seconds_flag);
1978  if (current->seconds_flag) {
1979  fc(6, seconds_value, 0, 59);
1980  flag(minutes_flag);
1981  if (current->minutes_flag) {
1982  fc(6, minutes_value, 0, 59);
1983  flag(hours_flag);
1984  if (current->hours_flag)
1985  fc(5, hours_value, 0, 23);
1986  }
1987  }
1988  }
1989 
1990  fb(5, time_offset_length);
1991  if (current->time_offset_length > 0)
1992  fb(current->time_offset_length, time_offset_value);
1993  else
1994  infer(time_offset_length, 0);
1995 
1996  return 0;
1997 }
1998 
2000  AV1RawMetadata *current)
2001 {
2002  int err;
2003 
2004  leb128(metadata_type);
2005 
2006  switch (current->metadata_type) {
2008  CHECK(FUNC(metadata_hdr_cll)(ctx, rw, &current->metadata.hdr_cll));
2009  break;
2011  CHECK(FUNC(metadata_hdr_mdcv)(ctx, rw, &current->metadata.hdr_mdcv));
2012  break;
2014  CHECK(FUNC(metadata_scalability)(ctx, rw, &current->metadata.scalability));
2015  break;
2017  CHECK(FUNC(metadata_itut_t35)(ctx, rw, &current->metadata.itut_t35));
2018  break;
2020  CHECK(FUNC(metadata_timecode)(ctx, rw, &current->metadata.timecode));
2021  break;
2022  default:
2023  // Unknown metadata type.
2024  return AVERROR_PATCHWELCOME;
2025  }
2026 
2027  return 0;
2028 }
2029 
2031  AV1RawPadding *current)
2032 {
2033  int i, err;
2034 
2035  HEADER("Padding");
2036 
2037 #ifdef READ
2038  // The payload runs up to the start of the trailing bits, but there might
2039  // be arbitrarily many trailing zeroes so we need to read through twice.
2040  current->payload_size = cbs_av1_get_payload_bytes_left(rw);
2041 
2042  current->payload_ref = av_buffer_alloc(current->payload_size);
2043  if (!current->payload_ref)
2044  return AVERROR(ENOMEM);
2045  current->payload = current->payload_ref->data;
2046 #endif
2047 
2048  for (i = 0; i < current->payload_size; i++)
2049  xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i);
2050 
2051  return 0;
2052 }
static int FUNC() tile_group_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawTileGroup *current)
static int FUNC() trailing_bits(CodedBitstreamContext *ctx, RWContext *rw, int nb_bits)
#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:125
uint8_t frame_width_bits_minus_1
Definition: cbs_av1.h:96
int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]
Definition: cbs_av1.h:417
uint8_t enable_superres
Definition: cbs_av1.h:124
#define fixed(width, name, value)
Definition: cbs_av1.c:565
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:661
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:2128
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:513
static int FUNC() uncompressed_header(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
frame_type
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:704
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:532
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:163
static int FUNC() delta_lf_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
#define subexp(name, max, subs,...)
Definition: cbs_av1.c:692
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:429
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:550
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
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:194
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1479
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:558
uint8_t separate_uv_delta_q
Definition: cbs_av1.h:55
#define FUNC(a)
AVBufferRef * frame_header_ref
Definition: cbs_av1.h:428
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:215
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:460
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:83
static int cbs_av1_tile_log2(int blksize, int target)
Definition: cbs_av1.c:501
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:548
uint8_t use_128x128_superblock
Definition: cbs_av1.h:105
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
uint8_t enable_restoration
Definition: cbs_av1.h:126
uint8_t feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]
Definition: cbs_av1.h:419
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
AVFormatContext * ctx
Definition: movenc.c:48
uint8_t enable_cdef
Definition: cbs_av1.h:125
#define increment(name, min, max)
Definition: cbs_av1.c:687
static int FUNC() frame_size_with_refs(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
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:556
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:698
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:67
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:520
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:676
#define FF_PROFILE_AV1_PROFESSIONAL
Definition: avcodec.h:1954
Context structure for coded bitstream operations.
Definition: cbs.h:170
static int FUNC() global_motion_param(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current, int type, int ref, int idx)
AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]
Definition: cbs_av1.h:451
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:1952
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
int8_t loop_filter_mode_deltas[2]
Definition: cbs_av1.h:418
static void update_refs(VP8Context *s)
Definition: vp8.c:469
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:424
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:560
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
int16_t feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]
Definition: cbs_av1.h:420
#define ns(max_value, name, subs,...)
Definition: cbs_av1.c:681
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:497
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:117
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:552
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:215
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:663
void * priv_data
Format private data.
Definition: avformat.h:1267
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:562
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:508
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:708
static double val(void *priv, double ch)
Definition: aeval.c:76
uint8_t seq_force_screen_content_tools
Definition: cbs_av1.h:118
static int FUNC() padding_obu(CodedBitstreamContext *ctx, RWContext *rw, AV1RawPadding *current)
int i
Definition: input.c:407
#define FF_PROFILE_AV1_HIGH
Definition: avcodec.h:1953
static uint8_t tmp[11]
Definition: aes_ctr.c:26