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}
This commit is contained in:
committed by
Commit Bot
parent
4db954eec1
commit
6476d0bf02
@ -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 ||
|
||||
|
||||
@ -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_
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user