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

Code cleanup

上级 e7f5d409
......@@ -68,6 +68,7 @@ namespace RTC
scale(scale)
{
uint64_t now = DepLibUV::GetTime();
this->Reset(now - windowSize);
}
......
......@@ -282,7 +282,8 @@ namespace RTC
Json::Value toJson();
void ReduceCodecsAndEncodings(RtpCapabilities& capabilities);
void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions);
uint32_t GetClockRateForEncoding(size_t encodingIdx);
uint32_t GetEncodingClockRate(size_t encodingIdx);
uint32_t GetEncodingMediaSsrc(size_t encodingIdx);
private:
void ValidateCodecs();
......
......@@ -19,6 +19,7 @@ namespace RTC
// Set data in the index before the oldest index.
uint32_t offset = this->windowSize - 1;
uint32_t index = this->oldestIndex + offset;
if (index >= this->windowSize)
index -= this->windowSize;
......@@ -46,15 +47,11 @@ namespace RTC
// Should never happen.
if (newOldestTime < this->oldestTime)
{
return;
}
// We are in the same time unit (ms) as the last entry.
if (newOldestTime == this->oldestTime)
{
return;
}
// A whole window size time has elapsed since last entry. Reset the buffer.
if (newOldestTime > this->oldestTime + this->windowSize)
......@@ -66,8 +63,10 @@ namespace RTC
while (this->oldestTime < newOldestTime)
{
const BufferItem& oldestItem = buffer[this->oldestIndex];
this->totalCount -= oldestItem.count;
this->buffer[this->oldestIndex] = BufferItem();
if (++this->oldestIndex >= this->windowSize)
this->oldestIndex = 0;
++this->oldestTime;
......
......@@ -246,7 +246,7 @@ namespace RTC
this->headerExtensions = updatedHeaderExtensions;
}
uint32_t RtpParameters::GetClockRateForEncoding(size_t encodingIdx)
uint32_t RtpParameters::GetEncodingClockRate(size_t encodingIdx)
{
MS_TRACE();
......@@ -278,6 +278,16 @@ namespace RTC
return clockRate;
}
uint32_t RtpParameters::GetEncodingMediaSsrc(size_t encodingIdx)
{
MS_TRACE();
if (this->encodings.size() < encodingIdx + 1)
MS_ABORT("no such a encoding [encodingIdx:%zu]", encodingIdx);
return this->encodings[encodingIdx].ssrc;
}
inline
void RtpParameters::ValidateCodecs()
{
......
......@@ -167,7 +167,7 @@ namespace RTC
// Set the RtpStreamRecv.
// TODO: This assumes a single receiving stream for now.
uint32_t streamClockRate = this->rtpParameters->GetClockRateForEncoding(0);
uint32_t streamClockRate = this->rtpParameters->GetEncodingClockRate(0);
// Create a RtpStreamRecv for receiving a media stream.
this->rtpStream = new RTC::RtpStreamRecv(streamClockRate);
......
......@@ -139,12 +139,16 @@ namespace RTC
MS_ASSERT(rtpParameters, "no RTP parameters given");
auto previousRtpParameters = this->rtpParameters;
auto hadParameters = this->rtpParameters ? true : false;
// Free the previous rtpParameters.
if (previousRtpParameters)
if (hadParameters)
delete this->rtpParameters;
// Delete previous RtpStreamSend (if any).
if (this->rtpStream)
delete this->rtpStream;
// Clone given RTP parameters so we manage our own sender parameters.
this->rtpParameters = new RTC::RtpParameters(rtpParameters);
......@@ -200,20 +204,26 @@ namespace RTC
// Set the RtpStreamSend.
// NOTE: We assume a single stream when sending to remote peers.
uint32_t streamClockRate = this->rtpParameters->GetClockRateForEncoding(0);
uint32_t streamClockRate = this->rtpParameters->GetEncodingClockRate(0);
// Create a RtpStreamSend for sending a single media stream.
switch (this->kind)
{
case RTC::Media::Kind::VIDEO:
case RTC::Media::Kind::DEPTH:
{
// Buffer up to 200 packets.
this->rtpStream = new RTC::RtpStreamSend(streamClockRate, 200);
break;
}
case RTC::Media::Kind::AUDIO:
{
// No buffer for audio streams.
this->rtpStream = new RTC::RtpStreamSend(streamClockRate, 0);
break;
}
default:
;
}
......@@ -224,7 +234,7 @@ namespace RTC
}
// Emit "parameterschange" if these are updated parameters.
if (previousRtpParameters)
if (hadParameters)
{
Json::Value event_data(Json::objectValue);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论