Changeset 130260 in webkit


Ignore:
Timestamp:
Oct 3, 2012 1:01:25 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Add data passing to the GetStats interface of RTCPeerConnection
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:
Location:
trunk
Files:
21 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r130255 r130260  
     12012-10-03  Harald Alvestrand  <hta@google.com>
     2
     3        Add data passing to the GetStats interface of RTCPeerConnection
     4        https://bugs.webkit.org/show_bug.cgi?id=98003
     5
     6        Reviewed by Adam Barth.
     7
     8        * fast/mediastream/RTCPeerConnection-stats-expected.txt:
     9        * fast/mediastream/RTCPeerConnection-stats.html:
     10
    1112012-10-02  Arko Saha  <arko@motorola.com>
    212
  • trunk/LayoutTests/fast/mediastream/RTCPeerConnection-stats-expected.txt

    r129908 r130260  
    55
    66PASS pc = new webkitRTCPeerConnection(null) did not throw exception.
    7 PASS pc.getStats(statsHandler) did not throw exception.
    8 PASS statsHandler was called
     7PASS pc.getStats(statsHandler1) did not throw exception.
     8PASS statsHandler1 was called
    99PASS status is non-null.
    1010PASS result.length is 0
     11PASS getUserMedia({audio:true, video:true}, gotStream) did not throw exception.
     12PASS Got a stream.
     13PASS pc.getStats(statsHandler2) did not throw exception.
     14PASS statsHandler2 was called
     15PASS result.length is >= 2
     16PASS local.length is 1
     17PASS local[0].stat("type") is "audio"
    1118PASS successfullyParsed is true
    1219
  • trunk/LayoutTests/fast/mediastream/RTCPeerConnection-stats.html

    r129908 r130260  
    99
    1010var pc = null;
     11var result;
     12var local;
    1113
    12 function statsHandler(status)
     14function getUserMedia(dictionary, callback) {
     15    try {
     16        navigator.webkitGetUserMedia(dictionary, callback, error);
     17    } catch (e) {
     18        testFailed('webkitGetUserMedia threw exception :' + e);
     19        finishJSTest();
     20    }
     21}
     22
     23function error() {
     24    testFailed('Stream generation failed.');
     25    finishJSTest();
     26}
     27
     28function statsHandler1(status)
    1329{
    14     testPassed("statsHandler was called");
     30    testPassed("statsHandler1 was called");
    1531    shouldBeNonNull('status');
    1632    result = status.result();
    1733    shouldBe('result.length', '0');
     34    shouldNotThrow('getUserMedia({audio:true, video:true}, gotStream)');
     35}
     36
     37function gotStream(s) {
     38    testPassed('Got a stream.');
     39    stream = s;
     40
     41    pc.addStream(stream);
     42    shouldNotThrow('pc.getStats(statsHandler2)');
     43}
     44
     45function statsHandler2(status)
     46{
     47    testPassed("statsHandler2 was called");
     48    result = status.result();
     49    shouldBeGreaterThanOrEqual('result.length', '2');
     50    local = result[0].local();
     51    shouldBe('local.length', '1');
     52    shouldBe('local[0].stat("type")', '"audio"');
    1853    finishJSTest();
    1954}
    2055
    2156shouldNotThrow('pc = new webkitRTCPeerConnection(null)');
    22 shouldNotThrow('pc.getStats(statsHandler)');
     57shouldNotThrow('pc.getStats(statsHandler1)');
    2358
    2459window.jsTestIsAsync = true;
  • trunk/Source/Platform/ChangeLog

    r130180 r130260  
     12012-10-03  Harald Alvestrand  <hta@google.com>
     2
     3        Add data passing to the GetStats interface of RTCPeerConnection
     4        https://bugs.webkit.org/show_bug.cgi?id=98003
     5
     6        Reviewed by Adam Barth.
     7
     8        * Platform.gypi:
     9        * chromium/public/WebRTCStatsRequest.h:
     10        (WebKit):
     11        (WebRTCStatsRequest):
     12        * chromium/public/WebRTCStatsResponse.h: Added.
     13        (WebCore):
     14        (WebKit):
     15        (WebRTCStatsResponse):
     16        (WebKit::WebRTCStatsResponse::WebRTCStatsResponse):
     17        (WebKit::WebRTCStatsResponse::~WebRTCStatsResponse):
     18        (WebKit::WebRTCStatsResponse::operator=):
     19
    1202012-10-02  Terry Anderson  <tdanderson@chromium.org>
    221
  • trunk/Source/Platform/Platform.gypi

    r129894 r130260  
    113113            'chromium/public/WebRTCSessionDescription.h',
    114114            'chromium/public/WebRTCSessionDescriptionRequest.h',
     115            'chromium/public/WebRTCStatsRequest.h',
     116            'chromium/public/WebRTCStatsResponse.h',
    115117            'chromium/public/WebRTCVoidRequest.h',
    116118            'chromium/public/WebRect.h',
  • trunk/Source/Platform/chromium/public/WebRTCStatsRequest.h

    r129908 r130260  
    4242namespace WebKit {
    4343
     44class WebRTCStatsResponse;
     45
     46// The WebRTCStatsRequest class represents a JavaScript call on
     47// RTCPeerConnection.getStats(). The user of this API will use
     48// the calls on this class and WebRTCStatsResponse to fill in the
     49// data that will be returned via a callback to the user in an
     50// RTCStatsResponse structure.
     51//
     52// The typical usage pattern is:
     53// WebRTCStatsRequest request = <from somewhere>
     54// WebRTCStatsResponse response = request.createResponse();
     55//
     56// For each item on which statistics are going to be reported:
     57//   size_t reportIndex = response.addReport();
     58//   Add local information:
     59//   size_t elementIndex = response.addElement(reportIndex, true, dateNow());
     60//   For each statistic being reported on:
     61//     response.addStatistic(reportIndex, true, elementIndex,
     62//                           "name of statistic", "statistic value");
     63//   Remote information (typically RTCP-derived) is added in the same way.
     64// When finished adding information:
     65// request.requestSucceeded(response);
     66
    4467class WebRTCStatsRequest {
    4568public:
     
    5881    WEBKIT_EXPORT void reset();
    5982
    60     WEBKIT_EXPORT void requestSucceeded() const;
     83    WEBKIT_EXPORT void requestSucceeded(const WebRTCStatsResponse&) const;
     84
     85    WEBKIT_EXPORT WebRTCStatsResponse createResponse() const;
    6186
    6287#if WEBKIT_IMPLEMENTATION
  • trunk/Source/Platform/chromium/public/WebRTCStatsResponse.h

    r130259 r130260  
    2323 */
    2424
    25 #ifndef RTCStatsRequestImpl_h
    26 #define RTCStatsRequestImpl_h
     25#ifndef WebRTCStatsResponse_h
     26#define WebRTCStatsResponse_h
    2727
    28 #if ENABLE(MEDIA_STREAM)
    29 
    30 #include "ActiveDOMObject.h"
    31 #include "RTCStatsRequest.h"
    32 #include <wtf/PassRefPtr.h>
    33 #include <wtf/RefCounted.h>
    34 #include <wtf/text/WTFString.h>
     28#include "WebCommon.h"
     29#include "WebPrivatePtr.h"
     30#include "WebString.h"
    3531
    3632namespace WebCore {
     33class RTCStatsResponseBase;
     34}
    3735
    38 class RTCStatsCallback;
     36namespace WebKit {
    3937
    40 class RTCStatsRequestImpl : public RTCStatsRequest, public ActiveDOMObject {
     38class WebRTCStatsResponse {
    4139public:
    42     static PassRefPtr<RTCStatsRequestImpl> create(ScriptExecutionContext*, PassRefPtr<RTCStatsCallback>);
    43     virtual ~RTCStatsRequestImpl();
     40    WebRTCStatsResponse() { }
     41    WebRTCStatsResponse(const WebRTCStatsResponse& other) { assign(other); }
     42    ~WebRTCStatsResponse() { reset(); }
    4443
    45     virtual void requestSucceeded();
     44    WebRTCStatsResponse& operator=(const WebRTCStatsResponse& other)
     45    {
     46        assign(other);
     47        return *this;
     48    }
    4649
    47     // ActiveDOMObject
    48     virtual void stop() OVERRIDE;
     50    WEBKIT_EXPORT void assign(const WebRTCStatsResponse&);
     51
     52    WEBKIT_EXPORT void reset();
     53
     54    WEBKIT_EXPORT size_t addReport();
     55    WEBKIT_EXPORT size_t addElement(size_t report, bool isLocal, long timestamp);
     56    WEBKIT_EXPORT void addStatistic(size_t report, bool isLocal, size_t element, WebString name, WebString value);
     57
     58#if WEBKIT_IMPLEMENTATION
     59    WebRTCStatsResponse(const WTF::PassRefPtr<WebCore::RTCStatsResponseBase>&);
     60
     61    operator WTF::PassRefPtr<WebCore::RTCStatsResponseBase>() const;
     62#endif
    4963
    5064private:
    51     RTCStatsRequestImpl(ScriptExecutionContext*, PassRefPtr<RTCStatsCallback>);
    52 
    53     void clear();
    54 
    55     RefPtr<RTCStatsCallback> m_successCallback;
     65    WebPrivatePtr<WebCore::RTCStatsResponseBase> m_private;
    5666};
    5767
    58 } // namespace WebCore
     68} // namespace WebKit
    5969
    60 #endif // ENABLE(MEDIA_STREAM)
    61 
    62 #endif // RTCStatsRequestImpl_h
     70#endif // WebRTCStatsResponse_h
  • trunk/Source/WebCore/ChangeLog

    r130259 r130260  
     12012-10-03  Harald Alvestrand  <hta@google.com>
     2
     3        Add data passing to the GetStats interface of RTCPeerConnection
     4        https://bugs.webkit.org/show_bug.cgi?id=98003
     5
     6        Reviewed by Adam Barth.
     7
     8        Added an RTCStatsResponseBase interface to platform, and let the
     9        RTCStatsRequestImpl class produce an implementation of it that's returned
     10        to WebCore.
     11
     12        Tested by extension of the RTCPeerConnection-stats.html test.
     13
     14        * Modules/mediastream/RTCStatsElement.cpp:
     15        (WebCore::RTCStatsElement::addStatistic):
     16        (WebCore):
     17        * Modules/mediastream/RTCStatsElement.h:
     18        (RTCStatsElement):
     19        * Modules/mediastream/RTCStatsReport.cpp:
     20        (WebCore):
     21        (WebCore::RTCStatsReport::addElement):
     22        (WebCore::RTCStatsReport::addStatistic):
     23        * Modules/mediastream/RTCStatsReport.h:
     24        (RTCStatsReport):
     25        * Modules/mediastream/RTCStatsRequestImpl.cpp:
     26        (WebCore::RTCStatsRequestImpl::createResponse):
     27        (WebCore):
     28        (WebCore::RTCStatsRequestImpl::requestSucceeded):
     29        * Modules/mediastream/RTCStatsRequestImpl.h:
     30        (RTCStatsRequestImpl):
     31        * Modules/mediastream/RTCStatsResponse.cpp:
     32        (WebCore::RTCStatsResponse::create):
     33        (WebCore::RTCStatsResponse::addReport):
     34        (WebCore):
     35        (WebCore::RTCStatsResponse::addElement):
     36        (WebCore::RTCStatsResponse::addStatistic):
     37        * Modules/mediastream/RTCStatsResponse.h:
     38        (RTCStatsResponse):
     39        * WebCore.gypi:
     40        * platform/chromium/support/WebRTCStatsRequest.cpp:
     41        (WebKit::WebRTCStatsRequest::response):
     42        (WebKit):
     43        (WebKit::WebRTCStatsRequest::requestSucceeded):
     44        * platform/chromium/support/WebRTCStatsResponse.cpp: Added.
     45        (WebKit):
     46        (WebKit::WebRTCStatsResponse::WebRTCStatsResponse):
     47        (WebKit::WebRTCStatsResponse::assign):
     48        (WebKit::WebRTCStatsResponse::reset):
     49        (WebKit::WebRTCStatsResponse::operator WTF::PassRefPtr<WebCore::RTCStatsResponseBase>):
     50        (WebKit::WebRTCStatsResponse::addReport):
     51        (WebKit::WebRTCStatsResponse::addElement):
     52        (WebKit::WebRTCStatsResponse::addStatistic):
     53        * platform/mediastream/RTCStatsRequest.h:
     54        (WebCore):
     55        (RTCStatsRequest):
     56        * platform/mediastream/RTCStatsResponseBase.h: Added.
     57        (WebCore):
     58        (RTCStatsResponseBase):
     59        (WebCore::RTCStatsResponseBase::~RTCStatsResponseBase):
     60
    1612012-10-02  Carlos Garcia Campos  <cgarcia@igalia.com>
    262
  • trunk/Source/WebCore/Modules/mediastream/RTCStatsElement.cpp

    r129908 r130260  
    4848}
    4949
     50void RTCStatsElement::addStatistic(const String& name, const String& value)
     51{
     52    m_stats.add(name, value);
     53}
     54
    5055} // namespace WebCore
    5156
  • trunk/Source/WebCore/Modules/mediastream/RTCStatsElement.h

    r129908 r130260  
    3838    long timestamp() const { return m_timestamp; }
    3939    String stat(const String& name) const;
     40    void addStatistic(const String& name, const String& value);
    4041
    4142private:
  • trunk/Source/WebCore/Modules/mediastream/RTCStatsReport.cpp

    r129908 r130260  
    4040}
    4141
     42size_t RTCStatsReport::addElement(bool isLocal, long timestamp)
     43{
     44    if (isLocal) {
     45        m_local.append(RTCStatsElement::create(timestamp));
     46        return m_local.size() - 1;
     47    }
     48    m_remote.append(RTCStatsElement::create(timestamp));
     49    return m_remote.size() - 1;
     50}
     51
     52void RTCStatsReport::addStatistic(bool isLocal, size_t element, String name, String value)
     53{
     54    if (isLocal) {
     55        ASSERT(element >= 0 && element < m_local.size());
     56        m_local[element]->addStatistic(name, value);
     57    } else {
     58        ASSERT(element >= 0 && element < m_remote.size());
     59        m_remote[element]->addStatistic(name, value);
     60    }
     61}
     62
    4263} // namespace WebCore
    4364
  • trunk/Source/WebCore/Modules/mediastream/RTCStatsReport.h

    r129908 r130260  
    4141    const Vector<RefPtr<RTCStatsElement> >& remote() const { return m_remote; }
    4242
     43    size_t addElement(bool isLocal, long timestamp);
     44    void addStatistic(bool isLocal, size_t element, String name, String value);
     45
    4346private:
    4447    RTCStatsReport();
  • trunk/Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.cpp

    r129908 r130260  
    5252}
    5353
    54 void RTCStatsRequestImpl::requestSucceeded()
     54PassRefPtr<RTCStatsResponseBase> RTCStatsRequestImpl::createResponse()
     55{
     56    return RTCStatsResponse::create();
     57}
     58
     59void RTCStatsRequestImpl::requestSucceeded(PassRefPtr<RTCStatsResponseBase> response)
    5560{
    5661    if (!m_successCallback)
    5762        return;
    58     // FIXME: Fill in content of stats parameter.
    59     RefPtr<RTCStatsResponse> stats = RTCStatsResponse::create();
    60     m_successCallback->handleEvent(stats.get());
     63    m_successCallback->handleEvent(static_cast<RTCStatsResponse*>(response.get()));
    6164    clear();
    6265}
  • trunk/Source/WebCore/Modules/mediastream/RTCStatsRequestImpl.h

    r129908 r130260  
    3030#include "ActiveDOMObject.h"
    3131#include "RTCStatsRequest.h"
     32#include "RTCStatsResponse.h"
    3233#include <wtf/PassRefPtr.h>
    3334#include <wtf/RefCounted.h>
     
    4344    virtual ~RTCStatsRequestImpl();
    4445
    45     virtual void requestSucceeded();
     46    virtual PassRefPtr<RTCStatsResponseBase> createResponse();
     47    virtual void requestSucceeded(PassRefPtr<RTCStatsResponseBase>);
    4648
    4749    // ActiveDOMObject
  • trunk/Source/WebCore/Modules/mediastream/RTCStatsResponse.cpp

    r129908 r130260  
    3434{
    3535    return adoptRef(new RTCStatsResponse());
    36     // FIXME: Pass an RTCStatsRequest argument and populate from it.
    3736}
    3837
     
    4140}
    4241
     42size_t RTCStatsResponse::addReport()
     43{
     44    m_result.append(RTCStatsReport::create());
     45    return m_result.size() - 1;
     46}
     47
     48size_t RTCStatsResponse::addElement(size_t report, bool isLocal, long timestamp)
     49{
     50    ASSERT(report >= 0 && report < m_result.size());
     51    return m_result[report]->addElement(isLocal, timestamp);
     52}
     53
     54void RTCStatsResponse::addStatistic(size_t report, bool isLocal, size_t element, String name, String value)
     55{
     56    ASSERT(report >= 0 && report < m_result.size());
     57    return m_result[report]->addStatistic(isLocal, element, name, value);
     58}
     59
    4360} // namespace WebCore
    4461
  • trunk/Source/WebCore/Modules/mediastream/RTCStatsResponse.h

    r129908 r130260  
    3535#include "MediaStreamTrack.h"
    3636#include "RTCStatsReport.h"
     37#include "RTCStatsResponseBase.h"
    3738
    3839namespace WebCore {
    3940
    40 class RTCStatsResponse : public RefCounted<RTCStatsResponse> {
     41class RTCStatsResponse : public RTCStatsResponseBase {
    4142public:
    4243    static PassRefPtr<RTCStatsResponse> create();
    4344
    4445    const Vector<RefPtr<RTCStatsReport> >& result() const { return m_result; };
     46
     47    virtual size_t addReport() OVERRIDE;
     48    virtual size_t addElement(size_t report, bool isLocal, long timestamp) OVERRIDE;
     49    virtual void addStatistic(size_t report, bool isLocal, size_t element, String name, String value) OVERRIDE;
    4550
    4651private:
  • trunk/Source/WebCore/WebCore.gypi

    r130106 r130260  
    83748374            'platform/chromium/support/WebRTCSessionDescriptionRequest.cpp',
    83758375            'platform/chromium/support/WebRTCStatsRequest.cpp',
     8376            'platform/chromium/support/WebRTCStatsResponse.cpp',
    83768377            'platform/chromium/support/WebRTCVoidRequest.cpp',
    83778378            'platform/chromium/support/WebScrollbarThemeGeometryNative.cpp',
  • trunk/Source/WebCore/platform/chromium/support/WebRTCStatsRequest.cpp

    r129908 r130260  
    3434
    3535#include <public/WebRTCStatsRequest.h>
     36#include <public/WebRTCStatsResponse.h>
    3637
    3738#include "RTCStatsRequest.h"
     39#include "RTCStatsResponse.h"
    3840#include <wtf/PassOwnPtr.h>
    3941
     
    5759}
    5860
    59 void WebRTCStatsRequest::requestSucceeded() const
     61WebRTCStatsResponse WebRTCStatsRequest::createResponse() const
    6062{
    61     m_private->requestSucceeded();
     63    return WebRTCStatsResponse(m_private->createResponse());
     64}
     65
     66void WebRTCStatsRequest::requestSucceeded(const WebRTCStatsResponse& response) const
     67{
     68    m_private->requestSucceeded(response);
    6269}
    6370
  • trunk/Source/WebCore/platform/chromium/support/WebRTCStatsResponse.cpp

    r130259 r130260  
    2727#if ENABLE(MEDIA_STREAM)
    2828
    29 #include "RTCStatsElement.h"
     29#include <public/WebRTCStatsResponse.h>
    3030
    31 #include <wtf/text/StringHash.h>
     31#include "RTCStatsResponseBase.h"
     32#include <wtf/PassOwnPtr.h>
    3233
    33 namespace WebCore {
     34using namespace WebCore;
    3435
    35 PassRefPtr<RTCStatsElement> RTCStatsElement::create(long timestamp)
    36 {
    37     return adoptRef(new RTCStatsElement(timestamp));
    38 }
     36namespace WebKit {
    3937
    40 RTCStatsElement::RTCStatsElement(long timestamp)
    41     : m_timestamp(timestamp)
     38WebRTCStatsResponse::WebRTCStatsResponse(const PassRefPtr<RTCStatsResponseBase>& request)
     39    : m_private(request)
    4240{
    4341}
    4442
    45 String RTCStatsElement::stat(const String& name) const
     43void WebRTCStatsResponse::assign(const WebRTCStatsResponse& other)
    4644{
    47     return m_stats.get(name);
     45    m_private = other.m_private;
    4846}
    4947
    50 } // namespace WebCore
     48void WebRTCStatsResponse::reset()
     49{
     50    m_private.reset();
     51}
     52
     53WebRTCStatsResponse::operator WTF::PassRefPtr<WebCore::RTCStatsResponseBase>() const
     54{
     55    return m_private.get();
     56}
     57
     58size_t WebRTCStatsResponse::addReport()
     59{
     60    return m_private->addReport();
     61}
     62
     63size_t WebRTCStatsResponse::addElement(size_t report, bool isLocal, long timestamp)
     64{
     65    return m_private->addElement(report, isLocal, timestamp);
     66}
     67
     68void WebRTCStatsResponse::addStatistic(size_t report, bool isLocal, size_t element, WebString name, WebString value)
     69{
     70    m_private->addStatistic(report, isLocal, element, name, value);
     71}
     72
     73} // namespace WebKit
    5174
    5275#endif // ENABLE(MEDIA_STREAM)
     76
  • trunk/Source/WebCore/platform/mediastream/RTCStatsRequest.h

    r129908 r130260  
    4040namespace WebCore {
    4141
     42class RTCStatsResponseBase;
     43
    4244class RTCStatsRequest : public RefCounted<RTCStatsRequest> {
    4345public:
    4446    virtual ~RTCStatsRequest() { }
    4547
    46     virtual void requestSucceeded() = 0;
     48    virtual PassRefPtr<RTCStatsResponseBase> createResponse() = 0;
     49    virtual void requestSucceeded(PassRefPtr<RTCStatsResponseBase>) = 0;
    4750
    4851protected:
  • trunk/Source/WebCore/platform/mediastream/RTCStatsResponseBase.h

    r130259 r130260  
    2323 */
    2424
    25 #ifndef RTCStatsElement_h
    26 #define RTCStatsElement_h
     25#ifndef RTCStatsResponseBase_h
     26#define RTCStatsResponseBase_h
    2727
    28 #include <wtf/HashMap.h>
     28#if ENABLE(MEDIA_STREAM)
     29
    2930#include <wtf/PassRefPtr.h>
    3031#include <wtf/RefCounted.h>
     
    3334namespace WebCore {
    3435
    35 class RTCStatsElement : public RefCounted<RTCStatsElement> {
     36class RTCStatsResponseBase : public RefCounted<RTCStatsResponseBase> {
    3637public:
    37     static PassRefPtr<RTCStatsElement> create(long timestamp);
    38     long timestamp() const { return m_timestamp; }
    39     String stat(const String& name) const;
     38    virtual ~RTCStatsResponseBase() { }
    4039
    41 private:
    42     explicit RTCStatsElement(long timestamp);
    43 
    44     long m_timestamp;
    45     HashMap<String, String> m_stats;
     40    virtual size_t addReport() = 0;
     41    virtual size_t addElement(size_t report, bool isLocal, long timestamp) = 0;
     42    virtual void addStatistic(size_t report, bool isLocal, size_t element, String name, String value) = 0;
    4643};
    4744
    4845} // namespace WebCore
    4946
    50 #endif // RTCStatsElement_h
     47#endif // ENABLE(MEDIA_STREAM)
     48
     49#endif // RTCStatsResponseBase_h
  • trunk/Tools/ChangeLog

    r130237 r130260  
     12012-10-03  Harald Alvestrand  <hta@google.com>
     2
     3        Add data passing to the GetStats interface of RTCPeerConnection
     4        https://bugs.webkit.org/show_bug.cgi?id=98003
     5
     6        Reviewed by Adam Barth.
     7
     8        * DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp:
     9        (RTCStatsRequestSucceededTask::RTCStatsRequestSucceededTask):
     10        (MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler):
     11        (MockWebRTCPeerConnectionHandler::addStream):
     12        (MockWebRTCPeerConnectionHandler::removeStream):
     13        (MockWebRTCPeerConnectionHandler::getStats):
     14        * DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.h:
     15        (MockWebRTCPeerConnectionHandler):
     16
    117== Rolled over to ChangeLog-2012-10-02 ==
  • trunk/Tools/DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.cpp

    r129908 r130260  
    4040#include <public/WebRTCSessionDescriptionRequest.h>
    4141#include <public/WebRTCStatsRequest.h>
     42#include <public/WebRTCStatsResponse.h>
    4243#include <public/WebRTCVoidRequest.h>
    4344#include <public/WebString.h>
     
    8485class RTCStatsRequestSucceededTask : public MethodTask<MockWebRTCPeerConnectionHandler> {
    8586public:
    86     RTCStatsRequestSucceededTask(MockWebRTCPeerConnectionHandler* object, const WebKit::WebRTCStatsRequest& request)
    87         : MethodTask<MockWebRTCPeerConnectionHandler>(object)
    88         , m_request(request)
    89     {
    90     }
    91 
    92     virtual void runIfValid() OVERRIDE
    93     {
    94         m_request.requestSucceeded();
     87    RTCStatsRequestSucceededTask(MockWebRTCPeerConnectionHandler* object, const WebKit::WebRTCStatsRequest& request, const WebKit::WebRTCStatsResponse& response)
     88        : MethodTask<MockWebRTCPeerConnectionHandler>(object)
     89        , m_request(request)
     90        , m_response(response)
     91    {
     92    }
     93
     94    virtual void runIfValid() OVERRIDE
     95    {
     96        m_request.requestSucceeded(m_response);
    9597    }
    9698
    9799private:
    98100    WebKit::WebRTCStatsRequest m_request;
     101    WebKit::WebRTCStatsResponse m_response;
    99102};
    100103
     
    125128MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler(WebRTCPeerConnectionHandlerClient* client)
    126129    : m_client(client)
     130    , m_streamCount(0)
    127131{
    128132}
     
    196200bool MockWebRTCPeerConnectionHandler::addStream(const WebMediaStreamDescriptor& stream, const WebMediaConstraints&)
    197201{
     202    m_streamCount += 1;
    198203    m_client->didAddRemoteStream(stream);
    199204    m_client->negotiationNeeded();
     
    203208void MockWebRTCPeerConnectionHandler::removeStream(const WebMediaStreamDescriptor& stream)
    204209{
     210    m_streamCount -= 1;
    205211    m_client->didRemoveRemoteStream(stream);
    206212    m_client->negotiationNeeded();
     
    209215void MockWebRTCPeerConnectionHandler::getStats(const WebRTCStatsRequest& request)
    210216{
    211     postTask(new RTCStatsRequestSucceededTask(this, request));
    212 }
    213 
     217    WebRTCStatsResponse response = request.createResponse();
     218    for (int i = 0; i < m_streamCount; ++i) {
     219        size_t reportIndex = response.addReport();
     220        size_t elementIndex = response.addElement(reportIndex, true, 12345);
     221        response.addStatistic(reportIndex, true, elementIndex, "type", "audio");
     222        reportIndex = response.addReport();
     223        elementIndex = response.addElement(reportIndex, true, 12345);
     224        response.addStatistic(reportIndex, true, elementIndex, "type", "video");
     225    }
     226    postTask(new RTCStatsRequestSucceededTask(this, request, response));
     227}
    214228
    215229void MockWebRTCPeerConnectionHandler::stop()
  • trunk/Tools/DumpRenderTree/chromium/MockWebRTCPeerConnectionHandler.h

    r129908 r130260  
    7373    WebKit::WebRTCSessionDescription m_localDescription;
    7474    WebKit::WebRTCSessionDescription m_remoteDescription;
     75    int m_streamCount;
    7576};
    7677
Note: See TracChangeset for help on using the changeset viewer.