annotate input/ar.c @ 34045:4831a5fa1d78

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