annotate input/appleir.c @ 37195:ac6c37d85d65 default tip

configure: Fix initialization of variable def_local_aligned_32 It contiained the #define of HAVE_LOCAL_ALIGNED_16 instead of HAVE_LOCAL_ALIGNED_32.
author al
date Sun, 28 Sep 2014 18:38:41 +0000
parents 277ec491a8a7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26763
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
1 /*
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
2 * Linux Apple IR Remote input interface
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
3 *
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
4 * Copyright (C) 2008 Benjamin Zores <ben at geexbox dot org>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
5 *
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
6 * This file is part of MPlayer.
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
7 *
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
11 * (at your option) any later version.
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
12 *
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
16 * GNU General Public License for more details.
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
17 *
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License along
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
21 */
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
22
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
23 #include "config.h"
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
24
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
25 #include "ar.h"
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
26 #include "input.h"
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
27
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
28 #include <stdlib.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
29 #include <stdio.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
30 #include <string.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
31 #include <unistd.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
32 #include <sys/types.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
33 #include <sys/stat.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
34 #include <fcntl.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
35 #include <errno.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
36
26809
5ca7a8309193 add potentially missing types
ben
parents: 26763
diff changeset
37 #include <linux/types.h>
26763
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
38 #include <linux/input.h>
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
39
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
40 #include "mp_msg.h"
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
41 #include "help_mp.h"
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
42
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
43 #define EVDEV_MAX_EVENTS 32
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
44
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
45 /* ripped from AppleIR driver */
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
46 #define USB_VENDOR_APPLE 0x05ac
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
47 #define USB_DEV_APPLE_IR 0x8240
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
48 #define USB_DEV_APPLE_IR_2 0x8242
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
49
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
50 /* Apple IR Remote evdev mapping */
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
51 #define APPLE_IR_MINUS KEY_VOLUMEDOWN
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
52 #define APPLE_IR_PLUS KEY_VOLUMEUP
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
53 #define APPLE_IR_MENU KEY_MENU
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
54 #define APPLE_IR_FORWARD KEY_NEXTSONG
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
55 #define APPLE_IR_PLAY KEY_PLAYPAUSE
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
56 #define APPLE_IR_BACKWARD KEY_PREVIOUSSONG
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
57
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
58 static const struct {
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
59 int linux_keycode;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
60 int value;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
61 int mp_keycode;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
62 } apple_ir_mapping[] = {
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
63 { APPLE_IR_PLAY, 1, AR_PLAY },
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
64 { APPLE_IR_PLAY, 2, AR_PLAY_HOLD },
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
65 { APPLE_IR_FORWARD, 1, AR_NEXT },
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
66 { APPLE_IR_FORWARD, 2, AR_NEXT_HOLD },
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
67 { APPLE_IR_BACKWARD, 1, AR_PREV },
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
68 { APPLE_IR_BACKWARD, 2, AR_PREV_HOLD },
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
69 { APPLE_IR_MENU, 1, AR_MENU },
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
70 { APPLE_IR_MENU, 2, AR_MENU_HOLD },
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26809
diff changeset
71 { APPLE_IR_PLUS, 1, AR_VUP },
26763
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
72 { APPLE_IR_MINUS, 1, AR_VDOWN },
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
73 { -1, -1, -1 }
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
74 };
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
75
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
76 int mp_input_appleir_init (char *dev)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
77 {
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
78 int i, fd;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
79
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
80 if (dev)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
81 {
33827
277ec491a8a7 Do not translate console messages of verbosity level MSGL_V and above.
diego
parents: 29263
diff changeset
82 mp_msg (MSGT_INPUT, MSGL_V, "Initializing Apple IR on %s\n", dev);
26763
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
83 fd = open (dev, O_RDONLY | O_NONBLOCK);
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
84 if (fd < 0)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
85 {
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
86 mp_msg (MSGT_INPUT, MSGL_ERR,
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
87 MSGTR_INPUT_APPLE_IR_CantOpen, strerror (errno));
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
88 return -1;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
89 }
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
90
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
91 return fd;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
92 }
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
93 else
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
94 {
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
95 /* look for a valid AppleIR device on system */
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
96 for (i = 0; i < EVDEV_MAX_EVENTS; i++)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
97 {
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
98 struct input_id id;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
99 char file[64];
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
100
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
101 sprintf (file, "/dev/input/event%d", i);
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
102 fd = open (file, O_RDONLY | O_NONBLOCK);
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
103 if (fd < 0)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
104 continue;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26809
diff changeset
105
26763
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
106 ioctl (fd, EVIOCGID, &id);
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
107 if (id.bustype == BUS_USB &&
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
108 id.vendor == USB_VENDOR_APPLE &&
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
109 (id.product == USB_DEV_APPLE_IR ||id.product == USB_DEV_APPLE_IR_2))
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
110 {
33827
277ec491a8a7 Do not translate console messages of verbosity level MSGL_V and above.
diego
parents: 29263
diff changeset
111 mp_msg (MSGT_INPUT, MSGL_V, "Detected Apple IR on %s\n", file);
26763
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
112 return fd;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
113 }
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
114 close (fd);
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
115 }
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
116
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
117 mp_msg (MSGT_INPUT, MSGL_ERR,
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
118 MSGTR_INPUT_APPLE_IR_CantOpen, strerror (errno));
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
119 }
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
120
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
121 return -1;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
122 }
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
123
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
124 int mp_input_appleir_read (int fd)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
125 {
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
126 struct input_event ev;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
127 int i, r;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
128
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
129 r = read (fd, &ev, sizeof (struct input_event));
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
130 if (r <= 0 || r < sizeof (struct input_event))
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
131 return MP_INPUT_NOTHING;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
132
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
133 /* check for key press only */
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
134 if (ev.type != EV_KEY)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
135 return MP_INPUT_NOTHING;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
136
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
137 /* EvDev Key values:
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
138 * 0: key release
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
139 * 1: key press
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
140 * 2: key auto-repeat
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
141 */
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
142 if (ev.value == 0)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
143 return MP_INPUT_NOTHING;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
144
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
145 /* find Linux evdev -> MPlayer keycode mapping */
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
146 for (i = 0; apple_ir_mapping[i].linux_keycode != -1; i++)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
147 if (apple_ir_mapping[i].linux_keycode == ev.code &&
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
148 apple_ir_mapping[i].value == ev.value)
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
149 return apple_ir_mapping[i].mp_keycode;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26809
diff changeset
150
26763
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
151 return MP_INPUT_NOTHING;
c13288eeb9f6 Add support for AppleIR Remote as an input under Linux systems.
ben
parents:
diff changeset
152 }