From patchwork Wed Jan 15 07:01:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 17354 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 D639644AD2B for ; Wed, 15 Jan 2020 09:01:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BF71268B0D7; Wed, 15 Jan 2020 09:01:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A866568B0B8 for ; Wed, 15 Jan 2020 09:01:32 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2020 23:01:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,321,1574150400"; d="scan'208";a="225474226" Received: from unknown (HELO icl-dev.sh.intel.com) ([10.239.158.73]) by orsmga003.jf.intel.com with ESMTP; 14 Jan 2020 23:01:29 -0800 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Jan 2020 15:01:42 +0800 Message-Id: <1579071702-13109-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH 6/9] lavc/vaapi_hevc: add function to find exact va_profile for REXT 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" Add vaapi_parse_rext_profile and use profile constraint flags to determine the exact va_profile for HEVC_REXT. If profile mismatch is allowed, select Main profile by default. Add build object in Makefile for h265_profile_level dependency. Signed-off-by: Linjie Fu --- libavcodec/Makefile | 2 +- libavcodec/vaapi_hevc.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/vaapi_hevc.h | 27 +++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 libavcodec/vaapi_hevc.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index c1f35b4..7cb914d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -884,7 +884,7 @@ OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL) += dxva2_hevc.o OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o OBJS-$(CONFIG_HEVC_QSV_HWACCEL) += qsvdec_h2645.o -OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o +OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o h265_profile_level.o OBJS-$(CONFIG_HEVC_VDPAU_HWACCEL) += vdpau_hevc.o OBJS-$(CONFIG_MJPEG_NVDEC_HWACCEL) += nvdec_mjpeg.o OBJS-$(CONFIG_MJPEG_VAAPI_HWACCEL) += vaapi_mjpeg.o diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c index ee54e44..80696bf 100644 --- a/libavcodec/vaapi_hevc.c +++ b/libavcodec/vaapi_hevc.c @@ -27,6 +27,8 @@ #include "hevcdec.h" #include "hwaccel.h" #include "vaapi_decode.h" +#include "vaapi_hevc.h" +#include "h265_profile_level.h" typedef struct VAAPIDecodePictureHEVC { #if VA_CHECK_VERSION(1, 2, 0) @@ -487,6 +489,82 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx, return 0; } +static int ptl_convert(const PTLCommon *general_ptl, H265RawProfileTierLevel *h265_raw_ptl) +{ + h265_raw_ptl->general_profile_space = general_ptl->profile_space; + h265_raw_ptl->general_tier_flag = general_ptl->tier_flag; + h265_raw_ptl->general_profile_idc = general_ptl->profile_idc; + + memcpy(h265_raw_ptl->general_profile_compatibility_flag, + general_ptl->profile_compatibility_flag, 32 * sizeof(uint8_t)); + +#define copy_field(name) h265_raw_ptl->general_ ## name = general_ptl->name + copy_field(progressive_source_flag); + copy_field(interlaced_source_flag); + copy_field(non_packed_constraint_flag); + copy_field(frame_only_constraint_flag); + copy_field(max_12bit_constraint_flag); + copy_field(max_10bit_constraint_flag); + copy_field(max_422chroma_constraint_flag); + copy_field(max_420chroma_constraint_flag); + copy_field(max_monochrome_constraint_flag); + copy_field(intra_constraint_flag); + copy_field(one_picture_only_constraint_flag); + copy_field(lower_bit_rate_constraint_flag); + copy_field(max_14bit_constraint_flag); + copy_field(inbld_flag); + copy_field(level_idc); +#undef copy_field + + return 0; +} + +/* + * Find exact va_profile for HEVC Range Extension + */ +VAProfile ff_vaapi_parse_hevc_rext_profile(AVCodecContext *avctx) +{ + const HEVCContext *h = avctx->priv_data; + const HEVCSPS *sps = h->ps.sps; + const PTL *ptl = &(sps->ptl); + const PTLCommon *general_ptl = &(ptl->general_ptl); + const H265ProfileDescriptor *profile = NULL; + H265RawProfileTierLevel h265_raw_ptl = {0}; + + /* convert PTLCommon to H265RawProfileTierLevel */ + ptl_convert(general_ptl, &h265_raw_ptl); + + profile = ff_h265_get_profile(&h265_raw_ptl); + if (!profile) { + av_log(avctx, AV_LOG_WARNING, "HEVC profile is not found.\n"); + goto end; + } else { + av_log(avctx, AV_LOG_VERBOSE, "HEVC profile %s is found.\n", profile->name); + } + +#if VA_CHECK_VERSION(1, 2, 0) + if (!strcmp(profile->name, "Main 4:2:2 10") || + !strcmp(profile->name, "Main 4:2:2 10 Intra")) + return VAProfileHEVCMain422_10; + else if (!strcmp(profile->name, "Main 4:4:4") || + !strcmp(profile->name, "Main 4:4:4 Intra")) + return VAProfileHEVCMain444; + else if (!strcmp(profile->name, "Main 4:4:4 10") || + !strcmp(profile->name, "Main 4:4:4 10 Intra")) + return VAProfileHEVCMain444_10; +#else + av_log(avctx, AV_LOG_WARNING, "HEVC profile %s is " + "not supported with this VA version.\n", profile->name); +#endif + +end: + if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) { + // Default to select Main profile if profile mismatch is allowed + return VAProfileHEVCMain; + } else + return VAProfileNone; +} + const AVHWAccel ff_hevc_vaapi_hwaccel = { .name = "hevc_vaapi", .type = AVMEDIA_TYPE_VIDEO, diff --git a/libavcodec/vaapi_hevc.h b/libavcodec/vaapi_hevc.h new file mode 100644 index 0000000..b3b0e6f --- /dev/null +++ b/libavcodec/vaapi_hevc.h @@ -0,0 +1,27 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_VAAPI_HEVC_H +#define AVCODEC_VAAPI_HEVC_H + +#include +#include "avcodec.h" + +VAProfile ff_vaapi_parse_hevc_rext_profile(AVCodecContext *avctx); + +#endif /* AVCODEC_VAAPI_HEVC_H */