blob: 34e174014e39c7860963a3bf28b9ba89bbecb1fe [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"
26#include "test/call_test.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000027
28namespace webrtc {
29
30static const int kTransmissionTimeOffsetExtensionId = 6;
31static const int kAbsSendTimeExtensionId = 7;
Erik Språng6b8d3552015-09-24 15:06:57 +020032static const int kTransportSequenceNumberExtensionId = 8;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000033static const unsigned int kSingleStreamTargetBps = 1000000;
34
35class Clock;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000036
stefan4fbd1452015-09-28 03:57:14 -070037class RampUpTester : public test::EndToEndTest {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000038 public:
stefanff483612015-12-21 03:14:00 -080039 RampUpTester(size_t num_video_streams,
40 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080041 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070042 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080043 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070044 const std::string& extension_type,
45 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080046 bool red,
Tommi5e005f42019-08-05 15:29:14 +020047 bool report_perf_stats,
Yves Gerey6516f762019-08-29 11:50:23 +020048 test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue);
stefan4fbd1452015-09-28 03:57:14 -070049 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000050
Stefan Holmerd20e6512016-01-12 15:51:22 +010051 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010052 size_t GetNumAudioStreams() const override;
philipel5ef2bc12017-02-21 07:28:31 -080053 size_t GetNumFlexfecStreams() const override;
Stefan Holmerd20e6512016-01-12 15:51:22 +010054
stefan4fbd1452015-09-28 03:57:14 -070055 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000056
stefan4fbd1452015-09-28 03:57:14 -070057 protected:
tommi0f8b4032017-02-22 11:22:05 -080058 virtual void PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000059
stefan092508a2015-09-29 02:26:42 -070060 void AccumulateStats(const VideoSendStream::StreamStats& stream,
61 size_t* total_packets_sent,
62 size_t* total_sent,
63 size_t* padding_sent,
64 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000065
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000066 void ReportResult(const std::string& measurement,
67 size_t value,
stefan4fbd1452015-09-28 03:57:14 -070068 const std::string& units) const;
69 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000070
71 Clock* const clock_;
Artem Titov75e36472018-10-08 12:28:56 +020072 BuiltInNetworkBehaviorConfig forward_transport_config_;
stefanff483612015-12-21 03:14:00 -080073 const size_t num_video_streams_;
74 const size_t num_audio_streams_;
philipel5ef2bc12017-02-21 07:28:31 -080075 const size_t num_flexfec_streams_;
stefan4fbd1452015-09-28 03:57:14 -070076 const bool rtx_;
77 const bool red_;
stefan45b5fe52017-03-09 06:27:02 -080078 const bool report_perf_stats_;
mflodman86cc6ff2016-07-26 04:44:06 -070079 Call* sender_call_;
stefan4fbd1452015-09-28 03:57:14 -070080 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 08:29:42 -070081 test::PacketTransport* send_transport_;
Artem Titov631cafa2018-08-21 21:01:00 +020082 SimulatedNetwork* send_simulated_network_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000083
84 private:
stefan4fbd1452015-09-28 03:57:14 -070085 typedef std::map<uint32_t, uint32_t> SsrcMap;
perkjfa10b552016-10-02 23:45:26 -070086 class VideoStreamFactory;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000087
Niels Möllerde8e6e62018-11-13 15:10:33 +010088 void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override;
stefanff483612015-12-21 03:14:00 -080089 void OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070090 VideoSendStream* send_stream,
91 const std::vector<VideoReceiveStream*>& receive_streams) override;
Danil Chapovalov44db4362019-09-30 04:16:28 +020092 std::unique_ptr<test::PacketTransport> CreateSendTransport(
93 TaskQueueBase* task_queue,
eladalon413ee9a2017-08-22 04:02:52 -070094 Call* sender_call) override;
stefanff483612015-12-21 03:14:00 -080095 void ModifyVideoConfigs(
96 VideoSendStream::Config* send_config,
97 std::vector<VideoReceiveStream::Config>* receive_configs,
98 VideoEncoderConfig* encoder_config) override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010099 void ModifyAudioConfigs(
100 AudioSendStream::Config* send_config,
101 std::vector<AudioReceiveStream::Config>* receive_configs) override;
philipel5ef2bc12017-02-21 07:28:31 -0800102 void ModifyFlexfecConfigs(
103 std::vector<FlexfecReceiveStream::Config>* receive_configs) override;
stefan4fbd1452015-09-28 03:57:14 -0700104 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000105
stefan4fbd1452015-09-28 03:57:14 -0700106 const int start_bitrate_bps_;
stefan5a2c5062017-01-27 06:43:18 -0800107 const int64_t min_run_time_ms_;
stefan4fbd1452015-09-28 03:57:14 -0700108 int expected_bitrate_bps_;
109 int64_t test_start_ms_;
110 int64_t ramp_up_finished_ms_;
111
112 const std::string extension_type_;
stefanff483612015-12-21 03:14:00 -0800113 std::vector<uint32_t> video_ssrcs_;
114 std::vector<uint32_t> video_rtx_ssrcs_;
115 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700116
Tommi6b117a52019-08-20 09:58:56 +0200117 // Initially zero, then set to the target time in milliseconds for when
118 // PollStats() will next be called.
119 int64_t next_scheduled_poll_time_ms_ = 0;
120
Tommi5e005f42019-08-05 15:29:14 +0200121 protected:
Tommi6b117a52019-08-20 09:58:56 +0200122 // Call from within PollStats to ensure that initial PollStats() timestamp
123 // is captured.
124 void EnsurePollTimeSet();
125
126 // Calculates the interval from now and until when PollStats() next should be
127 // called. Internally updates a timestamp, so each call will yield the
128 // subsequent timestamp (in milliseconds).
129 // Must be called from the |task_queue_|.
130 int64_t GetIntervalForNextPoll();
131
Yves Gerey6516f762019-08-29 11:50:23 +0200132 test::DEPRECATED_SingleThreadedTaskQueueForTesting* const task_queue_;
133 test::DEPRECATED_SingleThreadedTaskQueueForTesting::TaskId pending_task_ = -1;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000134};
135
stefan4fbd1452015-09-28 03:57:14 -0700136class RampUpDownUpTester : public RampUpTester {
137 public:
Yves Gerey6516f762019-08-29 11:50:23 +0200138 RampUpDownUpTester(
139 size_t num_video_streams,
140 size_t num_audio_streams,
141 size_t num_flexfec_streams,
142 unsigned int start_bitrate_bps,
143 const std::string& extension_type,
144 bool rtx,
145 bool red,
146 const std::vector<int>& loss_rates,
147 bool report_perf_stats,
148 test::DEPRECATED_SingleThreadedTaskQueueForTesting* task_queue);
stefan4fbd1452015-09-28 03:57:14 -0700149 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000150
stefan4fbd1452015-09-28 03:57:14 -0700151 protected:
tommi0f8b4032017-02-22 11:22:05 -0800152 void PollStats() override;
stefan4fbd1452015-09-28 03:57:14 -0700153
154 private:
philipel5ef2bc12017-02-21 07:28:31 -0800155 enum TestStates {
156 kFirstRampup = 0,
157 kLowRate,
158 kSecondRampup,
159 kTestEnd,
160 kTransitionToNextState,
161 };
stefan4fbd1452015-09-28 03:57:14 -0700162
Niels Möllerde8e6e62018-11-13 15:10:33 +0100163 void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
stefan4fbd1452015-09-28 03:57:14 -0700164
165 std::string GetModifierString() const;
stefandb752f92016-12-05 08:23:40 -0800166 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 04:19:24 -0800167 int GetHighLinkCapacity() const;
philipel5ef2bc12017-02-21 07:28:31 -0800168 size_t GetFecBytes() const;
169 bool ExpectingFec() const;
stefan4fbd1452015-09-28 03:57:14 -0700170 void EvolveTestState(int bitrate_bps, bool suspended);
171
philipel5ef2bc12017-02-21 07:28:31 -0800172 const std::vector<int> link_rates_;
stefan4fbd1452015-09-28 03:57:14 -0700173 TestStates test_state_;
philipel5ef2bc12017-02-21 07:28:31 -0800174 TestStates next_state_;
stefan4fbd1452015-09-28 03:57:14 -0700175 int64_t state_start_ms_;
176 int64_t interval_start_ms_;
177 int sent_bytes_;
philipel5ef2bc12017-02-21 07:28:31 -0800178 std::vector<int> loss_rates_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000179};
180} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200181#endif // CALL_RAMPUP_TESTS_H_