Unverified 提交 f60845ba authored 作者: Javier Cerviño's avatar Javier Cerviño 提交者: GitHub

Fix wrong PictureID rolling over in VP9 and VP8 (#984)

上级 daca24ca
...@@ -71,7 +71,7 @@ namespace RTC ...@@ -71,7 +71,7 @@ namespace RTC
} }
public: public:
RTC::SeqManager<uint16_t> pictureIdManager; RTC::SeqManager<uint16_t, 15> pictureIdManager;
bool syncRequired{ false }; bool syncRequired{ false };
}; };
......
...@@ -96,7 +96,7 @@ namespace RTC ...@@ -96,7 +96,7 @@ namespace RTC
} }
public: public:
RTC::SeqManager<uint16_t> pictureIdManager; RTC::SeqManager<uint16_t, 15> pictureIdManager;
RTC::SeqManager<uint8_t> tl0PictureIndexManager; RTC::SeqManager<uint8_t> tl0PictureIndexManager;
bool syncRequired{ false }; bool syncRequired{ false };
}; };
......
...@@ -113,7 +113,7 @@ namespace RTC ...@@ -113,7 +113,7 @@ namespace RTC
} }
public: public:
RTC::SeqManager<uint16_t> pictureIdManager; RTC::SeqManager<uint16_t, 15> pictureIdManager;
bool syncRequired{ false }; bool syncRequired{ false };
}; };
......
...@@ -7,11 +7,13 @@ ...@@ -7,11 +7,13 @@
namespace RTC namespace RTC
{ {
template<typename T> // T is the base type (uint16_t, uint32_t, ...).
// N is the max number of bits used in T.
template<typename T, uint8_t N = 0>
class SeqManager class SeqManager
{ {
public: public:
static constexpr T MaxValue = std::numeric_limits<T>::max(); static constexpr T MaxValue = (N == 0) ? std::numeric_limits<T>::max() : ((1 << N) - 1);
public: public:
struct SeqLowerThan struct SeqLowerThan
...@@ -27,6 +29,7 @@ namespace RTC ...@@ -27,6 +29,7 @@ namespace RTC
private: private:
static const SeqLowerThan isSeqLowerThan; static const SeqLowerThan isSeqLowerThan;
static const SeqHigherThan isSeqHigherThan; static const SeqHigherThan isSeqHigherThan;
static T Delta(const T lhs, const T rhs);
public: public:
static bool IsSeqLowerThan(const T lhs, const T rhs); static bool IsSeqLowerThan(const T lhs, const T rhs);
......
...@@ -295,6 +295,7 @@ mediasoup_worker_test = executable( ...@@ -295,6 +295,7 @@ mediasoup_worker_test = executable(
'test/src/RTC/TestTrendCalculator.cpp', 'test/src/RTC/TestTrendCalculator.cpp',
'test/src/RTC/TestRtpEncodingParameters.cpp', 'test/src/RTC/TestRtpEncodingParameters.cpp',
'test/src/RTC/Codecs/TestVP8.cpp', 'test/src/RTC/Codecs/TestVP8.cpp',
'test/src/RTC/Codecs/TestVP9.cpp',
'test/src/RTC/Codecs/TestH264.cpp', 'test/src/RTC/Codecs/TestH264.cpp',
'test/src/RTC/Codecs/TestH264_SVC.cpp', 'test/src/RTC/Codecs/TestH264_SVC.cpp',
'test/src/RTC/RTCP/TestFeedbackPsAfb.cpp', 'test/src/RTC/RTCP/TestFeedbackPsAfb.cpp',
......
...@@ -258,7 +258,7 @@ namespace RTC ...@@ -258,7 +258,7 @@ namespace RTC
this->payloadDescriptor->hasPictureId && this->payloadDescriptor->hasPictureId &&
this->payloadDescriptor->hasTlIndex && this->payloadDescriptor->hasTlIndex &&
this->payloadDescriptor->hasTl0PictureIndex && this->payloadDescriptor->hasTl0PictureIndex &&
!RTC::SeqManager<uint16_t>::IsSeqLowerThan( !RTC::SeqManager<uint16_t, 15>::IsSeqLowerThan(
this->payloadDescriptor->pictureId, this->payloadDescriptor->pictureId,
context->pictureIdManager.GetMaxInput()) context->pictureIdManager.GetMaxInput())
) )
......
...@@ -213,7 +213,7 @@ namespace RTC ...@@ -213,7 +213,7 @@ namespace RTC
// clang-format off // clang-format off
bool isOldPacket = ( bool isOldPacket = (
this->payloadDescriptor->hasPictureId && this->payloadDescriptor->hasPictureId &&
RTC::SeqManager<uint16_t>::IsSeqLowerThan( RTC::SeqManager<uint16_t, 15>::IsSeqLowerThan(
this->payloadDescriptor->pictureId, this->payloadDescriptor->pictureId,
context->pictureIdManager.GetMaxInput()) context->pictureIdManager.GetMaxInput())
); );
......
...@@ -7,43 +7,51 @@ ...@@ -7,43 +7,51 @@
namespace RTC namespace RTC
{ {
template<typename T> template<typename T, uint8_t N>
bool SeqManager<T>::SeqLowerThan::operator()(const T lhs, const T rhs) const bool SeqManager<T, N>::SeqLowerThan::operator()(const T lhs, const T rhs) const
{ {
return ((rhs > lhs) && (rhs - lhs <= MaxValue / 2)) || return ((rhs > lhs) && (rhs - lhs <= MaxValue / 2)) ||
((lhs > rhs) && (lhs - rhs > MaxValue / 2)); ((lhs > rhs) && (lhs - rhs > MaxValue / 2));
} }
template<typename T> template<typename T, uint8_t N>
bool SeqManager<T>::SeqHigherThan::operator()(const T lhs, const T rhs) const bool SeqManager<T, N>::SeqHigherThan::operator()(const T lhs, const T rhs) const
{ {
return ((lhs > rhs) && (lhs - rhs <= MaxValue / 2)) || return ((lhs > rhs) && (lhs - rhs <= MaxValue / 2)) ||
((rhs > lhs) && (rhs - lhs > MaxValue / 2)); ((rhs > lhs) && (rhs - lhs > MaxValue / 2));
} }
template<typename T> template<typename T, uint8_t N>
const typename SeqManager<T>::SeqLowerThan SeqManager<T>::isSeqLowerThan{}; const typename SeqManager<T, N>::SeqLowerThan SeqManager<T, N>::isSeqLowerThan{};
template<typename T> template<typename T, uint8_t N>
const typename SeqManager<T>::SeqHigherThan SeqManager<T>::isSeqHigherThan{}; const typename SeqManager<T, N>::SeqHigherThan SeqManager<T, N>::isSeqHigherThan{};
template<typename T> template<typename T, uint8_t N>
bool SeqManager<T>::IsSeqLowerThan(const T lhs, const T rhs) bool SeqManager<T, N>::IsSeqLowerThan(const T lhs, const T rhs)
{ {
return isSeqLowerThan(lhs, rhs); return isSeqLowerThan(lhs, rhs);
} }
template<typename T> template<typename T, uint8_t N>
bool SeqManager<T>::IsSeqHigherThan(const T lhs, const T rhs) bool SeqManager<T, N>::IsSeqHigherThan(const T lhs, const T rhs)
{ {
return isSeqHigherThan(lhs, rhs); return isSeqHigherThan(lhs, rhs);
} }
template<typename T> template<typename T, uint8_t N>
void SeqManager<T>::Sync(T input) T SeqManager<T, N>::Delta(const T lhs, const T rhs)
{
T value = (lhs > rhs) ? (lhs - rhs) : (MaxValue - rhs + lhs);
return value & MaxValue;
}
template<typename T, uint8_t N>
void SeqManager<T, N>::Sync(T input)
{ {
// Update base. // Update base.
this->base = this->maxOutput - input; this->base = (this->maxOutput - input) & MaxValue;
// Update maxInput. // Update maxInput.
this->maxInput = input; this->maxInput = input;
...@@ -52,24 +60,24 @@ namespace RTC ...@@ -52,24 +60,24 @@ namespace RTC
this->dropped.clear(); this->dropped.clear();
} }
template<typename T> template<typename T, uint8_t N>
void SeqManager<T>::Drop(T input) void SeqManager<T, N>::Drop(T input)
{ {
// Mark as dropped if 'input' is higher than anyone already processed. // Mark as dropped if 'input' is higher than anyone already processed.
if (SeqManager<T>::IsSeqHigherThan(input, this->maxInput)) if (SeqManager<T, N>::IsSeqHigherThan(input, this->maxInput))
{ {
this->dropped.insert(input); this->dropped.insert(input);
} }
} }
template<typename T> template<typename T, uint8_t N>
void SeqManager<T>::Offset(T offset) void SeqManager<T, N>::Offset(T offset)
{ {
this->base += offset; this->base = (this->base + offset) & MaxValue;
} }
template<typename T> template<typename T, uint8_t N>
bool SeqManager<T>::Input(const T input, T& output) bool SeqManager<T, N>::Input(const T input, T& output)
{ {
auto base = this->base; auto base = this->base;
...@@ -78,10 +86,10 @@ namespace RTC ...@@ -78,10 +86,10 @@ namespace RTC
{ {
// Delete dropped inputs older than input - MaxValue/2. // Delete dropped inputs older than input - MaxValue/2.
size_t droppedCount = this->dropped.size(); size_t droppedCount = this->dropped.size();
auto it = this->dropped.lower_bound(input - MaxValue / 2); size_t threshold = (input - MaxValue / 2) & MaxValue;
auto it = this->dropped.lower_bound(threshold);
this->dropped.erase(this->dropped.begin(), it); this->dropped.erase(this->dropped.begin(), it);
this->base -= (droppedCount - this->dropped.size()); this->base = (this->base - (droppedCount - this->dropped.size())) & MaxValue;
// Count dropped entries before 'input' in order to adapt the base. // Count dropped entries before 'input' in order to adapt the base.
droppedCount = this->dropped.size(); droppedCount = this->dropped.size();
...@@ -100,13 +108,13 @@ namespace RTC ...@@ -100,13 +108,13 @@ namespace RTC
droppedCount -= std::distance(it, this->dropped.end()); droppedCount -= std::distance(it, this->dropped.end());
} }
base = this->base - droppedCount; base = (this->base - droppedCount) & MaxValue;
} }
output = input + base; output = (input + base) & MaxValue;
T idelta = input - this->maxInput; T idelta = SeqManager<T, N>::Delta(input, this->maxInput);
T odelta = output - this->maxOutput; T odelta = SeqManager<T, N>::Delta(output, this->maxOutput);
// New input is higher than the maximum seen. But less than acceptable units higher. // New input is higher than the maximum seen. But less than acceptable units higher.
// Keep it as the maximum seen. See Drop(). // Keep it as the maximum seen. See Drop().
...@@ -121,14 +129,14 @@ namespace RTC ...@@ -121,14 +129,14 @@ namespace RTC
return true; return true;
} }
template<typename T> template<typename T, uint8_t N>
T SeqManager<T>::GetMaxInput() const T SeqManager<T, N>::GetMaxInput() const
{ {
return this->maxInput; return this->maxInput;
} }
template<typename T> template<typename T, uint8_t N>
T SeqManager<T>::GetMaxOutput() const T SeqManager<T, N>::GetMaxOutput() const
{ {
return this->maxOutput; return this->maxOutput;
} }
...@@ -136,6 +144,7 @@ namespace RTC ...@@ -136,6 +144,7 @@ namespace RTC
// Explicit instantiation to have all SeqManager definitions in this file. // Explicit instantiation to have all SeqManager definitions in this file.
template class SeqManager<uint8_t>; template class SeqManager<uint8_t>;
template class SeqManager<uint16_t>; template class SeqManager<uint16_t>;
template class SeqManager<uint16_t, 15>; // For PictureID (15 bits).
template class SeqManager<uint32_t>; template class SeqManager<uint32_t>;
} // namespace RTC } // namespace RTC
...@@ -586,6 +586,7 @@ namespace RTC ...@@ -586,6 +586,7 @@ namespace RTC
MS_DEBUG_TAG(rtp, "sync key frame received"); MS_DEBUG_TAG(rtp, "sync key frame received");
this->rtpSeqManager.Sync(packet->GetSequenceNumber() - 1); this->rtpSeqManager.Sync(packet->GetSequenceNumber() - 1);
this->encodingContext->SyncRequired();
this->syncRequired = false; this->syncRequired = false;
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
using namespace RTC; using namespace RTC;
constexpr uint16_t MaxPictureId = (1 << 15) - 1;
SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]") SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]")
{ {
SECTION("parse payload descriptor") SECTION("parse payload descriptor")
...@@ -274,22 +276,50 @@ SCENARIO("process VP8 payload descriptor", "[codecs][vp8]") ...@@ -274,22 +276,50 @@ SCENARIO("process VP8 payload descriptor", "[codecs][vp8]")
context.SetCurrentTemporalLayer(0); context.SetCurrentTemporalLayer(0);
context.SetTargetTemporalLayer(0); context.SetTargetTemporalLayer(0);
// Frame 1 // Frame 1.
auto forwarded = ProcessPacket(context, 0, 0, 0); auto forwarded = ProcessPacket(context, 0, 0, 0);
REQUIRE(forwarded); REQUIRE(forwarded);
REQUIRE(forwarded->pictureId == 0); REQUIRE(forwarded->pictureId == 0);
REQUIRE(forwarded->tl0PictureIndex == 0); REQUIRE(forwarded->tl0PictureIndex == 0);
// Frame 2 gets lost // Frame 2 gets lost.
// Frame 3 // Frame 3.
forwarded = ProcessPacket(context, 2, 1, 1); forwarded = ProcessPacket(context, 2, 1, 1);
REQUIRE_FALSE(forwarded); REQUIRE_FALSE(forwarded);
// Frame 2 retransmitted // Frame 2 retransmitted.
forwarded = ProcessPacket(context, 1, 1, 0); forwarded = ProcessPacket(context, 1, 1, 0);
REQUIRE(forwarded); REQUIRE(forwarded);
REQUIRE(forwarded->pictureId == 1); REQUIRE(forwarded->pictureId == 1);
REQUIRE(forwarded->tl0PictureIndex == 1); REQUIRE(forwarded->tl0PictureIndex == 1);
} }
SECTION("drop packets that belong to other temporal layers after rolling over pictureID")
{
RTC::Codecs::EncodingContext::Params params;
params.spatialLayers = 0;
params.temporalLayers = 2;
Codecs::VP8::EncodingContext context(params);
context.SyncRequired();
context.SetCurrentTemporalLayer(0);
context.SetTargetTemporalLayer(0);
// Frame 1.
auto forwarded = ProcessPacket(context, MaxPictureId, 0, 0);
REQUIRE(forwarded);
REQUIRE(forwarded->pictureId == 1);
REQUIRE(forwarded->tl0PictureIndex == 1);
// Frame 2.
forwarded = ProcessPacket(context, 0, 0, 0);
REQUIRE(forwarded);
REQUIRE(forwarded->pictureId == 2);
REQUIRE(forwarded->tl0PictureIndex == 1);
// Frame 3.
forwarded = ProcessPacket(context, 1, 0, 1);
REQUIRE_FALSE(forwarded);
}
} }
#include "common.hpp"
#include "RTC/Codecs/VP9.hpp"
#include <catch2/catch.hpp>
#include <cstring> // std::memcmp()
using namespace RTC;
constexpr uint16_t MaxPictureId = (1 << 15) - 1;
Codecs::VP9::PayloadDescriptor* CreateVP9Packet(
uint8_t* buffer, size_t bufferLen, uint16_t pictureId, uint8_t tlIndex)
{
buffer[0] = 0xAD; // I and L bits
uint16_t netPictureId = htons(pictureId);
std::memcpy(buffer + 1, &netPictureId, 2);
buffer[1] |= 0x80;
buffer[3] = tlIndex << 6;
auto* payloadDescriptor = Codecs::VP9::Parse(buffer, bufferLen);
REQUIRE(payloadDescriptor);
return payloadDescriptor;
}
std::unique_ptr<Codecs::VP9::PayloadDescriptor> ProcessVP9Packet(
Codecs::VP9::EncodingContext& context, uint16_t pictureId, uint8_t tlIndex)
{
// clang-format off
uint8_t buffer[] =
{
0xAD, 0x80, 0x00, 0x00, 0x00, 0x00
};
// clang-format on
bool marker;
auto* payloadDescriptor = CreateVP9Packet(buffer, sizeof(buffer), pictureId, tlIndex);
std::unique_ptr<Codecs::VP9::PayloadDescriptorHandler> payloadDescriptorHandler(
new Codecs::VP9::PayloadDescriptorHandler(payloadDescriptor));
if (payloadDescriptorHandler->Process(&context, buffer, marker))
{
return std::unique_ptr<Codecs::VP9::PayloadDescriptor>(Codecs::VP9::Parse(buffer, sizeof(buffer)));
}
return nullptr;
}
SCENARIO("process VP9 payload descriptor", "[codecs][vp9]")
{
SECTION("drop packets that belong to other temporal layers after rolling over pictureID")
{
RTC::Codecs::EncodingContext::Params params;
params.spatialLayers = 1;
params.temporalLayers = 3;
Codecs::VP9::EncodingContext context(params);
context.SyncRequired();
context.SetCurrentTemporalLayer(0);
context.SetTargetTemporalLayer(0);
context.SetCurrentSpatialLayer(0);
context.SetTargetSpatialLayer(0);
// Frame 1.
auto forwarded = ProcessVP9Packet(context, MaxPictureId, 0);
REQUIRE(forwarded);
REQUIRE(forwarded->pictureId == MaxPictureId);
// Frame 2.
forwarded = ProcessVP9Packet(context, 0, 0);
REQUIRE(forwarded);
REQUIRE(forwarded->pictureId == 0);
// Frame 3.
forwarded = ProcessVP9Packet(context, 1, 1);
REQUIRE_FALSE(forwarded);
}
}
...@@ -6,11 +6,14 @@ ...@@ -6,11 +6,14 @@
using namespace RTC; using namespace RTC;
constexpr uint16_t kMaxNumberFor15Bits = (1 << 15) - 1;
template<typename T> template<typename T>
struct TestSeqManagerInput struct TestSeqManagerInput
{ {
TestSeqManagerInput(T input, T output, bool sync = false, bool drop = false, T offset = 0) TestSeqManagerInput(
: input(input), output(output), sync(sync), drop(drop), offset(offset) T input, T output, bool sync = false, bool drop = false, T offset = 0, int64_t maxInput = -1)
: input(input), output(output), sync(sync), drop(drop), offset(offset), maxInput(maxInput)
{ {
} }
...@@ -19,10 +22,11 @@ struct TestSeqManagerInput ...@@ -19,10 +22,11 @@ struct TestSeqManagerInput
bool sync{ false }; bool sync{ false };
bool drop{ false }; bool drop{ false };
T offset{ 0 }; T offset{ 0 };
int64_t maxInput{ -1 };
}; };
template<typename T> template<typename T, uint8_t N>
void validate(SeqManager<T>& seqManager, std::vector<TestSeqManagerInput<T>>& inputs) void validate(SeqManager<T, N>& seqManager, std::vector<TestSeqManagerInput<T>>& inputs)
{ {
for (auto& element : inputs) for (auto& element : inputs)
{ {
...@@ -44,6 +48,10 @@ void validate(SeqManager<T>& seqManager, std::vector<TestSeqManagerInput<T>>& in ...@@ -44,6 +48,10 @@ void validate(SeqManager<T>& seqManager, std::vector<TestSeqManagerInput<T>>& in
// 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)
{
REQUIRE(std::to_string(element.maxInput) == std::to_string(seqManager.GetMaxInput()));
}
} }
} }
} }
...@@ -55,6 +63,11 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -55,6 +63,11 @@ SCENARIO("SeqManager", "[rtc]")
REQUIRE(SeqManager<uint16_t>::IsSeqHigherThan(0, 65000) == true); REQUIRE(SeqManager<uint16_t>::IsSeqHigherThan(0, 65000) == true);
} }
SECTION("0 is greater than 32500 in range 15")
{
REQUIRE(SeqManager<uint16_t, 15>::IsSeqHigherThan(0, 32500) == true);
}
SECTION("receive ordered numbers, no sync, no drop") SECTION("receive ordered numbers, no sync, no drop")
{ {
// clang-format off // clang-format off
...@@ -76,7 +89,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -76,7 +89,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("receive ordered numbers, sync, no drop") SECTION("receive ordered numbers, sync, no drop")
...@@ -96,7 +111,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -96,7 +111,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("receive ordered numbers, sync, drop") SECTION("receive ordered numbers, sync, drop")
...@@ -121,7 +138,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -121,7 +138,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("receive ordered wrapped numbers") SECTION("receive ordered wrapped numbers")
...@@ -154,7 +173,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -154,7 +173,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("receive mixed numbers with a big jump, drop before jump") SECTION("receive mixed numbers with a big jump, drop before jump")
...@@ -172,7 +193,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -172,7 +193,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("receive mixed numbers with a big jump, drop after jump") SECTION("receive mixed numbers with a big jump, drop after jump")
...@@ -189,7 +212,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -189,7 +212,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("drop, receive numbers newer and older than the one dropped") SECTION("drop, receive numbers newer and older than the one dropped")
...@@ -206,7 +231,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -206,7 +231,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("receive mixed numbers, sync, drop") SECTION("receive mixed numbers, sync, drop")
...@@ -284,7 +311,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -284,7 +311,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("drop many inputs at the beginning (using uint16_t)") SECTION("drop many inputs at the beginning (using uint16_t)")
...@@ -325,7 +354,9 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -325,7 +354,9 @@ SCENARIO("SeqManager", "[rtc]")
// clang-format on // clang-format on
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
SeqManager<uint16_t, 15> seqManager2;
validate(seqManager, inputs); validate(seqManager, inputs);
validate(seqManager2, inputs);
} }
SECTION("drop many inputs at the beginning (using uint8_t)") SECTION("drop many inputs at the beginning (using uint8_t)")
...@@ -369,6 +400,64 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -369,6 +400,64 @@ SCENARIO("SeqManager", "[rtc]")
validate(seqManager, inputs); validate(seqManager, inputs);
} }
SECTION("receive mixed numbers, sync, drop in range 15")
{
// clang-format off
std::vector<TestSeqManagerInput<uint16_t>> inputs =
{
{ 0, 0, false, false },
{ 1, 1, false, false },
{ 2, 2, false, false },
{ 3, 3, false, false },
{ 7, 7, false, false },
{ 6, 0, false, true }, // drop.
{ 8, 8, false, false },
{ 10, 10, false, false },
{ 9, 9, false, false },
{ 11, 11, false, false },
{ 0, 12, true, false }, // sync.
{ 2, 14, false, false },
{ 3, 15, false, false },
{ 4, 16, false, false },
{ 5, 17, false, false },
{ 6, 18, false, false },
{ 7, 19, false, false },
{ 8, 20, false, false },
{ 9, 21, false, false },
{ 10, 22, false, false },
{ 9, 0, false, true }, // drop.
{ 61, 23, true, false }, // sync.
{ 62, 24, false, false },
{ 63, 25, false, false },
{ 64, 26, false, false },
{ 65, 27, false, false },
{ 11, 28, true, false }, // sync.
{ 12, 29, false, false },
{ 13, 30, false, false },
{ 14, 31, false, false },
{ 15, 32, false, false },
{ 1, 33, true, false }, // sync.
{ 2, 34, false, false },
{ 3, 35, false, false },
{ 4, 36, false, false },
{ 5, 37, false, false },
{ 32767, 38, true, false }, // sync.
{ 32768, 39, false, false },
{ 32769, 40, false, false },
{ 0, 41, true, false }, // sync.
{ 1, 42, false, false },
{ 3, 0, false, true }, // drop.
{ 4, 44, false, false },
{ 5, 45, false, false },
{ 6, 46, false, false },
{ 7, 47, false, false }
};
// clang-format on
SeqManager<uint16_t, 15> seqManager;
validate(seqManager, inputs);
}
SECTION("drop many inputs at the beginning (using uint16_t with high values)") SECTION("drop many inputs at the beginning (using uint16_t with high values)")
{ {
// clang-format off // clang-format off
...@@ -424,4 +513,98 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -424,4 +513,98 @@ SCENARIO("SeqManager", "[rtc]")
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
validate(seqManager, inputs); validate(seqManager, inputs);
} }
SECTION("drop many inputs at the beginning (using uint16_t range 15 with high values)")
{
// clang-format off
std::vector<TestSeqManagerInput<uint16_t>> inputs =
{
{ 1, 1, false, false },
{ 2, 0, false, true }, // drop.
{ 3, 0, false, true }, // drop.
{ 4, 0, false, true }, // drop.
{ 5, 0, false, true }, // drop.
{ 6, 0, false, true }, // drop.
{ 7, 0, false, true }, // drop.
{ 8, 0, false, true }, // drop.
{ 9, 0, false, true }, // drop.
{ 16384, 16376, false, false },
{ 16385, 16377, false, false },
{ 16386, 16378, false, false },
{ 16387, 16379, false, false },
{ 16388, 16380, false, false },
{ 16389, 16381, false, false },
{ 16390, 16382, false, false },
{ 16391, 16383, false, false },
{ 16392, 16384, false, false },
{ 16393, 16385, false, false },
{ 16394, 16386, false, false },
{ 16395, 16387, false, false },
{ 16396, 16388, false, false }
};
// clang-format on
SeqManager<uint16_t, 15> seqManager;
validate(seqManager, inputs);
}
SECTION("sync and drop some input near max-value in a 15bit range")
{
// clang-format off
std::vector<TestSeqManagerInput<uint16_t>> inputs =
{
{ 32762, 1, true, false, 0, 32762 },
{ 32763, 2, false, false, 0, 32763 },
{ 32764, 3, false, false, 0, 32764 },
{ 32765, 0, false, true, 0, 32765 },
{ 32766, 0, false, true, 0, 32766 },
{ 32767, 4, false, false, 0, 32767 },
{ 0, 5, false, false, 0, 0 },
{ 1, 6, false, false, 0, 1 },
{ 2, 7, false, false, 0, 2 },
{ 3, 8, false, false, 0, 3 }
};
// clang-format on
SeqManager<uint16_t, 15> seqManager;
validate(seqManager, inputs);
}
SECTION("should update all values during multiple roll overs")
{
// clang-format off
std::vector<TestSeqManagerInput<uint16_t>> inputs =
{
{ 0, 1, true, false, 0, 0 },
};
for (uint16_t j = 0; j < 100; ++j) {
for (uint16_t i = 1; i < std::numeric_limits<uint16_t>::max(); ++i) {
uint16_t output = i + 1;
inputs.push_back({ i, output, false, false, 0, i });
}
}
// clang-format on
SeqManager<uint16_t> seqManager;
validate(seqManager, inputs);
}
SECTION("should update all values during multiple roll overs (15 bits range)")
{
// clang-format off
std::vector<TestSeqManagerInput<uint16_t>> inputs =
{
{ 0, 1, true, false, 0, 0 },
};
for (uint16_t j = 0; j < 100; ++j) {
for (uint16_t i = 1; i < kMaxNumberFor15Bits; ++i) {
uint16_t output = i + 1;
inputs.push_back({ i, output, false, false, 0, i });
}
}
// clang-format on
SeqManager<uint16_t, 15> seqManager;
validate(seqManager, inputs);
}
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论