mpv/input/input.c

1914 lines
58 KiB
C
Raw Normal View History

/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
2009-03-14 22:52:45 +01:00
#include <stdbool.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <ctype.h>
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
#include <assert.h>
#include "osdep/io.h"
#include "input.h"
#include "mp_fifo.h"
#include "keycodes.h"
#include "osdep/timer.h"
#include "libavutil/avstring.h"
#include "libavutil/common.h"
#include "mp_msg.h"
#include "m_config.h"
#include "m_option.h"
#include "path.h"
#include "talloc.h"
2008-04-30 17:57:02 +02:00
#include "options.h"
#include "bstr.h"
#include "stream/stream.h"
#include "joystick.h"
#ifdef CONFIG_LIRC
#include "lirc.h"
#endif
#ifdef CONFIG_LIRCC
#include <lirc/lircc.h>
#endif
#include "ar.h"
#ifdef CONFIG_COCOA
#include "osdep/cocoa_events.h"
#endif
#define MP_MAX_KEY_DOWN 32
struct cmd_bind {
2011-04-25 10:38:46 +02:00
int input[MP_MAX_KEY_DOWN + 1];
char *cmd;
};
struct key_name {
2011-04-25 10:38:46 +02:00
int key;
char *name;
};
/* This array defines all known commands.
* The first field is an id used to recognize the command.
* The second is the command name used in slave mode and input.conf.
* Then comes the definition of each argument, first mandatory arguments
* (ARG_INT, ARG_FLOAT, ARG_STRING) if any, then optional arguments
* (OARG_INT(default), etc) if any. The command will be given the default
* argument value if the user didn't give enough arguments to specify it.
* A command can take a maximum of MP_CMD_MAX_ARGS arguments (10).
*/
#define ARG_INT { .type = MP_CMD_ARG_INT }
#define OARG_INT(def) { .type = MP_CMD_ARG_INT, .optional = true, .v.i = def }
#define ARG_FLOAT { .type = MP_CMD_ARG_FLOAT }
#define OARG_FLOAT(def) { .type = MP_CMD_ARG_FLOAT, .optional = true, .v.f = def }
#define ARG_STRING { .type = MP_CMD_ARG_STRING }
#define OARG_STRING(def) { .type = MP_CMD_ARG_STRING, .optional = true, .v.s = def }
static const mp_cmd_t mp_cmds[] = {
#ifdef CONFIG_RADIO
{ MP_CMD_RADIO_STEP_CHANNEL, "radio_step_channel", { ARG_INT } },
{ MP_CMD_RADIO_SET_CHANNEL, "radio_set_channel", { ARG_STRING } },
{ MP_CMD_RADIO_SET_FREQ, "radio_set_freq", { ARG_FLOAT } },
{ MP_CMD_RADIO_STEP_FREQ, "radio_step_freq", {ARG_FLOAT } },
#endif
{ MP_CMD_SEEK, "seek", { ARG_FLOAT, OARG_INT(0), OARG_INT(0) } },
{ MP_CMD_EDL_MARK, "edl_mark", },
{ MP_CMD_AUDIO_DELAY, "audio_delay", { ARG_FLOAT, OARG_INT(0) } },
{ MP_CMD_SPEED_INCR, "speed_incr", { ARG_FLOAT } },
{ MP_CMD_SPEED_MULT, "speed_mult", { ARG_FLOAT } },
{ MP_CMD_SPEED_SET, "speed_set", { ARG_FLOAT } },
{ MP_CMD_QUIT, "quit", { OARG_INT(0) } },
{ MP_CMD_STOP, "stop", },
{ MP_CMD_PAUSE, "pause", },
{ MP_CMD_FRAME_STEP, "frame_step", },
mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started.
2012-07-31 21:33:26 +02:00
{ MP_CMD_PLAYLIST_NEXT, "playlist_next", { OARG_INT(0) } },
{ MP_CMD_PLAYLIST_PREV, "playlist_prev", { OARG_INT(0) } },
{ MP_CMD_LOOP, "loop", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_SUB_DELAY, "sub_delay", { ARG_FLOAT, OARG_INT(0) } },
{ MP_CMD_SUB_STEP, "sub_step", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_OSD, "osd", { OARG_INT(-1) } },
{ MP_CMD_OSD_SHOW_TEXT, "osd_show_text", { ARG_STRING, OARG_INT(-1), OARG_INT(0) } },
{ MP_CMD_OSD_SHOW_PROPERTY_TEXT, "osd_show_property_text", { ARG_STRING, OARG_INT(-1), OARG_INT(0) } },
{ MP_CMD_OSD_SHOW_PROGRESSION, "osd_show_progression", },
{ MP_CMD_VOLUME, "volume", { ARG_FLOAT, OARG_INT(0) } },
{ MP_CMD_BALANCE, "balance", { ARG_FLOAT, OARG_INT(0) } },
{ MP_CMD_MIXER_USEMASTER, "use_master", },
{ MP_CMD_MUTE, "mute", { OARG_INT(-1) } },
{ MP_CMD_CONTRAST, "contrast", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_GAMMA, "gamma", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_BRIGHTNESS, "brightness", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_HUE, "hue", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_SATURATION, "saturation", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_FRAMEDROPPING, "frame_drop", { OARG_INT(-1) } },
{ MP_CMD_SUB_POS, "sub_pos", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_SUB_ALIGNMENT, "sub_alignment", { OARG_INT(-1) } },
{ MP_CMD_SUB_VISIBILITY, "sub_visibility", { OARG_INT(-1) } },
{ MP_CMD_SUB_LOAD, "sub_load", { ARG_STRING } },
{ MP_CMD_SUB_REMOVE, "sub_remove", { OARG_INT(-1) } },
{ MP_CMD_SUB_SELECT, "vobsub_lang", { OARG_INT(-2) } }, // for compatibility
{ MP_CMD_SUB_SELECT, "sub_select", { OARG_INT(-2) } },
{ MP_CMD_SUB_SOURCE, "sub_source", { OARG_INT(-2) } },
{ MP_CMD_SUB_VOB, "sub_vob", { OARG_INT(-2) } },
{ MP_CMD_SUB_DEMUX, "sub_demux", { OARG_INT(-2) } },
{ MP_CMD_SUB_FILE, "sub_file", { OARG_INT(-2) } },
{ MP_CMD_SUB_LOG, "sub_log", },
{ MP_CMD_SUB_SCALE, "sub_scale", { ARG_FLOAT, OARG_INT(0) } },
#ifdef CONFIG_ASS
{ MP_CMD_ASS_USE_MARGINS, "ass_use_margins", { OARG_INT(-1) } },
#endif
{ MP_CMD_GET_PERCENT_POS, "get_percent_pos", },
{ MP_CMD_GET_TIME_POS, "get_time_pos", },
{ MP_CMD_GET_TIME_LENGTH, "get_time_length", },
{ MP_CMD_GET_FILENAME, "get_file_name", },
{ MP_CMD_GET_VIDEO_CODEC, "get_video_codec", },
{ MP_CMD_GET_VIDEO_BITRATE, "get_video_bitrate", },
{ MP_CMD_GET_VIDEO_RESOLUTION, "get_video_resolution", },
{ MP_CMD_GET_AUDIO_CODEC, "get_audio_codec", },
{ MP_CMD_GET_AUDIO_BITRATE, "get_audio_bitrate", },
{ MP_CMD_GET_AUDIO_SAMPLES, "get_audio_samples", },
{ MP_CMD_GET_META_TITLE, "get_meta_title", },
{ MP_CMD_GET_META_ARTIST, "get_meta_artist", },
{ MP_CMD_GET_META_ALBUM, "get_meta_album", },
{ MP_CMD_GET_META_YEAR, "get_meta_year", },
{ MP_CMD_GET_META_COMMENT, "get_meta_comment", },
{ MP_CMD_GET_META_TRACK, "get_meta_track", },
{ MP_CMD_GET_META_GENRE, "get_meta_genre", },
{ MP_CMD_SWITCH_AUDIO, "switch_audio", { OARG_INT(-1) } },
{ MP_CMD_SWITCH_ANGLE, "switch_angle", { OARG_INT(-1) } },
{ MP_CMD_SWITCH_TITLE, "switch_title", { OARG_INT(-1) } },
#ifdef CONFIG_TV
{ MP_CMD_TV_START_SCAN, "tv_start_scan", },
{ MP_CMD_TV_STEP_CHANNEL, "tv_step_channel", { ARG_INT } },
{ MP_CMD_TV_STEP_NORM, "tv_step_norm", },
{ MP_CMD_TV_STEP_CHANNEL_LIST, "tv_step_chanlist", },
{ MP_CMD_TV_SET_CHANNEL, "tv_set_channel", { ARG_STRING } },
{ MP_CMD_TV_LAST_CHANNEL, "tv_last_channel", },
{ MP_CMD_TV_SET_FREQ, "tv_set_freq", { ARG_FLOAT } },
{ MP_CMD_TV_STEP_FREQ, "tv_step_freq", { ARG_FLOAT } },
{ MP_CMD_TV_SET_NORM, "tv_set_norm", { ARG_STRING } },
{ MP_CMD_TV_SET_BRIGHTNESS, "tv_set_brightness", { ARG_INT, OARG_INT(1) } },
{ MP_CMD_TV_SET_CONTRAST, "tv_set_contrast", { ARG_INT, OARG_INT(1) } },
{ MP_CMD_TV_SET_HUE, "tv_set_hue", { ARG_INT, OARG_INT(1) } },
{ MP_CMD_TV_SET_SATURATION, "tv_set_saturation", { ARG_INT, OARG_INT(1) } },
#endif
{ MP_CMD_SUB_FORCED_ONLY, "forced_subs_only", { OARG_INT(-1) } },
#ifdef CONFIG_DVBIN
{ MP_CMD_DVB_SET_CHANNEL, "dvb_set_channel", { ARG_INT, ARG_INT } },
#endif
{ MP_CMD_SWITCH_RATIO, "switch_ratio", { OARG_FLOAT(0) } },
{ MP_CMD_VO_FULLSCREEN, "vo_fullscreen", { OARG_INT(-1) } },
{ MP_CMD_VO_ONTOP, "vo_ontop", { OARG_INT(-1) } },
{ MP_CMD_VO_ROOTWIN, "vo_rootwin", { OARG_INT(-1) } },
{ MP_CMD_VO_BORDER, "vo_border", { OARG_INT(-1) } },
{ MP_CMD_SCREENSHOT, "screenshot", { OARG_INT(0), OARG_INT(0) } },
{ MP_CMD_PANSCAN, "panscan", { ARG_FLOAT, OARG_INT(0) } },
{ MP_CMD_SWITCH_VSYNC, "switch_vsync", { OARG_INT(0) } },
{ MP_CMD_LOADFILE, "loadfile", { ARG_STRING, OARG_INT(0) } },
{ MP_CMD_LOADLIST, "loadlist", { ARG_STRING, OARG_INT(0) } },
mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started.
2012-07-31 21:33:26 +02:00
{ MP_CMD_PLAYLIST_CLEAR, "playlist_clear", },
{ MP_CMD_RUN, "run", { ARG_STRING } },
{ MP_CMD_CAPTURING, "capturing", },
{ MP_CMD_VF_CHANGE_RECTANGLE, "change_rectangle", { ARG_INT, ARG_INT } },
{ MP_CMD_TV_TELETEXT_ADD_DEC, "teletext_add_dec", { ARG_STRING } },
{ MP_CMD_TV_TELETEXT_GO_LINK, "teletext_go_link", { ARG_INT } },
#ifdef CONFIG_DVDNAV
{ MP_CMD_DVDNAV, "dvdnav", { ARG_STRING } },
#endif
{ MP_CMD_GET_VO_FULLSCREEN, "get_vo_fullscreen", },
{ MP_CMD_GET_SUB_VISIBILITY, "get_sub_visibility", },
{ MP_CMD_KEYDOWN_EVENTS, "key_down_event", { ARG_INT } },
{ MP_CMD_SET_PROPERTY, "set_property", { ARG_STRING, ARG_STRING } },
{ MP_CMD_SET_PROPERTY_OSD, "set_property_osd", { ARG_STRING, ARG_STRING } },
{ MP_CMD_GET_PROPERTY, "get_property", { ARG_STRING } },
{ MP_CMD_STEP_PROPERTY, "step_property", { ARG_STRING, OARG_FLOAT(0), OARG_INT(0) } },
{ MP_CMD_STEP_PROPERTY_OSD, "step_property_osd", { ARG_STRING, OARG_FLOAT(0), OARG_INT(0) } },
{ MP_CMD_SEEK_CHAPTER, "seek_chapter", { ARG_INT, OARG_INT(0) } },
{ MP_CMD_SET_MOUSE_POS, "set_mouse_pos", { ARG_INT, ARG_INT } },
{ MP_CMD_AF_SWITCH, "af_switch", { ARG_STRING } },
{ MP_CMD_AF_ADD, "af_add", { ARG_STRING } },
{ MP_CMD_AF_DEL, "af_del", { ARG_STRING } },
{ MP_CMD_AF_CLR, "af_clr", },
{ MP_CMD_AF_CMDLINE, "af_cmdline", { ARG_STRING, ARG_STRING } },
{ MP_CMD_SHOW_CHAPTERS, "show_chapters_osd", },
{ MP_CMD_SHOW_TRACKS, "show_tracks_osd", },
{ MP_CMD_VO_CMDLINE, "vo_cmdline", { ARG_STRING } },
{0}
};
/// The names of the keys as used in input.conf
/// If you add some new keys, you also need to add them here
static const struct key_name key_names[] = {
{ ' ', "SPACE" },
{ '#', "SHARP" },
{ KEY_ENTER, "ENTER" },
{ KEY_TAB, "TAB" },
{ KEY_BACKSPACE, "BS" },
{ KEY_DELETE, "DEL" },
{ KEY_INSERT, "INS" },
{ KEY_HOME, "HOME" },
{ KEY_END, "END" },
{ KEY_PAGE_UP, "PGUP" },
{ KEY_PAGE_DOWN, "PGDWN" },
{ KEY_ESC, "ESC" },
2012-01-13 10:09:40 +01:00
{ KEY_PRINT, "PRINT" },
{ KEY_RIGHT, "RIGHT" },
{ KEY_LEFT, "LEFT" },
{ KEY_DOWN, "DOWN" },
{ KEY_UP, "UP" },
{ KEY_F+1, "F1" },
{ KEY_F+2, "F2" },
{ KEY_F+3, "F3" },
{ KEY_F+4, "F4" },
{ KEY_F+5, "F5" },
{ KEY_F+6, "F6" },
{ KEY_F+7, "F7" },
{ KEY_F+8, "F8" },
{ KEY_F+9, "F9" },
{ KEY_F+10, "F10" },
{ KEY_F+11, "F11" },
{ KEY_F+12, "F12" },
{ KEY_KP0, "KP0" },
{ KEY_KP1, "KP1" },
{ KEY_KP2, "KP2" },
{ KEY_KP3, "KP3" },
{ KEY_KP4, "KP4" },
{ KEY_KP5, "KP5" },
{ KEY_KP6, "KP6" },
{ KEY_KP7, "KP7" },
{ KEY_KP8, "KP8" },
{ KEY_KP9, "KP9" },
{ KEY_KPDEL, "KP_DEL" },
{ KEY_KPDEC, "KP_DEC" },
{ KEY_KPINS, "KP_INS" },
{ KEY_KPENTER, "KP_ENTER" },
{ MOUSE_BTN0, "MOUSE_BTN0" },
{ MOUSE_BTN1, "MOUSE_BTN1" },
{ MOUSE_BTN2, "MOUSE_BTN2" },
{ MOUSE_BTN3, "MOUSE_BTN3" },
{ MOUSE_BTN4, "MOUSE_BTN4" },
{ MOUSE_BTN5, "MOUSE_BTN5" },
{ MOUSE_BTN6, "MOUSE_BTN6" },
{ MOUSE_BTN7, "MOUSE_BTN7" },
{ MOUSE_BTN8, "MOUSE_BTN8" },
{ MOUSE_BTN9, "MOUSE_BTN9" },
{ MOUSE_BTN10, "MOUSE_BTN10" },
{ MOUSE_BTN11, "MOUSE_BTN11" },
{ MOUSE_BTN12, "MOUSE_BTN12" },
{ MOUSE_BTN13, "MOUSE_BTN13" },
{ MOUSE_BTN14, "MOUSE_BTN14" },
{ MOUSE_BTN15, "MOUSE_BTN15" },
{ MOUSE_BTN16, "MOUSE_BTN16" },
{ MOUSE_BTN17, "MOUSE_BTN17" },
{ MOUSE_BTN18, "MOUSE_BTN18" },
{ MOUSE_BTN19, "MOUSE_BTN19" },
{ MOUSE_BTN0_DBL, "MOUSE_BTN0_DBL" },
{ MOUSE_BTN1_DBL, "MOUSE_BTN1_DBL" },
{ MOUSE_BTN2_DBL, "MOUSE_BTN2_DBL" },
{ MOUSE_BTN3_DBL, "MOUSE_BTN3_DBL" },
{ MOUSE_BTN4_DBL, "MOUSE_BTN4_DBL" },
{ MOUSE_BTN5_DBL, "MOUSE_BTN5_DBL" },
{ MOUSE_BTN6_DBL, "MOUSE_BTN6_DBL" },
{ MOUSE_BTN7_DBL, "MOUSE_BTN7_DBL" },
{ MOUSE_BTN8_DBL, "MOUSE_BTN8_DBL" },
{ MOUSE_BTN9_DBL, "MOUSE_BTN9_DBL" },
{ MOUSE_BTN10_DBL, "MOUSE_BTN10_DBL" },
{ MOUSE_BTN11_DBL, "MOUSE_BTN11_DBL" },
{ MOUSE_BTN12_DBL, "MOUSE_BTN12_DBL" },
{ MOUSE_BTN13_DBL, "MOUSE_BTN13_DBL" },
{ MOUSE_BTN14_DBL, "MOUSE_BTN14_DBL" },
{ MOUSE_BTN15_DBL, "MOUSE_BTN15_DBL" },
{ MOUSE_BTN16_DBL, "MOUSE_BTN16_DBL" },
{ MOUSE_BTN17_DBL, "MOUSE_BTN17_DBL" },
{ MOUSE_BTN18_DBL, "MOUSE_BTN18_DBL" },
{ MOUSE_BTN19_DBL, "MOUSE_BTN19_DBL" },
{ JOY_AXIS1_MINUS, "JOY_UP" },
{ JOY_AXIS1_PLUS, "JOY_DOWN" },
{ JOY_AXIS0_MINUS, "JOY_LEFT" },
{ JOY_AXIS0_PLUS, "JOY_RIGHT" },
{ JOY_AXIS0_PLUS, "JOY_AXIS0_PLUS" },
{ JOY_AXIS0_MINUS, "JOY_AXIS0_MINUS" },
{ JOY_AXIS1_PLUS, "JOY_AXIS1_PLUS" },
{ JOY_AXIS1_MINUS, "JOY_AXIS1_MINUS" },
{ JOY_AXIS2_PLUS, "JOY_AXIS2_PLUS" },
{ JOY_AXIS2_MINUS, "JOY_AXIS2_MINUS" },
{ JOY_AXIS3_PLUS, "JOY_AXIS3_PLUS" },
{ JOY_AXIS3_MINUS, "JOY_AXIS3_MINUS" },
{ JOY_AXIS4_PLUS, "JOY_AXIS4_PLUS" },
{ JOY_AXIS4_MINUS, "JOY_AXIS4_MINUS" },
{ JOY_AXIS5_PLUS, "JOY_AXIS5_PLUS" },
{ JOY_AXIS5_MINUS, "JOY_AXIS5_MINUS" },
{ JOY_AXIS6_PLUS, "JOY_AXIS6_PLUS" },
{ JOY_AXIS6_MINUS, "JOY_AXIS6_MINUS" },
{ JOY_AXIS7_PLUS, "JOY_AXIS7_PLUS" },
{ JOY_AXIS7_MINUS, "JOY_AXIS7_MINUS" },
{ JOY_AXIS8_PLUS, "JOY_AXIS8_PLUS" },
{ JOY_AXIS8_MINUS, "JOY_AXIS8_MINUS" },
{ JOY_AXIS9_PLUS, "JOY_AXIS9_PLUS" },
{ JOY_AXIS9_MINUS, "JOY_AXIS9_MINUS" },
{ JOY_BTN0, "JOY_BTN0" },
{ JOY_BTN1, "JOY_BTN1" },
{ JOY_BTN2, "JOY_BTN2" },
{ JOY_BTN3, "JOY_BTN3" },
{ JOY_BTN4, "JOY_BTN4" },
{ JOY_BTN5, "JOY_BTN5" },
{ JOY_BTN6, "JOY_BTN6" },
{ JOY_BTN7, "JOY_BTN7" },
{ JOY_BTN8, "JOY_BTN8" },
{ JOY_BTN9, "JOY_BTN9" },
{ AR_PLAY, "AR_PLAY" },
{ AR_PLAY_HOLD, "AR_PLAY_HOLD" },
{ AR_NEXT, "AR_NEXT" },
{ AR_NEXT_HOLD, "AR_NEXT_HOLD" },
{ AR_PREV, "AR_PREV" },
{ AR_PREV_HOLD, "AR_PREV_HOLD" },
{ AR_MENU, "AR_MENU" },
{ AR_MENU_HOLD, "AR_MENU_HOLD" },
{ AR_VUP, "AR_VUP" },
{ AR_VDOWN, "AR_VDOWN" },
{ KEY_POWER, "POWER" },
{ KEY_MENU, "MENU" },
{ KEY_PLAY, "PLAY" },
{ KEY_PAUSE, "PAUSE" },
{ KEY_PLAYPAUSE, "PLAYPAUSE" },
{ KEY_STOP, "STOP" },
{ KEY_FORWARD, "FORWARD" },
{ KEY_REWIND, "REWIND" },
{ KEY_NEXT, "NEXT" },
{ KEY_PREV, "PREV" },
{ KEY_VOLUME_UP, "VOLUME_UP" },
{ KEY_VOLUME_DOWN, "VOLUME_DOWN" },
{ KEY_MUTE, "MUTE" },
// These are kept for backward compatibility
{ KEY_PAUSE, "XF86_PAUSE" },
{ KEY_STOP, "XF86_STOP" },
{ KEY_PREV, "XF86_PREV" },
{ KEY_NEXT, "XF86_NEXT" },
{ KEY_CLOSE_WIN, "CLOSE_WIN" },
{ 0, NULL }
};
struct key_name modifier_names[] = {
{ KEY_MODIFIER_SHIFT, "Shift" },
{ KEY_MODIFIER_CTRL, "Ctrl" },
{ KEY_MODIFIER_ALT, "Alt" },
{ KEY_MODIFIER_META, "Meta" },
{ 0 }
};
#define KEY_MODIFIER_MASK (KEY_MODIFIER_SHIFT | KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_META)
// This is the default binding. The content of input.conf overrides these.
// The first arg is a null terminated array of key codes.
// The second is the command
static const struct cmd_bind def_cmd_binds[] = {
{ { MOUSE_BTN0_DBL, 0 }, "vo_fullscreen" },
{ { MOUSE_BTN2, 0 }, "pause" },
{ { MOUSE_BTN3, 0 }, "seek 10" },
{ { MOUSE_BTN4, 0 }, "seek -10" },
{ { MOUSE_BTN5, 0 }, "volume 1" },
{ { MOUSE_BTN6, 0 }, "volume -1" },
#ifdef CONFIG_DVDNAV
{ { KEY_KP8, 0 }, "dvdnav up" }, // up
{ { KEY_KP2, 0 }, "dvdnav down" }, // down
{ { KEY_KP4, 0 }, "dvdnav left" }, // left
{ { KEY_KP6, 0 }, "dvdnav right" }, // right
{ { KEY_KP5, 0 }, "dvdnav menu" }, // menu
{ { KEY_KPENTER, 0 }, "dvdnav select" }, // select
{ { MOUSE_BTN0, 0 }, "dvdnav mouse" }, //select
{ { KEY_KP7, 0 }, "dvdnav prev" }, // previous menu
#endif
{ { KEY_RIGHT, 0 }, "seek 10" },
{ { KEY_LEFT, 0 }, "seek -10" },
{ { KEY_MODIFIER_SHIFT + KEY_RIGHT, 0 }, "seek 1 0 1" },
{ { KEY_MODIFIER_SHIFT + KEY_LEFT, 0 }, "seek -1 0 1" },
{ { KEY_UP, 0 }, "seek 60" },
{ { KEY_DOWN, 0 }, "seek -60" },
{ { KEY_MODIFIER_SHIFT + KEY_UP, 0 }, "seek 5 0 1" },
{ { KEY_MODIFIER_SHIFT + KEY_DOWN, 0 }, "seek -5 0 1" },
{ { KEY_PAGE_UP, 0 }, "seek 600" },
{ { KEY_PAGE_DOWN, 0 }, "seek -600" },
{ { '+', 0 }, "audio_delay 0.100" },
{ { '-', 0 }, "audio_delay -0.100" },
{ { '[', 0 }, "speed_mult 0.9091" },
{ { ']', 0 }, "speed_mult 1.1" },
{ { '{', 0 }, "speed_mult 0.5" },
{ { '}', 0 }, "speed_mult 2.0" },
{ { KEY_BACKSPACE, 0 }, "speed_set 1.0" },
{ { 'q', 0 }, "quit" },
{ { KEY_ESC, 0 }, "quit" },
{ { 'p', 0 }, "pause" },
{ { ' ', 0 }, "pause" },
{ { '.', 0 }, "frame_step" },
mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started.
2012-07-31 21:33:26 +02:00
{ { '>', 0 }, "playlist_next" },
{ { KEY_ENTER, 0 }, "playlist_next 1" },
{ { '<', 0 }, "playlist_prev" },
{ { 'o', 0 }, "osd" },
{ { 'I', 0 }, "osd_show_property_text \"${filename}\"" },
{ { 'P', 0 }, "osd_show_progression" },
{ { 'z', 0 }, "sub_delay -0.1" },
{ { 'x', 0 }, "sub_delay +0.1" },
{ { 'g', 0 }, "sub_step -1" },
{ { 'y', 0 }, "sub_step +1" },
{ { '9', 0 }, "volume -1" },
{ { '/', 0 }, "volume -1" },
{ { '0', 0 }, "volume 1" },
{ { '*', 0 }, "volume 1" },
{ { '(', 0 }, "balance -0.1" },
{ { ')', 0 }, "balance 0.1" },
{ { 'm', 0 }, "mute" },
{ { '1', 0 }, "contrast -1" },
{ { '2', 0 }, "contrast 1" },
{ { '3', 0 }, "brightness -1" },
{ { '4', 0 }, "brightness 1" },
{ { '5', 0 }, "hue -1" },
{ { '6', 0 }, "hue 1" },
{ { '7', 0 }, "saturation -1" },
{ { '8', 0 }, "saturation 1" },
{ { 'd', 0 }, "frame_drop" },
{ { 'D', 0 }, "step_property_osd deinterlace" },
video, options: implement better YUV->RGB conversion control Rewrite control of the colorspace and input/output level parameters used in YUV-RGB conversions, replacing VO-specific suboptions with new common options and adding configuration support to more cases. Add new option --colormatrix which selects the colorspace the original video is assumed to have in YUV->RGB conversions. The default behavior changes from assuming BT.601 to colorspace autoselection between BT.601 and BT.709 using a simple heuristic based on video size. Add new options --colormatrix-input-range and --colormatrix-output-range which select input YUV and output RGB range. Disable the previously existing VO-specific colorspace and level conversion suboptions in vo_gl and vo_vdpau. Remove the "yuv_colorspace" property and replace it with one named "colormatrix" and semantics matching the new option. Add new properties matching the options for level conversion. Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv and vf_scale, and all can change it at runtime (previously only vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion matrix generation as vo_gl instead of libvdpau functionality; the main functional difference is that the "contrast" equalizer control behaves somewhat differently (it scales the Y component around 1/2 instead of around 0, so that contrast 0 makes the image gray rather than black). vo_xv does not support level conversion. vf_scale supports range setting for input, but always outputs full-range RGB. The value of the slave properties is the policy setting used for conversions. This means they can be set to any value regardless of whether the current VO supports that value or whether there currently even is any video. Possibly separate properties could be added to query the conversion actually used at the moment, if any. Because the colorspace and level settings are now set with a single VF/VO control call, the return value of that is no longer used to signal whether all the settings are actually supported. Instead code should set all the details it can support, and ignore the rest. The core will use GET_YUV_COLORSPACE to check which colorspace details have been set and which not. In other words, the return value for SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace conversion handling exists at all, and VOs have to take care to return the actual state with GET_YUV_COLORSPACE instead. To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
{ { 'c', 0 }, "step_property_osd colormatrix" },
{ { 'r', 0 }, "sub_pos -1" },
{ { 't', 0 }, "sub_pos +1" },
{ { 'a', 0 }, "sub_alignment" },
{ { 'v', 0 }, "sub_visibility" },
{ { 'V', 0 }, "step_property_osd ass_vsfilter_aspect_compat" },
{ { 'j', 0 }, "sub_select" },
{ { 'J', 0 }, "sub_select -3" },
{ { 'F', 0 }, "forced_subs_only" },
{ { '#', 0 }, "switch_audio" },
{ { '_', 0 }, "step_property switch_video" },
{ { KEY_TAB, 0 }, "step_property switch_program" },
{ { 'i', 0 }, "edl_mark" },
#ifdef CONFIG_TV
{ { 'h', 0 }, "tv_step_channel 1" },
{ { 'k', 0 }, "tv_step_channel -1" },
{ { 'n', 0 }, "tv_step_norm" },
{ { 'u', 0 }, "tv_step_chanlist" },
#endif
{ { 'X', 0 }, "step_property teletext_mode 1" },
{ { 'W', 0 }, "step_property teletext_page 1" },
{ { 'Q', 0 }, "step_property teletext_page -1" },
#ifdef CONFIG_JOYSTICK
{ { JOY_AXIS0_PLUS, 0 }, "seek 10" },
{ { JOY_AXIS0_MINUS, 0 }, "seek -10" },
{ { JOY_AXIS1_MINUS, 0 }, "seek 60" },
{ { JOY_AXIS1_PLUS, 0 }, "seek -60" },
{ { JOY_BTN0, 0 }, "pause" },
{ { JOY_BTN1, 0 }, "osd" },
{ { JOY_BTN2, 0 }, "volume 1"},
{ { JOY_BTN3, 0 }, "volume -1"},
#endif
#ifdef CONFIG_APPLE_REMOTE
{ { AR_PLAY, 0}, "pause" },
{ { AR_PLAY_HOLD, 0}, "quit" },
{ { AR_NEXT, 0 }, "seek 30" },
{ { AR_NEXT_HOLD, 0 }, "seek 120" },
{ { AR_PREV, 0 }, "seek -10" },
{ { AR_PREV_HOLD, 0 }, "seek -120" },
{ { AR_MENU, 0 }, "osd" },
{ { AR_MENU_HOLD, 0 }, "mute" },
{ { AR_VUP, 0 }, "volume 1"},
{ { AR_VDOWN, 0 }, "volume -1"},
#endif
{ { 'T', 0 }, "vo_ontop" },
{ { 'f', 0 }, "vo_fullscreen" },
{ { 'C', 0 }, "step_property_osd capturing" },
{ { 's', 0 }, "screenshot 0" },
{ { 'S', 0 }, "screenshot 1" },
{ { KEY_MODIFIER_ALT + 's', 0 }, "screenshot 0 1" },
{ { KEY_MODIFIER_ALT + 'S', 0 }, "screenshot 1 1" },
{ { 'w', 0 }, "panscan -0.1" },
{ { 'e', 0 }, "panscan +0.1" },
{ { KEY_POWER, 0 }, "quit" },
{ { KEY_MENU, 0 }, "osd" },
{ { KEY_PLAY, 0 }, "pause" },
{ { KEY_PAUSE, 0 }, "pause" },
{ { KEY_PLAYPAUSE, 0 }, "pause" },
{ { KEY_STOP, 0 }, "quit" },
{ { KEY_FORWARD, 0 }, "seek 60" },
{ { KEY_REWIND, 0 }, "seek -60" },
mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started.
2012-07-31 21:33:26 +02:00
{ { KEY_NEXT, 0 }, "playlist_next" },
{ { KEY_PREV, 0 }, "playlist_prev" },
{ { KEY_VOLUME_UP, 0 }, "volume 1" },
{ { KEY_VOLUME_DOWN, 0 }, "volume -1" },
{ { KEY_MUTE, 0 }, "mute" },
{ { KEY_CLOSE_WIN, 0 }, "quit" },
{ { '!', 0 }, "seek_chapter -1" },
{ { '@', 0 }, "seek_chapter 1" },
{ { 'A', 0 }, "switch_angle 1" },
{ { 'U', 0 }, "stop" },
{ { 0 }, NULL }
};
#ifndef MP_MAX_KEY_FD
#define MP_MAX_KEY_FD 10
#endif
#ifndef MP_MAX_CMD_FD
#define MP_MAX_CMD_FD 10
#endif
struct input_fd {
2011-04-25 10:38:46 +02:00
int fd;
union {
int (*key)(void *ctx, int fd);
int (*cmd)(int fd, char *dest, int size);
2011-04-25 10:38:46 +02:00
} read_func;
int (*close_func)(int fd);
2011-04-25 10:38:46 +02:00
void *ctx;
unsigned eof : 1;
unsigned drop : 1;
unsigned dead : 1;
unsigned got_cmd : 1;
unsigned no_select : 1;
// These fields are for the cmd fds.
char *buffer;
int pos, size;
};
struct cmd_bind_section {
struct cmd_bind *cmd_binds;
2011-04-25 10:38:46 +02:00
char *section;
struct cmd_bind_section *next;
};
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
struct cmd_queue {
struct mp_cmd *first;
};
struct input_ctx {
// Autorepeat stuff
short ar_state;
mp_cmd_t *ar_cmd;
unsigned int last_ar;
2008-04-30 17:57:02 +02:00
// Autorepeat config
unsigned int ar_delay;
unsigned int ar_rate;
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
// Maximum number of queued commands from keypresses (limit to avoid
// repeated slow commands piling up)
int key_fifo_size;
// these are the keys currently down
int key_down[MP_MAX_KEY_DOWN];
unsigned int num_key_down;
unsigned int last_key_down;
2009-04-01 01:26:34 +02:00
bool default_bindings;
// List of command binding sections
struct cmd_bind_section *cmd_bind_sections;
// Name of currently used command section
char *section;
// The command binds of current section
struct cmd_bind *cmd_binds;
struct cmd_bind *cmd_binds_default;
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
// Used to track whether we managed to read something while checking
// events sources. If yes, the sources may have more queued.
bool got_new_events;
struct input_fd key_fds[MP_MAX_KEY_FD];
unsigned int num_key_fd;
struct input_fd cmd_fds[MP_MAX_CMD_FD];
unsigned int num_cmd_fd;
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
struct cmd_queue key_cmd_queue;
struct cmd_queue control_cmd_queue;
int wakeup_pipe[2];
};
int async_quit_request;
static int print_key_list(m_option_t *cfg, char *optname, char *optparam);
static int print_cmd_list(m_option_t *cfg, char *optname, char *optparam);
// Our command line options
2008-04-26 15:35:40 +02:00
static const m_option_t input_conf[] = {
options: support parsing values into substructs Add an alternate mode for option parser objects (struct m_config) which is not inherently tied to any particular instance of an option value struct. Instead, this type or parsers can be used to initialize defaults in or parse values into a struct given as a parameter. They do not have the save slot functionality used for main player configuration. The new functionality will be used to replace the separate subopt_helper.c parsing code that is currently used to parse per-object suboptions in VOs etc. Previously, option default values were handled by initializing them in external code before creating a parser. This initialization was done with constants even for dynamically-allocated types like strings. Because trying to free a pointer to a constant would cause a crash when trying to replace the default with another value, parser initialization code then replaced all the original defaults with dynamically-allocated copies. This replace-with-copy behavior is no longer supported for new-style options; instead the option definition itself may contain a default value (new OPTDEF macros), and the new function m_config_initialize() is used to set all options to their default values. Convert the existing initialized dynamically allocated options in main config (the string options --dumpfile, --term-osd-esc, --input=conf) to use this. Other non-dynamic ones could be later converted to use this style of initialization too. There's currently no public call to free all dynamically allocated options in a given option struct because I intend to use talloc functionality for that (make them children of the struct and free with it).
2012-05-17 02:31:11 +02:00
OPT_STRING("conf", input.config_file, CONF_GLOBAL, OPTDEF_STR("input.conf")),
2011-04-25 10:38:46 +02:00
OPT_INT("ar-delay", input.ar_delay, CONF_GLOBAL),
2008-04-30 17:57:02 +02:00
OPT_INT("ar-rate", input.ar_rate, CONF_GLOBAL),
{ "keylist", print_key_list, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
{ "cmdlist", print_cmd_list, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
2008-04-30 17:57:02 +02:00
OPT_STRING("js-dev", input.js_dev, CONF_GLOBAL),
OPT_STRING("ar-dev", input.ar_dev, CONF_GLOBAL),
2008-04-30 17:57:02 +02:00
OPT_STRING("file", input.in_file, CONF_GLOBAL),
OPT_MAKE_FLAGS("default-bindings", input.default_bindings, CONF_GLOBAL),
2011-04-25 10:38:46 +02:00
{ NULL, NULL, 0, 0, 0, 0, NULL}
};
2008-04-26 15:35:40 +02:00
static const m_option_t mp_input_opts[] = {
{ "input", (void *)&input_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
OPT_MAKE_FLAGS("joystick", input.use_joystick, CONF_GLOBAL),
OPT_MAKE_FLAGS("lirc", input.use_lirc, CONF_GLOBAL),
OPT_MAKE_FLAGS("lircc", input.use_lircc, CONF_GLOBAL),
OPT_MAKE_FLAGS("ar", input.use_ar, CONF_GLOBAL),
2011-04-25 10:38:46 +02:00
{ NULL, NULL, 0, 0, 0, 0, NULL}
};
2011-04-25 10:38:46 +02:00
static int default_cmd_func(int fd, char *buf, int l);
// Encode the unicode codepoint as UTF-8, and append to the end of the
// talloc'ed buffer.
static char *append_utf8_buffer(char *buffer, uint32_t codepoint)
{
char data[8];
uint8_t tmp;
char *output = data;
PUT_UTF8(codepoint, tmp, *output++ = tmp;);
return talloc_strndup_append_buffer(buffer, data, output - data);
}
static char *get_key_name(int key, char *ret)
{
for (int i = 0; modifier_names[i].name; i++) {
if (modifier_names[i].key & key) {
ret = talloc_asprintf_append_buffer(ret, "%s+",
modifier_names[i].name);
key -= modifier_names[i].key;
}
}
for (int i = 0; key_names[i].name != NULL; i++) {
if (key_names[i].key == key)
return talloc_asprintf_append_buffer(ret, "%s", key_names[i].name);
}
// printable, and valid unicode range
if (key >= 32 && key <= 0x10FFFF)
return append_utf8_buffer(ret, key);
// Print the hex key code
return talloc_asprintf_append_buffer(ret, "%#-8x", key);
}
static char *get_key_combo_name(int *keys, int max)
{
char *ret = talloc_strdup(NULL, "");
while (1) {
ret = get_key_name(*keys, ret);
if (--max && *++keys)
talloc_asprintf_append_buffer(ret, "-");
else
break;
}
return ret;
}
mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started.
2012-07-31 21:33:26 +02:00
bool mp_input_is_abort_cmd(int cmd_id)
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
{
switch (cmd_id) {
case MP_CMD_QUIT:
mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started.
2012-07-31 21:33:26 +02:00
case MP_CMD_PLAYLIST_NEXT:
case MP_CMD_PLAYLIST_PREV:
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
return true;
}
return false;
}
static int queue_count_cmds(struct cmd_queue *queue)
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
{
int res = 0;
for (struct mp_cmd *cmd = queue->first; cmd; cmd = cmd->queue_next)
res++;
return res;
}
static bool queue_has_abort_cmds(struct cmd_queue *queue)
{
for (struct mp_cmd *cmd = queue->first; cmd; cmd = cmd->queue_next) {
mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started.
2012-07-31 21:33:26 +02:00
if (mp_input_is_abort_cmd(cmd->id))
return true;
}
return false;
}
static void queue_remove(struct cmd_queue *queue, struct mp_cmd *cmd)
{
struct mp_cmd **p_prev = &queue->first;
while (*p_prev != cmd) {
p_prev = &(*p_prev)->queue_next;
}
// if this fails, cmd was not in the queue
assert(*p_prev == cmd);
*p_prev = cmd->queue_next;
}
static void queue_pop(struct cmd_queue *queue)
{
queue_remove(queue, queue->first);
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
}
static void queue_add(struct cmd_queue *queue, struct mp_cmd *cmd,
bool at_head)
{
if (at_head) {
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
cmd->queue_next = queue->first;
queue->first = cmd;
} else {
struct mp_cmd **p_prev = &queue->first;
while (*p_prev)
p_prev = &(*p_prev)->queue_next;
*p_prev = cmd;
cmd->queue_next = NULL;
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
}
}
int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select,
int read_func(int fd, char *dest, int size),
int close_func(int fd))
{
2011-04-25 10:38:46 +02:00
if (ictx->num_cmd_fd == MP_MAX_CMD_FD) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many command file descriptors, "
"cannot register file descriptor %d.\n", fd);
return 0;
}
if (select && fd < 0) {
mp_msg(MSGT_INPUT, MSGL_ERR,
"Invalid fd %d in mp_input_add_cmd_fd", fd);
return 0;
}
ictx->cmd_fds[ictx->num_cmd_fd] = (struct input_fd){
2011-04-25 10:38:46 +02:00
.fd = fd,
.read_func.cmd = read_func ? read_func : default_cmd_func,
.close_func = close_func,
.no_select = !select
};
ictx->num_cmd_fd++;
2011-04-25 10:38:46 +02:00
return 1;
}
void mp_input_rm_cmd_fd(struct input_ctx *ictx, int fd)
{
struct input_fd *cmd_fds = ictx->cmd_fds;
2011-04-25 10:38:46 +02:00
unsigned int i;
for (i = 0; i < ictx->num_cmd_fd; i++) {
if (cmd_fds[i].fd == fd)
break;
}
if (i == ictx->num_cmd_fd)
return;
if (cmd_fds[i].close_func)
cmd_fds[i].close_func(cmd_fds[i].fd);
talloc_free(cmd_fds[i].buffer);
if (i + 1 < ictx->num_cmd_fd)
memmove(&cmd_fds[i], &cmd_fds[i + 1],
(ictx->num_cmd_fd - i - 1) * sizeof(struct input_fd));
2011-04-25 10:38:46 +02:00
ictx->num_cmd_fd--;
}
void mp_input_rm_key_fd(struct input_ctx *ictx, int fd)
{
struct input_fd *key_fds = ictx->key_fds;
2011-04-25 10:38:46 +02:00
unsigned int i;
for (i = 0; i < ictx->num_key_fd; i++) {
if (key_fds[i].fd == fd)
break;
}
if (i == ictx->num_key_fd)
return;
if (key_fds[i].close_func)
key_fds[i].close_func(key_fds[i].fd);
if (i + 1 < ictx->num_key_fd)
memmove(&key_fds[i], &key_fds[i + 1],
(ictx->num_key_fd - i - 1) * sizeof(struct input_fd));
2011-04-25 10:38:46 +02:00
ictx->num_key_fd--;
}
int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select,
int read_func(void *ctx, int fd),
int close_func(int fd), void *ctx)
{
2011-04-25 10:38:46 +02:00
if (ictx->num_key_fd == MP_MAX_KEY_FD) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many key file descriptors, "
"cannot register file descriptor %d.\n", fd);
return 0;
}
if (select && fd < 0) {
mp_msg(MSGT_INPUT, MSGL_ERR,
"Invalid fd %d in mp_input_add_key_fd", fd);
return 0;
}
ictx->key_fds[ictx->num_key_fd] = (struct input_fd){
2011-04-25 10:38:46 +02:00
.fd = fd,
.read_func.key = read_func,
.close_func = close_func,
.no_select = !select,
.ctx = ctx,
};
ictx->num_key_fd++;
return 1;
}
2011-04-25 10:38:46 +02:00
mp_cmd_t *mp_input_parse_cmd(char *str)
{
int i, l;
int pausing = 0;
char *ptr;
2011-04-25 10:38:46 +02:00
const mp_cmd_t *cmd_def;
2011-04-25 10:38:46 +02:00
// Ignore heading spaces.
while (str[0] == ' ' || str[0] == '\t')
++str;
2011-04-25 10:38:46 +02:00
if (strncmp(str, "pausing ", 8) == 0) {
pausing = 1;
str = &str[8];
} else if (strncmp(str, "pausing_keep ", 13) == 0) {
pausing = 2;
str = &str[13];
} else if (strncmp(str, "pausing_toggle ", 15) == 0) {
pausing = 3;
str = &str[15];
} else if (strncmp(str, "pausing_keep_force ", 19) == 0) {
pausing = 4;
str = &str[19];
}
ptr = str + strcspn(str, "\t ");
if (*ptr != 0)
2011-04-25 10:38:46 +02:00
l = ptr - str;
else
l = strlen(str);
2011-04-25 10:38:46 +02:00
if (l == 0)
return NULL;
for (i = 0; mp_cmds[i].name != NULL; i++) {
if (strncasecmp(mp_cmds[i].name, str, l) == 0)
break;
}
2011-04-25 10:38:46 +02:00
if (mp_cmds[i].name == NULL)
return NULL;
2011-04-25 10:38:46 +02:00
cmd_def = &mp_cmds[i];
mp_cmd_t *cmd = talloc_ptrtype(NULL, cmd);
*cmd = (mp_cmd_t){
.id = cmd_def->id,
.name = talloc_strdup(cmd, cmd_def->name),
.pausing = pausing,
};
2011-04-25 10:38:46 +02:00
ptr = str;
for (i = 0; ptr && i < MP_CMD_MAX_ARGS; i++) {
while (ptr[0] != ' ' && ptr[0] != '\t' && ptr[0] != '\0')
ptr++;
if (ptr[0] == '\0')
break;
while (ptr[0] == ' ' || ptr[0] == '\t')
ptr++;
if (ptr[0] == '\0' || ptr[0] == '#')
break;
cmd->args[i].type = cmd_def->args[i].type;
switch (cmd_def->args[i].type) {
case MP_CMD_ARG_INT:
errno = 0;
cmd->args[i].v.i = atoi(ptr);
if (errno != 0) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command %s: argument %d "
"isn't an integer.\n", cmd_def->name, i + 1);
goto error;
2011-04-25 10:38:46 +02:00
}
break;
case MP_CMD_ARG_FLOAT:
errno = 0;
cmd->args[i].v.f = atof(ptr);
if (errno != 0) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command %s: argument %d "
"isn't a float.\n", cmd_def->name, i + 1);
goto error;
2011-04-25 10:38:46 +02:00
}
break;
case MP_CMD_ARG_STRING: {
int term = ' ';
if (*ptr == '\'' || *ptr == '"')
term = *ptr++;
char *argptr = talloc_size(cmd, strlen(ptr) + 1);
cmd->args[i].v.s = argptr;
2011-04-25 10:38:46 +02:00
while (1) {
if (*ptr == 0) {
if (term == ' ')
break;
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command %s: argument %d is "
"unterminated.\n", cmd_def->name, i + 1);
goto error;
}
if (*ptr == term)
2011-04-25 10:38:46 +02:00
break;
if (*ptr == '\\')
ptr++;
if (*ptr != 0)
*argptr++ = *ptr++;
2011-04-25 10:38:46 +02:00
}
*argptr = 0;
2011-04-25 10:38:46 +02:00
break;
}
case 0:
2011-04-25 10:38:46 +02:00
ptr = NULL;
break;
default:
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Unknown argument %d\n", i);
}
}
cmd->nargs = i;
int min_args;
for (min_args = 0; min_args < MP_CMD_MAX_ARGS
&& cmd_def->args[min_args].type
&& !cmd_def->args[min_args].optional; min_args++);
if (cmd->nargs < min_args) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command \"%s\" requires at least %d "
2011-04-25 10:38:46 +02:00
"arguments, we found only %d so far.\n", cmd_def->name,
min_args, cmd->nargs);
goto error;
2011-04-25 10:38:46 +02:00
}
for (; i < MP_CMD_MAX_ARGS && cmd_def->args[i].type; i++) {
memcpy(&cmd->args[i], &cmd_def->args[i], sizeof(struct mp_cmd_arg));
2011-04-25 10:38:46 +02:00
if (cmd_def->args[i].type == MP_CMD_ARG_STRING
&& cmd_def->args[i].v.s != NULL)
cmd->args[i].v.s = talloc_strdup(cmd, cmd_def->args[i].v.s);
}
if (i < MP_CMD_MAX_ARGS)
cmd->args[i].type = 0;
2011-04-25 10:38:46 +02:00
return cmd;
error:
mp_cmd_free(cmd);
return NULL;
}
#define MP_CMD_MAX_SIZE 4096
static int read_cmd(struct input_fd *mp_fd, char **ret)
{
2011-04-25 10:38:46 +02:00
char *end;
*ret = NULL;
// Allocate the buffer if it doesn't exist
if (!mp_fd->buffer) {
mp_fd->buffer = talloc_size(NULL, MP_CMD_MAX_SIZE);
mp_fd->pos = 0;
mp_fd->size = MP_CMD_MAX_SIZE;
}
2011-04-25 10:38:46 +02:00
// Get some data if needed/possible
while (!mp_fd->got_cmd && !mp_fd->eof && (mp_fd->size - mp_fd->pos > 1)) {
int r = mp_fd->read_func.cmd(mp_fd->fd, mp_fd->buffer + mp_fd->pos,
mp_fd->size - 1 - mp_fd->pos);
// Error ?
if (r < 0) {
switch (r) {
case MP_INPUT_ERROR:
case MP_INPUT_DEAD:
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Error while reading "
"command file descriptor %d: %s\n",
mp_fd->fd, strerror(errno));
case MP_INPUT_NOTHING:
return r;
case MP_INPUT_RETRY:
continue;
}
// EOF ?
} else if (r == 0) {
mp_fd->eof = 1;
break;
}
mp_fd->pos += r;
break;
}
2011-04-25 10:38:46 +02:00
mp_fd->got_cmd = 0;
while (1) {
int l = 0;
// Find the cmd end
mp_fd->buffer[mp_fd->pos] = '\0';
end = strchr(mp_fd->buffer, '\r');
if (end)
*end = '\n';
end = strchr(mp_fd->buffer, '\n');
// No cmd end ?
if (!end) {
// If buffer is full we must drop all until the next \n
if (mp_fd->size - mp_fd->pos <= 1) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Command buffer of file "
"descriptor %d is full: dropping content.\n",
mp_fd->fd);
mp_fd->pos = 0;
mp_fd->drop = 1;
}
break;
}
// We already have a cmd : set the got_cmd flag
else if ((*ret)) {
mp_fd->got_cmd = 1;
break;
}
2011-04-25 10:38:46 +02:00
l = end - mp_fd->buffer;
2011-04-25 10:38:46 +02:00
// Not dropping : put the cmd in ret
if (!mp_fd->drop)
*ret = talloc_strndup(NULL, mp_fd->buffer, l);
else
mp_fd->drop = 0;
mp_fd->pos -= l + 1;
memmove(mp_fd->buffer, end + 1, mp_fd->pos);
}
if (*ret)
return 1;
else
return MP_INPUT_NOTHING;
}
2011-04-25 10:38:46 +02:00
static int default_cmd_func(int fd, char *buf, int l)
{
2011-04-25 10:38:46 +02:00
while (1) {
int r = read(fd, buf, l);
// Error ?
if (r < 0) {
if (errno == EINTR)
continue;
else if (errno == EAGAIN)
return MP_INPUT_NOTHING;
return MP_INPUT_ERROR;
// EOF ?
}
return r;
}
}
static int read_wakeup(void *ctx, int fd)
{
char buf[100];
read(fd, buf, sizeof(buf));
return MP_INPUT_NOTHING;
}
static char *find_bind_for_key(const struct cmd_bind *binds, int n, int *keys)
{
2011-04-25 10:38:46 +02:00
int j;
if (n <= 0)
return NULL;
for (j = 0; binds[j].cmd != NULL; j++) {
int found = 1, s;
for (s = 0; s < n && binds[j].input[s] != 0; s++) {
if (binds[j].input[s] != keys[s]) {
found = 0;
break;
}
}
if (found && binds[j].input[s] == 0 && s == n)
break;
}
return binds[j].cmd;
}
static struct cmd_bind_section *get_bind_section(struct input_ctx *ictx,
char *section)
{
struct cmd_bind_section *bind_section = ictx->cmd_bind_sections;
2011-04-25 10:38:46 +02:00
if (section == NULL)
section = "default";
while (bind_section) {
if (strcmp(section, bind_section->section) == 0)
return bind_section;
if (bind_section->next == NULL)
break;
bind_section = bind_section->next;
}
if (bind_section) {
bind_section->next = talloc_ptrtype(ictx, bind_section->next);
bind_section = bind_section->next;
} else {
ictx->cmd_bind_sections = talloc_ptrtype(ictx, ictx->cmd_bind_sections);
bind_section = ictx->cmd_bind_sections;
}
bind_section->cmd_binds = NULL;
bind_section->section = talloc_strdup(bind_section, section);
bind_section->next = NULL;
return bind_section;
}
static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys)
{
2011-04-25 10:38:46 +02:00
char *cmd = NULL;
mp_cmd_t *ret;
if (ictx->cmd_binds)
cmd = find_bind_for_key(ictx->cmd_binds, n, keys);
if (ictx->cmd_binds_default && cmd == NULL)
cmd = find_bind_for_key(ictx->cmd_binds_default, n, keys);
if (ictx->default_bindings && cmd == NULL)
cmd = find_bind_for_key(def_cmd_binds, n, keys);
if (cmd == NULL) {
char *key_buf = get_key_combo_name(keys, n);
mp_tmsg(MSGT_INPUT, MSGL_WARN,
"No bind found for key '%s'.\n", key_buf);
2011-04-25 10:38:46 +02:00
talloc_free(key_buf);
return NULL;
}
2011-04-25 10:38:46 +02:00
if (strcmp(cmd, "ignore") == 0)
return NULL;
ret = mp_input_parse_cmd(cmd);
if (!ret) {
char *key_buf = get_key_combo_name(keys, n);
mp_tmsg(MSGT_INPUT, MSGL_ERR,
"Invalid command for bound key '%s': '%s'\n", key_buf, cmd);
2011-04-25 10:38:46 +02:00
talloc_free(key_buf);
}
2011-04-25 10:38:46 +02:00
return ret;
}
2011-04-25 10:38:46 +02:00
static mp_cmd_t *interpret_key(struct input_ctx *ictx, int code)
{
2011-04-25 10:38:46 +02:00
unsigned int j;
mp_cmd_t *ret;
/* On normal keyboards shift changes the character code of non-special
* keys, so don't count the modifier separately for those. In other words
* we want to have "a" and "A" instead of "a" and "Shift+A"; but a separate
* shift modifier is still kept for special keys like arrow keys.
*/
int unmod = code & ~KEY_MODIFIER_MASK;
if (unmod >= 32 && unmod < MP_KEY_BASE)
code &= ~KEY_MODIFIER_SHIFT;
2011-04-25 10:38:46 +02:00
if (code & MP_KEY_DOWN) {
if (ictx->num_key_down > MP_MAX_KEY_DOWN) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many key down events "
"at the same time\n");
return NULL;
}
code &= ~MP_KEY_DOWN;
// Check if we don't already have this key as pushed
for (j = 0; j < ictx->num_key_down; j++) {
if (ictx->key_down[j] == code)
break;
}
if (j != ictx->num_key_down)
return NULL;
ictx->key_down[ictx->num_key_down] = code;
ictx->num_key_down++;
ictx->last_key_down = GetTimer();
ictx->ar_state = 0;
return NULL;
}
// button released or press of key with no separate down/up events
for (j = 0; j < ictx->num_key_down; j++) {
2011-04-25 10:38:46 +02:00
if (ictx->key_down[j] == code)
break;
}
bool doubleclick = code >= MOUSE_BTN0_DBL && code < MOUSE_BTN_DBL_END;
if (doubleclick) {
int btn = code - MOUSE_BTN0_DBL + MOUSE_BTN0;
if (!ictx->num_key_down
|| ictx->key_down[ictx->num_key_down - 1] != btn)
return NULL;
j = ictx->num_key_down - 1;
ictx->key_down[j] = code;
}
2011-04-25 10:38:46 +02:00
if (j == ictx->num_key_down) { // was not already down; add temporarily
if (ictx->num_key_down > MP_MAX_KEY_DOWN) {
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Too many key down events "
"at the same time\n");
return NULL;
}
ictx->key_down[ictx->num_key_down] = code;
ictx->num_key_down++;
ictx->last_key_down = 1;
}
2011-04-25 10:38:46 +02:00
// Interpret only maximal point of multibutton event
ret = ictx->last_key_down ?
2011-04-25 10:38:46 +02:00
get_cmd_from_keys(ictx, ictx->num_key_down, ictx->key_down)
: NULL;
if (doubleclick) {
ictx->key_down[j] = code - MOUSE_BTN0_DBL + MOUSE_BTN0;
return ret;
}
// Remove the key
2011-04-25 10:38:46 +02:00
if (j + 1 < ictx->num_key_down)
memmove(&ictx->key_down[j], &ictx->key_down[j + 1],
(ictx->num_key_down - (j + 1)) * sizeof(int));
ictx->num_key_down--;
ictx->last_key_down = 0;
ictx->ar_state = -1;
mp_cmd_free(ictx->ar_cmd);
ictx->ar_cmd = NULL;
return ret;
}
static mp_cmd_t *check_autorepeat(struct input_ctx *ictx)
{
2011-04-25 10:38:46 +02:00
// No input : autorepeat ?
if (ictx->ar_rate > 0 && ictx->ar_state >= 0 && ictx->num_key_down > 0
&& !(ictx->key_down[ictx->num_key_down - 1] & MP_NO_REPEAT_KEY)) {
unsigned int t = GetTimer();
// First time : wait delay
if (ictx->ar_state == 0
&& (t - ictx->last_key_down) >= ictx->ar_delay * 1000) {
ictx->ar_cmd = get_cmd_from_keys(ictx, ictx->num_key_down,
ictx->key_down);
if (!ictx->ar_cmd) {
ictx->ar_state = -1;
return NULL;
}
ictx->ar_state = 1;
ictx->last_ar = t;
return mp_cmd_clone(ictx->ar_cmd);
// Then send rate / sec event
} else if (ictx->ar_state == 1
&& (t - ictx->last_ar) >= 1000000 / ictx->ar_rate) {
ictx->last_ar = t;
return mp_cmd_clone(ictx->ar_cmd);
}
}
2011-04-25 10:38:46 +02:00
return NULL;
}
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
void mp_input_feed_key(struct input_ctx *ictx, int code)
{
ictx->got_new_events = true;
if (code == MP_INPUT_RELEASE_ALL) {
memset(ictx->key_down, 0, sizeof(ictx->key_down));
ictx->num_key_down = 0;
ictx->last_key_down = 0;
return;
}
struct mp_cmd *cmd = interpret_key(ictx, code);
if (!cmd)
return;
struct cmd_queue *queue = &ictx->key_cmd_queue;
if (queue_count_cmds(queue) >= ictx->key_fifo_size &&
mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started.
2012-07-31 21:33:26 +02:00
(!mp_input_is_abort_cmd(cmd->id) || queue_has_abort_cmds(queue)))
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
return;
queue_add(queue, cmd, false);
}
static void read_cmd_fd(struct input_ctx *ictx, struct input_fd *cmd_fd)
{
int r;
char *text;
while ((r = read_cmd(cmd_fd, &text)) >= 0) {
ictx->got_new_events = true;
struct mp_cmd *cmd = mp_input_parse_cmd(text);
talloc_free(text);
if (cmd)
queue_add(&ictx->control_cmd_queue, cmd, false);
if (!cmd_fd->got_cmd)
return;
}
if (r == MP_INPUT_ERROR)
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Error on command file descriptor %d\n",
cmd_fd->fd);
else if (r == MP_INPUT_DEAD)
cmd_fd->dead = true;
}
static void read_key_fd(struct input_ctx *ictx, struct input_fd *key_fd)
{
int code = key_fd->read_func.key(key_fd->ctx, key_fd->fd);
if (code >= 0 || code == MP_INPUT_RELEASE_ALL) {
mp_input_feed_key(ictx, code);
return;
}
if (code == MP_INPUT_ERROR)
mp_tmsg(MSGT_INPUT, MSGL_ERR,
"Error on key input file descriptor %d\n", key_fd->fd);
else if (code == MP_INPUT_DEAD) {
mp_tmsg(MSGT_INPUT, MSGL_ERR,
"Dead key input on file descriptor %d\n", key_fd->fd);
key_fd->dead = true;
}
}
/**
* \param time time to wait at most for an event in milliseconds
*/
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
static void read_events(struct input_ctx *ictx, int time)
{
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
ictx->got_new_events = false;
struct input_fd *key_fds = ictx->key_fds;
struct input_fd *cmd_fds = ictx->cmd_fds;
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
for (int i = 0; i < ictx->num_key_fd; i++)
2011-04-25 10:38:46 +02:00
if (key_fds[i].dead) {
mp_input_rm_key_fd(ictx, key_fds[i].fd);
i--;
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
} else if (time && key_fds[i].no_select)
read_key_fd(ictx, &key_fds[i]);
for (int i = 0; i < ictx->num_cmd_fd; i++)
2011-04-25 10:38:46 +02:00
if (cmd_fds[i].dead || cmd_fds[i].eof) {
mp_input_rm_cmd_fd(ictx, cmd_fds[i].fd);
i--;
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
} else if (time && cmd_fds[i].no_select)
read_cmd_fd(ictx, &cmd_fds[i]);
if (ictx->got_new_events)
time = 0;
#ifdef HAVE_POSIX_SELECT
fd_set fds;
FD_ZERO(&fds);
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
int max_fd = 0;
for (int i = 0; i < ictx->num_key_fd; i++) {
if (key_fds[i].no_select)
continue;
if (key_fds[i].fd > max_fd)
max_fd = key_fds[i].fd;
FD_SET(key_fds[i].fd, &fds);
}
for (int i = 0; i < ictx->num_cmd_fd; i++) {
if (cmd_fds[i].no_select)
continue;
if (cmd_fds[i].fd > max_fd)
max_fd = cmd_fds[i].fd;
FD_SET(cmd_fds[i].fd, &fds);
}
struct timeval tv, *time_val;
if (time >= 0) {
tv.tv_sec = time / 1000;
tv.tv_usec = (time % 1000) * 1000;
time_val = &tv;
} else
time_val = NULL;
if (select(max_fd + 1, &fds, NULL, NULL, time_val) < 0) {
if (errno != EINTR)
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Select error: %s\n",
strerror(errno));
FD_ZERO(&fds);
}
#else
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
if (time)
2011-04-25 10:38:46 +02:00
usec_sleep(time * 1000);
#endif
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
for (int i = 0; i < ictx->num_key_fd; i++) {
#ifdef HAVE_POSIX_SELECT
2011-04-25 10:38:46 +02:00
if (!key_fds[i].no_select && !FD_ISSET(key_fds[i].fd, &fds))
continue;
#endif
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
read_key_fd(ictx, &key_fds[i]);
}
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
for (int i = 0; i < ictx->num_cmd_fd; i++) {
#ifdef HAVE_POSIX_SELECT
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
if (!cmd_fds[i].no_select && !FD_ISSET(cmd_fds[i].fd, &fds))
2011-04-25 10:38:46 +02:00
continue;
#endif
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
read_cmd_fd(ictx, &cmd_fds[i]);
}
}
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
/* To support blocking file descriptors we don't loop the read over
* every source until it's known to be empty. Instead we use this wrapper
* to run select() again.
*/
static void read_all_fd_events(struct input_ctx *ictx, int time)
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
{
while (1) {
read_events(ictx, time);
if (!ictx->got_new_events)
return;
time = 0;
}
}
static void read_all_events(struct input_ctx *ictx, int time)
{
#ifdef CONFIG_COCOA
cocoa_events_read_all_events(ictx, time);
#else
read_all_fd_events(ictx, time);
#endif
}
2011-04-25 10:38:46 +02:00
int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd)
{
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
ictx->got_new_events = true;
if (!cmd)
2011-04-25 10:38:46 +02:00
return 0;
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
queue_add(&ictx->control_cmd_queue, cmd, true);
2011-04-25 10:38:46 +02:00
return 1;
}
/**
* \param peek_only when set, the returned command stays in the queue.
* Do not free the returned cmd whe you set this!
*/
mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int peek_only)
{
2011-04-25 10:38:46 +02:00
if (async_quit_request)
return mp_input_parse_cmd("quit 1");
if (ictx->control_cmd_queue.first || ictx->key_cmd_queue.first)
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
time = 0;
read_all_events(ictx, time);
struct mp_cmd *ret;
struct cmd_queue *queue = &ictx->control_cmd_queue;
if (!queue->first)
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
queue = &ictx->key_cmd_queue;
if (!queue->first) {
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
ret = check_autorepeat(ictx);
if (!ret)
return NULL;
queue_add(queue, ret, false);
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
} else
ret = queue->first;
if (!peek_only)
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
queue_pop(queue);
2011-04-25 10:38:46 +02:00
return ret;
}
void mp_cmd_free(mp_cmd_t *cmd)
{
talloc_free(cmd);
}
mp_cmd_t *mp_cmd_clone(mp_cmd_t *cmd)
{
2011-04-25 10:38:46 +02:00
mp_cmd_t *ret;
int i;
2011-04-25 10:38:46 +02:00
ret = talloc_memdup(NULL, cmd, sizeof(mp_cmd_t));
ret->name = talloc_strdup(ret, cmd->name);
for (i = 0; i < MP_CMD_MAX_ARGS && cmd->args[i].type; i++) {
2011-04-25 10:38:46 +02:00
if (cmd->args[i].type == MP_CMD_ARG_STRING && cmd->args[i].v.s != NULL)
ret->args[i].v.s = talloc_strdup(ret, cmd->args[i].v.s);
}
2011-04-25 10:38:46 +02:00
return ret;
}
int mp_input_get_key_from_name(const char *name)
{
int modifiers = 0;
const char *p;
while ((p = strchr(name, '+'))) {
for (struct key_name *m = modifier_names; m->name; m++)
if (!bstrcasecmp(bstr0(m->name),
(struct bstr){(char *)name, p - name})) {
modifiers |= m->key;
goto found;
}
if (!strcmp(name, "+"))
return '+' + modifiers;
return -1;
2011-04-25 10:38:46 +02:00
found:
name = p + 1;
}
struct bstr bname = bstr0(name);
struct bstr rest;
int code = bstr_decode_utf8(bname, &rest);
if (code >= 0 && rest.len == 0)
return code + modifiers;
if (bstr_startswith0(bname, "0x"))
return strtol(name, NULL, 16) + modifiers;
for (int i = 0; key_names[i].name != NULL; i++) {
if (strcasecmp(key_names[i].name, name) == 0)
return key_names[i].key + modifiers;
}
return -1;
}
2011-04-25 10:38:46 +02:00
static int get_input_from_name(char *name, int *keys)
{
char *end, *ptr;
int n = 0;
ptr = name;
n = 0;
for (end = strchr(ptr, '-'); ptr != NULL; end = strchr(ptr, '-')) {
if (end && end[1] != '\0') {
if (end[1] == '-')
end = &end[1];
end[0] = '\0';
}
keys[n] = mp_input_get_key_from_name(ptr);
if (keys[n] < 0)
return 0;
n++;
if (end && end[1] != '\0' && n < MP_MAX_KEY_DOWN)
ptr = &end[1];
else
break;
}
2011-04-25 10:38:46 +02:00
keys[n] = 0;
return 1;
}
#define SPACE_CHAR " \n\r\t"
static void bind_keys(struct input_ctx *ictx,
2011-04-25 10:38:46 +02:00
const int keys[MP_MAX_KEY_DOWN + 1], char *cmd)
{
2011-04-25 10:38:46 +02:00
int i = 0, j;
struct cmd_bind *bind = NULL;
struct cmd_bind_section *bind_section = NULL;
2011-04-25 10:38:46 +02:00
char *section = NULL, *p;
2011-04-25 10:38:46 +02:00
if (*cmd == '{' && (p = strchr(cmd, '}'))) {
*p = 0;
section = ++cmd;
cmd = ++p;
// Jump beginning space
cmd += strspn(cmd, SPACE_CHAR);
2011-04-25 10:38:46 +02:00
}
bind_section = get_bind_section(ictx, section);
if (bind_section->cmd_binds) {
for (i = 0; bind_section->cmd_binds[i].cmd != NULL; i++) {
for (j = 0; bind_section->cmd_binds[i].input[j] == keys[j] && keys[j] != 0; j++)
/* NOTHING */;
if (keys[j] == 0 && bind_section->cmd_binds[i].input[j] == 0 ) {
bind = &bind_section->cmd_binds[i];
break;
}
}
}
if (!bind) {
bind_section->cmd_binds = talloc_realloc(bind_section,
bind_section->cmd_binds,
struct cmd_bind, i + 2);
memset(&bind_section->cmd_binds[i], 0, 2 * sizeof(struct cmd_bind));
2011-04-25 10:38:46 +02:00
bind = &bind_section->cmd_binds[i];
}
2011-04-25 10:38:46 +02:00
talloc_free(bind->cmd);
bind->cmd = talloc_strdup(bind_section->cmd_binds, cmd);
memcpy(bind->input, keys, (MP_MAX_KEY_DOWN + 1) * sizeof(int));
}
static int parse_config(struct input_ctx *ictx, bstr data)
{
int n_binds = 0, keys[MP_MAX_KEY_DOWN + 1];
while (data.len) {
bstr line = bstr_strip_linebreaks(bstr_getline(data, &data));
line = bstr_lstrip(line);
if (line.len == 0 || bstr_startswith0(line, "#"))
2011-04-25 10:38:46 +02:00
continue;
struct bstr command;
// Find the key name starting a line
struct bstr keyname = bstr_split(line, SPACE_CHAR, &command);
command = bstr_strip(command);
if (command.len == 0) {
mp_tmsg(MSGT_INPUT, MSGL_ERR,
"Unfinished key binding: %.*s\n", BSTR_P(line));
continue;
}
char *name = bstrdup0(NULL, keyname);
if (!get_input_from_name(name, keys)) {
talloc_free(name);
mp_tmsg(MSGT_INPUT, MSGL_ERR,
"Unknown key '%.*s'\n", BSTR_P(keyname));
2011-04-25 10:38:46 +02:00
continue;
}
talloc_free(name);
char *cmd = bstrdup0(NULL, command);
bind_keys(ictx, keys, cmd);
n_binds++;
talloc_free(cmd);
}
return n_binds;
}
static int parse_config_file(struct input_ctx *ictx, char *file)
{
struct bstr res = {0};
stream_t *s = open_stream(file, NULL, NULL);
if (!s) {
mp_msg(MSGT_INPUT, MSGL_V, "Can't open input config file %s.\n", file);
return 0;
}
res = stream_read_complete(s, NULL, 1000000, 0);
free_stream(s);
mp_msg(MSGT_INPUT, MSGL_V, "Parsing input config file %s\n", file);
int n_binds = parse_config(ictx, res);
talloc_free(res.start);
mp_msg(MSGT_INPUT, MSGL_V, "Input config file %s parsed: %d binds\n",
file, n_binds);
return 1;
}
void mp_input_set_section(struct input_ctx *ictx, char *name)
{
struct cmd_bind_section *bind_section = NULL;
ictx->cmd_binds = NULL;
ictx->cmd_binds_default = NULL;
talloc_free(ictx->section);
if (name)
ictx->section = talloc_strdup(ictx, name);
else
ictx->section = talloc_strdup(ictx, "default");
if ((bind_section = get_bind_section(ictx, ictx->section)))
ictx->cmd_binds = bind_section->cmd_binds;
if (strcmp(ictx->section, "default") == 0)
return;
if ((bind_section = get_bind_section(ictx, NULL)))
ictx->cmd_binds_default = bind_section->cmd_binds;
}
char *mp_input_get_section(struct input_ctx *ictx)
{
return ictx->section;
}
struct input_ctx *mp_input_init(struct input_conf *input_conf)
{
struct input_ctx *ictx = talloc_ptrtype(NULL, ictx);
*ictx = (struct input_ctx){
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
.key_fifo_size = input_conf->key_fifo_size,
.ar_state = -1,
2008-04-30 17:57:02 +02:00
.ar_delay = input_conf->ar_delay,
.ar_rate = input_conf->ar_rate,
2009-04-01 01:26:34 +02:00
.default_bindings = input_conf->default_bindings,
.wakeup_pipe = {-1, -1},
};
#ifdef CONFIG_COCOA
cocoa_events_init(ictx, read_all_fd_events);
#endif
#ifndef __MINGW32__
long ret = pipe(ictx->wakeup_pipe);
for (int i = 0; i < 2 && ret >= 0; i++) {
ret = fcntl(ictx->wakeup_pipe[i], F_GETFL);
if (ret < 0)
break;
ret = fcntl(ictx->wakeup_pipe[i], F_SETFL, ret | O_NONBLOCK);
}
if (ret < 0)
mp_msg(MSGT_INPUT, MSGL_ERR,
"Failed to initialize wakeup pipe: %s\n", strerror(errno));
else
mp_input_add_key_fd(ictx, ictx->wakeup_pipe[0], true, read_wakeup,
NULL, NULL);
#endif
2011-04-25 10:38:46 +02:00
char *file;
char *config_file = input_conf->config_file;
file = config_file[0] != '/' ? get_path(config_file) : config_file;
if (!file)
return ictx;
if (!parse_config_file(ictx, file)) {
2011-04-25 10:38:46 +02:00
// free file if it was allocated by get_path(),
// before it gets overwritten
if (file != config_file)
free(file);
// Try global conf dir
file = MPLAYER_CONFDIR "/input.conf";
if (!parse_config_file(ictx, file))
2011-04-25 10:38:46 +02:00
mp_msg(MSGT_INPUT, MSGL_V, "Falling back on default (hardcoded) "
"input config\n");
} else {
// free file if it was allocated by get_path()
if (file != config_file)
free(file);
}
#ifdef CONFIG_JOYSTICK
2011-04-25 10:38:46 +02:00
if (input_conf->use_joystick) {
int fd = mp_input_joystick_init(input_conf->js_dev);
if (fd < 0)
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't init input joystick\n");
else
mp_input_add_key_fd(ictx, fd, 1, mp_input_joystick_read,
close, NULL);
2011-04-25 10:38:46 +02:00
}
#endif
#ifdef CONFIG_LIRC
2011-04-25 10:38:46 +02:00
if (input_conf->use_lirc) {
int fd = mp_input_lirc_init();
if (fd > 0)
mp_input_add_cmd_fd(ictx, fd, 0, mp_input_lirc_read,
mp_input_lirc_close);
}
#endif
#ifdef CONFIG_LIRCC
2011-04-25 10:38:46 +02:00
if (input_conf->use_lircc) {
int fd = lircc_init("mplayer", NULL);
if (fd >= 0)
mp_input_add_cmd_fd(ictx, fd, 1, NULL, lircc_cleanup);
2011-04-25 10:38:46 +02:00
}
#endif
#ifdef CONFIG_APPLE_REMOTE
2011-04-25 10:38:46 +02:00
if (input_conf->use_ar) {
if (mp_input_ar_init() < 0)
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't init Apple Remote.\n");
else
mp_input_add_key_fd(ictx, -1, 0, mp_input_ar_read,
mp_input_ar_close, NULL);
}
#endif
#ifdef CONFIG_APPLE_IR
2011-04-25 10:38:46 +02:00
if (input_conf->use_ar) {
int fd = mp_input_appleir_init(input_conf->ar_dev);
if (fd < 0)
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't init Apple Remote.\n");
else
mp_input_add_key_fd(ictx, fd, 1, mp_input_appleir_read,
close, NULL);
2011-04-25 10:38:46 +02:00
}
#endif
2011-04-25 10:38:46 +02:00
if (input_conf->in_file) {
int mode = O_RDONLY;
#ifndef __MINGW32__
2011-04-25 10:38:46 +02:00
// Use RDWR for FIFOs to ensure they stay open over multiple accesses.
// Note that on Windows due to how the API works, using RDONLY should
// be ok.
struct stat st;
2011-04-25 10:38:46 +02:00
if (stat(input_conf->in_file, &st) == 0 && S_ISFIFO(st.st_mode))
mode = O_RDWR;
mode |= O_NONBLOCK;
#endif
2011-04-25 10:38:46 +02:00
int in_file_fd = open(input_conf->in_file, mode);
if (in_file_fd >= 0)
mp_input_add_cmd_fd(ictx, in_file_fd, 1, NULL, close);
2011-04-25 10:38:46 +02:00
else
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't open %s: %s\n",
input_conf->in_file, strerror(errno));
}
2011-04-25 10:38:46 +02:00
return ictx;
}
void mp_input_uninit(struct input_ctx *ictx)
{
#ifdef CONFIG_COCOA
cocoa_events_uninit();
#endif
if (!ictx)
return;
for (int i = 0; i < ictx->num_key_fd; i++) {
2011-04-25 10:38:46 +02:00
if (ictx->key_fds[i].close_func)
ictx->key_fds[i].close_func(ictx->key_fds[i].fd);
}
for (int i = 0; i < ictx->num_cmd_fd; i++) {
2011-04-25 10:38:46 +02:00
if (ictx->cmd_fds[i].close_func)
ictx->cmd_fds[i].close_func(ictx->cmd_fds[i].fd);
}
for (int i = 0; i < 2; i++)
if (ictx->wakeup_pipe[i] != -1)
close(ictx->wakeup_pipe[i]);
2011-04-25 10:38:46 +02:00
talloc_free(ictx);
}
2011-04-25 10:38:46 +02:00
void mp_input_register_options(m_config_t *cfg)
{
m_config_register_options(cfg, mp_input_opts);
}
static int print_key_list(m_option_t *cfg, char *optname, char *optparam)
{
2011-04-25 10:38:46 +02:00
int i;
printf("\n");
for (i = 0; key_names[i].name != NULL; i++)
printf("%s\n", key_names[i].name);
return M_OPT_EXIT;
}
static int print_cmd_list(m_option_t *cfg, char *optname, char *optparam)
{
2011-04-25 10:38:46 +02:00
const mp_cmd_t *cmd;
int i, j;
const char *type;
for (i = 0; (cmd = &mp_cmds[i])->name != NULL; i++) {
printf("%-20.20s", cmd->name);
for (j = 0; j < MP_CMD_MAX_ARGS && cmd->args[j].type; j++) {
2011-04-25 10:38:46 +02:00
switch (cmd->args[j].type) {
case MP_CMD_ARG_INT:
type = "Integer";
break;
case MP_CMD_ARG_FLOAT:
type = "Float";
break;
case MP_CMD_ARG_STRING:
type = "String";
break;
default:
type = "??";
}
if (cmd->args[j].optional)
2011-04-25 10:38:46 +02:00
printf(" [%s]", type);
else
printf(" %s", type);
}
printf("\n");
}
return M_OPT_EXIT;
}
void mp_input_wakeup(struct input_ctx *ictx)
{
if (ictx->wakeup_pipe[1] >= 0)
write(ictx->wakeup_pipe[1], &(char){0}, 1);
}
/**
* \param time time to wait for an interruption in milliseconds
*/
int mp_input_check_interrupt(struct input_ctx *ictx, int time)
{
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
for (int i = 0; ; i++) {
if (async_quit_request || queue_has_abort_cmds(&ictx->key_cmd_queue) ||
queue_has_abort_cmds(&ictx->control_cmd_queue)) {
input: rework event reading and command queuing Rework much of the logic related to reading from event sources and queuing commands. The two biggest architecture changes are: - The code buffering keycodes in mp_fifo.c is gone. Instead key input is now immediately fed to input.c and interpreted as commands, and then the commands are buffered instead. - mp_input_get_cmd() now always tries to read every available event from every event source and convert them to (buffered) commands. Before it would only process new events until one new command became available. Some relevant behavior changes: - Before commands could be lost when stream code called mp_input_check_interrupt() which read commands (to see if they were of types that triggered aborts during slow IO tasks) and then threw them away. This was especially an issue if cache was enabled and slow to read. Fixed - now it's possible to check whether there are queued commands which will abort playback of the current file without throwing other commands away. - mp_input_check_interrupt() now prints a message if it returns true. This is especially useful because the failures caused by aborted stream reads can trigger error messages from other code that was doing the read; the new message makes it more obvious what the cause of the subsequent error messages is. - It's now possible to again avoid making stdin non-blocking (which caused some issues) without reintroducing extra latency. The change will be done in a subsequent commit. - Event sources that do not support select() should now have somewhat lower latency in certain situations as they will be checked both before and after select()/sleep in input reading; before the sleep always happened first even if such sources already had queued input. Before the key fifo was also handled in this manner (first key triggered select, but if multiple were read then rest could be delayed; however in most cases this didn't add latency in practice as after central code started doing command handling it queried for further commands with a max sleep time of 0). - Key fifo limiting is more accurate now: it now counts actual commands intead of keycodes, and all queued keys are read immediately from input devices so they can be counted correctly. - Since keypresses are now interpreted immediately, commands which change keybindings will no longer affect following keypresses that have already been read before the command is executed. This should not be an issue in practice with current keybinding behavior.
2011-07-17 03:47:50 +02:00
mp_tmsg(MSGT_INPUT, MSGL_WARN, "Received command to move to "
"another file. Aborting current processing.\n");
return true;
}
if (i)
return false;
read_all_events(ictx, time);
2011-04-25 10:38:46 +02:00
}
}