Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
Adopt changes to GetBaseDelta from versatica#900
Add tests for GetBaseDelta Wraparound.
  • Loading branch information
Eugene Voityuk committed Sep 6, 2022
1 parent 2b53714 commit b4b0ac8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,32 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
MS_ASSERT(arrival_time_delta_ms != nullptr, "arrival_time_delta_ms is null");
MS_ASSERT(packet_size_delta != nullptr, "packet_size_delta is null");
bool calculated_deltas = false;
if (current_timestamp_group_.IsFirstPacket()) {
// We don't have enough data to update the filter, so we store it until we
// have two frames of data to process.
current_timestamp_group_.timestamp = timestamp;
current_timestamp_group_.first_timestamp = timestamp;
current_timestamp_group_.first_arrival_ms = arrival_time_ms;
} else if (!PacketInOrder(timestamp, arrival_time_ms)) {
return false;
} else if (NewTimestampGroup(arrival_time_ms, timestamp)) {
// First packet of a later frame, the previous frame sample is ready.
if (prev_timestamp_group_.complete_time_ms >= 0) {
*timestamp_delta =
current_timestamp_group_.timestamp - prev_timestamp_group_.timestamp;
*arrival_time_delta_ms = current_timestamp_group_.complete_time_ms -
prev_timestamp_group_.complete_time_ms;
MS_DEBUG_DEV("timestamp previous/current [%" PRIu32 "/%" PRIu32"] complete time previous/current [%" PRIi64 "/%" PRIi64 "]",
prev_timestamp_group_.timestamp, current_timestamp_group_.timestamp,
prev_timestamp_group_.complete_time_ms, current_timestamp_group_.complete_time_ms);
if (current_timestamp_group_.IsFirstPacket())
{
// We don't have enough data to update the filter, so we store it until we
// have two frames of data to process.
current_timestamp_group_.timestamp = timestamp;
current_timestamp_group_.first_timestamp = timestamp;
current_timestamp_group_.first_arrival_ms = arrival_time_ms;
}
else if (!PacketInOrder(timestamp))
{
return false;
}
else if (NewTimestampGroup(arrival_time_ms, timestamp))
{
// First packet of a later frame, the previous frame sample is ready.
if (prev_timestamp_group_.complete_time_ms >= 0)
{
*timestamp_delta = current_timestamp_group_.timestamp - prev_timestamp_group_.timestamp;
*arrival_time_delta_ms =
current_timestamp_group_.complete_time_ms - prev_timestamp_group_.complete_time_ms;
MS_DEBUG_DEV(
"timestamp previous/current [%" PRIu32 "/%" PRIu32
"] complete time previous/current [%" PRIi64 "/%" PRIi64 "]",
prev_timestamp_group_.timestamp,
current_timestamp_group_.timestamp,
prev_timestamp_group_.complete_time_ms, current_timestamp_group_.complete_time_ms);
// Check system time differences to see if we have an unproportional jump
// in arrival time. In that case reset the inter-arrival computations.
int64_t system_time_delta_ms =
Expand Down Expand Up @@ -115,27 +123,22 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
return calculated_deltas;
}

bool InterArrival::PacketInOrder(uint32_t timestamp, int64_t arrival_time_ms) {
if (current_timestamp_group_.IsFirstPacket()) {
return true;
} else if (arrival_time_ms < 0) {
// NOTE: Change related to https://github.com/versatica/mediasoup/issues/357
//
// Sometimes we do get negative arrival time, which causes BelongsToBurst()
// to fail, which may cause anything that uses InterArrival to crash.
//
// Credits to @sspanak and @Ivaka.
return false;
} else {
// Assume that a diff which is bigger than half the timestamp interval
// (32 bits) must be due to reordering. This code is almost identical to
// that in IsNewerTimestamp() in module_common_types.h.
uint32_t timestamp_diff =
timestamp - current_timestamp_group_.first_timestamp;

const static uint32_t int_middle = 0x80000000;

if (timestamp_diff == int_middle) {
bool InterArrival::PacketInOrder(uint32_t timestamp)
{
if (current_timestamp_group_.IsFirstPacket())
{
return true;
}
else
{
// Assume that a diff which is bigger than half the timestamp interval
// (32 bits) must be due to reordering. This code is almost identical to
// that in IsNewerTimestamp() in module_common_types.h.
uint32_t timestamp_diff = timestamp - current_timestamp_group_.first_timestamp;

const static uint32_t int_middle = 0x80000000;

if (timestamp_diff == int_middle) {
return timestamp > current_timestamp_group_.first_timestamp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,10 @@ class InterArrival {
int64_t last_system_time_ms;
};

// Returns true if the packet with timestamp |timestamp| arrived in order.
//
// NOTE: Change related to https://github.com/versatica/mediasoup/issues/357
//
// bool PacketInOrder(uint32_t timestamp);
bool PacketInOrder(uint32_t timestamp, int64_t arrival_time_ms);

// Returns true if the last packet was the end of the current batch and the
// Returns true if the packet with timestamp |timestamp| arrived in order.
bool PacketInOrder(uint32_t timestamp);

// Returns true if the last packet was the end of the current batch and the
// packet with |timestamp| is the first of a new batch.
bool NewTimestampGroup(int64_t arrival_time_ms, uint32_t timestamp) const;

Expand Down

0 comments on commit b4b0ac8

Please sign in to comment.