diff mbox series

[FFmpeg-devel,2/3] libavcodec/qsvdec: remove redundant decodeHeader()

Message ID 20210426030341.3274799-2-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel,1/3] libavcodec/qsvdec: reinit decoder according to decode() return value
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Chen, Wenbin April 26, 2021, 3:03 a.m. UTC
From: "Chen,Wenbin" <wenbin.chen@intel.com>

Since ffmpeg-qsv uses return value to reinit decoder, it doesn't need to
decode header each time. Move qsv_decode_header's position so that
it will be called only if codec needed to be reinitialized.
Rearrange the code of flushing decoder and re-init decoder operation.
Remove the buffer_count and use the got_frame to decide whether the
decoder is drain.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Signed-off-by Guangxin Xu <guangxin.xu@intel.com>
---
 libavcodec/qsvdec.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

Comments

Chen, Wenbin May 6, 2021, 3:06 a.m. UTC | #1
Ping on this patch.

> -----Original Message-----
> From: Chen, Wenbin <wenbin.chen@intel.com>
> Sent: Monday, April 26, 2021 11:04 AM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Chen, Wenbin <wenbin.chen@intel.com>
> Subject: [PATCH 2/3] libavcodec/qsvdec: remove redundant decodeHeader()
> 
> From: "Chen,Wenbin" <wenbin.chen@intel.com>
> 
> Since ffmpeg-qsv uses return value to reinit decoder, it doesn't need to
> decode header each time. Move qsv_decode_header's position so that
> it will be called only if codec needed to be reinitialized.
> Rearrange the code of flushing decoder and re-init decoder operation.
> Remove the buffer_count and use the got_frame to decide whether the
> decoder is drain.
> 
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> Signed-off-by Guangxin Xu <guangxin.xu@intel.com>
> ---
>  libavcodec/qsvdec.c | 26 ++++++++++++--------------
>  1 file changed, 12 insertions(+), 14 deletions(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 88232f5d8d..fe416e74ca 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -63,7 +63,6 @@ typedef struct QSVContext {
> 
>      AVFifoBuffer *async_fifo;
>      int zero_consume_run;
> -    int buffered_count;
>      int reinit_flag;
> 
>      enum AVPixelFormat orig_pix_fmt;
> @@ -504,8 +503,6 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
>          ++q->zero_consume_run;
>          if (q->zero_consume_run > 1)
>              ff_qsv_print_warning(avctx, ret, "A decode call did not consume any
> data");
> -    } else if (!*sync && bs.DataOffset) {
> -        ++q->buffered_count;
>      } else {
>          q->zero_consume_run = 0;
>      }
> @@ -637,20 +634,21 @@ static int qsv_process_data(AVCodecContext
> *avctx, QSVContext *q,
>      if (!avctx->coded_height)
>          avctx->coded_height = 720;
> 
> -    ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
> -
> -    if (q->reinit_flag || (ret >= 0 && (q->orig_pix_fmt !=
> ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
> -        avctx->coded_width  != param.mfx.FrameInfo.Width ||
> -        avctx->coded_height != param.mfx.FrameInfo.Height))) {
> +    /* decode zero-size pkt to flush the buffered pkt before reinit */
> +    if (q->reinit_flag) {
>          AVPacket zero_pkt = {0};
> +        ret = qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
> +        if (*got_frame)
> +            return ret;
> +    }
> 
> -        if (q->buffered_count) {
> -            q->reinit_flag = 1;
> -            /* decode zero-size pkt to flush the buffered pkt before reinit */
> -            q->buffered_count--;
> -            return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
> -        }
> +    if (q->reinit_flag || !q->session) {
>          q->reinit_flag = 0;
> +        ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
> +        if (ret < 0) {
> +            av_log(avctx, AV_LOG_ERROR, "Error decoding header\n");
> +            goto reinit_fail;
> +        }
> 
>          q->orig_pix_fmt = avctx->pix_fmt = pix_fmt =
> ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
> 
> --
> 2.25.1
diff mbox series

Patch

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 88232f5d8d..fe416e74ca 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -63,7 +63,6 @@  typedef struct QSVContext {
 
     AVFifoBuffer *async_fifo;
     int zero_consume_run;
-    int buffered_count;
     int reinit_flag;
 
     enum AVPixelFormat orig_pix_fmt;
@@ -504,8 +503,6 @@  static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
         ++q->zero_consume_run;
         if (q->zero_consume_run > 1)
             ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
-    } else if (!*sync && bs.DataOffset) {
-        ++q->buffered_count;
     } else {
         q->zero_consume_run = 0;
     }
@@ -637,20 +634,21 @@  static int qsv_process_data(AVCodecContext *avctx, QSVContext *q,
     if (!avctx->coded_height)
         avctx->coded_height = 720;
 
-    ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
-
-    if (q->reinit_flag || (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
-        avctx->coded_width  != param.mfx.FrameInfo.Width ||
-        avctx->coded_height != param.mfx.FrameInfo.Height))) {
+    /* decode zero-size pkt to flush the buffered pkt before reinit */
+    if (q->reinit_flag) {
         AVPacket zero_pkt = {0};
+        ret = qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
+        if (*got_frame)
+            return ret;
+    }
 
-        if (q->buffered_count) {
-            q->reinit_flag = 1;
-            /* decode zero-size pkt to flush the buffered pkt before reinit */
-            q->buffered_count--;
-            return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
-        }
+    if (q->reinit_flag || !q->session) {
         q->reinit_flag = 0;
+        ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
+        if (ret < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Error decoding header\n");
+            goto reinit_fail;
+        }
 
         q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);