Skip to content

Commit

Permalink
Fix padding removal handler (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Apr 11, 2017
1 parent c30da45 commit 27dc114
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
21 changes: 16 additions & 5 deletions erizo/src/erizo/rtp/RtpPaddingRemovalHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ void RtpPaddingRemovalHandler::disable() {

void RtpPaddingRemovalHandler::read(Context *ctx, std::shared_ptr<dataPacket> packet) {
RtcpHeader *chead = reinterpret_cast<RtcpHeader*>(packet->data);
RtpHeader *rtp_header = reinterpret_cast<RtpHeader*>(packet->data);

if (!chead->isRtcp() && enabled_ && packet->type == VIDEO_PACKET) {
if (!removePaddingBytes(packet)) {
uint32_t ssrc = rtp_header->getSSRC();
auto translator_it = translator_map_.find(ssrc);
std::shared_ptr<SequenceNumberTranslator> translator;
if (translator_it != translator_map_.end()) {
translator = translator_it->second;
} else {
ELOG_DEBUG("message: no Translator found creating a new one, ssrc: %u", ssrc);
translator = std::make_shared<SequenceNumberTranslator>();
translator_map_[ssrc] = translator;
}
if (!removePaddingBytes(packet, translator)) {
return;
}
RtpHeader *rtp_header = reinterpret_cast<RtpHeader*>(packet->data);
uint16_t sequence_number = rtp_header->getSeqNumber();
SequenceNumber sequence_number_info = translator_.get(sequence_number, false);
SequenceNumber sequence_number_info = translator->get(sequence_number, false);

if (sequence_number_info.type != SequenceNumberType::Valid) {
return;
Expand All @@ -39,14 +49,15 @@ void RtpPaddingRemovalHandler::write(Context *ctx, std::shared_ptr<dataPacket> p
ctx->fireWrite(packet);
}

bool RtpPaddingRemovalHandler::removePaddingBytes(std::shared_ptr<dataPacket> packet) {
bool RtpPaddingRemovalHandler::removePaddingBytes(std::shared_ptr<dataPacket> packet,
std::shared_ptr<SequenceNumberTranslator> translator) {
RtpHeader *rtp_header = reinterpret_cast<RtpHeader*>(packet->data);
int header_length = rtp_header->getHeaderLength();

int padding_length = RtpUtils::getPaddingLength(packet);
if (padding_length + header_length == packet->length) {
uint16_t sequence_number = rtp_header->getSeqNumber();
translator_.get(sequence_number, true);
translator->get(sequence_number, true);
return false;
}
packet->length -= padding_length;
Expand Down
7 changes: 5 additions & 2 deletions erizo/src/erizo/rtp/RtpPaddingRemovalHandler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef ERIZO_SRC_ERIZO_RTP_RTPPADDINGREMOVALHANDLER_H_
#define ERIZO_SRC_ERIZO_RTP_RTPPADDINGREMOVALHANDLER_H_

#include <map>

#include "./logger.h"
#include "pipeline/Handler.h"
#include "rtp/SequenceNumberTranslator.h"
Expand Down Expand Up @@ -28,12 +30,13 @@ class RtpPaddingRemovalHandler: public Handler, public std::enable_shared_from_t
void notifyUpdate() override;

private:
bool removePaddingBytes(std::shared_ptr<dataPacket> packet);
bool removePaddingBytes(std::shared_ptr<dataPacket> packet,
std::shared_ptr<SequenceNumberTranslator> translator);

private:
bool enabled_;
bool initialized_;
SequenceNumberTranslator translator_;
std::map<uint32_t, std::shared_ptr<SequenceNumberTranslator>> translator_map_;
};
} // namespace erizo

Expand Down

0 comments on commit 27dc114

Please sign in to comment.