00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00067 static inline void
00068 encoder_struct_init(struct encoder *encoder,
00069 const struct encoder_plugin *plugin)
00070 {
00071 encoder->plugin = plugin;
00072 }
00073
00082 static inline struct encoder *
00083 encoder_init(const struct encoder_plugin *plugin,
00084 const struct config_param *param, GError **error)
00085 {
00086 return plugin->init(param, error);
00087 }
00088
00094 static inline void
00095 encoder_finish(struct encoder *encoder)
00096 {
00097 encoder->plugin->finish(encoder);
00098 }
00099
00111 static inline bool
00112 encoder_open(struct encoder *encoder, struct audio_format *audio_format,
00113 GError **error)
00114 {
00115 return encoder->plugin->open(encoder, audio_format, error);
00116 }
00117
00124 static inline void
00125 encoder_close(struct encoder *encoder)
00126 {
00127 if (encoder->plugin->close != NULL)
00128 encoder->plugin->close(encoder);
00129 }
00130
00139 static inline bool
00140 encoder_flush(struct encoder *encoder, GError **error)
00141 {
00142
00143 return encoder->plugin->flush != NULL
00144 ? encoder->plugin->flush(encoder, error)
00145 : true;
00146 }
00147
00156 static inline bool
00157 encoder_tag(struct encoder *encoder, const struct tag *tag, GError **error)
00158 {
00159
00160 return encoder->plugin->tag != NULL
00161 ? encoder->plugin->tag(encoder, tag, error)
00162 : true;
00163 }
00164
00174 static inline bool
00175 encoder_write(struct encoder *encoder, const void *data, size_t length,
00176 GError **error)
00177 {
00178 return encoder->plugin->write(encoder, data, length, error);
00179 }
00180
00189 static inline size_t
00190 encoder_read(struct encoder *encoder, void *dest, size_t length)
00191 {
00192 return encoder->plugin->read(encoder, dest, length);
00193 }
00194
00195 #endif