From patchwork Mon Apr 22 21:23:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 48228 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:2d06:b0:1a9:af23:56c1 with SMTP id tw6csp33217pzb; Mon, 22 Apr 2024 14:23:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWNG7kAc1x4lMF4jPe9znA9VixYsrNT6oVvzipVSaSzb5x9CZLexPe2xh7iLI53glM2MwFtMIvAvhIElDnTJvUHGjjjmdrAMm7Y/w== X-Google-Smtp-Source: AGHT+IH8+leEFOq6CrXIe/SEMNaCtZpxhqG6HavaQNGCTtyVDfdG83915RdL9PgmPncusxva/c8a X-Received: by 2002:a17:906:db03:b0:a55:b062:3bfd with SMTP id xj3-20020a170906db0300b00a55b0623bfdmr4393119ejb.35.1713820991425; Mon, 22 Apr 2024 14:23:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713820991; cv=none; d=google.com; s=arc-20160816; b=qbaKg/A0+1NEcrHJEhnkQeRpcQT9Z2OGjqrB06UkQs2G781tuZPxpyNCN/hF5GMb+g EbRGXxrEqZlERORiq42tSzTqZNDUoG5l6XAdW2jBeQcEph21nYKF/+YM/g7EPOncYvfd FLv9kycB3BoJns9J4MrZZl+aN4RS5VWVdv0t5vEHu+P2r7RtcWIGIcF8PnEy6xSwB4pa IEd+jQOsO7vhG8bTNho1ltSKBsgOsOfqUTD4HFIgdwnMrUUeh0kgPAZFESNfHeMCD1Yr ZSlwZLQ/CcNvV/Nxi8JoYOEZXn8djO+NbFZ9jUXVAFjDnd3elMTLpfY2vloOc2SrWkIw RHLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:in-reply-to:references:to:from:content-language :user-agent:mime-version:date:message-id:dkim-signature:delivered-to; bh=f9RKh/SlMS42ifDsLHU8c8whtPIxoXCnBhLbhHd+pT0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=U5A2rv3ztNJL8TN1pkkuh7nklr0CncRsHgiOaRJUEp6d6UDhGCjjLgyPJtAfGXIF/e pqBwfDDwNo4gi52Ouol/5gx8zUQ5PQttQtDKNELCO26ixzAKtAT233fY7aJv4YFHtOAa LWI0YXvzRSSGMjDqW2kBiq7VC7PA4kapeJHGm9EyV7Xcu3Xzy3TpbN7BRHX8P9lMGubC XL9smytTRM72WvXqXFo1tUubRTgFZNBvu0tFJgU64g/uDJZfxGE4Adc6v4g3Zf5YisVN 2k6I3u0YRqY4IvwtogqlsjhF6fSpTnPsP1G+QHssupkwCk4PcLx8Ic3DMCIJ+Yl9V8Ur yqmA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20230601.gappssmtp.com header.s=20230601 header.b=Q7JX1pDp; 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 i16-20020a170906a29000b00a525c60aeefsi6563692ejz.478.2024.04.22.14.23.06; Mon, 22 Apr 2024 14:23:11 -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; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20230601.gappssmtp.com header.s=20230601 header.b=Q7JX1pDp; 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 DEB8168D388; Tue, 23 Apr 2024 00:23:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CBEE968D0E0 for ; Tue, 23 Apr 2024 00:22:58 +0300 (EEST) Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-41a7ae25d53so8734695e9.1 for ; Mon, 22 Apr 2024 14:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20230601.gappssmtp.com; s=20230601; t=1713820978; x=1714425778; darn=ffmpeg.org; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=WyVuOWbG43077YFkY5UGZGsNkQkPKl/wfXzhnHULt+U=; b=Q7JX1pDpKwmxJLUsdXLIovvLcSxruu3rH9xCoOn7C7hENFJQE3txhO4EgMGm85FZ96 oM3wgg0NVLugUWXJwFR9Uu2ZbhteSufnLSZFiWSATlSa+dimLbrSUomUCvQ5trCmJSR0 kcXgcGPRVdvxT0B9kjHfM1m54ElNgdnzxhsY/6elsz3lKvKOF/HIjVS98hEGk9cBez9A NPoXcx+2/kTsvNTbvgGtn6AEUxBLM5T2zMuyRP8d2Sqdmc731xShH+6IpCPYf739ULjj zVu5N7yQGpBpiKfJhDABjmx/Wo4JtlNz3iHUM7yORkSbbJksCpQKDcXazxRYUd9SkePo vOHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713820978; x=1714425778; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WyVuOWbG43077YFkY5UGZGsNkQkPKl/wfXzhnHULt+U=; b=nIHlI4SKv/OW0meSvqLQ873cHCKkLdSKXDQJDxs5mnr+vk5R9WXaSuqXmyUyhGxYXO 6oZUFU/Hm1FxV9j4jb4rM7k2+zM3+NBBnh4kN2mN2hWHb1wnHWWP4/6XRql127CDGr+d us0VIr6giczOZvLjQUYy5p/yeG4c2kCQoktzLIHtg1oITopPploOyZes76/hJXiXkyfH tHM0q7yusG39rkS46gmjRYy4344MkT2s9vXfUi53P516Qf3NsVbZ3j4Uu4Ip5130RAz3 IR6+4NMlpHoSM9PMfNcl1MTUFtwwc6DRlG8u98FbSKXLnwFcKJ9vdBvj33exu5QEFFcW ji9g== X-Gm-Message-State: AOJu0YxklIJDycfFQXHt6LXRIZhX3WTH8X5O/h8jPVj1vp+S32yBqszT dQExHljzQhAWzL0RSH9iLPr2mhBmlG5EsBK3L1AzZH3Xh5uE1Z7rbHgyXat7iiLnED+6vbmqpM7 V X-Received: by 2002:a05:600c:314e:b0:41a:44da:896d with SMTP id h14-20020a05600c314e00b0041a44da896dmr3562730wmo.34.1713820978027; Mon, 22 Apr 2024 14:22:58 -0700 (PDT) Received: from [192.168.0.15] (cpc92302-cmbg19-2-0-cust1183.5-4.cable.virginm.net. [82.1.212.160]) by smtp.gmail.com with ESMTPSA id t6-20020a05600c450600b0041a3e724fc5sm6004402wmo.19.2024.04.22.14.22.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 14:22:57 -0700 (PDT) Message-ID: Date: Mon, 22 Apr 2024 22:23:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Mark Thompson To: ffmpeg-devel@ffmpeg.org References: <20240318042111.21983-1-fei.w.wang@intel.com> <90d041b98b5d9ba69b093d9dcae168130389b364.camel@intel.com> <1fa0491e-4609-49ae-bad4-820ea63a52b0@jkqxz.net> <6aca0a524bb0862d07f6469097a4c1b1a991e222.camel@intel.com> <4bccfe20-83a0-4c8f-a6d3-974faf064dbc@jkqxz.net> <1bcdfb6e-8d63-4d1f-9cd9-631e79c03f5f@jkqxz.net> In-Reply-To: <1bcdfb6e-8d63-4d1f-9cd9-631e79c03f5f@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_hevc: Don't require exact profiles X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 25CvUTOh1+cz Rather than turning the constraint flags into a single profile and then searching for that profile (and failing if it doesn't match any profile exactly), instead search all supported profiles and use the first one which supports the given set of constraint flags. --- This fixes decode of rext 8-bit 4:2:0; it will correctly pick Main 12 or Main 4:2:2 10 or Main 4:4:4 (first one available) to use as the decoding profile after this patch. libavcodec/vaapi_decode.c | 45 ++++++++++++------- libavcodec/vaapi_hevc.c | 95 +++++++++++++++++++++------------------ libavcodec/vaapi_hevc.h | 4 +- 3 files changed, 83 insertions(+), 61 deletions(-) diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index 21b273cd0f..f1327464f5 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -387,7 +387,9 @@ static const struct { enum AVCodecID codec_id; int codec_profile; VAProfile va_profile; - VAProfile (*profile_parser)(AVCodecContext *avctx); + VAProfile (*match_profile)(AVCodecContext *avctx, + const VAProfile *profile_list, + int profile_count); } vaapi_profile_map[] = { #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ } MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ), @@ -414,9 +416,9 @@ static const struct { #endif #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL MAP(HEVC, HEVC_REXT, None, - ff_vaapi_parse_hevc_rext_scc_profile ), + ff_vaapi_hevc_match_rext_scc_profile ), MAP(HEVC, HEVC_SCC, None, - ff_vaapi_parse_hevc_rext_scc_profile ), + ff_vaapi_hevc_match_rext_scc_profile ), #endif MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT, JPEGBaseline), @@ -499,22 +501,33 @@ static int vaapi_decode_make_config(AVCodecContext *avctx, vaapi_profile_map[i].codec_profile == AV_PROFILE_UNKNOWN) profile_match = 1; - va_profile = vaapi_profile_map[i].profile_parser ? - vaapi_profile_map[i].profile_parser(avctx) : - vaapi_profile_map[i].va_profile; codec_profile = vaapi_profile_map[i].codec_profile; - - for (j = 0; j < profile_count; j++) { - if (va_profile == profile_list[j]) { - exact_match = profile_match; + if (vaapi_profile_map[i].match_profile) { + va_profile = + vaapi_profile_map[i].match_profile(avctx, profile_list, + profile_count); + if (va_profile != VAProfileNone) { + matched_va_profile = va_profile; + matched_ff_profile = codec_profile; + exact_match = 1; break; } - } - if (j < profile_count) { - matched_va_profile = va_profile; - matched_ff_profile = codec_profile; - if (exact_match) - break; + } else { + va_profile = vaapi_profile_map[i].va_profile; + + for (j = 0; j < profile_count; j++) { + if (va_profile == profile_list[j]) { + exact_match = profile_match; + break; + } + } + + if (j < profile_count) { + matched_va_profile = va_profile; + matched_ff_profile = codec_profile; + if (exact_match) + break; + } } } av_freep(&profile_list); diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c index 77f55ff8b1..28f7c9280e 100644 --- a/libavcodec/vaapi_hevc.c +++ b/libavcodec/vaapi_hevc.c @@ -590,63 +590,70 @@ static int ptl_convert(const PTLCommon *general_ptl, H265RawProfileTierLevel *h2 } /* - * Find exact va_profile for HEVC Range Extension and Screen Content Coding Extension + * Find compatible va_profile for HEVC Range Extension and Screen + * Content Coding Extension profiles. */ -VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx) +VAProfile ff_vaapi_hevc_match_rext_scc_profile(AVCodecContext *avctx, + const VAProfile *profile_list, + int profile_count) { 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; H265RawProfileTierLevel h265_raw_ptl = {0}; + static const struct { + int profile; + VAProfile va_profile; + } map[] = { +#if VA_CHECK_VERSION(1, 2, 0) + { H265_PROFILE_MAIN_12, + VAProfileHEVCMain12 }, + { H265_PROFILE_MAIN_422_10, + VAProfileHEVCMain422_10 }, + { H265_PROFILE_MAIN_444, + VAProfileHEVCMain444 }, + { H265_PROFILE_MAIN_444_10, + VAProfileHEVCMain444_10 }, + { H265_PROFILE_MAIN_444_12, + VAProfileHEVCMain444_12 }, + { H265_PROFILE_SCREEN_EXTENDED_MAIN, + VAProfileHEVCSccMain }, + { H265_PROFILE_SCREEN_EXTENDED_MAIN_10, + VAProfileHEVCSccMain10 }, +#endif +#if VA_CHECK_VERSION(1, 8, 0) + { H265_PROFILE_SCREEN_EXTENDED_MAIN_444, + VAProfileHEVCSccMain444 }, +#endif + }; + /* convert PTLCommon to H265RawProfileTierLevel */ ptl_convert(general_ptl, &h265_raw_ptl); - profile = ff_h265_find_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); + for (int i = 0; i < FF_ARRAY_ELEMS(map); i++) { + int available = 0; + for (int j = 0; j < profile_count; j++) { + if (profile_list[j] == map[i].va_profile) { + available = 1; + break; + } + } + if (!available) + continue; + + if (ff_h265_profile_compatible(&h265_raw_ptl, + map[i].profile)) { + const H265ProfileDescriptor *profile_desc = + ff_h265_get_profile(map[i].profile); + av_log(avctx, AV_LOG_VERBOSE, + "Decoding with HEVC profile %s.\n", + profile_desc->name); + return map[i].va_profile; + } } -#if VA_CHECK_VERSION(1, 2, 0) - if (!strcmp(profile->name, "Main 12") || - !strcmp(profile->name, "Main 12 Intra")) - return VAProfileHEVCMain12; - else 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:2:2 12") || - !strcmp(profile->name, "Main 4:2:2 12 Intra")) - return VAProfileHEVCMain422_12; - 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 if (!strcmp(profile->name, "Main 4:4:4 12") || - !strcmp(profile->name, "Main 4:4:4 12 Intra")) - return VAProfileHEVCMain444_12; - else if (!strcmp(profile->name, "Screen-Extended Main")) - return VAProfileHEVCSccMain; - else if (!strcmp(profile->name, "Screen-Extended Main 10")) - return VAProfileHEVCSccMain10; - else if (!strcmp(profile->name, "Screen-Extended Main 4:4:4")) - return VAProfileHEVCSccMain444; -#if VA_CHECK_VERSION(1, 8, 0) - else if (!strcmp(profile->name, "Screen-Extended Main 4:4:4 10")) - return VAProfileHEVCSccMain444_10; -#endif -#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 selecting Main profile if profile mismatch is allowed return VAProfileHEVCMain; diff --git a/libavcodec/vaapi_hevc.h b/libavcodec/vaapi_hevc.h index 449635d0d7..455c68e6ba 100644 --- a/libavcodec/vaapi_hevc.h +++ b/libavcodec/vaapi_hevc.h @@ -22,6 +22,8 @@ #include #include "avcodec.h" -VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx); +VAProfile ff_vaapi_hevc_match_rext_scc_profile(AVCodecContext *avctx, + const VAProfile *profile_list, + int profile_count); #endif /* AVCODEC_VAAPI_HEVC_H */