Use LOG_AND_RETURN_ERROR for returning RTCError
BUG=None
Change-Id: Ia5c27f0ae752810fabb53aea58f8731c6c314519
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/311920
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@microsoft.com>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40469}
diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc
index 407cf9a..2ae2602 100644
--- a/pc/sdp_offer_answer.cc
+++ b/pc/sdp_offer_answer.cc
@@ -314,17 +314,13 @@
}
if (dtls_enabled) {
if (!tinfo->description.identity_fingerprint) {
- RTC_LOG(LS_WARNING)
- << "Session description must have DTLS fingerprint if "
- "DTLS enabled.";
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- kSdpWithoutDtlsFingerprint);
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ kSdpWithoutDtlsFingerprint);
}
} else {
if (media->cryptos().empty()) {
- RTC_LOG(LS_WARNING)
- << "Session description must have SDES when DTLS disabled.";
- return RTCError(RTCErrorType::INVALID_PARAMETER, kSdpWithoutSdesCrypto);
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ kSdpWithoutSdesCrypto);
}
}
}
@@ -397,12 +393,12 @@
payload_to_codec_parameters.find(codec_parameters.payload_type);
if (existing_codec_parameters != payload_to_codec_parameters.end() &&
codec_parameters != existing_codec_parameters->second) {
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "A BUNDLE group contains a codec collision for "
- "payload_type='" +
- rtc::ToString(codec_parameters.payload_type) +
- ". All codecs must share the same type, "
- "encoding name, clock rate and parameters.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ "A BUNDLE group contains a codec collision for "
+ "payload_type='" +
+ rtc::ToString(codec_parameters.payload_type) +
+ ". All codecs must share the same type, "
+ "encoding name, clock rate and parameters.");
}
payload_to_codec_parameters.insert(
std::make_pair(codec_parameters.payload_type, codec_parameters));
@@ -424,9 +420,9 @@
const cricket::MediaContentDescription* media_description =
description.GetContentDescriptionByName(content_name);
if (!media_description) {
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "A BUNDLE group contains a MID='" + content_name +
- "' matching no m= section.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ "A BUNDLE group contains a MID='" + content_name +
+ "' matching no m= section.");
}
if (!media_description->has_codecs()) {
continue;
@@ -463,7 +459,7 @@
if (existing_extension != id_to_extension.end() &&
!(extension.uri == existing_extension->second.uri &&
extension.encrypt == existing_extension->second.encrypt)) {
- return RTCError(
+ LOG_AND_RETURN_ERROR(
RTCErrorType::INVALID_PARAMETER,
"A BUNDLE group contains a codec collision for "
"header extension id=" +
@@ -487,9 +483,9 @@
const cricket::MediaContentDescription* media_description =
description.GetContentDescriptionByName(content_name);
if (!media_description) {
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "A BUNDLE group contains a MID='" + content_name +
- "' matching no m= section.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ "A BUNDLE group contains a MID='" + content_name +
+ "' matching no m= section.");
}
for (const auto& extension : media_description->rtp_header_extensions()) {
auto error =
@@ -518,10 +514,10 @@
return ext.uri == RtpExtension::kRidUri;
});
if (it == extensions.end()) {
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "The media section with MID='" + content.mid() +
- "' negotiates simulcast but does not negotiate "
- "the RID RTP header extension.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ "The media section with MID='" + content.mid() +
+ "' negotiates simulcast but does not negotiate "
+ "the RID RTP header extension.");
}
}
return RTCError::OK();
@@ -3029,10 +3025,11 @@
auto state = signaling_state();
if (state != PeerConnectionInterface::kHaveLocalOffer &&
state != PeerConnectionInterface::kHaveRemoteOffer) {
- return RTCError(RTCErrorType::INVALID_STATE,
- (rtc::StringBuilder("Called in wrong signalingState: ")
- << (PeerConnectionInterface::AsString(signaling_state())))
- .Release());
+ LOG_AND_RETURN_ERROR(
+ RTCErrorType::INVALID_STATE,
+ (rtc::StringBuilder("Called in wrong signalingState: ")
+ << (PeerConnectionInterface::AsString(signaling_state())))
+ .Release());
}
RTC_DCHECK_RUN_ON(signaling_thread());
RTC_DCHECK(IsUnifiedPlan());
@@ -3487,16 +3484,17 @@
RTC_DCHECK_EQ(SessionError::kNone, session_error());
if (!sdesc || !sdesc->description()) {
- return RTCError(RTCErrorType::INVALID_PARAMETER, kInvalidSdp);
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, kInvalidSdp);
}
SdpType type = sdesc->GetType();
if ((source == cricket::CS_LOCAL && !ExpectSetLocalDescription(type)) ||
(source == cricket::CS_REMOTE && !ExpectSetRemoteDescription(type))) {
- return RTCError(RTCErrorType::INVALID_STATE,
- (rtc::StringBuilder("Called in wrong state: ")
- << PeerConnectionInterface::AsString(signaling_state()))
- .Release());
+ LOG_AND_RETURN_ERROR(
+ RTCErrorType::INVALID_STATE,
+ (rtc::StringBuilder("Called in wrong state: ")
+ << PeerConnectionInterface::AsString(signaling_state()))
+ .Release());
}
RTCError error = ValidateMids(*sdesc->description());
@@ -3517,7 +3515,8 @@
// Verify ice-ufrag and ice-pwd.
if (!VerifyIceUfragPwdPresent(sdesc->description(), bundle_groups_by_mid)) {
- return RTCError(RTCErrorType::INVALID_PARAMETER, kSdpWithoutIceUfragPwd);
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ kSdpWithoutIceUfragPwd);
}
// Validate that there are no collisions of bundled payload types.
@@ -3538,7 +3537,8 @@
if (!pc_->ValidateBundleSettings(sdesc->description(),
bundle_groups_by_mid)) {
- return RTCError(RTCErrorType::INVALID_PARAMETER, kBundleWithoutRtcpMux);
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ kBundleWithoutRtcpMux);
}
// TODO(skvlad): When the local rtcp-mux policy is Require, reject any
@@ -3554,7 +3554,8 @@
if (!MediaSectionsHaveSameCount(*offer_desc, *sdesc->description()) ||
!MediaSectionsInSameOrder(*offer_desc, nullptr, *sdesc->description(),
type)) {
- return RTCError(RTCErrorType::INVALID_PARAMETER, kMlineMismatchInAnswer);
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ kMlineMismatchInAnswer);
}
} else {
// The re-offers should respect the order of m= sections in current
@@ -3578,8 +3579,8 @@
if (current_desc &&
!MediaSectionsInSameOrder(*current_desc, secondary_current_desc,
*sdesc->description(), type)) {
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- kMlineMismatchInSubsequentOffer);
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ kMlineMismatchInSubsequentOffer);
}
}
@@ -3594,7 +3595,7 @@
if ((desc.type() == cricket::MEDIA_TYPE_AUDIO ||
desc.type() == cricket::MEDIA_TYPE_VIDEO) &&
desc.streams().size() > 1u) {
- return RTCError(
+ LOG_AND_RETURN_ERROR(
RTCErrorType::INVALID_PARAMETER,
"Media section has more than one track specified with a=ssrc lines "
"which is not supported with Unified Plan.");
@@ -3631,7 +3632,7 @@
if (pc_->configuration()->bundle_policy ==
PeerConnectionInterface::kBundlePolicyMaxBundle &&
bundle_groups_by_mid.empty()) {
- return RTCError(
+ LOG_AND_RETURN_ERROR(
RTCErrorType::INVALID_PARAMETER,
"max-bundle configured but session description has no BUNDLE group");
}
@@ -3721,7 +3722,8 @@
} else if (media_type == cricket::MEDIA_TYPE_UNSUPPORTED) {
RTC_LOG(LS_INFO) << "Ignoring unsupported media type";
} else {
- return RTCError(RTCErrorType::INTERNAL_ERROR, "Unknown section type.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
+ "Unknown section type.");
}
}
@@ -3766,8 +3768,8 @@
}
if (!transceiver) {
// This may happen normally when media sections are rejected.
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "Transceiver not found based on m-line index");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ "Transceiver not found based on m-line index");
}
} else {
RTC_DCHECK_EQ(source, cricket::CS_REMOTE);
@@ -3826,8 +3828,9 @@
}
if (transceiver->media_type() != media_desc->type()) {
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "Transceiver type does not match media description type.");
+ LOG_AND_RETURN_ERROR(
+ RTCErrorType::INVALID_PARAMETER,
+ "Transceiver type does not match media description type.");
}
if (media_desc->HasSimulcast()) {
@@ -3908,8 +3911,8 @@
error.set_error_detail(RTCErrorDetailType::DATA_CHANNEL_FAILURE);
DestroyDataChannelTransport(error);
} else if (!CreateDataChannel(content.name)) {
- return RTCError(RTCErrorType::INTERNAL_ERROR,
- "Failed to create data channel.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
+ "Failed to create data channel.");
}
return RTCError::OK();
}
@@ -4760,8 +4763,8 @@
// Note that this is never expected to fail, since RtpDemuxer doesn't
// return an error when changing payload type demux criteria, which is all
// this does.
- return RTCError(RTCErrorType::INTERNAL_ERROR,
- "Failed to update payload type demuxing state.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
+ "Failed to update payload type demuxing state.");
}
// Push down the new SDP media section for each audio/video transceiver.
@@ -4804,7 +4807,7 @@
: entry.first->SetRemoteContent(entry.second, type, error);
});
if (!success) {
- return RTCError(RTCErrorType::INVALID_PARAMETER, error);
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, error);
}
}
}
@@ -5041,7 +5044,7 @@
return content_info.mid() == candidate->sdp_mid();
});
if (it == contents.end()) {
- return RTCError(
+ LOG_AND_RETURN_ERROR(
RTCErrorType::INVALID_PARAMETER,
"Mid " + candidate->sdp_mid() +
" specified but no media section with that mid found.");
@@ -5055,16 +5058,16 @@
if (mediacontent_index < content_size) {
return &description->description()->contents()[mediacontent_index];
} else {
- return RTCError(RTCErrorType::INVALID_RANGE,
- "Media line index (" +
- rtc::ToString(candidate->sdp_mline_index()) +
- ") out of range (number of mlines: " +
- rtc::ToString(content_size) + ").");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
+ "Media line index (" +
+ rtc::ToString(candidate->sdp_mline_index()) +
+ ") out of range (number of mlines: " +
+ rtc::ToString(content_size) + ").");
}
}
- return RTCError(RTCErrorType::INVALID_PARAMETER,
- "Neither sdp_mline_index nor sdp_mid specified.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
+ "Neither sdp_mline_index nor sdp_mid specified.");
}
RTCError SdpOfferAnswerHandler::CreateChannels(const SessionDescription& desc) {
@@ -5109,8 +5112,8 @@
const cricket::ContentInfo* data = cricket::GetFirstDataContent(&desc);
if (data && !data->rejected && !CreateDataChannel(data->name)) {
- return RTCError(RTCErrorType::INTERNAL_ERROR,
- "Failed to create data channel.");
+ LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
+ "Failed to create data channel.");
}
return RTCError::OK();