vaapi_h264: Fix HRD bit_rate/cpb_size scaling
authorMark Thompson <sw@jkqxz.net>
Mon, 12 Sep 2016 23:25:07 +0000 (00:25 +0100)
committerMark Thompson <sw@jkqxz.net>
Wed, 14 Sep 2016 19:48:36 +0000 (20:48 +0100)
There should be an extra offset of 6 on bit_rate_scale and of 4 on
cpb_size_scale which were not accounted for here.

libavcodec/vaapi_encode_h264.c

index 5bd5605..9d6ff27 100644 (file)
@@ -861,14 +861,14 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
             // Try to scale these to a sensible range so that the
             // golomb encode of the value is not overlong.
             mseq->bit_rate_scale =
-                av_clip(av_log2(avctx->bit_rate) - 15, 0, 15);
+                av_clip_uintp2(av_log2(avctx->bit_rate) - 15 - 6, 4);
             mseq->bit_rate_value_minus1[0] =
-                (avctx->bit_rate >> mseq->bit_rate_scale) - 1;
+                (avctx->bit_rate >> mseq->bit_rate_scale + 6) - 1;
 
             mseq->cpb_size_scale =
-                av_clip(av_log2(priv->hrd_params.hrd.buffer_size) - 15, 0, 15);
+                av_clip_uintp2(av_log2(priv->hrd_params.hrd.buffer_size) - 15 - 4, 4);
             mseq->cpb_size_value_minus1[0] =
-                (priv->hrd_params.hrd.buffer_size >> mseq->cpb_size_scale) - 1;
+                (priv->hrd_params.hrd.buffer_size >> mseq->cpb_size_scale + 4) - 1;
 
             // CBR mode isn't actually available here, despite naming.
             mseq->cbr_flag[0] = 0;