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