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"; |
| 50 | const char StatsReport::kStatsValueNameBucketDelay[] = "googBucketDelay"; |
| 51 | const char StatsReport::kStatsValueNameBytesReceived[] = "bytesReceived"; |
| 52 | const char StatsReport::kStatsValueNameBytesSent[] = "bytesSent"; |
| 53 | const char StatsReport::kStatsValueNameChannelId[] = "googChannelId"; |
| 54 | const char StatsReport::kStatsValueNameCodecName[] = "googCodecName"; |
| 55 | const char StatsReport::kStatsValueNameComponent[] = "googComponent"; |
| 56 | const char StatsReport::kStatsValueNameContentName[] = "googContentName"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 57 | const char StatsReport::kStatsValueNameDer[] = "googDerBase64"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | // Echo metrics from the audio processing module. |
| 59 | const char StatsReport::kStatsValueNameEchoCancellationQualityMin[] = |
| 60 | "googEchoCancellationQualityMin"; |
| 61 | const char StatsReport::kStatsValueNameEchoDelayMedian[] = |
| 62 | "googEchoCancellationEchoDelayMedian"; |
| 63 | const char StatsReport::kStatsValueNameEchoDelayStdDev[] = |
| 64 | "googEchoCancellationEchoDelayStdDev"; |
| 65 | const char StatsReport::kStatsValueNameEchoReturnLoss[] = |
| 66 | "googEchoCancellationReturnLoss"; |
| 67 | const char StatsReport::kStatsValueNameEchoReturnLossEnhancement[] = |
| 68 | "googEchoCancellationReturnLossEnhancement"; |
| 69 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 70 | const char StatsReport::kStatsValueNameFingerprint[] = "googFingerprint"; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 71 | const char StatsReport::kStatsValueNameFingerprintAlgorithm[] = |
| 72 | "googFingerprintAlgorithm"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | const char StatsReport::kStatsValueNameFirsReceived[] = "googFirsReceived"; |
| 74 | const char StatsReport::kStatsValueNameFirsSent[] = "googFirsSent"; |
| 75 | const char StatsReport::kStatsValueNameFrameHeightReceived[] = |
| 76 | "googFrameHeightReceived"; |
| 77 | const char StatsReport::kStatsValueNameFrameHeightSent[] = |
| 78 | "googFrameHeightSent"; |
| 79 | const char StatsReport::kStatsValueNameFrameRateReceived[] = |
| 80 | "googFrameRateReceived"; |
| 81 | const char StatsReport::kStatsValueNameFrameRateDecoded[] = |
| 82 | "googFrameRateDecoded"; |
| 83 | const char StatsReport::kStatsValueNameFrameRateOutput[] = |
| 84 | "googFrameRateOutput"; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 85 | const char StatsReport::kStatsValueNameDecodeMs[] = "googDecodeMs"; |
| 86 | const char StatsReport::kStatsValueNameMaxDecodeMs[] = "googMaxDecodeMs"; |
| 87 | const char StatsReport::kStatsValueNameCurrentDelayMs[] = "googCurrentDelayMs"; |
| 88 | const char StatsReport::kStatsValueNameTargetDelayMs[] = "googTargetDelayMs"; |
| 89 | const char StatsReport::kStatsValueNameJitterBufferMs[] = "googJitterBufferMs"; |
| 90 | const char StatsReport::kStatsValueNameMinPlayoutDelayMs[] = |
| 91 | "googMinPlayoutDelayMs"; |
| 92 | const char StatsReport::kStatsValueNameRenderDelayMs[] = "googRenderDelayMs"; |
| 93 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 94 | const char StatsReport::kStatsValueNameFrameRateInput[] = "googFrameRateInput"; |
| 95 | const char StatsReport::kStatsValueNameFrameRateSent[] = "googFrameRateSent"; |
| 96 | const char StatsReport::kStatsValueNameFrameWidthReceived[] = |
| 97 | "googFrameWidthReceived"; |
| 98 | const char StatsReport::kStatsValueNameFrameWidthSent[] = "googFrameWidthSent"; |
| 99 | const char StatsReport::kStatsValueNameInitiator[] = "googInitiator"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 100 | const char StatsReport::kStatsValueNameIssuerId[] = "googIssuerId"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | const char StatsReport::kStatsValueNameJitterReceived[] = "googJitterReceived"; |
| 102 | const char StatsReport::kStatsValueNameLocalAddress[] = "googLocalAddress"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame^] | 103 | const char StatsReport::kStatsValueNameLocalCandidateType[] = |
| 104 | "googLocalCandidateType"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 105 | const char StatsReport::kStatsValueNameLocalCertificateId[] = |
| 106 | "googLocalCertificateId"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 107 | const char StatsReport::kStatsValueNameNacksReceived[] = "googNacksReceived"; |
| 108 | const char StatsReport::kStatsValueNameNacksSent[] = "googNacksSent"; |
| 109 | const char StatsReport::kStatsValueNamePacketsReceived[] = "packetsReceived"; |
| 110 | const char StatsReport::kStatsValueNamePacketsSent[] = "packetsSent"; |
| 111 | const char StatsReport::kStatsValueNamePacketsLost[] = "packetsLost"; |
| 112 | const char StatsReport::kStatsValueNameReadable[] = "googReadable"; |
| 113 | const char StatsReport::kStatsValueNameRemoteAddress[] = "googRemoteAddress"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame^] | 114 | const char StatsReport::kStatsValueNameRemoteCandidateType[] = |
| 115 | "googRemoteCandidateType"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 116 | const char StatsReport::kStatsValueNameRemoteCertificateId[] = |
| 117 | "googRemoteCertificateId"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | const char StatsReport::kStatsValueNameRetransmitBitrate[] = |
| 119 | "googRetransmitBitrate"; |
| 120 | const char StatsReport::kStatsValueNameRtt[] = "googRtt"; |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 121 | const char StatsReport::kStatsValueNameSsrc[] = "ssrc"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | const char StatsReport::kStatsValueNameTargetEncBitrate[] = |
| 123 | "googTargetEncBitrate"; |
| 124 | const char StatsReport::kStatsValueNameTransmitBitrate[] = |
| 125 | "googTransmitBitrate"; |
| 126 | const char StatsReport::kStatsValueNameTransportId[] = "transportId"; |
| 127 | const char StatsReport::kStatsValueNameTransportType[] = "googTransportType"; |
| 128 | const char StatsReport::kStatsValueNameTrackId[] = "googTrackId"; |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 129 | const char StatsReport::kStatsValueNameTypingNoiseState[] = |
| 130 | "googTypingNoiseState"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 131 | const char StatsReport::kStatsValueNameWritable[] = "googWritable"; |
| 132 | |
| 133 | const char StatsReport::kStatsReportTypeSession[] = "googLibjingleSession"; |
| 134 | const char StatsReport::kStatsReportTypeBwe[] = "VideoBwe"; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 135 | const char StatsReport::kStatsReportTypeRemoteSsrc[] = "remoteSsrc"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | const char StatsReport::kStatsReportTypeSsrc[] = "ssrc"; |
| 137 | const char StatsReport::kStatsReportTypeTrack[] = "googTrack"; |
| 138 | const char StatsReport::kStatsReportTypeIceCandidate[] = "iceCandidate"; |
| 139 | const char StatsReport::kStatsReportTypeTransport[] = "googTransport"; |
| 140 | const char StatsReport::kStatsReportTypeComponent[] = "googComponent"; |
| 141 | const char StatsReport::kStatsReportTypeCandidatePair[] = "googCandidatePair"; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 142 | const char StatsReport::kStatsReportTypeCertificate[] = "googCertificate"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | |
| 144 | const char StatsReport::kStatsReportVideoBweId[] = "bweforvideo"; |
| 145 | |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 146 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 147 | // Implementations of functions in statstypes.h |
| 148 | void StatsReport::AddValue(const std::string& name, const std::string& value) { |
| 149 | Value temp; |
| 150 | temp.name = name; |
| 151 | temp.value = value; |
| 152 | values.push_back(temp); |
| 153 | } |
| 154 | |
| 155 | void StatsReport::AddValue(const std::string& name, int64 value) { |
| 156 | AddValue(name, talk_base::ToString<int64>(value)); |
| 157 | } |
| 158 | |
| 159 | void StatsReport::AddBoolean(const std::string& name, bool value) { |
| 160 | AddValue(name, value ? "true" : "false"); |
| 161 | } |
| 162 | |
| 163 | namespace { |
| 164 | typedef std::map<std::string, StatsReport> StatsMap; |
| 165 | |
| 166 | std::string StatsId(const std::string& type, const std::string& id) { |
| 167 | return type + "_" + id; |
| 168 | } |
| 169 | |
| 170 | bool ExtractValueFromReport( |
| 171 | const StatsReport& report, |
| 172 | const std::string& name, |
| 173 | std::string* value) { |
| 174 | StatsReport::Values::const_iterator it = report.values.begin(); |
| 175 | for (; it != report.values.end(); ++it) { |
| 176 | if (it->name == name) { |
| 177 | *value = it->value; |
| 178 | return true; |
| 179 | } |
| 180 | } |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | template <class TrackVector> |
| 185 | void CreateTrackReports(const TrackVector& tracks, StatsMap* reports) { |
| 186 | for (size_t j = 0; j < tracks.size(); ++j) { |
| 187 | webrtc::MediaStreamTrackInterface* track = tracks[j]; |
| 188 | // Adds an empty track report. |
| 189 | StatsReport report; |
| 190 | report.type = StatsReport::kStatsReportTypeTrack; |
| 191 | report.id = StatsId(StatsReport::kStatsReportTypeTrack, track->id()); |
| 192 | report.AddValue(StatsReport::kStatsValueNameTrackId, |
| 193 | track->id()); |
| 194 | (*reports)[report.id] = report; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | void ExtractStats(const cricket::VoiceReceiverInfo& info, StatsReport* report) { |
| 199 | report->AddValue(StatsReport::kStatsValueNameAudioOutputLevel, |
| 200 | info.audio_level); |
| 201 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 202 | info.bytes_rcvd); |
| 203 | report->AddValue(StatsReport::kStatsValueNameJitterReceived, |
| 204 | info.jitter_ms); |
| 205 | report->AddValue(StatsReport::kStatsValueNamePacketsReceived, |
| 206 | info.packets_rcvd); |
| 207 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 208 | info.packets_lost); |
| 209 | } |
| 210 | |
| 211 | void ExtractStats(const cricket::VoiceSenderInfo& info, StatsReport* report) { |
| 212 | report->AddValue(StatsReport::kStatsValueNameAudioInputLevel, |
| 213 | info.audio_level); |
| 214 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 215 | info.bytes_sent); |
| 216 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 217 | info.packets_sent); |
| 218 | report->AddValue(StatsReport::kStatsValueNameJitterReceived, |
| 219 | info.jitter_ms); |
| 220 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 221 | report->AddValue(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
| 222 | talk_base::ToString<float>(info.aec_quality_min)); |
| 223 | report->AddValue(StatsReport::kStatsValueNameEchoDelayMedian, |
| 224 | info.echo_delay_median_ms); |
| 225 | report->AddValue(StatsReport::kStatsValueNameEchoDelayStdDev, |
| 226 | info.echo_delay_std_ms); |
| 227 | report->AddValue(StatsReport::kStatsValueNameEchoReturnLoss, |
| 228 | info.echo_return_loss); |
| 229 | report->AddValue(StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
| 230 | info.echo_return_loss_enhancement); |
| 231 | report->AddValue(StatsReport::kStatsValueNameCodecName, info.codec_name); |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 +0000 | [diff] [blame] | 232 | report->AddBoolean(StatsReport::kStatsValueNameTypingNoiseState, |
| 233 | info.typing_noise_detected); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | void ExtractStats(const cricket::VideoReceiverInfo& info, StatsReport* report) { |
| 237 | report->AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 238 | info.bytes_rcvd); |
| 239 | report->AddValue(StatsReport::kStatsValueNamePacketsReceived, |
| 240 | info.packets_rcvd); |
| 241 | report->AddValue(StatsReport::kStatsValueNamePacketsLost, |
| 242 | info.packets_lost); |
| 243 | |
| 244 | report->AddValue(StatsReport::kStatsValueNameFirsSent, |
| 245 | info.firs_sent); |
| 246 | report->AddValue(StatsReport::kStatsValueNameNacksSent, |
| 247 | info.nacks_sent); |
| 248 | report->AddValue(StatsReport::kStatsValueNameFrameWidthReceived, |
| 249 | info.frame_width); |
| 250 | report->AddValue(StatsReport::kStatsValueNameFrameHeightReceived, |
| 251 | info.frame_height); |
| 252 | report->AddValue(StatsReport::kStatsValueNameFrameRateReceived, |
| 253 | info.framerate_rcvd); |
| 254 | report->AddValue(StatsReport::kStatsValueNameFrameRateDecoded, |
| 255 | info.framerate_decoded); |
| 256 | report->AddValue(StatsReport::kStatsValueNameFrameRateOutput, |
| 257 | info.framerate_output); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 258 | |
| 259 | report->AddValue(StatsReport::kStatsValueNameDecodeMs, |
| 260 | info.decode_ms); |
| 261 | report->AddValue(StatsReport::kStatsValueNameMaxDecodeMs, |
| 262 | info.max_decode_ms); |
| 263 | report->AddValue(StatsReport::kStatsValueNameCurrentDelayMs, |
| 264 | info.current_delay_ms); |
| 265 | report->AddValue(StatsReport::kStatsValueNameTargetDelayMs, |
| 266 | info.target_delay_ms); |
| 267 | report->AddValue(StatsReport::kStatsValueNameJitterBufferMs, |
| 268 | info.jitter_buffer_ms); |
| 269 | report->AddValue(StatsReport::kStatsValueNameMinPlayoutDelayMs, |
| 270 | info.min_playout_delay_ms); |
| 271 | report->AddValue(StatsReport::kStatsValueNameRenderDelayMs, |
| 272 | info.render_delay_ms); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void ExtractStats(const cricket::VideoSenderInfo& info, StatsReport* report) { |
| 276 | report->AddValue(StatsReport::kStatsValueNameBytesSent, |
| 277 | info.bytes_sent); |
| 278 | report->AddValue(StatsReport::kStatsValueNamePacketsSent, |
| 279 | info.packets_sent); |
| 280 | |
| 281 | report->AddValue(StatsReport::kStatsValueNameFirsReceived, |
| 282 | info.firs_rcvd); |
| 283 | report->AddValue(StatsReport::kStatsValueNameNacksReceived, |
| 284 | info.nacks_rcvd); |
| 285 | report->AddValue(StatsReport::kStatsValueNameFrameWidthSent, |
| 286 | info.frame_width); |
| 287 | report->AddValue(StatsReport::kStatsValueNameFrameHeightSent, |
| 288 | info.frame_height); |
| 289 | report->AddValue(StatsReport::kStatsValueNameFrameRateInput, |
| 290 | info.framerate_input); |
| 291 | report->AddValue(StatsReport::kStatsValueNameFrameRateSent, |
| 292 | info.framerate_sent); |
| 293 | report->AddValue(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 294 | report->AddValue(StatsReport::kStatsValueNameCodecName, info.codec_name); |
| 295 | } |
| 296 | |
| 297 | void ExtractStats(const cricket::BandwidthEstimationInfo& info, |
| 298 | double stats_gathering_started, |
| 299 | StatsReport* report) { |
| 300 | report->id = StatsReport::kStatsReportVideoBweId; |
| 301 | report->type = StatsReport::kStatsReportTypeBwe; |
| 302 | |
| 303 | // Clear out stats from previous GatherStats calls if any. |
| 304 | if (report->timestamp != stats_gathering_started) { |
| 305 | report->values.clear(); |
| 306 | report->timestamp = stats_gathering_started; |
| 307 | } |
| 308 | |
| 309 | report->AddValue(StatsReport::kStatsValueNameAvailableSendBandwidth, |
| 310 | info.available_send_bandwidth); |
| 311 | report->AddValue(StatsReport::kStatsValueNameAvailableReceiveBandwidth, |
| 312 | info.available_recv_bandwidth); |
| 313 | report->AddValue(StatsReport::kStatsValueNameTargetEncBitrate, |
| 314 | info.target_enc_bitrate); |
| 315 | report->AddValue(StatsReport::kStatsValueNameActualEncBitrate, |
| 316 | info.actual_enc_bitrate); |
| 317 | report->AddValue(StatsReport::kStatsValueNameRetransmitBitrate, |
| 318 | info.retransmit_bitrate); |
| 319 | report->AddValue(StatsReport::kStatsValueNameTransmitBitrate, |
| 320 | info.transmit_bitrate); |
| 321 | report->AddValue(StatsReport::kStatsValueNameBucketDelay, |
| 322 | info.bucket_delay); |
| 323 | } |
| 324 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 325 | void ExtractRemoteStats(const cricket::MediaSenderInfo& info, |
| 326 | StatsReport* report) { |
| 327 | report->timestamp = info.remote_stats[0].timestamp; |
| 328 | // TODO(hta): Extract some stats here. |
| 329 | } |
| 330 | |
| 331 | void ExtractRemoteStats(const cricket::MediaReceiverInfo& info, |
| 332 | StatsReport* report) { |
| 333 | report->timestamp = info.remote_stats[0].timestamp; |
| 334 | // TODO(hta): Extract some stats here. |
| 335 | } |
| 336 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 337 | uint32 ExtractSsrc(const cricket::VoiceReceiverInfo& info) { |
| 338 | return info.ssrc; |
| 339 | } |
| 340 | |
| 341 | uint32 ExtractSsrc(const cricket::VoiceSenderInfo& info) { |
| 342 | return info.ssrc; |
| 343 | } |
| 344 | |
| 345 | uint32 ExtractSsrc(const cricket::VideoReceiverInfo& info) { |
| 346 | return info.ssrcs[0]; |
| 347 | } |
| 348 | |
| 349 | uint32 ExtractSsrc(const cricket::VideoSenderInfo& info) { |
| 350 | return info.ssrcs[0]; |
| 351 | } |
| 352 | |
| 353 | // Template to extract stats from a data vector. |
| 354 | // ExtractSsrc and ExtractStats must be defined and overloaded for each type. |
| 355 | template<typename T> |
| 356 | void ExtractStatsFromList(const std::vector<T>& data, |
| 357 | const std::string& transport_id, |
| 358 | StatsCollector* collector) { |
| 359 | typename std::vector<T>::const_iterator it = data.begin(); |
| 360 | for (; it != data.end(); ++it) { |
| 361 | std::string id; |
| 362 | uint32 ssrc = ExtractSsrc(*it); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 363 | // Each object can result in 2 objects, a local and a remote object. |
| 364 | // TODO(hta): Handle the case of multiple SSRCs per object. |
| 365 | StatsReport* report = collector->PrepareLocalReport(ssrc, transport_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 366 | if (!report) { |
| 367 | continue; |
| 368 | } |
| 369 | ExtractStats(*it, report); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 370 | if (it->remote_stats.size() > 0) { |
| 371 | report = collector->PrepareRemoteReport(ssrc, transport_id); |
| 372 | if (!report) { |
| 373 | continue; |
| 374 | } |
| 375 | ExtractRemoteStats(*it, report); |
| 376 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 377 | } |
| 378 | }; |
| 379 | |
| 380 | } // namespace |
| 381 | |
| 382 | StatsCollector::StatsCollector() |
| 383 | : session_(NULL), stats_gathering_started_(0) { |
| 384 | } |
| 385 | |
| 386 | // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 387 | // to GetStats. |
| 388 | void StatsCollector::AddStream(MediaStreamInterface* stream) { |
| 389 | ASSERT(stream != NULL); |
| 390 | |
| 391 | CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), |
| 392 | &reports_); |
| 393 | CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), |
| 394 | &reports_); |
| 395 | } |
| 396 | |
| 397 | bool StatsCollector::GetStats(MediaStreamTrackInterface* track, |
| 398 | StatsReports* reports) { |
| 399 | ASSERT(reports != NULL); |
| 400 | reports->clear(); |
| 401 | |
| 402 | StatsMap::iterator it; |
| 403 | if (!track) { |
| 404 | for (it = reports_.begin(); it != reports_.end(); ++it) { |
| 405 | reports->push_back(it->second); |
| 406 | } |
| 407 | return true; |
| 408 | } |
| 409 | |
| 410 | it = reports_.find(StatsId(StatsReport::kStatsReportTypeSession, |
| 411 | session_->id())); |
| 412 | if (it != reports_.end()) { |
| 413 | reports->push_back(it->second); |
| 414 | } |
| 415 | |
| 416 | it = reports_.find(StatsId(StatsReport::kStatsReportTypeTrack, track->id())); |
| 417 | |
| 418 | if (it == reports_.end()) { |
| 419 | LOG(LS_WARNING) << "No StatsReport is available for "<< track->id(); |
| 420 | return false; |
| 421 | } |
| 422 | |
| 423 | reports->push_back(it->second); |
| 424 | |
| 425 | std::string track_id; |
| 426 | for (it = reports_.begin(); it != reports_.end(); ++it) { |
| 427 | if (it->second.type != StatsReport::kStatsReportTypeSsrc) { |
| 428 | continue; |
| 429 | } |
| 430 | if (ExtractValueFromReport(it->second, |
| 431 | StatsReport::kStatsValueNameTrackId, |
| 432 | &track_id)) { |
| 433 | if (track_id == track->id()) { |
| 434 | reports->push_back(it->second); |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | return true; |
| 440 | } |
| 441 | |
| 442 | void StatsCollector::UpdateStats() { |
| 443 | double time_now = GetTimeNow(); |
| 444 | // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of |
| 445 | // ms apart will be ignored. |
| 446 | const double kMinGatherStatsPeriod = 50; |
| 447 | if (stats_gathering_started_ + kMinGatherStatsPeriod > time_now) { |
| 448 | return; |
| 449 | } |
| 450 | stats_gathering_started_ = time_now; |
| 451 | |
| 452 | if (session_) { |
| 453 | ExtractSessionInfo(); |
| 454 | ExtractVoiceInfo(); |
| 455 | ExtractVideoInfo(); |
| 456 | } |
| 457 | } |
| 458 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 459 | StatsReport* StatsCollector::PrepareLocalReport( |
| 460 | uint32 ssrc, |
| 461 | const std::string& transport_id) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 462 | std::string ssrc_id = talk_base::ToString<uint32>(ssrc); |
| 463 | StatsMap::iterator it = reports_.find(StatsId( |
| 464 | StatsReport::kStatsReportTypeSsrc, ssrc_id)); |
| 465 | |
| 466 | std::string track_id; |
| 467 | if (it == reports_.end()) { |
| 468 | if (!session()->GetTrackIdBySsrc(ssrc, &track_id)) { |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 469 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 470 | << " is not associated with a track"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 471 | return NULL; |
| 472 | } |
| 473 | } else { |
| 474 | // Keeps the old track id since we want to report the stats for inactive |
| 475 | // tracks. |
| 476 | ExtractValueFromReport(it->second, |
| 477 | StatsReport::kStatsValueNameTrackId, |
| 478 | &track_id); |
| 479 | } |
| 480 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 481 | StatsReport* report = GetOrCreateReport(StatsReport::kStatsReportTypeSsrc, |
| 482 | ssrc_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 483 | |
| 484 | // Clear out stats from previous GatherStats calls if any. |
| 485 | if (report->timestamp != stats_gathering_started_) { |
| 486 | report->values.clear(); |
| 487 | report->timestamp = stats_gathering_started_; |
| 488 | } |
| 489 | |
| 490 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 491 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 492 | // Add the mapping of SSRC to transport. |
| 493 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 494 | transport_id); |
| 495 | return report; |
| 496 | } |
| 497 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 498 | StatsReport* StatsCollector::PrepareRemoteReport( |
| 499 | uint32 ssrc, |
| 500 | const std::string& transport_id) { |
| 501 | std::string ssrc_id = talk_base::ToString<uint32>(ssrc); |
| 502 | StatsMap::iterator it = reports_.find(StatsId( |
| 503 | StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id)); |
| 504 | |
| 505 | std::string track_id; |
| 506 | if (it == reports_.end()) { |
| 507 | if (!session()->GetTrackIdBySsrc(ssrc, &track_id)) { |
| 508 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 509 | << " is not associated with a track"; |
| 510 | return NULL; |
| 511 | } |
| 512 | } else { |
| 513 | // Keeps the old track id since we want to report the stats for inactive |
| 514 | // tracks. |
| 515 | ExtractValueFromReport(it->second, |
| 516 | StatsReport::kStatsValueNameTrackId, |
| 517 | &track_id); |
| 518 | } |
| 519 | |
| 520 | StatsReport* report = GetOrCreateReport( |
| 521 | StatsReport::kStatsReportTypeRemoteSsrc, ssrc_id); |
| 522 | |
| 523 | // Clear out stats from previous GatherStats calls if any. |
| 524 | // The timestamp will be added later. Zero it for debugging. |
| 525 | report->values.clear(); |
| 526 | report->timestamp = 0; |
| 527 | |
| 528 | report->AddValue(StatsReport::kStatsValueNameSsrc, ssrc_id); |
| 529 | report->AddValue(StatsReport::kStatsValueNameTrackId, track_id); |
| 530 | // Add the mapping of SSRC to transport. |
| 531 | report->AddValue(StatsReport::kStatsValueNameTransportId, |
| 532 | transport_id); |
| 533 | return report; |
| 534 | } |
| 535 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 536 | std::string StatsCollector::AddOneCertificateReport( |
| 537 | const talk_base::SSLCertificate* cert, const std::string& issuer_id) { |
| 538 | // TODO(bemasc): Move this computation to a helper class that caches these |
| 539 | // values to reduce CPU use in GetStats. This will require adding a fast |
| 540 | // SSLCertificate::Equals() method to detect certificate changes. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 541 | |
| 542 | std::string digest_algorithm; |
| 543 | if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) |
| 544 | return std::string(); |
| 545 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 546 | talk_base::scoped_ptr<talk_base::SSLFingerprint> ssl_fingerprint( |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 547 | talk_base::SSLFingerprint::Create(digest_algorithm, cert)); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 548 | std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); |
| 549 | |
| 550 | talk_base::Buffer der_buffer; |
| 551 | cert->ToDER(&der_buffer); |
| 552 | std::string der_base64; |
| 553 | talk_base::Base64::EncodeFromArray( |
| 554 | der_buffer.data(), der_buffer.length(), &der_base64); |
| 555 | |
| 556 | StatsReport report; |
| 557 | report.type = StatsReport::kStatsReportTypeCertificate; |
| 558 | report.id = StatsId(report.type, fingerprint); |
| 559 | report.timestamp = stats_gathering_started_; |
| 560 | report.AddValue(StatsReport::kStatsValueNameFingerprint, fingerprint); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 561 | report.AddValue(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 562 | digest_algorithm); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 563 | report.AddValue(StatsReport::kStatsValueNameDer, der_base64); |
| 564 | if (!issuer_id.empty()) |
| 565 | report.AddValue(StatsReport::kStatsValueNameIssuerId, issuer_id); |
| 566 | reports_[report.id] = report; |
| 567 | return report.id; |
| 568 | } |
| 569 | |
| 570 | std::string StatsCollector::AddCertificateReports( |
| 571 | const talk_base::SSLCertificate* cert) { |
| 572 | // Produces a chain of StatsReports representing this certificate and the rest |
| 573 | // of its chain, and adds those reports to |reports_|. The return value is |
| 574 | // the id of the leaf report. The provided cert must be non-null, so at least |
| 575 | // one report will always be provided and the returned string will never be |
| 576 | // empty. |
| 577 | ASSERT(cert != NULL); |
| 578 | |
| 579 | std::string issuer_id; |
| 580 | talk_base::scoped_ptr<talk_base::SSLCertChain> chain; |
| 581 | if (cert->GetChain(chain.accept())) { |
| 582 | // This loop runs in reverse, i.e. from root to leaf, so that each |
| 583 | // certificate's issuer's report ID is known before the child certificate's |
| 584 | // report is generated. The root certificate does not have an issuer ID |
| 585 | // value. |
| 586 | for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { |
| 587 | const talk_base::SSLCertificate& cert_i = chain->Get(i); |
| 588 | issuer_id = AddOneCertificateReport(&cert_i, issuer_id); |
| 589 | } |
| 590 | } |
| 591 | // Add the leaf certificate. |
| 592 | return AddOneCertificateReport(cert, issuer_id); |
| 593 | } |
| 594 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 595 | void StatsCollector::ExtractSessionInfo() { |
| 596 | // Extract information from the base session. |
| 597 | StatsReport report; |
| 598 | report.id = StatsId(StatsReport::kStatsReportTypeSession, session_->id()); |
| 599 | report.type = StatsReport::kStatsReportTypeSession; |
| 600 | report.timestamp = stats_gathering_started_; |
| 601 | report.values.clear(); |
| 602 | report.AddBoolean(StatsReport::kStatsValueNameInitiator, |
| 603 | session_->initiator()); |
| 604 | |
| 605 | reports_[report.id] = report; |
| 606 | |
| 607 | cricket::SessionStats stats; |
| 608 | if (session_->GetStats(&stats)) { |
| 609 | // Store the proxy map away for use in SSRC reporting. |
| 610 | proxy_to_transport_ = stats.proxy_to_transport; |
| 611 | |
| 612 | for (cricket::TransportStatsMap::iterator transport_iter |
| 613 | = stats.transport_stats.begin(); |
| 614 | transport_iter != stats.transport_stats.end(); ++transport_iter) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 615 | // Attempt to get a copy of the certificates from the transport and |
| 616 | // expose them in stats reports. All channels in a transport share the |
| 617 | // same local and remote certificates. |
| 618 | std::string local_cert_report_id, remote_cert_report_id; |
| 619 | cricket::Transport* transport = |
| 620 | session_->GetTransport(transport_iter->second.content_name); |
| 621 | if (transport) { |
| 622 | talk_base::scoped_ptr<talk_base::SSLIdentity> identity; |
| 623 | if (transport->GetIdentity(identity.accept())) |
| 624 | local_cert_report_id = AddCertificateReports( |
| 625 | &(identity->certificate())); |
| 626 | |
| 627 | talk_base::scoped_ptr<talk_base::SSLCertificate> cert; |
| 628 | if (transport->GetRemoteCertificate(cert.accept())) |
| 629 | remote_cert_report_id = AddCertificateReports(cert.get()); |
| 630 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 631 | for (cricket::TransportChannelStatsList::iterator channel_iter |
| 632 | = transport_iter->second.channel_stats.begin(); |
| 633 | channel_iter != transport_iter->second.channel_stats.end(); |
| 634 | ++channel_iter) { |
| 635 | StatsReport channel_report; |
| 636 | std::ostringstream ostc; |
| 637 | ostc << "Channel-" << transport_iter->second.content_name |
| 638 | << "-" << channel_iter->component; |
| 639 | channel_report.id = ostc.str(); |
| 640 | channel_report.type = StatsReport::kStatsReportTypeComponent; |
| 641 | channel_report.timestamp = stats_gathering_started_; |
| 642 | channel_report.AddValue(StatsReport::kStatsValueNameComponent, |
| 643 | channel_iter->component); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 644 | if (!local_cert_report_id.empty()) |
| 645 | channel_report.AddValue( |
| 646 | StatsReport::kStatsValueNameLocalCertificateId, |
| 647 | local_cert_report_id); |
| 648 | if (!remote_cert_report_id.empty()) |
| 649 | channel_report.AddValue( |
| 650 | StatsReport::kStatsValueNameRemoteCertificateId, |
| 651 | remote_cert_report_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 652 | reports_[channel_report.id] = channel_report; |
| 653 | for (size_t i = 0; |
| 654 | i < channel_iter->connection_infos.size(); |
| 655 | ++i) { |
| 656 | StatsReport report; |
| 657 | const cricket::ConnectionInfo& info |
| 658 | = channel_iter->connection_infos[i]; |
| 659 | std::ostringstream ost; |
| 660 | ost << "Conn-" << transport_iter->first << "-" |
| 661 | << channel_iter->component << "-" << i; |
| 662 | report.id = ost.str(); |
| 663 | report.type = StatsReport::kStatsReportTypeCandidatePair; |
| 664 | report.timestamp = stats_gathering_started_; |
| 665 | // Link from connection to its containing channel. |
| 666 | report.AddValue(StatsReport::kStatsValueNameChannelId, |
| 667 | channel_report.id); |
| 668 | report.AddValue(StatsReport::kStatsValueNameBytesSent, |
| 669 | info.sent_total_bytes); |
| 670 | report.AddValue(StatsReport::kStatsValueNameBytesReceived, |
| 671 | info.recv_total_bytes); |
| 672 | report.AddBoolean(StatsReport::kStatsValueNameWritable, |
| 673 | info.writable); |
| 674 | report.AddBoolean(StatsReport::kStatsValueNameReadable, |
| 675 | info.readable); |
| 676 | report.AddBoolean(StatsReport::kStatsValueNameActiveConnection, |
| 677 | info.best_connection); |
| 678 | report.AddValue(StatsReport::kStatsValueNameLocalAddress, |
| 679 | info.local_candidate.address().ToString()); |
| 680 | report.AddValue(StatsReport::kStatsValueNameRemoteAddress, |
| 681 | info.remote_candidate.address().ToString()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 682 | report.AddValue(StatsReport::kStatsValueNameRtt, info.rtt); |
| 683 | report.AddValue(StatsReport::kStatsValueNameTransportType, |
| 684 | info.local_candidate.protocol()); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame^] | 685 | report.AddValue(StatsReport::kStatsValueNameLocalCandidateType, |
| 686 | info.local_candidate.type()); |
| 687 | report.AddValue(StatsReport::kStatsValueNameRemoteCandidateType, |
| 688 | info.remote_candidate.type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 689 | reports_[report.id] = report; |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | void StatsCollector::ExtractVoiceInfo() { |
| 697 | if (!session_->voice_channel()) { |
| 698 | return; |
| 699 | } |
| 700 | cricket::VoiceMediaInfo voice_info; |
| 701 | if (!session_->voice_channel()->GetStats(&voice_info)) { |
| 702 | LOG(LS_ERROR) << "Failed to get voice channel stats."; |
| 703 | return; |
| 704 | } |
| 705 | std::string transport_id; |
| 706 | if (!GetTransportIdFromProxy(session_->voice_channel()->content_name(), |
| 707 | &transport_id)) { |
| 708 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 709 | << session_->voice_channel()->content_name(); |
| 710 | return; |
| 711 | } |
| 712 | ExtractStatsFromList(voice_info.receivers, transport_id, this); |
| 713 | ExtractStatsFromList(voice_info.senders, transport_id, this); |
| 714 | } |
| 715 | |
| 716 | void StatsCollector::ExtractVideoInfo() { |
| 717 | if (!session_->video_channel()) { |
| 718 | return; |
| 719 | } |
| 720 | cricket::VideoMediaInfo video_info; |
| 721 | if (!session_->video_channel()->GetStats(&video_info)) { |
| 722 | LOG(LS_ERROR) << "Failed to get video channel stats."; |
| 723 | return; |
| 724 | } |
| 725 | std::string transport_id; |
| 726 | if (!GetTransportIdFromProxy(session_->video_channel()->content_name(), |
| 727 | &transport_id)) { |
| 728 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
| 729 | << session_->video_channel()->content_name(); |
| 730 | return; |
| 731 | } |
| 732 | ExtractStatsFromList(video_info.receivers, transport_id, this); |
| 733 | ExtractStatsFromList(video_info.senders, transport_id, this); |
| 734 | if (video_info.bw_estimations.size() != 1) { |
| 735 | LOG(LS_ERROR) << "BWEs count: " << video_info.bw_estimations.size(); |
| 736 | } else { |
| 737 | StatsReport* report = &reports_[StatsReport::kStatsReportVideoBweId]; |
| 738 | ExtractStats( |
| 739 | video_info.bw_estimations[0], stats_gathering_started_, report); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | double StatsCollector::GetTimeNow() { |
| 744 | return timing_.WallTimeNow() * talk_base::kNumMillisecsPerSec; |
| 745 | } |
| 746 | |
| 747 | bool StatsCollector::GetTransportIdFromProxy(const std::string& proxy, |
| 748 | std::string* transport) { |
| 749 | // TODO(hta): Remove handling of empty proxy name once tests do not use it. |
| 750 | if (proxy.empty()) { |
| 751 | transport->clear(); |
| 752 | return true; |
| 753 | } |
| 754 | if (proxy_to_transport_.find(proxy) == proxy_to_transport_.end()) { |
| 755 | LOG(LS_ERROR) << "No transport ID mapping for " << proxy; |
| 756 | return false; |
| 757 | } |
| 758 | std::ostringstream ost; |
| 759 | // Component 1 is always used for RTP. |
| 760 | ost << "Channel-" << proxy_to_transport_[proxy] << "-1"; |
| 761 | *transport = ost.str(); |
| 762 | return true; |
| 763 | } |
| 764 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 765 | StatsReport* StatsCollector::GetOrCreateReport(const std::string& type, |
| 766 | const std::string& id) { |
| 767 | std::string statsid = StatsId(type, id); |
| 768 | StatsReport* report = NULL; |
| 769 | std::map<std::string, StatsReport>::iterator it = reports_.find(statsid); |
| 770 | if (it == reports_.end()) { |
| 771 | report = &reports_[statsid]; // Create new element. |
| 772 | report->id = statsid; |
| 773 | report->type = type; |
| 774 | } else { |
| 775 | report = &reports_[statsid]; |
| 776 | } |
| 777 | return report; |
| 778 | } |
| 779 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 780 | } // namespace webrtc |