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}
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index 071867d..60d6b16 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -215,7 +215,7 @@
 
 // Add options to |session_options| from |rtp_data_channels|.
 void AddRtpDataChannelOptions(
-    const std::map<std::string, rtc::scoped_refptr<DataChannel>>&
+    const std::map<std::string, rtc::scoped_refptr<RtpDataChannel>>&
         rtp_data_channels,
     cricket::MediaDescriptionOptions* data_media_description_options) {
   if (!data_media_description_options) {
@@ -223,9 +223,9 @@
   }
   // Check for data channels.
   for (const auto& kv : rtp_data_channels) {
-    const DataChannel* channel = kv.second;
-    if (channel->state() == DataChannel::kConnecting ||
-        channel->state() == DataChannel::kOpen) {
+    const RtpDataChannel* channel = kv.second;
+    if (channel->state() == RtpDataChannel::kConnecting ||
+        channel->state() == RtpDataChannel::kOpen) {
       // Legacy RTP data channels are signaled with the track/stream ID set to
       // the data channel's label.
       data_media_description_options->AddRtpDataChannel(channel->label(),
@@ -2130,8 +2130,8 @@
   if (config) {
     internal_config.reset(new InternalDataChannelInit(*config));
   }
-  rtc::scoped_refptr<DataChannel> channel(
-      data_channel_controller_.InternalCreateDataChannel(
+  rtc::scoped_refptr<DataChannelInterface> channel(
+      data_channel_controller_.InternalCreateDataChannelWithProxy(
           label, internal_config.get()));
   if (!channel.get()) {
     return nullptr;
@@ -2143,7 +2143,7 @@
     UpdateNegotiationNeeded();
   }
   NoteUsageEvent(UsageEvent::DATA_ADDED);
-  return DataChannel::CreateProxy(std::move(channel));
+  return channel;
 }
 
 void PeerConnection::RestartIce() {
@@ -2731,7 +2731,7 @@
   // If setting the description decided our SSL role, allocate any necessary
   // SCTP sids.
   rtc::SSLRole role;
-  if (DataChannel::IsSctpLike(data_channel_type()) && GetSctpSslRole(&role)) {
+  if (IsSctpLike(data_channel_type()) && GetSctpSslRole(&role)) {
     data_channel_controller_.AllocateSctpSids(role);
   }
 
@@ -3170,7 +3170,7 @@
   // If setting the description decided our SSL role, allocate any necessary
   // SCTP sids.
   rtc::SSLRole role;
-  if (DataChannel::IsSctpLike(data_channel_type()) && GetSctpSslRole(&role)) {
+  if (IsSctpLike(data_channel_type()) && GetSctpSslRole(&role)) {
     data_channel_controller_.AllocateSctpSids(role);
   }
 
@@ -5541,10 +5541,11 @@
   sender->internal()->SetSsrc(0);
 }
 
-void PeerConnection::OnSctpDataChannelClosed(DataChannel* channel) {
+void PeerConnection::OnSctpDataChannelClosed(DataChannelInterface* channel) {
   // Since data_channel_controller doesn't do signals, this
   // signal is relayed here.
-  data_channel_controller_.OnSctpDataChannelClosed(channel);
+  data_channel_controller_.OnSctpDataChannelClosed(
+      static_cast<SctpDataChannel*>(channel));
 }
 
 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
@@ -5656,7 +5657,7 @@
   return nullptr;
 }
 
-DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
+SctpDataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
   return data_channel_controller_.FindDataChannelBySid(sid);
 }
 
@@ -6045,7 +6046,7 @@
   return ice_config;
 }
 
-std::vector<DataChannel::Stats> PeerConnection::GetDataChannelStats() const {
+std::vector<DataChannelStats> PeerConnection::GetDataChannelStats() const {
   RTC_DCHECK_RUN_ON(signaling_thread());
   return data_channel_controller_.GetDataChannelStats();
 }