diff options
author | Max Kellermann <max@duempel.org> | 2016-05-04 09:31:21 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2016-05-04 16:32:31 +0200 |
commit | e7edc0264745499609aa22bd19620e15f6ef3e62 (patch) | |
tree | 057402f9c77c5d5e9bf3346ca8cff4499ca444b6 /test | |
parent | 69bf835059cfb8c233979b9988404a65c971e2a5 (diff) |
encoder/Interface: move instance methods to abstract class
Rename struct Encoder to PreparedEncoder, and add a new (abstract)
class Encoder which represents one encoder instance.
Diffstat (limited to 'test')
-rw-r--r-- | test/run_encoder.cxx | 15 | ||||
-rw-r--r-- | test/test_vorbis_encoder.cxx | 22 |
2 files changed, 19 insertions, 18 deletions
diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx index 8341e7ff5..ad4d1444a 100644 --- a/test/run_encoder.cxx +++ b/test/run_encoder.cxx @@ -65,8 +65,8 @@ int main(int argc, char **argv) try { Error error; - const auto encoder = encoder_init(*plugin, block, error); - if (encoder == NULL) { + const auto p_encoder = encoder_init(*plugin, block, error); + if (p_encoder == nullptr) { LogError(error, "Failed to initialize encoder"); return EXIT_FAILURE; } @@ -81,7 +81,8 @@ int main(int argc, char **argv) } } - if (!encoder->Open(audio_format, error)) { + auto *encoder = p_encoder->Open(audio_format, error); + if (encoder == nullptr) { LogError(error, "Failed to open encoder"); return EXIT_FAILURE; } @@ -94,7 +95,7 @@ int main(int argc, char **argv) ssize_t nbytes; while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { - if (!encoder_write(encoder, buffer, nbytes, error)) { + if (!encoder->Write(buffer, nbytes, error)) { LogError(error, "encoder_write() failed"); return EXIT_FAILURE; } @@ -102,15 +103,15 @@ int main(int argc, char **argv) EncoderToOutputStream(os, *encoder); } - if (!encoder_end(encoder, error)) { + if (!encoder->End(error)) { LogError(error, "encoder_flush() failed"); return EXIT_FAILURE; } EncoderToOutputStream(os, *encoder); - encoder->Close(); - encoder->Dispose(); + delete encoder; + p_encoder->Dispose(); return EXIT_SUCCESS; } catch (const std::exception &e) { diff --git a/test/test_vorbis_encoder.cxx b/test/test_vorbis_encoder.cxx index 4989c4f0b..e0ccd5ea6 100644 --- a/test/test_vorbis_encoder.cxx +++ b/test/test_vorbis_encoder.cxx @@ -48,15 +48,15 @@ main(gcc_unused int argc, gcc_unused char **argv) ConfigBlock block; block.AddBlockParam("quality", "5.0", -1); - const auto encoder = encoder_init(*plugin, block, IgnoreError()); - assert(encoder != NULL); + const auto p_encoder = encoder_init(*plugin, block, IgnoreError()); + assert(p_encoder != nullptr); try { /* open the encoder */ AudioFormat audio_format(44100, SampleFormat::S16, 2); - success = encoder->Open(audio_format, IgnoreError()); - assert(success); + auto encoder = p_encoder->Open(audio_format, IgnoreError()); + assert(encoder != nullptr); StdioOutputStream os(stdout); @@ -64,14 +64,14 @@ main(gcc_unused int argc, gcc_unused char **argv) /* write a block of data */ - success = encoder_write(encoder, zero, sizeof(zero), IgnoreError()); + success = encoder->Write(zero, sizeof(zero), IgnoreError()); assert(success); EncoderToOutputStream(os, *encoder); /* write a tag */ - success = encoder_pre_tag(encoder, IgnoreError()); + success = encoder->PreTag(IgnoreError()); assert(success); EncoderToOutputStream(os, *encoder); @@ -85,25 +85,25 @@ main(gcc_unused int argc, gcc_unused char **argv) tag_builder.Commit(tag); } - success = encoder_tag(encoder, tag, IgnoreError()); + success = encoder->SendTag(tag, IgnoreError()); assert(success); EncoderToOutputStream(os, *encoder); /* write another block of data */ - success = encoder_write(encoder, zero, sizeof(zero), IgnoreError()); + success = encoder->Write(zero, sizeof(zero), IgnoreError()); assert(success); /* finish */ - success = encoder_end(encoder, IgnoreError()); + success = encoder->End(IgnoreError()); assert(success); EncoderToOutputStream(os, *encoder); - encoder->Close(); - encoder->Dispose(); + delete encoder; + p_encoder->Dispose(); return EXIT_SUCCESS; } catch (const std::exception &e) { |