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

add ExtensionId translator #1400

Merged
merged 5 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
95 changes: 95 additions & 0 deletions erizo/src/erizo/MediaStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,11 @@ void MediaStream::read(std::shared_ptr<DataPacket> packet) {
// Deliver data
if (isVideoSourceSSRC(recvSSRC) && video_sink_) {
parseIncomingPayloadType(buf, len, VIDEO_PACKET);
parseIncomingExtensionId(buf, len, VIDEO_PACKET);
video_sink_->deliverVideoData(std::move(packet));
} else if (isAudioSourceSSRC(recvSSRC) && audio_sink_) {
parseIncomingPayloadType(buf, len, AUDIO_PACKET);
parseIncomingExtensionId(buf, len, AUDIO_PACKET);
audio_sink_->deliverAudioData(std::move(packet));
} else {
ELOG_DEBUG("%s read video unknownSSRC: %u, localVideoSSRC: %u, localAudioSSRC: %u",
Expand All @@ -508,6 +510,7 @@ void MediaStream::read(std::shared_ptr<DataPacket> packet) {
} else {
if (packet->type == AUDIO_PACKET && audio_sink_) {
parseIncomingPayloadType(buf, len, AUDIO_PACKET);
parseIncomingExtensionId(buf, len, AUDIO_PACKET);
// Firefox does not send SSRC in SDP
if (getAudioSourceSSRC() == 0) {
ELOG_DEBUG("%s discoveredAudioSourceSSRC:%u", toLog(), recvSSRC);
Expand All @@ -516,6 +519,7 @@ void MediaStream::read(std::shared_ptr<DataPacket> packet) {
audio_sink_->deliverAudioData(std::move(packet));
} else if (packet->type == VIDEO_PACKET && video_sink_) {
parseIncomingPayloadType(buf, len, VIDEO_PACKET);
parseIncomingExtensionId(buf, len, VIDEO_PACKET);
// Firefox does not send SSRC in SDP
if (getVideoSourceSSRC() == 0) {
ELOG_DEBUG("%s discoveredVideoSourceSSRC:%u", toLog(), recvSSRC);
Expand Down Expand Up @@ -580,6 +584,7 @@ void MediaStream::sendPacketAsync(std::shared_ptr<DataPacket> packet) {
}

changeDeliverPayloadType(packet.get(), packet->type);
changeDeliverExtensionId(packet.get(), packet->type);
worker_->task([stream_ptr, packet]{
stream_ptr->sendPacket(packet);
});
Expand Down Expand Up @@ -677,6 +682,52 @@ void MediaStream::getJSONStats(std::function<void(std::string)> callback) {
});
}

void MediaStream::changeDeliverExtensionId(DataPacket *dp, packetType type) {
RtpHeader* h = reinterpret_cast<RtpHeader*>(dp->data);
RtcpHeader *chead = reinterpret_cast<RtcpHeader*>(dp->data);
if (!chead->isRtcp()) {
// Extension Id to external
if (h->getExtension()) {
std::array<RTPExtensions, 15> extMap;
RtpExtensionProcessor& ext_processor = getRtpExtensionProcessor();
switch (type) {
case VIDEO_PACKET:
extMap = ext_processor.getVideoExtensionMap();
break;
case AUDIO_PACKET:
extMap = ext_processor.getAudioExtensionMap();
break;
default:
ELOG_WARN("%s Won't process RTP extensions for unknown type packets", toLog());
return;
break;
}
uint16_t totalExtLength = h->getExtLength();
if (h->getExtId() == 0xBEDE) { // One-Byte Header
char* extBuffer = (char*)&h->extensions; // NOLINT
uint8_t extByte = 0;
uint16_t currentPlace = 1;
uint8_t extId = 0;
uint8_t extLength = 0;
while (currentPlace < (totalExtLength*4)) {
extByte = (uint8_t)(*extBuffer);
extId = extByte >> 4;
extLength = extByte & 0x0F;
// extId == 0 should never happen, see https://tools.ietf.org/html/rfc5285#section-4.2
lidedongsn marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 1; i < 15; i++) {
lidedongsn marked this conversation as resolved.
Show resolved Hide resolved
if (extMap.at(i) == extId) {
extBuffer[0] = (extBuffer[0] | 0xF0) & (i << 4 | 0x0F);
}
}
extBuffer = extBuffer + extLength + 2;
currentPlace = currentPlace + extLength + 2;
}
} else {
ELOG_WARN("%s Two-Byte Header not handled!", toLog());
}
}
}
}
void MediaStream::changeDeliverPayloadType(DataPacket *dp, packetType type) {
RtpHeader* h = reinterpret_cast<RtpHeader*>(dp->data);
RtcpHeader *chead = reinterpret_cast<RtcpHeader*>(dp->data);
Expand All @@ -694,6 +745,50 @@ void MediaStream::changeDeliverPayloadType(DataPacket *dp, packetType type) {
}
}

void MediaStream::parseIncomingExtensionId(char *buf, int len, packetType type) {
RtcpHeader* chead = reinterpret_cast<RtcpHeader*>(buf);
RtpHeader* h = reinterpret_cast<RtpHeader*>(buf);
if (!chead->isRtcp()) {
// Extension Id to internal
if (h->getExtension()) {
std::array<RTPExtensions, 15> extMap;
RtpExtensionProcessor& ext_processor = getRtpExtensionProcessor();
switch (type) {
case VIDEO_PACKET:
extMap = ext_processor.getVideoExtensionMap();
break;
case AUDIO_PACKET:
extMap = ext_processor.getAudioExtensionMap();
break;
default:
ELOG_WARN("%s Won't process RTP extensions for unknown type packets", toLog());
return;
break;
}
uint16_t totalExtLength = h->getExtLength();
if (h->getExtId() == 0xBEDE) { // One-Byte Header
char* extBuffer = (char*)&h->extensions; // NOLINT
uint8_t extByte = 0;
uint16_t currentPlace = 1;
uint8_t extId = 0;
uint8_t extLength = 0;
while (currentPlace < (totalExtLength*4)) {
extByte = (uint8_t)(*extBuffer);
extId = extByte >> 4;
extLength = extByte & 0x0F;
if (extId != 0 && extMap[extId] != 0) {
extBuffer[0] = (extBuffer[0] | 0xF0) & (extMap[extId] << 4 | 0x0F);
}
extBuffer = extBuffer + extLength + 2;
currentPlace = currentPlace + extLength + 2;
}
} else {
ELOG_WARN("%s Two-Byte Header not handled!", toLog());
}
}
}
}

// parses incoming payload type, replaces occurence in buf
void MediaStream::parseIncomingPayloadType(char *buf, int len, packetType type) {
RtcpHeader* chead = reinterpret_cast<RtcpHeader*>(buf);
Expand Down
2 changes: 2 additions & 0 deletions erizo/src/erizo/MediaStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class MediaStream: public MediaSink, public MediaSource, public FeedbackSink,
bool isSourceSSRC(uint32_t ssrc);
bool isSinkSSRC(uint32_t ssrc);
void parseIncomingPayloadType(char *buf, int len, packetType type);
void parseIncomingExtensionId(char *buf, int len, packetType type);

bool isPipelineInitialized() { return pipeline_initialized_; }
bool isRunning() { return pipeline_initialized_ && sending_; }
Expand All @@ -173,6 +174,7 @@ class MediaStream: public MediaSink, public MediaSource, public FeedbackSink,
void transferLayerStats(std::string spatial, std::string temporal);
void transferMediaStats(std::string target_node, std::string source_parent, std::string source_node);

void changeDeliverExtensionId(DataPacket *dp, packetType type);
void changeDeliverPayloadType(DataPacket *dp, packetType type);
// parses incoming payload type, replaces occurence in buf
uint32_t getRandomValue(uint32_t min, uint32_t max);
Expand Down
8 changes: 4 additions & 4 deletions erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ void BandwidthEstimationHandler::process() {
}, std::chrono::milliseconds(rbe_->TimeUntilNextProcess()));
}

void BandwidthEstimationHandler::updateExtensionMaps(std::array<RTPExtensions, 10> video_map,
std::array<RTPExtensions, 10> audio_map) {
void BandwidthEstimationHandler::updateExtensionMaps(std::array<RTPExtensions, 15> video_map,
std::array<RTPExtensions, 15> audio_map) {
updateExtensionMap(true, video_map);
updateExtensionMap(false, audio_map);
}

void BandwidthEstimationHandler::updateExtensionMap(bool is_video, std::array<RTPExtensions, 10> map) {
void BandwidthEstimationHandler::updateExtensionMap(bool is_video, std::array<RTPExtensions, 15> map) {
webrtc::RTPExtensionType type = webrtc::kRtpExtensionNone;
for (uint8_t id = 0; id < 10; id++) {
for (uint8_t id = 0; id < 15; id++) {
RTPExtensions extension = map[id];
switch (extension) {
case RTP_ID:
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/rtp/BandwidthEstimationHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BandwidthEstimationHandler: public Handler, public RemoteBitrateObserver,
void write(Context *ctx, std::shared_ptr<DataPacket> packet) override;
void notifyUpdate() override;

void updateExtensionMaps(std::array<RTPExtensions, 10> video_map, std::array<RTPExtensions, 10> audio_map);
void updateExtensionMaps(std::array<RTPExtensions, 15> video_map, std::array<RTPExtensions, 15> audio_map);

private:
void process();
Expand All @@ -66,7 +66,7 @@ class BandwidthEstimationHandler: public Handler, public RemoteBitrateObserver,
void pickEstimatorFromHeader();
void pickEstimator();

void updateExtensionMap(bool video, std::array<RTPExtensions, 10> map);
void updateExtensionMap(bool video, std::array<RTPExtensions, 15> map);

MediaStream *stream_;
std::shared_ptr<Worker> worker_;
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/rtp/RtpExtensionProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool RtpExtensionProcessor::isValidExtension(std::string uri) {
uint32_t RtpExtensionProcessor::processRtpExtensions(std::shared_ptr<DataPacket> p) {
const RtpHeader* head = reinterpret_cast<const RtpHeader*>(p->data);
uint32_t len = p->length;
std::array<RTPExtensions, 10> extMap;
std::array<RTPExtensions, 15> extMap;
if (head->getExtension()) {
switch (p->type) {
case VIDEO_PACKET:
Expand All @@ -92,7 +92,7 @@ uint32_t RtpExtensionProcessor::processRtpExtensions(std::shared_ptr<DataPacket>
extId = extByte >> 4;
extLength = extByte & 0x0F;
if (extId != 0 && extMap[extId] != 0) {
switch (extMap[extId]) {
switch (extId) {
case ABS_SEND_TIME:
processAbsSendTime(extBuffer);
break;
Expand Down
7 changes: 4 additions & 3 deletions erizo/src/erizo/rtp/RtpExtensionProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ class RtpExtensionProcessor{
uint32_t processRtpExtensions(std::shared_ptr<DataPacket> p);
VideoRotation getVideoRotation();

std::array<RTPExtensions, 10> getVideoExtensionMap() {
// extensions id range see https://tools.ietf.org/html/rfc5285#section-4.2
std::array<RTPExtensions, 15> getVideoExtensionMap() {
return ext_map_video_;
}
std::array<RTPExtensions, 10> getAudioExtensionMap() {
std::array<RTPExtensions, 15> getAudioExtensionMap() {
return ext_map_audio_;
}
std::vector<ExtMap> getSupportedExtensionMap() {
Expand All @@ -47,7 +48,7 @@ class RtpExtensionProcessor{

private:
std::vector<ExtMap> ext_mappings_;
std::array<RTPExtensions, 10> ext_map_video_, ext_map_audio_;
std::array<RTPExtensions, 15> ext_map_video_, ext_map_audio_;
std::map<std::string, uint8_t> translationMap_;
VideoRotation video_orientation_;
uint32_t processAbsSendTime(char* buf);
Expand Down