aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>2005-08-13 19:51:17 +0000
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>2005-08-13 19:51:17 +0000
commit0877ce3b6f6cee972818a8c0a2d1bc862c8482be (patch)
tree91d23f198dc8dba893cf47ac3d2bad660da1b366 /lib
parenta072a06516d83d3a11c52544bf2f7cb8ab567b4e (diff)
downloadenigma2-0877ce3b6f6cee972818a8c0a2d1bc862c8482be.tar.gz
enigma2-0877ce3b6f6cee972818a8c0a2d1bc862c8482be.zip
adding volume control
Diffstat (limited to 'lib')
-rw-r--r--lib/dvb/Makefile.am2
-rw-r--r--lib/dvb/volume.cpp136
-rw-r--r--lib/dvb/volume.h36
-rw-r--r--lib/python/Components/VolumeBar.py7
-rw-r--r--lib/python/Screens/InfoBar.py26
-rw-r--r--lib/python/enigma_python.i2
6 files changed, 205 insertions, 4 deletions
diff --git a/lib/dvb/Makefile.am b/lib/dvb/Makefile.am
index ca200102..797e54d4 100644
--- a/lib/dvb/Makefile.am
+++ b/lib/dvb/Makefile.am
@@ -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 \
- 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
index 00000000..bc3d6574
--- /dev/null
+++ b/lib/dvb/volume.cpp
@@ -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
index 00000000..cee31406
--- /dev/null
+++ b/lib/dvb/volume.h
@@ -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
diff --git a/lib/python/Components/VolumeBar.py b/lib/python/Components/VolumeBar.py
index a6da5980..63771e24 100644
--- a/lib/python/Components/VolumeBar.py
+++ b/lib/python/Components/VolumeBar.py
@@ -1,12 +1,15 @@
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):
-
def __init__(self):
- GUIComponent.__init__(self)
VariableValue.__init__(self)
+ GUIComponent.__init__(self)
def createWidget(self, parent):
g = eSlider(parent)
diff --git a/lib/python/Screens/InfoBar.py b/lib/python/Screens/InfoBar.py
index be6b65c9..6f8dde1b 100644
--- a/lib/python/Screens/InfoBar.py
+++ b/lib/python/Screens/InfoBar.py
@@ -1,6 +1,7 @@
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
@@ -22,7 +23,8 @@ class InfoBar(Screen):
#instantiate forever
self.servicelist = self.session.instantiateDialog(ChannelSelection)
-
+ self.volumeBar = VolumeBar()
+
self["actions"] = ActionMap( [ "InfobarActions" ],
{
"switchChannelUp": self.switchChannelUp,
@@ -30,14 +32,20 @@ class InfoBar(Screen):
"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,
+ "quit": self.quit
})
# self["okbutton"] = Button("mainMenu", [self.mainMenu])
self["CurrentTime"] = Clock()
+
+ self["Volume"] = self.volumeBar
self["ServiceName"] = ServiceName(self.session.nav)
@@ -79,6 +87,21 @@ class InfoBar(Screen):
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?!")
@@ -105,3 +128,4 @@ class InfoBar(Screen):
def showMovies(self):
self.session.open(MovieSelection)
+
diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i
index ae8bf92d..c2d62613 100644
--- a/lib/python/enigma_python.i
+++ b/lib/python/enigma_python.i
@@ -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/dvb/volume.h>
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/dvb/volume.h>
%include <lib/gdi/gpixmap.h>
/************** eptr **************/