blob: 55735c0b83a0bb7690ea4a192d9d6d1e0b58f12e [file] [log] [blame]
hbosd565b732016-08-30 14:04:35 -07001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080011#include "pc/rtc_stats_collector.h"
hbosd565b732016-08-30 14:04:35 -070012
13#include <memory>
Steve Anton36b29d12017-10-30 09:57:42 -070014#include <string>
hbosd565b732016-08-30 14:04:35 -070015#include <utility>
16#include <vector>
17
Karl Wiberg918f50c2018-07-05 11:40:33 +020018#include "absl/memory/memory.h"
Patrik Höglunde2d6a062017-10-05 14:53:33 +020019#include "api/candidate.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/media_stream_interface.h"
21#include "api/peer_connection_interface.h"
Henrik Boström2e069262019-04-09 13:59:31 +020022#include "api/video/video_content_type.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "media/base/media_channel.h"
24#include "p2p/base/p2p_constants.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "pc/peer_connection.h"
27#include "pc/rtc_stats_traversal.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "rtc_base/checks.h"
Jonas Olsson43568dd2018-06-11 16:25:54 +020029#include "rtc_base/strings/string_builder.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "rtc_base/time_utils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "rtc_base/trace_event.h"
hbosd565b732016-08-30 14:04:35 -070032
33namespace webrtc {
34
hboscc555c52016-10-18 12:48:31 -070035namespace {
36
Henrik Boström646fda02019-05-22 15:49:42 +020037// TODO(https://crbug.com/webrtc/10656): Consider making IDs less predictable.
hbos2fa7c672016-10-24 04:00:05 -070038std::string RTCCertificateIDFromFingerprint(const std::string& fingerprint) {
39 return "RTCCertificate_" + fingerprint;
40}
41
Steve Anton57858b32018-02-15 15:19:50 -080042std::string RTCCodecStatsIDFromMidDirectionAndPayload(const std::string& mid,
43 bool inbound,
44 uint32_t payload_type) {
Jonas Olsson43568dd2018-06-11 16:25:54 +020045 char buf[1024];
46 rtc::SimpleStringBuilder sb(buf);
47 sb << "RTCCodec_" << mid << (inbound ? "_Inbound_" : "_Outbound_")
48 << payload_type;
49 return sb.str();
hbos0adb8282016-11-23 02:32:06 -080050}
51
hbos2fa7c672016-10-24 04:00:05 -070052std::string RTCIceCandidatePairStatsIDFromConnectionInfo(
53 const cricket::ConnectionInfo& info) {
Jonas Olsson43568dd2018-06-11 16:25:54 +020054 char buf[4096];
55 rtc::SimpleStringBuilder sb(buf);
56 sb << "RTCIceCandidatePair_" << info.local_candidate.id() << "_"
57 << info.remote_candidate.id();
58 return sb.str();
hbos2fa7c672016-10-24 04:00:05 -070059}
60
Harald Alvestranda3dab842018-01-14 09:18:58 +010061const char kSender[] = "sender";
62const char kReceiver[] = "receiver";
63
64std::string RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
65 const char* direction,
Harald Alvestrandc72af932018-01-11 17:18:19 +010066 int attachment_id) {
Jonas Olsson43568dd2018-06-11 16:25:54 +020067 char buf[1024];
68 rtc::SimpleStringBuilder sb(buf);
69 sb << "RTCMediaStreamTrack_" << direction << "_" << attachment_id;
70 return sb.str();
hbos09bc1282016-11-08 06:29:22 -080071}
72
hbos2fa7c672016-10-24 04:00:05 -070073std::string RTCTransportStatsIDFromTransportChannel(
Jonas Olssona4d87372019-07-05 19:08:33 +020074 const std::string& transport_name,
75 int channel_component) {
Jonas Olsson43568dd2018-06-11 16:25:54 +020076 char buf[1024];
77 rtc::SimpleStringBuilder sb(buf);
78 sb << "RTCTransport_" << transport_name << "_" << channel_component;
79 return sb.str();
hbos2fa7c672016-10-24 04:00:05 -070080}
81
hboseeafe942016-11-01 03:00:17 -070082std::string RTCInboundRTPStreamStatsIDFromSSRC(bool audio, uint32_t ssrc) {
Jonas Olsson43568dd2018-06-11 16:25:54 +020083 char buf[1024];
84 rtc::SimpleStringBuilder sb(buf);
85 sb << "RTCInboundRTP" << (audio ? "Audio" : "Video") << "Stream_" << ssrc;
86 return sb.str();
hboseeafe942016-11-01 03:00:17 -070087}
88
hbos6ded1902016-11-01 01:50:46 -070089std::string RTCOutboundRTPStreamStatsIDFromSSRC(bool audio, uint32_t ssrc) {
Jonas Olsson43568dd2018-06-11 16:25:54 +020090 char buf[1024];
91 rtc::SimpleStringBuilder sb(buf);
92 sb << "RTCOutboundRTP" << (audio ? "Audio" : "Video") << "Stream_" << ssrc;
93 return sb.str();
hbos6ded1902016-11-01 01:50:46 -070094}
95
Henrik Boström8605fbf2019-06-24 16:44:51 +020096std::string RTCRemoteInboundRtpStreamStatsIdFromSourceSsrc(
Henrik Boström883eefc2019-05-27 13:40:25 +020097 cricket::MediaType media_type,
Henrik Boström883eefc2019-05-27 13:40:25 +020098 uint32_t source_ssrc) {
99 char buf[1024];
100 rtc::SimpleStringBuilder sb(buf);
101 sb << "RTCRemoteInboundRtp"
102 << (media_type == cricket::MEDIA_TYPE_AUDIO ? "Audio" : "Video")
Henrik Boström8605fbf2019-06-24 16:44:51 +0200103 << "Stream_" << source_ssrc;
Henrik Boström883eefc2019-05-27 13:40:25 +0200104 return sb.str();
105}
106
Henrik Boström646fda02019-05-22 15:49:42 +0200107std::string RTCMediaSourceStatsIDFromKindAndAttachment(
108 cricket::MediaType media_type,
109 int attachment_id) {
110 char buf[1024];
111 rtc::SimpleStringBuilder sb(buf);
112 sb << "RTC" << (media_type == cricket::MEDIA_TYPE_AUDIO ? "Audio" : "Video")
113 << "Source_" << attachment_id;
114 return sb.str();
115}
116
hbosab9f6e42016-10-07 02:18:47 -0700117const char* CandidateTypeToRTCIceCandidateType(const std::string& type) {
118 if (type == cricket::LOCAL_PORT_TYPE)
119 return RTCIceCandidateType::kHost;
120 if (type == cricket::STUN_PORT_TYPE)
121 return RTCIceCandidateType::kSrflx;
122 if (type == cricket::PRFLX_PORT_TYPE)
123 return RTCIceCandidateType::kPrflx;
124 if (type == cricket::RELAY_PORT_TYPE)
125 return RTCIceCandidateType::kRelay;
126 RTC_NOTREACHED();
127 return nullptr;
128}
129
hboscc555c52016-10-18 12:48:31 -0700130const char* DataStateToRTCDataChannelState(
131 DataChannelInterface::DataState state) {
132 switch (state) {
133 case DataChannelInterface::kConnecting:
134 return RTCDataChannelState::kConnecting;
135 case DataChannelInterface::kOpen:
136 return RTCDataChannelState::kOpen;
137 case DataChannelInterface::kClosing:
138 return RTCDataChannelState::kClosing;
139 case DataChannelInterface::kClosed:
140 return RTCDataChannelState::kClosed;
141 default:
142 RTC_NOTREACHED();
143 return nullptr;
144 }
145}
146
hbos06495bc2017-01-02 08:08:18 -0800147const char* IceCandidatePairStateToRTCStatsIceCandidatePairState(
148 cricket::IceCandidatePairState state) {
149 switch (state) {
150 case cricket::IceCandidatePairState::WAITING:
151 return RTCStatsIceCandidatePairState::kWaiting;
152 case cricket::IceCandidatePairState::IN_PROGRESS:
153 return RTCStatsIceCandidatePairState::kInProgress;
154 case cricket::IceCandidatePairState::SUCCEEDED:
155 return RTCStatsIceCandidatePairState::kSucceeded;
156 case cricket::IceCandidatePairState::FAILED:
157 return RTCStatsIceCandidatePairState::kFailed;
158 default:
159 RTC_NOTREACHED();
160 return nullptr;
161 }
162}
163
hbos7064d592017-01-16 07:38:02 -0800164const char* DtlsTransportStateToRTCDtlsTransportState(
165 cricket::DtlsTransportState state) {
166 switch (state) {
167 case cricket::DTLS_TRANSPORT_NEW:
168 return RTCDtlsTransportState::kNew;
169 case cricket::DTLS_TRANSPORT_CONNECTING:
170 return RTCDtlsTransportState::kConnecting;
171 case cricket::DTLS_TRANSPORT_CONNECTED:
172 return RTCDtlsTransportState::kConnected;
173 case cricket::DTLS_TRANSPORT_CLOSED:
174 return RTCDtlsTransportState::kClosed;
175 case cricket::DTLS_TRANSPORT_FAILED:
176 return RTCDtlsTransportState::kFailed;
177 default:
178 RTC_NOTREACHED();
179 return nullptr;
180 }
181}
182
Gary Liu37e489c2017-11-21 10:49:36 -0800183const char* NetworkAdapterTypeToStatsType(rtc::AdapterType type) {
184 switch (type) {
185 case rtc::ADAPTER_TYPE_CELLULAR:
186 return RTCNetworkType::kCellular;
187 case rtc::ADAPTER_TYPE_ETHERNET:
188 return RTCNetworkType::kEthernet;
189 case rtc::ADAPTER_TYPE_WIFI:
190 return RTCNetworkType::kWifi;
191 case rtc::ADAPTER_TYPE_VPN:
192 return RTCNetworkType::kVpn;
193 case rtc::ADAPTER_TYPE_UNKNOWN:
194 case rtc::ADAPTER_TYPE_LOOPBACK:
Qingsi Wang9f1de692018-06-28 15:38:09 -0700195 case rtc::ADAPTER_TYPE_ANY:
Gary Liu37e489c2017-11-21 10:49:36 -0800196 return RTCNetworkType::kUnknown;
197 }
198 RTC_NOTREACHED();
199 return nullptr;
200}
201
Henrik Boströmce33b6a2019-05-28 17:42:38 +0200202const char* QualityLimitationReasonToRTCQualityLimitationReason(
203 QualityLimitationReason reason) {
204 switch (reason) {
205 case QualityLimitationReason::kNone:
206 return RTCQualityLimitationReason::kNone;
207 case QualityLimitationReason::kCpu:
208 return RTCQualityLimitationReason::kCpu;
209 case QualityLimitationReason::kBandwidth:
210 return RTCQualityLimitationReason::kBandwidth;
211 case QualityLimitationReason::kOther:
212 return RTCQualityLimitationReason::kOther;
213 }
214}
215
hbos9e302742017-01-20 02:47:10 -0800216double DoubleAudioLevelFromIntAudioLevel(int audio_level) {
217 RTC_DCHECK_GE(audio_level, 0);
218 RTC_DCHECK_LE(audio_level, 32767);
219 return audio_level / 32767.0;
220}
221
hbos0adb8282016-11-23 02:32:06 -0800222std::unique_ptr<RTCCodecStats> CodecStatsFromRtpCodecParameters(
Steve Anton57858b32018-02-15 15:19:50 -0800223 uint64_t timestamp_us,
224 const std::string& mid,
225 bool inbound,
hbos0adb8282016-11-23 02:32:06 -0800226 const RtpCodecParameters& codec_params) {
227 RTC_DCHECK_GE(codec_params.payload_type, 0);
228 RTC_DCHECK_LE(codec_params.payload_type, 127);
deadbeefe702b302017-02-04 12:09:01 -0800229 RTC_DCHECK(codec_params.clock_rate);
hbos0adb8282016-11-23 02:32:06 -0800230 uint32_t payload_type = static_cast<uint32_t>(codec_params.payload_type);
231 std::unique_ptr<RTCCodecStats> codec_stats(new RTCCodecStats(
Steve Anton57858b32018-02-15 15:19:50 -0800232 RTCCodecStatsIDFromMidDirectionAndPayload(mid, inbound, payload_type),
hbos0adb8282016-11-23 02:32:06 -0800233 timestamp_us));
234 codec_stats->payload_type = payload_type;
hbos13f54b22017-02-28 06:56:04 -0800235 codec_stats->mime_type = codec_params.mime_type();
deadbeefe702b302017-02-04 12:09:01 -0800236 if (codec_params.clock_rate) {
237 codec_stats->clock_rate = static_cast<uint32_t>(*codec_params.clock_rate);
238 }
hbos0adb8282016-11-23 02:32:06 -0800239 return codec_stats;
240}
241
hbos09bc1282016-11-08 06:29:22 -0800242void SetMediaStreamTrackStatsFromMediaStreamTrackInterface(
243 const MediaStreamTrackInterface& track,
244 RTCMediaStreamTrackStats* track_stats) {
245 track_stats->track_identifier = track.id();
246 track_stats->ended = (track.state() == MediaStreamTrackInterface::kEnded);
247}
248
hbos820f5782016-11-22 03:16:50 -0800249// Provides the media independent counters (both audio and video).
hboseeafe942016-11-01 03:00:17 -0700250void SetInboundRTPStreamStatsFromMediaReceiverInfo(
251 const cricket::MediaReceiverInfo& media_receiver_info,
252 RTCInboundRTPStreamStats* inbound_stats) {
253 RTC_DCHECK(inbound_stats);
hbos3443bb72017-02-07 06:28:11 -0800254 inbound_stats->ssrc = media_receiver_info.ssrc();
Harald Alvestrand89061872018-01-02 14:08:34 +0100255 // TODO(hbos): Support the remote case. https://crbug.com/657855
hboseeafe942016-11-01 03:00:17 -0700256 inbound_stats->is_remote = false;
hboseeafe942016-11-01 03:00:17 -0700257 inbound_stats->packets_received =
258 static_cast<uint32_t>(media_receiver_info.packets_rcvd);
259 inbound_stats->bytes_received =
260 static_cast<uint64_t>(media_receiver_info.bytes_rcvd);
hbos02cd4d62016-12-09 04:19:44 -0800261 inbound_stats->packets_lost =
Harald Alvestrand719487e2017-12-13 12:26:04 +0100262 static_cast<int32_t>(media_receiver_info.packets_lost);
hboseeafe942016-11-01 03:00:17 -0700263}
264
265void SetInboundRTPStreamStatsFromVoiceReceiverInfo(
Steve Anton57858b32018-02-15 15:19:50 -0800266 const std::string& mid,
hboseeafe942016-11-01 03:00:17 -0700267 const cricket::VoiceReceiverInfo& voice_receiver_info,
hbos820f5782016-11-22 03:16:50 -0800268 RTCInboundRTPStreamStats* inbound_audio) {
Jonas Olssona4d87372019-07-05 19:08:33 +0200269 SetInboundRTPStreamStatsFromMediaReceiverInfo(voice_receiver_info,
270 inbound_audio);
hbos820f5782016-11-22 03:16:50 -0800271 inbound_audio->media_type = "audio";
Philipp Hancke3bc01662018-08-28 14:55:03 +0200272 inbound_audio->kind = "audio";
hbos585a9b12017-02-07 04:59:16 -0800273 if (voice_receiver_info.codec_payload_type) {
Steve Anton57858b32018-02-15 15:19:50 -0800274 inbound_audio->codec_id = RTCCodecStatsIDFromMidDirectionAndPayload(
275 mid, true, *voice_receiver_info.codec_payload_type);
hbos585a9b12017-02-07 04:59:16 -0800276 }
Jonas Olssona4d87372019-07-05 19:08:33 +0200277 inbound_audio->jitter = static_cast<double>(voice_receiver_info.jitter_ms) /
278 rtc::kNumMillisecsPerSec;
hbos820f5782016-11-22 03:16:50 -0800279 // |fir_count|, |pli_count| and |sli_count| are only valid for video and are
280 // purposefully left undefined for audio.
Henrik Boström01738c62019-04-15 17:32:00 +0200281 if (voice_receiver_info.last_packet_received_timestamp_ms) {
282 inbound_audio->last_packet_received_timestamp =
283 static_cast<double>(
284 *voice_receiver_info.last_packet_received_timestamp_ms) /
285 rtc::kNumMillisecsPerSec;
286 }
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200287 inbound_audio->fec_packets_received =
288 voice_receiver_info.fec_packets_received;
289 inbound_audio->fec_packets_discarded =
290 voice_receiver_info.fec_packets_discarded;
hboseeafe942016-11-01 03:00:17 -0700291}
292
293void SetInboundRTPStreamStatsFromVideoReceiverInfo(
Steve Anton57858b32018-02-15 15:19:50 -0800294 const std::string& mid,
hboseeafe942016-11-01 03:00:17 -0700295 const cricket::VideoReceiverInfo& video_receiver_info,
hbos820f5782016-11-22 03:16:50 -0800296 RTCInboundRTPStreamStats* inbound_video) {
Jonas Olssona4d87372019-07-05 19:08:33 +0200297 SetInboundRTPStreamStatsFromMediaReceiverInfo(video_receiver_info,
298 inbound_video);
hbos820f5782016-11-22 03:16:50 -0800299 inbound_video->media_type = "video";
Philipp Hancke3bc01662018-08-28 14:55:03 +0200300 inbound_video->kind = "video";
hbos585a9b12017-02-07 04:59:16 -0800301 if (video_receiver_info.codec_payload_type) {
Steve Anton57858b32018-02-15 15:19:50 -0800302 inbound_video->codec_id = RTCCodecStatsIDFromMidDirectionAndPayload(
303 mid, true, *video_receiver_info.codec_payload_type);
hbos585a9b12017-02-07 04:59:16 -0800304 }
hbos820f5782016-11-22 03:16:50 -0800305 inbound_video->fir_count =
306 static_cast<uint32_t>(video_receiver_info.firs_sent);
307 inbound_video->pli_count =
308 static_cast<uint32_t>(video_receiver_info.plis_sent);
309 inbound_video->nack_count =
310 static_cast<uint32_t>(video_receiver_info.nacks_sent);
hbos6769c492017-01-02 08:35:13 -0800311 inbound_video->frames_decoded = video_receiver_info.frames_decoded;
Rasmus Brandt2efae772019-06-27 14:29:34 +0200312 inbound_video->key_frames_decoded = video_receiver_info.key_frames_decoded;
hbosa51d4f32017-02-16 05:34:48 -0800313 if (video_receiver_info.qp_sum)
314 inbound_video->qp_sum = *video_receiver_info.qp_sum;
Johannes Kronbfd343b2019-07-01 10:07:50 +0200315 inbound_video->total_decode_time =
316 static_cast<double>(video_receiver_info.total_decode_time_ms) /
317 rtc::kNumMillisecsPerSec;
Henrik Boström01738c62019-04-15 17:32:00 +0200318 if (video_receiver_info.last_packet_received_timestamp_ms) {
319 inbound_video->last_packet_received_timestamp =
320 static_cast<double>(
321 *video_receiver_info.last_packet_received_timestamp_ms) /
322 rtc::kNumMillisecsPerSec;
323 }
Henrik Boström2e069262019-04-09 13:59:31 +0200324 // TODO(https://crbug.com/webrtc/10529): When info's |content_info| is
325 // optional, support the "unspecified" value.
326 if (video_receiver_info.content_type == VideoContentType::SCREENSHARE)
327 inbound_video->content_type = RTCContentType::kScreenshare;
hboseeafe942016-11-01 03:00:17 -0700328}
329
hbos820f5782016-11-22 03:16:50 -0800330// Provides the media independent counters (both audio and video).
hbos6ded1902016-11-01 01:50:46 -0700331void SetOutboundRTPStreamStatsFromMediaSenderInfo(
332 const cricket::MediaSenderInfo& media_sender_info,
333 RTCOutboundRTPStreamStats* outbound_stats) {
334 RTC_DCHECK(outbound_stats);
hbos3443bb72017-02-07 06:28:11 -0800335 outbound_stats->ssrc = media_sender_info.ssrc();
Harald Alvestrand89061872018-01-02 14:08:34 +0100336 // TODO(hbos): Support the remote case. https://crbug.com/657856
hbos6ded1902016-11-01 01:50:46 -0700337 outbound_stats->is_remote = false;
hbos6ded1902016-11-01 01:50:46 -0700338 outbound_stats->packets_sent =
339 static_cast<uint32_t>(media_sender_info.packets_sent);
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200340 outbound_stats->retransmitted_packets_sent =
341 media_sender_info.retransmitted_packets_sent;
hbos6ded1902016-11-01 01:50:46 -0700342 outbound_stats->bytes_sent =
343 static_cast<uint64_t>(media_sender_info.bytes_sent);
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200344 outbound_stats->retransmitted_bytes_sent =
345 media_sender_info.retransmitted_bytes_sent;
hbos6ded1902016-11-01 01:50:46 -0700346}
347
348void SetOutboundRTPStreamStatsFromVoiceSenderInfo(
Steve Anton57858b32018-02-15 15:19:50 -0800349 const std::string& mid,
hbos6ded1902016-11-01 01:50:46 -0700350 const cricket::VoiceSenderInfo& voice_sender_info,
351 RTCOutboundRTPStreamStats* outbound_audio) {
Jonas Olssona4d87372019-07-05 19:08:33 +0200352 SetOutboundRTPStreamStatsFromMediaSenderInfo(voice_sender_info,
353 outbound_audio);
hbos6ded1902016-11-01 01:50:46 -0700354 outbound_audio->media_type = "audio";
Philipp Hancke3bc01662018-08-28 14:55:03 +0200355 outbound_audio->kind = "audio";
hbos585a9b12017-02-07 04:59:16 -0800356 if (voice_sender_info.codec_payload_type) {
Steve Anton57858b32018-02-15 15:19:50 -0800357 outbound_audio->codec_id = RTCCodecStatsIDFromMidDirectionAndPayload(
358 mid, false, *voice_sender_info.codec_payload_type);
hbos585a9b12017-02-07 04:59:16 -0800359 }
hbos6ded1902016-11-01 01:50:46 -0700360 // |fir_count|, |pli_count| and |sli_count| are only valid for video and are
361 // purposefully left undefined for audio.
362}
363
364void SetOutboundRTPStreamStatsFromVideoSenderInfo(
Steve Anton57858b32018-02-15 15:19:50 -0800365 const std::string& mid,
hbos6ded1902016-11-01 01:50:46 -0700366 const cricket::VideoSenderInfo& video_sender_info,
367 RTCOutboundRTPStreamStats* outbound_video) {
Jonas Olssona4d87372019-07-05 19:08:33 +0200368 SetOutboundRTPStreamStatsFromMediaSenderInfo(video_sender_info,
369 outbound_video);
hbos6ded1902016-11-01 01:50:46 -0700370 outbound_video->media_type = "video";
Philipp Hancke3bc01662018-08-28 14:55:03 +0200371 outbound_video->kind = "video";
hbos585a9b12017-02-07 04:59:16 -0800372 if (video_sender_info.codec_payload_type) {
Steve Anton57858b32018-02-15 15:19:50 -0800373 outbound_video->codec_id = RTCCodecStatsIDFromMidDirectionAndPayload(
374 mid, false, *video_sender_info.codec_payload_type);
hbos585a9b12017-02-07 04:59:16 -0800375 }
hbos6ded1902016-11-01 01:50:46 -0700376 outbound_video->fir_count =
377 static_cast<uint32_t>(video_sender_info.firs_rcvd);
378 outbound_video->pli_count =
379 static_cast<uint32_t>(video_sender_info.plis_rcvd);
380 outbound_video->nack_count =
381 static_cast<uint32_t>(video_sender_info.nacks_rcvd);
hbos6769c492017-01-02 08:35:13 -0800382 if (video_sender_info.qp_sum)
383 outbound_video->qp_sum = *video_sender_info.qp_sum;
384 outbound_video->frames_encoded = video_sender_info.frames_encoded;
Rasmus Brandt2efae772019-06-27 14:29:34 +0200385 outbound_video->key_frames_encoded = video_sender_info.key_frames_encoded;
Henrik Boströmf71362f2019-04-08 16:14:23 +0200386 outbound_video->total_encode_time =
387 static_cast<double>(video_sender_info.total_encode_time_ms) /
388 rtc::kNumMillisecsPerSec;
Henrik Boström23aff9b2019-05-20 15:15:38 +0200389 outbound_video->total_encoded_bytes_target =
390 video_sender_info.total_encoded_bytes_target;
Henrik Boström9fe18342019-05-16 18:38:20 +0200391 outbound_video->total_packet_send_delay =
392 static_cast<double>(video_sender_info.total_packet_send_delay_ms) /
393 rtc::kNumMillisecsPerSec;
Henrik Boströmce33b6a2019-05-28 17:42:38 +0200394 outbound_video->quality_limitation_reason =
395 QualityLimitationReasonToRTCQualityLimitationReason(
396 video_sender_info.quality_limitation_reason);
Henrik Boström2e069262019-04-09 13:59:31 +0200397 // TODO(https://crbug.com/webrtc/10529): When info's |content_info| is
398 // optional, support the "unspecified" value.
399 if (video_sender_info.content_type == VideoContentType::SCREENSHARE)
400 outbound_video->content_type = RTCContentType::kScreenshare;
hbos6ded1902016-11-01 01:50:46 -0700401}
402
Henrik Boström883eefc2019-05-27 13:40:25 +0200403std::unique_ptr<RTCRemoteInboundRtpStreamStats>
404ProduceRemoteInboundRtpStreamStatsFromReportBlockData(
405 const ReportBlockData& report_block_data,
406 cricket::MediaType media_type,
407 const RTCStatsReport& report) {
408 const auto& report_block = report_block_data.report_block();
409 // RTCStats' timestamp generally refers to when the metric was sampled, but
410 // for "remote-[outbound/inbound]-rtp" it refers to the local time when the
411 // Report Block was received.
412 auto remote_inbound = absl::make_unique<RTCRemoteInboundRtpStreamStats>(
Henrik Boström8605fbf2019-06-24 16:44:51 +0200413 RTCRemoteInboundRtpStreamStatsIdFromSourceSsrc(media_type,
414 report_block.source_ssrc),
Henrik Boström883eefc2019-05-27 13:40:25 +0200415 /*timestamp=*/report_block_data.report_block_timestamp_utc_us());
Henrik Boström8605fbf2019-06-24 16:44:51 +0200416 remote_inbound->ssrc = report_block.source_ssrc;
Henrik Boström883eefc2019-05-27 13:40:25 +0200417 remote_inbound->kind =
418 media_type == cricket::MEDIA_TYPE_AUDIO ? "audio" : "video";
419 remote_inbound->packets_lost = report_block.packets_lost;
420 remote_inbound->round_trip_time =
421 static_cast<double>(report_block_data.last_rtt_ms()) /
422 rtc::kNumMillisecsPerSec;
423
424 std::string local_id = RTCOutboundRTPStreamStatsIDFromSSRC(
425 media_type == cricket::MEDIA_TYPE_AUDIO, report_block.source_ssrc);
426 const auto* local_id_stat = report.Get(local_id);
427 if (local_id_stat) {
428 remote_inbound->local_id = local_id;
429 const auto& outbound_rtp =
430 local_id_stat->cast_to<RTCOutboundRTPStreamStats>();
431 // The RTP/RTCP transport is obtained from the
432 // RTCOutboundRtpStreamStats's transport.
433 const auto* transport_from_id = outbound_rtp.transport_id.is_defined()
434 ? report.Get(*outbound_rtp.transport_id)
435 : nullptr;
436 if (transport_from_id) {
437 const auto& transport = transport_from_id->cast_to<RTCTransportStats>();
438 // If RTP and RTCP are not multiplexed, there is a separate RTCP
439 // transport paired with the RTP transport, otherwise the same
440 // transport is used for RTCP and RTP.
441 remote_inbound->transport_id =
442 transport.rtcp_transport_stats_id.is_defined()
443 ? *transport.rtcp_transport_stats_id
444 : *outbound_rtp.transport_id;
445 }
446 // We're assuming the same codec is used on both ends. However if the
447 // codec is switched out on the fly we may have received a Report Block
448 // based on the previous codec and there is no way to tell which point in
449 // time the codec changed for the remote end.
450 const auto* codec_from_id = outbound_rtp.codec_id.is_defined()
451 ? report.Get(*outbound_rtp.codec_id)
452 : nullptr;
453 if (codec_from_id) {
454 remote_inbound->codec_id = *outbound_rtp.codec_id;
455 const auto& codec = codec_from_id->cast_to<RTCCodecStats>();
456 if (codec.clock_rate.is_defined()) {
457 // The Report Block jitter is expressed in RTP timestamp units
458 // (https://tools.ietf.org/html/rfc3550#section-6.4.1). To convert this
459 // to seconds we divide by the codec's clock rate.
460 remote_inbound->jitter =
461 static_cast<double>(report_block.jitter) / *codec.clock_rate;
462 }
463 }
464 }
465 return remote_inbound;
466}
467
hbos02ba2112016-10-28 05:14:53 -0700468void ProduceCertificateStatsFromSSLCertificateStats(
Jonas Olssona4d87372019-07-05 19:08:33 +0200469 int64_t timestamp_us,
470 const rtc::SSLCertificateStats& certificate_stats,
hbos02ba2112016-10-28 05:14:53 -0700471 RTCStatsReport* report) {
472 RTCCertificateStats* prev_certificate_stats = nullptr;
473 for (const rtc::SSLCertificateStats* s = &certificate_stats; s;
474 s = s->issuer.get()) {
hbos02d2a922016-12-21 01:29:05 -0800475 std::string certificate_stats_id =
476 RTCCertificateIDFromFingerprint(s->fingerprint);
477 // It is possible for the same certificate to show up multiple times, e.g.
478 // if local and remote side use the same certificate in a loopback call.
479 // If the report already contains stats for this certificate, skip it.
480 if (report->Get(certificate_stats_id)) {
481 RTC_DCHECK_EQ(s, &certificate_stats);
482 break;
483 }
Jonas Olssona4d87372019-07-05 19:08:33 +0200484 RTCCertificateStats* certificate_stats =
485 new RTCCertificateStats(certificate_stats_id, timestamp_us);
hbos02ba2112016-10-28 05:14:53 -0700486 certificate_stats->fingerprint = s->fingerprint;
487 certificate_stats->fingerprint_algorithm = s->fingerprint_algorithm;
488 certificate_stats->base64_certificate = s->base64_certificate;
489 if (prev_certificate_stats)
490 prev_certificate_stats->issuer_certificate_id = certificate_stats->id();
491 report->AddStats(std::unique_ptr<RTCCertificateStats>(certificate_stats));
492 prev_certificate_stats = certificate_stats;
493 }
494}
495
Jonas Olssona4d87372019-07-05 19:08:33 +0200496const std::string& ProduceIceCandidateStats(int64_t timestamp_us,
497 const cricket::Candidate& candidate,
498 bool is_local,
499 const std::string& transport_id,
500 RTCStatsReport* report) {
hbos02ba2112016-10-28 05:14:53 -0700501 const std::string& id = "RTCIceCandidate_" + candidate.id();
502 const RTCStats* stats = report->Get(id);
503 if (!stats) {
504 std::unique_ptr<RTCIceCandidateStats> candidate_stats;
505 if (is_local)
506 candidate_stats.reset(new RTCLocalIceCandidateStats(id, timestamp_us));
507 else
508 candidate_stats.reset(new RTCRemoteIceCandidateStats(id, timestamp_us));
hbosb4e426e2017-01-02 09:59:31 -0800509 candidate_stats->transport_id = transport_id;
Gary Liu37e489c2017-11-21 10:49:36 -0800510 if (is_local) {
511 candidate_stats->network_type =
512 NetworkAdapterTypeToStatsType(candidate.network_type());
Philipp Hancke95513752018-09-27 14:40:08 +0200513 if (candidate.type() == cricket::RELAY_PORT_TYPE) {
514 std::string relay_protocol = candidate.relay_protocol();
515 RTC_DCHECK(relay_protocol.compare("udp") == 0 ||
516 relay_protocol.compare("tcp") == 0 ||
517 relay_protocol.compare("tls") == 0);
518 candidate_stats->relay_protocol = relay_protocol;
519 }
Gary Liu37e489c2017-11-21 10:49:36 -0800520 } else {
521 // We don't expect to know the adapter type of remote candidates.
522 RTC_DCHECK_EQ(rtc::ADAPTER_TYPE_UNKNOWN, candidate.network_type());
523 }
hbos02ba2112016-10-28 05:14:53 -0700524 candidate_stats->ip = candidate.address().ipaddr().ToString();
525 candidate_stats->port = static_cast<int32_t>(candidate.address().port());
526 candidate_stats->protocol = candidate.protocol();
Jonas Olssona4d87372019-07-05 19:08:33 +0200527 candidate_stats->candidate_type =
528 CandidateTypeToRTCIceCandidateType(candidate.type());
hbos02ba2112016-10-28 05:14:53 -0700529 candidate_stats->priority = static_cast<int32_t>(candidate.priority());
530
531 stats = candidate_stats.get();
532 report->AddStats(std::move(candidate_stats));
533 }
534 RTC_DCHECK_EQ(stats->type(), is_local ? RTCLocalIceCandidateStats::kType
535 : RTCRemoteIceCandidateStats::kType);
536 return stats->id();
537}
538
hbos9e302742017-01-20 02:47:10 -0800539std::unique_ptr<RTCMediaStreamTrackStats>
540ProduceMediaStreamTrackStatsFromVoiceSenderInfo(
541 int64_t timestamp_us,
542 const AudioTrackInterface& audio_track,
Harald Alvestrandc72af932018-01-11 17:18:19 +0100543 const cricket::VoiceSenderInfo& voice_sender_info,
544 int attachment_id) {
hbos9e302742017-01-20 02:47:10 -0800545 std::unique_ptr<RTCMediaStreamTrackStats> audio_track_stats(
546 new RTCMediaStreamTrackStats(
Harald Alvestranda3dab842018-01-14 09:18:58 +0100547 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(kSender,
548 attachment_id),
Harald Alvestrandc72af932018-01-11 17:18:19 +0100549 timestamp_us, RTCMediaStreamTrackKind::kAudio));
hbos9e302742017-01-20 02:47:10 -0800550 SetMediaStreamTrackStatsFromMediaStreamTrackInterface(
551 audio_track, audio_track_stats.get());
Henrik Boström646fda02019-05-22 15:49:42 +0200552 audio_track_stats->media_source_id =
553 RTCMediaSourceStatsIDFromKindAndAttachment(cricket::MEDIA_TYPE_AUDIO,
554 attachment_id);
hbos9e302742017-01-20 02:47:10 -0800555 audio_track_stats->remote_source = false;
556 audio_track_stats->detached = false;
Ivo Creusen56d46092017-11-24 17:29:59 +0100557 if (voice_sender_info.apm_statistics.echo_return_loss) {
558 audio_track_stats->echo_return_loss =
559 *voice_sender_info.apm_statistics.echo_return_loss;
hbos9e302742017-01-20 02:47:10 -0800560 }
Ivo Creusen56d46092017-11-24 17:29:59 +0100561 if (voice_sender_info.apm_statistics.echo_return_loss_enhancement) {
562 audio_track_stats->echo_return_loss_enhancement =
563 *voice_sender_info.apm_statistics.echo_return_loss_enhancement;
hbos9e302742017-01-20 02:47:10 -0800564 }
565 return audio_track_stats;
566}
567
568std::unique_ptr<RTCMediaStreamTrackStats>
569ProduceMediaStreamTrackStatsFromVoiceReceiverInfo(
570 int64_t timestamp_us,
571 const AudioTrackInterface& audio_track,
Harald Alvestrandc72af932018-01-11 17:18:19 +0100572 const cricket::VoiceReceiverInfo& voice_receiver_info,
573 int attachment_id) {
574 // Since receiver tracks can't be reattached, we use the SSRC as
575 // an attachment identifier.
hbos9e302742017-01-20 02:47:10 -0800576 std::unique_ptr<RTCMediaStreamTrackStats> audio_track_stats(
577 new RTCMediaStreamTrackStats(
Harald Alvestranda3dab842018-01-14 09:18:58 +0100578 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(kReceiver,
579 attachment_id),
Harald Alvestrandc72af932018-01-11 17:18:19 +0100580 timestamp_us, RTCMediaStreamTrackKind::kAudio));
hbos9e302742017-01-20 02:47:10 -0800581 SetMediaStreamTrackStatsFromMediaStreamTrackInterface(
582 audio_track, audio_track_stats.get());
583 audio_track_stats->remote_source = true;
584 audio_track_stats->detached = false;
585 if (voice_receiver_info.audio_level >= 0) {
Jonas Olssona4d87372019-07-05 19:08:33 +0200586 audio_track_stats->audio_level =
587 DoubleAudioLevelFromIntAudioLevel(voice_receiver_info.audio_level);
hbos9e302742017-01-20 02:47:10 -0800588 }
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200589 audio_track_stats->jitter_buffer_delay =
590 voice_receiver_info.jitter_buffer_delay_seconds;
Chen Xing0acffb52019-01-15 15:46:29 +0100591 audio_track_stats->jitter_buffer_emitted_count =
592 voice_receiver_info.jitter_buffer_emitted_count;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200593 audio_track_stats->inserted_samples_for_deceleration =
594 voice_receiver_info.inserted_samples_for_deceleration;
595 audio_track_stats->removed_samples_for_acceleration =
596 voice_receiver_info.removed_samples_for_acceleration;
zsteine76bd3a2017-07-14 12:17:49 -0700597 audio_track_stats->total_audio_energy =
598 voice_receiver_info.total_output_energy;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700599 audio_track_stats->total_samples_received =
600 voice_receiver_info.total_samples_received;
zsteine76bd3a2017-07-14 12:17:49 -0700601 audio_track_stats->total_samples_duration =
602 voice_receiver_info.total_output_duration;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700603 audio_track_stats->concealed_samples = voice_receiver_info.concealed_samples;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200604 audio_track_stats->silent_concealed_samples =
605 voice_receiver_info.silent_concealed_samples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200606 audio_track_stats->concealment_events =
607 voice_receiver_info.concealment_events;
Ruslan Burakov8af88962018-11-22 17:21:10 +0100608 audio_track_stats->jitter_buffer_flushes =
609 voice_receiver_info.jitter_buffer_flushes;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100610 audio_track_stats->delayed_packet_outage_samples =
611 voice_receiver_info.delayed_packet_outage_samples;
Jakob Ivarsson232b3fd2019-03-06 09:18:40 +0100612 audio_track_stats->relative_packet_arrival_delay =
613 voice_receiver_info.relative_packet_arrival_delay_seconds;
Henrik Lundin44125fa2019-04-29 17:00:46 +0200614 audio_track_stats->interruption_count =
615 voice_receiver_info.interruption_count >= 0
616 ? voice_receiver_info.interruption_count
617 : 0;
618 audio_track_stats->total_interruption_duration =
619 static_cast<double>(voice_receiver_info.total_interruption_duration_ms) /
620 rtc::kNumMillisecsPerSec;
hbos9e302742017-01-20 02:47:10 -0800621 return audio_track_stats;
622}
623
624std::unique_ptr<RTCMediaStreamTrackStats>
625ProduceMediaStreamTrackStatsFromVideoSenderInfo(
626 int64_t timestamp_us,
627 const VideoTrackInterface& video_track,
Harald Alvestrandc72af932018-01-11 17:18:19 +0100628 const cricket::VideoSenderInfo& video_sender_info,
629 int attachment_id) {
hbos9e302742017-01-20 02:47:10 -0800630 std::unique_ptr<RTCMediaStreamTrackStats> video_track_stats(
631 new RTCMediaStreamTrackStats(
Harald Alvestranda3dab842018-01-14 09:18:58 +0100632 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(kSender,
Harald Alvestranda3dab842018-01-14 09:18:58 +0100633 attachment_id),
Harald Alvestrandc72af932018-01-11 17:18:19 +0100634 timestamp_us, RTCMediaStreamTrackKind::kVideo));
hbos9e302742017-01-20 02:47:10 -0800635 SetMediaStreamTrackStatsFromMediaStreamTrackInterface(
636 video_track, video_track_stats.get());
Henrik Boström646fda02019-05-22 15:49:42 +0200637 video_track_stats->media_source_id =
638 RTCMediaSourceStatsIDFromKindAndAttachment(cricket::MEDIA_TYPE_VIDEO,
639 attachment_id);
hbos9e302742017-01-20 02:47:10 -0800640 video_track_stats->remote_source = false;
641 video_track_stats->detached = false;
Jonas Olssona4d87372019-07-05 19:08:33 +0200642 video_track_stats->frame_width =
643 static_cast<uint32_t>(video_sender_info.send_frame_width);
644 video_track_stats->frame_height =
645 static_cast<uint32_t>(video_sender_info.send_frame_height);
hbosfefe0762017-01-20 06:14:25 -0800646 // TODO(hbos): Will reduce this by frames dropped due to congestion control
Harald Alvestrand89061872018-01-02 14:08:34 +0100647 // when available. https://crbug.com/659137
hbosfefe0762017-01-20 06:14:25 -0800648 video_track_stats->frames_sent = video_sender_info.frames_encoded;
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100649 video_track_stats->huge_frames_sent = video_sender_info.huge_frames_sent;
hbos9e302742017-01-20 02:47:10 -0800650 return video_track_stats;
651}
652
653std::unique_ptr<RTCMediaStreamTrackStats>
654ProduceMediaStreamTrackStatsFromVideoReceiverInfo(
655 int64_t timestamp_us,
656 const VideoTrackInterface& video_track,
Harald Alvestrandc72af932018-01-11 17:18:19 +0100657 const cricket::VideoReceiverInfo& video_receiver_info,
658 int attachment_id) {
hbos9e302742017-01-20 02:47:10 -0800659 std::unique_ptr<RTCMediaStreamTrackStats> video_track_stats(
660 new RTCMediaStreamTrackStats(
Harald Alvestranda3dab842018-01-14 09:18:58 +0100661 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(kReceiver,
662
663 attachment_id),
Harald Alvestrandc72af932018-01-11 17:18:19 +0100664 timestamp_us, RTCMediaStreamTrackKind::kVideo));
hbos9e302742017-01-20 02:47:10 -0800665 SetMediaStreamTrackStatsFromMediaStreamTrackInterface(
666 video_track, video_track_stats.get());
667 video_track_stats->remote_source = true;
668 video_track_stats->detached = false;
669 if (video_receiver_info.frame_width > 0 &&
670 video_receiver_info.frame_height > 0) {
Jonas Olssona4d87372019-07-05 19:08:33 +0200671 video_track_stats->frame_width =
672 static_cast<uint32_t>(video_receiver_info.frame_width);
673 video_track_stats->frame_height =
674 static_cast<uint32_t>(video_receiver_info.frame_height);
hbos9e302742017-01-20 02:47:10 -0800675 }
Guido Urdaneta67378412019-05-28 17:38:08 +0200676 video_track_stats->jitter_buffer_delay =
677 video_receiver_info.jitter_buffer_delay_seconds;
678 video_track_stats->jitter_buffer_emitted_count =
679 video_receiver_info.jitter_buffer_emitted_count;
hbos42f6d2f2017-01-20 03:56:50 -0800680 video_track_stats->frames_received = video_receiver_info.frames_received;
hbosf64941f2017-01-20 07:39:09 -0800681 // TODO(hbos): When we support receiving simulcast, this should be the total
682 // number of frames correctly decoded, independent of which SSRC it was
683 // received from. Since we don't support that, this is correct and is the same
Harald Alvestrand89061872018-01-02 14:08:34 +0100684 // value as "RTCInboundRTPStreamStats.framesDecoded". https://crbug.com/659137
hbosf64941f2017-01-20 07:39:09 -0800685 video_track_stats->frames_decoded = video_receiver_info.frames_decoded;
hbos50cfe1f2017-01-23 07:21:55 -0800686 RTC_DCHECK_GE(video_receiver_info.frames_received,
687 video_receiver_info.frames_rendered);
Jonas Olssona4d87372019-07-05 19:08:33 +0200688 video_track_stats->frames_dropped =
689 video_receiver_info.frames_received - video_receiver_info.frames_rendered;
Sergey Silkin02371062019-01-31 16:45:42 +0100690 video_track_stats->freeze_count = video_receiver_info.freeze_count;
691 video_track_stats->pause_count = video_receiver_info.pause_count;
692 video_track_stats->total_freezes_duration =
693 static_cast<double>(video_receiver_info.total_freezes_duration_ms) /
694 rtc::kNumMillisecsPerSec;
695 video_track_stats->total_pauses_duration =
696 static_cast<double>(video_receiver_info.total_pauses_duration_ms) /
697 rtc::kNumMillisecsPerSec;
698 video_track_stats->total_frames_duration =
699 static_cast<double>(video_receiver_info.total_frames_duration_ms) /
700 rtc::kNumMillisecsPerSec;
701 video_track_stats->sum_squared_frame_durations =
702 video_receiver_info.sum_squared_frame_durations;
703
hbos9e302742017-01-20 02:47:10 -0800704 return video_track_stats;
705}
706
Harald Alvestrand89061872018-01-02 14:08:34 +0100707void ProduceSenderMediaTrackStats(
708 int64_t timestamp_us,
709 const TrackMediaInfoMap& track_media_info_map,
Steve Anton57858b32018-02-15 15:19:50 -0800710 std::vector<rtc::scoped_refptr<RtpSenderInternal>> senders,
Harald Alvestrand89061872018-01-02 14:08:34 +0100711 RTCStatsReport* report) {
712 // This function iterates over the senders to generate outgoing track stats.
713
714 // TODO(hbos): Return stats of detached tracks. We have to perform stats
715 // gathering at the time of detachment to get accurate stats and timestamps.
716 // https://crbug.com/659137
Mirko Bonadei739baf02019-01-27 17:29:42 +0100717 for (const auto& sender : senders) {
Harald Alvestrand89061872018-01-02 14:08:34 +0100718 if (sender->media_type() == cricket::MEDIA_TYPE_AUDIO) {
719 AudioTrackInterface* track =
720 static_cast<AudioTrackInterface*>(sender->track().get());
721 if (!track)
722 continue;
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100723 cricket::VoiceSenderInfo null_sender_info;
724 const cricket::VoiceSenderInfo* voice_sender_info = &null_sender_info;
725 // TODO(hta): Checking on ssrc is not proper. There should be a way
726 // to see from a sender whether it's connected or not.
727 // Related to https://crbug.com/8694 (using ssrc 0 to indicate "none")
Steve Anton57858b32018-02-15 15:19:50 -0800728 if (sender->ssrc() != 0) {
Harald Alvestrand76d29522018-01-30 14:43:29 +0100729 // When pc.close is called, sender info is discarded, so
730 // we generate zeroes instead. Bug: It should be retained.
731 // https://crbug.com/807174
Steve Anton57858b32018-02-15 15:19:50 -0800732 const cricket::VoiceSenderInfo* sender_info =
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100733 track_media_info_map.GetVoiceSenderInfoBySsrc(sender->ssrc());
Harald Alvestrand76d29522018-01-30 14:43:29 +0100734 if (sender_info) {
735 voice_sender_info = sender_info;
736 } else {
737 RTC_LOG(LS_INFO)
738 << "RTCStatsCollector: No voice sender info for sender with ssrc "
739 << sender->ssrc();
740 }
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100741 }
Harald Alvestrand89061872018-01-02 14:08:34 +0100742 std::unique_ptr<RTCMediaStreamTrackStats> audio_track_stats =
Harald Alvestrandc72af932018-01-11 17:18:19 +0100743 ProduceMediaStreamTrackStatsFromVoiceSenderInfo(
744 timestamp_us, *track, *voice_sender_info, sender->AttachmentId());
Harald Alvestrand89061872018-01-02 14:08:34 +0100745 report->AddStats(std::move(audio_track_stats));
746 } else if (sender->media_type() == cricket::MEDIA_TYPE_VIDEO) {
747 VideoTrackInterface* track =
748 static_cast<VideoTrackInterface*>(sender->track().get());
749 if (!track)
750 continue;
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100751 cricket::VideoSenderInfo null_sender_info;
752 const cricket::VideoSenderInfo* video_sender_info = &null_sender_info;
753 // TODO(hta): Check on state not ssrc when state is available
Harald Alvestrand76d29522018-01-30 14:43:29 +0100754 // Related to https://bugs.webrtc.org/8694 (using ssrc 0 to indicate
755 // "none")
Steve Anton57858b32018-02-15 15:19:50 -0800756 if (sender->ssrc() != 0) {
Harald Alvestrand76d29522018-01-30 14:43:29 +0100757 // When pc.close is called, sender info is discarded, so
758 // we generate zeroes instead. Bug: It should be retained.
759 // https://crbug.com/807174
Steve Anton57858b32018-02-15 15:19:50 -0800760 const cricket::VideoSenderInfo* sender_info =
Harald Alvestrandb8e12012018-01-23 15:28:16 +0100761 track_media_info_map.GetVideoSenderInfoBySsrc(sender->ssrc());
Harald Alvestrand76d29522018-01-30 14:43:29 +0100762 if (sender_info) {
763 video_sender_info = sender_info;
764 } else {
765 RTC_LOG(LS_INFO) << "No video sender info for sender with ssrc "
766 << sender->ssrc();
767 }
768 }
Harald Alvestrand89061872018-01-02 14:08:34 +0100769 std::unique_ptr<RTCMediaStreamTrackStats> video_track_stats =
Harald Alvestrandc72af932018-01-11 17:18:19 +0100770 ProduceMediaStreamTrackStatsFromVideoSenderInfo(
771 timestamp_us, *track, *video_sender_info, sender->AttachmentId());
Harald Alvestrand89061872018-01-02 14:08:34 +0100772 report->AddStats(std::move(video_track_stats));
773 } else {
774 RTC_NOTREACHED();
775 }
776 }
777}
778
779void ProduceReceiverMediaTrackStats(
780 int64_t timestamp_us,
781 const TrackMediaInfoMap& track_media_info_map,
Steve Anton57858b32018-02-15 15:19:50 -0800782 std::vector<rtc::scoped_refptr<RtpReceiverInternal>> receivers,
Harald Alvestrand89061872018-01-02 14:08:34 +0100783 RTCStatsReport* report) {
784 // This function iterates over the receivers to find the remote tracks.
Mirko Bonadei739baf02019-01-27 17:29:42 +0100785 for (const auto& receiver : receivers) {
Harald Alvestrand89061872018-01-02 14:08:34 +0100786 if (receiver->media_type() == cricket::MEDIA_TYPE_AUDIO) {
787 AudioTrackInterface* track =
788 static_cast<AudioTrackInterface*>(receiver->track().get());
789 const cricket::VoiceReceiverInfo* voice_receiver_info =
790 track_media_info_map.GetVoiceReceiverInfo(*track);
791 if (!voice_receiver_info) {
792 continue;
793 }
794 std::unique_ptr<RTCMediaStreamTrackStats> audio_track_stats =
795 ProduceMediaStreamTrackStatsFromVoiceReceiverInfo(
Harald Alvestrandc72af932018-01-11 17:18:19 +0100796 timestamp_us, *track, *voice_receiver_info,
797 receiver->AttachmentId());
Harald Alvestrand89061872018-01-02 14:08:34 +0100798 report->AddStats(std::move(audio_track_stats));
799 } else if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) {
800 VideoTrackInterface* track =
801 static_cast<VideoTrackInterface*>(receiver->track().get());
802 const cricket::VideoReceiverInfo* video_receiver_info =
803 track_media_info_map.GetVideoReceiverInfo(*track);
804 if (!video_receiver_info) {
805 continue;
806 }
807 std::unique_ptr<RTCMediaStreamTrackStats> video_track_stats =
808 ProduceMediaStreamTrackStatsFromVideoReceiverInfo(
Harald Alvestrandc72af932018-01-11 17:18:19 +0100809 timestamp_us, *track, *video_receiver_info,
810 receiver->AttachmentId());
Harald Alvestrand89061872018-01-02 14:08:34 +0100811 report->AddStats(std::move(video_track_stats));
812 } else {
813 RTC_NOTREACHED();
814 }
815 }
816}
817
Henrik Boström5b3541f2018-03-19 13:52:56 +0100818rtc::scoped_refptr<RTCStatsReport> CreateReportFilteredBySelector(
819 bool filter_by_sender_selector,
820 rtc::scoped_refptr<const RTCStatsReport> report,
821 rtc::scoped_refptr<RtpSenderInternal> sender_selector,
822 rtc::scoped_refptr<RtpReceiverInternal> receiver_selector) {
823 std::vector<std::string> rtpstream_ids;
824 if (filter_by_sender_selector) {
825 // Filter mode: RTCStatsCollector::RequestInfo::kSenderSelector
826 if (sender_selector) {
827 // Find outbound-rtp(s) of the sender, i.e. the outbound-rtp(s) that
828 // reference the sender stats.
829 // Because we do not implement sender stats, we look at outbound-rtp(s)
830 // that reference the track attachment stats for the sender instead.
831 std::string track_id =
832 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
833 kSender, sender_selector->AttachmentId());
834 for (const auto& stats : *report) {
835 if (stats.type() != RTCOutboundRTPStreamStats::kType)
836 continue;
837 const auto& outbound_rtp = stats.cast_to<RTCOutboundRTPStreamStats>();
838 if (outbound_rtp.track_id.is_defined() &&
839 *outbound_rtp.track_id == track_id) {
840 rtpstream_ids.push_back(outbound_rtp.id());
841 }
842 }
843 }
844 } else {
845 // Filter mode: RTCStatsCollector::RequestInfo::kReceiverSelector
846 if (receiver_selector) {
847 // Find inbound-rtp(s) of the receiver, i.e. the inbound-rtp(s) that
848 // reference the receiver stats.
849 // Because we do not implement receiver stats, we look at inbound-rtp(s)
850 // that reference the track attachment stats for the receiver instead.
851 std::string track_id =
852 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
853 kReceiver, receiver_selector->AttachmentId());
854 for (const auto& stats : *report) {
855 if (stats.type() != RTCInboundRTPStreamStats::kType)
856 continue;
857 const auto& inbound_rtp = stats.cast_to<RTCInboundRTPStreamStats>();
858 if (inbound_rtp.track_id.is_defined() &&
859 *inbound_rtp.track_id == track_id) {
860 rtpstream_ids.push_back(inbound_rtp.id());
861 }
862 }
863 }
864 }
865 if (rtpstream_ids.empty())
866 return RTCStatsReport::Create(report->timestamp_us());
867 return TakeReferencedStats(report->Copy(), rtpstream_ids);
868}
869
hboscc555c52016-10-18 12:48:31 -0700870} // namespace
871
Henrik Boström5b3541f2018-03-19 13:52:56 +0100872RTCStatsCollector::RequestInfo::RequestInfo(
873 rtc::scoped_refptr<RTCStatsCollectorCallback> callback)
874 : RequestInfo(FilterMode::kAll, std::move(callback), nullptr, nullptr) {}
875
876RTCStatsCollector::RequestInfo::RequestInfo(
877 rtc::scoped_refptr<RtpSenderInternal> selector,
878 rtc::scoped_refptr<RTCStatsCollectorCallback> callback)
879 : RequestInfo(FilterMode::kSenderSelector,
880 std::move(callback),
881 std::move(selector),
882 nullptr) {}
883
884RTCStatsCollector::RequestInfo::RequestInfo(
885 rtc::scoped_refptr<RtpReceiverInternal> selector,
886 rtc::scoped_refptr<RTCStatsCollectorCallback> callback)
887 : RequestInfo(FilterMode::kReceiverSelector,
888 std::move(callback),
889 nullptr,
890 std::move(selector)) {}
891
892RTCStatsCollector::RequestInfo::RequestInfo(
893 RTCStatsCollector::RequestInfo::FilterMode filter_mode,
894 rtc::scoped_refptr<RTCStatsCollectorCallback> callback,
895 rtc::scoped_refptr<RtpSenderInternal> sender_selector,
896 rtc::scoped_refptr<RtpReceiverInternal> receiver_selector)
897 : filter_mode_(filter_mode),
898 callback_(std::move(callback)),
899 sender_selector_(std::move(sender_selector)),
900 receiver_selector_(std::move(receiver_selector)) {
901 RTC_DCHECK(callback_);
902 RTC_DCHECK(!sender_selector_ || !receiver_selector_);
903}
904
hbosc82f2e12016-09-05 01:36:50 -0700905rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create(
Steve Anton2d8609c2018-01-23 16:38:46 -0800906 PeerConnectionInternal* pc,
907 int64_t cache_lifetime_us) {
hbosc82f2e12016-09-05 01:36:50 -0700908 return rtc::scoped_refptr<RTCStatsCollector>(
909 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us));
910}
911
Steve Anton2d8609c2018-01-23 16:38:46 -0800912RTCStatsCollector::RTCStatsCollector(PeerConnectionInternal* pc,
hbosc82f2e12016-09-05 01:36:50 -0700913 int64_t cache_lifetime_us)
hbosd565b732016-08-30 14:04:35 -0700914 : pc_(pc),
Steve Anton978b8762017-09-29 12:15:02 -0700915 signaling_thread_(pc->signaling_thread()),
916 worker_thread_(pc->worker_thread()),
917 network_thread_(pc->network_thread()),
hbosc82f2e12016-09-05 01:36:50 -0700918 num_pending_partial_reports_(0),
919 partial_report_timestamp_us_(0),
Henrik Boström40b030e2019-02-28 09:49:31 +0100920 network_report_event_(true /* manual_reset */,
921 true /* initially_signaled */),
hbos0e6758d2016-08-31 07:57:36 -0700922 cache_timestamp_us_(0),
923 cache_lifetime_us_(cache_lifetime_us) {
hbosd565b732016-08-30 14:04:35 -0700924 RTC_DCHECK(pc_);
hbosc82f2e12016-09-05 01:36:50 -0700925 RTC_DCHECK(signaling_thread_);
926 RTC_DCHECK(worker_thread_);
927 RTC_DCHECK(network_thread_);
hbos0e6758d2016-08-31 07:57:36 -0700928 RTC_DCHECK_GE(cache_lifetime_us_, 0);
Steve Anton2d8609c2018-01-23 16:38:46 -0800929 pc_->SignalDataChannelCreated().connect(
hbos82ebe022016-11-14 01:41:09 -0800930 this, &RTCStatsCollector::OnDataChannelCreated);
hbosd565b732016-08-30 14:04:35 -0700931}
932
hbosb78306a2016-12-19 05:06:57 -0800933RTCStatsCollector::~RTCStatsCollector() {
934 RTC_DCHECK_EQ(num_pending_partial_reports_, 0);
935}
936
hbosc82f2e12016-09-05 01:36:50 -0700937void RTCStatsCollector::GetStatsReport(
938 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) {
Henrik Boström5b3541f2018-03-19 13:52:56 +0100939 GetStatsReportInternal(RequestInfo(std::move(callback)));
940}
941
942void RTCStatsCollector::GetStatsReport(
943 rtc::scoped_refptr<RtpSenderInternal> selector,
944 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) {
945 GetStatsReportInternal(RequestInfo(std::move(selector), std::move(callback)));
946}
947
948void RTCStatsCollector::GetStatsReport(
949 rtc::scoped_refptr<RtpReceiverInternal> selector,
950 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) {
951 GetStatsReportInternal(RequestInfo(std::move(selector), std::move(callback)));
952}
953
954void RTCStatsCollector::GetStatsReportInternal(
955 RTCStatsCollector::RequestInfo request) {
hbosc82f2e12016-09-05 01:36:50 -0700956 RTC_DCHECK(signaling_thread_->IsCurrent());
Henrik Boström5b3541f2018-03-19 13:52:56 +0100957 requests_.push_back(std::move(request));
hbosc82f2e12016-09-05 01:36:50 -0700958
hbos0e6758d2016-08-31 07:57:36 -0700959 // "Now" using a monotonically increasing timer.
960 int64_t cache_now_us = rtc::TimeMicros();
961 if (cached_report_ &&
962 cache_now_us - cache_timestamp_us_ <= cache_lifetime_us_) {
Taylor Brandstetter25e022f2018-03-08 09:53:47 -0800963 // We have a fresh cached report to deliver. Deliver asynchronously, since
964 // the caller may not be expecting a synchronous callback, and it avoids
965 // reentrancy problems.
Henrik Boström5b3541f2018-03-19 13:52:56 +0100966 std::vector<RequestInfo> requests;
967 requests.swap(requests_);
Henrik Boström40b030e2019-02-28 09:49:31 +0100968 signaling_thread_->PostTask(
969 RTC_FROM_HERE, rtc::Bind(&RTCStatsCollector::DeliverCachedReport, this,
970 cached_report_, std::move(requests)));
hbosc82f2e12016-09-05 01:36:50 -0700971 } else if (!num_pending_partial_reports_) {
972 // Only start gathering stats if we're not already gathering stats. In the
973 // case of already gathering stats, |callback_| will be invoked when there
974 // are no more pending partial reports.
975
976 // "Now" using a system clock, relative to the UNIX epoch (Jan 1, 1970,
977 // UTC), in microseconds. The system clock could be modified and is not
978 // necessarily monotonically increasing.
nissecdf37a92016-09-13 23:41:47 -0700979 int64_t timestamp_us = rtc::TimeUTCMicros();
hbosc82f2e12016-09-05 01:36:50 -0700980
hbosf415f8a2017-01-02 04:28:51 -0800981 num_pending_partial_reports_ = 2;
hbosc82f2e12016-09-05 01:36:50 -0700982 partial_report_timestamp_us_ = cache_now_us;
hbosdf6075a2016-12-19 04:58:02 -0800983
Steve Anton57858b32018-02-15 15:19:50 -0800984 // Prepare |transceiver_stats_infos_| for use in
hbos84abeb12017-01-16 06:16:44 -0800985 // |ProducePartialResultsOnNetworkThread| and
986 // |ProducePartialResultsOnSignalingThread|.
Steve Anton57858b32018-02-15 15:19:50 -0800987 transceiver_stats_infos_ = PrepareTransceiverStatsInfos_s();
Steve Anton7eca0932018-03-30 15:18:41 -0700988 // Prepare |transport_names_| for use in
989 // |ProducePartialResultsOnNetworkThread|.
990 transport_names_ = PrepareTransportNames_s();
Steve Anton5dfde182018-02-06 10:34:40 -0800991
stefanf79ade12017-06-02 06:44:03 -0700992 // Prepare |call_stats_| here since GetCallStats() will hop to the worker
993 // thread.
994 // TODO(holmer): To avoid the hop we could move BWE and BWE stats to the
995 // network thread, where it more naturally belongs.
Steve Anton978b8762017-09-29 12:15:02 -0700996 call_stats_ = pc_->GetCallStats();
stefanf79ade12017-06-02 06:44:03 -0700997
Henrik Boström40b030e2019-02-28 09:49:31 +0100998 // Don't touch |network_report_| on the signaling thread until
999 // ProducePartialResultsOnNetworkThread() has signaled the
1000 // |network_report_event_|.
1001 network_report_event_.Reset();
1002 network_thread_->PostTask(
1003 RTC_FROM_HERE,
hbosc82f2e12016-09-05 01:36:50 -07001004 rtc::Bind(&RTCStatsCollector::ProducePartialResultsOnNetworkThread,
Henrik Boström40b030e2019-02-28 09:49:31 +01001005 this, timestamp_us));
hbosf415f8a2017-01-02 04:28:51 -08001006 ProducePartialResultsOnSignalingThread(timestamp_us);
hbos0e6758d2016-08-31 07:57:36 -07001007 }
hbosd565b732016-08-30 14:04:35 -07001008}
1009
1010void RTCStatsCollector::ClearCachedStatsReport() {
hbosc82f2e12016-09-05 01:36:50 -07001011 RTC_DCHECK(signaling_thread_->IsCurrent());
hbosd565b732016-08-30 14:04:35 -07001012 cached_report_ = nullptr;
1013}
1014
hbosb78306a2016-12-19 05:06:57 -08001015void RTCStatsCollector::WaitForPendingRequest() {
1016 RTC_DCHECK(signaling_thread_->IsCurrent());
Henrik Boström40b030e2019-02-28 09:49:31 +01001017 // If a request is pending, blocks until the |network_report_event_| is
1018 // signaled and then delivers the result. Otherwise this is a NO-OP.
1019 MergeNetworkReport_s();
hbosb78306a2016-12-19 05:06:57 -08001020}
1021
hbosc82f2e12016-09-05 01:36:50 -07001022void RTCStatsCollector::ProducePartialResultsOnSignalingThread(
1023 int64_t timestamp_us) {
1024 RTC_DCHECK(signaling_thread_->IsCurrent());
Henrik Boström40b030e2019-02-28 09:49:31 +01001025 partial_report_ = RTCStatsReport::Create(timestamp_us);
hbosc82f2e12016-09-05 01:36:50 -07001026
Henrik Boström40b030e2019-02-28 09:49:31 +01001027 ProducePartialResultsOnSignalingThreadImpl(timestamp_us,
1028 partial_report_.get());
hbosc82f2e12016-09-05 01:36:50 -07001029
Henrik Boström40b030e2019-02-28 09:49:31 +01001030 // ProducePartialResultsOnSignalingThread() is running synchronously on the
1031 // signaling thread, so it is always the first partial result delivered on the
1032 // signaling thread. The request is not complete until MergeNetworkReport_s()
1033 // happens; we don't have to do anything here.
1034 RTC_DCHECK_GT(num_pending_partial_reports_, 1);
1035 --num_pending_partial_reports_;
1036}
1037
1038void RTCStatsCollector::ProducePartialResultsOnSignalingThreadImpl(
1039 int64_t timestamp_us,
1040 RTCStatsReport* partial_report) {
1041 RTC_DCHECK(signaling_thread_->IsCurrent());
1042 ProduceDataChannelStats_s(timestamp_us, partial_report);
1043 ProduceMediaStreamStats_s(timestamp_us, partial_report);
1044 ProduceMediaStreamTrackStats_s(timestamp_us, partial_report);
Henrik Boström646fda02019-05-22 15:49:42 +02001045 ProduceMediaSourceStats_s(timestamp_us, partial_report);
Henrik Boström40b030e2019-02-28 09:49:31 +01001046 ProducePeerConnectionStats_s(timestamp_us, partial_report);
hbosc82f2e12016-09-05 01:36:50 -07001047}
1048
hbosc82f2e12016-09-05 01:36:50 -07001049void RTCStatsCollector::ProducePartialResultsOnNetworkThread(
1050 int64_t timestamp_us) {
1051 RTC_DCHECK(network_thread_->IsCurrent());
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +02001052 // Touching |network_report_| on this thread is safe by this method because
Henrik Boström40b030e2019-02-28 09:49:31 +01001053 // |network_report_event_| is reset before this method is invoked.
1054 network_report_ = RTCStatsReport::Create(timestamp_us);
hbosc82f2e12016-09-05 01:36:50 -07001055
Steve Anton5dfde182018-02-06 10:34:40 -08001056 std::map<std::string, cricket::TransportStats> transport_stats_by_name =
Steve Anton7eca0932018-03-30 15:18:41 -07001057 pc_->GetTransportStatsByNames(transport_names_);
Steve Anton5dfde182018-02-06 10:34:40 -08001058 std::map<std::string, CertificateStatsPair> transport_cert_stats =
1059 PrepareTransportCertificateStats_n(transport_stats_by_name);
1060
Henrik Boström40b030e2019-02-28 09:49:31 +01001061 ProducePartialResultsOnNetworkThreadImpl(
1062 timestamp_us, transport_stats_by_name, transport_cert_stats,
1063 network_report_.get());
Mirko Bonadeica890ee2019-02-15 21:10:40 +00001064
Henrik Boström40b030e2019-02-28 09:49:31 +01001065 // Signal that it is now safe to touch |network_report_| on the signaling
1066 // thread, and post a task to merge it into the final results.
1067 network_report_event_.Set();
1068 signaling_thread_->PostTask(
1069 RTC_FROM_HERE, rtc::Bind(&RTCStatsCollector::MergeNetworkReport_s, this));
Henrik Boström05d43c62019-02-15 10:23:08 +01001070}
1071
Henrik Boström40b030e2019-02-28 09:49:31 +01001072void RTCStatsCollector::ProducePartialResultsOnNetworkThreadImpl(
1073 int64_t timestamp_us,
1074 const std::map<std::string, cricket::TransportStats>&
1075 transport_stats_by_name,
1076 const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
1077 RTCStatsReport* partial_report) {
1078 RTC_DCHECK(network_thread_->IsCurrent());
1079 ProduceCertificateStats_n(timestamp_us, transport_cert_stats, partial_report);
1080 ProduceCodecStats_n(timestamp_us, transceiver_stats_infos_, partial_report);
1081 ProduceIceCandidateAndPairStats_n(timestamp_us, transport_stats_by_name,
1082 call_stats_, partial_report);
Henrik Boström40b030e2019-02-28 09:49:31 +01001083 ProduceTransportStats_n(timestamp_us, transport_stats_by_name,
1084 transport_cert_stats, partial_report);
Henrik Boström883eefc2019-05-27 13:40:25 +02001085 ProduceRTPStreamStats_n(timestamp_us, transceiver_stats_infos_,
1086 partial_report);
Henrik Boström40b030e2019-02-28 09:49:31 +01001087}
1088
1089void RTCStatsCollector::MergeNetworkReport_s() {
1090 RTC_DCHECK(signaling_thread_->IsCurrent());
1091 // The |network_report_event_| must be signaled for it to be safe to touch
1092 // |network_report_|. This is normally not blocking, but if
1093 // WaitForPendingRequest() is called while a request is pending, we might have
1094 // to wait until the network thread is done touching |network_report_|.
1095 network_report_event_.Wait(rtc::Event::kForever);
1096 if (!network_report_) {
1097 // Normally, MergeNetworkReport_s() is executed because it is posted from
1098 // the network thread. But if WaitForPendingRequest() is called while a
1099 // request is pending, an early call to MergeNetworkReport_s() is made,
1100 // merging the report and setting |network_report_| to null. If so, when the
1101 // previously posted MergeNetworkReport_s() is later executed, the report is
1102 // already null and nothing needs to be done here.
hbosc82f2e12016-09-05 01:36:50 -07001103 return;
1104 }
Mirko Bonadeica890ee2019-02-15 21:10:40 +00001105 RTC_DCHECK_GT(num_pending_partial_reports_, 0);
Henrik Boström40b030e2019-02-28 09:49:31 +01001106 RTC_DCHECK(partial_report_);
1107 partial_report_->TakeMembersFrom(network_report_);
1108 network_report_ = nullptr;
Mirko Bonadeica890ee2019-02-15 21:10:40 +00001109 --num_pending_partial_reports_;
Henrik Boström40b030e2019-02-28 09:49:31 +01001110 // |network_report_| is currently the only partial report collected
1111 // asynchronously, so |num_pending_partial_reports_| must now be 0 and we are
1112 // ready to deliver the result.
1113 RTC_DCHECK_EQ(num_pending_partial_reports_, 0);
1114 cache_timestamp_us_ = partial_report_timestamp_us_;
1115 cached_report_ = partial_report_;
1116 partial_report_ = nullptr;
1117 transceiver_stats_infos_.clear();
1118 // Trace WebRTC Stats when getStats is called on Javascript.
1119 // This allows access to WebRTC stats from trace logs. To enable them,
1120 // select the "webrtc_stats" category when recording traces.
1121 TRACE_EVENT_INSTANT1("webrtc_stats", "webrtc_stats", "report",
1122 cached_report_->ToJson());
Mirko Bonadeica890ee2019-02-15 21:10:40 +00001123
Henrik Boström40b030e2019-02-28 09:49:31 +01001124 // Deliver report and clear |requests_|.
1125 std::vector<RequestInfo> requests;
1126 requests.swap(requests_);
1127 DeliverCachedReport(cached_report_, std::move(requests));
hbosc82f2e12016-09-05 01:36:50 -07001128}
1129
Taylor Brandstetter25e022f2018-03-08 09:53:47 -08001130void RTCStatsCollector::DeliverCachedReport(
1131 rtc::scoped_refptr<const RTCStatsReport> cached_report,
Henrik Boström5b3541f2018-03-19 13:52:56 +01001132 std::vector<RTCStatsCollector::RequestInfo> requests) {
hbosc82f2e12016-09-05 01:36:50 -07001133 RTC_DCHECK(signaling_thread_->IsCurrent());
Henrik Boström5b3541f2018-03-19 13:52:56 +01001134 RTC_DCHECK(!requests.empty());
Taylor Brandstetter25e022f2018-03-08 09:53:47 -08001135 RTC_DCHECK(cached_report);
Taylor Brandstetter87d5a742018-03-06 09:42:25 -08001136
Henrik Boström5b3541f2018-03-19 13:52:56 +01001137 for (const RequestInfo& request : requests) {
1138 if (request.filter_mode() == RequestInfo::FilterMode::kAll) {
1139 request.callback()->OnStatsDelivered(cached_report);
1140 } else {
1141 bool filter_by_sender_selector;
1142 rtc::scoped_refptr<RtpSenderInternal> sender_selector;
1143 rtc::scoped_refptr<RtpReceiverInternal> receiver_selector;
1144 if (request.filter_mode() == RequestInfo::FilterMode::kSenderSelector) {
1145 filter_by_sender_selector = true;
1146 sender_selector = request.sender_selector();
1147 } else {
1148 RTC_DCHECK(request.filter_mode() ==
1149 RequestInfo::FilterMode::kReceiverSelector);
1150 filter_by_sender_selector = false;
1151 receiver_selector = request.receiver_selector();
1152 }
1153 request.callback()->OnStatsDelivered(CreateReportFilteredBySelector(
1154 filter_by_sender_selector, cached_report, sender_selector,
1155 receiver_selector));
1156 }
hbosc82f2e12016-09-05 01:36:50 -07001157 }
hbosd565b732016-08-30 14:04:35 -07001158}
1159
hbosdf6075a2016-12-19 04:58:02 -08001160void RTCStatsCollector::ProduceCertificateStats_n(
hbos2fa7c672016-10-24 04:00:05 -07001161 int64_t timestamp_us,
1162 const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
hbos6ab97ce2016-10-03 14:16:56 -07001163 RTCStatsReport* report) const {
hbosdf6075a2016-12-19 04:58:02 -08001164 RTC_DCHECK(network_thread_->IsCurrent());
hbos02ba2112016-10-28 05:14:53 -07001165 for (const auto& transport_cert_stats_pair : transport_cert_stats) {
1166 if (transport_cert_stats_pair.second.local) {
1167 ProduceCertificateStatsFromSSLCertificateStats(
1168 timestamp_us, *transport_cert_stats_pair.second.local.get(), report);
hbos6ab97ce2016-10-03 14:16:56 -07001169 }
hbos02ba2112016-10-28 05:14:53 -07001170 if (transport_cert_stats_pair.second.remote) {
1171 ProduceCertificateStatsFromSSLCertificateStats(
1172 timestamp_us, *transport_cert_stats_pair.second.remote.get(), report);
hbos6ab97ce2016-10-03 14:16:56 -07001173 }
1174 }
1175}
1176
hbosdf6075a2016-12-19 04:58:02 -08001177void RTCStatsCollector::ProduceCodecStats_n(
Steve Anton57858b32018-02-15 15:19:50 -08001178 int64_t timestamp_us,
1179 const std::vector<RtpTransceiverStatsInfo>& transceiver_stats_infos,
hbos0adb8282016-11-23 02:32:06 -08001180 RTCStatsReport* report) const {
hbosdf6075a2016-12-19 04:58:02 -08001181 RTC_DCHECK(network_thread_->IsCurrent());
Steve Anton57858b32018-02-15 15:19:50 -08001182 for (const auto& stats : transceiver_stats_infos) {
1183 if (!stats.mid) {
1184 continue;
hbos0adb8282016-11-23 02:32:06 -08001185 }
Steve Anton57858b32018-02-15 15:19:50 -08001186 const cricket::VoiceMediaInfo* voice_media_info =
1187 stats.track_media_info_map->voice_media_info();
1188 const cricket::VideoMediaInfo* video_media_info =
1189 stats.track_media_info_map->video_media_info();
1190 // Audio
1191 if (voice_media_info) {
1192 // Inbound
1193 for (const auto& pair : voice_media_info->receive_codecs) {
1194 report->AddStats(CodecStatsFromRtpCodecParameters(
1195 timestamp_us, *stats.mid, true, pair.second));
1196 }
1197 // Outbound
1198 for (const auto& pair : voice_media_info->send_codecs) {
1199 report->AddStats(CodecStatsFromRtpCodecParameters(
1200 timestamp_us, *stats.mid, false, pair.second));
1201 }
Guido Urdanetaee2388f2018-02-15 16:36:19 +00001202 }
Steve Anton57858b32018-02-15 15:19:50 -08001203 // Video
1204 if (video_media_info) {
1205 // Inbound
1206 for (const auto& pair : video_media_info->receive_codecs) {
1207 report->AddStats(CodecStatsFromRtpCodecParameters(
1208 timestamp_us, *stats.mid, true, pair.second));
1209 }
1210 // Outbound
1211 for (const auto& pair : video_media_info->send_codecs) {
1212 report->AddStats(CodecStatsFromRtpCodecParameters(
1213 timestamp_us, *stats.mid, false, pair.second));
1214 }
hbos0adb8282016-11-23 02:32:06 -08001215 }
1216 }
1217}
1218
hboscc555c52016-10-18 12:48:31 -07001219void RTCStatsCollector::ProduceDataChannelStats_s(
Jonas Olssona4d87372019-07-05 19:08:33 +02001220 int64_t timestamp_us,
1221 RTCStatsReport* report) const {
hboscc555c52016-10-18 12:48:31 -07001222 RTC_DCHECK(signaling_thread_->IsCurrent());
1223 for (const rtc::scoped_refptr<DataChannel>& data_channel :
1224 pc_->sctp_data_channels()) {
1225 std::unique_ptr<RTCDataChannelStats> data_channel_stats(
1226 new RTCDataChannelStats(
Jonas Olsson6b1985d2018-07-05 11:59:48 +02001227 "RTCDataChannel_" + rtc::ToString(data_channel->id()),
hboscc555c52016-10-18 12:48:31 -07001228 timestamp_us));
1229 data_channel_stats->label = data_channel->label();
1230 data_channel_stats->protocol = data_channel->protocol();
1231 data_channel_stats->datachannelid = data_channel->id();
1232 data_channel_stats->state =
1233 DataStateToRTCDataChannelState(data_channel->state());
1234 data_channel_stats->messages_sent = data_channel->messages_sent();
1235 data_channel_stats->bytes_sent = data_channel->bytes_sent();
1236 data_channel_stats->messages_received = data_channel->messages_received();
1237 data_channel_stats->bytes_received = data_channel->bytes_received();
1238 report->AddStats(std::move(data_channel_stats));
1239 }
1240}
1241
hbosdf6075a2016-12-19 04:58:02 -08001242void RTCStatsCollector::ProduceIceCandidateAndPairStats_n(
stefanf79ade12017-06-02 06:44:03 -07001243 int64_t timestamp_us,
Steve Anton5dfde182018-02-06 10:34:40 -08001244 const std::map<std::string, cricket::TransportStats>&
1245 transport_stats_by_name,
stefanf79ade12017-06-02 06:44:03 -07001246 const Call::Stats& call_stats,
1247 RTCStatsReport* report) const {
hbosdf6075a2016-12-19 04:58:02 -08001248 RTC_DCHECK(network_thread_->IsCurrent());
Steve Anton5dfde182018-02-06 10:34:40 -08001249 for (const auto& entry : transport_stats_by_name) {
1250 const std::string& transport_name = entry.first;
1251 const cricket::TransportStats& transport_stats = entry.second;
1252 for (const auto& channel_stats : transport_stats.channel_stats) {
hbos0583b282016-11-30 01:50:14 -08001253 std::string transport_id = RTCTransportStatsIDFromTransportChannel(
Steve Anton5dfde182018-02-06 10:34:40 -08001254 transport_name, channel_stats.component);
hbosc47a0c32016-10-11 14:54:49 -07001255 for (const cricket::ConnectionInfo& info :
1256 channel_stats.connection_infos) {
hbosc47a0c32016-10-11 14:54:49 -07001257 std::unique_ptr<RTCIceCandidatePairStats> candidate_pair_stats(
hbos2fa7c672016-10-24 04:00:05 -07001258 new RTCIceCandidatePairStats(
1259 RTCIceCandidatePairStatsIDFromConnectionInfo(info),
1260 timestamp_us));
hbosc47a0c32016-10-11 14:54:49 -07001261
hbos0583b282016-11-30 01:50:14 -08001262 candidate_pair_stats->transport_id = transport_id;
hbosab9f6e42016-10-07 02:18:47 -07001263 // TODO(hbos): There could be other candidates that are not paired with
1264 // anything. We don't have a complete list. Local candidates come from
1265 // Port objects, and prflx candidates (both local and remote) are only
Harald Alvestrand89061872018-01-02 14:08:34 +01001266 // stored in candidate pairs. https://crbug.com/632723
hbos02ba2112016-10-28 05:14:53 -07001267 candidate_pair_stats->local_candidate_id = ProduceIceCandidateStats(
hbosb4e426e2017-01-02 09:59:31 -08001268 timestamp_us, info.local_candidate, true, transport_id, report);
hbos02ba2112016-10-28 05:14:53 -07001269 candidate_pair_stats->remote_candidate_id = ProduceIceCandidateStats(
hbosb4e426e2017-01-02 09:59:31 -08001270 timestamp_us, info.remote_candidate, false, transport_id, report);
hbos06495bc2017-01-02 08:08:18 -08001271 candidate_pair_stats->state =
1272 IceCandidatePairStateToRTCStatsIceCandidatePairState(info.state);
1273 candidate_pair_stats->priority = info.priority;
hbos92eaec62017-02-27 01:38:08 -08001274 candidate_pair_stats->nominated = info.nominated;
hbosc47a0c32016-10-11 14:54:49 -07001275 // TODO(hbos): This writable is different than the spec. It goes to
1276 // false after a certain amount of time without a response passes.
Harald Alvestrand89061872018-01-02 14:08:34 +01001277 // https://crbug.com/633550
hbosc47a0c32016-10-11 14:54:49 -07001278 candidate_pair_stats->writable = info.writable;
hbosc47a0c32016-10-11 14:54:49 -07001279 candidate_pair_stats->bytes_sent =
1280 static_cast<uint64_t>(info.sent_total_bytes);
1281 candidate_pair_stats->bytes_received =
1282 static_cast<uint64_t>(info.recv_total_bytes);
hbosbf8d3e52017-02-28 06:34:47 -08001283 candidate_pair_stats->total_round_trip_time =
1284 static_cast<double>(info.total_round_trip_time_ms) /
1285 rtc::kNumMillisecsPerSec;
1286 if (info.current_round_trip_time_ms) {
1287 candidate_pair_stats->current_round_trip_time =
1288 static_cast<double>(*info.current_round_trip_time_ms) /
1289 rtc::kNumMillisecsPerSec;
1290 }
stefanf79ade12017-06-02 06:44:03 -07001291 if (info.best_connection) {
hbos338f78a2017-02-07 06:41:21 -08001292 // The bandwidth estimations we have are for the selected candidate
1293 // pair ("info.best_connection").
stefanf79ade12017-06-02 06:44:03 -07001294 RTC_DCHECK_GE(call_stats.send_bandwidth_bps, 0);
1295 RTC_DCHECK_GE(call_stats.recv_bandwidth_bps, 0);
1296 if (call_stats.send_bandwidth_bps > 0) {
hbos338f78a2017-02-07 06:41:21 -08001297 candidate_pair_stats->available_outgoing_bitrate =
stefanf79ade12017-06-02 06:44:03 -07001298 static_cast<double>(call_stats.send_bandwidth_bps);
hbos338f78a2017-02-07 06:41:21 -08001299 }
stefanf79ade12017-06-02 06:44:03 -07001300 if (call_stats.recv_bandwidth_bps > 0) {
hbos338f78a2017-02-07 06:41:21 -08001301 candidate_pair_stats->available_incoming_bitrate =
stefanf79ade12017-06-02 06:44:03 -07001302 static_cast<double>(call_stats.recv_bandwidth_bps);
hbos338f78a2017-02-07 06:41:21 -08001303 }
1304 }
hbosd82f5122016-12-09 04:12:39 -08001305 candidate_pair_stats->requests_received =
1306 static_cast<uint64_t>(info.recv_ping_requests);
hbose448dd52016-12-12 01:22:53 -08001307 candidate_pair_stats->requests_sent = static_cast<uint64_t>(
1308 info.sent_ping_requests_before_first_response);
hbosc47a0c32016-10-11 14:54:49 -07001309 candidate_pair_stats->responses_received =
1310 static_cast<uint64_t>(info.recv_ping_responses);
1311 candidate_pair_stats->responses_sent =
1312 static_cast<uint64_t>(info.sent_ping_responses);
hbose448dd52016-12-12 01:22:53 -08001313 RTC_DCHECK_GE(info.sent_ping_requests_total,
1314 info.sent_ping_requests_before_first_response);
1315 candidate_pair_stats->consent_requests_sent = static_cast<uint64_t>(
1316 info.sent_ping_requests_total -
1317 info.sent_ping_requests_before_first_response);
hbosc47a0c32016-10-11 14:54:49 -07001318
1319 report->AddStats(std::move(candidate_pair_stats));
hbosab9f6e42016-10-07 02:18:47 -07001320 }
1321 }
1322 }
1323}
1324
Steve Anton57858b32018-02-15 15:19:50 -08001325void RTCStatsCollector::ProduceMediaStreamStats_s(
1326 int64_t timestamp_us,
1327 RTCStatsReport* report) const {
hbos09bc1282016-11-08 06:29:22 -08001328 RTC_DCHECK(signaling_thread_->IsCurrent());
Steve Anton57858b32018-02-15 15:19:50 -08001329
1330 std::map<std::string, std::vector<std::string>> track_ids;
1331
1332 for (const auto& stats : transceiver_stats_infos_) {
Mirko Bonadei739baf02019-01-27 17:29:42 +01001333 for (const auto& sender : stats.transceiver->senders()) {
Steve Anton57858b32018-02-15 15:19:50 -08001334 std::string track_id =
1335 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
1336 kSender, sender->internal()->AttachmentId());
1337 for (auto& stream_id : sender->stream_ids()) {
1338 track_ids[stream_id].push_back(track_id);
1339 }
1340 }
Mirko Bonadei739baf02019-01-27 17:29:42 +01001341 for (const auto& receiver : stats.transceiver->receivers()) {
Steve Anton57858b32018-02-15 15:19:50 -08001342 std::string track_id =
1343 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
1344 kReceiver, receiver->internal()->AttachmentId());
1345 for (auto& stream : receiver->streams()) {
Seth Hampson13b8bad2018-03-13 16:05:28 -07001346 track_ids[stream->id()].push_back(track_id);
Steve Anton57858b32018-02-15 15:19:50 -08001347 }
1348 }
1349 }
1350
1351 // Build stats for each stream ID known.
1352 for (auto& it : track_ids) {
1353 std::unique_ptr<RTCMediaStreamStats> stream_stats(
1354 new RTCMediaStreamStats("RTCMediaStream_" + it.first, timestamp_us));
1355 stream_stats->stream_identifier = it.first;
1356 stream_stats->track_ids = it.second;
1357 report->AddStats(std::move(stream_stats));
1358 }
1359}
1360
1361void RTCStatsCollector::ProduceMediaStreamTrackStats_s(
1362 int64_t timestamp_us,
1363 RTCStatsReport* report) const {
1364 RTC_DCHECK(signaling_thread_->IsCurrent());
1365 for (const RtpTransceiverStatsInfo& stats : transceiver_stats_infos_) {
1366 std::vector<rtc::scoped_refptr<RtpSenderInternal>> senders;
Mirko Bonadei739baf02019-01-27 17:29:42 +01001367 for (const auto& sender : stats.transceiver->senders()) {
Steve Anton57858b32018-02-15 15:19:50 -08001368 senders.push_back(sender->internal());
1369 }
1370 ProduceSenderMediaTrackStats(timestamp_us, *stats.track_media_info_map,
1371 senders, report);
1372
1373 std::vector<rtc::scoped_refptr<RtpReceiverInternal>> receivers;
Mirko Bonadei739baf02019-01-27 17:29:42 +01001374 for (const auto& receiver : stats.transceiver->receivers()) {
Steve Anton57858b32018-02-15 15:19:50 -08001375 receivers.push_back(receiver->internal());
1376 }
1377 ProduceReceiverMediaTrackStats(timestamp_us, *stats.track_media_info_map,
1378 receivers, report);
1379 }
hbos09bc1282016-11-08 06:29:22 -08001380}
1381
Henrik Boström646fda02019-05-22 15:49:42 +02001382void RTCStatsCollector::ProduceMediaSourceStats_s(
1383 int64_t timestamp_us,
1384 RTCStatsReport* report) const {
1385 RTC_DCHECK(signaling_thread_->IsCurrent());
1386 for (const RtpTransceiverStatsInfo& transceiver_stats_info :
1387 transceiver_stats_infos_) {
1388 const auto& track_media_info_map =
1389 transceiver_stats_info.track_media_info_map;
1390 for (const auto& sender : transceiver_stats_info.transceiver->senders()) {
1391 const auto& sender_internal = sender->internal();
1392 const auto& track = sender_internal->track();
1393 if (!track)
1394 continue;
Henrik Boströmd2c336f2019-07-03 17:11:10 +02001395 // TODO(https://crbug.com/webrtc/10771): The same track could be attached
1396 // to multiple senders which should result in multiple senders referencing
1397 // the same media-source stats. When all media source related metrics are
1398 // moved to the track's source (e.g. input frame rate is moved from
1399 // cricket::VideoSenderInfo to VideoTrackSourceInterface::Stats and audio
1400 // levels are moved to the corresponding audio track/source object), don't
1401 // create separate media source stats objects on a per-attachment basis.
Henrik Boström646fda02019-05-22 15:49:42 +02001402 std::unique_ptr<RTCMediaSourceStats> media_source_stats;
1403 if (track->kind() == MediaStreamTrackInterface::kAudioKind) {
Henrik Boströmd2c336f2019-07-03 17:11:10 +02001404 auto audio_source_stats = absl::make_unique<RTCAudioSourceStats>(
Henrik Boström646fda02019-05-22 15:49:42 +02001405 RTCMediaSourceStatsIDFromKindAndAttachment(
1406 cricket::MEDIA_TYPE_AUDIO, sender_internal->AttachmentId()),
1407 timestamp_us);
Henrik Boströmd2c336f2019-07-03 17:11:10 +02001408 // TODO(https://crbug.com/webrtc/10771): We shouldn't need to have an
1409 // SSRC assigned (there shouldn't need to exist a send-stream, created
1410 // by an O/A exchange) in order to read audio media-source stats.
1411 // TODO(https://crbug.com/webrtc/8694): SSRC 0 shouldn't be a magic
1412 // value indicating no SSRC.
1413 if (sender_internal->ssrc() != 0) {
1414 auto* voice_sender_info =
1415 track_media_info_map->GetVoiceSenderInfoBySsrc(
1416 sender_internal->ssrc());
1417 if (voice_sender_info) {
1418 audio_source_stats->audio_level = DoubleAudioLevelFromIntAudioLevel(
1419 voice_sender_info->audio_level);
1420 audio_source_stats->total_audio_energy =
1421 voice_sender_info->total_input_energy;
1422 audio_source_stats->total_samples_duration =
1423 voice_sender_info->total_input_duration;
1424 }
1425 }
1426 media_source_stats = std::move(audio_source_stats);
Henrik Boström646fda02019-05-22 15:49:42 +02001427 } else {
1428 RTC_DCHECK_EQ(MediaStreamTrackInterface::kVideoKind, track->kind());
1429 auto video_source_stats = absl::make_unique<RTCVideoSourceStats>(
1430 RTCMediaSourceStatsIDFromKindAndAttachment(
1431 cricket::MEDIA_TYPE_VIDEO, sender_internal->AttachmentId()),
1432 timestamp_us);
1433 auto* video_track = static_cast<VideoTrackInterface*>(track.get());
1434 auto* video_source = video_track->GetSource();
1435 VideoTrackSourceInterface::Stats source_stats;
1436 if (video_source && video_source->GetStats(&source_stats)) {
1437 video_source_stats->width = source_stats.input_width;
1438 video_source_stats->height = source_stats.input_height;
1439 }
Henrik Boströmd2c336f2019-07-03 17:11:10 +02001440 // TODO(https://crbug.com/webrtc/10771): We shouldn't need to have an
1441 // SSRC assigned (there shouldn't need to exist a send-stream, created
1442 // by an O/A exchange) in order to get framesPerSecond.
1443 // TODO(https://crbug.com/webrtc/8694): SSRC 0 shouldn't be a magic
1444 // value indicating no SSRC.
Henrik Boström646fda02019-05-22 15:49:42 +02001445 if (sender_internal->ssrc() != 0) {
Henrik Boströmd2c336f2019-07-03 17:11:10 +02001446 auto* video_sender_info =
1447 track_media_info_map->GetVideoSenderInfoBySsrc(
1448 sender_internal->ssrc());
1449 if (video_sender_info) {
Henrik Boström646fda02019-05-22 15:49:42 +02001450 video_source_stats->frames_per_second =
Henrik Boströmd2c336f2019-07-03 17:11:10 +02001451 video_sender_info->framerate_input;
Henrik Boström646fda02019-05-22 15:49:42 +02001452 }
1453 }
1454 media_source_stats = std::move(video_source_stats);
1455 }
1456 media_source_stats->track_identifier = track->id();
1457 media_source_stats->kind = track->kind();
1458 report->AddStats(std::move(media_source_stats));
1459 }
1460 }
1461}
1462
hbos6ab97ce2016-10-03 14:16:56 -07001463void RTCStatsCollector::ProducePeerConnectionStats_s(
Jonas Olssona4d87372019-07-05 19:08:33 +02001464 int64_t timestamp_us,
1465 RTCStatsReport* report) const {
hbosc82f2e12016-09-05 01:36:50 -07001466 RTC_DCHECK(signaling_thread_->IsCurrent());
hbosd565b732016-08-30 14:04:35 -07001467 std::unique_ptr<RTCPeerConnectionStats> stats(
Jonas Olssona4d87372019-07-05 19:08:33 +02001468 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us));
hbos82ebe022016-11-14 01:41:09 -08001469 stats->data_channels_opened = internal_record_.data_channels_opened;
1470 stats->data_channels_closed = internal_record_.data_channels_closed;
hbos6ab97ce2016-10-03 14:16:56 -07001471 report->AddStats(std::move(stats));
hbosd565b732016-08-30 14:04:35 -07001472}
1473
hbosdf6075a2016-12-19 04:58:02 -08001474void RTCStatsCollector::ProduceRTPStreamStats_n(
Steve Anton593e3252017-12-15 11:44:48 -08001475 int64_t timestamp_us,
Steve Anton57858b32018-02-15 15:19:50 -08001476 const std::vector<RtpTransceiverStatsInfo>& transceiver_stats_infos,
hbos84abeb12017-01-16 06:16:44 -08001477 RTCStatsReport* report) const {
hbosdf6075a2016-12-19 04:58:02 -08001478 RTC_DCHECK(network_thread_->IsCurrent());
hbos6ded1902016-11-01 01:50:46 -07001479
Steve Anton57858b32018-02-15 15:19:50 -08001480 for (const RtpTransceiverStatsInfo& stats : transceiver_stats_infos) {
1481 if (stats.media_type == cricket::MEDIA_TYPE_AUDIO) {
1482 ProduceAudioRTPStreamStats_n(timestamp_us, stats, report);
1483 } else if (stats.media_type == cricket::MEDIA_TYPE_VIDEO) {
1484 ProduceVideoRTPStreamStats_n(timestamp_us, stats, report);
1485 } else {
1486 RTC_NOTREACHED();
Guido Urdanetaee2388f2018-02-15 16:36:19 +00001487 }
Steve Anton56bae8d2018-02-14 16:07:42 -08001488 }
Steve Anton57858b32018-02-15 15:19:50 -08001489}
1490
1491void RTCStatsCollector::ProduceAudioRTPStreamStats_n(
1492 int64_t timestamp_us,
1493 const RtpTransceiverStatsInfo& stats,
1494 RTCStatsReport* report) const {
1495 if (!stats.mid || !stats.transport_name) {
1496 return;
1497 }
1498 RTC_DCHECK(stats.track_media_info_map);
1499 const TrackMediaInfoMap& track_media_info_map = *stats.track_media_info_map;
1500 RTC_DCHECK(track_media_info_map.voice_media_info());
1501 std::string mid = *stats.mid;
1502 std::string transport_id = RTCTransportStatsIDFromTransportChannel(
1503 *stats.transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
1504 // Inbound
1505 for (const cricket::VoiceReceiverInfo& voice_receiver_info :
1506 track_media_info_map.voice_media_info()->receivers) {
1507 if (!voice_receiver_info.connected())
1508 continue;
Karl Wiberg918f50c2018-07-05 11:40:33 +02001509 auto inbound_audio = absl::make_unique<RTCInboundRTPStreamStats>(
Steve Anton57858b32018-02-15 15:19:50 -08001510 RTCInboundRTPStreamStatsIDFromSSRC(true, voice_receiver_info.ssrc()),
1511 timestamp_us);
1512 SetInboundRTPStreamStatsFromVoiceReceiverInfo(mid, voice_receiver_info,
1513 inbound_audio.get());
1514 // TODO(hta): This lookup should look for the sender, not the track.
1515 rtc::scoped_refptr<AudioTrackInterface> audio_track =
1516 track_media_info_map.GetAudioTrack(voice_receiver_info);
1517 if (audio_track) {
1518 inbound_audio->track_id =
1519 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
1520 kReceiver,
1521 track_media_info_map.GetAttachmentIdByTrack(audio_track).value());
hbos6ded1902016-11-01 01:50:46 -07001522 }
Steve Anton57858b32018-02-15 15:19:50 -08001523 inbound_audio->transport_id = transport_id;
1524 report->AddStats(std::move(inbound_audio));
1525 }
1526 // Outbound
1527 for (const cricket::VoiceSenderInfo& voice_sender_info :
1528 track_media_info_map.voice_media_info()->senders) {
1529 if (!voice_sender_info.connected())
1530 continue;
Karl Wiberg918f50c2018-07-05 11:40:33 +02001531 auto outbound_audio = absl::make_unique<RTCOutboundRTPStreamStats>(
Steve Anton57858b32018-02-15 15:19:50 -08001532 RTCOutboundRTPStreamStatsIDFromSSRC(true, voice_sender_info.ssrc()),
1533 timestamp_us);
1534 SetOutboundRTPStreamStatsFromVoiceSenderInfo(mid, voice_sender_info,
1535 outbound_audio.get());
1536 rtc::scoped_refptr<AudioTrackInterface> audio_track =
1537 track_media_info_map.GetAudioTrack(voice_sender_info);
1538 if (audio_track) {
Henrik Boström646fda02019-05-22 15:49:42 +02001539 int attachment_id =
1540 track_media_info_map.GetAttachmentIdByTrack(audio_track).value();
Steve Anton57858b32018-02-15 15:19:50 -08001541 outbound_audio->track_id =
Henrik Boström646fda02019-05-22 15:49:42 +02001542 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(kSender,
1543 attachment_id);
1544 outbound_audio->media_source_id =
1545 RTCMediaSourceStatsIDFromKindAndAttachment(cricket::MEDIA_TYPE_AUDIO,
1546 attachment_id);
Steve Anton56bae8d2018-02-14 16:07:42 -08001547 }
Steve Anton57858b32018-02-15 15:19:50 -08001548 outbound_audio->transport_id = transport_id;
1549 report->AddStats(std::move(outbound_audio));
1550 }
Henrik Boström883eefc2019-05-27 13:40:25 +02001551 // Remote-inbound
1552 // These are Report Block-based, information sent from the remote endpoint,
1553 // providing metrics about our Outbound streams. We take advantage of the fact
1554 // that RTCOutboundRtpStreamStats, RTCCodecStats and RTCTransport have already
1555 // been added to the report.
1556 for (const cricket::VoiceSenderInfo& voice_sender_info :
1557 track_media_info_map.voice_media_info()->senders) {
1558 for (const auto& report_block_data : voice_sender_info.report_block_datas) {
1559 report->AddStats(ProduceRemoteInboundRtpStreamStatsFromReportBlockData(
1560 report_block_data, cricket::MEDIA_TYPE_AUDIO, *report));
1561 }
1562 }
Steve Anton57858b32018-02-15 15:19:50 -08001563}
1564
1565void RTCStatsCollector::ProduceVideoRTPStreamStats_n(
1566 int64_t timestamp_us,
1567 const RtpTransceiverStatsInfo& stats,
1568 RTCStatsReport* report) const {
1569 if (!stats.mid || !stats.transport_name) {
1570 return;
1571 }
1572 RTC_DCHECK(stats.track_media_info_map);
1573 const TrackMediaInfoMap& track_media_info_map = *stats.track_media_info_map;
1574 RTC_DCHECK(track_media_info_map.video_media_info());
1575 std::string mid = *stats.mid;
1576 std::string transport_id = RTCTransportStatsIDFromTransportChannel(
1577 *stats.transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
1578 // Inbound
1579 for (const cricket::VideoReceiverInfo& video_receiver_info :
1580 track_media_info_map.video_media_info()->receivers) {
1581 if (!video_receiver_info.connected())
1582 continue;
Karl Wiberg918f50c2018-07-05 11:40:33 +02001583 auto inbound_video = absl::make_unique<RTCInboundRTPStreamStats>(
Steve Anton57858b32018-02-15 15:19:50 -08001584 RTCInboundRTPStreamStatsIDFromSSRC(false, video_receiver_info.ssrc()),
1585 timestamp_us);
1586 SetInboundRTPStreamStatsFromVideoReceiverInfo(mid, video_receiver_info,
1587 inbound_video.get());
1588 rtc::scoped_refptr<VideoTrackInterface> video_track =
1589 track_media_info_map.GetVideoTrack(video_receiver_info);
1590 if (video_track) {
1591 inbound_video->track_id =
1592 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(
1593 kReceiver,
1594 track_media_info_map.GetAttachmentIdByTrack(video_track).value());
1595 }
1596 inbound_video->transport_id = transport_id;
1597 report->AddStats(std::move(inbound_video));
1598 }
1599 // Outbound
1600 for (const cricket::VideoSenderInfo& video_sender_info :
1601 track_media_info_map.video_media_info()->senders) {
1602 if (!video_sender_info.connected())
1603 continue;
Karl Wiberg918f50c2018-07-05 11:40:33 +02001604 auto outbound_video = absl::make_unique<RTCOutboundRTPStreamStats>(
Steve Anton57858b32018-02-15 15:19:50 -08001605 RTCOutboundRTPStreamStatsIDFromSSRC(false, video_sender_info.ssrc()),
1606 timestamp_us);
1607 SetOutboundRTPStreamStatsFromVideoSenderInfo(mid, video_sender_info,
1608 outbound_video.get());
1609 rtc::scoped_refptr<VideoTrackInterface> video_track =
1610 track_media_info_map.GetVideoTrack(video_sender_info);
1611 if (video_track) {
Henrik Boström646fda02019-05-22 15:49:42 +02001612 int attachment_id =
1613 track_media_info_map.GetAttachmentIdByTrack(video_track).value();
Steve Anton57858b32018-02-15 15:19:50 -08001614 outbound_video->track_id =
Henrik Boström646fda02019-05-22 15:49:42 +02001615 RTCMediaStreamTrackStatsIDFromDirectionAndAttachment(kSender,
1616 attachment_id);
1617 outbound_video->media_source_id =
1618 RTCMediaSourceStatsIDFromKindAndAttachment(cricket::MEDIA_TYPE_VIDEO,
1619 attachment_id);
Steve Anton57858b32018-02-15 15:19:50 -08001620 }
1621 outbound_video->transport_id = transport_id;
1622 report->AddStats(std::move(outbound_video));
hbos6ded1902016-11-01 01:50:46 -07001623 }
Henrik Boström883eefc2019-05-27 13:40:25 +02001624 // Remote-inbound
1625 // These are Report Block-based, information sent from the remote endpoint,
1626 // providing metrics about our Outbound streams. We take advantage of the fact
1627 // that RTCOutboundRtpStreamStats, RTCCodecStats and RTCTransport have already
1628 // been added to the report.
1629 for (const cricket::VideoSenderInfo& video_sender_info :
1630 track_media_info_map.video_media_info()->senders) {
1631 for (const auto& report_block_data : video_sender_info.report_block_datas) {
1632 report->AddStats(ProduceRemoteInboundRtpStreamStatsFromReportBlockData(
1633 report_block_data, cricket::MEDIA_TYPE_VIDEO, *report));
1634 }
1635 }
hbos6ded1902016-11-01 01:50:46 -07001636}
1637
hbosdf6075a2016-12-19 04:58:02 -08001638void RTCStatsCollector::ProduceTransportStats_n(
Steve Anton5dfde182018-02-06 10:34:40 -08001639 int64_t timestamp_us,
1640 const std::map<std::string, cricket::TransportStats>&
1641 transport_stats_by_name,
hbos2fa7c672016-10-24 04:00:05 -07001642 const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
1643 RTCStatsReport* report) const {
hbosdf6075a2016-12-19 04:58:02 -08001644 RTC_DCHECK(network_thread_->IsCurrent());
Steve Anton5dfde182018-02-06 10:34:40 -08001645 for (const auto& entry : transport_stats_by_name) {
1646 const std::string& transport_name = entry.first;
1647 const cricket::TransportStats& transport_stats = entry.second;
1648
hbos2fa7c672016-10-24 04:00:05 -07001649 // Get reference to RTCP channel, if it exists.
1650 std::string rtcp_transport_stats_id;
Steve Anton5dfde182018-02-06 10:34:40 -08001651 for (const cricket::TransportChannelStats& channel_stats :
1652 transport_stats.channel_stats) {
Jonas Olssona4d87372019-07-05 19:08:33 +02001653 if (channel_stats.component == cricket::ICE_CANDIDATE_COMPONENT_RTCP) {
hbos2fa7c672016-10-24 04:00:05 -07001654 rtcp_transport_stats_id = RTCTransportStatsIDFromTransportChannel(
Steve Anton5dfde182018-02-06 10:34:40 -08001655 transport_name, channel_stats.component);
hbos2fa7c672016-10-24 04:00:05 -07001656 break;
1657 }
1658 }
1659
1660 // Get reference to local and remote certificates of this transport, if they
1661 // exist.
Steve Anton5dfde182018-02-06 10:34:40 -08001662 const auto& certificate_stats_it =
1663 transport_cert_stats.find(transport_name);
hbos2fa7c672016-10-24 04:00:05 -07001664 RTC_DCHECK(certificate_stats_it != transport_cert_stats.cend());
1665 std::string local_certificate_id;
1666 if (certificate_stats_it->second.local) {
1667 local_certificate_id = RTCCertificateIDFromFingerprint(
1668 certificate_stats_it->second.local->fingerprint);
1669 }
1670 std::string remote_certificate_id;
1671 if (certificate_stats_it->second.remote) {
1672 remote_certificate_id = RTCCertificateIDFromFingerprint(
1673 certificate_stats_it->second.remote->fingerprint);
1674 }
1675
1676 // There is one transport stats for each channel.
Steve Anton5dfde182018-02-06 10:34:40 -08001677 for (const cricket::TransportChannelStats& channel_stats :
1678 transport_stats.channel_stats) {
hbos2fa7c672016-10-24 04:00:05 -07001679 std::unique_ptr<RTCTransportStats> transport_stats(
Steve Anton5dfde182018-02-06 10:34:40 -08001680 new RTCTransportStats(RTCTransportStatsIDFromTransportChannel(
1681 transport_name, channel_stats.component),
1682 timestamp_us));
hbos2fa7c672016-10-24 04:00:05 -07001683 transport_stats->bytes_sent = 0;
1684 transport_stats->bytes_received = 0;
Jonas Olssona4d87372019-07-05 19:08:33 +02001685 transport_stats->dtls_state =
1686 DtlsTransportStateToRTCDtlsTransportState(channel_stats.dtls_state);
hbos2fa7c672016-10-24 04:00:05 -07001687 for (const cricket::ConnectionInfo& info :
1688 channel_stats.connection_infos) {
1689 *transport_stats->bytes_sent += info.sent_total_bytes;
1690 *transport_stats->bytes_received += info.recv_total_bytes;
1691 if (info.best_connection) {
hbos2fa7c672016-10-24 04:00:05 -07001692 transport_stats->selected_candidate_pair_id =
1693 RTCIceCandidatePairStatsIDFromConnectionInfo(info);
1694 }
1695 }
1696 if (channel_stats.component != cricket::ICE_CANDIDATE_COMPONENT_RTCP &&
1697 !rtcp_transport_stats_id.empty()) {
1698 transport_stats->rtcp_transport_stats_id = rtcp_transport_stats_id;
1699 }
1700 if (!local_certificate_id.empty())
1701 transport_stats->local_certificate_id = local_certificate_id;
1702 if (!remote_certificate_id.empty())
1703 transport_stats->remote_certificate_id = remote_certificate_id;
1704 report->AddStats(std::move(transport_stats));
1705 }
1706 }
1707}
1708
1709std::map<std::string, RTCStatsCollector::CertificateStatsPair>
hbosdf6075a2016-12-19 04:58:02 -08001710RTCStatsCollector::PrepareTransportCertificateStats_n(
Steve Anton5dfde182018-02-06 10:34:40 -08001711 const std::map<std::string, cricket::TransportStats>&
1712 transport_stats_by_name) const {
hbosdf6075a2016-12-19 04:58:02 -08001713 RTC_DCHECK(network_thread_->IsCurrent());
hbos2fa7c672016-10-24 04:00:05 -07001714 std::map<std::string, CertificateStatsPair> transport_cert_stats;
Steve Anton5dfde182018-02-06 10:34:40 -08001715 for (const auto& entry : transport_stats_by_name) {
1716 const std::string& transport_name = entry.first;
1717
hbos2fa7c672016-10-24 04:00:05 -07001718 CertificateStatsPair certificate_stats_pair;
1719 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate;
Steve Anton5dfde182018-02-06 10:34:40 -08001720 if (pc_->GetLocalCertificate(transport_name, &local_certificate)) {
hbos2fa7c672016-10-24 04:00:05 -07001721 certificate_stats_pair.local =
Benjamin Wright6c6c9df2018-10-25 01:16:26 -07001722 local_certificate->GetSSLCertificateChain().GetStats();
hbos2fa7c672016-10-24 04:00:05 -07001723 }
Steve Anton5dfde182018-02-06 10:34:40 -08001724
Taylor Brandstetterc3928662018-02-23 13:04:51 -08001725 std::unique_ptr<rtc::SSLCertChain> remote_cert_chain =
1726 pc_->GetRemoteSSLCertChain(transport_name);
1727 if (remote_cert_chain) {
1728 certificate_stats_pair.remote = remote_cert_chain->GetStats();
hbos2fa7c672016-10-24 04:00:05 -07001729 }
Steve Anton5dfde182018-02-06 10:34:40 -08001730
hbos2fa7c672016-10-24 04:00:05 -07001731 transport_cert_stats.insert(
Steve Anton5dfde182018-02-06 10:34:40 -08001732 std::make_pair(transport_name, std::move(certificate_stats_pair)));
hbos2fa7c672016-10-24 04:00:05 -07001733 }
1734 return transport_cert_stats;
1735}
1736
Steve Anton57858b32018-02-15 15:19:50 -08001737std::vector<RTCStatsCollector::RtpTransceiverStatsInfo>
1738RTCStatsCollector::PrepareTransceiverStatsInfos_s() const {
1739 std::vector<RtpTransceiverStatsInfo> transceiver_stats_infos;
Steve Anton56bae8d2018-02-14 16:07:42 -08001740
Steve Anton57858b32018-02-15 15:19:50 -08001741 // These are used to invoke GetStats for all the media channels together in
1742 // one worker thread hop.
1743 std::map<cricket::VoiceMediaChannel*,
1744 std::unique_ptr<cricket::VoiceMediaInfo>>
1745 voice_stats;
1746 std::map<cricket::VideoMediaChannel*,
1747 std::unique_ptr<cricket::VideoMediaInfo>>
1748 video_stats;
1749
Mirko Bonadei739baf02019-01-27 17:29:42 +01001750 for (const auto& transceiver : pc_->GetTransceiversInternal()) {
Steve Anton57858b32018-02-15 15:19:50 -08001751 cricket::MediaType media_type = transceiver->media_type();
1752
1753 // Prepare stats entry. The TrackMediaInfoMap will be filled in after the
1754 // stats have been fetched on the worker thread.
1755 transceiver_stats_infos.emplace_back();
1756 RtpTransceiverStatsInfo& stats = transceiver_stats_infos.back();
1757 stats.transceiver = transceiver->internal();
1758 stats.media_type = media_type;
1759
Amit Hilbuchdd9390c2018-11-13 16:26:05 -08001760 cricket::ChannelInterface* channel = transceiver->internal()->channel();
Steve Anton57858b32018-02-15 15:19:50 -08001761 if (!channel) {
1762 // The remaining fields require a BaseChannel.
1763 continue;
1764 }
1765
1766 stats.mid = channel->content_name();
1767 stats.transport_name = channel->transport_name();
1768
1769 if (media_type == cricket::MEDIA_TYPE_AUDIO) {
1770 auto* voice_channel = static_cast<cricket::VoiceChannel*>(channel);
1771 RTC_DCHECK(voice_stats.find(voice_channel->media_channel()) ==
1772 voice_stats.end());
1773 voice_stats[voice_channel->media_channel()] =
Karl Wiberg918f50c2018-07-05 11:40:33 +02001774 absl::make_unique<cricket::VoiceMediaInfo>();
Steve Anton57858b32018-02-15 15:19:50 -08001775 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
1776 auto* video_channel = static_cast<cricket::VideoChannel*>(channel);
1777 RTC_DCHECK(video_stats.find(video_channel->media_channel()) ==
1778 video_stats.end());
1779 video_stats[video_channel->media_channel()] =
Karl Wiberg918f50c2018-07-05 11:40:33 +02001780 absl::make_unique<cricket::VideoMediaInfo>();
Steve Anton57858b32018-02-15 15:19:50 -08001781 } else {
1782 RTC_NOTREACHED();
1783 }
Guido Urdanetaee2388f2018-02-15 16:36:19 +00001784 }
Steve Anton57858b32018-02-15 15:19:50 -08001785
1786 // Call GetStats for all media channels together on the worker thread in one
1787 // hop.
1788 worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] {
1789 for (const auto& entry : voice_stats) {
1790 if (!entry.first->GetStats(entry.second.get())) {
1791 RTC_LOG(LS_WARNING) << "Failed to get voice stats.";
1792 }
1793 }
1794 for (const auto& entry : video_stats) {
1795 if (!entry.first->GetStats(entry.second.get())) {
1796 RTC_LOG(LS_WARNING) << "Failed to get video stats.";
1797 }
1798 }
1799 });
1800
1801 // Create the TrackMediaInfoMap for each transceiver stats object.
1802 for (auto& stats : transceiver_stats_infos) {
1803 auto transceiver = stats.transceiver;
1804 std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info;
1805 std::unique_ptr<cricket::VideoMediaInfo> video_media_info;
1806 if (transceiver->channel()) {
1807 cricket::MediaType media_type = transceiver->media_type();
1808 if (media_type == cricket::MEDIA_TYPE_AUDIO) {
1809 auto* voice_channel =
1810 static_cast<cricket::VoiceChannel*>(transceiver->channel());
1811 RTC_DCHECK(voice_stats[voice_channel->media_channel()]);
1812 voice_media_info =
1813 std::move(voice_stats[voice_channel->media_channel()]);
1814 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
1815 auto* video_channel =
1816 static_cast<cricket::VideoChannel*>(transceiver->channel());
1817 RTC_DCHECK(video_stats[video_channel->media_channel()]);
1818 video_media_info =
1819 std::move(video_stats[video_channel->media_channel()]);
1820 }
1821 }
1822 std::vector<rtc::scoped_refptr<RtpSenderInternal>> senders;
Mirko Bonadei739baf02019-01-27 17:29:42 +01001823 for (const auto& sender : transceiver->senders()) {
Steve Anton57858b32018-02-15 15:19:50 -08001824 senders.push_back(sender->internal());
1825 }
1826 std::vector<rtc::scoped_refptr<RtpReceiverInternal>> receivers;
Mirko Bonadei739baf02019-01-27 17:29:42 +01001827 for (const auto& receiver : transceiver->receivers()) {
Steve Anton57858b32018-02-15 15:19:50 -08001828 receivers.push_back(receiver->internal());
1829 }
Karl Wiberg918f50c2018-07-05 11:40:33 +02001830 stats.track_media_info_map = absl::make_unique<TrackMediaInfoMap>(
Steve Anton57858b32018-02-15 15:19:50 -08001831 std::move(voice_media_info), std::move(video_media_info), senders,
1832 receivers);
Guido Urdanetaee2388f2018-02-15 16:36:19 +00001833 }
Steve Anton57858b32018-02-15 15:19:50 -08001834
1835 return transceiver_stats_infos;
hbos0adb8282016-11-23 02:32:06 -08001836}
1837
Steve Anton7eca0932018-03-30 15:18:41 -07001838std::set<std::string> RTCStatsCollector::PrepareTransportNames_s() const {
1839 std::set<std::string> transport_names;
1840 for (const auto& transceiver : pc_->GetTransceiversInternal()) {
1841 if (transceiver->internal()->channel()) {
1842 transport_names.insert(
1843 transceiver->internal()->channel()->transport_name());
1844 }
1845 }
1846 if (pc_->rtp_data_channel()) {
1847 transport_names.insert(pc_->rtp_data_channel()->transport_name());
1848 }
1849 if (pc_->sctp_transport_name()) {
1850 transport_names.insert(*pc_->sctp_transport_name());
1851 }
1852 return transport_names;
1853}
1854
hbos82ebe022016-11-14 01:41:09 -08001855void RTCStatsCollector::OnDataChannelCreated(DataChannel* channel) {
1856 channel->SignalOpened.connect(this, &RTCStatsCollector::OnDataChannelOpened);
1857 channel->SignalClosed.connect(this, &RTCStatsCollector::OnDataChannelClosed);
1858}
1859
1860void RTCStatsCollector::OnDataChannelOpened(DataChannel* channel) {
1861 RTC_DCHECK(signaling_thread_->IsCurrent());
Jonas Olssona4d87372019-07-05 19:08:33 +02001862 bool result = internal_record_.opened_data_channels
1863 .insert(reinterpret_cast<uintptr_t>(channel))
1864 .second;
hbos82ebe022016-11-14 01:41:09 -08001865 ++internal_record_.data_channels_opened;
1866 RTC_DCHECK(result);
1867}
1868
1869void RTCStatsCollector::OnDataChannelClosed(DataChannel* channel) {
1870 RTC_DCHECK(signaling_thread_->IsCurrent());
1871 // Only channels that have been fully opened (and have increased the
1872 // |data_channels_opened_| counter) increase the closed counter.
hbos5bf9def2017-03-20 03:14:14 -07001873 if (internal_record_.opened_data_channels.erase(
1874 reinterpret_cast<uintptr_t>(channel))) {
hbos82ebe022016-11-14 01:41:09 -08001875 ++internal_record_.data_channels_closed;
1876 }
1877}
1878
hboscc555c52016-10-18 12:48:31 -07001879const char* CandidateTypeToRTCIceCandidateTypeForTesting(
1880 const std::string& type) {
1881 return CandidateTypeToRTCIceCandidateType(type);
1882}
1883
1884const char* DataStateToRTCDataChannelStateForTesting(
1885 DataChannelInterface::DataState state) {
1886 return DataStateToRTCDataChannelState(state);
1887}
1888
hbosd565b732016-08-30 14:04:35 -07001889} // namespace webrtc