Fix race condition in cleanup of old frame records.
Fix race condition in cleanup of old frame records.

VideoEncoderWrapper may be released and reused (Release() followed by
InitEncode()). This often happens back to back when encoders are
reconfigured. Because encoded frames are posted asynchronously to the
encoder queue, they may be processed after the encoder associated with
them has already been released.

In the existing code, if a frame for the new encoder had already been
received, the processing of the frame for the old encoder would clear
out the record for the new encoder's frame. This is now fixed by only
clearing out records that are older than the encoded frame being
processed.

A particularly bad symptom is when the new encoder is used for the same
stream as the old one (but was reconfigured for e.g. a change in
resolution). In that case, the new encoder's initial keyframe gets
dropped, and all subsequent difference frames are based off the last
sent frame from the old encoder. This all renders as garbage until a new
keyframe is sent.

Bug: webrtc:8849
Change-Id: I25094f12b38e03e158dc10ac66e92aa9ebaa5541
Reviewed-on: https://webrtc-review.googlesource.com/47549
Commit-Queue: Jonathan Yu <53511739ffbf37996986922e276a03226eb89d41@chromium.org>
Reviewed-by: Sami Kalliomäki <b9debeb8943b89663e00c95863751401cba91c9a@webrtc.org>
Cr-Commit-Position: 972c6d2dc6dd5efdad1377c0d224e03eb8f276f7@{#21896}
ShiftMediaProject/libilbc,TimothyGu/libilbc,ShiftMediaProject/libilbc,TimothyGu/libilbc,TimothyGu/libilbc,ShiftMediaProject/libilbc,ShiftMediaProject/libilbc,ShiftMediaProject/libilbc,TimothyGu/libilbc,TimothyGu/libilbc