Convert MediaSessionFactory to return unique_ptrs

Bug: None
Change-Id: Ia0dbe00fd063b083caad8598102236aa3bb3079d
Reviewed-on: https://webrtc-review.googlesource.com/c/113826
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25974}
This commit is contained in:
Steve Anton 2018-12-11 10:15:23 -08:00 committed by Commit Bot
parent 1a9d3c398d
commit 6fe1fba7b1
7 changed files with 272 additions and 238 deletions

View File

@ -144,6 +144,7 @@ rtc_static_library("libjingle_peerconnection_api") {
"transport:network_control",
"video:encoded_image",
"video:video_frame",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
# Basically, don't add stuff here. You might break sensitive downstream

View File

@ -18,6 +18,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/candidate.h"
#include "api/jsep.h"
#include "api/jsepicecandidate.h"
@ -35,6 +36,11 @@ class JsepSessionDescription : public SessionDescriptionInterface {
explicit JsepSessionDescription(SdpType type);
// TODO(steveanton): Remove this once callers have switched to SdpType.
explicit JsepSessionDescription(const std::string& type);
JsepSessionDescription(
SdpType type,
std::unique_ptr<cricket::SessionDescription> description,
absl::string_view session_id,
absl::string_view session_version);
virtual ~JsepSessionDescription();
// Takes ownership of |description|.

View File

@ -164,6 +164,19 @@ JsepSessionDescription::JsepSessionDescription(const std::string& type) {
}
}
JsepSessionDescription::JsepSessionDescription(
SdpType type,
std::unique_ptr<cricket::SessionDescription> description,
absl::string_view session_id,
absl::string_view session_version)
: description_(std::move(description)),
session_id_(session_id),
session_version_(session_version),
type_(type) {
RTC_DCHECK(description_);
candidate_collection_.resize(number_of_mediasections());
}
JsepSessionDescription::~JsepSessionDescription() {}
bool JsepSessionDescription::Initialize(

View File

@ -1275,7 +1275,7 @@ void MediaSessionDescriptionFactory::set_audio_codecs(
ComputeAudioCodecsIntersectionAndUnion();
}
SessionDescription* MediaSessionDescriptionFactory::CreateOffer(
std::unique_ptr<SessionDescription> MediaSessionDescriptionFactory::CreateOffer(
const MediaSessionOptions& session_options,
const SessionDescription* current_description) const {
// Must have options for each existing section.
@ -1400,10 +1400,11 @@ SessionDescription* MediaSessionDescriptionFactory::CreateOffer(
offer->set_extmap_allow_mixed(session_options.offer_extmap_allow_mixed);
return offer.release();
return offer;
}
SessionDescription* MediaSessionDescriptionFactory::CreateAnswer(
std::unique_ptr<SessionDescription>
MediaSessionDescriptionFactory::CreateAnswer(
const SessionDescription* offer,
const MediaSessionOptions& session_options,
const SessionDescription* current_description) const {
@ -1575,7 +1576,7 @@ SessionDescription* MediaSessionDescriptionFactory::CreateAnswer(
answer->set_msid_signaling(cricket::kMsidSignalingSsrcAttribute);
}
return answer.release();
return answer;
}
const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForOffer(

View File

@ -163,10 +163,10 @@ class MediaSessionDescriptionFactory {
is_unified_plan_ = is_unified_plan;
}
SessionDescription* CreateOffer(
std::unique_ptr<SessionDescription> CreateOffer(
const MediaSessionOptions& options,
const SessionDescription* current_description) const;
SessionDescription* CreateAnswer(
std::unique_ptr<SessionDescription> CreateAnswer(
const SessionDescription* offer,
const MediaSessionOptions& options,
const SessionDescription* current_description) const;

File diff suppressed because it is too large Load Diff

View File

@ -336,10 +336,17 @@ void WebRtcSessionDescriptionFactory::InternalCreateOffer(
}
}
cricket::SessionDescription* desc(session_desc_factory_.CreateOffer(
request.options, pc_->local_description()
? pc_->local_description()->description()
: nullptr));
std::unique_ptr<cricket::SessionDescription> desc =
session_desc_factory_.CreateOffer(
request.options, pc_->local_description()
? pc_->local_description()->description()
: nullptr);
if (!desc) {
PostCreateSessionDescriptionFailed(request.observer,
"Failed to initialize the offer.");
return;
}
// RFC 3264
// When issuing an offer that modifies the session,
// the "o=" line of the new SDP MUST be identical to that in the
@ -350,13 +357,9 @@ void WebRtcSessionDescriptionFactory::InternalCreateOffer(
// is created regardless if it's identical to the previous one or not.
// The |session_version_| is a uint64_t, the wrap around should not happen.
RTC_DCHECK(session_version_ + 1 > session_version_);
auto offer = absl::make_unique<JsepSessionDescription>(SdpType::kOffer);
if (!offer->Initialize(desc, session_id_,
rtc::ToString(session_version_++))) {
PostCreateSessionDescriptionFailed(request.observer,
"Failed to initialize the offer.");
return;
}
auto offer = absl::make_unique<JsepSessionDescription>(
SdpType::kOffer, std::move(desc), session_id_,
rtc::ToString(session_version_++));
if (pc_->local_description()) {
for (const cricket::MediaDescriptionOptions& options :
request.options.media_description_options) {
@ -389,12 +392,19 @@ void WebRtcSessionDescriptionFactory::InternalCreateAnswer(
}
}
cricket::SessionDescription* desc(session_desc_factory_.CreateAnswer(
pc_->remote_description() ? pc_->remote_description()->description()
: nullptr,
request.options,
pc_->local_description() ? pc_->local_description()->description()
: nullptr));
std::unique_ptr<cricket::SessionDescription> desc =
session_desc_factory_.CreateAnswer(
pc_->remote_description() ? pc_->remote_description()->description()
: nullptr,
request.options,
pc_->local_description() ? pc_->local_description()->description()
: nullptr);
if (!desc) {
PostCreateSessionDescriptionFailed(request.observer,
"Failed to initialize the answer.");
return;
}
// RFC 3264
// If the answer is different from the offer in any way (different IP
// addresses, ports, etc.), the origin line MUST be different in the answer.
@ -403,13 +413,9 @@ void WebRtcSessionDescriptionFactory::InternalCreateAnswer(
// Get a new version number by increasing the |session_version_answer_|.
// The |session_version_| is a uint64_t, the wrap around should not happen.
RTC_DCHECK(session_version_ + 1 > session_version_);
auto answer = absl::make_unique<JsepSessionDescription>(SdpType::kAnswer);
if (!answer->Initialize(desc, session_id_,
rtc::ToString(session_version_++))) {
PostCreateSessionDescriptionFailed(request.observer,
"Failed to initialize the answer.");
return;
}
auto answer = absl::make_unique<JsepSessionDescription>(
SdpType::kAnswer, std::move(desc), session_id_,
rtc::ToString(session_version_++));
if (pc_->local_description()) {
// Include all local ICE candidates in the SessionDescription unless
// the remote peer has requested an ICE restart.