From 2bf1b99c6d80d9ace60c6e4117f4222f6b5acefe Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Tue, 26 Sep 2023 09:04:46 +0200 Subject: [PATCH] Make CreateOffer/CreateAnswer return RTCErrorOr BUG=webrtc:15499 Change-Id: I8b128fcd9a1114ae4625777a27f074a8314ef190 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/320720 Reviewed-by: Florent Castelli Reviewed-by: Harald Alvestrand Commit-Queue: Philipp Hancke Cr-Commit-Position: refs/heads/main@{#40812} --- pc/media_session.cc | 354 +++---- pc/media_session.h | 38 +- pc/media_session_unittest.cc | 963 ++++++++++-------- pc/webrtc_session_description_factory.cc | 42 +- .../sanitizers/lsan_suppressions_webrtc.cc | 4 - 5 files changed, 755 insertions(+), 646 deletions(-) diff --git a/pc/media_session.cc b/pc/media_session.cc index 4f74870a5b..ca4c757ef5 100644 --- a/pc/media_session.cc +++ b/pc/media_session.cc @@ -43,6 +43,8 @@ namespace { using rtc::UniqueRandomIdGenerator; +using webrtc::RTCError; +using webrtc::RTCErrorType; using webrtc::RtpTransceiverDirection; const char kInline[] = "inline:"; @@ -661,7 +663,7 @@ static std::vector GetActiveContents( // crypto (in current_cryptos) and it is enabled (in secure_policy), crypto is // created (according to crypto_suites). The created content is added to the // offer. -static bool CreateContentOffer( +static RTCError CreateContentOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const SecurePolicy& secure_policy, @@ -701,18 +703,20 @@ static bool CreateContentOffer( } if (offer->cryptos().empty()) { if (!CreateMediaCryptos(crypto_suites, offer)) { - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Failed to create crypto parameters"); } } } if (secure_policy == SEC_REQUIRED && offer->cryptos().empty()) { - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Failed to create crypto parameters"); } - return true; + return RTCError::OK(); } -static bool CreateMediaContentOffer( +static RTCError CreateMediaContentOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const std::vector& codecs, @@ -728,7 +732,8 @@ static bool CreateMediaContentOffer( if (!AddStreamParams(media_description_options.sender_options, session_options.rtcp_cname, ssrc_generator, current_streams, offer, field_trials)) { - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Failed to add stream parameters"); } return CreateContentOffer(media_description_options, session_options, @@ -1666,7 +1671,8 @@ MediaSessionDescriptionFactory::filtered_rtp_header_extensions( return extensions; } -std::unique_ptr MediaSessionDescriptionFactory::CreateOffer( +webrtc::RTCErrorOr> +MediaSessionDescriptionFactory::CreateOfferOrError( const MediaSessionOptions& session_options, const SessionDescription* current_description) const { // Must have options for each existing section. @@ -1712,43 +1718,37 @@ std::unique_ptr MediaSessionDescriptionFactory::CreateOffer( IsMediaContentOfType(current_content, media_description_options.type)); } + RTCError error; switch (media_description_options.type) { case MEDIA_TYPE_AUDIO: - if (!AddAudioContentForOffer(media_description_options, session_options, - current_content, current_description, - extensions_with_ids.audio, - offer_audio_codecs, ¤t_streams, - offer.get(), &ice_credentials)) { - return nullptr; - } + error = AddAudioContentForOffer( + media_description_options, session_options, current_content, + current_description, extensions_with_ids.audio, offer_audio_codecs, + ¤t_streams, offer.get(), &ice_credentials); break; case MEDIA_TYPE_VIDEO: - if (!AddVideoContentForOffer(media_description_options, session_options, - current_content, current_description, - extensions_with_ids.video, - offer_video_codecs, ¤t_streams, - offer.get(), &ice_credentials)) { - return nullptr; - } + error = AddVideoContentForOffer( + media_description_options, session_options, current_content, + current_description, extensions_with_ids.video, offer_video_codecs, + ¤t_streams, offer.get(), &ice_credentials); break; case MEDIA_TYPE_DATA: - if (!AddDataContentForOffer(media_description_options, session_options, - current_content, current_description, - ¤t_streams, offer.get(), - &ice_credentials)) { - return nullptr; - } + error = AddDataContentForOffer(media_description_options, + session_options, current_content, + current_description, ¤t_streams, + offer.get(), &ice_credentials); break; case MEDIA_TYPE_UNSUPPORTED: - if (!AddUnsupportedContentForOffer( - media_description_options, session_options, current_content, - current_description, offer.get(), &ice_credentials)) { - return nullptr; - } + error = AddUnsupportedContentForOffer( + media_description_options, session_options, current_content, + current_description, offer.get(), &ice_credentials); break; default: RTC_DCHECK_NOTREACHED(); } + if (!error.ok()) { + return error; + } ++msection_index; } @@ -1770,14 +1770,14 @@ std::unique_ptr MediaSessionDescriptionFactory::CreateOffer( if (!offer_bundle.content_names().empty()) { offer->AddGroup(offer_bundle); if (!UpdateTransportInfoForBundle(offer_bundle, offer.get())) { - RTC_LOG(LS_ERROR) - << "CreateOffer failed to UpdateTransportInfoForBundle."; - return nullptr; + LOG_AND_RETURN_ERROR( + RTCErrorType::INTERNAL_ERROR, + "CreateOffer failed to UpdateTransportInfoForBundle"); } if (!UpdateCryptoParamsForBundle(offer_bundle, offer.get())) { - RTC_LOG(LS_ERROR) - << "CreateOffer failed to UpdateCryptoParamsForBundle."; - return nullptr; + LOG_AND_RETURN_ERROR( + RTCErrorType::INTERNAL_ERROR, + "CreateOffer failed to UpdateCryptoParamsForBundle."); } } } @@ -1800,13 +1800,13 @@ std::unique_ptr MediaSessionDescriptionFactory::CreateOffer( return offer; } -std::unique_ptr -MediaSessionDescriptionFactory::CreateAnswer( +webrtc::RTCErrorOr> +MediaSessionDescriptionFactory::CreateAnswerOrError( const SessionDescription* offer, const MediaSessionOptions& session_options, const SessionDescription* current_description) const { if (!offer) { - return nullptr; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, "Called without offer."); } // Must have options for exactly as many sections as in the offer. @@ -1887,44 +1887,40 @@ MediaSessionDescriptionFactory::CreateAnswer( RtpHeaderExtensions header_extensions = RtpHeaderExtensionsFromCapabilities( UnstoppedRtpHeaderExtensionCapabilities( media_description_options.header_extensions)); + RTCError error; switch (media_description_options.type) { case MEDIA_TYPE_AUDIO: - if (!AddAudioContentForAnswer( - media_description_options, session_options, offer_content, - offer, current_content, current_description, bundle_transport, - answer_audio_codecs, header_extensions, ¤t_streams, - answer.get(), &ice_credentials)) { - return nullptr; - } + error = AddAudioContentForAnswer( + media_description_options, session_options, offer_content, offer, + current_content, current_description, bundle_transport, + answer_audio_codecs, header_extensions, ¤t_streams, + answer.get(), &ice_credentials); break; case MEDIA_TYPE_VIDEO: - if (!AddVideoContentForAnswer( - media_description_options, session_options, offer_content, - offer, current_content, current_description, bundle_transport, - answer_video_codecs, header_extensions, ¤t_streams, - answer.get(), &ice_credentials)) { - return nullptr; - } + error = AddVideoContentForAnswer( + media_description_options, session_options, offer_content, offer, + current_content, current_description, bundle_transport, + answer_video_codecs, header_extensions, ¤t_streams, + answer.get(), &ice_credentials); break; case MEDIA_TYPE_DATA: - if (!AddDataContentForAnswer( - media_description_options, session_options, offer_content, - offer, current_content, current_description, bundle_transport, - ¤t_streams, answer.get(), &ice_credentials)) { - return nullptr; - } + error = AddDataContentForAnswer( + media_description_options, session_options, offer_content, offer, + current_content, current_description, bundle_transport, + ¤t_streams, answer.get(), &ice_credentials); break; case MEDIA_TYPE_UNSUPPORTED: - if (!AddUnsupportedContentForAnswer( - media_description_options, session_options, offer_content, - offer, current_content, current_description, bundle_transport, - answer.get(), &ice_credentials)) { - return nullptr; - } + error = AddUnsupportedContentForAnswer( + media_description_options, session_options, offer_content, offer, + current_content, current_description, bundle_transport, + answer.get(), &ice_credentials); break; default: RTC_DCHECK_NOTREACHED(); } + if (!error.ok()) { + return error; + } ++msection_index; // See if we can add the newly generated m= section to the BUNDLE group in // the answer. @@ -1953,15 +1949,15 @@ MediaSessionDescriptionFactory::CreateAnswer( // Share the same ICE credentials and crypto params across all contents, // as BUNDLE requires. if (!UpdateTransportInfoForBundle(answer_bundle, answer.get())) { - RTC_LOG(LS_ERROR) - << "CreateAnswer failed to UpdateTransportInfoForBundle."; - return NULL; + LOG_AND_RETURN_ERROR( + RTCErrorType::INTERNAL_ERROR, + "CreateAnswer failed to UpdateTransportInfoForBundle."); } if (!UpdateCryptoParamsForBundle(answer_bundle, answer.get())) { - RTC_LOG(LS_ERROR) - << "CreateAnswer failed to UpdateCryptoParamsForBundle."; - return NULL; + LOG_AND_RETURN_ERROR( + RTCErrorType::INTERNAL_ERROR, + "CreateAnswer failed to UpdateCryptoParamsForBundle."); } } } @@ -2249,14 +2245,16 @@ MediaSessionDescriptionFactory::GetOfferedRtpHeaderExtensionsWithIds( return offered_extensions; } -bool MediaSessionDescriptionFactory::AddTransportOffer( +RTCError MediaSessionDescriptionFactory::AddTransportOffer( const std::string& content_name, const TransportOptions& transport_options, const SessionDescription* current_desc, SessionDescription* offer_desc, IceCredentialsIterator* ice_credentials) const { - if (!transport_desc_factory_) - return false; + if (!transport_desc_factory_) { + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Missing transport description factory"); + } const TransportDescription* current_tdesc = GetTransportDescription(content_name, current_desc); std::unique_ptr new_tdesc( @@ -2267,7 +2265,7 @@ bool MediaSessionDescriptionFactory::AddTransportOffer( << content_name; } offer_desc->AddTransportInfo(TransportInfo(content_name, *new_tdesc)); - return true; + return RTCError::OK(); } std::unique_ptr @@ -2278,8 +2276,9 @@ MediaSessionDescriptionFactory::CreateTransportAnswer( const SessionDescription* current_desc, bool require_transport_attributes, IceCredentialsIterator* ice_credentials) const { - if (!transport_desc_factory_) - return NULL; + if (!transport_desc_factory_) { + return nullptr; + } const TransportDescription* offer_tdesc = GetTransportDescription(content_name, offer_desc); const TransportDescription* current_tdesc = @@ -2289,12 +2288,12 @@ MediaSessionDescriptionFactory::CreateTransportAnswer( current_tdesc, ice_credentials); } -bool MediaSessionDescriptionFactory::AddTransportAnswer( +RTCError MediaSessionDescriptionFactory::AddTransportAnswer( const std::string& content_name, const TransportDescription& transport_desc, SessionDescription* answer_desc) const { answer_desc->AddTransportInfo(TransportInfo(content_name, transport_desc)); - return true; + return RTCError::OK(); } // `audio_codecs` = set of all possible codecs that can be used, with correct @@ -2309,7 +2308,7 @@ bool MediaSessionDescriptionFactory::AddTransportAnswer( // from acd->codecs() and then supported_codecs, to ensure that re-offers don't // change existing codec priority, and that new codecs are added with the right // priority. -bool MediaSessionDescriptionFactory::AddAudioContentForOffer( +RTCError MediaSessionDescriptionFactory::AddAudioContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* current_content, @@ -2342,10 +2341,10 @@ bool MediaSessionDescriptionFactory::AddAudioContentForOffer( if (!IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO)) { // TODO(bugs.webrtc.org/15471): add a unit test for this since // it is not clear how this can happen for offers. - RTC_LOG(LS_ERROR) << "Media type for content with mid='" - << current_content->name - << "' does not match previous type."; - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Media type for content with mid='" + + current_content->name + + "' does not match previous type."); } const AudioContentDescription* acd = current_content->media_description()->as_audio(); @@ -2383,12 +2382,13 @@ bool MediaSessionDescriptionFactory::AddAudioContentForOffer( std::vector crypto_suites; GetSupportedAudioSdesCryptoSuiteNames(session_options.crypto_options, &crypto_suites); - if (!CreateMediaContentOffer( - media_description_options, session_options, filtered_codecs, - sdes_policy, GetCryptos(current_content), crypto_suites, - audio_rtp_extensions, ssrc_generator(), current_streams, audio.get(), - transport_desc_factory_->trials())) { - return false; + auto error = CreateMediaContentOffer( + media_description_options, session_options, filtered_codecs, sdes_policy, + GetCryptos(current_content), crypto_suites, audio_rtp_extensions, + ssrc_generator(), current_streams, audio.get(), + transport_desc_factory_->trials()); + if (!error.ok()) { + return error; } bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); @@ -2398,18 +2398,19 @@ bool MediaSessionDescriptionFactory::AddAudioContentForOffer( desc->AddContent(media_description_options.mid, MediaProtocolType::kRtp, media_description_options.stopped, std::move(audio)); - if (!AddTransportOffer(media_description_options.mid, - media_description_options.transport_options, - current_description, desc, ice_credentials)) { - return false; + error = AddTransportOffer(media_description_options.mid, + media_description_options.transport_options, + current_description, desc, ice_credentials); + if (!error.ok()) { + return error; } - return true; + return RTCError::OK(); } // TODO(kron): This function is very similar to AddAudioContentForOffer. // Refactor to reuse shared code. -bool MediaSessionDescriptionFactory::AddVideoContentForOffer( +RTCError MediaSessionDescriptionFactory::AddVideoContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* current_content, @@ -2442,10 +2443,10 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( if (!IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO)) { // TODO(bugs.webrtc.org/15471): add a unit test for this since // it is not clear how this can happen for offers. - RTC_LOG(LS_ERROR) << "Media type for content with mid='" - << current_content->name - << "' does not match previous type."; - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Media type for content with mid='" + + current_content->name + + "' does not match previous type."); } const VideoContentDescription* vcd = @@ -2503,12 +2504,13 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( std::vector crypto_suites; GetSupportedVideoSdesCryptoSuiteNames(session_options.crypto_options, &crypto_suites); - if (!CreateMediaContentOffer( - media_description_options, session_options, filtered_codecs, - sdes_policy, GetCryptos(current_content), crypto_suites, - video_rtp_extensions, ssrc_generator(), current_streams, video.get(), - transport_desc_factory_->trials())) { - return false; + auto error = CreateMediaContentOffer( + media_description_options, session_options, filtered_codecs, sdes_policy, + GetCryptos(current_content), crypto_suites, video_rtp_extensions, + ssrc_generator(), current_streams, video.get(), + transport_desc_factory_->trials()); + if (!error.ok()) { + return error; } video->set_bandwidth(kAutoBandwidth); @@ -2520,16 +2522,12 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( desc->AddContent(media_description_options.mid, MediaProtocolType::kRtp, media_description_options.stopped, std::move(video)); - if (!AddTransportOffer(media_description_options.mid, - media_description_options.transport_options, - current_description, desc, ice_credentials)) { - return false; - } - - return true; + return AddTransportOffer(media_description_options.mid, + media_description_options.transport_options, + current_description, desc, ice_credentials); } -bool MediaSessionDescriptionFactory::AddDataContentForOffer( +RTCError MediaSessionDescriptionFactory::AddDataContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* current_content, @@ -2557,24 +2555,22 @@ bool MediaSessionDescriptionFactory::AddDataContentForOffer( data->set_use_sctpmap(session_options.use_obsolete_sctp_sdp); data->set_max_message_size(kSctpSendBufferSize); - if (!CreateContentOffer(media_description_options, session_options, - sdes_policy, GetCryptos(current_content), - crypto_suites, RtpHeaderExtensions(), - ssrc_generator(), current_streams, data.get())) { - return false; + auto error = CreateContentOffer( + media_description_options, session_options, sdes_policy, + GetCryptos(current_content), crypto_suites, RtpHeaderExtensions(), + ssrc_generator(), current_streams, data.get()); + if (!error.ok()) { + return error; } desc->AddContent(media_description_options.mid, MediaProtocolType::kSctp, media_description_options.stopped, std::move(data)); - if (!AddTransportOffer(media_description_options.mid, - media_description_options.transport_options, - current_description, desc, ice_credentials)) { - return false; - } - return true; + return AddTransportOffer(media_description_options.mid, + media_description_options.transport_options, + current_description, desc, ice_credentials); } -bool MediaSessionDescriptionFactory::AddUnsupportedContentForOffer( +RTCError MediaSessionDescriptionFactory::AddUnsupportedContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* current_content, @@ -2591,12 +2587,9 @@ bool MediaSessionDescriptionFactory::AddUnsupportedContentForOffer( desc->AddContent(media_description_options.mid, MediaProtocolType::kOther, /*rejected=*/true, std::move(unsupported)); - if (!AddTransportOffer(media_description_options.mid, - media_description_options.transport_options, - current_description, desc, ice_credentials)) { - return false; - } - return true; + return AddTransportOffer(media_description_options.mid, + media_description_options.transport_options, + current_description, desc, ice_credentials); } // `audio_codecs` = set of all possible codecs that can be used, with correct @@ -2611,7 +2604,7 @@ bool MediaSessionDescriptionFactory::AddUnsupportedContentForOffer( // from acd->codecs() and then supported_codecs, to ensure that re-offers don't // change existing codec priority, and that new codecs are added with the right // priority. -bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( +RTCError MediaSessionDescriptionFactory::AddAudioContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* offer_content, @@ -2635,7 +2628,9 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( media_description_options.transport_options, current_description, bundle_transport != nullptr, ice_credentials); if (!audio_transport) { - return false; + LOG_AND_RETURN_ERROR( + RTCErrorType::INTERNAL_ERROR, + "Failed to create transport answer, audio transport is missing"); } // Pick codecs based on the requested communications direction in the offer @@ -2660,10 +2655,10 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( current_content->name == media_description_options.mid) { if (!IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO)) { // Can happen if the remote side re-uses a MID while recycling. - RTC_LOG(LS_ERROR) << "Media type for content with mid='" - << current_content->name - << "' does not match previous type."; - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Media type for content with mid='" + + current_content->name + + "' does not match previous type."); } const AudioContentDescription* acd = current_content->media_description()->as_audio(); @@ -2708,7 +2703,8 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( media_description_options, session_options, ssrc_generator(), current_streams, audio_answer.get(), transport_desc_factory_->trials())) { - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Failed to set codecs in answer"); } if (!CreateMediaContentAnswer( offer_audio_description, media_description_options, session_options, @@ -2716,7 +2712,8 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( filtered_rtp_header_extensions(rtp_header_extensions), ssrc_generator(), enable_encrypted_rtp_header_extensions_, current_streams, bundle_enabled, audio_answer.get())) { - return false; // Fails the session setup. + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Failed to create answer"); } bool secure = bundle_transport ? bundle_transport->description.secure() @@ -2725,9 +2722,10 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( offer_content->rejected || !has_common_media_codecs || !IsMediaProtocolSupported(MEDIA_TYPE_AUDIO, audio_answer->protocol(), secure); - if (!AddTransportAnswer(media_description_options.mid, - *(audio_transport.get()), answer)) { - return false; + auto error = AddTransportAnswer(media_description_options.mid, + *(audio_transport.get()), answer); + if (!error.ok()) { + return error; } if (rejected) { @@ -2737,12 +2735,12 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( answer->AddContent(media_description_options.mid, offer_content->type, rejected, std::move(audio_answer)); - return true; + return RTCError::OK(); } // TODO(kron): This function is very similar to AddAudioContentForAnswer. // Refactor to reuse shared code. -bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( +RTCError MediaSessionDescriptionFactory::AddVideoContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* offer_content, @@ -2766,7 +2764,9 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( media_description_options.transport_options, current_description, bundle_transport != nullptr, ice_credentials); if (!video_transport) { - return false; + LOG_AND_RETURN_ERROR( + RTCErrorType::INTERNAL_ERROR, + "Failed to create transport answer, video transport is missing"); } // Pick codecs based on the requested communications direction in the offer @@ -2791,10 +2791,10 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( current_content->name == media_description_options.mid) { if (!IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO)) { // Can happen if the remote side re-uses a MID while recycling. - RTC_LOG(LS_ERROR) << "Media type for content with mid='" - << current_content->name - << "' does not match previous type."; - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Media type for content with mid='" + + current_content->name + + "' does not match previous type."); } const VideoContentDescription* vcd = current_content->media_description()->as_video(); @@ -2849,7 +2849,8 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( media_description_options, session_options, ssrc_generator(), current_streams, video_answer.get(), transport_desc_factory_->trials())) { - return false; + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Failed to set codecs in answer"); } if (!CreateMediaContentAnswer( offer_video_description, media_description_options, session_options, @@ -2857,7 +2858,8 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( filtered_rtp_header_extensions(default_video_rtp_header_extensions), ssrc_generator(), enable_encrypted_rtp_header_extensions_, current_streams, bundle_enabled, video_answer.get())) { - return false; // Failed the session setup. + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Failed to create answer"); } bool secure = bundle_transport ? bundle_transport->description.secure() : video_transport->secure(); @@ -2865,9 +2867,10 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( offer_content->rejected || !has_common_media_codecs || !IsMediaProtocolSupported(MEDIA_TYPE_VIDEO, video_answer->protocol(), secure); - if (!AddTransportAnswer(media_description_options.mid, - *(video_transport.get()), answer)) { - return false; + auto error = AddTransportAnswer(media_description_options.mid, + *(video_transport.get()), answer); + if (!error.ok()) { + return error; } if (!rejected) { @@ -2878,10 +2881,10 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( } answer->AddContent(media_description_options.mid, offer_content->type, rejected, std::move(video_answer)); - return true; + return RTCError::OK(); } -bool MediaSessionDescriptionFactory::AddDataContentForAnswer( +RTCError MediaSessionDescriptionFactory::AddDataContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* offer_content, @@ -2897,7 +2900,9 @@ bool MediaSessionDescriptionFactory::AddDataContentForAnswer( media_description_options.transport_options, current_description, bundle_transport != nullptr, ice_credentials); if (!data_transport) { - return false; + LOG_AND_RETURN_ERROR( + RTCErrorType::INTERNAL_ERROR, + "Failed to create transport answer, data transport is missing"); } // Do not require or create SDES cryptos if DTLS is used. @@ -2930,7 +2935,8 @@ bool MediaSessionDescriptionFactory::AddDataContentForAnswer( sdes_policy, GetCryptos(current_content), RtpHeaderExtensions(), ssrc_generator(), enable_encrypted_rtp_header_extensions_, current_streams, bundle_enabled, data_answer.get())) { - return false; // Fails the session setup. + LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR, + "Failed to create answer"); } // Respond with sctpmap if the offer uses sctpmap. bool offer_uses_sctpmap = offer_data_description->use_sctpmap(); @@ -2946,17 +2952,17 @@ bool MediaSessionDescriptionFactory::AddDataContentForAnswer( offer_content->rejected || !IsMediaProtocolSupported(MEDIA_TYPE_DATA, data_answer->protocol(), secure); - if (!AddTransportAnswer(media_description_options.mid, - *(data_transport.get()), answer)) { - return false; + auto error = AddTransportAnswer(media_description_options.mid, + *(data_transport.get()), answer); + if (!error.ok()) { + return error; } - answer->AddContent(media_description_options.mid, offer_content->type, rejected, std::move(data_answer)); - return true; + return RTCError::OK(); } -bool MediaSessionDescriptionFactory::AddUnsupportedContentForAnswer( +RTCError MediaSessionDescriptionFactory::AddUnsupportedContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* offer_content, @@ -2972,7 +2978,9 @@ bool MediaSessionDescriptionFactory::AddUnsupportedContentForAnswer( current_description, bundle_transport != nullptr, ice_credentials); if (!unsupported_transport) { - return false; + LOG_AND_RETURN_ERROR( + RTCErrorType::INTERNAL_ERROR, + "Failed to create transport answer, unsupported transport is missing"); } RTC_CHECK(IsMediaContentOfType(offer_content, MEDIA_TYPE_UNSUPPORTED)); @@ -2983,13 +2991,15 @@ bool MediaSessionDescriptionFactory::AddUnsupportedContentForAnswer( offer_unsupported_description->media_type()); unsupported_answer->set_protocol(offer_unsupported_description->protocol()); - if (!AddTransportAnswer(media_description_options.mid, - *(unsupported_transport.get()), answer)) { - return false; + auto error = AddTransportAnswer(media_description_options.mid, + *(unsupported_transport.get()), answer); + if (!error.ok()) { + return error; } + answer->AddContent(media_description_options.mid, offer_content->type, /*rejected=*/true, std::move(unsupported_answer)); - return true; + return RTCError::OK(); } void MediaSessionDescriptionFactory::ComputeAudioCodecsIntersectionAndUnion() { diff --git a/pc/media_session.h b/pc/media_session.h index 87f04c779f..9a3e9bf021 100644 --- a/pc/media_session.h +++ b/pc/media_session.h @@ -177,10 +177,10 @@ class MediaSessionDescriptionFactory { is_unified_plan_ = is_unified_plan; } - std::unique_ptr CreateOffer( + webrtc::RTCErrorOr> CreateOfferOrError( const MediaSessionOptions& options, const SessionDescription* current_description) const; - std::unique_ptr CreateAnswer( + webrtc::RTCErrorOr> CreateAnswerOrError( const SessionDescription* offer, const MediaSessionOptions& options, const SessionDescription* current_description) const; @@ -215,11 +215,12 @@ class MediaSessionDescriptionFactory { bool extmap_allow_mixed, const std::vector& media_description_options) const; - bool AddTransportOffer(const std::string& content_name, - const TransportOptions& transport_options, - const SessionDescription* current_desc, - SessionDescription* offer, - IceCredentialsIterator* ice_credentials) const; + webrtc::RTCError AddTransportOffer( + const std::string& content_name, + const TransportOptions& transport_options, + const SessionDescription* current_desc, + SessionDescription* offer, + IceCredentialsIterator* ice_credentials) const; std::unique_ptr CreateTransportAnswer( const std::string& content_name, @@ -229,15 +230,16 @@ class MediaSessionDescriptionFactory { bool require_transport_attributes, IceCredentialsIterator* ice_credentials) const; - bool AddTransportAnswer(const std::string& content_name, - const TransportDescription& transport_desc, - SessionDescription* answer_desc) const; + webrtc::RTCError AddTransportAnswer( + const std::string& content_name, + const TransportDescription& transport_desc, + SessionDescription* answer_desc) const; // Helpers for adding media contents to the SessionDescription. Returns true // it succeeds or the media content is not needed, or false if there is any // error. - bool AddAudioContentForOffer( + webrtc::RTCError AddAudioContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* current_content, @@ -248,7 +250,7 @@ class MediaSessionDescriptionFactory { SessionDescription* desc, IceCredentialsIterator* ice_credentials) const; - bool AddVideoContentForOffer( + webrtc::RTCError AddVideoContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* current_content, @@ -259,7 +261,7 @@ class MediaSessionDescriptionFactory { SessionDescription* desc, IceCredentialsIterator* ice_credentials) const; - bool AddDataContentForOffer( + webrtc::RTCError AddDataContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* current_content, @@ -268,7 +270,7 @@ class MediaSessionDescriptionFactory { SessionDescription* desc, IceCredentialsIterator* ice_credentials) const; - bool AddUnsupportedContentForOffer( + webrtc::RTCError AddUnsupportedContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* current_content, @@ -276,7 +278,7 @@ class MediaSessionDescriptionFactory { SessionDescription* desc, IceCredentialsIterator* ice_credentials) const; - bool AddAudioContentForAnswer( + webrtc::RTCError AddAudioContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* offer_content, @@ -290,7 +292,7 @@ class MediaSessionDescriptionFactory { SessionDescription* answer, IceCredentialsIterator* ice_credentials) const; - bool AddVideoContentForAnswer( + webrtc::RTCError AddVideoContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* offer_content, @@ -304,7 +306,7 @@ class MediaSessionDescriptionFactory { SessionDescription* answer, IceCredentialsIterator* ice_credentials) const; - bool AddDataContentForAnswer( + webrtc::RTCError AddDataContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* offer_content, @@ -316,7 +318,7 @@ class MediaSessionDescriptionFactory { SessionDescription* answer, IceCredentialsIterator* ice_credentials) const; - bool AddUnsupportedContentForAnswer( + webrtc::RTCError AddUnsupportedContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, const ContentInfo* offer_content, diff --git a/pc/media_session_unittest.cc b/pc/media_session_unittest.cc index a4979b86fe..3f52d5c1cc 100644 --- a/pc/media_session_unittest.cc +++ b/pc/media_session_unittest.cc @@ -523,16 +523,16 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { "data", TransportDescription(current_data_ufrag, current_data_pwd))); } if (offer) { - desc = f1_.CreateOffer(options, current_desc.get()); + desc = f1_.CreateOfferOrError(options, current_desc.get()).MoveValue(); } else { std::unique_ptr offer; - offer = f1_.CreateOffer(options, NULL); - desc = f1_.CreateAnswer(offer.get(), options, current_desc.get()); + offer = f1_.CreateOfferOrError(options, nullptr).MoveValue(); + desc = f1_.CreateAnswerOrError(offer.get(), options, current_desc.get()) + .MoveValue(); } - ASSERT_TRUE(desc.get() != NULL); + ASSERT_TRUE(desc); const TransportInfo* ti_audio = desc->GetTransportInfoByName("audio"); if (options.has_audio()) { - EXPECT_TRUE(ti_audio != NULL); if (has_current_desc) { EXPECT_EQ(current_audio_ufrag, ti_audio->description.ice_ufrag); EXPECT_EQ(current_audio_pwd, ti_audio->description.ice_pwd); @@ -547,12 +547,9 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { EXPECT_EQ( media_desc_options_it->transport_options.enable_ice_renomination, GetIceRenomination(ti_audio)); - } else { - EXPECT_TRUE(ti_audio == NULL); } const TransportInfo* ti_video = desc->GetTransportInfoByName("video"); if (options.has_video()) { - EXPECT_TRUE(ti_video != NULL); auto media_desc_options_it = FindFirstMediaDescriptionByMid("video", options); if (options.bundle_enabled) { @@ -573,12 +570,9 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { EXPECT_EQ( media_desc_options_it->transport_options.enable_ice_renomination, GetIceRenomination(ti_video)); - } else { - EXPECT_TRUE(ti_video == NULL); } const TransportInfo* ti_data = desc->GetTransportInfoByName("data"); if (options.has_data()) { - EXPECT_TRUE(ti_data != NULL); if (options.bundle_enabled) { EXPECT_EQ(ti_audio->description.ice_ufrag, ti_data->description.ice_ufrag); @@ -599,9 +593,6 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { EXPECT_EQ( media_desc_options_it->transport_options.enable_ice_renomination, GetIceRenomination(ti_data)); - - } else { - EXPECT_TRUE(ti_data == NULL); } } @@ -613,13 +604,14 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { std::unique_ptr desc; if (offer) { options.bundle_enabled = false; - ref_desc = f1_.CreateOffer(options, NULL); + ref_desc = f1_.CreateOfferOrError(options, nullptr).MoveValue(); options.bundle_enabled = true; - desc = f1_.CreateOffer(options, ref_desc.get()); + desc = f1_.CreateOfferOrError(options, ref_desc.get()).MoveValue(); } else { options.bundle_enabled = true; - ref_desc = f1_.CreateOffer(options, NULL); - desc = f1_.CreateAnswer(ref_desc.get(), options, NULL); + ref_desc = f1_.CreateOfferOrError(options, nullptr).MoveValue(); + desc = + f1_.CreateAnswerOrError(ref_desc.get(), options, nullptr).MoveValue(); } ASSERT_TRUE(desc); const cricket::MediaContentDescription* audio_media_desc = @@ -659,17 +651,17 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { AddAudioVideoSections(direction_in_offer, &offer_opts); std::unique_ptr offer = - f1_.CreateOffer(offer_opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* ac_offer = offer->GetContentByName("audio"); - ASSERT_TRUE(ac_offer != NULL); + ASSERT_TRUE(ac_offer); ContentInfo* vc_offer = offer->GetContentByName("video"); - ASSERT_TRUE(vc_offer != NULL); + ASSERT_TRUE(vc_offer); MediaSessionOptions answer_opts; AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &answer_opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), answer_opts, NULL); + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); const AudioContentDescription* acd_answer = GetFirstAudioContentDescription(answer.get()); EXPECT_EQ(expected_direction_in_answer, acd_answer->direction()); @@ -704,8 +696,8 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { f1_.set_secure(SEC_ENABLED); f2_.set_secure(SEC_ENABLED); std::unique_ptr offer = - f1_.CreateOffer(offer_opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); if (gcm_offer && gcm_answer) { for (cricket::ContentInfo& content : offer->contents()) { auto cryptos = content.media_description()->cryptos(); @@ -714,11 +706,11 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { } } std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), answer_opts, NULL); + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); EXPECT_EQ(MediaProtocolType::kRtp, ac->type); EXPECT_EQ(MediaProtocolType::kRtp, vc->type); const AudioContentDescription* acd = ac->media_description()->as_audio(); @@ -752,11 +744,12 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); SetAudioVideoRtpHeaderExtensions(offered, offered, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); SetAudioVideoRtpHeaderExtensions(local, local, &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_EQ( expectedAnswer, @@ -812,12 +805,13 @@ class MediaSessionDescriptionFactoryTest : public ::testing::Test { TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { f1_.set_secure(SEC_ENABLED); std::unique_ptr offer = - f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); - ASSERT_TRUE(offer.get() != NULL); + f1_.CreateOfferOrError(CreatePlanBMediaSessionOptions(), nullptr) + .MoveValue(); + ASSERT_TRUE(offer.get()); const ContentInfo* ac = offer->GetContentByName("audio"); const ContentInfo* vc = offer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc == NULL); + ASSERT_TRUE(ac); + EXPECT_FALSE(vc); EXPECT_EQ(MediaProtocolType::kRtp, ac->type); const AudioContentDescription* acd = ac->media_description()->as_audio(); EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); @@ -834,12 +828,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoOffer) { MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); f1_.set_secure(SEC_ENABLED); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); const ContentInfo* ac = offer->GetContentByName("audio"); const ContentInfo* vc = offer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); EXPECT_EQ(MediaProtocolType::kRtp, ac->type); EXPECT_EQ(MediaProtocolType::kRtp, vc->type); const AudioContentDescription* acd = ac->media_description()->as_audio(); @@ -871,13 +866,14 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestBundleOfferWithSameCodecPlType) { MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); opts.bundle_enabled = true; - std::unique_ptr offer = f2_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f2_.CreateOfferOrError(opts, nullptr).MoveValue(); const VideoContentDescription* vcd = GetFirstVideoContentDescription(offer.get()); const AudioContentDescription* acd = GetFirstAudioContentDescription(offer.get()); - ASSERT_TRUE(NULL != vcd); - ASSERT_TRUE(NULL != acd); + ASSERT_TRUE(vcd); + ASSERT_TRUE(acd); EXPECT_NE(vcd->codecs()[0].id, acd->codecs()[0].id); EXPECT_EQ(vcd->codecs()[0].name, offered_video_codec.name); EXPECT_EQ(acd->codecs()[0].name, offered_audio_codec.name); @@ -897,22 +893,23 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kInactive, kStopped, &opts); opts.bundle_enabled = true; - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); MediaSessionOptions updated_opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &updated_opts); updated_opts.bundle_enabled = true; std::unique_ptr updated_offer( - f1_.CreateOffer(updated_opts, answer.get())); + f1_.CreateOfferOrError(updated_opts, answer.get()).MoveValue()); const AudioContentDescription* acd = GetFirstAudioContentDescription(updated_offer.get()); const VideoContentDescription* vcd = GetFirstVideoContentDescription(updated_offer.get()); - EXPECT_TRUE(NULL != vcd); - EXPECT_TRUE(NULL != acd); + EXPECT_TRUE(vcd); + EXPECT_TRUE(acd); ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); EXPECT_EQ(cricket::kMediaProtocolSavpf, acd->protocol()); @@ -926,9 +923,10 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSctpDataOffer) { opts.bundle_enabled = true; AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); f1_.set_secure(SEC_ENABLED); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - EXPECT_TRUE(offer.get() != NULL); - EXPECT_TRUE(offer->GetContentByName("data") != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + EXPECT_TRUE(offer.get()); + EXPECT_TRUE(offer->GetContentByName("data")); auto dcd = GetFirstSctpDataContentDescription(offer.get()); ASSERT_TRUE(dcd); // Since this transport is insecure, the protocol should be "SCTP". @@ -942,9 +940,10 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSecureSctpDataOffer) { AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); f1_.set_secure(SEC_ENABLED); tdf1_.set_secure(SEC_ENABLED); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - EXPECT_TRUE(offer.get() != NULL); - EXPECT_TRUE(offer->GetContentByName("data") != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + EXPECT_TRUE(offer.get()); + EXPECT_TRUE(offer->GetContentByName("data")); auto dcd = GetFirstSctpDataContentDescription(offer.get()); ASSERT_TRUE(dcd); // The protocol should now be "UDP/DTLS/SCTP" @@ -957,16 +956,17 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateImplicitSctpDataOffer) { opts.bundle_enabled = true; AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); f1_.set_secure(SEC_ENABLED); - std::unique_ptr offer1(f1_.CreateOffer(opts, NULL)); - ASSERT_TRUE(offer1.get() != NULL); + std::unique_ptr offer1( + f1_.CreateOfferOrError(opts, nullptr).MoveValue()); + ASSERT_TRUE(offer1.get()); const ContentInfo* data = offer1->GetContentByName("data"); - ASSERT_TRUE(data != NULL); + ASSERT_TRUE(data); ASSERT_EQ(cricket::kMediaProtocolSctp, data->media_description()->protocol()); std::unique_ptr offer2( - f1_.CreateOffer(opts, offer1.get())); + f1_.CreateOfferOrError(opts, offer1.get()).MoveValue()); data = offer2->GetContentByName("data"); - ASSERT_TRUE(data != NULL); + ASSERT_TRUE(data); EXPECT_EQ(cricket::kMediaProtocolSctp, data->media_description()->protocol()); } @@ -978,11 +978,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, ReOfferNoBundleGroupIfAllRejected) { AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); opts.media_description_options[0].stopped = true; std::unique_ptr reoffer = - f1_.CreateOffer(opts, offer.get()); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); EXPECT_FALSE(reoffer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE)); } @@ -996,15 +997,16 @@ TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerNoBundleGroupIfAllRejected) { AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); opts.media_description_options[0].stopped = true; std::unique_ptr reoffer = - f1_.CreateOffer(opts, offer.get()); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); std::unique_ptr reanswer = - f2_.CreateAnswer(reoffer.get(), opts, answer.get()); + f2_.CreateAnswerOrError(reoffer.get(), opts, answer.get()).MoveValue(); EXPECT_FALSE(reanswer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE)); } @@ -1018,7 +1020,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, ReOfferChangeBundleOffererTagged) { AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); // Reject the audio m= section and add a video m= section. opts.media_description_options[0].stopped = true; @@ -1026,7 +1029,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, ReOfferChangeBundleOffererTagged) { RtpTransceiverDirection::kSendRecv, kActive, &opts); std::unique_ptr reoffer = - f1_.CreateOffer(opts, offer.get()); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); const cricket::ContentGroup* bundle_group = reoffer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); @@ -1044,9 +1047,10 @@ TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerChangedBundleOffererTagged) { AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); // Reject the audio m= section and add a video m= section. opts.media_description_options[0].stopped = true; @@ -1054,9 +1058,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, ReAnswerChangedBundleOffererTagged) { RtpTransceiverDirection::kSendRecv, kActive, &opts); std::unique_ptr reoffer = - f1_.CreateOffer(opts, offer.get()); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); std::unique_ptr reanswer = - f2_.CreateAnswer(reoffer.get(), opts, answer.get()); + f2_.CreateAnswerOrError(reoffer.get(), opts, answer.get()).MoveValue(); const cricket::ContentGroup* bundle_group = reanswer->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); @@ -1082,7 +1086,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "4", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer->groups().empty()); // Munge the offer to have two groups. Offers like these cannot be generated @@ -1101,7 +1106,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, // groups. opts.bundle_enabled = true; std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); std::vector answer_groups = answer->GetGroupsByName(cricket::GROUP_TYPE_BUNDLE); @@ -1116,7 +1121,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, // If BUNDLE is disabled, the answer to this offer should reject both BUNDLE // groups. opts.bundle_enabled = false; - answer = f2_.CreateAnswer(offer.get(), opts, nullptr); + answer = f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); answer_groups = answer->GetGroupsByName(cricket::GROUP_TYPE_BUNDLE); // Rejected groups are still listed, but they are empty. @@ -1134,14 +1139,15 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; opts.bundle_enabled = true; AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); // Reject the audio m= section. opts.media_description_options[0].stopped = true; std::unique_ptr reoffer = - f1_.CreateOffer(opts, offer.get()); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); const TransportDescription* offer_tagged = offer->GetTransportDescriptionByName("audio"); @@ -1162,16 +1168,17 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; opts.bundle_enabled = true; AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); // Reject the audio m= section. opts.media_description_options[0].stopped = true; std::unique_ptr reoffer = - f1_.CreateOffer(opts, offer.get()); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); std::unique_ptr reanswer = - f2_.CreateAnswer(reoffer.get(), opts, answer.get()); + f2_.CreateAnswerOrError(reoffer.get(), opts, answer.get()).MoveValue(); const TransportDescription* answer_tagged = answer->GetTransportDescriptionByName("audio"); @@ -1188,12 +1195,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferWithoutLegacyStreams) { MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); const ContentInfo* ac = offer->GetContentByName("audio"); const ContentInfo* vc = offer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); const AudioContentDescription* acd = ac->media_description()->as_audio(); const VideoContentDescription* vcd = vc->media_description()->as_video(); @@ -1210,8 +1218,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSendOnlyOffer) { AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); EXPECT_EQ(2u, offer->contents().size()); EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[0], MEDIA_TYPE_AUDIO)); EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[1], MEDIA_TYPE_VIDEO)); @@ -1228,8 +1237,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { MediaSessionOptions opts; AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer1(f1_.CreateOffer(opts, NULL)); - ASSERT_TRUE(offer1.get() != NULL); + std::unique_ptr offer1( + f1_.CreateOfferOrError(opts, nullptr).MoveValue()); + ASSERT_TRUE(offer1.get()); EXPECT_EQ(1u, offer1->contents().size()); EXPECT_TRUE(IsMediaContentOfType(&offer1->contents()[0], MEDIA_TYPE_DATA)); @@ -1237,8 +1247,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { RtpTransceiverDirection::kRecvOnly, kActive, &opts); std::unique_ptr offer2( - f1_.CreateOffer(opts, offer1.get())); - ASSERT_TRUE(offer2.get() != NULL); + f1_.CreateOfferOrError(opts, offer1.get()).MoveValue()); + ASSERT_TRUE(offer2.get()); EXPECT_EQ(2u, offer2->contents().size()); EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[0], MEDIA_TYPE_DATA)); EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[1], MEDIA_TYPE_VIDEO)); @@ -1247,8 +1257,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { RtpTransceiverDirection::kRecvOnly, kActive, &opts); std::unique_ptr offer3( - f1_.CreateOffer(opts, offer2.get())); - ASSERT_TRUE(offer3.get() != NULL); + f1_.CreateOfferOrError(opts, offer2.get()).MoveValue()); + ASSERT_TRUE(offer3.get()); EXPECT_EQ(3u, offer3->contents().size()); EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[0], MEDIA_TYPE_DATA)); EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[1], MEDIA_TYPE_VIDEO)); @@ -1260,14 +1270,17 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswer) { f1_.set_secure(SEC_ENABLED); f2_.set_secure(SEC_ENABLED); std::unique_ptr offer = - f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); - ASSERT_TRUE(offer.get() != NULL); + f1_.CreateOfferOrError(CreatePlanBMediaSessionOptions(), nullptr) + .MoveValue(); + ASSERT_TRUE(offer.get()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); + f2_.CreateAnswerOrError(offer.get(), CreatePlanBMediaSessionOptions(), + nullptr) + .MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc == NULL); + ASSERT_TRUE(ac); + EXPECT_FALSE(vc); EXPECT_EQ(MediaProtocolType::kRtp, ac->type); const AudioContentDescription* acd = ac->media_description()->as_audio(); EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); @@ -1286,19 +1299,20 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { f2_.set_secure(SEC_ENABLED); MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); opts.crypto_options.srtp.enable_gcm_crypto_suites = true; - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); for (cricket::ContentInfo& content : offer->contents()) { auto cryptos = content.media_description()->cryptos(); PreferGcmCryptoParameters(&cryptos); content.media_description()->set_cryptos(cryptos); } std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc == NULL); + ASSERT_TRUE(ac); + EXPECT_FALSE(vc); EXPECT_EQ(MediaProtocolType::kRtp, ac->type); const AudioContentDescription* acd = ac->media_description()->as_audio(); EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); @@ -1323,11 +1337,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, std::vector f2_codecs = {cricket::CreateAudioCodec(0, "PCMU", 8000, 1)}; f2_.set_audio_codecs(f2_codecs, f2_codecs); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); - ASSERT_TRUE(ac != NULL); + ASSERT_TRUE(ac); EXPECT_TRUE(ac->rejected); } @@ -1337,14 +1352,15 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); f1_.set_secure(SEC_ENABLED); f2_.set_secure(SEC_ENABLED); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); EXPECT_EQ(MediaProtocolType::kRtp, ac->type); EXPECT_EQ(MediaProtocolType::kRtp, vc->type); const AudioContentDescription* acd = ac->media_description()->as_audio(); @@ -1394,11 +1410,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, std::vector f2_codecs = {cricket::CreateVideoCodec(97, "VP8")}; f2_.set_video_codecs(f2_codecs, f2_codecs); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(vc); EXPECT_TRUE(vc->rejected); } @@ -1418,11 +1435,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, cricket::CreateVideoCodec(118, "flexfec-03")}; f2_.set_video_codecs(f2_codecs, f2_codecs); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(vc); EXPECT_TRUE(vc->rejected); } @@ -1431,18 +1449,19 @@ TEST_F(MediaSessionDescriptionFactoryTest, TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerUsesSctpmap) { MediaSessionOptions opts; AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* dc_offer = offer->GetContentByName("data"); - ASSERT_TRUE(dc_offer != NULL); + ASSERT_TRUE(dc_offer); SctpDataContentDescription* dcd_offer = dc_offer->media_description()->as_sctp(); EXPECT_TRUE(dcd_offer->use_sctpmap()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* dc_answer = answer->GetContentByName("data"); - ASSERT_TRUE(dc_answer != NULL); + ASSERT_TRUE(dc_answer); const SctpDataContentDescription* dcd_answer = dc_answer->media_description()->as_sctp(); EXPECT_TRUE(dcd_answer->use_sctpmap()); @@ -1452,18 +1471,19 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerUsesSctpmap) { TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerWithoutSctpmap) { MediaSessionOptions opts; AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* dc_offer = offer->GetContentByName("data"); - ASSERT_TRUE(dc_offer != NULL); + ASSERT_TRUE(dc_offer); SctpDataContentDescription* dcd_offer = dc_offer->media_description()->as_sctp(); dcd_offer->set_use_sctpmap(false); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* dc_answer = answer->GetContentByName("data"); - ASSERT_TRUE(dc_answer != NULL); + ASSERT_TRUE(dc_answer); const SctpDataContentDescription* dcd_answer = dc_answer->media_description()->as_sctp(); EXPECT_FALSE(dcd_answer->use_sctpmap()); @@ -1482,10 +1502,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); - ASSERT_TRUE(offer.get() != nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* dc_offer = offer->GetContentByName("data"); - ASSERT_TRUE(dc_offer != nullptr); + ASSERT_TRUE(dc_offer); SctpDataContentDescription* dcd_offer = dc_offer->media_description()->as_sctp(); ASSERT_TRUE(dcd_offer); @@ -1495,9 +1516,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, for (const std::string& proto : protos) { dcd_offer->set_protocol(proto); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* dc_answer = answer->GetContentByName("data"); - ASSERT_TRUE(dc_answer != nullptr); + ASSERT_TRUE(dc_answer); const SctpDataContentDescription* dcd_answer = dc_answer->media_description()->as_sctp(); EXPECT_FALSE(dc_answer->rejected); @@ -1516,18 +1537,19 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); - ASSERT_TRUE(offer.get() != nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* dc_offer = offer->GetContentByName("data"); - ASSERT_TRUE(dc_offer != nullptr); + ASSERT_TRUE(dc_offer); SctpDataContentDescription* dcd_offer = dc_offer->media_description()->as_sctp(); ASSERT_TRUE(dcd_offer); dcd_offer->set_max_message_size(1234); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* dc_answer = answer->GetContentByName("data"); - ASSERT_TRUE(dc_answer != nullptr); + ASSERT_TRUE(dc_answer); const SctpDataContentDescription* dcd_answer = dc_answer->media_description()->as_sctp(); EXPECT_FALSE(dc_answer->rejected); @@ -1545,18 +1567,19 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); - ASSERT_TRUE(offer.get() != nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* dc_offer = offer->GetContentByName("data"); - ASSERT_TRUE(dc_offer != nullptr); + ASSERT_TRUE(dc_offer); SctpDataContentDescription* dcd_offer = dc_offer->media_description()->as_sctp(); ASSERT_TRUE(dcd_offer); dcd_offer->set_max_message_size(0); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* dc_answer = answer->GetContentByName("data"); - ASSERT_TRUE(dc_answer != nullptr); + ASSERT_TRUE(dc_answer); const SctpDataContentDescription* dcd_answer = dc_answer->media_description()->as_sctp(); EXPECT_FALSE(dc_answer->rejected); @@ -1570,28 +1593,29 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { // Creates a data only offer. AddDataSection(RtpTransceiverDirection::kSendRecv, &opts); - std::unique_ptr offer1(f1_.CreateOffer(opts, NULL)); - ASSERT_TRUE(offer1.get() != NULL); + std::unique_ptr offer1( + f1_.CreateOfferOrError(opts, nullptr).MoveValue()); + ASSERT_TRUE(offer1.get()); // Appends audio to the offer. AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", RtpTransceiverDirection::kRecvOnly, kActive, &opts); std::unique_ptr offer2( - f1_.CreateOffer(opts, offer1.get())); - ASSERT_TRUE(offer2.get() != NULL); + f1_.CreateOfferOrError(opts, offer1.get()).MoveValue()); + ASSERT_TRUE(offer2.get()); // Appends video to the offer. AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", RtpTransceiverDirection::kRecvOnly, kActive, &opts); std::unique_ptr offer3( - f1_.CreateOffer(opts, offer2.get())); - ASSERT_TRUE(offer3.get() != NULL); + f1_.CreateOfferOrError(opts, offer2.get()).MoveValue()); + ASSERT_TRUE(offer3.get()); std::unique_ptr answer = - f2_.CreateAnswer(offer3.get(), opts, NULL); - ASSERT_TRUE(answer.get() != NULL); + f2_.CreateAnswerOrError(offer3.get(), opts, nullptr).MoveValue(); + ASSERT_TRUE(answer.get()); EXPECT_EQ(3u, answer->contents().size()); EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[0], MEDIA_TYPE_DATA)); EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[1], MEDIA_TYPE_AUDIO)); @@ -1637,22 +1661,23 @@ TEST_F(MediaSessionDescriptionFactoryTest, AudioOfferAnswerWithCryptoDisabled) { tdf1_.set_secure(SEC_DISABLED); tdf2_.set_secure(SEC_DISABLED); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); const AudioContentDescription* offer_acd = GetFirstAudioContentDescription(offer.get()); - ASSERT_TRUE(offer_acd != NULL); + ASSERT_TRUE(offer_acd); EXPECT_EQ(cricket::kMediaProtocolAvpf, offer_acd->protocol()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* ac_answer = answer->GetContentByName("audio"); - ASSERT_TRUE(ac_answer != NULL); + ASSERT_TRUE(ac_answer); EXPECT_FALSE(ac_answer->rejected); const AudioContentDescription* answer_acd = GetFirstAudioContentDescription(answer.get()); - ASSERT_TRUE(answer_acd != NULL); + ASSERT_TRUE(answer_acd); EXPECT_EQ(cricket::kMediaProtocolAvpf, answer_acd->protocol()); } @@ -1664,12 +1689,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestOfferAnswerWithRtpExtensions) { SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), MAKE_VECTOR(kVideoRtpExtension1), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), MAKE_VECTOR(kVideoRtpExtension2), &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_EQ( MAKE_VECTOR(kAudioRtpExtension1), @@ -1719,12 +1745,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, SetAudioVideoRtpHeaderExtensions( MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00), MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); SetAudioVideoRtpHeaderExtensions( MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), MAKE_VECTOR(kRtpExtensionTransportSequenceNumber01), &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), ElementsAreArray(kRtpExtensionGenericFrameDescriptorUri00)); @@ -1741,9 +1768,10 @@ TEST_F(MediaSessionDescriptionFactoryTest, SetAudioVideoRtpHeaderExtensions( MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00), MAKE_VECTOR(kRtpExtensionGenericFrameDescriptorUri00), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetFirstAudioContentDescription(answer.get())->rtp_header_extensions(), ElementsAreArray(kRtpExtensionGenericFrameDescriptorUri00)); @@ -1759,11 +1787,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtension offer_dd(RtpExtension::kDependencyDescriptorUri, 7); SetAudioVideoRtpHeaderExtensions({}, {offer_dd}, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); RtpExtension local_tsn(RtpExtension::kTransportSequenceNumberUri, 5); SetAudioVideoRtpHeaderExtensions({}, {local_tsn}, &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), ElementsAre(offer_dd)); @@ -1777,10 +1806,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtension offer_dd(RtpExtension::kDependencyDescriptorUri, 7); RtpExtension local_dd(RtpExtension::kDependencyDescriptorUri, 5); SetAudioVideoRtpHeaderExtensions({}, {offer_dd}, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); SetAudioVideoRtpHeaderExtensions({}, {local_dd}, &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), ElementsAre(offer_dd)); @@ -1797,10 +1827,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtension(RtpExtension::kTransportSequenceNumberUri, 5)}; SetAudioVideoRtpHeaderExtensions(offered_extensions, offered_extensions, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); SetAudioVideoRtpHeaderExtensions(local_extensions, local_extensions, &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), ElementsAreArray(offered_extensions)); @@ -1820,10 +1851,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 5)}; SetAudioVideoRtpHeaderExtensions(offered_extensions, offered_extensions, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); SetAudioVideoRtpHeaderExtensions(local_extensions, local_extensions, &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), ElementsAreArray(offered_extensions)); @@ -1843,10 +1875,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtension(RtpExtension::kAbsoluteCaptureTimeUri, 5)}; SetAudioVideoRtpHeaderExtensions(offered_extensions, offered_extensions, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); SetAudioVideoRtpHeaderExtensions(local_extensions, local_extensions, &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetFirstVideoContentDescription(answer.get())->rtp_header_extensions(), IsEmpty()); @@ -1874,7 +1907,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kStopped), webrtc::RtpHeaderExtensionCapability("uri3", 7, RtpTransceiverDirection::kSendOnly)}; - auto offer = f1_.CreateOffer(opts, nullptr); + auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); EXPECT_THAT( offer->contents(), ElementsAre( @@ -1907,7 +1940,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv), webrtc::RtpHeaderExtensionCapability("uri3", 7, RtpTransceiverDirection::kSendOnly)}; - auto offer = f1_.CreateOffer(opts, nullptr); + auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); EXPECT_THAT( offer->contents(), ElementsAre( @@ -1942,7 +1975,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv), webrtc::RtpHeaderExtensionCapability("uri3", 7, RtpTransceiverDirection::kStopped)}; - auto offer = f1_.CreateOffer(opts, nullptr); + auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); EXPECT_THAT( offer->contents(), ElementsAre( @@ -1972,7 +2005,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, AnswersUnstoppedExtensions) { RtpTransceiverDirection::kRecvOnly), webrtc::RtpHeaderExtensionCapability("uri4", 1, RtpTransceiverDirection::kSendRecv)}; - auto offer = f1_.CreateOffer(opts, nullptr); + auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); opts.media_description_options.back().header_extensions = { webrtc::RtpHeaderExtensionCapability("uri1", 4, RtpTransceiverDirection::kSendOnly), @@ -1982,7 +2015,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, AnswersUnstoppedExtensions) { RtpTransceiverDirection::kStopped), webrtc::RtpHeaderExtensionCapability("uri4", 1, RtpTransceiverDirection::kSendRecv)}; - auto answer = f2_.CreateAnswer(offer.get(), opts, nullptr); + auto answer = f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( answer->contents(), ElementsAre(Property( @@ -2001,7 +2034,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, opts.media_description_options.back().header_extensions = { webrtc::RtpHeaderExtensionCapability("uri1", 1, RtpTransceiverDirection::kSendRecv)}; - auto offer = f1_.CreateOffer(opts, nullptr); + auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); opts.media_description_options.back().header_extensions = { webrtc::RtpHeaderExtensionCapability("uri1", 2, RtpTransceiverDirection::kSendRecv), @@ -2011,7 +2044,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kStopped), webrtc::RtpHeaderExtensionCapability("uri4", 6, RtpTransceiverDirection::kSendRecv)}; - auto offer2 = f1_.CreateOffer(opts, offer.get()); + auto offer2 = f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); EXPECT_THAT( offer2->contents(), ElementsAre(Property( @@ -2033,7 +2066,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv), webrtc::RtpHeaderExtensionCapability("uri2", 2, RtpTransceiverDirection::kSendRecv)}; - auto offer = f1_.CreateOffer(opts, nullptr); + auto offer = f1_.CreateOfferOrError(opts, nullptr).MoveValue(); // Check that a subsequent offer after setting "uri2" to stopped no longer // contains the extension. @@ -2042,7 +2075,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv), webrtc::RtpHeaderExtensionCapability("uri2", 2, RtpTransceiverDirection::kStopped)}; - auto offer2 = f1_.CreateOffer(opts, offer.get()); + auto offer2 = f1_.CreateOfferOrError(opts, offer.get()).MoveValue(); EXPECT_THAT( offer2->contents(), ElementsAre(Property( @@ -2061,12 +2094,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), MAKE_VECTOR(kVideoRtpExtension1), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), MAKE_VECTOR(kVideoRtpExtension2), &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_EQ( MAKE_VECTOR(kAudioRtpExtensionEncrypted1), @@ -2091,12 +2125,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), MAKE_VECTOR(kVideoRtpExtension1), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), MAKE_VECTOR(kVideoRtpExtension2), &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_EQ( MAKE_VECTOR(kAudioRtpExtensionEncrypted1), @@ -2121,12 +2156,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), MAKE_VECTOR(kVideoRtpExtension1), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), MAKE_VECTOR(kVideoRtpExtension2), &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_EQ( MAKE_VECTOR(kAudioRtpExtension1), @@ -2147,14 +2183,15 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerWithoutLegacyStreams) { MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); const AudioContentDescription* acd = ac->media_description()->as_audio(); const VideoContentDescription* vcd = vc->media_description()->as_video(); @@ -2175,12 +2212,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { offer_opts.rtcp_mux_enabled = true; answer_opts.rtcp_mux_enabled = true; - offer = f1_.CreateOffer(offer_opts, NULL); - answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); - ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); - ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); - ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); - ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); + offer = f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); + answer = + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); + ASSERT_TRUE(GetFirstAudioContentDescription(offer.get())); + ASSERT_TRUE(GetFirstVideoContentDescription(offer.get())); + ASSERT_TRUE(GetFirstAudioContentDescription(answer.get())); + ASSERT_TRUE(GetFirstVideoContentDescription(answer.get())); EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); EXPECT_TRUE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); @@ -2188,12 +2226,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { offer_opts.rtcp_mux_enabled = true; answer_opts.rtcp_mux_enabled = false; - offer = f1_.CreateOffer(offer_opts, NULL); - answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); - ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); - ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); - ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); - ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); + offer = f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); + answer = + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); + ASSERT_TRUE(GetFirstAudioContentDescription(offer.get())); + ASSERT_TRUE(GetFirstVideoContentDescription(offer.get())); + ASSERT_TRUE(GetFirstAudioContentDescription(answer.get())); + ASSERT_TRUE(GetFirstVideoContentDescription(answer.get())); EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); @@ -2201,12 +2240,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { offer_opts.rtcp_mux_enabled = false; answer_opts.rtcp_mux_enabled = true; - offer = f1_.CreateOffer(offer_opts, NULL); - answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); - ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); - ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); - ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); - ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); + offer = f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); + answer = + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); + ASSERT_TRUE(GetFirstAudioContentDescription(offer.get())); + ASSERT_TRUE(GetFirstVideoContentDescription(offer.get())); + ASSERT_TRUE(GetFirstAudioContentDescription(answer.get())); + ASSERT_TRUE(GetFirstVideoContentDescription(answer.get())); EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); @@ -2214,12 +2254,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { offer_opts.rtcp_mux_enabled = false; answer_opts.rtcp_mux_enabled = false; - offer = f1_.CreateOffer(offer_opts, NULL); - answer = f2_.CreateAnswer(offer.get(), answer_opts, NULL); - ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); - ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); - ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); - ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); + offer = f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); + answer = + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); + ASSERT_TRUE(GetFirstAudioContentDescription(offer.get())); + ASSERT_TRUE(GetFirstVideoContentDescription(offer.get())); + ASSERT_TRUE(GetFirstAudioContentDescription(answer.get())); + ASSERT_TRUE(GetFirstVideoContentDescription(answer.get())); EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); @@ -2235,17 +2276,18 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerToVideo) { AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", RtpTransceiverDirection::kRecvOnly, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); opts.media_description_options[1].stopped = true; std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); - ASSERT_TRUE(vc->media_description() != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); + ASSERT_TRUE(vc->media_description()); EXPECT_TRUE(vc->rejected); } @@ -2254,20 +2296,21 @@ TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToOfferWithRejectedMedia) { MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* ac = offer->GetContentByName("audio"); ContentInfo* vc = offer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); ac->rejected = true; vc->rejected = true; std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); ac = answer->GetContentByName("audio"); vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); EXPECT_TRUE(ac->rejected); EXPECT_TRUE(vc->rejected); } @@ -2276,11 +2319,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, OfferAndAnswerDoesNotHaveMixedByteSessionAttribute) { MediaSessionOptions opts; std::unique_ptr offer = - f1_.CreateOffer(opts, /*current_description=*/nullptr); + f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); offer->set_extmap_allow_mixed(false); std::unique_ptr answer( - f2_.CreateAnswer(offer.get(), opts, /*current_description=*/nullptr)); + f2_.CreateAnswerOrError(offer.get(), opts, + /*current_description=*/nullptr) + .MoveValue()); EXPECT_FALSE(answer->extmap_allow_mixed()); } @@ -2289,11 +2334,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, OfferAndAnswerHaveMixedByteSessionAttribute) { MediaSessionOptions opts; std::unique_ptr offer = - f1_.CreateOffer(opts, /*current_description=*/nullptr); + f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); offer->set_extmap_allow_mixed(true); std::unique_ptr answer_support( - f2_.CreateAnswer(offer.get(), opts, /*current_description=*/nullptr)); + f2_.CreateAnswerOrError(offer.get(), opts, + /*current_description=*/nullptr) + .MoveValue()); EXPECT_TRUE(answer_support->extmap_allow_mixed()); } @@ -2303,7 +2350,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); std::unique_ptr offer = - f1_.CreateOffer(opts, /*current_description=*/nullptr); + f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); offer->set_extmap_allow_mixed(false); MediaContentDescription* audio_offer = offer->GetContentDescriptionByName("audio"); @@ -2315,7 +2362,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, video_offer->extmap_allow_mixed_enum()); std::unique_ptr answer( - f2_.CreateAnswer(offer.get(), opts, /*current_description=*/nullptr)); + f2_.CreateAnswerOrError(offer.get(), opts, + /*current_description=*/nullptr) + .MoveValue()); MediaContentDescription* audio_answer = answer->GetContentDescriptionByName("audio"); @@ -2332,7 +2381,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); std::unique_ptr offer = - f1_.CreateOffer(opts, /*current_description=*/nullptr); + f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); offer->set_extmap_allow_mixed(false); MediaContentDescription* audio_offer = offer->GetContentDescriptionByName("audio"); @@ -2342,7 +2391,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); std::unique_ptr answer( - f2_.CreateAnswer(offer.get(), opts, /*current_description=*/nullptr)); + f2_.CreateAnswerOrError(offer.get(), opts, + /*current_description=*/nullptr) + .MoveValue()); MediaContentDescription* audio_answer = answer->GetContentDescriptionByName("audio"); @@ -2359,7 +2410,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kSendRecv, &opts); std::unique_ptr offer = - f1_.CreateOffer(opts, /*current_description=*/nullptr); + f1_.CreateOfferOrError(opts, /*current_description=*/nullptr).MoveValue(); offer->set_extmap_allow_mixed(false); MediaContentDescription* audio_offer = offer->GetContentDescriptionByName("audio"); @@ -2369,7 +2420,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, video_offer->set_extmap_allow_mixed_enum(MediaContentDescription::kMedia); std::unique_ptr answer( - f2_.CreateAnswer(offer.get(), opts, /*current_description=*/nullptr)); + f2_.CreateAnswerOrError(offer.get(), opts, + /*current_description=*/nullptr) + .MoveValue()); MediaContentDescription* audio_answer = answer->GetContentDescriptionByName("audio"); @@ -2397,13 +2450,14 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoOffer) { {kMediaStream1}, 1, &opts); f1_.set_secure(SEC_ENABLED); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); - ASSERT_TRUE(offer.get() != NULL); + ASSERT_TRUE(offer.get()); const ContentInfo* ac = offer->GetContentByName("audio"); const ContentInfo* vc = offer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); const AudioContentDescription* acd = ac->media_description()->as_audio(); const VideoContentDescription* vcd = vc->media_description()->as_video(); EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); @@ -2442,13 +2496,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoOffer) { AttachSenderToMediaDescriptionOptions("audio", MEDIA_TYPE_AUDIO, kAudioTrack3, {kMediaStream1}, 1, &opts); std::unique_ptr updated_offer( - f1_.CreateOffer(opts, offer.get())); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); - ASSERT_TRUE(updated_offer.get() != NULL); + ASSERT_TRUE(updated_offer.get()); ac = updated_offer->GetContentByName("audio"); vc = updated_offer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); const AudioContentDescription* updated_acd = ac->media_description()->as_audio(); const VideoContentDescription* updated_vcd = @@ -2491,11 +2545,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSimulcastVideoOffer) { const int num_sim_layers = 3; AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, num_sim_layers, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); - ASSERT_TRUE(offer.get() != NULL); + ASSERT_TRUE(offer.get()); const ContentInfo* vc = offer->GetContentByName("video"); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(vc); const VideoContentDescription* vcd = vc->media_description()->as_video(); const StreamParamsVec& video_streams = vcd->streams(); @@ -2503,7 +2558,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSimulcastVideoOffer) { EXPECT_EQ(kVideoTrack1, video_streams[0].id); const SsrcGroup* sim_ssrc_group = video_streams[0].get_ssrc_group(cricket::kSimSsrcGroupSemantics); - ASSERT_TRUE(sim_ssrc_group != NULL); + ASSERT_TRUE(sim_ssrc_group); EXPECT_EQ(static_cast(num_sim_layers), sim_ssrc_group->ssrcs.size()); } @@ -2557,7 +2612,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastOffer) { AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, send_rids, simulcast_layers, 0, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); CheckSimulcastInSessionDescription(offer.get(), "video", send_rids, simulcast_layers); @@ -2574,7 +2630,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestOfferWithRidsNoSimulcast) { AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, {rid}, SimulcastLayerList(), 0, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_NE(offer.get(), nullptr); const ContentInfo* content = offer->GetContentByName("video"); @@ -2599,7 +2656,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastAnswer) { AttachSenderToMediaDescriptionOptions("video", MEDIA_TYPE_VIDEO, kVideoTrack1, {kMediaStream1}, 1, &offer_opts); std::unique_ptr offer = - f1_.CreateOffer(offer_opts, nullptr); + f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); MediaSessionOptions answer_opts; AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", @@ -2619,7 +2676,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateCompliantSimulcastAnswer) { {kMediaStream1}, rid_descriptions, simulcast_layers, 0, &answer_opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), answer_opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); CheckSimulcastInSessionDescription(answer.get(), "video", rid_descriptions, simulcast_layers); @@ -2638,7 +2695,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestAnswerWithRidsNoSimulcast) { {kMediaStream1}, {rid_offer}, SimulcastLayerList(), 0, &offer_opts); std::unique_ptr offer = - f1_.CreateOffer(offer_opts, nullptr); + f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); MediaSessionOptions answer_opts; AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "video", @@ -2650,7 +2707,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestAnswerWithRidsNoSimulcast) { {kMediaStream1}, {rid_answer}, SimulcastLayerList(), 0, &answer_opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), answer_opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); ASSERT_NE(answer.get(), nullptr); const ContentInfo* content = offer->GetContentByName("video"); @@ -2681,7 +2738,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { &offer_opts); f1_.set_secure(SEC_ENABLED); f2_.set_secure(SEC_ENABLED); - std::unique_ptr offer = f1_.CreateOffer(offer_opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); MediaSessionOptions answer_opts; AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", @@ -2698,13 +2756,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { {kMediaStream1}, 1, &answer_opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), answer_opts, NULL); + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); - ASSERT_TRUE(answer.get() != NULL); + ASSERT_TRUE(answer.get()); const ContentInfo* ac = answer->GetContentByName("audio"); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); const AudioContentDescription* acd = ac->media_description()->as_audio(); const VideoContentDescription* vcd = vc->media_description()->as_video(); ASSERT_CRYPTO(acd, 1U, kDefaultSrtpCryptoSuite); @@ -2742,13 +2800,14 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { {kMediaStream2}, 1, &answer_opts); DetachSenderFromMediaSection("audio", kAudioTrack2, &answer_opts); std::unique_ptr updated_answer( - f2_.CreateAnswer(offer.get(), answer_opts, answer.get())); + f2_.CreateAnswerOrError(offer.get(), answer_opts, answer.get()) + .MoveValue()); - ASSERT_TRUE(updated_answer.get() != NULL); + ASSERT_TRUE(updated_answer.get()); ac = updated_answer->GetContentByName("audio"); vc = updated_answer->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); const AudioContentDescription* updated_acd = ac->media_description()->as_audio(); const VideoContentDescription* updated_vcd = @@ -2784,9 +2843,10 @@ TEST_F(MediaSessionDescriptionFactoryTest, MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const AudioContentDescription* acd = GetFirstAudioContentDescription(answer.get()); @@ -2797,7 +2857,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, EXPECT_THAT(vcd->codecs(), ElementsAreArray(kVideoCodecsAnswer)); std::unique_ptr updated_offer( - f2_.CreateOffer(opts, answer.get())); + f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); // The expected audio codecs are the common audio codecs from the first // offer/answer exchange plus the audio codecs only `f2_` offer, sorted in @@ -2838,14 +2898,15 @@ TEST_F(MediaSessionDescriptionFactoryTest, AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); // Recycle the media section by changing its mid. opts.media_description_options[0].mid = "a1"; std::unique_ptr reoffer = - f2_.CreateOffer(opts, answer.get()); + f2_.CreateOfferOrError(opts, answer.get()).MoveValue(); // Expect that the results of the first negotiation are ignored. If the m= // section was not recycled the payload types would match the initial offerer. @@ -2865,13 +2926,14 @@ TEST_F(MediaSessionDescriptionFactoryTest, AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); - auto answer = f2_.CreateAnswer(offer.get(), opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + auto answer = f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); // Recycle the media section by changing its mid. opts.media_description_options[0].mid = "v1"; std::unique_ptr reoffer = - f2_.CreateOffer(opts, answer.get()); + f2_.CreateOfferOrError(opts, answer.get()).MoveValue(); // Expect that the results of the first negotiation are ignored. If the m= // section was not recycled the payload types would match the initial offerer. @@ -2893,16 +2955,17 @@ TEST_F(MediaSessionDescriptionFactoryTest, AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "a0", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f2_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f2_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f1_.CreateAnswer(offer.get(), opts, nullptr); + f1_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); // Recycle the media section by changing its mid. opts.media_description_options[0].mid = "a1"; std::unique_ptr reoffer = - f1_.CreateOffer(opts, answer.get()); + f1_.CreateOfferOrError(opts, answer.get()).MoveValue(); std::unique_ptr reanswer = - f2_.CreateAnswer(reoffer.get(), opts, offer.get()); + f2_.CreateAnswerOrError(reoffer.get(), opts, offer.get()).MoveValue(); // Expect that the results of the first negotiation are ignored. If the m= // section was not recycled the payload types would match the initial offerer. @@ -2924,16 +2987,17 @@ TEST_F(MediaSessionDescriptionFactoryTest, AddMediaDescriptionOptions(MEDIA_TYPE_VIDEO, "v0", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f2_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f2_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f1_.CreateAnswer(offer.get(), opts, nullptr); + f1_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); // Recycle the media section by changing its mid. opts.media_description_options[0].mid = "v1"; std::unique_ptr reoffer = - f1_.CreateOffer(opts, answer.get()); + f1_.CreateOfferOrError(opts, answer.get()).MoveValue(); std::unique_ptr reanswer = - f2_.CreateAnswer(reoffer.get(), opts, offer.get()); + f2_.CreateAnswerOrError(reoffer.get(), opts, offer.get()).MoveValue(); // Expect that the results of the first negotiation are ignored. If the m= // section was not recycled the payload types would match the initial offerer. @@ -2963,10 +3027,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, &f2_codecs); f2_.set_video_codecs(f2_codecs, f2_codecs); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const VideoContentDescription* vcd = GetFirstVideoContentDescription(answer.get()); @@ -2981,10 +3046,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, // an updated offer even though the default payload types between `f1_` and // `f2_` are different. std::unique_ptr updated_offer( - f2_.CreateOffer(opts, answer.get())); + f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); ASSERT_TRUE(updated_offer); std::unique_ptr updated_answer( - f1_.CreateAnswer(updated_offer.get(), opts, answer.get())); + f1_.CreateAnswerOrError(updated_offer.get(), opts, answer.get()) + .MoveValue()); const VideoContentDescription* updated_vcd = GetFirstVideoContentDescription(updated_answer.get()); @@ -3027,15 +3093,16 @@ TEST_F(MediaSessionDescriptionFactoryTest, f2_.set_audio_codecs(audio_codecs, audio_codecs); // Offer will be {VP8, RTX for VP8}. Answer will be the same. - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); // Updated offer *should* be {VP8, RTX for VP8, VP9, RTX for VP9}. // But if the bug is triggered, RTX for VP8 ends up last. std::unique_ptr updated_offer( - f2_.CreateOffer(opts, answer.get())); + f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); const VideoContentDescription* vcd = GetFirstVideoContentDescription(updated_offer.get()); @@ -3064,9 +3131,10 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kRecvOnly, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const AudioContentDescription* acd = GetFirstAudioContentDescription(answer.get()); @@ -3085,10 +3153,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, f2_.set_video_codecs(f2_codecs, f2_codecs); std::unique_ptr updated_offer( - f2_.CreateOffer(opts, answer.get())); + f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); ASSERT_TRUE(updated_offer); std::unique_ptr updated_answer( - f1_.CreateAnswer(updated_offer.get(), opts, answer.get())); + f1_.CreateAnswerOrError(updated_offer.get(), opts, answer.get()) + .MoveValue()); const AudioContentDescription* updated_acd = GetFirstAudioContentDescription(answer.get()); @@ -3121,10 +3190,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, &f2_codecs); f2_.set_video_codecs(f2_codecs, f2_codecs); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); - ASSERT_TRUE(offer.get() != nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const VideoContentDescription* vcd = GetFirstVideoContentDescription(answer.get()); @@ -3136,7 +3206,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, // updated offer, even though the default payload types are different from // those of `f1_`. std::unique_ptr updated_offer( - f2_.CreateOffer(opts, answer.get())); + f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); ASSERT_TRUE(updated_offer); const VideoContentDescription* updated_vcd = @@ -3167,8 +3237,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { &f2_codecs); f2_.set_video_codecs(f2_codecs, f2_codecs); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); // kCodecParamAssociatedPayloadType will always be added to the offer when RTX // is selected. Manually remove kCodecParamAssociatedPayloadType so that it // is possible to test that that RTX is dropped when @@ -3186,7 +3257,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { desc->set_codecs(codecs); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), @@ -3212,12 +3283,13 @@ TEST_F(MediaSessionDescriptionFactoryTest, FilterOutRtxIfAptDoesntMatch) { &f2_codecs); f2_.set_video_codecs(f2_codecs, f2_codecs); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); // Associated payload type doesn't match, therefore, RTX codec is removed in // the answer. std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_THAT( GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), @@ -3251,10 +3323,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, // H264-SVC codec is removed in the answer, therefore, associated RTX codec // for H264-SVC should also be removed. - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const VideoContentDescription* vcd = GetFirstVideoContentDescription(answer.get()); std::vector expected_codecs = MAKE_VECTOR(kVideoCodecsAnswer); @@ -3277,7 +3350,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, AddSecondRtxInNewOffer) { &f1_codecs); f1_.set_video_codecs(f1_codecs, f1_codecs); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); const VideoContentDescription* vcd = GetFirstVideoContentDescription(offer.get()); @@ -3293,7 +3367,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, AddSecondRtxInNewOffer) { f1_.set_video_codecs(f1_codecs, f1_codecs); std::unique_ptr updated_offer( - f1_.CreateOffer(opts, offer.get())); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); ASSERT_TRUE(updated_offer); vcd = GetFirstVideoContentDescription(updated_offer.get()); @@ -3321,8 +3395,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateMultipleRtxSsrcs) { // Ensure that the offer has an RTX ssrc for each regular ssrc, and that there // is a FID ssrc + grouping for each. - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); MediaContentDescription* media_desc = offer->GetContentDescriptionByName(cricket::CN_VIDEO); ASSERT_TRUE(media_desc); @@ -3365,8 +3440,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { // Ensure that the offer has a single FlexFEC ssrc and that // there is no FEC-FR ssrc + grouping for each. - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); - ASSERT_TRUE(offer.get() != nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); MediaContentDescription* media_desc = offer->GetContentDescriptionByName(cricket::CN_VIDEO); ASSERT_TRUE(media_desc); @@ -3408,8 +3484,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateNoFlexfecSsrcs) { // Ensure that the offer has no FlexFEC ssrcs for each regular ssrc, and that // there is no FEC-FR ssrc + grouping for each. - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); - ASSERT_TRUE(offer.get() != nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); MediaContentDescription* media_desc = offer->GetContentDescriptionByName(cricket::CN_VIDEO); ASSERT_TRUE(media_desc); @@ -3442,11 +3519,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension1), MAKE_VECTOR(kVideoRtpExtension1), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension2), MAKE_VECTOR(kVideoRtpExtension2), &opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, NULL); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); EXPECT_EQ( MAKE_VECTOR(kAudioRtpExtensionAnswer), @@ -3456,7 +3534,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, GetFirstVideoContentDescription(answer.get())->rtp_header_extensions()); std::unique_ptr updated_offer( - f2_.CreateOffer(opts, answer.get())); + f2_.CreateOfferOrError(opts, answer.get()).MoveValue()); // The expected RTP header extensions in the new offer are the resulting // extensions from the first offer/answer exchange plus the extensions only @@ -3497,7 +3575,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReused) { SetAudioVideoRtpHeaderExtensions(MAKE_VECTOR(kAudioRtpExtension3), MAKE_VECTOR(kVideoRtpExtension3), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); // Since the audio extensions used ID 3 for "both_audio_and_video", so should // the video extensions. @@ -3515,7 +3594,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReused) { // Nothing should change when creating a new offer std::unique_ptr updated_offer( - f1_.CreateOffer(opts, offer.get())); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3), GetFirstAudioContentDescription(updated_offer.get()) @@ -3536,7 +3615,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReusedEncrypted) { SetAudioVideoRtpHeaderExtensions( MAKE_VECTOR(kAudioRtpExtension3ForEncryption), MAKE_VECTOR(kVideoRtpExtension3ForEncryption), &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); EXPECT_EQ( MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), @@ -3547,7 +3627,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReusedEncrypted) { // Nothing should change when creating a new offer std::unique_ptr updated_offer( - f1_.CreateOffer(opts, offer.get())); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension3ForEncryptionOffer), GetFirstAudioContentDescription(updated_offer.get()) @@ -3573,12 +3653,12 @@ TEST(MediaSessionDescription, CopySessionDescription) { source.AddContent(cricket::CN_VIDEO, MediaProtocolType::kRtp, vcd->Clone()); std::unique_ptr copy = source.Clone(); - ASSERT_TRUE(copy.get() != NULL); + ASSERT_TRUE(copy.get()); EXPECT_TRUE(copy->HasGroup(cricket::CN_AUDIO)); const ContentInfo* ac = copy->GetContentByName("audio"); const ContentInfo* vc = copy->GetContentByName("video"); - ASSERT_TRUE(ac != NULL); - ASSERT_TRUE(vc != NULL); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); EXPECT_EQ(MediaProtocolType::kRtp, ac->type); const AudioContentDescription* acd_copy = ac->media_description()->as_audio(); EXPECT_EQ(acd->codecs(), acd_copy->codecs()); @@ -3725,19 +3805,22 @@ TEST_F(MediaSessionDescriptionFactoryTest, tdf2_.set_secure(SEC_DISABLED); std::unique_ptr offer = - f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); - ASSERT_TRUE(offer.get() != NULL); + f1_.CreateOfferOrError(CreatePlanBMediaSessionOptions(), nullptr) + .MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* offer_content = offer->GetContentByName("audio"); - ASSERT_TRUE(offer_content != NULL); + ASSERT_TRUE(offer_content); AudioContentDescription* offer_audio_desc = offer_content->media_description()->as_audio(); offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); - ASSERT_TRUE(answer != NULL); + f2_.CreateAnswerOrError(offer.get(), CreatePlanBMediaSessionOptions(), + nullptr) + .MoveValue(); + ASSERT_TRUE(answer); ContentInfo* answer_content = answer->GetContentByName("audio"); - ASSERT_TRUE(answer_content != NULL); + ASSERT_TRUE(answer_content); ASSERT_TRUE(answer_content->rejected); } @@ -3751,20 +3834,23 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestOfferDtlsSavpfCreateAnswer) { tdf2_.set_secure(SEC_ENABLED); std::unique_ptr offer = - f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL); - ASSERT_TRUE(offer.get() != NULL); + f1_.CreateOfferOrError(CreatePlanBMediaSessionOptions(), nullptr) + .MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* offer_content = offer->GetContentByName("audio"); - ASSERT_TRUE(offer_content != NULL); + ASSERT_TRUE(offer_content); AudioContentDescription* offer_audio_desc = offer_content->media_description()->as_audio(); offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL); - ASSERT_TRUE(answer != NULL); + f2_.CreateAnswerOrError(offer.get(), CreatePlanBMediaSessionOptions(), + nullptr) + .MoveValue(); + ASSERT_TRUE(answer); const ContentInfo* answer_content = answer->GetContentByName("audio"); - ASSERT_TRUE(answer_content != NULL); + ASSERT_TRUE(answer_content); ASSERT_FALSE(answer_content->rejected); const AudioContentDescription* answer_audio_desc = @@ -3788,79 +3874,79 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoDtls) { const cricket::TransportDescription* video_trans_desc; // Generate an offer with SDES and DTLS support. - offer = f1_.CreateOffer(options, NULL); - ASSERT_TRUE(offer.get() != NULL); + offer = f1_.CreateOfferOrError(options, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); audio_media_desc = offer->GetContentDescriptionByName("audio"); - ASSERT_TRUE(audio_media_desc != NULL); + ASSERT_TRUE(audio_media_desc); video_media_desc = offer->GetContentDescriptionByName("video"); - ASSERT_TRUE(video_media_desc != NULL); + ASSERT_TRUE(video_media_desc); EXPECT_EQ(1u, audio_media_desc->cryptos().size()); EXPECT_EQ(1u, video_media_desc->cryptos().size()); audio_trans_desc = offer->GetTransportDescriptionByName("audio"); - ASSERT_TRUE(audio_trans_desc != NULL); + ASSERT_TRUE(audio_trans_desc); video_trans_desc = offer->GetTransportDescriptionByName("video"); - ASSERT_TRUE(video_trans_desc != NULL); - ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); - ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); + ASSERT_TRUE(video_trans_desc); + ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get()); + ASSERT_TRUE(video_trans_desc->identity_fingerprint.get()); // Generate an answer with only SDES support, since tdf2 has crypto disabled. - answer = f2_.CreateAnswer(offer.get(), options, NULL); - ASSERT_TRUE(answer.get() != NULL); + answer = f2_.CreateAnswerOrError(offer.get(), options, nullptr).MoveValue(); + ASSERT_TRUE(answer.get()); audio_media_desc = answer->GetContentDescriptionByName("audio"); - ASSERT_TRUE(audio_media_desc != NULL); + ASSERT_TRUE(audio_media_desc); video_media_desc = answer->GetContentDescriptionByName("video"); - ASSERT_TRUE(video_media_desc != NULL); + ASSERT_TRUE(video_media_desc); EXPECT_EQ(1u, audio_media_desc->cryptos().size()); EXPECT_EQ(1u, video_media_desc->cryptos().size()); audio_trans_desc = answer->GetTransportDescriptionByName("audio"); - ASSERT_TRUE(audio_trans_desc != NULL); + ASSERT_TRUE(audio_trans_desc); video_trans_desc = answer->GetTransportDescriptionByName("video"); - ASSERT_TRUE(video_trans_desc != NULL); - ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() == NULL); - ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() == NULL); + ASSERT_TRUE(video_trans_desc); + ASSERT_FALSE(audio_trans_desc->identity_fingerprint.get()); + ASSERT_FALSE(video_trans_desc->identity_fingerprint.get()); // Enable DTLS; the answer should now only have DTLS support. tdf2_.set_secure(SEC_ENABLED); - answer = f2_.CreateAnswer(offer.get(), options, NULL); - ASSERT_TRUE(answer.get() != NULL); + answer = f2_.CreateAnswerOrError(offer.get(), options, nullptr).MoveValue(); + ASSERT_TRUE(answer.get()); audio_media_desc = answer->GetContentDescriptionByName("audio"); - ASSERT_TRUE(audio_media_desc != NULL); + ASSERT_TRUE(audio_media_desc); video_media_desc = answer->GetContentDescriptionByName("video"); - ASSERT_TRUE(video_media_desc != NULL); + ASSERT_TRUE(video_media_desc); EXPECT_TRUE(audio_media_desc->cryptos().empty()); EXPECT_TRUE(video_media_desc->cryptos().empty()); EXPECT_EQ(cricket::kMediaProtocolSavpf, audio_media_desc->protocol()); EXPECT_EQ(cricket::kMediaProtocolSavpf, video_media_desc->protocol()); audio_trans_desc = answer->GetTransportDescriptionByName("audio"); - ASSERT_TRUE(audio_trans_desc != NULL); + ASSERT_TRUE(audio_trans_desc); video_trans_desc = answer->GetTransportDescriptionByName("video"); - ASSERT_TRUE(video_trans_desc != NULL); - ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); - ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); + ASSERT_TRUE(video_trans_desc); + ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get()); + ASSERT_TRUE(video_trans_desc->identity_fingerprint.get()); // Try creating offer again. DTLS enabled now, crypto's should be empty // in new offer. - offer = f1_.CreateOffer(options, offer.get()); - ASSERT_TRUE(offer.get() != NULL); + offer = f1_.CreateOfferOrError(options, offer.get()).MoveValue(); + ASSERT_TRUE(offer.get()); audio_media_desc = offer->GetContentDescriptionByName("audio"); - ASSERT_TRUE(audio_media_desc != NULL); + ASSERT_TRUE(audio_media_desc); video_media_desc = offer->GetContentDescriptionByName("video"); - ASSERT_TRUE(video_media_desc != NULL); + ASSERT_TRUE(video_media_desc); EXPECT_TRUE(audio_media_desc->cryptos().empty()); EXPECT_TRUE(video_media_desc->cryptos().empty()); audio_trans_desc = offer->GetTransportDescriptionByName("audio"); - ASSERT_TRUE(audio_trans_desc != NULL); + ASSERT_TRUE(audio_trans_desc); video_trans_desc = offer->GetTransportDescriptionByName("video"); - ASSERT_TRUE(video_trans_desc != NULL); - ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); - ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); + ASSERT_TRUE(video_trans_desc); + ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get()); + ASSERT_TRUE(video_trans_desc->identity_fingerprint.get()); } // Test that an answer can't be created if cryptos are required but the offer is @@ -3872,11 +3958,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestSecureAnswerToUnsecureOffer) { f2_.set_secure(SEC_REQUIRED); tdf1_.set_secure(SEC_ENABLED); - std::unique_ptr offer = f1_.CreateOffer(options, NULL); - ASSERT_TRUE(offer.get() != NULL); - std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), options, NULL); - EXPECT_TRUE(answer.get() == NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(options, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); + + auto error = f2_.CreateAnswerOrError(offer.get(), options, nullptr); + EXPECT_FALSE(error.ok()); } // Test that we accept a DTLS offer without SDES and create an appropriate @@ -3890,8 +3977,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); // Generate an offer with DTLS but without SDES. - std::unique_ptr offer = f1_.CreateOffer(options, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(options, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); const AudioContentDescription* audio_offer = GetFirstAudioContentDescription(offer.get()); @@ -3902,22 +3990,22 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { const cricket::TransportDescription* audio_offer_trans_desc = offer->GetTransportDescriptionByName("audio"); - ASSERT_TRUE(audio_offer_trans_desc->identity_fingerprint.get() != NULL); + ASSERT_TRUE(audio_offer_trans_desc->identity_fingerprint.get()); const cricket::TransportDescription* video_offer_trans_desc = offer->GetTransportDescriptionByName("video"); - ASSERT_TRUE(video_offer_trans_desc->identity_fingerprint.get() != NULL); + ASSERT_TRUE(video_offer_trans_desc->identity_fingerprint.get()); // Generate an answer with DTLS. std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), options, NULL); - ASSERT_TRUE(answer.get() != NULL); + f2_.CreateAnswerOrError(offer.get(), options, nullptr).MoveValue(); + ASSERT_TRUE(answer.get()); const cricket::TransportDescription* audio_answer_trans_desc = answer->GetTransportDescriptionByName("audio"); - EXPECT_TRUE(audio_answer_trans_desc->identity_fingerprint.get() != NULL); + EXPECT_TRUE(audio_answer_trans_desc->identity_fingerprint.get()); const cricket::TransportDescription* video_answer_trans_desc = answer->GetTransportDescriptionByName("video"); - EXPECT_TRUE(video_answer_trans_desc->identity_fingerprint.get() != NULL); + EXPECT_TRUE(video_answer_trans_desc->identity_fingerprint.get()); } // Verifies if vad_enabled option is set to false, CN codecs are not present in @@ -3925,19 +4013,20 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { TEST_F(MediaSessionDescriptionFactoryTest, TestVADEnableOption) { MediaSessionOptions options; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &options); - std::unique_ptr offer = f1_.CreateOffer(options, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + f1_.CreateOfferOrError(options, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); const ContentInfo* audio_content = offer->GetContentByName("audio"); EXPECT_FALSE(VerifyNoCNCodecs(audio_content)); options.vad_enabled = false; - offer = f1_.CreateOffer(options, NULL); - ASSERT_TRUE(offer.get() != NULL); + offer = f1_.CreateOfferOrError(options, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); audio_content = offer->GetContentByName("audio"); EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); std::unique_ptr answer = - f1_.CreateAnswer(offer.get(), options, NULL); - ASSERT_TRUE(answer.get() != NULL); + f1_.CreateAnswerOrError(offer.get(), options, nullptr).MoveValue(); + ASSERT_TRUE(answer.get()); audio_content = answer->GetContentByName("audio"); EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); } @@ -3955,16 +4044,17 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestMIDsMatchesExistingOffer) { RtpTransceiverDirection::kSendRecv, kActive, &opts); // Create offer. - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); std::unique_ptr updated_offer( - f1_.CreateOffer(opts, offer.get())); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); const ContentInfo* audio_content = GetFirstAudioContent(updated_offer.get()); const ContentInfo* video_content = GetFirstVideoContent(updated_offer.get()); const ContentInfo* data_content = GetFirstDataContent(updated_offer.get()); - ASSERT_TRUE(audio_content != nullptr); - ASSERT_TRUE(video_content != nullptr); - ASSERT_TRUE(data_content != nullptr); + ASSERT_TRUE(audio_content); + ASSERT_TRUE(video_content); + ASSERT_TRUE(data_content); EXPECT_EQ("audio_modified", audio_content->name); EXPECT_EQ("video_modified", video_content->name); EXPECT_EQ("data_modified", data_content->name); @@ -3999,7 +4089,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, &opts); AttachSenderToMediaDescriptionOptions( "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(4u, offer->contents().size()); @@ -4059,10 +4150,11 @@ TEST_F(MediaSessionDescriptionFactoryTest, AttachSenderToMediaDescriptionOptions( "video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, {kMediaStream2}, 1, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); ASSERT_EQ(4u, answer->contents().size()); EXPECT_FALSE(answer->contents()[0].rejected); @@ -4105,7 +4197,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kInactive, kStopped, &offer_opts); std::unique_ptr offer = - f1_.CreateOffer(offer_opts, nullptr); + f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(2u, offer->contents().size()); EXPECT_FALSE(offer->contents()[0].rejected); @@ -4125,7 +4217,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kInactive, kStopped, &offer_opts); std::unique_ptr offer = - f1_.CreateOffer(offer_opts, nullptr); + f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(2u, offer->contents().size()); EXPECT_FALSE(offer->contents()[0].rejected); @@ -4140,7 +4232,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv, kActive, &answer_opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), answer_opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); ASSERT_EQ(2u, answer->contents().size()); EXPECT_FALSE(answer->contents()[0].rejected); EXPECT_TRUE(answer->contents()[1].rejected); @@ -4159,7 +4251,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv, kActive, &offer_opts); std::unique_ptr offer = - f1_.CreateOffer(offer_opts, nullptr); + f1_.CreateOfferOrError(offer_opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(2u, offer->contents().size()); ASSERT_FALSE(offer->contents()[0].rejected); @@ -4174,7 +4266,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kInactive, kStopped, &answer_opts); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), answer_opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), answer_opts, nullptr).MoveValue(); ASSERT_EQ(2u, answer->contents().size()); EXPECT_FALSE(answer->contents()[0].rejected); EXPECT_TRUE(answer->contents()[1].rejected); @@ -4197,7 +4289,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(2u, offer->contents().size()); @@ -4217,7 +4310,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv, kActive, &opts); // Create an offer with two video sections using same codecs. - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(2u, offer->contents().size()); const VideoContentDescription* vcd1 = @@ -4233,7 +4327,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, // Create answer and negotiate the codecs. std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); ASSERT_TRUE(answer); ASSERT_EQ(2u, answer->contents().size()); vcd1 = answer->contents()[0].media_description()->as_video(); @@ -4261,7 +4355,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, PacketizationIsEqual) { &opts); // Create an offer with two video sections using same codecs. - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(1u, offer->contents().size()); const VideoContentDescription* vcd1 = @@ -4271,7 +4366,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, PacketizationIsEqual) { // Create answer and negotiate the codecs. std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); ASSERT_TRUE(answer); ASSERT_EQ(1u, answer->contents().size()); vcd1 = answer->contents()[0].media_description()->as_video(); @@ -4296,7 +4391,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, PacketizationIsDifferent) { &opts); // Create an offer with two video sections using same codecs. - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(1u, offer->contents().size()); const VideoContentDescription* vcd1 = @@ -4306,7 +4402,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, PacketizationIsDifferent) { // Create answer and negotiate the codecs. std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); ASSERT_TRUE(answer); ASSERT_EQ(1u, answer->contents().size()); vcd1 = answer->contents()[0].media_description()->as_video(); @@ -4326,7 +4422,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv, kActive, &opts); // Create an offer with two video sections using same codecs. - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(2u, offer->contents().size()); VideoContentDescription* vcd1 = @@ -4342,7 +4439,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); vcd1->set_codecs(video_codecs_reverse); std::unique_ptr updated_offer( - f1_.CreateOffer(opts, offer.get())); + f1_.CreateOfferOrError(opts, offer.get()).MoveValue()); vcd1 = updated_offer->contents()[0].media_description()->as_video(); vcd2 = updated_offer->contents()[1].media_description()->as_video(); // The video codec preference order should be respected. @@ -4362,7 +4459,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv, kActive, &opts); // Create an offer with two video sections using same codecs. - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); ASSERT_EQ(2u, offer->contents().size()); VideoContentDescription* vcd1 = @@ -4378,7 +4476,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, auto video_codecs_reverse = MAKE_VECTOR(kVideoCodecs1Reverse); vcd1->set_codecs(video_codecs_reverse); std::unique_ptr answer = - f1_.CreateAnswer(offer.get(), opts, nullptr); + f1_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); vcd1 = answer->contents()[0].media_description()->as_video(); vcd2 = answer->contents()[1].media_description()->as_video(); // The video codec preference order should be respected. @@ -4420,7 +4518,8 @@ TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerWithLocalCodecParams) { RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); auto offer_acd = offer->contents()[0].media_description()->as_audio(); auto offer_vcd = offer->contents()[1].media_description()->as_video(); @@ -4431,7 +4530,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerWithLocalCodecParams) { EXPECT_EQ(video_value1, value); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); ASSERT_TRUE(answer); auto answer_acd = answer->contents()[0].media_description()->as_audio(); auto answer_vcd = answer->contents()[1].media_description()->as_video(); @@ -4468,11 +4567,12 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtpTransceiverDirection::kSendRecv, kActive, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); ASSERT_TRUE(offer); std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); ASSERT_TRUE(answer); // Answer should have one negotiated codec with packetization-mode=1 using the @@ -4522,18 +4622,19 @@ class MediaProtocolTest : public ::testing::TestWithParam { TEST_P(MediaProtocolTest, TestAudioVideoAcceptance) { MediaSessionOptions opts; AddAudioVideoSections(RtpTransceiverDirection::kRecvOnly, &opts); - std::unique_ptr offer = f1_.CreateOffer(opts, nullptr); - ASSERT_TRUE(offer.get() != nullptr); + std::unique_ptr offer = + f1_.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); // Set the protocol for all the contents. for (auto& content : offer.get()->contents()) { content.media_description()->set_protocol(GetParam()); } std::unique_ptr answer = - f2_.CreateAnswer(offer.get(), opts, nullptr); + f2_.CreateAnswerOrError(offer.get(), opts, nullptr).MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); const ContentInfo* vc = answer->GetContentByName("video"); - ASSERT_TRUE(ac != nullptr); - ASSERT_TRUE(vc != nullptr); + ASSERT_TRUE(ac); + ASSERT_TRUE(vc); EXPECT_FALSE(ac->rejected); // the offer is accepted EXPECT_FALSE(vc->rejected); const AudioContentDescription* acd = ac->media_description()->as_audio(); @@ -4642,8 +4743,9 @@ void TestAudioCodecsOffer(RtpTransceiverDirection direction) { "audio", MEDIA_TYPE_AUDIO, kAudioTrack1, {kMediaStream1}, 1, &opts); } - std::unique_ptr offer = sf.CreateOffer(opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + std::unique_ptr offer = + sf.CreateOfferOrError(opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); ContentInfo* ac = offer->GetContentByName("audio"); // If the factory didn't add any audio content to the offer, we cannot check @@ -4748,8 +4850,8 @@ void TestAudioCodecsAnswer(RtpTransceiverDirection offer_direction, } std::unique_ptr offer = - offer_factory.CreateOffer(offer_opts, NULL); - ASSERT_TRUE(offer.get() != NULL); + offer_factory.CreateOfferOrError(offer_opts, nullptr).MoveValue(); + ASSERT_TRUE(offer.get()); MediaSessionOptions answer_opts; AddMediaDescriptionOptions(MEDIA_TYPE_AUDIO, "audio", answer_direction, @@ -4761,7 +4863,8 @@ void TestAudioCodecsAnswer(RtpTransceiverDirection offer_direction, &answer_opts); } std::unique_ptr answer = - answer_factory.CreateAnswer(offer.get(), answer_opts, NULL); + answer_factory.CreateAnswerOrError(offer.get(), answer_opts, nullptr) + .MoveValue(); const ContentInfo* ac = answer->GetContentByName("audio"); // If the factory didn't add any audio content to the answer, we cannot diff --git a/pc/webrtc_session_description_factory.cc b/pc/webrtc_session_description_factory.cc index 05cbe47aef..42a8da3e70 100644 --- a/pc/webrtc_session_description_factory.cc +++ b/pc/webrtc_session_description_factory.cc @@ -280,17 +280,16 @@ void WebRtcSessionDescriptionFactory::InternalCreateOffer( } } - std::unique_ptr desc = - session_desc_factory_.CreateOffer( - request.options, sdp_info_->local_description() - ? sdp_info_->local_description()->description() - : nullptr); - if (!desc) { - PostCreateSessionDescriptionFailed( - request.observer.get(), RTCError(RTCErrorType::INTERNAL_ERROR, - "Failed to initialize the offer.")); + auto result = session_desc_factory_.CreateOfferOrError( + request.options, sdp_info_->local_description() + ? sdp_info_->local_description()->description() + : nullptr); + if (!result.ok()) { + PostCreateSessionDescriptionFailed(request.observer.get(), result.error()); return; } + std::unique_ptr desc = std::move(result.value()); + RTC_CHECK(desc); // RFC 3264 // When issuing an offer that modifies the session, @@ -339,21 +338,20 @@ void WebRtcSessionDescriptionFactory::InternalCreateAnswer( } } - std::unique_ptr desc = - session_desc_factory_.CreateAnswer( - sdp_info_->remote_description() - ? sdp_info_->remote_description()->description() - : nullptr, - request.options, - sdp_info_->local_description() - ? sdp_info_->local_description()->description() - : nullptr); - if (!desc) { - PostCreateSessionDescriptionFailed( - request.observer.get(), RTCError(RTCErrorType::INTERNAL_ERROR, - "Failed to initialize the answer.")); + auto result = session_desc_factory_.CreateAnswerOrError( + sdp_info_->remote_description() + ? sdp_info_->remote_description()->description() + : nullptr, + request.options, + sdp_info_->local_description() + ? sdp_info_->local_description()->description() + : nullptr); + if (!result.ok()) { + PostCreateSessionDescriptionFailed(request.observer.get(), result.error()); return; } + std::unique_ptr desc = std::move(result.value()); + RTC_CHECK(desc); // RFC 3264 // If the answer is different from the offer in any way (different IP diff --git a/tools_webrtc/sanitizers/lsan_suppressions_webrtc.cc b/tools_webrtc/sanitizers/lsan_suppressions_webrtc.cc index 064b2804ab..eb9f6a4761 100644 --- a/tools_webrtc/sanitizers/lsan_suppressions_webrtc.cc +++ b/tools_webrtc/sanitizers/lsan_suppressions_webrtc.cc @@ -74,8 +74,6 @@ char kLSanDefaultSuppressions[] = // peerconnection_unittests // https://code.google.com/p/webrtc/issues/detail?id=2528 "leak:cricket::FakeVideoMediaChannel::~FakeVideoMediaChannel\n" - "leak:cricket::MediaSessionDescriptionFactory::CreateAnswer\n" - "leak:cricket::MediaSessionDescriptionFactory::CreateOffer\n" "leak:DtmfSenderTest_InsertEmptyTonesToCancelPreviousTask_Test::TestBody\n" "leak:sigslot::_signal_base2*::~_signal_base2\n" "leak:testing::internal::CmpHelperEQ\n" @@ -83,8 +81,6 @@ char kLSanDefaultSuppressions[] = "leak:webrtc::AudioDeviceLinuxALSA::InitSpeaker\n" "leak:webrtc::CreateIceCandidate\n" "leak:webrtc::WebRtcIdentityRequestObserver::OnSuccess\n" - "leak:webrtc::WebRtcSessionDescriptionFactory::InternalCreateAnswer\n" - "leak:webrtc::WebRtcSessionDescriptionFactory::InternalCreateOffer\n" "leak:PeerConnectionInterfaceTest_SsrcInOfferAnswer_Test::TestBody\n" "leak:PeerConnectionInterfaceTest_CloseAndTestMethods_Test::TestBody\n" "leak:WebRtcSdpTest::TestDeserializeRtcpFb\n"