mirror of
https://github.com/mpv-player/mpv
synced 2024-12-24 07:33:46 +01:00
Add support for AppleIR Remote as an input under Linux systems.
This requires Linux 2.6 with evdev and appleir drivers. The keymapping is done to mimics the one that was done for MacOSX. WARNING: Most distributions do not seems to bother and only let root access to the device. Modify udev rules accordingly if you want regular user to be able to use the remote. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26795 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
971b1a83d8
commit
dc6d14fb1b
@ -950,6 +950,8 @@ Available commands are:
|
||||
Specify input configuration file other than the default
|
||||
~/\:.mplayer/\:input.conf.
|
||||
~/\:.mplayer/\:<filename> is assumed if no full path is given.
|
||||
.IPs ar-dev=<device>
|
||||
Device to be used for Apple IR Remote (default is autodetected, Linux only).
|
||||
.IPs ar-delay
|
||||
Delay in milliseconds before we start to autorepeat a key (0 to disable).
|
||||
.IPs ar-rate
|
||||
|
@ -998,6 +998,9 @@ D
|
||||
lieu de ~/\:.mplayer/\:input.conf par défaut.
|
||||
Si vous ne donnez pas le chemin absolu, il sera cherché à
|
||||
~/\:.mplayer/\:<nom_fichier>.
|
||||
.IPs ar-dev=<peripherique>
|
||||
Périphérique à utiliser pour contrôler la télécommande Apple IR
|
||||
(auto-détecté par défaut, Linux uniquement).
|
||||
.IPs ar-delay
|
||||
Temps en milli-secondes avant de démarrer la répétition automatique
|
||||
d'une touche
|
||||
|
1
Makefile
1
Makefile
@ -510,6 +510,7 @@ SRCS_MPLAYER = mplayer.c \
|
||||
$(addprefix libvo/,$(VO_SRCS)) \
|
||||
|
||||
SRCS_MPLAYER-$(APPLE_REMOTE) += input/ar.c
|
||||
SRCS_MPLAYER-$(APPLE_IR) += input/appleir.c
|
||||
SRCS_MPLAYER-$(GUI_GTK) += gui/app.c \
|
||||
gui/bitmap.c \
|
||||
gui/cfg.c \
|
||||
|
29
configure
vendored
29
configure
vendored
@ -229,6 +229,7 @@ Optional features:
|
||||
--enable-lircc enable LIRCCD (LIRC client daemon) input [autodetect]
|
||||
--enable-joystick enable joystick support [disable]
|
||||
--enable-apple-remote enable Apple Remote input (Mac OS X only) [autodetect]
|
||||
--enable-apple-ir enable Apple IR Remote input (Linux only) [autodetect]
|
||||
--disable-vm disable X video mode extensions [autodetect]
|
||||
--disable-xf86keysym disable support for multimedia keys [autodetect]
|
||||
--enable-radio enable radio interface [disable]
|
||||
@ -630,6 +631,7 @@ _libnut=auto
|
||||
_lirc=auto
|
||||
_lircc=auto
|
||||
_apple_remote=auto
|
||||
_apple_ir=auto
|
||||
_gui=no
|
||||
_gtk1=no
|
||||
_termcap=auto
|
||||
@ -1073,6 +1075,8 @@ for ac_option do
|
||||
--disable-lircc) _lircc=no ;;
|
||||
--enable-apple-remote) _apple_remote=yes ;;
|
||||
--disable-apple-remote) _apple_remote=no ;;
|
||||
--enable-apple-ir) _apple_ir=yes ;;
|
||||
--disable-apple-ir) _apple_ir=no ;;
|
||||
--enable-gui) _gui=yes ;;
|
||||
--disable-gui) _gui=no ;;
|
||||
--enable-gtk1) _gtk1=yes ;;
|
||||
@ -3604,6 +3608,27 @@ echores "$_apple_remote"
|
||||
|
||||
fi #if darwin
|
||||
|
||||
if linux; then
|
||||
|
||||
echocheck "Apple IR"
|
||||
if test "$_apple_ir" = auto ; then
|
||||
_apple_ir=no
|
||||
cat > $TMPC <<EOF
|
||||
#include <linux/input.h>
|
||||
int main(void) {
|
||||
struct input_event ev;
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
cc_check && tmp_run && _apple_ir=yes
|
||||
fi
|
||||
if test "$_apple_ir" = yes ; then
|
||||
_def_apple_ir='#define HAVE_APPLE_IR 1'
|
||||
else
|
||||
_def_apple_ir='#undef HAVE_APPLE_IR'
|
||||
fi
|
||||
echores "$_apple_ir"
|
||||
fi #if linux
|
||||
|
||||
echocheck "pkg-config"
|
||||
_pkg_config=pkg-config
|
||||
@ -7640,6 +7665,7 @@ LADSPA = $_ladspa
|
||||
JOYSTICK = $_joystick
|
||||
LIRC = $_lirc
|
||||
APPLE_REMOTE = $_apple_remote
|
||||
APPLE_IR = $_apple_ir
|
||||
TV = $_tv
|
||||
TV_V4L = $_tv_v4l
|
||||
TV_V4L1 = $_tv_v4l1
|
||||
@ -8050,6 +8076,9 @@ $_def_lirc
|
||||
/* Apple Remote (remote control, see http://docs.info.apple.com/article.html?artnum=302504) support: */
|
||||
$_def_apple_remote
|
||||
|
||||
/* Apple IR Remote (Linux remote control driver) */
|
||||
$_def_apple_ir
|
||||
|
||||
/* Support for maemo (http://www.maemo.org) */
|
||||
$_def_maemo
|
||||
|
||||
|
@ -1296,6 +1296,12 @@ static char help_text[]=
|
||||
#define MSGTR_INPUT_JOYSTICK_WarnLostSync "Joystick: warning init event, we have lost sync with driver.\n"
|
||||
#define MSGTR_INPUT_JOYSTICK_WarnUnknownEvent "Joystick warning unknown event type %d\n"
|
||||
|
||||
// appleir.c
|
||||
|
||||
#define MSGTR_INPUT_APPLE_IR_Init "Initializing Apple IR on %s\n"
|
||||
#define MSGTR_INPUT_APPLE_IR_Detect "Detected Apple IR on %s\n"
|
||||
#define MSGTR_INPUT_APPLE_IR_CantOpen "Can't open Apple IR device: %s\n"
|
||||
|
||||
// input.c
|
||||
|
||||
#define MSGTR_INPUT_INPUT_ErrCantRegister2ManyCmdFds "Too many command file descriptors, cannot register file descriptor %d.\n"
|
||||
|
151
input/appleir.c
Normal file
151
input/appleir.c
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Linux Apple IR Remote input interface
|
||||
*
|
||||
* Copyright (C) 2008 Benjamin Zores <ben at geexbox dot org>
|
||||
*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MPlayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ar.h"
|
||||
#include "input.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
#include "mp_msg.h"
|
||||
#include "help_mp.h"
|
||||
|
||||
#define EVDEV_MAX_EVENTS 32
|
||||
|
||||
/* ripped from AppleIR driver */
|
||||
#define USB_VENDOR_APPLE 0x05ac
|
||||
#define USB_DEV_APPLE_IR 0x8240
|
||||
#define USB_DEV_APPLE_IR_2 0x8242
|
||||
|
||||
/* Apple IR Remote evdev mapping */
|
||||
#define APPLE_IR_MINUS KEY_VOLUMEDOWN
|
||||
#define APPLE_IR_PLUS KEY_VOLUMEUP
|
||||
#define APPLE_IR_MENU KEY_MENU
|
||||
#define APPLE_IR_FORWARD KEY_NEXTSONG
|
||||
#define APPLE_IR_PLAY KEY_PLAYPAUSE
|
||||
#define APPLE_IR_BACKWARD KEY_PREVIOUSSONG
|
||||
|
||||
static const struct {
|
||||
int linux_keycode;
|
||||
int value;
|
||||
int mp_keycode;
|
||||
} apple_ir_mapping[] = {
|
||||
{ APPLE_IR_PLAY, 1, AR_PLAY },
|
||||
{ APPLE_IR_PLAY, 2, AR_PLAY_HOLD },
|
||||
{ APPLE_IR_FORWARD, 1, AR_NEXT },
|
||||
{ APPLE_IR_FORWARD, 2, AR_NEXT_HOLD },
|
||||
{ APPLE_IR_BACKWARD, 1, AR_PREV },
|
||||
{ APPLE_IR_BACKWARD, 2, AR_PREV_HOLD },
|
||||
{ APPLE_IR_MENU, 1, AR_MENU },
|
||||
{ APPLE_IR_MENU, 2, AR_MENU_HOLD },
|
||||
{ APPLE_IR_PLUS, 1, AR_VUP },
|
||||
{ APPLE_IR_MINUS, 1, AR_VDOWN },
|
||||
{ -1, -1, -1 }
|
||||
};
|
||||
|
||||
int mp_input_appleir_init (char *dev)
|
||||
{
|
||||
int i, fd;
|
||||
|
||||
if (dev)
|
||||
{
|
||||
mp_msg (MSGT_INPUT, MSGL_V, MSGTR_INPUT_APPLE_IR_Init, dev);
|
||||
fd = open (dev, O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
{
|
||||
mp_msg (MSGT_INPUT, MSGL_ERR,
|
||||
MSGTR_INPUT_APPLE_IR_CantOpen, strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* look for a valid AppleIR device on system */
|
||||
for (i = 0; i < EVDEV_MAX_EVENTS; i++)
|
||||
{
|
||||
struct input_id id;
|
||||
char file[64];
|
||||
|
||||
sprintf (file, "/dev/input/event%d", i);
|
||||
fd = open (file, O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
continue;
|
||||
|
||||
ioctl (fd, EVIOCGID, &id);
|
||||
if (id.bustype == BUS_USB &&
|
||||
id.vendor == USB_VENDOR_APPLE &&
|
||||
(id.product == USB_DEV_APPLE_IR ||id.product == USB_DEV_APPLE_IR_2))
|
||||
{
|
||||
mp_msg (MSGT_INPUT, MSGL_V, MSGTR_INPUT_APPLE_IR_Detect, file);
|
||||
return fd;
|
||||
}
|
||||
close (fd);
|
||||
}
|
||||
|
||||
mp_msg (MSGT_INPUT, MSGL_ERR,
|
||||
MSGTR_INPUT_APPLE_IR_CantOpen, strerror (errno));
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mp_input_appleir_read (int fd)
|
||||
{
|
||||
struct input_event ev;
|
||||
int i, r;
|
||||
|
||||
r = read (fd, &ev, sizeof (struct input_event));
|
||||
if (r <= 0 || r < sizeof (struct input_event))
|
||||
return MP_INPUT_NOTHING;
|
||||
|
||||
/* check for key press only */
|
||||
if (ev.type != EV_KEY)
|
||||
return MP_INPUT_NOTHING;
|
||||
|
||||
/* EvDev Key values:
|
||||
* 0: key release
|
||||
* 1: key press
|
||||
* 2: key auto-repeat
|
||||
*/
|
||||
if (ev.value == 0)
|
||||
return MP_INPUT_NOTHING;
|
||||
|
||||
/* find Linux evdev -> MPlayer keycode mapping */
|
||||
for (i = 0; apple_ir_mapping[i].linux_keycode != -1; i++)
|
||||
if (apple_ir_mapping[i].linux_keycode == ev.code &&
|
||||
apple_ir_mapping[i].value == ev.value)
|
||||
return apple_ir_mapping[i].mp_keycode;
|
||||
|
||||
return MP_INPUT_NOTHING;
|
||||
}
|
@ -35,8 +35,13 @@
|
||||
#define AR_VUP (AR_BASE + 8)
|
||||
#define AR_VDOWN (AR_BASE + 9)
|
||||
|
||||
/* MacOSX Driver */
|
||||
int mp_input_ar_init(void);
|
||||
int mp_input_ar_read(int fd);
|
||||
void mp_input_ar_close(int fd);
|
||||
|
||||
/* Linux Driver */
|
||||
int mp_input_appleir_init(char* dev);
|
||||
int mp_input_appleir_read(int fd);
|
||||
|
||||
#endif /* MPLAYER_AR_H */
|
||||
|
@ -569,6 +569,7 @@ static char* config_file = "input.conf";
|
||||
static int use_ar = 1;
|
||||
|
||||
static char* js_dev = NULL;
|
||||
static char* ar_dev = NULL;
|
||||
|
||||
static char* in_file = NULL;
|
||||
static int in_file_fd = -1;
|
||||
@ -579,6 +580,7 @@ static int mp_input_print_cmd_list(m_option_t* cfg);
|
||||
// Our command line options
|
||||
static m_option_t input_conf[] = {
|
||||
{ "conf", &config_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL },
|
||||
{ "ar-dev", &ar_dev, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL },
|
||||
{ "ar-delay", &ar_delay, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL },
|
||||
{ "ar-rate", &ar_rate, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL },
|
||||
{ "keylist", mp_input_print_key_list, CONF_TYPE_FUNC, CONF_GLOBAL, 0, 0, NULL },
|
||||
@ -1760,6 +1762,16 @@ mp_input_init(int use_gui) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_APPLE_IR
|
||||
if(use_ar) {
|
||||
int fd = mp_input_appleir_init(ar_dev);
|
||||
if(fd < 0)
|
||||
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantInitAppleRemote);
|
||||
else
|
||||
mp_input_add_key_fd(fd,1,mp_input_appleir_read,(mp_close_func_t)close);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(in_file) {
|
||||
struct stat st;
|
||||
if(stat(in_file,&st))
|
||||
|
Loading…
Reference in New Issue
Block a user