Delete TestAudioDeviceModule methods using rtc::PlatformFile
Bug: webrtc:6463 Change-Id: I5d1d9e9036b5e745d5b37c971de91b1b38fdd368 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/141666 Reviewed-by: Henrik Grunell <henrikg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28255}
This commit is contained in:
parent
08fa953711
commit
44bc19b0f8
@ -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<WavReader>(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<WavWriter>(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::Capturer>
|
||||
TestAudioDeviceModule::CreateWavFileReader(rtc::PlatformFile file,
|
||||
int sampling_frequency_in_hz,
|
||||
int num_channels) {
|
||||
return absl::make_unique<WavFileReader>(file, sampling_frequency_in_hz,
|
||||
num_channels, false);
|
||||
}
|
||||
|
||||
std::unique_ptr<TestAudioDeviceModule::Capturer>
|
||||
TestAudioDeviceModule::CreateWavFileReader(rtc::PlatformFile file,
|
||||
bool repeat) {
|
||||
WavReader reader(file);
|
||||
int sampling_frequency_in_hz = reader.sample_rate();
|
||||
int num_channels = rtc::checked_cast<int>(reader.num_channels());
|
||||
return absl::make_unique<WavFileReader>(file, sampling_frequency_in_hz,
|
||||
num_channels, repeat);
|
||||
}
|
||||
|
||||
std::unique_ptr<TestAudioDeviceModule::Renderer>
|
||||
TestAudioDeviceModule::CreateWavFileWriter(rtc::PlatformFile file,
|
||||
int sampling_frequency_in_hz,
|
||||
int num_channels) {
|
||||
return absl::make_unique<WavFileWriter>(file, sampling_frequency_in_hz,
|
||||
num_channels);
|
||||
}
|
||||
|
||||
std::unique_ptr<TestAudioDeviceModule::Renderer>
|
||||
TestAudioDeviceModule::CreateBoundedWavFileWriter(rtc::PlatformFile file,
|
||||
int sampling_frequency_in_hz,
|
||||
int num_channels) {
|
||||
return absl::make_unique<BoundedWavFileWriter>(file, sampling_frequency_in_hz,
|
||||
num_channels);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -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<Capturer> 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<Capturer> CreateWavFileReader(rtc::PlatformFile file,
|
||||
bool repeat = false);
|
||||
|
||||
// Returns a Renderer instance that writes its data to a file.
|
||||
static std::unique_ptr<Renderer> 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<Renderer> 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;
|
||||
|
||||
|
||||
@ -24,49 +24,6 @@ namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
void RunTestViaRtcPlatformFileAPI(
|
||||
rtc::ArrayView<const int16_t> input_samples,
|
||||
rtc::ArrayView<const int16_t> 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<TestAudioDeviceModule::Renderer> writer =
|
||||
TestAudioDeviceModule::CreateBoundedWavFileWriter(file, 800);
|
||||
|
||||
for (size_t i = 0; i < input_samples.size(); i += kSamplesPerFrame) {
|
||||
EXPECT_TRUE(writer->Render(rtc::ArrayView<const int16_t>(
|
||||
&input_samples[i],
|
||||
std::min(kSamplesPerFrame, input_samples.size() - i))));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto file = rtc::OpenPlatformFile(output_filename);
|
||||
WavReader reader(file);
|
||||
std::vector<int16_t> 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<int16_t>& input_samples,
|
||||
const std::vector<int16_t>& 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<int16_t> kInputSamples = {
|
||||
0, 0, 0, 0, 3, 0, 0, 0, 0, 3, -13222, -7, -3525, 5787, -25247, 8};
|
||||
static const std::vector<int16_t> kExpectedSamples(kInputSamples.begin() + 10,
|
||||
kInputSamples.end());
|
||||
RunTestViaRtcPlatformFileAPI(kInputSamples, kExpectedSamples, 8);
|
||||
}
|
||||
|
||||
TEST(BoundedWavFileWriterTest, NegativeStartSilence) {
|
||||
static const std::vector<int16_t> kInputSamples = {
|
||||
0, -4, -6, 0, 3, 0, 0, 0, 0, 3, -13222, -7, -3525, 5787, -25247, 8};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user