1/*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2017 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "JSDOMMapLike.h"
29
30namespace WebCore {
31
32class RTCStatsReport : public RefCounted<RTCStatsReport> {
33public:
34 static Ref<RTCStatsReport> create() { return adoptRef(*new RTCStatsReport); }
35
36 void synchronizeBackingMap(Ref<DOMMapLike>&& mapLike) { m_mapLike = WTFMove(mapLike); }
37 DOMMapLike* backingMap() { return m_mapLike.get(); }
38
39 template<typename Value> void addStats(typename Value::ParameterType&& value) { m_mapLike->set<IDLDOMString, Value>(value.id, std::forward<typename Value::ParameterType>(value)); }
40
41
42 enum class Type {
43 Codec,
44 InboundRtp,
45 OutboundRtp,
46 PeerConnection,
47 DataChannel,
48 Track,
49 Transport,
50 CandidatePair,
51 LocalCandidate,
52 RemoteCandidate,
53 Certificate
54 };
55 struct Stats {
56 double timestamp;
57 Type type;
58 String id;
59 };
60
61 struct RTCRTPStreamStats : Stats {
62 Optional<uint32_t> ssrc;
63 String associateStatsId;
64 bool isRemote { false };
65 String mediaType;
66
67 String trackId;
68 String transportId;
69 String codecId;
70 Optional<uint32_t> firCount;
71 Optional<uint32_t> pliCount;
72 Optional<uint32_t> nackCount;
73 Optional<uint32_t> sliCount;
74 Optional<uint64_t> qpSum;
75 };
76
77 struct InboundRTPStreamStats : RTCRTPStreamStats {
78 InboundRTPStreamStats() { type = RTCStatsReport::Type::InboundRtp; }
79
80 Optional<uint32_t> packetsReceived;
81 Optional<uint64_t> bytesReceived;
82 Optional<uint32_t> packetsLost;
83 Optional<double> jitter;
84 Optional<double> fractionLost;
85 Optional<uint32_t> packetsDiscarded;
86 Optional<uint32_t> packetsRepaired;
87 Optional<uint32_t> burstPacketsLost;
88 Optional<uint32_t> burstPacketsDiscarded;
89 Optional<uint32_t> burstLossCount;
90 Optional<uint32_t> burstDiscardCount;
91 Optional<double> burstLossRate;
92 Optional<double> burstDiscardRate;
93 Optional<double> gapLossRate;
94 Optional<double> gapDiscardRate;
95 Optional<uint32_t> framesDecoded;
96 };
97
98 struct OutboundRTPStreamStats : RTCRTPStreamStats {
99 OutboundRTPStreamStats() { type = RTCStatsReport::Type::OutboundRtp; }
100
101 Optional<uint32_t> packetsSent;
102 Optional<uint64_t> bytesSent;
103 Optional<double> targetBitrate;
104 Optional<uint32_t> framesEncoded;
105 };
106
107 struct MediaStreamTrackStats : Stats {
108 MediaStreamTrackStats() { type = RTCStatsReport::Type::Track; }
109
110 String trackIdentifier;
111 Optional<bool> remoteSource;
112 Optional<bool> ended;
113 Optional<bool> detached;
114 Optional<uint32_t> frameWidth;
115 Optional<uint32_t> frameHeight;
116 Optional<double> framesPerSecond;
117 Optional<uint32_t> framesSent;
118 Optional<uint32_t> framesReceived;
119 Optional<uint32_t> framesDecoded;
120 Optional<uint32_t> framesDropped;
121 Optional<uint32_t> framesCorrupted;
122 Optional<uint32_t> partialFramesLost;
123 Optional<uint32_t> fullFramesLost;
124 Optional<double> audioLevel;
125 Optional<double> echoReturnLoss;
126 Optional<double> echoReturnLossEnhancement;
127 };
128
129 struct DataChannelStats : Stats {
130 DataChannelStats() { type = RTCStatsReport::Type::DataChannel; }
131
132 String label;
133 String protocol;
134 Optional<int> datachannelid;
135 String state;
136 Optional<uint32_t> messagesSent;
137 Optional<uint64_t> bytesSent;
138 Optional<uint32_t> messagesReceived;
139 Optional<uint64_t> bytesReceived;
140 };
141
142 enum class IceCandidatePairState {
143 Frozen,
144 Waiting,
145 Inprogress,
146 Failed,
147 Succeeded,
148 Cancelled
149 };
150
151 struct IceCandidatePairStats : Stats {
152 IceCandidatePairStats() { type = RTCStatsReport::Type::CandidatePair; }
153
154 String transportId;
155 String localCandidateId;
156 String remoteCandidateId;
157 IceCandidatePairState state;
158 Optional<uint64_t> priority;
159 Optional<bool> nominated;
160 Optional<bool> writable;
161 Optional<bool> readable;
162 Optional<uint64_t> bytesSent;
163 Optional<uint64_t> bytesReceived;
164 Optional<double> totalRoundTripTime;
165 Optional<double> currentRoundTripTime;
166 Optional<double> availableOutgoingBitrate;
167 Optional<double> availableIncomingBitrate;
168 Optional<uint64_t> requestsReceived;
169 Optional<uint64_t> requestsSent;
170 Optional<uint64_t> responsesReceived;
171 Optional<uint64_t> responsesSent;
172 Optional<uint64_t> retransmissionsReceived;
173 Optional<uint64_t> retransmissionsSent;
174 Optional<uint64_t> consentRequestsReceived;
175 Optional<uint64_t> consentRequestsSent;
176 Optional<uint64_t> consentResponsesReceived;
177 Optional<uint64_t> consentResponsesSent;
178 };
179
180 enum class IceCandidateType { Host, Srflx, Prflx, Relay };
181
182 struct IceCandidateStats : Stats {
183 String transportId;
184 String address;
185 Optional<int32_t> port;
186 String protocol;
187 Optional<IceCandidateType> candidateType;
188 Optional<int32_t> priority;
189 String url;
190 bool deleted { false };
191 };
192
193 struct CertificateStats : Stats {
194 CertificateStats() { type = RTCStatsReport::Type::Certificate; }
195
196 String fingerprint;
197 String fingerprintAlgorithm;
198 String base64Certificate;
199 String issuerCertificateId;
200 };
201
202 enum class CodecType {
203 Encode,
204 Decode
205 };
206
207 struct CodecStats : Stats {
208 CodecStats() { type = RTCStatsReport::Type::Codec; }
209
210 Optional<uint32_t> payloadType;
211 Optional<CodecType> codecType;
212 String transportId;
213 String mimeType;
214 Optional<uint32_t> clockRate;
215 Optional<uint32_t> channels;
216 String sdpFmtpLine;
217 String implementation;
218 };
219
220 struct TransportStats : Stats {
221 TransportStats() { type = RTCStatsReport::Type::Transport; }
222
223 Optional<uint64_t> bytesSent;
224 Optional<uint64_t> bytesReceived;
225 String rtcpTransportStatsId;
226 String selectedCandidatePairId;
227 String localCertificateId;
228 String remoteCertificateId;
229 };
230
231 struct PeerConnectionStats : Stats {
232 PeerConnectionStats() { type = RTCStatsReport::Type::PeerConnection; }
233
234 Optional<uint32_t> dataChannelsOpened;
235 Optional<uint32_t> dataChannelsClosed;
236 };
237
238private:
239 RTCStatsReport() = default;
240
241private:
242 RefPtr<DOMMapLike> m_mapLike;
243};
244
245} // namespace WebCore
246