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