From patchwork Thu Oct 12 08:20:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhong Li X-Patchwork-Id: 5537 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp1613572jah; Thu, 12 Oct 2017 01:24:04 -0700 (PDT) X-Google-Smtp-Source: AOwi7QC8DSgPKnignqcgXzr6pn+FFODMaroMBlR/4aqhtzm3+ibg4U8gU21CJhy4Hj/qMkn6kB1d X-Received: by 10.223.176.183 with SMTP id i52mr1255860wra.4.1507796644388; Thu, 12 Oct 2017 01:24:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507796644; cv=none; d=google.com; s=arc-20160816; b=n/d24ifQ8EdMs3TqHBAJN8TqCfaQWppL+1kfUUrnBU/61QCy4VCu3/LLR+nyW3fMTv 2jeH3hfY1I6ST8Y50pNpBAM3wBJ9Ye4nxu1Tyz0J2gdEcph3amqpXu5j048/NGDh/koN 7YCB/Aux4DnUufWw2waA7dRaUw/lnOGpFXEuDfiIj545E8nic+D8aemY6Otgm3YjIRCe mSKVsbYAMRrMBYvUd/W5deFQu2yChwoDDIWFiHLzrkWAtLtxmuTkDysKdLRfWB88tgSy bXb7nJT/d0MEpM1dm3yggiWhDSxtGjDnqicT/c58xuJEPW8iW1AVCXaYa9DlfM/9pev5 rujg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=zvTY6erHSKMXBXACGr76f6Ryb853iNf3S85dPZeZ6rU=; b=LPOGvXaHMKD2Yi7dpGcbV+EKBlB8x949PXBIpFKhIhmdjNgvgGBCAadSzLW/IZ2AgE e3y5W+PbPK9JcJ5i7Lwltck6O4cX8zk/BVvVAu51XeRUboBoOCaIj/kOM4uiuGQv9xUa 1hLZQcsaxx0wnOkCclCgsJeGYoXG062kRGXqvvthU9sCfgbxrfA4gDqg+OvfPQwfNo8d mEP69uBbUUdG00Gz/t8OVzSKSfH0eJSrI905nPOgjRi0dPEp7myaAHwWmb4+jtRPaAq0 u6vCUj2QKtCTc6xjzdNDNoM+B9NSOxtpc5/CN9JE2V1D0MMLHq/9VBrCPBT9qBiy3Don LkcQ== 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b65si11360268wmd.92.2017.10.12.01.23.41; Thu, 12 Oct 2017 01:24:04 -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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C86E8689EF4; Thu, 12 Oct 2017 11:23:30 +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 0848F689DB1 for ; Thu, 12 Oct 2017 11:23:23 +0300 (EEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Oct 2017 01:23:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,365,1503385200"; d="scan'208";a="322376870" Received: from bluekbl.sh.intel.com (HELO bluekbl.\040none\041) ([10.239.159.160]) by fmsmga004.fm.intel.com with ESMTP; 12 Oct 2017 01:23:15 -0700 From: Zhong Li To: ffmpeg-devel@ffmpeg.org Date: Thu, 12 Oct 2017 16:20:45 +0800 Message-Id: <20171012082045.21146-2-zhong.li@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171012082045.21146-1-zhong.li@intel.com> References: <20171012082045.21146-1-zhong.li@intel.com> Subject: [FFmpeg-devel] [PATCH V3 2/2] hwaccel_mpeg: check reference pictures are available 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: Zhong Li , sw@jkqxz.net, jun.zhao@intel.com, nfxjfg@googlemail.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" some reference pictures are not existed but valiad surface_ids are set, (for example, the second field of the first key frame can be P_Picture_Type but there is no preivous frame.) then may cause some driver problems (e.g, segment fault on mesa/AMD driver). Signed-off-by: Zhong Li --- libavcodec/dxva2_mpeg2.c | 4 ++-- libavcodec/vaapi_mpeg2.c | 6 ++++-- libavcodec/vdpau_mpeg12.c | 15 ++++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c index b7c69378f0..9117a3d7b1 100644 --- a/libavcodec/dxva2_mpeg2.c +++ b/libavcodec/dxva2_mpeg2.c @@ -51,11 +51,11 @@ static void fill_picture_parameters(AVCodecContext *avctx, memset(pp, 0, sizeof(*pp)); pp->wDecodedPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, current_picture->f); pp->wDeblockedPictureIndex = 0; - if (s->pict_type != AV_PICTURE_TYPE_I) + if (s->pict_type != AV_PICTURE_TYPE_I && s->last_picture_ptr) pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_picture.f); else pp->wForwardRefPictureIndex = 0xffff; - if (s->pict_type == AV_PICTURE_TYPE_B) + if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr) pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_picture.f); else pp->wBackwardRefPictureIndex = 0xffff; diff --git a/libavcodec/vaapi_mpeg2.c b/libavcodec/vaapi_mpeg2.c index 0d197c9692..942711b39f 100644 --- a/libavcodec/vaapi_mpeg2.c +++ b/libavcodec/vaapi_mpeg2.c @@ -73,10 +73,12 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_ switch (s->pict_type) { case AV_PICTURE_TYPE_B: - pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_picture.f); + if (s->next_picture_ptr) + pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_picture.f); // fall-through case AV_PICTURE_TYPE_P: - pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_picture.f); + if (s->last_picture_ptr) + pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_picture.f); break; } diff --git a/libavcodec/vdpau_mpeg12.c b/libavcodec/vdpau_mpeg12.c index b657007ee7..6d73d45f1a 100644 --- a/libavcodec/vdpau_mpeg12.c +++ b/libavcodec/vdpau_mpeg12.c @@ -45,13 +45,18 @@ static int vdpau_mpeg_start_frame(AVCodecContext *avctx, switch (s->pict_type) { case AV_PICTURE_TYPE_B: - ref = ff_vdpau_get_surface_id(s->next_picture.f); - assert(ref != VDP_INVALID_HANDLE); - info->backward_reference = ref; + if (s->next_picture_ptr) { + ref = ff_vdpau_get_surface_id(s->next_picture.f); + assert(ref != VDP_INVALID_HANDLE); + info->backward_reference = ref; + } /* fall through to forward prediction */ case AV_PICTURE_TYPE_P: - ref = ff_vdpau_get_surface_id(s->last_picture.f); - info->forward_reference = ref; + if (s->last_picture_ptr) { + ref = ff_vdpau_get_surface_id(s->last_picture.f); + assert(ref != VDP_INVALID_HANDLE); + info->forward_reference = ref; + } } info->slice_count = 0;