blob: 9c2f57dd0076933043c23c7217f77fe999f1b82f [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
Tommi5e005f42019-08-05 15:29:14 +0200115 protected:
116 test::SingleThreadedTaskQueueForTesting* const task_queue_;
117 test::SingleThreadedTaskQueueForTesting::TaskId pending_task_ = -1;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000118};
119
stefan4fbd1452015-09-28 03:57:14 -0700120class RampUpDownUpTester : public RampUpTester {
121 public:
Stefan Holmerff2a6352016-01-14 10:00:21 +0100122 RampUpDownUpTester(size_t num_video_streams,
123 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800124 size_t num_flexfec_streams,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000125 unsigned int start_bitrate_bps,
Shao Changbine62202f2015-04-21 20:24:50 +0800126 const std::string& extension_type,
127 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800128 bool red,
stefan45b5fe52017-03-09 06:27:02 -0800129 const std::vector<int>& loss_rates,
Tommi5e005f42019-08-05 15:29:14 +0200130 bool report_perf_stats,
131 test::SingleThreadedTaskQueueForTesting* task_queue);
stefan4fbd1452015-09-28 03:57:14 -0700132 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000133
stefan4fbd1452015-09-28 03:57:14 -0700134 protected:
tommi0f8b4032017-02-22 11:22:05 -0800135 void PollStats() override;
stefan4fbd1452015-09-28 03:57:14 -0700136
137 private:
philipel5ef2bc12017-02-21 07:28:31 -0800138 enum TestStates {
139 kFirstRampup = 0,
140 kLowRate,
141 kSecondRampup,
142 kTestEnd,
143 kTransitionToNextState,
144 };
stefan4fbd1452015-09-28 03:57:14 -0700145
Niels Möllerde8e6e62018-11-13 15:10:33 +0100146 void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
stefan4fbd1452015-09-28 03:57:14 -0700147
148 std::string GetModifierString() const;
stefandb752f92016-12-05 08:23:40 -0800149 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 04:19:24 -0800150 int GetHighLinkCapacity() const;
philipel5ef2bc12017-02-21 07:28:31 -0800151 size_t GetFecBytes() const;
152 bool ExpectingFec() const;
stefan4fbd1452015-09-28 03:57:14 -0700153 void EvolveTestState(int bitrate_bps, bool suspended);
154
philipel5ef2bc12017-02-21 07:28:31 -0800155 const std::vector<int> link_rates_;
stefan4fbd1452015-09-28 03:57:14 -0700156 TestStates test_state_;
philipel5ef2bc12017-02-21 07:28:31 -0800157 TestStates next_state_;
stefan4fbd1452015-09-28 03:57:14 -0700158 int64_t state_start_ms_;
159 int64_t interval_start_ms_;
160 int sent_bytes_;
philipel5ef2bc12017-02-21 07:28:31 -0800161 std::vector<int> loss_rates_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000162};
163} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200164#endif // CALL_RAMPUP_TESTS_H_