mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-14 06:10:40 +01:00

The new version of MSan (rolled by [1]) detects the following: ``` ==39908==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x5591400a52ef in GetPlayoutDelayMs ./../../modules/audio_coding/neteq/decision_logic.cc:466:35 #1 0x5591400a52ef in webrtc::DecisionLogic::ExpectedPacketAvailable(webrtc::NetEqController::NetEqStatus) ./../../modules/audio_coding/neteq/decision_logic.cc:311:36 #2 0x5591400a39e9 in webrtc::DecisionLogic::GetDecision(webrtc::NetEqController::NetEqStatus const&, bool*) ./../../modules/audio_coding/neteq/decision_logic.cc:0:0 #3 0x55913cf590c9 in webrtc::DecisionLogicTest_PreemptiveExpand_Test::TestBody() ./../../modules/audio_coding/neteq/decision_logic_unittest.cc:139:3 #4 0x55913ef28283 in HandleExceptionsInMethodIfSupported<testing::Test, void> ./../../third_party/googletest/src/googletest/src/gtest.cc:0:3 #5 0x55913ef28283 in testing::Test::Run() ./../../third_party/googletest/src/googletest/src/gtest.cc:2710:5 #6 0x55913ef2ab46 in testing::TestInfo::Run() ./../../third_party/googletest/src/googletest/src/gtest.cc:2856:11 #7 0x55913ef2da34 in testing::TestSuite::Run() ./../../third_party/googletest/src/googletest/src/gtest.cc:3034:30 #8 0x55913ef621e8 in testing::internal::UnitTestImpl::RunAllTests() ./../../third_party/googletest/src/googletest/src/gtest.cc:5964:44 #9 0x55913ef60f54 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> ./../../third_party/googletest/src/googletest/src/gtest.cc:0:0 #10 0x55913ef60f54 in testing::UnitTest::Run() ./../../third_party/googletest/src/googletest/src/gtest.cc:5543:10 #11 0x55913ee1a944 in RUN_ALL_TESTS ./../../third_party/googletest/src/googletest/include/gtest/gtest.h:2334:73 #12 0x55913ee1a944 in webrtc::(anonymous namespace)::TestMainImpl::Run(int, char**) ./../../test/test_main_lib.cc:203:21 #13 0x55913cbd36b8 in main ./../../test/test_main.cc:72:16 #14 0x7fdb18c73082 in __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:308:16 #15 0x55913cb3e1a9 in _start ??:0:0 ``` [1] - https://webrtc-review.googlesource.com/c/src/+/353620 Bug: b/344970813 Change-Id: I9b5d7791e68b4c494168ba9f007a3099ae21fed4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353581 Auto-Submit: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Commit-Queue: Jakob Ivarsson <jakobi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42433}
205 lines
7.5 KiB
C++
205 lines
7.5 KiB
C++
/*
|
|
* Copyright (c) 2012 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.
|
|
*/
|
|
|
|
// Unit tests for DecisionLogic class and derived classes.
|
|
|
|
#include "modules/audio_coding/neteq/decision_logic.h"
|
|
|
|
#include "api/neteq/neteq_controller.h"
|
|
#include "api/neteq/tick_timer.h"
|
|
#include "modules/audio_coding/neteq/delay_manager.h"
|
|
#include "modules/audio_coding/neteq/mock/mock_buffer_level_filter.h"
|
|
#include "modules/audio_coding/neteq/mock/mock_delay_manager.h"
|
|
#include "modules/audio_coding/neteq/mock/mock_packet_arrival_history.h"
|
|
#include "test/gtest.h"
|
|
|
|
namespace webrtc {
|
|
|
|
namespace {
|
|
|
|
constexpr int kSampleRate = 8000;
|
|
constexpr int kSamplesPerMs = kSampleRate / 1000;
|
|
constexpr int kOutputSizeSamples = kSamplesPerMs * 10;
|
|
constexpr int kMinTimescaleInterval = 5;
|
|
|
|
NetEqController::NetEqStatus CreateNetEqStatus(NetEq::Mode last_mode,
|
|
int current_delay_ms) {
|
|
NetEqController::NetEqStatus status;
|
|
status.play_dtmf = false;
|
|
status.last_mode = last_mode;
|
|
status.target_timestamp = 1234;
|
|
status.generated_noise_samples = 0;
|
|
status.expand_mutefactor = 0;
|
|
status.packet_buffer_info.num_samples = current_delay_ms * kSamplesPerMs;
|
|
status.packet_buffer_info.span_samples = current_delay_ms * kSamplesPerMs;
|
|
status.packet_buffer_info.span_samples_wait_time =
|
|
current_delay_ms * kSamplesPerMs;
|
|
status.packet_buffer_info.dtx_or_cng = false;
|
|
status.next_packet = {status.target_timestamp, false, false};
|
|
status.sync_buffer_samples = 0;
|
|
return status;
|
|
}
|
|
|
|
using ::testing::_;
|
|
using ::testing::Return;
|
|
|
|
} // namespace
|
|
|
|
class DecisionLogicTest : public ::testing::Test {
|
|
protected:
|
|
DecisionLogicTest() {
|
|
NetEqController::Config config;
|
|
config.tick_timer = &tick_timer_;
|
|
config.allow_time_stretching = true;
|
|
auto delay_manager = std::make_unique<MockDelayManager>(
|
|
DelayManager::Config(), config.tick_timer);
|
|
mock_delay_manager_ = delay_manager.get();
|
|
auto buffer_level_filter = std::make_unique<MockBufferLevelFilter>();
|
|
mock_buffer_level_filter_ = buffer_level_filter.get();
|
|
auto packet_arrival_history =
|
|
std::make_unique<MockPacketArrivalHistory>(&tick_timer_);
|
|
mock_packet_arrival_history_ = packet_arrival_history.get();
|
|
decision_logic_ = std::make_unique<DecisionLogic>(
|
|
config, std::move(delay_manager), std::move(buffer_level_filter),
|
|
std::move(packet_arrival_history));
|
|
decision_logic_->SetSampleRate(kSampleRate, kOutputSizeSamples);
|
|
}
|
|
|
|
TickTimer tick_timer_;
|
|
std::unique_ptr<DecisionLogic> decision_logic_;
|
|
MockDelayManager* mock_delay_manager_;
|
|
MockBufferLevelFilter* mock_buffer_level_filter_;
|
|
MockPacketArrivalHistory* mock_packet_arrival_history_;
|
|
};
|
|
|
|
TEST_F(DecisionLogicTest, NormalOperation) {
|
|
EXPECT_CALL(*mock_delay_manager_, TargetDelayMs())
|
|
.WillRepeatedly(Return(100));
|
|
EXPECT_CALL(*mock_packet_arrival_history_, GetDelayMs(_))
|
|
.WillRepeatedly(Return(100));
|
|
EXPECT_CALL(*mock_packet_arrival_history_, GetMaxDelayMs())
|
|
.WillRepeatedly(Return(0));
|
|
|
|
bool reset_decoder = false;
|
|
tick_timer_.Increment(kMinTimescaleInterval + 1);
|
|
EXPECT_EQ(decision_logic_->GetDecision(
|
|
CreateNetEqStatus(NetEq::Mode::kNormal, 100), &reset_decoder),
|
|
NetEq::Operation::kNormal);
|
|
EXPECT_FALSE(reset_decoder);
|
|
}
|
|
|
|
TEST_F(DecisionLogicTest, Accelerate) {
|
|
EXPECT_CALL(*mock_delay_manager_, TargetDelayMs())
|
|
.WillRepeatedly(Return(100));
|
|
EXPECT_CALL(*mock_packet_arrival_history_, GetDelayMs(_))
|
|
.WillRepeatedly(Return(150));
|
|
EXPECT_CALL(*mock_packet_arrival_history_, GetMaxDelayMs())
|
|
.WillRepeatedly(Return(0));
|
|
|
|
bool reset_decoder = false;
|
|
tick_timer_.Increment(kMinTimescaleInterval + 1);
|
|
EXPECT_EQ(decision_logic_->GetDecision(
|
|
CreateNetEqStatus(NetEq::Mode::kNormal, 100), &reset_decoder),
|
|
NetEq::Operation::kAccelerate);
|
|
EXPECT_FALSE(reset_decoder);
|
|
}
|
|
|
|
TEST_F(DecisionLogicTest, FastAccelerate) {
|
|
EXPECT_CALL(*mock_delay_manager_, TargetDelayMs())
|
|
.WillRepeatedly(Return(100));
|
|
EXPECT_CALL(*mock_packet_arrival_history_, GetDelayMs(_))
|
|
.WillRepeatedly(Return(500));
|
|
EXPECT_CALL(*mock_packet_arrival_history_, GetMaxDelayMs())
|
|
.WillRepeatedly(Return(0));
|
|
|
|
bool reset_decoder = false;
|
|
tick_timer_.Increment(kMinTimescaleInterval + 1);
|
|
EXPECT_EQ(decision_logic_->GetDecision(
|
|
CreateNetEqStatus(NetEq::Mode::kNormal, 100), &reset_decoder),
|
|
NetEq::Operation::kFastAccelerate);
|
|
EXPECT_FALSE(reset_decoder);
|
|
}
|
|
|
|
TEST_F(DecisionLogicTest, PreemptiveExpand) {
|
|
EXPECT_CALL(*mock_delay_manager_, TargetDelayMs())
|
|
.WillRepeatedly(Return(100));
|
|
EXPECT_CALL(*mock_packet_arrival_history_, GetDelayMs(_))
|
|
.WillRepeatedly(Return(50));
|
|
EXPECT_CALL(*mock_packet_arrival_history_, GetMaxDelayMs())
|
|
.WillRepeatedly(Return(0));
|
|
|
|
bool reset_decoder = false;
|
|
tick_timer_.Increment(kMinTimescaleInterval + 1);
|
|
EXPECT_EQ(decision_logic_->GetDecision(
|
|
CreateNetEqStatus(NetEq::Mode::kNormal, 100), &reset_decoder),
|
|
NetEq::Operation::kPreemptiveExpand);
|
|
EXPECT_FALSE(reset_decoder);
|
|
}
|
|
|
|
TEST_F(DecisionLogicTest, PostponeDecodeAfterExpand) {
|
|
EXPECT_CALL(*mock_delay_manager_, TargetDelayMs())
|
|
.WillRepeatedly(Return(500));
|
|
|
|
// Below 50% target delay threshold.
|
|
bool reset_decoder = false;
|
|
EXPECT_EQ(decision_logic_->GetDecision(
|
|
CreateNetEqStatus(NetEq::Mode::kExpand, 200), &reset_decoder),
|
|
NetEq::Operation::kExpand);
|
|
EXPECT_FALSE(reset_decoder);
|
|
|
|
// Above 50% target delay threshold.
|
|
EXPECT_EQ(decision_logic_->GetDecision(
|
|
CreateNetEqStatus(NetEq::Mode::kExpand, 250), &reset_decoder),
|
|
NetEq::Operation::kNormal);
|
|
EXPECT_FALSE(reset_decoder);
|
|
}
|
|
|
|
TEST_F(DecisionLogicTest, TimeStrechComfortNoise) {
|
|
EXPECT_CALL(*mock_delay_manager_, TargetDelayMs())
|
|
.WillRepeatedly(Return(500));
|
|
|
|
{
|
|
bool reset_decoder = false;
|
|
// Below target window.
|
|
auto status = CreateNetEqStatus(NetEq::Mode::kCodecInternalCng, 200);
|
|
status.generated_noise_samples = 400 * kSamplesPerMs;
|
|
status.next_packet->timestamp =
|
|
status.target_timestamp + 400 * kSamplesPerMs;
|
|
EXPECT_EQ(decision_logic_->GetDecision(status, &reset_decoder),
|
|
NetEq::Operation::kCodecInternalCng);
|
|
EXPECT_FALSE(reset_decoder);
|
|
}
|
|
|
|
{
|
|
bool reset_decoder = false;
|
|
// Above target window.
|
|
auto status = CreateNetEqStatus(NetEq::Mode::kCodecInternalCng, 600);
|
|
status.generated_noise_samples = 200 * kSamplesPerMs;
|
|
status.next_packet->timestamp =
|
|
status.target_timestamp + 400 * kSamplesPerMs;
|
|
EXPECT_EQ(decision_logic_->GetDecision(status, &reset_decoder),
|
|
NetEq::Operation::kNormal);
|
|
EXPECT_FALSE(reset_decoder);
|
|
}
|
|
}
|
|
|
|
TEST_F(DecisionLogicTest, CngTimeout) {
|
|
auto status = CreateNetEqStatus(NetEq::Mode::kCodecInternalCng, 0);
|
|
status.next_packet = absl::nullopt;
|
|
status.generated_noise_samples = kSamplesPerMs * 500;
|
|
bool reset_decoder = false;
|
|
EXPECT_EQ(decision_logic_->GetDecision(status, &reset_decoder),
|
|
NetEq::Operation::kCodecInternalCng);
|
|
status.generated_noise_samples = kSamplesPerMs * 1010;
|
|
EXPECT_EQ(decision_logic_->GetDecision(status, &reset_decoder),
|
|
NetEq::Operation::kExpand);
|
|
}
|
|
|
|
} // namespace webrtc
|