henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2012, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "talk/app/webrtc/statscollector.h" |
| 29 | |
| 30 | #include <utility> |
| 31 | #include <vector> |
| 32 | |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 33 | #include "talk/session/media/channel.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 34 | #include "webrtc/base/base64.h" |
| 35 | #include "webrtc/base/scoped_ptr.h" |
| 36 | #include "webrtc/base/timing.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | |
| 38 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | namespace { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 41 | // The following is the enum RTCStatsIceCandidateType from |
| 42 | // http://w3c.github.io/webrtc-stats/#rtcstatsicecandidatetype-enum such that |
| 43 | // our stats report for ice candidate type could conform to that. |
| 44 | const char STATSREPORT_LOCAL_PORT_TYPE[] = "host"; |
| 45 | const char STATSREPORT_STUN_PORT_TYPE[] = "serverreflexive"; |
| 46 | const char STATSREPORT_PRFLX_PORT_TYPE[] = "peerreflexive"; |
| 47 | const char STATSREPORT_RELAY_PORT_TYPE[] = "relayed"; |
| 48 | |
| 49 | // Strings used by the stats collector to report adapter types. This fits the |
| 50 | // general stype of http://w3c.github.io/webrtc-stats than what |
| 51 | // AdapterTypeToString does. |
| 52 | const char* STATSREPORT_ADAPTER_TYPE_ETHERNET = "lan"; |
| 53 | const char* STATSREPORT_ADAPTER_TYPE_WIFI = "wlan"; |
| 54 | const char* STATSREPORT_ADAPTER_TYPE_WWAN = "wwan"; |
| 55 | const char* STATSREPORT_ADAPTER_TYPE_VPN = "vpn"; |
| 56 | |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 57 | double GetTimeNow() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 58 | return rtc::Timing::WallTimeNow() * rtc::kNumMillisecsPerSec; |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | bool GetTransportIdFromProxy(const cricket::ProxyTransportMap& map, |
| 62 | const std::string& proxy, |
| 63 | std::string* transport) { |
| 64 | // TODO(hta): Remove handling of empty proxy name once tests do not use it. |
| 65 | if (proxy.empty()) { |
| 66 | transport->clear(); |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | cricket::ProxyTransportMap::const_iterator found = map.find(proxy); |
| 71 | if (found == map.end()) { |
| 72 | LOG(LS_ERROR) << "No transport ID mapping for " << proxy; |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | std::ostringstream ost; |
| 77 | // Component 1 is always used for RTP. |
| 78 | ost << "Channel-" << found->second << "-1"; |
| 79 | *transport = ost.str(); |
| 80 | return true; |
| 81 | } |
| 82 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | std::string StatsId(const std::string& type, const std::string& id) { |
| 84 | return type + "_" + id; |
| 85 | } |
| 86 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 87 | std::string StatsId(const std::string& type, const std::string& id, |
| 88 | StatsCollector::TrackDirection direction) { |
| 89 | ASSERT(direction == StatsCollector::kSending || |
| 90 | direction == StatsCollector::kReceiving); |
| 91 | |
| 92 | // Strings for the direction of the track. |
| 93 | const char kSendDirection[] = "send"; |
| 94 | const char kRecvDirection[] = "recv"; |
| 95 | |
| 96 | const std::string direction_id = (direction == StatsCollector::kSending) ? |
| 97 | kSendDirection : kRecvDirection; |
| 98 | return type + "_" + id + "_" + direction_id; |
| 99 | } |
| 100 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | bool ExtractValueFromReport( |
| 102 | const StatsReport& report, |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 103 | StatsReport::StatsValueName name, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | std::string* value) { |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 105 | StatsReport::Values::const_iterator it = report.values.begin(); |
| 106 | for (; it != report.values.end(); ++it) { |
| 107 | if (it->name == name) { |
| 108 | *value = it->value; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | return true; |
| 110 | } |
| 111 | } |
| 112 | return false; |
| 113 | } |
| 114 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 115 | void AddTrackReport(StatsSet* reports, const std::string& track_id) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 116 | // Adds an empty track report. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 117 | StatsReport* report = reports->ReplaceOrAddNew( |
| 118 | StatsId(StatsReport::kStatsReportTypeTrack, track_id)); |
| 119 | report->type = StatsReport::kStatsReportTypeTrack; |
| 120 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 121 | } |
| 122 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | template <class TrackVector> |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 124 | void CreateTrackReports(const TrackVector& tracks, StatsSet* reports) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | for (size_t j = 0; j < tracks.size(); ++j) { |
| 126 | webrtc::MediaStreamTrackInterface* track = tracks[j]; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 127 | AddTrackReport(reports, track->id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | void ExtractStats(const cricket::VoiceReceiverInfo& info, StatsReport* report) { |
| 132 | report->AddValue(StatsReport::kStatsValueNameAudioOutputLevel, |
| 133 | info.audio_level); |
| 134 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 135 | info.bytes_rcvd); |
| 136 | report->AddValue(StatsReport::kStatsValueNameJitterReceived, |
| 137 | info.jitter_ms); |
jiayl@webrtc.org | 11aab0e | 2014-03-07 18:56:26 +0000 | [diff] [blame] | 138 | report->AddValue(StatsReport::kStatsValueNameJitterBufferMs, |
| 139 | info.jitter_buffer_ms); |
| 140 | report->AddValue(StatsReport::kStatsValueNamePreferredJitterBufferMs, |
| 141 | info.jitter_buffer_preferred_ms); |
| 142 | report->AddValue(StatsReport::kStatsValueNameCurrentDelayMs, |
| 143 | info.delay_estimate_ms); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 144 | report->AddValue(StatsReport::kStatsValueNameExpandRate, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 145 | rtc::ToString<float>(info.expand_rate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | report->AddValue(StatsReport::kStatsValueNamePacketsReceived, |
| 147 | info.packets_rcvd); |
| 148 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 149 | info.packets_lost); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 150 | report->AddValue(StatsReport::kStatsValueNameDecodingCTSG, |
| 151 | info.decoding_calls_to_silence_generator); |
| 152 | report->AddValue(StatsReport::kStatsValueNameDecodingCTN, |
| 153 | info.decoding_calls_to_neteq); |
| 154 | report->AddValue(StatsReport::kStatsValueNameDecodingNormal, |
| 155 | info.decoding_normal); |
| 156 | report->AddValue(StatsReport::kStatsValueNameDecodingPLC, |
| 157 | info.decoding_plc); |
| 158 | report->AddValue(StatsReport::kStatsValueNameDecodingCNG, |
| 159 | info.decoding_cng); |
| 160 | report->AddValue(StatsReport::kStatsValueNameDecodingPLCCNG, |
| 161 | info.decoding_plc_cng); |
buildbot@webrtc.org | b525a9d | 2014-06-03 09:42:15 +0000 | [diff] [blame] | 162 | report->AddValue(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 163 | info.capture_start_ntp_time_ms); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 164 | report->AddValue(StatsReport::kStatsValueNameCodecName, info.codec_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void ExtractStats(const cricket::VoiceSenderInfo& info, StatsReport* report) { |
| 168 | report->AddValue(StatsReport::kStatsValueNameAudioInputLevel, |
| 169 | info.audio_level); |
| 170 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 171 | info.bytes_sent); |
| 172 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 173 | info.packets_sent); |
henrike@webrtc.org | ffe2620 | 2014-03-19 22:20:10 +0000 | [diff] [blame] | 174 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 175 | info.packets_lost); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | report->AddValue(StatsReport::kStatsValueNameJitterReceived, |
| 177 | info.jitter_ms); |
| 178 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 179 | report->AddValue(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 180 | rtc::ToString<float>(info.aec_quality_min)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 181 | report->AddValue(StatsReport::kStatsValueNameEchoDelayMedian, |
| 182 | info.echo_delay_median_ms); |
| 183 | report->AddValue(StatsReport::kStatsValueNameEchoDelayStdDev, |
| 184 | info.echo_delay_std_ms); |
| 185 | report->AddValue(StatsReport::kStatsValueNameEchoReturnLoss, |
| 186 | info.echo_return_loss); |
| 187 | report->AddValue(StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
| 188 | info.echo_return_loss_enhancement); |
| 189 | report->AddValue(StatsReport::kStatsValueNameCodecName, info.codec_name); |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 190 | report->AddBoolean(StatsReport::kStatsValueNameTypingNoiseState, |
| 191 | info.typing_noise_detected); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void ExtractStats(const cricket::VideoReceiverInfo& info, StatsReport* report) { |
| 195 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 196 | info.bytes_rcvd); |
| 197 | report->AddValue(StatsReport::kStatsValueNamePacketsReceived, |
| 198 | info.packets_rcvd); |
| 199 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 200 | info.packets_lost); |
| 201 | |
| 202 | report->AddValue(StatsReport::kStatsValueNameFirsSent, |
| 203 | info.firs_sent); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 204 | report->AddValue(StatsReport::kStatsValueNamePlisSent, |
| 205 | info.plis_sent); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | report->AddValue(StatsReport::kStatsValueNameNacksSent, |
| 207 | info.nacks_sent); |
| 208 | report->AddValue(StatsReport::kStatsValueNameFrameWidthReceived, |
| 209 | info.frame_width); |
| 210 | report->AddValue(StatsReport::kStatsValueNameFrameHeightReceived, |
| 211 | info.frame_height); |
| 212 | report->AddValue(StatsReport::kStatsValueNameFrameRateReceived, |
| 213 | info.framerate_rcvd); |
| 214 | report->AddValue(StatsReport::kStatsValueNameFrameRateDecoded, |
| 215 | info.framerate_decoded); |
| 216 | report->AddValue(StatsReport::kStatsValueNameFrameRateOutput, |
| 217 | info.framerate_output); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 218 | |
| 219 | report->AddValue(StatsReport::kStatsValueNameDecodeMs, |
| 220 | info.decode_ms); |
| 221 | report->AddValue(StatsReport::kStatsValueNameMaxDecodeMs, |
| 222 | info.max_decode_ms); |
| 223 | report->AddValue(StatsReport::kStatsValueNameCurrentDelayMs, |
| 224 | info.current_delay_ms); |
| 225 | report->AddValue(StatsReport::kStatsValueNameTargetDelayMs, |
| 226 | info.target_delay_ms); |
| 227 | report->AddValue(StatsReport::kStatsValueNameJitterBufferMs, |
| 228 | info.jitter_buffer_ms); |
| 229 | report->AddValue(StatsReport::kStatsValueNameMinPlayoutDelayMs, |
| 230 | info.min_playout_delay_ms); |
| 231 | report->AddValue(StatsReport::kStatsValueNameRenderDelayMs, |
| 232 | info.render_delay_ms); |
buildbot@webrtc.org | 0581f0b | 2014-05-06 21:36:31 +0000 | [diff] [blame] | 233 | |
| 234 | report->AddValue(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 235 | info.capture_start_ntp_time_ms); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void ExtractStats(const cricket::VideoSenderInfo& info, StatsReport* report) { |
| 239 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 240 | info.bytes_sent); |
| 241 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 242 | info.packets_sent); |
henrike@webrtc.org | ffe2620 | 2014-03-19 22:20:10 +0000 | [diff] [blame] | 243 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 244 | info.packets_lost); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | |
| 246 | report->AddValue(StatsReport::kStatsValueNameFirsReceived, |
| 247 | info.firs_rcvd); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 248 | report->AddValue(StatsReport::kStatsValueNamePlisReceived, |
| 249 | info.plis_rcvd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 250 | report->AddValue(StatsReport::kStatsValueNameNacksReceived, |
| 251 | info.nacks_rcvd); |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 252 | report->AddValue(StatsReport::kStatsValueNameFrameWidthInput, |
| 253 | info.input_frame_width); |
| 254 | report->AddValue(StatsReport::kStatsValueNameFrameHeightInput, |
| 255 | info.input_frame_height); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 256 | report->AddValue(StatsReport::kStatsValueNameFrameWidthSent, |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 257 | info.send_frame_width); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 258 | report->AddValue(StatsReport::kStatsValueNameFrameHeightSent, |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 259 | info.send_frame_height); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 260 | report->AddValue(StatsReport::kStatsValueNameFrameRateInput, |
| 261 | info.framerate_input); |
| 262 | report->AddValue(StatsReport::kStatsValueNameFrameRateSent, |
| 263 | info.framerate_sent); |
| 264 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 265 | report->AddValue(StatsReport::kStatsValueNameCodecName, info.codec_name); |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 266 | report->AddBoolean(StatsReport::kStatsValueNameCpuLimitedResolution, |
| 267 | (info.adapt_reason & 0x1) > 0); |
| 268 | report->AddBoolean(StatsReport::kStatsValueNameBandwidthLimitedResolution, |
| 269 | (info.adapt_reason & 0x2) > 0); |
| 270 | report->AddBoolean(StatsReport::kStatsValueNameViewLimitedResolution, |
| 271 | (info.adapt_reason & 0x4) > 0); |
buildbot@webrtc.org | 71dffb7 | 2014-06-24 07:24:49 +0000 | [diff] [blame] | 272 | report->AddValue(StatsReport::kStatsValueNameAdaptationChanges, |
| 273 | info.adapt_changes); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 274 | report->AddValue(StatsReport::kStatsValueNameAvgEncodeMs, info.avg_encode_ms); |
| 275 | report->AddValue(StatsReport::kStatsValueNameCaptureJitterMs, |
| 276 | info.capture_jitter_ms); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 277 | report->AddValue(StatsReport::kStatsValueNameCaptureQueueDelayMsPerS, |
| 278 | info.capture_queue_delay_ms_per_s); |
| 279 | report->AddValue(StatsReport::kStatsValueNameEncodeUsagePercent, |
| 280 | info.encode_usage_percent); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void ExtractStats(const cricket::BandwidthEstimationInfo& info, |
| 284 | double stats_gathering_started, |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 285 | PeerConnectionInterface::StatsOutputLevel level, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 286 | StatsReport* report) { |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 287 | ASSERT(report->id == StatsReport::kStatsReportVideoBweId); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 288 | report->type = StatsReport::kStatsReportTypeBwe; |
| 289 | |
| 290 | // Clear out stats from previous GatherStats calls if any. |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 291 | if (report->timestamp != stats_gathering_started) { |
| 292 | report->values.clear(); |
| 293 | report->timestamp = stats_gathering_started; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | report->AddValue(StatsReport::kStatsValueNameAvailableSendBandwidth, |
| 297 | info.available_send_bandwidth); |
| 298 | report->AddValue(StatsReport::kStatsValueNameAvailableReceiveBandwidth, |
| 299 | info.available_recv_bandwidth); |
| 300 | report->AddValue(StatsReport::kStatsValueNameTargetEncBitrate, |
| 301 | info.target_enc_bitrate); |
| 302 | report->AddValue(StatsReport::kStatsValueNameActualEncBitrate, |
| 303 | info.actual_enc_bitrate); |
| 304 | report->AddValue(StatsReport::kStatsValueNameRetransmitBitrate, |
| 305 | info.retransmit_bitrate); |
| 306 | report->AddValue(StatsReport::kStatsValueNameTransmitBitrate, |
| 307 | info.transmit_bitrate); |
| 308 | report->AddValue(StatsReport::kStatsValueNameBucketDelay, |
| 309 | info.bucket_delay); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 310 | if (level >= PeerConnectionInterface::kStatsOutputLevelDebug) { |
| 311 | report->AddValue( |
| 312 | StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaSumDebug, |
| 313 | info.total_received_propagation_delta_ms); |
| 314 | if (info.recent_received_propagation_delta_ms.size() > 0) { |
| 315 | report->AddValue( |
| 316 | StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaDebug, |
| 317 | info.recent_received_propagation_delta_ms); |
| 318 | report->AddValue( |
| 319 | StatsReport::kStatsValueNameRecvPacketGroupArrivalTimeDebug, |
| 320 | info.recent_received_packet_group_arrival_time_ms); |
| 321 | } |
| 322 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 323 | } |
| 324 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 325 | void ExtractRemoteStats(const cricket::MediaSenderInfo& info, |
| 326 | StatsReport* report) { |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 327 | report->timestamp = info.remote_stats[0].timestamp; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 328 | // TODO(hta): Extract some stats here. |
| 329 | } |
| 330 | |
| 331 | void ExtractRemoteStats(const cricket::MediaReceiverInfo& info, |
| 332 | StatsReport* report) { |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 333 | report->timestamp = info.remote_stats[0].timestamp; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 334 | // TODO(hta): Extract some stats here. |
| 335 | } |
| 336 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 337 | // Template to extract stats from a data vector. |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 338 | // In order to use the template, the functions that are called from it, |
| 339 | // ExtractStats and ExtractRemoteStats, must be defined and overloaded |
| 340 | // for each type. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | template<typename T> |
| 342 | void ExtractStatsFromList(const std::vector<T>& data, |
| 343 | const std::string& transport_id, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 344 | StatsCollector* collector, |
| 345 | StatsCollector::TrackDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 346 | typename std::vector<T>::const_iterator it = data.begin(); |
| 347 | for (; it != data.end(); ++it) { |
| 348 | std::string id; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 349 | uint32 ssrc = it->ssrc(); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 350 | // Each track can have stats for both local and remote objects. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 351 | // TODO(hta): Handle the case of multiple SSRCs per object. |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 352 | StatsReport* report = collector->PrepareLocalReport(ssrc, transport_id, |
| 353 | direction); |
| 354 | if (report) |
| 355 | ExtractStats(*it, report); |
| 356 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 357 | if (it->remote_stats.size() > 0) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 358 | report = collector->PrepareRemoteReport(ssrc, transport_id, |
| 359 | direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 360 | if (!report) { |
| 361 | continue; |
| 362 | } |
| 363 | ExtractRemoteStats(*it, report); |
| 364 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 365 | } |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 366 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 367 | |
| 368 | } // namespace |
| 369 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 370 | const char* IceCandidateTypeToStatsType(const std::string& candidate_type) { |
| 371 | if (candidate_type == cricket::LOCAL_PORT_TYPE) { |
| 372 | return STATSREPORT_LOCAL_PORT_TYPE; |
| 373 | } |
| 374 | if (candidate_type == cricket::STUN_PORT_TYPE) { |
| 375 | return STATSREPORT_STUN_PORT_TYPE; |
| 376 | } |
| 377 | if (candidate_type == cricket::PRFLX_PORT_TYPE) { |
| 378 | return STATSREPORT_PRFLX_PORT_TYPE; |
| 379 | } |
| 380 | if (candidate_type == cricket::RELAY_PORT_TYPE) { |
| 381 | return STATSREPORT_RELAY_PORT_TYPE; |
| 382 | } |
| 383 | ASSERT(false); |
| 384 | return "unknown"; |
| 385 | } |
| 386 | |
| 387 | const char* AdapterTypeToStatsType(rtc::AdapterType type) { |
| 388 | switch (type) { |
| 389 | case rtc::ADAPTER_TYPE_UNKNOWN: |
| 390 | return "unknown"; |
| 391 | case rtc::ADAPTER_TYPE_ETHERNET: |
| 392 | return STATSREPORT_ADAPTER_TYPE_ETHERNET; |
| 393 | case rtc::ADAPTER_TYPE_WIFI: |
| 394 | return STATSREPORT_ADAPTER_TYPE_WIFI; |
| 395 | case rtc::ADAPTER_TYPE_CELLULAR: |
| 396 | return STATSREPORT_ADAPTER_TYPE_WWAN; |
| 397 | case rtc::ADAPTER_TYPE_VPN: |
| 398 | return STATSREPORT_ADAPTER_TYPE_VPN; |
| 399 | default: |
| 400 | ASSERT(false); |
| 401 | return ""; |
| 402 | } |
| 403 | } |
| 404 | |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 405 | StatsCollector::StatsCollector(WebRtcSession* session) |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 406 | : session_(session), |
| 407 | stats_gathering_started_(0) { |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 408 | ASSERT(session_); |
| 409 | } |
| 410 | |
| 411 | StatsCollector::~StatsCollector() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 412 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 416 | // to GetStats. |
| 417 | void StatsCollector::AddStream(MediaStreamInterface* stream) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 418 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 419 | ASSERT(stream != NULL); |
| 420 | |
| 421 | CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), |
| 422 | &reports_); |
| 423 | CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), |
| 424 | &reports_); |
| 425 | } |
| 426 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 427 | void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, |
| 428 | uint32 ssrc) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 429 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 430 | ASSERT(audio_track != NULL); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 431 | for (LocalAudioTrackVector::iterator it = local_audio_tracks_.begin(); |
| 432 | it != local_audio_tracks_.end(); ++it) { |
| 433 | ASSERT(it->first != audio_track || it->second != ssrc); |
| 434 | } |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 435 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 436 | local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc)); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 437 | |
| 438 | // Create the kStatsReportTypeTrack report for the new track if there is no |
| 439 | // report yet. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 440 | StatsReport* found = reports_.Find( |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 441 | StatsId(StatsReport::kStatsReportTypeTrack, audio_track->id())); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 442 | if (!found) |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 443 | AddTrackReport(&reports_, audio_track->id()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, |
| 447 | uint32 ssrc) { |
| 448 | ASSERT(audio_track != NULL); |
| 449 | for (LocalAudioTrackVector::iterator it = local_audio_tracks_.begin(); |
| 450 | it != local_audio_tracks_.end(); ++it) { |
| 451 | if (it->first == audio_track && it->second == ssrc) { |
| 452 | local_audio_tracks_.erase(it); |
| 453 | return; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | ASSERT(false); |
| 458 | } |
| 459 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 460 | void StatsCollector::GetStats(MediaStreamTrackInterface* track, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 461 | StatsReports* reports) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 462 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 463 | ASSERT(reports != NULL); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 464 | ASSERT(reports->empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 466 | if (!track) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 467 | StatsSet::const_iterator it; |
| 468 | for (it = reports_.begin(); it != reports_.end(); ++it) |
| 469 | reports->push_back(&(*it)); |
| 470 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 471 | } |
| 472 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 473 | StatsReport* report = |
| 474 | reports_.Find(StatsId(StatsReport::kStatsReportTypeSession, |
| 475 | session_->id())); |
| 476 | if (report) |
| 477 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 478 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 479 | report = reports_.Find( |
| 480 | StatsId(StatsReport::kStatsReportTypeTrack, track->id())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 481 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 482 | if (!report) |
| 483 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 484 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 485 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 486 | |
| 487 | std::string track_id; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 488 | for (StatsSet::const_iterator it = reports_.begin(); it != reports_.end(); |
| 489 | ++it) { |
| 490 | if (it->type != StatsReport::kStatsReportTypeSsrc) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 491 | continue; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 492 | |
| 493 | if (ExtractValueFromReport(*it, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 494 | StatsReport::kStatsValueNameTrackId, |
| 495 | &track_id)) { |
| 496 | if (track_id == track->id()) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 497 | reports->push_back(&(*it)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 501 | } |
| 502 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 503 | void |
| 504 | StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 505 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 506 | double time_now = GetTimeNow(); |
| 507 | // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of |
| 508 | // ms apart will be ignored. |
| 509 | const double kMinGatherStatsPeriod = 50; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 510 | if (stats_gathering_started_ != 0 && |
| 511 | stats_gathering_started_ + kMinGatherStatsPeriod > time_now) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 512 | return; |
| 513 | } |
| 514 | stats_gathering_started_ = time_now; |
| 515 | |
| 516 | if (session_) { |
| 517 | ExtractSessionInfo(); |
| 518 | ExtractVoiceInfo(); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 519 | ExtractVideoInfo(level); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 520 | ExtractDataInfo(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 524 | StatsReport* StatsCollector::PrepareLocalReport( |
| 525 | uint32 ssrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 526 | const std::string& transport_id, |
| 527 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 528 | ASSERT(session_->signaling_thread()->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 529 | const std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 530 | StatsReport* report = reports_.Find( |
| 531 | StatsId(StatsReport::kStatsReportTypeSsrc, ssrc_id, direction)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 532 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 533 | // 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] | 534 | std::string track_id; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 535 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 536 | if (!report) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 537 | // The ssrc is not used by any track or existing report, return NULL |
| 538 | // 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] | 539 | return NULL; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | // The ssrc is not used by any existing track. Keeps the old track id |
| 543 | // since we want to report the stats for inactive ssrc. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 544 | ExtractValueFromReport(*report, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 545 | StatsReport::kStatsValueNameTrackId, |
| 546 | &track_id); |
| 547 | } |
| 548 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 549 | report = GetOrCreateReport( |
| 550 | StatsReport::kStatsReportTypeSsrc, ssrc_id, direction); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 551 | |
| 552 | // Clear out stats from previous GatherStats calls if any. |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 553 | // This is required since the report will be returned for the new values. |
| 554 | // Having the old values in the report will lead to multiple values with |
| 555 | // the same name. |
| 556 | // TODO(xians): Consider changing StatsReport to use map instead of vector. |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 557 | report->values.clear(); |
| 558 | report->timestamp = stats_gathering_started_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 559 | |
| 560 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 561 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 562 | // Add the mapping of SSRC to transport. |
| 563 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 564 | transport_id); |
| 565 | return report; |
| 566 | } |
| 567 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 568 | StatsReport* StatsCollector::PrepareRemoteReport( |
| 569 | uint32 ssrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 570 | const std::string& transport_id, |
| 571 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 572 | ASSERT(session_->signaling_thread()->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 573 | const std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 574 | StatsReport* report = reports_.Find( |
| 575 | StatsId(StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id, direction)); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 576 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 577 | // Use the ID of the track that is currently mapped to the SSRC, if any. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 578 | std::string track_id; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 579 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 580 | if (!report) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 581 | // The ssrc is not used by any track or existing report, return NULL |
| 582 | // in such case to indicate no report is prepared for the ssrc. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 583 | return NULL; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | // The ssrc is not used by any existing track. Keeps the old track id |
| 587 | // since we want to report the stats for inactive ssrc. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 588 | ExtractValueFromReport(*report, |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 589 | StatsReport::kStatsValueNameTrackId, |
| 590 | &track_id); |
| 591 | } |
| 592 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 593 | report = GetOrCreateReport( |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 594 | StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id, direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 595 | |
| 596 | // Clear out stats from previous GatherStats calls if any. |
| 597 | // The timestamp will be added later. Zero it for debugging. |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 598 | report->values.clear(); |
| 599 | report->timestamp = 0; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 600 | |
| 601 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 602 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 603 | // Add the mapping of SSRC to transport. |
| 604 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 605 | transport_id); |
| 606 | return report; |
| 607 | } |
| 608 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 609 | std::string StatsCollector::AddOneCertificateReport( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 610 | const rtc::SSLCertificate* cert, const std::string& issuer_id) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 611 | // TODO(bemasc): Move this computation to a helper class that caches these |
| 612 | // values to reduce CPU use in GetStats. This will require adding a fast |
| 613 | // SSLCertificate::Equals() method to detect certificate changes. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 614 | |
| 615 | std::string digest_algorithm; |
| 616 | if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) |
| 617 | return std::string(); |
| 618 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 619 | rtc::scoped_ptr<rtc::SSLFingerprint> ssl_fingerprint( |
| 620 | rtc::SSLFingerprint::Create(digest_algorithm, cert)); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 621 | |
| 622 | // SSLFingerprint::Create can fail if the algorithm returned by |
| 623 | // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the |
| 624 | // implementation of SSLCertificate::ComputeDigest. This currently happens |
| 625 | // with MD5- and SHA-224-signed certificates when linked to libNSS. |
| 626 | if (!ssl_fingerprint) |
| 627 | return std::string(); |
| 628 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 629 | std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); |
| 630 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 631 | rtc::Buffer der_buffer; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 632 | cert->ToDER(&der_buffer); |
| 633 | std::string der_base64; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 634 | rtc::Base64::EncodeFromArray( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 635 | der_buffer.data(), der_buffer.length(), &der_base64); |
| 636 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 637 | StatsReport* report = reports_.ReplaceOrAddNew( |
| 638 | StatsId(StatsReport::kStatsReportTypeCertificate, fingerprint)); |
| 639 | report->type = StatsReport::kStatsReportTypeCertificate; |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 640 | report->timestamp = stats_gathering_started_; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 641 | report->AddValue(StatsReport::kStatsValueNameFingerprint, fingerprint); |
| 642 | report->AddValue(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 643 | digest_algorithm); |
| 644 | report->AddValue(StatsReport::kStatsValueNameDer, der_base64); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 645 | if (!issuer_id.empty()) |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 646 | report->AddValue(StatsReport::kStatsValueNameIssuerId, issuer_id); |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 647 | return report->id; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | std::string StatsCollector::AddCertificateReports( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 651 | const rtc::SSLCertificate* cert) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 652 | // Produces a chain of StatsReports representing this certificate and the rest |
| 653 | // of its chain, and adds those reports to |reports_|. The return value is |
| 654 | // the id of the leaf report. The provided cert must be non-null, so at least |
| 655 | // one report will always be provided and the returned string will never be |
| 656 | // empty. |
| 657 | ASSERT(cert != NULL); |
| 658 | |
| 659 | std::string issuer_id; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 660 | rtc::scoped_ptr<rtc::SSLCertChain> chain; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 661 | if (cert->GetChain(chain.accept())) { |
| 662 | // This loop runs in reverse, i.e. from root to leaf, so that each |
| 663 | // certificate's issuer's report ID is known before the child certificate's |
| 664 | // report is generated. The root certificate does not have an issuer ID |
| 665 | // value. |
| 666 | for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 667 | const rtc::SSLCertificate& cert_i = chain->Get(i); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 668 | issuer_id = AddOneCertificateReport(&cert_i, issuer_id); |
| 669 | } |
| 670 | } |
| 671 | // Add the leaf certificate. |
| 672 | return AddOneCertificateReport(cert, issuer_id); |
| 673 | } |
| 674 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 675 | std::string StatsCollector::AddCandidateReport( |
| 676 | const cricket::Candidate& candidate, |
| 677 | const std::string& report_type) { |
| 678 | std::ostringstream ost; |
| 679 | ost << "Cand-" << candidate.id(); |
| 680 | StatsReport* report = reports_.Find(ost.str()); |
| 681 | if (!report) { |
| 682 | report = reports_.InsertNew(ost.str()); |
| 683 | DCHECK(StatsReport::kStatsReportTypeIceLocalCandidate == report_type || |
| 684 | StatsReport::kStatsReportTypeIceRemoteCandidate == report_type); |
| 685 | report->type = report_type; |
| 686 | if (report_type == StatsReport::kStatsReportTypeIceLocalCandidate) { |
| 687 | report->AddValue(StatsReport::kStatsValueNameCandidateNetworkType, |
| 688 | AdapterTypeToStatsType(candidate.network_type())); |
| 689 | } |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 690 | report->timestamp = stats_gathering_started_; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 691 | report->AddValue(StatsReport::kStatsValueNameCandidateIPAddress, |
| 692 | candidate.address().ipaddr().ToString()); |
| 693 | report->AddValue(StatsReport::kStatsValueNameCandidatePortNumber, |
| 694 | candidate.address().PortAsString()); |
| 695 | report->AddValue(StatsReport::kStatsValueNameCandidatePriority, |
| 696 | candidate.priority()); |
| 697 | report->AddValue(StatsReport::kStatsValueNameCandidateType, |
| 698 | IceCandidateTypeToStatsType(candidate.type())); |
| 699 | report->AddValue(StatsReport::kStatsValueNameCandidateTransportType, |
| 700 | candidate.protocol()); |
| 701 | } |
| 702 | |
| 703 | return ost.str(); |
| 704 | } |
| 705 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 706 | void StatsCollector::ExtractSessionInfo() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 707 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 708 | // Extract information from the base session. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 709 | StatsReport* report = reports_.ReplaceOrAddNew( |
| 710 | StatsId(StatsReport::kStatsReportTypeSession, session_->id())); |
| 711 | report->type = StatsReport::kStatsReportTypeSession; |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 712 | report->timestamp = stats_gathering_started_; |
| 713 | report->values.clear(); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 714 | report->AddBoolean(StatsReport::kStatsValueNameInitiator, |
| 715 | session_->initiator()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 716 | |
| 717 | cricket::SessionStats stats; |
| 718 | if (session_->GetStats(&stats)) { |
| 719 | // Store the proxy map away for use in SSRC reporting. |
| 720 | proxy_to_transport_ = stats.proxy_to_transport; |
| 721 | |
| 722 | for (cricket::TransportStatsMap::iterator transport_iter |
| 723 | = stats.transport_stats.begin(); |
| 724 | transport_iter != stats.transport_stats.end(); ++transport_iter) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 725 | // Attempt to get a copy of the certificates from the transport and |
| 726 | // expose them in stats reports. All channels in a transport share the |
| 727 | // same local and remote certificates. |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 728 | // |
| 729 | // Note that Transport::GetIdentity and Transport::GetRemoteCertificate |
| 730 | // invoke method calls on the worker thread and block this thread, but |
| 731 | // messages are still processed on this thread, which may blow way the |
| 732 | // existing transports. So we cannot reuse |transport| after these calls. |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 733 | std::string local_cert_report_id, remote_cert_report_id; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 734 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 735 | cricket::Transport* transport = |
| 736 | session_->GetTransport(transport_iter->second.content_name); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 737 | rtc::scoped_ptr<rtc::SSLIdentity> identity; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 738 | if (transport && transport->GetIdentity(identity.accept())) { |
| 739 | local_cert_report_id = |
| 740 | AddCertificateReports(&(identity->certificate())); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 741 | } |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 742 | |
| 743 | transport = session_->GetTransport(transport_iter->second.content_name); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 744 | rtc::scoped_ptr<rtc::SSLCertificate> cert; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 745 | if (transport && transport->GetRemoteCertificate(cert.accept())) { |
| 746 | remote_cert_report_id = AddCertificateReports(cert.get()); |
| 747 | } |
| 748 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | for (cricket::TransportChannelStatsList::iterator channel_iter |
| 750 | = transport_iter->second.channel_stats.begin(); |
| 751 | channel_iter != transport_iter->second.channel_stats.end(); |
| 752 | ++channel_iter) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 753 | std::ostringstream ostc; |
| 754 | ostc << "Channel-" << transport_iter->second.content_name |
| 755 | << "-" << channel_iter->component; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 756 | StatsReport* channel_report = reports_.ReplaceOrAddNew(ostc.str()); |
| 757 | channel_report->type = StatsReport::kStatsReportTypeComponent; |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 758 | channel_report->timestamp = stats_gathering_started_; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 759 | channel_report->AddValue(StatsReport::kStatsValueNameComponent, |
| 760 | channel_iter->component); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 761 | if (!local_cert_report_id.empty()) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 762 | channel_report->AddValue( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 763 | StatsReport::kStatsValueNameLocalCertificateId, |
| 764 | local_cert_report_id); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 765 | } |
| 766 | if (!remote_cert_report_id.empty()) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 767 | channel_report->AddValue( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 768 | StatsReport::kStatsValueNameRemoteCertificateId, |
| 769 | remote_cert_report_id); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 770 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 771 | for (size_t i = 0; |
| 772 | i < channel_iter->connection_infos.size(); |
| 773 | ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 774 | std::ostringstream ost; |
| 775 | ost << "Conn-" << transport_iter->first << "-" |
| 776 | << channel_iter->component << "-" << i; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 777 | StatsReport* report = reports_.ReplaceOrAddNew(ost.str()); |
| 778 | report->type = StatsReport::kStatsReportTypeCandidatePair; |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 779 | report->timestamp = stats_gathering_started_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 780 | // Link from connection to its containing channel. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 781 | report->AddValue(StatsReport::kStatsValueNameChannelId, |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 782 | channel_report->id); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 783 | |
| 784 | const cricket::ConnectionInfo& info = |
| 785 | channel_iter->connection_infos[i]; |
| 786 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 787 | info.sent_total_bytes); |
guoweis@webrtc.org | 930e004 | 2014-11-17 19:42:14 +0000 | [diff] [blame] | 788 | report->AddValue(StatsReport::kStatsValueNameSendPacketsDiscarded, |
| 789 | info.sent_discarded_packets); |
| 790 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 791 | info.sent_total_packets); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 792 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 793 | info.recv_total_bytes); |
| 794 | report->AddBoolean(StatsReport::kStatsValueNameWritable, |
| 795 | info.writable); |
| 796 | report->AddBoolean(StatsReport::kStatsValueNameReadable, |
| 797 | info.readable); |
| 798 | report->AddBoolean(StatsReport::kStatsValueNameActiveConnection, |
| 799 | info.best_connection); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 800 | report->AddValue(StatsReport::kStatsValueNameLocalCandidateId, |
| 801 | AddCandidateReport( |
| 802 | info.local_candidate, |
| 803 | StatsReport::kStatsReportTypeIceLocalCandidate)); |
| 804 | report->AddValue( |
| 805 | StatsReport::kStatsValueNameRemoteCandidateId, |
| 806 | AddCandidateReport( |
| 807 | info.remote_candidate, |
| 808 | StatsReport::kStatsReportTypeIceRemoteCandidate)); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 809 | report->AddValue(StatsReport::kStatsValueNameLocalAddress, |
| 810 | info.local_candidate.address().ToString()); |
| 811 | report->AddValue(StatsReport::kStatsValueNameRemoteAddress, |
| 812 | info.remote_candidate.address().ToString()); |
| 813 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt); |
| 814 | report->AddValue(StatsReport::kStatsValueNameTransportType, |
| 815 | info.local_candidate.protocol()); |
| 816 | report->AddValue(StatsReport::kStatsValueNameLocalCandidateType, |
| 817 | info.local_candidate.type()); |
| 818 | report->AddValue(StatsReport::kStatsValueNameRemoteCandidateType, |
| 819 | info.remote_candidate.type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | void StatsCollector::ExtractVoiceInfo() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 827 | ASSERT(session_->signaling_thread()->IsCurrent()); |
| 828 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 829 | if (!session_->voice_channel()) { |
| 830 | return; |
| 831 | } |
| 832 | cricket::VoiceMediaInfo voice_info; |
| 833 | if (!session_->voice_channel()->GetStats(&voice_info)) { |
| 834 | LOG(LS_ERROR) << "Failed to get voice channel stats."; |
| 835 | return; |
| 836 | } |
| 837 | std::string transport_id; |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 838 | if (!GetTransportIdFromProxy(proxy_to_transport_, |
| 839 | session_->voice_channel()->content_name(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 840 | &transport_id)) { |
| 841 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 842 | << session_->voice_channel()->content_name(); |
| 843 | return; |
| 844 | } |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 845 | ExtractStatsFromList(voice_info.receivers, transport_id, this, kReceiving); |
| 846 | ExtractStatsFromList(voice_info.senders, transport_id, this, kSending); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 847 | |
| 848 | UpdateStatsFromExistingLocalAudioTracks(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 849 | } |
| 850 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 851 | void StatsCollector::ExtractVideoInfo( |
| 852 | PeerConnectionInterface::StatsOutputLevel level) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 853 | ASSERT(session_->signaling_thread()->IsCurrent()); |
| 854 | |
| 855 | if (!session_->video_channel()) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 856 | return; |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 857 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 858 | cricket::StatsOptions options; |
| 859 | options.include_received_propagation_stats = |
| 860 | (level >= PeerConnectionInterface::kStatsOutputLevelDebug) ? |
| 861 | true : false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 862 | cricket::VideoMediaInfo video_info; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 863 | if (!session_->video_channel()->GetStats(options, &video_info)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 864 | LOG(LS_ERROR) << "Failed to get video channel stats."; |
| 865 | return; |
| 866 | } |
| 867 | std::string transport_id; |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 868 | if (!GetTransportIdFromProxy(proxy_to_transport_, |
| 869 | session_->video_channel()->content_name(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 870 | &transport_id)) { |
| 871 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 872 | << session_->video_channel()->content_name(); |
| 873 | return; |
| 874 | } |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 875 | ExtractStatsFromList(video_info.receivers, transport_id, this, kReceiving); |
| 876 | ExtractStatsFromList(video_info.senders, transport_id, this, kSending); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 877 | if (video_info.bw_estimations.size() != 1) { |
| 878 | LOG(LS_ERROR) << "BWEs count: " << video_info.bw_estimations.size(); |
| 879 | } else { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 880 | StatsReport* report = |
| 881 | reports_.FindOrAddNew(StatsReport::kStatsReportVideoBweId); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | ExtractStats( |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 883 | video_info.bw_estimations[0], stats_gathering_started_, level, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 887 | void StatsCollector::ExtractDataInfo() { |
| 888 | ASSERT(session_->signaling_thread()->IsCurrent()); |
| 889 | |
| 890 | for (const auto& dc : |
| 891 | session_->mediastream_signaling()->sctp_data_channels()) { |
| 892 | StatsReport* report = reports_.ReplaceOrAddNew( |
| 893 | StatsId(StatsReport::kStatsReportTypeDataChannel, dc->label())); |
| 894 | report->type = StatsReport::kStatsReportTypeDataChannel; |
| 895 | report->AddValue(StatsReport::kStatsValueNameLabel, dc->label()); |
| 896 | report->AddValue(StatsReport::kStatsValueNameDataChannelId, dc->id()); |
| 897 | report->AddValue(StatsReport::kStatsValueNameProtocol, dc->protocol()); |
| 898 | report->AddValue(StatsReport::kStatsValueNameState, |
| 899 | DataChannelInterface::DataStateString(dc->state())); |
| 900 | } |
| 901 | } |
| 902 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 903 | StatsReport* StatsCollector::GetReport(const std::string& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 904 | const std::string& id, |
| 905 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 906 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 907 | ASSERT(type == StatsReport::kStatsReportTypeSsrc || |
| 908 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 909 | return reports_.Find(StatsId(type, id, direction)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | StatsReport* StatsCollector::GetOrCreateReport(const std::string& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 913 | const std::string& id, |
| 914 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 915 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 916 | ASSERT(type == StatsReport::kStatsReportTypeSsrc || |
| 917 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
| 918 | StatsReport* report = GetReport(type, id, direction); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 919 | if (report == NULL) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 920 | std::string statsid = StatsId(type, id, direction); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 921 | report = reports_.FindOrAddNew(statsid); |
tommi@webrtc.org | 43e54e3 | 2015-01-19 17:34:23 +0000 | [diff] [blame^] | 922 | ASSERT(report->id == statsid); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 923 | report->type = type; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 924 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 925 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 926 | return report; |
| 927 | } |
| 928 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 929 | void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 930 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 931 | // Loop through the existing local audio tracks. |
| 932 | for (LocalAudioTrackVector::const_iterator it = local_audio_tracks_.begin(); |
| 933 | it != local_audio_tracks_.end(); ++it) { |
| 934 | AudioTrackInterface* track = it->first; |
| 935 | uint32 ssrc = it->second; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 936 | std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 937 | StatsReport* report = GetReport(StatsReport::kStatsReportTypeSsrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 938 | ssrc_id, |
| 939 | kSending); |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 940 | if (report == NULL) { |
| 941 | // This can happen if a local audio track is added to a stream on the |
| 942 | // fly and the report has not been set up yet. Do nothing in this case. |
| 943 | LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; |
| 944 | continue; |
| 945 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 946 | |
| 947 | // The same ssrc can be used by both local and remote audio tracks. |
| 948 | std::string track_id; |
| 949 | if (!ExtractValueFromReport(*report, |
| 950 | StatsReport::kStatsValueNameTrackId, |
| 951 | &track_id) || |
| 952 | track_id != track->id()) { |
| 953 | continue; |
| 954 | } |
| 955 | |
| 956 | UpdateReportFromAudioTrack(track, report); |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, |
| 961 | StatsReport* report) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 962 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 963 | ASSERT(track != NULL); |
| 964 | if (report == NULL) |
| 965 | return; |
| 966 | |
| 967 | int signal_level = 0; |
| 968 | if (track->GetSignalLevel(&signal_level)) { |
| 969 | report->ReplaceValue(StatsReport::kStatsValueNameAudioInputLevel, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 970 | rtc::ToString<int>(signal_level)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 971 | } |
| 972 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 973 | rtc::scoped_refptr<AudioProcessorInterface> audio_processor( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 974 | track->GetAudioProcessor()); |
| 975 | if (audio_processor.get() == NULL) |
| 976 | return; |
| 977 | |
| 978 | AudioProcessorInterface::AudioProcessorStats stats; |
| 979 | audio_processor->GetStats(&stats); |
| 980 | report->ReplaceValue(StatsReport::kStatsValueNameTypingNoiseState, |
| 981 | stats.typing_noise_detected ? "true" : "false"); |
| 982 | report->ReplaceValue(StatsReport::kStatsValueNameEchoReturnLoss, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 983 | rtc::ToString<int>(stats.echo_return_loss)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 984 | report->ReplaceValue( |
| 985 | StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 986 | rtc::ToString<int>(stats.echo_return_loss_enhancement)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 987 | report->ReplaceValue(StatsReport::kStatsValueNameEchoDelayMedian, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 988 | rtc::ToString<int>(stats.echo_delay_median_ms)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 989 | report->ReplaceValue(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 990 | rtc::ToString<float>(stats.aec_quality_min)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 991 | report->ReplaceValue(StatsReport::kStatsValueNameEchoDelayStdDev, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 992 | rtc::ToString<int>(stats.echo_delay_std_ms)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 993 | } |
| 994 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 995 | bool StatsCollector::GetTrackIdBySsrc(uint32 ssrc, std::string* track_id, |
| 996 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 997 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 998 | if (direction == kSending) { |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 999 | if (!session_->GetLocalTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1000 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 1001 | << " is not associated with a sending track"; |
| 1002 | return false; |
| 1003 | } |
| 1004 | } else { |
| 1005 | ASSERT(direction == kReceiving); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1006 | if (!session_->GetRemoteTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1007 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 1008 | << " is not associated with a receiving track"; |
| 1009 | return false; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | return true; |
| 1014 | } |
| 1015 | |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 1016 | void StatsCollector::ClearUpdateStatsCacheForTest() { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1017 | stats_gathering_started_ = 0; |
| 1018 | } |
| 1019 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1020 | } // namespace webrtc |