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