Add a sctp_transport_interface build target

Introduce a dedicated sctp_transport_interface build target to improve
modularity and break an undesirable dependency. Previously,
`webrtc_sdp.cc` included `sctp_transport_internal.h` to access SCTP
constants.

The biggest code block in this CL is moving the block commented as
"Constants that are important to API users" block from the internal code
to `sctp_transport_interface.h`.

Bug: webrtc:42222470
Change-Id: I6f211e871584ccad5662a9303fd60b7690124419
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/415920
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45908}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 0a2da74..6dfb63c 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -297,6 +297,20 @@
   ]
 }
 
+rtc_library("sctp_transport_interface") {
+  visibility = [ "*" ]
+  sources = [
+    "sctp_transport_interface.cc",
+    "sctp_transport_interface.h",
+  ]
+  deps = [
+    ":dtls_transport_interface",
+    ":ref_count",
+    ":scoped_refptr",
+    "../rtc_base/system:rtc_export",
+  ]
+}
+
 rtc_library("jsep") {
   visibility = [ "*" ]
   cflags = []
@@ -340,8 +354,6 @@
     "rtp_receiver_interface.h",
     "rtp_transceiver_interface.cc",
     "rtp_transceiver_interface.h",
-    "sctp_transport_interface.cc",
-    "sctp_transport_interface.h",
     "set_local_description_observer_interface.h",
     "set_remote_description_observer_interface.h",
     "uma_metrics.h",
@@ -351,12 +363,14 @@
     "dtmf_sender_interface.h",
     "jsep.h",  # allow to be included from peer_connection_interface.h
     "rtp_sender_interface.h",
+    "sctp_transport_interface.h",
   ]
   public_deps += [  # no-presubmit-check TODO(webrtc:8603)
     # Remove when downstream has been updated
     ":dtmf_sender_interface",
     ":jsep",
     ":rtp_sender_interface",
+    ":sctp_transport_interface",
   ]
   deps = [
     ":array_view",
@@ -1420,6 +1434,7 @@
       ":rtc_error",
       ":rtc_stats_api",
       ":rtp_parameters",
+      ":sctp_transport_interface",
       "../api:scoped_refptr",
       "../rtc_base:refcount",
       "../rtc_base:threading",
diff --git a/api/sctp_transport_interface.h b/api/sctp_transport_interface.h
index ba68ca0..450266c 100644
--- a/api/sctp_transport_interface.h
+++ b/api/sctp_transport_interface.h
@@ -11,6 +11,7 @@
 #ifndef API_SCTP_TRANSPORT_INTERFACE_H_
 #define API_SCTP_TRANSPORT_INTERFACE_H_
 
+#include <cstdint>
 #include <optional>
 
 #include "api/dtls_transport_interface.h"
@@ -20,6 +21,48 @@
 
 namespace webrtc {
 
+// Constants that are important to API users
+
+// The number of outgoing streams that we'll negotiate. Since stream IDs (SIDs)
+// are 0-based, the highest usable SID is 1023.
+//
+// It's recommended to use the maximum of 65535 in:
+// https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-13#section-6.2
+// However, we use 1024 in order to save memory. usrsctp allocates 104 bytes
+// for each pair of incoming/outgoing streams (on a 64-bit system), so 65535
+// streams would waste ~6MB.
+//
+// Note: "max" and "min" here are inclusive.
+constexpr uint16_t kMaxSctpStreams = 1024;
+constexpr uint16_t kMaxSctpSid = kMaxSctpStreams - 1;
+constexpr uint16_t kMinSctpSid = 0;
+// The maximum number of streams that can be negotiated according to spec.
+constexpr uint16_t kSpecMaxSctpSid = 65535;
+
+// This is the default SCTP port to use. It is passed along the wire and the
+// connectee and connector must be using the same port. It is not related to the
+// ports at the IP level. (Corresponds to: sockaddr_conn.sconn_port in
+// usrsctp.h)
+const int kSctpDefaultPort = 5000;
+
+// Error cause codes defined at
+// https://www.iana.org/assignments/sctp-parameters/sctp-parameters.xhtml#sctp-parameters-24
+enum class SctpErrorCauseCode : uint16_t {
+  kInvalidStreamIdentifier = 1,
+  kMissingMandatoryParameter = 2,
+  kStaleCookieError = 3,
+  kOutOfResource = 4,
+  kUnresolvableAddress = 5,
+  kUnrecognizedChunkType = 6,
+  kInvalidMandatoryParameter = 7,
+  kUnrecognizedParameters = 8,
+  kNoUserData = 9,
+  kCookieReceivedWhileShuttingDown = 10,
+  kRestartWithNewAddresses = 11,
+  kUserInitiatedAbort = 12,
+  kProtocolViolation = 13,
+};
+
 // States of a SCTP transport, corresponding to the JS API specification.
 // http://w3c.github.io/webrtc-pc/#dom-rtcsctptransportstate
 enum class SctpTransportState {
diff --git a/media/BUILD.gn b/media/BUILD.gn
index af61a88..01e3095 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -705,6 +705,7 @@
     "../api:libjingle_peerconnection_api",
     "../api:priority",
     "../api:rtc_error",
+    "../api:sctp_transport_interface",
     "../api/transport:datagram_transport_interface",
     "../p2p:dtls_transport_internal",
     "../p2p:packet_transport_internal",
@@ -728,6 +729,7 @@
       "../api:libjingle_peerconnection_api",
       "../api:priority",
       "../api:rtc_error",
+      "../api:sctp_transport_interface",
       "../api:sequence_checker",
       "../api/environment",
       "../api/task_queue",
diff --git a/media/sctp/sctp_transport_internal.h b/media/sctp/sctp_transport_internal.h
index 400d783..a9023b5 100644
--- a/media/sctp/sctp_transport_internal.h
+++ b/media/sctp/sctp_transport_internal.h
@@ -15,7 +15,6 @@
 // anything in media/.
 
 #include <cstddef>
-#include <cstdint>
 #include <functional>
 #include <optional>
 
@@ -28,48 +27,6 @@
 
 namespace webrtc {
 
-// Constants that are important to API users
-
-// The number of outgoing streams that we'll negotiate. Since stream IDs (SIDs)
-// are 0-based, the highest usable SID is 1023.
-//
-// It's recommended to use the maximum of 65535 in:
-// https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-13#section-6.2
-// However, we use 1024 in order to save memory. usrsctp allocates 104 bytes
-// for each pair of incoming/outgoing streams (on a 64-bit system), so 65535
-// streams would waste ~6MB.
-//
-// Note: "max" and "min" here are inclusive.
-constexpr uint16_t kMaxSctpStreams = 1024;
-constexpr uint16_t kMaxSctpSid = kMaxSctpStreams - 1;
-constexpr uint16_t kMinSctpSid = 0;
-// The maximum number of streams that can be negotiated according to spec.
-constexpr uint16_t kSpecMaxSctpSid = 65535;
-
-// This is the default SCTP port to use. It is passed along the wire and the
-// connectee and connector must be using the same port. It is not related to the
-// ports at the IP level. (Corresponds to: sockaddr_conn.sconn_port in
-// usrsctp.h)
-const int kSctpDefaultPort = 5000;
-
-// Error cause codes defined at
-// https://www.iana.org/assignments/sctp-parameters/sctp-parameters.xhtml#sctp-parameters-24
-enum class SctpErrorCauseCode : uint16_t {
-  kInvalidStreamIdentifier = 1,
-  kMissingMandatoryParameter = 2,
-  kStaleCookieError = 3,
-  kOutOfResource = 4,
-  kUnresolvableAddress = 5,
-  kUnrecognizedChunkType = 6,
-  kInvalidMandatoryParameter = 7,
-  kUnrecognizedParameters = 8,
-  kNoUserData = 9,
-  kCookieReceivedWhileShuttingDown = 10,
-  kRestartWithNewAddresses = 11,
-  kUserInitiatedAbort = 12,
-  kProtocolViolation = 13,
-};
-
 // Abstract SctpTransport interface for use internally (by PeerConnection etc.).
 // Exists to allow mock/fake SctpTransports to be created.
 class SctpTransportInternal {
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index 65cd5db..e911ad2 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -366,6 +366,7 @@
     "../api:rtc_error",
     "../api:rtp_parameters",
     "../api:rtp_transceiver_direction",
+    "../api:sctp_transport_interface",
     "../media:codec",
     "../media:codec_list",
     "../media:media_constants",
@@ -510,6 +511,7 @@
     "../api:rtc_stats_api",
     "../api:rtp_parameters",
     "../api:scoped_refptr",
+    "../api:sctp_transport_interface",
     "../api/adaptation:resource_adaptation_api",
     "../api/transport:bandwidth_estimation_settings",
     "../api/transport:bitrate_settings",
@@ -644,6 +646,7 @@
     "../api:priority",
     "../api:rtc_error",
     "../api:scoped_refptr",
+    "../api:sctp_transport_interface",
     "../api:sequence_checker",
     "../api/transport:datagram_transport_interface",
     "../media:rtc_data_sctp_transport_internal",
@@ -964,6 +967,7 @@
     "../api:rtc_error",
     "../api:rtp_parameters",
     "../api:scoped_refptr",
+    "../api:sctp_transport_interface",
     "../api/audio:audio_device",
     "../api/crypto:options",
     "../call:call_interfaces",
@@ -1248,6 +1252,7 @@
     "../api:rtp_parameters",
     "../api:rtp_transceiver_direction",
     "../api:scoped_refptr",
+    "../api:sctp_transport_interface",
     "../api:sequence_checker",
     "../api:turn_customizer",
     "../api/adaptation:resource_adaptation_api",
@@ -1309,6 +1314,7 @@
 
 rtc_library("simulcast_sdp_serializer") {
   visibility = [ ":*" ]
+
   sources = [
     "simulcast_sdp_serializer.cc",
     "simulcast_sdp_serializer.h",
@@ -1443,15 +1449,14 @@
     "../api:rtc_error",
     "../api:rtp_parameters",
     "../api:rtp_transceiver_direction",
+    "../api:sctp_transport_interface",
     "../api:sequence_checker",
     "../api/audio:audio_frame_api",
     "../media:codec",
     "../media:media_constants",
     "../media:rid_description",
-    "../media:rtc_data_sctp_transport_internal",
     "../media:rtp_utils",
     "../media:stream_params",
-    "../p2p:ice_transport_internal",
     "../p2p:p2p_constants",
     "../p2p:transport_description",
     "../p2p:transport_info",
@@ -2225,6 +2230,7 @@
       "../api:rtp_parameters",
       "../api:rtp_transceiver_direction",
       "../api:scoped_refptr",
+      "../api:sctp_transport_interface",
       "../api:sequence_checker",
       "../api/audio_codecs:audio_codecs_api",
       "../api/crypto:options",
@@ -2592,6 +2598,7 @@
       "../api:rtp_sender_interface",
       "../api:rtp_transceiver_direction",
       "../api:scoped_refptr",
+      "../api:sctp_transport_interface",
       "../api:sequence_checker",
       "../api/adaptation:resource_adaptation_api",
       "../api/audio:audio_device",
@@ -2965,6 +2972,7 @@
       "../api:rtp_headers",
       "../api:rtp_parameters",
       "../api:scoped_refptr",
+      "../api:sctp_transport_interface",
       "../api:sequence_checker",
       "../api/adaptation:resource_adaptation_api",
       "../api/audio:audio_device",
diff --git a/pc/webrtc_sdp.cc b/pc/webrtc_sdp.cc
index 406543f..08d598c 100644
--- a/pc/webrtc_sdp.cc
+++ b/pc/webrtc_sdp.cc
@@ -36,13 +36,12 @@
 #include "api/rtc_error.h"
 #include "api/rtp_parameters.h"
 #include "api/rtp_transceiver_direction.h"
+#include "api/sctp_transport_interface.h"
 #include "media/base/codec.h"
 #include "media/base/media_constants.h"
 #include "media/base/rid_description.h"
 #include "media/base/rtp_utils.h"
 #include "media/base/stream_params.h"
-#include "media/sctp/sctp_transport_internal.h"
-#include "p2p/base/ice_transport_internal.h"
 #include "p2p/base/p2p_constants.h"
 #include "p2p/base/transport_description.h"
 #include "p2p/base/transport_info.h"
@@ -2278,7 +2277,7 @@
     }
 
     for (const Codec& existing_codec : media_desc->codecs()) {
-      // TODO(crbug.com/1338902) re-add checks for clockrate and number of
+      // TODO: crbug.com/1338902 - re-add checks for clockrate and number of
       // channels.
       if (!existing_codec.name.empty() && payload_type == existing_codec.id &&
           (!absl::EqualsIgnoreCase(encoding_name, existing_codec.name))) {
@@ -2446,7 +2445,7 @@
 
   // The media level "ice-ufrag" and "ice-pwd".
   // The candidates before update the media level "ice-pwd" and "ice-ufrag".
-  Candidates candidates_orig;
+  std::vector<Candidate> candidates_orig;
   std::string mline_id;
   // Tracks created out of the ssrc attributes.
   StreamParamsVec tracks;
diff --git a/test/pc/sctp/BUILD.gn b/test/pc/sctp/BUILD.gn
index e30fd82..c0a8739 100644
--- a/test/pc/sctp/BUILD.gn
+++ b/test/pc/sctp/BUILD.gn
@@ -15,6 +15,7 @@
     "../../../api:libjingle_peerconnection_api",
     "../../../api:priority",
     "../../../api:rtc_error",
+    "../../../api:sctp_transport_interface",
     "../../../api/environment",
     "../../../api/transport:datagram_transport_interface",
     "../../../api/transport:sctp_transport_factory_interface",