MPD 0.17~git
src/encoder_plugin.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2011 The Music Player Daemon Project
00003  * http://www.musicpd.org
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #ifndef MPD_ENCODER_PLUGIN_H
00021 #define MPD_ENCODER_PLUGIN_H
00022 
00023 #include <glib.h>
00024 
00025 #include <stdbool.h>
00026 #include <stddef.h>
00027 
00028 struct encoder_plugin;
00029 struct audio_format;
00030 struct config_param;
00031 struct tag;
00032 
00033 struct encoder {
00034         const struct encoder_plugin *plugin;
00035 };
00036 
00037 struct encoder_plugin {
00038         const char *name;
00039 
00040         struct encoder *(*init)(const struct config_param *param,
00041                                 GError **error);
00042 
00043         void (*finish)(struct encoder *encoder);
00044 
00045         bool (*open)(struct encoder *encoder,
00046                      struct audio_format *audio_format,
00047                      GError **error);
00048 
00049         void (*close)(struct encoder *encoder);
00050 
00051         bool (*flush)(struct encoder *encoder, GError **error);
00052 
00053         bool (*pre_tag)(struct encoder *encoder, GError **error);
00054 
00055         bool (*tag)(struct encoder *encoder, const struct tag *tag,
00056                     GError **error);
00057 
00058         bool (*write)(struct encoder *encoder,
00059                       const void *data, size_t length,
00060                       GError **error);
00061 
00062         size_t (*read)(struct encoder *encoder, void *dest, size_t length);
00063 
00064         const char *(*get_mime_type)(struct encoder *encoder);
00065 };
00066 
00071 static inline void
00072 encoder_struct_init(struct encoder *encoder,
00073                     const struct encoder_plugin *plugin)
00074 {
00075         encoder->plugin = plugin;
00076 }
00077 
00086 static inline struct encoder *
00087 encoder_init(const struct encoder_plugin *plugin,
00088              const struct config_param *param, GError **error)
00089 {
00090         return plugin->init(param, error);
00091 }
00092 
00098 static inline void
00099 encoder_finish(struct encoder *encoder)
00100 {
00101         encoder->plugin->finish(encoder);
00102 }
00103 
00115 static inline bool
00116 encoder_open(struct encoder *encoder, struct audio_format *audio_format,
00117              GError **error)
00118 {
00119         return encoder->plugin->open(encoder, audio_format, error);
00120 }
00121 
00128 static inline void
00129 encoder_close(struct encoder *encoder)
00130 {
00131         if (encoder->plugin->close != NULL)
00132                 encoder->plugin->close(encoder);
00133 }
00134 
00143 static inline bool
00144 encoder_flush(struct encoder *encoder, GError **error)
00145 {
00146         /* this method is optional */
00147         return encoder->plugin->flush != NULL
00148                 ? encoder->plugin->flush(encoder, error)
00149                 : true;
00150 }
00151 
00162 static inline bool
00163 encoder_pre_tag(struct encoder *encoder, GError **error)
00164 {
00165         /* this method is optional */
00166         return encoder->plugin->pre_tag != NULL
00167                 ? encoder->plugin->pre_tag(encoder, error)
00168                 : true;
00169 }
00170 
00182 static inline bool
00183 encoder_tag(struct encoder *encoder, const struct tag *tag, GError **error)
00184 {
00185         /* this method is optional */
00186         return encoder->plugin->tag != NULL
00187                 ? encoder->plugin->tag(encoder, tag, error)
00188                 : true;
00189 }
00190 
00200 static inline bool
00201 encoder_write(struct encoder *encoder, const void *data, size_t length,
00202               GError **error)
00203 {
00204         return encoder->plugin->write(encoder, data, length, error);
00205 }
00206 
00215 static inline size_t
00216 encoder_read(struct encoder *encoder, void *dest, size_t length)
00217 {
00218         return encoder->plugin->read(encoder, dest, length);
00219 }
00220 
00227 static inline const char *
00228 encoder_get_mime_type(struct encoder *encoder)
00229 {
00230         /* this method is optional */
00231         return encoder->plugin->get_mime_type != NULL
00232                 ? encoder->plugin->get_mime_type(encoder)
00233                 : NULL;
00234 }
00235 
00236 #endif