frontends/va: Parse H264 SPS for max_num_reorder_frames
authorDavid Rosca <nowrep@gmail.com>
Wed, 4 Oct 2023 14:51:05 +0000 (16:51 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 25 Oct 2023 01:03:58 +0000 (01:03 +0000)
Reviewed-by: Ruijing Dong <ruijing.dong@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25565>

src/gallium/frontends/va/picture_h264_enc.c
src/gallium/include/pipe/p_video_state.h

index 48403b17e7832d57ccb289eabf626f095adcd488..87b427b0ec5349269fa7abcece6730c7e840e6d6 100644 (file)
@@ -325,9 +325,28 @@ vlVaHandleVAEncMiscParameterTypeFrameRateH264(vlVaContext *context, VAEncMiscPar
    return VA_STATUS_SUCCESS;
 }
 
+static void parseEncHrdParamsH264(struct vl_rbsp *rbsp)
+{
+   unsigned i, cpb_cnt_minus1;
+
+   cpb_cnt_minus1 = vl_rbsp_ue(rbsp);
+   vl_rbsp_u(rbsp, 4); /* bit_rate_scale */
+   vl_rbsp_u(rbsp, 4); /* cpb_size_scale */
+   for (i = 0; i <= cpb_cnt_minus1; ++i) {
+      vl_rbsp_ue(rbsp); /* bit_rate_value_minus1[i] */
+      vl_rbsp_ue(rbsp); /* cpb_size_value_minus1[i] */
+      vl_rbsp_u(rbsp, 1); /* cbr_flag[i] */
+   }
+   vl_rbsp_u(rbsp, 5); /* initial_cpb_removal_delay_length_minus1 */
+   vl_rbsp_u(rbsp, 5); /* cpb_removal_delay_length_minus1 */
+   vl_rbsp_u(rbsp, 5); /* dpb_output_delay_length_minus1 */
+   vl_rbsp_u(rbsp, 5); /* time_offset_length */
+}
+
 static void parseEncSpsParamsH264(vlVaContext *context, struct vl_rbsp *rbsp)
 {
    unsigned i, profile_idc, num_ref_frames_in_pic_order_cnt_cycle;
+   unsigned nal_hrd_parameters_present_flag, vcl_hrd_parameters_present_flag;
 
    profile_idc = vl_rbsp_u(rbsp, 8);
 
@@ -412,6 +431,35 @@ static void parseEncSpsParamsH264(vlVaContext *context, struct vl_rbsp *rbsp)
          context->desc.h264enc.seq.chroma_sample_loc_type_top_field = vl_rbsp_ue(rbsp);
          context->desc.h264enc.seq.chroma_sample_loc_type_bottom_field = vl_rbsp_ue(rbsp);
       }
+
+      if (vl_rbsp_u(rbsp, 1)) { /* timing_info_present_flag */
+         vl_rbsp_u(rbsp, 32); /* num_units_in_tick */
+         vl_rbsp_u(rbsp, 32); /* time_scale */
+         vl_rbsp_u(rbsp, 1); /* fixed_frame_rate_flag */
+      }
+
+      nal_hrd_parameters_present_flag = vl_rbsp_u(rbsp, 1);
+      if (nal_hrd_parameters_present_flag)
+         parseEncHrdParamsH264(rbsp);
+
+      vcl_hrd_parameters_present_flag = vl_rbsp_u(rbsp, 1);
+      if (vcl_hrd_parameters_present_flag)
+         parseEncHrdParamsH264(rbsp);
+
+      if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag)
+         vl_rbsp_u(rbsp, 1); /* low_delay_hrd_flag */
+
+      vl_rbsp_u(rbsp, 1); /* pic_struct_present_flag */
+
+      if (vl_rbsp_u(rbsp, 1)) { /* bitstream_restriction_flag */
+         vl_rbsp_u(rbsp, 1); /* motion_vectors_over_pic_boundaries_flag */
+         vl_rbsp_ue(rbsp); /* max_bytes_per_pic_denom */
+         vl_rbsp_ue(rbsp); /* max_bits_per_mb_denom */
+         vl_rbsp_ue(rbsp); /* log2_max_mv_length_horizontal */
+         vl_rbsp_ue(rbsp); /* log2_max_mv_length_vertical */
+         context->desc.h264enc.seq.max_num_reorder_frames = vl_rbsp_ue(rbsp);
+         vl_rbsp_ue(rbsp); /* max_dec_frame_buffering */
+      }
    }
 }
 
index c3fe4371256a80c3896ea400f0af3e072593bac0..9cb34c55aa03abb4b07ccaf10517e9293b0824d8 100644 (file)
@@ -528,6 +528,7 @@ struct pipe_h264_enc_seq_param
    uint32_t matrix_coefficients;
    uint32_t chroma_sample_loc_type_top_field;
    uint32_t chroma_sample_loc_type_bottom_field;
+   uint32_t max_num_reorder_frames;
 };
 
 struct pipe_h264_enc_picture_desc