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

Simulcast based on SSRC ready for multiple profiles

上级 8f6a367a
......@@ -15,12 +15,12 @@
#include "RTC/RtpStreamSend.hpp"
#include "RTC/Transport.hpp"
#include <json/json.h>
#include <unordered_set>
#include <set>
#include <unordered_set>
namespace RTC
{
class Consumer: public RtpStream::Listener
class Consumer : public RtpStream::Listener
{
public:
Consumer(
......@@ -64,7 +64,7 @@ namespace RTC
void RetransmitRtpPacket(RTC::RtpPacket* packet);
void RecalculateEffectiveProfile();
/* Pure virtual methods inherited from RTC::RtpStream::Listener. */
/* Pure virtual methods inherited from RTC::RtpStream::Listener. */
public:
void OnRtpStreamHealthReport(RTC::RtpStream* rtpStream, bool healthy) override;
......@@ -100,8 +100,8 @@ namespace RTC
bool syncRequired{ true };
// RTP profiles.
std::set<RTC::RtpEncodingParameters::Profile> profiles;
RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::NONE };
RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::NONE };
RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
};
/* Inline methods. */
......
......@@ -15,9 +15,9 @@
#include "handles/Timer.hpp"
#include <json/json.h>
#include <map>
#include <set>
#include <string>
#include <unordered_set>
#include <set>
#include <vector>
namespace RTC
......@@ -119,7 +119,7 @@ namespace RTC
// Allocated by this.
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> rtpProfiles;
std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> profiles;
Timer* fullFrameRequestBlockTimer{ nullptr };
// Others.
std::vector<RtpEncodingParameters> outputEncodings;
......@@ -171,7 +171,7 @@ namespace RTC
{
std::set<RTC::RtpEncodingParameters::Profile> profiles;
for (const auto& it : this->rtpProfiles)
for (const auto& it : this->profiles)
{
for (const auto& it2 : it.second)
{
......
......@@ -18,8 +18,10 @@ namespace RTC
virtual void OnProducerResumed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpPacket(
RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile) = 0;
virtual void OnProducerProfileEnabled(RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0;
virtual void OnProducerProfileDisabled(RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0;
virtual void OnProducerProfileEnabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0;
virtual void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0;
};
} // namespace RTC
......
......@@ -72,11 +72,9 @@ namespace RTC
RTC::RtpPacket* packet,
RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileEnabled(
RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile) override;
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileDisabled(
RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile) override;
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
/* Pure virtual methods inherited from RTC::ConsumerListener. */
public:
......
......@@ -210,6 +210,7 @@ namespace RTC
enum class Profile : uint8_t
{
NONE = 0,
DEFAULT,
LOW,
MEDIUM,
HIGH
......@@ -239,7 +240,7 @@ namespace RTC
bool active{ true };
std::string encodingId;
std::vector<std::string> dependencyEncodingIds;
Profile profile{ Profile::NONE };
Profile profile{ Profile::DEFAULT };
};
class RtpHeaderExtensionParameters
......
......@@ -9,7 +9,7 @@
namespace RTC
{
class RtpStream: public Timer::Listener
class RtpStream : public Timer::Listener
{
public:
class Listener
......@@ -48,7 +48,7 @@ namespace RTC
/* Pure virtual methods that must be implemented by the subclass. */
protected:
virtual void OnInitSeq() = 0;
virtual void OnInitSeq() = 0;
virtual void CheckHealth() = 0;
/* Pure virtual methods inherited from Timer::Listener. */
......
......@@ -158,11 +158,9 @@ namespace RTC
RTC::RtpPacket* packet,
RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileEnabled(
RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile) override;
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileDisabled(
RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile) override;
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
/* Pure virtual methods inherited from RTC::ConsumerListener. */
public:
......
......@@ -226,20 +226,40 @@ namespace RTC
void Consumer::AddProfile(const RTC::RtpEncodingParameters::Profile profile)
{
MS_ASSERT(
profile != RTC::RtpEncodingParameters::Profile::NONE &&
profile != RTC::RtpEncodingParameters::Profile::DEFAULT,
"invalid profile");
MS_ASSERT(this->profiles.find(profile) != this->profiles.end(), "profile already exists");
// Insert profile.
this->profiles.insert(profile);
MS_DEBUG_TAG(rtp, "profile added: %s", RTC::RtpEncodingParameters::profile2String[profile].c_str());;
MS_DEBUG_TAG(
rtp, "profile added: %s", RTC::RtpEncodingParameters::profile2String[profile].c_str());
;
RecalculateEffectiveProfile();
}
void Consumer::RemoveProfile(const RTC::RtpEncodingParameters::Profile profile)
{
MS_ASSERT(
profile != RTC::RtpEncodingParameters::Profile::NONE &&
profile != RTC::RtpEncodingParameters::Profile::DEFAULT,
"invalid profile");
MS_ASSERT(this->profiles.find(profile) == this->profiles.end(), "profile not found");
// Remove profile.
this->profiles.erase(profile);
MS_DEBUG_TAG(rtp, "profile removed: %s", RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str());;
MS_DEBUG_TAG(
rtp,
"profile removed: %s",
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str());
;
RecalculateEffectiveProfile();
}
......@@ -311,17 +331,6 @@ namespace RTC
// Check whether sequence number and timestamp sync is required.
if (this->syncRequired)
{
// TODO
MS_ERROR("------------ syncRequired IS TRUE !!!!!");
// TODO
MS_ERROR(
"--- [profile:%s, effectiveProfile:%s, ssrc:%" PRIu32 ", packet->seq:%" PRIu16 "]",
RTC::RtpEncodingParameters::profile2String[profile].c_str(),
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str(),
packet->GetSsrc(),
packet->GetSequenceNumber());
this->seqNum += 1;
auto now = static_cast<uint32_t>(DepLibUV::GetTime());
......@@ -364,17 +373,6 @@ namespace RTC
// Update transmitted RTP data counter.
this->transmittedCounter.Update(packet);
}
else
{
// TODO
MS_ERROR(
"--- rtpStream->ReceivePacket() failed [profile:%s, effectiveProfile:%s, ssrc:%" PRIu32
", packet->seq:%" PRIu16 "]",
RTC::RtpEncodingParameters::profile2String[profile].c_str(),
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str(),
ssrc,
this->lastRecvSeqNum);
}
// Restore packet SSRC.
packet->SetSsrc(ssrc);
......@@ -587,10 +585,19 @@ namespace RTC
RTC::RtpEncodingParameters::Profile newProfile;
// If there are no profiles, select none or default, depending on whether this
// is single stream or simulcast/SVC.
if (this->profiles.empty())
{
if (this->effectiveProfile != RtpEncodingParameters::Profile::DEFAULT)
newProfile = RtpEncodingParameters::Profile::NONE;
else
newProfile = RtpEncodingParameters::Profile::DEFAULT;
}
// If there is no preferred profile, take the best one available.
if (this->preferredProfile == RTC::RtpEncodingParameters::Profile::NONE)
else if (this->preferredProfile == RTC::RtpEncodingParameters::Profile::DEFAULT)
{
auto it = this->profiles.crbegin();
auto it = this->profiles.crbegin();
newProfile = *it;
}
// Otherwise take the highest available profile equal or lower than the preferred.
......@@ -617,7 +624,11 @@ namespace RTC
this->effectiveProfile = newProfile;
MS_DEBUG_TAG(rtp, "new effective profile: %s", RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str());;
MS_DEBUG_TAG(
rtp,
"new effective profile: %s",
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile].c_str());
;
// Notify.
eventData[JsonStringProfile] = RTC::RtpEncodingParameters::profile2String[this->effectiveProfile];
......
......@@ -575,6 +575,7 @@ namespace RTC
this->rtpStreams.clear();
this->mapRtxStreams.clear();
this->profiles.clear();
}
void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const
......@@ -612,32 +613,40 @@ namespace RTC
}
}
RTC::RtpEncodingParameters::Profile Producer::GetProfile(RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet)
RTC::RtpEncodingParameters::Profile Producer::GetProfile(
RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet)
{
auto ssrc = packet->GetSsrc();
// The stream is already mapped to a profile.
if (this->rtpProfiles.find(rtpStream) != this->rtpProfiles.end())
if (this->profiles.find(rtpStream) != this->profiles.end())
{
auto it = this->rtpProfiles[rtpStream].begin();
auto it = this->profiles[rtpStream].begin();
auto profile = *it;
return *it;
return profile;
}
auto ssrc = packet->GetSsrc();
// Look for the encoding associated with the SSRC.
// NOTE: This is specific to simulcast with no temporal layers.
for (auto& encoding : this->rtpParameters.encodings)
{
if (encoding.ssrc == ssrc)
{
this->rtpProfiles[rtpStream].insert(encoding.profile);
auto profile = encoding.profile;
for (auto& listener : this->listeners)
this->profiles[rtpStream].insert(profile);
// Don't announce default profile, but just those for simulcast/SVC.
if (profile != RTC::RtpEncodingParameters::Profile::DEFAULT)
{
listener->OnProducerProfileEnabled(this, encoding.profile);
for (auto& listener : this->listeners)
{
listener->OnProducerProfileEnabled(this, profile);
}
}
return encoding.profile;
return profile;
}
}
......@@ -713,7 +722,7 @@ namespace RTC
MS_TRACE();
auto rtpStreamRecv = static_cast<RtpStreamRecv*>(rtpStream);
auto& profiles = this->rtpProfiles[rtpStreamRecv];
auto& profiles = this->profiles[rtpStreamRecv];
// The stream has transitioned to non healthy.
if (rtpStream->IsHealthy() && !healthy)
......@@ -723,8 +732,14 @@ namespace RTC
// Notify about the profiles being disabled.
for (auto& profile : profiles)
{
// Don't announce default profile, but just those for simulcast/SVC.
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break;
for (auto& listener : this->listeners)
{
listener->OnProducerProfileDisabled(this, profile);
}
}
}
......@@ -736,8 +751,14 @@ namespace RTC
// Notify about the profiles being disabled.
for (auto& profile : profiles)
{
// Don't announce default profile, but just those for simulcast/SVC.
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break;
for (auto& listener : this->listeners)
{
listener->OnProducerProfileEnabled(this, profile);
}
}
}
}
......
......@@ -1115,7 +1115,16 @@ namespace RTC
return;
}
consumer->SetPreferredProfile(it->second);
auto profile = it->second;
if (profile == RTC::RtpEncodingParameters::Profile::NONE || profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
{
request->Reject("invalid profile");
return;
}
consumer->SetPreferredProfile(profile);
request->Accept();
......@@ -1416,7 +1425,8 @@ namespace RTC
}
}
void Router::OnProducerProfileEnabled(RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile)
void Router::OnProducerProfileEnabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile)
{
MS_TRACE();
......@@ -1432,9 +1442,9 @@ namespace RTC
}
}
void Router::OnProducerProfileDisabled(RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile)
void Router::OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile)
{
MS_TRACE();
MS_ASSERT(
......
......@@ -12,18 +12,20 @@ namespace RTC
// clang-format off
std::map<std::string, RTC::RtpEncodingParameters::Profile> RTC::RtpEncodingParameters::string2Profile =
{
{ "none", RTC::RtpEncodingParameters::Profile::NONE },
{ "low", RTC::RtpEncodingParameters::Profile::LOW },
{ "medium", RTC::RtpEncodingParameters::Profile::MEDIUM },
{ "high", RTC::RtpEncodingParameters::Profile::HIGH }
{ "none", RTC::RtpEncodingParameters::Profile::NONE },
{ "default", RTC::RtpEncodingParameters::Profile::DEFAULT },
{ "low", RTC::RtpEncodingParameters::Profile::LOW },
{ "medium", RTC::RtpEncodingParameters::Profile::MEDIUM },
{ "high", RTC::RtpEncodingParameters::Profile::HIGH }
};
std::map<RTC::RtpEncodingParameters::Profile, std::string> RTC::RtpEncodingParameters::profile2String =
{
{ RTC::RtpEncodingParameters::Profile::NONE, "none" },
{ RTC::RtpEncodingParameters::Profile::LOW, "low" },
{ RTC::RtpEncodingParameters::Profile::MEDIUM, "medium" },
{ RTC::RtpEncodingParameters::Profile::HIGH, "high" }
{ RTC::RtpEncodingParameters::Profile::NONE, "none" },
{ RTC::RtpEncodingParameters::Profile::DEFAULT, "default" },
{ RTC::RtpEncodingParameters::Profile::LOW, "low" },
{ RTC::RtpEncodingParameters::Profile::MEDIUM, "medium" },
{ RTC::RtpEncodingParameters::Profile::HIGH, "high" }
};
// clang-format on
......@@ -115,6 +117,13 @@ namespace RTC
MS_THROW_ERROR("unknown profile");
this->profile = string2Profile[profileStr];
if (
this->profile == RTC::RtpEncodingParameters::Profile::NONE ||
this->profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
{
MS_THROW_ERROR("invalid profile");
}
}
}
......
......@@ -14,7 +14,7 @@ namespace RTC
static constexpr uint16_t MaxDropout{ 3000 };
static constexpr uint16_t MaxMisorder{ 100 };
static constexpr uint32_t RtpSeqMod{ 1 << 16 };
static constexpr uint16_t HealthCheckPeriod { 1000 };
static constexpr uint16_t HealthCheckPeriod{ 1000 };
/* Instance methods. */
......
......@@ -249,7 +249,7 @@ namespace RTC
void RtpStreamRecv::CheckHealth()
{
auto now = DepLibUV::GetTime();
auto now = DepLibUV::GetTime();
bool healthy = true;
if (this->receivedCounter.GetRate(now) == 0)
......
......@@ -1563,14 +1563,14 @@ namespace RTC
// Do nothing.
}
void Transport::OnProducerProfileEnabled(RTC::Producer* /*producer*/,
RTC::RtpEncodingParameters::Profile /*profile*/)
void Transport::OnProducerProfileEnabled(
RTC::Producer* /*producer*/, RTC::RtpEncodingParameters::Profile /*profile*/)
{
// Do nothing.
}
void Transport::OnProducerProfileDisabled(RTC::Producer* /*producer*/,
RTC::RtpEncodingParameters::Profile /*profile*/)
void Transport::OnProducerProfileDisabled(
RTC::Producer* /*producer*/, RTC::RtpEncodingParameters::Profile /*profile*/)
{
// Do nothing.
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论