]> git.sesse.net Git - ffmpeg/commit
avcodec/h26[45]_metadata_bsf: Use separate contexts for reading/writing
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 5 Jul 2020 22:46:40 +0000 (00:46 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 7 Jul 2020 03:07:15 +0000 (05:07 +0200)
commit235a5734e084f2746b4c133bf33cb4579a6ca17f
tree4e8689103e568ebed7876556d7323e595802196f
parent1bdbc50bf4379d3993b47b8510045e4d236de555
avcodec/h26[45]_metadata_bsf: Use separate contexts for reading/writing

Currently, both bsfs used the same CodedBitstreamContext for reading and
writing; as a consequence, the state of the writer's context at the
beginning of writing a fragment is exactly the state of the reader after
having read the fragment; in particular, the writer might not have
encountered one of its active parameter sets yet.

This is not nice and may lead to invalid output even when the input
is completely spec-compliant: Think of an access unit containing
a primary coded picture referencing a PPS with id id (that is known from
an earlier access unit/from extradata), then a new version of the PPS
with id id and then a redundant coded picture that is also referencing
the PPS with id id. This is spec-compliant, as the standard allows to
overwrite a PPS with a different PPS in between coded pictures and not
only at the beginning of an access unit. In this scenario, the reader
would read the primary coded picture with the old PPS and the redundant
coded picture with the new PPS (as it should); yet the writer would
write both with the new PPS as extradata which might lead to errors or
to invalid data being output without any error (e.g. if the two PPS
differed in redundant_pic_cnt_present_flag).

The above scenario does not directly translate to HEVC as long as one
restricts oneself to input with nuh_layer_id == 0 only (as cbs_h265
does: it currently strips away any NAL unit with nuh_layer_id > 0 when
decomposing); if one doesn't the same issue as above can happen.

If one also allowed input packets to contain more than one access unit,
issues like the above can happen even without redundant coded
pictures/multiple layers.

Therefore this commit uses separate contexts for reader and writer.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/h264_metadata_bsf.c
libavcodec/h265_metadata_bsf.c