[Mesa-dev] [PATCH 2/2] st/va: fix gop size for rate control

boyuan.zhang at amd.com boyuan.zhang at amd.com
Fri Nov 11 16:27:25 UTC 2016


From: Boyuan Zhang <boyuan.zhang at amd.com>

The gop_size in rate control is the budget window for internal rate
control calculation, and shouldn't always equal to idr period. Define 
a coefficient to let budget window contains a number of idr period for
proper rate control calculation. Adjust the number of i/p frame remaining
accordingly.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=98005

Signed-off-by: Boyuan Zhang <boyuan.zhang at amd.com>
---
 src/gallium/state_trackers/va/picture.c    | 14 ++++++++------
 src/gallium/state_trackers/va/va_private.h |  1 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/gallium/state_trackers/va/picture.c b/src/gallium/state_trackers/va/picture.c
index a49c790..14d6d06 100644
--- a/src/gallium/state_trackers/va/picture.c
+++ b/src/gallium/state_trackers/va/picture.c
@@ -351,7 +351,7 @@ handleVAEncSequenceParameterBufferType(vlVaDriver *drv, vlVaContext *context, vl
       if (!context->decoder)
          return VA_STATUS_ERROR_ALLOCATION_FAILED;
    }
-   context->desc.h264enc.gop_size = h264->intra_idr_period;
+   context->desc.h264enc.gop_size = h264->intra_idr_period * VL_VA_ENC_GOP_COEFF;
    context->desc.h264enc.rate_ctrl.frame_rate_num = h264->time_scale / 2;
    context->desc.h264enc.rate_ctrl.frame_rate_den = 1;
    return VA_STATUS_SUCCESS;
@@ -391,10 +391,10 @@ handleVAEncPictureParameterBufferType(vlVaDriver *drv, vlVaContext *context, vlV
    context->desc.h264enc.not_referenced = false;
    context->desc.h264enc.is_idr = (h264->pic_fields.bits.idr_pic_flag == 1);
    context->desc.h264enc.pic_order_cnt = h264->CurrPic.TopFieldOrderCnt;
-   if (context->desc.h264enc.is_idr)
-      context->desc.h264enc.i_remain = 1;
-   else
-      context->desc.h264enc.i_remain = 0;
+   if (context->desc.h264enc.gop_cnt == 0)
+      context->desc.h264enc.i_remain = VL_VA_ENC_GOP_COEFF;
+   else if (context->desc.h264enc.frame_num == 1)
+      context->desc.h264enc.i_remain--;
 
    context->desc.h264enc.p_remain = context->desc.h264enc.gop_size - context->desc.h264enc.gop_cnt - context->desc.h264enc.i_remain;
 
@@ -578,9 +578,11 @@ vlVaEndPicture(VADriverContextP ctx, VAContextID context_id)
 
    context->decoder->end_frame(context->decoder, context->target, &context->desc.base);
    if (context->decoder->entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE) {
+      int idr_period = context->desc.h264enc.gop_size / VL_VA_ENC_GOP_COEFF;
+      int p_remain_in_idr = idr_period - context->desc.h264enc.frame_num;
       surf->frame_num_cnt = context->desc.h264enc.frame_num_cnt;
       surf->force_flushed = false;
-      if (context->first_single_submitted || (context->desc.h264enc.p_remain == 1)) {
+      if (context->first_single_submitted || (p_remain_in_idr == 1)) {
          context->decoder->flush(context->decoder);
          context->first_single_submitted = false;
          surf->force_flushed = true;
diff --git a/src/gallium/state_trackers/va/va_private.h b/src/gallium/state_trackers/va/va_private.h
index 9e3ba03..89c9532 100644
--- a/src/gallium/state_trackers/va/va_private.h
+++ b/src/gallium/state_trackers/va/va_private.h
@@ -50,6 +50,7 @@
 #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
 
 #define VL_VA_MAX_IMAGE_FORMATS 9
+#define VL_VA_ENC_GOP_COEFF 16
 
 static inline enum pipe_video_chroma_format
 ChromaToPipe(int format)
-- 
2.7.4



More information about the mesa-dev mailing list