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:
@@ -47,7 +47,8 @@ class RecorderOutput {
|
||||
/**
|
||||
* The configured encoder plugin.
|
||||
*/
|
||||
Encoder *encoder = nullptr;
|
||||
PreparedEncoder *prepared_encoder = nullptr;
|
||||
Encoder *encoder;
|
||||
|
||||
/**
|
||||
* The destination file name.
|
||||
@@ -75,8 +76,8 @@ class RecorderOutput {
|
||||
:base(recorder_output_plugin) {}
|
||||
|
||||
~RecorderOutput() {
|
||||
if (encoder != nullptr)
|
||||
encoder->Dispose();
|
||||
if (prepared_encoder != nullptr)
|
||||
prepared_encoder->Dispose();
|
||||
}
|
||||
|
||||
bool Initialize(const ConfigBlock &block, Error &error_r) {
|
||||
@@ -148,8 +149,8 @@ RecorderOutput::Configure(const ConfigBlock &block, Error &error)
|
||||
|
||||
/* initialize encoder */
|
||||
|
||||
encoder = encoder_init(*encoder_plugin, block, error);
|
||||
if (encoder == nullptr)
|
||||
prepared_encoder = encoder_init(*encoder_plugin, block, error);
|
||||
if (prepared_encoder == nullptr)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -205,7 +206,8 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
|
||||
|
||||
/* open the encoder */
|
||||
|
||||
if (!encoder->Open(audio_format, error)) {
|
||||
encoder = prepared_encoder->Open(audio_format, error);
|
||||
if (encoder == nullptr) {
|
||||
delete file;
|
||||
return false;
|
||||
}
|
||||
@@ -214,7 +216,7 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
|
||||
try {
|
||||
EncoderToFile();
|
||||
} catch (const std::exception &e) {
|
||||
encoder->Close();
|
||||
delete encoder;
|
||||
error.Set(recorder_domain, e.what());
|
||||
return false;
|
||||
}
|
||||
@@ -224,7 +226,7 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
|
||||
|
||||
/* close the encoder for now; it will be opened as
|
||||
soon as we have received a tag */
|
||||
encoder->Close();
|
||||
delete encoder;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -237,19 +239,19 @@ RecorderOutput::Commit(Error &error)
|
||||
|
||||
/* flush the encoder and write the rest to the file */
|
||||
|
||||
bool success = encoder_end(encoder, error);
|
||||
bool success = encoder->End(error);
|
||||
if (success) {
|
||||
try {
|
||||
EncoderToFile();
|
||||
} catch (...) {
|
||||
encoder->Close();
|
||||
delete encoder;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/* now really close everything */
|
||||
|
||||
encoder->Close();
|
||||
delete encoder;
|
||||
|
||||
if (success) {
|
||||
try {
|
||||
@@ -326,7 +328,8 @@ RecorderOutput::ReopenFormat(AllocatedPath &&new_path, Error &error)
|
||||
}
|
||||
|
||||
AudioFormat new_audio_format = effective_audio_format;
|
||||
if (!encoder->Open(new_audio_format, error)) {
|
||||
encoder = prepared_encoder->Open(new_audio_format, error);
|
||||
if (encoder == nullptr) {
|
||||
delete new_file;
|
||||
return false;
|
||||
}
|
||||
@@ -338,7 +341,7 @@ RecorderOutput::ReopenFormat(AllocatedPath &&new_path, Error &error)
|
||||
try {
|
||||
EncoderToOutputStream(*new_file, *encoder);
|
||||
} catch (const std::exception &e) {
|
||||
encoder->Close();
|
||||
delete encoder;
|
||||
delete new_file;
|
||||
error.Set(recorder_domain, e.what());
|
||||
return false;
|
||||
@@ -386,7 +389,7 @@ RecorderOutput::SendTag(const Tag &tag)
|
||||
}
|
||||
|
||||
Error error;
|
||||
if (!encoder_pre_tag(encoder, error)) {
|
||||
if (!encoder->PreTag(error)) {
|
||||
LogError(error);
|
||||
return;
|
||||
}
|
||||
@@ -398,7 +401,7 @@ RecorderOutput::SendTag(const Tag &tag)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!encoder_tag(encoder, tag, error))
|
||||
if (!encoder->SendTag(tag, error))
|
||||
LogError(error);
|
||||
}
|
||||
|
||||
@@ -413,7 +416,7 @@ RecorderOutput::Play(const void *chunk, size_t size, Error &error)
|
||||
return size;
|
||||
}
|
||||
|
||||
if (!encoder_write(encoder, chunk, size, error))
|
||||
if (!encoder->Write(chunk, size, error))
|
||||
return 0;
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user