pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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. |
| 9 | */ |
asapersson | f8cdd18 | 2016-03-15 08:00:47 | [diff] [blame] | 10 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 11 | #include <algorithm> |
asapersson | f8cdd18 | 2016-03-15 08:00:47 | [diff] [blame] | 12 | #include <limits> |
kwiberg | b25345e | 2016-03-12 14:10:44 | [diff] [blame] | 13 | #include <memory> |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 16 | #include "absl/strings/string_view.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 18 | #include "api/numerics/samples_stats_counter.h" |
Danil Chapovalov | 83bbe91 | 2019-08-07 10:24:53 | [diff] [blame] | 19 | #include "api/rtc_event_log/rtc_event_log.h" |
Artem Titov | c374d11 | 2022-06-16 19:27:45 | [diff] [blame] | 20 | #include "api/task_queue/pending_task_safety_flag.h" |
Danil Chapovalov | 44db436 | 2019-09-30 02:16:28 | [diff] [blame] | 21 | #include "api/task_queue/task_queue_base.h" |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 22 | #include "api/test/metrics/global_metrics_logger_and_exporter.h" |
| 23 | #include "api/test/metrics/metric.h" |
Artem Titov | 46c4e60 | 2018-08-17 12:26:54 | [diff] [blame] | 24 | #include "api/test/simulated_network.h" |
Jiawei Ou | c2ebe21 | 2018-11-08 18:02:56 | [diff] [blame] | 25 | #include "api/video/builtin_video_bitrate_allocator_factory.h" |
Erik Språng | ef75ebe | 2018-05-15 13:18:36 | [diff] [blame] | 26 | #include "api/video/video_bitrate_allocation.h" |
Elad Alon | 370f93a | 2019-06-11 12:57:57 | [diff] [blame] | 27 | #include "api/video_codecs/video_encoder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 28 | #include "call/call.h" |
Artem Titov | 4e199e9 | 2018-08-20 11:30:39 | [diff] [blame] | 29 | #include "call/fake_network_pipe.h" |
| 30 | #include "call/simulated_network.h" |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 31 | #include "media/engine/internal_encoder_factory.h" |
| 32 | #include "media/engine/simulcast_encoder_adapter.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 33 | #include "modules/audio_coding/include/audio_coding_module.h" |
Artem Titov | 3faa832 | 2018-03-07 13:44:00 | [diff] [blame] | 34 | #include "modules/audio_device/include/test_audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 35 | #include "modules/audio_mixer/audio_mixer_impl.h" |
Danil Chapovalov | 1b4e4bf | 2019-12-06 11:34:57 | [diff] [blame] | 36 | #include "modules/rtp_rtcp/source/rtp_packet.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 37 | #include "rtc_base/checks.h" |
Markus Handell | 8fe932a | 2020-07-06 15:41:35 | [diff] [blame] | 38 | #include "rtc_base/synchronization/mutex.h" |
Danil Chapovalov | 82a3f0a | 2019-10-21 07:24:27 | [diff] [blame] | 39 | #include "rtc_base/task_queue_for_test.h" |
Niels Möller | a837030 | 2019-09-02 13:16:49 | [diff] [blame] | 40 | #include "rtc_base/thread.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 41 | #include "rtc_base/thread_annotations.h" |
Mirko Bonadei | 17f4878 | 2018-09-28 06:51:10 | [diff] [blame] | 42 | #include "system_wrappers/include/metrics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 43 | #include "test/call_test.h" |
| 44 | #include "test/direct_transport.h" |
| 45 | #include "test/drifting_clock.h" |
| 46 | #include "test/encoder_settings.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 47 | #include "test/fake_encoder.h" |
| 48 | #include "test/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 49 | #include "test/frame_generator_capturer.h" |
| 50 | #include "test/gtest.h" |
Niels Möller | ae4237e | 2018-10-05 09:28:38 | [diff] [blame] | 51 | #include "test/null_transport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 52 | #include "test/rtp_rtcp_observer.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 53 | #include "test/testsupport/file_utils.h" |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 54 | #include "test/video_encoder_proxy_factory.h" |
Jonas Oreland | 6c2dae2 | 2022-09-29 08:28:24 | [diff] [blame] | 55 | #include "video/config/video_encoder_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 56 | #include "video/transport_adapter.h" |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 57 | |
danilchap | 9c6a0c7 | 2016-02-10 18:54:47 | [diff] [blame] | 58 | using webrtc::test::DriftingClock; |
danilchap | 9c6a0c7 | 2016-02-10 18:54:47 | [diff] [blame] | 59 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 60 | namespace webrtc { |
Elad Alon | d8d3248 | 2019-02-18 22:45:57 | [diff] [blame] | 61 | namespace { |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 62 | |
| 63 | using ::webrtc::test::GetGlobalMetricsLogger; |
| 64 | using ::webrtc::test::ImprovementDirection; |
| 65 | using ::webrtc::test::Unit; |
| 66 | |
Elad Alon | d8d3248 | 2019-02-18 22:45:57 | [diff] [blame] | 67 | enum : int { // The first valid value is 1. |
| 68 | kTransportSequenceNumberExtensionId = 1, |
| 69 | }; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 70 | |
Elad Alon | d8d3248 | 2019-02-18 22:45:57 | [diff] [blame] | 71 | } // namespace |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 72 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 73 | class CallPerfTest : public test::CallTest { |
Elad Alon | d8d3248 | 2019-02-18 22:45:57 | [diff] [blame] | 74 | public: |
| 75 | CallPerfTest() { |
| 76 | RegisterRtpExtension(RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 77 | kTransportSequenceNumberExtensionId)); |
| 78 | } |
| 79 | |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 80 | protected: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 81 | enum class FecMode { kOn, kOff }; |
| 82 | enum class CreateOrder { kAudioFirst, kVideoFirst }; |
Danil Chapovalov | cde5d6b | 2016-02-15 10:14:58 | [diff] [blame] | 83 | void TestAudioVideoSync(FecMode fec, |
| 84 | CreateOrder create_first, |
danilchap | 9c6a0c7 | 2016-02-10 18:54:47 | [diff] [blame] | 85 | float video_ntp_speed, |
| 86 | float video_rtp_speed, |
Edward Lemur | 947f3fe | 2017-12-28 14:50:33 | [diff] [blame] | 87 | float audio_rtp_speed, |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 88 | absl::string_view test_label); |
stefan@webrtc.org | 01581da | 2014-09-04 06:48:14 | [diff] [blame] | 89 | |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 90 | void TestMinTransmitBitrate(bool pad_to_min_bitrate); |
| 91 | |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 92 | void TestCaptureNtpTime(const BuiltInNetworkBehaviorConfig& net_config, |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 93 | int threshold_ms, |
| 94 | int start_time_ms, |
| 95 | int run_time_ms); |
Jonas Olsson | 0182a03 | 2019-07-09 10:31:20 | [diff] [blame] | 96 | void TestMinAudioVideoBitrate(int test_bitrate_from, |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 97 | int test_bitrate_to, |
| 98 | int test_bitrate_step, |
| 99 | int min_bwe, |
| 100 | int start_bwe, |
| 101 | int max_bwe); |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 102 | void TestEncodeFramerate(VideoEncoderFactory* encoder_factory, |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 103 | absl::string_view payload_name, |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 104 | const std::vector<int>& max_framerates); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 105 | }; |
| 106 | |
asapersson | f8cdd18 | 2016-03-15 08:00:47 | [diff] [blame] | 107 | class VideoRtcpAndSyncObserver : public test::RtpRtcpObserver, |
nisse | 7ade7b3 | 2016-03-23 11:48:10 | [diff] [blame] | 108 | public rtc::VideoSinkInterface<VideoFrame> { |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 109 | static const int kInSyncThresholdMs = 50; |
| 110 | static const int kStartupTimeMs = 2000; |
| 111 | static const int kMinRunTimeMs = 30000; |
| 112 | |
| 113 | public: |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 114 | explicit VideoRtcpAndSyncObserver(TaskQueueBase* task_queue, |
| 115 | Clock* clock, |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 116 | absl::string_view test_label) |
Markus Handell | f4f2287 | 2022-08-16 11:02:45 | [diff] [blame] | 117 | : test::RtpRtcpObserver(CallPerfTest::kLongTimeout), |
asapersson | f8cdd18 | 2016-03-15 08:00:47 | [diff] [blame] | 118 | clock_(clock), |
Edward Lemur | 947f3fe | 2017-12-28 14:50:33 | [diff] [blame] | 119 | test_label_(test_label), |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 120 | creation_time_ms_(clock_->TimeInMilliseconds()), |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 121 | task_queue_(task_queue) {} |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 122 | |
nisse | eb83a1a | 2016-03-21 08:27:56 | [diff] [blame] | 123 | void OnFrame(const VideoFrame& video_frame) override { |
Danil Chapovalov | b7128ed | 2022-07-06 16:35:01 | [diff] [blame] | 124 | task_queue_->PostTask([this]() { CheckStats(); }); |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void CheckStats() { |
| 128 | if (!receive_stream_) |
| 129 | return; |
| 130 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 131 | VideoReceiveStreamInterface::Stats stats = receive_stream_->GetStats(); |
asapersson | f8cdd18 | 2016-03-15 08:00:47 | [diff] [blame] | 132 | if (stats.sync_offset_ms == std::numeric_limits<int>::max()) |
| 133 | return; |
| 134 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 135 | int64_t now_ms = clock_->TimeInMilliseconds(); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 136 | int64_t time_since_creation = now_ms - creation_time_ms_; |
| 137 | // During the first couple of seconds audio and video can falsely be |
| 138 | // estimated as being synchronized. We don't want to trigger on those. |
| 139 | if (time_since_creation < kStartupTimeMs) |
| 140 | return; |
asapersson | f8cdd18 | 2016-03-15 08:00:47 | [diff] [blame] | 141 | if (std::abs(stats.sync_offset_ms) < kInSyncThresholdMs) { |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 142 | if (first_time_in_sync_ == -1) { |
| 143 | first_time_in_sync_ = now_ms; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 144 | GetGlobalMetricsLogger()->LogSingleValueMetric( |
| 145 | "sync_convergence_time" + test_label_, "synchronization", |
| 146 | time_since_creation, Unit::kMilliseconds, |
| 147 | ImprovementDirection::kSmallerIsBetter); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 148 | } |
| 149 | if (time_since_creation > kMinRunTimeMs) |
Peter Boström | 5811a39 | 2015-12-10 12:02:50 | [diff] [blame] | 150 | observation_complete_.Set(); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 151 | } |
Danil Chapovalov | 371b43b | 2016-06-16 07:58:44 | [diff] [blame] | 152 | if (first_time_in_sync_ != -1) |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 153 | sync_offset_ms_list_.AddSample(stats.sync_offset_ms); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 154 | } |
| 155 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 156 | void set_receive_stream(VideoReceiveStreamInterface* receive_stream) { |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 157 | RTC_DCHECK_EQ(task_queue_, TaskQueueBase::Current()); |
| 158 | // Note that receive_stream may be nullptr. |
asapersson | f8cdd18 | 2016-03-15 08:00:47 | [diff] [blame] | 159 | receive_stream_ = receive_stream; |
| 160 | } |
| 161 | |
danilchap | 46b89b9 | 2016-06-03 16:27:37 | [diff] [blame] | 162 | void PrintResults() { |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 163 | GetGlobalMetricsLogger()->LogMetric( |
| 164 | "stream_offset" + test_label_, "synchronization", sync_offset_ms_list_, |
| 165 | Unit::kMilliseconds, ImprovementDirection::kNeitherIsBetter); |
danilchap | 46b89b9 | 2016-06-03 16:27:37 | [diff] [blame] | 166 | } |
| 167 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 168 | private: |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 | [diff] [blame] | 169 | Clock* const clock_; |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 170 | const std::string test_label_; |
stefan | f116bd0 | 2015-10-27 15:29:42 | [diff] [blame] | 171 | const int64_t creation_time_ms_; |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 172 | int64_t first_time_in_sync_ = -1; |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 173 | VideoReceiveStreamInterface* receive_stream_ = nullptr; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 174 | SamplesStatsCounter sync_offset_ms_list_; |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 175 | TaskQueueBase* const task_queue_; |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 176 | }; |
| 177 | |
Danil Chapovalov | cde5d6b | 2016-02-15 10:14:58 | [diff] [blame] | 178 | void CallPerfTest::TestAudioVideoSync(FecMode fec, |
| 179 | CreateOrder create_first, |
danilchap | 9c6a0c7 | 2016-02-10 18:54:47 | [diff] [blame] | 180 | float video_ntp_speed, |
| 181 | float video_rtp_speed, |
Edward Lemur | 947f3fe | 2017-12-28 14:50:33 | [diff] [blame] | 182 | float audio_rtp_speed, |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 183 | absl::string_view test_label) { |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 184 | const char* kSyncGroup = "av_sync"; |
Stefan Holmer | b86d4e4 | 2015-12-07 09:26:18 | [diff] [blame] | 185 | const uint32_t kAudioSendSsrc = 1234; |
| 186 | const uint32_t kAudioRecvSsrc = 5678; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 187 | |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 188 | BuiltInNetworkBehaviorConfig audio_net_config; |
mflodman | 3d7db26 | 2016-04-29 07:57:13 | [diff] [blame] | 189 | audio_net_config.queue_delay_ms = 500; |
| 190 | audio_net_config.loss_percent = 5; |
minyue | 20c84cc | 2017-04-10 23:57:57 | [diff] [blame] | 191 | |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 192 | auto observer = std::make_unique<VideoRtcpAndSyncObserver>( |
| 193 | task_queue(), Clock::GetRealTimeClock(), test_label); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 194 | |
minyue | 20c84cc | 2017-04-10 23:57:57 | [diff] [blame] | 195 | std::map<uint8_t, MediaType> audio_pt_map; |
| 196 | std::map<uint8_t, MediaType> video_pt_map; |
minyue | 20c84cc | 2017-04-10 23:57:57 | [diff] [blame] | 197 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 198 | std::unique_ptr<test::PacketTransport> audio_send_transport; |
| 199 | std::unique_ptr<test::PacketTransport> video_send_transport; |
| 200 | std::unique_ptr<test::PacketTransport> receive_transport; |
mflodman | 3d7db26 | 2016-04-29 07:57:13 | [diff] [blame] | 201 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 202 | AudioSendStream* audio_send_stream; |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 203 | AudioReceiveStreamInterface* audio_receive_stream; |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 204 | std::unique_ptr<DriftingClock> drifting_clock; |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 205 | |
Danil Chapovalov | e519f38 | 2022-08-11 10:26:09 | [diff] [blame] | 206 | SendTask(task_queue(), [&]() { |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 207 | metrics::Reset(); |
Artem Titov | 3faa832 | 2018-03-07 13:44:00 | [diff] [blame] | 208 | rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device = |
Danil Chapovalov | 08fa953 | 2019-06-12 11:49:17 | [diff] [blame] | 209 | TestAudioDeviceModule::Create( |
| 210 | task_queue_factory_.get(), |
Artem Titov | 3faa832 | 2018-03-07 13:44:00 | [diff] [blame] | 211 | TestAudioDeviceModule::CreatePulsedNoiseCapturer(256, 48000), |
| 212 | TestAudioDeviceModule::CreateDiscardRenderer(48000), |
| 213 | audio_rtp_speed); |
Fredrik Solenberg | d319534 | 2017-11-21 19:33:05 | [diff] [blame] | 214 | EXPECT_EQ(0, fake_audio_device->Init()); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 215 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 216 | AudioState::Config send_audio_state_config; |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 217 | send_audio_state_config.audio_mixer = AudioMixerImpl::Create(); |
Ivo Creusen | 62337e5 | 2018-01-09 13:17:33 | [diff] [blame] | 218 | send_audio_state_config.audio_processing = |
| 219 | AudioProcessingBuilder().Create(); |
Fredrik Solenberg | 2a87797 | 2017-12-15 15:42:15 | [diff] [blame] | 220 | send_audio_state_config.audio_device_module = fake_audio_device; |
Sebastian Jansson | 8e6602f | 2018-07-13 08:43:20 | [diff] [blame] | 221 | Call::Config sender_config(send_event_log_.get()); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 222 | |
Fredrik Solenberg | d319534 | 2017-11-21 19:33:05 | [diff] [blame] | 223 | auto audio_state = AudioState::Create(send_audio_state_config); |
| 224 | fake_audio_device->RegisterAudioCallback(audio_state->audio_transport()); |
| 225 | sender_config.audio_state = audio_state; |
Sebastian Jansson | 8e6602f | 2018-07-13 08:43:20 | [diff] [blame] | 226 | Call::Config receiver_config(recv_event_log_.get()); |
Fredrik Solenberg | d319534 | 2017-11-21 19:33:05 | [diff] [blame] | 227 | receiver_config.audio_state = audio_state; |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 228 | CreateCalls(sender_config, receiver_config); |
| 229 | |
| 230 | std::copy_if(std::begin(payload_type_map_), std::end(payload_type_map_), |
| 231 | std::inserter(audio_pt_map, audio_pt_map.end()), |
| 232 | [](const std::pair<const uint8_t, MediaType>& pair) { |
| 233 | return pair.second == MediaType::AUDIO; |
| 234 | }); |
| 235 | std::copy_if(std::begin(payload_type_map_), std::end(payload_type_map_), |
| 236 | std::inserter(video_pt_map, video_pt_map.end()), |
| 237 | [](const std::pair<const uint8_t, MediaType>& pair) { |
| 238 | return pair.second == MediaType::VIDEO; |
| 239 | }); |
| 240 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 241 | audio_send_transport = std::make_unique<test::PacketTransport>( |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 242 | task_queue(), sender_call_.get(), observer.get(), |
Artem Titov | 4e199e9 | 2018-08-20 11:30:39 | [diff] [blame] | 243 | test::PacketTransport::kSender, audio_pt_map, |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 244 | std::make_unique<FakeNetworkPipe>( |
Artem Titov | 4e199e9 | 2018-08-20 11:30:39 | [diff] [blame] | 245 | Clock::GetRealTimeClock(), |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 246 | std::make_unique<SimulatedNetwork>(audio_net_config))); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 247 | audio_send_transport->SetReceiver(receiver_call_->Receiver()); |
| 248 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 249 | video_send_transport = std::make_unique<test::PacketTransport>( |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 250 | task_queue(), sender_call_.get(), observer.get(), |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 251 | test::PacketTransport::kSender, video_pt_map, |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 252 | std::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(), |
| 253 | std::make_unique<SimulatedNetwork>( |
| 254 | BuiltInNetworkBehaviorConfig()))); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 255 | video_send_transport->SetReceiver(receiver_call_->Receiver()); |
| 256 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 257 | receive_transport = std::make_unique<test::PacketTransport>( |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 258 | task_queue(), receiver_call_.get(), observer.get(), |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 259 | test::PacketTransport::kReceiver, payload_type_map_, |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 260 | std::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(), |
| 261 | std::make_unique<SimulatedNetwork>( |
| 262 | BuiltInNetworkBehaviorConfig()))); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 263 | receive_transport->SetReceiver(sender_call_->Receiver()); |
| 264 | |
| 265 | CreateSendConfig(1, 0, 0, video_send_transport.get()); |
| 266 | CreateMatchingReceiveConfigs(receive_transport.get()); |
| 267 | |
Bjorn A Mellem | 7a9a092 | 2019-11-26 17:19:40 | [diff] [blame] | 268 | AudioSendStream::Config audio_send_config(audio_send_transport.get()); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 269 | audio_send_config.rtp.ssrc = kAudioSendSsrc; |
Oskar Sundbom | fedc00c | 2017-11-16 09:55:08 | [diff] [blame] | 270 | audio_send_config.send_codec_spec = AudioSendStream::Config::SendCodecSpec( |
| 271 | kAudioSendPayloadType, {"ISAC", 16000, 1}); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 272 | audio_send_config.encoder_factory = CreateBuiltinAudioEncoderFactory(); |
| 273 | audio_send_stream = sender_call_->CreateAudioSendStream(audio_send_config); |
| 274 | |
Sebastian Jansson | f33905d | 2018-07-13 07:49:00 | [diff] [blame] | 275 | GetVideoSendConfig()->rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 276 | if (fec == FecMode::kOn) { |
Sebastian Jansson | f33905d | 2018-07-13 07:49:00 | [diff] [blame] | 277 | GetVideoSendConfig()->rtp.ulpfec.red_payload_type = kRedPayloadType; |
| 278 | GetVideoSendConfig()->rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType; |
nisse | 3b3622f | 2017-09-26 09:49:21 | [diff] [blame] | 279 | video_receive_configs_[0].rtp.red_payload_type = kRedPayloadType; |
| 280 | video_receive_configs_[0].rtp.ulpfec_payload_type = kUlpfecPayloadType; |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 281 | } |
| 282 | video_receive_configs_[0].rtp.nack.rtp_history_ms = 1000; |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 283 | video_receive_configs_[0].renderer = observer.get(); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 284 | video_receive_configs_[0].sync_group = kSyncGroup; |
| 285 | |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 286 | AudioReceiveStreamInterface::Config audio_recv_config; |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 287 | audio_recv_config.rtp.remote_ssrc = kAudioSendSsrc; |
| 288 | audio_recv_config.rtp.local_ssrc = kAudioRecvSsrc; |
Jakob Ivarsson | 4cd92d8 | 2020-10-31 11:40:43 | [diff] [blame] | 289 | audio_recv_config.rtcp_send_transport = receive_transport.get(); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 290 | audio_recv_config.sync_group = kSyncGroup; |
Niels Möller | 2784a03 | 2018-03-28 12:16:04 | [diff] [blame] | 291 | audio_recv_config.decoder_factory = audio_decoder_factory_; |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 292 | audio_recv_config.decoder_map = { |
| 293 | {kAudioSendPayloadType, {"ISAC", 16000, 1}}}; |
| 294 | |
| 295 | if (create_first == CreateOrder::kAudioFirst) { |
| 296 | audio_receive_stream = |
| 297 | receiver_call_->CreateAudioReceiveStream(audio_recv_config); |
| 298 | CreateVideoStreams(); |
| 299 | } else { |
| 300 | CreateVideoStreams(); |
| 301 | audio_receive_stream = |
| 302 | receiver_call_->CreateAudioReceiveStream(audio_recv_config); |
| 303 | } |
| 304 | EXPECT_EQ(1u, video_receive_streams_.size()); |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 305 | observer->set_receive_stream(video_receive_streams_[0]); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 306 | drifting_clock = std::make_unique<DriftingClock>(clock_, video_ntp_speed); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 307 | CreateFrameGeneratorCapturerWithDrift(drifting_clock.get(), video_rtp_speed, |
| 308 | kDefaultFramerate, kDefaultWidth, |
| 309 | kDefaultHeight); |
| 310 | |
| 311 | Start(); |
| 312 | |
| 313 | audio_send_stream->Start(); |
| 314 | audio_receive_stream->Start(); |
| 315 | }); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 316 | |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 317 | EXPECT_TRUE(observer->Wait()) |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 318 | << "Timed out while waiting for audio and video to be synchronized."; |
| 319 | |
Danil Chapovalov | e519f38 | 2022-08-11 10:26:09 | [diff] [blame] | 320 | SendTask(task_queue(), [&]() { |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 321 | // Clear the pointer to the receive stream since it will now be deleted. |
| 322 | observer->set_receive_stream(nullptr); |
| 323 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 324 | audio_send_stream->Stop(); |
| 325 | audio_receive_stream->Stop(); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 326 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 327 | Stop(); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 328 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 329 | DestroyStreams(); |
Stefan Holmer | b86d4e4 | 2015-12-07 09:26:18 | [diff] [blame] | 330 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 331 | sender_call_->DestroyAudioSendStream(audio_send_stream); |
| 332 | receiver_call_->DestroyAudioReceiveStream(audio_receive_stream); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 333 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 334 | DestroyCalls(); |
Danil Chapovalov | 5d2bf19 | 2020-12-30 16:12:27 | [diff] [blame] | 335 | // Call may post periodic rtcp packet to the transport on the process |
| 336 | // thread, thus transport should be destroyed after the call objects. |
| 337 | // Though transports keep pointers to the call objects, transports handle |
| 338 | // packets on the task_queue() and thus wouldn't create a race while current |
| 339 | // destruction happens in the same task as destruction of the call objects. |
| 340 | video_send_transport.reset(); |
| 341 | audio_send_transport.reset(); |
| 342 | receive_transport.reset(); |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 343 | }); |
asapersson | f8cdd18 | 2016-03-15 08:00:47 | [diff] [blame] | 344 | |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 345 | observer->PrintResults(); |
ilnik | 5328b9e | 2017-02-21 13:20:28 | [diff] [blame] | 346 | |
| 347 | // In quick test synchronization may not be achieved in time. |
sprang | e5d3a3e | 2017-03-01 14:20:56 | [diff] [blame] | 348 | if (!field_trial::IsEnabled("WebRTC-QuickPerfTest")) { |
Artem Titarenko | ded1e4f | 2019-03-15 10:36:39 | [diff] [blame] | 349 | // TODO(bugs.webrtc.org/10417): Reenable this for iOS |
| 350 | #if !defined(WEBRTC_IOS) |
Ying Wang | ef3998f | 2019-12-09 12:06:53 | [diff] [blame] | 351 | EXPECT_METRIC_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs")); |
Artem Titarenko | ded1e4f | 2019-03-15 10:36:39 | [diff] [blame] | 352 | #endif |
ilnik | 5328b9e | 2017-02-21 13:20:28 | [diff] [blame] | 353 | } |
Tommi | 3c9bcc1 | 2020-04-15 14:45:47 | [diff] [blame] | 354 | |
| 355 | task_queue()->PostTask( |
Danil Chapovalov | b7128ed | 2022-07-06 16:35:01 | [diff] [blame] | 356 | [to_delete = observer.release()]() { delete to_delete; }); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 357 | } |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 358 | |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 359 | TEST_F(CallPerfTest, Synchronization_PlaysOutAudioAndVideoWithoutClockDrift) { |
Niels Möller | 9a75061 | 2018-08-09 09:04:32 | [diff] [blame] | 360 | TestAudioVideoSync(FecMode::kOff, CreateOrder::kAudioFirst, |
| 361 | DriftingClock::kNoDrift, DriftingClock::kNoDrift, |
| 362 | DriftingClock::kNoDrift, "_video_no_drift"); |
| 363 | } |
| 364 | |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 365 | TEST_F(CallPerfTest, Synchronization_PlaysOutAudioAndVideoWithVideoNtpDrift) { |
Danil Chapovalov | cde5d6b | 2016-02-15 10:14:58 | [diff] [blame] | 366 | TestAudioVideoSync(FecMode::kOff, CreateOrder::kAudioFirst, |
| 367 | DriftingClock::PercentsFaster(10.0f), |
Edward Lemur | 947f3fe | 2017-12-28 14:50:33 | [diff] [blame] | 368 | DriftingClock::kNoDrift, DriftingClock::kNoDrift, |
| 369 | "_video_ntp_drift"); |
danilchap | 9c6a0c7 | 2016-02-10 18:54:47 | [diff] [blame] | 370 | } |
| 371 | |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 372 | TEST_F(CallPerfTest, |
| 373 | Synchronization_PlaysOutAudioAndVideoWithAudioFasterThanVideoDrift) { |
Danil Chapovalov | cde5d6b | 2016-02-15 10:14:58 | [diff] [blame] | 374 | TestAudioVideoSync(FecMode::kOff, CreateOrder::kAudioFirst, |
| 375 | DriftingClock::kNoDrift, |
danilchap | 9c6a0c7 | 2016-02-10 18:54:47 | [diff] [blame] | 376 | DriftingClock::PercentsSlower(30.0f), |
Edward Lemur | 947f3fe | 2017-12-28 14:50:33 | [diff] [blame] | 377 | DriftingClock::PercentsFaster(30.0f), "_audio_faster"); |
danilchap | 9c6a0c7 | 2016-02-10 18:54:47 | [diff] [blame] | 378 | } |
| 379 | |
Danil Chapovalov | 5d2bf19 | 2020-12-30 16:12:27 | [diff] [blame] | 380 | TEST_F(CallPerfTest, |
| 381 | Synchronization_PlaysOutAudioAndVideoWithVideoFasterThanAudioDrift) { |
Danil Chapovalov | cde5d6b | 2016-02-15 10:14:58 | [diff] [blame] | 382 | TestAudioVideoSync(FecMode::kOn, CreateOrder::kVideoFirst, |
| 383 | DriftingClock::kNoDrift, |
danilchap | 9c6a0c7 | 2016-02-10 18:54:47 | [diff] [blame] | 384 | DriftingClock::PercentsFaster(30.0f), |
Edward Lemur | 947f3fe | 2017-12-28 14:50:33 | [diff] [blame] | 385 | DriftingClock::PercentsSlower(30.0f), "_video_faster"); |
stefan@webrtc.org | 01581da | 2014-09-04 06:48:14 | [diff] [blame] | 386 | } |
| 387 | |
Artem Titov | 46c4e60 | 2018-08-17 12:26:54 | [diff] [blame] | 388 | void CallPerfTest::TestCaptureNtpTime( |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 389 | const BuiltInNetworkBehaviorConfig& net_config, |
Artem Titov | 46c4e60 | 2018-08-17 12:26:54 | [diff] [blame] | 390 | int threshold_ms, |
| 391 | int start_time_ms, |
| 392 | int run_time_ms) { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 393 | class CaptureNtpTimeObserver : public test::EndToEndTest, |
nisse | 7ade7b3 | 2016-03-23 11:48:10 | [diff] [blame] | 394 | public rtc::VideoSinkInterface<VideoFrame> { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 395 | public: |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 396 | CaptureNtpTimeObserver(const BuiltInNetworkBehaviorConfig& net_config, |
stefan | e74eef1 | 2016-01-08 14:47:13 | [diff] [blame] | 397 | int threshold_ms, |
| 398 | int start_time_ms, |
| 399 | int run_time_ms) |
Markus Handell | f4f2287 | 2022-08-16 11:02:45 | [diff] [blame] | 400 | : EndToEndTest(kLongTimeout), |
stefan | e74eef1 | 2016-01-08 14:47:13 | [diff] [blame] | 401 | net_config_(net_config), |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 402 | clock_(Clock::GetRealTimeClock()), |
| 403 | threshold_ms_(threshold_ms), |
| 404 | start_time_ms_(start_time_ms), |
| 405 | run_time_ms_(run_time_ms), |
| 406 | creation_time_ms_(clock_->TimeInMilliseconds()), |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 407 | capturer_(nullptr), |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 408 | rtp_start_timestamp_set_(false), |
| 409 | rtp_start_timestamp_(0) {} |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 410 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 411 | private: |
Danil Chapovalov | 44db436 | 2019-09-30 02:16:28 | [diff] [blame] | 412 | std::unique_ptr<test::PacketTransport> CreateSendTransport( |
| 413 | TaskQueueBase* task_queue, |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 414 | Call* sender_call) override { |
Danil Chapovalov | 44db436 | 2019-09-30 02:16:28 | [diff] [blame] | 415 | return std::make_unique<test::PacketTransport>( |
Artem Titov | 4e199e9 | 2018-08-20 11:30:39 | [diff] [blame] | 416 | task_queue, sender_call, this, test::PacketTransport::kSender, |
| 417 | payload_type_map_, |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 418 | std::make_unique<FakeNetworkPipe>( |
Artem Titov | 4e199e9 | 2018-08-20 11:30:39 | [diff] [blame] | 419 | Clock::GetRealTimeClock(), |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 420 | std::make_unique<SimulatedNetwork>(net_config_))); |
stefan | e74eef1 | 2016-01-08 14:47:13 | [diff] [blame] | 421 | } |
| 422 | |
Danil Chapovalov | 44db436 | 2019-09-30 02:16:28 | [diff] [blame] | 423 | std::unique_ptr<test::PacketTransport> CreateReceiveTransport( |
| 424 | TaskQueueBase* task_queue) override { |
| 425 | return std::make_unique<test::PacketTransport>( |
Artem Titov | 4e199e9 | 2018-08-20 11:30:39 | [diff] [blame] | 426 | task_queue, nullptr, this, test::PacketTransport::kReceiver, |
| 427 | payload_type_map_, |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 428 | std::make_unique<FakeNetworkPipe>( |
Artem Titov | 4e199e9 | 2018-08-20 11:30:39 | [diff] [blame] | 429 | Clock::GetRealTimeClock(), |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 430 | std::make_unique<SimulatedNetwork>(net_config_))); |
Stefan Holmer | ea8c0f6 | 2016-01-13 07:58:38 | [diff] [blame] | 431 | } |
| 432 | |
nisse | eb83a1a | 2016-03-21 08:27:56 | [diff] [blame] | 433 | void OnFrame(const VideoFrame& video_frame) override { |
Markus Handell | 8fe932a | 2020-07-06 15:41:35 | [diff] [blame] | 434 | MutexLock lock(&mutex_); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 435 | if (video_frame.ntp_time_ms() <= 0) { |
| 436 | // Haven't got enough RTCP SR in order to calculate the capture ntp |
| 437 | // time. |
| 438 | return; |
| 439 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 440 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 441 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 442 | int64_t time_since_creation = now_ms - creation_time_ms_; |
| 443 | if (time_since_creation < start_time_ms_) { |
Artem Titov | ea24027 | 2021-07-26 10:40:21 | [diff] [blame] | 444 | // Wait for `start_time_ms_` before start measuring. |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 445 | return; |
| 446 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 447 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 448 | if (time_since_creation > run_time_ms_) { |
Peter Boström | 5811a39 | 2015-12-10 12:02:50 | [diff] [blame] | 449 | observation_complete_.Set(); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 450 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 451 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 452 | FrameCaptureTimeList::iterator iter = |
| 453 | capture_time_list_.find(video_frame.timestamp()); |
| 454 | EXPECT_TRUE(iter != capture_time_list_.end()); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 455 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 456 | // The real capture time has been wrapped to uint32_t before converted |
| 457 | // to rtp timestamp in the sender side. So here we convert the estimated |
| 458 | // capture time to a uint32_t 90k timestamp also for comparing. |
| 459 | uint32_t estimated_capture_timestamp = |
| 460 | 90 * static_cast<uint32_t>(video_frame.ntp_time_ms()); |
| 461 | uint32_t real_capture_timestamp = iter->second; |
| 462 | int time_offset_ms = real_capture_timestamp - estimated_capture_timestamp; |
| 463 | time_offset_ms = time_offset_ms / 90; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 464 | time_offset_ms_list_.AddSample(time_offset_ms); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 465 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 466 | EXPECT_TRUE(std::abs(time_offset_ms) < threshold_ms_); |
| 467 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 468 | |
nisse | ef8b61e | 2016-04-29 13:09:15 | [diff] [blame] | 469 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
Markus Handell | 8fe932a | 2020-07-06 15:41:35 | [diff] [blame] | 470 | MutexLock lock(&mutex_); |
Danil Chapovalov | 1b4e4bf | 2019-12-06 11:34:57 | [diff] [blame] | 471 | RtpPacket rtp_packet; |
| 472 | EXPECT_TRUE(rtp_packet.Parse(packet, length)); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 473 | |
| 474 | if (!rtp_start_timestamp_set_) { |
| 475 | // Calculate the rtp timestamp offset in order to calculate the real |
| 476 | // capture time. |
| 477 | uint32_t first_capture_timestamp = |
| 478 | 90 * static_cast<uint32_t>(capturer_->first_frame_capture_time()); |
Danil Chapovalov | 1b4e4bf | 2019-12-06 11:34:57 | [diff] [blame] | 479 | rtp_start_timestamp_ = rtp_packet.Timestamp() - first_capture_timestamp; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 480 | rtp_start_timestamp_set_ = true; |
| 481 | } |
| 482 | |
Danil Chapovalov | 1b4e4bf | 2019-12-06 11:34:57 | [diff] [blame] | 483 | uint32_t capture_timestamp = |
| 484 | rtp_packet.Timestamp() - rtp_start_timestamp_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 485 | capture_time_list_.insert( |
| 486 | capture_time_list_.end(), |
Danil Chapovalov | 1b4e4bf | 2019-12-06 11:34:57 | [diff] [blame] | 487 | std::make_pair(rtp_packet.Timestamp(), capture_timestamp)); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 488 | return SEND_PACKET; |
| 489 | } |
| 490 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 491 | void OnFrameGeneratorCapturerCreated( |
| 492 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 493 | capturer_ = frame_generator_capturer; |
| 494 | } |
| 495 | |
stefan | ff48361 | 2015-12-21 11:14:00 | [diff] [blame] | 496 | void ModifyVideoConfigs( |
| 497 | VideoSendStream::Config* send_config, |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 498 | std::vector<VideoReceiveStreamInterface::Config>* receive_configs, |
stefan | ff48361 | 2015-12-21 11:14:00 | [diff] [blame] | 499 | VideoEncoderConfig* encoder_config) override { |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 | [diff] [blame] | 500 | (*receive_configs)[0].renderer = this; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 501 | // Enable the receiver side rtt calculation. |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 | [diff] [blame] | 502 | (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 503 | } |
| 504 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 505 | void PerformTest() override { |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 506 | EXPECT_TRUE(Wait()) << "Timed out while waiting for estimated capture " |
| 507 | "NTP time to be within bounds."; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 508 | GetGlobalMetricsLogger()->LogMetric( |
| 509 | "capture_ntp_time", "real - estimated", time_offset_ms_list_, |
| 510 | Unit::kMilliseconds, ImprovementDirection::kNeitherIsBetter); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 511 | } |
| 512 | |
Markus Handell | 8fe932a | 2020-07-06 15:41:35 | [diff] [blame] | 513 | Mutex mutex_; |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 514 | const BuiltInNetworkBehaviorConfig net_config_; |
stefan | f116bd0 | 2015-10-27 15:29:42 | [diff] [blame] | 515 | Clock* const clock_; |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 516 | const int threshold_ms_; |
| 517 | const int start_time_ms_; |
| 518 | const int run_time_ms_; |
| 519 | const int64_t creation_time_ms_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 520 | test::FrameGeneratorCapturer* capturer_; |
| 521 | bool rtp_start_timestamp_set_; |
| 522 | uint32_t rtp_start_timestamp_; |
| 523 | typedef std::map<uint32_t, uint32_t> FrameCaptureTimeList; |
Markus Handell | 8fe932a | 2020-07-06 15:41:35 | [diff] [blame] | 524 | FrameCaptureTimeList capture_time_list_ RTC_GUARDED_BY(&mutex_); |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 525 | SamplesStatsCounter time_offset_ms_list_; |
stefan | e74eef1 | 2016-01-08 14:47:13 | [diff] [blame] | 526 | } test(net_config, threshold_ms, start_time_ms, run_time_ms); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 527 | |
stefan | e74eef1 | 2016-01-08 14:47:13 | [diff] [blame] | 528 | RunBaseTest(&test); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 529 | } |
| 530 | |
Alex Loiko | af228ee | 2018-11-22 10:53:18 | [diff] [blame] | 531 | // Flaky tests, disabled on Mac and Windows due to webrtc:8291. |
| 532 | #if !(defined(WEBRTC_MAC) || defined(WEBRTC_WIN)) |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 533 | TEST_F(CallPerfTest, Real_Estimated_CaptureNtpTimeWithNetworkDelay) { |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 534 | BuiltInNetworkBehaviorConfig net_config; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 535 | net_config.queue_delay_ms = 100; |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 536 | // TODO(wu): lower the threshold as the calculation/estimation becomes more |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 537 | // accurate. |
wu@webrtc.org | 9aa7d8d | 2014-05-29 05:03:52 | [diff] [blame] | 538 | const int kThresholdMs = 100; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 539 | const int kStartTimeMs = 10000; |
| 540 | const int kRunTimeMs = 20000; |
| 541 | TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); |
| 542 | } |
| 543 | |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 544 | TEST_F(CallPerfTest, Real_Estimated_CaptureNtpTimeWithNetworkJitter) { |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 545 | BuiltInNetworkBehaviorConfig net_config; |
wu@webrtc.org | 0224c20 | 2014-05-05 17:42:43 | [diff] [blame] | 546 | net_config.queue_delay_ms = 100; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 547 | net_config.delay_standard_deviation_ms = 10; |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 548 | // TODO(wu): lower the threshold as the calculation/estimation becomes more |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 549 | // accurate. |
wu@webrtc.org | 0224c20 | 2014-05-05 17:42:43 | [diff] [blame] | 550 | const int kThresholdMs = 100; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 551 | const int kStartTimeMs = 10000; |
| 552 | const int kRunTimeMs = 20000; |
| 553 | TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); |
| 554 | } |
Alex Loiko | 5aea38c | 2017-09-27 11:10:28 | [diff] [blame] | 555 | #endif |
kthelgason | fa5fdce | 2017-02-27 08:15:31 | [diff] [blame] | 556 | |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 557 | TEST_F(CallPerfTest, ReceivesCpuOveruseAndUnderuse) { |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 558 | // Minimal normal usage at the start, then 30s overuse to allow filter to |
| 559 | // settle, and then 80s underuse to allow plenty of time for rampup again. |
| 560 | test::ScopedFieldTrials fake_overuse_settings( |
| 561 | "WebRTC-ForceSimulatedOveruseIntervalMs/1-30000-80000/"); |
| 562 | |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 563 | class LoadObserver : public test::SendTest, |
| 564 | public test::FrameGeneratorCapturer::SinkWantsObserver { |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 565 | public: |
Markus Handell | f4f2287 | 2022-08-16 11:02:45 | [diff] [blame] | 566 | LoadObserver() : SendTest(kLongTimeout), test_phase_(TestPhase::kInit) {} |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 567 | |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 568 | void OnFrameGeneratorCapturerCreated( |
| 569 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
| 570 | frame_generator_capturer->SetSinkWantsObserver(this); |
kthelgason | fa5fdce | 2017-02-27 08:15:31 | [diff] [blame] | 571 | // Set a high initial resolution to be sure that we can scale down. |
| 572 | frame_generator_capturer->ChangeResolution(1920, 1080); |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink |
| 576 | // is called. |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 577 | // TODO(sprang): Add integration test for maintain-framerate mode? |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 578 | void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 579 | const rtc::VideoSinkWants& wants) override { |
Henrik Boström | 1124ed1 | 2021-02-25 09:30:39 | [diff] [blame] | 580 | // The sink wants can change either because an adaptation happened (i.e. |
| 581 | // the pixels or frame rate changed) or for other reasons, such as encoded |
| 582 | // resolutions being communicated (happens whenever we capture a new frame |
| 583 | // size). In this test, we only care about adaptations. |
| 584 | bool did_adapt = |
| 585 | last_wants_.max_pixel_count != wants.max_pixel_count || |
| 586 | last_wants_.target_pixel_count != wants.target_pixel_count || |
| 587 | last_wants_.max_framerate_fps != wants.max_framerate_fps; |
| 588 | last_wants_ = wants; |
| 589 | if (!did_adapt) { |
| 590 | return; |
| 591 | } |
Åsa Persson | 8c1bf95 | 2018-09-13 08:42:19 | [diff] [blame] | 592 | // At kStart expect CPU overuse. Then expect CPU underuse when the encoder |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 593 | // delay has been decreased. |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 594 | switch (test_phase_) { |
Åsa Persson | 8c1bf95 | 2018-09-13 08:42:19 | [diff] [blame] | 595 | case TestPhase::kInit: |
| 596 | // Max framerate should be set initially. |
| 597 | if (wants.max_framerate_fps != std::numeric_limits<int>::max() && |
| 598 | wants.max_pixel_count == std::numeric_limits<int>::max()) { |
| 599 | test_phase_ = TestPhase::kStart; |
| 600 | } else { |
| 601 | ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 602 | << wants.max_pixel_count << ", target res = " |
| 603 | << wants.target_pixel_count.value_or(-1) |
| 604 | << ", max fps = " << wants.max_framerate_fps; |
| 605 | } |
| 606 | break; |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 607 | case TestPhase::kStart: |
| 608 | if (wants.max_pixel_count < std::numeric_limits<int>::max()) { |
mflodman | cc3d442 | 2017-08-03 15:27:51 | [diff] [blame] | 609 | // On adapting down, VideoStreamEncoder::VideoSourceProxy will set |
| 610 | // only the max pixel count, leaving the target unset. |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 611 | test_phase_ = TestPhase::kAdaptedDown; |
| 612 | } else { |
| 613 | ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 614 | << wants.max_pixel_count << ", target res = " |
| 615 | << wants.target_pixel_count.value_or(-1) |
| 616 | << ", max fps = " << wants.max_framerate_fps; |
| 617 | } |
| 618 | break; |
| 619 | case TestPhase::kAdaptedDown: |
| 620 | // On adapting up, the adaptation counter will again be at zero, and |
| 621 | // so all constraints will be reset. |
| 622 | if (wants.max_pixel_count == std::numeric_limits<int>::max() && |
| 623 | !wants.target_pixel_count) { |
| 624 | test_phase_ = TestPhase::kAdaptedUp; |
| 625 | observation_complete_.Set(); |
| 626 | } else { |
| 627 | ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 628 | << wants.max_pixel_count << ", target res = " |
| 629 | << wants.target_pixel_count.value_or(-1) |
| 630 | << ", max fps = " << wants.max_framerate_fps; |
| 631 | } |
| 632 | break; |
| 633 | case TestPhase::kAdaptedUp: |
| 634 | ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 635 | << wants.max_pixel_count << ", target res = " |
| 636 | << wants.target_pixel_count.value_or(-1) |
| 637 | << ", max fps = " << wants.max_framerate_fps; |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 638 | } |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 639 | } |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 640 | |
stefan | ff48361 | 2015-12-21 11:14:00 | [diff] [blame] | 641 | void ModifyVideoConfigs( |
| 642 | VideoSendStream::Config* send_config, |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 643 | std::vector<VideoReceiveStreamInterface::Config>* receive_configs, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 644 | VideoEncoderConfig* encoder_config) override {} |
asapersson@webrtc.org | 049e4ec | 2014-11-20 10:19:46 | [diff] [blame] | 645 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 646 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 12:02:50 | [diff] [blame] | 647 | EXPECT_TRUE(Wait()) << "Timed out before receiving an overuse callback."; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 648 | } |
asapersson@webrtc.org | 049e4ec | 2014-11-20 10:19:46 | [diff] [blame] | 649 | |
Åsa Persson | 8c1bf95 | 2018-09-13 08:42:19 | [diff] [blame] | 650 | enum class TestPhase { |
| 651 | kInit, |
| 652 | kStart, |
| 653 | kAdaptedDown, |
| 654 | kAdaptedUp |
| 655 | } test_phase_; |
Henrik Boström | 1124ed1 | 2021-02-25 09:30:39 | [diff] [blame] | 656 | |
| 657 | private: |
| 658 | rtc::VideoSinkWants last_wants_; |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 659 | } test; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 660 | |
stefan | e74eef1 | 2016-01-08 14:47:13 | [diff] [blame] | 661 | RunBaseTest(&test); |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 662 | } |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 663 | |
| 664 | void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) { |
| 665 | static const int kMaxEncodeBitrateKbps = 30; |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 | [diff] [blame] | 666 | static const int kMinTransmitBitrateBps = 150000; |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 667 | static const int kMinAcceptableTransmitBitrate = 130; |
| 668 | static const int kMaxAcceptableTransmitBitrate = 170; |
| 669 | static const int kNumBitrateObservationsInRange = 100; |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 670 | static const int kAcceptableBitrateErrorMargin = 15; // +- 7 |
stefan | f116bd0 | 2015-10-27 15:29:42 | [diff] [blame] | 671 | class BitrateObserver : public test::EndToEndTest { |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 672 | public: |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 673 | explicit BitrateObserver(bool using_min_transmit_bitrate, |
| 674 | TaskQueueBase* task_queue) |
Markus Handell | f4f2287 | 2022-08-16 11:02:45 | [diff] [blame] | 675 | : EndToEndTest(kLongTimeout), |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 676 | send_stream_(nullptr), |
Danil Chapovalov | 371b43b | 2016-06-16 07:58:44 | [diff] [blame] | 677 | converged_(false), |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 678 | pad_to_min_bitrate_(using_min_transmit_bitrate), |
Danil Chapovalov | 371b43b | 2016-06-16 07:58:44 | [diff] [blame] | 679 | min_acceptable_bitrate_(using_min_transmit_bitrate |
| 680 | ? kMinAcceptableTransmitBitrate |
| 681 | : (kMaxEncodeBitrateKbps - |
| 682 | kAcceptableBitrateErrorMargin / 2)), |
| 683 | max_acceptable_bitrate_(using_min_transmit_bitrate |
| 684 | ? kMaxAcceptableTransmitBitrate |
| 685 | : (kMaxEncodeBitrateKbps + |
| 686 | kAcceptableBitrateErrorMargin / 2)), |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 687 | num_bitrate_observations_in_range_(0), |
Niels Möller | 05a9e5a | 2021-08-13 12:00:44 | [diff] [blame] | 688 | task_queue_(task_queue), |
| 689 | task_safety_flag_(PendingTaskSafetyFlag::CreateDetached()) {} |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 690 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 691 | private: |
stefan | f116bd0 | 2015-10-27 15:29:42 | [diff] [blame] | 692 | // TODO(holmer): Run this with a timer instead of once per packet. |
| 693 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
Danil Chapovalov | b7128ed | 2022-07-06 16:35:01 | [diff] [blame] | 694 | task_queue_->PostTask(SafeTask(task_safety_flag_, [this]() { |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 695 | VideoSendStream::Stats stats = send_stream_->GetStats(); |
| 696 | |
| 697 | if (!stats.substreams.empty()) { |
| 698 | RTC_DCHECK_EQ(1, stats.substreams.size()); |
| 699 | int bitrate_kbps = |
| 700 | stats.substreams.begin()->second.total_bitrate_bps / 1000; |
| 701 | if (bitrate_kbps > min_acceptable_bitrate_ && |
| 702 | bitrate_kbps < max_acceptable_bitrate_) { |
| 703 | converged_ = true; |
| 704 | ++num_bitrate_observations_in_range_; |
| 705 | if (num_bitrate_observations_in_range_ == |
| 706 | kNumBitrateObservationsInRange) |
| 707 | observation_complete_.Set(); |
| 708 | } |
| 709 | if (converged_) |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 710 | bitrate_kbps_list_.AddSample(bitrate_kbps); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 711 | } |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 712 | })); |
stefan | f116bd0 | 2015-10-27 15:29:42 | [diff] [blame] | 713 | return SEND_PACKET; |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 714 | } |
| 715 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 716 | void OnVideoStreamsCreated(VideoSendStream* send_stream, |
| 717 | const std::vector<VideoReceiveStreamInterface*>& |
| 718 | receive_streams) override { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 719 | send_stream_ = send_stream; |
| 720 | } |
| 721 | |
Niels Möller | 05a9e5a | 2021-08-13 12:00:44 | [diff] [blame] | 722 | void OnStreamsStopped() override { task_safety_flag_->SetNotAlive(); } |
| 723 | |
stefan | ff48361 | 2015-12-21 11:14:00 | [diff] [blame] | 724 | void ModifyVideoConfigs( |
| 725 | VideoSendStream::Config* send_config, |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 726 | std::vector<VideoReceiveStreamInterface::Config>* receive_configs, |
stefan | ff48361 | 2015-12-21 11:14:00 | [diff] [blame] | 727 | VideoEncoderConfig* encoder_config) override { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 728 | if (pad_to_min_bitrate_) { |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 | [diff] [blame] | 729 | encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 730 | } else { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 731 | RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 735 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 12:02:50 | [diff] [blame] | 736 | EXPECT_TRUE(Wait()) << "Timeout while waiting for send-bitrate stats."; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 737 | GetGlobalMetricsLogger()->LogMetric( |
| 738 | std::string("bitrate_stats_") + |
| 739 | (pad_to_min_bitrate_ ? "min_transmit_bitrate" |
| 740 | : "without_min_transmit_bitrate"), |
Artem Titov | e82c228 | 2022-09-28 13:18:33 | [diff] [blame] | 741 | "bitrate_kbps", bitrate_kbps_list_, Unit::kUnitless, |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 742 | ImprovementDirection::kNeitherIsBetter); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 743 | } |
| 744 | |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 745 | VideoSendStream* send_stream_; |
Danil Chapovalov | 371b43b | 2016-06-16 07:58:44 | [diff] [blame] | 746 | bool converged_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 | [diff] [blame] | 747 | const bool pad_to_min_bitrate_; |
Danil Chapovalov | 371b43b | 2016-06-16 07:58:44 | [diff] [blame] | 748 | const int min_acceptable_bitrate_; |
| 749 | const int max_acceptable_bitrate_; |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 750 | int num_bitrate_observations_in_range_; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 751 | SamplesStatsCounter bitrate_kbps_list_; |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 752 | TaskQueueBase* task_queue_; |
Niels Möller | 05a9e5a | 2021-08-13 12:00:44 | [diff] [blame] | 753 | rtc::scoped_refptr<PendingTaskSafetyFlag> task_safety_flag_; |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 754 | } test(pad_to_min_bitrate, task_queue()); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 755 | |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 756 | fake_encoder_max_bitrate_ = kMaxEncodeBitrateKbps; |
stefan | e74eef1 | 2016-01-08 14:47:13 | [diff] [blame] | 757 | RunBaseTest(&test); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 758 | } |
| 759 | |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 760 | TEST_F(CallPerfTest, Bitrate_Kbps_PadsToMinTransmitBitrate) { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 761 | TestMinTransmitBitrate(true); |
| 762 | } |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 763 | |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 764 | TEST_F(CallPerfTest, Bitrate_Kbps_NoPadWithoutMinTransmitBitrate) { |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 | [diff] [blame] | 765 | TestMinTransmitBitrate(false); |
| 766 | } |
| 767 | |
Taylor Brandstetter | 85904f4 | 2018-02-16 18:11:49 | [diff] [blame] | 768 | // TODO(bugs.webrtc.org/8878) |
| 769 | #if defined(WEBRTC_MAC) |
| 770 | #define MAYBE_KeepsHighBitrateWhenReconfiguringSender \ |
| 771 | DISABLED_KeepsHighBitrateWhenReconfiguringSender |
| 772 | #else |
| 773 | #define MAYBE_KeepsHighBitrateWhenReconfiguringSender \ |
| 774 | KeepsHighBitrateWhenReconfiguringSender |
| 775 | #endif |
| 776 | TEST_F(CallPerfTest, MAYBE_KeepsHighBitrateWhenReconfiguringSender) { |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 777 | static const uint32_t kInitialBitrateKbps = 400; |
| 778 | static const uint32_t kReconfigureThresholdKbps = 600; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 779 | |
Jakob Ivarsson | 36274f9 | 2020-10-22 11:01:07 | [diff] [blame] | 780 | // We get lower bitrate than expected by this test if the following field |
| 781 | // trial is enabled. |
Jonas Oreland | 8ca0613 | 2022-03-14 11:52:48 | [diff] [blame] | 782 | test::ScopedKeyValueConfig field_trials( |
| 783 | field_trials_, "WebRTC-SendSideBwe-WithOverhead/Disabled/"); |
Jakob Ivarsson | 36274f9 | 2020-10-22 11:01:07 | [diff] [blame] | 784 | |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 785 | class VideoStreamFactory |
| 786 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 787 | public: |
| 788 | VideoStreamFactory() {} |
| 789 | |
| 790 | private: |
| 791 | std::vector<VideoStream> CreateEncoderStreams( |
Jonas Oreland | 80c87d7 | 2022-09-29 13:01:09 | [diff] [blame] | 792 | int frame_width, |
| 793 | int frame_height, |
| 794 | const webrtc::VideoEncoderConfig& encoder_config) override { |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 795 | std::vector<VideoStream> streams = |
Jonas Oreland | 80c87d7 | 2022-09-29 13:01:09 | [diff] [blame] | 796 | test::CreateVideoStreams(frame_width, frame_height, encoder_config); |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 797 | streams[0].min_bitrate_bps = 50000; |
| 798 | streams[0].target_bitrate_bps = streams[0].max_bitrate_bps = 2000000; |
| 799 | return streams; |
| 800 | } |
| 801 | }; |
| 802 | |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 803 | class BitrateObserver : public test::EndToEndTest, public test::FakeEncoder { |
| 804 | public: |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 805 | explicit BitrateObserver(TaskQueueBase* task_queue) |
Markus Handell | f4f2287 | 2022-08-16 11:02:45 | [diff] [blame] | 806 | : EndToEndTest(kDefaultTimeout), |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 807 | FakeEncoder(Clock::GetRealTimeClock()), |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 808 | encoder_inits_(0), |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 809 | last_set_bitrate_kbps_(0), |
| 810 | send_stream_(nullptr), |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 811 | frame_generator_(nullptr), |
Jiawei Ou | c2ebe21 | 2018-11-08 18:02:56 | [diff] [blame] | 812 | encoder_factory_(this), |
| 813 | bitrate_allocator_factory_( |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 814 | CreateBuiltinVideoBitrateAllocatorFactory()), |
| 815 | task_queue_(task_queue) {} |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 816 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 817 | int32_t InitEncode(const VideoCodec* config, |
Elad Alon | 370f93a | 2019-06-11 12:57:57 | [diff] [blame] | 818 | const VideoEncoder::Settings& settings) override { |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 819 | ++encoder_inits_; |
| 820 | if (encoder_inits_ == 1) { |
emircan | 05a55b5 | 2016-10-28 21:06:29 | [diff] [blame] | 821 | // First time initialization. Frame size is known. |
Artem Titov | ea24027 | 2021-07-26 10:40:21 | [diff] [blame] | 822 | // `expected_bitrate` is affected by bandwidth estimation before the |
Per | 21d45d2 | 2016-10-30 20:37:57 | [diff] [blame] | 823 | // first frame arrives to the encoder. |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 824 | uint32_t expected_bitrate = last_set_bitrate_kbps_ > 0 |
| 825 | ? last_set_bitrate_kbps_ |
| 826 | : kInitialBitrateKbps; |
Per | 21d45d2 | 2016-10-30 20:37:57 | [diff] [blame] | 827 | EXPECT_EQ(expected_bitrate, config->startBitrate) |
| 828 | << "Encoder not initialized at expected bitrate."; |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 829 | EXPECT_EQ(kDefaultWidth, config->width); |
| 830 | EXPECT_EQ(kDefaultHeight, config->height); |
Per | 21d45d2 | 2016-10-30 20:37:57 | [diff] [blame] | 831 | } else if (encoder_inits_ == 2) { |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 832 | EXPECT_EQ(2 * kDefaultWidth, config->width); |
| 833 | EXPECT_EQ(2 * kDefaultHeight, config->height); |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 834 | EXPECT_GE(last_set_bitrate_kbps_, kReconfigureThresholdKbps); |
philipel | 0676f22 | 2018-04-17 14:12:21 | [diff] [blame] | 835 | EXPECT_GT(config->startBitrate, kReconfigureThresholdKbps) |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 836 | << "Encoder reconfigured with bitrate too far away from last set."; |
Peter Boström | 5811a39 | 2015-12-10 12:02:50 | [diff] [blame] | 837 | observation_complete_.Set(); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 838 | } |
Elad Alon | 370f93a | 2019-06-11 12:57:57 | [diff] [blame] | 839 | return FakeEncoder::InitEncode(config, settings); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 840 | } |
| 841 | |
Erik Språng | 16cb8f5 | 2019-04-12 11:59:09 | [diff] [blame] | 842 | void SetRates(const RateControlParameters& parameters) override { |
| 843 | last_set_bitrate_kbps_ = parameters.bitrate.get_sum_kbps(); |
Per | 21d45d2 | 2016-10-30 20:37:57 | [diff] [blame] | 844 | if (encoder_inits_ == 1 && |
Erik Språng | 16cb8f5 | 2019-04-12 11:59:09 | [diff] [blame] | 845 | parameters.bitrate.get_sum_kbps() > kReconfigureThresholdKbps) { |
Peter Boström | 5811a39 | 2015-12-10 12:02:50 | [diff] [blame] | 846 | time_to_reconfigure_.Set(); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 847 | } |
Erik Språng | 16cb8f5 | 2019-04-12 11:59:09 | [diff] [blame] | 848 | FakeEncoder::SetRates(parameters); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 849 | } |
| 850 | |
Niels Möller | de8e6e6 | 2018-11-13 14:10:33 | [diff] [blame] | 851 | void ModifySenderBitrateConfig( |
| 852 | BitrateConstraints* bitrate_config) override { |
| 853 | bitrate_config->start_bitrate_bps = kInitialBitrateKbps * 1000; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 854 | } |
| 855 | |
stefan | ff48361 | 2015-12-21 11:14:00 | [diff] [blame] | 856 | void ModifyVideoConfigs( |
| 857 | VideoSendStream::Config* send_config, |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 858 | std::vector<VideoReceiveStreamInterface::Config>* receive_configs, |
stefan | ff48361 | 2015-12-21 11:14:00 | [diff] [blame] | 859 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 860 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
Jiawei Ou | c2ebe21 | 2018-11-08 18:02:56 | [diff] [blame] | 861 | send_config->encoder_settings.bitrate_allocator_factory = |
| 862 | bitrate_allocator_factory_.get(); |
Per | 21d45d2 | 2016-10-30 20:37:57 | [diff] [blame] | 863 | encoder_config->max_bitrate_bps = 2 * kReconfigureThresholdKbps * 1000; |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 864 | encoder_config->video_stream_factory = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 865 | rtc::make_ref_counted<VideoStreamFactory>(); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 866 | |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 867 | encoder_config_ = encoder_config->Copy(); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 868 | } |
| 869 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 870 | void OnVideoStreamsCreated(VideoSendStream* send_stream, |
| 871 | const std::vector<VideoReceiveStreamInterface*>& |
| 872 | receive_streams) override { |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 873 | send_stream_ = send_stream; |
| 874 | } |
| 875 | |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 876 | void OnFrameGeneratorCapturerCreated( |
| 877 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
| 878 | frame_generator_ = frame_generator_capturer; |
| 879 | } |
| 880 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 881 | void PerformTest() override { |
Markus Handell | 2cfc1af | 2022-08-19 08:16:48 | [diff] [blame] | 882 | ASSERT_TRUE(time_to_reconfigure_.Wait(kDefaultTimeout)) |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 883 | << "Timed out before receiving an initial high bitrate."; |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 884 | frame_generator_->ChangeResolution(kDefaultWidth * 2, kDefaultHeight * 2); |
Danil Chapovalov | e519f38 | 2022-08-11 10:26:09 | [diff] [blame] | 885 | SendTask(task_queue_, [&]() { |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 886 | send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); |
| 887 | }); |
Peter Boström | 5811a39 | 2015-12-10 12:02:50 | [diff] [blame] | 888 | EXPECT_TRUE(Wait()) |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 889 | << "Timed out while waiting for a couple of high bitrate estimates " |
| 890 | "after reconfiguring the send stream."; |
| 891 | } |
| 892 | |
| 893 | private: |
Peter Boström | 5811a39 | 2015-12-10 12:02:50 | [diff] [blame] | 894 | rtc::Event time_to_reconfigure_; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 895 | int encoder_inits_; |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 896 | uint32_t last_set_bitrate_kbps_; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 897 | VideoSendStream* send_stream_; |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 898 | test::FrameGeneratorCapturer* frame_generator_; |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 899 | test::VideoEncoderProxyFactory encoder_factory_; |
Jiawei Ou | c2ebe21 | 2018-11-08 18:02:56 | [diff] [blame] | 900 | std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 901 | VideoEncoderConfig encoder_config_; |
Tomas Gunnarsson | 788d805 | 2021-05-03 14:23:08 | [diff] [blame] | 902 | TaskQueueBase* task_queue_; |
| 903 | } test(task_queue()); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 904 | |
stefan | e74eef1 | 2016-01-08 14:47:13 | [diff] [blame] | 905 | RunBaseTest(&test); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 | [diff] [blame] | 906 | } |
| 907 | |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 908 | // Discovers the minimal supported audio+video bitrate. The test bitrate is |
| 909 | // considered supported if Rtt does not go above 400ms with the network |
| 910 | // contrained to the test bitrate. |
| 911 | // |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 912 | // |test_bitrate_from test_bitrate_to| bitrate constraint range |
Artem Titov | ea24027 | 2021-07-26 10:40:21 | [diff] [blame] | 913 | // `test_bitrate_step` bitrate constraint update step during the test |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 914 | // |min_bwe max_bwe| BWE range |
Artem Titov | ea24027 | 2021-07-26 10:40:21 | [diff] [blame] | 915 | // `start_bwe` initial BWE |
Jonas Olsson | 0182a03 | 2019-07-09 10:31:20 | [diff] [blame] | 916 | void CallPerfTest::TestMinAudioVideoBitrate(int test_bitrate_from, |
| 917 | int test_bitrate_to, |
| 918 | int test_bitrate_step, |
| 919 | int min_bwe, |
| 920 | int start_bwe, |
| 921 | int max_bwe) { |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 922 | static const std::string kAudioTrackId = "audio_track_0"; |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 923 | static constexpr int kOpusBitrateFbBps = 32000; |
| 924 | static constexpr int kBitrateStabilizationMs = 10000; |
| 925 | static constexpr int kBitrateMeasurements = 10; |
| 926 | static constexpr int kBitrateMeasurementMs = 1000; |
Ilya Nikolaevskiy | 0500b52 | 2019-01-22 10:12:51 | [diff] [blame] | 927 | static constexpr int kShortDelayMs = 10; |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 928 | static constexpr int kMinGoodRttMs = 400; |
| 929 | |
| 930 | class MinVideoAndAudioBitrateTester : public test::EndToEndTest { |
| 931 | public: |
Danil Chapovalov | 85a1000 | 2019-10-21 13:00:53 | [diff] [blame] | 932 | MinVideoAndAudioBitrateTester(int test_bitrate_from, |
| 933 | int test_bitrate_to, |
| 934 | int test_bitrate_step, |
| 935 | int min_bwe, |
| 936 | int start_bwe, |
| 937 | int max_bwe, |
| 938 | TaskQueueBase* task_queue) |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 939 | : EndToEndTest(), |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 940 | test_bitrate_from_(test_bitrate_from), |
| 941 | test_bitrate_to_(test_bitrate_to), |
| 942 | test_bitrate_step_(test_bitrate_step), |
| 943 | min_bwe_(min_bwe), |
| 944 | start_bwe_(start_bwe), |
Tommi | c24a5b1 | 2019-08-05 13:23:45 | [diff] [blame] | 945 | max_bwe_(max_bwe), |
| 946 | task_queue_(task_queue) {} |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 947 | |
| 948 | protected: |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 949 | BuiltInNetworkBehaviorConfig GetFakeNetworkPipeConfig() { |
| 950 | BuiltInNetworkBehaviorConfig pipe_config; |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 951 | pipe_config.link_capacity_kbps = test_bitrate_from_; |
| 952 | return pipe_config; |
| 953 | } |
| 954 | |
Danil Chapovalov | 44db436 | 2019-09-30 02:16:28 | [diff] [blame] | 955 | std::unique_ptr<test::PacketTransport> CreateSendTransport( |
| 956 | TaskQueueBase* task_queue, |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 957 | Call* sender_call) override { |
Artem Titov | 631cafa | 2018-08-21 19:01:00 | [diff] [blame] | 958 | auto network = |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 959 | std::make_unique<SimulatedNetwork>(GetFakeNetworkPipeConfig()); |
Artem Titov | 631cafa | 2018-08-21 19:01:00 | [diff] [blame] | 960 | send_simulated_network_ = network.get(); |
Danil Chapovalov | 44db436 | 2019-09-30 02:16:28 | [diff] [blame] | 961 | return std::make_unique<test::PacketTransport>( |
Artem Titov | 631cafa | 2018-08-21 19:01:00 | [diff] [blame] | 962 | task_queue, sender_call, this, test::PacketTransport::kSender, |
| 963 | test::CallTest::payload_type_map_, |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 964 | std::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(), |
| 965 | std::move(network))); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 966 | } |
| 967 | |
Danil Chapovalov | 44db436 | 2019-09-30 02:16:28 | [diff] [blame] | 968 | std::unique_ptr<test::PacketTransport> CreateReceiveTransport( |
| 969 | TaskQueueBase* task_queue) override { |
Artem Titov | 631cafa | 2018-08-21 19:01:00 | [diff] [blame] | 970 | auto network = |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 971 | std::make_unique<SimulatedNetwork>(GetFakeNetworkPipeConfig()); |
Artem Titov | 631cafa | 2018-08-21 19:01:00 | [diff] [blame] | 972 | receive_simulated_network_ = network.get(); |
Danil Chapovalov | 44db436 | 2019-09-30 02:16:28 | [diff] [blame] | 973 | return std::make_unique<test::PacketTransport>( |
Artem Titov | 631cafa | 2018-08-21 19:01:00 | [diff] [blame] | 974 | task_queue, nullptr, this, test::PacketTransport::kReceiver, |
| 975 | test::CallTest::payload_type_map_, |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 976 | std::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(), |
| 977 | std::move(network))); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | void PerformTest() override { |
Ilya Nikolaevskiy | 0500b52 | 2019-01-22 10:12:51 | [diff] [blame] | 981 | // Quick test mode, just to exercise all the code paths without actually |
| 982 | // caring about performance measurements. |
| 983 | const bool quick_perf_test = |
| 984 | field_trial::IsEnabled("WebRTC-QuickPerfTest"); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 985 | int last_passed_test_bitrate = -1; |
| 986 | for (int test_bitrate = test_bitrate_from_; |
| 987 | test_bitrate_from_ < test_bitrate_to_ |
| 988 | ? test_bitrate <= test_bitrate_to_ |
| 989 | : test_bitrate >= test_bitrate_to_; |
| 990 | test_bitrate += test_bitrate_step_) { |
Artem Titov | 75e3647 | 2018-10-08 10:28:56 | [diff] [blame] | 991 | BuiltInNetworkBehaviorConfig pipe_config; |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 992 | pipe_config.link_capacity_kbps = test_bitrate; |
Artem Titov | 631cafa | 2018-08-21 19:01:00 | [diff] [blame] | 993 | send_simulated_network_->SetConfig(pipe_config); |
| 994 | receive_simulated_network_->SetConfig(pipe_config); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 995 | |
Tommi | c24a5b1 | 2019-08-05 13:23:45 | [diff] [blame] | 996 | rtc::Thread::SleepMs(quick_perf_test ? kShortDelayMs |
| 997 | : kBitrateStabilizationMs); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 998 | |
| 999 | int64_t avg_rtt = 0; |
| 1000 | for (int i = 0; i < kBitrateMeasurements; i++) { |
Tommi | c24a5b1 | 2019-08-05 13:23:45 | [diff] [blame] | 1001 | Call::Stats call_stats; |
Danil Chapovalov | e519f38 | 2022-08-11 10:26:09 | [diff] [blame] | 1002 | SendTask(task_queue_, [this, &call_stats]() { |
Danil Chapovalov | 82a3f0a | 2019-10-21 07:24:27 | [diff] [blame] | 1003 | call_stats = sender_call_->GetStats(); |
| 1004 | }); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1005 | avg_rtt += call_stats.rtt_ms; |
Tommi | c24a5b1 | 2019-08-05 13:23:45 | [diff] [blame] | 1006 | rtc::Thread::SleepMs(quick_perf_test ? kShortDelayMs |
| 1007 | : kBitrateMeasurementMs); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1008 | } |
| 1009 | avg_rtt = avg_rtt / kBitrateMeasurements; |
| 1010 | if (avg_rtt > kMinGoodRttMs) { |
| 1011 | break; |
| 1012 | } else { |
| 1013 | last_passed_test_bitrate = test_bitrate; |
| 1014 | } |
| 1015 | } |
| 1016 | EXPECT_GT(last_passed_test_bitrate, -1) |
| 1017 | << "Minimum supported bitrate out of the test scope"; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 1018 | GetGlobalMetricsLogger()->LogSingleValueMetric( |
| 1019 | "min_test_bitrate_", "min_bitrate", last_passed_test_bitrate, |
Artem Titov | e82c228 | 2022-09-28 13:18:33 | [diff] [blame] | 1020 | Unit::kUnitless, ImprovementDirection::kNeitherIsBetter); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 1024 | sender_call_ = sender_call; |
Sebastian Jansson | fc8d26b | 2018-02-21 08:52:06 | [diff] [blame] | 1025 | BitrateConstraints bitrate_config; |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1026 | bitrate_config.min_bitrate_bps = min_bwe_; |
| 1027 | bitrate_config.start_bitrate_bps = start_bwe_; |
| 1028 | bitrate_config.max_bitrate_bps = max_bwe_; |
Sebastian Jansson | 8f83b42 | 2018-02-21 12:07:13 | [diff] [blame] | 1029 | sender_call->GetTransportControllerSend()->SetSdpBitrateParameters( |
| 1030 | bitrate_config); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | size_t GetNumVideoStreams() const override { return 1; } |
| 1034 | |
| 1035 | size_t GetNumAudioStreams() const override { return 1; } |
| 1036 | |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 1037 | void ModifyAudioConfigs(AudioSendStream::Config* send_config, |
| 1038 | std::vector<AudioReceiveStreamInterface::Config>* |
| 1039 | receive_configs) override { |
Jonas Olsson | 0182a03 | 2019-07-09 10:31:20 | [diff] [blame] | 1040 | send_config->send_codec_spec->target_bitrate_bps = |
| 1041 | absl::optional<int>(kOpusBitrateFbBps); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | private: |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1045 | const int test_bitrate_from_; |
| 1046 | const int test_bitrate_to_; |
| 1047 | const int test_bitrate_step_; |
| 1048 | const int min_bwe_; |
| 1049 | const int start_bwe_; |
| 1050 | const int max_bwe_; |
Artem Titov | 631cafa | 2018-08-21 19:01:00 | [diff] [blame] | 1051 | SimulatedNetwork* send_simulated_network_; |
| 1052 | SimulatedNetwork* receive_simulated_network_; |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1053 | Call* sender_call_; |
Danil Chapovalov | 85a1000 | 2019-10-21 13:00:53 | [diff] [blame] | 1054 | TaskQueueBase* const task_queue_; |
Jonas Olsson | 0182a03 | 2019-07-09 10:31:20 | [diff] [blame] | 1055 | } test(test_bitrate_from, test_bitrate_to, test_bitrate_step, min_bwe, |
Danil Chapovalov | d15a028 | 2019-10-22 08:48:17 | [diff] [blame] | 1056 | start_bwe, max_bwe, task_queue()); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1057 | |
| 1058 | RunBaseTest(&test); |
| 1059 | } |
| 1060 | |
Taylor Brandstetter | 85904f4 | 2018-02-16 18:11:49 | [diff] [blame] | 1061 | // TODO(bugs.webrtc.org/8878) |
| 1062 | #if defined(WEBRTC_MAC) |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 1063 | #define MAYBE_Min_Bitrate_VideoAndAudio DISABLED_Min_Bitrate_VideoAndAudio |
Taylor Brandstetter | 85904f4 | 2018-02-16 18:11:49 | [diff] [blame] | 1064 | #else |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 1065 | #define MAYBE_Min_Bitrate_VideoAndAudio Min_Bitrate_VideoAndAudio |
Taylor Brandstetter | 85904f4 | 2018-02-16 18:11:49 | [diff] [blame] | 1066 | #endif |
Jeremy Leconte | c8850cb | 2020-09-10 18:46:33 | [diff] [blame] | 1067 | TEST_F(CallPerfTest, MAYBE_Min_Bitrate_VideoAndAudio) { |
Jonas Olsson | 0182a03 | 2019-07-09 10:31:20 | [diff] [blame] | 1068 | TestMinAudioVideoBitrate(110, 40, -10, 10000, 70000, 200000); |
Alex Narest | d0e196b | 2017-11-22 16:22:35 | [diff] [blame] | 1069 | } |
| 1070 | |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1071 | void CallPerfTest::TestEncodeFramerate(VideoEncoderFactory* encoder_factory, |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 1072 | absl::string_view payload_name, |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1073 | const std::vector<int>& max_framerates) { |
| 1074 | static constexpr double kAllowedFpsDiff = 1.5; |
| 1075 | static constexpr TimeDelta kMinGetStatsInterval = TimeDelta::Millis(400); |
| 1076 | static constexpr TimeDelta kMinRunTime = TimeDelta::Seconds(15); |
| 1077 | static constexpr DataRate kMaxBitrate = DataRate::KilobitsPerSec(1000); |
| 1078 | |
| 1079 | class FramerateObserver |
| 1080 | : public test::EndToEndTest, |
| 1081 | public test::FrameGeneratorCapturer::SinkWantsObserver { |
| 1082 | public: |
| 1083 | FramerateObserver(VideoEncoderFactory* encoder_factory, |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 1084 | absl::string_view payload_name, |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1085 | const std::vector<int>& max_framerates, |
| 1086 | TaskQueueBase* task_queue) |
Markus Handell | f4f2287 | 2022-08-16 11:02:45 | [diff] [blame] | 1087 | : EndToEndTest(kDefaultTimeout), |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1088 | clock_(Clock::GetRealTimeClock()), |
| 1089 | encoder_factory_(encoder_factory), |
| 1090 | payload_name_(payload_name), |
| 1091 | max_framerates_(max_framerates), |
| 1092 | task_queue_(task_queue), |
| 1093 | start_time_(clock_->CurrentTime()), |
| 1094 | last_getstats_time_(start_time_), |
| 1095 | send_stream_(nullptr) {} |
| 1096 | |
| 1097 | void OnFrameGeneratorCapturerCreated( |
| 1098 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
| 1099 | frame_generator_capturer->ChangeResolution(640, 360); |
| 1100 | } |
| 1101 | |
| 1102 | void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 1103 | const rtc::VideoSinkWants& wants) override {} |
| 1104 | |
| 1105 | void ModifySenderBitrateConfig( |
| 1106 | BitrateConstraints* bitrate_config) override { |
| 1107 | bitrate_config->start_bitrate_bps = kMaxBitrate.bps() / 2; |
| 1108 | } |
| 1109 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 1110 | void OnVideoStreamsCreated(VideoSendStream* send_stream, |
| 1111 | const std::vector<VideoReceiveStreamInterface*>& |
| 1112 | receive_streams) override { |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1113 | send_stream_ = send_stream; |
| 1114 | } |
| 1115 | |
| 1116 | size_t GetNumVideoStreams() const override { |
| 1117 | return max_framerates_.size(); |
| 1118 | } |
| 1119 | |
| 1120 | void ModifyVideoConfigs( |
| 1121 | VideoSendStream::Config* send_config, |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 1122 | std::vector<VideoReceiveStreamInterface::Config>* receive_configs, |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1123 | VideoEncoderConfig* encoder_config) override { |
| 1124 | send_config->encoder_settings.encoder_factory = encoder_factory_; |
| 1125 | send_config->rtp.payload_name = payload_name_; |
| 1126 | send_config->rtp.payload_type = test::CallTest::kVideoSendPayloadType; |
| 1127 | encoder_config->video_format.name = payload_name_; |
| 1128 | encoder_config->codec_type = PayloadStringToCodecType(payload_name_); |
| 1129 | encoder_config->max_bitrate_bps = kMaxBitrate.bps(); |
| 1130 | for (size_t i = 0; i < max_framerates_.size(); ++i) { |
| 1131 | encoder_config->simulcast_layers[i].max_framerate = max_framerates_[i]; |
| 1132 | configured_framerates_[send_config->rtp.ssrcs[i]] = max_framerates_[i]; |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | void PerformTest() override { |
| 1137 | EXPECT_TRUE(Wait()) << "Timeout while waiting for framerate stats."; |
| 1138 | } |
| 1139 | |
| 1140 | void VerifyStats() const { |
Åsa Persson | 4281208 | 2021-08-31 07:53:46 | [diff] [blame] | 1141 | double input_fps = 0.0; |
| 1142 | for (const auto& configured_framerate : configured_framerates_) { |
| 1143 | input_fps = std::max(configured_framerate.second, input_fps); |
| 1144 | } |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1145 | for (const auto& encode_frame_rate_list : encode_frame_rate_lists_) { |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 1146 | const SamplesStatsCounter& values = encode_frame_rate_list.second; |
| 1147 | GetGlobalMetricsLogger()->LogMetric( |
| 1148 | "substream_fps", "encode_frame_rate", values, Unit::kUnitless, |
| 1149 | ImprovementDirection::kNeitherIsBetter); |
| 1150 | if (values.IsEmpty()) { |
| 1151 | continue; |
| 1152 | } |
| 1153 | double average_fps = values.GetAverage(); |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1154 | uint32_t ssrc = encode_frame_rate_list.first; |
| 1155 | double expected_fps = configured_framerates_.find(ssrc)->second; |
Åsa Persson | 4281208 | 2021-08-31 07:53:46 | [diff] [blame] | 1156 | if (expected_fps != input_fps) |
| 1157 | EXPECT_NEAR(expected_fps, average_fps, kAllowedFpsDiff); |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 1162 | const Timestamp now = clock_->CurrentTime(); |
| 1163 | if (now - last_getstats_time_ > kMinGetStatsInterval) { |
| 1164 | last_getstats_time_ = now; |
Danil Chapovalov | b7128ed | 2022-07-06 16:35:01 | [diff] [blame] | 1165 | task_queue_->PostTask([this, now]() { |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1166 | VideoSendStream::Stats stats = send_stream_->GetStats(); |
| 1167 | for (const auto& stat : stats.substreams) { |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 1168 | encode_frame_rate_lists_[stat.first].AddSample( |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1169 | stat.second.encode_frame_rate); |
| 1170 | } |
| 1171 | if (now - start_time_ > kMinRunTime) { |
| 1172 | VerifyStats(); |
| 1173 | observation_complete_.Set(); |
| 1174 | } |
Danil Chapovalov | b7128ed | 2022-07-06 16:35:01 | [diff] [blame] | 1175 | }); |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1176 | } |
| 1177 | return SEND_PACKET; |
| 1178 | } |
| 1179 | |
| 1180 | Clock* const clock_; |
| 1181 | VideoEncoderFactory* const encoder_factory_; |
| 1182 | const std::string payload_name_; |
| 1183 | const std::vector<int> max_framerates_; |
| 1184 | TaskQueueBase* const task_queue_; |
| 1185 | const Timestamp start_time_; |
| 1186 | Timestamp last_getstats_time_; |
| 1187 | VideoSendStream* send_stream_; |
Artem Titov | 14b42c2 | 2022-09-26 11:21:14 | [diff] [blame] | 1188 | std::map<uint32_t, SamplesStatsCounter> encode_frame_rate_lists_; |
Åsa Persson | 59947d2 | 2021-08-26 10:04:27 | [diff] [blame] | 1189 | std::map<uint32_t, double> configured_framerates_; |
| 1190 | } test(encoder_factory, payload_name, max_framerates, task_queue()); |
| 1191 | |
| 1192 | RunBaseTest(&test); |
| 1193 | } |
| 1194 | |
| 1195 | TEST_F(CallPerfTest, TestEncodeFramerateVp8Simulcast) { |
| 1196 | InternalEncoderFactory internal_encoder_factory; |
| 1197 | test::FunctionVideoEncoderFactory encoder_factory( |
| 1198 | [&internal_encoder_factory]() { |
| 1199 | return std::make_unique<SimulcastEncoderAdapter>( |
| 1200 | &internal_encoder_factory, SdpVideoFormat("VP8")); |
| 1201 | }); |
| 1202 | |
| 1203 | TestEncodeFramerate(&encoder_factory, "VP8", |
| 1204 | /*max_framerates=*/{20, 30}); |
| 1205 | } |
| 1206 | |
Åsa Persson | d3bf4d4 | 2021-09-02 11:19:05 | [diff] [blame] | 1207 | TEST_F(CallPerfTest, TestEncodeFramerateVp8SimulcastLowerInputFps) { |
| 1208 | InternalEncoderFactory internal_encoder_factory; |
| 1209 | test::FunctionVideoEncoderFactory encoder_factory( |
| 1210 | [&internal_encoder_factory]() { |
| 1211 | return std::make_unique<SimulcastEncoderAdapter>( |
| 1212 | &internal_encoder_factory, SdpVideoFormat("VP8")); |
| 1213 | }); |
| 1214 | |
| 1215 | TestEncodeFramerate(&encoder_factory, "VP8", |
| 1216 | /*max_framerates=*/{14, 20}); |
| 1217 | } |
| 1218 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 | [diff] [blame] | 1219 | } // namespace webrtc |