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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "pc/stats_collector.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> |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 14 | #include <set> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | #include <utility> |
| 16 | #include <vector> |
| 17 | |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 18 | #include "absl/memory/memory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "pc/channel.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "pc/peer_connection.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "rtc_base/checks.h" |
Artem Titov | a76af0c | 2018-07-23 17:38:12 +0200 | [diff] [blame] | 22 | #include "rtc_base/third_party/base64/base64.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | namespace { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 26 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 27 | // The following is the enum RTCStatsIceCandidateType from |
| 28 | // http://w3c.github.io/webrtc-stats/#rtcstatsicecandidatetype-enum such that |
| 29 | // our stats report for ice candidate type could conform to that. |
| 30 | const char STATSREPORT_LOCAL_PORT_TYPE[] = "host"; |
| 31 | const char STATSREPORT_STUN_PORT_TYPE[] = "serverreflexive"; |
| 32 | const char STATSREPORT_PRFLX_PORT_TYPE[] = "peerreflexive"; |
| 33 | const char STATSREPORT_RELAY_PORT_TYPE[] = "relayed"; |
| 34 | |
| 35 | // Strings used by the stats collector to report adapter types. This fits the |
| 36 | // general stype of http://w3c.github.io/webrtc-stats than what |
| 37 | // AdapterTypeToString does. |
| 38 | const char* STATSREPORT_ADAPTER_TYPE_ETHERNET = "lan"; |
| 39 | const char* STATSREPORT_ADAPTER_TYPE_WIFI = "wlan"; |
| 40 | const char* STATSREPORT_ADAPTER_TYPE_WWAN = "wwan"; |
| 41 | const char* STATSREPORT_ADAPTER_TYPE_VPN = "vpn"; |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 +0000 | [diff] [blame] | 42 | const char* STATSREPORT_ADAPTER_TYPE_LOOPBACK = "loopback"; |
Qingsi Wang | 01560de | 2018-07-26 10:44:02 -0700 | [diff] [blame] | 43 | const char* STATSREPORT_ADAPTER_TYPE_WILDCARD = "wildcard"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 44 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 45 | template <typename ValueType> |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 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 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 56 | StatsReport* AddTrackReport(StatsCollection* reports, |
| 57 | const std::string& track_id) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 58 | // Adds an empty track report. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 59 | StatsReport::Id id( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 60 | StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, track_id)); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 61 | StatsReport* report = reports->ReplaceOrAddNew(id); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 62 | report->AddString(StatsReport::kStatsValueNameTrackId, track_id); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 63 | return report; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 66 | template <class Track> |
| 67 | void CreateTrackReport(const Track* track, |
| 68 | StatsCollection* reports, |
| 69 | TrackIdMap* track_ids) { |
| 70 | const std::string& track_id = track->id(); |
| 71 | StatsReport* report = AddTrackReport(reports, track_id); |
| 72 | RTC_DCHECK(report != nullptr); |
| 73 | (*track_ids)[track_id] = report; |
| 74 | } |
| 75 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | template <class TrackVector> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 77 | void CreateTrackReports(const TrackVector& tracks, |
| 78 | StatsCollection* reports, |
| 79 | TrackIdMap* track_ids) { |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 80 | for (const auto& track : tracks) { |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 81 | CreateTrackReport(track.get(), reports, track_ids); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 82 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | } |
| 84 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 85 | void ExtractCommonSendProperties(const cricket::MediaSenderInfo& info, |
| 86 | StatsReport* report) { |
| 87 | report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name); |
| 88 | report->AddInt64(StatsReport::kStatsValueNameBytesSent, info.bytes_sent); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 89 | if (info.rtt_ms >= 0) { |
| 90 | report->AddInt64(StatsReport::kStatsValueNameRtt, info.rtt_ms); |
| 91 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 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 | |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 99 | void SetAudioProcessingStats(StatsReport* report, |
| 100 | bool typing_noise_detected, |
| 101 | const AudioProcessingStats& apm_stats) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 102 | report->AddBoolean(StatsReport::kStatsValueNameTypingNoiseState, |
| 103 | typing_noise_detected); |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 104 | if (apm_stats.delay_median_ms) { |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 105 | report->AddInt(StatsReport::kStatsValueNameEchoDelayMedian, |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 106 | *apm_stats.delay_median_ms); |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 107 | } |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 108 | if (apm_stats.delay_standard_deviation_ms) { |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 109 | report->AddInt(StatsReport::kStatsValueNameEchoDelayStdDev, |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 110 | *apm_stats.delay_standard_deviation_ms); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 111 | } |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 112 | if (apm_stats.echo_return_loss) { |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 113 | report->AddInt(StatsReport::kStatsValueNameEchoReturnLoss, |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 114 | *apm_stats.echo_return_loss); |
henrik.lundin | 04a057b | 2017-01-16 23:53:59 -0800 | [diff] [blame] | 115 | } |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 116 | if (apm_stats.echo_return_loss_enhancement) { |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 117 | report->AddInt(StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 118 | *apm_stats.echo_return_loss_enhancement); |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 119 | } |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 120 | if (apm_stats.residual_echo_likelihood) { |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 121 | report->AddFloat(StatsReport::kStatsValueNameResidualEchoLikelihood, |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 122 | static_cast<float>(*apm_stats.residual_echo_likelihood)); |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 123 | } |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 124 | if (apm_stats.residual_echo_likelihood_recent_max) { |
ivoc | 4e477a1 | 2017-01-15 08:29:46 -0800 | [diff] [blame] | 125 | report->AddFloat( |
| 126 | StatsReport::kStatsValueNameResidualEchoLikelihoodRecentMax, |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 127 | static_cast<float>(*apm_stats.residual_echo_likelihood_recent_max)); |
| 128 | } |
| 129 | if (apm_stats.divergent_filter_fraction) { |
| 130 | report->AddFloat(StatsReport::kStatsValueNameAecDivergentFilterFraction, |
| 131 | static_cast<float>(*apm_stats.divergent_filter_fraction)); |
ivoc | 8c63a82 | 2016-10-21 04:10:03 -0700 | [diff] [blame] | 132 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 133 | } |
| 134 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | void ExtractStats(const cricket::VoiceReceiverInfo& info, StatsReport* report) { |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 136 | ExtractCommonReceiveProperties(info, report); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 137 | const FloatForAdd floats[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 138 | {StatsReport::kStatsValueNameExpandRate, info.expand_rate}, |
| 139 | {StatsReport::kStatsValueNameSecondaryDecodedRate, |
| 140 | info.secondary_decoded_rate}, |
| 141 | {StatsReport::kStatsValueNameSecondaryDiscardedRate, |
| 142 | info.secondary_discarded_rate}, |
| 143 | {StatsReport::kStatsValueNameSpeechExpandRate, info.speech_expand_rate}, |
| 144 | {StatsReport::kStatsValueNameAccelerateRate, info.accelerate_rate}, |
| 145 | {StatsReport::kStatsValueNamePreemptiveExpandRate, |
| 146 | info.preemptive_expand_rate}, |
| 147 | {StatsReport::kStatsValueNameTotalAudioEnergy, info.total_output_energy}, |
| 148 | {StatsReport::kStatsValueNameTotalSamplesDuration, |
| 149 | info.total_output_duration}}; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 150 | |
| 151 | const IntForAdd ints[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 152 | {StatsReport::kStatsValueNameCurrentDelayMs, info.delay_estimate_ms}, |
| 153 | {StatsReport::kStatsValueNameDecodingCNG, info.decoding_cng}, |
| 154 | {StatsReport::kStatsValueNameDecodingCTN, info.decoding_calls_to_neteq}, |
| 155 | {StatsReport::kStatsValueNameDecodingCTSG, |
| 156 | info.decoding_calls_to_silence_generator}, |
| 157 | {StatsReport::kStatsValueNameDecodingMutedOutput, |
| 158 | info.decoding_muted_output}, |
| 159 | {StatsReport::kStatsValueNameDecodingNormal, info.decoding_normal}, |
| 160 | {StatsReport::kStatsValueNameDecodingPLC, info.decoding_plc}, |
| 161 | {StatsReport::kStatsValueNameDecodingPLCCNG, info.decoding_plc_cng}, |
| 162 | {StatsReport::kStatsValueNameJitterBufferMs, info.jitter_buffer_ms}, |
| 163 | {StatsReport::kStatsValueNameJitterReceived, info.jitter_ms}, |
| 164 | {StatsReport::kStatsValueNamePacketsLost, info.packets_lost}, |
| 165 | {StatsReport::kStatsValueNamePacketsReceived, info.packets_rcvd}, |
| 166 | {StatsReport::kStatsValueNamePreferredJitterBufferMs, |
| 167 | info.jitter_buffer_preferred_ms}, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | for (const auto& f : floats) |
| 171 | report->AddFloat(f.name, f.value); |
| 172 | |
| 173 | for (const auto& i : ints) |
| 174 | report->AddInt(i.name, i.value); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 175 | if (info.audio_level >= 0) { |
| 176 | report->AddInt(StatsReport::kStatsValueNameAudioOutputLevel, |
| 177 | info.audio_level); |
| 178 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 179 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 180 | report->AddInt64(StatsReport::kStatsValueNameBytesReceived, info.bytes_rcvd); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 181 | if (info.capture_start_ntp_time_ms >= 0) { |
| 182 | report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 183 | info.capture_start_ntp_time_ms); |
| 184 | } |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 185 | report->AddString(StatsReport::kStatsValueNameMediaType, "audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void ExtractStats(const cricket::VoiceSenderInfo& info, StatsReport* report) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 189 | ExtractCommonSendProperties(info, report); |
| 190 | |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 191 | SetAudioProcessingStats(report, info.typing_noise_detected, |
| 192 | info.apm_statistics); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 193 | |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 194 | const FloatForAdd floats[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 195 | {StatsReport::kStatsValueNameTotalAudioEnergy, info.total_input_energy}, |
| 196 | {StatsReport::kStatsValueNameTotalSamplesDuration, |
| 197 | info.total_input_duration}}; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 198 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 199 | RTC_DCHECK_GE(info.audio_level, 0); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 200 | const IntForAdd ints[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 201 | {StatsReport::kStatsValueNameAudioInputLevel, info.audio_level}, |
| 202 | {StatsReport::kStatsValueNameJitterReceived, info.jitter_ms}, |
| 203 | {StatsReport::kStatsValueNamePacketsLost, info.packets_lost}, |
| 204 | {StatsReport::kStatsValueNamePacketsSent, info.packets_sent}, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 207 | for (const auto& f : floats) { |
| 208 | report->AddFloat(f.name, f.value); |
| 209 | } |
| 210 | |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 211 | for (const auto& i : ints) { |
| 212 | if (i.value >= 0) { |
| 213 | report->AddInt(i.name, i.value); |
| 214 | } |
| 215 | } |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 216 | report->AddString(StatsReport::kStatsValueNameMediaType, "audio"); |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 217 | if (info.ana_statistics.bitrate_action_counter) { |
| 218 | report->AddInt(StatsReport::kStatsValueNameAnaBitrateActionCounter, |
| 219 | *info.ana_statistics.bitrate_action_counter); |
| 220 | } |
| 221 | if (info.ana_statistics.channel_action_counter) { |
| 222 | report->AddInt(StatsReport::kStatsValueNameAnaChannelActionCounter, |
| 223 | *info.ana_statistics.channel_action_counter); |
| 224 | } |
| 225 | if (info.ana_statistics.dtx_action_counter) { |
| 226 | report->AddInt(StatsReport::kStatsValueNameAnaDtxActionCounter, |
| 227 | *info.ana_statistics.dtx_action_counter); |
| 228 | } |
| 229 | if (info.ana_statistics.fec_action_counter) { |
| 230 | report->AddInt(StatsReport::kStatsValueNameAnaFecActionCounter, |
| 231 | *info.ana_statistics.fec_action_counter); |
| 232 | } |
ivoc | 0d0b912 | 2017-09-08 13:24:21 -0700 | [diff] [blame] | 233 | if (info.ana_statistics.frame_length_increase_counter) { |
| 234 | report->AddInt(StatsReport::kStatsValueNameAnaFrameLengthIncreaseCounter, |
| 235 | *info.ana_statistics.frame_length_increase_counter); |
| 236 | } |
| 237 | if (info.ana_statistics.frame_length_decrease_counter) { |
| 238 | report->AddInt(StatsReport::kStatsValueNameAnaFrameLengthDecreaseCounter, |
| 239 | *info.ana_statistics.frame_length_decrease_counter); |
| 240 | } |
| 241 | if (info.ana_statistics.uplink_packet_loss_fraction) { |
| 242 | report->AddFloat(StatsReport::kStatsValueNameAnaUplinkPacketLossFraction, |
| 243 | *info.ana_statistics.uplink_packet_loss_fraction); |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 244 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void ExtractStats(const cricket::VideoReceiverInfo& info, StatsReport* report) { |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 248 | ExtractCommonReceiveProperties(info, report); |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 249 | report->AddString(StatsReport::kStatsValueNameCodecImplementationName, |
| 250 | info.decoder_implementation_name); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 251 | report->AddInt64(StatsReport::kStatsValueNameBytesReceived, info.bytes_rcvd); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 252 | if (info.capture_start_ntp_time_ms >= 0) { |
| 253 | report->AddInt64(StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 254 | info.capture_start_ntp_time_ms); |
| 255 | } |
Benjamin Wright | 514f084 | 2018-12-10 09:55:17 -0800 | [diff] [blame] | 256 | if (info.first_frame_received_to_decoded_ms >= 0) { |
| 257 | report->AddInt64(StatsReport::kStatsValueNameFirstFrameReceivedToDecodedMs, |
| 258 | info.first_frame_received_to_decoded_ms); |
| 259 | } |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 260 | if (info.qp_sum) |
| 261 | report->AddInt64(StatsReport::kStatsValueNameQpSum, *info.qp_sum); |
| 262 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 263 | const IntForAdd ints[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 264 | {StatsReport::kStatsValueNameCurrentDelayMs, info.current_delay_ms}, |
| 265 | {StatsReport::kStatsValueNameDecodeMs, info.decode_ms}, |
| 266 | {StatsReport::kStatsValueNameFirsSent, info.firs_sent}, |
| 267 | {StatsReport::kStatsValueNameFrameHeightReceived, info.frame_height}, |
| 268 | {StatsReport::kStatsValueNameFrameRateDecoded, info.framerate_decoded}, |
| 269 | {StatsReport::kStatsValueNameFrameRateOutput, info.framerate_output}, |
| 270 | {StatsReport::kStatsValueNameFrameRateReceived, info.framerate_rcvd}, |
| 271 | {StatsReport::kStatsValueNameFrameWidthReceived, info.frame_width}, |
| 272 | {StatsReport::kStatsValueNameJitterBufferMs, info.jitter_buffer_ms}, |
| 273 | {StatsReport::kStatsValueNameMaxDecodeMs, info.max_decode_ms}, |
| 274 | {StatsReport::kStatsValueNameMinPlayoutDelayMs, |
| 275 | info.min_playout_delay_ms}, |
| 276 | {StatsReport::kStatsValueNameNacksSent, info.nacks_sent}, |
| 277 | {StatsReport::kStatsValueNamePacketsLost, info.packets_lost}, |
| 278 | {StatsReport::kStatsValueNamePacketsReceived, info.packets_rcvd}, |
| 279 | {StatsReport::kStatsValueNamePlisSent, info.plis_sent}, |
| 280 | {StatsReport::kStatsValueNameRenderDelayMs, info.render_delay_ms}, |
| 281 | {StatsReport::kStatsValueNameTargetDelayMs, info.target_delay_ms}, |
| 282 | {StatsReport::kStatsValueNameFramesDecoded, info.frames_decoded}, |
Artem Titov | 8a3ab0e | 2018-07-27 14:52:57 +0000 | [diff] [blame] | 283 | }; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 284 | |
| 285 | for (const auto& i : ints) |
| 286 | report->AddInt(i.name, i.value); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 287 | report->AddString(StatsReport::kStatsValueNameMediaType, "video"); |
ilnik | f04afde | 2017-07-07 01:26:24 -0700 | [diff] [blame] | 288 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 289 | if (info.timing_frame_info) { |
| 290 | report->AddString(StatsReport::kStatsValueNameTimingFrameInfo, |
| 291 | info.timing_frame_info->ToString()); |
| 292 | } |
ilnik | f04afde | 2017-07-07 01:26:24 -0700 | [diff] [blame] | 293 | |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 294 | report->AddInt64(StatsReport::kStatsValueNameInterframeDelayMaxMs, |
| 295 | info.interframe_delay_max_ms); |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 296 | |
| 297 | report->AddString( |
| 298 | StatsReport::kStatsValueNameContentType, |
| 299 | webrtc::videocontenttypehelpers::ToString(info.content_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void ExtractStats(const cricket::VideoSenderInfo& info, StatsReport* report) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 303 | ExtractCommonSendProperties(info, report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 305 | report->AddString(StatsReport::kStatsValueNameCodecImplementationName, |
| 306 | info.encoder_implementation_name); |
mallinath@webrtc.org | 62451dc | 2013-12-13 12:29:34 +0000 | [diff] [blame] | 307 | report->AddBoolean(StatsReport::kStatsValueNameBandwidthLimitedResolution, |
| 308 | (info.adapt_reason & 0x2) > 0); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 309 | report->AddBoolean(StatsReport::kStatsValueNameCpuLimitedResolution, |
| 310 | (info.adapt_reason & 0x1) > 0); |
Ă…sa Persson | c3ed630 | 2017-11-16 14:04:52 +0100 | [diff] [blame] | 311 | report->AddBoolean(StatsReport::kStatsValueNameHasEnteredLowResolution, |
| 312 | info.has_entered_low_resolution); |
| 313 | |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 314 | if (info.qp_sum) |
| 315 | report->AddInt(StatsReport::kStatsValueNameQpSum, *info.qp_sum); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 316 | |
| 317 | const IntForAdd ints[] = { |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 318 | {StatsReport::kStatsValueNameAdaptationChanges, info.adapt_changes}, |
| 319 | {StatsReport::kStatsValueNameAvgEncodeMs, info.avg_encode_ms}, |
| 320 | {StatsReport::kStatsValueNameEncodeUsagePercent, |
| 321 | info.encode_usage_percent}, |
| 322 | {StatsReport::kStatsValueNameFirsReceived, info.firs_rcvd}, |
| 323 | {StatsReport::kStatsValueNameFrameHeightSent, info.send_frame_height}, |
| 324 | {StatsReport::kStatsValueNameFrameRateInput, info.framerate_input}, |
| 325 | {StatsReport::kStatsValueNameFrameRateSent, info.framerate_sent}, |
| 326 | {StatsReport::kStatsValueNameFrameWidthSent, info.send_frame_width}, |
| 327 | {StatsReport::kStatsValueNameNacksReceived, info.nacks_rcvd}, |
| 328 | {StatsReport::kStatsValueNamePacketsLost, info.packets_lost}, |
| 329 | {StatsReport::kStatsValueNamePacketsSent, info.packets_sent}, |
| 330 | {StatsReport::kStatsValueNamePlisReceived, info.plis_rcvd}, |
| 331 | {StatsReport::kStatsValueNameFramesEncoded, info.frames_encoded}, |
| 332 | {StatsReport::kStatsValueNameHugeFramesSent, info.huge_frames_sent}, |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | for (const auto& i : ints) |
| 336 | report->AddInt(i.name, i.value); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 337 | report->AddString(StatsReport::kStatsValueNameMediaType, "video"); |
ilnik | 50864a8 | 2017-09-06 12:32:35 -0700 | [diff] [blame] | 338 | report->AddString( |
| 339 | StatsReport::kStatsValueNameContentType, |
| 340 | webrtc::videocontenttypehelpers::ToString(info.content_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | void ExtractStats(const cricket::BandwidthEstimationInfo& info, |
| 344 | double stats_gathering_started, |
| 345 | StatsReport* report) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 346 | RTC_DCHECK(report->type() == StatsReport::kStatsReportTypeBwe); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 347 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 348 | report->set_timestamp(stats_gathering_started); |
| 349 | const IntForAdd ints[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 350 | {StatsReport::kStatsValueNameAvailableSendBandwidth, |
| 351 | info.available_send_bandwidth}, |
| 352 | {StatsReport::kStatsValueNameAvailableReceiveBandwidth, |
| 353 | info.available_recv_bandwidth}, |
| 354 | {StatsReport::kStatsValueNameTargetEncBitrate, info.target_enc_bitrate}, |
| 355 | {StatsReport::kStatsValueNameActualEncBitrate, info.actual_enc_bitrate}, |
| 356 | {StatsReport::kStatsValueNameRetransmitBitrate, info.retransmit_bitrate}, |
| 357 | {StatsReport::kStatsValueNameTransmitBitrate, info.transmit_bitrate}, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 358 | }; |
| 359 | for (const auto& i : ints) |
| 360 | report->AddInt(i.name, i.value); |
| 361 | report->AddInt64(StatsReport::kStatsValueNameBucketDelay, info.bucket_delay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 362 | } |
| 363 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 364 | void ExtractRemoteStats(const cricket::MediaSenderInfo& info, |
| 365 | StatsReport* report) { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 366 | report->set_timestamp(info.remote_stats[0].timestamp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 367 | // TODO(hta): Extract some stats here. |
| 368 | } |
| 369 | |
| 370 | void ExtractRemoteStats(const cricket::MediaReceiverInfo& info, |
| 371 | StatsReport* report) { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 372 | report->set_timestamp(info.remote_stats[0].timestamp); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 373 | // TODO(hta): Extract some stats here. |
| 374 | } |
| 375 | |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 376 | std::string GetTrackIdBySsrc( |
| 377 | uint32_t ssrc, |
| 378 | StatsReport::Direction direction, |
| 379 | const std::map<uint32_t, std::string>& track_id_by_ssrc) { |
| 380 | auto it = track_id_by_ssrc.find(ssrc); |
| 381 | if (it != track_id_by_ssrc.end()) { |
| 382 | return it->second; |
| 383 | } |
| 384 | if (direction == StatsReport::kReceive) { |
| 385 | // If the track ID was not found, this might be an unsignaled receive |
| 386 | // SSRC, so try looking up by the special SSRC 0. |
| 387 | it = track_id_by_ssrc.find(0); |
| 388 | if (it != track_id_by_ssrc.end()) { |
| 389 | RTC_LOG(LS_INFO) << "Assuming SSRC=" << ssrc |
| 390 | << " is an unsignalled receive stream corresponding " |
| 391 | "to the RtpReceiver with track ID \"" |
| 392 | << it->second << "\"."; |
| 393 | return it->second; |
| 394 | } |
| 395 | } |
| 396 | RTC_LOG(LS_INFO) << "Missing track ID for " |
| 397 | << (direction == StatsReport::kSend ? "send" : "recv") |
| 398 | << " SSRC=" << ssrc << "."; |
| 399 | return ""; |
| 400 | } |
| 401 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 402 | // Template to extract stats from a data vector. |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 403 | // In order to use the template, the functions that are called from it, |
| 404 | // ExtractStats and ExtractRemoteStats, must be defined and overloaded |
| 405 | // for each type. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 406 | template <typename T> |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 407 | void ExtractStatsFromList( |
| 408 | const std::vector<T>& data, |
| 409 | const StatsReport::Id& transport_id, |
| 410 | StatsCollector* collector, |
| 411 | StatsReport::Direction direction, |
| 412 | const std::map<uint32_t, std::string>& track_id_by_ssrc) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 413 | for (const auto& d : data) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 414 | uint32_t ssrc = d.ssrc(); |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 415 | std::string track_id = GetTrackIdBySsrc(ssrc, direction, track_id_by_ssrc); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 416 | // Each track can have stats for both local and remote objects. |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 417 | // TODO(hta): Handle the case of multiple SSRCs per object. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 418 | StatsReport* report = |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 419 | collector->PrepareReport(true, ssrc, track_id, transport_id, direction); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 420 | if (report) |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 421 | ExtractStats(d, report); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 422 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 423 | if (!d.remote_stats.empty()) { |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 424 | report = collector->PrepareReport(false, ssrc, track_id, transport_id, |
| 425 | direction); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 426 | if (report) |
| 427 | ExtractRemoteStats(d, report); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 428 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 429 | } |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 430 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 431 | |
| 432 | } // namespace |
| 433 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 434 | const char* IceCandidateTypeToStatsType(const std::string& candidate_type) { |
| 435 | if (candidate_type == cricket::LOCAL_PORT_TYPE) { |
| 436 | return STATSREPORT_LOCAL_PORT_TYPE; |
| 437 | } |
| 438 | if (candidate_type == cricket::STUN_PORT_TYPE) { |
| 439 | return STATSREPORT_STUN_PORT_TYPE; |
| 440 | } |
| 441 | if (candidate_type == cricket::PRFLX_PORT_TYPE) { |
| 442 | return STATSREPORT_PRFLX_PORT_TYPE; |
| 443 | } |
| 444 | if (candidate_type == cricket::RELAY_PORT_TYPE) { |
| 445 | return STATSREPORT_RELAY_PORT_TYPE; |
| 446 | } |
nisse | eb4ca4e | 2017-01-12 02:24:27 -0800 | [diff] [blame] | 447 | RTC_NOTREACHED(); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 448 | return "unknown"; |
| 449 | } |
| 450 | |
| 451 | const char* AdapterTypeToStatsType(rtc::AdapterType type) { |
| 452 | switch (type) { |
| 453 | case rtc::ADAPTER_TYPE_UNKNOWN: |
| 454 | return "unknown"; |
| 455 | case rtc::ADAPTER_TYPE_ETHERNET: |
| 456 | return STATSREPORT_ADAPTER_TYPE_ETHERNET; |
| 457 | case rtc::ADAPTER_TYPE_WIFI: |
| 458 | return STATSREPORT_ADAPTER_TYPE_WIFI; |
| 459 | case rtc::ADAPTER_TYPE_CELLULAR: |
| 460 | return STATSREPORT_ADAPTER_TYPE_WWAN; |
| 461 | case rtc::ADAPTER_TYPE_VPN: |
| 462 | return STATSREPORT_ADAPTER_TYPE_VPN; |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 +0000 | [diff] [blame] | 463 | case rtc::ADAPTER_TYPE_LOOPBACK: |
| 464 | return STATSREPORT_ADAPTER_TYPE_LOOPBACK; |
Qingsi Wang | 01560de | 2018-07-26 10:44:02 -0700 | [diff] [blame] | 465 | case rtc::ADAPTER_TYPE_ANY: |
| 466 | return STATSREPORT_ADAPTER_TYPE_WILDCARD; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 467 | default: |
nisse | eb4ca4e | 2017-01-12 02:24:27 -0800 | [diff] [blame] | 468 | RTC_NOTREACHED(); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 469 | return ""; |
| 470 | } |
| 471 | } |
| 472 | |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 473 | StatsCollector::StatsCollector(PeerConnectionInternal* pc) |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 474 | : pc_(pc), stats_gathering_started_(0) { |
| 475 | RTC_DCHECK(pc_); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | StatsCollector::~StatsCollector() { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 479 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 480 | } |
| 481 | |
nisse | cdf37a9 | 2016-09-13 23:41:47 -0700 | [diff] [blame] | 482 | // Wallclock time in ms. |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 483 | double StatsCollector::GetTimeNow() { |
Minyue Li | 656d609 | 2018-08-10 15:38:52 +0200 | [diff] [blame] | 484 | return static_cast<double>(rtc::TimeUTCMillis()); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 485 | } |
| 486 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 487 | // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 488 | // to GetStats. |
| 489 | void StatsCollector::AddStream(MediaStreamInterface* stream) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 490 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 491 | RTC_DCHECK(stream != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 492 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 493 | CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), &reports_, |
| 494 | &track_ids_); |
| 495 | CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), &reports_, |
| 496 | &track_ids_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 499 | void StatsCollector::AddTrack(MediaStreamTrackInterface* track) { |
| 500 | if (track->kind() == MediaStreamTrackInterface::kAudioKind) { |
| 501 | CreateTrackReport(static_cast<AudioTrackInterface*>(track), &reports_, |
| 502 | &track_ids_); |
| 503 | } else if (track->kind() == MediaStreamTrackInterface::kVideoKind) { |
| 504 | CreateTrackReport(static_cast<VideoTrackInterface*>(track), &reports_, |
| 505 | &track_ids_); |
| 506 | } else { |
| 507 | RTC_NOTREACHED() << "Illegal track kind"; |
| 508 | } |
| 509 | } |
| 510 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 511 | void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 512 | uint32_t ssrc) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 513 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 514 | RTC_DCHECK(audio_track != NULL); |
kwiberg | 5377bc7 | 2016-10-04 13:46:56 -0700 | [diff] [blame] | 515 | #if RTC_DCHECK_IS_ON |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 516 | for (const auto& track : local_audio_tracks_) |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 517 | RTC_DCHECK(track.first != audio_track || track.second != ssrc); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 518 | #endif |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 519 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 520 | local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc)); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 521 | |
| 522 | // Create the kStatsReportTypeTrack report for the new track if there is no |
| 523 | // report yet. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 524 | StatsReport::Id id(StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, |
| 525 | audio_track->id())); |
| 526 | StatsReport* report = reports_.Find(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 527 | if (!report) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 528 | report = reports_.InsertNew(id); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 529 | report->AddString(StatsReport::kStatsValueNameTrackId, audio_track->id()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 530 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 534 | uint32_t ssrc) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 535 | RTC_DCHECK(audio_track != NULL); |
deadbeef | 19b3a55 | 2017-06-16 20:19:08 -0700 | [diff] [blame] | 536 | local_audio_tracks_.erase( |
| 537 | std::remove_if( |
| 538 | local_audio_tracks_.begin(), local_audio_tracks_.end(), |
| 539 | [audio_track, ssrc](const LocalAudioTrackVector::value_type& track) { |
| 540 | return track.first == audio_track && track.second == ssrc; |
| 541 | }), |
| 542 | local_audio_tracks_.end()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 543 | } |
| 544 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 545 | void StatsCollector::GetStats(MediaStreamTrackInterface* track, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 546 | StatsReports* reports) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 547 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 548 | RTC_DCHECK(reports != NULL); |
| 549 | RTC_DCHECK(reports->empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 550 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 551 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 552 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 553 | if (!track) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 554 | reports->reserve(reports_.size()); |
| 555 | for (auto* r : reports_) |
| 556 | reports->push_back(r); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 557 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 558 | } |
| 559 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 560 | StatsReport* report = reports_.Find(StatsReport::NewTypedId( |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 561 | StatsReport::kStatsReportTypeSession, pc_->session_id())); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 562 | if (report) |
| 563 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 564 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 565 | report = reports_.Find( |
| 566 | StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, track->id())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 567 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 568 | if (!report) |
| 569 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 570 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 571 | reports->push_back(report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 572 | |
| 573 | std::string track_id; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 574 | for (const auto* r : reports_) { |
| 575 | if (r->type() != StatsReport::kStatsReportTypeSsrc) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 576 | continue; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 577 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 578 | const StatsReport::Value* v = |
| 579 | r->FindValue(StatsReport::kStatsValueNameTrackId); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 580 | if (v && v->string_val() == track->id()) |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 581 | reports->push_back(r); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 582 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 585 | void StatsCollector::UpdateStats( |
| 586 | PeerConnectionInterface::StatsOutputLevel level) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 587 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 588 | double time_now = GetTimeNow(); |
| 589 | // Calls to UpdateStats() that occur less than kMinGatherStatsPeriod number of |
| 590 | // ms apart will be ignored. |
| 591 | const double kMinGatherStatsPeriod = 50; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 592 | if (stats_gathering_started_ != 0 && |
| 593 | stats_gathering_started_ + kMinGatherStatsPeriod > time_now) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 594 | return; |
| 595 | } |
| 596 | stats_gathering_started_ = time_now; |
| 597 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 598 | // TODO(tommi): All of these hop over to the worker thread to fetch |
| 599 | // information. We could use an AsyncInvoker to run all of these and post |
| 600 | // the information back to the signaling thread where we can create and |
| 601 | // update stats reports. That would also clean up the threading story a bit |
| 602 | // since we'd be creating/updating the stats report objects consistently on |
| 603 | // the same thread (this class has no locks right now). |
| 604 | ExtractSessionInfo(); |
| 605 | ExtractBweInfo(); |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 606 | ExtractMediaInfo(); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 607 | ExtractSenderInfo(); |
| 608 | ExtractDataInfo(); |
| 609 | UpdateTrackReports(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 612 | StatsReport* StatsCollector::PrepareReport(bool local, |
| 613 | uint32_t ssrc, |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 614 | const std::string& track_id, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 615 | const StatsReport::Id& transport_id, |
| 616 | StatsReport::Direction direction) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 617 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 618 | StatsReport::Id id(StatsReport::NewIdWithDirection( |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 619 | local ? StatsReport::kStatsReportTypeSsrc |
| 620 | : StatsReport::kStatsReportTypeRemoteSsrc, |
Jonas Olsson | 6b1985d | 2018-07-05 11:59:48 +0200 | [diff] [blame] | 621 | rtc::ToString(ssrc), direction)); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 622 | StatsReport* report = reports_.Find(id); |
Steve Anton | a41959e | 2018-11-28 11:15:33 -0800 | [diff] [blame] | 623 | if (!report) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 624 | report = reports_.InsertNew(id); |
Steve Anton | a41959e | 2018-11-28 11:15:33 -0800 | [diff] [blame] | 625 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 626 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 627 | // FYI - for remote reports, the timestamp will be overwritten later. |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 628 | report->set_timestamp(stats_gathering_started_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 629 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 630 | report->AddInt64(StatsReport::kStatsValueNameSsrc, ssrc); |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 631 | if (!track_id.empty()) { |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 632 | report->AddString(StatsReport::kStatsValueNameTrackId, track_id); |
Taylor Brandstetter | a465344 | 2018-06-19 09:44:26 -0700 | [diff] [blame] | 633 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 634 | // Add the mapping of SSRC to transport. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 635 | report->AddId(StatsReport::kStatsValueNameTransportId, transport_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 636 | return report; |
| 637 | } |
| 638 | |
zhihuang | e9e94c3 | 2016-11-04 11:38:15 -0700 | [diff] [blame] | 639 | bool StatsCollector::IsValidTrack(const std::string& track_id) { |
| 640 | return reports_.Find(StatsReport::NewTypedId( |
| 641 | StatsReport::kStatsReportTypeTrack, track_id)) != nullptr; |
| 642 | } |
| 643 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 644 | StatsReport* StatsCollector::AddCertificateReports( |
Taylor Brandstetter | c392866 | 2018-02-23 13:04:51 -0800 | [diff] [blame] | 645 | std::unique_ptr<rtc::SSLCertificateStats> cert_stats) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 646 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 647 | |
hbos | e29352b | 2016-08-25 03:52:38 -0700 | [diff] [blame] | 648 | StatsReport* first_report = nullptr; |
| 649 | StatsReport* prev_report = nullptr; |
Taylor Brandstetter | c392866 | 2018-02-23 13:04:51 -0800 | [diff] [blame] | 650 | for (rtc::SSLCertificateStats* stats = cert_stats.get(); stats; |
hbos | e29352b | 2016-08-25 03:52:38 -0700 | [diff] [blame] | 651 | stats = stats->issuer.get()) { |
| 652 | StatsReport::Id id(StatsReport::NewTypedId( |
| 653 | StatsReport::kStatsReportTypeCertificate, stats->fingerprint)); |
| 654 | |
| 655 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
| 656 | report->set_timestamp(stats_gathering_started_); |
| 657 | report->AddString(StatsReport::kStatsValueNameFingerprint, |
| 658 | stats->fingerprint); |
| 659 | report->AddString(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 660 | stats->fingerprint_algorithm); |
| 661 | report->AddString(StatsReport::kStatsValueNameDer, |
| 662 | stats->base64_certificate); |
| 663 | if (!first_report) |
| 664 | first_report = report; |
| 665 | else |
| 666 | prev_report->AddId(StatsReport::kStatsValueNameIssuerId, id); |
| 667 | prev_report = report; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 668 | } |
hbos | e29352b | 2016-08-25 03:52:38 -0700 | [diff] [blame] | 669 | return first_report; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 670 | } |
| 671 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 672 | StatsReport* StatsCollector::AddConnectionInfoReport( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 673 | const std::string& content_name, |
| 674 | int component, |
| 675 | int connection_id, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 676 | const StatsReport::Id& channel_report_id, |
| 677 | const cricket::ConnectionInfo& info) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 678 | StatsReport::Id id( |
| 679 | StatsReport::NewCandidatePairId(content_name, component, connection_id)); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 680 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
| 681 | report->set_timestamp(stats_gathering_started_); |
| 682 | |
| 683 | const BoolForAdd bools[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 684 | {StatsReport::kStatsValueNameActiveConnection, info.best_connection}, |
| 685 | {StatsReport::kStatsValueNameReceiving, info.receiving}, |
| 686 | {StatsReport::kStatsValueNameWritable, info.writable}, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 687 | }; |
| 688 | for (const auto& b : bools) |
| 689 | report->AddBoolean(b.name, b.value); |
| 690 | |
| 691 | report->AddId(StatsReport::kStatsValueNameChannelId, channel_report_id); |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 692 | cricket::CandidateStats local_candidate_stats(info.local_candidate); |
| 693 | cricket::CandidateStats remote_candidate_stats(info.remote_candidate); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 694 | report->AddId(StatsReport::kStatsValueNameLocalCandidateId, |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 695 | AddCandidateReport(local_candidate_stats, true)->id()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 696 | report->AddId(StatsReport::kStatsValueNameRemoteCandidateId, |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 697 | AddCandidateReport(remote_candidate_stats, false)->id()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 698 | |
| 699 | const Int64ForAdd int64s[] = { |
zhihuang | 5ecf16c | 2016-06-01 17:09:15 -0700 | [diff] [blame] | 700 | {StatsReport::kStatsValueNameBytesReceived, info.recv_total_bytes}, |
| 701 | {StatsReport::kStatsValueNameBytesSent, info.sent_total_bytes}, |
| 702 | {StatsReport::kStatsValueNamePacketsSent, info.sent_total_packets}, |
| 703 | {StatsReport::kStatsValueNameRtt, info.rtt}, |
| 704 | {StatsReport::kStatsValueNameSendPacketsDiscarded, |
| 705 | info.sent_discarded_packets}, |
| 706 | {StatsReport::kStatsValueNameSentPingRequestsTotal, |
| 707 | info.sent_ping_requests_total}, |
| 708 | {StatsReport::kStatsValueNameSentPingRequestsBeforeFirstResponse, |
| 709 | info.sent_ping_requests_before_first_response}, |
| 710 | {StatsReport::kStatsValueNameSentPingResponses, info.sent_ping_responses}, |
| 711 | {StatsReport::kStatsValueNameRecvPingRequests, info.recv_ping_requests}, |
| 712 | {StatsReport::kStatsValueNameRecvPingResponses, info.recv_ping_responses}, |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 713 | }; |
| 714 | for (const auto& i : int64s) |
| 715 | report->AddInt64(i.name, i.value); |
| 716 | |
| 717 | report->AddString(StatsReport::kStatsValueNameLocalAddress, |
| 718 | info.local_candidate.address().ToString()); |
| 719 | report->AddString(StatsReport::kStatsValueNameLocalCandidateType, |
| 720 | info.local_candidate.type()); |
| 721 | report->AddString(StatsReport::kStatsValueNameRemoteAddress, |
| 722 | info.remote_candidate.address().ToString()); |
| 723 | report->AddString(StatsReport::kStatsValueNameRemoteCandidateType, |
| 724 | info.remote_candidate.type()); |
| 725 | report->AddString(StatsReport::kStatsValueNameTransportType, |
| 726 | info.local_candidate.protocol()); |
| 727 | |
| 728 | return report; |
| 729 | } |
| 730 | |
| 731 | StatsReport* StatsCollector::AddCandidateReport( |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 732 | const cricket::CandidateStats& candidate_stats, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 733 | bool local) { |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 734 | const auto& candidate = candidate_stats.candidate; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 735 | StatsReport::Id id(StatsReport::NewCandidateId(local, candidate.id())); |
| 736 | StatsReport* report = reports_.Find(id); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 737 | if (!report) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 738 | report = reports_.InsertNew(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 739 | report->set_timestamp(stats_gathering_started_); |
| 740 | if (local) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 741 | report->AddString(StatsReport::kStatsValueNameCandidateNetworkType, |
| 742 | AdapterTypeToStatsType(candidate.network_type())); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 743 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 744 | report->AddString(StatsReport::kStatsValueNameCandidateIPAddress, |
| 745 | candidate.address().ipaddr().ToString()); |
| 746 | report->AddString(StatsReport::kStatsValueNameCandidatePortNumber, |
| 747 | candidate.address().PortAsString()); |
| 748 | report->AddInt(StatsReport::kStatsValueNameCandidatePriority, |
| 749 | candidate.priority()); |
| 750 | report->AddString(StatsReport::kStatsValueNameCandidateType, |
| 751 | IceCandidateTypeToStatsType(candidate.type())); |
| 752 | report->AddString(StatsReport::kStatsValueNameCandidateTransportType, |
| 753 | candidate.protocol()); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 754 | } |
Philipp Hancke | fe0b499 | 2019-03-22 09:00:50 +0100 | [diff] [blame] | 755 | report->set_timestamp(stats_gathering_started_); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 756 | |
Qingsi Wang | 4ff5443 | 2018-03-01 18:25:20 -0800 | [diff] [blame] | 757 | if (local && candidate_stats.stun_stats.has_value()) { |
| 758 | const auto& stun_stats = candidate_stats.stun_stats.value(); |
| 759 | report->AddInt64(StatsReport::kStatsValueNameSentStunKeepaliveRequests, |
| 760 | stun_stats.stun_binding_requests_sent); |
| 761 | report->AddInt64(StatsReport::kStatsValueNameRecvStunKeepaliveResponses, |
| 762 | stun_stats.stun_binding_responses_received); |
| 763 | report->AddFloat(StatsReport::kStatsValueNameStunKeepaliveRttTotal, |
| 764 | stun_stats.stun_binding_rtt_ms_total); |
| 765 | report->AddFloat(StatsReport::kStatsValueNameStunKeepaliveRttSquaredTotal, |
| 766 | stun_stats.stun_binding_rtt_ms_squared_total); |
| 767 | } |
| 768 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 769 | return report; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 770 | } |
| 771 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 772 | void StatsCollector::ExtractSessionInfo() { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 773 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 774 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 775 | // Extract information from the base session. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 776 | StatsReport::Id id(StatsReport::NewTypedId( |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 777 | StatsReport::kStatsReportTypeSession, pc_->session_id())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 778 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 779 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 780 | report->AddBoolean(StatsReport::kStatsValueNameInitiator, |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 781 | pc_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 782 | |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 783 | cricket::CandidateStatsList pooled_candidate_stats_list = |
| 784 | pc_->GetPooledCandidateStats(); |
| 785 | |
| 786 | for (const cricket::CandidateStats& stats : pooled_candidate_stats_list) { |
| 787 | AddCandidateReport(stats, true); |
| 788 | } |
| 789 | |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 790 | std::set<std::string> transport_names; |
| 791 | for (const auto& entry : pc_->GetTransportNamesByMid()) { |
| 792 | transport_names.insert(entry.second); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 793 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 794 | |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 795 | std::map<std::string, cricket::TransportStats> transport_stats_by_name = |
| 796 | pc_->GetTransportStatsByNames(transport_names); |
| 797 | |
| 798 | for (const auto& entry : transport_stats_by_name) { |
| 799 | const std::string& transport_name = entry.first; |
| 800 | const cricket::TransportStats& transport_stats = entry.second; |
| 801 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 802 | // Attempt to get a copy of the certificates from the transport and |
| 803 | // expose them in stats reports. All channels in a transport share the |
| 804 | // same local and remote certificates. |
| 805 | // |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 806 | StatsReport::Id local_cert_report_id, remote_cert_report_id; |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 807 | rtc::scoped_refptr<rtc::RTCCertificate> certificate; |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 808 | if (pc_->GetLocalCertificate(transport_name, &certificate)) { |
Benjamin Wright | 6c6c9df | 2018-10-25 01:16:26 -0700 | [diff] [blame] | 809 | StatsReport* r = AddCertificateReports( |
| 810 | certificate->GetSSLCertificateChain().GetStats()); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 811 | if (r) |
| 812 | local_cert_report_id = r->id(); |
| 813 | } |
| 814 | |
Taylor Brandstetter | c392866 | 2018-02-23 13:04:51 -0800 | [diff] [blame] | 815 | std::unique_ptr<rtc::SSLCertChain> remote_cert_chain = |
| 816 | pc_->GetRemoteSSLCertChain(transport_name); |
| 817 | if (remote_cert_chain) { |
| 818 | StatsReport* r = AddCertificateReports(remote_cert_chain->GetStats()); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 819 | if (r) |
| 820 | remote_cert_report_id = r->id(); |
| 821 | } |
| 822 | |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 823 | for (const auto& channel_iter : transport_stats.channel_stats) { |
| 824 | StatsReport::Id id( |
| 825 | StatsReport::NewComponentId(transport_name, channel_iter.component)); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 826 | StatsReport* channel_report = reports_.ReplaceOrAddNew(id); |
| 827 | channel_report->set_timestamp(stats_gathering_started_); |
| 828 | channel_report->AddInt(StatsReport::kStatsValueNameComponent, |
| 829 | channel_iter.component); |
| 830 | if (local_cert_report_id.get()) { |
| 831 | channel_report->AddId(StatsReport::kStatsValueNameLocalCertificateId, |
| 832 | local_cert_report_id); |
| 833 | } |
| 834 | if (remote_cert_report_id.get()) { |
| 835 | channel_report->AddId(StatsReport::kStatsValueNameRemoteCertificateId, |
| 836 | remote_cert_report_id); |
| 837 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 838 | int srtp_crypto_suite = channel_iter.srtp_crypto_suite; |
| 839 | if (srtp_crypto_suite != rtc::SRTP_INVALID_CRYPTO_SUITE && |
| 840 | rtc::SrtpCryptoSuiteToName(srtp_crypto_suite).length()) { |
| 841 | channel_report->AddString( |
| 842 | StatsReport::kStatsValueNameSrtpCipher, |
| 843 | rtc::SrtpCryptoSuiteToName(srtp_crypto_suite)); |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 844 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 845 | int ssl_cipher_suite = channel_iter.ssl_cipher_suite; |
| 846 | if (ssl_cipher_suite != rtc::TLS_NULL_WITH_NULL_NULL && |
| 847 | rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite) |
| 848 | .length()) { |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 849 | channel_report->AddString( |
| 850 | StatsReport::kStatsValueNameDtlsCipher, |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 851 | rtc::SSLStreamAdapter::SslCipherSuiteToName(ssl_cipher_suite)); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 852 | } |
jiayl@webrtc.org | 06b04ec | 2014-07-24 20:41:20 +0000 | [diff] [blame] | 853 | |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 854 | // Collect stats for non-pooled candidates. Note that the reports |
| 855 | // generated here supersedes the candidate reports generated in |
| 856 | // AddConnectionInfoReport below, and they may report candidates that are |
| 857 | // not paired. Also, the candidate report generated in |
| 858 | // AddConnectionInfoReport do not report port stats like StunStats. |
| 859 | for (const cricket::CandidateStats& stats : |
| 860 | channel_iter.candidate_stats_list) { |
| 861 | AddCandidateReport(stats, true); |
| 862 | } |
| 863 | |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 864 | int connection_id = 0; |
| 865 | for (const cricket::ConnectionInfo& info : |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 866 | channel_iter.connection_infos) { |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 867 | StatsReport* connection_report = AddConnectionInfoReport( |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 868 | transport_name, channel_iter.component, connection_id++, |
pthatcher@webrtc.org | c04a97f | 2015-03-16 19:31:40 +0000 | [diff] [blame] | 869 | channel_report->id(), info); |
| 870 | if (info.best_connection) { |
| 871 | channel_report->AddId( |
| 872 | StatsReport::kStatsValueNameSelectedCandidatePairId, |
| 873 | connection_report->id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | } |
| 879 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 880 | void StatsCollector::ExtractBweInfo() { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 881 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 882 | |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 883 | if (pc_->signaling_state() == PeerConnectionInterface::kClosed) |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 884 | return; |
| 885 | |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 886 | webrtc::Call::Stats call_stats = pc_->GetCallStats(); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 887 | cricket::BandwidthEstimationInfo bwe_info; |
| 888 | bwe_info.available_send_bandwidth = call_stats.send_bandwidth_bps; |
| 889 | bwe_info.available_recv_bandwidth = call_stats.recv_bandwidth_bps; |
| 890 | bwe_info.bucket_delay = call_stats.pacer_delay_ms; |
Steve Anton | afb0bb7 | 2018-02-20 11:35:37 -0800 | [diff] [blame] | 891 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 892 | // Fill in target encoder bitrate, actual encoder bitrate, rtx bitrate, etc. |
| 893 | // TODO(holmer): Also fill this in for audio. |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 894 | for (const auto& transceiver : pc_->GetTransceiversInternal()) { |
Steve Anton | afb0bb7 | 2018-02-20 11:35:37 -0800 | [diff] [blame] | 895 | if (transceiver->media_type() != cricket::MEDIA_TYPE_VIDEO) { |
| 896 | continue; |
| 897 | } |
| 898 | auto* video_channel = |
| 899 | static_cast<cricket::VideoChannel*>(transceiver->internal()->channel()); |
| 900 | if (!video_channel) { |
| 901 | continue; |
| 902 | } |
| 903 | video_channel->FillBitrateInfo(&bwe_info); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 904 | } |
Steve Anton | afb0bb7 | 2018-02-20 11:35:37 -0800 | [diff] [blame] | 905 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 906 | StatsReport::Id report_id(StatsReport::NewBandwidthEstimationId()); |
| 907 | StatsReport* report = reports_.FindOrAddNew(report_id); |
| 908 | ExtractStats(bwe_info, stats_gathering_started_, report); |
| 909 | } |
| 910 | |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 911 | namespace { |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 912 | |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 913 | class MediaChannelStatsGatherer { |
| 914 | public: |
| 915 | virtual ~MediaChannelStatsGatherer() = default; |
| 916 | |
| 917 | virtual bool GetStatsOnWorkerThread() = 0; |
| 918 | |
| 919 | virtual void ExtractStats(StatsCollector* collector) const = 0; |
| 920 | |
| 921 | virtual bool HasRemoteAudio() const = 0; |
| 922 | |
| 923 | std::string mid; |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 924 | std::string transport_name; |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 925 | std::map<uint32_t, std::string> sender_track_id_by_ssrc; |
| 926 | std::map<uint32_t, std::string> receiver_track_id_by_ssrc; |
| 927 | |
| 928 | protected: |
| 929 | template <typename ReceiverT, typename SenderT> |
| 930 | void ExtractSenderReceiverStats( |
| 931 | StatsCollector* collector, |
| 932 | const std::vector<ReceiverT>& receiver_data, |
| 933 | const std::vector<SenderT>& sender_data) const { |
| 934 | RTC_DCHECK(collector); |
| 935 | StatsReport::Id transport_id = StatsReport::NewComponentId( |
| 936 | transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 937 | ExtractStatsFromList(receiver_data, transport_id, collector, |
| 938 | StatsReport::kReceive, receiver_track_id_by_ssrc); |
| 939 | ExtractStatsFromList(sender_data, transport_id, collector, |
| 940 | StatsReport::kSend, sender_track_id_by_ssrc); |
| 941 | } |
| 942 | }; |
| 943 | |
| 944 | class VoiceMediaChannelStatsGatherer final : public MediaChannelStatsGatherer { |
| 945 | public: |
| 946 | VoiceMediaChannelStatsGatherer( |
| 947 | cricket::VoiceMediaChannel* voice_media_channel) |
| 948 | : voice_media_channel_(voice_media_channel) { |
| 949 | RTC_DCHECK(voice_media_channel_); |
| 950 | } |
| 951 | |
| 952 | bool GetStatsOnWorkerThread() override { |
| 953 | return voice_media_channel_->GetStats(&voice_media_info); |
| 954 | } |
| 955 | |
| 956 | void ExtractStats(StatsCollector* collector) const override { |
| 957 | ExtractSenderReceiverStats(collector, voice_media_info.receivers, |
| 958 | voice_media_info.senders); |
| 959 | } |
| 960 | |
| 961 | bool HasRemoteAudio() const override { |
| 962 | return !voice_media_info.receivers.empty(); |
| 963 | } |
| 964 | |
| 965 | private: |
| 966 | cricket::VoiceMediaChannel* voice_media_channel_; |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 967 | cricket::VoiceMediaInfo voice_media_info; |
| 968 | }; |
| 969 | |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 970 | class VideoMediaChannelStatsGatherer final : public MediaChannelStatsGatherer { |
| 971 | public: |
| 972 | VideoMediaChannelStatsGatherer( |
| 973 | cricket::VideoMediaChannel* video_media_channel) |
| 974 | : video_media_channel_(video_media_channel) { |
| 975 | RTC_DCHECK(video_media_channel_); |
| 976 | } |
| 977 | |
| 978 | bool GetStatsOnWorkerThread() override { |
| 979 | return video_media_channel_->GetStats(&video_media_info); |
| 980 | } |
| 981 | |
| 982 | void ExtractStats(StatsCollector* collector) const override { |
| 983 | ExtractSenderReceiverStats(collector, video_media_info.receivers, |
| 984 | video_media_info.senders); |
| 985 | } |
| 986 | |
| 987 | bool HasRemoteAudio() const override { return false; } |
| 988 | |
| 989 | private: |
| 990 | cricket::VideoMediaChannel* video_media_channel_; |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 991 | cricket::VideoMediaInfo video_media_info; |
| 992 | }; |
| 993 | |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 994 | std::unique_ptr<MediaChannelStatsGatherer> CreateMediaChannelStatsGatherer( |
| 995 | cricket::MediaChannel* channel) { |
| 996 | RTC_DCHECK(channel); |
| 997 | if (channel->media_type() == cricket::MEDIA_TYPE_AUDIO) { |
| 998 | return absl::make_unique<VoiceMediaChannelStatsGatherer>( |
| 999 | static_cast<cricket::VoiceMediaChannel*>(channel)); |
| 1000 | } else { |
| 1001 | RTC_DCHECK_EQ(channel->media_type(), cricket::MEDIA_TYPE_VIDEO); |
| 1002 | return absl::make_unique<VideoMediaChannelStatsGatherer>( |
| 1003 | static_cast<cricket::VideoMediaChannel*>(channel)); |
| 1004 | } |
| 1005 | } |
| 1006 | |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1007 | } // namespace |
| 1008 | |
| 1009 | void StatsCollector::ExtractMediaInfo() { |
| 1010 | RTC_DCHECK_RUN_ON(pc_->signaling_thread()); |
| 1011 | |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 1012 | std::vector<std::unique_ptr<MediaChannelStatsGatherer>> gatherers; |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1013 | |
| 1014 | { |
| 1015 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 1016 | for (const auto& transceiver : pc_->GetTransceiversInternal()) { |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 1017 | cricket::ChannelInterface* channel = transceiver->internal()->channel(); |
| 1018 | if (!channel) { |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1019 | continue; |
| 1020 | } |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 1021 | std::unique_ptr<MediaChannelStatsGatherer> gatherer = |
| 1022 | CreateMediaChannelStatsGatherer(channel->media_channel()); |
| 1023 | gatherer->mid = channel->content_name(); |
| 1024 | gatherer->transport_name = channel->transport_name(); |
| 1025 | for (const auto& sender : transceiver->internal()->senders()) { |
| 1026 | std::string track_id = (sender->track() ? sender->track()->id() : ""); |
| 1027 | gatherer->sender_track_id_by_ssrc.insert( |
| 1028 | std::make_pair(sender->ssrc(), track_id)); |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1029 | } |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 1030 | for (const auto& receiver : transceiver->internal()->receivers()) { |
| 1031 | gatherer->receiver_track_id_by_ssrc.insert(std::make_pair( |
| 1032 | receiver->internal()->ssrc(), receiver->track()->id())); |
| 1033 | } |
| 1034 | gatherers.push_back(std::move(gatherer)); |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1035 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1036 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1037 | |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1038 | pc_->worker_thread()->Invoke<void>(RTC_FROM_HERE, [&] { |
| 1039 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 1040 | for (auto it = gatherers.begin(); it != gatherers.end(); |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1041 | /* incremented manually */) { |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 1042 | MediaChannelStatsGatherer* gatherer = it->get(); |
| 1043 | if (!gatherer->GetStatsOnWorkerThread()) { |
| 1044 | RTC_LOG(LS_ERROR) << "Failed to get media channel stats for mid=" |
| 1045 | << gatherer->mid; |
| 1046 | it = gatherers.erase(it); |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1047 | continue; |
| 1048 | } |
| 1049 | ++it; |
| 1050 | } |
| 1051 | }); |
| 1052 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1053 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 1054 | |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1055 | bool has_remote_audio = false; |
Steve Anton | efe4c92 | 2019-03-27 10:26:06 -0700 | [diff] [blame^] | 1056 | for (const auto& gatherer : gatherers) { |
| 1057 | gatherer->ExtractStats(this); |
| 1058 | has_remote_audio |= gatherer->HasRemoteAudio(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1059 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1060 | |
Steve Anton | b886711 | 2018-02-13 10:07:54 -0800 | [diff] [blame] | 1061 | UpdateStatsFromExistingLocalAudioTracks(has_remote_audio); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 1064 | void StatsCollector::ExtractSenderInfo() { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 1065 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 1066 | |
| 1067 | for (const auto& sender : pc_->GetSenders()) { |
| 1068 | // TODO(nisse): SSRC == 0 currently means none. Delete check when |
| 1069 | // that is fixed. |
| 1070 | if (!sender->ssrc()) { |
| 1071 | continue; |
| 1072 | } |
| 1073 | const rtc::scoped_refptr<MediaStreamTrackInterface> track(sender->track()); |
| 1074 | if (!track || track->kind() != MediaStreamTrackInterface::kVideoKind) { |
| 1075 | continue; |
| 1076 | } |
| 1077 | // Safe, because kind() == kVideoKind implies a subclass of |
| 1078 | // VideoTrackInterface; see mediastreaminterface.h. |
| 1079 | VideoTrackSourceInterface* source = |
| 1080 | static_cast<VideoTrackInterface*>(track.get())->GetSource(); |
| 1081 | |
| 1082 | VideoTrackSourceInterface::Stats stats; |
| 1083 | if (!source->GetStats(&stats)) { |
| 1084 | continue; |
| 1085 | } |
| 1086 | const StatsReport::Id stats_id = StatsReport::NewIdWithDirection( |
Jonas Olsson | 6b1985d | 2018-07-05 11:59:48 +0200 | [diff] [blame] | 1087 | StatsReport::kStatsReportTypeSsrc, rtc::ToString(sender->ssrc()), |
| 1088 | StatsReport::kSend); |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 1089 | StatsReport* report = reports_.FindOrAddNew(stats_id); |
| 1090 | report->AddInt(StatsReport::kStatsValueNameFrameWidthInput, |
| 1091 | stats.input_width); |
| 1092 | report->AddInt(StatsReport::kStatsValueNameFrameHeightInput, |
| 1093 | stats.input_height); |
| 1094 | } |
| 1095 | } |
| 1096 | |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1097 | void StatsCollector::ExtractDataInfo() { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 1098 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1099 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1100 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 1101 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1102 | for (const auto& dc : pc_->sctp_data_channels()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1103 | StatsReport::Id id(StatsReport::NewTypedIntId( |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 1104 | StatsReport::kStatsReportTypeDataChannel, dc->id())); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1105 | StatsReport* report = reports_.ReplaceOrAddNew(id); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 1106 | report->set_timestamp(stats_gathering_started_); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 1107 | report->AddString(StatsReport::kStatsValueNameLabel, dc->label()); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1108 | // Filter out the initial id (-1). |
| 1109 | if (dc->id() >= 0) { |
| 1110 | report->AddInt(StatsReport::kStatsValueNameDataChannelId, dc->id()); |
| 1111 | } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 1112 | report->AddString(StatsReport::kStatsValueNameProtocol, dc->protocol()); |
| 1113 | report->AddString(StatsReport::kStatsValueNameState, |
| 1114 | DataChannelInterface::DataStateString(dc->state())); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 1118 | StatsReport* StatsCollector::GetReport(const StatsReport::StatsType& type, |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1119 | const std::string& id, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 1120 | StatsReport::Direction direction) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 1121 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 1122 | RTC_DCHECK(type == StatsReport::kStatsReportTypeSsrc || |
| 1123 | type == StatsReport::kStatsReportTypeRemoteSsrc); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 1124 | return reports_.Find(StatsReport::NewIdWithDirection(type, id, direction)); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 1127 | void StatsCollector::UpdateStatsFromExistingLocalAudioTracks( |
| 1128 | bool has_remote_tracks) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 1129 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1130 | // Loop through the existing local audio tracks. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1131 | for (const auto& it : local_audio_tracks_) { |
| 1132 | AudioTrackInterface* track = it.first; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1133 | uint32_t ssrc = it.second; |
Jonas Olsson | 6b1985d | 2018-07-05 11:59:48 +0200 | [diff] [blame] | 1134 | StatsReport* report = GetReport(StatsReport::kStatsReportTypeSsrc, |
| 1135 | rtc::ToString(ssrc), StatsReport::kSend); |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 1136 | if (report == NULL) { |
| 1137 | // This can happen if a local audio track is added to a stream on the |
| 1138 | // fly and the report has not been set up yet. Do nothing in this case. |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1139 | RTC_LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 1140 | continue; |
| 1141 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1142 | |
| 1143 | // 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] | 1144 | const StatsReport::Value* v = |
| 1145 | report->FindValue(StatsReport::kStatsValueNameTrackId); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1146 | if (!v || v->string_val() != track->id()) |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1147 | continue; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1148 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 1149 | report->set_timestamp(stats_gathering_started_); |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 1150 | UpdateReportFromAudioTrack(track, report, has_remote_tracks); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 1155 | StatsReport* report, |
| 1156 | bool has_remote_tracks) { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 1157 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 1158 | RTC_DCHECK(track != NULL); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1159 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 1160 | // Don't overwrite report values if they're not available. |
| 1161 | int signal_level; |
| 1162 | if (track->GetSignalLevel(&signal_level)) { |
| 1163 | RTC_DCHECK_GE(signal_level, 0); |
| 1164 | report->AddInt(StatsReport::kStatsValueNameAudioInputLevel, signal_level); |
| 1165 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1166 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 1167 | auto audio_processor(track->GetAudioProcessor()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1168 | |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 1169 | if (audio_processor.get()) { |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 1170 | AudioProcessorInterface::AudioProcessorStatistics stats = |
| 1171 | audio_processor->GetStats(has_remote_tracks); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 1172 | |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 1173 | SetAudioProcessingStats(report, stats.typing_noise_detected, |
| 1174 | stats.apm_statistics); |
andrew | 2fe1cb0 | 2015-11-27 17:27:35 -0800 | [diff] [blame] | 1175 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 1178 | void StatsCollector::UpdateTrackReports() { |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 1179 | RTC_DCHECK(pc_->signaling_thread()->IsCurrent()); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 1180 | |
| 1181 | rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 1182 | |
| 1183 | for (const auto& entry : track_ids_) { |
| 1184 | StatsReport* report = entry.second; |
| 1185 | report->set_timestamp(stats_gathering_started_); |
| 1186 | } |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 1189 | void StatsCollector::ClearUpdateStatsCacheForTest() { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1190 | stats_gathering_started_ = 0; |
| 1191 | } |
| 1192 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1193 | } // namespace webrtc |