blob: 259aa7995430426d6474aaf5b7cab028b9d49e01 [file] [log] [blame]
stefan@webrtc.org3d7da882014-07-08 13:59:461/*
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 04:47:3111#ifndef CALL_RAMPUP_TESTS_H_
12#define CALL_RAMPUP_TESTS_H_
stefan@webrtc.org3d7da882014-07-08 13:59:4613
Harald Alvestrand93c9aa12024-09-02 20:55:5214#include <cstddef>
15#include <cstdint>
stefan@webrtc.org3d7da882014-07-08 13:59:4616#include <map>
17#include <string>
18#include <vector>
19
Ali Tofigh641a1b12022-05-17 09:48:4620#include "absl/strings/string_view.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/metric.h"
Artem Titov46c4e602018-08-17 12:26:5423#include "api/test/simulated_network.h"
Harald Alvestrand93c9aa12024-09-02 20:55:5224#include "api/transport/bitrate_settings.h"
25#include "call/audio_receive_stream.h"
26#include "call/audio_send_stream.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3127#include "call/call.h"
Harald Alvestrand93c9aa12024-09-02 20:55:5228#include "call/flexfec_receive_stream.h"
29#include "call/video_receive_stream.h"
30#include "call/video_send_stream.h"
Danil Chapovalov9f5ae7b2019-10-21 09:08:1331#include "rtc_base/task_utils/repeating_task.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3132#include "test/call_test.h"
Harald Alvestrand93c9aa12024-09-02 20:55:5233#include "test/rtp_rtcp_observer.h"
34#include "video/config/video_encoder_config.h"
stefan@webrtc.org3d7da882014-07-08 13:59:4635
36namespace webrtc {
37
38static const int kTransmissionTimeOffsetExtensionId = 6;
39static const int kAbsSendTimeExtensionId = 7;
Erik Språng6b8d3552015-09-24 13:06:5740static const int kTransportSequenceNumberExtensionId = 8;
stefan@webrtc.org3d7da882014-07-08 13:59:4641static const unsigned int kSingleStreamTargetBps = 1000000;
42
43class Clock;
stefan@webrtc.org3d7da882014-07-08 13:59:4644
stefan4fbd1452015-09-28 10:57:1445class RampUpTester : public test::EndToEndTest {
stefan@webrtc.org3d7da882014-07-08 13:59:4646 public:
stefanff483612015-12-21 11:14:0047 RampUpTester(size_t num_video_streams,
48 size_t num_audio_streams,
philipel5ef2bc12017-02-21 15:28:3149 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 10:57:1450 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 14:43:1851 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 10:57:1452 bool rtx,
stefan5a2c5062017-01-27 14:43:1853 bool red,
Tommi5e005f42019-08-05 13:29:1454 bool report_perf_stats,
Danil Chapovalov9f5ae7b2019-10-21 09:08:1355 TaskQueueBase* task_queue);
stefan4fbd1452015-09-28 10:57:1456 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:4657
Stefan Holmerd20e6512016-01-12 14:51:2258 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 09:00:2159 size_t GetNumAudioStreams() const override;
philipel5ef2bc12017-02-21 15:28:3160 size_t GetNumFlexfecStreams() const override;
Stefan Holmerd20e6512016-01-12 14:51:2261
stefan4fbd1452015-09-28 10:57:1462 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:4663
stefan4fbd1452015-09-28 10:57:1464 protected:
tommi0f8b4032017-02-22 19:22:0565 virtual void PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:4666
stefan092508a2015-09-29 09:26:4267 void AccumulateStats(const VideoSendStream::StreamStats& stream,
68 size_t* total_packets_sent,
69 size_t* total_sent,
70 size_t* padding_sent,
71 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:4672
Ali Tofigh641a1b12022-05-17 09:48:4673 void ReportResult(absl::string_view measurement,
stefan@webrtc.org3d7da882014-07-08 13:59:4674 size_t value,
Artem Titov14b42c22022-09-26 11:21:1475 test::Unit unit,
76 test::ImprovementDirection improvement_direction) const;
stefan4fbd1452015-09-28 10:57:1477 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:4678
79 Clock* const clock_;
Artem Titov75e36472018-10-08 10:28:5680 BuiltInNetworkBehaviorConfig forward_transport_config_;
stefanff483612015-12-21 11:14:0081 const size_t num_video_streams_;
82 const size_t num_audio_streams_;
philipel5ef2bc12017-02-21 15:28:3183 const size_t num_flexfec_streams_;
stefan4fbd1452015-09-28 10:57:1484 const bool rtx_;
85 const bool red_;
stefan45b5fe52017-03-09 14:27:0286 const bool report_perf_stats_;
mflodman86cc6ff2016-07-26 11:44:0687 Call* sender_call_;
stefan4fbd1452015-09-28 10:57:1488 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 15:29:4289 test::PacketTransport* send_transport_;
Per Kjellander89870ff2023-01-19 15:45:5890 SimulatedNetworkInterface* send_simulated_network_;
stefan@webrtc.org3d7da882014-07-08 13:59:4691
92 private:
stefan4fbd1452015-09-28 10:57:1493 typedef std::map<uint32_t, uint32_t> SsrcMap;
perkjfa10b552016-10-03 06:45:2694 class VideoStreamFactory;
stefan@webrtc.org3d7da882014-07-08 13:59:4695
Niels Möllerde8e6e62018-11-13 14:10:3396 void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override;
Tommif6f45432022-05-20 13:21:2097 void OnVideoStreamsCreated(VideoSendStream* send_stream,
98 const std::vector<VideoReceiveStreamInterface*>&
99 receive_streams) override;
Per Kjellander89870ff2023-01-19 15:45:58100 BuiltInNetworkBehaviorConfig GetSendTransportConfig() const override;
stefanff483612015-12-21 11:14:00101 void ModifyVideoConfigs(
102 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 13:21:20103 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
stefanff483612015-12-21 11:14:00104 VideoEncoderConfig* encoder_config) override;
Tommi3176ef72022-05-22 18:47:28105 void ModifyAudioConfigs(AudioSendStream::Config* send_config,
106 std::vector<AudioReceiveStreamInterface::Config>*
107 receive_configs) override;
philipel5ef2bc12017-02-21 15:28:31108 void ModifyFlexfecConfigs(
109 std::vector<FlexfecReceiveStream::Config>* receive_configs) override;
stefan4fbd1452015-09-28 10:57:14110 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
Per Kjellander89870ff2023-01-19 15:45:58111 void OnTransportCreated(test::PacketTransport* to_receiver,
112 SimulatedNetworkInterface* sender_network,
113 test::PacketTransport* to_sender,
114 SimulatedNetworkInterface* receiver_network) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46115
stefan4fbd1452015-09-28 10:57:14116 const int start_bitrate_bps_;
stefan5a2c5062017-01-27 14:43:18117 const int64_t min_run_time_ms_;
stefan4fbd1452015-09-28 10:57:14118 int expected_bitrate_bps_;
119 int64_t test_start_ms_;
120 int64_t ramp_up_finished_ms_;
121
stefanff483612015-12-21 11:14:00122 std::vector<uint32_t> video_ssrcs_;
123 std::vector<uint32_t> video_rtx_ssrcs_;
124 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 10:57:14125
Tommi5e005f42019-08-05 13:29:14126 protected:
Danil Chapovalov9f5ae7b2019-10-21 09:08:13127 TaskQueueBase* const task_queue_;
128 RepeatingTaskHandle pending_task_;
stefan@webrtc.org3d7da882014-07-08 13:59:46129};
130
stefan4fbd1452015-09-28 10:57:14131class RampUpDownUpTester : public RampUpTester {
132 public:
Danil Chapovalov9f5ae7b2019-10-21 09:08:13133 RampUpDownUpTester(size_t num_video_streams,
134 size_t num_audio_streams,
135 size_t num_flexfec_streams,
136 unsigned int start_bitrate_bps,
Danil Chapovalov9f5ae7b2019-10-21 09:08:13137 bool rtx,
138 bool red,
139 const std::vector<int>& loss_rates,
140 bool report_perf_stats,
141 TaskQueueBase* task_queue);
stefan4fbd1452015-09-28 10:57:14142 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46143
stefan4fbd1452015-09-28 10:57:14144 protected:
tommi0f8b4032017-02-22 19:22:05145 void PollStats() override;
stefan4fbd1452015-09-28 10:57:14146
147 private:
philipel5ef2bc12017-02-21 15:28:31148 enum TestStates {
149 kFirstRampup = 0,
150 kLowRate,
151 kSecondRampup,
152 kTestEnd,
153 kTransitionToNextState,
154 };
stefan4fbd1452015-09-28 10:57:14155
Niels Möllerde8e6e62018-11-13 14:10:33156 void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
stefan4fbd1452015-09-28 10:57:14157
158 std::string GetModifierString() const;
stefandb752f92016-12-05 16:23:40159 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 12:19:24160 int GetHighLinkCapacity() const;
philipel5ef2bc12017-02-21 15:28:31161 size_t GetFecBytes() const;
162 bool ExpectingFec() const;
stefan4fbd1452015-09-28 10:57:14163 void EvolveTestState(int bitrate_bps, bool suspended);
164
philipel5ef2bc12017-02-21 15:28:31165 const std::vector<int> link_rates_;
stefan4fbd1452015-09-28 10:57:14166 TestStates test_state_;
philipel5ef2bc12017-02-21 15:28:31167 TestStates next_state_;
stefan4fbd1452015-09-28 10:57:14168 int64_t state_start_ms_;
169 int64_t interval_start_ms_;
170 int sent_bytes_;
philipel5ef2bc12017-02-21 15:28:31171 std::vector<int> loss_rates_;
stefan@webrtc.org3d7da882014-07-08 13:59:46172};
Artem Titov14b42c22022-09-26 11:21:14173
stefan@webrtc.org3d7da882014-07-08 13:59:46174} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 04:47:31175#endif // CALL_RAMPUP_TESTS_H_