blob: ad1f7c6ed35c5d8c3bc7e0538dc94a1fa914b005 [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öllerd5696fb2018-11-28 15:34:37 +0100207 // 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) 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öllerd5696fb2018-11-28 15:34:37 +0100216 // 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) Slatalae804f922018-09-25 08:40:30 -0700219 webrtc::EncodedImage encoded_image_;
220
Niels Möllerd5696fb2018-11-28 15:34:37 +0100221 // If non-empty, this is the data for the encoded image.
222 std::vector<uint8_t> encoded_data_;
223
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700224 // 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.
243class 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) Slatalae804f922018-09-25 08:40:30 -0700250};
251
Niels Möller1c7f5f62018-12-10 11:06:02 +0100252// Interface for video sender to be notified of received key frame request.
253class 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 Mellemc78b0ea2018-10-29 15:21:31 -0700261// 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.
265enum class MediaTransportState {
266 kPending,
267 kWritable,
268 kClosed,
269};
270
271// Callback invoked whenever the state of the media transport changes.
272class 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öller46879152019-01-07 15:54:47 +0100280// 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.
285class 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 Mellem1f6aa9f2018-10-30 15:15:00 -0700293// Supported types of application data messages.
294enum 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.
309struct SendDataParams {
310 SendDataParams();
Niels Möllere0446cb2018-11-30 09:35:52 +0100311 SendDataParams(const SendDataParams&);
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700312
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.
335class 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 Sukhanovf60bd4b2018-09-05 13:41:46 -0400354// Media transport interface for sending / receiving encoded audio/video frames
355// and receiving bandwidth estimate update from congestion control.
356class MediaTransportInterface {
357 public:
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800358 MediaTransportInterface();
359 virtual ~MediaTransportInterface();
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400360
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700361 // 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 Sukhanovf60bd4b2018-09-05 13:41:46 -0400365 virtual RTCError SendAudioFrame(uint64_t channel_id,
366 MediaTransportEncodedAudioFrame frame) = 0;
367
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700368 // 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öller1c7f5f62018-12-10 11:06:02 +0100375 // Used by video sender to be notified on key frame requests.
376 virtual void SetKeyFrameRequestCallback(
377 MediaTransportKeyFrameRequestCallback* callback);
378
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700379 // 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 Sukhanovf60bd4b2018-09-05 13:41:46 -0400387 virtual void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) = 0;
388
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700389 // 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) Slatalaada077f2018-11-08 07:43:31 -0800393 // 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öller46879152019-01-07 15:54:47 +0100399 TargetTransferRateObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800400
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öller46879152019-01-07 15:54:47 +0100404 TargetTransferRateObserver* observer);
405
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800406 // 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öller46879152019-01-07 15:54:47 +0100415 // 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) Slatalaada077f2018-11-08 07:43:31 -0800420
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öller30b182a2019-02-05 00:59:35 +0100436 // TODO(nisse): The SetNetworkChangeCallback is being replaced with Add/Remove
437 // methods, because both video channel and voice channel need to register.
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800438 virtual void SetNetworkChangeCallback(
439 MediaTransportNetworkChangeCallback* callback);
Niels Möller30b182a2019-02-05 00:59:35 +0100440 virtual void AddNetworkChangeCallback(
441 MediaTransportNetworkChangeCallback* callback);
442 virtual void RemoveNetworkChangeCallback(
443 MediaTransportNetworkChangeCallback* callback);
Piotr (Peter) Slatala6b9d8232018-10-26 07:59:46 -0700444
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700445 // 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 Mellemc78b0ea2018-10-29 15:21:31 -0700449 virtual void SetMediaTransportStateCallback(
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700450 MediaTransportStateCallback* callback) = 0;
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700451
Piotr (Peter) Slatala48c54932019-01-28 06:50:38 -0800452 // Updates allocation limits.
453 // TODO(psla): Make abstract when downstream implementation implement it.
454 virtual void SetAllocatedBitrateLimits(
455 const MediaTransportAllocatedBitrateLimits& limits);
456
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700457 // 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 Mellem1f6aa9f2018-10-30 15:15:00 -0700460 virtual RTCError SendData(int channel_id,
461 const SendDataParams& params,
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700462 const rtc::CopyOnWriteBuffer& buffer) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700463
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 Mellemeb2c6412018-10-31 15:25:32 -0700467 virtual RTCError CloseChannel(int channel_id) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700468
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 Mellemeb2c6412018-10-31 15:25:32 -0700472 virtual void SetDataSink(DataChannelSink* sink) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700473
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400474 // TODO(sukhanov): RtcEventLogs.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400475};
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.
484class 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) Slatalaa0677d12018-10-29 07:31:42 -0700492 // TODO(bugs.webrtc.org/9938) This constructor will be removed and replaced
493 // with the one below.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400494 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
495 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
496 rtc::Thread* network_thread,
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700497 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) Slatalaed7b8b12018-10-29 10:43:16 -0700506 const MediaTransportSettings& settings);
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400507};
508
509} // namespace webrtc
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400510#endif // API_MEDIA_TRANSPORT_INTERFACE_H_