提交 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 ...@@ -107,6 +107,7 @@ namespace RTC
uint16_t GetExtensionHeaderId() const; uint16_t GetExtensionHeaderId() const;
size_t GetExtensionHeaderLength() const; size_t GetExtensionHeaderLength() const;
uint8_t* GetExtensionHeaderValue() const; uint8_t* GetExtensionHeaderValue() const;
void MangleExtensionHeaderIds(std::map<uint8_t, uint8_t>& idMapping);
bool HasOneByteExtensions() const; bool HasOneByteExtensions() const;
bool HasTwoBytesExtensions() const; bool HasTwoBytesExtensions() const;
void AddExtensionMapping(RtpHeaderExtensionUri::Type uri, uint8_t id); void AddExtensionMapping(RtpHeaderExtensionUri::Type uri, uint8_t id);
...@@ -293,7 +294,7 @@ namespace RTC ...@@ -293,7 +294,7 @@ namespace RTC
if (this->twoBytesExtensions.find(id) == this->twoBytesExtensions.end()) if (this->twoBytesExtensions.find(id) == this->twoBytesExtensions.end())
return nullptr; return nullptr;
*len = this->twoByteExtensions.at(id)->len; *len = this->twoBytesExtensions.at(id)->len;
return this->twoBytesExtensions.at(id)->value; return this->twoBytesExtensions.at(id)->value;
} }
......
...@@ -264,16 +264,15 @@ namespace RTC ...@@ -264,16 +264,15 @@ namespace RTC
RTC::RtpStreamRecv* rtpStream{ nullptr }; 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; return;
} }
else if (this->rtxStreamMap.find(ssrc) != this->rtxStreamMap.end())
else
{ {
rtpStream = this->rtxStreamMap[ssrc]; rtpStream = this->rtxStreamMap[ssrc];
...@@ -281,13 +280,10 @@ namespace RTC ...@@ -281,13 +280,10 @@ namespace RTC
if (!rtpStream->ReceiveRtxPacket(packet)) if (!rtpStream->ReceiveRtxPacket(packet))
return; return;
} }
}
else else
{ {
rtpStream = this->rtpStreams[ssrc]; MS_WARN_TAG(rtp, "no RtpStream found for given RTP packet [ssrc:%" PRIu32 "]", ssrc);
// Process the packet.
if (!rtpStream->ReceivePacket(packet))
return; return;
} }
...@@ -410,14 +406,8 @@ namespace RTC ...@@ -410,14 +406,8 @@ namespace RTC
for (auto& pair : rtpMapping[JsonStringCodecPayloadTypes]) for (auto& pair : rtpMapping[JsonStringCodecPayloadTypes])
{ {
if ( if (!pair.isArray() || pair.size() != 2 || !pair[0].isUInt() || !pair[1].isUInt())
!pair.isArray() ||
pair.size() != 2 ||
!pair[0].isUInt() ||
!pair[1].isUInt())
{
MS_THROW_ERROR("wrong rtpMapping entry"); MS_THROW_ERROR("wrong rtpMapping entry");
}
auto sourcePayloadType = static_cast<uint8_t>(pair[0].asUInt()); auto sourcePayloadType = static_cast<uint8_t>(pair[0].asUInt());
auto mappedPayloadType = static_cast<uint8_t>(pair[1].asUInt()); auto mappedPayloadType = static_cast<uint8_t>(pair[1].asUInt());
...@@ -427,14 +417,8 @@ namespace RTC ...@@ -427,14 +417,8 @@ namespace RTC
for (auto& pair : rtpMapping[JsonStringHeaderExtensionIds]) for (auto& pair : rtpMapping[JsonStringHeaderExtensionIds])
{ {
if ( if (!pair.isArray() || pair.size() != 2 || !pair[0].isUInt() || !pair[1].isUInt())
!pair.isArray() ||
pair.size() != 2 ||
!pair[0].isUInt() ||
!pair[1].isUInt())
{
MS_THROW_ERROR("wrong rtpMapping entry"); MS_THROW_ERROR("wrong rtpMapping entry");
}
auto sourceHeaderExtensionId = static_cast<uint8_t>(pair[0].asUInt()); auto sourceHeaderExtensionId = static_cast<uint8_t>(pair[0].asUInt());
auto mappedHeaderExtensionId = static_cast<uint8_t>(pair[1].asUInt()); auto mappedHeaderExtensionId = static_cast<uint8_t>(pair[1].asUInt());
...@@ -443,9 +427,10 @@ namespace RTC ...@@ -443,9 +427,10 @@ namespace RTC
mappedHeaderExtensionId; 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 ssrcAudioLevelId{ 0 };
uint8_t absSendTimeId{ 0 }; uint8_t absSendTimeId{ 0 };
...@@ -454,8 +439,8 @@ namespace RTC ...@@ -454,8 +439,8 @@ namespace RTC
if (this->kind == RTC::Media::Kind::AUDIO && (ssrcAudioLevelId == 0u) && if (this->kind == RTC::Media::Kind::AUDIO && (ssrcAudioLevelId == 0u) &&
exten.type == RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL) exten.type == RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL)
{ {
if (headerExtensionIds.find(exten.id) != headerExtensionIds.end()) if (idMapping.find(exten.id) != idMapping.end())
ssrcAudioLevelId = headerExtensionIds[exten.id]; ssrcAudioLevelId = idMapping[exten.id];
else else
ssrcAudioLevelId = exten.id; ssrcAudioLevelId = exten.id;
...@@ -464,8 +449,8 @@ namespace RTC ...@@ -464,8 +449,8 @@ namespace RTC
if ((absSendTimeId == 0u) && exten.type == RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME) if ((absSendTimeId == 0u) && exten.type == RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME)
{ {
if (headerExtensionIds.find(exten.id) != headerExtensionIds.end()) if (idMapping.find(exten.id) != idMapping.end())
absSendTimeId = headerExtensionIds[exten.id]; absSendTimeId = idMapping[exten.id];
else else
absSendTimeId = exten.id; absSendTimeId = exten.id;
...@@ -631,15 +616,33 @@ namespace RTC ...@@ -631,15 +616,33 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
auto& codecPayloadTypes = this->rtpMapping.codecPayloadTypes; auto& codecPayloadTypeMap = this->rtpMapping.codecPayloadTypes;
auto& headerExtensionIds = this->rtpMapping.headerExtensionIds; auto& headerExtensionIdMap = this->rtpMapping.headerExtensionIds;
auto payloadType = packet->GetPayloadType(); auto payloadType = packet->GetPayloadType();
if (codecPayloadTypes.find(payloadType) != codecPayloadTypes.end()) // Mangle payload type.
if (codecPayloadTypeMap.find(payloadType) != codecPayloadTypeMap.end())
{ {
packet->SetPayloadType(codecPayloadTypes[payloadType]); packet->SetPayloadType(codecPayloadTypeMap[payloadType]);
} }
// TODO: Mangle header extension ids. // Mangle header extension ids.
packet->MangleExtensionHeaderIds(headerExtensionIdMap);
if (this->knownHeaderExtensions.ssrcAudioLevelId)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL,
this->knownHeaderExtensions.ssrcAudioLevelId);
}
if (this->knownHeaderExtensions.absSendTimeId)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME,
this->knownHeaderExtensions.absSendTimeId);
}
} }
} // namespace RTC } // namespace RTC
#define MS_CLASS "RTC::RtpPacket" #define MS_CLASS "RTC::RtpPacket"
#define MS_LOG_DEV #define MS_LOG_DEV // TODO: TMP
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include <vector>
#include <iterator> // std::ostream_iterator
#include <sstream> // std::ostringstream
#include <cstring> // std::memcpy() #include <cstring> // std::memcpy()
namespace RTC namespace RTC
...@@ -159,6 +162,36 @@ namespace RTC ...@@ -159,6 +162,36 @@ namespace RTC
MS_DUMP(" id : %" PRIu16, GetExtensionHeaderId()); MS_DUMP(" id : %" PRIu16, GetExtensionHeaderId());
MS_DUMP(" length : %zu bytes", GetExtensionHeaderLength()); MS_DUMP(" length : %zu bytes", GetExtensionHeaderLength());
} }
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(" csrc count : %" PRIu8, this->header->csrcCount);
MS_DUMP(" marker : %s", HasMarker() ? "true" : "false"); MS_DUMP(" marker : %s", HasMarker() ? "true" : "false");
MS_DUMP(" payload type : %" PRIu8, GetPayloadType()); MS_DUMP(" payload type : %" PRIu8, GetPayloadType());
...@@ -173,6 +206,44 @@ namespace RTC ...@@ -173,6 +206,44 @@ namespace RTC
MS_DUMP("</RtpPacket>"); 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) void RtpPacket::Serialize(uint8_t* buffer)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include <map>
using namespace RTC; using namespace RTC;
...@@ -159,6 +160,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -159,6 +160,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
REQUIRE(packet->ReadAbsSendTime(&absSendTime) == true); REQUIRE(packet->ReadAbsSendTime(&absSendTime) == true);
REQUIRE(absSendTime == 0x65341e); 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); auto clonedPacket = packet->Clone(buffer2);
delete packet; delete packet;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论