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 | 5b76fd7 | 2015-01-19 16:49:33 +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) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 287 | report->type = StatsReport::kStatsReportTypeBwe; |
| 288 | |
| 289 | // Clear out stats from previous GatherStats calls if any. |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 290 | if (report->timestamp() != stats_gathering_started) { |
| 291 | report->ResetValues(); |
| 292 | report->set_timestamp(stats_gathering_started); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | report->AddValue(StatsReport::kStatsValueNameAvailableSendBandwidth, |
| 296 | info.available_send_bandwidth); |
| 297 | report->AddValue(StatsReport::kStatsValueNameAvailableReceiveBandwidth, |
| 298 | info.available_recv_bandwidth); |
| 299 | report->AddValue(StatsReport::kStatsValueNameTargetEncBitrate, |
| 300 | info.target_enc_bitrate); |
| 301 | report->AddValue(StatsReport::kStatsValueNameActualEncBitrate, |
| 302 | info.actual_enc_bitrate); |
| 303 | report->AddValue(StatsReport::kStatsValueNameRetransmitBitrate, |
| 304 | info.retransmit_bitrate); |
| 305 | report->AddValue(StatsReport::kStatsValueNameTransmitBitrate, |
| 306 | info.transmit_bitrate); |
| 307 | report->AddValue(StatsReport::kStatsValueNameBucketDelay, |
| 308 | info.bucket_delay); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 309 | if (level >= PeerConnectionInterface::kStatsOutputLevelDebug) { |
| 310 | report->AddValue( |
| 311 | StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaSumDebug, |
| 312 | info.total_received_propagation_delta_ms); |
| 313 | if (info.recent_received_propagation_delta_ms.size() > 0) { |
| 314 | report->AddValue( |
| 315 | StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaDebug, |
| 316 | info.recent_received_propagation_delta_ms); |
| 317 | report->AddValue( |
| 318 | StatsReport::kStatsValueNameRecvPacketGroupArrivalTimeDebug, |
| 319 | info.recent_received_packet_group_arrival_time_ms); |
| 320 | } |
| 321 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 322 | } |
| 323 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 324 | void ExtractRemoteStats(const cricket::MediaSenderInfo& info, |
| 325 | StatsReport* report) { |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 326 | report->set_timestamp(info.remote_stats[0].timestamp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 327 | // TODO(hta): Extract some stats here. |
| 328 | } |
| 329 | |
| 330 | void ExtractRemoteStats(const cricket::MediaReceiverInfo& info, |
| 331 | StatsReport* report) { |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 332 | report->set_timestamp(info.remote_stats[0].timestamp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 333 | // TODO(hta): Extract some stats here. |
| 334 | } |
| 335 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 336 | // Template to extract stats from a data vector. |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 337 | // In order to use the template, the functions that are called from it, |
| 338 | // ExtractStats and ExtractRemoteStats, must be defined and overloaded |
| 339 | // for each type. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 340 | template<typename T> |
| 341 | void ExtractStatsFromList(const std::vector<T>& data, |
| 342 | const std::string& transport_id, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 343 | StatsCollector* collector, |
| 344 | StatsCollector::TrackDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 345 | typename std::vector<T>::const_iterator it = data.begin(); |
| 346 | for (; it != data.end(); ++it) { |
| 347 | std::string id; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 348 | uint32 ssrc = it->ssrc(); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 349 | // Each track can have stats for both local and remote objects. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 350 | // TODO(hta): Handle the case of multiple SSRCs per object. |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 351 | StatsReport* report = collector->PrepareLocalReport(ssrc, transport_id, |
| 352 | direction); |
| 353 | if (report) |
| 354 | ExtractStats(*it, report); |
| 355 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 356 | if (it->remote_stats.size() > 0) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 357 | report = collector->PrepareRemoteReport(ssrc, transport_id, |
| 358 | direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 359 | if (!report) { |
| 360 | continue; |
| 361 | } |
| 362 | ExtractRemoteStats(*it, report); |
| 363 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 364 | } |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 365 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 366 | |
| 367 | } // namespace |
| 368 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 369 | const char* IceCandidateTypeToStatsType(const std::string& candidate_type) { |
| 370 | if (candidate_type == cricket::LOCAL_PORT_TYPE) { |
| 371 | return STATSREPORT_LOCAL_PORT_TYPE; |
| 372 | } |
| 373 | if (candidate_type == cricket::STUN_PORT_TYPE) { |
| 374 | return STATSREPORT_STUN_PORT_TYPE; |
| 375 | } |
| 376 | if (candidate_type == cricket::PRFLX_PORT_TYPE) { |
| 377 | return STATSREPORT_PRFLX_PORT_TYPE; |
| 378 | } |
| 379 | if (candidate_type == cricket::RELAY_PORT_TYPE) { |
| 380 | return STATSREPORT_RELAY_PORT_TYPE; |
| 381 | } |
| 382 | ASSERT(false); |
| 383 | return "unknown"; |
| 384 | } |
| 385 | |
| 386 | const char* AdapterTypeToStatsType(rtc::AdapterType type) { |
| 387 | switch (type) { |
| 388 | case rtc::ADAPTER_TYPE_UNKNOWN: |
| 389 | return "unknown"; |
| 390 | case rtc::ADAPTER_TYPE_ETHERNET: |
| 391 | return STATSREPORT_ADAPTER_TYPE_ETHERNET; |
| 392 | case rtc::ADAPTER_TYPE_WIFI: |
| 393 | return STATSREPORT_ADAPTER_TYPE_WIFI; |
| 394 | case rtc::ADAPTER_TYPE_CELLULAR: |
| 395 | return STATSREPORT_ADAPTER_TYPE_WWAN; |
| 396 | case rtc::ADAPTER_TYPE_VPN: |
| 397 | return STATSREPORT_ADAPTER_TYPE_VPN; |
| 398 | default: |
| 399 | ASSERT(false); |
| 400 | return ""; |
| 401 | } |
| 402 | } |
| 403 | |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 404 | StatsCollector::StatsCollector(WebRtcSession* session) |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 405 | : session_(session), |
| 406 | stats_gathering_started_(0) { |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 407 | ASSERT(session_); |
| 408 | } |
| 409 | |
| 410 | StatsCollector::~StatsCollector() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 411 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 415 | // to GetStats. |
| 416 | void StatsCollector::AddStream(MediaStreamInterface* stream) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 417 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 418 | ASSERT(stream != NULL); |
| 419 | |
| 420 | CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), |
| 421 | &reports_); |
| 422 | CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), |
| 423 | &reports_); |
| 424 | } |
| 425 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 426 | void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, |
| 427 | uint32 ssrc) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 428 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 429 | ASSERT(audio_track != NULL); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 430 | for (LocalAudioTrackVector::iterator it = local_audio_tracks_.begin(); |
| 431 | it != local_audio_tracks_.end(); ++it) { |
| 432 | ASSERT(it->first != audio_track || it->second != ssrc); |
| 433 | } |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 434 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 435 | local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc)); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 436 | |
| 437 | // Create the kStatsReportTypeTrack report for the new track if there is no |
| 438 | // report yet. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 439 | StatsReport* found = reports_.Find( |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 440 | StatsId(StatsReport::kStatsReportTypeTrack, audio_track->id())); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 441 | if (!found) |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 442 | AddTrackReport(&reports_, audio_track->id()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, |
| 446 | uint32 ssrc) { |
| 447 | ASSERT(audio_track != NULL); |
| 448 | for (LocalAudioTrackVector::iterator it = local_audio_tracks_.begin(); |
| 449 | it != local_audio_tracks_.end(); ++it) { |
| 450 | if (it->first == audio_track && it->second == ssrc) { |
| 451 | local_audio_tracks_.erase(it); |
| 452 | return; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | ASSERT(false); |
| 457 | } |
| 458 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 459 | void StatsCollector::GetStats(MediaStreamTrackInterface* track, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 460 | StatsReports* reports) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 461 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 462 | ASSERT(reports != NULL); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 463 | ASSERT(reports->empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 464 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | if (!track) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 466 | StatsSet::const_iterator it; |
| 467 | for (it = reports_.begin(); it != reports_.end(); ++it) |
| 468 | reports->push_back(&(*it)); |
| 469 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 470 | } |
| 471 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 472 | StatsReport* report = |
| 473 | reports_.Find(StatsId(StatsReport::kStatsReportTypeSession, |
| 474 | session_->id())); |
| 475 | if (report) |
| 476 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 477 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 478 | report = reports_.Find( |
| 479 | StatsId(StatsReport::kStatsReportTypeTrack, track->id())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 480 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 481 | if (!report) |
| 482 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 483 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 484 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 485 | |
| 486 | std::string track_id; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 487 | for (StatsSet::const_iterator it = reports_.begin(); it != reports_.end(); |
| 488 | ++it) { |
| 489 | if (it->type != StatsReport::kStatsReportTypeSsrc) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | continue; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 491 | |
| 492 | if (ExtractValueFromReport(*it, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 493 | StatsReport::kStatsValueNameTrackId, |
| 494 | &track_id)) { |
| 495 | if (track_id == track->id()) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 496 | reports->push_back(&(*it)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 500 | } |
| 501 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 502 | void |
| 503 | StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 504 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 505 | double time_now = GetTimeNow(); |
| 506 | // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of |
| 507 | // ms apart will be ignored. |
| 508 | const double kMinGatherStatsPeriod = 50; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 509 | if (stats_gathering_started_ != 0 && |
| 510 | stats_gathering_started_ + kMinGatherStatsPeriod > time_now) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 511 | return; |
| 512 | } |
| 513 | stats_gathering_started_ = time_now; |
| 514 | |
| 515 | if (session_) { |
| 516 | ExtractSessionInfo(); |
| 517 | ExtractVoiceInfo(); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 518 | ExtractVideoInfo(level); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 519 | ExtractDataInfo(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 523 | StatsReport* StatsCollector::PrepareLocalReport( |
| 524 | uint32 ssrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 525 | const std::string& transport_id, |
| 526 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 527 | ASSERT(session_->signaling_thread()->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 528 | const std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 529 | StatsReport* report = reports_.Find( |
| 530 | StatsId(StatsReport::kStatsReportTypeSsrc, ssrc_id, direction)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 531 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 532 | // 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] | 533 | std::string track_id; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 534 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 535 | if (!report) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 536 | // The ssrc is not used by any track or existing report, return NULL |
| 537 | // 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] | 538 | return NULL; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | // The ssrc is not used by any existing track. Keeps the old track id |
| 542 | // since we want to report the stats for inactive ssrc. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 543 | ExtractValueFromReport(*report, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 544 | StatsReport::kStatsValueNameTrackId, |
| 545 | &track_id); |
| 546 | } |
| 547 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 548 | report = GetOrCreateReport( |
| 549 | StatsReport::kStatsReportTypeSsrc, ssrc_id, direction); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 550 | |
| 551 | // Clear out stats from previous GatherStats calls if any. |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 552 | // This is required since the report will be returned for the new values. |
| 553 | // Having the old values in the report will lead to multiple values with |
| 554 | // the same name. |
| 555 | // TODO(xians): Consider changing StatsReport to use map instead of vector. |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 556 | report->ResetValues(); |
| 557 | report->set_timestamp(stats_gathering_started_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 558 | |
| 559 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 560 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 561 | // Add the mapping of SSRC to transport. |
| 562 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 563 | transport_id); |
| 564 | return report; |
| 565 | } |
| 566 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 567 | StatsReport* StatsCollector::PrepareRemoteReport( |
| 568 | uint32 ssrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 569 | const std::string& transport_id, |
| 570 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 571 | ASSERT(session_->signaling_thread()->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 572 | const std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 573 | StatsReport* report = reports_.Find( |
| 574 | StatsId(StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id, direction)); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 575 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 576 | // 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] | 577 | std::string track_id; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 578 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 579 | if (!report) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 580 | // The ssrc is not used by any track or existing report, return NULL |
| 581 | // 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] | 582 | return NULL; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | // The ssrc is not used by any existing track. Keeps the old track id |
| 586 | // since we want to report the stats for inactive ssrc. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 587 | ExtractValueFromReport(*report, |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 588 | StatsReport::kStatsValueNameTrackId, |
| 589 | &track_id); |
| 590 | } |
| 591 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 592 | report = GetOrCreateReport( |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 593 | StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id, direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 594 | |
| 595 | // Clear out stats from previous GatherStats calls if any. |
| 596 | // The timestamp will be added later. Zero it for debugging. |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 597 | report->ResetValues(); |
| 598 | report->set_timestamp(0); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 599 | |
| 600 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 601 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 602 | // Add the mapping of SSRC to transport. |
| 603 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 604 | transport_id); |
| 605 | return report; |
| 606 | } |
| 607 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 608 | std::string StatsCollector::AddOneCertificateReport( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 609 | const rtc::SSLCertificate* cert, const std::string& issuer_id) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 610 | // TODO(bemasc): Move this computation to a helper class that caches these |
| 611 | // values to reduce CPU use in GetStats. This will require adding a fast |
| 612 | // SSLCertificate::Equals() method to detect certificate changes. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 613 | |
| 614 | std::string digest_algorithm; |
| 615 | if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) |
| 616 | return std::string(); |
| 617 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 618 | rtc::scoped_ptr<rtc::SSLFingerprint> ssl_fingerprint( |
| 619 | rtc::SSLFingerprint::Create(digest_algorithm, cert)); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 620 | |
| 621 | // SSLFingerprint::Create can fail if the algorithm returned by |
| 622 | // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the |
| 623 | // implementation of SSLCertificate::ComputeDigest. This currently happens |
| 624 | // with MD5- and SHA-224-signed certificates when linked to libNSS. |
| 625 | if (!ssl_fingerprint) |
| 626 | return std::string(); |
| 627 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 628 | std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); |
| 629 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 630 | rtc::Buffer der_buffer; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 631 | cert->ToDER(&der_buffer); |
| 632 | std::string der_base64; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 633 | rtc::Base64::EncodeFromArray( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 634 | der_buffer.data(), der_buffer.length(), &der_base64); |
| 635 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 636 | StatsReport* report = reports_.ReplaceOrAddNew( |
| 637 | StatsId(StatsReport::kStatsReportTypeCertificate, fingerprint)); |
| 638 | report->type = StatsReport::kStatsReportTypeCertificate; |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 639 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 640 | report->AddValue(StatsReport::kStatsValueNameFingerprint, fingerprint); |
| 641 | report->AddValue(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 642 | digest_algorithm); |
| 643 | report->AddValue(StatsReport::kStatsValueNameDer, der_base64); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 644 | if (!issuer_id.empty()) |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 645 | report->AddValue(StatsReport::kStatsValueNameIssuerId, issuer_id); |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 646 | return report->id().ToString(); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | std::string StatsCollector::AddCertificateReports( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 650 | const rtc::SSLCertificate* cert) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 651 | // Produces a chain of StatsReports representing this certificate and the rest |
| 652 | // of its chain, and adds those reports to |reports_|. The return value is |
| 653 | // the id of the leaf report. The provided cert must be non-null, so at least |
| 654 | // one report will always be provided and the returned string will never be |
| 655 | // empty. |
| 656 | ASSERT(cert != NULL); |
| 657 | |
| 658 | std::string issuer_id; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 659 | rtc::scoped_ptr<rtc::SSLCertChain> chain; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 660 | if (cert->GetChain(chain.accept())) { |
| 661 | // This loop runs in reverse, i.e. from root to leaf, so that each |
| 662 | // certificate's issuer's report ID is known before the child certificate's |
| 663 | // report is generated. The root certificate does not have an issuer ID |
| 664 | // value. |
| 665 | for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 666 | const rtc::SSLCertificate& cert_i = chain->Get(i); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 667 | issuer_id = AddOneCertificateReport(&cert_i, issuer_id); |
| 668 | } |
| 669 | } |
| 670 | // Add the leaf certificate. |
| 671 | return AddOneCertificateReport(cert, issuer_id); |
| 672 | } |
| 673 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 674 | std::string StatsCollector::AddCandidateReport( |
| 675 | const cricket::Candidate& candidate, |
| 676 | const std::string& report_type) { |
| 677 | std::ostringstream ost; |
| 678 | ost << "Cand-" << candidate.id(); |
| 679 | StatsReport* report = reports_.Find(ost.str()); |
| 680 | if (!report) { |
| 681 | report = reports_.InsertNew(ost.str()); |
| 682 | DCHECK(StatsReport::kStatsReportTypeIceLocalCandidate == report_type || |
| 683 | StatsReport::kStatsReportTypeIceRemoteCandidate == report_type); |
| 684 | report->type = report_type; |
| 685 | if (report_type == StatsReport::kStatsReportTypeIceLocalCandidate) { |
| 686 | report->AddValue(StatsReport::kStatsValueNameCandidateNetworkType, |
| 687 | AdapterTypeToStatsType(candidate.network_type())); |
| 688 | } |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 689 | report->set_timestamp(stats_gathering_started_); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 690 | report->AddValue(StatsReport::kStatsValueNameCandidateIPAddress, |
| 691 | candidate.address().ipaddr().ToString()); |
| 692 | report->AddValue(StatsReport::kStatsValueNameCandidatePortNumber, |
| 693 | candidate.address().PortAsString()); |
| 694 | report->AddValue(StatsReport::kStatsValueNameCandidatePriority, |
| 695 | candidate.priority()); |
| 696 | report->AddValue(StatsReport::kStatsValueNameCandidateType, |
| 697 | IceCandidateTypeToStatsType(candidate.type())); |
| 698 | report->AddValue(StatsReport::kStatsValueNameCandidateTransportType, |
| 699 | candidate.protocol()); |
| 700 | } |
| 701 | |
| 702 | return ost.str(); |
| 703 | } |
| 704 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 705 | void StatsCollector::ExtractSessionInfo() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 706 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 707 | // Extract information from the base session. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 708 | StatsReport* report = reports_.ReplaceOrAddNew( |
| 709 | StatsId(StatsReport::kStatsReportTypeSession, session_->id())); |
| 710 | report->type = StatsReport::kStatsReportTypeSession; |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 711 | report->set_timestamp(stats_gathering_started_); |
| 712 | report->ResetValues(); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 713 | report->AddBoolean(StatsReport::kStatsValueNameInitiator, |
| 714 | session_->initiator()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 715 | |
| 716 | cricket::SessionStats stats; |
| 717 | if (session_->GetStats(&stats)) { |
| 718 | // Store the proxy map away for use in SSRC reporting. |
| 719 | proxy_to_transport_ = stats.proxy_to_transport; |
| 720 | |
| 721 | for (cricket::TransportStatsMap::iterator transport_iter |
| 722 | = stats.transport_stats.begin(); |
| 723 | transport_iter != stats.transport_stats.end(); ++transport_iter) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 724 | // Attempt to get a copy of the certificates from the transport and |
| 725 | // expose them in stats reports. All channels in a transport share the |
| 726 | // same local and remote certificates. |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 727 | // |
| 728 | // Note that Transport::GetIdentity and Transport::GetRemoteCertificate |
| 729 | // invoke method calls on the worker thread and block this thread, but |
| 730 | // messages are still processed on this thread, which may blow way the |
| 731 | // existing transports. So we cannot reuse |transport| after these calls. |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 732 | std::string local_cert_report_id, remote_cert_report_id; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 733 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 734 | cricket::Transport* transport = |
| 735 | session_->GetTransport(transport_iter->second.content_name); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 736 | rtc::scoped_ptr<rtc::SSLIdentity> identity; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 737 | if (transport && transport->GetIdentity(identity.accept())) { |
| 738 | local_cert_report_id = |
| 739 | AddCertificateReports(&(identity->certificate())); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 740 | } |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 741 | |
| 742 | transport = session_->GetTransport(transport_iter->second.content_name); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 743 | rtc::scoped_ptr<rtc::SSLCertificate> cert; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 744 | if (transport && transport->GetRemoteCertificate(cert.accept())) { |
| 745 | remote_cert_report_id = AddCertificateReports(cert.get()); |
| 746 | } |
| 747 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 748 | for (cricket::TransportChannelStatsList::iterator channel_iter |
| 749 | = transport_iter->second.channel_stats.begin(); |
| 750 | channel_iter != transport_iter->second.channel_stats.end(); |
| 751 | ++channel_iter) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 752 | std::ostringstream ostc; |
| 753 | ostc << "Channel-" << transport_iter->second.content_name |
| 754 | << "-" << channel_iter->component; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 755 | StatsReport* channel_report = reports_.ReplaceOrAddNew(ostc.str()); |
| 756 | channel_report->type = StatsReport::kStatsReportTypeComponent; |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 757 | channel_report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 758 | channel_report->AddValue(StatsReport::kStatsValueNameComponent, |
| 759 | channel_iter->component); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 760 | if (!local_cert_report_id.empty()) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 761 | channel_report->AddValue( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 762 | StatsReport::kStatsValueNameLocalCertificateId, |
| 763 | local_cert_report_id); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 764 | } |
| 765 | if (!remote_cert_report_id.empty()) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 766 | channel_report->AddValue( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 767 | StatsReport::kStatsValueNameRemoteCertificateId, |
| 768 | remote_cert_report_id); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 769 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 770 | for (size_t i = 0; |
| 771 | i < channel_iter->connection_infos.size(); |
| 772 | ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 773 | std::ostringstream ost; |
| 774 | ost << "Conn-" << transport_iter->first << "-" |
| 775 | << channel_iter->component << "-" << i; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 776 | StatsReport* report = reports_.ReplaceOrAddNew(ost.str()); |
| 777 | report->type = StatsReport::kStatsReportTypeCandidatePair; |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 778 | report->set_timestamp(stats_gathering_started_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 779 | // Link from connection to its containing channel. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 780 | report->AddValue(StatsReport::kStatsValueNameChannelId, |
tommi@webrtc.org | 5b76fd7 | 2015-01-19 16:49:33 +0000 | [diff] [blame^] | 781 | channel_report->id().ToString()); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 782 | |
| 783 | const cricket::ConnectionInfo& info = |
| 784 | channel_iter->connection_infos[i]; |
| 785 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 786 | info.sent_total_bytes); |
guoweis@webrtc.org | 930e004 | 2014-11-17 19:42:14 +0000 | [diff] [blame] | 787 | report->AddValue(StatsReport::kStatsValueNameSendPacketsDiscarded, |
| 788 | info.sent_discarded_packets); |
| 789 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 790 | info.sent_total_packets); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 791 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 792 | info.recv_total_bytes); |
| 793 | report->AddBoolean(StatsReport::kStatsValueNameWritable, |
| 794 | info.writable); |
| 795 | report->AddBoolean(StatsReport::kStatsValueNameReadable, |
| 796 | info.readable); |
| 797 | report->AddBoolean(StatsReport::kStatsValueNameActiveConnection, |
| 798 | info.best_connection); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 799 | report->AddValue(StatsReport::kStatsValueNameLocalCandidateId, |
| 800 | AddCandidateReport( |
| 801 | info.local_candidate, |
| 802 | StatsReport::kStatsReportTypeIceLocalCandidate)); |
| 803 | report->AddValue( |
| 804 | StatsReport::kStatsValueNameRemoteCandidateId, |
| 805 | AddCandidateReport( |
| 806 | info.remote_candidate, |
| 807 | StatsReport::kStatsReportTypeIceRemoteCandidate)); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 808 | report->AddValue(StatsReport::kStatsValueNameLocalAddress, |
| 809 | info.local_candidate.address().ToString()); |
| 810 | report->AddValue(StatsReport::kStatsValueNameRemoteAddress, |
| 811 | info.remote_candidate.address().ToString()); |
| 812 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt); |
| 813 | report->AddValue(StatsReport::kStatsValueNameTransportType, |
| 814 | info.local_candidate.protocol()); |
| 815 | report->AddValue(StatsReport::kStatsValueNameLocalCandidateType, |
| 816 | info.local_candidate.type()); |
| 817 | report->AddValue(StatsReport::kStatsValueNameRemoteCandidateType, |
| 818 | info.remote_candidate.type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | void StatsCollector::ExtractVoiceInfo() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 826 | ASSERT(session_->signaling_thread()->IsCurrent()); |
| 827 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | if (!session_->voice_channel()) { |
| 829 | return; |
| 830 | } |
| 831 | cricket::VoiceMediaInfo voice_info; |
| 832 | if (!session_->voice_channel()->GetStats(&voice_info)) { |
| 833 | LOG(LS_ERROR) << "Failed to get voice channel stats."; |
| 834 | return; |
| 835 | } |
| 836 | std::string transport_id; |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 837 | if (!GetTransportIdFromProxy(proxy_to_transport_, |
| 838 | session_->voice_channel()->content_name(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 839 | &transport_id)) { |
| 840 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 841 | << session_->voice_channel()->content_name(); |
| 842 | return; |
| 843 | } |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 844 | ExtractStatsFromList(voice_info.receivers, transport_id, this, kReceiving); |
| 845 | ExtractStatsFromList(voice_info.senders, transport_id, this, kSending); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 846 | |
| 847 | UpdateStatsFromExistingLocalAudioTracks(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 848 | } |
| 849 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 850 | void StatsCollector::ExtractVideoInfo( |
| 851 | PeerConnectionInterface::StatsOutputLevel level) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 852 | ASSERT(session_->signaling_thread()->IsCurrent()); |
| 853 | |
| 854 | if (!session_->video_channel()) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 855 | return; |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 856 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 857 | cricket::StatsOptions options; |
| 858 | options.include_received_propagation_stats = |
| 859 | (level >= PeerConnectionInterface::kStatsOutputLevelDebug) ? |
| 860 | true : false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 861 | cricket::VideoMediaInfo video_info; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 862 | if (!session_->video_channel()->GetStats(options, &video_info)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 863 | LOG(LS_ERROR) << "Failed to get video channel stats."; |
| 864 | return; |
| 865 | } |
| 866 | std::string transport_id; |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 867 | if (!GetTransportIdFromProxy(proxy_to_transport_, |
| 868 | session_->video_channel()->content_name(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 869 | &transport_id)) { |
| 870 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 871 | << session_->video_channel()->content_name(); |
| 872 | return; |
| 873 | } |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 874 | ExtractStatsFromList(video_info.receivers, transport_id, this, kReceiving); |
| 875 | ExtractStatsFromList(video_info.senders, transport_id, this, kSending); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 876 | if (video_info.bw_estimations.size() != 1) { |
| 877 | LOG(LS_ERROR) << "BWEs count: " << video_info.bw_estimations.size(); |
| 878 | } else { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 879 | StatsReport* report = |
| 880 | reports_.FindOrAddNew(StatsReport::kStatsReportVideoBweId); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 881 | ExtractStats( |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 882 | video_info.bw_estimations[0], stats_gathering_started_, level, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 886 | void StatsCollector::ExtractDataInfo() { |
| 887 | ASSERT(session_->signaling_thread()->IsCurrent()); |
| 888 | |
| 889 | for (const auto& dc : |
| 890 | session_->mediastream_signaling()->sctp_data_channels()) { |
| 891 | StatsReport* report = reports_.ReplaceOrAddNew( |
| 892 | StatsId(StatsReport::kStatsReportTypeDataChannel, dc->label())); |
| 893 | report->type = StatsReport::kStatsReportTypeDataChannel; |
| 894 | report->AddValue(StatsReport::kStatsValueNameLabel, dc->label()); |
| 895 | report->AddValue(StatsReport::kStatsValueNameDataChannelId, dc->id()); |
| 896 | report->AddValue(StatsReport::kStatsValueNameProtocol, dc->protocol()); |
| 897 | report->AddValue(StatsReport::kStatsValueNameState, |
| 898 | DataChannelInterface::DataStateString(dc->state())); |
| 899 | } |
| 900 | } |
| 901 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 902 | StatsReport* StatsCollector::GetReport(const std::string& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 903 | const std::string& id, |
| 904 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 905 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 906 | ASSERT(type == StatsReport::kStatsReportTypeSsrc || |
| 907 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 908 | return reports_.Find(StatsId(type, id, direction)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | StatsReport* StatsCollector::GetOrCreateReport(const std::string& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 912 | const std::string& id, |
| 913 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 914 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 915 | ASSERT(type == StatsReport::kStatsReportTypeSsrc || |
| 916 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
| 917 | StatsReport* report = GetReport(type, id, direction); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 918 | if (report == NULL) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 919 | std::string statsid = StatsId(type, id, direction); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 920 | report = reports_.FindOrAddNew(statsid); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 921 | report->type = type; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 922 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 923 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 924 | return report; |
| 925 | } |
| 926 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 927 | void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 928 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 929 | // Loop through the existing local audio tracks. |
| 930 | for (LocalAudioTrackVector::const_iterator it = local_audio_tracks_.begin(); |
| 931 | it != local_audio_tracks_.end(); ++it) { |
| 932 | AudioTrackInterface* track = it->first; |
| 933 | uint32 ssrc = it->second; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 934 | std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 935 | StatsReport* report = GetReport(StatsReport::kStatsReportTypeSsrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 936 | ssrc_id, |
| 937 | kSending); |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 938 | if (report == NULL) { |
| 939 | // This can happen if a local audio track is added to a stream on the |
| 940 | // fly and the report has not been set up yet. Do nothing in this case. |
| 941 | LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; |
| 942 | continue; |
| 943 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 944 | |
| 945 | // The same ssrc can be used by both local and remote audio tracks. |
| 946 | std::string track_id; |
| 947 | if (!ExtractValueFromReport(*report, |
| 948 | StatsReport::kStatsValueNameTrackId, |
| 949 | &track_id) || |
| 950 | track_id != track->id()) { |
| 951 | continue; |
| 952 | } |
| 953 | |
| 954 | UpdateReportFromAudioTrack(track, report); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, |
| 959 | StatsReport* report) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 960 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 961 | ASSERT(track != NULL); |
| 962 | if (report == NULL) |
| 963 | return; |
| 964 | |
| 965 | int signal_level = 0; |
| 966 | if (track->GetSignalLevel(&signal_level)) { |
| 967 | report->ReplaceValue(StatsReport::kStatsValueNameAudioInputLevel, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 968 | rtc::ToString<int>(signal_level)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 969 | } |
| 970 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 971 | rtc::scoped_refptr<AudioProcessorInterface> audio_processor( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 972 | track->GetAudioProcessor()); |
| 973 | if (audio_processor.get() == NULL) |
| 974 | return; |
| 975 | |
| 976 | AudioProcessorInterface::AudioProcessorStats stats; |
| 977 | audio_processor->GetStats(&stats); |
| 978 | report->ReplaceValue(StatsReport::kStatsValueNameTypingNoiseState, |
| 979 | stats.typing_noise_detected ? "true" : "false"); |
| 980 | report->ReplaceValue(StatsReport::kStatsValueNameEchoReturnLoss, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 981 | rtc::ToString<int>(stats.echo_return_loss)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 982 | report->ReplaceValue( |
| 983 | StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 984 | rtc::ToString<int>(stats.echo_return_loss_enhancement)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 985 | report->ReplaceValue(StatsReport::kStatsValueNameEchoDelayMedian, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 986 | rtc::ToString<int>(stats.echo_delay_median_ms)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 987 | report->ReplaceValue(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 988 | rtc::ToString<float>(stats.aec_quality_min)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 989 | report->ReplaceValue(StatsReport::kStatsValueNameEchoDelayStdDev, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 990 | rtc::ToString<int>(stats.echo_delay_std_ms)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 991 | } |
| 992 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 993 | bool StatsCollector::GetTrackIdBySsrc(uint32 ssrc, std::string* track_id, |
| 994 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 995 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 996 | if (direction == kSending) { |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 997 | if (!session_->GetLocalTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 998 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 999 | << " is not associated with a sending track"; |
| 1000 | return false; |
| 1001 | } |
| 1002 | } else { |
| 1003 | ASSERT(direction == kReceiving); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1004 | if (!session_->GetRemoteTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1005 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 1006 | << " is not associated with a receiving track"; |
| 1007 | return false; |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | return true; |
| 1012 | } |
| 1013 | |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 1014 | void StatsCollector::ClearUpdateStatsCacheForTest() { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1015 | stats_gathering_started_ = 0; |
| 1016 | } |
| 1017 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1018 | } // namespace webrtc |