Remove testonly from unpack_aecdump.

This CL duplicates a few lines of utility code from
//modules/audio_processing:audioproc_test_utils (which contains more
testonly things) and allows the possibility to remove testonly from
the unpack_aecdump tool.

Bug: b/237526033
Change-Id: If2e1dd4cc825429c496091cf8640c67069fb6e6f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/267701
Reviewed-by: Per Åhgren <peah@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37437}
This commit is contained in:
Mirko Bonadei 2022-07-05 10:16:11 +02:00 committed by WebRTC LUCI CQ
parent 6939f63ca1
commit 2ad75b3956
4 changed files with 71 additions and 85 deletions

View file

@ -17,24 +17,6 @@
namespace webrtc {
RawFile::RawFile(const std::string& filename)
: file_handle_(fopen(filename.c_str(), "wb")) {}
RawFile::~RawFile() {
fclose(file_handle_);
}
void RawFile::WriteSamples(const int16_t* samples, size_t num_samples) {
#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
#error "Need to convert samples to little-endian when writing to PCM file"
#endif
fwrite(samples, sizeof(*samples), num_samples, file_handle_);
}
void RawFile::WriteSamples(const float* samples, size_t num_samples) {
fwrite(samples, sizeof(*samples), num_samples, file_handle_);
}
ChannelBufferWavReader::ChannelBufferWavReader(std::unique_ptr<WavReader> file)
: file_(std::move(file)) {}
@ -86,40 +68,6 @@ void ChannelBufferVectorWriter::Write(const ChannelBuffer<float>& buffer) {
output_->data() + old_size);
}
void WriteIntData(const int16_t* data,
size_t length,
WavWriter* wav_file,
RawFile* raw_file) {
if (wav_file) {
wav_file->WriteSamples(data, length);
}
if (raw_file) {
raw_file->WriteSamples(data, length);
}
}
void WriteFloatData(const float* const* data,
size_t samples_per_channel,
size_t num_channels,
WavWriter* wav_file,
RawFile* raw_file) {
size_t length = num_channels * samples_per_channel;
std::unique_ptr<float[]> buffer(new float[length]);
Interleave(data, samples_per_channel, num_channels, buffer.get());
if (raw_file) {
raw_file->WriteSamples(buffer.get(), length);
}
// TODO(aluebs): Use ScaleToInt16Range() from audio_util
for (size_t i = 0; i < length; ++i) {
buffer[i] = buffer[i] > 0
? buffer[i] * std::numeric_limits<int16_t>::max()
: -buffer[i] * std::numeric_limits<int16_t>::min();
}
if (wav_file) {
wav_file->WriteSamples(buffer.get(), length);
}
}
FILE* OpenFile(const std::string& filename, const char* mode) {
FILE* file = fopen(filename.c_str(), mode);
if (!file) {

View file

@ -29,21 +29,6 @@ namespace webrtc {
static const AudioProcessing::Error kNoErr = AudioProcessing::kNoError;
#define EXPECT_NOERR(expr) EXPECT_EQ(kNoErr, (expr))
class RawFile final {
public:
explicit RawFile(const std::string& filename);
~RawFile();
RawFile(const RawFile&) = delete;
RawFile& operator=(const RawFile&) = delete;
void WriteSamples(const int16_t* samples, size_t num_samples);
void WriteSamples(const float* samples, size_t num_samples);
private:
FILE* file_handle_;
};
// Encapsulates samples and metadata for an integer frame.
struct Int16FrameData {
// Max data size that matches the data size of the AudioFrame class, providing
@ -126,17 +111,6 @@ class ChannelBufferVectorWriter final {
std::vector<float>* output_;
};
void WriteIntData(const int16_t* data,
size_t length,
WavWriter* wav_file,
RawFile* raw_file);
void WriteFloatData(const float* const* data,
size_t samples_per_channel,
size_t num_channels,
WavWriter* wav_file,
RawFile* raw_file);
// Exits on failure; do not use in unit tests.
FILE* OpenFile(const std::string& filename, const char* mode);

View file

@ -574,7 +574,6 @@ if (rtc_include_tests) {
rtc_executable("unpack_aecdump") {
visibility = [ "*" ]
testonly = true
sources = [ "unpack_aecdump/unpack.cc" ]
deps = [
@ -584,11 +583,12 @@ if (rtc_include_tests) {
"../modules/audio_processing:audioproc_debug_proto",
"../modules/audio_processing:audioproc_debug_proto",
"../modules/audio_processing:audioproc_protobuf_utils",
"../modules/audio_processing:audioproc_test_utils",
"../rtc_base:checks",
"../rtc_base:ignore_wundef",
"../rtc_base:macromagic",
"../rtc_base:protobuf_utils",
"../rtc_base:stringutils",
"../rtc_base/system:arch",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
]

View file

@ -25,11 +25,13 @@
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "api/function_view.h"
#include "common_audio/include/audio_util.h"
#include "common_audio/wav_file.h"
#include "modules/audio_processing/test/protobuf_utils.h"
#include "modules/audio_processing/test/test_utils.h"
#include "rtc_base/checks.h"
#include "rtc_base/ignore_wundef.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/system/arch.h"
RTC_PUSH_IGNORING_WUNDEF()
#include "modules/audio_processing/debug.pb.h"
@ -103,15 +105,77 @@ using audioproc::ReverseStream;
using audioproc::Stream;
namespace {
class RawFile final {
public:
explicit RawFile(const std::string& filename)
: file_handle_(fopen(filename.c_str(), "wb")) {}
~RawFile() { fclose(file_handle_); }
RawFile(const RawFile&) = delete;
RawFile& operator=(const RawFile&) = delete;
void WriteSamples(const int16_t* samples, size_t num_samples) {
#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
#error "Need to convert samples to little-endian when writing to PCM file"
#endif
fwrite(samples, sizeof(*samples), num_samples, file_handle_);
}
void WriteSamples(const float* samples, size_t num_samples) {
fwrite(samples, sizeof(*samples), num_samples, file_handle_);
}
private:
FILE* file_handle_;
};
void WriteIntData(const int16_t* data,
size_t length,
WavWriter* wav_file,
RawFile* raw_file) {
if (wav_file) {
wav_file->WriteSamples(data, length);
}
if (raw_file) {
raw_file->WriteSamples(data, length);
}
}
void WriteFloatData(const float* const* data,
size_t samples_per_channel,
size_t num_channels,
WavWriter* wav_file,
RawFile* raw_file) {
size_t length = num_channels * samples_per_channel;
std::unique_ptr<float[]> buffer(new float[length]);
Interleave(data, samples_per_channel, num_channels, buffer.get());
if (raw_file) {
raw_file->WriteSamples(buffer.get(), length);
}
// TODO(aluebs): Use ScaleToInt16Range() from audio_util
for (size_t i = 0; i < length; ++i) {
buffer[i] = buffer[i] > 0
? buffer[i] * std::numeric_limits<int16_t>::max()
: -buffer[i] * std::numeric_limits<int16_t>::min();
}
if (wav_file) {
wav_file->WriteSamples(buffer.get(), length);
}
}
// Exits on failure; do not use in unit tests.
FILE* OpenFile(const std::string& filename, const char* mode) {
FILE* file = fopen(filename.c_str(), mode);
RTC_CHECK(file) << "Unable to open file " << filename;
return file;
}
void WriteData(const void* data,
size_t size,
FILE* file,
const std::string& filename) {
if (fwrite(data, size, 1, file) != 1) {
printf("Error when writing to %s\n", filename.c_str());
exit(1);
}
RTC_CHECK_EQ(fwrite(data, size, 1, file), 1)
<< "Error when writing to " << filename.c_str();
}
void WriteCallOrderData(const bool render_call,