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

- transport.consume() now allow passing preferredLayers.

- Remove Consumer::TransportConnected().
- Add Consumer::UseBandwidth() (fake for now).
- Add Consumer::ProducerRtpStream() (to differentiate it from ProducerNewRtpStream() method).
- SimulcastConsumer::Paused() now unset current and target layers to -1.
- SimulcastConsumer::Resumed() now calls to RecalculateTargetSpatialLayer().
上级 7445bae4
......@@ -361,6 +361,7 @@ class Transport extends EnhancedEventEmitter
* @param {String} producerId
* @param {RTCRtpCapabilities} rtpCapabilities - Remote RTP capabilities.
* @param {Boolean} [paused=false] - Whether the Consumer must start paused.
* @param {Object} [preferredLayers] - Preferred spatial and temporal layers.
* @param {Object} [appData={}] - Custom app data.
*
* @async
......@@ -372,6 +373,7 @@ class Transport extends EnhancedEventEmitter
producerId,
rtpCapabilities,
paused = false,
preferredLayers,
appData = {}
} = {}
)
......@@ -401,7 +403,8 @@ class Transport extends EnhancedEventEmitter
rtpParameters,
type : producer.type,
consumableRtpEncodings : producer.consumableRtpParameters.encodings,
paused
paused,
preferredLayers
};
const status =
......
......@@ -345,6 +345,7 @@ test('transport.consume() succeeds', async () =>
producerId : videoProducer.id,
rtpCapabilities : consumerDeviceCapabilities,
paused : true,
preferredLayers : { spatialLayer: 12 },
appData : { baz: 'LOL' }
});
......
......@@ -49,10 +49,11 @@ namespace RTC
const std::vector<uint32_t>& GetMediaSsrcs() const;
bool IsActive() const;
bool IsPaused() const;
bool IsProducerPaused() const; // This is needed by the Transport.
virtual void TransportConnected() = 0;
bool IsProducerPaused() const;
virtual void UseBandwidth(uint32_t availableBandwidth) = 0;
void ProducerPaused();
void ProducerResumed();
virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
virtual void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
virtual void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) = 0;
void ProducerClosed();
......
......@@ -17,7 +17,8 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
void TransportConnected() override;
void UseBandwidth(uint32_t availableBandwidth) override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
void SendRtpPacket(RTC::RtpPacket* packet) override;
......
......@@ -19,7 +19,8 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
void TransportConnected() override;
void UseBandwidth(uint32_t availableBandwidth) override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
void SendRtpPacket(RTC::RtpPacket* packet) override;
......
......@@ -19,7 +19,8 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
void TransportConnected() override;
void UseBandwidth(uint32_t availableBandwidth) override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score) override;
void SendRtpPacket(RTC::RtpPacket* packet) override;
......@@ -39,7 +40,7 @@ namespace RTC
void RetransmitRtpPacket(RTC::RtpPacket* packet);
void EmitScore() const;
void SetCurrentSpatialLayer(int16_t spatialLayer);
void RecalculateTargetSpatialLayer(bool force = false);
void RecalculateTargetSpatialLayer();
RTC::RtpStream* GetProducerCurrentRtpStream() const;
RTC::RtpStream* GetProducerTargetRtpStream() const;
......
......@@ -80,13 +80,20 @@ namespace RTC
}
}
void PipeConsumer::TransportConnected()
void PipeConsumer::UseBandwidth(uint32_t availableBandwidth)
{
MS_TRACE();
RequestKeyFrame();
}
void PipeConsumer::ProducerRtpStream(RTC::RtpStream* /*rtpStream*/, uint32_t /*mappedSsrc*/)
{
MS_TRACE();
// Do nothing.
}
void PipeConsumer::ProducerNewRtpStream(RTC::RtpStream* /*rtpStream*/, uint32_t /*mappedSsrc*/)
{
MS_TRACE();
......@@ -181,8 +188,7 @@ namespace RTC
{
MS_TRACE();
if (!IsActive())
return;
// TODO: Must call the corresponding rtpStream->ReceiveKeyFrameRequest(messageType);
RequestKeyFrame();
}
......
......@@ -35,16 +35,16 @@ namespace RTC
// TODO: Testing.
uint32_t rembBitrate = static_cast<uint32_t>(remb->GetBitrate());
uint64_t now = DepLibUV::GetTime();
uint32_t bitrate = this->transmissionCounter.GetRate(now);
int32_t diff = rembBitrate - bitrate;
MS_ERROR(
"REMB received [sending bitrate:%" PRIu32 ", REMB available bitrate:%" PRIu32
", diff:%" PRIi32 "]",
bitrate,
rembBitrate,
diff);
// uint32_t rembBitrate = static_cast<uint32_t>(remb->GetBitrate());
// uint64_t now = DepLibUV::GetTime();
// uint32_t bitrate = this->transmissionCounter.GetRate(now);
// int32_t diff = rembBitrate - bitrate;
// MS_ERROR(
// "REMB received [sending bitrate:%" PRIu32 ", REMB available bitrate:%" PRIu32
// ", diff:%" PRIi32 "]",
// bitrate,
// rembBitrate,
// diff);
}
} // namespace RTC
......@@ -646,15 +646,12 @@ namespace RTC
this->mapConsumerProducer[consumer] = producer;
// Get all streams in the Producer and provide the Consumer with them.
// NOTE: This must be done at the end. Otherwise, if consumer->ProducerNewRtpStream()
// invokes Router::OnTransportConsumerKeyFrameRequested(), it would crash due to
// Consumer still not being present in Router maps.
for (auto& kv : producer->GetRtpStreams())
{
auto* rtpStream = kv.first;
uint32_t mappedSsrc = kv.second;
consumer->ProducerNewRtpStream(rtpStream, mappedSsrc);
consumer->ProducerRtpStream(rtpStream, mappedSsrc);
}
}
......
......@@ -99,13 +99,23 @@ namespace RTC
}
}
void SimpleConsumer::TransportConnected()
void SimpleConsumer::UseBandwidth(uint32_t availableBandwidth)
{
MS_TRACE();
RequestKeyFrame();
}
void SimpleConsumer::ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t /*mappedSsrc*/)
{
MS_TRACE();
this->producerRtpStream = rtpStream;
// Emit the score event.
EmitScore();
}
void SimpleConsumer::ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t /*mappedSsrc*/)
{
MS_TRACE();
......@@ -298,9 +308,6 @@ namespace RTC
{
MS_TRACE();
if (!IsActive())
return;
this->rtpStream->ReceiveKeyFrameRequest(messageType);
RequestKeyFrame();
......
......@@ -21,11 +21,7 @@ namespace RTC
if (this->consumableRtpEncodings.size() <= 1)
MS_THROW_TYPE_ERROR("invalid consumableRtpEncodings with size <= 1");
// Set the RTCP report generation interval.
if (this->kind == RTC::Media::Kind::AUDIO)
this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs;
else
this->maxRtcpInterval = RTC::RTCP::MaxVideoIntervalMs;
auto jsonPreferredLayersIt = data.find("preferredLayers");
// Fill mapMappedSsrcSpatialLayer.
for (size_t idx{ 0 }; idx < this->consumableRtpEncodings.size(); ++idx)
......@@ -35,12 +31,42 @@ namespace RTC
this->mapMappedSsrcSpatialLayer[encoding.ssrc] = static_cast<int16_t>(idx);
}
// Set preferredLayers (if given).
if (jsonPreferredLayersIt != data.end() && jsonPreferredLayersIt->is_object())
{
// TODO: Handle temporalLayer.
auto jsonSpatialLayerIt = jsonPreferredLayersIt->find("spatialLayer");
if (jsonSpatialLayerIt == jsonPreferredLayersIt->end() || !jsonSpatialLayerIt->is_number_unsigned())
{
MS_THROW_TYPE_ERROR("missing preferredLayers.spatialLayer");
}
this->preferredSpatialLayer = jsonSpatialLayerIt->get<int16_t>();
if (this->preferredSpatialLayer >= static_cast<int16_t>(this->consumableRtpEncodings.size()))
{
this->preferredSpatialLayer = static_cast<int16_t>(this->consumableRtpEncodings.size()) - 1;
}
}
else
{
// Initially set preferreSpatialLayer to the maximum value.
this->preferredSpatialLayer = static_cast<int16_t>(this->consumableRtpEncodings.size()) - 1;
// TODO: Set initial temporal layer.
}
// Reserve space for the Producer RTP streams.
this->producerRtpStreams.insert(
this->producerRtpStreams.begin(), this->consumableRtpEncodings.size(), nullptr);
// Initially set preferreSpatialLayer to the maximum value.
this->preferredSpatialLayer = static_cast<int16_t>(this->consumableRtpEncodings.size()) - 1;
// Set the RTCP report generation interval.
if (this->kind == RTC::Media::Kind::AUDIO)
this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs;
else
this->maxRtcpInterval = RTC::RTCP::MaxVideoIntervalMs;
// Create RtpStreamSend instance for sending a single stream to the remote.
CreateRtpStream();
......@@ -122,6 +148,8 @@ namespace RTC
case Channel::Request::MethodId::CONSUMER_SET_PREFERRED_LAYERS:
{
// TODO: Handle temporalLayer.
auto jsonSpatialLayerIt = request->data.find("spatialLayer");
if (jsonSpatialLayerIt == request->data.end() || !jsonSpatialLayerIt->is_number_unsigned())
......@@ -131,9 +159,9 @@ namespace RTC
auto preferredSpatialLayer = jsonSpatialLayerIt->get<int16_t>();
if (preferredSpatialLayer >= static_cast<int16_t>(this->mapMappedSsrcSpatialLayer.size()))
if (preferredSpatialLayer >= static_cast<int16_t>(this->consumableRtpEncodings.size()))
{
preferredSpatialLayer = static_cast<int16_t>(this->mapMappedSsrcSpatialLayer.size()) - 1;
preferredSpatialLayer = static_cast<int16_t>(this->consumableRtpEncodings.size()) - 1;
}
if (preferredSpatialLayer == this->preferredSpatialLayer)
......@@ -150,7 +178,8 @@ namespace RTC
this->preferredSpatialLayer,
this->id.c_str());
RecalculateTargetSpatialLayer(true /*force*/);
if (IsActive())
RecalculateTargetSpatialLayer();
request->Accept();
......@@ -165,11 +194,28 @@ namespace RTC
}
}
void SimulcastConsumer::TransportConnected()
void SimulcastConsumer::UseBandwidth(uint32_t availableBandwidth)
{
MS_TRACE();
RequestKeyFrame();
if (IsActive())
RecalculateTargetSpatialLayer();
}
void SimulcastConsumer::ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc)
{
MS_TRACE();
auto it = this->mapMappedSsrcSpatialLayer.find(mappedSsrc);
MS_ASSERT(it != this->mapMappedSsrcSpatialLayer.end(), "unknown mappedSsrc");
int16_t spatialLayer = it->second;
this->producerRtpStreams[spatialLayer] = rtpStream;
// Emit the score event.
EmitScore();
}
void SimulcastConsumer::ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc)
......@@ -185,10 +231,9 @@ namespace RTC
this->producerRtpStreams[spatialLayer] = rtpStream;
// Recalculate layers.
RecalculateTargetSpatialLayer();
if (IsActive())
RecalculateTargetSpatialLayer();
// TODO: Probably just if this stream is the current spatial layer.
//
// Emit the score event.
EmitScore();
}
......@@ -198,7 +243,8 @@ namespace RTC
MS_TRACE();
// Recalculate layers.
RecalculateTargetSpatialLayer();
if (IsActive())
RecalculateTargetSpatialLayer();
// Emit the score event.
EmitScore();
......@@ -400,9 +446,6 @@ namespace RTC
{
MS_TRACE();
if (!IsActive())
return;
this->rtpStream->ReceiveKeyFrameRequest(messageType);
RequestKeyFrame();
......@@ -449,6 +492,10 @@ namespace RTC
MS_TRACE();
this->rtpStream->Pause();
// Unset current and target layers.
this->targetSpatialLayer = -1;
this->currentSpatialLayer = -1;
}
void SimulcastConsumer::Resumed(bool wasProducer)
......@@ -461,10 +508,8 @@ namespace RTC
// receiver will request lot of NACKs due to unknown RTP packets.
this->syncRequired = true;
// If we have been resumed due to the Producer becoming resumed, we don't
// need to request a key frame since the Producer already requested it.
if (!wasProducer)
RequestKeyFrame();
if (IsActive())
RecalculateTargetSpatialLayer();
}
void SimulcastConsumer::CreateRtpStream()
......@@ -552,12 +597,12 @@ namespace RTC
{
MS_TRACE();
auto* producerTargetRtpStream = GetProducerTargetRtpStream();
auto* producerCurrentRtpStream = GetProducerCurrentRtpStream();
if (!IsActive() || this->kind != RTC::Media::Kind::VIDEO)
return;
auto* producerTargetRtpStream = GetProducerTargetRtpStream();
auto* producerCurrentRtpStream = GetProducerCurrentRtpStream();
if (producerTargetRtpStream)
{
auto mappedSsrc = this->consumableRtpEncodings[this->targetSpatialLayer].ssrc;
......@@ -611,7 +656,7 @@ namespace RTC
EmitScore();
}
void SimulcastConsumer::RecalculateTargetSpatialLayer(bool /*force*/)
void SimulcastConsumer::RecalculateTargetSpatialLayer()
{
MS_TRACE();
......@@ -792,7 +837,8 @@ namespace RTC
{
MS_TRACE();
this->RecalculateTargetSpatialLayer();
if (IsActive())
RecalculateTargetSpatialLayer();
// Emit the score event.
EmitScore();
......
......@@ -338,9 +338,11 @@ namespace RTC
// Tell the subclass.
UserOnNewConsumer(consumer);
// If the Transport is already connected tell it to the new Consumer.
// TODO: Update with new BWE API.
//
// If the Transport is already connected tell the new Consumer to ask for bandwidth.
if (IsConnected())
consumer->TransportConnected();
consumer->UseBandwidth(0);
break;
}
......@@ -437,13 +439,13 @@ namespace RTC
// Start the RTCP timer.
this->rtcpTimer->Start(static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs / 2));
// Iterate all Consumers and tell them that the Transport is connected, so they
// will request key frames.
// Iterate all Consumers and tell them to use bandwidth.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
consumer->TransportConnected();
// TODO: Update with new BWE API.
consumer->UseBandwidth(0);
}
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论