blob: 9379dce83307a0bdb8808f6eee365c73f87773b7 [file] [log] [blame]
pbos@webrtc.org1d096902013-12-13 12:48:051/*
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 */
asaperssonf8cdd182016-03-15 08:00:4710
pbos@webrtc.org1d096902013-12-13 12:48:0511#include <algorithm>
asaperssonf8cdd182016-03-15 08:00:4712#include <limits>
kwibergb25345e2016-03-12 14:10:4413#include <memory>
pbos@webrtc.org1d096902013-12-13 12:48:0514#include <string>
15
Ali Tofigh641a1b12022-05-17 09:48:4616#include "absl/strings/string_view.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Artem Titov14b42c22022-09-26 11:21:1418#include "api/numerics/samples_stats_counter.h"
Danil Chapovalov83bbe912019-08-07 10:24:5319#include "api/rtc_event_log/rtc_event_log.h"
Artem Titovc374d112022-06-16 19:27:4520#include "api/task_queue/pending_task_safety_flag.h"
Danil Chapovalov44db4362019-09-30 02:16:2821#include "api/task_queue/task_queue_base.h"
Artem Titov14b42c22022-09-26 11:21:1422#include "api/test/metrics/global_metrics_logger_and_exporter.h"
23#include "api/test/metrics/metric.h"
Artem Titov46c4e602018-08-17 12:26:5424#include "api/test/simulated_network.h"
Jiawei Ouc2ebe212018-11-08 18:02:5625#include "api/video/builtin_video_bitrate_allocator_factory.h"
Erik Språngef75ebe2018-05-15 13:18:3626#include "api/video/video_bitrate_allocation.h"
Elad Alon370f93a2019-06-11 12:57:5727#include "api/video_codecs/video_encoder.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3128#include "call/call.h"
Artem Titov4e199e92018-08-20 11:30:3929#include "call/fake_network_pipe.h"
30#include "call/simulated_network.h"
Åsa Persson59947d22021-08-26 10:04:2731#include "media/engine/internal_encoder_factory.h"
32#include "media/engine/simulcast_encoder_adapter.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3133#include "modules/audio_coding/include/audio_coding_module.h"
Artem Titov3faa8322018-03-07 13:44:0034#include "modules/audio_device/include/test_audio_device.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3135#include "modules/audio_mixer/audio_mixer_impl.h"
Danil Chapovalov1b4e4bf2019-12-06 11:34:5736#include "modules/rtp_rtcp/source/rtp_packet.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3137#include "rtc_base/checks.h"
Markus Handell8fe932a2020-07-06 15:41:3538#include "rtc_base/synchronization/mutex.h"
Danil Chapovalov82a3f0a2019-10-21 07:24:2739#include "rtc_base/task_queue_for_test.h"
Niels Möllera8370302019-09-02 13:16:4940#include "rtc_base/thread.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3141#include "rtc_base/thread_annotations.h"
Mirko Bonadei17f48782018-09-28 06:51:1042#include "system_wrappers/include/metrics.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3143#include "test/call_test.h"
44#include "test/direct_transport.h"
45#include "test/drifting_clock.h"
46#include "test/encoder_settings.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3147#include "test/fake_encoder.h"
48#include "test/field_trial.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3149#include "test/frame_generator_capturer.h"
50#include "test/gtest.h"
Niels Möllerae4237e2018-10-05 09:28:3851#include "test/null_transport.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3152#include "test/rtp_rtcp_observer.h"
Steve Anton10542f22019-01-11 17:11:0053#include "test/testsupport/file_utils.h"
Niels Möllercbcbc222018-09-28 07:07:2454#include "test/video_encoder_proxy_factory.h"
Jonas Oreland6c2dae22022-09-29 08:28:2455#include "video/config/video_encoder_config.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3156#include "video/transport_adapter.h"
pbos@webrtc.org1d096902013-12-13 12:48:0557
danilchap9c6a0c72016-02-10 18:54:4758using webrtc::test::DriftingClock;
danilchap9c6a0c72016-02-10 18:54:4759
pbos@webrtc.org1d096902013-12-13 12:48:0560namespace webrtc {
Elad Alond8d32482019-02-18 22:45:5761namespace {
Artem Titov14b42c22022-09-26 11:21:1462
63using ::webrtc::test::GetGlobalMetricsLogger;
64using ::webrtc::test::ImprovementDirection;
65using ::webrtc::test::Unit;
66
Elad Alond8d32482019-02-18 22:45:5767enum : int { // The first valid value is 1.
68 kTransportSequenceNumberExtensionId = 1,
69};
Artem Titov14b42c22022-09-26 11:21:1470
Elad Alond8d32482019-02-18 22:45:5771} // namespace
pbos@webrtc.org1d096902013-12-13 12:48:0572
pbos@webrtc.org994d0b72014-06-27 08:47:5273class CallPerfTest : public test::CallTest {
Elad Alond8d32482019-02-18 22:45:5774 public:
75 CallPerfTest() {
76 RegisterRtpExtension(RtpExtension(RtpExtension::kTransportSequenceNumberUri,
77 kTransportSequenceNumberExtensionId));
78 }
79
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:0780 protected:
Yves Gerey665174f2018-06-19 13:03:0581 enum class FecMode { kOn, kOff };
82 enum class CreateOrder { kAudioFirst, kVideoFirst };
Danil Chapovalovcde5d6b2016-02-15 10:14:5883 void TestAudioVideoSync(FecMode fec,
84 CreateOrder create_first,
danilchap9c6a0c72016-02-10 18:54:4785 float video_ntp_speed,
86 float video_rtp_speed,
Edward Lemur947f3fe2017-12-28 14:50:3387 float audio_rtp_speed,
Ali Tofigh641a1b12022-05-17 09:48:4688 absl::string_view test_label);
stefan@webrtc.org01581da2014-09-04 06:48:1489
pbos@webrtc.org3349ae02014-03-13 12:52:2790 void TestMinTransmitBitrate(bool pad_to_min_bitrate);
91
Artem Titov75e36472018-10-08 10:28:5692 void TestCaptureNtpTime(const BuiltInNetworkBehaviorConfig& net_config,
wu@webrtc.orgcd701192014-04-24 22:10:2493 int threshold_ms,
94 int start_time_ms,
95 int run_time_ms);
Jonas Olsson0182a032019-07-09 10:31:2096 void TestMinAudioVideoBitrate(int test_bitrate_from,
Alex Narestd0e196b2017-11-22 16:22:3597 int test_bitrate_to,
98 int test_bitrate_step,
99 int min_bwe,
100 int start_bwe,
101 int max_bwe);
Åsa Persson59947d22021-08-26 10:04:27102 void TestEncodeFramerate(VideoEncoderFactory* encoder_factory,
Ali Tofigh641a1b12022-05-17 09:48:46103 absl::string_view payload_name,
Åsa Persson59947d22021-08-26 10:04:27104 const std::vector<int>& max_framerates);
pbos@webrtc.org1d096902013-12-13 12:48:05105};
106
asaperssonf8cdd182016-03-15 08:00:47107class VideoRtcpAndSyncObserver : public test::RtpRtcpObserver,
nisse7ade7b32016-03-23 11:48:10108 public rtc::VideoSinkInterface<VideoFrame> {
pbos@webrtc.org1d096902013-12-13 12:48:05109 static const int kInSyncThresholdMs = 50;
110 static const int kStartupTimeMs = 2000;
111 static const int kMinRunTimeMs = 30000;
112
113 public:
Tommi3c9bcc12020-04-15 14:45:47114 explicit VideoRtcpAndSyncObserver(TaskQueueBase* task_queue,
115 Clock* clock,
Ali Tofigh641a1b12022-05-17 09:48:46116 absl::string_view test_label)
Markus Handellf4f22872022-08-16 11:02:45117 : test::RtpRtcpObserver(CallPerfTest::kLongTimeout),
asaperssonf8cdd182016-03-15 08:00:47118 clock_(clock),
Edward Lemur947f3fe2017-12-28 14:50:33119 test_label_(test_label),
pbos@webrtc.org1d096902013-12-13 12:48:05120 creation_time_ms_(clock_->TimeInMilliseconds()),
Tommi3c9bcc12020-04-15 14:45:47121 task_queue_(task_queue) {}
pbos@webrtc.org1d096902013-12-13 12:48:05122
nisseeb83a1a2016-03-21 08:27:56123 void OnFrame(const VideoFrame& video_frame) override {
Danil Chapovalovb7128ed2022-07-06 16:35:01124 task_queue_->PostTask([this]() { CheckStats(); });
Tommi3c9bcc12020-04-15 14:45:47125 }
126
127 void CheckStats() {
128 if (!receive_stream_)
129 return;
130
Tommif6f45432022-05-20 13:21:20131 VideoReceiveStreamInterface::Stats stats = receive_stream_->GetStats();
asaperssonf8cdd182016-03-15 08:00:47132 if (stats.sync_offset_ms == std::numeric_limits<int>::max())
133 return;
134
pbos@webrtc.org1d096902013-12-13 12:48:05135 int64_t now_ms = clock_->TimeInMilliseconds();
pbos@webrtc.org1d096902013-12-13 12:48:05136 int64_t time_since_creation = now_ms - creation_time_ms_;
137 // During the first couple of seconds audio and video can falsely be
138 // estimated as being synchronized. We don't want to trigger on those.
139 if (time_since_creation < kStartupTimeMs)
140 return;
asaperssonf8cdd182016-03-15 08:00:47141 if (std::abs(stats.sync_offset_ms) < kInSyncThresholdMs) {
pbos@webrtc.org1d096902013-12-13 12:48:05142 if (first_time_in_sync_ == -1) {
143 first_time_in_sync_ = now_ms;
Artem Titov14b42c22022-09-26 11:21:14144 GetGlobalMetricsLogger()->LogSingleValueMetric(
145 "sync_convergence_time" + test_label_, "synchronization",
146 time_since_creation, Unit::kMilliseconds,
147 ImprovementDirection::kSmallerIsBetter);
pbos@webrtc.org1d096902013-12-13 12:48:05148 }
149 if (time_since_creation > kMinRunTimeMs)
Peter Boström5811a392015-12-10 12:02:50150 observation_complete_.Set();
pbos@webrtc.org1d096902013-12-13 12:48:05151 }
Danil Chapovalov371b43b2016-06-16 07:58:44152 if (first_time_in_sync_ != -1)
Artem Titov14b42c22022-09-26 11:21:14153 sync_offset_ms_list_.AddSample(stats.sync_offset_ms);
pbos@webrtc.org1d096902013-12-13 12:48:05154 }
155
Tommif6f45432022-05-20 13:21:20156 void set_receive_stream(VideoReceiveStreamInterface* receive_stream) {
Tommi3c9bcc12020-04-15 14:45:47157 RTC_DCHECK_EQ(task_queue_, TaskQueueBase::Current());
158 // Note that receive_stream may be nullptr.
asaperssonf8cdd182016-03-15 08:00:47159 receive_stream_ = receive_stream;
160 }
161
danilchap46b89b92016-06-03 16:27:37162 void PrintResults() {
Artem Titov14b42c22022-09-26 11:21:14163 GetGlobalMetricsLogger()->LogMetric(
164 "stream_offset" + test_label_, "synchronization", sync_offset_ms_list_,
165 Unit::kMilliseconds, ImprovementDirection::kNeitherIsBetter);
danilchap46b89b92016-06-03 16:27:37166 }
167
pbos@webrtc.org1d096902013-12-13 12:48:05168 private:
pbos@webrtc.orgde1429e2014-04-28 13:00:21169 Clock* const clock_;
Åsa Persson59947d22021-08-26 10:04:27170 const std::string test_label_;
stefanf116bd02015-10-27 15:29:42171 const int64_t creation_time_ms_;
Tommi3c9bcc12020-04-15 14:45:47172 int64_t first_time_in_sync_ = -1;
Tommif6f45432022-05-20 13:21:20173 VideoReceiveStreamInterface* receive_stream_ = nullptr;
Artem Titov14b42c22022-09-26 11:21:14174 SamplesStatsCounter sync_offset_ms_list_;
Tommi3c9bcc12020-04-15 14:45:47175 TaskQueueBase* const task_queue_;
pbos@webrtc.org1d096902013-12-13 12:48:05176};
177
Danil Chapovalovcde5d6b2016-02-15 10:14:58178void CallPerfTest::TestAudioVideoSync(FecMode fec,
179 CreateOrder create_first,
danilchap9c6a0c72016-02-10 18:54:47180 float video_ntp_speed,
181 float video_rtp_speed,
Edward Lemur947f3fe2017-12-28 14:50:33182 float audio_rtp_speed,
Ali Tofigh641a1b12022-05-17 09:48:46183 absl::string_view test_label) {
pbos8fc7fa72015-07-15 15:02:58184 const char* kSyncGroup = "av_sync";
Stefan Holmerb86d4e42015-12-07 09:26:18185 const uint32_t kAudioSendSsrc = 1234;
186 const uint32_t kAudioRecvSsrc = 5678;
pbos@webrtc.org994d0b72014-06-27 08:47:52187
Artem Titov75e36472018-10-08 10:28:56188 BuiltInNetworkBehaviorConfig audio_net_config;
mflodman3d7db262016-04-29 07:57:13189 audio_net_config.queue_delay_ms = 500;
190 audio_net_config.loss_percent = 5;
minyue20c84cc2017-04-10 23:57:57191
Tommi3c9bcc12020-04-15 14:45:47192 auto observer = std::make_unique<VideoRtcpAndSyncObserver>(
193 task_queue(), Clock::GetRealTimeClock(), test_label);
eladalon413ee9a2017-08-22 11:02:52194
minyue20c84cc2017-04-10 23:57:57195 std::map<uint8_t, MediaType> audio_pt_map;
196 std::map<uint8_t, MediaType> video_pt_map;
minyue20c84cc2017-04-10 23:57:57197
eladalon413ee9a2017-08-22 11:02:52198 std::unique_ptr<test::PacketTransport> audio_send_transport;
199 std::unique_ptr<test::PacketTransport> video_send_transport;
200 std::unique_ptr<test::PacketTransport> receive_transport;
mflodman3d7db262016-04-29 07:57:13201
eladalon413ee9a2017-08-22 11:02:52202 AudioSendStream* audio_send_stream;
Tommi3176ef72022-05-22 18:47:28203 AudioReceiveStreamInterface* audio_receive_stream;
eladalon413ee9a2017-08-22 11:02:52204 std::unique_ptr<DriftingClock> drifting_clock;
pbos8fc7fa72015-07-15 15:02:58205
Danil Chapovalove519f382022-08-11 10:26:09206 SendTask(task_queue(), [&]() {
eladalon413ee9a2017-08-22 11:02:52207 metrics::Reset();
Artem Titov3faa8322018-03-07 13:44:00208 rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device =
Danil Chapovalov08fa9532019-06-12 11:49:17209 TestAudioDeviceModule::Create(
210 task_queue_factory_.get(),
Artem Titov3faa8322018-03-07 13:44:00211 TestAudioDeviceModule::CreatePulsedNoiseCapturer(256, 48000),
212 TestAudioDeviceModule::CreateDiscardRenderer(48000),
213 audio_rtp_speed);
Fredrik Solenbergd3195342017-11-21 19:33:05214 EXPECT_EQ(0, fake_audio_device->Init());
pbos@webrtc.org994d0b72014-06-27 08:47:52215
eladalon413ee9a2017-08-22 11:02:52216 AudioState::Config send_audio_state_config;
eladalon413ee9a2017-08-22 11:02:52217 send_audio_state_config.audio_mixer = AudioMixerImpl::Create();
Ivo Creusen62337e52018-01-09 13:17:33218 send_audio_state_config.audio_processing =
219 AudioProcessingBuilder().Create();
Fredrik Solenberg2a877972017-12-15 15:42:15220 send_audio_state_config.audio_device_module = fake_audio_device;
Sebastian Jansson8e6602f2018-07-13 08:43:20221 Call::Config sender_config(send_event_log_.get());
pbos@webrtc.org1d096902013-12-13 12:48:05222
Fredrik Solenbergd3195342017-11-21 19:33:05223 auto audio_state = AudioState::Create(send_audio_state_config);
224 fake_audio_device->RegisterAudioCallback(audio_state->audio_transport());
225 sender_config.audio_state = audio_state;
Sebastian Jansson8e6602f2018-07-13 08:43:20226 Call::Config receiver_config(recv_event_log_.get());
Fredrik Solenbergd3195342017-11-21 19:33:05227 receiver_config.audio_state = audio_state;
eladalon413ee9a2017-08-22 11:02:52228 CreateCalls(sender_config, receiver_config);
229
230 std::copy_if(std::begin(payload_type_map_), std::end(payload_type_map_),
231 std::inserter(audio_pt_map, audio_pt_map.end()),
232 [](const std::pair<const uint8_t, MediaType>& pair) {
233 return pair.second == MediaType::AUDIO;
234 });
235 std::copy_if(std::begin(payload_type_map_), std::end(payload_type_map_),
236 std::inserter(video_pt_map, video_pt_map.end()),
237 [](const std::pair<const uint8_t, MediaType>& pair) {
238 return pair.second == MediaType::VIDEO;
239 });
240
Mirko Bonadei317a1f02019-09-17 15:06:18241 audio_send_transport = std::make_unique<test::PacketTransport>(
Tommi3c9bcc12020-04-15 14:45:47242 task_queue(), sender_call_.get(), observer.get(),
Artem Titov4e199e92018-08-20 11:30:39243 test::PacketTransport::kSender, audio_pt_map,
Mirko Bonadei317a1f02019-09-17 15:06:18244 std::make_unique<FakeNetworkPipe>(
Artem Titov4e199e92018-08-20 11:30:39245 Clock::GetRealTimeClock(),
Mirko Bonadei317a1f02019-09-17 15:06:18246 std::make_unique<SimulatedNetwork>(audio_net_config)));
eladalon413ee9a2017-08-22 11:02:52247 audio_send_transport->SetReceiver(receiver_call_->Receiver());
248
Mirko Bonadei317a1f02019-09-17 15:06:18249 video_send_transport = std::make_unique<test::PacketTransport>(
Tommi3c9bcc12020-04-15 14:45:47250 task_queue(), sender_call_.get(), observer.get(),
eladalon413ee9a2017-08-22 11:02:52251 test::PacketTransport::kSender, video_pt_map,
Mirko Bonadei317a1f02019-09-17 15:06:18252 std::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(),
253 std::make_unique<SimulatedNetwork>(
254 BuiltInNetworkBehaviorConfig())));
eladalon413ee9a2017-08-22 11:02:52255 video_send_transport->SetReceiver(receiver_call_->Receiver());
256
Mirko Bonadei317a1f02019-09-17 15:06:18257 receive_transport = std::make_unique<test::PacketTransport>(
Tommi3c9bcc12020-04-15 14:45:47258 task_queue(), receiver_call_.get(), observer.get(),
eladalon413ee9a2017-08-22 11:02:52259 test::PacketTransport::kReceiver, payload_type_map_,
Mirko Bonadei317a1f02019-09-17 15:06:18260 std::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(),
261 std::make_unique<SimulatedNetwork>(
262 BuiltInNetworkBehaviorConfig())));
eladalon413ee9a2017-08-22 11:02:52263 receive_transport->SetReceiver(sender_call_->Receiver());
264
265 CreateSendConfig(1, 0, 0, video_send_transport.get());
266 CreateMatchingReceiveConfigs(receive_transport.get());
267
Bjorn A Mellem7a9a0922019-11-26 17:19:40268 AudioSendStream::Config audio_send_config(audio_send_transport.get());
eladalon413ee9a2017-08-22 11:02:52269 audio_send_config.rtp.ssrc = kAudioSendSsrc;
Oskar Sundbomfedc00c2017-11-16 09:55:08270 audio_send_config.send_codec_spec = AudioSendStream::Config::SendCodecSpec(
271 kAudioSendPayloadType, {"ISAC", 16000, 1});
eladalon413ee9a2017-08-22 11:02:52272 audio_send_config.encoder_factory = CreateBuiltinAudioEncoderFactory();
273 audio_send_stream = sender_call_->CreateAudioSendStream(audio_send_config);
274
Sebastian Janssonf33905d2018-07-13 07:49:00275 GetVideoSendConfig()->rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
eladalon413ee9a2017-08-22 11:02:52276 if (fec == FecMode::kOn) {
Sebastian Janssonf33905d2018-07-13 07:49:00277 GetVideoSendConfig()->rtp.ulpfec.red_payload_type = kRedPayloadType;
278 GetVideoSendConfig()->rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType;
nisse3b3622f2017-09-26 09:49:21279 video_receive_configs_[0].rtp.red_payload_type = kRedPayloadType;
280 video_receive_configs_[0].rtp.ulpfec_payload_type = kUlpfecPayloadType;
eladalon413ee9a2017-08-22 11:02:52281 }
282 video_receive_configs_[0].rtp.nack.rtp_history_ms = 1000;
Tommi3c9bcc12020-04-15 14:45:47283 video_receive_configs_[0].renderer = observer.get();
eladalon413ee9a2017-08-22 11:02:52284 video_receive_configs_[0].sync_group = kSyncGroup;
285
Tommi3176ef72022-05-22 18:47:28286 AudioReceiveStreamInterface::Config audio_recv_config;
eladalon413ee9a2017-08-22 11:02:52287 audio_recv_config.rtp.remote_ssrc = kAudioSendSsrc;
288 audio_recv_config.rtp.local_ssrc = kAudioRecvSsrc;
Jakob Ivarsson4cd92d82020-10-31 11:40:43289 audio_recv_config.rtcp_send_transport = receive_transport.get();
eladalon413ee9a2017-08-22 11:02:52290 audio_recv_config.sync_group = kSyncGroup;
Niels Möller2784a032018-03-28 12:16:04291 audio_recv_config.decoder_factory = audio_decoder_factory_;
eladalon413ee9a2017-08-22 11:02:52292 audio_recv_config.decoder_map = {
293 {kAudioSendPayloadType, {"ISAC", 16000, 1}}};
294
295 if (create_first == CreateOrder::kAudioFirst) {
296 audio_receive_stream =
297 receiver_call_->CreateAudioReceiveStream(audio_recv_config);
298 CreateVideoStreams();
299 } else {
300 CreateVideoStreams();
301 audio_receive_stream =
302 receiver_call_->CreateAudioReceiveStream(audio_recv_config);
303 }
304 EXPECT_EQ(1u, video_receive_streams_.size());
Tommi3c9bcc12020-04-15 14:45:47305 observer->set_receive_stream(video_receive_streams_[0]);
Mirko Bonadei317a1f02019-09-17 15:06:18306 drifting_clock = std::make_unique<DriftingClock>(clock_, video_ntp_speed);
eladalon413ee9a2017-08-22 11:02:52307 CreateFrameGeneratorCapturerWithDrift(drifting_clock.get(), video_rtp_speed,
308 kDefaultFramerate, kDefaultWidth,
309 kDefaultHeight);
310
311 Start();
312
313 audio_send_stream->Start();
314 audio_receive_stream->Start();
315 });
pbos@webrtc.org1d096902013-12-13 12:48:05316
Tommi3c9bcc12020-04-15 14:45:47317 EXPECT_TRUE(observer->Wait())
pbos@webrtc.org1d096902013-12-13 12:48:05318 << "Timed out while waiting for audio and video to be synchronized.";
319
Danil Chapovalove519f382022-08-11 10:26:09320 SendTask(task_queue(), [&]() {
Tommi3c9bcc12020-04-15 14:45:47321 // Clear the pointer to the receive stream since it will now be deleted.
322 observer->set_receive_stream(nullptr);
323
eladalon413ee9a2017-08-22 11:02:52324 audio_send_stream->Stop();
325 audio_receive_stream->Stop();
pbos@webrtc.org1d096902013-12-13 12:48:05326
eladalon413ee9a2017-08-22 11:02:52327 Stop();
pbos@webrtc.org1d096902013-12-13 12:48:05328
eladalon413ee9a2017-08-22 11:02:52329 DestroyStreams();
Stefan Holmerb86d4e42015-12-07 09:26:18330
eladalon413ee9a2017-08-22 11:02:52331 sender_call_->DestroyAudioSendStream(audio_send_stream);
332 receiver_call_->DestroyAudioReceiveStream(audio_receive_stream);
pbos@webrtc.org994d0b72014-06-27 08:47:52333
eladalon413ee9a2017-08-22 11:02:52334 DestroyCalls();
Danil Chapovalov5d2bf192020-12-30 16:12:27335 // Call may post periodic rtcp packet to the transport on the process
336 // thread, thus transport should be destroyed after the call objects.
337 // Though transports keep pointers to the call objects, transports handle
338 // packets on the task_queue() and thus wouldn't create a race while current
339 // destruction happens in the same task as destruction of the call objects.
340 video_send_transport.reset();
341 audio_send_transport.reset();
342 receive_transport.reset();
eladalon413ee9a2017-08-22 11:02:52343 });
asaperssonf8cdd182016-03-15 08:00:47344
Tommi3c9bcc12020-04-15 14:45:47345 observer->PrintResults();
ilnik5328b9e2017-02-21 13:20:28346
347 // In quick test synchronization may not be achieved in time.
sprange5d3a3e2017-03-01 14:20:56348 if (!field_trial::IsEnabled("WebRTC-QuickPerfTest")) {
Artem Titarenkoded1e4f2019-03-15 10:36:39349// TODO(bugs.webrtc.org/10417): Reenable this for iOS
350#if !defined(WEBRTC_IOS)
Ying Wangef3998f2019-12-09 12:06:53351 EXPECT_METRIC_EQ(1, metrics::NumSamples("WebRTC.Video.AVSyncOffsetInMs"));
Artem Titarenkoded1e4f2019-03-15 10:36:39352#endif
ilnik5328b9e2017-02-21 13:20:28353 }
Tommi3c9bcc12020-04-15 14:45:47354
355 task_queue()->PostTask(
Danil Chapovalovb7128ed2022-07-06 16:35:01356 [to_delete = observer.release()]() { delete to_delete; });
pbos@webrtc.org1d096902013-12-13 12:48:05357}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07358
Jeremy Lecontec8850cb2020-09-10 18:46:33359TEST_F(CallPerfTest, Synchronization_PlaysOutAudioAndVideoWithoutClockDrift) {
Niels Möller9a750612018-08-09 09:04:32360 TestAudioVideoSync(FecMode::kOff, CreateOrder::kAudioFirst,
361 DriftingClock::kNoDrift, DriftingClock::kNoDrift,
362 DriftingClock::kNoDrift, "_video_no_drift");
363}
364
Jeremy Lecontec8850cb2020-09-10 18:46:33365TEST_F(CallPerfTest, Synchronization_PlaysOutAudioAndVideoWithVideoNtpDrift) {
Danil Chapovalovcde5d6b2016-02-15 10:14:58366 TestAudioVideoSync(FecMode::kOff, CreateOrder::kAudioFirst,
367 DriftingClock::PercentsFaster(10.0f),
Edward Lemur947f3fe2017-12-28 14:50:33368 DriftingClock::kNoDrift, DriftingClock::kNoDrift,
369 "_video_ntp_drift");
danilchap9c6a0c72016-02-10 18:54:47370}
371
Jeremy Lecontec8850cb2020-09-10 18:46:33372TEST_F(CallPerfTest,
373 Synchronization_PlaysOutAudioAndVideoWithAudioFasterThanVideoDrift) {
Danil Chapovalovcde5d6b2016-02-15 10:14:58374 TestAudioVideoSync(FecMode::kOff, CreateOrder::kAudioFirst,
375 DriftingClock::kNoDrift,
danilchap9c6a0c72016-02-10 18:54:47376 DriftingClock::PercentsSlower(30.0f),
Edward Lemur947f3fe2017-12-28 14:50:33377 DriftingClock::PercentsFaster(30.0f), "_audio_faster");
danilchap9c6a0c72016-02-10 18:54:47378}
379
Danil Chapovalov5d2bf192020-12-30 16:12:27380TEST_F(CallPerfTest,
381 Synchronization_PlaysOutAudioAndVideoWithVideoFasterThanAudioDrift) {
Danil Chapovalovcde5d6b2016-02-15 10:14:58382 TestAudioVideoSync(FecMode::kOn, CreateOrder::kVideoFirst,
383 DriftingClock::kNoDrift,
danilchap9c6a0c72016-02-10 18:54:47384 DriftingClock::PercentsFaster(30.0f),
Edward Lemur947f3fe2017-12-28 14:50:33385 DriftingClock::PercentsSlower(30.0f), "_video_faster");
stefan@webrtc.org01581da2014-09-04 06:48:14386}
387
Artem Titov46c4e602018-08-17 12:26:54388void CallPerfTest::TestCaptureNtpTime(
Artem Titov75e36472018-10-08 10:28:56389 const BuiltInNetworkBehaviorConfig& net_config,
Artem Titov46c4e602018-08-17 12:26:54390 int threshold_ms,
391 int start_time_ms,
392 int run_time_ms) {
pbos@webrtc.org994d0b72014-06-27 08:47:52393 class CaptureNtpTimeObserver : public test::EndToEndTest,
nisse7ade7b32016-03-23 11:48:10394 public rtc::VideoSinkInterface<VideoFrame> {
pbos@webrtc.org994d0b72014-06-27 08:47:52395 public:
Artem Titov75e36472018-10-08 10:28:56396 CaptureNtpTimeObserver(const BuiltInNetworkBehaviorConfig& net_config,
stefane74eef12016-01-08 14:47:13397 int threshold_ms,
398 int start_time_ms,
399 int run_time_ms)
Markus Handellf4f22872022-08-16 11:02:45400 : EndToEndTest(kLongTimeout),
stefane74eef12016-01-08 14:47:13401 net_config_(net_config),
pbos@webrtc.org994d0b72014-06-27 08:47:52402 clock_(Clock::GetRealTimeClock()),
403 threshold_ms_(threshold_ms),
404 start_time_ms_(start_time_ms),
405 run_time_ms_(run_time_ms),
406 creation_time_ms_(clock_->TimeInMilliseconds()),
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24407 capturer_(nullptr),
pbos@webrtc.org994d0b72014-06-27 08:47:52408 rtp_start_timestamp_set_(false),
409 rtp_start_timestamp_(0) {}
wu@webrtc.orgcd701192014-04-24 22:10:24410
pbos@webrtc.org994d0b72014-06-27 08:47:52411 private:
Danil Chapovalov44db4362019-09-30 02:16:28412 std::unique_ptr<test::PacketTransport> CreateSendTransport(
413 TaskQueueBase* task_queue,
eladalon413ee9a2017-08-22 11:02:52414 Call* sender_call) override {
Danil Chapovalov44db4362019-09-30 02:16:28415 return std::make_unique<test::PacketTransport>(
Artem Titov4e199e92018-08-20 11:30:39416 task_queue, sender_call, this, test::PacketTransport::kSender,
417 payload_type_map_,
Mirko Bonadei317a1f02019-09-17 15:06:18418 std::make_unique<FakeNetworkPipe>(
Artem Titov4e199e92018-08-20 11:30:39419 Clock::GetRealTimeClock(),
Mirko Bonadei317a1f02019-09-17 15:06:18420 std::make_unique<SimulatedNetwork>(net_config_)));
stefane74eef12016-01-08 14:47:13421 }
422
Danil Chapovalov44db4362019-09-30 02:16:28423 std::unique_ptr<test::PacketTransport> CreateReceiveTransport(
424 TaskQueueBase* task_queue) override {
425 return std::make_unique<test::PacketTransport>(
Artem Titov4e199e92018-08-20 11:30:39426 task_queue, nullptr, this, test::PacketTransport::kReceiver,
427 payload_type_map_,
Mirko Bonadei317a1f02019-09-17 15:06:18428 std::make_unique<FakeNetworkPipe>(
Artem Titov4e199e92018-08-20 11:30:39429 Clock::GetRealTimeClock(),
Mirko Bonadei317a1f02019-09-17 15:06:18430 std::make_unique<SimulatedNetwork>(net_config_)));
Stefan Holmerea8c0f62016-01-13 07:58:38431 }
432
nisseeb83a1a2016-03-21 08:27:56433 void OnFrame(const VideoFrame& video_frame) override {
Markus Handell8fe932a2020-07-06 15:41:35434 MutexLock lock(&mutex_);
pbos@webrtc.org994d0b72014-06-27 08:47:52435 if (video_frame.ntp_time_ms() <= 0) {
436 // Haven't got enough RTCP SR in order to calculate the capture ntp
437 // time.
438 return;
439 }
wu@webrtc.orgcd701192014-04-24 22:10:24440
pbos@webrtc.org994d0b72014-06-27 08:47:52441 int64_t now_ms = clock_->TimeInMilliseconds();
442 int64_t time_since_creation = now_ms - creation_time_ms_;
443 if (time_since_creation < start_time_ms_) {
Artem Titovea240272021-07-26 10:40:21444 // Wait for `start_time_ms_` before start measuring.
pbos@webrtc.org994d0b72014-06-27 08:47:52445 return;
446 }
wu@webrtc.orgcd701192014-04-24 22:10:24447
pbos@webrtc.org994d0b72014-06-27 08:47:52448 if (time_since_creation > run_time_ms_) {
Peter Boström5811a392015-12-10 12:02:50449 observation_complete_.Set();
pbos@webrtc.org994d0b72014-06-27 08:47:52450 }
wu@webrtc.orgcd701192014-04-24 22:10:24451
pbos@webrtc.org994d0b72014-06-27 08:47:52452 FrameCaptureTimeList::iterator iter =
453 capture_time_list_.find(video_frame.timestamp());
454 EXPECT_TRUE(iter != capture_time_list_.end());
wu@webrtc.orgcd701192014-04-24 22:10:24455
pbos@webrtc.org994d0b72014-06-27 08:47:52456 // The real capture time has been wrapped to uint32_t before converted
457 // to rtp timestamp in the sender side. So here we convert the estimated
458 // capture time to a uint32_t 90k timestamp also for comparing.
459 uint32_t estimated_capture_timestamp =
460 90 * static_cast<uint32_t>(video_frame.ntp_time_ms());
461 uint32_t real_capture_timestamp = iter->second;
462 int time_offset_ms = real_capture_timestamp - estimated_capture_timestamp;
463 time_offset_ms = time_offset_ms / 90;
Artem Titov14b42c22022-09-26 11:21:14464 time_offset_ms_list_.AddSample(time_offset_ms);
wu@webrtc.orgcd701192014-04-24 22:10:24465
pbos@webrtc.org994d0b72014-06-27 08:47:52466 EXPECT_TRUE(std::abs(time_offset_ms) < threshold_ms_);
467 }
wu@webrtc.orgcd701192014-04-24 22:10:24468
nisseef8b61e2016-04-29 13:09:15469 Action OnSendRtp(const uint8_t* packet, size_t length) override {
Markus Handell8fe932a2020-07-06 15:41:35470 MutexLock lock(&mutex_);
Danil Chapovalov1b4e4bf2019-12-06 11:34:57471 RtpPacket rtp_packet;
472 EXPECT_TRUE(rtp_packet.Parse(packet, length));
pbos@webrtc.org994d0b72014-06-27 08:47:52473
474 if (!rtp_start_timestamp_set_) {
475 // Calculate the rtp timestamp offset in order to calculate the real
476 // capture time.
477 uint32_t first_capture_timestamp =
478 90 * static_cast<uint32_t>(capturer_->first_frame_capture_time());
Danil Chapovalov1b4e4bf2019-12-06 11:34:57479 rtp_start_timestamp_ = rtp_packet.Timestamp() - first_capture_timestamp;
pbos@webrtc.org994d0b72014-06-27 08:47:52480 rtp_start_timestamp_set_ = true;
481 }
482
Danil Chapovalov1b4e4bf2019-12-06 11:34:57483 uint32_t capture_timestamp =
484 rtp_packet.Timestamp() - rtp_start_timestamp_;
pbos@webrtc.org994d0b72014-06-27 08:47:52485 capture_time_list_.insert(
486 capture_time_list_.end(),
Danil Chapovalov1b4e4bf2019-12-06 11:34:57487 std::make_pair(rtp_packet.Timestamp(), capture_timestamp));
pbos@webrtc.org994d0b72014-06-27 08:47:52488 return SEND_PACKET;
489 }
490
kjellander@webrtc.org14665ff2015-03-04 12:58:35491 void OnFrameGeneratorCapturerCreated(
492 test::FrameGeneratorCapturer* frame_generator_capturer) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52493 capturer_ = frame_generator_capturer;
494 }
495
stefanff483612015-12-21 11:14:00496 void ModifyVideoConfigs(
497 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 13:21:20498 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
stefanff483612015-12-21 11:14:00499 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09500 (*receive_configs)[0].renderer = this;
pbos@webrtc.org994d0b72014-06-27 08:47:52501 // Enable the receiver side rtt calculation.
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09502 (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true;
pbos@webrtc.org994d0b72014-06-27 08:47:52503 }
504
kjellander@webrtc.org14665ff2015-03-04 12:58:35505 void PerformTest() override {
Åsa Persson59947d22021-08-26 10:04:27506 EXPECT_TRUE(Wait()) << "Timed out while waiting for estimated capture "
507 "NTP time to be within bounds.";
Artem Titov14b42c22022-09-26 11:21:14508 GetGlobalMetricsLogger()->LogMetric(
509 "capture_ntp_time", "real - estimated", time_offset_ms_list_,
510 Unit::kMilliseconds, ImprovementDirection::kNeitherIsBetter);
pbos@webrtc.org994d0b72014-06-27 08:47:52511 }
512
Markus Handell8fe932a2020-07-06 15:41:35513 Mutex mutex_;
Artem Titov75e36472018-10-08 10:28:56514 const BuiltInNetworkBehaviorConfig net_config_;
stefanf116bd02015-10-27 15:29:42515 Clock* const clock_;
Åsa Persson59947d22021-08-26 10:04:27516 const int threshold_ms_;
517 const int start_time_ms_;
518 const int run_time_ms_;
519 const int64_t creation_time_ms_;
pbos@webrtc.org994d0b72014-06-27 08:47:52520 test::FrameGeneratorCapturer* capturer_;
521 bool rtp_start_timestamp_set_;
522 uint32_t rtp_start_timestamp_;
523 typedef std::map<uint32_t, uint32_t> FrameCaptureTimeList;
Markus Handell8fe932a2020-07-06 15:41:35524 FrameCaptureTimeList capture_time_list_ RTC_GUARDED_BY(&mutex_);
Artem Titov14b42c22022-09-26 11:21:14525 SamplesStatsCounter time_offset_ms_list_;
stefane74eef12016-01-08 14:47:13526 } test(net_config, threshold_ms, start_time_ms, run_time_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52527
stefane74eef12016-01-08 14:47:13528 RunBaseTest(&test);
wu@webrtc.orgcd701192014-04-24 22:10:24529}
530
Alex Loikoaf228ee2018-11-22 10:53:18531// Flaky tests, disabled on Mac and Windows due to webrtc:8291.
532#if !(defined(WEBRTC_MAC) || defined(WEBRTC_WIN))
Jeremy Lecontec8850cb2020-09-10 18:46:33533TEST_F(CallPerfTest, Real_Estimated_CaptureNtpTimeWithNetworkDelay) {
Artem Titov75e36472018-10-08 10:28:56534 BuiltInNetworkBehaviorConfig net_config;
wu@webrtc.orgcd701192014-04-24 22:10:24535 net_config.queue_delay_ms = 100;
Åsa Persson59947d22021-08-26 10:04:27536 // TODO(wu): lower the threshold as the calculation/estimation becomes more
wu@webrtc.orgcd701192014-04-24 22:10:24537 // accurate.
wu@webrtc.org9aa7d8d2014-05-29 05:03:52538 const int kThresholdMs = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24539 const int kStartTimeMs = 10000;
540 const int kRunTimeMs = 20000;
541 TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs);
542}
543
Jeremy Lecontec8850cb2020-09-10 18:46:33544TEST_F(CallPerfTest, Real_Estimated_CaptureNtpTimeWithNetworkJitter) {
Artem Titov75e36472018-10-08 10:28:56545 BuiltInNetworkBehaviorConfig net_config;
wu@webrtc.org0224c202014-05-05 17:42:43546 net_config.queue_delay_ms = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24547 net_config.delay_standard_deviation_ms = 10;
Åsa Persson59947d22021-08-26 10:04:27548 // TODO(wu): lower the threshold as the calculation/estimation becomes more
wu@webrtc.orgcd701192014-04-24 22:10:24549 // accurate.
wu@webrtc.org0224c202014-05-05 17:42:43550 const int kThresholdMs = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24551 const int kStartTimeMs = 10000;
552 const int kRunTimeMs = 20000;
553 TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs);
554}
Alex Loiko5aea38c2017-09-27 11:10:28555#endif
kthelgasonfa5fdce2017-02-27 08:15:31556
perkj803d97f2016-11-01 18:45:46557TEST_F(CallPerfTest, ReceivesCpuOveruseAndUnderuse) {
sprangc5d62e22017-04-03 06:53:04558 // Minimal normal usage at the start, then 30s overuse to allow filter to
559 // settle, and then 80s underuse to allow plenty of time for rampup again.
560 test::ScopedFieldTrials fake_overuse_settings(
561 "WebRTC-ForceSimulatedOveruseIntervalMs/1-30000-80000/");
562
perkj803d97f2016-11-01 18:45:46563 class LoadObserver : public test::SendTest,
564 public test::FrameGeneratorCapturer::SinkWantsObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07565 public:
Markus Handellf4f22872022-08-16 11:02:45566 LoadObserver() : SendTest(kLongTimeout), test_phase_(TestPhase::kInit) {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07567
perkj803d97f2016-11-01 18:45:46568 void OnFrameGeneratorCapturerCreated(
569 test::FrameGeneratorCapturer* frame_generator_capturer) override {
570 frame_generator_capturer->SetSinkWantsObserver(this);
kthelgasonfa5fdce2017-02-27 08:15:31571 // Set a high initial resolution to be sure that we can scale down.
572 frame_generator_capturer->ChangeResolution(1920, 1080);
perkj803d97f2016-11-01 18:45:46573 }
574
575 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
576 // is called.
sprangc5d62e22017-04-03 06:53:04577 // TODO(sprang): Add integration test for maintain-framerate mode?
perkj803d97f2016-11-01 18:45:46578 void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
579 const rtc::VideoSinkWants& wants) override {
Henrik Boström1124ed12021-02-25 09:30:39580 // The sink wants can change either because an adaptation happened (i.e.
581 // the pixels or frame rate changed) or for other reasons, such as encoded
582 // resolutions being communicated (happens whenever we capture a new frame
583 // size). In this test, we only care about adaptations.
584 bool did_adapt =
585 last_wants_.max_pixel_count != wants.max_pixel_count ||
586 last_wants_.target_pixel_count != wants.target_pixel_count ||
587 last_wants_.max_framerate_fps != wants.max_framerate_fps;
588 last_wants_ = wants;
589 if (!did_adapt) {
590 return;
591 }
Åsa Persson8c1bf952018-09-13 08:42:19592 // At kStart expect CPU overuse. Then expect CPU underuse when the encoder
perkj803d97f2016-11-01 18:45:46593 // delay has been decreased.
sprangc5d62e22017-04-03 06:53:04594 switch (test_phase_) {
Åsa Persson8c1bf952018-09-13 08:42:19595 case TestPhase::kInit:
596 // Max framerate should be set initially.
597 if (wants.max_framerate_fps != std::numeric_limits<int>::max() &&
598 wants.max_pixel_count == std::numeric_limits<int>::max()) {
599 test_phase_ = TestPhase::kStart;
600 } else {
601 ADD_FAILURE() << "Got unexpected adaptation request, max res = "
602 << wants.max_pixel_count << ", target res = "
603 << wants.target_pixel_count.value_or(-1)
604 << ", max fps = " << wants.max_framerate_fps;
605 }
606 break;
sprangc5d62e22017-04-03 06:53:04607 case TestPhase::kStart:
608 if (wants.max_pixel_count < std::numeric_limits<int>::max()) {
mflodmancc3d4422017-08-03 15:27:51609 // On adapting down, VideoStreamEncoder::VideoSourceProxy will set
610 // only the max pixel count, leaving the target unset.
sprangc5d62e22017-04-03 06:53:04611 test_phase_ = TestPhase::kAdaptedDown;
612 } else {
613 ADD_FAILURE() << "Got unexpected adaptation request, max res = "
614 << wants.max_pixel_count << ", target res = "
615 << wants.target_pixel_count.value_or(-1)
616 << ", max fps = " << wants.max_framerate_fps;
617 }
618 break;
619 case TestPhase::kAdaptedDown:
620 // On adapting up, the adaptation counter will again be at zero, and
621 // so all constraints will be reset.
622 if (wants.max_pixel_count == std::numeric_limits<int>::max() &&
623 !wants.target_pixel_count) {
624 test_phase_ = TestPhase::kAdaptedUp;
625 observation_complete_.Set();
626 } else {
627 ADD_FAILURE() << "Got unexpected adaptation request, max res = "
628 << wants.max_pixel_count << ", target res = "
629 << wants.target_pixel_count.value_or(-1)
630 << ", max fps = " << wants.max_framerate_fps;
631 }
632 break;
633 case TestPhase::kAdaptedUp:
634 ADD_FAILURE() << "Got unexpected adaptation request, max res = "
635 << wants.max_pixel_count << ", target res = "
636 << wants.target_pixel_count.value_or(-1)
637 << ", max fps = " << wants.max_framerate_fps;
perkj803d97f2016-11-01 18:45:46638 }
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07639 }
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07640
stefanff483612015-12-21 11:14:00641 void ModifyVideoConfigs(
642 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 13:21:20643 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
Yves Gerey665174f2018-06-19 13:03:05644 VideoEncoderConfig* encoder_config) override {}
asapersson@webrtc.org049e4ec2014-11-20 10:19:46645
kjellander@webrtc.org14665ff2015-03-04 12:58:35646 void PerformTest() override {
Peter Boström5811a392015-12-10 12:02:50647 EXPECT_TRUE(Wait()) << "Timed out before receiving an overuse callback.";
pbos@webrtc.org994d0b72014-06-27 08:47:52648 }
asapersson@webrtc.org049e4ec2014-11-20 10:19:46649
Åsa Persson8c1bf952018-09-13 08:42:19650 enum class TestPhase {
651 kInit,
652 kStart,
653 kAdaptedDown,
654 kAdaptedUp
655 } test_phase_;
Henrik Boström1124ed12021-02-25 09:30:39656
657 private:
658 rtc::VideoSinkWants last_wants_;
perkj803d97f2016-11-01 18:45:46659 } test;
pbos@webrtc.org994d0b72014-06-27 08:47:52660
stefane74eef12016-01-08 14:47:13661 RunBaseTest(&test);
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07662}
pbos@webrtc.org3349ae02014-03-13 12:52:27663
664void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) {
665 static const int kMaxEncodeBitrateKbps = 30;
pbos@webrtc.org709e2972014-03-19 10:59:52666 static const int kMinTransmitBitrateBps = 150000;
pbos@webrtc.org3349ae02014-03-13 12:52:27667 static const int kMinAcceptableTransmitBitrate = 130;
668 static const int kMaxAcceptableTransmitBitrate = 170;
669 static const int kNumBitrateObservationsInRange = 100;
sprang867fb522015-08-03 11:38:41670 static const int kAcceptableBitrateErrorMargin = 15; // +- 7
stefanf116bd02015-10-27 15:29:42671 class BitrateObserver : public test::EndToEndTest {
pbos@webrtc.org3349ae02014-03-13 12:52:27672 public:
Tomas Gunnarsson788d8052021-05-03 14:23:08673 explicit BitrateObserver(bool using_min_transmit_bitrate,
674 TaskQueueBase* task_queue)
Markus Handellf4f22872022-08-16 11:02:45675 : EndToEndTest(kLongTimeout),
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24676 send_stream_(nullptr),
Danil Chapovalov371b43b2016-06-16 07:58:44677 converged_(false),
pbos@webrtc.org994d0b72014-06-27 08:47:52678 pad_to_min_bitrate_(using_min_transmit_bitrate),
Danil Chapovalov371b43b2016-06-16 07:58:44679 min_acceptable_bitrate_(using_min_transmit_bitrate
680 ? kMinAcceptableTransmitBitrate
681 : (kMaxEncodeBitrateKbps -
682 kAcceptableBitrateErrorMargin / 2)),
683 max_acceptable_bitrate_(using_min_transmit_bitrate
684 ? kMaxAcceptableTransmitBitrate
685 : (kMaxEncodeBitrateKbps +
686 kAcceptableBitrateErrorMargin / 2)),
Tomas Gunnarsson788d8052021-05-03 14:23:08687 num_bitrate_observations_in_range_(0),
Niels Möller05a9e5a2021-08-13 12:00:44688 task_queue_(task_queue),
689 task_safety_flag_(PendingTaskSafetyFlag::CreateDetached()) {}
pbos@webrtc.org3349ae02014-03-13 12:52:27690
pbos@webrtc.org994d0b72014-06-27 08:47:52691 private:
stefanf116bd02015-10-27 15:29:42692 // TODO(holmer): Run this with a timer instead of once per packet.
693 Action OnSendRtp(const uint8_t* packet, size_t length) override {
Danil Chapovalovb7128ed2022-07-06 16:35:01694 task_queue_->PostTask(SafeTask(task_safety_flag_, [this]() {
Tomas Gunnarsson788d8052021-05-03 14:23:08695 VideoSendStream::Stats stats = send_stream_->GetStats();
696
697 if (!stats.substreams.empty()) {
698 RTC_DCHECK_EQ(1, stats.substreams.size());
699 int bitrate_kbps =
700 stats.substreams.begin()->second.total_bitrate_bps / 1000;
701 if (bitrate_kbps > min_acceptable_bitrate_ &&
702 bitrate_kbps < max_acceptable_bitrate_) {
703 converged_ = true;
704 ++num_bitrate_observations_in_range_;
705 if (num_bitrate_observations_in_range_ ==
706 kNumBitrateObservationsInRange)
707 observation_complete_.Set();
708 }
709 if (converged_)
Artem Titov14b42c22022-09-26 11:21:14710 bitrate_kbps_list_.AddSample(bitrate_kbps);
pbos@webrtc.org3349ae02014-03-13 12:52:27711 }
Tomas Gunnarsson788d8052021-05-03 14:23:08712 }));
stefanf116bd02015-10-27 15:29:42713 return SEND_PACKET;
pbos@webrtc.org3349ae02014-03-13 12:52:27714 }
715
Tommif6f45432022-05-20 13:21:20716 void OnVideoStreamsCreated(VideoSendStream* send_stream,
717 const std::vector<VideoReceiveStreamInterface*>&
718 receive_streams) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52719 send_stream_ = send_stream;
720 }
721
Niels Möller05a9e5a2021-08-13 12:00:44722 void OnStreamsStopped() override { task_safety_flag_->SetNotAlive(); }
723
stefanff483612015-12-21 11:14:00724 void ModifyVideoConfigs(
725 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 13:21:20726 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
stefanff483612015-12-21 11:14:00727 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52728 if (pad_to_min_bitrate_) {
pbos@webrtc.orgad3b5a52014-10-24 09:23:21729 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps;
pbos@webrtc.org994d0b72014-06-27 08:47:52730 } else {
henrikg91d6ede2015-09-17 07:24:34731 RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps);
pbos@webrtc.org994d0b72014-06-27 08:47:52732 }
733 }
734
kjellander@webrtc.org14665ff2015-03-04 12:58:35735 void PerformTest() override {
Peter Boström5811a392015-12-10 12:02:50736 EXPECT_TRUE(Wait()) << "Timeout while waiting for send-bitrate stats.";
Artem Titov14b42c22022-09-26 11:21:14737 GetGlobalMetricsLogger()->LogMetric(
738 std::string("bitrate_stats_") +
739 (pad_to_min_bitrate_ ? "min_transmit_bitrate"
740 : "without_min_transmit_bitrate"),
Artem Titove82c2282022-09-28 13:18:33741 "bitrate_kbps", bitrate_kbps_list_, Unit::kUnitless,
Artem Titov14b42c22022-09-26 11:21:14742 ImprovementDirection::kNeitherIsBetter);
pbos@webrtc.org994d0b72014-06-27 08:47:52743 }
744
pbos@webrtc.org3349ae02014-03-13 12:52:27745 VideoSendStream* send_stream_;
Danil Chapovalov371b43b2016-06-16 07:58:44746 bool converged_;
pbos@webrtc.org994d0b72014-06-27 08:47:52747 const bool pad_to_min_bitrate_;
Danil Chapovalov371b43b2016-06-16 07:58:44748 const int min_acceptable_bitrate_;
749 const int max_acceptable_bitrate_;
pbos@webrtc.org3349ae02014-03-13 12:52:27750 int num_bitrate_observations_in_range_;
Artem Titov14b42c22022-09-26 11:21:14751 SamplesStatsCounter bitrate_kbps_list_;
Tomas Gunnarsson788d8052021-05-03 14:23:08752 TaskQueueBase* task_queue_;
Niels Möller05a9e5a2021-08-13 12:00:44753 rtc::scoped_refptr<PendingTaskSafetyFlag> task_safety_flag_;
Tomas Gunnarsson788d8052021-05-03 14:23:08754 } test(pad_to_min_bitrate, task_queue());
pbos@webrtc.org3349ae02014-03-13 12:52:27755
Niels Möller4db138e2018-04-19 07:04:13756 fake_encoder_max_bitrate_ = kMaxEncodeBitrateKbps;
stefane74eef12016-01-08 14:47:13757 RunBaseTest(&test);
pbos@webrtc.org3349ae02014-03-13 12:52:27758}
759
Jeremy Lecontec8850cb2020-09-10 18:46:33760TEST_F(CallPerfTest, Bitrate_Kbps_PadsToMinTransmitBitrate) {
Yves Gerey665174f2018-06-19 13:03:05761 TestMinTransmitBitrate(true);
762}
pbos@webrtc.org3349ae02014-03-13 12:52:27763
Jeremy Lecontec8850cb2020-09-10 18:46:33764TEST_F(CallPerfTest, Bitrate_Kbps_NoPadWithoutMinTransmitBitrate) {
pbos@webrtc.org3349ae02014-03-13 12:52:27765 TestMinTransmitBitrate(false);
766}
767
Taylor Brandstetter85904f42018-02-16 18:11:49768// TODO(bugs.webrtc.org/8878)
769#if defined(WEBRTC_MAC)
770#define MAYBE_KeepsHighBitrateWhenReconfiguringSender \
771 DISABLED_KeepsHighBitrateWhenReconfiguringSender
772#else
773#define MAYBE_KeepsHighBitrateWhenReconfiguringSender \
774 KeepsHighBitrateWhenReconfiguringSender
775#endif
776TEST_F(CallPerfTest, MAYBE_KeepsHighBitrateWhenReconfiguringSender) {
pbos@webrtc.org32452b22014-10-22 12:15:24777 static const uint32_t kInitialBitrateKbps = 400;
778 static const uint32_t kReconfigureThresholdKbps = 600;
pbos@webrtc.org32452b22014-10-22 12:15:24779
Jakob Ivarsson36274f92020-10-22 11:01:07780 // We get lower bitrate than expected by this test if the following field
781 // trial is enabled.
Jonas Oreland8ca06132022-03-14 11:52:48782 test::ScopedKeyValueConfig field_trials(
783 field_trials_, "WebRTC-SendSideBwe-WithOverhead/Disabled/");
Jakob Ivarsson36274f92020-10-22 11:01:07784
perkjfa10b552016-10-03 06:45:26785 class VideoStreamFactory
786 : public VideoEncoderConfig::VideoStreamFactoryInterface {
787 public:
788 VideoStreamFactory() {}
789
790 private:
791 std::vector<VideoStream> CreateEncoderStreams(
Jonas Oreland80c87d72022-09-29 13:01:09792 int frame_width,
793 int frame_height,
794 const webrtc::VideoEncoderConfig& encoder_config) override {
perkjfa10b552016-10-03 06:45:26795 std::vector<VideoStream> streams =
Jonas Oreland80c87d72022-09-29 13:01:09796 test::CreateVideoStreams(frame_width, frame_height, encoder_config);
perkjfa10b552016-10-03 06:45:26797 streams[0].min_bitrate_bps = 50000;
798 streams[0].target_bitrate_bps = streams[0].max_bitrate_bps = 2000000;
799 return streams;
800 }
801 };
802
pbos@webrtc.org32452b22014-10-22 12:15:24803 class BitrateObserver : public test::EndToEndTest, public test::FakeEncoder {
804 public:
Tomas Gunnarsson788d8052021-05-03 14:23:08805 explicit BitrateObserver(TaskQueueBase* task_queue)
Markus Handellf4f22872022-08-16 11:02:45806 : EndToEndTest(kDefaultTimeout),
pbos@webrtc.org32452b22014-10-22 12:15:24807 FakeEncoder(Clock::GetRealTimeClock()),
sprang867fb522015-08-03 11:38:41808 encoder_inits_(0),
Erik Språng08127a92016-11-16 15:41:30809 last_set_bitrate_kbps_(0),
810 send_stream_(nullptr),
Niels Möller4db138e2018-04-19 07:04:13811 frame_generator_(nullptr),
Jiawei Ouc2ebe212018-11-08 18:02:56812 encoder_factory_(this),
813 bitrate_allocator_factory_(
Tomas Gunnarsson788d8052021-05-03 14:23:08814 CreateBuiltinVideoBitrateAllocatorFactory()),
815 task_queue_(task_queue) {}
pbos@webrtc.org32452b22014-10-22 12:15:24816
kjellander@webrtc.org14665ff2015-03-04 12:58:35817 int32_t InitEncode(const VideoCodec* config,
Elad Alon370f93a2019-06-11 12:57:57818 const VideoEncoder::Settings& settings) override {
perkjfa10b552016-10-03 06:45:26819 ++encoder_inits_;
820 if (encoder_inits_ == 1) {
emircan05a55b52016-10-28 21:06:29821 // First time initialization. Frame size is known.
Artem Titovea240272021-07-26 10:40:21822 // `expected_bitrate` is affected by bandwidth estimation before the
Per21d45d22016-10-30 20:37:57823 // first frame arrives to the encoder.
Erik Språng08127a92016-11-16 15:41:30824 uint32_t expected_bitrate = last_set_bitrate_kbps_ > 0
825 ? last_set_bitrate_kbps_
826 : kInitialBitrateKbps;
Per21d45d22016-10-30 20:37:57827 EXPECT_EQ(expected_bitrate, config->startBitrate)
828 << "Encoder not initialized at expected bitrate.";
perkjfa10b552016-10-03 06:45:26829 EXPECT_EQ(kDefaultWidth, config->width);
830 EXPECT_EQ(kDefaultHeight, config->height);
Per21d45d22016-10-30 20:37:57831 } else if (encoder_inits_ == 2) {
perkjfa10b552016-10-03 06:45:26832 EXPECT_EQ(2 * kDefaultWidth, config->width);
833 EXPECT_EQ(2 * kDefaultHeight, config->height);
Erik Språng08127a92016-11-16 15:41:30834 EXPECT_GE(last_set_bitrate_kbps_, kReconfigureThresholdKbps);
philipel0676f222018-04-17 14:12:21835 EXPECT_GT(config->startBitrate, kReconfigureThresholdKbps)
pbos@webrtc.org32452b22014-10-22 12:15:24836 << "Encoder reconfigured with bitrate too far away from last set.";
Peter Boström5811a392015-12-10 12:02:50837 observation_complete_.Set();
pbos@webrtc.org32452b22014-10-22 12:15:24838 }
Elad Alon370f93a2019-06-11 12:57:57839 return FakeEncoder::InitEncode(config, settings);
pbos@webrtc.org32452b22014-10-22 12:15:24840 }
841
Erik Språng16cb8f52019-04-12 11:59:09842 void SetRates(const RateControlParameters& parameters) override {
843 last_set_bitrate_kbps_ = parameters.bitrate.get_sum_kbps();
Per21d45d22016-10-30 20:37:57844 if (encoder_inits_ == 1 &&
Erik Språng16cb8f52019-04-12 11:59:09845 parameters.bitrate.get_sum_kbps() > kReconfigureThresholdKbps) {
Peter Boström5811a392015-12-10 12:02:50846 time_to_reconfigure_.Set();
pbos@webrtc.org32452b22014-10-22 12:15:24847 }
Erik Språng16cb8f52019-04-12 11:59:09848 FakeEncoder::SetRates(parameters);
pbos@webrtc.org32452b22014-10-22 12:15:24849 }
850
Niels Möllerde8e6e62018-11-13 14:10:33851 void ModifySenderBitrateConfig(
852 BitrateConstraints* bitrate_config) override {
853 bitrate_config->start_bitrate_bps = kInitialBitrateKbps * 1000;
pbos@webrtc.org32452b22014-10-22 12:15:24854 }
855
stefanff483612015-12-21 11:14:00856 void ModifyVideoConfigs(
857 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 13:21:20858 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
stefanff483612015-12-21 11:14:00859 VideoEncoderConfig* encoder_config) override {
Niels Möller4db138e2018-04-19 07:04:13860 send_config->encoder_settings.encoder_factory = &encoder_factory_;
Jiawei Ouc2ebe212018-11-08 18:02:56861 send_config->encoder_settings.bitrate_allocator_factory =
862 bitrate_allocator_factory_.get();
Per21d45d22016-10-30 20:37:57863 encoder_config->max_bitrate_bps = 2 * kReconfigureThresholdKbps * 1000;
perkjfa10b552016-10-03 06:45:26864 encoder_config->video_stream_factory =
Tomas Gunnarssonc1d58912021-04-22 17:21:43865 rtc::make_ref_counted<VideoStreamFactory>();
pbos@webrtc.org32452b22014-10-22 12:15:24866
perkj26091b12016-09-01 08:17:40867 encoder_config_ = encoder_config->Copy();
pbos@webrtc.org32452b22014-10-22 12:15:24868 }
869
Tommif6f45432022-05-20 13:21:20870 void OnVideoStreamsCreated(VideoSendStream* send_stream,
871 const std::vector<VideoReceiveStreamInterface*>&
872 receive_streams) override {
pbos@webrtc.org32452b22014-10-22 12:15:24873 send_stream_ = send_stream;
874 }
875
perkjfa10b552016-10-03 06:45:26876 void OnFrameGeneratorCapturerCreated(
877 test::FrameGeneratorCapturer* frame_generator_capturer) override {
878 frame_generator_ = frame_generator_capturer;
879 }
880
kjellander@webrtc.org14665ff2015-03-04 12:58:35881 void PerformTest() override {
Markus Handell2cfc1af2022-08-19 08:16:48882 ASSERT_TRUE(time_to_reconfigure_.Wait(kDefaultTimeout))
pbos@webrtc.org32452b22014-10-22 12:15:24883 << "Timed out before receiving an initial high bitrate.";
perkjfa10b552016-10-03 06:45:26884 frame_generator_->ChangeResolution(kDefaultWidth * 2, kDefaultHeight * 2);
Danil Chapovalove519f382022-08-11 10:26:09885 SendTask(task_queue_, [&]() {
Tomas Gunnarsson788d8052021-05-03 14:23:08886 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy());
887 });
Peter Boström5811a392015-12-10 12:02:50888 EXPECT_TRUE(Wait())
pbos@webrtc.org32452b22014-10-22 12:15:24889 << "Timed out while waiting for a couple of high bitrate estimates "
890 "after reconfiguring the send stream.";
891 }
892
893 private:
Peter Boström5811a392015-12-10 12:02:50894 rtc::Event time_to_reconfigure_;
pbos@webrtc.org32452b22014-10-22 12:15:24895 int encoder_inits_;
Erik Språng08127a92016-11-16 15:41:30896 uint32_t last_set_bitrate_kbps_;
pbos@webrtc.org32452b22014-10-22 12:15:24897 VideoSendStream* send_stream_;
perkjfa10b552016-10-03 06:45:26898 test::FrameGeneratorCapturer* frame_generator_;
Niels Möllercbcbc222018-09-28 07:07:24899 test::VideoEncoderProxyFactory encoder_factory_;
Jiawei Ouc2ebe212018-11-08 18:02:56900 std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_;
pbos@webrtc.org32452b22014-10-22 12:15:24901 VideoEncoderConfig encoder_config_;
Tomas Gunnarsson788d8052021-05-03 14:23:08902 TaskQueueBase* task_queue_;
903 } test(task_queue());
pbos@webrtc.org32452b22014-10-22 12:15:24904
stefane74eef12016-01-08 14:47:13905 RunBaseTest(&test);
pbos@webrtc.org32452b22014-10-22 12:15:24906}
907
Alex Narestd0e196b2017-11-22 16:22:35908// Discovers the minimal supported audio+video bitrate. The test bitrate is
909// considered supported if Rtt does not go above 400ms with the network
910// contrained to the test bitrate.
911//
Alex Narestd0e196b2017-11-22 16:22:35912// |test_bitrate_from test_bitrate_to| bitrate constraint range
Artem Titovea240272021-07-26 10:40:21913// `test_bitrate_step` bitrate constraint update step during the test
Alex Narestd0e196b2017-11-22 16:22:35914// |min_bwe max_bwe| BWE range
Artem Titovea240272021-07-26 10:40:21915// `start_bwe` initial BWE
Jonas Olsson0182a032019-07-09 10:31:20916void CallPerfTest::TestMinAudioVideoBitrate(int test_bitrate_from,
917 int test_bitrate_to,
918 int test_bitrate_step,
919 int min_bwe,
920 int start_bwe,
921 int max_bwe) {
Alex Narestd0e196b2017-11-22 16:22:35922 static const std::string kAudioTrackId = "audio_track_0";
Alex Narestd0e196b2017-11-22 16:22:35923 static constexpr int kOpusBitrateFbBps = 32000;
924 static constexpr int kBitrateStabilizationMs = 10000;
925 static constexpr int kBitrateMeasurements = 10;
926 static constexpr int kBitrateMeasurementMs = 1000;
Ilya Nikolaevskiy0500b522019-01-22 10:12:51927 static constexpr int kShortDelayMs = 10;
Alex Narestd0e196b2017-11-22 16:22:35928 static constexpr int kMinGoodRttMs = 400;
929
930 class MinVideoAndAudioBitrateTester : public test::EndToEndTest {
931 public:
Danil Chapovalov85a10002019-10-21 13:00:53932 MinVideoAndAudioBitrateTester(int test_bitrate_from,
933 int test_bitrate_to,
934 int test_bitrate_step,
935 int min_bwe,
936 int start_bwe,
937 int max_bwe,
938 TaskQueueBase* task_queue)
Alex Narestd0e196b2017-11-22 16:22:35939 : EndToEndTest(),
Alex Narestd0e196b2017-11-22 16:22:35940 test_bitrate_from_(test_bitrate_from),
941 test_bitrate_to_(test_bitrate_to),
942 test_bitrate_step_(test_bitrate_step),
943 min_bwe_(min_bwe),
944 start_bwe_(start_bwe),
Tommic24a5b12019-08-05 13:23:45945 max_bwe_(max_bwe),
946 task_queue_(task_queue) {}
Alex Narestd0e196b2017-11-22 16:22:35947
948 protected:
Artem Titov75e36472018-10-08 10:28:56949 BuiltInNetworkBehaviorConfig GetFakeNetworkPipeConfig() {
950 BuiltInNetworkBehaviorConfig pipe_config;
Alex Narestd0e196b2017-11-22 16:22:35951 pipe_config.link_capacity_kbps = test_bitrate_from_;
952 return pipe_config;
953 }
954
Danil Chapovalov44db4362019-09-30 02:16:28955 std::unique_ptr<test::PacketTransport> CreateSendTransport(
956 TaskQueueBase* task_queue,
Alex Narestd0e196b2017-11-22 16:22:35957 Call* sender_call) override {
Artem Titov631cafa2018-08-21 19:01:00958 auto network =
Mirko Bonadei317a1f02019-09-17 15:06:18959 std::make_unique<SimulatedNetwork>(GetFakeNetworkPipeConfig());
Artem Titov631cafa2018-08-21 19:01:00960 send_simulated_network_ = network.get();
Danil Chapovalov44db4362019-09-30 02:16:28961 return std::make_unique<test::PacketTransport>(
Artem Titov631cafa2018-08-21 19:01:00962 task_queue, sender_call, this, test::PacketTransport::kSender,
963 test::CallTest::payload_type_map_,
Mirko Bonadei317a1f02019-09-17 15:06:18964 std::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(),
965 std::move(network)));
Alex Narestd0e196b2017-11-22 16:22:35966 }
967
Danil Chapovalov44db4362019-09-30 02:16:28968 std::unique_ptr<test::PacketTransport> CreateReceiveTransport(
969 TaskQueueBase* task_queue) override {
Artem Titov631cafa2018-08-21 19:01:00970 auto network =
Mirko Bonadei317a1f02019-09-17 15:06:18971 std::make_unique<SimulatedNetwork>(GetFakeNetworkPipeConfig());
Artem Titov631cafa2018-08-21 19:01:00972 receive_simulated_network_ = network.get();
Danil Chapovalov44db4362019-09-30 02:16:28973 return std::make_unique<test::PacketTransport>(
Artem Titov631cafa2018-08-21 19:01:00974 task_queue, nullptr, this, test::PacketTransport::kReceiver,
975 test::CallTest::payload_type_map_,
Mirko Bonadei317a1f02019-09-17 15:06:18976 std::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(),
977 std::move(network)));
Alex Narestd0e196b2017-11-22 16:22:35978 }
979
980 void PerformTest() override {
Ilya Nikolaevskiy0500b522019-01-22 10:12:51981 // Quick test mode, just to exercise all the code paths without actually
982 // caring about performance measurements.
983 const bool quick_perf_test =
984 field_trial::IsEnabled("WebRTC-QuickPerfTest");
Alex Narestd0e196b2017-11-22 16:22:35985 int last_passed_test_bitrate = -1;
986 for (int test_bitrate = test_bitrate_from_;
987 test_bitrate_from_ < test_bitrate_to_
988 ? test_bitrate <= test_bitrate_to_
989 : test_bitrate >= test_bitrate_to_;
990 test_bitrate += test_bitrate_step_) {
Artem Titov75e36472018-10-08 10:28:56991 BuiltInNetworkBehaviorConfig pipe_config;
Alex Narestd0e196b2017-11-22 16:22:35992 pipe_config.link_capacity_kbps = test_bitrate;
Artem Titov631cafa2018-08-21 19:01:00993 send_simulated_network_->SetConfig(pipe_config);
994 receive_simulated_network_->SetConfig(pipe_config);
Alex Narestd0e196b2017-11-22 16:22:35995
Tommic24a5b12019-08-05 13:23:45996 rtc::Thread::SleepMs(quick_perf_test ? kShortDelayMs
997 : kBitrateStabilizationMs);
Alex Narestd0e196b2017-11-22 16:22:35998
999 int64_t avg_rtt = 0;
1000 for (int i = 0; i < kBitrateMeasurements; i++) {
Tommic24a5b12019-08-05 13:23:451001 Call::Stats call_stats;
Danil Chapovalove519f382022-08-11 10:26:091002 SendTask(task_queue_, [this, &call_stats]() {
Danil Chapovalov82a3f0a2019-10-21 07:24:271003 call_stats = sender_call_->GetStats();
1004 });
Alex Narestd0e196b2017-11-22 16:22:351005 avg_rtt += call_stats.rtt_ms;
Tommic24a5b12019-08-05 13:23:451006 rtc::Thread::SleepMs(quick_perf_test ? kShortDelayMs
1007 : kBitrateMeasurementMs);
Alex Narestd0e196b2017-11-22 16:22:351008 }
1009 avg_rtt = avg_rtt / kBitrateMeasurements;
1010 if (avg_rtt > kMinGoodRttMs) {
1011 break;
1012 } else {
1013 last_passed_test_bitrate = test_bitrate;
1014 }
1015 }
1016 EXPECT_GT(last_passed_test_bitrate, -1)
1017 << "Minimum supported bitrate out of the test scope";
Artem Titov14b42c22022-09-26 11:21:141018 GetGlobalMetricsLogger()->LogSingleValueMetric(
1019 "min_test_bitrate_", "min_bitrate", last_passed_test_bitrate,
Artem Titove82c2282022-09-28 13:18:331020 Unit::kUnitless, ImprovementDirection::kNeitherIsBetter);
Alex Narestd0e196b2017-11-22 16:22:351021 }
1022
1023 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
1024 sender_call_ = sender_call;
Sebastian Janssonfc8d26b2018-02-21 08:52:061025 BitrateConstraints bitrate_config;
Alex Narestd0e196b2017-11-22 16:22:351026 bitrate_config.min_bitrate_bps = min_bwe_;
1027 bitrate_config.start_bitrate_bps = start_bwe_;
1028 bitrate_config.max_bitrate_bps = max_bwe_;
Sebastian Jansson8f83b422018-02-21 12:07:131029 sender_call->GetTransportControllerSend()->SetSdpBitrateParameters(
1030 bitrate_config);
Alex Narestd0e196b2017-11-22 16:22:351031 }
1032
1033 size_t GetNumVideoStreams() const override { return 1; }
1034
1035 size_t GetNumAudioStreams() const override { return 1; }
1036
Tommi3176ef72022-05-22 18:47:281037 void ModifyAudioConfigs(AudioSendStream::Config* send_config,
1038 std::vector<AudioReceiveStreamInterface::Config>*
1039 receive_configs) override {
Jonas Olsson0182a032019-07-09 10:31:201040 send_config->send_codec_spec->target_bitrate_bps =
1041 absl::optional<int>(kOpusBitrateFbBps);
Alex Narestd0e196b2017-11-22 16:22:351042 }
1043
1044 private:
Alex Narestd0e196b2017-11-22 16:22:351045 const int test_bitrate_from_;
1046 const int test_bitrate_to_;
1047 const int test_bitrate_step_;
1048 const int min_bwe_;
1049 const int start_bwe_;
1050 const int max_bwe_;
Artem Titov631cafa2018-08-21 19:01:001051 SimulatedNetwork* send_simulated_network_;
1052 SimulatedNetwork* receive_simulated_network_;
Alex Narestd0e196b2017-11-22 16:22:351053 Call* sender_call_;
Danil Chapovalov85a10002019-10-21 13:00:531054 TaskQueueBase* const task_queue_;
Jonas Olsson0182a032019-07-09 10:31:201055 } test(test_bitrate_from, test_bitrate_to, test_bitrate_step, min_bwe,
Danil Chapovalovd15a0282019-10-22 08:48:171056 start_bwe, max_bwe, task_queue());
Alex Narestd0e196b2017-11-22 16:22:351057
1058 RunBaseTest(&test);
1059}
1060
Taylor Brandstetter85904f42018-02-16 18:11:491061// TODO(bugs.webrtc.org/8878)
1062#if defined(WEBRTC_MAC)
Jeremy Lecontec8850cb2020-09-10 18:46:331063#define MAYBE_Min_Bitrate_VideoAndAudio DISABLED_Min_Bitrate_VideoAndAudio
Taylor Brandstetter85904f42018-02-16 18:11:491064#else
Jeremy Lecontec8850cb2020-09-10 18:46:331065#define MAYBE_Min_Bitrate_VideoAndAudio Min_Bitrate_VideoAndAudio
Taylor Brandstetter85904f42018-02-16 18:11:491066#endif
Jeremy Lecontec8850cb2020-09-10 18:46:331067TEST_F(CallPerfTest, MAYBE_Min_Bitrate_VideoAndAudio) {
Jonas Olsson0182a032019-07-09 10:31:201068 TestMinAudioVideoBitrate(110, 40, -10, 10000, 70000, 200000);
Alex Narestd0e196b2017-11-22 16:22:351069}
1070
Åsa Persson59947d22021-08-26 10:04:271071void CallPerfTest::TestEncodeFramerate(VideoEncoderFactory* encoder_factory,
Ali Tofigh641a1b12022-05-17 09:48:461072 absl::string_view payload_name,
Åsa Persson59947d22021-08-26 10:04:271073 const std::vector<int>& max_framerates) {
1074 static constexpr double kAllowedFpsDiff = 1.5;
1075 static constexpr TimeDelta kMinGetStatsInterval = TimeDelta::Millis(400);
1076 static constexpr TimeDelta kMinRunTime = TimeDelta::Seconds(15);
1077 static constexpr DataRate kMaxBitrate = DataRate::KilobitsPerSec(1000);
1078
1079 class FramerateObserver
1080 : public test::EndToEndTest,
1081 public test::FrameGeneratorCapturer::SinkWantsObserver {
1082 public:
1083 FramerateObserver(VideoEncoderFactory* encoder_factory,
Ali Tofigh641a1b12022-05-17 09:48:461084 absl::string_view payload_name,
Åsa Persson59947d22021-08-26 10:04:271085 const std::vector<int>& max_framerates,
1086 TaskQueueBase* task_queue)
Markus Handellf4f22872022-08-16 11:02:451087 : EndToEndTest(kDefaultTimeout),
Åsa Persson59947d22021-08-26 10:04:271088 clock_(Clock::GetRealTimeClock()),
1089 encoder_factory_(encoder_factory),
1090 payload_name_(payload_name),
1091 max_framerates_(max_framerates),
1092 task_queue_(task_queue),
1093 start_time_(clock_->CurrentTime()),
1094 last_getstats_time_(start_time_),
1095 send_stream_(nullptr) {}
1096
1097 void OnFrameGeneratorCapturerCreated(
1098 test::FrameGeneratorCapturer* frame_generator_capturer) override {
1099 frame_generator_capturer->ChangeResolution(640, 360);
1100 }
1101
1102 void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
1103 const rtc::VideoSinkWants& wants) override {}
1104
1105 void ModifySenderBitrateConfig(
1106 BitrateConstraints* bitrate_config) override {
1107 bitrate_config->start_bitrate_bps = kMaxBitrate.bps() / 2;
1108 }
1109
Tommif6f45432022-05-20 13:21:201110 void OnVideoStreamsCreated(VideoSendStream* send_stream,
1111 const std::vector<VideoReceiveStreamInterface*>&
1112 receive_streams) override {
Åsa Persson59947d22021-08-26 10:04:271113 send_stream_ = send_stream;
1114 }
1115
1116 size_t GetNumVideoStreams() const override {
1117 return max_framerates_.size();
1118 }
1119
1120 void ModifyVideoConfigs(
1121 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 13:21:201122 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
Åsa Persson59947d22021-08-26 10:04:271123 VideoEncoderConfig* encoder_config) override {
1124 send_config->encoder_settings.encoder_factory = encoder_factory_;
1125 send_config->rtp.payload_name = payload_name_;
1126 send_config->rtp.payload_type = test::CallTest::kVideoSendPayloadType;
1127 encoder_config->video_format.name = payload_name_;
1128 encoder_config->codec_type = PayloadStringToCodecType(payload_name_);
1129 encoder_config->max_bitrate_bps = kMaxBitrate.bps();
1130 for (size_t i = 0; i < max_framerates_.size(); ++i) {
1131 encoder_config->simulcast_layers[i].max_framerate = max_framerates_[i];
1132 configured_framerates_[send_config->rtp.ssrcs[i]] = max_framerates_[i];
1133 }
1134 }
1135
1136 void PerformTest() override {
1137 EXPECT_TRUE(Wait()) << "Timeout while waiting for framerate stats.";
1138 }
1139
1140 void VerifyStats() const {
Åsa Persson42812082021-08-31 07:53:461141 double input_fps = 0.0;
1142 for (const auto& configured_framerate : configured_framerates_) {
1143 input_fps = std::max(configured_framerate.second, input_fps);
1144 }
Åsa Persson59947d22021-08-26 10:04:271145 for (const auto& encode_frame_rate_list : encode_frame_rate_lists_) {
Artem Titov14b42c22022-09-26 11:21:141146 const SamplesStatsCounter& values = encode_frame_rate_list.second;
1147 GetGlobalMetricsLogger()->LogMetric(
1148 "substream_fps", "encode_frame_rate", values, Unit::kUnitless,
1149 ImprovementDirection::kNeitherIsBetter);
1150 if (values.IsEmpty()) {
1151 continue;
1152 }
1153 double average_fps = values.GetAverage();
Åsa Persson59947d22021-08-26 10:04:271154 uint32_t ssrc = encode_frame_rate_list.first;
1155 double expected_fps = configured_framerates_.find(ssrc)->second;
Åsa Persson42812082021-08-31 07:53:461156 if (expected_fps != input_fps)
1157 EXPECT_NEAR(expected_fps, average_fps, kAllowedFpsDiff);
Åsa Persson59947d22021-08-26 10:04:271158 }
1159 }
1160
1161 Action OnSendRtp(const uint8_t* packet, size_t length) override {
1162 const Timestamp now = clock_->CurrentTime();
1163 if (now - last_getstats_time_ > kMinGetStatsInterval) {
1164 last_getstats_time_ = now;
Danil Chapovalovb7128ed2022-07-06 16:35:011165 task_queue_->PostTask([this, now]() {
Åsa Persson59947d22021-08-26 10:04:271166 VideoSendStream::Stats stats = send_stream_->GetStats();
1167 for (const auto& stat : stats.substreams) {
Artem Titov14b42c22022-09-26 11:21:141168 encode_frame_rate_lists_[stat.first].AddSample(
Åsa Persson59947d22021-08-26 10:04:271169 stat.second.encode_frame_rate);
1170 }
1171 if (now - start_time_ > kMinRunTime) {
1172 VerifyStats();
1173 observation_complete_.Set();
1174 }
Danil Chapovalovb7128ed2022-07-06 16:35:011175 });
Åsa Persson59947d22021-08-26 10:04:271176 }
1177 return SEND_PACKET;
1178 }
1179
1180 Clock* const clock_;
1181 VideoEncoderFactory* const encoder_factory_;
1182 const std::string payload_name_;
1183 const std::vector<int> max_framerates_;
1184 TaskQueueBase* const task_queue_;
1185 const Timestamp start_time_;
1186 Timestamp last_getstats_time_;
1187 VideoSendStream* send_stream_;
Artem Titov14b42c22022-09-26 11:21:141188 std::map<uint32_t, SamplesStatsCounter> encode_frame_rate_lists_;
Åsa Persson59947d22021-08-26 10:04:271189 std::map<uint32_t, double> configured_framerates_;
1190 } test(encoder_factory, payload_name, max_framerates, task_queue());
1191
1192 RunBaseTest(&test);
1193}
1194
1195TEST_F(CallPerfTest, TestEncodeFramerateVp8Simulcast) {
1196 InternalEncoderFactory internal_encoder_factory;
1197 test::FunctionVideoEncoderFactory encoder_factory(
1198 [&internal_encoder_factory]() {
1199 return std::make_unique<SimulcastEncoderAdapter>(
1200 &internal_encoder_factory, SdpVideoFormat("VP8"));
1201 });
1202
1203 TestEncodeFramerate(&encoder_factory, "VP8",
1204 /*max_framerates=*/{20, 30});
1205}
1206
Åsa Perssond3bf4d42021-09-02 11:19:051207TEST_F(CallPerfTest, TestEncodeFramerateVp8SimulcastLowerInputFps) {
1208 InternalEncoderFactory internal_encoder_factory;
1209 test::FunctionVideoEncoderFactory encoder_factory(
1210 [&internal_encoder_factory]() {
1211 return std::make_unique<SimulcastEncoderAdapter>(
1212 &internal_encoder_factory, SdpVideoFormat("VP8"));
1213 });
1214
1215 TestEncodeFramerate(&encoder_factory, "VP8",
1216 /*max_framerates=*/{14, 20});
1217}
1218
pbos@webrtc.org1d096902013-12-13 12:48:051219} // namespace webrtc