From b4b0ac8758ded1b6099b40ccb585d5a3ad4a8ad0 Mon Sep 17 00:00:00 2001 From: Eugene Voityuk Date: Tue, 6 Sep 2022 21:14:40 +0300 Subject: [PATCH] Fix tests. Adopt changes to GetBaseDelta from https://github.com/versatica/mediasoup/pull/900 Add tests for GetBaseDelta Wraparound. --- .../remote_bitrate_estimator/inter_arrival.cc | 81 ++++++++++--------- .../remote_bitrate_estimator/inter_arrival.h | 12 +-- 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/inter_arrival.cc b/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/inter_arrival.cc index 46e2df75dc..1d8b4ba06a 100644 --- a/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/inter_arrival.cc +++ b/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/inter_arrival.cc @@ -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 = @@ -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; } diff --git a/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/inter_arrival.h b/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/inter_arrival.h index 1602a62bb7..504e11729d 100644 --- a/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/inter_arrival.h +++ b/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/inter_arrival.h @@ -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;