Use unique_ptr in webrtcsdp.cc
Bug: None Change-Id: I68c1d1bbde928667b215340e2b1a6133b344d179 Reviewed-on: https://webrtc-review.googlesource.com/c/114907 Reviewed-by: Amit Hilbuch <amithi@webrtc.org> Commit-Queue: Steve Anton <steveanton@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26052}
This commit is contained in:
118
pc/webrtcsdp.cc
118
pc/webrtcsdp.cc
@ -23,6 +23,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/memory/memory.h"
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
#include "api/candidate.h"
|
#include "api/candidate.h"
|
||||||
#include "api/cryptoparams.h"
|
#include "api/cryptoparams.h"
|
||||||
@ -296,21 +297,22 @@ static bool ParseMediaDescription(
|
|||||||
size_t* pos,
|
size_t* pos,
|
||||||
const rtc::SocketAddress& session_connection_addr,
|
const rtc::SocketAddress& session_connection_addr,
|
||||||
cricket::SessionDescription* desc,
|
cricket::SessionDescription* desc,
|
||||||
std::vector<JsepIceCandidate*>* candidates,
|
std::vector<std::unique_ptr<JsepIceCandidate>>* candidates,
|
||||||
|
SdpParseError* error);
|
||||||
|
static bool ParseContent(
|
||||||
|
const std::string& message,
|
||||||
|
const cricket::MediaType media_type,
|
||||||
|
int mline_index,
|
||||||
|
const std::string& protocol,
|
||||||
|
const std::vector<int>& payload_types,
|
||||||
|
size_t* pos,
|
||||||
|
std::string* content_name,
|
||||||
|
bool* bundle_only,
|
||||||
|
int* msid_signaling,
|
||||||
|
MediaContentDescription* media_desc,
|
||||||
|
TransportDescription* transport,
|
||||||
|
std::vector<std::unique_ptr<JsepIceCandidate>>* candidates,
|
||||||
SdpParseError* error);
|
SdpParseError* error);
|
||||||
static bool ParseContent(const std::string& message,
|
|
||||||
const cricket::MediaType media_type,
|
|
||||||
int mline_index,
|
|
||||||
const std::string& protocol,
|
|
||||||
const std::vector<int>& payload_types,
|
|
||||||
size_t* pos,
|
|
||||||
std::string* content_name,
|
|
||||||
bool* bundle_only,
|
|
||||||
int* msid_signaling,
|
|
||||||
MediaContentDescription* media_desc,
|
|
||||||
TransportDescription* transport,
|
|
||||||
std::vector<JsepIceCandidate*>* candidates,
|
|
||||||
SdpParseError* error);
|
|
||||||
static bool ParseSsrcAttribute(const std::string& line,
|
static bool ParseSsrcAttribute(const std::string& line,
|
||||||
SsrcInfoVec* ssrc_infos,
|
SsrcInfoVec* ssrc_infos,
|
||||||
int* msid_signaling,
|
int* msid_signaling,
|
||||||
@ -957,34 +959,28 @@ bool SdpDeserialize(const std::string& message,
|
|||||||
TransportDescription session_td("", "");
|
TransportDescription session_td("", "");
|
||||||
RtpHeaderExtensions session_extmaps;
|
RtpHeaderExtensions session_extmaps;
|
||||||
rtc::SocketAddress session_connection_addr;
|
rtc::SocketAddress session_connection_addr;
|
||||||
cricket::SessionDescription* desc = new cricket::SessionDescription();
|
auto desc = absl::make_unique<cricket::SessionDescription>();
|
||||||
std::vector<JsepIceCandidate*> candidates;
|
|
||||||
size_t current_pos = 0;
|
size_t current_pos = 0;
|
||||||
|
|
||||||
// Session Description
|
// Session Description
|
||||||
if (!ParseSessionDescription(message, ¤t_pos, &session_id,
|
if (!ParseSessionDescription(message, ¤t_pos, &session_id,
|
||||||
&session_version, &session_td, &session_extmaps,
|
&session_version, &session_td, &session_extmaps,
|
||||||
&session_connection_addr, desc, error)) {
|
&session_connection_addr, desc.get(), error)) {
|
||||||
delete desc;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Media Description
|
// Media Description
|
||||||
|
std::vector<std::unique_ptr<JsepIceCandidate>> candidates;
|
||||||
if (!ParseMediaDescription(message, session_td, session_extmaps, ¤t_pos,
|
if (!ParseMediaDescription(message, session_td, session_extmaps, ¤t_pos,
|
||||||
session_connection_addr, desc, &candidates,
|
session_connection_addr, desc.get(), &candidates,
|
||||||
error)) {
|
error)) {
|
||||||
delete desc;
|
|
||||||
for (JsepIceCandidate* candidate : candidates) {
|
|
||||||
delete candidate;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
jdesc->Initialize(desc, session_id, session_version);
|
jdesc->Initialize(desc.release(), session_id, session_version);
|
||||||
|
|
||||||
for (JsepIceCandidate* candidate : candidates) {
|
for (const auto& candidate : candidates) {
|
||||||
jdesc->AddCandidate(candidate);
|
jdesc->AddCandidate(candidate.get());
|
||||||
delete candidate;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2540,19 +2536,20 @@ void MaybeCreateStaticPayloadAudioCodecs(const std::vector<int>& fmts,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class C>
|
template <class C>
|
||||||
static C* ParseContentDescription(const std::string& message,
|
static std::unique_ptr<C> ParseContentDescription(
|
||||||
const cricket::MediaType media_type,
|
const std::string& message,
|
||||||
int mline_index,
|
const cricket::MediaType media_type,
|
||||||
const std::string& protocol,
|
int mline_index,
|
||||||
const std::vector<int>& payload_types,
|
const std::string& protocol,
|
||||||
size_t* pos,
|
const std::vector<int>& payload_types,
|
||||||
std::string* content_name,
|
size_t* pos,
|
||||||
bool* bundle_only,
|
std::string* content_name,
|
||||||
int* msid_signaling,
|
bool* bundle_only,
|
||||||
TransportDescription* transport,
|
int* msid_signaling,
|
||||||
std::vector<JsepIceCandidate*>* candidates,
|
TransportDescription* transport,
|
||||||
webrtc::SdpParseError* error) {
|
std::vector<std::unique_ptr<JsepIceCandidate>>* candidates,
|
||||||
C* media_desc = new C();
|
webrtc::SdpParseError* error) {
|
||||||
|
auto media_desc = absl::make_unique<C>();
|
||||||
switch (media_type) {
|
switch (media_type) {
|
||||||
case cricket::MEDIA_TYPE_AUDIO:
|
case cricket::MEDIA_TYPE_AUDIO:
|
||||||
*content_name = cricket::CN_AUDIO;
|
*content_name = cricket::CN_AUDIO;
|
||||||
@ -2568,9 +2565,8 @@ static C* ParseContentDescription(const std::string& message,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!ParseContent(message, media_type, mline_index, protocol, payload_types,
|
if (!ParseContent(message, media_type, mline_index, protocol, payload_types,
|
||||||
pos, content_name, bundle_only, msid_signaling, media_desc,
|
pos, content_name, bundle_only, msid_signaling,
|
||||||
transport, candidates, error)) {
|
media_desc.get(), transport, candidates, error)) {
|
||||||
delete media_desc;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
// Sort the codecs according to the m-line fmt list.
|
// Sort the codecs according to the m-line fmt list.
|
||||||
@ -2593,14 +2589,15 @@ static C* ParseContentDescription(const std::string& message,
|
|||||||
return media_desc;
|
return media_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParseMediaDescription(const std::string& message,
|
bool ParseMediaDescription(
|
||||||
const TransportDescription& session_td,
|
const std::string& message,
|
||||||
const RtpHeaderExtensions& session_extmaps,
|
const TransportDescription& session_td,
|
||||||
size_t* pos,
|
const RtpHeaderExtensions& session_extmaps,
|
||||||
const rtc::SocketAddress& session_connection_addr,
|
size_t* pos,
|
||||||
cricket::SessionDescription* desc,
|
const rtc::SocketAddress& session_connection_addr,
|
||||||
std::vector<JsepIceCandidate*>* candidates,
|
cricket::SessionDescription* desc,
|
||||||
SdpParseError* error) {
|
std::vector<std::unique_ptr<JsepIceCandidate>>* candidates,
|
||||||
|
SdpParseError* error) {
|
||||||
RTC_DCHECK(desc != NULL);
|
RTC_DCHECK(desc != NULL);
|
||||||
std::string line;
|
std::string line;
|
||||||
int mline_index = -1;
|
int mline_index = -1;
|
||||||
@ -2663,33 +2660,34 @@ bool ParseMediaDescription(const std::string& message,
|
|||||||
bool bundle_only = false;
|
bool bundle_only = false;
|
||||||
int section_msid_signaling = 0;
|
int section_msid_signaling = 0;
|
||||||
if (HasAttribute(line, kMediaTypeVideo)) {
|
if (HasAttribute(line, kMediaTypeVideo)) {
|
||||||
content.reset(ParseContentDescription<VideoContentDescription>(
|
content = ParseContentDescription<VideoContentDescription>(
|
||||||
message, cricket::MEDIA_TYPE_VIDEO, mline_index, protocol,
|
message, cricket::MEDIA_TYPE_VIDEO, mline_index, protocol,
|
||||||
payload_types, pos, &content_name, &bundle_only,
|
payload_types, pos, &content_name, &bundle_only,
|
||||||
§ion_msid_signaling, &transport, candidates, error));
|
§ion_msid_signaling, &transport, candidates, error);
|
||||||
} else if (HasAttribute(line, kMediaTypeAudio)) {
|
} else if (HasAttribute(line, kMediaTypeAudio)) {
|
||||||
content.reset(ParseContentDescription<AudioContentDescription>(
|
content = ParseContentDescription<AudioContentDescription>(
|
||||||
message, cricket::MEDIA_TYPE_AUDIO, mline_index, protocol,
|
message, cricket::MEDIA_TYPE_AUDIO, mline_index, protocol,
|
||||||
payload_types, pos, &content_name, &bundle_only,
|
payload_types, pos, &content_name, &bundle_only,
|
||||||
§ion_msid_signaling, &transport, candidates, error));
|
§ion_msid_signaling, &transport, candidates, error);
|
||||||
} else if (HasAttribute(line, kMediaTypeData)) {
|
} else if (HasAttribute(line, kMediaTypeData)) {
|
||||||
DataContentDescription* data_desc =
|
std::unique_ptr<DataContentDescription> data_desc =
|
||||||
ParseContentDescription<DataContentDescription>(
|
ParseContentDescription<DataContentDescription>(
|
||||||
message, cricket::MEDIA_TYPE_DATA, mline_index, protocol,
|
message, cricket::MEDIA_TYPE_DATA, mline_index, protocol,
|
||||||
payload_types, pos, &content_name, &bundle_only,
|
payload_types, pos, &content_name, &bundle_only,
|
||||||
§ion_msid_signaling, &transport, candidates, error);
|
§ion_msid_signaling, &transport, candidates, error);
|
||||||
content.reset(data_desc);
|
|
||||||
|
|
||||||
if (data_desc && IsDtlsSctp(protocol)) {
|
if (data_desc && IsDtlsSctp(protocol)) {
|
||||||
int p;
|
int p;
|
||||||
if (rtc::FromString(fields[3], &p)) {
|
if (rtc::FromString(fields[3], &p)) {
|
||||||
if (!AddSctpDataCodec(data_desc, p)) {
|
if (!AddSctpDataCodec(data_desc.get(), p)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (fields[3] == kDefaultSctpmapProtocol) {
|
} else if (fields[3] == kDefaultSctpmapProtocol) {
|
||||||
data_desc->set_use_sctpmap(false);
|
data_desc->set_use_sctpmap(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content = std::move(data_desc);
|
||||||
} else {
|
} else {
|
||||||
RTC_LOG(LS_WARNING) << "Unsupported media type: " << line;
|
RTC_LOG(LS_WARNING) << "Unsupported media type: " << line;
|
||||||
continue;
|
continue;
|
||||||
@ -2917,7 +2915,7 @@ bool ParseContent(const std::string& message,
|
|||||||
int* msid_signaling,
|
int* msid_signaling,
|
||||||
MediaContentDescription* media_desc,
|
MediaContentDescription* media_desc,
|
||||||
TransportDescription* transport,
|
TransportDescription* transport,
|
||||||
std::vector<JsepIceCandidate*>* candidates,
|
std::vector<std::unique_ptr<JsepIceCandidate>>* candidates,
|
||||||
SdpParseError* error) {
|
SdpParseError* error) {
|
||||||
RTC_DCHECK(media_desc != NULL);
|
RTC_DCHECK(media_desc != NULL);
|
||||||
RTC_DCHECK(content_name != NULL);
|
RTC_DCHECK(content_name != NULL);
|
||||||
@ -3309,7 +3307,7 @@ bool ParseContent(const std::string& message,
|
|||||||
RTC_DCHECK(candidate.password().empty());
|
RTC_DCHECK(candidate.password().empty());
|
||||||
candidate.set_password(transport->ice_pwd);
|
candidate.set_password(transport->ice_pwd);
|
||||||
candidates->push_back(
|
candidates->push_back(
|
||||||
new JsepIceCandidate(mline_id, mline_index, candidate));
|
absl::make_unique<JsepIceCandidate>(mline_id, mline_index, candidate));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user