annotate input/ar.c @ 29932:7c5fd4b35889

Add support for nv12/nv21 input.
author ramiro
date Thu, 03 Dec 2009 18:18:13 +0000
parents eda346733b8c
children c3c015112837
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
1 /*
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
2 * Apple Remote input interface
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
3 *
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
4 * Copyright (C) 2007 Zoltan Ponekker <pontscho at kac.poliod.hu>
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
5 *
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
6 * (modified a bit by Ulion <ulion2002 at gmail.com>)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
7 *
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
8 * This file is part of MPlayer.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
9 *
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
10 * MPlayer is free software; you can redistribute it and/or modify
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
13 * (at your option) any later version.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
14 *
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
15 * MPlayer is distributed in the hope that it will be useful,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
18 * GNU General Public License for more details.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
19 *
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 25962
diff changeset
20 * You should have received a copy of the GNU General Public License along
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 25962
diff changeset
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 25962
diff changeset
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
23 */
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
24
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
25 #include <IOKit/IOCFPlugIn.h>
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
26 #include <IOKit/hid/IOHIDLib.h>
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
27 #include <Carbon/Carbon.h>
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
28
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
29 #include <sys/types.h>
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
30 #include <unistd.h>
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
31
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
32 #include "input.h"
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
33 #include "ar.h"
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
34
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
35 extern int slave_mode;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
36
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
37 extern const double NSAppKitVersionNumber;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
38
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
39 typedef struct cookie_keycode_map {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
40 char *cookies;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
41 int seq_len;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
42 int keycode;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
43 } cookie_keycode_map_t;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
44
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
45 /* On tiger, 5 always follows 6; on leopard, 18 always follows 19.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
46 * On leopard, there seems to be no cookie value of 5 or 6.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
47 * Following is the shortened cookie sequence list
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
48 * keycode cookies_on_tiger cookies_on_leopard *down_state
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
49 * AR_PREV_HOLD 14+6+3+2 31+19+3+2 yes
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
50 * AR_NEXT_HOLD 14+6+4+2 31+19+4+2 yes
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
51 * AR_MENU_HOLD 14+6+14+6 31+19+31+19
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
52 * AR_VUP 14+12+11+6 31+29+28+19 yes
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
53 * AR_VDOWN 14+13+11+6 31+30+28+19 yes
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
54 * AR_MENU 14+7+6+14+7+6 31+20+19+31+20+19
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
55 * AR_PLAY 14+8+6+14+8+6 31+21+19+31+21+19
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
56 * AR_NEXT 14+9+6+14+9+6 31+22+19+31+22+19
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
57 * AR_PREV 14+10+6+14+10+6 31+23+19+31+23+19
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
58 * AR_PLAY_HOLD 18+14+6+18+14+6 35+31+19+35+31+19
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
59 *
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
60 * *down_state: A button with this feature has a pressed event and
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
61 * a released event, with which we can trace the state of the button.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
62 * A button without this feature will only return one release event.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
63 *
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
64 * hidden keys currently not implemented:
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
65 * hold for 5 secs
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
66 * MENU_NEXT_HOLD 15+14+6+15+14+6
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
67 * MENU_PREV_HOLD 16+14+6+16+14+6
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
68 * MENU_VUP_HOLD 20+14+6+20+14+6
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
69 * MENU_VDOWN_HOLD 19+14+6+19+14+6
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
70 *
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
71 * It seems that pressing 'menu' and 'play' on the Apple Remote for
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
72 * 5 seconds will trigger the make-pair function of the remote.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
73 * MENU_PLAY_HOLD 21+15+14+6+15+14+6
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
74 */
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
75
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
76 static const cookie_keycode_map_t ar_codes_tiger[] = {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
77 { "\x0E\x06\x03\x02", 4, AR_PREV_HOLD },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
78 { "\x0E\x06\x04\x02", 4, AR_NEXT_HOLD },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
79 { "\x0E\x06\x0E\x06", 4, AR_MENU_HOLD },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
80 { "\x0E\x0C\x0B\x06", 4, AR_VUP },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
81 { "\x0E\x0D\x0B\x06", 4, AR_VDOWN },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
82 { "\x0E\x07\x06\x0E\x07\x06", 6, AR_MENU },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
83 { "\x0E\x08\x06\x0E\x08\x06", 6, AR_PLAY },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
84 { "\x0E\x09\x06\x0E\x09\x06", 6, AR_NEXT },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
85 { "\x0E\x0A\x06\x0E\x0A\x06", 6, AR_PREV },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
86 { "\x12\x0E\x06\x12\x0E\x06", 6, AR_PLAY_HOLD },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
87 { NULL, 0, MP_INPUT_NOTHING },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
88 };
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
89
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
90 static const cookie_keycode_map_t ar_codes_leopard[] = {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
91 { "\x1F\x13\x03\x02", 4, AR_PREV_HOLD },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
92 { "\x1F\x13\x04\x02", 4, AR_NEXT_HOLD },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
93 { "\x1F\x13\x1F\x13", 4, AR_MENU_HOLD },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
94 { "\x1F\x1D\x1C\x13", 4, AR_VUP },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
95 { "\x1F\x1E\x1C\x13", 4, AR_VDOWN },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
96 { "\x1F\x14\x13\x1F\x14\x13", 6, AR_MENU },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
97 { "\x1F\x15\x13\x1F\x15\x13", 6, AR_PLAY },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
98 { "\x1F\x16\x13\x1F\x16\x13", 6, AR_NEXT },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
99 { "\x1F\x17\x13\x1F\x17\x13", 6, AR_PREV },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
100 { "\x23\x1F\x13\x23\x1F\x13", 6, AR_PLAY_HOLD },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
101 { NULL, 0, MP_INPUT_NOTHING },
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
102 };
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
103
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
104 static int is_leopard;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
105 static const cookie_keycode_map_t *ar_codes;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
106
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
107 static IOHIDQueueInterface **queue;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
108 static IOHIDDeviceInterface **hidDeviceInterface = NULL;
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24643
diff changeset
109 static int initialized = 0;
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
110 static int hidDeviceIsOpen;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
111
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
112 /* Maximum number of elements in queue before oldest elements
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
113 in queue begin to be lost. Set to 16 to hold at least 2 events. */
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
114 static const int MAX_QUEUE_SIZE = 16;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
115
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
116
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
117 static int FindHIDDevices(mach_port_t masterPort,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
118 io_iterator_t *hidObjectIterator)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
119 {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
120 CFMutableDictionaryRef hidMatchDictionary;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
121 IOReturn ioReturnValue;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
122
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
123 // Set up a matching dictionary to search the I/O Registry
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
124 // by class name for all HID class devices.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
125 hidMatchDictionary = IOServiceMatching("AppleIRController");
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
126
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
127 // Now search I/O Registry for matching devices.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
128 ioReturnValue = IOServiceGetMatchingServices(masterPort,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
129 hidMatchDictionary,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
130 hidObjectIterator);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
131
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
132 // If search is unsuccessful, print message and hang.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
133 if (ioReturnValue != kIOReturnSuccess ||
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
134 !IOIteratorIsValid(*hidObjectIterator)) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
135 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
136 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
137 return 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
138 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
139
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
140 static int getHIDCookies(IOHIDDeviceInterface122 **handle,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
141 IOHIDElementCookie **cookies,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
142 int *nr_cookies)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
143 {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
144 CFTypeRef object;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
145 long number;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
146 CFArrayRef elements;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
147 CFDictionaryRef element;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
148 CFIndex i;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
149
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
150 *nr_cookies = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
151
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
152 if (!handle || !(*handle))
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
153 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
154
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
155 // Copy all elements, since we're grabbing most of the elements
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
156 // for this device anyway, and thus, it's faster to iterate them
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
157 // ourselves. When grabbing only one or two elements, a matching
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
158 // dictionary should be passed in here instead of NULL.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
159 if (((*handle)->copyMatchingElements(handle, NULL, &elements)) != kIOReturnSuccess)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
160 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
161
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
162 // No elements, still a valid result.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
163 if (CFArrayGetCount(elements)==0)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
164 return 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
165
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
166 *cookies = calloc(CFArrayGetCount(elements), sizeof(IOHIDElementCookie));
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
167 if (*cookies == NULL)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
168 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
169
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
170 for (i=0; i<CFArrayGetCount(elements); i++) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
171 element = CFArrayGetValueAtIndex(elements, i);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
172
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
173 // Get cookie.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
174 object = CFDictionaryGetValue(element, CFSTR(kIOHIDElementCookieKey));
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
175 if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID())
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
176 continue;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
177 if (!CFNumberGetValue((CFNumberRef)object, kCFNumberLongType, &number))
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
178 continue;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
179 (*cookies)[(*nr_cookies)++] = (IOHIDElementCookie)number;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
180 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
181
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
182 return 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
183 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
184
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
185 static int CreateHIDDeviceInterface(io_object_t hidDevice,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
186 IOHIDDeviceInterface ***hidDeviceInterface)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
187 {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
188 io_name_t className;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
189 IOCFPlugInInterface **plugInInterface = NULL;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
190 SInt32 score = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
191
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
192 if (IOObjectGetClass(hidDevice, className) != kIOReturnSuccess)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
193 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
194
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
195 if (IOCreatePlugInInterfaceForService(hidDevice,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
196 kIOHIDDeviceUserClientTypeID,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
197 kIOCFPlugInInterfaceID,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
198 &plugInInterface,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
199 &score) != kIOReturnSuccess)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
200 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
201
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
202 // Call a method of the intermediate plugin to create the device interface
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
203 if ((*plugInInterface)->QueryInterface(plugInInterface,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
204 CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
205 (LPVOID)hidDeviceInterface) != S_OK
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
206 || *hidDeviceInterface == NULL || **hidDeviceInterface == NULL) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
207 (*plugInInterface)->Release(plugInInterface);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
208 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
209 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
210
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
211 (*plugInInterface)->Release(plugInInterface);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
212
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
213 return 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
214 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
215
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
216 int mp_input_ar_init(void)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
217 {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
218 io_iterator_t hidObjectIterator;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
219 io_object_t hidDevice;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
220 int i;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
221 IOHIDElementCookie *cookies = NULL;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
222 int nr_cookies = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
223
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24643
diff changeset
224 if (initialized)
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
225 mp_input_ar_close(-1);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
226
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
227 if (floor(NSAppKitVersionNumber) <= 824 /* NSAppKitVersionNumber10_4 */) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
228 ar_codes = &ar_codes_tiger[0];
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
229 is_leopard = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
230 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
231 else {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
232 ar_codes = &ar_codes_leopard[0];
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
233 is_leopard = 1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
234 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
235
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
236 if (FindHIDDevices(kIOMasterPortDefault, &hidObjectIterator))
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
237 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
238
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
239 // Multiple controls could be found, we only use the first usable one.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
240 while ((hidDevice = IOIteratorNext(hidObjectIterator))) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
241 if (CreateHIDDeviceInterface(hidDevice, &hidDeviceInterface) < 0) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
242 hidDeviceInterface = NULL;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
243 IOObjectRelease(hidDevice);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
244 continue;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
245 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
246 if (getHIDCookies((IOHIDDeviceInterface122 **)hidDeviceInterface,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
247 &cookies,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
248 &nr_cookies) < 0) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
249 (*hidDeviceInterface)->Release(hidDeviceInterface);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
250 hidDeviceInterface = NULL;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
251 IOObjectRelease(hidDevice);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
252 continue;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
253 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
254 IOObjectRelease(hidDevice);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
255 break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
256 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
257 if (hidDeviceInterface == NULL)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
258 goto mp_input_ar_init_error;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
259
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
260 // Open the device.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
261 if ((*hidDeviceInterface)->open(hidDeviceInterface,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
262 kIOHIDOptionsTypeSeizeDevice) != kIOReturnSuccess)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
263 goto mp_input_ar_init_error;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
264 hidDeviceIsOpen = 1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
265
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
266 if ((queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface)) == NULL
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
267 || *queue == NULL)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
268 goto mp_input_ar_init_error;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
269
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
270 // Create the queue.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
271 (*queue)->create(queue, 0, MAX_QUEUE_SIZE);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
272
24042
0354fab1e257 Clarify comment as pointed out by Ulion.
diego
parents: 24037
diff changeset
273 // Add elements to the queue to make the queue work.
0354fab1e257 Clarify comment as pointed out by Ulion.
diego
parents: 24037
diff changeset
274 // On tiger, it's a sequence from 1 to 21,
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
275 // maybe it's the range of cookie values.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
276 for (i = 0;i < nr_cookies;i++)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
277 (*queue)->addElement(queue, cookies[i], 0);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
278
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
279 // not used anymore
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
280 if (cookies != NULL)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
281 free(cookies);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
282
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
283 // Start data delivery to the queue.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
284 (*queue)->start(queue);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
285
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
286 // not useful anymore
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
287 IOObjectRelease(hidObjectIterator);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
288
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24643
diff changeset
289 initialized = 1;
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
290 return 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
291
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
292 mp_input_ar_init_error:
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
293 if (cookies != NULL)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
294 free(cookies);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
295 if (hidDeviceInterface != NULL) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
296 if (*hidDeviceInterface != NULL) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
297 (*hidDeviceInterface)->close(hidDeviceInterface);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
298 (*hidDeviceInterface)->Release(hidDeviceInterface);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
299 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
300 hidDeviceInterface = NULL;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
301 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
302 IOObjectRelease(hidObjectIterator);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
303 return -1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
304 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
305
29212
eda346733b8c Add missing 'void' to parameterless function declarations.
diego
parents: 26743
diff changeset
306 int is_mplayer_front(void)
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
307 {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
308 ProcessSerialNumber myProc, frProc;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
309 Boolean sameProc;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
310 pid_t parentPID;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
311
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
312 if (GetFrontProcess(&frProc) == noErr
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
313 && GetCurrentProcess(&myProc) == noErr
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
314 && SameProcess(&frProc, &myProc, &sameProc) == noErr) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
315 if (sameProc)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
316 return 1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
317 // If MPlayer is running in slave mode, also check parent process.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
318 if (slave_mode && GetProcessPID(&frProc, &parentPID) == noErr)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
319 return parentPID==getppid();
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
320 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
321 return 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
322 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
323
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
324 int mp_input_ar_read(int fd)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
325 {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
326 int i, down = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
327 int ret = MP_INPUT_NOTHING;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
328 AbsoluteTime zeroTime = {0,0};
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
329 IOHIDEventStruct event;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
330 static int prev_event = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
331 IOReturn result = kIOReturnSuccess;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
332
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
333 const cookie_keycode_map_t *ar_code;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
334 int cookie_nr = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
335 char cookie_queue[MAX_QUEUE_SIZE];
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
336 int value_queue[MAX_QUEUE_SIZE];
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
337
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24643
diff changeset
338 if (initialized == 0)
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
339 return MP_INPUT_NOTHING;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
340
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
341 while ((result = (*queue)->getNextEvent(queue, &event, zeroTime, 0)) == kIOReturnSuccess) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
342 #ifdef TEST
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
343 printf(" - event cookie: %d, value: %d, long value: %d\n",
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
344 (int)event.elementCookie, (int)event.value, (int)event.longValue);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
345 #endif
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
346 // Shorten cookie sequence by removing cookies value 5 and 18,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
347 // since 5 always follows 6 (on tiger), 18 follows 19 (on leopard).
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
348 if ((int)event.elementCookie == 5
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
349 || ((int)event.elementCookie == 18 && is_leopard))
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
350 continue;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
351 // Check valid cookie range.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
352 if ((int)event.elementCookie > 35 || (int)event.elementCookie < 2) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
353 cookie_nr = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
354 continue;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
355 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
356 cookie_queue[cookie_nr] = (char)(int)event.elementCookie;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
357 value_queue[cookie_nr++] = event.value;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
358 // 4 cookies are necessary to make up a valid sequence.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
359 if (cookie_nr>=4) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
360 // Find matching sequence.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
361 ar_code = ar_codes;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
362 while (ar_code->cookies != NULL &&
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
363 (cookie_nr < ar_code->seq_len ||
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
364 0 != memcmp(ar_code->cookies,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
365 &cookie_queue[cookie_nr-ar_code->seq_len],
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
366 ar_code->seq_len)))
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
367 ++ar_code;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
368 if (ar_code->cookies != NULL) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
369 ret = ar_code->keycode;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
370 switch (ret) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
371 // For these 4 keys, the remote can keep a hold state.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
372 case AR_VUP:
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
373 case AR_VDOWN:
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
374 case AR_NEXT_HOLD:
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
375 case AR_PREV_HOLD:
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
376 for (i = cookie_nr-ar_code->seq_len; i < cookie_nr; ++i) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
377 if (value_queue[i]) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
378 down = MP_KEY_DOWN;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
379 break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
380 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
381 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
382 break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
383 default:
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
384 down = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
385 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
386 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
387 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
388 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
389
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
390 if (!is_mplayer_front()) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
391 if (hidDeviceIsOpen) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
392 (*hidDeviceInterface)->close(hidDeviceInterface);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
393 hidDeviceIsOpen = 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
394
24643
d1827bb15d79 spelling cosmetics
diego
parents: 24042
diff changeset
395 // Read out all pending events.
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
396 while (result == kIOReturnSuccess)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
397 result = (*queue)->getNextEvent(queue, &event, zeroTime, 0);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
398 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
399 return MP_INPUT_NOTHING;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
400 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
401 // If we are switched from running as a foreground process to a
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
402 // background process and back again, re-open the device to make
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
403 // sure we are not affected by the system or other applications
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
404 // using the Apple Remote.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
405 else if (!hidDeviceIsOpen) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
406 if ((*hidDeviceInterface)->open(hidDeviceInterface,
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
407 kIOHIDOptionsTypeSeizeDevice) == kIOReturnSuccess)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
408 hidDeviceIsOpen = 1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
409 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
410
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
411 if (ret > 0)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
412 prev_event = ret;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
413 return ret | down;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
414 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
415
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
416 void mp_input_ar_close(int fd)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
417 {
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24643
diff changeset
418 if (initialized == 0)
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
419 return;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
420
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
421 // Close the device.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
422 (*hidDeviceInterface)->close(hidDeviceInterface);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
423
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
424 // Stop data delivery to queue.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
425 (*queue)->stop(queue);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
426 // Dispose of queue.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
427 (*queue)->dispose(queue);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
428 // Release the queue we allocated.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
429 (*queue)->Release(queue);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
430
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
431 // Release the interface.
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
432 (*hidDeviceInterface)->Release(hidDeviceInterface);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
433
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 24643
diff changeset
434 initialized = 0;
24037
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
435 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
436
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
437 #ifdef TEST
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
438 int main(void)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
439 {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
440 int ret;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
441
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
442 if (mp_input_ar_init() < 0) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
443 printf("Unable to initialize Apple Remote.\n");
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
444 return 1;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
445 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
446
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
447 while (1) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
448 switch ((ret = mp_input_ar_read(0)) & ~MP_KEY_DOWN) {
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
449 case AR_PLAY: printf(" - AR_PLAY."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
450 case AR_PLAY_HOLD: printf(" - AR_PLAY_HOLD."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
451 case AR_NEXT: printf(" - AR_NEXT."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
452 case AR_NEXT_HOLD: printf(" - AR_NEXT_HOLD."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
453 case AR_PREV: printf(" - AR_PREV."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
454 case AR_PREV_HOLD: printf(" - AR_PREV_HOLD."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
455 case AR_MENU: printf(" - AR_MENU."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
456 case AR_MENU_HOLD: printf(" - AR_MENU_HOLD."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
457 case AR_VUP: printf(" - AR_VUP."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
458 case AR_VDOWN: printf(" - AR_VDOWN."); break;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
459 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
460 if ((ret > 0 )&&(ret & MP_KEY_DOWN))
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
461 printf(" [hold]");
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
462 if (ret > 0)
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
463 printf("\n");
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
464 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
465
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
466 mp_input_ar_close(0);
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
467 return 0;
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
468 }
c7f95196dfe5 Apple Remote support
diego
parents:
diff changeset
469 #endif