blob: 1339f1f2dc7c86cc10ce22759d92dd26ad09797e [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>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "call/call.h"
19#include "logging/rtc_event_log/rtc_event_log.h"
20#include "rtc_base/event.h"
21#include "test/call_test.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000022
23namespace webrtc {
24
25static const int kTransmissionTimeOffsetExtensionId = 6;
26static const int kAbsSendTimeExtensionId = 7;
Erik Språng6b8d3552015-09-24 15:06:57 +020027static const int kTransportSequenceNumberExtensionId = 8;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000028static const unsigned int kSingleStreamTargetBps = 1000000;
29
30class Clock;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000031
stefan4fbd1452015-09-28 03:57:14 -070032class RampUpTester : public test::EndToEndTest {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000033 public:
stefanff483612015-12-21 03:14:00 -080034 RampUpTester(size_t num_video_streams,
35 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080036 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070037 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080038 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070039 const std::string& extension_type,
40 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080041 bool red,
42 bool report_perf_stats);
stefan4fbd1452015-09-28 03:57:14 -070043 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000044
Stefan Holmerd20e6512016-01-12 15:51:22 +010045 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010046 size_t GetNumAudioStreams() const override;
philipel5ef2bc12017-02-21 07:28:31 -080047 size_t GetNumFlexfecStreams() const override;
Stefan Holmerd20e6512016-01-12 15:51:22 +010048
stefan4fbd1452015-09-28 03:57:14 -070049 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000050
stefan4fbd1452015-09-28 03:57:14 -070051 protected:
tommi0f8b4032017-02-22 11:22:05 -080052 virtual void PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000053
stefan092508a2015-09-29 02:26:42 -070054 void AccumulateStats(const VideoSendStream::StreamStats& stream,
55 size_t* total_packets_sent,
56 size_t* total_sent,
57 size_t* padding_sent,
58 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000059
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000060 void ReportResult(const std::string& measurement,
61 size_t value,
stefan4fbd1452015-09-28 03:57:14 -070062 const std::string& units) const;
63 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000064
skvlad11a9cbf2016-10-07 11:53:05 -070065 webrtc::RtcEventLogNullImpl event_log_;
tommi0f8b4032017-02-22 11:22:05 -080066 rtc::Event stop_event_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000067 Clock* const clock_;
stefanf116bd02015-10-27 08:29:42 -070068 FakeNetworkPipe::Config forward_transport_config_;
stefanff483612015-12-21 03:14:00 -080069 const size_t num_video_streams_;
70 const size_t num_audio_streams_;
philipel5ef2bc12017-02-21 07:28:31 -080071 const size_t num_flexfec_streams_;
stefan4fbd1452015-09-28 03:57:14 -070072 const bool rtx_;
73 const bool red_;
stefan45b5fe52017-03-09 06:27:02 -080074 const bool report_perf_stats_;
mflodman86cc6ff2016-07-26 04:44:06 -070075 Call* sender_call_;
stefan4fbd1452015-09-28 03:57:14 -070076 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 08:29:42 -070077 test::PacketTransport* send_transport_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000078
79 private:
stefan4fbd1452015-09-28 03:57:14 -070080 typedef std::map<uint32_t, uint32_t> SsrcMap;
perkjfa10b552016-10-02 23:45:26 -070081 class VideoStreamFactory;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000082
stefan4fbd1452015-09-28 03:57:14 -070083 Call::Config GetSenderCallConfig() override;
stefanff483612015-12-21 03:14:00 -080084 void OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070085 VideoSendStream* send_stream,
86 const std::vector<VideoReceiveStream*>& receive_streams) override;
eladalon413ee9a2017-08-22 04:02:52 -070087 test::PacketTransport* CreateSendTransport(
88 test::SingleThreadedTaskQueueForTesting* task_queue,
89 Call* sender_call) override;
stefanff483612015-12-21 03:14:00 -080090 void ModifyVideoConfigs(
91 VideoSendStream::Config* send_config,
92 std::vector<VideoReceiveStream::Config>* receive_configs,
93 VideoEncoderConfig* encoder_config) override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010094 void ModifyAudioConfigs(
95 AudioSendStream::Config* send_config,
96 std::vector<AudioReceiveStream::Config>* receive_configs) override;
philipel5ef2bc12017-02-21 07:28:31 -080097 void ModifyFlexfecConfigs(
98 std::vector<FlexfecReceiveStream::Config>* receive_configs) override;
stefan4fbd1452015-09-28 03:57:14 -070099 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000100
tommi0f8b4032017-02-22 11:22:05 -0800101 static void BitrateStatsPollingThread(void* obj);
stefan4fbd1452015-09-28 03:57:14 -0700102
103 const int start_bitrate_bps_;
stefan5a2c5062017-01-27 06:43:18 -0800104 const int64_t min_run_time_ms_;
stefan4fbd1452015-09-28 03:57:14 -0700105 int expected_bitrate_bps_;
106 int64_t test_start_ms_;
107 int64_t ramp_up_finished_ms_;
108
109 const std::string extension_type_;
stefanff483612015-12-21 03:14:00 -0800110 std::vector<uint32_t> video_ssrcs_;
111 std::vector<uint32_t> video_rtx_ssrcs_;
112 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700113
Peter Boström8c38e8b2015-11-26 17:45:47 +0100114 rtc::PlatformThread poller_thread_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000115};
116
stefan4fbd1452015-09-28 03:57:14 -0700117class RampUpDownUpTester : public RampUpTester {
118 public:
Stefan Holmerff2a6352016-01-14 10:00:21 +0100119 RampUpDownUpTester(size_t num_video_streams,
120 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800121 size_t num_flexfec_streams,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000122 unsigned int start_bitrate_bps,
Shao Changbine62202f2015-04-21 20:24:50 +0800123 const std::string& extension_type,
124 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800125 bool red,
stefan45b5fe52017-03-09 06:27:02 -0800126 const std::vector<int>& loss_rates,
127 bool report_perf_stats);
stefan4fbd1452015-09-28 03:57:14 -0700128 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000129
stefan4fbd1452015-09-28 03:57:14 -0700130 protected:
tommi0f8b4032017-02-22 11:22:05 -0800131 void PollStats() override;
stefan4fbd1452015-09-28 03:57:14 -0700132
133 private:
philipel5ef2bc12017-02-21 07:28:31 -0800134 enum TestStates {
135 kFirstRampup = 0,
136 kLowRate,
137 kSecondRampup,
138 kTestEnd,
139 kTransitionToNextState,
140 };
stefan4fbd1452015-09-28 03:57:14 -0700141
142 Call::Config GetReceiverCallConfig() override;
143
144 std::string GetModifierString() const;
stefandb752f92016-12-05 08:23:40 -0800145 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 04:19:24 -0800146 int GetHighLinkCapacity() const;
philipel5ef2bc12017-02-21 07:28:31 -0800147 size_t GetFecBytes() const;
148 bool ExpectingFec() const;
stefan4fbd1452015-09-28 03:57:14 -0700149 void EvolveTestState(int bitrate_bps, bool suspended);
150
philipel5ef2bc12017-02-21 07:28:31 -0800151 const std::vector<int> link_rates_;
stefan4fbd1452015-09-28 03:57:14 -0700152 TestStates test_state_;
philipel5ef2bc12017-02-21 07:28:31 -0800153 TestStates next_state_;
stefan4fbd1452015-09-28 03:57:14 -0700154 int64_t state_start_ms_;
155 int64_t interval_start_ms_;
156 int sent_bytes_;
philipel5ef2bc12017-02-21 07:28:31 -0800157 std::vector<int> loss_rates_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000158};
159} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200160#endif // CALL_RAMPUP_TESTS_H_