6d3450ffc9c7ae7e644adf762c266dd49d11d743
[WebKit-https.git] / Source / WebCore / Modules / mediastream / RTCStatsReport.h
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 "LibWebRTCStatsCollector.h"
29
30 namespace WebCore {
31
32 class DOMMapAdapter;
33
34 class RTCStatsReport : public RefCounted<RTCStatsReport> {
35 public:
36     using MapInitializer = Function<void(DOMMapAdapter&)>;
37     static Ref<RTCStatsReport> create(MapInitializer&& mapInitializer) { return adoptRef(*new RTCStatsReport(WTFMove(mapInitializer))); }
38
39     void initializeMapLike(DOMMapAdapter& adapter) { m_mapInitializer(adapter); }
40
41     enum class Type {
42         Codec,
43         InboundRtp,
44         OutboundRtp,
45         PeerConnection,
46         DataChannel,
47         Track,
48         Transport,
49         CandidatePair,
50         LocalCandidate,
51         RemoteCandidate,
52         Certificate
53     };
54     struct Stats {
55         double timestamp;
56         Type type;
57         String id;
58     };
59
60     struct RTCRTPStreamStats : Stats {
61         Optional<uint32_t> ssrc;
62         bool isRemote { false };
63         String mediaType;
64
65         String trackId;
66         String transportId;
67         String codecId;
68         Optional<uint32_t> firCount;
69         Optional<uint32_t> pliCount;
70         Optional<uint32_t> nackCount;
71         Optional<uint32_t> sliCount;
72         Optional<uint64_t> qpSum;
73     };
74
75     struct InboundRTPStreamStats : RTCRTPStreamStats {
76         InboundRTPStreamStats() { type = RTCStatsReport::Type::InboundRtp; }
77
78         Optional<uint32_t> packetsReceived;
79         Optional<uint64_t> bytesReceived;
80         Optional<uint32_t> packetsLost;
81         Optional<double> jitter;
82         Optional<double> fractionLost;
83         Optional<uint32_t> packetsDiscarded;
84         Optional<uint32_t> packetsRepaired;
85         Optional<uint32_t> burstPacketsLost;
86         Optional<uint32_t> burstPacketsDiscarded;
87         Optional<uint32_t> burstLossCount;
88         Optional<uint32_t> burstDiscardCount;
89         Optional<double> burstLossRate;
90         Optional<double> burstDiscardRate;
91         Optional<double> gapLossRate;
92         Optional<double> gapDiscardRate;
93         Optional<uint32_t> framesDecoded;
94     };
95
96     struct OutboundRTPStreamStats : RTCRTPStreamStats {
97         OutboundRTPStreamStats() { type = RTCStatsReport::Type::OutboundRtp; }
98
99         Optional<uint32_t> packetsSent;
100         Optional<uint64_t> bytesSent;
101         Optional<double> targetBitrate;
102         Optional<uint32_t> framesEncoded;
103     };
104
105     struct MediaStreamTrackStats : Stats {
106         MediaStreamTrackStats() { type = RTCStatsReport::Type::Track; }
107
108         String trackIdentifier;
109         Optional<bool> remoteSource;
110         Optional<bool> ended;
111         Optional<bool> detached;
112         Optional<uint32_t> frameWidth;
113         Optional<uint32_t> frameHeight;
114         Optional<double> framesPerSecond;
115         Optional<uint32_t> framesSent;
116         Optional<uint32_t> framesReceived;
117         Optional<uint32_t> framesDecoded;
118         Optional<uint32_t> framesDropped;
119         Optional<uint32_t> framesCorrupted;
120         Optional<uint32_t> partialFramesLost;
121         Optional<uint32_t> fullFramesLost;
122         Optional<double> audioLevel;
123         Optional<double> echoReturnLoss;
124         Optional<double> echoReturnLossEnhancement;
125     };
126
127     struct DataChannelStats : Stats {
128         DataChannelStats() { type = RTCStatsReport::Type::DataChannel; }
129         
130         String label;
131         String protocol;
132         Optional<int> datachannelid;
133         String state;
134         Optional<uint32_t> messagesSent;
135         Optional<uint64_t> bytesSent;
136         Optional<uint32_t> messagesReceived;
137         Optional<uint64_t> bytesReceived;
138     };
139
140     enum class IceCandidatePairState {
141         Frozen,
142         Waiting,
143         Inprogress,
144         Failed,
145         Succeeded,
146         Cancelled
147     };
148
149     struct IceCandidatePairStats : Stats {
150         IceCandidatePairStats() { type = RTCStatsReport::Type::CandidatePair; }
151
152         String transportId;
153         String localCandidateId;
154         String remoteCandidateId;
155         IceCandidatePairState state;
156         Optional<uint64_t> priority;
157         Optional<bool> nominated;
158         Optional<bool> writable;
159         Optional<bool> readable;
160         Optional<uint64_t> bytesSent;
161         Optional<uint64_t> bytesReceived;
162         Optional<double> totalRoundTripTime;
163         Optional<double> currentRoundTripTime;
164         Optional<double> availableOutgoingBitrate;
165         Optional<double> availableIncomingBitrate;
166         Optional<uint64_t> requestsReceived;
167         Optional<uint64_t> requestsSent;
168         Optional<uint64_t> responsesReceived;
169         Optional<uint64_t> responsesSent;
170         Optional<uint64_t> retransmissionsReceived;
171         Optional<uint64_t> retransmissionsSent;
172         Optional<uint64_t> consentRequestsReceived;
173         Optional<uint64_t> consentRequestsSent;
174         Optional<uint64_t> consentResponsesReceived;
175         Optional<uint64_t> consentResponsesSent;
176     };
177
178     enum class IceCandidateType { Host, Srflx, Prflx, Relay };
179
180     struct IceCandidateStats : Stats {
181         String transportId;
182         String address;
183         Optional<int32_t> port;
184         String protocol;
185         Optional<IceCandidateType> candidateType;
186         Optional<int32_t> priority;
187         String url;
188         bool deleted { false };
189     };
190
191     struct CertificateStats : Stats {
192         CertificateStats() { type = RTCStatsReport::Type::Certificate; }
193
194         String fingerprint;
195         String fingerprintAlgorithm;
196         String base64Certificate;
197         String issuerCertificateId;
198     };
199
200     enum class CodecType {
201         Encode,
202         Decode
203     };
204
205     struct CodecStats : Stats {
206         CodecStats() { type = RTCStatsReport::Type::Codec; }
207
208         Optional<uint32_t> payloadType;
209         Optional<CodecType> codecType;
210         String transportId;
211         String mimeType;
212         Optional<uint32_t> clockRate;
213         Optional<uint32_t> channels;
214         String sdpFmtpLine;
215         String implementation;
216     };
217
218     struct TransportStats : Stats {
219         TransportStats() { type = RTCStatsReport::Type::Transport; }
220
221         Optional<uint64_t> bytesSent;
222         Optional<uint64_t> bytesReceived;
223         String rtcpTransportStatsId;
224         String selectedCandidatePairId;
225         String localCertificateId;
226         String remoteCertificateId;
227     };
228
229     struct PeerConnectionStats : Stats {
230         PeerConnectionStats() { type = RTCStatsReport::Type::PeerConnection; }
231
232         Optional<uint32_t> dataChannelsOpened;
233         Optional<uint32_t> dataChannelsClosed;
234     };
235
236 private:
237     explicit RTCStatsReport(MapInitializer&&);
238
239     MapInitializer m_mapInitializer;
240 };
241
242 inline RTCStatsReport::RTCStatsReport(MapInitializer&& mapInitializer)
243     : m_mapInitializer(WTFMove(mapInitializer))
244 {
245 }
246
247 } // namespace WebCore