You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
6.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2018 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 TEST_SCENARIO_CALL_CLIENT_H_
  11. #define TEST_SCENARIO_CALL_CLIENT_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 "call/call.h"
  19. #include "modules/audio_device/include/test_audio_device.h"
  20. #include "modules/congestion_controller/goog_cc/test/goog_cc_printer.h"
  21. #include "rtc_base/constructor_magic.h"
  22. #include "rtc_base/task_queue_for_test.h"
  23. #include "test/logging/log_writer.h"
  24. #include "test/network/network_emulation.h"
  25. #include "test/rtp_header_parser.h"
  26. #include "test/scenario/column_printer.h"
  27. #include "test/scenario/network_node.h"
  28. #include "test/scenario/scenario_config.h"
  29. #include "test/time_controller/time_controller.h"
  30. namespace webrtc {
  31. namespace test {
  32. // Helper class to capture network controller state.
  33. class NetworkControleUpdateCache : public NetworkControllerInterface {
  34. public:
  35. explicit NetworkControleUpdateCache(
  36. std::unique_ptr<NetworkControllerInterface> controller);
  37. NetworkControlUpdate OnNetworkAvailability(NetworkAvailability msg) override;
  38. NetworkControlUpdate OnNetworkRouteChange(NetworkRouteChange msg) override;
  39. NetworkControlUpdate OnProcessInterval(ProcessInterval msg) override;
  40. NetworkControlUpdate OnRemoteBitrateReport(RemoteBitrateReport msg) override;
  41. NetworkControlUpdate OnRoundTripTimeUpdate(RoundTripTimeUpdate msg) override;
  42. NetworkControlUpdate OnSentPacket(SentPacket msg) override;
  43. NetworkControlUpdate OnReceivedPacket(ReceivedPacket msg) override;
  44. NetworkControlUpdate OnStreamsConfig(StreamsConfig msg) override;
  45. NetworkControlUpdate OnTargetRateConstraints(
  46. TargetRateConstraints msg) override;
  47. NetworkControlUpdate OnTransportLossReport(TransportLossReport msg) override;
  48. NetworkControlUpdate OnTransportPacketsFeedback(
  49. TransportPacketsFeedback msg) override;
  50. NetworkControlUpdate OnNetworkStateEstimate(
  51. NetworkStateEstimate msg) override;
  52. NetworkControlUpdate update_state() const;
  53. private:
  54. NetworkControlUpdate Update(NetworkControlUpdate update);
  55. const std::unique_ptr<NetworkControllerInterface> controller_;
  56. NetworkControlUpdate update_state_;
  57. };
  58. class LoggingNetworkControllerFactory
  59. : public NetworkControllerFactoryInterface {
  60. public:
  61. LoggingNetworkControllerFactory(LogWriterFactoryInterface* log_writer_factory,
  62. TransportControllerConfig config);
  63. RTC_DISALLOW_COPY_AND_ASSIGN(LoggingNetworkControllerFactory);
  64. ~LoggingNetworkControllerFactory();
  65. std::unique_ptr<NetworkControllerInterface> Create(
  66. NetworkControllerConfig config) override;
  67. TimeDelta GetProcessInterval() const override;
  68. // TODO(srte): Consider using the Columnprinter interface for this.
  69. void LogCongestionControllerStats(Timestamp at_time);
  70. NetworkControlUpdate GetUpdate() const;
  71. private:
  72. GoogCcDebugFactory goog_cc_factory_;
  73. NetworkControllerFactoryInterface* cc_factory_ = nullptr;
  74. bool print_cc_state_ = false;
  75. NetworkControleUpdateCache* last_controller_ = nullptr;
  76. };
  77. struct CallClientFakeAudio {
  78. rtc::scoped_refptr<AudioProcessing> apm;
  79. rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device;
  80. rtc::scoped_refptr<AudioState> audio_state;
  81. };
  82. // CallClient represents a participant in a call scenario. It is created by the
  83. // Scenario class and is used as sender and receiver when setting up a media
  84. // stream session.
  85. class CallClient : public EmulatedNetworkReceiverInterface {
  86. public:
  87. CallClient(TimeController* time_controller,
  88. std::unique_ptr<LogWriterFactoryInterface> log_writer_factory,
  89. CallClientConfig config);
  90. RTC_DISALLOW_COPY_AND_ASSIGN(CallClient);
  91. ~CallClient();
  92. ColumnPrinter StatsPrinter();
  93. Call::Stats GetStats();
  94. DataRate send_bandwidth() {
  95. return DataRate::bps(GetStats().send_bandwidth_bps);
  96. }
  97. DataRate target_rate() const;
  98. DataRate stable_target_rate() const;
  99. DataRate padding_rate() const;
  100. void OnPacketReceived(EmulatedIpPacket packet) override;
  101. std::unique_ptr<RtcEventLogOutput> GetLogWriter(std::string name);
  102. private:
  103. friend class Scenario;
  104. friend class CallClientPair;
  105. friend class SendVideoStream;
  106. friend class VideoStreamPair;
  107. friend class ReceiveVideoStream;
  108. friend class SendAudioStream;
  109. friend class ReceiveAudioStream;
  110. friend class AudioStreamPair;
  111. friend class NetworkNodeTransport;
  112. uint32_t GetNextVideoSsrc();
  113. uint32_t GetNextVideoLocalSsrc();
  114. uint32_t GetNextAudioSsrc();
  115. uint32_t GetNextAudioLocalSsrc();
  116. uint32_t GetNextRtxSsrc();
  117. void AddExtensions(std::vector<RtpExtension> extensions);
  118. void SendTask(std::function<void()> task);
  119. TimeController* const time_controller_;
  120. Clock* clock_;
  121. const std::unique_ptr<LogWriterFactoryInterface> log_writer_factory_;
  122. std::unique_ptr<RtcEventLog> event_log_;
  123. LoggingNetworkControllerFactory network_controller_factory_;
  124. CallClientFakeAudio fake_audio_setup_;
  125. std::unique_ptr<Call> call_;
  126. std::unique_ptr<NetworkNodeTransport> transport_;
  127. std::unique_ptr<RtpHeaderParser> const header_parser_;
  128. // Stores the configured overhead per known destination endpoint. This is used
  129. // to subtract the overhead before processing.
  130. std::map<rtc::IPAddress, DataSize> route_overhead_;
  131. int next_video_ssrc_index_ = 0;
  132. int next_video_local_ssrc_index_ = 0;
  133. int next_rtx_ssrc_index_ = 0;
  134. int next_audio_ssrc_index_ = 0;
  135. int next_audio_local_ssrc_index_ = 0;
  136. std::map<uint32_t, MediaType> ssrc_media_types_;
  137. // Defined last so it's destroyed first.
  138. TaskQueueForTest task_queue_;
  139. };
  140. class CallClientPair {
  141. public:
  142. RTC_DISALLOW_COPY_AND_ASSIGN(CallClientPair);
  143. ~CallClientPair();
  144. CallClient* first() { return first_; }
  145. CallClient* second() { return second_; }
  146. std::pair<CallClient*, CallClient*> forward() { return {first(), second()}; }
  147. std::pair<CallClient*, CallClient*> reverse() { return {second(), first()}; }
  148. private:
  149. friend class Scenario;
  150. CallClientPair(CallClient* first, CallClient* second)
  151. : first_(first), second_(second) {}
  152. CallClient* const first_;
  153. CallClient* const second_;
  154. };
  155. } // namespace test
  156. } // namespace webrtc
  157. #endif // TEST_SCENARIO_CALL_CLIENT_H_