blob: bdbf7bd29a535c4ba45293879366ee7f53154107 [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
Ali Tofigh641a1b12022-05-17 11:48:46 +020018#include "absl/strings/string_view.h"
Henrik Boströmf4a99912020-06-11 12:07:14 +020019#include "api/adaptation/resource.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/media_types.h"
Tomas Gunnarssone984aa22021-04-19 09:21:06 +020021#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "call/audio_receive_stream.h"
23#include "call/audio_send_stream.h"
Paulina Hensman11b34f42018-04-09 14:24:52 +020024#include "call/call_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "call/flexfec_receive_stream.h"
Niels Möller70082872018-08-07 11:03:12 +020026#include "call/packet_receiver.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "call/rtp_transport_controller_send_interface.h"
28#include "call/video_receive_stream.h"
29#include "call/video_send_stream.h"
Sebastian Jansson896b47c2019-03-01 18:48:16 +010030#include "modules/utility/include/process_thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "rtc_base/copy_on_write_buffer.h"
Sebastian Jansson12985412018-10-15 21:06:26 +020032#include "rtc_base/network/sent_packet.h"
Steve Anton10542f22019-01-11 09:11:00 -080033#include "rtc_base/network_route.h"
Tommi25c77c12020-05-25 17:44:55 +020034#include "rtc_base/ref_count.h"
ossuf515ab82016-12-07 04:52:58 -080035
36namespace webrtc {
37
Tommi25c77c12020-05-25 17:44:55 +020038// A restricted way to share the module process thread across multiple instances
39// of Call that are constructed on the same worker thread (which is what the
40// peer connection factory guarantees).
41// SharedModuleThread supports a callback that is issued when only one reference
42// remains, which is used to indicate to the original owner that the thread may
43// be discarded.
Niels Möller6b7b2552022-01-14 09:18:23 +010044class SharedModuleThread final {
Tommi25c77c12020-05-25 17:44:55 +020045 public:
Tommi25c77c12020-05-25 17:44:55 +020046 // Allows injection of an externally created process thread.
47 static rtc::scoped_refptr<SharedModuleThread> Create(
48 std::unique_ptr<ProcessThread> process_thread,
49 std::function<void()> on_one_ref_remaining);
50
51 void EnsureStarted();
52
53 ProcessThread* process_thread();
54
55 private:
Niels Möller6b7b2552022-01-14 09:18:23 +010056 friend class rtc::scoped_refptr<SharedModuleThread>;
57 SharedModuleThread(std::unique_ptr<ProcessThread> process_thread,
58 std::function<void()> on_one_ref_remaining);
59 ~SharedModuleThread();
60
61 void AddRef() const;
62 rtc::RefCountReleaseStatus Release() const;
Tommi25c77c12020-05-25 17:44:55 +020063
64 class Impl;
65 mutable std::unique_ptr<Impl> impl_;
66};
67
Harald Alvestrandd5f414c2022-01-24 09:11:23 +000068// A Call represents a two-way connection carrying zero or more outgoing
69// and incoming media streams, transported over one or more RTP transports.
70
ossuf515ab82016-12-07 04:52:58 -080071// A Call instance can contain several send and/or receive streams. All streams
72// are assumed to have the same remote endpoint and will share bitrate estimates
73// etc.
Harald Alvestrandd5f414c2022-01-24 09:11:23 +000074
75// When using the PeerConnection API, there is an one to one relationship
76// between the PeerConnection and the Call.
77
ossuf515ab82016-12-07 04:52:58 -080078class Call {
79 public:
Niels Möller8366e172018-02-14 12:20:13 +010080 using Config = CallConfig;
ossuf515ab82016-12-07 04:52:58 -080081
82 struct Stats {
83 std::string ToString(int64_t time_ms) const;
84
85 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
86 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
87 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
88 int64_t pacer_delay_ms = 0;
89 int64_t rtt_ms = -1;
90 };
91
92 static Call* Create(const Call::Config& config);
Sebastian Jansson896b47c2019-03-01 18:48:16 +010093 static Call* Create(const Call::Config& config,
Sebastian Jansson4e5f5ed2019-03-01 18:13:27 +010094 Clock* clock,
Tommi25c77c12020-05-25 17:44:55 +020095 rtc::scoped_refptr<SharedModuleThread> call_thread,
Danil Chapovalov359fe332019-04-01 10:46:36 +020096 std::unique_ptr<ProcessThread> pacer_thread);
Vojin Ilic504fc192021-05-31 14:02:28 +020097 static Call* Create(const Call::Config& config,
98 Clock* clock,
99 rtc::scoped_refptr<SharedModuleThread> call_thread,
100 std::unique_ptr<RtpTransportControllerSendInterface>
101 transportControllerSend);
ossuf515ab82016-12-07 04:52:58 -0800102
103 virtual AudioSendStream* CreateAudioSendStream(
104 const AudioSendStream::Config& config) = 0;
Piotr (Peter) Slatalacc8e8bb2018-11-15 08:26:19 -0800105
ossuf515ab82016-12-07 04:52:58 -0800106 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
107
108 virtual AudioReceiveStream* CreateAudioReceiveStream(
109 const AudioReceiveStream::Config& config) = 0;
110 virtual void DestroyAudioReceiveStream(
111 AudioReceiveStream* receive_stream) = 0;
112
113 virtual VideoSendStream* CreateVideoSendStream(
114 VideoSendStream::Config config,
115 VideoEncoderConfig encoder_config) = 0;
Ying Wang3b790f32018-01-19 17:58:57 +0100116 virtual VideoSendStream* CreateVideoSendStream(
117 VideoSendStream::Config config,
118 VideoEncoderConfig encoder_config,
119 std::unique_ptr<FecController> fec_controller);
ossuf515ab82016-12-07 04:52:58 -0800120 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
121
Tommif6f45432022-05-20 15:21:20 +0200122 virtual VideoReceiveStreamInterface* CreateVideoReceiveStream(
123 VideoReceiveStreamInterface::Config configuration) = 0;
ossuf515ab82016-12-07 04:52:58 -0800124 virtual void DestroyVideoReceiveStream(
Tommif6f45432022-05-20 15:21:20 +0200125 VideoReceiveStreamInterface* receive_stream) = 0;
ossuf515ab82016-12-07 04:52:58 -0800126
Tommif6f45432022-05-20 15:21:20 +0200127 // In order for a created VideoReceiveStreamInterface to be aware that it is
brandtrfb45c6c2017-01-27 06:47:55 -0800128 // protected by a FlexfecReceiveStream, the latter should be created before
129 // the former.
ossuf515ab82016-12-07 04:52:58 -0800130 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
Tommicf4ed152022-05-09 20:46:57 +0000131 const FlexfecReceiveStream::Config config) = 0;
ossuf515ab82016-12-07 04:52:58 -0800132 virtual void DestroyFlexfecReceiveStream(
133 FlexfecReceiveStream* receive_stream) = 0;
134
Henrik Boströmf4a99912020-06-11 12:07:14 +0200135 // When a resource is overused, the Call will try to reduce the load on the
136 // sysem, for example by reducing the resolution or frame rate of encoded
137 // streams.
138 virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
139
ossuf515ab82016-12-07 04:52:58 -0800140 // All received RTP and RTCP packets for the call should be inserted to this
141 // PacketReceiver. The PacketReceiver pointer is valid as long as the
142 // Call instance exists.
143 virtual PacketReceiver* Receiver() = 0;
144
Sebastian Jansson8f83b422018-02-21 13:07:13 +0100145 // This is used to access the transport controller send instance owned by
146 // Call. The send transport controller is currently owned by Call for legacy
147 // reasons. (for instance variants of call tests are built on this assumtion)
148 // TODO(srte): Move ownership of transport controller send out of Call and
149 // remove this method interface.
150 virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0;
151
ossuf515ab82016-12-07 04:52:58 -0800152 // Returns the call statistics, such as estimated send and receive bandwidth,
153 // pacing delay, etc.
154 virtual Stats GetStats() const = 0;
155
ossuf515ab82016-12-07 04:52:58 -0800156 // TODO(skvlad): When the unbundled case with multiple streams for the same
157 // media type going over different networks is supported, track the state
158 // for each stream separately. Right now it's global per media type.
159 virtual void SignalChannelNetworkState(MediaType media,
160 NetworkState state) = 0;
161
Stefan Holmer64be7fa2018-10-04 15:21:55 +0200162 virtual void OnAudioTransportOverheadChanged(
ossuf515ab82016-12-07 04:52:58 -0800163 int transport_overhead_per_packet) = 0;
164
Tommi08be9ba2021-06-15 23:01:57 +0200165 // Called when a receive stream's local ssrc has changed and association with
166 // send streams needs to be updated.
167 virtual void OnLocalSsrcUpdated(AudioReceiveStream& stream,
168 uint32_t local_ssrc) = 0;
Tommif6f45432022-05-20 15:21:20 +0200169 virtual void OnLocalSsrcUpdated(VideoReceiveStreamInterface& stream,
Tommi1331c182022-05-17 10:13:52 +0200170 uint32_t local_ssrc) = 0;
171 virtual void OnLocalSsrcUpdated(FlexfecReceiveStream& stream,
172 uint32_t local_ssrc) = 0;
Tommi08be9ba2021-06-15 23:01:57 +0200173
Tommi55107c82021-06-16 16:31:18 +0200174 virtual void OnUpdateSyncGroup(AudioReceiveStream& stream,
Ali Tofigh641a1b12022-05-17 11:48:46 +0200175 absl::string_view sync_group) = 0;
Tommi55107c82021-06-16 16:31:18 +0200176
ossuf515ab82016-12-07 04:52:58 -0800177 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
178
Piotr (Peter) Slatala7fbfaa42019-03-18 10:31:54 -0700179 virtual void SetClientBitratePreferences(
180 const BitrateSettings& preferences) = 0;
181
Jonas Orelande62c2f22022-03-29 11:04:48 +0200182 virtual const FieldTrialsView& trials() const = 0;
Erik Språngceb44952020-09-22 11:36:35 +0200183
Tomas Gunnarssone984aa22021-04-19 09:21:06 +0200184 virtual TaskQueueBase* network_thread() const = 0;
185 virtual TaskQueueBase* worker_thread() const = 0;
186
ossuf515ab82016-12-07 04:52:58 -0800187 virtual ~Call() {}
188};
189
190} // namespace webrtc
191
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200192#endif // CALL_CALL_H_