Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 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 <memory> |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "call/call.h" |
| 17 | #include "logging/rtc_event_log/rtc_event_log.h" |
| 18 | #include "modules/audio_device/include/test_audio_device.h" |
| 19 | #include "modules/congestion_controller/test/controller_printer.h" |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/include/rtp_header_parser.h" |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 21 | #include "rtc_base/constructormagic.h" |
| 22 | #include "test/scenario/column_printer.h" |
Artem Titov | 40f5115 | 2019-01-04 15:45:01 +0100 | [diff] [blame^] | 23 | #include "test/scenario/network/network_emulation.h" |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 24 | #include "test/scenario/network_node.h" |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 25 | #include "test/scenario/scenario_config.h" |
| 26 | |
| 27 | namespace webrtc { |
| 28 | |
| 29 | namespace test { |
| 30 | class LoggingNetworkControllerFactory |
| 31 | : public NetworkControllerFactoryInterface { |
| 32 | public: |
| 33 | LoggingNetworkControllerFactory(std::string filename, |
| 34 | TransportControllerConfig config); |
| 35 | RTC_DISALLOW_COPY_AND_ASSIGN(LoggingNetworkControllerFactory); |
| 36 | ~LoggingNetworkControllerFactory(); |
| 37 | std::unique_ptr<NetworkControllerInterface> Create( |
| 38 | NetworkControllerConfig config) override; |
| 39 | TimeDelta GetProcessInterval() const override; |
| 40 | // TODO(srte): Consider using the Columnprinter interface for this. |
| 41 | void LogCongestionControllerStats(Timestamp at_time); |
| 42 | RtcEventLog* GetEventLog() const; |
| 43 | |
| 44 | private: |
| 45 | std::unique_ptr<RtcEventLog> event_log_; |
Sebastian Jansson | f0d0312 | 2018-12-18 15:53:04 +0100 | [diff] [blame] | 46 | std::unique_ptr<NetworkControllerFactoryInterface> owned_cc_factory_; |
| 47 | NetworkControllerFactoryInterface* cc_factory_ = nullptr; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 48 | std::unique_ptr<ControlStatePrinter> cc_printer_; |
| 49 | FILE* cc_out_ = nullptr; |
| 50 | }; |
| 51 | |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 52 | struct CallClientFakeAudio { |
| 53 | rtc::scoped_refptr<AudioProcessing> apm; |
| 54 | rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device; |
| 55 | rtc::scoped_refptr<AudioState> audio_state; |
| 56 | }; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 57 | // CallClient represents a participant in a call scenario. It is created by the |
| 58 | // Scenario class and is used as sender and receiver when setting up a media |
| 59 | // stream session. |
Artem Titov | 40f5115 | 2019-01-04 15:45:01 +0100 | [diff] [blame^] | 60 | class CallClient : public EmulatedNetworkReceiverInterface { |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 61 | public: |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 62 | CallClient(Clock* clock, |
| 63 | std::string name, |
| 64 | std::string log_filename, |
| 65 | CallClientConfig config); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 66 | RTC_DISALLOW_COPY_AND_ASSIGN(CallClient); |
| 67 | |
| 68 | ~CallClient(); |
| 69 | ColumnPrinter StatsPrinter(); |
| 70 | Call::Stats GetStats(); |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 71 | DataRate send_bandwidth() { |
| 72 | return DataRate::bps(GetStats().send_bandwidth_bps); |
| 73 | } |
| 74 | |
Artem Titov | 40f5115 | 2019-01-04 15:45:01 +0100 | [diff] [blame^] | 75 | void OnPacketReceived(EmulatedIpPacket packet) override; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | friend class Scenario; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 79 | friend class CallClientPair; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 80 | friend class SendVideoStream; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 81 | friend class VideoStreamPair; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 82 | friend class ReceiveVideoStream; |
| 83 | friend class SendAudioStream; |
| 84 | friend class ReceiveAudioStream; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 85 | friend class AudioStreamPair; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 86 | friend class NetworkNodeTransport; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 87 | uint32_t GetNextVideoSsrc(); |
| 88 | uint32_t GetNextAudioSsrc(); |
| 89 | uint32_t GetNextRtxSsrc(); |
| 90 | std::string GetNextPriorityId(); |
Sebastian Jansson | fd20171 | 2018-11-12 16:44:16 +0100 | [diff] [blame] | 91 | void AddExtensions(std::vector<RtpExtension> extensions); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 92 | |
| 93 | Clock* clock_; |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 94 | const std::string name_; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 95 | LoggingNetworkControllerFactory network_controller_factory_; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 96 | CallClientFakeAudio fake_audio_setup_; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 97 | std::unique_ptr<Call> call_; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 98 | NetworkNodeTransport transport_; |
| 99 | RtpHeaderParser* const header_parser_; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 100 | |
| 101 | std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_; |
Artem Titov | 40f5115 | 2019-01-04 15:45:01 +0100 | [diff] [blame^] | 102 | // Stores the configured overhead per known destination endpoint. This is used |
| 103 | // to subtract the overhead before processing. |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 104 | std::map<uint64_t, DataSize> route_overhead_; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 105 | int next_video_ssrc_index_ = 0; |
| 106 | int next_rtx_ssrc_index_ = 0; |
| 107 | int next_audio_ssrc_index_ = 0; |
| 108 | int next_priority_index_ = 0; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 109 | std::map<uint32_t, MediaType> ssrc_media_types_; |
| 110 | }; |
| 111 | |
| 112 | class CallClientPair { |
| 113 | public: |
| 114 | RTC_DISALLOW_COPY_AND_ASSIGN(CallClientPair); |
| 115 | ~CallClientPair(); |
| 116 | CallClient* first() { return first_; } |
| 117 | CallClient* second() { return second_; } |
| 118 | std::pair<CallClient*, CallClient*> forward() { return {first(), second()}; } |
| 119 | std::pair<CallClient*, CallClient*> reverse() { return {second(), first()}; } |
| 120 | |
| 121 | private: |
| 122 | friend class Scenario; |
| 123 | CallClientPair(CallClient* first, CallClient* second) |
| 124 | : first_(first), second_(second) {} |
| 125 | CallClient* const first_; |
| 126 | CallClient* const second_; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 127 | }; |
| 128 | } // namespace test |
| 129 | } // namespace webrtc |
| 130 | |
| 131 | #endif // TEST_SCENARIO_CALL_CLIENT_H_ |