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