[Mesa-dev] [PATCH 10/11] st/va: add preset values for VAAPI encode

Boyuan Zhang boyuan.zhang at amd.com
Fri Jul 15 22:41:48 UTC 2016


Add some hardcoded values hardware needs mainly for rate control purpose. With previously hardcoded values for OMX, the rate control result is not correct. This change fixed the rate control result by setting correct values for Vaapi.

Signed-off-by: Boyuan Zhang <boyuan.zhang at amd.com>
---
 src/gallium/state_trackers/va/picture.c | 36 +++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/gallium/state_trackers/va/picture.c b/src/gallium/state_trackers/va/picture.c
index c244619..275250f 100644
--- a/src/gallium/state_trackers/va/picture.c
+++ b/src/gallium/state_trackers/va/picture.c
@@ -95,6 +95,41 @@ vlVaGetReferenceFrame(vlVaDriver *drv, VASurfaceID surface_id,
       *ref_frame = NULL;
 }
 
+static void
+getEncParamPreset(vlVaContext *context)
+{
+   //motion estimation preset
+   context->desc.h264enc.motion_est.motion_est_quarter_pixel = 0x00000001;
+   context->desc.h264enc.motion_est.lsmvert = 0x00000002;
+   context->desc.h264enc.motion_est.enc_disable_sub_mode = 0x00000078;
+   context->desc.h264enc.motion_est.enc_en_ime_overw_dis_subm = 0x00000001;
+   context->desc.h264enc.motion_est.enc_ime_overw_dis_subm_no = 0x00000001;
+   context->desc.h264enc.motion_est.enc_ime2_search_range_x = 0x00000004;
+   context->desc.h264enc.motion_est.enc_ime2_search_range_y = 0x00000004;
+
+   //pic control preset
+   context->desc.h264enc.pic_ctrl.enc_cabac_enable = 0x00000001;
+   context->desc.h264enc.pic_ctrl.enc_constraint_set_flags = 0x00000040;
+
+   //rate control
+   context->desc.h264enc.rate_ctrl.vbv_buffer_size = 20000000;
+   if (context->desc.h264enc.rate_ctrl.frame_rate_num == 0) {
+      context->desc.h264enc.rate_ctrl.frame_rate_num = 30;
+      context->desc.h264enc.rate_ctrl.frame_rate_den = 1;
+   }
+   context->desc.h264enc.rate_ctrl.vbv_buf_lv = 48;
+   context->desc.h264enc.rate_ctrl.fill_data_enable = 1;
+   context->desc.h264enc.rate_ctrl.enforce_hrd = 1;
+   context->desc.h264enc.enable_vui = false;
+   context->desc.h264enc.rate_ctrl.target_bits_picture =
+	   context->desc.h264enc.rate_ctrl.target_bitrate / context->desc.h264enc.rate_ctrl.frame_rate_num;
+   context->desc.h264enc.rate_ctrl.peak_bits_picture_integer =
+	   context->desc.h264enc.rate_ctrl.peak_bitrate / context->desc.h264enc.rate_ctrl.frame_rate_num;
+   context->desc.h264enc.rate_ctrl.peak_bits_picture_fraction = 0;
+
+   context->desc.h264enc.ref_pic_mode = 0x00000201;
+}
+
 static VAStatus
 handlePictureParameterBuffer(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
 {
@@ -514,6 +549,7 @@ vlVaEndPicture(VADriverContextP ctx, VAContextID context_id)
 
    if (context->decoder->entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE) {
       coded_buf = context->coded_buf;
+      getEncParamPreset(context);
       context->decoder->begin_frame(context->decoder, context->target, &context->desc.base);
       context->decoder->encode_bitstream(context->decoder, context->target,
                                          coded_buf->derived_surface.resource, &feedback);
-- 
2.7.4



More information about the mesa-dev mailing list