chromium/third_party/blink/renderer/modules/mediastream/media_stream_audio_processor_test.cc

// Copyright 2013 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/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/modules/mediastream/media_stream_audio_processor.h"

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

#include <optional>
#include <string>
#include <vector>

#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/aligned_memory.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h"
#include "base/test/mock_callback.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/webrtc/constants.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h"
#include "third_party/blink/renderer/modules/webrtc/webrtc_audio_device_impl.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_processor_options.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/webrtc/api/media_stream_interface.h"
#include "third_party/webrtc/rtc_base/ref_counted_object.h"

_;
AnyNumber;
AtLeast;
Return;

AudioParameters;

AnalogGainController;

namespace blink {
namespace {

MockProcessedCaptureCallback;

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

void ReadDataFromSpeechFile(base::HeapArray<int16_t>& data) {}

}  // namespace

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

class MediaStreamAudioProcessorTestMultichannel
    : public MediaStreamAudioProcessorTest,
      public ::testing::WithParamInterface<bool> {};

// 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(MediaStreamAudioProcessorTestMultichannel, MAYBE_WithAudioProcessing) {}

TEST_F(MediaStreamAudioProcessorTest, 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(MediaStreamAudioProcessorTestMultichannel, MAYBE_TestAllSampleRates) {}

TEST_F(MediaStreamAudioProcessorTest, StartStopAecDump) {}

TEST_P(MediaStreamAudioProcessorTestMultichannel, TestStereoAudio) {}

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

INSTANTIATE_TEST_SUITE_P();

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

// When audio processing is performed, input containing 10 ms several times over
// should trigger a comparable number of processing callbacks.
TEST(MediaStreamAudioProcessorCallbackTest,
     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(MediaStreamAudioProcessorCallbackTest,
     UnprocessedAudioIsDeliveredImmediatelyWithShortBuffers) {}

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

namespace {
scoped_refptr<MediaStreamAudioProcessor> CreateAudioProcessorWithProperties(
    AudioProcessingProperties properties) {}
}  // namespace

TEST(MediaStreamAudioProcessorWouldModifyAudioTest, TrueByDefault) {}

TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     FalseWhenEverythingIsDisabled) {}

TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     FalseWhenOnlyHardwareEffectsAreUsed) {}

#if BUILDFLAG(IS_IOS)
// TODO(https://crbug.com/1417474): Remove legacy iOS case in
// AudioProcessingSettings::NeedWebrtcAudioProcessing().
#define MAYBE_TrueWhenSoftwareEchoCancellationIsEnabled
#else
#define MAYBE_TrueWhenSoftwareEchoCancellationIsEnabled
#endif  // BUILDFLAG(IS_IOS)
TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     MAYBE_TrueWhenSoftwareEchoCancellationIsEnabled) {}

#if BUILDFLAG(IS_IOS)
// TODO(https://crbug.com/1417474): Remove legacy iOS case in
// AudioProcessingSettings::NeedWebrtcAudioProcessing().
#define MAYBE_TrueWhenStereoMirroringIsEnabled
#else
#define MAYBE_TrueWhenStereoMirroringIsEnabled
#endif  // BUILDFLAG(IS_IOS)
TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     MAYBE_TrueWhenStereoMirroringIsEnabled) {}

#if BUILDFLAG(IS_IOS)
// TODO(https://crbug.com/1417474): Remove legacy iOS case in
// AudioProcessingSettings::NeedWebrtcAudioProcessing().
#define MAYBE_TrueWhenGainControlIsEnabled
#else
#define MAYBE_TrueWhenGainControlIsEnabled
#endif  // BUILDFLAG(IS_IOS)
TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     MAYBE_TrueWhenGainControlIsEnabled) {}

#if BUILDFLAG(IS_IOS)
// TODO(https://crbug.com/1417474): Remove legacy iOS case in
// AudioProcessingSettings::NeedWebrtcAudioProcessing().
#define MAYBE_TrueWhenExperimentalEchoCancellationIsEnabled
#else
#define MAYBE_TrueWhenExperimentalEchoCancellationIsEnabled
#endif  // BUILDFLAG(IS_IOS)
// "Experimental echo cancellation" does not map to any real effect, but still
// enables audio processing.
// TODO(https://crbug.com/1269723): Remove the experimental AEC option. This
// test documents *current* behavior, not *desired* behavior.
TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     MAYBE_TrueWhenExperimentalEchoCancellationIsEnabled) {}

TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     TrueWhenNoiseSuppressionIsEnabled) {}

TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     TrueWhenExperimentalNoiseSuppression) {}

TEST(MediaStreamAudioProcessorWouldModifyAudioTest,
     TrueWhenHighpassFilterIsEnabled) {}

}  // namespace blink