1 /*
2  *  Copyright 2016 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef API_STATS_RTCSTATS_OBJECTS_H_
12 #define API_STATS_RTCSTATS_OBJECTS_H_
13 
14 #include <string>
15 #include <vector>
16 
17 #include "api/stats/rtcstats.h"
18 
19 namespace webrtc {
20 
21 // https://w3c.github.io/webrtc-pc/#idl-def-rtcdatachannelstate
22 struct RTCDataChannelState {
23   static const char* const kConnecting;
24   static const char* const kOpen;
25   static const char* const kClosing;
26   static const char* const kClosed;
27 };
28 
29 // https://w3c.github.io/webrtc-stats/#dom-rtcstatsicecandidatepairstate
30 struct RTCStatsIceCandidatePairState {
31   static const char* const kFrozen;
32   static const char* const kWaiting;
33   static const char* const kInProgress;
34   static const char* const kFailed;
35   static const char* const kSucceeded;
36 };
37 
38 // https://w3c.github.io/webrtc-pc/#rtcicecandidatetype-enum
39 struct RTCIceCandidateType {
40   static const char* const kHost;
41   static const char* const kSrflx;
42   static const char* const kPrflx;
43   static const char* const kRelay;
44 };
45 
46 // https://w3c.github.io/webrtc-pc/#idl-def-rtcdtlstransportstate
47 struct RTCDtlsTransportState {
48   static const char* const kNew;
49   static const char* const kConnecting;
50   static const char* const kConnected;
51   static const char* const kClosed;
52   static const char* const kFailed;
53 };
54 
55 // |RTCMediaStreamTrackStats::kind| is not an enum in the spec but the only
56 // valid values are "audio" and "video".
57 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-kind
58 struct RTCMediaStreamTrackKind {
59   static const char* const kAudio;
60   static const char* const kVideo;
61 };
62 
63 // https://w3c.github.io/webrtc-stats/#dom-rtcnetworktype
64 struct RTCNetworkType {
65   static const char* const kBluetooth;
66   static const char* const kCellular;
67   static const char* const kEthernet;
68   static const char* const kWifi;
69   static const char* const kWimax;
70   static const char* const kVpn;
71   static const char* const kUnknown;
72 };
73 
74 // https://w3c.github.io/webrtc-stats/#certificatestats-dict*
75 class RTCCertificateStats final : public RTCStats {
76  public:
77   WEBRTC_RTCSTATS_DECL();
78 
79   RTCCertificateStats(const std::string& id, int64_t timestamp_us);
80   RTCCertificateStats(std::string&& id, int64_t timestamp_us);
81   RTCCertificateStats(const RTCCertificateStats& other);
82   ~RTCCertificateStats() override;
83 
84   RTCStatsMember<std::string> fingerprint;
85   RTCStatsMember<std::string> fingerprint_algorithm;
86   RTCStatsMember<std::string> base64_certificate;
87   RTCStatsMember<std::string> issuer_certificate_id;
88 };
89 
90 // https://w3c.github.io/webrtc-stats/#codec-dict*
91 class RTCCodecStats final : public RTCStats {
92  public:
93   WEBRTC_RTCSTATS_DECL();
94 
95   RTCCodecStats(const std::string& id, int64_t timestamp_us);
96   RTCCodecStats(std::string&& id, int64_t timestamp_us);
97   RTCCodecStats(const RTCCodecStats& other);
98   ~RTCCodecStats() override;
99 
100   RTCStatsMember<uint32_t> payload_type;
101   RTCStatsMember<std::string> mime_type;
102   RTCStatsMember<uint32_t> clock_rate;
103   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7061
104   RTCStatsMember<uint32_t> channels;
105   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7061
106   RTCStatsMember<std::string> sdp_fmtp_line;
107   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7061
108   RTCStatsMember<std::string> implementation;
109 };
110 
111 // https://w3c.github.io/webrtc-stats/#dcstats-dict*
112 class RTCDataChannelStats final : public RTCStats {
113  public:
114   WEBRTC_RTCSTATS_DECL();
115 
116   RTCDataChannelStats(const std::string& id, int64_t timestamp_us);
117   RTCDataChannelStats(std::string&& id, int64_t timestamp_us);
118   RTCDataChannelStats(const RTCDataChannelStats& other);
119   ~RTCDataChannelStats() override;
120 
121   RTCStatsMember<std::string> label;
122   RTCStatsMember<std::string> protocol;
123   RTCStatsMember<int32_t> datachannelid;
124   // TODO(hbos): Support enum types? "RTCStatsMember<RTCDataChannelState>"?
125   RTCStatsMember<std::string> state;
126   RTCStatsMember<uint32_t> messages_sent;
127   RTCStatsMember<uint64_t> bytes_sent;
128   RTCStatsMember<uint32_t> messages_received;
129   RTCStatsMember<uint64_t> bytes_received;
130 };
131 
132 // https://w3c.github.io/webrtc-stats/#candidatepair-dict*
133 // TODO(hbos): Tracking bug https://bugs.webrtc.org/7062
134 class RTCIceCandidatePairStats final : public RTCStats {
135  public:
136   WEBRTC_RTCSTATS_DECL();
137 
138   RTCIceCandidatePairStats(const std::string& id, int64_t timestamp_us);
139   RTCIceCandidatePairStats(std::string&& id, int64_t timestamp_us);
140   RTCIceCandidatePairStats(const RTCIceCandidatePairStats& other);
141   ~RTCIceCandidatePairStats() override;
142 
143   RTCStatsMember<std::string> transport_id;
144   RTCStatsMember<std::string> local_candidate_id;
145   RTCStatsMember<std::string> remote_candidate_id;
146   // TODO(hbos): Support enum types?
147   // "RTCStatsMember<RTCStatsIceCandidatePairState>"?
148   RTCStatsMember<std::string> state;
149   RTCStatsMember<uint64_t> priority;
150   RTCStatsMember<bool> nominated;
151   // TODO(hbos): Collect this the way the spec describes it. We have a value for
152   // it but it is not spec-compliant. https://bugs.webrtc.org/7062
153   RTCStatsMember<bool> writable;
154   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062
155   RTCStatsMember<bool> readable;
156   RTCStatsMember<uint64_t> bytes_sent;
157   RTCStatsMember<uint64_t> bytes_received;
158   RTCStatsMember<double> total_round_trip_time;
159   RTCStatsMember<double> current_round_trip_time;
160   RTCStatsMember<double> available_outgoing_bitrate;
161   // TODO(hbos): Populate this value. It is wired up and collected the same way
162   // "VideoBwe.googAvailableReceiveBandwidth" is, but that value is always
163   // undefined. https://bugs.webrtc.org/7062
164   RTCStatsMember<double> available_incoming_bitrate;
165   RTCStatsMember<uint64_t> requests_received;
166   RTCStatsMember<uint64_t> requests_sent;
167   RTCStatsMember<uint64_t> responses_received;
168   RTCStatsMember<uint64_t> responses_sent;
169   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062
170   RTCStatsMember<uint64_t> retransmissions_received;
171   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062
172   RTCStatsMember<uint64_t> retransmissions_sent;
173   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062
174   RTCStatsMember<uint64_t> consent_requests_received;
175   RTCStatsMember<uint64_t> consent_requests_sent;
176   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062
177   RTCStatsMember<uint64_t> consent_responses_received;
178   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062
179   RTCStatsMember<uint64_t> consent_responses_sent;
180 };
181 
182 // https://w3c.github.io/webrtc-stats/#icecandidate-dict*
183 // TODO(hbos): |RTCStatsCollector| only collects candidates that are part of
184 // ice candidate pairs, but there could be candidates not paired with anything.
185 // crbug.com/632723
186 class RTCIceCandidateStats : public RTCStats {
187  public:
188   WEBRTC_RTCSTATS_DECL();
189 
190   RTCIceCandidateStats(const RTCIceCandidateStats& other);
191   ~RTCIceCandidateStats() override;
192 
193   RTCStatsMember<std::string> transport_id;
194   RTCStatsMember<bool> is_remote;
195   RTCStatsMember<std::string> network_type;
196   RTCStatsMember<std::string> ip;
197   RTCStatsMember<int32_t> port;
198   RTCStatsMember<std::string> protocol;
199   // TODO(hbos): Support enum types? "RTCStatsMember<RTCIceCandidateType>"?
200   RTCStatsMember<std::string> candidate_type;
201   RTCStatsMember<int32_t> priority;
202   // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/632723
203   RTCStatsMember<std::string> url;
204   // TODO(hbos): |deleted = true| case is not supported by |RTCStatsCollector|.
205   // crbug.com/632723
206   RTCStatsMember<bool> deleted;  // = false
207 
208  protected:
209   RTCIceCandidateStats(
210       const std::string& id, int64_t timestamp_us, bool is_remote);
211   RTCIceCandidateStats(std::string&& id, int64_t timestamp_us, bool is_remote);
212 };
213 
214 // In the spec both local and remote varieties are of type RTCIceCandidateStats.
215 // But here we define them as subclasses of |RTCIceCandidateStats| because the
216 // |kType| need to be different ("RTCStatsType type") in the local/remote case.
217 // https://w3c.github.io/webrtc-stats/#rtcstatstype-str*
218 class RTCLocalIceCandidateStats final : public RTCIceCandidateStats {
219  public:
220   static const char kType[];
221   RTCLocalIceCandidateStats(const std::string& id, int64_t timestamp_us);
222   RTCLocalIceCandidateStats(std::string&& id, int64_t timestamp_us);
223   const char* type() const override;
224 };
225 
226 class RTCRemoteIceCandidateStats final : public RTCIceCandidateStats {
227  public:
228   static const char kType[];
229   RTCRemoteIceCandidateStats(const std::string& id, int64_t timestamp_us);
230   RTCRemoteIceCandidateStats(std::string&& id, int64_t timestamp_us);
231   const char* type() const override;
232 };
233 
234 // https://w3c.github.io/webrtc-stats/#msstats-dict*
235 // TODO(hbos): Tracking bug crbug.com/660827
236 class RTCMediaStreamStats final : public RTCStats {
237  public:
238   WEBRTC_RTCSTATS_DECL();
239 
240   RTCMediaStreamStats(const std::string& id, int64_t timestamp_us);
241   RTCMediaStreamStats(std::string&& id, int64_t timestamp_us);
242   RTCMediaStreamStats(const RTCMediaStreamStats& other);
243   ~RTCMediaStreamStats() override;
244 
245   RTCStatsMember<std::string> stream_identifier;
246   RTCStatsMember<std::vector<std::string>> track_ids;
247 };
248 
249 // https://w3c.github.io/webrtc-stats/#mststats-dict*
250 // TODO(hbos): Tracking bug crbug.com/659137
251 class RTCMediaStreamTrackStats final : public RTCStats {
252  public:
253   WEBRTC_RTCSTATS_DECL();
254 
255   RTCMediaStreamTrackStats(const std::string& id, int64_t timestamp_us,
256                            const char* kind);
257   RTCMediaStreamTrackStats(std::string&& id, int64_t timestamp_us,
258                            const char* kind);
259   RTCMediaStreamTrackStats(const RTCMediaStreamTrackStats& other);
260   ~RTCMediaStreamTrackStats() override;
261 
262   RTCStatsMember<std::string> track_identifier;
263   RTCStatsMember<bool> remote_source;
264   RTCStatsMember<bool> ended;
265   // TODO(hbos): |RTCStatsCollector| does not return stats for detached tracks.
266   // crbug.com/659137
267   RTCStatsMember<bool> detached;
268   // See |RTCMediaStreamTrackKind| for valid values.
269   RTCStatsMember<std::string> kind;
270   // TODO(gustaf): Implement jitter_buffer_delay for video (currently
271   // implemented for audio only).
272   // https://crbug.com/webrtc/8318
273   RTCStatsMember<double> jitter_buffer_delay;
274   // Video-only members
275   RTCStatsMember<uint32_t> frame_width;
276   RTCStatsMember<uint32_t> frame_height;
277   // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/659137
278   RTCStatsMember<double> frames_per_second;
279   RTCStatsMember<uint32_t> frames_sent;
280   RTCStatsMember<uint32_t> frames_received;
281   RTCStatsMember<uint32_t> frames_decoded;
282   RTCStatsMember<uint32_t> frames_dropped;
283   // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/659137
284   RTCStatsMember<uint32_t> frames_corrupted;
285   // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/659137
286   RTCStatsMember<uint32_t> partial_frames_lost;
287   // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/659137
288   RTCStatsMember<uint32_t> full_frames_lost;
289   // Audio-only members
290   RTCStatsMember<double> audio_level;
291   RTCStatsMember<double> total_audio_energy;
292   RTCStatsMember<double> echo_return_loss;
293   RTCStatsMember<double> echo_return_loss_enhancement;
294   RTCStatsMember<uint64_t> total_samples_received;
295   RTCStatsMember<double> total_samples_duration;
296   RTCStatsMember<uint64_t> concealed_samples;
297   RTCStatsMember<uint64_t> concealment_events;
298 };
299 
300 // https://w3c.github.io/webrtc-stats/#pcstats-dict*
301 class RTCPeerConnectionStats final : public RTCStats {
302  public:
303   WEBRTC_RTCSTATS_DECL();
304 
305   RTCPeerConnectionStats(const std::string& id, int64_t timestamp_us);
306   RTCPeerConnectionStats(std::string&& id, int64_t timestamp_us);
307   RTCPeerConnectionStats(const RTCPeerConnectionStats& other);
308   ~RTCPeerConnectionStats() override;
309 
310   RTCStatsMember<uint32_t> data_channels_opened;
311   RTCStatsMember<uint32_t> data_channels_closed;
312 };
313 
314 // https://w3c.github.io/webrtc-stats/#streamstats-dict*
315 // TODO(hbos): Tracking bug crbug.com/657854
316 class RTCRTPStreamStats : public RTCStats {
317  public:
318   WEBRTC_RTCSTATS_DECL();
319 
320   RTCRTPStreamStats(const RTCRTPStreamStats& other);
321   ~RTCRTPStreamStats() override;
322 
323   RTCStatsMember<uint32_t> ssrc;
324   // TODO(hbos): When the remote case is supported |RTCStatsCollector| needs to
325   // set this. crbug.com/657855, 657856
326   RTCStatsMember<std::string> associate_stats_id;
327   // TODO(hbos): Remote case not supported by |RTCStatsCollector|.
328   // crbug.com/657855, 657856
329   RTCStatsMember<bool> is_remote;  // = false
330   RTCStatsMember<std::string> media_type;
331   RTCStatsMember<std::string> track_id;
332   RTCStatsMember<std::string> transport_id;
333   RTCStatsMember<std::string> codec_id;
334   // FIR and PLI counts are only defined for |media_type == "video"|.
335   RTCStatsMember<uint32_t> fir_count;
336   RTCStatsMember<uint32_t> pli_count;
337   // TODO(hbos): NACK count should be collected by |RTCStatsCollector| for both
338   // audio and video but is only defined in the "video" case. crbug.com/657856
339   RTCStatsMember<uint32_t> nack_count;
340   // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/657854
341   // SLI count is only defined for |media_type == "video"|.
342   RTCStatsMember<uint32_t> sli_count;
343   RTCStatsMember<uint64_t> qp_sum;
344 
345  protected:
346   RTCRTPStreamStats(const std::string& id, int64_t timestamp_us);
347   RTCRTPStreamStats(std::string&& id, int64_t timestamp_us);
348 };
349 
350 // https://w3c.github.io/webrtc-stats/#inboundrtpstats-dict*
351 // TODO(hbos): Support the remote case |is_remote = true|.
352 // https://bugs.webrtc.org/7065
353 class RTCInboundRTPStreamStats final : public RTCRTPStreamStats {
354  public:
355   WEBRTC_RTCSTATS_DECL();
356 
357   RTCInboundRTPStreamStats(const std::string& id, int64_t timestamp_us);
358   RTCInboundRTPStreamStats(std::string&& id, int64_t timestamp_us);
359   RTCInboundRTPStreamStats(const RTCInboundRTPStreamStats& other);
360   ~RTCInboundRTPStreamStats() override;
361 
362   RTCStatsMember<uint32_t> packets_received;
363   RTCStatsMember<uint64_t> bytes_received;
364   RTCStatsMember<uint32_t> packets_lost;
365   // TODO(hbos): Collect and populate this value for both "audio" and "video",
366   // currently not collected for "video". https://bugs.webrtc.org/7065
367   RTCStatsMember<double> jitter;
368   RTCStatsMember<double> fraction_lost;
369   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
370   RTCStatsMember<double> round_trip_time;
371   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
372   RTCStatsMember<uint32_t> packets_discarded;
373   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
374   RTCStatsMember<uint32_t> packets_repaired;
375   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
376   RTCStatsMember<uint32_t> burst_packets_lost;
377   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
378   RTCStatsMember<uint32_t> burst_packets_discarded;
379   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
380   RTCStatsMember<uint32_t> burst_loss_count;
381   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
382   RTCStatsMember<uint32_t> burst_discard_count;
383   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
384   RTCStatsMember<double> burst_loss_rate;
385   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
386   RTCStatsMember<double> burst_discard_rate;
387   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
388   RTCStatsMember<double> gap_loss_rate;
389   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065
390   RTCStatsMember<double> gap_discard_rate;
391   RTCStatsMember<uint32_t> frames_decoded;
392 };
393 
394 // https://w3c.github.io/webrtc-stats/#outboundrtpstats-dict*
395 // TODO(hbos): Support the remote case |is_remote = true|.
396 // https://bugs.webrtc.org/7066
397 class RTCOutboundRTPStreamStats final : public RTCRTPStreamStats {
398  public:
399   WEBRTC_RTCSTATS_DECL();
400 
401   RTCOutboundRTPStreamStats(const std::string& id, int64_t timestamp_us);
402   RTCOutboundRTPStreamStats(std::string&& id, int64_t timestamp_us);
403   RTCOutboundRTPStreamStats(const RTCOutboundRTPStreamStats& other);
404   ~RTCOutboundRTPStreamStats() override;
405 
406   RTCStatsMember<uint32_t> packets_sent;
407   RTCStatsMember<uint64_t> bytes_sent;
408   // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7066
409   RTCStatsMember<double> target_bitrate;
410   RTCStatsMember<uint32_t> frames_encoded;
411 };
412 
413 // https://w3c.github.io/webrtc-stats/#transportstats-dict*
414 class RTCTransportStats final : public RTCStats {
415  public:
416   WEBRTC_RTCSTATS_DECL();
417 
418   RTCTransportStats(const std::string& id, int64_t timestamp_us);
419   RTCTransportStats(std::string&& id, int64_t timestamp_us);
420   RTCTransportStats(const RTCTransportStats& other);
421   ~RTCTransportStats() override;
422 
423   RTCStatsMember<uint64_t> bytes_sent;
424   RTCStatsMember<uint64_t> bytes_received;
425   RTCStatsMember<std::string> rtcp_transport_stats_id;
426   // TODO(hbos): Support enum types? "RTCStatsMember<RTCDtlsTransportState>"?
427   RTCStatsMember<std::string> dtls_state;
428   RTCStatsMember<std::string> selected_candidate_pair_id;
429   RTCStatsMember<std::string> local_certificate_id;
430   RTCStatsMember<std::string> remote_certificate_id;
431 };
432 
433 }  // namespace webrtc
434 
435 #endif  // API_STATS_RTCSTATS_OBJECTS_H_
436