Create SctpDataChannel objects on the network thread.
* Change data channel creation code to return RTCError for more
detailed/accurate errors.
* Move DataChannelController::sid_allocator_ to the network thread.
* Add a temporary duplicate vector of channels on the network thread.
This will eventually be the main vector.
* Delete one test that turns out to be racy (as long as we're using
both the signaling and network threads).
Bug: webrtc:11547, webrtc:12796
Change-Id: I93ab721a09872d075046a907df60e8aee4263371
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/298624
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39719}
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index 5697624..8de19b2 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -1392,6 +1392,11 @@
RTC_DCHECK_RUN_ON(signaling_thread());
TRACE_EVENT0("webrtc", "PeerConnection::CreateDataChannel");
+ if (IsClosed()) {
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_STATE,
+ "CreateDataChannelOrError: PeerConnection is closed.");
+ }
+
bool first_datachannel = !data_channel_controller_.HasUsedDataChannels();
InternalDataChannelInit internal_config;
@@ -1400,16 +1405,15 @@
}
internal_config.fallback_ssl_role = sdp_handler_->GuessSslRole();
-
- // TODO(bugs.webrtc.org/12796): Return a more specific error.
- rtc::scoped_refptr<DataChannelInterface> channel(
+ RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>> ret =
data_channel_controller_.InternalCreateDataChannelWithProxy(
- label, internal_config));
- if (!channel.get()) {
- return RTCError(RTCErrorType::INTERNAL_ERROR,
- "Data channel creation failed");
+ label, internal_config);
+ if (!ret.ok()) {
+ return ret.MoveError();
}
+ rtc::scoped_refptr<DataChannelInterface> channel = ret.MoveValue();
+
// Trigger the onRenegotiationNeeded event for
// the first SCTP DataChannel.
if (first_datachannel) {