adding volume control
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Sat, 13 Aug 2005 19:51:17 +0000 (19:51 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Sat, 13 Aug 2005 19:51:17 +0000 (19:51 +0000)
keymap.xml
lib/dvb/Makefile.am
lib/dvb/volume.cpp [new file with mode: 0644]
lib/dvb/volume.h [new file with mode: 0644]
lib/python/Components/VolumeBar.py
lib/python/Screens/InfoBar.py
lib/python/enigma_python.i

index 7b9d0c6..e0fc87a 100644 (file)
                <key id="KEY_OK" mapto="toggleShow" flags="mr" />
                <key id="KEY_EXIT" mapto="hide" flags="mr" />
                <key id="KEY_VIDEO" mapto="showMovies" flags="m" />
                <key id="KEY_OK" mapto="toggleShow" flags="mr" />
                <key id="KEY_EXIT" mapto="hide" flags="mr" />
                <key id="KEY_VIDEO" mapto="showMovies" flags="m" />
+               <key id="KEY_VOLUMEUP" mapto="volumeUp" flags="mr" />
+               <key id="KEY_VOLUMEDOWN" mapto="volumeDown" flags="mr" />
+               <key id="KEY_MUTE" mapto="volumeMute" flags="mr" />
+               <key id="KEY_POWER" mapto="quit" flags="mr" />
        </map>
        
        <map context="ChannelSelectActions">
        </map>
        
        <map context="ChannelSelectActions">
index ca20010..797e54d 100644 (file)
@@ -5,4 +5,4 @@ noinst_LIBRARIES = libenigma_dvb.a
 
 libenigma_dvb_a_SOURCES = dvb.cpp demux.cpp frontend.cpp esection.cpp db.cpp \
        sec.cpp scan.cpp crc32.cpp pmt.cpp decoder.cpp eit.cpp rotor_calc.cpp \
 
 libenigma_dvb_a_SOURCES = dvb.cpp demux.cpp frontend.cpp esection.cpp db.cpp \
        sec.cpp scan.cpp crc32.cpp pmt.cpp decoder.cpp eit.cpp rotor_calc.cpp \
-       epgcache.cpp dvbtime.cpp metaparser.cpp
+       epgcache.cpp dvbtime.cpp metaparser.cpp volume.cpp
diff --git a/lib/dvb/volume.cpp b/lib/dvb/volume.cpp
new file mode 100644 (file)
index 0000000..bc3d657
--- /dev/null
@@ -0,0 +1,136 @@
+#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"
+#include <ost/audio.h>
+#include <ost/video.h>
+#else
+#define VIDEO_DEV "/dev/dvb/adapter0/video0"
+#define AUDIO_DEV "/dev/dvb/adapter0/audio0"
+#include <linux/dvb/audio.h>
+#include <linux/dvb/video.h>
+#endif
+
+eDVBVolumecontrol* eDVBVolumecontrol::instance = NULL;
+
+eDVBVolumecontrol* eDVBVolumecontrol::getInstance()
+{
+       if (instance == NULL)
+               instance = new eDVBVolumecontrol;
+       return instance;
+}
+
+eDVBVolumecontrol::eDVBVolumecontrol()
+{
+       volumeUnMute();
+       setVolume(100, 100);
+}
+
+int eDVBVolumecontrol::openMixer()
+{
+       return open( AUDIO_DEV, O_RDWR );
+}
+
+void eDVBVolumecontrol::closeMixer(int fd)
+{
+       close(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);
+}
+
+int eDVBVolumecontrol::checkVolume(int vol)
+{
+       if (vol < 0)
+               vol = 0;
+       else if (vol > 100)
+               vol = 100;
+       return vol;
+}
+
+void eDVBVolumecontrol::setVolume(int left, int right)
+{
+       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;
+#else
+               audio_mixer_t mixer;
+#endif
+
+#ifdef HAVE_DVB_API_VERSION
+               mixer.volume_left = (left * left) / 64;
+               mixer.volume_right = (right * right) / 64;
+#endif
+
+               int fd = openMixer();
+#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);              
+}
+
+int eDVBVolumecontrol::getVolume()
+{
+       if (isMuted())
+               return 0;
+       return leftVol;
+}
+
+bool eDVBVolumecontrol::isMuted()
+{
+       return muted;
+}
+
+
+void eDVBVolumecontrol::volumeMute()
+{
+       int fd = openMixer();
+#ifdef HAVE_DVB_API_VERSION    
+       ioctl(fd, AUDIO_SET_MUTE, true);
+#endif
+       closeMixer(fd);
+       muted = true;
+}
+
+void eDVBVolumecontrol::volumeUnMute()
+{
+       int fd = openMixer();
+#ifdef HAVE_DVB_API_VERSION
+       ioctl(fd, AUDIO_SET_MUTE, false);
+#endif
+       closeMixer(fd);
+       muted = false;
+}
+
+void eDVBVolumecontrol::volumeToggleMute()
+{
+       printf("Mute\n");
+       if (isMuted())
+               volumeUnMute();
+       else
+               volumeMute();
+               
+}
\ No newline at end of file
diff --git a/lib/dvb/volume.h b/lib/dvb/volume.h
new file mode 100644 (file)
index 0000000..cee3140
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef __volume_h
+#define __volume_h
+
+#include <lib/base/ebase.h>
+
+class eDVBVolumecontrol
+{
+private:
+       static eDVBVolumecontrol *instance;
+       eDVBVolumecontrol();
+       
+       int openMixer();
+       void closeMixer(int fd);
+       
+       bool muted;
+       int leftVol, rightVol;
+       
+       int checkVolume(int vol);
+       
+public:
+       static eDVBVolumecontrol* getInstance();
+
+       void volumeUp(int left = 5, int right = 5);
+       void volumeDown(int left = 5, int right = 5);
+
+       void setVolume(int left, int right);
+
+       void volumeMute();
+       void volumeUnMute();    
+       void volumeToggleMute();
+                       
+       int getVolume();
+       bool isMuted();
+};
+
+#endif //__volume_h
index a6da598..63771e2 100644 (file)
@@ -1,12 +1,15 @@
 from HTMLComponent import *
 from GUIComponent import *
 from VariableValue import *
 from HTMLComponent import *
 from GUIComponent import *
 from VariableValue import *
+from VariableText import *
+
+from enigma import eSlider
+from enigma import eLabel
 
 class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
 
 class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
-       
        def __init__(self):
        def __init__(self):
-               GUIComponent.__init__(self)
                VariableValue.__init__(self)
                VariableValue.__init__(self)
+               GUIComponent.__init__(self)
 
        def createWidget(self, parent):
                g = eSlider(parent)
 
        def createWidget(self, parent):
                g = eSlider(parent)
index be6b65c..6f8dde1 100644 (file)
@@ -1,6 +1,7 @@
 from Screen import Screen
 from ChannelSelection import ChannelSelection
 from Components.Clock import Clock
 from Screen import Screen
 from ChannelSelection import ChannelSelection
 from Components.Clock import Clock
+from Components.VolumeBar import VolumeBar
 from Components.ActionMap import ActionMap
 from Components.Button import Button
 from Components.ServiceName import ServiceName
 from Components.ActionMap import ActionMap
 from Components.Button import Button
 from Components.ServiceName import ServiceName
@@ -22,7 +23,8 @@ class InfoBar(Screen):
 
                #instantiate forever
                self.servicelist = self.session.instantiateDialog(ChannelSelection)
 
                #instantiate forever
                self.servicelist = self.session.instantiateDialog(ChannelSelection)
-               
+               self.volumeBar = VolumeBar()            
+
                self["actions"] = ActionMap( [ "InfobarActions" ], 
                        {
                                "switchChannelUp": self.switchChannelUp,
                self["actions"] = ActionMap( [ "InfobarActions" ], 
                        {
                                "switchChannelUp": self.switchChannelUp,
@@ -30,14 +32,20 @@ class InfoBar(Screen):
                                "mainMenu": self.mainMenu,
                                "zapUp": self.zapUp,
                                "zapDown": self.zapDown,
                                "mainMenu": self.mainMenu,
                                "zapUp": self.zapUp,
                                "zapDown": self.zapDown,
+                               "volumeUp": self.volUp,
+                               "volumeDown": self.volDown,
+                               "volumeMute": self.volMute,
                                "instantRecord": self.instantRecord,
                                "hide": self.hide,
                                "toggleShow": self.toggleShow,
                                "showMovies": self.showMovies,
                                "instantRecord": self.instantRecord,
                                "hide": self.hide,
                                "toggleShow": self.toggleShow,
                                "showMovies": self.showMovies,
+                               "quit": self.quit
                        })
 #              self["okbutton"] = Button("mainMenu", [self.mainMenu])
                
                self["CurrentTime"] = Clock()
                        })
 #              self["okbutton"] = Button("mainMenu", [self.mainMenu])
                
                self["CurrentTime"] = Clock()
+
+               self["Volume"] = self.volumeBar
                
                self["ServiceName"] = ServiceName(self.session.nav)
                
                
                self["ServiceName"] = ServiceName(self.session.nav)
                
@@ -79,6 +87,21 @@ class InfoBar(Screen):
        def     zapDown(self):
                self.servicelist.moveDown()
                self.servicelist.zap()
        def     zapDown(self):
                self.servicelist.moveDown()
                self.servicelist.zap()
+
+       def     volUp(self):
+               eDVBVolumecontrol.getInstance().volumeUp()
+               self.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
+
+       def     volDown(self):
+               eDVBVolumecontrol.getInstance().volumeDown()
+               self.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
+
+       def     volMute(self):
+               eDVBVolumecontrol.getInstance().volumeToggleMute()
+               self.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
+
+       def     quit(self):
+               quitMainloop()
                
        def instantRecord(self):
                self.session.open(MessageBox, "this would be an instant recording! do you really know what you're doing?!")
                
        def instantRecord(self):
                self.session.open(MessageBox, "this would be an instant recording! do you really know what you're doing?!")
@@ -105,3 +128,4 @@ class InfoBar(Screen):
        
        def showMovies(self):
                self.session.open(MovieSelection)
        
        def showMovies(self):
                self.session.open(MovieSelection)
+
index ae8bf92..c2d6261 100644 (file)
@@ -67,6 +67,7 @@ is usually caused by not marking PSignals as immutable.
 #include <lib/actions/action.h>
 #include <lib/gdi/gfont.h>
 #include <lib/gdi/epng.h>
 #include <lib/actions/action.h>
 #include <lib/gdi/gfont.h>
 #include <lib/gdi/epng.h>
+#include <lib/dvb/volume.h>
 
 extern void runMainloop();
 extern void quitMainloop();
 
 extern void runMainloop();
 extern void quitMainloop();
@@ -123,6 +124,7 @@ extern PSignal1<void,int> &keyPressedSignal();
 %include <lib/actions/action.h>
 %include <lib/gdi/gfont.h>
 %include <lib/gdi/epng.h>
 %include <lib/actions/action.h>
 %include <lib/gdi/gfont.h>
 %include <lib/gdi/epng.h>
+%include <lib/dvb/volume.h>
 
 %include <lib/gdi/gpixmap.h>
 /**************  eptr  **************/
 
 %include <lib/gdi/gpixmap.h>
 /**************  eptr  **************/