From patchwork Sat Sep 30 16:42:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Cheng X-Patchwork-Id: 44051 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp481708pzf; Sat, 30 Sep 2023 09:42:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvjQQXEOw/X5K33ml48cNZE+nilmJOkyGPb4Ug4IEZoWUhfNs5YsC2bWHaKoGtDl/W5BCp X-Received: by 2002:a5d:5a17:0:b0:319:8bd0:d18c with SMTP id bq23-20020a5d5a17000000b003198bd0d18cmr1491421wrb.52.1696092172435; Sat, 30 Sep 2023 09:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696092172; cv=none; d=google.com; s=arc-20160816; b=zSEIHY108DH1qYHTNMI/a8GsOGQa9pHiJ7Jkdmr+yI6/7YlvhjEqToPxEGml2EYR11 XaLLNr+vztFEzKHs6lJOjpzlE0eHQNAvMSirVWabLrkFzN84Z0vu3vPwYnxzFEW4gUq0 OgReH8s51eN76n3LmWkJuZ6bYiLOPvJ+JD/szwwQrqT8bpmsNbg1ji9R/OIrAXL/5VfS QXkU83PRxz1xZqMtP4Ip5rC6faw72cY82w542QCIoo1OeAnJneTyStmzHSi/PvdUiMls t30PS06uC0Av4FiROtgC4qWOHMe1X4euIV3JTs8juUjT0d9KBzJdJaYXD5bG0xgOTyI3 /JMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to :delivered-to; bh=4wyIqhZXih+UlhIOCoJEFc7PUHzN2tR/EUWgQweR22Q=; fh=gclhhGXccg6u5Ag9tYQBjkHCTtwdm1Rs9cVW3gQSMVo=; b=kLSo9Rkh/jLWj5RC5y7gC7nk/oN1jKgXYWo/PMvcSH4e2eiZSkPKZ9zhFcg8la5vtG ZuDSsgT6Fec7MT57HGgZuPjN/vltmWg4v6q4zu+ZEHq+fHYOHNX6dmlRht+L60DdFcaC 93uA2/0P3LiHMTTH5kgcyMtxlYKFRm+gGbOxhfH9L3qAwLMavNT5/DA8GLQq+RihZSQq gLGJe+5aCHV2Hp0+Hnxh6r040Alvhw3ytKNPOETQarNQroF5t/jNEpsZ4wcdmk+ebraf O3N3gazihF6B1+5aA3EuY6LMblKf+I7I93pHpcC2YvqGUNDACrGhqpB+W8QTs5XAK1ty L7Mg== 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 h13-20020a1709062dcd00b009ad8def1f49si17807808eji.572.2023.09.30.09.42.51; Sat, 30 Sep 2023 09:42:52 -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 7887768CCDD; Sat, 30 Sep 2023 19:42:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out-205.mta0.migadu.com (out-205.mta0.migadu.com [91.218.175.205]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 16A8568CCC9 for ; Sat, 30 Sep 2023 19:42:42 +0300 (EEST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 Sep 2023 12:42:30 -0400 Message-ID: <20230930164230.48519-1-ben@bcheng.me> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Subject: [FFmpeg-devel] [PATCH] vulkan_hevc: handle non-contiguous SPS/PPS/VPS ids 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: , X-Patchwork-Original-From: Benjamin Cheng via ffmpeg-devel From: Benjamin Cheng Reply-To: FFmpeg development discussions and patches Cc: Benjamin Cheng Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: EvL+S/xVmxUa Some clips (i.e. SLIST_B_Sony_9) will use PPS 0 and 8, before PPS 1-7. vulkan_hevc expects {sps,pps,vps}_list to be filled in order, which causes PPS 8 to not be added to the Vulkan session params when it is being used by a picture. This removes the expectation that these lists are filled in order. The indicies into vps_list are saved since there are multiple usages of it. This also fixes a bug with some clips (i.e. PPS_A_qualcomm_7) which use all 64 available PPS slots, causing the old loop to think there are more than 64 PPS-es. --- libavcodec/vulkan_hevc.c | 47 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c index 52f223ceb2..a8265acf32 100644 --- a/libavcodec/vulkan_hevc.c +++ b/libavcodec/vulkan_hevc.c @@ -70,6 +70,7 @@ typedef struct HEVCHeaderSet { static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, int nb_vps, + const int vps_list_idx[HEVC_MAX_VPS_COUNT], AVBufferRef * const vps_list[HEVC_MAX_VPS_COUNT]) { uint8_t *data_ptr; @@ -77,7 +78,7 @@ static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, size_t buf_size = sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS); for (int i = 0; i < nb_vps; i++) { - const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data; + const HEVCVPS *vps = (const HEVCVPS *)vps_list[vps_list_idx[i]]->data; buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; } @@ -96,7 +97,7 @@ static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, hdr->hvps = (HEVCHeaderVPS *)(data_ptr + sizeof(HEVCHeaderSet)); data_ptr += sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS); for (int i = 0; i < nb_vps; i++) { - const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data; + const HEVCVPS *vps = (const HEVCVPS *)vps_list[vps_list_idx[i]]->data; hdr->hvps[i].sls = (HEVCHeaderVPSSet *)data_ptr; data_ptr += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; } @@ -655,13 +656,15 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) .videoSessionParametersTemplate = NULL, }; - int nb_vps = 0; HEVCHeaderSet *hdr; + int nb_vps = 0; + int vps_list_idx[HEVC_MAX_VPS_COUNT]; - for (int i = 0; h->ps.vps_list[i]; i++) - nb_vps++; + for (int i = 0; i < HEVC_MAX_VPS_COUNT; i++) + if (h->ps.vps_list[i]) + vps_list_idx[nb_vps++] = i; - err = alloc_hevc_header_structs(dec, nb_vps, h->ps.vps_list); + err = alloc_hevc_header_structs(dec, nb_vps, vps_list_idx, h->ps.vps_list); if (err < 0) return err; @@ -672,29 +675,33 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) h265_params_info.pStdVPSs = hdr->vps; /* SPS list */ - for (int i = 0; h->ps.sps_list[i]; i++) { - const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data; - set_sps(sps_l, i, &hdr->hsps[i].scaling, &hdr->hsps[i].vui_header, - &hdr->hsps[i].vui, &hdr->sps[i], hdr->hsps[i].nal_hdr, - hdr->hsps[i].vcl_hdr, &hdr->hsps[i].ptl, &hdr->hsps[i].dpbm, - &hdr->hsps[i].pal, hdr->hsps[i].str, &hdr->hsps[i].ltr); - h265_params_info.stdSPSCount++; + for (int i = 0; i < HEVC_MAX_SPS_COUNT; i++) { + if (h->ps.sps_list[i]) { + const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data; + int idx = h265_params_info.stdSPSCount++; + set_sps(sps_l, i, &hdr->hsps[idx].scaling, &hdr->hsps[idx].vui_header, + &hdr->hsps[idx].vui, &hdr->sps[idx], hdr->hsps[idx].nal_hdr, + hdr->hsps[idx].vcl_hdr, &hdr->hsps[idx].ptl, &hdr->hsps[idx].dpbm, + &hdr->hsps[idx].pal, hdr->hsps[idx].str, &hdr->hsps[idx].ltr); + } } /* PPS list */ - for (int i = 0; h->ps.pps_list[i]; i++) { - const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data; - const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[pps_l->sps_id]->data; - set_pps(pps_l, sps_l, &hdr->hpps[i].scaling, &hdr->pps[i], &hdr->hpps[i].pal); - h265_params_info.stdPPSCount++; + for (int i = 0; i < HEVC_MAX_PPS_COUNT; i++) { + if (h->ps.pps_list[i]) { + const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data; + const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[pps_l->sps_id]->data; + int idx = h265_params_info.stdPPSCount++; + set_pps(pps_l, sps_l, &hdr->hpps[idx].scaling, + &hdr->pps[idx], &hdr->hpps[idx].pal); + } } /* VPS list */ for (int i = 0; i < nb_vps; i++) { - const HEVCVPS *vps_l = (const HEVCVPS *)h->ps.vps_list[i]->data; + const HEVCVPS *vps_l = (const HEVCVPS *)h->ps.vps_list[vps_list_idx[i]]->data; set_vps(vps_l, &hdr->vps[i], &hdr->hvps[i].ptl, &hdr->hvps[i].dpbm, hdr->hvps[i].hdr, hdr->hvps[i].sls); - h265_params_info.stdVPSCount++; } h265_params.maxStdSPSCount = h265_params_info.stdSPSCount;