diff mbox

[FFmpeg-devel,v2,2/5] vaapi_encode_mpeg2: Use common slice sizing code

Message ID 20180923215300.2077-2-sw@jkqxz.net
State Accepted
Commit 29816e278f4ff22f50d9c831e3cf5f4d1b0e0214
Headers show

Commit Message

Mark Thompson Sept. 23, 2018, 9:52 p.m. UTC
---
 libavcodec/vaapi_encode_mpeg2.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index 1377eeb9bb..99a8b43237 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -35,9 +35,6 @@  typedef struct VAAPIEncodeMPEG2Context {
     int level;
 
     // Derived settings.
-    int mb_width;
-    int mb_height;
-
     int quant_i;
     int quant_p;
     int quant_b;
@@ -477,8 +474,6 @@  static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx,
     vpic->f_code[1][0]       = pce->f_code[1][0];
     vpic->f_code[1][1]       = pce->f_code[1][1];
 
-    pic->nb_slices = priv->mb_height;
-
     return 0;
 }
 
@@ -490,8 +485,8 @@  static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx,
     VAEncSliceParameterBufferMPEG2   *vslice = slice->codec_slice_params;
     int qp;
 
-    vslice->macroblock_address = priv->mb_width * slice->index;
-    vslice->num_macroblocks    = priv->mb_width;
+    vslice->macroblock_address = slice->block_start;
+    vslice->num_macroblocks    = slice->block_size;
 
     switch (pic->type) {
     case PICTURE_TYPE_IDR:
@@ -525,9 +520,6 @@  static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
     if (err < 0)
         return err;
 
-    priv->mb_width  = FFALIGN(avctx->width,  16) / 16;
-    priv->mb_height = FFALIGN(avctx->height, 16) / 16;
-
     if (ctx->va_rc_mode == VA_RC_CQP) {
         priv->quant_p = av_clip(avctx->global_quality, 1, 31);
         if (avctx->i_quant_factor > 0.0)
@@ -553,6 +545,12 @@  static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
         av_assert0(0 && "Invalid RC mode.");
     }
 
+    ctx->slice_block_rows = FFALIGN(avctx->width,  16) / 16;
+    ctx->slice_block_cols = FFALIGN(avctx->height, 16) / 16;
+
+    ctx->nb_slices  = ctx->slice_block_rows;
+    ctx->slice_size = 1;
+
     return 0;
 }