blob: a440860ffc58eb57d9d192de440276137fa77515 [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"
Niels Möller3a742392018-10-08 11:13:58 +020029#include "api/video/encoded_image.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "rtc_base/copy_on_write_buffer.h"
Niels Möllerd8a1b7a2018-12-06 13:00:27 +010031#include "rtc_base/deprecation.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) Slatalaa0677d12018-10-29 07:31:42 -070052// A collection of settings for creation of media transport.
53struct MediaTransportSettings final {
54 MediaTransportSettings();
Piotr (Peter) Slatalaed7b8b12018-10-29 10:43:16 -070055 MediaTransportSettings(const MediaTransportSettings&);
56 MediaTransportSettings& operator=(const MediaTransportSettings&);
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070057 ~MediaTransportSettings();
58
59 // Group calls are not currently supported, in 1:1 call one side must set
60 // is_caller = true and another is_caller = false.
61 bool is_caller;
62
63 // Must be set if a pre-shared key is used for the call.
Piotr (Peter) Slatala9f956252018-10-31 08:25:26 -070064 // TODO(bugs.webrtc.org/9944): This should become zero buffer in the distant
65 // future.
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070066 absl::optional<std::string> pre_shared_key;
Piotr (Peter) Slatala0c022502018-12-28 10:39:39 -080067
68 // If present, provides the event log that media transport should use.
69 // Media transport does not own it. The lifetime of |event_log| will exceed
70 // the lifetime of the instance of MediaTransportInterface instance.
71 RtcEventLog* event_log = nullptr;
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -070072};
73
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040074// Represents encoded audio frame in any encoding (type of encoding is opaque).
75// To avoid copying of encoded data use move semantics when passing by value.
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070076class MediaTransportEncodedAudioFrame final {
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040077 public:
78 enum class FrameType {
79 // Normal audio frame (equivalent to webrtc::kAudioFrameSpeech).
80 kSpeech,
81
82 // DTX frame (equivalent to webrtc::kAudioFrameCN).
Niels Möller7d76a312018-10-26 12:57:07 +020083 // DTX frame (equivalent to webrtc::kAudioFrameCN).
84 kDiscontinuousTransmission,
85 // TODO(nisse): Mis-spelled version, update users, then delete.
86 kDiscountinuousTransmission = kDiscontinuousTransmission,
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -040087 };
88
89 MediaTransportEncodedAudioFrame(
90 // Audio sampling rate, for example 48000.
91 int sampling_rate_hz,
92
93 // Starting sample index of the frame, i.e. how many audio samples were
94 // before this frame since the beginning of the call or beginning of time
95 // in one channel (the starting point should not matter for NetEq). In
96 // WebRTC it is used as a timestamp of the frame.
97 // TODO(sukhanov): Starting_sample_index is currently adjusted on the
98 // receiver side in RTP path. Non-RTP implementations should preserve it.
99 // For NetEq initial offset should not matter so we should consider fixing
100 // RTP path.
101 int starting_sample_index,
102
103 // Number of audio samples in audio frame in 1 channel.
104 int samples_per_channel,
105
106 // Sequence number of the frame in the order sent, it is currently
107 // required by NetEq, but we can fix NetEq, because starting_sample_index
108 // should be enough.
109 int sequence_number,
110
111 // If audio frame is a speech or discontinued transmission.
112 FrameType frame_type,
113
114 // Opaque payload type. In RTP codepath payload type is stored in RTP
115 // header. In other implementations it should be simply passed through the
116 // wire -- it's needed for decoder.
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100117 int payload_type,
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400118
119 // Vector with opaque encoded data.
Niels Möller3a742392018-10-08 11:13:58 +0200120 std::vector<uint8_t> encoded_data);
121
122 ~MediaTransportEncodedAudioFrame();
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700123 MediaTransportEncodedAudioFrame(const MediaTransportEncodedAudioFrame&);
124 MediaTransportEncodedAudioFrame& operator=(
125 const MediaTransportEncodedAudioFrame& other);
126 MediaTransportEncodedAudioFrame& operator=(
127 MediaTransportEncodedAudioFrame&& other);
128 MediaTransportEncodedAudioFrame(MediaTransportEncodedAudioFrame&&);
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400129
130 // Getters.
131 int sampling_rate_hz() const { return sampling_rate_hz_; }
132 int starting_sample_index() const { return starting_sample_index_; }
133 int samples_per_channel() const { return samples_per_channel_; }
134 int sequence_number() const { return sequence_number_; }
135
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100136 int payload_type() const { return payload_type_; }
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400137 FrameType frame_type() const { return frame_type_; }
138
139 rtc::ArrayView<const uint8_t> encoded_data() const { return encoded_data_; }
140
141 private:
142 int sampling_rate_hz_;
143 int starting_sample_index_;
144 int samples_per_channel_;
145
146 // TODO(sukhanov): Refactor NetEq so we don't need sequence number.
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700147 // Having sample_index and samples_per_channel should be enough.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400148 int sequence_number_;
149
150 FrameType frame_type_;
151
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100152 int payload_type_;
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400153
154 std::vector<uint8_t> encoded_data_;
155};
156
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800157// Callback to notify about network route changes.
158class MediaTransportNetworkChangeCallback {
159 public:
160 virtual ~MediaTransportNetworkChangeCallback() = default;
161
162 // Called when the network route is changed, with the new network route.
163 virtual void OnNetworkRouteChanged(
164 const rtc::NetworkRoute& new_network_route) = 0;
165};
166
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400167// Interface for receiving encoded audio frames from MediaTransportInterface
168// implementations.
169class MediaTransportAudioSinkInterface {
170 public:
171 virtual ~MediaTransportAudioSinkInterface() = default;
172
173 // Called when new encoded audio frame is received.
174 virtual void OnData(uint64_t channel_id,
175 MediaTransportEncodedAudioFrame frame) = 0;
176};
177
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700178// Represents encoded video frame, along with the codec information.
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700179class MediaTransportEncodedVideoFrame final {
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700180 public:
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100181 // TODO(bugs.webrtc.org/9719): Switch to payload_type
182 RTC_DEPRECATED MediaTransportEncodedVideoFrame(
183 int64_t frame_id,
184 std::vector<int64_t> referenced_frame_ids,
185 VideoCodecType codec_type,
186 const webrtc::EncodedImage& encoded_image);
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700187 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 // TODO(bugs.webrtc.org/9719): Switch to payload_type
200 RTC_DEPRECATED VideoCodecType codec_type() const { return codec_type_; }
201 int payload_type() const { return payload_type_; }
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700202 const webrtc::EncodedImage& encoded_image() const { return encoded_image_; }
203
204 int64_t frame_id() const { return frame_id_; }
205 const std::vector<int64_t>& referenced_frame_ids() const {
206 return referenced_frame_ids_;
207 }
208
Niels Möllerd5696fb2018-11-28 15:34:37 +0100209 // Hack to workaround lack of ownership of the encoded_image_._buffer. If we
210 // don't already own the underlying data, make a copy.
211 void Retain();
212
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700213 private:
Niels Möllerd5696fb2018-11-28 15:34:37 +0100214 MediaTransportEncodedVideoFrame();
215
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700216 VideoCodecType codec_type_;
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100217 int payload_type_;
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700218
Niels Möllerd5696fb2018-11-28 15:34:37 +0100219 // The buffer is not owned by the encoded image. On the sender it means that
220 // it will need to make a copy using the Retain() method, if it wants to
221 // deliver it asynchronously.
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700222 webrtc::EncodedImage encoded_image_;
223
Niels Möllerd5696fb2018-11-28 15:34:37 +0100224 // If non-empty, this is the data for the encoded image.
225 std::vector<uint8_t> encoded_data_;
226
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700227 // Frame id uniquely identifies a frame in a stream. It needs to be unique in
228 // a given time window (i.e. technically unique identifier for the lifetime of
229 // the connection is not needed, but you need to guarantee that remote side
230 // got rid of the previous frame_id if you plan to reuse it).
231 //
232 // It is required by a remote jitter buffer, and is the same as
233 // EncodedFrame::id::picture_id.
234 //
235 // This data must be opaque to the media transport, and media transport should
236 // itself not make any assumptions about what it is and its uniqueness.
237 int64_t frame_id_;
238
239 // A single frame might depend on other frames. This is set of identifiers on
240 // which the current frame depends.
241 std::vector<int64_t> referenced_frame_ids_;
242};
243
244// Interface for receiving encoded video frames from MediaTransportInterface
245// implementations.
246class MediaTransportVideoSinkInterface {
247 public:
248 virtual ~MediaTransportVideoSinkInterface() = default;
249
250 // Called when new encoded video frame is received.
251 virtual void OnData(uint64_t channel_id,
252 MediaTransportEncodedVideoFrame frame) = 0;
253
Niels Möllerd8a1b7a2018-12-06 13:00:27 +0100254 // TODO(bugs.webrtc.org/9719): Belongs on send side, not receive side.
255 RTC_DEPRECATED virtual void OnKeyFrameRequested(uint64_t channel_id) {}
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700256};
257
Niels Möller1c7f5f62018-12-10 11:06:02 +0100258// Interface for video sender to be notified of received key frame request.
259class MediaTransportKeyFrameRequestCallback {
260 public:
261 virtual ~MediaTransportKeyFrameRequestCallback() = default;
262
263 // Called when a key frame request is received on the transport.
264 virtual void OnKeyFrameRequested(uint64_t channel_id) = 0;
265};
266
Bjorn Mellemc78b0ea2018-10-29 15:21:31 -0700267// State of the media transport. Media transport begins in the pending state.
268// It transitions to writable when it is ready to send media. It may transition
269// back to pending if the connection is blocked. It may transition to closed at
270// any time. Closed is terminal: a transport will never re-open once closed.
271enum class MediaTransportState {
272 kPending,
273 kWritable,
274 kClosed,
275};
276
277// Callback invoked whenever the state of the media transport changes.
278class MediaTransportStateCallback {
279 public:
280 virtual ~MediaTransportStateCallback() = default;
281
282 // Invoked whenever the state of the media transport changes.
283 virtual void OnStateChanged(MediaTransportState state) = 0;
284};
285
Niels Möller46879152019-01-07 15:54:47 +0100286// Callback for RTT measurements on the receive side.
287// TODO(nisse): Related interfaces: CallStatsObserver and RtcpRttStats. It's
288// somewhat unclear what type of measurement is needed. It's used to configure
289// NACK generation and playout buffer. Either raw measurement values or recent
290// maximum would make sense for this use. Need consolidation of RTT signalling.
291class MediaTransportRttObserver {
292 public:
293 virtual ~MediaTransportRttObserver() = default;
294
295 // Invoked when a new RTT measurement is available, typically once per ACK.
296 virtual void OnRttUpdated(int64_t rtt_ms) = 0;
297};
298
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700299// Supported types of application data messages.
300enum class DataMessageType {
301 // Application data buffer with the binary bit unset.
302 kText,
303
304 // Application data buffer with the binary bit set.
305 kBinary,
306
307 // Transport-agnostic control messages, such as open or open-ack messages.
308 kControl,
309};
310
311// Parameters for sending data. The parameters may change from message to
312// message, even within a single channel. For example, control messages may be
313// sent reliably and in-order, even if the data channel is configured for
314// unreliable delivery.
315struct SendDataParams {
316 SendDataParams();
Niels Möllere0446cb2018-11-30 09:35:52 +0100317 SendDataParams(const SendDataParams&);
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700318
319 DataMessageType type = DataMessageType::kText;
320
321 // Whether to deliver the message in order with respect to other ordered
322 // messages with the same channel_id.
323 bool ordered = false;
324
325 // If set, the maximum number of times this message may be
326 // retransmitted by the transport before it is dropped.
327 // Setting this value to zero disables retransmission.
328 // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set
329 // simultaneously.
330 absl::optional<int> max_rtx_count;
331
332 // If set, the maximum number of milliseconds for which the transport
333 // may retransmit this message 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_ms;
338};
339
340// Sink for callbacks related to a data channel.
341class DataChannelSink {
342 public:
343 virtual ~DataChannelSink() = default;
344
345 // Callback issued when data is received by the transport.
346 virtual void OnDataReceived(int channel_id,
347 DataMessageType type,
348 const rtc::CopyOnWriteBuffer& buffer) = 0;
349
350 // Callback issued when a remote data channel begins the closing procedure.
351 // Messages sent after the closing procedure begins will not be transmitted.
352 virtual void OnChannelClosing(int channel_id) = 0;
353
354 // Callback issued when a (remote or local) data channel completes the closing
355 // procedure. Closing channels become closed after all pending data has been
356 // transmitted.
357 virtual void OnChannelClosed(int channel_id) = 0;
358};
359
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400360// Media transport interface for sending / receiving encoded audio/video frames
361// and receiving bandwidth estimate update from congestion control.
362class MediaTransportInterface {
363 public:
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800364 MediaTransportInterface();
365 virtual ~MediaTransportInterface();
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400366
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700367 // Start asynchronous send of audio frame. The status returned by this method
368 // only pertains to the synchronous operations (e.g.
369 // serialization/packetization), not to the asynchronous operation.
370
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400371 virtual RTCError SendAudioFrame(uint64_t channel_id,
372 MediaTransportEncodedAudioFrame frame) = 0;
373
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700374 // Start asynchronous send of video 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 virtual RTCError SendVideoFrame(
378 uint64_t channel_id,
379 const MediaTransportEncodedVideoFrame& frame) = 0;
380
Niels Möller1c7f5f62018-12-10 11:06:02 +0100381 // Used by video sender to be notified on key frame requests.
382 virtual void SetKeyFrameRequestCallback(
383 MediaTransportKeyFrameRequestCallback* callback);
384
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700385 // Requests a keyframe for the particular channel (stream). The caller should
386 // check that the keyframe is not present in a jitter buffer already (i.e.
387 // don't request a keyframe if there is one that you will get from the jitter
388 // buffer in a moment).
389 virtual RTCError RequestKeyFrame(uint64_t channel_id) = 0;
390
391 // Sets audio sink. Sink must be unset by calling SetReceiveAudioSink(nullptr)
392 // before the media transport is destroyed or before new sink is set.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400393 virtual void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) = 0;
394
Piotr (Peter) Slatalae804f922018-09-25 08:40:30 -0700395 // Registers a video sink. Before destruction of media transport, you must
396 // pass a nullptr.
397 virtual void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) = 0;
398
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800399 // Adds a target bitrate observer. Before media transport is destructed
400 // the observer must be unregistered (by calling
401 // RemoveTargetTransferRateObserver).
402 // A newly registered observer will be called back with the latest recorded
403 // target rate, if available.
404 virtual void AddTargetTransferRateObserver(
Niels Möller46879152019-01-07 15:54:47 +0100405 TargetTransferRateObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800406
407 // Removes an existing |observer| from observers. If observer was never
408 // registered, an error is logged and method does nothing.
409 virtual void RemoveTargetTransferRateObserver(
Niels Möller46879152019-01-07 15:54:47 +0100410 TargetTransferRateObserver* observer);
411
Piotr (Peter) Slatala309aafe2019-01-15 14:24:34 -0800412 // Sets audio packets observer, which gets informed about incoming audio
413 // packets. Before destruction, the observer must be unregistered by setting
414 // nullptr.
415 //
416 // This method may be temporary, when the multiplexer is implemented (or
417 // multiplexer may use it to demultiplex channel ids).
418 virtual void SetFirstAudioPacketReceivedObserver(
419 AudioPacketReceivedObserver* observer);
420
Niels Möller46879152019-01-07 15:54:47 +0100421 // Intended for receive side. AddRttObserver registers an observer to be
422 // called for each RTT measurement, typically once per ACK. Before media
423 // transport is destructed the observer must be unregistered.
424 virtual void AddRttObserver(MediaTransportRttObserver* observer);
425 virtual void RemoveRttObserver(MediaTransportRttObserver* observer);
Piotr (Peter) Slatalaada077f2018-11-08 07:43:31 -0800426
427 // Returns the last known target transfer rate as reported to the above
428 // observers.
429 virtual absl::optional<TargetTransferRate> GetLatestTargetTransferRate();
430
431 // Gets the audio packet overhead in bytes. Returned overhead does not include
432 // transport overhead (ipv4/6, turn channeldata, tcp/udp, etc.).
433 // If the transport is capable of fusing packets together, this overhead
434 // might not be a very accurate number.
435 virtual size_t GetAudioPacketOverhead() const;
436
437 // Sets an observer for network change events. If the network route is already
438 // established when the callback is set, |callback| will be called immediately
439 // with the current network route.
440 // Before media transport is destroyed, the callback must be unregistered by
441 // setting it to nullptr.
442 virtual void SetNetworkChangeCallback(
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
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700452 // Sends a data buffer to the remote endpoint using the given send parameters.
453 // |buffer| may not be larger than 256 KiB. Returns an error if the send
454 // fails.
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700455 virtual RTCError SendData(int channel_id,
456 const SendDataParams& params,
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700457 const rtc::CopyOnWriteBuffer& buffer) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700458
459 // Closes |channel_id| gracefully. Returns an error if |channel_id| is not
460 // open. Data sent after the closing procedure begins will not be
461 // transmitted. The channel becomes closed after pending data is transmitted.
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700462 virtual RTCError CloseChannel(int channel_id) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700463
464 // Sets a sink for data messages and channel state callbacks. Before media
465 // transport is destroyed, the sink must be unregistered by setting it to
466 // nullptr.
Bjorn Mellemeb2c6412018-10-31 15:25:32 -0700467 virtual void SetDataSink(DataChannelSink* sink) = 0;
Bjorn Mellem1f6aa9f2018-10-30 15:15:00 -0700468
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400469 // TODO(sukhanov): RtcEventLogs.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400470};
471
472// If media transport factory is set in peer connection factory, it will be
473// used to create media transport for sending/receiving encoded frames and
474// this transport will be used instead of default RTP/SRTP transport.
475//
476// Currently Media Transport negotiation is not supported in SDP.
477// If application is using media transport, it must negotiate it before
478// setting media transport factory in peer connection.
479class MediaTransportFactory {
480 public:
481 virtual ~MediaTransportFactory() = default;
482
483 // Creates media transport.
484 // - Does not take ownership of packet_transport or network_thread.
485 // - Does not support group calls, in 1:1 call one side must set
486 // is_caller = true and another is_caller = false.
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700487 // TODO(bugs.webrtc.org/9938) This constructor will be removed and replaced
488 // with the one below.
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400489 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
490 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
491 rtc::Thread* network_thread,
Piotr (Peter) Slatalaa0677d12018-10-29 07:31:42 -0700492 bool is_caller);
493
494 // Creates media transport.
495 // - Does not take ownership of packet_transport or network_thread.
496 // TODO(bugs.webrtc.org/9938): remove default implementation once all children
497 // override it.
498 virtual RTCErrorOr<std::unique_ptr<MediaTransportInterface>>
499 CreateMediaTransport(rtc::PacketTransportInternal* packet_transport,
500 rtc::Thread* network_thread,
Piotr (Peter) Slatalaed7b8b12018-10-29 10:43:16 -0700501 const MediaTransportSettings& settings);
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400502};
503
504} // namespace webrtc
Anton Sukhanovf60bd4b2018-09-05 13:41:46 -0400505#endif // API_MEDIA_TRANSPORT_INTERFACE_H_