diff --git a/api/jsep.h b/api/jsep.h index cbc0a6c6bf..4d4bcc0bfb 100644 --- a/api/jsep.h +++ b/api/jsep.h @@ -197,6 +197,14 @@ std::unique_ptr CreateSessionDescription( const std::string& sdp, SdpParseError* error_out); +// Creates a SessionDescriptionInterface based on a parsed SDP structure and the +// given type, ID and version. +std::unique_ptr CreateSessionDescription( + SdpType type, + const std::string& session_id, + const std::string& session_version, + std::unique_ptr description); + // CreateOffer and CreateAnswer callback interface. class CreateSessionDescriptionObserver : public rtc::RefCountInterface { public: diff --git a/pc/jsepsessiondescription.cc b/pc/jsepsessiondescription.cc index 2adf69d6a3..64a7a2bd59 100644 --- a/pc/jsepsessiondescription.cc +++ b/pc/jsepsessiondescription.cc @@ -167,6 +167,18 @@ std::unique_ptr CreateSessionDescription( return std::move(jsep_desc); } +std::unique_ptr CreateSessionDescription( + SdpType type, + const std::string& session_id, + const std::string& session_version, + std::unique_ptr description) { + auto jsep_description = absl::make_unique(type); + bool initialize_success = jsep_description->Initialize( + description.release(), session_id, session_version); + RTC_DCHECK(initialize_success); + return std::move(jsep_description); +} + JsepSessionDescription::JsepSessionDescription(SdpType type) : type_(type) {} JsepSessionDescription::JsepSessionDescription(const std::string& type) { diff --git a/pc/peerconnectioninterface_unittest.cc b/pc/peerconnectioninterface_unittest.cc index c0f2c73909..1beb34721c 100644 --- a/pc/peerconnectioninterface_unittest.cc +++ b/pc/peerconnectioninterface_unittest.cc @@ -3200,10 +3200,11 @@ TEST_P(PeerConnectionInterfaceTest, std::unique_ptr offer; ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); // Grab a copy of the offer before it gets passed into the PC. - auto modified_offer = absl::make_unique( - webrtc::SdpType::kOffer); - modified_offer->Initialize(offer->description()->Copy(), offer->session_id(), - offer->session_version()); + std::unique_ptr modified_offer = + webrtc::CreateSessionDescription( + webrtc::SdpType::kOffer, offer->session_id(), + offer->session_version(), + absl::WrapUnique(offer->description()->Copy())); EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); auto senders = pc_->GetSenders();