Source/ThirdParty/libwebrtc:
[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         CandidatePair,
43         Certificate,
44         Codec,
45         DataChannel,
46         InboundRtp,
47         LocalCandidate,
48         MediaSource,
49         OutboundRtp,
50         PeerConnection,
51         RemoteCandidate,
52         Track,
53         Transport
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         bool isRemote { false };
64         String mediaType;
65
66         String trackId;
67         String transportId;
68         String codecId;
69         Optional<uint32_t> firCount;
70         Optional<uint32_t> pliCount;
71         Optional<uint32_t> nackCount;
72         Optional<uint32_t> sliCount;
73         Optional<uint64_t> qpSum;
74     };
75
76     struct InboundRTPStreamStats : RTCRTPStreamStats {
77         InboundRTPStreamStats() { type = RTCStatsReport::Type::InboundRtp; }
78
79         Optional<uint32_t> packetsReceived;
80         Optional<uint64_t> bytesReceived;
81         Optional<uint32_t> packetsLost;
82         Optional<double> jitter;
83         Optional<double> fractionLost;
84         Optional<uint32_t> packetsDiscarded;
85         Optional<uint32_t> packetsRepaired;
86         Optional<uint32_t> burstPacketsLost;
87         Optional<uint32_t> burstPacketsDiscarded;
88         Optional<uint32_t> burstLossCount;
89         Optional<uint32_t> burstDiscardCount;
90         Optional<double> burstLossRate;
91         Optional<double> burstDiscardRate;
92         Optional<double> gapLossRate;
93         Optional<double> gapDiscardRate;
94         Optional<uint32_t> framesDecoded;
95     };
96
97     struct OutboundRTPStreamStats : RTCRTPStreamStats {
98         OutboundRTPStreamStats() { type = RTCStatsReport::Type::OutboundRtp; }
99
100         Optional<uint32_t> packetsSent;
101         Optional<uint64_t> bytesSent;
102         Optional<double> targetBitrate;
103         Optional<uint32_t> framesEncoded;
104         String mediaSourceId;
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
238     struct MediaSourceStats : Stats {
239         String trackIdentifier;
240         String kind;
241         Optional<bool> relayedSource;
242     };
243
244     struct AudioSourceStats : MediaSourceStats {
245         AudioSourceStats() { type = RTCStatsReport::Type::MediaSource; }
246
247         Optional<double> audioLevel;
248         Optional<double> totalAudioEnergy;
249         Optional<double> totalSamplesDuration;
250         Optional<double> echoReturnLoss;
251         Optional<double> echoReturnLossEnhancement;
252     };
253
254     struct VideoSourceStats : MediaSourceStats {
255         VideoSourceStats() { type = RTCStatsReport::Type::MediaSource; }
256
257         Optional<unsigned long> width;
258         Optional<unsigned long> height;
259         Optional<unsigned long> bitDepth;
260         Optional<unsigned long> frames;
261         Optional<double> framesPerSecond;
262     };
263
264 private:
265     explicit RTCStatsReport(MapInitializer&&);
266
267     MapInitializer m_mapInitializer;
268 };
269
270 inline RTCStatsReport::RTCStatsReport(MapInitializer&& mapInitializer)
271     : m_mapInitializer(WTFMove(mapInitializer))
272 {
273 }
274
275 } // namespace WebCore