2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/types.h>
39 #include "osdep/keycodes.h"
40 #include "osdep/timer.h"
41 #include "libavutil/avstring.h"
56 #include <lirc/lircc.h>
61 typedef struct mp_cmd_bind
{
62 int input
[MP_MAX_KEY_DOWN
+1];
66 typedef struct mp_key_name
{
71 /// This array defines all known commands.
72 /// The first field is an id used to recognize the command without too many strcmp.
73 /// The second is obviously the command name.
74 /// The third is the minimum number of arguments this command needs.
75 /// Then comes the definition of each argument, terminated with an arg of type -1.
76 /// A command can take a maximum of MP_CMD_MAX_ARGS-1 arguments (-1 because of
77 /// the last one) which is actually 9.
79 /// For the args, the first field is the type (actually int, float or string), the second
80 /// is the default value wich is used for optional arguments
82 static const mp_cmd_t mp_cmds
[] = {
84 { MP_CMD_RADIO_STEP_CHANNEL
, "radio_step_channel", 1, { { MP_CMD_ARG_INT
,{0}}, {-1,{0}} }},
85 { MP_CMD_RADIO_SET_CHANNEL
, "radio_set_channel", 1, { { MP_CMD_ARG_STRING
, {0}}, {-1,{0}} }},
86 { MP_CMD_RADIO_SET_FREQ
, "radio_set_freq", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
87 { MP_CMD_RADIO_STEP_FREQ
, "radio_step_freq", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
89 { MP_CMD_SEEK
, "seek", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
90 { MP_CMD_EDL_MARK
, "edl_mark", 0, { {-1,{0}} } },
91 { MP_CMD_AUDIO_DELAY
, "audio_delay", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
92 { MP_CMD_SPEED_INCR
, "speed_incr", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
93 { MP_CMD_SPEED_MULT
, "speed_mult", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
94 { MP_CMD_SPEED_SET
, "speed_set", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
95 { MP_CMD_QUIT
, "quit", 0, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
96 { MP_CMD_STOP
, "stop", 0, { {-1,{0}} } },
97 { MP_CMD_PAUSE
, "pause", 0, { {-1,{0}} } },
98 { MP_CMD_FRAME_STEP
, "frame_step", 0, { {-1,{0}} } },
99 { MP_CMD_PLAY_TREE_STEP
, "pt_step",1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
100 { MP_CMD_PLAY_TREE_UP_STEP
, "pt_up_step",1, { { MP_CMD_ARG_INT
,{0} }, { MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
101 { MP_CMD_PLAY_ALT_SRC_STEP
, "alt_src_step",1, { { MP_CMD_ARG_INT
,{0} }, {-1,{0}} } },
102 { MP_CMD_LOOP
, "loop", 1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
103 { MP_CMD_SUB_DELAY
, "sub_delay",1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
104 { MP_CMD_SUB_STEP
, "sub_step",1, { { MP_CMD_ARG_INT
,{0} }, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
105 { MP_CMD_OSD
, "osd",0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
106 { 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}} } },
107 { 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}} } },
108 { MP_CMD_OSD_SHOW_PROGRESSION
, "osd_show_progression", 0, { {-1,{0}} } },
109 { MP_CMD_VOLUME
, "volume", 1, { { MP_CMD_ARG_FLOAT
,{0} }, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
110 { MP_CMD_BALANCE
, "balance", 1, { { MP_CMD_ARG_FLOAT
,{0} }, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
111 { MP_CMD_MIXER_USEMASTER
, "use_master", 0, { {-1,{0}} } },
112 { MP_CMD_MUTE
, "mute", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
113 { MP_CMD_CONTRAST
, "contrast",1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
114 { MP_CMD_GAMMA
, "gamma", 1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
115 { MP_CMD_BRIGHTNESS
, "brightness",1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
116 { MP_CMD_HUE
, "hue",1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
117 { MP_CMD_SATURATION
, "saturation",1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
118 { MP_CMD_FRAMEDROPPING
, "frame_drop",0, { { MP_CMD_ARG_INT
,{-1} }, {-1,{0}} } },
119 { MP_CMD_SUB_POS
, "sub_pos", 1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
120 { MP_CMD_SUB_ALIGNMENT
, "sub_alignment",0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
121 { MP_CMD_SUB_VISIBILITY
, "sub_visibility", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
122 { MP_CMD_SUB_LOAD
, "sub_load", 1, { {MP_CMD_ARG_STRING
,{0}}, {-1,{0}} } },
123 { MP_CMD_SUB_REMOVE
, "sub_remove", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
124 { MP_CMD_SUB_SELECT
, "vobsub_lang", 0, { { MP_CMD_ARG_INT
,{-2} }, {-1,{0}} } }, // for compatibility
125 { MP_CMD_SUB_SELECT
, "sub_select", 0, { { MP_CMD_ARG_INT
,{-2} }, {-1,{0}} } },
126 { MP_CMD_SUB_SOURCE
, "sub_source", 0, { { MP_CMD_ARG_INT
,{-2} }, {-1,{0}} } },
127 { MP_CMD_SUB_VOB
, "sub_vob", 0, { { MP_CMD_ARG_INT
,{-2} }, {-1,{0}} } },
128 { MP_CMD_SUB_DEMUX
, "sub_demux", 0, { { MP_CMD_ARG_INT
,{-2} }, {-1,{0}} } },
129 { MP_CMD_SUB_FILE
, "sub_file", 0, { { MP_CMD_ARG_INT
,{-2} }, {-1,{0}} } },
130 { MP_CMD_SUB_LOG
, "sub_log", 0, { {-1,{0}} } },
131 { MP_CMD_SUB_SCALE
, "sub_scale",1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
133 { MP_CMD_ASS_USE_MARGINS
, "ass_use_margins", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
135 { MP_CMD_GET_PERCENT_POS
, "get_percent_pos", 0, { {-1,{0}} } },
136 { MP_CMD_GET_TIME_POS
, "get_time_pos", 0, { {-1,{0}} } },
137 { MP_CMD_GET_TIME_LENGTH
, "get_time_length", 0, { {-1,{0}} } },
138 { MP_CMD_GET_FILENAME
, "get_file_name", 0, { {-1,{0}} } },
139 { MP_CMD_GET_VIDEO_CODEC
, "get_video_codec", 0, { {-1,{0}} } },
140 { MP_CMD_GET_VIDEO_BITRATE
, "get_video_bitrate", 0, { {-1,{0}} } },
141 { MP_CMD_GET_VIDEO_RESOLUTION
, "get_video_resolution", 0, { {-1,{0}} } },
142 { MP_CMD_GET_AUDIO_CODEC
, "get_audio_codec", 0, { {-1,{0}} } },
143 { MP_CMD_GET_AUDIO_BITRATE
, "get_audio_bitrate", 0, { {-1,{0}} } },
144 { MP_CMD_GET_AUDIO_SAMPLES
, "get_audio_samples", 0, { {-1,{0}} } },
145 { MP_CMD_GET_META_TITLE
, "get_meta_title", 0, { {-1,{0}} } },
146 { MP_CMD_GET_META_ARTIST
, "get_meta_artist", 0, { {-1,{0}} } },
147 { MP_CMD_GET_META_ALBUM
, "get_meta_album", 0, { {-1,{0}} } },
148 { MP_CMD_GET_META_YEAR
, "get_meta_year", 0, { {-1,{0}} } },
149 { MP_CMD_GET_META_COMMENT
, "get_meta_comment", 0, { {-1,{0}} } },
150 { MP_CMD_GET_META_TRACK
, "get_meta_track", 0, { {-1,{0}} } },
151 { MP_CMD_GET_META_GENRE
, "get_meta_genre", 0, { {-1,{0}} } },
152 { MP_CMD_SWITCH_AUDIO
, "switch_audio", 0, { { MP_CMD_ARG_INT
,{-1} }, {-1,{0}} } },
153 { MP_CMD_SWITCH_ANGLE
, "switch_angle", 0, { { MP_CMD_ARG_INT
,{-1} }, {-1,{0}} } },
154 { MP_CMD_SWITCH_TITLE
, "switch_title", 0, { { MP_CMD_ARG_INT
,{-1} }, {-1,{0}} } },
156 { MP_CMD_TV_START_SCAN
, "tv_start_scan", 0, { {-1,{0}} }},
157 { MP_CMD_TV_STEP_CHANNEL
, "tv_step_channel", 1, { { MP_CMD_ARG_INT
,{0}}, {-1,{0}} }},
158 { MP_CMD_TV_STEP_NORM
, "tv_step_norm",0, { {-1,{0}} } },
159 { MP_CMD_TV_STEP_CHANNEL_LIST
, "tv_step_chanlist", 0, { {-1,{0}} } },
160 { MP_CMD_TV_SET_CHANNEL
, "tv_set_channel", 1, { { MP_CMD_ARG_STRING
, {0}}, {-1,{0}} }},
161 { MP_CMD_TV_LAST_CHANNEL
, "tv_last_channel", 0, { {-1,{0}} } },
162 { MP_CMD_TV_SET_FREQ
, "tv_set_freq", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
163 { MP_CMD_TV_STEP_FREQ
, "tv_step_freq", 1, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
164 { MP_CMD_TV_SET_NORM
, "tv_set_norm", 1, { {MP_CMD_ARG_STRING
,{0}}, {-1,{0}} } },
165 { MP_CMD_TV_SET_BRIGHTNESS
, "tv_set_brightness", 1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{1} }, {-1,{0}} }},
166 { MP_CMD_TV_SET_CONTRAST
, "tv_set_contrast", 1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{1} }, {-1,{0}} }},
167 { MP_CMD_TV_SET_HUE
, "tv_set_hue", 1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{1} }, {-1,{0}} }},
168 { MP_CMD_TV_SET_SATURATION
, "tv_set_saturation", 1, { { MP_CMD_ARG_INT
,{0}}, { MP_CMD_ARG_INT
,{1} }, {-1,{0}} }},
170 { MP_CMD_SUB_FORCED_ONLY
, "forced_subs_only", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
172 { MP_CMD_DVB_SET_CHANNEL
, "dvb_set_channel", 2, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}}}},
174 { MP_CMD_SWITCH_RATIO
, "switch_ratio", 0, { {MP_CMD_ARG_FLOAT
,{0}}, {-1,{0}} } },
175 { MP_CMD_VO_FULLSCREEN
, "vo_fullscreen", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
176 { MP_CMD_VO_ONTOP
, "vo_ontop", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
177 { MP_CMD_FILE_FILTER
, "file_filter", 1, { { MP_CMD_ARG_INT
, {0}}, {-1,{0}}}},
178 { MP_CMD_VO_ROOTWIN
, "vo_rootwin", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
179 { MP_CMD_VO_BORDER
, "vo_border", 0, { {MP_CMD_ARG_INT
,{-1}}, {-1,{0}} } },
180 { MP_CMD_SCREENSHOT
, "screenshot", 0, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
181 { MP_CMD_PANSCAN
, "panscan",1, { {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
182 { MP_CMD_SWITCH_VSYNC
, "switch_vsync", 0, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
183 { MP_CMD_LOADFILE
, "loadfile", 1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
184 { MP_CMD_LOADLIST
, "loadlist", 1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
185 { MP_CMD_RUN
, "run", 1, { {MP_CMD_ARG_STRING
,{0}}, {-1,{0}} } },
186 { MP_CMD_VF_CHANGE_RECTANGLE
, "change_rectangle", 2, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}}}},
187 { MP_CMD_TV_TELETEXT_ADD_DEC
, "teletext_add_dec", 1, { {MP_CMD_ARG_STRING
,{0}}, {-1,{0}} } },
188 { MP_CMD_TV_TELETEXT_GO_LINK
, "teletext_go_link", 1, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
191 { MP_CMD_DVDNAV
, "dvdnav", 1, { {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
195 { MP_CMD_MENU
, "menu",1, { {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
196 { MP_CMD_SET_MENU
, "set_menu",1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
197 { MP_CMD_CHELP
, "help", 0, { {-1,{0}} } },
198 { MP_CMD_CEXIT
, "exit", 0, { {-1,{0}} } },
199 { MP_CMD_CHIDE
, "hide", 0, { {MP_CMD_ARG_INT
,{3000}}, {-1,{0}} } },
202 { MP_CMD_GET_VO_FULLSCREEN
, "get_vo_fullscreen", 0, { {-1,{0}} } },
203 { MP_CMD_GET_SUB_VISIBILITY
, "get_sub_visibility", 0, { {-1,{0}} } },
204 { MP_CMD_KEYDOWN_EVENTS
, "key_down_event", 1, { {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
205 { MP_CMD_SET_PROPERTY
, "set_property", 2, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
206 { MP_CMD_SET_PROPERTY_OSD
, "set_property_osd", 2, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
207 { MP_CMD_GET_PROPERTY
, "get_property", 1, { {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
208 { MP_CMD_STEP_PROPERTY
, "step_property", 1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
209 { MP_CMD_STEP_PROPERTY_OSD
, "step_property_osd", 1, { {MP_CMD_ARG_STRING
, {0}}, {MP_CMD_ARG_FLOAT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
211 { MP_CMD_SEEK_CHAPTER
, "seek_chapter", 1, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
212 { MP_CMD_SET_MOUSE_POS
, "set_mouse_pos", 2, { {MP_CMD_ARG_INT
,{0}}, {MP_CMD_ARG_INT
,{0}}, {-1,{0}} } },
214 { MP_CMD_AF_SWITCH
, "af_switch", 1, { {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
215 { MP_CMD_AF_ADD
, "af_add", 1, { {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
216 { MP_CMD_AF_DEL
, "af_del", 1, { {MP_CMD_ARG_STRING
, {0}}, {-1,{0}} } },
217 { MP_CMD_AF_CLR
, "af_clr", 0, { {-1,{0}} } },
222 /// The names of the keys as used in input.conf
223 /// If you add some new keys, you also need to add them here
225 static const mp_key_name_t key_names
[] = {
228 { KEY_ENTER
, "ENTER" },
230 { KEY_CTRL
, "CTRL" },
231 { KEY_BACKSPACE
, "BS" },
232 { KEY_DELETE
, "DEL" },
233 { KEY_INSERT
, "INS" },
234 { KEY_HOME
, "HOME" },
236 { KEY_PAGE_UP
, "PGUP" },
237 { KEY_PAGE_DOWN
, "PGDWN" },
239 { KEY_RIGHT
, "RIGHT" },
240 { KEY_LEFT
, "LEFT" },
241 { KEY_DOWN
, "DOWN" },
265 { KEY_KPDEL
, "KP_DEL" },
266 { KEY_KPDEC
, "KP_DEC" },
267 { KEY_KPINS
, "KP_INS" },
268 { KEY_KPENTER
, "KP_ENTER" },
269 { MOUSE_BTN0
, "MOUSE_BTN0" },
270 { MOUSE_BTN1
, "MOUSE_BTN1" },
271 { MOUSE_BTN2
, "MOUSE_BTN2" },
272 { MOUSE_BTN3
, "MOUSE_BTN3" },
273 { MOUSE_BTN4
, "MOUSE_BTN4" },
274 { MOUSE_BTN5
, "MOUSE_BTN5" },
275 { MOUSE_BTN6
, "MOUSE_BTN6" },
276 { MOUSE_BTN7
, "MOUSE_BTN7" },
277 { MOUSE_BTN8
, "MOUSE_BTN8" },
278 { MOUSE_BTN9
, "MOUSE_BTN9" },
279 { MOUSE_BTN0_DBL
, "MOUSE_BTN0_DBL" },
280 { MOUSE_BTN1_DBL
, "MOUSE_BTN1_DBL" },
281 { MOUSE_BTN2_DBL
, "MOUSE_BTN2_DBL" },
282 { MOUSE_BTN3_DBL
, "MOUSE_BTN3_DBL" },
283 { MOUSE_BTN4_DBL
, "MOUSE_BTN4_DBL" },
284 { MOUSE_BTN5_DBL
, "MOUSE_BTN5_DBL" },
285 { MOUSE_BTN6_DBL
, "MOUSE_BTN6_DBL" },
286 { MOUSE_BTN7_DBL
, "MOUSE_BTN7_DBL" },
287 { MOUSE_BTN8_DBL
, "MOUSE_BTN8_DBL" },
288 { MOUSE_BTN9_DBL
, "MOUSE_BTN9_DBL" },
289 { JOY_AXIS1_MINUS
, "JOY_UP" },
290 { JOY_AXIS1_PLUS
, "JOY_DOWN" },
291 { JOY_AXIS0_MINUS
, "JOY_LEFT" },
292 { JOY_AXIS0_PLUS
, "JOY_RIGHT" },
294 { JOY_AXIS0_PLUS
, "JOY_AXIS0_PLUS" },
295 { JOY_AXIS0_MINUS
, "JOY_AXIS0_MINUS" },
296 { JOY_AXIS1_PLUS
, "JOY_AXIS1_PLUS" },
297 { JOY_AXIS1_MINUS
, "JOY_AXIS1_MINUS" },
298 { JOY_AXIS2_PLUS
, "JOY_AXIS2_PLUS" },
299 { JOY_AXIS2_MINUS
, "JOY_AXIS2_MINUS" },
300 { JOY_AXIS3_PLUS
, "JOY_AXIS3_PLUS" },
301 { JOY_AXIS3_MINUS
, "JOY_AXIS3_MINUS" },
302 { JOY_AXIS4_PLUS
, "JOY_AXIS4_PLUS" },
303 { JOY_AXIS4_MINUS
, "JOY_AXIS4_MINUS" },
304 { JOY_AXIS5_PLUS
, "JOY_AXIS5_PLUS" },
305 { JOY_AXIS5_MINUS
, "JOY_AXIS5_MINUS" },
306 { JOY_AXIS6_PLUS
, "JOY_AXIS6_PLUS" },
307 { JOY_AXIS6_MINUS
, "JOY_AXIS6_MINUS" },
308 { JOY_AXIS7_PLUS
, "JOY_AXIS7_PLUS" },
309 { JOY_AXIS7_MINUS
, "JOY_AXIS7_MINUS" },
310 { JOY_AXIS8_PLUS
, "JOY_AXIS8_PLUS" },
311 { JOY_AXIS8_MINUS
, "JOY_AXIS8_MINUS" },
312 { JOY_AXIS9_PLUS
, "JOY_AXIS9_PLUS" },
313 { JOY_AXIS9_MINUS
, "JOY_AXIS9_MINUS" },
315 { JOY_BTN0
, "JOY_BTN0" },
316 { JOY_BTN1
, "JOY_BTN1" },
317 { JOY_BTN2
, "JOY_BTN2" },
318 { JOY_BTN3
, "JOY_BTN3" },
319 { JOY_BTN4
, "JOY_BTN4" },
320 { JOY_BTN5
, "JOY_BTN5" },
321 { JOY_BTN6
, "JOY_BTN6" },
322 { JOY_BTN7
, "JOY_BTN7" },
323 { JOY_BTN8
, "JOY_BTN8" },
324 { JOY_BTN9
, "JOY_BTN9" },
326 { AR_PLAY
, "AR_PLAY" },
327 { AR_PLAY_HOLD
, "AR_PLAY_HOLD" },
328 { AR_NEXT
, "AR_NEXT" },
329 { AR_NEXT_HOLD
, "AR_NEXT_HOLD" },
330 { AR_PREV
, "AR_PREV" },
331 { AR_PREV_HOLD
, "AR_PREV_HOLD" },
332 { AR_MENU
, "AR_MENU" },
333 { AR_MENU_HOLD
, "AR_MENU_HOLD" },
334 { AR_VUP
, "AR_VUP" },
335 { AR_VDOWN
, "AR_VDOWN" },
337 { KEY_POWER
, "POWER" },
338 { KEY_MENU
, "MENU" },
339 { KEY_PLAY
, "PLAY" },
340 { KEY_PAUSE
, "PAUSE" },
341 { KEY_PLAYPAUSE
, "PLAYPAUSE" },
342 { KEY_STOP
, "STOP" },
343 { KEY_FORWARD
, "FORWARD" },
344 { KEY_REWIND
, "REWIND" },
345 { KEY_NEXT
, "NEXT" },
346 { KEY_PREV
, "PREV" },
347 { KEY_VOLUME_UP
, "VOLUME_UP" },
348 { KEY_VOLUME_DOWN
, "VOLUME_DOWN" },
349 { KEY_MUTE
, "MUTE" },
351 // These are kept for backward compatibility
352 { KEY_PAUSE
, "XF86_PAUSE" },
353 { KEY_STOP
, "XF86_STOP" },
354 { KEY_PREV
, "XF86_PREV" },
355 { KEY_NEXT
, "XF86_NEXT" },
357 { KEY_CLOSE_WIN
, "CLOSE_WIN" },
362 // This is the default binding. The content of input.conf overrides these.
363 // The first arg is a null terminated array of key codes.
364 // The second is the command
366 static const mp_cmd_bind_t def_cmd_binds
[] = {
368 { { MOUSE_BTN3
, 0 }, "seek 10" },
369 { { MOUSE_BTN4
, 0 }, "seek -10" },
370 { { MOUSE_BTN5
, 0 }, "volume 1" },
371 { { MOUSE_BTN6
, 0 }, "volume -1" },
374 { { KEY_KP8
, 0 }, "dvdnav up" }, // up
375 { { KEY_KP2
, 0 }, "dvdnav down" }, // down
376 { { KEY_KP4
, 0 }, "dvdnav left" }, // left
377 { { KEY_KP6
, 0 }, "dvdnav right" }, // right
378 { { KEY_KP5
, 0 }, "dvdnav menu" }, // menu
379 { { KEY_KPENTER
, 0 }, "dvdnav select" }, // select
380 { { MOUSE_BTN0
, 0 }, "dvdnav mouse" }, //select
381 { { KEY_KP7
, 0 }, "dvdnav prev" }, // previous menu
384 { { KEY_RIGHT
, 0 }, "seek 10" },
385 { { KEY_LEFT
, 0 }, "seek -10" },
386 { { KEY_UP
, 0 }, "seek 60" },
387 { { KEY_DOWN
, 0 }, "seek -60" },
388 { { KEY_PAGE_UP
, 0 }, "seek 600" },
389 { { KEY_PAGE_DOWN
, 0 }, "seek -600" },
390 { { '+', 0 }, "audio_delay 0.100" },
391 { { '-', 0 }, "audio_delay -0.100" },
392 { { '[', 0 }, "speed_mult 0.9091" },
393 { { ']', 0 }, "speed_mult 1.1" },
394 { { '{', 0 }, "speed_mult 0.5" },
395 { { '}', 0 }, "speed_mult 2.0" },
396 { { KEY_BACKSPACE
, 0 }, "speed_set 1.0" },
397 { { 'q', 0 }, "quit" },
398 { { KEY_ESC
, 0 }, "quit" },
399 { { 'p', 0 }, "pause" },
400 { { ' ', 0 }, "pause" },
401 { { '.', 0 }, "frame_step" },
402 { { KEY_HOME
, 0 }, "pt_up_step 1" },
403 { { KEY_END
, 0 }, "pt_up_step -1" },
404 { { '>', 0 }, "pt_step 1" },
405 { { KEY_ENTER
, 0 }, "pt_step 1 1" },
406 { { '<', 0 }, "pt_step -1" },
407 { { KEY_INS
, 0 }, "alt_src_step 1" },
408 { { KEY_DEL
, 0 }, "alt_src_step -1" },
409 { { 'o', 0 }, "osd" },
410 { { 'I', 0 }, "osd_show_property_text \"${filename}\"" },
411 { { 'P', 0 }, "osd_show_progression" },
412 { { 'z', 0 }, "sub_delay -0.1" },
413 { { 'x', 0 }, "sub_delay +0.1" },
414 { { 'g', 0 }, "sub_step -1" },
415 { { 'y', 0 }, "sub_step +1" },
416 { { '9', 0 }, "volume -1" },
417 { { '/', 0 }, "volume -1" },
418 { { '0', 0 }, "volume 1" },
419 { { '*', 0 }, "volume 1" },
420 { { '(', 0 }, "balance -0.1" },
421 { { ')', 0 }, "balance 0.1" },
422 { { 'm', 0 }, "mute" },
423 { { '1', 0 }, "contrast -1" },
424 { { '2', 0 }, "contrast 1" },
425 { { '3', 0 }, "brightness -1" },
426 { { '4', 0 }, "brightness 1" },
427 { { '5', 0 }, "hue -1" },
428 { { '6', 0 }, "hue 1" },
429 { { '7', 0 }, "saturation -1" },
430 { { '8', 0 }, "saturation 1" },
431 { { 'd', 0 }, "frame_drop" },
432 { { 'D', 0 }, "step_property_osd deinterlace" },
433 { { 'c', 0 }, "step_property_osd yuv_colorspace" },
434 { { 'r', 0 }, "sub_pos -1" },
435 { { 't', 0 }, "sub_pos +1" },
436 { { 'a', 0 }, "sub_alignment" },
437 { { 'v', 0 }, "sub_visibility" },
438 { { 'j', 0 }, "sub_select" },
439 { { 'F', 0 }, "forced_subs_only" },
440 { { '#', 0 }, "switch_audio" },
441 { { '_', 0 }, "step_property switch_video" },
442 { { KEY_TAB
, 0 }, "step_property switch_program" },
443 { { 'i', 0 }, "edl_mark" },
445 { { 'h', 0 }, "tv_step_channel 1" },
446 { { 'k', 0 }, "tv_step_channel -1" },
447 { { 'n', 0 }, "tv_step_norm" },
448 { { 'u', 0 }, "tv_step_chanlist" },
450 { { 'X', 0 }, "step_property teletext_mode 1" },
451 { { 'W', 0 }, "step_property teletext_page 1" },
452 { { 'Q', 0 }, "step_property teletext_page -1" },
453 #ifdef CONFIG_JOYSTICK
454 { { JOY_AXIS0_PLUS
, 0 }, "seek 10" },
455 { { JOY_AXIS0_MINUS
, 0 }, "seek -10" },
456 { { JOY_AXIS1_MINUS
, 0 }, "seek 60" },
457 { { JOY_AXIS1_PLUS
, 0 }, "seek -60" },
458 { { JOY_BTN0
, 0 }, "pause" },
459 { { JOY_BTN1
, 0 }, "osd" },
460 { { JOY_BTN2
, 0 }, "volume 1"},
461 { { JOY_BTN3
, 0 }, "volume -1"},
463 #ifdef CONFIG_APPLE_REMOTE
464 { { AR_PLAY
, 0}, "pause" },
465 { { AR_PLAY_HOLD
, 0}, "quit" },
466 { { AR_NEXT
, 0 }, "seek 30" },
467 { { AR_NEXT_HOLD
, 0 }, "seek 120" },
468 { { AR_PREV
, 0 }, "seek -10" },
469 { { AR_PREV_HOLD
, 0 }, "seek -120" },
470 { { AR_MENU
, 0 }, "osd" },
471 { { AR_MENU_HOLD
, 0 }, "mute" },
472 { { AR_VUP
, 0 }, "volume 1"},
473 { { AR_VDOWN
, 0 }, "volume -1"},
475 { { 'T', 0 }, "vo_ontop" },
476 { { 'f', 0 }, "vo_fullscreen" },
477 { { 's', 0 }, "screenshot 0" },
478 { { 'S', 0 }, "screenshot 1" },
479 { { 'w', 0 }, "panscan -0.1" },
480 { { 'e', 0 }, "panscan +0.1" },
482 { { KEY_POWER
, 0 }, "quit" },
483 { { KEY_MENU
, 0 }, "osd" },
484 { { KEY_PLAY
, 0 }, "pause" },
485 { { KEY_PAUSE
, 0 }, "pause" },
486 { { KEY_PLAYPAUSE
, 0 }, "pause" },
487 { { KEY_STOP
, 0 }, "quit" },
488 { { KEY_FORWARD
, 0 }, "seek 60" },
489 { { KEY_REWIND
, 0 }, "seek -60" },
490 { { KEY_NEXT
, 0 }, "pt_step 1" },
491 { { KEY_PREV
, 0 }, "pt_step -1" },
492 { { KEY_VOLUME_UP
, 0 }, "volume 1" },
493 { { KEY_VOLUME_DOWN
, 0 }, "volume -1" },
494 { { KEY_MUTE
, 0 }, "mute" },
496 { { KEY_CLOSE_WIN
, 0 }, "quit" },
498 { { '!', 0 }, "seek_chapter -1" },
499 { { '@', 0 }, "seek_chapter 1" },
500 { { 'A', 0 }, "switch_angle 1" },
501 { { 'U', 0 }, "stop" },
507 #ifndef MP_MAX_KEY_FD
508 #define MP_MAX_KEY_FD 10
511 #ifndef MP_MAX_CMD_FD
512 #define MP_MAX_CMD_FD 10
515 #define CMD_QUEUE_SIZE 100
517 typedef struct mp_input_fd
{
523 mp_close_func_t close_func
;
528 unsigned got_cmd
: 1;
529 unsigned no_select
: 1;
530 // These fields are for the cmd fds.
535 typedef struct mp_cmd_filter mp_cmd_filter_t
;
537 struct mp_cmd_filter
{
538 mp_input_cmd_filter filter
;
540 mp_cmd_filter_t
* next
;
543 typedef struct mp_cmd_bind_section mp_cmd_bind_section_t
;
545 struct mp_cmd_bind_section
{
546 mp_cmd_bind_t
* cmd_binds
;
548 mp_cmd_bind_section_t
* next
;
555 unsigned int last_ar
;
557 unsigned int ar_delay
;
558 unsigned int ar_rate
;
560 // these are the keys currently down
561 int key_down
[MP_MAX_KEY_DOWN
];
562 unsigned int num_key_down
;
563 unsigned int last_key_down
;
565 bool default_bindings
;
566 // List of command binding sections
567 mp_cmd_bind_section_t
*cmd_bind_sections
;
568 // Name of currently used command section
570 // The command binds of current section
571 mp_cmd_bind_t
*cmd_binds
;
572 mp_cmd_bind_t
*cmd_binds_default
;
574 mp_input_fd_t key_fds
[MP_MAX_KEY_FD
];
575 unsigned int num_key_fd
;
577 mp_input_fd_t cmd_fds
[MP_MAX_CMD_FD
];
578 unsigned int num_cmd_fd
;
580 mp_cmd_t
*cmd_queue
[CMD_QUEUE_SIZE
];
581 unsigned int cmd_queue_length
, cmd_queue_start
, cmd_queue_end
;
585 static mp_cmd_filter_t
* cmd_filters
= NULL
;
587 // Callback to allow the menu filter to grab the incoming keys
588 int (*mp_input_key_cb
)(int code
) = NULL
;
590 int async_quit_request
;
592 static int print_key_list(m_option_t
* cfg
);
593 static int print_cmd_list(m_option_t
* cfg
);
595 // Our command line options
596 static const m_option_t input_conf
[] = {
597 OPT_STRING("conf", input
.config_file
, CONF_GLOBAL
),
598 OPT_INT("ar-delay",input
.ar_delay
, CONF_GLOBAL
),
599 OPT_INT("ar-rate", input
.ar_rate
, CONF_GLOBAL
),
600 { "keylist", print_key_list
, CONF_TYPE_FUNC
, CONF_GLOBAL
, 0, 0, NULL
},
601 { "cmdlist", print_cmd_list
, CONF_TYPE_FUNC
, CONF_GLOBAL
, 0, 0, NULL
},
602 OPT_STRING("js-dev", input
.js_dev
, CONF_GLOBAL
),
603 OPT_STRING("ar-dev", input
.ar_dev
, CONF_GLOBAL
),
604 OPT_STRING("file", input
.in_file
, CONF_GLOBAL
),
605 OPT_FLAG_ON("default-bindings", input
.default_bindings
, CONF_GLOBAL
),
606 OPT_FLAG_OFF("nodefault-bindings", input
.default_bindings
, CONF_GLOBAL
),
607 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
610 static const m_option_t mp_input_opts
[] = {
611 { "input", &input_conf
, CONF_TYPE_SUBCONFIG
, 0, 0, 0, NULL
},
612 OPT_FLAG_OFF("nojoystick", input
.use_joystick
, CONF_GLOBAL
),
613 OPT_FLAG_ON("joystick", input
.use_joystick
, CONF_GLOBAL
),
614 OPT_FLAG_OFF("nolirc", input
.use_lirc
, CONF_GLOBAL
),
615 OPT_FLAG_ON("lirc", input
.use_lirc
, CONF_GLOBAL
),
616 OPT_FLAG_OFF("nolircc", input
.use_lircc
, CONF_GLOBAL
),
617 OPT_FLAG_ON("lircc", input
.use_lircc
, CONF_GLOBAL
),
618 OPT_FLAG_OFF("noar", input
.use_ar
, CONF_GLOBAL
),
619 OPT_FLAG_ON("ar", input
.use_ar
, CONF_GLOBAL
),
620 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
623 static int default_cmd_func(int fd
,char* buf
, int l
);
625 static char *get_key_name(int key
, char buffer
[12]);
628 int mp_input_add_cmd_fd(struct input_ctx
*ictx
, int fd
, int select
,
629 mp_cmd_func_t read_func
, mp_close_func_t close_func
)
631 if (ictx
->num_cmd_fd
== MP_MAX_CMD_FD
) {
632 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Too many command file descriptors, cannot register file descriptor %d.\n",fd
);
635 if (select
&& fd
< 0) {
636 mp_msg(MSGT_INPUT
, MSGL_ERR
, "Invalid fd %i in mp_input_add_cmd_fd", fd
);
640 ictx
->cmd_fds
[ictx
->num_cmd_fd
] = (struct mp_input_fd
){
642 .read_func
.cmd
= read_func
? read_func
: default_cmd_func
,
643 .close_func
= close_func
,
651 void mp_input_rm_cmd_fd(struct input_ctx
*ictx
, int fd
)
653 struct mp_input_fd
*cmd_fds
= ictx
->cmd_fds
;
656 for (i
= 0; i
< ictx
->num_cmd_fd
; i
++) {
657 if(cmd_fds
[i
].fd
== fd
)
660 if (i
== ictx
->num_cmd_fd
)
662 if(cmd_fds
[i
].close_func
)
663 cmd_fds
[i
].close_func(cmd_fds
[i
].fd
);
664 if(cmd_fds
[i
].buffer
)
665 talloc_free(cmd_fds
[i
].buffer
);
667 if (i
+ 1 < ictx
->num_cmd_fd
)
668 memmove(&cmd_fds
[i
], &cmd_fds
[i
+1],
669 (ictx
->num_cmd_fd
- i
- 1) * sizeof(mp_input_fd_t
));
673 void mp_input_rm_key_fd(struct input_ctx
*ictx
, int fd
)
675 struct mp_input_fd
*key_fds
= ictx
->key_fds
;
678 for (i
= 0; i
< ictx
->num_key_fd
; i
++) {
679 if(key_fds
[i
].fd
== fd
)
682 if (i
== ictx
->num_key_fd
)
684 if(key_fds
[i
].close_func
)
685 key_fds
[i
].close_func(key_fds
[i
].fd
);
687 if(i
+ 1 < ictx
->num_key_fd
)
688 memmove(&key_fds
[i
], &key_fds
[i
+1],
689 (ictx
->num_key_fd
- i
- 1) * sizeof(mp_input_fd_t
));
693 int mp_input_add_key_fd(struct input_ctx
*ictx
, int fd
, int select
,
694 mp_key_func_t read_func
, mp_close_func_t close_func
,
697 if (ictx
->num_key_fd
== MP_MAX_KEY_FD
) {
698 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Too many key file descriptors, cannot register file descriptor %d.\n",fd
);
701 if (select
&& fd
< 0) {
702 mp_msg(MSGT_INPUT
, MSGL_ERR
, "Invalid fd %i in mp_input_add_key_fd", fd
);
706 ictx
->key_fds
[ictx
->num_key_fd
] = (struct mp_input_fd
){
708 .read_func
.key
= read_func
,
709 .close_func
= close_func
,
710 .no_select
= !select
,
718 int mp_input_parse_and_queue_cmds(struct input_ctx
*ictx
, const char *str
)
722 while (*str
== '\n' || *str
== '\r' || *str
== ' ')
726 size_t len
= strcspn(str
, "\r\n");
727 char *cmdbuf
= talloc_size(NULL
, len
+1);
728 av_strlcpy(cmdbuf
, str
, len
+1);
729 cmd
= mp_input_parse_cmd(cmdbuf
);
731 mp_input_queue_cmd(ictx
, cmd
);
735 while (*str
== '\n' || *str
== '\r' || *str
== ' ')
743 mp_input_parse_cmd(char* str
) {
747 const mp_cmd_t
*cmd_def
;
753 // Ignore heading spaces.
754 while (str
[0] == ' ' || str
[0] == '\t')
757 if (strncmp(str
, "pausing ", 8) == 0) {
760 } else if (strncmp(str
, "pausing_keep ", 13) == 0) {
763 } else if (strncmp(str
, "pausing_toggle ", 15) == 0) {
766 } else if (strncmp(str
, "pausing_keep_force ", 19) == 0) {
771 for(ptr
= str
; ptr
[0] != '\0' && ptr
[0] != '\t' && ptr
[0] != ' ' ; ptr
++)
781 for(i
=0; mp_cmds
[i
].name
!= NULL
; i
++) {
782 if(strncasecmp(mp_cmds
[i
].name
,str
,l
) == 0)
786 if(mp_cmds
[i
].name
== NULL
)
789 cmd_def
= &mp_cmds
[i
];
791 mp_cmd_t
*cmd
= talloc_ptrtype(NULL
, cmd
);
794 .name
= talloc_strdup(cmd
, cmd_def
->name
),
800 for(i
=0; ptr
&& i
< MP_CMD_MAX_ARGS
; i
++) {
801 while(ptr
[0] != ' ' && ptr
[0] != '\t' && ptr
[0] != '\0') ptr
++;
802 if(ptr
[0] == '\0') break;
803 while(ptr
[0] == ' ' || ptr
[0] == '\t') ptr
++;
804 if(ptr
[0] == '\0' || ptr
[0] == '#') break;
805 cmd
->args
[i
].type
= cmd_def
->args
[i
].type
;
806 switch(cmd_def
->args
[i
].type
) {
809 cmd
->args
[i
].v
.i
= atoi(ptr
);
811 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Command %s: argument %d isn't an integer.\n",cmd_def
->name
,i
+1);
815 case MP_CMD_ARG_FLOAT
:
817 cmd
->args
[i
].v
.f
= atof(ptr
);
819 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Command %s: argument %d isn't a float.\n",cmd_def
->name
,i
+1);
823 case MP_CMD_ARG_STRING
: {
825 char* ptr2
= ptr
, *start
;
827 if(ptr
[0] == '\'' || ptr
[0] == '"') {
834 e
= strchr(ptr2
,term
);
836 if(e
<= ptr2
|| *(e
- 1) != '\\') break;
840 if(term
!= ' ' && (!e
|| e
[0] == '\0')) {
841 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Command %s: argument %d is unterminated.\n",cmd_def
->name
,i
+1);
844 } else if(!e
) e
= ptr
+strlen(ptr
);
847 for(e
= strchr(ptr2
,'\\') ; e
&& e
<start
+l
; e
= strchr(ptr2
,'\\')) {
848 memmove(e
,e
+1,strlen(e
));
852 cmd
->args
[i
].v
.s
= talloc_strndup(cmd
, start
, l
);
853 if(term
!= ' ') ptr
+= l
+2;
859 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Unknown argument %d\n",i
);
864 if(cmd_def
->nargs
> cmd
->nargs
) {
865 /* mp_msg(MSGT_INPUT,MSGL_ERR,"Got command '%s' but\n",str); */
866 mp_tmsg(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
);
871 for( ; i
< MP_CMD_MAX_ARGS
&& cmd_def
->args
[i
].type
!= -1 ; i
++) {
872 memcpy(&cmd
->args
[i
],&cmd_def
->args
[i
],sizeof(mp_cmd_arg_t
));
873 if(cmd_def
->args
[i
].type
== MP_CMD_ARG_STRING
&& cmd_def
->args
[i
].v
.s
!= NULL
)
874 cmd
->args
[i
].v
.s
= talloc_strdup(cmd
, cmd_def
->args
[i
].v
.s
);
877 if(i
< MP_CMD_MAX_ARGS
)
878 cmd
->args
[i
].type
= -1;
883 #define MP_CMD_MAX_SIZE 4096
885 static int read_cmd(mp_input_fd_t
* mp_fd
, char** ret
)
890 // Allocate the buffer if it doesn't exist
892 mp_fd
->buffer
= talloc_size(NULL
, MP_CMD_MAX_SIZE
);
894 mp_fd
->size
= MP_CMD_MAX_SIZE
;
897 // Get some data if needed/possible
898 while (!mp_fd
->got_cmd
&& !mp_fd
->eof
&& (mp_fd
->size
- mp_fd
->pos
> 1) ) {
899 int r
= mp_fd
->read_func
.cmd(mp_fd
->fd
, mp_fd
->buffer
+mp_fd
->pos
,
900 mp_fd
->size
- 1 - mp_fd
->pos
);
906 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Error while reading command file descriptor %d: %s\n",mp_fd
->fd
,strerror(errno
));
907 case MP_INPUT_NOTHING
:
926 mp_fd
->buffer
[mp_fd
->pos
] = '\0';
927 end
= strchr(mp_fd
->buffer
,'\r');
928 if (end
) *end
= '\n';
929 end
= strchr(mp_fd
->buffer
,'\n');
932 // If buffer is full we must drop all until the next \n
933 if(mp_fd
->size
- mp_fd
->pos
<= 1) {
934 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Command buffer of file descriptor %d is full: dropping content.\n",mp_fd
->fd
);
940 // We already have a cmd : set the got_cmd flag
946 l
= end
- mp_fd
->buffer
;
948 // Not dropping : put the cmd in ret
950 *ret
= talloc_strndup(NULL
, mp_fd
->buffer
, l
);
954 memmove(mp_fd
->buffer
, end
+1, mp_fd
->pos
);
960 return MP_INPUT_NOTHING
;
963 static int default_cmd_func(int fd
,char* buf
, int l
)
966 int r
= read(fd
,buf
,l
);
971 else if(errno
== EAGAIN
)
972 return MP_INPUT_NOTHING
;
973 return MP_INPUT_ERROR
;
983 mp_input_add_cmd_filter(mp_input_cmd_filter func
, void* ctx
) {
984 mp_cmd_filter_t
*filter
= talloc_ptrtype(NULL
, filter
);
986 filter
->filter
= func
;
988 filter
->next
= cmd_filters
;
989 cmd_filters
= filter
;
993 static char *find_bind_for_key(const mp_cmd_bind_t
* binds
, int n
,int* keys
)
997 if (n
<= 0) return NULL
;
998 for(j
= 0; binds
[j
].cmd
!= NULL
; j
++) {
1000 for(s
= 0; s
< n
&& binds
[j
].input
[s
] != 0; s
++) {
1001 if(binds
[j
].input
[s
] != keys
[s
]) {
1006 if(found
&& binds
[j
].input
[s
] == 0 && s
== n
)
1009 return binds
[j
].cmd
;
1012 static mp_cmd_bind_section_t
*get_bind_section(struct input_ctx
*ictx
,
1015 mp_cmd_bind_section_t
*bind_section
= ictx
->cmd_bind_sections
;
1017 if (section
==NULL
) section
="default";
1018 while (bind_section
) {
1019 if(strcmp(section
,bind_section
->section
)==0) return bind_section
;
1020 if(bind_section
->next
==NULL
) break;
1021 bind_section
=bind_section
->next
;
1024 bind_section
->next
= talloc_ptrtype(ictx
, bind_section
->next
);
1025 bind_section
=bind_section
->next
;
1027 ictx
->cmd_bind_sections
= talloc_ptrtype(ictx
, ictx
->cmd_bind_sections
);
1028 bind_section
= ictx
->cmd_bind_sections
;
1030 bind_section
->cmd_binds
=NULL
;
1031 bind_section
->section
= talloc_strdup(bind_section
, section
);
1032 bind_section
->next
=NULL
;
1033 return bind_section
;
1036 static mp_cmd_t
*get_cmd_from_keys(struct input_ctx
*ictx
, int n
, int *keys
)
1042 if (ictx
->cmd_binds
)
1043 cmd
= find_bind_for_key(ictx
->cmd_binds
, n
, keys
);
1044 if (ictx
->cmd_binds_default
&& cmd
== NULL
)
1045 cmd
= find_bind_for_key(ictx
->cmd_binds_default
, n
, keys
);
1046 if (ictx
->default_bindings
&& cmd
== NULL
)
1047 cmd
= find_bind_for_key(def_cmd_binds
,n
,keys
);
1050 mp_tmsg(MSGT_INPUT
,MSGL_WARN
,"No bind found for key '%s'.", get_key_name(keys
[0],
1054 for(s
=1; s
< n
; s
++)
1055 mp_msg(MSGT_INPUT
,MSGL_WARN
,"-%s", get_key_name(keys
[s
], key_buf
));
1057 mp_msg(MSGT_INPUT
,MSGL_WARN
," \n");
1060 if (strcmp(cmd
, "ignore") == 0) return NULL
;
1061 ret
= mp_input_parse_cmd(cmd
);
1063 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Invalid command for bound key %s",
1064 get_key_name(ictx
->key_down
[0], key_buf
));
1065 if (ictx
->num_key_down
> 1) {
1067 for(s
=1; s
< ictx
->num_key_down
; s
++)
1068 mp_msg(MSGT_INPUT
,MSGL_ERR
,"-%s", get_key_name(ictx
->key_down
[s
],
1071 mp_msg(MSGT_INPUT
,MSGL_ERR
," : %s \n",cmd
);
1077 static mp_cmd_t
* interpret_key(struct input_ctx
*ictx
, int code
)
1082 if(mp_input_key_cb
) {
1083 if (code
& MP_KEY_DOWN
)
1085 code
&= ~(MP_KEY_DOWN
|MP_NO_REPEAT_KEY
);
1086 if (mp_input_key_cb(code
))
1090 if(code
& MP_KEY_DOWN
) {
1091 if (ictx
->num_key_down
> MP_MAX_KEY_DOWN
) {
1092 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Too many key down events at the same time\n");
1095 code
&= ~MP_KEY_DOWN
;
1096 // Check if we don't already have this key as pushed
1097 for (j
= 0; j
< ictx
->num_key_down
; j
++) {
1098 if (ictx
->key_down
[j
] == code
)
1101 if (j
!= ictx
->num_key_down
)
1103 ictx
->key_down
[ictx
->num_key_down
] = code
;
1104 ictx
->num_key_down
++;
1105 ictx
->last_key_down
= GetTimer();
1110 // Check if the key is in the down key, driver which can't send push event
1111 // send only release event
1112 for (j
= 0; j
< ictx
->num_key_down
; j
++) {
1113 if (ictx
->key_down
[j
] == code
)
1116 if (j
== ictx
->num_key_down
) { // key was not in the down keys : add it
1117 if (ictx
->num_key_down
> MP_MAX_KEY_DOWN
) {
1118 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Too many key down events at the same time\n");
1121 ictx
->key_down
[ictx
->num_key_down
] = code
;
1122 ictx
->num_key_down
++;
1123 ictx
->last_key_down
= 1;
1125 // We ignore key from last combination
1126 ret
= ictx
->last_key_down
?
1127 get_cmd_from_keys(ictx
, ictx
->num_key_down
, ictx
->key_down
)
1130 if (j
+1 < ictx
->num_key_down
)
1131 memmove(&ictx
->key_down
[j
], &ictx
->key_down
[j
+1],
1132 (ictx
->num_key_down
-(j
+1))*sizeof(int));
1133 ictx
->num_key_down
--;
1134 ictx
->last_key_down
= 0;
1135 ictx
->ar_state
= -1;
1137 mp_cmd_free(ictx
->ar_cmd
);
1138 ictx
->ar_cmd
= NULL
;
1143 static mp_cmd_t
*check_autorepeat(struct input_ctx
*ictx
)
1145 // No input : autorepeat ?
1146 if (ictx
->ar_rate
> 0 && ictx
->ar_state
>=0 && ictx
->num_key_down
> 0
1147 && !(ictx
->key_down
[ictx
->num_key_down
-1] & MP_NO_REPEAT_KEY
)) {
1148 unsigned int t
= GetTimer();
1149 // First time : wait delay
1150 if (ictx
->ar_state
== 0
1151 && (t
- ictx
->last_key_down
) >= ictx
->ar_delay
*1000) {
1152 ictx
->ar_cmd
= get_cmd_from_keys(ictx
, ictx
->num_key_down
,
1154 if (!ictx
->ar_cmd
) {
1155 ictx
->ar_state
= -1;
1160 return mp_cmd_clone(ictx
->ar_cmd
);
1161 // Then send rate / sec event
1162 } else if (ictx
->ar_state
== 1
1163 && (t
-ictx
->last_ar
) >= 1000000 / ictx
->ar_rate
) {
1165 return mp_cmd_clone(ictx
->ar_cmd
);
1173 * \param time time to wait at most for an event in milliseconds
1175 static mp_cmd_t
*read_events(struct input_ctx
*ictx
, int time
)
1179 struct mp_input_fd
*key_fds
= ictx
->key_fds
;
1180 struct mp_input_fd
*cmd_fds
= ictx
->cmd_fds
;
1181 for (i
= 0; i
< ictx
->num_key_fd
; i
++)
1182 if (key_fds
[i
].dead
) {
1183 mp_input_rm_key_fd(ictx
, key_fds
[i
].fd
);
1186 for (i
= 0; i
< ictx
->num_cmd_fd
; i
++)
1187 if (cmd_fds
[i
].dead
|| cmd_fds
[i
].eof
) {
1188 mp_input_rm_cmd_fd(ictx
, cmd_fds
[i
].fd
);
1191 else if (cmd_fds
[i
].got_cmd
)
1193 #ifdef HAVE_POSIX_SELECT
1197 int max_fd
= 0, num_fd
= 0;
1198 for (i
= 0; i
< ictx
->num_key_fd
; i
++) {
1199 if (key_fds
[i
].no_select
)
1201 if (key_fds
[i
].fd
> max_fd
)
1202 max_fd
= key_fds
[i
].fd
;
1203 FD_SET(key_fds
[i
].fd
, &fds
);
1206 for (i
= 0; i
< ictx
->num_cmd_fd
; i
++) {
1207 if (cmd_fds
[i
].no_select
)
1209 if (cmd_fds
[i
].fd
> max_fd
)
1210 max_fd
= cmd_fds
[i
].fd
;
1211 FD_SET(cmd_fds
[i
].fd
, &fds
);
1215 struct timeval tv
, *time_val
;
1217 tv
.tv_sec
= time
/ 1000;
1218 tv
.tv_usec
= (time
% 1000) * 1000;
1223 if (select(max_fd
+ 1, &fds
, NULL
, NULL
, time_val
) < 0) {
1225 mp_tmsg(MSGT_INPUT
, MSGL_ERR
, "Select error: %s\n",
1232 if (!got_cmd
&& time
)
1233 usec_sleep(time
* 1000);
1237 for (i
= 0; i
< ictx
->num_key_fd
; i
++) {
1238 #ifdef HAVE_POSIX_SELECT
1239 if (!key_fds
[i
].no_select
&& !FD_ISSET(key_fds
[i
].fd
, &fds
))
1243 int code
= key_fds
[i
].read_func
.key(key_fds
[i
].ctx
, key_fds
[i
].fd
);
1245 mp_cmd_t
*ret
= interpret_key(ictx
, code
);
1249 else if (code
== MP_INPUT_ERROR
)
1250 mp_tmsg(MSGT_INPUT
, MSGL_ERR
, "Error on key input file descriptor %d\n",
1252 else if (code
== MP_INPUT_DEAD
) {
1253 mp_tmsg(MSGT_INPUT
, MSGL_ERR
, "Dead key input on file descriptor %d\n",
1255 key_fds
[i
].dead
= 1;
1258 mp_cmd_t
*autorepeat_cmd
= check_autorepeat(ictx
);
1260 return autorepeat_cmd
;
1262 for (i
= 0; i
< ictx
->num_cmd_fd
; i
++) {
1263 #ifdef HAVE_POSIX_SELECT
1264 if (!cmd_fds
[i
].no_select
&& !FD_ISSET(cmd_fds
[i
].fd
, &fds
) &&
1265 !cmd_fds
[i
].got_cmd
)
1269 int r
= read_cmd(&cmd_fds
[i
], &cmd
);
1271 mp_cmd_t
*ret
= mp_input_parse_cmd(cmd
);
1276 else if (r
== MP_INPUT_ERROR
)
1277 mp_tmsg(MSGT_INPUT
, MSGL_ERR
, "Error on command file descriptor %d\n",
1279 else if (r
== MP_INPUT_DEAD
)
1280 cmd_fds
[i
].dead
= 1;
1287 int mp_input_queue_cmd(struct input_ctx
*ictx
, mp_cmd_t
* cmd
)
1289 if (!cmd
|| ictx
->cmd_queue_length
>= CMD_QUEUE_SIZE
)
1291 ictx
->cmd_queue
[ictx
->cmd_queue_end
] = cmd
;
1292 ictx
->cmd_queue_end
= (ictx
->cmd_queue_end
+ 1) % CMD_QUEUE_SIZE
;
1293 ictx
->cmd_queue_length
++;
1297 static mp_cmd_t
*get_queued_cmd(struct input_ctx
*ictx
, int peek_only
)
1301 if (ictx
->cmd_queue_length
== 0)
1304 ret
= ictx
->cmd_queue
[ictx
->cmd_queue_start
];
1307 ictx
->cmd_queue_length
--;
1308 ictx
->cmd_queue_start
= (ictx
->cmd_queue_start
+ 1) % CMD_QUEUE_SIZE
;
1315 * \param peek_only when set, the returned command stays in the queue.
1316 * Do not free the returned cmd whe you set this!
1318 mp_cmd_t
*mp_input_get_cmd(struct input_ctx
*ictx
, int time
, int peek_only
)
1320 mp_cmd_t
* ret
= NULL
;
1321 mp_cmd_filter_t
* cf
;
1324 if (async_quit_request
)
1325 return mp_input_parse_cmd("quit 1");
1328 ret
= get_queued_cmd(ictx
, peek_only
);
1331 ret
= read_events(ictx
, time
);
1334 ret
= get_queued_cmd(ictx
, peek_only
);
1338 if(!ret
) return NULL
;
1340 for(cf
= cmd_filters
; cf
; cf
= cf
->next
) {
1341 if (cf
->filter(ret
, cf
->ctx
)) {
1342 if (peek_only
&& from_queue
)
1343 // The filter ate the cmd, so we remove it from queue
1344 ret
= get_queued_cmd(ictx
, 0);
1350 if (!from_queue
&& peek_only
)
1351 mp_input_queue_cmd(ictx
, ret
);
1357 mp_cmd_free(mp_cmd_t
* cmd
) {
1362 mp_cmd_clone(mp_cmd_t
* cmd
) {
1366 assert(cmd
!= NULL
);
1369 ret
= talloc_memdup(NULL
, cmd
, sizeof(mp_cmd_t
));
1370 ret
->name
= talloc_strdup(ret
, cmd
->name
);
1371 for(i
= 0; i
< MP_CMD_MAX_ARGS
&& cmd
->args
[i
].type
!= -1; i
++) {
1372 if(cmd
->args
[i
].type
== MP_CMD_ARG_STRING
&& cmd
->args
[i
].v
.s
!= NULL
)
1373 ret
->args
[i
].v
.s
= talloc_strdup(ret
, cmd
->args
[i
].v
.s
);
1379 static char *get_key_name(int key
, char buffer
[12])
1383 for(i
= 0; key_names
[i
].name
!= NULL
; i
++) {
1384 if(key_names
[i
].key
== key
)
1385 return key_names
[i
].name
;
1389 snprintf(buffer
, 12, "%c",(char)key
);
1393 // Print the hex key code
1394 snprintf(buffer
, 12, "%#-8x",key
);
1400 mp_input_get_key_from_name(const char *name
) {
1401 int i
,ret
= 0,len
= strlen(name
);
1402 if(len
== 1) { // Direct key code
1403 ret
= (unsigned char)name
[0];
1405 } else if(len
> 2 && strncasecmp("0x",name
,2) == 0)
1406 return strtol(name
,NULL
,16);
1408 for(i
= 0; key_names
[i
].name
!= NULL
; i
++) {
1409 if(strcasecmp(key_names
[i
].name
,name
) == 0)
1410 return key_names
[i
].key
;
1416 static int get_input_from_name(char* name
,int* keys
) {
1422 for(end
= strchr(ptr
,'-') ; ptr
!= NULL
; end
= strchr(ptr
,'-')) {
1423 if(end
&& end
[1] != '\0') {
1428 keys
[n
] = mp_input_get_key_from_name(ptr
);
1433 if(end
&& end
[1] != '\0' && n
< MP_MAX_KEY_DOWN
)
1443 #define SPACE_CHAR " \n\r\t"
1445 static void bind_keys(struct input_ctx
*ictx
,
1446 const int keys
[MP_MAX_KEY_DOWN
+1], char *cmd
)
1449 mp_cmd_bind_t
* bind
= NULL
;
1450 mp_cmd_bind_section_t
* bind_section
= NULL
;
1451 char *section
=NULL
, *p
;
1454 assert(keys
!= NULL
);
1455 assert(cmd
!= NULL
);
1458 if(*cmd
=='{' && (p
=strchr(cmd
,'}'))) {
1462 // Jump beginning space
1463 for( ; cmd
[0] != '\0' && strchr(SPACE_CHAR
,cmd
[0]) != NULL
; cmd
++)
1466 bind_section
= get_bind_section(ictx
, section
);
1468 if(bind_section
->cmd_binds
) {
1469 for(i
= 0; bind_section
->cmd_binds
[i
].cmd
!= NULL
; i
++) {
1470 for(j
= 0 ; bind_section
->cmd_binds
[i
].input
[j
] == keys
[j
] && keys
[j
] != 0 ; j
++)
1472 if(keys
[j
] == 0 && bind_section
->cmd_binds
[i
].input
[j
] == 0 ) {
1473 bind
= &bind_section
->cmd_binds
[i
];
1480 bind_section
->cmd_binds
= talloc_realloc(bind_section
,
1481 bind_section
->cmd_binds
,
1482 mp_cmd_bind_t
, i
+ 2);
1483 memset(&bind_section
->cmd_binds
[i
],0,2*sizeof(mp_cmd_bind_t
));
1484 bind
= &bind_section
->cmd_binds
[i
];
1487 talloc_free(bind
->cmd
);
1488 bind
->cmd
= talloc_strdup(bind_section
->cmd_binds
, cmd
);
1489 memcpy(bind
->input
,keys
,(MP_MAX_KEY_DOWN
+1)*sizeof(int));
1492 static void add_binds(struct input_ctx
*ictx
, const mp_cmd_bind_t
* list
)
1495 for(i
= 0 ; list
[i
].cmd
; i
++)
1496 bind_keys(ictx
, list
[i
].input
,list
[i
].cmd
);
1499 static int parse_config(struct input_ctx
*ictx
, char *file
)
1502 int bs
= 0,r
,eof
= 0,comments
= 0;
1504 char buffer
[BS_MAX
];
1505 int n_binds
= 0, keys
[MP_MAX_KEY_DOWN
+1] = { 0 };
1507 fd
= open(file
,O_RDONLY
);
1510 mp_msg(MSGT_INPUT
,MSGL_V
,"Can't open input config file %s: %s\n",file
,strerror(errno
));
1514 mp_msg(MSGT_INPUT
,MSGL_V
,"Parsing input config file %s\n",file
);
1517 if(! eof
&& bs
< BS_MAX
-1) {
1519 r
= read(fd
,buffer
+bs
,BS_MAX
-1-bs
);
1523 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Error while reading input config file %s: %s\n",file
,strerror(errno
));
1530 buffer
[bs
-1] = '\0';
1533 // Empty buffer : return
1535 mp_msg(MSGT_INPUT
,MSGL_V
,"Input config file %s parsed: %d binds\n",file
,n_binds
);
1543 for( ; iter
[0] != '\0' && iter
[0] != '\n' ; iter
++)
1545 if(iter
[0] == '\0') { // Buffer was full of comment
1551 memmove(buffer
,iter
,r
+1);
1557 // Find the wanted key
1559 // Jump beginning space
1560 for( ; iter
[0] != '\0' && strchr(SPACE_CHAR
,iter
[0]) != NULL
; iter
++)
1562 if(iter
[0] == '\0') { // Buffer was full of space char
1566 if(iter
[0] == '#') { // Comments
1570 // Find the end of the key code name
1571 for(end
= iter
; end
[0] != '\0' && strchr(SPACE_CHAR
,end
[0]) == NULL
; end
++)
1573 if(end
[0] == '\0') { // Key name doesn't fit in the buffer
1574 if(buffer
== iter
) {
1575 if(eof
&& (buffer
-iter
) == bs
)
1576 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Unfinished binding %s\n",iter
);
1578 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Buffer is too small for this key name: %s\n",iter
);
1581 memmove(buffer
,iter
,end
-iter
);
1586 char name
[end
-iter
+1];
1587 strncpy(name
,iter
,end
-iter
);
1588 name
[end
-iter
] = '\0';
1589 if (!get_input_from_name(name
,keys
)) {
1590 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Unknown key '%s'\n",name
);
1595 if( bs
> (end
-buffer
))
1596 memmove(buffer
,end
,bs
- (end
-buffer
));
1599 } else { // Get the command
1600 while(iter
[0] == ' ' || iter
[0] == '\t') iter
++;
1602 if(iter
[0] == '\n' || iter
[0] == '\r') {
1605 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"No command found for key %s", get_key_name(keys
[0], key_buf
));
1606 for(i
= 1; keys
[i
] != 0 ; i
++)
1607 mp_msg(MSGT_INPUT
,MSGL_ERR
,"-%s", get_key_name(keys
[i
], key_buf
));
1608 mp_msg(MSGT_INPUT
,MSGL_ERR
,"\n");
1611 memmove(buffer
,iter
,bs
- (iter
-buffer
));
1612 bs
-= (iter
-buffer
);
1616 for(end
= iter
; end
[0] != '\n' && end
[0] != '\r' && end
[0] != '\0' ; end
++)
1618 if(end
[0] == '\0' && ! (eof
&& ((end
+1) - buffer
) == bs
)) {
1619 if(iter
== buffer
) {
1620 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Buffer is too small for command %s\n",buffer
);
1624 memmove(buffer
,iter
,end
- iter
);
1629 char cmd
[end
-iter
+1];
1630 strncpy(cmd
,iter
,end
-iter
);
1631 cmd
[end
-iter
] = '\0';
1632 //printf("Set bind %d => %s\n",keys[0],cmd);
1633 bind_keys(ictx
, keys
,cmd
);
1638 if(bs
> (end
-buffer
))
1639 memmove(buffer
,end
,bs
-(end
-buffer
));
1641 buffer
[bs
-1] = '\0';
1645 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"What are we doing here?\n");
1647 mp_input_set_section(ictx
, NULL
);
1651 void mp_input_set_section(struct input_ctx
*ictx
, char *name
)
1653 mp_cmd_bind_section_t
* bind_section
= NULL
;
1655 ictx
->cmd_binds
= NULL
;
1656 ictx
->cmd_binds_default
= NULL
;
1658 talloc_free(ictx
->section
);
1660 ictx
->section
= talloc_strdup(ictx
, name
);
1662 ictx
->section
= talloc_strdup(ictx
, "default");
1663 if ((bind_section
= get_bind_section(ictx
, ictx
->section
)))
1664 ictx
->cmd_binds
= bind_section
->cmd_binds
;
1665 if (strcmp(ictx
->section
, "default") == 0)
1667 if ((bind_section
= get_bind_section(ictx
, NULL
)))
1668 ictx
->cmd_binds_default
= bind_section
->cmd_binds
;
1671 char *mp_input_get_section(struct input_ctx
*ictx
)
1673 return ictx
->section
;
1676 struct input_ctx
*mp_input_init(struct input_conf
*input_conf
)
1678 struct input_ctx
*ictx
= talloc_ptrtype(NULL
, ictx
);
1679 *ictx
= (struct input_ctx
){
1681 .ar_delay
= input_conf
->ar_delay
,
1682 .ar_rate
= input_conf
->ar_rate
,
1683 .default_bindings
= input_conf
->default_bindings
,
1687 char *config_file
= input_conf
->config_file
;
1688 file
= config_file
[0] != '/' ? get_path(config_file
) : config_file
;
1692 if (!parse_config(ictx
, file
)) {
1693 // free file if it was allocated by get_path(),
1694 // before it gets overwritten
1695 if( file
!= config_file
)
1699 // Try global conf dir
1700 file
= MPLAYER_CONFDIR
"/input.conf";
1701 if (!parse_config(ictx
, file
))
1702 mp_msg(MSGT_INPUT
,MSGL_V
,"Falling back on default (hardcoded) input config\n");
1706 // free file if it was allocated by get_path()
1707 if( file
!= config_file
)
1711 #ifdef CONFIG_JOYSTICK
1712 if (input_conf
->use_joystick
) {
1713 int fd
= mp_input_joystick_init(input_conf
->js_dev
);
1715 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Can't init input joystick\n");
1717 mp_input_add_key_fd(ictx
, fd
, 1, mp_input_joystick_read
,
1718 (mp_close_func_t
)close
,NULL
);
1723 if (input_conf
->use_lirc
) {
1724 int fd
= mp_input_lirc_init();
1726 mp_input_add_cmd_fd(ictx
, fd
, 0, mp_input_lirc_read
,
1727 mp_input_lirc_close
);
1732 if (input_conf
->use_lircc
) {
1733 int fd
= lircc_init("mplayer", NULL
);
1735 mp_input_add_cmd_fd(ictx
, fd
, 1, NULL
, (mp_close_func_t
)lircc_cleanup
);
1739 #ifdef CONFIG_APPLE_REMOTE
1740 if (input_conf
->use_ar
) {
1741 if(mp_input_ar_init() < 0)
1742 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Can't init Apple Remote.\n");
1744 mp_input_add_key_fd(ictx
, -1, 0, mp_input_ar_read
, mp_input_ar_close
,
1749 #ifdef CONFIG_APPLE_IR
1750 if (input_conf
->use_ar
) {
1751 int fd
= mp_input_appleir_init(input_conf
->ar_dev
);
1753 mp_tmsg(MSGT_INPUT
,MSGL_ERR
,"Can't init Apple Remote.\n");
1755 mp_input_add_key_fd(ictx
, fd
, 1, mp_input_appleir_read
,
1756 (mp_close_func_t
)close
, NULL
);
1760 if (input_conf
->in_file
) {
1762 int mode
= O_RDONLY
;
1763 // Use RDWR for FIFOs to ensure they stay open over multiple accesses.
1764 // Note that on Windows stat may fail for named pipes, but due to how the
1765 // API works, using RDONLY should be ok.
1766 if (stat(input_conf
->in_file
, &st
) == 0 && S_ISFIFO(st
.st_mode
))
1768 int in_file_fd
= open(input_conf
->in_file
, mode
);
1770 mp_input_add_cmd_fd(ictx
, in_file_fd
, 1, NULL
,
1771 (mp_close_func_t
)close
);
1773 mp_tmsg(MSGT_INPUT
, MSGL_ERR
, "Can't open %s: %s\n",
1774 input_conf
->in_file
, strerror(errno
));
1779 void mp_input_uninit(struct input_ctx
*ictx
)
1786 for (i
=0; i
< ictx
->num_key_fd
; i
++) {
1787 if (ictx
->key_fds
[i
].close_func
)
1788 ictx
->key_fds
[i
].close_func(ictx
->key_fds
[i
].fd
);
1791 for (i
= 0; i
< ictx
->num_cmd_fd
; i
++) {
1792 if (ictx
->cmd_fds
[i
].close_func
)
1793 ictx
->cmd_fds
[i
].close_func(ictx
->cmd_fds
[i
].fd
);
1799 mp_input_register_options(m_config_t
* cfg
) {
1800 m_config_register_options(cfg
,mp_input_opts
);
1803 static int print_key_list(m_option_t
* cfg
)
1807 for(i
= 0; key_names
[i
].name
!= NULL
; i
++)
1808 printf("%s\n",key_names
[i
].name
);
1812 static int print_cmd_list(m_option_t
* cfg
)
1814 const mp_cmd_t
*cmd
;
1818 for(i
= 0; (cmd
= &mp_cmds
[i
])->name
!= NULL
; i
++) {
1819 printf("%-20.20s",cmd
->name
);
1820 for(j
= 0 ; j
< MP_CMD_MAX_ARGS
&& cmd
->args
[j
].type
!= -1 ; j
++) {
1821 switch(cmd
->args
[j
].type
) {
1822 case MP_CMD_ARG_INT
:
1825 case MP_CMD_ARG_FLOAT
:
1828 case MP_CMD_ARG_STRING
:
1834 if(j
+1 > cmd
->nargs
)
1835 printf(" [%s]",type
);
1845 * \param time time to wait for an interruption in milliseconds
1847 int mp_input_check_interrupt(struct input_ctx
*ictx
, int time
)
1850 if ((cmd
= mp_input_get_cmd(ictx
, time
, 1)) == NULL
)
1854 case MP_CMD_PLAY_TREE_STEP
:
1855 case MP_CMD_PLAY_TREE_UP_STEP
:
1856 case MP_CMD_PLAY_ALT_SRC_STEP
:
1857 // The cmd will be executed when we are back in the main loop
1860 // remove the cmd from the queue
1861 cmd
= mp_input_get_cmd(ictx
, time
, 0);