提交 92504600 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Lot of work in Producer and RTP mapping

上级 e490be12
......@@ -107,6 +107,7 @@ namespace RTC
uint16_t GetExtensionHeaderId() const;
size_t GetExtensionHeaderLength() const;
uint8_t* GetExtensionHeaderValue() const;
void MangleExtensionHeaderIds(std::map<uint8_t, uint8_t>& idMapping);
bool HasOneByteExtensions() const;
bool HasTwoBytesExtensions() const;
void AddExtensionMapping(RtpHeaderExtensionUri::Type uri, uint8_t id);
......@@ -293,7 +294,7 @@ namespace RTC
if (this->twoBytesExtensions.find(id) == this->twoBytesExtensions.end())
return nullptr;
*len = this->twoByteExtensions.at(id)->len;
*len = this->twoBytesExtensions.at(id)->len;
return this->twoBytesExtensions.at(id)->value;
}
......
......@@ -264,32 +264,28 @@ namespace RTC
RTC::RtpStreamRecv* rtpStream{ nullptr };
if (this->rtpStreams.find(ssrc) == this->rtpStreams.end())
if (this->rtpStreams.find(ssrc) != this->rtpStreams.end())
{
if (this->rtxStreamMap.find(ssrc) == this->rtxStreamMap.end())
{
MS_WARN_TAG(rtp, "no RtpStream found for given RTP packet [ssrc:%" PRIu32 "]", ssrc);
rtpStream = this->rtpStreams[ssrc];
// Process the packet.
if (!rtpStream->ReceivePacket(packet))
return;
}
else
{
rtpStream = this->rtxStreamMap[ssrc];
// Process the packet.
if (!rtpStream->ReceiveRtxPacket(packet))
return;
}
}
else
else if (this->rtxStreamMap.find(ssrc) != this->rtxStreamMap.end())
{
rtpStream = this->rtpStreams[ssrc];
rtpStream = this->rtxStreamMap[ssrc];
// Process the packet.
if (!rtpStream->ReceivePacket(packet))
if (!rtpStream->ReceiveRtxPacket(packet))
return;
}
else
{
MS_WARN_TAG(rtp, "no RtpStream found for given RTP packet [ssrc:%" PRIu32 "]", ssrc);
return;
}
// Apply the Producer RTP mapping before dispatching the packet to the Room.
ApplyRtpMapping(packet);
......@@ -410,14 +406,8 @@ namespace RTC
for (auto& pair : rtpMapping[JsonStringCodecPayloadTypes])
{
if (
!pair.isArray() ||
pair.size() != 2 ||
!pair[0].isUInt() ||
!pair[1].isUInt())
{
if (!pair.isArray() || pair.size() != 2 || !pair[0].isUInt() || !pair[1].isUInt())
MS_THROW_ERROR("wrong rtpMapping entry");
}
auto sourcePayloadType = static_cast<uint8_t>(pair[0].asUInt());
auto mappedPayloadType = static_cast<uint8_t>(pair[1].asUInt());
......@@ -427,14 +417,8 @@ namespace RTC
for (auto& pair : rtpMapping[JsonStringHeaderExtensionIds])
{
if (
!pair.isArray() ||
pair.size() != 2 ||
!pair[0].isUInt() ||
!pair[1].isUInt())
{
if (!pair.isArray() || pair.size() != 2 || !pair[0].isUInt() || !pair[1].isUInt())
MS_THROW_ERROR("wrong rtpMapping entry");
}
auto sourceHeaderExtensionId = static_cast<uint8_t>(pair[0].asUInt());
auto mappedHeaderExtensionId = static_cast<uint8_t>(pair[1].asUInt());
......@@ -443,9 +427,10 @@ namespace RTC
mappedHeaderExtensionId;
}
// Also, fill the RTP header extensions ids with the mapped valules.
// Also, fill the id of well known RTP header extensions with the mapped ids
// (if any).
auto& headerExtensionIds = this->rtpMapping.headerExtensionIds;
auto& idMapping = this->rtpMapping.headerExtensionIds;
uint8_t ssrcAudioLevelId{ 0 };
uint8_t absSendTimeId{ 0 };
......@@ -454,8 +439,8 @@ namespace RTC
if (this->kind == RTC::Media::Kind::AUDIO && (ssrcAudioLevelId == 0u) &&
exten.type == RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL)
{
if (headerExtensionIds.find(exten.id) != headerExtensionIds.end())
ssrcAudioLevelId = headerExtensionIds[exten.id];
if (idMapping.find(exten.id) != idMapping.end())
ssrcAudioLevelId = idMapping[exten.id];
else
ssrcAudioLevelId = exten.id;
......@@ -464,8 +449,8 @@ namespace RTC
if ((absSendTimeId == 0u) && exten.type == RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME)
{
if (headerExtensionIds.find(exten.id) != headerExtensionIds.end())
absSendTimeId = headerExtensionIds[exten.id];
if (idMapping.find(exten.id) != idMapping.end())
absSendTimeId = idMapping[exten.id];
else
absSendTimeId = exten.id;
......@@ -631,15 +616,33 @@ namespace RTC
{
MS_TRACE();
auto& codecPayloadTypes = this->rtpMapping.codecPayloadTypes;
auto& headerExtensionIds = this->rtpMapping.headerExtensionIds;
auto& codecPayloadTypeMap = this->rtpMapping.codecPayloadTypes;
auto& headerExtensionIdMap = this->rtpMapping.headerExtensionIds;
auto payloadType = packet->GetPayloadType();
if (codecPayloadTypes.find(payloadType) != codecPayloadTypes.end())
// Mangle payload type.
if (codecPayloadTypeMap.find(payloadType) != codecPayloadTypeMap.end())
{
packet->SetPayloadType(codecPayloadTypeMap[payloadType]);
}
// Mangle header extension ids.
packet->MangleExtensionHeaderIds(headerExtensionIdMap);
if (this->knownHeaderExtensions.ssrcAudioLevelId)
{
packet->SetPayloadType(codecPayloadTypes[payloadType]);
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL,
this->knownHeaderExtensions.ssrcAudioLevelId);
}
// TODO: Mangle header extension ids.
if (this->knownHeaderExtensions.absSendTimeId)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME,
this->knownHeaderExtensions.absSendTimeId);
}
}
} // namespace RTC
#define MS_CLASS "RTC::RtpPacket"
#define MS_LOG_DEV
#define MS_LOG_DEV // TODO: TMP
#include "RTC/RtpPacket.hpp"
#include "Logger.hpp"
#include <vector>
#include <iterator> // std::ostream_iterator
#include <sstream> // std::ostringstream
#include <cstring> // std::memcpy()
namespace RTC
......@@ -152,27 +155,95 @@ namespace RTC
MS_TRACE();
MS_DUMP("<RtpPacket>");
MS_DUMP(" padding : %s", this->header->padding ? "true" : "false");
MS_DUMP(" extension header : %s", HasExtensionHeader() ? "true" : "false");
MS_DUMP(" padding : %s", this->header->padding ? "true" : "false");
MS_DUMP(" extension header : %s", HasExtensionHeader() ? "true" : "false");
if (HasExtensionHeader())
{
MS_DUMP(" id : %" PRIu16, GetExtensionHeaderId());
MS_DUMP(" length : %zu bytes", GetExtensionHeaderLength());
MS_DUMP(" id : %" PRIu16, GetExtensionHeaderId());
MS_DUMP(" length : %zu bytes", GetExtensionHeaderLength());
}
MS_DUMP(" csrc count : %" PRIu8, this->header->csrcCount);
MS_DUMP(" marker : %s", HasMarker() ? "true" : "false");
MS_DUMP(" payload type : %" PRIu8, GetPayloadType());
MS_DUMP(" sequence number : %" PRIu16, GetSequenceNumber());
MS_DUMP(" timestamp : %" PRIu32, GetTimestamp());
MS_DUMP(" ssrc : %" PRIu32, GetSsrc());
MS_DUMP(" payload size : %zu bytes", GetPayloadLength());
if (HasOneByteExtensions())
{
MS_DUMP(" RFC5285 ext style : One-Byte Header");
}
if (HasTwoBytesExtensions())
{
MS_DUMP(" RFC5285 ext style : Two-Bytes Header");
}
if (HasOneByteExtensions() || HasTwoBytesExtensions())
{
std::vector<std::string> extIds;
std::ostringstream extIdsStream;
if (HasOneByteExtensions())
{
for (const auto& pair : this->oneByteExtensions)
extIds.push_back(std::to_string(pair.first));
}
else
{
for (const auto& pair : this->twoBytesExtensions)
extIds.push_back(std::to_string(pair.first));
}
std::copy(
extIds.begin(), extIds.end() - 1, std::ostream_iterator<std::string>(extIdsStream, ","));
extIdsStream << extIds.back();
MS_DUMP(" RFC5285 ext ids : %s", extIdsStream.str().c_str());
}
MS_DUMP(" csrc count : %" PRIu8, this->header->csrcCount);
MS_DUMP(" marker : %s", HasMarker() ? "true" : "false");
MS_DUMP(" payload type : %" PRIu8, GetPayloadType());
MS_DUMP(" sequence number : %" PRIu16, GetSequenceNumber());
MS_DUMP(" timestamp : %" PRIu32, GetTimestamp());
MS_DUMP(" ssrc : %" PRIu32, GetSsrc());
MS_DUMP(" payload size : %zu bytes", GetPayloadLength());
if (this->header->padding)
{
MS_DUMP(" padding size : %" PRIu8 " bytes", this->payloadPadding);
MS_DUMP(" padding size : %" PRIu8 " bytes", this->payloadPadding);
}
MS_DUMP("</RtpPacket>");
}
void RtpPacket::MangleExtensionHeaderIds(std::map<uint8_t, uint8_t>& idMapping)
{
MS_TRACE();
if (HasOneByteExtensions())
{
for (const auto& pair : this->oneByteExtensions)
{
auto& id = pair.first;
auto& oneByteExtension = pair.second;
if (idMapping.find(id) != idMapping.end())
{
oneByteExtension->id = idMapping[id];
}
}
}
else if (HasTwoBytesExtensions())
{
for (const auto& pair : this->twoBytesExtensions)
{
auto& id = pair.first;
auto& twoBytesExtension = pair.second;
if (idMapping.find(id) != idMapping.end())
{
twoBytesExtension->id = idMapping[id];
}
}
}
// Clear the URI to id map.
this->extensionMap.clear();
// Parse extensions again.
ParseExtensions();
}
void RtpPacket::Serialize(uint8_t* buffer)
{
MS_TRACE();
......
......@@ -3,6 +3,7 @@
#include "common.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpDictionaries.hpp"
#include <map>
using namespace RTC;
......@@ -159,6 +160,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
REQUIRE(packet->ReadAbsSendTime(&absSendTime) == true);
REQUIRE(absSendTime == 0x65341e);
std::map<uint8_t, uint8_t> idMapping;
idMapping[1] = 11;
idMapping[3] = 13;
packet->MangleExtensionHeaderIds(idMapping);
packet->AddExtensionMapping(RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, 11);
packet->AddExtensionMapping(RtpHeaderExtensionUri::Type::ABS_SEND_TIME, 13);
auto clonedPacket = packet->Clone(buffer2);
delete packet;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论