Skip to content

Commit

Permalink
[eDVBVolumecontrol]
Browse files Browse the repository at this point in the history
* format code
* add getVolumeLeft / getVolumeRight
  • Loading branch information
jbleyel committed Aug 27, 2024
1 parent 2d2337b commit 94341c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
57 changes: 22 additions & 35 deletions lib/dvb/volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@
#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;
return instance;
}

eDVBVolumecontrol::eDVBVolumecontrol()
:m_volsteps(5)
: m_volsteps(5)
{
#ifdef HAVE_ALSA
mainVolume = NULL;
Expand Down Expand Up @@ -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
}

Expand All @@ -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));
Expand All @@ -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);

Expand All @@ -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;

Expand All @@ -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
Expand All @@ -213,7 +200,7 @@ void eDVBVolumecontrol::volumeMute()
}
muted = true;

//HACK?
// HACK?
CFile::writeInt("/proc/stb/audio/j1_mute", 1);
#endif
}
Expand All @@ -236,7 +223,7 @@ void eDVBVolumecontrol::volumeUnMute()
}
muted = false;

//HACK?
// HACK?
CFile::writeInt("/proc/stb/audio/j1_mute", 0);
#endif
}
Expand Down
10 changes: 6 additions & 4 deletions lib/dvb/volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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

0 comments on commit 94341c0

Please sign in to comment.