Introduce speaker selection/deselection helpers

This commit is contained in:
Julien BLACHE 2010-11-21 10:05:41 +01:00
parent 55f0c7cfcd
commit 78df98ba35
1 changed files with 53 additions and 15 deletions

View File

@ -248,6 +248,32 @@ status_update(enum play_status status)
} }
/* Device select/deselect hooks */
static void
speaker_select_laudio(void)
{
laudio_selected = 1;
}
static void
speaker_select_raop(struct raop_device *rd)
{
rd->selected = 1;
}
static void
speaker_deselect_laudio(void)
{
laudio_selected = 0;
}
static void
speaker_deselect_raop(struct raop_device *rd)
{
rd->selected = 0;
}
static int static int
player_get_current_pos_clock(uint64_t *pos, struct timespec *ts, int commit) player_get_current_pos_clock(uint64_t *pos, struct timespec *ts, int commit)
{ {
@ -379,7 +405,7 @@ player_laudio_status_cb(enum laudio_state status)
if (raop_sessions == 0) if (raop_sessions == 0)
playback_stop(NULL); playback_stop(NULL);
laudio_selected = 0; speaker_deselect_laudio();
break; break;
default: default:
@ -1225,7 +1251,9 @@ device_add(struct player_command *cmd)
if (dev_autoselect) if (dev_autoselect)
{ {
ret = db_config_has_tuple_hex64(VAR_ACTIVE_SPK, rd->id); ret = db_config_has_tuple_hex64(VAR_ACTIVE_SPK, rd->id);
rd->selected = (ret == 1);
if (ret == 1)
speaker_select_raop(rd);
} }
rd->next = dev_list; rd->next = dev_list;
@ -1344,7 +1372,7 @@ device_streaming_cb(struct raop_device *dev, struct raop_session *rs, enum raop_
DPRINTF(E_LOG, L_PLAYER, "AirTunes device %s FAILED\n", dev->name); DPRINTF(E_LOG, L_PLAYER, "AirTunes device %s FAILED\n", dev->name);
if (player_state == PLAY_PLAYING) if (player_state == PLAY_PLAYING)
dev->selected = 0; speaker_deselect_raop(dev);
dev->session = NULL; dev->session = NULL;
@ -1468,7 +1496,7 @@ device_activate_cb(struct raop_device *dev, struct raop_session *rs, enum raop_s
if (status == RAOP_FAILED) if (status == RAOP_FAILED)
{ {
dev->selected = 0; speaker_deselect_raop(dev);
if (!dev->advertised) if (!dev->advertised)
device_remove(dev); device_remove(dev);
@ -1542,7 +1570,7 @@ device_probe_cb(struct raop_device *dev, struct raop_session *rs, enum raop_sess
if (status == RAOP_FAILED) if (status == RAOP_FAILED)
{ {
dev->selected = 0; speaker_deselect_raop(dev);
if (!dev->advertised) if (!dev->advertised)
device_remove(dev); device_remove(dev);
@ -1584,7 +1612,7 @@ device_restart_cb(struct raop_device *dev, struct raop_session *rs, enum raop_se
if (status == RAOP_FAILED) if (status == RAOP_FAILED)
{ {
dev->selected = 0; speaker_deselect_raop(dev);
if (!dev->advertised) if (!dev->advertised)
device_remove(dev); device_remove(dev);
@ -2197,8 +2225,8 @@ speaker_enumerate(struct player_command *cmd)
laudio_name = cfg_getstr(cfg_getsec(cfg, "audio"), "nickname"); laudio_name = cfg_getstr(cfg_getsec(cfg, "audio"), "nickname");
/* Auto-select local audio if there are no AirTunes devices */ /* Auto-select local audio if there are no AirTunes devices */
if (!dev_list) if (!dev_list && !laudio_selected)
laudio_selected = 1; speaker_select_laudio();
spk_enum->cb(0, laudio_name, laudio_selected, 0, spk_enum->arg); spk_enum->cb(0, laudio_name, laudio_selected, 0, spk_enum->arg);
@ -2368,7 +2396,9 @@ speaker_set(struct player_command *cmd)
} }
DPRINTF(E_DBG, L_PLAYER, "RAOP device %s selected\n", rd->name); DPRINTF(E_DBG, L_PLAYER, "RAOP device %s selected\n", rd->name);
rd->selected = 1;
if (!rd->selected)
speaker_select_raop(rd);
if (!rd->session) if (!rd->session)
{ {
@ -2377,7 +2407,7 @@ speaker_set(struct player_command *cmd)
{ {
DPRINTF(E_LOG, L_PLAYER, "Could not activate RAOP device %s\n", rd->name); DPRINTF(E_LOG, L_PLAYER, "Could not activate RAOP device %s\n", rd->name);
rd->selected = 0; speaker_deselect_raop(rd);
if (cmd->ret != -2) if (cmd->ret != -2)
cmd->ret = -1; cmd->ret = -1;
@ -2390,7 +2420,9 @@ speaker_set(struct player_command *cmd)
else else
{ {
DPRINTF(E_DBG, L_PLAYER, "RAOP device %s NOT selected\n", rd->name); DPRINTF(E_DBG, L_PLAYER, "RAOP device %s NOT selected\n", rd->name);
rd->selected = 0;
if (rd->selected)
speaker_deselect_raop(rd);
if (rd->session) if (rd->session)
{ {
@ -2419,7 +2451,9 @@ speaker_set(struct player_command *cmd)
if (i <= nspk) if (i <= nspk)
{ {
DPRINTF(E_DBG, L_PLAYER, "Local audio selected\n"); DPRINTF(E_DBG, L_PLAYER, "Local audio selected\n");
laudio_selected = 1;
if (!laudio_selected)
speaker_select_laudio();
if (!(laudio_status & LAUDIO_F_STARTED)) if (!(laudio_status & LAUDIO_F_STARTED))
{ {
@ -2428,7 +2462,7 @@ speaker_set(struct player_command *cmd)
{ {
DPRINTF(E_LOG, L_PLAYER, "Could not activate local audio output\n"); DPRINTF(E_LOG, L_PLAYER, "Could not activate local audio output\n");
laudio_selected = 0; speaker_deselect_laudio();
if (cmd->ret != -2) if (cmd->ret != -2)
cmd->ret = -1; cmd->ret = -1;
@ -2438,7 +2472,9 @@ speaker_set(struct player_command *cmd)
else else
{ {
DPRINTF(E_DBG, L_PLAYER, "Local audio NOT selected\n"); DPRINTF(E_DBG, L_PLAYER, "Local audio NOT selected\n");
laudio_selected = 0;
if (laudio_selected)
speaker_deselect_laudio();
if (laudio_status != LAUDIO_CLOSED) if (laudio_status != LAUDIO_CLOSED)
{ {
@ -3336,6 +3372,7 @@ player_init(void)
dev_autoselect = 1; dev_autoselect = 1;
dev_list = NULL; dev_list = NULL;
laudio_selected = 0;
laudio_status = LAUDIO_CLOSED; laudio_status = LAUDIO_CLOSED;
raop_sessions = 0; raop_sessions = 0;
@ -3362,7 +3399,8 @@ player_init(void)
rng_init(&shuffle_rng); rng_init(&shuffle_rng);
ret = db_config_has_tuple_hex64(VAR_ACTIVE_SPK, 0); ret = db_config_has_tuple_hex64(VAR_ACTIVE_SPK, 0);
laudio_selected = (ret == 1); if (ret == 1)
speaker_select_laudio();
ret = db_config_fetch_int(VAR_PLAYER_VOLUME, &master_volume); ret = db_config_fetch_int(VAR_PLAYER_VOLUME, &master_volume);
if (ret < 0) if (ret < 0)