blob: 884a21b8b11d59ae422f2409e50a9e2e24a891cc [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
Ying Wang3b790f32018-01-19 16:58:5718#include "api/fec_controller.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "api/rtcerror.h"
20#include "call/audio_receive_stream.h"
21#include "call/audio_send_stream.h"
22#include "call/audio_state.h"
23#include "call/flexfec_receive_stream.h"
24#include "call/rtp_transport_controller_send_interface.h"
25#include "call/video_receive_stream.h"
26#include "call/video_send_stream.h"
Mirko Bonadei71207422017-09-15 11:58:0927#include "common_types.h" // NOLINT(build/include)
Alex Narest78609d52017-10-20 08:37:4728#include "rtc_base/bitrateallocationstrategy.h"
Danil Chapovalov292a73e2017-12-07 16:00:4029#include "rtc_base/copyonwritebuffer.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3130#include "rtc_base/networkroute.h"
31#include "rtc_base/platform_file.h"
32#include "rtc_base/socket.h"
ossuf515ab82016-12-07 12:52:5833
34namespace webrtc {
35
36class AudioProcessing;
37class RtcEventLog;
38
ossuf515ab82016-12-07 12:52:5839enum class MediaType {
40 ANY,
41 AUDIO,
42 VIDEO,
43 DATA
44};
45
zsteina5e0df62017-06-14 18:41:4846// Like std::min, but considers non-positive values to be unset.
47// TODO(zstein): Remove once all callers use rtc::Optional.
48template <typename T>
49static T MinPositive(T a, T b) {
50 if (a <= 0) {
51 return b;
52 }
53 if (b <= 0) {
54 return a;
55 }
56 return std::min(a, b);
57}
58
ossuf515ab82016-12-07 12:52:5859class PacketReceiver {
60 public:
61 enum DeliveryStatus {
62 DELIVERY_OK,
63 DELIVERY_UNKNOWN_SSRC,
64 DELIVERY_PACKET_ERROR,
65 };
66
67 virtual DeliveryStatus DeliverPacket(MediaType media_type,
Danil Chapovalov292a73e2017-12-07 16:00:4068 rtc::CopyOnWriteBuffer packet,
ossuf515ab82016-12-07 12:52:5869 const PacketTime& packet_time) = 0;
70
71 protected:
72 virtual ~PacketReceiver() {}
73};
74
Niels Möller8366e172018-02-14 11:20:1375struct CallConfig {
76 explicit CallConfig(RtcEventLog* event_log) : event_log(event_log) {
77 RTC_DCHECK(event_log);
78 }
79
80 static constexpr int kDefaultStartBitrateBps = 300000;
81
82 // Bitrate config used until valid bitrate estimates are calculated. Also
83 // used to cap total bitrate used. This comes from the remote connection.
84 struct BitrateConfig {
85 int min_bitrate_bps = 0;
86 int start_bitrate_bps = kDefaultStartBitrateBps;
87 int max_bitrate_bps = -1;
88 } bitrate_config;
89
90 // The local client's bitrate preferences. The actual configuration used
91 // is a combination of this and |bitrate_config|. The combination is
92 // currently more complicated than a simple mask operation (see
93 // SetBitrateConfig and SetBitrateConfigMask). Assumes that 0 <= min <=
94 // start <= max holds for set parameters.
95 struct BitrateConfigMask {
96 rtc::Optional<int> min_bitrate_bps;
97 rtc::Optional<int> start_bitrate_bps;
98 rtc::Optional<int> max_bitrate_bps;
99 };
100
101 // AudioState which is possibly shared between multiple calls.
102 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
103 rtc::scoped_refptr<AudioState> audio_state;
104
105 // Audio Processing Module to be used in this call.
106 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
107 AudioProcessing* audio_processing = nullptr;
108
109 // RtcEventLog to use for this call. Required.
110 // Use webrtc::RtcEventLog::CreateNull() for a null implementation.
111 RtcEventLog* event_log = nullptr;
112};
113
ossuf515ab82016-12-07 12:52:58114// A Call instance can contain several send and/or receive streams. All streams
115// are assumed to have the same remote endpoint and will share bitrate estimates
116// etc.
117class Call {
118 public:
Niels Möller8366e172018-02-14 11:20:13119 using Config = CallConfig;
ossuf515ab82016-12-07 12:52:58120
121 struct Stats {
122 std::string ToString(int64_t time_ms) const;
123
124 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
125 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
126 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
127 int64_t pacer_delay_ms = 0;
128 int64_t rtt_ms = -1;
129 };
130
131 static Call* Create(const Call::Config& config);
132
zstein7cb69d52017-05-08 18:52:38133 // Allows mocking |transport_send| for testing.
134 static Call* Create(
135 const Call::Config& config,
136 std::unique_ptr<RtpTransportControllerSendInterface> transport_send);
137
ossuf515ab82016-12-07 12:52:58138 virtual AudioSendStream* CreateAudioSendStream(
139 const AudioSendStream::Config& config) = 0;
140 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
141
142 virtual AudioReceiveStream* CreateAudioReceiveStream(
143 const AudioReceiveStream::Config& config) = 0;
144 virtual void DestroyAudioReceiveStream(
145 AudioReceiveStream* receive_stream) = 0;
146
147 virtual VideoSendStream* CreateVideoSendStream(
148 VideoSendStream::Config config,
149 VideoEncoderConfig encoder_config) = 0;
Ying Wang3b790f32018-01-19 16:58:57150 virtual VideoSendStream* CreateVideoSendStream(
151 VideoSendStream::Config config,
152 VideoEncoderConfig encoder_config,
153 std::unique_ptr<FecController> fec_controller);
ossuf515ab82016-12-07 12:52:58154 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
155
156 virtual VideoReceiveStream* CreateVideoReceiveStream(
157 VideoReceiveStream::Config configuration) = 0;
158 virtual void DestroyVideoReceiveStream(
159 VideoReceiveStream* receive_stream) = 0;
160
brandtrfb45c6c2017-01-27 14:47:55161 // In order for a created VideoReceiveStream to be aware that it is
162 // protected by a FlexfecReceiveStream, the latter should be created before
163 // the former.
ossuf515ab82016-12-07 12:52:58164 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
brandtr446fcb62016-12-08 12:14:24165 const FlexfecReceiveStream::Config& config) = 0;
ossuf515ab82016-12-07 12:52:58166 virtual void DestroyFlexfecReceiveStream(
167 FlexfecReceiveStream* receive_stream) = 0;
168
169 // All received RTP and RTCP packets for the call should be inserted to this
170 // PacketReceiver. The PacketReceiver pointer is valid as long as the
171 // Call instance exists.
172 virtual PacketReceiver* Receiver() = 0;
173
174 // Returns the call statistics, such as estimated send and receive bandwidth,
175 // pacing delay, etc.
176 virtual Stats GetStats() const = 0;
177
zstein4b979802017-06-02 21:37:37178 // The greater min and smaller max set by this and SetBitrateConfigMask will
179 // be used. The latest non-negative start value from either call will be used.
180 // Specifying a start bitrate (>0) will reset the current bitrate estimate.
181 // This is due to how the 'x-google-start-bitrate' flag is currently
182 // implemented. Passing -1 leaves the start bitrate unchanged. Behavior is not
183 // guaranteed for other negative values or 0.
ossuf515ab82016-12-07 12:52:58184 virtual void SetBitrateConfig(
185 const Config::BitrateConfig& bitrate_config) = 0;
186
zstein4b979802017-06-02 21:37:37187 // The greater min and smaller max set by this and SetBitrateConfig will be
188 // used. The latest non-negative start value form either call will be used.
189 // Specifying a start bitrate will reset the current bitrate estimate.
190 // Assumes 0 <= min <= start <= max holds for set parameters.
191 virtual void SetBitrateConfigMask(
192 const Config::BitrateConfigMask& bitrate_mask) = 0;
193
Alex Narest78609d52017-10-20 08:37:47194 virtual void SetBitrateAllocationStrategy(
195 std::unique_ptr<rtc::BitrateAllocationStrategy>
196 bitrate_allocation_strategy) = 0;
197
ossuf515ab82016-12-07 12:52:58198 // TODO(skvlad): When the unbundled case with multiple streams for the same
199 // media type going over different networks is supported, track the state
200 // for each stream separately. Right now it's global per media type.
201 virtual void SignalChannelNetworkState(MediaType media,
202 NetworkState state) = 0;
203
204 virtual void OnTransportOverheadChanged(
205 MediaType media,
206 int transport_overhead_per_packet) = 0;
207
208 virtual void OnNetworkRouteChanged(
209 const std::string& transport_name,
210 const rtc::NetworkRoute& network_route) = 0;
211
212 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
213
214 virtual ~Call() {}
215};
216
217} // namespace webrtc
218
Mirko Bonadei92ea95e2017-09-15 04:47:31219#endif // CALL_CALL_H_