Split DataChannel into two separate classes for RTP and SCTP.
Done in preparation for some threading changes that would be quite messy if implemented with the class as-is. This results in some code duplication, but is preferable to one class having two completely different modes of operation. RTP data channels are in the process of being removed anyway, so the duplicated code won't last forever. Bug: webrtc:9883 Change-Id: Idfd41a669b56a4bb4819572e4a264a4ffaaba9c0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178940 Commit-Queue: Taylor <deadbeef@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31691}
This commit is contained in:
committed by
Commit Bot
parent
61c2d99d1e
commit
3a034e15b4
@ -17,14 +17,16 @@
|
||||
#include <vector>
|
||||
|
||||
#include "pc/channel.h"
|
||||
#include "pc/data_channel.h"
|
||||
#include "pc/rtp_data_channel.h"
|
||||
#include "pc/sctp_data_channel.h"
|
||||
#include "rtc_base/weak_ptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class PeerConnection;
|
||||
|
||||
class DataChannelController : public DataChannelProviderInterface,
|
||||
class DataChannelController : public RtpDataChannelProviderInterface,
|
||||
public SctpDataChannelProviderInterface,
|
||||
public DataChannelSink {
|
||||
public:
|
||||
explicit DataChannelController(PeerConnection* pc) : pc_(pc) {}
|
||||
@ -35,12 +37,15 @@ class DataChannelController : public DataChannelProviderInterface,
|
||||
DataChannelController(DataChannelController&&) = delete;
|
||||
DataChannelController& operator=(DataChannelController&& other) = delete;
|
||||
|
||||
// Implements DataChannelProviderInterface.
|
||||
// Implements RtpDataChannelProviderInterface/
|
||||
// SctpDataChannelProviderInterface.
|
||||
bool SendData(const cricket::SendDataParams& params,
|
||||
const rtc::CopyOnWriteBuffer& payload,
|
||||
cricket::SendDataResult* result) override;
|
||||
bool ConnectDataChannel(DataChannel* webrtc_data_channel) override;
|
||||
void DisconnectDataChannel(DataChannel* webrtc_data_channel) override;
|
||||
bool ConnectDataChannel(RtpDataChannel* webrtc_data_channel) override;
|
||||
void DisconnectDataChannel(RtpDataChannel* webrtc_data_channel) override;
|
||||
bool ConnectDataChannel(SctpDataChannel* webrtc_data_channel) override;
|
||||
void DisconnectDataChannel(SctpDataChannel* webrtc_data_channel) override;
|
||||
void AddSctpDataStream(int sid) override;
|
||||
void RemoveSctpDataStream(int sid) override;
|
||||
bool ReadyToSendData() const override;
|
||||
@ -65,17 +70,17 @@ class DataChannelController : public DataChannelProviderInterface,
|
||||
DataChannelTransportInterface* data_channel_transport);
|
||||
|
||||
// Called from PeerConnection::GetDataChannelStats on the signaling thread.
|
||||
std::vector<DataChannel::Stats> GetDataChannelStats() const;
|
||||
std::vector<DataChannelStats> GetDataChannelStats() const;
|
||||
|
||||
// Creates channel and adds it to the collection of DataChannels that will
|
||||
// be offered in a SessionDescription.
|
||||
rtc::scoped_refptr<DataChannel> InternalCreateDataChannel(
|
||||
// be offered in a SessionDescription, and wraps it in a proxy object.
|
||||
rtc::scoped_refptr<DataChannelInterface> InternalCreateDataChannelWithProxy(
|
||||
const std::string& label,
|
||||
const InternalDataChannelInit*
|
||||
config) /* RTC_RUN_ON(signaling_thread()) */;
|
||||
void AllocateSctpSids(rtc::SSLRole role);
|
||||
|
||||
DataChannel* FindDataChannelBySid(int sid) const;
|
||||
SctpDataChannel* FindDataChannelBySid(int sid) const;
|
||||
|
||||
// Checks if any data channel has been added.
|
||||
bool HasDataChannels() const;
|
||||
@ -102,19 +107,32 @@ class DataChannelController : public DataChannelProviderInterface,
|
||||
}
|
||||
DataChannelTransportInterface* data_channel_transport() const;
|
||||
void set_data_channel_transport(DataChannelTransportInterface* transport);
|
||||
const std::map<std::string, rtc::scoped_refptr<DataChannel>>*
|
||||
const std::map<std::string, rtc::scoped_refptr<RtpDataChannel>>*
|
||||
rtp_data_channels() const;
|
||||
|
||||
sigslot::signal1<DataChannel*>& SignalDataChannelCreated() {
|
||||
sigslot::signal1<RtpDataChannel*>& SignalRtpDataChannelCreated() {
|
||||
RTC_DCHECK_RUN_ON(signaling_thread());
|
||||
return SignalDataChannelCreated_;
|
||||
return SignalRtpDataChannelCreated_;
|
||||
}
|
||||
sigslot::signal1<SctpDataChannel*>& SignalSctpDataChannelCreated() {
|
||||
RTC_DCHECK_RUN_ON(signaling_thread());
|
||||
return SignalSctpDataChannelCreated_;
|
||||
}
|
||||
// Called when the transport for the data channels is closed or destroyed.
|
||||
void OnTransportChannelClosed();
|
||||
|
||||
void OnSctpDataChannelClosed(DataChannel* channel);
|
||||
void OnSctpDataChannelClosed(SctpDataChannel* channel);
|
||||
|
||||
private:
|
||||
rtc::scoped_refptr<RtpDataChannel> InternalCreateRtpDataChannel(
|
||||
const std::string& label,
|
||||
const DataChannelInit* config) /* RTC_RUN_ON(signaling_thread()) */;
|
||||
|
||||
rtc::scoped_refptr<SctpDataChannel> InternalCreateSctpDataChannel(
|
||||
const std::string& label,
|
||||
const InternalDataChannelInit*
|
||||
config) /* RTC_RUN_ON(signaling_thread()) */;
|
||||
|
||||
// Parses and handles open messages. Returns true if the message is an open
|
||||
// message, false otherwise.
|
||||
bool HandleOpenMessage_s(const cricket::ReceiveDataParams& params,
|
||||
@ -174,13 +192,13 @@ class DataChannelController : public DataChannelProviderInterface,
|
||||
// signaling and some other thread.
|
||||
|
||||
SctpSidAllocator sid_allocator_ /* RTC_GUARDED_BY(signaling_thread()) */;
|
||||
std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_
|
||||
std::vector<rtc::scoped_refptr<SctpDataChannel>> sctp_data_channels_
|
||||
RTC_GUARDED_BY(signaling_thread());
|
||||
std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_
|
||||
std::vector<rtc::scoped_refptr<SctpDataChannel>> sctp_data_channels_to_free_
|
||||
RTC_GUARDED_BY(signaling_thread());
|
||||
|
||||
// Map of label -> DataChannel
|
||||
std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_
|
||||
std::map<std::string, rtc::scoped_refptr<RtpDataChannel>> rtp_data_channels_
|
||||
RTC_GUARDED_BY(signaling_thread());
|
||||
|
||||
// Signals from |data_channel_transport_|. These are invoked on the
|
||||
@ -198,7 +216,9 @@ class DataChannelController : public DataChannelProviderInterface,
|
||||
sigslot::signal1<int> SignalDataChannelTransportChannelClosed_s
|
||||
RTC_GUARDED_BY(signaling_thread());
|
||||
|
||||
sigslot::signal1<DataChannel*> SignalDataChannelCreated_
|
||||
sigslot::signal1<RtpDataChannel*> SignalRtpDataChannelCreated_
|
||||
RTC_GUARDED_BY(signaling_thread());
|
||||
sigslot::signal1<SctpDataChannel*> SignalSctpDataChannelCreated_
|
||||
RTC_GUARDED_BY(signaling_thread());
|
||||
|
||||
// Used to invoke data channel transport signals on the signaling thread.
|
||||
|
||||
Reference in New Issue
Block a user