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