blob: 366978392e885f0b380613b734d77a9930831bb6 [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
Ali Tofigh641a1b12022-05-17 09:48:4618#include "absl/strings/string_view.h"
Henrik Boströmf4a99912020-06-11 10:07:1419#include "api/adaptation/resource.h"
Steve Anton10542f22019-01-11 17:11:0020#include "api/media_types.h"
Tomas Gunnarssone984aa22021-04-19 07:21:0621#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "call/audio_receive_stream.h"
23#include "call/audio_send_stream.h"
Paulina Hensman11b34f42018-04-09 12:24:5224#include "call/call_config.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "call/flexfec_receive_stream.h"
Niels Möller70082872018-08-07 09:03:1226#include "call/packet_receiver.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3127#include "call/rtp_transport_controller_send_interface.h"
28#include "call/video_receive_stream.h"
29#include "call/video_send_stream.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
Harald Alvestrandd5f414c2022-01-24 09:11:2337// A Call represents a two-way connection carrying zero or more outgoing
38// and incoming media streams, transported over one or more RTP transports.
39
ossuf515ab82016-12-07 12:52:5840// A Call instance can contain several send and/or receive streams. All streams
41// are assumed to have the same remote endpoint and will share bitrate estimates
42// etc.
Harald Alvestrandd5f414c2022-01-24 09:11:2343
44// When using the PeerConnection API, there is an one to one relationship
45// between the PeerConnection and the Call.
46
ossuf515ab82016-12-07 12:52:5847class Call {
48 public:
Niels Möller8366e172018-02-14 11:20:1349 using Config = CallConfig;
ossuf515ab82016-12-07 12:52:5850
51 struct Stats {
52 std::string ToString(int64_t time_ms) const;
53
54 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
55 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
56 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
57 int64_t pacer_delay_ms = 0;
58 int64_t rtt_ms = -1;
59 };
60
61 static Call* Create(const Call::Config& config);
Sebastian Jansson896b47c2019-03-01 17:48:1662 static Call* Create(const Call::Config& config,
Sebastian Jansson4e5f5ed2019-03-01 17:13:2763 Clock* clock,
Vojin Ilic504fc192021-05-31 12:02:2864 std::unique_ptr<RtpTransportControllerSendInterface>
65 transportControllerSend);
ossuf515ab82016-12-07 12:52:5866
67 virtual AudioSendStream* CreateAudioSendStream(
68 const AudioSendStream::Config& config) = 0;
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:1969
ossuf515ab82016-12-07 12:52:5870 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
71
Tommi3176ef72022-05-22 18:47:2872 virtual AudioReceiveStreamInterface* CreateAudioReceiveStream(
73 const AudioReceiveStreamInterface::Config& config) = 0;
ossuf515ab82016-12-07 12:52:5874 virtual void DestroyAudioReceiveStream(
Tommi3176ef72022-05-22 18:47:2875 AudioReceiveStreamInterface* receive_stream) = 0;
ossuf515ab82016-12-07 12:52:5876
77 virtual VideoSendStream* CreateVideoSendStream(
78 VideoSendStream::Config config,
79 VideoEncoderConfig encoder_config) = 0;
Ying Wang3b790f32018-01-19 16:58:5780 virtual VideoSendStream* CreateVideoSendStream(
81 VideoSendStream::Config config,
82 VideoEncoderConfig encoder_config,
83 std::unique_ptr<FecController> fec_controller);
ossuf515ab82016-12-07 12:52:5884 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
85
Tommif6f45432022-05-20 13:21:2086 virtual VideoReceiveStreamInterface* CreateVideoReceiveStream(
87 VideoReceiveStreamInterface::Config configuration) = 0;
ossuf515ab82016-12-07 12:52:5888 virtual void DestroyVideoReceiveStream(
Tommif6f45432022-05-20 13:21:2089 VideoReceiveStreamInterface* receive_stream) = 0;
ossuf515ab82016-12-07 12:52:5890
Tommif6f45432022-05-20 13:21:2091 // In order for a created VideoReceiveStreamInterface to be aware that it is
brandtrfb45c6c2017-01-27 14:47:5592 // protected by a FlexfecReceiveStream, the latter should be created before
93 // the former.
ossuf515ab82016-12-07 12:52:5894 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
Tommicf4ed152022-05-09 20:46:5795 const FlexfecReceiveStream::Config config) = 0;
ossuf515ab82016-12-07 12:52:5896 virtual void DestroyFlexfecReceiveStream(
97 FlexfecReceiveStream* receive_stream) = 0;
98
Henrik Boströmf4a99912020-06-11 10:07:1499 // When a resource is overused, the Call will try to reduce the load on the
100 // sysem, for example by reducing the resolution or frame rate of encoded
101 // streams.
102 virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
103
ossuf515ab82016-12-07 12:52:58104 // All received RTP and RTCP packets for the call should be inserted to this
105 // PacketReceiver. The PacketReceiver pointer is valid as long as the
106 // Call instance exists.
107 virtual PacketReceiver* Receiver() = 0;
108
Sebastian Jansson8f83b422018-02-21 12:07:13109 // This is used to access the transport controller send instance owned by
110 // Call. The send transport controller is currently owned by Call for legacy
111 // reasons. (for instance variants of call tests are built on this assumtion)
112 // TODO(srte): Move ownership of transport controller send out of Call and
113 // remove this method interface.
114 virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0;
115
ossuf515ab82016-12-07 12:52:58116 // Returns the call statistics, such as estimated send and receive bandwidth,
117 // pacing delay, etc.
118 virtual Stats GetStats() const = 0;
119
ossuf515ab82016-12-07 12:52:58120 // TODO(skvlad): When the unbundled case with multiple streams for the same
121 // media type going over different networks is supported, track the state
122 // for each stream separately. Right now it's global per media type.
123 virtual void SignalChannelNetworkState(MediaType media,
124 NetworkState state) = 0;
125
Stefan Holmer64be7fa2018-10-04 13:21:55126 virtual void OnAudioTransportOverheadChanged(
ossuf515ab82016-12-07 12:52:58127 int transport_overhead_per_packet) = 0;
128
Tommi08be9ba2021-06-15 21:01:57129 // Called when a receive stream's local ssrc has changed and association with
130 // send streams needs to be updated.
Tommi3176ef72022-05-22 18:47:28131 virtual void OnLocalSsrcUpdated(AudioReceiveStreamInterface& stream,
Tommi08be9ba2021-06-15 21:01:57132 uint32_t local_ssrc) = 0;
Tommif6f45432022-05-20 13:21:20133 virtual void OnLocalSsrcUpdated(VideoReceiveStreamInterface& stream,
Tommi1331c182022-05-17 08:13:52134 uint32_t local_ssrc) = 0;
135 virtual void OnLocalSsrcUpdated(FlexfecReceiveStream& stream,
136 uint32_t local_ssrc) = 0;
Tommi08be9ba2021-06-15 21:01:57137
Tommi3176ef72022-05-22 18:47:28138 virtual void OnUpdateSyncGroup(AudioReceiveStreamInterface& stream,
Ali Tofigh641a1b12022-05-17 09:48:46139 absl::string_view sync_group) = 0;
Tommi55107c82021-06-16 14:31:18140
ossuf515ab82016-12-07 12:52:58141 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
142
Piotr (Peter) Slatala7fbfaa42019-03-18 17:31:54143 virtual void SetClientBitratePreferences(
144 const BitrateSettings& preferences) = 0;
145
Jonas Orelande62c2f22022-03-29 09:04:48146 virtual const FieldTrialsView& trials() const = 0;
Erik Språngceb44952020-09-22 09:36:35147
Tomas Gunnarssone984aa22021-04-19 07:21:06148 virtual TaskQueueBase* network_thread() const = 0;
149 virtual TaskQueueBase* worker_thread() const = 0;
150
ossuf515ab82016-12-07 12:52:58151 virtual ~Call() {}
152};
153
154} // namespace webrtc
155
Mirko Bonadei92ea95e2017-09-15 04:47:31156#endif // CALL_CALL_H_