From 84c38c6cdb516824395f2e311aee0f4f19083515 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Fri, 19 May 2006 20:32:07 +0000 Subject: [PATCH] Windows port --- osdwin.cc | 34 +- recman.h | 6 + recording.cc | 22 +- remotewin.cc | 424 ++++++++--------- videowin.cc | 22 +- videowin.h | 5 + vompreswin.h | 62 +-- vompwin.rc | 88 ++-- winmain.cc | 1223 +++++++++++++++++++++++++++----------------------- 9 files changed, 1020 insertions(+), 866 deletions(-) diff --git a/osdwin.cc b/osdwin.cc index 962017c..2df6fe1 100644 --- a/osdwin.cc +++ b/osdwin.cc @@ -21,7 +21,7 @@ #include "osdwin.h" #include "mtd.h" -#include "video.h" +#include "videowin.h" #include "surfacewin.h" #include "dsallocator.h" @@ -75,7 +75,7 @@ int OsdWin::init(void* device) d3dparas.Windowed=TRUE; d3dparas.SwapEffect=D3DSWAPEFFECT_COPY; if (d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,*((HWND*) device), - D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dparas,&d3ddevice)!=D3D_OK) { + D3DCREATE_SOFTWARE_VERTEXPROCESSING |D3DCREATE_MULTITHREADED,&d3dparas,&d3ddevice)!=D3D_OK) { Log::getInstance()->log("OSD", Log::WARN, "Could not create Direct3D9 device!"); return 0; } @@ -188,8 +188,34 @@ void OsdWin::InternalRendering(LPDIRECT3DSURFACE9 present){ if (external_driving) { //Copy video to Backbuffer if (present!=NULL) { - d3ddevice->StretchRect(present,NULL,d3drtsurf ,NULL,D3DTEXF_LINEAR); - + VideoWin* video =(VideoWin*) Video::getInstance(); + /*calculating destination rect */ + RECT destrect={0,0,video->getScreenWidth(),video->getScreenHeight()}; + UCHAR mode=video->getMode(); + switch (mode) { + case Video::EIGHTH: + destrect.right=destrect.right/2; + destrect.bottom=destrect.bottom/2; + case Video::QUARTER: + destrect.right=destrect.right/2+video->getPosx()*2; + destrect.bottom=destrect.bottom/2+video->getPosy()*2; + destrect.left=video->getPosx()*2; + destrect.top=video->getPosy()*2; + d3ddevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0); + break; + }; + D3DSURFACE_DESC surf_desc; + present->GetDesc(&surf_desc);//for chop sides + RECT sourcerect= {0,0,surf_desc.Width,surf_desc.Height}; + if (video->getPseudoTVsize()==Video::ASPECT4X3 + && video->getMode()==Video::NORMAL + && video->getAspectRatio()==Video::ASPECT16X9) { + unsigned int correction=((double) (surf_desc.Width))*4.*9./3./16.; + sourcerect.left=(surf_desc.Width-correction)/2; + sourcerect.right=sourcerect.left+correction; + } + + d3ddevice->StretchRect(present,&sourcerect,d3drtsurf ,&destrect,D3DTEXF_LINEAR); } } else { //Clear Background diff --git a/recman.h b/recman.h index 81a01d7..68b8691 100644 --- a/recman.h +++ b/recman.h @@ -23,6 +23,12 @@ #include +#ifdef WIN32 +#include +#include +#define PATH_MAX FILENAME_MAX +#endif + #include "directory.h" #include "recording.h" diff --git a/recording.cc b/recording.cc index 365b532..8272fd7 100644 --- a/recording.cc +++ b/recording.cc @@ -30,8 +30,8 @@ Recording::Recording() Recording::~Recording() { - if (progName) { free(progName); progName = NULL; } - if (fileName) { free(fileName); fileName = NULL; } + if (progName) { delete[] progName; progName = NULL; } + if (fileName) { delete[] fileName; fileName = NULL; } index = -1; // just in case } @@ -57,22 +57,16 @@ void Recording::setStartTime(ULONG tstartTime) void Recording::setProgName(char* tProgName) { - if (progName) free(progName); + if (progName) delete[] progName; - if (asprintf(&progName, tProgName) == -1) - { - free(progName); - progName = NULL; - } + progName = new char[strlen(tProgName) + 1]; + if (progName) strcpy(progName, tProgName); } void Recording::setFileName(char* tFileName) { - if (fileName) free(fileName); + if (fileName) delete[] fileName; - if (asprintf(&fileName, tFileName) == -1) - { - free(fileName); - fileName = NULL; - } + fileName = new char[strlen(tFileName) + 1]; + if (fileName) strcpy(fileName, tFileName); } diff --git a/remotewin.cc b/remotewin.cc index 37e1fac..1d6fbc3 100644 --- a/remotewin.cc +++ b/remotewin.cc @@ -1,211 +1,213 @@ -/* - 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 "remotewin.h" - - -RemoteWin::RemoteWin() -{ - initted = 0; - curevent=NA_NONE; - signal=false; -} - -RemoteWin::~RemoteWin() -{ -} - -int RemoteWin::init(char* devName) -{ - if (initted) return 0; - initted = 1; - event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL); - - - return 1; -} - -int RemoteWin::shutdown() -{ - if (!initted) return 0; - CloseHandle(event); - initted = 0; - return 1; -} - -UCHAR RemoteWin::getButtonPress(int waitType) -{ - /* how = 0 - block - how = 1 - start new wait - how = 2 - continue wait - how = 3 - no wait - */ - DWORD wait; - - if (curevent!=NA_NONE) { - UCHAR temp=curevent; - curevent=NA_NONE; - return temp; - } - if (waitType==3) { - return NA_NONE; - } - if (waitType==0) { - wait=INFINITE; - } else { //We do not distingish between 2 and 3 - wait=1000; - - } - WaitForSingleObject(event,wait); - ResetEvent(event); - if (curevent==NA_NONE) { - if (signal) { - signal=false; - return NA_SIGNAL; //Since we have no signals on windows, we simulate this - } else { - return NA_NONE; - } - } - UCHAR temp2=curevent; - curevent=NA_NONE; - return temp2; - -} - -void RemoteWin::clearBuffer() -{ -} - -int RemoteWin::ReceiveButtonVK(UINT button) { - UCHAR pb=NA_NONE; - //should we use a translation table ? No APPCOMMAND iS DWORD! - switch (button) { //Processing VK_Messages - case VK_DOWN: - pb=DOWN; break; - case VK_RETURN: - case VK_SPACE: - pb=OK;break; - case VK_LEFT: - pb=LEFT;break; - case '9': - case VK_NUMPAD9: - pb=NINE;break; - case '8': - case VK_NUMPAD8: - pb=EIGHT;break; - case '7': - case VK_NUMPAD7: - pb=SEVEN;break; - case '6': - case VK_NUMPAD6: - pb=SIX;break; - case '5': - case VK_NUMPAD5: - pb=FIVE;break; - case '4': - case VK_NUMPAD4: - pb=FOUR;break; - case '3': - case VK_NUMPAD3: - pb=THREE;break; - case '2': - case VK_NUMPAD2: - pb=TWO;break; - case '1': - case VK_NUMPAD1: - pb=ONE;break; - case '0': - case VK_NUMPAD0: - pb=ZERO;break; - case VK_RIGHT: - pb=RIGHT;break; - case VK_UP: - pb=UP;break; - case VK_MULTIPLY: - pb=STAR;break; - case 'J'://j for JUMP TO instead of go to - pb=GO;break; - case VK_ESCAPE: - pb=POWER;break; - case VK_BACK: - pb=BACK;break; - case 'M': - pb=MENU;break; - case 'R': - pb=RED;break; - case 'G': - pb=GREEN;break; - case 'Y': - pb=YELLOW;break; - case 'B': - pb=BLUE; break; - - - }; //All other commands are process via APPCOMMAND_MESSAGES - if (pb==NA_NONE) return 0; - curevent=pb; - //PulseEvent(event); - SetEvent(event); - return 1; -} - -int RemoteWin::ReceiveButtonAP(UINT button) { - UCHAR pb=NA_NONE; - //should we use a translation table ? No APPCOMMAND iS DWORD! - switch (button) { //Processing VK_Messages - case APPCOMMAND_MEDIA_CHANNEL_DOWN: - pb=CHANNELDOWN;break; - case APPCOMMAND_MEDIA_CHANNEL_UP: - pb=CHANNELUP;break; - case APPCOMMAND_MEDIA_FAST_FORWARD: - pb=FORWARD;break; - case APPCOMMAND_VOLUME_MUTE: - pb=MUTE;break; - case APPCOMMAND_MEDIA_PAUSE: - pb=PAUSE;break; - case APPCOMMAND_MEDIA_PLAY: - pb=PLAY;break; - case APPCOMMAND_MEDIA_RECORD: - pb=RECORD;break; - case APPCOMMAND_MEDIA_PREVIOUSTRACK: - pb=SKIPBACK;break; - case APPCOMMAND_MEDIA_REWIND: - pb=REVERSE;break; - case APPCOMMAND_MEDIA_NEXTTRACK: - pb=SKIPFORWARD;break; - case APPCOMMAND_MEDIA_STOP: - pb=STOP;break; - case APPCOMMAND_VOLUME_DOWN: - pb=VOLUMEDOWN;break; - case APPCOMMAND_VOLUME_UP: - pb=VOLUMEUP;break; - }; - if (pb==NA_NONE) return 0; - curevent=pb; - //PulseEvent(event); - SetEvent(event); - return 1; -} - -void RemoteWin::Signal() { - signal=true; - //PulseEvent(event); - SetEvent(event); -} +/* + 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 "remotewin.h" +#include "vompreswin.h" + + +RemoteWin::RemoteWin() +{ + initted = 0; + curevent=NA_NONE; + signal=false; +} + +RemoteWin::~RemoteWin() +{ +} + +int RemoteWin::init(char* devName) +{ + if (initted) return 0; + initted = 1; + event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL); + + + return 1; +} + +int RemoteWin::shutdown() +{ + if (!initted) return 0; + CloseHandle(event); + initted = 0; + return 1; +} + +UCHAR RemoteWin::getButtonPress(int waitType) +{ + /* how = 0 - block + how = 1 - start new wait + how = 2 - continue wait + how = 3 - no wait + */ + DWORD wait; + + if (curevent!=NA_NONE) { + UCHAR temp=curevent; + curevent=NA_NONE; + return temp; + } + if (waitType==3) { + return NA_NONE; + } + if (waitType==0) { + wait=INFINITE; + } else { //We do not distingish between 2 and 3 + wait=1000; + + } + WaitForSingleObject(event,wait); + ResetEvent(event); + if (curevent==NA_NONE) { + if (signal) { + signal=false; + return NA_SIGNAL; //Since we have no signals on windows, we simulate this + } else { + return NA_NONE; + } + } + UCHAR temp2=curevent; + curevent=NA_NONE; + return temp2; + +} + +void RemoteWin::clearBuffer() +{ +} + +int RemoteWin::ReceiveButtonVK(UINT button) { + UCHAR pb=NA_NONE; + //should we use a translation table ? No APPCOMMAND iS DWORD! + switch (button) { //Processing VK_Messages + case VK_DOWN: + pb=DOWN; break; + case VK_RETURN: + case VK_SPACE: + pb=OK;break; + case VK_LEFT: + pb=LEFT;break; + case '9': + case VK_NUMPAD9: + pb=NINE;break; + case '8': + case VK_NUMPAD8: + pb=EIGHT;break; + case '7': + case VK_NUMPAD7: + pb=SEVEN;break; + case '6': + case VK_NUMPAD6: + pb=SIX;break; + case '5': + case VK_NUMPAD5: + pb=FIVE;break; + case '4': + case VK_NUMPAD4: + pb=FOUR;break; + case '3': + case VK_NUMPAD3: + pb=THREE;break; + case '2': + case VK_NUMPAD2: + pb=TWO;break; + case '1': + case VK_NUMPAD1: + pb=ONE;break; + case '0': + case VK_NUMPAD0: + pb=ZERO;break; + case VK_RIGHT: + pb=RIGHT;break; + case VK_UP: + pb=UP;break; + case VK_MULTIPLY: + pb=STAR;break; + case 'J'://j for JUMP TO instead of go to + pb=GO;break; + case VK_ESCAPE: + pb=POWER;break; + case VK_BACK: + pb=BACK;break; + case 'M': + pb=MENU;break; + case 'R': + pb=RED;break; + case 'G': + pb=GREEN;break; + case 'Y': + pb=YELLOW;break; + case 'B': + pb=BLUE; break; + + + }; //All other commands are process via APPCOMMAND_MESSAGES + if (pb==NA_NONE) return 0; + curevent=pb; + //PulseEvent(event); + SetEvent(event); + return 1; +} + +int RemoteWin::ReceiveButtonAP(UINT button) { + UCHAR pb=NA_NONE; + //should we use a translation table ? No APPCOMMAND iS DWORD! + switch (button) { //Processing VK_Messages + case APPCOMMAND_MEDIA_CHANNEL_DOWN: + pb=CHANNELDOWN;break; + case APPCOMMAND_MEDIA_CHANNEL_UP: + pb=CHANNELUP;break; + case APPCOMMAND_MEDIA_FAST_FORWARD: + pb=FORWARD;break; + case APPCOMMAND_VOLUME_MUTE: + pb=MUTE;break; + case APPCOMMAND_MEDIA_PAUSE: + pb=PAUSE;break; + case APPCOMMAND_MEDIA_PLAY: + pb=PLAY;break; + case APPCOMMAND_MEDIA_RECORD: + pb=RECORD;break; + case APPCOMMAND_MEDIA_PREVIOUSTRACK: + pb=SKIPBACK;break; + case APPCOMMAND_MEDIA_REWIND: + pb=REVERSE;break; + case APPCOMMAND_MEDIA_NEXTTRACK: + pb=SKIPFORWARD;break; + case APPCOMMAND_MEDIA_STOP: + pb=STOP;break; + case APPCOMMAND_VOLUME_DOWN: + pb=VOLUMEDOWN;break; + case APPCOMMAND_VOLUME_UP: + pb=VOLUMEUP;break; + }; + if (pb==NA_NONE) return 0; + curevent=pb; + //PulseEvent(event); + SetEvent(event); + return 1; +} + +void RemoteWin::Signal() { + signal=true; + //PulseEvent(event); + SetEvent(event); +} + diff --git a/videowin.cc b/videowin.cc index 8c1962d..c1e3356 100644 --- a/videowin.cc +++ b/videowin.cc @@ -45,12 +45,16 @@ VideoWin::VideoWin() startoffset=0; lastrefaudiotime=0; lastrefvideotime=0; + lastreftimeBYTE=0; + lastreftimeRT=0; firstsynched=false; cur_audio_media_sample=NULL; cur_video_media_sample=NULL; videoon=true; audioon=true; pseudotvsize=0; + videoposx=0; + videoposy=0; @@ -72,7 +76,9 @@ int VideoWin::init(UCHAR tformat) initted = 1; tvsize=Video::ASPECT16X9; //Internally Vomp should think we are a 16:9 TV - + videoposx=0; + videoposy=0; + if (!setFormat(tformat)){ shutdown(); return 0; } return 1; } @@ -141,6 +147,8 @@ int VideoWin::setMode(UCHAR tmode) if ((tmode != NORMAL) && (tmode != LETTERBOX) && (tmode != UNKNOWN2) && (tmode != QUARTER) && (tmode != EIGHTH) && (tmode != ZOOM) && (tmode != UNKNOWN6)) return 0; mode = tmode; + videoposx=0; + videoposy=0; AdjustWindow(); return 1; @@ -166,7 +174,10 @@ int VideoWin::setSource() int VideoWin::setPosition(int x, int y) { if (!initted) return 0; - + if (mode==QUARTER || mode==EIGHTH) { + videoposx=x; + videoposy=y; + } return 1; } @@ -301,7 +312,8 @@ int VideoWin::stop() int VideoWin::reset() { if (!initted) return 0; - + videoposx=0; + videoposy=0; return 1; } @@ -665,6 +677,10 @@ void VideoWin::ResetTimeOffsets() { startoffset=0; lastrefaudiotime=0; lastrefvideotime=0; + lastreftimeBYTE=0; + lastreftimeRT=0; + + } diff --git a/videowin.h b/videowin.h index 36e8052..9897112 100644 --- a/videowin.h +++ b/videowin.h @@ -91,6 +91,9 @@ class VideoWin : public Video void turnVideoOn(){videoon=true;}; void turnVideoOff(){videoon=false;}; + unsigned int getPosx() {return videoposx;}; + unsigned int getPosy() {return videoposy;}; + #ifdef DEV int test(); int test2(); @@ -122,6 +125,8 @@ private: UCHAR pseudotvsize; REFERENCE_TIME lastreftimeRT; ULLONG lastreftimeBYTE; + unsigned int videoposx; + unsigned int videoposy; #ifdef DS_DEBUG DWORD graphidentifier; #endif diff --git a/vompreswin.h b/vompreswin.h index 28facbe..1178760 100644 --- a/vompreswin.h +++ b/vompreswin.h @@ -1,30 +1,32 @@ - -/* - 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 -*/ - -#ifndef VOMPRESWIN_H -#define _WIN32_WINNT 0x501 - -#include -#include -#define VOMPACCELERATOR 1 - -#define VOMPRESWIN_H -#endif + +/* + 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 +*/ + +#ifndef VOMPRESWIN_H +#define _WIN32_WINNT 0x501 + +#include +#include +#define VOMPACCELERATOR 1 +#define VOMP_FULL_SCREEN 101 + +#define VOMPRESWIN_H +#endif + diff --git a/vompwin.rc b/vompwin.rc index 103371a..7d0fbf5 100644 --- a/vompwin.rc +++ b/vompwin.rc @@ -1,43 +1,45 @@ - - -#include "vompreswin.h" - - - -//1 TEXTINCLUDE -//BEGIN -// "#include ""winsock2.h""\r\n" -// "#include ""vompreswin.h""\r\n" -// "\0" -//END - - - - - -VOMPACCELERATOR ACCELERATORS -BEGIN - VK_INSERT, APPCOMMAND_MEDIA_CHANNEL_DOWN, VIRTKEY, CONTROL, - NOINVERT - VK_INSERT, APPCOMMAND_MEDIA_CHANNEL_DOWN, VIRTKEY, NOINVERT - VK_PRIOR, APPCOMMAND_MEDIA_CHANNEL_DOWN, VIRTKEY, NOINVERT - VK_OEM_PLUS, APPCOMMAND_MEDIA_CHANNEL_UP, VIRTKEY, CONTROL, NOINVERT - VK_OEM_PLUS, APPCOMMAND_MEDIA_CHANNEL_UP, VIRTKEY, NOINVERT - VK_NEXT, APPCOMMAND_MEDIA_CHANNEL_UP, VIRTKEY, NOINVERT - "F", APPCOMMAND_MEDIA_FAST_FORWARD, VIRTKEY, SHIFT, CONTROL, - NOINVERT - VK_F8, APPCOMMAND_VOLUME_MUTE, VIRTKEY, NOINVERT - "P", APPCOMMAND_MEDIA_PAUSE, VIRTKEY, CONTROL, NOINVERT - "P", APPCOMMAND_MEDIA_PLAY, VIRTKEY, SHIFT, CONTROL, - NOINVERT - "R", APPCOMMAND_MEDIA_RECORD, VIRTKEY, CONTROL, NOINVERT - "B", APPCOMMAND_MEDIA_PREVIOUSTRACK, VIRTKEY, CONTROL, - NOINVERT - "F", APPCOMMAND_MEDIA_NEXTTRACK, VIRTKEY, CONTROL, NOINVERT - "S", APPCOMMAND_MEDIA_STOP, VIRTKEY, CONTROL, NOINVERT - VK_F9, APPCOMMAND_VOLUME_DOWN, VIRTKEY, NOINVERT - VK_F10, APPCOMMAND_VOLUME_UP, VIRTKEY, NOINVERT -END - - - + + +#include "vompreswin.h" + + + +//1 TEXTINCLUDE +//BEGIN +// "#include ""winsock2.h""\r\n" +// "#include ""vompreswin.h""\r\n" +// "\0" +//END + + + + + +VOMPACCELERATOR ACCELERATORS +BEGIN + VK_INSERT, APPCOMMAND_MEDIA_CHANNEL_DOWN, VIRTKEY, CONTROL, + NOINVERT + VK_INSERT, APPCOMMAND_MEDIA_CHANNEL_DOWN, VIRTKEY, NOINVERT + VK_PRIOR, APPCOMMAND_MEDIA_CHANNEL_DOWN, VIRTKEY, NOINVERT + VK_OEM_PLUS, APPCOMMAND_MEDIA_CHANNEL_UP, VIRTKEY, CONTROL, NOINVERT + VK_OEM_PLUS, APPCOMMAND_MEDIA_CHANNEL_UP, VIRTKEY, NOINVERT + VK_NEXT, APPCOMMAND_MEDIA_CHANNEL_UP, VIRTKEY, NOINVERT + "F", APPCOMMAND_MEDIA_FAST_FORWARD, VIRTKEY, SHIFT, CONTROL, + NOINVERT + VK_F8, APPCOMMAND_VOLUME_MUTE, VIRTKEY, NOINVERT + "P", APPCOMMAND_MEDIA_PAUSE, VIRTKEY, CONTROL, NOINVERT + "P", APPCOMMAND_MEDIA_PLAY, VIRTKEY, SHIFT, CONTROL, + NOINVERT + "R", APPCOMMAND_MEDIA_RECORD, VIRTKEY, CONTROL, NOINVERT + "B", APPCOMMAND_MEDIA_PREVIOUSTRACK, VIRTKEY, CONTROL, + NOINVERT + "F", APPCOMMAND_MEDIA_NEXTTRACK, VIRTKEY, CONTROL, NOINVERT + "S", APPCOMMAND_MEDIA_STOP, VIRTKEY, CONTROL, NOINVERT + VK_F9, APPCOMMAND_VOLUME_DOWN, VIRTKEY, NOINVERT + VK_F10, APPCOMMAND_VOLUME_UP, VIRTKEY, NOINVERT + VK_RETURN, VOMP_FULL_SCREEN, VIRTKEY, ALT, NOINVERT +END + + + + diff --git a/winmain.cc b/winmain.cc index f6053fa..e6e9459 100644 --- a/winmain.cc +++ b/winmain.cc @@ -1,566 +1,667 @@ -/* - 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 -*/ -#ifdef WIN32 -#include -#include -#include -#include - -#define _WIN32_WINNT 0x501 -#include -#include - -#include "vompreswin.h" - -#include "defines.h" -#include "log.h" -#include "remotewin.h" -#include "ledwin.h" -#include "mtdwin.h" -#include "timers.h" -#include "videowin.h" -#include "audiowin.h" -#include "vdr.h" -#include "osdwin.h" -#include "viewman.h" -#include "command.h" - -void sighandler(int signalReceived); -void shutdown(int code); - -// Global variables -------------------------------------------------------------------------------------------------- -int debugEnabled = 0; -Log* logger; -Remote* remote; -Mtd* mtd; -Led* led; -Osd* osd; -Timers* timers; -ViewMan* viewman; -Command* command; -VDR* vdr; -Video* video; -Audio* audio; - - +/* + 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 +*/ +#ifdef WIN32 +#include +#include +#include +#include + +#define _WIN32_WINNT 0x501 +#include +#include + +#include "vompreswin.h" + +#include "defines.h" +#include "log.h" +#include "remotewin.h" +#include "ledwin.h" +#include "mtdwin.h" +#include "timers.h" +#include "videowin.h" +#include "audiowin.h" +#include "vdr.h" +#include "osdwin.h" +#include "viewman.h" +#include "command.h" + +void sighandler(int signalReceived); +void shutdown(int code); + +// Global variables -------------------------------------------------------------------------------------------------- +int debugEnabled = 0; +Log* logger; +Remote* remote; +Mtd* mtd; +Led* led; +Osd* osd; +Timers* timers; +ViewMan* viewman; +Command* command; +VDR* vdr; +Video* video; +Audio* audio; +bool wnd_fullscreen=false; +RECT wnd_fs_rect={20,20,768+20,576+20}; +RECT wnd_fs_rect_client={0,0,768,576}; + + void MILLISLEEP(ULONG a) { Sleep(a); -} - -DWORD WINAPI commandthreadStart(void *arg) -{ - command->run(); - return 0; -} - -bool InitApp(HINSTANCE hinst,int cmdshow); - -HWND win;//global window handle -HACCEL acc; - -#define ERROR_MSG(str) MessageBox(win,str,"Error!",MB_OK|MB_ICONWARNING) -INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmdshow) -{ - //On Windows we have to init a window, we use DXUT - if (!InitApp(hinst,cmdshow)) return false; - //Starting Network support - WSADATA wsadat; - int result = WSAStartup(MAKEWORD(2,2),&wsadat); - if (result!=NO_ERROR) { - ERROR_MSG("Initialising WinSocked: Error at WSAStartup()\n"); - return 0; - } - result= CoInitializeEx(NULL,COINIT_MULTITHREADED );//Initialize COM for DirectShow - if (result!=S_OK) { - ERROR_MSG("Initialising COM: Error at Coinitialize()\n"); - return 0; - } - - - - - // Init global vars ------------------------------------------------------------------------------------------------ - - logger = new Log(); - remote = new RemoteWin(); - mtd = new MtdWin(); - led = new LedWin(); - timers = new Timers(); - osd = new OsdWin(); - vdr = new VDR(); - video = new VideoWin(); - audio = new AudioWin(); - viewman = new ViewMan(); - command = new Command(); - - if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command) - { - ERROR_MSG("Could not create objects. Memory problems?\n"); - shutdown(1); - WSACleanup(); - return 0; - } - - // Get logging module started -------------------------------------------------------------------------------------- - - if (!logger->init(Log::DEBUG, "vompwin.log", true)) - { - ERROR_MSG("Could not initialise log object. Aborting.\n"); - shutdown(1); - WSACleanup(); - return 0; - } - - logger->log("Core", Log::INFO, "Starting up..."); - - - - // Init modules ---------------------------------------------------------------------------------------------------- - int success; - - success = remote->init("/dev/rawir"); - if (success) - { - logger->log("Core", Log::INFO, "Remote module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Remote module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = led->init(0); - if (success) - { - logger->log("Core", Log::INFO, "LED module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "LED module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = mtd->init("/dev/mtd1"); - if (success) - { - logger->log("Core", Log::INFO, "Mtd module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Mtd module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = timers->init(); - if (success) - { - logger->log("Core", Log::INFO, "Timers module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Timers module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC(); - if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576"); - else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480"); - else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480"); - - success = video->init(videoFormat); - if (success) - { - logger->log("Core", Log::INFO, "Video module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Video module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = osd->init((void*)&win); - if (success) - { - logger->log("Core", Log::INFO, "OSD module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "OSD module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = audio->init(Audio::MPEG2_PES); - if (success) - { - logger->log("Core", Log::INFO, "Audio module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Audio module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = vdr->init(3024); - if (success) - { - logger->log("Core", Log::INFO, "VDR module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "VDR module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = viewman->init(); - if (success) - { - logger->log("Core", Log::INFO, "ViewMan module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "ViewMan module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - success = command->init(); - if (success) - { - logger->log("Core", Log::INFO, "Command module initialised"); - } - else - { - logger->log("Core", Log::EMERG, "Command module failed to initialise"); - shutdown(1); - WSACleanup(); - return 0; - } - - // Other init ------------------------------------------------------------------------------------------------------ - - logger->log("Core", Log::NOTICE, "Startup successful"); - - // Run main loop --------------------------------------------------------------------------------------------------- - - // Ok, all major device components and other bits are loaded and ready - - HANDLE commandthread; - commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0, - NULL); - MSG message; - message.message=WM_NULL; - bool run=true; - while(run && WaitForSingleObject(commandthread,0)==WAIT_TIMEOUT) { - if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) { - if (TranslateAccelerator(win,acc,&message)==NULL) { - TranslateMessage(&message); - DispatchMessage(&message); - switch (message.message) { - case WM_QUIT: - run=false; //TODO post exit to command Messages - }; - } - } else { - //Render - ((OsdWin*)osd)->Render(); - } - } - // When that returns quit ------------------------------------------------------------------------------------------ - WaitForSingleObject(commandthread,INFINITE); - shutdown(0); - WSACleanup(); - return 0; - -} - - - -void CalculateWindowSize(RECT * size,ULONG size_mode) { - DWORD width, height; - DWORD adjheight,adjwidth; - DWORD flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU - |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX; - RECT wnted={50,50,150,150}; - AdjustWindowRect(&wnted,flags ,false); - adjwidth=-wnted.left+wnted.right-100; - adjheight=-wnted.top+wnted.bottom-100; - width=size->right-size->left-adjwidth; - height=size->bottom-size->top-adjheight; - UCHAR mode=video->getMode(); - UCHAR aspect=((VideoWin*)video)->getAspectRatio(); - UCHAR tvsize=((VideoWin*)video)->getPseudoTVsize(); - double aspectrt=4./3.; - if (tvsize==Video::ASPECT16X9) { - if (aspect==Video::ASPECT16X9) { - aspectrt=4./3.; //looks strange, but it is a 16:9 tv - } else if (aspect==Video::ASPECT4X3) { - aspectrt=4./3./(16./9.)*(4./3.); //I hope this is correct - } - } else if (tvsize==Video::ASPECT4X3) { - if (aspect==Video::ASPECT16X9) { - if (mode==Video::LETTERBOX) { - aspectrt=16./9.; - } else { - aspectrt=4./3.; - } - } if (aspect==Video::ASPECT4X3) { - aspectrt=4./3.; - } - } - switch (size_mode) { - case WMSZ_BOTTOM: - case WMSZ_BOTTOMRIGHT: - case WMSZ_TOP: - case WMSZ_TOPRIGHT: - width=(ULONG)(((double)height)*aspectrt); - size->right=size->left+width+adjwidth; - break; - case WMSZ_BOTTOMLEFT: - case WMSZ_TOPLEFT: - width=(ULONG)(((double)height)*aspectrt); - size->left=size->right-width-adjwidth; - break; - case WMSZ_LEFT: - case WMSZ_RIGHT: - height=(ULONG)(((double)width)/aspectrt); - size->bottom=size->top+height+adjheight; - break; - } -} - -void AdjustWindow() { - RECT winrect; - GetWindowRect(win,&winrect); - CalculateWindowSize(&winrect,WMSZ_BOTTOM); - MoveWindow(win,winrect.left, - winrect.top,winrect.right-winrect.left,winrect.bottom-winrect.top,true); - -} - -LONG FAR PASCAL WindowProc(HWND win, UINT msg, WPARAM wparam, LPARAM lparam) -{ - switch (msg) { - case WM_DESTROY: { - //TODO: call command - logger->log("Core", Log::NOTICE, "Window closed, shutting down..."); - command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe? - ((RemoteWin*)Remote::getInstance())->Signal(); - PostQuitMessage(0); - }break; - case WM_SIZING: { - CalculateWindowSize((RECT*) lparam,wparam); - return TRUE; - }break; - case WM_SIZE: { - int width = LOWORD(lparam); - int height = HIWORD(lparam); - //Call device - } - break; - case WM_PAINT: - RECT r; - PAINTSTRUCT ps; - if (GetUpdateRect(win, &r, FALSE)) { - BeginPaint(win, &ps); - //Call Painting Mechanism - EndPaint(win, &ps); - } - break; - case WM_KEYDOWN: - if (((RemoteWin*)remote)->ReceiveButtonVK(wparam)) { - return 0L; //We process that Key - } else { - return DefWindowProc(win, msg, wparam, lparam); - } - - break; - case WM_APPCOMMAND: - if (((RemoteWin*)remote)->ReceiveButtonAP(GET_APPCOMMAND_LPARAM(lparam))){ - return TRUE; //yes we process that message - } else { - return DefWindowProc(win, msg, wparam, lparam); - } - - break; - case WM_COMMAND: - if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){ - return 0; //yes we process that message - } else { - return DefWindowProc(win, msg, wparam, lparam); - } - - break; - default: - return DefWindowProc(win, msg, wparam, lparam); - } - return 0L; -} - - -bool InitApp(HINSTANCE hinst,int cmdshow) { - WNDCLASS wcs; - DWORD flags; - wcs.style = CS_HREDRAW | CS_VREDRAW; - wcs.lpfnWndProc = WindowProc; - wcs.cbClsExtra = 0; - wcs.cbWndExtra = sizeof(DWORD); - wcs.hInstance = hinst; - wcs.hIcon = NULL; - wcs.hCursor = NULL; - wcs.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); - wcs.lpszMenuName = NULL; - wcs.lpszClassName = "vomp"; - acc=LoadAccelerators(hinst,MAKEINTRESOURCE(VOMPACCELERATOR)); - if (!RegisterClass(&wcs)) - return false; - flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU - |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX; - RECT wnted={50,50,768+50,576+50}; - AdjustWindowRect(&wnted,flags ,false); - win=CreateWindow("vomp","vomp",flags, CW_USEDEFAULT,CW_USEDEFAULT, - wnted.right-wnted.left,wnted.bottom-wnted.top,NULL,NULL,hinst,NULL); - if (!win) - return FALSE; - ShowWindow(win,SW_SHOWNORMAL); - UpdateWindow(win); - return TRUE; -} - - - - - -// ------------------------------------------------------------------------------------------------------------------- - -void shutdown(int code) -{ - if (viewman) - { - viewman->shutdown(); - delete viewman; - logger->log("Core", Log::NOTICE, "ViewMan module shut down"); - } - - if (command) // shut down command here in case views have posted messages - { - command->shutdown(); - delete command; - logger->log("Core", Log::NOTICE, "Command module shut down"); - } - - if (vdr) - { - vdr->shutdown(); - delete vdr; - logger->log("Core", Log::NOTICE, "VDR module shut down"); - } - - if (osd) - { - osd->shutdown(); - delete osd; - logger->log("Core", Log::NOTICE, "OSD module shut down"); - } - - if (audio) - { - audio->shutdown(); - delete audio; - logger->log("Core", Log::NOTICE, "Audio module shut down"); - } - - if (video) - { - video->shutdown(); - delete video; - logger->log("Core", Log::NOTICE, "Video module shut down"); - } - - if (timers) - { - timers->shutdown(); - delete timers; - logger->log("Core", Log::NOTICE, "Timers module shut down"); - } - - if (mtd) - { - mtd->shutdown(); - delete mtd; - logger->log("Core", Log::NOTICE, "MTD module shut down"); - } - - if (led) - { - led->shutdown(); - delete led; - logger->log("Core", Log::NOTICE, "LED module shut down"); - } - - if (remote) - { - remote->shutdown(); - delete remote; - logger->log("Core", Log::NOTICE, "Remote module shut down"); - } - - if (logger) - { - logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n"); - logger->shutdown(); - delete logger; - } - ExitProcess(0); - -} - -// ------------------------------------------------------------------------------------------------------------------- - -ULLONG ntohll(ULLONG a) -{ - return htonll(a); -} - -ULLONG htonll(ULLONG a) -{ - return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32) - |(ULONG)htonl(((ULONG) (a >> 32)))); -} -#endif +} + +DWORD WINAPI commandthreadStart(void *arg) +{ + command->run(); + return 0; +} + +bool InitApp(HINSTANCE hinst,int cmdshow); + +HWND win_main;//global window handle +HWND win;//global child window handle +HACCEL acc; + +#define ERROR_MSG(str) MessageBox(win_main,str,"Error!",MB_OK|MB_ICONWARNING) +INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmdshow) +{ + //On Windows we have to init a window, we use DXUT + if (!InitApp(hinst,cmdshow)) return false; + //Starting Network support + WSADATA wsadat; + int result = WSAStartup(MAKEWORD(2,2),&wsadat); + if (result!=NO_ERROR) { + ERROR_MSG("Initialising WinSocked: Error at WSAStartup()\n"); + return 0; + } + result= CoInitializeEx(NULL,COINIT_MULTITHREADED );//Initialize COM for DirectShow + if (result!=S_OK) { + ERROR_MSG("Initialising COM: Error at Coinitialize()\n"); + return 0; + } + + + + + // Init global vars ------------------------------------------------------------------------------------------------ + + logger = new Log(); + remote = new RemoteWin(); + mtd = new MtdWin(); + led = new LedWin(); + timers = new Timers(); + osd = new OsdWin(); + vdr = new VDR(); + video = new VideoWin(); + audio = new AudioWin(); + viewman = new ViewMan(); + command = new Command(); + + if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command) + { + ERROR_MSG("Could not create objects. Memory problems?\n"); + shutdown(1); + WSACleanup(); + return 0; + } + + // Get logging module started -------------------------------------------------------------------------------------- + + if (!logger->init(Log::DEBUG, "vompwin.log", true)) + { + ERROR_MSG("Could not initialise log object. Aborting.\n"); + shutdown(1); + WSACleanup(); + return 0; + } + + logger->log("Core", Log::INFO, "Starting up..."); + + + + // Init modules ---------------------------------------------------------------------------------------------------- + int success; + + success = remote->init("/dev/rawir"); + if (success) + { + logger->log("Core", Log::INFO, "Remote module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "Remote module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + success = led->init(0); + if (success) + { + logger->log("Core", Log::INFO, "LED module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "LED module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + success = mtd->init("/dev/mtd1"); + if (success) + { + logger->log("Core", Log::INFO, "Mtd module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "Mtd module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + success = timers->init(); + if (success) + { + logger->log("Core", Log::INFO, "Timers module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "Timers module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC(); + if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576"); + else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480"); + else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480"); + + success = video->init(videoFormat); + if (success) + { + logger->log("Core", Log::INFO, "Video module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "Video module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + success = osd->init((void*)&win); + if (success) + { + logger->log("Core", Log::INFO, "OSD module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "OSD module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + success = audio->init(Audio::MPEG2_PES); + if (success) + { + logger->log("Core", Log::INFO, "Audio module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "Audio module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + success = vdr->init(3024); + if (success) + { + logger->log("Core", Log::INFO, "VDR module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "VDR module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + success = viewman->init(); + if (success) + { + logger->log("Core", Log::INFO, "ViewMan module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "ViewMan module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + success = command->init(); + if (success) + { + logger->log("Core", Log::INFO, "Command module initialised"); + } + else + { + logger->log("Core", Log::EMERG, "Command module failed to initialise"); + shutdown(1); + WSACleanup(); + return 0; + } + + // Other init ------------------------------------------------------------------------------------------------------ + + logger->log("Core", Log::NOTICE, "Startup successful"); + + // Run main loop --------------------------------------------------------------------------------------------------- + + // Ok, all major device components and other bits are loaded and ready + + HANDLE commandthread; + commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0, + NULL); + MSG message; + message.message=WM_NULL; + bool run=true; + while(run && WaitForSingleObject(commandthread,0)==WAIT_TIMEOUT) { + if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) { + if (TranslateAccelerator(win_main,acc,&message)==NULL) { + TranslateMessage(&message); + DispatchMessage(&message); + switch (message.message) { + case WM_QUIT: + run=false; //TODO post exit to command Messages + }; + } + } else { + //Render + ((OsdWin*)osd)->Render(); + } + } + // When that returns quit ------------------------------------------------------------------------------------------ + WaitForSingleObject(commandthread,INFINITE); + shutdown(0); + WSACleanup(); + return 0; + +} + + + +void CalculateWindowSize(RECT * size,ULONG size_mode) { + + DWORD width, height; + DWORD adjheight,adjwidth; + if (!wnd_fullscreen) { + DWORD flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU + |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX; + RECT wnted={50,50,150,150}; + AdjustWindowRect(&wnted,flags ,false); + adjwidth=-wnted.left+wnted.right-100; + adjheight=-wnted.top+wnted.bottom-100; + } else { + adjwidth=adjheight=0; + } + width=size->right-size->left-adjwidth; + height=size->bottom-size->top-adjheight; + UCHAR mode=video->getMode(); + UCHAR aspect=((VideoWin*)video)->getAspectRatio(); + UCHAR tvsize=((VideoWin*)video)->getPseudoTVsize(); + double aspectrt=4./3.; + if (tvsize==Video::ASPECT16X9) { + if (aspect==Video::ASPECT16X9) { + aspectrt=4./3.; //looks strange, but it is a 16:9 tv + } else if (aspect==Video::ASPECT4X3) { + aspectrt=4./3./(16./9.)*(4./3.); //I hope this is correct + } + } else if (tvsize==Video::ASPECT4X3) { + if (aspect==Video::ASPECT16X9) { + if (mode!=Video::NORMAL) { + aspectrt=16./9.; + } else { + aspectrt=4./3.; + } + } else if (aspect==Video::ASPECT4X3) { + aspectrt=4./3.; + } + } + if (!wnd_fullscreen) { + switch (size_mode) { + case WMSZ_BOTTOM: + case WMSZ_BOTTOMRIGHT: + case WMSZ_TOP: + case WMSZ_TOPRIGHT: + width=(ULONG)(((double)height)*aspectrt); + size->right=size->left+width+adjwidth; + break; + case WMSZ_BOTTOMLEFT: + case WMSZ_TOPLEFT: + width=(ULONG)(((double)height)*aspectrt); + size->left=size->right-width-adjwidth; + break; + case WMSZ_LEFT: + case WMSZ_RIGHT: + height=(ULONG)(((double)width)/aspectrt); + size->bottom=size->top+height+adjheight; + break; + } + MoveWindow(win,0,0,width,height,TRUE); + } else { + RECT newrect={0,0,width,height}; + DWORD newlength; + if ((ULONG)(((double)height)*aspectrt)>width) { + newlength=(ULONG)(((double)width)/aspectrt); + newrect.top+=(height-newlength)/2; + newrect.bottom-=(height-newlength); + } else { + newlength=(ULONG)(((double)height)*aspectrt); + newrect.left+=(width-newlength)/2; + newrect.right-=(width-newlength); + } + MoveWindow(win,newrect.left,newrect.top,newrect.right,newrect.bottom,TRUE); + } + +} + +void AdjustWindow() { + if (!wnd_fullscreen) { + RECT winrect; + GetWindowRect(win_main,&winrect); + CalculateWindowSize(&winrect,WMSZ_BOTTOM); + MoveWindow(win_main,winrect.left, + winrect.top,winrect.right-winrect.left,winrect.bottom-winrect.top,true); + } else { + RECT winrect; + GetWindowRect(win_main,&winrect); + CalculateWindowSize(&winrect,WMSZ_BOTTOM); + + } +} + +void ToggleFullscreen() { + if (wnd_fullscreen) { + wnd_fullscreen=false; + SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU + |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX); + SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + + SetWindowPos(win_main,HWND_TOP,wnd_fs_rect.left,wnd_fs_rect.top, + wnd_fs_rect.right-wnd_fs_rect.left, + wnd_fs_rect.bottom-wnd_fs_rect.top, + SWP_DRAWFRAME | SWP_FRAMECHANGED); + MoveWindow(win,wnd_fs_rect_client.left,wnd_fs_rect_client.top, + wnd_fs_rect_client.right-wnd_fs_rect_client.left, + wnd_fs_rect_client.bottom-wnd_fs_rect_client.top,TRUE); + AdjustWindow(); + } else { + GetWindowRect(win_main,&wnd_fs_rect); + GetWindowRect(win,&wnd_fs_rect_client); + SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP ); + SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + HMONITOR monitor=MonitorFromWindow(win_main,MONITOR_DEFAULTTONEAREST); + MONITORINFO moninfo; + moninfo.cbSize=sizeof(moninfo); + wnd_fullscreen=true; + if (!GetMonitorInfo(monitor,&moninfo)) return ; + SetWindowPos(win_main,HWND_TOP,moninfo.rcMonitor.left,moninfo.rcMonitor.top, + moninfo.rcMonitor.right,moninfo.rcMonitor.bottom,SWP_FRAMECHANGED); + + AdjustWindow(); + + } + + +} + +LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) +{ + switch (msg) { + case WM_DESTROY: { + //TODO: call command + logger->log("Core", Log::NOTICE, "Window closed, shutting down..."); + command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe? + ((RemoteWin*)Remote::getInstance())->Signal(); + PostQuitMessage(0); + }break; + case WM_SIZING: { + CalculateWindowSize((RECT*) lparam,wparam); + return TRUE; + }break; + case WM_SIZE: { + int width = LOWORD(lparam); + int height = HIWORD(lparam); + //Call device + } + break; + case WM_PAINT: + RECT r; + PAINTSTRUCT ps; + if (GetUpdateRect(wind, &r, FALSE)) { + BeginPaint(wind, &ps); + //Call Painting Mechanism + EndPaint(wind, &ps); + } + break; + case WM_KEYDOWN: + if (((RemoteWin*)remote)->ReceiveButtonVK(wparam)) { + return 0L; //We process that Key + } else { + return DefWindowProc(wind, msg, wparam, lparam); + } + + break; + case WM_APPCOMMAND: + if (((RemoteWin*)remote)->ReceiveButtonAP(GET_APPCOMMAND_LPARAM(lparam))){ + return TRUE; //yes we process that message + } else { + return DefWindowProc(wind, msg, wparam, lparam); + } + + break; + case WM_COMMAND: + if (LOWORD(wparam)==VOMP_FULL_SCREEN) { + ToggleFullscreen(); + return 0; + } + if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){ + return 0; //yes we process that message + } else { + return DefWindowProc(wind, msg, wparam, lparam); + } + + break; + case WM_SETCURSOR: + if (((HANDLE)wparam)==win) { + SetCursor(NULL); + return 1; + } else { + return DefWindowProc(wind, msg, wparam, lparam); + } + break; + default: + return DefWindowProc(wind, msg, wparam, lparam); + } + return 0L; +} + + +bool InitApp(HINSTANCE hinst,int cmdshow) { + /* main window */ + WNDCLASS wcs; + DWORD flags; + wcs.style = CS_HREDRAW | CS_VREDRAW; + wcs.lpfnWndProc = WindowProc; + wcs.cbClsExtra = 0; + wcs.cbWndExtra = sizeof(DWORD); + wcs.hInstance = hinst; + wcs.hIcon = NULL; + wcs.hCursor = NULL; + wcs.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + wcs.lpszMenuName = NULL; + wcs.lpszClassName = "vomp"; + acc=LoadAccelerators(hinst,MAKEINTRESOURCE(VOMPACCELERATOR)); + if (!RegisterClass(&wcs)) + return false; + flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU + |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX; + RECT wnted={50,50,768+50,576+50}; + AdjustWindowRect(&wnted,flags ,false); + win_main=CreateWindow("vomp","VOMP on Windows",flags, CW_USEDEFAULT,CW_USEDEFAULT, + wnted.right-wnted.left,wnted.bottom-wnted.top,NULL,NULL,hinst,NULL); + if (!win_main) + return FALSE; + ShowWindow(win_main,SW_SHOWNORMAL); + UpdateWindow(win_main); + /* in order to handle letterboxing we use a child window */ + WNDCLASS child_wcs; + child_wcs.style = CS_HREDRAW | CS_VREDRAW; + child_wcs.lpfnWndProc = DefWindowProc; + child_wcs.cbClsExtra = 0; + child_wcs.cbWndExtra = sizeof(DWORD); + child_wcs.hInstance = hinst; + child_wcs.hIcon = NULL; + child_wcs.hCursor = NULL; + child_wcs.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + child_wcs.lpszMenuName = NULL; + child_wcs.lpszClassName = "vomp_playback"; + if (!RegisterClass(&child_wcs)) + return false; + + win=CreateWindow("vomp_playback","Vomp Playback Window",WS_VISIBLE | WS_CHILD |WS_CLIPCHILDREN, + 0,0,768,576,win_main,NULL,hinst,NULL); + if (!win) + return FALSE; + ShowWindow(win,SW_SHOWNORMAL); + UpdateWindow(win); + return TRUE; +} + + + + + +// ------------------------------------------------------------------------------------------------------------------- + +void shutdown(int code) +{ + if (viewman) + { + viewman->shutdown(); + delete viewman; + logger->log("Core", Log::NOTICE, "ViewMan module shut down"); + } + + if (command) // shut down command here in case views have posted messages + { + command->shutdown(); + delete command; + logger->log("Core", Log::NOTICE, "Command module shut down"); + } + + if (vdr) + { + vdr->shutdown(); + delete vdr; + logger->log("Core", Log::NOTICE, "VDR module shut down"); + } + + if (osd) + { + osd->shutdown(); + delete osd; + logger->log("Core", Log::NOTICE, "OSD module shut down"); + } + + if (audio) + { + audio->shutdown(); + delete audio; + logger->log("Core", Log::NOTICE, "Audio module shut down"); + } + + if (video) + { + video->shutdown(); + delete video; + logger->log("Core", Log::NOTICE, "Video module shut down"); + } + + if (timers) + { + timers->shutdown(); + delete timers; + logger->log("Core", Log::NOTICE, "Timers module shut down"); + } + + if (mtd) + { + mtd->shutdown(); + delete mtd; + logger->log("Core", Log::NOTICE, "MTD module shut down"); + } + + if (led) + { + led->shutdown(); + delete led; + logger->log("Core", Log::NOTICE, "LED module shut down"); + } + + if (remote) + { + remote->shutdown(); + delete remote; + logger->log("Core", Log::NOTICE, "Remote module shut down"); + } + + if (logger) + { + logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n"); + logger->shutdown(); + delete logger; + } + ExitProcess(0); + +} + +// ------------------------------------------------------------------------------------------------------------------- + +ULLONG ntohll(ULLONG a) +{ + return htonll(a); +} + +ULLONG htonll(ULLONG a) +{ + return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32) + |(ULONG)htonl(((ULONG) (a >> 32)))); +} +#endif -- 2.39.2