summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/pc/jsep_transport_controller.cc
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/pc/jsep_transport_controller.cc')
-rw-r--r--third_party/libwebrtc/pc/jsep_transport_controller.cc228
1 files changed, 127 insertions, 101 deletions
diff --git a/third_party/libwebrtc/pc/jsep_transport_controller.cc b/third_party/libwebrtc/pc/jsep_transport_controller.cc
index 7c669a5ae3..d5d1cd24a9 100644
--- a/third_party/libwebrtc/pc/jsep_transport_controller.cc
+++ b/third_party/libwebrtc/pc/jsep_transport_controller.cc
@@ -76,14 +76,18 @@ JsepTransportController::~JsepTransportController() {
RTCError JsepTransportController::SetLocalDescription(
SdpType type,
- const cricket::SessionDescription* description) {
+ const cricket::SessionDescription* local_desc,
+ const cricket::SessionDescription* remote_desc) {
+ RTC_DCHECK(local_desc);
TRACE_EVENT0("webrtc", "JsepTransportController::SetLocalDescription");
+
if (!network_thread_->IsCurrent()) {
return network_thread_->BlockingCall(
- [=] { return SetLocalDescription(type, description); });
+ [=] { return SetLocalDescription(type, local_desc, remote_desc); });
}
RTC_DCHECK_RUN_ON(network_thread_);
+
if (!initial_offerer_.has_value()) {
initial_offerer_.emplace(type == SdpType::kOffer);
if (*initial_offerer_) {
@@ -92,20 +96,22 @@ RTCError JsepTransportController::SetLocalDescription(
SetIceRole_n(cricket::ICEROLE_CONTROLLED);
}
}
- return ApplyDescription_n(/*local=*/true, type, description);
+ return ApplyDescription_n(/*local=*/true, type, local_desc, remote_desc);
}
RTCError JsepTransportController::SetRemoteDescription(
SdpType type,
- const cricket::SessionDescription* description) {
+ const cricket::SessionDescription* local_desc,
+ const cricket::SessionDescription* remote_desc) {
+ RTC_DCHECK(remote_desc);
TRACE_EVENT0("webrtc", "JsepTransportController::SetRemoteDescription");
if (!network_thread_->IsCurrent()) {
return network_thread_->BlockingCall(
- [=] { return SetRemoteDescription(type, description); });
+ [=] { return SetRemoteDescription(type, local_desc, remote_desc); });
}
RTC_DCHECK_RUN_ON(network_thread_);
- return ApplyDescription_n(/*local=*/false, type, description);
+ return ApplyDescription_n(/*local=*/false, type, local_desc, remote_desc);
}
RtpTransportInternal* JsepTransportController::GetRtpTransport(
@@ -148,7 +154,7 @@ JsepTransportController::GetRtcpDtlsTransport(const std::string& mid) const {
return jsep_transport->rtcp_dtls_transport();
}
-rtc::scoped_refptr<webrtc::DtlsTransport>
+rtc::scoped_refptr<DtlsTransport>
JsepTransportController::LookupDtlsTransportByMid(const std::string& mid) {
RTC_DCHECK_RUN_ON(network_thread_);
auto jsep_transport = GetJsepTransportForMid(mid);
@@ -383,7 +389,7 @@ RTCError JsepTransportController::RollbackTransports() {
return RTCError::OK();
}
-rtc::scoped_refptr<webrtc::IceTransportInterface>
+rtc::scoped_refptr<IceTransportInterface>
JsepTransportController::CreateIceTransport(const std::string& transport_name,
bool rtcp) {
int component = rtcp ? cricket::ICE_CANDIDATE_COMPONENT_RTCP
@@ -433,29 +439,43 @@ JsepTransportController::CreateDtlsTransport(
this, &JsepTransportController::OnTransportWritableState_n);
dtls->SignalReceivingState.connect(
this, &JsepTransportController::OnTransportReceivingState_n);
- dtls->ice_transport()->SignalGatheringState.connect(
- this, &JsepTransportController::OnTransportGatheringState_n);
+ dtls->ice_transport()->SetGatheringStateCallback(
+ [this](cricket::IceTransportInternal* transport) {
+ RTC_DCHECK_RUN_ON(network_thread_);
+ OnTransportGatheringState_n(transport);
+ });
dtls->ice_transport()->SignalCandidateGathered.connect(
this, &JsepTransportController::OnTransportCandidateGathered_n);
- dtls->ice_transport()->SignalCandidateError.connect(
- this, &JsepTransportController::OnTransportCandidateError_n);
- dtls->ice_transport()->SignalCandidatesRemoved.connect(
- this, &JsepTransportController::OnTransportCandidatesRemoved_n);
+ dtls->ice_transport()->SetCandidateErrorCallback(
+ [this](cricket::IceTransportInternal* transport,
+ const cricket::IceCandidateErrorEvent& error) {
+ RTC_DCHECK_RUN_ON(network_thread_);
+ OnTransportCandidateError_n(transport, error);
+ });
+ dtls->ice_transport()->SetCandidatesRemovedCallback(
+ [this](cricket::IceTransportInternal* transport,
+ const cricket::Candidates& candidates) {
+ RTC_DCHECK_RUN_ON(network_thread_);
+ OnTransportCandidatesRemoved_n(transport, candidates);
+ });
dtls->ice_transport()->SignalRoleConflict.connect(
this, &JsepTransportController::OnTransportRoleConflict_n);
dtls->ice_transport()->SignalStateChanged.connect(
this, &JsepTransportController::OnTransportStateChanged_n);
dtls->ice_transport()->SignalIceTransportStateChanged.connect(
this, &JsepTransportController::OnTransportStateChanged_n);
- dtls->ice_transport()->SignalCandidatePairChanged.connect(
- this, &JsepTransportController::OnTransportCandidatePairChanged_n);
+ dtls->ice_transport()->SetCandidatePairChangeCallback(
+ [this](const cricket::CandidatePairChangeEvent& event) {
+ RTC_DCHECK_RUN_ON(network_thread_);
+ OnTransportCandidatePairChanged_n(event);
+ });
dtls->SubscribeDtlsHandshakeError(
[this](rtc::SSLHandshakeError error) { OnDtlsHandshakeError(error); });
return dtls;
}
-std::unique_ptr<webrtc::RtpTransport>
+std::unique_ptr<RtpTransport>
JsepTransportController::CreateUnencryptedRtpTransport(
const std::string& transport_name,
rtc::PacketTransportInternal* rtp_packet_transport,
@@ -470,13 +490,12 @@ JsepTransportController::CreateUnencryptedRtpTransport(
return unencrypted_rtp_transport;
}
-std::unique_ptr<webrtc::SrtpTransport>
-JsepTransportController::CreateSdesTransport(
+std::unique_ptr<SrtpTransport> JsepTransportController::CreateSdesTransport(
const std::string& transport_name,
cricket::DtlsTransportInternal* rtp_dtls_transport,
cricket::DtlsTransportInternal* rtcp_dtls_transport) {
RTC_DCHECK_RUN_ON(network_thread_);
- auto srtp_transport = std::make_unique<webrtc::SrtpTransport>(
+ auto srtp_transport = std::make_unique<SrtpTransport>(
rtcp_dtls_transport == nullptr, *config_.field_trials);
RTC_DCHECK(rtp_dtls_transport);
srtp_transport->SetRtpPacketTransport(rtp_dtls_transport);
@@ -489,13 +508,13 @@ JsepTransportController::CreateSdesTransport(
return srtp_transport;
}
-std::unique_ptr<webrtc::DtlsSrtpTransport>
+std::unique_ptr<DtlsSrtpTransport>
JsepTransportController::CreateDtlsSrtpTransport(
const std::string& transport_name,
cricket::DtlsTransportInternal* rtp_dtls_transport,
cricket::DtlsTransportInternal* rtcp_dtls_transport) {
RTC_DCHECK_RUN_ON(network_thread_);
- auto dtls_srtp_transport = std::make_unique<webrtc::DtlsSrtpTransport>(
+ auto dtls_srtp_transport = std::make_unique<DtlsSrtpTransport>(
rtcp_dtls_transport == nullptr, *config_.field_trials);
if (config_.enable_external_auth) {
dtls_srtp_transport->EnableExternalAuth();
@@ -550,18 +569,20 @@ JsepTransportController::GetActiveDtlsTransports() {
RTCError JsepTransportController::ApplyDescription_n(
bool local,
SdpType type,
- const cricket::SessionDescription* description) {
+ const cricket::SessionDescription* local_desc,
+ const cricket::SessionDescription* remote_desc) {
TRACE_EVENT0("webrtc", "JsepTransportController::ApplyDescription_n");
- RTC_DCHECK(description);
- if (local) {
- local_desc_ = description;
- } else {
- remote_desc_ = description;
- }
+ // Stash away the description object that we'll be applying (since this
+ // function is used for both local and remote).
+ const cricket::SessionDescription* description =
+ local ? local_desc : remote_desc;
+
+ RTC_DCHECK(description);
RTCError error;
- error = ValidateAndMaybeUpdateBundleGroups(local, type, description);
+ error =
+ ValidateAndMaybeUpdateBundleGroups(local, type, local_desc, remote_desc);
if (!error.ok()) {
return error;
}
@@ -673,7 +694,11 @@ RTCError JsepTransportController::ApplyDescription_n(
RTCError JsepTransportController::ValidateAndMaybeUpdateBundleGroups(
bool local,
SdpType type,
- const cricket::SessionDescription* description) {
+ const cricket::SessionDescription* local_desc,
+ const cricket::SessionDescription* remote_desc) {
+ const cricket::SessionDescription* description =
+ local ? local_desc : remote_desc;
+
RTC_DCHECK(description);
std::vector<const cricket::ContentGroup*> new_bundle_groups =
@@ -739,72 +764,74 @@ RTCError JsepTransportController::ValidateAndMaybeUpdateBundleGroups(
}
}
} else if (type == SdpType::kAnswer) {
- std::vector<const cricket::ContentGroup*> offered_bundle_groups =
- local ? remote_desc_->GetGroupsByName(cricket::GROUP_TYPE_BUNDLE)
- : local_desc_->GetGroupsByName(cricket::GROUP_TYPE_BUNDLE);
-
- std::map<std::string, const cricket::ContentGroup*>
- offered_bundle_groups_by_mid;
- for (const cricket::ContentGroup* offered_bundle_group :
- offered_bundle_groups) {
- for (const std::string& content_name :
- offered_bundle_group->content_names()) {
- offered_bundle_groups_by_mid[content_name] = offered_bundle_group;
+ if ((local && remote_desc) || (!local && local_desc)) {
+ std::vector<const cricket::ContentGroup*> offered_bundle_groups =
+ local ? remote_desc->GetGroupsByName(cricket::GROUP_TYPE_BUNDLE)
+ : local_desc->GetGroupsByName(cricket::GROUP_TYPE_BUNDLE);
+
+ std::map<std::string, const cricket::ContentGroup*>
+ offered_bundle_groups_by_mid;
+ for (const cricket::ContentGroup* offered_bundle_group :
+ offered_bundle_groups) {
+ for (const std::string& content_name :
+ offered_bundle_group->content_names()) {
+ offered_bundle_groups_by_mid[content_name] = offered_bundle_group;
+ }
}
- }
- std::map<const cricket::ContentGroup*, const cricket::ContentGroup*>
- new_bundle_groups_by_offered_bundle_groups;
- for (const cricket::ContentGroup* new_bundle_group : new_bundle_groups) {
- if (!new_bundle_group->FirstContentName()) {
- // Empty groups could be a subset of any group.
- continue;
- }
- // The group in the answer (new_bundle_group) must have a corresponding
- // group in the offer (original_group), because the answer groups may only
- // be subsets of the offer groups.
- auto it = offered_bundle_groups_by_mid.find(
- *new_bundle_group->FirstContentName());
- if (it == offered_bundle_groups_by_mid.end()) {
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "A BUNDLE group was added in the answer that did not "
- "exist in the offer.");
- }
- const cricket::ContentGroup* offered_bundle_group = it->second;
- if (new_bundle_groups_by_offered_bundle_groups.find(
- offered_bundle_group) !=
- new_bundle_groups_by_offered_bundle_groups.end()) {
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "A MID in the answer has changed group.");
- }
- new_bundle_groups_by_offered_bundle_groups.insert(
- std::make_pair(offered_bundle_group, new_bundle_group));
- for (const std::string& content_name :
- new_bundle_group->content_names()) {
- it = offered_bundle_groups_by_mid.find(content_name);
- // The BUNDLE group in answer should be a subset of offered group.
- if (it == offered_bundle_groups_by_mid.end() ||
- it->second != offered_bundle_group) {
+ std::map<const cricket::ContentGroup*, const cricket::ContentGroup*>
+ new_bundle_groups_by_offered_bundle_groups;
+ for (const cricket::ContentGroup* new_bundle_group : new_bundle_groups) {
+ if (!new_bundle_group->FirstContentName()) {
+ // Empty groups could be a subset of any group.
+ continue;
+ }
+ // The group in the answer (new_bundle_group) must have a corresponding
+ // group in the offer (original_group), because the answer groups may
+ // only be subsets of the offer groups.
+ auto it = offered_bundle_groups_by_mid.find(
+ *new_bundle_group->FirstContentName());
+ if (it == offered_bundle_groups_by_mid.end()) {
return RTCError(RTCErrorType::INVALID_PARAMETER,
- "A BUNDLE group in answer contains a MID='" +
- content_name +
- "' that was not in the offered group.");
+ "A BUNDLE group was added in the answer that did not "
+ "exist in the offer.");
}
- }
- }
-
- for (const auto& bundle_group : bundles_.bundle_groups()) {
- for (const std::string& content_name : bundle_group->content_names()) {
- // An answer that removes m= sections from pre-negotiated BUNDLE group
- // without rejecting it, is invalid.
- auto it = new_bundle_groups_by_mid.find(content_name);
- if (it == new_bundle_groups_by_mid.end()) {
- auto* content_info = description->GetContentByName(content_name);
- if (!content_info || !content_info->rejected) {
+ const cricket::ContentGroup* offered_bundle_group = it->second;
+ if (new_bundle_groups_by_offered_bundle_groups.find(
+ offered_bundle_group) !=
+ new_bundle_groups_by_offered_bundle_groups.end()) {
+ return RTCError(RTCErrorType::INVALID_PARAMETER,
+ "A MID in the answer has changed group.");
+ }
+ new_bundle_groups_by_offered_bundle_groups.insert(
+ std::make_pair(offered_bundle_group, new_bundle_group));
+ for (const std::string& content_name :
+ new_bundle_group->content_names()) {
+ it = offered_bundle_groups_by_mid.find(content_name);
+ // The BUNDLE group in answer should be a subset of offered group.
+ if (it == offered_bundle_groups_by_mid.end() ||
+ it->second != offered_bundle_group) {
return RTCError(RTCErrorType::INVALID_PARAMETER,
- "Answer cannot remove m= section with mid='" +
+ "A BUNDLE group in answer contains a MID='" +
content_name +
- "' from already-established BUNDLE group.");
+ "' that was not in the offered group.");
+ }
+ }
+ }
+
+ for (const auto& bundle_group : bundles_.bundle_groups()) {
+ for (const std::string& content_name : bundle_group->content_names()) {
+ // An answer that removes m= sections from pre-negotiated BUNDLE group
+ // without rejecting it, is invalid.
+ auto it = new_bundle_groups_by_mid.find(content_name);
+ if (it == new_bundle_groups_by_mid.end()) {
+ auto* content_info = description->GetContentByName(content_name);
+ if (!content_info || !content_info->rejected) {
+ return RTCError(RTCErrorType::INVALID_PARAMETER,
+ "Answer cannot remove m= section with mid='" +
+ content_name +
+ "' from already-established BUNDLE group.");
+ }
}
}
}
@@ -985,13 +1012,12 @@ int JsepTransportController::GetRtpAbsSendTimeHeaderExtensionId(
const cricket::MediaContentDescription* content_desc =
content_info.media_description();
- const webrtc::RtpExtension* send_time_extension =
- webrtc::RtpExtension::FindHeaderExtensionByUri(
- content_desc->rtp_header_extensions(),
- webrtc::RtpExtension::kAbsSendTimeUri,
+ const RtpExtension* send_time_extension =
+ RtpExtension::FindHeaderExtensionByUri(
+ content_desc->rtp_header_extensions(), RtpExtension::kAbsSendTimeUri,
config_.crypto_options.srtp.enable_encrypted_rtp_header_extensions
- ? webrtc::RtpExtension::kPreferEncryptedExtension
- : webrtc::RtpExtension::kDiscardEncryptedExtension);
+ ? RtpExtension::kPreferEncryptedExtension
+ : RtpExtension::kDiscardEncryptedExtension);
return send_time_extension ? send_time_extension->id : -1;
}
@@ -1039,7 +1065,7 @@ RTCError JsepTransportController::MaybeCreateJsepTransport(
"SDES and DTLS-SRTP cannot be enabled at the same time.");
}
- rtc::scoped_refptr<webrtc::IceTransportInterface> ice =
+ rtc::scoped_refptr<IceTransportInterface> ice =
CreateIceTransport(content_info.name, /*rtcp=*/false);
std::unique_ptr<cricket::DtlsTransportInternal> rtp_dtls_transport =
@@ -1050,7 +1076,7 @@ RTCError JsepTransportController::MaybeCreateJsepTransport(
std::unique_ptr<SrtpTransport> sdes_transport;
std::unique_ptr<DtlsSrtpTransport> dtls_srtp_transport;
- rtc::scoped_refptr<webrtc::IceTransportInterface> rtcp_ice;
+ rtc::scoped_refptr<IceTransportInterface> rtcp_ice;
if (config_.rtcp_mux_policy !=
PeerConnectionInterface::kRtcpMuxPolicyRequire &&
content_info.type == cricket::MediaProtocolType::kRtp) {
@@ -1096,7 +1122,7 @@ RTCError JsepTransportController::MaybeCreateJsepTransport(
OnRtcpPacketReceived_n(buffer, packet_time_ms);
});
jsep_transport->rtp_transport()->SetUnDemuxableRtpPacketReceivedHandler(
- [this](webrtc::RtpPacketReceived& packet) {
+ [this](RtpPacketReceived& packet) {
RTC_DCHECK_RUN_ON(network_thread_);
OnUnDemuxableRtpPacketReceived_n(packet);
});
@@ -1421,7 +1447,7 @@ void JsepTransportController::OnRtcpPacketReceived_n(
}
void JsepTransportController::OnUnDemuxableRtpPacketReceived_n(
- const webrtc::RtpPacketReceived& packet) {
+ const RtpPacketReceived& packet) {
RTC_DCHECK(config_.un_demuxable_packet_handler);
config_.un_demuxable_packet_handler(packet);
}