blob: 4e9217fa58c44ef122a15f5cc8b910877bfad150 [file] [log] [blame]
stefan@webrtc.org3d7da882014-07-08 13:59:46 +00001/*
2 * Copyright (c) 2014 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 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef CALL_RAMPUP_TESTS_H_
12#define CALL_RAMPUP_TESTS_H_
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000013
14#include <map>
Danil Chapovalov44db4362019-09-30 04:16:28 +020015#include <memory>
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000016#include <string>
Artem Titov631cafa2018-08-21 21:01:00 +020017#include <utility>
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000018#include <vector>
19
Ali Tofigh641a1b12022-05-17 11:48:46 +020020#include "absl/strings/string_view.h"
Danil Chapovalov83bbe912019-08-07 12:24:53 +020021#include "api/rtc_event_log/rtc_event_log.h"
Danil Chapovalov44db4362019-09-30 04:16:28 +020022#include "api/task_queue/task_queue_base.h"
Artem Titov46c4e602018-08-17 14:26:54 +020023#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "call/call.h"
Artem Titov631cafa2018-08-21 21:01:00 +020025#include "call/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/event.h"
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +020027#include "rtc_base/task_utils/repeating_task.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "test/call_test.h"
Stefan Holmer6d113ea2022-01-05 17:03:49 +010029#include "test/testsupport/perf_test.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000030
31namespace webrtc {
32
33static const int kTransmissionTimeOffsetExtensionId = 6;
34static const int kAbsSendTimeExtensionId = 7;
Erik Språng6b8d3552015-09-24 15:06:57 +020035static const int kTransportSequenceNumberExtensionId = 8;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000036static const unsigned int kSingleStreamTargetBps = 1000000;
37
38class Clock;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000039
stefan4fbd1452015-09-28 03:57:14 -070040class RampUpTester : public test::EndToEndTest {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000041 public:
stefanff483612015-12-21 03:14:00 -080042 RampUpTester(size_t num_video_streams,
43 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080044 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070045 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080046 int64_t min_run_time_ms,
Ali Tofigh641a1b12022-05-17 11:48:46 +020047 absl::string_view extension_type,
stefan4fbd1452015-09-28 03:57:14 -070048 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080049 bool red,
Tommi5e005f42019-08-05 15:29:14 +020050 bool report_perf_stats,
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +020051 TaskQueueBase* task_queue);
stefan4fbd1452015-09-28 03:57:14 -070052 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000053
Stefan Holmerd20e6512016-01-12 15:51:22 +010054 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010055 size_t GetNumAudioStreams() const override;
philipel5ef2bc12017-02-21 07:28:31 -080056 size_t GetNumFlexfecStreams() const override;
Stefan Holmerd20e6512016-01-12 15:51:22 +010057
stefan4fbd1452015-09-28 03:57:14 -070058 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000059
stefan4fbd1452015-09-28 03:57:14 -070060 protected:
tommi0f8b4032017-02-22 11:22:05 -080061 virtual void PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000062
stefan092508a2015-09-29 02:26:42 -070063 void AccumulateStats(const VideoSendStream::StreamStats& stream,
64 size_t* total_packets_sent,
65 size_t* total_sent,
66 size_t* padding_sent,
67 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000068
Ali Tofigh641a1b12022-05-17 11:48:46 +020069 void ReportResult(absl::string_view measurement,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000070 size_t value,
Ali Tofigh641a1b12022-05-17 11:48:46 +020071 absl::string_view units,
Stefan Holmer6d113ea2022-01-05 17:03:49 +010072 test::ImproveDirection improve_direction) const;
stefan4fbd1452015-09-28 03:57:14 -070073 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000074
75 Clock* const clock_;
Artem Titov75e36472018-10-08 12:28:56 +020076 BuiltInNetworkBehaviorConfig forward_transport_config_;
stefanff483612015-12-21 03:14:00 -080077 const size_t num_video_streams_;
78 const size_t num_audio_streams_;
philipel5ef2bc12017-02-21 07:28:31 -080079 const size_t num_flexfec_streams_;
stefan4fbd1452015-09-28 03:57:14 -070080 const bool rtx_;
81 const bool red_;
stefan45b5fe52017-03-09 06:27:02 -080082 const bool report_perf_stats_;
mflodman86cc6ff2016-07-26 04:44:06 -070083 Call* sender_call_;
stefan4fbd1452015-09-28 03:57:14 -070084 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 08:29:42 -070085 test::PacketTransport* send_transport_;
Artem Titov631cafa2018-08-21 21:01:00 +020086 SimulatedNetwork* send_simulated_network_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000087
88 private:
stefan4fbd1452015-09-28 03:57:14 -070089 typedef std::map<uint32_t, uint32_t> SsrcMap;
perkjfa10b552016-10-02 23:45:26 -070090 class VideoStreamFactory;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000091
Niels Möllerde8e6e62018-11-13 15:10:33 +010092 void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override;
Tommif6f45432022-05-20 15:21:20 +020093 void OnVideoStreamsCreated(VideoSendStream* send_stream,
94 const std::vector<VideoReceiveStreamInterface*>&
95 receive_streams) override;
Danil Chapovalov44db4362019-09-30 04:16:28 +020096 std::unique_ptr<test::PacketTransport> CreateSendTransport(
97 TaskQueueBase* task_queue,
eladalon413ee9a2017-08-22 04:02:52 -070098 Call* sender_call) override;
stefanff483612015-12-21 03:14:00 -080099 void ModifyVideoConfigs(
100 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 15:21:20 +0200101 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
stefanff483612015-12-21 03:14:00 -0800102 VideoEncoderConfig* encoder_config) override;
Tommi3176ef72022-05-22 20:47:28 +0200103 void ModifyAudioConfigs(AudioSendStream::Config* send_config,
104 std::vector<AudioReceiveStreamInterface::Config>*
105 receive_configs) override;
philipel5ef2bc12017-02-21 07:28:31 -0800106 void ModifyFlexfecConfigs(
107 std::vector<FlexfecReceiveStream::Config>* receive_configs) override;
stefan4fbd1452015-09-28 03:57:14 -0700108 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000109
stefan4fbd1452015-09-28 03:57:14 -0700110 const int start_bitrate_bps_;
stefan5a2c5062017-01-27 06:43:18 -0800111 const int64_t min_run_time_ms_;
stefan4fbd1452015-09-28 03:57:14 -0700112 int expected_bitrate_bps_;
113 int64_t test_start_ms_;
114 int64_t ramp_up_finished_ms_;
115
116 const std::string extension_type_;
stefanff483612015-12-21 03:14:00 -0800117 std::vector<uint32_t> video_ssrcs_;
118 std::vector<uint32_t> video_rtx_ssrcs_;
119 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700120
Tommi5e005f42019-08-05 15:29:14 +0200121 protected:
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +0200122 TaskQueueBase* const task_queue_;
123 RepeatingTaskHandle pending_task_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000124};
125
stefan4fbd1452015-09-28 03:57:14 -0700126class RampUpDownUpTester : public RampUpTester {
127 public:
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +0200128 RampUpDownUpTester(size_t num_video_streams,
129 size_t num_audio_streams,
130 size_t num_flexfec_streams,
131 unsigned int start_bitrate_bps,
Ali Tofigh641a1b12022-05-17 11:48:46 +0200132 absl::string_view extension_type,
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +0200133 bool rtx,
134 bool red,
135 const std::vector<int>& loss_rates,
136 bool report_perf_stats,
137 TaskQueueBase* task_queue);
stefan4fbd1452015-09-28 03:57:14 -0700138 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000139
stefan4fbd1452015-09-28 03:57:14 -0700140 protected:
tommi0f8b4032017-02-22 11:22:05 -0800141 void PollStats() override;
stefan4fbd1452015-09-28 03:57:14 -0700142
143 private:
philipel5ef2bc12017-02-21 07:28:31 -0800144 enum TestStates {
145 kFirstRampup = 0,
146 kLowRate,
147 kSecondRampup,
148 kTestEnd,
149 kTransitionToNextState,
150 };
stefan4fbd1452015-09-28 03:57:14 -0700151
Niels Möllerde8e6e62018-11-13 15:10:33 +0100152 void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
stefan4fbd1452015-09-28 03:57:14 -0700153
154 std::string GetModifierString() const;
stefandb752f92016-12-05 08:23:40 -0800155 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 04:19:24 -0800156 int GetHighLinkCapacity() const;
philipel5ef2bc12017-02-21 07:28:31 -0800157 size_t GetFecBytes() const;
158 bool ExpectingFec() const;
stefan4fbd1452015-09-28 03:57:14 -0700159 void EvolveTestState(int bitrate_bps, bool suspended);
160
philipel5ef2bc12017-02-21 07:28:31 -0800161 const std::vector<int> link_rates_;
stefan4fbd1452015-09-28 03:57:14 -0700162 TestStates test_state_;
philipel5ef2bc12017-02-21 07:28:31 -0800163 TestStates next_state_;
stefan4fbd1452015-09-28 03:57:14 -0700164 int64_t state_start_ms_;
165 int64_t interval_start_ms_;
166 int sent_bytes_;
philipel5ef2bc12017-02-21 07:28:31 -0800167 std::vector<int> loss_rates_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000168};
169} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200170#endif // CALL_RAMPUP_TESTS_H_