Make mid_ a private member variable

Bug: webrtc:42233761
Change-Id: I17458a5b8c2d1999b40e4272dd51502ca6099219
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374665
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43791}
This commit is contained in:
Tommi 2025-01-21 22:34:35 +01:00 committed by WebRTC LUCI CQ
parent 7fe307df59
commit a70cc7886c
5 changed files with 87 additions and 88 deletions

View File

@ -223,7 +223,7 @@ bool JsepSessionDescription::AddCandidate(
if (mediasection_index >= number_of_mediasections()) if (mediasection_index >= number_of_mediasections())
return false; return false;
const std::string& content_name = const std::string& content_name =
description_->contents()[mediasection_index].name; description_->contents()[mediasection_index].mid();
const cricket::TransportInfo* transport_info = const cricket::TransportInfo* transport_info =
description_->GetTransportInfoByName(content_name); description_->GetTransportInfoByName(content_name);
if (!transport_info) { if (!transport_info) {
@ -314,7 +314,7 @@ bool JsepSessionDescription::GetMediasectionIndex(
bool found = false; bool found = false;
// Try to match the sdp_mid with content name. // Try to match the sdp_mid with content name.
for (size_t i = 0; i < description_->contents().size(); ++i) { for (size_t i = 0; i < description_->contents().size(); ++i) {
if (candidate->sdp_mid() == description_->contents().at(i).name) { if (candidate->sdp_mid() == description_->contents().at(i).mid()) {
*index = i; *index = i;
found = true; found = true;
break; break;
@ -333,7 +333,7 @@ int JsepSessionDescription::GetMediasectionIndex(const Candidate& candidate) {
// Find the description with a matching transport name of the candidate. // Find the description with a matching transport name of the candidate.
const std::string& transport_name = candidate.transport_name(); const std::string& transport_name = candidate.transport_name();
for (size_t i = 0; i < description_->contents().size(); ++i) { for (size_t i = 0; i < description_->contents().size(); ++i) {
if (transport_name == description_->contents().at(i).name) { if (transport_name == description_->contents().at(i).mid()) {
return static_cast<int>(i); return static_cast<int>(i);
} }
} }

View File

@ -385,7 +385,7 @@ std::vector<const ContentInfo*> GetActiveContents(
const MediaDescriptionOptions& media_options = const MediaDescriptionOptions& media_options =
session_options.media_description_options[i]; session_options.media_description_options[i];
if (!content.rejected && !media_options.stopped && if (!content.rejected && !media_options.stopped &&
content.name == media_options.mid) { content.mid() == media_options.mid) {
active_contents.push_back(&content); active_contents.push_back(&content);
} }
} }
@ -1145,13 +1145,13 @@ webrtc::RTCErrorOr<std::vector<Codec>> GetNegotiatedCodecsForOffer(
// Add the codecs from current content if it exists and is not rejected nor // Add the codecs from current content if it exists and is not rejected nor
// recycled. // recycled.
if (current_content && !current_content->rejected && if (current_content && !current_content->rejected &&
current_content->name == media_description_options.mid) { current_content->mid() == media_description_options.mid) {
if (!IsMediaContentOfType(current_content, if (!IsMediaContentOfType(current_content,
media_description_options.type)) { media_description_options.type)) {
// Can happen if the remote side re-uses a MID while recycling. // Can happen if the remote side re-uses a MID while recycling.
LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
"Media type for content with mid='" + "Media type for content with mid='" +
current_content->name + current_content->mid() +
"' does not match previous type."); "' does not match previous type.");
} }
const MediaContentDescription* mcd = current_content->media_description(); const MediaContentDescription* mcd = current_content->media_description();
@ -1223,13 +1223,13 @@ webrtc::RTCErrorOr<Codecs> GetNegotiatedCodecsForAnswer(
// Add the codecs from current content if it exists and is not rejected nor // Add the codecs from current content if it exists and is not rejected nor
// recycled. // recycled.
if (current_content && !current_content->rejected && if (current_content && !current_content->rejected &&
current_content->name == media_description_options.mid) { current_content->mid() == media_description_options.mid) {
if (!IsMediaContentOfType(current_content, if (!IsMediaContentOfType(current_content,
media_description_options.type)) { media_description_options.type)) {
// Can happen if the remote side re-uses a MID while recycling. // Can happen if the remote side re-uses a MID while recycling.
LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
"Media type for content with mid='" + "Media type for content with mid='" +
current_content->name + current_content->mid() +
"' does not match previous type."); "' does not match previous type.");
} }
const MediaContentDescription* mcd = current_content->media_description(); const MediaContentDescription* mcd = current_content->media_description();
@ -1492,7 +1492,7 @@ MediaSessionDescriptionFactory::CreateOfferOrError(
// type to represent different codecs, or same IDs for different header // type to represent different codecs, or same IDs for different header
// extensions. We need to detect this and not try to bundle those media // extensions. We need to detect this and not try to bundle those media
// descriptions together. // descriptions together.
offer_bundle.AddContentName(content.name); offer_bundle.AddContentName(content.mid());
} }
if (!offer_bundle.content_names().empty()) { if (!offer_bundle.content_names().empty()) {
offer->AddGroup(offer_bundle); offer->AddGroup(offer_bundle);
@ -1606,7 +1606,7 @@ MediaSessionDescriptionFactory::CreateAnswerOrError(
// MediaDescriptionOptions. // MediaDescriptionOptions.
RTC_DCHECK( RTC_DCHECK(
IsMediaContentOfType(offer_content, media_description_options.type)); IsMediaContentOfType(offer_content, media_description_options.type));
RTC_DCHECK(media_description_options.mid == offer_content->name); RTC_DCHECK(media_description_options.mid == offer_content->mid());
// Get the index of the BUNDLE group that this MID belongs to, if any. // Get the index of the BUNDLE group that this MID belongs to, if any.
std::optional<size_t> bundle_index; std::optional<size_t> bundle_index;
for (size_t i = 0; i < offer_bundles.size(); ++i) { for (size_t i = 0; i < offer_bundles.size(); ++i) {
@ -1673,10 +1673,10 @@ MediaSessionDescriptionFactory::CreateAnswerOrError(
if (!added.rejected && session_options.bundle_enabled && if (!added.rejected && session_options.bundle_enabled &&
bundle_index.has_value()) { bundle_index.has_value()) {
// The `bundle_index` is for `media_description_options.mid`. // The `bundle_index` is for `media_description_options.mid`.
RTC_DCHECK_EQ(media_description_options.mid, added.name); RTC_DCHECK_EQ(media_description_options.mid, added.mid());
answer_bundles[bundle_index.value()].AddContentName(added.name); answer_bundles[bundle_index.value()].AddContentName(added.mid());
bundle_transports[bundle_index.value()].reset( bundle_transports[bundle_index.value()].reset(
new TransportInfo(*answer->GetTransportInfoByName(added.name))); new TransportInfo(*answer->GetTransportInfoByName(added.mid())));
} }
} }

View File

@ -288,7 +288,7 @@ bool MediaSectionsInSameOrder(const SessionDescription& current_desc,
// valid for the MID and media type to change. // valid for the MID and media type to change.
continue; continue;
} }
if (new_desc.contents()[i].name != current_desc.contents()[i].name) { if (new_desc.contents()[i].mid() != current_desc.contents()[i].mid()) {
return false; return false;
} }
const MediaContentDescription* new_desc_mdesc = const MediaContentDescription* new_desc_mdesc =
@ -320,7 +320,7 @@ RTCError VerifyCrypto(const SessionDescription* desc,
if (content_info.rejected) { if (content_info.rejected) {
continue; continue;
} }
const std::string& mid = content_info.name; const auto mid = content_info.mid();
auto it = bundle_groups_by_mid.find(mid); auto it = bundle_groups_by_mid.find(mid);
const cricket::ContentGroup* bundle = const cricket::ContentGroup* bundle =
it != bundle_groups_by_mid.end() ? it->second : nullptr; it != bundle_groups_by_mid.end() ? it->second : nullptr;
@ -362,7 +362,7 @@ bool VerifyIceUfragPwdPresent(
if (content_info.rejected) { if (content_info.rejected) {
continue; continue;
} }
const std::string& mid = content_info.name; const auto mid = content_info.mid();
auto it = bundle_groups_by_mid.find(mid); auto it = bundle_groups_by_mid.find(mid);
const cricket::ContentGroup* bundle = const cricket::ContentGroup* bundle =
it != bundle_groups_by_mid.end() ? it->second : nullptr; it != bundle_groups_by_mid.end() ? it->second : nullptr;
@ -393,18 +393,18 @@ bool VerifyIceUfragPwdPresent(
RTCError ValidateMids(const cricket::SessionDescription& description) { RTCError ValidateMids(const cricket::SessionDescription& description) {
std::set<std::string> mids; std::set<std::string> mids;
for (const cricket::ContentInfo& content : description.contents()) { for (const cricket::ContentInfo& content : description.contents()) {
if (content.name.empty()) { if (content.mid().empty()) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
"A media section is missing a MID attribute."); "A media section is missing a MID attribute.");
} }
if (content.name.size() > kMidMaxSize) { if (content.mid().size() > kMidMaxSize) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
"The MID attribute exceeds the maximum supported " "The MID attribute exceeds the maximum supported "
"length of 16 characters."); "length of 16 characters.");
} }
if (!mids.insert(content.name).second) { if (!mids.insert(content.mid()).second) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
"Duplicate a=mid value '" + content.name + "'."); "Duplicate a=mid value '" + content.mid() + "'.");
} }
} }
return RTCError::OK(); return RTCError::OK();
@ -919,7 +919,7 @@ void UpdateRtpHeaderExtensionPreferencesFromSdpMunging(
RTC_DCHECK(description); RTC_DCHECK(description);
RTC_DCHECK(transceivers); RTC_DCHECK(transceivers);
for (const auto& content : description->contents()) { for (const auto& content : description->contents()) {
auto transceiver = transceivers->FindByMid(content.name); auto transceiver = transceivers->FindByMid(content.mid());
if (!transceiver) { if (!transceiver) {
continue; continue;
} }
@ -2115,9 +2115,9 @@ void SdpOfferAnswerHandler::ApplyRemoteDescription(
// remote description, this should reset pending_ice_restarts and compare // remote description, this should reset pending_ice_restarts and compare
// against the current description. // against the current description.
if (CheckForRemoteIceRestart(operation->old_remote_description(), if (CheckForRemoteIceRestart(operation->old_remote_description(),
remote_description(), content.name)) { remote_description(), content.mid())) {
if (operation->type() == SdpType::kOffer) { if (operation->type() == SdpType::kOffer) {
pending_ice_restarts_.insert(content.name); pending_ice_restarts_.insert(content.mid());
} }
} else { } else {
// We retain all received candidates only if ICE is not restarted. // We retain all received candidates only if ICE is not restarted.
@ -2128,7 +2128,7 @@ void SdpOfferAnswerHandler::ApplyRemoteDescription(
// description plus any candidates added since then. We should remove // description plus any candidates added since then. We should remove
// this once we're sure it won't break anything. // this once we're sure it won't break anything.
WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription(
operation->old_remote_description(), content.name, operation->old_remote_description(), content.mid(),
mutable_remote_description()); mutable_remote_description());
} }
} }
@ -2226,7 +2226,7 @@ void SdpOfferAnswerHandler::ApplyRemoteDescriptionUpdateTransceiverState(
stream_ids = media_desc->streams()[0].stream_ids(); stream_ids = media_desc->streams()[0].stream_ids();
} }
RTC_LOG(LS_INFO) << "Processing the MSIDs for MID=" << content->name RTC_LOG(LS_INFO) << "Processing the MSIDs for MID=" << content->mid()
<< " (" << GetStreamIdsString(stream_ids) << ")."; << " (" << GetStreamIdsString(stream_ids) << ").";
SetAssociatedRemoteStreams(transceiver->receiver_internal(), stream_ids, SetAssociatedRemoteStreams(transceiver->receiver_internal(), stream_ids,
&added_streams, &removed_streams); &added_streams, &removed_streams);
@ -2237,7 +2237,7 @@ void SdpOfferAnswerHandler::ApplyRemoteDescriptionUpdateTransceiverState(
if (!transceiver->fired_direction() || if (!transceiver->fired_direction() ||
!RtpTransceiverDirectionHasRecv(*transceiver->fired_direction())) { !RtpTransceiverDirectionHasRecv(*transceiver->fired_direction())) {
RTC_LOG(LS_INFO) << "Processing the addition of a remote track for MID=" RTC_LOG(LS_INFO) << "Processing the addition of a remote track for MID="
<< content->name << "."; << content->mid() << ".";
// Since the transceiver is passed to the user in an // Since the transceiver is passed to the user in an
// OnTrack event, we must use the proxied transceiver. // OnTrack event, we must use the proxied transceiver.
now_receiving_transceivers.push_back(transceiver_ext); now_receiving_transceivers.push_back(transceiver_ext);
@ -2281,7 +2281,7 @@ void SdpOfferAnswerHandler::ApplyRemoteDescriptionUpdateTransceiverState(
// 2.2.8.1.12: If the media description is rejected, and transceiver is // 2.2.8.1.12: If the media description is rejected, and transceiver is
// not already stopped, stop the RTCRtpTransceiver transceiver. // not already stopped, stop the RTCRtpTransceiver transceiver.
if (content->rejected && !transceiver->stopped()) { if (content->rejected && !transceiver->stopped()) {
RTC_LOG(LS_INFO) << "Stopping transceiver for MID=" << content->name RTC_LOG(LS_INFO) << "Stopping transceiver for MID=" << content->mid()
<< " since the media section was rejected."; << " since the media section was rejected.";
transceiver->StopTransceiverProcedure(); transceiver->StopTransceiverProcedure();
} }
@ -3535,7 +3535,7 @@ bool SdpOfferAnswerHandler::CheckIfNegotiationIsNeeded() {
const cricket::ContentInfo* remote_data_content = const cricket::ContentInfo* remote_data_content =
current_remote_description() current_remote_description()
? current_remote_description()->description()->GetContentByName( ? current_remote_description()->description()->GetContentByName(
data_content->name) data_content->mid())
: nullptr; : nullptr;
if (remote_data_content && remote_data_content->rejected) { if (remote_data_content && remote_data_content->rejected) {
return true; return true;
@ -3839,8 +3839,8 @@ RTCError SdpOfferAnswerHandler::UpdateTransceiversAndDataChannels(
for (size_t i = 0; i < new_contents.size(); ++i) { for (size_t i = 0; i < new_contents.size(); ++i) {
const cricket::ContentInfo& new_content = new_contents[i]; const cricket::ContentInfo& new_content = new_contents[i];
cricket::MediaType media_type = new_content.media_description()->type(); cricket::MediaType media_type = new_content.media_description()->type();
mid_generator_.AddKnownId(new_content.name); mid_generator_.AddKnownId(new_content.mid());
auto it = bundle_groups_by_mid.find(new_content.name); auto it = bundle_groups_by_mid.find(new_content.mid());
const cricket::ContentGroup* bundle_group = const cricket::ContentGroup* bundle_group =
it != bundle_groups_by_mid.end() ? it->second : nullptr; it != bundle_groups_by_mid.end() ? it->second : nullptr;
if (media_type == cricket::MEDIA_TYPE_AUDIO || if (media_type == cricket::MEDIA_TYPE_AUDIO ||
@ -3907,10 +3907,10 @@ RTCError SdpOfferAnswerHandler::UpdateTransceiversAndDataChannels(
} }
} else if (media_type == cricket::MEDIA_TYPE_DATA) { } else if (media_type == cricket::MEDIA_TYPE_DATA) {
const auto data_mid = pc_->sctp_mid(); const auto data_mid = pc_->sctp_mid();
if (data_mid && new_content.name != data_mid.value()) { if (data_mid && new_content.mid() != data_mid.value()) {
// Ignore all but the first data section. // Ignore all but the first data section.
RTC_LOG(LS_INFO) << "Ignoring data media section with MID=" RTC_LOG(LS_INFO) << "Ignoring data media section with MID="
<< new_content.name; << new_content.mid();
continue; continue;
} }
RTCError error = RTCError error =
@ -3946,10 +3946,9 @@ SdpOfferAnswerHandler::AssociateTransceiver(
// should have been removed by RemoveStoppedtransceivers()-> // should have been removed by RemoveStoppedtransceivers()->
if (IsMediaSectionBeingRecycled(type, content, old_local_content, if (IsMediaSectionBeingRecycled(type, content, old_local_content,
old_remote_content)) { old_remote_content)) {
const std::string& old_mid = const auto old_mid = (old_local_content && old_local_content->rejected)
(old_local_content && old_local_content->rejected) ? old_local_content->mid()
? old_local_content->name : old_remote_content->mid();
: old_remote_content->name;
auto old_transceiver = transceivers()->FindByMid(old_mid); auto old_transceiver = transceivers()->FindByMid(old_mid);
// The transceiver should be disassociated in RemoveStoppedTransceivers() // The transceiver should be disassociated in RemoveStoppedTransceivers()
RTC_DCHECK(!old_transceiver); RTC_DCHECK(!old_transceiver);
@ -3957,7 +3956,7 @@ SdpOfferAnswerHandler::AssociateTransceiver(
#endif #endif
const MediaContentDescription* media_desc = content.media_description(); const MediaContentDescription* media_desc = content.media_description();
auto transceiver = transceivers()->FindByMid(content.name); auto transceiver = transceivers()->FindByMid(content.mid());
if (source == cricket::CS_LOCAL) { if (source == cricket::CS_LOCAL) {
// Find the RtpTransceiver that corresponds to this m= section, using the // Find the RtpTransceiver that corresponds to this m= section, using the
// mapping between transceivers and m= section indices established when // mapping between transceivers and m= section indices established when
@ -3986,7 +3985,7 @@ SdpOfferAnswerHandler::AssociateTransceiver(
if (!transceiver) { if (!transceiver) {
RTC_LOG(LS_INFO) << "Adding " RTC_LOG(LS_INFO) << "Adding "
<< cricket::MediaTypeToString(media_desc->type()) << cricket::MediaTypeToString(media_desc->type())
<< " transceiver for MID=" << content.name << " transceiver for MID=" << content.mid()
<< " at i=" << mline_index << " at i=" << mline_index
<< " in response to the remote description."; << " in response to the remote description.";
std::string sender_id = rtc::CreateRandomUuid(); std::string sender_id = rtc::CreateRandomUuid();
@ -4047,7 +4046,7 @@ SdpOfferAnswerHandler::AssociateTransceiver(
} }
} }
if (type == SdpType::kOffer) { if (type == SdpType::kOffer) {
bool state_changes = transceiver->internal()->mid() != content.name || bool state_changes = transceiver->internal()->mid() != content.mid() ||
transceiver->internal()->mline_index() != mline_index; transceiver->internal()->mline_index() != mline_index;
if (state_changes) { if (state_changes) {
transceivers() transceivers()
@ -4060,7 +4059,7 @@ SdpOfferAnswerHandler::AssociateTransceiver(
// setting the value of the RtpTransceiver's mid property to the MID of the m= // setting the value of the RtpTransceiver's mid property to the MID of the m=
// section, and establish a mapping between the transceiver and the index of // section, and establish a mapping between the transceiver and the index of
// the m= section. // the m= section.
transceiver->internal()->set_mid(content.name); transceiver->internal()->set_mid(content.mid());
transceiver->internal()->set_mline_index(mline_index); transceiver->internal()->set_mline_index(mline_index);
return std::move(transceiver); return std::move(transceiver);
} }
@ -4081,7 +4080,7 @@ RTCError SdpOfferAnswerHandler::UpdateTransceiverChannel(
} else { } else {
if (!channel) { if (!channel) {
auto error = transceiver->internal()->CreateChannel( auto error = transceiver->internal()->CreateChannel(
content.name, pc_->call_ptr(), pc_->configuration()->media_config, content.mid(), pc_->call_ptr(), pc_->configuration()->media_config,
pc_->SrtpRequired(), pc_->GetCryptoOptions(), audio_options(), pc_->SrtpRequired(), pc_->GetCryptoOptions(), audio_options(),
video_options(), video_bitrate_allocator_factory_.get(), video_options(), video_bitrate_allocator_factory_.get(),
[&](absl::string_view mid) { [&](absl::string_view mid) {
@ -4109,7 +4108,7 @@ RTCError SdpOfferAnswerHandler::UpdateDataChannelTransport(
RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA, sb.Release()); RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA, sb.Release());
error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE); error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE);
pc_->DestroyDataChannelTransport(error); pc_->DestroyDataChannelTransport(error);
} else if (!pc_->CreateDataChannelTransport(content.name)) { } else if (!pc_->CreateDataChannelTransport(content.mid())) {
LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
"Failed to create data channel."); "Failed to create data channel.");
} }
@ -4153,17 +4152,17 @@ void SdpOfferAnswerHandler::FillInMissingRemoteMids(
: no_infos); : no_infos);
for (size_t i = 0; i < new_remote_description->contents().size(); ++i) { for (size_t i = 0; i < new_remote_description->contents().size(); ++i) {
cricket::ContentInfo& content = new_remote_description->contents()[i]; cricket::ContentInfo& content = new_remote_description->contents()[i];
if (!content.name.empty()) { if (!content.mid().empty()) {
continue; continue;
} }
std::string new_mid; std::string new_mid;
absl::string_view source_explanation; absl::string_view source_explanation;
if (IsUnifiedPlan()) { if (IsUnifiedPlan()) {
if (i < local_contents.size()) { if (i < local_contents.size()) {
new_mid = local_contents[i].name; new_mid = local_contents[i].mid();
source_explanation = "from the matching local media section"; source_explanation = "from the matching local media section";
} else if (i < remote_contents.size()) { } else if (i < remote_contents.size()) {
new_mid = remote_contents[i].name; new_mid = remote_contents[i].mid();
source_explanation = "from the matching previous remote media section"; source_explanation = "from the matching previous remote media section";
} else { } else {
new_mid = mid_generator_.GenerateString(); new_mid = mid_generator_.GenerateString();
@ -4175,7 +4174,7 @@ void SdpOfferAnswerHandler::FillInMissingRemoteMids(
source_explanation = "to match pre-existing behavior"; source_explanation = "to match pre-existing behavior";
} }
RTC_DCHECK(!new_mid.empty()); RTC_DCHECK(!new_mid.empty());
content.name = new_mid; content.set_mid(new_mid);
new_remote_description->transport_infos()[i].content_name = new_mid; new_remote_description->transport_infos()[i].content_name = new_mid;
RTC_LOG(LS_INFO) << "SetRemoteDescription: Remote media section at i=" << i RTC_LOG(LS_INFO) << "SetRemoteDescription: Remote media section at i=" << i
<< " is missing an a=mid line. Filling in the value '" << " is missing an a=mid line. Filling in the value '"
@ -4388,7 +4387,7 @@ void SdpOfferAnswerHandler::GetOptionsForUnifiedPlanOffer(
(current_local_content && current_local_content->rejected) || (current_local_content && current_local_content->rejected) ||
(current_remote_content && current_remote_content->rejected); (current_remote_content && current_remote_content->rejected);
const std::string& mid = const std::string& mid =
(local_content ? local_content->name : remote_content->name); (local_content ? local_content->mid() : remote_content->mid());
cricket::MediaType media_type = cricket::MediaType media_type =
(local_content ? local_content->media_description()->type() (local_content ? local_content->media_description()->type()
: remote_content->media_description()->type()); : remote_content->media_description()->type());
@ -4605,24 +4604,24 @@ void SdpOfferAnswerHandler::GetOptionsForUnifiedPlanAnswer(
cricket::MediaType media_type = content.media_description()->type(); cricket::MediaType media_type = content.media_description()->type();
if (media_type == cricket::MEDIA_TYPE_AUDIO || if (media_type == cricket::MEDIA_TYPE_AUDIO ||
media_type == cricket::MEDIA_TYPE_VIDEO) { media_type == cricket::MEDIA_TYPE_VIDEO) {
auto transceiver = transceivers()->FindByMid(content.name); auto transceiver = transceivers()->FindByMid(content.mid());
if (transceiver) { if (transceiver) {
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
GetMediaDescriptionOptionsForTransceiver( GetMediaDescriptionOptionsForTransceiver(
transceiver->internal(), content.name, transceiver->internal(), content.mid(),
/*is_create_offer=*/false)); /*is_create_offer=*/false));
} else { } else {
// This should only happen with rejected transceivers. // This should only happen with rejected transceivers.
RTC_DCHECK(content.rejected); RTC_DCHECK(content.rejected);
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
cricket::MediaDescriptionOptions(media_type, content.name, cricket::MediaDescriptionOptions(media_type, content.mid(),
RtpTransceiverDirection::kInactive, RtpTransceiverDirection::kInactive,
/*stopped=*/true)); /*stopped=*/true));
} }
} else if (media_type == cricket::MEDIA_TYPE_UNSUPPORTED) { } else if (media_type == cricket::MEDIA_TYPE_UNSUPPORTED) {
RTC_DCHECK(content.rejected); RTC_DCHECK(content.rejected);
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
cricket::MediaDescriptionOptions(media_type, content.name, cricket::MediaDescriptionOptions(media_type, content.mid(),
RtpTransceiverDirection::kInactive, RtpTransceiverDirection::kInactive,
/*stopped=*/true)); /*stopped=*/true));
} else { } else {
@ -4630,12 +4629,14 @@ void SdpOfferAnswerHandler::GetOptionsForUnifiedPlanAnswer(
// Reject all data sections if data channels are disabled. // Reject all data sections if data channels are disabled.
// Reject a data section if it has already been rejected. // Reject a data section if it has already been rejected.
// Reject all data sections except for the first one. // Reject all data sections except for the first one.
if (content.rejected || content.name != *(pc_->sctp_mid())) { auto sctp_mid = pc_->sctp_mid();
if (content.rejected ||
(sctp_mid.has_value() && content.mid() != *sctp_mid)) {
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
GetMediaDescriptionOptionsForRejectedData(content.name)); GetMediaDescriptionOptionsForRejectedData(content.mid()));
} else { } else {
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
GetMediaDescriptionOptionsForActiveData(content.name)); GetMediaDescriptionOptionsForActiveData(content.mid()));
} }
} }
} }
@ -5152,7 +5153,7 @@ void SdpOfferAnswerHandler::RemoveUnusedChannels(
pc_->DestroyDataChannelTransport(error); pc_->DestroyDataChannelTransport(error);
} else if (data_info->rejected) { } else if (data_info->rejected) {
rtc::StringBuilder sb; rtc::StringBuilder sb;
sb << "Rejected data channel with mid=" << data_info->name << "."; sb << "Rejected data channel with mid=" << data_info->mid() << ".";
RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA, sb.Release()); RTCError error(RTCErrorType::OPERATION_ERROR_WITH_DATA, sb.Release());
error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE); error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE);
@ -5225,7 +5226,7 @@ bool SdpOfferAnswerHandler::UseCandidate(
return true; return true;
} }
pc_->AddRemoteCandidate(result.value()->name, c); pc_->AddRemoteCandidate(result.value()->mid(), c);
return true; return true;
} }
@ -5308,7 +5309,7 @@ RTCError SdpOfferAnswerHandler::CreateChannels(const SessionDescription& desc) {
!rtp_manager()->GetAudioTransceiver()->internal()->channel()) { !rtp_manager()->GetAudioTransceiver()->internal()->channel()) {
auto error = auto error =
rtp_manager()->GetAudioTransceiver()->internal()->CreateChannel( rtp_manager()->GetAudioTransceiver()->internal()->CreateChannel(
voice->name, pc_->call_ptr(), pc_->configuration()->media_config, voice->mid(), pc_->call_ptr(), pc_->configuration()->media_config,
pc_->SrtpRequired(), pc_->GetCryptoOptions(), audio_options(), pc_->SrtpRequired(), pc_->GetCryptoOptions(), audio_options(),
video_options(), video_bitrate_allocator_factory_.get(), video_options(), video_bitrate_allocator_factory_.get(),
[&](absl::string_view mid) { [&](absl::string_view mid) {
@ -5325,7 +5326,7 @@ RTCError SdpOfferAnswerHandler::CreateChannels(const SessionDescription& desc) {
!rtp_manager()->GetVideoTransceiver()->internal()->channel()) { !rtp_manager()->GetVideoTransceiver()->internal()->channel()) {
auto error = auto error =
rtp_manager()->GetVideoTransceiver()->internal()->CreateChannel( rtp_manager()->GetVideoTransceiver()->internal()->CreateChannel(
video->name, pc_->call_ptr(), pc_->configuration()->media_config, video->mid(), pc_->call_ptr(), pc_->configuration()->media_config,
pc_->SrtpRequired(), pc_->GetCryptoOptions(), pc_->SrtpRequired(), pc_->GetCryptoOptions(),
audio_options(), video_options(), audio_options(), video_options(),
@ -5339,7 +5340,8 @@ RTCError SdpOfferAnswerHandler::CreateChannels(const SessionDescription& desc) {
} }
const cricket::ContentInfo* data = cricket::GetFirstDataContent(&desc); const cricket::ContentInfo* data = cricket::GetFirstDataContent(&desc);
if (data && !data->rejected && !pc_->CreateDataChannelTransport(data->name)) { if (data && !data->rejected &&
!pc_->CreateDataChannelTransport(data->mid())) {
LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
"Failed to create data channel."); "Failed to create data channel.");
} }
@ -5388,13 +5390,13 @@ void SdpOfferAnswerHandler::GenerateMediaDescriptionOptions(
if (*audio_index) { if (*audio_index) {
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
cricket::MediaDescriptionOptions( cricket::MediaDescriptionOptions(
cricket::MEDIA_TYPE_AUDIO, content.name, cricket::MEDIA_TYPE_AUDIO, content.mid(),
RtpTransceiverDirection::kInactive, /*stopped=*/true)); RtpTransceiverDirection::kInactive, /*stopped=*/true));
} else { } else {
bool stopped = (audio_direction == RtpTransceiverDirection::kInactive); bool stopped = (audio_direction == RtpTransceiverDirection::kInactive);
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
cricket::MediaDescriptionOptions(cricket::MEDIA_TYPE_AUDIO, cricket::MediaDescriptionOptions(cricket::MEDIA_TYPE_AUDIO,
content.name, audio_direction, content.mid(), audio_direction,
stopped)); stopped));
*audio_index = session_options->media_description_options.size() - 1; *audio_index = session_options->media_description_options.size() - 1;
} }
@ -5405,13 +5407,13 @@ void SdpOfferAnswerHandler::GenerateMediaDescriptionOptions(
if (*video_index) { if (*video_index) {
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
cricket::MediaDescriptionOptions( cricket::MediaDescriptionOptions(
cricket::MEDIA_TYPE_VIDEO, content.name, cricket::MEDIA_TYPE_VIDEO, content.mid(),
RtpTransceiverDirection::kInactive, /*stopped=*/true)); RtpTransceiverDirection::kInactive, /*stopped=*/true));
} else { } else {
bool stopped = (video_direction == RtpTransceiverDirection::kInactive); bool stopped = (video_direction == RtpTransceiverDirection::kInactive);
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
cricket::MediaDescriptionOptions(cricket::MEDIA_TYPE_VIDEO, cricket::MediaDescriptionOptions(cricket::MEDIA_TYPE_VIDEO,
content.name, video_direction, content.mid(), video_direction,
stopped)); stopped));
*video_index = session_options->media_description_options.size() - 1; *video_index = session_options->media_description_options.size() - 1;
} }
@ -5420,7 +5422,7 @@ void SdpOfferAnswerHandler::GenerateMediaDescriptionOptions(
} else if (IsUnsupportedContent(&content)) { } else if (IsUnsupportedContent(&content)) {
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
cricket::MediaDescriptionOptions(cricket::MEDIA_TYPE_UNSUPPORTED, cricket::MediaDescriptionOptions(cricket::MEDIA_TYPE_UNSUPPORTED,
content.name, content.mid(),
RtpTransceiverDirection::kInactive, RtpTransceiverDirection::kInactive,
/*stopped=*/true)); /*stopped=*/true));
} else { } else {
@ -5428,10 +5430,10 @@ void SdpOfferAnswerHandler::GenerateMediaDescriptionOptions(
// If we already have an data m= section, reject this extra one. // If we already have an data m= section, reject this extra one.
if (*data_index) { if (*data_index) {
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
GetMediaDescriptionOptionsForRejectedData(content.name)); GetMediaDescriptionOptionsForRejectedData(content.mid()));
} else { } else {
session_options->media_description_options.push_back( session_options->media_description_options.push_back(
GetMediaDescriptionOptionsForActiveData(content.name)); GetMediaDescriptionOptionsForActiveData(content.mid()));
*data_index = session_options->media_description_options.size() - 1; *data_index = session_options->media_description_options.size() - 1;
} }
} }
@ -5489,7 +5491,7 @@ bool SdpOfferAnswerHandler::UpdatePayloadTypeDemuxingState(
bool mid_header_extension_missing_audio = false; bool mid_header_extension_missing_audio = false;
bool mid_header_extension_missing_video = false; bool mid_header_extension_missing_video = false;
for (auto& content_info : sdesc->description()->contents()) { for (auto& content_info : sdesc->description()->contents()) {
auto it = bundle_groups_by_mid.find(content_info.name); auto it = bundle_groups_by_mid.find(content_info.mid());
const cricket::ContentGroup* bundle_group = const cricket::ContentGroup* bundle_group =
it != bundle_groups_by_mid.end() ? it->second : nullptr; it != bundle_groups_by_mid.end() ? it->second : nullptr;
// If this m= section isn't bundled, it's safe to demux by payload type // If this m= section isn't bundled, it's safe to demux by payload type

View File

@ -149,9 +149,7 @@ void SessionDescription::AddContent(
const std::string& name, const std::string& name,
MediaProtocolType type, MediaProtocolType type,
std::unique_ptr<MediaContentDescription> description) { std::unique_ptr<MediaContentDescription> description) {
ContentInfo content(type, std::move(description)); AddContent(ContentInfo(type, name, std::move(description)));
content.name = name;
AddContent(std::move(content));
} }
void SessionDescription::AddContent( void SessionDescription::AddContent(
@ -159,10 +157,7 @@ void SessionDescription::AddContent(
MediaProtocolType type, MediaProtocolType type,
bool rejected, bool rejected,
std::unique_ptr<MediaContentDescription> description) { std::unique_ptr<MediaContentDescription> description) {
ContentInfo content(type, std::move(description)); AddContent(ContentInfo(type, name, std::move(description), rejected));
content.name = name;
content.rejected = rejected;
AddContent(std::move(content));
} }
void SessionDescription::AddContent( void SessionDescription::AddContent(
@ -171,11 +166,8 @@ void SessionDescription::AddContent(
bool rejected, bool rejected,
bool bundle_only, bool bundle_only,
std::unique_ptr<MediaContentDescription> description) { std::unique_ptr<MediaContentDescription> description) {
ContentInfo content(type, std::move(description)); AddContent(
content.name = name; ContentInfo(type, name, std::move(description), rejected, bundle_only));
content.rejected = rejected;
content.bundle_only = bundle_only;
AddContent(std::move(content));
} }
void SessionDescription::AddContent(ContentInfo&& content) { void SessionDescription::AddContent(ContentInfo&& content) {
@ -282,10 +274,10 @@ ContentInfo::~ContentInfo() {}
// Copy operator. // Copy operator.
ContentInfo::ContentInfo(const ContentInfo& o) ContentInfo::ContentInfo(const ContentInfo& o)
: name(o.name), : type(o.type),
type(o.type),
rejected(o.rejected), rejected(o.rejected),
bundle_only(o.bundle_only), bundle_only(o.bundle_only),
mid_(o.mid_),
description_(o.description_->Clone()) {} description_(o.description_->Clone()) {}
const MediaContentDescription* ContentInfo::media_description() const { const MediaContentDescription* ContentInfo::media_description() const {

View File

@ -400,8 +400,15 @@ class RTC_EXPORT ContentInfo {
public: public:
explicit ContentInfo(MediaProtocolType type) : type(type) {} explicit ContentInfo(MediaProtocolType type) : type(type) {}
ContentInfo(MediaProtocolType type, ContentInfo(MediaProtocolType type,
std::unique_ptr<MediaContentDescription> description) absl::string_view mid,
: type(type), description_(std::move(description)) {} std::unique_ptr<MediaContentDescription> description,
bool rejected = false,
bool bundle_only = false)
: type(type),
rejected(rejected),
bundle_only(bundle_only),
mid_(mid),
description_(std::move(description)) {}
~ContentInfo(); ~ContentInfo();
// Copy ctor and assignment will clone `description_`. // Copy ctor and assignment will clone `description_`.
@ -412,22 +419,20 @@ class RTC_EXPORT ContentInfo {
ContentInfo(ContentInfo&& o) = default; ContentInfo(ContentInfo&& o) = default;
ContentInfo& operator=(ContentInfo&& o) = default; ContentInfo& operator=(ContentInfo&& o) = default;
// Alias for `name`.
// TODO(tommi): change return type to string_view. // TODO(tommi): change return type to string_view.
const std::string& mid() const { return name; } const std::string& mid() const { return mid_; }
void set_mid(absl::string_view mid) { name = std::string(mid); } void set_mid(absl::string_view mid) { mid_ = std::string(mid); }
// Alias for `description`. // Alias for `description`.
MediaContentDescription* media_description(); MediaContentDescription* media_description();
const MediaContentDescription* media_description() const; const MediaContentDescription* media_description() const;
// TODO(bugs.webrtc.org/8620): Rename this to mid and make private.
std::string name;
MediaProtocolType type; MediaProtocolType type;
bool rejected = false; bool rejected = false;
bool bundle_only = false; bool bundle_only = false;
private: private:
std::string mid_;
friend class SessionDescription; friend class SessionDescription;
std::unique_ptr<MediaContentDescription> description_; std::unique_ptr<MediaContentDescription> description_;
}; };