Reland "Refactoring DataContentDescription class"

This reverts commit 1859dc04fd8bd35a3d2ee1140bde3eac210bb0c2.

Reason for revert: Issue likely unrelated to this CL.

Original change's description:
> Revert "Refactoring DataContentDescription class"
>
> This reverts commit 8a9193c217d818fea77b9540bd4ca7ebad53db76.
>
> Reason for revert: Breaks downstreams
>
> Original change's description:
> > Refactoring DataContentDescription class
> >
> > This CL splits the cricket::DataContentDescription class into
> > two classes: cricket::DataContentDescription (used for RTP data) and
> > cricket::SctpDataContentDescription (used for SCTP only).
> >
> > SctpDataContentDescription no longer inherits from
> > MediaContentDescriptionImpl, and no longer contains "codecs".
> >
> > Design document:
> > https://docs.google.com/document/d/1H5LfQxJA2ikMWTQ8FZ3_GAmaXM7knfVQWiSz6ph8VQ0/edit#
> >
> > Bug: webrtc:10358
> > Change-Id: Ie7160610506aeef56d1f821b5fdb5d9492201f43
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132700
> > Reviewed-by: Steve Anton <steveanton@webrtc.org>
> > Commit-Queue: Harald Alvestrand <hta@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#27651}
>
> TBR=steveanton@webrtc.org,kwiberg@webrtc.org,hbos@webrtc.org,hta@webrtc.org
>
> Change-Id: I3b8a68cd481c41ce30eeb5ffbc5da735a9659019
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:10358
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/133360
> Reviewed-by: Seth Hampson <shampson@webrtc.org>
> Commit-Queue: Seth Hampson <shampson@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#27652}

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: webrtc:10358
Change-Id: Ie58f862f8c55d2a994eaee1caa107ef701b0770f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/133624
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27698}
This commit is contained in:
Harald Alvestrand
2019-04-23 05:20:17 +00:00
committed by Commit Bot
parent 62acb5a8c0
commit 26bf7c4682
12 changed files with 498 additions and 309 deletions

View File

@ -54,29 +54,30 @@ using cricket::Candidates;
using cricket::ContentInfo;
using cricket::CryptoParams;
using cricket::DataContentDescription;
using cricket::ICE_CANDIDATE_COMPONENT_RTP;
using cricket::ICE_CANDIDATE_COMPONENT_RTCP;
using cricket::ICE_CANDIDATE_COMPONENT_RTP;
using cricket::kCodecParamAssociatedPayloadType;
using cricket::kCodecParamMaxAverageBitrate;
using cricket::kCodecParamMaxBitrate;
using cricket::kCodecParamMaxPlaybackRate;
using cricket::kCodecParamMaxPTime;
using cricket::kCodecParamMaxQuantization;
using cricket::kCodecParamMinBitrate;
using cricket::kCodecParamMinPTime;
using cricket::kCodecParamPTime;
using cricket::kCodecParamSctpProtocol;
using cricket::kCodecParamSctpStreams;
using cricket::kCodecParamSPropStereo;
using cricket::kCodecParamStartBitrate;
using cricket::kCodecParamStereo;
using cricket::kCodecParamUseInbandFec;
using cricket::kCodecParamUseDtx;
using cricket::kCodecParamSctpProtocol;
using cricket::kCodecParamSctpStreams;
using cricket::kCodecParamMaxAverageBitrate;
using cricket::kCodecParamMaxPlaybackRate;
using cricket::kCodecParamAssociatedPayloadType;
using cricket::kCodecParamUseInbandFec;
using cricket::MediaContentDescription;
using cricket::MediaType;
using cricket::RtpHeaderExtensions;
using cricket::MediaProtocolType;
using cricket::MediaType;
using cricket::RidDescription;
using cricket::RtpHeaderExtensions;
using cricket::SctpDataContentDescription;
using cricket::SimulcastDescription;
using cricket::SimulcastLayer;
using cricket::SimulcastLayerList;
@ -1337,8 +1338,6 @@ void BuildMediaDescription(const ContentInfo* content_info,
const MediaContentDescription* media_desc = content_info->media_description();
RTC_DCHECK(media_desc);
int sctp_port = cricket::kSctpDefaultPort;
// RFC 4566
// m=<media> <port> <proto> <fmt>
// fmt is a list of payload type numbers that MAY be used in the session.
@ -1366,24 +1365,18 @@ void BuildMediaDescription(const ContentInfo* content_info,
fmt.append(rtc::ToString(codec.id));
}
} else if (media_type == cricket::MEDIA_TYPE_DATA) {
const DataContentDescription* data_desc = media_desc->as_data();
if (IsDtlsSctp(media_desc->protocol())) {
const cricket::SctpDataContentDescription* data_desc =
media_desc->as_sctp();
fmt.append(" ");
if (data_desc->use_sctpmap()) {
for (const cricket::DataCodec& codec : data_desc->codecs()) {
if (absl::EqualsIgnoreCase(codec.name,
cricket::kGoogleSctpDataCodecName) &&
codec.GetParam(cricket::kCodecParamPort, &sctp_port)) {
break;
}
}
fmt.append(rtc::ToString(sctp_port));
fmt.append(rtc::ToString(data_desc->port()));
} else {
fmt.append(kDefaultSctpmapProtocol);
}
} else {
const DataContentDescription* data_desc = media_desc->as_data();
for (const cricket::DataCodec& codec : data_desc->codecs()) {
fmt.append(" ");
fmt.append(rtc::ToString(codec.id));
@ -1523,9 +1516,10 @@ void BuildMediaDescription(const ContentInfo* content_info,
AddLine(os.str(), message);
if (IsDtlsSctp(media_desc->protocol())) {
const DataContentDescription* data_desc = media_desc->as_data();
const cricket::SctpDataContentDescription* data_desc =
media_desc->as_sctp();
bool use_sctpmap = data_desc->use_sctpmap();
BuildSctpContentAttributes(message, sctp_port, use_sctpmap);
BuildSctpContentAttributes(message, data_desc->port(), use_sctpmap);
} else if (IsRtp(media_desc->protocol())) {
BuildRtpContentAttributes(media_desc, media_type, msid_signaling, message);
}
@ -1834,43 +1828,6 @@ void AddRtcpFbLines(const T& codec, std::string* message) {
}
}
cricket::DataCodec FindOrMakeSctpDataCodec(DataContentDescription* media_desc) {
for (const auto& codec : media_desc->codecs()) {
if (absl::EqualsIgnoreCase(codec.name, cricket::kGoogleSctpDataCodecName)) {
return codec;
}
}
cricket::DataCodec codec_port(cricket::kGoogleSctpDataCodecPlType,
cricket::kGoogleSctpDataCodecName);
return codec_port;
}
bool AddOrModifySctpDataCodecPort(DataContentDescription* media_desc,
int sctp_port) {
// Add the SCTP Port number as a pseudo-codec "port" parameter
auto codec = FindOrMakeSctpDataCodec(media_desc);
int dummy;
if (codec.GetParam(cricket::kCodecParamPort, &dummy)) {
return false;
}
codec.SetParam(cricket::kCodecParamPort, sctp_port);
media_desc->AddOrReplaceCodec(codec);
return true;
}
bool AddOrModifySctpDataMaxMessageSize(DataContentDescription* media_desc,
int max_message_size) {
// Add the SCTP Max Message Size as a pseudo-parameter to the codec
auto codec = FindOrMakeSctpDataCodec(media_desc);
int dummy;
if (codec.GetParam(cricket::kCodecParamMaxMessageSize, &dummy)) {
return false;
}
codec.SetParam(cricket::kCodecParamMaxMessageSize, max_message_size);
media_desc->AddOrReplaceCodec(codec);
return true;
}
bool GetMinValue(const std::vector<int>& values, int* value) {
if (values.empty()) {
return false;
@ -2748,24 +2705,30 @@ bool ParseMediaDescription(
payload_types, pos, &content_name, &bundle_only,
&section_msid_signaling, &transport, candidates, error);
} else if (HasAttribute(line, kMediaTypeData)) {
std::unique_ptr<DataContentDescription> data_desc =
ParseContentDescription<DataContentDescription>(
message, cricket::MEDIA_TYPE_DATA, mline_index, protocol,
payload_types, pos, &content_name, &bundle_only,
&section_msid_signaling, &transport, candidates, error);
if (data_desc && IsDtlsSctp(protocol)) {
if (IsDtlsSctp(protocol)) {
auto data_desc = absl::make_unique<SctpDataContentDescription>();
int p;
if (rtc::FromString(fields[3], &p)) {
if (!AddOrModifySctpDataCodecPort(data_desc.get(), p)) {
return false;
}
data_desc->set_port(p);
} else if (fields[3] == kDefaultSctpmapProtocol) {
data_desc->set_use_sctpmap(false);
}
if (!ParseContent(message, cricket::MEDIA_TYPE_DATA, mline_index,
protocol, payload_types, pos, &content_name,
&bundle_only, &section_msid_signaling,
data_desc.get(), &transport, candidates, error)) {
return false;
}
content = std::move(data_desc);
} else {
// RTP
std::unique_ptr<DataContentDescription> data_desc =
ParseContentDescription<DataContentDescription>(
message, cricket::MEDIA_TYPE_DATA, mline_index, protocol,
payload_types, pos, &content_name, &bundle_only,
&section_msid_signaling, &transport, candidates, error);
content = std::move(data_desc);
}
content = std::move(data_desc);
} else {
RTC_LOG(LS_WARNING) << "Unsupported media type: " << line;
continue;
@ -3138,13 +3101,15 @@ bool ParseContent(const std::string& message,
line, "sctp-port attribute found in non-data media description.",
error);
}
if (media_desc->as_sctp()->use_sctpmap()) {
return ParseFailed(
line, "sctp-port attribute can't be used with sctpmap.", error);
}
int sctp_port;
if (!ParseSctpPort(line, &sctp_port, error)) {
return false;
}
if (!AddOrModifySctpDataCodecPort(media_desc->as_data(), sctp_port)) {
return false;
}
media_desc->as_sctp()->set_port(sctp_port);
} else if (IsDtlsSctp(protocol) &&
HasAttribute(line, kAttributeMaxMessageSize)) {
if (media_type != cricket::MEDIA_TYPE_DATA) {
@ -3157,10 +3122,7 @@ bool ParseContent(const std::string& message,
if (!ParseSctpMaxMessageSize(line, &max_message_size, error)) {
return false;
}
if (!AddOrModifySctpDataMaxMessageSize(media_desc->as_data(),
max_message_size)) {
return false;
}
media_desc->as_sctp()->set_max_message_size(max_message_size);
} else if (IsRtp(protocol)) {
//
// RTP specific attrubtes