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" |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 28 | #include "api/rtcerror.h" |
Niels Möller | 3a74239 | 2018-10-08 11:13:58 +0200 | [diff] [blame] | 29 | #include "api/video/encoded_image.h" |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 30 | #include "rtc_base/copyonwritebuffer.h" |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 31 | #include "rtc_base/networkroute.h" |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 32 | |
| 33 | namespace rtc { |
| 34 | class PacketTransportInternal; |
| 35 | class Thread; |
| 36 | } // namespace rtc |
| 37 | |
| 38 | namespace webrtc { |
| 39 | |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 40 | // A collection of settings for creation of media transport. |
| 41 | struct MediaTransportSettings final { |
| 42 | MediaTransportSettings(); |
Piotr (Peter) Slatala | ed7b8b1 | 2018-10-29 10:43:16 -0700 | [diff] [blame] | 43 | MediaTransportSettings(const MediaTransportSettings&); |
| 44 | MediaTransportSettings& operator=(const MediaTransportSettings&); |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 45 | ~MediaTransportSettings(); |
| 46 | |
| 47 | // Group calls are not currently supported, in 1:1 call one side must set |
| 48 | // is_caller = true and another is_caller = false. |
| 49 | bool is_caller; |
| 50 | |
| 51 | // 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] | 52 | // TODO(bugs.webrtc.org/9944): This should become zero buffer in the distant |
| 53 | // future. |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 54 | absl::optional<std::string> pre_shared_key; |
| 55 | }; |
| 56 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 57 | // Represents encoded audio frame in any encoding (type of encoding is opaque). |
| 58 | // To avoid copying of encoded data use move semantics when passing by value. |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 59 | class MediaTransportEncodedAudioFrame final { |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 60 | public: |
| 61 | enum class FrameType { |
| 62 | // Normal audio frame (equivalent to webrtc::kAudioFrameSpeech). |
| 63 | kSpeech, |
| 64 | |
| 65 | // DTX frame (equivalent to webrtc::kAudioFrameCN). |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 66 | // DTX frame (equivalent to webrtc::kAudioFrameCN). |
| 67 | kDiscontinuousTransmission, |
| 68 | // TODO(nisse): Mis-spelled version, update users, then delete. |
| 69 | kDiscountinuousTransmission = kDiscontinuousTransmission, |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | MediaTransportEncodedAudioFrame( |
| 73 | // Audio sampling rate, for example 48000. |
| 74 | int sampling_rate_hz, |
| 75 | |
| 76 | // Starting sample index of the frame, i.e. how many audio samples were |
| 77 | // before this frame since the beginning of the call or beginning of time |
| 78 | // in one channel (the starting point should not matter for NetEq). In |
| 79 | // WebRTC it is used as a timestamp of the frame. |
| 80 | // TODO(sukhanov): Starting_sample_index is currently adjusted on the |
| 81 | // receiver side in RTP path. Non-RTP implementations should preserve it. |
| 82 | // For NetEq initial offset should not matter so we should consider fixing |
| 83 | // RTP path. |
| 84 | int starting_sample_index, |
| 85 | |
| 86 | // Number of audio samples in audio frame in 1 channel. |
| 87 | int samples_per_channel, |
| 88 | |
| 89 | // Sequence number of the frame in the order sent, it is currently |
| 90 | // required by NetEq, but we can fix NetEq, because starting_sample_index |
| 91 | // should be enough. |
| 92 | int sequence_number, |
| 93 | |
| 94 | // If audio frame is a speech or discontinued transmission. |
| 95 | FrameType frame_type, |
| 96 | |
| 97 | // Opaque payload type. In RTP codepath payload type is stored in RTP |
| 98 | // header. In other implementations it should be simply passed through the |
| 99 | // wire -- it's needed for decoder. |
| 100 | uint8_t payload_type, |
| 101 | |
| 102 | // Vector with opaque encoded data. |
Niels Möller | 3a74239 | 2018-10-08 11:13:58 +0200 | [diff] [blame] | 103 | std::vector<uint8_t> encoded_data); |
| 104 | |
| 105 | ~MediaTransportEncodedAudioFrame(); |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 106 | MediaTransportEncodedAudioFrame(const MediaTransportEncodedAudioFrame&); |
| 107 | MediaTransportEncodedAudioFrame& operator=( |
| 108 | const MediaTransportEncodedAudioFrame& other); |
| 109 | MediaTransportEncodedAudioFrame& operator=( |
| 110 | MediaTransportEncodedAudioFrame&& other); |
| 111 | MediaTransportEncodedAudioFrame(MediaTransportEncodedAudioFrame&&); |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 112 | |
| 113 | // Getters. |
| 114 | int sampling_rate_hz() const { return sampling_rate_hz_; } |
| 115 | int starting_sample_index() const { return starting_sample_index_; } |
| 116 | int samples_per_channel() const { return samples_per_channel_; } |
| 117 | int sequence_number() const { return sequence_number_; } |
| 118 | |
| 119 | uint8_t payload_type() const { return payload_type_; } |
| 120 | FrameType frame_type() const { return frame_type_; } |
| 121 | |
| 122 | rtc::ArrayView<const uint8_t> encoded_data() const { return encoded_data_; } |
| 123 | |
| 124 | private: |
| 125 | int sampling_rate_hz_; |
| 126 | int starting_sample_index_; |
| 127 | int samples_per_channel_; |
| 128 | |
| 129 | // TODO(sukhanov): Refactor NetEq so we don't need sequence number. |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 130 | // Having sample_index and samples_per_channel should be enough. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 131 | int sequence_number_; |
| 132 | |
| 133 | FrameType frame_type_; |
| 134 | |
| 135 | // TODO(sukhanov): Consider enumerating allowed encodings and store enum |
| 136 | // instead of uint payload_type. |
| 137 | uint8_t payload_type_; |
| 138 | |
| 139 | std::vector<uint8_t> encoded_data_; |
| 140 | }; |
| 141 | |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 142 | // Callback to notify about network route changes. |
| 143 | class MediaTransportNetworkChangeCallback { |
| 144 | public: |
| 145 | virtual ~MediaTransportNetworkChangeCallback() = default; |
| 146 | |
| 147 | // Called when the network route is changed, with the new network route. |
| 148 | virtual void OnNetworkRouteChanged( |
| 149 | const rtc::NetworkRoute& new_network_route) = 0; |
| 150 | }; |
| 151 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 152 | // Interface for receiving encoded audio frames from MediaTransportInterface |
| 153 | // implementations. |
| 154 | class MediaTransportAudioSinkInterface { |
| 155 | public: |
| 156 | virtual ~MediaTransportAudioSinkInterface() = default; |
| 157 | |
| 158 | // Called when new encoded audio frame is received. |
| 159 | virtual void OnData(uint64_t channel_id, |
| 160 | MediaTransportEncodedAudioFrame frame) = 0; |
| 161 | }; |
| 162 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 163 | // Represents encoded video frame, along with the codec information. |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 164 | class MediaTransportEncodedVideoFrame final { |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 165 | public: |
| 166 | MediaTransportEncodedVideoFrame(int64_t frame_id, |
| 167 | std::vector<int64_t> referenced_frame_ids, |
| 168 | VideoCodecType codec_type, |
Niels Möller | 3a74239 | 2018-10-08 11:13:58 +0200 | [diff] [blame] | 169 | const webrtc::EncodedImage& encoded_image); |
| 170 | ~MediaTransportEncodedVideoFrame(); |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 171 | MediaTransportEncodedVideoFrame(const MediaTransportEncodedVideoFrame&); |
| 172 | MediaTransportEncodedVideoFrame& operator=( |
| 173 | const MediaTransportEncodedVideoFrame& other); |
| 174 | MediaTransportEncodedVideoFrame& operator=( |
| 175 | MediaTransportEncodedVideoFrame&& other); |
| 176 | MediaTransportEncodedVideoFrame(MediaTransportEncodedVideoFrame&&); |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 177 | |
| 178 | VideoCodecType codec_type() const { return codec_type_; } |
| 179 | const webrtc::EncodedImage& encoded_image() const { return encoded_image_; } |
| 180 | |
| 181 | int64_t frame_id() const { return frame_id_; } |
| 182 | const std::vector<int64_t>& referenced_frame_ids() const { |
| 183 | return referenced_frame_ids_; |
| 184 | } |
| 185 | |
Niels Möller | d5696fb | 2018-11-28 15:34:37 +0100 | [diff] [blame] | 186 | // Hack to workaround lack of ownership of the encoded_image_._buffer. If we |
| 187 | // don't already own the underlying data, make a copy. |
| 188 | void Retain(); |
| 189 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 190 | private: |
Niels Möller | d5696fb | 2018-11-28 15:34:37 +0100 | [diff] [blame] | 191 | MediaTransportEncodedVideoFrame(); |
| 192 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 193 | VideoCodecType codec_type_; |
| 194 | |
Niels Möller | d5696fb | 2018-11-28 15:34:37 +0100 | [diff] [blame] | 195 | // The buffer is not owned by the encoded image. On the sender it means that |
| 196 | // it will need to make a copy using the Retain() method, if it wants to |
| 197 | // deliver it asynchronously. |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 198 | webrtc::EncodedImage encoded_image_; |
| 199 | |
Niels Möller | d5696fb | 2018-11-28 15:34:37 +0100 | [diff] [blame] | 200 | // If non-empty, this is the data for the encoded image. |
| 201 | std::vector<uint8_t> encoded_data_; |
| 202 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 203 | // Frame id uniquely identifies a frame in a stream. It needs to be unique in |
| 204 | // a given time window (i.e. technically unique identifier for the lifetime of |
| 205 | // the connection is not needed, but you need to guarantee that remote side |
| 206 | // got rid of the previous frame_id if you plan to reuse it). |
| 207 | // |
| 208 | // It is required by a remote jitter buffer, and is the same as |
| 209 | // EncodedFrame::id::picture_id. |
| 210 | // |
| 211 | // This data must be opaque to the media transport, and media transport should |
| 212 | // itself not make any assumptions about what it is and its uniqueness. |
| 213 | int64_t frame_id_; |
| 214 | |
| 215 | // A single frame might depend on other frames. This is set of identifiers on |
| 216 | // which the current frame depends. |
| 217 | std::vector<int64_t> referenced_frame_ids_; |
| 218 | }; |
| 219 | |
| 220 | // Interface for receiving encoded video frames from MediaTransportInterface |
| 221 | // implementations. |
| 222 | class MediaTransportVideoSinkInterface { |
| 223 | public: |
| 224 | virtual ~MediaTransportVideoSinkInterface() = default; |
| 225 | |
| 226 | // Called when new encoded video frame is received. |
| 227 | virtual void OnData(uint64_t channel_id, |
| 228 | MediaTransportEncodedVideoFrame frame) = 0; |
| 229 | |
| 230 | // Called when the request for keyframe is received. |
| 231 | virtual void OnKeyFrameRequested(uint64_t channel_id) = 0; |
| 232 | }; |
| 233 | |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 234 | // State of the media transport. Media transport begins in the pending state. |
| 235 | // It transitions to writable when it is ready to send media. It may transition |
| 236 | // back to pending if the connection is blocked. It may transition to closed at |
| 237 | // any time. Closed is terminal: a transport will never re-open once closed. |
| 238 | enum class MediaTransportState { |
| 239 | kPending, |
| 240 | kWritable, |
| 241 | kClosed, |
| 242 | }; |
| 243 | |
| 244 | // Callback invoked whenever the state of the media transport changes. |
| 245 | class MediaTransportStateCallback { |
| 246 | public: |
| 247 | virtual ~MediaTransportStateCallback() = default; |
| 248 | |
| 249 | // Invoked whenever the state of the media transport changes. |
| 250 | virtual void OnStateChanged(MediaTransportState state) = 0; |
| 251 | }; |
| 252 | |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 253 | // Supported types of application data messages. |
| 254 | enum class DataMessageType { |
| 255 | // Application data buffer with the binary bit unset. |
| 256 | kText, |
| 257 | |
| 258 | // Application data buffer with the binary bit set. |
| 259 | kBinary, |
| 260 | |
| 261 | // Transport-agnostic control messages, such as open or open-ack messages. |
| 262 | kControl, |
| 263 | }; |
| 264 | |
| 265 | // Parameters for sending data. The parameters may change from message to |
| 266 | // message, even within a single channel. For example, control messages may be |
| 267 | // sent reliably and in-order, even if the data channel is configured for |
| 268 | // unreliable delivery. |
| 269 | struct SendDataParams { |
| 270 | SendDataParams(); |
Niels Möller | e0446cb | 2018-11-30 09:35:52 +0100 | [diff] [blame^] | 271 | SendDataParams(const SendDataParams&); |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 272 | |
| 273 | DataMessageType type = DataMessageType::kText; |
| 274 | |
| 275 | // Whether to deliver the message in order with respect to other ordered |
| 276 | // messages with the same channel_id. |
| 277 | bool ordered = false; |
| 278 | |
| 279 | // If set, the maximum number of times this message may be |
| 280 | // retransmitted by the transport before it is dropped. |
| 281 | // Setting this value to zero disables retransmission. |
| 282 | // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set |
| 283 | // simultaneously. |
| 284 | absl::optional<int> max_rtx_count; |
| 285 | |
| 286 | // If set, the maximum number of milliseconds for which the transport |
| 287 | // may retransmit this message before it is dropped. |
| 288 | // Setting this value to zero disables retransmission. |
| 289 | // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set |
| 290 | // simultaneously. |
| 291 | absl::optional<int> max_rtx_ms; |
| 292 | }; |
| 293 | |
| 294 | // Sink for callbacks related to a data channel. |
| 295 | class DataChannelSink { |
| 296 | public: |
| 297 | virtual ~DataChannelSink() = default; |
| 298 | |
| 299 | // Callback issued when data is received by the transport. |
| 300 | virtual void OnDataReceived(int channel_id, |
| 301 | DataMessageType type, |
| 302 | const rtc::CopyOnWriteBuffer& buffer) = 0; |
| 303 | |
| 304 | // Callback issued when a remote data channel begins the closing procedure. |
| 305 | // Messages sent after the closing procedure begins will not be transmitted. |
| 306 | virtual void OnChannelClosing(int channel_id) = 0; |
| 307 | |
| 308 | // Callback issued when a (remote or local) data channel completes the closing |
| 309 | // procedure. Closing channels become closed after all pending data has been |
| 310 | // transmitted. |
| 311 | virtual void OnChannelClosed(int channel_id) = 0; |
| 312 | }; |
| 313 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 314 | // Media transport interface for sending / receiving encoded audio/video frames |
| 315 | // and receiving bandwidth estimate update from congestion control. |
| 316 | class MediaTransportInterface { |
| 317 | public: |
| 318 | virtual ~MediaTransportInterface() = default; |
| 319 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 320 | // Start asynchronous send of audio frame. The status returned by this method |
| 321 | // only pertains to the synchronous operations (e.g. |
| 322 | // serialization/packetization), not to the asynchronous operation. |
| 323 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 324 | virtual RTCError SendAudioFrame(uint64_t channel_id, |
| 325 | MediaTransportEncodedAudioFrame frame) = 0; |
| 326 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 327 | // Start asynchronous send of video frame. The status returned by this method |
| 328 | // only pertains to the synchronous operations (e.g. |
| 329 | // serialization/packetization), not to the asynchronous operation. |
| 330 | virtual RTCError SendVideoFrame( |
| 331 | uint64_t channel_id, |
| 332 | const MediaTransportEncodedVideoFrame& frame) = 0; |
| 333 | |
| 334 | // Requests a keyframe for the particular channel (stream). The caller should |
| 335 | // check that the keyframe is not present in a jitter buffer already (i.e. |
| 336 | // don't request a keyframe if there is one that you will get from the jitter |
| 337 | // buffer in a moment). |
| 338 | virtual RTCError RequestKeyFrame(uint64_t channel_id) = 0; |
| 339 | |
| 340 | // Sets audio sink. Sink must be unset by calling SetReceiveAudioSink(nullptr) |
| 341 | // before the media transport is destroyed or before new sink is set. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 342 | virtual void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) = 0; |
| 343 | |
Piotr (Peter) Slatala | e804f92 | 2018-09-25 08:40:30 -0700 | [diff] [blame] | 344 | // Registers a video sink. Before destruction of media transport, you must |
| 345 | // pass a nullptr. |
| 346 | virtual void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) = 0; |
| 347 | |
Piotr (Peter) Slatala | ada077f | 2018-11-08 07:43:31 -0800 | [diff] [blame] | 348 | // Adds a target bitrate observer. Before media transport is destructed |
| 349 | // the observer must be unregistered (by calling |
| 350 | // RemoveTargetTransferRateObserver). |
| 351 | // A newly registered observer will be called back with the latest recorded |
| 352 | // target rate, if available. |
| 353 | virtual void AddTargetTransferRateObserver( |
| 354 | webrtc::TargetTransferRateObserver* observer); |
| 355 | |
| 356 | // Removes an existing |observer| from observers. If observer was never |
| 357 | // registered, an error is logged and method does nothing. |
| 358 | virtual void RemoveTargetTransferRateObserver( |
| 359 | webrtc::TargetTransferRateObserver* observer); |
| 360 | |
| 361 | // Returns the last known target transfer rate as reported to the above |
| 362 | // observers. |
| 363 | virtual absl::optional<TargetTransferRate> GetLatestTargetTransferRate(); |
| 364 | |
| 365 | // Gets the audio packet overhead in bytes. Returned overhead does not include |
| 366 | // transport overhead (ipv4/6, turn channeldata, tcp/udp, etc.). |
| 367 | // If the transport is capable of fusing packets together, this overhead |
| 368 | // might not be a very accurate number. |
| 369 | virtual size_t GetAudioPacketOverhead() const; |
| 370 | |
| 371 | // Sets an observer for network change events. If the network route is already |
| 372 | // established when the callback is set, |callback| will be called immediately |
| 373 | // with the current network route. |
| 374 | // Before media transport is destroyed, the callback must be unregistered by |
| 375 | // setting it to nullptr. |
| 376 | virtual void SetNetworkChangeCallback( |
| 377 | MediaTransportNetworkChangeCallback* callback); |
Piotr (Peter) Slatala | 6b9d823 | 2018-10-26 07:59:46 -0700 | [diff] [blame] | 378 | |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 379 | // Sets a state observer callback. Before media transport is destroyed, the |
| 380 | // callback must be unregistered by setting it to nullptr. |
| 381 | // A newly registered callback will be called with the current state. |
| 382 | // Media transport does not invoke this callback concurrently. |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 383 | virtual void SetMediaTransportStateCallback( |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 384 | MediaTransportStateCallback* callback) = 0; |
Bjorn Mellem | c78b0ea | 2018-10-29 15:21:31 -0700 | [diff] [blame] | 385 | |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 386 | // Sends a data buffer to the remote endpoint using the given send parameters. |
| 387 | // |buffer| may not be larger than 256 KiB. Returns an error if the send |
| 388 | // fails. |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 389 | virtual RTCError SendData(int channel_id, |
| 390 | const SendDataParams& params, |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 391 | const rtc::CopyOnWriteBuffer& buffer) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 392 | |
| 393 | // Closes |channel_id| gracefully. Returns an error if |channel_id| is not |
| 394 | // open. Data sent after the closing procedure begins will not be |
| 395 | // transmitted. The channel becomes closed after pending data is transmitted. |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 396 | virtual RTCError CloseChannel(int channel_id) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 397 | |
| 398 | // Sets a sink for data messages and channel state callbacks. Before media |
| 399 | // transport is destroyed, the sink must be unregistered by setting it to |
| 400 | // nullptr. |
Bjorn Mellem | eb2c641 | 2018-10-31 15:25:32 -0700 | [diff] [blame] | 401 | virtual void SetDataSink(DataChannelSink* sink) = 0; |
Bjorn Mellem | 1f6aa9f | 2018-10-30 15:15:00 -0700 | [diff] [blame] | 402 | |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 403 | // TODO(sukhanov): RtcEventLogs. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | // If media transport factory is set in peer connection factory, it will be |
| 407 | // used to create media transport for sending/receiving encoded frames and |
| 408 | // this transport will be used instead of default RTP/SRTP transport. |
| 409 | // |
| 410 | // Currently Media Transport negotiation is not supported in SDP. |
| 411 | // If application is using media transport, it must negotiate it before |
| 412 | // setting media transport factory in peer connection. |
| 413 | class MediaTransportFactory { |
| 414 | public: |
| 415 | virtual ~MediaTransportFactory() = default; |
| 416 | |
| 417 | // Creates media transport. |
| 418 | // - Does not take ownership of packet_transport or network_thread. |
| 419 | // - Does not support group calls, in 1:1 call one side must set |
| 420 | // is_caller = true and another is_caller = false. |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 421 | // TODO(bugs.webrtc.org/9938) This constructor will be removed and replaced |
| 422 | // with the one below. |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 423 | virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>> |
| 424 | CreateMediaTransport(rtc::PacketTransportInternal* packet_transport, |
| 425 | rtc::Thread* network_thread, |
Piotr (Peter) Slatala | a0677d1 | 2018-10-29 07:31:42 -0700 | [diff] [blame] | 426 | bool is_caller); |
| 427 | |
| 428 | // Creates media transport. |
| 429 | // - Does not take ownership of packet_transport or network_thread. |
| 430 | // TODO(bugs.webrtc.org/9938): remove default implementation once all children |
| 431 | // override it. |
| 432 | virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>> |
| 433 | CreateMediaTransport(rtc::PacketTransportInternal* packet_transport, |
| 434 | rtc::Thread* network_thread, |
Piotr (Peter) Slatala | ed7b8b1 | 2018-10-29 10:43:16 -0700 | [diff] [blame] | 435 | const MediaTransportSettings& settings); |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | } // namespace webrtc |
Anton Sukhanov | f60bd4b | 2018-09-05 13:41:46 -0400 | [diff] [blame] | 439 | #endif // API_MEDIA_TRANSPORT_INTERFACE_H_ |