1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebRTCStatsRequest_h 32 #define WebRTCStatsRequest_h 33 34 #include "WebCommon.h" 35 #include "WebPrivatePtr.h" 36 #include "WebString.h" 37 38 namespace blink { 39 40 class RTCStatsRequest; 41 class WebMediaStreamTrack; 42 class WebMediaStream; 43 class WebRTCStatsResponse; 44 45 // The WebRTCStatsRequest class represents a JavaScript call on 46 // RTCPeerConnection.getStats(). The user of this API will use 47 // the calls on this class and WebRTCStatsResponse to fill in the 48 // data that will be returned via a callback to the user in an 49 // RTCStatsResponse structure. 50 // 51 // The typical usage pattern is: 52 // WebRTCStatsRequest request = <from somewhere> 53 // WebRTCStatsResponse response = request.createResponse(); 54 // 55 // For each item on which statistics are going to be reported: 56 // size_t reportIndex = response.addReport(); 57 // Add local information: 58 // size_t elementIndex = response.addElement(reportIndex, true, dateNow()); 59 // For each statistic being reported on: 60 // response.addStatistic(reportIndex, true, elementIndex, 61 // "name of statistic", "statistic value"); 62 // Remote information (typically RTCP-derived) is added in the same way. 63 // When finished adding information: 64 // request.requestSucceeded(response); 65 66 class WebRTCStatsRequest { 67 public: 68 WebRTCStatsRequest() { } 69 WebRTCStatsRequest(const WebRTCStatsRequest& other) { assign(other); } 70 ~WebRTCStatsRequest() { reset(); } 71 72 WebRTCStatsRequest& operator=(const WebRTCStatsRequest& other) 73 { 74 assign(other); 75 return *this; 76 } 77 78 BLINK_PLATFORM_EXPORT void assign(const WebRTCStatsRequest&); 79 80 BLINK_PLATFORM_EXPORT void reset(); 81 82 // This function returns true if a selector argument was given to getStats. 83 BLINK_PLATFORM_EXPORT bool hasSelector() const; 84 85 // The component() accessor give the information 86 // required to look up a MediaStreamTrack implementation. 87 // It is only useful to call it when hasSelector() returns true. 88 BLINK_PLATFORM_EXPORT const WebMediaStreamTrack component() const; 89 90 BLINK_PLATFORM_EXPORT void requestSucceeded(const WebRTCStatsResponse&) const; 91 92 BLINK_PLATFORM_EXPORT WebRTCStatsResponse createResponse() const; 93 94 #if INSIDE_BLINK 95 BLINK_PLATFORM_EXPORT WebRTCStatsRequest(RTCStatsRequest*); 96 #endif 97 98 private: 99 WebPrivatePtr<RTCStatsRequest> m_private; 100 }; 101 102 } // namespace blink 103 104 #endif // WebRTCStatsRequest_h 105