blob: 075de6d88800bc43040207d547ec42417ed8ed9e [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
Danil Chapovalov83bbe912019-08-07 12:24:53 +020020#include "api/rtc_event_log/rtc_event_log.h"
Danil Chapovalov44db4362019-09-30 04:16:28 +020021#include "api/task_queue/task_queue_base.h"
Artem Titov46c4e602018-08-17 14:26:54 +020022#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "call/call.h"
Artem Titov631cafa2018-08-21 21:01:00 +020024#include "call/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/event.h"
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +020026#include "rtc_base/task_utils/repeating_task.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "test/call_test.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000028
29namespace webrtc {
30
31static const int kTransmissionTimeOffsetExtensionId = 6;
32static const int kAbsSendTimeExtensionId = 7;
Erik Språng6b8d3552015-09-24 15:06:57 +020033static const int kTransportSequenceNumberExtensionId = 8;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000034static const unsigned int kSingleStreamTargetBps = 1000000;
35
36class Clock;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000037
stefan4fbd1452015-09-28 03:57:14 -070038class RampUpTester : public test::EndToEndTest {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000039 public:
stefanff483612015-12-21 03:14:00 -080040 RampUpTester(size_t num_video_streams,
41 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080042 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070043 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080044 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070045 const std::string& extension_type,
46 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080047 bool red,
Tommi5e005f42019-08-05 15:29:14 +020048 bool report_perf_stats,
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +020049 TaskQueueBase* task_queue);
stefan4fbd1452015-09-28 03:57:14 -070050 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000051
Stefan Holmerd20e6512016-01-12 15:51:22 +010052 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010053 size_t GetNumAudioStreams() const override;
philipel5ef2bc12017-02-21 07:28:31 -080054 size_t GetNumFlexfecStreams() const override;
Stefan Holmerd20e6512016-01-12 15:51:22 +010055
stefan4fbd1452015-09-28 03:57:14 -070056 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000057
stefan4fbd1452015-09-28 03:57:14 -070058 protected:
tommi0f8b4032017-02-22 11:22:05 -080059 virtual void PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000060
stefan092508a2015-09-29 02:26:42 -070061 void AccumulateStats(const VideoSendStream::StreamStats& stream,
62 size_t* total_packets_sent,
63 size_t* total_sent,
64 size_t* padding_sent,
65 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000066
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000067 void ReportResult(const std::string& measurement,
68 size_t value,
stefan4fbd1452015-09-28 03:57:14 -070069 const std::string& units) const;
70 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000071
72 Clock* const clock_;
Artem Titov75e36472018-10-08 12:28:56 +020073 BuiltInNetworkBehaviorConfig forward_transport_config_;
stefanff483612015-12-21 03:14:00 -080074 const size_t num_video_streams_;
75 const size_t num_audio_streams_;
philipel5ef2bc12017-02-21 07:28:31 -080076 const size_t num_flexfec_streams_;
stefan4fbd1452015-09-28 03:57:14 -070077 const bool rtx_;
78 const bool red_;
stefan45b5fe52017-03-09 06:27:02 -080079 const bool report_perf_stats_;
mflodman86cc6ff2016-07-26 04:44:06 -070080 Call* sender_call_;
stefan4fbd1452015-09-28 03:57:14 -070081 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 08:29:42 -070082 test::PacketTransport* send_transport_;
Artem Titov631cafa2018-08-21 21:01:00 +020083 SimulatedNetwork* send_simulated_network_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000084
85 private:
stefan4fbd1452015-09-28 03:57:14 -070086 typedef std::map<uint32_t, uint32_t> SsrcMap;
perkjfa10b552016-10-02 23:45:26 -070087 class VideoStreamFactory;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000088
Niels Möllerde8e6e62018-11-13 15:10:33 +010089 void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override;
stefanff483612015-12-21 03:14:00 -080090 void OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070091 VideoSendStream* send_stream,
92 const std::vector<VideoReceiveStream*>& receive_streams) override;
Danil Chapovalov44db4362019-09-30 04:16:28 +020093 std::unique_ptr<test::PacketTransport> CreateSendTransport(
94 TaskQueueBase* task_queue,
eladalon413ee9a2017-08-22 04:02:52 -070095 Call* sender_call) override;
stefanff483612015-12-21 03:14:00 -080096 void ModifyVideoConfigs(
97 VideoSendStream::Config* send_config,
98 std::vector<VideoReceiveStream::Config>* receive_configs,
99 VideoEncoderConfig* encoder_config) override;
Stefan Holmerff2a6352016-01-14 10:00:21 +0100100 void ModifyAudioConfigs(
101 AudioSendStream::Config* send_config,
102 std::vector<AudioReceiveStream::Config>* receive_configs) override;
philipel5ef2bc12017-02-21 07:28:31 -0800103 void ModifyFlexfecConfigs(
104 std::vector<FlexfecReceiveStream::Config>* receive_configs) override;
stefan4fbd1452015-09-28 03:57:14 -0700105 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000106
stefan4fbd1452015-09-28 03:57:14 -0700107 const int start_bitrate_bps_;
stefan5a2c5062017-01-27 06:43:18 -0800108 const int64_t min_run_time_ms_;
stefan4fbd1452015-09-28 03:57:14 -0700109 int expected_bitrate_bps_;
110 int64_t test_start_ms_;
111 int64_t ramp_up_finished_ms_;
112
113 const std::string extension_type_;
stefanff483612015-12-21 03:14:00 -0800114 std::vector<uint32_t> video_ssrcs_;
115 std::vector<uint32_t> video_rtx_ssrcs_;
116 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700117
Tommi5e005f42019-08-05 15:29:14 +0200118 protected:
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +0200119 TaskQueueBase* const task_queue_;
120 RepeatingTaskHandle pending_task_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000121};
122
stefan4fbd1452015-09-28 03:57:14 -0700123class RampUpDownUpTester : public RampUpTester {
124 public:
Danil Chapovalov9f5ae7b2019-10-21 11:08:13 +0200125 RampUpDownUpTester(size_t num_video_streams,
126 size_t num_audio_streams,
127 size_t num_flexfec_streams,
128 unsigned int start_bitrate_bps,
129 const std::string& extension_type,
130 bool rtx,
131 bool red,
132 const std::vector<int>& loss_rates,
133 bool report_perf_stats,
134 TaskQueueBase* task_queue);
stefan4fbd1452015-09-28 03:57:14 -0700135 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000136
stefan4fbd1452015-09-28 03:57:14 -0700137 protected:
tommi0f8b4032017-02-22 11:22:05 -0800138 void PollStats() override;
stefan4fbd1452015-09-28 03:57:14 -0700139
140 private:
philipel5ef2bc12017-02-21 07:28:31 -0800141 enum TestStates {
142 kFirstRampup = 0,
143 kLowRate,
144 kSecondRampup,
145 kTestEnd,
146 kTransitionToNextState,
147 };
stefan4fbd1452015-09-28 03:57:14 -0700148
Niels Möllerde8e6e62018-11-13 15:10:33 +0100149 void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
stefan4fbd1452015-09-28 03:57:14 -0700150
151 std::string GetModifierString() const;
stefandb752f92016-12-05 08:23:40 -0800152 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 04:19:24 -0800153 int GetHighLinkCapacity() const;
philipel5ef2bc12017-02-21 07:28:31 -0800154 size_t GetFecBytes() const;
155 bool ExpectingFec() const;
stefan4fbd1452015-09-28 03:57:14 -0700156 void EvolveTestState(int bitrate_bps, bool suspended);
157
philipel5ef2bc12017-02-21 07:28:31 -0800158 const std::vector<int> link_rates_;
stefan4fbd1452015-09-28 03:57:14 -0700159 TestStates test_state_;
philipel5ef2bc12017-02-21 07:28:31 -0800160 TestStates next_state_;
stefan4fbd1452015-09-28 03:57:14 -0700161 int64_t state_start_ms_;
162 int64_t interval_start_ms_;
163 int sent_bytes_;
philipel5ef2bc12017-02-21 07:28:31 -0800164 std::vector<int> loss_rates_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000165};
166} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200167#endif // CALL_RAMPUP_TESTS_H_