blob: b7d4af5f5a8898fafa0b6b3a1345706cb82c9759 [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
Artem Titov46c4e602018-08-17 14:26:54 +020019#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "call/call.h"
Artem Titov631cafa2018-08-21 21:01:00 +020021#include "call/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "logging/rtc_event_log/rtc_event_log.h"
23#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,
45 bool report_perf_stats);
stefan4fbd1452015-09-28 03:57:14 -070046 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000047
Stefan Holmerd20e6512016-01-12 15:51:22 +010048 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010049 size_t GetNumAudioStreams() const override;
philipel5ef2bc12017-02-21 07:28:31 -080050 size_t GetNumFlexfecStreams() const override;
Stefan Holmerd20e6512016-01-12 15:51:22 +010051
stefan4fbd1452015-09-28 03:57:14 -070052 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000053
stefan4fbd1452015-09-28 03:57:14 -070054 protected:
tommi0f8b4032017-02-22 11:22:05 -080055 virtual void PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000056
stefan092508a2015-09-29 02:26:42 -070057 void AccumulateStats(const VideoSendStream::StreamStats& stream,
58 size_t* total_packets_sent,
59 size_t* total_sent,
60 size_t* padding_sent,
61 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000062
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000063 void ReportResult(const std::string& measurement,
64 size_t value,
stefan4fbd1452015-09-28 03:57:14 -070065 const std::string& units) const;
66 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000067
tommi0f8b4032017-02-22 11:22:05 -080068 rtc::Event stop_event_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000069 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
tommi0f8b4032017-02-22 11:22:05 -0800104 static void BitrateStatsPollingThread(void* obj);
stefan4fbd1452015-09-28 03:57:14 -0700105
106 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
Peter Boström8c38e8b2015-11-26 17:45:47 +0100117 rtc::PlatformThread poller_thread_;
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,
130 bool report_perf_stats);
stefan4fbd1452015-09-28 03:57:14 -0700131 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000132
stefan4fbd1452015-09-28 03:57:14 -0700133 protected:
tommi0f8b4032017-02-22 11:22:05 -0800134 void PollStats() override;
stefan4fbd1452015-09-28 03:57:14 -0700135
136 private:
philipel5ef2bc12017-02-21 07:28:31 -0800137 enum TestStates {
138 kFirstRampup = 0,
139 kLowRate,
140 kSecondRampup,
141 kTestEnd,
142 kTransitionToNextState,
143 };
stefan4fbd1452015-09-28 03:57:14 -0700144
Niels Möllerde8e6e62018-11-13 15:10:33 +0100145 void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
stefan4fbd1452015-09-28 03:57:14 -0700146
147 std::string GetModifierString() const;
stefandb752f92016-12-05 08:23:40 -0800148 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 04:19:24 -0800149 int GetHighLinkCapacity() const;
philipel5ef2bc12017-02-21 07:28:31 -0800150 size_t GetFecBytes() const;
151 bool ExpectingFec() const;
stefan4fbd1452015-09-28 03:57:14 -0700152 void EvolveTestState(int bitrate_bps, bool suspended);
153
philipel5ef2bc12017-02-21 07:28:31 -0800154 const std::vector<int> link_rates_;
stefan4fbd1452015-09-28 03:57:14 -0700155 TestStates test_state_;
philipel5ef2bc12017-02-21 07:28:31 -0800156 TestStates next_state_;
stefan4fbd1452015-09-28 03:57:14 -0700157 int64_t state_start_ms_;
158 int64_t interval_start_ms_;
159 int sent_bytes_;
philipel5ef2bc12017-02-21 07:28:31 -0800160 std::vector<int> loss_rates_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000161};
162} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200163#endif // CALL_RAMPUP_TESTS_H_