From e53ca368a5448291ca2783b8061727635084618f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 23 Oct 2009 10:55:52 +0200 Subject: output_plugin: added methods enable() and disable() With these methods, an output plugin can allocate some global resources only if it is actually enabled. The method enable() is called after daemonization, which allows for more sophisticated resource allocation during that method. --- src/output_plugin.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/output_plugin.h') diff --git a/src/output_plugin.h b/src/output_plugin.h index 13dba0d0..3a9748d4 100644 --- a/src/output_plugin.h +++ b/src/output_plugin.h @@ -66,6 +66,24 @@ struct audio_output_plugin { */ void (*finish)(void *data); + /** + * Enable the device. This may allocate resources, preparing + * for the device to be opened. Enabling a device cannot + * fail: if an error occurs during that, it should be reported + * by the open() method. + * + * @param error_r location to store the error occuring, or + * NULL to ignore errors + * @return true on success, false on error + */ + bool (*enable)(void *data, GError **error_r); + + /** + * Disables the device. It is closed before this method is + * called. + */ + void (*disable)(void *data); + /** * Really open the device. * @@ -149,6 +167,22 @@ ao_plugin_finish(const struct audio_output_plugin *plugin, void *data) plugin->finish(data); } +static inline bool +ao_plugin_enable(const struct audio_output_plugin *plugin, void *data, + GError **error_r) +{ + return plugin->enable != NULL + ? plugin->enable(data, error_r) + : true; +} + +static inline void +ao_plugin_disable(const struct audio_output_plugin *plugin, void *data) +{ + if (plugin->disable != NULL) + plugin->disable(data); +} + static inline bool ao_plugin_open(const struct audio_output_plugin *plugin, void *data, struct audio_format *audio_format, -- cgit v1.2.3