rampup_tests.h 5.2 KB

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