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