blob: 561ed0ddea68bc8af0d9b4a3bc110bb8f0533f6c [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"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000019#include "webrtc/base/scoped_ptr.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000020#include "webrtc/call.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,
37 const std::string& extension_type,
38 bool rtx,
39 bool red);
40 ~RampUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000041
stefan4fbd1452015-09-28 03:57:14 -070042 void PerformTest() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000043
stefan4fbd1452015-09-28 03:57:14 -070044 protected:
45 virtual bool PollStats();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000046
stefan092508a2015-09-29 02:26:42 -070047 void AccumulateStats(const VideoSendStream::StreamStats& stream,
48 size_t* total_packets_sent,
49 size_t* total_sent,
50 size_t* padding_sent,
51 size_t* media_sent) const;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000052
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000053 void ReportResult(const std::string& measurement,
54 size_t value,
stefan4fbd1452015-09-28 03:57:14 -070055 const std::string& units) const;
56 void TriggerTestDone();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000057
stefan4fbd1452015-09-28 03:57:14 -070058 rtc::Event event_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000059 Clock* const clock_;
stefanf116bd02015-10-27 08:29:42 -070060 FakeNetworkPipe::Config forward_transport_config_;
stefanff483612015-12-21 03:14:00 -080061 const size_t num_video_streams_;
62 const size_t num_audio_streams_;
stefan4fbd1452015-09-28 03:57:14 -070063 const bool rtx_;
64 const bool red_;
65 VideoSendStream* send_stream_;
stefanf116bd02015-10-27 08:29:42 -070066 test::PacketTransport* send_transport_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000067
68 private:
stefan4fbd1452015-09-28 03:57:14 -070069 typedef std::map<uint32_t, uint32_t> SsrcMap;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000070
stefan4fbd1452015-09-28 03:57:14 -070071 Call::Config GetSenderCallConfig() override;
stefanff483612015-12-21 03:14:00 -080072 void OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070073 VideoSendStream* send_stream,
74 const std::vector<VideoReceiveStream*>& receive_streams) override;
stefanf116bd02015-10-27 08:29:42 -070075 void OnTransportsCreated(test::PacketTransport* send_transport,
76 test::PacketTransport* receive_transport) override;
stefanff483612015-12-21 03:14:00 -080077 void ModifyVideoConfigs(
78 VideoSendStream::Config* send_config,
79 std::vector<VideoReceiveStream::Config>* receive_configs,
80 VideoEncoderConfig* encoder_config) override;
stefan4fbd1452015-09-28 03:57:14 -070081 void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000082
stefan4fbd1452015-09-28 03:57:14 -070083 static bool BitrateStatsPollingThread(void* obj);
84
85 const int start_bitrate_bps_;
86 bool start_bitrate_verified_;
87 int expected_bitrate_bps_;
88 int64_t test_start_ms_;
89 int64_t ramp_up_finished_ms_;
90
91 const std::string extension_type_;
stefanff483612015-12-21 03:14:00 -080092 std::vector<uint32_t> video_ssrcs_;
93 std::vector<uint32_t> video_rtx_ssrcs_;
94 std::vector<uint32_t> audio_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -070095 SsrcMap rtx_ssrc_map_;
96
Peter Boström8c38e8b2015-11-26 17:45:47 +010097 rtc::PlatformThread poller_thread_;
stefan4fbd1452015-09-28 03:57:14 -070098 Call* sender_call_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000099};
100
stefan4fbd1452015-09-28 03:57:14 -0700101class RampUpDownUpTester : public RampUpTester {
102 public:
103 RampUpDownUpTester(size_t num_streams,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000104 unsigned int start_bitrate_bps,
Shao Changbine62202f2015-04-21 20:24:50 +0800105 const std::string& extension_type,
106 bool rtx,
107 bool red);
stefan4fbd1452015-09-28 03:57:14 -0700108 ~RampUpDownUpTester() override;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000109
stefan4fbd1452015-09-28 03:57:14 -0700110 protected:
111 bool PollStats() override;
112
113 private:
114 static const int kHighBandwidthLimitBps = 80000;
115 static const int kExpectedHighBitrateBps = 60000;
116 static const int kLowBandwidthLimitBps = 20000;
117 static const int kExpectedLowBitrateBps = 20000;
118 enum TestStates { kFirstRampup, kLowRate, kSecondRampup };
119
120 Call::Config GetReceiverCallConfig() override;
121
122 std::string GetModifierString() const;
123 void EvolveTestState(int bitrate_bps, bool suspended);
124
stefan4fbd1452015-09-28 03:57:14 -0700125 TestStates test_state_;
126 int64_t state_start_ms_;
127 int64_t interval_start_ms_;
128 int sent_bytes_;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000129};
130} // namespace webrtc
stefanff483612015-12-21 03:14:00 -0800131#endif // WEBRTC_CALL_RAMPUP_TESTS_H_