diff --git a/modules/audio_device/include/test_audio_device.cc b/modules/audio_device/include/test_audio_device.cc index 08ce8ad12a..e673f82510 100644 --- a/modules/audio_device/include/test_audio_device.cc +++ b/modules/audio_device/include/test_audio_device.cc @@ -275,15 +275,6 @@ class WavFileReader final : public TestAudioDeviceModule::Capturer { num_channels, repeat) {} - WavFileReader(rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels, - bool repeat) - : WavFileReader(absl::make_unique(file), - sampling_frequency_in_hz, - num_channels, - repeat) {} - int SamplingFrequency() const override { return sampling_frequency_in_hz_; } int NumChannels() const override { return num_channels_; } @@ -338,15 +329,6 @@ class WavFileWriter final : public TestAudioDeviceModule::Renderer { sampling_frequency_in_hz, num_channels) {} - WavFileWriter(rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels) - : WavFileWriter(absl::make_unique(file, - sampling_frequency_in_hz, - num_channels), - sampling_frequency_in_hz, - num_channels) {} - int SamplingFrequency() const override { return sampling_frequency_in_hz_; } int NumChannels() const override { return num_channels_; } @@ -384,19 +366,6 @@ class BoundedWavFileWriter : public TestAudioDeviceModule::Renderer { started_writing_(false), trailing_zeros_(0) {} - BoundedWavFileWriter(rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels) - : sampling_frequency_in_hz_(sampling_frequency_in_hz), - wav_writer_(file, sampling_frequency_in_hz, num_channels), - num_channels_(num_channels), - silent_audio_( - TestAudioDeviceModule::SamplesPerFrame(sampling_frequency_in_hz) * - num_channels, - 0), - started_writing_(false), - trailing_zeros_(0) {} - int SamplingFrequency() const override { return sampling_frequency_in_hz_; } int NumChannels() const override { return num_channels_; } @@ -530,38 +499,4 @@ TestAudioDeviceModule::CreateBoundedWavFileWriter(std::string filename, filename, sampling_frequency_in_hz, num_channels); } -std::unique_ptr -TestAudioDeviceModule::CreateWavFileReader(rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels) { - return absl::make_unique(file, sampling_frequency_in_hz, - num_channels, false); -} - -std::unique_ptr -TestAudioDeviceModule::CreateWavFileReader(rtc::PlatformFile file, - bool repeat) { - WavReader reader(file); - int sampling_frequency_in_hz = reader.sample_rate(); - int num_channels = rtc::checked_cast(reader.num_channels()); - return absl::make_unique(file, sampling_frequency_in_hz, - num_channels, repeat); -} - -std::unique_ptr -TestAudioDeviceModule::CreateWavFileWriter(rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels) { - return absl::make_unique(file, sampling_frequency_in_hz, - num_channels); -} - -std::unique_ptr -TestAudioDeviceModule::CreateBoundedWavFileWriter(rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels) { - return absl::make_unique(file, sampling_frequency_in_hz, - num_channels); -} - } // namespace webrtc diff --git a/modules/audio_device/include/test_audio_device.h b/modules/audio_device/include/test_audio_device.h index a3b1b3ac38..f92edf5653 100644 --- a/modules/audio_device/include/test_audio_device.h +++ b/modules/audio_device/include/test_audio_device.h @@ -22,7 +22,6 @@ #include "modules/audio_device/include/audio_device_defines.h" #include "rtc_base/buffer.h" #include "rtc_base/event.h" -#include "rtc_base/platform_file.h" namespace webrtc { @@ -128,36 +127,6 @@ class TestAudioDeviceModule : public AudioDeviceModule { int sampling_frequency_in_hz, int num_channels = 1); - // WavReader and WavWriter creation based on rtc::PlatformFile. - - // Returns a Capturer instance that gets its data from a file. The sample rate - // and channels will be checked against the Wav file. - static std::unique_ptr CreateWavFileReader( - rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels = 1); - - // Returns a Capturer instance that gets its data from a file. - // Automatically detects sample rate and num of channels. - // |repeat| - if true, the file will be replayed from the start when we reach - // the end of file. - static std::unique_ptr CreateWavFileReader(rtc::PlatformFile file, - bool repeat = false); - - // Returns a Renderer instance that writes its data to a file. - static std::unique_ptr CreateWavFileWriter( - rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels = 1); - - // Returns a Renderer instance that writes its data to a WAV file, cutting - // off silence at the beginning (not necessarily perfect silence, see - // kAmplitudeThreshold) and at the end (only actual 0 samples in this case). - static std::unique_ptr CreateBoundedWavFileWriter( - rtc::PlatformFile file, - int sampling_frequency_in_hz, - int num_channels = 1); - int32_t Init() override = 0; int32_t RegisterAudioCallback(AudioTransport* callback) override = 0; diff --git a/modules/audio_device/include/test_audio_device_unittest.cc b/modules/audio_device/include/test_audio_device_unittest.cc index 8038b95350..bc872c6de8 100644 --- a/modules/audio_device/include/test_audio_device_unittest.cc +++ b/modules/audio_device/include/test_audio_device_unittest.cc @@ -24,49 +24,6 @@ namespace webrtc { namespace { -void RunTestViaRtcPlatformFileAPI( - rtc::ArrayView input_samples, - rtc::ArrayView expected_samples, - size_t samples_per_frame) { - const ::testing::TestInfo* const test_info = - ::testing::UnitTest::GetInstance()->current_test_info(); - - const std::string output_filename = - test::OutputPath() + "BoundedWavFileWriterTest_" + test_info->name() + - "_" + std::to_string(std::rand()) + ".wav"; - - static const size_t kSamplesPerFrame = 8; - static const int kSampleRate = kSamplesPerFrame * 100; - EXPECT_EQ(TestAudioDeviceModule::SamplesPerFrame(kSampleRate), - kSamplesPerFrame); - - // Test through rtc::PlatformFile API. - { - auto file = rtc::CreatePlatformFile(output_filename); - std::unique_ptr writer = - TestAudioDeviceModule::CreateBoundedWavFileWriter(file, 800); - - for (size_t i = 0; i < input_samples.size(); i += kSamplesPerFrame) { - EXPECT_TRUE(writer->Render(rtc::ArrayView( - &input_samples[i], - std::min(kSamplesPerFrame, input_samples.size() - i)))); - } - } - - { - auto file = rtc::OpenPlatformFile(output_filename); - WavReader reader(file); - std::vector read_samples(expected_samples.size()); - EXPECT_EQ(expected_samples.size(), - reader.ReadSamples(read_samples.size(), read_samples.data())); - EXPECT_THAT(expected_samples, ::testing::ElementsAreArray(read_samples)); - - EXPECT_EQ(0u, reader.ReadSamples(read_samples.size(), read_samples.data())); - } - - remove(output_filename.c_str()); -} - void RunTest(const std::vector& input_samples, const std::vector& expected_samples, size_t samples_per_frame) { @@ -124,14 +81,6 @@ TEST(BoundedWavFileWriterTest, SomeStartSilence) { RunTest(kInputSamples, kExpectedSamples, 8); } -TEST(BoundedWavFileWriterTest, SomeStartSilenceRtcFile) { - static const std::vector kInputSamples = { - 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, -13222, -7, -3525, 5787, -25247, 8}; - static const std::vector kExpectedSamples(kInputSamples.begin() + 10, - kInputSamples.end()); - RunTestViaRtcPlatformFileAPI(kInputSamples, kExpectedSamples, 8); -} - TEST(BoundedWavFileWriterTest, NegativeStartSilence) { static const std::vector kInputSamples = { 0, -4, -6, 0, 3, 0, 0, 0, 0, 3, -13222, -7, -3525, 5787, -25247, 8};