Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 1 | /* Copyright 2018 The WebRTC project authors. All Rights Reserved. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 2 | * |
| 3 | * Use of this source code is governed by a BSD-style license |
| 4 | * that can be found in the LICENSE file in the root of the source |
| 5 | * tree. An additional intellectual property rights grant can be found |
| 6 | * in the file PATENTS. All contributing project authors may |
| 7 | * be found in the AUTHORS file in the root of the source tree. |
| 8 | */ |
| 9 | |
| 10 | // This is EXPERIMENTAL interface for media transport. |
| 11 | // |
| 12 | // The goal is to refactor WebRTC code so that audio and video frames |
| 13 | // are sent / received through the media transport interface. This will |
| 14 | // enable different media transport implementations, including QUIC-based |
| 15 | // media transport. |
| 16 | |
| 17 | #ifndef API_MEDIA_TRANSPORT_INTERFACE_H_ |
| 18 | #define API_MEDIA_TRANSPORT_INTERFACE_H_ |
| 19 | |
Piotr (Peter) Slatala | 6b9d823 | 2018-10-26 07:59:46 -0700 | [diff] [blame] | 20 | #include <api/transport/network_control.h> |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 21 | #include <memory> |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 22 | #include <string> |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 23 | #include <utility> |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 24 | |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 25 | #include "absl/types/optional.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 26 | #include "api/array_view.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 27 | #include "api/rtc_error.h" |
Niels Möller | ec3b9ff | 2019-02-08 00:28:39 +0100 | [diff] [blame] | 28 | #include "api/transport/media/audio_transport.h" |
Niels Möller | 7e0e44f | 2019-02-12 14:04:11 +0100 | [diff] [blame] | 29 | #include "api/transport/media/video_transport.h" |
Piotr (Peter) Slatala | 48c5493 | 2019-01-28 06:50:38 -0800 | [diff] [blame] | 30 | #include "api/units/data_rate.h" |
Niels Möller | d5af402 | 2019-03-05 08:56:48 +0100 | [diff] [blame] | 31 | #include "common_types.h" // NOLINT(build/include) |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 32 | #include "rtc_base/copy_on_write_buffer.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 33 | #include "rtc_base/network_route.h" |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 34 | |
| 35 | namespace rtc { |
| 36 | class PacketTransportInternal; |
| 37 | class Thread; |
| 38 | } // namespace rtc |
| 39 | |
| 40 | namespace webrtc { |
| 41 | |
Anton Sukhanov | 6b319e6 | 2019-05-17 14:48:23 -0700 | [diff] [blame^] | 42 | class DatagramTransportInterface; |
Piotr (Peter) Slatala | 0c02250 | 2018-12-28 10:39:39 -0800 | [diff] [blame] | 43 | class RtcEventLog; |
| 44 | |
Piotr (Peter) Slatala | 309aafe | 2019-01-15 14:24:34 -0800 | [diff] [blame] | 45 | class AudioPacketReceivedObserver { |
| 46 | public: |
| 47 | virtual ~AudioPacketReceivedObserver() = default; |
| 48 | |
| 49 | // Invoked for the first received audio packet on a given channel id. |
| 50 | // It will be invoked once for each channel id. |
| 51 | virtual void OnFirstAudioPacketReceived(int64_t channel_id) = 0; |
| 52 | }; |
| 53 | |
Piotr (Peter) Slatala | 946b968 | 2019-03-18 10:25:02 -0700 | [diff] [blame] | 54 | // Used to configure stream allocations. |
Piotr (Peter) Slatala | 48c5493 | 2019-01-28 06:50:38 -0800 | [diff] [blame] | 55 | struct MediaTransportAllocatedBitrateLimits { |
| 56 | DataRate min_pacing_rate = DataRate::Zero(); |
| 57 | DataRate max_padding_bitrate = DataRate::Zero(); |
| 58 | DataRate max_total_allocated_bitrate = DataRate::Zero(); |
| 59 | }; |
| 60 | |
Piotr (Peter) Slatala | 946b968 | 2019-03-18 10:25:02 -0700 | [diff] [blame] | 61 | // Used to configure target bitrate constraints. |
| 62 | // If the value is provided, the constraint is updated. |
| 63 | // If the value is omitted, the value is left unchanged. |
| 64 | struct MediaTransportTargetRateConstraints { |
| 65 | absl::optional<DataRate> min_bitrate; |
| 66 | absl::optional<DataRate> max_bitrate; |
| 67 | absl::optional<DataRate> starting_bitrate; |
| 68 | }; |
| 69 | |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 70 | // A collection of settings for creation of media transport. |
| 71 | struct MediaTransportSettings final { |
| 72 | MediaTransportSettings(); |
Piotr (Peter) Slatala | ed7b8b1 | 2018-10-29 10:43:16 -0700 | [diff] [blame] | 73 | MediaTransportSettings(const MediaTransportSettings&); |
| 74 | MediaTransportSettings& operator=(const MediaTransportSettings&); |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 75 | ~MediaTransportSettings(); |
| 76 | |
| 77 | // Group calls are not currently supported, in 1:1 call one side must set |
| 78 | // is_caller = true and another is_caller = false. |
| 79 | bool is_caller; |
| 80 | |
| 81 | // Must be set if a pre-shared key is used for the call. |
Piotr (Peter) Slatala | 9f95625 | 2018-10-31 08:25:26 -0700 | [diff] [blame] | 82 | // TODO(bugs.webrtc.org/9944): This should become zero buffer in the distant |
| 83 | // future. |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 84 | absl::optional<std::string> pre_shared_key; |
Piotr (Peter) Slatala | 0c02250 | 2018-12-28 10:39:39 -0800 | [diff] [blame] | 85 | |
Piotr (Peter) Slatala | d6f61dd | 2019-02-26 12:08:27 -0800 | [diff] [blame] | 86 | // If present, this is a config passed from the caller to the answerer in the |
| 87 | // offer. Each media transport knows how to understand its own parameters. |
| 88 | absl::optional<std::string> remote_transport_parameters; |
| 89 | |
Piotr (Peter) Slatala | 0c02250 | 2018-12-28 10:39:39 -0800 | [diff] [blame] | 90 | // If present, provides the event log that media transport should use. |
| 91 | // Media transport does not own it. The lifetime of |event_log| will exceed |
| 92 | // the lifetime of the instance of MediaTransportInterface instance. |
| 93 | RtcEventLog* event_log = nullptr; |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 96 | // Callback to notify about network route changes. |
| 97 | class MediaTransportNetworkChangeCallback { |
| 98 | public: |
| 99 | virtual ~MediaTransportNetworkChangeCallback() = default; |
| 100 | |
| 101 | // Called when the network route is changed, with the new network route. |
| 102 | virtual void OnNetworkRouteChanged( |
| 103 | const rtc::NetworkRoute& new_network_route) = 0; |
| 104 | }; |
| 105 | |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 106 | // State of the media transport. Media transport begins in the pending state. |
| 107 | // It transitions to writable when it is ready to send media. It may transition |
| 108 | // back to pending if the connection is blocked. It may transition to closed at |
| 109 | // any time. Closed is terminal: a transport will never re-open once closed. |
| 110 | enum class MediaTransportState { |
| 111 | kPending, |
| 112 | kWritable, |
| 113 | kClosed, |
| 114 | }; |
| 115 | |
| 116 | // Callback invoked whenever the state of the media transport changes. |
| 117 | class MediaTransportStateCallback { |
| 118 | public: |
| 119 | virtual ~MediaTransportStateCallback() = default; |
| 120 | |
| 121 | // Invoked whenever the state of the media transport changes. |
| 122 | virtual void OnStateChanged(MediaTransportState state) = 0; |
| 123 | }; |
| 124 | |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 125 | // Callback for RTT measurements on the receive side. |
| 126 | // TODO(nisse): Related interfaces: CallStatsObserver and RtcpRttStats. It's |
| 127 | // somewhat unclear what type of measurement is needed. It's used to configure |
| 128 | // NACK generation and playout buffer. Either raw measurement values or recent |
| 129 | // maximum would make sense for this use. Need consolidation of RTT signalling. |
| 130 | class MediaTransportRttObserver { |
| 131 | public: |
| 132 | virtual ~MediaTransportRttObserver() = default; |
| 133 | |
| 134 | // Invoked when a new RTT measurement is available, typically once per ACK. |
| 135 | virtual void OnRttUpdated(int64_t rtt_ms) = 0; |
| 136 | }; |
| 137 | |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 138 | // Supported types of application data messages. |
| 139 | enum class DataMessageType { |
| 140 | // Application data buffer with the binary bit unset. |
| 141 | kText, |
| 142 | |
| 143 | // Application data buffer with the binary bit set. |
| 144 | kBinary, |
| 145 | |
| 146 | // Transport-agnostic control messages, such as open or open-ack messages. |
| 147 | kControl, |
| 148 | }; |
| 149 | |
| 150 | // Parameters for sending data. The parameters may change from message to |
| 151 | // message, even within a single channel. For example, control messages may be |
| 152 | // sent reliably and in-order, even if the data channel is configured for |
| 153 | // unreliable delivery. |
| 154 | struct SendDataParams { |
| 155 | SendDataParams(); |
Niels Möller | e0446cb | 2018-11-30 09:35:52 +0100 | [diff] [blame] | 156 | SendDataParams(const SendDataParams&); |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 157 | |
| 158 | DataMessageType type = DataMessageType::kText; |
| 159 | |
| 160 | // Whether to deliver the message in order with respect to other ordered |
| 161 | // messages with the same channel_id. |
| 162 | bool ordered = false; |
| 163 | |
| 164 | // If set, the maximum number of times this message may be |
| 165 | // retransmitted by the transport before it is dropped. |
| 166 | // Setting this value to zero disables retransmission. |
| 167 | // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set |
| 168 | // simultaneously. |
| 169 | absl::optional<int> max_rtx_count; |
| 170 | |
| 171 | // If set, the maximum number of milliseconds for which the transport |
| 172 | // may retransmit this message before it is dropped. |
| 173 | // Setting this value to zero disables retransmission. |
| 174 | // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set |
| 175 | // simultaneously. |
| 176 | absl::optional<int> max_rtx_ms; |
| 177 | }; |
| 178 | |
| 179 | // Sink for callbacks related to a data channel. |
| 180 | class DataChannelSink { |
| 181 | public: |
| 182 | virtual ~DataChannelSink() = default; |
| 183 | |
| 184 | // Callback issued when data is received by the transport. |
| 185 | virtual void OnDataReceived(int channel_id, |
| 186 | DataMessageType type, |
| 187 | const rtc::CopyOnWriteBuffer& buffer) = 0; |
| 188 | |
| 189 | // Callback issued when a remote data channel begins the closing procedure. |
| 190 | // Messages sent after the closing procedure begins will not be transmitted. |
| 191 | virtual void OnChannelClosing(int channel_id) = 0; |
| 192 | |
| 193 | // Callback issued when a (remote or local) data channel completes the closing |
| 194 | // procedure. Closing channels become closed after all pending data has been |
| 195 | // transmitted. |
| 196 | virtual void OnChannelClosed(int channel_id) = 0; |
| 197 | }; |
| 198 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 199 | // Media transport interface for sending / receiving encoded audio/video frames |
| 200 | // and receiving bandwidth estimate update from congestion control. |
| 201 | class MediaTransportInterface { |
| 202 | public: |
Piotr (Peter) Slatala | 309aafe | 2019-01-15 14:24:34 -0800 | [diff] [blame] | 203 | MediaTransportInterface(); |
| 204 | virtual ~MediaTransportInterface(); |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 205 | |
Piotr (Peter) Slatala | d6f61dd | 2019-02-26 12:08:27 -0800 | [diff] [blame] | 206 | // Retrieves callers config (i.e. media transport offer) that should be passed |
| 207 | // to the callee, before the call is connected. Such config is opaque to SDP |
| 208 | // (sdp just passes it through). The config is a binary blob, so SDP may |
| 209 | // choose to use base64 to serialize it (or any other approach that guarantees |
| 210 | // that the binary blob goes through). This should only be called for the |
| 211 | // caller's perspective. |
| 212 | // |
| 213 | // This may return an unset optional, which means that the given media |
| 214 | // transport is not supported / disabled and shouldn't be reported in SDP. |
| 215 | // |
| 216 | // It may also return an empty string, in which case the media transport is |
| 217 | // supported, but without any extra settings. |
| 218 | // TODO(psla): Make abstract. |
| 219 | virtual absl::optional<std::string> GetTransportParametersOffer() const; |
| 220 | |
| 221 | // Connect the media transport to the ICE transport. |
| 222 | // The implementation must be able to ignore incoming packets that don't |
| 223 | // belong to it. |
| 224 | // TODO(psla): Make abstract. |
| 225 | virtual void Connect(rtc::PacketTransportInternal* packet_transport); |
| 226 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 227 | // Start asynchronous send of audio frame. The status returned by this method |
| 228 | // only pertains to the synchronous operations (e.g. |
| 229 | // serialization/packetization), not to the asynchronous operation. |
Sergey Silkin | e049eba | 2019-02-18 09:52:26 +0000 | [diff] [blame] | 230 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 231 | virtual RTCError SendAudioFrame(uint64_t channel_id, |
| 232 | MediaTransportEncodedAudioFrame frame) = 0; |
| 233 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 234 | // Start asynchronous send of video frame. The status returned by this method |
| 235 | // only pertains to the synchronous operations (e.g. |
| 236 | // serialization/packetization), not to the asynchronous operation. |
| 237 | virtual RTCError SendVideoFrame( |
| 238 | uint64_t channel_id, |
| 239 | const MediaTransportEncodedVideoFrame& frame) = 0; |
| 240 | |
Niels Möller | 1c7f5f6 | 2018-12-10 11:06:02 +0100 | [diff] [blame] | 241 | // Used by video sender to be notified on key frame requests. |
| 242 | virtual void SetKeyFrameRequestCallback( |
| 243 | MediaTransportKeyFrameRequestCallback* callback); |
| 244 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 245 | // Requests a keyframe for the particular channel (stream). The caller should |
| 246 | // check that the keyframe is not present in a jitter buffer already (i.e. |
| 247 | // don't request a keyframe if there is one that you will get from the jitter |
| 248 | // buffer in a moment). |
| 249 | virtual RTCError RequestKeyFrame(uint64_t channel_id) = 0; |
| 250 | |
| 251 | // Sets audio sink. Sink must be unset by calling SetReceiveAudioSink(nullptr) |
| 252 | // before the media transport is destroyed or before new sink is set. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 253 | virtual void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) = 0; |
| 254 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 255 | // Registers a video sink. Before destruction of media transport, you must |
| 256 | // pass a nullptr. |
| 257 | virtual void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) = 0; |
| 258 | |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 259 | // Adds a target bitrate observer. Before media transport is destructed |
| 260 | // the observer must be unregistered (by calling |
| 261 | // RemoveTargetTransferRateObserver). |
| 262 | // A newly registered observer will be called back with the latest recorded |
| 263 | // target rate, if available. |
| 264 | virtual void AddTargetTransferRateObserver( |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 265 | TargetTransferRateObserver* observer); |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 266 | |
| 267 | // Removes an existing |observer| from observers. If observer was never |
| 268 | // registered, an error is logged and method does nothing. |
| 269 | virtual void RemoveTargetTransferRateObserver( |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 270 | TargetTransferRateObserver* observer); |
| 271 | |
Piotr (Peter) Slatala | 309aafe | 2019-01-15 14:24:34 -0800 | [diff] [blame] | 272 | // Sets audio packets observer, which gets informed about incoming audio |
| 273 | // packets. Before destruction, the observer must be unregistered by setting |
| 274 | // nullptr. |
| 275 | // |
| 276 | // This method may be temporary, when the multiplexer is implemented (or |
| 277 | // multiplexer may use it to demultiplex channel ids). |
| 278 | virtual void SetFirstAudioPacketReceivedObserver( |
| 279 | AudioPacketReceivedObserver* observer); |
| 280 | |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 281 | // Intended for receive side. AddRttObserver registers an observer to be |
| 282 | // called for each RTT measurement, typically once per ACK. Before media |
| 283 | // transport is destructed the observer must be unregistered. |
| 284 | virtual void AddRttObserver(MediaTransportRttObserver* observer); |
| 285 | virtual void RemoveRttObserver(MediaTransportRttObserver* observer); |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 286 | |
| 287 | // Returns the last known target transfer rate as reported to the above |
| 288 | // observers. |
| 289 | virtual absl::optional<TargetTransferRate> GetLatestTargetTransferRate(); |
| 290 | |
| 291 | // Gets the audio packet overhead in bytes. Returned overhead does not include |
| 292 | // transport overhead (ipv4/6, turn channeldata, tcp/udp, etc.). |
| 293 | // If the transport is capable of fusing packets together, this overhead |
| 294 | // might not be a very accurate number. |
Niels Möller | d5af402 | 2019-03-05 08:56:48 +0100 | [diff] [blame] | 295 | // TODO(nisse): Deprecated. |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 296 | virtual size_t GetAudioPacketOverhead() const; |
| 297 | |
Niels Möller | d5af402 | 2019-03-05 08:56:48 +0100 | [diff] [blame] | 298 | // Corresponding observers for audio and video overhead. Before destruction, |
| 299 | // the observers must be unregistered by setting nullptr. |
| 300 | |
| 301 | // TODO(nisse): Should move to per-stream objects, since packetization |
| 302 | // overhead can vary per stream, e.g., depending on negotiated extensions. In |
| 303 | // addition, we should move towards reporting total overhead including all |
| 304 | // layers. Currently, overhead of the lower layers is reported elsewhere, |
| 305 | // e.g., on route change between IPv4 and IPv6. |
| 306 | virtual void SetAudioOverheadObserver(OverheadObserver* observer) {} |
| 307 | |
Niels Möller | d70a114 | 2019-02-06 17:36:29 +0100 | [diff] [blame] | 308 | // Registers an observer for network change events. If the network route is |
| 309 | // already established when the callback is added, |callback| will be called |
| 310 | // immediately with the current network route. Before media transport is |
| 311 | // destroyed, the callback must be removed. |
Niels Möller | 30b182a | 2019-02-05 00:59:35 +0100 | [diff] [blame] | 312 | virtual void AddNetworkChangeCallback( |
| 313 | MediaTransportNetworkChangeCallback* callback); |
| 314 | virtual void RemoveNetworkChangeCallback( |
| 315 | MediaTransportNetworkChangeCallback* callback); |
Piotr (Peter) Slatala | 6b9d823 | 2018-10-26 07:59:46 -0700 | [diff] [blame] | 316 | |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 317 | // Sets a state observer callback. Before media transport is destroyed, the |
| 318 | // callback must be unregistered by setting it to nullptr. |
| 319 | // A newly registered callback will be called with the current state. |
| 320 | // Media transport does not invoke this callback concurrently. |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 321 | virtual void SetMediaTransportStateCallback( |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 322 | MediaTransportStateCallback* callback) = 0; |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 323 | |
Piotr (Peter) Slatala | 48c5493 | 2019-01-28 06:50:38 -0800 | [diff] [blame] | 324 | // Updates allocation limits. |
| 325 | // TODO(psla): Make abstract when downstream implementation implement it. |
| 326 | virtual void SetAllocatedBitrateLimits( |
| 327 | const MediaTransportAllocatedBitrateLimits& limits); |
| 328 | |
Piotr (Peter) Slatala | 946b968 | 2019-03-18 10:25:02 -0700 | [diff] [blame] | 329 | // Sets starting rate. |
| 330 | // TODO(psla): Make abstract when downstream implementation implement it. |
| 331 | virtual void SetTargetBitrateLimits( |
| 332 | const MediaTransportTargetRateConstraints& target_rate_constraints) {} |
| 333 | |
Bjorn Mellem | f58e43e | 2019-02-22 10:31:48 -0800 | [diff] [blame] | 334 | // Opens a data |channel_id| for sending. May return an error if the |
| 335 | // specified |channel_id| is unusable. Must be called before |SendData|. |
Bjorn Mellem | 9ded485 | 2019-02-28 12:27:11 -0800 | [diff] [blame] | 336 | virtual RTCError OpenChannel(int channel_id) = 0; |
Bjorn Mellem | f58e43e | 2019-02-22 10:31:48 -0800 | [diff] [blame] | 337 | |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 338 | // Sends a data buffer to the remote endpoint using the given send parameters. |
| 339 | // |buffer| may not be larger than 256 KiB. Returns an error if the send |
| 340 | // fails. |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 341 | virtual RTCError SendData(int channel_id, |
| 342 | const SendDataParams& params, |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 343 | const rtc::CopyOnWriteBuffer& buffer) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 344 | |
| 345 | // Closes |channel_id| gracefully. Returns an error if |channel_id| is not |
| 346 | // open. Data sent after the closing procedure begins will not be |
| 347 | // transmitted. The channel becomes closed after pending data is transmitted. |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 348 | virtual RTCError CloseChannel(int channel_id) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 349 | |
| 350 | // Sets a sink for data messages and channel state callbacks. Before media |
| 351 | // transport is destroyed, the sink must be unregistered by setting it to |
| 352 | // nullptr. |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 353 | virtual void SetDataSink(DataChannelSink* sink) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 354 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 355 | // TODO(sukhanov): RtcEventLogs. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 356 | }; |
| 357 | |
| 358 | // If media transport factory is set in peer connection factory, it will be |
| 359 | // used to create media transport for sending/receiving encoded frames and |
| 360 | // this transport will be used instead of default RTP/SRTP transport. |
| 361 | // |
| 362 | // Currently Media Transport negotiation is not supported in SDP. |
| 363 | // If application is using media transport, it must negotiate it before |
| 364 | // setting media transport factory in peer connection. |
| 365 | class MediaTransportFactory { |
| 366 | public: |
| 367 | virtual ~MediaTransportFactory() = default; |
| 368 | |
| 369 | // Creates media transport. |
| 370 | // - Does not take ownership of packet_transport or network_thread. |
| 371 | // - Does not support group calls, in 1:1 call one side must set |
| 372 | // is_caller = true and another is_caller = false. |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 373 | virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>> |
| 374 | CreateMediaTransport(rtc::PacketTransportInternal* packet_transport, |
| 375 | rtc::Thread* network_thread, |
Piotr (Peter) Slatala | ed7b8b1 | 2018-10-29 10:43:16 -0700 | [diff] [blame] | 376 | const MediaTransportSettings& settings); |
Piotr (Peter) Slatala | d6f61dd | 2019-02-26 12:08:27 -0800 | [diff] [blame] | 377 | |
| 378 | // Creates a new Media Transport in a disconnected state. If the media |
| 379 | // transport for the caller is created, one can then call |
| 380 | // MediaTransportInterface::GetTransportParametersOffer on that new instance. |
| 381 | // TODO(psla): Make abstract. |
| 382 | virtual RTCErrorOr<std::unique_ptr<webrtc::MediaTransportInterface>> |
| 383 | CreateMediaTransport(rtc::Thread* network_thread, |
| 384 | const MediaTransportSettings& settings); |
| 385 | |
Anton Sukhanov | 6b319e6 | 2019-05-17 14:48:23 -0700 | [diff] [blame^] | 386 | // Creates a new Datagram Transport in a disconnected state. If the datagram |
| 387 | // transport for the caller is created, one can then call |
| 388 | // DatagramTransportInterface::GetTransportParametersOffer on that new |
| 389 | // instance. |
| 390 | // |
| 391 | // TODO(sukhanov): Consider separating media and datagram transport factories. |
| 392 | // TODO(sukhanov): Move factory to a separate .h file. |
| 393 | virtual RTCErrorOr<std::unique_ptr<DatagramTransportInterface>> |
| 394 | CreateDatagramTransport(rtc::Thread* network_thread, |
| 395 | const MediaTransportSettings& settings); |
| 396 | |
Piotr (Peter) Slatala | d6f61dd | 2019-02-26 12:08:27 -0800 | [diff] [blame] | 397 | // Gets a transport name which is supported by the implementation. |
| 398 | // Different factories should return different transport names, and at runtime |
| 399 | // it will be checked that different names were used. |
| 400 | // For example, "rtp" or "generic" may be returned by two different |
| 401 | // implementations. |
| 402 | // The value returned by this method must never change in the lifetime of the |
| 403 | // factory. |
| 404 | // TODO(psla): Make abstract. |
| 405 | virtual std::string GetTransportName() const; |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 406 | }; |
| 407 | |
| 408 | } // namespace webrtc |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 409 | #endif // API_MEDIA_TRANSPORT_INTERFACE_H_ |