From 9e9c3e42cc5040272fb42659f38902130d634c5f Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Fri, 19 Nov 2010 21:49:17 +0100 Subject: [PATCH] Rework RAOP volume setting to be per-speaker Player now pilots RAOP volume setting directly on a per-speaker basis. --- src/player.c | 9 +++---- src/raop.c | 67 +++++++++++++++++++++++++++------------------------- src/raop.h | 2 +- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/player.c b/src/player.c index a7c15644..673fc59a 100644 --- a/src/player.c +++ b/src/player.c @@ -2514,13 +2514,16 @@ volume_set(struct player_command *cmd) master_volume = cmd->arg.intval; laudio_volume = master_volume; - - cmd->raop_pending = raop_set_volume(master_volume, device_command_cb); laudio_set_volume(laudio_volume); + cmd->raop_pending = 0; + for (rd = dev_list; rd; rd = rd->next) { rd->volume = master_volume; + + if (rd->session) + cmd->raop_pending += raop_set_volume_one(rd->session, rd->volume, device_command_cb); } if (cmd->raop_pending > 0) @@ -3501,8 +3504,6 @@ player_init(void) goto raop_fail; } - raop_set_volume(master_volume, NULL); - ret = mdns_browse("_raop._tcp", raop_device_cb); if (ret < 0) { diff --git a/src/raop.c b/src/raop.c index 02e726d1..b080423b 100644 --- a/src/raop.c +++ b/src/raop.c @@ -106,6 +106,7 @@ struct raop_session char *devname; char *address; + int volume; uint64_t start_rtptime; /* Do not dereference - only passed to the status cb */ @@ -207,9 +208,6 @@ static int pktbuf_size; static struct raop_v2_packet *pktbuf_head; static struct raop_v2_packet *pktbuf_tail; -/* Volume */ -static double raop_volume; - /* FLUSH timer */ static struct event flush_timer; @@ -1642,6 +1640,8 @@ raop_session_make(struct raop_device *rd, int family, raop_status_cb cb) rs->devname = strdup(rd->name); rs->address = strdup(address); + rs->volume = rd->volume; + rs->next = sessions; sessions = rs; @@ -1667,10 +1667,28 @@ raop_session_failure_cb(struct evrtsp_request *req, void *arg) /* Volume handling */ +static double +raop_volume_convert(int volume) +{ + double raop_volume; + + /* RAOP volume + * -144.0 is off + * 0 - -30.0 maps to 100 - 0 + */ + if (volume == 0) + raop_volume = -144.0; + else + raop_volume = -30.0 + ((double)volume * 30.0) / 100.0; + + return raop_volume; +} + static int -raop_set_volume_internal(struct raop_session *rs, evrtsp_req_cb cb) +raop_set_volume_internal(struct raop_session *rs, int volume, evrtsp_req_cb cb) { struct evbuffer *evbuf; + double raop_volume; int ret; evbuf = evbuffer_new(); @@ -1681,6 +1699,8 @@ raop_set_volume_internal(struct raop_session *rs, evrtsp_req_cb cb) return -1; } + raop_volume = raop_volume_convert(volume); + /* Don't let locales get in the way here */ ret = evbuffer_add_printf(evbuf, "volume: %d.%06d", (int)raop_volume, (int)(1000000.0 * (raop_volume - floor(raop_volume)))); if (ret < 0) @@ -1741,42 +1761,25 @@ raop_set_volume_cb(struct evrtsp_request *req, void *arg) /* Volume in [0 - 100] */ int -raop_set_volume(int volume, raop_status_cb cb) +raop_set_volume_one(struct raop_session *rs, int volume, raop_status_cb cb) { - struct raop_session *rs; - int pending; int ret; - /* RAOP volume - * -144.0 is off - * 0 - -30.0 maps to 100 - 0 - */ - if (volume == 0) - raop_volume = -144.0; - else - raop_volume = -30.0 + ((double)volume * 30.0) / 100.0; + if (!(rs->state & RAOP_CONNECTED)) + return 0; - pending = 0; - for (rs = sessions; rs; rs = rs->next) + ret = raop_set_volume_internal(rs, volume, raop_set_volume_cb); + if (ret < 0) { - if (!(rs->state & RAOP_CONNECTED)) - continue; + raop_session_failure(rs); - ret = raop_set_volume_internal(rs, raop_set_volume_cb); - if (ret < 0) - { - raop_session_failure(rs); - - continue; - } - - rs->status_cb = cb; - pending++; + return 0; } - return pending; -} + rs->status_cb = cb; + return 1; +} static void raop_flush_cb(struct evrtsp_request *req, void *arg) @@ -2895,7 +2898,7 @@ raop_cb_startup_record(struct evrtsp_request *req, void *arg) rs->state = RAOP_RECORD; /* Set initial volume */ - raop_set_volume_internal(rs, raop_cb_startup_volume); + raop_set_volume_internal(rs, rs->volume, raop_cb_startup_volume); return; diff --git a/src/raop.h b/src/raop.h index 3ef00454..4825225f 100644 --- a/src/raop.h +++ b/src/raop.h @@ -102,7 +102,7 @@ raop_playback_stop(void); int -raop_set_volume(int volume, raop_status_cb cb); +raop_set_volume_one(struct raop_session *rs, int volume, raop_status_cb cb); int raop_flush(raop_status_cb cb, uint64_t rtptime);