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 2014 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 | |
| 11 | #include <stdio.h> |
| 12 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 13 | #include <algorithm> |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 14 | #include <memory> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 15 | #include <utility> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "pc/statscollector.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "pc/mediastream.h" |
| 20 | #include "pc/mediastreamtrack.h" |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 21 | #include "pc/test/fakepeerconnectionforstats.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "pc/test/fakevideotracksource.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "pc/videotrack.h" |
| 24 | #include "rtc_base/base64.h" |
| 25 | #include "rtc_base/fakesslidentity.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "test/gtest.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 28 | using cricket::ConnectionInfo; |
| 29 | using cricket::SsrcReceiverInfo; |
| 30 | using cricket::TransportChannelStats; |
| 31 | using cricket::VideoMediaInfo; |
| 32 | using cricket::VideoReceiverInfo; |
| 33 | using cricket::VideoSenderInfo; |
| 34 | using cricket::VoiceMediaInfo; |
| 35 | using cricket::VoiceReceiverInfo; |
| 36 | using cricket::VoiceSenderInfo; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 38 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | |
tkchin | 7d06a8c | 2016-04-04 14:10:43 -0700 | [diff] [blame] | 40 | namespace internal { |
| 41 | // This value comes from openssl/tls1.h |
| 42 | static const int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014; |
| 43 | } // namespace internal |
| 44 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | // Error return values |
| 46 | const char kNotFound[] = "NOT FOUND"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 48 | // Constant names for track identification. |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 49 | const char kLocalTrackId[] = "local_track_id"; |
| 50 | const char kRemoteTrackId[] = "remote_track_id"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 51 | const uint32_t kSsrcOfTrack = 1234; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 52 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 53 | class FakeAudioProcessor : public AudioProcessorInterface { |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 54 | public: |
| 55 | FakeAudioProcessor() {} |
| 56 | ~FakeAudioProcessor() {} |
| 57 | |
| 58 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 59 | void GetStats(AudioProcessorInterface::AudioProcessorStats* stats) override { |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 60 | stats->typing_noise_detected = true; |
| 61 | stats->echo_return_loss = 2; |
| 62 | stats->echo_return_loss_enhancement = 3; |
| 63 | stats->echo_delay_median_ms = 4; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 64 | stats->echo_delay_std_ms = 6; |
| 65 | } |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 66 | |
| 67 | AudioProcessorInterface::AudioProcessorStatistics GetStats( |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 68 | bool has_recv_streams) override { |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 69 | AudioProcessorStatistics stats; |
| 70 | stats.typing_noise_detected = true; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 71 | if (has_recv_streams) { |
| 72 | stats.apm_statistics.echo_return_loss = 2.0; |
| 73 | stats.apm_statistics.echo_return_loss_enhancement = 3.0; |
| 74 | stats.apm_statistics.delay_median_ms = 4; |
| 75 | stats.apm_statistics.delay_standard_deviation_ms = 5; |
| 76 | } |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 77 | return stats; |
| 78 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 81 | class FakeAudioTrack : public MediaStreamTrack<AudioTrackInterface> { |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 82 | public: |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 83 | explicit FakeAudioTrack(const std::string& id) |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 84 | : MediaStreamTrack<AudioTrackInterface>(id), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 85 | processor_(new rtc::RefCountedObject<FakeAudioProcessor>()) {} |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 86 | std::string kind() const override { return "audio"; } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 87 | AudioSourceInterface* GetSource() const override { return NULL; } |
| 88 | void AddSink(AudioTrackSinkInterface* sink) override {} |
| 89 | void RemoveSink(AudioTrackSinkInterface* sink) override {} |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 90 | bool GetSignalLevel(int* level) override { |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 91 | *level = 1; |
| 92 | return true; |
| 93 | } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 94 | rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor() override { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 95 | return processor_; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 99 | rtc::scoped_refptr<FakeAudioProcessor> processor_; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 102 | // This fake audio processor is used to verify that the undesired initial values |
| 103 | // (-1) will be filtered out. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 104 | class FakeAudioProcessorWithInitValue : public AudioProcessorInterface { |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 105 | public: |
| 106 | FakeAudioProcessorWithInitValue() {} |
| 107 | ~FakeAudioProcessorWithInitValue() {} |
| 108 | |
| 109 | private: |
| 110 | void GetStats(AudioProcessorInterface::AudioProcessorStats* stats) override { |
| 111 | stats->typing_noise_detected = false; |
| 112 | stats->echo_return_loss = -100; |
| 113 | stats->echo_return_loss_enhancement = -100; |
| 114 | stats->echo_delay_median_ms = -1; |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 115 | stats->echo_delay_std_ms = -1; |
| 116 | } |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 117 | |
| 118 | AudioProcessorInterface::AudioProcessorStatistics GetStats( |
| 119 | bool /*has_recv_streams*/) override { |
| 120 | AudioProcessorStatistics stats; |
| 121 | stats.typing_noise_detected = false; |
| 122 | return stats; |
| 123 | } |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | class FakeAudioTrackWithInitValue |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 127 | : public MediaStreamTrack<AudioTrackInterface> { |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 128 | public: |
| 129 | explicit FakeAudioTrackWithInitValue(const std::string& id) |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 130 | : MediaStreamTrack<AudioTrackInterface>(id), |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 131 | processor_( |
| 132 | new rtc::RefCountedObject<FakeAudioProcessorWithInitValue>()) {} |
| 133 | std::string kind() const override { return "audio"; } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 134 | AudioSourceInterface* GetSource() const override { return NULL; } |
| 135 | void AddSink(AudioTrackSinkInterface* sink) override {} |
| 136 | void RemoveSink(AudioTrackSinkInterface* sink) override {} |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 137 | bool GetSignalLevel(int* level) override { |
| 138 | *level = 1; |
| 139 | return true; |
| 140 | } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 141 | rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor() override { |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 142 | return processor_; |
| 143 | } |
| 144 | |
| 145 | private: |
| 146 | rtc::scoped_refptr<FakeAudioProcessorWithInitValue> processor_; |
| 147 | }; |
| 148 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 149 | bool GetValue(const StatsReport* report, |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 150 | StatsReport::StatsValueName name, |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 151 | std::string* value) { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 152 | const StatsReport::Value* v = report->FindValue(name); |
| 153 | if (!v) |
| 154 | return false; |
| 155 | *value = v->ToString(); |
| 156 | return true; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 157 | } |
| 158 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 159 | std::string ExtractStatsValue(const StatsReport::StatsType& type, |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 160 | const StatsReports& reports, |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 161 | StatsReport::StatsValueName name) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 162 | for (const auto* r : reports) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 163 | std::string ret; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 164 | if (r->type() == type && GetValue(r, name, &ret)) |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 165 | return ret; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | return kNotFound; |
| 169 | } |
| 170 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 171 | StatsReport::Id TypedIdFromIdString(StatsReport::StatsType type, |
| 172 | const std::string& value) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 173 | EXPECT_FALSE(value.empty()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 174 | StatsReport::Id id; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 175 | if (value.empty()) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 176 | return id; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 177 | |
| 178 | // This has assumptions about how the ID is constructed. As is, this is |
| 179 | // OK since this is for testing purposes only, but if we ever need this |
| 180 | // in production, we should add a generic method that does this. |
| 181 | size_t index = value.find('_'); |
| 182 | EXPECT_NE(index, std::string::npos); |
| 183 | if (index == std::string::npos || index == (value.length() - 1)) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 184 | return id; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 185 | |
| 186 | id = StatsReport::NewTypedId(type, value.substr(index + 1)); |
| 187 | EXPECT_EQ(id->ToString(), value); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 188 | return id; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 189 | } |
| 190 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 191 | StatsReport::Id IdFromCertIdString(const std::string& cert_id) { |
| 192 | return TypedIdFromIdString(StatsReport::kStatsReportTypeCertificate, cert_id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 193 | } |
| 194 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 195 | // Finds the |n|-th report of type |type| in |reports|. |
| 196 | // |n| starts from 1 for finding the first report. |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 197 | const StatsReport* FindNthReportByType( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 198 | const StatsReports& reports, const StatsReport::StatsType& type, int n) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | for (size_t i = 0; i < reports.size(); ++i) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 200 | if (reports[i]->type() == type) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | n--; |
| 202 | if (n == 0) |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 203 | return reports[i]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 206 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 207 | } |
| 208 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 209 | const StatsReport* FindReportById(const StatsReports& reports, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 210 | const StatsReport::Id& id) { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 211 | for (const auto* r : reports) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 212 | if (r->id()->Equals(id)) |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 213 | return r; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 214 | } |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 215 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 218 | std::string ExtractSsrcStatsValue(const StatsReports& reports, |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 219 | StatsReport::StatsValueName name) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 220 | return ExtractStatsValue(StatsReport::kStatsReportTypeSsrc, reports, name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 223 | std::string ExtractBweStatsValue(const StatsReports& reports, |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 224 | StatsReport::StatsValueName name) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | return ExtractStatsValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 226 | StatsReport::kStatsReportTypeBwe, reports, name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | } |
| 228 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 229 | std::string DerToPem(const std::string& der) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 230 | return rtc::SSLIdentity::DerToPem( |
| 231 | rtc::kPemTypeCertificate, |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 232 | reinterpret_cast<const unsigned char*>(der.c_str()), |
| 233 | der.length()); |
| 234 | } |
| 235 | |
| 236 | std::vector<std::string> DersToPems( |
| 237 | const std::vector<std::string>& ders) { |
| 238 | std::vector<std::string> pems(ders.size()); |
| 239 | std::transform(ders.begin(), ders.end(), pems.begin(), DerToPem); |
| 240 | return pems; |
| 241 | } |
| 242 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 243 | void CheckCertChainReports(const StatsReports& reports, |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 244 | const std::vector<std::string>& ders, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 245 | const StatsReport::Id& start_id) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 246 | StatsReport::Id cert_id; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 247 | const StatsReport::Id* certificate_id = &start_id; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 248 | size_t i = 0; |
| 249 | while (true) { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 250 | const StatsReport* report = FindReportById(reports, *certificate_id); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 251 | ASSERT_TRUE(report != NULL); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 252 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 253 | std::string der_base64; |
| 254 | EXPECT_TRUE(GetValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 255 | report, StatsReport::kStatsValueNameDer, &der_base64)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 256 | std::string der = rtc::Base64::Decode(der_base64, rtc::Base64::DO_STRICT); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 257 | EXPECT_EQ(ders[i], der); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 258 | |
| 259 | std::string fingerprint_algorithm; |
| 260 | EXPECT_TRUE(GetValue( |
| 261 | report, |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 262 | StatsReport::kStatsValueNameFingerprintAlgorithm, |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 263 | &fingerprint_algorithm)); |
| 264 | // The digest algorithm for a FakeSSLCertificate is always SHA-1. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 265 | std::string sha_1_str = rtc::DIGEST_SHA_1; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 266 | EXPECT_EQ(sha_1_str, fingerprint_algorithm); |
| 267 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 268 | std::string fingerprint; |
| 269 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameFingerprint, |
| 270 | &fingerprint)); |
| 271 | EXPECT_FALSE(fingerprint.empty()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 272 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 273 | ++i; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 274 | std::string issuer_id; |
| 275 | if (!GetValue(report, StatsReport::kStatsValueNameIssuerId, |
| 276 | &issuer_id)) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 277 | break; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 278 | } |
| 279 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 280 | cert_id = IdFromCertIdString(issuer_id); |
| 281 | certificate_id = &cert_id; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 282 | } |
| 283 | EXPECT_EQ(ders.size(), i); |
| 284 | } |
| 285 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 286 | void VerifyVoiceReceiverInfoReport( |
| 287 | const StatsReport* report, |
| 288 | const cricket::VoiceReceiverInfo& info) { |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 289 | std::string value_in_report; |
| 290 | EXPECT_TRUE(GetValue( |
| 291 | report, StatsReport::kStatsValueNameAudioOutputLevel, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 292 | EXPECT_EQ(rtc::ToString<int>(info.audio_level), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 293 | EXPECT_TRUE(GetValue( |
| 294 | report, StatsReport::kStatsValueNameBytesReceived, &value_in_report)); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 295 | EXPECT_EQ(rtc::ToString<int64_t>(info.bytes_rcvd), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 296 | EXPECT_TRUE(GetValue( |
| 297 | report, StatsReport::kStatsValueNameJitterReceived, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 298 | EXPECT_EQ(rtc::ToString<int>(info.jitter_ms), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 299 | EXPECT_TRUE(GetValue( |
| 300 | report, StatsReport::kStatsValueNameJitterBufferMs, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 301 | EXPECT_EQ(rtc::ToString<int>(info.jitter_buffer_ms), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 302 | EXPECT_TRUE(GetValue( |
| 303 | report, StatsReport::kStatsValueNamePreferredJitterBufferMs, |
| 304 | &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 305 | EXPECT_EQ(rtc::ToString<int>(info.jitter_buffer_preferred_ms), |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 306 | value_in_report); |
| 307 | EXPECT_TRUE(GetValue( |
| 308 | report, StatsReport::kStatsValueNameCurrentDelayMs, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 309 | EXPECT_EQ(rtc::ToString<int>(info.delay_estimate_ms), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 310 | EXPECT_TRUE(GetValue( |
| 311 | report, StatsReport::kStatsValueNameExpandRate, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 312 | EXPECT_EQ(rtc::ToString<float>(info.expand_rate), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 313 | EXPECT_TRUE(GetValue( |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 +0000 | [diff] [blame] | 314 | report, StatsReport::kStatsValueNameSpeechExpandRate, &value_in_report)); |
| 315 | EXPECT_EQ(rtc::ToString<float>(info.speech_expand_rate), value_in_report); |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 316 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameAccelerateRate, |
| 317 | &value_in_report)); |
| 318 | EXPECT_EQ(rtc::ToString<float>(info.accelerate_rate), value_in_report); |
| 319 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNamePreemptiveExpandRate, |
| 320 | &value_in_report)); |
| 321 | EXPECT_EQ(rtc::ToString<float>(info.preemptive_expand_rate), value_in_report); |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 +0000 | [diff] [blame] | 322 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameSecondaryDecodedRate, |
| 323 | &value_in_report)); |
| 324 | EXPECT_EQ(rtc::ToString<float>(info.secondary_decoded_rate), value_in_report); |
minyue-webrtc | 0e320ec | 2017-08-28 13:51:27 +0200 | [diff] [blame] | 325 | EXPECT_TRUE(GetValue(report, |
| 326 | StatsReport::kStatsValueNameSecondaryDiscardedRate, |
| 327 | &value_in_report)); |
| 328 | EXPECT_EQ(rtc::ToString<float>(info.secondary_discarded_rate), |
| 329 | value_in_report); |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 +0000 | [diff] [blame] | 330 | EXPECT_TRUE(GetValue( |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 331 | report, StatsReport::kStatsValueNamePacketsReceived, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 332 | EXPECT_EQ(rtc::ToString<int>(info.packets_rcvd), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 333 | EXPECT_TRUE(GetValue( |
| 334 | report, StatsReport::kStatsValueNameDecodingCTSG, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 335 | EXPECT_EQ(rtc::ToString<int>(info.decoding_calls_to_silence_generator), |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 336 | value_in_report); |
| 337 | EXPECT_TRUE(GetValue( |
| 338 | report, StatsReport::kStatsValueNameDecodingCTN, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 339 | EXPECT_EQ(rtc::ToString<int>(info.decoding_calls_to_neteq), |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 340 | value_in_report); |
| 341 | EXPECT_TRUE(GetValue( |
| 342 | report, StatsReport::kStatsValueNameDecodingNormal, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 343 | EXPECT_EQ(rtc::ToString<int>(info.decoding_normal), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 344 | EXPECT_TRUE(GetValue( |
| 345 | report, StatsReport::kStatsValueNameDecodingPLC, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 346 | EXPECT_EQ(rtc::ToString<int>(info.decoding_plc), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 347 | EXPECT_TRUE(GetValue( |
| 348 | report, StatsReport::kStatsValueNameDecodingCNG, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 349 | EXPECT_EQ(rtc::ToString<int>(info.decoding_cng), value_in_report); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 350 | EXPECT_TRUE(GetValue( |
| 351 | report, StatsReport::kStatsValueNameDecodingPLCCNG, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 352 | EXPECT_EQ(rtc::ToString<int>(info.decoding_plc_cng), value_in_report); |
henrik.lundin | 6348978 | 2016-09-20 01:47:12 -0700 | [diff] [blame] | 353 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameDecodingMutedOutput, |
| 354 | &value_in_report)); |
| 355 | EXPECT_EQ(rtc::ToString<int>(info.decoding_muted_output), value_in_report); |
| 356 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameCodecName, |
| 357 | &value_in_report)); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 361 | void VerifyVoiceSenderInfoReport(const StatsReport* report, |
| 362 | const cricket::VoiceSenderInfo& sinfo) { |
| 363 | std::string value_in_report; |
| 364 | EXPECT_TRUE(GetValue( |
| 365 | report, StatsReport::kStatsValueNameCodecName, &value_in_report)); |
| 366 | EXPECT_EQ(sinfo.codec_name, value_in_report); |
| 367 | EXPECT_TRUE(GetValue( |
| 368 | report, StatsReport::kStatsValueNameBytesSent, &value_in_report)); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 369 | EXPECT_EQ(rtc::ToString<int64_t>(sinfo.bytes_sent), value_in_report); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 370 | EXPECT_TRUE(GetValue( |
| 371 | report, StatsReport::kStatsValueNamePacketsSent, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 372 | EXPECT_EQ(rtc::ToString<int>(sinfo.packets_sent), value_in_report); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 373 | EXPECT_TRUE(GetValue( |
henrike@webrtc.org | ffe2620 | 2014-03-19 22:20:10 +0000 | [diff] [blame] | 374 | report, StatsReport::kStatsValueNamePacketsLost, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 375 | EXPECT_EQ(rtc::ToString<int>(sinfo.packets_lost), value_in_report); |
henrike@webrtc.org | ffe2620 | 2014-03-19 22:20:10 +0000 | [diff] [blame] | 376 | EXPECT_TRUE(GetValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 377 | report, StatsReport::kStatsValueNameRtt, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 378 | EXPECT_EQ(rtc::ToString<int>(sinfo.rtt_ms), value_in_report); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 379 | EXPECT_TRUE(GetValue( |
| 380 | report, StatsReport::kStatsValueNameRtt, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 381 | EXPECT_EQ(rtc::ToString<int>(sinfo.rtt_ms), value_in_report); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 382 | EXPECT_TRUE(GetValue( |
| 383 | report, StatsReport::kStatsValueNameJitterReceived, &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 384 | EXPECT_EQ(rtc::ToString<int>(sinfo.jitter_ms), value_in_report); |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 385 | if (sinfo.apm_statistics.delay_median_ms) { |
| 386 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameEchoDelayMedian, |
| 387 | &value_in_report)); |
| 388 | EXPECT_EQ(rtc::ToString<int>(*sinfo.apm_statistics.delay_median_ms), |
| 389 | value_in_report); |
| 390 | } else { |
| 391 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameEchoDelayMedian, |
| 392 | &value_in_report)); |
| 393 | } |
| 394 | if (sinfo.apm_statistics.delay_standard_deviation_ms) { |
| 395 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameEchoDelayStdDev, |
| 396 | &value_in_report)); |
| 397 | EXPECT_EQ( |
| 398 | rtc::ToString<int>(*sinfo.apm_statistics.delay_standard_deviation_ms), |
| 399 | value_in_report); |
| 400 | } else { |
| 401 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameEchoDelayStdDev, |
| 402 | &value_in_report)); |
| 403 | } |
| 404 | if (sinfo.apm_statistics.echo_return_loss) { |
| 405 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameEchoReturnLoss, |
| 406 | &value_in_report)); |
| 407 | EXPECT_EQ(rtc::ToString<int>(*sinfo.apm_statistics.echo_return_loss), |
| 408 | value_in_report); |
| 409 | } else { |
| 410 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameEchoReturnLoss, |
| 411 | &value_in_report)); |
| 412 | } |
| 413 | if (sinfo.apm_statistics.echo_return_loss_enhancement) { |
| 414 | EXPECT_TRUE(GetValue(report, |
| 415 | StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
| 416 | &value_in_report)); |
| 417 | EXPECT_EQ( |
| 418 | rtc::ToString<int>(*sinfo.apm_statistics.echo_return_loss_enhancement), |
| 419 | value_in_report); |
| 420 | } else { |
| 421 | EXPECT_FALSE(GetValue(report, |
| 422 | StatsReport::kStatsValueNameEchoReturnLossEnhancement, |
| 423 | &value_in_report)); |
| 424 | } |
| 425 | if (sinfo.apm_statistics.residual_echo_likelihood) { |
| 426 | EXPECT_TRUE(GetValue(report, |
| 427 | StatsReport::kStatsValueNameResidualEchoLikelihood, |
| 428 | &value_in_report)); |
| 429 | EXPECT_EQ( |
| 430 | rtc::ToString<float>(*sinfo.apm_statistics.residual_echo_likelihood), |
| 431 | value_in_report); |
| 432 | } else { |
| 433 | EXPECT_FALSE(GetValue(report, |
| 434 | StatsReport::kStatsValueNameResidualEchoLikelihood, |
| 435 | &value_in_report)); |
| 436 | } |
| 437 | if (sinfo.apm_statistics.residual_echo_likelihood_recent_max) { |
| 438 | EXPECT_TRUE(GetValue( |
| 439 | report, StatsReport::kStatsValueNameResidualEchoLikelihoodRecentMax, |
| 440 | &value_in_report)); |
| 441 | EXPECT_EQ(rtc::ToString<float>( |
| 442 | *sinfo.apm_statistics.residual_echo_likelihood_recent_max), |
| 443 | value_in_report); |
| 444 | } else { |
| 445 | EXPECT_FALSE(GetValue( |
| 446 | report, StatsReport::kStatsValueNameResidualEchoLikelihoodRecentMax, |
| 447 | &value_in_report)); |
| 448 | } |
ivoc | 8c63a82 | 2016-10-21 04:10:03 -0700 | [diff] [blame] | 449 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameAudioInputLevel, |
| 450 | &value_in_report)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 451 | EXPECT_EQ(rtc::ToString<int>(sinfo.audio_level), value_in_report); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 452 | EXPECT_TRUE(GetValue( |
| 453 | report, StatsReport::kStatsValueNameTypingNoiseState, &value_in_report)); |
| 454 | std::string typing_detected = sinfo.typing_noise_detected ? "true" : "false"; |
| 455 | EXPECT_EQ(typing_detected, value_in_report); |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 456 | EXPECT_TRUE(GetValue(report, |
| 457 | StatsReport::kStatsValueNameAnaBitrateActionCounter, |
| 458 | &value_in_report)); |
| 459 | ASSERT_TRUE(sinfo.ana_statistics.bitrate_action_counter); |
| 460 | EXPECT_EQ( |
| 461 | rtc::ToString<uint32_t>(*sinfo.ana_statistics.bitrate_action_counter), |
| 462 | value_in_report); |
| 463 | EXPECT_TRUE(GetValue(report, |
| 464 | StatsReport::kStatsValueNameAnaChannelActionCounter, |
| 465 | &value_in_report)); |
| 466 | ASSERT_TRUE(sinfo.ana_statistics.channel_action_counter); |
| 467 | EXPECT_EQ( |
| 468 | rtc::ToString<uint32_t>(*sinfo.ana_statistics.channel_action_counter), |
| 469 | value_in_report); |
| 470 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameAnaDtxActionCounter, |
| 471 | &value_in_report)); |
| 472 | ASSERT_TRUE(sinfo.ana_statistics.dtx_action_counter); |
| 473 | EXPECT_EQ(rtc::ToString<uint32_t>(*sinfo.ana_statistics.dtx_action_counter), |
| 474 | value_in_report); |
| 475 | EXPECT_TRUE(GetValue(report, StatsReport::kStatsValueNameAnaFecActionCounter, |
| 476 | &value_in_report)); |
| 477 | ASSERT_TRUE(sinfo.ana_statistics.fec_action_counter); |
| 478 | EXPECT_EQ(rtc::ToString<uint32_t>(*sinfo.ana_statistics.fec_action_counter), |
| 479 | value_in_report); |
ivoc | 0d0b912 | 2017-09-08 13:24:21 -0700 | [diff] [blame] | 480 | EXPECT_TRUE(GetValue( |
| 481 | report, StatsReport::kStatsValueNameAnaFrameLengthIncreaseCounter, |
| 482 | &value_in_report)); |
| 483 | ASSERT_TRUE(sinfo.ana_statistics.frame_length_increase_counter); |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 484 | EXPECT_EQ(rtc::ToString<uint32_t>( |
ivoc | 0d0b912 | 2017-09-08 13:24:21 -0700 | [diff] [blame] | 485 | *sinfo.ana_statistics.frame_length_increase_counter), |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 486 | value_in_report); |
ivoc | 0d0b912 | 2017-09-08 13:24:21 -0700 | [diff] [blame] | 487 | EXPECT_TRUE(GetValue( |
| 488 | report, StatsReport::kStatsValueNameAnaFrameLengthDecreaseCounter, |
| 489 | &value_in_report)); |
| 490 | ASSERT_TRUE(sinfo.ana_statistics.frame_length_decrease_counter); |
| 491 | EXPECT_EQ(rtc::ToString<uint32_t>( |
| 492 | *sinfo.ana_statistics.frame_length_decrease_counter), |
| 493 | value_in_report); |
| 494 | EXPECT_TRUE(GetValue(report, |
| 495 | StatsReport::kStatsValueNameAnaUplinkPacketLossFraction, |
| 496 | &value_in_report)); |
| 497 | ASSERT_TRUE(sinfo.ana_statistics.uplink_packet_loss_fraction); |
| 498 | EXPECT_EQ( |
| 499 | rtc::ToString<float>(*sinfo.ana_statistics.uplink_packet_loss_fraction), |
| 500 | value_in_report); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 501 | } |
| 502 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 503 | // Helper methods to avoid duplication of code. |
| 504 | void InitVoiceSenderInfo(cricket::VoiceSenderInfo* voice_sender_info) { |
| 505 | voice_sender_info->add_ssrc(kSsrcOfTrack); |
| 506 | voice_sender_info->codec_name = "fake_codec"; |
| 507 | voice_sender_info->bytes_sent = 100; |
| 508 | voice_sender_info->packets_sent = 101; |
| 509 | voice_sender_info->rtt_ms = 102; |
| 510 | voice_sender_info->fraction_lost = 103; |
| 511 | voice_sender_info->jitter_ms = 104; |
| 512 | voice_sender_info->packets_lost = 105; |
| 513 | voice_sender_info->ext_seqnum = 106; |
| 514 | voice_sender_info->audio_level = 107; |
| 515 | voice_sender_info->echo_return_loss = 108; |
| 516 | voice_sender_info->echo_return_loss_enhancement = 109; |
| 517 | voice_sender_info->echo_delay_median_ms = 110; |
| 518 | voice_sender_info->echo_delay_std_ms = 111; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 519 | voice_sender_info->typing_noise_detected = false; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 520 | voice_sender_info->ana_statistics.bitrate_action_counter = 112; |
| 521 | voice_sender_info->ana_statistics.channel_action_counter = 113; |
| 522 | voice_sender_info->ana_statistics.dtx_action_counter = 114; |
| 523 | voice_sender_info->ana_statistics.fec_action_counter = 115; |
| 524 | voice_sender_info->ana_statistics.frame_length_increase_counter = 116; |
| 525 | voice_sender_info->ana_statistics.frame_length_decrease_counter = 117; |
| 526 | voice_sender_info->ana_statistics.uplink_packet_loss_fraction = 118.0; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | void UpdateVoiceSenderInfoFromAudioTrack( |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 530 | AudioTrackInterface* audio_track, |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 531 | cricket::VoiceSenderInfo* voice_sender_info, |
| 532 | bool has_remote_tracks) { |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 533 | audio_track->GetSignalLevel(&voice_sender_info->audio_level); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 534 | AudioProcessorInterface::AudioProcessorStatistics audio_processor_stats = |
| 535 | audio_track->GetAudioProcessor()->GetStats(has_remote_tracks); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 536 | voice_sender_info->typing_noise_detected = |
| 537 | audio_processor_stats.typing_noise_detected; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 538 | voice_sender_info->apm_statistics = audio_processor_stats.apm_statistics; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | void InitVoiceReceiverInfo(cricket::VoiceReceiverInfo* voice_receiver_info) { |
| 542 | voice_receiver_info->add_ssrc(kSsrcOfTrack); |
| 543 | voice_receiver_info->bytes_rcvd = 110; |
| 544 | voice_receiver_info->packets_rcvd = 111; |
| 545 | voice_receiver_info->packets_lost = 112; |
| 546 | voice_receiver_info->fraction_lost = 113; |
| 547 | voice_receiver_info->packets_lost = 114; |
| 548 | voice_receiver_info->ext_seqnum = 115; |
| 549 | voice_receiver_info->jitter_ms = 116; |
| 550 | voice_receiver_info->jitter_buffer_ms = 117; |
| 551 | voice_receiver_info->jitter_buffer_preferred_ms = 118; |
| 552 | voice_receiver_info->delay_estimate_ms = 119; |
| 553 | voice_receiver_info->audio_level = 120; |
| 554 | voice_receiver_info->expand_rate = 121; |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 +0000 | [diff] [blame] | 555 | voice_receiver_info->speech_expand_rate = 122; |
| 556 | voice_receiver_info->secondary_decoded_rate = 123; |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 557 | voice_receiver_info->accelerate_rate = 124; |
| 558 | voice_receiver_info->preemptive_expand_rate = 125; |
minyue-webrtc | 0e320ec | 2017-08-28 13:51:27 +0200 | [diff] [blame] | 559 | voice_receiver_info->secondary_discarded_rate = 126; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 562 | class StatsCollectorForTest : public StatsCollector { |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 563 | public: |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 564 | explicit StatsCollectorForTest(PeerConnectionInternal* pc) |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 565 | : StatsCollector(pc), time_now_(19477) {} |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 566 | |
| 567 | double GetTimeNow() override { |
| 568 | return time_now_; |
| 569 | } |
| 570 | |
| 571 | private: |
| 572 | double time_now_; |
| 573 | }; |
| 574 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 575 | class StatsCollectorTest : public testing::Test { |
| 576 | protected: |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 577 | rtc::scoped_refptr<FakePeerConnectionForStats> CreatePeerConnection() { |
| 578 | return new rtc::RefCountedObject<FakePeerConnectionForStats>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 581 | std::unique_ptr<StatsCollectorForTest> CreateStatsCollector( |
| 582 | PeerConnectionInternal* pc) { |
| 583 | return rtc::MakeUnique<StatsCollectorForTest>(pc); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 586 | void VerifyAudioTrackStats(FakeAudioTrack* audio_track, |
| 587 | StatsCollectorForTest* stats, |
| 588 | const VoiceMediaInfo& voice_info, |
| 589 | StatsReports* reports) { |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 590 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
tommi@webrtc.org | 69bc5a3 | 2014-12-15 09:44:48 +0000 | [diff] [blame] | 591 | stats->ClearUpdateStatsCacheForTest(); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 592 | stats->GetStats(nullptr, reports); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 593 | |
| 594 | // Verify the existence of the track report. |
| 595 | const StatsReport* report = FindNthReportByType( |
| 596 | *reports, StatsReport::kStatsReportTypeSsrc, 1); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 597 | ASSERT_TRUE(report); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 598 | EXPECT_EQ(stats->GetTimeNow(), report->timestamp()); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 599 | std::string track_id = ExtractSsrcStatsValue( |
| 600 | *reports, StatsReport::kStatsValueNameTrackId); |
| 601 | EXPECT_EQ(audio_track->id(), track_id); |
| 602 | std::string ssrc_id = ExtractSsrcStatsValue( |
| 603 | *reports, StatsReport::kStatsValueNameSsrc); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 604 | EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 605 | |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 606 | std::string media_type = ExtractSsrcStatsValue(*reports, |
| 607 | StatsReport::kStatsValueNameMediaType); |
| 608 | EXPECT_EQ("audio", media_type); |
| 609 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 610 | // Verifies the values in the track report. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 611 | if (!voice_info.senders.empty()) { |
| 612 | VerifyVoiceSenderInfoReport(report, voice_info.senders[0]); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 613 | } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 614 | if (!voice_info.receivers.empty()) { |
| 615 | VerifyVoiceReceiverInfoReport(report, voice_info.receivers[0]); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | // Verify we get the same result by passing a track to GetStats(). |
| 619 | StatsReports track_reports; // returned values. |
| 620 | stats->GetStats(audio_track, &track_reports); |
| 621 | const StatsReport* track_report = FindNthReportByType( |
| 622 | track_reports, StatsReport::kStatsReportTypeSsrc, 1); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 623 | ASSERT_TRUE(track_report); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 624 | EXPECT_EQ(stats->GetTimeNow(), track_report->timestamp()); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 625 | track_id = ExtractSsrcStatsValue(track_reports, |
| 626 | StatsReport::kStatsValueNameTrackId); |
| 627 | EXPECT_EQ(audio_track->id(), track_id); |
| 628 | ssrc_id = ExtractSsrcStatsValue(track_reports, |
| 629 | StatsReport::kStatsValueNameSsrc); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 630 | EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 631 | if (!voice_info.senders.empty()) { |
| 632 | VerifyVoiceSenderInfoReport(track_report, voice_info.senders[0]); |
| 633 | } |
| 634 | if (!voice_info.receivers.empty()) { |
| 635 | VerifyVoiceReceiverInfoReport(track_report, voice_info.receivers[0]); |
| 636 | } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 637 | } |
| 638 | |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 639 | void TestCertificateReports( |
| 640 | const rtc::FakeSSLCertificate& local_cert, |
| 641 | const std::vector<std::string>& local_ders, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 642 | std::unique_ptr<rtc::FakeSSLCertificate> remote_cert, |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 643 | const std::vector<std::string>& remote_ders) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 644 | const std::string kTransportName = "transport"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 645 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 646 | auto pc = CreatePeerConnection(); |
| 647 | auto stats = CreateStatsCollector(pc); |
| 648 | |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 649 | pc->AddVoiceChannel("audio", kTransportName); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 650 | |
| 651 | // Fake stats to process. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 652 | TransportChannelStats channel_stats; |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 653 | channel_stats.component = 1; |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 654 | channel_stats.srtp_crypto_suite = rtc::SRTP_AES128_CM_SHA1_80; |
tkchin | 7d06a8c | 2016-04-04 14:10:43 -0700 | [diff] [blame] | 655 | channel_stats.ssl_cipher_suite = |
| 656 | internal::TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 657 | pc->SetTransportStats(kTransportName, channel_stats); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 658 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 659 | // Fake certificate to report |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 660 | rtc::scoped_refptr<rtc::RTCCertificate> local_certificate( |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 661 | rtc::RTCCertificate::Create( |
| 662 | rtc::MakeUnique<rtc::FakeSSLIdentity>(local_cert))); |
| 663 | pc->SetLocalCertificate(kTransportName, local_certificate); |
| 664 | pc->SetRemoteCertificate(kTransportName, std::move(remote_cert)); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 665 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 666 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 667 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 668 | StatsReports reports; |
| 669 | stats->GetStats(nullptr, &reports); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 670 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 671 | const StatsReport* channel_report = FindNthReportByType( |
| 672 | reports, StatsReport::kStatsReportTypeComponent, 1); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 673 | EXPECT_TRUE(channel_report); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 674 | |
| 675 | // Check local certificate chain. |
| 676 | std::string local_certificate_id = ExtractStatsValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 677 | StatsReport::kStatsReportTypeComponent, |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 678 | reports, |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 679 | StatsReport::kStatsValueNameLocalCertificateId); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 680 | if (local_ders.size() > 0) { |
| 681 | EXPECT_NE(kNotFound, local_certificate_id); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 682 | StatsReport::Id id(IdFromCertIdString(local_certificate_id)); |
| 683 | CheckCertChainReports(reports, local_ders, id); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 684 | } else { |
| 685 | EXPECT_EQ(kNotFound, local_certificate_id); |
| 686 | } |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 687 | |
| 688 | // Check remote certificate chain. |
| 689 | std::string remote_certificate_id = ExtractStatsValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 690 | StatsReport::kStatsReportTypeComponent, |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 691 | reports, |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 692 | StatsReport::kStatsValueNameRemoteCertificateId); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 693 | if (remote_ders.size() > 0) { |
| 694 | EXPECT_NE(kNotFound, remote_certificate_id); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 695 | StatsReport::Id id(IdFromCertIdString(remote_certificate_id)); |
| 696 | CheckCertChainReports(reports, remote_ders, id); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 697 | } else { |
| 698 | EXPECT_EQ(kNotFound, remote_certificate_id); |
| 699 | } |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 700 | |
| 701 | // Check negotiated ciphers. |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 702 | std::string dtls_cipher_suite = |
| 703 | ExtractStatsValue(StatsReport::kStatsReportTypeComponent, reports, |
| 704 | StatsReport::kStatsValueNameDtlsCipher); |
| 705 | EXPECT_EQ(rtc::SSLStreamAdapter::SslCipherSuiteToName( |
tkchin | 7d06a8c | 2016-04-04 14:10:43 -0700 | [diff] [blame] | 706 | internal::TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA), |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 707 | dtls_cipher_suite); |
| 708 | std::string srtp_crypto_suite = |
| 709 | ExtractStatsValue(StatsReport::kStatsReportTypeComponent, reports, |
| 710 | StatsReport::kStatsValueNameSrtpCipher); |
| 711 | EXPECT_EQ(rtc::SrtpCryptoSuiteToName(rtc::SRTP_AES128_CM_SHA1_80), |
| 712 | srtp_crypto_suite); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 713 | } |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 714 | }; |
| 715 | |
| 716 | class StatsCollectorTrackTest : public StatsCollectorTest, |
| 717 | public ::testing::WithParamInterface<bool> { |
| 718 | public: |
| 719 | // Adds a outgoing video track with a given SSRC into the stats. |
| 720 | // If GetParam() returns true, the track is also inserted into the local |
| 721 | // stream, which is created if necessary. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 722 | void AddOutgoingVideoTrack(FakePeerConnectionForStats* pc, |
| 723 | StatsCollectorForTest* stats) { |
| 724 | track_ = VideoTrack::Create(kLocalTrackId, FakeVideoTrackSource::Create(), |
| 725 | rtc::Thread::Current()); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 726 | if (GetParam()) { |
| 727 | if (!stream_) |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 728 | stream_ = MediaStream::Create("streamlabel"); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 729 | stream_->AddTrack(track_); |
| 730 | stats->AddStream(stream_); |
| 731 | } else { |
| 732 | stats->AddTrack(track_); |
| 733 | } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 734 | pc->AddLocalTrack(kSsrcOfTrack, kLocalTrackId); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // Adds a incoming video track with a given SSRC into the stats. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 738 | void AddIncomingVideoTrack(FakePeerConnectionForStats* pc, |
| 739 | StatsCollectorForTest* stats) { |
| 740 | track_ = VideoTrack::Create(kRemoteTrackId, FakeVideoTrackSource::Create(), |
| 741 | rtc::Thread::Current()); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 742 | if (GetParam()) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 743 | stream_ = MediaStream::Create("streamlabel"); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 744 | stream_->AddTrack(track_); |
| 745 | stats->AddStream(stream_); |
| 746 | } else { |
| 747 | stats->AddTrack(track_); |
| 748 | } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 749 | pc->AddRemoteTrack(kSsrcOfTrack, kRemoteTrackId); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | // Adds a outgoing audio track with a given SSRC into the stats, |
| 753 | // and register it into the stats object. |
| 754 | // If GetParam() returns true, the track is also inserted into the local |
| 755 | // stream, which is created if necessary. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 756 | void AddOutgoingAudioTrack(FakePeerConnectionForStats* pc, |
| 757 | StatsCollectorForTest* stats) { |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 758 | audio_track_ = new rtc::RefCountedObject<FakeAudioTrack>(kLocalTrackId); |
| 759 | if (GetParam()) { |
| 760 | if (!stream_) |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 761 | stream_ = MediaStream::Create("streamlabel"); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 762 | stream_->AddTrack(audio_track_); |
| 763 | stats->AddStream(stream_); |
| 764 | } else { |
| 765 | stats->AddTrack(audio_track_); |
| 766 | } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 767 | pc->AddLocalTrack(kSsrcOfTrack, kLocalTrackId); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | // Adds a incoming audio track with a given SSRC into the stats. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 771 | void AddIncomingAudioTrack(FakePeerConnectionForStats* pc, |
| 772 | StatsCollectorForTest* stats) { |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 773 | audio_track_ = new rtc::RefCountedObject<FakeAudioTrack>(kRemoteTrackId); |
| 774 | if (GetParam()) { |
| 775 | if (stream_ == NULL) |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 776 | stream_ = MediaStream::Create("streamlabel"); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 777 | stream_->AddTrack(audio_track_); |
| 778 | stats->AddStream(stream_); |
| 779 | } else { |
| 780 | stats->AddTrack(audio_track_); |
| 781 | } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 782 | pc->AddRemoteTrack(kSsrcOfTrack, kRemoteTrackId); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 783 | } |
| 784 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 785 | rtc::scoped_refptr<MediaStream> stream_; |
| 786 | rtc::scoped_refptr<VideoTrack> track_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 787 | rtc::scoped_refptr<FakeAudioTrack> audio_track_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 788 | }; |
| 789 | |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 790 | TEST_F(StatsCollectorTest, FilterOutNegativeDataChannelId) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 791 | auto pc = CreatePeerConnection(); |
| 792 | auto stats = CreateStatsCollector(pc); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 793 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 794 | pc->AddSctpDataChannel("hacks"); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 795 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 796 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 797 | StatsReports reports; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 798 | stats->GetStats(nullptr, &reports); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 799 | |
| 800 | const StatsReport* report = |
| 801 | FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1); |
| 802 | |
| 803 | std::string value_in_report; |
| 804 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameDataChannelId, |
| 805 | &value_in_report)); |
| 806 | } |
| 807 | |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 808 | // Verify that ExtractDataInfo populates reports. |
| 809 | TEST_F(StatsCollectorTest, ExtractDataInfo) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 810 | const std::string kDataChannelLabel = "hacks"; |
| 811 | constexpr int kDataChannelId = 31337; |
| 812 | const std::string kConnectingString = DataChannelInterface::DataStateString( |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 813 | DataChannelInterface::DataState::kConnecting); |
| 814 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 815 | auto pc = CreatePeerConnection(); |
| 816 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 817 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 818 | InternalDataChannelInit init; |
| 819 | init.id = kDataChannelId; |
| 820 | pc->AddSctpDataChannel(kDataChannelLabel, init); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 821 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 822 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 823 | StatsReports reports; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 824 | stats->GetStats(nullptr, &reports); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 825 | |
| 826 | const StatsReport* report = |
| 827 | FindNthReportByType(reports, StatsReport::kStatsReportTypeDataChannel, 1); |
| 828 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 829 | StatsReport::Id report_id = StatsReport::NewTypedIntId( |
| 830 | StatsReport::kStatsReportTypeDataChannel, kDataChannelId); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 831 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 832 | EXPECT_TRUE(report_id->Equals(report->id())); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 833 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 834 | EXPECT_EQ(stats->GetTimeNow(), report->timestamp()); |
| 835 | EXPECT_EQ(kDataChannelLabel, |
| 836 | ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, reports, |
| 837 | StatsReport::kStatsValueNameLabel)); |
| 838 | EXPECT_EQ(rtc::ToString<int64_t>(kDataChannelId), |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 839 | ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, reports, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 840 | StatsReport::kStatsValueNameDataChannelId)); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 841 | EXPECT_EQ(kConnectingString, |
| 842 | ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, reports, |
| 843 | StatsReport::kStatsValueNameState)); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 844 | EXPECT_EQ("", ExtractStatsValue(StatsReport::kStatsReportTypeDataChannel, |
| 845 | reports, |
| 846 | StatsReport::kStatsValueNameProtocol)); |
| 847 | } |
| 848 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 849 | // This test verifies that 64-bit counters are passed successfully. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 850 | TEST_P(StatsCollectorTrackTest, BytesCounterHandles64Bits) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 851 | // The number of bytes must be larger than 0xFFFFFFFF for this test. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 852 | constexpr int64_t kBytesSent = 12345678901234LL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 853 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 854 | auto pc = CreatePeerConnection(); |
| 855 | auto stats = CreateStatsCollector(pc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 856 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 857 | VideoSenderInfo video_sender_info; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 858 | video_sender_info.add_ssrc(1234); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 859 | video_sender_info.bytes_sent = kBytesSent; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 860 | VideoMediaInfo video_info; |
| 861 | video_info.senders.push_back(video_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 862 | |
| 863 | auto* video_media_channel = pc->AddVideoChannel("video", "transport"); |
| 864 | video_media_channel->SetStats(video_info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 865 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 866 | AddOutgoingVideoTrack(pc, stats.get()); |
| 867 | |
| 868 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 869 | StatsReports reports; |
| 870 | stats->GetStats(nullptr, &reports); |
| 871 | |
| 872 | EXPECT_EQ( |
| 873 | rtc::ToString(kBytesSent), |
| 874 | ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameBytesSent)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 877 | // Test that audio BWE information is reported via stats. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 878 | TEST_P(StatsCollectorTrackTest, AudioBandwidthEstimationInfoIsReported) { |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 879 | // Set up an SSRC just to test that we get both kinds of stats back: SSRC and |
| 880 | // BWE. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 881 | constexpr int64_t kBytesSent = 12345678901234LL; |
| 882 | constexpr int kSendBandwidth = 1234567; |
| 883 | constexpr int kRecvBandwidth = 12345678; |
| 884 | constexpr int kPacerDelay = 123; |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 885 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 886 | auto pc = CreatePeerConnection(); |
| 887 | auto stats = CreateStatsCollector(pc); |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 888 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 889 | VoiceSenderInfo voice_sender_info; |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 890 | voice_sender_info.add_ssrc(1234); |
| 891 | voice_sender_info.bytes_sent = kBytesSent; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 892 | VoiceMediaInfo voice_info; |
| 893 | voice_info.senders.push_back(voice_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 894 | |
| 895 | auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport"); |
| 896 | voice_media_channel->SetStats(voice_info); |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 897 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 898 | AddOutgoingAudioTrack(pc, stats.get()); |
| 899 | |
| 900 | Call::Stats call_stats; |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 901 | call_stats.send_bandwidth_bps = kSendBandwidth; |
| 902 | call_stats.recv_bandwidth_bps = kRecvBandwidth; |
| 903 | call_stats.pacer_delay_ms = kPacerDelay; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 904 | pc->SetCallStats(call_stats); |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 905 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 906 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 907 | StatsReports reports; |
| 908 | stats->GetStats(nullptr, &reports); |
| 909 | |
| 910 | EXPECT_EQ( |
| 911 | rtc::ToString(kBytesSent), |
| 912 | ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameBytesSent)); |
| 913 | EXPECT_EQ(rtc::ToString(kSendBandwidth), |
| 914 | ExtractBweStatsValue( |
| 915 | reports, StatsReport::kStatsValueNameAvailableSendBandwidth)); |
| 916 | EXPECT_EQ( |
| 917 | rtc::ToString(kRecvBandwidth), |
| 918 | ExtractBweStatsValue( |
| 919 | reports, StatsReport::kStatsValueNameAvailableReceiveBandwidth)); |
| 920 | EXPECT_EQ( |
| 921 | rtc::ToString(kPacerDelay), |
| 922 | ExtractBweStatsValue(reports, StatsReport::kStatsValueNameBucketDelay)); |
Alex Narest | 42308f6 | 2017-06-19 17:58:12 +0200 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // Test that video BWE information is reported via stats. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 926 | TEST_P(StatsCollectorTrackTest, VideoBandwidthEstimationInfoIsReported) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 927 | // Set up an SSRC just to test that we get both kinds of stats back: SSRC and |
| 928 | // BWE. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 929 | constexpr int64_t kBytesSent = 12345678901234LL; |
| 930 | constexpr int kSendBandwidth = 1234567; |
| 931 | constexpr int kRecvBandwidth = 12345678; |
| 932 | constexpr int kPacerDelay = 123; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 933 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 934 | auto pc = CreatePeerConnection(); |
| 935 | auto stats = CreateStatsCollector(pc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 936 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 937 | VideoSenderInfo video_sender_info; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 938 | video_sender_info.add_ssrc(1234); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 939 | video_sender_info.bytes_sent = kBytesSent; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 940 | VideoMediaInfo video_info; |
| 941 | video_info.senders.push_back(video_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 942 | |
| 943 | auto* video_media_channel = pc->AddVideoChannel("video", "transport"); |
| 944 | video_media_channel->SetStats(video_info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 945 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 946 | AddOutgoingVideoTrack(pc, stats.get()); |
| 947 | |
| 948 | Call::Stats call_stats; |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 949 | call_stats.send_bandwidth_bps = kSendBandwidth; |
| 950 | call_stats.recv_bandwidth_bps = kRecvBandwidth; |
| 951 | call_stats.pacer_delay_ms = kPacerDelay; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 952 | pc->SetCallStats(call_stats); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 953 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 954 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 955 | StatsReports reports; |
| 956 | stats->GetStats(nullptr, &reports); |
| 957 | |
| 958 | EXPECT_EQ( |
| 959 | rtc::ToString(kBytesSent), |
| 960 | ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameBytesSent)); |
| 961 | EXPECT_EQ(rtc::ToString(kSendBandwidth), |
| 962 | ExtractBweStatsValue( |
| 963 | reports, StatsReport::kStatsValueNameAvailableSendBandwidth)); |
| 964 | EXPECT_EQ( |
| 965 | rtc::ToString(kRecvBandwidth), |
| 966 | ExtractBweStatsValue( |
| 967 | reports, StatsReport::kStatsValueNameAvailableReceiveBandwidth)); |
| 968 | EXPECT_EQ( |
| 969 | rtc::ToString(kPacerDelay), |
| 970 | ExtractBweStatsValue(reports, StatsReport::kStatsValueNameBucketDelay)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | // This test verifies that an object of type "googSession" always |
| 974 | // exists in the returned stats. |
| 975 | TEST_F(StatsCollectorTest, SessionObjectExists) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 976 | auto pc = CreatePeerConnection(); |
| 977 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 978 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 979 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 980 | StatsReports reports; |
| 981 | stats->GetStats(nullptr, &reports); |
| 982 | |
| 983 | EXPECT_TRUE( |
| 984 | FindNthReportByType(reports, StatsReport::kStatsReportTypeSession, 1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | // This test verifies that only one object of type "googSession" exists |
| 988 | // in the returned stats. |
| 989 | TEST_F(StatsCollectorTest, OnlyOneSessionObjectExists) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 990 | auto pc = CreatePeerConnection(); |
| 991 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 992 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 993 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 994 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 995 | StatsReports reports; |
| 996 | stats->GetStats(nullptr, &reports); |
| 997 | |
| 998 | EXPECT_TRUE( |
| 999 | FindNthReportByType(reports, StatsReport::kStatsReportTypeSession, 1)); |
| 1000 | EXPECT_FALSE( |
| 1001 | FindNthReportByType(reports, StatsReport::kStatsReportTypeSession, 2)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | // This test verifies that the empty track report exists in the returned stats |
| 1005 | // without calling StatsCollector::UpdateStats. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1006 | TEST_P(StatsCollectorTrackTest, TrackObjectExistsWithoutUpdateStats) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1007 | auto pc = CreatePeerConnection(); |
| 1008 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1009 | |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1010 | pc->AddVideoChannel("video", "transport"); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1011 | AddOutgoingVideoTrack(pc, stats.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1012 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1013 | // Verfies the existence of the track report. |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1014 | StatsReports reports; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1015 | stats->GetStats(nullptr, &reports); |
| 1016 | ASSERT_EQ(1u, reports.size()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 1017 | EXPECT_EQ(StatsReport::kStatsReportTypeTrack, reports[0]->type()); |
jbauch | be24c94 | 2015-06-22 15:06:43 -0700 | [diff] [blame] | 1018 | EXPECT_EQ(0, reports[0]->timestamp()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1019 | |
| 1020 | std::string trackValue = |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1021 | ExtractStatsValue(StatsReport::kStatsReportTypeTrack, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1022 | reports, |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1023 | StatsReport::kStatsValueNameTrackId); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1024 | EXPECT_EQ(kLocalTrackId, trackValue); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | // This test verifies that the empty track report exists in the returned stats |
| 1028 | // when StatsCollector::UpdateStats is called with ssrc stats. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1029 | TEST_P(StatsCollectorTrackTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1030 | constexpr int64_t kBytesSent = 12345678901234LL; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1031 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1032 | auto pc = CreatePeerConnection(); |
| 1033 | auto stats = CreateStatsCollector(pc); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1034 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1035 | VideoSenderInfo video_sender_info; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 1036 | video_sender_info.add_ssrc(1234); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1037 | video_sender_info.bytes_sent = kBytesSent; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1038 | VideoMediaInfo video_info; |
| 1039 | video_info.senders.push_back(video_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1040 | |
| 1041 | auto* video_media_channel = pc->AddVideoChannel("video", "transport"); |
| 1042 | video_media_channel->SetStats(video_info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1043 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1044 | AddOutgoingVideoTrack(pc, stats.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1045 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1046 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1047 | StatsReports reports; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1048 | stats->GetStats(nullptr, &reports); |
| 1049 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1050 | // |reports| should contain at least one session report, one track report, |
| 1051 | // and one ssrc report. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1052 | EXPECT_LE(3u, reports.size()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1053 | const StatsReport* track_report = FindNthReportByType( |
| 1054 | reports, StatsReport::kStatsReportTypeTrack, 1); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1055 | EXPECT_TRUE(track_report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1056 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1057 | // Get report for the specific |track|. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 1058 | reports.clear(); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1059 | stats->GetStats(track_, &reports); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1060 | // |reports| should contain at least one session report, one track report, |
| 1061 | // and one ssrc report. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1062 | EXPECT_LE(3u, reports.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1063 | track_report = FindNthReportByType( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1064 | reports, StatsReport::kStatsReportTypeTrack, 1); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1065 | ASSERT_TRUE(track_report); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1066 | EXPECT_EQ(stats->GetTimeNow(), track_report->timestamp()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1067 | |
| 1068 | std::string ssrc_id = ExtractSsrcStatsValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1069 | reports, StatsReport::kStatsValueNameSsrc); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1070 | EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1071 | |
| 1072 | std::string track_id = ExtractSsrcStatsValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1073 | reports, StatsReport::kStatsValueNameTrackId); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1074 | EXPECT_EQ(kLocalTrackId, track_id); |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 1075 | |
| 1076 | std::string media_type = ExtractSsrcStatsValue(reports, |
| 1077 | StatsReport::kStatsValueNameMediaType); |
| 1078 | EXPECT_EQ("video", media_type); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | // This test verifies that an SSRC object has the identifier of a Transport |
| 1082 | // stats object, and that this transport stats object exists in stats. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1083 | TEST_P(StatsCollectorTrackTest, TransportObjectLinkedFromSsrcObject) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1084 | constexpr int64_t kBytesSent = 12345678901234LL; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1085 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1086 | auto pc = CreatePeerConnection(); |
| 1087 | auto stats = CreateStatsCollector(pc); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1088 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1089 | VideoSenderInfo video_sender_info; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 1090 | video_sender_info.add_ssrc(1234); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1091 | video_sender_info.bytes_sent = kBytesSent; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1092 | VideoMediaInfo video_info; |
| 1093 | video_info.senders.push_back(video_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1094 | |
| 1095 | auto* video_media_channel = pc->AddVideoChannel("video", "transport"); |
| 1096 | video_media_channel->SetStats(video_info); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1097 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1098 | AddOutgoingVideoTrack(pc, stats.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1099 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1100 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1101 | StatsReports reports; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1102 | stats->GetStats(nullptr, &reports); |
| 1103 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1104 | std::string transport_id = ExtractStatsValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1105 | StatsReport::kStatsReportTypeSsrc, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1106 | reports, |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1107 | StatsReport::kStatsValueNameTransportId); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1108 | ASSERT_NE(kNotFound, transport_id); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1109 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 1110 | // Transport id component ID will always be 1. |
| 1111 | // This has assumptions about how the ID is constructed. As is, this is |
| 1112 | // OK since this is for testing purposes only, but if we ever need this |
| 1113 | // in production, we should add a generic method that does this. |
| 1114 | size_t index = transport_id.find('-'); |
| 1115 | ASSERT_NE(std::string::npos, index); |
| 1116 | std::string content = transport_id.substr(index + 1); |
| 1117 | index = content.rfind('-'); |
| 1118 | ASSERT_NE(std::string::npos, index); |
| 1119 | content = content.substr(0, index); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1120 | StatsReport::Id id(StatsReport::NewComponentId(content, 1)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 1121 | ASSERT_EQ(transport_id, id->ToString()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 1122 | const StatsReport* transport_report = FindReportById(reports, id); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1123 | ASSERT_TRUE(transport_report); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1126 | // This test verifies that a remote stats object will not be created for |
| 1127 | // an outgoing SSRC where remote stats are not returned. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1128 | TEST_P(StatsCollectorTrackTest, RemoteSsrcInfoIsAbsent) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1129 | auto pc = CreatePeerConnection(); |
| 1130 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1131 | |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1132 | pc->AddVideoChannel("video", "transport"); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1133 | AddOutgoingVideoTrack(pc, stats.get()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1134 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1135 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1136 | StatsReports reports; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1137 | stats->GetStats(nullptr, &reports); |
| 1138 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1139 | const StatsReport* remote_report = FindNthReportByType(reports, |
| 1140 | StatsReport::kStatsReportTypeRemoteSsrc, 1); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1141 | EXPECT_FALSE(remote_report); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | // This test verifies that a remote stats object will be created for |
| 1145 | // an outgoing SSRC where stats are returned. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1146 | TEST_P(StatsCollectorTrackTest, RemoteSsrcInfoIsPresent) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1147 | auto pc = CreatePeerConnection(); |
| 1148 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1149 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1150 | SsrcReceiverInfo remote_ssrc_stats; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1151 | remote_ssrc_stats.timestamp = 12345.678; |
| 1152 | remote_ssrc_stats.ssrc = kSsrcOfTrack; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1153 | VideoSenderInfo video_sender_info; |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 1154 | video_sender_info.add_ssrc(kSsrcOfTrack); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1155 | video_sender_info.remote_stats.push_back(remote_ssrc_stats); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1156 | VideoMediaInfo video_info; |
| 1157 | video_info.senders.push_back(video_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1158 | |
| 1159 | auto* video_media_channel = pc->AddVideoChannel("video", "transport"); |
| 1160 | video_media_channel->SetStats(video_info); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1161 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1162 | AddOutgoingVideoTrack(pc, stats.get()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1163 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1164 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1165 | StatsReports reports; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1166 | stats->GetStats(nullptr, &reports); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1167 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1168 | const StatsReport* remote_report = FindNthReportByType(reports, |
| 1169 | StatsReport::kStatsReportTypeRemoteSsrc, 1); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1170 | ASSERT_TRUE(remote_report); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 1171 | EXPECT_EQ(12345.678, remote_report->timestamp()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1174 | // This test verifies that the empty track report exists in the returned stats |
| 1175 | // when StatsCollector::UpdateStats is called with ssrc stats. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1176 | TEST_P(StatsCollectorTrackTest, ReportsFromRemoteTrack) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1177 | constexpr int64_t kNumOfPacketsConcealed = 54321; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1178 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1179 | auto pc = CreatePeerConnection(); |
| 1180 | auto stats = CreateStatsCollector(pc); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1181 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1182 | VideoReceiverInfo video_receiver_info; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1183 | video_receiver_info.add_ssrc(1234); |
pbos@webrtc.org | 1ed6224 | 2015-02-19 13:57:03 +0000 | [diff] [blame] | 1184 | video_receiver_info.packets_concealed = kNumOfPacketsConcealed; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1185 | VideoMediaInfo video_info; |
| 1186 | video_info.receivers.push_back(video_receiver_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1187 | |
| 1188 | auto* video_media_info = pc->AddVideoChannel("video", "transport"); |
| 1189 | video_media_info->SetStats(video_info); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1190 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1191 | AddIncomingVideoTrack(pc, stats.get()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1192 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1193 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
tommi@webrtc.org | 03505bc | 2014-07-14 20:15:26 +0000 | [diff] [blame] | 1194 | StatsReports reports; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1195 | stats->GetStats(nullptr, &reports); |
| 1196 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1197 | // |reports| should contain at least one session report, one track report, |
| 1198 | // and one ssrc report. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1199 | EXPECT_LE(3u, reports.size()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1200 | const StatsReport* track_report = FindNthReportByType( |
| 1201 | reports, StatsReport::kStatsReportTypeTrack, 1); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1202 | ASSERT_TRUE(track_report); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1203 | EXPECT_EQ(stats->GetTimeNow(), track_report->timestamp()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1204 | |
| 1205 | std::string ssrc_id = ExtractSsrcStatsValue( |
| 1206 | reports, StatsReport::kStatsValueNameSsrc); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1207 | EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1208 | |
| 1209 | std::string track_id = ExtractSsrcStatsValue( |
| 1210 | reports, StatsReport::kStatsValueNameTrackId); |
| 1211 | EXPECT_EQ(kRemoteTrackId, track_id); |
| 1212 | } |
| 1213 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1214 | // This test verifies the Ice Candidate report should contain the correct |
| 1215 | // information from local/remote candidates. |
| 1216 | TEST_F(StatsCollectorTest, IceCandidateReport) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1217 | const std::string kTransportName = "transport"; |
| 1218 | const rtc::AdapterType kNetworkType = rtc::ADAPTER_TYPE_ETHERNET; |
| 1219 | constexpr uint32_t kPriority = 1000; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1220 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1221 | constexpr int kLocalPort = 2000; |
| 1222 | const std::string kLocalIp = "192.168.0.1"; |
| 1223 | const rtc::SocketAddress kLocalAddress(kLocalIp, kLocalPort); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1224 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1225 | constexpr int kRemotePort = 2001; |
| 1226 | const std::string kRemoteIp = "192.168.0.2"; |
| 1227 | const rtc::SocketAddress kRemoteAddress(kRemoteIp, kRemotePort); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1228 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1229 | auto pc = CreatePeerConnection(); |
| 1230 | auto stats = CreateStatsCollector(pc); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1231 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1232 | cricket::Candidate local; |
| 1233 | EXPECT_GT(local.id().length(), 0u); |
| 1234 | local.set_type(cricket::LOCAL_PORT_TYPE); |
| 1235 | local.set_protocol(cricket::UDP_PROTOCOL_NAME); |
| 1236 | local.set_address(kLocalAddress); |
| 1237 | local.set_priority(kPriority); |
| 1238 | local.set_network_type(kNetworkType); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1239 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1240 | cricket::Candidate remote; |
| 1241 | EXPECT_GT(remote.id().length(), 0u); |
| 1242 | remote.set_type(cricket::PRFLX_PORT_TYPE); |
| 1243 | remote.set_protocol(cricket::UDP_PROTOCOL_NAME); |
| 1244 | remote.set_address(kRemoteAddress); |
| 1245 | remote.set_priority(kPriority); |
| 1246 | remote.set_network_type(kNetworkType); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1247 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1248 | ConnectionInfo connection_info; |
| 1249 | connection_info.local_candidate = local; |
| 1250 | connection_info.remote_candidate = remote; |
| 1251 | TransportChannelStats channel_stats; |
| 1252 | channel_stats.connection_infos.push_back(connection_info); |
| 1253 | |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1254 | pc->AddVoiceChannel("audio", kTransportName); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1255 | pc->SetTransportStats(kTransportName, channel_stats); |
| 1256 | |
| 1257 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 1258 | StatsReports reports; |
| 1259 | stats->GetStats(nullptr, &reports); |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1260 | |
| 1261 | // Verify the local candidate report is populated correctly. |
| 1262 | EXPECT_EQ( |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1263 | "Cand-" + local.id(), |
| 1264 | ExtractStatsValue(StatsReport::kStatsReportTypeCandidatePair, reports, |
| 1265 | StatsReport::kStatsValueNameLocalCandidateId)); |
| 1266 | EXPECT_EQ( |
| 1267 | kLocalIp, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1268 | ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports, |
| 1269 | StatsReport::kStatsValueNameCandidateIPAddress)); |
| 1270 | EXPECT_EQ( |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1271 | rtc::ToString(kLocalPort), |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1272 | ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports, |
| 1273 | StatsReport::kStatsValueNameCandidatePortNumber)); |
| 1274 | EXPECT_EQ( |
| 1275 | cricket::UDP_PROTOCOL_NAME, |
| 1276 | ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports, |
| 1277 | StatsReport::kStatsValueNameCandidateTransportType)); |
| 1278 | EXPECT_EQ( |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1279 | rtc::ToString(kPriority), |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1280 | ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports, |
| 1281 | StatsReport::kStatsValueNameCandidatePriority)); |
| 1282 | EXPECT_EQ( |
| 1283 | IceCandidateTypeToStatsType(cricket::LOCAL_PORT_TYPE), |
| 1284 | ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports, |
| 1285 | StatsReport::kStatsValueNameCandidateType)); |
| 1286 | EXPECT_EQ( |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1287 | AdapterTypeToStatsType(kNetworkType), |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1288 | ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports, |
| 1289 | StatsReport::kStatsValueNameCandidateNetworkType)); |
| 1290 | |
| 1291 | // Verify the remote candidate report is populated correctly. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1292 | EXPECT_EQ( |
| 1293 | "Cand-" + remote.id(), |
| 1294 | ExtractStatsValue(StatsReport::kStatsReportTypeCandidatePair, reports, |
| 1295 | StatsReport::kStatsValueNameRemoteCandidateId)); |
| 1296 | EXPECT_EQ(kRemoteIp, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1297 | ExtractStatsValue(StatsReport::kStatsReportTypeIceRemoteCandidate, |
| 1298 | reports, |
| 1299 | StatsReport::kStatsValueNameCandidateIPAddress)); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1300 | EXPECT_EQ(rtc::ToString(kRemotePort), |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1301 | ExtractStatsValue(StatsReport::kStatsReportTypeIceRemoteCandidate, |
| 1302 | reports, |
| 1303 | StatsReport::kStatsValueNameCandidatePortNumber)); |
| 1304 | EXPECT_EQ(cricket::UDP_PROTOCOL_NAME, |
| 1305 | ExtractStatsValue( |
| 1306 | StatsReport::kStatsReportTypeIceRemoteCandidate, reports, |
| 1307 | StatsReport::kStatsValueNameCandidateTransportType)); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1308 | EXPECT_EQ(rtc::ToString(kPriority), |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1309 | ExtractStatsValue(StatsReport::kStatsReportTypeIceRemoteCandidate, |
| 1310 | reports, |
| 1311 | StatsReport::kStatsValueNameCandidatePriority)); |
| 1312 | EXPECT_EQ( |
| 1313 | IceCandidateTypeToStatsType(cricket::PRFLX_PORT_TYPE), |
| 1314 | ExtractStatsValue(StatsReport::kStatsReportTypeIceRemoteCandidate, |
| 1315 | reports, StatsReport::kStatsValueNameCandidateType)); |
| 1316 | EXPECT_EQ(kNotFound, |
| 1317 | ExtractStatsValue( |
| 1318 | StatsReport::kStatsReportTypeIceRemoteCandidate, reports, |
| 1319 | StatsReport::kStatsValueNameCandidateNetworkType)); |
| 1320 | } |
| 1321 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1322 | // This test verifies that all chained certificates are correctly |
| 1323 | // reported |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1324 | TEST_F(StatsCollectorTest, ChainedCertificateReportsCreated) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1325 | // Build local certificate chain. |
| 1326 | std::vector<std::string> local_ders(5); |
| 1327 | local_ders[0] = "These"; |
| 1328 | local_ders[1] = "are"; |
| 1329 | local_ders[2] = "some"; |
| 1330 | local_ders[3] = "der"; |
| 1331 | local_ders[4] = "values"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1332 | rtc::FakeSSLCertificate local_cert(DersToPems(local_ders)); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1333 | |
| 1334 | // Build remote certificate chain |
| 1335 | std::vector<std::string> remote_ders(4); |
| 1336 | remote_ders[0] = "A"; |
| 1337 | remote_ders[1] = "non-"; |
| 1338 | remote_ders[2] = "intersecting"; |
| 1339 | remote_ders[3] = "set"; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1340 | std::unique_ptr<rtc::FakeSSLCertificate> remote_cert( |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1341 | new rtc::FakeSSLCertificate(DersToPems(remote_ders))); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1342 | |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1343 | TestCertificateReports(local_cert, local_ders, std::move(remote_cert), |
| 1344 | remote_ders); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | // This test verifies that all certificates without chains are correctly |
| 1348 | // reported. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1349 | TEST_F(StatsCollectorTest, ChainlessCertificateReportsCreated) { |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1350 | // Build local certificate. |
| 1351 | std::string local_der = "This is the local der."; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1352 | rtc::FakeSSLCertificate local_cert(DerToPem(local_der)); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1353 | |
| 1354 | // Build remote certificate. |
| 1355 | std::string remote_der = "This is somebody else's der."; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1356 | std::unique_ptr<rtc::FakeSSLCertificate> remote_cert( |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1357 | new rtc::FakeSSLCertificate(DerToPem(remote_der))); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1358 | |
| 1359 | TestCertificateReports(local_cert, std::vector<std::string>(1, local_der), |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1360 | std::move(remote_cert), |
| 1361 | std::vector<std::string>(1, remote_der)); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | // This test verifies that the stats are generated correctly when no |
| 1365 | // transport is present. |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1366 | TEST_F(StatsCollectorTest, NoTransport) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1367 | auto pc = CreatePeerConnection(); |
| 1368 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1369 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1370 | // This will cause the fake PeerConnection to generate a TransportStats entry |
| 1371 | // but with only a single dummy TransportChannelStats. |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1372 | pc->AddVoiceChannel("audio", "transport"); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1373 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1374 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 1375 | StatsReports reports; |
| 1376 | stats->GetStats(nullptr, &reports); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1377 | |
| 1378 | // Check that the local certificate is absent. |
| 1379 | std::string local_certificate_id = ExtractStatsValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1380 | StatsReport::kStatsReportTypeComponent, |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1381 | reports, |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1382 | StatsReport::kStatsValueNameLocalCertificateId); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1383 | ASSERT_EQ(kNotFound, local_certificate_id); |
| 1384 | |
| 1385 | // Check that the remote certificate is absent. |
| 1386 | std::string remote_certificate_id = ExtractStatsValue( |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1387 | StatsReport::kStatsReportTypeComponent, |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1388 | reports, |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1389 | StatsReport::kStatsValueNameRemoteCertificateId); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1390 | ASSERT_EQ(kNotFound, remote_certificate_id); |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 1391 | |
| 1392 | // Check that the negotiated ciphers are absent. |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1393 | std::string dtls_cipher_suite = |
| 1394 | ExtractStatsValue(StatsReport::kStatsReportTypeComponent, reports, |
| 1395 | StatsReport::kStatsValueNameDtlsCipher); |
| 1396 | ASSERT_EQ(kNotFound, dtls_cipher_suite); |
| 1397 | std::string srtp_crypto_suite = |
| 1398 | ExtractStatsValue(StatsReport::kStatsReportTypeComponent, reports, |
| 1399 | StatsReport::kStatsValueNameSrtpCipher); |
| 1400 | ASSERT_EQ(kNotFound, srtp_crypto_suite); |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 1403 | // This test verifies that a remote certificate with an unsupported digest |
| 1404 | // algorithm is correctly ignored. |
| 1405 | TEST_F(StatsCollectorTest, UnsupportedDigestIgnored) { |
| 1406 | // Build a local certificate. |
| 1407 | std::string local_der = "This is the local der."; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1408 | rtc::FakeSSLCertificate local_cert(DerToPem(local_der)); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 1409 | |
| 1410 | // Build a remote certificate with an unsupported digest algorithm. |
| 1411 | std::string remote_der = "This is somebody else's der."; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1412 | std::unique_ptr<rtc::FakeSSLCertificate> remote_cert( |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1413 | new rtc::FakeSSLCertificate(DerToPem(remote_der))); |
| 1414 | remote_cert->set_digest_algorithm("foobar"); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 1415 | |
| 1416 | TestCertificateReports(local_cert, std::vector<std::string>(1, local_der), |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1417 | std::move(remote_cert), std::vector<std::string>()); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1420 | // This test verifies that the audio/video related stats which are -1 initially |
| 1421 | // will be filtered out. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1422 | TEST_P(StatsCollectorTrackTest, FilterOutNegativeInitialValues) { |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1423 | // This test uses streams, but only works for the stream case. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1424 | if (!GetParam()) { |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1425 | return; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1426 | } |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1427 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1428 | auto pc = CreatePeerConnection(); |
| 1429 | auto stats = CreateStatsCollector(pc); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1430 | |
| 1431 | // Create a local stream with a local audio track and adds it to the stats. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1432 | stream_ = MediaStream::Create("streamlabel"); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1433 | rtc::scoped_refptr<FakeAudioTrackWithInitValue> local_track( |
| 1434 | new rtc::RefCountedObject<FakeAudioTrackWithInitValue>(kLocalTrackId)); |
| 1435 | stream_->AddTrack(local_track); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1436 | pc->AddLocalTrack(kSsrcOfTrack, kLocalTrackId); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1437 | if (GetParam()) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1438 | stats->AddStream(stream_); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1439 | } |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1440 | stats->AddLocalAudioTrack(local_track.get(), kSsrcOfTrack); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1441 | |
| 1442 | // Create a remote stream with a remote audio track and adds it to the stats. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1443 | rtc::scoped_refptr<MediaStream> remote_stream( |
| 1444 | MediaStream::Create("remotestreamlabel")); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1445 | rtc::scoped_refptr<FakeAudioTrackWithInitValue> remote_track( |
| 1446 | new rtc::RefCountedObject<FakeAudioTrackWithInitValue>(kRemoteTrackId)); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1447 | remote_stream->AddTrack(remote_track); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1448 | pc->AddRemoteTrack(kSsrcOfTrack, kRemoteTrackId); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1449 | if (GetParam()) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1450 | stats->AddStream(remote_stream); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1451 | } |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1452 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1453 | VoiceSenderInfo voice_sender_info; |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1454 | voice_sender_info.add_ssrc(kSsrcOfTrack); |
| 1455 | // These values are set to -1 initially in audio_send_stream. |
| 1456 | // The voice_sender_info will read the values from audio_send_stream. |
| 1457 | voice_sender_info.rtt_ms = -1; |
| 1458 | voice_sender_info.packets_lost = -1; |
| 1459 | voice_sender_info.jitter_ms = -1; |
| 1460 | |
| 1461 | // Some of the contents in |voice_sender_info| needs to be updated from the |
| 1462 | // |audio_track_|. |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 1463 | UpdateVoiceSenderInfoFromAudioTrack(local_track.get(), &voice_sender_info, |
| 1464 | true); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1465 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1466 | VoiceReceiverInfo voice_receiver_info; |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1467 | voice_receiver_info.add_ssrc(kSsrcOfTrack); |
| 1468 | voice_receiver_info.capture_start_ntp_time_ms = -1; |
| 1469 | voice_receiver_info.audio_level = -1; |
| 1470 | |
| 1471 | // Constructs an ssrc stats update. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1472 | VoiceMediaInfo voice_info; |
| 1473 | voice_info.senders.push_back(voice_sender_info); |
| 1474 | voice_info.receivers.push_back(voice_receiver_info); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1475 | |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1476 | auto* voice_media_channel = pc->AddVoiceChannel("voice", "transport"); |
| 1477 | voice_media_channel->SetStats(voice_info); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1478 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1479 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1480 | |
| 1481 | // Get stats for the local track. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1482 | StatsReports reports; |
| 1483 | stats->GetStats(local_track.get(), &reports); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1484 | const StatsReport* report = |
| 1485 | FindNthReportByType(reports, StatsReport::kStatsReportTypeSsrc, 1); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1486 | ASSERT_TRUE(report); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1487 | // The -1 will not be added to the stats report. |
| 1488 | std::string value_in_report; |
| 1489 | EXPECT_FALSE( |
| 1490 | GetValue(report, StatsReport::kStatsValueNameRtt, &value_in_report)); |
| 1491 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNamePacketsLost, |
| 1492 | &value_in_report)); |
| 1493 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameJitterReceived, |
| 1494 | &value_in_report)); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1495 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameEchoDelayMedian, |
| 1496 | &value_in_report)); |
| 1497 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameEchoDelayStdDev, |
| 1498 | &value_in_report)); |
| 1499 | |
| 1500 | // Get stats for the remote track. |
| 1501 | reports.clear(); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1502 | stats->GetStats(remote_track.get(), &reports); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1503 | report = FindNthReportByType(reports, StatsReport::kStatsReportTypeSsrc, 1); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1504 | ASSERT_TRUE(report); |
zhihuang | 6ba3b19 | 2016-05-13 11:46:35 -0700 | [diff] [blame] | 1505 | EXPECT_FALSE(GetValue(report, |
| 1506 | StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 1507 | &value_in_report)); |
| 1508 | EXPECT_FALSE(GetValue(report, StatsReport::kStatsValueNameAudioInputLevel, |
| 1509 | &value_in_report)); |
| 1510 | } |
| 1511 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1512 | // This test verifies that a local stats object can get statistics via |
| 1513 | // AudioTrackInterface::GetStats() method. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1514 | TEST_P(StatsCollectorTrackTest, GetStatsFromLocalAudioTrack) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1515 | auto pc = CreatePeerConnection(); |
| 1516 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1517 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1518 | AddOutgoingAudioTrack(pc, stats.get()); |
| 1519 | stats->AddLocalAudioTrack(audio_track_, kSsrcOfTrack); |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 1520 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1521 | VoiceSenderInfo voice_sender_info; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1522 | InitVoiceSenderInfo(&voice_sender_info); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1523 | UpdateVoiceSenderInfoFromAudioTrack(audio_track_, &voice_sender_info, false); |
| 1524 | VoiceMediaInfo voice_info; |
| 1525 | voice_info.senders.push_back(voice_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1526 | |
| 1527 | auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport"); |
| 1528 | voice_media_channel->SetStats(voice_info); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1529 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1530 | StatsReports reports; // returned values. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1531 | VerifyAudioTrackStats(audio_track_, stats.get(), voice_info, &reports); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1532 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1533 | // Verify that there is no remote report for the local audio track because |
| 1534 | // we did not set it up. |
| 1535 | const StatsReport* remote_report = FindNthReportByType(reports, |
| 1536 | StatsReport::kStatsReportTypeRemoteSsrc, 1); |
| 1537 | EXPECT_TRUE(remote_report == NULL); |
| 1538 | } |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 1539 | |
| 1540 | // This test verifies that audio receive streams populate stats reports |
| 1541 | // correctly. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1542 | TEST_P(StatsCollectorTrackTest, GetStatsFromRemoteStream) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1543 | auto pc = CreatePeerConnection(); |
| 1544 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1545 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1546 | AddIncomingAudioTrack(pc, stats.get()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1547 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1548 | VoiceReceiverInfo voice_receiver_info; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1549 | InitVoiceReceiverInfo(&voice_receiver_info); |
buildbot@webrtc.org | 7e71b77 | 2014-06-13 01:14:01 +0000 | [diff] [blame] | 1550 | voice_receiver_info.codec_name = "fake_codec"; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1551 | VoiceMediaInfo voice_info; |
| 1552 | voice_info.receivers.push_back(voice_receiver_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1553 | |
| 1554 | auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport"); |
| 1555 | voice_media_channel->SetStats(voice_info); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 1556 | |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 1557 | StatsReports reports; // returned values. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1558 | VerifyAudioTrackStats(audio_track_, stats.get(), voice_info, &reports); |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1561 | // This test verifies that a local stats object won't update its statistics |
| 1562 | // after a RemoveLocalAudioTrack() call. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1563 | TEST_P(StatsCollectorTrackTest, GetStatsAfterRemoveAudioStream) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1564 | auto pc = CreatePeerConnection(); |
| 1565 | auto stats = CreateStatsCollector(pc); |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 1566 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1567 | AddOutgoingAudioTrack(pc, stats.get()); |
| 1568 | stats->AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1569 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1570 | VoiceSenderInfo voice_sender_info; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1571 | InitVoiceSenderInfo(&voice_sender_info); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1572 | VoiceMediaInfo voice_info; |
| 1573 | voice_info.senders.push_back(voice_sender_info); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1574 | |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1575 | auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport"); |
| 1576 | voice_media_channel->SetStats(voice_info); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1577 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1578 | stats->RemoveLocalAudioTrack(audio_track_.get(), kSsrcOfTrack); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1579 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1580 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 1581 | StatsReports reports; |
| 1582 | stats->GetStats(nullptr, &reports); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1583 | |
| 1584 | // The report will exist since we don't remove them in RemoveStream(). |
| 1585 | const StatsReport* report = FindNthReportByType( |
| 1586 | reports, StatsReport::kStatsReportTypeSsrc, 1); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1587 | ASSERT_TRUE(report); |
| 1588 | EXPECT_EQ(stats->GetTimeNow(), report->timestamp()); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1589 | std::string track_id = ExtractSsrcStatsValue( |
| 1590 | reports, StatsReport::kStatsValueNameTrackId); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1591 | EXPECT_EQ(kLocalTrackId, track_id); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1592 | std::string ssrc_id = ExtractSsrcStatsValue( |
| 1593 | reports, StatsReport::kStatsValueNameSsrc); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1594 | EXPECT_EQ(rtc::ToString<uint32_t>(kSsrcOfTrack), ssrc_id); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 1595 | |
| 1596 | // Verifies the values in the track report, no value will be changed by the |
| 1597 | // AudioTrackInterface::GetSignalValue() and |
| 1598 | // AudioProcessorInterface::AudioProcessorStats::GetStats(); |
| 1599 | VerifyVoiceSenderInfoReport(report, voice_sender_info); |
| 1600 | } |
| 1601 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1602 | // This test verifies that when ongoing and incoming audio tracks are using |
| 1603 | // the same ssrc, they populate stats reports correctly. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1604 | TEST_P(StatsCollectorTrackTest, LocalAndRemoteTracksWithSameSsrc) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1605 | auto pc = CreatePeerConnection(); |
| 1606 | auto stats = CreateStatsCollector(pc); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1607 | |
| 1608 | // Create a local stream with a local audio track and adds it to the stats. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1609 | AddOutgoingAudioTrack(pc, stats.get()); |
| 1610 | stats->AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1611 | |
| 1612 | // Create a remote stream with a remote audio track and adds it to the stats. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1613 | rtc::scoped_refptr<MediaStream> remote_stream( |
| 1614 | MediaStream::Create("remotestreamlabel")); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1615 | rtc::scoped_refptr<FakeAudioTrack> remote_track( |
| 1616 | new rtc::RefCountedObject<FakeAudioTrack>(kRemoteTrackId)); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1617 | pc->AddRemoteTrack(kSsrcOfTrack, kRemoteTrackId); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1618 | remote_stream->AddTrack(remote_track); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1619 | stats->AddStream(remote_stream); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1620 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1621 | VoiceSenderInfo voice_sender_info; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1622 | InitVoiceSenderInfo(&voice_sender_info); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1623 | // Some of the contents in |voice_sender_info| needs to be updated from the |
| 1624 | // |audio_track_|. |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 1625 | UpdateVoiceSenderInfoFromAudioTrack(audio_track_.get(), &voice_sender_info, |
| 1626 | true); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1627 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1628 | VoiceReceiverInfo voice_receiver_info; |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1629 | InitVoiceReceiverInfo(&voice_receiver_info); |
| 1630 | |
| 1631 | // Constructs an ssrc stats update. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1632 | VoiceMediaInfo voice_info; |
| 1633 | voice_info.senders.push_back(voice_sender_info); |
| 1634 | voice_info.receivers.push_back(voice_receiver_info); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1635 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1636 | // Instruct the session to return stats containing the transport channel. |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1637 | auto* voice_media_channel = pc->AddVoiceChannel("audio", "transport"); |
| 1638 | voice_media_channel->SetStats(voice_info); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1639 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1640 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1641 | |
| 1642 | // Get stats for the local track. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1643 | StatsReports reports; // returned values. |
| 1644 | stats->GetStats(audio_track_.get(), &reports); |
| 1645 | |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1646 | const StatsReport* track_report = FindNthReportByType( |
| 1647 | reports, StatsReport::kStatsReportTypeSsrc, 1); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1648 | ASSERT_TRUE(track_report); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1649 | EXPECT_EQ(stats->GetTimeNow(), track_report->timestamp()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1650 | std::string track_id = ExtractSsrcStatsValue( |
| 1651 | reports, StatsReport::kStatsValueNameTrackId); |
| 1652 | EXPECT_EQ(kLocalTrackId, track_id); |
| 1653 | VerifyVoiceSenderInfoReport(track_report, voice_sender_info); |
| 1654 | |
| 1655 | // Get stats for the remote track. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 1656 | reports.clear(); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1657 | stats->GetStats(remote_track.get(), &reports); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1658 | track_report = FindNthReportByType(reports, |
| 1659 | StatsReport::kStatsReportTypeSsrc, 1); |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1660 | ASSERT_TRUE(track_report); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1661 | EXPECT_EQ(stats->GetTimeNow(), track_report->timestamp()); |
xians@webrtc.org | 4cb0128 | 2014-06-12 14:57:05 +0000 | [diff] [blame] | 1662 | track_id = ExtractSsrcStatsValue(reports, |
| 1663 | StatsReport::kStatsValueNameTrackId); |
| 1664 | EXPECT_EQ(kRemoteTrackId, track_id); |
| 1665 | VerifyVoiceReceiverInfoReport(track_report, voice_receiver_info); |
| 1666 | } |
| 1667 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1668 | // This test verifies that when two outgoing audio tracks are using the same |
| 1669 | // ssrc at different times, they populate stats reports correctly. |
| 1670 | // TODO(xians): Figure out if it is possible to encapsulate the setup and |
| 1671 | // avoid duplication of code in test cases. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1672 | TEST_P(StatsCollectorTrackTest, TwoLocalTracksWithSameSsrc) { |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1673 | // This test only makes sense when we're using streams. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1674 | if (!GetParam()) { |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1675 | return; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1676 | } |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1677 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1678 | auto pc = CreatePeerConnection(); |
| 1679 | auto stats = CreateStatsCollector(pc); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1680 | |
| 1681 | // Create a local stream with a local audio track and adds it to the stats. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1682 | AddOutgoingAudioTrack(pc, stats.get()); |
| 1683 | stats->AddLocalAudioTrack(audio_track_, kSsrcOfTrack); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1684 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1685 | VoiceSenderInfo voice_sender_info; |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 1686 | InitVoiceSenderInfo(&voice_sender_info); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1687 | UpdateVoiceSenderInfoFromAudioTrack(audio_track_, &voice_sender_info, false); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1688 | voice_sender_info.add_ssrc(kSsrcOfTrack); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1689 | VoiceMediaInfo voice_info; |
| 1690 | voice_info.senders.push_back(voice_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1691 | |
| 1692 | auto* voice_media_channel = pc->AddVoiceChannel("voice", "transport"); |
| 1693 | voice_media_channel->SetStats(voice_info); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1694 | |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1695 | StatsReports reports; // returned values. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1696 | VerifyAudioTrackStats(audio_track_, stats.get(), voice_info, &reports); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1697 | |
| 1698 | // Remove the previous audio track from the stream. |
| 1699 | stream_->RemoveTrack(audio_track_.get()); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1700 | stats->RemoveLocalAudioTrack(audio_track_.get(), kSsrcOfTrack); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1701 | |
| 1702 | // Create a new audio track and adds it to the stream and stats. |
| 1703 | static const std::string kNewTrackId = "new_track_id"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1704 | rtc::scoped_refptr<FakeAudioTrack> new_audio_track( |
| 1705 | new rtc::RefCountedObject<FakeAudioTrack>(kNewTrackId)); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1706 | pc->AddLocalTrack(kSsrcOfTrack, kNewTrackId); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1707 | stream_->AddTrack(new_audio_track); |
| 1708 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1709 | stats->AddLocalAudioTrack(new_audio_track, kSsrcOfTrack); |
| 1710 | stats->ClearUpdateStatsCacheForTest(); |
| 1711 | |
| 1712 | VoiceSenderInfo new_voice_sender_info; |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1713 | InitVoiceSenderInfo(&new_voice_sender_info); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1714 | UpdateVoiceSenderInfoFromAudioTrack(new_audio_track, &new_voice_sender_info, |
| 1715 | false); |
| 1716 | VoiceMediaInfo new_voice_info; |
| 1717 | new_voice_info.senders.push_back(new_voice_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1718 | voice_media_channel->SetStats(new_voice_info); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1719 | |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 1720 | reports.clear(); |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1721 | VerifyAudioTrackStats(new_audio_track, stats.get(), new_voice_info, &reports); |
xians@webrtc.org | 01bda20 | 2014-07-09 07:38:38 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 1724 | // This test verifies that stats are correctly set in video send ssrc stats. |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1725 | TEST_P(StatsCollectorTrackTest, VerifyVideoSendSsrcStats) { |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1726 | auto pc = CreatePeerConnection(); |
| 1727 | auto stats = CreateStatsCollector(pc); |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 1728 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1729 | AddOutgoingVideoTrack(pc, stats.get()); |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 1730 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1731 | VideoSenderInfo video_sender_info; |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 1732 | video_sender_info.add_ssrc(1234); |
| 1733 | video_sender_info.frames_encoded = 10; |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1734 | video_sender_info.qp_sum = 11; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1735 | VideoMediaInfo video_info; |
| 1736 | video_info.senders.push_back(video_sender_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1737 | |
| 1738 | auto* video_media_channel = pc->AddVideoChannel("video", "transport"); |
| 1739 | video_media_channel->SetStats(video_info); |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 1740 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1741 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 1742 | StatsReports reports; |
| 1743 | stats->GetStats(nullptr, &reports); |
| 1744 | |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 1745 | EXPECT_EQ(rtc::ToString(video_sender_info.frames_encoded), |
| 1746 | ExtractSsrcStatsValue(reports, |
| 1747 | StatsReport::kStatsValueNameFramesEncoded)); |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 1748 | EXPECT_EQ(rtc::ToString(*video_sender_info.qp_sum), |
| 1749 | ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameQpSum)); |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1752 | // This test verifies that stats are correctly set in video receive ssrc stats. |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1753 | TEST_P(StatsCollectorTrackTest, VerifyVideoReceiveSsrcStatsNew) { |
| 1754 | auto pc = CreatePeerConnection(); |
| 1755 | auto stats = CreateStatsCollector(pc); |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1756 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1757 | AddIncomingVideoTrack(pc, stats.get()); |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1758 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1759 | VideoReceiverInfo video_receiver_info; |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1760 | video_receiver_info.add_ssrc(1234); |
| 1761 | video_receiver_info.frames_decoded = 10; |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1762 | video_receiver_info.qp_sum = 11; |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1763 | VideoMediaInfo video_info; |
| 1764 | video_info.receivers.push_back(video_receiver_info); |
Steve Anton | 5b38731 | 2018-02-02 16:00:20 -0800 | [diff] [blame] | 1765 | |
| 1766 | auto* video_media_channel = pc->AddVideoChannel("video", "transport"); |
| 1767 | video_media_channel->SetStats(video_info); |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1768 | |
Steve Anton | 3871f6f | 2018-01-26 10:25:53 -0800 | [diff] [blame] | 1769 | stats->UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); |
| 1770 | StatsReports reports; |
| 1771 | stats->GetStats(nullptr, &reports); |
| 1772 | |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1773 | EXPECT_EQ(rtc::ToString(video_receiver_info.frames_decoded), |
| 1774 | ExtractSsrcStatsValue(reports, |
| 1775 | StatsReport::kStatsValueNameFramesDecoded)); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 1776 | EXPECT_EQ(rtc::ToString(*video_receiver_info.qp_sum), |
| 1777 | ExtractSsrcStatsValue(reports, StatsReport::kStatsValueNameQpSum)); |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Harald Alvestrand | 75ceef2 | 2018-01-04 15:26:13 +0100 | [diff] [blame] | 1780 | INSTANTIATE_TEST_CASE_P(HasStream, StatsCollectorTrackTest, ::testing::Bool()); |
| 1781 | |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 1782 | } // namespace webrtc |