ossu | f515ab8 | 2016-12-07 12:52:58 | [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 04:47:31 | [diff] [blame] | 10 | #ifndef CALL_CALL_H_ |
| 11 | #define CALL_CALL_H_ |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 12 | |
zstein | a5e0df6 | 2017-06-14 18:41:48 | [diff] [blame] | 13 | #include <algorithm> |
zstein | 7cb69d5 | 2017-05-08 18:52:38 | [diff] [blame] | 14 | #include <memory> |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 18 | #include "absl/strings/string_view.h" |
Henrik Boström | f4a9991 | 2020-06-11 10:07:14 | [diff] [blame] | 19 | #include "api/adaptation/resource.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 20 | #include "api/media_types.h" |
Tomas Gunnarsson | e984aa2 | 2021-04-19 07:21:06 | [diff] [blame] | 21 | #include "api/task_queue/task_queue_base.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 22 | #include "call/audio_receive_stream.h" |
| 23 | #include "call/audio_send_stream.h" |
Paulina Hensman | 11b34f4 | 2018-04-09 12:24:52 | [diff] [blame] | 24 | #include "call/call_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 25 | #include "call/flexfec_receive_stream.h" |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 26 | #include "call/packet_receiver.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 27 | #include "call/video_receive_stream.h" |
| 28 | #include "call/video_send_stream.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 29 | #include "rtc_base/copy_on_write_buffer.h" |
Sebastian Jansson | 1298541 | 2018-10-15 19:06:26 | [diff] [blame] | 30 | #include "rtc_base/network/sent_packet.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 31 | #include "rtc_base/network_route.h" |
Tommi | 25c77c1 | 2020-05-25 15:44:55 | [diff] [blame] | 32 | #include "rtc_base/ref_count.h" |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 33 | |
| 34 | namespace webrtc { |
| 35 | |
Harald Alvestrand | d5f414c | 2022-01-24 09:11:23 | [diff] [blame] | 36 | // A Call represents a two-way connection carrying zero or more outgoing |
| 37 | // and incoming media streams, transported over one or more RTP transports. |
| 38 | |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 39 | // A Call instance can contain several send and/or receive streams. All streams |
| 40 | // are assumed to have the same remote endpoint and will share bitrate estimates |
| 41 | // etc. |
Harald Alvestrand | d5f414c | 2022-01-24 09:11:23 | [diff] [blame] | 42 | |
| 43 | // When using the PeerConnection API, there is an one to one relationship |
| 44 | // between the PeerConnection and the Call. |
| 45 | |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 46 | class Call { |
| 47 | public: |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 48 | struct Stats { |
| 49 | std::string ToString(int64_t time_ms) const; |
| 50 | |
| 51 | int send_bandwidth_bps = 0; // Estimated available send bandwidth. |
| 52 | int max_padding_bitrate_bps = 0; // Cumulative configured max padding. |
| 53 | int recv_bandwidth_bps = 0; // Estimated available receive bandwidth. |
| 54 | int64_t pacer_delay_ms = 0; |
| 55 | int64_t rtt_ms = -1; |
| 56 | }; |
| 57 | |
Danil Chapovalov | a3ce407 | 2023-10-13 11:53:00 | [diff] [blame] | 58 | static std::unique_ptr<Call> Create(const CallConfig& config); |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 59 | |
| 60 | virtual AudioSendStream* CreateAudioSendStream( |
| 61 | const AudioSendStream::Config& config) = 0; |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 62 | |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 63 | virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0; |
| 64 | |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 65 | virtual AudioReceiveStreamInterface* CreateAudioReceiveStream( |
| 66 | const AudioReceiveStreamInterface::Config& config) = 0; |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 67 | virtual void DestroyAudioReceiveStream( |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 68 | AudioReceiveStreamInterface* receive_stream) = 0; |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 69 | |
| 70 | virtual VideoSendStream* CreateVideoSendStream( |
| 71 | VideoSendStream::Config config, |
| 72 | VideoEncoderConfig encoder_config) = 0; |
Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 73 | virtual VideoSendStream* CreateVideoSendStream( |
| 74 | VideoSendStream::Config config, |
| 75 | VideoEncoderConfig encoder_config, |
| 76 | std::unique_ptr<FecController> fec_controller); |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 77 | virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0; |
| 78 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 79 | virtual VideoReceiveStreamInterface* CreateVideoReceiveStream( |
| 80 | VideoReceiveStreamInterface::Config configuration) = 0; |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 81 | virtual void DestroyVideoReceiveStream( |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 82 | VideoReceiveStreamInterface* receive_stream) = 0; |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 83 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 84 | // In order for a created VideoReceiveStreamInterface to be aware that it is |
brandtr | fb45c6c | 2017-01-27 14:47:55 | [diff] [blame] | 85 | // protected by a FlexfecReceiveStream, the latter should be created before |
| 86 | // the former. |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 87 | virtual FlexfecReceiveStream* CreateFlexfecReceiveStream( |
Tommi | cf4ed15 | 2022-05-09 20:46:57 | [diff] [blame] | 88 | const FlexfecReceiveStream::Config config) = 0; |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 89 | virtual void DestroyFlexfecReceiveStream( |
| 90 | FlexfecReceiveStream* receive_stream) = 0; |
| 91 | |
Henrik Boström | f4a9991 | 2020-06-11 10:07:14 | [diff] [blame] | 92 | // When a resource is overused, the Call will try to reduce the load on the |
| 93 | // sysem, for example by reducing the resolution or frame rate of encoded |
| 94 | // streams. |
| 95 | virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0; |
| 96 | |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 97 | // All received RTP and RTCP packets for the call should be inserted to this |
| 98 | // PacketReceiver. The PacketReceiver pointer is valid as long as the |
| 99 | // Call instance exists. |
| 100 | virtual PacketReceiver* Receiver() = 0; |
| 101 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 12:07:13 | [diff] [blame] | 102 | // This is used to access the transport controller send instance owned by |
| 103 | // Call. The send transport controller is currently owned by Call for legacy |
| 104 | // reasons. (for instance variants of call tests are built on this assumtion) |
| 105 | // TODO(srte): Move ownership of transport controller send out of Call and |
| 106 | // remove this method interface. |
| 107 | virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0; |
| 108 | |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 109 | // Returns the call statistics, such as estimated send and receive bandwidth, |
| 110 | // pacing delay, etc. |
| 111 | virtual Stats GetStats() const = 0; |
| 112 | |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 113 | // TODO(skvlad): When the unbundled case with multiple streams for the same |
| 114 | // media type going over different networks is supported, track the state |
| 115 | // for each stream separately. Right now it's global per media type. |
| 116 | virtual void SignalChannelNetworkState(MediaType media, |
| 117 | NetworkState state) = 0; |
| 118 | |
Stefan Holmer | 64be7fa | 2018-10-04 13:21:55 | [diff] [blame] | 119 | virtual void OnAudioTransportOverheadChanged( |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 120 | int transport_overhead_per_packet) = 0; |
| 121 | |
Tommi | 08be9ba | 2021-06-15 21:01:57 | [diff] [blame] | 122 | // Called when a receive stream's local ssrc has changed and association with |
| 123 | // send streams needs to be updated. |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 124 | virtual void OnLocalSsrcUpdated(AudioReceiveStreamInterface& stream, |
Tommi | 08be9ba | 2021-06-15 21:01:57 | [diff] [blame] | 125 | uint32_t local_ssrc) = 0; |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 126 | virtual void OnLocalSsrcUpdated(VideoReceiveStreamInterface& stream, |
Tommi | 1331c18 | 2022-05-17 08:13:52 | [diff] [blame] | 127 | uint32_t local_ssrc) = 0; |
| 128 | virtual void OnLocalSsrcUpdated(FlexfecReceiveStream& stream, |
| 129 | uint32_t local_ssrc) = 0; |
Tommi | 08be9ba | 2021-06-15 21:01:57 | [diff] [blame] | 130 | |
Tommi | 3176ef7 | 2022-05-22 18:47:28 | [diff] [blame] | 131 | virtual void OnUpdateSyncGroup(AudioReceiveStreamInterface& stream, |
Ali Tofigh | 641a1b1 | 2022-05-17 09:48:46 | [diff] [blame] | 132 | absl::string_view sync_group) = 0; |
Tommi | 55107c8 | 2021-06-16 14:31:18 | [diff] [blame] | 133 | |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 134 | virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0; |
| 135 | |
Piotr (Peter) Slatala | 7fbfaa4 | 2019-03-18 17:31:54 | [diff] [blame] | 136 | virtual void SetClientBitratePreferences( |
| 137 | const BitrateSettings& preferences) = 0; |
| 138 | |
Jonas Oreland | e62c2f2 | 2022-03-29 09:04:48 | [diff] [blame] | 139 | virtual const FieldTrialsView& trials() const = 0; |
Erik Språng | ceb4495 | 2020-09-22 09:36:35 | [diff] [blame] | 140 | |
Tomas Gunnarsson | e984aa2 | 2021-04-19 07:21:06 | [diff] [blame] | 141 | virtual TaskQueueBase* network_thread() const = 0; |
| 142 | virtual TaskQueueBase* worker_thread() const = 0; |
| 143 | |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 144 | virtual ~Call() {} |
| 145 | }; |
| 146 | |
| 147 | } // namespace webrtc |
| 148 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 149 | #endif // CALL_CALL_H_ |