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

Code cleanup

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