[FFmpeg-devel] [PATCH] lavc/qsvdec: reinit if the resolution changes little

Linjie Fu linjie.fu at intel.com
Wed Feb 13 12:00:10 EET 2019


Currently, resolution change detection is based on 16 alignment,
small resolution changes (same after FFALIGN 16) in coded width or
coded height will not trigger the reinit and will lead to a decode
failure.

Modify to use last_coded_width and last_coded_height to detect the
small resolution change.

Signed-off-by: Linjie Fu <linjie.fu at intel.com>
---
 libavcodec/qsvdec.c | 8 +++++---
 libavcodec/qsvdec.h | 2 ++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 4a0be811fb..b29f869366 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -523,9 +523,9 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
 
     avctx->field_order  = q->parser->field_order;
     /* TODO: flush delayed frames on reinit */
-    if (q->parser->format       != q->orig_pix_fmt    ||
-        FFALIGN(q->parser->coded_width, 16)  != FFALIGN(avctx->coded_width, 16) ||
-        FFALIGN(q->parser->coded_height, 16) != FFALIGN(avctx->coded_height, 16)) {
+    if (q->parser->format != q->orig_pix_fmt ||
+        q->last_coded_height != q->parser->coded_height ||
+        q->last_coded_width !=  q->parser->coded_width) {
         enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
                                            AV_PIX_FMT_NONE,
                                            AV_PIX_FMT_NONE };
@@ -558,6 +558,8 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
         avctx->coded_height = FFALIGN(q->parser->coded_height, 16);
         avctx->level        = q->avctx_internal->level;
         avctx->profile      = q->avctx_internal->profile;
+        q->last_coded_width = q->parser->coded_width;
+        q->last_coded_height = q->parser->coded_height;
 
         ret = ff_get_format(avctx, pix_fmts);
         if (ret < 0)
diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h
index 111536caba..1af0c42404 100644
--- a/libavcodec/qsvdec.h
+++ b/libavcodec/qsvdec.h
@@ -55,6 +55,8 @@ typedef struct QSVContext {
     int zero_consume_run;
     int buffered_count;
     int reinit_flag;
+    int last_coded_width;
+    int last_coded_height;
 
     // the internal parser and codec context for parsing the data
     AVCodecParserContext *parser;
-- 
2.17.1



More information about the ffmpeg-devel mailing list