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 WEBRTC_CALL_RAMPUP_TESTS_H_ 12 #define WEBRTC_CALL_RAMPUP_TESTS_H_ 13 14 #include <map> 15 #include <string> 16 #include <vector> 17 18 #include "webrtc/base/event.h" 19 #include "webrtc/call/call.h" 20 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 21 #include "webrtc/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 unsigned int start_bitrate_bps, 37 const std::string& extension_type, 38 bool rtx, 39 bool red); 40 ~RampUpTester() override; 41 42 size_t GetNumVideoStreams() const override; 43 size_t GetNumAudioStreams() const override; 44 45 void PerformTest() override; 46 47 protected: 48 virtual bool PollStats(); 49 50 void AccumulateStats(const VideoSendStream::StreamStats& stream, 51 size_t* total_packets_sent, 52 size_t* total_sent, 53 size_t* padding_sent, 54 size_t* media_sent) const; 55 56 void ReportResult(const std::string& measurement, 57 size_t value, 58 const std::string& units) const; 59 void TriggerTestDone(); 60 61 webrtc::RtcEventLogNullImpl event_log_; 62 rtc::Event event_; 63 Clock* const clock_; 64 FakeNetworkPipe::Config forward_transport_config_; 65 const size_t num_video_streams_; 66 const size_t num_audio_streams_; 67 const bool rtx_; 68 const bool red_; 69 Call* sender_call_; 70 VideoSendStream* send_stream_; 71 test::PacketTransport* send_transport_; 72 73 private: 74 typedef std::map<uint32_t, uint32_t> SsrcMap; 75 class VideoStreamFactory; 76 77 Call::Config GetSenderCallConfig() override; 78 void OnVideoStreamsCreated( 79 VideoSendStream* send_stream, 80 const std::vector<VideoReceiveStream*>& receive_streams) override; 81 test::PacketTransport* CreateSendTransport(Call* sender_call) override; 82 void ModifyVideoConfigs( 83 VideoSendStream::Config* send_config, 84 std::vector<VideoReceiveStream::Config>* receive_configs, 85 VideoEncoderConfig* encoder_config) override; 86 void ModifyAudioConfigs( 87 AudioSendStream::Config* send_config, 88 std::vector<AudioReceiveStream::Config>* receive_configs) override; 89 void OnCallsCreated(Call* sender_call, Call* receiver_call) override; 90 91 static bool BitrateStatsPollingThread(void* obj); 92 93 const int start_bitrate_bps_; 94 bool start_bitrate_verified_; 95 int expected_bitrate_bps_; 96 int64_t test_start_ms_; 97 int64_t ramp_up_finished_ms_; 98 99 const std::string extension_type_; 100 std::vector<uint32_t> video_ssrcs_; 101 std::vector<uint32_t> video_rtx_ssrcs_; 102 std::vector<uint32_t> audio_ssrcs_; 103 104 rtc::PlatformThread poller_thread_; 105 }; 106 107 class RampUpDownUpTester : public RampUpTester { 108 public: 109 RampUpDownUpTester(size_t num_video_streams, 110 size_t num_audio_streams, 111 unsigned int start_bitrate_bps, 112 const std::string& extension_type, 113 bool rtx, 114 bool red); 115 ~RampUpDownUpTester() override; 116 117 protected: 118 bool PollStats() override; 119 120 private: 121 enum TestStates { kFirstRampup, kLowRate, kSecondRampup }; 122 123 Call::Config GetReceiverCallConfig() override; 124 125 std::string GetModifierString() const; 126 int GetExpectedHighBitrate() const; 127 int GetHighLinkCapacity() const; 128 void EvolveTestState(int bitrate_bps, bool suspended); 129 130 TestStates test_state_; 131 int64_t state_start_ms_; 132 int64_t interval_start_ms_; 133 int sent_bytes_; 134 }; 135 } // namespace webrtc 136 #endif // WEBRTC_CALL_RAMPUP_TESTS_H_ 137