2002-01-30 12:46:03 +00:00
|
|
|
#include "../config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/types.h>
|
2002-10-22 14:32:17 +00:00
|
|
|
#include <sys/stat.h>
|
2002-02-04 14:48:32 +00:00
|
|
|
#include <sys/time.h>
|
2002-01-30 12:46:03 +00:00
|
|
|
#include <fcntl.h>
|
2002-06-12 10:39:04 +00:00
|
|
|
#include <ctype.h>
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
#include "input.h"
|
2002-02-08 18:10:56 +00:00
|
|
|
#include "mouse.h"
|
2002-01-30 12:46:03 +00:00
|
|
|
#ifdef MP_DEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
#endif
|
2003-02-09 20:18:23 +00:00
|
|
|
#include "../osdep/getch2.h"
|
|
|
|
#include "../osdep/keycodes.h"
|
|
|
|
#include "../osdep/timer.h"
|
2002-11-12 01:56:42 +00:00
|
|
|
#include "../mp_msg.h"
|
2003-08-13 16:29:32 +00:00
|
|
|
#include "../m_config.h"
|
|
|
|
#include "../m_option.h"
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
#include "joystick.h"
|
|
|
|
|
2002-01-31 09:39:11 +00:00
|
|
|
#ifdef HAVE_LIRC
|
|
|
|
#include "lirc.h"
|
|
|
|
#endif
|
|
|
|
|
2003-05-30 18:23:55 +00:00
|
|
|
#ifdef HAVE_LIRCC
|
|
|
|
#include <lirc/lircc.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-09 01:42:19 +00:00
|
|
|
/// This array defines all known commands.
|
|
|
|
/// The first field is an id used to recognize the command without too many strcmp.
|
|
|
|
/// The second is obviously the command name.
|
|
|
|
/// The third is the minimum number of arguments this command needs.
|
|
|
|
/// Then comes the definition of each argument, terminated with an arg of type -1.
|
|
|
|
/// A command can take a maximum of MP_CMD_MAX_ARGS-1 arguments (-1 because of
|
|
|
|
/// the last one) which is actually 9.
|
2002-03-19 13:30:16 +00:00
|
|
|
|
|
|
|
/// For the args, the first field is the type (actually int, float or string), the second
|
|
|
|
/// is the default value wich is used for optional arguments
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
static mp_cmd_t mp_cmds[] = {
|
2005-02-17 15:56:25 +00:00
|
|
|
{ MP_CMD_SEEK, "seek", 1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-12-23 00:33:22 +00:00
|
|
|
#ifdef USE_EDL
|
|
|
|
{ MP_CMD_EDL_MARK, "edl_mark", 0, { {-1,{0}} } },
|
|
|
|
#endif
|
2002-01-30 12:46:03 +00:00
|
|
|
{ MP_CMD_AUDIO_DELAY, "audio_delay", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
|
2004-10-20 20:07:50 +00:00
|
|
|
{ MP_CMD_SPEED_INCR, "speed_incr", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_SPEED_MULT, "speed_mult", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_SPEED_SET, "speed_set", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
|
2004-09-15 09:29:10 +00:00
|
|
|
{ MP_CMD_QUIT, "quit", 0, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-01-30 12:46:03 +00:00
|
|
|
{ MP_CMD_PAUSE, "pause", 0, { {-1,{0}} } },
|
2004-10-12 22:10:56 +00:00
|
|
|
{ MP_CMD_FRAME_STEP, "frame_step", 0, { {-1,{0}} } },
|
2002-03-12 12:04:40 +00:00
|
|
|
{ MP_CMD_GRAB_FRAMES, "grab_frames",0, { {-1,{0}} } },
|
2002-03-16 16:36:32 +00:00
|
|
|
{ MP_CMD_PLAY_TREE_STEP, "pt_step",1, { { MP_CMD_ARG_INT ,{0}}, { MP_CMD_ARG_INT ,{0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_PLAY_TREE_UP_STEP, "pt_up_step",1, { { MP_CMD_ARG_INT,{0} }, { MP_CMD_ARG_INT ,{0}}, {-1,{0}} } },
|
2002-01-30 12:46:03 +00:00
|
|
|
{ MP_CMD_PLAY_ALT_SRC_STEP, "alt_src_step",1, { { MP_CMD_ARG_INT,{0} }, {-1,{0}} } },
|
|
|
|
{ MP_CMD_SUB_DELAY, "sub_delay",1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-12-05 00:15:56 +00:00
|
|
|
{ MP_CMD_SUB_STEP, "sub_step",1, { { MP_CMD_ARG_INT,{0} }, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-01-30 12:46:03 +00:00
|
|
|
{ MP_CMD_OSD, "osd",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
|
2003-05-17 09:21:21 +00:00
|
|
|
{ MP_CMD_OSD_SHOW_TEXT, "osd_show_text", 1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },
|
2002-08-21 20:44:29 +00:00
|
|
|
{ MP_CMD_VOLUME, "volume", 1, { { MP_CMD_ARG_INT,{0} }, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-01-30 12:46:03 +00:00
|
|
|
{ MP_CMD_MIXER_USEMASTER, "use_master", 0, { {-1,{0}} } },
|
2002-06-06 07:13:57 +00:00
|
|
|
{ MP_CMD_MUTE, "mute", 0, { {-1,{0}} } },
|
2002-01-30 12:46:03 +00:00
|
|
|
{ MP_CMD_CONTRAST, "contrast",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-09-27 21:08:36 +00:00
|
|
|
{ MP_CMD_GAMMA, "gamma", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-01-30 12:46:03 +00:00
|
|
|
{ MP_CMD_BRIGHTNESS, "brightness",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_HUE, "hue",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_SATURATION, "saturation",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_FRAMEDROPPING, "frame_drop",0, { { MP_CMD_ARG_INT,{-1} }, {-1,{0}} } },
|
2002-03-10 03:47:53 +00:00
|
|
|
{ MP_CMD_SUB_POS, "sub_pos", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-12-23 01:37:43 +00:00
|
|
|
{ MP_CMD_SUB_ALIGNMENT, "sub_alignment",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
|
2002-10-06 17:40:51 +00:00
|
|
|
{ MP_CMD_SUB_VISIBILITY, "sub_visibility", 0, { {-1,{0}} } },
|
2005-06-09 20:13:53 +00:00
|
|
|
{ MP_CMD_SUB_LOAD, "sub_load", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_SUB_REMOVE, "sub_remove", 0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
|
2005-04-11 21:26:14 +00:00
|
|
|
{ MP_CMD_SUB_SELECT, "vobsub_lang", 0, { { MP_CMD_ARG_INT,{-2} }, {-1,{0}} } }, // for compatibility
|
|
|
|
{ MP_CMD_SUB_SELECT, "sub_select", 0, { { MP_CMD_ARG_INT,{-2} }, {-1,{0}} } },
|
2005-02-12 14:45:54 +00:00
|
|
|
{ MP_CMD_SUB_LOG, "sub_log", 0, { {-1,{0}} } },
|
2002-12-05 00:11:12 +00:00
|
|
|
{ MP_CMD_GET_PERCENT_POS, "get_percent_pos", 0, { {-1,{0}} } },
|
2005-05-18 11:38:06 +00:00
|
|
|
{ MP_CMD_GET_TIME_POS, "get_time_pos", 0, { {-1,{0}} } },
|
2002-12-05 00:11:12 +00:00
|
|
|
{ MP_CMD_GET_TIME_LENGTH, "get_time_length", 0, { {-1,{0}} } },
|
2005-04-28 14:43:19 +00:00
|
|
|
{ MP_CMD_SWITCH_AUDIO, "switch_audio", 0, { { MP_CMD_ARG_INT,{-1} }, {-1,{0}} } },
|
2002-01-30 12:46:03 +00:00
|
|
|
#ifdef USE_TV
|
|
|
|
{ MP_CMD_TV_STEP_CHANNEL, "tv_step_channel", 1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
|
|
|
|
{ MP_CMD_TV_STEP_NORM, "tv_step_norm",0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_TV_STEP_CHANNEL_LIST, "tv_step_chanlist", 0, { {-1,{0}} } },
|
2002-12-19 10:09:43 +00:00
|
|
|
{ MP_CMD_TV_SET_CHANNEL, "tv_set_channel", 1, { { MP_CMD_ARG_STRING, {0}}, {-1,{0}} }},
|
2002-12-28 22:57:39 +00:00
|
|
|
{ MP_CMD_TV_LAST_CHANNEL, "tv_last_channel", 0, { {-1,{0}} } },
|
2003-08-04 09:13:10 +00:00
|
|
|
{ MP_CMD_TV_SET_FREQ, "tv_set_freq", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_TV_SET_NORM, "tv_set_norm", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
|
2003-08-12 07:38:49 +00:00
|
|
|
{ MP_CMD_TV_SET_BRIGHTNESS, "tv_set_brightness", 1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
|
|
|
|
{ MP_CMD_TV_SET_CONTRAST, "tv_set_contrast", 1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
|
|
|
|
{ MP_CMD_TV_SET_HUE, "tv_set_hue", 1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
|
|
|
|
{ MP_CMD_TV_SET_SATURATION, "tv_set_saturation", 1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
|
2003-08-16 09:51:05 +00:00
|
|
|
#endif
|
2003-09-21 14:21:43 +00:00
|
|
|
{ MP_CMD_SUB_FORCED_ONLY, "forced_subs_only", 0, { {-1,{0}} } },
|
2003-08-16 09:51:05 +00:00
|
|
|
#ifdef HAS_DVBIN_SUPPORT
|
2004-04-26 21:15:14 +00:00
|
|
|
{ MP_CMD_DVB_SET_CHANNEL, "dvb_set_channel", 2, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}}}},
|
2002-01-30 12:46:03 +00:00
|
|
|
#endif
|
2004-09-15 09:45:34 +00:00
|
|
|
{ MP_CMD_SWITCH_RATIO, "switch_ratio", 0, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
|
2002-02-17 01:06:50 +00:00
|
|
|
{ MP_CMD_VO_FULLSCREEN, "vo_fullscreen", 0, { {-1,{0}} } },
|
2003-11-30 16:36:10 +00:00
|
|
|
{ MP_CMD_VO_ONTOP, "vo_ontop", 0, { {-1,{0}} } },
|
2004-08-22 19:01:56 +00:00
|
|
|
{ MP_CMD_VO_ROOTWIN, "vo_rootwin", 0, { {-1,{0}} } },
|
2002-05-18 00:11:43 +00:00
|
|
|
{ MP_CMD_SCREENSHOT, "screenshot", 0, { {-1,{0}} } },
|
2002-06-04 20:17:07 +00:00
|
|
|
{ MP_CMD_PANSCAN, "panscan",1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2004-09-02 12:02:06 +00:00
|
|
|
{ MP_CMD_SWITCH_VSYNC, "switch_vsync", 0, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-07-26 21:26:39 +00:00
|
|
|
{ MP_CMD_LOADFILE, "loadfile", 1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_LOADLIST, "loadlist", 1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },
|
2004-12-02 14:37:16 +00:00
|
|
|
{ MP_CMD_RUN, "run", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
|
2002-08-04 02:22:27 +00:00
|
|
|
{ MP_CMD_VF_CHANGE_RECTANGLE, "change_rectangle", 2, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}}}},
|
2002-02-25 13:14:27 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_NEW_GUI
|
|
|
|
{ MP_CMD_GUI_LOADFILE, "gui_loadfile", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_GUI_LOADSUBTITLE, "gui_loadsubtitle", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_GUI_ABOUT, "gui_about", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_GUI_PLAY, "gui_play", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_GUI_STOP, "gui_stop", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_GUI_PLAYLIST, "gui_playlist", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_GUI_PREFERENCES, "gui_preferences", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_GUI_SKINBROWSER, "gui_skinbrowser", 0, { {-1,{0}} } },
|
|
|
|
#endif
|
2002-03-28 20:40:21 +00:00
|
|
|
|
|
|
|
#ifdef USE_DVDNAV
|
|
|
|
{ MP_CMD_DVDNAV, "dvdnav", 1, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
|
2002-04-03 17:58:17 +00:00
|
|
|
{ MP_CMD_DVDNAV_EVENT, "dvdnav_event", 1, { { MP_CMD_ARG_VOID, {0}}, {-1, {0}} } },
|
2002-03-28 20:40:21 +00:00
|
|
|
#endif
|
2002-11-14 23:41:44 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
{ MP_CMD_MENU, "menu",1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_SET_MENU, "set_menu",1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },
|
|
|
|
{ MP_CMD_CHELP, "help", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_CEXIT, "exit", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_CHIDE, "hide", 0, { {MP_CMD_ARG_INT,{3000}}, {-1,{0}} } },
|
|
|
|
#endif
|
2003-09-19 20:44:30 +00:00
|
|
|
|
|
|
|
{ MP_CMD_GET_VO_FULLSCREEN, "get_vo_fullscreen", 0, { {-1,{0}} } },
|
|
|
|
{ MP_CMD_GET_SUB_VISIBILITY, "get_sub_visibility", 0, { {-1,{0}} } },
|
2002-02-25 13:14:27 +00:00
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
{ 0, NULL, 0, {} }
|
|
|
|
};
|
|
|
|
|
2003-07-09 01:42:19 +00:00
|
|
|
/// The names of the keys as used in input.conf
|
2002-03-19 13:30:16 +00:00
|
|
|
/// If you add some new keys, you also need to add them here
|
|
|
|
|
2002-02-08 18:10:56 +00:00
|
|
|
static mp_key_name_t key_names[] = {
|
2002-01-30 12:46:03 +00:00
|
|
|
{ ' ', "SPACE" },
|
|
|
|
{ KEY_ENTER, "ENTER" },
|
|
|
|
{ KEY_TAB, "TAB" },
|
|
|
|
{ KEY_CTRL, "CTRL" },
|
|
|
|
{ KEY_BACKSPACE, "BS" },
|
|
|
|
{ KEY_DELETE, "DEL" },
|
|
|
|
{ KEY_INSERT, "INS" },
|
|
|
|
{ KEY_HOME, "HOME" },
|
|
|
|
{ KEY_END, "END" },
|
|
|
|
{ KEY_PAGE_UP, "PGUP" },
|
|
|
|
{ KEY_PAGE_DOWN, "PGDWN" },
|
|
|
|
{ KEY_ESC, "ESC" },
|
|
|
|
{ KEY_RIGHT, "RIGHT" },
|
|
|
|
{ KEY_LEFT, "LEFT" },
|
|
|
|
{ KEY_DOWN, "DOWN" },
|
|
|
|
{ KEY_UP, "UP" },
|
2003-04-09 17:05:39 +00:00
|
|
|
{ KEY_F+1, "F1" },
|
|
|
|
{ KEY_F+2, "F2" },
|
|
|
|
{ KEY_F+3, "F3" },
|
|
|
|
{ KEY_F+4, "F4" },
|
|
|
|
{ KEY_F+5, "F5" },
|
|
|
|
{ KEY_F+6, "F6" },
|
|
|
|
{ KEY_F+7, "F7" },
|
|
|
|
{ KEY_F+8, "F8" },
|
|
|
|
{ KEY_F+9, "F9" },
|
|
|
|
{ KEY_F+10, "F10" },
|
2004-01-16 17:31:38 +00:00
|
|
|
{ KEY_F+11, "F11" },
|
|
|
|
{ KEY_F+12, "F12" },
|
2003-04-09 17:05:39 +00:00
|
|
|
{ KEY_KP0, "KP0" },
|
|
|
|
{ KEY_KP1, "KP1" },
|
|
|
|
{ KEY_KP2, "KP2" },
|
|
|
|
{ KEY_KP3, "KP3" },
|
|
|
|
{ KEY_KP4, "KP4" },
|
|
|
|
{ KEY_KP5, "KP5" },
|
|
|
|
{ KEY_KP6, "KP6" },
|
|
|
|
{ KEY_KP7, "KP7" },
|
|
|
|
{ KEY_KP8, "KP8" },
|
|
|
|
{ KEY_KP9, "KP9" },
|
|
|
|
{ KEY_KPDEL, "KP_DEL" },
|
2003-09-02 17:44:38 +00:00
|
|
|
{ KEY_KPDEC, "KP_DEC" },
|
|
|
|
{ KEY_KPINS, "KP_INS" },
|
2003-04-09 17:05:39 +00:00
|
|
|
{ KEY_KPENTER, "KP_ENTER" },
|
2002-02-08 18:10:56 +00:00
|
|
|
{ MOUSE_BTN0, "MOUSE_BTN0" },
|
|
|
|
{ MOUSE_BTN1, "MOUSE_BTN1" },
|
|
|
|
{ MOUSE_BTN2, "MOUSE_BTN2" },
|
|
|
|
{ MOUSE_BTN3, "MOUSE_BTN3" },
|
|
|
|
{ MOUSE_BTN4, "MOUSE_BTN4" },
|
|
|
|
{ MOUSE_BTN5, "MOUSE_BTN5" },
|
|
|
|
{ MOUSE_BTN6, "MOUSE_BTN6" },
|
|
|
|
{ MOUSE_BTN7, "MOUSE_BTN7" },
|
|
|
|
{ MOUSE_BTN8, "MOUSE_BTN8" },
|
|
|
|
{ MOUSE_BTN9, "MOUSE_BTN9" },
|
2002-02-04 14:19:54 +00:00
|
|
|
{ JOY_AXIS1_MINUS, "JOY_UP" },
|
|
|
|
{ JOY_AXIS1_PLUS, "JOY_DOWN" },
|
|
|
|
{ JOY_AXIS0_MINUS, "JOY_LEFT" },
|
|
|
|
{ JOY_AXIS0_PLUS, "JOY_RIGHT" },
|
2002-02-03 19:13:00 +00:00
|
|
|
|
|
|
|
{ JOY_AXIS0_PLUS, "JOY_AXIS0_PLUS" },
|
|
|
|
{ JOY_AXIS0_MINUS, "JOY_AXIS0_MINUS" },
|
2002-03-20 13:30:57 +00:00
|
|
|
{ JOY_AXIS1_PLUS, "JOY_AXIS1_PLUS" },
|
2002-02-03 19:13:00 +00:00
|
|
|
{ JOY_AXIS1_MINUS, "JOY_AXIS1_MINUS" },
|
|
|
|
{ JOY_AXIS2_PLUS, "JOY_AXIS2_PLUS" },
|
|
|
|
{ JOY_AXIS2_MINUS, "JOY_AXIS2_MINUS" },
|
2002-03-20 13:30:57 +00:00
|
|
|
{ JOY_AXIS3_PLUS, "JOY_AXIS3_PLUS" },
|
2002-02-03 19:13:00 +00:00
|
|
|
{ JOY_AXIS3_MINUS, "JOY_AXIS3_MINUS" },
|
|
|
|
{ JOY_AXIS4_PLUS, "JOY_AXIS4_PLUS" },
|
|
|
|
{ JOY_AXIS4_MINUS, "JOY_AXIS4_MINUS" },
|
2002-03-20 13:30:57 +00:00
|
|
|
{ JOY_AXIS5_PLUS, "JOY_AXIS5_PLUS" },
|
2002-02-03 19:13:00 +00:00
|
|
|
{ JOY_AXIS5_MINUS, "JOY_AXIS5_MINUS" },
|
|
|
|
{ JOY_AXIS6_PLUS, "JOY_AXIS6_PLUS" },
|
|
|
|
{ JOY_AXIS6_MINUS, "JOY_AXIS6_MINUS" },
|
2002-03-20 13:30:57 +00:00
|
|
|
{ JOY_AXIS7_PLUS, "JOY_AXIS7_PLUS" },
|
2002-02-03 19:13:00 +00:00
|
|
|
{ JOY_AXIS7_MINUS, "JOY_AXIS7_MINUS" },
|
|
|
|
{ JOY_AXIS8_PLUS, "JOY_AXIS8_PLUS" },
|
|
|
|
{ JOY_AXIS8_MINUS, "JOY_AXIS8_MINUS" },
|
2002-03-20 13:30:57 +00:00
|
|
|
{ JOY_AXIS9_PLUS, "JOY_AXIS9_PLUS" },
|
2002-02-03 19:13:00 +00:00
|
|
|
{ JOY_AXIS9_MINUS, "JOY_AXIS9_MINUS" },
|
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
{ JOY_BTN0, "JOY_BTN0" },
|
|
|
|
{ JOY_BTN1, "JOY_BTN1" },
|
|
|
|
{ JOY_BTN2, "JOY_BTN2" },
|
|
|
|
{ JOY_BTN3, "JOY_BTN3" },
|
|
|
|
{ JOY_BTN4, "JOY_BTN4" },
|
|
|
|
{ JOY_BTN5, "JOY_BTN5" },
|
|
|
|
{ JOY_BTN6, "JOY_BTN6" },
|
|
|
|
{ JOY_BTN7, "JOY_BTN7" },
|
|
|
|
{ JOY_BTN8, "JOY_BTN8" },
|
|
|
|
{ JOY_BTN9, "JOY_BTN9" },
|
2003-04-04 15:04:26 +00:00
|
|
|
|
|
|
|
{ KEY_XF86_PAUSE, "XF86_PAUSE" },
|
|
|
|
{ KEY_XF86_STOP, "XF86_STOP" },
|
|
|
|
{ KEY_XF86_PREV, "XF86_PREV" },
|
|
|
|
{ KEY_XF86_NEXT, "XF86_NEXT" },
|
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2003-07-09 01:42:19 +00:00
|
|
|
// This is the default binding. The content of input.conf overrides these.
|
|
|
|
// The first arg is a null terminated array of key codes.
|
2002-03-19 13:30:16 +00:00
|
|
|
// The second is the command
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
static mp_cmd_bind_t def_cmd_binds[] = {
|
2002-03-13 10:59:20 +00:00
|
|
|
|
|
|
|
{ { MOUSE_BTN3, 0 }, "seek 10" },
|
|
|
|
{ { MOUSE_BTN4, 0 }, "seek -10" },
|
|
|
|
{ { MOUSE_BTN5, 0 }, "volume 1" },
|
|
|
|
{ { MOUSE_BTN6, 0 }, "volume -1" },
|
|
|
|
|
2002-03-28 20:40:21 +00:00
|
|
|
#ifdef USE_DVDNAV
|
|
|
|
{ { 'K', 0 }, "dvdnav 1" }, // up
|
|
|
|
{ { 'J', 0 }, "dvdnav 2" }, // down
|
|
|
|
{ { 'H', 0 }, "dvdnav 3" }, // left
|
|
|
|
{ { 'L', 0 }, "dvdnav 4" }, // right
|
|
|
|
{ { 'M', 0 }, "dvdnav 5" }, // menu
|
|
|
|
{ { 'S', 0 }, "dvdnav 6" }, // select
|
|
|
|
#endif
|
|
|
|
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { KEY_RIGHT, 0 }, "seek 10" },
|
|
|
|
{ { KEY_LEFT, 0 }, "seek -10" },
|
|
|
|
{ { KEY_UP, 0 }, "seek 60" },
|
|
|
|
{ { KEY_DOWN, 0 }, "seek -60" },
|
|
|
|
{ { KEY_PAGE_UP, 0 }, "seek 600" },
|
|
|
|
{ { KEY_PAGE_DOWN, 0 }, "seek -600" },
|
2002-03-16 16:47:35 +00:00
|
|
|
{ { '-', 0 }, "audio_delay 0.100" },
|
|
|
|
{ { '+', 0 }, "audio_delay -0.100" },
|
2004-10-20 20:07:50 +00:00
|
|
|
{ { '[', 0 }, "speed_mult 0.9091" },
|
|
|
|
{ { ']', 0 }, "speed_mult 1.1" },
|
|
|
|
{ { '{', 0 }, "speed_mult 0.5" },
|
|
|
|
{ { '}', 0 }, "speed_mult 2.0" },
|
|
|
|
{ { KEY_BACKSPACE, 0 }, "speed_set 1.0" },
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { 'q', 0 }, "quit" },
|
|
|
|
{ { KEY_ESC, 0 }, "quit" },
|
2002-03-16 16:36:32 +00:00
|
|
|
#ifndef HAVE_NEW_GUI
|
|
|
|
{ { 'p', 0 }, "pause" },
|
|
|
|
#endif
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { ' ', 0 }, "pause" },
|
2004-10-14 15:33:10 +00:00
|
|
|
{ { '.', 0 }, "frame_step" },
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { KEY_HOME, 0 }, "pt_up_step 1" },
|
|
|
|
{ { KEY_END, 0 }, "pt_up_step -1" },
|
|
|
|
{ { '>', 0 }, "pt_step 1" },
|
2002-03-16 16:36:32 +00:00
|
|
|
#ifndef HAVE_NEW_GUI
|
|
|
|
{ { KEY_ENTER, 0 }, "pt_step 1 1" },
|
|
|
|
#endif
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { '<', 0 }, "pt_step -1" },
|
|
|
|
{ { KEY_INS, 0 }, "alt_src_step 1" },
|
|
|
|
{ { KEY_DEL, 0 }, "alt_src_step -1" },
|
|
|
|
{ { 'o', 0 }, "osd" },
|
|
|
|
{ { 'z', 0 }, "sub_delay -0.1" },
|
|
|
|
{ { 'x', 0 }, "sub_delay +0.1" },
|
2002-12-05 00:15:56 +00:00
|
|
|
{ { 'g', 0 }, "sub_step -1" },
|
|
|
|
{ { 'y', 0 }, "sub_step +1" },
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { '9', 0 }, "volume -1" },
|
|
|
|
{ { '/', 0 }, "volume -1" },
|
|
|
|
{ { '0', 0 }, "volume 1" },
|
|
|
|
{ { '*', 0 }, "volume 1" },
|
2002-06-06 07:13:57 +00:00
|
|
|
{ { 'm', 0 }, "mute" },
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { '1', 0 }, "contrast -1" },
|
|
|
|
{ { '2', 0 }, "contrast 1" },
|
|
|
|
{ { '3', 0 }, "brightness -1" },
|
|
|
|
{ { '4', 0 }, "brightness 1" },
|
|
|
|
{ { '5', 0 }, "hue -1" },
|
|
|
|
{ { '6', 0 }, "hue 1" },
|
|
|
|
{ { '7', 0 }, "saturation -1" },
|
|
|
|
{ { '8', 0 }, "saturation 1" },
|
|
|
|
{ { 'd', 0 }, "frame_drop" },
|
2002-03-10 03:47:53 +00:00
|
|
|
{ { 'r', 0 }, "sub_pos -1" },
|
|
|
|
{ { 't', 0 }, "sub_pos +1" },
|
2003-01-12 18:56:48 +00:00
|
|
|
{ { 'a', 0 }, "sub_alignment" },
|
2002-10-06 17:40:51 +00:00
|
|
|
{ { 'v', 0 }, "sub_visibility" },
|
2004-07-17 12:47:12 +00:00
|
|
|
{ { 'b', 0 }, "sub_select" },
|
2002-10-17 15:41:20 +00:00
|
|
|
{ { 'j', 0 }, "vobsub_lang" },
|
2003-09-21 14:21:43 +00:00
|
|
|
{ { 'F', 0 }, "forced_subs_only" },
|
2005-04-03 14:08:28 +00:00
|
|
|
{ { '#', 0 }, "switch_audio" },
|
2002-12-23 00:33:22 +00:00
|
|
|
#ifdef USE_EDL
|
|
|
|
{ { 'i', 0 }, "edl_mark" },
|
|
|
|
#endif
|
2002-01-30 12:46:03 +00:00
|
|
|
#ifdef USE_TV
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { 'h', 0 }, "tv_step_channel 1" },
|
2002-02-25 13:14:27 +00:00
|
|
|
{ { 'k', 0 }, "tv_step_channel -1" },
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { 'n', 0 }, "tv_step_norm" },
|
2002-06-06 07:13:57 +00:00
|
|
|
{ { 'u', 0 }, "tv_step_chanlist" },
|
2002-02-25 13:14:27 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NEW_GUI
|
|
|
|
{ { 'l', 0 }, "gui_loadfile" },
|
|
|
|
{ { 't', 0 }, "gui_loadsubtitle" },
|
|
|
|
{ { KEY_ENTER, 0 }, "gui_play" },
|
|
|
|
{ { 's', 0 }, "gui_stop" },
|
|
|
|
{ { 'p', 0 }, "gui_playlist" },
|
|
|
|
{ { 'r', 0 }, "gui_preferences" },
|
|
|
|
{ { 'c', 0 }, "gui_skinbrowser" },
|
2002-02-04 14:48:32 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_JOYSTICK
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { JOY_AXIS0_PLUS, 0 }, "seek 10" },
|
|
|
|
{ { JOY_AXIS0_MINUS, 0 }, "seek -10" },
|
|
|
|
{ { JOY_AXIS1_MINUS, 0 }, "seek 60" },
|
|
|
|
{ { JOY_AXIS1_PLUS, 0 }, "seek -60" },
|
|
|
|
{ { JOY_BTN0, 0 }, "pause" },
|
|
|
|
{ { JOY_BTN1, 0 }, "osd" },
|
|
|
|
{ { JOY_BTN2, 0 }, "volume 1"},
|
|
|
|
{ { JOY_BTN3, 0 }, "volume -1"},
|
2002-01-30 12:46:03 +00:00
|
|
|
#endif
|
2003-11-30 16:36:10 +00:00
|
|
|
{ { 'T', 0 }, "vo_ontop" },
|
2002-02-17 01:06:50 +00:00
|
|
|
{ { 'f', 0 }, "vo_fullscreen" },
|
2002-05-18 00:11:43 +00:00
|
|
|
{ { 's', 0 }, "screenshot" },
|
2002-06-04 20:17:07 +00:00
|
|
|
{ { 'w', 0 }, "panscan -0.1" },
|
|
|
|
{ { 'e', 0 }, "panscan +0.1" },
|
2003-04-04 15:04:26 +00:00
|
|
|
|
|
|
|
{ { KEY_XF86_PAUSE, 0 }, "pause" },
|
|
|
|
{ { KEY_XF86_STOP, 0 }, "quit" },
|
|
|
|
{ { KEY_XF86_PREV, 0 }, "seek -60" },
|
|
|
|
{ { KEY_XF86_NEXT, 0 }, "seek +60" },
|
|
|
|
|
2002-02-08 18:10:56 +00:00
|
|
|
{ { 0 }, NULL }
|
2002-01-30 12:46:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef MP_MAX_KEY_FD
|
|
|
|
#define MP_MAX_KEY_FD 10
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MP_MAX_CMD_FD
|
|
|
|
#define MP_MAX_CMD_FD 10
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MP_FD_EOF (1<<0)
|
|
|
|
#define MP_FD_DROP (1<<1)
|
|
|
|
#define MP_FD_DEAD (1<<2)
|
|
|
|
#define MP_FD_GOT_CMD (1<<3)
|
|
|
|
#define MP_FD_NO_SELECT (1<<4)
|
|
|
|
|
2002-04-03 17:58:17 +00:00
|
|
|
#define CMD_QUEUE_SIZE 100
|
2002-02-23 21:13:35 +00:00
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
typedef struct mp_input_fd {
|
|
|
|
int fd;
|
|
|
|
void* read_func;
|
|
|
|
mp_close_func_t close_func;
|
|
|
|
int flags;
|
2003-07-09 01:42:19 +00:00
|
|
|
// These fields are for the cmd fds.
|
2002-01-30 12:46:03 +00:00
|
|
|
char* buffer;
|
|
|
|
int pos,size;
|
|
|
|
} mp_input_fd_t;
|
|
|
|
|
2002-11-14 23:41:44 +00:00
|
|
|
typedef struct mp_cmd_filter_st mp_cmd_filter_t;
|
|
|
|
|
|
|
|
struct mp_cmd_filter_st {
|
|
|
|
mp_input_cmd_filter filter;
|
|
|
|
void* ctx;
|
|
|
|
mp_cmd_filter_t* next;
|
|
|
|
};
|
|
|
|
|
2002-03-19 13:30:16 +00:00
|
|
|
// These are the user defined binds
|
2002-02-24 16:31:27 +00:00
|
|
|
static mp_cmd_bind_t* cmd_binds = NULL;
|
2002-11-14 23:41:44 +00:00
|
|
|
static mp_cmd_filter_t* cmd_filters = NULL;
|
|
|
|
|
|
|
|
// Callback to allow the menu filter to grab the incoming keys
|
|
|
|
void (*mp_input_key_cb)(int code) = NULL;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
static mp_input_fd_t key_fds[MP_MAX_KEY_FD];
|
|
|
|
static unsigned int num_key_fd = 0;
|
|
|
|
static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD];
|
|
|
|
static unsigned int num_cmd_fd = 0;
|
2002-02-23 21:13:35 +00:00
|
|
|
static mp_cmd_t* cmd_queue[CMD_QUEUE_SIZE];
|
|
|
|
static unsigned int cmd_queue_length = 0,cmd_queue_start = 0, cmd_queue_end = 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
2002-02-08 18:10:56 +00:00
|
|
|
// this is the key currently down
|
|
|
|
static int key_down[MP_MAX_KEY_DOWN];
|
2002-02-11 11:42:08 +00:00
|
|
|
static unsigned int num_key_down = 0, last_key_down = 0;
|
|
|
|
|
|
|
|
// Autorepeat stuff
|
|
|
|
static short ar_state = -1;
|
|
|
|
static mp_cmd_t* ar_cmd = NULL;
|
|
|
|
static unsigned int ar_delay = 100, ar_rate = 8, last_ar = 0;
|
|
|
|
|
2003-05-30 18:23:55 +00:00
|
|
|
static int use_joystick = 1, use_lirc = 1, use_lircc = 1;
|
2002-06-24 12:17:23 +00:00
|
|
|
static char* config_file = "input.conf";
|
2002-02-11 11:42:08 +00:00
|
|
|
|
2002-04-20 08:51:09 +00:00
|
|
|
static char* js_dev = NULL;
|
|
|
|
|
2002-10-22 14:32:17 +00:00
|
|
|
static char* in_file = NULL;
|
|
|
|
static int in_file_fd = -1;
|
|
|
|
|
2003-08-13 16:29:32 +00:00
|
|
|
static int mp_input_print_key_list(m_option_t* cfg);
|
|
|
|
static int mp_input_print_cmd_list(m_option_t* cfg);
|
2002-03-20 13:30:57 +00:00
|
|
|
|
2002-03-19 13:30:16 +00:00
|
|
|
// Our command line options
|
2003-08-13 16:29:32 +00:00
|
|
|
static m_option_t input_conf[] = {
|
2002-02-24 13:03:47 +00:00
|
|
|
{ "conf", &config_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL },
|
2002-02-11 11:42:08 +00:00
|
|
|
{ "ar-delay", &ar_delay, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL },
|
|
|
|
{ "ar-rate", &ar_rate, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL },
|
2002-03-20 13:30:57 +00:00
|
|
|
{ "keylist", mp_input_print_key_list, CONF_TYPE_FUNC, CONF_GLOBAL, 0, 0, NULL },
|
|
|
|
{ "cmdlist", mp_input_print_cmd_list, CONF_TYPE_FUNC, CONF_GLOBAL, 0, 0, NULL },
|
2002-04-20 08:51:09 +00:00
|
|
|
{ "js-dev", &js_dev, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL },
|
2002-10-22 14:32:17 +00:00
|
|
|
{ "file", &in_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL },
|
2002-02-11 11:42:08 +00:00
|
|
|
{ NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2003-08-13 16:29:32 +00:00
|
|
|
static m_option_t mp_input_opts[] = {
|
2002-02-11 11:42:08 +00:00
|
|
|
{ "input", &input_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
|
|
|
|
{ "nojoystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL },
|
|
|
|
{ "joystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL },
|
|
|
|
{ "nolirc", &use_lirc, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL },
|
|
|
|
{ "lirc", &use_lirc, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL },
|
2003-05-30 18:23:55 +00:00
|
|
|
{ "nolircc", &use_lircc, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL },
|
|
|
|
{ "lircc", &use_lircc, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL },
|
2002-02-11 11:42:08 +00:00
|
|
|
{ NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
2002-02-08 18:10:56 +00:00
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
static int
|
|
|
|
mp_input_default_key_func(int fd);
|
|
|
|
|
2002-10-25 16:06:25 +00:00
|
|
|
static int
|
|
|
|
mp_input_default_cmd_func(int fd,char* buf, int l);
|
|
|
|
|
2002-02-11 11:42:08 +00:00
|
|
|
static char*
|
|
|
|
mp_input_get_key_name(int key);
|
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func) {
|
|
|
|
if(num_cmd_fd == MP_MAX_CMD_FD) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Too many command fds, unable to register fd %d.\n",fd);
|
2002-01-30 12:46:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t));
|
|
|
|
cmd_fds[num_cmd_fd].fd = fd;
|
2002-10-25 16:06:25 +00:00
|
|
|
cmd_fds[num_cmd_fd].read_func = read_func ? read_func : mp_input_default_cmd_func;
|
2002-01-30 12:46:03 +00:00
|
|
|
cmd_fds[num_cmd_fd].close_func = close_func;
|
|
|
|
if(!select)
|
|
|
|
cmd_fds[num_cmd_fd].flags = MP_FD_NO_SELECT;
|
|
|
|
num_cmd_fd++;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mp_input_rm_cmd_fd(int fd) {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for(i = 0; i < num_cmd_fd; i++) {
|
|
|
|
if(cmd_fds[i].fd == fd)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(i == num_cmd_fd)
|
|
|
|
return;
|
|
|
|
if(cmd_fds[i].close_func)
|
|
|
|
cmd_fds[i].close_func(cmd_fds[i].fd);
|
2002-11-14 23:41:44 +00:00
|
|
|
if(cmd_fds[i].buffer)
|
|
|
|
free(cmd_fds[i].buffer);
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
if(i + 1 < num_cmd_fd)
|
|
|
|
memmove(&cmd_fds[i],&cmd_fds[i+1],(num_cmd_fd - i - 1)*sizeof(mp_input_fd_t));
|
|
|
|
num_cmd_fd--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mp_input_rm_key_fd(int fd) {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for(i = 0; i < num_key_fd; i++) {
|
|
|
|
if(key_fds[i].fd == fd)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(i == num_key_fd)
|
|
|
|
return;
|
|
|
|
if(key_fds[i].close_func)
|
|
|
|
key_fds[i].close_func(key_fds[i].fd);
|
|
|
|
|
|
|
|
if(i + 1 < num_key_fd)
|
|
|
|
memmove(&key_fds[i],&key_fds[i+1],(num_key_fd - i - 1)*sizeof(mp_input_fd_t));
|
|
|
|
num_key_fd--;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func) {
|
|
|
|
if(num_key_fd == MP_MAX_KEY_FD) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Too many key fds, unable to register fd %d.\n",fd);
|
2002-01-30 12:46:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t));
|
|
|
|
key_fds[num_key_fd].fd = fd;
|
|
|
|
key_fds[num_key_fd].read_func = read_func ? read_func : mp_input_default_key_func;
|
|
|
|
key_fds[num_key_fd].close_func = close_func;
|
|
|
|
if(!select)
|
|
|
|
key_fds[num_key_fd].flags |= MP_FD_NO_SELECT;
|
|
|
|
num_key_fd++;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-11-14 23:41:44 +00:00
|
|
|
mp_cmd_t*
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_input_parse_cmd(char* str) {
|
|
|
|
int i,l;
|
2004-11-20 10:51:13 +00:00
|
|
|
int pausing = 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
char *ptr,*e;
|
|
|
|
mp_cmd_t *cmd, *cmd_def;
|
|
|
|
|
|
|
|
#ifdef MP_DEBUG
|
|
|
|
assert(str != NULL);
|
|
|
|
#endif
|
|
|
|
|
2004-11-20 10:51:13 +00:00
|
|
|
if (strncmp(str, "pausing ", 8) == 0) {
|
|
|
|
pausing = 1;
|
|
|
|
str = &str[8];
|
|
|
|
}
|
|
|
|
|
2002-02-24 16:31:27 +00:00
|
|
|
for(ptr = str ; ptr[0] != '\0' && ptr[0] != '\t' && ptr[0] != ' ' ; ptr++)
|
|
|
|
/* NOTHING */;
|
|
|
|
if(ptr[0] != '\0')
|
2002-01-30 12:46:03 +00:00
|
|
|
l = ptr-str;
|
|
|
|
else
|
|
|
|
l = strlen(str);
|
|
|
|
|
|
|
|
if(l == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for(i=0; mp_cmds[i].name != NULL; i++) {
|
|
|
|
if(strncasecmp(mp_cmds[i].name,str,l) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mp_cmds[i].name == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cmd_def = &mp_cmds[i];
|
|
|
|
|
|
|
|
cmd = (mp_cmd_t*)malloc(sizeof(mp_cmd_t));
|
|
|
|
cmd->id = cmd_def->id;
|
|
|
|
cmd->name = strdup(cmd_def->name);
|
2004-11-20 10:51:13 +00:00
|
|
|
cmd->pausing = pausing;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
ptr = str;
|
|
|
|
|
|
|
|
for(i=0; ptr && i < MP_CMD_MAX_ARGS; i++) {
|
|
|
|
ptr = strchr(ptr,' ');
|
|
|
|
if(!ptr) break;
|
2002-02-23 22:43:25 +00:00
|
|
|
while(ptr[0] == ' ' || ptr[0] == '\t') ptr++;
|
2002-07-20 14:26:38 +00:00
|
|
|
if(ptr[0] == '\0') break;
|
|
|
|
cmd->args[i].type = cmd_def->args[i].type;
|
2002-01-30 12:46:03 +00:00
|
|
|
switch(cmd_def->args[i].type) {
|
|
|
|
case MP_CMD_ARG_INT:
|
|
|
|
errno = 0;
|
|
|
|
cmd->args[i].v.i = atoi(ptr);
|
|
|
|
if(errno != 0) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s: argument %d isn't an integer.\n",cmd_def->name,i+1);
|
2002-01-30 12:46:03 +00:00
|
|
|
ptr = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MP_CMD_ARG_FLOAT:
|
|
|
|
errno = 0;
|
|
|
|
cmd->args[i].v.f = atof(ptr);
|
|
|
|
if(errno != 0) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s: argument %d isn't a float.\n",cmd_def->name,i+1);
|
2002-01-30 12:46:03 +00:00
|
|
|
ptr = NULL;
|
|
|
|
}
|
|
|
|
break;
|
2002-11-18 00:11:56 +00:00
|
|
|
case MP_CMD_ARG_STRING: {
|
|
|
|
char term;
|
|
|
|
char* ptr2 = ptr, *start;
|
|
|
|
|
|
|
|
if(ptr[0] == '\'' || ptr[0] == '"') {
|
|
|
|
term = ptr[0];
|
|
|
|
ptr2++;
|
|
|
|
} else
|
|
|
|
term = ' ';
|
|
|
|
start = ptr2;
|
|
|
|
while(1) {
|
|
|
|
e = strchr(ptr2,term);
|
|
|
|
if(!e) break;
|
|
|
|
if(e <= ptr2 || *(e - 1) != '\\') break;
|
|
|
|
ptr2 = e + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(term != ' ' && (!e || e[0] == '\0')) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s: argument %d is unterminated.\n",cmd_def->name,i+1);
|
2002-11-18 00:11:56 +00:00
|
|
|
ptr = NULL;
|
|
|
|
break;
|
|
|
|
} else if(!e) e = ptr+strlen(ptr);
|
|
|
|
l = e-start;
|
|
|
|
ptr2 = start;
|
2005-04-15 14:52:33 +00:00
|
|
|
for(e = strchr(ptr2,'\\') ; e && e<start+l ; e = strchr(ptr2,'\\')) {
|
2002-11-18 00:11:56 +00:00
|
|
|
memmove(e,e+1,strlen(e));
|
|
|
|
ptr2 = e + 1;
|
2003-08-15 18:45:35 +00:00
|
|
|
l--;
|
2002-11-18 00:11:56 +00:00
|
|
|
}
|
2003-08-15 18:45:35 +00:00
|
|
|
cmd->args[i].v.s = (char*)malloc((l+1)*sizeof(char));
|
|
|
|
strncpy(cmd->args[i].v.s,start,l);
|
|
|
|
cmd->args[i].v.s[l] = '\0';
|
2005-02-11 11:44:00 +00:00
|
|
|
if(term != ' ') ptr += l+2;
|
2002-11-18 00:11:56 +00:00
|
|
|
} break;
|
2002-01-30 12:46:03 +00:00
|
|
|
case -1:
|
|
|
|
ptr = NULL;
|
2005-01-03 13:56:48 +00:00
|
|
|
break;
|
2002-01-30 12:46:03 +00:00
|
|
|
default :
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Unknown argument %d\n",i);
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd->nargs = i;
|
|
|
|
|
|
|
|
if(cmd_def->nargs > cmd->nargs) {
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Got command '%s' but\n",str);
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"command %s requires at least %d arguments, we found only %d so far.\n",cmd_def->name,cmd_def->nargs,cmd->nargs);
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_cmd_free(cmd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-02-11 11:42:08 +00:00
|
|
|
for( ; i < MP_CMD_MAX_ARGS && cmd_def->args[i].type != -1 ; i++) {
|
|
|
|
memcpy(&cmd->args[i],&cmd_def->args[i],sizeof(mp_cmd_arg_t));
|
|
|
|
if(cmd_def->args[i].type == MP_CMD_ARG_STRING && cmd_def->args[i].v.s != NULL)
|
|
|
|
cmd->args[i].v.s = strdup(cmd_def->args[i].v.s);
|
|
|
|
}
|
2002-01-30 12:46:03 +00:00
|
|
|
|
2002-03-19 18:27:54 +00:00
|
|
|
if(i < MP_CMD_MAX_ARGS)
|
|
|
|
cmd->args[i].type = -1;
|
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mp_input_default_key_func(int fd) {
|
|
|
|
int r,code=0;
|
|
|
|
unsigned int l;
|
|
|
|
l = 0;
|
|
|
|
while(l < sizeof(int)) {
|
2004-09-15 14:08:46 +00:00
|
|
|
r = read(fd,((char *)&code)+l,sizeof(int)-l);
|
2002-01-30 12:46:03 +00:00
|
|
|
if(r <= 0)
|
|
|
|
break;
|
|
|
|
l +=r;
|
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MP_CMD_MAX_SIZE 256
|
|
|
|
|
|
|
|
static int
|
|
|
|
mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) {
|
|
|
|
char* end;
|
|
|
|
(*ret) = NULL;
|
|
|
|
|
2003-07-09 01:42:19 +00:00
|
|
|
// Allocate the buffer if it doesn't exist
|
2002-01-30 12:46:03 +00:00
|
|
|
if(!mp_fd->buffer) {
|
|
|
|
mp_fd->buffer = (char*)malloc(MP_CMD_MAX_SIZE*sizeof(char));
|
|
|
|
mp_fd->pos = 0;
|
|
|
|
mp_fd->size = MP_CMD_MAX_SIZE;
|
|
|
|
}
|
2002-04-12 10:17:24 +00:00
|
|
|
|
|
|
|
// Get some data if needed/possible
|
|
|
|
while( !(mp_fd->flags & MP_FD_GOT_CMD) && !(mp_fd->flags & MP_FD_EOF) && (mp_fd->size - mp_fd->pos > 1) ) {
|
2002-01-30 12:46:03 +00:00
|
|
|
int r = ((mp_cmd_func_t)mp_fd->read_func)(mp_fd->fd,mp_fd->buffer+mp_fd->pos,mp_fd->size - 1 - mp_fd->pos);
|
2002-04-12 10:17:24 +00:00
|
|
|
// Error ?
|
2002-01-30 12:46:03 +00:00
|
|
|
if(r < 0) {
|
2002-10-25 16:06:25 +00:00
|
|
|
switch(r) {
|
|
|
|
case MP_INPUT_ERROR:
|
|
|
|
case MP_INPUT_DEAD:
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Error while reading cmd fd %d: %s\n",mp_fd->fd,strerror(errno));
|
2002-10-25 16:06:25 +00:00
|
|
|
case MP_INPUT_NOTHING:
|
|
|
|
return r;
|
2005-06-27 08:16:23 +00:00
|
|
|
case MP_INPUT_RETRY:
|
|
|
|
continue;
|
2002-10-25 16:06:25 +00:00
|
|
|
}
|
2002-04-12 10:17:24 +00:00
|
|
|
// EOF ?
|
2002-10-25 16:06:25 +00:00
|
|
|
} else if(r == 0) {
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_fd->flags |= MP_FD_EOF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mp_fd->pos += r;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-04-12 10:17:24 +00:00
|
|
|
// Reset the got_cmd flag
|
|
|
|
mp_fd->flags &= ~MP_FD_GOT_CMD;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int l = 0;
|
2002-04-12 10:17:24 +00:00
|
|
|
// Find the cmd end
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_fd->buffer[mp_fd->pos] = '\0';
|
|
|
|
end = strchr(mp_fd->buffer,'\n');
|
2002-04-12 10:17:24 +00:00
|
|
|
// No cmd end ?
|
|
|
|
if(!end) {
|
|
|
|
// If buffer is full we must drop all until the next \n
|
|
|
|
if(mp_fd->size - mp_fd->pos <= 1) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Cmd buffer of fd %d is full: dropping content\n",mp_fd->fd);
|
2002-04-12 10:17:24 +00:00
|
|
|
mp_fd->pos = 0;
|
|
|
|
mp_fd->flags |= MP_FD_DROP;
|
|
|
|
}
|
2002-01-30 12:46:03 +00:00
|
|
|
break;
|
2002-04-12 10:17:24 +00:00
|
|
|
}
|
2003-07-09 01:42:19 +00:00
|
|
|
// We already have a cmd : set the got_cmd flag
|
2002-01-30 12:46:03 +00:00
|
|
|
else if((*ret)) {
|
|
|
|
mp_fd->flags |= MP_FD_GOT_CMD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = end - mp_fd->buffer;
|
|
|
|
|
2002-04-12 10:17:24 +00:00
|
|
|
// Not dropping : put the cmd in ret
|
2002-01-30 12:46:03 +00:00
|
|
|
if( ! (mp_fd->flags & MP_FD_DROP)) {
|
|
|
|
(*ret) = (char*)malloc((l+1)*sizeof(char));
|
|
|
|
strncpy((*ret),mp_fd->buffer,l);
|
|
|
|
(*ret)[l] = '\0';
|
2002-04-12 10:17:24 +00:00
|
|
|
} else { // Remove the dropping flag
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_fd->flags &= ~MP_FD_DROP;
|
|
|
|
}
|
|
|
|
if( mp_fd->pos - (l+1) > 0)
|
2002-04-12 10:17:24 +00:00
|
|
|
memmove(mp_fd->buffer,end+1,mp_fd->pos-(l+1));
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_fd->pos -= l+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ret)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return MP_INPUT_NOTHING;
|
|
|
|
}
|
|
|
|
|
2002-10-25 16:06:25 +00:00
|
|
|
static int
|
|
|
|
mp_input_default_cmd_func(int fd,char* buf, int l) {
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int r = read(fd,buf,l);
|
|
|
|
// Error ?
|
|
|
|
if(r < 0) {
|
|
|
|
if(errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else if(errno == EAGAIN)
|
|
|
|
return MP_INPUT_NOTHING;
|
|
|
|
return MP_INPUT_ERROR;
|
|
|
|
// EOF ?
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-11-14 23:41:44 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
mp_input_add_cmd_filter(mp_input_cmd_filter func, void* ctx) {
|
2002-11-23 10:58:14 +00:00
|
|
|
mp_cmd_filter_t* filter = malloc(sizeof(mp_cmd_filter_t))/*, *prev*/;
|
2002-11-14 23:41:44 +00:00
|
|
|
|
|
|
|
filter->filter = func;
|
|
|
|
filter->ctx = ctx;
|
|
|
|
filter->next = cmd_filters;
|
|
|
|
cmd_filters = filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-24 16:31:27 +00:00
|
|
|
static char*
|
|
|
|
mp_input_find_bind_for_key(mp_cmd_bind_t* binds, int n,int* keys) {
|
2002-02-11 11:42:08 +00:00
|
|
|
int j;
|
2002-02-24 16:31:27 +00:00
|
|
|
|
|
|
|
for(j = 0; binds[j].cmd != NULL; j++) {
|
2002-02-11 11:42:08 +00:00
|
|
|
if(n > 0) {
|
|
|
|
int found = 1,s;
|
2002-02-24 16:31:27 +00:00
|
|
|
for(s = 0; s < n && binds[j].input[s] != 0; s++) {
|
|
|
|
if(binds[j].input[s] != keys[s]) {
|
2002-02-11 11:42:08 +00:00
|
|
|
found = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-02-24 16:31:27 +00:00
|
|
|
if(found && binds[j].input[s] == 0 && s == n)
|
2002-02-11 11:42:08 +00:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
} else if(n == 1){
|
2002-02-24 16:31:27 +00:00
|
|
|
if(binds[j].input[0] == keys[0] && binds[j].input[1] == 0)
|
2002-02-11 11:42:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-02-24 16:31:27 +00:00
|
|
|
return binds[j].cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static mp_cmd_t*
|
|
|
|
mp_input_get_cmd_from_keys(int n,int* keys, int paused) {
|
|
|
|
char* cmd = NULL;
|
2002-02-24 21:22:12 +00:00
|
|
|
mp_cmd_t* ret;
|
2002-02-24 16:31:27 +00:00
|
|
|
|
|
|
|
if(cmd_binds)
|
|
|
|
cmd = mp_input_find_bind_for_key(cmd_binds,n,keys);
|
|
|
|
if(cmd == NULL)
|
|
|
|
cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys);
|
|
|
|
|
|
|
|
if(cmd == NULL) {
|
2002-05-25 09:46:37 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_WARN,"No bind found for key %s",mp_input_get_key_name(keys[0]));
|
2002-02-11 11:42:08 +00:00
|
|
|
if(n > 1) {
|
|
|
|
int s;
|
|
|
|
for(s=1; s < n; s++)
|
2002-05-25 09:46:37 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_WARN,"-%s",mp_input_get_key_name(keys[s]));
|
2002-02-11 11:42:08 +00:00
|
|
|
}
|
2002-05-25 09:46:37 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_WARN," \n");
|
2002-02-11 11:42:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-02-24 21:22:12 +00:00
|
|
|
ret = mp_input_parse_cmd(cmd);
|
|
|
|
if(!ret) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Invalid command for bound key %s",mp_input_get_key_name(key_down[0]));
|
2002-02-24 21:22:12 +00:00
|
|
|
if( num_key_down > 1) {
|
|
|
|
unsigned int s;
|
|
|
|
for(s=1; s < num_key_down; s++)
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"-%s",mp_input_get_key_name(key_down[s]));
|
2002-02-24 21:22:12 +00:00
|
|
|
}
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR," : %s \n",cmd);
|
2002-02-24 21:22:12 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2002-02-11 11:42:08 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 23:41:44 +00:00
|
|
|
int
|
|
|
|
mp_input_read_key_code(int time) {
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-01-30 12:46:03 +00:00
|
|
|
fd_set fds;
|
2002-02-11 11:42:08 +00:00
|
|
|
struct timeval tv,*time_val;
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-02-11 11:42:08 +00:00
|
|
|
int i,n=0,max_fd = 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
static int last_loop = 0;
|
|
|
|
|
|
|
|
if(num_key_fd == 0)
|
2002-11-14 23:41:44 +00:00
|
|
|
return MP_INPUT_NOTHING;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-01-30 12:46:03 +00:00
|
|
|
FD_ZERO(&fds);
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-02-11 11:42:08 +00:00
|
|
|
// Remove fd marked as dead and build the fd_set
|
2003-03-29 21:52:08 +00:00
|
|
|
// n == number of fd's to be select() checked
|
2002-01-30 12:46:03 +00:00
|
|
|
for(i = 0; (unsigned int)i < num_key_fd; i++) {
|
|
|
|
if( (key_fds[i].flags & MP_FD_DEAD) ) {
|
|
|
|
mp_input_rm_key_fd(key_fds[i].fd);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
} else if(key_fds[i].flags & MP_FD_NO_SELECT)
|
|
|
|
continue;
|
2002-02-11 11:42:08 +00:00
|
|
|
if(key_fds[i].fd > max_fd)
|
|
|
|
max_fd = key_fds[i].fd;
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-01-30 12:46:03 +00:00
|
|
|
FD_SET(key_fds[i].fd,&fds);
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-01-30 12:46:03 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2003-03-29 21:52:08 +00:00
|
|
|
if(num_key_fd == 0)
|
2002-11-14 23:41:44 +00:00
|
|
|
return MP_INPUT_NOTHING;
|
2002-02-20 14:45:18 +00:00
|
|
|
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2003-03-29 21:52:08 +00:00
|
|
|
// if we have fd's without MP_FD_NO_SELECT flag, call select():
|
|
|
|
if(n>0){
|
|
|
|
|
2002-02-11 11:42:08 +00:00
|
|
|
if(time >= 0 ) {
|
2002-01-30 12:46:03 +00:00
|
|
|
tv.tv_sec=time/1000;
|
|
|
|
tv.tv_usec = (time%1000)*1000;
|
2002-02-11 11:42:08 +00:00
|
|
|
time_val = &tv;
|
|
|
|
} else
|
|
|
|
time_val = NULL;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
2003-03-29 21:52:08 +00:00
|
|
|
while(1) {
|
2002-02-11 11:42:08 +00:00
|
|
|
if(select(max_fd+1,&fds,NULL,NULL,time_val) < 0) {
|
|
|
|
if(errno == EINTR)
|
|
|
|
continue;
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Select error: %s\n",strerror(errno));
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
2002-02-11 11:42:08 +00:00
|
|
|
break;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
2003-03-29 21:52:08 +00:00
|
|
|
|
|
|
|
}
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2003-03-29 21:52:08 +00:00
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
for(i = last_loop + 1 ; i != last_loop ; i++) {
|
2002-02-08 18:10:56 +00:00
|
|
|
int code = -1;
|
2003-07-09 01:42:19 +00:00
|
|
|
// This is to check all fds in turn
|
2002-01-30 12:46:03 +00:00
|
|
|
if((unsigned int)i >= num_key_fd) {
|
|
|
|
i = -1;
|
|
|
|
last_loop++;
|
2002-02-28 13:49:04 +00:00
|
|
|
last_loop %= (num_key_fd+1);
|
2002-01-30 12:46:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-02-11 11:42:08 +00:00
|
|
|
// No input from this fd
|
2004-09-15 14:08:46 +00:00
|
|
|
if(! (key_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(key_fds[i].fd,&fds) && key_fds[i].fd != 0)
|
2002-01-30 12:46:03 +00:00
|
|
|
continue;
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-01-30 12:46:03 +00:00
|
|
|
if(key_fds[i].fd == 0) { // stdin is handled by getch2
|
|
|
|
code = getch2(time);
|
|
|
|
if(code < 0)
|
|
|
|
code = MP_INPUT_NOTHING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd);
|
2002-11-14 23:41:44 +00:00
|
|
|
|
|
|
|
if(code >= 0)
|
|
|
|
return code;
|
|
|
|
|
|
|
|
if(code == MP_INPUT_ERROR)
|
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Error on key input fd %d\n",key_fds[i].fd);
|
|
|
|
else if(code == MP_INPUT_DEAD) {
|
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Dead key input on fd %d\n",key_fds[i].fd);
|
|
|
|
key_fds[i].flags |= MP_FD_DEAD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MP_INPUT_NOTHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static mp_cmd_t*
|
|
|
|
mp_input_read_keys(int time,int paused) {
|
|
|
|
int code = mp_input_read_key_code(time);
|
|
|
|
unsigned int j;
|
|
|
|
mp_cmd_t* ret;
|
|
|
|
|
|
|
|
if(mp_input_key_cb) {
|
|
|
|
for( ; code >= 0 ; code = mp_input_read_key_code(0) ) {
|
|
|
|
if(code & MP_KEY_DOWN) continue;
|
|
|
|
code &= ~(MP_KEY_DOWN|MP_NO_REPEAT_KEY);
|
|
|
|
mp_input_key_cb(code);
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
2002-11-14 23:41:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ; code >= 0 ; code = mp_input_read_key_code(0) ) {
|
2002-02-11 11:42:08 +00:00
|
|
|
// key pushed
|
|
|
|
if(code & MP_KEY_DOWN) {
|
2002-02-08 18:10:56 +00:00
|
|
|
if(num_key_down > MP_MAX_KEY_DOWN) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Too many key down events at the same time\n");
|
2002-02-08 18:10:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
code &= ~MP_KEY_DOWN;
|
2002-03-12 12:04:40 +00:00
|
|
|
// Check if we don't already have this key as pushed
|
2002-02-11 11:42:08 +00:00
|
|
|
for(j = 0; j < num_key_down; j++) {
|
|
|
|
if(key_down[j] == code)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(j != num_key_down)
|
|
|
|
continue;
|
2002-02-08 18:10:56 +00:00
|
|
|
key_down[num_key_down] = code;
|
|
|
|
num_key_down++;
|
2002-02-11 11:42:08 +00:00
|
|
|
last_key_down = GetTimer();
|
|
|
|
ar_state = 0;
|
2002-02-08 18:10:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-02-11 11:42:08 +00:00
|
|
|
// key released
|
2002-03-12 12:04:40 +00:00
|
|
|
// Check if the key is in the down key, driver which can't send push event
|
2002-02-11 11:42:08 +00:00
|
|
|
// send only release event
|
|
|
|
for(j = 0; j < num_key_down; j++) {
|
|
|
|
if(key_down[j] == code)
|
|
|
|
break;
|
2002-02-08 18:10:56 +00:00
|
|
|
}
|
2002-02-11 11:42:08 +00:00
|
|
|
if(j == num_key_down) { // key was not in the down keys : add it
|
|
|
|
if(num_key_down > MP_MAX_KEY_DOWN) {
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Too many key down events at the same time\n");
|
2002-02-08 18:10:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-02-11 11:42:08 +00:00
|
|
|
key_down[num_key_down] = code;
|
|
|
|
num_key_down++;
|
|
|
|
last_key_down = 1;
|
|
|
|
}
|
|
|
|
// We ignore key from last combination
|
|
|
|
ret = last_key_down ? mp_input_get_cmd_from_keys(num_key_down,key_down,paused) : NULL;
|
|
|
|
// Remove the key
|
|
|
|
if(j+1 < num_key_down)
|
|
|
|
memmove(&key_down[j],&key_down[j+1],(num_key_down-(j+1))*sizeof(int));
|
|
|
|
num_key_down--;
|
|
|
|
last_key_down = 0;
|
|
|
|
ar_state = -1;
|
|
|
|
if(ar_cmd) {
|
|
|
|
mp_cmd_free(ar_cmd);
|
|
|
|
ar_cmd = NULL;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
2002-02-11 11:42:08 +00:00
|
|
|
if(ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No input : autorepeat ?
|
|
|
|
if(ar_rate > 0 && ar_state >=0 && num_key_down > 0 && ! (key_down[num_key_down-1] & MP_NO_REPEAT_KEY)) {
|
|
|
|
unsigned int t = GetTimer();
|
|
|
|
// First time : wait delay
|
|
|
|
if(ar_state == 0 && (t - last_key_down) >= ar_delay*1000) {
|
|
|
|
ar_cmd = mp_input_get_cmd_from_keys(num_key_down,key_down,paused);
|
2002-03-19 13:30:16 +00:00
|
|
|
if(!ar_cmd) {
|
2002-02-11 11:42:08 +00:00
|
|
|
ar_state = -1;
|
2002-03-19 13:30:16 +00:00
|
|
|
return NULL;
|
2002-02-08 18:10:56 +00:00
|
|
|
}
|
2002-03-19 13:30:16 +00:00
|
|
|
ar_state = 1;
|
|
|
|
last_ar = t;
|
2002-02-11 11:42:08 +00:00
|
|
|
return mp_cmd_clone(ar_cmd);
|
|
|
|
// Then send rate / sec event
|
|
|
|
} else if(ar_state == 1 && (t -last_ar) >= 1000000/ar_rate) {
|
|
|
|
last_ar = t;
|
|
|
|
return mp_cmd_clone(ar_cmd);
|
2002-02-03 19:13:00 +00:00
|
|
|
}
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static mp_cmd_t*
|
|
|
|
mp_input_read_cmds(int time) {
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-01-30 12:46:03 +00:00
|
|
|
fd_set fds;
|
2002-02-11 11:42:08 +00:00
|
|
|
struct timeval tv,*time_val;
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-04-12 10:17:24 +00:00
|
|
|
int i,n = 0,max_fd = 0,got_cmd = 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_cmd_t* ret;
|
|
|
|
static int last_loop = 0;
|
|
|
|
|
|
|
|
if(num_cmd_fd == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-01-30 12:46:03 +00:00
|
|
|
FD_ZERO(&fds);
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-01-30 12:46:03 +00:00
|
|
|
for(i = 0; (unsigned int)i < num_cmd_fd ; i++) {
|
|
|
|
if( (cmd_fds[i].flags & MP_FD_DEAD) || (cmd_fds[i].flags & MP_FD_EOF) ) {
|
|
|
|
mp_input_rm_cmd_fd(cmd_fds[i].fd);
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
} else if(cmd_fds[i].flags & MP_FD_NO_SELECT)
|
2002-02-11 11:42:08 +00:00
|
|
|
continue;
|
2002-04-12 10:17:24 +00:00
|
|
|
if(cmd_fds[i].flags & MP_FD_GOT_CMD)
|
|
|
|
got_cmd = 1;
|
2002-02-11 11:42:08 +00:00
|
|
|
if(cmd_fds[i].fd > max_fd)
|
|
|
|
max_fd = cmd_fds[i].fd;
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-01-30 12:46:03 +00:00
|
|
|
FD_SET(cmd_fds[i].fd,&fds);
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-01-30 12:46:03 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2002-02-20 14:45:18 +00:00
|
|
|
if(num_cmd_fd == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-02-11 11:42:08 +00:00
|
|
|
if(time >= 0) {
|
2002-01-30 12:46:03 +00:00
|
|
|
tv.tv_sec=time/1000;
|
|
|
|
tv.tv_usec = (time%1000)*1000;
|
2002-02-11 11:42:08 +00:00
|
|
|
time_val = &tv;
|
|
|
|
} else
|
|
|
|
time_val = NULL;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
2002-02-11 11:42:08 +00:00
|
|
|
while(n > 0) {
|
|
|
|
if((i = select(max_fd+1,&fds,NULL,NULL,time_val)) <= 0) {
|
|
|
|
if(i < 0) {
|
|
|
|
if(errno == EINTR)
|
|
|
|
continue;
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Select error: %s\n",strerror(errno));
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
2002-04-12 10:17:24 +00:00
|
|
|
if(!got_cmd)
|
|
|
|
return NULL;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
2002-02-11 11:42:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
for(i = last_loop + 1; i != last_loop ; i++) {
|
|
|
|
int r = 0;
|
|
|
|
char* cmd;
|
|
|
|
if((unsigned int)i >= num_cmd_fd) {
|
|
|
|
i = -1;
|
|
|
|
last_loop++;
|
2002-02-28 13:49:04 +00:00
|
|
|
last_loop %= (num_cmd_fd+1);
|
2002-01-30 12:46:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-04-04 20:56:29 +00:00
|
|
|
#ifndef HAVE_NO_POSIX_SELECT
|
2002-01-30 12:46:03 +00:00
|
|
|
if( ! (cmd_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(cmd_fds[i].fd,&fds) && ! (cmd_fds[i].flags & MP_FD_GOT_CMD) )
|
|
|
|
continue;
|
2003-04-04 20:56:29 +00:00
|
|
|
#endif
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
r = mp_input_read_cmd(&cmd_fds[i],&cmd);
|
|
|
|
if(r < 0) {
|
|
|
|
if(r == MP_INPUT_ERROR)
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Error on cmd fd %d\n",cmd_fds[i].fd);
|
2002-01-30 12:46:03 +00:00
|
|
|
else if(r == MP_INPUT_DEAD)
|
|
|
|
cmd_fds[i].flags |= MP_FD_DEAD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ret = mp_input_parse_cmd(cmd);
|
|
|
|
free(cmd);
|
|
|
|
if(!ret)
|
|
|
|
continue;
|
|
|
|
last_loop = i;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_loop = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-02-23 21:13:35 +00:00
|
|
|
int
|
|
|
|
mp_input_queue_cmd(mp_cmd_t* cmd) {
|
|
|
|
if(cmd_queue_length >= CMD_QUEUE_SIZE)
|
|
|
|
return 0;
|
|
|
|
cmd_queue[cmd_queue_end] = cmd;
|
|
|
|
cmd_queue_end = (cmd_queue_end + 1) % CMD_QUEUE_SIZE;
|
|
|
|
cmd_queue_length++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static mp_cmd_t*
|
2004-10-10 17:39:07 +00:00
|
|
|
mp_input_get_queued_cmd(int peek_only) {
|
2002-02-23 21:13:35 +00:00
|
|
|
mp_cmd_t* ret;
|
|
|
|
|
|
|
|
if(cmd_queue_length == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = cmd_queue[cmd_queue_start];
|
|
|
|
|
2004-10-10 17:39:07 +00:00
|
|
|
if (!peek_only) {
|
2002-02-23 21:13:35 +00:00
|
|
|
cmd_queue_length--;
|
|
|
|
cmd_queue_start = (cmd_queue_start + 1) % CMD_QUEUE_SIZE;
|
2004-10-10 17:39:07 +00:00
|
|
|
}
|
2002-02-23 21:13:35 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-10-10 17:39:07 +00:00
|
|
|
/**
|
|
|
|
* \param peek_only when set, the returned command stays in the queue.
|
|
|
|
* Do not free the returned cmd whe you set this!
|
|
|
|
*/
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_cmd_t*
|
2004-10-10 17:39:07 +00:00
|
|
|
mp_input_get_cmd(int time, int paused, int peek_only) {
|
2002-11-14 23:41:44 +00:00
|
|
|
mp_cmd_t* ret = NULL;
|
|
|
|
mp_cmd_filter_t* cf;
|
2004-10-10 17:39:07 +00:00
|
|
|
int from_queue;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
2002-11-14 23:41:44 +00:00
|
|
|
while(1) {
|
2004-10-10 17:39:07 +00:00
|
|
|
from_queue = 1;
|
|
|
|
ret = mp_input_get_queued_cmd(peek_only);
|
2002-11-14 23:41:44 +00:00
|
|
|
if(ret) break;
|
2004-10-10 17:39:07 +00:00
|
|
|
from_queue = 0;
|
2002-11-14 23:41:44 +00:00
|
|
|
ret = mp_input_read_keys(time,paused);
|
|
|
|
if(ret) break;
|
|
|
|
ret = mp_input_read_cmds(time);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!ret) return NULL;
|
2002-02-23 21:13:35 +00:00
|
|
|
|
2002-11-14 23:41:44 +00:00
|
|
|
for(cf = cmd_filters ; cf ; cf = cf->next) {
|
|
|
|
if(cf->filter(ret,paused,cf->ctx))
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-01-30 12:46:03 +00:00
|
|
|
|
2004-10-10 17:39:07 +00:00
|
|
|
if (!from_queue && peek_only)
|
|
|
|
mp_input_queue_cmd(ret);
|
|
|
|
|
2002-11-14 23:41:44 +00:00
|
|
|
return ret;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mp_cmd_free(mp_cmd_t* cmd) {
|
|
|
|
int i;
|
2002-03-11 09:19:15 +00:00
|
|
|
//#ifdef MP_DEBUG
|
|
|
|
// assert(cmd != NULL);
|
|
|
|
//#endif
|
|
|
|
if ( !cmd ) return;
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
if(cmd->name)
|
|
|
|
free(cmd->name);
|
|
|
|
|
|
|
|
for(i=0; i < MP_CMD_MAX_ARGS && cmd->args[i].type != -1; i++) {
|
2002-02-11 11:42:08 +00:00
|
|
|
if(cmd->args[i].type == MP_CMD_ARG_STRING && cmd->args[i].v.s != NULL)
|
2002-01-30 12:46:03 +00:00
|
|
|
free(cmd->args[i].v.s);
|
|
|
|
}
|
|
|
|
free(cmd);
|
|
|
|
}
|
|
|
|
|
2002-02-11 11:42:08 +00:00
|
|
|
mp_cmd_t*
|
|
|
|
mp_cmd_clone(mp_cmd_t* cmd) {
|
|
|
|
mp_cmd_t* ret;
|
|
|
|
int i;
|
|
|
|
#ifdef MP_DEBUG
|
|
|
|
assert(cmd != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ret = (mp_cmd_t*)malloc(sizeof(mp_cmd_t));
|
|
|
|
memcpy(ret,cmd,sizeof(mp_cmd_t));
|
|
|
|
if(cmd->name)
|
|
|
|
ret->name = strdup(cmd->name);
|
|
|
|
for(i = 0; i < MP_CMD_MAX_ARGS && cmd->args[i].type != -1; i++) {
|
|
|
|
if(cmd->args[i].type == MP_CMD_ARG_STRING && cmd->args[i].v.s != NULL)
|
|
|
|
ret->args[i].v.s = strdup(cmd->args[i].v.s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-06-12 10:39:04 +00:00
|
|
|
static char key_str[12];
|
2002-02-11 11:42:08 +00:00
|
|
|
|
|
|
|
static char*
|
|
|
|
mp_input_get_key_name(int key) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; key_names[i].name != NULL; i++) {
|
|
|
|
if(key_names[i].key == key)
|
|
|
|
return key_names[i].name;
|
|
|
|
}
|
|
|
|
|
2002-06-12 10:39:04 +00:00
|
|
|
if(isascii(key)) {
|
|
|
|
snprintf(key_str,12,"%c",(char)key);
|
2002-02-23 21:13:35 +00:00
|
|
|
return key_str;
|
|
|
|
}
|
|
|
|
|
2002-06-12 10:39:04 +00:00
|
|
|
// Print the hex key code
|
|
|
|
snprintf(key_str,12,"%#-8x",key);
|
|
|
|
return key_str;
|
|
|
|
|
2002-02-11 11:42:08 +00:00
|
|
|
}
|
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
static int
|
|
|
|
mp_input_get_key_from_name(char* name) {
|
2002-06-12 10:39:04 +00:00
|
|
|
int i,ret = 0,len = strlen(name);
|
|
|
|
if(len == 1) { // Direct key code
|
|
|
|
ret = (unsigned char)name[0];
|
2002-01-30 12:46:03 +00:00
|
|
|
return ret;
|
2002-06-12 10:39:04 +00:00
|
|
|
} else if(len > 2 && strncasecmp("0x",name,2) == 0)
|
|
|
|
return strtol(name,NULL,16);
|
2002-01-30 12:46:03 +00:00
|
|
|
|
2002-02-08 18:10:56 +00:00
|
|
|
for(i = 0; key_names[i].name != NULL; i++) {
|
|
|
|
if(strcasecmp(key_names[i].name,name) == 0)
|
|
|
|
return key_names[i].key;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-02-08 18:10:56 +00:00
|
|
|
static int
|
|
|
|
mp_input_get_input_from_name(char* name,int* keys) {
|
|
|
|
char *end,*ptr;
|
|
|
|
int n=0;
|
|
|
|
|
|
|
|
ptr = name;
|
|
|
|
n = 0;
|
|
|
|
for(end = strchr(ptr,'-') ; ptr != NULL ; end = strchr(ptr,'-')) {
|
|
|
|
if(end && end[1] != '\0') {
|
|
|
|
if(end[1] == '-')
|
|
|
|
end = &end[1];
|
|
|
|
end[0] = '\0';
|
|
|
|
}
|
|
|
|
keys[n] = mp_input_get_key_from_name(ptr);
|
|
|
|
if(keys[n] < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
if(end && end[1] != '\0' && n < MP_MAX_KEY_DOWN)
|
|
|
|
ptr = &end[1];
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
keys[n] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-02-24 16:31:27 +00:00
|
|
|
void
|
|
|
|
mp_input_bind_keys(int keys[MP_MAX_KEY_DOWN+1], char* cmd) {
|
|
|
|
int i = 0,j;
|
|
|
|
mp_cmd_bind_t* bind = NULL;
|
|
|
|
|
|
|
|
#ifdef MP_DEBUG
|
|
|
|
assert(keys != NULL);
|
|
|
|
assert(cmd != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(cmd_binds) {
|
|
|
|
for(i = 0; cmd_binds[i].cmd != NULL ; i++) {
|
|
|
|
for(j = 0 ; cmd_binds[i].input[j] == keys[j] && keys[j] != 0 ; j++)
|
|
|
|
/* NOTHING */;
|
|
|
|
if(keys[j] == 0 && cmd_binds[i].input[j] == 0 ) {
|
|
|
|
bind = &cmd_binds[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!bind) {
|
|
|
|
cmd_binds = (mp_cmd_bind_t*)realloc(cmd_binds,(i+2)*sizeof(mp_cmd_bind_t));
|
|
|
|
memset(&cmd_binds[i],0,2*sizeof(mp_cmd_bind_t));
|
|
|
|
bind = &cmd_binds[i];
|
|
|
|
}
|
|
|
|
if(bind->cmd)
|
|
|
|
free(bind->cmd);
|
|
|
|
bind->cmd = strdup(cmd);
|
2002-02-24 21:22:12 +00:00
|
|
|
memcpy(bind->input,keys,(MP_MAX_KEY_DOWN+1)*sizeof(int));
|
2002-02-24 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
static void
|
|
|
|
mp_input_free_binds(mp_cmd_bind_t* binds) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!binds)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(i = 0; binds[i].cmd != NULL; i++)
|
|
|
|
free(binds[i].cmd);
|
|
|
|
|
|
|
|
free(binds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define BS_MAX 256
|
|
|
|
#define SPACE_CHAR " \n\r\t"
|
|
|
|
|
2002-02-04 14:48:32 +00:00
|
|
|
static int
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_input_parse_config(char *file) {
|
2002-02-08 18:10:56 +00:00
|
|
|
int fd;
|
2002-02-20 14:45:18 +00:00
|
|
|
int bs = 0,r,eof = 0,comments = 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
char *iter,*end;
|
|
|
|
char buffer[BS_MAX];
|
2002-02-08 18:10:56 +00:00
|
|
|
int n_binds = 0, keys[MP_MAX_KEY_DOWN+1] = { 0 };
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_cmd_bind_t* binds = NULL;
|
|
|
|
|
|
|
|
fd = open(file,O_RDONLY);
|
|
|
|
|
|
|
|
if(fd < 0) {
|
2004-11-15 09:09:29 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_V,"Can't open input config file %s: %s\n",file,strerror(errno));
|
2002-02-04 14:48:32 +00:00
|
|
|
return 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_V,"Parsing input config file %s\n",file);
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if(! eof && bs < BS_MAX-1) {
|
|
|
|
if(bs > 0) bs--;
|
|
|
|
r = read(fd,buffer+bs,BS_MAX-1-bs);
|
|
|
|
if(r < 0) {
|
|
|
|
if(errno == EINTR)
|
|
|
|
continue;
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Error while reading input config file %s: %s\n",file,strerror(errno));
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_input_free_binds(binds);
|
2002-06-19 16:41:38 +00:00
|
|
|
close(fd);
|
2002-02-04 14:48:32 +00:00
|
|
|
return 0;
|
2002-11-25 13:28:40 +00:00
|
|
|
} else if(r == 0) {
|
2002-01-30 12:46:03 +00:00
|
|
|
eof = 1;
|
2002-11-25 13:28:40 +00:00
|
|
|
} else {
|
2002-01-30 12:46:03 +00:00
|
|
|
bs += r+1;
|
|
|
|
buffer[bs-1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Empty buffer : return
|
2002-11-25 14:17:15 +00:00
|
|
|
if(bs <= 1) {
|
2004-11-15 09:09:29 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_V,"Input config file %s parsed: %d binds\n",file,n_binds);
|
2002-01-30 12:46:03 +00:00
|
|
|
if(binds)
|
|
|
|
cmd_binds = binds;
|
2002-06-19 16:41:38 +00:00
|
|
|
close(fd);
|
2002-02-04 14:48:32 +00:00
|
|
|
return 1;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
2002-02-23 22:43:25 +00:00
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
iter = buffer;
|
|
|
|
|
2002-02-20 14:45:18 +00:00
|
|
|
if(comments) {
|
|
|
|
for( ; iter[0] != '\0' && iter[0] != '\n' ; iter++)
|
|
|
|
/* NOTHING */;
|
|
|
|
if(iter[0] == '\0') { // Buffer was full of comment
|
|
|
|
bs = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
r = strlen(iter);
|
|
|
|
if(r)
|
|
|
|
memmove(buffer,iter,r+1);
|
|
|
|
bs = r+1;
|
|
|
|
if(iter[0] != '#')
|
|
|
|
comments = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
// Find the wanted key
|
2002-02-08 18:10:56 +00:00
|
|
|
if(keys[0] == 0) {
|
2002-03-12 12:04:40 +00:00
|
|
|
// Jump beginning space
|
2002-01-30 12:46:03 +00:00
|
|
|
for( ; iter[0] != '\0' && strchr(SPACE_CHAR,iter[0]) != NULL ; iter++)
|
|
|
|
/* NOTHING */;
|
|
|
|
if(iter[0] == '\0') { // Buffer was full of space char
|
|
|
|
bs = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2002-02-20 14:45:18 +00:00
|
|
|
if(iter[0] == '#') { // Comments
|
|
|
|
comments = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2002-01-30 12:46:03 +00:00
|
|
|
// Find the end of the key code name
|
|
|
|
for(end = iter; end[0] != '\0' && strchr(SPACE_CHAR,end[0]) == NULL ; end++)
|
|
|
|
/*NOTHING */;
|
2003-07-09 01:42:19 +00:00
|
|
|
if(end[0] == '\0') { // Key name doesn't fit in the buffer
|
2002-01-30 12:46:03 +00:00
|
|
|
if(buffer == iter) {
|
|
|
|
if(eof && (buffer-iter) == bs)
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Unfinished binding %s\n",iter);
|
2002-01-30 12:46:03 +00:00
|
|
|
else
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Buffer is too small for this key name: %s\n",iter);
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_input_free_binds(binds);
|
2002-02-04 14:48:32 +00:00
|
|
|
return 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
memmove(buffer,iter,end-iter);
|
|
|
|
bs = end-iter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
char name[end-iter+1];
|
|
|
|
strncpy(name,iter,end-iter);
|
|
|
|
name[end-iter] = '\0';
|
2002-02-08 18:10:56 +00:00
|
|
|
if(! mp_input_get_input_from_name(name,keys)) {
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Unknown key '%s'\n",name);
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_input_free_binds(binds);
|
2002-06-19 16:41:38 +00:00
|
|
|
close(fd);
|
2002-02-04 14:48:32 +00:00
|
|
|
return 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if( bs > (end-buffer))
|
|
|
|
memmove(buffer,end,bs - (end-buffer));
|
|
|
|
bs -= end-buffer;
|
|
|
|
continue;
|
|
|
|
} else { // Get the command
|
|
|
|
while(iter[0] == ' ' || iter[0] == '\t') iter++;
|
|
|
|
// Found new line
|
|
|
|
if(iter[0] == '\n' || iter[0] == '\r') {
|
2002-02-11 11:42:08 +00:00
|
|
|
int i;
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"No command found for key %s" ,mp_input_get_key_name(keys[0]));
|
2002-02-11 11:42:08 +00:00
|
|
|
for(i = 1; keys[i] != 0 ; i++)
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"-%s",mp_input_get_key_name(keys[i]));
|
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"\n");
|
2002-02-08 18:10:56 +00:00
|
|
|
keys[0] = 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
if(iter > buffer) {
|
|
|
|
memmove(buffer,iter,bs- (iter-buffer));
|
|
|
|
bs -= (iter-buffer);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++)
|
|
|
|
/* NOTHING */;
|
2002-02-23 21:13:35 +00:00
|
|
|
if(end[0] == '\0' && ! (eof && ((end+1) - buffer) == bs)) {
|
2002-01-30 12:46:03 +00:00
|
|
|
if(iter == buffer) {
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Buffer is too small for command %s\n",buffer);
|
2002-01-30 12:46:03 +00:00
|
|
|
mp_input_free_binds(binds);
|
2002-06-19 16:41:38 +00:00
|
|
|
close(fd);
|
2002-02-04 14:48:32 +00:00
|
|
|
return 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
memmove(buffer,iter,end - iter);
|
|
|
|
bs = end - iter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
char cmd[end-iter+1];
|
|
|
|
strncpy(cmd,iter,end-iter);
|
|
|
|
cmd[end-iter] = '\0';
|
2002-11-25 14:17:15 +00:00
|
|
|
//printf("Set bind %d => %s\n",keys[0],cmd);
|
2002-02-24 16:31:27 +00:00
|
|
|
mp_input_bind_keys(keys,cmd);
|
2002-01-30 12:46:03 +00:00
|
|
|
n_binds++;
|
|
|
|
}
|
2002-02-08 18:10:56 +00:00
|
|
|
keys[0] = 0;
|
2002-02-23 21:13:35 +00:00
|
|
|
end++;
|
2002-01-30 12:46:03 +00:00
|
|
|
if(bs > (end-buffer))
|
|
|
|
memmove(buffer,end,bs-(end-buffer));
|
|
|
|
bs -= (end-buffer);
|
2002-02-23 21:13:35 +00:00
|
|
|
buffer[bs-1] = '\0';
|
2002-01-30 12:46:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2003-07-09 01:42:19 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"What are we doing here?\n");
|
2002-06-19 16:41:38 +00:00
|
|
|
close(fd);
|
2002-02-04 14:48:32 +00:00
|
|
|
return 0;
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern char *get_path(char *filename);
|
|
|
|
|
|
|
|
void
|
|
|
|
mp_input_init(void) {
|
|
|
|
char* file;
|
|
|
|
|
2002-02-24 13:03:47 +00:00
|
|
|
file = config_file[0] != '/' ? get_path(config_file) : config_file;
|
2002-01-30 12:46:03 +00:00
|
|
|
if(!file)
|
|
|
|
return;
|
|
|
|
|
2004-08-03 12:21:14 +00:00
|
|
|
if( !mp_input_parse_config(file)) {
|
|
|
|
// free file if it was allocated by get_path(),
|
|
|
|
// before it gets overwritten
|
|
|
|
if( file != config_file)
|
|
|
|
{
|
|
|
|
free(file);
|
|
|
|
}
|
2002-06-24 12:17:23 +00:00
|
|
|
// Try global conf dir
|
2003-06-09 12:15:48 +00:00
|
|
|
file = MPLAYER_CONFDIR "/input.conf";
|
2002-06-24 12:17:23 +00:00
|
|
|
if(! mp_input_parse_config(file))
|
2004-11-15 09:09:29 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_V,"Falling back on default (hardcoded) input config\n");
|
2002-06-24 12:17:23 +00:00
|
|
|
}
|
2004-08-03 12:21:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// free file if it was allocated by get_path()
|
|
|
|
if( file != config_file)
|
|
|
|
free(file);
|
|
|
|
}
|
2002-01-30 12:46:03 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_JOYSTICK
|
2002-02-11 11:42:08 +00:00
|
|
|
if(use_joystick) {
|
2002-04-20 08:51:09 +00:00
|
|
|
int fd = mp_input_joystick_init(js_dev);
|
2002-01-30 12:46:03 +00:00
|
|
|
if(fd < 0)
|
2002-03-19 13:30:16 +00:00
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Can't init input joystick\n");
|
2002-01-30 12:46:03 +00:00
|
|
|
else
|
2002-02-04 14:19:54 +00:00
|
|
|
mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close);
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-01-31 09:39:11 +00:00
|
|
|
#ifdef HAVE_LIRC
|
2002-02-11 11:42:08 +00:00
|
|
|
if(use_lirc) {
|
2002-01-31 09:39:11 +00:00
|
|
|
int fd = mp_input_lirc_init();
|
|
|
|
if(fd > 0)
|
2002-10-23 22:23:12 +00:00
|
|
|
mp_input_add_cmd_fd(fd,0,mp_input_lirc_read,mp_input_lirc_close);
|
2002-01-31 09:39:11 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-05-30 18:23:55 +00:00
|
|
|
#ifdef HAVE_LIRCC
|
|
|
|
if(use_lircc) {
|
|
|
|
int fd = lircc_init("mplayer", NULL);
|
|
|
|
if(fd >= 0)
|
|
|
|
mp_input_add_cmd_fd(fd,1,NULL,(mp_close_func_t)lircc_cleanup);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-22 14:32:17 +00:00
|
|
|
if(in_file) {
|
|
|
|
struct stat st;
|
|
|
|
if(stat(in_file,&st))
|
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Can't stat %s: %s\n",in_file,strerror(errno));
|
|
|
|
else {
|
|
|
|
in_file_fd = open(in_file,S_ISFIFO(st.st_mode) ? O_RDWR : O_RDONLY);
|
|
|
|
if(in_file_fd >= 0)
|
|
|
|
mp_input_add_cmd_fd(in_file_fd,1,NULL,(mp_close_func_t)close);
|
|
|
|
else
|
|
|
|
mp_msg(MSGT_INPUT,MSGL_ERR,"Can't open %s: %s\n",in_file,strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-31 09:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mp_input_uninit(void) {
|
2002-02-03 19:13:00 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for(i=0; i < num_key_fd; i++) {
|
|
|
|
if(key_fds[i].close_func)
|
|
|
|
key_fds[i].close_func(key_fds[i].fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i < num_cmd_fd; i++) {
|
|
|
|
if(cmd_fds[i].close_func)
|
|
|
|
cmd_fds[i].close_func(cmd_fds[i].fd);
|
|
|
|
}
|
2004-10-30 10:40:53 +00:00
|
|
|
mp_input_free_binds(cmd_binds);
|
|
|
|
cmd_binds=NULL;
|
2002-02-03 19:13:00 +00:00
|
|
|
|
2002-01-30 12:46:03 +00:00
|
|
|
}
|
|
|
|
|
2002-02-11 11:42:08 +00:00
|
|
|
void
|
|
|
|
mp_input_register_options(m_config_t* cfg) {
|
|
|
|
m_config_register_options(cfg,mp_input_opts);
|
|
|
|
}
|
|
|
|
|
2003-08-13 16:29:32 +00:00
|
|
|
static int mp_input_print_key_list(m_option_t* cfg) {
|
2002-03-20 13:30:57 +00:00
|
|
|
int i;
|
|
|
|
printf("\n");
|
|
|
|
for(i= 0; key_names[i].name != NULL ; i++)
|
|
|
|
printf("%s\n",key_names[i].name);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2003-08-13 16:29:32 +00:00
|
|
|
static int mp_input_print_cmd_list(m_option_t* cfg) {
|
2002-03-20 13:30:57 +00:00
|
|
|
mp_cmd_t *cmd;
|
|
|
|
int i,j;
|
|
|
|
char* type;
|
|
|
|
|
|
|
|
for(i = 0; (cmd = &mp_cmds[i])->name != NULL ; i++) {
|
|
|
|
printf("%-20.20s",cmd->name);
|
|
|
|
for(j= 0 ; j < MP_CMD_MAX_ARGS && cmd->args[j].type != -1 ; j++) {
|
|
|
|
switch(cmd->args[j].type) {
|
|
|
|
case MP_CMD_ARG_INT:
|
|
|
|
type = "Integer";
|
|
|
|
break;
|
|
|
|
case MP_CMD_ARG_FLOAT:
|
|
|
|
type = "Float";
|
|
|
|
break;
|
|
|
|
case MP_CMD_ARG_STRING:
|
|
|
|
type = "String";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "??";
|
|
|
|
}
|
|
|
|
if(j+1 > cmd->nargs)
|
|
|
|
printf(" [%s]",type);
|
|
|
|
else
|
|
|
|
printf(" %s",type);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
2002-10-23 14:46:20 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
mp_input_check_interrupt(int time) {
|
|
|
|
mp_cmd_t* cmd;
|
2004-10-10 17:39:07 +00:00
|
|
|
if((cmd = mp_input_get_cmd(time,0,1)) == NULL)
|
2002-10-23 14:46:20 +00:00
|
|
|
return 0;
|
|
|
|
switch(cmd->id) {
|
|
|
|
case MP_CMD_QUIT:
|
|
|
|
case MP_CMD_PLAY_TREE_STEP:
|
|
|
|
case MP_CMD_PLAY_TREE_UP_STEP:
|
|
|
|
case MP_CMD_PLAY_ALT_SRC_STEP:
|
|
|
|
// The cmd will be executed when we are back in the main loop
|
|
|
|
return 1;
|
|
|
|
}
|
2004-10-10 17:39:07 +00:00
|
|
|
// remove the cmd from the queue
|
|
|
|
cmd = mp_input_get_cmd(time,0,0);
|
2002-10-23 14:46:20 +00:00
|
|
|
mp_cmd_free(cmd);
|
|
|
|
return 0;
|
|
|
|
}
|