|
MPD
|
00001 /* 00002 * Copyright (C) 2003-2010 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 (*tag)(struct encoder *encoder, const struct tag *tag, 00054 GError **error); 00055 00056 bool (*write)(struct encoder *encoder, 00057 const void *data, size_t length, 00058 GError **error); 00059 00060 size_t (*read)(struct encoder *encoder, void *dest, size_t length); 00061 00062 const char *(*get_mime_type)(struct encoder *encoder); 00063 }; 00064 00069 static inline void 00070 encoder_struct_init(struct encoder *encoder, 00071 const struct encoder_plugin *plugin) 00072 { 00073 encoder->plugin = plugin; 00074 } 00075 00084 static inline struct encoder * 00085 encoder_init(const struct encoder_plugin *plugin, 00086 const struct config_param *param, GError **error) 00087 { 00088 return plugin->init(param, error); 00089 } 00090 00096 static inline void 00097 encoder_finish(struct encoder *encoder) 00098 { 00099 encoder->plugin->finish(encoder); 00100 } 00101 00113 static inline bool 00114 encoder_open(struct encoder *encoder, struct audio_format *audio_format, 00115 GError **error) 00116 { 00117 return encoder->plugin->open(encoder, audio_format, error); 00118 } 00119 00126 static inline void 00127 encoder_close(struct encoder *encoder) 00128 { 00129 if (encoder->plugin->close != NULL) 00130 encoder->plugin->close(encoder); 00131 } 00132 00141 static inline bool 00142 encoder_flush(struct encoder *encoder, GError **error) 00143 { 00144 /* this method is optional */ 00145 return encoder->plugin->flush != NULL 00146 ? encoder->plugin->flush(encoder, error) 00147 : true; 00148 } 00149 00158 static inline bool 00159 encoder_tag(struct encoder *encoder, const struct tag *tag, GError **error) 00160 { 00161 /* this method is optional */ 00162 return encoder->plugin->tag != NULL 00163 ? encoder->plugin->tag(encoder, tag, error) 00164 : true; 00165 } 00166 00176 static inline bool 00177 encoder_write(struct encoder *encoder, const void *data, size_t length, 00178 GError **error) 00179 { 00180 return encoder->plugin->write(encoder, data, length, error); 00181 } 00182 00191 static inline size_t 00192 encoder_read(struct encoder *encoder, void *dest, size_t length) 00193 { 00194 return encoder->plugin->read(encoder, dest, length); 00195 } 00196 00203 static inline const char * 00204 encoder_get_mime_type(struct encoder *encoder) 00205 { 00206 /* this method is optional */ 00207 return encoder->plugin->get_mime_type != NULL 00208 ? encoder->plugin->get_mime_type(encoder) 00209 : NULL; 00210 } 00211 00212 #endif
1.7.3