ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [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 06:47:31 +0200 | [diff] [blame] | 10 | #ifndef CALL_CALL_H_ |
| 11 | #define CALL_CALL_H_ |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 12 | |
zstein | a5e0df6 | 2017-06-14 11:41:48 -0700 | [diff] [blame] | 13 | #include <algorithm> |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame] | 14 | #include <memory> |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/rtcerror.h" |
| 19 | #include "call/audio_receive_stream.h" |
| 20 | #include "call/audio_send_stream.h" |
| 21 | #include "call/audio_state.h" |
| 22 | #include "call/flexfec_receive_stream.h" |
| 23 | #include "call/rtp_transport_controller_send_interface.h" |
| 24 | #include "call/video_receive_stream.h" |
| 25 | #include "call/video_send_stream.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 26 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "rtc_base/networkroute.h" |
| 28 | #include "rtc_base/platform_file.h" |
| 29 | #include "rtc_base/socket.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 30 | |
| 31 | namespace webrtc { |
| 32 | |
| 33 | class AudioProcessing; |
| 34 | class RtcEventLog; |
| 35 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 36 | enum class MediaType { |
| 37 | ANY, |
| 38 | AUDIO, |
| 39 | VIDEO, |
| 40 | DATA |
| 41 | }; |
| 42 | |
zstein | a5e0df6 | 2017-06-14 11:41:48 -0700 | [diff] [blame] | 43 | // Like std::min, but considers non-positive values to be unset. |
| 44 | // TODO(zstein): Remove once all callers use rtc::Optional. |
| 45 | template <typename T> |
| 46 | static T MinPositive(T a, T b) { |
| 47 | if (a <= 0) { |
| 48 | return b; |
| 49 | } |
| 50 | if (b <= 0) { |
| 51 | return a; |
| 52 | } |
| 53 | return std::min(a, b); |
| 54 | } |
| 55 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 56 | class PacketReceiver { |
| 57 | public: |
| 58 | enum DeliveryStatus { |
| 59 | DELIVERY_OK, |
| 60 | DELIVERY_UNKNOWN_SSRC, |
| 61 | DELIVERY_PACKET_ERROR, |
| 62 | }; |
| 63 | |
| 64 | virtual DeliveryStatus DeliverPacket(MediaType media_type, |
| 65 | const uint8_t* packet, |
| 66 | size_t length, |
| 67 | const PacketTime& packet_time) = 0; |
| 68 | |
| 69 | protected: |
| 70 | virtual ~PacketReceiver() {} |
| 71 | }; |
| 72 | |
| 73 | // A Call instance can contain several send and/or receive streams. All streams |
| 74 | // are assumed to have the same remote endpoint and will share bitrate estimates |
| 75 | // etc. |
| 76 | class Call { |
| 77 | public: |
| 78 | struct Config { |
| 79 | explicit Config(RtcEventLog* event_log) : event_log(event_log) { |
| 80 | RTC_DCHECK(event_log); |
| 81 | } |
| 82 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 83 | static constexpr int kDefaultStartBitrateBps = 300000; |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 84 | |
| 85 | // Bitrate config used until valid bitrate estimates are calculated. Also |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 86 | // used to cap total bitrate used. This comes from the remote connection. |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 87 | struct BitrateConfig { |
| 88 | int min_bitrate_bps = 0; |
| 89 | int start_bitrate_bps = kDefaultStartBitrateBps; |
| 90 | int max_bitrate_bps = -1; |
| 91 | } bitrate_config; |
| 92 | |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 93 | // The local client's bitrate preferences. The actual configuration used |
| 94 | // is a combination of this and |bitrate_config|. The combination is |
| 95 | // currently more complicated than a simple mask operation (see |
| 96 | // SetBitrateConfig and SetBitrateConfigMask). Assumes that 0 <= min <= |
| 97 | // start <= max holds for set parameters. |
| 98 | struct BitrateConfigMask { |
| 99 | rtc::Optional<int> min_bitrate_bps; |
| 100 | rtc::Optional<int> start_bitrate_bps; |
| 101 | rtc::Optional<int> max_bitrate_bps; |
| 102 | }; |
| 103 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 104 | // AudioState which is possibly shared between multiple calls. |
| 105 | // TODO(solenberg): Change this to a shared_ptr once we can use C++11. |
| 106 | rtc::scoped_refptr<AudioState> audio_state; |
| 107 | |
| 108 | // Audio Processing Module to be used in this call. |
| 109 | // TODO(solenberg): Change this to a shared_ptr once we can use C++11. |
| 110 | AudioProcessing* audio_processing = nullptr; |
| 111 | |
| 112 | // RtcEventLog to use for this call. Required. |
| 113 | // Use webrtc::RtcEventLog::CreateNull() for a null implementation. |
| 114 | RtcEventLog* event_log = nullptr; |
| 115 | }; |
| 116 | |
| 117 | struct Stats { |
| 118 | std::string ToString(int64_t time_ms) const; |
| 119 | |
| 120 | int send_bandwidth_bps = 0; // Estimated available send bandwidth. |
| 121 | int max_padding_bitrate_bps = 0; // Cumulative configured max padding. |
| 122 | int recv_bandwidth_bps = 0; // Estimated available receive bandwidth. |
| 123 | int64_t pacer_delay_ms = 0; |
| 124 | int64_t rtt_ms = -1; |
| 125 | }; |
| 126 | |
| 127 | static Call* Create(const Call::Config& config); |
| 128 | |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame] | 129 | // Allows mocking |transport_send| for testing. |
| 130 | static Call* Create( |
| 131 | const Call::Config& config, |
| 132 | std::unique_ptr<RtpTransportControllerSendInterface> transport_send); |
| 133 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 134 | virtual AudioSendStream* CreateAudioSendStream( |
| 135 | const AudioSendStream::Config& config) = 0; |
| 136 | virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0; |
| 137 | |
| 138 | virtual AudioReceiveStream* CreateAudioReceiveStream( |
| 139 | const AudioReceiveStream::Config& config) = 0; |
| 140 | virtual void DestroyAudioReceiveStream( |
| 141 | AudioReceiveStream* receive_stream) = 0; |
| 142 | |
| 143 | virtual VideoSendStream* CreateVideoSendStream( |
| 144 | VideoSendStream::Config config, |
| 145 | VideoEncoderConfig encoder_config) = 0; |
| 146 | virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0; |
| 147 | |
| 148 | virtual VideoReceiveStream* CreateVideoReceiveStream( |
| 149 | VideoReceiveStream::Config configuration) = 0; |
| 150 | virtual void DestroyVideoReceiveStream( |
| 151 | VideoReceiveStream* receive_stream) = 0; |
| 152 | |
brandtr | fb45c6c | 2017-01-27 06:47:55 -0800 | [diff] [blame] | 153 | // In order for a created VideoReceiveStream to be aware that it is |
| 154 | // protected by a FlexfecReceiveStream, the latter should be created before |
| 155 | // the former. |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 156 | virtual FlexfecReceiveStream* CreateFlexfecReceiveStream( |
brandtr | 446fcb6 | 2016-12-08 04:14:24 -0800 | [diff] [blame] | 157 | const FlexfecReceiveStream::Config& config) = 0; |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 158 | virtual void DestroyFlexfecReceiveStream( |
| 159 | FlexfecReceiveStream* receive_stream) = 0; |
| 160 | |
| 161 | // All received RTP and RTCP packets for the call should be inserted to this |
| 162 | // PacketReceiver. The PacketReceiver pointer is valid as long as the |
| 163 | // Call instance exists. |
| 164 | virtual PacketReceiver* Receiver() = 0; |
| 165 | |
| 166 | // Returns the call statistics, such as estimated send and receive bandwidth, |
| 167 | // pacing delay, etc. |
| 168 | virtual Stats GetStats() const = 0; |
| 169 | |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 170 | // The greater min and smaller max set by this and SetBitrateConfigMask will |
| 171 | // be used. The latest non-negative start value from either call will be used. |
| 172 | // Specifying a start bitrate (>0) will reset the current bitrate estimate. |
| 173 | // This is due to how the 'x-google-start-bitrate' flag is currently |
| 174 | // implemented. Passing -1 leaves the start bitrate unchanged. Behavior is not |
| 175 | // guaranteed for other negative values or 0. |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 176 | virtual void SetBitrateConfig( |
| 177 | const Config::BitrateConfig& bitrate_config) = 0; |
| 178 | |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 179 | // The greater min and smaller max set by this and SetBitrateConfig will be |
| 180 | // used. The latest non-negative start value form either call will be used. |
| 181 | // Specifying a start bitrate will reset the current bitrate estimate. |
| 182 | // Assumes 0 <= min <= start <= max holds for set parameters. |
| 183 | virtual void SetBitrateConfigMask( |
| 184 | const Config::BitrateConfigMask& bitrate_mask) = 0; |
| 185 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 186 | // TODO(skvlad): When the unbundled case with multiple streams for the same |
| 187 | // media type going over different networks is supported, track the state |
| 188 | // for each stream separately. Right now it's global per media type. |
| 189 | virtual void SignalChannelNetworkState(MediaType media, |
| 190 | NetworkState state) = 0; |
| 191 | |
| 192 | virtual void OnTransportOverheadChanged( |
| 193 | MediaType media, |
| 194 | int transport_overhead_per_packet) = 0; |
| 195 | |
| 196 | virtual void OnNetworkRouteChanged( |
| 197 | const std::string& transport_name, |
| 198 | const rtc::NetworkRoute& network_route) = 0; |
| 199 | |
| 200 | virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0; |
| 201 | |
| 202 | virtual ~Call() {} |
| 203 | }; |
| 204 | |
| 205 | } // namespace webrtc |
| 206 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 207 | #endif // CALL_CALL_H_ |