blob: 37d784f72675c964a3c1b629849ff41e8ee33d03 [file] [log] [blame]
ossuf515ab82016-12-07 04:52:58 -08001/*
2 * Copyright (c) 2013 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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef CALL_CALL_H_
11#define CALL_CALL_H_
ossuf515ab82016-12-07 04:52:58 -080012
zsteina5e0df62017-06-14 11:41:48 -070013#include <algorithm>
zstein7cb69d52017-05-08 11:52:38 -070014#include <memory>
ossuf515ab82016-12-07 04:52:58 -080015#include <string>
16#include <vector>
17
Henrik Boströmf4a99912020-06-11 12:07:14 +020018#include "api/adaptation/resource.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "api/media_types.h"
Tomas Gunnarssone984aa22021-04-19 09:21:06 +020020#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "call/audio_receive_stream.h"
22#include "call/audio_send_stream.h"
Paulina Hensman11b34f42018-04-09 14:24:52 +020023#include "call/call_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "call/flexfec_receive_stream.h"
Niels Möller70082872018-08-07 11:03:12 +020025#include "call/packet_receiver.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "call/rtp_transport_controller_send_interface.h"
27#include "call/video_receive_stream.h"
28#include "call/video_send_stream.h"
Sebastian Jansson896b47c2019-03-01 18:48:16 +010029#include "modules/utility/include/process_thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "rtc_base/copy_on_write_buffer.h"
Sebastian Jansson12985412018-10-15 21:06:26 +020031#include "rtc_base/network/sent_packet.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "rtc_base/network_route.h"
Tommi25c77c12020-05-25 17:44:55 +020033#include "rtc_base/ref_count.h"
ossuf515ab82016-12-07 04:52:58 -080034
35namespace webrtc {
36
Tommi25c77c12020-05-25 17:44:55 +020037// A restricted way to share the module process thread across multiple instances
38// of Call that are constructed on the same worker thread (which is what the
39// peer connection factory guarantees).
40// SharedModuleThread supports a callback that is issued when only one reference
41// remains, which is used to indicate to the original owner that the thread may
42// be discarded.
43class SharedModuleThread : public rtc::RefCountInterface {
44 protected:
45 SharedModuleThread(std::unique_ptr<ProcessThread> process_thread,
46 std::function<void()> on_one_ref_remaining);
47 friend class rtc::scoped_refptr<SharedModuleThread>;
48 ~SharedModuleThread() override;
49
50 public:
Tommi25c77c12020-05-25 17:44:55 +020051 // Allows injection of an externally created process thread.
52 static rtc::scoped_refptr<SharedModuleThread> Create(
53 std::unique_ptr<ProcessThread> process_thread,
54 std::function<void()> on_one_ref_remaining);
55
56 void EnsureStarted();
57
58 ProcessThread* process_thread();
59
60 private:
61 void AddRef() const override;
62 rtc::RefCountReleaseStatus Release() const override;
63
64 class Impl;
65 mutable std::unique_ptr<Impl> impl_;
66};
67
ossuf515ab82016-12-07 04:52:58 -080068// A Call instance can contain several send and/or receive streams. All streams
69// are assumed to have the same remote endpoint and will share bitrate estimates
70// etc.
71class Call {
72 public:
Niels Möller8366e172018-02-14 12:20:13 +010073 using Config = CallConfig;
ossuf515ab82016-12-07 04:52:58 -080074
75 struct Stats {
76 std::string ToString(int64_t time_ms) const;
77
78 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
79 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
80 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
81 int64_t pacer_delay_ms = 0;
82 int64_t rtt_ms = -1;
83 };
84
85 static Call* Create(const Call::Config& config);
Sebastian Jansson896b47c2019-03-01 18:48:16 +010086 static Call* Create(const Call::Config& config,
Tommi25c77c12020-05-25 17:44:55 +020087 rtc::scoped_refptr<SharedModuleThread> call_thread);
88 static Call* Create(const Call::Config& config,
Sebastian Jansson4e5f5ed2019-03-01 18:13:27 +010089 Clock* clock,
Tommi25c77c12020-05-25 17:44:55 +020090 rtc::scoped_refptr<SharedModuleThread> call_thread,
Danil Chapovalov359fe332019-04-01 10:46:36 +020091 std::unique_ptr<ProcessThread> pacer_thread);
ossuf515ab82016-12-07 04:52:58 -080092
93 virtual AudioSendStream* CreateAudioSendStream(
94 const AudioSendStream::Config& config) = 0;
Piotr (Peter) Slatalacc8e8bb2018-11-15 08:26:19 -080095
ossuf515ab82016-12-07 04:52:58 -080096 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
97
98 virtual AudioReceiveStream* CreateAudioReceiveStream(
99 const AudioReceiveStream::Config& config) = 0;
100 virtual void DestroyAudioReceiveStream(
101 AudioReceiveStream* receive_stream) = 0;
102
103 virtual VideoSendStream* CreateVideoSendStream(
104 VideoSendStream::Config config,
105 VideoEncoderConfig encoder_config) = 0;
Ying Wang3b790f32018-01-19 17:58:57 +0100106 virtual VideoSendStream* CreateVideoSendStream(
107 VideoSendStream::Config config,
108 VideoEncoderConfig encoder_config,
109 std::unique_ptr<FecController> fec_controller);
ossuf515ab82016-12-07 04:52:58 -0800110 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
111
112 virtual VideoReceiveStream* CreateVideoReceiveStream(
113 VideoReceiveStream::Config configuration) = 0;
114 virtual void DestroyVideoReceiveStream(
115 VideoReceiveStream* receive_stream) = 0;
116
brandtrfb45c6c2017-01-27 06:47:55 -0800117 // In order for a created VideoReceiveStream to be aware that it is
118 // protected by a FlexfecReceiveStream, the latter should be created before
119 // the former.
ossuf515ab82016-12-07 04:52:58 -0800120 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
brandtr446fcb62016-12-08 04:14:24 -0800121 const FlexfecReceiveStream::Config& config) = 0;
ossuf515ab82016-12-07 04:52:58 -0800122 virtual void DestroyFlexfecReceiveStream(
123 FlexfecReceiveStream* receive_stream) = 0;
124
Henrik Boströmf4a99912020-06-11 12:07:14 +0200125 // When a resource is overused, the Call will try to reduce the load on the
126 // sysem, for example by reducing the resolution or frame rate of encoded
127 // streams.
128 virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
129
ossuf515ab82016-12-07 04:52:58 -0800130 // All received RTP and RTCP packets for the call should be inserted to this
131 // PacketReceiver. The PacketReceiver pointer is valid as long as the
132 // Call instance exists.
133 virtual PacketReceiver* Receiver() = 0;
134
Sebastian Jansson8f83b422018-02-21 13:07:13 +0100135 // This is used to access the transport controller send instance owned by
136 // Call. The send transport controller is currently owned by Call for legacy
137 // reasons. (for instance variants of call tests are built on this assumtion)
138 // TODO(srte): Move ownership of transport controller send out of Call and
139 // remove this method interface.
140 virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0;
141
ossuf515ab82016-12-07 04:52:58 -0800142 // Returns the call statistics, such as estimated send and receive bandwidth,
143 // pacing delay, etc.
144 virtual Stats GetStats() const = 0;
145
ossuf515ab82016-12-07 04:52:58 -0800146 // TODO(skvlad): When the unbundled case with multiple streams for the same
147 // media type going over different networks is supported, track the state
148 // for each stream separately. Right now it's global per media type.
149 virtual void SignalChannelNetworkState(MediaType media,
150 NetworkState state) = 0;
151
Stefan Holmer64be7fa2018-10-04 15:21:55 +0200152 virtual void OnAudioTransportOverheadChanged(
ossuf515ab82016-12-07 04:52:58 -0800153 int transport_overhead_per_packet) = 0;
154
ossuf515ab82016-12-07 04:52:58 -0800155 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
156
Piotr (Peter) Slatala7fbfaa42019-03-18 10:31:54 -0700157 virtual void SetClientBitratePreferences(
158 const BitrateSettings& preferences) = 0;
159
Erik Språngceb44952020-09-22 11:36:35 +0200160 virtual const WebRtcKeyValueConfig& trials() const = 0;
161
Tomas Gunnarssone984aa22021-04-19 09:21:06 +0200162 virtual TaskQueueBase* network_thread() const = 0;
163 virtual TaskQueueBase* worker_thread() const = 0;
164
ossuf515ab82016-12-07 04:52:58 -0800165 virtual ~Call() {}
166};
167
168} // namespace webrtc
169
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200170#endif // CALL_CALL_H_