From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 1BEF74A7E0 for ; Fri, 19 Sep 2025 20:24:16 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'zjpRPP9sZ4JdXtc1/fjLO+EOWvkftWA14fNVZYJjySw=', expected b'DdChX1scB7OcV2vcMvwwNYPdxCG2tf0EW41GfvYisFU=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1758313437; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=zjpRPP9sZ4JdXtc1/fjLO+EOWvkftWA14fNVZYJjySw=; b=m1oQVf/65xUewwvYxjIcx5U4E1CKk94mzJIiOx4OPXUvN90xM4nAkxYV874qk5tqT1PqE /DwDKOzi2XBa0HK022Da0Hwo0abiFGCo+g1yOHRGgM3m2BZVhfZGzKjgtJQrLHQZ8qxcZWa +27UWf+9VM8Rz4EqadEmfFQ0fAant559HAkjorVvlWeM31wUOOVl/ClHGxJLq/jFtQf+zR3 g+jRrQv8pBGYeecdljiSmlfZGUiN9RdtYWW4PgNdZdrSQisokM41uV2KMETwd+O9TBSAnDD vCqVnx8i6jCPtmE9od1jnqEhbeQnhWVKxZ+Zu2TZSmZd9EGcnDoW/V4yQqaw== Received: from [172.19.0.4] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 1743468EB60; Fri, 19 Sep 2025 23:23:57 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1758313434; b=Lkizrsl0wSmwLh6jAyRVJDNX4br4TqucWeXWv8P7fc3+VAad26Suvtw5/AgxkChtwIGjU f4B7LaWBpkxFeQk/+z59KSs2WK5hdl1NQRTjB6SqM0aPCJ4k69aWzAwbmiffNARjcBaROpD mNCMzoV3yMtA342mI8ZvarMSwD+6iRTwVoFxQPD+afaWI7/4BrmMia9UKuAhLeJbATNNDHC SWK5aEEFSUIcjPUps5026dwb1XM9LTQJsb4q7zb4xoKgBpNBzJc5SoJ/PlekA4p3T6Y+agm 5HJWwHgnZbwiMZYyvIn43MX1Noudto1QfL14mWx13YkJ/ntFVcOm3n9B2rCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1758313434; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=owYunJ4IZMJNLgNttm1FFjFOP+tiL0Ysdnejlt1K3jI=; b=fL8pRtHQsiOSuDzw5OZFsyTwbayhA7iHz/oGDdf6v+lksIRP58Wv7q/V+0jKo29u1877e 2HZTd9PQ3/S4y+s/XH6A6Z4ucgE0cOd8DkFsvcWY4u+SzFogAEquQwR1w6kYqeEnJGvlazF 0G9N4B5JnCMepyXvCpXRiMCsDXQtfh8eilQpJUEL03Cb+mOkXOVMtkSdkFlUCw2I/Xswftz Xc1sfNBgoowzVn28+0DIdctwVCbqnhn4TdYmkxoWx3Byr2veJACdz8vbsVNfLf8U1cpTdCk vV4/PQVJpAVkQyngpd8v0gvuZ8n5MbHYN9y8ZQNZieUwxwcKgFuZfVEqtujg== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=none Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1758313424; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=DdChX1scB7OcV2vcMvwwNYPdxCG2tf0EW41GfvYisFU=; b=bEuqXIoVKXrsf92/+vbZM+hrQUCTt6YCOESMMpuYRgPMZiLwbd4JdDNDg2mas+mzeLdHB 2OLEs45CZo6YpoFAvxPfT8yxbbRvnt0gDrs8rNh/xMcN8elOp0Bo70L6rTCuhRIlTABWJUf 6FyMK44peh5foAUZUga2em1GLocxsyS2uHtkbNbxOmB3p6pgQUFyOXyWcaKYM53uIYVMsgD gY8kpmWAWt08sO+54VxasRTH2jmdGL7C098VEATIde0ACCrnR+nbUiqI0YPX/LWCo1akR7W qUPaLhJtmwshOxd3s3CM+iK5G5PNKMXGt8Dxj49UKOTCvsRmUr1XOunUfdrg== Received: from ed19c606a818 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id CBC3968EB4F for ; Fri, 19 Sep 2025 23:23:44 +0300 (EEST) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Sep 2025 20:23:44 -0000 Message-ID: <175831342515.25.6278373688975206795@463a07221176> Message-ID-Hash: O5SEZTNKOCO3KYRVXHTC5JMMQUOFBGOE X-Message-ID-Hash: O5SEZTNKOCO3KYRVXHTC5JMMQUOFBGOE X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] lavc/vvc: Store RefStruct references to referenced PSs/headers in slice (PR #20557) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: frankplow via ffmpeg-devel Cc: frankplow Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20557 opened by frankplow URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20557 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20557.patch This loosens the coupling between CBS and the decoder by no longer using `CodedBitstreamH266Context` (containing the most recently parsed PSs & PH) to retrieve the PSs & PH in the decoder. Doing so is beneficial in two ways: 1. It improves robustness to the case in which an `AVPacket` doesn't contain precisely one PU. 2. It allows the decoder parameter set manager to properly handle the case in which a single PU (erroneously) contains conflicting parameter sets. >>From b736ddd0f324c03577577a721bf82a522d658432 Mon Sep 17 00:00:00 2001 From: Frank Plowman Date: Thu, 18 Sep 2025 21:24:29 +0100 Subject: [PATCH] lavc/vvc: Store RefStruct references to referenced PSs/headers in slice This loosens the coupling between CBS and the decoder by no longer using CodedBitstreamH266Context (containing the most recently parsed PSs & PH) to retrieve the PSs & PH in the decoder. Doing so is beneficial in two ways: 1. It improves robustness to the case in which an AVPacket doesn't contain precisely one PU. 2. It allows the decoder parameter set manager to properly handle the case in which a single PU (erroneously) contains conflicting parameter sets. --- libavcodec/cbs_h2645.c | 28 +++++++++++++++++++++++----- libavcodec/cbs_h266.h | 5 +++++ libavcodec/vvc/dec.c | 5 ++--- libavcodec/vvc/ps.c | 32 ++++++++++++++------------------ libavcodec/vvc/ps.h | 3 ++- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 75784b03a9..f537686245 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1086,6 +1086,7 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx, { GetBitContext gbc; int err; + CodedBitstreamH266Context *h266 = ctx->priv_data; err = init_get_bits8(&gbc, unit->data, unit->data_size); if (err < 0) @@ -1201,7 +1202,13 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx, err = cbs_h266_replace_ph(ctx, unit, &slice->header.sh_picture_header); if (err < 0) return err; + slice->ph_ref = NULL; + } else { + slice->ph_ref = av_refstruct_ref(h266->ph_ref); } + slice->ph = h266->ph; + slice->pps = av_refstruct_ref(h266->pps[slice->ph->ph_pic_parameter_set_id]); + slice->sps = av_refstruct_ref(h266->sps[slice->pps->pps_seq_parameter_set_id]); slice->header_size = pos / 8; slice->data_size = len - pos / 8; @@ -2037,6 +2044,16 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = { CBS_UNIT_TYPE_END_OF_LIST }; +static void cbs_h266_free_slice(AVRefStructOpaque unused, void *content) +{ + H266RawSlice *slice = content; + av_buffer_unref(&slice->data_ref); + av_refstruct_unref(&slice->sps); + av_refstruct_unref(&slice->pps); + av_refstruct_unref(&slice->ph_ref); +} + + static void cbs_h266_free_sei(AVRefStructOpaque unused, void *content) { H266RawSEI *sei = content; @@ -2065,11 +2082,12 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = { CBS_UNIT_TYPE_POD(VVC_PH_NUT , H266RawPH), CBS_UNIT_TYPE_POD(VVC_AUD_NUT, H266RawAUD), - CBS_UNIT_RANGE_INTERNAL_REF(VVC_TRAIL_NUT, VVC_RASL_NUT, - H266RawSlice, data), - - CBS_UNIT_RANGE_INTERNAL_REF(VVC_IDR_W_RADL, VVC_GDR_NUT, - H266RawSlice, data), + CBS_UNIT_TYPES_COMPLEX((VVC_TRAIL_NUT, VVC_STSA_NUT, VVC_RADL_NUT), + H266RawSlice, cbs_h266_free_slice), + CBS_UNIT_TYPES_COMPLEX((VVC_RASL_NUT, VVC_IDR_W_RADL, VVC_IDR_N_LP), + H266RawSlice, cbs_h266_free_slice), + CBS_UNIT_TYPES_COMPLEX((VVC_CRA_NUT, VVC_GDR_NUT), + H266RawSlice, cbs_h266_free_slice), CBS_UNIT_TYPES_COMPLEX((VVC_PREFIX_SEI_NUT, VVC_SUFFIX_SEI_NUT), H266RawSEI, cbs_h266_free_sei), diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h index 67a3ff6151..8d851a0bfb 100644 --- a/libavcodec/cbs_h266.h +++ b/libavcodec/cbs_h266.h @@ -848,6 +848,11 @@ typedef struct H266RawSlice { size_t header_size; size_t data_size; int data_bit_start; + + H266RawSPS *sps; ///< RefStruct reference to referred-to SPS + H266RawPPS *pps; ///< RefStruct reference to referred-to PPS + H266RawPictureHeader *ph; + void *ph_ref; ///< RefStruct reference backing referred-to PH above } H266RawSlice; typedef struct H266RawSEI { diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c index 6f52306080..7ef5bf1b71 100644 --- a/libavcodec/vvc/dec.c +++ b/libavcodec/vvc/dec.c @@ -852,8 +852,6 @@ static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, if (ret < 0) return ret; - av_refstruct_replace(&sc->ref, unit->content_ref); - if (is_first_slice) { ret = frame_start(s, fc, sc); if (ret < 0) @@ -927,7 +925,7 @@ static int export_frame_params(VVCContext *s, const VVCFrameContext *fc) static int frame_setup(VVCFrameContext *fc, VVCContext *s) { - int ret = ff_vvc_decode_frame_ps(&fc->ps, s); + int ret = ff_vvc_decode_frame_ps(fc, s); if (ret < 0) return ret; @@ -954,6 +952,7 @@ static int decode_slice(VVCContext *s, VVCFrameContext *fc, AVBufferRef *buf_ref return ret; sc = fc->slices[fc->nb_slices]; + av_refstruct_replace(&sc->ref, unit->content_ref); s->vcl_unit_type = nal->type; if (is_first_slice) { diff --git a/libavcodec/vvc/ps.c b/libavcodec/vvc/ps.c index 6eec0fe586..8faee1d826 100644 --- a/libavcodec/vvc/ps.c +++ b/libavcodec/vvc/ps.c @@ -743,21 +743,16 @@ static int decode_pps(VVCParamSets *ps, const H266RawPPS *rpps) return ret; } -static int decode_ps(VVCParamSets *ps, AVCodecContext *c, const CodedBitstreamH266Context *h266, int is_clvss) +static int decode_ps(VVCParamSets *ps, AVCodecContext *c, const SliceContext *sc, int is_clvss) { - const H266RawPictureHeader *ph = h266->ph; - const H266RawPPS *rpps; - const H266RawSPS *rsps; + const H266RawSlice *sl = sc->ref; + const H266RawPPS *rpps = sl->pps; + const H266RawSPS *rsps = sl->sps; int ret; - if (!ph) - return AVERROR_INVALIDDATA; - - rpps = h266->pps[ph->ph_pic_parameter_set_id]; if (!rpps) return AVERROR_INVALIDDATA; - rsps = h266->sps[rpps->pps_seq_parameter_set_id]; if (!rsps) return AVERROR_INVALIDDATA; @@ -1005,23 +1000,23 @@ static int decode_ph(VVCFrameParamSets *fps, const H266RawPictureHeader *rph, vo } static int decode_frame_ps(VVCFrameParamSets *fps, const VVCParamSets *ps, - const CodedBitstreamH266Context *h266, const int poc_tid0, const int is_clvss) + const SliceContext *sc, const int poc_tid0, const int is_clvss, const VVCContext *s) { - const H266RawPictureHeader *ph = h266->ph; - const H266RawPPS *rpps; + const H266RawSlice *sl = sc->ref; + const H266RawPictureHeader *ph = sl->ph; + const H266RawPPS *rpps = sl->pps; int ret; if (!ph) return AVERROR_INVALIDDATA; - rpps = h266->pps[ph->ph_pic_parameter_set_id]; if (!rpps) return AVERROR_INVALIDDATA; av_refstruct_replace(&fps->sps, ps->sps_list[rpps->pps_seq_parameter_set_id]); av_refstruct_replace(&fps->pps, ps->pps_list[rpps->pps_pic_parameter_set_id]); - ret = decode_ph(fps, ph, h266->ph_ref, poc_tid0, is_clvss); + ret = decode_ph(fps, ph, sl->ph_ref, poc_tid0, is_clvss); if (ret < 0) return ret; @@ -1058,21 +1053,22 @@ static void decode_recovery_poc(VVCContext *s, const VVCPH *ph) } } -int ff_vvc_decode_frame_ps(VVCFrameParamSets *fps, struct VVCContext *s) +int ff_vvc_decode_frame_ps(struct VVCFrameContext *fc, struct VVCContext *s) { int ret = 0; + VVCFrameParamSets *fps = &fc->ps; VVCParamSets *ps = &s->ps; - const CodedBitstreamH266Context *h266 = s->cbc->priv_data; + const SliceContext *sc = fc->slices[0]; int is_clvss; decode_recovery_flag(s); is_clvss = IS_CLVSS(s); - ret = decode_ps(ps, s->avctx, h266, is_clvss); + ret = decode_ps(ps, s->avctx, sc, is_clvss); if (ret < 0) return ret; - ret = decode_frame_ps(fps, ps, h266, s->poc_tid0, is_clvss); + ret = decode_frame_ps(fps, ps, sc, s->poc_tid0, is_clvss, s); decode_recovery_poc(s, &fps->ph); return ret; } diff --git a/libavcodec/vvc/ps.h b/libavcodec/vvc/ps.h index 3ec2238c17..90bd4c0e9e 100644 --- a/libavcodec/vvc/ps.h +++ b/libavcodec/vvc/ps.h @@ -266,8 +266,9 @@ typedef struct VVCSH { } VVCSH; struct VVCContext; +struct VVCFrameContext; -int ff_vvc_decode_frame_ps(VVCFrameParamSets *fps, struct VVCContext *s); +int ff_vvc_decode_frame_ps(struct VVCFrameContext *fc, struct VVCContext *s); int ff_vvc_decode_aps(VVCParamSets *ps, const CodedBitstreamUnit *unit); int ff_vvc_decode_sh(VVCSH *sh, const VVCFrameParamSets *ps, const CodedBitstreamUnit *unit); void ff_vvc_frame_ps_free(VVCFrameParamSets *fps); -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org