blob: 69b7237116c1e48dadb37efe7521b278965e9b9f [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_
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 Jansson800e1212018-10-22 11:49:03 +020020#include "modules/rtp_rtcp/include/rtp_header_parser.h"
Sebastian Jansson98b07e92018-09-27 13:47:01 +020021#include "rtc_base/constructormagic.h"
22#include "test/scenario/column_printer.h"
Sebastian Jansson800e1212018-10-22 11:49:03 +020023#include "test/scenario/network_node.h"
Sebastian Jansson98b07e92018-09-27 13:47:01 +020024#include "test/scenario/scenario_config.h"
25
26namespace webrtc {
27
28namespace test {
29class LoggingNetworkControllerFactory
30 : public NetworkControllerFactoryInterface {
31 public:
32 LoggingNetworkControllerFactory(std::string filename,
33 TransportControllerConfig config);
34 RTC_DISALLOW_COPY_AND_ASSIGN(LoggingNetworkControllerFactory);
35 ~LoggingNetworkControllerFactory();
36 std::unique_ptr<NetworkControllerInterface> Create(
37 NetworkControllerConfig config) override;
38 TimeDelta GetProcessInterval() const override;
39 // TODO(srte): Consider using the Columnprinter interface for this.
40 void LogCongestionControllerStats(Timestamp at_time);
41 RtcEventLog* GetEventLog() const;
42
43 private:
44 std::unique_ptr<RtcEventLog> event_log_;
Sebastian Janssonf0d03122018-12-18 15:53:04 +010045 std::unique_ptr<NetworkControllerFactoryInterface> owned_cc_factory_;
46 NetworkControllerFactoryInterface* cc_factory_ = nullptr;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020047 std::unique_ptr<ControlStatePrinter> cc_printer_;
48 FILE* cc_out_ = nullptr;
49};
50
Sebastian Jansson800e1212018-10-22 11:49:03 +020051struct CallClientFakeAudio {
52 rtc::scoped_refptr<AudioProcessing> apm;
53 rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device;
54 rtc::scoped_refptr<AudioState> audio_state;
55};
Sebastian Jansson98b07e92018-09-27 13:47:01 +020056// CallClient represents a participant in a call scenario. It is created by the
57// Scenario class and is used as sender and receiver when setting up a media
58// stream session.
Sebastian Jansson800e1212018-10-22 11:49:03 +020059class CallClient : public NetworkReceiverInterface {
Sebastian Jansson98b07e92018-09-27 13:47:01 +020060 public:
61 CallClient(Clock* clock, std::string log_filename, CallClientConfig config);
62 RTC_DISALLOW_COPY_AND_ASSIGN(CallClient);
63
64 ~CallClient();
65 ColumnPrinter StatsPrinter();
66 Call::Stats GetStats();
Sebastian Jansson800e1212018-10-22 11:49:03 +020067 DataRate send_bandwidth() {
68 return DataRate::bps(GetStats().send_bandwidth_bps);
69 }
70
71 bool TryDeliverPacket(rtc::CopyOnWriteBuffer packet,
72 uint64_t receiver,
73 Timestamp at_time) override;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020074
75 private:
76 friend class Scenario;
Sebastian Jansson800e1212018-10-22 11:49:03 +020077 friend class CallClientPair;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020078 friend class SendVideoStream;
Sebastian Jansson800e1212018-10-22 11:49:03 +020079 friend class VideoStreamPair;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020080 friend class ReceiveVideoStream;
81 friend class SendAudioStream;
82 friend class ReceiveAudioStream;
Sebastian Jansson800e1212018-10-22 11:49:03 +020083 friend class AudioStreamPair;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020084 friend class NetworkNodeTransport;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020085 uint32_t GetNextVideoSsrc();
86 uint32_t GetNextAudioSsrc();
87 uint32_t GetNextRtxSsrc();
88 std::string GetNextPriorityId();
Sebastian Janssonfd201712018-11-12 16:44:16 +010089 void AddExtensions(std::vector<RtpExtension> extensions);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020090
91 Clock* clock_;
92 LoggingNetworkControllerFactory network_controller_factory_;
Sebastian Jansson800e1212018-10-22 11:49:03 +020093 CallClientFakeAudio fake_audio_setup_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020094 std::unique_ptr<Call> call_;
Sebastian Jansson800e1212018-10-22 11:49:03 +020095 NetworkNodeTransport transport_;
96 RtpHeaderParser* const header_parser_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020097
98 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_;
Sebastian Jansson800e1212018-10-22 11:49:03 +020099 // Stores the configured overhead per known incomming route. This is used to
100 // subtract the overhead before processing.
101 std::map<uint64_t, DataSize> route_overhead_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200102 int next_video_ssrc_index_ = 0;
103 int next_rtx_ssrc_index_ = 0;
104 int next_audio_ssrc_index_ = 0;
105 int next_priority_index_ = 0;
Sebastian Jansson800e1212018-10-22 11:49:03 +0200106 std::map<uint32_t, MediaType> ssrc_media_types_;
107};
108
109class CallClientPair {
110 public:
111 RTC_DISALLOW_COPY_AND_ASSIGN(CallClientPair);
112 ~CallClientPair();
113 CallClient* first() { return first_; }
114 CallClient* second() { return second_; }
115 std::pair<CallClient*, CallClient*> forward() { return {first(), second()}; }
116 std::pair<CallClient*, CallClient*> reverse() { return {second(), first()}; }
117
118 private:
119 friend class Scenario;
120 CallClientPair(CallClient* first, CallClient* second)
121 : first_(first), second_(second) {}
122 CallClient* const first_;
123 CallClient* const second_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200124};
125} // namespace test
126} // namespace webrtc
127
128#endif // TEST_SCENARIO_CALL_CLIENT_H_