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