Problem description
===================
1)The reference decoder crashes when error concealment of type 1 (frame copy) is enabled. Even with valid bitstreams, the decoder can crash.

The issue is caused by a number of things.

- The variable last_output_poc in the dpb is not updated when non reference pictures are send directly to the output. As a result, the decoder sometimes thinks there are missing frames while they have been processed correctly. It then tries to read concealed pictures but
can not find any, resulting in a crash.

- The function conceal_non_ref_pics does not detect all missing non reference pictures. As a result, it sometimes does not conceal a missing picture after which write_lost_non_ref_pic tries to retrieve a non-existing picture and makes the decoder crash.

- The function write_lost_non_ref_pic only writes out one picture at a time. As a result, if consecutive non reference frames are concealed, only the first one is written when needed, and the second one is written much later at an incorrect position. So when decoding is finished, there can actually be several concealed pictures still be in the buffer.

- The function free_global_buffers is called before the dpb is flushed at the end of the decoding loop. There still might be missing non reference pictures which are not yet concealed. As a result, the error concealment tools have no longer access to the 'global buffers'.

2)Reporting in case of error concealment is missing, incomplete of printed in the wrong place.

- Only if the PSNR is calculated, a report is printed on concealed reference pictures.

- No report is printed on concealed non-reference pictures.

- The final Report is printed before the dpb is flushed at the end of the decoding loop. There still might be missing non reference pictures which are not yet concealed. As a result, stats on those pictures might be displayed after the final report.




Content of this zip file
========================
configs
-------
Configuration files

encoder.cfg: configuration file used to generate lossless.264
decoder.cfg: example configuration file to decode the (corrupted) streams

testvectors
-----------
All testvectors are based on lossless.264 which is the encoded following file:

  IDR b1 b2 b3 P1 b4 b5 b6 P2

lossless.264: no losses
loss01.264  : P1 is lost
loss02.264  : b1 and P1 are lost
loss03.264  : P1 and b4 are lost
loss04.264  : b3, P1, and b4 are lost
loss05.264  : b1 is lost
loss06.264  : b2 is lost
loss07.264  : b3 is lost
loss08.264  : b1 and b2 are lost
loss09.264  : b2 and b3 are lost
loss10.264  : b1 and b3 are lost
loss11.264  : b1, b2, and b3 are lost
loss12.264  : P2 is lost
loss13.264  : P2 and b6 are lost
loss14.264  : P2 and b4 are lost
loss15.264  : b4 is lost
loss16.264  : b5 is lost
loss17.264  : b6 is lost
loss18.264  : b4 and b5 are lost
loss19.264  : b5 and b6 are lost
loss20.264  : b4 and b6 are lost
loss21.264  : b4, b5, and b6 are lost

src
---
Adjusted source files.

ldecod.c    : moved calls to "free_slice", "free_global_buffers", and "Report" to after "flush_dpb" in main.
mbuffer.c   : changed calls to error concealment functions, updated last_output_poc in case of direct output
image.c     : commented out reporting code for concealed frames
erc_do_p.c  : rewrote most of the missing non reference picture detection and concealment code
, added reporting functions




Note
====
This does not fix the issues with motion copy concealment!