RTCInboundRtpStreamStats  should have a framesDropped property
https://bugs.webkit.org/show_bug.cgi?id=241844
rdar://problem/95669239

Patch by Youenn Fablet <youennf@gmail.com> on 2022-06-23
Reviewed by Eric Carlson.

We should add framesDropped to RTCReceivedRtpStreamStats as per spec but our WebRC backend only supports it in RTCInboundRtpStreamStats.
Let's add this property there since this is used by some applications.

* LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-mandatory-getStats.https.html:
* LayoutTests/webrtc/video-stats.html:
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.cpp:
(WebCore::fillReceivedRtpStreamStats):
(WebCore::fillInboundRtpStreamStats):

Canonical link: https://commits.webkit.org/251778@main

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@295773 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-mandatory-getStats.https-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-mandatory-getStats.https-expected.txt
index 0a8ae96..067d58c 100644
--- a/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-mandatory-getStats.https-expected.txt
+++ b/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-mandatory-getStats.https-expected.txt
@@ -9,7 +9,7 @@
 PASS RTCReceivedRtpStreamStats's packetsLost
 PASS RTCReceivedRtpStreamStats's jitter
 PASS RTCReceivedRtpStreamStats's packetsDiscarded
-FAIL RTCReceivedRtpStreamStats's framesDropped assert_true: Is framesDropped present expected true got false
+PASS RTCReceivedRtpStreamStats's framesDropped
 FAIL RTCInboundRtpStreamStats's receiverId assert_true: Is receiverId present expected true got false
 FAIL RTCInboundRtpStreamStats's remoteId assert_true: Is remoteId present expected true got false
 PASS RTCInboundRtpStreamStats's framesDecoded
diff --git a/LayoutTests/webrtc/video-stats.html b/LayoutTests/webrtc/video-stats.html
index c79bec8..a2604ce 100644
--- a/LayoutTests/webrtc/video-stats.html
+++ b/LayoutTests/webrtc/video-stats.html
@@ -122,6 +122,7 @@
 function checkInboundFramesNumberIncreased(secondConnection, statsSecondConnection, count)
 {
     return getInboundRTPStats(secondConnection).then((stats) => {
+        assert_true("framesDropped" in stats);
         assert_true(!!stats.kind);
         if (stats.framesDecoded > statsSecondConnection.framesDecoded) {
             if (testTimestampDifference(stats.timestamp - statsSecondConnection.timestamp, stats.framesDecoded - statsSecondConnection.framesDecoded))
diff --git a/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.cpp b/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.cpp
index 5466115..02c1447 100644
--- a/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.cpp
+++ b/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCStatsCollector.cpp
@@ -80,12 +80,15 @@
 {
     fillRtpStreamStats(stats, rtcStats);
 
+    // packetsReceived
     if (rtcStats.packets_lost.is_defined())
         stats.packetsLost = *rtcStats.packets_lost;
     if (rtcStats.jitter.is_defined())
         stats.jitter = *rtcStats.jitter;
+    // FIXME: Remove packets_discarded
     if (rtcStats.packets_discarded.is_defined())
         stats.packetsDiscarded = *rtcStats.packets_discarded;
+    // framesDropped
 }
 
 static inline void fillInboundRtpStreamStats(RTCStatsReport::InboundRtpStreamStats& stats, const webrtc::RTCInboundRTPStreamStats& rtcStats)
@@ -114,7 +117,9 @@
         stats.gapLossRate = *rtcStats.gap_loss_rate;
     if (rtcStats.gap_discard_rate.is_defined())
         stats.gapDiscardRate = *rtcStats.gap_discard_rate;
-    // Add frames_dropped and full_frames_lost.
+    if (rtcStats.frames_dropped.is_defined())
+        stats.framesDropped = *rtcStats.frames_dropped;
+    // full_frames_lost.
 
     if (rtcStats.frames_decoded.is_defined())
         stats.framesDecoded = *rtcStats.frames_decoded;