mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-16 07:10:38 +01:00

A packet arrival history is used to store the timing of incoming packets and tracks the earliest and latest packets by taking the difference between rtp timestamp and arrival time. The history is windowed to 2 seconds by default. The packet arrival history will replace the relative arrival delay tracker in a follow up cl. The playout delay is estimated by taking the difference between the current playout timestamp and the earliest packet arrival in the history. This method works better when DTX is used compared to the buffer level filter that it replaces. The threshold for acceleration is changed to be the maximum of the target delay and the maximum packet arrival delay in the history. This prevents any acceleration immediately after an underrun and gives some time to adapt the target delay to new network conditions. The logic when to decode the next packet after a packet loss is also changed to do concealment for the full loss duration unless the delay is too high. The new mode is default disabled and can be enabled using a field trial. Bug: webrtc:13322,webrtc:13966 Change-Id: Idfa0020584591261475b9ca350cc7c6531de9911 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/259820 Reviewed-by: Minyue Li <minyue@webrtc.org> Commit-Queue: Jakob Ivarsson <jakobi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36899}
122 lines
3.8 KiB
C++
122 lines
3.8 KiB
C++
/*
|
|
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/audio_coding/neteq/packet_arrival_history.h"
|
|
|
|
#include <cstdint>
|
|
#include <limits>
|
|
|
|
#include "test/gtest.h"
|
|
|
|
namespace webrtc {
|
|
namespace {
|
|
|
|
constexpr int kFs = 8000;
|
|
constexpr int kFsKhz = kFs / 1000;
|
|
constexpr int kFrameSizeMs = 20;
|
|
constexpr int kWindowSizeMs = 1000;
|
|
|
|
class PacketArrivalHistoryTest : public testing::Test {
|
|
public:
|
|
PacketArrivalHistoryTest() : history_(kWindowSizeMs) {
|
|
history_.set_sample_rate(kFs);
|
|
}
|
|
void IncrementTime(int delta_ms) { time_ms_ += delta_ms; }
|
|
int InsertPacketAndGetDelay(int timestamp_delta_ms) {
|
|
uint32_t timestamp = timestamp_ + timestamp_delta_ms * kFsKhz;
|
|
if (timestamp_delta_ms > 0) {
|
|
timestamp_ = timestamp;
|
|
}
|
|
history_.Insert(timestamp, time_ms_);
|
|
return history_.GetDelayMs(timestamp, time_ms_);
|
|
}
|
|
|
|
protected:
|
|
int64_t time_ms_ = 0;
|
|
PacketArrivalHistory history_;
|
|
uint32_t timestamp_ = 0x12345678;
|
|
};
|
|
|
|
TEST_F(PacketArrivalHistoryTest, RelativeArrivalDelay) {
|
|
EXPECT_EQ(InsertPacketAndGetDelay(0), 0);
|
|
|
|
IncrementTime(kFrameSizeMs);
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), 0);
|
|
|
|
IncrementTime(2 * kFrameSizeMs);
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), 20);
|
|
|
|
// Reordered packet.
|
|
EXPECT_EQ(InsertPacketAndGetDelay(-2 * kFrameSizeMs), 60);
|
|
|
|
IncrementTime(2 * kFrameSizeMs);
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), 40);
|
|
|
|
// Move reference packet forward.
|
|
EXPECT_EQ(InsertPacketAndGetDelay(4 * kFrameSizeMs), 0);
|
|
|
|
IncrementTime(2 * kFrameSizeMs);
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), 20);
|
|
|
|
// Earlier packet is now more delayed due to the new reference packet.
|
|
EXPECT_EQ(history_.GetMaxDelayMs(), 100);
|
|
}
|
|
|
|
TEST_F(PacketArrivalHistoryTest, ReorderedPackets) {
|
|
// Insert first packet.
|
|
EXPECT_EQ(InsertPacketAndGetDelay(0), 0);
|
|
|
|
// Insert reordered packet.
|
|
EXPECT_EQ(InsertPacketAndGetDelay(-80), 80);
|
|
|
|
// Insert another reordered packet.
|
|
EXPECT_EQ(InsertPacketAndGetDelay(-kFrameSizeMs), 20);
|
|
|
|
// Insert the next packet in order and verify that the relative delay is
|
|
// estimated based on the first inserted packet.
|
|
IncrementTime(4 * kFrameSizeMs);
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), 60);
|
|
|
|
EXPECT_EQ(history_.GetMaxDelayMs(), 80);
|
|
}
|
|
|
|
TEST_F(PacketArrivalHistoryTest, MaxHistorySize) {
|
|
EXPECT_EQ(InsertPacketAndGetDelay(0), 0);
|
|
|
|
IncrementTime(2 * kFrameSizeMs);
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), 20);
|
|
EXPECT_EQ(history_.GetMaxDelayMs(), 20);
|
|
|
|
// Insert next packet with a timestamp difference larger than maximum history
|
|
// size. This removes the previously inserted packet from the history.
|
|
IncrementTime(kWindowSizeMs + kFrameSizeMs);
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs + kWindowSizeMs), 0);
|
|
EXPECT_EQ(history_.GetMaxDelayMs(), 0);
|
|
}
|
|
|
|
TEST_F(PacketArrivalHistoryTest, TimestampWraparound) {
|
|
timestamp_ = std::numeric_limits<uint32_t>::max();
|
|
EXPECT_EQ(InsertPacketAndGetDelay(0), 0);
|
|
|
|
IncrementTime(2 * kFrameSizeMs);
|
|
// Insert timestamp that will wrap around.
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), kFrameSizeMs);
|
|
|
|
// Insert reordered packet before the wraparound.
|
|
EXPECT_EQ(InsertPacketAndGetDelay(-2 * kFrameSizeMs), 3 * kFrameSizeMs);
|
|
|
|
// Insert another in-order packet after the wraparound.
|
|
EXPECT_EQ(InsertPacketAndGetDelay(kFrameSizeMs), 0);
|
|
|
|
EXPECT_EQ(history_.GetMaxDelayMs(), 3 * kFrameSizeMs);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace webrtc
|