blob: cc97b353e88c7cef35628885b4640499a2e9ed91 [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öllerfe6e50f2019-02-05 17:32:57 +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:
188 MediaTransportEncodedVideoFrame(int64_t frame_id,
189 std::vector<int64_t> referenced_frame_ids,
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100190 int payload_type,
Niels Möller3a742392018-10-08 11:13:58 +0200191 const webrtc::EncodedImage& encoded_image);
192 ~MediaTransportEncodedVideoFrame();
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700193 MediaTransportEncodedVideoFrame(const MediaTransportEncodedVideoFrame&);
194 MediaTransportEncodedVideoFrame& operator=(
195 const MediaTransportEncodedVideoFrame& other);
196 MediaTransportEncodedVideoFrame& operator=(
197 MediaTransportEncodedVideoFrame&& other);
198 MediaTransportEncodedVideoFrame(MediaTransportEncodedVideoFrame&&);
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700199
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100200 int payload_type() const { return payload_type_; }
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700201 const webrtc::EncodedImage& encoded_image() const { return encoded_image_; }
202
203 int64_t frame_id() const { return frame_id_; }
204 const std::vector<int64_t>& referenced_frame_ids() const {
205 return referenced_frame_ids_;
206 }
207
Niels Möllerd5696fb2018-11-28 15:34:37 +0100208 // Hack to workaround lack of ownership of the encoded_image_._buffer. If we
209 // don't already own the underlying data, make a copy.
210 void Retain();
211
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700212 private:
Niels Möllerd5696fb2018-11-28 15:34:37 +0100213 MediaTransportEncodedVideoFrame();
214
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100215 int payload_type_;
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700216
Niels Möllerd5696fb2018-11-28 15:34:37 +0100217 // The buffer is not owned by the encoded image. On the sender it means that
218 // it will need to make a copy using the Retain() method, if it wants to
219 // deliver it asynchronously.
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700220 webrtc::EncodedImage encoded_image_;
221
Niels Möllerd5696fb2018-11-28 15:34:37 +0100222 // If non-empty, this is the data for the encoded image.
223 std::vector<uint8_t> encoded_data_;
224
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700225 // Frame id uniquely identifies a frame in a stream. It needs to be unique in
226 // a given time window (i.e. technically unique identifier for the lifetime of
227 // the connection is not needed, but you need to guarantee that remote side
228 // got rid of the previous frame_id if you plan to reuse it).
229 //
230 // It is required by a remote jitter buffer, and is the same as
231 // EncodedFrame::id::picture_id.
232 //
233 // This data must be opaque to the media transport, and media transport should
234 // itself not make any assumptions about what it is and its uniqueness.
235 int64_t frame_id_;
236
237 // A single frame might depend on other frames. This is set of identifiers on
238 // which the current frame depends.
239 std::vector<int64_t> referenced_frame_ids_;
240};
241
242// Interface for receiving encoded video frames from MediaTransportInterface
243// implementations.
244class MediaTransportVideoSinkInterface {
245 public:
246 virtual ~MediaTransportVideoSinkInterface() = default;
247
248 // Called when new encoded video frame is received.
249 virtual void OnData(uint64_t channel_id,
250 MediaTransportEncodedVideoFrame frame) = 0;
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700251};
252
Niels Möller1c7f5f62018-12-10 11:06:02 +0100253// Interface for video sender to be notified of received key frame request.
254class MediaTransportKeyFrameRequestCallback {
255 public:
256 virtual ~MediaTransportKeyFrameRequestCallback() = default;
257
258 // Called when a key frame request is received on the transport.
259 virtual void OnKeyFrameRequested(uint64_t channel_id) = 0;
260};
261
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700262// State of the media transport. Media transport begins in the pending state.
263// It transitions to writable when it is ready to send media. It may transition
264// back to pending if the connection is blocked. It may transition to closed at
265// any time. Closed is terminal: a transport will never re-open once closed.
266enum class MediaTransportState {
267 kPending,
268 kWritable,
269 kClosed,
270};
271
272// Callback invoked whenever the state of the media transport changes.
273class MediaTransportStateCallback {
274 public:
275 virtual ~MediaTransportStateCallback() = default;
276
277 // Invoked whenever the state of the media transport changes.
278 virtual void OnStateChanged(MediaTransportState state) = 0;
279};
280
Niels Möller46879152019-01-07 15:54:47 +0100281// Callback for RTT measurements on the receive side.
282// TODO(nisse): Related interfaces: CallStatsObserver and RtcpRttStats. It's
283// somewhat unclear what type of measurement is needed. It's used to configure
284// NACK generation and playout buffer. Either raw measurement values or recent
285// maximum would make sense for this use. Need consolidation of RTT signalling.
286class MediaTransportRttObserver {
287 public:
288 virtual ~MediaTransportRttObserver() = default;
289
290 // Invoked when a new RTT measurement is available, typically once per ACK.
291 virtual void OnRttUpdated(int64_t rtt_ms) = 0;
292};
293
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700294// Supported types of application data messages.
295enum class DataMessageType {
296 // Application data buffer with the binary bit unset.
297 kText,
298
299 // Application data buffer with the binary bit set.
300 kBinary,
301
302 // Transport-agnostic control messages, such as open or open-ack messages.
303 kControl,
304};
305
306// Parameters for sending data. The parameters may change from message to
307// message, even within a single channel. For example, control messages may be
308// sent reliably and in-order, even if the data channel is configured for
309// unreliable delivery.
310struct SendDataParams {
311 SendDataParams();
Niels Möllere0446cb2018-11-30 09:35:52 +0100312 SendDataParams(const SendDataParams&);
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700313
314 DataMessageType type = DataMessageType::kText;
315
316 // Whether to deliver the message in order with respect to other ordered
317 // messages with the same channel_id.
318 bool ordered = false;
319
320 // If set, the maximum number of times this message may be
321 // retransmitted by the transport before it is dropped.
322 // Setting this value to zero disables retransmission.
323 // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set
324 // simultaneously.
325 absl::optional<int> max_rtx_count;
326
327 // If set, the maximum number of milliseconds for which the transport
328 // may retransmit this message before it is dropped.
329 // Setting this value to zero disables retransmission.
330 // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set
331 // simultaneously.
332 absl::optional<int> max_rtx_ms;
333};
334
335// Sink for callbacks related to a data channel.
336class DataChannelSink {
337 public:
338 virtual ~DataChannelSink() = default;
339
340 // Callback issued when data is received by the transport.
341 virtual void OnDataReceived(int channel_id,
342 DataMessageType type,
343 const rtc::CopyOnWriteBuffer& buffer) = 0;
344
345 // Callback issued when a remote data channel begins the closing procedure.
346 // Messages sent after the closing procedure begins will not be transmitted.
347 virtual void OnChannelClosing(int channel_id) = 0;
348
349 // Callback issued when a (remote or local) data channel completes the closing
350 // procedure. Closing channels become closed after all pending data has been
351 // transmitted.
352 virtual void OnChannelClosed(int channel_id) = 0;
353};
354
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400355// Media transport interface for sending / receiving encoded audio/video frames
356// and receiving bandwidth estimate update from congestion control.
357class MediaTransportInterface {
358 public:
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800359 MediaTransportInterface();
360 virtual ~MediaTransportInterface();
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400361
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700362 // Start asynchronous send of audio frame. The status returned by this method
363 // only pertains to the synchronous operations (e.g.
364 // serialization/packetization), not to the asynchronous operation.
365
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400366 virtual RTCError SendAudioFrame(uint64_t channel_id,
367 MediaTransportEncodedAudioFrame frame) = 0;
368
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700369 // Start asynchronous send of video frame. The status returned by this method
370 // only pertains to the synchronous operations (e.g.
371 // serialization/packetization), not to the asynchronous operation.
372 virtual RTCError SendVideoFrame(
373 uint64_t channel_id,
374 const MediaTransportEncodedVideoFrame& frame) = 0;
375
Niels Möller1c7f5f62018-12-10 11:06:02 +0100376 // Used by video sender to be notified on key frame requests.
377 virtual void SetKeyFrameRequestCallback(
378 MediaTransportKeyFrameRequestCallback* callback);
379
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700380 // Requests a keyframe for the particular channel (stream). The caller should
381 // check that the keyframe is not present in a jitter buffer already (i.e.
382 // don't request a keyframe if there is one that you will get from the jitter
383 // buffer in a moment).
384 virtual RTCError RequestKeyFrame(uint64_t channel_id) = 0;
385
386 // Sets audio sink. Sink must be unset by calling SetReceiveAudioSink(nullptr)
387 // before the media transport is destroyed or before new sink is set.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400388 virtual void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) = 0;
389
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700390 // Registers a video sink. Before destruction of media transport, you must
391 // pass a nullptr.
392 virtual void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) = 0;
393
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800394 // Adds a target bitrate observer. Before media transport is destructed
395 // the observer must be unregistered (by calling
396 // RemoveTargetTransferRateObserver).
397 // A newly registered observer will be called back with the latest recorded
398 // target rate, if available.
399 virtual void AddTargetTransferRateObserver(
Niels Möller46879152019-01-07 15:54:47 +0100400 TargetTransferRateObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800401
402 // Removes an existing |observer| from observers. If observer was never
403 // registered, an error is logged and method does nothing.
404 virtual void RemoveTargetTransferRateObserver(
Niels Möller46879152019-01-07 15:54:47 +0100405 TargetTransferRateObserver* observer);
406
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800407 // Sets audio packets observer, which gets informed about incoming audio
408 // packets. Before destruction, the observer must be unregistered by setting
409 // nullptr.
410 //
411 // This method may be temporary, when the multiplexer is implemented (or
412 // multiplexer may use it to demultiplex channel ids).
413 virtual void SetFirstAudioPacketReceivedObserver(
414 AudioPacketReceivedObserver* observer);
415
Niels Möller46879152019-01-07 15:54:47 +0100416 // Intended for receive side. AddRttObserver registers an observer to be
417 // called for each RTT measurement, typically once per ACK. Before media
418 // transport is destructed the observer must be unregistered.
419 virtual void AddRttObserver(MediaTransportRttObserver* observer);
420 virtual void RemoveRttObserver(MediaTransportRttObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800421
422 // Returns the last known target transfer rate as reported to the above
423 // observers.
424 virtual absl::optional<TargetTransferRate> GetLatestTargetTransferRate();
425
426 // Gets the audio packet overhead in bytes. Returned overhead does not include
427 // transport overhead (ipv4/6, turn channeldata, tcp/udp, etc.).
428 // If the transport is capable of fusing packets together, this overhead
429 // might not be a very accurate number.
430 virtual size_t GetAudioPacketOverhead() const;
431
432 // Sets an observer for network change events. If the network route is already
433 // established when the callback is set, |callback| will be called immediately
434 // with the current network route.
435 // Before media transport is destroyed, the callback must be unregistered by
436 // setting it to nullptr.
Niels Möller30b182a2019-02-05 00:59:35 +0100437 // TODO(nisse): The SetNetworkChangeCallback is being replaced with Add/Remove
438 // methods, because both video channel and voice channel need to register.
Niels Möllerfe6e50f2019-02-05 17:32:57 +0100439 RTC_DEPRECATED
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800440 virtual void SetNetworkChangeCallback(
441 MediaTransportNetworkChangeCallback* callback);
Niels Möller30b182a2019-02-05 00:59:35 +0100442 virtual void AddNetworkChangeCallback(
443 MediaTransportNetworkChangeCallback* callback);
444 virtual void RemoveNetworkChangeCallback(
445 MediaTransportNetworkChangeCallback* callback);
Piotr (Peter) Slatala6b9d8232018-10-26 07:59:46 -0700446
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700447 // Sets a state observer callback. Before media transport is destroyed, the
448 // callback must be unregistered by setting it to nullptr.
449 // A newly registered callback will be called with the current state.
450 // Media transport does not invoke this callback concurrently.
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700451 virtual void SetMediaTransportStateCallback(
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700452 MediaTransportStateCallback* callback) = 0;
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700453
Piotr (Peter) Slatala48c54932019-01-28 06:50:38 -0800454 // Updates allocation limits.
455 // TODO(psla): Make abstract when downstream implementation implement it.
456 virtual void SetAllocatedBitrateLimits(
457 const MediaTransportAllocatedBitrateLimits& limits);
458
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700459 // Sends a data buffer to the remote endpoint using the given send parameters.
460 // |buffer| may not be larger than 256 KiB. Returns an error if the send
461 // fails.
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700462 virtual RTCError SendData(int channel_id,
463 const SendDataParams& params,
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700464 const rtc::CopyOnWriteBuffer& buffer) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700465
466 // Closes |channel_id| gracefully. Returns an error if |channel_id| is not
467 // open. Data sent after the closing procedure begins will not be
468 // transmitted. The channel becomes closed after pending data is transmitted.
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700469 virtual RTCError CloseChannel(int channel_id) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700470
471 // Sets a sink for data messages and channel state callbacks. Before media
472 // transport is destroyed, the sink must be unregistered by setting it to
473 // nullptr.
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700474 virtual void SetDataSink(DataChannelSink* sink) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700475
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400476 // TODO(sukhanov): RtcEventLogs.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400477};
478
479// If media transport factory is set in peer connection factory, it will be
480// used to create media transport for sending/receiving encoded frames and
481// this transport will be used instead of default RTP/SRTP transport.
482//
483// Currently Media Transport negotiation is not supported in SDP.
484// If application is using media transport, it must negotiate it before
485// setting media transport factory in peer connection.
486class MediaTransportFactory {
487 public:
488 virtual ~MediaTransportFactory() = default;
489
490 // Creates media transport.
491 // - Does not take ownership of packet_transport or network_thread.
492 // - Does not support group calls, in 1:1 call one side must set
493 // is_caller = true and another is_caller = false.
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700494 // TODO(bugs.webrtc.org/9938) This constructor will be removed and replaced
495 // with the one below.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400496 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
497 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
498 rtc::Thread* network_thread,
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700499 bool is_caller);
500
501 // Creates media transport.
502 // - Does not take ownership of packet_transport or network_thread.
503 // TODO(bugs.webrtc.org/9938): remove default implementation once all children
504 // override it.
505 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
506 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
507 rtc::Thread* network_thread,
Piotr (Peter) Slatalaed7b8b12018-10-29 10:43:16 -0700508 const MediaTransportSettings& settings);
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400509};
510
511} // namespace webrtc
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400512#endif // API_MEDIA_TRANSPORT_INTERFACE_H_