From d9e4a06374b32c4d32f3597586fbc6dfa3b7c531 Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Tue, 24 Jul 2018 18:23:33 -0700 Subject: [PATCH] Add CreateSessionDescription overload which takes a cricket::SessionDescription This gives clients a way to create a SessionDescriptionInterface from a parsed cricket::SessionDescription other than depending on JsepSessionDescription. Bug: webrtc:9544 Change-Id: I3eec87b24aa005e6cbc4a018ad452c0d6823435d Reviewed-on: https://webrtc-review.googlesource.com/90382 Reviewed-by: Seth Hampson Commit-Queue: Steve Anton Cr-Commit-Position: refs/heads/master@{#24105} --- api/jsep.h | 8 ++++++++ pc/jsepsessiondescription.cc | 12 ++++++++++++ pc/peerconnectioninterface_unittest.cc | 9 +++++---- 3 files changed, 25 insertions(+), 4 deletions(-) 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();