diff options
author | Tomas Gunnarsson <tommi@webrtc.org> | 2020-06-16 18:39:50 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-17 07:06:34 +0000 |
commit | 6476d0bf02d2871bff3a3d5db79d576eb6f58ead (patch) | |
tree | 341a635f18354379026303cc35983086a910131e /pc | |
parent | 4db954eec11258d57e0d507b0436a183178dae22 (diff) | |
download | webrtc-6476d0bf02d2871bff3a3d5db79d576eb6f58ead.tar.gz |
Consolidate creation of DataChannel proxy to a single place
Change-Id: I707733f521a4fda1536741b204a559dd511d0c00
Bug: webrtc:11547
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/177344
Reviewed-by: Taylor <deadbeef@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31535}
Diffstat (limited to 'pc')
-rw-r--r-- | pc/data_channel.cc | 41 | ||||
-rw-r--r-- | pc/data_channel.h | 35 | ||||
-rw-r--r-- | pc/data_channel_controller.cc | 6 | ||||
-rw-r--r-- | pc/peer_connection.cc | 5 |
4 files changed, 50 insertions, 37 deletions
diff --git a/pc/data_channel.cc b/pc/data_channel.cc index 22655107ca..ca6b6145cb 100644 --- a/pc/data_channel.cc +++ b/pc/data_channel.cc @@ -14,6 +14,7 @@ #include <string> #include <utility> +#include "api/proxy.h" #include "media/sctp/sctp_transport_internal.h" #include "pc/sctp_utils.h" #include "rtc_base/checks.h" @@ -149,6 +150,46 @@ rtc::scoped_refptr<DataChannel> DataChannel::Create( return channel; } +// Define proxy for DataChannelInterface. +BEGIN_SIGNALING_PROXY_MAP(DataChannel) +PROXY_SIGNALING_THREAD_DESTRUCTOR() +PROXY_METHOD1(void, RegisterObserver, DataChannelObserver*) +PROXY_METHOD0(void, UnregisterObserver) +BYPASS_PROXY_CONSTMETHOD0(std::string, label) +BYPASS_PROXY_CONSTMETHOD0(bool, reliable) +BYPASS_PROXY_CONSTMETHOD0(bool, ordered) +BYPASS_PROXY_CONSTMETHOD0(uint16_t, maxRetransmitTime) +BYPASS_PROXY_CONSTMETHOD0(uint16_t, maxRetransmits) +BYPASS_PROXY_CONSTMETHOD0(absl::optional<int>, maxRetransmitsOpt) +BYPASS_PROXY_CONSTMETHOD0(absl::optional<int>, maxPacketLifeTime) +BYPASS_PROXY_CONSTMETHOD0(std::string, protocol) +BYPASS_PROXY_CONSTMETHOD0(bool, negotiated) +// Can't bypass the proxy since the id may change. +PROXY_CONSTMETHOD0(int, id) +BYPASS_PROXY_CONSTMETHOD0(Priority, priority) +PROXY_CONSTMETHOD0(DataState, state) +PROXY_CONSTMETHOD0(RTCError, error) +PROXY_CONSTMETHOD0(uint32_t, messages_sent) +PROXY_CONSTMETHOD0(uint64_t, bytes_sent) +PROXY_CONSTMETHOD0(uint32_t, messages_received) +PROXY_CONSTMETHOD0(uint64_t, bytes_received) +PROXY_CONSTMETHOD0(uint64_t, buffered_amount) +PROXY_METHOD0(void, Close) +// TODO(bugs.webrtc.org/11547): Change to run on the network thread. +PROXY_METHOD1(bool, Send, const DataBuffer&) +END_PROXY_MAP() + +// static +rtc::scoped_refptr<DataChannelInterface> DataChannel::CreateProxy( + rtc::scoped_refptr<DataChannel> channel) { + // TODO(bugs.webrtc.org/11547): incorporate the network thread in the proxy. + // Also, consider allowing the proxy object to own the reference (std::move). + // As is, the proxy has a raw pointer and no reference to the channel object + // and trusting that the lifetime management aligns with the + // sctp_data_channels_ array in DataChannelController. + return DataChannelProxy::Create(channel->signaling_thread_, channel.get()); +} + bool DataChannel::IsSctpLike(cricket::DataChannelType type) { return type == cricket::DCT_SCTP || type == cricket::DCT_MEDIA_TRANSPORT || type == cricket::DCT_DATA_CHANNEL_TRANSPORT || diff --git a/pc/data_channel.h b/pc/data_channel.h index c1e855d879..210b8ce7a4 100644 --- a/pc/data_channel.h +++ b/pc/data_channel.h @@ -18,7 +18,6 @@ #include "api/data_channel_interface.h" #include "api/priority.h" -#include "api/proxy.h" #include "api/scoped_refptr.h" #include "media/base/media_channel.h" #include "pc/channel.h" @@ -133,6 +132,11 @@ class DataChannel : public DataChannelInterface, public sigslot::has_slots<> { rtc::Thread* signaling_thread, rtc::Thread* network_thread); + // Instantiates an API proxy for a DataChannel instance that will be handed + // out to external callers. + static rtc::scoped_refptr<DataChannelInterface> CreateProxy( + rtc::scoped_refptr<DataChannel> channel); + static bool IsSctpLike(cricket::DataChannelType type); void RegisterObserver(DataChannelObserver* observer) override; @@ -338,35 +342,6 @@ class DataChannel : public DataChannelInterface, public sigslot::has_slots<> { rtc::AsyncInvoker invoker_ RTC_GUARDED_BY(signaling_thread_); }; -// Define proxy for DataChannelInterface. -BEGIN_SIGNALING_PROXY_MAP(DataChannel) -PROXY_SIGNALING_THREAD_DESTRUCTOR() -PROXY_METHOD1(void, RegisterObserver, DataChannelObserver*) -PROXY_METHOD0(void, UnregisterObserver) -BYPASS_PROXY_CONSTMETHOD0(std::string, label) -BYPASS_PROXY_CONSTMETHOD0(bool, reliable) -BYPASS_PROXY_CONSTMETHOD0(bool, ordered) -BYPASS_PROXY_CONSTMETHOD0(uint16_t, maxRetransmitTime) -BYPASS_PROXY_CONSTMETHOD0(uint16_t, maxRetransmits) -BYPASS_PROXY_CONSTMETHOD0(absl::optional<int>, maxRetransmitsOpt) -BYPASS_PROXY_CONSTMETHOD0(absl::optional<int>, maxPacketLifeTime) -BYPASS_PROXY_CONSTMETHOD0(std::string, protocol) -BYPASS_PROXY_CONSTMETHOD0(bool, negotiated) -// Can't bypass the proxy since the id may change. -PROXY_CONSTMETHOD0(int, id) -BYPASS_PROXY_CONSTMETHOD0(Priority, priority) -PROXY_CONSTMETHOD0(DataState, state) -PROXY_CONSTMETHOD0(RTCError, error) -PROXY_CONSTMETHOD0(uint32_t, messages_sent) -PROXY_CONSTMETHOD0(uint64_t, bytes_sent) -PROXY_CONSTMETHOD0(uint32_t, messages_received) -PROXY_CONSTMETHOD0(uint64_t, bytes_received) -PROXY_CONSTMETHOD0(uint64_t, buffered_amount) -PROXY_METHOD0(void, Close) -// TODO(bugs.webrtc.org/11547): Change to run on the network thread. -PROXY_METHOD1(bool, Send, const DataBuffer&) -END_PROXY_MAP() - } // namespace webrtc #endif // PC_DATA_CHANNEL_H_ diff --git a/pc/data_channel_controller.cc b/pc/data_channel_controller.cc index a8a1491b7f..710ca8e531 100644 --- a/pc/data_channel_controller.cc +++ b/pc/data_channel_controller.cc @@ -251,9 +251,8 @@ void DataChannelController::OnDataChannelOpenMessage( return; } - // TODO(bugs.webrtc.org/11547): Inject the network thread as well. rtc::scoped_refptr<DataChannelInterface> proxy_channel = - DataChannelProxy::Create(signaling_thread(), channel); + DataChannel::CreateProxy(std::move(channel)); pc_->Observer()->OnDataChannel(std::move(proxy_channel)); pc_->NoteDataAddedEvent(); } @@ -508,9 +507,8 @@ void DataChannelController::CreateRemoteRtpDataChannel(const std::string& label, return; } channel->SetReceiveSsrc(remote_ssrc); - // TODO(bugs.webrtc.org/11547): Inject the network thread as well. rtc::scoped_refptr<DataChannelInterface> proxy_channel = - DataChannelProxy::Create(signaling_thread(), channel); + DataChannel::CreateProxy(std::move(channel)); pc_->Observer()->OnDataChannel(std::move(proxy_channel)); } diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 9b3b760f21..9e86753d6f 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -2198,7 +2198,7 @@ rtc::scoped_refptr<DataChannelInterface> PeerConnection::CreateDataChannel( if (config) { internal_config.reset(new InternalDataChannelInit(*config)); } - rtc::scoped_refptr<DataChannelInterface> channel( + rtc::scoped_refptr<DataChannel> channel( data_channel_controller_.InternalCreateDataChannel( label, internal_config.get())); if (!channel.get()) { @@ -2211,8 +2211,7 @@ rtc::scoped_refptr<DataChannelInterface> PeerConnection::CreateDataChannel( UpdateNegotiationNeeded(); } NoteUsageEvent(UsageEvent::DATA_ADDED); - // TODO(bugs.webrtc.org/11547): Inject the network thread as well. - return DataChannelProxy::Create(signaling_thread(), channel.get()); + return DataChannel::CreateProxy(std::move(channel)); } void PeerConnection::RestartIce() { |