blob: 11451c5c825d27c22a597f386e97f8f9a1af609a [file] [log] [blame]
ossuf515ab82016-12-07 12:52:581/*
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 04:47:3110#ifndef CALL_CALL_H_
11#define CALL_CALL_H_
ossuf515ab82016-12-07 12:52:5812
zsteina5e0df62017-06-14 18:41:4813#include <algorithm>
zstein7cb69d52017-05-08 18:52:3814#include <memory>
ossuf515ab82016-12-07 12:52:5815#include <string>
16#include <vector>
17
Henrik Boströmf4a99912020-06-11 10:07:1418#include "api/adaptation/resource.h"
Steve Anton10542f22019-01-11 17:11:0019#include "api/media_types.h"
Tomas Gunnarssone984aa22021-04-19 07:21:0620#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "call/audio_receive_stream.h"
22#include "call/audio_send_stream.h"
Paulina Hensman11b34f42018-04-09 12:24:5223#include "call/call_config.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "call/flexfec_receive_stream.h"
Niels Möller70082872018-08-07 09:03:1225#include "call/packet_receiver.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3126#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 17:48:1629#include "modules/utility/include/process_thread.h"
Steve Anton10542f22019-01-11 17:11:0030#include "rtc_base/copy_on_write_buffer.h"
Sebastian Jansson12985412018-10-15 19:06:2631#include "rtc_base/network/sent_packet.h"
Steve Anton10542f22019-01-11 17:11:0032#include "rtc_base/network_route.h"
Tommi25c77c12020-05-25 15:44:5533#include "rtc_base/ref_count.h"
ossuf515ab82016-12-07 12:52:5834
35namespace webrtc {
36
Tommi25c77c12020-05-25 15:44:5537// 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.
Niels Möller6b7b2552022-01-14 08:18:2343class SharedModuleThread final {
Tommi25c77c12020-05-25 15:44:5544 public:
Tommi25c77c12020-05-25 15:44:5545 // Allows injection of an externally created process thread.
46 static rtc::scoped_refptr<SharedModuleThread> Create(
47 std::unique_ptr<ProcessThread> process_thread,
48 std::function<void()> on_one_ref_remaining);
49
50 void EnsureStarted();
51
52 ProcessThread* process_thread();
53
54 private:
Niels Möller6b7b2552022-01-14 08:18:2355 friend class rtc::scoped_refptr<SharedModuleThread>;
56 SharedModuleThread(std::unique_ptr<ProcessThread> process_thread,
57 std::function<void()> on_one_ref_remaining);
58 ~SharedModuleThread();
59
60 void AddRef() const;
61 rtc::RefCountReleaseStatus Release() const;
Tommi25c77c12020-05-25 15:44:5562
63 class Impl;
64 mutable std::unique_ptr<Impl> impl_;
65};
66
Harald Alvestrandd5f414c2022-01-24 09:11:2367// A Call represents a two-way connection carrying zero or more outgoing
68// and incoming media streams, transported over one or more RTP transports.
69
ossuf515ab82016-12-07 12:52:5870// A Call instance can contain several send and/or receive streams. All streams
71// are assumed to have the same remote endpoint and will share bitrate estimates
72// etc.
Harald Alvestrandd5f414c2022-01-24 09:11:2373
74// When using the PeerConnection API, there is an one to one relationship
75// between the PeerConnection and the Call.
76
ossuf515ab82016-12-07 12:52:5877class Call {
78 public:
Niels Möller8366e172018-02-14 11:20:1379 using Config = CallConfig;
ossuf515ab82016-12-07 12:52:5880
81 struct Stats {
82 std::string ToString(int64_t time_ms) const;
83
84 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
85 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
86 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
87 int64_t pacer_delay_ms = 0;
88 int64_t rtt_ms = -1;
89 };
90
91 static Call* Create(const Call::Config& config);
Sebastian Jansson896b47c2019-03-01 17:48:1692 static Call* Create(const Call::Config& config,
Sebastian Jansson4e5f5ed2019-03-01 17:13:2793 Clock* clock,
Tommi25c77c12020-05-25 15:44:5594 rtc::scoped_refptr<SharedModuleThread> call_thread,
Danil Chapovalov359fe332019-04-01 08:46:3695 std::unique_ptr<ProcessThread> pacer_thread);
Vojin Ilic504fc192021-05-31 12:02:2896 static Call* Create(const Call::Config& config,
97 Clock* clock,
98 rtc::scoped_refptr<SharedModuleThread> call_thread,
99 std::unique_ptr<RtpTransportControllerSendInterface>
100 transportControllerSend);
ossuf515ab82016-12-07 12:52:58101
102 virtual AudioSendStream* CreateAudioSendStream(
103 const AudioSendStream::Config& config) = 0;
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19104
ossuf515ab82016-12-07 12:52:58105 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
106
107 virtual AudioReceiveStream* CreateAudioReceiveStream(
108 const AudioReceiveStream::Config& config) = 0;
109 virtual void DestroyAudioReceiveStream(
110 AudioReceiveStream* receive_stream) = 0;
111
112 virtual VideoSendStream* CreateVideoSendStream(
113 VideoSendStream::Config config,
114 VideoEncoderConfig encoder_config) = 0;
Ying Wang3b790f32018-01-19 16:58:57115 virtual VideoSendStream* CreateVideoSendStream(
116 VideoSendStream::Config config,
117 VideoEncoderConfig encoder_config,
118 std::unique_ptr<FecController> fec_controller);
ossuf515ab82016-12-07 12:52:58119 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
120
121 virtual VideoReceiveStream* CreateVideoReceiveStream(
122 VideoReceiveStream::Config configuration) = 0;
123 virtual void DestroyVideoReceiveStream(
124 VideoReceiveStream* receive_stream) = 0;
125
brandtrfb45c6c2017-01-27 14:47:55126 // In order for a created VideoReceiveStream to be aware that it is
127 // protected by a FlexfecReceiveStream, the latter should be created before
128 // the former.
ossuf515ab82016-12-07 12:52:58129 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
brandtr446fcb62016-12-08 12:14:24130 const FlexfecReceiveStream::Config& config) = 0;
ossuf515ab82016-12-07 12:52:58131 virtual void DestroyFlexfecReceiveStream(
132 FlexfecReceiveStream* receive_stream) = 0;
133
Henrik Boströmf4a99912020-06-11 10:07:14134 // When a resource is overused, the Call will try to reduce the load on the
135 // sysem, for example by reducing the resolution or frame rate of encoded
136 // streams.
137 virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
138
ossuf515ab82016-12-07 12:52:58139 // All received RTP and RTCP packets for the call should be inserted to this
140 // PacketReceiver. The PacketReceiver pointer is valid as long as the
141 // Call instance exists.
142 virtual PacketReceiver* Receiver() = 0;
143
Sebastian Jansson8f83b422018-02-21 12:07:13144 // This is used to access the transport controller send instance owned by
145 // Call. The send transport controller is currently owned by Call for legacy
146 // reasons. (for instance variants of call tests are built on this assumtion)
147 // TODO(srte): Move ownership of transport controller send out of Call and
148 // remove this method interface.
149 virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0;
150
ossuf515ab82016-12-07 12:52:58151 // Returns the call statistics, such as estimated send and receive bandwidth,
152 // pacing delay, etc.
153 virtual Stats GetStats() const = 0;
154
ossuf515ab82016-12-07 12:52:58155 // TODO(skvlad): When the unbundled case with multiple streams for the same
156 // media type going over different networks is supported, track the state
157 // for each stream separately. Right now it's global per media type.
158 virtual void SignalChannelNetworkState(MediaType media,
159 NetworkState state) = 0;
160
Stefan Holmer64be7fa2018-10-04 13:21:55161 virtual void OnAudioTransportOverheadChanged(
ossuf515ab82016-12-07 12:52:58162 int transport_overhead_per_packet) = 0;
163
Tommi08be9ba2021-06-15 21:01:57164 // Called when a receive stream's local ssrc has changed and association with
165 // send streams needs to be updated.
166 virtual void OnLocalSsrcUpdated(AudioReceiveStream& stream,
167 uint32_t local_ssrc) = 0;
168
Tommi55107c82021-06-16 14:31:18169 virtual void OnUpdateSyncGroup(AudioReceiveStream& stream,
170 const std::string& sync_group) = 0;
171
ossuf515ab82016-12-07 12:52:58172 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
173
Piotr (Peter) Slatala7fbfaa42019-03-18 17:31:54174 virtual void SetClientBitratePreferences(
175 const BitrateSettings& preferences) = 0;
176
Erik Språngceb44952020-09-22 09:36:35177 virtual const WebRtcKeyValueConfig& trials() const = 0;
178
Tomas Gunnarssone984aa22021-04-19 07:21:06179 virtual TaskQueueBase* network_thread() const = 0;
180 virtual TaskQueueBase* worker_thread() const = 0;
181
ossuf515ab82016-12-07 12:52:58182 virtual ~Call() {}
183};
184
185} // namespace webrtc
186
Mirko Bonadei92ea95e2017-09-15 04:47:31187#endif // CALL_CALL_H_