Merge svn changes up to r28087
[mplayer.git] / input / input.h
blob99fab98e7745f299dd747a6c8b75ab44b05b791c
1 #ifndef MPLAYER_INPUT_H
2 #define MPLAYER_INPUT_H
4 // All command IDs
5 typedef enum {
6 MP_CMD_SEEK,
7 MP_CMD_AUDIO_DELAY,
8 MP_CMD_QUIT,
9 MP_CMD_PAUSE,
10 MP_CMD_GRAB_FRAMES, // deprecated: was a no-op command for years
11 MP_CMD_PLAY_TREE_STEP,
12 MP_CMD_PLAY_TREE_UP_STEP,
13 MP_CMD_PLAY_ALT_SRC_STEP,
14 MP_CMD_SUB_DELAY,
15 MP_CMD_OSD,
16 MP_CMD_VOLUME,
17 MP_CMD_MIXER_USEMASTER,
18 MP_CMD_CONTRAST,
19 MP_CMD_BRIGHTNESS,
20 MP_CMD_HUE,
21 MP_CMD_SATURATION,
22 MP_CMD_FRAMEDROPPING,
23 MP_CMD_TV_STEP_CHANNEL,
24 MP_CMD_TV_STEP_NORM,
25 MP_CMD_TV_STEP_CHANNEL_LIST,
26 MP_CMD_VO_FULLSCREEN,
27 MP_CMD_SUB_POS,
28 MP_CMD_DVDNAV,
29 MP_CMD_SCREENSHOT,
30 MP_CMD_PANSCAN,
31 MP_CMD_MUTE,
32 MP_CMD_LOADFILE,
33 MP_CMD_LOADLIST,
34 MP_CMD_VF_CHANGE_RECTANGLE,
35 MP_CMD_GAMMA,
36 MP_CMD_SUB_VISIBILITY,
37 MP_CMD_VOBSUB_LANG, // deprecated: combined with SUB_SELECT
38 MP_CMD_MENU,
39 MP_CMD_SET_MENU,
40 MP_CMD_GET_TIME_LENGTH,
41 MP_CMD_GET_PERCENT_POS,
42 MP_CMD_SUB_STEP,
43 MP_CMD_TV_SET_CHANNEL,
44 MP_CMD_EDL_MARK,
45 MP_CMD_SUB_ALIGNMENT,
46 MP_CMD_TV_LAST_CHANNEL,
47 MP_CMD_OSD_SHOW_TEXT,
48 MP_CMD_TV_SET_FREQ,
49 MP_CMD_TV_SET_NORM,
50 MP_CMD_TV_SET_BRIGHTNESS,
51 MP_CMD_TV_SET_CONTRAST,
52 MP_CMD_TV_SET_HUE,
53 MP_CMD_TV_SET_SATURATION,
54 MP_CMD_GET_VO_FULLSCREEN,
55 MP_CMD_GET_SUB_VISIBILITY,
56 MP_CMD_SUB_FORCED_ONLY,
57 MP_CMD_VO_ONTOP,
58 MP_CMD_SUB_SELECT,
59 MP_CMD_VO_ROOTWIN,
60 MP_CMD_SWITCH_VSYNC,
61 MP_CMD_SWITCH_RATIO,
62 MP_CMD_FRAME_STEP,
63 MP_CMD_SPEED_INCR,
64 MP_CMD_SPEED_MULT,
65 MP_CMD_SPEED_SET,
66 MP_CMD_RUN,
67 MP_CMD_SUB_LOG,
68 MP_CMD_SWITCH_AUDIO,
69 MP_CMD_GET_TIME_POS,
70 MP_CMD_SUB_LOAD,
71 MP_CMD_SUB_REMOVE,
72 MP_CMD_KEYDOWN_EVENTS,
73 MP_CMD_VO_BORDER,
74 MP_CMD_SET_PROPERTY,
75 MP_CMD_GET_PROPERTY,
76 MP_CMD_OSD_SHOW_PROPERTY_TEXT,
77 MP_CMD_SEEK_CHAPTER,
78 MP_CMD_FILE_FILTER,
79 MP_CMD_GET_FILENAME,
80 MP_CMD_GET_VIDEO_CODEC,
81 MP_CMD_GET_VIDEO_BITRATE,
82 MP_CMD_GET_VIDEO_RESOLUTION,
83 MP_CMD_GET_AUDIO_CODEC,
84 MP_CMD_GET_AUDIO_BITRATE,
85 MP_CMD_GET_AUDIO_SAMPLES,
86 MP_CMD_GET_META_TITLE,
87 MP_CMD_GET_META_ARTIST,
88 MP_CMD_GET_META_ALBUM,
89 MP_CMD_GET_META_YEAR,
90 MP_CMD_GET_META_COMMENT,
91 MP_CMD_GET_META_TRACK,
92 MP_CMD_GET_META_GENRE,
93 MP_CMD_RADIO_STEP_CHANNEL,
94 MP_CMD_RADIO_SET_CHANNEL,
95 MP_CMD_RADIO_SET_FREQ,
96 MP_CMD_SET_MOUSE_POS,
97 MP_CMD_STEP_PROPERTY,
98 MP_CMD_RADIO_STEP_FREQ,
99 MP_CMD_TV_STEP_FREQ,
100 MP_CMD_LOOP,
101 MP_CMD_BALANCE,
102 MP_CMD_SUB_SCALE,
103 MP_CMD_TV_TELETEXT_ADD_DEC,
104 MP_CMD_TV_TELETEXT_GO_LINK,
105 MP_CMD_TV_START_SCAN,
106 MP_CMD_SUB_SOURCE,
107 MP_CMD_SUB_FILE,
108 MP_CMD_SUB_VOB,
109 MP_CMD_SUB_DEMUX,
110 MP_CMD_SWITCH_ANGLE,
111 MP_CMD_ASS_USE_MARGINS,
112 MP_CMD_SWITCH_TITLE,
113 MP_CMD_STOP,
115 /// DVDNAV commands
116 MP_CMD_DVDNAV_UP = 1000,
117 MP_CMD_DVDNAV_DOWN,
118 MP_CMD_DVDNAV_LEFT,
119 MP_CMD_DVDNAV_RIGHT,
120 MP_CMD_DVDNAV_MENU,
121 MP_CMD_DVDNAV_SELECT,
122 MP_CMD_DVDNAV_PREVMENU,
123 MP_CMD_DVDNAV_MOUSECLICK,
125 /// GUI commands
126 MP_CMD_GUI_EVENTS = 5000,
127 MP_CMD_GUI_LOADFILE,
128 MP_CMD_GUI_LOADSUBTITLE,
129 MP_CMD_GUI_ABOUT,
130 MP_CMD_GUI_PLAY,
131 MP_CMD_GUI_STOP,
132 MP_CMD_GUI_PLAYLIST,
133 MP_CMD_GUI_PREFERENCES,
134 MP_CMD_GUI_FULLSCREEN,
135 MP_CMD_GUI_SKINBROWSER,
137 /// DVB commands
138 MP_CMD_DVB_SET_CHANNEL = 5101,
140 /// Console commands
141 MP_CMD_CHELP = 7000,
142 MP_CMD_CEXIT,
143 MP_CMD_CHIDE,
144 } mp_command_type;
146 // The arg types
147 #define MP_CMD_ARG_INT 0
148 #define MP_CMD_ARG_FLOAT 1
149 #define MP_CMD_ARG_STRING 2
150 #define MP_CMD_ARG_VOID 3
152 #ifndef MP_CMD_MAX_ARGS
153 #define MP_CMD_MAX_ARGS 10
154 #endif
156 // Error codes for the drivers
158 // An error occurred but we can continue
159 #define MP_INPUT_ERROR -1
160 // A fatal error occurred, this driver should be removed
161 #define MP_INPUT_DEAD -2
162 // No input was available
163 #define MP_INPUT_NOTHING -3
164 //! Input will be available if you try again
165 #define MP_INPUT_RETRY -4
167 // For the key's drivers, if possible you can send key up and key down
168 // events. Key up is the default, to send a key down you must use the
169 // OR operator between the key code and MP_KEY_DOWN.
170 #define MP_KEY_DOWN (1<<29)
171 // Use this when the key shouldn't be auto-repeated (like mouse buttons)
172 #define MP_NO_REPEAT_KEY (1<<28)
174 #ifndef MP_MAX_KEY_DOWN
175 #define MP_MAX_KEY_DOWN 32
176 #endif
178 struct input_ctx;
180 typedef union mp_cmd_arg_value {
181 int i;
182 float f;
183 char* s;
184 void* v;
185 } mp_cmd_arg_value_t;
187 typedef struct mp_cmd_arg {
188 int type;
189 mp_cmd_arg_value_t v;
190 } mp_cmd_arg_t;
192 typedef struct mp_cmd {
193 int id;
194 char* name;
195 int nargs;
196 mp_cmd_arg_t args[MP_CMD_MAX_ARGS];
197 int pausing;
198 } mp_cmd_t;
201 // These typedefs are for the drivers. They are the functions used to retrieve
202 // the next key code or command.
204 // These functions should return the key code or one of the error codes
205 typedef int (*mp_key_func_t)(void *ctx, int fd);
206 // These functions should act like read but they must use our error code (if needed ;-)
207 typedef int (*mp_cmd_func_t)(int fd,char* dest,int size);
208 // These are used to close the driver
209 typedef void (*mp_close_func_t)(int fd);
211 // Set this to grab all incoming key codes
212 int (*mp_input_key_cb)(int code);
213 // Should return 1 if the command was processed
214 typedef int (*mp_input_cmd_filter)(mp_cmd_t* cmd, int paused, void* ctx);
216 // This function adds a new key driver.
217 // The first arg is a file descriptor (use a negative value if you don't use any fd)
218 // The second arg tells if we use select on the fd to know if something is available.
219 // The third arg is optional. If null a default function wich reads an int from the
220 // fd will be used.
221 // The last arg can be NULL if nothing is needed to close the driver. The close
222 // function can be used
223 int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select,
224 mp_cmd_func_t read_func, mp_close_func_t close_func);
226 // This removes a cmd driver, you usually don't need to use it.
227 void mp_input_rm_cmd_fd(struct input_ctx *ictx, int fd);
229 // The args are the same as for the key's drivers. If you don't use any valid fd you MUST
230 // give a read_func.
231 int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select,
232 mp_key_func_t read_func, mp_close_func_t close_func,
233 void *ctx);
235 // As for the cmd one you usually don't need this function.
236 void mp_input_rm_key_fd(struct input_ctx *ictx, int fd);
238 /// Get input key from its name.
239 int mp_input_get_key_from_name(const char *name);
241 // This function can be used to put a command in the system again. It's used by libmpdemux
242 // when it performs a blocking operation to resend the command it received to the main
243 // loop.
244 int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t* cmd);
246 // This function retrieves the next available command waiting no more than time msec.
247 // If pause is true, the next input will always return a pause command.
248 mp_cmd_t*
249 mp_input_get_cmd(struct input_ctx *ictx, int time, int paused, int peek_only);
251 mp_cmd_t*
252 mp_input_parse_cmd(char* str);
255 * Parse and queue commands separated by '\n'.
256 * @return count of commands new queued.
258 int mp_input_parse_and_queue_cmds(struct input_ctx *ictx, const char *str);
260 /// These filters allow you to process the command before MPlayer.
261 /// If a filter returns a true value mp_input_get_cmd will return NULL.
262 void
263 mp_input_add_cmd_filter(mp_input_cmd_filter, void* ctx);
265 // After getting a command from mp_input_get_cmd you need to free it using this
266 // function
267 void
268 mp_cmd_free(mp_cmd_t* cmd);
270 // This creates a copy of a command (used by the auto repeat stuff).
271 mp_cmd_t*
272 mp_cmd_clone(mp_cmd_t* cmd);
274 // Set current input section
275 void mp_input_set_section(struct input_ctx *ictx, char *name);
277 // Get current input section
278 char *mp_input_get_section(struct input_ctx *ictx);
280 // When you create a new driver you should add it in these 2 functions.
281 struct input_conf;
282 struct input_ctx *mp_input_init(struct input_conf *input_conf, int use_gui);
284 void mp_input_uninit(struct input_ctx *ictx);
286 struct m_config;
287 void mp_input_register_options(struct m_config *cfg);
289 // Interruptible usleep: (used by libmpdemux)
291 mp_input_check_interrupt(struct input_ctx *ictx, int time);
293 extern int async_quit_request;
295 #endif /* MPLAYER_INPUT_H */