Add dropped frames metric on the receive side

Reported to UMA and logged for at the end of the call.

Bug: webrtc:8355
Change-Id: I4ef31bf9e55feaba9cf28be5cb4fcfae929c7179
Reviewed-on: https://webrtc-review.googlesource.com/53760
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22132}
diff --git a/modules/video_coding/packet_buffer.cc b/modules/video_coding/packet_buffer.cc
index 741c11e..4a8904e 100644
--- a/modules/video_coding/packet_buffer.cc
+++ b/modules/video_coding/packet_buffer.cc
@@ -48,6 +48,7 @@
       data_buffer_(start_buffer_size),
       sequence_buffer_(start_buffer_size),
       received_frame_callback_(received_frame_callback),
+      unique_frames_seen_(0),
       sps_pps_idr_is_h264_keyframe_(
           field_trial::IsEnabled("WebRTC-SpsPpsIdrIsH264Keyframe")) {
   RTC_DCHECK_LE(start_buffer_size, max_buffer_size);
@@ -65,6 +66,8 @@
   {
     rtc::CritScope lock(&crit_);
 
+    OnTimestampReceived(packet->timestamp);
+
     uint16_t seq_num = packet->seqNum;
     size_t index = seq_num % size_;
 
@@ -207,6 +210,11 @@
   return last_received_keyframe_packet_ms_;
 }
 
+int PacketBuffer::GetUniqueFramesSeen() const {
+  rtc::CritScope lock(&crit_);
+  return unique_frames_seen_;
+}
+
 bool PacketBuffer::ExpandBufferSize() {
   if (size_ == max_size_) {
     RTC_LOG(LS_WARNING) << "PacketBuffer is already at max size (" << max_size_
@@ -484,5 +492,18 @@
   }
 }
 
+void PacketBuffer::OnTimestampReceived(uint32_t rtp_timestamp) {
+  const size_t kMaxTimestampsHistory = 1000;
+  if (rtp_timestamps_history_set_.insert(rtp_timestamp).second) {
+    rtp_timestamps_history_queue_.push(rtp_timestamp);
+    ++unique_frames_seen_;
+    if (rtp_timestamps_history_set_.size() > kMaxTimestampsHistory) {
+      uint32_t discarded_timestamp = rtp_timestamps_history_queue_.front();
+      rtp_timestamps_history_set_.erase(discarded_timestamp);
+      rtp_timestamps_history_queue_.pop();
+    }
+  }
+}
+
 }  // namespace video_coding
 }  // namespace webrtc