StreamDataCounters::last_packet_received_timestamp_ms added.

This a standard stat:
https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp

This is collected by StreamStatisticianImpl. A follow-up CL with plumb
it to the RTCStatsCollector.

Bug: webrtc:10449
Change-Id: I44e7f4735f9df78704ce21198f52e66d11e63740
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130479
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27416}
diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.h b/modules/rtp_rtcp/include/rtp_rtcp_defines.h
index 8691fe7..cbeb77f 100644
--- a/modules/rtp_rtcp/include/rtp_rtcp_defines.h
+++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.h
@@ -448,6 +448,10 @@
   }
 
   int64_t first_packet_time_ms;    // Time when first packet is sent/received.
+  // The timestamp at which the last packet was received, i.e. the time of the
+  // local clock when it was received - not the RTP timestamp of that packet.
+  // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
+  absl::optional<int64_t> last_packet_received_timestamp_ms;
   RtpPacketCounter transmitted;    // Number of transmitted packets/bytes.
   RtpPacketCounter retransmitted;  // Number of retransmitted packets/bytes.
   RtpPacketCounter fec;            // Number of redundancy packets/bytes.
diff --git a/modules/rtp_rtcp/source/receive_statistics_impl.cc b/modules/rtp_rtcp/source/receive_statistics_impl.cc
index 066dc4b..b696daa 100644
--- a/modules/rtp_rtcp/source/receive_statistics_impl.cc
+++ b/modules/rtp_rtcp/source/receive_statistics_impl.cc
@@ -108,6 +108,7 @@
   int64_t now_ms = clock_->TimeInMilliseconds();
 
   incoming_bitrate_.Update(packet.size(), now_ms);
+  receive_counters_.last_packet_received_timestamp_ms = now_ms;
   receive_counters_.transmitted.AddPacket(packet);
 
   int64_t sequence_number =
diff --git a/modules/rtp_rtcp/source/receive_statistics_unittest.cc b/modules/rtp_rtcp/source/receive_statistics_unittest.cc
index 1703cee..2c6dc38 100644
--- a/modules/rtp_rtcp/source/receive_statistics_unittest.cc
+++ b/modules/rtp_rtcp/source/receive_statistics_unittest.cc
@@ -605,6 +605,19 @@
   callback.Matches(5, kSsrc1, expected);
 }
 
+TEST_F(ReceiveStatisticsTest, LastPacketReceivedTimestamp) {
+  RtpTestCallback callback;
+  receive_statistics_ = ReceiveStatistics::Create(&clock_, nullptr, &callback);
+
+  clock_.AdvanceTimeMilliseconds(42);
+  receive_statistics_->OnRtpPacket(packet1_);
+  EXPECT_EQ(42, callback.stats_.last_packet_received_timestamp_ms);
+
+  clock_.AdvanceTimeMilliseconds(3);
+  receive_statistics_->OnRtpPacket(packet1_);
+  EXPECT_EQ(45, callback.stats_.last_packet_received_timestamp_ms);
+}
+
 TEST_F(ReceiveStatisticsTest, RtpCallbacksFecFirst) {
   RtpTestCallback callback;
   receive_statistics_ = ReceiveStatistics::Create(&clock_, nullptr, &callback);