From ae4c189e191fd83ee1394f0a180e7ca9430e66c9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 8 Jan 2015 19:36:19 +0100 Subject: encoder/Interface: move functions into the struct --- src/encoder/EncoderInterface.hxx | 92 ++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 51 deletions(-) (limited to 'src/encoder') 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 -- cgit v1.2.3