提交 13ca7f07 authored 作者: José Luis Millán's avatar José Luis Millán

smooth profile transition.

Wait upon reception of a video key frame to make the transition effective.
上级 2df20fbf
...@@ -63,6 +63,7 @@ namespace RTC ...@@ -63,6 +63,7 @@ namespace RTC
void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void RetransmitRtpPacket(RTC::RtpPacket* packet); void RetransmitRtpPacket(RTC::RtpPacket* packet);
void RecalculateEffectiveProfile(); void RecalculateEffectiveProfile();
void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile);
/* Pure virtual methods inherited from RTC::RtpStream::Listener. */ /* Pure virtual methods inherited from RTC::RtpStream::Listener. */
public: public:
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupError.hpp" #include "MediaSoupError.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "RTC/Codecs/Codecs.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp" #include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include <vector> #include <vector>
...@@ -237,7 +238,7 @@ namespace RTC ...@@ -237,7 +238,7 @@ namespace RTC
this->profiles.insert(profile); this->profiles.insert(profile);
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, "profile added: %s", RTC::RtpEncodingParameters::profile2String[profile].c_str()); rtp, "profile added [profile:%s]", RTC::RtpEncodingParameters::profile2String[profile].c_str());
; ;
RecalculateEffectiveProfile(); RecalculateEffectiveProfile();
...@@ -257,8 +258,8 @@ namespace RTC ...@@ -257,8 +258,8 @@ namespace RTC
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
"profile removed: %s", "profile removed [profile:%s]",
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str()); RTC::RtpEncodingParameters::profile2String[profile].c_str());
; ;
RecalculateEffectiveProfile(); RecalculateEffectiveProfile();
...@@ -273,6 +274,12 @@ namespace RTC ...@@ -273,6 +274,12 @@ namespace RTC
this->preferredProfile = profile; this->preferredProfile = profile;
MS_DEBUG_TAG(
rtp,
"preferred profile set [profile:%s]",
RTC::RtpEncodingParameters::profile2String[profile].c_str());
;
RecalculateEffectiveProfile(); RecalculateEffectiveProfile();
} }
...@@ -323,6 +330,26 @@ namespace RTC ...@@ -323,6 +330,26 @@ namespace RTC
return; return;
} }
// Whether we want to re-transmit the packet.
bool retransmissionNeeded = false;
// Check whether this is the key frame we are waiting for in order to update the effective
// profile.
if (
this->effectiveProfile != this->preferredProfile && profile == this->preferredProfile &&
Codecs::isKeyFrame(this->rtpStream->GetMymeType(), packet))
{
MS_DEBUG_TAG(rtp, "changing effective profile after receiving a key frame");
this->syncRequired = true;
this->rtpStream->ClearRetransmissionBuffer();
// Send this packet twice.
retransmissionNeeded = true;
SetEffectiveProfile(this->preferredProfile);
}
// If the packet belongs to different profile than the one being sent, drop it. // If the packet belongs to different profile than the one being sent, drop it.
// NOTE: This is specific to simulcast with no temporal layers. // NOTE: This is specific to simulcast with no temporal layers.
if (profile != this->effectiveProfile) if (profile != this->effectiveProfile)
...@@ -391,6 +418,17 @@ namespace RTC ...@@ -391,6 +418,17 @@ namespace RTC
// Update transmitted RTP data counter. // Update transmitted RTP data counter.
this->transmittedCounter.Update(packet); this->transmittedCounter.Update(packet);
if (retransmissionNeeded)
{
MS_DEBUG_TAG(
rtp,
"retransmitting packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(),
packet->GetSequenceNumber());
RetransmitRtpPacket(packet);
}
} }
// Restore packet SSRC. // Restore packet SSRC.
...@@ -568,8 +606,8 @@ namespace RTC ...@@ -568,8 +606,8 @@ namespace RTC
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"sending RTX packet [ssrc: %" PRIu32 ", seq: %" PRIu16 "sending RTX packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "] recovering original [ssrc:%" PRIu32
"] recovering original [ssrc: %" PRIu32 ", seq: %" PRIu16 "]", ", seq:%" PRIu16 "]",
rtxPacket->GetSsrc(), rtxPacket->GetSsrc(),
rtxPacket->GetSequenceNumber(), rtxPacket->GetSequenceNumber(),
packet->GetSsrc(), packet->GetSsrc(),
...@@ -580,7 +618,7 @@ namespace RTC ...@@ -580,7 +618,7 @@ namespace RTC
rtxPacket = packet; rtxPacket = packet;
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"retransmitting packet [ssrc: %" PRIu32 ", seq: %" PRIu16 "]", "retransmitting packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
rtxPacket->GetSsrc(), rtxPacket->GetSsrc(),
rtxPacket->GetSequenceNumber()); rtxPacket->GetSequenceNumber());
} }
...@@ -598,10 +636,6 @@ namespace RTC ...@@ -598,10 +636,6 @@ namespace RTC
void Consumer::RecalculateEffectiveProfile() void Consumer::RecalculateEffectiveProfile()
{ {
static const Json::StaticString JsonStringProfile{ "profile" };
Json::Value eventData(Json::objectValue);
RTC::RtpEncodingParameters::Profile newProfile; RTC::RtpEncodingParameters::Profile newProfile;
// If there are no profiles, select none or default, depending on whether this // If there are no profiles, select none or default, depending on whether this
...@@ -641,7 +675,43 @@ namespace RTC ...@@ -641,7 +675,43 @@ namespace RTC
if (newProfile == this->effectiveProfile) if (newProfile == this->effectiveProfile)
return; return;
this->effectiveProfile = newProfile; if (IsEnabled() && !IsPaused())
{
/*
* - This is the first time we are setting the effective profile.
* - The current effective profile is no longer available.
* - We don't handle the key frames for the used codec.
*/
if (
this->effectiveProfile == RTC::RtpEncodingParameters::Profile::DEFAULT ||
this->profiles.find(this->effectiveProfile) == this->profiles.end() ||
!RTC::Codecs::isKnown(this->rtpStream->GetMymeType()))
{
this->syncRequired = true;
this->rtpStream->ClearRetransmissionBuffer();
SetEffectiveProfile(newProfile);
}
// Otherwise set the effective profile upon reception of a key frame.
else
{
}
RequestFullFrame();
}
else
{
SetEffectiveProfile(newProfile);
}
}
void Consumer::SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile)
{
static const Json::StaticString JsonStringProfile{ "profile" };
Json::Value eventData(Json::objectValue);
this->effectiveProfile = profile;
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
...@@ -652,14 +722,5 @@ namespace RTC ...@@ -652,14 +722,5 @@ namespace RTC
// Notify. // Notify.
eventData[JsonStringProfile] = RTC::RtpEncodingParameters::profile2String[this->effectiveProfile]; eventData[JsonStringProfile] = RTC::RtpEncodingParameters::profile2String[this->effectiveProfile];
this->notifier->Emit(this->consumerId, "effectiveprofilechange", eventData); this->notifier->Emit(this->consumerId, "effectiveprofilechange", eventData);
if (IsEnabled() && !IsPaused())
{
this->rtpStream->ClearRetransmissionBuffer();
RequestFullFrame();
}
this->syncRequired = true;
} }
} // namespace RTC } // namespace RTC
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论