• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
11 #ifndef CALL_RAMPUP_TESTS_H_
12 #define CALL_RAMPUP_TESTS_H_
13 
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 #include "api/rtc_event_log/rtc_event_log.h"
21 #include "api/task_queue/task_queue_base.h"
22 #include "api/test/simulated_network.h"
23 #include "call/call.h"
24 #include "call/simulated_network.h"
25 #include "rtc_base/event.h"
26 #include "rtc_base/task_utils/repeating_task.h"
27 #include "test/call_test.h"
28 
29 namespace webrtc {
30 
31 static const int kTransmissionTimeOffsetExtensionId = 6;
32 static const int kAbsSendTimeExtensionId = 7;
33 static const int kTransportSequenceNumberExtensionId = 8;
34 static const unsigned int kSingleStreamTargetBps = 1000000;
35 
36 class Clock;
37 
38 class RampUpTester : public test::EndToEndTest {
39  public:
40   RampUpTester(size_t num_video_streams,
41                size_t num_audio_streams,
42                size_t num_flexfec_streams,
43                unsigned int start_bitrate_bps,
44                int64_t min_run_time_ms,
45                const std::string& extension_type,
46                bool rtx,
47                bool red,
48                bool report_perf_stats,
49                TaskQueueBase* task_queue);
50   ~RampUpTester() override;
51 
52   size_t GetNumVideoStreams() const override;
53   size_t GetNumAudioStreams() const override;
54   size_t GetNumFlexfecStreams() const override;
55 
56   void PerformTest() override;
57 
58  protected:
59   virtual void PollStats();
60 
61   void AccumulateStats(const VideoSendStream::StreamStats& stream,
62                        size_t* total_packets_sent,
63                        size_t* total_sent,
64                        size_t* padding_sent,
65                        size_t* media_sent) const;
66 
67   void ReportResult(const std::string& measurement,
68                     size_t value,
69                     const std::string& units) const;
70   void TriggerTestDone();
71 
72   Clock* const clock_;
73   BuiltInNetworkBehaviorConfig forward_transport_config_;
74   const size_t num_video_streams_;
75   const size_t num_audio_streams_;
76   const size_t num_flexfec_streams_;
77   const bool rtx_;
78   const bool red_;
79   const bool report_perf_stats_;
80   Call* sender_call_;
81   VideoSendStream* send_stream_;
82   test::PacketTransport* send_transport_;
83   SimulatedNetwork* send_simulated_network_;
84 
85  private:
86   typedef std::map<uint32_t, uint32_t> SsrcMap;
87   class VideoStreamFactory;
88 
89   void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override;
90   void OnVideoStreamsCreated(
91       VideoSendStream* send_stream,
92       const std::vector<VideoReceiveStream*>& receive_streams) override;
93   std::unique_ptr<test::PacketTransport> CreateSendTransport(
94       TaskQueueBase* task_queue,
95       Call* sender_call) override;
96   void ModifyVideoConfigs(
97       VideoSendStream::Config* send_config,
98       std::vector<VideoReceiveStream::Config>* receive_configs,
99       VideoEncoderConfig* encoder_config) override;
100   void ModifyAudioConfigs(
101       AudioSendStream::Config* send_config,
102       std::vector<AudioReceiveStream::Config>* receive_configs) override;
103   void ModifyFlexfecConfigs(
104       std::vector<FlexfecReceiveStream::Config>* receive_configs) override;
105   void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
106 
107   const int start_bitrate_bps_;
108   const int64_t min_run_time_ms_;
109   int expected_bitrate_bps_;
110   int64_t test_start_ms_;
111   int64_t ramp_up_finished_ms_;
112 
113   const std::string extension_type_;
114   std::vector<uint32_t> video_ssrcs_;
115   std::vector<uint32_t> video_rtx_ssrcs_;
116   std::vector<uint32_t> audio_ssrcs_;
117 
118  protected:
119   TaskQueueBase* const task_queue_;
120   RepeatingTaskHandle pending_task_;
121 };
122 
123 class RampUpDownUpTester : public RampUpTester {
124  public:
125   RampUpDownUpTester(size_t num_video_streams,
126                      size_t num_audio_streams,
127                      size_t num_flexfec_streams,
128                      unsigned int start_bitrate_bps,
129                      const std::string& extension_type,
130                      bool rtx,
131                      bool red,
132                      const std::vector<int>& loss_rates,
133                      bool report_perf_stats,
134                      TaskQueueBase* task_queue);
135   ~RampUpDownUpTester() override;
136 
137  protected:
138   void PollStats() override;
139 
140  private:
141   enum TestStates {
142     kFirstRampup = 0,
143     kLowRate,
144     kSecondRampup,
145     kTestEnd,
146     kTransitionToNextState,
147   };
148 
149   void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
150 
151   std::string GetModifierString() const;
152   int GetExpectedHighBitrate() const;
153   int GetHighLinkCapacity() const;
154   size_t GetFecBytes() const;
155   bool ExpectingFec() const;
156   void EvolveTestState(int bitrate_bps, bool suspended);
157 
158   const std::vector<int> link_rates_;
159   TestStates test_state_;
160   TestStates next_state_;
161   int64_t state_start_ms_;
162   int64_t interval_start_ms_;
163   int sent_bytes_;
164   std::vector<int> loss_rates_;
165 };
166 }  // namespace webrtc
167 #endif  // CALL_RAMPUP_TESTS_H_
168