blob: 16a012b50c29f970fbb446e269f9e0e0a2fc3f52 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "pc/statscollector.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
jbauch555604a2016-04-26 03:13:22 -070013#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014#include <utility>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "pc/channel.h"
18#include "pc/peerconnection.h"
19#include "rtc_base/base64.h"
20#include "rtc_base/checks.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
22namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000023namespace {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024
guoweis@webrtc.org950c5182014-12-16 23:01:31 +000025// The following is the enum RTCStatsIceCandidateType from
26// http://w3c.github.io/webrtc-stats/#rtcstatsicecandidatetype-enum such that
27// our stats report for ice candidate type could conform to that.
28const char STATSREPORT_LOCAL_PORT_TYPE[] = "host";
29const char STATSREPORT_STUN_PORT_TYPE[] = "serverreflexive";
30const char STATSREPORT_PRFLX_PORT_TYPE[] = "peerreflexive";
31const char STATSREPORT_RELAY_PORT_TYPE[] = "relayed";
32
33// Strings used by the stats collector to report adapter types. This fits the
34// general stype of http://w3c.github.io/webrtc-stats than what
35// AdapterTypeToString does.
36const char* STATSREPORT_ADAPTER_TYPE_ETHERNET = "lan";
37const char* STATSREPORT_ADAPTER_TYPE_WIFI = "wlan";
38const char* STATSREPORT_ADAPTER_TYPE_WWAN = "wwan";
39const char* STATSREPORT_ADAPTER_TYPE_VPN = "vpn";
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000040const char* STATSREPORT_ADAPTER_TYPE_LOOPBACK = "loopback";
guoweis@webrtc.org950c5182014-12-16 23:01:31 +000041
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000042template<typename ValueType>
43struct TypeForAdd {
tommi@webrtc.org92f40182015-03-04 15:25:19 +000044 const StatsReport::StatsValueName name;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000045 const ValueType& value;
tommi@webrtc.org92f40182015-03-04 15:25:19 +000046};
47
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000048typedef TypeForAdd<bool> BoolForAdd;
49typedef TypeForAdd<float> FloatForAdd;
Peter Boström0c4e06b2015-10-07 12:23:21 +020050typedef TypeForAdd<int64_t> Int64ForAdd;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000051typedef TypeForAdd<int> IntForAdd;
tommi@webrtc.org92f40182015-03-04 15:25:19 +000052
jbauchbe24c942015-06-22 15:06:43 -070053StatsReport* AddTrackReport(StatsCollection* reports,
54 const std::string& track_id) {
xians@webrtc.org01bda202014-07-09 07:38:38 +000055 // Adds an empty track report.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000056 StatsReport::Id id(
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000057 StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, track_id));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000058 StatsReport* report = reports->ReplaceOrAddNew(id);
tommi@webrtc.org92f40182015-03-04 15:25:19 +000059 report->AddString(StatsReport::kStatsValueNameTrackId, track_id);
jbauchbe24c942015-06-22 15:06:43 -070060 return report;
xians@webrtc.org01bda202014-07-09 07:38:38 +000061}
62
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063template <class TrackVector>
Steve Anton36b29d12017-10-30 09:57:42 -070064void CreateTrackReports(const TrackVector& tracks,
65 StatsCollection* reports,
66 TrackIdMap* track_ids) {
jbauchbe24c942015-06-22 15:06:43 -070067 for (const auto& track : tracks) {
68 const std::string& track_id = track->id();
69 StatsReport* report = AddTrackReport(reports, track_id);
henrikg91d6ede2015-09-17 00:24:34 -070070 RTC_DCHECK(report != nullptr);
Steve Anton36b29d12017-10-30 09:57:42 -070071 (*track_ids)[track_id] = report;
jbauchbe24c942015-06-22 15:06:43 -070072 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073}
74
tommi@webrtc.org92f40182015-03-04 15:25:19 +000075void ExtractCommonSendProperties(const cricket::MediaSenderInfo& info,
76 StatsReport* report) {
77 report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name);
78 report->AddInt64(StatsReport::kStatsValueNameBytesSent, info.bytes_sent);
zhihuang6ba3b192016-05-13 11:46:35 -070079 if (info.rtt_ms >= 0) {
80 report->AddInt64(StatsReport::kStatsValueNameRtt, info.rtt_ms);
81 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +000082}
83
pbosf42376c2015-08-28 07:35:32 -070084void ExtractCommonReceiveProperties(const cricket::MediaReceiverInfo& info,
85 StatsReport* report) {
86 report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name);
87}
88
Ivo Creusen56d46092017-11-24 17:29:59 +010089void SetAudioProcessingStats(StatsReport* report,
90 bool typing_noise_detected,
91 const AudioProcessingStats& apm_stats) {
tommi@webrtc.org92f40182015-03-04 15:25:19 +000092 report->AddBoolean(StatsReport::kStatsValueNameTypingNoiseState,
93 typing_noise_detected);
Ivo Creusen56d46092017-11-24 17:29:59 +010094 if (apm_stats.delay_median_ms) {
Ivo Creusenae026092017-11-20 13:07:16 +010095 report->AddInt(StatsReport::kStatsValueNameEchoDelayMedian,
Ivo Creusen56d46092017-11-24 17:29:59 +010096 *apm_stats.delay_median_ms);
Ivo Creusenae026092017-11-20 13:07:16 +010097 }
Ivo Creusen56d46092017-11-24 17:29:59 +010098 if (apm_stats.delay_standard_deviation_ms) {
Ivo Creusenae026092017-11-20 13:07:16 +010099 report->AddInt(StatsReport::kStatsValueNameEchoDelayStdDev,
Ivo Creusen56d46092017-11-24 17:29:59 +0100100 *apm_stats.delay_standard_deviation_ms);
zhihuang6ba3b192016-05-13 11:46:35 -0700101 }
Ivo Creusen56d46092017-11-24 17:29:59 +0100102 if (apm_stats.echo_return_loss) {
Ivo Creusenae026092017-11-20 13:07:16 +0100103 report->AddInt(StatsReport::kStatsValueNameEchoReturnLoss,
Ivo Creusen56d46092017-11-24 17:29:59 +0100104 *apm_stats.echo_return_loss);
henrik.lundin04a057b2017-01-16 23:53:59 -0800105 }
Ivo Creusen56d46092017-11-24 17:29:59 +0100106 if (apm_stats.echo_return_loss_enhancement) {
Ivo Creusenae026092017-11-20 13:07:16 +0100107 report->AddInt(StatsReport::kStatsValueNameEchoReturnLossEnhancement,
Ivo Creusen56d46092017-11-24 17:29:59 +0100108 *apm_stats.echo_return_loss_enhancement);
Ivo Creusenae026092017-11-20 13:07:16 +0100109 }
Ivo Creusen56d46092017-11-24 17:29:59 +0100110 if (apm_stats.residual_echo_likelihood) {
Ivo Creusenae026092017-11-20 13:07:16 +0100111 report->AddFloat(StatsReport::kStatsValueNameResidualEchoLikelihood,
Ivo Creusen56d46092017-11-24 17:29:59 +0100112 static_cast<float>(*apm_stats.residual_echo_likelihood));
Ivo Creusenae026092017-11-20 13:07:16 +0100113 }
Ivo Creusen56d46092017-11-24 17:29:59 +0100114 if (apm_stats.residual_echo_likelihood_recent_max) {
ivoc4e477a12017-01-15 08:29:46 -0800115 report->AddFloat(
116 StatsReport::kStatsValueNameResidualEchoLikelihoodRecentMax,
Ivo Creusen56d46092017-11-24 17:29:59 +0100117 static_cast<float>(*apm_stats.residual_echo_likelihood_recent_max));
118 }
119 if (apm_stats.divergent_filter_fraction) {
120 report->AddFloat(StatsReport::kStatsValueNameAecDivergentFilterFraction,
121 static_cast<float>(*apm_stats.divergent_filter_fraction));
ivoc8c63a822016-10-21 04:10:03 -0700122 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000123}
124
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125void ExtractStats(const cricket::VoiceReceiverInfo& info, StatsReport* report) {
pbosf42376c2015-08-28 07:35:32 -0700126 ExtractCommonReceiveProperties(info, report);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000127 const FloatForAdd floats[] = {
128 { StatsReport::kStatsValueNameExpandRate, info.expand_rate },
129 { StatsReport::kStatsValueNameSecondaryDecodedRate,
130 info.secondary_decoded_rate },
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200131 { StatsReport::kStatsValueNameSecondaryDiscardedRate,
132 info.secondary_discarded_rate },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000133 { StatsReport::kStatsValueNameSpeechExpandRate, info.speech_expand_rate },
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200134 { StatsReport::kStatsValueNameAccelerateRate, info.accelerate_rate },
135 { StatsReport::kStatsValueNamePreemptiveExpandRate,
136 info.preemptive_expand_rate },
zsteine76bd3a2017-07-14 12:17:49 -0700137 { StatsReport::kStatsValueNameTotalAudioEnergy, info.total_output_energy },
138 { StatsReport::kStatsValueNameTotalSamplesDuration,
139 info.total_output_duration }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000140 };
141
142 const IntForAdd ints[] = {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000143 { StatsReport::kStatsValueNameCurrentDelayMs, info.delay_estimate_ms },
144 { StatsReport::kStatsValueNameDecodingCNG, info.decoding_cng },
145 { StatsReport::kStatsValueNameDecodingCTN, info.decoding_calls_to_neteq },
146 { StatsReport::kStatsValueNameDecodingCTSG,
147 info.decoding_calls_to_silence_generator },
henrik.lundin63489782016-09-20 01:47:12 -0700148 { StatsReport::kStatsValueNameDecodingMutedOutput,
149 info.decoding_muted_output },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000150 { StatsReport::kStatsValueNameDecodingNormal, info.decoding_normal },
151 { StatsReport::kStatsValueNameDecodingPLC, info.decoding_plc },
152 { StatsReport::kStatsValueNameDecodingPLCCNG, info.decoding_plc_cng },
153 { StatsReport::kStatsValueNameJitterBufferMs, info.jitter_buffer_ms },
154 { StatsReport::kStatsValueNameJitterReceived, info.jitter_ms },
155 { StatsReport::kStatsValueNamePacketsLost, info.packets_lost },
156 { StatsReport::kStatsValueNamePacketsReceived, info.packets_rcvd },
157 { StatsReport::kStatsValueNamePreferredJitterBufferMs,
158 info.jitter_buffer_preferred_ms },
159 };
160
161 for (const auto& f : floats)
162 report->AddFloat(f.name, f.value);
163
164 for (const auto& i : ints)
165 report->AddInt(i.name, i.value);
zhihuang6ba3b192016-05-13 11:46:35 -0700166 if (info.audio_level >= 0) {
167 report->AddInt(StatsReport::kStatsValueNameAudioOutputLevel,
168 info.audio_level);
169 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000170
171 report->AddInt64(StatsReport::kStatsValueNameBytesReceived,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 info.bytes_rcvd);
zhihuang6ba3b192016-05-13 11:46:35 -0700173 if (info.capture_start_ntp_time_ms >= 0) {
174 report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs,
175 info.capture_start_ntp_time_ms);
176 }
fippobec70ab2016-01-28 01:27:15 -0800177 report->AddString(StatsReport::kStatsValueNameMediaType, "audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178}
179
180void ExtractStats(const cricket::VoiceSenderInfo& info, StatsReport* report) {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000181 ExtractCommonSendProperties(info, report);
182
Ivo Creusen56d46092017-11-24 17:29:59 +0100183 SetAudioProcessingStats(report, info.typing_noise_detected,
184 info.apm_statistics);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000185
zsteine76bd3a2017-07-14 12:17:49 -0700186 const FloatForAdd floats[] = {
187 { StatsReport::kStatsValueNameTotalAudioEnergy, info.total_input_energy },
188 { StatsReport::kStatsValueNameTotalSamplesDuration,
189 info.total_input_duration }
190 };
191
andrew2fe1cb02015-11-27 17:27:35 -0800192 RTC_DCHECK_GE(info.audio_level, 0);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000193 const IntForAdd ints[] = {
andrew2fe1cb02015-11-27 17:27:35 -0800194 { StatsReport::kStatsValueNameAudioInputLevel, info.audio_level},
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000195 { StatsReport::kStatsValueNameJitterReceived, info.jitter_ms },
196 { StatsReport::kStatsValueNamePacketsLost, info.packets_lost },
197 { StatsReport::kStatsValueNamePacketsSent, info.packets_sent },
198 };
199
zsteine76bd3a2017-07-14 12:17:49 -0700200 for (const auto& f : floats) {
201 report->AddFloat(f.name, f.value);
202 }
203
zhihuang6ba3b192016-05-13 11:46:35 -0700204 for (const auto& i : ints) {
205 if (i.value >= 0) {
206 report->AddInt(i.name, i.value);
207 }
208 }
fippobec70ab2016-01-28 01:27:15 -0800209 report->AddString(StatsReport::kStatsValueNameMediaType, "audio");
ivoce1198e02017-09-08 08:13:19 -0700210 if (info.ana_statistics.bitrate_action_counter) {
211 report->AddInt(StatsReport::kStatsValueNameAnaBitrateActionCounter,
212 *info.ana_statistics.bitrate_action_counter);
213 }
214 if (info.ana_statistics.channel_action_counter) {
215 report->AddInt(StatsReport::kStatsValueNameAnaChannelActionCounter,
216 *info.ana_statistics.channel_action_counter);
217 }
218 if (info.ana_statistics.dtx_action_counter) {
219 report->AddInt(StatsReport::kStatsValueNameAnaDtxActionCounter,
220 *info.ana_statistics.dtx_action_counter);
221 }
222 if (info.ana_statistics.fec_action_counter) {
223 report->AddInt(StatsReport::kStatsValueNameAnaFecActionCounter,
224 *info.ana_statistics.fec_action_counter);
225 }
ivoc0d0b9122017-09-08 13:24:21 -0700226 if (info.ana_statistics.frame_length_increase_counter) {
227 report->AddInt(StatsReport::kStatsValueNameAnaFrameLengthIncreaseCounter,
228 *info.ana_statistics.frame_length_increase_counter);
229 }
230 if (info.ana_statistics.frame_length_decrease_counter) {
231 report->AddInt(StatsReport::kStatsValueNameAnaFrameLengthDecreaseCounter,
232 *info.ana_statistics.frame_length_decrease_counter);
233 }
234 if (info.ana_statistics.uplink_packet_loss_fraction) {
235 report->AddFloat(StatsReport::kStatsValueNameAnaUplinkPacketLossFraction,
236 *info.ana_statistics.uplink_packet_loss_fraction);
ivoce1198e02017-09-08 08:13:19 -0700237 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238}
239
240void ExtractStats(const cricket::VideoReceiverInfo& info, StatsReport* report) {
pbosf42376c2015-08-28 07:35:32 -0700241 ExtractCommonReceiveProperties(info, report);
Peter Boströmb7d9a972015-12-18 16:01:11 +0100242 report->AddString(StatsReport::kStatsValueNameCodecImplementationName,
243 info.decoder_implementation_name);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000244 report->AddInt64(StatsReport::kStatsValueNameBytesReceived,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 info.bytes_rcvd);
zhihuang6ba3b192016-05-13 11:46:35 -0700246 if (info.capture_start_ntp_time_ms >= 0) {
247 report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs,
248 info.capture_start_ntp_time_ms);
249 }
sakalcc452e12017-02-09 04:53:45 -0800250 if (info.qp_sum)
251 report->AddInt64(StatsReport::kStatsValueNameQpSum, *info.qp_sum);
252
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000253 const IntForAdd ints[] = {
254 { StatsReport::kStatsValueNameCurrentDelayMs, info.current_delay_ms },
255 { StatsReport::kStatsValueNameDecodeMs, info.decode_ms },
256 { StatsReport::kStatsValueNameFirsSent, info.firs_sent },
257 { StatsReport::kStatsValueNameFrameHeightReceived, info.frame_height },
258 { StatsReport::kStatsValueNameFrameRateDecoded, info.framerate_decoded },
259 { StatsReport::kStatsValueNameFrameRateOutput, info.framerate_output },
260 { StatsReport::kStatsValueNameFrameRateReceived, info.framerate_rcvd },
261 { StatsReport::kStatsValueNameFrameWidthReceived, info.frame_width },
262 { StatsReport::kStatsValueNameJitterBufferMs, info.jitter_buffer_ms },
263 { StatsReport::kStatsValueNameMaxDecodeMs, info.max_decode_ms },
264 { StatsReport::kStatsValueNameMinPlayoutDelayMs,
265 info.min_playout_delay_ms },
266 { StatsReport::kStatsValueNameNacksSent, info.nacks_sent },
267 { StatsReport::kStatsValueNamePacketsLost, info.packets_lost },
268 { StatsReport::kStatsValueNamePacketsReceived, info.packets_rcvd },
269 { StatsReport::kStatsValueNamePlisSent, info.plis_sent },
270 { StatsReport::kStatsValueNameRenderDelayMs, info.render_delay_ms },
271 { StatsReport::kStatsValueNameTargetDelayMs, info.target_delay_ms },
sakale5ba44e2016-10-26 07:09:24 -0700272 { StatsReport::kStatsValueNameFramesDecoded, info.frames_decoded },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000273 };
274
275 for (const auto& i : ints)
276 report->AddInt(i.name, i.value);
fippobec70ab2016-01-28 01:27:15 -0800277 report->AddString(StatsReport::kStatsValueNameMediaType, "video");
ilnikf04afde2017-07-07 01:26:24 -0700278
ilnik2edc6842017-07-06 03:06:50 -0700279 if (info.timing_frame_info) {
280 report->AddString(StatsReport::kStatsValueNameTimingFrameInfo,
281 info.timing_frame_info->ToString());
282 }
ilnikf04afde2017-07-07 01:26:24 -0700283
ilnika79cc282017-08-23 05:24:10 -0700284 report->AddInt64(StatsReport::kStatsValueNameInterframeDelayMaxMs,
285 info.interframe_delay_max_ms);
ilnik2e1b40b2017-09-04 07:57:17 -0700286
287 report->AddString(
288 StatsReport::kStatsValueNameContentType,
289 webrtc::videocontenttypehelpers::ToString(info.content_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290}
291
292void ExtractStats(const cricket::VideoSenderInfo& info, StatsReport* report) {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000293 ExtractCommonSendProperties(info, report);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294
Peter Boströmb7d9a972015-12-18 16:01:11 +0100295 report->AddString(StatsReport::kStatsValueNameCodecImplementationName,
296 info.encoder_implementation_name);
mallinath@webrtc.org62451dc2013-12-13 12:29:34 +0000297 report->AddBoolean(StatsReport::kStatsValueNameBandwidthLimitedResolution,
298 (info.adapt_reason & 0x2) > 0);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000299 report->AddBoolean(StatsReport::kStatsValueNameCpuLimitedResolution,
300 (info.adapt_reason & 0x1) > 0);
Åsa Perssonc3ed6302017-11-16 14:04:52 +0100301 report->AddBoolean(StatsReport::kStatsValueNameHasEnteredLowResolution,
302 info.has_entered_low_resolution);
303
sakal87da4042016-10-31 06:53:47 -0700304 if (info.qp_sum)
305 report->AddInt(StatsReport::kStatsValueNameQpSum, *info.qp_sum);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000306
307 const IntForAdd ints[] = {
308 { StatsReport::kStatsValueNameAdaptationChanges, info.adapt_changes },
309 { StatsReport::kStatsValueNameAvgEncodeMs, info.avg_encode_ms },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000310 { StatsReport::kStatsValueNameEncodeUsagePercent,
311 info.encode_usage_percent },
312 { StatsReport::kStatsValueNameFirsReceived, info.firs_rcvd },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000313 { StatsReport::kStatsValueNameFrameHeightSent, info.send_frame_height },
314 { StatsReport::kStatsValueNameFrameRateInput, info.framerate_input },
315 { StatsReport::kStatsValueNameFrameRateSent, info.framerate_sent },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000316 { StatsReport::kStatsValueNameFrameWidthSent, info.send_frame_width },
317 { StatsReport::kStatsValueNameNacksReceived, info.nacks_rcvd },
318 { StatsReport::kStatsValueNamePacketsLost, info.packets_lost },
319 { StatsReport::kStatsValueNamePacketsSent, info.packets_sent },
320 { StatsReport::kStatsValueNamePlisReceived, info.plis_rcvd },
sakal43536c32016-10-24 01:46:43 -0700321 { StatsReport::kStatsValueNameFramesEncoded, info.frames_encoded },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000322 };
323
324 for (const auto& i : ints)
325 report->AddInt(i.name, i.value);
fippobec70ab2016-01-28 01:27:15 -0800326 report->AddString(StatsReport::kStatsValueNameMediaType, "video");
ilnik50864a82017-09-06 12:32:35 -0700327 report->AddString(
328 StatsReport::kStatsValueNameContentType,
329 webrtc::videocontenttypehelpers::ToString(info.content_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330}
331
332void ExtractStats(const cricket::BandwidthEstimationInfo& info,
333 double stats_gathering_started,
334 StatsReport* report) {
henrikg91d6ede2015-09-17 00:24:34 -0700335 RTC_DCHECK(report->type() == StatsReport::kStatsReportTypeBwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000337 report->set_timestamp(stats_gathering_started);
338 const IntForAdd ints[] = {
339 { StatsReport::kStatsValueNameAvailableSendBandwidth,
340 info.available_send_bandwidth },
341 { StatsReport::kStatsValueNameAvailableReceiveBandwidth,
342 info.available_recv_bandwidth },
343 { StatsReport::kStatsValueNameTargetEncBitrate, info.target_enc_bitrate },
344 { StatsReport::kStatsValueNameActualEncBitrate, info.actual_enc_bitrate },
345 { StatsReport::kStatsValueNameRetransmitBitrate, info.retransmit_bitrate },
346 { StatsReport::kStatsValueNameTransmitBitrate, info.transmit_bitrate },
347 };
348 for (const auto& i : ints)
349 report->AddInt(i.name, i.value);
350 report->AddInt64(StatsReport::kStatsValueNameBucketDelay, info.bucket_delay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351}
352
wu@webrtc.org97077a32013-10-25 21:18:33 +0000353void ExtractRemoteStats(const cricket::MediaSenderInfo& info,
354 StatsReport* report) {
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000355 report->set_timestamp(info.remote_stats[0].timestamp);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000356 // TODO(hta): Extract some stats here.
357}
358
359void ExtractRemoteStats(const cricket::MediaReceiverInfo& info,
360 StatsReport* report) {
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000361 report->set_timestamp(info.remote_stats[0].timestamp);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000362 // TODO(hta): Extract some stats here.
363}
364
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365// Template to extract stats from a data vector.
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000366// In order to use the template, the functions that are called from it,
367// ExtractStats and ExtractRemoteStats, must be defined and overloaded
368// for each type.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369template<typename T>
370void ExtractStatsFromList(const std::vector<T>& data,
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000371 const StatsReport::Id& transport_id,
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000372 StatsCollector* collector,
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000373 StatsReport::Direction direction) {
374 for (const auto& d : data) {
Peter Boström0c4e06b2015-10-07 12:23:21 +0200375 uint32_t ssrc = d.ssrc();
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000376 // Each track can have stats for both local and remote objects.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000377 // TODO(hta): Handle the case of multiple SSRCs per object.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000378 StatsReport* report = collector->PrepareReport(true, ssrc, transport_id,
379 direction);
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000380 if (report)
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000381 ExtractStats(d, report);
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000382
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000383 if (!d.remote_stats.empty()) {
384 report = collector->PrepareReport(false, ssrc, transport_id, direction);
385 if (report)
386 ExtractRemoteStats(d, report);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000387 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 }
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000389}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390
391} // namespace
392
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000393const char* IceCandidateTypeToStatsType(const std::string& candidate_type) {
394 if (candidate_type == cricket::LOCAL_PORT_TYPE) {
395 return STATSREPORT_LOCAL_PORT_TYPE;
396 }
397 if (candidate_type == cricket::STUN_PORT_TYPE) {
398 return STATSREPORT_STUN_PORT_TYPE;
399 }
400 if (candidate_type == cricket::PRFLX_PORT_TYPE) {
401 return STATSREPORT_PRFLX_PORT_TYPE;
402 }
403 if (candidate_type == cricket::RELAY_PORT_TYPE) {
404 return STATSREPORT_RELAY_PORT_TYPE;
405 }
nisseeb4ca4e2017-01-12 02:24:27 -0800406 RTC_NOTREACHED();
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000407 return "unknown";
408}
409
410const char* AdapterTypeToStatsType(rtc::AdapterType type) {
411 switch (type) {
412 case rtc::ADAPTER_TYPE_UNKNOWN:
413 return "unknown";
414 case rtc::ADAPTER_TYPE_ETHERNET:
415 return STATSREPORT_ADAPTER_TYPE_ETHERNET;
416 case rtc::ADAPTER_TYPE_WIFI:
417 return STATSREPORT_ADAPTER_TYPE_WIFI;
418 case rtc::ADAPTER_TYPE_CELLULAR:
419 return STATSREPORT_ADAPTER_TYPE_WWAN;
420 case rtc::ADAPTER_TYPE_VPN:
421 return STATSREPORT_ADAPTER_TYPE_VPN;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000422 case rtc::ADAPTER_TYPE_LOOPBACK:
423 return STATSREPORT_ADAPTER_TYPE_LOOPBACK;
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000424 default:
nisseeb4ca4e2017-01-12 02:24:27 -0800425 RTC_NOTREACHED();
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000426 return "";
427 }
428}
429
deadbeefab9b2d12015-10-14 11:33:11 -0700430StatsCollector::StatsCollector(PeerConnection* pc)
431 : pc_(pc), stats_gathering_started_(0) {
432 RTC_DCHECK(pc_);
tommi@webrtc.org03505bc2014-07-14 20:15:26 +0000433}
434
435StatsCollector::~StatsCollector() {
Steve Anton978b8762017-09-29 12:15:02 -0700436 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437}
438
nissecdf37a92016-09-13 23:41:47 -0700439// Wallclock time in ms.
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000440double StatsCollector::GetTimeNow() {
nissecdf37a92016-09-13 23:41:47 -0700441 return rtc::TimeUTCMicros() /
442 static_cast<double>(rtc::kNumMicrosecsPerMillisec);
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000443}
444
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445// Adds a MediaStream with tracks that can be used as a |selector| in a call
446// to GetStats.
447void StatsCollector::AddStream(MediaStreamInterface* stream) {
Steve Anton978b8762017-09-29 12:15:02 -0700448 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700449 RTC_DCHECK(stream != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450
Steve Anton36b29d12017-10-30 09:57:42 -0700451 CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), &reports_,
452 &track_ids_);
453 CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), &reports_,
454 &track_ids_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455}
456
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000457void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200458 uint32_t ssrc) {
Steve Anton978b8762017-09-29 12:15:02 -0700459 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700460 RTC_DCHECK(audio_track != NULL);
kwiberg5377bc72016-10-04 13:46:56 -0700461#if RTC_DCHECK_IS_ON
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000462 for (const auto& track : local_audio_tracks_)
henrikg91d6ede2015-09-17 00:24:34 -0700463 RTC_DCHECK(track.first != audio_track || track.second != ssrc);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000464#endif
xians@webrtc.org01bda202014-07-09 07:38:38 +0000465
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000466 local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc));
xians@webrtc.org01bda202014-07-09 07:38:38 +0000467
468 // Create the kStatsReportTypeTrack report for the new track if there is no
469 // report yet.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000470 StatsReport::Id id(StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack,
471 audio_track->id()));
472 StatsReport* report = reports_.Find(id);
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000473 if (!report) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000474 report = reports_.InsertNew(id);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000475 report->AddString(StatsReport::kStatsValueNameTrackId, audio_track->id());
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000476 }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000477}
478
479void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200480 uint32_t ssrc) {
henrikg91d6ede2015-09-17 00:24:34 -0700481 RTC_DCHECK(audio_track != NULL);
deadbeef19b3a552017-06-16 20:19:08 -0700482 local_audio_tracks_.erase(
483 std::remove_if(
484 local_audio_tracks_.begin(), local_audio_tracks_.end(),
485 [audio_track, ssrc](const LocalAudioTrackVector::value_type& track) {
486 return track.first == audio_track && track.second == ssrc;
487 }),
488 local_audio_tracks_.end());
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000489}
490
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000491void StatsCollector::GetStats(MediaStreamTrackInterface* track,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492 StatsReports* reports) {
Steve Anton978b8762017-09-29 12:15:02 -0700493 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700494 RTC_DCHECK(reports != NULL);
495 RTC_DCHECK(reports->empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000497 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
498
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 if (!track) {
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000500 reports->reserve(reports_.size());
501 for (auto* r : reports_)
502 reports->push_back(r);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000503 return;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 }
505
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000506 StatsReport* report = reports_.Find(StatsReport::NewTypedId(
Steve Anton978b8762017-09-29 12:15:02 -0700507 StatsReport::kStatsReportTypeSession, pc_->session_id()));
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000508 if (report)
509 reports->push_back(report);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000511 report = reports_.Find(StatsReport::NewTypedId(
512 StatsReport::kStatsReportTypeTrack, track->id()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000514 if (!report)
515 return;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000516
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000517 reports->push_back(report);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518
519 std::string track_id;
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000520 for (const auto* r : reports_) {
521 if (r->type() != StatsReport::kStatsReportTypeSsrc)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 continue;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000523
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000524 const StatsReport::Value* v =
525 r->FindValue(StatsReport::kStatsValueNameTrackId);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000526 if (v && v->string_val() == track->id())
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000527 reports->push_back(r);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529}
530
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000531void
532StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) {
Steve Anton978b8762017-09-29 12:15:02 -0700533 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 double time_now = GetTimeNow();
535 // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of
536 // ms apart will be ignored.
537 const double kMinGatherStatsPeriod = 50;
xians@webrtc.org01bda202014-07-09 07:38:38 +0000538 if (stats_gathering_started_ != 0 &&
539 stats_gathering_started_ + kMinGatherStatsPeriod > time_now) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540 return;
541 }
542 stats_gathering_started_ = time_now;
543
Steve Anton75737c02017-11-06 10:37:17 -0800544 // TODO(tommi): All of these hop over to the worker thread to fetch
545 // information. We could use an AsyncInvoker to run all of these and post
546 // the information back to the signaling thread where we can create and
547 // update stats reports. That would also clean up the threading story a bit
548 // since we'd be creating/updating the stats report objects consistently on
549 // the same thread (this class has no locks right now).
550 ExtractSessionInfo();
551 ExtractBweInfo();
552 ExtractVoiceInfo();
553 ExtractVideoInfo(level);
554 ExtractSenderInfo();
555 ExtractDataInfo();
556 UpdateTrackReports();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557}
558
deadbeefab9b2d12015-10-14 11:33:11 -0700559StatsReport* StatsCollector::PrepareReport(
560 bool local,
561 uint32_t ssrc,
562 const StatsReport::Id& transport_id,
563 StatsReport::Direction direction) {
Steve Anton978b8762017-09-29 12:15:02 -0700564 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000565 StatsReport::Id id(StatsReport::NewIdWithDirection(
Peter Boström0c4e06b2015-10-07 12:23:21 +0200566 local ? StatsReport::kStatsReportTypeSsrc
567 : StatsReport::kStatsReportTypeRemoteSsrc,
568 rtc::ToString<uint32_t>(ssrc), direction));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000569 StatsReport* report = reports_.Find(id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570
xians@webrtc.org01bda202014-07-09 07:38:38 +0000571 // Use the ID of the track that is currently mapped to the SSRC, if any.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 std::string track_id;
xians@webrtc.org01bda202014-07-09 07:38:38 +0000573 if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) {
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000574 if (!report) {
xians@webrtc.org01bda202014-07-09 07:38:38 +0000575 // The ssrc is not used by any track or existing report, return NULL
576 // in such case to indicate no report is prepared for the ssrc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 return NULL;
xians@webrtc.org01bda202014-07-09 07:38:38 +0000578 }
579
580 // The ssrc is not used by any existing track. Keeps the old track id
581 // since we want to report the stats for inactive ssrc.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000582 const StatsReport::Value* v =
583 report->FindValue(StatsReport::kStatsValueNameTrackId);
584 if (v)
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000585 track_id = v->string_val();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586 }
587
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000588 if (!report)
589 report = reports_.InsertNew(id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000591 // FYI - for remote reports, the timestamp will be overwritten later.
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000592 report->set_timestamp(stats_gathering_started_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000594 report->AddInt64(StatsReport::kStatsValueNameSsrc, ssrc);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000595 report->AddString(StatsReport::kStatsValueNameTrackId, track_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 // Add the mapping of SSRC to transport.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000597 report->AddId(StatsReport::kStatsValueNameTransportId, transport_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 return report;
599}
600
zhihuange9e94c32016-11-04 11:38:15 -0700601bool StatsCollector::IsValidTrack(const std::string& track_id) {
602 return reports_.Find(StatsReport::NewTypedId(
603 StatsReport::kStatsReportTypeTrack, track_id)) != nullptr;
604}
605
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000606StatsReport* StatsCollector::AddCertificateReports(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000607 const rtc::SSLCertificate* cert) {
Steve Anton978b8762017-09-29 12:15:02 -0700608 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700609 RTC_DCHECK(cert != NULL);
wu@webrtc.org4551b792013-10-09 15:37:36 +0000610
hbose29352b2016-08-25 03:52:38 -0700611 std::unique_ptr<rtc::SSLCertificateStats> first_stats = cert->GetStats();
612 StatsReport* first_report = nullptr;
613 StatsReport* prev_report = nullptr;
614 for (rtc::SSLCertificateStats* stats = first_stats.get(); stats;
615 stats = stats->issuer.get()) {
616 StatsReport::Id id(StatsReport::NewTypedId(
617 StatsReport::kStatsReportTypeCertificate, stats->fingerprint));
618
619 StatsReport* report = reports_.ReplaceOrAddNew(id);
620 report->set_timestamp(stats_gathering_started_);
621 report->AddString(StatsReport::kStatsValueNameFingerprint,
622 stats->fingerprint);
623 report->AddString(StatsReport::kStatsValueNameFingerprintAlgorithm,
624 stats->fingerprint_algorithm);
625 report->AddString(StatsReport::kStatsValueNameDer,
626 stats->base64_certificate);
627 if (!first_report)
628 first_report = report;
629 else
630 prev_report->AddId(StatsReport::kStatsValueNameIssuerId, id);
631 prev_report = report;
wu@webrtc.org4551b792013-10-09 15:37:36 +0000632 }
hbose29352b2016-08-25 03:52:38 -0700633 return first_report;
wu@webrtc.org4551b792013-10-09 15:37:36 +0000634}
635
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000636StatsReport* StatsCollector::AddConnectionInfoReport(
637 const std::string& content_name, int component, int connection_id,
638 const StatsReport::Id& channel_report_id,
639 const cricket::ConnectionInfo& info) {
640 StatsReport::Id id(StatsReport::NewCandidatePairId(content_name, component,
641 connection_id));
642 StatsReport* report = reports_.ReplaceOrAddNew(id);
643 report->set_timestamp(stats_gathering_started_);
644
645 const BoolForAdd bools[] = {
Peter Thatcher04ac81f2015-09-21 11:48:28 -0700646 {StatsReport::kStatsValueNameActiveConnection, info.best_connection},
647 {StatsReport::kStatsValueNameReceiving, info.receiving},
648 {StatsReport::kStatsValueNameWritable, info.writable},
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000649 };
650 for (const auto& b : bools)
651 report->AddBoolean(b.name, b.value);
652
653 report->AddId(StatsReport::kStatsValueNameChannelId, channel_report_id);
654 report->AddId(StatsReport::kStatsValueNameLocalCandidateId,
655 AddCandidateReport(info.local_candidate, true)->id());
656 report->AddId(StatsReport::kStatsValueNameRemoteCandidateId,
657 AddCandidateReport(info.remote_candidate, false)->id());
658
659 const Int64ForAdd int64s[] = {
zhihuang5ecf16c2016-06-01 17:09:15 -0700660 {StatsReport::kStatsValueNameBytesReceived, info.recv_total_bytes},
661 {StatsReport::kStatsValueNameBytesSent, info.sent_total_bytes},
662 {StatsReport::kStatsValueNamePacketsSent, info.sent_total_packets},
663 {StatsReport::kStatsValueNameRtt, info.rtt},
664 {StatsReport::kStatsValueNameSendPacketsDiscarded,
665 info.sent_discarded_packets},
666 {StatsReport::kStatsValueNameSentPingRequestsTotal,
667 info.sent_ping_requests_total},
668 {StatsReport::kStatsValueNameSentPingRequestsBeforeFirstResponse,
669 info.sent_ping_requests_before_first_response},
670 {StatsReport::kStatsValueNameSentPingResponses, info.sent_ping_responses},
671 {StatsReport::kStatsValueNameRecvPingRequests, info.recv_ping_requests},
672 {StatsReport::kStatsValueNameRecvPingResponses, info.recv_ping_responses},
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000673 };
674 for (const auto& i : int64s)
675 report->AddInt64(i.name, i.value);
676
677 report->AddString(StatsReport::kStatsValueNameLocalAddress,
678 info.local_candidate.address().ToString());
679 report->AddString(StatsReport::kStatsValueNameLocalCandidateType,
680 info.local_candidate.type());
681 report->AddString(StatsReport::kStatsValueNameRemoteAddress,
682 info.remote_candidate.address().ToString());
683 report->AddString(StatsReport::kStatsValueNameRemoteCandidateType,
684 info.remote_candidate.type());
685 report->AddString(StatsReport::kStatsValueNameTransportType,
686 info.local_candidate.protocol());
687
688 return report;
689}
690
691StatsReport* StatsCollector::AddCandidateReport(
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000692 const cricket::Candidate& candidate,
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000693 bool local) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000694 StatsReport::Id id(StatsReport::NewCandidateId(local, candidate.id()));
695 StatsReport* report = reports_.Find(id);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000696 if (!report) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000697 report = reports_.InsertNew(id);
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000698 report->set_timestamp(stats_gathering_started_);
699 if (local) {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000700 report->AddString(StatsReport::kStatsValueNameCandidateNetworkType,
701 AdapterTypeToStatsType(candidate.network_type()));
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000702 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000703 report->AddString(StatsReport::kStatsValueNameCandidateIPAddress,
704 candidate.address().ipaddr().ToString());
705 report->AddString(StatsReport::kStatsValueNameCandidatePortNumber,
706 candidate.address().PortAsString());
707 report->AddInt(StatsReport::kStatsValueNameCandidatePriority,
708 candidate.priority());
709 report->AddString(StatsReport::kStatsValueNameCandidateType,
710 IceCandidateTypeToStatsType(candidate.type()));
711 report->AddString(StatsReport::kStatsValueNameCandidateTransportType,
712 candidate.protocol());
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000713 }
714
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000715 return report;
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000716}
717
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718void StatsCollector::ExtractSessionInfo() {
Steve Anton978b8762017-09-29 12:15:02 -0700719 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000720
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 // Extract information from the base session.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000722 StatsReport::Id id(StatsReport::NewTypedId(
Steve Anton978b8762017-09-29 12:15:02 -0700723 StatsReport::kStatsReportTypeSession, pc_->session_id()));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000724 StatsReport* report = reports_.ReplaceOrAddNew(id);
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000725 report->set_timestamp(stats_gathering_started_);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000726 report->AddBoolean(StatsReport::kStatsValueNameInitiator,
Steve Anton978b8762017-09-29 12:15:02 -0700727 pc_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728
Steve Anton978b8762017-09-29 12:15:02 -0700729 std::unique_ptr<SessionStats> stats = pc_->GetSessionStats_s();
hbosdf6075a2016-12-19 04:58:02 -0800730 if (!stats) {
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000731 return;
732 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733
hbosdf6075a2016-12-19 04:58:02 -0800734 for (const auto& transport_iter : stats->transport_stats) {
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000735 // Attempt to get a copy of the certificates from the transport and
736 // expose them in stats reports. All channels in a transport share the
737 // same local and remote certificates.
738 //
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000739 StatsReport::Id local_cert_report_id, remote_cert_report_id;
Henrik Boströmd8281982015-08-27 10:12:24 +0200740 rtc::scoped_refptr<rtc::RTCCertificate> certificate;
Steve Anton978b8762017-09-29 12:15:02 -0700741 if (pc_->GetLocalCertificate(transport_iter.second.transport_name,
742 &certificate)) {
Henrik Boströmd8281982015-08-27 10:12:24 +0200743 StatsReport* r = AddCertificateReports(&(certificate->ssl_certificate()));
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000744 if (r)
745 local_cert_report_id = r->id();
746 }
747
jbauch555604a2016-04-26 03:13:22 -0700748 std::unique_ptr<rtc::SSLCertificate> cert =
Steve Anton978b8762017-09-29 12:15:02 -0700749 pc_->GetRemoteSSLCertificate(transport_iter.second.transport_name);
kwibergb4d01c42016-04-06 05:15:06 -0700750 if (cert) {
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000751 StatsReport* r = AddCertificateReports(cert.get());
752 if (r)
753 remote_cert_report_id = r->id();
754 }
755
756 for (const auto& channel_iter : transport_iter.second.channel_stats) {
757 StatsReport::Id id(StatsReport::NewComponentId(
deadbeefcbecd352015-09-23 11:50:27 -0700758 transport_iter.second.transport_name, channel_iter.component));
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000759 StatsReport* channel_report = reports_.ReplaceOrAddNew(id);
760 channel_report->set_timestamp(stats_gathering_started_);
761 channel_report->AddInt(StatsReport::kStatsValueNameComponent,
762 channel_iter.component);
763 if (local_cert_report_id.get()) {
764 channel_report->AddId(StatsReport::kStatsValueNameLocalCertificateId,
765 local_cert_report_id);
766 }
767 if (remote_cert_report_id.get()) {
768 channel_report->AddId(StatsReport::kStatsValueNameRemoteCertificateId,
769 remote_cert_report_id);
770 }
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800771 int srtp_crypto_suite = channel_iter.srtp_crypto_suite;
772 if (srtp_crypto_suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
773 rtc::SrtpCryptoSuiteToName(srtp_crypto_suite).length()) {
774 channel_report->AddString(
775 StatsReport::kStatsValueNameSrtpCipher,
776 rtc::SrtpCryptoSuiteToName(srtp_crypto_suite));
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000777 }
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800778 int ssl_cipher_suite = channel_iter.ssl_cipher_suite;
779 if (ssl_cipher_suite != rtc::TLS_NULL_WITH_NULL_NULL &&
780 rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite)
781 .length()) {
Guo-wei Shieh456696a2015-09-30 21:48:54 -0700782 channel_report->AddString(
783 StatsReport::kStatsValueNameDtlsCipher,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800784 rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite));
wu@webrtc.org4551b792013-10-09 15:37:36 +0000785 }
jiayl@webrtc.org06b04ec2014-07-24 20:41:20 +0000786
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000787 int connection_id = 0;
788 for (const cricket::ConnectionInfo& info :
789 channel_iter.connection_infos) {
790 StatsReport* connection_report = AddConnectionInfoReport(
791 transport_iter.first, channel_iter.component, connection_id++,
792 channel_report->id(), info);
793 if (info.best_connection) {
794 channel_report->AddId(
795 StatsReport::kStatsValueNameSelectedCandidatePairId,
796 connection_report->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 }
798 }
799 }
800 }
801}
802
stefanf79ade12017-06-02 06:44:03 -0700803void StatsCollector::ExtractBweInfo() {
Steve Anton978b8762017-09-29 12:15:02 -0700804 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
stefanf79ade12017-06-02 06:44:03 -0700805
Steve Anton978b8762017-09-29 12:15:02 -0700806 if (pc_->signaling_state() == PeerConnectionInterface::kClosed)
stefanf79ade12017-06-02 06:44:03 -0700807 return;
808
Steve Anton978b8762017-09-29 12:15:02 -0700809 webrtc::Call::Stats call_stats = pc_->GetCallStats();
stefanf79ade12017-06-02 06:44:03 -0700810 cricket::BandwidthEstimationInfo bwe_info;
811 bwe_info.available_send_bandwidth = call_stats.send_bandwidth_bps;
812 bwe_info.available_recv_bandwidth = call_stats.recv_bandwidth_bps;
813 bwe_info.bucket_delay = call_stats.pacer_delay_ms;
814 // Fill in target encoder bitrate, actual encoder bitrate, rtx bitrate, etc.
815 // TODO(holmer): Also fill this in for audio.
Steve Anton978b8762017-09-29 12:15:02 -0700816 if (pc_->video_channel()) {
817 pc_->video_channel()->FillBitrateInfo(&bwe_info);
stefanf79ade12017-06-02 06:44:03 -0700818 }
stefanf79ade12017-06-02 06:44:03 -0700819 StatsReport::Id report_id(StatsReport::NewBandwidthEstimationId());
820 StatsReport* report = reports_.FindOrAddNew(report_id);
821 ExtractStats(bwe_info, stats_gathering_started_, report);
822}
823
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824void StatsCollector::ExtractVoiceInfo() {
Steve Anton978b8762017-09-29 12:15:02 -0700825 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
tommi@webrtc.org69bc5a32014-12-15 09:44:48 +0000826
Steve Anton978b8762017-09-29 12:15:02 -0700827 if (!pc_->voice_channel()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 return;
829 }
830 cricket::VoiceMediaInfo voice_info;
Steve Anton978b8762017-09-29 12:15:02 -0700831 if (!pc_->voice_channel()->GetStats(&voice_info)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100832 RTC_LOG(LS_ERROR) << "Failed to get voice channel stats.";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 return;
834 }
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000835
836 // TODO(tommi): The above code should run on the worker thread and post the
837 // results back to the signaling thread, where we can add data to the reports.
838 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
839
Steve Anton74116482017-12-18 11:00:14 -0800840 StatsReport::Id transport_id =
841 StatsReport::NewComponentId(pc_->voice_channel()->transport_name(),
842 cricket::ICE_CANDIDATE_COMPONENT_RTP);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000843
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000844 ExtractStatsFromList(voice_info.receivers, transport_id, this,
845 StatsReport::kReceive);
846 ExtractStatsFromList(voice_info.senders, transport_id, this,
847 StatsReport::kSend);
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000848
Ivo Creusenae026092017-11-20 13:07:16 +0100849 UpdateStatsFromExistingLocalAudioTracks(voice_info.receivers.size() > 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850}
851
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000852void StatsCollector::ExtractVideoInfo(
853 PeerConnectionInterface::StatsOutputLevel level) {
Steve Anton978b8762017-09-29 12:15:02 -0700854 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
tommi@webrtc.org69bc5a32014-12-15 09:44:48 +0000855
Steve Anton74116482017-12-18 11:00:14 -0800856 if (!pc_->video_channel()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 return;
Steve Anton74116482017-12-18 11:00:14 -0800858 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 cricket::VideoMediaInfo video_info;
Steve Anton978b8762017-09-29 12:15:02 -0700860 if (!pc_->video_channel()->GetStats(&video_info)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100861 RTC_LOG(LS_ERROR) << "Failed to get video channel stats.";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 return;
863 }
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000864
865 // TODO(tommi): The above code should run on the worker thread and post the
866 // results back to the signaling thread, where we can add data to the reports.
867 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
868
Steve Anton74116482017-12-18 11:00:14 -0800869 StatsReport::Id transport_id =
870 StatsReport::NewComponentId(pc_->video_channel()->transport_name(),
871 cricket::ICE_CANDIDATE_COMPONENT_RTP);
872
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000873 ExtractStatsFromList(video_info.receivers, transport_id, this,
874 StatsReport::kReceive);
875 ExtractStatsFromList(video_info.senders, transport_id, this,
876 StatsReport::kSend);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877}
878
nissefcc640f2016-04-01 01:10:42 -0700879void StatsCollector::ExtractSenderInfo() {
Steve Anton978b8762017-09-29 12:15:02 -0700880 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
nissefcc640f2016-04-01 01:10:42 -0700881
882 for (const auto& sender : pc_->GetSenders()) {
883 // TODO(nisse): SSRC == 0 currently means none. Delete check when
884 // that is fixed.
885 if (!sender->ssrc()) {
886 continue;
887 }
888 const rtc::scoped_refptr<MediaStreamTrackInterface> track(sender->track());
889 if (!track || track->kind() != MediaStreamTrackInterface::kVideoKind) {
890 continue;
891 }
892 // Safe, because kind() == kVideoKind implies a subclass of
893 // VideoTrackInterface; see mediastreaminterface.h.
894 VideoTrackSourceInterface* source =
895 static_cast<VideoTrackInterface*>(track.get())->GetSource();
896
897 VideoTrackSourceInterface::Stats stats;
898 if (!source->GetStats(&stats)) {
899 continue;
900 }
901 const StatsReport::Id stats_id = StatsReport::NewIdWithDirection(
902 StatsReport::kStatsReportTypeSsrc,
903 rtc::ToString<uint32_t>(sender->ssrc()), StatsReport::kSend);
904 StatsReport* report = reports_.FindOrAddNew(stats_id);
905 report->AddInt(StatsReport::kStatsValueNameFrameWidthInput,
906 stats.input_width);
907 report->AddInt(StatsReport::kStatsValueNameFrameHeightInput,
908 stats.input_height);
909 }
910}
911
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000912void StatsCollector::ExtractDataInfo() {
Steve Anton978b8762017-09-29 12:15:02 -0700913 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000914
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000915 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
916
deadbeefab9b2d12015-10-14 11:33:11 -0700917 for (const auto& dc : pc_->sctp_data_channels()) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000918 StatsReport::Id id(StatsReport::NewTypedIntId(
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000919 StatsReport::kStatsReportTypeDataChannel, dc->id()));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000920 StatsReport* report = reports_.ReplaceOrAddNew(id);
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000921 report->set_timestamp(stats_gathering_started_);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000922 report->AddString(StatsReport::kStatsValueNameLabel, dc->label());
zhihuang6ba3b192016-05-13 11:46:35 -0700923 // Filter out the initial id (-1).
924 if (dc->id() >= 0) {
925 report->AddInt(StatsReport::kStatsValueNameDataChannelId, dc->id());
926 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000927 report->AddString(StatsReport::kStatsValueNameProtocol, dc->protocol());
928 report->AddString(StatsReport::kStatsValueNameState,
929 DataChannelInterface::DataStateString(dc->state()));
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000930 }
931}
932
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000933StatsReport* StatsCollector::GetReport(const StatsReport::StatsType& type,
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000934 const std::string& id,
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000935 StatsReport::Direction direction) {
Steve Anton978b8762017-09-29 12:15:02 -0700936 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700937 RTC_DCHECK(type == StatsReport::kStatsReportTypeSsrc ||
938 type == StatsReport::kStatsReportTypeRemoteSsrc);
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000939 return reports_.Find(StatsReport::NewIdWithDirection(type, id, direction));
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000940}
941
Ivo Creusenae026092017-11-20 13:07:16 +0100942void StatsCollector::UpdateStatsFromExistingLocalAudioTracks(
943 bool has_remote_tracks) {
Steve Anton978b8762017-09-29 12:15:02 -0700944 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000945 // Loop through the existing local audio tracks.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000946 for (const auto& it : local_audio_tracks_) {
947 AudioTrackInterface* track = it.first;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200948 uint32_t ssrc = it.second;
949 StatsReport* report =
950 GetReport(StatsReport::kStatsReportTypeSsrc,
951 rtc::ToString<uint32_t>(ssrc), StatsReport::kSend);
henrike@webrtc.orgd3d6bce2014-03-10 20:41:22 +0000952 if (report == NULL) {
953 // This can happen if a local audio track is added to a stream on the
954 // fly and the report has not been set up yet. Do nothing in this case.
Mirko Bonadei675513b2017-11-09 11:09:25 +0100955 RTC_LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc;
henrike@webrtc.orgd3d6bce2014-03-10 20:41:22 +0000956 continue;
957 }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000958
959 // The same ssrc can be used by both local and remote audio tracks.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000960 const StatsReport::Value* v =
961 report->FindValue(StatsReport::kStatsValueNameTrackId);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000962 if (!v || v->string_val() != track->id())
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000963 continue;
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000964
jbauchbe24c942015-06-22 15:06:43 -0700965 report->set_timestamp(stats_gathering_started_);
Ivo Creusenae026092017-11-20 13:07:16 +0100966 UpdateReportFromAudioTrack(track, report, has_remote_tracks);
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000967 }
968}
969
970void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track,
Ivo Creusenae026092017-11-20 13:07:16 +0100971 StatsReport* report,
972 bool has_remote_tracks) {
Steve Anton978b8762017-09-29 12:15:02 -0700973 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700974 RTC_DCHECK(track != NULL);
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000975
andrew2fe1cb02015-11-27 17:27:35 -0800976 // Don't overwrite report values if they're not available.
977 int signal_level;
978 if (track->GetSignalLevel(&signal_level)) {
979 RTC_DCHECK_GE(signal_level, 0);
980 report->AddInt(StatsReport::kStatsValueNameAudioInputLevel, signal_level);
981 }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000982
andrew2fe1cb02015-11-27 17:27:35 -0800983 auto audio_processor(track->GetAudioProcessor());
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000984
andrew2fe1cb02015-11-27 17:27:35 -0800985 if (audio_processor.get()) {
Ivo Creusenae026092017-11-20 13:07:16 +0100986 AudioProcessorInterface::AudioProcessorStatistics stats =
987 audio_processor->GetStats(has_remote_tracks);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000988
Ivo Creusen56d46092017-11-24 17:29:59 +0100989 SetAudioProcessingStats(report, stats.typing_noise_detected,
990 stats.apm_statistics);
andrew2fe1cb02015-11-27 17:27:35 -0800991 }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000992}
993
Peter Boström0c4e06b2015-10-07 12:23:21 +0200994bool StatsCollector::GetTrackIdBySsrc(uint32_t ssrc,
995 std::string* track_id,
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000996 StatsReport::Direction direction) {
Steve Anton978b8762017-09-29 12:15:02 -0700997 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000998 if (direction == StatsReport::kSend) {
Steve Anton978b8762017-09-29 12:15:02 -0700999 if (!pc_->GetLocalTrackIdBySsrc(ssrc, track_id)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001000 RTC_LOG(LS_WARNING) << "The SSRC " << ssrc
1001 << " is not associated with a sending track";
xians@webrtc.org4cb01282014-06-12 14:57:05 +00001002 return false;
1003 }
1004 } else {
henrikg91d6ede2015-09-17 00:24:34 -07001005 RTC_DCHECK(direction == StatsReport::kReceive);
Steve Anton978b8762017-09-29 12:15:02 -07001006 if (!pc_->GetRemoteTrackIdBySsrc(ssrc, track_id)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001007 RTC_LOG(LS_WARNING) << "The SSRC " << ssrc
1008 << " is not associated with a receiving track";
xians@webrtc.org4cb01282014-06-12 14:57:05 +00001009 return false;
1010 }
1011 }
1012
1013 return true;
1014}
1015
jbauchbe24c942015-06-22 15:06:43 -07001016void StatsCollector::UpdateTrackReports() {
Steve Anton978b8762017-09-29 12:15:02 -07001017 RTC_DCHECK(pc_->signaling_thread()->IsCurrent());
jbauchbe24c942015-06-22 15:06:43 -07001018
1019 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
1020
1021 for (const auto& entry : track_ids_) {
1022 StatsReport* report = entry.second;
1023 report->set_timestamp(stats_gathering_started_);
1024 }
jbauchbe24c942015-06-22 15:06:43 -07001025}
1026
tommi@webrtc.org69bc5a32014-12-15 09:44:48 +00001027void StatsCollector::ClearUpdateStatsCacheForTest() {
xians@webrtc.org01bda202014-07-09 07:38:38 +00001028 stats_gathering_started_ = 0;
1029}
1030
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031} // namespace webrtc