diff options
author | Max Kellermann <max@duempel.org> | 2015-12-16 10:24:43 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-12-16 10:24:43 +0100 |
commit | e4a06da14e1184eacd00834aaf05c5457703a7eb (patch) | |
tree | 7d4d168bfd8475e9113b2d9d2e4b8b74c606f092 /test/run_encoder.cxx | |
parent | 36d6ead65cf507948744ee5d8615c8ef20e42f9d (diff) |
fs/io/OutputStream: use C++ exceptions in Write()
Diffstat (limited to 'test/run_encoder.cxx')
-rw-r--r-- | test/run_encoder.cxx | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx index 307d1b73d..cd6a413a2 100644 --- a/test/run_encoder.cxx +++ b/test/run_encoder.cxx @@ -63,60 +63,58 @@ int main(int argc, char **argv) ConfigBlock block; block.AddBlockParam("quality", "5.0", -1); - Error error; - const auto encoder = encoder_init(*plugin, block, error); - if (encoder == NULL) { - LogError(error, "Failed to initialize encoder"); - return EXIT_FAILURE; - } + try { + Error error; + const auto encoder = encoder_init(*plugin, block, error); + if (encoder == NULL) { + LogError(error, "Failed to initialize encoder"); + return EXIT_FAILURE; + } - /* open the encoder */ + /* open the encoder */ - AudioFormat audio_format(44100, SampleFormat::S16, 2); - if (argc > 2) { - if (!audio_format_parse(audio_format, argv[2], false, error)) { - LogError(error, "Failed to parse audio format"); + AudioFormat audio_format(44100, SampleFormat::S16, 2); + if (argc > 2) { + if (!audio_format_parse(audio_format, argv[2], false, error)) { + LogError(error, "Failed to parse audio format"); + return EXIT_FAILURE; + } + } + + if (!encoder->Open(audio_format, error)) { + LogError(error, "Failed to open encoder"); return EXIT_FAILURE; } - } - if (!encoder->Open(audio_format, error)) { - LogError(error, "Failed to open encoder"); - return EXIT_FAILURE; - } + StdioOutputStream os(stdout); - StdioOutputStream os(stdout); + EncoderToOutputStream(os, *encoder); - if (!EncoderToOutputStream(os, *encoder, error)) { - LogError(error); - return EXIT_FAILURE; - } + /* do it */ - /* do it */ + ssize_t nbytes; + while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { + if (!encoder_write(encoder, buffer, nbytes, error)) { + LogError(error, "encoder_write() failed"); + return EXIT_FAILURE; + } - ssize_t nbytes; - while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { - if (!encoder_write(encoder, buffer, nbytes, error)) { - LogError(error, "encoder_write() failed"); - return EXIT_FAILURE; + EncoderToOutputStream(os, *encoder); } - if (!EncoderToOutputStream(os, *encoder, error)) { - LogError(error); + if (!encoder_end(encoder, error)) { + LogError(error, "encoder_flush() failed"); return EXIT_FAILURE; } - } - if (!encoder_end(encoder, error)) { - LogError(error, "encoder_flush() failed"); - return EXIT_FAILURE; - } + EncoderToOutputStream(os, *encoder); - if (!EncoderToOutputStream(os, *encoder, error)) { - LogError(error); + encoder->Close(); + encoder->Dispose(); + + return EXIT_SUCCESS; + } catch (const std::exception &e) { + LogError(e); return EXIT_FAILURE; } - - encoder->Close(); - encoder->Dispose(); } |