提交 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) # 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 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: * Must mangle RTP sequence numbers in Consumers:
......
...@@ -623,7 +623,7 @@ class Peer extends EnhancedEventEmitter ...@@ -623,7 +623,7 @@ class Peer extends EnhancedEventEmitter
source : producer source : producer
}; };
// Create a Producer instance. // Create a Consumer instance.
const consumer = new Consumer(internal, data, this._channel); const consumer = new Consumer(internal, data, this._channel);
consumer.appData = producer.appData; consumer.appData = producer.appData;
......
...@@ -262,10 +262,6 @@ exports.getProducerRtpParametersMapping = function(params, caps) ...@@ -262,10 +262,6 @@ exports.getProducerRtpParametersMapping = function(params, caps)
* and the RTP capabilities of the Room. * and the RTP capabilities of the Room.
* It may throw if invalid or non supported RTP parameters are given. * 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 {RTCRtpParameters} params
* @param {RTCRtpCapabilities} caps * @param {RTCRtpCapabilities} caps
* @param {Object} rtpMapping - As generated by getProducerRtpParametersMapping(). * @param {Object} rtpMapping - As generated by getProducerRtpParametersMapping().
...@@ -379,7 +375,7 @@ exports.getConsumableRtpParameters = function(params, caps, rtpMapping) ...@@ -379,7 +375,7 @@ exports.getConsumableRtpParameters = function(params, caps, rtpMapping)
/** /**
* Generate RTP parameters for a specific Consumer. * 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. * can enable this Consumer or not.
* *
* @param {RTCRtpParameters} consumableRtpParameters - Consumable RTP parameters. * @param {RTCRtpParameters} consumableRtpParameters - Consumable RTP parameters.
...@@ -427,7 +423,7 @@ exports.getConsumerRtpParameters = function(consumableRtpParameters, rtpCapabili ...@@ -427,7 +423,7 @@ exports.getConsumerRtpParameters = function(consumableRtpParameters, rtpCapabili
const consumerEncoding = const consumerEncoding =
{ {
ssrc : consumableRtpParameters.encodings[0].ssrc ssrc : utils.randomNumber()
}; };
if (rtxSupported) if (rtxSupported)
......
...@@ -64,7 +64,6 @@ namespace RTC ...@@ -64,7 +64,6 @@ 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);
...@@ -76,8 +75,7 @@ namespace RTC ...@@ -76,8 +75,7 @@ namespace RTC
void FillKnownHeaderExtensions(); void FillKnownHeaderExtensions();
void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void ClearRtpStreams(); void ClearRtpStreams();
void ApplyPayloadTypeMapping(RTC::RtpPacket* packet) const; void ApplyRtpMapping(RTC::RtpPacket* packet) const;
void ApplySsrcMapping(RTC::RtpPacket* packet) const;
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public: public:
...@@ -108,7 +106,6 @@ namespace RTC ...@@ -108,7 +106,6 @@ namespace RTC
// Others. // Others.
std::vector<RtpEncodingParameters> outputEncodings; std::vector<RtpEncodingParameters> outputEncodings;
struct KnownHeaderExtensions knownHeaderExtensions; struct KnownHeaderExtensions knownHeaderExtensions;
std::map<uint32_t, uint32_t> ssrcMapping;
bool paused{ false }; bool paused{ false };
bool rtpRawEventEnabled{ false }; bool rtpRawEventEnabled{ false };
bool rtpObjectEventEnabled{ false }; bool rtpObjectEventEnabled{ false };
......
...@@ -119,6 +119,12 @@ namespace RTC ...@@ -119,6 +119,12 @@ namespace RTC
{ {
MS_TRACE(); 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()) if (IsEnabled())
Disable(); Disable();
...@@ -250,15 +256,6 @@ namespace RTC ...@@ -250,15 +256,6 @@ namespace RTC
if (IsPaused()) if (IsPaused())
return; 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. // Map the payload type.
auto payloadType = packet->GetPayloadType(); auto payloadType = packet->GetPayloadType();
...@@ -295,10 +292,16 @@ namespace RTC ...@@ -295,10 +292,16 @@ namespace RTC
// Save the received timestamp. // Save the received timestamp.
this->lastRecvRtpTimestamp = packet->GetTimestamp(); 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); packet->SetSequenceNumber(this->seqNum);
// Update packet timestamp. // Rewrite packet timestamp.
packet->SetTimestamp(this->rtpTimestamp); packet->SetTimestamp(this->rtpTimestamp);
// Process the packet. // Process the packet.
...@@ -311,6 +314,9 @@ namespace RTC ...@@ -311,6 +314,9 @@ namespace RTC
this->transmittedCounter.Update(packet); this->transmittedCounter.Update(packet);
} }
// Restore packet SSRC.
packet->SetSsrc(ssrc);
// Restore the original sequence number. // Restore the original sequence number.
packet->SetSequenceNumber(this->lastRecvSeqNum); packet->SetSequenceNumber(this->lastRecvSeqNum);
......
...@@ -165,36 +165,6 @@ namespace RTC ...@@ -165,36 +165,6 @@ namespace RTC
listener->OnProducerRtpParametersUpdated(this); 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); MS_DEBUG_DEV("Producer RTP parameters updated [producerId:%" PRIu32 "]", this->producerId);
RequestFullFrame(true); RequestFullFrame(true);
...@@ -325,10 +295,9 @@ namespace RTC ...@@ -325,10 +295,9 @@ namespace RTC
if (this->paused) if (this->paused)
return; return;
// Apply the Producer codec payload type and SSRC mapping before dispatching // Apply the Producer codec payload type and extension header mapping before
// the packet. // dispatching the packet.
ApplyPayloadTypeMapping(packet); ApplyRtpMapping(packet);
ApplySsrcMapping(packet);
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
...@@ -377,27 +346,6 @@ namespace RTC ...@@ -377,27 +346,6 @@ 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();
...@@ -592,7 +540,7 @@ namespace RTC ...@@ -592,7 +540,7 @@ namespace RTC
this->rtpStreams.clear(); this->rtpStreams.clear();
} }
void Producer::ApplyPayloadTypeMapping(RTC::RtpPacket* packet) const void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const
{ {
MS_TRACE(); MS_TRACE();
...@@ -603,16 +551,22 @@ namespace RTC ...@@ -603,16 +551,22 @@ namespace RTC
{ {
packet->SetPayloadType(codecPayloadTypeMap.at(payloadType)); packet->SetPayloadType(codecPayloadTypeMap.at(payloadType));
} }
}
void Producer::ApplySsrcMapping(RTC::RtpPacket* packet) const auto& headerExtensionIdMap = this->rtpMapping.headerExtensionIds;
{
MS_TRACE();
auto ssrc = packet->GetSsrc(); packet->MangleExtensionHeaderIds(headerExtensionIdMap);
if (this->ssrcMapping.find(ssrc) != this->ssrcMapping.end()) if (this->knownHeaderExtensions.ssrcAudioLevelId != 0u)
packet->SetSsrc(this->ssrcMapping.at(ssrc)); {
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( void Producer::OnRtpStreamRecvNackRequired(
......
...@@ -988,6 +988,9 @@ namespace RTC ...@@ -988,6 +988,9 @@ namespace RTC
{ {
// NOTE: This may throw. // NOTE: This may throw.
rtpParameters = RTC::RtpParameters(request->data[JsonStringRtpParameters]); rtpParameters = RTC::RtpParameters(request->data[JsonStringRtpParameters]);
// NOTE: This may throw.
consumer->Enable(transport, rtpParameters);
} }
catch (const MediaSoupError& error) catch (const MediaSoupError& error)
{ {
...@@ -996,8 +999,6 @@ namespace RTC ...@@ -996,8 +999,6 @@ namespace RTC
return; return;
} }
consumer->Enable(transport, rtpParameters);
// Tell the Transport to handle the new Consumer. // Tell the Transport to handle the new Consumer.
transport->HandleConsumer(consumer); transport->HandleConsumer(consumer);
......
...@@ -1122,9 +1122,8 @@ namespace RTC ...@@ -1122,9 +1122,8 @@ 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);
// Apply the RTP header extension mapping into the packet (we need it for the // Pass the RTP packet to the corresponding Producer.
// bitrate estimator). producer->ReceiveRtpPacket(packet);
producer->ApplyExtensionIdMapping(packet);
// Feed the remote bitrate estimator (REMB). // Feed the remote bitrate estimator (REMB).
if (this->remoteBitrateEstimator) if (this->remoteBitrateEstimator)
...@@ -1138,9 +1137,6 @@ namespace RTC ...@@ -1138,9 +1137,6 @@ namespace RTC
} }
} }
// Pass the RTP packet to the corresponding Producer.
producer->ReceiveRtpPacket(packet);
delete packet; delete packet;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论