From patchwork Mon Oct 23 07:43:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhong Li X-Patchwork-Id: 5657 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp6455604jah; Mon, 23 Oct 2017 00:46:48 -0700 (PDT) X-Google-Smtp-Source: ABhQp+S0RX6IQunLbBm3nbrfEg/U5sHEZY2a6gylELOQOtU+KsSJP9C4xA+rZTb1fu2fIDUhEe9d X-Received: by 10.223.173.104 with SMTP id p95mr9632668wrc.209.1508744808787; Mon, 23 Oct 2017 00:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508744808; cv=none; d=google.com; s=arc-20160816; b=E8DxG1bq+tkIV04MffWL+Ux6ZkFPZt9vMkqd0OJr5ZguDIM4/bapq9AfAurZjuai3K TzhfMDsofUEBV5rhpwPJ7lPCYu9164SkJ+sobPoUU74ghJubxo+66EhKPVC1VwgAgSYk MMJURP08uVoO1tHgiSIvw90Kcf4jnN9mBgzr5g7VpepXOUitG4c70jXYizZxuTCySuEj 0FCiWtkWZpIzUc4jI4CulOq7AcPk1GTvvWBxxjBn3CsU4EvFzuAOYnHqgy6Hobc0a8Xe kd7qqh99/51bwDYTkyPKlb9Jy72caJW1SPESptbPpreUhsAxoLwVAbZ9H1+XwW0sTQYH YOGw== 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=YE+mqcf9EcfCb0V/WAgeWyUrEO6smnaZLcjeul6vvls=; b=UN8NvdWzFQ+BY3KpxnsXY3aULdltewE6ggnBQrnohHNx0TE/QQtQf7vYZAkLefWPoU OCbT6lmY6jVYMps1I4DynX4cnIlAdoswLKyE2knaK+7immscp9tinE99kudgGsPrCW3e Gio+B5oFxxYawO0plXcTfMUied7r6XzGVJ+MZXRtdxFsuaScOGeroljqCbQa9Zz317UU E7txGy9LwXy+emPFraud7YE4WYGwwxR3sjcSIf31a2z25vk/s5j3NhXm+dHs3+b5R90+ Dq47t/kYnQvU3NaUXO7W9vJs/c9tuEJuyjz7Vzq4asFiI2A88uO4zfvW0WdaG1Q0Ss0W hncA== 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 f11si4951790wrg.44.2017.10.23.00.46.47; Mon, 23 Oct 2017 00:46:48 -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 E74E3689C96; Mon, 23 Oct 2017 10:46:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 19753689B98 for ; Mon, 23 Oct 2017 10:46:32 +0300 (EEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2017 00:46:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.43,421,1503385200"; d="scan'208"; a="1208859229" Received: from bluekbl.sh.intel.com (HELO bluekbl.\040none\041) ([10.239.159.160]) by fmsmga001.fm.intel.com with ESMTP; 23 Oct 2017 00:46:16 -0700 From: Zhong Li To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Oct 2017 15:43:31 +0800 Message-Id: <20171023074331.1603-2-zhong.li@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171023074331.1603-1-zhong.li@intel.com> References: <20171023074331.1603-1-zhong.li@intel.com> Subject: [FFmpeg-devel] [PATCH V4 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" some reference pictures are not existed but valid 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..b6391ea216 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); + av_assert0(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); + av_assert0(ref != VDP_INVALID_HANDLE); + info->forward_reference = ref; + } } info->slice_count = 0;