henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #include "webrtc/api/statscollector.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 13 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 14 | #include <utility> |
| 15 | #include <vector> |
| 16 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 17 | #include "webrtc/api/peerconnection.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 18 | #include "webrtc/base/base64.h" |
tommi@webrtc.org | 4b89aa0 | 2015-03-16 09:52:30 +0000 | [diff] [blame] | 19 | #include "webrtc/base/checks.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 20 | #include "webrtc/base/timing.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 21 | #include "webrtc/pc/channel.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 24 | namespace { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 26 | // 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. |
| 29 | const char STATSREPORT_LOCAL_PORT_TYPE[] = "host"; |
| 30 | const char STATSREPORT_STUN_PORT_TYPE[] = "serverreflexive"; |
| 31 | const char STATSREPORT_PRFLX_PORT_TYPE[] = "peerreflexive"; |
| 32 | const 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. |
| 37 | const char* STATSREPORT_ADAPTER_TYPE_ETHERNET = "lan"; |
| 38 | const char* STATSREPORT_ADAPTER_TYPE_WIFI = "wlan"; |
| 39 | const char* STATSREPORT_ADAPTER_TYPE_WWAN = "wwan"; |
| 40 | const char* STATSREPORT_ADAPTER_TYPE_VPN = "vpn"; |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 +0000 | [diff] [blame] | 41 | const char* STATSREPORT_ADAPTER_TYPE_LOOPBACK = "loopback"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 42 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 43 | template<typename ValueType> |
| 44 | struct TypeForAdd { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 45 | const StatsReport::StatsValueName name; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 46 | const ValueType& value; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 49 | typedef TypeForAdd<bool> BoolForAdd; |
| 50 | typedef TypeForAdd<float> FloatForAdd; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 51 | typedef TypeForAdd<int64_t> Int64ForAdd; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 52 | typedef TypeForAdd<int> IntForAdd; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 53 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 54 | StatsReport::Id GetTransportIdFromProxy(const ProxyTransportMap& map, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 55 | const std::string& proxy) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 56 | RTC_DCHECK(!proxy.empty()); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 57 | auto found = map.find(proxy); |
| 58 | if (found == map.end()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 59 | return StatsReport::Id(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 60 | } |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 61 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 62 | return StatsReport::NewComponentId( |
| 63 | found->second, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 64 | } |
| 65 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 66 | StatsReport* AddTrackReport(StatsCollection* reports, |
| 67 | const std::string& track_id) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 68 | // Adds an empty track report. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 69 | StatsReport::Id id( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 70 | StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, track_id)); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 71 | StatsReport* report = reports->ReplaceOrAddNew(id); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 72 | report->AddString(StatsReport::kStatsValueNameTrackId, track_id); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 73 | return report; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 74 | } |
| 75 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | template <class TrackVector> |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 77 | void 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); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 82 | RTC_DCHECK(report != nullptr); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 83 | track_ids[track_id] = report; |
| 84 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | } |
| 86 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 87 | void ExtractCommonSendProperties(const cricket::MediaSenderInfo& info, |
| 88 | StatsReport* report) { |
| 89 | report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name); |
| 90 | report->AddInt64(StatsReport::kStatsValueNameBytesSent, info.bytes_sent); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame^] | 91 | if (info.rtt_ms >= 0) { |
| 92 | report->AddInt64(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 93 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 94 | } |
| 95 | |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 96 | void ExtractCommonReceiveProperties(const cricket::MediaReceiverInfo& info, |
| 97 | StatsReport* report) { |
| 98 | report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name); |
| 99 | } |
| 100 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 101 | void 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.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 108 | report->AddBoolean(StatsReport::kStatsValueNameTypingNoiseState, |
| 109 | typing_noise_detected); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame^] | 110 | if (aec_quality_min >= 0.0f) { |
| 111 | report->AddFloat(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
| 112 | aec_quality_min); |
| 113 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 114 | const IntForAdd ints[] = { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 115 | { StatsReport::kStatsValueNameEchoDelayMedian, echo_delay_median_ms }, |
| 116 | { StatsReport::kStatsValueNameEchoDelayStdDev, echo_delay_std_ms }, |
| 117 | }; |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame^] | 118 | 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.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 127 | } |
| 128 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | void ExtractStats(const cricket::VoiceReceiverInfo& info, StatsReport* report) { |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 130 | ExtractCommonReceiveProperties(info, report); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 131 | 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 Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 136 | { StatsReport::kStatsValueNameAccelerateRate, info.accelerate_rate }, |
| 137 | { StatsReport::kStatsValueNamePreemptiveExpandRate, |
| 138 | info.preemptive_expand_rate }, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | const IntForAdd ints[] = { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 142 | { 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); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame^] | 163 | if (info.audio_level >= 0) { |
| 164 | report->AddInt(StatsReport::kStatsValueNameAudioOutputLevel, |
| 165 | info.audio_level); |
| 166 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 167 | |
| 168 | report->AddInt64(StatsReport::kStatsValueNameBytesReceived, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | info.bytes_rcvd); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame^] | 170 | if (info.capture_start_ntp_time_ms >= 0) { |
| 171 | report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 172 | info.capture_start_ntp_time_ms); |
| 173 | } |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 174 | report->AddString(StatsReport::kStatsValueNameMediaType, "audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void ExtractStats(const cricket::VoiceSenderInfo& info, StatsReport* report) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 178 | ExtractCommonSendProperties(info, report); |
| 179 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 180 | 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.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 184 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 185 | RTC_DCHECK_GE(info.audio_level, 0); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 186 | const IntForAdd ints[] = { |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 187 | { StatsReport::kStatsValueNameAudioInputLevel, info.audio_level}, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 188 | { StatsReport::kStatsValueNameJitterReceived, info.jitter_ms }, |
| 189 | { StatsReport::kStatsValueNamePacketsLost, info.packets_lost }, |
| 190 | { StatsReport::kStatsValueNamePacketsSent, info.packets_sent }, |
| 191 | }; |
| 192 | |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame^] | 193 | for (const auto& i : ints) { |
| 194 | if (i.value >= 0) { |
| 195 | report->AddInt(i.name, i.value); |
| 196 | } |
| 197 | } |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 198 | report->AddString(StatsReport::kStatsValueNameMediaType, "audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | void ExtractStats(const cricket::VideoReceiverInfo& info, StatsReport* report) { |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 202 | ExtractCommonReceiveProperties(info, report); |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 203 | report->AddString(StatsReport::kStatsValueNameCodecImplementationName, |
| 204 | info.decoder_implementation_name); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 205 | report->AddInt64(StatsReport::kStatsValueNameBytesReceived, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | info.bytes_rcvd); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame^] | 207 | if (info.capture_start_ntp_time_ms >= 0) { |
| 208 | report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 209 | info.capture_start_ntp_time_ms); |
| 210 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 211 | 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); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 234 | report->AddString(StatsReport::kStatsValueNameMediaType, "video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void ExtractStats(const cricket::VideoSenderInfo& info, StatsReport* report) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 238 | ExtractCommonSendProperties(info, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 239 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 240 | report->AddString(StatsReport::kStatsValueNameCodecImplementationName, |
| 241 | info.encoder_implementation_name); |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 242 | report->AddBoolean(StatsReport::kStatsValueNameBandwidthLimitedResolution, |
| 243 | (info.adapt_reason & 0x2) > 0); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 244 | report->AddBoolean(StatsReport::kStatsValueNameCpuLimitedResolution, |
| 245 | (info.adapt_reason & 0x1) > 0); |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 246 | report->AddBoolean(StatsReport::kStatsValueNameViewLimitedResolution, |
| 247 | (info.adapt_reason & 0x4) > 0); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 248 | |
| 249 | const IntForAdd ints[] = { |
| 250 | { StatsReport::kStatsValueNameAdaptationChanges, info.adapt_changes }, |
| 251 | { StatsReport::kStatsValueNameAvgEncodeMs, info.avg_encode_ms }, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 252 | { StatsReport::kStatsValueNameEncodeUsagePercent, |
| 253 | info.encode_usage_percent }, |
| 254 | { StatsReport::kStatsValueNameFirsReceived, info.firs_rcvd }, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 255 | { StatsReport::kStatsValueNameFrameHeightSent, info.send_frame_height }, |
| 256 | { StatsReport::kStatsValueNameFrameRateInput, info.framerate_input }, |
| 257 | { StatsReport::kStatsValueNameFrameRateSent, info.framerate_sent }, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 258 | { 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); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 267 | report->AddString(StatsReport::kStatsValueNameMediaType, "video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void ExtractStats(const cricket::BandwidthEstimationInfo& info, |
| 271 | double stats_gathering_started, |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 272 | PeerConnectionInterface::StatsOutputLevel level, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 273 | StatsReport* report) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 274 | RTC_DCHECK(report->type() == StatsReport::kStatsReportTypeBwe); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 275 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 276 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 290 | } |
| 291 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 292 | void ExtractRemoteStats(const cricket::MediaSenderInfo& info, |
| 293 | StatsReport* report) { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 294 | report->set_timestamp(info.remote_stats[0].timestamp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 295 | // TODO(hta): Extract some stats here. |
| 296 | } |
| 297 | |
| 298 | void ExtractRemoteStats(const cricket::MediaReceiverInfo& info, |
| 299 | StatsReport* report) { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 300 | report->set_timestamp(info.remote_stats[0].timestamp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 301 | // TODO(hta): Extract some stats here. |
| 302 | } |
| 303 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | // Template to extract stats from a data vector. |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 305 | // 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 308 | template<typename T> |
| 309 | void ExtractStatsFromList(const std::vector<T>& data, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 310 | const StatsReport::Id& transport_id, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 311 | StatsCollector* collector, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 312 | StatsReport::Direction direction) { |
| 313 | for (const auto& d : data) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 314 | uint32_t ssrc = d.ssrc(); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 315 | // Each track can have stats for both local and remote objects. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 316 | // TODO(hta): Handle the case of multiple SSRCs per object. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 317 | StatsReport* report = collector->PrepareReport(true, ssrc, transport_id, |
| 318 | direction); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 319 | if (report) |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 320 | ExtractStats(d, report); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 321 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 322 | if (!d.remote_stats.empty()) { |
| 323 | report = collector->PrepareReport(false, ssrc, transport_id, direction); |
| 324 | if (report) |
| 325 | ExtractRemoteStats(d, report); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 326 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 327 | } |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 328 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 329 | |
| 330 | } // namespace |
| 331 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 332 | const 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 | } |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 345 | RTC_DCHECK(false); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 346 | return "unknown"; |
| 347 | } |
| 348 | |
| 349 | const 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.org | 006521d | 2015-02-12 09:23:59 +0000 | [diff] [blame] | 361 | case rtc::ADAPTER_TYPE_LOOPBACK: |
| 362 | return STATSREPORT_ADAPTER_TYPE_LOOPBACK; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 363 | default: |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 364 | RTC_DCHECK(false); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 365 | return ""; |
| 366 | } |
| 367 | } |
| 368 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 369 | StatsCollector::StatsCollector(PeerConnection* pc) |
| 370 | : pc_(pc), stats_gathering_started_(0) { |
| 371 | RTC_DCHECK(pc_); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | StatsCollector::~StatsCollector() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 375 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 376 | } |
| 377 | |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 378 | double StatsCollector::GetTimeNow() { |
| 379 | return rtc::Timing::WallTimeNow() * rtc::kNumMillisecsPerSec; |
| 380 | } |
| 381 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 382 | // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 383 | // to GetStats. |
| 384 | void StatsCollector::AddStream(MediaStreamInterface* stream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 385 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 386 | RTC_DCHECK(stream != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 387 | |
| 388 | CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 389 | &reports_, track_ids_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 391 | &reports_, track_ids_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 392 | } |
| 393 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 394 | void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 395 | uint32_t ssrc) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 396 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 397 | RTC_DCHECK(audio_track != NULL); |
tommi@webrtc.org | 4b89aa0 | 2015-03-16 09:52:30 +0000 | [diff] [blame] | 398 | #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 399 | for (const auto& track : local_audio_tracks_) |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 400 | RTC_DCHECK(track.first != audio_track || track.second != ssrc); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 401 | #endif |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 402 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 403 | local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc)); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 404 | |
| 405 | // Create the kStatsReportTypeTrack report for the new track if there is no |
| 406 | // report yet. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 407 | StatsReport::Id id(StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, |
| 408 | audio_track->id())); |
| 409 | StatsReport* report = reports_.Find(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 410 | if (!report) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 411 | report = reports_.InsertNew(id); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 412 | report->AddString(StatsReport::kStatsValueNameTrackId, audio_track->id()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 413 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 417 | uint32_t ssrc) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 418 | RTC_DCHECK(audio_track != NULL); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 419 | 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.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 424 | } |
| 425 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 426 | void StatsCollector::GetStats(MediaStreamTrackInterface* track, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 427 | StatsReports* reports) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 428 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 429 | RTC_DCHECK(reports != NULL); |
| 430 | RTC_DCHECK(reports->empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 431 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 432 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 433 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 434 | if (!track) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 435 | reports->reserve(reports_.size()); |
| 436 | for (auto* r : reports_) |
| 437 | reports->push_back(r); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 438 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 439 | } |
| 440 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 441 | StatsReport* report = reports_.Find(StatsReport::NewTypedId( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 442 | StatsReport::kStatsReportTypeSession, pc_->session()->id())); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 443 | if (report) |
| 444 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 445 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 446 | report = reports_.Find(StatsReport::NewTypedId( |
| 447 | StatsReport::kStatsReportTypeTrack, track->id())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 448 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 449 | if (!report) |
| 450 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 451 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 452 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 453 | |
| 454 | std::string track_id; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 455 | for (const auto* r : reports_) { |
| 456 | if (r->type() != StatsReport::kStatsReportTypeSsrc) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 457 | continue; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 458 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 459 | const StatsReport::Value* v = |
| 460 | r->FindValue(StatsReport::kStatsValueNameTrackId); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 461 | if (v && v->string_val() == track->id()) |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 462 | reports->push_back(r); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 463 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 464 | } |
| 465 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 466 | void |
| 467 | StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 468 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 469 | 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.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 473 | if (stats_gathering_started_ != 0 && |
| 474 | stats_gathering_started_ + kMinGatherStatsPeriod > time_now) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 475 | return; |
| 476 | } |
| 477 | stats_gathering_started_ = time_now; |
| 478 | |
solenberg | 03d6d57 | 2016-03-01 12:42:03 -0800 | [diff] [blame] | 479 | // TODO(pthatcher): Merge PeerConnection and WebRtcSession so there is no |
| 480 | // pc_->session(). |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 481 | if (pc_->session()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 482 | // 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 488 | ExtractSessionInfo(); |
| 489 | ExtractVoiceInfo(); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 490 | ExtractVideoInfo(level); |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 491 | ExtractSenderInfo(); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 492 | ExtractDataInfo(); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 493 | UpdateTrackReports(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 497 | StatsReport* 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.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 503 | StatsReport::Id id(StatsReport::NewIdWithDirection( |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 504 | local ? StatsReport::kStatsReportTypeSsrc |
| 505 | : StatsReport::kStatsReportTypeRemoteSsrc, |
| 506 | rtc::ToString<uint32_t>(ssrc), direction)); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 507 | StatsReport* report = reports_.Find(id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 508 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 509 | // Use the ID of the track that is currently mapped to the SSRC, if any. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 510 | std::string track_id; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 511 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 512 | if (!report) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 513 | // 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 515 | return NULL; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 516 | } |
| 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.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 520 | const StatsReport::Value* v = |
| 521 | report->FindValue(StatsReport::kStatsValueNameTrackId); |
| 522 | if (v) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 523 | track_id = v->string_val(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 524 | } |
| 525 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 526 | if (!report) |
| 527 | report = reports_.InsertNew(id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 528 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 529 | // FYI - for remote reports, the timestamp will be overwritten later. |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 530 | report->set_timestamp(stats_gathering_started_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 531 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 532 | report->AddInt64(StatsReport::kStatsValueNameSsrc, ssrc); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 533 | report->AddString(StatsReport::kStatsValueNameTrackId, track_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 534 | // Add the mapping of SSRC to transport. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 535 | report->AddId(StatsReport::kStatsValueNameTransportId, transport_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 536 | return report; |
| 537 | } |
| 538 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 539 | StatsReport* StatsCollector::AddOneCertificateReport( |
| 540 | const rtc::SSLCertificate* cert, const StatsReport* issuer) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 541 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 542 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 543 | // 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.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 546 | |
| 547 | std::string digest_algorithm; |
| 548 | if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 549 | return nullptr; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 550 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 551 | std::unique_ptr<rtc::SSLFingerprint> ssl_fingerprint( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 552 | rtc::SSLFingerprint::Create(digest_algorithm, cert)); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 553 | |
| 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.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 559 | return nullptr; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 560 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 561 | std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); |
| 562 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 563 | rtc::Buffer der_buffer; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 564 | cert->ToDER(&der_buffer); |
| 565 | std::string der_base64; |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 566 | rtc::Base64::EncodeFromArray(der_buffer.data(), der_buffer.size(), |
| 567 | &der_base64); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 568 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 569 | StatsReport::Id id(StatsReport::NewTypedId( |
| 570 | StatsReport::kStatsReportTypeCertificate, fingerprint)); |
| 571 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 572 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 573 | report->AddString(StatsReport::kStatsValueNameFingerprint, fingerprint); |
| 574 | report->AddString(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 575 | digest_algorithm); |
| 576 | report->AddString(StatsReport::kStatsValueNameDer, der_base64); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 577 | if (issuer) |
| 578 | report->AddId(StatsReport::kStatsValueNameIssuerId, issuer->id()); |
| 579 | return report; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 580 | } |
| 581 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 582 | StatsReport* StatsCollector::AddCertificateReports( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 583 | const rtc::SSLCertificate* cert) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 584 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 585 | // 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. |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 590 | RTC_DCHECK(cert != NULL); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 591 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 592 | StatsReport* issuer = nullptr; |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 593 | std::unique_ptr<rtc::SSLCertChain> chain = cert->GetChain(); |
kwiberg | f5d4786 | 2016-03-15 12:53:24 -0700 | [diff] [blame] | 594 | if (chain) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 595 | // 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 600 | const rtc::SSLCertificate& cert_i = chain->Get(i); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 601 | issuer = AddOneCertificateReport(&cert_i, issuer); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | // Add the leaf certificate. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 605 | return AddOneCertificateReport(cert, issuer); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 606 | } |
| 607 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 608 | StatsReport* 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 Thatcher | 04ac81f | 2015-09-21 11:48:28 -0700 | [diff] [blame] | 618 | {StatsReport::kStatsValueNameActiveConnection, info.best_connection}, |
| 619 | {StatsReport::kStatsValueNameReceiving, info.receiving}, |
| 620 | {StatsReport::kStatsValueNameWritable, info.writable}, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 621 | }; |
| 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[] = { |
| 632 | { 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 | }; |
| 639 | for (const auto& i : int64s) |
| 640 | report->AddInt64(i.name, i.value); |
| 641 | |
| 642 | report->AddString(StatsReport::kStatsValueNameLocalAddress, |
| 643 | info.local_candidate.address().ToString()); |
| 644 | report->AddString(StatsReport::kStatsValueNameLocalCandidateType, |
| 645 | info.local_candidate.type()); |
| 646 | report->AddString(StatsReport::kStatsValueNameRemoteAddress, |
| 647 | info.remote_candidate.address().ToString()); |
| 648 | report->AddString(StatsReport::kStatsValueNameRemoteCandidateType, |
| 649 | info.remote_candidate.type()); |
| 650 | report->AddString(StatsReport::kStatsValueNameTransportType, |
| 651 | info.local_candidate.protocol()); |
| 652 | |
| 653 | return report; |
| 654 | } |
| 655 | |
| 656 | StatsReport* StatsCollector::AddCandidateReport( |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 657 | const cricket::Candidate& candidate, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 658 | bool local) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 659 | StatsReport::Id id(StatsReport::NewCandidateId(local, candidate.id())); |
| 660 | StatsReport* report = reports_.Find(id); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 661 | if (!report) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 662 | report = reports_.InsertNew(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 663 | report->set_timestamp(stats_gathering_started_); |
| 664 | if (local) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 665 | report->AddString(StatsReport::kStatsValueNameCandidateNetworkType, |
| 666 | AdapterTypeToStatsType(candidate.network_type())); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 667 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 668 | report->AddString(StatsReport::kStatsValueNameCandidateIPAddress, |
| 669 | candidate.address().ipaddr().ToString()); |
| 670 | report->AddString(StatsReport::kStatsValueNameCandidatePortNumber, |
| 671 | candidate.address().PortAsString()); |
| 672 | report->AddInt(StatsReport::kStatsValueNameCandidatePriority, |
| 673 | candidate.priority()); |
| 674 | report->AddString(StatsReport::kStatsValueNameCandidateType, |
| 675 | IceCandidateTypeToStatsType(candidate.type())); |
| 676 | report->AddString(StatsReport::kStatsValueNameCandidateTransportType, |
| 677 | candidate.protocol()); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 678 | } |
| 679 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 680 | return report; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 681 | } |
| 682 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 683 | void StatsCollector::ExtractSessionInfo() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 684 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 685 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 686 | // Extract information from the base session. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 687 | StatsReport::Id id(StatsReport::NewTypedId( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 688 | StatsReport::kStatsReportTypeSession, pc_->session()->id())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 689 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 690 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 691 | report->AddBoolean(StatsReport::kStatsValueNameInitiator, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 692 | pc_->session()->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 693 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 694 | SessionStats stats; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 695 | if (!pc_->session()->GetTransportStats(&stats)) { |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 696 | return; |
| 697 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 698 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 699 | // Store the proxy map away for use in SSRC reporting. |
| 700 | // TODO(tommi): This shouldn't be necessary if we post the stats back to the |
| 701 | // signaling thread after fetching them on the worker thread, then just use |
| 702 | // the proxy map directly from the session stats. |
| 703 | // As is, if GetStats() failed, we could be using old (incorrect?) proxy |
| 704 | // data. |
| 705 | proxy_to_transport_ = stats.proxy_to_transport; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 706 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 707 | for (const auto& transport_iter : stats.transport_stats) { |
| 708 | // Attempt to get a copy of the certificates from the transport and |
| 709 | // expose them in stats reports. All channels in a transport share the |
| 710 | // same local and remote certificates. |
| 711 | // |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 712 | StatsReport::Id local_cert_report_id, remote_cert_report_id; |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 713 | rtc::scoped_refptr<rtc::RTCCertificate> certificate; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 714 | if (pc_->session()->GetLocalCertificate( |
| 715 | transport_iter.second.transport_name, &certificate)) { |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 716 | StatsReport* r = AddCertificateReports(&(certificate->ssl_certificate())); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 717 | if (r) |
| 718 | local_cert_report_id = r->id(); |
| 719 | } |
| 720 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 721 | std::unique_ptr<rtc::SSLCertificate> cert = |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 722 | pc_->session()->GetRemoteSSLCertificate( |
| 723 | transport_iter.second.transport_name); |
| 724 | if (cert) { |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 725 | StatsReport* r = AddCertificateReports(cert.get()); |
| 726 | if (r) |
| 727 | remote_cert_report_id = r->id(); |
| 728 | } |
| 729 | |
| 730 | for (const auto& channel_iter : transport_iter.second.channel_stats) { |
| 731 | StatsReport::Id id(StatsReport::NewComponentId( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 732 | transport_iter.second.transport_name, channel_iter.component)); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 733 | StatsReport* channel_report = reports_.ReplaceOrAddNew(id); |
| 734 | channel_report->set_timestamp(stats_gathering_started_); |
| 735 | channel_report->AddInt(StatsReport::kStatsValueNameComponent, |
| 736 | channel_iter.component); |
| 737 | if (local_cert_report_id.get()) { |
| 738 | channel_report->AddId(StatsReport::kStatsValueNameLocalCertificateId, |
| 739 | local_cert_report_id); |
| 740 | } |
| 741 | if (remote_cert_report_id.get()) { |
| 742 | channel_report->AddId(StatsReport::kStatsValueNameRemoteCertificateId, |
| 743 | remote_cert_report_id); |
| 744 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 745 | int srtp_crypto_suite = channel_iter.srtp_crypto_suite; |
| 746 | if (srtp_crypto_suite != rtc::SRTP_INVALID_CRYPTO_SUITE && |
| 747 | rtc::SrtpCryptoSuiteToName(srtp_crypto_suite).length()) { |
| 748 | channel_report->AddString( |
| 749 | StatsReport::kStatsValueNameSrtpCipher, |
| 750 | rtc::SrtpCryptoSuiteToName(srtp_crypto_suite)); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 751 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 752 | int ssl_cipher_suite = channel_iter.ssl_cipher_suite; |
| 753 | if (ssl_cipher_suite != rtc::TLS_NULL_WITH_NULL_NULL && |
| 754 | rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite) |
| 755 | .length()) { |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 756 | channel_report->AddString( |
| 757 | StatsReport::kStatsValueNameDtlsCipher, |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 758 | rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite)); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 759 | } |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 760 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 761 | int connection_id = 0; |
| 762 | for (const cricket::ConnectionInfo& info : |
| 763 | channel_iter.connection_infos) { |
| 764 | StatsReport* connection_report = AddConnectionInfoReport( |
| 765 | transport_iter.first, channel_iter.component, connection_id++, |
| 766 | channel_report->id(), info); |
| 767 | if (info.best_connection) { |
| 768 | channel_report->AddId( |
| 769 | StatsReport::kStatsValueNameSelectedCandidatePairId, |
| 770 | connection_report->id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | void StatsCollector::ExtractVoiceInfo() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 778 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 779 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 780 | if (!pc_->session()->voice_channel()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | cricket::VoiceMediaInfo voice_info; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 784 | if (!pc_->session()->voice_channel()->GetStats(&voice_info)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 785 | LOG(LS_ERROR) << "Failed to get voice channel stats."; |
| 786 | return; |
| 787 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 788 | |
| 789 | // TODO(tommi): The above code should run on the worker thread and post the |
| 790 | // results back to the signaling thread, where we can add data to the reports. |
| 791 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 792 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 793 | StatsReport::Id transport_id(GetTransportIdFromProxy( |
| 794 | proxy_to_transport_, pc_->session()->voice_channel()->content_name())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 795 | if (!transport_id.get()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 796 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 797 | << pc_->session()->voice_channel()->content_name(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 798 | return; |
| 799 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 800 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 801 | ExtractStatsFromList(voice_info.receivers, transport_id, this, |
| 802 | StatsReport::kReceive); |
| 803 | ExtractStatsFromList(voice_info.senders, transport_id, this, |
| 804 | StatsReport::kSend); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 805 | |
| 806 | UpdateStatsFromExistingLocalAudioTracks(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 807 | } |
| 808 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 809 | void StatsCollector::ExtractVideoInfo( |
| 810 | PeerConnectionInterface::StatsOutputLevel level) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 811 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 812 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 813 | if (!pc_->session()->video_channel()) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 814 | return; |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 815 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 816 | cricket::VideoMediaInfo video_info; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 817 | if (!pc_->session()->video_channel()->GetStats(&video_info)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 818 | LOG(LS_ERROR) << "Failed to get video channel stats."; |
| 819 | return; |
| 820 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 821 | |
| 822 | // TODO(tommi): The above code should run on the worker thread and post the |
| 823 | // results back to the signaling thread, where we can add data to the reports. |
| 824 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 825 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 826 | StatsReport::Id transport_id(GetTransportIdFromProxy( |
| 827 | proxy_to_transport_, pc_->session()->video_channel()->content_name())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 828 | if (!transport_id.get()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 829 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 830 | << pc_->session()->video_channel()->content_name(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 831 | return; |
| 832 | } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 833 | ExtractStatsFromList(video_info.receivers, transport_id, this, |
| 834 | StatsReport::kReceive); |
| 835 | ExtractStatsFromList(video_info.senders, transport_id, this, |
| 836 | StatsReport::kSend); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 837 | if (video_info.bw_estimations.size() != 1) { |
| 838 | LOG(LS_ERROR) << "BWEs count: " << video_info.bw_estimations.size(); |
| 839 | } else { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 840 | StatsReport::Id report_id(StatsReport::NewBandwidthEstimationId()); |
| 841 | StatsReport* report = reports_.FindOrAddNew(report_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 842 | ExtractStats( |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 843 | video_info.bw_estimations[0], stats_gathering_started_, level, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 847 | void StatsCollector::ExtractSenderInfo() { |
| 848 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 849 | |
| 850 | for (const auto& sender : pc_->GetSenders()) { |
| 851 | // TODO(nisse): SSRC == 0 currently means none. Delete check when |
| 852 | // that is fixed. |
| 853 | if (!sender->ssrc()) { |
| 854 | continue; |
| 855 | } |
| 856 | const rtc::scoped_refptr<MediaStreamTrackInterface> track(sender->track()); |
| 857 | if (!track || track->kind() != MediaStreamTrackInterface::kVideoKind) { |
| 858 | continue; |
| 859 | } |
| 860 | // Safe, because kind() == kVideoKind implies a subclass of |
| 861 | // VideoTrackInterface; see mediastreaminterface.h. |
| 862 | VideoTrackSourceInterface* source = |
| 863 | static_cast<VideoTrackInterface*>(track.get())->GetSource(); |
| 864 | |
| 865 | VideoTrackSourceInterface::Stats stats; |
| 866 | if (!source->GetStats(&stats)) { |
| 867 | continue; |
| 868 | } |
| 869 | const StatsReport::Id stats_id = StatsReport::NewIdWithDirection( |
| 870 | StatsReport::kStatsReportTypeSsrc, |
| 871 | rtc::ToString<uint32_t>(sender->ssrc()), StatsReport::kSend); |
| 872 | StatsReport* report = reports_.FindOrAddNew(stats_id); |
| 873 | report->AddInt(StatsReport::kStatsValueNameFrameWidthInput, |
| 874 | stats.input_width); |
| 875 | report->AddInt(StatsReport::kStatsValueNameFrameHeightInput, |
| 876 | stats.input_height); |
| 877 | } |
| 878 | } |
| 879 | |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 880 | void StatsCollector::ExtractDataInfo() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 881 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 882 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 883 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 884 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 885 | for (const auto& dc : pc_->sctp_data_channels()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 886 | StatsReport::Id id(StatsReport::NewTypedIntId( |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 887 | StatsReport::kStatsReportTypeDataChannel, dc->id())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 888 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 889 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 890 | report->AddString(StatsReport::kStatsValueNameLabel, dc->label()); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame^] | 891 | // Filter out the initial id (-1). |
| 892 | if (dc->id() >= 0) { |
| 893 | report->AddInt(StatsReport::kStatsValueNameDataChannelId, dc->id()); |
| 894 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 895 | report->AddString(StatsReport::kStatsValueNameProtocol, dc->protocol()); |
| 896 | report->AddString(StatsReport::kStatsValueNameState, |
| 897 | DataChannelInterface::DataStateString(dc->state())); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 901 | StatsReport* StatsCollector::GetReport(const StatsReport::StatsType& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 902 | const std::string& id, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 903 | StatsReport::Direction direction) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 904 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 905 | RTC_DCHECK(type == StatsReport::kStatsReportTypeSsrc || |
| 906 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 907 | return reports_.Find(StatsReport::NewIdWithDirection(type, id, direction)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 908 | } |
| 909 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 910 | void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 911 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 912 | // Loop through the existing local audio tracks. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 913 | for (const auto& it : local_audio_tracks_) { |
| 914 | AudioTrackInterface* track = it.first; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 915 | uint32_t ssrc = it.second; |
| 916 | StatsReport* report = |
| 917 | GetReport(StatsReport::kStatsReportTypeSsrc, |
| 918 | rtc::ToString<uint32_t>(ssrc), StatsReport::kSend); |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 919 | if (report == NULL) { |
| 920 | // This can happen if a local audio track is added to a stream on the |
| 921 | // fly and the report has not been set up yet. Do nothing in this case. |
| 922 | LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; |
| 923 | continue; |
| 924 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 925 | |
| 926 | // The same ssrc can be used by both local and remote audio tracks. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 927 | const StatsReport::Value* v = |
| 928 | report->FindValue(StatsReport::kStatsValueNameTrackId); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 929 | if (!v || v->string_val() != track->id()) |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 930 | continue; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 931 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 932 | report->set_timestamp(stats_gathering_started_); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 933 | UpdateReportFromAudioTrack(track, report); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, |
| 938 | StatsReport* report) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 939 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 940 | RTC_DCHECK(track != NULL); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 941 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 942 | // Don't overwrite report values if they're not available. |
| 943 | int signal_level; |
| 944 | if (track->GetSignalLevel(&signal_level)) { |
| 945 | RTC_DCHECK_GE(signal_level, 0); |
| 946 | report->AddInt(StatsReport::kStatsValueNameAudioInputLevel, signal_level); |
| 947 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 948 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 949 | auto audio_processor(track->GetAudioProcessor()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 950 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 951 | if (audio_processor.get()) { |
| 952 | AudioProcessorInterface::AudioProcessorStats stats; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 953 | audio_processor->GetStats(&stats); |
| 954 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 955 | SetAudioProcessingStats( |
| 956 | report, stats.typing_noise_detected, stats.echo_return_loss, |
| 957 | stats.echo_return_loss_enhancement, stats.echo_delay_median_ms, |
| 958 | stats.aec_quality_min, stats.echo_delay_std_ms); |
Minyue | 2a8a78c | 2016-04-07 16:48:15 +0200 | [diff] [blame] | 959 | |
| 960 | report->AddFloat(StatsReport::kStatsValueNameAecDivergentFilterFraction, |
| 961 | stats.aec_divergent_filter_fraction); |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 962 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 963 | } |
| 964 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 965 | bool StatsCollector::GetTrackIdBySsrc(uint32_t ssrc, |
| 966 | std::string* track_id, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 967 | StatsReport::Direction direction) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 968 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 969 | if (direction == StatsReport::kSend) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 970 | if (!pc_->session()->GetLocalTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 971 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 972 | << " is not associated with a sending track"; |
| 973 | return false; |
| 974 | } |
| 975 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 976 | RTC_DCHECK(direction == StatsReport::kReceive); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 977 | if (!pc_->session()->GetRemoteTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 978 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 979 | << " is not associated with a receiving track"; |
| 980 | return false; |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | return true; |
| 985 | } |
| 986 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 987 | void StatsCollector::UpdateTrackReports() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 988 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 989 | |
| 990 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 991 | |
| 992 | for (const auto& entry : track_ids_) { |
| 993 | StatsReport* report = entry.second; |
| 994 | report->set_timestamp(stats_gathering_started_); |
| 995 | } |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 996 | } |
| 997 | |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 998 | void StatsCollector::ClearUpdateStatsCacheForTest() { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 999 | stats_gathering_started_ = 0; |
| 1000 | } |
| 1001 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1002 | } // namespace webrtc |