aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-01-08 19:36:19 +0100
committerMax Kellermann <max@duempel.org>2015-01-08 19:36:19 +0100
commitae4c189e191fd83ee1394f0a180e7ca9430e66c9 (patch)
tree15be9475ebefd2a948edb10efec4e88628fc4fdb /src
parent362a6e6d460a3b197db33f0f2f082e0015f23820 (diff)
downloadmpd-ae4c189e191fd83ee1394f0a180e7ca9430e66c9.tar.gz
mpd-ae4c189e191fd83ee1394f0a180e7ca9430e66c9.tar.xz
mpd-ae4c189e191fd83ee1394f0a180e7ca9430e66c9.zip
encoder/Interface: move functions into the struct
Diffstat (limited to '')
-rw-r--r--src/encoder/EncoderInterface.hxx92
-rw-r--r--src/output/plugins/RecorderOutputPlugin.cxx8
-rw-r--r--src/output/plugins/ShoutOutputPlugin.cxx8
-rw-r--r--src/output/plugins/httpd/HttpdOutputPlugin.cxx6
4 files changed, 52 insertions, 62 deletions
diff --git a/src/encoder/EncoderInterface.hxx b/src/encoder/EncoderInterface.hxx
index 165c5eeca..8ee723a63 100644
--- a/src/encoder/EncoderInterface.hxx
+++ b/src/encoder/EncoderInterface.hxx
@@ -37,67 +37,57 @@ struct Encoder {
, 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);
-}
+ /**
+ * Frees an #Encoder object.
+ */
+ void Dispose() {
+ assert(!open);
-/**
- * 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);
+ 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 = encoder->plugin.open(encoder, audio_format, error);
+ bool success = plugin.open(this, audio_format, error);
#ifndef NDEBUG
- encoder->open = success;
- encoder->pre_tag = encoder->tag = encoder->end = false;
+ open = success;
+ pre_tag = tag = end = false;
#endif
- return success;
-}
+ 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);
+ /**
+ * 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
- encoder->open = false;
+ open = false;
#endif
-}
+ }
+};
/**
* Ends the stream: flushes the encoder object, generate an
@@ -105,7 +95,7 @@ encoder_close(Encoder *encoder)
* currently be buffered available by encoder_read().
*
* 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.
*
* @param encoder the encoder
diff --git a/src/output/plugins/RecorderOutputPlugin.cxx b/src/output/plugins/RecorderOutputPlugin.cxx
index fb73f7b6f..f6508e33c 100644
--- a/src/output/plugins/RecorderOutputPlugin.cxx
+++ b/src/output/plugins/RecorderOutputPlugin.cxx
@@ -64,7 +64,7 @@ class RecorderOutput {
~RecorderOutput() {
if (encoder != nullptr)
- encoder_finish(encoder);
+ encoder->Dispose();
}
bool Initialize(const config_param &param, Error &error_r) {
@@ -175,13 +175,13 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
/* open the encoder */
- if (!encoder_open(encoder, audio_format, error)) {
+ if (!encoder->Open(audio_format, error)) {
delete file;
return false;
}
if (!EncoderToFile(error)) {
- encoder_close(encoder);
+ encoder->Close();
delete file;
return false;
}
@@ -199,7 +199,7 @@ RecorderOutput::Commit(Error &error)
/* now really close everything */
- encoder_close(encoder);
+ encoder->Close();
if (success && !file->Commit(error))
success = false;
diff --git a/src/output/plugins/ShoutOutputPlugin.cxx b/src/output/plugins/ShoutOutputPlugin.cxx
index e5d8b23a4..f9070026e 100644
--- a/src/output/plugins/ShoutOutputPlugin.cxx
+++ b/src/output/plugins/ShoutOutputPlugin.cxx
@@ -346,7 +346,7 @@ static void close_shout_conn(ShoutOutput * sd)
if (encoder_end(sd->encoder, IgnoreError()))
write_page(sd, IgnoreError());
- encoder_close(sd->encoder);
+ sd->encoder->Close();
}
if (shout_get_connected(sd->shout_conn) != SHOUTERR_UNCONNECTED &&
@@ -362,7 +362,7 @@ my_shout_finish_driver(AudioOutput *ao)
{
ShoutOutput *sd = (ShoutOutput *)ao;
- encoder_finish(sd->encoder);
+ sd->encoder->Dispose();
delete sd;
@@ -416,13 +416,13 @@ my_shout_open_device(AudioOutput *ao, AudioFormat &audio_format,
if (!shout_connect(sd, error))
return false;
- if (!encoder_open(sd->encoder, audio_format, error)) {
+ if (!sd->encoder->Open(audio_format, error)) {
shout_close(sd->shout_conn);
return false;
}
if (!write_page(sd, error)) {
- encoder_close(sd->encoder);
+ sd->encoder->Close();
shout_close(sd->shout_conn);
return false;
}
diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx
index 811cdaaff..19ee38cd2 100644
--- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx
+++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx
@@ -64,7 +64,7 @@ HttpdOutput::~HttpdOutput()
metadata->Unref();
if (encoder != nullptr)
- encoder_finish(encoder);
+ encoder->Dispose();
}
@@ -295,7 +295,7 @@ httpd_output_disable(AudioOutput *ao)
inline bool
HttpdOutput::OpenEncoder(AudioFormat &audio_format, Error &error)
{
- if (!encoder_open(encoder, audio_format, error))
+ if (!encoder->Open(audio_format, error))
return false;
/* we have to remember the encoder header, i.e. the first
@@ -355,7 +355,7 @@ HttpdOutput::Close()
if (header != nullptr)
header->Unref();
- encoder_close(encoder);
+ encoder->Close();
}
static void