From f58e43e2a69764702016d3fa4358a53257a5662c Mon Sep 17 00:00:00 2001 From: Bjorn Mellem Date: Fri, 22 Feb 2019 10:31:48 -0800 Subject: [PATCH] Add an OpenChannel method to MediaTransportInterface and call it whenever PeerConnection opens a new data channel. This informs the media transport that PeerConnection wants to use a data channel and gives it a chance to set up before the data channel sends the first message. Bug: webrtc:9719 Change-Id: I6ea905a74b29b8735e77ac68bc8606e7bca77f18 Reviewed-on: https://webrtc-review.googlesource.com/c/124020 Reviewed-by: Steve Anton Reviewed-by: Peter Slatala Commit-Queue: Bjorn Mellem Cr-Commit-Position: refs/heads/master@{#26823} --- api/media_transport_interface.cc | 7 +++++++ api/media_transport_interface.h | 5 +++++ pc/peer_connection.cc | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api/media_transport_interface.cc b/api/media_transport_interface.cc index de04e197fa..abd9861652 100644 --- a/api/media_transport_interface.cc +++ b/api/media_transport_interface.cc @@ -88,4 +88,11 @@ size_t MediaTransportInterface::GetAudioPacketOverhead() const { void MediaTransportInterface::SetAllocatedBitrateLimits( const MediaTransportAllocatedBitrateLimits& limits) {} +// TODO(mellem): Delete when all implementations support it. +RTCError MediaTransportInterface::OpenChannel(int channel_id) { + // NB: This must return OK to avoid breaking existing implementations, which + // do not require calling OpenChannel. + return RTCError::OK(); +} + } // namespace webrtc diff --git a/api/media_transport_interface.h b/api/media_transport_interface.h index 2f5431f980..edbd3b1da0 100644 --- a/api/media_transport_interface.h +++ b/api/media_transport_interface.h @@ -278,6 +278,11 @@ class MediaTransportInterface { virtual void SetAllocatedBitrateLimits( const MediaTransportAllocatedBitrateLimits& limits); + // Opens a data |channel_id| for sending. May return an error if the + // specified |channel_id| is unusable. Must be called before |SendData|. + // TODO(mellem): Make pure virtual when all implementations support it. + virtual RTCError OpenChannel(int channel_id); + // 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. diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 341a570b68..0288afca3b 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -5694,7 +5694,7 @@ void PeerConnection::DisconnectDataChannel(DataChannel* webrtc_data_channel) { void PeerConnection::AddSctpDataStream(int sid) { if (media_transport_) { - // No-op. Media transport does not need to add streams. + media_transport_->OpenChannel(sid); return; } if (!sctp_transport_) {