From patchwork Sun Jul 7 16:38:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 13839 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 29E39449F07 for ; Sun, 7 Jul 2019 07:41:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E606868AC7E; Sun, 7 Jul 2019 07:41:29 +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 04C1268AC60 for ; Sun, 7 Jul 2019 07:41:22 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2019 21:41:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,461,1557212400"; d="scan'208";a="175838993" Received: from icl-dev.sh.intel.com ([10.239.158.32]) by orsmga002.jf.intel.com with ESMTP; 06 Jul 2019 21:41:19 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 Jul 2019 12:38:38 -0400 Message-Id: <1562517518-1391-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH 1/2] lavc/decode: recreate hw_frames_ctx instead of return if already exists X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If hw_frames_ctx exists when calling ff_decode_get_hw_frames_ctx, it is allowed to be recreated instead of just return. Move hw_frames_ctx check outside ff_decode_get_hw_frames_ctx, and check in relevant code. Signed-off-by: Linjie Fu --- libavcodec/decode.c | 2 +- libavcodec/dxva2.c | 8 +++++--- libavcodec/vdpau.c | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6c31166..0863b82 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1230,7 +1230,7 @@ int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, return AVERROR(ENOSYS); if (avctx->hw_frames_ctx) - return 0; + av_buffer_unref(&avctx->hw_frames_ctx); if (!avctx->hw_device_ctx) { av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is " "required for hardware accelerated decoding.\n"); diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c index 3241611..0404064 100644 --- a/libavcodec/dxva2.c +++ b/libavcodec/dxva2.c @@ -661,9 +661,11 @@ int ff_dxva2_decode_init(AVCodecContext *avctx) // (avctx->pix_fmt is not updated yet at this point) sctx->pix_fmt = avctx->hwaccel->pix_fmt; - ret = ff_decode_get_hw_frames_ctx(avctx, dev_type); - if (ret < 0) - return ret; + if (!avctx->hw_frames_ctx) { + ret = ff_decode_get_hw_frames_ctx(avctx, dev_type); + if (ret < 0) + return ret; + } frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; sctx->device_ctx = frames_ctx->device_ctx; diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c index 167f06d..b7a4e9c 100644 --- a/libavcodec/vdpau.c +++ b/libavcodec/vdpau.c @@ -178,10 +178,11 @@ int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, AVHWFramesContext *frames_ctx; AVVDPAUDeviceContext *dev_ctx; - ret = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VDPAU); - if (ret < 0) - return ret; - + if (!avctx->hw_frames_ctx) { + ret = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VDPAU); + if (ret < 0) + return ret; + } frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; dev_ctx = frames_ctx->device_ctx->hwctx;