From patchwork Tue Jun 11 19:19:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 13499 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 5B979445EC6 for ; Tue, 11 Jun 2019 10:20:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 38F866800F8; Tue, 11 Jun 2019 10:20:24 +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 AF39B6800D2 for ; Tue, 11 Jun 2019 10:20:17 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2019 00:20:14 -0700 X-ExtLoop1: 1 Received: from icl-dev.sh.intel.com ([10.239.158.32]) by fmsmga007.fm.intel.com with ESMTP; 11 Jun 2019 00:20:13 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jun 2019 15:19:30 -0400 Message-Id: <1560280770-3760-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH, RFC] lavc/vp9dec: fix the multi-thread HWAccel decode error 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" Fix the multi-thread HWAccel decode error for vp9. VP9 supports the resolution changing. In multi-thread mode, worker-threads destroy and free the first created VAAPIDecodeContext if resolution change happens and create new one. Other threads still request to destroy previous and demand for new context. This leads to decode failures and memory issue. Modify to call hwaccel_uninit/hwaccel_init by ff_thread_get_format only when the first-come thread detected the resolution changing. Signed-off-by: Linjie Fu --- Fix the same issue vaapi_vp8 decoding meets: https://patchwork.ffmpeg.org/patch/12507/ libavcodec/vp9.c | 18 ++++++++++++++---- libavcodec/vp9dec.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index acf3ffc..e2fad9d 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -179,6 +179,7 @@ static int update_size(AVCodecContext *avctx, int w, int h) uint8_t *p; int bytesperpixel = s->bytesperpixel, ret, cols, rows; int lflvl_len, i; + int dim_reset = 0; av_assert0(w > 0 && h > 0); @@ -186,6 +187,10 @@ static int update_size(AVCodecContext *avctx, int w, int h) if ((ret = ff_set_dimensions(avctx, w, h)) < 0) return ret; + if (!avctx->internal->hwaccel_priv_data || + s->context == avctx->internal->hwaccel_priv_data) + dim_reset = 1; + switch (s->pix_fmt) { case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUV420P10: @@ -216,16 +221,21 @@ static int update_size(AVCodecContext *avctx, int w, int h) *fmtp++ = s->pix_fmt; *fmtp = AV_PIX_FMT_NONE; - ret = ff_thread_get_format(avctx, pix_fmts); - if (ret < 0) - return ret; + if (dim_reset) { + ret = ff_thread_get_format(avctx, pix_fmts); + if (ret < 0) + return ret; + + avctx->pix_fmt = ret; + } - avctx->pix_fmt = ret; s->gf_fmt = s->pix_fmt; s->w = w; s->h = h; } + s->context = avctx->internal->hwaccel_priv_data; + cols = (w + 7) >> 3; rows = (h + 7) >> 3; diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h index 66573ed..bc3f36c 100644 --- a/libavcodec/vp9dec.h +++ b/libavcodec/vp9dec.h @@ -152,6 +152,8 @@ typedef struct VP9Context { int block_alloc_using_2pass; uint16_t mvscale[3][2]; uint8_t mvstep[3][2]; + + void *context; } VP9Context; struct VP9TileData {