blob: 5cd29234b6b40f73ef3f382e04b385058f6083f3 [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"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "rtc_base/network_route.h"
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040033
34namespace rtc {
35class PacketTransportInternal;
36class Thread;
37} // namespace rtc
38
39namespace webrtc {
40
Piotr (Peter) Slatala0c022502018-12-28 10:39:39 -080041class RtcEventLog;
42
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -080043class 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) Slatala48c54932019-01-28 06:50:38 -080052struct 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) Slatalaa0677d12018-10-29 07:31:42 -070058// A collection of settings for creation of media transport.
59struct MediaTransportSettings final {
60 MediaTransportSettings();
Piotr (Peter) Slatalaed7b8b12018-10-29 10:43:16 -070061 MediaTransportSettings(const MediaTransportSettings&);
62 MediaTransportSettings& operator=(const MediaTransportSettings&);
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070063 ~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) Slatala9f956252018-10-31 08:25:26 -070070 // TODO(bugs.webrtc.org/9944): This should become zero buffer in the distant
71 // future.
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070072 absl::optional<std::string> pre_shared_key;
Piotr (Peter) Slatala0c022502018-12-28 10:39:39 -080073
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) Slatalaa0677d12018-10-29 07:31:42 -070078};
79
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040080// 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) Slatalae0c2e972018-10-08 09:43:21 -070082class MediaTransportEncodedAudioFrame final {
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040083 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öller7d76a312018-10-26 12:57:07 +020089 // DTX frame (equivalent to webrtc::kAudioFrameCN).
90 kDiscontinuousTransmission,
91 // TODO(nisse): Mis-spelled version, update users, then delete.
92 kDiscountinuousTransmission = kDiscontinuousTransmission,
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040093 };
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öllerd8a1b7a2018-12-06 13:00:27 +0100123 int payload_type,
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400124
125 // Vector with opaque encoded data.
Niels Möller3a742392018-10-08 11:13:58 +0200126 std::vector<uint8_t> encoded_data);
127
128 ~MediaTransportEncodedAudioFrame();
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700129 MediaTransportEncodedAudioFrame(const MediaTransportEncodedAudioFrame&);
130 MediaTransportEncodedAudioFrame& operator=(
131 const MediaTransportEncodedAudioFrame& other);
132 MediaTransportEncodedAudioFrame& operator=(
133 MediaTransportEncodedAudioFrame&& other);
134 MediaTransportEncodedAudioFrame(MediaTransportEncodedAudioFrame&&);
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400135
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öllerd8a1b7a2018-12-06 13:00:27 +0100142 int payload_type() const { return payload_type_; }
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400143 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) Slatalae804f922018-09-25 08:40:30 -0700153 // Having sample_index and samples_per_channel should be enough.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400154 int sequence_number_;
155
156 FrameType frame_type_;
157
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100158 int payload_type_;
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400159
160 std::vector<uint8_t> encoded_data_;
161};
162
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800163// Callback to notify about network route changes.
164class 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 Sukhanovf60bd4b2018-09-05 13:41:46 -0400173// Interface for receiving encoded audio frames from MediaTransportInterface
174// implementations.
175class 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) Slatalae804f922018-09-25 08:40:30 -0700184// Represents encoded video frame, along with the codec information.
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700185class MediaTransportEncodedVideoFrame final {
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700186 public:
187 MediaTransportEncodedVideoFrame(int64_t frame_id,
188 std::vector<int64_t> referenced_frame_ids,
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100189 int payload_type,
Niels Möller3a742392018-10-08 11:13:58 +0200190 const webrtc::EncodedImage& encoded_image);
191 ~MediaTransportEncodedVideoFrame();
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700192 MediaTransportEncodedVideoFrame(const MediaTransportEncodedVideoFrame&);
193 MediaTransportEncodedVideoFrame& operator=(
194 const MediaTransportEncodedVideoFrame& other);
195 MediaTransportEncodedVideoFrame& operator=(
196 MediaTransportEncodedVideoFrame&& other);
197 MediaTransportEncodedVideoFrame(MediaTransportEncodedVideoFrame&&);
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700198
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100199 int payload_type() const { return payload_type_; }
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700200 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öller938dd9f2019-02-07 00:02:17 +0100207 // Hack to workaround lack of ownership of the EncodedImage buffer. If we
Niels Möllerd5696fb2018-11-28 15:34:37 +0100208 // don't already own the underlying data, make a copy.
Niels Möller938dd9f2019-02-07 00:02:17 +0100209 void Retain() { encoded_image_.Retain(); }
Niels Möllerd5696fb2018-11-28 15:34:37 +0100210
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700211 private:
Niels Möllerd5696fb2018-11-28 15:34:37 +0100212 MediaTransportEncodedVideoFrame();
213
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100214 int payload_type_;
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700215
Niels Möller938dd9f2019-02-07 00:02:17 +0100216 // The buffer is not always owned by the encoded image. On the sender it means
217 // that it will need to make a copy using the Retain() method, if it wants to
Niels Möllerd5696fb2018-11-28 15:34:37 +0100218 // deliver it asynchronously.
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700219 webrtc::EncodedImage encoded_image_;
220
221 // Frame id uniquely identifies a frame in a stream. It needs to be unique in
222 // a given time window (i.e. technically unique identifier for the lifetime of
223 // the connection is not needed, but you need to guarantee that remote side
224 // got rid of the previous frame_id if you plan to reuse it).
225 //
226 // It is required by a remote jitter buffer, and is the same as
227 // EncodedFrame::id::picture_id.
228 //
229 // This data must be opaque to the media transport, and media transport should
230 // itself not make any assumptions about what it is and its uniqueness.
231 int64_t frame_id_;
232
233 // A single frame might depend on other frames. This is set of identifiers on
234 // which the current frame depends.
235 std::vector<int64_t> referenced_frame_ids_;
236};
237
238// Interface for receiving encoded video frames from MediaTransportInterface
239// implementations.
240class MediaTransportVideoSinkInterface {
241 public:
242 virtual ~MediaTransportVideoSinkInterface() = default;
243
244 // Called when new encoded video frame is received.
245 virtual void OnData(uint64_t channel_id,
246 MediaTransportEncodedVideoFrame frame) = 0;
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700247};
248
Niels Möller1c7f5f62018-12-10 11:06:02 +0100249// Interface for video sender to be notified of received key frame request.
250class 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 Mellemc78b0ea2018-10-29 15:21:31 -0700258// 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.
262enum class MediaTransportState {
263 kPending,
264 kWritable,
265 kClosed,
266};
267
268// Callback invoked whenever the state of the media transport changes.
269class 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öller46879152019-01-07 15:54:47 +0100277// 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.
282class 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 Mellem1f6aa9f2018-10-30 15:15:00 -0700290// Supported types of application data messages.
291enum 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.
306struct SendDataParams {
307 SendDataParams();
Niels Möllere0446cb2018-11-30 09:35:52 +0100308 SendDataParams(const SendDataParams&);
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700309
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.
332class 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 Sukhanovf60bd4b2018-09-05 13:41:46 -0400351// Media transport interface for sending / receiving encoded audio/video frames
352// and receiving bandwidth estimate update from congestion control.
353class MediaTransportInterface {
354 public:
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800355 MediaTransportInterface();
356 virtual ~MediaTransportInterface();
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400357
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700358 // Start asynchronous send of audio frame. The status returned by this method
359 // only pertains to the synchronous operations (e.g.
360 // serialization/packetization), not to the asynchronous operation.
361
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400362 virtual RTCError SendAudioFrame(uint64_t channel_id,
363 MediaTransportEncodedAudioFrame frame) = 0;
364
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700365 // Start asynchronous send of video frame. The status returned by this method
366 // only pertains to the synchronous operations (e.g.
367 // serialization/packetization), not to the asynchronous operation.
368 virtual RTCError SendVideoFrame(
369 uint64_t channel_id,
370 const MediaTransportEncodedVideoFrame& frame) = 0;
371
Niels Möller1c7f5f62018-12-10 11:06:02 +0100372 // Used by video sender to be notified on key frame requests.
373 virtual void SetKeyFrameRequestCallback(
374 MediaTransportKeyFrameRequestCallback* callback);
375
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700376 // Requests a keyframe for the particular channel (stream). The caller should
377 // check that the keyframe is not present in a jitter buffer already (i.e.
378 // don't request a keyframe if there is one that you will get from the jitter
379 // buffer in a moment).
380 virtual RTCError RequestKeyFrame(uint64_t channel_id) = 0;
381
382 // Sets audio sink. Sink must be unset by calling SetReceiveAudioSink(nullptr)
383 // before the media transport is destroyed or before new sink is set.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400384 virtual void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) = 0;
385
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700386 // Registers a video sink. Before destruction of media transport, you must
387 // pass a nullptr.
388 virtual void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) = 0;
389
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800390 // Adds a target bitrate observer. Before media transport is destructed
391 // the observer must be unregistered (by calling
392 // RemoveTargetTransferRateObserver).
393 // A newly registered observer will be called back with the latest recorded
394 // target rate, if available.
395 virtual void AddTargetTransferRateObserver(
Niels Möller46879152019-01-07 15:54:47 +0100396 TargetTransferRateObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800397
398 // Removes an existing |observer| from observers. If observer was never
399 // registered, an error is logged and method does nothing.
400 virtual void RemoveTargetTransferRateObserver(
Niels Möller46879152019-01-07 15:54:47 +0100401 TargetTransferRateObserver* observer);
402
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800403 // Sets audio packets observer, which gets informed about incoming audio
404 // packets. Before destruction, the observer must be unregistered by setting
405 // nullptr.
406 //
407 // This method may be temporary, when the multiplexer is implemented (or
408 // multiplexer may use it to demultiplex channel ids).
409 virtual void SetFirstAudioPacketReceivedObserver(
410 AudioPacketReceivedObserver* observer);
411
Niels Möller46879152019-01-07 15:54:47 +0100412 // Intended for receive side. AddRttObserver registers an observer to be
413 // called for each RTT measurement, typically once per ACK. Before media
414 // transport is destructed the observer must be unregistered.
415 virtual void AddRttObserver(MediaTransportRttObserver* observer);
416 virtual void RemoveRttObserver(MediaTransportRttObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800417
418 // Returns the last known target transfer rate as reported to the above
419 // observers.
420 virtual absl::optional<TargetTransferRate> GetLatestTargetTransferRate();
421
422 // Gets the audio packet overhead in bytes. Returned overhead does not include
423 // transport overhead (ipv4/6, turn channeldata, tcp/udp, etc.).
424 // If the transport is capable of fusing packets together, this overhead
425 // might not be a very accurate number.
426 virtual size_t GetAudioPacketOverhead() const;
427
Niels Möllerd70a1142019-02-06 17:36:29 +0100428 // Registers an observer for network change events. If the network route is
429 // already established when the callback is added, |callback| will be called
430 // immediately with the current network route. Before media transport is
431 // destroyed, the callback must be removed.
Niels Möller30b182a2019-02-05 00:59:35 +0100432 virtual void AddNetworkChangeCallback(
433 MediaTransportNetworkChangeCallback* callback);
434 virtual void RemoveNetworkChangeCallback(
435 MediaTransportNetworkChangeCallback* callback);
Piotr (Peter) Slatala6b9d8232018-10-26 07:59:46 -0700436
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700437 // Sets a state observer callback. Before media transport is destroyed, the
438 // callback must be unregistered by setting it to nullptr.
439 // A newly registered callback will be called with the current state.
440 // Media transport does not invoke this callback concurrently.
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700441 virtual void SetMediaTransportStateCallback(
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700442 MediaTransportStateCallback* callback) = 0;
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700443
Piotr (Peter) Slatala48c54932019-01-28 06:50:38 -0800444 // Updates allocation limits.
445 // TODO(psla): Make abstract when downstream implementation implement it.
446 virtual void SetAllocatedBitrateLimits(
447 const MediaTransportAllocatedBitrateLimits& limits);
448
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700449 // Sends a data buffer to the remote endpoint using the given send parameters.
450 // |buffer| may not be larger than 256 KiB. Returns an error if the send
451 // fails.
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700452 virtual RTCError SendData(int channel_id,
453 const SendDataParams& params,
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700454 const rtc::CopyOnWriteBuffer& buffer) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700455
456 // Closes |channel_id| gracefully. Returns an error if |channel_id| is not
457 // open. Data sent after the closing procedure begins will not be
458 // transmitted. The channel becomes closed after pending data is transmitted.
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700459 virtual RTCError CloseChannel(int channel_id) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700460
461 // Sets a sink for data messages and channel state callbacks. Before media
462 // transport is destroyed, the sink must be unregistered by setting it to
463 // nullptr.
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700464 virtual void SetDataSink(DataChannelSink* sink) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700465
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400466 // TODO(sukhanov): RtcEventLogs.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400467};
468
469// If media transport factory is set in peer connection factory, it will be
470// used to create media transport for sending/receiving encoded frames and
471// this transport will be used instead of default RTP/SRTP transport.
472//
473// Currently Media Transport negotiation is not supported in SDP.
474// If application is using media transport, it must negotiate it before
475// setting media transport factory in peer connection.
476class MediaTransportFactory {
477 public:
478 virtual ~MediaTransportFactory() = default;
479
480 // Creates media transport.
481 // - Does not take ownership of packet_transport or network_thread.
482 // - Does not support group calls, in 1:1 call one side must set
483 // is_caller = true and another is_caller = false.
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700484 // TODO(bugs.webrtc.org/9938) This constructor will be removed and replaced
485 // with the one below.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400486 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
487 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
488 rtc::Thread* network_thread,
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700489 bool is_caller);
490
491 // Creates media transport.
492 // - Does not take ownership of packet_transport or network_thread.
493 // TODO(bugs.webrtc.org/9938): remove default implementation once all children
494 // override it.
495 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
496 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
497 rtc::Thread* network_thread,
Piotr (Peter) Slatalaed7b8b12018-10-29 10:43:16 -0700498 const MediaTransportSettings& settings);
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400499};
500
501} // namespace webrtc
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400502#endif // API_MEDIA_TRANSPORT_INTERFACE_H_