Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RTCP forwarding in Single PC #1183

Merged
merged 4 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions erizo/src/erizo/WebRtcConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,22 +470,46 @@ void WebRtcConnection::onCandidate(const CandidateInfo& cand, Transport *transpo
}
}

void WebRtcConnection::onRtcpFromTransport(std::shared_ptr<DataPacket> packet, Transport *transport) {
RtpUtils::forEachRtcpBlock(packet, [this, packet, transport](RtcpHeader *chead) {
uint32_t ssrc = chead->isFeedback() ? chead->getSourceSSRC() : chead->getSSRC();
std::shared_ptr<DataPacket> rtcp = std::make_shared<DataPacket>(*packet);
rtcp->length = (ntohs(chead->length) + 1) * 4;
std::memcpy(rtcp->data, chead, rtcp->length);
forEachMediaStream([rtcp, transport, ssrc, chead] (const std::shared_ptr<MediaStream> &media_stream) {
if (chead->isREMB()) {
for (uint8_t index = 0; index < chead->getREMBNumSSRC(); index++) {
uint32_t ssrc_feed = chead->getREMBFeedSSRC(index);
if (media_stream->isSourceSSRC(ssrc_feed) || media_stream->isSinkSSRC(ssrc_feed)) {
// TODO(javier): Calculate the portion of bitrate that corresponds to this stream.
media_stream->onTransportData(rtcp, transport);
}
}
} else if (media_stream->isSourceSSRC(ssrc) || media_stream->isSinkSSRC(ssrc)) {
media_stream->onTransportData(rtcp, transport);
}
});
});
}

void WebRtcConnection::onTransportData(std::shared_ptr<DataPacket> packet, Transport *transport) {
if (getCurrentState() != CONN_READY) {
return;
}
char* buf = packet->data;
RtpHeader *head = reinterpret_cast<RtpHeader*> (buf);
RtcpHeader *chead = reinterpret_cast<RtcpHeader*> (buf);
uint32_t ssrc = head->getSSRC();
if (chead->isRtcp() && chead->packettype != RTCP_Sender_PT) { // Sender Report
ssrc = chead->getSourceSSRC();
if (chead->isRtcp()) {
onRtcpFromTransport(packet, transport);
return;
} else {
RtpHeader *head = reinterpret_cast<RtpHeader*> (buf);
uint32_t ssrc = head->getSSRC();
forEachMediaStream([packet, transport, ssrc] (const std::shared_ptr<MediaStream> &media_stream) {
if (media_stream->isSourceSSRC(ssrc) || media_stream->isSinkSSRC(ssrc)) {
media_stream->onTransportData(packet, transport);
}
});
}
forEachMediaStream([packet, transport, ssrc] (const std::shared_ptr<MediaStream> &media_stream) {
if (media_stream->isSourceSSRC(ssrc) || media_stream->isSinkSSRC(ssrc)) {
media_stream->onTransportData(packet, transport);
}
});
}

void WebRtcConnection::asyncTask(std::function<void(std::shared_ptr<WebRtcConnection>)> f) {
Expand Down
1 change: 1 addition & 0 deletions erizo/src/erizo/WebRtcConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class WebRtcConnection: public TransportListener, public LogContext,
void onRemoteSdpsSetToMediaStreams(std::string stream_id);
std::string getJSONCandidate(const std::string& mid, const std::string& sdp);
void trackTransportInfo();
void onRtcpFromTransport(std::shared_ptr<DataPacket> packet, Transport *transport);

private:
std::string connection_id_;
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void BandwidthEstimationHandler::sendREMBPacket() {
ELOG_DEBUG("Bitrates min(%u,%u) = %u", bitrate_, max_video_bw_, capped_bitrate);
remb_packet_.setREMBBitRate(capped_bitrate);
remb_packet_.setREMBNumSSRC(1);
remb_packet_.setREMBFeedSSRC(stream_->getVideoSourceSSRC());
remb_packet_.setREMBFeedSSRC(0, stream_->getVideoSourceSSRC());
int remb_length = (remb_packet_.getLength() + 1) * 4;
if (active_) {
ELOG_DEBUG("BWE Estimation is %d", last_send_bitrate_);
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/QualityFilterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void QualityFilterHandler::disable() {
}

void QualityFilterHandler::handleFeedbackPackets(const std::shared_ptr<DataPacket> &packet) {
RtpUtils::forEachRRBlock(packet, [this](RtcpHeader *chead) {
RtpUtils::forEachRtcpBlock(packet, [this](RtcpHeader *chead) {
if (chead->packettype == RTCP_PS_Feedback_PT &&
(chead->getBlockCount() == RTCP_PLI_FMT ||
chead->getBlockCount() == RTCP_SLI_FMT ||
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/RtcpAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ int RtcpAggregator::addREMB(char* buf, int len, uint32_t bitrate) {
theREMB.setLength(5);
theREMB.setREMBBitRate(bitrate);
theREMB.setREMBNumSSRC(1);
theREMB.setREMBFeedSSRC(rtcpSource_->getVideoSourceSSRC());
theREMB.setREMBFeedSSRC(0, rtcpSource_->getVideoSourceSSRC());
int rembLength = (theREMB.getLength()+1)*4;

memcpy(buf, reinterpret_cast<uint8_t*>(&theREMB), rembLength);
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/RtcpForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int RtcpForwarder::addREMB(char* buf, int len, uint32_t bitrate) {
theREMB.setLength(5);
theREMB.setREMBBitRate(bitrate);
theREMB.setREMBNumSSRC(1);
theREMB.setREMBFeedSSRC(rtcpSource_->getVideoSourceSSRC());
theREMB.setREMBFeedSSRC(0, rtcpSource_->getVideoSourceSSRC());
int rembLength = (theREMB.getLength()+1)*4;

memcpy(buf, reinterpret_cast<uint8_t*>(&theREMB), rembLength);
Expand Down
13 changes: 8 additions & 5 deletions erizo/src/erizo/rtp/RtpHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class RtcpHeader {
uint32_t uniqueid;
uint32_t numssrc:8;
uint32_t brLength :24;
uint32_t ssrcfeedb;
uint32_t ssrcfeedb[50];
} rembPacket;

struct pli_t {
Expand All @@ -372,6 +372,9 @@ class RtcpHeader {
packettype == RTCP_PS_Feedback_PT ||
packettype == RTCP_RTP_Feedback_PT);
}
inline bool isREMB() {
return packettype == RTCP_PS_Feedback_PT && blockcount == RTCP_AFB;
}
inline bool isRtcp(void) {
return (packettype >= RTCP_MIN_PT && packettype <= RTCP_MAX_PT);
}
Expand Down Expand Up @@ -511,11 +514,11 @@ class RtcpHeader {
inline void setREMBNumSSRC(uint8_t num) {
report.rembPacket.numssrc = num;
}
inline uint32_t getREMBFeedSSRC() {
return ntohl(report.rembPacket.ssrcfeedb);
inline uint32_t getREMBFeedSSRC(uint8_t index) {
return ntohl(report.rembPacket.ssrcfeedb[index]);
}
inline void setREMBFeedSSRC(uint32_t ssrc) {
report.rembPacket.ssrcfeedb = htonl(ssrc);
inline void setREMBFeedSSRC(uint8_t index, uint32_t ssrc) {
report.rembPacket.ssrcfeedb[index] = htonl(ssrc);
}
inline uint32_t getFCI() {
return ntohl(report.pli.fci);
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/RtpPaddingRemovalHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void RtpPaddingRemovalHandler::write(Context *ctx, std::shared_ptr<DataPacket> p
ctx->fireWrite(std::move(packet));
return;
}
RtpUtils::forEachRRBlock(packet, [this, translator, ssrc](RtcpHeader *chead) {
RtpUtils::forEachRtcpBlock(packet, [this, translator, ssrc](RtcpHeader *chead) {
if (chead->packettype == RTCP_RTP_Feedback_PT) {
RtpUtils::forEachNack(chead, [this, translator, ssrc](uint16_t new_seq_num, uint16_t new_plb,
RtcpHeader* nack_header) {
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/RtpRetransmissionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void RtpRetransmissionHandler::read(Context *ctx, std::shared_ptr<DataPacket> pa
bool contains_nack = false;
bool is_fully_recovered = true;

RtpUtils::forEachRRBlock(packet, [this, &contains_nack, &is_fully_recovered](RtcpHeader *chead) {
RtpUtils::forEachRtcpBlock(packet, [this, &contains_nack, &is_fully_recovered](RtcpHeader *chead) {
if (chead->packettype == RTCP_RTP_Feedback_PT) {
contains_nack = true;

Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/RtpSlideShowHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void RtpSlideShowHandler::read(Context *ctx, std::shared_ptr<DataPacket> packet)
ctx->fireRead(std::move(packet));
return;
}
RtpUtils::forEachRRBlock(packet, [this](RtcpHeader *chead) {
RtpUtils::forEachRtcpBlock(packet, [this](RtcpHeader *chead) {
switch (chead->packettype) {
case RTCP_Receiver_PT:
{
Expand Down
8 changes: 4 additions & 4 deletions erizo/src/erizo/rtp/RtpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void RtpUtils::forEachNack(RtcpHeader *chead, std::function<void(uint16_t, uint1

bool RtpUtils::isPLI(std::shared_ptr<DataPacket> packet) {
bool is_pli = false;
forEachRRBlock(packet, [&is_pli] (RtcpHeader *header) {
forEachRtcpBlock(packet, [&is_pli] (RtcpHeader *header) {
if (header->getPacketType() == RTCP_PS_Feedback_PT &&
header->getBlockCount() == RTCP_PLI_FMT) {
is_pli = true;
Expand All @@ -51,7 +51,7 @@ bool RtpUtils::isPLI(std::shared_ptr<DataPacket> packet) {

bool RtpUtils::isFIR(std::shared_ptr<DataPacket> packet) {
bool is_fir = false;
forEachRRBlock(packet, [&is_fir] (RtcpHeader *header) {
forEachRtcpBlock(packet, [&is_fir] (RtcpHeader *header) {
if (header->getPacketType() == RTCP_PS_Feedback_PT &&
header->getBlockCount() == RTCP_FIR_FMT) {
is_fir = true;
Expand Down Expand Up @@ -95,10 +95,10 @@ int RtpUtils::getPaddingLength(std::shared_ptr<DataPacket> packet) {
return 0;
}

void RtpUtils::forEachRRBlock(std::shared_ptr<DataPacket> packet, std::function<void(RtcpHeader*)> f) {
void RtpUtils::forEachRtcpBlock(std::shared_ptr<DataPacket> packet, std::function<void(RtcpHeader*)> f) {
RtcpHeader *chead = reinterpret_cast<RtcpHeader*>(packet->data);
int len = packet->length;
if (chead->isFeedback()) {
if (chead->isRtcp()) {
char* moving_buffer = packet->data;
int rtcp_length = 0;
int total_length = 0;
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/RtpUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RtpUtils {
public:
static bool sequenceNumberLessThan(uint16_t first, uint16_t second);

static void forEachRRBlock(std::shared_ptr<DataPacket> packet, std::function<void(RtcpHeader*)> f);
static void forEachRtcpBlock(std::shared_ptr<DataPacket> packet, std::function<void(RtcpHeader*)> f);

static void updateREMB(RtcpHeader *chead, uint bitrate);

Expand Down
2 changes: 1 addition & 1 deletion erizo/src/test/utils/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class PacketTools {
remb_packet->setLength(5);
remb_packet->setREMBBitRate(bitrate);
remb_packet->setREMBNumSSRC(1);
remb_packet->setREMBFeedSSRC(55554);
remb_packet->setREMBFeedSSRC(0, 55554);
int remb_length = (remb_packet->getLength() + 1) * 4;
char *buf = reinterpret_cast<char*>(remb_packet);
auto packet = std::make_shared<erizo::DataPacket>(0, buf, remb_length, erizo::OTHER_PACKET);
Expand Down