Add support for Certificate and IceCandidatePair stats
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 May 2017 23:32:00 +0000 (23:32 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 May 2017 23:32:00 +0000 (23:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172734

Patch by Youenn Fablet <youenn@apple.com> on 2017-05-30
Reviewed by Geoff Garen.

Source/WebCore:

Covered by updated test.

Adding support for these two stats in the IDL and in the libwebrtc binding code.

* Modules/mediastream/RTCStatsReport.h:
(WebCore::RTCStatsReport::IceCandidatePairStats::IceCandidatePairStats):
(WebCore::RTCStatsReport::CertificateStats::CertificateStats):
* Modules/mediastream/RTCStatsReport.idl:
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::iceCandidatePairState):
(WebCore::fillRTCIceCandidatePairStats):
(WebCore::fillRTCCertificateStats):
(WebCore::LibWebRTCMediaEndpoint::StatsCollector::OnStatsDelivered):

LayoutTests:

* webrtc/video-stats.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217583 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webrtc/video-stats.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCStatsReport.h
Source/WebCore/Modules/mediastream/RTCStatsReport.idl
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

index bd7d741..c4445d3 100644 (file)
@@ -1,3 +1,12 @@
+2017-05-30  Youenn Fablet  <youenn@apple.com>
+
+        Add support for Certificate and IceCandidatePair stats
+        https://bugs.webkit.org/show_bug.cgi?id=172734
+
+        Reviewed by Geoff Garen.
+
+        * webrtc/video-stats.html:
+
 2017-05-30  Chris Dumez  <cdumez@apple.com>
 
         REGRESSION(r215946): Can't reference a table cell in Google spreadsheet
index 6e9d9a9..3340bf1 100644 (file)
@@ -9,6 +9,17 @@
     <body>
         <script src ="routines.js"></script>
         <script>
+function getStatsType(connection)
+{
+    return connection.getStats().then((report) => {
+        var reportTypes = [];
+        report.forEach((statItem) => {
+            if (reportTypes.indexOf(statItem.type) === -1)
+                reportTypes.push(statItem.type);
+        });
+        return reportTypes.sort();
+    });
+}
 
 function checkStatsReportIterator(report)
 {
@@ -114,6 +125,14 @@ promise_test((test) => {
         return checkInboundFramesNumberIncreased(secondConnection, statsSecondConnection, 0);
     }).then(() => {
         return checkOutboundFramesNumberIncreased(firstConnection, statsFirstConnection, 0);
+    }).then(() => {
+        return getStatsType(firstConnection);
+    }).then((types) => {
+        assert_array_equals(types, ["candidate-pair", "certificate", "outbound-rtp"]);
+    }).then(() => {
+        return getStatsType(secondConnection);
+    }).then((types) => {
+        assert_array_equals(types, ["candidate-pair", "certificate", "inbound-rtp", "track"]);
     });
 }, "Basic video stats");
         </script>
index 9a614c4..add6c92 100644 (file)
@@ -1,3 +1,24 @@
+2017-05-30  Youenn Fablet  <youenn@apple.com>
+
+        Add support for Certificate and IceCandidatePair stats
+        https://bugs.webkit.org/show_bug.cgi?id=172734
+
+        Reviewed by Geoff Garen.
+
+        Covered by updated test.
+
+        Adding support for these two stats in the IDL and in the libwebrtc binding code.
+
+        * Modules/mediastream/RTCStatsReport.h:
+        (WebCore::RTCStatsReport::IceCandidatePairStats::IceCandidatePairStats):
+        (WebCore::RTCStatsReport::CertificateStats::CertificateStats):
+        * Modules/mediastream/RTCStatsReport.idl:
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::iceCandidatePairState):
+        (WebCore::fillRTCIceCandidatePairStats):
+        (WebCore::fillRTCCertificateStats):
+        (WebCore::LibWebRTCMediaEndpoint::StatsCollector::OnStatsDelivered):
+
 2017-05-30  Jiewen Tan  <jiewen_tan@apple.com>
 
         Unreviewed, add some comments to HKDF/PBKDF2 Mac implementations
index ff84f1e..01f3e7f 100644 (file)
@@ -151,6 +151,53 @@ public:
         unsigned long long bytesReceived { 0 };
     };
 
+    enum class IceCandidatePairState {
+        Frozen,
+        Waiting,
+        Inprogress,
+        Failed,
+        Succeeded,
+        Cancelled
+    };
+
+    struct IceCandidatePairStats : Stats {
+        IceCandidatePairStats() { type = RTCStatsReport::Type::CandidatePair; }
+
+        String transportId;
+        String localCandidateId;
+        String remoteCandidateId;
+        IceCandidatePairState state;
+        unsigned long long priority { 0 };
+        bool nominated { false };
+        bool writable { false };
+        bool readable { false };
+        unsigned long long bytesSent { 0 };
+        unsigned long long bytesReceived { 0 };
+        double totalRoundTripTime { 0 };
+        double currentRoundTripTime { 0 };
+        double availableOutgoingBitrate { 0 };
+        double availableIncomingBitrate { 0 };
+        unsigned long long requestsReceived { 0 };
+        unsigned long long requestsSent { 0 };
+        unsigned long long responsesReceived { 0 };
+        unsigned long long responsesSent { 0 };
+        unsigned long long retransmissionsReceived { 0 };
+        unsigned long long retransmissionsSent { 0 };
+        unsigned long long consentRequestsReceived { 0 };
+        unsigned long long consentRequestsSent { 0 };
+        unsigned long long consentResponsesReceived { 0 };
+        unsigned long long consentResponsesSent { 0 };
+    };
+
+    struct CertificateStats : Stats {
+        CertificateStats() { type = RTCStatsReport::Type::Certificate; }
+
+        String fingerprint;
+        String fingerprintAlgorithm;
+        String base64Certificate;
+        String issuerCertificateId;
+    };
+
 private:
     RTCStatsReport() = default;
 
index 144fbfb..7460426 100644 (file)
@@ -133,11 +133,49 @@ dictionary RTCDataChannelStats : RTCStats {
     unsigned long long bytesReceived;
 };
 
+enum RTCStatsIceCandidatePairState {
+    "frozen",
+    "waiting",
+    "inprogress",
+    "failed",
+    "succeeded",
+    "cancelled"
+};
+
+[ JSGenerateToJSObject ]
+dictionary RTCIceCandidatePairStats : RTCStats {
+    DOMString transportId;
+    DOMString localCandidateId;
+    DOMString remoteCandidateId;
+    RTCStatsIceCandidatePairState state;
+    unsigned long long priority;
+    boolean nominated;
+    boolean writable;
+    boolean readable;
+    unsigned long long bytesSent;
+    unsigned long long bytesReceived;
+    double totalRoundTripTime;
+    double currentRoundTripTime;
+    double availableOutgoingBitrate;
+    double availableIncomingBitrate;
+    unsigned long long requestsReceived;
+    unsigned long long requestsSent;
+    unsigned long long responsesReceived;
+    unsigned long long responsesSent;
+    // FIXME: Expose other fields once libwebrtc support them.
+};
+
+[ JSGenerateToJSObject ]
+dictionary RTCCertificateStats : RTCStats {
+    DOMString fingerprint;
+    DOMString fingerprintAlgorithm;
+    DOMString base64Certificate;
+    DOMString issuerCertificateId;
+};
+
 // FIXME 169662: missing RTCCodecStats
 // FIXME 169662: missing RTCPeerConnectionStats
 // FIXME 169662: missing RTCMediaStreamStats
 // FIXME 169662: missing RTCTransportStats
 // FIXME 169662: missing RTCIceCandidateStats
-// FIXME 169662: missing RTCIceCandidatePairStats
 // FIXME 169662: missing RTCStatsIceCandidatePairState
-// FIXME 169662: missing RTCCertificateStats
index d2923d3..e437fe1 100644 (file)
@@ -386,6 +386,96 @@ static inline void fillRTCDataChannelStats(RTCStatsReport::DataChannelStats& sta
         stats.bytesReceived = *rtcStats.bytes_received;
 }
 
+static inline RTCStatsReport::IceCandidatePairState iceCandidatePairState(const std::string& state)
+{
+    if (state == "frozen")
+        return RTCStatsReport::IceCandidatePairState::Frozen;
+    if (state == "waiting")
+        return RTCStatsReport::IceCandidatePairState::Waiting;
+    if (state == "in-progress")
+        return RTCStatsReport::IceCandidatePairState::Inprogress;
+    if (state == "failed")
+        return RTCStatsReport::IceCandidatePairState::Failed;
+    if (state == "succeeded")
+        return RTCStatsReport::IceCandidatePairState::Succeeded;
+    if (state == "cancelled")
+        return RTCStatsReport::IceCandidatePairState::Cancelled;
+    ASSERT_NOT_REACHED();
+    return RTCStatsReport::IceCandidatePairState::Frozen;
+}
+
+static inline void fillRTCIceCandidatePairStats(RTCStatsReport::IceCandidatePairStats& stats, const webrtc::RTCIceCandidatePairStats& rtcStats)
+{
+    fillRTCStats(stats, rtcStats);
+
+    if (rtcStats.transport_id.is_defined())
+        stats.transportId = fromStdString(*rtcStats.transport_id);
+    if (rtcStats.local_candidate_id.is_defined())
+        stats.localCandidateId = fromStdString(*rtcStats.local_candidate_id);
+    if (rtcStats.remote_candidate_id.is_defined())
+        stats.remoteCandidateId = fromStdString(*rtcStats.remote_candidate_id);
+    if (rtcStats.state.is_defined())
+        stats.state = iceCandidatePairState(*rtcStats.state);
+
+    if (rtcStats.priority.is_defined())
+        stats.priority = *rtcStats.priority;
+    if (rtcStats.nominated.is_defined())
+        stats.nominated = *rtcStats.nominated;
+    if (rtcStats.writable.is_defined())
+        stats.writable = *rtcStats.writable;
+    if (rtcStats.readable.is_defined())
+        stats.readable = *rtcStats.readable;
+
+    if (rtcStats.bytes_sent.is_defined())
+        stats.bytesSent = *rtcStats.bytes_sent;
+    if (rtcStats.bytes_received.is_defined())
+        stats.bytesReceived = *rtcStats.bytes_received;
+    if (rtcStats.total_round_trip_time.is_defined())
+        stats.totalRoundTripTime = *rtcStats.total_round_trip_time;
+    if (rtcStats.current_round_trip_time.is_defined())
+        stats.currentRoundTripTime = *rtcStats.current_round_trip_time;
+    if (rtcStats.available_outgoing_bitrate.is_defined())
+        stats.availableOutgoingBitrate = *rtcStats.available_outgoing_bitrate;
+    if (rtcStats.available_incoming_bitrate.is_defined())
+        stats.availableIncomingBitrate = *rtcStats.available_incoming_bitrate;
+
+    if (rtcStats.requests_received.is_defined())
+        stats.requestsReceived = *rtcStats.requests_received;
+    if (rtcStats.requests_sent.is_defined())
+        stats.requestsSent = *rtcStats.requests_sent;
+    if (rtcStats.responses_received.is_defined())
+        stats.responsesReceived = *rtcStats.responses_received;
+    if (rtcStats.responses_sent.is_defined())
+        stats.responsesSent = *rtcStats.responses_sent;
+
+    if (rtcStats.requests_received.is_defined())
+        stats.retransmissionsReceived = *rtcStats.requests_received;
+    if (rtcStats.requests_sent.is_defined())
+        stats.retransmissionsSent = *rtcStats.requests_sent;
+    if (rtcStats.responses_received.is_defined())
+        stats.consentRequestsReceived = *rtcStats.responses_received;
+    if (rtcStats.responses_sent.is_defined())
+        stats.consentRequestsSent = *rtcStats.responses_sent;
+    if (rtcStats.responses_received.is_defined())
+        stats.consentResponsesReceived = *rtcStats.responses_received;
+    if (rtcStats.responses_sent.is_defined())
+        stats.consentResponsesSent = *rtcStats.responses_sent;
+}
+
+static inline void fillRTCCertificateStats(RTCStatsReport::CertificateStats& stats, const webrtc::RTCCertificateStats& rtcStats)
+{
+    fillRTCStats(stats, rtcStats);
+
+    if (rtcStats.fingerprint.is_defined())
+        stats.fingerprint = fromStdString(*rtcStats.fingerprint);
+    if (rtcStats.fingerprint_algorithm.is_defined())
+        stats.fingerprintAlgorithm = fromStdString(*rtcStats.fingerprint_algorithm);
+    if (rtcStats.base64_certificate.is_defined())
+        stats.base64Certificate = fromStdString(*rtcStats.base64_certificate);
+    if (rtcStats.issuer_certificate_id.is_defined())
+        stats.issuerCertificateId = fromStdString(*rtcStats.issuer_certificate_id);
+}
+
 void LibWebRTCMediaEndpoint::StatsCollector::OnStatsDelivered(const rtc::scoped_refptr<const webrtc::RTCStatsReport>& rtcReport)
 {
     callOnMainThread([protectedThis = rtc::scoped_refptr<LibWebRTCMediaEndpoint::StatsCollector>(this), rtcReport] {
@@ -413,6 +503,14 @@ void LibWebRTCMediaEndpoint::StatsCollector::OnStatsDelivered(const rtc::scoped_
                 RTCStatsReport::DataChannelStats stats;
                 fillRTCDataChannelStats(stats, static_cast<const webrtc::RTCDataChannelStats&>(rtcStats));
                 report->addStats<IDLDictionary<RTCStatsReport::DataChannelStats>>(WTFMove(stats));
+            } else if (rtcStats.type() == webrtc::RTCIceCandidatePairStats::kType) {
+                RTCStatsReport::IceCandidatePairStats stats;
+                fillRTCIceCandidatePairStats(stats, static_cast<const webrtc::RTCIceCandidatePairStats&>(rtcStats));
+                report->addStats<IDLDictionary<RTCStatsReport::IceCandidatePairStats>>(WTFMove(stats));
+            } else if (rtcStats.type() == webrtc::RTCCertificateStats::kType) {
+                RTCStatsReport::CertificateStats stats;
+                fillRTCCertificateStats(stats, static_cast<const webrtc::RTCCertificateStats&>(rtcStats));
+                report->addStats<IDLDictionary<RTCStatsReport::CertificateStats>>(WTFMove(stats));
             }
         }
     });