提交 8f75544e authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Habemus simulcast in Firefox

上级 6210868d
...@@ -77,7 +77,8 @@ namespace RTC ...@@ -77,7 +77,8 @@ namespace RTC
private: private:
void FillHeaderExtensionIds(); void FillHeaderExtensionIds();
void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void MayNeedNewStream(RTC::RtpPacket* packet);
void CreateRtpStream(RTC::RtpEncodingParameters& encoding, uint32_t ssrc);
void ClearRtpStream(RTC::RtpStreamRecv* rtpStream); void ClearRtpStream(RTC::RtpStreamRecv* rtpStream);
void ClearRtpStreams(); void ClearRtpStreams();
void ApplyRtpMapping(RTC::RtpPacket* packet) const; void ApplyRtpMapping(RTC::RtpPacket* packet) const;
......
...@@ -259,29 +259,11 @@ namespace RTC ...@@ -259,29 +259,11 @@ namespace RTC
static const Json::StaticString JsonStringTimestamp{ "timestamp" }; static const Json::StaticString JsonStringTimestamp{ "timestamp" };
static const Json::StaticString JsonStringSsrc{ "ssrc" }; static const Json::StaticString JsonStringSsrc{ "ssrc" };
// May need to create a new RtpStreamRecv.
MayNeedNewStream(packet);
// Find the corresponding RtpStreamRecv. // Find the corresponding RtpStreamRecv.
uint32_t ssrc = packet->GetSsrc(); uint32_t ssrc = packet->GetSsrc();
if (
this->rtpStreams.find(ssrc) == this->rtpStreams.end() &&
this->mapRtxStreams.find(ssrc) == this->mapRtxStreams.end())
{
for (auto& encoding : this->rtpParameters.encodings)
{
// TODO: This is not ready for RID usage (without SSRC in encodings).
if (encoding.ssrc == ssrc)
{
CreateRtpStream(encoding);
// If this is the first media packet for this stream request a full frame.
if (encoding.ssrc == ssrc)
RequestFullFrame(true);
break;
}
}
}
RTC::RtpStreamRecv* rtpStream{ nullptr }; RTC::RtpStreamRecv* rtpStream{ nullptr };
if (this->rtpStreams.find(ssrc) != this->rtpStreams.end()) if (this->rtpStreams.find(ssrc) != this->rtpStreams.end())
...@@ -488,11 +470,61 @@ namespace RTC ...@@ -488,11 +470,61 @@ namespace RTC
} }
} }
void Producer::CreateRtpStream(RTC::RtpEncodingParameters& encoding) void Producer::MayNeedNewStream(RTC::RtpPacket* packet)
{ {
MS_TRACE(); MS_TRACE();
uint32_t ssrc = encoding.ssrc; uint32_t ssrc = packet->GetSsrc();
// If already exists, do nothing.
if (
this->rtpStreams.find(ssrc) != this->rtpStreams.end() ||
this->mapRtxStreams.find(ssrc) != this->mapRtxStreams.end())
{
return;
}
// First look for encodings with ssrc field.
{
for (auto& encoding : this->rtpParameters.encodings)
{
if (encoding.ssrc == ssrc)
{
CreateRtpStream(encoding, ssrc);
return;
}
}
}
// TODO: Look for muxId.
// If not found, look for encodings with encodingId (RID) field.
{
const uint8_t* ridPtr;
size_t ridLen;
if (packet->ReadRid(&ridPtr, &ridLen))
{
auto* charRidPtr = const_cast<char*>(reinterpret_cast<const char*>(ridPtr));
std::string rid(charRidPtr, ridLen);
for (auto& encoding : this->rtpParameters.encodings)
{
if (encoding.encodingId == rid)
{
CreateRtpStream(encoding, ssrc);
return;
}
}
}
}
}
void Producer::CreateRtpStream(RTC::RtpEncodingParameters& encoding, uint32_t ssrc)
{
MS_TRACE();
MS_ASSERT(this->rtpStreams.find(ssrc) == this->rtpStreams.end(), "stream already exists"); MS_ASSERT(this->rtpStreams.find(ssrc) == this->rtpStreams.end(), "stream already exists");
...@@ -543,7 +575,7 @@ namespace RTC ...@@ -543,7 +575,7 @@ namespace RTC
if (useRemb) if (useRemb)
this->transport->EnableRemb(); this->transport->EnableRemb();
// Check rtx capabilities. // Check RTX capabilities.
if (encoding.hasRtx && encoding.rtx.ssrc != 0u) if (encoding.hasRtx && encoding.rtx.ssrc != 0u)
{ {
if (this->mapRtxStreams.find(encoding.rtx.ssrc) != this->mapRtxStreams.end()) if (this->mapRtxStreams.find(encoding.rtx.ssrc) != this->mapRtxStreams.end())
...@@ -570,6 +602,9 @@ namespace RTC ...@@ -570,6 +602,9 @@ namespace RTC
listener->OnProducerProfileEnabled(this, profile); listener->OnProducerProfileEnabled(this, profile);
} }
} }
// Request a full frame since we may have lost the first packets of this stream.
RequestFullFrame(true);
} }
void Producer::ClearRtpStream(RTC::RtpStreamRecv* rtpStream) void Producer::ClearRtpStream(RTC::RtpStreamRecv* rtpStream)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论