blob: f3779e21f7137438cb518d9029a407a2372e1c86 [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"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000019#include "webrtc/call.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000020#include "webrtc/test/call_test.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000021
22namespace webrtc {
23
24static const int kTransmissionTimeOffsetExtensionId = 6;
25static const int kAbsSendTimeExtensionId = 7;
Erik Språng6b8d3552015-09-24 15:06:57 +020026static const int kTransportSequenceNumberExtensionId = 8;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000027static const unsigned int kSingleStreamTargetBps = 1000000;
28
29class Clock;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000030
stefan4fbd1452015-09-28 03:57:14 -070031class RampUpTester : public test::EndToEndTest {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000032 public:
stefanff483612015-12-21 03:14:00 -080033 RampUpTester(size_t num_video_streams,
34 size_t num_audio_streams,
stefan4fbd1452015-09-28 03:57:14 -070035 unsigned int start_bitrate_bps,
36 const std::string& extension_type,
37 bool rtx,
38 bool red);
39 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000040
Stefan Holmerd20e6512016-01-12 15:51:22 +010041 size_t GetNumVideoStreams() const override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010042 size_t GetNumAudioStreams() const override;
Stefan Holmerd20e6512016-01-12 15:51:22 +010043
stefan4fbd1452015-09-28 03:57:14 -070044 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000045
stefan4fbd1452015-09-28 03:57:14 -070046 protected:
47 virtual bool PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000048
stefan092508a2015-09-29 02:26:42 -070049 void AccumulateStats(const VideoSendStream::StreamStats& stream,
50 size_t* total_packets_sent,
51 size_t* total_sent,
52 size_t* padding_sent,
53 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000054
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000055 void ReportResult(const std::string& measurement,
56 size_t value,
stefan4fbd1452015-09-28 03:57:14 -070057 const std::string& units) const;
58 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000059
stefan4fbd1452015-09-28 03:57:14 -070060 rtc::Event event_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000061 Clock* const clock_;
stefanf116bd02015-10-27 08:29:42 -070062 FakeNetworkPipe::Config forward_transport_config_;
stefanff483612015-12-21 03:14:00 -080063 const size_t num_video_streams_;
64 const size_t num_audio_streams_;
stefan4fbd1452015-09-28 03:57:14 -070065 const bool rtx_;
66 const bool red_;
mflodman86cc6ff2016-07-26 04:44:06 -070067 Call* sender_call_;
stefan4fbd1452015-09-28 03:57:14 -070068 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 08:29:42 -070069 test::PacketTransport* send_transport_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000070
71 private:
stefan4fbd1452015-09-28 03:57:14 -070072 typedef std::map<uint32_t, uint32_t> SsrcMap;
perkjfa10b552016-10-02 23:45:26 -070073 class VideoStreamFactory;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000074
stefan4fbd1452015-09-28 03:57:14 -070075 Call::Config GetSenderCallConfig() override;
stefanff483612015-12-21 03:14:00 -080076 void OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070077 VideoSendStream* send_stream,
78 const std::vector<VideoReceiveStream*>& receive_streams) override;
stefane74eef12016-01-08 06:47:13 -080079 test::PacketTransport* CreateSendTransport(Call* sender_call) override;
stefanff483612015-12-21 03:14:00 -080080 void ModifyVideoConfigs(
81 VideoSendStream::Config* send_config,
82 std::vector<VideoReceiveStream::Config>* receive_configs,
83 VideoEncoderConfig* encoder_config) override;
Stefan Holmerff2a6352016-01-14 10:00:21 +010084 void ModifyAudioConfigs(
85 AudioSendStream::Config* send_config,
86 std::vector<AudioReceiveStream::Config>* receive_configs) override;
stefan4fbd1452015-09-28 03:57:14 -070087 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000088
stefan4fbd1452015-09-28 03:57:14 -070089 static bool BitrateStatsPollingThread(void* obj);
90
91 const int start_bitrate_bps_;
92 bool start_bitrate_verified_;
93 int expected_bitrate_bps_;
94 int64_t test_start_ms_;
95 int64_t ramp_up_finished_ms_;
96
97 const std::string extension_type_;
stefanff483612015-12-21 03:14:00 -080098 std::vector<uint32_t> video_ssrcs_;
99 std::vector<uint32_t> video_rtx_ssrcs_;
100 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700101 SsrcMap rtx_ssrc_map_;
102
Peter Boström8c38e8b2015-11-26 17:45:47 +0100103 rtc::PlatformThread poller_thread_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000104};
105
stefan4fbd1452015-09-28 03:57:14 -0700106class RampUpDownUpTester : public RampUpTester {
107 public:
Stefan Holmerff2a6352016-01-14 10:00:21 +0100108 RampUpDownUpTester(size_t num_video_streams,
109 size_t num_audio_streams,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000110 unsigned int start_bitrate_bps,
Shao Changbine62202f2015-04-21 20:24:50 +0800111 const std::string& extension_type,
112 bool rtx,
113 bool red);
stefan4fbd1452015-09-28 03:57:14 -0700114 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000115
stefan4fbd1452015-09-28 03:57:14 -0700116 protected:
117 bool PollStats() override;
118
119 private:
120 static const int kHighBandwidthLimitBps = 80000;
121 static const int kExpectedHighBitrateBps = 60000;
122 static const int kLowBandwidthLimitBps = 20000;
123 static const int kExpectedLowBitrateBps = 20000;
124 enum TestStates { kFirstRampup, kLowRate, kSecondRampup };
125
126 Call::Config GetReceiverCallConfig() override;
127
128 std::string GetModifierString() const;
129 void EvolveTestState(int bitrate_bps, bool suspended);
130
stefan4fbd1452015-09-28 03:57:14 -0700131 TestStates test_state_;
132 int64_t state_start_ms_;
133 int64_t interval_start_ms_;
134 int sent_bytes_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000135};
136} // namespace webrtc
stefanff483612015-12-21 03:14:00 -0800137#endif // WEBRTC_CALL_RAMPUP_TESTS_H_