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 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 33 | #include "talk/base/base64.h" |
| 34 | #include "talk/base/scoped_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | #include "talk/session/media/channel.h" |
| 36 | |
| 37 | namespace webrtc { |
| 38 | |
| 39 | // The items below are in alphabetical order. |
| 40 | const char StatsReport::kStatsValueNameActiveConnection[] = |
| 41 | "googActiveConnection"; |
| 42 | const char StatsReport::kStatsValueNameActualEncBitrate[] = |
| 43 | "googActualEncBitrate"; |
| 44 | const char StatsReport::kStatsValueNameAudioOutputLevel[] = "audioOutputLevel"; |
| 45 | const char StatsReport::kStatsValueNameAudioInputLevel[] = "audioInputLevel"; |
| 46 | const char StatsReport::kStatsValueNameAvailableReceiveBandwidth[] = |
| 47 | "googAvailableReceiveBandwidth"; |
| 48 | const char StatsReport::kStatsValueNameAvailableSendBandwidth[] = |
| 49 | "googAvailableSendBandwidth"; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 50 | const char StatsReport::kStatsValueNameAvgEncodeMs[] = "googAvgEncodeMs"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | const char StatsReport::kStatsValueNameBucketDelay[] = "googBucketDelay"; |
| 52 | const char StatsReport::kStatsValueNameBytesReceived[] = "bytesReceived"; |
| 53 | const char StatsReport::kStatsValueNameBytesSent[] = "bytesSent"; |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 54 | const char StatsReport::kStatsValueNameBandwidthLimitedResolution[] = |
| 55 | "googBandwidthLimitedResolution"; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 56 | const char StatsReport::kStatsValueNameCaptureJitterMs[] = |
| 57 | "googCaptureJitterMs"; |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 58 | const char StatsReport::kStatsValueNameCaptureQueueDelayMsPerS[] = |
| 59 | "googCaptureQueueDelayMsPerS"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | const char StatsReport::kStatsValueNameChannelId[] = "googChannelId"; |
| 61 | const char StatsReport::kStatsValueNameCodecName[] = "googCodecName"; |
| 62 | const char StatsReport::kStatsValueNameComponent[] = "googComponent"; |
| 63 | const char StatsReport::kStatsValueNameContentName[] = "googContentName"; |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 64 | const char StatsReport::kStatsValueNameCpuLimitedResolution[] = |
| 65 | "googCpuLimitedResolution"; |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 66 | const char StatsReport::kStatsValueNameDecodingCTSG[] = |
| 67 | "googDecodingCTSG"; |
| 68 | const char StatsReport::kStatsValueNameDecodingCTN[] = |
| 69 | "googDecodingCTN"; |
| 70 | const char StatsReport::kStatsValueNameDecodingNormal[] = |
| 71 | "googDecodingNormal"; |
| 72 | const char StatsReport::kStatsValueNameDecodingPLC[] = |
| 73 | "googDecodingPLC"; |
| 74 | const char StatsReport::kStatsValueNameDecodingCNG[] = |
| 75 | "googDecodingCNG"; |
| 76 | const char StatsReport::kStatsValueNameDecodingPLCCNG[] = |
| 77 | "googDecodingPLCCNG"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 78 | const char StatsReport::kStatsValueNameDer[] = "googDerBase64"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | // Echo metrics from the audio processing module. |
| 80 | const char StatsReport::kStatsValueNameEchoCancellationQualityMin[] = |
| 81 | "googEchoCancellationQualityMin"; |
| 82 | const char StatsReport::kStatsValueNameEchoDelayMedian[] = |
| 83 | "googEchoCancellationEchoDelayMedian"; |
| 84 | const char StatsReport::kStatsValueNameEchoDelayStdDev[] = |
| 85 | "googEchoCancellationEchoDelayStdDev"; |
| 86 | const char StatsReport::kStatsValueNameEchoReturnLoss[] = |
| 87 | "googEchoCancellationReturnLoss"; |
| 88 | const char StatsReport::kStatsValueNameEchoReturnLossEnhancement[] = |
| 89 | "googEchoCancellationReturnLossEnhancement"; |
| 90 | |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 91 | const char StatsReport::kStatsValueNameEncodeUsagePercent[] = |
| 92 | "googEncodeUsagePercent"; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 93 | const char StatsReport::kStatsValueNameExpandRate[] = "googExpandRate"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 94 | const char StatsReport::kStatsValueNameFingerprint[] = "googFingerprint"; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 95 | const char StatsReport::kStatsValueNameFingerprintAlgorithm[] = |
| 96 | "googFingerprintAlgorithm"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 97 | const char StatsReport::kStatsValueNameFirsReceived[] = "googFirsReceived"; |
| 98 | const char StatsReport::kStatsValueNameFirsSent[] = "googFirsSent"; |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 99 | const char StatsReport::kStatsValueNameFrameHeightInput[] = |
| 100 | "googFrameHeightInput"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | const char StatsReport::kStatsValueNameFrameHeightReceived[] = |
| 102 | "googFrameHeightReceived"; |
| 103 | const char StatsReport::kStatsValueNameFrameHeightSent[] = |
| 104 | "googFrameHeightSent"; |
| 105 | const char StatsReport::kStatsValueNameFrameRateReceived[] = |
| 106 | "googFrameRateReceived"; |
| 107 | const char StatsReport::kStatsValueNameFrameRateDecoded[] = |
| 108 | "googFrameRateDecoded"; |
| 109 | const char StatsReport::kStatsValueNameFrameRateOutput[] = |
| 110 | "googFrameRateOutput"; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 111 | const char StatsReport::kStatsValueNameDecodeMs[] = "googDecodeMs"; |
| 112 | const char StatsReport::kStatsValueNameMaxDecodeMs[] = "googMaxDecodeMs"; |
| 113 | const char StatsReport::kStatsValueNameCurrentDelayMs[] = "googCurrentDelayMs"; |
| 114 | const char StatsReport::kStatsValueNameTargetDelayMs[] = "googTargetDelayMs"; |
| 115 | const char StatsReport::kStatsValueNameJitterBufferMs[] = "googJitterBufferMs"; |
| 116 | const char StatsReport::kStatsValueNameMinPlayoutDelayMs[] = |
| 117 | "googMinPlayoutDelayMs"; |
| 118 | const char StatsReport::kStatsValueNameRenderDelayMs[] = "googRenderDelayMs"; |
| 119 | |
buildbot@webrtc.org | 0581f0b | 2014-05-06 21:36:31 +0000 | [diff] [blame] | 120 | const char StatsReport::kStatsValueNameCaptureStartNtpTimeMs[] = |
| 121 | "googCaptureStartNtpTimeMs"; |
| 122 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | const char StatsReport::kStatsValueNameFrameRateInput[] = "googFrameRateInput"; |
| 124 | const char StatsReport::kStatsValueNameFrameRateSent[] = "googFrameRateSent"; |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 125 | const char StatsReport::kStatsValueNameFrameWidthInput[] = |
| 126 | "googFrameWidthInput"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 127 | const char StatsReport::kStatsValueNameFrameWidthReceived[] = |
| 128 | "googFrameWidthReceived"; |
| 129 | const char StatsReport::kStatsValueNameFrameWidthSent[] = "googFrameWidthSent"; |
| 130 | const char StatsReport::kStatsValueNameInitiator[] = "googInitiator"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 131 | const char StatsReport::kStatsValueNameIssuerId[] = "googIssuerId"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | const char StatsReport::kStatsValueNameJitterReceived[] = "googJitterReceived"; |
| 133 | const char StatsReport::kStatsValueNameLocalAddress[] = "googLocalAddress"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 134 | const char StatsReport::kStatsValueNameLocalCandidateType[] = |
| 135 | "googLocalCandidateType"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 136 | const char StatsReport::kStatsValueNameLocalCertificateId[] = |
| 137 | "googLocalCertificateId"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | const char StatsReport::kStatsValueNameNacksReceived[] = "googNacksReceived"; |
| 139 | const char StatsReport::kStatsValueNameNacksSent[] = "googNacksSent"; |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 140 | const char StatsReport::kStatsValueNamePlisReceived[] = "googPlisReceived"; |
| 141 | const char StatsReport::kStatsValueNamePlisSent[] = "googPlisSent"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | const char StatsReport::kStatsValueNamePacketsReceived[] = "packetsReceived"; |
| 143 | const char StatsReport::kStatsValueNamePacketsSent[] = "packetsSent"; |
| 144 | const char StatsReport::kStatsValueNamePacketsLost[] = "packetsLost"; |
jiayl@webrtc.org | 11aab0e | 2014-03-07 18:56:26 +0000 | [diff] [blame] | 145 | const char StatsReport::kStatsValueNamePreferredJitterBufferMs[] = |
| 146 | "googPreferredJitterBufferMs"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 147 | const char StatsReport::kStatsValueNameReadable[] = "googReadable"; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 148 | const char StatsReport::kStatsValueNameRecvPacketGroupArrivalTimeDebug[] = |
| 149 | "googReceivedPacketGroupArrivalTimeDebug"; |
| 150 | const char StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaDebug[] = |
| 151 | "googReceivedPacketGroupPropagationDeltaDebug"; |
| 152 | const char |
| 153 | StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaSumDebug[] = |
| 154 | "googReceivedPacketGroupPropagationDeltaSumDebug"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | const char StatsReport::kStatsValueNameRemoteAddress[] = "googRemoteAddress"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 156 | const char StatsReport::kStatsValueNameRemoteCandidateType[] = |
| 157 | "googRemoteCandidateType"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 158 | const char StatsReport::kStatsValueNameRemoteCertificateId[] = |
| 159 | "googRemoteCertificateId"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 160 | const char StatsReport::kStatsValueNameRetransmitBitrate[] = |
| 161 | "googRetransmitBitrate"; |
| 162 | const char StatsReport::kStatsValueNameRtt[] = "googRtt"; |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 163 | const char StatsReport::kStatsValueNameSsrc[] = "ssrc"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | const char StatsReport::kStatsValueNameTargetEncBitrate[] = |
| 165 | "googTargetEncBitrate"; |
| 166 | const char StatsReport::kStatsValueNameTransmitBitrate[] = |
| 167 | "googTransmitBitrate"; |
| 168 | const char StatsReport::kStatsValueNameTransportId[] = "transportId"; |
| 169 | const char StatsReport::kStatsValueNameTransportType[] = "googTransportType"; |
| 170 | const char StatsReport::kStatsValueNameTrackId[] = "googTrackId"; |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 171 | const char StatsReport::kStatsValueNameTypingNoiseState[] = |
| 172 | "googTypingNoiseState"; |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 173 | const char StatsReport::kStatsValueNameViewLimitedResolution[] = |
| 174 | "googViewLimitedResolution"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 175 | const char StatsReport::kStatsValueNameWritable[] = "googWritable"; |
| 176 | |
| 177 | const char StatsReport::kStatsReportTypeSession[] = "googLibjingleSession"; |
| 178 | const char StatsReport::kStatsReportTypeBwe[] = "VideoBwe"; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 179 | const char StatsReport::kStatsReportTypeRemoteSsrc[] = "remoteSsrc"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | const char StatsReport::kStatsReportTypeSsrc[] = "ssrc"; |
| 181 | const char StatsReport::kStatsReportTypeTrack[] = "googTrack"; |
| 182 | const char StatsReport::kStatsReportTypeIceCandidate[] = "iceCandidate"; |
| 183 | const char StatsReport::kStatsReportTypeTransport[] = "googTransport"; |
| 184 | const char StatsReport::kStatsReportTypeComponent[] = "googComponent"; |
| 185 | const char StatsReport::kStatsReportTypeCandidatePair[] = "googCandidatePair"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 186 | const char StatsReport::kStatsReportTypeCertificate[] = "googCertificate"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | |
| 188 | const char StatsReport::kStatsReportVideoBweId[] = "bweforvideo"; |
| 189 | |
| 190 | // Implementations of functions in statstypes.h |
| 191 | void StatsReport::AddValue(const std::string& name, const std::string& value) { |
| 192 | Value temp; |
| 193 | temp.name = name; |
| 194 | temp.value = value; |
| 195 | values.push_back(temp); |
| 196 | } |
| 197 | |
| 198 | void StatsReport::AddValue(const std::string& name, int64 value) { |
| 199 | AddValue(name, talk_base::ToString<int64>(value)); |
| 200 | } |
| 201 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 202 | template <typename T> |
| 203 | void StatsReport::AddValue(const std::string& name, |
| 204 | const std::vector<T>& value) { |
| 205 | std::ostringstream oss; |
| 206 | oss << "["; |
| 207 | for (size_t i = 0; i < value.size(); ++i) { |
| 208 | oss << talk_base::ToString<T>(value[i]); |
| 209 | if (i != value.size() - 1) |
| 210 | oss << ", "; |
| 211 | } |
| 212 | oss << "]"; |
| 213 | AddValue(name, oss.str()); |
| 214 | } |
| 215 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 216 | void StatsReport::AddBoolean(const std::string& name, bool value) { |
| 217 | AddValue(name, value ? "true" : "false"); |
| 218 | } |
| 219 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 220 | void StatsReport::ReplaceValue(const std::string& name, |
| 221 | const std::string& value) { |
| 222 | for (Values::iterator it = values.begin(); it != values.end(); ++it) { |
| 223 | if ((*it).name == name) { |
| 224 | it->value = value; |
| 225 | return; |
| 226 | } |
| 227 | } |
| 228 | // It is not reachable here, add an ASSERT to make sure the overwriting is |
| 229 | // always a success. |
| 230 | ASSERT(false); |
| 231 | } |
| 232 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 233 | namespace { |
| 234 | typedef std::map<std::string, StatsReport> StatsMap; |
| 235 | |
| 236 | std::string StatsId(const std::string& type, const std::string& id) { |
| 237 | return type + "_" + id; |
| 238 | } |
| 239 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 240 | std::string StatsId(const std::string& type, const std::string& id, |
| 241 | StatsCollector::TrackDirection direction) { |
| 242 | ASSERT(direction == StatsCollector::kSending || |
| 243 | direction == StatsCollector::kReceiving); |
| 244 | |
| 245 | // Strings for the direction of the track. |
| 246 | const char kSendDirection[] = "send"; |
| 247 | const char kRecvDirection[] = "recv"; |
| 248 | |
| 249 | const std::string direction_id = (direction == StatsCollector::kSending) ? |
| 250 | kSendDirection : kRecvDirection; |
| 251 | return type + "_" + id + "_" + direction_id; |
| 252 | } |
| 253 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 254 | bool ExtractValueFromReport( |
| 255 | const StatsReport& report, |
| 256 | const std::string& name, |
| 257 | std::string* value) { |
| 258 | StatsReport::Values::const_iterator it = report.values.begin(); |
| 259 | for (; it != report.values.end(); ++it) { |
| 260 | if (it->name == name) { |
| 261 | *value = it->value; |
| 262 | return true; |
| 263 | } |
| 264 | } |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | template <class TrackVector> |
| 269 | void CreateTrackReports(const TrackVector& tracks, StatsMap* reports) { |
| 270 | for (size_t j = 0; j < tracks.size(); ++j) { |
| 271 | webrtc::MediaStreamTrackInterface* track = tracks[j]; |
| 272 | // Adds an empty track report. |
| 273 | StatsReport report; |
| 274 | report.type = StatsReport::kStatsReportTypeTrack; |
| 275 | report.id = StatsId(StatsReport::kStatsReportTypeTrack, track->id()); |
| 276 | report.AddValue(StatsReport::kStatsValueNameTrackId, |
| 277 | track->id()); |
| 278 | (*reports)[report.id] = report; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | void ExtractStats(const cricket::VoiceReceiverInfo& info, StatsReport* report) { |
| 283 | report->AddValue(StatsReport::kStatsValueNameAudioOutputLevel, |
| 284 | info.audio_level); |
| 285 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 286 | info.bytes_rcvd); |
| 287 | report->AddValue(StatsReport::kStatsValueNameJitterReceived, |
| 288 | info.jitter_ms); |
jiayl@webrtc.org | 11aab0e | 2014-03-07 18:56:26 +0000 | [diff] [blame] | 289 | report->AddValue(StatsReport::kStatsValueNameJitterBufferMs, |
| 290 | info.jitter_buffer_ms); |
| 291 | report->AddValue(StatsReport::kStatsValueNamePreferredJitterBufferMs, |
| 292 | info.jitter_buffer_preferred_ms); |
| 293 | report->AddValue(StatsReport::kStatsValueNameCurrentDelayMs, |
| 294 | info.delay_estimate_ms); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 295 | report->AddValue(StatsReport::kStatsValueNameExpandRate, |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 296 | talk_base::ToString<float>(info.expand_rate)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 297 | report->AddValue(StatsReport::kStatsValueNamePacketsReceived, |
| 298 | info.packets_rcvd); |
| 299 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 300 | info.packets_lost); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 301 | report->AddValue(StatsReport::kStatsValueNameDecodingCTSG, |
| 302 | info.decoding_calls_to_silence_generator); |
| 303 | report->AddValue(StatsReport::kStatsValueNameDecodingCTN, |
| 304 | info.decoding_calls_to_neteq); |
| 305 | report->AddValue(StatsReport::kStatsValueNameDecodingNormal, |
| 306 | info.decoding_normal); |
| 307 | report->AddValue(StatsReport::kStatsValueNameDecodingPLC, |
| 308 | info.decoding_plc); |
| 309 | report->AddValue(StatsReport::kStatsValueNameDecodingCNG, |
| 310 | info.decoding_cng); |
| 311 | report->AddValue(StatsReport::kStatsValueNameDecodingPLCCNG, |
| 312 | info.decoding_plc_cng); |
buildbot@webrtc.org | b525a9d | 2014-06-03 09:42:15 +0000 | [diff] [blame] | 313 | report->AddValue(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 314 | info.capture_start_ntp_time_ms); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 315 | report->AddValue(StatsReport::kStatsValueNameCodecName, info.codec_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | void ExtractStats(const cricket::VoiceSenderInfo& info, StatsReport* report) { |
| 319 | report->AddValue(StatsReport::kStatsValueNameAudioInputLevel, |
| 320 | info.audio_level); |
| 321 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 322 | info.bytes_sent); |
| 323 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 324 | info.packets_sent); |
henrike@webrtc.org | ffe2620 | 2014-03-19 22:20:10 +0000 | [diff] [blame] | 325 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 326 | info.packets_lost); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 327 | report->AddValue(StatsReport::kStatsValueNameJitterReceived, |
| 328 | info.jitter_ms); |
| 329 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 330 | report->AddValue(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
| 331 | talk_base::ToString<float>(info.aec_quality_min)); |
| 332 | report->AddValue(StatsReport::kStatsValueNameEchoDelayMedian, |
| 333 | info.echo_delay_median_ms); |
| 334 | report->AddValue(StatsReport::kStatsValueNameEchoDelayStdDev, |
| 335 | info.echo_delay_std_ms); |
| 336 | report->AddValue(StatsReport::kStatsValueNameEchoReturnLoss, |
| 337 | info.echo_return_loss); |
| 338 | report->AddValue(StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
| 339 | info.echo_return_loss_enhancement); |
| 340 | report->AddValue(StatsReport::kStatsValueNameCodecName, info.codec_name); |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 341 | report->AddBoolean(StatsReport::kStatsValueNameTypingNoiseState, |
| 342 | info.typing_noise_detected); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | void ExtractStats(const cricket::VideoReceiverInfo& info, StatsReport* report) { |
| 346 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 347 | info.bytes_rcvd); |
| 348 | report->AddValue(StatsReport::kStatsValueNamePacketsReceived, |
| 349 | info.packets_rcvd); |
| 350 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 351 | info.packets_lost); |
| 352 | |
| 353 | report->AddValue(StatsReport::kStatsValueNameFirsSent, |
| 354 | info.firs_sent); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 355 | report->AddValue(StatsReport::kStatsValueNamePlisSent, |
| 356 | info.plis_sent); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 357 | report->AddValue(StatsReport::kStatsValueNameNacksSent, |
| 358 | info.nacks_sent); |
| 359 | report->AddValue(StatsReport::kStatsValueNameFrameWidthReceived, |
| 360 | info.frame_width); |
| 361 | report->AddValue(StatsReport::kStatsValueNameFrameHeightReceived, |
| 362 | info.frame_height); |
| 363 | report->AddValue(StatsReport::kStatsValueNameFrameRateReceived, |
| 364 | info.framerate_rcvd); |
| 365 | report->AddValue(StatsReport::kStatsValueNameFrameRateDecoded, |
| 366 | info.framerate_decoded); |
| 367 | report->AddValue(StatsReport::kStatsValueNameFrameRateOutput, |
| 368 | info.framerate_output); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 369 | |
| 370 | report->AddValue(StatsReport::kStatsValueNameDecodeMs, |
| 371 | info.decode_ms); |
| 372 | report->AddValue(StatsReport::kStatsValueNameMaxDecodeMs, |
| 373 | info.max_decode_ms); |
| 374 | report->AddValue(StatsReport::kStatsValueNameCurrentDelayMs, |
| 375 | info.current_delay_ms); |
| 376 | report->AddValue(StatsReport::kStatsValueNameTargetDelayMs, |
| 377 | info.target_delay_ms); |
| 378 | report->AddValue(StatsReport::kStatsValueNameJitterBufferMs, |
| 379 | info.jitter_buffer_ms); |
| 380 | report->AddValue(StatsReport::kStatsValueNameMinPlayoutDelayMs, |
| 381 | info.min_playout_delay_ms); |
| 382 | report->AddValue(StatsReport::kStatsValueNameRenderDelayMs, |
| 383 | info.render_delay_ms); |
buildbot@webrtc.org | 0581f0b | 2014-05-06 21:36:31 +0000 | [diff] [blame] | 384 | |
| 385 | report->AddValue(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 386 | info.capture_start_ntp_time_ms); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | void ExtractStats(const cricket::VideoSenderInfo& info, StatsReport* report) { |
| 390 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 391 | info.bytes_sent); |
| 392 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 393 | info.packets_sent); |
henrike@webrtc.org | ffe2620 | 2014-03-19 22:20:10 +0000 | [diff] [blame] | 394 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 395 | info.packets_lost); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 396 | |
| 397 | report->AddValue(StatsReport::kStatsValueNameFirsReceived, |
| 398 | info.firs_rcvd); |
henrike@webrtc.org | 704bf9e | 2014-02-27 17:52:04 +0000 | [diff] [blame] | 399 | report->AddValue(StatsReport::kStatsValueNamePlisReceived, |
| 400 | info.plis_rcvd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 401 | report->AddValue(StatsReport::kStatsValueNameNacksReceived, |
| 402 | info.nacks_rcvd); |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 403 | report->AddValue(StatsReport::kStatsValueNameFrameWidthInput, |
| 404 | info.input_frame_width); |
| 405 | report->AddValue(StatsReport::kStatsValueNameFrameHeightInput, |
| 406 | info.input_frame_height); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | report->AddValue(StatsReport::kStatsValueNameFrameWidthSent, |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 408 | info.send_frame_width); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 409 | report->AddValue(StatsReport::kStatsValueNameFrameHeightSent, |
wu@webrtc.org | 987f2c9 | 2014-03-28 16:22:19 +0000 | [diff] [blame] | 410 | info.send_frame_height); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 411 | report->AddValue(StatsReport::kStatsValueNameFrameRateInput, |
| 412 | info.framerate_input); |
| 413 | report->AddValue(StatsReport::kStatsValueNameFrameRateSent, |
| 414 | info.framerate_sent); |
| 415 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 416 | report->AddValue(StatsReport::kStatsValueNameCodecName, info.codec_name); |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 417 | report->AddBoolean(StatsReport::kStatsValueNameCpuLimitedResolution, |
| 418 | (info.adapt_reason & 0x1) > 0); |
| 419 | report->AddBoolean(StatsReport::kStatsValueNameBandwidthLimitedResolution, |
| 420 | (info.adapt_reason & 0x2) > 0); |
| 421 | report->AddBoolean(StatsReport::kStatsValueNameViewLimitedResolution, |
| 422 | (info.adapt_reason & 0x4) > 0); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 423 | report->AddValue(StatsReport::kStatsValueNameAvgEncodeMs, info.avg_encode_ms); |
| 424 | report->AddValue(StatsReport::kStatsValueNameCaptureJitterMs, |
| 425 | info.capture_jitter_ms); |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 426 | report->AddValue(StatsReport::kStatsValueNameCaptureQueueDelayMsPerS, |
| 427 | info.capture_queue_delay_ms_per_s); |
| 428 | report->AddValue(StatsReport::kStatsValueNameEncodeUsagePercent, |
| 429 | info.encode_usage_percent); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | void ExtractStats(const cricket::BandwidthEstimationInfo& info, |
| 433 | double stats_gathering_started, |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 434 | PeerConnectionInterface::StatsOutputLevel level, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 435 | StatsReport* report) { |
| 436 | report->id = StatsReport::kStatsReportVideoBweId; |
| 437 | report->type = StatsReport::kStatsReportTypeBwe; |
| 438 | |
| 439 | // Clear out stats from previous GatherStats calls if any. |
| 440 | if (report->timestamp != stats_gathering_started) { |
| 441 | report->values.clear(); |
| 442 | report->timestamp = stats_gathering_started; |
| 443 | } |
| 444 | |
| 445 | report->AddValue(StatsReport::kStatsValueNameAvailableSendBandwidth, |
| 446 | info.available_send_bandwidth); |
| 447 | report->AddValue(StatsReport::kStatsValueNameAvailableReceiveBandwidth, |
| 448 | info.available_recv_bandwidth); |
| 449 | report->AddValue(StatsReport::kStatsValueNameTargetEncBitrate, |
| 450 | info.target_enc_bitrate); |
| 451 | report->AddValue(StatsReport::kStatsValueNameActualEncBitrate, |
| 452 | info.actual_enc_bitrate); |
| 453 | report->AddValue(StatsReport::kStatsValueNameRetransmitBitrate, |
| 454 | info.retransmit_bitrate); |
| 455 | report->AddValue(StatsReport::kStatsValueNameTransmitBitrate, |
| 456 | info.transmit_bitrate); |
| 457 | report->AddValue(StatsReport::kStatsValueNameBucketDelay, |
| 458 | info.bucket_delay); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 459 | if (level >= PeerConnectionInterface::kStatsOutputLevelDebug) { |
| 460 | report->AddValue( |
| 461 | StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaSumDebug, |
| 462 | info.total_received_propagation_delta_ms); |
| 463 | if (info.recent_received_propagation_delta_ms.size() > 0) { |
| 464 | report->AddValue( |
| 465 | StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaDebug, |
| 466 | info.recent_received_propagation_delta_ms); |
| 467 | report->AddValue( |
| 468 | StatsReport::kStatsValueNameRecvPacketGroupArrivalTimeDebug, |
| 469 | info.recent_received_packet_group_arrival_time_ms); |
| 470 | } |
| 471 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 472 | } |
| 473 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 474 | void ExtractRemoteStats(const cricket::MediaSenderInfo& info, |
| 475 | StatsReport* report) { |
| 476 | report->timestamp = info.remote_stats[0].timestamp; |
| 477 | // TODO(hta): Extract some stats here. |
| 478 | } |
| 479 | |
| 480 | void ExtractRemoteStats(const cricket::MediaReceiverInfo& info, |
| 481 | StatsReport* report) { |
| 482 | report->timestamp = info.remote_stats[0].timestamp; |
| 483 | // TODO(hta): Extract some stats here. |
| 484 | } |
| 485 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 486 | // Template to extract stats from a data vector. |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 487 | // In order to use the template, the functions that are called from it, |
| 488 | // ExtractStats and ExtractRemoteStats, must be defined and overloaded |
| 489 | // for each type. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | template<typename T> |
| 491 | void ExtractStatsFromList(const std::vector<T>& data, |
| 492 | const std::string& transport_id, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 493 | StatsCollector* collector, |
| 494 | StatsCollector::TrackDirection direction) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 495 | typename std::vector<T>::const_iterator it = data.begin(); |
| 496 | for (; it != data.end(); ++it) { |
| 497 | std::string id; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 498 | uint32 ssrc = it->ssrc(); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 499 | // Each track can have stats for both local and remote objects. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 500 | // TODO(hta): Handle the case of multiple SSRCs per object. |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 501 | StatsReport* report = collector->PrepareLocalReport(ssrc, transport_id, |
| 502 | direction); |
| 503 | if (report) |
| 504 | ExtractStats(*it, report); |
| 505 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 506 | if (it->remote_stats.size() > 0) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 507 | report = collector->PrepareRemoteReport(ssrc, transport_id, |
| 508 | direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 509 | if (!report) { |
| 510 | continue; |
| 511 | } |
| 512 | ExtractRemoteStats(*it, report); |
| 513 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 514 | } |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 515 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 516 | |
| 517 | } // namespace |
| 518 | |
| 519 | StatsCollector::StatsCollector() |
| 520 | : session_(NULL), stats_gathering_started_(0) { |
| 521 | } |
| 522 | |
| 523 | // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 524 | // to GetStats. |
| 525 | void StatsCollector::AddStream(MediaStreamInterface* stream) { |
| 526 | ASSERT(stream != NULL); |
| 527 | |
| 528 | CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), |
| 529 | &reports_); |
| 530 | CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), |
| 531 | &reports_); |
| 532 | } |
| 533 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 534 | void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, |
| 535 | uint32 ssrc) { |
| 536 | ASSERT(audio_track != NULL); |
| 537 | #ifdef _DEBUG |
| 538 | for (LocalAudioTrackVector::iterator it = local_audio_tracks_.begin(); |
| 539 | it != local_audio_tracks_.end(); ++it) { |
| 540 | ASSERT(it->first != audio_track || it->second != ssrc); |
| 541 | } |
| 542 | #endif |
| 543 | local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc)); |
| 544 | } |
| 545 | |
| 546 | void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, |
| 547 | uint32 ssrc) { |
| 548 | ASSERT(audio_track != NULL); |
| 549 | for (LocalAudioTrackVector::iterator it = local_audio_tracks_.begin(); |
| 550 | it != local_audio_tracks_.end(); ++it) { |
| 551 | if (it->first == audio_track && it->second == ssrc) { |
| 552 | local_audio_tracks_.erase(it); |
| 553 | return; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | ASSERT(false); |
| 558 | } |
| 559 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 560 | bool StatsCollector::GetStats(MediaStreamTrackInterface* track, |
| 561 | StatsReports* reports) { |
| 562 | ASSERT(reports != NULL); |
| 563 | reports->clear(); |
| 564 | |
| 565 | StatsMap::iterator it; |
| 566 | if (!track) { |
| 567 | for (it = reports_.begin(); it != reports_.end(); ++it) { |
| 568 | reports->push_back(it->second); |
| 569 | } |
| 570 | return true; |
| 571 | } |
| 572 | |
| 573 | it = reports_.find(StatsId(StatsReport::kStatsReportTypeSession, |
| 574 | session_->id())); |
| 575 | if (it != reports_.end()) { |
| 576 | reports->push_back(it->second); |
| 577 | } |
| 578 | |
| 579 | it = reports_.find(StatsId(StatsReport::kStatsReportTypeTrack, track->id())); |
| 580 | |
| 581 | if (it == reports_.end()) { |
| 582 | LOG(LS_WARNING) << "No StatsReport is available for "<< track->id(); |
| 583 | return false; |
| 584 | } |
| 585 | |
| 586 | reports->push_back(it->second); |
| 587 | |
| 588 | std::string track_id; |
| 589 | for (it = reports_.begin(); it != reports_.end(); ++it) { |
| 590 | if (it->second.type != StatsReport::kStatsReportTypeSsrc) { |
| 591 | continue; |
| 592 | } |
| 593 | if (ExtractValueFromReport(it->second, |
| 594 | StatsReport::kStatsValueNameTrackId, |
| 595 | &track_id)) { |
| 596 | if (track_id == track->id()) { |
| 597 | reports->push_back(it->second); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return true; |
| 603 | } |
| 604 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 605 | void |
| 606 | StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 607 | double time_now = GetTimeNow(); |
| 608 | // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of |
| 609 | // ms apart will be ignored. |
| 610 | const double kMinGatherStatsPeriod = 50; |
| 611 | if (stats_gathering_started_ + kMinGatherStatsPeriod > time_now) { |
| 612 | return; |
| 613 | } |
| 614 | stats_gathering_started_ = time_now; |
| 615 | |
| 616 | if (session_) { |
| 617 | ExtractSessionInfo(); |
| 618 | ExtractVoiceInfo(); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 619 | ExtractVideoInfo(level); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 623 | StatsReport* StatsCollector::PrepareLocalReport( |
| 624 | uint32 ssrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 625 | const std::string& transport_id, |
| 626 | TrackDirection direction) { |
| 627 | const std::string ssrc_id = talk_base::ToString<uint32>(ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 628 | StatsMap::iterator it = reports_.find(StatsId( |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 629 | StatsReport::kStatsReportTypeSsrc, ssrc_id, direction)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 630 | |
| 631 | std::string track_id; |
| 632 | if (it == reports_.end()) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 633 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 634 | return NULL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 635 | } else { |
| 636 | // Keeps the old track id since we want to report the stats for inactive |
| 637 | // tracks. |
| 638 | ExtractValueFromReport(it->second, |
| 639 | StatsReport::kStatsValueNameTrackId, |
| 640 | &track_id); |
| 641 | } |
| 642 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 643 | StatsReport* report = GetOrCreateReport(StatsReport::kStatsReportTypeSsrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 644 | ssrc_id, direction); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 645 | |
| 646 | // Clear out stats from previous GatherStats calls if any. |
| 647 | if (report->timestamp != stats_gathering_started_) { |
| 648 | report->values.clear(); |
| 649 | report->timestamp = stats_gathering_started_; |
| 650 | } |
| 651 | |
| 652 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 653 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 654 | // Add the mapping of SSRC to transport. |
| 655 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 656 | transport_id); |
| 657 | return report; |
| 658 | } |
| 659 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 660 | StatsReport* StatsCollector::PrepareRemoteReport( |
| 661 | uint32 ssrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 662 | const std::string& transport_id, |
| 663 | TrackDirection direction) { |
| 664 | const std::string ssrc_id = talk_base::ToString<uint32>(ssrc); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 665 | StatsMap::iterator it = reports_.find(StatsId( |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 666 | StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id, direction)); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 667 | |
| 668 | std::string track_id; |
| 669 | if (it == reports_.end()) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 670 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 671 | return NULL; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 672 | } else { |
| 673 | // Keeps the old track id since we want to report the stats for inactive |
| 674 | // tracks. |
| 675 | ExtractValueFromReport(it->second, |
| 676 | StatsReport::kStatsValueNameTrackId, |
| 677 | &track_id); |
| 678 | } |
| 679 | |
| 680 | StatsReport* report = GetOrCreateReport( |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 681 | StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id, direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 682 | |
| 683 | // Clear out stats from previous GatherStats calls if any. |
| 684 | // The timestamp will be added later. Zero it for debugging. |
| 685 | report->values.clear(); |
| 686 | report->timestamp = 0; |
| 687 | |
| 688 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 689 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 690 | // Add the mapping of SSRC to transport. |
| 691 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 692 | transport_id); |
| 693 | return report; |
| 694 | } |
| 695 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 696 | std::string StatsCollector::AddOneCertificateReport( |
| 697 | const talk_base::SSLCertificate* cert, const std::string& issuer_id) { |
| 698 | // TODO(bemasc): Move this computation to a helper class that caches these |
| 699 | // values to reduce CPU use in GetStats. This will require adding a fast |
| 700 | // SSLCertificate::Equals() method to detect certificate changes. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 701 | |
| 702 | std::string digest_algorithm; |
| 703 | if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) |
| 704 | return std::string(); |
| 705 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 706 | talk_base::scoped_ptr<talk_base::SSLFingerprint> ssl_fingerprint( |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 707 | talk_base::SSLFingerprint::Create(digest_algorithm, cert)); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 708 | |
| 709 | // SSLFingerprint::Create can fail if the algorithm returned by |
| 710 | // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the |
| 711 | // implementation of SSLCertificate::ComputeDigest. This currently happens |
| 712 | // with MD5- and SHA-224-signed certificates when linked to libNSS. |
| 713 | if (!ssl_fingerprint) |
| 714 | return std::string(); |
| 715 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 716 | std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); |
| 717 | |
| 718 | talk_base::Buffer der_buffer; |
| 719 | cert->ToDER(&der_buffer); |
| 720 | std::string der_base64; |
| 721 | talk_base::Base64::EncodeFromArray( |
| 722 | der_buffer.data(), der_buffer.length(), &der_base64); |
| 723 | |
| 724 | StatsReport report; |
| 725 | report.type = StatsReport::kStatsReportTypeCertificate; |
| 726 | report.id = StatsId(report.type, fingerprint); |
| 727 | report.timestamp = stats_gathering_started_; |
| 728 | report.AddValue(StatsReport::kStatsValueNameFingerprint, fingerprint); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 729 | report.AddValue(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 730 | digest_algorithm); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 731 | report.AddValue(StatsReport::kStatsValueNameDer, der_base64); |
| 732 | if (!issuer_id.empty()) |
| 733 | report.AddValue(StatsReport::kStatsValueNameIssuerId, issuer_id); |
| 734 | reports_[report.id] = report; |
| 735 | return report.id; |
| 736 | } |
| 737 | |
| 738 | std::string StatsCollector::AddCertificateReports( |
| 739 | const talk_base::SSLCertificate* cert) { |
| 740 | // Produces a chain of StatsReports representing this certificate and the rest |
| 741 | // of its chain, and adds those reports to |reports_|. The return value is |
| 742 | // the id of the leaf report. The provided cert must be non-null, so at least |
| 743 | // one report will always be provided and the returned string will never be |
| 744 | // empty. |
| 745 | ASSERT(cert != NULL); |
| 746 | |
| 747 | std::string issuer_id; |
| 748 | talk_base::scoped_ptr<talk_base::SSLCertChain> chain; |
| 749 | if (cert->GetChain(chain.accept())) { |
| 750 | // This loop runs in reverse, i.e. from root to leaf, so that each |
| 751 | // certificate's issuer's report ID is known before the child certificate's |
| 752 | // report is generated. The root certificate does not have an issuer ID |
| 753 | // value. |
| 754 | for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { |
| 755 | const talk_base::SSLCertificate& cert_i = chain->Get(i); |
| 756 | issuer_id = AddOneCertificateReport(&cert_i, issuer_id); |
| 757 | } |
| 758 | } |
| 759 | // Add the leaf certificate. |
| 760 | return AddOneCertificateReport(cert, issuer_id); |
| 761 | } |
| 762 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 763 | void StatsCollector::ExtractSessionInfo() { |
| 764 | // Extract information from the base session. |
| 765 | StatsReport report; |
| 766 | report.id = StatsId(StatsReport::kStatsReportTypeSession, session_->id()); |
| 767 | report.type = StatsReport::kStatsReportTypeSession; |
| 768 | report.timestamp = stats_gathering_started_; |
| 769 | report.values.clear(); |
| 770 | report.AddBoolean(StatsReport::kStatsValueNameInitiator, |
| 771 | session_->initiator()); |
| 772 | |
| 773 | reports_[report.id] = report; |
| 774 | |
| 775 | cricket::SessionStats stats; |
| 776 | if (session_->GetStats(&stats)) { |
| 777 | // Store the proxy map away for use in SSRC reporting. |
| 778 | proxy_to_transport_ = stats.proxy_to_transport; |
| 779 | |
| 780 | for (cricket::TransportStatsMap::iterator transport_iter |
| 781 | = stats.transport_stats.begin(); |
| 782 | transport_iter != stats.transport_stats.end(); ++transport_iter) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 783 | // Attempt to get a copy of the certificates from the transport and |
| 784 | // expose them in stats reports. All channels in a transport share the |
| 785 | // same local and remote certificates. |
| 786 | std::string local_cert_report_id, remote_cert_report_id; |
| 787 | cricket::Transport* transport = |
| 788 | session_->GetTransport(transport_iter->second.content_name); |
| 789 | if (transport) { |
| 790 | talk_base::scoped_ptr<talk_base::SSLIdentity> identity; |
| 791 | if (transport->GetIdentity(identity.accept())) |
| 792 | local_cert_report_id = AddCertificateReports( |
| 793 | &(identity->certificate())); |
| 794 | |
| 795 | talk_base::scoped_ptr<talk_base::SSLCertificate> cert; |
| 796 | if (transport->GetRemoteCertificate(cert.accept())) |
| 797 | remote_cert_report_id = AddCertificateReports(cert.get()); |
| 798 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 799 | for (cricket::TransportChannelStatsList::iterator channel_iter |
| 800 | = transport_iter->second.channel_stats.begin(); |
| 801 | channel_iter != transport_iter->second.channel_stats.end(); |
| 802 | ++channel_iter) { |
| 803 | StatsReport channel_report; |
| 804 | std::ostringstream ostc; |
| 805 | ostc << "Channel-" << transport_iter->second.content_name |
| 806 | << "-" << channel_iter->component; |
| 807 | channel_report.id = ostc.str(); |
| 808 | channel_report.type = StatsReport::kStatsReportTypeComponent; |
| 809 | channel_report.timestamp = stats_gathering_started_; |
| 810 | channel_report.AddValue(StatsReport::kStatsValueNameComponent, |
| 811 | channel_iter->component); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 812 | if (!local_cert_report_id.empty()) |
| 813 | channel_report.AddValue( |
| 814 | StatsReport::kStatsValueNameLocalCertificateId, |
| 815 | local_cert_report_id); |
| 816 | if (!remote_cert_report_id.empty()) |
| 817 | channel_report.AddValue( |
| 818 | StatsReport::kStatsValueNameRemoteCertificateId, |
| 819 | remote_cert_report_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 820 | reports_[channel_report.id] = channel_report; |
| 821 | for (size_t i = 0; |
| 822 | i < channel_iter->connection_infos.size(); |
| 823 | ++i) { |
| 824 | StatsReport report; |
| 825 | const cricket::ConnectionInfo& info |
| 826 | = channel_iter->connection_infos[i]; |
| 827 | std::ostringstream ost; |
| 828 | ost << "Conn-" << transport_iter->first << "-" |
| 829 | << channel_iter->component << "-" << i; |
| 830 | report.id = ost.str(); |
| 831 | report.type = StatsReport::kStatsReportTypeCandidatePair; |
| 832 | report.timestamp = stats_gathering_started_; |
| 833 | // Link from connection to its containing channel. |
| 834 | report.AddValue(StatsReport::kStatsValueNameChannelId, |
| 835 | channel_report.id); |
| 836 | report.AddValue(StatsReport::kStatsValueNameBytesSent, |
| 837 | info.sent_total_bytes); |
| 838 | report.AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 839 | info.recv_total_bytes); |
| 840 | report.AddBoolean(StatsReport::kStatsValueNameWritable, |
| 841 | info.writable); |
| 842 | report.AddBoolean(StatsReport::kStatsValueNameReadable, |
| 843 | info.readable); |
| 844 | report.AddBoolean(StatsReport::kStatsValueNameActiveConnection, |
| 845 | info.best_connection); |
| 846 | report.AddValue(StatsReport::kStatsValueNameLocalAddress, |
| 847 | info.local_candidate.address().ToString()); |
| 848 | report.AddValue(StatsReport::kStatsValueNameRemoteAddress, |
| 849 | info.remote_candidate.address().ToString()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 850 | report.AddValue(StatsReport::kStatsValueNameRtt, info.rtt); |
| 851 | report.AddValue(StatsReport::kStatsValueNameTransportType, |
| 852 | info.local_candidate.protocol()); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 853 | report.AddValue(StatsReport::kStatsValueNameLocalCandidateType, |
| 854 | info.local_candidate.type()); |
| 855 | report.AddValue(StatsReport::kStatsValueNameRemoteCandidateType, |
| 856 | info.remote_candidate.type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 857 | reports_[report.id] = report; |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | void StatsCollector::ExtractVoiceInfo() { |
| 865 | if (!session_->voice_channel()) { |
| 866 | return; |
| 867 | } |
| 868 | cricket::VoiceMediaInfo voice_info; |
| 869 | if (!session_->voice_channel()->GetStats(&voice_info)) { |
| 870 | LOG(LS_ERROR) << "Failed to get voice channel stats."; |
| 871 | return; |
| 872 | } |
| 873 | std::string transport_id; |
| 874 | if (!GetTransportIdFromProxy(session_->voice_channel()->content_name(), |
| 875 | &transport_id)) { |
| 876 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 877 | << session_->voice_channel()->content_name(); |
| 878 | return; |
| 879 | } |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 880 | ExtractStatsFromList(voice_info.receivers, transport_id, this, kReceiving); |
| 881 | ExtractStatsFromList(voice_info.senders, transport_id, this, kSending); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 882 | |
| 883 | UpdateStatsFromExistingLocalAudioTracks(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 884 | } |
| 885 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 886 | void StatsCollector::ExtractVideoInfo( |
| 887 | PeerConnectionInterface::StatsOutputLevel level) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 888 | if (!session_->video_channel()) { |
| 889 | return; |
| 890 | } |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 891 | cricket::StatsOptions options; |
| 892 | options.include_received_propagation_stats = |
| 893 | (level >= PeerConnectionInterface::kStatsOutputLevelDebug) ? |
| 894 | true : false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 895 | cricket::VideoMediaInfo video_info; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 896 | if (!session_->video_channel()->GetStats(options, &video_info)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 897 | LOG(LS_ERROR) << "Failed to get video channel stats."; |
| 898 | return; |
| 899 | } |
| 900 | std::string transport_id; |
| 901 | if (!GetTransportIdFromProxy(session_->video_channel()->content_name(), |
| 902 | &transport_id)) { |
| 903 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 904 | << session_->video_channel()->content_name(); |
| 905 | return; |
| 906 | } |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 907 | ExtractStatsFromList(video_info.receivers, transport_id, this, kReceiving); |
| 908 | ExtractStatsFromList(video_info.senders, transport_id, this, kSending); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 909 | if (video_info.bw_estimations.size() != 1) { |
| 910 | LOG(LS_ERROR) << "BWEs count: " << video_info.bw_estimations.size(); |
| 911 | } else { |
| 912 | StatsReport* report = &reports_[StatsReport::kStatsReportVideoBweId]; |
| 913 | ExtractStats( |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 914 | video_info.bw_estimations[0], stats_gathering_started_, level, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | |
| 918 | double StatsCollector::GetTimeNow() { |
| 919 | return timing_.WallTimeNow() * talk_base::kNumMillisecsPerSec; |
| 920 | } |
| 921 | |
| 922 | bool StatsCollector::GetTransportIdFromProxy(const std::string& proxy, |
| 923 | std::string* transport) { |
| 924 | // TODO(hta): Remove handling of empty proxy name once tests do not use it. |
| 925 | if (proxy.empty()) { |
| 926 | transport->clear(); |
| 927 | return true; |
| 928 | } |
| 929 | if (proxy_to_transport_.find(proxy) == proxy_to_transport_.end()) { |
| 930 | LOG(LS_ERROR) << "No transport ID mapping for " << proxy; |
| 931 | return false; |
| 932 | } |
| 933 | std::ostringstream ost; |
| 934 | // Component 1 is always used for RTP. |
| 935 | ost << "Channel-" << proxy_to_transport_[proxy] << "-1"; |
| 936 | *transport = ost.str(); |
| 937 | return true; |
| 938 | } |
| 939 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 940 | StatsReport* StatsCollector::GetReport(const std::string& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 941 | const std::string& id, |
| 942 | TrackDirection direction) { |
| 943 | ASSERT(type == StatsReport::kStatsReportTypeSsrc || |
| 944 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
| 945 | std::string statsid = StatsId(type, id, direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 946 | StatsReport* report = NULL; |
| 947 | std::map<std::string, StatsReport>::iterator it = reports_.find(statsid); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 948 | if (it != reports_.end()) |
| 949 | report = &(it->second); |
| 950 | |
| 951 | return report; |
| 952 | } |
| 953 | |
| 954 | StatsReport* StatsCollector::GetOrCreateReport(const std::string& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 955 | const std::string& id, |
| 956 | TrackDirection direction) { |
| 957 | ASSERT(type == StatsReport::kStatsReportTypeSsrc || |
| 958 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
| 959 | StatsReport* report = GetReport(type, id, direction); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 960 | if (report == NULL) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 961 | std::string statsid = StatsId(type, id, direction); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 962 | report = &reports_[statsid]; // Create new element. |
| 963 | report->id = statsid; |
| 964 | report->type = type; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 965 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 966 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 967 | return report; |
| 968 | } |
| 969 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 970 | void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { |
| 971 | // Loop through the existing local audio tracks. |
| 972 | for (LocalAudioTrackVector::const_iterator it = local_audio_tracks_.begin(); |
| 973 | it != local_audio_tracks_.end(); ++it) { |
| 974 | AudioTrackInterface* track = it->first; |
| 975 | uint32 ssrc = it->second; |
| 976 | std::string ssrc_id = talk_base::ToString<uint32>(ssrc); |
| 977 | StatsReport* report = GetReport(StatsReport::kStatsReportTypeSsrc, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 978 | ssrc_id, |
| 979 | kSending); |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 980 | if (report == NULL) { |
| 981 | // This can happen if a local audio track is added to a stream on the |
| 982 | // fly and the report has not been set up yet. Do nothing in this case. |
| 983 | LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; |
| 984 | continue; |
| 985 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 986 | |
| 987 | // The same ssrc can be used by both local and remote audio tracks. |
| 988 | std::string track_id; |
| 989 | if (!ExtractValueFromReport(*report, |
| 990 | StatsReport::kStatsValueNameTrackId, |
| 991 | &track_id) || |
| 992 | track_id != track->id()) { |
| 993 | continue; |
| 994 | } |
| 995 | |
| 996 | UpdateReportFromAudioTrack(track, report); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, |
| 1001 | StatsReport* report) { |
| 1002 | ASSERT(track != NULL); |
| 1003 | if (report == NULL) |
| 1004 | return; |
| 1005 | |
| 1006 | int signal_level = 0; |
| 1007 | if (track->GetSignalLevel(&signal_level)) { |
| 1008 | report->ReplaceValue(StatsReport::kStatsValueNameAudioInputLevel, |
| 1009 | talk_base::ToString<int>(signal_level)); |
| 1010 | } |
| 1011 | |
| 1012 | talk_base::scoped_refptr<AudioProcessorInterface> audio_processor( |
| 1013 | track->GetAudioProcessor()); |
| 1014 | if (audio_processor.get() == NULL) |
| 1015 | return; |
| 1016 | |
| 1017 | AudioProcessorInterface::AudioProcessorStats stats; |
| 1018 | audio_processor->GetStats(&stats); |
| 1019 | report->ReplaceValue(StatsReport::kStatsValueNameTypingNoiseState, |
| 1020 | stats.typing_noise_detected ? "true" : "false"); |
| 1021 | report->ReplaceValue(StatsReport::kStatsValueNameEchoReturnLoss, |
| 1022 | talk_base::ToString<int>(stats.echo_return_loss)); |
| 1023 | report->ReplaceValue( |
| 1024 | StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
| 1025 | talk_base::ToString<int>(stats.echo_return_loss_enhancement)); |
| 1026 | report->ReplaceValue(StatsReport::kStatsValueNameEchoDelayMedian, |
| 1027 | talk_base::ToString<int>(stats.echo_delay_median_ms)); |
| 1028 | report->ReplaceValue(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
| 1029 | talk_base::ToString<float>(stats.aec_quality_min)); |
| 1030 | report->ReplaceValue(StatsReport::kStatsValueNameEchoDelayStdDev, |
| 1031 | talk_base::ToString<int>(stats.echo_delay_std_ms)); |
| 1032 | } |
| 1033 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1034 | bool StatsCollector::GetTrackIdBySsrc(uint32 ssrc, std::string* track_id, |
| 1035 | TrackDirection direction) { |
| 1036 | if (direction == kSending) { |
| 1037 | if (!session()->GetLocalTrackIdBySsrc(ssrc, track_id)) { |
| 1038 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 1039 | << " is not associated with a sending track"; |
| 1040 | return false; |
| 1041 | } |
| 1042 | } else { |
| 1043 | ASSERT(direction == kReceiving); |
| 1044 | if (!session()->GetRemoteTrackIdBySsrc(ssrc, track_id)) { |
| 1045 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 1046 | << " is not associated with a receiving track"; |
| 1047 | return false; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | return true; |
| 1052 | } |
| 1053 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1054 | } // namespace webrtc |