From 1ef98753ff23287aaa23e0c35e03719256ea268f Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Wed, 19 Aug 2015 09:43:17 +0000 Subject: using QSocketNotifier to track alsa volume (patch by Hong Jen Yee) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@5424 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Output/alsa/outputalsa.cpp | 44 +++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'src/plugins/Output/alsa/outputalsa.cpp') diff --git a/src/plugins/Output/alsa/outputalsa.cpp b/src/plugins/Output/alsa/outputalsa.cpp index 4e6a33b54..69662abfe 100644 --- a/src/plugins/Output/alsa/outputalsa.cpp +++ b/src/plugins/Output/alsa/outputalsa.cpp @@ -18,9 +18,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include #include -#include +#include #include #include @@ -33,6 +32,7 @@ #include #include "outputalsa.h" + OutputALSA::OutputALSA() : m_inited(false) { QSettings settings(Qmmp::configFile(), QSettings::IniFormat); @@ -425,15 +425,16 @@ void VolumeALSA::setVolume(const VolumeSettings &vol) VolumeSettings VolumeALSA::volume() const { VolumeSettings vol; - if (!pcm_element) - return vol; - - long value = 0; - snd_mixer_handle_events(m_mixer); - snd_mixer_selem_get_playback_volume(pcm_element, SND_MIXER_SCHN_FRONT_LEFT, &value); - vol.left = value; - snd_mixer_selem_get_playback_volume(pcm_element, SND_MIXER_SCHN_FRONT_RIGHT, &value); - vol.right = value; + + if(pcm_element) + { + long value = 0; + snd_mixer_handle_events(m_mixer); + snd_mixer_selem_get_playback_volume(pcm_element, SND_MIXER_SCHN_FRONT_LEFT, &value); + vol.left = value; + snd_mixer_selem_get_playback_volume(pcm_element, SND_MIXER_SCHN_FRONT_RIGHT, &value); + vol.right = value; + } return vol; } @@ -467,10 +468,26 @@ int VolumeALSA::setupMixer(QString card, QString device) return -1; } + // setup socket notifiers to monitor the state changes of the mixer + int n = snd_mixer_poll_descriptors_count(m_mixer); + if(n > 0) + { + struct pollfd* fds = new struct pollfd[n]; + n = snd_mixer_poll_descriptors(m_mixer, fds, n); + for(int i = 0; i < n; ++i) + { + int sock = fds[i].fd; + QSocketNotifier* sn = new QSocketNotifier(sock, QSocketNotifier::Read, this); + connect(sn, SIGNAL(activated(int)), SIGNAL(changed())); + } + delete []fds; + } + qDebug("OutputALSA: setupMixer() success"); return 0; } + void VolumeALSA::parseMixerName(char *str, char **name, int *index) { char *end; @@ -543,3 +560,8 @@ int VolumeALSA::getMixer(snd_mixer_t **mixer, QString card) } return (*mixer != NULL); } + +bool VolumeALSA::hasNotifySignal() const +{ + return true; +} -- cgit v1.2.3-13-gbd6f