servicemp3.cpp: more simple/flexible streaming detection
[enigma2.git] / lib / dvb / volume.cpp
index bc3d6574d65365d5533d7074fb16b9366dd42e19..6409dba86bf9adb7b477e0dc3a2676d897687114 100644 (file)
@@ -1,10 +1,10 @@
+#include <lib/base/eerror.h>
 #include <lib/dvb/volume.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 
-#include <config.h>
 #if HAVE_DVB_API_VERSION < 3
 #define VIDEO_DEV "/dev/dvb/card0/video0"
 #define AUDIO_DEV "/dev/dvb/card0/audio0"
@@ -44,13 +44,11 @@ void eDVBVolumecontrol::closeMixer(int fd)
 
 void eDVBVolumecontrol::volumeUp(int left, int right)
 {
-       printf("[volume.cpp] Volume up\n");
        setVolume(leftVol + left, rightVol + right);
 }
 
 void eDVBVolumecontrol::volumeDown(int left, int right)
 {
-       printf("[volume.cpp] Volume down\n");
        setVolume(leftVol - left, rightVol - right);
 }
 
@@ -65,37 +63,60 @@ int eDVBVolumecontrol::checkVolume(int vol)
 
 void eDVBVolumecontrol::setVolume(int left, int right)
 {
+               /* left, right is 0..100 */
        leftVol = checkVolume(left);
        rightVol = checkVolume(right);
        
-       left = 63 - leftVol / 100.0 * 63.0;
-       right = 63 - rightVol / 100.0 * 63.0;
-       
-#if HAVE_DVB_API_VERSION < 3   
-               audioMixer_t mixer;
+               /* convert to -1dB steps */
+       left = 63 - leftVol * 63 / 100;
+       right = 63 - rightVol * 63 / 100;
+               /* now range is 63..0, where 0 is loudest */
+
+#if HAVE_DVB_API_VERSION < 3
+       audioMixer_t mixer;
 #else
-               audio_mixer_t mixer;
+       audio_mixer_t mixer;
 #endif
 
-#ifdef HAVE_DVB_API_VERSION
-               mixer.volume_left = (left * left) / 64;
-               mixer.volume_right = (right * right) / 64;
+#if HAVE_DVB_API_VERSION < 3
+               /* convert to linear scale. 0 = loudest, ..63 */
+       mixer.volume_left = 63.0-pow(1.068241, 63-left);
+       mixer.volume_right = 63.0-pow(1.068241, 63-right);
+#else
+       mixer.volume_left = left;
+       mixer.volume_right = right;
 #endif
 
-               int fd = openMixer();
+       eDebug("Setvolume: %d %d (raw)", leftVol, rightVol);
+       eDebug("Setvolume: %d %d (-1db)", left, right);
+#if HAVE_DVB_API_VERSION < 3
+       eDebug("Setvolume: %d %d (lin)", mixer.volume_left, mixer.volume_right);
+#endif
+
+       int fd = openMixer();
+       if (fd >= 0)
+       {
 #ifdef HAVE_DVB_API_VERSION
                ioctl(fd, AUDIO_SET_MIXER, &mixer);
 #endif
                closeMixer(fd);
-               
-               printf("Setvolume: %d %d\n", leftVol, rightVol);
-               printf("Setvolume: %d %d\n", left, right);              
+               return;
+       }
+
+       //HACK?
+       FILE *f;
+       if((f = fopen("/proc/stb/avs/0/volume", "wb")) == NULL) {
+               eDebug("cannot open /proc/stb/avs/0/volume(%m)");
+               return;
+       }
+
+       fprintf(f, "%d", left); /* in -1dB */
+
+       fclose(f);
 }
 
 int eDVBVolumecontrol::getVolume()
 {
-       if (isMuted())
-               return 0;
        return leftVol;
 }
 
@@ -113,6 +134,17 @@ void eDVBVolumecontrol::volumeMute()
 #endif
        closeMixer(fd);
        muted = true;
+
+       //HACK?
+       FILE *f;
+       if((f = fopen("/proc/stb/audio/j1_mute", "wb")) == NULL) {
+               eDebug("cannot open /proc/stb/audio/j1_mute(%m)");
+               return;
+       }
+       
+       fprintf(f, "%d", 1);
+
+       fclose(f);
 }
 
 void eDVBVolumecontrol::volumeUnMute()
@@ -123,14 +155,23 @@ void eDVBVolumecontrol::volumeUnMute()
 #endif
        closeMixer(fd);
        muted = false;
+
+       //HACK?
+       FILE *f;
+       if((f = fopen("/proc/stb/audio/j1_mute", "wb")) == NULL) {
+               eDebug("cannot open /proc/stb/audio/j1_mute(%m)");
+               return;
+       }
+       
+       fprintf(f, "%d", 0);
+
+       fclose(f);
 }
 
 void eDVBVolumecontrol::volumeToggleMute()
 {
-       printf("Mute\n");
        if (isMuted())
                volumeUnMute();
        else
                volumeMute();
-               
-}
\ No newline at end of file
+}