提交 1fb92014 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Add uint32_t RtpParameters::GetClockRateForEncoding(uint8_t encodingIdx)

上级 7a924fc9
...@@ -281,6 +281,7 @@ namespace RTC ...@@ -281,6 +281,7 @@ namespace RTC
Json::Value toJson(); Json::Value toJson();
void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions); void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions);
uint32_t GetClockRateForEncoding(uint8_t encodingIdx);
private: private:
void ValidateCodecs(); void ValidateCodecs();
......
...@@ -184,6 +184,38 @@ namespace RTC ...@@ -184,6 +184,38 @@ namespace RTC
this->headerExtensions = updatedHeaderExtensions; this->headerExtensions = updatedHeaderExtensions;
} }
uint32_t RtpParameters::GetClockRateForEncoding(uint8_t encodingIdx)
{
MS_TRACE();
if (this->encodings.size() < encodingIdx + 1)
MS_ABORT("no such a encoding [encodingIdx:%" PRIu8 "]", encodingIdx);
uint8_t payloadType = this->encodings[encodingIdx].codecPayloadType;
uint32_t clockRate = 0;
auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it)
{
auto& codec = *it;
if (codec.payloadType == payloadType)
{
clockRate = codec.clockRate;
break;
}
}
// This should never happen.
if (it == this->codecs.end())
{
MS_ABORT("no valid codec payload type for the requested encoding [encodingIdx:%" PRIu8 "]", encodingIdx);
}
return clockRate;
}
inline inline
void RtpParameters::ValidateCodecs() void RtpParameters::ValidateCodecs()
{ {
......
...@@ -161,30 +161,8 @@ namespace RTC ...@@ -161,30 +161,8 @@ namespace RTC
this->listener->onRtpReceiverParametersDone(this); this->listener->onRtpReceiverParametersDone(this);
// Set the RtpStreamRecv. // Set the RtpStreamRecv.
// TODO: This assumes a single stream for now. // TODO: This assumes a single receiving stream for now.
// TODO: We need a much better way to get the clock rate. uint32_t streamClockRate = this->rtpParameters->GetClockRateForEncoding(0);
uint8_t streamPayloadType = this->rtpParameters->encodings[0].codecPayloadType;
uint32_t streamClockRate;
auto it = this->rtpParameters->codecs.begin();
for (; it != this->rtpParameters->codecs.end(); ++it)
{
auto& codec = *it;
if (codec.payloadType == streamPayloadType)
{
streamClockRate = codec.clockRate;
break;
}
}
// This should never happen.
if (it == this->rtpParameters->codecs.end())
{
MS_ABORT("no valid codec payload type found for the first encoding");
}
// Create a RtpStreamRecv for receiving a media stream. // Create a RtpStreamRecv for receiving a media stream.
this->rtpStream = new RTC::RtpStreamRecv(streamClockRate); this->rtpStream = new RTC::RtpStreamRecv(streamClockRate);
......
...@@ -193,30 +193,8 @@ namespace RTC ...@@ -193,30 +193,8 @@ namespace RTC
this->available = true; this->available = true;
// Set the RtpStreamSend. // Set the RtpStreamSend.
// TODO: This assumes a single stream for now. // NOTE: We assume a single stream when sending to remote peers.
// TODO: We need a much better way to get the clock rate. uint32_t streamClockRate = this->rtpParameters->GetClockRateForEncoding(0);
uint8_t streamPayloadType = this->rtpParameters->encodings[0].codecPayloadType;
uint32_t streamClockRate;
auto it = this->rtpParameters->codecs.begin();
for (; it != this->rtpParameters->codecs.end(); ++it)
{
auto& codec = *it;
if (codec.payloadType == streamPayloadType)
{
streamClockRate = codec.clockRate;
break;
}
}
// This should never happen.
if (it == this->rtpParameters->codecs.end())
{
MS_ABORT("no valid codec payload type found for the first encoding");
}
// Create a RtpStreamSend for sending a single media stream. // Create a RtpStreamSend for sending a single media stream.
switch (this->kind) switch (this->kind)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论