Use string_view for a few more sdp-related functions

Bug: webrtc:13579
Change-Id: I536bb2b2dbe8e1eb00b7ad4637faa7e08ff849ed
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/231127
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Ali Tofigh <alito@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36836}
This commit is contained in:
Niels Möller
2022-05-10 12:39:29 +02:00
committed by WebRTC LUCI CQ
parent 7ee45945da
commit e34291fed9
2 changed files with 98 additions and 100 deletions

View File

@ -289,7 +289,7 @@ static void BuildCandidate(const std::vector<Candidate>& candidates,
std::string* message); std::string* message);
static void BuildIceOptions(const std::vector<std::string>& transport_options, static void BuildIceOptions(const std::vector<std::string>& transport_options,
std::string* message); std::string* message);
static bool ParseSessionDescription(const std::string& message, static bool ParseSessionDescription(absl::string_view message,
size_t* pos, size_t* pos,
std::string* session_id, std::string* session_id,
std::string* session_version, std::string* session_version,
@ -299,7 +299,7 @@ static bool ParseSessionDescription(const std::string& message,
cricket::SessionDescription* desc, cricket::SessionDescription* desc,
SdpParseError* error); SdpParseError* error);
static bool ParseMediaDescription( static bool ParseMediaDescription(
const std::string& message, absl::string_view message,
const TransportDescription& session_td, const TransportDescription& session_td,
const RtpHeaderExtensions& session_extmaps, const RtpHeaderExtensions& session_extmaps,
size_t* pos, size_t* pos,
@ -308,10 +308,10 @@ static bool ParseMediaDescription(
std::vector<std::unique_ptr<JsepIceCandidate>>* candidates, std::vector<std::unique_ptr<JsepIceCandidate>>* candidates,
SdpParseError* error); SdpParseError* error);
static bool ParseContent( static bool ParseContent(
const std::string& message, absl::string_view message,
const cricket::MediaType media_type, const cricket::MediaType media_type,
int mline_index, int mline_index,
const std::string& protocol, absl::string_view protocol,
const std::vector<int>& payload_types, const std::vector<int>& payload_types,
size_t* pos, size_t* pos,
std::string* content_name, std::string* content_name,
@ -321,25 +321,25 @@ static bool ParseContent(
TransportDescription* transport, TransportDescription* transport,
std::vector<std::unique_ptr<JsepIceCandidate>>* candidates, std::vector<std::unique_ptr<JsepIceCandidate>>* candidates,
SdpParseError* error); SdpParseError* error);
static bool ParseGroupAttribute(const std::string& line, static bool ParseGroupAttribute(absl::string_view line,
cricket::SessionDescription* desc, cricket::SessionDescription* desc,
SdpParseError* error); SdpParseError* error);
static bool ParseSsrcAttribute(const std::string& line, static bool ParseSsrcAttribute(absl::string_view line,
SsrcInfoVec* ssrc_infos, SsrcInfoVec* ssrc_infos,
int* msid_signaling, int* msid_signaling,
SdpParseError* error); SdpParseError* error);
static bool ParseSsrcGroupAttribute(const std::string& line, static bool ParseSsrcGroupAttribute(absl::string_view line,
SsrcGroupVec* ssrc_groups, SsrcGroupVec* ssrc_groups,
SdpParseError* error); SdpParseError* error);
static bool ParseCryptoAttribute(const std::string& line, static bool ParseCryptoAttribute(absl::string_view line,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error); SdpParseError* error);
static bool ParseRtpmapAttribute(const std::string& line, static bool ParseRtpmapAttribute(absl::string_view line,
const cricket::MediaType media_type, const cricket::MediaType media_type,
const std::vector<int>& payload_types, const std::vector<int>& payload_types,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error); SdpParseError* error);
static bool ParseFmtpAttributes(const std::string& line, static bool ParseFmtpAttributes(absl::string_view line,
const cricket::MediaType media_type, const cricket::MediaType media_type,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error); SdpParseError* error);
@ -347,28 +347,28 @@ static bool ParseFmtpParam(absl::string_view line,
std::string* parameter, std::string* parameter,
std::string* value, std::string* value,
SdpParseError* error); SdpParseError* error);
static bool ParsePacketizationAttribute(const std::string& line, static bool ParsePacketizationAttribute(absl::string_view line,
const cricket::MediaType media_type, const cricket::MediaType media_type,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error); SdpParseError* error);
static bool ParseRtcpFbAttribute(const std::string& line, static bool ParseRtcpFbAttribute(absl::string_view line,
const cricket::MediaType media_type, const cricket::MediaType media_type,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error); SdpParseError* error);
static bool ParseIceOptions(const std::string& line, static bool ParseIceOptions(absl::string_view line,
std::vector<std::string>* transport_options, std::vector<std::string>* transport_options,
SdpParseError* error); SdpParseError* error);
static bool ParseExtmap(const std::string& line, static bool ParseExtmap(absl::string_view line,
RtpExtension* extmap, RtpExtension* extmap,
SdpParseError* error); SdpParseError* error);
static bool ParseFingerprintAttribute( static bool ParseFingerprintAttribute(
const std::string& line, absl::string_view line,
std::unique_ptr<rtc::SSLFingerprint>* fingerprint, std::unique_ptr<rtc::SSLFingerprint>* fingerprint,
SdpParseError* error); SdpParseError* error);
static bool ParseDtlsSetup(const std::string& line, static bool ParseDtlsSetup(absl::string_view line,
cricket::ConnectionRole* role, cricket::ConnectionRole* role,
SdpParseError* error); SdpParseError* error);
static bool ParseMsidAttribute(const std::string& line, static bool ParseMsidAttribute(absl::string_view line,
std::vector<std::string>* stream_ids, std::vector<std::string>* stream_ids,
std::string* track_id, std::string* track_id,
SdpParseError* error); SdpParseError* error);
@ -459,7 +459,7 @@ static bool ParseFailedExpectMinFieldNum(absl::string_view line,
// `line` is the failing line. The failure is due to the fact that it failed to // `line` is the failing line. The failure is due to the fact that it failed to
// get the value of `attribute`. // get the value of `attribute`.
static bool ParseFailedGetValue(absl::string_view line, static bool ParseFailedGetValue(absl::string_view line,
const std::string& attribute, absl::string_view attribute,
SdpParseError* error) { SdpParseError* error) {
rtc::StringBuilder description; rtc::StringBuilder description;
description << "Failed to get the value of attribute: " << attribute; description << "Failed to get the value of attribute: " << attribute;
@ -481,21 +481,19 @@ static bool ParseFailedExpectLine(absl::string_view message,
return ParseFailed(message, line_start, description.Release(), error); return ParseFailed(message, line_start, description.Release(), error);
} }
static bool AddLine(const std::string& line, std::string* message) { static bool AddLine(absl::string_view line, std::string* message) {
if (!message) if (!message)
return false; return false;
message->append(line); message->append(line.data(), line.size());
message->append(kLineBreak); message->append(kLineBreak);
return true; return true;
} }
static bool GetLine(const std::string& message, static bool GetLine(absl::string_view message, size_t* pos, std::string* line) {
size_t* pos,
std::string* line) {
size_t line_begin = *pos; size_t line_begin = *pos;
size_t line_end = message.find(kNewLine, line_begin); size_t line_end = message.find(kNewLine, line_begin);
if (line_end == std::string::npos) { if (line_end == absl::string_view::npos) {
return false; return false;
} }
// Update the new start position // Update the new start position
@ -503,7 +501,7 @@ static bool GetLine(const std::string& message,
if (line_end > 0 && (message.at(line_end - 1) == kReturnChar)) { if (line_end > 0 && (message.at(line_end - 1) == kReturnChar)) {
--line_end; --line_end;
} }
*line = message.substr(line_begin, (line_end - line_begin)); *line = std::string(message.substr(line_begin, (line_end - line_begin)));
const char* cline = line->c_str(); const char* cline = line->c_str();
// RFC 4566 // RFC 4566
// An SDP session description consists of a number of lines of text of // An SDP session description consists of a number of lines of text of
@ -530,19 +528,19 @@ static bool GetLine(const std::string& message,
// Init `os` to "`type`=`value`". // Init `os` to "`type`=`value`".
static void InitLine(const char type, static void InitLine(const char type,
const std::string& value, absl::string_view value,
rtc::StringBuilder* os) { rtc::StringBuilder* os) {
os->Clear(); os->Clear();
*os << std::string(1, type) << kSdpDelimiterEqual << value; *os << std::string(1, type) << kSdpDelimiterEqual << value;
} }
// Init `os` to "a=`attribute`". // Init `os` to "a=`attribute`".
static void InitAttrLine(const std::string& attribute, rtc::StringBuilder* os) { static void InitAttrLine(absl::string_view attribute, rtc::StringBuilder* os) {
InitLine(kLineTypeAttributes, attribute, os); InitLine(kLineTypeAttributes, attribute, os);
} }
// Writes a SDP attribute line based on `attribute` and `value` to `message`. // Writes a SDP attribute line based on `attribute` and `value` to `message`.
static void AddAttributeLine(const std::string& attribute, static void AddAttributeLine(absl::string_view attribute,
int value, int value,
std::string* message) { std::string* message) {
rtc::StringBuilder os; rtc::StringBuilder os;
@ -551,22 +549,21 @@ static void AddAttributeLine(const std::string& attribute,
AddLine(os.str(), message); AddLine(os.str(), message);
} }
static bool IsLineType(const std::string& message, static bool IsLineType(absl::string_view message,
const char type, const char type,
size_t line_start) { size_t line_start) {
if (message.size() < line_start + kLinePrefixLength) { if (message.size() < line_start + kLinePrefixLength) {
return false; return false;
} }
const char* cmessage = message.c_str(); return (message[line_start] == type &&
return (cmessage[line_start] == type && message[line_start + 1] == kSdpDelimiterEqualChar);
cmessage[line_start + 1] == kSdpDelimiterEqualChar);
} }
static bool IsLineType(const std::string& line, const char type) { static bool IsLineType(absl::string_view line, const char type) {
return IsLineType(line, type, 0); return IsLineType(line, type, 0);
} }
static bool GetLineWithType(const std::string& message, static bool GetLineWithType(absl::string_view message,
size_t* pos, size_t* pos,
std::string* line, std::string* line,
const char type) { const char type) {
@ -580,8 +577,7 @@ static bool GetLineWithType(const std::string& message,
return true; return true;
} }
static bool HasAttribute(const std::string& line, static bool HasAttribute(absl::string_view line, absl::string_view attribute) {
const std::string& attribute) {
if (line.compare(kLinePrefixLength, attribute.size(), attribute) == 0) { if (line.compare(kLinePrefixLength, attribute.size(), attribute) == 0) {
// Make sure that the match is not only a partial match. If length of // Make sure that the match is not only a partial match. If length of
// strings doesn't match, the next character of the line must be ':' or ' '. // strings doesn't match, the next character of the line must be ':' or ' '.
@ -598,8 +594,8 @@ static bool HasAttribute(const std::string& line,
} }
static bool AddSsrcLine(uint32_t ssrc_id, static bool AddSsrcLine(uint32_t ssrc_id,
const std::string& attribute, absl::string_view attribute,
const std::string& value, absl::string_view value,
std::string* message) { std::string* message) {
// RFC 5576 // RFC 5576
// a=ssrc:<ssrc-id> <attribute>:<value> // a=ssrc:<ssrc-id> <attribute>:<value>
@ -611,8 +607,8 @@ static bool AddSsrcLine(uint32_t ssrc_id,
} }
// Get value only from <attribute>:<value>. // Get value only from <attribute>:<value>.
static bool GetValue(const std::string& message, static bool GetValue(absl::string_view message,
const std::string& attribute, absl::string_view attribute,
std::string* value, std::string* value,
SdpParseError* error) { SdpParseError* error) {
std::string leftpart; std::string leftpart;
@ -621,16 +617,17 @@ static bool GetValue(const std::string& message,
} }
// The left part should end with the expected attribute. // The left part should end with the expected attribute.
if (leftpart.length() < attribute.length() || if (leftpart.length() < attribute.length() ||
leftpart.compare(leftpart.length() - attribute.length(), absl::string_view(leftpart).compare(
attribute.length(), attribute) != 0) { leftpart.length() - attribute.length(), attribute.length(),
attribute) != 0) {
return ParseFailedGetValue(message, attribute, error); return ParseFailedGetValue(message, attribute, error);
} }
return true; return true;
} }
// Get a single [token] from <attribute>:<token> // Get a single [token] from <attribute>:<token>
static bool GetSingleTokenValue(const std::string& message, static bool GetSingleTokenValue(absl::string_view message,
const std::string& attribute, absl::string_view attribute,
std::string* value, std::string* value,
SdpParseError* error) { SdpParseError* error) {
if (!GetValue(message, attribute, value, error)) { if (!GetValue(message, attribute, value, error)) {
@ -651,8 +648,8 @@ static bool CaseInsensitiveFind(std::string str1, std::string str2) {
} }
template <class T> template <class T>
static bool GetValueFromString(const std::string& line, static bool GetValueFromString(absl::string_view line,
const std::string& s, absl::string_view s,
T* t, T* t,
SdpParseError* error) { SdpParseError* error) {
if (!rtc::FromString(s, t)) { if (!rtc::FromString(s, t)) {
@ -663,8 +660,8 @@ static bool GetValueFromString(const std::string& line,
return true; return true;
} }
static bool GetPayloadTypeFromString(const std::string& line, static bool GetPayloadTypeFromString(absl::string_view line,
const std::string& s, absl::string_view s,
int* payload_type, int* payload_type,
SdpParseError* error) { SdpParseError* error) {
return GetValueFromString(line, s, payload_type, error) && return GetValueFromString(line, s, payload_type, error) &&
@ -675,7 +672,7 @@ static bool GetPayloadTypeFromString(const std::string& line,
// This is a track that does not contain SSRCs and only contains // This is a track that does not contain SSRCs and only contains
// stream_ids/track_id if it's signaled with a=msid lines. // stream_ids/track_id if it's signaled with a=msid lines.
void CreateTrackWithNoSsrcs(const std::vector<std::string>& msid_stream_ids, void CreateTrackWithNoSsrcs(const std::vector<std::string>& msid_stream_ids,
const std::string& msid_track_id, absl::string_view msid_track_id,
const std::vector<RidDescription>& rids, const std::vector<RidDescription>& rids,
StreamParamsVec* tracks) { StreamParamsVec* tracks) {
StreamParams track; StreamParams track;
@ -685,7 +682,7 @@ void CreateTrackWithNoSsrcs(const std::vector<std::string>& msid_stream_ids,
return; return;
} }
track.set_stream_ids(msid_stream_ids); track.set_stream_ids(msid_stream_ids);
track.id = msid_track_id; track.id = std::string(msid_track_id);
track.set_rids(rids); track.set_rids(rids);
tracks->push_back(track); tracks->push_back(track);
} }
@ -696,7 +693,7 @@ void CreateTrackWithNoSsrcs(const std::vector<std::string>& msid_stream_ids,
// exist. We prioritize getting stream_ids/track_ids signaled in a=msid lines. // exist. We prioritize getting stream_ids/track_ids signaled in a=msid lines.
void CreateTracksFromSsrcInfos(const SsrcInfoVec& ssrc_infos, void CreateTracksFromSsrcInfos(const SsrcInfoVec& ssrc_infos,
const std::vector<std::string>& msid_stream_ids, const std::vector<std::string>& msid_stream_ids,
const std::string& msid_track_id, absl::string_view msid_track_id,
StreamParamsVec* tracks, StreamParamsVec* tracks,
int msid_signaling) { int msid_signaling) {
RTC_DCHECK(tracks != NULL); RTC_DCHECK(tracks != NULL);
@ -712,7 +709,7 @@ void CreateTracksFromSsrcInfos(const SsrcInfoVec& ssrc_infos,
if (msid_signaling & cricket::kMsidSignalingMediaSection) { if (msid_signaling & cricket::kMsidSignalingMediaSection) {
// This is the case with Unified Plan SDP msid signaling. // This is the case with Unified Plan SDP msid signaling.
stream_ids = msid_stream_ids; stream_ids = msid_stream_ids;
track_id = msid_track_id; track_id = std::string(msid_track_id);
} else if (msid_signaling & cricket::kMsidSignalingSsrcAttribute) { } else if (msid_signaling & cricket::kMsidSignalingSsrcAttribute) {
// This is the case with Plan B SDP msid signaling. // This is the case with Plan B SDP msid signaling.
stream_ids.push_back(ssrc_info.stream_id); stream_ids.push_back(ssrc_info.stream_id);
@ -765,7 +762,7 @@ static const int kPreferenceHost = 1;
static const int kPreferenceReflexive = 2; static const int kPreferenceReflexive = 2;
static const int kPreferenceRelayed = 3; static const int kPreferenceRelayed = 3;
static int GetCandidatePreferenceFromType(const std::string& type) { static int GetCandidatePreferenceFromType(absl::string_view type) {
int preference = kPreferenceUnknown; int preference = kPreferenceUnknown;
if (type == cricket::LOCAL_PORT_TYPE) { if (type == cricket::LOCAL_PORT_TYPE) {
preference = kPreferenceHost; preference = kPreferenceHost;
@ -977,7 +974,7 @@ std::string SdpSerializeCandidate(const cricket::Candidate& candidate) {
return message; return message;
} }
bool SdpDeserialize(const std::string& message, bool SdpDeserialize(absl::string_view message,
JsepSessionDescription* jdesc, JsepSessionDescription* jdesc,
SdpParseError* error) { SdpParseError* error) {
std::string session_id; std::string session_id;
@ -1011,7 +1008,7 @@ bool SdpDeserialize(const std::string& message,
return true; return true;
} }
bool SdpDeserializeCandidate(const std::string& message, bool SdpDeserializeCandidate(absl::string_view message,
JsepIceCandidate* jcandidate, JsepIceCandidate* jcandidate,
SdpParseError* error) { SdpParseError* error) {
RTC_DCHECK(jcandidate != NULL); RTC_DCHECK(jcandidate != NULL);
@ -1023,8 +1020,8 @@ bool SdpDeserializeCandidate(const std::string& message,
return true; return true;
} }
bool SdpDeserializeCandidate(const std::string& transport_name, bool SdpDeserializeCandidate(absl::string_view transport_name,
const std::string& message, absl::string_view message,
cricket::Candidate* candidate, cricket::Candidate* candidate,
SdpParseError* error) { SdpParseError* error) {
RTC_DCHECK(candidate != nullptr); RTC_DCHECK(candidate != nullptr);
@ -1035,14 +1032,14 @@ bool SdpDeserializeCandidate(const std::string& transport_name,
return true; return true;
} }
bool ParseCandidate(const std::string& message, bool ParseCandidate(absl::string_view message,
Candidate* candidate, Candidate* candidate,
SdpParseError* error, SdpParseError* error,
bool is_raw) { bool is_raw) {
RTC_DCHECK(candidate != NULL); RTC_DCHECK(candidate != NULL);
// Get the first line from `message`. // Get the first line from `message`.
std::string first_line = message; std::string first_line = std::string(message);
size_t pos = 0; size_t pos = 0;
GetLine(message, &pos, &first_line); GetLine(message, &pos, &first_line);
@ -1237,7 +1234,7 @@ bool ParseCandidate(const std::string& message,
return true; return true;
} }
bool ParseIceOptions(const std::string& line, bool ParseIceOptions(absl::string_view line,
std::vector<std::string>* transport_options, std::vector<std::string>* transport_options,
SdpParseError* error) { SdpParseError* error) {
std::string ice_options; std::string ice_options;
@ -1252,7 +1249,7 @@ bool ParseIceOptions(const std::string& line,
return true; return true;
} }
bool ParseSctpPort(const std::string& line, bool ParseSctpPort(absl::string_view line,
int* sctp_port, int* sctp_port,
SdpParseError* error) { SdpParseError* error) {
// draft-ietf-mmusic-sctp-sdp-26 // draft-ietf-mmusic-sctp-sdp-26
@ -1273,7 +1270,7 @@ bool ParseSctpPort(const std::string& line,
return true; return true;
} }
bool ParseSctpMaxMessageSize(const std::string& line, bool ParseSctpMaxMessageSize(absl::string_view line,
int* max_message_size, int* max_message_size,
SdpParseError* error) { SdpParseError* error) {
// draft-ietf-mmusic-sctp-sdp-26 // draft-ietf-mmusic-sctp-sdp-26
@ -1290,7 +1287,7 @@ bool ParseSctpMaxMessageSize(const std::string& line,
return true; return true;
} }
bool ParseExtmap(const std::string& line, bool ParseExtmap(absl::string_view line,
RtpExtension* extmap, RtpExtension* extmap,
SdpParseError* error) { SdpParseError* error) {
// RFC 5285 // RFC 5285
@ -1787,10 +1784,10 @@ void WriteRtcpFbHeader(int payload_type, rtc::StringBuilder* os) {
} }
} }
void WriteFmtpParameter(const std::string& parameter_name, void WriteFmtpParameter(absl::string_view parameter_name,
const std::string& parameter_value, absl::string_view parameter_value,
rtc::StringBuilder* os) { rtc::StringBuilder* os) {
if (parameter_name == "") { if (parameter_name.empty()) {
// RFC 2198 and RFC 4733 don't use key-value pairs. // RFC 2198 and RFC 4733 don't use key-value pairs.
*os << parameter_value; *os << parameter_value;
} else { } else {
@ -1799,7 +1796,7 @@ void WriteFmtpParameter(const std::string& parameter_name,
} }
} }
bool IsFmtpParam(const std::string& name) { bool IsFmtpParam(absl::string_view name) {
// RFC 4855, section 3 specifies the mapping of media format parameters to SDP // RFC 4855, section 3 specifies the mapping of media format parameters to SDP
// parameters. Only ptime, maxptime, channels and rate are placed outside of // parameters. Only ptime, maxptime, channels and rate are placed outside of
// the fmtp line. In WebRTC, channels and rate are already handled separately // the fmtp line. In WebRTC, channels and rate are already handled separately
@ -2040,7 +2037,7 @@ void BuildIceOptions(const std::vector<std::string>& transport_options,
} }
} }
bool ParseConnectionData(const std::string& line, bool ParseConnectionData(absl::string_view line,
rtc::SocketAddress* addr, rtc::SocketAddress* addr,
SdpParseError* error) { SdpParseError* error) {
// Parse the line from left to right. // Parse the line from left to right.
@ -2091,7 +2088,7 @@ bool ParseConnectionData(const std::string& line,
return true; return true;
} }
bool ParseSessionDescription(const std::string& message, bool ParseSessionDescription(absl::string_view message,
size_t* pos, size_t* pos,
std::string* session_id, std::string* session_id,
std::string* session_version, std::string* session_version,
@ -2253,7 +2250,7 @@ bool ParseSessionDescription(const std::string& message,
return true; return true;
} }
bool ParseGroupAttribute(const std::string& line, bool ParseGroupAttribute(absl::string_view line,
cricket::SessionDescription* desc, cricket::SessionDescription* desc,
SdpParseError* error) { SdpParseError* error) {
RTC_DCHECK(desc != NULL); RTC_DCHECK(desc != NULL);
@ -2275,7 +2272,7 @@ bool ParseGroupAttribute(const std::string& line,
} }
static bool ParseFingerprintAttribute( static bool ParseFingerprintAttribute(
const std::string& line, absl::string_view line,
std::unique_ptr<rtc::SSLFingerprint>* fingerprint, std::unique_ptr<rtc::SSLFingerprint>* fingerprint,
SdpParseError* error) { SdpParseError* error) {
std::vector<std::string> fields; std::vector<std::string> fields;
@ -2306,7 +2303,7 @@ static bool ParseFingerprintAttribute(
return true; return true;
} }
static bool ParseDtlsSetup(const std::string& line, static bool ParseDtlsSetup(absl::string_view line,
cricket::ConnectionRole* role, cricket::ConnectionRole* role,
SdpParseError* error) { SdpParseError* error) {
// setup-attr = "a=setup:" role // setup-attr = "a=setup:" role
@ -2324,7 +2321,7 @@ static bool ParseDtlsSetup(const std::string& line,
return true; return true;
} }
static bool ParseMsidAttribute(const std::string& line, static bool ParseMsidAttribute(absl::string_view line,
std::vector<std::string>* stream_ids, std::vector<std::string>* stream_ids,
std::string* track_id, std::string* track_id,
SdpParseError* error) { SdpParseError* error) {
@ -2562,10 +2559,10 @@ void MaybeCreateStaticPayloadAudioCodecs(const std::vector<int>& fmts,
template <class C> template <class C>
static std::unique_ptr<C> ParseContentDescription( static std::unique_ptr<C> ParseContentDescription(
const std::string& message, absl::string_view message,
const cricket::MediaType media_type, const cricket::MediaType media_type,
int mline_index, int mline_index,
const std::string& protocol, absl::string_view protocol,
const std::vector<int>& payload_types, const std::vector<int>& payload_types,
size_t* pos, size_t* pos,
std::string* content_name, std::string* content_name,
@ -2601,7 +2598,7 @@ static std::unique_ptr<C> ParseContentDescription(
} }
bool ParseMediaDescription( bool ParseMediaDescription(
const std::string& message, absl::string_view message,
const TransportDescription& session_td, const TransportDescription& session_td,
const RtpHeaderExtensions& session_extmaps, const RtpHeaderExtensions& session_extmaps,
size_t* pos, size_t* pos,
@ -2898,7 +2895,7 @@ void UpdateCodec(MediaContentDescription* content_desc,
// according to `packetization`. // according to `packetization`.
void UpdateVideoCodecPacketization(VideoContentDescription* video_desc, void UpdateVideoCodecPacketization(VideoContentDescription* video_desc,
int payload_type, int payload_type,
const std::string& packetization) { absl::string_view packetization) {
if (packetization != cricket::kPacketizationParamRaw) { if (packetization != cricket::kPacketizationParamRaw) {
// Ignore unsupported packetization attribute. // Ignore unsupported packetization attribute.
return; return;
@ -2907,7 +2904,7 @@ void UpdateVideoCodecPacketization(VideoContentDescription* video_desc,
// Codec might already have been populated (from rtpmap). // Codec might already have been populated (from rtpmap).
cricket::VideoCodec codec = cricket::VideoCodec codec =
GetCodecWithPayloadType(video_desc->codecs(), payload_type); GetCodecWithPayloadType(video_desc->codecs(), payload_type);
codec.packetization = packetization; codec.packetization = std::string(packetization);
AddOrReplaceCodec<VideoContentDescription, cricket::VideoCodec>(video_desc, AddOrReplaceCodec<VideoContentDescription, cricket::VideoCodec>(video_desc,
codec); codec);
} }
@ -2938,22 +2935,22 @@ void UpdateFromWildcardCodecs(cricket::MediaContentDescriptionImpl<T>* desc) {
} }
void AddAudioAttribute(const std::string& name, void AddAudioAttribute(const std::string& name,
const std::string& value, absl::string_view value,
AudioContentDescription* audio_desc) { AudioContentDescription* audio_desc) {
if (value.empty()) { if (value.empty()) {
return; return;
} }
std::vector<cricket::AudioCodec> codecs = audio_desc->codecs(); std::vector<cricket::AudioCodec> codecs = audio_desc->codecs();
for (cricket::AudioCodec& codec : codecs) { for (cricket::AudioCodec& codec : codecs) {
codec.params[name] = value; codec.params[name] = std::string(value);
} }
audio_desc->set_codecs(codecs); audio_desc->set_codecs(codecs);
} }
bool ParseContent(const std::string& message, bool ParseContent(absl::string_view message,
const cricket::MediaType media_type, const cricket::MediaType media_type,
int mline_index, int mline_index,
const std::string& protocol, absl::string_view protocol,
const std::vector<int>& payload_types, const std::vector<int>& payload_types,
size_t* pos, size_t* pos,
std::string* content_name, std::string* content_name,
@ -3379,7 +3376,7 @@ bool ParseContent(const std::string& message,
return true; return true;
} }
bool ParseSsrcAttribute(const std::string& line, bool ParseSsrcAttribute(absl::string_view line,
SsrcInfoVec* ssrc_infos, SsrcInfoVec* ssrc_infos,
int* msid_signaling, int* msid_signaling,
SdpParseError* error) { SdpParseError* error) {
@ -3453,7 +3450,7 @@ bool ParseSsrcAttribute(const std::string& line,
return true; return true;
} }
bool ParseSsrcGroupAttribute(const std::string& line, bool ParseSsrcGroupAttribute(absl::string_view line,
SsrcGroupVec* ssrc_groups, SsrcGroupVec* ssrc_groups,
SdpParseError* error) { SdpParseError* error) {
RTC_DCHECK(ssrc_groups != NULL); RTC_DCHECK(ssrc_groups != NULL);
@ -3481,7 +3478,7 @@ bool ParseSsrcGroupAttribute(const std::string& line,
return true; return true;
} }
bool ParseCryptoAttribute(const std::string& line, bool ParseCryptoAttribute(absl::string_view line,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error) { SdpParseError* error) {
std::vector<std::string> fields; std::vector<std::string> fields;
@ -3514,7 +3511,7 @@ bool ParseCryptoAttribute(const std::string& line,
// Updates or creates a new codec entry in the audio description with according // Updates or creates a new codec entry in the audio description with according
// to `name`, `clockrate`, `bitrate`, and `channels`. // to `name`, `clockrate`, `bitrate`, and `channels`.
void UpdateCodec(int payload_type, void UpdateCodec(int payload_type,
const std::string& name, absl::string_view name,
int clockrate, int clockrate,
int bitrate, int bitrate,
size_t channels, size_t channels,
@ -3523,7 +3520,7 @@ void UpdateCodec(int payload_type,
// (from an fmtp). // (from an fmtp).
cricket::AudioCodec codec = cricket::AudioCodec codec =
GetCodecWithPayloadType(audio_desc->codecs(), payload_type); GetCodecWithPayloadType(audio_desc->codecs(), payload_type);
codec.name = name; codec.name = std::string(name);
codec.clockrate = clockrate; codec.clockrate = clockrate;
codec.bitrate = bitrate; codec.bitrate = bitrate;
codec.channels = channels; codec.channels = channels;
@ -3534,18 +3531,18 @@ void UpdateCodec(int payload_type,
// Updates or creates a new codec entry in the video description according to // Updates or creates a new codec entry in the video description according to
// `name`, `width`, `height`, and `framerate`. // `name`, `width`, `height`, and `framerate`.
void UpdateCodec(int payload_type, void UpdateCodec(int payload_type,
const std::string& name, absl::string_view name,
VideoContentDescription* video_desc) { VideoContentDescription* video_desc) {
// Codec may already be populated with (only) optional parameters // Codec may already be populated with (only) optional parameters
// (from an fmtp). // (from an fmtp).
cricket::VideoCodec codec = cricket::VideoCodec codec =
GetCodecWithPayloadType(video_desc->codecs(), payload_type); GetCodecWithPayloadType(video_desc->codecs(), payload_type);
codec.name = name; codec.name = std::string(name);
AddOrReplaceCodec<VideoContentDescription, cricket::VideoCodec>(video_desc, AddOrReplaceCodec<VideoContentDescription, cricket::VideoCodec>(video_desc,
codec); codec);
} }
bool ParseRtpmapAttribute(const std::string& line, bool ParseRtpmapAttribute(absl::string_view line,
const cricket::MediaType media_type, const cricket::MediaType media_type,
const std::vector<int>& payload_types, const std::vector<int>& payload_types,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
@ -3630,7 +3627,7 @@ bool ParseFmtpParam(absl::string_view line,
return true; return true;
} }
bool ParseFmtpAttributes(const std::string& line, bool ParseFmtpAttributes(absl::string_view line,
const cricket::MediaType media_type, const cricket::MediaType media_type,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error) { SdpParseError* error) {
@ -3692,7 +3689,7 @@ bool ParseFmtpAttributes(const std::string& line,
return true; return true;
} }
bool ParsePacketizationAttribute(const std::string& line, bool ParsePacketizationAttribute(absl::string_view line,
const cricket::MediaType media_type, const cricket::MediaType media_type,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error) { SdpParseError* error) {
@ -3700,7 +3697,7 @@ bool ParsePacketizationAttribute(const std::string& line,
return true; return true;
} }
std::vector<std::string> packetization_fields; std::vector<std::string> packetization_fields;
rtc::split(line.c_str(), kSdpDelimiterSpaceChar, &packetization_fields); rtc::split(line, kSdpDelimiterSpaceChar, &packetization_fields);
if (packetization_fields.size() < 2) { if (packetization_fields.size() < 2) {
return ParseFailedGetValue(line, kAttributePacketization, error); return ParseFailedGetValue(line, kAttributePacketization, error);
} }
@ -3720,7 +3717,7 @@ bool ParsePacketizationAttribute(const std::string& line,
return true; return true;
} }
bool ParseRtcpFbAttribute(const std::string& line, bool ParseRtcpFbAttribute(absl::string_view line,
const cricket::MediaType media_type, const cricket::MediaType media_type,
MediaContentDescription* media_desc, MediaContentDescription* media_desc,
SdpParseError* error) { SdpParseError* error) {
@ -3729,7 +3726,7 @@ bool ParseRtcpFbAttribute(const std::string& line,
return true; return true;
} }
std::vector<std::string> rtcp_fb_fields; std::vector<std::string> rtcp_fb_fields;
rtc::split(line.c_str(), kSdpDelimiterSpaceChar, &rtcp_fb_fields); rtc::split(line, kSdpDelimiterSpaceChar, &rtcp_fb_fields);
if (rtcp_fb_fields.size() < 2) { if (rtcp_fb_fields.size() < 2) {
return ParseFailedGetValue(line, kAttributeRtcpFb, error); return ParseFailedGetValue(line, kAttributeRtcpFb, error);
} }

View File

@ -22,6 +22,7 @@
#include <string> #include <string>
#include "absl/strings/string_view.h"
#include "api/candidate.h" #include "api/candidate.h"
#include "api/jsep.h" #include "api/jsep.h"
#include "api/jsep_ice_candidate.h" #include "api/jsep_ice_candidate.h"
@ -66,7 +67,7 @@ RTC_EXPORT std::string SdpSerializeCandidate(
// jdesc - The JsepSessionDescription deserialized from the SDP string. // jdesc - The JsepSessionDescription deserialized from the SDP string.
// error - The detail error information when parsing fails. // error - The detail error information when parsing fails.
// return - true on success, false on failure. // return - true on success, false on failure.
bool SdpDeserialize(const std::string& message, bool SdpDeserialize(absl::string_view message,
JsepSessionDescription* jdesc, JsepSessionDescription* jdesc,
SdpParseError* error); SdpParseError* error);
@ -77,7 +78,7 @@ bool SdpDeserialize(const std::string& message,
// candidates - The JsepIceCandidate from the SDP string. // candidates - The JsepIceCandidate from the SDP string.
// error - The detail error information when parsing fails. // error - The detail error information when parsing fails.
// return - true on success, false on failure. // return - true on success, false on failure.
RTC_EXPORT bool SdpDeserializeCandidate(const std::string& message, RTC_EXPORT bool SdpDeserializeCandidate(absl::string_view message,
JsepIceCandidate* candidate, JsepIceCandidate* candidate,
SdpParseError* error); SdpParseError* error);
@ -89,8 +90,8 @@ RTC_EXPORT bool SdpDeserializeCandidate(const std::string& message,
// candidate - The cricket Candidate from the SDP string. // candidate - The cricket Candidate from the SDP string.
// error - The detail error information when parsing fails. // error - The detail error information when parsing fails.
// return - true on success, false on failure. // return - true on success, false on failure.
RTC_EXPORT bool SdpDeserializeCandidate(const std::string& transport_name, RTC_EXPORT bool SdpDeserializeCandidate(absl::string_view transport_name,
const std::string& message, absl::string_view message,
cricket::Candidate* candidate, cricket::Candidate* candidate,
SdpParseError* error); SdpParseError* error);
@ -100,7 +101,7 @@ RTC_EXPORT bool SdpDeserializeCandidate(const std::string& transport_name,
// `error` is not null. // `error` is not null.
// If `is_raw` is false, `message` is expected to be prefixed with "a=". // If `is_raw` is false, `message` is expected to be prefixed with "a=".
// If `is_raw` is true, no prefix is expected in `messaage`. // If `is_raw` is true, no prefix is expected in `messaage`.
RTC_EXPORT bool ParseCandidate(const std::string& message, RTC_EXPORT bool ParseCandidate(absl::string_view message,
cricket::Candidate* candidate, cricket::Candidate* candidate,
SdpParseError* error, SdpParseError* error,
bool is_raw); bool is_raw);