xref: /aosp_15_r20/external/webrtc/call/call.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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  */
10 #ifndef CALL_CALL_H_
11 #define CALL_CALL_H_
12 
13 #include <algorithm>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "absl/strings/string_view.h"
19 #include "api/adaptation/resource.h"
20 #include "api/media_types.h"
21 #include "api/task_queue/task_queue_base.h"
22 #include "call/audio_receive_stream.h"
23 #include "call/audio_send_stream.h"
24 #include "call/call_config.h"
25 #include "call/flexfec_receive_stream.h"
26 #include "call/packet_receiver.h"
27 #include "call/rtp_transport_controller_send_interface.h"
28 #include "call/video_receive_stream.h"
29 #include "call/video_send_stream.h"
30 #include "rtc_base/copy_on_write_buffer.h"
31 #include "rtc_base/network/sent_packet.h"
32 #include "rtc_base/network_route.h"
33 #include "rtc_base/ref_count.h"
34 
35 namespace webrtc {
36 
37 // 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 
40 // 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.
43 
44 // When using the PeerConnection API, there is an one to one relationship
45 // between the PeerConnection and the Call.
46 
47 class Call {
48  public:
49   using Config = CallConfig;
50 
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);
62   static Call* Create(const Call::Config& config,
63                       Clock* clock,
64                       std::unique_ptr<RtpTransportControllerSendInterface>
65                           transportControllerSend);
66 
67   virtual AudioSendStream* CreateAudioSendStream(
68       const AudioSendStream::Config& config) = 0;
69 
70   virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
71 
72   virtual AudioReceiveStreamInterface* CreateAudioReceiveStream(
73       const AudioReceiveStreamInterface::Config& config) = 0;
74   virtual void DestroyAudioReceiveStream(
75       AudioReceiveStreamInterface* receive_stream) = 0;
76 
77   virtual VideoSendStream* CreateVideoSendStream(
78       VideoSendStream::Config config,
79       VideoEncoderConfig encoder_config) = 0;
80   virtual VideoSendStream* CreateVideoSendStream(
81       VideoSendStream::Config config,
82       VideoEncoderConfig encoder_config,
83       std::unique_ptr<FecController> fec_controller);
84   virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
85 
86   virtual VideoReceiveStreamInterface* CreateVideoReceiveStream(
87       VideoReceiveStreamInterface::Config configuration) = 0;
88   virtual void DestroyVideoReceiveStream(
89       VideoReceiveStreamInterface* receive_stream) = 0;
90 
91   // In order for a created VideoReceiveStreamInterface to be aware that it is
92   // protected by a FlexfecReceiveStream, the latter should be created before
93   // the former.
94   virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
95       const FlexfecReceiveStream::Config config) = 0;
96   virtual void DestroyFlexfecReceiveStream(
97       FlexfecReceiveStream* receive_stream) = 0;
98 
99   // 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 
104   // 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 
109   // 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 
116   // Returns the call statistics, such as estimated send and receive bandwidth,
117   // pacing delay, etc.
118   virtual Stats GetStats() const = 0;
119 
120   // 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 
126   virtual void OnAudioTransportOverheadChanged(
127       int transport_overhead_per_packet) = 0;
128 
129   // Called when a receive stream's local ssrc has changed and association with
130   // send streams needs to be updated.
131   virtual void OnLocalSsrcUpdated(AudioReceiveStreamInterface& stream,
132                                   uint32_t local_ssrc) = 0;
133   virtual void OnLocalSsrcUpdated(VideoReceiveStreamInterface& stream,
134                                   uint32_t local_ssrc) = 0;
135   virtual void OnLocalSsrcUpdated(FlexfecReceiveStream& stream,
136                                   uint32_t local_ssrc) = 0;
137 
138   virtual void OnUpdateSyncGroup(AudioReceiveStreamInterface& stream,
139                                  absl::string_view sync_group) = 0;
140 
141   virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
142 
143   virtual void SetClientBitratePreferences(
144       const BitrateSettings& preferences) = 0;
145 
146   virtual const FieldTrialsView& trials() const = 0;
147 
148   virtual TaskQueueBase* network_thread() const = 0;
149   virtual TaskQueueBase* worker_thread() const = 0;
150 
~Call()151   virtual ~Call() {}
152 };
153 
154 }  // namespace webrtc
155 
156 #endif  // CALL_CALL_H_
157