gl_common: minor cleanup/refactor
[mplayer.git] / input / input.h
blobc5f694099076ab10c7c6b82d47cbb63521094b0b
1 /*
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.
19 #ifndef MPLAYER_INPUT_H
20 #define MPLAYER_INPUT_H
22 #include <stdbool.h>
24 // All command IDs
25 enum mp_command_type {
26 MP_CMD_SEEK,
27 MP_CMD_AUDIO_DELAY,
28 MP_CMD_QUIT,
29 MP_CMD_PAUSE,
30 MP_CMD_GRAB_FRAMES, // deprecated: was a no-op command for years
31 MP_CMD_PLAY_TREE_STEP,
32 MP_CMD_PLAY_TREE_UP_STEP,
33 MP_CMD_PLAY_ALT_SRC_STEP,
34 MP_CMD_SUB_DELAY,
35 MP_CMD_OSD,
36 MP_CMD_VOLUME,
37 MP_CMD_MIXER_USEMASTER,
38 MP_CMD_CONTRAST,
39 MP_CMD_BRIGHTNESS,
40 MP_CMD_HUE,
41 MP_CMD_SATURATION,
42 MP_CMD_FRAMEDROPPING,
43 MP_CMD_TV_STEP_CHANNEL,
44 MP_CMD_TV_STEP_NORM,
45 MP_CMD_TV_STEP_CHANNEL_LIST,
46 MP_CMD_CAPTURING,
47 MP_CMD_VO_FULLSCREEN,
48 MP_CMD_SUB_POS,
49 MP_CMD_DVDNAV,
50 MP_CMD_SCREENSHOT,
51 MP_CMD_PANSCAN,
52 MP_CMD_MUTE,
53 MP_CMD_LOADFILE,
54 MP_CMD_LOADLIST,
55 MP_CMD_VF_CHANGE_RECTANGLE,
56 MP_CMD_GAMMA,
57 MP_CMD_SUB_VISIBILITY,
58 MP_CMD_VOBSUB_LANG, // deprecated: combined with SUB_SELECT
59 MP_CMD_GET_TIME_LENGTH,
60 MP_CMD_GET_PERCENT_POS,
61 MP_CMD_SUB_STEP,
62 MP_CMD_TV_SET_CHANNEL,
63 MP_CMD_EDL_MARK,
64 MP_CMD_SUB_ALIGNMENT,
65 MP_CMD_TV_LAST_CHANNEL,
66 MP_CMD_OSD_SHOW_TEXT,
67 MP_CMD_TV_SET_FREQ,
68 MP_CMD_TV_SET_NORM,
69 MP_CMD_TV_SET_BRIGHTNESS,
70 MP_CMD_TV_SET_CONTRAST,
71 MP_CMD_TV_SET_HUE,
72 MP_CMD_TV_SET_SATURATION,
73 MP_CMD_GET_VO_FULLSCREEN,
74 MP_CMD_GET_SUB_VISIBILITY,
75 MP_CMD_SUB_FORCED_ONLY,
76 MP_CMD_VO_ONTOP,
77 MP_CMD_SUB_SELECT,
78 MP_CMD_VO_ROOTWIN,
79 MP_CMD_SWITCH_VSYNC,
80 MP_CMD_SWITCH_RATIO,
81 MP_CMD_FRAME_STEP,
82 MP_CMD_SPEED_INCR,
83 MP_CMD_SPEED_MULT,
84 MP_CMD_SPEED_SET,
85 MP_CMD_RUN,
86 MP_CMD_SUB_LOG,
87 MP_CMD_SWITCH_AUDIO,
88 MP_CMD_GET_TIME_POS,
89 MP_CMD_SUB_LOAD,
90 MP_CMD_SUB_REMOVE,
91 MP_CMD_KEYDOWN_EVENTS,
92 MP_CMD_VO_BORDER,
93 MP_CMD_SET_PROPERTY,
94 MP_CMD_SET_PROPERTY_OSD,
95 MP_CMD_GET_PROPERTY,
96 MP_CMD_OSD_SHOW_PROPERTY_TEXT,
97 MP_CMD_OSD_SHOW_PROGRESSION,
98 MP_CMD_SEEK_CHAPTER,
99 MP_CMD_GET_FILENAME,
100 MP_CMD_GET_VIDEO_CODEC,
101 MP_CMD_GET_VIDEO_BITRATE,
102 MP_CMD_GET_VIDEO_RESOLUTION,
103 MP_CMD_GET_AUDIO_CODEC,
104 MP_CMD_GET_AUDIO_BITRATE,
105 MP_CMD_GET_AUDIO_SAMPLES,
106 MP_CMD_GET_META_TITLE,
107 MP_CMD_GET_META_ARTIST,
108 MP_CMD_GET_META_ALBUM,
109 MP_CMD_GET_META_YEAR,
110 MP_CMD_GET_META_COMMENT,
111 MP_CMD_GET_META_TRACK,
112 MP_CMD_GET_META_GENRE,
113 MP_CMD_RADIO_STEP_CHANNEL,
114 MP_CMD_RADIO_SET_CHANNEL,
115 MP_CMD_RADIO_SET_FREQ,
116 MP_CMD_SET_MOUSE_POS,
117 MP_CMD_STEP_PROPERTY,
118 MP_CMD_STEP_PROPERTY_OSD,
119 MP_CMD_RADIO_STEP_FREQ,
120 MP_CMD_TV_STEP_FREQ,
121 MP_CMD_LOOP,
122 MP_CMD_BALANCE,
123 MP_CMD_SUB_SCALE,
124 MP_CMD_TV_TELETEXT_ADD_DEC,
125 MP_CMD_TV_TELETEXT_GO_LINK,
126 MP_CMD_TV_START_SCAN,
127 MP_CMD_SUB_SOURCE,
128 MP_CMD_SUB_FILE,
129 MP_CMD_SUB_VOB,
130 MP_CMD_SUB_DEMUX,
131 MP_CMD_SWITCH_ANGLE,
132 MP_CMD_ASS_USE_MARGINS,
133 MP_CMD_SWITCH_TITLE,
134 MP_CMD_STOP,
136 /// DVDNAV commands
137 MP_CMD_DVDNAV_UP = 1000,
138 MP_CMD_DVDNAV_DOWN,
139 MP_CMD_DVDNAV_LEFT,
140 MP_CMD_DVDNAV_RIGHT,
141 MP_CMD_DVDNAV_MENU,
142 MP_CMD_DVDNAV_SELECT,
143 MP_CMD_DVDNAV_PREVMENU,
144 MP_CMD_DVDNAV_MOUSECLICK,
146 /// DVB commands
147 MP_CMD_DVB_SET_CHANNEL = 5101,
149 /// Audio Filter commands
150 MP_CMD_AF_SWITCH,
151 MP_CMD_AF_ADD,
152 MP_CMD_AF_DEL,
153 MP_CMD_AF_CLR,
154 MP_CMD_AF_CMDLINE,
157 // The arg types
158 #define MP_CMD_ARG_INT 1
159 #define MP_CMD_ARG_FLOAT 2
160 #define MP_CMD_ARG_STRING 3
162 #define MP_CMD_MAX_ARGS 10
164 // Error codes for the drivers
166 // An error occurred but we can continue
167 #define MP_INPUT_ERROR -1
168 // A fatal error occurred, this driver should be removed
169 #define MP_INPUT_DEAD -2
170 // No input was available
171 #define MP_INPUT_NOTHING -3
172 //! Input will be available if you try again
173 #define MP_INPUT_RETRY -4
174 // Key FIFO was full - release events may be lost, zero button-down status
175 #define MP_INPUT_RELEASE_ALL -5
178 struct input_ctx;
180 struct mp_cmd_arg {
181 int type;
182 bool optional;
183 union {
184 int i;
185 float f;
186 char *s;
187 } v;
190 typedef struct mp_cmd {
191 int id;
192 char *name;
193 struct mp_cmd_arg args[MP_CMD_MAX_ARGS];
194 int nargs;
195 int pausing;
196 struct mp_cmd *queue_prev;
197 struct mp_cmd *queue_next;
198 } mp_cmd_t;
201 /* Add a new command input source.
202 * "fd" is a file descriptor (use a negative value if you don't use any fd)
203 * "select" tells whether to use select() on the fd to determine when to
204 * try reading.
205 * "read_func" is optional. If NULL a default function which reads data
206 * directly from the fd will be used. It must return either text data
207 * or one of the MP_INPUT error codes above.
208 * "close_func" will be called when closing. Can be NULL. Its return value
209 * is ignored (it's only there to allow using standard close() as the func).
211 int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select,
212 int read_func(int fd, char *dest, int size),
213 int close_func(int fd));
215 // This removes a cmd driver, you usually don't need to use it.
216 void mp_input_rm_cmd_fd(struct input_ctx *ictx, int fd);
218 /* The args are similar to the cmd version above, except you must give
219 * a read_func, and it should return key codes (ASCII plus keycodes.h).
221 int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select,
222 int read_func(void *ctx, int fd),
223 int close_func(int fd), void *ctx);
225 // Feed a keypress (alternative to being returned from read_func above)
226 void mp_input_feed_key(struct input_ctx *ictx, int code);
228 // As for the cmd one you usually don't need this function.
229 void mp_input_rm_key_fd(struct input_ctx *ictx, int fd);
231 // Get input key from its name.
232 int mp_input_get_key_from_name(const char *name);
234 // Add a command to the command queue.
235 int mp_input_queue_cmd(struct input_ctx *ictx, struct mp_cmd *cmd);
237 /* Return next available command, or sleep up to "time" ms if none is
238 * available. If "peek_only" is true return a reference to the command
239 * but leave it queued.
241 struct mp_cmd *mp_input_get_cmd(struct input_ctx *ictx, int time,
242 int peek_only);
244 /* Parse text and return corresponding struct mp_cmd. */
245 struct mp_cmd *mp_input_parse_cmd(char *str);
248 * Parse and queue commands separated by '\n'.
249 * Return number of commands queued.
251 int mp_input_parse_and_queue_cmds(struct input_ctx *ictx, const char *str);
253 // After getting a command from mp_input_get_cmd you need to free it using this
254 // function
255 void mp_cmd_free(struct mp_cmd *cmd);
257 // This creates a copy of a command (used by the auto repeat stuff).
258 struct mp_cmd *mp_cmd_clone(struct mp_cmd *cmd);
260 // Set current input section
261 void mp_input_set_section(struct input_ctx *ictx, char *name);
263 // Get current input section
264 char *mp_input_get_section(struct input_ctx *ictx);
266 // Initialize the input system
267 struct input_conf;
268 struct input_ctx *mp_input_init(struct input_conf *input_conf);
270 void mp_input_uninit(struct input_ctx *ictx);
272 struct m_config;
273 void mp_input_register_options(struct m_config *cfg);
275 // Wake up sleeping input loop from another thread.
276 void mp_input_wakeup(struct input_ctx *ictx);
278 // Interruptible usleep: (used by libmpdemux)
279 int mp_input_check_interrupt(struct input_ctx *ictx, int time);
281 extern int async_quit_request;
283 #endif /* MPLAYER_INPUT_H */