diff --git a/api/DEPS b/api/DEPS index 3fe2bff773..def36c791d 100644 --- a/api/DEPS +++ b/api/DEPS @@ -96,6 +96,10 @@ specific_include_rules = { "+rtc_base/scoped_ref_ptr.h", ], + "media_transport_interface\.h": [ + "+rtc_base/copyonwritebuffer.h", # As used by datachannelinterface.h + ], + "peerconnectionfactoryproxy\.h": [ "+rtc_base/bind.h", ], diff --git a/api/media_transport_interface.cc b/api/media_transport_interface.cc index c583fb4c8d..a97b7894cc 100644 --- a/api/media_transport_interface.cc +++ b/api/media_transport_interface.cc @@ -83,6 +83,21 @@ MediaTransportEncodedVideoFrame::MediaTransportEncodedVideoFrame( MediaTransportEncodedVideoFrame::MediaTransportEncodedVideoFrame( MediaTransportEncodedVideoFrame&&) = default; +SendDataParams::SendDataParams() = default; + +RTCError MediaTransportInterface::SendData( + int channel_id, + const SendDataParams& params, + const rtc::CopyOnWriteBuffer& buffer) { + RTC_NOTREACHED(); + return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); +} + +RTCError MediaTransportInterface::CloseChannel(int channel_id) { + RTC_NOTREACHED(); + return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); +} + RTCErrorOr> MediaTransportFactory::CreateMediaTransport( rtc::PacketTransportInternal* packet_transport, diff --git a/api/media_transport_interface.h b/api/media_transport_interface.h index 1323635342..e0e7453067 100644 --- a/api/media_transport_interface.h +++ b/api/media_transport_interface.h @@ -28,6 +28,7 @@ #include "api/rtcerror.h" #include "api/video/encoded_image.h" #include "common_types.h" // NOLINT(build/include) +#include "rtc_base/copyonwritebuffer.h" namespace rtc { class PacketTransportInternal; @@ -230,6 +231,66 @@ class MediaTransportStateCallback { virtual void OnStateChanged(MediaTransportState state) = 0; }; +// Supported types of application data messages. +enum class DataMessageType { + // Application data buffer with the binary bit unset. + kText, + + // Application data buffer with the binary bit set. + kBinary, + + // Transport-agnostic control messages, such as open or open-ack messages. + kControl, +}; + +// Parameters for sending data. The parameters may change from message to +// message, even within a single channel. For example, control messages may be +// sent reliably and in-order, even if the data channel is configured for +// unreliable delivery. +struct SendDataParams { + SendDataParams(); + + DataMessageType type = DataMessageType::kText; + + // Whether to deliver the message in order with respect to other ordered + // messages with the same channel_id. + bool ordered = false; + + // If set, the maximum number of times this message may be + // retransmitted by the transport before it is dropped. + // Setting this value to zero disables retransmission. + // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set + // simultaneously. + absl::optional max_rtx_count; + + // If set, the maximum number of milliseconds for which the transport + // may retransmit this message before it is dropped. + // Setting this value to zero disables retransmission. + // Must be non-negative. |max_rtx_count| and |max_rtx_ms| may not be set + // simultaneously. + absl::optional max_rtx_ms; +}; + +// Sink for callbacks related to a data channel. +class DataChannelSink { + public: + virtual ~DataChannelSink() = default; + + // Callback issued when data is received by the transport. + virtual void OnDataReceived(int channel_id, + DataMessageType type, + const rtc::CopyOnWriteBuffer& buffer) = 0; + + // Callback issued when a remote data channel begins the closing procedure. + // Messages sent after the closing procedure begins will not be transmitted. + virtual void OnChannelClosing(int channel_id) = 0; + + // Callback issued when a (remote or local) data channel completes the closing + // procedure. Closing channels become closed after all pending data has been + // transmitted. + virtual void OnChannelClosed(int channel_id) = 0; +}; + // Media transport interface for sending / receiving encoded audio/video frames // and receiving bandwidth estimate update from congestion control. class MediaTransportInterface { @@ -279,6 +340,26 @@ class MediaTransportInterface { virtual void SetMediaTransportStateCallback( MediaTransportStateCallback* callback) {} + // Sends a data buffer to the remote endpoint using the given send parameters. + // |buffer| may not be larger than 256 KiB. Returns an error if the send + // fails. + // TODO(mellem): Make this pure virtual once all implementations support it. + virtual RTCError SendData(int channel_id, + const SendDataParams& params, + const rtc::CopyOnWriteBuffer& buffer); + + // Closes |channel_id| gracefully. Returns an error if |channel_id| is not + // open. Data sent after the closing procedure begins will not be + // transmitted. The channel becomes closed after pending data is transmitted. + // TODO(mellem): Make this pure virtual once all implementations support it. + virtual RTCError CloseChannel(int channel_id); + + // Sets a sink for data messages and channel state callbacks. Before media + // transport is destroyed, the sink must be unregistered by setting it to + // nullptr. + // TODO(mellem): Make this pure virtual once all implementations support it. + virtual void SetDataSink(DataChannelSink* sink) {} + // TODO(sukhanov): RtcEventLogs. };