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