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