Title: [131584] trunk
Revision
131584
Author
[email protected]
Date
2012-10-17 04:15:07 -0700 (Wed, 17 Oct 2012)

Log Message

Implement the Selector argument to RTCPeerConnection.getStats
https://bugs.webkit.org/show_bug.cgi?id=99460

Patch by Harald Alvestrand <[email protected]> on 2012-10-17
Reviewed by Adam Barth.

Source/Platform:

* chromium/public/WebRTCStatsRequest.h:
(WebKit):
(WebRTCStatsRequest):

Source/WebCore:

The change adds two new parameters to the RTCStatsRequest object:
stream and component. Together these are enough to identify a
MediaStreamTrack.

Test: fast/mediastream/RTCPeerConnection-statsSelector.html

* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::streamDescriptor):
(WebCore):
* Modules/mediastream/MediaStreamTrack.h:
* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::getStats):
* Modules/mediastream/RTCStatsRequestImpl.cpp:
(WebCore::RTCStatsRequestImpl::create):
(WebCore::RTCStatsRequestImpl::RTCStatsRequestImpl):
(WebCore::RTCStatsRequestImpl::hasSelector):
(WebCore):
(WebCore::RTCStatsRequestImpl::stream):
(WebCore::RTCStatsRequestImpl::component):
* Modules/mediastream/RTCStatsRequestImpl.h:
(RTCStatsRequestImpl):
* platform/chromium/support/WebRTCStatsRequest.cpp:
(WebKit):
(WebKit::WebRTCStatsRequest::hasSelector):
(WebKit::WebRTCStatsRequest::stream):
(WebKit::WebRTCStatsRequest::component):
* platform/mediastream/RTCStatsRequest.h:
(WebCore):
(RTCStatsRequest):

Tools:

The MockWebRTCPeerConnectionHandler will return one object only
when it gets a selector, and an even number when there is no selector.
This allows to verify that the argument is passed, but not its value.

* DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp:
(MockWebRTCPeerConnectionHandler::getStats):

LayoutTests:

* fast/mediastream/RTCPeerConnection-statsSelector-expected.txt: Added.
* fast/mediastream/RTCPeerConnection-statsSelector.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (131583 => 131584)


--- trunk/LayoutTests/ChangeLog	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/LayoutTests/ChangeLog	2012-10-17 11:15:07 UTC (rev 131584)
@@ -1,3 +1,13 @@
+2012-10-17  Harald Alvestrand  <[email protected]>
+
+        Implement the Selector argument to RTCPeerConnection.getStats
+        https://bugs.webkit.org/show_bug.cgi?id=99460
+
+        Reviewed by Adam Barth.
+
+        * fast/mediastream/RTCPeerConnection-statsSelector-expected.txt: Added.
+        * fast/mediastream/RTCPeerConnection-statsSelector.html: Added.
+
 2012-10-17  Mikhail Pozdnyakov  <[email protected]>
 
         WebKitTestRunner needs layoutTestController.queueReload

Added: trunk/LayoutTests/fast/mediastream/RTCPeerConnection-statsSelector-expected.txt (0 => 131584)


--- trunk/LayoutTests/fast/mediastream/RTCPeerConnection-statsSelector-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/RTCPeerConnection-statsSelector-expected.txt	2012-10-17 11:15:07 UTC (rev 131584)
@@ -0,0 +1,17 @@
+Tests the RTCPeerConnection stats selector argument.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS pc = new webkitRTCPeerConnection(null) did not throw exception.
+PASS getUserMedia({audio:true, video:true}, gotStream) did not throw exception.
+PASS Got a stream.
+PASS pc.getStats(statsHandler2, pc.localStreams[0].videoTracks[0]) did not throw exception.
+PASS statsHandler2 was called
+PASS result.length is >= 1
+PASS timestamp is >= startTime
+PASS local.stat("type") is "video"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/mediastream/RTCPeerConnection-statsSelector.html (0 => 131584)


--- trunk/LayoutTests/fast/mediastream/RTCPeerConnection-statsSelector.html	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/RTCPeerConnection-statsSelector.html	2012-10-17 11:15:07 UTC (rev 131584)
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description("Tests the RTCPeerConnection stats selector argument.");
+
+var pc = null;
+var result;
+var timestamp;
+var local;
+
+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 gotStream(s) {
+    testPassed('Got a stream.');
+    stream = s;
+
+    pc.addStream(stream);
+    shouldNotThrow('pc.getStats(statsHandler2, pc.localStreams[0].videoTracks[0])');
+}
+
+function statsHandler2(status)
+{
+    testPassed("statsHandler2 was called");
+    result = status.result();
+    shouldBeGreaterThanOrEqual('result.length', '1');
+    local = result[0].local;
+    timestamp = local.timestamp;
+    shouldBeGreaterThanOrEqual('timestamp', 'startTime');
+    shouldBe('local.stat("type")', '"video"');
+    finishJSTest();
+}
+
+var startTime = new Date().getTime();
+shouldNotThrow('pc = new webkitRTCPeerConnection(null)');
+shouldNotThrow('getUserMedia({audio:true, video:true}, gotStream)');
+
+window.jsTestIsAsync = true;
+window.successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/Platform/ChangeLog (131583 => 131584)


--- trunk/Source/Platform/ChangeLog	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/Platform/ChangeLog	2012-10-17 11:15:07 UTC (rev 131584)
@@ -1,3 +1,14 @@
+2012-10-17  Harald Alvestrand  <[email protected]>
+
+        Implement the Selector argument to RTCPeerConnection.getStats
+        https://bugs.webkit.org/show_bug.cgi?id=99460
+
+        Reviewed by Adam Barth.
+
+        * chromium/public/WebRTCStatsRequest.h:
+        (WebKit):
+        (WebRTCStatsRequest):
+
 2012-10-16  Tommy Widenflycht  <[email protected]>
 
         MediaStream API: Add the chromium API for RTCDataChannel

Modified: trunk/Source/Platform/chromium/public/WebRTCStatsRequest.h (131583 => 131584)


--- trunk/Source/Platform/chromium/public/WebRTCStatsRequest.h	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/Platform/chromium/public/WebRTCStatsRequest.h	2012-10-17 11:15:07 UTC (rev 131584)
@@ -41,6 +41,8 @@
 
 namespace WebKit {
 
+class WebMediaStreamComponent;
+class WebMediaStreamDescriptor;
 class WebRTCStatsResponse;
 
 // The WebRTCStatsRequest class represents a _javascript_ call on
@@ -80,6 +82,16 @@
 
     WEBKIT_EXPORT void reset();
 
+    // This function returns true if a selector argument was given to getStats.
+    WEBKIT_EXPORT bool hasSelector() const;
+
+    // The stream() and component() accessors give the two pieces of information
+    // required to look up a MediaStreamTrack implementation.
+    // It is only useful to call them when hasSelector() returns true.
+    WEBKIT_EXPORT const WebMediaStreamDescriptor stream() const;
+
+    WEBKIT_EXPORT const WebMediaStreamComponent component() const;
+
     WEBKIT_EXPORT void requestSucceeded(const WebRTCStatsResponse&) const;
 
     WEBKIT_EXPORT WebRTCStatsResponse createResponse() const;

Modified: trunk/Source/WebCore/ChangeLog (131583 => 131584)


--- trunk/Source/WebCore/ChangeLog	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/WebCore/ChangeLog	2012-10-17 11:15:07 UTC (rev 131584)
@@ -1,3 +1,40 @@
+2012-10-17  Harald Alvestrand  <[email protected]>
+
+        Implement the Selector argument to RTCPeerConnection.getStats
+        https://bugs.webkit.org/show_bug.cgi?id=99460
+
+        Reviewed by Adam Barth.
+
+        The change adds two new parameters to the RTCStatsRequest object:
+        stream and component. Together these are enough to identify a
+        MediaStreamTrack.
+
+        Test: fast/mediastream/RTCPeerConnection-statsSelector.html
+
+        * Modules/mediastream/MediaStreamTrack.cpp:
+        (WebCore::MediaStreamTrack::streamDescriptor):
+        (WebCore):
+        * Modules/mediastream/MediaStreamTrack.h:
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::RTCPeerConnection::getStats):
+        * Modules/mediastream/RTCStatsRequestImpl.cpp:
+        (WebCore::RTCStatsRequestImpl::create):
+        (WebCore::RTCStatsRequestImpl::RTCStatsRequestImpl):
+        (WebCore::RTCStatsRequestImpl::hasSelector):
+        (WebCore):
+        (WebCore::RTCStatsRequestImpl::stream):
+        (WebCore::RTCStatsRequestImpl::component):
+        * Modules/mediastream/RTCStatsRequestImpl.h:
+        (RTCStatsRequestImpl):
+        * platform/chromium/support/WebRTCStatsRequest.cpp:
+        (WebKit):
+        (WebKit::WebRTCStatsRequest::hasSelector):
+        (WebKit::WebRTCStatsRequest::stream):
+        (WebKit::WebRTCStatsRequest::component):
+        * platform/mediastream/RTCStatsRequest.h:
+        (WebCore):
+        (RTCStatsRequest):
+
 2012-10-17  Simon Hausmann  <[email protected]>
 
         [Qt] Enable use of more AllInOne files

Modified: trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp (131583 => 131584)


--- trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp	2012-10-17 11:15:07 UTC (rev 131584)
@@ -130,6 +130,11 @@
     }
 }
 
+MediaStreamDescriptor* MediaStreamTrack::streamDescriptor()
+{
+    return m_streamDescriptor.get();
+}
+
 MediaStreamComponent* MediaStreamTrack::component()
 {
     return m_component.get();

Modified: trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h (131583 => 131584)


--- trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h	2012-10-17 11:15:07 UTC (rev 131584)
@@ -64,6 +64,7 @@
     DEFINE_ATTRIBUTE_EVENT_LISTENER(unmute);
     DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
 
+    MediaStreamDescriptor* streamDescriptor();
     MediaStreamComponent* component();
 
     // EventTarget

Modified: trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp (131583 => 131584)


--- trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp	2012-10-17 11:15:07 UTC (rev 131584)
@@ -405,7 +405,7 @@
 
 void RTCPeerConnection::getStats(PassRefPtr<RTCStatsCallback> successCallback, PassRefPtr<MediaStreamTrack> selector)
 {
-    RefPtr<RTCStatsRequestImpl> statsRequest = RTCStatsRequestImpl::create(scriptExecutionContext(), successCallback);
+    RefPtr<RTCStatsRequestImpl> statsRequest = RTCStatsRequestImpl::create(scriptExecutionContext(), successCallback, selector);
     // FIXME: Add passing selector as part of the statsRequest.
     m_peerHandler->getStats(statsRequest.release());
 }

Modified: trunk/Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.cpp (131583 => 131584)


--- trunk/Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.cpp	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.cpp	2012-10-17 11:15:07 UTC (rev 131584)
@@ -34,16 +34,18 @@
 
 namespace WebCore {
 
-PassRefPtr<RTCStatsRequestImpl> RTCStatsRequestImpl::create(ScriptExecutionContext* context, PassRefPtr<RTCStatsCallback> callback)
+PassRefPtr<RTCStatsRequestImpl> RTCStatsRequestImpl::create(ScriptExecutionContext* context, PassRefPtr<RTCStatsCallback> callback, PassRefPtr<MediaStreamTrack> selector)
 {
-    RefPtr<RTCStatsRequestImpl> request = adoptRef(new RTCStatsRequestImpl(context, callback));
+    RefPtr<RTCStatsRequestImpl> request = adoptRef(new RTCStatsRequestImpl(context, callback, selector));
     request->suspendIfNeeded();
     return request.release();
 }
 
-RTCStatsRequestImpl::RTCStatsRequestImpl(ScriptExecutionContext* context, PassRefPtr<RTCStatsCallback> callback)
+RTCStatsRequestImpl::RTCStatsRequestImpl(ScriptExecutionContext* context, PassRefPtr<RTCStatsCallback> callback, PassRefPtr<MediaStreamTrack> selector)
     : ActiveDOMObject(context, this)
     , m_successCallback(callback)
+    , m_stream(selector ? selector->streamDescriptor() : 0)
+    , m_component(selector ? selector->component() : 0)
 {
 }
 
@@ -56,6 +58,21 @@
     return RTCStatsResponse::create();
 }
 
+bool RTCStatsRequestImpl::hasSelector()
+{
+    return m_stream;
+}
+
+MediaStreamDescriptor* RTCStatsRequestImpl::stream()
+{
+    return m_stream.get();
+}
+
+MediaStreamComponent* RTCStatsRequestImpl::component()
+{
+    return m_component.get();
+}
+
 void RTCStatsRequestImpl::requestSucceeded(PassRefPtr<RTCStatsResponseBase> response)
 {
     if (!m_successCallback)

Modified: trunk/Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.h (131583 => 131584)


--- trunk/Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.h	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.h	2012-10-17 11:15:07 UTC (rev 131584)
@@ -40,21 +40,27 @@
 
 class RTCStatsRequestImpl : public RTCStatsRequest, public ActiveDOMObject {
 public:
-    static PassRefPtr<RTCStatsRequestImpl> create(ScriptExecutionContext*, PassRefPtr<RTCStatsCallback>);
+    static PassRefPtr<RTCStatsRequestImpl> create(ScriptExecutionContext*, PassRefPtr<RTCStatsCallback>, PassRefPtr<MediaStreamTrack>);
     virtual ~RTCStatsRequestImpl();
 
-    virtual PassRefPtr<RTCStatsResponseBase> createResponse();
-    virtual void requestSucceeded(PassRefPtr<RTCStatsResponseBase>);
+    virtual PassRefPtr<RTCStatsResponseBase> createResponse() OVERRIDE;
+    virtual bool hasSelector() OVERRIDE;
+    virtual MediaStreamDescriptor* stream() OVERRIDE;
+    virtual MediaStreamComponent* component() OVERRIDE;
 
+    virtual void requestSucceeded(PassRefPtr<RTCStatsResponseBase>) OVERRIDE;
+
     // ActiveDOMObject
     virtual void stop() OVERRIDE;
 
 private:
-    RTCStatsRequestImpl(ScriptExecutionContext*, PassRefPtr<RTCStatsCallback>);
+    RTCStatsRequestImpl(ScriptExecutionContext*, PassRefPtr<RTCStatsCallback>, PassRefPtr<MediaStreamTrack>);
 
     void clear();
 
     RefPtr<RTCStatsCallback> m_successCallback;
+    RefPtr<MediaStreamDescriptor> m_stream;
+    RefPtr<MediaStreamComponent> m_component;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/chromium/support/WebRTCStatsRequest.cpp (131583 => 131584)


--- trunk/Source/WebCore/platform/chromium/support/WebRTCStatsRequest.cpp	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/WebCore/platform/chromium/support/WebRTCStatsRequest.cpp	2012-10-17 11:15:07 UTC (rev 131584)
@@ -1,3 +1,4 @@
+
 /*
  * Copyright (C) 2012 Google Inc. All rights reserved.
  *
@@ -32,6 +33,8 @@
 
 #if ENABLE(MEDIA_STREAM)
 
+#include <public/WebMediaStreamComponent.h>
+#include <public/WebMediaStreamDescriptor.h>
 #include <public/WebRTCStatsRequest.h>
 #include <public/WebRTCStatsResponse.h>
 
@@ -63,6 +66,21 @@
     return WebRTCStatsResponse(m_private->createResponse());
 }
 
+bool WebRTCStatsRequest::hasSelector() const
+{
+    return m_private->hasSelector();
+}
+
+const WebMediaStreamDescriptor WebRTCStatsRequest::stream() const
+{
+    return WebMediaStreamDescriptor(m_private->stream());
+}
+
+const WebMediaStreamComponent WebRTCStatsRequest::component() const
+{
+    return WebMediaStreamComponent(m_private->component());
+}
+
 void WebRTCStatsRequest::requestSucceeded(const WebRTCStatsResponse& response) const
 {
     m_private->requestSucceeded(response);
@@ -71,4 +89,3 @@
 } // namespace WebKit
 
 #endif // ENABLE(MEDIA_STREAM)
-

Modified: trunk/Source/WebCore/platform/mediastream/RTCStatsRequest.h (131583 => 131584)


--- trunk/Source/WebCore/platform/mediastream/RTCStatsRequest.h	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Source/WebCore/platform/mediastream/RTCStatsRequest.h	2012-10-17 11:15:07 UTC (rev 131584)
@@ -39,6 +39,8 @@
 
 namespace WebCore {
 
+class MediaStreamComponent;
+class MediaStreamDescriptor;
 class RTCStatsResponseBase;
 
 class RTCStatsRequest : public RefCounted<RTCStatsRequest> {
@@ -46,6 +48,9 @@
     virtual ~RTCStatsRequest() { }
 
     virtual PassRefPtr<RTCStatsResponseBase> createResponse() = 0;
+    virtual bool hasSelector() = 0;
+    virtual MediaStreamDescriptor* stream() = 0;
+    virtual MediaStreamComponent* component() = 0;
     virtual void requestSucceeded(PassRefPtr<RTCStatsResponseBase>) = 0;
 
 protected:

Modified: trunk/Tools/ChangeLog (131583 => 131584)


--- trunk/Tools/ChangeLog	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Tools/ChangeLog	2012-10-17 11:15:07 UTC (rev 131584)
@@ -1,3 +1,17 @@
+2012-10-17  Harald Alvestrand  <[email protected]>
+
+        Implement the Selector argument to RTCPeerConnection.getStats
+        https://bugs.webkit.org/show_bug.cgi?id=99460
+
+        Reviewed by Adam Barth.
+
+        The MockWebRTCPeerConnectionHandler will return one object only
+        when it gets a selector, and an even number when there is no selector.
+        This allows to verify that the argument is passed, but not its value.
+
+        * DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp:
+        (MockWebRTCPeerConnectionHandler::getStats):
+
 2012-10-17  Mikhail Pozdnyakov  <[email protected]>
 
         WebKitTestRunner needs layoutTestController.queueReload

Modified: trunk/Tools/DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp (131583 => 131584)


--- trunk/Tools/DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp	2012-10-17 11:07:13 UTC (rev 131583)
+++ trunk/Tools/DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp	2012-10-17 11:15:07 UTC (rev 131584)
@@ -35,6 +35,8 @@
 
 #include "MockConstraints.h"
 #include <public/WebMediaConstraints.h>
+#include <public/WebMediaStreamComponent.h>
+#include <public/WebMediaStreamDescriptor.h>
 #include <public/WebRTCPeerConnectionHandlerClient.h>
 #include <public/WebRTCSessionDescription.h>
 #include <public/WebRTCSessionDescriptionRequest.h>
@@ -303,13 +305,22 @@
 {
     WebRTCStatsResponse response = request.createResponse();
     double currentDate = WTF::jsCurrentTime();
-    for (int i = 0; i < m_streamCount; ++i) {
+    if (request.hasSelector()) {
+        WebMediaStreamDescriptor stream = request.stream();
+        WebMediaStreamComponent component = request.component();
+        // FIXME: There is no check that the fetched values are valid.
         size_t reportIndex = response.addReport();
         response.addElement(reportIndex, true, currentDate);
-        response.addStatistic(reportIndex, true, "type", "audio");
-        reportIndex = response.addReport();
-        response.addElement(reportIndex, true, currentDate);
         response.addStatistic(reportIndex, true, "type", "video");
+    } else {
+        for (int i = 0; i < m_streamCount; ++i) {
+            size_t reportIndex = response.addReport();
+            response.addElement(reportIndex, true, currentDate);
+            response.addStatistic(reportIndex, true, "type", "audio");
+            reportIndex = response.addReport();
+            response.addElement(reportIndex, true, currentDate);
+            response.addStatistic(reportIndex, true, "type", "video");
+        }
     }
     postTask(new RTCStatsRequestSucceededTask(this, request, response));
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to