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