From 710b41f81d6de84abd2c0a099e71f154fd663f44 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 25 Mar 2006 17:04:56 +0000 Subject: [PATCH] Windows port --- Makefile | 24 ++++-- audio.cc | 201 --------------------------------------------- audio.h | 66 ++++++--------- audiomvp.cc | 231 ++++++++++++++++++++++++++++++++++++++++++++++++++++ audiomvp.h | 70 ++++++++++++++++ audiowin.cc | 135 ++++++++++++++++++++++++++++++ audiowin.h | 59 ++++++++++++++ main.cc | 13 ++- 8 files changed, 549 insertions(+), 250 deletions(-) create mode 100644 audiomvp.cc create mode 100644 audiomvp.h create mode 100644 audiowin.cc create mode 100644 audiowin.h diff --git a/Makefile b/Makefile index 9df68d4..ba18e92 100644 --- a/Makefile +++ b/Makefile @@ -11,14 +11,22 @@ LIBPATHS = LIBS = -lpthread -lrt CROSSLIBS = ../jpeg-6b/libjpeg.a -OBJECTS = main.o command.o log.o remote.o led.o mtd.o video.o audio.o tcp.o directory.o thread.o event.o \ - player.o demuxer.o stream.o vfeed.o afeed.o afeedr.o osd.o surface.o viewman.o vdr.o dsock.o box.o \ - recording.o channel.o message.o messagequeue.o rectimer.o vtimeredit.o voptionsmenu.o \ - view.o vinfo.o vwallpaper.o vvolume.o vrecordinglist.o vlivebanner.o vmute.o vtimerlist.o \ - vrecordingmenu.o vquestion.o vchannellist.o vwelcome.o vvideolive.o vvideorec.o vepgsettimer.o \ - vchannelselect.o vserverselect.o colour.o vconnect.o voptions.o vepg.o region.o \ - widget.o wselectlist.o wjpeg.o wsymbol.o wbutton.o woptionbox.o wtextbox.o i18n.o timers.o \ - fonts/helvB24.o fonts/helvB18.o +OBJECTS1 = main.o command.o log.o tcp.o dsock.o thread.o timers.o i18n.o \ + message.o messagequeue.o \ + vdr.o recording.o channel.o rectimer.o event.o directory.o \ + player.o demuxer.o stream.o vfeed.o afeed.o afeedr.o \ + viewman.o box.o region.o colour.o view.o \ + vinfo.o vwallpaper.o vvolume.o vrecordinglist.o vlivebanner.o vmute.o \ + vtimerlist.o vtimeredit.o voptionsmenu.o vrecordingmenu.o vquestion.o \ + vchannellist.o vwelcome.o vvideolive.o vvideorec.o vepgsettimer.o \ + vchannelselect.o vserverselect.o vconnect.o voptions.o vepg.o \ + widget.o wselectlist.o wjpeg.o wsymbol.o wbutton.o woptionbox.o wtextbox.o \ + fonts/helvB24.o fonts/helvB18.o + +OBJECTS2 = remote.o led.o mtd.o video.o audio.o osd.o surface.o \ + audiomvp.o audiowin.o + +OBJECTS = $(OBJECTS1) $(OBJECTS2) .PHONY: clean fresh all install strip diff --git a/audio.cc b/audio.cc index 116c1ca..0066afa 100644 --- a/audio.cc +++ b/audio.cc @@ -26,13 +26,6 @@ Audio::Audio() { if (instance) return; instance = this; - initted = 0; - fdAudio = 0; - streamType = 0; - volume = 20; - muted = 0; - userMute = 0; - systemMute = 0; } Audio::~Audio() @@ -45,200 +38,6 @@ Audio* Audio::getInstance() return instance; } -int Audio::init(UCHAR tstreamType) -{ - if (initted) return 0; - initted = 1; - -// if ((fdAudio = open("/dev/adec_mpg", O_RDWR | O_NONBLOCK)) < 0) return 0; - if ((fdAudio = open("/dev/adec_mpg", O_WRONLY)) < 0) return 0; - - streamType = tstreamType; - - if (!initAllParams()) - { - shutdown(); - return 0; - } - - unMute(); - - // Set the volume variable to what the hardware is set at now - int hwvol = -1; - int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol); - if (!hwvolFail) - { - volume = 20 - ((hwvol >> 16) & 0xFF); - if ((volume < 0) || (volume > 20)) volume = 20; - } - - return 1; -} - -int Audio::initAllParams() -{ - return (setStreamType(streamType) && setChannel() && setSource()); -} - -int Audio::shutdown() -{ - if (!initted) return 0; - initted = 0; - close(fdAudio); - return 1; -} - -int Audio::getFD() -{ - if (!initted) return 0; - - return fdAudio; -} - -int Audio::write(char *buf, int len) -{ - return 0; //write(fdAudio, buf, len); -} - -int Audio::setStreamType(UCHAR type) -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0; - return 1; -} - -int Audio::setChannel() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0; - return 1; -} - -int Audio::setSource() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0; - return 1; -} - -int Audio::sync() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0; - return 1; -} - -int Audio::play() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0; - return 1; -} - -int Audio::stop() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0; - return 1; -} - -int Audio::mute() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0; - Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE"); - - muted = 1; - return 1; -} - -int Audio::unMute() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0; - Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF"); - - muted = 0; - return 1; -} - -int Audio::pause() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0; - return 1; -} - -int Audio::unPause() -{ - if (!initted) return 0; - - if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0; - return 1; -} - -int Audio::reset() -{ - if (!initted) return 0; -//test(); - if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0; - if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0; - - doMuting(); - return 1; -} - -int Audio::setVolume(int tvolume) -{ - // parameter: 0 for silence, 20 for full - if ((tvolume < 0) || (tvolume > 20)) return 0; - -// volume = 2 * (20 - volume); -// Right, that one was rubbish... 0-10 were almost -// inaudible, 11-20 did what should have been done -// over the whole 0-20 range - - tvolume = 20 - tvolume; - - unsigned long vol = (tvolume << 24) | (tvolume << 16); - - Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol); - Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume); - - if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0; - return 1; -} - -#ifdef DEV -int Audio::test() -{ -// ULLONG stc = 0; -// return ioctl(fdAudio, AV_SET_AUD_STC, &stc); - - aud_sync_parms_t a; - a.parm1 = 0; - a.parm2 = 0; - - int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a); - - - printf("Audio sync disable = %i\n", b); // is in a DEV block - - return 1; - - -} -#endif - int Audio::volumeUp() { if (!initted) return 0; diff --git a/audio.h b/audio.h index 5b2877b..b3c0c5a 100644 --- a/audio.h +++ b/audio.h @@ -24,68 +24,56 @@ #define AUDIO_H #include -#include -#include -#include - #include "defines.h" #include "log.h" -#include "stb.h" class Audio { public: Audio(); - ~Audio(); + virtual ~Audio(); static Audio* getInstance(); - int init(UCHAR streamType); - int shutdown(); + virtual int init(UCHAR streamType)=0; + virtual int shutdown()=0; + virtual int setStreamType(UCHAR streamType)=0; + virtual int setChannel()=0; + virtual int setSource()=0; + virtual int sync()=0; + virtual int play()=0; + virtual int stop()=0; + virtual int pause()=0; + virtual int unPause()=0; + virtual int reset()=0; + virtual int setVolume(int volume)=0; + virtual int mute()=0; + virtual int unMute()=0; + virtual int write(char *buf, int len)=0; + virtual int getFD()=0; // FIXME MVP specific - // Audio stream type - const static UCHAR MPEG2_PES = 2; - const static UCHAR MPEG1_PES = 3; // unused - - int setStreamType(UCHAR streamType); - int setChannel(); - int setSource(); - int sync(); - int play(); - int stop(); - int pause(); - int unPause(); - int reset(); - int setVolume(int volume); int volumeUp(); int volumeDown(); int getVolume(); int toggleUserMute(); int systemMuteOn(); int systemMuteOff(); -#ifdef DEV - int test(); -#endif + int doMuting(); - int write(char *buf, int len); + // Audio stream type // FIXME these are MVP specific (probably!) + const static UCHAR MPEG2_PES = 2; + const static UCHAR MPEG1_PES = 3; // unused - int getFD(); +#ifdef DEV + virtual int test()=0; +#endif - int doMuting(); - private: + protected: static Audio* instance; int initted; - int volume; - UCHAR muted; UCHAR userMute; UCHAR systemMute; - - int mute(); - int unMute(); - int initAllParams(); - - UCHAR streamType; - - int fdAudio; + UCHAR muted; + int volume; }; #endif diff --git a/audiomvp.cc b/audiomvp.cc new file mode 100644 index 0000000..dbd5110 --- /dev/null +++ b/audiomvp.cc @@ -0,0 +1,231 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "audiomvp.h" + +AudioMVP::AudioMVP() +{ + if (instance) return; + initted = 0; + fdAudio = 0; + streamType = 0; + volume = 20; + muted = 0; + userMute = 0; + systemMute = 0; +} + +AudioMVP::~AudioMVP() +{ +} + +int AudioMVP::init(UCHAR tstreamType) +{ + if (initted) return 0; + initted = 1; + +// if ((fdAudio = open("/dev/adec_mpg", O_RDWR | O_NONBLOCK)) < 0) return 0; + if ((fdAudio = open("/dev/adec_mpg", O_WRONLY)) < 0) return 0; + + streamType = tstreamType; + + if (!initAllParams()) + { + shutdown(); + return 0; + } + + unMute(); + + // Set the volume variable to what the hardware is set at now + int hwvol = -1; + int hwvolFail = ioctl(fdAudio, AV_GET_AUD_VOLUME, &hwvol); + if (!hwvolFail) + { + volume = 20 - ((hwvol >> 16) & 0xFF); + if ((volume < 0) || (volume > 20)) volume = 20; + } + + return 1; +} + +int AudioMVP::initAllParams() +{ + return (setStreamType(streamType) && setChannel() && setSource()); +} + +int AudioMVP::shutdown() +{ + if (!initted) return 0; + initted = 0; + close(fdAudio); + return 1; +} + +int AudioMVP::getFD() +{ + if (!initted) return 0; + + return fdAudio; +} + +int AudioMVP::write(char *buf, int len) +{ + return 0; //write(fdAudio, buf, len); +} + +int AudioMVP::setStreamType(UCHAR type) +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0; + return 1; +} + +int AudioMVP::setChannel() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0; + return 1; +} + +int AudioMVP::setSource() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0; + return 1; +} + +int AudioMVP::sync() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0; + return 1; +} + +int AudioMVP::play() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0; + return 1; +} + +int AudioMVP::stop() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0; + return 1; +} + +int AudioMVP::mute() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_MUTE, 1) != 0) return 0; + Log::getInstance()->log("Audio", Log::DEBUG, "MUTE MUTE MUTE"); + + muted = 1; + return 1; +} + +int AudioMVP::unMute() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_MUTE, 0) != 0) return 0; + Log::getInstance()->log("Audio", Log::DEBUG, "MUTE OFF OFF OFF"); + + muted = 0; + return 1; +} + +int AudioMVP::pause() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_PAUSE, 1) != 0) return 0; + return 1; +} + +int AudioMVP::unPause() +{ + if (!initted) return 0; + + if (ioctl(fdAudio, AV_SET_AUD_UNPAUSE, 1) != 0) return 0; + return 1; +} + +int AudioMVP::reset() +{ + if (!initted) return 0; +//test(); + if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0; + if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0; + + doMuting(); + return 1; +} + +int AudioMVP::setVolume(int tvolume) +{ + // parameter: 0 for silence, 20 for full + if ((tvolume < 0) || (tvolume > 20)) return 0; + +// volume = 2 * (20 - volume); +// Right, that one was rubbish... 0-10 were almost +// inaudible, 11-20 did what should have been done +// over the whole 0-20 range + + tvolume = 20 - tvolume; + + unsigned long vol = (tvolume << 24) | (tvolume << 16); + + Log::getInstance()->log("Audio", Log::DEBUG, "%lx", vol); + Log::getInstance()->log("Audio", Log::DEBUG, "%i", tvolume); + + if (ioctl(fdAudio, AV_SET_AUD_VOLUME, &vol) != 0) return 0; + return 1; +} + +#ifdef DEV +int AudioMVP::test() +{ +// ULLONG stc = 0; +// return ioctl(fdAudio, AV_SET_AUD_STC, &stc); + + aud_sync_parms_t a; + a.parm1 = 0; + a.parm2 = 0; + + int b = ioctl(fdAudio, AV_SET_AUD_DISABLE_SYNC, &a); + + + printf("Audio sync disable = %i\n", b); // is in a DEV block + + return 1; + + +} +#endif diff --git a/audiomvp.h b/audiomvp.h new file mode 100644 index 0000000..7b48a10 --- /dev/null +++ b/audiomvp.h @@ -0,0 +1,70 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +// Thanks to Jon Gettler and BtB for all the ioctl information + +#ifndef AUDIOMVP_H +#define AUDIOMVP_H + +#include +#include +#include +#include + +#include "defines.h" +#include "log.h" +#include "stb.h" +#include "audio.h" + +class AudioMVP : public Audio +{ + public: + AudioMVP(); + ~AudioMVP(); + + int init(UCHAR streamType); + int shutdown(); + + int setStreamType(UCHAR streamType); + int setChannel(); + int setSource(); + int sync(); + int play(); + int stop(); + int pause(); + int unPause(); + int reset(); + int setVolume(int volume); + int mute(); + int unMute(); + int write(char *buf, int len); + int getFD(); + +#ifdef DEV + int test(); +#endif + + private: + int initAllParams(); + UCHAR streamType; + int fdAudio; +}; + +#endif diff --git a/audiowin.cc b/audiowin.cc new file mode 100644 index 0000000..75019e3 --- /dev/null +++ b/audiowin.cc @@ -0,0 +1,135 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "audiowin.h" + +AudioWin::AudioWin() +{ + if (instance) return; + initted = 0; +} + +AudioWin::~AudioWin() +{ +} + +int AudioWin::init(UCHAR tstreamType) +{ + if (initted) return 0; + initted = 1; + return 1; +} + +int AudioWin::shutdown() +{ + if (!initted) return 0; + initted = 0; + return 1; +} + +int AudioWin::getFD() +{ + return 0; +} + +int AudioWin::write(char *buf, int len) +{ + return 0; //write(fdAudio, buf, len); +} + +int AudioWin::setStreamType(UCHAR type) +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::setChannel() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::setSource() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::sync() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::play() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::stop() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::pause() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::unPause() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::reset() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::setVolume(int tvolume) +{ + // parameter: 0 for silence, 20 for full + if ((tvolume < 0) || (tvolume > 20)) return 0; + return 1; +} + +int AudioWin::mute() +{ + if (!initted) return 0; + return 1; +} + +int AudioWin::unMute() +{ + if (!initted) return 0; + return 1; +} + +#ifdef DEV +int AudioWin::test() +{ + return 0; +} +#endif diff --git a/audiowin.h b/audiowin.h new file mode 100644 index 0000000..823fb65 --- /dev/null +++ b/audiowin.h @@ -0,0 +1,59 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +// Thanks to Jon Gettler and BtB for all the ioctl information + +#ifndef AUDIOWIN_H +#define AUDIOWIN_H + +#include "defines.h" +#include "log.h" +#include "audio.h" + +class AudioWin : public Audio +{ + public: + AudioWin(); + ~AudioWin(); + + int init(UCHAR streamType); + int shutdown(); + + int setStreamType(UCHAR streamType); + int setChannel(); + int setSource(); + int sync(); + int play(); + int stop(); + int pause(); + int unPause(); + int reset(); + int setVolume(int volume); + int mute(); + int unMute(); + int write(char *buf, int len); + int getFD(); + +#ifdef DEV + int test(); +#endif +}; + +#endif diff --git a/main.cc b/main.cc index 84dafac..f403e5e 100644 --- a/main.cc +++ b/main.cc @@ -32,12 +32,17 @@ #include "mtd.h" #include "timers.h" #include "video.h" -#include "audio.h" #include "vdr.h" #include "osd.h" #include "viewman.h" #include "command.h" +#ifndef WIN32 + #include "audiomvp.h" +#else + #include "audiowin.h" +#endif + void sighandler(int signalReceived); void shutdown(int code); @@ -70,7 +75,11 @@ int main(int argc, char** argv) osd = new Osd(); vdr = new VDR(); video = new Video(); - audio = new Audio(); +#ifndef WIN32 + audio = new AudioMVP(); +#else + audio = new AudioWin(); +#endif viewman = new ViewMan(); command = new Command(); -- 2.39.5