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 | |
Ying Wang | 3b790f3 | 2018-01-19 17:58:57 +0100 | [diff] [blame] | 18 | #include "api/fec_controller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #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 Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 23 | #include "call/bitrate_constraints.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #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 Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 28 | #include "common_types.h" // NOLINT(build/include) |
Alex Narest | 78609d5 | 2017-10-20 10:37:47 +0200 | [diff] [blame] | 29 | #include "rtc_base/bitrateallocationstrategy.h" |
Danil Chapovalov | 292a73e | 2017-12-07 17:00:40 +0100 | [diff] [blame] | 30 | #include "rtc_base/copyonwritebuffer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "rtc_base/networkroute.h" |
| 32 | #include "rtc_base/platform_file.h" |
| 33 | #include "rtc_base/socket.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 34 | |
| 35 | namespace webrtc { |
| 36 | |
| 37 | class AudioProcessing; |
| 38 | class RtcEventLog; |
| 39 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 40 | enum class MediaType { |
| 41 | ANY, |
| 42 | AUDIO, |
| 43 | VIDEO, |
| 44 | DATA |
| 45 | }; |
| 46 | |
| 47 | class 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 Chapovalov | 292a73e | 2017-12-07 17:00:40 +0100 | [diff] [blame] | 56 | rtc::CopyOnWriteBuffer packet, |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 57 | const PacketTime& packet_time) = 0; |
| 58 | |
| 59 | protected: |
| 60 | virtual ~PacketReceiver() {} |
| 61 | }; |
| 62 | |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 63 | struct CallConfig { |
| 64 | explicit CallConfig(RtcEventLog* event_log) : event_log(event_log) { |
| 65 | RTC_DCHECK(event_log); |
| 66 | } |
| 67 | |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 68 | RTC_DEPRECATED static constexpr int kDefaultStartBitrateBps = 300000; |
Lu Liu | e4bf600 | 2018-02-20 19:16:26 +0000 | [diff] [blame] | 69 | |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 70 | // Bitrate config used until valid bitrate estimates are calculated. Also |
| 71 | // used to cap total bitrate used. This comes from the remote connection. |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 72 | BitrateConstraints bitrate_config; |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 73 | |
| 74 | // AudioState which is possibly shared between multiple calls. |
| 75 | // TODO(solenberg): Change this to a shared_ptr once we can use C++11. |
| 76 | rtc::scoped_refptr<AudioState> audio_state; |
| 77 | |
| 78 | // Audio Processing Module to be used in this call. |
| 79 | // TODO(solenberg): Change this to a shared_ptr once we can use C++11. |
| 80 | AudioProcessing* audio_processing = nullptr; |
| 81 | |
| 82 | // RtcEventLog to use for this call. Required. |
| 83 | // Use webrtc::RtcEventLog::CreateNull() for a null implementation. |
| 84 | RtcEventLog* event_log = nullptr; |
Ying Wang | 0dd1b0a | 2018-02-20 12:50:27 +0100 | [diff] [blame] | 85 | |
| 86 | // FecController to use for this call. |
| 87 | FecControllerFactoryInterface* fec_controller_factory = nullptr; |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 90 | // A Call instance can contain several send and/or receive streams. All streams |
| 91 | // are assumed to have the same remote endpoint and will share bitrate estimates |
| 92 | // etc. |
| 93 | class Call { |
| 94 | public: |
Niels Möller | 8366e17 | 2018-02-14 12:20:13 +0100 | [diff] [blame] | 95 | using Config = CallConfig; |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 96 | |
| 97 | struct Stats { |
| 98 | std::string ToString(int64_t time_ms) const; |
| 99 | |
| 100 | int send_bandwidth_bps = 0; // Estimated available send bandwidth. |
| 101 | int max_padding_bitrate_bps = 0; // Cumulative configured max padding. |
| 102 | int recv_bandwidth_bps = 0; // Estimated available receive bandwidth. |
| 103 | int64_t pacer_delay_ms = 0; |
| 104 | int64_t rtt_ms = -1; |
| 105 | }; |
| 106 | |
| 107 | static Call* Create(const Call::Config& config); |
| 108 | |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame] | 109 | // Allows mocking |transport_send| for testing. |
| 110 | static Call* Create( |
| 111 | const Call::Config& config, |
| 112 | std::unique_ptr<RtpTransportControllerSendInterface> transport_send); |
| 113 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 114 | virtual AudioSendStream* CreateAudioSendStream( |
| 115 | const AudioSendStream::Config& config) = 0; |
| 116 | virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0; |
| 117 | |
| 118 | virtual AudioReceiveStream* CreateAudioReceiveStream( |
| 119 | const AudioReceiveStream::Config& config) = 0; |
| 120 | virtual void DestroyAudioReceiveStream( |
| 121 | AudioReceiveStream* receive_stream) = 0; |
| 122 | |
| 123 | virtual VideoSendStream* CreateVideoSendStream( |
| 124 | VideoSendStream::Config config, |
| 125 | VideoEncoderConfig encoder_config) = 0; |
Ying Wang | 3b790f3 | 2018-01-19 17:58:57 +0100 | [diff] [blame] | 126 | virtual VideoSendStream* CreateVideoSendStream( |
| 127 | VideoSendStream::Config config, |
| 128 | VideoEncoderConfig encoder_config, |
| 129 | std::unique_ptr<FecController> fec_controller); |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 130 | virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0; |
| 131 | |
| 132 | virtual VideoReceiveStream* CreateVideoReceiveStream( |
| 133 | VideoReceiveStream::Config configuration) = 0; |
| 134 | virtual void DestroyVideoReceiveStream( |
| 135 | VideoReceiveStream* receive_stream) = 0; |
| 136 | |
brandtr | fb45c6c | 2017-01-27 06:47:55 -0800 | [diff] [blame] | 137 | // In order for a created VideoReceiveStream to be aware that it is |
| 138 | // protected by a FlexfecReceiveStream, the latter should be created before |
| 139 | // the former. |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 140 | virtual FlexfecReceiveStream* CreateFlexfecReceiveStream( |
brandtr | 446fcb6 | 2016-12-08 04:14:24 -0800 | [diff] [blame] | 141 | const FlexfecReceiveStream::Config& config) = 0; |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 142 | virtual void DestroyFlexfecReceiveStream( |
| 143 | FlexfecReceiveStream* receive_stream) = 0; |
| 144 | |
| 145 | // All received RTP and RTCP packets for the call should be inserted to this |
| 146 | // PacketReceiver. The PacketReceiver pointer is valid as long as the |
| 147 | // Call instance exists. |
| 148 | virtual PacketReceiver* Receiver() = 0; |
| 149 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame^] | 150 | // This is used to access the transport controller send instance owned by |
| 151 | // Call. The send transport controller is currently owned by Call for legacy |
| 152 | // reasons. (for instance variants of call tests are built on this assumtion) |
| 153 | // TODO(srte): Move ownership of transport controller send out of Call and |
| 154 | // remove this method interface. |
| 155 | virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0; |
| 156 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 157 | // Returns the call statistics, such as estimated send and receive bandwidth, |
| 158 | // pacing delay, etc. |
| 159 | virtual Stats GetStats() const = 0; |
| 160 | |
Alex Narest | 78609d5 | 2017-10-20 10:37:47 +0200 | [diff] [blame] | 161 | virtual void SetBitrateAllocationStrategy( |
| 162 | std::unique_ptr<rtc::BitrateAllocationStrategy> |
| 163 | bitrate_allocation_strategy) = 0; |
| 164 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 165 | // TODO(skvlad): When the unbundled case with multiple streams for the same |
| 166 | // media type going over different networks is supported, track the state |
| 167 | // for each stream separately. Right now it's global per media type. |
| 168 | virtual void SignalChannelNetworkState(MediaType media, |
| 169 | NetworkState state) = 0; |
| 170 | |
| 171 | virtual void OnTransportOverheadChanged( |
| 172 | MediaType media, |
| 173 | int transport_overhead_per_packet) = 0; |
| 174 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 175 | virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0; |
| 176 | |
| 177 | virtual ~Call() {} |
| 178 | }; |
| 179 | |
| 180 | } // namespace webrtc |
| 181 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 182 | #endif // CALL_CALL_H_ |