henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #include "webrtc/api/statscollector.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
| 13 | #include <utility> |
| 14 | #include <vector> |
| 15 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 16 | #include "webrtc/api/peerconnection.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 17 | #include "webrtc/base/base64.h" |
tommi@webrtc.org | 4b89aa0 | 2015-03-16 09:52:30 +0000 | [diff] [blame] | 18 | #include "webrtc/base/checks.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 19 | #include "webrtc/base/scoped_ptr.h" |
| 20 | #include "webrtc/base/timing.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 21 | #include "webrtc/pc/channel.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 23 | using rtc::scoped_ptr; |
| 24 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 26 | namespace { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 28 | // The following is the enum RTCStatsIceCandidateType from |
| 29 | // http://w3c.github.io/webrtc-stats/#rtcstatsicecandidatetype-enum such that |
| 30 | // our stats report for ice candidate type could conform to that. |
| 31 | const char STATSREPORT_LOCAL_PORT_TYPE[] = "host"; |
| 32 | const char STATSREPORT_STUN_PORT_TYPE[] = "serverreflexive"; |
| 33 | const char STATSREPORT_PRFLX_PORT_TYPE[] = "peerreflexive"; |
| 34 | const char STATSREPORT_RELAY_PORT_TYPE[] = "relayed"; |
| 35 | |
| 36 | // Strings used by the stats collector to report adapter types. This fits the |
| 37 | // general stype of http://w3c.github.io/webrtc-stats than what |
| 38 | // AdapterTypeToString does. |
| 39 | const char* STATSREPORT_ADAPTER_TYPE_ETHERNET = "lan"; |
| 40 | const char* STATSREPORT_ADAPTER_TYPE_WIFI = "wlan"; |
| 41 | const char* STATSREPORT_ADAPTER_TYPE_WWAN = "wwan"; |
| 42 | const char* STATSREPORT_ADAPTER_TYPE_VPN = "vpn"; |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 +0000 | [diff] [blame] | 43 | const char* STATSREPORT_ADAPTER_TYPE_LOOPBACK = "loopback"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 44 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 45 | template<typename ValueType> |
| 46 | struct TypeForAdd { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 47 | const StatsReport::StatsValueName name; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 48 | const ValueType& value; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 51 | typedef TypeForAdd<bool> BoolForAdd; |
| 52 | typedef TypeForAdd<float> FloatForAdd; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 53 | typedef TypeForAdd<int64_t> Int64ForAdd; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 54 | typedef TypeForAdd<int> IntForAdd; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 55 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 56 | StatsReport::Id GetTransportIdFromProxy(const ProxyTransportMap& map, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 57 | const std::string& proxy) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 58 | RTC_DCHECK(!proxy.empty()); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 59 | auto found = map.find(proxy); |
| 60 | if (found == map.end()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 61 | return StatsReport::Id(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 62 | } |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 63 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 64 | return StatsReport::NewComponentId( |
| 65 | found->second, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
tommi@webrtc.org | 4721895 | 2014-07-15 19:22:37 +0000 | [diff] [blame] | 66 | } |
| 67 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 68 | StatsReport* AddTrackReport(StatsCollection* reports, |
| 69 | const std::string& track_id) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 70 | // Adds an empty track report. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 71 | StatsReport::Id id( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 72 | StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, track_id)); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 73 | StatsReport* report = reports->ReplaceOrAddNew(id); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 74 | report->AddString(StatsReport::kStatsValueNameTrackId, track_id); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 75 | return report; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 76 | } |
| 77 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | template <class TrackVector> |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 79 | void CreateTrackReports(const TrackVector& tracks, StatsCollection* reports, |
| 80 | TrackIdMap& track_ids) { |
| 81 | for (const auto& track : tracks) { |
| 82 | const std::string& track_id = track->id(); |
| 83 | StatsReport* report = AddTrackReport(reports, track_id); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 84 | RTC_DCHECK(report != nullptr); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 85 | track_ids[track_id] = report; |
| 86 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | } |
| 88 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 89 | void ExtractCommonSendProperties(const cricket::MediaSenderInfo& info, |
| 90 | StatsReport* report) { |
| 91 | report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name); |
| 92 | report->AddInt64(StatsReport::kStatsValueNameBytesSent, info.bytes_sent); |
| 93 | report->AddInt64(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 94 | } |
| 95 | |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 96 | void ExtractCommonReceiveProperties(const cricket::MediaReceiverInfo& info, |
| 97 | StatsReport* report) { |
| 98 | report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name); |
| 99 | } |
| 100 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 101 | void SetAudioProcessingStats(StatsReport* report, |
| 102 | bool typing_noise_detected, |
| 103 | int echo_return_loss, |
| 104 | int echo_return_loss_enhancement, |
| 105 | int echo_delay_median_ms, |
| 106 | float aec_quality_min, |
| 107 | int echo_delay_std_ms) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 108 | report->AddBoolean(StatsReport::kStatsValueNameTypingNoiseState, |
| 109 | typing_noise_detected); |
| 110 | report->AddFloat(StatsReport::kStatsValueNameEchoCancellationQualityMin, |
| 111 | aec_quality_min); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 112 | const IntForAdd ints[] = { |
| 113 | { StatsReport::kStatsValueNameEchoReturnLoss, echo_return_loss }, |
| 114 | { StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
| 115 | echo_return_loss_enhancement }, |
| 116 | { StatsReport::kStatsValueNameEchoDelayMedian, echo_delay_median_ms }, |
| 117 | { StatsReport::kStatsValueNameEchoDelayStdDev, echo_delay_std_ms }, |
| 118 | }; |
| 119 | for (const auto& i : ints) |
| 120 | report->AddInt(i.name, i.value); |
| 121 | } |
| 122 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | void ExtractStats(const cricket::VoiceReceiverInfo& info, StatsReport* report) { |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 124 | ExtractCommonReceiveProperties(info, report); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 125 | const FloatForAdd floats[] = { |
| 126 | { StatsReport::kStatsValueNameExpandRate, info.expand_rate }, |
| 127 | { StatsReport::kStatsValueNameSecondaryDecodedRate, |
| 128 | info.secondary_decoded_rate }, |
| 129 | { StatsReport::kStatsValueNameSpeechExpandRate, info.speech_expand_rate }, |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 130 | { StatsReport::kStatsValueNameAccelerateRate, info.accelerate_rate }, |
| 131 | { StatsReport::kStatsValueNamePreemptiveExpandRate, |
| 132 | info.preemptive_expand_rate }, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | const IntForAdd ints[] = { |
| 136 | { StatsReport::kStatsValueNameAudioOutputLevel, info.audio_level }, |
| 137 | { StatsReport::kStatsValueNameCurrentDelayMs, info.delay_estimate_ms }, |
| 138 | { StatsReport::kStatsValueNameDecodingCNG, info.decoding_cng }, |
| 139 | { StatsReport::kStatsValueNameDecodingCTN, info.decoding_calls_to_neteq }, |
| 140 | { StatsReport::kStatsValueNameDecodingCTSG, |
| 141 | info.decoding_calls_to_silence_generator }, |
| 142 | { StatsReport::kStatsValueNameDecodingNormal, info.decoding_normal }, |
| 143 | { StatsReport::kStatsValueNameDecodingPLC, info.decoding_plc }, |
| 144 | { StatsReport::kStatsValueNameDecodingPLCCNG, info.decoding_plc_cng }, |
| 145 | { StatsReport::kStatsValueNameJitterBufferMs, info.jitter_buffer_ms }, |
| 146 | { StatsReport::kStatsValueNameJitterReceived, info.jitter_ms }, |
| 147 | { StatsReport::kStatsValueNamePacketsLost, info.packets_lost }, |
| 148 | { StatsReport::kStatsValueNamePacketsReceived, info.packets_rcvd }, |
| 149 | { StatsReport::kStatsValueNamePreferredJitterBufferMs, |
| 150 | info.jitter_buffer_preferred_ms }, |
| 151 | }; |
| 152 | |
| 153 | for (const auto& f : floats) |
| 154 | report->AddFloat(f.name, f.value); |
| 155 | |
| 156 | for (const auto& i : ints) |
| 157 | report->AddInt(i.name, i.value); |
| 158 | |
| 159 | report->AddInt64(StatsReport::kStatsValueNameBytesReceived, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 160 | info.bytes_rcvd); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 161 | report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
buildbot@webrtc.org | b525a9d | 2014-06-03 09:42:15 +0000 | [diff] [blame] | 162 | info.capture_start_ntp_time_ms); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 163 | report->AddString(StatsReport::kStatsValueNameMediaType, "audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void ExtractStats(const cricket::VoiceSenderInfo& info, StatsReport* report) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 167 | ExtractCommonSendProperties(info, report); |
| 168 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 169 | SetAudioProcessingStats( |
| 170 | report, info.typing_noise_detected, info.echo_return_loss, |
| 171 | info.echo_return_loss_enhancement, info.echo_delay_median_ms, |
| 172 | info.aec_quality_min, info.echo_delay_std_ms); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 173 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 174 | RTC_DCHECK_GE(info.audio_level, 0); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 175 | const IntForAdd ints[] = { |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 176 | { StatsReport::kStatsValueNameAudioInputLevel, info.audio_level}, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 177 | { StatsReport::kStatsValueNameJitterReceived, info.jitter_ms }, |
| 178 | { StatsReport::kStatsValueNamePacketsLost, info.packets_lost }, |
| 179 | { StatsReport::kStatsValueNamePacketsSent, info.packets_sent }, |
| 180 | }; |
| 181 | |
| 182 | for (const auto& i : ints) |
| 183 | report->AddInt(i.name, i.value); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 184 | report->AddString(StatsReport::kStatsValueNameMediaType, "audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | void ExtractStats(const cricket::VideoReceiverInfo& info, StatsReport* report) { |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 188 | ExtractCommonReceiveProperties(info, report); |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 189 | report->AddString(StatsReport::kStatsValueNameCodecImplementationName, |
| 190 | info.decoder_implementation_name); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 191 | report->AddInt64(StatsReport::kStatsValueNameBytesReceived, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | info.bytes_rcvd); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 193 | report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
buildbot@webrtc.org | 0581f0b | 2014-05-06 21:36:31 +0000 | [diff] [blame] | 194 | info.capture_start_ntp_time_ms); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 195 | const IntForAdd ints[] = { |
| 196 | { StatsReport::kStatsValueNameCurrentDelayMs, info.current_delay_ms }, |
| 197 | { StatsReport::kStatsValueNameDecodeMs, info.decode_ms }, |
| 198 | { StatsReport::kStatsValueNameFirsSent, info.firs_sent }, |
| 199 | { StatsReport::kStatsValueNameFrameHeightReceived, info.frame_height }, |
| 200 | { StatsReport::kStatsValueNameFrameRateDecoded, info.framerate_decoded }, |
| 201 | { StatsReport::kStatsValueNameFrameRateOutput, info.framerate_output }, |
| 202 | { StatsReport::kStatsValueNameFrameRateReceived, info.framerate_rcvd }, |
| 203 | { StatsReport::kStatsValueNameFrameWidthReceived, info.frame_width }, |
| 204 | { StatsReport::kStatsValueNameJitterBufferMs, info.jitter_buffer_ms }, |
| 205 | { StatsReport::kStatsValueNameMaxDecodeMs, info.max_decode_ms }, |
| 206 | { StatsReport::kStatsValueNameMinPlayoutDelayMs, |
| 207 | info.min_playout_delay_ms }, |
| 208 | { StatsReport::kStatsValueNameNacksSent, info.nacks_sent }, |
| 209 | { StatsReport::kStatsValueNamePacketsLost, info.packets_lost }, |
| 210 | { StatsReport::kStatsValueNamePacketsReceived, info.packets_rcvd }, |
| 211 | { StatsReport::kStatsValueNamePlisSent, info.plis_sent }, |
| 212 | { StatsReport::kStatsValueNameRenderDelayMs, info.render_delay_ms }, |
| 213 | { StatsReport::kStatsValueNameTargetDelayMs, info.target_delay_ms }, |
| 214 | }; |
| 215 | |
| 216 | for (const auto& i : ints) |
| 217 | report->AddInt(i.name, i.value); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 218 | report->AddString(StatsReport::kStatsValueNameMediaType, "video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void ExtractStats(const cricket::VideoSenderInfo& info, StatsReport* report) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 222 | ExtractCommonSendProperties(info, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 223 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 224 | report->AddString(StatsReport::kStatsValueNameCodecImplementationName, |
| 225 | info.encoder_implementation_name); |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 226 | report->AddBoolean(StatsReport::kStatsValueNameBandwidthLimitedResolution, |
| 227 | (info.adapt_reason & 0x2) > 0); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 228 | report->AddBoolean(StatsReport::kStatsValueNameCpuLimitedResolution, |
| 229 | (info.adapt_reason & 0x1) > 0); |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 230 | report->AddBoolean(StatsReport::kStatsValueNameViewLimitedResolution, |
| 231 | (info.adapt_reason & 0x4) > 0); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 232 | |
| 233 | const IntForAdd ints[] = { |
| 234 | { StatsReport::kStatsValueNameAdaptationChanges, info.adapt_changes }, |
| 235 | { StatsReport::kStatsValueNameAvgEncodeMs, info.avg_encode_ms }, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 236 | { StatsReport::kStatsValueNameEncodeUsagePercent, |
| 237 | info.encode_usage_percent }, |
| 238 | { StatsReport::kStatsValueNameFirsReceived, info.firs_rcvd }, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 239 | { StatsReport::kStatsValueNameFrameHeightSent, info.send_frame_height }, |
| 240 | { StatsReport::kStatsValueNameFrameRateInput, info.framerate_input }, |
| 241 | { StatsReport::kStatsValueNameFrameRateSent, info.framerate_sent }, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 242 | { StatsReport::kStatsValueNameFrameWidthSent, info.send_frame_width }, |
| 243 | { StatsReport::kStatsValueNameNacksReceived, info.nacks_rcvd }, |
| 244 | { StatsReport::kStatsValueNamePacketsLost, info.packets_lost }, |
| 245 | { StatsReport::kStatsValueNamePacketsSent, info.packets_sent }, |
| 246 | { StatsReport::kStatsValueNamePlisReceived, info.plis_rcvd }, |
| 247 | }; |
| 248 | |
| 249 | for (const auto& i : ints) |
| 250 | report->AddInt(i.name, i.value); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 251 | report->AddString(StatsReport::kStatsValueNameMediaType, "video"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void ExtractStats(const cricket::BandwidthEstimationInfo& info, |
| 255 | double stats_gathering_started, |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 256 | PeerConnectionInterface::StatsOutputLevel level, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 257 | StatsReport* report) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 258 | RTC_DCHECK(report->type() == StatsReport::kStatsReportTypeBwe); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 259 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 260 | report->set_timestamp(stats_gathering_started); |
| 261 | const IntForAdd ints[] = { |
| 262 | { StatsReport::kStatsValueNameAvailableSendBandwidth, |
| 263 | info.available_send_bandwidth }, |
| 264 | { StatsReport::kStatsValueNameAvailableReceiveBandwidth, |
| 265 | info.available_recv_bandwidth }, |
| 266 | { StatsReport::kStatsValueNameTargetEncBitrate, info.target_enc_bitrate }, |
| 267 | { StatsReport::kStatsValueNameActualEncBitrate, info.actual_enc_bitrate }, |
| 268 | { StatsReport::kStatsValueNameRetransmitBitrate, info.retransmit_bitrate }, |
| 269 | { StatsReport::kStatsValueNameTransmitBitrate, info.transmit_bitrate }, |
| 270 | }; |
| 271 | for (const auto& i : ints) |
| 272 | report->AddInt(i.name, i.value); |
| 273 | report->AddInt64(StatsReport::kStatsValueNameBucketDelay, info.bucket_delay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | } |
| 275 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 276 | void ExtractRemoteStats(const cricket::MediaSenderInfo& info, |
| 277 | StatsReport* report) { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 278 | report->set_timestamp(info.remote_stats[0].timestamp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 279 | // TODO(hta): Extract some stats here. |
| 280 | } |
| 281 | |
| 282 | void ExtractRemoteStats(const cricket::MediaReceiverInfo& info, |
| 283 | StatsReport* report) { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 284 | report->set_timestamp(info.remote_stats[0].timestamp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 285 | // TODO(hta): Extract some stats here. |
| 286 | } |
| 287 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 288 | // Template to extract stats from a data vector. |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 289 | // In order to use the template, the functions that are called from it, |
| 290 | // ExtractStats and ExtractRemoteStats, must be defined and overloaded |
| 291 | // for each type. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 292 | template<typename T> |
| 293 | void ExtractStatsFromList(const std::vector<T>& data, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 294 | const StatsReport::Id& transport_id, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 295 | StatsCollector* collector, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 296 | StatsReport::Direction direction) { |
| 297 | for (const auto& d : data) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 298 | uint32_t ssrc = d.ssrc(); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 299 | // Each track can have stats for both local and remote objects. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 300 | // TODO(hta): Handle the case of multiple SSRCs per object. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 301 | StatsReport* report = collector->PrepareReport(true, ssrc, transport_id, |
| 302 | direction); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 303 | if (report) |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 304 | ExtractStats(d, report); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 305 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 306 | if (!d.remote_stats.empty()) { |
| 307 | report = collector->PrepareReport(false, ssrc, transport_id, direction); |
| 308 | if (report) |
| 309 | ExtractRemoteStats(d, report); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 310 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 311 | } |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 312 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 313 | |
| 314 | } // namespace |
| 315 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 316 | const char* IceCandidateTypeToStatsType(const std::string& candidate_type) { |
| 317 | if (candidate_type == cricket::LOCAL_PORT_TYPE) { |
| 318 | return STATSREPORT_LOCAL_PORT_TYPE; |
| 319 | } |
| 320 | if (candidate_type == cricket::STUN_PORT_TYPE) { |
| 321 | return STATSREPORT_STUN_PORT_TYPE; |
| 322 | } |
| 323 | if (candidate_type == cricket::PRFLX_PORT_TYPE) { |
| 324 | return STATSREPORT_PRFLX_PORT_TYPE; |
| 325 | } |
| 326 | if (candidate_type == cricket::RELAY_PORT_TYPE) { |
| 327 | return STATSREPORT_RELAY_PORT_TYPE; |
| 328 | } |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 329 | RTC_DCHECK(false); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 330 | return "unknown"; |
| 331 | } |
| 332 | |
| 333 | const char* AdapterTypeToStatsType(rtc::AdapterType type) { |
| 334 | switch (type) { |
| 335 | case rtc::ADAPTER_TYPE_UNKNOWN: |
| 336 | return "unknown"; |
| 337 | case rtc::ADAPTER_TYPE_ETHERNET: |
| 338 | return STATSREPORT_ADAPTER_TYPE_ETHERNET; |
| 339 | case rtc::ADAPTER_TYPE_WIFI: |
| 340 | return STATSREPORT_ADAPTER_TYPE_WIFI; |
| 341 | case rtc::ADAPTER_TYPE_CELLULAR: |
| 342 | return STATSREPORT_ADAPTER_TYPE_WWAN; |
| 343 | case rtc::ADAPTER_TYPE_VPN: |
| 344 | return STATSREPORT_ADAPTER_TYPE_VPN; |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 +0000 | [diff] [blame] | 345 | case rtc::ADAPTER_TYPE_LOOPBACK: |
| 346 | return STATSREPORT_ADAPTER_TYPE_LOOPBACK; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 347 | default: |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 348 | RTC_DCHECK(false); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 349 | return ""; |
| 350 | } |
| 351 | } |
| 352 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 353 | StatsCollector::StatsCollector(PeerConnection* pc) |
| 354 | : pc_(pc), stats_gathering_started_(0) { |
| 355 | RTC_DCHECK(pc_); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | StatsCollector::~StatsCollector() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 359 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 360 | } |
| 361 | |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 362 | double StatsCollector::GetTimeNow() { |
| 363 | return rtc::Timing::WallTimeNow() * rtc::kNumMillisecsPerSec; |
| 364 | } |
| 365 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 366 | // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 367 | // to GetStats. |
| 368 | void StatsCollector::AddStream(MediaStreamInterface* stream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 369 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 370 | RTC_DCHECK(stream != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 371 | |
| 372 | CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 373 | &reports_, track_ids_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 374 | CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 375 | &reports_, track_ids_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 376 | } |
| 377 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 378 | void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 379 | uint32_t ssrc) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 380 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 381 | RTC_DCHECK(audio_track != NULL); |
tommi@webrtc.org | 4b89aa0 | 2015-03-16 09:52:30 +0000 | [diff] [blame] | 382 | #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 383 | for (const auto& track : local_audio_tracks_) |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 384 | RTC_DCHECK(track.first != audio_track || track.second != ssrc); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 385 | #endif |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 386 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 387 | local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc)); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 388 | |
| 389 | // Create the kStatsReportTypeTrack report for the new track if there is no |
| 390 | // report yet. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 391 | StatsReport::Id id(StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, |
| 392 | audio_track->id())); |
| 393 | StatsReport* report = reports_.Find(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 394 | if (!report) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 395 | report = reports_.InsertNew(id); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 396 | report->AddString(StatsReport::kStatsValueNameTrackId, audio_track->id()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 397 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 401 | uint32_t ssrc) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 402 | RTC_DCHECK(audio_track != NULL); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 403 | local_audio_tracks_.erase(std::remove_if(local_audio_tracks_.begin(), |
| 404 | local_audio_tracks_.end(), |
| 405 | [audio_track, ssrc](const LocalAudioTrackVector::value_type& track) { |
| 406 | return track.first == audio_track && track.second == ssrc; |
| 407 | })); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 408 | } |
| 409 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 410 | void StatsCollector::GetStats(MediaStreamTrackInterface* track, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 411 | StatsReports* reports) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 412 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 413 | RTC_DCHECK(reports != NULL); |
| 414 | RTC_DCHECK(reports->empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 415 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 416 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 417 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 418 | if (!track) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 419 | reports->reserve(reports_.size()); |
| 420 | for (auto* r : reports_) |
| 421 | reports->push_back(r); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 422 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 423 | } |
| 424 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 425 | StatsReport* report = reports_.Find(StatsReport::NewTypedId( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 426 | StatsReport::kStatsReportTypeSession, pc_->session()->id())); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 427 | if (report) |
| 428 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 429 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 430 | report = reports_.Find(StatsReport::NewTypedId( |
| 431 | StatsReport::kStatsReportTypeTrack, track->id())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 432 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 433 | if (!report) |
| 434 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 435 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 436 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 437 | |
| 438 | std::string track_id; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 439 | for (const auto* r : reports_) { |
| 440 | if (r->type() != StatsReport::kStatsReportTypeSsrc) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 441 | continue; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 442 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 443 | const StatsReport::Value* v = |
| 444 | r->FindValue(StatsReport::kStatsValueNameTrackId); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 445 | if (v && v->string_val() == track->id()) |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 446 | reports->push_back(r); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 447 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 448 | } |
| 449 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 450 | void |
| 451 | StatsCollector::UpdateStats(PeerConnectionInterface::StatsOutputLevel level) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 452 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 453 | double time_now = GetTimeNow(); |
| 454 | // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of |
| 455 | // ms apart will be ignored. |
| 456 | const double kMinGatherStatsPeriod = 50; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 457 | if (stats_gathering_started_ != 0 && |
| 458 | stats_gathering_started_ + kMinGatherStatsPeriod > time_now) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | stats_gathering_started_ = time_now; |
| 462 | |
solenberg | 03d6d57 | 2016-03-01 12:42:03 -0800 | [diff] [blame] | 463 | // TODO(pthatcher): Merge PeerConnection and WebRtcSession so there is no |
| 464 | // pc_->session(). |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 465 | if (pc_->session()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 466 | // TODO(tommi): All of these hop over to the worker thread to fetch |
| 467 | // information. We could use an AsyncInvoker to run all of these and post |
| 468 | // the information back to the signaling thread where we can create and |
| 469 | // update stats reports. That would also clean up the threading story a bit |
| 470 | // since we'd be creating/updating the stats report objects consistently on |
| 471 | // the same thread (this class has no locks right now). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 472 | ExtractSessionInfo(); |
| 473 | ExtractVoiceInfo(); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 474 | ExtractVideoInfo(level); |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 475 | ExtractSenderInfo(); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 476 | ExtractDataInfo(); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 477 | UpdateTrackReports(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 481 | StatsReport* StatsCollector::PrepareReport( |
| 482 | bool local, |
| 483 | uint32_t ssrc, |
| 484 | const StatsReport::Id& transport_id, |
| 485 | StatsReport::Direction direction) { |
| 486 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 487 | StatsReport::Id id(StatsReport::NewIdWithDirection( |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 488 | local ? StatsReport::kStatsReportTypeSsrc |
| 489 | : StatsReport::kStatsReportTypeRemoteSsrc, |
| 490 | rtc::ToString<uint32_t>(ssrc), direction)); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 491 | StatsReport* report = reports_.Find(id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 492 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 493 | // 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] | 494 | std::string track_id; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 495 | if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 496 | if (!report) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 497 | // The ssrc is not used by any track or existing report, return NULL |
| 498 | // 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] | 499 | return NULL; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | // The ssrc is not used by any existing track. Keeps the old track id |
| 503 | // since we want to report the stats for inactive ssrc. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 504 | const StatsReport::Value* v = |
| 505 | report->FindValue(StatsReport::kStatsValueNameTrackId); |
| 506 | if (v) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 507 | track_id = v->string_val(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 508 | } |
| 509 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 510 | if (!report) |
| 511 | report = reports_.InsertNew(id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 512 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 513 | // FYI - for remote reports, the timestamp will be overwritten later. |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 514 | report->set_timestamp(stats_gathering_started_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 515 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 516 | report->AddInt64(StatsReport::kStatsValueNameSsrc, ssrc); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 517 | report->AddString(StatsReport::kStatsValueNameTrackId, track_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 518 | // Add the mapping of SSRC to transport. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 519 | report->AddId(StatsReport::kStatsValueNameTransportId, transport_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 520 | return report; |
| 521 | } |
| 522 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 523 | StatsReport* StatsCollector::AddOneCertificateReport( |
| 524 | const rtc::SSLCertificate* cert, const StatsReport* issuer) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 525 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 526 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 527 | // TODO(bemasc): Move this computation to a helper class that caches these |
| 528 | // values to reduce CPU use in GetStats. This will require adding a fast |
| 529 | // SSLCertificate::Equals() method to detect certificate changes. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 530 | |
| 531 | std::string digest_algorithm; |
| 532 | if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 533 | return nullptr; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 534 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 535 | rtc::scoped_ptr<rtc::SSLFingerprint> ssl_fingerprint( |
| 536 | rtc::SSLFingerprint::Create(digest_algorithm, cert)); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 537 | |
| 538 | // SSLFingerprint::Create can fail if the algorithm returned by |
| 539 | // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the |
| 540 | // implementation of SSLCertificate::ComputeDigest. This currently happens |
| 541 | // with MD5- and SHA-224-signed certificates when linked to libNSS. |
| 542 | if (!ssl_fingerprint) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 543 | return nullptr; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 544 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 545 | std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); |
| 546 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 547 | rtc::Buffer der_buffer; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 548 | cert->ToDER(&der_buffer); |
| 549 | std::string der_base64; |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 550 | rtc::Base64::EncodeFromArray(der_buffer.data(), der_buffer.size(), |
| 551 | &der_base64); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 552 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 553 | StatsReport::Id id(StatsReport::NewTypedId( |
| 554 | StatsReport::kStatsReportTypeCertificate, fingerprint)); |
| 555 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 556 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 557 | report->AddString(StatsReport::kStatsValueNameFingerprint, fingerprint); |
| 558 | report->AddString(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 559 | digest_algorithm); |
| 560 | report->AddString(StatsReport::kStatsValueNameDer, der_base64); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 561 | if (issuer) |
| 562 | report->AddId(StatsReport::kStatsValueNameIssuerId, issuer->id()); |
| 563 | return report; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 564 | } |
| 565 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 566 | StatsReport* StatsCollector::AddCertificateReports( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 567 | const rtc::SSLCertificate* cert) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 568 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 569 | // Produces a chain of StatsReports representing this certificate and the rest |
| 570 | // of its chain, and adds those reports to |reports_|. The return value is |
| 571 | // the id of the leaf report. The provided cert must be non-null, so at least |
| 572 | // one report will always be provided and the returned string will never be |
| 573 | // empty. |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 574 | RTC_DCHECK(cert != NULL); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 575 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 576 | StatsReport* issuer = nullptr; |
kwiberg | f5d4786 | 2016-03-15 12:53:24 -0700 | [diff] [blame] | 577 | rtc::scoped_ptr<rtc::SSLCertChain> chain = cert->GetChain(); |
| 578 | if (chain) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 579 | // This loop runs in reverse, i.e. from root to leaf, so that each |
| 580 | // certificate's issuer's report ID is known before the child certificate's |
| 581 | // report is generated. The root certificate does not have an issuer ID |
| 582 | // value. |
| 583 | for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 584 | const rtc::SSLCertificate& cert_i = chain->Get(i); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 585 | issuer = AddOneCertificateReport(&cert_i, issuer); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | // Add the leaf certificate. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 589 | return AddOneCertificateReport(cert, issuer); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 590 | } |
| 591 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 592 | StatsReport* StatsCollector::AddConnectionInfoReport( |
| 593 | const std::string& content_name, int component, int connection_id, |
| 594 | const StatsReport::Id& channel_report_id, |
| 595 | const cricket::ConnectionInfo& info) { |
| 596 | StatsReport::Id id(StatsReport::NewCandidatePairId(content_name, component, |
| 597 | connection_id)); |
| 598 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
| 599 | report->set_timestamp(stats_gathering_started_); |
| 600 | |
| 601 | const BoolForAdd bools[] = { |
Peter Thatcher | 04ac81f | 2015-09-21 11:48:28 -0700 | [diff] [blame] | 602 | {StatsReport::kStatsValueNameActiveConnection, info.best_connection}, |
| 603 | {StatsReport::kStatsValueNameReceiving, info.receiving}, |
| 604 | {StatsReport::kStatsValueNameWritable, info.writable}, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 605 | }; |
| 606 | for (const auto& b : bools) |
| 607 | report->AddBoolean(b.name, b.value); |
| 608 | |
| 609 | report->AddId(StatsReport::kStatsValueNameChannelId, channel_report_id); |
| 610 | report->AddId(StatsReport::kStatsValueNameLocalCandidateId, |
| 611 | AddCandidateReport(info.local_candidate, true)->id()); |
| 612 | report->AddId(StatsReport::kStatsValueNameRemoteCandidateId, |
| 613 | AddCandidateReport(info.remote_candidate, false)->id()); |
| 614 | |
| 615 | const Int64ForAdd int64s[] = { |
| 616 | { StatsReport::kStatsValueNameBytesReceived, info.recv_total_bytes }, |
| 617 | { StatsReport::kStatsValueNameBytesSent, info.sent_total_bytes }, |
| 618 | { StatsReport::kStatsValueNamePacketsSent, info.sent_total_packets }, |
| 619 | { StatsReport::kStatsValueNameRtt, info.rtt }, |
| 620 | { StatsReport::kStatsValueNameSendPacketsDiscarded, |
| 621 | info.sent_discarded_packets }, |
| 622 | }; |
| 623 | for (const auto& i : int64s) |
| 624 | report->AddInt64(i.name, i.value); |
| 625 | |
| 626 | report->AddString(StatsReport::kStatsValueNameLocalAddress, |
| 627 | info.local_candidate.address().ToString()); |
| 628 | report->AddString(StatsReport::kStatsValueNameLocalCandidateType, |
| 629 | info.local_candidate.type()); |
| 630 | report->AddString(StatsReport::kStatsValueNameRemoteAddress, |
| 631 | info.remote_candidate.address().ToString()); |
| 632 | report->AddString(StatsReport::kStatsValueNameRemoteCandidateType, |
| 633 | info.remote_candidate.type()); |
| 634 | report->AddString(StatsReport::kStatsValueNameTransportType, |
| 635 | info.local_candidate.protocol()); |
| 636 | |
| 637 | return report; |
| 638 | } |
| 639 | |
| 640 | StatsReport* StatsCollector::AddCandidateReport( |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 641 | const cricket::Candidate& candidate, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 642 | bool local) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 643 | StatsReport::Id id(StatsReport::NewCandidateId(local, candidate.id())); |
| 644 | StatsReport* report = reports_.Find(id); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 645 | if (!report) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 646 | report = reports_.InsertNew(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 647 | report->set_timestamp(stats_gathering_started_); |
| 648 | if (local) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 649 | report->AddString(StatsReport::kStatsValueNameCandidateNetworkType, |
| 650 | AdapterTypeToStatsType(candidate.network_type())); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 651 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 652 | report->AddString(StatsReport::kStatsValueNameCandidateIPAddress, |
| 653 | candidate.address().ipaddr().ToString()); |
| 654 | report->AddString(StatsReport::kStatsValueNameCandidatePortNumber, |
| 655 | candidate.address().PortAsString()); |
| 656 | report->AddInt(StatsReport::kStatsValueNameCandidatePriority, |
| 657 | candidate.priority()); |
| 658 | report->AddString(StatsReport::kStatsValueNameCandidateType, |
| 659 | IceCandidateTypeToStatsType(candidate.type())); |
| 660 | report->AddString(StatsReport::kStatsValueNameCandidateTransportType, |
| 661 | candidate.protocol()); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 662 | } |
| 663 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 664 | return report; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 665 | } |
| 666 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 667 | void StatsCollector::ExtractSessionInfo() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 668 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 669 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 670 | // Extract information from the base session. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 671 | StatsReport::Id id(StatsReport::NewTypedId( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 672 | StatsReport::kStatsReportTypeSession, pc_->session()->id())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 673 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 674 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 675 | report->AddBoolean(StatsReport::kStatsValueNameInitiator, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 676 | pc_->session()->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 677 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 678 | SessionStats stats; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 679 | if (!pc_->session()->GetTransportStats(&stats)) { |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 680 | return; |
| 681 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 682 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 683 | // Store the proxy map away for use in SSRC reporting. |
| 684 | // TODO(tommi): This shouldn't be necessary if we post the stats back to the |
| 685 | // signaling thread after fetching them on the worker thread, then just use |
| 686 | // the proxy map directly from the session stats. |
| 687 | // As is, if GetStats() failed, we could be using old (incorrect?) proxy |
| 688 | // data. |
| 689 | proxy_to_transport_ = stats.proxy_to_transport; |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 690 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 691 | for (const auto& transport_iter : stats.transport_stats) { |
| 692 | // Attempt to get a copy of the certificates from the transport and |
| 693 | // expose them in stats reports. All channels in a transport share the |
| 694 | // same local and remote certificates. |
| 695 | // |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 696 | StatsReport::Id local_cert_report_id, remote_cert_report_id; |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 697 | rtc::scoped_refptr<rtc::RTCCertificate> certificate; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 698 | if (pc_->session()->GetLocalCertificate( |
| 699 | transport_iter.second.transport_name, &certificate)) { |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 700 | StatsReport* r = AddCertificateReports(&(certificate->ssl_certificate())); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 701 | if (r) |
| 702 | local_cert_report_id = r->id(); |
| 703 | } |
| 704 | |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame^] | 705 | rtc::scoped_ptr<rtc::SSLCertificate> cert = |
| 706 | pc_->session()->GetRemoteSSLCertificate( |
| 707 | transport_iter.second.transport_name); |
| 708 | if (cert) { |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 709 | StatsReport* r = AddCertificateReports(cert.get()); |
| 710 | if (r) |
| 711 | remote_cert_report_id = r->id(); |
| 712 | } |
| 713 | |
| 714 | for (const auto& channel_iter : transport_iter.second.channel_stats) { |
| 715 | StatsReport::Id id(StatsReport::NewComponentId( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 716 | transport_iter.second.transport_name, channel_iter.component)); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 717 | StatsReport* channel_report = reports_.ReplaceOrAddNew(id); |
| 718 | channel_report->set_timestamp(stats_gathering_started_); |
| 719 | channel_report->AddInt(StatsReport::kStatsValueNameComponent, |
| 720 | channel_iter.component); |
| 721 | if (local_cert_report_id.get()) { |
| 722 | channel_report->AddId(StatsReport::kStatsValueNameLocalCertificateId, |
| 723 | local_cert_report_id); |
| 724 | } |
| 725 | if (remote_cert_report_id.get()) { |
| 726 | channel_report->AddId(StatsReport::kStatsValueNameRemoteCertificateId, |
| 727 | remote_cert_report_id); |
| 728 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 729 | int srtp_crypto_suite = channel_iter.srtp_crypto_suite; |
| 730 | if (srtp_crypto_suite != rtc::SRTP_INVALID_CRYPTO_SUITE && |
| 731 | rtc::SrtpCryptoSuiteToName(srtp_crypto_suite).length()) { |
| 732 | channel_report->AddString( |
| 733 | StatsReport::kStatsValueNameSrtpCipher, |
| 734 | rtc::SrtpCryptoSuiteToName(srtp_crypto_suite)); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 735 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 736 | int ssl_cipher_suite = channel_iter.ssl_cipher_suite; |
| 737 | if (ssl_cipher_suite != rtc::TLS_NULL_WITH_NULL_NULL && |
| 738 | rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite) |
| 739 | .length()) { |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 740 | channel_report->AddString( |
| 741 | StatsReport::kStatsValueNameDtlsCipher, |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 742 | rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite)); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 743 | } |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 744 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 745 | int connection_id = 0; |
| 746 | for (const cricket::ConnectionInfo& info : |
| 747 | channel_iter.connection_infos) { |
| 748 | StatsReport* connection_report = AddConnectionInfoReport( |
| 749 | transport_iter.first, channel_iter.component, connection_id++, |
| 750 | channel_report->id(), info); |
| 751 | if (info.best_connection) { |
| 752 | channel_report->AddId( |
| 753 | StatsReport::kStatsValueNameSelectedCandidatePairId, |
| 754 | connection_report->id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | void StatsCollector::ExtractVoiceInfo() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 762 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 763 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 764 | if (!pc_->session()->voice_channel()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 765 | return; |
| 766 | } |
| 767 | cricket::VoiceMediaInfo voice_info; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 768 | if (!pc_->session()->voice_channel()->GetStats(&voice_info)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 769 | LOG(LS_ERROR) << "Failed to get voice channel stats."; |
| 770 | return; |
| 771 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 772 | |
| 773 | // TODO(tommi): The above code should run on the worker thread and post the |
| 774 | // results back to the signaling thread, where we can add data to the reports. |
| 775 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 776 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 777 | StatsReport::Id transport_id(GetTransportIdFromProxy( |
| 778 | proxy_to_transport_, pc_->session()->voice_channel()->content_name())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 779 | if (!transport_id.get()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 780 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 781 | << pc_->session()->voice_channel()->content_name(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 782 | return; |
| 783 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 784 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 785 | ExtractStatsFromList(voice_info.receivers, transport_id, this, |
| 786 | StatsReport::kReceive); |
| 787 | ExtractStatsFromList(voice_info.senders, transport_id, this, |
| 788 | StatsReport::kSend); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 789 | |
| 790 | UpdateStatsFromExistingLocalAudioTracks(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 791 | } |
| 792 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 793 | void StatsCollector::ExtractVideoInfo( |
| 794 | PeerConnectionInterface::StatsOutputLevel level) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 795 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 796 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 797 | if (!pc_->session()->video_channel()) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 798 | return; |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 799 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 800 | cricket::VideoMediaInfo video_info; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 801 | if (!pc_->session()->video_channel()->GetStats(&video_info)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 802 | LOG(LS_ERROR) << "Failed to get video channel stats."; |
| 803 | return; |
| 804 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 805 | |
| 806 | // TODO(tommi): The above code should run on the worker thread and post the |
| 807 | // results back to the signaling thread, where we can add data to the reports. |
| 808 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 809 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 810 | StatsReport::Id transport_id(GetTransportIdFromProxy( |
| 811 | proxy_to_transport_, pc_->session()->video_channel()->content_name())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 812 | if (!transport_id.get()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 813 | LOG(LS_ERROR) << "Failed to get transport name for proxy " |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 814 | << pc_->session()->video_channel()->content_name(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 815 | return; |
| 816 | } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 817 | ExtractStatsFromList(video_info.receivers, transport_id, this, |
| 818 | StatsReport::kReceive); |
| 819 | ExtractStatsFromList(video_info.senders, transport_id, this, |
| 820 | StatsReport::kSend); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 821 | if (video_info.bw_estimations.size() != 1) { |
| 822 | LOG(LS_ERROR) << "BWEs count: " << video_info.bw_estimations.size(); |
| 823 | } else { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 824 | StatsReport::Id report_id(StatsReport::NewBandwidthEstimationId()); |
| 825 | StatsReport* report = reports_.FindOrAddNew(report_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 826 | ExtractStats( |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 827 | video_info.bw_estimations[0], stats_gathering_started_, level, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 831 | void StatsCollector::ExtractSenderInfo() { |
| 832 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 833 | |
| 834 | for (const auto& sender : pc_->GetSenders()) { |
| 835 | // TODO(nisse): SSRC == 0 currently means none. Delete check when |
| 836 | // that is fixed. |
| 837 | if (!sender->ssrc()) { |
| 838 | continue; |
| 839 | } |
| 840 | const rtc::scoped_refptr<MediaStreamTrackInterface> track(sender->track()); |
| 841 | if (!track || track->kind() != MediaStreamTrackInterface::kVideoKind) { |
| 842 | continue; |
| 843 | } |
| 844 | // Safe, because kind() == kVideoKind implies a subclass of |
| 845 | // VideoTrackInterface; see mediastreaminterface.h. |
| 846 | VideoTrackSourceInterface* source = |
| 847 | static_cast<VideoTrackInterface*>(track.get())->GetSource(); |
| 848 | |
| 849 | VideoTrackSourceInterface::Stats stats; |
| 850 | if (!source->GetStats(&stats)) { |
| 851 | continue; |
| 852 | } |
| 853 | const StatsReport::Id stats_id = StatsReport::NewIdWithDirection( |
| 854 | StatsReport::kStatsReportTypeSsrc, |
| 855 | rtc::ToString<uint32_t>(sender->ssrc()), StatsReport::kSend); |
| 856 | StatsReport* report = reports_.FindOrAddNew(stats_id); |
| 857 | report->AddInt(StatsReport::kStatsValueNameFrameWidthInput, |
| 858 | stats.input_width); |
| 859 | report->AddInt(StatsReport::kStatsValueNameFrameHeightInput, |
| 860 | stats.input_height); |
| 861 | } |
| 862 | } |
| 863 | |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 864 | void StatsCollector::ExtractDataInfo() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 865 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 866 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 867 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 868 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 869 | for (const auto& dc : pc_->sctp_data_channels()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 870 | StatsReport::Id id(StatsReport::NewTypedIntId( |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 871 | StatsReport::kStatsReportTypeDataChannel, dc->id())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 872 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 873 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 874 | report->AddString(StatsReport::kStatsValueNameLabel, dc->label()); |
| 875 | report->AddInt(StatsReport::kStatsValueNameDataChannelId, dc->id()); |
| 876 | report->AddString(StatsReport::kStatsValueNameProtocol, dc->protocol()); |
| 877 | report->AddString(StatsReport::kStatsValueNameState, |
| 878 | DataChannelInterface::DataStateString(dc->state())); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 882 | StatsReport* StatsCollector::GetReport(const StatsReport::StatsType& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 883 | const std::string& id, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 884 | StatsReport::Direction direction) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 885 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 886 | RTC_DCHECK(type == StatsReport::kStatsReportTypeSsrc || |
| 887 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 888 | return reports_.Find(StatsReport::NewIdWithDirection(type, id, direction)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 889 | } |
| 890 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 891 | void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 892 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 893 | // Loop through the existing local audio tracks. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 894 | for (const auto& it : local_audio_tracks_) { |
| 895 | AudioTrackInterface* track = it.first; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 896 | uint32_t ssrc = it.second; |
| 897 | StatsReport* report = |
| 898 | GetReport(StatsReport::kStatsReportTypeSsrc, |
| 899 | rtc::ToString<uint32_t>(ssrc), StatsReport::kSend); |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 900 | if (report == NULL) { |
| 901 | // This can happen if a local audio track is added to a stream on the |
| 902 | // fly and the report has not been set up yet. Do nothing in this case. |
| 903 | LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; |
| 904 | continue; |
| 905 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 906 | |
| 907 | // The same ssrc can be used by both local and remote audio tracks. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 908 | const StatsReport::Value* v = |
| 909 | report->FindValue(StatsReport::kStatsValueNameTrackId); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 910 | if (!v || v->string_val() != track->id()) |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 911 | continue; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 912 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 913 | report->set_timestamp(stats_gathering_started_); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 914 | UpdateReportFromAudioTrack(track, report); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, |
| 919 | StatsReport* report) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 920 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 921 | RTC_DCHECK(track != NULL); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 922 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 923 | // Don't overwrite report values if they're not available. |
| 924 | int signal_level; |
| 925 | if (track->GetSignalLevel(&signal_level)) { |
| 926 | RTC_DCHECK_GE(signal_level, 0); |
| 927 | report->AddInt(StatsReport::kStatsValueNameAudioInputLevel, signal_level); |
| 928 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 929 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 930 | auto audio_processor(track->GetAudioProcessor()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 931 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 932 | if (audio_processor.get()) { |
| 933 | AudioProcessorInterface::AudioProcessorStats stats; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 934 | audio_processor->GetStats(&stats); |
| 935 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 936 | SetAudioProcessingStats( |
| 937 | report, stats.typing_noise_detected, stats.echo_return_loss, |
| 938 | stats.echo_return_loss_enhancement, stats.echo_delay_median_ms, |
| 939 | stats.aec_quality_min, stats.echo_delay_std_ms); |
| 940 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 943 | bool StatsCollector::GetTrackIdBySsrc(uint32_t ssrc, |
| 944 | std::string* track_id, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 945 | StatsReport::Direction direction) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 946 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 947 | if (direction == StatsReport::kSend) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 948 | if (!pc_->session()->GetLocalTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 949 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 950 | << " is not associated with a sending track"; |
| 951 | return false; |
| 952 | } |
| 953 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 954 | RTC_DCHECK(direction == StatsReport::kReceive); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 955 | if (!pc_->session()->GetRemoteTrackIdBySsrc(ssrc, track_id)) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 956 | LOG(LS_WARNING) << "The SSRC " << ssrc |
| 957 | << " is not associated with a receiving track"; |
| 958 | return false; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | return true; |
| 963 | } |
| 964 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 965 | void StatsCollector::UpdateTrackReports() { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 966 | RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 967 | |
| 968 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 969 | |
| 970 | for (const auto& entry : track_ids_) { |
| 971 | StatsReport* report = entry.second; |
| 972 | report->set_timestamp(stats_gathering_started_); |
| 973 | } |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 974 | } |
| 975 | |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 976 | void StatsCollector::ClearUpdateStatsCacheForTest() { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 977 | stats_gathering_started_ = 0; |
| 978 | } |
| 979 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 980 | } // namespace webrtc |