encoder/Interface: move functions into the struct
This commit is contained in:
parent
362a6e6d46
commit
ae4c189e19
|
@ -37,75 +37,65 @@ struct Encoder {
|
||||||
, open(false)
|
, open(false)
|
||||||
#endif
|
#endif
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees an #Encoder object.
|
||||||
|
*/
|
||||||
|
void Dispose() {
|
||||||
|
assert(!open);
|
||||||
|
|
||||||
|
plugin.finish(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the object. You must call this prior to using it.
|
||||||
|
* Before you free it, you must call Close(). You may open
|
||||||
|
* and close (reuse) one encoder any number of times.
|
||||||
|
*
|
||||||
|
* After this function returns successfully and before the
|
||||||
|
* first encoder_write() call, you should invoke
|
||||||
|
* encoder_read() to obtain the file header.
|
||||||
|
*
|
||||||
|
* @param audio_format the encoder's input audio format; the plugin
|
||||||
|
* may modify the struct to adapt it to its abilities
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool Open(AudioFormat &audio_format, Error &error) {
|
||||||
|
assert(!open);
|
||||||
|
|
||||||
|
bool success = plugin.open(this, audio_format, error);
|
||||||
|
#ifndef NDEBUG
|
||||||
|
open = success;
|
||||||
|
pre_tag = tag = end = false;
|
||||||
|
#endif
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the object. This disables the encoder, and readies
|
||||||
|
* it for reusal by calling Open() again.
|
||||||
|
*/
|
||||||
|
void Close() {
|
||||||
|
assert(open);
|
||||||
|
|
||||||
|
if (plugin.close != nullptr)
|
||||||
|
plugin.close(this);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
open = false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Frees an encoder object.
|
|
||||||
*
|
|
||||||
* @param encoder the encoder
|
|
||||||
*/
|
|
||||||
static inline void
|
|
||||||
encoder_finish(Encoder *encoder)
|
|
||||||
{
|
|
||||||
assert(!encoder->open);
|
|
||||||
|
|
||||||
encoder->plugin.finish(encoder);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens an encoder object. You must call this prior to using it.
|
|
||||||
* Before you free it, you must call encoder_close(). You may open
|
|
||||||
* and close (reuse) one encoder any number of times.
|
|
||||||
*
|
|
||||||
* After this function returns successfully and before the first
|
|
||||||
* encoder_write() call, you should invoke encoder_read() to obtain
|
|
||||||
* the file header.
|
|
||||||
*
|
|
||||||
* @param encoder the encoder
|
|
||||||
* @param audio_format the encoder's input audio format; the plugin
|
|
||||||
* may modify the struct to adapt it to its abilities
|
|
||||||
* @return true on success
|
|
||||||
*/
|
|
||||||
static inline bool
|
|
||||||
encoder_open(Encoder *encoder, AudioFormat &audio_format,
|
|
||||||
Error &error)
|
|
||||||
{
|
|
||||||
assert(!encoder->open);
|
|
||||||
|
|
||||||
bool success = encoder->plugin.open(encoder, audio_format, error);
|
|
||||||
#ifndef NDEBUG
|
|
||||||
encoder->open = success;
|
|
||||||
encoder->pre_tag = encoder->tag = encoder->end = false;
|
|
||||||
#endif
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes an encoder object. This disables the encoder, and readies
|
|
||||||
* it for reusal by calling encoder_open() again.
|
|
||||||
*
|
|
||||||
* @param encoder the encoder
|
|
||||||
*/
|
|
||||||
static inline void
|
|
||||||
encoder_close(Encoder *encoder)
|
|
||||||
{
|
|
||||||
assert(encoder->open);
|
|
||||||
|
|
||||||
if (encoder->plugin.close != nullptr)
|
|
||||||
encoder->plugin.close(encoder);
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
encoder->open = false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends the stream: flushes the encoder object, generate an
|
* Ends the stream: flushes the encoder object, generate an
|
||||||
* end-of-stream marker (if applicable), make everything which might
|
* end-of-stream marker (if applicable), make everything which might
|
||||||
* currently be buffered available by encoder_read().
|
* currently be buffered available by encoder_read().
|
||||||
*
|
*
|
||||||
* After this function has been called, the encoder may not be usable
|
* After this function has been called, the encoder may not be usable
|
||||||
* for more data, and only encoder_read() and encoder_close() can be
|
* for more data, and only encoder_read() and Encoder::Close() can be
|
||||||
* called.
|
* called.
|
||||||
*
|
*
|
||||||
* @param encoder the encoder
|
* @param encoder the encoder
|
||||||
|
|
|
@ -64,7 +64,7 @@ class RecorderOutput {
|
||||||
|
|
||||||
~RecorderOutput() {
|
~RecorderOutput() {
|
||||||
if (encoder != nullptr)
|
if (encoder != nullptr)
|
||||||
encoder_finish(encoder);
|
encoder->Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Initialize(const config_param ¶m, Error &error_r) {
|
bool Initialize(const config_param ¶m, Error &error_r) {
|
||||||
|
@ -175,13 +175,13 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
|
||||||
|
|
||||||
/* open the encoder */
|
/* open the encoder */
|
||||||
|
|
||||||
if (!encoder_open(encoder, audio_format, error)) {
|
if (!encoder->Open(audio_format, error)) {
|
||||||
delete file;
|
delete file;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EncoderToFile(error)) {
|
if (!EncoderToFile(error)) {
|
||||||
encoder_close(encoder);
|
encoder->Close();
|
||||||
delete file;
|
delete file;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ RecorderOutput::Commit(Error &error)
|
||||||
|
|
||||||
/* now really close everything */
|
/* now really close everything */
|
||||||
|
|
||||||
encoder_close(encoder);
|
encoder->Close();
|
||||||
|
|
||||||
if (success && !file->Commit(error))
|
if (success && !file->Commit(error))
|
||||||
success = false;
|
success = false;
|
||||||
|
|
|
@ -346,7 +346,7 @@ static void close_shout_conn(ShoutOutput * sd)
|
||||||
if (encoder_end(sd->encoder, IgnoreError()))
|
if (encoder_end(sd->encoder, IgnoreError()))
|
||||||
write_page(sd, IgnoreError());
|
write_page(sd, IgnoreError());
|
||||||
|
|
||||||
encoder_close(sd->encoder);
|
sd->encoder->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED &&
|
if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED &&
|
||||||
|
@ -362,7 +362,7 @@ my_shout_finish_driver(AudioOutput *ao)
|
||||||
{
|
{
|
||||||
ShoutOutput *sd = (ShoutOutput *)ao;
|
ShoutOutput *sd = (ShoutOutput *)ao;
|
||||||
|
|
||||||
encoder_finish(sd->encoder);
|
sd->encoder->Dispose();
|
||||||
|
|
||||||
delete sd;
|
delete sd;
|
||||||
|
|
||||||
|
@ -416,13 +416,13 @@ my_shout_open_device(AudioOutput *ao, AudioFormat &audio_format,
|
||||||
if (!shout_connect(sd, error))
|
if (!shout_connect(sd, error))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!encoder_open(sd->encoder, audio_format, error)) {
|
if (!sd->encoder->Open(audio_format, error)) {
|
||||||
shout_close(sd->shout_conn);
|
shout_close(sd->shout_conn);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!write_page(sd, error)) {
|
if (!write_page(sd, error)) {
|
||||||
encoder_close(sd->encoder);
|
sd->encoder->Close();
|
||||||
shout_close(sd->shout_conn);
|
shout_close(sd->shout_conn);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ HttpdOutput::~HttpdOutput()
|
||||||
metadata->Unref();
|
metadata->Unref();
|
||||||
|
|
||||||
if (encoder != nullptr)
|
if (encoder != nullptr)
|
||||||
encoder_finish(encoder);
|
encoder->Dispose();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ httpd_output_disable(AudioOutput *ao)
|
||||||
inline bool
|
inline bool
|
||||||
HttpdOutput::OpenEncoder(AudioFormat &audio_format, Error &error)
|
HttpdOutput::OpenEncoder(AudioFormat &audio_format, Error &error)
|
||||||
{
|
{
|
||||||
if (!encoder_open(encoder, audio_format, error))
|
if (!encoder->Open(audio_format, error))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* we have to remember the encoder header, i.e. the first
|
/* we have to remember the encoder header, i.e. the first
|
||||||
|
@ -355,7 +355,7 @@ HttpdOutput::Close()
|
||||||
if (header != nullptr)
|
if (header != nullptr)
|
||||||
header->Unref();
|
header->Unref();
|
||||||
|
|
||||||
encoder_close(encoder);
|
encoder->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -90,7 +90,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!encoder_open(encoder, audio_format, error)) {
|
if (!encoder->Open(audio_format, error)) {
|
||||||
LogError(error, "Failed to open encoder");
|
LogError(error, "Failed to open encoder");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,6 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
encoder_to_stdout(*encoder);
|
encoder_to_stdout(*encoder);
|
||||||
|
|
||||||
encoder_close(encoder);
|
encoder->Close();
|
||||||
encoder_finish(encoder);
|
encoder->Dispose();
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ main(gcc_unused int argc, gcc_unused char **argv)
|
||||||
/* open the encoder */
|
/* open the encoder */
|
||||||
|
|
||||||
AudioFormat audio_format(44100, SampleFormat::S16, 2);
|
AudioFormat audio_format(44100, SampleFormat::S16, 2);
|
||||||
success = encoder_open(encoder, audio_format, IgnoreError());
|
success = encoder->Open(audio_format, IgnoreError());
|
||||||
assert(success);
|
assert(success);
|
||||||
|
|
||||||
encoder_to_stdout(*encoder);
|
encoder_to_stdout(*encoder);
|
||||||
|
@ -108,6 +108,6 @@ main(gcc_unused int argc, gcc_unused char **argv)
|
||||||
|
|
||||||
encoder_to_stdout(*encoder);
|
encoder_to_stdout(*encoder);
|
||||||
|
|
||||||
encoder_close(encoder);
|
encoder->Close();
|
||||||
encoder_finish(encoder);
|
encoder->Dispose();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue