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