ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #ifndef CALL_CALL_H_ |
| 11 | #define CALL_CALL_H_ |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 12 | |
zstein | a5e0df6 | 2017-06-14 11:41:48 -0700 | [diff] [blame] | 13 | #include <algorithm> |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame] | 14 | #include <memory> |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Henrik Boström | f4a9991 | 2020-06-11 12:07:14 +0200 | [diff] [blame] | 18 | #include "api/adaptation/resource.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "api/media_types.h" |
Tomas Gunnarsson | e984aa2 | 2021-04-19 09:21:06 +0200 | [diff] [blame] | 20 | #include "api/task_queue/task_queue_base.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "call/audio_receive_stream.h" |
| 22 | #include "call/audio_send_stream.h" |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 23 | #include "call/call_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "call/flexfec_receive_stream.h" |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 25 | #include "call/packet_receiver.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "call/rtp_transport_controller_send_interface.h" |
| 27 | #include "call/video_receive_stream.h" |
| 28 | #include "call/video_send_stream.h" |
Sebastian Jansson | 896b47c | 2019-03-01 18:48:16 +0100 | [diff] [blame] | 29 | #include "modules/utility/include/process_thread.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "rtc_base/copy_on_write_buffer.h" |
Sebastian Jansson | 1298541 | 2018-10-15 21:06:26 +0200 | [diff] [blame] | 31 | #include "rtc_base/network/sent_packet.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 32 | #include "rtc_base/network_route.h" |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 33 | #include "rtc_base/ref_count.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 34 | |
| 35 | namespace webrtc { |
| 36 | |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 37 | // 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öller | 6b7b255 | 2022-01-14 09:18:23 +0100 | [diff] [blame^] | 43 | class SharedModuleThread final { |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 44 | public: |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 45 | // 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öller | 6b7b255 | 2022-01-14 09:18:23 +0100 | [diff] [blame^] | 55 | 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; |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 62 | |
| 63 | class Impl; |
| 64 | mutable std::unique_ptr<Impl> impl_; |
| 65 | }; |
| 66 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 67 | // A Call instance can contain several send and/or receive streams. All streams |
| 68 | // are assumed to have the same remote endpoint and will share bitrate estimates |
| 69 | // etc. |
| 70 | class Call { |
| 71 | public: |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 72 | using Config = CallConfig; |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 73 | |
| 74 | struct Stats { |
| 75 | std::string ToString(int64_t time_ms) const; |
| 76 | |
| 77 | int send_bandwidth_bps = 0; // Estimated available send bandwidth. |
| 78 | int max_padding_bitrate_bps = 0; // Cumulative configured max padding. |
| 79 | int recv_bandwidth_bps = 0; // Estimated available receive bandwidth. |
| 80 | int64_t pacer_delay_ms = 0; |
| 81 | int64_t rtt_ms = -1; |
| 82 | }; |
| 83 | |
| 84 | static Call* Create(const Call::Config& config); |
Sebastian Jansson | 896b47c | 2019-03-01 18:48:16 +0100 | [diff] [blame] | 85 | static Call* Create(const Call::Config& config, |
Sebastian Jansson | 4e5f5ed | 2019-03-01 18:13:27 +0100 | [diff] [blame] | 86 | Clock* clock, |
Tommi | 25c77c1 | 2020-05-25 17:44:55 +0200 | [diff] [blame] | 87 | rtc::scoped_refptr<SharedModuleThread> call_thread, |
Danil Chapovalov | 359fe33 | 2019-04-01 10:46:36 +0200 | [diff] [blame] | 88 | std::unique_ptr<ProcessThread> pacer_thread); |
Vojin Ilic | 504fc19 | 2021-05-31 14:02:28 +0200 | [diff] [blame] | 89 | static Call* Create(const Call::Config& config, |
| 90 | Clock* clock, |
| 91 | rtc::scoped_refptr<SharedModuleThread> call_thread, |
| 92 | std::unique_ptr<RtpTransportControllerSendInterface> |
| 93 | transportControllerSend); |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 94 | |
| 95 | virtual AudioSendStream* CreateAudioSendStream( |
| 96 | const AudioSendStream::Config& config) = 0; |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 08:26:19 -0800 | [diff] [blame] | 97 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 98 | virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0; |
| 99 | |
| 100 | virtual AudioReceiveStream* CreateAudioReceiveStream( |
| 101 | const AudioReceiveStream::Config& config) = 0; |
| 102 | virtual void DestroyAudioReceiveStream( |
| 103 | AudioReceiveStream* receive_stream) = 0; |
| 104 | |
| 105 | virtual VideoSendStream* CreateVideoSendStream( |
| 106 | VideoSendStream::Config config, |
| 107 | VideoEncoderConfig encoder_config) = 0; |
Ying Wang | 3b790f3 | 2018-01-19 17:58:57 +0100 | [diff] [blame] | 108 | virtual VideoSendStream* CreateVideoSendStream( |
| 109 | VideoSendStream::Config config, |
| 110 | VideoEncoderConfig encoder_config, |
| 111 | std::unique_ptr<FecController> fec_controller); |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 112 | virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0; |
| 113 | |
| 114 | virtual VideoReceiveStream* CreateVideoReceiveStream( |
| 115 | VideoReceiveStream::Config configuration) = 0; |
| 116 | virtual void DestroyVideoReceiveStream( |
| 117 | VideoReceiveStream* receive_stream) = 0; |
| 118 | |
brandtr | fb45c6c | 2017-01-27 06:47:55 -0800 | [diff] [blame] | 119 | // In order for a created VideoReceiveStream to be aware that it is |
| 120 | // protected by a FlexfecReceiveStream, the latter should be created before |
| 121 | // the former. |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 122 | virtual FlexfecReceiveStream* CreateFlexfecReceiveStream( |
brandtr | 446fcb6 | 2016-12-08 04:14:24 -0800 | [diff] [blame] | 123 | const FlexfecReceiveStream::Config& config) = 0; |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 124 | virtual void DestroyFlexfecReceiveStream( |
| 125 | FlexfecReceiveStream* receive_stream) = 0; |
| 126 | |
Henrik Boström | f4a9991 | 2020-06-11 12:07:14 +0200 | [diff] [blame] | 127 | // When a resource is overused, the Call will try to reduce the load on the |
| 128 | // sysem, for example by reducing the resolution or frame rate of encoded |
| 129 | // streams. |
| 130 | virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0; |
| 131 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 132 | // All received RTP and RTCP packets for the call should be inserted to this |
| 133 | // PacketReceiver. The PacketReceiver pointer is valid as long as the |
| 134 | // Call instance exists. |
| 135 | virtual PacketReceiver* Receiver() = 0; |
| 136 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 137 | // This is used to access the transport controller send instance owned by |
| 138 | // Call. The send transport controller is currently owned by Call for legacy |
| 139 | // reasons. (for instance variants of call tests are built on this assumtion) |
| 140 | // TODO(srte): Move ownership of transport controller send out of Call and |
| 141 | // remove this method interface. |
| 142 | virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0; |
| 143 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 144 | // Returns the call statistics, such as estimated send and receive bandwidth, |
| 145 | // pacing delay, etc. |
| 146 | virtual Stats GetStats() const = 0; |
| 147 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 148 | // TODO(skvlad): When the unbundled case with multiple streams for the same |
| 149 | // media type going over different networks is supported, track the state |
| 150 | // for each stream separately. Right now it's global per media type. |
| 151 | virtual void SignalChannelNetworkState(MediaType media, |
| 152 | NetworkState state) = 0; |
| 153 | |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 154 | virtual void OnAudioTransportOverheadChanged( |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 155 | int transport_overhead_per_packet) = 0; |
| 156 | |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 157 | // Called when a receive stream's local ssrc has changed and association with |
| 158 | // send streams needs to be updated. |
| 159 | virtual void OnLocalSsrcUpdated(AudioReceiveStream& stream, |
| 160 | uint32_t local_ssrc) = 0; |
| 161 | |
Tommi | 55107c8 | 2021-06-16 16:31:18 +0200 | [diff] [blame] | 162 | virtual void OnUpdateSyncGroup(AudioReceiveStream& stream, |
| 163 | const std::string& sync_group) = 0; |
| 164 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 165 | virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0; |
| 166 | |
Piotr (Peter) Slatala | 7fbfaa4 | 2019-03-18 10:31:54 -0700 | [diff] [blame] | 167 | virtual void SetClientBitratePreferences( |
| 168 | const BitrateSettings& preferences) = 0; |
| 169 | |
Erik Språng | ceb4495 | 2020-09-22 11:36:35 +0200 | [diff] [blame] | 170 | virtual const WebRtcKeyValueConfig& trials() const = 0; |
| 171 | |
Tomas Gunnarsson | e984aa2 | 2021-04-19 09:21:06 +0200 | [diff] [blame] | 172 | virtual TaskQueueBase* network_thread() const = 0; |
| 173 | virtual TaskQueueBase* worker_thread() const = 0; |
| 174 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 175 | virtual ~Call() {} |
| 176 | }; |
| 177 | |
| 178 | } // namespace webrtc |
| 179 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 180 | #endif // CALL_CALL_H_ |