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.
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user