pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [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 01:00:47 -0700 | [diff] [blame] | 10 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 11 | #include <algorithm> |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 12 | #include <limits> |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 13 | #include <memory> |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame^] | 16 | #include "absl/memory/memory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Erik Språng | ef75ebe | 2018-05-15 15:18:36 +0200 | [diff] [blame] | 18 | #include "api/video/video_bitrate_allocation.h" |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 19 | #include "api/video_codecs/video_encoder_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "call/call.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "logging/rtc_event_log/rtc_event_log.h" |
| 22 | #include "modules/audio_coding/include/audio_coding_module.h" |
Artem Titov | 3faa832 | 2018-03-07 14:44:00 +0100 | [diff] [blame] | 23 | #include "modules/audio_device/include/test_audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "modules/audio_mixer/audio_mixer_impl.h" |
| 25 | #include "modules/rtp_rtcp/include/rtp_header_parser.h" |
Alex Narest | d0e196b | 2017-11-22 17:22:35 +0100 | [diff] [blame] | 26 | #include "rtc_base/bitrateallocationstrategy.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "rtc_base/thread_annotations.h" |
| 29 | #include "system_wrappers/include/metrics_default.h" |
| 30 | #include "test/call_test.h" |
| 31 | #include "test/direct_transport.h" |
| 32 | #include "test/drifting_clock.h" |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 33 | #include "test/encoder_proxy_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "test/encoder_settings.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 35 | #include "test/fake_encoder.h" |
| 36 | #include "test/field_trial.h" |
| 37 | #include "test/frame_generator.h" |
| 38 | #include "test/frame_generator_capturer.h" |
| 39 | #include "test/gtest.h" |
| 40 | #include "test/rtp_rtcp_observer.h" |
| 41 | #include "test/single_threaded_task_queue.h" |
| 42 | #include "test/testsupport/fileutils.h" |
| 43 | #include "test/testsupport/perf_test.h" |
| 44 | #include "video/transport_adapter.h" |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 45 | |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 46 | using webrtc::test::DriftingClock; |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 47 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 48 | namespace webrtc { |
| 49 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 50 | class CallPerfTest : public test::CallTest { |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 51 | protected: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 52 | enum class FecMode { kOn, kOff }; |
| 53 | enum class CreateOrder { kAudioFirst, kVideoFirst }; |
Danil Chapovalov | cde5d6b | 2016-02-15 11:14:58 +0100 | [diff] [blame] | 54 | void TestAudioVideoSync(FecMode fec, |
| 55 | CreateOrder create_first, |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 56 | float video_ntp_speed, |
| 57 | float video_rtp_speed, |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 58 | float audio_rtp_speed, |
| 59 | const std::string& test_label); |
stefan@webrtc.org | 01581da | 2014-09-04 06:48:14 +0000 | [diff] [blame] | 60 | |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 61 | void TestMinTransmitBitrate(bool pad_to_min_bitrate); |
| 62 | |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 63 | void TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config, |
| 64 | int threshold_ms, |
| 65 | int start_time_ms, |
| 66 | int run_time_ms); |
Alex Narest | d0e196b | 2017-11-22 17:22:35 +0100 | [diff] [blame] | 67 | void TestMinAudioVideoBitrate(bool use_bitrate_allocation_strategy, |
| 68 | int test_bitrate_from, |
| 69 | int test_bitrate_to, |
| 70 | int test_bitrate_step, |
| 71 | int min_bwe, |
| 72 | int start_bwe, |
| 73 | int max_bwe); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 76 | class VideoRtcpAndSyncObserver : public test::RtpRtcpObserver, |
nisse | 7ade7b3 | 2016-03-23 04:48:10 -0700 | [diff] [blame] | 77 | public rtc::VideoSinkInterface<VideoFrame> { |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 78 | static const int kInSyncThresholdMs = 50; |
| 79 | static const int kStartupTimeMs = 2000; |
| 80 | static const int kMinRunTimeMs = 30000; |
| 81 | |
| 82 | public: |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 83 | explicit VideoRtcpAndSyncObserver(Clock* clock, const std::string& test_label) |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 84 | : test::RtpRtcpObserver(CallPerfTest::kLongTimeoutMs), |
| 85 | clock_(clock), |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 86 | test_label_(test_label), |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 87 | creation_time_ms_(clock_->TimeInMilliseconds()), |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 88 | first_time_in_sync_(-1), |
| 89 | receive_stream_(nullptr) {} |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 90 | |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 91 | void OnFrame(const VideoFrame& video_frame) override { |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 92 | VideoReceiveStream::Stats stats; |
| 93 | { |
| 94 | rtc::CritScope lock(&crit_); |
| 95 | if (receive_stream_) |
| 96 | stats = receive_stream_->GetStats(); |
| 97 | } |
| 98 | if (stats.sync_offset_ms == std::numeric_limits<int>::max()) |
| 99 | return; |
| 100 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 101 | int64_t now_ms = clock_->TimeInMilliseconds(); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 102 | int64_t time_since_creation = now_ms - creation_time_ms_; |
| 103 | // During the first couple of seconds audio and video can falsely be |
| 104 | // estimated as being synchronized. We don't want to trigger on those. |
| 105 | if (time_since_creation < kStartupTimeMs) |
| 106 | return; |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 107 | if (std::abs(stats.sync_offset_ms) < kInSyncThresholdMs) { |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 108 | if (first_time_in_sync_ == -1) { |
| 109 | first_time_in_sync_ = now_ms; |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 110 | webrtc::test::PrintResult("sync_convergence_time", test_label_, |
| 111 | "synchronization", time_since_creation, "ms", |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 112 | false); |
| 113 | } |
| 114 | if (time_since_creation > kMinRunTimeMs) |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 115 | observation_complete_.Set(); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 116 | } |
Danil Chapovalov | 371b43b | 2016-06-16 09:58:44 +0200 | [diff] [blame] | 117 | if (first_time_in_sync_ != -1) |
| 118 | sync_offset_ms_list_.push_back(stats.sync_offset_ms); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 119 | } |
| 120 | |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 121 | void set_receive_stream(VideoReceiveStream* receive_stream) { |
| 122 | rtc::CritScope lock(&crit_); |
| 123 | receive_stream_ = receive_stream; |
| 124 | } |
| 125 | |
danilchap | 46b89b9 | 2016-06-03 09:27:37 -0700 | [diff] [blame] | 126 | void PrintResults() { |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 127 | test::PrintResultList("stream_offset", test_label_, "synchronization", |
Edward Lemur | 2f06168 | 2017-11-24 13:40:01 +0100 | [diff] [blame] | 128 | sync_offset_ms_list_, "ms", false); |
danilchap | 46b89b9 | 2016-06-03 09:27:37 -0700 | [diff] [blame] | 129 | } |
| 130 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 131 | private: |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 132 | Clock* const clock_; |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 133 | std::string test_label_; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 134 | const int64_t creation_time_ms_; |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 135 | int64_t first_time_in_sync_; |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 136 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 137 | VideoReceiveStream* receive_stream_ RTC_GUARDED_BY(crit_); |
Edward Lemur | 2f06168 | 2017-11-24 13:40:01 +0100 | [diff] [blame] | 138 | std::vector<double> sync_offset_ms_list_; |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Danil Chapovalov | cde5d6b | 2016-02-15 11:14:58 +0100 | [diff] [blame] | 141 | void CallPerfTest::TestAudioVideoSync(FecMode fec, |
| 142 | CreateOrder create_first, |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 143 | float video_ntp_speed, |
| 144 | float video_rtp_speed, |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 145 | float audio_rtp_speed, |
| 146 | const std::string& test_label) { |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 147 | const char* kSyncGroup = "av_sync"; |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 148 | const uint32_t kAudioSendSsrc = 1234; |
| 149 | const uint32_t kAudioRecvSsrc = 5678; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 150 | |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 151 | FakeNetworkPipe::Config audio_net_config; |
| 152 | audio_net_config.queue_delay_ms = 500; |
| 153 | audio_net_config.loss_percent = 5; |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 154 | |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 155 | VideoRtcpAndSyncObserver observer(Clock::GetRealTimeClock(), test_label); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 156 | |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 157 | std::map<uint8_t, MediaType> audio_pt_map; |
| 158 | std::map<uint8_t, MediaType> video_pt_map; |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 159 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 160 | std::unique_ptr<test::PacketTransport> audio_send_transport; |
| 161 | std::unique_ptr<test::PacketTransport> video_send_transport; |
| 162 | std::unique_ptr<test::PacketTransport> receive_transport; |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 163 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 164 | AudioSendStream* audio_send_stream; |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 165 | AudioReceiveStream* audio_receive_stream; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 166 | std::unique_ptr<DriftingClock> drifting_clock; |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 167 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 168 | task_queue_.SendTask([&]() { |
| 169 | metrics::Reset(); |
Artem Titov | 3faa832 | 2018-03-07 14:44:00 +0100 | [diff] [blame] | 170 | rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device = |
| 171 | TestAudioDeviceModule::CreateTestAudioDeviceModule( |
| 172 | TestAudioDeviceModule::CreatePulsedNoiseCapturer(256, 48000), |
| 173 | TestAudioDeviceModule::CreateDiscardRenderer(48000), |
| 174 | audio_rtp_speed); |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 175 | EXPECT_EQ(0, fake_audio_device->Init()); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 176 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 177 | AudioState::Config send_audio_state_config; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 178 | send_audio_state_config.audio_mixer = AudioMixerImpl::Create(); |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 179 | send_audio_state_config.audio_processing = |
| 180 | AudioProcessingBuilder().Create(); |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 181 | send_audio_state_config.audio_device_module = fake_audio_device; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 182 | Call::Config sender_config(event_log_.get()); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 183 | |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 184 | auto audio_state = AudioState::Create(send_audio_state_config); |
| 185 | fake_audio_device->RegisterAudioCallback(audio_state->audio_transport()); |
| 186 | sender_config.audio_state = audio_state; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 187 | Call::Config receiver_config(event_log_.get()); |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 188 | receiver_config.audio_state = audio_state; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 189 | CreateCalls(sender_config, receiver_config); |
| 190 | |
| 191 | std::copy_if(std::begin(payload_type_map_), std::end(payload_type_map_), |
| 192 | std::inserter(audio_pt_map, audio_pt_map.end()), |
| 193 | [](const std::pair<const uint8_t, MediaType>& pair) { |
| 194 | return pair.second == MediaType::AUDIO; |
| 195 | }); |
| 196 | std::copy_if(std::begin(payload_type_map_), std::end(payload_type_map_), |
| 197 | std::inserter(video_pt_map, video_pt_map.end()), |
| 198 | [](const std::pair<const uint8_t, MediaType>& pair) { |
| 199 | return pair.second == MediaType::VIDEO; |
| 200 | }); |
| 201 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame^] | 202 | audio_send_transport = absl::make_unique<test::PacketTransport>( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 203 | &task_queue_, sender_call_.get(), &observer, |
| 204 | test::PacketTransport::kSender, audio_pt_map, audio_net_config); |
| 205 | audio_send_transport->SetReceiver(receiver_call_->Receiver()); |
| 206 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame^] | 207 | video_send_transport = absl::make_unique<test::PacketTransport>( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 208 | &task_queue_, sender_call_.get(), &observer, |
| 209 | test::PacketTransport::kSender, video_pt_map, |
| 210 | FakeNetworkPipe::Config()); |
| 211 | video_send_transport->SetReceiver(receiver_call_->Receiver()); |
| 212 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame^] | 213 | receive_transport = absl::make_unique<test::PacketTransport>( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 214 | &task_queue_, receiver_call_.get(), &observer, |
| 215 | test::PacketTransport::kReceiver, payload_type_map_, |
| 216 | FakeNetworkPipe::Config()); |
| 217 | receive_transport->SetReceiver(sender_call_->Receiver()); |
| 218 | |
| 219 | CreateSendConfig(1, 0, 0, video_send_transport.get()); |
| 220 | CreateMatchingReceiveConfigs(receive_transport.get()); |
| 221 | |
| 222 | AudioSendStream::Config audio_send_config(audio_send_transport.get()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 223 | audio_send_config.rtp.ssrc = kAudioSendSsrc; |
Oskar Sundbom | fedc00c | 2017-11-16 10:55:08 +0100 | [diff] [blame] | 224 | audio_send_config.send_codec_spec = AudioSendStream::Config::SendCodecSpec( |
| 225 | kAudioSendPayloadType, {"ISAC", 16000, 1}); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 226 | audio_send_config.encoder_factory = CreateBuiltinAudioEncoderFactory(); |
| 227 | audio_send_stream = sender_call_->CreateAudioSendStream(audio_send_config); |
| 228 | |
| 229 | video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 230 | if (fec == FecMode::kOn) { |
| 231 | video_send_config_.rtp.ulpfec.red_payload_type = kRedPayloadType; |
| 232 | video_send_config_.rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType; |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 233 | video_receive_configs_[0].rtp.red_payload_type = kRedPayloadType; |
| 234 | video_receive_configs_[0].rtp.ulpfec_payload_type = kUlpfecPayloadType; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 235 | } |
| 236 | video_receive_configs_[0].rtp.nack.rtp_history_ms = 1000; |
| 237 | video_receive_configs_[0].renderer = &observer; |
| 238 | video_receive_configs_[0].sync_group = kSyncGroup; |
| 239 | |
| 240 | AudioReceiveStream::Config audio_recv_config; |
| 241 | audio_recv_config.rtp.remote_ssrc = kAudioSendSsrc; |
| 242 | audio_recv_config.rtp.local_ssrc = kAudioRecvSsrc; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 243 | audio_recv_config.sync_group = kSyncGroup; |
Niels Möller | 2784a03 | 2018-03-28 14:16:04 +0200 | [diff] [blame] | 244 | audio_recv_config.decoder_factory = audio_decoder_factory_; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 245 | audio_recv_config.decoder_map = { |
| 246 | {kAudioSendPayloadType, {"ISAC", 16000, 1}}}; |
| 247 | |
| 248 | if (create_first == CreateOrder::kAudioFirst) { |
| 249 | audio_receive_stream = |
| 250 | receiver_call_->CreateAudioReceiveStream(audio_recv_config); |
| 251 | CreateVideoStreams(); |
| 252 | } else { |
| 253 | CreateVideoStreams(); |
| 254 | audio_receive_stream = |
| 255 | receiver_call_->CreateAudioReceiveStream(audio_recv_config); |
| 256 | } |
| 257 | EXPECT_EQ(1u, video_receive_streams_.size()); |
| 258 | observer.set_receive_stream(video_receive_streams_[0]); |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame^] | 259 | drifting_clock = absl::make_unique<DriftingClock>(clock_, video_ntp_speed); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 260 | CreateFrameGeneratorCapturerWithDrift(drifting_clock.get(), video_rtp_speed, |
| 261 | kDefaultFramerate, kDefaultWidth, |
| 262 | kDefaultHeight); |
| 263 | |
| 264 | Start(); |
| 265 | |
| 266 | audio_send_stream->Start(); |
| 267 | audio_receive_stream->Start(); |
| 268 | }); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 269 | |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 270 | EXPECT_TRUE(observer.Wait()) |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 271 | << "Timed out while waiting for audio and video to be synchronized."; |
| 272 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 273 | task_queue_.SendTask([&]() { |
| 274 | audio_send_stream->Stop(); |
| 275 | audio_receive_stream->Stop(); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 276 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 277 | Stop(); |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 278 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 279 | DestroyStreams(); |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 280 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 281 | video_send_transport.reset(); |
| 282 | audio_send_transport.reset(); |
| 283 | receive_transport.reset(); |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 284 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 285 | sender_call_->DestroyAudioSendStream(audio_send_stream); |
| 286 | receiver_call_->DestroyAudioReceiveStream(audio_receive_stream); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 287 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 288 | DestroyCalls(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 289 | }); |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 290 | |
danilchap | 46b89b9 | 2016-06-03 09:27:37 -0700 | [diff] [blame] | 291 | observer.PrintResults(); |
ilnik | 5328b9e | 2017-02-21 05:20:28 -0800 | [diff] [blame] | 292 | |
| 293 | // In quick test synchronization may not be achieved in time. |
sprang | e5d3a3e | 2017-03-01 06:20:56 -0800 | [diff] [blame] | 294 | if (!field_trial::IsEnabled("WebRTC-QuickPerfTest")) { |
ilnik | 5328b9e | 2017-02-21 05:20:28 -0800 | [diff] [blame] | 295 | EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs")); |
| 296 | } |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 297 | } |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 298 | |
danilchap | ac287ee | 2016-02-29 12:17:04 -0800 | [diff] [blame] | 299 | TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithVideoNtpDrift) { |
Danil Chapovalov | cde5d6b | 2016-02-15 11:14:58 +0100 | [diff] [blame] | 300 | TestAudioVideoSync(FecMode::kOff, CreateOrder::kAudioFirst, |
| 301 | DriftingClock::PercentsFaster(10.0f), |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 302 | DriftingClock::kNoDrift, DriftingClock::kNoDrift, |
| 303 | "_video_ntp_drift"); |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 304 | } |
| 305 | |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 306 | TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithAudioFasterThanVideoDrift) { |
Danil Chapovalov | cde5d6b | 2016-02-15 11:14:58 +0100 | [diff] [blame] | 307 | TestAudioVideoSync(FecMode::kOff, CreateOrder::kAudioFirst, |
| 308 | DriftingClock::kNoDrift, |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 309 | DriftingClock::PercentsSlower(30.0f), |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 310 | DriftingClock::PercentsFaster(30.0f), "_audio_faster"); |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithVideoFasterThanAudioDrift) { |
Danil Chapovalov | cde5d6b | 2016-02-15 11:14:58 +0100 | [diff] [blame] | 314 | TestAudioVideoSync(FecMode::kOn, CreateOrder::kVideoFirst, |
| 315 | DriftingClock::kNoDrift, |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 316 | DriftingClock::PercentsFaster(30.0f), |
Edward Lemur | 947f3fe | 2017-12-28 15:50:33 +0100 | [diff] [blame] | 317 | DriftingClock::PercentsSlower(30.0f), "_video_faster"); |
stefan@webrtc.org | 01581da | 2014-09-04 06:48:14 +0000 | [diff] [blame] | 318 | } |
| 319 | |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 320 | void CallPerfTest::TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config, |
| 321 | int threshold_ms, |
| 322 | int start_time_ms, |
| 323 | int run_time_ms) { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 324 | class CaptureNtpTimeObserver : public test::EndToEndTest, |
nisse | 7ade7b3 | 2016-03-23 04:48:10 -0700 | [diff] [blame] | 325 | public rtc::VideoSinkInterface<VideoFrame> { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 326 | public: |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 327 | CaptureNtpTimeObserver(const FakeNetworkPipe::Config& net_config, |
| 328 | int threshold_ms, |
| 329 | int start_time_ms, |
| 330 | int run_time_ms) |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 331 | : EndToEndTest(kLongTimeoutMs), |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 332 | net_config_(net_config), |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 333 | clock_(Clock::GetRealTimeClock()), |
| 334 | threshold_ms_(threshold_ms), |
| 335 | start_time_ms_(start_time_ms), |
| 336 | run_time_ms_(run_time_ms), |
| 337 | creation_time_ms_(clock_->TimeInMilliseconds()), |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 338 | capturer_(nullptr), |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 339 | rtp_start_timestamp_set_(false), |
| 340 | rtp_start_timestamp_(0) {} |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 341 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 342 | private: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 343 | test::PacketTransport* CreateSendTransport( |
| 344 | test::SingleThreadedTaskQueueForTesting* task_queue, |
| 345 | Call* sender_call) override { |
| 346 | return new test::PacketTransport(task_queue, sender_call, this, |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 347 | test::PacketTransport::kSender, |
| 348 | payload_type_map_, net_config_); |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 349 | } |
| 350 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 351 | test::PacketTransport* CreateReceiveTransport( |
| 352 | test::SingleThreadedTaskQueueForTesting* task_queue) override { |
| 353 | return new test::PacketTransport(task_queue, nullptr, this, |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 354 | test::PacketTransport::kReceiver, |
| 355 | payload_type_map_, net_config_); |
Stefan Holmer | ea8c0f6 | 2016-01-13 08:58:38 +0100 | [diff] [blame] | 356 | } |
| 357 | |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 358 | void OnFrame(const VideoFrame& video_frame) override { |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 359 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 360 | if (video_frame.ntp_time_ms() <= 0) { |
| 361 | // Haven't got enough RTCP SR in order to calculate the capture ntp |
| 362 | // time. |
| 363 | return; |
| 364 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 365 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 366 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 367 | int64_t time_since_creation = now_ms - creation_time_ms_; |
| 368 | if (time_since_creation < start_time_ms_) { |
| 369 | // Wait for |start_time_ms_| before start measuring. |
| 370 | return; |
| 371 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 372 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 373 | if (time_since_creation > run_time_ms_) { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 374 | observation_complete_.Set(); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 375 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 376 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 377 | FrameCaptureTimeList::iterator iter = |
| 378 | capture_time_list_.find(video_frame.timestamp()); |
| 379 | EXPECT_TRUE(iter != capture_time_list_.end()); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 380 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 381 | // The real capture time has been wrapped to uint32_t before converted |
| 382 | // to rtp timestamp in the sender side. So here we convert the estimated |
| 383 | // capture time to a uint32_t 90k timestamp also for comparing. |
| 384 | uint32_t estimated_capture_timestamp = |
| 385 | 90 * static_cast<uint32_t>(video_frame.ntp_time_ms()); |
| 386 | uint32_t real_capture_timestamp = iter->second; |
| 387 | int time_offset_ms = real_capture_timestamp - estimated_capture_timestamp; |
| 388 | time_offset_ms = time_offset_ms / 90; |
danilchap | 46b89b9 | 2016-06-03 09:27:37 -0700 | [diff] [blame] | 389 | time_offset_ms_list_.push_back(time_offset_ms); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 390 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 391 | EXPECT_TRUE(std::abs(time_offset_ms) < threshold_ms_); |
| 392 | } |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 393 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 394 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 395 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 396 | RTPHeader header; |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 397 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 398 | |
| 399 | if (!rtp_start_timestamp_set_) { |
| 400 | // Calculate the rtp timestamp offset in order to calculate the real |
| 401 | // capture time. |
| 402 | uint32_t first_capture_timestamp = |
| 403 | 90 * static_cast<uint32_t>(capturer_->first_frame_capture_time()); |
| 404 | rtp_start_timestamp_ = header.timestamp - first_capture_timestamp; |
| 405 | rtp_start_timestamp_set_ = true; |
| 406 | } |
| 407 | |
| 408 | uint32_t capture_timestamp = header.timestamp - rtp_start_timestamp_; |
| 409 | capture_time_list_.insert( |
| 410 | capture_time_list_.end(), |
| 411 | std::make_pair(header.timestamp, capture_timestamp)); |
| 412 | return SEND_PACKET; |
| 413 | } |
| 414 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 415 | void OnFrameGeneratorCapturerCreated( |
| 416 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 417 | capturer_ = frame_generator_capturer; |
| 418 | } |
| 419 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 420 | void ModifyVideoConfigs( |
| 421 | VideoSendStream::Config* send_config, |
| 422 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 423 | VideoEncoderConfig* encoder_config) override { |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 +0000 | [diff] [blame] | 424 | (*receive_configs)[0].renderer = this; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 425 | // Enable the receiver side rtt calculation. |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 +0000 | [diff] [blame] | 426 | (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 427 | } |
| 428 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 429 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 430 | EXPECT_TRUE(Wait()) << "Timed out while waiting for " |
| 431 | "estimated capture NTP time to be " |
| 432 | "within bounds."; |
danilchap | 46b89b9 | 2016-06-03 09:27:37 -0700 | [diff] [blame] | 433 | test::PrintResultList("capture_ntp_time", "", "real - estimated", |
Edward Lemur | 2f06168 | 2017-11-24 13:40:01 +0100 | [diff] [blame] | 434 | time_offset_ms_list_, "ms", true); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 435 | } |
| 436 | |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 437 | rtc::CriticalSection crit_; |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 438 | const FakeNetworkPipe::Config net_config_; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 439 | Clock* const clock_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 440 | int threshold_ms_; |
| 441 | int start_time_ms_; |
| 442 | int run_time_ms_; |
| 443 | int64_t creation_time_ms_; |
| 444 | test::FrameGeneratorCapturer* capturer_; |
| 445 | bool rtp_start_timestamp_set_; |
| 446 | uint32_t rtp_start_timestamp_; |
| 447 | typedef std::map<uint32_t, uint32_t> FrameCaptureTimeList; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 448 | FrameCaptureTimeList capture_time_list_ RTC_GUARDED_BY(&crit_); |
Edward Lemur | 2f06168 | 2017-11-24 13:40:01 +0100 | [diff] [blame] | 449 | std::vector<double> time_offset_ms_list_; |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 450 | } test(net_config, threshold_ms, start_time_ms, run_time_ms); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 451 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 452 | RunBaseTest(&test); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Alex Loiko | 5aea38c | 2017-09-27 13:10:28 +0200 | [diff] [blame] | 455 | // Flaky tests, disabled on Mac due to webrtc:8291. |
| 456 | #if !(defined(WEBRTC_MAC)) |
wu@webrtc.org | 9aa7d8d | 2014-05-29 05:03:52 +0000 | [diff] [blame] | 457 | TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkDelay) { |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 458 | FakeNetworkPipe::Config net_config; |
| 459 | net_config.queue_delay_ms = 100; |
| 460 | // TODO(wu): lower the threshold as the calculation/estimatation becomes more |
| 461 | // accurate. |
wu@webrtc.org | 9aa7d8d | 2014-05-29 05:03:52 +0000 | [diff] [blame] | 462 | const int kThresholdMs = 100; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 463 | const int kStartTimeMs = 10000; |
| 464 | const int kRunTimeMs = 20000; |
| 465 | TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); |
| 466 | } |
| 467 | |
wu@webrtc.org | 0224c20 | 2014-05-05 17:42:43 +0000 | [diff] [blame] | 468 | TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkJitter) { |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 469 | FakeNetworkPipe::Config net_config; |
wu@webrtc.org | 0224c20 | 2014-05-05 17:42:43 +0000 | [diff] [blame] | 470 | net_config.queue_delay_ms = 100; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 471 | net_config.delay_standard_deviation_ms = 10; |
| 472 | // TODO(wu): lower the threshold as the calculation/estimatation becomes more |
| 473 | // accurate. |
wu@webrtc.org | 0224c20 | 2014-05-05 17:42:43 +0000 | [diff] [blame] | 474 | const int kThresholdMs = 100; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 475 | const int kStartTimeMs = 10000; |
| 476 | const int kRunTimeMs = 20000; |
| 477 | TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); |
| 478 | } |
Alex Loiko | 5aea38c | 2017-09-27 13:10:28 +0200 | [diff] [blame] | 479 | #endif |
kthelgason | fa5fdce | 2017-02-27 00:15:31 -0800 | [diff] [blame] | 480 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 481 | TEST_F(CallPerfTest, ReceivesCpuOveruseAndUnderuse) { |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 482 | // Minimal normal usage at the start, then 30s overuse to allow filter to |
| 483 | // settle, and then 80s underuse to allow plenty of time for rampup again. |
| 484 | test::ScopedFieldTrials fake_overuse_settings( |
| 485 | "WebRTC-ForceSimulatedOveruseIntervalMs/1-30000-80000/"); |
| 486 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 487 | class LoadObserver : public test::SendTest, |
| 488 | public test::FrameGeneratorCapturer::SinkWantsObserver { |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 489 | public: |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 490 | LoadObserver() : SendTest(kLongTimeoutMs), test_phase_(TestPhase::kStart) {} |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 491 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 492 | void OnFrameGeneratorCapturerCreated( |
| 493 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
| 494 | frame_generator_capturer->SetSinkWantsObserver(this); |
kthelgason | fa5fdce | 2017-02-27 00:15:31 -0800 | [diff] [blame] | 495 | // Set a high initial resolution to be sure that we can scale down. |
| 496 | frame_generator_capturer->ChangeResolution(1920, 1080); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink |
| 500 | // is called. |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 501 | // TODO(sprang): Add integration test for maintain-framerate mode? |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 502 | void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 503 | const rtc::VideoSinkWants& wants) override { |
| 504 | // First expect CPU overuse. Then expect CPU underuse when the encoder |
| 505 | // delay has been decreased. |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 506 | switch (test_phase_) { |
| 507 | case TestPhase::kStart: |
| 508 | if (wants.max_pixel_count < std::numeric_limits<int>::max()) { |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 509 | // On adapting down, VideoStreamEncoder::VideoSourceProxy will set |
| 510 | // only the max pixel count, leaving the target unset. |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 511 | test_phase_ = TestPhase::kAdaptedDown; |
| 512 | } else { |
| 513 | ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 514 | << wants.max_pixel_count << ", target res = " |
| 515 | << wants.target_pixel_count.value_or(-1) |
| 516 | << ", max fps = " << wants.max_framerate_fps; |
| 517 | } |
| 518 | break; |
| 519 | case TestPhase::kAdaptedDown: |
| 520 | // On adapting up, the adaptation counter will again be at zero, and |
| 521 | // so all constraints will be reset. |
| 522 | if (wants.max_pixel_count == std::numeric_limits<int>::max() && |
| 523 | !wants.target_pixel_count) { |
| 524 | test_phase_ = TestPhase::kAdaptedUp; |
| 525 | observation_complete_.Set(); |
| 526 | } else { |
| 527 | ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 528 | << wants.max_pixel_count << ", target res = " |
| 529 | << wants.target_pixel_count.value_or(-1) |
| 530 | << ", max fps = " << wants.max_framerate_fps; |
| 531 | } |
| 532 | break; |
| 533 | case TestPhase::kAdaptedUp: |
| 534 | ADD_FAILURE() << "Got unexpected adaptation request, max res = " |
| 535 | << wants.max_pixel_count << ", target res = " |
| 536 | << wants.target_pixel_count.value_or(-1) |
| 537 | << ", max fps = " << wants.max_framerate_fps; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 538 | } |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 539 | } |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 540 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 541 | void ModifyVideoConfigs( |
| 542 | VideoSendStream::Config* send_config, |
| 543 | std::vector<VideoReceiveStream::Config>* receive_configs, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 544 | VideoEncoderConfig* encoder_config) override {} |
asapersson@webrtc.org | 049e4ec | 2014-11-20 10:19:46 +0000 | [diff] [blame] | 545 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 546 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 547 | EXPECT_TRUE(Wait()) << "Timed out before receiving an overuse callback."; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 548 | } |
asapersson@webrtc.org | 049e4ec | 2014-11-20 10:19:46 +0000 | [diff] [blame] | 549 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 550 | enum class TestPhase { kStart, kAdaptedDown, kAdaptedUp } test_phase_; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 551 | } test; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 552 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 553 | RunBaseTest(&test); |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 554 | } |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 555 | |
| 556 | void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) { |
| 557 | static const int kMaxEncodeBitrateKbps = 30; |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 558 | static const int kMinTransmitBitrateBps = 150000; |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 559 | static const int kMinAcceptableTransmitBitrate = 130; |
| 560 | static const int kMaxAcceptableTransmitBitrate = 170; |
| 561 | static const int kNumBitrateObservationsInRange = 100; |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 562 | static const int kAcceptableBitrateErrorMargin = 15; // +- 7 |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 563 | class BitrateObserver : public test::EndToEndTest { |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 564 | public: |
| 565 | explicit BitrateObserver(bool using_min_transmit_bitrate) |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 566 | : EndToEndTest(kLongTimeoutMs), |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 567 | send_stream_(nullptr), |
Danil Chapovalov | 371b43b | 2016-06-16 09:58:44 +0200 | [diff] [blame] | 568 | converged_(false), |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 569 | pad_to_min_bitrate_(using_min_transmit_bitrate), |
Danil Chapovalov | 371b43b | 2016-06-16 09:58:44 +0200 | [diff] [blame] | 570 | min_acceptable_bitrate_(using_min_transmit_bitrate |
| 571 | ? kMinAcceptableTransmitBitrate |
| 572 | : (kMaxEncodeBitrateKbps - |
| 573 | kAcceptableBitrateErrorMargin / 2)), |
| 574 | max_acceptable_bitrate_(using_min_transmit_bitrate |
| 575 | ? kMaxAcceptableTransmitBitrate |
| 576 | : (kMaxEncodeBitrateKbps + |
| 577 | kAcceptableBitrateErrorMargin / 2)), |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 578 | num_bitrate_observations_in_range_(0) {} |
| 579 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 580 | private: |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 581 | // TODO(holmer): Run this with a timer instead of once per packet. |
| 582 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 583 | VideoSendStream::Stats stats = send_stream_->GetStats(); |
| 584 | if (stats.substreams.size() > 0) { |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 585 | RTC_DCHECK_EQ(1, stats.substreams.size()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 586 | int bitrate_kbps = |
| 587 | stats.substreams.begin()->second.total_bitrate_bps / 1000; |
Danil Chapovalov | 371b43b | 2016-06-16 09:58:44 +0200 | [diff] [blame] | 588 | if (bitrate_kbps > min_acceptable_bitrate_ && |
| 589 | bitrate_kbps < max_acceptable_bitrate_) { |
| 590 | converged_ = true; |
| 591 | ++num_bitrate_observations_in_range_; |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 592 | if (num_bitrate_observations_in_range_ == |
| 593 | kNumBitrateObservationsInRange) |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 594 | observation_complete_.Set(); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 595 | } |
Danil Chapovalov | 371b43b | 2016-06-16 09:58:44 +0200 | [diff] [blame] | 596 | if (converged_) |
| 597 | bitrate_kbps_list_.push_back(bitrate_kbps); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 598 | } |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 599 | return SEND_PACKET; |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 600 | } |
| 601 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 602 | void OnVideoStreamsCreated( |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 +0000 | [diff] [blame] | 603 | VideoSendStream* send_stream, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 604 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 605 | send_stream_ = send_stream; |
| 606 | } |
| 607 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 608 | void ModifyVideoConfigs( |
| 609 | VideoSendStream::Config* send_config, |
| 610 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 611 | VideoEncoderConfig* encoder_config) override { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 612 | if (pad_to_min_bitrate_) { |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 613 | encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 614 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 615 | RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 619 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 620 | EXPECT_TRUE(Wait()) << "Timeout while waiting for send-bitrate stats."; |
danilchap | 46b89b9 | 2016-06-03 09:27:37 -0700 | [diff] [blame] | 621 | test::PrintResultList( |
| 622 | "bitrate_stats_", |
| 623 | (pad_to_min_bitrate_ ? "min_transmit_bitrate" |
| 624 | : "without_min_transmit_bitrate"), |
Edward Lemur | 2f06168 | 2017-11-24 13:40:01 +0100 | [diff] [blame] | 625 | "bitrate_kbps", bitrate_kbps_list_, "kbps", false); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 626 | } |
| 627 | |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 628 | VideoSendStream* send_stream_; |
Danil Chapovalov | 371b43b | 2016-06-16 09:58:44 +0200 | [diff] [blame] | 629 | bool converged_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 630 | const bool pad_to_min_bitrate_; |
Danil Chapovalov | 371b43b | 2016-06-16 09:58:44 +0200 | [diff] [blame] | 631 | const int min_acceptable_bitrate_; |
| 632 | const int max_acceptable_bitrate_; |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 633 | int num_bitrate_observations_in_range_; |
Edward Lemur | 2f06168 | 2017-11-24 13:40:01 +0100 | [diff] [blame] | 634 | std::vector<double> bitrate_kbps_list_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 635 | } test(pad_to_min_bitrate); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 636 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 637 | fake_encoder_max_bitrate_ = kMaxEncodeBitrateKbps; |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 638 | RunBaseTest(&test); |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 641 | TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { |
| 642 | TestMinTransmitBitrate(true); |
| 643 | } |
pbos@webrtc.org | 3349ae0 | 2014-03-13 12:52:27 +0000 | [diff] [blame] | 644 | |
| 645 | TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) { |
| 646 | TestMinTransmitBitrate(false); |
| 647 | } |
| 648 | |
Taylor Brandstetter | 85904f4 | 2018-02-16 10:11:49 -0800 | [diff] [blame] | 649 | // TODO(bugs.webrtc.org/8878) |
| 650 | #if defined(WEBRTC_MAC) |
| 651 | #define MAYBE_KeepsHighBitrateWhenReconfiguringSender \ |
| 652 | DISABLED_KeepsHighBitrateWhenReconfiguringSender |
| 653 | #else |
| 654 | #define MAYBE_KeepsHighBitrateWhenReconfiguringSender \ |
| 655 | KeepsHighBitrateWhenReconfiguringSender |
| 656 | #endif |
| 657 | TEST_F(CallPerfTest, MAYBE_KeepsHighBitrateWhenReconfiguringSender) { |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 658 | static const uint32_t kInitialBitrateKbps = 400; |
| 659 | static const uint32_t kReconfigureThresholdKbps = 600; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 660 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 661 | class VideoStreamFactory |
| 662 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 663 | public: |
| 664 | VideoStreamFactory() {} |
| 665 | |
| 666 | private: |
| 667 | std::vector<VideoStream> CreateEncoderStreams( |
| 668 | int width, |
| 669 | int height, |
| 670 | const VideoEncoderConfig& encoder_config) override { |
| 671 | std::vector<VideoStream> streams = |
| 672 | test::CreateVideoStreams(width, height, encoder_config); |
| 673 | streams[0].min_bitrate_bps = 50000; |
| 674 | streams[0].target_bitrate_bps = streams[0].max_bitrate_bps = 2000000; |
| 675 | return streams; |
| 676 | } |
| 677 | }; |
| 678 | |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 679 | class BitrateObserver : public test::EndToEndTest, public test::FakeEncoder { |
| 680 | public: |
| 681 | BitrateObserver() |
| 682 | : EndToEndTest(kDefaultTimeoutMs), |
| 683 | FakeEncoder(Clock::GetRealTimeClock()), |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 684 | time_to_reconfigure_(false, false), |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 685 | encoder_inits_(0), |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 686 | last_set_bitrate_kbps_(0), |
| 687 | send_stream_(nullptr), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 688 | frame_generator_(nullptr), |
| 689 | encoder_factory_(this) {} |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 690 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 691 | int32_t InitEncode(const VideoCodec* config, |
| 692 | int32_t number_of_cores, |
| 693 | size_t max_payload_size) override { |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 694 | ++encoder_inits_; |
| 695 | if (encoder_inits_ == 1) { |
emircan | 05a55b5 | 2016-10-28 14:06:29 -0700 | [diff] [blame] | 696 | // First time initialization. Frame size is known. |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 697 | // |expected_bitrate| is affected by bandwidth estimation before the |
| 698 | // first frame arrives to the encoder. |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 699 | uint32_t expected_bitrate = last_set_bitrate_kbps_ > 0 |
| 700 | ? last_set_bitrate_kbps_ |
| 701 | : kInitialBitrateKbps; |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 702 | EXPECT_EQ(expected_bitrate, config->startBitrate) |
| 703 | << "Encoder not initialized at expected bitrate."; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 704 | EXPECT_EQ(kDefaultWidth, config->width); |
| 705 | EXPECT_EQ(kDefaultHeight, config->height); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 706 | } else if (encoder_inits_ == 2) { |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 707 | EXPECT_EQ(2 * kDefaultWidth, config->width); |
| 708 | EXPECT_EQ(2 * kDefaultHeight, config->height); |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 709 | EXPECT_GE(last_set_bitrate_kbps_, kReconfigureThresholdKbps); |
philipel | 0676f22 | 2018-04-17 16:12:21 +0200 | [diff] [blame] | 710 | EXPECT_GT(config->startBitrate, kReconfigureThresholdKbps) |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 711 | << "Encoder reconfigured with bitrate too far away from last set."; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 712 | observation_complete_.Set(); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 713 | } |
| 714 | return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 715 | } |
| 716 | |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 717 | int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation, |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 718 | uint32_t framerate) override { |
| 719 | last_set_bitrate_kbps_ = rate_allocation.get_sum_kbps(); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 720 | if (encoder_inits_ == 1 && |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 721 | rate_allocation.get_sum_kbps() > kReconfigureThresholdKbps) { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 722 | time_to_reconfigure_.Set(); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 723 | } |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 724 | return FakeEncoder::SetRateAllocation(rate_allocation, framerate); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 725 | } |
| 726 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 727 | Call::Config GetSenderCallConfig() override { |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 728 | Call::Config config = EndToEndTest::GetSenderCallConfig(); |
philipel | 4fb651d | 2017-04-10 03:54:05 -0700 | [diff] [blame] | 729 | config.event_log = event_log_.get(); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 730 | config.bitrate_config.start_bitrate_bps = kInitialBitrateKbps * 1000; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 731 | return config; |
| 732 | } |
| 733 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 734 | void ModifyVideoConfigs( |
| 735 | VideoSendStream::Config* send_config, |
| 736 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 737 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 738 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 739 | encoder_config->max_bitrate_bps = 2 * kReconfigureThresholdKbps * 1000; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 740 | encoder_config->video_stream_factory = |
| 741 | new rtc::RefCountedObject<VideoStreamFactory>(); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 742 | |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 743 | encoder_config_ = encoder_config->Copy(); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 744 | } |
| 745 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 746 | void OnVideoStreamsCreated( |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 747 | VideoSendStream* send_stream, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 748 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 749 | send_stream_ = send_stream; |
| 750 | } |
| 751 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 752 | void OnFrameGeneratorCapturerCreated( |
| 753 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
| 754 | frame_generator_ = frame_generator_capturer; |
| 755 | } |
| 756 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 757 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 758 | ASSERT_TRUE(time_to_reconfigure_.Wait(kDefaultTimeoutMs)) |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 759 | << "Timed out before receiving an initial high bitrate."; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 760 | frame_generator_->ChangeResolution(kDefaultWidth * 2, kDefaultHeight * 2); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 761 | send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 762 | EXPECT_TRUE(Wait()) |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 763 | << "Timed out while waiting for a couple of high bitrate estimates " |
| 764 | "after reconfiguring the send stream."; |
| 765 | } |
| 766 | |
| 767 | private: |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 768 | rtc::Event time_to_reconfigure_; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 769 | int encoder_inits_; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 770 | uint32_t last_set_bitrate_kbps_; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 771 | VideoSendStream* send_stream_; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 772 | test::FrameGeneratorCapturer* frame_generator_; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 773 | test::EncoderProxyFactory encoder_factory_; |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 774 | VideoEncoderConfig encoder_config_; |
| 775 | } test; |
| 776 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 777 | RunBaseTest(&test); |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Alex Narest | d0e196b | 2017-11-22 17:22:35 +0100 | [diff] [blame] | 780 | // Discovers the minimal supported audio+video bitrate. The test bitrate is |
| 781 | // considered supported if Rtt does not go above 400ms with the network |
| 782 | // contrained to the test bitrate. |
| 783 | // |
| 784 | // |use_bitrate_allocation_strategy| use AudioPriorityBitrateAllocationStrategy |
| 785 | // |test_bitrate_from test_bitrate_to| bitrate constraint range |
| 786 | // |test_bitrate_step| bitrate constraint update step during the test |
| 787 | // |min_bwe max_bwe| BWE range |
| 788 | // |start_bwe| initial BWE |
| 789 | void CallPerfTest::TestMinAudioVideoBitrate( |
| 790 | bool use_bitrate_allocation_strategy, |
| 791 | int test_bitrate_from, |
| 792 | int test_bitrate_to, |
| 793 | int test_bitrate_step, |
| 794 | int min_bwe, |
| 795 | int start_bwe, |
| 796 | int max_bwe) { |
| 797 | static const std::string kAudioTrackId = "audio_track_0"; |
| 798 | static constexpr uint32_t kSufficientAudioBitrateBps = 16000; |
| 799 | static constexpr int kOpusMinBitrateBps = 6000; |
| 800 | static constexpr int kOpusBitrateFbBps = 32000; |
| 801 | static constexpr int kBitrateStabilizationMs = 10000; |
| 802 | static constexpr int kBitrateMeasurements = 10; |
| 803 | static constexpr int kBitrateMeasurementMs = 1000; |
| 804 | static constexpr int kMinGoodRttMs = 400; |
| 805 | |
| 806 | class MinVideoAndAudioBitrateTester : public test::EndToEndTest { |
| 807 | public: |
| 808 | MinVideoAndAudioBitrateTester(bool use_bitrate_allocation_strategy, |
| 809 | int test_bitrate_from, |
| 810 | int test_bitrate_to, |
| 811 | int test_bitrate_step, |
| 812 | int min_bwe, |
| 813 | int start_bwe, |
| 814 | int max_bwe) |
| 815 | : EndToEndTest(), |
| 816 | allocation_strategy_(new rtc::AudioPriorityBitrateAllocationStrategy( |
| 817 | kAudioTrackId, |
| 818 | kSufficientAudioBitrateBps)), |
| 819 | use_bitrate_allocation_strategy_(use_bitrate_allocation_strategy), |
| 820 | test_bitrate_from_(test_bitrate_from), |
| 821 | test_bitrate_to_(test_bitrate_to), |
| 822 | test_bitrate_step_(test_bitrate_step), |
| 823 | min_bwe_(min_bwe), |
| 824 | start_bwe_(start_bwe), |
| 825 | max_bwe_(max_bwe) {} |
| 826 | |
| 827 | protected: |
| 828 | FakeNetworkPipe::Config GetFakeNetworkPipeConfig() { |
| 829 | FakeNetworkPipe::Config pipe_config; |
| 830 | pipe_config.link_capacity_kbps = test_bitrate_from_; |
| 831 | return pipe_config; |
| 832 | } |
| 833 | |
| 834 | test::PacketTransport* CreateSendTransport( |
| 835 | test::SingleThreadedTaskQueueForTesting* task_queue, |
| 836 | Call* sender_call) override { |
| 837 | return send_transport_ = new test::PacketTransport( |
| 838 | task_queue, sender_call, this, test::PacketTransport::kSender, |
| 839 | test::CallTest::payload_type_map_, GetFakeNetworkPipeConfig()); |
| 840 | } |
| 841 | |
| 842 | test::PacketTransport* CreateReceiveTransport( |
| 843 | test::SingleThreadedTaskQueueForTesting* task_queue) override { |
| 844 | return receive_transport_ = new test::PacketTransport( |
| 845 | task_queue, nullptr, this, test::PacketTransport::kReceiver, |
| 846 | test::CallTest::payload_type_map_, GetFakeNetworkPipeConfig()); |
| 847 | } |
| 848 | |
| 849 | void PerformTest() override { |
| 850 | int last_passed_test_bitrate = -1; |
| 851 | for (int test_bitrate = test_bitrate_from_; |
| 852 | test_bitrate_from_ < test_bitrate_to_ |
| 853 | ? test_bitrate <= test_bitrate_to_ |
| 854 | : test_bitrate >= test_bitrate_to_; |
| 855 | test_bitrate += test_bitrate_step_) { |
| 856 | FakeNetworkPipe::Config pipe_config; |
| 857 | pipe_config.link_capacity_kbps = test_bitrate; |
| 858 | send_transport_->SetConfig(pipe_config); |
| 859 | receive_transport_->SetConfig(pipe_config); |
| 860 | |
| 861 | rtc::ThreadManager::Instance()->CurrentThread()->SleepMs( |
| 862 | kBitrateStabilizationMs); |
| 863 | |
| 864 | int64_t avg_rtt = 0; |
| 865 | for (int i = 0; i < kBitrateMeasurements; i++) { |
| 866 | Call::Stats call_stats = sender_call_->GetStats(); |
| 867 | avg_rtt += call_stats.rtt_ms; |
| 868 | rtc::ThreadManager::Instance()->CurrentThread()->SleepMs( |
| 869 | kBitrateMeasurementMs); |
| 870 | } |
| 871 | avg_rtt = avg_rtt / kBitrateMeasurements; |
| 872 | if (avg_rtt > kMinGoodRttMs) { |
| 873 | break; |
| 874 | } else { |
| 875 | last_passed_test_bitrate = test_bitrate; |
| 876 | } |
| 877 | } |
| 878 | EXPECT_GT(last_passed_test_bitrate, -1) |
| 879 | << "Minimum supported bitrate out of the test scope"; |
Edward Lemur | 7f331fa | 2018-01-08 17:35:51 +0100 | [diff] [blame] | 880 | webrtc::test::PrintResult( |
| 881 | "min_test_bitrate_", |
| 882 | use_bitrate_allocation_strategy_ ? "with_allocation_strategy" |
| 883 | : "no_allocation_strategy", |
| 884 | "min_bitrate", last_passed_test_bitrate, "kbps", false); |
Alex Narest | d0e196b | 2017-11-22 17:22:35 +0100 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 888 | sender_call_ = sender_call; |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 889 | BitrateConstraints bitrate_config; |
Alex Narest | d0e196b | 2017-11-22 17:22:35 +0100 | [diff] [blame] | 890 | bitrate_config.min_bitrate_bps = min_bwe_; |
| 891 | bitrate_config.start_bitrate_bps = start_bwe_; |
| 892 | bitrate_config.max_bitrate_bps = max_bwe_; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 893 | sender_call->GetTransportControllerSend()->SetSdpBitrateParameters( |
| 894 | bitrate_config); |
Alex Narest | d0e196b | 2017-11-22 17:22:35 +0100 | [diff] [blame] | 895 | if (use_bitrate_allocation_strategy_) { |
| 896 | sender_call->SetBitrateAllocationStrategy( |
| 897 | std::move(allocation_strategy_)); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | size_t GetNumVideoStreams() const override { return 1; } |
| 902 | |
| 903 | size_t GetNumAudioStreams() const override { return 1; } |
| 904 | |
| 905 | void ModifyAudioConfigs( |
| 906 | AudioSendStream::Config* send_config, |
| 907 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
| 908 | if (use_bitrate_allocation_strategy_) { |
| 909 | send_config->track_id = kAudioTrackId; |
| 910 | send_config->min_bitrate_bps = kOpusMinBitrateBps; |
| 911 | send_config->max_bitrate_bps = kOpusBitrateFbBps; |
| 912 | } else { |
| 913 | send_config->send_codec_spec->target_bitrate_bps = |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 914 | absl::optional<int>(kOpusBitrateFbBps); |
Alex Narest | d0e196b | 2017-11-22 17:22:35 +0100 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | |
| 918 | private: |
| 919 | std::unique_ptr<rtc::BitrateAllocationStrategy> allocation_strategy_; |
| 920 | const bool use_bitrate_allocation_strategy_; |
| 921 | const int test_bitrate_from_; |
| 922 | const int test_bitrate_to_; |
| 923 | const int test_bitrate_step_; |
| 924 | const int min_bwe_; |
| 925 | const int start_bwe_; |
| 926 | const int max_bwe_; |
| 927 | test::PacketTransport* send_transport_; |
| 928 | test::PacketTransport* receive_transport_; |
| 929 | Call* sender_call_; |
| 930 | } test(use_bitrate_allocation_strategy, test_bitrate_from, test_bitrate_to, |
| 931 | test_bitrate_step, min_bwe, start_bwe, max_bwe); |
| 932 | |
| 933 | RunBaseTest(&test); |
| 934 | } |
| 935 | |
Taylor Brandstetter | 85904f4 | 2018-02-16 10:11:49 -0800 | [diff] [blame] | 936 | // TODO(bugs.webrtc.org/8878) |
| 937 | #if defined(WEBRTC_MAC) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 938 | #define MAYBE_MinVideoAndAudioBitrate DISABLED_MinVideoAndAudioBitrate |
Taylor Brandstetter | 85904f4 | 2018-02-16 10:11:49 -0800 | [diff] [blame] | 939 | #else |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 940 | #define MAYBE_MinVideoAndAudioBitrate MinVideoAndAudioBitrate |
Taylor Brandstetter | 85904f4 | 2018-02-16 10:11:49 -0800 | [diff] [blame] | 941 | #endif |
| 942 | TEST_F(CallPerfTest, MAYBE_MinVideoAndAudioBitrate) { |
Alex Narest | d0e196b | 2017-11-22 17:22:35 +0100 | [diff] [blame] | 943 | TestMinAudioVideoBitrate(false, 110, 40, -10, 10000, 70000, 200000); |
| 944 | } |
| 945 | TEST_F(CallPerfTest, MinVideoAndAudioBitrateWStrategy) { |
| 946 | TestMinAudioVideoBitrate(true, 110, 40, -10, 10000, 70000, 200000); |
| 947 | } |
| 948 | |
pbos@webrtc.org | 1d09690 | 2013-12-13 12:48:05 +0000 | [diff] [blame] | 949 | } // namespace webrtc |