2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define _WIN32_WINNT 0x501
30 #include "vompreswin.h"
34 #include "remotewin.h"
45 void sighandler(int signalReceived);
46 void shutdown(int code);
48 // Global variables --------------------------------------------------------------------------------------------------
63 void MILLISLEEP(ULONG a)
70 DWORD WINAPI commandthreadStart(void *arg)
76 bool InitApp(HINSTANCE hinst,int cmdshow);
78 HWND win;//global window handle
81 #define ERROR_MSG(str) MessageBox(win,str,"Error!",MB_OK|MB_ICONWARNING)
82 INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmdshow)
84 //On Windows we have to init a window, we use DXUT
85 if (!InitApp(hinst,cmdshow)) return false;
86 //Starting Network support
88 int result = WSAStartup(MAKEWORD(2,2),&wsadat);
89 if (result!=NO_ERROR) {
90 ERROR_MSG("Initialising WinSocked: Error at WSAStartup()\n");
93 result= CoInitializeEx(NULL,COINIT_MULTITHREADED );//Initialize COM for DirectShow
95 ERROR_MSG("Initialising COM: Error at Coinitialize()\n");
102 // Init global vars ------------------------------------------------------------------------------------------------
105 remote = new RemoteWin();
108 timers = new Timers();
111 video = new VideoWin();
112 audio = new AudioWin();
113 viewman = new ViewMan();
114 command = new Command();
116 if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
118 ERROR_MSG("Could not create objects. Memory problems?\n");
124 // Get logging module started --------------------------------------------------------------------------------------
126 if (!logger->init(Log::DEBUG, "vompwin.log", true))
128 ERROR_MSG("Could not initialise log object. Aborting.\n");
134 logger->log("Core", Log::INFO, "Starting up...");
138 // Init modules ----------------------------------------------------------------------------------------------------
141 success = remote->init("/dev/rawir");
144 logger->log("Core", Log::INFO, "Remote module initialised");
148 logger->log("Core", Log::EMERG, "Remote module failed to initialise");
154 success = led->init(0);
157 logger->log("Core", Log::INFO, "LED module initialised");
161 logger->log("Core", Log::EMERG, "LED module failed to initialise");
167 success = mtd->init("/dev/mtd1");
170 logger->log("Core", Log::INFO, "Mtd module initialised");
174 logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
180 success = timers->init();
183 logger->log("Core", Log::INFO, "Timers module initialised");
187 logger->log("Core", Log::EMERG, "Timers module failed to initialise");
193 UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
194 if (videoFormat == Video::PAL) logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
195 else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
196 else logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
198 success = video->init(videoFormat);
201 logger->log("Core", Log::INFO, "Video module initialised");
205 logger->log("Core", Log::EMERG, "Video module failed to initialise");
211 success = osd->init((void*)&win);
214 logger->log("Core", Log::INFO, "OSD module initialised");
218 logger->log("Core", Log::EMERG, "OSD module failed to initialise");
224 success = audio->init(Audio::MPEG2_PES);
227 logger->log("Core", Log::INFO, "Audio module initialised");
231 logger->log("Core", Log::EMERG, "Audio module failed to initialise");
237 success = vdr->init(3024);
240 logger->log("Core", Log::INFO, "VDR module initialised");
244 logger->log("Core", Log::EMERG, "VDR module failed to initialise");
250 success = viewman->init();
253 logger->log("Core", Log::INFO, "ViewMan module initialised");
257 logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
263 success = command->init();
266 logger->log("Core", Log::INFO, "Command module initialised");
270 logger->log("Core", Log::EMERG, "Command module failed to initialise");
276 // Other init ------------------------------------------------------------------------------------------------------
278 logger->log("Core", Log::NOTICE, "Startup successful");
280 // Run main loop ---------------------------------------------------------------------------------------------------
282 // Ok, all major device components and other bits are loaded and ready
284 HANDLE commandthread;
285 commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0,
288 message.message=WM_NULL;
290 while(run && WaitForSingleObject(commandthread,0)==WAIT_TIMEOUT) {
291 if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) {
292 if (TranslateAccelerator(win,acc,&message)==NULL) {
293 TranslateMessage(&message);
294 DispatchMessage(&message);
295 switch (message.message) {
297 run=false; //TODO post exit to command Messages
302 ((OsdWin*)osd)->Render();
305 // When that returns quit ------------------------------------------------------------------------------------------
306 WaitForSingleObject(commandthread,INFINITE);
313 LONG FAR PASCAL WindowProc(HWND win, UINT msg, WPARAM wparam, LPARAM lparam)
318 logger->log("Core", Log::NOTICE, "Window closed, shutting down...");
319 command->stop(); // FIXME this is probably not safe - use the messaging system / is that even safe?
320 ((RemoteWin*)Remote::getInstance())->Signal();
324 int width = LOWORD(lparam);
325 int height = HIWORD(lparam);
332 if (GetUpdateRect(win, &r, FALSE)) {
333 BeginPaint(win, &ps);
334 //Call Painting Mechanism
339 if (((RemoteWin*)remote)->ReceiveButtonVK(wparam)) {
340 return 0L; //We process that Key
342 return DefWindowProc(win, msg, wparam, lparam);
347 if (((RemoteWin*)remote)->ReceiveButtonAP(GET_APPCOMMAND_LPARAM(lparam))){
348 return TRUE; //yes we process that message
350 return DefWindowProc(win, msg, wparam, lparam);
355 if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){
356 return 0; //yes we process that message
358 return DefWindowProc(win, msg, wparam, lparam);
363 return DefWindowProc(win, msg, wparam, lparam);
369 bool InitApp(HINSTANCE hinst,int cmdshow) {
372 wcs.style = CS_HREDRAW | CS_VREDRAW;
373 wcs.lpfnWndProc = WindowProc;
375 wcs.cbWndExtra = sizeof(DWORD);
376 wcs.hInstance = hinst;
379 wcs.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
380 wcs.lpszMenuName = NULL;
381 wcs.lpszClassName = "vomp";
382 acc=LoadAccelerators(hinst,MAKEINTRESOURCE(VOMPACCELERATOR));
383 if (!RegisterClass(&wcs))
385 flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU
386 |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX;
387 RECT wnted={0,0,720,576};
388 AdjustWindowRect(&wnted,flags ,false);
389 win=CreateWindow("vomp","vomp",flags, CW_USEDEFAULT,CW_USEDEFAULT,
390 wnted.right-wnted.left,wnted.bottom-wnted.top,NULL,NULL,hinst,NULL);
393 ShowWindow(win,SW_SHOWNORMAL);
402 // -------------------------------------------------------------------------------------------------------------------
404 void shutdown(int code)
410 logger->log("Core", Log::NOTICE, "ViewMan module shut down");
413 if (command) // shut down command here in case views have posted messages
417 logger->log("Core", Log::NOTICE, "Command module shut down");
424 logger->log("Core", Log::NOTICE, "VDR module shut down");
431 logger->log("Core", Log::NOTICE, "OSD module shut down");
438 logger->log("Core", Log::NOTICE, "Audio module shut down");
445 logger->log("Core", Log::NOTICE, "Video module shut down");
452 logger->log("Core", Log::NOTICE, "Timers module shut down");
459 logger->log("Core", Log::NOTICE, "MTD module shut down");
466 logger->log("Core", Log::NOTICE, "LED module shut down");
473 logger->log("Core", Log::NOTICE, "Remote module shut down");
478 logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
486 // -------------------------------------------------------------------------------------------------------------------
488 ULLONG ntohll(ULLONG a)
493 ULLONG htonll(ULLONG a)
496 #if BYTE_ORDER == BIG_ENDIAN
501 b = ((a << 56) & 0xFF00000000000000ULL)
502 | ((a << 40) & 0x00FF000000000000ULL)
503 | ((a << 24) & 0x0000FF0000000000ULL)
504 | ((a << 8) & 0x000000FF00000000ULL)
505 | ((a >> 8) & 0x00000000FF000000ULL)
506 | ((a >> 24) & 0x0000000000FF0000ULL)
507 | ((a >> 40) & 0x000000000000FF00ULL)
508 | ((a >> 56) & 0x00000000000000FFULL) ;
511 #endif*///This macro switching does not work for windows, here is a implementation without
513 //#define ntohll(x) (((_int64)(ntohl((int)((x << 32) >> 32))) << 32) |
514 // (unsigned int)ntohl(((int)(x >> 32)))) //By Runner
516 return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32)
517 |(ULONG)htonl(((ULONG) (a >> 32))));