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> |
| 24 | #include <vector> |
| 25 | |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 26 | #include "absl/types/optional.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 27 | #include "api/array_view.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "api/rtc_error.h" |
Niels Möller | ec3b9ff | 2019-02-08 00:28:39 +0100 | [diff] [blame^] | 29 | #include "api/transport/media/audio_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 | 3a74239 | 2018-10-08 11:13:58 +0200 | [diff] [blame] | 31 | #include "api/video/encoded_image.h" |
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 | |
Piotr (Peter) Slatala | 0c02250 | 2018-12-28 10:39:39 -0800 | [diff] [blame] | 42 | class RtcEventLog; |
| 43 | |
Piotr (Peter) Slatala | 309aafe | 2019-01-15 14:24:34 -0800 | [diff] [blame] | 44 | class AudioPacketReceivedObserver { |
| 45 | public: |
| 46 | virtual ~AudioPacketReceivedObserver() = default; |
| 47 | |
| 48 | // Invoked for the first received audio packet on a given channel id. |
| 49 | // It will be invoked once for each channel id. |
| 50 | virtual void OnFirstAudioPacketReceived(int64_t channel_id) = 0; |
| 51 | }; |
| 52 | |
Piotr (Peter) Slatala | 48c5493 | 2019-01-28 06:50:38 -0800 | [diff] [blame] | 53 | struct MediaTransportAllocatedBitrateLimits { |
| 54 | DataRate min_pacing_rate = DataRate::Zero(); |
| 55 | DataRate max_padding_bitrate = DataRate::Zero(); |
| 56 | DataRate max_total_allocated_bitrate = DataRate::Zero(); |
| 57 | }; |
| 58 | |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 59 | // A collection of settings for creation of media transport. |
| 60 | struct MediaTransportSettings final { |
| 61 | MediaTransportSettings(); |
Piotr (Peter) Slatala | ed7b8b1 | 2018-10-29 10:43:16 -0700 | [diff] [blame] | 62 | MediaTransportSettings(const MediaTransportSettings&); |
| 63 | MediaTransportSettings& operator=(const MediaTransportSettings&); |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 64 | ~MediaTransportSettings(); |
| 65 | |
| 66 | // Group calls are not currently supported, in 1:1 call one side must set |
| 67 | // is_caller = true and another is_caller = false. |
| 68 | bool is_caller; |
| 69 | |
| 70 | // 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] | 71 | // TODO(bugs.webrtc.org/9944): This should become zero buffer in the distant |
| 72 | // future. |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 73 | absl::optional<std::string> pre_shared_key; |
Piotr (Peter) Slatala | 0c02250 | 2018-12-28 10:39:39 -0800 | [diff] [blame] | 74 | |
| 75 | // If present, provides the event log that media transport should use. |
| 76 | // Media transport does not own it. The lifetime of |event_log| will exceed |
| 77 | // the lifetime of the instance of MediaTransportInterface instance. |
| 78 | RtcEventLog* event_log = nullptr; |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 81 | // Callback to notify about network route changes. |
| 82 | class MediaTransportNetworkChangeCallback { |
| 83 | public: |
| 84 | virtual ~MediaTransportNetworkChangeCallback() = default; |
| 85 | |
| 86 | // Called when the network route is changed, with the new network route. |
| 87 | virtual void OnNetworkRouteChanged( |
| 88 | const rtc::NetworkRoute& new_network_route) = 0; |
| 89 | }; |
| 90 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 91 | // Represents encoded video frame, along with the codec information. |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 92 | class MediaTransportEncodedVideoFrame final { |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 93 | public: |
| 94 | MediaTransportEncodedVideoFrame(int64_t frame_id, |
| 95 | std::vector<int64_t> referenced_frame_ids, |
Niels Möller | d8a1b7a | 2018-12-06 13:00:27 +0100 | [diff] [blame] | 96 | int payload_type, |
Niels Möller | 3a74239 | 2018-10-08 11:13:58 +0200 | [diff] [blame] | 97 | const webrtc::EncodedImage& encoded_image); |
| 98 | ~MediaTransportEncodedVideoFrame(); |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 99 | MediaTransportEncodedVideoFrame(const MediaTransportEncodedVideoFrame&); |
| 100 | MediaTransportEncodedVideoFrame& operator=( |
| 101 | const MediaTransportEncodedVideoFrame& other); |
| 102 | MediaTransportEncodedVideoFrame& operator=( |
| 103 | MediaTransportEncodedVideoFrame&& other); |
| 104 | MediaTransportEncodedVideoFrame(MediaTransportEncodedVideoFrame&&); |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 105 | |
Niels Möller | d8a1b7a | 2018-12-06 13:00:27 +0100 | [diff] [blame] | 106 | int payload_type() const { return payload_type_; } |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 107 | const webrtc::EncodedImage& encoded_image() const { return encoded_image_; } |
| 108 | |
| 109 | int64_t frame_id() const { return frame_id_; } |
| 110 | const std::vector<int64_t>& referenced_frame_ids() const { |
| 111 | return referenced_frame_ids_; |
| 112 | } |
| 113 | |
Niels Möller | 938dd9f | 2019-02-07 00:02:17 +0100 | [diff] [blame] | 114 | // Hack to workaround lack of ownership of the EncodedImage buffer. If we |
Niels Möller | d5696fb | 2018-11-28 15:34:37 +0100 | [diff] [blame] | 115 | // don't already own the underlying data, make a copy. |
Niels Möller | 938dd9f | 2019-02-07 00:02:17 +0100 | [diff] [blame] | 116 | void Retain() { encoded_image_.Retain(); } |
Niels Möller | d5696fb | 2018-11-28 15:34:37 +0100 | [diff] [blame] | 117 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 118 | private: |
Niels Möller | d5696fb | 2018-11-28 15:34:37 +0100 | [diff] [blame] | 119 | MediaTransportEncodedVideoFrame(); |
| 120 | |
Niels Möller | d8a1b7a | 2018-12-06 13:00:27 +0100 | [diff] [blame] | 121 | int payload_type_; |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 122 | |
Niels Möller | 938dd9f | 2019-02-07 00:02:17 +0100 | [diff] [blame] | 123 | // The buffer is not always owned by the encoded image. On the sender it means |
| 124 | // that it will need to make a copy using the Retain() method, if it wants to |
Niels Möller | d5696fb | 2018-11-28 15:34:37 +0100 | [diff] [blame] | 125 | // deliver it asynchronously. |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 126 | webrtc::EncodedImage encoded_image_; |
| 127 | |
| 128 | // Frame id uniquely identifies a frame in a stream. It needs to be unique in |
| 129 | // a given time window (i.e. technically unique identifier for the lifetime of |
| 130 | // the connection is not needed, but you need to guarantee that remote side |
| 131 | // got rid of the previous frame_id if you plan to reuse it). |
| 132 | // |
| 133 | // It is required by a remote jitter buffer, and is the same as |
| 134 | // EncodedFrame::id::picture_id. |
| 135 | // |
| 136 | // This data must be opaque to the media transport, and media transport should |
| 137 | // itself not make any assumptions about what it is and its uniqueness. |
| 138 | int64_t frame_id_; |
| 139 | |
| 140 | // A single frame might depend on other frames. This is set of identifiers on |
| 141 | // which the current frame depends. |
| 142 | std::vector<int64_t> referenced_frame_ids_; |
| 143 | }; |
| 144 | |
| 145 | // Interface for receiving encoded video frames from MediaTransportInterface |
| 146 | // implementations. |
| 147 | class MediaTransportVideoSinkInterface { |
| 148 | public: |
| 149 | virtual ~MediaTransportVideoSinkInterface() = default; |
| 150 | |
| 151 | // Called when new encoded video frame is received. |
| 152 | virtual void OnData(uint64_t channel_id, |
| 153 | MediaTransportEncodedVideoFrame frame) = 0; |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Niels Möller | 1c7f5f6 | 2018-12-10 11:06:02 +0100 | [diff] [blame] | 156 | // Interface for video sender to be notified of received key frame request. |
| 157 | class MediaTransportKeyFrameRequestCallback { |
| 158 | public: |
| 159 | virtual ~MediaTransportKeyFrameRequestCallback() = default; |
| 160 | |
| 161 | // Called when a key frame request is received on the transport. |
| 162 | virtual void OnKeyFrameRequested(uint64_t channel_id) = 0; |
| 163 | }; |
| 164 | |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 165 | // State of the media transport. Media transport begins in the pending state. |
| 166 | // It transitions to writable when it is ready to send media. It may transition |
| 167 | // back to pending if the connection is blocked. It may transition to closed at |
| 168 | // any time. Closed is terminal: a transport will never re-open once closed. |
| 169 | enum class MediaTransportState { |
| 170 | kPending, |
| 171 | kWritable, |
| 172 | kClosed, |
| 173 | }; |
| 174 | |
| 175 | // Callback invoked whenever the state of the media transport changes. |
| 176 | class MediaTransportStateCallback { |
| 177 | public: |
| 178 | virtual ~MediaTransportStateCallback() = default; |
| 179 | |
| 180 | // Invoked whenever the state of the media transport changes. |
| 181 | virtual void OnStateChanged(MediaTransportState state) = 0; |
| 182 | }; |
| 183 | |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 184 | // Callback for RTT measurements on the receive side. |
| 185 | // TODO(nisse): Related interfaces: CallStatsObserver and RtcpRttStats. It's |
| 186 | // somewhat unclear what type of measurement is needed. It's used to configure |
| 187 | // NACK generation and playout buffer. Either raw measurement values or recent |
| 188 | // maximum would make sense for this use. Need consolidation of RTT signalling. |
| 189 | class MediaTransportRttObserver { |
| 190 | public: |
| 191 | virtual ~MediaTransportRttObserver() = default; |
| 192 | |
| 193 | // Invoked when a new RTT measurement is available, typically once per ACK. |
| 194 | virtual void OnRttUpdated(int64_t rtt_ms) = 0; |
| 195 | }; |
| 196 | |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 197 | // Supported types of application data messages. |
| 198 | enum class DataMessageType { |
| 199 | // Application data buffer with the binary bit unset. |
| 200 | kText, |
| 201 | |
| 202 | // Application data buffer with the binary bit set. |
| 203 | kBinary, |
| 204 | |
| 205 | // Transport-agnostic control messages, such as open or open-ack messages. |
| 206 | kControl, |
| 207 | }; |
| 208 | |
| 209 | // Parameters for sending data. The parameters may change from message to |
| 210 | // message, even within a single channel. For example, control messages may be |
| 211 | // sent reliably and in-order, even if the data channel is configured for |
| 212 | // unreliable delivery. |
| 213 | struct SendDataParams { |
| 214 | SendDataParams(); |
Niels Möller | e0446cb | 2018-11-30 09:35:52 +0100 | [diff] [blame] | 215 | SendDataParams(const SendDataParams&); |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 216 | |
| 217 | DataMessageType type = DataMessageType::kText; |
| 218 | |
| 219 | // Whether to deliver the message in order with respect to other ordered |
| 220 | // messages with the same channel_id. |
| 221 | bool ordered = false; |
| 222 | |
| 223 | // If set, the maximum number of times this message may be |
| 224 | // retransmitted by the transport before it is dropped. |
| 225 | // Setting this value to zero disables retransmission. |
| 226 | // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set |
| 227 | // simultaneously. |
| 228 | absl::optional<int> max_rtx_count; |
| 229 | |
| 230 | // If set, the maximum number of milliseconds for which the transport |
| 231 | // may retransmit this message before it is dropped. |
| 232 | // Setting this value to zero disables retransmission. |
| 233 | // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set |
| 234 | // simultaneously. |
| 235 | absl::optional<int> max_rtx_ms; |
| 236 | }; |
| 237 | |
| 238 | // Sink for callbacks related to a data channel. |
| 239 | class DataChannelSink { |
| 240 | public: |
| 241 | virtual ~DataChannelSink() = default; |
| 242 | |
| 243 | // Callback issued when data is received by the transport. |
| 244 | virtual void OnDataReceived(int channel_id, |
| 245 | DataMessageType type, |
| 246 | const rtc::CopyOnWriteBuffer& buffer) = 0; |
| 247 | |
| 248 | // Callback issued when a remote data channel begins the closing procedure. |
| 249 | // Messages sent after the closing procedure begins will not be transmitted. |
| 250 | virtual void OnChannelClosing(int channel_id) = 0; |
| 251 | |
| 252 | // Callback issued when a (remote or local) data channel completes the closing |
| 253 | // procedure. Closing channels become closed after all pending data has been |
| 254 | // transmitted. |
| 255 | virtual void OnChannelClosed(int channel_id) = 0; |
| 256 | }; |
| 257 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 258 | // Media transport interface for sending / receiving encoded audio/video frames |
| 259 | // and receiving bandwidth estimate update from congestion control. |
| 260 | class MediaTransportInterface { |
| 261 | public: |
Piotr (Peter) Slatala | 309aafe | 2019-01-15 14:24:34 -0800 | [diff] [blame] | 262 | MediaTransportInterface(); |
| 263 | virtual ~MediaTransportInterface(); |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 264 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 265 | // Start asynchronous send of audio frame. The status returned by this method |
| 266 | // only pertains to the synchronous operations (e.g. |
| 267 | // serialization/packetization), not to the asynchronous operation. |
| 268 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 269 | virtual RTCError SendAudioFrame(uint64_t channel_id, |
| 270 | MediaTransportEncodedAudioFrame frame) = 0; |
| 271 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 272 | // Start asynchronous send of video frame. The status returned by this method |
| 273 | // only pertains to the synchronous operations (e.g. |
| 274 | // serialization/packetization), not to the asynchronous operation. |
| 275 | virtual RTCError SendVideoFrame( |
| 276 | uint64_t channel_id, |
| 277 | const MediaTransportEncodedVideoFrame& frame) = 0; |
| 278 | |
Niels Möller | 1c7f5f6 | 2018-12-10 11:06:02 +0100 | [diff] [blame] | 279 | // Used by video sender to be notified on key frame requests. |
| 280 | virtual void SetKeyFrameRequestCallback( |
| 281 | MediaTransportKeyFrameRequestCallback* callback); |
| 282 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 283 | // Requests a keyframe for the particular channel (stream). The caller should |
| 284 | // check that the keyframe is not present in a jitter buffer already (i.e. |
| 285 | // don't request a keyframe if there is one that you will get from the jitter |
| 286 | // buffer in a moment). |
| 287 | virtual RTCError RequestKeyFrame(uint64_t channel_id) = 0; |
| 288 | |
| 289 | // Sets audio sink. Sink must be unset by calling SetReceiveAudioSink(nullptr) |
| 290 | // before the media transport is destroyed or before new sink is set. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 291 | virtual void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) = 0; |
| 292 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 293 | // Registers a video sink. Before destruction of media transport, you must |
| 294 | // pass a nullptr. |
| 295 | virtual void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) = 0; |
| 296 | |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 297 | // Adds a target bitrate observer. Before media transport is destructed |
| 298 | // the observer must be unregistered (by calling |
| 299 | // RemoveTargetTransferRateObserver). |
| 300 | // A newly registered observer will be called back with the latest recorded |
| 301 | // target rate, if available. |
| 302 | virtual void AddTargetTransferRateObserver( |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 303 | TargetTransferRateObserver* observer); |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 304 | |
| 305 | // Removes an existing |observer| from observers. If observer was never |
| 306 | // registered, an error is logged and method does nothing. |
| 307 | virtual void RemoveTargetTransferRateObserver( |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 308 | TargetTransferRateObserver* observer); |
| 309 | |
Piotr (Peter) Slatala | 309aafe | 2019-01-15 14:24:34 -0800 | [diff] [blame] | 310 | // Sets audio packets observer, which gets informed about incoming audio |
| 311 | // packets. Before destruction, the observer must be unregistered by setting |
| 312 | // nullptr. |
| 313 | // |
| 314 | // This method may be temporary, when the multiplexer is implemented (or |
| 315 | // multiplexer may use it to demultiplex channel ids). |
| 316 | virtual void SetFirstAudioPacketReceivedObserver( |
| 317 | AudioPacketReceivedObserver* observer); |
| 318 | |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 319 | // Intended for receive side. AddRttObserver registers an observer to be |
| 320 | // called for each RTT measurement, typically once per ACK. Before media |
| 321 | // transport is destructed the observer must be unregistered. |
| 322 | virtual void AddRttObserver(MediaTransportRttObserver* observer); |
| 323 | virtual void RemoveRttObserver(MediaTransportRttObserver* observer); |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 324 | |
| 325 | // Returns the last known target transfer rate as reported to the above |
| 326 | // observers. |
| 327 | virtual absl::optional<TargetTransferRate> GetLatestTargetTransferRate(); |
| 328 | |
| 329 | // Gets the audio packet overhead in bytes. Returned overhead does not include |
| 330 | // transport overhead (ipv4/6, turn channeldata, tcp/udp, etc.). |
| 331 | // If the transport is capable of fusing packets together, this overhead |
| 332 | // might not be a very accurate number. |
| 333 | virtual size_t GetAudioPacketOverhead() const; |
| 334 | |
Niels Möller | d70a114 | 2019-02-06 17:36:29 +0100 | [diff] [blame] | 335 | // Registers an observer for network change events. If the network route is |
| 336 | // already established when the callback is added, |callback| will be called |
| 337 | // immediately with the current network route. Before media transport is |
| 338 | // destroyed, the callback must be removed. |
Niels Möller | 30b182a | 2019-02-05 00:59:35 +0100 | [diff] [blame] | 339 | virtual void AddNetworkChangeCallback( |
| 340 | MediaTransportNetworkChangeCallback* callback); |
| 341 | virtual void RemoveNetworkChangeCallback( |
| 342 | MediaTransportNetworkChangeCallback* callback); |
Piotr (Peter) Slatala | 6b9d823 | 2018-10-26 07:59:46 -0700 | [diff] [blame] | 343 | |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 344 | // Sets a state observer callback. Before media transport is destroyed, the |
| 345 | // callback must be unregistered by setting it to nullptr. |
| 346 | // A newly registered callback will be called with the current state. |
| 347 | // Media transport does not invoke this callback concurrently. |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 348 | virtual void SetMediaTransportStateCallback( |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 349 | MediaTransportStateCallback* callback) = 0; |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 350 | |
Piotr (Peter) Slatala | 48c5493 | 2019-01-28 06:50:38 -0800 | [diff] [blame] | 351 | // Updates allocation limits. |
| 352 | // TODO(psla): Make abstract when downstream implementation implement it. |
| 353 | virtual void SetAllocatedBitrateLimits( |
| 354 | const MediaTransportAllocatedBitrateLimits& limits); |
| 355 | |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 356 | // Sends a data buffer to the remote endpoint using the given send parameters. |
| 357 | // |buffer| may not be larger than 256 KiB. Returns an error if the send |
| 358 | // fails. |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 359 | virtual RTCError SendData(int channel_id, |
| 360 | const SendDataParams& params, |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 361 | const rtc::CopyOnWriteBuffer& buffer) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 362 | |
| 363 | // Closes |channel_id| gracefully. Returns an error if |channel_id| is not |
| 364 | // open. Data sent after the closing procedure begins will not be |
| 365 | // transmitted. The channel becomes closed after pending data is transmitted. |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 366 | virtual RTCError CloseChannel(int channel_id) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 367 | |
| 368 | // Sets a sink for data messages and channel state callbacks. Before media |
| 369 | // transport is destroyed, the sink must be unregistered by setting it to |
| 370 | // nullptr. |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 371 | virtual void SetDataSink(DataChannelSink* sink) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 372 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 373 | // TODO(sukhanov): RtcEventLogs. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 374 | }; |
| 375 | |
| 376 | // If media transport factory is set in peer connection factory, it will be |
| 377 | // used to create media transport for sending/receiving encoded frames and |
| 378 | // this transport will be used instead of default RTP/SRTP transport. |
| 379 | // |
| 380 | // Currently Media Transport negotiation is not supported in SDP. |
| 381 | // If application is using media transport, it must negotiate it before |
| 382 | // setting media transport factory in peer connection. |
| 383 | class MediaTransportFactory { |
| 384 | public: |
| 385 | virtual ~MediaTransportFactory() = default; |
| 386 | |
| 387 | // Creates media transport. |
| 388 | // - Does not take ownership of packet_transport or network_thread. |
| 389 | // - Does not support group calls, in 1:1 call one side must set |
| 390 | // is_caller = true and another is_caller = false. |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 391 | // TODO(bugs.webrtc.org/9938) This constructor will be removed and replaced |
| 392 | // with the one below. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 393 | virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>> |
| 394 | CreateMediaTransport(rtc::PacketTransportInternal* packet_transport, |
| 395 | rtc::Thread* network_thread, |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 396 | bool is_caller); |
| 397 | |
| 398 | // Creates media transport. |
| 399 | // - Does not take ownership of packet_transport or network_thread. |
| 400 | // TODO(bugs.webrtc.org/9938): remove default implementation once all children |
| 401 | // override it. |
| 402 | virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>> |
| 403 | CreateMediaTransport(rtc::PacketTransportInternal* packet_transport, |
| 404 | rtc::Thread* network_thread, |
Piotr (Peter) Slatala | ed7b8b1 | 2018-10-29 10:43:16 -0700 | [diff] [blame] | 405 | const MediaTransportSettings& settings); |
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_ |