Replace timestamp map with a deque in generic decoder

* Add test to Generic decoder unittests to ensure drop behaviour is covered.
* Use simulated time in the generic decoder unittests.

Bug: webrtc:14324
Change-Id: I10b28b45c434f92d5344683fb9ca6676efe0e08c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/270662
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37710}
diff --git a/modules/video_coding/generic_decoder.h b/modules/video_coding/generic_decoder.h
index 70c79da..d7e1850 100644
--- a/modules/video_coding/generic_decoder.h
+++ b/modules/video_coding/generic_decoder.h
@@ -11,14 +11,15 @@
 #ifndef MODULES_VIDEO_CODING_GENERIC_DECODER_H_
 #define MODULES_VIDEO_CODING_GENERIC_DECODER_H_
 
+#include <cstdint>
+#include <deque>
 #include <string>
+#include <utility>
 
 #include "api/field_trials_view.h"
 #include "api/sequence_checker.h"
 #include "api/video_codecs/video_decoder.h"
 #include "modules/video_coding/encoded_frame.h"
-#include "modules/video_coding/include/video_codec_interface.h"
-#include "modules/video_coding/timestamp_map.h"
 #include "modules/video_coding/timing/timing.h"
 #include "rtc_base/synchronization/mutex.h"
 
@@ -26,7 +27,26 @@
 
 class VCMReceiveCallback;
 
-enum { kDecoderFrameMemoryLength = 10 };
+struct FrameInfo {
+  FrameInfo() = default;
+  FrameInfo(const FrameInfo&) = delete;
+  FrameInfo& operator=(const FrameInfo&) = delete;
+  FrameInfo(FrameInfo&&) = default;
+  FrameInfo& operator=(FrameInfo&&) = default;
+
+  uint32_t rtp_timestamp;
+  // This is likely not optional, but some inputs seem to sometimes be negative.
+  // TODO(bugs.webrtc.org/13756): See if this can be replaced with Timestamp
+  // once all inputs to this field use Timestamp instead of an integer.
+  absl::optional<Timestamp> render_time;
+  absl::optional<Timestamp> decode_start;
+  VideoRotation rotation;
+  VideoContentType content_type;
+  EncodedImage::Timing timing;
+  int64_t ntp_time_ms;
+  RtpPacketInfos packet_infos;
+  // ColorSpace is not stored here, as it might be modified by decoders.
+};
 
 class VCMDecodedFrameCallback : public DecodedImageCallback {
  public:
@@ -45,12 +65,14 @@
 
   void OnDecoderImplementationName(const char* implementation_name);
 
-  void Map(uint32_t timestamp, const FrameInformation& frameInfo);
+  void Map(FrameInfo frameInfo);
   void ClearTimestampMap();
 
  private:
+  std::pair<absl::optional<FrameInfo>, size_t> FindFrameInfo(
+      uint32_t rtp_timestamp) RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
+
   SequenceChecker construction_thread_;
-  // Protect `_timestampMap`.
   Clock* const _clock;
   // This callback must be set before the decoder thread starts running
   // and must only be unset when external threads (e.g decoder thread)
@@ -60,7 +82,7 @@
   VCMReceiveCallback* _receiveCallback = nullptr;
   VCMTiming* _timing;
   Mutex lock_;
-  TimestampMap _timestampMap RTC_GUARDED_BY(lock_);
+  std::deque<FrameInfo> frame_infos_ RTC_GUARDED_BY(lock_);
   int64_t ntp_offset_;
 };