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) { |
| 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; |
| 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 | 5b06b06 | 2014-08-15 08:38:30 +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. |
| 291 | if (report->timestamp != stats_gathering_started) { |
| 292 | report->values.clear(); |
| 293 | report->timestamp = stats_gathering_started; |
| 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) { |
| 327 | report->timestamp = info.remote_stats[0].timestamp; |
| 328 | // TODO(hta): Extract some stats here. |
| 329 | } |
| 330 | |
| 331 | void ExtractRemoteStats(const cricket::MediaReceiverInfo& info, |
| 332 | StatsReport* report) { |
| 333 | report->timestamp = info.remote_stats[0].timestamp; |
| 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) |
| 406 | : session_(session), stats_gathering_started_(0) { |
| 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); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 522 | StatsReport* StatsCollector::PrepareLocalReport( |
| 523 | uint32 ssrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 524 | const std::string& transport_id, |
| 525 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 526 | ASSERT(session_->signaling_thread()->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 527 | const std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 528 | StatsReport* report = reports_.Find( |
| 529 | StatsId(StatsReport::kStatsReportTypeSsrc, ssrc_id, direction)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 530 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 531 | // 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] | 532 | std::string track_id; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 533 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 534 | if (!report) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 535 | // The ssrc is not used by any track or existing report, return NULL |
| 536 | // 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] | 537 | return NULL; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | // The ssrc is not used by any existing track. Keeps the old track id |
| 541 | // since we want to report the stats for inactive ssrc. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 542 | ExtractValueFromReport(*report, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 543 | StatsReport::kStatsValueNameTrackId, |
| 544 | &track_id); |
| 545 | } |
| 546 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 547 | report = GetOrCreateReport( |
| 548 | StatsReport::kStatsReportTypeSsrc, ssrc_id, direction); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 549 | |
| 550 | // Clear out stats from previous GatherStats calls if any. |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 551 | // This is required since the report will be returned for the new values. |
| 552 | // Having the old values in the report will lead to multiple values with |
| 553 | // the same name. |
| 554 | // TODO(xians): Consider changing StatsReport to use map instead of vector. |
| 555 | report->values.clear(); |
| 556 | report->timestamp = stats_gathering_started_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 557 | |
| 558 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 559 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 560 | // Add the mapping of SSRC to transport. |
| 561 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 562 | transport_id); |
| 563 | return report; |
| 564 | } |
| 565 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 566 | StatsReport* StatsCollector::PrepareRemoteReport( |
| 567 | uint32 ssrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 568 | const std::string& transport_id, |
| 569 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 570 | ASSERT(session_->signaling_thread()->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 571 | const std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 572 | StatsReport* report = reports_.Find( |
| 573 | StatsId(StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id, direction)); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 574 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 575 | // 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] | 576 | std::string track_id; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 577 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 578 | if (!report) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 579 | // The ssrc is not used by any track or existing report, return NULL |
| 580 | // 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] | 581 | return NULL; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | // The ssrc is not used by any existing track. Keeps the old track id |
| 585 | // since we want to report the stats for inactive ssrc. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 586 | ExtractValueFromReport(*report, |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 587 | StatsReport::kStatsValueNameTrackId, |
| 588 | &track_id); |
| 589 | } |
| 590 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 591 | report = GetOrCreateReport( |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 592 | StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id, direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 593 | |
| 594 | // Clear out stats from previous GatherStats calls if any. |
| 595 | // The timestamp will be added later. Zero it for debugging. |
| 596 | report->values.clear(); |
| 597 | report->timestamp = 0; |
| 598 | |
| 599 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 600 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 601 | // Add the mapping of SSRC to transport. |
| 602 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 603 | transport_id); |
| 604 | return report; |
| 605 | } |
| 606 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 607 | std::string StatsCollector::AddOneCertificateReport( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 608 | const rtc::SSLCertificate* cert, const std::string& issuer_id) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 609 | // TODO(bemasc): Move this computation to a helper class that caches these |
| 610 | // values to reduce CPU use in GetStats. This will require adding a fast |
| 611 | // SSLCertificate::Equals() method to detect certificate changes. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 612 | |
| 613 | std::string digest_algorithm; |
| 614 | if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) |
| 615 | return std::string(); |
| 616 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 617 | rtc::scoped_ptr<rtc::SSLFingerprint> ssl_fingerprint( |
| 618 | rtc::SSLFingerprint::Create(digest_algorithm, cert)); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 619 | |
| 620 | // SSLFingerprint::Create can fail if the algorithm returned by |
| 621 | // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the |
| 622 | // implementation of SSLCertificate::ComputeDigest. This currently happens |
| 623 | // with MD5- and SHA-224-signed certificates when linked to libNSS. |
| 624 | if (!ssl_fingerprint) |
| 625 | return std::string(); |
| 626 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 627 | std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); |
| 628 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 629 | rtc::Buffer der_buffer; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 630 | cert->ToDER(&der_buffer); |
| 631 | std::string der_base64; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 632 | rtc::Base64::EncodeFromArray( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 633 | der_buffer.data(), der_buffer.length(), &der_base64); |
| 634 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 635 | StatsReport* report = reports_.ReplaceOrAddNew( |
| 636 | StatsId(StatsReport::kStatsReportTypeCertificate, fingerprint)); |
| 637 | report->type = StatsReport::kStatsReportTypeCertificate; |
| 638 | report->timestamp = stats_gathering_started_; |
| 639 | report->AddValue(StatsReport::kStatsValueNameFingerprint, fingerprint); |
| 640 | report->AddValue(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 641 | digest_algorithm); |
| 642 | report->AddValue(StatsReport::kStatsValueNameDer, der_base64); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 643 | if (!issuer_id.empty()) |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 644 | report->AddValue(StatsReport::kStatsValueNameIssuerId, issuer_id); |
| 645 | return report->id; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | std::string StatsCollector::AddCertificateReports( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 649 | const rtc::SSLCertificate* cert) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 650 | // Produces a chain of StatsReports representing this certificate and the rest |
| 651 | // of its chain, and adds those reports to |reports_|. The return value is |
| 652 | // the id of the leaf report. The provided cert must be non-null, so at least |
| 653 | // one report will always be provided and the returned string will never be |
| 654 | // empty. |
| 655 | ASSERT(cert != NULL); |
| 656 | |
| 657 | std::string issuer_id; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 658 | rtc::scoped_ptr<rtc::SSLCertChain> chain; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 659 | if (cert->GetChain(chain.accept())) { |
| 660 | // This loop runs in reverse, i.e. from root to leaf, so that each |
| 661 | // certificate's issuer's report ID is known before the child certificate's |
| 662 | // report is generated. The root certificate does not have an issuer ID |
| 663 | // value. |
| 664 | for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 665 | const rtc::SSLCertificate& cert_i = chain->Get(i); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 666 | issuer_id = AddOneCertificateReport(&cert_i, issuer_id); |
| 667 | } |
| 668 | } |
| 669 | // Add the leaf certificate. |
| 670 | return AddOneCertificateReport(cert, issuer_id); |
| 671 | } |
| 672 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame^] | 673 | std::string StatsCollector::AddCandidateReport( |
| 674 | const cricket::Candidate& candidate, |
| 675 | const std::string& report_type) { |
| 676 | std::ostringstream ost; |
| 677 | ost << "Cand-" << candidate.id(); |
| 678 | StatsReport* report = reports_.Find(ost.str()); |
| 679 | if (!report) { |
| 680 | report = reports_.InsertNew(ost.str()); |
| 681 | DCHECK(StatsReport::kStatsReportTypeIceLocalCandidate == report_type || |
| 682 | StatsReport::kStatsReportTypeIceRemoteCandidate == report_type); |
| 683 | report->type = report_type; |
| 684 | if (report_type == StatsReport::kStatsReportTypeIceLocalCandidate) { |
| 685 | report->AddValue(StatsReport::kStatsValueNameCandidateNetworkType, |
| 686 | AdapterTypeToStatsType(candidate.network_type())); |
| 687 | } |
| 688 | report->timestamp = stats_gathering_started_; |
| 689 | report->AddValue(StatsReport::kStatsValueNameCandidateIPAddress, |
| 690 | candidate.address().ipaddr().ToString()); |
| 691 | report->AddValue(StatsReport::kStatsValueNameCandidatePortNumber, |
| 692 | candidate.address().PortAsString()); |
| 693 | report->AddValue(StatsReport::kStatsValueNameCandidatePriority, |
| 694 | candidate.priority()); |
| 695 | report->AddValue(StatsReport::kStatsValueNameCandidateType, |
| 696 | IceCandidateTypeToStatsType(candidate.type())); |
| 697 | report->AddValue(StatsReport::kStatsValueNameCandidateTransportType, |
| 698 | candidate.protocol()); |
| 699 | } |
| 700 | |
| 701 | return ost.str(); |
| 702 | } |
| 703 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 704 | void StatsCollector::ExtractSessionInfo() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 705 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 706 | // Extract information from the base session. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 707 | StatsReport* report = reports_.ReplaceOrAddNew( |
| 708 | StatsId(StatsReport::kStatsReportTypeSession, session_->id())); |
| 709 | report->type = StatsReport::kStatsReportTypeSession; |
| 710 | report->timestamp = stats_gathering_started_; |
| 711 | report->values.clear(); |
| 712 | report->AddBoolean(StatsReport::kStatsValueNameInitiator, |
| 713 | session_->initiator()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 714 | |
| 715 | cricket::SessionStats stats; |
| 716 | if (session_->GetStats(&stats)) { |
| 717 | // Store the proxy map away for use in SSRC reporting. |
| 718 | proxy_to_transport_ = stats.proxy_to_transport; |
| 719 | |
| 720 | for (cricket::TransportStatsMap::iterator transport_iter |
| 721 | = stats.transport_stats.begin(); |
| 722 | transport_iter != stats.transport_stats.end(); ++transport_iter) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 723 | // Attempt to get a copy of the certificates from the transport and |
| 724 | // expose them in stats reports. All channels in a transport share the |
| 725 | // same local and remote certificates. |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 726 | // |
| 727 | // Note that Transport::GetIdentity and Transport::GetRemoteCertificate |
| 728 | // invoke method calls on the worker thread and block this thread, but |
| 729 | // messages are still processed on this thread, which may blow way the |
| 730 | // existing transports. So we cannot reuse |transport| after these calls. |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 731 | std::string local_cert_report_id, remote_cert_report_id; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 732 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 733 | cricket::Transport* transport = |
| 734 | session_->GetTransport(transport_iter->second.content_name); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 735 | rtc::scoped_ptr<rtc::SSLIdentity> identity; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 736 | if (transport && transport->GetIdentity(identity.accept())) { |
| 737 | local_cert_report_id = |
| 738 | AddCertificateReports(&(identity->certificate())); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 739 | } |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 740 | |
| 741 | transport = session_->GetTransport(transport_iter->second.content_name); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 742 | rtc::scoped_ptr<rtc::SSLCertificate> cert; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 743 | if (transport && transport->GetRemoteCertificate(cert.accept())) { |
| 744 | remote_cert_report_id = AddCertificateReports(cert.get()); |
| 745 | } |
| 746 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 747 | for (cricket::TransportChannelStatsList::iterator channel_iter |
| 748 | = transport_iter->second.channel_stats.begin(); |
| 749 | channel_iter != transport_iter->second.channel_stats.end(); |
| 750 | ++channel_iter) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 751 | std::ostringstream ostc; |
| 752 | ostc << "Channel-" << transport_iter->second.content_name |
| 753 | << "-" << channel_iter->component; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 754 | StatsReport* channel_report = reports_.ReplaceOrAddNew(ostc.str()); |
| 755 | channel_report->type = StatsReport::kStatsReportTypeComponent; |
| 756 | channel_report->timestamp = stats_gathering_started_; |
| 757 | channel_report->AddValue(StatsReport::kStatsValueNameComponent, |
| 758 | channel_iter->component); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 759 | if (!local_cert_report_id.empty()) |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 760 | channel_report->AddValue( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 761 | StatsReport::kStatsValueNameLocalCertificateId, |
| 762 | local_cert_report_id); |
| 763 | if (!remote_cert_report_id.empty()) |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 764 | channel_report->AddValue( |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 765 | StatsReport::kStatsValueNameRemoteCertificateId, |
| 766 | remote_cert_report_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 767 | for (size_t i = 0; |
| 768 | i < channel_iter->connection_infos.size(); |
| 769 | ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 770 | std::ostringstream ost; |
| 771 | ost << "Conn-" << transport_iter->first << "-" |
| 772 | << channel_iter->component << "-" << i; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 773 | StatsReport* report = reports_.ReplaceOrAddNew(ost.str()); |
| 774 | report->type = StatsReport::kStatsReportTypeCandidatePair; |
| 775 | report->timestamp = stats_gathering_started_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 776 | // Link from connection to its containing channel. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 777 | report->AddValue(StatsReport::kStatsValueNameChannelId, |
| 778 | channel_report->id); |
| 779 | |
| 780 | const cricket::ConnectionInfo& info = |
| 781 | channel_iter->connection_infos[i]; |
| 782 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 783 | info.sent_total_bytes); |
guoweis@webrtc.org | 930e004 | 2014-11-17 19:42:14 +0000 | [diff] [blame] | 784 | report->AddValue(StatsReport::kStatsValueNameSendPacketsDiscarded, |
| 785 | info.sent_discarded_packets); |
| 786 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 787 | info.sent_total_packets); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 788 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 789 | info.recv_total_bytes); |
| 790 | report->AddBoolean(StatsReport::kStatsValueNameWritable, |
| 791 | info.writable); |
| 792 | report->AddBoolean(StatsReport::kStatsValueNameReadable, |
| 793 | info.readable); |
| 794 | report->AddBoolean(StatsReport::kStatsValueNameActiveConnection, |
| 795 | info.best_connection); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame^] | 796 | report->AddValue(StatsReport::kStatsValueNameLocalCandidateId, |
| 797 | AddCandidateReport( |
| 798 | info.local_candidate, |
| 799 | StatsReport::kStatsReportTypeIceLocalCandidate)); |
| 800 | report->AddValue( |
| 801 | StatsReport::kStatsValueNameRemoteCandidateId, |
| 802 | AddCandidateReport( |
| 803 | info.remote_candidate, |
| 804 | StatsReport::kStatsReportTypeIceRemoteCandidate)); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 805 | report->AddValue(StatsReport::kStatsValueNameLocalAddress, |
| 806 | info.local_candidate.address().ToString()); |
| 807 | report->AddValue(StatsReport::kStatsValueNameRemoteAddress, |
| 808 | info.remote_candidate.address().ToString()); |
| 809 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt); |
| 810 | report->AddValue(StatsReport::kStatsValueNameTransportType, |
| 811 | info.local_candidate.protocol()); |
| 812 | report->AddValue(StatsReport::kStatsValueNameLocalCandidateType, |
| 813 | info.local_candidate.type()); |
| 814 | report->AddValue(StatsReport::kStatsValueNameRemoteCandidateType, |
| 815 | info.remote_candidate.type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | void StatsCollector::ExtractVoiceInfo() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 823 | ASSERT(session_->signaling_thread()->IsCurrent()); |
| 824 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 825 | if (!session_->voice_channel()) { |
| 826 | return; |
| 827 | } |
| 828 | cricket::VoiceMediaInfo voice_info; |
| 829 | if (!session_->voice_channel()->GetStats(&voice_info)) { |
| 830 | LOG(LS_ERROR) << "Failed to get voice channel stats."; |
| 831 | return; |
| 832 | } |
| 833 | std::string transport_id; |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 834 | if (!GetTransportIdFromProxy(proxy_to_transport_, |
| 835 | session_->voice_channel()->content_name(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 836 | &transport_id)) { |
| 837 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 838 | << session_->voice_channel()->content_name(); |
| 839 | return; |
| 840 | } |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 841 | ExtractStatsFromList(voice_info.receivers, transport_id, this, kReceiving); |
| 842 | ExtractStatsFromList(voice_info.senders, transport_id, this, kSending); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 843 | |
| 844 | UpdateStatsFromExistingLocalAudioTracks(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 845 | } |
| 846 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 847 | void StatsCollector::ExtractVideoInfo( |
| 848 | PeerConnectionInterface::StatsOutputLevel level) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 849 | ASSERT(session_->signaling_thread()->IsCurrent()); |
| 850 | |
| 851 | if (!session_->video_channel()) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 852 | return; |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 853 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 854 | cricket::StatsOptions options; |
| 855 | options.include_received_propagation_stats = |
| 856 | (level >= PeerConnectionInterface::kStatsOutputLevelDebug) ? |
| 857 | true : false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 858 | cricket::VideoMediaInfo video_info; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 859 | if (!session_->video_channel()->GetStats(options, &video_info)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 860 | LOG(LS_ERROR) << "Failed to get video channel stats."; |
| 861 | return; |
| 862 | } |
| 863 | std::string transport_id; |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 864 | if (!GetTransportIdFromProxy(proxy_to_transport_, |
| 865 | session_->video_channel()->content_name(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 866 | &transport_id)) { |
| 867 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 868 | << session_->video_channel()->content_name(); |
| 869 | return; |
| 870 | } |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 871 | ExtractStatsFromList(video_info.receivers, transport_id, this, kReceiving); |
| 872 | ExtractStatsFromList(video_info.senders, transport_id, this, kSending); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 873 | if (video_info.bw_estimations.size() != 1) { |
| 874 | LOG(LS_ERROR) << "BWEs count: " << video_info.bw_estimations.size(); |
| 875 | } else { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 876 | StatsReport* report = |
| 877 | reports_.FindOrAddNew(StatsReport::kStatsReportVideoBweId); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 878 | ExtractStats( |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 879 | video_info.bw_estimations[0], stats_gathering_started_, level, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 883 | StatsReport* StatsCollector::GetReport(const std::string& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 884 | const std::string& id, |
| 885 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 886 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 887 | ASSERT(type == StatsReport::kStatsReportTypeSsrc || |
| 888 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 889 | return reports_.Find(StatsId(type, id, direction)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | StatsReport* StatsCollector::GetOrCreateReport(const std::string& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 893 | const std::string& id, |
| 894 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 895 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 896 | ASSERT(type == StatsReport::kStatsReportTypeSsrc || |
| 897 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
| 898 | StatsReport* report = GetReport(type, id, direction); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 899 | if (report == NULL) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 900 | std::string statsid = StatsId(type, id, direction); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 901 | report = reports_.FindOrAddNew(statsid); |
| 902 | ASSERT(report->id == statsid); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 903 | report->type = type; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 904 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 905 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 906 | return report; |
| 907 | } |
| 908 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 909 | void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 910 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 911 | // Loop through the existing local audio tracks. |
| 912 | for (LocalAudioTrackVector::const_iterator it = local_audio_tracks_.begin(); |
| 913 | it != local_audio_tracks_.end(); ++it) { |
| 914 | AudioTrackInterface* track = it->first; |
| 915 | uint32 ssrc = it->second; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 916 | std::string ssrc_id = rtc::ToString<uint32>(ssrc); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 917 | StatsReport* report = GetReport(StatsReport::kStatsReportTypeSsrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 918 | ssrc_id, |
| 919 | kSending); |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 920 | if (report == NULL) { |
| 921 | // This can happen if a local audio track is added to a stream on the |
| 922 | // fly and the report has not been set up yet. Do nothing in this case. |
| 923 | LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; |
| 924 | continue; |
| 925 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 926 | |
| 927 | // The same ssrc can be used by both local and remote audio tracks. |
| 928 | std::string track_id; |
| 929 | if (!ExtractValueFromReport(*report, |
| 930 | StatsReport::kStatsValueNameTrackId, |
| 931 | &track_id) || |
| 932 | track_id != track->id()) { |
| 933 | continue; |
| 934 | } |
| 935 | |
| 936 | UpdateReportFromAudioTrack(track, report); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, |
| 941 | StatsReport* report) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 942 | ASSERT(session_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 943 | ASSERT(track != NULL); |
| 944 | if (report == NULL) |
| 945 | return; |
| 946 | |
| 947 | int signal_level = 0; |
| 948 | if (track->GetSignalLevel(&signal_level)) { |
| 949 | report->ReplaceValue(StatsReport::kStatsValueNameAudioInputLevel, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 950 | rtc::ToString<int>(signal_level)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 951 | } |
| 952 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 953 | rtc::scoped_refptr<AudioProcessorInterface> audio_processor( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 954 | track->GetAudioProcessor()); |
| 955 | if (audio_processor.get() == NULL) |
| 956 | return; |
| 957 | |
| 958 | AudioProcessorInterface::AudioProcessorStats stats; |
| 959 | audio_processor->GetStats(&stats); |
| 960 | report->ReplaceValue(StatsReport::kStatsValueNameTypingNoiseState, |
| 961 | stats.typing_noise_detected ? "true" : "false"); |
| 962 | report->ReplaceValue(StatsReport::kStatsValueNameEchoReturnLoss, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 963 | rtc::ToString<int>(stats.echo_return_loss)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 964 | report->ReplaceValue( |
| 965 | StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 966 | rtc::ToString<int>(stats.echo_return_loss_enhancement)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 967 | report->ReplaceValue(StatsReport::kStatsValueNameEchoDelayMedian, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 968 | rtc::ToString<int>(stats.echo_delay_median_ms)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 969 | report->ReplaceValue(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 970 | rtc::ToString<float>(stats.aec_quality_min)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 971 | report->ReplaceValue(StatsReport::kStatsValueNameEchoDelayStdDev, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 972 | rtc::ToString<int>(stats.echo_delay_std_ms)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 973 | } |
| 974 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 975 | bool StatsCollector::GetTrackIdBySsrc(uint32 ssrc, std::string* track_id, |
| 976 | TrackDirection direction) { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 977 | ASSERT(session_->signaling_thread()->IsCurrent()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 978 | if (direction == kSending) { |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 979 | if (!session_->GetLocalTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 980 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 981 | << " is not associated with a sending track"; |
| 982 | return false; |
| 983 | } |
| 984 | } else { |
| 985 | ASSERT(direction == kReceiving); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 986 | if (!session_->GetRemoteTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 987 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 988 | << " is not associated with a receiving track"; |
| 989 | return false; |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | return true; |
| 994 | } |
| 995 | |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 996 | void StatsCollector::ClearUpdateStatsCacheForTest() { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 997 | stats_gathering_started_ = 0; |
| 998 | } |
| 999 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1000 | } // namespace webrtc |