From 94341c0c0a034736b8cb554f0c05c2478dc7849e Mon Sep 17 00:00:00 2001 From: jbleyel Date: Tue, 27 Aug 2024 11:14:32 +0200 Subject: [PATCH] [eDVBVolumecontrol] * format code * add getVolumeLeft / getVolumeRight --- lib/dvb/volume.cpp | 57 ++++++++++++++++++---------------------------- lib/dvb/volume.h | 10 ++++---- 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/lib/dvb/volume.cpp b/lib/dvb/volume.cpp index ed44f67a46c..2b2c03872ff 100644 --- a/lib/dvb/volume.cpp +++ b/lib/dvb/volume.cpp @@ -26,17 +26,17 @@ #endif #ifdef HAVE_ALSA -# ifndef ALSA_VOLUME_MIXER -# define ALSA_VOLUME_MIXER "Master" -# endif -# ifndef ALSA_CARD -# define ALSA_CARD "default" -# endif +#ifndef ALSA_VOLUME_MIXER +#define ALSA_VOLUME_MIXER "Master" +#endif +#ifndef ALSA_CARD +#define ALSA_CARD "default" +#endif #endif -eDVBVolumecontrol* eDVBVolumecontrol::instance = NULL; +eDVBVolumecontrol *eDVBVolumecontrol::instance = NULL; -eDVBVolumecontrol* eDVBVolumecontrol::getInstance() +eDVBVolumecontrol *eDVBVolumecontrol::getInstance() { if (instance == NULL) instance = new eDVBVolumecontrol; @@ -44,7 +44,7 @@ eDVBVolumecontrol* eDVBVolumecontrol::getInstance() } eDVBVolumecontrol::eDVBVolumecontrol() -:m_volsteps(5) + : m_volsteps(5) { #ifdef HAVE_ALSA mainVolume = NULL; @@ -104,7 +104,7 @@ int eDVBVolumecontrol::openMixer() } return mainVolume ? 0 : -1; #else - return open( AUDIO_DEV, O_RDWR ); + return open(AUDIO_DEV, O_RDWR); #endif } @@ -113,15 +113,11 @@ void eDVBVolumecontrol::closeMixer(int fd) #ifdef HAVE_ALSA /* we want to keep the alsa mixer */ #else - if (fd >= 0) close(fd); + if (fd >= 0) + close(fd); #endif } -void eDVBVolumecontrol::setVolumeSteps(int steps) -{ - m_volsteps = steps; -} - void eDVBVolumecontrol::volumeUp(int left, int right) { setVolume(leftVol + (left ? left : m_volsteps), rightVol + (right ? right : m_volsteps)); @@ -143,7 +139,7 @@ int eDVBVolumecontrol::checkVolume(int vol) void eDVBVolumecontrol::setVolume(int left, int right) { - /* left, right is 0..100 */ + /* left, right is 0..100 */ leftVol = checkVolume(left); rightVol = checkVolume(right); @@ -152,10 +148,10 @@ void eDVBVolumecontrol::setVolume(int left, int right) if (mainVolume) snd_mixer_selem_set_playback_volume_all(mainVolume, muted ? 0 : leftVol); #else - /* convert to -1dB steps */ + /* convert to -1dB steps */ left = 63 - leftVol * 63 / 100; right = 63 - rightVol * 63 / 100; - /* now range is 63..0, where 0 is loudest */ + /* now range is 63..0, where 0 is loudest */ audio_mixer_t mixer; @@ -168,33 +164,24 @@ void eDVBVolumecontrol::setVolume(int left, int right) if (fd >= 0) { #ifdef DVB_API_VERSION - if (ioctl(fd, AUDIO_SET_MIXER, &mixer) < 0) { + if (ioctl(fd, AUDIO_SET_MIXER, &mixer) < 0) + { eDebug("[eDVBVolumecontrol] Setvolume failed: %m"); } #endif closeMixer(fd); return; } - else { + else + { eDebug("[eDVBVolumecontrol] SetVolume failed to open mixer: %m"); } - //HACK? + // HACK? CFile::writeInt("/proc/stb/avs/0/volume", left); /* in -1dB */ #endif } -int eDVBVolumecontrol::getVolume() -{ - return leftVol; -} - -bool eDVBVolumecontrol::isMuted() -{ - return muted; -} - - void eDVBVolumecontrol::volumeMute() { #ifdef HAVE_ALSA @@ -213,7 +200,7 @@ void eDVBVolumecontrol::volumeMute() } muted = true; - //HACK? + // HACK? CFile::writeInt("/proc/stb/audio/j1_mute", 1); #endif } @@ -236,7 +223,7 @@ void eDVBVolumecontrol::volumeUnMute() } muted = false; - //HACK? + // HACK? CFile::writeInt("/proc/stb/audio/j1_mute", 0); #endif } diff --git a/lib/dvb/volume.h b/lib/dvb/volume.h index 6592675443f..ef204db67df 100644 --- a/lib/dvb/volume.h +++ b/lib/dvb/volume.h @@ -35,9 +35,9 @@ class eDVBVolumecontrol int checkVolume(int vol); public: - static eDVBVolumecontrol* getInstance(); + static eDVBVolumecontrol *getInstance(); - void setVolumeSteps(int steps); + void setVolumeSteps(int steps) { m_volsteps = steps; } void volumeUp(int left = 0, int right = 0); void volumeDown(int left = 0, int right = 0); @@ -47,8 +47,10 @@ class eDVBVolumecontrol void volumeUnMute(); void volumeToggleMute(); - int getVolume(); - bool isMuted(); + int getVolume() { return leftVol; } + int getVolumeLeft() { return leftVol; } + int getVolumeRight() { return rightVol; } + bool isMuted() { return muted; } }; #endif //__volume_h