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

SimulcastConsumer:

- Improve key frame request handling.
- Be able to move to spatial layer -1 in more cases.
上级 87cebfe1
......@@ -42,7 +42,9 @@ namespace RTC
void UserOnPaused() override;
void UserOnResumed() override;
void CreateRtpStream();
void RequestKeyFrame();
void RequestKeyFrames();
void RequestKeyFrameForTargetSpatialLayer();
void RequestKeyFrameForCurrentSpatialLayer();
void MayChangeLayers(bool force = false);
bool RecalculateTargetLayers(int16_t& newTargetSpatialLayer, int16_t& newTargetTemporalLayer) const;
void UpdateTargetLayers(int16_t newTargetSpatialLayer, int16_t newTargetTemporalLayer);
......
......@@ -167,7 +167,7 @@ namespace RTC
case Channel::Request::MethodId::CONSUMER_REQUEST_KEY_FRAME:
{
if (IsActive())
RequestKeyFrame();
RequestKeyFrames();
request->Accept();
......@@ -276,20 +276,14 @@ namespace RTC
if (rtpStream == GetProducerCurrentRtpStream())
EmitScore();
// NOTE: Here it may happen that score is 0 and there is no other Producer stream
// with score > 0, so IsActive() will return false. We can live with that.
if (IsActive())
if (RTC::Consumer::IsActive())
{
// Just check target layers:
// - if our bitrate is not externally managed, or
// - if this is the target spatial layer and it has died or reborned.
// Just check target layers if the stream has died or reborned.
//
// clang-format off
if (
!this->externallyManagedBitrate ||
(
(score == 0 || previousScore == 0) &&
rtpStream == GetProducerTargetRtpStream()
)
(score == 0 || previousScore == 0)
)
// clang-format on
{
......@@ -309,7 +303,7 @@ namespace RTC
{
MS_TRACE();
if (!IsActive())
if (!RTC::Consumer::IsActive())
return 0;
int16_t prioritySpatialLayer{ 0 };
......@@ -345,7 +339,7 @@ namespace RTC
MS_ASSERT(this->externallyManagedBitrate == true, "bitrate is not externally managed");
if (!IsActive())
if (!RTC::Consumer::IsActive())
return 0;
// Calculate virtual available bitrate based on given bitrate and our
......@@ -464,7 +458,7 @@ namespace RTC
MS_ASSERT(this->externallyManagedBitrate == true, "bitrate is not externally managed");
if (!IsActive())
if (!RTC::Consumer::IsActive())
return 0;
// If no target spatial layer is selected, do nothing.
......@@ -551,7 +545,7 @@ namespace RTC
MS_ASSERT(this->externallyManagedBitrate == true, "bitrate is not externally managed");
if (!IsActive())
if (!RTC::Consumer::IsActive())
return;
// clang-format off
......@@ -777,7 +771,7 @@ namespace RTC
this->rtpStream->ReceiveKeyFrameRequest(messageType);
if (IsActive())
RequestKeyFrame();
RequestKeyFrameForCurrentSpatialLayer();
}
void SimulcastConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
......@@ -926,7 +920,7 @@ namespace RTC
this->encodingContext.reset(RTC::Codecs::GetEncodingContext(mediaCodec->mimeType));
}
void SimulcastConsumer::RequestKeyFrame()
void SimulcastConsumer::RequestKeyFrames()
{
MS_TRACE();
......@@ -951,6 +945,40 @@ namespace RTC
}
}
void SimulcastConsumer::RequestKeyFrameForTargetSpatialLayer()
{
MS_TRACE();
if (this->kind != RTC::Media::Kind::VIDEO)
return;
auto* producerTargetRtpStream = GetProducerTargetRtpStream();
if (!producerTargetRtpStream)
return;
auto mappedSsrc = this->consumableRtpEncodings[this->targetSpatialLayer].ssrc;
this->listener->OnConsumerKeyFrameRequested(this, mappedSsrc);
}
void SimulcastConsumer::RequestKeyFrameForCurrentSpatialLayer()
{
MS_TRACE();
if (this->kind != RTC::Media::Kind::VIDEO)
return;
auto* producerCurrentRtpStream = GetProducerCurrentRtpStream();
if (!producerCurrentRtpStream)
return;
auto mappedSsrc = this->consumableRtpEncodings[this->currentSpatialLayer].ssrc;
this->listener->OnConsumerKeyFrameRequested(this, mappedSsrc);
}
void SimulcastConsumer::MayChangeLayers(bool force)
{
MS_TRACE();
......@@ -1079,7 +1107,7 @@ namespace RTC
// If the target spatial layer is different than the current one, request
// a key frame.
if (this->targetSpatialLayer != this->currentSpatialLayer)
RequestKeyFrame();
RequestKeyFrameForTargetSpatialLayer();
}
void SimulcastConsumer::UpdateCurrentLayers()
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论