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

WIP: BWE

上级 8fa089fa
...@@ -50,7 +50,6 @@ namespace RTC ...@@ -50,7 +50,6 @@ namespace RTC
RTC::RtpParameters::Type GetType() const; RTC::RtpParameters::Type GetType() const;
const std::vector<uint32_t>& GetMediaSsrcs() const; const std::vector<uint32_t>& GetMediaSsrcs() const;
virtual bool IsActive() const; virtual bool IsActive() const;
virtual void SetBitrateExternallyManaged();
void TransportConnected(); void TransportConnected();
void TransportDisconnected(); void TransportDisconnected();
bool IsPaused() const; bool IsPaused() const;
...@@ -62,6 +61,8 @@ namespace RTC ...@@ -62,6 +61,8 @@ namespace RTC
virtual void ProducerRtpStreamScore( virtual void ProducerRtpStreamScore(
RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) = 0; RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) = 0;
void ProducerClosed(); void ProducerClosed();
virtual void SetBitrateExternallyManaged();
virtual int16_t GetBitratePriority() const;
virtual uint32_t UseBitrate(uint32_t bitrate); virtual uint32_t UseBitrate(uint32_t bitrate);
virtual void SendRtpPacket(RTC::RtpPacket* packet) = 0; virtual void SendRtpPacket(RTC::RtpPacket* packet) = 0;
virtual void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) = 0; virtual void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) = 0;
...@@ -139,11 +140,6 @@ namespace RTC ...@@ -139,11 +140,6 @@ namespace RTC
this->transportConnected && !this->paused && !this->producerPaused && !this->producerClosed); this->transportConnected && !this->paused && !this->producerPaused && !this->producerClosed);
} }
inline void Consumer::SetBitrateExternallyManaged()
{
// Do nothing.
}
inline bool Consumer::IsPaused() const inline bool Consumer::IsPaused() const
{ {
return this->paused; return this->paused;
......
...@@ -20,11 +20,12 @@ namespace RTC ...@@ -20,11 +20,12 @@ namespace RTC
void FillJsonScore(json& jsonObject) const override; void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override; void HandleRequest(Channel::Request* request) override;
bool IsActive() const override; bool IsActive() const override;
void SetBitrateExternallyManaged() override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override; void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
virtual uint32_t UseBitrate(uint32_t bitrate) override; void SetBitrateExternallyManaged() override;
int16_t GetBitratePriority() const override;
uint32_t UseBitrate(uint32_t bitrate) override;
void SendRtpPacket(RTC::RtpPacket* packet) override; void SendRtpPacket(RTC::RtpPacket* packet) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) override; void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) override;
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override; void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
...@@ -42,9 +43,9 @@ namespace RTC ...@@ -42,9 +43,9 @@ namespace RTC
void CreateRtpStream(); void CreateRtpStream();
void RequestKeyFrame(); void RequestKeyFrame();
void RetransmitRtpPacket(RTC::RtpPacket* packet); void RetransmitRtpPacket(RTC::RtpPacket* packet);
bool RecalculateTargetLayers(int16_t& newTargetSpatialLayer, int16_t& newTargetTemporalLayer) const;
void UpdateTargetLayers(int16_t newTargetSpatialLayer, int16_t newTargetTemporalLayer);
void UpdateCurrentLayers(); void UpdateCurrentLayers();
void RecalculateTargetLayers();
void RecalculateAndApplyTargetLayers();
void EmitScore() const; void EmitScore() const;
void EmitLayersChange() const; void EmitLayersChange() const;
RTC::RtpStream* GetProducerCurrentRtpStream() const; RTC::RtpStream* GetProducerCurrentRtpStream() const;
...@@ -90,11 +91,6 @@ namespace RTC ...@@ -90,11 +91,6 @@ namespace RTC
); );
// clang-format on // clang-format on
} }
inline void SimulcastConsumer::SetBitrateExternallyManaged()
{
this->bitrateExternallyManaged = false;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -327,6 +327,22 @@ namespace RTC ...@@ -327,6 +327,22 @@ namespace RTC
this->listener->onConsumerProducerClosed(this); this->listener->onConsumerProducerClosed(this);
} }
void Consumer::SetBitrateExternallyManaged()
{
MS_TRACE();
// Do nothing.
}
int16_t Consumer::GetBitratePriority() const
{
MS_TRACE();
// This method must be override by subclasses with layers. By default
// it just returns 0.
return 0;
}
uint32_t Consumer::UseBitrate(uint32_t /*bitrate*/) uint32_t Consumer::UseBitrate(uint32_t /*bitrate*/)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -137,7 +137,6 @@ namespace RTC ...@@ -137,7 +137,6 @@ namespace RTC
if (!IsActive()) if (!IsActive())
return; return;
// Map the payload type.
auto payloadType = packet->GetPayloadType(); auto payloadType = packet->GetPayloadType();
// NOTE: This may happen if this Consumer supports just some codecs of those // NOTE: This may happen if this Consumer supports just some codecs of those
......
#define MS_CLASS "RTC::SimulcastConsumer" #define MS_CLASS "RTC::SimulcastConsumer"
// #define MS_LOG_DEV #define MS_LOG_DEV
#include "RTC/SimulcastConsumer.hpp" #include "RTC/SimulcastConsumer.hpp"
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
...@@ -101,33 +101,6 @@ namespace RTC ...@@ -101,33 +101,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
auto now = DepLibUV::GetTime();
// TODO
for (auto* rtpStream : this->producerRtpStreams)
{
if (!rtpStream)
continue;
MS_ERROR("Producer RtpStream [total bitrate:%" PRIu32 "]", rtpStream->GetBitrate(now));
for (uint8_t sIdx = 0; sIdx < rtpStream->GetSpatialLayers(); ++sIdx)
{
for (uint8_t tIdx = 0; tIdx < rtpStream->GetTemporalLayers(); ++tIdx)
{
MS_ERROR(
"- [spatial:%" PRIu8 ", temporal:%" PRIu8 ", layer bitrate:%" PRIu32
", total bitrate:%" PRIu32 "]",
sIdx,
tIdx,
rtpStream->GetLayerBitrate(now, sIdx, tIdx),
rtpStream->GetBitrate(now, sIdx, tIdx));
}
}
return;
}
// Call the parent method. // Call the parent method.
RTC::Consumer::FillJson(jsonObject); RTC::Consumer::FillJson(jsonObject);
...@@ -233,14 +206,6 @@ namespace RTC ...@@ -233,14 +206,6 @@ namespace RTC
this->preferredTemporalLayer = this->rtpStream->GetTemporalLayers() - 1; this->preferredTemporalLayer = this->rtpStream->GetTemporalLayers() - 1;
} }
if (this->currentSpatialLayer == this->preferredSpatialLayer)
{
this->targetTemporalLayer = this->preferredTemporalLayer;
if (this->encodingContext)
this->encodingContext->preferences.temporalLayer = this->targetTemporalLayer;
}
MS_DEBUG_DEV( MS_DEBUG_DEV(
"preferred layers changed to [spatial:%" PRIi16 ", temporal:%" PRIi16 ", consumerId:%s]", "preferred layers changed to [spatial:%" PRIi16 ", temporal:%" PRIi16 ", consumerId:%s]",
this->preferredSpatialLayer, this->preferredSpatialLayer,
...@@ -259,10 +224,16 @@ namespace RTC ...@@ -259,10 +224,16 @@ namespace RTC
) )
// clang-format on // clang-format on
{ {
if (this->bitrateExternallyManaged) int16_t newTargetSpatialLayer;
this->listener->OnConsumerNeedBitrateChange(this); int16_t newTargetTemporalLayer;
else
RecalculateAndApplyTargetLayers(); if (RecalculateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer))
{
if (this->bitrateExternallyManaged)
this->listener->OnConsumerNeedBitrateChange(this);
else
UpdateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer);
}
} }
break; break;
...@@ -303,48 +274,97 @@ namespace RTC ...@@ -303,48 +274,97 @@ namespace RTC
if (IsActive()) if (IsActive())
{ {
if (this->bitrateExternallyManaged) int16_t newTargetSpatialLayer;
this->listener->OnConsumerNeedBitrateChange(this); int16_t newTargetTemporalLayer;
else
RecalculateAndApplyTargetLayers();
}
// TODO: Should just do it if the new stream has been selected. if (RecalculateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer))
// Emit the score event. {
EmitScore(); if (this->bitrateExternallyManaged)
this->listener->OnConsumerNeedBitrateChange(this);
else
UpdateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer);
}
}
} }
void SimulcastConsumer::ProducerRtpStreamScore( void SimulcastConsumer::ProducerRtpStreamScore(
RTC::RtpStream* /*rtpStream*/, uint8_t /*score*/, uint8_t /*previousScore*/) RTC::RtpStream* rtpStream, uint8_t /*score*/, uint8_t /*previousScore*/)
{ {
MS_TRACE(); MS_TRACE();
if (IsActive()) if (IsActive())
{ {
// TODO int16_t newTargetSpatialLayer;
// If score 0 (inactivity) and this is the Producer's RtpStream we are using, int16_t newTargetTemporalLayer;
// then we must recalculate our targets and notify the listener for
// redistribution. if (RecalculateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer))
{
if (this->bitrateExternallyManaged)
this->listener->OnConsumerNeedBitrateChange(this);
else
UpdateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer);
}
} }
if (IsActive()) // Emit score eventif the stream whose score changed is the current one.
// if (rtpStream == GetProducerCurrentRtpStream())
EmitScore();
}
void SimulcastConsumer::SetBitrateExternallyManaged()
{
MS_TRACE();
this->bitrateExternallyManaged = true;
}
int16_t SimulcastConsumer::GetBitratePriority() const
{
MS_TRACE();
// If no spatial layer is being sent, return 0.
if (this->currentSpatialLayer == -1)
return 0;
int16_t prioritySpatialLayer{ 0 };
// Otherwise, take the maximum available spatial layer up to the preferred
// one.
for (size_t idx = 0; idx < this->producerRtpStreams.size(); ++idx)
{ {
if (this->bitrateExternallyManaged) auto spatialLayer = static_cast<int16_t>(idx);
this->listener->OnConsumerNeedBitrateChange(this); auto* producerRtpStream = this->producerRtpStreams[idx];
else
RecalculateAndApplyTargetLayers(); // Ignore spatial layers for non existing Producer streams or for those
// with score 0.
if (!producerRtpStream || producerRtpStream->GetScore() == 0)
continue;
// Do not choose a layer greater than the preferred one if we already found
// an available layer equal or less than the preferred one.
if (spatialLayer > this->preferredSpatialLayer && prioritySpatialLayer >= -1)
break;
// Choose this layer for now.
prioritySpatialLayer = spatialLayer;
} }
// TODO: Should just do it if the stream is the selected one. // Return the choosen spatial layer plus one.
// Emit the score event. return prioritySpatialLayer + 1;
EmitScore();
} }
uint32_t SimulcastConsumer::UseBitrate(uint32_t bitrate) uint32_t SimulcastConsumer::UseBitrate(uint32_t bitrate)
{ {
MS_TRACE(); MS_TRACE();
// TODO. // TODO
int16_t newTargetSpatialLayer;
int16_t newTargetTemporalLayer;
RecalculateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer);
UpdateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer);
return bitrate; return bitrate;
} }
...@@ -355,7 +375,6 @@ namespace RTC ...@@ -355,7 +375,6 @@ namespace RTC
if (!IsActive()) if (!IsActive())
return; return;
// Map the payload type.
auto payloadType = packet->GetPayloadType(); auto payloadType = packet->GetPayloadType();
// NOTE: This may happen if this Consumer supports just some codecs of those // NOTE: This may happen if this Consumer supports just some codecs of those
...@@ -377,19 +396,6 @@ namespace RTC ...@@ -377,19 +396,6 @@ namespace RTC
if (this->keyFrameSupported && !packet->IsKeyFrame()) if (this->keyFrameSupported && !packet->IsKeyFrame())
return; return;
// If the new current spatial layer is the preferred one honor the preferred
// temporal layer.
if (this->targetSpatialLayer == this->preferredSpatialLayer)
{
this->targetTemporalLayer = this->preferredTemporalLayer;
}
// Otherwise, choose the highest temporal layer.
// TODO: No, target temporal layer could be less (as per BWE).
else
{
this->targetTemporalLayer = this->rtpStream->GetTemporalLayers() - 1;
}
// Update current spatial and temporal layers. // Update current spatial and temporal layers.
UpdateCurrentLayers(); UpdateCurrentLayers();
...@@ -444,8 +450,10 @@ namespace RTC ...@@ -444,8 +450,10 @@ namespace RTC
return; return;
} }
// Update current temporal layer if the packet honors the target temporal layer. // Update current temporal layer if the packet honors the target temporal layer
// (just if this packet belongs to the target spatial layer).
if ( if (
this->currentSpatialLayer == this->targetSpatialLayer &&
this->currentTemporalLayer != this->targetTemporalLayer && this->currentTemporalLayer != this->targetTemporalLayer &&
packet->GetTemporalLayer() == this->targetTemporalLayer) packet->GetTemporalLayer() == this->targetTemporalLayer)
{ {
...@@ -474,10 +482,11 @@ namespace RTC ...@@ -474,10 +482,11 @@ namespace RTC
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
"sending sync packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 "sending sync packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32
"] from original [seq:%" PRIu16 ", ts:%" PRIu32 "]", "] from original [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
packet->GetTimestamp(), packet->GetTimestamp(),
origSsrc,
origSeq, origSeq,
origTimestamp); origTimestamp);
} }
...@@ -493,10 +502,11 @@ namespace RTC ...@@ -493,10 +502,11 @@ namespace RTC
MS_WARN_TAG( MS_WARN_TAG(
rtp, rtp,
"failed to send packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 "failed to send packet [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32
"] from original [seq:%" PRIu16 ", ts:%" PRIu32 "]", "] from original [ssrc:%" PRIu32 ", seq:%" PRIu16 ", ts:%" PRIu32 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
packet->GetTimestamp(), packet->GetTimestamp(),
origSsrc,
origSeq, origSeq,
origTimestamp); origTimestamp);
} }
...@@ -614,10 +624,16 @@ namespace RTC ...@@ -614,10 +624,16 @@ namespace RTC
{ {
this->rtpStream->Resume(); this->rtpStream->Resume();
if (this->bitrateExternallyManaged) int16_t newTargetSpatialLayer;
this->listener->OnConsumerNeedBitrateChange(this); int16_t newTargetTemporalLayer;
else
RecalculateAndApplyTargetLayers(); if (RecalculateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer))
{
if (this->bitrateExternallyManaged)
this->listener->OnConsumerNeedBitrateChange(this);
else
UpdateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer);
}
} }
} }
...@@ -627,18 +643,7 @@ namespace RTC ...@@ -627,18 +643,7 @@ namespace RTC
this->rtpStream->Pause(); this->rtpStream->Pause();
// Unset current and target layers. UpdateTargetLayers(-1, -1);
this->targetSpatialLayer = -1;
this->currentSpatialLayer = -1;
this->targetTemporalLayer = -1;
this->currentTemporalLayer = -1;
if (this->encodingContext)
{
this->encodingContext->preferences.temporalLayer = this->rtpStream->GetTemporalLayers() - 1;
}
EmitLayersChange();
} }
void SimulcastConsumer::UserOnPaused() void SimulcastConsumer::UserOnPaused()
...@@ -647,18 +652,7 @@ namespace RTC ...@@ -647,18 +652,7 @@ namespace RTC
this->rtpStream->Pause(); this->rtpStream->Pause();
// Unset current and target layers. UpdateTargetLayers(-1, -1);
this->targetSpatialLayer = -1;
this->currentSpatialLayer = -1;
this->targetTemporalLayer = -1;
this->currentTemporalLayer = -1;
if (this->encodingContext)
{
this->encodingContext->preferences.temporalLayer = this->rtpStream->GetTemporalLayers() - 1;
}
EmitLayersChange();
} }
void SimulcastConsumer::UserOnResumed() void SimulcastConsumer::UserOnResumed()
...@@ -671,10 +665,16 @@ namespace RTC ...@@ -671,10 +665,16 @@ namespace RTC
{ {
this->rtpStream->Resume(); this->rtpStream->Resume();
if (this->bitrateExternallyManaged) int16_t newTargetSpatialLayer;
this->listener->OnConsumerNeedBitrateChange(this); int16_t newTargetTemporalLayer;
else
RecalculateAndApplyTargetLayers(); if (RecalculateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer))
{
if (this->bitrateExternallyManaged)
this->listener->OnConsumerNeedBitrateChange(this);
else
UpdateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer);
}
} }
} }
...@@ -789,51 +789,16 @@ namespace RTC ...@@ -789,51 +789,16 @@ namespace RTC
} }
} }
void SimulcastConsumer::UpdateCurrentLayers() bool SimulcastConsumer::RecalculateTargetLayers(
int16_t& newTargetSpatialLayer, int16_t& newTargetTemporalLayer) const
{ {
MS_TRACE(); MS_TRACE();
if (this->currentSpatialLayer == this->targetSpatialLayer && this->currentTemporalLayer == this->targetTemporalLayer) // Start with no layers.
{ newTargetSpatialLayer = -1;
return; newTargetTemporalLayer = -1;
}
bool emitScore{ false };
// Reset the score of our RtpStream to 10 if spatial layer changed.
if (this->targetSpatialLayer != this->currentSpatialLayer)
{
this->rtpStream->ResetScore(10, false);
emitScore = true;
}
this->currentSpatialLayer = this->targetSpatialLayer;
this->currentTemporalLayer = this->targetTemporalLayer;
if (this->encodingContext)
this->encodingContext->preferences.temporalLayer = this->targetTemporalLayer;
MS_DEBUG_DEV(
"current layers changed to [spatial:%" PRIi16 ", temporal:%" PRIi16 ", consumerId:%s]",
this->currentSpatialLayer,
this->currentTemporalLayer,
this->id.c_str());
// Emit the layersChange event.
EmitLayersChange();
// Emit the score event (just if spatial layer changed).
if (emitScore)
EmitScore();
}
void SimulcastConsumer::RecalculateAndApplyTargetLayers()
{
MS_TRACE();
uint8_t maxProducerScore{ 0 }; uint8_t maxProducerScore{ 0 };
int16_t newTargetSpatialLayer{ -1 };
for (size_t idx = 0; idx < this->producerRtpStreams.size(); ++idx) for (size_t idx = 0; idx < this->producerRtpStreams.size(); ++idx)
{ {
...@@ -858,16 +823,28 @@ namespace RTC ...@@ -858,16 +823,28 @@ namespace RTC
} }
} }
MS_DEBUG_TAG( if (newTargetSpatialLayer != -1)
simulcast, {
"newTargetSpatialLayer is %" PRIi16 " [consumerId:%s]", if (newTargetSpatialLayer == this->preferredSpatialLayer)
newTargetSpatialLayer, newTargetTemporalLayer = this->preferredTemporalLayer;
this->id.c_str()); else if (newTargetSpatialLayer < this->preferredSpatialLayer)
newTargetTemporalLayer = this->rtpStream->GetTemporalLayers() - 1;
else
newTargetTemporalLayer = 0;
}
// Return true if any target layer changed.
return (
newTargetSpatialLayer != this->targetSpatialLayer ||
newTargetTemporalLayer != this->targetTemporalLayer);
}
void SimulcastConsumer::UpdateTargetLayers(int16_t newTargetSpatialLayer, int16_t newTargetTemporalLayer)
{
MS_TRACE();
if (newTargetSpatialLayer == -1) if (newTargetSpatialLayer == -1)
{ {
MS_DEBUG_TAG(simulcast, "no valid spatial layer found");
// Unset current and target layers. // Unset current and target layers.
this->targetSpatialLayer = -1; this->targetSpatialLayer = -1;
this->currentSpatialLayer = -1; this->currentSpatialLayer = -1;
...@@ -884,23 +861,59 @@ namespace RTC ...@@ -884,23 +861,59 @@ namespace RTC
return; return;
} }
// Nothing changed. this->targetSpatialLayer = newTargetSpatialLayer;
if (newTargetSpatialLayer == this->targetSpatialLayer) this->targetTemporalLayer = newTargetTemporalLayer;
return;
this->targetSpatialLayer = newTargetSpatialLayer; // If the new target spatial layer matches the current one, apply the new
// target temporal layer now.
if (this->encodingContext && this->targetSpatialLayer == this->currentSpatialLayer)
this->encodingContext->preferences.temporalLayer = this->targetTemporalLayer;
MS_DEBUG_TAG( MS_DEBUG_TAG(
simulcast, simulcast,
"target spatial layer changed to %" PRIi16 " [consumerId:%s]", "target layers changed [spatial:%" PRIi16 ", temporal:%" PRIi16 ", consumerId:%s]",
this->targetSpatialLayer, this->targetSpatialLayer,
this->targetTemporalLayer,
this->id.c_str()); this->id.c_str());
// Already using the target layer. Do nothing. // If the target spatial layer is different than the current one, request
if (this->targetSpatialLayer == this->currentSpatialLayer) // a key frame.
return; if (this->targetSpatialLayer != this->currentSpatialLayer)
RequestKeyFrame();
}
void SimulcastConsumer::UpdateCurrentLayers()
{
MS_TRACE();
bool emitScore{ false };
// Reset the score of our RtpStream to 10 if spatial layer changed.
if (this->targetSpatialLayer != this->currentSpatialLayer)
{
this->rtpStream->ResetScore(10, false);
emitScore = true;
}
RequestKeyFrame(); this->currentSpatialLayer = this->targetSpatialLayer;
this->currentTemporalLayer = this->targetTemporalLayer;
if (this->encodingContext)
this->encodingContext->preferences.temporalLayer = this->targetTemporalLayer;
MS_DEBUG_DEV(
"current layers changed to [spatial:%" PRIi16 ", temporal:%" PRIi16 ", consumerId:%s]",
this->currentSpatialLayer,
this->currentTemporalLayer,
this->id.c_str());
// Emit the layersChange event.
EmitLayersChange();
// Emit the score event (just if spatial layer changed).
if (emitScore)
EmitScore();
} }
inline void SimulcastConsumer::EmitScore() const inline void SimulcastConsumer::EmitScore() const
...@@ -962,10 +975,16 @@ namespace RTC ...@@ -962,10 +975,16 @@ namespace RTC
if (IsActive()) if (IsActive())
{ {
if (this->bitrateExternallyManaged) int16_t newTargetSpatialLayer;
this->listener->OnConsumerNeedBitrateChange(this); int16_t newTargetTemporalLayer;
else
RecalculateAndApplyTargetLayers(); if (RecalculateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer))
{
if (this->bitrateExternallyManaged)
this->listener->OnConsumerNeedBitrateChange(this);
else
UpdateTargetLayers(newTargetSpatialLayer, newTargetTemporalLayer);
}
} }
// Emit the score event. // Emit the score event.
......
...@@ -1155,6 +1155,14 @@ namespace RTC ...@@ -1155,6 +1155,14 @@ namespace RTC
// TODO: Make this value configurable. // TODO: Make this value configurable.
this->rembClient = new RTC::RembClient(this, 300000); this->rembClient = new RTC::RembClient(this, 300000);
// Tell all the consumers that we are gonna manage their bitrate.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
consumer->SetBitrateExternallyManaged();
}
} }
} }
...@@ -1172,7 +1180,21 @@ namespace RTC ...@@ -1172,7 +1180,21 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// TODO // TODO: Should call to a separate function (since it will ba called in
// other cases) that distributes available bitrate based on consumers'
// priority, etc.
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
auto priority = consumer->GetBitratePriority();
uint32_t bitrate{ 0 };
if (this->rembClient)
bitrate = this->rembClient->GetAvailableBitrate();
consumer->UseBitrate(bitrate);
}
} }
inline void WebRtcTransport::OnPacketRecv( inline void WebRtcTransport::OnPacketRecv(
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论