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

Add RTP MID extension support to identify Producers.

上级 6c27019e
...@@ -275,11 +275,23 @@ const supportedRtpCapabilities = ...@@ -275,11 +275,23 @@ const supportedRtpCapabilities =
preferredId : 4, preferredId : 4,
preferredEncrypt : false preferredEncrypt : false
}, },
{
kind : 'audio',
uri : 'urn:ietf:params:rtp-hdrext:sdes:mid',
preferredId : 5,
preferredEncrypt : false
},
{ {
kind : 'video', kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id', uri : 'urn:ietf:params:rtp-hdrext:sdes:mid',
preferredId : 5, preferredId : 5,
preferredEncrypt : false preferredEncrypt : false
},
{
kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id',
preferredId : 6,
preferredEncrypt : false
} }
], ],
fecMechanisms : [] fecMechanisms : []
......
...@@ -35,6 +35,7 @@ namespace RTC ...@@ -35,6 +35,7 @@ namespace RTC
{ {
uint8_t ssrcAudioLevel{ 0 }; // 0 means no ssrc-audio-level id. uint8_t ssrcAudioLevel{ 0 }; // 0 means no ssrc-audio-level id.
uint8_t absSendTime{ 0 }; // 0 means no abs-send-time id. uint8_t absSendTime{ 0 }; // 0 means no abs-send-time id.
uint8_t mid{ 0 }; // 0 means no MID id.
uint8_t rid{ 0 }; // 0 means no RID id. uint8_t rid{ 0 }; // 0 means no RID id.
}; };
......
...@@ -134,7 +134,8 @@ namespace RTC ...@@ -134,7 +134,8 @@ namespace RTC
TO_OFFSET = 2, TO_OFFSET = 2,
ABS_SEND_TIME = 3, ABS_SEND_TIME = 3,
VIDEO_ORIENTATION = 4, VIDEO_ORIENTATION = 4,
RTP_STREAM_ID = 5 MID = 5,
RTP_STREAM_ID = 6
}; };
private: private:
......
...@@ -117,6 +117,7 @@ namespace RTC ...@@ -117,6 +117,7 @@ namespace RTC
uint8_t* GetExtension(RTC::RtpHeaderExtensionUri::Type uri, uint8_t* len) const; uint8_t* GetExtension(RTC::RtpHeaderExtensionUri::Type uri, uint8_t* len) const;
bool ReadAudioLevel(uint8_t* volume, bool* voice) const; bool ReadAudioLevel(uint8_t* volume, bool* voice) const;
bool ReadAbsSendTime(uint32_t* time) const; bool ReadAbsSendTime(uint32_t* time) const;
bool ReadMid(const uint8_t** data, size_t* len) const;
bool ReadRid(const uint8_t** data, size_t* len) const; bool ReadRid(const uint8_t** data, size_t* len) const;
uint8_t* GetPayload() const; uint8_t* GetPayload() const;
size_t GetPayloadLength() const; size_t GetPayloadLength() const;
...@@ -342,6 +343,22 @@ namespace RTC ...@@ -342,6 +343,22 @@ namespace RTC
return true; return true;
} }
inline bool RtpPacket::ReadMid(const uint8_t** data, size_t* len) const
{
uint8_t extenLen;
uint8_t* extenValue;
extenValue = GetExtension(RTC::RtpHeaderExtensionUri::Type::MID, &extenLen);
if (!extenValue || extenLen == 0)
return false;
*data = extenValue;
*len = static_cast<size_t>(extenLen);
return true;
}
inline bool RtpPacket::ReadRid(const uint8_t** data, size_t* len) const inline bool RtpPacket::ReadRid(const uint8_t** data, size_t* len) const
{ {
uint8_t extenLen; uint8_t extenLen;
......
...@@ -49,6 +49,7 @@ namespace RTC ...@@ -49,6 +49,7 @@ namespace RTC
struct HeaderExtensionIds struct HeaderExtensionIds
{ {
uint8_t absSendTime{ 0 }; // 0 means no abs-send-time id. uint8_t absSendTime{ 0 }; // 0 means no abs-send-time id.
uint8_t mid{ 0 }; // 0 means no MID id.
uint8_t rid{ 0 }; // 0 means no RID id. uint8_t rid{ 0 }; // 0 means no RID id.
}; };
......
...@@ -283,16 +283,19 @@ namespace RTC ...@@ -283,16 +283,19 @@ namespace RTC
} }
// Apply the Transport RTP header extension ids so the RTP listener can use them. // Apply the Transport RTP header extension ids so the RTP listener can use them.
if (this->headerExtensionIds.absSendTime != 0u)
if (this->headerExtensionIds.rid != 0u)
{ {
packet->AddExtensionMapping( packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::RTP_STREAM_ID, this->headerExtensionIds.rid); RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->headerExtensionIds.absSendTime);
} }
if (this->headerExtensionIds.absSendTime != 0u) if (this->headerExtensionIds.mid != 0u)
{
packet->AddExtensionMapping(RtpHeaderExtensionUri::Type::MID, this->headerExtensionIds.mid);
}
if (this->headerExtensionIds.rid != 0u)
{ {
packet->AddExtensionMapping( packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->headerExtensionIds.absSendTime); RtpHeaderExtensionUri::Type::RTP_STREAM_ID, this->headerExtensionIds.rid);
} }
// Get the associated Producer. // Get the associated Producer.
......
...@@ -385,6 +385,7 @@ namespace RTC ...@@ -385,6 +385,7 @@ namespace RTC
auto& idMapping = this->rtpMapping.headerExtensionIds; auto& idMapping = this->rtpMapping.headerExtensionIds;
uint8_t ssrcAudioLevelId{ 0 }; uint8_t ssrcAudioLevelId{ 0 };
uint8_t absSendTimeId{ 0 }; uint8_t absSendTimeId{ 0 };
uint8_t midId{ 0 };
uint8_t ridId{ 0 }; uint8_t ridId{ 0 };
for (auto& exten : this->rtpParameters.headerExtensions) for (auto& exten : this->rtpParameters.headerExtensions)
...@@ -412,6 +413,17 @@ namespace RTC ...@@ -412,6 +413,17 @@ namespace RTC
this->transportHeaderExtensionIds.absSendTime = exten.id; this->transportHeaderExtensionIds.absSendTime = exten.id;
} }
if ((midId == 0u) && exten.type == RTC::RtpHeaderExtensionUri::Type::MID)
{
if (idMapping.find(exten.id) != idMapping.end())
midId = idMapping[exten.id];
else
midId = exten.id;
this->headerExtensionIds.mid = midId;
this->transportHeaderExtensionIds.mid = exten.id;
}
if ((ridId == 0u) && exten.type == RTC::RtpHeaderExtensionUri::Type::RTP_STREAM_ID) if ((ridId == 0u) && exten.type == RTC::RtpHeaderExtensionUri::Type::RTP_STREAM_ID)
{ {
if (idMapping.find(exten.id) != idMapping.end()) if (idMapping.find(exten.id) != idMapping.end())
...@@ -452,8 +464,6 @@ namespace RTC ...@@ -452,8 +464,6 @@ namespace RTC
} }
} }
// TODO: Look for muxId.
// If not found, look for encodings with encodingId (RID) field. // If not found, look for encodings with encodingId (RID) field.
{ {
const uint8_t* ridPtr; const uint8_t* ridPtr;
......
...@@ -16,6 +16,7 @@ namespace RTC ...@@ -16,6 +16,7 @@ namespace RTC
{ "urn:ietf:params:rtp-hdrext:toffset", RtpHeaderExtensionUri::Type::TO_OFFSET }, { "urn:ietf:params:rtp-hdrext:toffset", RtpHeaderExtensionUri::Type::TO_OFFSET },
{ "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", RtpHeaderExtensionUri::Type::ABS_SEND_TIME }, { "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", RtpHeaderExtensionUri::Type::ABS_SEND_TIME },
{ "urn:3gpp:video-orientation", RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION }, { "urn:3gpp:video-orientation", RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION },
{ "urn:ietf:params:rtp-hdrext:sdes:mid", RtpHeaderExtensionUri::Type::MID },
{ "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id", RtpHeaderExtensionUri::Type::RTP_STREAM_ID } { "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id", RtpHeaderExtensionUri::Type::RTP_STREAM_ID }
}; };
// clang-format on // clang-format on
......
...@@ -264,7 +264,27 @@ namespace RTC ...@@ -264,7 +264,27 @@ namespace RTC
} }
// Otherwise lookup into the muxId table. // Otherwise lookup into the muxId table.
// TODO: Do it. {
const uint8_t* muxIdPtr;
size_t muxIdLen;
if (packet->ReadMid(&muxIdPtr, &muxIdLen))
{
auto* charMuxIdPtr = const_cast<char*>(reinterpret_cast<const char*>(muxIdPtr));
std::string muxId(charMuxIdPtr, muxIdLen);
auto it = this->muxIdTable.find(muxId);
if (it != this->muxIdTable.end())
{
auto producer = it->second;
// Fill the ssrc table.
this->ssrcTable[packet->GetSsrc()] = producer;
return producer;
}
}
}
// Otherwise lookup into the RID table. // Otherwise lookup into the RID table.
{ {
......
...@@ -160,15 +160,14 @@ namespace RTC ...@@ -160,15 +160,14 @@ namespace RTC
// and add them to the Transport. // and add them to the Transport.
if (producer->GetTransportHeaderExtensionIds().absSendTime != 0u) if (producer->GetTransportHeaderExtensionIds().absSendTime != 0u)
{
this->headerExtensionIds.absSendTime = producer->GetTransportHeaderExtensionIds().absSendTime; this->headerExtensionIds.absSendTime = producer->GetTransportHeaderExtensionIds().absSendTime;
}
if (producer->GetTransportHeaderExtensionIds().mid != 0u)
this->headerExtensionIds.mid = producer->GetTransportHeaderExtensionIds().mid;
if (producer->GetTransportHeaderExtensionIds().rid != 0u) if (producer->GetTransportHeaderExtensionIds().rid != 0u)
{
this->headerExtensionIds.rid = producer->GetTransportHeaderExtensionIds().rid; this->headerExtensionIds.rid = producer->GetTransportHeaderExtensionIds().rid;
} }
}
void Transport::HandleConsumer(RTC::Consumer* consumer) void Transport::HandleConsumer(RTC::Consumer* consumer)
{ {
......
...@@ -255,6 +255,7 @@ namespace RTC ...@@ -255,6 +255,7 @@ namespace RTC
static const Json::StaticString JsonStringFailed{ "failed" }; static const Json::StaticString JsonStringFailed{ "failed" };
static const Json::StaticString JsonStringHeaderExtensionIds{ "headerExtensionIds" }; static const Json::StaticString JsonStringHeaderExtensionIds{ "headerExtensionIds" };
static const Json::StaticString JsonStringAbsSendTime{ "absSendTime" }; static const Json::StaticString JsonStringAbsSendTime{ "absSendTime" };
static const Json::StaticString JsonStringMid{ "mid" };
static const Json::StaticString JsonStringRid{ "rid" }; static const Json::StaticString JsonStringRid{ "rid" };
static const Json::StaticString JsonStringRtpListener{ "rtpListener" }; static const Json::StaticString JsonStringRtpListener{ "rtpListener" };
...@@ -345,6 +346,9 @@ namespace RTC ...@@ -345,6 +346,9 @@ namespace RTC
if (this->headerExtensionIds.absSendTime != 0u) if (this->headerExtensionIds.absSendTime != 0u)
jsonHeaderExtensionIds[JsonStringAbsSendTime] = this->headerExtensionIds.absSendTime; jsonHeaderExtensionIds[JsonStringAbsSendTime] = this->headerExtensionIds.absSendTime;
if (this->headerExtensionIds.mid != 0u)
jsonHeaderExtensionIds[JsonStringMid] = this->headerExtensionIds.mid;
if (this->headerExtensionIds.rid != 0u) if (this->headerExtensionIds.rid != 0u)
jsonHeaderExtensionIds[JsonStringRid] = this->headerExtensionIds.rid; jsonHeaderExtensionIds[JsonStringRid] = this->headerExtensionIds.rid;
...@@ -856,15 +860,19 @@ namespace RTC ...@@ -856,15 +860,19 @@ namespace RTC
} }
// Apply the Transport RTP header extension ids so the RTP listener can use them. // Apply the Transport RTP header extension ids so the RTP listener can use them.
if (this->headerExtensionIds.rid != 0u) if (this->headerExtensionIds.absSendTime != 0u)
{ {
packet->AddExtensionMapping( packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::RTP_STREAM_ID, this->headerExtensionIds.rid); RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->headerExtensionIds.absSendTime);
} }
if (this->headerExtensionIds.absSendTime != 0u) if (this->headerExtensionIds.mid != 0u)
{
packet->AddExtensionMapping(RtpHeaderExtensionUri::Type::MID, this->headerExtensionIds.mid);
}
if (this->headerExtensionIds.rid != 0u)
{ {
packet->AddExtensionMapping( packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->headerExtensionIds.absSendTime); RtpHeaderExtensionUri::Type::RTP_STREAM_ID, this->headerExtensionIds.rid);
} }
// Feed the remote bitrate estimator (REMB). // Feed the remote bitrate estimator (REMB).
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论