blob: 5474bccfac642b88d844e7391f5a2aba585f6744 [file] [log] [blame]
ossuf515ab82016-12-07 04:52:58 -08001/*
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 06:47:31 +020010#ifndef CALL_CALL_H_
11#define CALL_CALL_H_
ossuf515ab82016-12-07 04:52:58 -080012
zsteina5e0df62017-06-14 11:41:48 -070013#include <algorithm>
zstein7cb69d52017-05-08 11:52:38 -070014#include <memory>
ossuf515ab82016-12-07 04:52:58 -080015#include <string>
16#include <vector>
17
Ying Wang3b790f32018-01-19 17:58:57 +010018#include "api/fec_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/rtcerror.h"
20#include "call/audio_receive_stream.h"
21#include "call/audio_send_stream.h"
22#include "call/audio_state.h"
Sebastian Jansson5897fe22018-02-20 17:28:20 +010023#include "call/bitrate_constraints.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "call/flexfec_receive_stream.h"
25#include "call/rtp_transport_controller_send_interface.h"
26#include "call/video_receive_stream.h"
27#include "call/video_send_stream.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020028#include "common_types.h" // NOLINT(build/include)
Alex Narest78609d52017-10-20 10:37:47 +020029#include "rtc_base/bitrateallocationstrategy.h"
Danil Chapovalov292a73e2017-12-07 17:00:40 +010030#include "rtc_base/copyonwritebuffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "rtc_base/networkroute.h"
32#include "rtc_base/platform_file.h"
33#include "rtc_base/socket.h"
ossuf515ab82016-12-07 04:52:58 -080034
35namespace webrtc {
36
37class AudioProcessing;
38class RtcEventLog;
39
ossuf515ab82016-12-07 04:52:58 -080040enum class MediaType {
41 ANY,
42 AUDIO,
43 VIDEO,
44 DATA
45};
46
47class PacketReceiver {
48 public:
49 enum DeliveryStatus {
50 DELIVERY_OK,
51 DELIVERY_UNKNOWN_SSRC,
52 DELIVERY_PACKET_ERROR,
53 };
54
55 virtual DeliveryStatus DeliverPacket(MediaType media_type,
Danil Chapovalov292a73e2017-12-07 17:00:40 +010056 rtc::CopyOnWriteBuffer packet,
ossuf515ab82016-12-07 04:52:58 -080057 const PacketTime& packet_time) = 0;
58
59 protected:
60 virtual ~PacketReceiver() {}
61};
62
Niels Möller8366e172018-02-14 12:20:13 +010063struct CallConfig {
64 explicit CallConfig(RtcEventLog* event_log) : event_log(event_log) {
65 RTC_DCHECK(event_log);
66 }
67
Niels Möller8366e172018-02-14 12:20:13 +010068 // Bitrate config used until valid bitrate estimates are calculated. Also
69 // used to cap total bitrate used. This comes from the remote connection.
Sebastian Jansson5897fe22018-02-20 17:28:20 +010070 BitrateConstraints bitrate_config;
Niels Möller8366e172018-02-14 12:20:13 +010071
72 // AudioState which is possibly shared between multiple calls.
73 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
74 rtc::scoped_refptr<AudioState> audio_state;
75
76 // Audio Processing Module to be used in this call.
77 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
78 AudioProcessing* audio_processing = nullptr;
79
80 // RtcEventLog to use for this call. Required.
81 // Use webrtc::RtcEventLog::CreateNull() for a null implementation.
82 RtcEventLog* event_log = nullptr;
Ying Wang0dd1b0a2018-02-20 12:50:27 +010083
84 // FecController to use for this call.
85 FecControllerFactoryInterface* fec_controller_factory = nullptr;
Niels Möller8366e172018-02-14 12:20:13 +010086};
87
ossuf515ab82016-12-07 04:52:58 -080088// A Call instance can contain several send and/or receive streams. All streams
89// are assumed to have the same remote endpoint and will share bitrate estimates
90// etc.
91class Call {
92 public:
Niels Möller8366e172018-02-14 12:20:13 +010093 using Config = CallConfig;
ossuf515ab82016-12-07 04:52:58 -080094
95 struct Stats {
96 std::string ToString(int64_t time_ms) const;
97
98 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
99 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
100 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
101 int64_t pacer_delay_ms = 0;
102 int64_t rtt_ms = -1;
103 };
104
105 static Call* Create(const Call::Config& config);
106
zstein7cb69d52017-05-08 11:52:38 -0700107 // Allows mocking |transport_send| for testing.
108 static Call* Create(
109 const Call::Config& config,
110 std::unique_ptr<RtpTransportControllerSendInterface> transport_send);
111
ossuf515ab82016-12-07 04:52:58 -0800112 virtual AudioSendStream* CreateAudioSendStream(
113 const AudioSendStream::Config& config) = 0;
114 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
115
116 virtual AudioReceiveStream* CreateAudioReceiveStream(
117 const AudioReceiveStream::Config& config) = 0;
118 virtual void DestroyAudioReceiveStream(
119 AudioReceiveStream* receive_stream) = 0;
120
121 virtual VideoSendStream* CreateVideoSendStream(
122 VideoSendStream::Config config,
123 VideoEncoderConfig encoder_config) = 0;
Ying Wang3b790f32018-01-19 17:58:57 +0100124 virtual VideoSendStream* CreateVideoSendStream(
125 VideoSendStream::Config config,
126 VideoEncoderConfig encoder_config,
127 std::unique_ptr<FecController> fec_controller);
ossuf515ab82016-12-07 04:52:58 -0800128 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
129
130 virtual VideoReceiveStream* CreateVideoReceiveStream(
131 VideoReceiveStream::Config configuration) = 0;
132 virtual void DestroyVideoReceiveStream(
133 VideoReceiveStream* receive_stream) = 0;
134
brandtrfb45c6c2017-01-27 06:47:55 -0800135 // In order for a created VideoReceiveStream to be aware that it is
136 // protected by a FlexfecReceiveStream, the latter should be created before
137 // the former.
ossuf515ab82016-12-07 04:52:58 -0800138 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
brandtr446fcb62016-12-08 04:14:24 -0800139 const FlexfecReceiveStream::Config& config) = 0;
ossuf515ab82016-12-07 04:52:58 -0800140 virtual void DestroyFlexfecReceiveStream(
141 FlexfecReceiveStream* receive_stream) = 0;
142
143 // All received RTP and RTCP packets for the call should be inserted to this
144 // PacketReceiver. The PacketReceiver pointer is valid as long as the
145 // Call instance exists.
146 virtual PacketReceiver* Receiver() = 0;
147
148 // Returns the call statistics, such as estimated send and receive bandwidth,
149 // pacing delay, etc.
150 virtual Stats GetStats() const = 0;
151
zstein4b979802017-06-02 14:37:37 -0700152 // The greater min and smaller max set by this and SetBitrateConfigMask will
153 // be used. The latest non-negative start value from either call will be used.
154 // Specifying a start bitrate (>0) will reset the current bitrate estimate.
155 // This is due to how the 'x-google-start-bitrate' flag is currently
156 // implemented. Passing -1 leaves the start bitrate unchanged. Behavior is not
157 // guaranteed for other negative values or 0.
Sebastian Jansson5897fe22018-02-20 17:28:20 +0100158 virtual void SetBitrateConfig(const BitrateConstraints& bitrate_config) = 0;
ossuf515ab82016-12-07 04:52:58 -0800159
zstein4b979802017-06-02 14:37:37 -0700160 // The greater min and smaller max set by this and SetBitrateConfig will be
161 // used. The latest non-negative start value form either call will be used.
162 // Specifying a start bitrate will reset the current bitrate estimate.
163 // Assumes 0 <= min <= start <= max holds for set parameters.
164 virtual void SetBitrateConfigMask(
Sebastian Jansson5897fe22018-02-20 17:28:20 +0100165 const BitrateConstraintsMask& bitrate_mask) = 0;
zstein4b979802017-06-02 14:37:37 -0700166
Alex Narest78609d52017-10-20 10:37:47 +0200167 virtual void SetBitrateAllocationStrategy(
168 std::unique_ptr<rtc::BitrateAllocationStrategy>
169 bitrate_allocation_strategy) = 0;
170
ossuf515ab82016-12-07 04:52:58 -0800171 // TODO(skvlad): When the unbundled case with multiple streams for the same
172 // media type going over different networks is supported, track the state
173 // for each stream separately. Right now it's global per media type.
174 virtual void SignalChannelNetworkState(MediaType media,
175 NetworkState state) = 0;
176
177 virtual void OnTransportOverheadChanged(
178 MediaType media,
179 int transport_overhead_per_packet) = 0;
180
181 virtual void OnNetworkRouteChanged(
182 const std::string& transport_name,
183 const rtc::NetworkRoute& network_route) = 0;
184
185 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
186
187 virtual ~Call() {}
188};
189
190} // namespace webrtc
191
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200192#endif // CALL_CALL_H_