Move Destroy/Create steps for DataChannelTransport to PeerConnection.
This moves steps from the sdp code for pc state over to the PC class
and slightly simplifies the contract between the two classes.
Moving forward it's easier to consolidate those steps in the PC
class with other grouped operations e.g. during teardown.
Also removing GetDataMid() method in favor of the sctp_mid() property.
Bug: none
Change-Id: I938f953099d327377abd94e6b2c9ece803d88e40
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/324300
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40981}
diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc
index 4a77b75..c795ccf 100644
--- a/pc/sdp_offer_answer.cc
+++ b/pc/sdp_offer_answer.cc
@@ -3791,13 +3791,15 @@
return error;
}
} else if (media_type == cricket::MEDIA_TYPE_DATA) {
- if (pc_->GetDataMid() && new_content.name != *(pc_->GetDataMid())) {
+ const auto data_mid = pc_->sctp_mid();
+ if (data_mid && new_content.name != data_mid.value()) {
// Ignore all but the first data section.
RTC_LOG(LS_INFO) << "Ignoring data media section with MID="
<< new_content.name;
continue;
}
- RTCError error = UpdateDataChannel(source, new_content, bundle_group);
+ RTCError error =
+ UpdateDataChannelTransport(source, new_content, bundle_group);
if (!error.ok()) {
return error;
}
@@ -3979,7 +3981,7 @@
return RTCError::OK();
}
-RTCError SdpOfferAnswerHandler::UpdateDataChannel(
+RTCError SdpOfferAnswerHandler::UpdateDataChannelTransport(
cricket::ContentSource source,
const cricket::ContentInfo& content,
const cricket::ContentGroup* bundle_group) {
@@ -3991,8 +3993,8 @@
sb << "Rejected data channel transport with mid=" << content.mid();
RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA, sb.Release());
error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE);
- DestroyDataChannelTransport(error);
- } else if (!CreateDataChannel(content.name)) {
+ pc_->DestroyDataChannelTransport(error);
+ } else if (!pc_->CreateDataChannelTransport(content.name)) {
LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
"Failed to create data channel.");
}
@@ -4323,8 +4325,9 @@
session_options->media_description_options.push_back(
GetMediaDescriptionOptionsForRejectedData(mid));
} else {
- RTC_CHECK(pc_->GetDataMid());
- if (mid == *(pc_->GetDataMid())) {
+ const auto data_mid = pc_->sctp_mid();
+ RTC_CHECK(data_mid);
+ if (mid == data_mid.value()) {
session_options->media_description_options.push_back(
GetMediaDescriptionOptionsForActiveData(mid));
} else {
@@ -4365,9 +4368,9 @@
}
// Lastly, add a m-section if we have requested local data channels and an
// m section does not already exist.
- if (!pc_->GetDataMid() && data_channel_controller()->HasDataChannels()) {
+ if (!pc_->sctp_mid() && data_channel_controller()->HasDataChannels()) {
// Attempt to recycle a stopped m-line.
- // TODO(crbug.com/1442604): GetDataMid() should return the mid if one was
+ // TODO(crbug.com/1442604): sctp_mid() should return the mid if one was
// ever created but rejected.
bool recycled = false;
for (size_t i = 0; i < session_options->media_description_options.size();
@@ -4510,7 +4513,7 @@
// Reject all data sections if data channels are disabled.
// Reject a data section if it has already been rejected.
// Reject all data sections except for the first one.
- if (content.rejected || content.name != *(pc_->GetDataMid())) {
+ if (content.rejected || content.name != *(pc_->sctp_mid())) {
session_options->media_description_options.push_back(
GetMediaDescriptionOptionsForRejectedData(content.name));
} else {
@@ -5003,14 +5006,14 @@
RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA,
"No data channel section in the description.");
error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE);
- DestroyDataChannelTransport(error);
+ pc_->DestroyDataChannelTransport(error);
} else if (data_info->rejected) {
rtc::StringBuilder sb;
sb << "Rejected data channel with mid=" << data_info->name << ".";
RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA, sb.Release());
error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE);
- DestroyDataChannelTransport(error);
+ pc_->DestroyDataChannelTransport(error);
}
}
@@ -5193,7 +5196,7 @@
}
const cricket::ContentInfo* data = cricket::GetFirstDataContent(&desc);
- if (data && !data->rejected && !CreateDataChannel(data->name)) {
+ if (data && !data->rejected && !pc_->CreateDataChannelTransport(data->name)) {
LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
"Failed to create data channel.");
}
@@ -5201,33 +5204,6 @@
return RTCError::OK();
}
-bool SdpOfferAnswerHandler::CreateDataChannel(const std::string& mid) {
- RTC_DCHECK_RUN_ON(signaling_thread());
- RTC_DCHECK(!pc_->sctp_mid().has_value() || mid == pc_->sctp_mid().value());
- RTC_LOG(LS_INFO) << "Creating data channel, mid=" << mid;
-
- absl::optional<std::string> transport_name =
- context_->network_thread()->BlockingCall([&] {
- RTC_DCHECK_RUN_ON(context_->network_thread());
- return pc_->SetupDataChannelTransport_n(mid);
- });
- if (!transport_name)
- return false;
-
- pc_->SetSctpDataInfo(mid, *transport_name);
- return true;
-}
-
-void SdpOfferAnswerHandler::DestroyDataChannelTransport(RTCError error) {
- RTC_DCHECK_RUN_ON(signaling_thread());
- context_->network_thread()->BlockingCall(
- [&, data_channel_controller = data_channel_controller()] {
- RTC_DCHECK_RUN_ON(context_->network_thread());
- pc_->TeardownDataChannelTransport_n(error);
- });
- pc_->ResetSctpDataInfo();
-}
-
void SdpOfferAnswerHandler::DestroyAllChannels() {
RTC_DCHECK_RUN_ON(signaling_thread());
if (!transceivers()) {
@@ -5252,7 +5228,7 @@
}
}
- DestroyDataChannelTransport({});
+ pc_->DestroyDataChannelTransport({});
}
void SdpOfferAnswerHandler::GenerateMediaDescriptionOptions(