blob: 5cf4c4fab506932d30b16dc1117c441d4e09fb9d [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
stefanff483612015-12-21 03:14:00 -080011#ifndef WEBRTC_CALL_RAMPUP_TESTS_H_
12#define WEBRTC_CALL_RAMPUP_TESTS_H_
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000013
14#include <map>
15#include <string>
16#include <vector>
17
Peter Boström5811a392015-12-10 13:02:50 +010018#include "webrtc/base/event.h"
ossuf515ab82016-12-07 04:52:58 -080019#include "webrtc/call/call.h"
skvlad11a9cbf2016-10-07 11:53:05 -070020#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000021#include "webrtc/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,
stefan4fbd1452015-09-28 03:57:14 -070036 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080037 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070038 const std::string& extension_type,
39 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080040 bool red,
41 bool report_perf_stats);
stefan4fbd1452015-09-28 03:57:14 -070042 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000043
Stefan Holmerd20e6512016-01-12 15:51:22 +010044 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010045 size_t GetNumAudioStreams() const override;
Stefan Holmerd20e6512016-01-12 15:51:22 +010046
stefan4fbd1452015-09-28 03:57:14 -070047 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000048
stefan4fbd1452015-09-28 03:57:14 -070049 protected:
50 virtual bool PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000051
stefan092508a2015-09-29 02:26:42 -070052 void AccumulateStats(const VideoSendStream::StreamStats& stream,
53 size_t* total_packets_sent,
54 size_t* total_sent,
55 size_t* padding_sent,
56 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000057
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000058 void ReportResult(const std::string& measurement,
59 size_t value,
stefan4fbd1452015-09-28 03:57:14 -070060 const std::string& units) const;
61 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000062
skvlad11a9cbf2016-10-07 11:53:05 -070063 webrtc::RtcEventLogNullImpl event_log_;
stefan4fbd1452015-09-28 03:57:14 -070064 rtc::Event event_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000065 Clock* const clock_;
stefanf116bd02015-10-27 08:29:42 -070066 FakeNetworkPipe::Config forward_transport_config_;
stefanff483612015-12-21 03:14:00 -080067 const size_t num_video_streams_;
68 const size_t num_audio_streams_;
stefan4fbd1452015-09-28 03:57:14 -070069 const bool rtx_;
70 const bool red_;
mflodman86cc6ff2016-07-26 04:44:06 -070071 Call* sender_call_;
stefan4fbd1452015-09-28 03:57:14 -070072 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 08:29:42 -070073 test::PacketTransport* send_transport_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000074
75 private:
stefan4fbd1452015-09-28 03:57:14 -070076 typedef std::map<uint32_t, uint32_t> SsrcMap;
perkjfa10b552016-10-02 23:45:26 -070077 class VideoStreamFactory;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000078
stefan4fbd1452015-09-28 03:57:14 -070079 Call::Config GetSenderCallConfig() override;
stefanff483612015-12-21 03:14:00 -080080 void OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070081 VideoSendStream* send_stream,
82 const std::vector<VideoReceiveStream*>& receive_streams) override;
stefane74eef12016-01-08 06:47:13 -080083 test::PacketTransport* CreateSendTransport(Call* sender_call) override;
stefanff483612015-12-21 03:14:00 -080084 void ModifyVideoConfigs(
85 VideoSendStream::Config* send_config,
86 std::vector<VideoReceiveStream::Config>* receive_configs,
87 VideoEncoderConfig* encoder_config) override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010088 void ModifyAudioConfigs(
89 AudioSendStream::Config* send_config,
90 std::vector<AudioReceiveStream::Config>* receive_configs) override;
stefan4fbd1452015-09-28 03:57:14 -070091 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000092
stefan4fbd1452015-09-28 03:57:14 -070093 static bool BitrateStatsPollingThread(void* obj);
94
95 const int start_bitrate_bps_;
stefan5a2c5062017-01-27 06:43:18 -080096 const int64_t min_run_time_ms_;
97 const bool report_perf_stats_;
stefan4fbd1452015-09-28 03:57:14 -070098 int expected_bitrate_bps_;
99 int64_t test_start_ms_;
100 int64_t ramp_up_finished_ms_;
101
102 const std::string extension_type_;
stefanff483612015-12-21 03:14:00 -0800103 std::vector<uint32_t> video_ssrcs_;
104 std::vector<uint32_t> video_rtx_ssrcs_;
105 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700106
Peter Boström8c38e8b2015-11-26 17:45:47 +0100107 rtc::PlatformThread poller_thread_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000108};
109
stefan4fbd1452015-09-28 03:57:14 -0700110class RampUpDownUpTester : public RampUpTester {
111 public:
Stefan Holmerff2a6352016-01-14 10:00:21 +0100112 RampUpDownUpTester(size_t num_video_streams,
113 size_t num_audio_streams,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000114 unsigned int start_bitrate_bps,
Shao Changbine62202f2015-04-21 20:24:50 +0800115 const std::string& extension_type,
116 bool rtx,
philipelb80bdca2017-02-21 06:52:26 -0800117 bool red);
stefan4fbd1452015-09-28 03:57:14 -0700118 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000119
stefan4fbd1452015-09-28 03:57:14 -0700120 protected:
121 bool PollStats() override;
122
123 private:
philipelb80bdca2017-02-21 06:52:26 -0800124 enum TestStates { kFirstRampup, kLowRate, kSecondRampup };
stefan4fbd1452015-09-28 03:57:14 -0700125
126 Call::Config GetReceiverCallConfig() override;
127
128 std::string GetModifierString() const;
stefandb752f92016-12-05 08:23:40 -0800129 int GetExpectedHighBitrate() const;
stefan38d8b3c2017-01-09 04:19:24 -0800130 int GetHighLinkCapacity() const;
stefan4fbd1452015-09-28 03:57:14 -0700131 void EvolveTestState(int bitrate_bps, bool suspended);
132
stefan4fbd1452015-09-28 03:57:14 -0700133 TestStates test_state_;
134 int64_t state_start_ms_;
135 int64_t interval_start_ms_;
136 int sent_bytes_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000137};
138} // namespace webrtc
stefanff483612015-12-21 03:14:00 -0800139#endif // WEBRTC_CALL_RAMPUP_TESTS_H_