diff --git a/test/run_output.cxx b/test/run_output.cxx index db567cab9..ad00c621f 100644 --- a/test/run_output.cxx +++ b/test/run_output.cxx @@ -39,6 +39,31 @@ #include #include +struct CommandLine { + FromNarrowPath config_path; + + const char *output_name = nullptr; + + AudioFormat audio_format{44100, SampleFormat::S16, 2}; +}; + +static CommandLine +ParseCommandLine(int argc, char **argv) +{ + CommandLine c; + + if (argc < 3 || argc > 4) + throw std::runtime_error("Usage: run_output CONFIG NAME [FORMAT] 3) + c.audio_format = ParseAudioFormat(argv[3], false); + + return c; +} + static std::unique_ptr LoadAudioOutput(const ConfigData &config, EventLoop &event_loop, const char *name) @@ -107,34 +132,23 @@ run_output(AudioOutput &ao, AudioFormat audio_format) int main(int argc, char **argv) try { - if (argc < 3 || argc > 4) { - fprintf(stderr, "Usage: run_output CONFIG NAME [FORMAT] 3) - audio_format = ParseAudioFormat(argv[3], false); + auto ao = LoadAudioOutput(config, io_thread.GetEventLoop(), + c.output_name); /* do it */ - run_output(*ao, audio_format); + run_output(*ao, c.audio_format); /* cleanup and exit */