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

Consumer: handle its own output media SSRC.

上级 4d679eda
# TODO in mediasoup v2 (server-side)
* Remote `producer.on('rtprawpacket')` and, instead, create a special `RtpConsumer` or something like that.
* Must avoid passing JSON data to Transport/Producer/Consumer instance methods. Instead, create API methods that receive "nice" C++ params and do all the JSON decode work in `Router::HandleRequest()`.
* Must mangle RTP sequence numbers in Consumers:
......
......@@ -623,7 +623,7 @@ class Peer extends EnhancedEventEmitter
source : producer
};
// Create a Producer instance.
// Create a Consumer instance.
const consumer = new Consumer(internal, data, this._channel);
consumer.appData = producer.appData;
......
......@@ -262,10 +262,6 @@ exports.getProducerRtpParametersMapping = function(params, caps)
* and the RTP capabilities of the Room.
* It may throw if invalid or non supported RTP parameters are given.
*
* TODO: This method should also reduce encodings in case of simulcast/SVC
* so the resulting consumable RTP parameters are suitable for a Consumer.
* For now we assume a single encoding in the Producer RTP parameters.
*
* @param {RTCRtpParameters} params
* @param {RTCRtpCapabilities} caps
* @param {Object} rtpMapping - As generated by getProducerRtpParametersMapping().
......@@ -379,7 +375,7 @@ exports.getConsumableRtpParameters = function(params, caps, rtpMapping)
/**
* Generate RTP parameters for a specific Consumer.
*
* NOTE: It's up to theremote Consumer to check the codecs and decide whether it
* NOTE: It's up to the remote Consumer to check the codecs and decide whether it
* can enable this Consumer or not.
*
* @param {RTCRtpParameters} consumableRtpParameters - Consumable RTP parameters.
......@@ -427,7 +423,7 @@ exports.getConsumerRtpParameters = function(consumableRtpParameters, rtpCapabili
const consumerEncoding =
{
ssrc : consumableRtpParameters.encodings[0].ssrc
ssrc : utils.randomNumber()
};
if (rtxSupported)
......
......@@ -64,7 +64,6 @@ namespace RTC
void SetRtpObjectEvent(bool enabled);
const RTC::RtpParameters& GetParameters() const;
bool IsPaused() const;
void ApplyExtensionIdMapping(RTC::RtpPacket* packet) const;
void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
......@@ -76,8 +75,7 @@ namespace RTC
void FillKnownHeaderExtensions();
void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void ClearRtpStreams();
void ApplyPayloadTypeMapping(RTC::RtpPacket* packet) const;
void ApplySsrcMapping(RTC::RtpPacket* packet) const;
void ApplyRtpMapping(RTC::RtpPacket* packet) const;
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public:
......@@ -108,7 +106,6 @@ namespace RTC
// Others.
std::vector<RtpEncodingParameters> outputEncodings;
struct KnownHeaderExtensions knownHeaderExtensions;
std::map<uint32_t, uint32_t> ssrcMapping;
bool paused{ false };
bool rtpRawEventEnabled{ false };
bool rtpObjectEventEnabled{ false };
......
......@@ -119,6 +119,12 @@ namespace RTC
{
MS_TRACE();
// Must have a single encoding.
if (rtpParameters.encodings.empty())
MS_THROW_ERROR("invalid empty rtpParameters.encodings");
else if (rtpParameters.encodings[0].ssrc == 0)
MS_THROW_ERROR("missing rtpParameters.encodings[0].ssrc");
if (IsEnabled())
Disable();
......@@ -250,15 +256,6 @@ namespace RTC
if (IsPaused())
return;
// Ignore the packet if the SSRC is not the single one in the sender
// RTP parameters.
if (packet->GetSsrc() != this->rtpParameters.encodings[0].ssrc)
{
MS_WARN_TAG(rtp, "ignoring packet with unknown SSRC [ssrc:%" PRIu32 "]", packet->GetSsrc());
return;
}
// Map the payload type.
auto payloadType = packet->GetPayloadType();
......@@ -295,10 +292,16 @@ namespace RTC
// Save the received timestamp.
this->lastRecvRtpTimestamp = packet->GetTimestamp();
// Update packet sequence number.
// Save real SSRC.
auto ssrc = packet->GetSsrc();
// Rewrite packet SSRC.
packet->SetSsrc(this->rtpParameters.encodings[0].ssrc);
// Rewrite packet sequence number.
packet->SetSequenceNumber(this->seqNum);
// Update packet timestamp.
// Rewrite packet timestamp.
packet->SetTimestamp(this->rtpTimestamp);
// Process the packet.
......@@ -311,6 +314,9 @@ namespace RTC
this->transmittedCounter.Update(packet);
}
// Restore packet SSRC.
packet->SetSsrc(ssrc);
// Restore the original sequence number.
packet->SetSequenceNumber(this->lastRecvSeqNum);
......
......@@ -165,36 +165,6 @@ namespace RTC
listener->OnProducerRtpParametersUpdated(this);
}
// Fill the SSRC mapping table.
this->ssrcMapping.clear();
auto& newEncodings = this->rtpParameters.encodings;
for (size_t i = 0; i != this->outputEncodings.size(); ++i)
{
if (i == newEncodings.size())
break;
auto& newEncoding = newEncodings[i];
auto& outputEncoding = this->outputEncodings[i];
if (outputEncoding.ssrc != newEncoding.ssrc)
{
this->ssrcMapping[newEncoding.ssrc] = outputEncoding.ssrc;
}
if (outputEncoding.hasRtx && newEncoding.hasRtx && outputEncoding.rtx.ssrc != newEncoding.rtx.ssrc)
{
this->ssrcMapping[newEncoding.rtx.ssrc] = outputEncoding.rtx.ssrc;
}
if (outputEncoding.hasFec && newEncoding.hasFec && outputEncoding.fec.ssrc != newEncoding.fec.ssrc)
{
this->ssrcMapping[newEncoding.fec.ssrc] = outputEncoding.fec.ssrc;
}
}
MS_DEBUG_DEV("Producer RTP parameters updated [producerId:%" PRIu32 "]", this->producerId);
RequestFullFrame(true);
......@@ -325,10 +295,9 @@ namespace RTC
if (this->paused)
return;
// Apply the Producer codec payload type and SSRC mapping before dispatching
// the packet.
ApplyPayloadTypeMapping(packet);
ApplySsrcMapping(packet);
// Apply the Producer codec payload type and extension header mapping before
// dispatching the packet.
ApplyRtpMapping(packet);
for (auto& listener : this->listeners)
{
......@@ -377,27 +346,6 @@ namespace RTC
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
{
MS_TRACE();
......@@ -592,7 +540,7 @@ namespace RTC
this->rtpStreams.clear();
}
void Producer::ApplyPayloadTypeMapping(RTC::RtpPacket* packet) const
void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const
{
MS_TRACE();
......@@ -603,16 +551,22 @@ namespace RTC
{
packet->SetPayloadType(codecPayloadTypeMap.at(payloadType));
}
}
void Producer::ApplySsrcMapping(RTC::RtpPacket* packet) const
{
MS_TRACE();
auto& headerExtensionIdMap = this->rtpMapping.headerExtensionIds;
auto ssrc = packet->GetSsrc();
packet->MangleExtensionHeaderIds(headerExtensionIdMap);
if (this->ssrcMapping.find(ssrc) != this->ssrcMapping.end())
packet->SetSsrc(this->ssrcMapping.at(ssrc));
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::OnRtpStreamRecvNackRequired(
......
......@@ -988,6 +988,9 @@ namespace RTC
{
// NOTE: This may throw.
rtpParameters = RTC::RtpParameters(request->data[JsonStringRtpParameters]);
// NOTE: This may throw.
consumer->Enable(transport, rtpParameters);
}
catch (const MediaSoupError& error)
{
......@@ -996,8 +999,6 @@ namespace RTC
return;
}
consumer->Enable(transport, rtpParameters);
// Tell the Transport to handle the new Consumer.
transport->HandleConsumer(consumer);
......
......@@ -1122,9 +1122,8 @@ namespace RTC
// Trick for clients performing aggressive ICE regardless we are ICE-Lite.
this->iceServer->ForceSelectedTuple(tuple);
// Apply the RTP header extension mapping into the packet (we need it for the
// bitrate estimator).
producer->ApplyExtensionIdMapping(packet);
// Pass the RTP packet to the corresponding Producer.
producer->ReceiveRtpPacket(packet);
// Feed the remote bitrate estimator (REMB).
if (this->remoteBitrateEstimator)
......@@ -1138,9 +1137,6 @@ namespace RTC
}
}
// Pass the RTP packet to the corresponding Producer.
producer->ReceiveRtpPacket(packet);
delete packet;
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论