blob: a28e425fa8d8888b056d48b241e2c9b72b229e92 [file] [log] [blame]
Sebastian Jansson98b07e92018-09-27 13:47:01 +02001/*
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 Terelius5c2f1f02019-01-16 17:45:05 +010012
13#include <map>
Sebastian Jansson98b07e92018-09-27 13:47:01 +020014#include <memory>
15#include <string>
Bjorn Terelius5c2f1f02019-01-16 17:45:05 +010016#include <utility>
Sebastian Jansson98b07e92018-09-27 13:47:01 +020017#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"
Sebastian Jansson871ac422019-05-17 17:53:44 +020022#include "modules/congestion_controller/goog_cc/test/goog_cc_printer.h"
Sebastian Jansson800e1212018-10-22 11:49:03 +020023#include "modules/rtp_rtcp/include/rtp_header_parser.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "rtc_base/constructor_magic.h"
Sebastian Jansson105a10a2019-04-01 09:18:14 +020025#include "rtc_base/task_queue_for_test.h"
Sebastian Jansson52de8b02019-01-16 17:25:44 +010026#include "test/logging/log_writer.h"
Sebastian Jansson98b07e92018-09-27 13:47:01 +020027#include "test/scenario/column_printer.h"
Artem Titov40f51152019-01-04 15:45:01 +010028#include "test/scenario/network/network_emulation.h"
Sebastian Jansson800e1212018-10-22 11:49:03 +020029#include "test/scenario/network_node.h"
Sebastian Jansson98b07e92018-09-27 13:47:01 +020030#include "test/scenario/scenario_config.h"
Sebastian Jansson105a10a2019-04-01 09:18:14 +020031#include "test/time_controller/time_controller.h"
Sebastian Jansson98b07e92018-09-27 13:47:01 +020032
33namespace webrtc {
34
35namespace test {
36class LoggingNetworkControllerFactory
37 : public NetworkControllerFactoryInterface {
38 public:
Sebastian Jansson7ccaf892019-04-24 15:13:26 +020039 LoggingNetworkControllerFactory(LogWriterFactoryInterface* log_writer_factory,
Sebastian Jansson98b07e92018-09-27 13:47:01 +020040 TransportControllerConfig config);
41 RTC_DISALLOW_COPY_AND_ASSIGN(LoggingNetworkControllerFactory);
42 ~LoggingNetworkControllerFactory();
43 std::unique_ptr<NetworkControllerInterface> Create(
44 NetworkControllerConfig config) override;
45 TimeDelta GetProcessInterval() const override;
46 // TODO(srte): Consider using the Columnprinter interface for this.
47 void LogCongestionControllerStats(Timestamp at_time);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020048
49 private:
Sebastian Jansson871ac422019-05-17 17:53:44 +020050 GoogCcDebugFactory goog_cc_factory_;
Sebastian Janssonf0d03122018-12-18 15:53:04 +010051 NetworkControllerFactoryInterface* cc_factory_ = nullptr;
Sebastian Jansson871ac422019-05-17 17:53:44 +020052 bool print_cc_state_ = false;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020053};
54
Sebastian Jansson800e1212018-10-22 11:49:03 +020055struct CallClientFakeAudio {
56 rtc::scoped_refptr<AudioProcessing> apm;
57 rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device;
58 rtc::scoped_refptr<AudioState> audio_state;
59};
Sebastian Jansson98b07e92018-09-27 13:47:01 +020060// CallClient represents a participant in a call scenario. It is created by the
61// Scenario class and is used as sender and receiver when setting up a media
62// stream session.
Artem Titov40f51152019-01-04 15:45:01 +010063class CallClient : public EmulatedNetworkReceiverInterface {
Sebastian Jansson98b07e92018-09-27 13:47:01 +020064 public:
Sebastian Jansson105a10a2019-04-01 09:18:14 +020065 CallClient(TimeController* time_controller,
Sebastian Jansson52de8b02019-01-16 17:25:44 +010066 std::unique_ptr<LogWriterFactoryInterface> log_writer_factory,
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010067 CallClientConfig config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020068 RTC_DISALLOW_COPY_AND_ASSIGN(CallClient);
69
70 ~CallClient();
71 ColumnPrinter StatsPrinter();
72 Call::Stats GetStats();
Sebastian Jansson800e1212018-10-22 11:49:03 +020073 DataRate send_bandwidth() {
74 return DataRate::bps(GetStats().send_bandwidth_bps);
75 }
76
Artem Titov40f51152019-01-04 15:45:01 +010077 void OnPacketReceived(EmulatedIpPacket packet) override;
Sebastian Jansson52de8b02019-01-16 17:25:44 +010078 std::unique_ptr<RtcEventLogOutput> GetLogWriter(std::string name);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020079
80 private:
81 friend class Scenario;
Sebastian Jansson800e1212018-10-22 11:49:03 +020082 friend class CallClientPair;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020083 friend class SendVideoStream;
Sebastian Jansson800e1212018-10-22 11:49:03 +020084 friend class VideoStreamPair;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020085 friend class ReceiveVideoStream;
86 friend class SendAudioStream;
87 friend class ReceiveAudioStream;
Sebastian Jansson800e1212018-10-22 11:49:03 +020088 friend class AudioStreamPair;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020089 friend class NetworkNodeTransport;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020090 uint32_t GetNextVideoSsrc();
Sebastian Jansson5fbebd52019-02-20 11:16:19 +010091 uint32_t GetNextVideoLocalSsrc();
Sebastian Jansson98b07e92018-09-27 13:47:01 +020092 uint32_t GetNextAudioSsrc();
Sebastian Jansson5fbebd52019-02-20 11:16:19 +010093 uint32_t GetNextAudioLocalSsrc();
Sebastian Jansson98b07e92018-09-27 13:47:01 +020094 uint32_t GetNextRtxSsrc();
95 std::string GetNextPriorityId();
Sebastian Janssonfd201712018-11-12 16:44:16 +010096 void AddExtensions(std::vector<RtpExtension> extensions);
Sebastian Jansson105a10a2019-04-01 09:18:14 +020097 void SendTask(std::function<void()> task);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020098
Sebastian Jansson105a10a2019-04-01 09:18:14 +020099 TimeController* const time_controller_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200100 Clock* clock_;
Sebastian Jansson52de8b02019-01-16 17:25:44 +0100101 const std::unique_ptr<LogWriterFactoryInterface> log_writer_factory_;
Sebastian Jansson7ccaf892019-04-24 15:13:26 +0200102 std::unique_ptr<RtcEventLog> event_log_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200103 LoggingNetworkControllerFactory network_controller_factory_;
Sebastian Jansson800e1212018-10-22 11:49:03 +0200104 CallClientFakeAudio fake_audio_setup_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200105 std::unique_ptr<Call> call_;
Sebastian Jansson105a10a2019-04-01 09:18:14 +0200106 std::unique_ptr<NetworkNodeTransport> transport_;
107 std::unique_ptr<RtpHeaderParser> const header_parser_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200108
Artem Titov40f51152019-01-04 15:45:01 +0100109 // Stores the configured overhead per known destination endpoint. This is used
110 // to subtract the overhead before processing.
Artem Titov4cd433e2019-04-01 11:01:16 +0200111 std::map<rtc::IPAddress, DataSize> route_overhead_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200112 int next_video_ssrc_index_ = 0;
Sebastian Jansson5fbebd52019-02-20 11:16:19 +0100113 int next_video_local_ssrc_index_ = 0;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200114 int next_rtx_ssrc_index_ = 0;
115 int next_audio_ssrc_index_ = 0;
Sebastian Jansson5fbebd52019-02-20 11:16:19 +0100116 int next_audio_local_ssrc_index_ = 0;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200117 int next_priority_index_ = 0;
Sebastian Jansson800e1212018-10-22 11:49:03 +0200118 std::map<uint32_t, MediaType> ssrc_media_types_;
Sebastian Jansson105a10a2019-04-01 09:18:14 +0200119 // Defined last so it's destroyed first.
120 TaskQueueForTest task_queue_;
Sebastian Jansson800e1212018-10-22 11:49:03 +0200121};
122
123class CallClientPair {
124 public:
125 RTC_DISALLOW_COPY_AND_ASSIGN(CallClientPair);
126 ~CallClientPair();
127 CallClient* first() { return first_; }
128 CallClient* second() { return second_; }
129 std::pair<CallClient*, CallClient*> forward() { return {first(), second()}; }
130 std::pair<CallClient*, CallClient*> reverse() { return {second(), first()}; }
131
132 private:
133 friend class Scenario;
134 CallClientPair(CallClient* first, CallClient* second)
135 : first_(first), second_(second) {}
136 CallClient* const first_;
137 CallClient* const second_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200138};
139} // namespace test
140} // namespace webrtc
141
142#endif // TEST_SCENARIO_CALL_CLIENT_H_