History

lavc/vvc: Error if SPS ID is duplicated within CVS

Key line from the spec is: "All SPS NAL units with a particular value of sps_seq_parameter_set_id in a CVS shall have the same content." Prior to this patch, the VVC decoder's behaviour on encountering a duplicated SPS ID (within the entire bitstream, not restricted to a CVS) was simply to replace the entry in the SPS lookup table with the new data. Illegal bitstreams with multiple SPSs in the same CVS sharing an ID but differing elsewhere could cause all manner of issues. The patch tracks which SPS IDs have been used in the given CVS using the new sps_id_used field of VVCParamSets. If it encounters an SPS with an ID already in use and whose content differs from the previous SPS, it throws an AVERROR_INVALIDDATA.

Frank Plowman committed 2 years ago

Commit 2d79ae31 parent 0dbf4512 files · +23 −8Browse files

Unified · Split

2 files
  1. libavcodec/vvc/ps.c +20 −8
  2. libavcodec/vvc/ps.h +3 −0
libavcodec/vvc/ps.c+20−8
@@ -219,14 +219,22 @@ fail: · 218 unmodified lines
219 return NULL;219 return NULL;
220}220}
221 221
222static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx)222static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx, int is_clvss)
223{223{
224 const int sps_id = rsps->sps_seq_parameter_set_id;224 const int sps_id = rsps->sps_seq_parameter_set_id;
225 const VVCSPS *old_sps = ps->sps_list[sps_id];225 const VVCSPS *old_sps = ps->sps_list[sps_id];
226 const VVCSPS *sps;226 const VVCSPS *sps;
227 227
228 if (old_sps && old_sps->r == rsps)228 if (is_clvss) {
229 return 0;229 ps->sps_id_used = 0;
230 }
231
232 if (old_sps) {
233 if (old_sps->r == rsps || !memcmp(old_sps->r, rsps, sizeof(*old_sps->r)))
234 return 0;
235 else if (ps->sps_id_used & (1 << sps_id))
236 return AVERROR_INVALIDDATA;
237 }
230 238
231 sps = sps_alloc(rsps, log_ctx);239 sps = sps_alloc(rsps, log_ctx);
232 if (!sps)240 if (!sps)
@@ -234,6 +242,7 @@ static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx) · 1 unmodified line
234 242
235 ff_refstruct_unref(&ps->sps_list[sps_id]);243 ff_refstruct_unref(&ps->sps_list[sps_id]);
236 ps->sps_list[sps_id] = sps;244 ps->sps_list[sps_id] = sps;
245 ps->sps_id_used |= (1 << sps_id);
237 246
238 return 0;247 return 0;
239}248}
@@ -610,7 +619,7 @@ static int decode_pps(VVCParamSets *ps, const H266RawPPS *rpps) · 370 unmodified lines
610 return ret;619 return ret;
611}620}
612 621
613static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, void *log_ctx)622static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, void *log_ctx, int is_clvss)
614{623{
615 const H266RawPictureHeader *ph = h266->ph;624 const H266RawPictureHeader *ph = h266->ph;
616 const H266RawPPS *rpps;625 const H266RawPPS *rpps;
@@ -628,7 +637,7 @@ static int decode_ps(VVCParamSets *ps, const CodedBitstreamH266Context *h266, vo · 11 unmodified lines
628 if (!rsps)637 if (!rsps)
629 return AVERROR_INVALIDDATA;638 return AVERROR_INVALIDDATA;
630 639
631 ret = decode_sps(ps, rsps, log_ctx);640 ret = decode_sps(ps, rsps, log_ctx, is_clvss);
632 if (ret < 0)641 if (ret < 0)
633 return ret;642 return ret;
634 643
@@ -867,13 +876,16 @@ int ff_vvc_decode_frame_ps(VVCFrameParamSets *fps, struct VVCContext *s) · 232 unmodified lines
867 int ret = 0;876 int ret = 0;
868 VVCParamSets *ps = &s->ps;877 VVCParamSets *ps = &s->ps;
869 const CodedBitstreamH266Context *h266 = s->cbc->priv_data;878 const CodedBitstreamH266Context *h266 = s->cbc->priv_data;
879 int is_clvss;
880
881 decode_recovery_flag(s);
882 is_clvss = IS_CLVSS(s);
870 883
871 ret = decode_ps(ps, h266, s->avctx);884 ret = decode_ps(ps, h266, s->avctx, is_clvss);
872 if (ret < 0)885 if (ret < 0)
873 return ret;886 return ret;
874 887
875 decode_recovery_flag(s);888 ret = decode_frame_ps(fps, ps, h266, s->poc_tid0, is_clvss);
876 ret = decode_frame_ps(fps, ps, h266, s->poc_tid0, IS_CLVSS(s));
877 decode_recovery_poc(s, &fps->ph);889 decode_recovery_poc(s, &fps->ph);
878 return ret;890 return ret;
879}891}
libavcodec/vvc/ps.h+3−0
@@ -214,6 +214,9 @@ typedef struct VVCParamSets { · 213 unmodified lines
214 const VVCALF *alf_list[VVC_MAX_ALF_COUNT]; ///< RefStruct reference214 const VVCALF *alf_list[VVC_MAX_ALF_COUNT]; ///< RefStruct reference
215 const H266RawAPS *lmcs_list[VVC_MAX_LMCS_COUNT]; ///< RefStruct reference215 const H266RawAPS *lmcs_list[VVC_MAX_LMCS_COUNT]; ///< RefStruct reference
216 const VVCScalingList *scaling_list[VVC_MAX_SL_COUNT]; ///< RefStruct reference216 const VVCScalingList *scaling_list[VVC_MAX_SL_COUNT]; ///< RefStruct reference
217
218 // Bit field of SPS IDs used in the current CVS
219 uint16_t sps_id_used;
217} VVCParamSets;220} VVCParamSets;
218 221
219typedef struct VVCFrameParamSets {222typedef struct VVCFrameParamSets {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t