Unverified 提交 fe8e84a6 authored 作者: José Luis Millán's avatar José Luis Millán 提交者: GitHub

Worker: const correctness (#1002)

上级 8c2ba441
...@@ -56,7 +56,7 @@ void DepLibSRTP::ClassInit() ...@@ -56,7 +56,7 @@ void DepLibSRTP::ClassInit()
{ {
MS_DEBUG_TAG(info, "libsrtp version: \"%s\"", srtp_get_version_string()); MS_DEBUG_TAG(info, "libsrtp version: \"%s\"", srtp_get_version_string());
srtp_err_status_t err = srtp_init(); const srtp_err_status_t err = srtp_init();
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
MS_THROW_ERROR("srtp_init() failed: %s", DepLibSRTP::GetErrorString(err)); MS_THROW_ERROR("srtp_init() failed: %s", DepLibSRTP::GetErrorString(err));
......
...@@ -38,7 +38,7 @@ void DepLibUV::ClassInit() ...@@ -38,7 +38,7 @@ void DepLibUV::ClassInit()
DepLibUV::loop = new uv_loop_t; DepLibUV::loop = new uv_loop_t;
int err = uv_loop_init(DepLibUV::loop); const int err = uv_loop_init(DepLibUV::loop);
if (err != 0) if (err != 0)
MS_ABORT("libuv loop initialization failed"); MS_ABORT("libuv loop initialization failed");
...@@ -88,7 +88,7 @@ void DepLibUV::RunLoop() ...@@ -88,7 +88,7 @@ void DepLibUV::RunLoop()
// This should never happen. // This should never happen.
MS_ASSERT(DepLibUV::loop != nullptr, "loop unset"); MS_ASSERT(DepLibUV::loop != nullptr, "loop unset");
int ret = uv_run(DepLibUV::loop, UV_RUN_DEFAULT); const int ret = uv_run(DepLibUV::loop, UV_RUN_DEFAULT);
MS_ASSERT(ret == 0, "uv_run() returned %s", uv_err_name(ret)); MS_ASSERT(ret == 0, "uv_run() returned %s", uv_err_name(ret));
} }
...@@ -237,7 +237,7 @@ void DepUsrSCTP::Checker::OnTimer(Timer* /*timer*/) ...@@ -237,7 +237,7 @@ void DepUsrSCTP::Checker::OnTimer(Timer* /*timer*/)
MS_TRACE(); MS_TRACE();
auto nowMs = DepLibUV::GetTimeMs(); auto nowMs = DepLibUV::GetTimeMs();
int elapsedMs = this->lastCalledAtMs ? static_cast<int>(nowMs - this->lastCalledAtMs) : 0; const int elapsedMs = this->lastCalledAtMs ? static_cast<int>(nowMs - this->lastCalledAtMs) : 0;
usrsctp_handle_timers(elapsedMs); usrsctp_handle_timers(elapsedMs);
......
...@@ -63,7 +63,7 @@ namespace RTC ...@@ -63,7 +63,7 @@ namespace RTC
// there is no frame-marking or if there is but keyframe was not detected above. // there is no frame-marking or if there is but keyframe was not detected above.
if (!frameMarking || !payloadDescriptor->isKeyFrame) if (!frameMarking || !payloadDescriptor->isKeyFrame)
{ {
uint8_t nal = *data & 0x1F; const uint8_t nal = *data & 0x1F;
switch (nal) switch (nal)
{ {
...@@ -88,7 +88,7 @@ namespace RTC ...@@ -88,7 +88,7 @@ namespace RTC
while (len >= 3) while (len >= 3)
{ {
auto naluSize = Utils::Byte::Get2Bytes(data, offset); auto naluSize = Utils::Byte::Get2Bytes(data, offset);
uint8_t subnal = *(data + offset + sizeof(naluSize)) & 0x1F; const uint8_t subnal = *(data + offset + sizeof(naluSize)) & 0x1F;
if (subnal == 7) if (subnal == 7)
{ {
...@@ -115,8 +115,8 @@ namespace RTC ...@@ -115,8 +115,8 @@ namespace RTC
case 28: case 28:
case 29: case 29:
{ {
uint8_t subnal = *(data + 1) & 0x1F; const uint8_t subnal = *(data + 1) & 0x1F;
uint8_t startBit = *(data + 1) & 0x80; const uint8_t startBit = *(data + 1) & 0x80;
if (subnal == 7 && startBit == 128) if (subnal == 7 && startBit == 128)
{ {
......
...@@ -58,7 +58,7 @@ namespace RTC ...@@ -58,7 +58,7 @@ namespace RTC
// there is no frame-marking or if there is but keyframe was not detected above. // there is no frame-marking or if there is but keyframe was not detected above.
if (!frameMarking || !payloadDescriptor->isKeyFrame) if (!frameMarking || !payloadDescriptor->isKeyFrame)
{ {
uint8_t nal = *data & 0x1F; const uint8_t nal = *data & 0x1F;
switch (nal) switch (nal)
{ {
...@@ -121,7 +121,7 @@ namespace RTC ...@@ -121,7 +121,7 @@ namespace RTC
case 28: case 28:
case 29: case 29:
{ {
uint8_t startBit = *(data + 1) & 0x80; const uint8_t startBit = *(data + 1) & 0x80;
if (startBit == 128) if (startBit == 128)
{ {
...@@ -145,7 +145,7 @@ namespace RTC ...@@ -145,7 +145,7 @@ namespace RTC
std::unique_ptr<H264_SVC::PayloadDescriptor> payloadDescriptor, std::unique_ptr<H264_SVC::PayloadDescriptor> payloadDescriptor,
bool isStartBit) bool isStartBit)
{ {
uint8_t nal = *data & 0x1F; const uint8_t nal = *data & 0x1F;
switch (nal) switch (nal)
{ {
...@@ -286,7 +286,7 @@ namespace RTC ...@@ -286,7 +286,7 @@ namespace RTC
} }
// clang-format off // clang-format off
bool isOldPacket = false; const bool isOldPacket = false;
// Upgrade current spatial layer if needed. // Upgrade current spatial layer if needed.
if (context->GetTargetSpatialLayer() > context->GetCurrentSpatialLayer()) if (context->GetTargetSpatialLayer() > context->GetCurrentSpatialLayer())
......
...@@ -223,7 +223,7 @@ namespace RTC ...@@ -223,7 +223,7 @@ namespace RTC
} }
// clang-format off // clang-format off
bool isOldPacket = ( const bool isOldPacket = (
this->payloadDescriptor->hasPictureId && this->payloadDescriptor->hasPictureId &&
RTC::SeqManager<uint16_t, 15>::IsSeqLowerThan( RTC::SeqManager<uint16_t, 15>::IsSeqLowerThan(
this->payloadDescriptor->pictureId, this->payloadDescriptor->pictureId,
......
...@@ -75,7 +75,7 @@ namespace RTC ...@@ -75,7 +75,7 @@ namespace RTC
} }
// 32 bits padding. // 32 bits padding.
size_t padding = (-offset) & 3; const size_t padding = (-offset) & 3;
for (size_t i{ 0 }; i < padding; ++i) for (size_t i{ 0 }; i < padding; ++i)
{ {
......
...@@ -25,7 +25,7 @@ namespace RTC ...@@ -25,7 +25,7 @@ namespace RTC
isCorrect = false; isCorrect = false;
} }
size_t paddingBytes = this->header->paddingBits / 8; const size_t paddingBytes = this->header->paddingBits / 8;
if (paddingBytes > FeedbackPsRpsiItem::maxBitStringSize) if (paddingBytes > FeedbackPsRpsiItem::maxBitStringSize)
{ {
...@@ -50,7 +50,7 @@ namespace RTC ...@@ -50,7 +50,7 @@ namespace RTC
this->header = reinterpret_cast<Header*>(this->raw); this->header = reinterpret_cast<Header*>(this->raw);
// 32 bits padding. // 32 bits padding.
size_t padding = (-length) & 3; const size_t padding = (-length) & 3;
this->header->paddingBits = padding * 8; this->header->paddingBits = padding * 8;
this->header->zero = 0; this->header->zero = 0;
......
...@@ -26,7 +26,7 @@ namespace RTC ...@@ -26,7 +26,7 @@ namespace RTC
size_t FeedbackPsSliItem::Serialize(uint8_t* buffer) size_t FeedbackPsSliItem::Serialize(uint8_t* buffer)
{ {
uint32_t compact = (this->first << 19) | (this->number << 6) | this->pictureId; const uint32_t compact = (this->first << 19) | (this->number << 6) | this->pictureId;
auto* header = reinterpret_cast<Header*>(buffer); auto* header = reinterpret_cast<Header*>(buffer);
header->compact = uint32_t{ htonl(compact) }; header->compact = uint32_t{ htonl(compact) };
......
...@@ -34,9 +34,9 @@ namespace RTC ...@@ -34,9 +34,9 @@ namespace RTC
// Copy the content. // Copy the content.
std::memcpy(buffer + 8, this->header->value, GetLength()); std::memcpy(buffer + 8, this->header->value, GetLength());
size_t offset = 8 + GetLength(); const size_t offset = 8 + GetLength();
// 32 bits padding. // 32 bits padding.
size_t padding = (-offset) & 3; const size_t padding = (-offset) & 3;
for (size_t i{ 0 }; i < padding; ++i) for (size_t i{ 0 }; i < padding; ++i)
{ {
......
...@@ -23,10 +23,10 @@ namespace RTC ...@@ -23,10 +23,10 @@ namespace RTC
this->ssrc = Utils::Byte::Get4Bytes(data, 0); this->ssrc = Utils::Byte::Get4Bytes(data, 0);
// Read the 4 bytes block. // Read the 4 bytes block.
uint32_t compact = Utils::Byte::Get4Bytes(data, 4); const uint32_t compact = Utils::Byte::Get4Bytes(data, 4);
// Read each component. // Read each component.
uint8_t exponent = compact >> 26; // 6 bits. const uint8_t exponent = compact >> 26; // 6 bits.
uint64_t mantissa = (compact >> 9) & 0x1ffff; // 17 bits. const uint64_t mantissa = (compact >> 9) & 0x1ffff; // 17 bits.
this->overhead = compact & 0x1ff; // 9 bits. this->overhead = compact & 0x1ff; // 9 bits.
// Get the bitrate out of exponent and mantissa. // Get the bitrate out of exponent and mantissa.
......
...@@ -265,7 +265,7 @@ namespace RTC ...@@ -265,7 +265,7 @@ namespace RTC
} }
// 32 bits padding. // 32 bits padding.
size_t padding = (-offset) & 3; const size_t padding = (-offset) & 3;
for (size_t i{ 0u }; i < padding; ++i) for (size_t i{ 0u }; i < padding; ++i)
{ {
...@@ -318,7 +318,7 @@ namespace RTC ...@@ -318,7 +318,7 @@ namespace RTC
// Deltas are represented as multiples of 250 us. // Deltas are represented as multiples of 250 us.
// NOTE: Read it as int 64 to detect long elapsed times. // NOTE: Read it as int 64 to detect long elapsed times.
int64_t delta64 = (timestamp - this->latestTimestamp) * 4; const int64_t delta64 = (timestamp - this->latestTimestamp) * 4;
// clang-format off // clang-format off
if ( if (
...@@ -414,7 +414,7 @@ namespace RTC ...@@ -414,7 +414,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
uint16_t expected = this->packetStatusCount; const uint16_t expected = this->packetStatusCount;
uint16_t lost{ 0u }; uint16_t lost{ 0u };
if (expected == 0u) if (expected == 0u)
......
...@@ -204,7 +204,7 @@ namespace RTC ...@@ -204,7 +204,7 @@ namespace RTC
this->header = reinterpret_cast<CommonHeader*>(buffer); this->header = reinterpret_cast<CommonHeader*>(buffer);
size_t length = (GetSize() / 4) - 1; const size_t length = (GetSize() / 4) - 1;
// Fill the common header. // Fill the common header.
this->header->version = 2; this->header->version = 2;
......
...@@ -86,7 +86,7 @@ namespace RTC ...@@ -86,7 +86,7 @@ namespace RTC
std::unique_ptr<ReceiverReportPacket> packet(new ReceiverReportPacket(header)); std::unique_ptr<ReceiverReportPacket> packet(new ReceiverReportPacket(header));
uint32_t ssrc = const uint32_t ssrc =
Utils::Byte::Get4Bytes(reinterpret_cast<uint8_t*>(header), Packet::CommonHeaderSize); Utils::Byte::Get4Bytes(reinterpret_cast<uint8_t*>(header), Packet::CommonHeaderSize);
packet->SetSsrc(ssrc); packet->SetSsrc(ssrc);
......
...@@ -119,7 +119,7 @@ namespace RTC ...@@ -119,7 +119,7 @@ namespace RTC
return nullptr; return nullptr;
} }
uint32_t ssrc = Utils::Byte::Get4Bytes(data, 0); const uint32_t ssrc = Utils::Byte::Get4Bytes(data, 0);
std::unique_ptr<SdesChunk> chunk(new SdesChunk(ssrc)); std::unique_ptr<SdesChunk> chunk(new SdesChunk(ssrc));
...@@ -156,7 +156,7 @@ namespace RTC ...@@ -156,7 +156,7 @@ namespace RTC
} }
// 32 bits padding. // 32 bits padding.
size_t padding = (-offset) & 3; const size_t padding = (-offset) & 3;
for (size_t i{ 0 }; i < padding; ++i) for (size_t i{ 0 }; i < padding; ++i)
{ {
......
...@@ -65,7 +65,7 @@ namespace RTC ...@@ -65,7 +65,7 @@ namespace RTC
auto* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data)); auto* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
std::unique_ptr<SenderReportPacket> packet(new SenderReportPacket(header)); std::unique_ptr<SenderReportPacket> packet(new SenderReportPacket(header));
size_t offset = Packet::CommonHeaderSize; const size_t offset = Packet::CommonHeaderSize;
SenderReport* report = SenderReport::Parse(data + offset, len - offset); SenderReport* report = SenderReport::Parse(data + offset, len - offset);
......
...@@ -71,7 +71,7 @@ namespace RTC ...@@ -71,7 +71,7 @@ namespace RTC
std::unique_ptr<ExtendedReportPacket> packet(new ExtendedReportPacket(header)); std::unique_ptr<ExtendedReportPacket> packet(new ExtendedReportPacket(header));
uint32_t ssrc = const uint32_t ssrc =
Utils::Byte::Get4Bytes(reinterpret_cast<uint8_t*>(header), Packet::CommonHeaderSize); Utils::Byte::Get4Bytes(reinterpret_cast<uint8_t*>(header), Packet::CommonHeaderSize);
packet->SetSsrc(ssrc); packet->SetSsrc(ssrc);
......
...@@ -94,7 +94,7 @@ namespace RTC ...@@ -94,7 +94,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
size_t length = static_cast<uint16_t>((SsrcInfo::BodySize * this->ssrcInfos.size() / 4)); const size_t length = static_cast<uint16_t>((SsrcInfo::BodySize * this->ssrcInfos.size() / 4));
// Fill the common header. // Fill the common header.
this->header->blockType = static_cast<uint8_t>(this->type); this->header->blockType = static_cast<uint8_t>(this->type);
......
...@@ -135,7 +135,7 @@ void TcpConnectionHandler::Setup( ...@@ -135,7 +135,7 @@ void TcpConnectionHandler::Setup(
MS_TRACE(); MS_TRACE();
// Set the UV handle. // Set the UV handle.
int err = uv_tcp_init(DepLibUV::GetLoop(), this->uvHandle); const int err = uv_tcp_init(DepLibUV::GetLoop(), this->uvHandle);
if (err != 0) if (err != 0)
{ {
...@@ -205,7 +205,7 @@ void TcpConnectionHandler::Write( ...@@ -205,7 +205,7 @@ void TcpConnectionHandler::Write(
return; return;
} }
size_t totalLen = len1 + len2; const size_t totalLen = len1 + len2;
uv_buf_t buffers[2]; uv_buf_t buffers[2];
int written{ 0 }; int written{ 0 };
int err; int err;
...@@ -246,7 +246,7 @@ void TcpConnectionHandler::Write( ...@@ -246,7 +246,7 @@ void TcpConnectionHandler::Write(
written = 0; written = 0;
} }
size_t pendingLen = totalLen - written; const size_t pendingLen = totalLen - written;
auto* writeData = new UvWriteData(pendingLen); auto* writeData = new UvWriteData(pendingLen);
writeData->req.data = static_cast<void*>(writeData); writeData->req.data = static_cast<void*>(writeData);
...@@ -269,7 +269,7 @@ void TcpConnectionHandler::Write( ...@@ -269,7 +269,7 @@ void TcpConnectionHandler::Write(
writeData->cb = cb; writeData->cb = cb;
uv_buf_t buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen); const uv_buf_t buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen);
err = uv_write( err = uv_write(
&writeData->req, &writeData->req,
......
...@@ -117,7 +117,7 @@ void TcpServerHandler::AcceptTcpConnection(TcpConnectionHandler* connection) ...@@ -117,7 +117,7 @@ void TcpServerHandler::AcceptTcpConnection(TcpConnectionHandler* connection)
} }
// Accept the connection. // Accept the connection.
int err = uv_accept( const int err = uv_accept(
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
reinterpret_cast<uv_stream_t*>(connection->GetUvHandle())); reinterpret_cast<uv_stream_t*>(connection->GetUvHandle()));
......
...@@ -27,7 +27,7 @@ Timer::Timer(Listener* listener) : listener(listener) ...@@ -27,7 +27,7 @@ Timer::Timer(Listener* listener) : listener(listener)
this->uvHandle = new uv_timer_t; this->uvHandle = new uv_timer_t;
this->uvHandle->data = static_cast<void*>(this); this->uvHandle->data = static_cast<void*>(this);
int err = uv_timer_init(DepLibUV::GetLoop(), this->uvHandle); const int err = uv_timer_init(DepLibUV::GetLoop(), this->uvHandle);
if (err != 0) if (err != 0)
{ {
...@@ -71,7 +71,7 @@ void Timer::Start(uint64_t timeout, uint64_t repeat) ...@@ -71,7 +71,7 @@ void Timer::Start(uint64_t timeout, uint64_t repeat)
if (uv_is_active(reinterpret_cast<uv_handle_t*>(this->uvHandle)) != 0) if (uv_is_active(reinterpret_cast<uv_handle_t*>(this->uvHandle)) != 0)
Stop(); Stop();
int err = uv_timer_start(this->uvHandle, static_cast<uv_timer_cb>(onTimer), timeout, repeat); const int err = uv_timer_start(this->uvHandle, static_cast<uv_timer_cb>(onTimer), timeout, repeat);
if (err != 0) if (err != 0)
MS_THROW_ERROR("uv_timer_start() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_timer_start() failed: %s", uv_strerror(err));
...@@ -84,7 +84,7 @@ void Timer::Stop() ...@@ -84,7 +84,7 @@ void Timer::Stop()
if (this->closed) if (this->closed)
MS_THROW_ERROR("closed"); MS_THROW_ERROR("closed");
int err = uv_timer_stop(this->uvHandle); const int err = uv_timer_stop(this->uvHandle);
if (err != 0) if (err != 0)
MS_THROW_ERROR("uv_timer_stop() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_timer_stop() failed: %s", uv_strerror(err));
...@@ -103,7 +103,7 @@ void Timer::Reset() ...@@ -103,7 +103,7 @@ void Timer::Reset()
if (this->repeat == 0u) if (this->repeat == 0u)
return; return;
int err = const int err =
uv_timer_start(this->uvHandle, static_cast<uv_timer_cb>(onTimer), this->repeat, this->repeat); uv_timer_start(this->uvHandle, static_cast<uv_timer_cb>(onTimer), this->repeat, this->repeat);
if (err != 0) if (err != 0)
...@@ -120,7 +120,7 @@ void Timer::Restart() ...@@ -120,7 +120,7 @@ void Timer::Restart()
if (uv_is_active(reinterpret_cast<uv_handle_t*>(this->uvHandle)) != 0) if (uv_is_active(reinterpret_cast<uv_handle_t*>(this->uvHandle)) != 0)
Stop(); Stop();
int err = const int err =
uv_timer_start(this->uvHandle, static_cast<uv_timer_cb>(onTimer), this->timeout, this->repeat); uv_timer_start(this->uvHandle, static_cast<uv_timer_cb>(onTimer), this->timeout, this->repeat);
if (err != 0) if (err != 0)
......
...@@ -101,7 +101,7 @@ void UdpSocketHandler::Close() ...@@ -101,7 +101,7 @@ void UdpSocketHandler::Close()
this->uvHandle->data = nullptr; this->uvHandle->data = nullptr;
// Don't read more. // Don't read more.
int err = uv_udp_recv_stop(this->uvHandle); const int err = uv_udp_recv_stop(this->uvHandle);
if (err != 0) if (err != 0)
MS_ABORT("uv_udp_recv_stop() failed: %s", uv_strerror(err)); MS_ABORT("uv_udp_recv_stop() failed: %s", uv_strerror(err));
...@@ -149,7 +149,7 @@ void UdpSocketHandler::Send( ...@@ -149,7 +149,7 @@ void UdpSocketHandler::Send(
// then build a uv_req_t and use uv_udp_send(). // then build a uv_req_t and use uv_udp_send().
uv_buf_t buffer = uv_buf_init(reinterpret_cast<char*>(const_cast<uint8_t*>(data)), len); uv_buf_t buffer = uv_buf_init(reinterpret_cast<char*>(const_cast<uint8_t*>(data)), len);
int sent = uv_udp_try_send(this->uvHandle, &buffer, 1, addr); const int sent = uv_udp_try_send(this->uvHandle, &buffer, 1, addr);
// Entire datagram was sent. Done. // Entire datagram was sent. Done.
if (sent == static_cast<int>(len)) if (sent == static_cast<int>(len))
......
...@@ -197,7 +197,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) ...@@ -197,7 +197,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len)
written = 0; written = 0;
} }
size_t pendingLen = len - written; const size_t pendingLen = len - written;
auto* writeData = new UvWriteData(pendingLen); auto* writeData = new UvWriteData(pendingLen);
writeData->req.data = static_cast<void*>(writeData); writeData->req.data = static_cast<void*>(writeData);
...@@ -205,7 +205,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) ...@@ -205,7 +205,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len)
buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen); buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen);
int err = uv_write( const int err = uv_write(
&writeData->req, &writeData->req,
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
&buffer, &buffer,
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论