Skip to content

Commit

Permalink
Fix various issues related to unencrypted transport, stream priority …
Browse files Browse the repository at this point in the history
…and multiple publishers (#1719)
  • Loading branch information
jcague authored Jun 7, 2021
1 parent 39db637 commit ef1b4fb
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 68 deletions.
78 changes: 39 additions & 39 deletions erizo/src/erizo/SdpInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,22 @@ namespace erizo {
payloadVector = internalPayloadVector_;
}

this->isBundle = bundle;
this->isRtcpMux = true;
if (videoEnabled)
this->videoSdpMLine = 0;
if (audioEnabled)
this->audioSdpMLine = 0;

this->videoDirection = SENDRECV;
this->audioDirection = SENDRECV;
isBundle = bundle;
isRtcpMux = true;
if (videoEnabled) {
videoSdpMLine = 0;
}
if (audioEnabled) {
audioSdpMLine = 0;
}

videoDirection = SENDRECV;
audioDirection = SENDRECV;
ELOG_DEBUG("Setting Offer SDP");
}

void SdpInfo::copyInfoFromSdp(std::shared_ptr<SdpInfo> offerSdp) {
for (const auto &payload : offerSdp->payloadVector) {
void SdpInfo::copyInfoFromSdp(std::shared_ptr<SdpInfo> offer_sdp) {
for (const auto &payload : offer_sdp->payloadVector) {
bool payload_exists = false;
for (const auto &local_payload : payloadVector) {
if (local_payload == payload) {
Expand All @@ -168,7 +170,7 @@ namespace erizo {
}
}

for (const auto &ext_map : offerSdp->extMapVector) {
for (const auto &ext_map : offer_sdp->extMapVector) {
bool ext_map_exists = false;
for (const auto &local_ext_map : extMapVector) {
if (local_ext_map == ext_map) {
Expand All @@ -184,54 +186,53 @@ namespace erizo {
extMapVector.size(), payloadVector.size());
}

void SdpInfo::setOfferSdp(std::shared_ptr<SdpInfo> offerSdp) {
this->payloadVector = offerSdp->payloadVector;
this->isBundle = offerSdp->isBundle;
this->profile = offerSdp->profile;
this->isRtcpMux = offerSdp->isRtcpMux;
this->videoSdpMLine = offerSdp->videoSdpMLine;
this->audioSdpMLine = offerSdp->audioSdpMLine;
this->inOutPTMap = offerSdp->inOutPTMap;
this->outInPTMap = offerSdp->outInPTMap;
this->bundleTags = offerSdp->bundleTags;
this->extMapVector = offerSdp->extMapVector;
this->rids_ = offerSdp->rids();
this->google_conference_flag_set = offerSdp->google_conference_flag_set;
void SdpInfo::setOfferSdp(std::shared_ptr<SdpInfo> offer_sdp) {
isBundle = offer_sdp->isBundle;
profile = offer_sdp->profile;
isRtcpMux = offer_sdp->isRtcpMux;
videoSdpMLine = offer_sdp->videoSdpMLine;
audioSdpMLine = offer_sdp->audioSdpMLine;
inOutPTMap = offer_sdp->inOutPTMap;
outInPTMap = offer_sdp->outInPTMap;
bundleTags = offer_sdp->bundleTags;
copyInfoFromSdp(offer_sdp);
rids_ = offer_sdp->rids();
google_conference_flag_set = offer_sdp->google_conference_flag_set;
for (auto& rid : rids_) {
rid.direction = reverse(rid.direction);
}
switch (offerSdp->videoDirection) {
switch (offer_sdp->videoDirection) {
case SENDONLY:
this->videoDirection = RECVONLY;
videoDirection = RECVONLY;
break;
case RECVONLY:
this->videoDirection = SENDONLY;
videoDirection = SENDONLY;
break;
case SENDRECV:
this->videoDirection = SENDRECV;
videoDirection = SENDRECV;
break;
case INACTIVE:
this->videoDirection = INACTIVE;
videoDirection = INACTIVE;
break;
default:
this->videoDirection = SENDRECV;
videoDirection = SENDRECV;
break;
}
switch (offerSdp->audioDirection) {
switch (offer_sdp->audioDirection) {
case SENDONLY:
this->audioDirection = RECVONLY;
audioDirection = RECVONLY;
break;
case RECVONLY:
this->audioDirection = SENDONLY;
audioDirection = SENDONLY;
break;
case SENDRECV:
this->audioDirection = SENDRECV;
audioDirection = SENDRECV;
break;
case INACTIVE:
this->audioDirection = INACTIVE;
audioDirection = INACTIVE;
break;
default:
this->audioDirection = SENDRECV;
audioDirection = SENDRECV;
break;
}
ELOG_DEBUG("Offer SDP successfully set");
Expand Down Expand Up @@ -502,8 +503,7 @@ namespace erizo {
}

bool operator==(const RtpMap& lhs, const RtpMap& rhs) {
return lhs.payload_type == rhs.payload_type &&
lhs.encoding_name == rhs.encoding_name &&
return lhs.encoding_name == rhs.encoding_name &&
lhs.clock_rate == rhs.clock_rate &&
lhs.media_type == rhs.media_type &&
lhs.channels == rhs.channels;
Expand Down
19 changes: 12 additions & 7 deletions erizo/src/erizo/WebRtcConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,14 +767,15 @@ boost::future<void> WebRtcConnection::processRemoteSdp() {

detectNewTransceiversInRemoteSdp();

local_sdp_->setOfferSdp(remote_sdp_);
extension_processor_.setSdpInfo(local_sdp_);
local_sdp_->updateSupportedExtensionMap(extension_processor_.getSupportedExtensionMap());

if (first_remote_sdp_processed_) {
return setRemoteSdpsToMediaStreams();
}

bundle_ = remote_sdp_->isBundle;
local_sdp_->setOfferSdp(remote_sdp_);
extension_processor_.setSdpInfo(local_sdp_);
local_sdp_->updateSupportedExtensionMap(extension_processor_.getSupportedExtensionMap());

if (remote_sdp_->profile == SAVPF) {
ELOG_DEBUG("%s message: creating encrypted transports", toLog());
Expand Down Expand Up @@ -885,7 +886,6 @@ bool WebRtcConnection::addRemoteCandidateSync(std::string mid, int mLineIndex, C
return false;
}
MediaType theType;
std::string theMid;

// TODO(pedro) check if this works with video+audio and no bundle
if (mLineIndex == -1) {
Expand All @@ -900,10 +900,8 @@ bool WebRtcConnection::addRemoteCandidateSync(std::string mid, int mLineIndex, C

if ((!mid.compare("video")) || (mLineIndex == remote_sdp_->videoSdpMLine)) {
theType = VIDEO_TYPE;
theMid = "video";
} else {
theType = AUDIO_TYPE;
theMid = "audio";
}
bool res = false;
candidate_list.push_back(candidate);
Expand Down Expand Up @@ -1041,15 +1039,22 @@ void WebRtcConnection::read(std::shared_ptr<DataPacket> packet) {
extension_processor_.processRtpExtensions(packet);
std::string mid = packet->mid;
extension_processor_.removeMidAndRidExtensions(packet);
forEachMediaStream([packet, transport, ssrc, &mid] (const std::shared_ptr<MediaStream> &media_stream) {
bool sent = false;
forEachMediaStream([packet, transport, ssrc, &mid, &sent] (const std::shared_ptr<MediaStream> &media_stream) {
if (!mid.empty()) {
if (media_stream->getVideoMid() == mid || media_stream->getAudioMid() == mid) {
sent = true;
media_stream->onTransportData(packet, transport);
}
} else if (media_stream->isSourceSSRC(ssrc) || media_stream->isSinkSSRC(ssrc)) {
sent = true;
media_stream->onTransportData(packet, transport);
}
});
if (!sent) {
ELOG_DEBUG("Packet does not belong to a known stream, ssrc: %u, length: %d, mid: %s, rid: %s",
ssrc, packet->length, packet->mid, packet->rid);
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,17 @@ void BandwidthEstimationHandler::updateExtensionMap(bool is_video, std::array<RT
continue;
}
if (is_video) {
ext_map_video_.RegisterByType(id, type);
if (!ext_map_video_.IsRegistered(type)) {
ext_map_video_.RegisterByType(id, type);
} else {
ELOG_DEBUG("Video extension Map already Registered type: %d, id: %d", type, id);
}
} else {
ext_map_audio_.RegisterByType(id, type);
if (!ext_map_audio_.IsRegistered(type)) {
ext_map_audio_.RegisterByType(id, type);
} else {
ELOG_DEBUG("Audio extension Map already Registered type: %d, id: %d", type, id);
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions erizo/src/erizo/rtp/QualityFilterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ void QualityFilterHandler::detectVideoScalability(const std::shared_ptr<DataPack
if (is_scalable_ || packet->type != VIDEO_PACKET) {
return;
}
if (packet->belongsToTemporalLayer(1) || packet->belongsToSpatialLayer(1)) {
if (packet->rid != "0" ||
packet->belongsToTemporalLayer(1) ||
packet->belongsToSpatialLayer(1) ||
packet->belongsToSpatialLayer(1)) {
is_scalable_ = true;
quality_manager_->enable();
}
Expand Down Expand Up @@ -160,7 +163,7 @@ void QualityFilterHandler::write(Context *ctx, std::shared_ptr<DataPacket> packe
int picture_id = packet->picture_id;
uint8_t tl0_pic_idx = packet->tl0_pic_idx;

if (last_ssrc_received_ != 0 && ssrc != last_ssrc_received_) {
if (packet->rid != "0" && !receiving_multiple_ssrc_) {
receiving_multiple_ssrc_ = true;
}

Expand Down Expand Up @@ -221,7 +224,7 @@ void QualityFilterHandler::write(Context *ctx, std::shared_ptr<DataPacket> packe
updateTL0PicIdx(packet, tl0_pic_idx_sent);
// removeVP8OptionalPayload(packet); // TODO(javier): uncomment this line in case of issues with pictureId

/* TODO(pedro): Disabled as part of the hack to reduce audio drift
/* TODO(pedro): Disabled as part of the hack to reduce audio drift
* We will have to go back here and fix timestamp updates
} else if (is_scalable_ && enabled_ && chead->isRtcp() && chead->isSenderReport()) {
uint32_t ssrc = chead->getSSRC();
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/RtpTrackMuteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void RtpTrackMuteHandler::handlePacket(Context *ctx, TrackMuteInfo *info, std::s
uint16_t packet_seq_num = rtp_header->getSeqNumber();
maybeUpdateHighestSeqNum(info, packet_seq_num);
SequenceNumber sequence_number_info = info->translator.get(packet_seq_num, should_skip_packet);
if (!should_skip_packet) {
if (!should_skip_packet && sequence_number_info.type == SequenceNumberType::Valid) {
setPacketSeqNumber(packet, sequence_number_info.output);
ctx->fireWrite(std::move(packet));
}
Expand Down
7 changes: 4 additions & 3 deletions erizo_controller/common/semanticSdp/SDPInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ class SDPInfo {

md.rtcpMux = 'rtcp-mux';

// TODO(javier): Enable RTCP-RSIZE: md.rtcpRsize = 'rtcp-rsize';

md.connection = media.getConnection();

md.xGoogleFlag = media.getXGoogleFlag();
Expand Down Expand Up @@ -313,8 +315,7 @@ class SDPInfo {
md.setup = Setup.toString(dtls.getSetup());
}

md.protocol = dtls ? 'UDP/TLS/RTP/SAVPF' : 'RTP/AVPF';

md.protocol = dtls.getFingerprint() ? 'UDP/TLS/RTP/SAVPF' : 'RTP/AVPF';
if (media.setup) {
md.setup = Setup.toString(media.setup);
}
Expand Down Expand Up @@ -614,7 +615,7 @@ function getSimulcastDir(index, md, simulcast) {
const simulcastList = md.simulcast[`list${index}`];
if (simulcastDir) {
const direction = DirectionWay.byValue(simulcastDir);
const list = SDPTransform.parseSimulcastStreamList(simulcastList);
const list = SDPTransform.parseSimulcastStreamList(`${simulcastList}`);
list.forEach((stream) => {
const alternatives = [];
stream.forEach((entry) => {
Expand Down
5 changes: 3 additions & 2 deletions erizo_controller/erizoJS/models/SessionDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,12 @@ class SessionDescription {

if (media.protocol === 'UDP/TLS/RTP/SAVPF') {
info.setProfile('SAVPF');
this.profole = 'SAVPF';
this.profile = 'SAVPF';
} else {
info.setProfile('AVPF');
this.profole = 'AVPF';
this.profile = 'AVPF';
}

info.addBundleTag(media.getId(), media.getType());

const candidates = media.getCandidates();
Expand Down
2 changes: 1 addition & 1 deletion erizo_controller/erizoJS/models/WebRtcConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class WebRtcConnection extends EventEmitter {
}
const mediaStream = new erizo.MediaStream(this.threadPool,
this.wrtc, id, options.label, isPublisher,
options.audio, options.video, options.priority, handlers);
options.audio, options.video, handlers, options.priority);
mediaStream.id = id;
mediaStream.label = options.label;
mediaStream.isPublisher = isPublisher;
Expand Down
Loading

0 comments on commit ef1b4fb

Please sign in to comment.