mixer_api: moved functions to mixer_control.c
mixer_control.h should provide the functions needed to manipulate a mixer, without exposing the internal mixer API (which is provided by mixer_api.h).
This commit is contained in:
		| @@ -602,6 +602,7 @@ test_run_output_SOURCES = test/run_output.c \ | |||||||
| 	src/output_init.c src/output_list.c \ | 	src/output_init.c src/output_list.c \ | ||||||
| 	$(ENCODER_SRC) \ | 	$(ENCODER_SRC) \ | ||||||
| 	src/mixer_api.c \ | 	src/mixer_api.c \ | ||||||
|  | 	src/mixer_control.c \ | ||||||
| 	$(MIXER_SRC) \ | 	$(MIXER_SRC) \ | ||||||
| 	$(OUTPUT_SRC) | 	$(OUTPUT_SRC) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,7 +23,6 @@ | |||||||
| #include "output_internal.h" | #include "output_internal.h" | ||||||
| #include "output_plugin.h" | #include "output_plugin.h" | ||||||
| #include "output_all.h" | #include "output_all.h" | ||||||
| #include "mixer_api.h" |  | ||||||
| #include "conf.h" | #include "conf.h" | ||||||
|  |  | ||||||
| #include <glib.h> | #include <glib.h> | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ | |||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #include "mixer_all.h" | #include "mixer_all.h" | ||||||
| #include "mixer_api.h" | #include "mixer_control.h" | ||||||
| #include "output_all.h" | #include "output_all.h" | ||||||
| #include "output_plugin.h" | #include "output_plugin.h" | ||||||
| #include "output_internal.h" | #include "output_internal.h" | ||||||
|   | |||||||
| @@ -26,58 +26,3 @@ | |||||||
|  |  | ||||||
| #undef G_LOG_DOMAIN | #undef G_LOG_DOMAIN | ||||||
| #define G_LOG_DOMAIN "mixer" | #define G_LOG_DOMAIN "mixer" | ||||||
|  |  | ||||||
| static bool mixers_enabled = true; |  | ||||||
|  |  | ||||||
| void mixer_disable_all(void) |  | ||||||
| { |  | ||||||
| 	g_debug("mixer api is disabled\n"); |  | ||||||
| 	mixers_enabled = false; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| struct mixer * |  | ||||||
| mixer_new(const struct mixer_plugin *plugin, const struct config_param *param) |  | ||||||
| { |  | ||||||
| 	struct mixer *mixer; |  | ||||||
|  |  | ||||||
| 	//mixers are disabled (by using software volume) |  | ||||||
| 	if (!mixers_enabled) { |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
| 	assert(plugin != NULL); |  | ||||||
|  |  | ||||||
| 	mixer = plugin->init(param); |  | ||||||
|  |  | ||||||
| 	assert(mixer == NULL || mixer->plugin == plugin); |  | ||||||
|  |  | ||||||
| 	return mixer; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void |  | ||||||
| mixer_free(struct mixer *mixer) |  | ||||||
| { |  | ||||||
| 	if (!mixer) { |  | ||||||
| 		return; |  | ||||||
| 	} |  | ||||||
| 	assert(mixer->plugin != NULL); |  | ||||||
|  |  | ||||||
| 	mixer->plugin->finish(mixer); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool mixer_open(struct mixer *mixer) |  | ||||||
| { |  | ||||||
| 	if (!mixer) { |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| 	assert(mixer->plugin != NULL); |  | ||||||
| 	return mixer->plugin->open(mixer); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void mixer_close(struct mixer *mixer) |  | ||||||
| { |  | ||||||
| 	if (!mixer) { |  | ||||||
| 		return; |  | ||||||
| 	} |  | ||||||
| 	assert(mixer->plugin != NULL); |  | ||||||
| 	mixer->plugin->close(mixer); |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -40,27 +40,4 @@ mixer_init(struct mixer *mixer, const struct mixer_plugin *plugin) | |||||||
| 	mixer->plugin = plugin; | 	mixer->plugin = plugin; | ||||||
| } | } | ||||||
|  |  | ||||||
| struct mixer * |  | ||||||
| mixer_new(const struct mixer_plugin *plugin, const struct config_param *param); |  | ||||||
|  |  | ||||||
| void |  | ||||||
| mixer_free(struct mixer *mixer); |  | ||||||
|  |  | ||||||
| bool mixer_open(struct mixer *mixer); |  | ||||||
| void mixer_close(struct mixer *mixer); |  | ||||||
|  |  | ||||||
| static inline int |  | ||||||
| mixer_get_volume(struct mixer *mixer) |  | ||||||
| { |  | ||||||
| 	return mixer->plugin->get_volume(mixer); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static inline bool |  | ||||||
| mixer_set_volume(struct mixer *mixer, unsigned volume) |  | ||||||
| { |  | ||||||
| 	return mixer->plugin->set_volume(mixer, volume); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void mixer_disable_all(void); |  | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -20,4 +20,80 @@ | |||||||
| #include "mixer_control.h" | #include "mixer_control.h" | ||||||
| #include "mixer_api.h" | #include "mixer_api.h" | ||||||
|  |  | ||||||
|  | #include <glib.h> | ||||||
|  |  | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
|  | #include <stddef.h> | ||||||
|  |  | ||||||
|  | #undef G_LOG_DOMAIN | ||||||
|  | #define G_LOG_DOMAIN "mixer" | ||||||
|  |  | ||||||
|  | static bool mixers_enabled = true; | ||||||
|  |  | ||||||
|  | void | ||||||
|  | mixer_disable_all(void) | ||||||
|  | { | ||||||
|  | 	g_debug("mixer api is disabled"); | ||||||
|  | 	mixers_enabled = false; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | struct mixer * | ||||||
|  | mixer_new(const struct mixer_plugin *plugin, const struct config_param *param) | ||||||
|  | { | ||||||
|  | 	struct mixer *mixer; | ||||||
|  |  | ||||||
|  | 	//mixers are disabled (by using software volume) | ||||||
|  | 	if (!mixers_enabled) { | ||||||
|  | 		return NULL; | ||||||
|  | 	} | ||||||
|  | 	assert(plugin != NULL); | ||||||
|  |  | ||||||
|  | 	mixer = plugin->init(param); | ||||||
|  |  | ||||||
|  | 	assert(mixer == NULL || mixer->plugin == plugin); | ||||||
|  |  | ||||||
|  | 	return mixer; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void | ||||||
|  | mixer_free(struct mixer *mixer) | ||||||
|  | { | ||||||
|  | 	if (!mixer) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	assert(mixer->plugin != NULL); | ||||||
|  |  | ||||||
|  | 	mixer->plugin->finish(mixer); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool | ||||||
|  | mixer_open(struct mixer *mixer) | ||||||
|  | { | ||||||
|  | 	if (!mixer) { | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  | 	assert(mixer->plugin != NULL); | ||||||
|  | 	return mixer->plugin->open(mixer); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void | ||||||
|  | mixer_close(struct mixer *mixer) | ||||||
|  | { | ||||||
|  | 	if (!mixer) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	assert(mixer->plugin != NULL); | ||||||
|  | 	mixer->plugin->close(mixer); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int | ||||||
|  | mixer_get_volume(struct mixer *mixer) | ||||||
|  | { | ||||||
|  | 	return mixer->plugin->get_volume(mixer); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool | ||||||
|  | mixer_set_volume(struct mixer *mixer, unsigned volume) | ||||||
|  | { | ||||||
|  | 	return mixer->plugin->set_volume(mixer, volume); | ||||||
|  | } | ||||||
|   | |||||||
| @@ -17,9 +17,39 @@ | |||||||
|  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | /** \file | ||||||
|  |  * | ||||||
|  |  * Functions which manipulate a #mixer object. | ||||||
|  |  */ | ||||||
|  |  | ||||||
| #ifndef MPD_MIXER_CONTROL_H | #ifndef MPD_MIXER_CONTROL_H | ||||||
| #define MPD_MIXER_CONTROL_H | #define MPD_MIXER_CONTROL_H | ||||||
|  |  | ||||||
| #include <stdbool.h> | #include <stdbool.h> | ||||||
|  |  | ||||||
|  | struct mixer; | ||||||
|  | struct mixer_plugin; | ||||||
|  | struct config_param; | ||||||
|  |  | ||||||
|  | void | ||||||
|  | mixer_disable_all(void); | ||||||
|  |  | ||||||
|  | struct mixer * | ||||||
|  | mixer_new(const struct mixer_plugin *plugin, const struct config_param *param); | ||||||
|  |  | ||||||
|  | void | ||||||
|  | mixer_free(struct mixer *mixer); | ||||||
|  |  | ||||||
|  | bool | ||||||
|  | mixer_open(struct mixer *mixer); | ||||||
|  |  | ||||||
|  | void | ||||||
|  | mixer_close(struct mixer *mixer); | ||||||
|  |  | ||||||
|  | int | ||||||
|  | mixer_get_volume(struct mixer *mixer); | ||||||
|  |  | ||||||
|  | bool | ||||||
|  | mixer_set_volume(struct mixer *mixer, unsigned volume); | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -19,6 +19,7 @@ | |||||||
|  |  | ||||||
| #include "../output_api.h" | #include "../output_api.h" | ||||||
| #include "../mixer_api.h" | #include "../mixer_api.h" | ||||||
|  | #include "mixer_control.h" | ||||||
|  |  | ||||||
| #include <glib.h> | #include <glib.h> | ||||||
| #include <alsa/asoundlib.h> | #include <alsa/asoundlib.h> | ||||||
|   | |||||||
| @@ -19,6 +19,7 @@ | |||||||
|  |  | ||||||
| #include "../output_api.h" | #include "../output_api.h" | ||||||
| #include "../mixer_api.h" | #include "../mixer_api.h" | ||||||
|  | #include "mixer_control.h" | ||||||
|  |  | ||||||
| #include <glib.h> | #include <glib.h> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,6 +19,7 @@ | |||||||
|  |  | ||||||
| #include "../output_api.h" | #include "../output_api.h" | ||||||
| #include "../mixer_api.h" | #include "../mixer_api.h" | ||||||
|  | #include "mixer_control.h" | ||||||
|  |  | ||||||
| #include <glib.h> | #include <glib.h> | ||||||
| #include <pulse/simple.h> | #include <pulse/simple.h> | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ | |||||||
| #include "output_all.h" | #include "output_all.h" | ||||||
| #include "output_internal.h" | #include "output_internal.h" | ||||||
| #include "output_plugin.h" | #include "output_plugin.h" | ||||||
| #include "mixer_api.h" | #include "mixer_control.h" | ||||||
| #include "idle.h" | #include "idle.h" | ||||||
|  |  | ||||||
| bool | bool | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ | |||||||
| #include "pcm_volume.h" | #include "pcm_volume.h" | ||||||
| #include "config.h" | #include "config.h" | ||||||
| #include "output_all.h" | #include "output_all.h" | ||||||
| #include "mixer_api.h" | #include "mixer_control.h" | ||||||
| #include "mixer_all.h" | #include "mixer_all.h" | ||||||
|  |  | ||||||
| #include <glib.h> | #include <glib.h> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann