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

SimulcastConsumer: do not select worst layers if not enough bitrate (fixes #299)

- If there is no available bitrate for a consumer, do not select the worst
  layer but honor the network conditions and emit "layerschanges" with null
  as argument (no layers).
- Introduce a new minimumAvailableBitrate (defaults to 100000 bps) setting
  in WebRtcTransport. This helps the bitrate recovery.
上级 7c07a1da
...@@ -215,6 +215,8 @@ class Router extends EnhancedEventEmitter ...@@ -215,6 +215,8 @@ class Router extends EnhancedEventEmitter
* @param {Boolean} [preferTcp=false] - Prefer TCP. * @param {Boolean} [preferTcp=false] - Prefer TCP.
* @param {Number} [initialAvailableOutgoingBitrate=600000] - Initial available * @param {Number} [initialAvailableOutgoingBitrate=600000] - Initial available
* outgoing bitrate (in bps) when the endpoint supports REMB or Transport-CC. * outgoing bitrate (in bps) when the endpoint supports REMB or Transport-CC.
* @param {Number} [minimumAvailableOutgoingBitrate=100000] - Minimum available
* outgoing bitrate (in bps).
* @param {Object} [appData={}] - Custom app data. * @param {Object} [appData={}] - Custom app data.
* *
* @async * @async
...@@ -228,6 +230,7 @@ class Router extends EnhancedEventEmitter ...@@ -228,6 +230,7 @@ class Router extends EnhancedEventEmitter
preferUdp = false, preferUdp = false,
preferTcp = false, preferTcp = false,
initialAvailableOutgoingBitrate = 600000, initialAvailableOutgoingBitrate = 600000,
minimumAvailableOutgoingBitrate = 100000,
appData = {} appData = {}
} = {} } = {}
) )
...@@ -265,7 +268,8 @@ class Router extends EnhancedEventEmitter ...@@ -265,7 +268,8 @@ class Router extends EnhancedEventEmitter
enableTcp, enableTcp,
preferUdp, preferUdp,
preferTcp, preferTcp,
initialAvailableOutgoingBitrate initialAvailableOutgoingBitrate,
minimumAvailableOutgoingBitrate
}; };
const data = const data =
......
...@@ -21,7 +21,10 @@ namespace RTC ...@@ -21,7 +21,10 @@ namespace RTC
}; };
public: public:
RembClient(RTC::RembClient::Listener* listener, uint32_t initialAvailableBitrate); RembClient(
RTC::RembClient::Listener* listener,
uint32_t initialAvailableBitrate,
uint32_t minimumAvailableBitrate);
virtual ~RembClient(); virtual ~RembClient();
public: public:
...@@ -44,6 +47,7 @@ namespace RTC ...@@ -44,6 +47,7 @@ namespace RTC
RTC::RtpProbator* rtpProbator{ nullptr }; RTC::RtpProbator* rtpProbator{ nullptr };
// Others. // Others.
uint32_t initialAvailableBitrate{ 0 }; uint32_t initialAvailableBitrate{ 0 };
uint32_t minimumAvailableBitrate{ 0 };
uint64_t initialAvailableBitrateAt{ 0 }; uint64_t initialAvailableBitrateAt{ 0 };
uint32_t availableBitrate{ 0 }; uint32_t availableBitrate{ 0 };
uint64_t lastEventAt{ 0 }; uint64_t lastEventAt{ 0 };
......
...@@ -135,7 +135,8 @@ namespace RTC ...@@ -135,7 +135,8 @@ namespace RTC
std::vector<RTC::IceCandidate> iceCandidates; std::vector<RTC::IceCandidate> iceCandidates;
RTC::TransportTuple* iceSelectedTuple{ nullptr }; RTC::TransportTuple* iceSelectedTuple{ nullptr };
RTC::DtlsTransport::Role dtlsRole{ RTC::DtlsTransport::Role::AUTO }; RTC::DtlsTransport::Role dtlsRole{ RTC::DtlsTransport::Role::AUTO };
uint32_t initialAvailableOutgoingBitrate{ 300000 }; uint32_t initialAvailableOutgoingBitrate{ 600000 };
uint32_t minimumAvailableOutgoingBitrate{ 100000 };
uint32_t maxIncomingBitrate{ 0 }; uint32_t maxIncomingBitrate{ 0 };
}; };
} // namespace RTC } // namespace RTC
......
...@@ -15,8 +15,12 @@ namespace RTC ...@@ -15,8 +15,12 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
RembClient::RembClient(RTC::RembClient::Listener* listener, uint32_t initialAvailableBitrate) RembClient::RembClient(
: listener(listener), initialAvailableBitrate(initialAvailableBitrate) RTC::RembClient::Listener* listener,
uint32_t initialAvailableBitrate,
uint32_t minimumAvailableBitrate)
: listener(listener), initialAvailableBitrate(initialAvailableBitrate),
minimumAvailableBitrate(minimumAvailableBitrate)
{ {
MS_TRACE(); MS_TRACE();
...@@ -52,6 +56,11 @@ namespace RTC ...@@ -52,6 +56,11 @@ namespace RTC
{ {
this->availableBitrate = this->initialAvailableBitrate; this->availableBitrate = this->initialAvailableBitrate;
} }
// Otherwise if REMB reports less than minimumAvailableBitrate, honor it.
else if (this->availableBitrate < this->minimumAvailableBitrate)
{
this->availableBitrate = this->minimumAvailableBitrate;
}
// Emit event if EventInterval elapsed. // Emit event if EventInterval elapsed.
if (now - this->lastEventAt >= EventInterval) if (now - this->lastEventAt >= EventInterval)
......
...@@ -307,7 +307,7 @@ namespace RTC ...@@ -307,7 +307,7 @@ namespace RTC
for (size_t idx{ 0 }; idx < this->producerRtpStreams.size(); ++idx) for (size_t idx{ 0 }; idx < this->producerRtpStreams.size(); ++idx)
{ {
auto spatialLayer = static_cast<int16_t>(idx); auto spatialLayer = static_cast<int16_t>(idx);
auto* producerRtpStream = this->producerRtpStreams[idx]; auto* producerRtpStream = this->producerRtpStreams.at(idx);
// Ignore spatial layers for non existing Producer streams or for those // Ignore spatial layers for non existing Producer streams or for those
// with score 0. // with score 0.
...@@ -359,7 +359,7 @@ namespace RTC ...@@ -359,7 +359,7 @@ namespace RTC
for (size_t idx{ 0 }; idx < this->producerRtpStreams.size(); ++idx) for (size_t idx{ 0 }; idx < this->producerRtpStreams.size(); ++idx)
{ {
auto spatialLayer = static_cast<int16_t>(idx); auto spatialLayer = static_cast<int16_t>(idx);
auto* producerRtpStream = this->producerRtpStreams[idx]; auto* producerRtpStream = this->producerRtpStreams.at(idx);
auto producerScore = producerRtpStream ? producerRtpStream->GetScore() : 0; auto producerScore = producerRtpStream ? producerRtpStream->GetScore() : 0;
// Ignore spatial layers for non existing Producer streams or for those // Ignore spatial layers for non existing Producer streams or for those
...@@ -369,14 +369,6 @@ namespace RTC ...@@ -369,14 +369,6 @@ namespace RTC
if (producerScore >= maxProducerScore || producerScore >= 7) if (producerScore >= maxProducerScore || producerScore >= 7)
{ {
// NOTE: If this is the first valid spatial layer take it. This is because,
// even if there is no enough bitrate for it, we need to take something.
if (this->provisionalTargetSpatialLayer == -1)
{
this->provisionalTargetSpatialLayer = spatialLayer;
this->provisionalTargetTemporalLayer = 0;
}
int16_t temporalLayer{ 0 }; int16_t temporalLayer{ 0 };
// Check bitrate of every layer. // Check bitrate of every layer.
...@@ -455,14 +447,9 @@ namespace RTC ...@@ -455,14 +447,9 @@ namespace RTC
if (!RTC::Consumer::IsActive()) if (!RTC::Consumer::IsActive())
return 0; return 0;
// If no target spatial layer is selected, do nothing.
if (this->provisionalTargetSpatialLayer == -1)
{
return 0;
}
// If already in the preferred layers, do nothing. // If already in the preferred layers, do nothing.
// clang-format off // clang-format off
else if ( if (
this->provisionalTargetSpatialLayer == this->preferredSpatialLayer && this->provisionalTargetSpatialLayer == this->preferredSpatialLayer &&
this->provisionalTargetTemporalLayer == this->preferredTemporalLayer this->provisionalTargetTemporalLayer == this->preferredTemporalLayer
) )
...@@ -484,13 +471,30 @@ namespace RTC ...@@ -484,13 +471,30 @@ namespace RTC
else else
virtualBitrate = bitrate; virtualBitrate = bitrate;
auto spatialLayer = this->provisionalTargetSpatialLayer; auto spatialLayer = this->provisionalTargetSpatialLayer;
auto temporalLayer = this->provisionalTargetTemporalLayer; auto temporalLayer = this->provisionalTargetTemporalLayer;
auto producerRtpStream = this->producerRtpStreams.at(spatialLayer); RTC::RtpStream* producerRtpStream{ nullptr };
// Can upgrade from no spatial layer to spatial layer 0.
if (spatialLayer == -1)
{
producerRtpStream = this->producerRtpStreams.at(0);
if (producerRtpStream && producerRtpStream->GetScore() > 0)
{
spatialLayer = 0;
temporalLayer = 0;
}
else
{
// Must return now since we do not even have a producerRtpStream.
return 0;
}
}
// Can upgrade temporal layer. // Can upgrade temporal layer.
if (temporalLayer < producerRtpStream->GetTemporalLayers() - 1) else if (temporalLayer < this->producerRtpStreams.at(spatialLayer)->GetTemporalLayers() - 1)
{ {
producerRtpStream = this->producerRtpStreams.at(spatialLayer);
++temporalLayer; ++temporalLayer;
} }
// Can upgrade spatial layer. // Can upgrade spatial layer.
...@@ -498,7 +502,7 @@ namespace RTC ...@@ -498,7 +502,7 @@ namespace RTC
{ {
producerRtpStream = this->producerRtpStreams.at(++spatialLayer); producerRtpStream = this->producerRtpStreams.at(++spatialLayer);
// Producer stream does not exist or it's dead. Exit. // Producer stream does not exist or it's not good. Exit.
if (!producerRtpStream || producerRtpStream->GetScore() < 7) if (!producerRtpStream || producerRtpStream->GetScore() < 7)
return 0; return 0;
...@@ -1013,7 +1017,7 @@ namespace RTC ...@@ -1013,7 +1017,7 @@ namespace RTC
for (size_t idx{ 0 }; idx < this->producerRtpStreams.size(); ++idx) for (size_t idx{ 0 }; idx < this->producerRtpStreams.size(); ++idx)
{ {
auto spatialLayer = static_cast<int16_t>(idx); auto spatialLayer = static_cast<int16_t>(idx);
auto* producerRtpStream = this->producerRtpStreams[idx]; auto* producerRtpStream = this->producerRtpStreams.at(idx);
auto producerScore = producerRtpStream ? producerRtpStream->GetScore() : 0; auto producerScore = producerRtpStream ? producerRtpStream->GetScore() : 0;
// Ignore spatial layers for non existing Producer streams or for those // Ignore spatial layers for non existing Producer streams or for those
......
...@@ -138,6 +138,22 @@ namespace RTC ...@@ -138,6 +138,22 @@ namespace RTC
this->initialAvailableOutgoingBitrate = jsonInitialAvailableOutgoingBitrateIt->get<uint32_t>(); this->initialAvailableOutgoingBitrate = jsonInitialAvailableOutgoingBitrateIt->get<uint32_t>();
} }
auto jsonMinimumAvailableOutgoingBitrateIt = data.find("minimumAvailableOutgoingBitrate");
if (jsonMinimumAvailableOutgoingBitrateIt != data.end())
{
if (!jsonMinimumAvailableOutgoingBitrateIt->is_number_unsigned())
MS_THROW_TYPE_ERROR("wrong minimumAvailableOutgoingBitrate (not a number)");
this->minimumAvailableOutgoingBitrate = jsonMinimumAvailableOutgoingBitrateIt->get<uint32_t>();
}
if (this->minimumAvailableOutgoingBitrate > this->initialAvailableOutgoingBitrate)
{
MS_THROW_TYPE_ERROR(
"minimumAvailableOutgoingBitrate bigger than initialAvailableOutgoingBitrate");
}
try try
{ {
uint16_t iceLocalPreferenceDecrement{ 0 }; uint16_t iceLocalPreferenceDecrement{ 0 };
...@@ -1287,7 +1303,8 @@ namespace RTC ...@@ -1287,7 +1303,8 @@ namespace RTC
{ {
MS_DEBUG_TAG(bwe, "enabling REMB client"); MS_DEBUG_TAG(bwe, "enabling REMB client");
this->rembClient = new RTC::RembClient(this, this->initialAvailableOutgoingBitrate); this->rembClient = new RTC::RembClient(
this, this->initialAvailableOutgoingBitrate, this->minimumAvailableOutgoingBitrate);
// Tell all the Consumers that we are gonna manage their bitrate. // Tell all the Consumers that we are gonna manage their bitrate.
for (auto& kv : this->mapConsumers) for (auto& kv : this->mapConsumers)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论