hxx_sei: Fix improper counting of remaining bytes due to 3-byte emulation
commit9a478df9efbc80b5718b2c7e5fe6511e183f56c4
authorDevin Heitmueller <dheitmueller@ltnglobal.com>
Thu, 9 Aug 2018 19:36:44 +0000 (9 15:36 -0400)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Sun, 19 Aug 2018 18:21:24 +0000 (19 20:21 +0200)
treee0e7f8cdf229c9074ed9bea5fad824213c9eeb57
parentfeb75e4148220664fc3c38766390083b19077904
hxx_sei: Fix improper counting of remaining bytes due to 3-byte emulation

The routine which iterates over the RBSP to process the SEIs
attempts to accommodate the individual parsers not reading all
the bytes (i.e. by reading any remaining bytes before restarting
the loop), as well as detecting if the parser for a given type
read past the end of SEI.  However the implementation does this
by noting the position of the start of the NAL, getting the
position after parsing, and computing the difference.  This does
not take into account that the bitstream parser has a pf_forward
routine to strip out 3-byte emulation.

Hence in cases where an emulation sequence is found, the number
of bytes processed by the parser don't match how many bytes were
actually consumed in the stream.  The failure occurs at the bottom
of the loop where either it fails to read out extra bytes if the
parser didn't process the entire SEI, or aborting prematurely
thinking that the parser processed too many bytes.

To avoid this issue, clone the bitstream into a second instance
which already has the three byte emulation stripped, and use that
with the existing parser routines.

The use case where this problem manifested was a low latency
stream where it failed to find the SEI recovery point because
there was an emulation sequence in the preceding picture timing
SEI section, and this caused the loop to bail out because the
bs_position was past the size of the picture_timing SEI length.

Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
Signed-off-by: Francois Cartegnie <fcvlcdev@free.fr>
modules/packetizer/hxxx_sei.c