Add data passing to the GetStats interface of RTCPeerConnection
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Oct 2012 08:01:25 +0000 (08:01 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Oct 2012 08:01:25 +0000 (08:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=98003

Patch by Harald Alvestrand <hta@google.com> on 2012-10-03
Reviewed by Adam Barth.

Source/Platform:

* Platform.gypi:
* chromium/public/WebRTCStatsRequest.h:
(WebKit):
(WebRTCStatsRequest):
* chromium/public/WebRTCStatsResponse.h: Added.
(WebCore):
(WebKit):
(WebRTCStatsResponse):
(WebKit::WebRTCStatsResponse::WebRTCStatsResponse):
(WebKit::WebRTCStatsResponse::~WebRTCStatsResponse):
(WebKit::WebRTCStatsResponse::operator=):

Source/WebCore:

Added an RTCStatsResponseBase interface to platform, and let the
RTCStatsRequestImpl class produce an implementation of it that's returned
to WebCore.

Tested by extension of the RTCPeerConnection-stats.html test.

* Modules/mediastream/RTCStatsElement.cpp:
(WebCore::RTCStatsElement::addStatistic):
(WebCore):
* Modules/mediastream/RTCStatsElement.h:
(RTCStatsElement):
* Modules/mediastream/RTCStatsReport.cpp:
(WebCore):
(WebCore::RTCStatsReport::addElement):
(WebCore::RTCStatsReport::addStatistic):
* Modules/mediastream/RTCStatsReport.h:
(RTCStatsReport):
* Modules/mediastream/RTCStatsRequestImpl.cpp:
(WebCore::RTCStatsRequestImpl::createResponse):
(WebCore):
(WebCore::RTCStatsRequestImpl::requestSucceeded):
* Modules/mediastream/RTCStatsRequestImpl.h:
(RTCStatsRequestImpl):
* Modules/mediastream/RTCStatsResponse.cpp:
(WebCore::RTCStatsResponse::create):
(WebCore::RTCStatsResponse::addReport):
(WebCore):
(WebCore::RTCStatsResponse::addElement):
(WebCore::RTCStatsResponse::addStatistic):
* Modules/mediastream/RTCStatsResponse.h:
(RTCStatsResponse):
* WebCore.gypi:
* platform/chromium/support/WebRTCStatsRequest.cpp:
(WebKit::WebRTCStatsRequest::response):
(WebKit):
(WebKit::WebRTCStatsRequest::requestSucceeded):
* platform/chromium/support/WebRTCStatsResponse.cpp: Added.
(WebKit):
(WebKit::WebRTCStatsResponse::WebRTCStatsResponse):
(WebKit::WebRTCStatsResponse::assign):
(WebKit::WebRTCStatsResponse::reset):
(WebKit::WebRTCStatsResponse::operator WTF::PassRefPtr<WebCore::RTCStatsResponseBase>):
(WebKit::WebRTCStatsResponse::addReport):
(WebKit::WebRTCStatsResponse::addElement):
(WebKit::WebRTCStatsResponse::addStatistic):
* platform/mediastream/RTCStatsRequest.h:
(WebCore):
(RTCStatsRequest):
* platform/mediastream/RTCStatsResponseBase.h: Added.
(WebCore):
(RTCStatsResponseBase):
(WebCore::RTCStatsResponseBase::~RTCStatsResponseBase):

Tools:

* DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp:
(RTCStatsRequestSucceededTask::RTCStatsRequestSucceededTask):
(MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler):
(MockWebRTCPeerConnectionHandler::addStream):
(MockWebRTCPeerConnectionHandler::removeStream):
(MockWebRTCPeerConnectionHandler::getStats):
* DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.h:
(MockWebRTCPeerConnectionHandler):

LayoutTests:

* fast/mediastream/RTCPeerConnection-stats-expected.txt:
* fast/mediastream/RTCPeerConnection-stats.html:

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

24 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/RTCPeerConnection-stats-expected.txt
LayoutTests/fast/mediastream/RTCPeerConnection-stats.html
Source/Platform/ChangeLog
Source/Platform/Platform.gypi
Source/Platform/chromium/public/WebRTCStatsRequest.h
Source/Platform/chromium/public/WebRTCStatsResponse.h [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCStatsElement.cpp
Source/WebCore/Modules/mediastream/RTCStatsElement.h
Source/WebCore/Modules/mediastream/RTCStatsReport.cpp
Source/WebCore/Modules/mediastream/RTCStatsReport.h
Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.cpp
Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.h
Source/WebCore/Modules/mediastream/RTCStatsResponse.cpp
Source/WebCore/Modules/mediastream/RTCStatsResponse.h
Source/WebCore/WebCore.gypi
Source/WebCore/platform/chromium/support/WebRTCStatsRequest.cpp
Source/WebCore/platform/chromium/support/WebRTCStatsResponse.cpp [new file with mode: 0644]
Source/WebCore/platform/mediastream/RTCStatsRequest.h
Source/WebCore/platform/mediastream/RTCStatsResponseBase.h [new file with mode: 0644]
Tools/ChangeLog
Tools/DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp
Tools/DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.h

index c257211..d6f5ef4 100644 (file)
@@ -1,3 +1,13 @@
+2012-10-03  Harald Alvestrand  <hta@google.com>
+
+        Add data passing to the GetStats interface of RTCPeerConnection
+        https://bugs.webkit.org/show_bug.cgi?id=98003
+
+        Reviewed by Adam Barth.
+
+        * fast/mediastream/RTCPeerConnection-stats-expected.txt:
+        * fast/mediastream/RTCPeerConnection-stats.html:
+
 2012-10-02  Arko Saha  <arko@motorola.com>
 
         Microdata: itemprop names must not override builtin properties.
index ffe336e..99cd8f9 100644 (file)
@@ -4,10 +4,17 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 
 
 PASS pc = new webkitRTCPeerConnection(null) did not throw exception.
-PASS pc.getStats(statsHandler) did not throw exception.
-PASS statsHandler was called
+PASS pc.getStats(statsHandler1) did not throw exception.
+PASS statsHandler1 was called
 PASS status is non-null.
 PASS result.length is 0
+PASS getUserMedia({audio:true, video:true}, gotStream) did not throw exception.
+PASS Got a stream.
+PASS pc.getStats(statsHandler2) did not throw exception.
+PASS statsHandler2 was called
+PASS result.length is >= 2
+PASS local.length is 1
+PASS local[0].stat("type") is "audio"
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 9675ca3..5985b7a 100644 (file)
@@ -8,18 +8,53 @@
 description("Tests the RTCPeerConnection stats interface.");
 
 var pc = null;
+var result;
+var local;
 
-function statsHandler(status)
+function getUserMedia(dictionary, callback) {
+    try {
+        navigator.webkitGetUserMedia(dictionary, callback, error);
+    } catch (e) {
+        testFailed('webkitGetUserMedia threw exception :' + e);
+        finishJSTest();
+    }
+}
+
+function error() {
+    testFailed('Stream generation failed.');
+    finishJSTest();
+}
+
+function statsHandler1(status)
 {
-    testPassed("statsHandler was called");
+    testPassed("statsHandler1 was called");
     shouldBeNonNull('status');
     result = status.result();
     shouldBe('result.length', '0');
+    shouldNotThrow('getUserMedia({audio:true, video:true}, gotStream)');
+}
+
+function gotStream(s) {
+    testPassed('Got a stream.');
+    stream = s;
+
+    pc.addStream(stream);
+    shouldNotThrow('pc.getStats(statsHandler2)');
+}
+
+function statsHandler2(status)
+{
+    testPassed("statsHandler2 was called");
+    result = status.result();
+    shouldBeGreaterThanOrEqual('result.length', '2');
+    local = result[0].local();
+    shouldBe('local.length', '1');
+    shouldBe('local[0].stat("type")', '"audio"');
     finishJSTest();
 }
 
 shouldNotThrow('pc = new webkitRTCPeerConnection(null)');
-shouldNotThrow('pc.getStats(statsHandler)');
+shouldNotThrow('pc.getStats(statsHandler1)');
 
 window.jsTestIsAsync = true;
 window.successfullyParsed = true;
index a06e6c6..8ad8619 100644 (file)
@@ -1,3 +1,22 @@
+2012-10-03  Harald Alvestrand  <hta@google.com>
+
+        Add data passing to the GetStats interface of RTCPeerConnection
+        https://bugs.webkit.org/show_bug.cgi?id=98003
+
+        Reviewed by Adam Barth.
+
+        * Platform.gypi:
+        * chromium/public/WebRTCStatsRequest.h:
+        (WebKit):
+        (WebRTCStatsRequest):
+        * chromium/public/WebRTCStatsResponse.h: Added.
+        (WebCore):
+        (WebKit):
+        (WebRTCStatsResponse):
+        (WebKit::WebRTCStatsResponse::WebRTCStatsResponse):
+        (WebKit::WebRTCStatsResponse::~WebRTCStatsResponse):
+        (WebKit::WebRTCStatsResponse::operator=):
+
 2012-10-02  Terry Anderson  <tdanderson@chromium.org>
 
         [chromium] Add field to WebRenderingStats to track if we have impl-thread scrolled
index a6c2457..69de937 100644 (file)
             'chromium/public/WebRTCPeerConnectionHandlerClient.h',
             'chromium/public/WebRTCSessionDescription.h',
             'chromium/public/WebRTCSessionDescriptionRequest.h',
+            'chromium/public/WebRTCStatsRequest.h',
+            'chromium/public/WebRTCStatsResponse.h',
             'chromium/public/WebRTCVoidRequest.h',
             'chromium/public/WebRect.h',
             'chromium/public/WebReferrerPolicy.h',
index 4d68c11..e67bd1f 100644 (file)
@@ -41,6 +41,29 @@ class RTCStatsRequest;
 
 namespace WebKit {
 
+class WebRTCStatsResponse;
+
+// The WebRTCStatsRequest class represents a JavaScript call on
+// RTCPeerConnection.getStats(). The user of this API will use
+// the calls on this class and WebRTCStatsResponse to fill in the
+// data that will be returned via a callback to the user in an
+// RTCStatsResponse structure.
+//
+// The typical usage pattern is:
+// WebRTCStatsRequest request = <from somewhere>
+// WebRTCStatsResponse response = request.createResponse();
+//
+// For each item on which statistics are going to be reported:
+//   size_t reportIndex = response.addReport();
+//   Add local information:
+//   size_t elementIndex = response.addElement(reportIndex, true, dateNow());
+//   For each statistic being reported on:
+//     response.addStatistic(reportIndex, true, elementIndex,
+//                           "name of statistic", "statistic value"); 
+//   Remote information (typically RTCP-derived) is added in the same way.
+// When finished adding information:
+// request.requestSucceeded(response);
+
 class WebRTCStatsRequest {
 public:
     WebRTCStatsRequest() { }
@@ -57,7 +80,9 @@ public:
 
     WEBKIT_EXPORT void reset();
 
-    WEBKIT_EXPORT void requestSucceeded() const;
+    WEBKIT_EXPORT void requestSucceeded(const WebRTCStatsResponse&) const;
+
+    WEBKIT_EXPORT WebRTCStatsResponse createResponse() const;
 
 #if WEBKIT_IMPLEMENTATION
     WebRTCStatsRequest(const WTF::PassRefPtr<WebCore::RTCStatsRequest>&);
diff --git a/Source/Platform/chromium/public/WebRTCStatsResponse.h b/Source/Platform/chromium/public/WebRTCStatsResponse.h
new file mode 100644 (file)
index 0000000..da25e1c
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebRTCStatsResponse_h
+#define WebRTCStatsResponse_h
+
+#include "WebCommon.h"
+#include "WebPrivatePtr.h"
+#include "WebString.h"
+
+namespace WebCore {
+class RTCStatsResponseBase;
+}
+
+namespace WebKit {
+
+class WebRTCStatsResponse {
+public:
+    WebRTCStatsResponse() { }
+    WebRTCStatsResponse(const WebRTCStatsResponse& other) { assign(other); }
+    ~WebRTCStatsResponse() { reset(); }
+
+    WebRTCStatsResponse& operator=(const WebRTCStatsResponse& other)
+    {
+        assign(other);
+        return *this;
+    }
+
+    WEBKIT_EXPORT void assign(const WebRTCStatsResponse&);
+
+    WEBKIT_EXPORT void reset();
+
+    WEBKIT_EXPORT size_t addReport();
+    WEBKIT_EXPORT size_t addElement(size_t report, bool isLocal, long timestamp);
+    WEBKIT_EXPORT void addStatistic(size_t report, bool isLocal, size_t element, WebString name, WebString value);
+
+#if WEBKIT_IMPLEMENTATION
+    WebRTCStatsResponse(const WTF::PassRefPtr<WebCore::RTCStatsResponseBase>&);
+
+    operator WTF::PassRefPtr<WebCore::RTCStatsResponseBase>() const;
+#endif
+
+private:
+    WebPrivatePtr<WebCore::RTCStatsResponseBase> m_private;
+};
+
+} // namespace WebKit
+
+#endif // WebRTCStatsResponse_h
index a25ceb4..1e3ce54 100644 (file)
@@ -1,3 +1,63 @@
+2012-10-03  Harald Alvestrand  <hta@google.com>
+
+        Add data passing to the GetStats interface of RTCPeerConnection
+        https://bugs.webkit.org/show_bug.cgi?id=98003
+
+        Reviewed by Adam Barth.
+
+        Added an RTCStatsResponseBase interface to platform, and let the
+        RTCStatsRequestImpl class produce an implementation of it that's returned
+        to WebCore.
+
+        Tested by extension of the RTCPeerConnection-stats.html test.
+
+        * Modules/mediastream/RTCStatsElement.cpp:
+        (WebCore::RTCStatsElement::addStatistic):
+        (WebCore):
+        * Modules/mediastream/RTCStatsElement.h:
+        (RTCStatsElement):
+        * Modules/mediastream/RTCStatsReport.cpp:
+        (WebCore):
+        (WebCore::RTCStatsReport::addElement):
+        (WebCore::RTCStatsReport::addStatistic):
+        * Modules/mediastream/RTCStatsReport.h:
+        (RTCStatsReport):
+        * Modules/mediastream/RTCStatsRequestImpl.cpp:
+        (WebCore::RTCStatsRequestImpl::createResponse):
+        (WebCore):
+        (WebCore::RTCStatsRequestImpl::requestSucceeded):
+        * Modules/mediastream/RTCStatsRequestImpl.h:
+        (RTCStatsRequestImpl):
+        * Modules/mediastream/RTCStatsResponse.cpp:
+        (WebCore::RTCStatsResponse::create):
+        (WebCore::RTCStatsResponse::addReport):
+        (WebCore):
+        (WebCore::RTCStatsResponse::addElement):
+        (WebCore::RTCStatsResponse::addStatistic):
+        * Modules/mediastream/RTCStatsResponse.h:
+        (RTCStatsResponse):
+        * WebCore.gypi:
+        * platform/chromium/support/WebRTCStatsRequest.cpp:
+        (WebKit::WebRTCStatsRequest::response):
+        (WebKit):
+        (WebKit::WebRTCStatsRequest::requestSucceeded):
+        * platform/chromium/support/WebRTCStatsResponse.cpp: Added.
+        (WebKit):
+        (WebKit::WebRTCStatsResponse::WebRTCStatsResponse):
+        (WebKit::WebRTCStatsResponse::assign):
+        (WebKit::WebRTCStatsResponse::reset):
+        (WebKit::WebRTCStatsResponse::operator WTF::PassRefPtr<WebCore::RTCStatsResponseBase>):
+        (WebKit::WebRTCStatsResponse::addReport):
+        (WebKit::WebRTCStatsResponse::addElement):
+        (WebKit::WebRTCStatsResponse::addStatistic):
+        * platform/mediastream/RTCStatsRequest.h:
+        (WebCore):
+        (RTCStatsRequest):
+        * platform/mediastream/RTCStatsResponseBase.h: Added.
+        (WebCore):
+        (RTCStatsResponseBase):
+        (WebCore::RTCStatsResponseBase::~RTCStatsResponseBase):
+
 2012-10-02  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Add API to get the web view that initiated a custom URI request to WebKit2 GTK+
index e78cc0b..4a3331f 100644 (file)
@@ -47,6 +47,11 @@ String RTCStatsElement::stat(const String& name) const
     return m_stats.get(name);
 }
 
+void RTCStatsElement::addStatistic(const String& name, const String& value)
+{
+    m_stats.add(name, value);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)
index 09ebed2..7f8d1bd 100644 (file)
@@ -37,6 +37,7 @@ public:
     static PassRefPtr<RTCStatsElement> create(long timestamp);
     long timestamp() const { return m_timestamp; }
     String stat(const String& name) const;
+    void addStatistic(const String& name, const String& value);
 
 private:
     explicit RTCStatsElement(long timestamp);
index d982dd7..5e95095 100644 (file)
@@ -39,6 +39,27 @@ RTCStatsReport::RTCStatsReport()
 {
 }
 
+size_t RTCStatsReport::addElement(bool isLocal, long timestamp)
+{
+    if (isLocal) {
+        m_local.append(RTCStatsElement::create(timestamp));
+        return m_local.size() - 1;
+    }
+    m_remote.append(RTCStatsElement::create(timestamp));
+    return m_remote.size() - 1;
+}
+
+void RTCStatsReport::addStatistic(bool isLocal, size_t element, String name, String value)
+{
+    if (isLocal) {
+        ASSERT(element >= 0 && element < m_local.size());
+        m_local[element]->addStatistic(name, value);
+    } else {
+        ASSERT(element >= 0 && element < m_remote.size());
+        m_remote[element]->addStatistic(name, value);
+    }
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)
index cb2cf03..ef7dcac 100644 (file)
@@ -40,6 +40,9 @@ public:
     const Vector<RefPtr<RTCStatsElement> >& local() const { return m_local; }
     const Vector<RefPtr<RTCStatsElement> >& remote() const { return m_remote; }
 
+    size_t addElement(bool isLocal, long timestamp);
+    void addStatistic(bool isLocal, size_t element, String name, String value);
+
 private:
     RTCStatsReport();
 
index afdb97f..01ecead 100644 (file)
@@ -51,13 +51,16 @@ RTCStatsRequestImpl::~RTCStatsRequestImpl()
 {
 }
 
-void RTCStatsRequestImpl::requestSucceeded()
+PassRefPtr<RTCStatsResponseBase> RTCStatsRequestImpl::createResponse()
+{
+    return RTCStatsResponse::create();
+}
+
+void RTCStatsRequestImpl::requestSucceeded(PassRefPtr<RTCStatsResponseBase> response)
 {
     if (!m_successCallback)
         return;
-    // FIXME: Fill in content of stats parameter.
-    RefPtr<RTCStatsResponse> stats = RTCStatsResponse::create();
-    m_successCallback->handleEvent(stats.get());
+    m_successCallback->handleEvent(static_cast<RTCStatsResponse*>(response.get()));
     clear();
 }
 
index 47663a7..bda155e 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "ActiveDOMObject.h"
 #include "RTCStatsRequest.h"
+#include "RTCStatsResponse.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
@@ -42,7 +43,8 @@ public:
     static PassRefPtr<RTCStatsRequestImpl> create(ScriptExecutionContext*, PassRefPtr<RTCStatsCallback>);
     virtual ~RTCStatsRequestImpl();
 
-    virtual void requestSucceeded();
+    virtual PassRefPtr<RTCStatsResponseBase> createResponse();
+    virtual void requestSucceeded(PassRefPtr<RTCStatsResponseBase>);
 
     // ActiveDOMObject
     virtual void stop() OVERRIDE;
index ff78f11..2acafa3 100644 (file)
@@ -33,13 +33,30 @@ namespace WebCore {
 PassRefPtr<RTCStatsResponse> RTCStatsResponse::create()
 {
     return adoptRef(new RTCStatsResponse());
-    // FIXME: Pass an RTCStatsRequest argument and populate from it.
 }
 
 RTCStatsResponse::RTCStatsResponse()
 {
 }
 
+size_t RTCStatsResponse::addReport()
+{
+    m_result.append(RTCStatsReport::create());
+    return m_result.size() - 1;
+}
+
+size_t RTCStatsResponse::addElement(size_t report, bool isLocal, long timestamp)
+{
+    ASSERT(report >= 0 && report < m_result.size());
+    return m_result[report]->addElement(isLocal, timestamp);
+}
+
+void RTCStatsResponse::addStatistic(size_t report, bool isLocal, size_t element, String name, String value)
+{
+    ASSERT(report >= 0 && report < m_result.size());
+    return m_result[report]->addStatistic(isLocal, element, name, value);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)
index c2ecc90..3fa8047 100644 (file)
 #include "EventTarget.h"
 #include "MediaStreamTrack.h"
 #include "RTCStatsReport.h"
+#include "RTCStatsResponseBase.h"
 
 namespace WebCore {
 
-class RTCStatsResponse : public RefCounted<RTCStatsResponse> {
+class RTCStatsResponse : public RTCStatsResponseBase {
 public:
     static PassRefPtr<RTCStatsResponse> create();
 
     const Vector<RefPtr<RTCStatsReport> >& result() const { return m_result; };
 
+    virtual size_t addReport() OVERRIDE;
+    virtual size_t addElement(size_t report, bool isLocal, long timestamp) OVERRIDE;
+    virtual void addStatistic(size_t report, bool isLocal, size_t element, String name, String value) OVERRIDE;
+
 private:
     RTCStatsResponse();
     Vector<RefPtr<RTCStatsReport> > m_result;
index a127162..55f3d54 100644 (file)
             'platform/chromium/support/WebRTCSessionDescription.cpp',
             'platform/chromium/support/WebRTCSessionDescriptionRequest.cpp',
             'platform/chromium/support/WebRTCStatsRequest.cpp',
+            'platform/chromium/support/WebRTCStatsResponse.cpp',
             'platform/chromium/support/WebRTCVoidRequest.cpp',
             'platform/chromium/support/WebScrollbarThemeGeometryNative.cpp',
             'platform/chromium/support/WebScrollbarThemeGeometryNative.h',
index df65ae6..3ac4c2f 100644 (file)
 #if ENABLE(MEDIA_STREAM)
 
 #include <public/WebRTCStatsRequest.h>
+#include <public/WebRTCStatsResponse.h>
 
 #include "RTCStatsRequest.h"
+#include "RTCStatsResponse.h"
 #include <wtf/PassOwnPtr.h>
 
 using namespace WebCore;
@@ -56,9 +58,14 @@ void WebRTCStatsRequest::reset()
     m_private.reset();
 }
 
-void WebRTCStatsRequest::requestSucceeded() const
+WebRTCStatsResponse WebRTCStatsRequest::createResponse() const
 {
-    m_private->requestSucceeded();
+    return WebRTCStatsResponse(m_private->createResponse());
+}
+
+void WebRTCStatsRequest::requestSucceeded(const WebRTCStatsResponse& response) const
+{
+    m_private->requestSucceeded(response);
 }
 
 } // namespace WebKit
diff --git a/Source/WebCore/platform/chromium/support/WebRTCStatsResponse.cpp b/Source/WebCore/platform/chromium/support/WebRTCStatsResponse.cpp
new file mode 100644 (file)
index 0000000..09d7e10
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(MEDIA_STREAM)
+
+#include <public/WebRTCStatsResponse.h>
+
+#include "RTCStatsResponseBase.h"
+#include <wtf/PassOwnPtr.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebRTCStatsResponse::WebRTCStatsResponse(const PassRefPtr<RTCStatsResponseBase>& request)
+    : m_private(request)
+{
+}
+
+void WebRTCStatsResponse::assign(const WebRTCStatsResponse& other)
+{
+    m_private = other.m_private;
+}
+
+void WebRTCStatsResponse::reset()
+{
+    m_private.reset();
+}
+
+WebRTCStatsResponse::operator WTF::PassRefPtr<WebCore::RTCStatsResponseBase>() const
+{
+    return m_private.get();
+}
+
+size_t WebRTCStatsResponse::addReport()
+{
+    return m_private->addReport();
+}
+
+size_t WebRTCStatsResponse::addElement(size_t report, bool isLocal, long timestamp)
+{
+    return m_private->addElement(report, isLocal, timestamp);
+}
+
+void WebRTCStatsResponse::addStatistic(size_t report, bool isLocal, size_t element, WebString name, WebString value)
+{
+    m_private->addStatistic(report, isLocal, element, name, value);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(MEDIA_STREAM)
+
index 6ece764..22c19b8 100644 (file)
 
 namespace WebCore {
 
+class RTCStatsResponseBase;
+
 class RTCStatsRequest : public RefCounted<RTCStatsRequest> {
 public:
     virtual ~RTCStatsRequest() { }
 
-    virtual void requestSucceeded() = 0;
+    virtual PassRefPtr<RTCStatsResponseBase> createResponse() = 0;
+    virtual void requestSucceeded(PassRefPtr<RTCStatsResponseBase>) = 0;
 
 protected:
     RTCStatsRequest() { }
diff --git a/Source/WebCore/platform/mediastream/RTCStatsResponseBase.h b/Source/WebCore/platform/mediastream/RTCStatsResponseBase.h
new file mode 100644 (file)
index 0000000..5547c5c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RTCStatsResponseBase_h
+#define RTCStatsResponseBase_h
+
+#if ENABLE(MEDIA_STREAM)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class RTCStatsResponseBase : public RefCounted<RTCStatsResponseBase> {
+public:
+    virtual ~RTCStatsResponseBase() { }
+
+    virtual size_t addReport() = 0;
+    virtual size_t addElement(size_t report, bool isLocal, long timestamp) = 0;
+    virtual void addStatistic(size_t report, bool isLocal, size_t element, String name, String value) = 0;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
+
+#endif // RTCStatsResponseBase_h
index bc4d6f0..76ec230 100644 (file)
@@ -1 +1,17 @@
+2012-10-03  Harald Alvestrand  <hta@google.com>
+
+        Add data passing to the GetStats interface of RTCPeerConnection
+        https://bugs.webkit.org/show_bug.cgi?id=98003
+
+        Reviewed by Adam Barth.
+
+        * DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp:
+        (RTCStatsRequestSucceededTask::RTCStatsRequestSucceededTask):
+        (MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler):
+        (MockWebRTCPeerConnectionHandler::addStream):
+        (MockWebRTCPeerConnectionHandler::removeStream):
+        (MockWebRTCPeerConnectionHandler::getStats):
+        * DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.h:
+        (MockWebRTCPeerConnectionHandler):
+
 == Rolled over to ChangeLog-2012-10-02 ==
index a702c8b..3add09a 100644 (file)
@@ -39,6 +39,7 @@
 #include <public/WebRTCSessionDescription.h>
 #include <public/WebRTCSessionDescriptionRequest.h>
 #include <public/WebRTCStatsRequest.h>
+#include <public/WebRTCStatsResponse.h>
 #include <public/WebRTCVoidRequest.h>
 #include <public/WebString.h>
 #include <public/WebVector.h>
@@ -83,19 +84,21 @@ private:
 
 class RTCStatsRequestSucceededTask : public MethodTask<MockWebRTCPeerConnectionHandler> {
 public:
-    RTCStatsRequestSucceededTask(MockWebRTCPeerConnectionHandler* object, const WebKit::WebRTCStatsRequest& request)
+    RTCStatsRequestSucceededTask(MockWebRTCPeerConnectionHandler* object, const WebKit::WebRTCStatsRequest& request, const WebKit::WebRTCStatsResponse& response)
         : MethodTask<MockWebRTCPeerConnectionHandler>(object)
         , m_request(request)
+        , m_response(response)
     {
     }
 
     virtual void runIfValid() OVERRIDE
     {
-        m_request.requestSucceeded();
+        m_request.requestSucceeded(m_response);
     }
 
 private:
     WebKit::WebRTCStatsRequest m_request;
+    WebKit::WebRTCStatsResponse m_response;
 };
 
 class RTCVoidRequestTask : public MethodTask<MockWebRTCPeerConnectionHandler> {
@@ -124,6 +127,7 @@ private:
 
 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler(WebRTCPeerConnectionHandlerClient* client)
     : m_client(client)
+    , m_streamCount(0)
 {
 }
 
@@ -195,6 +199,7 @@ bool MockWebRTCPeerConnectionHandler::addICECandidate(const WebRTCICECandidate&
 
 bool MockWebRTCPeerConnectionHandler::addStream(const WebMediaStreamDescriptor& stream, const WebMediaConstraints&)
 {
+    m_streamCount += 1;
     m_client->didAddRemoteStream(stream);
     m_client->negotiationNeeded();
     return true;
@@ -202,16 +207,25 @@ bool MockWebRTCPeerConnectionHandler::addStream(const WebMediaStreamDescriptor&
 
 void MockWebRTCPeerConnectionHandler::removeStream(const WebMediaStreamDescriptor& stream)
 {
+    m_streamCount -= 1;
     m_client->didRemoveRemoteStream(stream);
     m_client->negotiationNeeded();
 }
 
 void MockWebRTCPeerConnectionHandler::getStats(const WebRTCStatsRequest& request)
 {
-    postTask(new RTCStatsRequestSucceededTask(this, request));
+    WebRTCStatsResponse response = request.createResponse();
+    for (int i = 0; i < m_streamCount; ++i) {
+        size_t reportIndex = response.addReport();
+        size_t elementIndex = response.addElement(reportIndex, true, 12345);
+        response.addStatistic(reportIndex, true, elementIndex, "type", "audio");
+        reportIndex = response.addReport();
+        elementIndex = response.addElement(reportIndex, true, 12345);
+        response.addStatistic(reportIndex, true, elementIndex, "type", "video");
+    }
+    postTask(new RTCStatsRequestSucceededTask(this, request, response));
 }
 
-
 void MockWebRTCPeerConnectionHandler::stop()
 {
 }
index 8aa336e..43d087e 100644 (file)
@@ -72,6 +72,7 @@ private:
     TaskList m_taskList;
     WebKit::WebRTCSessionDescription m_localDescription;
     WebKit::WebRTCSessionDescription m_remoteDescription;
+    int m_streamCount;
 };
 
 #endif // ENABLE(MEDIA_STREAM)