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:
Max Kellermann
2016-05-04 09:31:21 +02:00
parent 69bf835059
commit e7edc02647
18 changed files with 777 additions and 996 deletions

View File

@@ -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) {