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 <shampson@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24105}
diff --git a/api/jsep.h b/api/jsep.h
index cbc0a6c..4d4bcc0 100644
--- a/api/jsep.h
+++ b/api/jsep.h
@@ -197,6 +197,14 @@
     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<SessionDescriptionInterface> CreateSessionDescription(
+    SdpType type,
+    const std::string& session_id,
+    const std::string& session_version,
+    std::unique_ptr<cricket::SessionDescription> description);
+
 // CreateOffer and CreateAnswer callback interface.
 class CreateSessionDescriptionObserver : public rtc::RefCountInterface {
  public:
diff --git a/pc/jsepsessiondescription.cc b/pc/jsepsessiondescription.cc
index 2adf69d..64a7a2b 100644
--- a/pc/jsepsessiondescription.cc
+++ b/pc/jsepsessiondescription.cc
@@ -167,6 +167,18 @@
   return std::move(jsep_desc);
 }
 
+std::unique_ptr<SessionDescriptionInterface> CreateSessionDescription(
+    SdpType type,
+    const std::string& session_id,
+    const std::string& session_version,
+    std::unique_ptr<cricket::SessionDescription> description) {
+  auto jsep_description = absl::make_unique<JsepSessionDescription>(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 c0f2c73..1beb347 100644
--- a/pc/peerconnectioninterface_unittest.cc
+++ b/pc/peerconnectioninterface_unittest.cc
@@ -3200,10 +3200,11 @@
   std::unique_ptr<SessionDescriptionInterface> 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::JsepSessionDescription>(
-      webrtc::SdpType::kOffer);
-  modified_offer->Initialize(offer->description()->Copy(), offer->session_id(),
-                             offer->session_version());
+  std::unique_ptr<SessionDescriptionInterface> 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();