mixer_type: moved volume_mixer_type from volume.c
This commit is contained in:
parent
8bd7b5b607
commit
89d4f438c0
@ -94,6 +94,7 @@ mpd_headers = \
|
||||
src/mixer_list.h \
|
||||
src/event_pipe.h \
|
||||
src/mixer_plugin.h \
|
||||
src/mixer_type.h \
|
||||
src/daemon.h \
|
||||
src/normalize.h \
|
||||
src/compress.h \
|
||||
@ -515,6 +516,7 @@ OUTPUT_SRC = \
|
||||
|
||||
MIXER_API_SRC = \
|
||||
src/mixer_control.c \
|
||||
src/mixer_type.c \
|
||||
src/mixer_all.c \
|
||||
src/mixer_api.c
|
||||
|
||||
|
38
src/mixer_type.c
Normal file
38
src/mixer_type.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "mixer_type.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
enum mixer_type
|
||||
mixer_type_parse(const char *input)
|
||||
{
|
||||
assert(input != NULL);
|
||||
|
||||
if (strcmp(input, "none") == 0 || strcmp(input, "disabled") == 0)
|
||||
return MIXER_TYPE_NONE;
|
||||
else if (strcmp(input, "hardware") == 0)
|
||||
return MIXER_TYPE_HARDWARE;
|
||||
else if (strcmp(input, "software") == 0)
|
||||
return MIXER_TYPE_SOFTWARE;
|
||||
else
|
||||
return MIXER_TYPE_UNKNOWN;
|
||||
}
|
47
src/mixer_type.h
Normal file
47
src/mixer_type.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_MIXER_TYPE_H
|
||||
#define MPD_MIXER_TYPE_H
|
||||
|
||||
enum mixer_type {
|
||||
/** parser error */
|
||||
MIXER_TYPE_UNKNOWN,
|
||||
|
||||
/** mixer disabled */
|
||||
MIXER_TYPE_NONE,
|
||||
|
||||
/** software mixer with pcm_volume() */
|
||||
MIXER_TYPE_SOFTWARE,
|
||||
|
||||
/** hardware mixer (output's plugin) */
|
||||
MIXER_TYPE_HARDWARE,
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses a "mixer_type" setting from the configuration file.
|
||||
*
|
||||
* @param input the configured string value; must not be NULL
|
||||
* @return a #mixer_type value; MIXER_TYPE_UNKNOWN means #input could
|
||||
* not be parsed
|
||||
*/
|
||||
enum mixer_type
|
||||
mixer_type_parse(const char *input);
|
||||
|
||||
#endif
|
43
src/volume.c
43
src/volume.c
@ -26,6 +26,7 @@
|
||||
#include "output_all.h"
|
||||
#include "mixer_control.h"
|
||||
#include "mixer_all.h"
|
||||
#include "mixer_type.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@ -39,11 +40,7 @@
|
||||
|
||||
#define SW_VOLUME_STATE "sw_volume: "
|
||||
|
||||
static enum {
|
||||
VOLUME_MIXER_TYPE_SOFTWARE,
|
||||
VOLUME_MIXER_TYPE_HARDWARE,
|
||||
VOLUME_MIXER_TYPE_DISABLED,
|
||||
} volume_mixer_type = VOLUME_MIXER_TYPE_HARDWARE;
|
||||
static enum mixer_type volume_mixer_type = MIXER_TYPE_HARDWARE;
|
||||
|
||||
static int volume_software_set = 100;
|
||||
|
||||
@ -54,7 +51,7 @@ static GTimer *hardware_volume_timer;
|
||||
|
||||
void volume_finish(void)
|
||||
{
|
||||
if (volume_mixer_type == VOLUME_MIXER_TYPE_HARDWARE)
|
||||
if (volume_mixer_type == MIXER_TYPE_HARDWARE)
|
||||
g_timer_destroy(hardware_volume_timer);
|
||||
}
|
||||
|
||||
@ -63,21 +60,24 @@ void volume_init(void)
|
||||
const struct config_param *param = config_get_param(CONF_MIXER_TYPE);
|
||||
//hw mixing is by default
|
||||
if (param) {
|
||||
if (strcmp(param->value, VOLUME_MIXER_SOFTWARE) == 0) {
|
||||
volume_mixer_type = VOLUME_MIXER_TYPE_SOFTWARE;
|
||||
volume_mixer_type = mixer_type_parse(param->value);
|
||||
switch (volume_mixer_type) {
|
||||
case MIXER_TYPE_NONE:
|
||||
case MIXER_TYPE_SOFTWARE:
|
||||
mixer_disable_all();
|
||||
} else if (strcmp(param->value, VOLUME_MIXER_DISABLED) == 0) {
|
||||
volume_mixer_type = VOLUME_MIXER_TYPE_DISABLED;
|
||||
mixer_disable_all();
|
||||
} else if (strcmp(param->value, VOLUME_MIXER_HARDWARE) == 0) {
|
||||
break;
|
||||
|
||||
case MIXER_TYPE_HARDWARE:
|
||||
//nothing to do
|
||||
} else {
|
||||
break;
|
||||
|
||||
case MIXER_TYPE_UNKNOWN:
|
||||
g_error("unknown mixer type %s at line %i\n",
|
||||
param->value, param->line);
|
||||
}
|
||||
}
|
||||
|
||||
if (volume_mixer_type == VOLUME_MIXER_TYPE_HARDWARE)
|
||||
if (volume_mixer_type == MIXER_TYPE_HARDWARE)
|
||||
hardware_volume_timer = g_timer_new();
|
||||
}
|
||||
|
||||
@ -103,11 +103,12 @@ static int software_volume_get(void)
|
||||
int volume_level_get(void)
|
||||
{
|
||||
switch (volume_mixer_type) {
|
||||
case VOLUME_MIXER_TYPE_SOFTWARE:
|
||||
case MIXER_TYPE_SOFTWARE:
|
||||
return software_volume_get();
|
||||
case VOLUME_MIXER_TYPE_HARDWARE:
|
||||
case MIXER_TYPE_HARDWARE:
|
||||
return hardware_volume_get();
|
||||
case VOLUME_MIXER_TYPE_DISABLED:
|
||||
case MIXER_TYPE_NONE:
|
||||
case MIXER_TYPE_UNKNOWN:
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -157,9 +158,9 @@ bool volume_level_change(int change, bool rel)
|
||||
idle_add(IDLE_MIXER);
|
||||
|
||||
switch (volume_mixer_type) {
|
||||
case VOLUME_MIXER_TYPE_HARDWARE:
|
||||
case MIXER_TYPE_HARDWARE:
|
||||
return hardware_volume_change(change, rel);
|
||||
case VOLUME_MIXER_TYPE_SOFTWARE:
|
||||
case MIXER_TYPE_SOFTWARE:
|
||||
return software_volume_change(change, rel);
|
||||
default:
|
||||
return true;
|
||||
@ -172,7 +173,7 @@ void read_sw_volume_state(FILE *fp)
|
||||
char *end = NULL;
|
||||
long int sv;
|
||||
|
||||
if (volume_mixer_type != VOLUME_MIXER_TYPE_SOFTWARE)
|
||||
if (volume_mixer_type != MIXER_TYPE_SOFTWARE)
|
||||
return;
|
||||
while (fgets(buf, sizeof(buf), fp)) {
|
||||
if (!g_str_has_prefix(buf, SW_VOLUME_STATE))
|
||||
@ -190,6 +191,6 @@ void read_sw_volume_state(FILE *fp)
|
||||
|
||||
void save_sw_volume_state(FILE *fp)
|
||||
{
|
||||
if (volume_mixer_type == VOLUME_MIXER_TYPE_SOFTWARE)
|
||||
if (volume_mixer_type == MIXER_TYPE_SOFTWARE)
|
||||
fprintf(fp, SW_VOLUME_STATE "%d\n", volume_software_set);
|
||||
}
|
||||
|
@ -23,10 +23,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define VOLUME_MIXER_SOFTWARE "software"
|
||||
#define VOLUME_MIXER_HARDWARE "hardware"
|
||||
#define VOLUME_MIXER_DISABLED "disabled"
|
||||
|
||||
void volume_init(void);
|
||||
|
||||
void volume_finish(void);
|
||||
|
Loading…
Reference in New Issue
Block a user