mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-27 22:46:02 -05:00
Switch speaker state-saving to new db_speaker_* interface
This commit is contained in:
parent
012e90b4a3
commit
9507f8d059
51
src/player.c
51
src/player.c
@ -64,9 +64,6 @@
|
|||||||
# define MIN(a, b) ((a < b) ? a : b)
|
# define MIN(a, b) ((a < b) ? a : b)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define VAR_PLAYER_VOLUME "player:volume"
|
|
||||||
#define VAR_ACTIVE_SPK "player:active-spk"
|
|
||||||
|
|
||||||
enum player_sync_source
|
enum player_sync_source
|
||||||
{
|
{
|
||||||
PLAYER_SYNC_CLOCK,
|
PLAYER_SYNC_CLOCK,
|
||||||
@ -1190,6 +1187,7 @@ device_remove(struct raop_device *dev)
|
|||||||
{
|
{
|
||||||
struct raop_device *rd;
|
struct raop_device *rd;
|
||||||
struct raop_device *prev;
|
struct raop_device *prev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
for (rd = dev_list; rd; rd = rd->next)
|
for (rd = dev_list; rd; rd = rd->next)
|
||||||
@ -1209,6 +1207,11 @@ device_remove(struct raop_device *dev)
|
|||||||
if (dev->selected)
|
if (dev->selected)
|
||||||
speaker_deselect_raop(dev);
|
speaker_deselect_raop(dev);
|
||||||
|
|
||||||
|
/* Save device volume */
|
||||||
|
ret = db_speaker_save(dev->id, 0, master_volume);
|
||||||
|
if (ret < 0)
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Could not save state for speaker %s\n", dev->name);
|
||||||
|
|
||||||
if (!prev)
|
if (!prev)
|
||||||
dev_list = dev->next;
|
dev_list = dev->next;
|
||||||
else
|
else
|
||||||
@ -1236,6 +1239,8 @@ device_add(struct player_command *cmd)
|
|||||||
{
|
{
|
||||||
struct raop_device *dev;
|
struct raop_device *dev;
|
||||||
struct raop_device *rd;
|
struct raop_device *rd;
|
||||||
|
int selected;
|
||||||
|
int dummy;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dev = cmd->arg.rd;
|
dev = cmd->arg.rd;
|
||||||
@ -1251,14 +1256,12 @@ device_add(struct player_command *cmd)
|
|||||||
{
|
{
|
||||||
rd = dev;
|
rd = dev;
|
||||||
|
|
||||||
/* Check if the device was selected last time */
|
ret = db_speaker_get(rd->id, &selected, &dummy);
|
||||||
if (dev_autoselect)
|
if (ret < 0)
|
||||||
{
|
selected = 0;
|
||||||
ret = db_config_has_tuple_hex64(VAR_ACTIVE_SPK, rd->id);
|
|
||||||
|
|
||||||
if (ret == 1)
|
if (dev_autoselect && selected)
|
||||||
speaker_select_raop(rd);
|
speaker_select_raop(rd);
|
||||||
}
|
|
||||||
|
|
||||||
rd->next = dev_list;
|
rd->next = dev_list;
|
||||||
dev_list = rd;
|
dev_list = rd;
|
||||||
@ -2502,17 +2505,11 @@ speaker_set(struct player_command *cmd)
|
|||||||
static int
|
static int
|
||||||
volume_set(struct player_command *cmd)
|
volume_set(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
|
|
||||||
master_volume = cmd->arg.intval;
|
master_volume = cmd->arg.intval;
|
||||||
|
|
||||||
cmd->raop_pending = raop_set_volume(master_volume, device_command_cb);
|
cmd->raop_pending = raop_set_volume(master_volume, device_command_cb);
|
||||||
laudio_set_volume(master_volume);
|
laudio_set_volume(master_volume);
|
||||||
|
|
||||||
ret = db_config_save_int(VAR_PLAYER_VOLUME, master_volume);
|
|
||||||
if (ret < 0)
|
|
||||||
DPRINTF(E_WARN, L_PLAYER, "Could not save volume setting to DB\n");
|
|
||||||
|
|
||||||
if (cmd->raop_pending > 0)
|
if (cmd->raop_pending > 0)
|
||||||
return 1; /* async */
|
return 1; /* async */
|
||||||
|
|
||||||
@ -3339,15 +3336,17 @@ player(void *arg)
|
|||||||
DPRINTF(E_LOG, L_PLAYER, "Player event loop terminated ahead of time!\n");
|
DPRINTF(E_LOG, L_PLAYER, "Player event loop terminated ahead of time!\n");
|
||||||
|
|
||||||
/* Save selected devices */
|
/* Save selected devices */
|
||||||
db_config_clear_key(VAR_ACTIVE_SPK);
|
db_speaker_clear_all();
|
||||||
|
|
||||||
if (laudio_selected)
|
ret = db_speaker_save(0, laudio_selected, master_volume);
|
||||||
db_config_save_hex64(VAR_ACTIVE_SPK, 0);
|
if (ret < 0)
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Could not save state for local audio\n");
|
||||||
|
|
||||||
for (rd = dev_list; rd; rd = rd->next)
|
for (rd = dev_list; rd; rd = rd->next)
|
||||||
{
|
{
|
||||||
if (rd->selected)
|
ret = db_speaker_save(rd->id, rd->selected, master_volume);
|
||||||
db_config_save_hex64(VAR_ACTIVE_SPK, rd->id);
|
if (ret < 0)
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Could not save state for speaker %s\n", rd->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
db_perthread_deinit();
|
db_perthread_deinit();
|
||||||
@ -3402,17 +3401,11 @@ player_init(void)
|
|||||||
|
|
||||||
rng_init(&shuffle_rng);
|
rng_init(&shuffle_rng);
|
||||||
|
|
||||||
ret = db_config_has_tuple_hex64(VAR_ACTIVE_SPK, 0);
|
ret = db_speaker_get(0, &laudio_selected, &master_volume);
|
||||||
if (ret == 1)
|
|
||||||
speaker_select_laudio();
|
|
||||||
|
|
||||||
ret = db_config_fetch_int(VAR_PLAYER_VOLUME, &master_volume);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
|
||||||
DPRINTF(E_WARN, L_PLAYER, "Could not fetch last volume setting from DB\n");
|
|
||||||
|
|
||||||
master_volume = 75;
|
master_volume = 75;
|
||||||
}
|
else if (laudio_selected)
|
||||||
|
speaker_select_laudio(); /* Run the select helper */
|
||||||
|
|
||||||
audio_buf = evbuffer_new();
|
audio_buf = evbuffer_new();
|
||||||
if (!audio_buf)
|
if (!audio_buf)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user