20 #include "osdep/getch2.h"
21 #include "osdep/keycodes.h"
22 #include "osdep/timer.h"
35 #include <lirc/lircc.h>
38 /// This array defines all known commands.
39 /// The first field is an id used to recognize the command without too many strcmp.
40 /// The second is obviously the command name.
41 /// The third is the minimum number of arguments this command needs.
42 /// Then comes the definition of each argument, terminated with an arg of type -1.
43 /// A command can take a maximum of MP_CMD_MAX_ARGS-1 arguments (-1 because of
44 /// the last one) which is actually 9.
46 /// For the args, the first field is the type (actually int, float or string), the second
47 /// is the default value wich is used for optional arguments
49 static mp_cmd_t mp_cmds
[] = {
51 { MP_CMD_RADIO_STEP_CHANNEL
, "radio_step_channel", 1, { { MP_CMD_ARG_INT
,{0}}, {-1,{0}} }},
52 { MP_CMD_RADIO_SET_CHANNEL
, "radio_set_channel", 1, { { MP_CMD_ARG_STRING
, {0}}, {-1,{0}} }},
53 { MP_CMD_RADIO_SET_FREQ
, "radio_set_freq", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
54 { MP_CMD_RADIO_STEP_FREQ
, "radio_step_freq", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
56 { MP_CMD_SEEK
, "seek", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
57 { MP_CMD_EDL_MARK
, "edl_mark", 0, { {-1,{0}} } },
58 { MP_CMD_AUDIO_DELAY
, "audio_delay", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
59 { MP_CMD_SPEED_INCR
, "speed_incr", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
60 { MP_CMD_SPEED_MULT
, "speed_mult", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
61 { MP_CMD_SPEED_SET
, "speed_set", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
62 { MP_CMD_QUIT
, "quit", 0, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
63 { MP_CMD_PAUSE
, "pause", 0, { {-1,{0}} } },
64 { MP_CMD_FRAME_STEP
, "frame_step", 0, { {-1,{0}} } },
65 { MP_CMD_PLAY_TREE_STEP
, "pt_step",1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
66 { MP_CMD_PLAY_TREE_UP_STEP
, "pt_up_step",1, { { MP_CMD_ARG_INT
,{0} }, { MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
67 { MP_CMD_PLAY_ALT_SRC_STEP
, "alt_src_step",1, { { MP_CMD_ARG_INT
,{0} }, {-1,{0}} } },
68 { MP_CMD_SUB_DELAY
, "sub_delay",1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
69 { MP_CMD_SUB_STEP
, "sub_step",1, { { MP_CMD_ARG_INT
,{0} }, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
70 { MP_CMD_OSD
, "osd",0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
71 { MP_CMD_OSD_SHOW_TEXT
, "osd_show_text", 1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_INT
,{-1}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
72 { MP_CMD_OSD_SHOW_PROPERTY_TEXT
, "osd_show_property_text",1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_INT
,{-1}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
73 { MP_CMD_VOLUME
, "volume", 1, { { MP_CMD_ARG_FLOAT
,{0} }, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
74 { MP_CMD_MIXER_USEMASTER
, "use_master", 0, { {-1,{0}} } },
75 { MP_CMD_MUTE
, "mute", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
76 { MP_CMD_CONTRAST
, "contrast",1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
77 { MP_CMD_GAMMA
, "gamma", 1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
78 { MP_CMD_BRIGHTNESS
, "brightness",1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
79 { MP_CMD_HUE
, "hue",1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
80 { MP_CMD_SATURATION
, "saturation",1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
81 { MP_CMD_FRAMEDROPPING
, "frame_drop",0, { { MP_CMD_ARG_INT
,{-1} }, {-1,{0}} } },
82 { MP_CMD_SUB_POS
, "sub_pos", 1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
83 { MP_CMD_SUB_ALIGNMENT
, "sub_alignment",0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
84 { MP_CMD_SUB_VISIBILITY
, "sub_visibility", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
85 { MP_CMD_SUB_LOAD
, "sub_load", 1, { {MP_CMD_ARG_STRING
,{0}}, {-1,{0}} } },
86 { MP_CMD_SUB_REMOVE
, "sub_remove", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
87 { MP_CMD_SUB_SELECT
, "vobsub_lang", 0, { { MP_CMD_ARG_INT
,{-2} }, {-1,{0}} } }, // for compatibility
88 { MP_CMD_SUB_SELECT
, "sub_select", 0, { { MP_CMD_ARG_INT
,{-2} }, {-1,{0}} } },
89 { MP_CMD_SUB_LOG
, "sub_log", 0, { {-1,{0}} } },
90 { MP_CMD_GET_PERCENT_POS
, "get_percent_pos", 0, { {-1,{0}} } },
91 { MP_CMD_GET_TIME_POS
, "get_time_pos", 0, { {-1,{0}} } },
92 { MP_CMD_GET_TIME_LENGTH
, "get_time_length", 0, { {-1,{0}} } },
93 { MP_CMD_GET_FILENAME
, "get_file_name", 0, { {-1,{0}} } },
94 { MP_CMD_GET_VIDEO_CODEC
, "get_video_codec", 0, { {-1,{0}} } },
95 { MP_CMD_GET_VIDEO_BITRATE
, "get_video_bitrate", 0, { {-1,{0}} } },
96 { MP_CMD_GET_VIDEO_RESOLUTION
, "get_video_resolution", 0, { {-1,{0}} } },
97 { MP_CMD_GET_AUDIO_CODEC
, "get_audio_codec", 0, { {-1,{0}} } },
98 { MP_CMD_GET_AUDIO_BITRATE
, "get_audio_bitrate", 0, { {-1,{0}} } },
99 { MP_CMD_GET_AUDIO_SAMPLES
, "get_audio_samples", 0, { {-1,{0}} } },
100 { MP_CMD_GET_META_TITLE
, "get_meta_title", 0, { {-1,{0}} } },
101 { MP_CMD_GET_META_ARTIST
, "get_meta_artist", 0, { {-1,{0}} } },
102 { MP_CMD_GET_META_ALBUM
, "get_meta_album", 0, { {-1,{0}} } },
103 { MP_CMD_GET_META_YEAR
, "get_meta_year", 0, { {-1,{0}} } },
104 { MP_CMD_GET_META_COMMENT
, "get_meta_comment", 0, { {-1,{0}} } },
105 { MP_CMD_GET_META_TRACK
, "get_meta_track", 0, { {-1,{0}} } },
106 { MP_CMD_GET_META_GENRE
, "get_meta_genre", 0, { {-1,{0}} } },
107 { MP_CMD_SWITCH_AUDIO
, "switch_audio", 0, { { MP_CMD_ARG_INT
,{-1} }, {-1,{0}} } },
109 { MP_CMD_TV_STEP_CHANNEL
, "tv_step_channel", 1, { { MP_CMD_ARG_INT
,{0}}, {-1,{0}} }},
110 { MP_CMD_TV_STEP_NORM
, "tv_step_norm",0, { {-1,{0}} } },
111 { MP_CMD_TV_STEP_CHANNEL_LIST
, "tv_step_chanlist", 0, { {-1,{0}} } },
112 { MP_CMD_TV_SET_CHANNEL
, "tv_set_channel", 1, { { MP_CMD_ARG_STRING
, {0}}, {-1,{0}} }},
113 { MP_CMD_TV_LAST_CHANNEL
, "tv_last_channel", 0, { {-1,{0}} } },
114 { MP_CMD_TV_SET_FREQ
, "tv_set_freq", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
115 { MP_CMD_TV_SET_NORM
, "tv_set_norm", 1, { {MP_CMD_ARG_STRING
,{0}}, {-1,{0}} } },
116 { MP_CMD_TV_SET_BRIGHTNESS
, "tv_set_brightness", 1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{1} }, {-1,{0}} }},
117 { MP_CMD_TV_SET_CONTRAST
, "tv_set_contrast", 1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{1} }, {-1,{0}} }},
118 { MP_CMD_TV_SET_HUE
, "tv_set_hue", 1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{1} }, {-1,{0}} }},
119 { MP_CMD_TV_SET_SATURATION
, "tv_set_saturation", 1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{1} }, {-1,{0}} }},
121 { MP_CMD_SUB_FORCED_ONLY
, "forced_subs_only", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
122 #ifdef HAS_DVBIN_SUPPORT
123 { MP_CMD_DVB_SET_CHANNEL
, "dvb_set_channel", 2, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}}}},
125 { MP_CMD_SWITCH_RATIO
, "switch_ratio", 0, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
126 { MP_CMD_VO_FULLSCREEN
, "vo_fullscreen", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
127 { MP_CMD_VO_ONTOP
, "vo_ontop", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
128 { MP_CMD_FILE_FILTER
, "file_filter", 1, { { MP_CMD_ARG_INT
, {0}}, {-1,{0}}}},
129 { MP_CMD_VO_ROOTWIN
, "vo_rootwin", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
130 { MP_CMD_VO_BORDER
, "vo_border", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
131 { MP_CMD_SCREENSHOT
, "screenshot", 0, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
132 { MP_CMD_PANSCAN
, "panscan",1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
133 { MP_CMD_SWITCH_VSYNC
, "switch_vsync", 0, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
134 { MP_CMD_LOADFILE
, "loadfile", 1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
135 { MP_CMD_LOADLIST
, "loadlist", 1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
136 { MP_CMD_RUN
, "run", 1, { {MP_CMD_ARG_STRING
,{0}}, {-1,{0}} } },
137 { MP_CMD_VF_CHANGE_RECTANGLE
, "change_rectangle", 2, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}}}},
140 { MP_CMD_GUI_LOADFILE
, "gui_loadfile", 0, { {-1,{0}} } },
141 { MP_CMD_GUI_LOADSUBTITLE
, "gui_loadsubtitle", 0, { {-1,{0}} } },
142 { MP_CMD_GUI_ABOUT
, "gui_about", 0, { {-1,{0}} } },
143 { MP_CMD_GUI_PLAY
, "gui_play", 0, { {-1,{0}} } },
144 { MP_CMD_GUI_STOP
, "gui_stop", 0, { {-1,{0}} } },
145 { MP_CMD_GUI_PLAYLIST
, "gui_playlist", 0, { {-1,{0}} } },
146 { MP_CMD_GUI_PREFERENCES
, "gui_preferences", 0, { {-1,{0}} } },
147 { MP_CMD_GUI_SKINBROWSER
, "gui_skinbrowser", 0, { {-1,{0}} } },
151 { MP_CMD_DVDNAV
, "dvdnav", 1, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
155 { MP_CMD_MENU
, "menu",1, { {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
156 { MP_CMD_SET_MENU
, "set_menu",1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
157 { MP_CMD_CHELP
, "help", 0, { {-1,{0}} } },
158 { MP_CMD_CEXIT
, "exit", 0, { {-1,{0}} } },
159 { MP_CMD_CHIDE
, "hide", 0, { {MP_CMD_ARG_INT
,{3000}}, {-1,{0}} } },
162 { MP_CMD_GET_VO_FULLSCREEN
, "get_vo_fullscreen", 0, { {-1,{0}} } },
163 { MP_CMD_GET_SUB_VISIBILITY
, "get_sub_visibility", 0, { {-1,{0}} } },
164 { MP_CMD_KEYDOWN_EVENTS
, "key_down_event", 1, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
165 { MP_CMD_SET_PROPERTY
, "set_property", 2, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
166 { MP_CMD_GET_PROPERTY
, "get_property", 1, { {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
167 { MP_CMD_STEP_PROPERTY
, "step_property", 1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
169 { MP_CMD_SEEK_CHAPTER
, "seek_chapter", 1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
170 { MP_CMD_SET_MOUSE_POS
, "set_mouse_pos", 2, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
175 /// The names of the keys as used in input.conf
176 /// If you add some new keys, you also need to add them here
178 static mp_key_name_t key_names
[] = {
180 { KEY_ENTER
, "ENTER" },
182 { KEY_CTRL
, "CTRL" },
183 { KEY_BACKSPACE
, "BS" },
184 { KEY_DELETE
, "DEL" },
185 { KEY_INSERT
, "INS" },
186 { KEY_HOME
, "HOME" },
188 { KEY_PAGE_UP
, "PGUP" },
189 { KEY_PAGE_DOWN
, "PGDWN" },
191 { KEY_RIGHT
, "RIGHT" },
192 { KEY_LEFT
, "LEFT" },
193 { KEY_DOWN
, "DOWN" },
217 { KEY_KPDEL
, "KP_DEL" },
218 { KEY_KPDEC
, "KP_DEC" },
219 { KEY_KPINS
, "KP_INS" },
220 { KEY_KPENTER
, "KP_ENTER" },
221 { MOUSE_BTN0
, "MOUSE_BTN0" },
222 { MOUSE_BTN1
, "MOUSE_BTN1" },
223 { MOUSE_BTN2
, "MOUSE_BTN2" },
224 { MOUSE_BTN3
, "MOUSE_BTN3" },
225 { MOUSE_BTN4
, "MOUSE_BTN4" },
226 { MOUSE_BTN5
, "MOUSE_BTN5" },
227 { MOUSE_BTN6
, "MOUSE_BTN6" },
228 { MOUSE_BTN7
, "MOUSE_BTN7" },
229 { MOUSE_BTN8
, "MOUSE_BTN8" },
230 { MOUSE_BTN9
, "MOUSE_BTN9" },
231 { MOUSE_BTN0_DBL
, "MOUSE_BTN0_DBL" },
232 { MOUSE_BTN1_DBL
, "MOUSE_BTN1_DBL" },
233 { MOUSE_BTN2_DBL
, "MOUSE_BTN2_DBL" },
234 { MOUSE_BTN3_DBL
, "MOUSE_BTN3_DBL" },
235 { MOUSE_BTN4_DBL
, "MOUSE_BTN4_DBL" },
236 { MOUSE_BTN5_DBL
, "MOUSE_BTN5_DBL" },
237 { MOUSE_BTN6_DBL
, "MOUSE_BTN6_DBL" },
238 { MOUSE_BTN7_DBL
, "MOUSE_BTN7_DBL" },
239 { MOUSE_BTN8_DBL
, "MOUSE_BTN8_DBL" },
240 { MOUSE_BTN9_DBL
, "MOUSE_BTN9_DBL" },
241 { JOY_AXIS1_MINUS
, "JOY_UP" },
242 { JOY_AXIS1_PLUS
, "JOY_DOWN" },
243 { JOY_AXIS0_MINUS
, "JOY_LEFT" },
244 { JOY_AXIS0_PLUS
, "JOY_RIGHT" },
246 { JOY_AXIS0_PLUS
, "JOY_AXIS0_PLUS" },
247 { JOY_AXIS0_MINUS
, "JOY_AXIS0_MINUS" },
248 { JOY_AXIS1_PLUS
, "JOY_AXIS1_PLUS" },
249 { JOY_AXIS1_MINUS
, "JOY_AXIS1_MINUS" },
250 { JOY_AXIS2_PLUS
, "JOY_AXIS2_PLUS" },
251 { JOY_AXIS2_MINUS
, "JOY_AXIS2_MINUS" },
252 { JOY_AXIS3_PLUS
, "JOY_AXIS3_PLUS" },
253 { JOY_AXIS3_MINUS
, "JOY_AXIS3_MINUS" },
254 { JOY_AXIS4_PLUS
, "JOY_AXIS4_PLUS" },
255 { JOY_AXIS4_MINUS
, "JOY_AXIS4_MINUS" },
256 { JOY_AXIS5_PLUS
, "JOY_AXIS5_PLUS" },
257 { JOY_AXIS5_MINUS
, "JOY_AXIS5_MINUS" },
258 { JOY_AXIS6_PLUS
, "JOY_AXIS6_PLUS" },
259 { JOY_AXIS6_MINUS
, "JOY_AXIS6_MINUS" },
260 { JOY_AXIS7_PLUS
, "JOY_AXIS7_PLUS" },
261 { JOY_AXIS7_MINUS
, "JOY_AXIS7_MINUS" },
262 { JOY_AXIS8_PLUS
, "JOY_AXIS8_PLUS" },
263 { JOY_AXIS8_MINUS
, "JOY_AXIS8_MINUS" },
264 { JOY_AXIS9_PLUS
, "JOY_AXIS9_PLUS" },
265 { JOY_AXIS9_MINUS
, "JOY_AXIS9_MINUS" },
267 { JOY_BTN0
, "JOY_BTN0" },
268 { JOY_BTN1
, "JOY_BTN1" },
269 { JOY_BTN2
, "JOY_BTN2" },
270 { JOY_BTN3
, "JOY_BTN3" },
271 { JOY_BTN4
, "JOY_BTN4" },
272 { JOY_BTN5
, "JOY_BTN5" },
273 { JOY_BTN6
, "JOY_BTN6" },
274 { JOY_BTN7
, "JOY_BTN7" },
275 { JOY_BTN8
, "JOY_BTN8" },
276 { JOY_BTN9
, "JOY_BTN9" },
278 { KEY_POWER
, "POWER" },
279 { KEY_MENU
, "MENU" },
280 { KEY_PLAY
, "PLAY" },
281 { KEY_PAUSE
, "PAUSE" },
282 { KEY_PLAYPAUSE
, "PLAYPAUSE" },
283 { KEY_STOP
, "STOP" },
284 { KEY_FORWARD
, "FORWARD" },
285 { KEY_REWIND
, "REWIND" },
286 { KEY_NEXT
, "NEXT" },
287 { KEY_PREV
, "PREV" },
288 { KEY_VOLUME_UP
, "VOLUME_UP" },
289 { KEY_VOLUME_DOWN
, "VOLUME_DOWN" },
290 { KEY_MUTE
, "MUTE" },
292 // These are kept for backward compatibility
293 { KEY_PAUSE
, "XF86_PAUSE" },
294 { KEY_STOP
, "XF86_STOP" },
295 { KEY_PREV
, "XF86_PREV" },
296 { KEY_NEXT
, "XF86_NEXT" },
298 { KEY_CLOSE_WIN
, "CLOSE_WIN" },
303 // This is the default binding. The content of input.conf overrides these.
304 // The first arg is a null terminated array of key codes.
305 // The second is the command
307 static mp_cmd_bind_t def_cmd_binds
[] = {
309 { { MOUSE_BTN3
, 0 }, "seek 10" },
310 { { MOUSE_BTN4
, 0 }, "seek -10" },
311 { { MOUSE_BTN5
, 0 }, "volume 1" },
312 { { MOUSE_BTN6
, 0 }, "volume -1" },
315 { { KEY_KP8
, 0 }, "dvdnav 1" }, // up
316 { { KEY_KP2
, 0 }, "dvdnav 2" }, // down
317 { { KEY_KP4
, 0 }, "dvdnav 3" }, // left
318 { { KEY_KP6
, 0 }, "dvdnav 4" }, // right
319 { { KEY_KP5
, 0 }, "dvdnav 5" }, // menu
320 { { KEY_KPENTER
, 0 }, "dvdnav 6" }, // select
321 { { MOUSE_BTN0
, 0 }, "dvdnav 8" }, //select
322 { { KEY_KP7
, 0 }, "dvdnav 7" }, // previous menu
325 { { KEY_RIGHT
, 0 }, "seek 10" },
326 { { KEY_LEFT
, 0 }, "seek -10" },
327 { { KEY_UP
, 0 }, "seek 60" },
328 { { KEY_DOWN
, 0 }, "seek -60" },
329 { { KEY_PAGE_UP
, 0 }, "seek 600" },
330 { { KEY_PAGE_DOWN
, 0 }, "seek -600" },
331 { { '+', 0 }, "audio_delay 0.100" },
332 { { '-', 0 }, "audio_delay -0.100" },
333 { { '[', 0 }, "speed_mult 0.9091" },
334 { { ']', 0 }, "speed_mult 1.1" },
335 { { '{', 0 }, "speed_mult 0.5" },
336 { { '}', 0 }, "speed_mult 2.0" },
337 { { KEY_BACKSPACE
, 0 }, "speed_set 1.0" },
338 { { 'q', 0 }, "quit" },
339 { { KEY_ESC
, 0 }, "quit" },
340 { { 'p', 0 }, "pause" },
341 { { ' ', 0 }, "pause" },
342 { { '.', 0 }, "frame_step" },
343 { { KEY_HOME
, 0 }, "pt_up_step 1" },
344 { { KEY_END
, 0 }, "pt_up_step -1" },
345 { { '>', 0 }, "pt_step 1" },
346 { { KEY_ENTER
, 0 }, "pt_step 1 1" },
347 { { '<', 0 }, "pt_step -1" },
348 { { KEY_INS
, 0 }, "alt_src_step 1" },
349 { { KEY_DEL
, 0 }, "alt_src_step -1" },
350 { { 'o', 0 }, "osd" },
351 { { 'I', 0 }, "osd_show_property_text \"${filename}\"" },
352 { { 'z', 0 }, "sub_delay -0.1" },
353 { { 'x', 0 }, "sub_delay +0.1" },
354 { { 'g', 0 }, "sub_step -1" },
355 { { 'y', 0 }, "sub_step +1" },
356 { { '9', 0 }, "volume -1" },
357 { { '/', 0 }, "volume -1" },
358 { { '0', 0 }, "volume 1" },
359 { { '*', 0 }, "volume 1" },
360 { { 'm', 0 }, "mute" },
361 { { '1', 0 }, "contrast -1" },
362 { { '2', 0 }, "contrast 1" },
363 { { '3', 0 }, "brightness -1" },
364 { { '4', 0 }, "brightness 1" },
365 { { '5', 0 }, "hue -1" },
366 { { '6', 0 }, "hue 1" },
367 { { '7', 0 }, "saturation -1" },
368 { { '8', 0 }, "saturation 1" },
369 { { 'd', 0 }, "frame_drop" },
370 { { 'D', 0 }, "step_property deinterlace" },
371 { { 'r', 0 }, "sub_pos -1" },
372 { { 't', 0 }, "sub_pos +1" },
373 { { 'a', 0 }, "sub_alignment" },
374 { { 'v', 0 }, "sub_visibility" },
375 { { 'j', 0 }, "sub_select" },
376 { { 'F', 0 }, "forced_subs_only" },
377 { { '#', 0 }, "switch_audio" },
378 { { '_', 0 }, "step_property switch_video" },
379 { { KEY_TAB
, 0 }, "step_property switch_program" },
380 { { 'i', 0 }, "edl_mark" },
382 { { 'h', 0 }, "tv_step_channel 1" },
383 { { 'k', 0 }, "tv_step_channel -1" },
384 { { 'n', 0 }, "tv_step_norm" },
385 { { 'u', 0 }, "tv_step_chanlist" },
388 { { JOY_AXIS0_PLUS
, 0 }, "seek 10" },
389 { { JOY_AXIS0_MINUS
, 0 }, "seek -10" },
390 { { JOY_AXIS1_MINUS
, 0 }, "seek 60" },
391 { { JOY_AXIS1_PLUS
, 0 }, "seek -60" },
392 { { JOY_BTN0
, 0 }, "pause" },
393 { { JOY_BTN1
, 0 }, "osd" },
394 { { JOY_BTN2
, 0 }, "volume 1"},
395 { { JOY_BTN3
, 0 }, "volume -1"},
397 { { 'T', 0 }, "vo_ontop" },
398 { { 'f', 0 }, "vo_fullscreen" },
399 { { 's', 0 }, "screenshot 0" },
400 { { 'S', 0 }, "screenshot 1" },
401 { { 'w', 0 }, "panscan -0.1" },
402 { { 'e', 0 }, "panscan +0.1" },
404 { { KEY_POWER
, 0 }, "quit" },
405 { { KEY_MENU
, 0 }, "osd" },
406 { { KEY_PLAY
, 0 }, "pause" },
407 { { KEY_PAUSE
, 0 }, "pause" },
408 { { KEY_PLAYPAUSE
, 0 }, "pause" },
409 { { KEY_STOP
, 0 }, "quit" },
410 { { KEY_FORWARD
, 0 }, "seek 60" },
411 { { KEY_REWIND
, 0 }, "seek -60" },
412 { { KEY_NEXT
, 0 }, "pt_step 1" },
413 { { KEY_PREV
, 0 }, "pt_step -1" },
414 { { KEY_VOLUME_UP
, 0 }, "volume 1" },
415 { { KEY_VOLUME_DOWN
, 0 }, "volume -1" },
416 { { KEY_MUTE
, 0 }, "mute" },
418 { { KEY_CLOSE_WIN
, 0 }, "quit" },
420 { { '!', 0 }, "seek_chapter -1" },
421 { { '@', 0 }, "seek_chapter 1" },
428 static mp_cmd_bind_t gui_def_cmd_binds
[] = {
430 { { 'l', 0 }, "gui_loadfile" },
431 { { 't', 0 }, "gui_loadsubtitle" },
432 { { KEY_ENTER
, 0 }, "gui_play" },
433 { { KEY_ESC
, 0 }, "gui_stop" },
434 { { 'p', 0 }, "gui_playlist" },
435 { { 'r', 0 }, "gui_preferences" },
436 { { 'c', 0 }, "gui_skinbrowser" },
442 #ifndef MP_MAX_KEY_FD
443 #define MP_MAX_KEY_FD 10
446 #ifndef MP_MAX_CMD_FD
447 #define MP_MAX_CMD_FD 10
450 #define MP_FD_EOF (1<<0)
451 #define MP_FD_DROP (1<<1)
452 #define MP_FD_DEAD (1<<2)
453 #define MP_FD_GOT_CMD (1<<3)
454 #define MP_FD_NO_SELECT (1<<4)
456 #define CMD_QUEUE_SIZE 100
458 typedef struct mp_input_fd
{
461 mp_close_func_t close_func
;
463 // These fields are for the cmd fds.
468 typedef struct mp_cmd_filter_st mp_cmd_filter_t
;
470 struct mp_cmd_filter_st
{
471 mp_input_cmd_filter filter
;
473 mp_cmd_filter_t
* next
;
476 // These are the user defined binds
477 static mp_cmd_bind_t
* cmd_binds
= NULL
;
478 static mp_cmd_filter_t
* cmd_filters
= NULL
;
480 // Callback to allow the menu filter to grab the incoming keys
481 void (*mp_input_key_cb
)(int code
) = NULL
;
483 static mp_input_fd_t key_fds
[MP_MAX_KEY_FD
];
484 static unsigned int num_key_fd
= 0;
485 static mp_input_fd_t cmd_fds
[MP_MAX_CMD_FD
];
486 static unsigned int num_cmd_fd
= 0;
487 static mp_cmd_t
* cmd_queue
[CMD_QUEUE_SIZE
];
488 static unsigned int cmd_queue_length
= 0,cmd_queue_start
= 0, cmd_queue_end
= 0;
490 // this is the key currently down
491 static int key_down
[MP_MAX_KEY_DOWN
];
492 static unsigned int num_key_down
= 0, last_key_down
= 0;
495 static short ar_state
= -1;
496 static mp_cmd_t
* ar_cmd
= NULL
;
497 static unsigned int ar_delay
= 100, ar_rate
= 8, last_ar
= 0;
499 static int use_joystick
= 1, use_lirc
= 1, use_lircc
= 1;
500 static char* config_file
= "input.conf";
502 static char* js_dev
= NULL
;
504 static char* in_file
= NULL
;
505 static int in_file_fd
= -1;
507 static int mp_input_print_key_list(m_option_t
* cfg
);
508 static int mp_input_print_cmd_list(m_option_t
* cfg
);
510 // Our command line options
511 static m_option_t input_conf
[] = {
512 { "conf", &config_file
, CONF_TYPE_STRING
, CONF_GLOBAL
, 0, 0, NULL
},
513 { "ar-delay", &ar_delay
, CONF_TYPE_INT
, CONF_GLOBAL
, 0, 0, NULL
},
514 { "ar-rate", &ar_rate
, CONF_TYPE_INT
, CONF_GLOBAL
, 0, 0, NULL
},
515 { "keylist", mp_input_print_key_list
, CONF_TYPE_FUNC
, CONF_GLOBAL
, 0, 0, NULL
},
516 { "cmdlist", mp_input_print_cmd_list
, CONF_TYPE_FUNC
, CONF_GLOBAL
, 0, 0, NULL
},
517 { "js-dev", &js_dev
, CONF_TYPE_STRING
, CONF_GLOBAL
, 0, 0, NULL
},
518 { "file", &in_file
, CONF_TYPE_STRING
, CONF_GLOBAL
, 0, 0, NULL
},
519 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
522 static m_option_t mp_input_opts
[] = {
523 { "input", &input_conf
, CONF_TYPE_SUBCONFIG
, 0, 0, 0, NULL
},
524 { "nojoystick", &use_joystick
, CONF_TYPE_FLAG
, CONF_GLOBAL
, 1, 0, NULL
},
525 { "joystick", &use_joystick
, CONF_TYPE_FLAG
, CONF_GLOBAL
, 0, 1, NULL
},
526 { "nolirc", &use_lirc
, CONF_TYPE_FLAG
, CONF_GLOBAL
, 1, 0, NULL
},
527 { "lirc", &use_lirc
, CONF_TYPE_FLAG
, CONF_GLOBAL
, 0, 1, NULL
},
528 { "nolircc", &use_lircc
, CONF_TYPE_FLAG
, CONF_GLOBAL
, 1, 0, NULL
},
529 { "lircc", &use_lircc
, CONF_TYPE_FLAG
, CONF_GLOBAL
, 0, 1, NULL
},
530 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
534 mp_input_default_key_func(int fd
);
537 mp_input_default_cmd_func(int fd
,char* buf
, int l
);
540 mp_input_get_key_name(int key
);
544 mp_input_add_cmd_fd(int fd
, int select
, mp_cmd_func_t read_func
, mp_close_func_t close_func
) {
545 if(num_cmd_fd
== MP_MAX_CMD_FD
) {
546 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrCantRegister2ManyCmdFds
,fd
);
550 memset(&cmd_fds
[num_cmd_fd
],0,sizeof(mp_input_fd_t
));
551 cmd_fds
[num_cmd_fd
].fd
= fd
;
552 cmd_fds
[num_cmd_fd
].read_func
= read_func
? read_func
: mp_input_default_cmd_func
;
553 cmd_fds
[num_cmd_fd
].close_func
= close_func
;
555 cmd_fds
[num_cmd_fd
].flags
= MP_FD_NO_SELECT
;
562 mp_input_rm_cmd_fd(int fd
) {
565 for(i
= 0; i
< num_cmd_fd
; i
++) {
566 if(cmd_fds
[i
].fd
== fd
)
571 if(cmd_fds
[i
].close_func
)
572 cmd_fds
[i
].close_func(cmd_fds
[i
].fd
);
573 if(cmd_fds
[i
].buffer
)
574 free(cmd_fds
[i
].buffer
);
576 if(i
+ 1 < num_cmd_fd
)
577 memmove(&cmd_fds
[i
],&cmd_fds
[i
+1],(num_cmd_fd
- i
- 1)*sizeof(mp_input_fd_t
));
582 mp_input_rm_key_fd(int fd
) {
585 for(i
= 0; i
< num_key_fd
; i
++) {
586 if(key_fds
[i
].fd
== fd
)
591 if(key_fds
[i
].close_func
)
592 key_fds
[i
].close_func(key_fds
[i
].fd
);
594 if(i
+ 1 < num_key_fd
)
595 memmove(&key_fds
[i
],&key_fds
[i
+1],(num_key_fd
- i
- 1)*sizeof(mp_input_fd_t
));
600 mp_input_add_key_fd(int fd
, int select
, mp_key_func_t read_func
, mp_close_func_t close_func
) {
601 if(num_key_fd
== MP_MAX_KEY_FD
) {
602 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds
,fd
);
606 memset(&key_fds
[num_key_fd
],0,sizeof(mp_input_fd_t
));
607 key_fds
[num_key_fd
].fd
= fd
;
608 key_fds
[num_key_fd
].read_func
= read_func
? read_func
: mp_input_default_key_func
;
609 key_fds
[num_key_fd
].close_func
= close_func
;
611 key_fds
[num_key_fd
].flags
|= MP_FD_NO_SELECT
;
620 mp_input_parse_cmd(char* str
) {
624 mp_cmd_t
*cmd
, *cmd_def
;
630 if (strncmp(str
, "pausing ", 8) == 0) {
633 } else if (strncmp(str
, "pausing_keep ", 13) == 0) {
636 } else if (strncmp(str
, "pausing_toggle ", 15) == 0) {
641 for(ptr
= str
; ptr
[0] != '\0' && ptr
[0] != '\t' && ptr
[0] != ' ' ; ptr
++)
651 for(i
=0; mp_cmds
[i
].name
!= NULL
; i
++) {
652 if(strncasecmp(mp_cmds
[i
].name
,str
,l
) == 0)
656 if(mp_cmds
[i
].name
== NULL
)
659 cmd_def
= &mp_cmds
[i
];
661 cmd
= calloc(1, sizeof(mp_cmd_t
));
662 cmd
->id
= cmd_def
->id
;
663 cmd
->name
= strdup(cmd_def
->name
);
664 cmd
->pausing
= pausing
;
668 for(i
=0; ptr
&& i
< MP_CMD_MAX_ARGS
; i
++) {
669 ptr
= strchr(ptr
,' ');
671 while(ptr
[0] == ' ' || ptr
[0] == '\t') ptr
++;
672 if(ptr
[0] == '\0') break;
673 cmd
->args
[i
].type
= cmd_def
->args
[i
].type
;
674 switch(cmd_def
->args
[i
].type
) {
677 cmd
->args
[i
].v
.i
= atoi(ptr
);
679 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrArgMustBeInt
,cmd_def
->name
,i
+1);
683 case MP_CMD_ARG_FLOAT
:
685 cmd
->args
[i
].v
.f
= atof(ptr
);
687 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrArgMustBeFloat
,cmd_def
->name
,i
+1);
691 case MP_CMD_ARG_STRING
: {
693 char* ptr2
= ptr
, *start
;
695 if(ptr
[0] == '\'' || ptr
[0] == '"') {
702 e
= strchr(ptr2
,term
);
704 if(e
<= ptr2
|| *(e
- 1) != '\\') break;
708 if(term
!= ' ' && (!e
|| e
[0] == '\0')) {
709 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrUnterminatedArg
,cmd_def
->name
,i
+1);
712 } else if(!e
) e
= ptr
+strlen(ptr
);
715 for(e
= strchr(ptr2
,'\\') ; e
&& e
<start
+l
; e
= strchr(ptr2
,'\\')) {
716 memmove(e
,e
+1,strlen(e
));
720 cmd
->args
[i
].v
.s
= malloc(l
+1);
721 strncpy(cmd
->args
[i
].v
.s
,start
,l
);
722 cmd
->args
[i
].v
.s
[l
] = '\0';
723 if(term
!= ' ') ptr
+= l
+2;
729 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrUnknownArg
,i
);
734 if(cmd_def
->nargs
> cmd
->nargs
) {
735 /* mp_msg(MSGT_INPUT,MSGL_ERR,"Got command '%s' but\n",str); */
736 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_Err2FewArgs
,cmd_def
->name
,cmd_def
->nargs
,cmd
->nargs
);
741 for( ; i
< MP_CMD_MAX_ARGS
&& cmd_def
->args
[i
].type
!= -1 ; i
++) {
742 memcpy(&cmd
->args
[i
],&cmd_def
->args
[i
],sizeof(mp_cmd_arg_t
));
743 if(cmd_def
->args
[i
].type
== MP_CMD_ARG_STRING
&& cmd_def
->args
[i
].v
.s
!= NULL
)
744 cmd
->args
[i
].v
.s
= strdup(cmd_def
->args
[i
].v
.s
);
747 if(i
< MP_CMD_MAX_ARGS
)
748 cmd
->args
[i
].type
= -1;
754 mp_input_default_key_func(int fd
) {
758 while(l
< sizeof(int)) {
759 r
= read(fd
,((char *)&code
)+l
,sizeof(int)-l
);
767 #define MP_CMD_MAX_SIZE 256
770 mp_input_read_cmd(mp_input_fd_t
* mp_fd
, char** ret
) {
774 // Allocate the buffer if it doesn't exist
776 mp_fd
->buffer
= malloc(MP_CMD_MAX_SIZE
);
778 mp_fd
->size
= MP_CMD_MAX_SIZE
;
781 // Get some data if needed/possible
782 while( !(mp_fd
->flags
& MP_FD_GOT_CMD
) && !(mp_fd
->flags
& MP_FD_EOF
) && (mp_fd
->size
- mp_fd
->pos
> 1) ) {
783 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
);
789 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrReadingCmdFd
,mp_fd
->fd
,strerror(errno
));
790 case MP_INPUT_NOTHING
:
797 mp_fd
->flags
|= MP_FD_EOF
;
804 // Reset the got_cmd flag
805 mp_fd
->flags
&= ~MP_FD_GOT_CMD
;
810 mp_fd
->buffer
[mp_fd
->pos
] = '\0';
811 end
= strchr(mp_fd
->buffer
,'\n');
814 // If buffer is full we must drop all until the next \n
815 if(mp_fd
->size
- mp_fd
->pos
<= 1) {
816 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrCmdBufferFullDroppingContent
,mp_fd
->fd
);
818 mp_fd
->flags
|= MP_FD_DROP
;
822 // We already have a cmd : set the got_cmd flag
824 mp_fd
->flags
|= MP_FD_GOT_CMD
;
828 l
= end
- mp_fd
->buffer
;
830 // Not dropping : put the cmd in ret
831 if( ! (mp_fd
->flags
& MP_FD_DROP
)) {
832 (*ret
) = malloc(l
+1);
833 strncpy((*ret
),mp_fd
->buffer
,l
);
835 } else { // Remove the dropping flag
836 mp_fd
->flags
&= ~MP_FD_DROP
;
838 if( mp_fd
->pos
- (l
+1) > 0)
839 memmove(mp_fd
->buffer
,end
+1,mp_fd
->pos
-(l
+1));
846 return MP_INPUT_NOTHING
;
850 mp_input_default_cmd_func(int fd
,char* buf
, int l
) {
853 int r
= read(fd
,buf
,l
);
858 else if(errno
== EAGAIN
)
859 return MP_INPUT_NOTHING
;
860 return MP_INPUT_ERROR
;
870 mp_input_add_cmd_filter(mp_input_cmd_filter func
, void* ctx
) {
871 mp_cmd_filter_t
* filter
= malloc(sizeof(mp_cmd_filter_t
))/*, *prev*/;
873 filter
->filter
= func
;
875 filter
->next
= cmd_filters
;
876 cmd_filters
= filter
;
881 mp_input_find_bind_for_key(mp_cmd_bind_t
* binds
, int n
,int* keys
) {
884 if (n
<= 0) return NULL
;
885 for(j
= 0; binds
[j
].cmd
!= NULL
; j
++) {
887 for(s
= 0; s
< n
&& binds
[j
].input
[s
] != 0; s
++) {
888 if(binds
[j
].input
[s
] != keys
[s
]) {
893 if(found
&& binds
[j
].input
[s
] == 0 && s
== n
)
900 mp_input_get_cmd_from_keys(int n
,int* keys
, int paused
) {
905 cmd
= mp_input_find_bind_for_key(cmd_binds
,n
,keys
);
907 cmd
= mp_input_find_bind_for_key(def_cmd_binds
,n
,keys
);
910 mp_msg(MSGT_INPUT
,MSGL_WARN
,MSGTR_NoBindFound
,mp_input_get_key_name(keys
[0]));
914 mp_msg(MSGT_INPUT
,MSGL_WARN
,"-%s",mp_input_get_key_name(keys
[s
]));
916 mp_msg(MSGT_INPUT
,MSGL_WARN
," \n");
919 if (strcmp(cmd
, "ignore") == 0) return NULL
;
920 ret
= mp_input_parse_cmd(cmd
);
922 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrInvalidCommandForKey
,mp_input_get_key_name(key_down
[0]));
923 if( num_key_down
> 1) {
925 for(s
=1; s
< num_key_down
; s
++)
926 mp_msg(MSGT_INPUT
,MSGL_ERR
,"-%s",mp_input_get_key_name(key_down
[s
]));
928 mp_msg(MSGT_INPUT
,MSGL_ERR
," : %s \n",cmd
);
934 mp_input_read_key_code(int time
) {
935 #ifndef HAVE_NO_POSIX_SELECT
937 struct timeval tv
,*time_val
;
939 int i
,n
=0,max_fd
= 0, did_sleep
= 0;
940 static int last_loop
= 0;
945 usec_sleep(time
* 1000);
946 return MP_INPUT_NOTHING
;
949 #ifndef HAVE_NO_POSIX_SELECT
952 // Remove fd marked as dead and build the fd_set
953 // n == number of fd's to be select() checked
954 for(i
= 0; (unsigned int)i
< num_key_fd
; i
++) {
955 if( (key_fds
[i
].flags
& MP_FD_DEAD
) ) {
956 mp_input_rm_key_fd(key_fds
[i
].fd
);
959 } else if(key_fds
[i
].flags
& MP_FD_NO_SELECT
)
961 if(key_fds
[i
].fd
> max_fd
)
962 max_fd
= key_fds
[i
].fd
;
963 #ifndef HAVE_NO_POSIX_SELECT
964 FD_SET(key_fds
[i
].fd
,&fds
);
969 #ifndef HAVE_NO_POSIX_SELECT
970 // if we have fd's without MP_FD_NO_SELECT flag, call select():
975 tv
.tv_usec
= (time
%1000)*1000;
981 if(select(max_fd
+1,&fds
,NULL
,NULL
,time_val
) < 0) {
984 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrSelect
,strerror(errno
));
993 for(i
= last_loop
+ 1 ; i
!= last_loop
; i
++) {
995 // This is to check all fds in turn
996 if((unsigned int)i
>= num_key_fd
) {
999 last_loop
%= (num_key_fd
+1);
1002 #ifndef HAVE_NO_POSIX_SELECT
1003 // No input from this fd
1004 if(! (key_fds
[i
].flags
& MP_FD_NO_SELECT
) && ! FD_ISSET(key_fds
[i
].fd
,&fds
) && key_fds
[i
].fd
!= 0)
1007 if(key_fds
[i
].fd
== 0) { // stdin is handled by getch2
1008 code
= getch2(time
);
1010 code
= MP_INPUT_NOTHING
;
1014 code
= ((mp_key_func_t
)key_fds
[i
].read_func
)(key_fds
[i
].fd
);
1019 if(code
== MP_INPUT_ERROR
)
1020 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrOnKeyInFd
,key_fds
[i
].fd
);
1021 else if(code
== MP_INPUT_DEAD
) {
1022 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrDeadKeyOnFd
,key_fds
[i
].fd
);
1023 key_fds
[i
].flags
|= MP_FD_DEAD
;
1026 if (time
&& !did_sleep
)
1027 usec_sleep(time
* 1000);
1028 return MP_INPUT_NOTHING
;
1033 mp_input_read_keys(int time
,int paused
) {
1034 int code
= mp_input_read_key_code(time
);
1038 if(mp_input_key_cb
) {
1039 for( ; code
>= 0 ; code
= mp_input_read_key_code(0) ) {
1040 if(code
& MP_KEY_DOWN
) continue;
1041 code
&= ~(MP_KEY_DOWN
|MP_NO_REPEAT_KEY
);
1042 mp_input_key_cb(code
);
1047 for( ; code
>= 0 ; code
= mp_input_read_key_code(0) ) {
1049 if(code
& MP_KEY_DOWN
) {
1050 if(num_key_down
> MP_MAX_KEY_DOWN
) {
1051 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_Err2ManyKeyDowns
);
1054 code
&= ~MP_KEY_DOWN
;
1055 // Check if we don't already have this key as pushed
1056 for(j
= 0; j
< num_key_down
; j
++) {
1057 if(key_down
[j
] == code
)
1060 if(j
!= num_key_down
)
1062 key_down
[num_key_down
] = code
;
1064 last_key_down
= GetTimer();
1069 // Check if the key is in the down key, driver which can't send push event
1070 // send only release event
1071 for(j
= 0; j
< num_key_down
; j
++) {
1072 if(key_down
[j
] == code
)
1075 if(j
== num_key_down
) { // key was not in the down keys : add it
1076 if(num_key_down
> MP_MAX_KEY_DOWN
) {
1077 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_Err2ManyKeyDowns
);
1080 key_down
[num_key_down
] = code
;
1084 // We ignore key from last combination
1085 ret
= last_key_down
? mp_input_get_cmd_from_keys(num_key_down
,key_down
,paused
) : NULL
;
1087 if(j
+1 < num_key_down
)
1088 memmove(&key_down
[j
],&key_down
[j
+1],(num_key_down
-(j
+1))*sizeof(int));
1093 mp_cmd_free(ar_cmd
);
1100 // No input : autorepeat ?
1101 if(ar_rate
> 0 && ar_state
>=0 && num_key_down
> 0 && ! (key_down
[num_key_down
-1] & MP_NO_REPEAT_KEY
)) {
1102 unsigned int t
= GetTimer();
1103 // First time : wait delay
1104 if(ar_state
== 0 && (t
- last_key_down
) >= ar_delay
*1000) {
1105 ar_cmd
= mp_input_get_cmd_from_keys(num_key_down
,key_down
,paused
);
1112 return mp_cmd_clone(ar_cmd
);
1113 // Then send rate / sec event
1114 } else if(ar_state
== 1 && (t
-last_ar
) >= 1000000/ar_rate
) {
1116 return mp_cmd_clone(ar_cmd
);
1124 mp_input_read_cmds(int time
) {
1125 #ifndef HAVE_NO_POSIX_SELECT
1127 struct timeval tv
,*time_val
;
1129 int i
,n
= 0,max_fd
= 0,got_cmd
= 0;
1131 static int last_loop
= 0;
1136 #ifndef HAVE_NO_POSIX_SELECT
1139 for(i
= 0; (unsigned int)i
< num_cmd_fd
; i
++) {
1140 if( (cmd_fds
[i
].flags
& MP_FD_DEAD
) || (cmd_fds
[i
].flags
& MP_FD_EOF
) ) {
1141 mp_input_rm_cmd_fd(cmd_fds
[i
].fd
);
1144 } else if(cmd_fds
[i
].flags
& MP_FD_NO_SELECT
)
1146 if(cmd_fds
[i
].flags
& MP_FD_GOT_CMD
)
1148 if(cmd_fds
[i
].fd
> max_fd
)
1149 max_fd
= cmd_fds
[i
].fd
;
1150 #ifndef HAVE_NO_POSIX_SELECT
1151 FD_SET(cmd_fds
[i
].fd
,&fds
);
1159 #ifndef HAVE_NO_POSIX_SELECT
1161 tv
.tv_sec
=time
/1000;
1162 tv
.tv_usec
= (time
%1000)*1000;
1168 if((i
= select(max_fd
+1,&fds
,NULL
,NULL
,time_val
)) <= 0) {
1172 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrSelect
,strerror(errno
));
1181 for(i
= last_loop
+ 1; i
!= last_loop
; i
++) {
1184 if((unsigned int)i
>= num_cmd_fd
) {
1187 last_loop
%= (num_cmd_fd
+1);
1190 #ifndef HAVE_NO_POSIX_SELECT
1191 if( ! (cmd_fds
[i
].flags
& MP_FD_NO_SELECT
) && ! FD_ISSET(cmd_fds
[i
].fd
,&fds
) && ! (cmd_fds
[i
].flags
& MP_FD_GOT_CMD
) )
1195 r
= mp_input_read_cmd(&cmd_fds
[i
],&cmd
);
1197 if(r
== MP_INPUT_ERROR
)
1198 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrOnCmdFd
,cmd_fds
[i
].fd
);
1199 else if(r
== MP_INPUT_DEAD
)
1200 cmd_fds
[i
].flags
|= MP_FD_DEAD
;
1203 ret
= mp_input_parse_cmd(cmd
);
1216 mp_input_queue_cmd(mp_cmd_t
* cmd
) {
1217 if(cmd_queue_length
>= CMD_QUEUE_SIZE
)
1219 cmd_queue
[cmd_queue_end
] = cmd
;
1220 cmd_queue_end
= (cmd_queue_end
+ 1) % CMD_QUEUE_SIZE
;
1226 mp_input_get_queued_cmd(int peek_only
) {
1229 if(cmd_queue_length
== 0)
1232 ret
= cmd_queue
[cmd_queue_start
];
1236 cmd_queue_start
= (cmd_queue_start
+ 1) % CMD_QUEUE_SIZE
;
1243 * \param peek_only when set, the returned command stays in the queue.
1244 * Do not free the returned cmd whe you set this!
1247 mp_input_get_cmd(int time
, int paused
, int peek_only
) {
1248 mp_cmd_t
* ret
= NULL
;
1249 mp_cmd_filter_t
* cf
;
1254 ret
= mp_input_get_queued_cmd(peek_only
);
1257 ret
= mp_input_read_keys(time
,paused
);
1259 ret
= mp_input_read_cmds(time
);
1262 if(!ret
) return NULL
;
1264 for(cf
= cmd_filters
; cf
; cf
= cf
->next
) {
1265 if(cf
->filter(ret
,paused
,cf
->ctx
))
1269 if (!from_queue
&& peek_only
)
1270 mp_input_queue_cmd(ret
);
1276 mp_cmd_free(mp_cmd_t
* cmd
) {
1279 // assert(cmd != NULL);
1286 for(i
=0; i
< MP_CMD_MAX_ARGS
&& cmd
->args
[i
].type
!= -1; i
++) {
1287 if(cmd
->args
[i
].type
== MP_CMD_ARG_STRING
&& cmd
->args
[i
].v
.s
!= NULL
)
1288 free(cmd
->args
[i
].v
.s
);
1294 mp_cmd_clone(mp_cmd_t
* cmd
) {
1298 assert(cmd
!= NULL
);
1301 ret
= malloc(sizeof(mp_cmd_t
));
1302 memcpy(ret
,cmd
,sizeof(mp_cmd_t
));
1304 ret
->name
= strdup(cmd
->name
);
1305 for(i
= 0; i
< MP_CMD_MAX_ARGS
&& cmd
->args
[i
].type
!= -1; i
++) {
1306 if(cmd
->args
[i
].type
== MP_CMD_ARG_STRING
&& cmd
->args
[i
].v
.s
!= NULL
)
1307 ret
->args
[i
].v
.s
= strdup(cmd
->args
[i
].v
.s
);
1313 static char key_str
[12];
1316 mp_input_get_key_name(int key
) {
1319 for(i
= 0; key_names
[i
].name
!= NULL
; i
++) {
1320 if(key_names
[i
].key
== key
)
1321 return key_names
[i
].name
;
1325 snprintf(key_str
,12,"%c",(char)key
);
1329 // Print the hex key code
1330 snprintf(key_str
,12,"%#-8x",key
);
1336 mp_input_get_key_from_name(char* name
) {
1337 int i
,ret
= 0,len
= strlen(name
);
1338 if(len
== 1) { // Direct key code
1339 ret
= (unsigned char)name
[0];
1341 } else if(len
> 2 && strncasecmp("0x",name
,2) == 0)
1342 return strtol(name
,NULL
,16);
1344 for(i
= 0; key_names
[i
].name
!= NULL
; i
++) {
1345 if(strcasecmp(key_names
[i
].name
,name
) == 0)
1346 return key_names
[i
].key
;
1353 mp_input_get_input_from_name(char* name
,int* keys
) {
1359 for(end
= strchr(ptr
,'-') ; ptr
!= NULL
; end
= strchr(ptr
,'-')) {
1360 if(end
&& end
[1] != '\0') {
1365 keys
[n
] = mp_input_get_key_from_name(ptr
);
1370 if(end
&& end
[1] != '\0' && n
< MP_MAX_KEY_DOWN
)
1380 mp_input_bind_keys(int keys
[MP_MAX_KEY_DOWN
+1], char* cmd
) {
1382 mp_cmd_bind_t
* bind
= NULL
;
1385 assert(keys
!= NULL
);
1386 assert(cmd
!= NULL
);
1390 for(i
= 0; cmd_binds
[i
].cmd
!= NULL
; i
++) {
1391 for(j
= 0 ; cmd_binds
[i
].input
[j
] == keys
[j
] && keys
[j
] != 0 ; j
++)
1393 if(keys
[j
] == 0 && cmd_binds
[i
].input
[j
] == 0 ) {
1394 bind
= &cmd_binds
[i
];
1401 cmd_binds
= (mp_cmd_bind_t
*)realloc(cmd_binds
,(i
+2)*sizeof(mp_cmd_bind_t
));
1402 memset(&cmd_binds
[i
],0,2*sizeof(mp_cmd_bind_t
));
1403 bind
= &cmd_binds
[i
];
1407 bind
->cmd
= strdup(cmd
);
1408 memcpy(bind
->input
,keys
,(MP_MAX_KEY_DOWN
+1)*sizeof(int));
1412 mp_input_add_binds(mp_cmd_bind_t
* list
) {
1414 for(i
= 0 ; list
[i
].cmd
; i
++)
1415 mp_input_bind_keys(list
[i
].input
,list
[i
].cmd
);
1419 mp_input_free_binds(mp_cmd_bind_t
* binds
) {
1425 for(i
= 0; binds
[i
].cmd
!= NULL
; i
++)
1434 #define SPACE_CHAR " \n\r\t"
1437 mp_input_parse_config(char *file
) {
1439 int bs
= 0,r
,eof
= 0,comments
= 0;
1441 char buffer
[BS_MAX
];
1442 int n_binds
= 0, keys
[MP_MAX_KEY_DOWN
+1] = { 0 };
1444 fd
= open(file
,O_RDONLY
);
1447 mp_msg(MSGT_INPUT
,MSGL_V
,"Can't open input config file %s: %s\n",file
,strerror(errno
));
1451 mp_msg(MSGT_INPUT
,MSGL_V
,"Parsing input config file %s\n",file
);
1454 if(! eof
&& bs
< BS_MAX
-1) {
1456 r
= read(fd
,buffer
+bs
,BS_MAX
-1-bs
);
1460 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrReadingInputConfig
,file
,strerror(errno
));
1467 buffer
[bs
-1] = '\0';
1470 // Empty buffer : return
1472 mp_msg(MSGT_INPUT
,MSGL_V
,"Input config file %s parsed: %d binds\n",file
,n_binds
);
1480 for( ; iter
[0] != '\0' && iter
[0] != '\n' ; iter
++)
1482 if(iter
[0] == '\0') { // Buffer was full of comment
1489 memmove(buffer
,iter
,r
+1);
1496 // Find the wanted key
1498 // Jump beginning space
1499 for( ; iter
[0] != '\0' && strchr(SPACE_CHAR
,iter
[0]) != NULL
; iter
++)
1501 if(iter
[0] == '\0') { // Buffer was full of space char
1505 if(iter
[0] == '#') { // Comments
1509 // Find the end of the key code name
1510 for(end
= iter
; end
[0] != '\0' && strchr(SPACE_CHAR
,end
[0]) == NULL
; end
++)
1512 if(end
[0] == '\0') { // Key name doesn't fit in the buffer
1513 if(buffer
== iter
) {
1514 if(eof
&& (buffer
-iter
) == bs
)
1515 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrUnfinishedBinding
,iter
);
1517 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrBuffer2SmallForKeyName
,iter
);
1520 memmove(buffer
,iter
,end
-iter
);
1525 char name
[end
-iter
+1];
1526 strncpy(name
,iter
,end
-iter
);
1527 name
[end
-iter
] = '\0';
1528 if(! mp_input_get_input_from_name(name
,keys
)) {
1529 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrUnknownKey
,name
);
1534 if( bs
> (end
-buffer
))
1535 memmove(buffer
,end
,bs
- (end
-buffer
));
1538 } else { // Get the command
1539 while(iter
[0] == ' ' || iter
[0] == '\t') iter
++;
1541 if(iter
[0] == '\n' || iter
[0] == '\r') {
1543 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrNoCmdForKey
,mp_input_get_key_name(keys
[0]));
1544 for(i
= 1; keys
[i
] != 0 ; i
++)
1545 mp_msg(MSGT_INPUT
,MSGL_ERR
,"-%s",mp_input_get_key_name(keys
[i
]));
1546 mp_msg(MSGT_INPUT
,MSGL_ERR
,"\n");
1549 memmove(buffer
,iter
,bs
- (iter
-buffer
));
1550 bs
-= (iter
-buffer
);
1554 for(end
= iter
; end
[0] != '\n' && end
[0] != '\r' && end
[0] != '\0' ; end
++)
1556 if(end
[0] == '\0' && ! (eof
&& ((end
+1) - buffer
) == bs
)) {
1557 if(iter
== buffer
) {
1558 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrBuffer2SmallForCmd
,buffer
);
1562 memmove(buffer
,iter
,end
- iter
);
1567 char cmd
[end
-iter
+1];
1568 strncpy(cmd
,iter
,end
-iter
);
1569 cmd
[end
-iter
] = '\0';
1570 //printf("Set bind %d => %s\n",keys[0],cmd);
1571 mp_input_bind_keys(keys
,cmd
);
1576 if(bs
> (end
-buffer
))
1577 memmove(buffer
,end
,bs
-(end
-buffer
));
1579 buffer
[bs
-1] = '\0';
1583 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrWhyHere
);
1588 extern char *get_path(const char *filename
);
1591 mp_input_init(int use_gui
) {
1596 mp_input_add_binds(gui_def_cmd_binds
);
1599 file
= config_file
[0] != '/' ? get_path(config_file
) : config_file
;
1603 if( !mp_input_parse_config(file
)) {
1604 // free file if it was allocated by get_path(),
1605 // before it gets overwritten
1606 if( file
!= config_file
)
1610 // Try global conf dir
1611 file
= MPLAYER_CONFDIR
"/input.conf";
1612 if(! mp_input_parse_config(file
))
1613 mp_msg(MSGT_INPUT
,MSGL_V
,"Falling back on default (hardcoded) input config\n");
1617 // free file if it was allocated by get_path()
1618 if( file
!= config_file
)
1622 #ifdef HAVE_JOYSTICK
1624 int fd
= mp_input_joystick_init(js_dev
);
1626 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrCantInitJoystick
);
1628 mp_input_add_key_fd(fd
,1,mp_input_joystick_read
,(mp_close_func_t
)close
);
1634 int fd
= mp_input_lirc_init();
1636 mp_input_add_cmd_fd(fd
,0,mp_input_lirc_read
,mp_input_lirc_close
);
1642 int fd
= lircc_init("mplayer", NULL
);
1644 mp_input_add_cmd_fd(fd
,1,NULL
,(mp_close_func_t
)lircc_cleanup
);
1650 if(stat(in_file
,&st
))
1651 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrCantStatFile
,in_file
,strerror(errno
));
1653 in_file_fd
= open(in_file
,S_ISFIFO(st
.st_mode
) ? O_RDWR
: O_RDONLY
);
1655 mp_input_add_cmd_fd(in_file_fd
,1,NULL
,(mp_close_func_t
)close
);
1657 mp_msg(MSGT_INPUT
,MSGL_ERR
,MSGTR_INPUT_INPUT_ErrCantOpenFile
,in_file
,strerror(errno
));
1664 mp_input_uninit(void) {
1667 for(i
=0; i
< num_key_fd
; i
++) {
1668 if(key_fds
[i
].close_func
)
1669 key_fds
[i
].close_func(key_fds
[i
].fd
);
1672 for(i
=0; i
< num_cmd_fd
; i
++) {
1673 if(cmd_fds
[i
].close_func
)
1674 cmd_fds
[i
].close_func(cmd_fds
[i
].fd
);
1676 mp_input_free_binds(cmd_binds
);
1682 mp_input_register_options(m_config_t
* cfg
) {
1683 m_config_register_options(cfg
,mp_input_opts
);
1686 static int mp_input_print_key_list(m_option_t
* cfg
) {
1689 for(i
= 0; key_names
[i
].name
!= NULL
; i
++)
1690 printf("%s\n",key_names
[i
].name
);
1694 static int mp_input_print_cmd_list(m_option_t
* cfg
) {
1699 for(i
= 0; (cmd
= &mp_cmds
[i
])->name
!= NULL
; i
++) {
1700 printf("%-20.20s",cmd
->name
);
1701 for(j
= 0 ; j
< MP_CMD_MAX_ARGS
&& cmd
->args
[j
].type
!= -1 ; j
++) {
1702 switch(cmd
->args
[j
].type
) {
1703 case MP_CMD_ARG_INT
:
1706 case MP_CMD_ARG_FLOAT
:
1709 case MP_CMD_ARG_STRING
:
1715 if(j
+1 > cmd
->nargs
)
1716 printf(" [%s]",type
);
1726 mp_input_check_interrupt(int time
) {
1728 if((cmd
= mp_input_get_cmd(time
,0,1)) == NULL
)
1732 case MP_CMD_PLAY_TREE_STEP
:
1733 case MP_CMD_PLAY_TREE_UP_STEP
:
1734 case MP_CMD_PLAY_ALT_SRC_STEP
:
1735 // The cmd will be executed when we are back in the main loop
1738 // remove the cmd from the queue
1739 cmd
= mp_input_get_cmd(time
,0,0);