Implement Outbound/InboundRtpStreamStats.mid.

This is what allowed us to remove "transceiver" stats from the spec.

Bug: webrtc:14191
Change-Id: I687a2dd97de016832005cb4271f6e1a0e0560cd3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266022
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Philipp Hancke <philipp.hancke@googlemail.com>
Cr-Commit-Position: refs/heads/main@{#37247}
diff --git a/api/stats/rtcstats_objects.h b/api/stats/rtcstats_objects.h
index 5465d15..b2ebdd6 100644
--- a/api/stats/rtcstats_objects.h
+++ b/api/stats/rtcstats_objects.h
@@ -452,6 +452,7 @@
   // TODO(https://crbug.com/webrtc/14174): Implement trackIdentifier and kind.
 
   RTCStatsMember<std::string> track_identifier;
+  RTCStatsMember<std::string> mid;
   RTCStatsMember<std::string> remote_id;
   RTCStatsMember<uint32_t> packets_received;
   RTCStatsMember<uint64_t> fec_packets_received;
@@ -515,6 +516,7 @@
 
   RTCStatsMember<std::string> media_source_id;
   RTCStatsMember<std::string> remote_id;
+  RTCStatsMember<std::string> mid;
   RTCStatsMember<std::string> rid;
   RTCStatsMember<uint32_t> packets_sent;
   RTCStatsMember<uint64_t> retransmitted_packets_sent;
diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc
index efc90a3..04ea8b2 100644
--- a/pc/rtc_stats_collector.cc
+++ b/pc/rtc_stats_collector.cc
@@ -422,6 +422,7 @@
       timestamp_us);
   SetInboundRTPStreamStatsFromMediaReceiverInfo(voice_receiver_info,
                                                 inbound_audio.get());
+  inbound_audio->mid = mid;
   inbound_audio->media_type = "audio";
   inbound_audio->kind = "audio";
   if (voice_receiver_info.codec_payload_type) {
@@ -524,6 +525,7 @@
     RTCInboundRTPStreamStats* inbound_video) {
   SetInboundRTPStreamStatsFromMediaReceiverInfo(video_receiver_info,
                                                 inbound_video);
+  inbound_video->mid = mid;
   inbound_video->media_type = "video";
   inbound_video->kind = "video";
   if (video_receiver_info.codec_payload_type) {
@@ -615,6 +617,7 @@
     RTCOutboundRTPStreamStats* outbound_audio) {
   SetOutboundRTPStreamStatsFromMediaSenderInfo(voice_sender_info,
                                                outbound_audio);
+  outbound_audio->mid = mid;
   outbound_audio->media_type = "audio";
   outbound_audio->kind = "audio";
   if (voice_sender_info.target_bitrate > 0) {
@@ -634,6 +637,7 @@
     RTCOutboundRTPStreamStats* outbound_video) {
   SetOutboundRTPStreamStatsFromMediaSenderInfo(video_sender_info,
                                                outbound_video);
+  outbound_video->mid = mid;
   outbound_video->media_type = "video";
   outbound_video->kind = "video";
   if (video_sender_info.codec_payload_type) {
diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc
index 89d0daa..c008c1b 100644
--- a/pc/rtc_stats_collector_unittest.cc
+++ b/pc/rtc_stats_collector_unittest.cc
@@ -2099,6 +2099,7 @@
   expected_audio.media_type = "audio";
   expected_audio.kind = "audio";
   expected_audio.track_identifier = "RemoteAudioTrackID";
+  expected_audio.mid = "AudioMid";
   expected_audio.track_id = stats_of_track_type[0]->id();
   expected_audio.transport_id = "RTCTransport_TransportName_1";
   expected_audio.codec_id = "RTCCodec_AudioMid_Inbound_42";
@@ -2208,6 +2209,7 @@
   expected_video.media_type = "video";
   expected_video.kind = "video";
   expected_video.track_identifier = "RemoteVideoTrackID";
+  expected_video.mid = "VideoMid";
   expected_video.track_id = IdForType<RTCMediaStreamTrackStats>(report.get());
   expected_video.transport_id = "RTCTransport_TransportName_1";
   expected_video.codec_id = "RTCCodec_VideoMid_Inbound_42";
@@ -2300,6 +2302,7 @@
                                            report->timestamp_us());
   expected_audio.media_source_id = "RTCAudioSource_50";
   // `expected_audio.remote_id` should be undefined.
+  expected_audio.mid = "AudioMid";
   expected_audio.ssrc = 1;
   expected_audio.media_type = "audio";
   expected_audio.kind = "audio";
@@ -2387,6 +2390,7 @@
                                            report->timestamp_us());
   expected_video.media_source_id = "RTCVideoSource_50";
   // `expected_video.remote_id` should be undefined.
+  expected_video.mid = "VideoMid";
   expected_video.ssrc = 1;
   expected_video.media_type = "video";
   expected_video.kind = "video";
@@ -2728,6 +2732,7 @@
   RTCOutboundRTPStreamStats expected_audio("RTCOutboundRTPAudioStream_1",
                                            report->timestamp_us());
   expected_audio.media_source_id = "RTCAudioSource_50";
+  expected_audio.mid = "AudioMid";
   expected_audio.ssrc = 1;
   expected_audio.media_type = "audio";
   expected_audio.kind = "audio";
diff --git a/pc/rtc_stats_integrationtest.cc b/pc/rtc_stats_integrationtest.cc
index 6125137..a071786 100644
--- a/pc/rtc_stats_integrationtest.cc
+++ b/pc/rtc_stats_integrationtest.cc
@@ -799,6 +799,7 @@
                                         *inbound_stream.media_type == "audio");
     verifier.TestMemberIsOptionalIDReference(
         inbound_stream.remote_id, RTCRemoteOutboundRtpStreamStats::kType);
+    verifier.TestMemberIsDefined(inbound_stream.mid);
     verifier.TestMemberIsDefined(inbound_stream.track_identifier);
     if (inbound_stream.kind.is_defined() &&
         *inbound_stream.media_type == "video") {
@@ -926,6 +927,7 @@
       const RTCOutboundRTPStreamStats& outbound_stream) {
     RTCStatsVerifier verifier(report_.get(), &outbound_stream);
     VerifyRTCRTPStreamStats(outbound_stream, verifier);
+    verifier.TestMemberIsDefined(outbound_stream.mid);
     if (outbound_stream.kind.is_defined() &&
         *outbound_stream.media_type == "video") {
       verifier.TestMemberIsIDReference(outbound_stream.media_source_id,
diff --git a/stats/rtcstats_objects.cc b/stats/rtcstats_objects.cc
index 0605f93..77a2414 100644
--- a/stats/rtcstats_objects.cc
+++ b/stats/rtcstats_objects.cc
@@ -641,6 +641,7 @@
 WEBRTC_RTCSTATS_IMPL(
     RTCInboundRTPStreamStats, RTCReceivedRtpStreamStats, "inbound-rtp",
     &track_identifier,
+    &mid,
     &remote_id,
     &packets_received,
     &fec_packets_received,
@@ -690,6 +691,7 @@
                                                    int64_t timestamp_us)
     : RTCReceivedRtpStreamStats(std::move(id), timestamp_us),
       track_identifier("trackIdentifier"),
+      mid("mid"),
       remote_id("remoteId"),
       packets_received("packetsReceived"),
       fec_packets_received("fecPacketsReceived"),
@@ -735,6 +737,7 @@
     const RTCInboundRTPStreamStats& other)
     : RTCReceivedRtpStreamStats(other),
       track_identifier(other.track_identifier),
+      mid(other.mid),
       remote_id(other.remote_id),
       packets_received(other.packets_received),
       fec_packets_received(other.fec_packets_received),
@@ -784,6 +787,7 @@
     RTCOutboundRTPStreamStats, RTCRTPStreamStats, "outbound-rtp",
     &media_source_id,
     &remote_id,
+    &mid,
     &rid,
     &packets_sent,
     &retransmitted_packets_sent,
@@ -821,6 +825,7 @@
     : RTCRTPStreamStats(std::move(id), timestamp_us),
       media_source_id("mediaSourceId"),
       remote_id("remoteId"),
+      mid("mid"),
       rid("rid"),
       packets_sent("packetsSent"),
       retransmitted_packets_sent("retransmittedPacketsSent"),
@@ -854,6 +859,7 @@
     : RTCRTPStreamStats(other),
       media_source_id(other.media_source_id),
       remote_id(other.remote_id),
+      mid(other.mid),
       rid(other.rid),
       packets_sent(other.packets_sent),
       retransmitted_packets_sent(other.retransmitted_packets_sent),