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

worker: Apply RTP extension id mapping into the packet before passing it to the Producer.

上级 ed8e46c8
...@@ -64,6 +64,7 @@ namespace RTC ...@@ -64,6 +64,7 @@ namespace RTC
void SetRtpObjectEvent(bool enabled); void SetRtpObjectEvent(bool enabled);
const RTC::RtpParameters& GetParameters() const; const RTC::RtpParameters& GetParameters() const;
bool IsPaused() const; bool IsPaused() const;
void ApplyExtensionIdMapping(RTC::RtpPacket* packet) const;
void ReceiveRtpPacket(RTC::RtpPacket* packet); void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
...@@ -75,8 +76,8 @@ namespace RTC ...@@ -75,8 +76,8 @@ namespace RTC
void FillKnownHeaderExtensions(); void FillKnownHeaderExtensions();
void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void ClearRtpStreams(); void ClearRtpStreams();
void ApplyRtpMapping(RTC::RtpPacket* packet); void ApplyPayloadTypeMapping(RTC::RtpPacket* packet) const;
void ApplySsrcMapping(RTC::RtpPacket* packet); void ApplySsrcMapping(RTC::RtpPacket* packet) const;
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public: public:
......
...@@ -107,7 +107,7 @@ namespace RTC ...@@ -107,7 +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); void MangleExtensionHeaderIds(const 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,8 +293,9 @@ namespace RTC ...@@ -293,8 +293,9 @@ namespace RTC
if (this->paused) if (this->paused)
return; return;
// Apply the Producer RTP and SSRC mapping before dispatching the packet. // Apply the Producer codec payload type and SSRC mapping before dispatching
ApplyRtpMapping(packet); // the packet.
ApplyPayloadTypeMapping(packet);
ApplySsrcMapping(packet); ApplySsrcMapping(packet);
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
...@@ -344,6 +345,27 @@ namespace RTC ...@@ -344,6 +345,27 @@ namespace RTC
this->lastRtcpSentTime = now; this->lastRtcpSentTime = now;
} }
void Producer::ApplyExtensionIdMapping(RTC::RtpPacket* packet) const
{
MS_TRACE();
auto& headerExtensionIdMap = this->rtpMapping.headerExtensionIds;
packet->MangleExtensionHeaderIds(headerExtensionIdMap);
if (this->knownHeaderExtensions.ssrcAudioLevelId != 0u)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, this->knownHeaderExtensions.ssrcAudioLevelId);
}
if (this->knownHeaderExtensions.absSendTimeId != 0u)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->knownHeaderExtensions.absSendTimeId);
}
}
void Producer::ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const void Producer::ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const
{ {
MS_TRACE(); MS_TRACE();
...@@ -538,47 +560,27 @@ namespace RTC ...@@ -538,47 +560,27 @@ namespace RTC
this->rtpStreams.clear(); this->rtpStreams.clear();
} }
void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) void Producer::ApplyPayloadTypeMapping(RTC::RtpPacket* packet) const
{ {
MS_TRACE(); MS_TRACE();
auto& codecPayloadTypeMap = this->rtpMapping.codecPayloadTypes; auto& codecPayloadTypeMap = this->rtpMapping.codecPayloadTypes;
auto& headerExtensionIdMap = this->rtpMapping.headerExtensionIds; auto payloadType = packet->GetPayloadType();
auto payloadType = packet->GetPayloadType();
// Mangle payload type.
if (codecPayloadTypeMap.find(payloadType) != codecPayloadTypeMap.end()) if (codecPayloadTypeMap.find(payloadType) != codecPayloadTypeMap.end())
{ {
packet->SetPayloadType(codecPayloadTypeMap[payloadType]); packet->SetPayloadType(codecPayloadTypeMap.at(payloadType));
}
// Mangle header extension ids.
packet->MangleExtensionHeaderIds(headerExtensionIdMap);
if (this->knownHeaderExtensions.ssrcAudioLevelId != 0u)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, this->knownHeaderExtensions.ssrcAudioLevelId);
}
if (this->knownHeaderExtensions.absSendTimeId != 0u)
{
packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->knownHeaderExtensions.absSendTimeId);
} }
} }
void Producer::ApplySsrcMapping(RTC::RtpPacket* packet) void Producer::ApplySsrcMapping(RTC::RtpPacket* packet) const
{ {
MS_TRACE(); MS_TRACE();
auto ssrc = packet->GetSsrc(); auto ssrc = packet->GetSsrc();
// Mangle SSRC.
if (this->ssrcMapping.find(ssrc) != this->ssrcMapping.end()) if (this->ssrcMapping.find(ssrc) != this->ssrcMapping.end())
packet->SetSsrc(this->ssrcMapping[ssrc]); packet->SetSsrc(this->ssrcMapping.at(ssrc));
} }
void Producer::OnRtpStreamRecvNackRequired( void Producer::OnRtpStreamRecvNackRequired(
......
...@@ -206,7 +206,7 @@ namespace RTC ...@@ -206,7 +206,7 @@ namespace RTC
MS_DUMP("</RtpPacket>"); MS_DUMP("</RtpPacket>");
} }
void RtpPacket::MangleExtensionHeaderIds(std::map<uint8_t, uint8_t>& idMapping) void RtpPacket::MangleExtensionHeaderIds(const std::map<uint8_t, uint8_t>& idMapping)
{ {
MS_TRACE(); MS_TRACE();
...@@ -219,7 +219,7 @@ namespace RTC ...@@ -219,7 +219,7 @@ namespace RTC
if (idMapping.find(id) != idMapping.end()) if (idMapping.find(id) != idMapping.end())
{ {
oneByteExtension->id = idMapping[id]; oneByteExtension->id = idMapping.at(id);
} }
} }
} }
...@@ -232,7 +232,7 @@ namespace RTC ...@@ -232,7 +232,7 @@ namespace RTC
if (idMapping.find(id) != idMapping.end()) if (idMapping.find(id) != idMapping.end())
{ {
twoBytesExtension->id = idMapping[id]; twoBytesExtension->id = idMapping.at(id);
} }
} }
} }
......
...@@ -1112,8 +1112,9 @@ namespace RTC ...@@ -1112,8 +1112,9 @@ namespace RTC
// Trick for clients performing aggressive ICE regardless we are ICE-Lite. // Trick for clients performing aggressive ICE regardless we are ICE-Lite.
this->iceServer->ForceSelectedTuple(tuple); this->iceServer->ForceSelectedTuple(tuple);
// Pass the RTP packet to the corresponding Producer. // Apply the RTP header extension mapping into the packet (we need it for the
producer->ReceiveRtpPacket(packet); // bitrate estimator).
producer->ApplyExtensionIdMapping(packet);
// Feed the remote bitrate estimator (REMB). // Feed the remote bitrate estimator (REMB).
if (this->remoteBitrateEstimator) if (this->remoteBitrateEstimator)
...@@ -1127,6 +1128,9 @@ namespace RTC ...@@ -1127,6 +1128,9 @@ namespace RTC
} }
} }
// Pass the RTP packet to the corresponding Producer.
producer->ReceiveRtpPacket(packet);
delete packet; delete packet;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论