]> git.vomp.tv Git - vompclient-marten.git/blob - remotewin.cc
FFMPEG decoding in color at 7 fps
[vompclient-marten.git] / remotewin.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "remotewin.h"
22 #include "vompreswin.h"
23 #include "i18n.h"
24
25 #define W_G_HCW(type,code) ( (((ULLONG)(type))<<32) | code)
26
27 #define W_HCW_VK 1 /* virtual key */
28 #define W_HCW_AP 2 /* App command */
29 #define W_HCW_RI 3 /* remote control */
30 #define W_HCW_CH 4 /* char */
31
32 RemoteWin::RemoteWin()
33 {
34   initted = 0;
35   curevent=0;
36   hascurevent=false;
37   signal=false;
38 }
39
40 RemoteWin::~RemoteWin()
41 {
42 }
43
44 int RemoteWin::init(char* devName)
45 {
46   if (initted) return 0;
47   initted = 1;
48   event = CreateEvent(NULL,/*FALSE*/TRUE,FALSE,NULL);
49
50
51   return 1;
52 }
53
54 int RemoteWin::shutdown()
55 {
56   if (!initted) return 0;
57   CloseHandle(event);
58   initted = 0;
59   return 1;
60 }
61
62 UCHAR RemoteWin::getButtonPress(int waitType)
63 {
64   /* how = 0 - block
65      how = 1 - start new wait
66      how = 2 - continue wait
67      how = 3 - no wait
68   */
69   DWORD wait;
70   
71
72   if (hascurevent) {
73           UCHAR temp=curevent;
74       hascurevent=false;
75
76           return temp;
77   }
78   if (waitType==3) {
79           return NA_NONE;
80   }
81   if (waitType==0) {
82           wait=INFINITE;
83   } else { //We do not distingish between 2 and 3
84           wait=1000;
85
86   }
87   WaitForSingleObject(event,wait);
88   ResetEvent(event);
89   if (!hascurevent) {
90           if (signal) {
91                   signal=false;
92                   return NA_SIGNAL; //Since we have no signals on windows, we simulate this
93           } else {
94                   return NA_NONE;
95           }
96   }
97   UCHAR temp2=curevent;
98   hascurevent=false;
99   return temp2;
100   
101 }
102
103 void RemoteWin::clearBuffer()
104 {
105 }
106
107 UCHAR RemoteWin::TranslateHWCFixed(ULLONG code)
108 {
109     switch (code) 
110     {
111     case W_G_HCW(W_HCW_VK,VK_DOWN):
112         return DOWN;
113     case W_G_HCW(W_HCW_VK,VK_UP):
114         return UP;
115     case W_G_HCW(W_HCW_VK,VK_LEFT):
116         return LEFT;
117     case W_G_HCW(W_HCW_VK,VK_RIGHT):
118         return RIGHT;
119     case W_G_HCW(W_HCW_CH,'m'):
120         return MENU;
121     case W_G_HCW(W_HCW_VK,VK_BACK):
122         return BACK;
123     case W_G_HCW(W_HCW_VK,VK_RETURN):
124     case W_G_HCW(W_HCW_VK,VK_SPACE):
125         return OK;
126     /* Menu IDs, no sense to make it user selectable */
127     case W_G_HCW(W_HCW_AP,APPCOMMAND_BROWSER_BACKWARD):
128                 return BACK;
129         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_CHANNEL_DOWN):
130                 return CHANNELDOWN;break;
131         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_CHANNEL_UP):
132                 return CHANNELUP;break;
133         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_FAST_FORWARD):
134                 return FORWARD;break;
135         case W_G_HCW(W_HCW_AP,APPCOMMAND_VOLUME_MUTE):
136                 return MUTE;break;
137         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_PAUSE):
138                 return PAUSE;break;
139         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_PLAY):
140                 return PLAY;break;
141         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_RECORD):
142                 return RECORD;break;
143         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_PREVIOUSTRACK):
144                 return SKIPBACK;break;
145         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_REWIND):
146                 return REVERSE;break;
147         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_NEXTTRACK):
148                 return SKIPFORWARD;break;
149         case W_G_HCW(W_HCW_AP,APPCOMMAND_MEDIA_STOP):
150                 return STOP;break;
151         case W_G_HCW(W_HCW_AP,APPCOMMAND_VOLUME_DOWN):
152                 return VOLUMEDOWN;break;
153         case W_G_HCW(W_HCW_AP,APPCOMMAND_VOLUME_UP):
154                 return VOLUMEUP;break;
155         case W_G_HCW(W_HCW_AP,VOMP_YELLOW):
156                 return YELLOW; break;
157         case W_G_HCW(W_HCW_AP,VOMP_BLUE):
158                 return BLUE;break;
159         case W_G_HCW(W_HCW_AP,VOMP_RED):
160                 return RED;break;
161         case W_G_HCW(W_HCW_AP,VOMP_GREEN):
162                 return GREEN;break;
163         case W_G_HCW(W_HCW_AP,VOMP_ENTER):
164                 return OK;break;
165         case W_G_HCW(W_HCW_AP,VOMP_CANCEL):
166                 return BACK;break;
167         case W_G_HCW(W_HCW_AP,VOMP_UP):
168                 return UP;break;
169         case W_G_HCW(W_HCW_AP,VOMP_DOWN):
170                 return DOWN;break;
171         case W_G_HCW(W_HCW_AP,VOMP_LEFT):
172                 return LEFT;break;
173         case W_G_HCW(W_HCW_AP,VOMP_RIGHT):
174                 return RIGHT;break;
175     case POWER:
176         return POWER;
177     default:
178         return NA_UNKNOWN;
179     };
180 }
181
182 const char*RemoteWin::HardcodedTranslateStr(UCHAR command)
183 {
184     switch (command) 
185     {
186     case DOWN:
187         return tr("Down");
188     case UP:
189         return tr("Up");
190     case LEFT:
191         return tr("Left");
192     case RIGHT:
193         return tr("Right");
194     case MENU:
195         return tr("M");
196     case BACK:
197         return tr("Backspace, Back");
198     case OK:
199         return tr("Return, Space");
200     case CHANNELDOWN:
201         return tr("Insrt, C+Insrt, Pg down");
202     case CHANNELUP:
203         return tr("+, C++, Pg up");
204     case VOLUMEUP:
205         return "F10";
206     case VOLUMEDOWN:
207         return "F9";
208     case POWER:
209         return "Esc, A+F4";
210     case MUTE:
211         return "F8";
212     case REVERSE:
213         return"S+C+B";
214     case FORWARD:
215         return "S+C+F";
216     case SKIPBACK:
217         return "C+B";
218     case SKIPFORWARD:
219         return "C+F";
220     case PLAY:
221         return "S+P";
222     case STOP:
223         return "C+S";
224     case PAUSE:
225         return "C+P";
226     default:
227         return NULL;
228     };
229     
230 }
231
232
233 void RemoteWin::InitHWCListwithDefaults()
234 {
235     //Processing VK_Messages
236     translist[W_G_HCW(W_HCW_CH,'9')] = NINE;
237     translist[W_G_HCW(W_HCW_CH,'8')] = EIGHT;
238     translist[W_G_HCW(W_HCW_CH,'7')] = SEVEN;
239     translist[W_G_HCW(W_HCW_CH,'6')] = SIX;
240     translist[W_G_HCW(W_HCW_CH,'5')] = FIVE;
241     translist[W_G_HCW(W_HCW_CH,'4')] = FOUR;
242     translist[W_G_HCW(W_HCW_CH,'3')] = THREE;
243     translist[W_G_HCW(W_HCW_CH,'2')] = TWO;
244     translist[W_G_HCW(W_HCW_CH,'1')] = ONE;
245     translist[W_G_HCW(W_HCW_CH,'0')] = ZERO;
246     translist[W_G_HCW(W_HCW_CH,'*')] = STAR;
247     translist[W_G_HCW(W_HCW_CH,'#')] = HASH;
248     translist[W_G_HCW(W_HCW_CH,'j')] = GO; //j for JUMP TO instead of go to
249     translist[W_G_HCW(W_HCW_CH,'r')] = RED; 
250     translist[W_G_HCW(W_HCW_CH,'g')] = GREEN;
251     translist[W_G_HCW(W_HCW_CH,'y')] = YELLOW; 
252     translist[W_G_HCW(W_HCW_CH,'b')] = BLUE; 
253     //Processing RI Messages
254     translist[W_G_HCW(W_HCW_RI,0x35c)] = GREEN;
255     translist[W_G_HCW(W_HCW_RI,0x35b)] = RED;
256     translist[W_G_HCW(W_HCW_RI,0x35d)] = YELLOW;
257     translist[W_G_HCW(W_HCW_RI,0x35e)] = BLUE;
258     translist[W_G_HCW(W_HCW_RI,0x30d)] = MENU;//MCE Button, used for Menu
259     translist[W_G_HCW(W_HCW_RI,0x348)] = RECORD; //Record Television
260     translist[W_G_HCW(W_HCW_RI,0x325)] = PLAY; //Playback Televison 
261     translist[W_G_HCW(W_HCW_RI,0x324)] = PLAY; //Playback DVD
262     translist[W_G_HCW(W_HCW_RI,0x209)] = OK;//Properties
263     translist[W_G_HCW(W_HCW_RI,0x35a)] = OK;//Teletext?
264
265 }
266
267 char* RemoteWin::HCWDesc(ULLONG hcw)
268 {
269     //Determine type
270     ULONG type =  hcw >> 32;
271     char *rt=NULL;
272     switch(type)
273     {
274     case W_HCW_VK:{
275         ULONG vk=(ULONG)hcw;
276         ULONG scancode=MapVirtualKey(vk,0);
277         rt=new char[10];
278         GetKeyNameText(scancode << 16,rt,10); 
279                   }break;
280     case W_HCW_CH:{
281         ULONG ch=(ULONG)hcw;
282         ULONG scancode=OemKeyScan(ch);
283   
284         rt=new char[10];
285         GetKeyNameText(scancode << 16,rt,10); 
286                   }break;
287     case W_HCW_RI:{
288         ULONG ri=(ULONG)hcw;
289         rt=new char[10];
290         sprintf(rt,"R: %X",ri);
291                   }break;
292
293     };
294     return rt;
295 }
296
297
298 int RemoteWin::ReceiveButtonVK(UINT button) {
299 /*      UCHAR pb=NA_NONE;
300         //should we use a translation table ? No APPCOMMAND iS DWORD!
301         switch (button) { //Processing VK_Messages
302         case VK_DOWN:
303                 pb=DOWN; break;
304         case VK_RETURN:
305         case VK_SPACE:
306                 pb=OK;break;
307         case VK_LEFT:
308                 pb=LEFT;break;
309         case '9':
310         case VK_NUMPAD9:
311                 pb=NINE;break;
312         case '8':
313         case VK_NUMPAD8:
314                 pb=EIGHT;break;
315         case '7':
316         case VK_NUMPAD7:
317                 pb=SEVEN;break;
318         case '6':
319         case VK_NUMPAD6:
320                 pb=SIX;break;
321         case '5':
322         case VK_NUMPAD5:
323                 pb=FIVE;break;
324         case '4':
325         case VK_NUMPAD4:
326                 pb=FOUR;break;
327         case '3':
328         case VK_NUMPAD3:
329                 pb=THREE;break;
330         case '2':
331         case VK_NUMPAD2:
332                 pb=TWO;break;
333         case '1':
334         case VK_NUMPAD1:
335                 pb=ONE;break;
336         case '0':
337         case VK_NUMPAD0:
338                 pb=ZERO;break;
339         case VK_RIGHT:
340                 pb=RIGHT;break;
341         case VK_UP:
342                 pb=UP;break;
343         case VK_MULTIPLY:
344                 pb=STAR;break;
345         case 'J'://j for JUMP TO instead of go to
346                 pb=GO;break;
347         //case VK_ESCAPE:
348         //      pb=POWER;break;
349         case VK_BACK:
350                 pb=BACK;break;
351         case 'M':
352                 pb=MENU;break;
353         case 'R':
354                 pb=RED;break;
355         case 'G':
356                 pb=GREEN;break;
357         case 'Y':
358                 pb=YELLOW;break;
359         case 'B':
360                 pb=BLUE; break;
361
362
363         }; //All other commands are process via APPCOMMAND_MESSAGES
364         if (pb==NA_NONE) return 0;*/
365     UCHAR pb=NA_NONE;
366         pb=TranslateHWC(W_G_HCW(W_HCW_VK,button));
367     if (pb==NA_UNKNOWN || pb==NA_NONE) return 0;
368     curevent=pb;
369     hascurevent=true;
370         //PulseEvent(event);
371         SetEvent(event);
372         return 1;
373 }
374
375 int RemoteWin::ReceiveButtonCH(UINT button) {
376     UCHAR pb=NA_NONE;
377         pb=TranslateHWC(W_G_HCW(W_HCW_CH,button));
378     if (pb==NA_UNKNOWN || pb==NA_NONE) return 0;
379     curevent=pb;
380     hascurevent=true;
381         //PulseEvent(event);
382         SetEvent(event);
383         return 1;
384 }
385
386 int RemoteWin::ReceiveButtonAP(UINT button) {
387 /*      UCHAR pb=NA_NONE;
388         //should we use a translation table ? No APPCOMMAND iS DWORD!
389         switch (button) { //Processing VK_Messages
390         case APPCOMMAND_BROWSER_BACKWARD:
391                 pb=BACK;break;
392         case APPCOMMAND_MEDIA_CHANNEL_DOWN:
393                 pb=CHANNELDOWN;break;
394         case APPCOMMAND_MEDIA_CHANNEL_UP:
395                 pb=CHANNELUP;break;
396         case APPCOMMAND_MEDIA_FAST_FORWARD:
397                 pb=FORWARD;break;
398         case APPCOMMAND_VOLUME_MUTE:
399                 pb=MUTE;break;
400         case APPCOMMAND_MEDIA_PAUSE:
401                 pb=PAUSE;break;
402         case APPCOMMAND_MEDIA_PLAY:
403                 pb=PLAY;break;
404         case APPCOMMAND_MEDIA_RECORD:
405                 pb=RECORD;break;
406         case APPCOMMAND_MEDIA_PREVIOUSTRACK:
407                 pb=SKIPBACK;break;
408         case APPCOMMAND_MEDIA_REWIND:
409                 pb=REVERSE;break;
410         case APPCOMMAND_MEDIA_NEXTTRACK:
411                 pb=SKIPFORWARD;break;
412         case APPCOMMAND_MEDIA_STOP:
413                 pb=STOP;break;
414         case APPCOMMAND_VOLUME_DOWN:
415                 pb=VOLUMEDOWN;break;
416         case APPCOMMAND_VOLUME_UP:
417                 pb=VOLUMEUP;break;
418         case VOMP_YELLOW:
419                 pb=YELLOW; break;
420         case VOMP_BLUE:
421                 pb=BLUE;break;
422         case VOMP_RED:
423                 pb=RED;break;
424         case VOMP_GREEN:
425                 pb=GREEN;break;
426         case VOMP_ENTER:
427                 pb=OK;break;
428         case VOMP_CANCEL:
429                 pb=BACK;break;
430         case VOMP_UP:
431                 pb=UP;break;
432         case VOMP_DOWN:
433                 pb=DOWN;break;
434         case VOMP_LEFT:
435                 pb=LEFT;break;
436         case VOMP_RIGHT:
437                 pb=RIGHT;break;
438         };*/
439     
440         //if (pb==NA_NONE) return 0;
441     UCHAR pb=NA_NONE;
442         pb=TranslateHWC(W_G_HCW(W_HCW_AP,button));
443     if (pb==NA_UNKNOWN || pb==NA_NONE) return 0;
444     curevent=pb;
445     hascurevent=true;
446         //PulseEvent(event);
447         SetEvent(event);
448         return 1;
449 }
450
451 int RemoteWin::ReceiveButtonRI(UINT button) {
452         //UCHAR pb=NA_NONE;
453         //Raw Input
454         /* Note Codes above 0x29c are not listed in the specs on usb.org
455            therefore they are used by try, they might be device dependent
456            thus please supply codes of your remote control */
457 /*      switch (button) { //Processing VK_Messages
458         case 0x35c: //Green
459                 pb=GREEN;break;
460         case 0x35b: //Red
461                 pb=RED;break;
462         case 0x35d: //Yellow
463                 pb=YELLOW;break;
464         case 0x35e: //Blue
465                 pb=BLUE;break;
466         case 0x30d: //MCE Button, used for Menu
467                 pb=MENU;break;
468         case 0x348: //Record Television
469                 pb=RECORD;break;
470         case 0x28d: //Attach File Mmh, how should we assign this
471                 pb=NA_NONE;break;
472         case 0x325: //Playback Televison
473                 pb=PLAY;break;
474         case 0x324: //Playback DVD
475                 pb=PLAY;break;
476         case 0x209: //Properties
477         case 0x35a: //Teletext?
478                 pb=OK;break;
479
480         
481         };
482         if (pb==NA_NONE) return 0;*/
483
484     UCHAR pb=NA_NONE;
485         pb=TranslateHWC(W_G_HCW(W_HCW_RI,button));
486     if (pb==NA_UNKNOWN || pb==NA_NONE) return 0;
487     curevent=pb;
488     hascurevent=true;
489         //PulseEvent(event);
490         SetEvent(event);
491         return 1;
492 }
493
494 void RemoteWin::Signal() {
495         signal=true;
496         //PulseEvent(event);
497         SetEvent(event);
498 }
499
500 void RemoteWin::SendPower()
501 {
502
503         curevent=POWER;
504     hascurevent=true;
505         SetEvent(event);
506 }
507