#include "third_party/blink/renderer/modules/mediastream/media_stream_constraints_util_audio.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "media/base/audio_parameters.h"
#include "media/base/media_switches.h"
#include "media/media_buildflags.h"
#include "media/webrtc/constants.h"
#include "media/webrtc/webrtc_features.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink-forward.h"
#include "third_party/blink/public/platform/modules/mediastream/web_platform_media_stream_source.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/core/testing/sim/sim_test.h"
#include "third_party/blink/renderer/modules/mediastream/local_media_stream_audio_source.h"
#include "third_party/blink/renderer/modules/mediastream/media_constraints.h"
#include "third_party/blink/renderer/modules/mediastream/mock_constraint_factory.h"
#include "third_party/blink/renderer/modules/mediastream/processed_local_audio_source.h"
#include "third_party/blink/renderer/modules/webrtc/webrtc_audio_device_impl.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_source.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/webrtc/rtc_base/ref_counted_object.h"
namespace blink {
AudioCaptureSettings;
AudioProcessingProperties;
EchoCancellationType;
ProcessingType;
namespace {
BoolSetFunction;
StringSetFunction;
MockFactoryAccessor;
const BoolSetFunction kBoolSetFunctions[] = …;
const MockFactoryAccessor kFactoryAccessors[] = …;
const bool kBoolValues[] = …;
const int kMinChannels = …;
AudioSettingsBoolMembers;
AudioPropertiesBoolMembers;
template <typename T>
static bool Contains(const WTF::Vector<T>& vector, T value) { … }
}
class MediaStreamConstraintsUtilAudioTestBase : public SimTest { … };
class MediaStreamConstraintsUtilAudioTest
: public MediaStreamConstraintsUtilAudioTestBase,
public testing::WithParamInterface<std::string> { … };
enum class ChromeWideAecExperiment { … };
class MediaStreamConstraintsRemoteAPMTest
: public MediaStreamConstraintsUtilAudioTestBase,
public testing::WithParamInterface<
std::tuple<std::string, ChromeWideAecExperiment>> { … };
TEST_P(MediaStreamConstraintsUtilAudioTest, Unconstrained) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, SingleBoolConstraint) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, SampleSize) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, Channels) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, MultiChannelEchoCancellation) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, ChannelsWithSource) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, SampleRate) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, SampleRateWithSource) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, Latency) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, LatencyWithSource) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, ExactArbitraryDeviceID) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, IdealArbitraryDeviceID) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, ExactValidDeviceID) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, ExactGroupID) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithWebRtc) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithSystem) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, GoogEchoCancellationWithWebRtc) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, GoogEchoCancellationWithSystem) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, ContradictoryEchoCancellation) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest,
EchoCancellationAndSingleBoolConstraint) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest,
ReconfigurationSystemEchoCancellation) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, VoiceIsolationControl) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedCompatibleConstraints) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest,
AdvancedConflictingMiddleConstraints) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, AdvancedConflictingLastConstraint) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, NoDevicesNoConstraints) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, NoDevicesWithConstraints) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, SourceWithNoAudioProcessing) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, SourceWithAudioProcessing) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, UsedAndUnusedSources) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest, ExperimentalEcWithSource) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest,
SelectEligibleSettingsAudioDeviceCapture_NoEligibleDevices) { … }
TEST_P(MediaStreamConstraintsUtilAudioTest,
SelectEligibleSettingsAudioDeviceCapture_IncludesEligibleDevices) { … }
TEST_P(MediaStreamConstraintsRemoteAPMTest, DeviceSampleRate) { … }
TEST_P(MediaStreamConstraintsRemoteAPMTest,
WebRtcSampleRateButNotDeviceSampleRate) { … }
#if BUILDFLAG(CHROME_WIDE_ECHO_CANCELLATION)
class MediaStreamConstraintsRemoteAPMSampleRateRestrictionTest
: public MediaStreamConstraintsUtilAudioTestBase,
public testing::WithParamInterface<bool> { … };
TEST_P(MediaStreamConstraintsRemoteAPMSampleRateRestrictionTest,
ToggleNondivisibleSampleRatesParameter) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
TEST_P(MediaStreamConstraintsUtilAudioTest, LatencyConstraint) { … }
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(CHROME_WIDE_ECHO_CANCELLATION)
INSTANTIATE_TEST_SUITE_P(…);
#else
INSTANTIATE_TEST_SUITE_P(
All,
MediaStreamConstraintsRemoteAPMTest,
testing::Combine(testing::Values("",
blink::kMediaStreamSourceTab,
blink::kMediaStreamSourceSystem,
blink::kMediaStreamSourceDesktop),
testing::Values(ChromeWideAecExperiment::kDisabled)));
#endif
}