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