chromium/media/webrtc/audio_processor_test.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "media/webrtc/audio_processor.h"

#include <stddef.h>
#include <stdint.h>

#include <optional>
#include <string>
#include <string_view>

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/memory/aligned_memory.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_file_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromecast_buildflags.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_parameters.h"
#include "media/base/audio_processing.h"
#include "media/webrtc/constants.h"
#include "media/webrtc/webrtc_features.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/webrtc/api/make_ref_counted.h"
#include "third_party/webrtc/modules/audio_processing/include/mock_audio_processing.h"

_;
AnyNumber;
AtLeast;
Return;

namespace media {
namespace {

// Test all sample rates observed in UMA metric WebRTC.AudioInputSampleRate.
static const int kSupportedSampleRates[] =;

MockProcessedCaptureCallback;

AudioProcessor::LogCallback LogCallbackForTesting() {}

// The number of packets used for testing.
const int kNumberOfPacketsForTest =;

void ReadDataFromSpeechFile(char* data, int length) {}

void DisableDefaultSettings(AudioProcessingSettings& settings) {}

}  // namespace

class AudioProcessorTest : public ::testing::Test {};

struct AudioProcessorTestMultichannelAndFormat
    : public AudioProcessorTest,
      public ::testing::WithParamInterface<std::tuple<bool, bool>> {};

INSTANTIATE_TEST_SUITE_P();

// Test crashing with ASAN on Android. crbug.com/468762
#if BUILDFLAG(IS_ANDROID) && defined(ADDRESS_SANITIZER)
#define MAYBE_WithAudioProcessing
#else
#define MAYBE_WithAudioProcessing
#endif
TEST_P(AudioProcessorTestMultichannelAndFormat, MAYBE_WithAudioProcessing) {}

TEST_F(AudioProcessorTest, TurnOffDefaultConstraints) {}

// Test crashing with ASAN on Android. crbug.com/468762
#if BUILDFLAG(IS_ANDROID) && defined(ADDRESS_SANITIZER)
#define MAYBE_TestAllSampleRates
#else
#define MAYBE_TestAllSampleRates
#endif
TEST_P(AudioProcessorTestMultichannelAndFormat, MAYBE_TestAllSampleRates) {}

TEST_F(AudioProcessorTest, StartStopAecDump) {}

TEST_F(AudioProcessorTest, StartAecDumpDuringOngoingAecDump) {}

TEST_P(AudioProcessorTestMultichannelAndFormat, TestStereoAudio) {}

struct AudioProcessorDefaultOutputFormatTest
    : public ::testing::Test,
      public ::testing::WithParamInterface<std::tuple<bool, int>> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(AudioProcessorDefaultOutputFormatTest, GetDefaultOutputFormat) {}

// Ensure that discrete channel layouts do not crash with audio processing
// enabled.
TEST_F(AudioProcessorTest, DiscreteChannelLayout) {}

class AudioProcessorPlayoutTest : public AudioProcessorTest {};

TEST_F(AudioProcessorPlayoutTest, OnPlayoutData_ForwardsDataToWebrtcApm) {}

TEST_F(AudioProcessorPlayoutTest, OnPlayoutData_BuffersPlayout) {}

TEST_F(AudioProcessorPlayoutTest, OnPlayoutData_HandlesVariableInputSize) {}

TEST_F(AudioProcessorPlayoutTest, OnPlayoutData_HandlesSampleRateChange) {}

// When audio processing is performed, processed audio should be delivered as
// soon as 10 ms of audio has been received.
TEST(AudioProcessorCallbackTest,
     ProcessedAudioIsDeliveredAsSoonAsPossibleWithShortBuffers) {}

// When audio processing is performed, input containing 10 ms several times over
// should trigger a comparable number of processing callbacks.
TEST(AudioProcessorCallbackTest,
     ProcessedAudioIsDeliveredAsSoonAsPossibleWithLongBuffers) {}

// When no audio processing is performed, audio is delivered immediately. Note
// that unlike the other cases, unprocessed audio input of less than 10 ms is
// forwarded directly instead of collecting chunks of 10 ms.
TEST(AudioProcessorCallbackTest,
     UnprocessedAudioIsDeliveredImmediatelyWithShortBuffers) {}

// When no audio processing is performed, audio is delivered immediately. Chunks
// greater than 10 ms are delivered in chunks of 10 ms.
TEST(AudioProcessorCallbackTest,
     UnprocessedAudioIsDeliveredImmediatelyWithLongBuffers) {}

class ApmTellsIfPlayoutReferenceIsNeededParametrizedTest
    : public ::testing::TestWithParam<bool> {};

// Checks that, when all the audio processing settings are disabled, APM does
// not need the playout reference.
TEST_P(ApmTellsIfPlayoutReferenceIsNeededParametrizedTest,
       DoesNotNeedPlayoutReference) {}

// Checks that, with echo cancellation, APM always needs the playout reference.
#if BUILDFLAG(IS_IOS)
#define MAYBE_NeedsPlayoutReference
#else
#define MAYBE_NeedsPlayoutReference
#endif
// TODO: This test is disabled for ios-blink platform as per the discussion on
// bug https://crbug.com/1417474
TEST_P(ApmTellsIfPlayoutReferenceIsNeededParametrizedTest,
       MAYBE_NeedsPlayoutReference) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace media