#define MS_CLASS "RTC::RtpEncodingParameters"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/RtpDictionaries.hpp"
#include <exception>
#include <regex>
namespace RTC
{
RtpEncodingParameters::RtpEncodingParameters(const FBS::RtpParameters::RtpEncodingParameters* data)
{
MS_TRACE();
if (auto ssrc = data->ssrc(); ssrc.has_value())
{
this->ssrc = ssrc.value();
}
if (flatbuffers::IsFieldPresent(data, FBS::RtpParameters::RtpEncodingParameters::VT_RID))
{
this->rid = data->rid()->str();
}
if (auto codecPayloadType = data->codecPayloadType(); codecPayloadType.has_value())
{
this->codecPayloadType = codecPayloadType.value();
this->hasCodecPayloadType = true;
}
if (flatbuffers::IsFieldPresent(data, FBS::RtpParameters::RtpEncodingParameters::VT_RTX))
{
this->rtx = RtpRtxParameters(data->rtx());
this->hasRtx = true;
}
if (auto maxBitrate = data->maxBitrate(); maxBitrate.has_value())
{
this->maxBitrate = maxBitrate.value();
}
this->dtx = data->dtx();
if (flatbuffers::IsFieldPresent(data, FBS::RtpParameters::RtpEncodingParameters::VT_SCALABILITYMODE))
{
const std::string scalabilityMode = data->scalabilityMode()->str();
static const std::regex ScalabilityModeRegex(
"^[LS]([1-9]\\d{0,1})T([1-9]\\d{0,1})(_KEY)?.*", std::regex_constants::ECMAScript);
std::smatch match;
std::regex_match(scalabilityMode, match, ScalabilityModeRegex);
if (!match.empty())
{
this->scalabilityMode = scalabilityMode;
try
{
this->spatialLayers = std::stoul(match[1].str());
this->temporalLayers = std::stoul(match[2].str());
this->ksvc = match.size() >= 4 && match[3].str() == "_KEY";
}
catch (std::exception& e)
{
MS_THROW_TYPE_ERROR("invalid scalabilityMode: %s", e.what());
}
}
}
}
flatbuffers::Offset<FBS::RtpParameters::RtpEncodingParameters> RtpEncodingParameters::FillBuffer(
flatbuffers::FlatBufferBuilder& builder) const
{
MS_TRACE();
return FBS::RtpParameters::CreateRtpEncodingParametersDirect(
builder,
this->ssrc != 0u ? flatbuffers::Optional<uint32_t>(this->ssrc) : flatbuffers::nullopt,
!this->rid.empty() ? this->rid.c_str() : nullptr,
this->hasCodecPayloadType ? flatbuffers::Optional<uint8_t>(this->codecPayloadType)
: flatbuffers::nullopt,
this->hasRtx ? this->rtx.FillBuffer(builder) : 0u,
this->dtx,
this->scalabilityMode.c_str());
}
}