From patchwork Mon May 16 13:15:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manoj Bonda X-Patchwork-Id: 35789 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp1536208pzb; Mon, 16 May 2022 06:16:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8ZAG2ENkSM80CbPpOSxSgcCTEGsNaXDsIlK7u+01pCBbagcN8SMjugLvzSen6yBgY8ti4 X-Received: by 2002:aa7:d3ca:0:b0:427:b3b2:2d03 with SMTP id o10-20020aa7d3ca000000b00427b3b22d03mr12858485edr.357.1652706993809; Mon, 16 May 2022 06:16:33 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g16-20020a1709065d1000b006f38d8c0e72si10967887ejt.268.2022.05.16.06.16.32; Mon, 16 May 2022 06:16:33 -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=@Nvidia.com header.s=selector2 header.b=T9aaRQcM; 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 05C69680725; Mon, 16 May 2022 16:16:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2066.outbound.protection.outlook.com [40.107.243.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4915668B037 for ; Mon, 16 May 2022 16:16:22 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=knsDY5hd/+kyrU5BkbVIRemsn/LD+SvCRObWdkccKEVkNaXARbUXzUgeN1m90PNhzIJvr5BPtP3UOHraNkWrweO6Ym8yrnwO7tpsaTl41z8O29ra5cCjqBeyAoUe/Ta3qobg8Muv3sb6OGuIvjrugtFsKDQ8R/vSznRp7H3+5sJCZpOo5AxXkfIRIVjk+vitmEGMApax8pRoi7+VqgjIVbySugHZVJhtpBNWu3dh2sm8y0QBBpMxCyfy+5q1I/PkddMxZgISItyQMYVK5efyVQdUr0Pq1Ircyf1ifm8Pt6htVp3C5cvj4jxX8rKWyZnZYdoak/HXjUm1akz8vkh7aQ== 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=6/wJe/HfpQowPwgCFUPYFwkvXz47qptDBVtP3sCmXsA=; b=Thsew/LXOo24Iji2mSogKKcl+1zmC/AtTL1ZRxlB70C7mN+ZmJneqVFYam7P3Ktm+iFBq1oZ5wd/HdBDN246Xzz1ZPjlfYSPZfp5XO9CCqlGpEsTx8xeLzddekCsjWA0QukezfkiNmN5b752ihLM3zBirHBjeoiqkfInh1UbUg4CjVYxPKppOMcqtUa3fF94DWd365Vl/afBmJxVbzeRO6W7QIS1y7bsn/d8AKe3Uj8XICkwXJ+PWAqtZj423185aPQJtCFkWlmc1y8mbIgh/kY3b7mfJkuawC4+lVSba/BYN6au5COZJrw0+sffuZsbIJhj6n8rckoWnEmfuDKvSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=overt.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6/wJe/HfpQowPwgCFUPYFwkvXz47qptDBVtP3sCmXsA=; b=T9aaRQcMNs0hBPsWvCrFgZHMAtreY3yvDQnEN9MlPUYMsgCgvg266ws5uvlJ0B9AvoAsi7N1I3thtx5ymQ0f46+fHM+siRUUBg60SjRjaDLMpPUX+Vh7JTAQ+GVs2+I7hjT/zVZnX2U3kfMxtzoTVKCb1pwk82nOUb/J//SJlpqM1v1uniQrpCVvLUelzfDX/ztW3U9yWH6laRSZRGdLl+kkxNLav28RJbQAWq4hwj/Hx8Erv+TEvjWD5KSLEUm38QMBMeAp7pGndgSCbRjTyLtSFQZYmujnOZ5NVeVvXNYeh73OGAuP0wl+wLJJ5yOp+m/mSlj6HxhZV7SJ8nix0A== Received: from MW4PR03CA0079.namprd03.prod.outlook.com (2603:10b6:303:b6::24) by DM6PR12MB3308.namprd12.prod.outlook.com (2603:10b6:5:182::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.13; Mon, 16 May 2022 13:16:17 +0000 Received: from CO1NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b6:cafe::48) by MW4PR03CA0079.outlook.office365.com (2603:10b6:303:b6::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.17 via Frontend Transport; Mon, 16 May 2022 13:16:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by CO1NAM11FT025.mail.protection.outlook.com (10.13.175.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5250.13 via Frontend Transport; Mon, 16 May 2022 13:16:16 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Mon, 16 May 2022 13:16:16 +0000 Received: from bondagupta-NVWorkStation.nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 16 May 2022 06:16:13 -0700 From: ManojGuptaBonda To: Date: Mon, 16 May 2022 18:45:58 +0530 Message-ID: <20220516131558.4163-1-mbonda@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 881b59c6-8d6b-44f4-25d8-08da373e4289 X-MS-TrafficTypeDiagnostic: DM6PR12MB3308:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q3AyjR3s/PQ/QPVPnRykOpymZobgbLmfLEPgfVu+M+Q0m95vE1Hgp4AbkzkCBfiLZ8sHiky+l1MNmWOJZeDfJRbyqHNs5PVDSozsqrTsrQxThf9coX68zXjhCaU+YWGBwnY+OACKYUSohWrLIgoJkwVX23ytA6Ows0YtXwspKfgcS1R3xv6McmL2gLa1DoQDdBS4nS2++TT3McjIEBbt+5NEw/9j13GGW3g1VkXvm6Fvha5t2eXDADbo7NHhPZiKGOrs8R752Bll/TU1hCHP6TmGH+8kIRHMxOyR1/CxT0Q/XBtjd3Pc/wPdFw/nZ9sCXB+8GldYjAPcy/DUNYj6D+fCiieFq6iIicqKs4SAdeNSnRWmvttJo5uD9VGkqmbMjSAq8Th6QgNK29X7d3bxx2vzuFMAedM/UTwmCfvoLgRe0RtUeoh5rQktpUnawQJBOzKhUfsR3tPsasDJELCJe+PUfnFraB//tcDe5sMPzYIv8rxThDh2M5MRe1fOD0uzFcVIAJy2wSvnJ8qWcLTR55ifQobowhRnqWVg0Q69vzLjdrAMQGg8ij+cxNcZl1dEL5BjEqbz60UYOzr2k2vAEXQMT/P+rDNXGfuK5aSeSbR/Bel6Dilx0Wzxg9GLA2UVxd+hiwwNoc/ZC3/6t95qTZq+yR8Mjl1kN48McSm/P31C5R83JmV+hDXvN2Z/mh3KVXWTd3g8Ko+HED6KBoCPnORWLON8jptvD9UQfA6e+I4= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(316002)(356005)(7696005)(82310400005)(1076003)(16526019)(54906003)(40460700003)(30864003)(107886003)(86362001)(81166007)(36860700001)(508600001)(8936002)(4326008)(2616005)(26005)(83380400001)(2906002)(19627235002)(70206006)(47076005)(70586007)(5660300002)(6916009)(36756003)(186003)(336012)(6666004)(426003)(8676002)(2004002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2022 13:16:16.8724 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 881b59c6-8d6b-44f4-25d8-08da373e4289 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3308 Subject: [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support 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 Cc: vdpau@lists.freedesktop.org, aplattner@nvidia.com, ManojGuptaBonda , ARitger@nvidia.com, philipl@overt.org Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: P/kE0vX1eG0w Support for VDPAU accelerated AV1 decoding was added with libvdpau-1.5. Support for the same in ffmpeg is added with this patch. Profiles related to VDPAU AV1 can be found in latest vdpau.h present in libvdpau-1.5. Add AV1 VDPAU to list of hwaccels and supported formats Added file vdpau_av1.c and Modified configure to add VDPAU AV1 support. Mapped AV1 profiles to VDPAU AV1 profiles. Populated the codec specific params that need to be passed to VDPAU. --- Changelog | 1 + configure | 3 + libavcodec/Makefile | 1 + libavcodec/av1dec.c | 13 +- libavcodec/hwaccels.h | 1 + libavcodec/vdpau_av1.c | 370 ++++++++++++++++++++++++++++++++++++ libavcodec/vdpau_internal.h | 3 + libavcodec/version.h | 2 +- 8 files changed, 392 insertions(+), 2 deletions(-) create mode 100644 libavcodec/vdpau_av1.c diff --git a/Changelog b/Changelog index 4d42a0f681..a713edf566 100644 --- a/Changelog +++ b/Changelog @@ -16,6 +16,7 @@ version 5.1: - blurdetect filter - multiply video filter - PGS subtitle frame merge bitstream filter +- VDPAU AV1 hwaccel version 5.0: diff --git a/configure b/configure index 0faf2455b7..702fb4d741 100755 --- a/configure +++ b/configure @@ -3025,6 +3025,8 @@ av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS" av1_nvdec_hwaccel_select="av1_decoder" av1_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferAV1_bit_depth_idx" av1_vaapi_hwaccel_select="av1_decoder" +av1_vdpau_hwaccel_deps="vdpau VdpPictureInfoAV1" +av1_vdpau_hwaccel_select="av1_decoder" h263_vaapi_hwaccel_deps="vaapi" h263_vaapi_hwaccel_select="h263_decoder" h263_videotoolbox_hwaccel_deps="videotoolbox" @@ -6391,6 +6393,7 @@ check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC" check_type "vdpau/vdpau.h" "VdpPictureInfoVP9" +check_type "vdpau/vdpau.h" "VdpPictureInfoAV1" if [ -z "$nvccflags" ]; then nvccflags=$nvccflags_default diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 38425d2f22..813989cee9 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -954,6 +954,7 @@ OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL) += dxva2_av1.o OBJS-$(CONFIG_AV1_DXVA2_HWACCEL) += dxva2_av1.o OBJS-$(CONFIG_AV1_NVDEC_HWACCEL) += nvdec_av1.o OBJS-$(CONFIG_AV1_VAAPI_HWACCEL) += vaapi_av1.o +OBJS-$(CONFIG_AV1_VDPAU_HWACCEL) += vdpau_av1.o OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o OBJS-$(CONFIG_H264_D3D11VA_HWACCEL) += dxva2_h264.o diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 1c09b1d6d6..dd83373dd6 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -441,7 +441,8 @@ static int get_pixel_format(AVCodecContext *avctx) #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \ CONFIG_AV1_D3D11VA_HWACCEL * 2 + \ CONFIG_AV1_NVDEC_HWACCEL + \ - CONFIG_AV1_VAAPI_HWACCEL) + CONFIG_AV1_VAAPI_HWACCEL + \ + CONFIG_AV1_VDPAU_HWACCEL) enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts; if (seq->seq_profile == 2 && seq->color_config.high_bitdepth) @@ -518,6 +519,9 @@ static int get_pixel_format(AVCodecContext *avctx) #endif #if CONFIG_AV1_VAAPI_HWACCEL *fmtp++ = AV_PIX_FMT_VAAPI; +#endif +#if CONFIG_AV1_VDPAU_HWACCEL + *fmtp++ = AV_PIX_FMT_VDPAU; #endif break; case AV_PIX_FMT_YUV420P10: @@ -533,6 +537,9 @@ static int get_pixel_format(AVCodecContext *avctx) #endif #if CONFIG_AV1_VAAPI_HWACCEL *fmtp++ = AV_PIX_FMT_VAAPI; +#endif +#if CONFIG_AV1_VDPAU_HWACCEL + *fmtp++ = AV_PIX_FMT_VDPAU; #endif break; case AV_PIX_FMT_GRAY8: @@ -1271,6 +1278,10 @@ const FFCodec ff_av1_decoder = { #if CONFIG_AV1_VAAPI_HWACCEL HWACCEL_VAAPI(av1), #endif +#if CONFIG_AV1_VDPAU_HWACCEL + HWACCEL_VDPAU(av1), +#endif + NULL }, }; diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h index ff4daca0e2..aca55831f3 100644 --- a/libavcodec/hwaccels.h +++ b/libavcodec/hwaccels.h @@ -26,6 +26,7 @@ extern const AVHWAccel ff_av1_d3d11va2_hwaccel; extern const AVHWAccel ff_av1_dxva2_hwaccel; extern const AVHWAccel ff_av1_nvdec_hwaccel; extern const AVHWAccel ff_av1_vaapi_hwaccel; +extern const AVHWAccel ff_av1_vdpau_hwaccel; extern const AVHWAccel ff_h263_vaapi_hwaccel; extern const AVHWAccel ff_h263_videotoolbox_hwaccel; extern const AVHWAccel ff_h264_d3d11va_hwaccel; diff --git a/libavcodec/vdpau_av1.c b/libavcodec/vdpau_av1.c new file mode 100644 index 0000000000..95c1e58cf7 --- /dev/null +++ b/libavcodec/vdpau_av1.c @@ -0,0 +1,370 @@ +/* + * AV1 HW decode acceleration through VDPAU + * + * Copyright (c) 2022 Manoj Gupta Bonda + * + * 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 + */ + +#include +#include "libavutil/pixdesc.h" +#include "avcodec.h" +#include "internal.h" +#include "av1dec.h" +#include "hwconfig.h" +#include "vdpau.h" +#include "vdpau_internal.h" + +static int get_bit_depth_from_seq(const AV1RawSequenceHeader *seq) +{ + if (seq->seq_profile == 2 && seq->color_config.high_bitdepth) { + return seq->color_config.twelve_bit ? 12 : 10; + } else if (seq->seq_profile <= 2 && seq->color_config.high_bitdepth) { + return 10; + } else { + return 8; + } +} + +static int vdpau_av1_start_frame(AVCodecContext *avctx, + const uint8_t *buffer, uint32_t size) +{ + AV1DecContext *s = avctx->priv_data; + const AV1RawSequenceHeader *seq = s->raw_seq; + const AV1RawFrameHeader *frame_header = s->raw_frame_header; + const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain; + + struct vdpau_picture_context *pic_ctx = s->cur_frame.hwaccel_picture_private; + int i,j; + + unsigned char remap_lr_type[4] = { AV1_RESTORE_NONE, AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ }; + + + VdpPictureInfoAV1 *info = &pic_ctx->info.av1; + const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt); + if (!pixdesc) { + return AV_PIX_FMT_NONE; + } + + info->width = avctx->width; + info->height = avctx->height; + + + info->frame_offset = frame_header->order_hint; + + /* Sequence Header */ + info->profile = seq->seq_profile; + info->use_128x128_superblock = seq->use_128x128_superblock; + info->subsampling_x = seq->color_config.subsampling_x; + info->subsampling_y = seq->color_config.subsampling_y; + info->mono_chrome = seq->color_config.mono_chrome; + info->bit_depth_minus8 = get_bit_depth_from_seq(seq) - 8; + info->enable_filter_intra = seq->enable_filter_intra; + info->enable_intra_edge_filter = seq->enable_intra_edge_filter; + info->enable_interintra_compound = seq->enable_interintra_compound; + info->enable_masked_compound = seq->enable_masked_compound; + info->enable_dual_filter = seq->enable_dual_filter; + info->enable_order_hint = seq->enable_order_hint; + info->order_hint_bits_minus1 = seq->order_hint_bits_minus_1; + info->enable_jnt_comp = seq->enable_jnt_comp; + info->enable_superres = seq->enable_superres; + info->enable_cdef = seq->enable_cdef; + info->enable_restoration = seq->enable_restoration; + info->enable_fgs = seq->film_grain_params_present; + + /* Frame Header */ + info->frame_type = frame_header->frame_type; + info->show_frame = frame_header->show_frame; + info->disable_cdf_update = frame_header->disable_cdf_update; + info->allow_screen_content_tools = frame_header->allow_screen_content_tools; + info->force_integer_mv = frame_header->force_integer_mv || + frame_header->frame_type == AV1_FRAME_INTRA_ONLY || + frame_header->frame_type == AV1_FRAME_KEY; + info->coded_denom = frame_header->coded_denom; + info->allow_intrabc = frame_header->allow_intrabc; + info->allow_high_precision_mv = frame_header->allow_high_precision_mv; + info->interp_filter = frame_header->interpolation_filter; + info->switchable_motion_mode = frame_header->is_motion_mode_switchable; + info->use_ref_frame_mvs = frame_header->use_ref_frame_mvs; + info->disable_frame_end_update_cdf = frame_header->disable_frame_end_update_cdf; + info->delta_q_present = frame_header->delta_q_present; + info->delta_q_res = frame_header->delta_q_res; + info->using_qmatrix = frame_header->using_qmatrix; + info->coded_lossless = s->cur_frame.coded_lossless; + info->use_superres = frame_header->use_superres; + info->tx_mode = frame_header->tx_mode; + info->reference_mode = frame_header->reference_select; + info->allow_warped_motion = frame_header->allow_warped_motion; + info->reduced_tx_set = frame_header->reduced_tx_set; + info->skip_mode = frame_header->skip_mode_present; + + /* Tiling Info */ + info->num_tile_cols = frame_header->tile_cols; + info->num_tile_rows = frame_header->tile_rows; + info->context_update_tile_id = frame_header->context_update_tile_id; + + /* CDEF */ + info->cdef_damping_minus_3 = frame_header->cdef_damping_minus_3; + info->cdef_bits = frame_header->cdef_bits; + + /* SkipModeFrames */ + info->SkipModeFrame0 = frame_header->skip_mode_present ? + s->cur_frame.skip_mode_frame_idx[0] : 0; + info->SkipModeFrame1 = frame_header->skip_mode_present ? + s->cur_frame.skip_mode_frame_idx[1] : 0; + + /* QP Information */ + info->base_qindex = frame_header->base_q_idx; + info->qp_y_dc_delta_q = frame_header->delta_q_y_dc; + info->qp_u_dc_delta_q = frame_header->delta_q_u_dc; + info->qp_v_dc_delta_q = frame_header->delta_q_v_dc; + info->qp_u_ac_delta_q = frame_header->delta_q_u_ac; + info->qp_v_ac_delta_q = frame_header->delta_q_v_ac; + info->qm_y = frame_header->qm_y; + info->qm_u = frame_header->qm_u; + info->qm_v = frame_header->qm_v; + + /* Segmentation */ + info->segmentation_enabled = frame_header->segmentation_enabled; + info->segmentation_update_map = frame_header->segmentation_update_map; + info->segmentation_update_data = frame_header->segmentation_update_data; + info->segmentation_temporal_update = frame_header->segmentation_temporal_update; + + /* Loopfilter */ + info->loop_filter_level[0] = frame_header->loop_filter_level[0]; + info->loop_filter_level[1] = frame_header->loop_filter_level[1]; + info->loop_filter_level_u = frame_header->loop_filter_level[2]; + info->loop_filter_level_v = frame_header->loop_filter_level[3]; + info->loop_filter_sharpness = frame_header->loop_filter_sharpness; + info->loop_filter_delta_enabled = frame_header->loop_filter_delta_enabled; + info->loop_filter_delta_update = frame_header->loop_filter_delta_update; + info->loop_filter_mode_deltas[0] = frame_header->loop_filter_mode_deltas[0]; + info->loop_filter_mode_deltas[1] = frame_header->loop_filter_mode_deltas[1]; + info->delta_lf_present = frame_header->delta_lf_present; + info->delta_lf_res = frame_header->delta_lf_res; + info->delta_lf_multi = frame_header->delta_lf_multi; + + /* Restoration */ + info->lr_type[0] = remap_lr_type[frame_header->lr_type[0]]; + info->lr_type[1] = remap_lr_type[frame_header->lr_type[1]]; + info->lr_type[2] = remap_lr_type[frame_header->lr_type[2]]; + info->lr_unit_size[0] = 1 + frame_header->lr_unit_shift; + info->lr_unit_size[1] = 1 + frame_header->lr_unit_shift - frame_header->lr_uv_shift; + info->lr_unit_size[2] = 1 + frame_header->lr_unit_shift - frame_header->lr_uv_shift; + + /* Reference Frames */ + info->temporal_layer_id = s->cur_frame.temporal_id; + info->spatial_layer_id = s->cur_frame.spatial_id; + + /* Film Grain Params */ + info->apply_grain = film_grain->apply_grain; + info->overlap_flag = film_grain->overlap_flag; + info->scaling_shift_minus8 = film_grain->grain_scaling_minus_8; + info->chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma; + info->ar_coeff_lag = film_grain->ar_coeff_lag; + info->ar_coeff_shift_minus6 = film_grain->ar_coeff_shift_minus_6; + info->grain_scale_shift = film_grain->grain_scale_shift; + info->clip_to_restricted_range = film_grain->clip_to_restricted_range; + info->num_y_points = film_grain->num_y_points; + info->num_cb_points = film_grain->num_cb_points; + info->num_cr_points = film_grain->num_cr_points; + info->random_seed = film_grain->grain_seed; + info->cb_mult = film_grain->cb_mult; + info->cb_luma_mult = film_grain->cb_luma_mult; + info->cb_offset = film_grain->cb_offset; + info->cr_mult = film_grain->cr_mult; + info->cr_luma_mult = film_grain->cr_luma_mult; + info->cr_offset = film_grain->cr_offset; + + /* Tiling Info */ + for (i = 0; i < frame_header->tile_cols; ++i) { + info->tile_widths[i] = frame_header->width_in_sbs_minus_1[i] + 1; + } + for (i = 0; i < frame_header->tile_rows; ++i) { + info->tile_heights[i] = frame_header->height_in_sbs_minus_1[i] + 1; + } + + /* CDEF */ + for (i = 0; i < (1 << frame_header->cdef_bits); ++i) { + info->cdef_y_strength[i] = (frame_header->cdef_y_pri_strength[i] & 0x0F) | (frame_header->cdef_y_sec_strength[i] << 4); + info->cdef_uv_strength[i] = (frame_header->cdef_uv_pri_strength[i] & 0x0F) | (frame_header->cdef_uv_sec_strength[i] << 4); + } + + + /* Segmentation */ + for (i = 0; i < AV1_MAX_SEGMENTS; ++i) { + info->segmentation_feature_mask[i] = 0; + for (j = 0; j < AV1_SEG_LVL_MAX; ++j) { + info->segmentation_feature_mask[i] |= frame_header->feature_enabled[i][j] << j; + info->segmentation_feature_data[i][j] = frame_header->feature_value[i][j]; + } + } + + for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) { + /* Loopfilter */ + info->loop_filter_ref_deltas[i] = frame_header->loop_filter_ref_deltas[i]; + + /* Reference Frames */ + info->ref_frame_map[i] = ff_vdpau_get_surface_id(s->ref[i].tf.f) ? ff_vdpau_get_surface_id(s->ref[i].tf.f) : VDP_INVALID_HANDLE; + } + + if (frame_header->primary_ref_frame == AV1_PRIMARY_REF_NONE) { + info->primary_ref_frame = -1; + } else { + int8_t pri_ref_idx = frame_header->ref_frame_idx[frame_header->primary_ref_frame]; + info->primary_ref_frame = info->ref_frame_map[pri_ref_idx]; + } + + for (i = 0; i < AV1_REFS_PER_FRAME; ++i) { + /* Ref Frame List */ + int8_t ref_idx = frame_header->ref_frame_idx[i]; + AVFrame *ref_frame = s->ref[ref_idx].tf.f; + + info->ref_frame[i].index = info->ref_frame_map[ref_idx]; + info->ref_frame[i].width = ref_frame->width; + info->ref_frame[i].height = ref_frame->height; + + /* Global Motion */ + info->global_motion[i].invalid = !frame_header->is_global[AV1_REF_FRAME_LAST + i]; + info->global_motion[i].wmtype = s->cur_frame.gm_type[AV1_REF_FRAME_LAST + i]; + for (j = 0; j < 6; ++j) { + info->global_motion[i].wmmat[j] = s->cur_frame.gm_params[AV1_REF_FRAME_LAST + i][j]; + } + } + + /* Film Grain Params */ + if (film_grain->apply_grain) { + for (i = 0; i < 14; ++i) { + info->scaling_points_y[i][0] = film_grain->point_y_value[i]; + info->scaling_points_y[i][1] = film_grain->point_y_scaling[i]; + } + for (i = 0; i < 10; ++i) { + info->scaling_points_cb[i][0] = film_grain->point_cb_value[i]; + info->scaling_points_cb[i][1] = film_grain->point_cb_scaling[i]; + info->scaling_points_cr[i][0] = film_grain->point_cr_value[i]; + info->scaling_points_cr[i][1] = film_grain->point_cr_scaling[i]; + } + for (i = 0; i < 24; ++i) { + info->ar_coeffs_y[i] = (short)film_grain->ar_coeffs_y_plus_128[i] - 128; + } + for (i = 0; i < 25; ++i) { + info->ar_coeffs_cb[i] = (short)film_grain->ar_coeffs_cb_plus_128[i] - 128; + info->ar_coeffs_cr[i] = (short)film_grain->ar_coeffs_cr_plus_128[i] - 128; + } + } + + + return ff_vdpau_common_start_frame(pic_ctx, buffer, size); + +} + +static int vdpau_av1_decode_slice(AVCodecContext *avctx, + const uint8_t *buffer, uint32_t size) +{ + const AV1DecContext *s = avctx->priv_data; + const AV1RawFrameHeader *frame_header = s->raw_frame_header; + struct vdpau_picture_context *pic_ctx = s->cur_frame.hwaccel_picture_private; + VdpPictureInfoAV1 *info = &pic_ctx->info.av1; + int val; + int nb_slices; + VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers; + int bitstream_len = 0; + + nb_slices = frame_header->tile_cols * frame_header->tile_rows; + /* Shortcut if all tiles are in the same buffer*/ + if (nb_slices == s->tg_end - s->tg_start + 1) { + for (int i = 0; i < nb_slices; ++i) { + info->tile_info[i*2 ] = s->tile_group_info[i].tile_offset; + info->tile_info[i*2 + 1] = info->tile_info[i*2] + s->tile_group_info[i].tile_size; + } + val = ff_vdpau_add_buffer(pic_ctx, buffer, size); + if (val) { + return val; + } + + return 0; + } + + for(int i = 0; i < pic_ctx->bitstream_buffers_used; i++) { + bitstream_len += buffers->bitstream_bytes; + buffers++; + } + + for (uint32_t tile_num = s->tg_start; tile_num <= s->tg_end; ++tile_num) { + info->tile_info[tile_num*2 ] = bitstream_len + s->tile_group_info[tile_num].tile_offset; + info->tile_info[tile_num*2 + 1] = info->tile_info[tile_num*2] + s->tile_group_info[tile_num].tile_size; + } + + val = ff_vdpau_add_buffer(pic_ctx, buffer, size); + if (val) { + return val; + } + + return 0; +} + +static int vdpau_av1_end_frame(AVCodecContext *avctx) +{ + const AV1DecContext *s = avctx->priv_data; + struct vdpau_picture_context *pic_ctx = s->cur_frame.hwaccel_picture_private; + + int val; + + val = ff_vdpau_common_end_frame(avctx, s->cur_frame.tf.f, pic_ctx); + if (val < 0) + return val; + + return 0; +} + +static int vdpau_av1_init(AVCodecContext *avctx) +{ + VdpDecoderProfile profile; + uint32_t level = avctx->level; + + switch (avctx->profile) { + case FF_PROFILE_AV1_MAIN: + profile = VDP_DECODER_PROFILE_AV1_MAIN; + break; + case FF_PROFILE_AV1_HIGH: + profile = VDP_DECODER_PROFILE_AV1_HIGH; + break; + case FF_PROFILE_AV1_PROFESSIONAL: + profile = VDP_DECODER_PROFILE_AV1_PROFESSIONAL; + break; + default: + return AVERROR(ENOTSUP); + } + + return ff_vdpau_common_init(avctx, profile, level); +} + +const AVHWAccel ff_av1_vdpau_hwaccel = { + .name = "av1_vdpau", + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_AV1, + .pix_fmt = AV_PIX_FMT_VDPAU, + .start_frame = vdpau_av1_start_frame, + .end_frame = vdpau_av1_end_frame, + .decode_slice = vdpau_av1_decode_slice, + .frame_priv_data_size = sizeof(struct vdpau_picture_context), + .init = vdpau_av1_init, + .uninit = ff_vdpau_common_uninit, + .frame_params = ff_vdpau_common_frame_params, + .priv_data_size = sizeof(VDPAUContext), + .caps_internal = HWACCEL_CAP_ASYNC_SAFE, +}; diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h index b6ea078cb2..347576e0c3 100644 --- a/libavcodec/vdpau_internal.h +++ b/libavcodec/vdpau_internal.h @@ -57,6 +57,9 @@ union VDPAUPictureInfo { #ifdef VDP_DECODER_PROFILE_VP9_PROFILE_0 VdpPictureInfoVP9 vp9; #endif +#ifdef VDP_DECODER_PROFILE_AV1_MAIN + VdpPictureInfoAV1 av1; +#endif }; typedef struct VDPAUHWContext { diff --git a/libavcodec/version.h b/libavcodec/version.h index 87b7284a95..5183deb68b 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #include "version_major.h" -#define LIBAVCODEC_VERSION_MINOR 28 +#define LIBAVCODEC_VERSION_MINOR 29 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \