• Andreas Rheinhardt's avatar
    avcodec/h26[45]_metadata_bsf: Use separate contexts for reading/writing · 235a5734
    Andreas Rheinhardt authored
    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: 's avatarMark Thompson <sw@jkqxz.net>
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
    235a5734
h265_metadata_bsf.c 21 KB