diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index d52396c3..8fa79076 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -46,6 +46,7 @@ #include "dmap_common.h" #include "db.h" #include "player.h" +#include "listener.h" /* httpd event base, from httpd.c */ extern struct event_base *evbase_httpd; @@ -342,10 +343,14 @@ playstatusupdate_cb(int fd, short what, void *arg) /* Thread: player */ static void -dacp_playstatus_update_handler(void) +dacp_playstatus_update_handler(enum listener_event_type type) { int ret; + // Only send status update on player change events + if (type != LISTENER_PLAYER) + return; + #ifdef USE_EVENTFD ret = eventfd_write(update_efd, 1); if (ret < 0) @@ -2423,7 +2428,7 @@ dacp_init(void) event_base_set(evbase_httpd, &updateev); event_add(&updateev, NULL); - player_set_update_handler(dacp_playstatus_update_handler); + listener_add(dacp_playstatus_update_handler); return 0; @@ -2444,7 +2449,7 @@ dacp_deinit(void) struct evhttp_connection *evcon; int i; - player_set_update_handler(NULL); + listener_remove(dacp_playstatus_update_handler); for (i = 0; dacp_handlers[i].handler; i++) regfree(&dacp_handlers[i].preg); diff --git a/src/player.c b/src/player.c index 450bb0ba..18c15bd8 100644 --- a/src/player.c +++ b/src/player.c @@ -165,7 +165,6 @@ struct player_command struct player_status *status; struct player_source *ps; struct player_metadata *pmd; - player_status_handler status_handler; uint32_t *id_ptr; uint64_t *raop_ids; enum repeat_mode mode; @@ -208,9 +207,6 @@ static enum play_status player_state; static enum repeat_mode repeat; static char shuffle; -/* Status updates (for DACP) */ -static player_status_handler update_handler; - /* Playback timer */ #if defined(__linux__) static int pb_timer_fd; @@ -300,9 +296,6 @@ status_update(enum play_status status) { player_state = status; - if (update_handler) - update_handler(); - listener_notify(LISTENER_PLAYER); if (status == PLAY_PLAYING) @@ -4125,14 +4118,6 @@ queue_plid(struct player_command *cmd) return 0; } -static int -set_update_handler(struct player_command *cmd) -{ - update_handler = cmd->arg.status_handler; - - return 0; -} - /* Command processing */ /* Thread: player */ static void @@ -4821,22 +4806,6 @@ player_queue_plid(uint32_t plid) command_deinit(&cmd); } -void -player_set_update_handler(player_status_handler handler) -{ - struct player_command cmd; - - command_init(&cmd); - - cmd.func = set_update_handler; - cmd.func_bh = NULL; - cmd.arg.status_handler = handler; - - sync_command(&cmd); - - command_deinit(&cmd); -} - /* Non-blocking commands used by mDNS */ static void player_device_add(struct raop_device *rd) @@ -5198,8 +5167,6 @@ player_init(void) repeat = REPEAT_OFF; shuffle = 0; - update_handler = NULL; - history = (struct player_history *)calloc(1, sizeof(struct player_history)); /* diff --git a/src/player.h b/src/player.h index a0a591e1..7f98d719 100644 --- a/src/player.h +++ b/src/player.h @@ -71,7 +71,6 @@ struct player_status { }; typedef void (*spk_enum_cb)(uint64_t id, const char *name, int relvol, struct spk_flags flags, void *arg); -typedef void (*player_status_handler)(void); struct player_source { @@ -224,9 +223,6 @@ player_queue_plid(uint32_t plid); struct player_history * player_history_get(void); -void -player_set_update_handler(player_status_handler handler); - int player_init(void);