From patchwork Mon Apr 26 03:03:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 27410 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp3598089iob; Sun, 25 Apr 2021 20:07:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0/E4iQ38+IKhMkAL2bEITZYXvyjRrI5qmxjTbPYWMG/ki6urTPx1knvj8o9+l/8dlgvGe X-Received: by 2002:aa7:db14:: with SMTP id t20mr18114933eds.311.1619406439840; Sun, 25 Apr 2021 20:07:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619406439; cv=none; d=google.com; s=arc-20160816; b=aTUfaUVFfHo3B55jdd6TKn2o5982FNwb5z188svFOxi7dgiVN1brIc8OF/Z5Xq49Vc AYxt6UZpTzvVp8EZ+yoaK3RI6atALre5z6DZzIb8esediGNU98ytejPpEAKZYVgfSAJD jd+PI4mLgubzZ9mkmq37vVVdf5P2DVLGcT7SXNljZSdhMiGH2PbEPFTIGw/VaDExJF5V rMOZBWXoF2LPrAjnRE0UxTiatqtV4+Lk3YXkqv+15AvIrZu9MGagoYtErniQ3ZWDCc3i U1kHaXA2hZdKLnuTNt20T0vNG+8N8Ii2GFHiF/UA6q3Rcs6wpKeApNeHM7CJ3xWNmaxr r3zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :ironport-sdr:ironport-sdr:delivered-to; bh=ZkBfnrTxt37lVcnJWPkbNv3Mm0TS/HJTrJ3UvonN+to=; b=HKhCMT7LMpTFyrbrNnUUK0KSAiZirWiBgXWIXXQn8JVWRk+k/d6fyLszZk+Djc5f3d H13E9KhJRxeKKRiH0RRrUJO3J8SwPUmIJnP51Xvu34H9lDg1NMd6J/QI2znZxtWLoqrU V6/Bbh1KVtbxDVBEXEA/2Rzz6wRhXC0ex0xKDGx9B48Zv5sSPJmG0f7FgxoEnd6CxWLv iK3t3uB/jlI07yjjZu3MyKB9/WLhauhnIe/Sisli3tUKBvknIL6RAaVVRRmDXyqVe0XV AzLSU2/sSQ+Ms81x9VSwJtikB6QdFcg09E9umviRK+/G4P/6ICBNil6ooG2T718Xh7+h 96nw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r17si11902248ejc.193.2021.04.25.20.07.19; Sun, 25 Apr 2021 20:07:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C69FC68994E; Mon, 26 Apr 2021 06:07:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9667C6891E7 for ; Mon, 26 Apr 2021 06:07:08 +0300 (EEST) IronPort-SDR: S91JIWuZ91EsR8dp9zLN73Q/hcVz6qSD4SzeMFdY7zbpG84Nc3cXrUNmYOHtjQoKLmlr4zmBa4 qgYcxiE+c8kg== X-IronPort-AV: E=McAfee;i="6200,9189,9965"; a="183406439" X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="183406439" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2021 20:07:04 -0700 IronPort-SDR: HoOo7KMXq7cPcQiiChGcjAUX49CkJsrQiLHMFh36izMLWbzINqAw0vy6q5EUr05TPJ9pUXqekD SEVgzwKYlDeg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="422435033" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.3]) by fmsmga008.fm.intel.com with ESMTP; 25 Apr 2021 20:07:03 -0700 From: wenbin.chen@intel.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Apr 2021 11:03:39 +0800 Message-Id: <20210426030341.3274799-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] libavcodec/qsvdec: reinit decoder according to decode() return value X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: "Chen,Wenbin" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: fzQS8Ni2DAXP From: "Chen,Wenbin" FFmpeg-qsv decoder reinit codec when width and height change, but there are not only resolution change need to reinit codec. I change it to use return value from DecodeFrameAsync() to decide whether decoder need to be reinitialized. Signed-off-by Wenbin Chen Signed-off-by Guangxin Xu --- libavcodec/qsvdec.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 5f2e641373..88232f5d8d 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -481,6 +481,13 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q, } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE); + if (ret == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) { + q->reinit_flag = 1; + av_log(avctx, AV_LOG_DEBUG, "Video parameter change\n"); + av_freep(&sync); + return 0; + } + if (ret != MFX_ERR_NONE && ret != MFX_ERR_MORE_DATA && ret != MFX_WRN_VIDEO_PARAM_CHANGED && @@ -632,9 +639,9 @@ static int qsv_process_data(AVCodecContext *avctx, QSVContext *q, ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m); - if (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) || + 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)) { + avctx->coded_height != param.mfx.FrameInfo.Height))) { AVPacket zero_pkt = {0}; if (q->buffered_count) { From patchwork Mon Apr 26 03:03:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 27411 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp3598182iob; Sun, 25 Apr 2021 20:07:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2jEhtpaiL5m3CawuNzoZb2gnF7GouvybcHdnCq4PNOjf1vhg30QGG0swdo1BliSb8JqJb X-Received: by 2002:a05:6402:416:: with SMTP id q22mr18534498edv.204.1619406451051; Sun, 25 Apr 2021 20:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619406451; cv=none; d=google.com; s=arc-20160816; b=qZWmtVeTbd2seyE+zn4a3SV+ZUKopWCBhYNB2rqCLec7L15P28N918n4Xw4+euCFlL SQkt1Yaer6Fy2e+njkqthUEgZ4lvM0EXPXs5oQkoFEQi0OOmZ94ulQaN5EWJZ7A/GVvg v2f4r502lnoOk5VtEyb5zvxtTDx40reV7yuDZnr/z84GEBRJri/yq88ZxB9dv82XIavR EtSrjyo03UpWpH2wTi0OoMqRglPWK983hmsOJ+GWJXb4eaSkPQs1OOKMpU+osPVUT87t QyMgMtBEc1XXnZvydSuPlBMqP0FL2WtgXdAxlTjQukCSZQQ8je0HOe5E/R7OB6/o0cJH NMrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:ironport-sdr:ironport-sdr:delivered-to; bh=g2lIgA4d1P7fbpmtYGPe9OnQ3SXd4vjF7f7tymrpeeo=; b=AmFpDlpP7IawL7eEP2U+3KopobCod/s81QJ7taosp/kXX8cHS7g6AbHr7fuJHCLZM+ 0s1+MY4CvR9KKPrhyMQ7g2jVYp53QkRmoIRqDyIlmKdgpsuhIkMWHn/b4ASYFvbddnnw vV5G1LVLPbzWBEeORe6IjYv8Zd8Kntm+4LQ3rnC2ACq72PQTpYJRrHBHhfjlq6fWN+ae tE5bGJ7WWF7ifXdjkTSKHrSjjSIATLxIwj1Rs/toMP3+o7utiVg8y7YOwkNMKscSz6O6 d8Dw52C7+fS6s5LtQHB2zhDngnQ0InMbJZM71aQs/o5B86VYJ/48s/DSB76BGRyDxpKg vVTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cy1si2284668edb.517.2021.04.25.20.07.30; Sun, 25 Apr 2021 20:07:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F2348689986; Mon, 26 Apr 2021 06:07:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D34426881BB for ; Mon, 26 Apr 2021 06:07:14 +0300 (EEST) IronPort-SDR: U2MD8NQ3F13XLoja6lD0kGoNjckjAw4ePxbhxGE1G3NwLDdl5fyM1AowTuDSuuc7vS/r4MjvLx X1oVWrl+A+kQ== X-IronPort-AV: E=McAfee;i="6200,9189,9965"; a="183406441" X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="183406441" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2021 20:07:06 -0700 IronPort-SDR: z7GRLfdfCfgF2M+GX2M2EvSobbz9s1w5hbkiiirAiU05FRLYciEJ8VBJxV6y8nGd37C9CTB2Fd 5ajj+mDzlvgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="422435051" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.3]) by fmsmga008.fm.intel.com with ESMTP; 25 Apr 2021 20:07:05 -0700 From: wenbin.chen@intel.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Apr 2021 11:03:40 +0800 Message-Id: <20210426030341.3274799-2-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210426030341.3274799-1-wenbin.chen@intel.com> References: <20210426030341.3274799-1-wenbin.chen@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] libavcodec/qsvdec: remove redundant decodeHeader() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: "Chen,Wenbin" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: D0KBCIQ3kByh From: "Chen,Wenbin" 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 Signed-off-by Guangxin Xu --- 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, ¶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 (*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, ¶m); + 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); From patchwork Mon Apr 26 03:03:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 27409 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp3598246iob; Sun, 25 Apr 2021 20:07:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWF4w9+EEBqSMQRXU9qpvVY97Nx5ZxMd63qxrmcD3iffwyKNolaWJXlzBOBJK08vR7gCc9 X-Received: by 2002:a17:906:38c5:: with SMTP id r5mr15708068ejd.230.1619406459789; Sun, 25 Apr 2021 20:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619406459; cv=none; d=google.com; s=arc-20160816; b=BBvQspF71tsAHatrRlVugVKM85LHc9ZmffvrKMiTXK57KVGYrrCFokgs4lG5yS+Lhh N3oywulQXBBPA6g5Gat+f4acqecoF46yAYSpeIE90ULPolPhRgr6SlGi57YGakJ3X37R L/GqBSRPH9mvxUjAK3m1sNX7I3q/lz381F7NM5kzy1LiK2ZuIxjuWEbRyfWGACHS5zSR 2pMfXpmaiHFuFQuEbUJRk6Gtdy6byFvPCkC1CWcHyO3N3k8A2Q6cBEc6nRGcT0qPiJ4k rN+0lKTU8ASJxdsIoyGmzUkjJzUKlxIy/9qpC7FBc/KIvyPQACp4meeNhGxwVyiiT9lj fhQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:ironport-sdr:ironport-sdr:delivered-to; bh=NB2LzzAuNJCzwdrPSz2Pj0ZJTERfdnWkRpDTCmr7R+E=; b=q2QdBdM6l9e2sI64him1md4ycgusK18/ptPQ0KwQXHh9sV/9MMbTOOdIXoGfnNg1bK tEo7FUcHHdOp533IdSygSKJasLQP+IAgU5Tt477UlwNy/WGrTwVA4vJs1wsTvgnI+3ai xLuldi/COIecVj3Kat2PW1Lsd93W5cAs8DhSMJBqnCFzYcPC6IAcTqvT9CNKOpoiKAFA Br3QBImOvEH1phxyVx88YzZ8MmnOvtIRwKrV46Gi3fZ2RvdUarhd+j12ObNBQXyU4fBB tZJ7yVKCAcwzjI0FBhvDWDsecuxqqK/fEmOBgH6jcJUJ84qIXR5VUgjjz6rLHXw3rSWp lXSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fy26si12587320ejb.76.2021.04.25.20.07.39; Sun, 25 Apr 2021 20:07:39 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 26392689A29; Mon, 26 Apr 2021 06:07:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 17CAF6899AB for ; Mon, 26 Apr 2021 06:07:22 +0300 (EEST) IronPort-SDR: s5pRatAO+Tz99x7HOvMnxAW9YEguejmq0T/UT0fJIllGGFUtQCApVkz3rhVQjQTmrVbChK/bFd sm2+635jUzpw== X-IronPort-AV: E=McAfee;i="6200,9189,9965"; a="257577157" X-IronPort-AV: E=Sophos;i="5.82,250,1613462400"; d="scan'208";a="257577157" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2021 20:07:20 -0700 IronPort-SDR: 4iMh7xMPlhl5m8g3SJdBvXAKu1PfbHeVZYfizm0S0Utp0CkAnoSo2ZQfuSLBOjW7j/ai9oM+4/ gpTTYL2WnXow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,251,1613462400"; d="scan'208";a="422435125" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.3]) by fmsmga008.fm.intel.com with ESMTP; 25 Apr 2021 20:07:19 -0700 From: wenbin.chen@intel.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Apr 2021 11:03:41 +0800 Message-Id: <20210426030341.3274799-3-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210426030341.3274799-1-wenbin.chen@intel.com> References: <20210426030341.3274799-1-wenbin.chen@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Wenbinc-Bin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nOXhLQu51KHE From: Wenbinc-Bin The init_pool_size is set to be 64 and it is too many. Use IOSurfQuery to get NumFrameSuggest which is the suggested number of frame that needed to be allocated when initializing the decoder. Considering that the hevc_qsv encoder uses the most frame buffer, async is 4 (default) and max_b_frames is 8 (default) and decoder may followed by VPP, use NumFrameSuggest + 16 to set init_pool_size. Sigend-off-by Wenbin Chen Signed-off-by Guangxin Xu --- fftools/ffmpeg_qsv.c | 9 ++++++++- libavcodec/qsvdec.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_qsv.c b/fftools/ffmpeg_qsv.c index 960c88b69d..3862dc1e7d 100644 --- a/fftools/ffmpeg_qsv.c +++ b/fftools/ffmpeg_qsv.c @@ -74,6 +74,7 @@ int qsv_init(AVCodecContext *s) InputStream *ist = s->opaque; AVHWFramesContext *frames_ctx; AVQSVFramesContext *frames_hwctx; + int suggest_pool_size; int ret; if (!hw_device_ctx) { @@ -82,6 +83,12 @@ int qsv_init(AVCodecContext *s) return ret; } + suggest_pool_size = 0; + if (ist->hw_frames_ctx) { + frames_ctx = (AVHWFramesContext *)ist->hw_frames_ctx->data; + suggest_pool_size = frames_ctx->initial_pool_size; + } + av_buffer_unref(&ist->hw_frames_ctx); ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx); if (!ist->hw_frames_ctx) @@ -94,7 +101,7 @@ int qsv_init(AVCodecContext *s) frames_ctx->height = FFALIGN(s->coded_height, 32); frames_ctx->format = AV_PIX_FMT_QSV; frames_ctx->sw_format = s->sw_pix_fmt; - frames_ctx->initial_pool_size = 64 + s->extra_hw_frames; + frames_ctx->initial_pool_size = suggest_pool_size + 16 + s->extra_hw_frames; frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; ret = av_hwframe_ctx_init(ist->hw_frames_ctx); diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index fe416e74ca..f7cd33cc74 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -643,18 +643,32 @@ static int qsv_process_data(AVCodecContext *avctx, QSVContext *q, } if (q->reinit_flag || !q->session) { + mfxFrameAllocRequest request; + AVHWFramesContext *hw_frames_ctx; + memset(&request, 0, sizeof(request)); + q->reinit_flag = 0; ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error decoding header\n"); goto reinit_fail; } + param.IOPattern = q->iopattern; q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC); avctx->coded_width = param.mfx.FrameInfo.Width; avctx->coded_height = param.mfx.FrameInfo.Height; + ret = MFXVideoDECODE_QueryIOSurf(q->session, ¶m, &request); + if (ret < 0) + return ff_qsv_print_error(avctx, ret, "Error querying IO surface"); + + if (avctx->hw_frames_ctx) { + hw_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; + hw_frames_ctx->initial_pool_size = request.NumFrameSuggested; + } + ret = qsv_decode_preinit(avctx, q, pix_fmt, ¶m); if (ret < 0) goto reinit_fail;