blob: c07c793f9164f6eaf7861e32fbd307cc56214edf [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>
15#include <string>
Artem Titov631cafa2018-08-21 21:01:00 +020016#include <utility>
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000017#include <vector>
18
Danil Chapovalov83bbe912019-08-07 12:24:53 +020019#include "api/rtc_event_log/rtc_event_log.h"
Artem Titov46c4e602018-08-17 14:26:54 +020020#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "call/call.h"
Artem Titov631cafa2018-08-21 21:01:00 +020022#include "call/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/event.h"
24#include "test/call_test.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000025
26namespace webrtc {
27
28static const int kTransmissionTimeOffsetExtensionId = 6;
29static const int kAbsSendTimeExtensionId = 7;
Erik Språng6b8d3552015-09-24 15:06:57 +020030static const int kTransportSequenceNumberExtensionId = 8;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000031static const unsigned int kSingleStreamTargetBps = 1000000;
32
33class Clock;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000034
stefan4fbd1452015-09-28 03:57:14 -070035class RampUpTester : public test::EndToEndTest {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000036 public:
stefanff483612015-12-21 03:14:00 -080037 RampUpTester(size_t num_video_streams,
38 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080039 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070040 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080041 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070042 const std::string& extension_type,
43 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080044 bool red,
Tommi5e005f42019-08-05 15:29:14 +020045 bool report_perf_stats,
46 test::SingleThreadedTaskQueueForTesting* task_queue);
stefan4fbd1452015-09-28 03:57:14 -070047 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000048
Stefan Holmerd20e6512016-01-12 15:51:22 +010049 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010050 size_t GetNumAudioStreams() const override;
philipel5ef2bc12017-02-21 07:28:31 -080051 size_t GetNumFlexfecStreams() const override;
Stefan Holmerd20e6512016-01-12 15:51:22 +010052
stefan4fbd1452015-09-28 03:57:14 -070053 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000054
stefan4fbd1452015-09-28 03:57:14 -070055 protected:
tommi0f8b4032017-02-22 11:22:05 -080056 virtual void PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000057
stefan092508a2015-09-29 02:26:42 -070058 void AccumulateStats(const VideoSendStream::StreamStats& stream,
59 size_t* total_packets_sent,
60 size_t* total_sent,
61 size_t* padding_sent,
62 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000063
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000064 void ReportResult(const std::string& measurement,
65 size_t value,
stefan4fbd1452015-09-28 03:57:14 -070066 const std::string& units) const;
67 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000068
69 Clock* const clock_;
Artem Titov75e36472018-10-08 12:28:56 +020070 BuiltInNetworkBehaviorConfig forward_transport_config_;
stefanff483612015-12-21 03:14:00 -080071 const size_t num_video_streams_;
72 const size_t num_audio_streams_;
philipel5ef2bc12017-02-21 07:28:31 -080073 const size_t num_flexfec_streams_;
stefan4fbd1452015-09-28 03:57:14 -070074 const bool rtx_;
75 const bool red_;
stefan45b5fe52017-03-09 06:27:02 -080076 const bool report_perf_stats_;
mflodman86cc6ff2016-07-26 04:44:06 -070077 Call* sender_call_;
stefan4fbd1452015-09-28 03:57:14 -070078 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 08:29:42 -070079 test::PacketTransport* send_transport_;
Artem Titov631cafa2018-08-21 21:01:00 +020080 SimulatedNetwork* send_simulated_network_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000081
82 private:
stefan4fbd1452015-09-28 03:57:14 -070083 typedef std::map<uint32_t, uint32_t> SsrcMap;
perkjfa10b552016-10-02 23:45:26 -070084 class VideoStreamFactory;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000085
Niels Möllerde8e6e62018-11-13 15:10:33 +010086 void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override;
stefanff483612015-12-21 03:14:00 -080087 void OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070088 VideoSendStream* send_stream,
89 const std::vector<VideoReceiveStream*>& receive_streams) override;
eladalon413ee9a2017-08-22 04:02:52 -070090 test::PacketTransport* CreateSendTransport(
91 test::SingleThreadedTaskQueueForTesting* task_queue,
92 Call* sender_call) override;
stefanff483612015-12-21 03:14:00 -080093 void ModifyVideoConfigs(
94 VideoSendStream::Config* send_config,
95 std::vector<VideoReceiveStream::Config>* receive_configs,
96 VideoEncoderConfig* encoder_config) override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010097 void ModifyAudioConfigs(
98 AudioSendStream::Config* send_config,
99 std::vector<AudioReceiveStream::Config>* receive_configs) override;
philipel5ef2bc12017-02-21 07:28:31 -0800100 void ModifyFlexfecConfigs(
101 std::vector<FlexfecReceiveStream::Config>* receive_configs) override;
stefan4fbd1452015-09-28 03:57:14 -0700102 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000103
stefan4fbd1452015-09-28 03:57:14 -0700104 const int start_bitrate_bps_;
stefan5a2c5062017-01-27 06:43:18 -0800105 const int64_t min_run_time_ms_;
stefan4fbd1452015-09-28 03:57:14 -0700106 int expected_bitrate_bps_;
107 int64_t test_start_ms_;
108 int64_t ramp_up_finished_ms_;
109
110 const std::string extension_type_;
stefanff483612015-12-21 03:14:00 -0800111 std::vector<uint32_t> video_ssrcs_;
112 std::vector<uint32_t> video_rtx_ssrcs_;
113 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700114
Tommi6b117a52019-08-20 09:58:56 +0200115 // Initially zero, then set to the target time in milliseconds for when
116 // PollStats() will next be called.
117 int64_t next_scheduled_poll_time_ms_ = 0;
118
Tommi5e005f42019-08-05 15:29:14 +0200119 protected:
Tommi6b117a52019-08-20 09:58:56 +0200120 // Call from within PollStats to ensure that initial PollStats() timestamp
121 // is captured.
122 void EnsurePollTimeSet();
123
124 // Calculates the interval from now and until when PollStats() next should be
125 // called. Internally updates a timestamp, so each call will yield the
126 // subsequent timestamp (in milliseconds).
127 // Must be called from the |task_queue_|.
128 int64_t GetIntervalForNextPoll();
129
Tommi5e005f42019-08-05 15:29:14 +0200130 test::SingleThreadedTaskQueueForTesting* const task_queue_;
131 test::SingleThreadedTaskQueueForTesting::TaskId pending_task_ = -1;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000132};
133
stefan4fbd1452015-09-28 03:57:14 -0700134class RampUpDownUpTester : public RampUpTester {
135 public:
Stefan Holmerff2a6352016-01-14 10:00:21 +0100136 RampUpDownUpTester(size_t num_video_streams,
137 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800138 size_t num_flexfec_streams,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000139 unsigned int start_bitrate_bps,
Shao Changbine62202f2015-04-21 20:24:50 +0800140 const std::string& extension_type,
141 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800142 bool red,
stefan45b5fe52017-03-09 06:27:02 -0800143 const std::vector<int>& loss_rates,
Tommi5e005f42019-08-05 15:29:14 +0200144 bool report_perf_stats,
145 test::SingleThreadedTaskQueueForTesting* task_queue);
stefan4fbd1452015-09-28 03:57:14 -0700146 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000147
stefan4fbd1452015-09-28 03:57:14 -0700148 protected:
tommi0f8b4032017-02-22 11:22:05 -0800149 void PollStats() override;
stefan4fbd1452015-09-28 03:57:14 -0700150
151 private:
philipel5ef2bc12017-02-21 07:28:31 -0800152 enum TestStates {
153 kFirstRampup = 0,
154 kLowRate,
155 kSecondRampup,
156 kTestEnd,
157 kTransitionToNextState,
158 };
stefan4fbd1452015-09-28 03:57:14 -0700159
Niels Möllerde8e6e62018-11-13 15:10:33 +0100160 void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
stefan4fbd1452015-09-28 03:57:14 -0700161
162 std::string GetModifierString() const;
stefandb752f92016-12-05 08:23:40 -0800163 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 04:19:24 -0800164 int GetHighLinkCapacity() const;
philipel5ef2bc12017-02-21 07:28:31 -0800165 size_t GetFecBytes() const;
166 bool ExpectingFec() const;
stefan4fbd1452015-09-28 03:57:14 -0700167 void EvolveTestState(int bitrate_bps, bool suspended);
168
philipel5ef2bc12017-02-21 07:28:31 -0800169 const std::vector<int> link_rates_;
stefan4fbd1452015-09-28 03:57:14 -0700170 TestStates test_state_;
philipel5ef2bc12017-02-21 07:28:31 -0800171 TestStates next_state_;
stefan4fbd1452015-09-28 03:57:14 -0700172 int64_t state_start_ms_;
173 int64_t interval_start_ms_;
174 int sent_bytes_;
philipel5ef2bc12017-02-21 07:28:31 -0800175 std::vector<int> loss_rates_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000176};
177} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200178#endif // CALL_RAMPUP_TESTS_H_