27     fc(1, obu_forbidden_bit, 0, 0);
 
   30     flag(obu_extension_flag);
 
   31     flag(obu_has_size_field);
 
   33     fc(1, obu_reserved_1bit, 0, 0);
 
   35     if (current->obu_extension_flag) {
 
   38         fc(3, extension_header_reserved_3bits, 0, 0);
 
   40         infer(temporal_id, 0);
 
   56     fixed(1, trailing_one_bit, 1);
 
   60         fixed(1, trailing_zero_bit, 0);
 
   72         fixed(1, zero_bit, 0);
 
   86         current->high_bitdepth) {
 
   88         priv->
bit_depth = current->twelve_bit ? 12 : 10;
 
   90         priv->
bit_depth = current->high_bitdepth ? 10 : 8;
 
   94         infer(mono_chrome, 0);
 
   97     priv->
num_planes = current->mono_chrome ? 1 : 3;
 
   99     flag(color_description_present_flag);
 
  100     if (current->color_description_present_flag) {
 
  103         fb(8, matrix_coefficients);
 
  110     if (current->mono_chrome) {
 
  113         infer(subsampling_x, 1);
 
  114         infer(subsampling_y, 1);
 
  116         infer(separate_uv_delta_q, 0);
 
  122         infer(subsampling_x, 0);
 
  123         infer(subsampling_y, 0);
 
  124         flag(separate_uv_delta_q);
 
  130             infer(subsampling_x, 1);
 
  131             infer(subsampling_y, 1);
 
  133             infer(subsampling_x, 0);
 
  134             infer(subsampling_y, 0);
 
  137                 fb(1, subsampling_x);
 
  138                 if (current->subsampling_x)
 
  139                     fb(1, subsampling_y);
 
  141                     infer(subsampling_y, 0);
 
  143                 infer(subsampling_x, 1);
 
  144                 infer(subsampling_y, 0);
 
  147         if (current->subsampling_x && current->subsampling_y) {
 
  152         flag(separate_uv_delta_q);
 
  166     flag(equal_picture_interval);
 
  167     if (current->equal_picture_interval)
 
  178     fb(5, buffer_delay_length_minus_1);
 
  180     fb(5,  buffer_removal_time_length_minus_1);
 
  181     fb(5,  frame_presentation_time_length_minus_1);
 
  191     HEADER(
"Sequence Header");
 
  196     flag(reduced_still_picture_header);
 
  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);
 
  205         fb(5, seq_level_idx[0]);
 
  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);
 
  212         flag(timing_info_present_flag);
 
  213         if (current->timing_info_present_flag) {
 
  216             flag(decoder_model_info_present_flag);
 
  217             if (current->decoder_model_info_present_flag) {
 
  219                           (
ctx, rw, ¤t->decoder_model_info));
 
  222             infer(decoder_model_info_present_flag, 0);
 
  225         flag(initial_display_delay_present_flag);
 
  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);
 
  232             if (current->seq_level_idx[
i] > 7)
 
  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);
 
  246                 infer(decoder_model_present_for_this_op[
i], 0);
 
  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);
 
  257     fb(4, frame_width_bits_minus_1);
 
  258     fb(4, frame_height_bits_minus_1);
 
  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);
 
  263     if (current->reduced_still_picture_header)
 
  264         infer(frame_id_numbers_present_flag, 0);
 
  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);
 
  272     flag(use_128x128_superblock);
 
  273     flag(enable_filter_intra);
 
  274     flag(enable_intra_edge_filter);
 
  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);
 
  285         infer(seq_force_screen_content_tools,
 
  287         infer(seq_force_integer_mv,
 
  290         flag(enable_interintra_compound);
 
  291         flag(enable_masked_compound);
 
  292         flag(enable_warped_motion);
 
  293         flag(enable_dual_filter);
 
  295         flag(enable_order_hint);
 
  296         if (current->enable_order_hint) {
 
  297             flag(enable_jnt_comp);
 
  298             flag(enable_ref_frame_mvs);
 
  300             infer(enable_jnt_comp,      0);
 
  301             infer(enable_ref_frame_mvs, 0);
 
  304         flag(seq_choose_screen_content_tools);
 
  305         if (current->seq_choose_screen_content_tools)
 
  306             infer(seq_force_screen_content_tools,
 
  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,
 
  316                 fb(1, seq_force_integer_mv);
 
  321         if (current->enable_order_hint)
 
  322             fb(3, order_hint_bits_minus_1);
 
  325     flag(enable_superres);
 
  327     flag(enable_restoration);
 
  330                              current->seq_profile));
 
  332     flag(film_grain_params_present);
 
  341     HEADER(
"Temporal Delimiter");
 
  359     int cur_frame_hint, latest_order_hint, earliest_order_hint, 
ref;
 
  369     used_frame[current->last_frame_idx] = 1;
 
  370     used_frame[current->golden_frame_idx] = 1;
 
  374         shifted_order_hints[
i] = cur_frame_hint +
 
  378     latest_order_hint = shifted_order_hints[current->last_frame_idx];
 
  379     earliest_order_hint = shifted_order_hints[current->golden_frame_idx];
 
  383         int hint = shifted_order_hints[
i];
 
  384         if (!used_frame[
i] && hint >= cur_frame_hint &&
 
  385             (ref < 0 || hint >= latest_order_hint)) {
 
  387             latest_order_hint = hint;
 
  397         int hint = shifted_order_hints[
i];
 
  398         if (!used_frame[
i] && hint >= cur_frame_hint &&
 
  399             (
ref < 0 || hint < earliest_order_hint)) {
 
  401             earliest_order_hint = hint;
 
  411         int hint = shifted_order_hints[
i];
 
  412         if (!used_frame[
i] && hint >= cur_frame_hint &&
 
  413             (
ref < 0 || hint < earliest_order_hint)) {
 
  415             earliest_order_hint = hint;
 
  428                 int hint = shifted_order_hints[j];
 
  429                 if (!used_frame[j] && hint < cur_frame_hint &&
 
  430                     (ref < 0 || hint >= latest_order_hint)) {
 
  432                     latest_order_hint = hint;
 
  444         int hint = shifted_order_hints[
i];
 
  445         if (
ref < 0 || hint < earliest_order_hint) {
 
  447             earliest_order_hint = hint;
 
  451         if (ref_frame_idx[
i] < 0)
 
  452             ref_frame_idx[
i] = 
ref;
 
  453         infer(ref_frame_idx[
i], ref_frame_idx[
i]);
 
  469         infer(use_superres, 0);
 
  471     if (current->use_superres) {
 
  492     if (current->frame_size_override_flag) {
 
  500     priv->
frame_width  = current->frame_width_minus_1  + 1;
 
  514     flag(render_and_frame_size_different);
 
  516     if (current->render_and_frame_size_different) {
 
  517         fb(16, render_width_minus_1);
 
  518         fb(16, render_height_minus_1);
 
  520         infer(render_width_minus_1,  current->frame_width_minus_1);
 
  521         infer(render_height_minus_1, current->frame_height_minus_1);
 
  538         if (current->found_ref[
i]) {
 
  540                 &priv->
ref[current->ref_frame_idx[
i]];
 
  544                        "Missing reference frame needed for frame size " 
  545                        "(ref = %d, ref_frame_idx = %d).\n",
 
  546                        i, current->ref_frame_idx[
i]);
 
  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);
 
  579     flag(is_filter_switchable);
 
  580     if (current->is_filter_switchable)
 
  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;
 
  604                                           : ((mi_cols + 15) >> 4);
 
  606                                           : ((mi_rows + 15) >> 4);
 
  609     sb_size  = sb_shift + 2;
 
  617     min_log2_tiles = 
FFMAX(min_log2_tile_cols,
 
  620     flag(uniform_tile_spacing_flag);
 
  622     if (current->uniform_tile_spacing_flag) {
 
  623         int tile_width_sb, tile_height_sb;
 
  625         increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols);
 
  627         tile_width_sb = (sb_cols + (1 << current->tile_cols_log2) - 1) >>
 
  628             current->tile_cols_log2;
 
  630         for (
int off = 0, 
i = 0; off < sb_cols; off += tile_width_sb)
 
  631             current->tile_start_col_sb[
i++] = off;
 
  633         current->tile_cols = (sb_cols + tile_width_sb - 1) / tile_width_sb;
 
  635         min_log2_tile_rows = 
FFMAX(min_log2_tiles - current->tile_cols_log2, 0);
 
  637         increment(tile_rows_log2, min_log2_tile_rows, max_log2_tile_rows);
 
  639         tile_height_sb = (sb_rows + (1 << current->tile_rows_log2) - 1) >>
 
  640             current->tile_rows_log2;
 
  642         for (
int off = 0, 
i = 0; off < sb_rows; off += tile_height_sb)
 
  643             current->tile_start_row_sb[
i++] = off;
 
  645         current->tile_rows = (sb_rows + tile_height_sb - 1) / tile_height_sb;
 
  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);
 
  657         int widest_tile_sb, start_sb, size_sb, max_width, max_height;
 
  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);
 
  671         current->tile_cols = 
i;
 
  673         if (min_log2_tiles > 0)
 
  674             max_tile_area_sb = (sb_rows * sb_cols) >> (min_log2_tiles + 1);
 
  676             max_tile_area_sb = sb_rows * sb_cols;
 
  677         max_tile_height_sb = 
FFMAX(max_tile_area_sb / widest_tile_sb, 1);
 
  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;
 
  688         current->tile_rows = 
i;
 
  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);
 
  697         infer(context_update_tile_id, 0);
 
  721             infer(diff_uv_delta, 0);
 
  726         if (current->diff_uv_delta) {
 
  730             infer(delta_q_v_dc, current->delta_q_u_dc);
 
  731             infer(delta_q_v_ac, current->delta_q_u_ac);
 
  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);
 
  741     if (current->using_qmatrix) {
 
  747             infer(qm_v, current->qm_u);
 
  758     static const uint8_t sign[
AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 };
 
  763     flag(segmentation_enabled);
 
  765     if (current->segmentation_enabled) {
 
  767             infer(segmentation_update_map,      1);
 
  768             infer(segmentation_temporal_update, 0);
 
  769             infer(segmentation_update_data,     1);
 
  771             flag(segmentation_update_map);
 
  772             if (current->segmentation_update_map)
 
  773                 flag(segmentation_temporal_update);
 
  775                 infer(segmentation_temporal_update, 0);
 
  776             flag(segmentation_update_data);
 
  780             const uint8_t *ref_feature_enabled;
 
  781             const int16_t *ref_feature_value;
 
  784                 ref_feature_enabled = default_feature_enabled;
 
  785                 ref_feature_value = default_feature_value;
 
  787                 ref_feature_enabled =
 
  794                 if (current->segmentation_update_data) {
 
  795                     flags(feature_enabled[
i][j], 2, 
i, j);
 
  797                     if (current->feature_enabled[
i][j] && 
bits[j] > 0) {
 
  799                             sus(1 + 
bits[j], feature_value[
i][j], 2, 
i, j);
 
  801                             fbs(
bits[j], feature_value[
i][j], 2, 
i, j);
 
  803                         infer(feature_value[
i][j], 0);
 
  806                     infer(feature_enabled[
i][j], ref_feature_enabled[j]);
 
  807                     infer(feature_value[
i][j], ref_feature_value[j]);
 
  814                 infer(feature_enabled[
i][j], 0);
 
  815                 infer(feature_value[
i][j],   0);
 
  828     if (current->base_q_idx > 0)
 
  829         flag(delta_q_present);
 
  831         infer(delta_q_present, 0);
 
  833     if (current->delta_q_present)
 
  844     if (current->delta_q_present) {
 
  845         if (!current->allow_intrabc)
 
  846             flag(delta_lf_present);
 
  848             infer(delta_lf_present, 0);
 
  849         if (current->delta_lf_present) {
 
  851             flag(delta_lf_multi);
 
  853             infer(delta_lf_res,   0);
 
  854             infer(delta_lf_multi, 0);
 
  857         infer(delta_lf_present, 0);
 
  858         infer(delta_lf_res,     0);
 
  859         infer(delta_lf_multi,   0);
 
  870         { 1, 0, 0, 0, -1, 0, -1, -1 };
 
  871     static const int8_t default_loop_filter_mode_deltas[2] = { 0, 0 };
 
  875         infer(loop_filter_level[0], 0);
 
  876         infer(loop_filter_level[1], 0);
 
  885         for (
i = 0; 
i < 2; 
i++)
 
  886             infer(loop_filter_mode_deltas[
i], 0);
 
  890     fb(6, loop_filter_level[0]);
 
  891     fb(6, loop_filter_level[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]);
 
  901     fb(3, loop_filter_sharpness);
 
  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;
 
  908             ref_loop_filter_ref_deltas = default_loop_filter_ref_deltas;
 
  909             ref_loop_filter_mode_deltas = default_loop_filter_mode_deltas;
 
  911             ref_loop_filter_ref_deltas =
 
  913             ref_loop_filter_mode_deltas =
 
  917         flag(loop_filter_delta_update);
 
  919             if (current->loop_filter_delta_update)
 
  920                 flags(update_ref_delta[
i], 1, 
i);
 
  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);
 
  926                 infer(loop_filter_ref_deltas[
i], ref_loop_filter_ref_deltas[
i]);
 
  928         for (
i = 0; 
i < 2; 
i++) {
 
  929             if (current->loop_filter_delta_update)
 
  930                 flags(update_mode_delta[
i], 1, 
i);
 
  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);
 
  936                 infer(loop_filter_mode_deltas[
i], ref_loop_filter_mode_deltas[
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]);
 
  957         infer(cdef_damping_minus_3, 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);
 
  967     fb(2, cdef_damping_minus_3);
 
  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);
 
  975             fbs(4, cdef_uv_pri_strength[
i], 1, 
i);
 
  976             fbs(2, cdef_uv_sec_strength[
i], 1, 
i);
 
  988     int uses_lr,  uses_chroma_lr;
 
  996     uses_lr = uses_chroma_lr = 0;
 
  998         fbs(2, lr_type[
i], 1, 
i);
 
 1017             infer(lr_uv_shift, 0);
 
 1045         infer(reference_select, 0);
 
 1047         flag(reference_select);
 
 1057     int skip_mode_allowed;
 
 1063         skip_mode_allowed = 0;
 
 1065         int forward_idx,  backward_idx;
 
 1066         int forward_hint, backward_hint;
 
 1067         int ref_hint, dist, 
i;
 
 1076                 if (forward_idx < 0 ||
 
 1078                                               forward_hint) > 0) {
 
 1080                     forward_hint = ref_hint;
 
 1082             } 
else if (dist > 0) {
 
 1083                 if (backward_idx < 0 ||
 
 1085                                               backward_hint) < 0) {
 
 1087                     backward_hint = ref_hint;
 
 1092         if (forward_idx < 0) {
 
 1093             skip_mode_allowed = 0;
 
 1094         } 
else if (backward_idx >= 0) {
 
 1095             skip_mode_allowed = 1;
 
 1098             int second_forward_idx;
 
 1099             int second_forward_hint;
 
 1101             second_forward_idx = -1;
 
 1105                                               forward_hint) < 0) {
 
 1106                     if (second_forward_idx < 0 ||
 
 1108                                                   second_forward_hint) > 0) {
 
 1109                         second_forward_idx  = 
i;
 
 1110                         second_forward_hint = ref_hint;
 
 1115             if (second_forward_idx < 0) {
 
 1116                 skip_mode_allowed = 0;
 
 1118                 skip_mode_allowed = 1;
 
 1124     if (skip_mode_allowed)
 
 1125         flag(skip_mode_present);
 
 1127         infer(skip_mode_present, 0);
 
 1136     uint32_t abs_bits, prec_bits, num_syms;
 
 1152     num_syms = 2 * (1 << abs_bits) + 1;
 
 1173         if (current->is_global[
ref]) {
 
 1175             if (current->is_rot_zoom[
ref]) {
 
 1212     int num_pos_luma, num_pos_chroma;
 
 1221     if (!current->apply_grain)
 
 1229         infer(update_grain, 1);
 
 1231     if (!current->update_grain) {
 
 1232         fb(3, film_grain_params_ref_idx);
 
 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,
 
 1242         fbs(8, point_y_scaling[
i], 1, 
i);
 
 1246         infer(chroma_scaling_from_luma, 0);
 
 1248         flag(chroma_scaling_from_luma);
 
 1251         current->chroma_scaling_from_luma ||
 
 1254          current->num_y_points == 0)) {
 
 1255         infer(num_cb_points, 0);
 
 1256         infer(num_cr_points, 0);
 
 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,
 
 1264             fbs(8, point_cb_scaling[
i], 1, 
i);
 
 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,
 
 1272             fbs(8, point_cr_scaling[
i], 1, 
i);
 
 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);
 
 1284         num_pos_chroma = num_pos_luma;
 
 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);
 
 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);
 
 1294     fb(2, ar_coeff_shift_minus_6);
 
 1295     fb(2, grain_scale_shift);
 
 1296     if (current->num_cb_points) {
 
 1298         fb(8, cb_luma_mult);
 
 1301     if (current->num_cr_points) {
 
 1303         fb(8, cr_luma_mult);
 
 1308     flag(clip_to_restricted_range);
 
 1318     int id_len, diff_len, all_frames, frame_is_intra, order_hint_bits;
 
 1323                "unable to decode frame header.\n");
 
 1333         infer(show_existing_frame, 0);
 
 1336         infer(showable_frame, 0);
 
 1340         flag(show_existing_frame);
 
 1342         if (current->show_existing_frame) {
 
 1345             fb(3, frame_to_show_map_idx);
 
 1346             ref = &priv->
ref[current->frame_to_show_map_idx];
 
 1350                        "show_existing_frame (frame_to_show_map_idx = %d).\n",
 
 1351                        current->frame_to_show_map_idx);
 
 1358                    frame_presentation_time);
 
 1362                 fb(id_len, display_frame_id);
 
 1366                 infer(refresh_frame_flags, all_frames);
 
 1369                 infer(current_frame_id, 
ref->frame_id);
 
 1379                        sizeof(
ref->loop_filter_ref_deltas));
 
 1381                        sizeof(
ref->loop_filter_mode_deltas));
 
 1383                        sizeof(
ref->feature_enabled));
 
 1385                        sizeof(
ref->feature_value));
 
 1387                 infer(refresh_frame_flags, 0);
 
 1389             infer(frame_width_minus_1,   
ref->upscaled_width - 1);
 
 1390             infer(frame_height_minus_1,  
ref->frame_height - 1);
 
 1391             infer(render_width_minus_1,  
ref->render_width - 1);
 
 1392             infer(render_height_minus_1, 
ref->render_height - 1);
 
 1403         if (current->show_frame &&
 
 1407                frame_presentation_time);
 
 1409         if (current->show_frame)
 
 1412             flag(showable_frame);
 
 1415             (current->frame_type == 
AV1_FRAME_KEY && current->show_frame))
 
 1416             infer(error_resilient_mode, 1);
 
 1418             flag(error_resilient_mode);
 
 1421     if (current->frame_type == 
AV1_FRAME_KEY && current->show_frame) {
 
 1430     flag(disable_cdf_update);
 
 1434         flag(allow_screen_content_tools);
 
 1436         infer(allow_screen_content_tools,
 
 1439     if (current->allow_screen_content_tools) {
 
 1441             flag(force_integer_mv);
 
 1445         infer(force_integer_mv, 0);
 
 1449         fb(id_len, current_frame_id);
 
 1453             if (current->current_frame_id > (1 << diff_len)) {
 
 1454                 if (priv->
ref[
i].
frame_id > current->current_frame_id ||
 
 1459                 if (priv->
ref[
i].
frame_id > current->current_frame_id &&
 
 1461                                              current->current_frame_id -
 
 1467         infer(current_frame_id, 0);
 
 1471         infer(frame_size_override_flag, 1);
 
 1473         infer(frame_size_override_flag, 0);
 
 1475         flag(frame_size_override_flag);
 
 1479     if (order_hint_bits > 0)
 
 1480         fb(order_hint_bits, order_hint);
 
 1482         infer(order_hint, 0);
 
 1485     if (frame_is_intra || current->error_resilient_mode)
 
 1488         fb(3, primary_ref_frame);
 
 1491         flag(buffer_removal_time_present_flag);
 
 1492         if (current->buffer_removal_time_present_flag) {
 
 1496                     int in_temporal_layer = (op_pt_idc >>  priv->
temporal_id    ) & 1;
 
 1497                     int in_spatial_layer  = (op_pt_idc >> (priv->
spatial_id + 8)) & 1;
 
 1499                         (in_temporal_layer && in_spatial_layer)) {
 
 1501                             buffer_removal_time[
i], 1, 
i);
 
 1509         (current->frame_type == 
AV1_FRAME_KEY && current->show_frame))
 
 1510         infer(refresh_frame_flags, all_frames);
 
 1512         fb(8, refresh_frame_flags);
 
 1514     if (!frame_is_intra || current->refresh_frame_flags != all_frames) {
 
 1517                 if (current->error_resilient_mode)
 
 1518                     fbs(order_hint_bits, ref_order_hint[
i], 1, 
i);
 
 1532         if (current->allow_screen_content_tools &&
 
 1534             flag(allow_intrabc);
 
 1536             infer(allow_intrabc, 0);
 
 1540             infer(frame_refs_short_signaling, 0);
 
 1542             flag(frame_refs_short_signaling);
 
 1543             if (current->frame_refs_short_signaling) {
 
 1544                 fb(3, last_frame_idx);
 
 1545                 fb(3, golden_frame_idx);
 
 1551             if (!current->frame_refs_short_signaling)
 
 1552                 fbs(3, ref_frame_idx[
i], 1, 
i);
 
 1555                     delta_frame_id_minus1[
i], 1, 
i);
 
 1559         if (current->frame_size_override_flag &&
 
 1560             !current->error_resilient_mode) {
 
 1567         if (current->force_integer_mv)
 
 1568             infer(allow_high_precision_mv, 0);
 
 1570             flag(allow_high_precision_mv);
 
 1574         flag(is_motion_mode_switchable);
 
 1576         if (current->error_resilient_mode ||
 
 1578             infer(use_ref_frame_mvs, 0);
 
 1580             flag(use_ref_frame_mvs);
 
 1591                                               current->order_hint) > 0;
 
 1595         infer(allow_intrabc, 0);
 
 1599         infer(disable_frame_end_update_cdf, 1);
 
 1601         flag(disable_frame_end_update_cdf);
 
 1611     if (current->use_ref_frame_mvs) {
 
 1631             qindex = (current->base_q_idx +
 
 1634             qindex = current->base_q_idx;
 
 1638         if (qindex                || current->delta_q_y_dc ||
 
 1639             current->delta_q_u_ac || current->delta_q_u_dc ||
 
 1640             current->delta_q_v_ac || current->delta_q_v_dc) {
 
 1659     if (frame_is_intra || current->error_resilient_mode ||
 
 1661         infer(allow_warped_motion, 0);
 
 1663         flag(allow_warped_motion);
 
 1665     flag(reduced_tx_set);
 
 1672            "upscaled %d  render %dx%d  subsample %dx%d  " 
 1673            "bitdepth %d  tiles %dx%d.\n", priv->
order_hint,
 
 1682         if (current->refresh_frame_flags & (1 << 
i)) {
 
 1685                 .frame_id       = current->current_frame_id,
 
 1691                 .frame_type     = current->frame_type,
 
 1703             if (current->show_existing_frame) {
 
 1714                        sizeof(current->loop_filter_ref_deltas));
 
 1716                        sizeof(current->loop_filter_mode_deltas));
 
 1718                        sizeof(current->feature_enabled));
 
 1720                        sizeof(current->feature_value));
 
 1733     int start_pos, fh_bits, fh_bytes, err;
 
 1739                    "frame header OBU.\n");
 
 1746             HEADER(
"Redundant Frame Header");
 
 1755                 xf(
b, frame_header_copy[
i],
 
 1761             HEADER(
"Redundant Frame Header (used as Frame Header)");
 
 1775         if (current->show_existing_frame) {
 
 1784             fh_start = (uint8_t*)rw->buffer + start_pos / 8;
 
 1794             fh_start = rw->buf + start_pos / 8;
 
 1796             fh_bytes = (fh_bits + 7) / 8;
 
 1800             if (rw_buffer_ref) {
 
 1823     int num_tiles, tile_bits;
 
 1830         flag(tile_start_and_end_present_flag);
 
 1832         infer(tile_start_and_end_present_flag, 0);
 
 1834     if (num_tiles == 1 || !current->tile_start_and_end_present_flag) {
 
 1836         infer(tg_end, num_tiles - 1);
 
 1840         fc(tile_bits, tg_start, priv->
tile_num, num_tiles - 1);
 
 1841         fc(tile_bits, tg_end, current->tg_start, num_tiles - 1);
 
 1844     priv->
tile_num = current->tg_end + 1;
 
 1849     if (current->tg_end == num_tiles - 1)
 
 1871 #if CBS_AV1_OBU_TILE_LIST 
 1877     fb(8, output_frame_width_in_tiles_minus_1);
 
 1878     fb(8, output_frame_height_in_tiles_minus_1);
 
 1880     fb(16, tile_count_minus_1);
 
 1888 #if CBS_AV1_OBU_METADATA 
 1894     HEADER(
"HDR CLL Metadata");
 
 1907     HEADER(
"HDR MDCV Metadata");
 
 1909     for (
i = 0; 
i < 3; 
i++) {
 
 1910         fbs(16, primary_chromaticity_x[
i], 1, 
i);
 
 1911         fbs(16, primary_chromaticity_y[
i], 1, 
i);
 
 1914     fb(16, white_point_chromaticity_x);
 
 1915     fb(16, white_point_chromaticity_y);
 
 1917     fb(32, luminance_max);
 
 1918     fb(32, luminance_min);
 
 1932                "unable to parse scalability metadata.\n");
 
 1937     fb(2, spatial_layers_cnt_minus_1);
 
 1938     flag(spatial_layer_dimensions_present_flag);
 
 1939     flag(spatial_layer_description_present_flag);
 
 1940     flag(temporal_group_description_present_flag);
 
 1941     fc(3, scalability_structure_reserved_3bits, 0, 0);
 
 1942     if (current->spatial_layer_dimensions_present_flag) {
 
 1943         for (
i = 0; 
i <= current->spatial_layers_cnt_minus_1; 
i++) {
 
 1944             fcs(16, spatial_layer_max_width[
i],
 
 1946             fcs(16, spatial_layer_max_height[
i],
 
 1950     if (current->spatial_layer_description_present_flag) {
 
 1951         for (
i = 0; 
i <= current->spatial_layers_cnt_minus_1; 
i++)
 
 1952             fbs(8, spatial_layer_ref_id[
i], 1, 
i);
 
 1954     if (current->temporal_group_description_present_flag) {
 
 1955         fb(8, temporal_group_size);
 
 1956         for (
i = 0; 
i < current->temporal_group_size; 
i++) {
 
 1957             fbs(3, temporal_group_temporal_id[
i], 1, 
i);
 
 1958             flags(temporal_group_temporal_switching_up_point_flag[
i], 1, 
i);
 
 1959             flags(temporal_group_spatial_switching_up_point_flag[
i], 1, 
i);
 
 1960             fbs(3, temporal_group_ref_cnt[
i], 1, 
i);
 
 1961             for (j = 0; j < current->temporal_group_ref_cnt[
i]; j++) {
 
 1962                 fbs(8, temporal_group_ref_pic_diff[
i][j], 2, 
i, j);
 
 1975     HEADER(
"Scalability Metadata");
 
 1977     fb(8, scalability_mode_idc);
 
 1991     HEADER(
"ITU-T T.35 Metadata");
 
 1993     fb(8, itu_t_t35_country_code);
 
 1994     if (current->itu_t_t35_country_code == 0xff)
 
 1995         fb(8, itu_t_t35_country_code_extension_byte);
 
 2003     if (!current->payload_ref)
 
 2005     current->payload = current->payload_ref->data;
 
 2008     for (
i = 0; 
i < current->payload_size; 
i++)
 
 2009         xf(8, itu_t_t35_payload_bytes[
i], current->payload[
i],
 
 2020     HEADER(
"Timecode Metadata");
 
 2022     fb(5, counting_type);
 
 2023     flag(full_timestamp_flag);
 
 2024     flag(discontinuity_flag);
 
 2025     flag(cnt_dropped_flag);
 
 2028     if (current->full_timestamp_flag) {
 
 2029         fc(6, seconds_value, 0, 59);
 
 2030         fc(6, minutes_value, 0, 59);
 
 2031         fc(5, hours_value,   0, 23);
 
 2034         if (current->seconds_flag) {
 
 2035             fc(6, seconds_value, 0, 59);
 
 2037             if (current->minutes_flag) {
 
 2038                 fc(6, minutes_value, 0, 59);
 
 2040                 if (current->hours_flag)
 
 2041                     fc(5, hours_value, 0, 23);
 
 2046     fb(5, time_offset_length);
 
 2047     if (current->time_offset_length > 0)
 
 2048         fb(current->time_offset_length, time_offset_value);
 
 2050         infer(time_offset_length, 0);
 
 2061     HEADER(
"Unknown Metadata");
 
 2067     if (!current->payload_ref)
 
 2069     current->payload = current->payload_ref->data;
 
 2072     for (
i = 0; 
i < current->payload_size; 
i++)
 
 2073         fbs(8, payload[
i], 1, 
i);
 
 2085     switch (current->metadata_type) {
 
 2109 #if CBS_AV1_OBU_PADDING 
 2123     if (!current->payload_ref)
 
 2125     current->payload = current->payload_ref->data;
 
 2128     for (
i = 0; 
i < current->payload_size; 
i++)
 
 2129         xf(8, obu_padding_byte[
i], current->payload[
i], 0x00, 0xff, 1, 
i);