提交 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 @@ ...@@ -15,12 +15,12 @@
#include "RTC/RtpStreamSend.hpp" #include "RTC/RtpStreamSend.hpp"
#include "RTC/Transport.hpp" #include "RTC/Transport.hpp"
#include <json/json.h> #include <json/json.h>
#include <unordered_set>
#include <set> #include <set>
#include <unordered_set>
namespace RTC namespace RTC
{ {
class Consumer: public RtpStream::Listener class Consumer : public RtpStream::Listener
{ {
public: public:
Consumer( Consumer(
...@@ -100,8 +100,8 @@ namespace RTC ...@@ -100,8 +100,8 @@ namespace RTC
bool syncRequired{ true }; bool syncRequired{ true };
// RTP profiles. // RTP profiles.
std::set<RTC::RtpEncodingParameters::Profile> profiles; std::set<RTC::RtpEncodingParameters::Profile> profiles;
RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::NONE }; RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::NONE }; RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
}; };
/* Inline methods. */ /* Inline methods. */
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#include "handles/Timer.hpp" #include "handles/Timer.hpp"
#include <json/json.h> #include <json/json.h>
#include <map> #include <map>
#include <set>
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
#include <set>
#include <vector> #include <vector>
namespace RTC namespace RTC
...@@ -119,7 +119,7 @@ namespace RTC ...@@ -119,7 +119,7 @@ namespace RTC
// Allocated by this. // Allocated by this.
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams; std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams; 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 }; Timer* fullFrameRequestBlockTimer{ nullptr };
// Others. // Others.
std::vector<RtpEncodingParameters> outputEncodings; std::vector<RtpEncodingParameters> outputEncodings;
...@@ -171,7 +171,7 @@ namespace RTC ...@@ -171,7 +171,7 @@ namespace RTC
{ {
std::set<RTC::RtpEncodingParameters::Profile> profiles; std::set<RTC::RtpEncodingParameters::Profile> profiles;
for (const auto& it : this->rtpProfiles) for (const auto& it : this->profiles)
{ {
for (const auto& it2 : it.second) for (const auto& it2 : it.second)
{ {
......
...@@ -18,8 +18,10 @@ namespace RTC ...@@ -18,8 +18,10 @@ namespace RTC
virtual void OnProducerResumed(RTC::Producer* producer) = 0; virtual void OnProducerResumed(RTC::Producer* producer) = 0;
virtual void OnProducerRtpPacket( virtual void OnProducerRtpPacket(
RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile) = 0; RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile) = 0;
virtual void OnProducerProfileEnabled(RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0; virtual void OnProducerProfileEnabled(
virtual void OnProducerProfileDisabled(RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0; RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0;
virtual void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0;
}; };
} // namespace RTC } // namespace RTC
......
...@@ -72,11 +72,9 @@ namespace RTC ...@@ -72,11 +72,9 @@ namespace RTC
RTC::RtpPacket* packet, RTC::RtpPacket* packet,
RTC::RtpEncodingParameters::Profile profile) override; RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileEnabled( void OnProducerProfileEnabled(
RTC::Producer* producer, RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileDisabled( void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
RTC::RtpEncodingParameters::Profile profile) override;
/* Pure virtual methods inherited from RTC::ConsumerListener. */ /* Pure virtual methods inherited from RTC::ConsumerListener. */
public: public:
......
...@@ -210,6 +210,7 @@ namespace RTC ...@@ -210,6 +210,7 @@ namespace RTC
enum class Profile : uint8_t enum class Profile : uint8_t
{ {
NONE = 0, NONE = 0,
DEFAULT,
LOW, LOW,
MEDIUM, MEDIUM,
HIGH HIGH
...@@ -239,7 +240,7 @@ namespace RTC ...@@ -239,7 +240,7 @@ namespace RTC
bool active{ true }; bool active{ true };
std::string encodingId; std::string encodingId;
std::vector<std::string> dependencyEncodingIds; std::vector<std::string> dependencyEncodingIds;
Profile profile{ Profile::NONE }; Profile profile{ Profile::DEFAULT };
}; };
class RtpHeaderExtensionParameters class RtpHeaderExtensionParameters
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace RTC namespace RTC
{ {
class RtpStream: public Timer::Listener class RtpStream : public Timer::Listener
{ {
public: public:
class Listener class Listener
......
...@@ -158,11 +158,9 @@ namespace RTC ...@@ -158,11 +158,9 @@ namespace RTC
RTC::RtpPacket* packet, RTC::RtpPacket* packet,
RTC::RtpEncodingParameters::Profile profile) override; RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileEnabled( void OnProducerProfileEnabled(
RTC::Producer* producer, RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileDisabled( void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
RTC::RtpEncodingParameters::Profile profile) override;
/* Pure virtual methods inherited from RTC::ConsumerListener. */ /* Pure virtual methods inherited from RTC::ConsumerListener. */
public: public:
......
...@@ -226,20 +226,40 @@ namespace RTC ...@@ -226,20 +226,40 @@ namespace RTC
void Consumer::AddProfile(const RTC::RtpEncodingParameters::Profile profile) 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. // Insert profile.
this->profiles.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(); RecalculateEffectiveProfile();
} }
void Consumer::RemoveProfile(const RTC::RtpEncodingParameters::Profile profile) 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. // Remove profile.
this->profiles.erase(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(); RecalculateEffectiveProfile();
} }
...@@ -311,17 +331,6 @@ namespace RTC ...@@ -311,17 +331,6 @@ namespace RTC
// Check whether sequence number and timestamp sync is required. // Check whether sequence number and timestamp sync is required.
if (this->syncRequired) 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; this->seqNum += 1;
auto now = static_cast<uint32_t>(DepLibUV::GetTime()); auto now = static_cast<uint32_t>(DepLibUV::GetTime());
...@@ -364,17 +373,6 @@ namespace RTC ...@@ -364,17 +373,6 @@ namespace RTC
// Update transmitted RTP data counter. // Update transmitted RTP data counter.
this->transmittedCounter.Update(packet); 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. // Restore packet SSRC.
packet->SetSsrc(ssrc); packet->SetSsrc(ssrc);
...@@ -587,8 +585,17 @@ namespace RTC ...@@ -587,8 +585,17 @@ namespace RTC
RTC::RtpEncodingParameters::Profile newProfile; 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 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; newProfile = *it;
...@@ -617,7 +624,11 @@ namespace RTC ...@@ -617,7 +624,11 @@ namespace RTC
this->effectiveProfile = newProfile; 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. // Notify.
eventData[JsonStringProfile] = RTC::RtpEncodingParameters::profile2String[this->effectiveProfile]; eventData[JsonStringProfile] = RTC::RtpEncodingParameters::profile2String[this->effectiveProfile];
......
...@@ -575,6 +575,7 @@ namespace RTC ...@@ -575,6 +575,7 @@ namespace RTC
this->rtpStreams.clear(); this->rtpStreams.clear();
this->mapRtxStreams.clear(); this->mapRtxStreams.clear();
this->profiles.clear();
} }
void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const
...@@ -612,32 +613,40 @@ namespace RTC ...@@ -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. // 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. // Look for the encoding associated with the SSRC.
// NOTE: This is specific to simulcast with no temporal layers. // NOTE: This is specific to simulcast with no temporal layers.
for (auto& encoding : this->rtpParameters.encodings) for (auto& encoding : this->rtpParameters.encodings)
{ {
if (encoding.ssrc == ssrc) if (encoding.ssrc == ssrc)
{ {
this->rtpProfiles[rtpStream].insert(encoding.profile); auto profile = encoding.profile;
this->profiles[rtpStream].insert(profile);
// Don't announce default profile, but just those for simulcast/SVC.
if (profile != RTC::RtpEncodingParameters::Profile::DEFAULT)
{
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
listener->OnProducerProfileEnabled(this, encoding.profile); listener->OnProducerProfileEnabled(this, profile);
}
} }
return encoding.profile; return profile;
} }
} }
...@@ -713,7 +722,7 @@ namespace RTC ...@@ -713,7 +722,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
auto rtpStreamRecv = static_cast<RtpStreamRecv*>(rtpStream); auto rtpStreamRecv = static_cast<RtpStreamRecv*>(rtpStream);
auto& profiles = this->rtpProfiles[rtpStreamRecv]; auto& profiles = this->profiles[rtpStreamRecv];
// The stream has transitioned to non healthy. // The stream has transitioned to non healthy.
if (rtpStream->IsHealthy() && !healthy) if (rtpStream->IsHealthy() && !healthy)
...@@ -723,10 +732,16 @@ namespace RTC ...@@ -723,10 +732,16 @@ namespace RTC
// Notify about the profiles being disabled. // Notify about the profiles being disabled.
for (auto& profile : profiles) 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) for (auto& listener : this->listeners)
{
listener->OnProducerProfileDisabled(this, profile); listener->OnProducerProfileDisabled(this, profile);
} }
} }
}
// The stream has transitioned to healthy. // The stream has transitioned to healthy.
if (!rtpStream->IsHealthy() && healthy) if (!rtpStream->IsHealthy() && healthy)
...@@ -736,11 +751,17 @@ namespace RTC ...@@ -736,11 +751,17 @@ namespace RTC
// Notify about the profiles being disabled. // Notify about the profiles being disabled.
for (auto& profile : profiles) 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) for (auto& listener : this->listeners)
{
listener->OnProducerProfileEnabled(this, profile); listener->OnProducerProfileEnabled(this, profile);
} }
} }
} }
}
inline void Producer::OnTimer(Timer* timer) inline void Producer::OnTimer(Timer* timer)
{ {
......
...@@ -1115,7 +1115,16 @@ namespace RTC ...@@ -1115,7 +1115,16 @@ namespace RTC
return; 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(); request->Accept();
...@@ -1416,7 +1425,8 @@ namespace RTC ...@@ -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(); MS_TRACE();
...@@ -1432,9 +1442,9 @@ namespace RTC ...@@ -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_TRACE();
MS_ASSERT( MS_ASSERT(
......
...@@ -13,6 +13,7 @@ namespace RTC ...@@ -13,6 +13,7 @@ namespace RTC
std::map<std::string, RTC::RtpEncodingParameters::Profile> RTC::RtpEncodingParameters::string2Profile = std::map<std::string, RTC::RtpEncodingParameters::Profile> RTC::RtpEncodingParameters::string2Profile =
{ {
{ "none", RTC::RtpEncodingParameters::Profile::NONE }, { "none", RTC::RtpEncodingParameters::Profile::NONE },
{ "default", RTC::RtpEncodingParameters::Profile::DEFAULT },
{ "low", RTC::RtpEncodingParameters::Profile::LOW }, { "low", RTC::RtpEncodingParameters::Profile::LOW },
{ "medium", RTC::RtpEncodingParameters::Profile::MEDIUM }, { "medium", RTC::RtpEncodingParameters::Profile::MEDIUM },
{ "high", RTC::RtpEncodingParameters::Profile::HIGH } { "high", RTC::RtpEncodingParameters::Profile::HIGH }
...@@ -21,6 +22,7 @@ namespace RTC ...@@ -21,6 +22,7 @@ namespace RTC
std::map<RTC::RtpEncodingParameters::Profile, std::string> RTC::RtpEncodingParameters::profile2String = std::map<RTC::RtpEncodingParameters::Profile, std::string> RTC::RtpEncodingParameters::profile2String =
{ {
{ RTC::RtpEncodingParameters::Profile::NONE, "none" }, { RTC::RtpEncodingParameters::Profile::NONE, "none" },
{ RTC::RtpEncodingParameters::Profile::DEFAULT, "default" },
{ RTC::RtpEncodingParameters::Profile::LOW, "low" }, { RTC::RtpEncodingParameters::Profile::LOW, "low" },
{ RTC::RtpEncodingParameters::Profile::MEDIUM, "medium" }, { RTC::RtpEncodingParameters::Profile::MEDIUM, "medium" },
{ RTC::RtpEncodingParameters::Profile::HIGH, "high" } { RTC::RtpEncodingParameters::Profile::HIGH, "high" }
...@@ -115,6 +117,13 @@ namespace RTC ...@@ -115,6 +117,13 @@ namespace RTC
MS_THROW_ERROR("unknown profile"); MS_THROW_ERROR("unknown profile");
this->profile = string2Profile[profileStr]; 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 ...@@ -14,7 +14,7 @@ namespace RTC
static constexpr uint16_t MaxDropout{ 3000 }; static constexpr uint16_t MaxDropout{ 3000 };
static constexpr uint16_t MaxMisorder{ 100 }; static constexpr uint16_t MaxMisorder{ 100 };
static constexpr uint32_t RtpSeqMod{ 1 << 16 }; static constexpr uint32_t RtpSeqMod{ 1 << 16 };
static constexpr uint16_t HealthCheckPeriod { 1000 }; static constexpr uint16_t HealthCheckPeriod{ 1000 };
/* Instance methods. */ /* Instance methods. */
......
...@@ -1563,14 +1563,14 @@ namespace RTC ...@@ -1563,14 +1563,14 @@ namespace RTC
// Do nothing. // Do nothing.
} }
void Transport::OnProducerProfileEnabled(RTC::Producer* /*producer*/, void Transport::OnProducerProfileEnabled(
RTC::RtpEncodingParameters::Profile /*profile*/) RTC::Producer* /*producer*/, RTC::RtpEncodingParameters::Profile /*profile*/)
{ {
// Do nothing. // Do nothing.
} }
void Transport::OnProducerProfileDisabled(RTC::Producer* /*producer*/, void Transport::OnProducerProfileDisabled(
RTC::RtpEncodingParameters::Profile /*profile*/) RTC::Producer* /*producer*/, RTC::RtpEncodingParameters::Profile /*profile*/)
{ {
// Do nothing. // Do nothing.
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论