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

C++: add { } in all remaining if() conditions (test and include folders)

上级 0efec5f2
...@@ -355,7 +355,9 @@ public: ...@@ -355,7 +355,9 @@ public:
bufferDataLen += loggerWritten; \ bufferDataLen += loggerWritten; \
} \ } \
if (bufferDataLen != 0) \ if (bufferDataLen != 0) \
{ \
Logger::channel->SendLog(Logger::buffer, static_cast<uint32_t>(bufferDataLen)); \ Logger::channel->SendLog(Logger::buffer, static_cast<uint32_t>(bufferDataLen)); \
} \
} \ } \
while (false) while (false)
......
...@@ -293,7 +293,9 @@ namespace RTC ...@@ -293,7 +293,9 @@ namespace RTC
size_t GetSize() const override size_t GetSize() const override
{ {
if (this->size) if (this->size)
{
return this->size; return this->size;
}
// Fixed packet size. // Fixed packet size.
size_t size = FeedbackRtpPacket::GetSize(); size_t size = FeedbackRtpPacket::GetSize();
......
...@@ -71,11 +71,15 @@ namespace RTC ...@@ -71,11 +71,15 @@ namespace RTC
// Possitive value. // Possitive value.
if (((value >> 23) & 1) == 0) if (((value >> 23) & 1) == 0)
{
return value; return value;
}
// Negative value. // Negative value.
if (value != 0x0800000) if (value != 0x0800000)
{
value &= ~(1 << 23); value &= ~(1 << 23);
}
return -value; return -value;
} }
...@@ -170,7 +174,9 @@ namespace RTC ...@@ -170,7 +174,9 @@ namespace RTC
auto it = std::find(this->reports.begin(), this->reports.end(), report); auto it = std::find(this->reports.begin(), this->reports.end(), report);
if (it != this->reports.end()) if (it != this->reports.end())
{
this->reports.erase(it); this->reports.erase(it);
}
} }
Iterator Begin() Iterator Begin()
{ {
......
...@@ -188,7 +188,9 @@ namespace RTC ...@@ -188,7 +188,9 @@ namespace RTC
auto it = std::find(this->chunks.begin(), this->chunks.end(), chunk); auto it = std::find(this->chunks.begin(), this->chunks.end(), chunk);
if (it != this->chunks.end()) if (it != this->chunks.end())
{
this->chunks.erase(it); this->chunks.erase(it);
}
} }
Iterator Begin() Iterator Begin()
{ {
......
...@@ -133,7 +133,9 @@ namespace RTC ...@@ -133,7 +133,9 @@ namespace RTC
auto it = std::find(this->reports.begin(), this->reports.end(), report); auto it = std::find(this->reports.begin(), this->reports.end(), report);
if (it != this->reports.end()) if (it != this->reports.end())
{
this->reports.erase(it); this->reports.erase(it);
}
} }
Iterator Begin() Iterator Begin()
{ {
......
...@@ -107,7 +107,9 @@ namespace RTC ...@@ -107,7 +107,9 @@ namespace RTC
auto it = std::find(this->reports.begin(), this->reports.end(), report); auto it = std::find(this->reports.begin(), this->reports.end(), report);
if (it != this->reports.end()) if (it != this->reports.end())
{
this->reports.erase(it); this->reports.erase(it);
}
} }
uint32_t GetSsrc() const uint32_t GetSsrc() const
{ {
......
...@@ -224,7 +224,9 @@ namespace RTC ...@@ -224,7 +224,9 @@ namespace RTC
uint16_t GetHeaderExtensionId() const uint16_t GetHeaderExtensionId() const
{ {
if (!this->headerExtension) if (!this->headerExtension)
{
return 0u; return 0u;
}
return uint16_t{ ntohs(this->headerExtension->id) }; return uint16_t{ ntohs(this->headerExtension->id) };
} }
...@@ -232,7 +234,9 @@ namespace RTC ...@@ -232,7 +234,9 @@ namespace RTC
size_t GetHeaderExtensionLength() const size_t GetHeaderExtensionLength() const
{ {
if (!this->headerExtension) if (!this->headerExtension)
{
return 0u; return 0u;
}
return static_cast<size_t>(ntohs(this->headerExtension->length) * 4); return static_cast<size_t>(ntohs(this->headerExtension->length) * 4);
} }
...@@ -240,7 +244,9 @@ namespace RTC ...@@ -240,7 +244,9 @@ namespace RTC
uint8_t* GetHeaderExtensionValue() const uint8_t* GetHeaderExtensionValue() const
{ {
if (!this->headerExtension) if (!this->headerExtension)
{
return nullptr; return nullptr;
}
return this->headerExtension->value; return this->headerExtension->value;
} }
...@@ -307,7 +313,9 @@ namespace RTC ...@@ -307,7 +313,9 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen); uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen);
if (!extenValue || extenLen == 0u) if (!extenValue || extenLen == 0u)
{
return false; return false;
}
mid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen)); mid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen));
...@@ -347,7 +355,9 @@ namespace RTC ...@@ -347,7 +355,9 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen); uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen);
if (!extenValue || extenLen != 3u) if (!extenValue || extenLen != 3u)
{
return false; return false;
}
absSendtime = Utils::Byte::Get3Bytes(extenValue, 0); absSendtime = Utils::Byte::Get3Bytes(extenValue, 0);
...@@ -360,7 +370,9 @@ namespace RTC ...@@ -360,7 +370,9 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen); uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen);
if (!extenValue || extenLen != 3u) if (!extenValue || extenLen != 3u)
{
return false; return false;
}
auto absSendTime = Utils::Time::TimeMsToAbsSendTime(ms); auto absSendTime = Utils::Time::TimeMsToAbsSendTime(ms);
...@@ -375,7 +387,9 @@ namespace RTC ...@@ -375,7 +387,9 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen); uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen);
if (!extenValue || extenLen != 2u) if (!extenValue || extenLen != 2u)
{
return false; return false;
}
wideSeqNumber = Utils::Byte::Get2Bytes(extenValue, 0); wideSeqNumber = Utils::Byte::Get2Bytes(extenValue, 0);
...@@ -388,7 +402,9 @@ namespace RTC ...@@ -388,7 +402,9 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen); uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen);
if (!extenValue || extenLen != 2u) if (!extenValue || extenLen != 2u)
{
return false; return false;
}
Utils::Byte::Set2Bytes(extenValue, 0, wideSeqNumber); Utils::Byte::Set2Bytes(extenValue, 0, wideSeqNumber);
...@@ -402,10 +418,14 @@ namespace RTC ...@@ -402,10 +418,14 @@ namespace RTC
// NOTE: Remove this once framemarking draft becomes RFC. // NOTE: Remove this once framemarking draft becomes RFC.
if (!extenValue) if (!extenValue)
{
extenValue = GetExtension(this->frameMarking07ExtensionId, extenLen); extenValue = GetExtension(this->frameMarking07ExtensionId, extenLen);
}
if (!extenValue || extenLen > 3u) if (!extenValue || extenLen > 3u)
{
return false; return false;
}
*frameMarking = reinterpret_cast<RtpPacket::FrameMarking*>(extenValue); *frameMarking = reinterpret_cast<RtpPacket::FrameMarking*>(extenValue);
length = extenLen; length = extenLen;
...@@ -419,7 +439,9 @@ namespace RTC ...@@ -419,7 +439,9 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->ssrcAudioLevelExtensionId, extenLen); uint8_t* extenValue = GetExtension(this->ssrcAudioLevelExtensionId, extenLen);
if (!extenValue || extenLen != 1u) if (!extenValue || extenLen != 1u)
{
return false; return false;
}
volume = Utils::Byte::Get1Byte(extenValue, 0); volume = Utils::Byte::Get1Byte(extenValue, 0);
voice = (volume & (1 << 7)) ? true : false; voice = (volume & (1 << 7)) ? true : false;
...@@ -434,7 +456,9 @@ namespace RTC ...@@ -434,7 +456,9 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->videoOrientationExtensionId, extenLen); uint8_t* extenValue = GetExtension(this->videoOrientationExtensionId, extenLen);
if (!extenValue || extenLen != 1u) if (!extenValue || extenLen != 1u)
{
return false; return false;
}
uint8_t cvoByte = Utils::Byte::Get1Byte(extenValue, 0); uint8_t cvoByte = Utils::Byte::Get1Byte(extenValue, 0);
uint8_t cameraValue = ((cvoByte & 0b00001000) >> 3); uint8_t cameraValue = ((cvoByte & 0b00001000) >> 3);
...@@ -472,7 +496,9 @@ namespace RTC ...@@ -472,7 +496,9 @@ namespace RTC
else if (HasOneByteExtensions()) else if (HasOneByteExtensions())
{ {
if (id > 14) if (id > 14)
{
return false; return false;
}
// `-1` because we have 14 elements total 0..13 and `id` is in the range 1..14. // `-1` because we have 14 elements total 0..13 and `id` is in the range 1..14.
return this->oneByteExtensions[id - 1] != nullptr; return this->oneByteExtensions[id - 1] != nullptr;
...@@ -482,13 +508,17 @@ namespace RTC ...@@ -482,13 +508,17 @@ namespace RTC
auto it = this->mapTwoBytesExtensions.find(id); auto it = this->mapTwoBytesExtensions.find(id);
if (it == this->mapTwoBytesExtensions.end()) if (it == this->mapTwoBytesExtensions.end())
{
return false; return false;
}
auto* extension = it->second; auto* extension = it->second;
// In Two-Byte extensions value length may be zero. If so, return false. // In Two-Byte extensions value length may be zero. If so, return false.
if (extension->len == 0u) if (extension->len == 0u)
{
return false; return false;
}
return true; return true;
} }
...@@ -509,13 +539,17 @@ namespace RTC ...@@ -509,13 +539,17 @@ namespace RTC
else if (HasOneByteExtensions()) else if (HasOneByteExtensions())
{ {
if (id > 14) if (id > 14)
{
return nullptr; return nullptr;
}
// `-1` because we have 14 elements total 0..13 and `id` is in the range 1..14. // `-1` because we have 14 elements total 0..13 and `id` is in the range 1..14.
auto* extension = this->oneByteExtensions[id - 1]; auto* extension = this->oneByteExtensions[id - 1];
if (!extension) if (!extension)
{
return nullptr; return nullptr;
}
// In One-Byte extensions value length 0 means 1. // In One-Byte extensions value length 0 means 1.
len = extension->len + 1; len = extension->len + 1;
...@@ -527,7 +561,9 @@ namespace RTC ...@@ -527,7 +561,9 @@ namespace RTC
auto it = this->mapTwoBytesExtensions.find(id); auto it = this->mapTwoBytesExtensions.find(id);
if (it == this->mapTwoBytesExtensions.end()) if (it == this->mapTwoBytesExtensions.end())
{
return nullptr; return nullptr;
}
auto* extension = it->second; auto* extension = it->second;
...@@ -535,7 +571,9 @@ namespace RTC ...@@ -535,7 +571,9 @@ namespace RTC
// In Two-Byte extensions value length may be zero. If so, return nullptr. // In Two-Byte extensions value length may be zero. If so, return nullptr.
if (extension->len == 0u) if (extension->len == 0u)
{
return nullptr; return nullptr;
}
return extension->value; return extension->value;
} }
...@@ -567,7 +605,9 @@ namespace RTC ...@@ -567,7 +605,9 @@ namespace RTC
uint8_t GetSpatialLayer() const uint8_t GetSpatialLayer() const
{ {
if (!this->payloadDescriptorHandler) if (!this->payloadDescriptorHandler)
{
return 0u; return 0u;
}
return this->payloadDescriptorHandler->GetSpatialLayer(); return this->payloadDescriptorHandler->GetSpatialLayer();
} }
...@@ -575,7 +615,9 @@ namespace RTC ...@@ -575,7 +615,9 @@ namespace RTC
uint8_t GetTemporalLayer() const uint8_t GetTemporalLayer() const
{ {
if (!this->payloadDescriptorHandler) if (!this->payloadDescriptorHandler)
{
return 0u; return 0u;
}
return this->payloadDescriptorHandler->GetTemporalLayer(); return this->payloadDescriptorHandler->GetTemporalLayer();
} }
...@@ -583,7 +625,9 @@ namespace RTC ...@@ -583,7 +625,9 @@ namespace RTC
bool IsKeyFrame() const bool IsKeyFrame() const
{ {
if (!this->payloadDescriptorHandler) if (!this->payloadDescriptorHandler)
{
return false; return false;
}
return this->payloadDescriptorHandler->IsKeyFrame(); return this->payloadDescriptorHandler->IsKeyFrame();
} }
......
...@@ -45,24 +45,34 @@ namespace RTC ...@@ -45,24 +45,34 @@ namespace RTC
protocol(tuple->protocol) protocol(tuple->protocol)
{ {
if (protocol == TransportTuple::Protocol::UDP) if (protocol == TransportTuple::Protocol::UDP)
{
StoreUdpRemoteAddress(); StoreUdpRemoteAddress();
}
} }
public: public:
void Close() void Close()
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
{
this->udpSocket->Close(); this->udpSocket->Close();
}
else else
{
this->tcpConnection->Close(); this->tcpConnection->Close();
}
} }
bool IsClosed() bool IsClosed()
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
{
return this->udpSocket->IsClosed(); return this->udpSocket->IsClosed();
}
else else
{
return this->tcpConnection->IsClosed(); return this->tcpConnection->IsClosed();
}
} }
flatbuffers::Offset<FBS::Transport::Tuple> FillBuffer(flatbuffers::FlatBufferBuilder& builder) const; flatbuffers::Offset<FBS::Transport::Tuple> FillBuffer(flatbuffers::FlatBufferBuilder& builder) const;
...@@ -90,9 +100,13 @@ namespace RTC ...@@ -90,9 +100,13 @@ namespace RTC
void Send(const uint8_t* data, size_t len, RTC::TransportTuple::onSendCallback* cb = nullptr) void Send(const uint8_t* data, size_t len, RTC::TransportTuple::onSendCallback* cb = nullptr)
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
{
this->udpSocket->Send(data, len, this->udpRemoteAddr, cb); this->udpSocket->Send(data, len, this->udpRemoteAddr, cb);
}
else else
{
this->tcpConnection->Send(data, len, cb); this->tcpConnection->Send(data, len, cb);
}
} }
Protocol GetProtocol() const Protocol GetProtocol() const
...@@ -103,33 +117,49 @@ namespace RTC ...@@ -103,33 +117,49 @@ namespace RTC
const struct sockaddr* GetLocalAddress() const const struct sockaddr* GetLocalAddress() const
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
{
return this->udpSocket->GetLocalAddress(); return this->udpSocket->GetLocalAddress();
}
else else
{
return this->tcpConnection->GetLocalAddress(); return this->tcpConnection->GetLocalAddress();
}
} }
const struct sockaddr* GetRemoteAddress() const const struct sockaddr* GetRemoteAddress() const
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
{
return (const struct sockaddr*)this->udpRemoteAddr; return (const struct sockaddr*)this->udpRemoteAddr;
}
else else
{
return this->tcpConnection->GetPeerAddress(); return this->tcpConnection->GetPeerAddress();
}
} }
size_t GetRecvBytes() const size_t GetRecvBytes() const
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
{
return this->udpSocket->GetRecvBytes(); return this->udpSocket->GetRecvBytes();
}
else else
{
return this->tcpConnection->GetRecvBytes(); return this->tcpConnection->GetRecvBytes();
}
} }
size_t GetSentBytes() const size_t GetSentBytes() const
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
{
return this->udpSocket->GetSentBytes(); return this->udpSocket->GetSentBytes();
}
else else
{
return this->tcpConnection->GetSentBytes(); return this->tcpConnection->GetSentBytes();
}
} }
private: private:
......
...@@ -18,7 +18,9 @@ namespace helpers ...@@ -18,7 +18,9 @@ namespace helpers
std::ifstream in(filePath, std::ios::ate | std::ios::binary); std::ifstream in(filePath, std::ios::ate | std::ios::binary);
if (!in) if (!in)
{
return false; return false;
}
*len = static_cast<size_t>(in.tellg()) - 1; *len = static_cast<size_t>(in.tellg()) - 1;
in.seekg(0, std::ios::beg); in.seekg(0, std::ios::beg);
...@@ -31,9 +33,12 @@ namespace helpers ...@@ -31,9 +33,12 @@ namespace helpers
inline bool addToBuffer(uint8_t* buf, int* size, uint8_t* data, size_t len) inline bool addToBuffer(uint8_t* buf, int* size, uint8_t* data, size_t len)
{ {
if (*size + len > BUFFER_SIZE) if (*size + len > BUFFER_SIZE)
{
return false; return false;
}
int i = 0; int i = 0;
if (len == 1) if (len == 1)
{ {
buf[*size] = *data; buf[*size] = *data;
...@@ -59,12 +64,15 @@ namespace helpers ...@@ -59,12 +64,15 @@ namespace helpers
std::ifstream in(filePath, std::ios::ate | std::ios::binary); std::ifstream in(filePath, std::ios::ate | std::ios::binary);
if (!in) if (!in)
{
return false; return false;
}
in.seekg(pos, std::ios::beg); in.seekg(pos, std::ios::beg);
in.read(reinterpret_cast<char*>(payload), bytes); in.read(reinterpret_cast<char*>(payload), bytes);
in.close(); in.close();
return true; return true;
} }
...@@ -93,52 +101,78 @@ namespace helpers ...@@ -93,52 +101,78 @@ namespace helpers
// write the RTP header // write the RTP header
if (!addToBuffer(buf, &packet_size, buffer, 16)) if (!addToBuffer(buf, &packet_size, buffer, 16))
{
return false; return false;
}
// write ID and length of frame marking extension // write ID and length of frame marking extension
// if first layer then length should be 0, else 1 // if first layer then length should be 0, else 1
oneByte = oneByte | 1 << 4; oneByte = oneByte | 1 << 4;
if (sid != -1) if (sid != -1)
{ {
oneByte = oneByte | 0x01; oneByte = oneByte | 0x01;
} }
if (!addToBuffer(buf, &packet_size, &oneByte, 1)) if (!addToBuffer(buf, &packet_size, &oneByte, 1))
{
return false; return false;
}
// write SEIDB TID bits // write SEIDB TID bits
oneByte = 0; oneByte = 0;
if (firstSliceId == 1) if (firstSliceId == 1)
{
oneByte = oneByte | 1 << 7; oneByte = oneByte | 1 << 7;
}
if (lastSliceId == 1) if (lastSliceId == 1)
{
oneByte = oneByte | 1 << 6; oneByte = oneByte | 1 << 6;
}
if (isIdr == 1) if (isIdr == 1)
{
oneByte = oneByte | 1 << 5; oneByte = oneByte | 1 << 5;
}
if (tid != -1) if (tid != -1)
{
oneByte = oneByte | tid; oneByte = oneByte | tid;
}
if (!addToBuffer(buf, &packet_size, &oneByte, 1)) if (!addToBuffer(buf, &packet_size, &oneByte, 1))
{
return false; return false;
}
// write DID QID bits // write DID QID bits
oneByte = 0; oneByte = 0;
if (sid != -1) if (sid != -1)
{
oneByte = oneByte | sid << 6; oneByte = oneByte | sid << 6;
}
if (!addToBuffer(buf, &packet_size, &oneByte, 1)) if (!addToBuffer(buf, &packet_size, &oneByte, 1))
{
return false; return false;
}
// write TL0PICIDX // write TL0PICIDX
oneByte = 0; oneByte = 0;
if (!addToBuffer(buf, &packet_size, &oneByte, 1)) if (!addToBuffer(buf, &packet_size, &oneByte, 1))
{
return false; return false;
}
// write payload // write payload
if (!addToBuffer(buf, &packet_size, payload, nalLength)) if (!addToBuffer(buf, &packet_size, payload, nalLength))
{
return false; return false;
}
*len = packet_size; *len = packet_size;
......
...@@ -228,7 +228,9 @@ Codecs::VP8::PayloadDescriptor* CreatePacket( ...@@ -228,7 +228,9 @@ Codecs::VP8::PayloadDescriptor* CreatePacket(
buffer[5] = tlIndex << 6; buffer[5] = tlIndex << 6;
if (layerSync) if (layerSync)
{
buffer[5] |= 0x20; // y bit buffer[5] |= 0x20; // y bit
}
auto* payloadDescriptor = Codecs::VP8::Parse(buffer, bufferLen); auto* payloadDescriptor = Codecs::VP8::Parse(buffer, bufferLen);
......
...@@ -20,12 +20,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -20,12 +20,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
std::string rid; std::string rid;
if (!helpers::readBinaryFile("data/packet1.raw", buffer, &len)) if (!helpers::readBinaryFile("data/packet1.raw", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -55,12 +59,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -55,12 +59,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
size_t len; size_t len;
if (!helpers::readBinaryFile("data/packet2.raw", buffer, &len)) if (!helpers::readBinaryFile("data/packet2.raw", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == false); REQUIRE(packet->HasHeaderExtension() == false);
...@@ -86,12 +94,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -86,12 +94,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
uint32_t absSendTime; uint32_t absSendTime;
if (!helpers::readBinaryFile("data/packet3.raw", buffer, &len)) if (!helpers::readBinaryFile("data/packet3.raw", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -181,7 +193,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -181,7 +193,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer));
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == false); REQUIRE(packet->HasHeaderExtension() == false);
...@@ -213,7 +227,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -213,7 +227,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer));
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -258,7 +274,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -258,7 +274,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer));
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -325,7 +343,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -325,7 +343,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer));
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -399,7 +419,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -399,7 +419,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->GetPayloadType() == 1); REQUIRE(packet->GetPayloadType() == 1);
...@@ -511,7 +533,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -511,7 +533,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
uint8_t* extenValue; uint8_t* extenValue;
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->GetSize() == 28); REQUIRE(packet->GetSize() == 28);
REQUIRE(packet->HasHeaderExtension() == false); REQUIRE(packet->HasHeaderExtension() == false);
...@@ -674,7 +698,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -674,7 +698,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
uint8_t* extenValue; uint8_t* extenValue;
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->GetSize() == 28); REQUIRE(packet->GetSize() == 28);
REQUIRE(packet->HasHeaderExtension() == false); REQUIRE(packet->HasHeaderExtension() == false);
...@@ -810,7 +836,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -810,7 +836,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer));
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
......
...@@ -22,12 +22,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") ...@@ -22,12 +22,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
uint8_t* extenValue; uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I0-7.bin", buffer, &len)) if (!helpers::readBinaryFile("data/H264_SVC/I0-7.bin", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -82,12 +86,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") ...@@ -82,12 +86,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
uint8_t* extenValue; uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I0-8.bin", buffer, &len)) if (!helpers::readBinaryFile("data/H264_SVC/I0-8.bin", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -142,12 +150,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") ...@@ -142,12 +150,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
uint8_t* extenValue; uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I0-5.bin", buffer, &len)) if (!helpers::readBinaryFile("data/H264_SVC/I0-5.bin", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -201,12 +213,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") ...@@ -201,12 +213,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
uint8_t* extenValue; uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I1-15.bin", buffer, &len)) if (!helpers::readBinaryFile("data/H264_SVC/I1-15.bin", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -261,12 +277,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") ...@@ -261,12 +277,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
uint8_t* extenValue; uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I0-14.bin", buffer, &len)) if (!helpers::readBinaryFile("data/H264_SVC/I0-14.bin", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -321,12 +341,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") ...@@ -321,12 +341,16 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
uint8_t* extenValue; uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/2SL-I14.bin", buffer, &len)) if (!helpers::readBinaryFile("data/H264_SVC/2SL-I14.bin", buffer, &len))
{
FAIL("cannot open file"); FAIL("cannot open file");
}
RtpPacket* packet = RtpPacket::Parse(buffer, len); RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
REQUIRE(packet->HasMarker() == false); REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true); REQUIRE(packet->HasHeaderExtension() == true);
...@@ -391,10 +415,12 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") ...@@ -391,10 +415,12 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
std::fstream nf; std::fstream nf;
nf.open("data/H264_SVC/naluInfo/naluInfo.csv", std::ios::in); nf.open("data/H264_SVC/naluInfo/naluInfo.csv", std::ios::in);
if (nf.is_open()) if (nf.is_open())
{ {
std::string line, word; std::string line, word;
getline(nf, line); // omit the header in the CSV getline(nf, line); // omit the header in the CSV
while (getline(nf, line)) while (getline(nf, line))
{ {
std::stringstream s(line); std::stringstream s(line);
...@@ -413,19 +439,26 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") ...@@ -413,19 +439,26 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
if (!helpers::readPayloadData( if (!helpers::readPayloadData(
"data/H264_SVC/naluInfo/naluInfo.264", pos + 4, bytes - 4, buffer)) "data/H264_SVC/naluInfo/naluInfo.264", pos + 4, bytes - 4, buffer))
{
FAIL("Failed to read payload data!\n"); FAIL("Failed to read payload data!\n");
}
// TODO: One additional byte is written as last value is omitted in the // TODO: One additional byte is written as last value is omitted in the
// test bench // test bench
std::string strFile1 = "rtp-" + std::to_string(rows) + ".bin"; std::string strFile1 = "rtp-" + std::to_string(rows) + ".bin";
if (!helpers::writeRtpPacket( if (!helpers::writeRtpPacket(
strFile1.c_str(), type, bytes - 4, sid, tid, isIdr, start, end, buffer, buffer2, &len)) strFile1.c_str(), type, bytes - 4, sid, tid, isIdr, start, end, buffer, buffer2, &len))
{
FAIL("Failed to write RTP packet!\n"); FAIL("Failed to write RTP packet!\n");
}
RtpPacket* packet = RtpPacket::Parse(buffer2, len); RtpPacket* packet = RtpPacket::Parse(buffer2, len);
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
packet->SetFrameMarkingExtensionId(1); packet->SetFrameMarkingExtensionId(1);
......
...@@ -86,7 +86,9 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") ...@@ -86,7 +86,9 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]")
for (size_t i{ 1 }; i < MaxRequestedPackets; ++i) for (size_t i{ 1 }; i < MaxRequestedPackets; ++i)
{ {
if ((bitmask & 1) != 0) if ((bitmask & 1) != 0)
{
this->nackedSeqNumbers.push_back(firstSeq + i); this->nackedSeqNumbers.push_back(firstSeq + i);
}
bitmask >>= 1; bitmask >>= 1;
} }
...@@ -129,7 +131,9 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") ...@@ -129,7 +131,9 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]")
RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer));
if (!packet) if (!packet)
{
FAIL("not a RTP packet"); FAIL("not a RTP packet");
}
RtpStream::Params params; RtpStream::Params params;
......
...@@ -45,6 +45,7 @@ void validate(SeqManager<T, N>& seqManager, std::vector<TestSeqManagerInput<T>>& ...@@ -45,6 +45,7 @@ void validate(SeqManager<T, N>& seqManager, std::vector<TestSeqManagerInput<T>>&
// Covert to string because otherwise Catch will print uint8_t as char. // Covert to string because otherwise Catch will print uint8_t as char.
REQUIRE(std::to_string(output) == std::to_string(element.output)); REQUIRE(std::to_string(output) == std::to_string(element.output));
if (element.maxInput != -1) if (element.maxInput != -1)
{ {
REQUIRE(std::to_string(element.maxInput) == std::to_string(seqManager.GetMaxInput())); REQUIRE(std::to_string(element.maxInput) == std::to_string(seqManager.GetMaxInput()));
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论