test/run_convert: move code to RunConvert()

This commit is contained in:
Max Kellermann 2021-03-08 16:41:46 +01:00
parent e227596c20
commit 3fb25d4062

View File

@ -101,18 +101,9 @@ public:
} }
}; };
int static void
main(int argc, char **argv) RunConvert(PcmConvert &convert, size_t in_frame_size)
try { {
const auto c = ParseCommandLine(argc, argv);
SetLogThreshold(c.verbose ? LogLevel::DEBUG : LogLevel::INFO);
const GlobalInit init(c.config_path);
const size_t in_frame_size = c.in_audio_format.GetFrameSize();
PcmConvert state(c.in_audio_format, c.out_audio_format);
StaticFifoBuffer<uint8_t, 4096> buffer; StaticFifoBuffer<uint8_t, 4096> buffer;
while (true) { while (true) {
@ -136,20 +127,32 @@ try {
buffer.Consume(src.size); buffer.Consume(src.size);
auto output = state.Convert({src.data, src.size}); auto output = convert.Convert({src.data, src.size});
[[maybe_unused]] ssize_t ignored = write(1, output.data, [[maybe_unused]] ssize_t ignored = write(1, output.data,
output.size); output.size);
} }
while (true) { while (true) {
auto output = state.Flush(); auto output = convert.Flush();
if (output.IsNull()) if (output.IsNull())
break; break;
[[maybe_unused]] ssize_t ignored = write(1, output.data, [[maybe_unused]] ssize_t ignored = write(1, output.data,
output.size); output.size);
} }
}
int
main(int argc, char **argv)
try {
const auto c = ParseCommandLine(argc, argv);
SetLogThreshold(c.verbose ? LogLevel::DEBUG : LogLevel::INFO);
const GlobalInit init(c.config_path);
PcmConvert state(c.in_audio_format, c.out_audio_format);
RunConvert(state, c.in_audio_format.GetFrameSize());
return EXIT_SUCCESS; return EXIT_SUCCESS;
} catch (...) { } catch (...) {