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

VP8 & H264: improve temporal layer switching (better currentTemporalLayer handling)

上级 4a75900b
......@@ -15,7 +15,8 @@ namespace RTC
virtual void Dump() const = 0;
};
// Encoding context used by PayloadDescriptorHandler to properly rewrite the PayloadDescriptor.
// Encoding context used by PayloadDescriptorHandler to properly rewrite the
// PayloadDescriptor.
class EncodingContext
{
public:
......@@ -29,11 +30,10 @@ namespace RTC
};
public:
virtual void SyncRequired() = 0;
virtual void SetPreferences(Preferences preferences);
virtual ~EncodingContext() = default;
public:
virtual ~EncodingContext() = default;
virtual void SyncRequired() = 0;
public:
Preferences preferences;
......@@ -41,6 +41,9 @@ namespace RTC
class PayloadDescriptorHandler
{
public:
virtual ~PayloadDescriptorHandler() = default;
public:
virtual void Dump() const = 0;
virtual bool Encode(RTC::Codecs::EncodingContext* context, uint8_t* data) = 0;
......@@ -48,15 +51,7 @@ namespace RTC
virtual uint8_t GetSpatialLayer() const = 0;
virtual uint8_t GetTemporalLayer() const = 0;
virtual bool IsKeyFrame() const = 0;
public:
virtual ~PayloadDescriptorHandler() = default;
};
inline void EncodingContext::SetPreferences(Preferences preferences)
{
this->preferences = preferences;
}
} // namespace Codecs
} // namespace RTC
......
......@@ -172,37 +172,37 @@ namespace RTC
auto* context = static_cast<RTC::Codecs::H264::EncodingContext*>(encodingContext);
// Check temporal layer.
// If a key frame, update currentTemporalLayer.
if (this->payloadDescriptor->isKeyFrame)
context->currentTemporalLayer = std::numeric_limits<uint8_t>::max();
// TODO: We should check incremental picture id here somehow and let it pass
// if so.
// if older than highest seen.
// Check temporal layer.
if (this->payloadDescriptor->tid > context->preferences.temporalLayer)
{
return false;
}
else if (context->currentTemporalLayer != context->preferences.temporalLayer)
{
// Payload descriptor contains the target temporal layer.
if (this->payloadDescriptor->tid == context->preferences.temporalLayer)
{
// Upgrade required. Drop current packet if base flag is not set.
// NOTE: It seems that Base Layer Sync flag is never set when in lowest
// simulcast stream. We may need to implement "The Layer Refresh Request
// (LRR) RTCP Feedback Message":
// https://tools.ietf.org/html/draft-ietf-avtext-lrr-07)
//
// clang-format off
// if (
// this->payloadDescriptor->tid > context->currentTemporalLayer &&
// !this->payloadDescriptor->b
// )
// // clang-format on
// {
// return false;
// }
context->currentTemporalLayer = this->payloadDescriptor->tid;
}
}
// Upgrade required. Drop current packet if base flag is not set.
// TODO: Cannot enable this until this issue is fixed (in libwebrtc?):
// https://github.com/versatica/mediasoup/issues/306
//
// clang-format off
// else if (
// this->payloadDescriptor->tid > context->currentTemporalLayer &&
// !this->payloadDescriptor->b
// )
// // clang-format on
// {
// return false;
// }
// Update/fix currentTemporalLayer.
if (this->payloadDescriptor->tid > context->currentTemporalLayer)
context->currentTemporalLayer = this->payloadDescriptor->tid;
else if (context->currentTemporalLayer > context->preferences.temporalLayer)
context->currentTemporalLayer = context->preferences.temporalLayer;
return true;
}
......
......@@ -232,9 +232,14 @@ namespace RTC
{
context->pictureIdManager.Sync(this->payloadDescriptor->pictureId - 1);
context->tl0PictureIndexManager.Sync(this->payloadDescriptor->tl0PictureIndex - 1);
context->syncRequired = false;
}
// If a key frame, update currentTemporalLayer.
if (this->payloadDescriptor->isKeyFrame)
context->currentTemporalLayer = std::numeric_limits<uint8_t>::max();
// Incremental pictureId. Check the temporal layer.
// clang-format off
if (
......@@ -254,27 +259,18 @@ namespace RTC
return false;
}
else if (context->currentTemporalLayer != context->preferences.temporalLayer)
// Upgrade required. Drop current packet if sync flag is not set.
// clang-format off
else if (
this->payloadDescriptor->tlIndex > context->currentTemporalLayer &&
!this->payloadDescriptor->y
)
// clang-format on
{
// Payload descriptor contains the target temporal layer.
if (this->payloadDescriptor->tlIndex == context->preferences.temporalLayer)
{
// Upgrade required. Drop current packet if sync flag is not set.
// clang-format off
if (
this->payloadDescriptor->tlIndex > context->currentTemporalLayer &&
!this->payloadDescriptor->y
)
// clang-format on
{
context->pictureIdManager.Drop(this->payloadDescriptor->pictureId);
context->tl0PictureIndexManager.Drop(this->payloadDescriptor->tl0PictureIndex);
return false;
}
context->currentTemporalLayer = this->payloadDescriptor->tlIndex;
}
context->pictureIdManager.Drop(this->payloadDescriptor->pictureId);
context->tl0PictureIndexManager.Drop(this->payloadDescriptor->tl0PictureIndex);
return false;
}
}
......@@ -284,7 +280,9 @@ namespace RTC
// Do not send a dropped pictureId.
if (!context->pictureIdManager.Input(this->payloadDescriptor->pictureId, pictureId))
{
return false;
}
// Do not send a dropped tl0PicutreIndex.
if (!context->tl0PictureIndexManager.Input(
......@@ -293,6 +291,12 @@ namespace RTC
return false;
}
// Update/fix currentTemporalLayer.
if (this->payloadDescriptor->tlIndex > context->currentTemporalLayer)
context->currentTemporalLayer = this->payloadDescriptor->tlIndex;
else if (context->currentTemporalLayer > context->preferences.temporalLayer)
context->currentTemporalLayer = context->preferences.temporalLayer;
this->payloadDescriptor->Encode(data, pictureId, tl0PictureIndex);
return true;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论