[FFmpeg-devel] [PATCH] lavc/vvc: Store RefStruct references to referenced PSs/headers in slice (PR #20557)
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 in
[FFmpeg-devel] [PATCH] lavc/vvc: Ensure seq_decode is always updated with SPS (PR #20717)
PR #20717 opened by frankplow
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20717
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20717.patch
seq_decode is used to ensure that a picture and all of its reference pictures
use the same SPS. Any time the SPS changes, seq_decode should be incremented.
Prior to this patch, seq_decode was incremented in frame_context_setup, which
is called after the SPS is potentially changed in decode_sps. Should the
decoder encounter an error between changing the SPS and incrementing
seq_decode, the SPS could be modified while seq_decode was not incremented,
which could lead to invalid reference pictures and various downstream issues.
By instead updating seq_decode within the picture set manager, we ensure
seq_decode and the SPS are always updated in tandem.
>From e611aeff64a15d12cede6da420e0173c665117a7 Mon Sep 17 00:00:00 2001
From: Frank Plowman
Date: Sun, 19 Oct 2025 12:28:00 +0100
Subject: [PATCH] lavc/vvc: Ensure seq_decode is always updated with SPS
seq_decode is used to ensure that a picture and all of its reference
pictures use the same SPS. Any time the SPS changes, seq_decode should
be incremented. Prior to this patch, seq_decode was incremented in
frame_context_setup, which is called after the SPS is potentially
changed in decode_sps. Should the decoder encounter an error between
changing the SPS and incrementing seq_decode, the SPS could be modified
while seq_decode was not incremented, which could lead to invalid
reference pictures and various downstream issues. By instead updating
seq_decode within the picture set manager, we ensure seq_decode and the
SPS are always updated in tandem.
---
libavcodec/vvc/dec.c | 1 -
libavcodec/vvc/ps.c | 2 ++
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
index bfe330e028..028f34b491 100644
--- a/libavcodec/vvc/dec.c
+++ b/libavcodec/vvc/dec.c
@@ -726,7 +726,6 @@ static int frame_context_setup(VVCFrameContext *fc,
VVCContext *s)
}
if (IS_IDR(s)) {
-s->seq_decode = (s->seq_decode + 1) & 0xff;
ff_vvc_clear_refs(fc);
}
diff --git a/libavcodec/vvc/ps.c b/libavcodec/vvc/ps.c
index 8faee1d826..a591851238 100644
--- a/libavcodec/vvc/ps.c
+++ b/libavcodec/vvc/ps.c
@@ -279,12 +279,14 @@ fail:
static int decode_sps(VVCParamSets *ps, AVCodecContext *c, const H266RawSPS
*rsps, int is_clvss)
{
+VVCContext *s = c->priv_data;
const int sps_id= rsps->sps_seq_parameter_set_id;
const VVCSPS *old_sps = ps->sps_list[sps_id];
const VVCSPS *sps;
if (is_clvss) {
ps->sps_id_used = 0;
+s->seq_decode = (s->seq_decode + 1) & 0xff;
}
if (old_sps) {
--
2.49.1
___
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
[FFmpeg-devel] [PATCH] lavc/Makefile: Make EXIF non-optional (PR #20317)
PR #20317 opened by frankplow URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20317 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20317.patch `av_exif_*` functions are used in decode.c since 5a9e5d8031b98dd269033918499e9db79c0a26c1, so we can't disable compiling the EXIF objects. Fixes compilation with `--disable-everything`. >From e2fb30f29f3051bf6d155fa1fb0c991f0603fde1 Mon Sep 17 00:00:00 2001 From: Frank Plowman Date: Fri, 22 Aug 2025 19:29:07 +0100 Subject: [PATCH] lavc/Makefile: Make EXIF non-optional av_exif_* functions are used in decode.c since 5a9e5d8031b98dd269033918499e9db79c0a26c1, so we can't disable compiling the EXIF objects. Fixes compilation with --disable-everything. --- libavcodec/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 35408949ac..3d036de4b6 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -43,6 +43,7 @@ OBJS = ac3_parser.o \ dirac.o \ dv_profile.o \ encode.o \ + exif.o \ get_buffer.o \ imgconvert.o \ jni.o\ @@ -57,6 +58,7 @@ OBJS = ac3_parser.o \ qsv_api.o\ raw.o\ threadprogress.o \ + tiff_common.o\ utils.o \ version.o\ vlc.o\ @@ -101,7 +103,6 @@ OBJS-$(CONFIG_DOVI_RPUDEC) += dovi_rpu.o dovi_rpudec.o OBJS-$(CONFIG_DOVI_RPUENC) += dovi_rpu.o dovi_rpuenc.o OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o OBJS-$(CONFIG_EVCPARSE)+= evc_parse.o evc_ps.o -OBJS-$(CONFIG_EXIF)+= exif.o tiff_common.o OBJS-$(CONFIG_FAANDCT) += faandct.o OBJS-$(CONFIG_FAANIDCT)+= faanidct.o OBJS-$(CONFIG_FDCTDSP) += fdctdsp.o jfdctfst.o jfdctint.o -- 2.49.1 ___ ffmpeg-devel mailing list [email protected] https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email [email protected] with subject "unsubscribe".
[FFmpeg-devel] [PATCH] lavc/cbs: Make error message more descriptive (PR #20374)
PR #20374 opened by frankplow
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20374
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20374.patch
>From f05e2e35768798c2ae17ebf94dd7579635a4361e Mon Sep 17 00:00:00 2001
From: Frank Plowman
Date: Sat, 30 Aug 2025 12:10:12 +0100
Subject: [PATCH] lavc/cbs: Make error message more descriptive
---
libavcodec/cbs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 6b2ebe597d..0f54c407f3 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -231,7 +231,8 @@ static int cbs_read_fragment_content(CodedBitstreamContext
*ctx,
unit->content = NULL;
} else if (err < 0) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
- "(type %"PRIu32").\n", i, unit->type);
+ "(type %"PRIu32"): %s.\n",
+ i, unit->type, av_err2str(err));
return err;
}
}
--
2.49.1
___
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
[FFmpeg-devel] [PATCH] lavc/hevc: Fix usage of slice segment in invalid state (PR #20869)
PR #20869 opened by frankplow
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20869
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20869.patch
Previously, we set s->slice_initialized to 0 to prevent other slice segments
from depending on this slice segment only if hls_slice_header failed. If
decode_slice fails for some other reason, however, before decode_slice_data is
called to bring the context back into a consistent state, then slices could
depend on this slice segment while it is in an invalid state. This can cause
segmentation faults and other sorts of nastiness. Patch fixes this by always
setting s->slice_initialized to 0 while the state is inconsistent.
Resolves #11652.
>From 59586a530a29b7f30c566fc8904c83e1053167bc Mon Sep 17 00:00:00 2001
From: Frank Plowman
Date: Sat, 8 Nov 2025 18:35:51 +
Subject: [PATCH] lavc/hevc: Fix usage of slice segment in invalid state
Previously, we set s->slice_initialized to 0 to prevent other slice
segments from depending on this slice segment only if hls_slice_header
failed. If decode_slice fails for some other reason, however, before
decode_slice_data is called to bring the context back into a consistent
state, then slices could depend on this slice segment while it is in an
invalid state. This can cause segmentation faults and other sorts of
nastiness. Patch fixes this by always setting s->slice_initialized to 0
while the state is inconsistent.
Resolves #11652.
---
libavcodec/hevc/hevcdec.c | 6 --
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 8d432a9a1f..74b4a4c046 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3544,10 +3544,12 @@ static int decode_slice(HEVCContext *s, unsigned
nal_idx, GetBitContext *gb)
ret = hls_slice_header(&s->sh, s, gb);
if (ret < 0) {
-// hls_slice_header() does not cleanup on failure thus the state now
is inconsistent so we cannot use it on dependent slices
-s->slice_initialized = 0;
return ret;
}
+// Once hls_slice_header has been called, the context is inconsistent with
the slice header
+// until the context is reinitialized according to the contents of the new
slice header
+// at the start of decode_slice_data.
+s->slice_initialized = 0;
if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type ==
HEVC_SLICE_B) ||
(s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type !=
HEVC_SLICE_I) ||
--
2.49.1
___
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
