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