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 <string> 16 #include <vector> 17 18 #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" 22 23 namespace webrtc { 24 25 static const int kTransmissionTimeOffsetExtensionId = 6; 26 static const int kAbsSendTimeExtensionId = 7; 27 static const int kTransportSequenceNumberExtensionId = 8; 28 static const unsigned int kSingleStreamTargetBps = 1000000; 29 30 class Clock; 31 32 class RampUpTester : public test::EndToEndTest { 33 public: 34 RampUpTester(size_t num_video_streams, 35 size_t num_audio_streams, 36 size_t num_flexfec_streams, 37 unsigned int start_bitrate_bps, 38 int64_t min_run_time_ms, 39 const std::string& extension_type, 40 bool rtx, 41 bool red, 42 bool report_perf_stats); 43 ~RampUpTester() override; 44 45 size_t GetNumVideoStreams() const override; 46 size_t GetNumAudioStreams() const override; 47 size_t GetNumFlexfecStreams() const override; 48 49 void PerformTest() override; 50 51 protected: 52 virtual void PollStats(); 53 54 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; 59 60 void ReportResult(const std::string& measurement, 61 size_t value, 62 const std::string& units) const; 63 void TriggerTestDone(); 64 65 webrtc::RtcEventLogNullImpl event_log_; 66 rtc::Event stop_event_; 67 Clock* const clock_; 68 FakeNetworkPipe::Config forward_transport_config_; 69 const size_t num_video_streams_; 70 const size_t num_audio_streams_; 71 const size_t num_flexfec_streams_; 72 const bool rtx_; 73 const bool red_; 74 const bool report_perf_stats_; 75 Call* sender_call_; 76 VideoSendStream* send_stream_; 77 test::PacketTransport* send_transport_; 78 79 private: 80 typedef std::map<uint32_t, uint32_t> SsrcMap; 81 class VideoStreamFactory; 82 83 Call::Config GetSenderCallConfig() override; 84 void OnVideoStreamsCreated( 85 VideoSendStream* send_stream, 86 const std::vector<VideoReceiveStream*>& receive_streams) override; 87 test::PacketTransport* CreateSendTransport( 88 test::SingleThreadedTaskQueueForTesting* task_queue, 89 Call* sender_call) override; 90 void ModifyVideoConfigs( 91 VideoSendStream::Config* send_config, 92 std::vector<VideoReceiveStream::Config>* receive_configs, 93 VideoEncoderConfig* encoder_config) override; 94 void ModifyAudioConfigs( 95 AudioSendStream::Config* send_config, 96 std::vector<AudioReceiveStream::Config>* receive_configs) override; 97 void ModifyFlexfecConfigs( 98 std::vector<FlexfecReceiveStream::Config>* receive_configs) override; 99 void OnCallsCreated(Call* sender_call, Call* receiver_call) override; 100 101 static void BitrateStatsPollingThread(void* obj); 102 103 const int start_bitrate_bps_; 104 const int64_t min_run_time_ms_; 105 int expected_bitrate_bps_; 106 int64_t test_start_ms_; 107 int64_t ramp_up_finished_ms_; 108 109 const std::string extension_type_; 110 std::vector<uint32_t> video_ssrcs_; 111 std::vector<uint32_t> video_rtx_ssrcs_; 112 std::vector<uint32_t> audio_ssrcs_; 113 114 rtc::PlatformThread poller_thread_; 115 }; 116 117 class RampUpDownUpTester : public RampUpTester { 118 public: 119 RampUpDownUpTester(size_t num_video_streams, 120 size_t num_audio_streams, 121 size_t num_flexfec_streams, 122 unsigned int start_bitrate_bps, 123 const std::string& extension_type, 124 bool rtx, 125 bool red, 126 const std::vector<int>& loss_rates, 127 bool report_perf_stats); 128 ~RampUpDownUpTester() override; 129 130 protected: 131 void PollStats() override; 132 133 private: 134 enum TestStates { 135 kFirstRampup = 0, 136 kLowRate, 137 kSecondRampup, 138 kTestEnd, 139 kTransitionToNextState, 140 }; 141 142 Call::Config GetReceiverCallConfig() override; 143 144 std::string GetModifierString() const; 145 int GetExpectedHighBitrate() const; 146 int GetHighLinkCapacity() const; 147 size_t GetFecBytes() const; 148 bool ExpectingFec() const; 149 void EvolveTestState(int bitrate_bps, bool suspended); 150 151 const std::vector<int> link_rates_; 152 TestStates test_state_; 153 TestStates next_state_; 154 int64_t state_start_ms_; 155 int64_t interval_start_ms_; 156 int sent_bytes_; 157 std::vector<int> loss_rates_; 158 }; 159 } // namespace webrtc 160 #endif // CALL_RAMPUP_TESTS_H_ 161