blob: ab191d15e5d799ebc4d2ba1a9da1359c84c94293 [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#include "webrtc/api/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
Henrik Kjellander15583c12016-02-10 10:53:12 +010017#include "webrtc/api/peerconnection.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000018#include "webrtc/base/base64.h"
tommi@webrtc.org4b89aa02015-03-16 09:52:30 +000019#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000020#include "webrtc/base/timing.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010021#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022
23namespace webrtc {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024namespace {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
guoweis@webrtc.org950c5182014-12-16 23:01:31 +000026// The following is the enum RTCStatsIceCandidateType from
27// http://w3c.github.io/webrtc-stats/#rtcstatsicecandidatetype-enum such that
28// our stats report for ice candidate type could conform to that.
29const char STATSREPORT_LOCAL_PORT_TYPE[] = "host";
30const char STATSREPORT_STUN_PORT_TYPE[] = "serverreflexive";
31const char STATSREPORT_PRFLX_PORT_TYPE[] = "peerreflexive";
32const char STATSREPORT_RELAY_PORT_TYPE[] = "relayed";
33
34// Strings used by the stats collector to report adapter types. This fits the
35// general stype of http://w3c.github.io/webrtc-stats than what
36// AdapterTypeToString does.
37const char* STATSREPORT_ADAPTER_TYPE_ETHERNET = "lan";
38const char* STATSREPORT_ADAPTER_TYPE_WIFI = "wlan";
39const char* STATSREPORT_ADAPTER_TYPE_WWAN = "wwan";
40const char* STATSREPORT_ADAPTER_TYPE_VPN = "vpn";
phoglund@webrtc.org006521d2015-02-12 09:23:59 +000041const char* STATSREPORT_ADAPTER_TYPE_LOOPBACK = "loopback";
guoweis@webrtc.org950c5182014-12-16 23:01:31 +000042
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000043template<typename ValueType>
44struct TypeForAdd {
tommi@webrtc.org92f40182015-03-04 15:25:19 +000045 const StatsReport::StatsValueName name;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000046 const ValueType& value;
tommi@webrtc.org92f40182015-03-04 15:25:19 +000047};
48
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000049typedef TypeForAdd<bool> BoolForAdd;
50typedef TypeForAdd<float> FloatForAdd;
Peter Boström0c4e06b2015-10-07 12:23:21 +020051typedef TypeForAdd<int64_t> Int64ForAdd;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000052typedef TypeForAdd<int> IntForAdd;
tommi@webrtc.org92f40182015-03-04 15:25:19 +000053
deadbeefd59daf82015-10-14 15:02:44 -070054StatsReport::Id GetTransportIdFromProxy(const ProxyTransportMap& map,
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000055 const std::string& proxy) {
henrikg91d6ede2015-09-17 00:24:34 -070056 RTC_DCHECK(!proxy.empty());
deadbeefd59daf82015-10-14 15:02:44 -070057 auto found = map.find(proxy);
58 if (found == map.end()) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000059 return StatsReport::Id();
deadbeefd59daf82015-10-14 15:02:44 -070060 }
tommi@webrtc.org47218952014-07-15 19:22:37 +000061
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000062 return StatsReport::NewComponentId(
63 found->second, cricket::ICE_CANDIDATE_COMPONENT_RTP);
tommi@webrtc.org47218952014-07-15 19:22:37 +000064}
65
jbauchbe24c942015-06-22 15:06:43 -070066StatsReport* AddTrackReport(StatsCollection* reports,
67 const std::string& track_id) {
xians@webrtc.org01bda202014-07-09 07:38:38 +000068 // Adds an empty track report.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000069 StatsReport::Id id(
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000070 StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, track_id));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000071 StatsReport* report = reports->ReplaceOrAddNew(id);
tommi@webrtc.org92f40182015-03-04 15:25:19 +000072 report->AddString(StatsReport::kStatsValueNameTrackId, track_id);
jbauchbe24c942015-06-22 15:06:43 -070073 return report;
xians@webrtc.org01bda202014-07-09 07:38:38 +000074}
75
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076template <class TrackVector>
jbauchbe24c942015-06-22 15:06:43 -070077void CreateTrackReports(const TrackVector& tracks, StatsCollection* reports,
78 TrackIdMap& track_ids) {
79 for (const auto& track : tracks) {
80 const std::string& track_id = track->id();
81 StatsReport* report = AddTrackReport(reports, track_id);
henrikg91d6ede2015-09-17 00:24:34 -070082 RTC_DCHECK(report != nullptr);
jbauchbe24c942015-06-22 15:06:43 -070083 track_ids[track_id] = report;
84 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085}
86
tommi@webrtc.org92f40182015-03-04 15:25:19 +000087void ExtractCommonSendProperties(const cricket::MediaSenderInfo& info,
88 StatsReport* report) {
89 report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name);
90 report->AddInt64(StatsReport::kStatsValueNameBytesSent, info.bytes_sent);
zhihuang6ba3b192016-05-13 11:46:35 -070091 if (info.rtt_ms >= 0) {
92 report->AddInt64(StatsReport::kStatsValueNameRtt, info.rtt_ms);
93 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +000094}
95
pbosf42376c2015-08-28 07:35:32 -070096void ExtractCommonReceiveProperties(const cricket::MediaReceiverInfo& info,
97 StatsReport* report) {
98 report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name);
99}
100
andrew2fe1cb02015-11-27 17:27:35 -0800101void SetAudioProcessingStats(StatsReport* report,
102 bool typing_noise_detected,
103 int echo_return_loss,
104 int echo_return_loss_enhancement,
105 int echo_delay_median_ms,
106 float aec_quality_min,
107 int echo_delay_std_ms) {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000108 report->AddBoolean(StatsReport::kStatsValueNameTypingNoiseState,
109 typing_noise_detected);
zhihuang6ba3b192016-05-13 11:46:35 -0700110 if (aec_quality_min >= 0.0f) {
111 report->AddFloat(StatsReport::kStatsValueNameEchoCancellationQualityMin,
112 aec_quality_min);
113 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000114 const IntForAdd ints[] = {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000115 { StatsReport::kStatsValueNameEchoDelayMedian, echo_delay_median_ms },
116 { StatsReport::kStatsValueNameEchoDelayStdDev, echo_delay_std_ms },
117 };
zhihuang6ba3b192016-05-13 11:46:35 -0700118 for (const auto& i : ints) {
119 if (i.value >= 0) {
120 report->AddInt(i.name, i.value);
121 }
122 }
123 // These can take on valid negative values.
124 report->AddInt(StatsReport::kStatsValueNameEchoReturnLoss, echo_return_loss);
125 report->AddInt(StatsReport::kStatsValueNameEchoReturnLossEnhancement,
126 echo_return_loss_enhancement);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000127}
128
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129void ExtractStats(const cricket::VoiceReceiverInfo& info, StatsReport* report) {
pbosf42376c2015-08-28 07:35:32 -0700130 ExtractCommonReceiveProperties(info, report);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000131 const FloatForAdd floats[] = {
132 { StatsReport::kStatsValueNameExpandRate, info.expand_rate },
133 { StatsReport::kStatsValueNameSecondaryDecodedRate,
134 info.secondary_decoded_rate },
135 { StatsReport::kStatsValueNameSpeechExpandRate, info.speech_expand_rate },
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200136 { StatsReport::kStatsValueNameAccelerateRate, info.accelerate_rate },
137 { StatsReport::kStatsValueNamePreemptiveExpandRate,
138 info.preemptive_expand_rate },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000139 };
140
141 const IntForAdd ints[] = {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000142 { StatsReport::kStatsValueNameCurrentDelayMs, info.delay_estimate_ms },
143 { StatsReport::kStatsValueNameDecodingCNG, info.decoding_cng },
144 { StatsReport::kStatsValueNameDecodingCTN, info.decoding_calls_to_neteq },
145 { StatsReport::kStatsValueNameDecodingCTSG,
146 info.decoding_calls_to_silence_generator },
147 { StatsReport::kStatsValueNameDecodingNormal, info.decoding_normal },
148 { StatsReport::kStatsValueNameDecodingPLC, info.decoding_plc },
149 { StatsReport::kStatsValueNameDecodingPLCCNG, info.decoding_plc_cng },
150 { StatsReport::kStatsValueNameJitterBufferMs, info.jitter_buffer_ms },
151 { StatsReport::kStatsValueNameJitterReceived, info.jitter_ms },
152 { StatsReport::kStatsValueNamePacketsLost, info.packets_lost },
153 { StatsReport::kStatsValueNamePacketsReceived, info.packets_rcvd },
154 { StatsReport::kStatsValueNamePreferredJitterBufferMs,
155 info.jitter_buffer_preferred_ms },
156 };
157
158 for (const auto& f : floats)
159 report->AddFloat(f.name, f.value);
160
161 for (const auto& i : ints)
162 report->AddInt(i.name, i.value);
zhihuang6ba3b192016-05-13 11:46:35 -0700163 if (info.audio_level >= 0) {
164 report->AddInt(StatsReport::kStatsValueNameAudioOutputLevel,
165 info.audio_level);
166 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000167
168 report->AddInt64(StatsReport::kStatsValueNameBytesReceived,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 info.bytes_rcvd);
zhihuang6ba3b192016-05-13 11:46:35 -0700170 if (info.capture_start_ntp_time_ms >= 0) {
171 report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs,
172 info.capture_start_ntp_time_ms);
173 }
fippobec70ab2016-01-28 01:27:15 -0800174 report->AddString(StatsReport::kStatsValueNameMediaType, "audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175}
176
177void ExtractStats(const cricket::VoiceSenderInfo& info, StatsReport* report) {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000178 ExtractCommonSendProperties(info, report);
179
andrew2fe1cb02015-11-27 17:27:35 -0800180 SetAudioProcessingStats(
181 report, info.typing_noise_detected, info.echo_return_loss,
182 info.echo_return_loss_enhancement, info.echo_delay_median_ms,
183 info.aec_quality_min, info.echo_delay_std_ms);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000184
andrew2fe1cb02015-11-27 17:27:35 -0800185 RTC_DCHECK_GE(info.audio_level, 0);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000186 const IntForAdd ints[] = {
andrew2fe1cb02015-11-27 17:27:35 -0800187 { StatsReport::kStatsValueNameAudioInputLevel, info.audio_level},
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000188 { StatsReport::kStatsValueNameJitterReceived, info.jitter_ms },
189 { StatsReport::kStatsValueNamePacketsLost, info.packets_lost },
190 { StatsReport::kStatsValueNamePacketsSent, info.packets_sent },
191 };
192
zhihuang6ba3b192016-05-13 11:46:35 -0700193 for (const auto& i : ints) {
194 if (i.value >= 0) {
195 report->AddInt(i.name, i.value);
196 }
197 }
fippobec70ab2016-01-28 01:27:15 -0800198 report->AddString(StatsReport::kStatsValueNameMediaType, "audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199}
200
201void ExtractStats(const cricket::VideoReceiverInfo& info, StatsReport* report) {
pbosf42376c2015-08-28 07:35:32 -0700202 ExtractCommonReceiveProperties(info, report);
Peter Boströmb7d9a972015-12-18 16:01:11 +0100203 report->AddString(StatsReport::kStatsValueNameCodecImplementationName,
204 info.decoder_implementation_name);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000205 report->AddInt64(StatsReport::kStatsValueNameBytesReceived,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 info.bytes_rcvd);
zhihuang6ba3b192016-05-13 11:46:35 -0700207 if (info.capture_start_ntp_time_ms >= 0) {
208 report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs,
209 info.capture_start_ntp_time_ms);
210 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000211 const IntForAdd ints[] = {
212 { StatsReport::kStatsValueNameCurrentDelayMs, info.current_delay_ms },
213 { StatsReport::kStatsValueNameDecodeMs, info.decode_ms },
214 { StatsReport::kStatsValueNameFirsSent, info.firs_sent },
215 { StatsReport::kStatsValueNameFrameHeightReceived, info.frame_height },
216 { StatsReport::kStatsValueNameFrameRateDecoded, info.framerate_decoded },
217 { StatsReport::kStatsValueNameFrameRateOutput, info.framerate_output },
218 { StatsReport::kStatsValueNameFrameRateReceived, info.framerate_rcvd },
219 { StatsReport::kStatsValueNameFrameWidthReceived, info.frame_width },
220 { StatsReport::kStatsValueNameJitterBufferMs, info.jitter_buffer_ms },
221 { StatsReport::kStatsValueNameMaxDecodeMs, info.max_decode_ms },
222 { StatsReport::kStatsValueNameMinPlayoutDelayMs,
223 info.min_playout_delay_ms },
224 { StatsReport::kStatsValueNameNacksSent, info.nacks_sent },
225 { StatsReport::kStatsValueNamePacketsLost, info.packets_lost },
226 { StatsReport::kStatsValueNamePacketsReceived, info.packets_rcvd },
227 { StatsReport::kStatsValueNamePlisSent, info.plis_sent },
228 { StatsReport::kStatsValueNameRenderDelayMs, info.render_delay_ms },
229 { StatsReport::kStatsValueNameTargetDelayMs, info.target_delay_ms },
230 };
231
232 for (const auto& i : ints)
233 report->AddInt(i.name, i.value);
fippobec70ab2016-01-28 01:27:15 -0800234 report->AddString(StatsReport::kStatsValueNameMediaType, "video");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235}
236
237void ExtractStats(const cricket::VideoSenderInfo& info, StatsReport* report) {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000238 ExtractCommonSendProperties(info, report);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
Peter Boströmb7d9a972015-12-18 16:01:11 +0100240 report->AddString(StatsReport::kStatsValueNameCodecImplementationName,
241 info.encoder_implementation_name);
mallinath@webrtc.org62451dc2013-12-13 12:29:34 +0000242 report->AddBoolean(StatsReport::kStatsValueNameBandwidthLimitedResolution,
243 (info.adapt_reason & 0x2) > 0);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000244 report->AddBoolean(StatsReport::kStatsValueNameCpuLimitedResolution,
245 (info.adapt_reason & 0x1) > 0);
mallinath@webrtc.org62451dc2013-12-13 12:29:34 +0000246 report->AddBoolean(StatsReport::kStatsValueNameViewLimitedResolution,
247 (info.adapt_reason & 0x4) > 0);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000248
249 const IntForAdd ints[] = {
250 { StatsReport::kStatsValueNameAdaptationChanges, info.adapt_changes },
251 { StatsReport::kStatsValueNameAvgEncodeMs, info.avg_encode_ms },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000252 { StatsReport::kStatsValueNameEncodeUsagePercent,
253 info.encode_usage_percent },
254 { StatsReport::kStatsValueNameFirsReceived, info.firs_rcvd },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000255 { StatsReport::kStatsValueNameFrameHeightSent, info.send_frame_height },
256 { StatsReport::kStatsValueNameFrameRateInput, info.framerate_input },
257 { StatsReport::kStatsValueNameFrameRateSent, info.framerate_sent },
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000258 { StatsReport::kStatsValueNameFrameWidthSent, info.send_frame_width },
259 { StatsReport::kStatsValueNameNacksReceived, info.nacks_rcvd },
260 { StatsReport::kStatsValueNamePacketsLost, info.packets_lost },
261 { StatsReport::kStatsValueNamePacketsSent, info.packets_sent },
262 { StatsReport::kStatsValueNamePlisReceived, info.plis_rcvd },
263 };
264
265 for (const auto& i : ints)
266 report->AddInt(i.name, i.value);
fippobec70ab2016-01-28 01:27:15 -0800267 report->AddString(StatsReport::kStatsValueNameMediaType, "video");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268}
269
270void ExtractStats(const cricket::BandwidthEstimationInfo& info,
271 double stats_gathering_started,
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000272 PeerConnectionInterface::StatsOutputLevel level,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 StatsReport* report) {
henrikg91d6ede2015-09-17 00:24:34 -0700274 RTC_DCHECK(report->type() == StatsReport::kStatsReportTypeBwe);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000276 report->set_timestamp(stats_gathering_started);
277 const IntForAdd ints[] = {
278 { StatsReport::kStatsValueNameAvailableSendBandwidth,
279 info.available_send_bandwidth },
280 { StatsReport::kStatsValueNameAvailableReceiveBandwidth,
281 info.available_recv_bandwidth },
282 { StatsReport::kStatsValueNameTargetEncBitrate, info.target_enc_bitrate },
283 { StatsReport::kStatsValueNameActualEncBitrate, info.actual_enc_bitrate },
284 { StatsReport::kStatsValueNameRetransmitBitrate, info.retransmit_bitrate },
285 { StatsReport::kStatsValueNameTransmitBitrate, info.transmit_bitrate },
286 };
287 for (const auto& i : ints)
288 report->AddInt(i.name, i.value);
289 report->AddInt64(StatsReport::kStatsValueNameBucketDelay, info.bucket_delay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290}
291
wu@webrtc.org97077a32013-10-25 21:18:33 +0000292void ExtractRemoteStats(const cricket::MediaSenderInfo& info,
293 StatsReport* report) {
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000294 report->set_timestamp(info.remote_stats[0].timestamp);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000295 // TODO(hta): Extract some stats here.
296}
297
298void ExtractRemoteStats(const cricket::MediaReceiverInfo& info,
299 StatsReport* report) {
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000300 report->set_timestamp(info.remote_stats[0].timestamp);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000301 // TODO(hta): Extract some stats here.
302}
303
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304// Template to extract stats from a data vector.
sergeyu@chromium.org5bc25c42013-12-05 00:24:06 +0000305// In order to use the template, the functions that are called from it,
306// ExtractStats and ExtractRemoteStats, must be defined and overloaded
307// for each type.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308template<typename T>
309void ExtractStatsFromList(const std::vector<T>& data,
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000310 const StatsReport::Id& transport_id,
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000311 StatsCollector* collector,
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000312 StatsReport::Direction direction) {
313 for (const auto& d : data) {
Peter Boström0c4e06b2015-10-07 12:23:21 +0200314 uint32_t ssrc = d.ssrc();
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000315 // Each track can have stats for both local and remote objects.
wu@webrtc.org97077a32013-10-25 21:18:33 +0000316 // TODO(hta): Handle the case of multiple SSRCs per object.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000317 StatsReport* report = collector->PrepareReport(true, ssrc, transport_id,
318 direction);
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000319 if (report)
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000320 ExtractStats(d, report);
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000321
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000322 if (!d.remote_stats.empty()) {
323 report = collector->PrepareReport(false, ssrc, transport_id, direction);
324 if (report)
325 ExtractRemoteStats(d, report);
wu@webrtc.org97077a32013-10-25 21:18:33 +0000326 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000328}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329
330} // namespace
331
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000332const char* IceCandidateTypeToStatsType(const std::string& candidate_type) {
333 if (candidate_type == cricket::LOCAL_PORT_TYPE) {
334 return STATSREPORT_LOCAL_PORT_TYPE;
335 }
336 if (candidate_type == cricket::STUN_PORT_TYPE) {
337 return STATSREPORT_STUN_PORT_TYPE;
338 }
339 if (candidate_type == cricket::PRFLX_PORT_TYPE) {
340 return STATSREPORT_PRFLX_PORT_TYPE;
341 }
342 if (candidate_type == cricket::RELAY_PORT_TYPE) {
343 return STATSREPORT_RELAY_PORT_TYPE;
344 }
henrikg91d6ede2015-09-17 00:24:34 -0700345 RTC_DCHECK(false);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000346 return "unknown";
347}
348
349const char* AdapterTypeToStatsType(rtc::AdapterType type) {
350 switch (type) {
351 case rtc::ADAPTER_TYPE_UNKNOWN:
352 return "unknown";
353 case rtc::ADAPTER_TYPE_ETHERNET:
354 return STATSREPORT_ADAPTER_TYPE_ETHERNET;
355 case rtc::ADAPTER_TYPE_WIFI:
356 return STATSREPORT_ADAPTER_TYPE_WIFI;
357 case rtc::ADAPTER_TYPE_CELLULAR:
358 return STATSREPORT_ADAPTER_TYPE_WWAN;
359 case rtc::ADAPTER_TYPE_VPN:
360 return STATSREPORT_ADAPTER_TYPE_VPN;
phoglund@webrtc.org006521d2015-02-12 09:23:59 +0000361 case rtc::ADAPTER_TYPE_LOOPBACK:
362 return STATSREPORT_ADAPTER_TYPE_LOOPBACK;
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000363 default:
henrikg91d6ede2015-09-17 00:24:34 -0700364 RTC_DCHECK(false);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000365 return "";
366 }
367}
368
deadbeefab9b2d12015-10-14 11:33:11 -0700369StatsCollector::StatsCollector(PeerConnection* pc)
370 : pc_(pc), stats_gathering_started_(0) {
371 RTC_DCHECK(pc_);
tommi@webrtc.org03505bc2014-07-14 20:15:26 +0000372}
373
374StatsCollector::~StatsCollector() {
deadbeefab9b2d12015-10-14 11:33:11 -0700375 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376}
377
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000378double StatsCollector::GetTimeNow() {
379 return rtc::Timing::WallTimeNow() * rtc::kNumMillisecsPerSec;
380}
381
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382// Adds a MediaStream with tracks that can be used as a |selector| in a call
383// to GetStats.
384void StatsCollector::AddStream(MediaStreamInterface* stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700385 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700386 RTC_DCHECK(stream != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387
388 CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(),
jbauchbe24c942015-06-22 15:06:43 -0700389 &reports_, track_ids_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(),
jbauchbe24c942015-06-22 15:06:43 -0700391 &reports_, track_ids_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392}
393
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000394void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200395 uint32_t ssrc) {
deadbeefab9b2d12015-10-14 11:33:11 -0700396 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700397 RTC_DCHECK(audio_track != NULL);
tommi@webrtc.org4b89aa02015-03-16 09:52:30 +0000398#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000399 for (const auto& track : local_audio_tracks_)
henrikg91d6ede2015-09-17 00:24:34 -0700400 RTC_DCHECK(track.first != audio_track || track.second != ssrc);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000401#endif
xians@webrtc.org01bda202014-07-09 07:38:38 +0000402
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000403 local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc));
xians@webrtc.org01bda202014-07-09 07:38:38 +0000404
405 // Create the kStatsReportTypeTrack report for the new track if there is no
406 // report yet.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000407 StatsReport::Id id(StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack,
408 audio_track->id()));
409 StatsReport* report = reports_.Find(id);
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000410 if (!report) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000411 report = reports_.InsertNew(id);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000412 report->AddString(StatsReport::kStatsValueNameTrackId, audio_track->id());
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000413 }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000414}
415
416void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200417 uint32_t ssrc) {
henrikg91d6ede2015-09-17 00:24:34 -0700418 RTC_DCHECK(audio_track != NULL);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000419 local_audio_tracks_.erase(std::remove_if(local_audio_tracks_.begin(),
420 local_audio_tracks_.end(),
421 [audio_track, ssrc](const LocalAudioTrackVector::value_type& track) {
422 return track.first == audio_track && track.second == ssrc;
423 }));
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000424}
425
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000426void StatsCollector::GetStats(MediaStreamTrackInterface* track,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 StatsReports* reports) {
deadbeefab9b2d12015-10-14 11:33:11 -0700428 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700429 RTC_DCHECK(reports != NULL);
430 RTC_DCHECK(reports->empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000432 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
433
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 if (!track) {
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000435 reports->reserve(reports_.size());
436 for (auto* r : reports_)
437 reports->push_back(r);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000438 return;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 }
440
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000441 StatsReport* report = reports_.Find(StatsReport::NewTypedId(
deadbeefab9b2d12015-10-14 11:33:11 -0700442 StatsReport::kStatsReportTypeSession, pc_->session()->id()));
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000443 if (report)
444 reports->push_back(report);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000446 report = reports_.Find(StatsReport::NewTypedId(
447 StatsReport::kStatsReportTypeTrack, track->id()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000449 if (!report)
450 return;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000452 reports->push_back(report);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453
454 std::string track_id;
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000455 for (const auto* r : reports_) {
456 if (r->type() != StatsReport::kStatsReportTypeSsrc)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 continue;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000458
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000459 const StatsReport::Value* v =
460 r->FindValue(StatsReport::kStatsValueNameTrackId);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000461 if (v && v->string_val() == track->id())
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000462 reports->push_back(r);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464}
465
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000466void
467StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) {
deadbeefab9b2d12015-10-14 11:33:11 -0700468 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 double time_now = GetTimeNow();
470 // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of
471 // ms apart will be ignored.
472 const double kMinGatherStatsPeriod = 50;
xians@webrtc.org01bda202014-07-09 07:38:38 +0000473 if (stats_gathering_started_ != 0 &&
474 stats_gathering_started_ + kMinGatherStatsPeriod > time_now) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 return;
476 }
477 stats_gathering_started_ = time_now;
478
solenberg03d6d572016-03-01 12:42:03 -0800479 // TODO(pthatcher): Merge PeerConnection and WebRtcSession so there is no
480 // pc_->session().
deadbeefab9b2d12015-10-14 11:33:11 -0700481 if (pc_->session()) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000482 // TODO(tommi): All of these hop over to the worker thread to fetch
483 // information. We could use an AsyncInvoker to run all of these and post
484 // the information back to the signaling thread where we can create and
485 // update stats reports. That would also clean up the threading story a bit
486 // since we'd be creating/updating the stats report objects consistently on
487 // the same thread (this class has no locks right now).
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 ExtractSessionInfo();
489 ExtractVoiceInfo();
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000490 ExtractVideoInfo(level);
nissefcc640f2016-04-01 01:10:42 -0700491 ExtractSenderInfo();
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000492 ExtractDataInfo();
jbauchbe24c942015-06-22 15:06:43 -0700493 UpdateTrackReports();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 }
495}
496
deadbeefab9b2d12015-10-14 11:33:11 -0700497StatsReport* StatsCollector::PrepareReport(
498 bool local,
499 uint32_t ssrc,
500 const StatsReport::Id& transport_id,
501 StatsReport::Direction direction) {
502 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000503 StatsReport::Id id(StatsReport::NewIdWithDirection(
Peter Boström0c4e06b2015-10-07 12:23:21 +0200504 local ? StatsReport::kStatsReportTypeSsrc
505 : StatsReport::kStatsReportTypeRemoteSsrc,
506 rtc::ToString<uint32_t>(ssrc), direction));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000507 StatsReport* report = reports_.Find(id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000508
xians@webrtc.org01bda202014-07-09 07:38:38 +0000509 // Use the ID of the track that is currently mapped to the SSRC, if any.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 std::string track_id;
xians@webrtc.org01bda202014-07-09 07:38:38 +0000511 if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) {
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000512 if (!report) {
xians@webrtc.org01bda202014-07-09 07:38:38 +0000513 // The ssrc is not used by any track or existing report, return NULL
514 // in such case to indicate no report is prepared for the ssrc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 return NULL;
xians@webrtc.org01bda202014-07-09 07:38:38 +0000516 }
517
518 // The ssrc is not used by any existing track. Keeps the old track id
519 // since we want to report the stats for inactive ssrc.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000520 const StatsReport::Value* v =
521 report->FindValue(StatsReport::kStatsValueNameTrackId);
522 if (v)
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000523 track_id = v->string_val();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 }
525
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000526 if (!report)
527 report = reports_.InsertNew(id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000529 // FYI - for remote reports, the timestamp will be overwritten later.
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000530 report->set_timestamp(stats_gathering_started_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000532 report->AddInt64(StatsReport::kStatsValueNameSsrc, ssrc);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000533 report->AddString(StatsReport::kStatsValueNameTrackId, track_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 // Add the mapping of SSRC to transport.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000535 report->AddId(StatsReport::kStatsValueNameTransportId, transport_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 return report;
537}
538
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000539StatsReport* StatsCollector::AddOneCertificateReport(
540 const rtc::SSLCertificate* cert, const StatsReport* issuer) {
deadbeefab9b2d12015-10-14 11:33:11 -0700541 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000542
wu@webrtc.org4551b792013-10-09 15:37:36 +0000543 // TODO(bemasc): Move this computation to a helper class that caches these
544 // values to reduce CPU use in GetStats. This will require adding a fast
545 // SSLCertificate::Equals() method to detect certificate changes.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000546
547 std::string digest_algorithm;
548 if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm))
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000549 return nullptr;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000550
jbauch555604a2016-04-26 03:13:22 -0700551 std::unique_ptr<rtc::SSLFingerprint> ssl_fingerprint(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000552 rtc::SSLFingerprint::Create(digest_algorithm, cert));
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000553
554 // SSLFingerprint::Create can fail if the algorithm returned by
555 // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the
556 // implementation of SSLCertificate::ComputeDigest. This currently happens
557 // with MD5- and SHA-224-signed certificates when linked to libNSS.
558 if (!ssl_fingerprint)
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000559 return nullptr;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000560
wu@webrtc.org4551b792013-10-09 15:37:36 +0000561 std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint();
562
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000563 rtc::Buffer der_buffer;
wu@webrtc.org4551b792013-10-09 15:37:36 +0000564 cert->ToDER(&der_buffer);
565 std::string der_base64;
kwiberg@webrtc.orgeebcab52015-03-24 09:19:06 +0000566 rtc::Base64::EncodeFromArray(der_buffer.data(), der_buffer.size(),
567 &der_base64);
wu@webrtc.org4551b792013-10-09 15:37:36 +0000568
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000569 StatsReport::Id id(StatsReport::NewTypedId(
570 StatsReport::kStatsReportTypeCertificate, fingerprint));
571 StatsReport* report = reports_.ReplaceOrAddNew(id);
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000572 report->set_timestamp(stats_gathering_started_);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000573 report->AddString(StatsReport::kStatsValueNameFingerprint, fingerprint);
574 report->AddString(StatsReport::kStatsValueNameFingerprintAlgorithm,
575 digest_algorithm);
576 report->AddString(StatsReport::kStatsValueNameDer, der_base64);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000577 if (issuer)
578 report->AddId(StatsReport::kStatsValueNameIssuerId, issuer->id());
579 return report;
wu@webrtc.org4551b792013-10-09 15:37:36 +0000580}
581
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000582StatsReport* StatsCollector::AddCertificateReports(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000583 const rtc::SSLCertificate* cert) {
deadbeefab9b2d12015-10-14 11:33:11 -0700584 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
wu@webrtc.org4551b792013-10-09 15:37:36 +0000585 // Produces a chain of StatsReports representing this certificate and the rest
586 // of its chain, and adds those reports to |reports_|. The return value is
587 // the id of the leaf report. The provided cert must be non-null, so at least
588 // one report will always be provided and the returned string will never be
589 // empty.
henrikg91d6ede2015-09-17 00:24:34 -0700590 RTC_DCHECK(cert != NULL);
wu@webrtc.org4551b792013-10-09 15:37:36 +0000591
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000592 StatsReport* issuer = nullptr;
jbauch555604a2016-04-26 03:13:22 -0700593 std::unique_ptr<rtc::SSLCertChain> chain = cert->GetChain();
kwibergf5d47862016-03-15 12:53:24 -0700594 if (chain) {
wu@webrtc.org4551b792013-10-09 15:37:36 +0000595 // This loop runs in reverse, i.e. from root to leaf, so that each
596 // certificate's issuer's report ID is known before the child certificate's
597 // report is generated. The root certificate does not have an issuer ID
598 // value.
599 for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000600 const rtc::SSLCertificate& cert_i = chain->Get(i);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000601 issuer = AddOneCertificateReport(&cert_i, issuer);
wu@webrtc.org4551b792013-10-09 15:37:36 +0000602 }
603 }
604 // Add the leaf certificate.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000605 return AddOneCertificateReport(cert, issuer);
wu@webrtc.org4551b792013-10-09 15:37:36 +0000606}
607
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000608StatsReport* StatsCollector::AddConnectionInfoReport(
609 const std::string& content_name, int component, int connection_id,
610 const StatsReport::Id& channel_report_id,
611 const cricket::ConnectionInfo& info) {
612 StatsReport::Id id(StatsReport::NewCandidatePairId(content_name, component,
613 connection_id));
614 StatsReport* report = reports_.ReplaceOrAddNew(id);
615 report->set_timestamp(stats_gathering_started_);
616
617 const BoolForAdd bools[] = {
Peter Thatcher04ac81f2015-09-21 11:48:28 -0700618 {StatsReport::kStatsValueNameActiveConnection, info.best_connection},
619 {StatsReport::kStatsValueNameReceiving, info.receiving},
620 {StatsReport::kStatsValueNameWritable, info.writable},
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000621 };
622 for (const auto& b : bools)
623 report->AddBoolean(b.name, b.value);
624
625 report->AddId(StatsReport::kStatsValueNameChannelId, channel_report_id);
626 report->AddId(StatsReport::kStatsValueNameLocalCandidateId,
627 AddCandidateReport(info.local_candidate, true)->id());
628 report->AddId(StatsReport::kStatsValueNameRemoteCandidateId,
629 AddCandidateReport(info.remote_candidate, false)->id());
630
631 const Int64ForAdd int64s[] = {
zhihuang5ecf16c2016-06-01 17:09:15 -0700632 {StatsReport::kStatsValueNameBytesReceived, info.recv_total_bytes},
633 {StatsReport::kStatsValueNameBytesSent, info.sent_total_bytes},
634 {StatsReport::kStatsValueNamePacketsSent, info.sent_total_packets},
635 {StatsReport::kStatsValueNameRtt, info.rtt},
636 {StatsReport::kStatsValueNameSendPacketsDiscarded,
637 info.sent_discarded_packets},
638 {StatsReport::kStatsValueNameSentPingRequestsTotal,
639 info.sent_ping_requests_total},
640 {StatsReport::kStatsValueNameSentPingRequestsBeforeFirstResponse,
641 info.sent_ping_requests_before_first_response},
642 {StatsReport::kStatsValueNameSentPingResponses, info.sent_ping_responses},
643 {StatsReport::kStatsValueNameRecvPingRequests, info.recv_ping_requests},
644 {StatsReport::kStatsValueNameRecvPingResponses, info.recv_ping_responses},
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000645 };
646 for (const auto& i : int64s)
647 report->AddInt64(i.name, i.value);
648
649 report->AddString(StatsReport::kStatsValueNameLocalAddress,
650 info.local_candidate.address().ToString());
651 report->AddString(StatsReport::kStatsValueNameLocalCandidateType,
652 info.local_candidate.type());
653 report->AddString(StatsReport::kStatsValueNameRemoteAddress,
654 info.remote_candidate.address().ToString());
655 report->AddString(StatsReport::kStatsValueNameRemoteCandidateType,
656 info.remote_candidate.type());
657 report->AddString(StatsReport::kStatsValueNameTransportType,
658 info.local_candidate.protocol());
659
660 return report;
661}
662
663StatsReport* StatsCollector::AddCandidateReport(
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000664 const cricket::Candidate& candidate,
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000665 bool local) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000666 StatsReport::Id id(StatsReport::NewCandidateId(local, candidate.id()));
667 StatsReport* report = reports_.Find(id);
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000668 if (!report) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000669 report = reports_.InsertNew(id);
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000670 report->set_timestamp(stats_gathering_started_);
671 if (local) {
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000672 report->AddString(StatsReport::kStatsValueNameCandidateNetworkType,
673 AdapterTypeToStatsType(candidate.network_type()));
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000674 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000675 report->AddString(StatsReport::kStatsValueNameCandidateIPAddress,
676 candidate.address().ipaddr().ToString());
677 report->AddString(StatsReport::kStatsValueNameCandidatePortNumber,
678 candidate.address().PortAsString());
679 report->AddInt(StatsReport::kStatsValueNameCandidatePriority,
680 candidate.priority());
681 report->AddString(StatsReport::kStatsValueNameCandidateType,
682 IceCandidateTypeToStatsType(candidate.type()));
683 report->AddString(StatsReport::kStatsValueNameCandidateTransportType,
684 candidate.protocol());
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000685 }
686
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000687 return report;
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000688}
689
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690void StatsCollector::ExtractSessionInfo() {
deadbeefab9b2d12015-10-14 11:33:11 -0700691 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000692
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 // Extract information from the base session.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000694 StatsReport::Id id(StatsReport::NewTypedId(
deadbeefab9b2d12015-10-14 11:33:11 -0700695 StatsReport::kStatsReportTypeSession, pc_->session()->id()));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000696 StatsReport* report = reports_.ReplaceOrAddNew(id);
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000697 report->set_timestamp(stats_gathering_started_);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000698 report->AddBoolean(StatsReport::kStatsValueNameInitiator,
deadbeefd59daf82015-10-14 15:02:44 -0700699 pc_->session()->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700
deadbeefd59daf82015-10-14 15:02:44 -0700701 SessionStats stats;
deadbeefab9b2d12015-10-14 11:33:11 -0700702 if (!pc_->session()->GetTransportStats(&stats)) {
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000703 return;
704 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000706 // Store the proxy map away for use in SSRC reporting.
707 // TODO(tommi): This shouldn't be necessary if we post the stats back to the
708 // signaling thread after fetching them on the worker thread, then just use
709 // the proxy map directly from the session stats.
710 // As is, if GetStats() failed, we could be using old (incorrect?) proxy
711 // data.
712 proxy_to_transport_ = stats.proxy_to_transport;
jiayl@webrtc.org06b04ec2014-07-24 20:41:20 +0000713
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000714 for (const auto& transport_iter : stats.transport_stats) {
715 // Attempt to get a copy of the certificates from the transport and
716 // expose them in stats reports. All channels in a transport share the
717 // same local and remote certificates.
718 //
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000719 StatsReport::Id local_cert_report_id, remote_cert_report_id;
Henrik Boströmd8281982015-08-27 10:12:24 +0200720 rtc::scoped_refptr<rtc::RTCCertificate> certificate;
deadbeefab9b2d12015-10-14 11:33:11 -0700721 if (pc_->session()->GetLocalCertificate(
722 transport_iter.second.transport_name, &certificate)) {
Henrik Boströmd8281982015-08-27 10:12:24 +0200723 StatsReport* r = AddCertificateReports(&(certificate->ssl_certificate()));
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000724 if (r)
725 local_cert_report_id = r->id();
726 }
727
jbauch555604a2016-04-26 03:13:22 -0700728 std::unique_ptr<rtc::SSLCertificate> cert =
kwibergb4d01c42016-04-06 05:15:06 -0700729 pc_->session()->GetRemoteSSLCertificate(
730 transport_iter.second.transport_name);
731 if (cert) {
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000732 StatsReport* r = AddCertificateReports(cert.get());
733 if (r)
734 remote_cert_report_id = r->id();
735 }
736
737 for (const auto& channel_iter : transport_iter.second.channel_stats) {
738 StatsReport::Id id(StatsReport::NewComponentId(
deadbeefcbecd352015-09-23 11:50:27 -0700739 transport_iter.second.transport_name, channel_iter.component));
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000740 StatsReport* channel_report = reports_.ReplaceOrAddNew(id);
741 channel_report->set_timestamp(stats_gathering_started_);
742 channel_report->AddInt(StatsReport::kStatsValueNameComponent,
743 channel_iter.component);
744 if (local_cert_report_id.get()) {
745 channel_report->AddId(StatsReport::kStatsValueNameLocalCertificateId,
746 local_cert_report_id);
747 }
748 if (remote_cert_report_id.get()) {
749 channel_report->AddId(StatsReport::kStatsValueNameRemoteCertificateId,
750 remote_cert_report_id);
751 }
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800752 int srtp_crypto_suite = channel_iter.srtp_crypto_suite;
753 if (srtp_crypto_suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
754 rtc::SrtpCryptoSuiteToName(srtp_crypto_suite).length()) {
755 channel_report->AddString(
756 StatsReport::kStatsValueNameSrtpCipher,
757 rtc::SrtpCryptoSuiteToName(srtp_crypto_suite));
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000758 }
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800759 int ssl_cipher_suite = channel_iter.ssl_cipher_suite;
760 if (ssl_cipher_suite != rtc::TLS_NULL_WITH_NULL_NULL &&
761 rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite)
762 .length()) {
Guo-wei Shieh456696a2015-09-30 21:48:54 -0700763 channel_report->AddString(
764 StatsReport::kStatsValueNameDtlsCipher,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800765 rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite));
wu@webrtc.org4551b792013-10-09 15:37:36 +0000766 }
jiayl@webrtc.org06b04ec2014-07-24 20:41:20 +0000767
pthatcher@webrtc.orgc04a97f2015-03-16 19:31:40 +0000768 int connection_id = 0;
769 for (const cricket::ConnectionInfo& info :
770 channel_iter.connection_infos) {
771 StatsReport* connection_report = AddConnectionInfoReport(
772 transport_iter.first, channel_iter.component, connection_id++,
773 channel_report->id(), info);
774 if (info.best_connection) {
775 channel_report->AddId(
776 StatsReport::kStatsValueNameSelectedCandidatePairId,
777 connection_report->id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 }
779 }
780 }
781 }
782}
783
784void StatsCollector::ExtractVoiceInfo() {
deadbeefab9b2d12015-10-14 11:33:11 -0700785 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
tommi@webrtc.org69bc5a32014-12-15 09:44:48 +0000786
deadbeefab9b2d12015-10-14 11:33:11 -0700787 if (!pc_->session()->voice_channel()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 return;
789 }
790 cricket::VoiceMediaInfo voice_info;
deadbeefab9b2d12015-10-14 11:33:11 -0700791 if (!pc_->session()->voice_channel()->GetStats(&voice_info)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 LOG(LS_ERROR) << "Failed to get voice channel stats.";
793 return;
794 }
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000795
796 // TODO(tommi): The above code should run on the worker thread and post the
797 // results back to the signaling thread, where we can add data to the reports.
798 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
799
deadbeefab9b2d12015-10-14 11:33:11 -0700800 StatsReport::Id transport_id(GetTransportIdFromProxy(
801 proxy_to_transport_, pc_->session()->voice_channel()->content_name()));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000802 if (!transport_id.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 LOG(LS_ERROR) << "Failed to get transport name for proxy "
deadbeefab9b2d12015-10-14 11:33:11 -0700804 << pc_->session()->voice_channel()->content_name();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 return;
806 }
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000807
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000808 ExtractStatsFromList(voice_info.receivers, transport_id, this,
809 StatsReport::kReceive);
810 ExtractStatsFromList(voice_info.senders, transport_id, this,
811 StatsReport::kSend);
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000812
813 UpdateStatsFromExistingLocalAudioTracks();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814}
815
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000816void StatsCollector::ExtractVideoInfo(
817 PeerConnectionInterface::StatsOutputLevel level) {
deadbeefab9b2d12015-10-14 11:33:11 -0700818 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
tommi@webrtc.org69bc5a32014-12-15 09:44:48 +0000819
deadbeefab9b2d12015-10-14 11:33:11 -0700820 if (!pc_->session()->video_channel())
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 return;
tommi@webrtc.org69bc5a32014-12-15 09:44:48 +0000822
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 cricket::VideoMediaInfo video_info;
deadbeefab9b2d12015-10-14 11:33:11 -0700824 if (!pc_->session()->video_channel()->GetStats(&video_info)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 LOG(LS_ERROR) << "Failed to get video channel stats.";
826 return;
827 }
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000828
829 // TODO(tommi): The above code should run on the worker thread and post the
830 // results back to the signaling thread, where we can add data to the reports.
831 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
832
deadbeefab9b2d12015-10-14 11:33:11 -0700833 StatsReport::Id transport_id(GetTransportIdFromProxy(
834 proxy_to_transport_, pc_->session()->video_channel()->content_name()));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000835 if (!transport_id.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 LOG(LS_ERROR) << "Failed to get transport name for proxy "
deadbeefab9b2d12015-10-14 11:33:11 -0700837 << pc_->session()->video_channel()->content_name();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 return;
839 }
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000840 ExtractStatsFromList(video_info.receivers, transport_id, this,
841 StatsReport::kReceive);
842 ExtractStatsFromList(video_info.senders, transport_id, this,
843 StatsReport::kSend);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 if (video_info.bw_estimations.size() != 1) {
845 LOG(LS_ERROR) << "BWEs count: " << video_info.bw_estimations.size();
846 } else {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000847 StatsReport::Id report_id(StatsReport::NewBandwidthEstimationId());
848 StatsReport* report = reports_.FindOrAddNew(report_id);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 ExtractStats(
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000850 video_info.bw_estimations[0], stats_gathering_started_, level, report);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 }
852}
853
nissefcc640f2016-04-01 01:10:42 -0700854void StatsCollector::ExtractSenderInfo() {
855 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
856
857 for (const auto& sender : pc_->GetSenders()) {
858 // TODO(nisse): SSRC == 0 currently means none. Delete check when
859 // that is fixed.
860 if (!sender->ssrc()) {
861 continue;
862 }
863 const rtc::scoped_refptr<MediaStreamTrackInterface> track(sender->track());
864 if (!track || track->kind() != MediaStreamTrackInterface::kVideoKind) {
865 continue;
866 }
867 // Safe, because kind() == kVideoKind implies a subclass of
868 // VideoTrackInterface; see mediastreaminterface.h.
869 VideoTrackSourceInterface* source =
870 static_cast<VideoTrackInterface*>(track.get())->GetSource();
871
872 VideoTrackSourceInterface::Stats stats;
873 if (!source->GetStats(&stats)) {
874 continue;
875 }
876 const StatsReport::Id stats_id = StatsReport::NewIdWithDirection(
877 StatsReport::kStatsReportTypeSsrc,
878 rtc::ToString<uint32_t>(sender->ssrc()), StatsReport::kSend);
879 StatsReport* report = reports_.FindOrAddNew(stats_id);
880 report->AddInt(StatsReport::kStatsValueNameFrameWidthInput,
881 stats.input_width);
882 report->AddInt(StatsReport::kStatsValueNameFrameHeightInput,
883 stats.input_height);
884 }
885}
886
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000887void StatsCollector::ExtractDataInfo() {
deadbeefab9b2d12015-10-14 11:33:11 -0700888 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000889
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000890 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
891
deadbeefab9b2d12015-10-14 11:33:11 -0700892 for (const auto& dc : pc_->sctp_data_channels()) {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000893 StatsReport::Id id(StatsReport::NewTypedIntId(
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000894 StatsReport::kStatsReportTypeDataChannel, dc->id()));
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000895 StatsReport* report = reports_.ReplaceOrAddNew(id);
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000896 report->set_timestamp(stats_gathering_started_);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000897 report->AddString(StatsReport::kStatsValueNameLabel, dc->label());
zhihuang6ba3b192016-05-13 11:46:35 -0700898 // Filter out the initial id (-1).
899 if (dc->id() >= 0) {
900 report->AddInt(StatsReport::kStatsValueNameDataChannelId, dc->id());
901 }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000902 report->AddString(StatsReport::kStatsValueNameProtocol, dc->protocol());
903 report->AddString(StatsReport::kStatsValueNameState,
904 DataChannelInterface::DataStateString(dc->state()));
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000905 }
906}
907
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000908StatsReport* StatsCollector::GetReport(const StatsReport::StatsType& type,
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000909 const std::string& id,
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000910 StatsReport::Direction direction) {
deadbeefab9b2d12015-10-14 11:33:11 -0700911 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700912 RTC_DCHECK(type == StatsReport::kStatsReportTypeSsrc ||
913 type == StatsReport::kStatsReportTypeRemoteSsrc);
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000914 return reports_.Find(StatsReport::NewIdWithDirection(type, id, direction));
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000915}
916
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000917void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() {
deadbeefab9b2d12015-10-14 11:33:11 -0700918 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000919 // Loop through the existing local audio tracks.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000920 for (const auto& it : local_audio_tracks_) {
921 AudioTrackInterface* track = it.first;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200922 uint32_t ssrc = it.second;
923 StatsReport* report =
924 GetReport(StatsReport::kStatsReportTypeSsrc,
925 rtc::ToString<uint32_t>(ssrc), StatsReport::kSend);
henrike@webrtc.orgd3d6bce2014-03-10 20:41:22 +0000926 if (report == NULL) {
927 // This can happen if a local audio track is added to a stream on the
928 // fly and the report has not been set up yet. Do nothing in this case.
929 LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc;
930 continue;
931 }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000932
933 // The same ssrc can be used by both local and remote audio tracks.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000934 const StatsReport::Value* v =
935 report->FindValue(StatsReport::kStatsValueNameTrackId);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000936 if (!v || v->string_val() != track->id())
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000937 continue;
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000938
jbauchbe24c942015-06-22 15:06:43 -0700939 report->set_timestamp(stats_gathering_started_);
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000940 UpdateReportFromAudioTrack(track, report);
941 }
942}
943
944void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track,
945 StatsReport* report) {
deadbeefab9b2d12015-10-14 11:33:11 -0700946 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
henrikg91d6ede2015-09-17 00:24:34 -0700947 RTC_DCHECK(track != NULL);
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000948
andrew2fe1cb02015-11-27 17:27:35 -0800949 // Don't overwrite report values if they're not available.
950 int signal_level;
951 if (track->GetSignalLevel(&signal_level)) {
952 RTC_DCHECK_GE(signal_level, 0);
953 report->AddInt(StatsReport::kStatsValueNameAudioInputLevel, signal_level);
954 }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000955
andrew2fe1cb02015-11-27 17:27:35 -0800956 auto audio_processor(track->GetAudioProcessor());
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000957
andrew2fe1cb02015-11-27 17:27:35 -0800958 if (audio_processor.get()) {
959 AudioProcessorInterface::AudioProcessorStats stats;
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000960 audio_processor->GetStats(&stats);
961
andrew2fe1cb02015-11-27 17:27:35 -0800962 SetAudioProcessingStats(
963 report, stats.typing_noise_detected, stats.echo_return_loss,
964 stats.echo_return_loss_enhancement, stats.echo_delay_median_ms,
965 stats.aec_quality_min, stats.echo_delay_std_ms);
Minyue2a8a78c2016-04-07 16:48:15 +0200966
967 report->AddFloat(StatsReport::kStatsValueNameAecDivergentFilterFraction,
968 stats.aec_divergent_filter_fraction);
andrew2fe1cb02015-11-27 17:27:35 -0800969 }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000970}
971
Peter Boström0c4e06b2015-10-07 12:23:21 +0200972bool StatsCollector::GetTrackIdBySsrc(uint32_t ssrc,
973 std::string* track_id,
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000974 StatsReport::Direction direction) {
deadbeefab9b2d12015-10-14 11:33:11 -0700975 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000976 if (direction == StatsReport::kSend) {
deadbeefab9b2d12015-10-14 11:33:11 -0700977 if (!pc_->session()->GetLocalTrackIdBySsrc(ssrc, track_id)) {
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000978 LOG(LS_WARNING) << "The SSRC " << ssrc
979 << " is not associated with a sending track";
980 return false;
981 }
982 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700983 RTC_DCHECK(direction == StatsReport::kReceive);
deadbeefab9b2d12015-10-14 11:33:11 -0700984 if (!pc_->session()->GetRemoteTrackIdBySsrc(ssrc, track_id)) {
xians@webrtc.org4cb01282014-06-12 14:57:05 +0000985 LOG(LS_WARNING) << "The SSRC " << ssrc
986 << " is not associated with a receiving track";
987 return false;
988 }
989 }
990
991 return true;
992}
993
jbauchbe24c942015-06-22 15:06:43 -0700994void StatsCollector::UpdateTrackReports() {
deadbeefab9b2d12015-10-14 11:33:11 -0700995 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
jbauchbe24c942015-06-22 15:06:43 -0700996
997 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
998
999 for (const auto& entry : track_ids_) {
1000 StatsReport* report = entry.second;
1001 report->set_timestamp(stats_gathering_started_);
1002 }
jbauchbe24c942015-06-22 15:06:43 -07001003}
1004
tommi@webrtc.org69bc5a32014-12-15 09:44:48 +00001005void StatsCollector::ClearUpdateStatsCacheForTest() {
xians@webrtc.org01bda202014-07-09 07:38:38 +00001006 stats_gathering_started_ = 0;
1007}
1008
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009} // namespace webrtc