提交 240fe01e authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Improve RtpParameters.

上级 1450d0eb
...@@ -46,7 +46,12 @@ namespace RTC ...@@ -46,7 +46,12 @@ namespace RTC
{ {
return this->type == Type::DOUBLE; return this->type == Type::DOUBLE;
} }
bool IsString(){ bool IsPositiveDouble()
{
return this->type == Type::DOUBLE && this->doubleValue >= 0;
}
bool IsString()
{
return this->type == Type::STRING; return this->type == Type::STRING;
} }
......
...@@ -70,7 +70,7 @@ namespace RTC ...@@ -70,7 +70,7 @@ namespace RTC
for (auto& kv : this->ssrcTable) for (auto& kv : this->ssrcTable)
{ {
auto& ssrc = kv.first; auto ssrc = kv.first;
auto& existingRtpReceiver = kv.second; auto& existingRtpReceiver = kv.second;
if (existingRtpReceiver == rtpReceiver) if (existingRtpReceiver == rtpReceiver)
...@@ -91,7 +91,7 @@ namespace RTC ...@@ -91,7 +91,7 @@ namespace RTC
for (auto& kv : this->ptTable) for (auto& kv : this->ptTable)
{ {
auto& payloadType = kv.first; auto payloadType = kv.first;
auto& existingRtpReceiver = kv.second; auto& existingRtpReceiver = kv.second;
if (existingRtpReceiver == rtpReceiver) if (existingRtpReceiver == rtpReceiver)
...@@ -313,7 +313,7 @@ namespace RTC ...@@ -313,7 +313,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
for (auto& ssrc : previousSsrcs) for (auto ssrc : previousSsrcs)
{ {
this->ssrcTable[ssrc] = rtpReceiver; this->ssrcTable[ssrc] = rtpReceiver;
} }
...@@ -321,7 +321,7 @@ namespace RTC ...@@ -321,7 +321,7 @@ namespace RTC
if (!previousMuxId.empty()) if (!previousMuxId.empty())
this->muxIdTable[previousMuxId] = rtpReceiver; this->muxIdTable[previousMuxId] = rtpReceiver;
for (auto& payloadType : previousPayloadTypes) for (auto payloadType : previousPayloadTypes)
{ {
this->ptTable[payloadType] = rtpReceiver; this->ptTable[payloadType] = rtpReceiver;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "RTC/RtpParameters.h" #include "RTC/RtpParameters.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
#include "Logger.h" #include "Logger.h"
#include <unordered_set>
namespace RTC namespace RTC
{ {
...@@ -238,10 +239,17 @@ namespace RTC ...@@ -238,10 +239,17 @@ namespace RTC
if (this->codecs.size() == 0) if (this->codecs.size() == 0)
MS_THROW_ERROR("empty RtpParameters.codecs"); MS_THROW_ERROR("empty RtpParameters.codecs");
// Validate each codec. std::unordered_set<uint8_t> payloadTypes;
// Validate each codec.
for (auto& codec : this->codecs) for (auto& codec : this->codecs)
{ {
// Payload types must be unique.
if (payloadTypes.find(codec.payloadType) != payloadTypes.end())
MS_THROW_ERROR("duplicated codec.payloadType");
else
payloadTypes.insert(codec.payloadType);
switch (codec.subtype) switch (codec.subtype)
{ {
// A RTX codec must have 'apt' parameter pointing to a non RTX codec. // A RTX codec must have 'apt' parameter pointing to a non RTX codec.
...@@ -258,10 +266,14 @@ namespace RTC ...@@ -258,10 +266,14 @@ namespace RTC
if ((int32_t)codec.payloadType == apt) if ((int32_t)codec.payloadType == apt)
{ {
if (codec.subtype != RtpCodecParameters::Subtype::RTX) if (codec.subtype == RtpCodecParameters::Subtype::RTX)
break; MS_THROW_ERROR("apt in RTX codec points to a RTX codec");
else if (codec.subtype == RtpCodecParameters::Subtype::ULPFEC)
MS_THROW_ERROR("apt in RTX codec points to a ULPFEC codec");
else if (codec.subtype == RtpCodecParameters::Subtype::FLEXFEC)
MS_THROW_ERROR("apt in RTX codec points to a FLEXFEC codec");
else else
MS_THROW_ERROR("apt in RTX codec points to RTX codec"); break;
} }
} }
if (it2 == this->codecs.end()) if (it2 == this->codecs.end())
...@@ -276,12 +288,10 @@ namespace RTC ...@@ -276,12 +288,10 @@ namespace RTC
void RtpParameters::ValidateEncodings() void RtpParameters::ValidateEncodings()
{ {
// If there are no encodings create one with `codecPayloadType` pointing to uint8_t firstMediaPayloadType;
// the first media codec. bool hasFirstMediaPayloadType = false;
if (this->encodings.size() == 0)
{
RtpEncodingParameters encoding;
{
auto it = this->codecs.begin(); auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it) for (; it != this->codecs.end(); ++it)
...@@ -291,49 +301,41 @@ namespace RTC ...@@ -291,49 +301,41 @@ namespace RTC
// Must be a media codec. // Must be a media codec.
if (codec.subtype == RtpCodecParameters::Subtype::MEDIA) if (codec.subtype == RtpCodecParameters::Subtype::MEDIA)
{ {
encoding.codecPayloadType = codec.payloadType; firstMediaPayloadType = codec.payloadType;
encoding.hasCodecPayloadType = true; hasFirstMediaPayloadType = true;
break; break;
} }
} }
if (it == this->codecs.end()) if (it == this->codecs.end())
MS_THROW_ERROR("no media codecs in RtpParameters.codecs"); MS_THROW_ERROR("no media codecs found");
// Insert into the encodings vector.
this->encodings.push_back(encoding);
} }
// If there are one encoding and does not have `codecPayloadType` do the same
// as above.
else if (this->encodings.size() == 1 && !this->encodings[0].hasCodecPayloadType)
{
auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it) // If there are no encodings create one with `codecPayloadType` pointing to
// the first media codec.
if (this->encodings.size() == 0)
{ {
auto codec = *it; RtpEncodingParameters encoding;
auto& encoding = this->encodings[0];
// Must be a media codec. encoding.codecPayloadType = firstMediaPayloadType;
if (codec.subtype == RtpCodecParameters::Subtype::MEDIA)
{
encoding.codecPayloadType = codec.payloadType;
encoding.hasCodecPayloadType = true; encoding.hasCodecPayloadType = true;
break; // Insert into the encodings vector.
} this->encodings.push_back(encoding);
}
if (it == this->codecs.end())
MS_THROW_ERROR("no media codecs in RtpParameters.codecs");
} }
// Otherwise all the encodings must point to a valid media codec. // Otherwise iterate all the encodings, set the first payloadType in all of them
// with codecPayloadType unset, and check that others point to a media codec.
else else
{ {
for (auto& encoding : this->encodings) for (auto& encoding : this->encodings)
{ {
if (!encoding.hasCodecPayloadType) if (!encoding.hasCodecPayloadType)
MS_THROW_ERROR("missing RTpEncodingParameters.codecPayloadType"); {
encoding.codecPayloadType = firstMediaPayloadType;
encoding.hasCodecPayloadType = true;
}
else
{
auto it = this->codecs.begin(); auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it) for (; it != this->codecs.end(); ++it)
...@@ -346,11 +348,12 @@ namespace RTC ...@@ -346,11 +348,12 @@ namespace RTC
if (codec.subtype == RtpCodecParameters::Subtype::MEDIA) if (codec.subtype == RtpCodecParameters::Subtype::MEDIA)
break; break;
else else
MS_THROW_ERROR("invalid RtpEncodingParameters.codecPayloadType"); MS_THROW_ERROR("invalid encoding.codecPayloadType");
} }
} }
if (it == this->codecs.end()) if (it == this->codecs.end())
MS_THROW_ERROR("unknown RtpEncodingParameters.codecPayloadType"); MS_THROW_ERROR("unknown encoding.codecPayloadType");
}
} }
} }
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论