diff options
Diffstat (limited to '')
-rw-r--r-- | src/Volume.cxx | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/Volume.cxx b/src/Volume.cxx index 6c5f8dc4d..4c897b21f 100644 --- a/src/Volume.cxx +++ b/src/Volume.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -22,11 +22,11 @@ #include "MixerAll.hxx" #include "Idle.hxx" #include "GlobalEvents.hxx" +#include "util/StringUtil.hxx" #include "util/Domain.hxx" +#include "system/PeriodClock.hxx" #include "Log.hxx" -#include <glib.h> - #include <assert.h> #include <stdlib.h> @@ -39,7 +39,7 @@ static unsigned volume_software_set = 100; /** the cached hardware mixer value; invalid if negative */ static int last_hardware_volume = -1; /** the age of #last_hardware_volume */ -static GTimer *hardware_volume_timer; +static PeriodClock hardware_volume_clock; /** * Handler for #GlobalEvents::MIXER. @@ -54,29 +54,19 @@ mixer_event_callback(void) idle_add(IDLE_MIXER); } -void volume_finish(void) -{ - g_timer_destroy(hardware_volume_timer); -} - void volume_init(void) { - hardware_volume_timer = g_timer_new(); - GlobalEvents::Register(GlobalEvents::MIXER, mixer_event_callback); } int volume_level_get(void) { - assert(hardware_volume_timer != nullptr); - if (last_hardware_volume >= 0 && - g_timer_elapsed(hardware_volume_timer, nullptr) < 1.0) + !hardware_volume_clock.CheckUpdate(1000)) /* throttle access to hardware mixers */ return last_hardware_volume; last_hardware_volume = mixer_all_get_volume(); - g_timer_start(hardware_volume_timer); return last_hardware_volume; } @@ -115,7 +105,7 @@ read_sw_volume_state(const char *line) char *end = nullptr; long int sv; - if (!g_str_has_prefix(line, SW_VOLUME_STATE)) + if (!StringStartsWith(line, SW_VOLUME_STATE)) return false; line += sizeof(SW_VOLUME_STATE) - 1; |