blob: a46c99446ec8b2524f6157d55e8101f30b274106 [file] [log] [blame]
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -07001/* Copyright 2018 The WebRTC project authors. All Rights Reserved.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -04002 *
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) Slatala6b9d8232018-10-26 07:59:46 -070020#include <api/transport/network_control.h>
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040021#include <memory>
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070022#include <string>
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040023#include <utility>
24#include <vector>
25
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070026#include "absl/types/optional.h"
Yves Gerey988cc082018-10-23 12:03:01 +020027#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "api/rtc_error.h"
Piotr (Peter) Slatala48c54932019-01-28 06:50:38 -080029#include "api/units/data_rate.h"
Niels Möller3a742392018-10-08 11:13:58 +020030#include "api/video/encoded_image.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "rtc_base/copy_on_write_buffer.h"
Niels Möllerd8a1b7a2018-12-06 13:00:27 +010032#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080033#include "rtc_base/network_route.h"
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040034
35namespace rtc {
36class PacketTransportInternal;
37class Thread;
38} // namespace rtc
39
40namespace webrtc {
41
Piotr (Peter) Slatala0c022502018-12-28 10:39:39 -080042class RtcEventLog;
43
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -080044class AudioPacketReceivedObserver {
45 public:
46 virtual ~AudioPacketReceivedObserver() = default;
47
48 // Invoked for the first received audio packet on a given channel id.
49 // It will be invoked once for each channel id.
50 virtual void OnFirstAudioPacketReceived(int64_t channel_id) = 0;
51};
52
Piotr (Peter) Slatala48c54932019-01-28 06:50:38 -080053struct MediaTransportAllocatedBitrateLimits {
54 DataRate min_pacing_rate = DataRate::Zero();
55 DataRate max_padding_bitrate = DataRate::Zero();
56 DataRate max_total_allocated_bitrate = DataRate::Zero();
57};
58
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070059// A collection of settings for creation of media transport.
60struct MediaTransportSettings final {
61 MediaTransportSettings();
Piotr (Peter) Slatalaed7b8b12018-10-29 10:43:16 -070062 MediaTransportSettings(const MediaTransportSettings&);
63 MediaTransportSettings& operator=(const MediaTransportSettings&);
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070064 ~MediaTransportSettings();
65
66 // Group calls are not currently supported, in 1:1 call one side must set
67 // is_caller = true and another is_caller = false.
68 bool is_caller;
69
70 // Must be set if a pre-shared key is used for the call.
Piotr (Peter) Slatala9f956252018-10-31 08:25:26 -070071 // TODO(bugs.webrtc.org/9944): This should become zero buffer in the distant
72 // future.
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070073 absl::optional<std::string> pre_shared_key;
Piotr (Peter) Slatala0c022502018-12-28 10:39:39 -080074
75 // If present, provides the event log that media transport should use.
76 // Media transport does not own it. The lifetime of |event_log| will exceed
77 // the lifetime of the instance of MediaTransportInterface instance.
78 RtcEventLog* event_log = nullptr;
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070079};
80
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040081// Represents encoded audio frame in any encoding (type of encoding is opaque).
82// To avoid copying of encoded data use move semantics when passing by value.
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070083class MediaTransportEncodedAudioFrame final {
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040084 public:
85 enum class FrameType {
86 // Normal audio frame (equivalent to webrtc::kAudioFrameSpeech).
87 kSpeech,
88
89 // DTX frame (equivalent to webrtc::kAudioFrameCN).
Niels Möller7d76a312018-10-26 12:57:07 +020090 // DTX frame (equivalent to webrtc::kAudioFrameCN).
91 kDiscontinuousTransmission,
92 // TODO(nisse): Mis-spelled version, update users, then delete.
93 kDiscountinuousTransmission = kDiscontinuousTransmission,
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040094 };
95
96 MediaTransportEncodedAudioFrame(
97 // Audio sampling rate, for example 48000.
98 int sampling_rate_hz,
99
100 // Starting sample index of the frame, i.e. how many audio samples were
101 // before this frame since the beginning of the call or beginning of time
102 // in one channel (the starting point should not matter for NetEq). In
103 // WebRTC it is used as a timestamp of the frame.
104 // TODO(sukhanov): Starting_sample_index is currently adjusted on the
105 // receiver side in RTP path. Non-RTP implementations should preserve it.
106 // For NetEq initial offset should not matter so we should consider fixing
107 // RTP path.
108 int starting_sample_index,
109
110 // Number of audio samples in audio frame in 1 channel.
111 int samples_per_channel,
112
113 // Sequence number of the frame in the order sent, it is currently
114 // required by NetEq, but we can fix NetEq, because starting_sample_index
115 // should be enough.
116 int sequence_number,
117
118 // If audio frame is a speech or discontinued transmission.
119 FrameType frame_type,
120
121 // Opaque payload type. In RTP codepath payload type is stored in RTP
122 // header. In other implementations it should be simply passed through the
123 // wire -- it's needed for decoder.
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100124 int payload_type,
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400125
126 // Vector with opaque encoded data.
Niels Möller3a742392018-10-08 11:13:58 +0200127 std::vector<uint8_t> encoded_data);
128
129 ~MediaTransportEncodedAudioFrame();
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700130 MediaTransportEncodedAudioFrame(const MediaTransportEncodedAudioFrame&);
131 MediaTransportEncodedAudioFrame& operator=(
132 const MediaTransportEncodedAudioFrame& other);
133 MediaTransportEncodedAudioFrame& operator=(
134 MediaTransportEncodedAudioFrame&& other);
135 MediaTransportEncodedAudioFrame(MediaTransportEncodedAudioFrame&&);
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400136
137 // Getters.
138 int sampling_rate_hz() const { return sampling_rate_hz_; }
139 int starting_sample_index() const { return starting_sample_index_; }
140 int samples_per_channel() const { return samples_per_channel_; }
141 int sequence_number() const { return sequence_number_; }
142
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100143 int payload_type() const { return payload_type_; }
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400144 FrameType frame_type() const { return frame_type_; }
145
146 rtc::ArrayView<const uint8_t> encoded_data() const { return encoded_data_; }
147
148 private:
149 int sampling_rate_hz_;
150 int starting_sample_index_;
151 int samples_per_channel_;
152
153 // TODO(sukhanov): Refactor NetEq so we don't need sequence number.
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700154 // Having sample_index and samples_per_channel should be enough.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400155 int sequence_number_;
156
157 FrameType frame_type_;
158
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100159 int payload_type_;
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400160
161 std::vector<uint8_t> encoded_data_;
162};
163
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800164// Callback to notify about network route changes.
165class MediaTransportNetworkChangeCallback {
166 public:
167 virtual ~MediaTransportNetworkChangeCallback() = default;
168
169 // Called when the network route is changed, with the new network route.
170 virtual void OnNetworkRouteChanged(
171 const rtc::NetworkRoute& new_network_route) = 0;
172};
173
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400174// Interface for receiving encoded audio frames from MediaTransportInterface
175// implementations.
176class MediaTransportAudioSinkInterface {
177 public:
178 virtual ~MediaTransportAudioSinkInterface() = default;
179
180 // Called when new encoded audio frame is received.
181 virtual void OnData(uint64_t channel_id,
182 MediaTransportEncodedAudioFrame frame) = 0;
183};
184
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700185// Represents encoded video frame, along with the codec information.
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700186class MediaTransportEncodedVideoFrame final {
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700187 public:
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100188 // TODO(bugs.webrtc.org/9719): Switch to payload_type
189 RTC_DEPRECATED MediaTransportEncodedVideoFrame(
190 int64_t frame_id,
191 std::vector<int64_t> referenced_frame_ids,
192 VideoCodecType codec_type,
193 const webrtc::EncodedImage& encoded_image);
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700194 MediaTransportEncodedVideoFrame(int64_t frame_id,
195 std::vector<int64_t> referenced_frame_ids,
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100196 int payload_type,
Niels Möller3a742392018-10-08 11:13:58 +0200197 const webrtc::EncodedImage& encoded_image);
198 ~MediaTransportEncodedVideoFrame();
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700199 MediaTransportEncodedVideoFrame(const MediaTransportEncodedVideoFrame&);
200 MediaTransportEncodedVideoFrame& operator=(
201 const MediaTransportEncodedVideoFrame& other);
202 MediaTransportEncodedVideoFrame& operator=(
203 MediaTransportEncodedVideoFrame&& other);
204 MediaTransportEncodedVideoFrame(MediaTransportEncodedVideoFrame&&);
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700205
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100206 // TODO(bugs.webrtc.org/9719): Switch to payload_type
207 RTC_DEPRECATED VideoCodecType codec_type() const { return codec_type_; }
208 int payload_type() const { return payload_type_; }
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700209 const webrtc::EncodedImage& encoded_image() const { return encoded_image_; }
210
211 int64_t frame_id() const { return frame_id_; }
212 const std::vector<int64_t>& referenced_frame_ids() const {
213 return referenced_frame_ids_;
214 }
215
Niels Möllerd5696fb2018-11-28 15:34:37 +0100216 // Hack to workaround lack of ownership of the encoded_image_._buffer. If we
217 // don't already own the underlying data, make a copy.
218 void Retain();
219
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700220 private:
Niels Möllerd5696fb2018-11-28 15:34:37 +0100221 MediaTransportEncodedVideoFrame();
222
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700223 VideoCodecType codec_type_;
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100224 int payload_type_;
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700225
Niels Möllerd5696fb2018-11-28 15:34:37 +0100226 // The buffer is not owned by the encoded image. On the sender it means that
227 // it will need to make a copy using the Retain() method, if it wants to
228 // deliver it asynchronously.
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700229 webrtc::EncodedImage encoded_image_;
230
Niels Möllerd5696fb2018-11-28 15:34:37 +0100231 // If non-empty, this is the data for the encoded image.
232 std::vector<uint8_t> encoded_data_;
233
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700234 // Frame id uniquely identifies a frame in a stream. It needs to be unique in
235 // a given time window (i.e. technically unique identifier for the lifetime of
236 // the connection is not needed, but you need to guarantee that remote side
237 // got rid of the previous frame_id if you plan to reuse it).
238 //
239 // It is required by a remote jitter buffer, and is the same as
240 // EncodedFrame::id::picture_id.
241 //
242 // This data must be opaque to the media transport, and media transport should
243 // itself not make any assumptions about what it is and its uniqueness.
244 int64_t frame_id_;
245
246 // A single frame might depend on other frames. This is set of identifiers on
247 // which the current frame depends.
248 std::vector<int64_t> referenced_frame_ids_;
249};
250
251// Interface for receiving encoded video frames from MediaTransportInterface
252// implementations.
253class MediaTransportVideoSinkInterface {
254 public:
255 virtual ~MediaTransportVideoSinkInterface() = default;
256
257 // Called when new encoded video frame is received.
258 virtual void OnData(uint64_t channel_id,
259 MediaTransportEncodedVideoFrame frame) = 0;
260
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100261 // TODO(bugs.webrtc.org/9719): Belongs on send side, not receive side.
262 RTC_DEPRECATED virtual void OnKeyFrameRequested(uint64_t channel_id) {}
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700263};
264
Niels Möller1c7f5f62018-12-10 11:06:02 +0100265// Interface for video sender to be notified of received key frame request.
266class MediaTransportKeyFrameRequestCallback {
267 public:
268 virtual ~MediaTransportKeyFrameRequestCallback() = default;
269
270 // Called when a key frame request is received on the transport.
271 virtual void OnKeyFrameRequested(uint64_t channel_id) = 0;
272};
273
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700274// State of the media transport. Media transport begins in the pending state.
275// It transitions to writable when it is ready to send media. It may transition
276// back to pending if the connection is blocked. It may transition to closed at
277// any time. Closed is terminal: a transport will never re-open once closed.
278enum class MediaTransportState {
279 kPending,
280 kWritable,
281 kClosed,
282};
283
284// Callback invoked whenever the state of the media transport changes.
285class MediaTransportStateCallback {
286 public:
287 virtual ~MediaTransportStateCallback() = default;
288
289 // Invoked whenever the state of the media transport changes.
290 virtual void OnStateChanged(MediaTransportState state) = 0;
291};
292
Niels Möller46879152019-01-07 15:54:47 +0100293// Callback for RTT measurements on the receive side.
294// TODO(nisse): Related interfaces: CallStatsObserver and RtcpRttStats. It's
295// somewhat unclear what type of measurement is needed. It's used to configure
296// NACK generation and playout buffer. Either raw measurement values or recent
297// maximum would make sense for this use. Need consolidation of RTT signalling.
298class MediaTransportRttObserver {
299 public:
300 virtual ~MediaTransportRttObserver() = default;
301
302 // Invoked when a new RTT measurement is available, typically once per ACK.
303 virtual void OnRttUpdated(int64_t rtt_ms) = 0;
304};
305
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700306// Supported types of application data messages.
307enum class DataMessageType {
308 // Application data buffer with the binary bit unset.
309 kText,
310
311 // Application data buffer with the binary bit set.
312 kBinary,
313
314 // Transport-agnostic control messages, such as open or open-ack messages.
315 kControl,
316};
317
318// Parameters for sending data. The parameters may change from message to
319// message, even within a single channel. For example, control messages may be
320// sent reliably and in-order, even if the data channel is configured for
321// unreliable delivery.
322struct SendDataParams {
323 SendDataParams();
Niels Möllere0446cb2018-11-30 09:35:52 +0100324 SendDataParams(const SendDataParams&);
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700325
326 DataMessageType type = DataMessageType::kText;
327
328 // Whether to deliver the message in order with respect to other ordered
329 // messages with the same channel_id.
330 bool ordered = false;
331
332 // If set, the maximum number of times this message may be
333 // retransmitted by the transport before it is dropped.
334 // Setting this value to zero disables retransmission.
335 // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set
336 // simultaneously.
337 absl::optional<int> max_rtx_count;
338
339 // If set, the maximum number of milliseconds for which the transport
340 // may retransmit this message before it is dropped.
341 // Setting this value to zero disables retransmission.
342 // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set
343 // simultaneously.
344 absl::optional<int> max_rtx_ms;
345};
346
347// Sink for callbacks related to a data channel.
348class DataChannelSink {
349 public:
350 virtual ~DataChannelSink() = default;
351
352 // Callback issued when data is received by the transport.
353 virtual void OnDataReceived(int channel_id,
354 DataMessageType type,
355 const rtc::CopyOnWriteBuffer& buffer) = 0;
356
357 // Callback issued when a remote data channel begins the closing procedure.
358 // Messages sent after the closing procedure begins will not be transmitted.
359 virtual void OnChannelClosing(int channel_id) = 0;
360
361 // Callback issued when a (remote or local) data channel completes the closing
362 // procedure. Closing channels become closed after all pending data has been
363 // transmitted.
364 virtual void OnChannelClosed(int channel_id) = 0;
365};
366
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400367// Media transport interface for sending / receiving encoded audio/video frames
368// and receiving bandwidth estimate update from congestion control.
369class MediaTransportInterface {
370 public:
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800371 MediaTransportInterface();
372 virtual ~MediaTransportInterface();
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400373
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700374 // Start asynchronous send of audio frame. The status returned by this method
375 // only pertains to the synchronous operations (e.g.
376 // serialization/packetization), not to the asynchronous operation.
377
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400378 virtual RTCError SendAudioFrame(uint64_t channel_id,
379 MediaTransportEncodedAudioFrame frame) = 0;
380
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700381 // Start asynchronous send of video frame. The status returned by this method
382 // only pertains to the synchronous operations (e.g.
383 // serialization/packetization), not to the asynchronous operation.
384 virtual RTCError SendVideoFrame(
385 uint64_t channel_id,
386 const MediaTransportEncodedVideoFrame& frame) = 0;
387
Niels Möller1c7f5f62018-12-10 11:06:02 +0100388 // Used by video sender to be notified on key frame requests.
389 virtual void SetKeyFrameRequestCallback(
390 MediaTransportKeyFrameRequestCallback* callback);
391
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700392 // Requests a keyframe for the particular channel (stream). The caller should
393 // check that the keyframe is not present in a jitter buffer already (i.e.
394 // don't request a keyframe if there is one that you will get from the jitter
395 // buffer in a moment).
396 virtual RTCError RequestKeyFrame(uint64_t channel_id) = 0;
397
398 // Sets audio sink. Sink must be unset by calling SetReceiveAudioSink(nullptr)
399 // before the media transport is destroyed or before new sink is set.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400400 virtual void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) = 0;
401
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700402 // Registers a video sink. Before destruction of media transport, you must
403 // pass a nullptr.
404 virtual void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) = 0;
405
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800406 // Adds a target bitrate observer. Before media transport is destructed
407 // the observer must be unregistered (by calling
408 // RemoveTargetTransferRateObserver).
409 // A newly registered observer will be called back with the latest recorded
410 // target rate, if available.
411 virtual void AddTargetTransferRateObserver(
Niels Möller46879152019-01-07 15:54:47 +0100412 TargetTransferRateObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800413
414 // Removes an existing |observer| from observers. If observer was never
415 // registered, an error is logged and method does nothing.
416 virtual void RemoveTargetTransferRateObserver(
Niels Möller46879152019-01-07 15:54:47 +0100417 TargetTransferRateObserver* observer);
418
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800419 // Sets audio packets observer, which gets informed about incoming audio
420 // packets. Before destruction, the observer must be unregistered by setting
421 // nullptr.
422 //
423 // This method may be temporary, when the multiplexer is implemented (or
424 // multiplexer may use it to demultiplex channel ids).
425 virtual void SetFirstAudioPacketReceivedObserver(
426 AudioPacketReceivedObserver* observer);
427
Niels Möller46879152019-01-07 15:54:47 +0100428 // Intended for receive side. AddRttObserver registers an observer to be
429 // called for each RTT measurement, typically once per ACK. Before media
430 // transport is destructed the observer must be unregistered.
431 virtual void AddRttObserver(MediaTransportRttObserver* observer);
432 virtual void RemoveRttObserver(MediaTransportRttObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800433
434 // Returns the last known target transfer rate as reported to the above
435 // observers.
436 virtual absl::optional<TargetTransferRate> GetLatestTargetTransferRate();
437
438 // Gets the audio packet overhead in bytes. Returned overhead does not include
439 // transport overhead (ipv4/6, turn channeldata, tcp/udp, etc.).
440 // If the transport is capable of fusing packets together, this overhead
441 // might not be a very accurate number.
442 virtual size_t GetAudioPacketOverhead() const;
443
444 // Sets an observer for network change events. If the network route is already
445 // established when the callback is set, |callback| will be called immediately
446 // with the current network route.
447 // Before media transport is destroyed, the callback must be unregistered by
448 // setting it to nullptr.
449 virtual void SetNetworkChangeCallback(
450 MediaTransportNetworkChangeCallback* callback);
Piotr (Peter) Slatala6b9d8232018-10-26 07:59:46 -0700451
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700452 // Sets a state observer callback. Before media transport is destroyed, the
453 // callback must be unregistered by setting it to nullptr.
454 // A newly registered callback will be called with the current state.
455 // Media transport does not invoke this callback concurrently.
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700456 virtual void SetMediaTransportStateCallback(
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700457 MediaTransportStateCallback* callback) = 0;
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700458
Piotr (Peter) Slatala48c54932019-01-28 06:50:38 -0800459 // Updates allocation limits.
460 // TODO(psla): Make abstract when downstream implementation implement it.
461 virtual void SetAllocatedBitrateLimits(
462 const MediaTransportAllocatedBitrateLimits& limits);
463
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700464 // Sends a data buffer to the remote endpoint using the given send parameters.
465 // |buffer| may not be larger than 256 KiB. Returns an error if the send
466 // fails.
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700467 virtual RTCError SendData(int channel_id,
468 const SendDataParams& params,
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700469 const rtc::CopyOnWriteBuffer& buffer) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700470
471 // Closes |channel_id| gracefully. Returns an error if |channel_id| is not
472 // open. Data sent after the closing procedure begins will not be
473 // transmitted. The channel becomes closed after pending data is transmitted.
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700474 virtual RTCError CloseChannel(int channel_id) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700475
476 // Sets a sink for data messages and channel state callbacks. Before media
477 // transport is destroyed, the sink must be unregistered by setting it to
478 // nullptr.
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700479 virtual void SetDataSink(DataChannelSink* sink) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700480
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400481 // TODO(sukhanov): RtcEventLogs.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400482};
483
484// If media transport factory is set in peer connection factory, it will be
485// used to create media transport for sending/receiving encoded frames and
486// this transport will be used instead of default RTP/SRTP transport.
487//
488// Currently Media Transport negotiation is not supported in SDP.
489// If application is using media transport, it must negotiate it before
490// setting media transport factory in peer connection.
491class MediaTransportFactory {
492 public:
493 virtual ~MediaTransportFactory() = default;
494
495 // Creates media transport.
496 // - Does not take ownership of packet_transport or network_thread.
497 // - Does not support group calls, in 1:1 call one side must set
498 // is_caller = true and another is_caller = false.
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700499 // TODO(bugs.webrtc.org/9938) This constructor will be removed and replaced
500 // with the one below.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400501 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
502 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
503 rtc::Thread* network_thread,
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700504 bool is_caller);
505
506 // Creates media transport.
507 // - Does not take ownership of packet_transport or network_thread.
508 // TODO(bugs.webrtc.org/9938): remove default implementation once all children
509 // override it.
510 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
511 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
512 rtc::Thread* network_thread,
Piotr (Peter) Slatalaed7b8b12018-10-29 10:43:16 -0700513 const MediaTransportSettings& settings);
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400514};
515
516} // namespace webrtc
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400517#endif // API_MEDIA_TRANSPORT_INTERFACE_H_