From: Wenbin Chen <wenbin.chen-at-intel.com@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 2/3] libavcodec/qsvdec: remove redundant decodeHeader() Date: Fri, 18 Mar 2022 14:25:10 +0800 Message-ID: <20220318062511.382951-2-wenbin.chen@intel.com> (raw) In-Reply-To: <20220318062511.382951-1-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 | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 0b5e416867..210bd0c1d5 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -82,7 +82,6 @@ typedef struct QSVContext { AVFifo *async_fifo; int zero_consume_run; - int buffered_count; int reinit_flag; enum AVPixelFormat orig_pix_fmt; @@ -653,8 +652,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; } @@ -787,20 +784,24 @@ 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, ¶m); - - 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 (ret < 0 || *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->initialized) { q->reinit_flag = 0; + ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m); + if (ret < 0) { + if (ret == AVERROR(EAGAIN)) + av_log(avctx, AV_LOG_INFO, "More data is required to decode header\n"); + else + 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.32.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-03-18 6:26 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-18 6:25 [FFmpeg-devel] [PATCH v2 1/3] libavcodec/qsvdec: reinit decoder according to decode() return value Wenbin Chen 2022-03-18 6:25 ` Wenbin Chen [this message] 2022-03-18 6:25 ` [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size Wenbin Chen 2022-03-18 7:40 ` Soft Works 2022-03-28 2:26 ` Xiang, Haihao 2022-04-02 8:52 ` Xiang, Haihao 2022-04-06 12:01 ` Xiang, Haihao
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220318062511.382951-2-wenbin.chen@intel.com \ --to=wenbin.chen-at-intel.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git