From patchwork Mon Dec 26 06:34:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianfeng Zheng X-Patchwork-Id: 39754 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp2483638pzb; Sun, 25 Dec 2022 22:35:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXtqMwcle1S7anDKRb/Vq4koOgUDgRbSBt7JqfayGmONra+kXvUA5R+KXxhmWRRcaCMs1rkj X-Received: by 2002:a17:906:850c:b0:7c0:f4f8:582a with SMTP id i12-20020a170906850c00b007c0f4f8582amr15207143ejx.52.1672036511861; Sun, 25 Dec 2022 22:35:11 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v18-20020a056402349200b0047b405e7746si8852770edc.1.2022.12.25.22.35.10; Sun, 25 Dec 2022 22:35:11 -0800 (PST) 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; arc=fail (body hash mismatch); 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 155CC68B4E4; Mon, 26 Dec 2022 08:35:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from CHN02-BJS-obe.outbound.protection.partner.outlook.cn (mail-bjschn02on2093.outbound.protection.partner.outlook.cn [139.219.17.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AF2F468B305 for ; Mon, 26 Dec 2022 08:34:59 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mN4sZHsbImEHZ5yWQAmBm/+ezpjB4kp62Z5nSQviRqyfkpFmsps2V2ZQh1r76C3Hb4mUeMcvrF6P/Gq9+DuFNYlpx3IllbbuwjZHhyUgiLjL8p03nB1kRVg0aAxxjQgqIX8rkshpKYzDAqYcGLuoxx3mK19+zE6SywMy6s4b6amY2GcFg89Nb3N6Fpjnk/6hBvcxmknGHqssdHGs0YumWilizB+Qyk+8kJFE73CnJJ/JnUg8aXxFgGZw1lLIVbZywIMItRQuEuiDA7+khzPikT2jd1oXWQQbqWWVLuJWesXbMNdIVhLoHyyArY9P5pQWEvji7oA9vgyyLaZqwE9MQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=k0WUBpipbtiUdHMQnisqqimu1tL+7CYm+DeJCKHthhk=; b=mVyS89zhwQpNt0xBpNFMhJRaIsj39lADxi0Iw7qlR3otWSpvh5BiyKEtCdfqTtrexZO0DIfCkDcEN3BO7rKQ3AU69dZ6eCpucf1bBvCpshQcmqdWTa4WO7UBHrYAHUsCZiHzPTqmWDasWUZEXYOZxLJIxV228EUi+9CgSCst2rVYrzCHYjAEa11KQfjwSCjDccDXaXmkyyh1runo0CjueB0FIvZuljEv9BO5jVW3GnJhHnRoCIJcZ85lGmQ+QeZH6PNU8mRMxE8XGE2jT36UZX8eO6NXlO6/01AEJKbHq+bMv4GcTKXGnXw/BLd4/rxN0KbRynWXRTNMQrMCP+BXSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mthreads.com; dmarc=pass action=none header.from=mthreads.com; dkim=pass header.d=mthreads.com; arc=none Received: from ZQ0PR01MB0998.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:1::11) by ZQ0PR01MB0965.CHNPR01.prod.partner.outlook.cn (2406:e500:c550::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.23; Mon, 26 Dec 2022 06:34:54 +0000 Received: from ZQ0PR01MB0998.CHNPR01.prod.partner.outlook.cn ([fe80::354a:252f:a9c4:dd91]) by ZQ0PR01MB0998.CHNPR01.prod.partner.outlook.cn ([fe80::354a:252f:a9c4:dd91%4]) with mapi id 15.20.5924.011; Mon, 26 Dec 2022 06:34:54 +0000 From: Jianfeng Zheng To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [EXTERNAL] [PATCH] vaapi: support VAProfileH264High10 Thread-Index: AdkY8/o2qu1OE7o9REiNLfoVIlrIdw== Date: Mon, 26 Dec 2022 06:34:54 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=mthreads.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: ZQ0PR01MB0998:EE_|ZQ0PR01MB0965:EE_ x-ms-office365-filtering-correlation-id: 4731bb4b-3854-4d9c-a0b8-08dae70b4cb1 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: swUpbgd0+ar+nlnYn9Ai0cSBypNnBePPNGLa5fQl4cq4ABPYbuOWLE0DjiOLu7nvmZs/ezwsXvSn1bdONduXlsi2lU/X+277OvyyspnuYnqWaiAAnAjILEkdKl+WXlVHRjJUaunqpLav5EMsL43jchV7mBDEXuqq/z1Y02CBpqNdkI+y4cqKf3Hn9HD/zwjZEbvGIAtbZsM0/JrUbqC1CxRG5qe7myTg7os8IJ2YmRa+KkjZ1LFyPkv4Im69Ci9YlhhyquV+z1v8OO1fRL5qZBJ7VyaWtIqO+1tnii3FLm6JCcAKthzC30esEq/cyPOJLwsqRA1tSSaPgVwrx14+8Z7WQV+9mvDaPPMQ3mhKTguZAFiRQJ+sxSOh0i5KEJLBYl8XLwNAK8w+XHHmFTfXkQnEsf7SqZXGmEG6OVLQpnJp2A68m8TFrNZ++xywZ63ejbwYGoOB1sKIvMv9GzAy7HUz/eJuZ6En/qXyJSu0l7T1LnagiTRYOl6VnAv4oSJOSHtXMqj5dpmw63iyyvBQ9nEPsHkoYrcF5TzGeOcODSDaVXmrzL3dWkk0l6ctYwcRLBt2CV/KLBIaqixQ4+ZeiNSo/k8D1GEO3d8ZRrL3aF7HYgbRlEccgIejcRI83Sa3RhFGE4pw9J5gcRtFEYZGcszRKHh0I1KsYlUndLASjz2+Dntlroynkt1n0rUVBhiUXLxJtnICXetOnmGJJ4qtVA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:ZQ0PR01MB0998.CHNPR01.prod.partner.outlook.cn; PTR:; CAT:NONE; SFS:(13230022)(396003)(366004)(39830400003)(346002)(136003)(451199015)(122000001)(83380400001)(86362001)(66476007)(33656002)(38070700005)(64756008)(44832011)(5660300002)(40180700001)(2906002)(40160700002)(66446008)(8676002)(76116006)(66556008)(66946007)(8936002)(41300700001)(55016003)(41320700001)(9686003)(186003)(26005)(53546011)(7696005)(6916009)(71200400001)(19627235002)(508600001)(966005)(38100700002)(66899015)(13296009); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: OxQX1s3+rjqGCkSe0LUAphpoAxx3jLGqDrDIg7D43iTrxWy5XceYb02AyuTj2MVw3T/PP8h5rejEqWEbq9GFQTrrgI5YDihkuxebRa/0ViFyQNjjRD8EyNf+AKgmh8WZTHJrPOUsb5GREmdM0neGQ1eQYmAeBLT/ekL0FP6+K9dYxjLbkDcEZPvw17IFYiHhVSn8GQbZmsa9rp/BEIF8hxbQyZhO80qZ8KKUK/Zz+HzwMsOwBudsn08EVLqIkQlz7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ESJi1JOb1m8Y6UPhP/XOTdZSsUi8YiWuC4fXLKpD+5iC3TguUrNcD3ph46sGGrw2crxJ/ruc9wY0bO0mSSlszY3T5EBP8iyMA4udto9zGDxTzVd9/yxvoZxdqpoLSRRxBKcuxTYk29GC2akHnMmlbVzo74Pbeig6/eKdS3OfDh3NAABAjq/HTx0GUGFeVAzGMYvJMGwV6VPyOnOboziml6v9M+EEUhnKNexGcKWnhOrMVgc0PChGoXsSw3kQ+2J3bmd0bLAshkRBCHialjS8vA== MIME-Version: 1.0 X-OriginatorOrg: mthreads.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: ZQ0PR01MB0998.CHNPR01.prod.partner.outlook.cn X-MS-Exchange-CrossTenant-Network-Message-Id: 4731bb4b-3854-4d9c-a0b8-08dae70b4cb1 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Dec 2022 06:34:54.3243 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: c62c01da-7ea0-4633-af61-38df1eee6b72 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: H+A2cxgYpBnHof3dL7XD0QG0vsO60lIAGVRoBQkmwGSsitbZ8tUksrE/auYPCyh0JAN+BSx0+1iVE1In3FM/2LWMf1rPGnh7GzXJNa6+/y0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: ZQ0PR01MB0965 Subject: [FFmpeg-devel] [EXTERNAL] [PATCH] vaapi: support VAProfileH264High10 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: jzdRX25u1jEn From 5a6450e1293efa8ca4678aad3ba59161c89d87a1 Mon Sep 17 00:00:00 2001 From: "jianfeng.zheng" Date: Mon, 18 Jul 2022 17:33:15 +0800 Subject: [PATCH] vaapi: support VAProfileH264High10 see https://github.com/intel/libva/pull/664 Signed-off-by: jianfeng.zheng --- configure | 13 +++++++++++++ libavcodec/h264_slice.c | 6 ++++++ libavcodec/vaapi_decode.c | 10 ++++++++++ libavcodec/vaapi_encode_h264.c | 24 ++++++++++++++++++++++-- libavcodec/vaapi_h264.c | 5 +++-- 5 files changed, 54 insertions(+), 4 deletions(-) .delta_pic_order_always_zero_flag = sps->delta_pic_order_always_zero_flag, }, - .pic_init_qp_minus26 = pps->init_qp - 26, - .pic_init_qs_minus26 = pps->init_qs - 26, + .pic_init_qp_minus26 = pps->init_qp - 26 - qp_bd_offset, + .pic_init_qs_minus26 = pps->init_qs - 26 - qp_bd_offset, .chroma_qp_index_offset = pps->chroma_qp_index_offset[0], .second_chroma_qp_index_offset = pps->chroma_qp_index_offset[1], .pic_fields.bits = { -- 2.25.1 diff --git a/configure b/configure index f08cdab3d1..ac199d97cb 100755 --- a/configure +++ b/configure @@ -2410,6 +2410,7 @@ HAVE_LIST=" texi2html xmllint zlib_gzip + va_profile_h264_high10 " # options emitted with CONFIG_ prefix but not available on the command line @@ -6958,6 +6959,18 @@ if enabled vaapi; then check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG" check_type "va/va.h va/va_enc_vp8.h" "VAEncPictureParameterBufferVP8" check_type "va/va.h va/va_enc_vp9.h" "VAEncPictureParameterBufferVP9" + + # + # Using 'VA_CHECK_VERSION' in source codes make things easy. But we have to wait + # until newly added VAProfile being distributed by VAAPI released version. + # + # Before or after that, we can use auto-detection to keep version compatibility. + # It always works. + # + disable va_profile_h264_high10 && enabled h264_vaapi_hwaccel + test_code cc va/va.h "VAProfile p = VAProfileH264High10" && + enable va_profile_h264_high10 + fi if enabled_all opencl libdrm ; then diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 420758ba0a..b9236281b1 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -806,6 +806,12 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) } else if (CHROMA422(h)) *fmt++ = AV_PIX_FMT_YUV422P10; else +#if CONFIG_H264_VAAPI_HWACCEL + // Just add as candidate. Whether VAProfileH264High10 usable or + // not is decided by vaapi_decode_make_config() defined in FFmpeg + // and vaQueryCodingProfile() defined in libva. + *fmt++ = AV_PIX_FMT_VAAPI; +#endif *fmt++ = AV_PIX_FMT_YUV420P10; break; case 12: diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index 134f10eca5..03bbbf2c41 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -402,6 +402,9 @@ static const struct { H264ConstrainedBaseline), MAP(H264, H264_MAIN, H264Main ), MAP(H264, H264_HIGH, H264High ), +#ifdef HAVE_VA_PROFILE_H264_HIGH10 + MAP(H264, H264_HIGH_10, H264High10 ), +#endif #if VA_CHECK_VERSION(0, 37, 0) MAP(HEVC, HEVC_MAIN, HEVCMain ), MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ), @@ -510,6 +513,13 @@ static int vaapi_decode_make_config(AVCodecContext *avctx, if (exact_match) break; } +#ifdef HAVE_VA_PROFILE_H264_HIGH10 + //incase 8bit stream being decoded under VAProfileH264High10 + if (avctx->codec_id == AV_CODEC_ID_H264 && + (avctx->profile == FF_PROFILE_H264_EXTENDED || avctx->profile == FF_PROFILE_H264_BASELINE) && + matched_va_profile == VAProfileH264High) + break; +#endif } av_freep(&profile_list); diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index dd17be2190..d26ac5a98f 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -23,6 +23,7 @@ #include "libavutil/avassert.h" #include "libavutil/common.h" +#include "libavutil/pixdesc.h" #include "libavutil/internal.h" #include "libavutil/opt.h" @@ -290,10 +291,21 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) H264RawPPS *pps = &priv->raw_pps; VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params; + const AVPixFmtDescriptor *desc; + int bit_depth; memset(sps, 0, sizeof(*sps)); memset(pps, 0, sizeof(*pps)); + desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format); + av_assert0(desc); + if (desc->nb_components == 1 || desc->log2_chroma_w != 1 || desc->log2_chroma_h != 1) { + av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format " + "%s is not supported.\n", desc->name); + return AVERROR(EINVAL); + } + bit_depth = desc->comp[0].depth; + sps->nal_unit_header.nal_ref_idc = 3; sps->nal_unit_header.nal_unit_type = H264_NAL_SPS; @@ -303,11 +315,11 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) avctx->profile == FF_PROFILE_H264_MAIN) sps->constraint_set1_flag = 1; - if (avctx->profile == FF_PROFILE_H264_HIGH) + if (avctx->profile == FF_PROFILE_H264_HIGH || avctx->profile == FF_PROFILE_H264_HIGH_10) sps->constraint_set3_flag = ctx->gop_size == 1; if (avctx->profile == FF_PROFILE_H264_MAIN || - avctx->profile == FF_PROFILE_H264_HIGH) { + avctx->profile == FF_PROFILE_H264_HIGH || avctx->profile == FF_PROFILE_H264_HIGH_10) { sps->constraint_set4_flag = 1; sps->constraint_set5_flag = ctx->b_per_p == 0; } @@ -348,6 +360,8 @@ static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx) sps->seq_parameter_set_id = 0; sps->chroma_format_idc = 1; + sps->bit_depth_luma_minus8 = bit_depth - 8; + sps->bit_depth_chroma_minus8 = bit_depth - 8; sps->log2_max_frame_num_minus4 = 4; sps->pic_order_cnt_type = 0; @@ -1111,6 +1125,9 @@ static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx) } static const VAAPIEncodeProfile vaapi_encode_h264_profiles[] = { +#ifdef HAVE_VA_PROFILE_H264_HIGH10 + { FF_PROFILE_H264_HIGH_10, 10, 3, 1, 1, VAProfileH264High10 }, +#endif { FF_PROFILE_H264_HIGH, 8, 3, 1, 1, VAProfileH264High }, { FF_PROFILE_H264_MAIN, 8, 3, 1, 1, VAProfileH264Main }, { FF_PROFILE_H264_CONSTRAINED_BASELINE, @@ -1175,11 +1192,13 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "H.264 extended profile " "is not supported.\n"); return AVERROR_PATCHWELCOME; +#ifndef HAVE_VA_PROFILE_H264_HIGH10 case FF_PROFILE_H264_HIGH_10: case FF_PROFILE_H264_HIGH_10_INTRA: av_log(avctx, AV_LOG_ERROR, "H.264 10-bit profiles " "are not supported.\n"); return AVERROR_PATCHWELCOME; +#endif case FF_PROFILE_H264_HIGH_422: case FF_PROFILE_H264_HIGH_422_INTRA: case FF_PROFILE_H264_HIGH_444: @@ -1267,6 +1286,7 @@ static const AVOption vaapi_encode_h264_options[] = { { PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) }, { PROFILE("main", FF_PROFILE_H264_MAIN) }, { PROFILE("high", FF_PROFILE_H264_HIGH) }, + { PROFILE("high10", FF_PROFILE_H264_HIGH_10) }, #undef PROFILE { "level", "Set level (level_idc)", diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c index 9332aa6f31..3e44c8caf6 100644 --- a/libavcodec/vaapi_h264.c +++ b/libavcodec/vaapi_h264.c @@ -234,6 +234,7 @@ static int vaapi_h264_start_frame(AVCodecContext *avctx, VAPictureParameterBufferH264 pic_param; VAIQMatrixBufferH264 iq_matrix; int err; + int qp_bd_offset = 6 * (sps->bit_depth_luma - 8); pic->output_surface = ff_vaapi_get_surface_id(h->cur_pic_ptr->f); @@ -256,8 +257,8 @@ static int vaapi_h264_start_frame(AVCodecContext *avctx, .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_poc_lsb - 4,