diff options
Diffstat (limited to 'input/input.c')
-rw-r--r-- | input/input.c | 753 |
1 files changed, 365 insertions, 388 deletions
diff --git a/input/input.c b/input/input.c index dcbeb2b11d..1f1d4a6ebf 100644 --- a/input/input.c +++ b/input/input.c @@ -35,7 +35,6 @@ #include <assert.h> #endif #include "mp_fifo.h" -#include "osdep/getch2.h" #include "osdep/keycodes.h" #include "osdep/timer.h" #include "libavutil/avstring.h" @@ -44,6 +43,8 @@ #include "m_config.h" #include "m_option.h" #include "get_path.h" +#include "talloc.h" +#include "options.h" #include "joystick.h" @@ -57,6 +58,16 @@ #include "ar.h" +typedef struct mp_cmd_bind { + int input[MP_MAX_KEY_DOWN+1]; + char* cmd; +} mp_cmd_bind_t; + +typedef struct mp_key_name { + int key; + char* name; +} mp_key_name_t; + /// This array defines all known commands. /// The first field is an id used to recognize the command without too many strcmp. /// The second is obviously the command name. @@ -525,40 +536,71 @@ static const mp_cmd_bind_t gui_def_cmd_binds[] = { typedef struct mp_input_fd { int fd; - void* read_func; + union { + mp_key_func_t key; + mp_cmd_func_t cmd; + } read_func; mp_close_func_t close_func; + void *ctx; unsigned eof : 1; unsigned drop : 1; unsigned dead : 1; unsigned got_cmd : 1; unsigned no_select : 1; - unsigned no_readfunc_retval : 1; // These fields are for the cmd fds. char* buffer; int pos,size; } mp_input_fd_t; -typedef struct mp_cmd_filter_st mp_cmd_filter_t; +typedef struct mp_cmd_filter mp_cmd_filter_t; -struct mp_cmd_filter_st { +struct mp_cmd_filter { mp_input_cmd_filter filter; void* ctx; mp_cmd_filter_t* next; }; -typedef struct mp_cmd_bind_section_st mp_cmd_bind_section_t; +typedef struct mp_cmd_bind_section mp_cmd_bind_section_t; -struct mp_cmd_bind_section_st { +struct mp_cmd_bind_section { mp_cmd_bind_t* cmd_binds; char* section; mp_cmd_bind_section_t* next; }; -// These are the user defined binds -static mp_cmd_bind_section_t* cmd_binds_section = NULL; -static char* section = NULL; -static mp_cmd_bind_t* cmd_binds = NULL; -static mp_cmd_bind_t* cmd_binds_default = NULL; +struct input_ctx { + // Autorepeat stuff + short ar_state; + mp_cmd_t *ar_cmd; + unsigned int last_ar; + // Autorepeat config + unsigned int ar_delay; + unsigned int ar_rate; + + // these are the keys currently down + int key_down[MP_MAX_KEY_DOWN]; + unsigned int num_key_down; + unsigned int last_key_down; + + // List of command binding sections + mp_cmd_bind_section_t *cmd_bind_sections; + // Name of currently used command section + char *section; + // The command binds of current section + mp_cmd_bind_t *cmd_binds; + mp_cmd_bind_t *cmd_binds_default; + + mp_input_fd_t key_fds[MP_MAX_KEY_FD]; + unsigned int num_key_fd; + + mp_input_fd_t cmd_fds[MP_MAX_CMD_FD]; + unsigned int num_cmd_fd; + + mp_cmd_t *cmd_queue[CMD_QUEUE_SIZE]; + unsigned int cmd_queue_length, cmd_queue_start, cmd_queue_end; +}; + + static mp_cmd_filter_t* cmd_filters = NULL; // Callback to allow the menu filter to grab the incoming keys @@ -566,77 +608,44 @@ int (*mp_input_key_cb)(int code) = NULL; int async_quit_request; -static mp_input_fd_t key_fds[MP_MAX_KEY_FD]; -static unsigned int num_key_fd = 0; -static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD]; -static unsigned int num_cmd_fd = 0; -static mp_cmd_t* cmd_queue[CMD_QUEUE_SIZE]; -static unsigned int cmd_queue_length = 0,cmd_queue_start = 0, cmd_queue_end = 0; - -// this is the key currently down -static int key_down[MP_MAX_KEY_DOWN]; -static unsigned int num_key_down = 0, last_key_down = 0; - -// Autorepeat stuff -static short ar_state = -1; -static mp_cmd_t* ar_cmd = NULL; -static unsigned int ar_delay = 100, ar_rate = 8, last_ar = 0; - -static int use_joystick = 1, use_lirc = 1, use_lircc = 1; -static char* config_file = "input.conf"; - -/* Apple Remote */ -#ifdef CONFIG_APPLE_REMOTE -static int use_ar = 1; -#else -static int use_ar = 0; -#endif - -static char* js_dev = NULL; -static char* ar_dev = NULL; - -static char* in_file = NULL; -static int in_file_fd = -1; - -static int mp_input_print_key_list(m_option_t* cfg); -static int mp_input_print_cmd_list(m_option_t* cfg); +static int print_key_list(m_option_t* cfg); +static int print_cmd_list(m_option_t* cfg); // Our command line options -static m_option_t input_conf[] = { - { "conf", &config_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL }, - { "ar-dev", &ar_dev, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL }, - { "ar-delay", &ar_delay, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL }, - { "ar-rate", &ar_rate, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL }, - { "keylist", mp_input_print_key_list, CONF_TYPE_FUNC, CONF_GLOBAL, 0, 0, NULL }, - { "cmdlist", mp_input_print_cmd_list, CONF_TYPE_FUNC, CONF_GLOBAL, 0, 0, NULL }, - { "js-dev", &js_dev, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL }, - { "file", &in_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL }, +static const m_option_t input_conf[] = { + OPT_STRING("conf", input.config_file, CONF_GLOBAL), + OPT_INT("ar-delay",input.ar_delay, CONF_GLOBAL), + OPT_INT("ar-rate", input.ar_rate, CONF_GLOBAL), + { "keylist", print_key_list, CONF_TYPE_FUNC, CONF_GLOBAL, 0, 0, NULL }, + { "cmdlist", print_cmd_list, CONF_TYPE_FUNC, CONF_GLOBAL, 0, 0, NULL }, + OPT_STRING("js-dev", input.js_dev, CONF_GLOBAL), + OPT_STRING("ar-dev", input.ar_dev, CONF_GLOBAL), + OPT_STRING("file", input.in_file, CONF_GLOBAL), { NULL, NULL, 0, 0, 0, 0, NULL} }; -static m_option_t mp_input_opts[] = { +static const m_option_t mp_input_opts[] = { { "input", &input_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, - { "nojoystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL }, - { "joystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL }, - { "nolirc", &use_lirc, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL }, - { "lirc", &use_lirc, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL }, - { "nolircc", &use_lircc, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL }, - { "lircc", &use_lircc, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL }, - { "noar", &use_ar, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL }, - { "ar", &use_ar, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL }, + OPT_FLAG_OFF("nojoystick", input.use_joystick, CONF_GLOBAL), + OPT_FLAG_ON("joystick", input.use_joystick, CONF_GLOBAL), + OPT_FLAG_OFF("nolirc", input.use_lirc, CONF_GLOBAL), + OPT_FLAG_ON("lirc", input.use_lirc, CONF_GLOBAL), + OPT_FLAG_OFF("nolircc", input.use_lircc, CONF_GLOBAL), + OPT_FLAG_ON("lircc", input.use_lircc, CONF_GLOBAL), + OPT_FLAG_OFF("noar", input.use_ar, CONF_GLOBAL), + OPT_FLAG_ON("ar", input.use_ar, CONF_GLOBAL), { NULL, NULL, 0, 0, 0, 0, NULL} }; -static int -mp_input_default_cmd_func(int fd,char* buf, int l); +static int default_cmd_func(int fd,char* buf, int l); -static char* -mp_input_get_key_name(int key); +static char *get_key_name(int key, char buffer[12]); -int -mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func) { - if(num_cmd_fd == MP_MAX_CMD_FD) { +int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select, + mp_cmd_func_t read_func, mp_close_func_t close_func) +{ + if (ictx->num_cmd_fd == MP_MAX_CMD_FD) { mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyCmdFds,fd); return 0; } @@ -645,57 +654,64 @@ mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t return 0; } - memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t)); - cmd_fds[num_cmd_fd].fd = fd; - cmd_fds[num_cmd_fd].read_func = read_func ? read_func : mp_input_default_cmd_func; - cmd_fds[num_cmd_fd].close_func = close_func; - cmd_fds[num_cmd_fd].no_select = !select; - num_cmd_fd++; + ictx->cmd_fds[ictx->num_cmd_fd] = (struct mp_input_fd){ + .fd = fd, + .read_func.cmd = read_func ? read_func : default_cmd_func, + .close_func = close_func, + .no_select = !select + }; + ictx->num_cmd_fd++; return 1; } -void -mp_input_rm_cmd_fd(int fd) { +void mp_input_rm_cmd_fd(struct input_ctx *ictx, int fd) +{ + struct mp_input_fd *cmd_fds = ictx->cmd_fds; unsigned int i; - for(i = 0; i < num_cmd_fd; i++) { + for (i = 0; i < ictx->num_cmd_fd; i++) { if(cmd_fds[i].fd == fd) break; } - if(i == num_cmd_fd) + if (i == ictx->num_cmd_fd) return; if(cmd_fds[i].close_func) cmd_fds[i].close_func(cmd_fds[i].fd); if(cmd_fds[i].buffer) - free(cmd_fds[i].buffer); + talloc_free(cmd_fds[i].buffer); - if(i + 1 < num_cmd_fd) - memmove(&cmd_fds[i],&cmd_fds[i+1],(num_cmd_fd - i - 1)*sizeof(mp_input_fd_t)); - num_cmd_fd--; + if (i + 1 < ictx->num_cmd_fd) + memmove(&cmd_fds[i], &cmd_fds[i+1], + (ictx->num_cmd_fd - i - 1) * sizeof(mp_input_fd_t)); + ictx->num_cmd_fd--; } -void -mp_input_rm_key_fd(int fd) { +void mp_input_rm_key_fd(struct input_ctx *ictx, int fd) +{ + struct mp_input_fd *key_fds = ictx->key_fds; unsigned int i; - for(i = 0; i < num_key_fd; i++) { + for (i = 0; i < ictx->num_key_fd; i++) { if(key_fds[i].fd == fd) break; } - if(i == num_key_fd) + 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 < num_key_fd) - memmove(&key_fds[i],&key_fds[i+1],(num_key_fd - i - 1)*sizeof(mp_input_fd_t)); - num_key_fd--; + if(i + 1 < ictx->num_key_fd) + memmove(&key_fds[i], &key_fds[i+1], + (ictx->num_key_fd - i - 1) * sizeof(mp_input_fd_t)); + ictx->num_key_fd--; } -int -mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func) { - if(num_key_fd == MP_MAX_KEY_FD) { +int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select, + mp_key_func_t read_func, mp_close_func_t close_func, + void *ctx) +{ + if (ictx->num_key_fd == MP_MAX_KEY_FD) { mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds,fd); return 0; } @@ -704,44 +720,20 @@ mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t return 0; } - memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t)); - key_fds[num_key_fd].fd = fd; - key_fds[num_key_fd].read_func = read_func; - key_fds[num_key_fd].close_func = close_func; - key_fds[num_key_fd].no_select = !select; - num_key_fd++; - - return 1; -} - -int -mp_input_add_event_fd(int fd, void (*read_func)(void)) -{ - if(num_key_fd == MP_MAX_KEY_FD) { - mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds,fd); - return 0; - } - if (fd < 0) { - mp_msg(MSGT_INPUT, MSGL_ERR, "Invalid fd %i in mp_input_add_event_fd", fd); - return 0; - } - - memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t)); - key_fds[num_key_fd].fd = fd; - key_fds[num_key_fd].read_func = read_func; - key_fds[num_key_fd].close_func = NULL; - key_fds[num_key_fd].no_readfunc_retval = 1; - num_key_fd++; + ictx->key_fds[ictx->num_key_fd] = (struct mp_input_fd){ + .fd = fd, + .read_func.key = read_func, + .close_func = close_func, + .no_select = !select, + .ctx = ctx, + }; + ictx->num_key_fd++; return 1; } -void mp_input_rm_event_fd(int fd) +int mp_input_parse_and_queue_cmds(struct input_ctx *ictx, const char *str) { - mp_input_rm_key_fd(fd); -} - -int mp_input_parse_and_queue_cmds(const char *str) { int cmd_num = 0; while (*str == '\n' || *str == '\r' || *str == ' ') @@ -749,17 +741,17 @@ int mp_input_parse_and_queue_cmds(const char *str) { while (*str) { mp_cmd_t *cmd; size_t len = strcspn(str, "\r\n"); - char *cmdbuf = malloc(len+1); + char *cmdbuf = talloc_size(NULL, len+1); av_strlcpy(cmdbuf, str, len+1); cmd = mp_input_parse_cmd(cmdbuf); if (cmd) { - mp_input_queue_cmd(cmd); + mp_input_queue_cmd(ictx, cmd); ++cmd_num; } str += len; while (*str == '\n' || *str == '\r' || *str == ' ') ++str; - free(cmdbuf); + talloc_free(cmdbuf); } return cmd_num; } @@ -769,7 +761,6 @@ mp_input_parse_cmd(char* str) { int i,l; int pausing = 0; char *ptr,*e; - mp_cmd_t *cmd; const mp_cmd_t *cmd_def; #ifdef MP_DEBUG @@ -814,10 +805,12 @@ mp_input_parse_cmd(char* str) { cmd_def = &mp_cmds[i]; - cmd = calloc(1, sizeof(mp_cmd_t)); - cmd->id = cmd_def->id; - cmd->name = strdup(cmd_def->name); - cmd->pausing = pausing; + 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, + }; ptr = str; @@ -873,9 +866,7 @@ mp_input_parse_cmd(char* str) { ptr2 = e + 1; l--; } - cmd->args[i].v.s = malloc(l+1); - strncpy(cmd->args[i].v.s,start,l); - cmd->args[i].v.s[l] = '\0'; + cmd->args[i].v.s = talloc_strndup(cmd, start, l); if(term != ' ') ptr += l+2; } break; case -1: @@ -897,7 +888,7 @@ mp_input_parse_cmd(char* str) { for( ; i < MP_CMD_MAX_ARGS && cmd_def->args[i].type != -1 ; i++) { memcpy(&cmd->args[i],&cmd_def->args[i],sizeof(mp_cmd_arg_t)); if(cmd_def->args[i].type == MP_CMD_ARG_STRING && cmd_def->args[i].v.s != NULL) - cmd->args[i].v.s = strdup(cmd_def->args[i].v.s); + cmd->args[i].v.s = talloc_strdup(cmd, cmd_def->args[i].v.s); } if(i < MP_CMD_MAX_ARGS) @@ -908,21 +899,22 @@ mp_input_parse_cmd(char* str) { #define MP_CMD_MAX_SIZE 256 -static int -mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) { +static int read_cmd(mp_input_fd_t* mp_fd, char** ret) +{ char* end; (*ret) = NULL; // Allocate the buffer if it doesn't exist if(!mp_fd->buffer) { - mp_fd->buffer = malloc(MP_CMD_MAX_SIZE); + mp_fd->buffer = talloc_size(NULL, MP_CMD_MAX_SIZE); mp_fd->pos = 0; mp_fd->size = MP_CMD_MAX_SIZE; } // Get some data if needed/possible while (!mp_fd->got_cmd && !mp_fd->eof && (mp_fd->size - mp_fd->pos > 1) ) { - int r = ((mp_cmd_func_t)mp_fd->read_func)(mp_fd->fd,mp_fd->buffer+mp_fd->pos,mp_fd->size - 1 - mp_fd->pos); + 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) { @@ -969,16 +961,12 @@ mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) { l = end - mp_fd->buffer; // Not dropping : put the cmd in ret - if (!mp_fd->drop) { - (*ret) = malloc(l+1); - strncpy((*ret),mp_fd->buffer,l); - (*ret)[l] = '\0'; - } else { // Remove the dropping flag + if (!mp_fd->drop) + *ret = talloc_strndup(NULL, mp_fd->buffer, l); + else mp_fd->drop = 0; - } - if( mp_fd->pos - (l+1) > 0) - memmove(mp_fd->buffer,end+1,mp_fd->pos-(l+1)); mp_fd->pos -= l+1; + memmove(mp_fd->buffer, end+1, mp_fd->pos); } if(*ret) @@ -987,9 +975,8 @@ mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) { return MP_INPUT_NOTHING; } -static int -mp_input_default_cmd_func(int fd,char* buf, int l) { - +static int default_cmd_func(int fd,char* buf, int l) +{ while(1) { int r = read(fd,buf,l); // Error ? @@ -1009,7 +996,7 @@ mp_input_default_cmd_func(int fd,char* buf, int l) { void mp_input_add_cmd_filter(mp_input_cmd_filter func, void* ctx) { - mp_cmd_filter_t* filter = malloc(sizeof(mp_cmd_filter_t))/*, *prev*/; + mp_cmd_filter_t *filter = talloc_ptrtype(NULL, filter); filter->filter = func; filter->ctx = ctx; @@ -1018,8 +1005,8 @@ mp_input_add_cmd_filter(mp_input_cmd_filter func, void* ctx) { } -static char* -mp_input_find_bind_for_key(const mp_cmd_bind_t* binds, int n,int* keys) { +static char *find_bind_for_key(const mp_cmd_bind_t* binds, int n,int* keys) +{ int j; if (n <= 0) return NULL; @@ -1037,9 +1024,10 @@ mp_input_find_bind_for_key(const mp_cmd_bind_t* binds, int n,int* keys) { return binds[j].cmd; } -static mp_cmd_bind_section_t* -mp_input_get_bind_section(char *section) { - mp_cmd_bind_section_t* bind_section = cmd_binds_section; +static mp_cmd_bind_section_t *get_bind_section(struct input_ctx *ictx, + char *section) +{ + mp_cmd_bind_section_t *bind_section = ictx->cmd_bind_sections; if (section==NULL) section="default"; while (bind_section) { @@ -1048,36 +1036,39 @@ mp_input_get_bind_section(char *section) { bind_section=bind_section->next; } if(bind_section) { - bind_section->next=malloc(sizeof(mp_cmd_bind_section_t)); + bind_section->next = talloc_ptrtype(ictx, bind_section->next); bind_section=bind_section->next; } else { - cmd_binds_section=malloc(sizeof(mp_cmd_bind_section_t)); - bind_section=cmd_binds_section; + 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=strdup(section); + bind_section->section = talloc_strdup(bind_section, section); bind_section->next=NULL; return bind_section; } -static mp_cmd_t* -mp_input_get_cmd_from_keys(int n,int* keys, int paused) { +static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys, + int paused) +{ char* cmd = NULL; mp_cmd_t* ret; + char key_buf[12]; - if(cmd_binds) - cmd = mp_input_find_bind_for_key(cmd_binds,n,keys); - if(cmd_binds_default && cmd == NULL) - cmd = mp_input_find_bind_for_key(cmd_binds_default,n,keys); + 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(cmd == NULL) - cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys); + cmd = find_bind_for_key(def_cmd_binds,n,keys); if(cmd == NULL) { - mp_msg(MSGT_INPUT,MSGL_WARN,MSGTR_NoBindFound,mp_input_get_key_name(keys[0])); + mp_msg(MSGT_INPUT,MSGL_WARN,MSGTR_NoBindFound, get_key_name(keys[0], + key_buf)); if(n > 1) { int s; for(s=1; s < n; s++) - mp_msg(MSGT_INPUT,MSGL_WARN,"-%s",mp_input_get_key_name(keys[s])); + mp_msg(MSGT_INPUT,MSGL_WARN,"-%s", get_key_name(keys[s], key_buf)); } mp_msg(MSGT_INPUT,MSGL_WARN," \n"); return NULL; @@ -1085,11 +1076,13 @@ mp_input_get_cmd_from_keys(int n,int* keys, int paused) { if (strcmp(cmd, "ignore") == 0) return NULL; ret = mp_input_parse_cmd(cmd); if(!ret) { - mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrInvalidCommandForKey,mp_input_get_key_name(key_down[0])); - if( num_key_down > 1) { + mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrInvalidCommandForKey, + get_key_name(ictx->key_down[0], key_buf)); + if (ictx->num_key_down > 1) { unsigned int s; - for(s=1; s < num_key_down; s++) - mp_msg(MSGT_INPUT,MSGL_ERR,"-%s",mp_input_get_key_name(key_down[s])); + for(s=1; s < ictx->num_key_down; s++) + mp_msg(MSGT_INPUT,MSGL_ERR,"-%s", get_key_name(ictx->key_down[s], + key_buf)); } mp_msg(MSGT_INPUT,MSGL_ERR," : %s \n",cmd); } @@ -1097,8 +1090,7 @@ mp_input_get_cmd_from_keys(int n,int* keys, int paused) { } -static mp_cmd_t* -interpret_key(int code, int paused) +static mp_cmd_t* interpret_key(struct input_ctx *ictx, int code, int paused) { unsigned int j; mp_cmd_t* ret; @@ -1112,105 +1104,111 @@ interpret_key(int code, int paused) } if(code & MP_KEY_DOWN) { - if(num_key_down > MP_MAX_KEY_DOWN) { + if (ictx->num_key_down > MP_MAX_KEY_DOWN) { mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_Err2ManyKeyDowns); return NULL; } code &= ~MP_KEY_DOWN; // Check if we don't already have this key as pushed - for(j = 0; j < num_key_down; j++) { - if(key_down[j] == code) + for (j = 0; j < ictx->num_key_down; j++) { + if (ictx->key_down[j] == code) break; } - if(j != num_key_down) + if (j != ictx->num_key_down) return NULL; - key_down[num_key_down] = code; - num_key_down++; - last_key_down = GetTimer(); - ar_state = 0; + ictx->key_down[ictx->num_key_down] = code; + ictx->num_key_down++; + ictx->last_key_down = GetTimer(); + ictx->ar_state = 0; return NULL; } // key released // Check if the key is in the down key, driver which can't send push event // send only release event - for(j = 0; j < num_key_down; j++) { - if(key_down[j] == code) + for (j = 0; j < ictx->num_key_down; j++) { + if (ictx->key_down[j] == code) break; } - if(j == num_key_down) { // key was not in the down keys : add it - if(num_key_down > MP_MAX_KEY_DOWN) { + if (j == ictx->num_key_down) { // key was not in the down keys : add it + if (ictx->num_key_down > MP_MAX_KEY_DOWN) { mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_Err2ManyKeyDowns); return NULL; } - key_down[num_key_down] = code; - num_key_down++; - last_key_down = 1; + ictx->key_down[ictx->num_key_down] = code; + ictx->num_key_down++; + ictx->last_key_down = 1; } // We ignore key from last combination - ret = last_key_down ? mp_input_get_cmd_from_keys(num_key_down,key_down,paused) : NULL; + ret = ictx->last_key_down ? + get_cmd_from_keys(ictx, ictx->num_key_down, ictx->key_down, paused) + : NULL; // Remove the key - if(j+1 < num_key_down) - memmove(&key_down[j],&key_down[j+1],(num_key_down-(j+1))*sizeof(int)); - num_key_down--; - last_key_down = 0; - ar_state = -1; - if(ar_cmd) { - mp_cmd_free(ar_cmd); - ar_cmd = NULL; + 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; + if (ictx->ar_cmd) { + mp_cmd_free(ictx->ar_cmd); + ictx->ar_cmd = NULL; } return ret; } -static mp_cmd_t *check_autorepeat(int paused) +static mp_cmd_t *check_autorepeat(struct input_ctx *ictx, int paused) { // No input : autorepeat ? - if(ar_rate > 0 && ar_state >=0 && num_key_down > 0 && ! (key_down[num_key_down-1] & MP_NO_REPEAT_KEY)) { + 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(ar_state == 0 && (t - last_key_down) >= ar_delay*1000) { - ar_cmd = mp_input_get_cmd_from_keys(num_key_down,key_down,paused); - if(!ar_cmd) { - ar_state = -1; + 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, paused); + if (!ictx->ar_cmd) { + ictx->ar_state = -1; return NULL; } - ar_state = 1; - last_ar = t; - return mp_cmd_clone(ar_cmd); + ictx->ar_state = 1; + ictx->last_ar = t; + return mp_cmd_clone(ictx->ar_cmd); // Then send rate / sec event - } else if(ar_state == 1 && (t -last_ar) >= 1000000/ar_rate) { - last_ar = t; - return mp_cmd_clone(ar_cmd); + } 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); } } return NULL; } -static mp_cmd_t *read_events(int time, int paused) +static mp_cmd_t *read_events(struct input_ctx *ictx, int time, int paused) { int i; int got_cmd = 0; - mp_cmd_t *autorepeat_cmd; -#ifdef HAVE_POSIX_SELECT - fd_set fds; -#endif - for (i = 0; i < num_key_fd; i++) + struct mp_input_fd *key_fds = ictx->key_fds; + struct mp_input_fd *cmd_fds = ictx->cmd_fds; + for (i = 0; i < ictx->num_key_fd; i++) if (key_fds[i].dead) { - mp_input_rm_key_fd(key_fds[i].fd); + mp_input_rm_key_fd(ictx, key_fds[i].fd); i--; } - for (i = 0; i < num_cmd_fd; i++) + for (i = 0; i < ictx->num_cmd_fd; i++) if (cmd_fds[i].dead || cmd_fds[i].eof) { - mp_input_rm_cmd_fd(cmd_fds[i].fd); + mp_input_rm_cmd_fd(ictx, cmd_fds[i].fd); i--; } else if (cmd_fds[i].got_cmd) got_cmd = 1; #ifdef HAVE_POSIX_SELECT + fd_set fds; FD_ZERO(&fds); if (!got_cmd) { int max_fd = 0, num_fd = 0; - for (i = 0; i < num_key_fd; i++) { + for (i = 0; i < ictx->num_key_fd; i++) { if (key_fds[i].no_select) continue; if (key_fds[i].fd > max_fd) @@ -1218,7 +1216,7 @@ static mp_cmd_t *read_events(int time, int paused) FD_SET(key_fds[i].fd, &fds); num_fd++; } - for (i = 0; i < num_cmd_fd; i++) { + for (i = 0; i < ictx->num_cmd_fd; i++) { if (cmd_fds[i].no_select) continue; if (cmd_fds[i].fd > max_fd) @@ -1249,25 +1247,15 @@ static mp_cmd_t *read_events(int time, int paused) #endif - for (i = 0; i < num_key_fd; i++) { - int code; + for (i = 0; i < ictx->num_key_fd; i++) { #ifdef HAVE_POSIX_SELECT if (!key_fds[i].no_select && !FD_ISSET(key_fds[i].fd, &fds)) continue; #endif - if (key_fds[i].no_readfunc_retval) { // getch2 handler special-cased for now - ((void (*)(void))key_fds[i].read_func)(); - if (cmd_queue_length) - return NULL; - code = mplayer_get_key(0); - if (code < 0) - code = MP_INPUT_NOTHING; - } - else - code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd); + int code = key_fds[i].read_func.key(key_fds[i].ctx, key_fds[i].fd); if (code >= 0) { - mp_cmd_t *ret = interpret_key(code, paused); + mp_cmd_t *ret = interpret_key(ictx, code, paused); if (ret) return ret; } @@ -1280,22 +1268,21 @@ static mp_cmd_t *read_events(int time, int paused) key_fds[i].dead = 1; } } - autorepeat_cmd = check_autorepeat(paused); + mp_cmd_t *autorepeat_cmd = check_autorepeat(ictx, paused); if (autorepeat_cmd) return autorepeat_cmd; - for (i = 0; i < num_cmd_fd; i++) { - char *cmd; - int r; + for (i = 0; i < ictx->num_cmd_fd; i++) { #ifdef HAVE_POSIX_SELECT if (!cmd_fds[i].no_select && !FD_ISSET(cmd_fds[i].fd, &fds) && !cmd_fds[i].got_cmd) continue; #endif - r = mp_input_read_cmd(&cmd_fds[i], &cmd); + char *cmd; + int r = read_cmd(&cmd_fds[i], &cmd); if (r >= 0) { mp_cmd_t *ret = mp_input_parse_cmd(cmd); - free(cmd); + talloc_free(cmd); if (ret) return ret; } @@ -1310,28 +1297,28 @@ static mp_cmd_t *read_events(int time, int paused) } -int -mp_input_queue_cmd(mp_cmd_t* cmd) { - if(!cmd || cmd_queue_length >= CMD_QUEUE_SIZE) +int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t* cmd) +{ + if (!cmd || ictx->cmd_queue_length >= CMD_QUEUE_SIZE) return 0; - cmd_queue[cmd_queue_end] = cmd; - cmd_queue_end = (cmd_queue_end + 1) % CMD_QUEUE_SIZE; - cmd_queue_length++; + ictx->cmd_queue[ictx->cmd_queue_end] = cmd; + ictx->cmd_queue_end = (ictx->cmd_queue_end + 1) % CMD_QUEUE_SIZE; + ictx->cmd_queue_length++; return 1; } -static mp_cmd_t* -mp_input_get_queued_cmd(int peek_only) { +static mp_cmd_t *get_queued_cmd(struct input_ctx *ictx, int peek_only) +{ mp_cmd_t* ret; - if(cmd_queue_length == 0) + if (ictx->cmd_queue_length == 0) return NULL; - ret = cmd_queue[cmd_queue_start]; + ret = ictx->cmd_queue[ictx->cmd_queue_start]; if (!peek_only) { - cmd_queue_length--; - cmd_queue_start = (cmd_queue_start + 1) % CMD_QUEUE_SIZE; + ictx->cmd_queue_length--; + ictx->cmd_queue_start = (ictx->cmd_queue_start + 1) % CMD_QUEUE_SIZE; } return ret; @@ -1341,8 +1328,9 @@ mp_input_get_queued_cmd(int peek_only) { * \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(int time, int paused, int peek_only) { +mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int paused, + int peek_only) +{ mp_cmd_t* ret = NULL; mp_cmd_filter_t* cf; int from_queue; @@ -1351,13 +1339,13 @@ mp_input_get_cmd(int time, int paused, int peek_only) { return mp_input_parse_cmd("quit 1"); while(1) { from_queue = 1; - ret = mp_input_get_queued_cmd(peek_only); + ret = get_queued_cmd(ictx, peek_only); if(ret) break; from_queue = 0; - ret = read_events(time, paused); + ret = read_events(ictx, time, paused); if (!ret) { from_queue = 1; - ret = mp_input_get_queued_cmd(peek_only); + ret = get_queued_cmd(ictx, peek_only); } break; } @@ -1367,34 +1355,21 @@ mp_input_get_cmd(int time, int paused, int peek_only) { if(cf->filter(ret,paused,cf->ctx)) { if (peek_only && from_queue) // The filter ate the cmd, so we remove it from queue - ret = mp_input_get_queued_cmd(0); + ret = get_queued_cmd(ictx, 0); mp_cmd_free(ret); return NULL; } } if (!from_queue && peek_only) - mp_input_queue_cmd(ret); + mp_input_queue_cmd(ictx, ret); return ret; } void mp_cmd_free(mp_cmd_t* cmd) { - int i; -//#ifdef MP_DEBUG -// assert(cmd != NULL); -//#endif - if ( !cmd ) return; - - if(cmd->name) - free(cmd->name); - - for(i=0; i < MP_CMD_MAX_ARGS && cmd->args[i].type != -1; i++) { - if(cmd->args[i].type == MP_CMD_ARG_STRING && cmd->args[i].v.s != NULL) - free(cmd->args[i].v.s); - } - free(cmd); + talloc_free(cmd); } mp_cmd_t* @@ -1405,22 +1380,18 @@ mp_cmd_clone(mp_cmd_t* cmd) { assert(cmd != NULL); #endif - ret = malloc(sizeof(mp_cmd_t)); - memcpy(ret,cmd,sizeof(mp_cmd_t)); - if(cmd->name) - ret->name = strdup(cmd->name); + 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 != -1; i++) { if(cmd->args[i].type == MP_CMD_ARG_STRING && cmd->args[i].v.s != NULL) - ret->args[i].v.s = strdup(cmd->args[i].v.s); + ret->args[i].v.s = talloc_strdup(ret, cmd->args[i].v.s); } return ret; } -static char key_str[12]; - -static char* -mp_input_get_key_name(int key) { +static char *get_key_name(int key, char buffer[12]) +{ int i; for(i = 0; key_names[i].name != NULL; i++) { @@ -1429,13 +1400,13 @@ mp_input_get_key_name(int key) { } if(isascii(key)) { - snprintf(key_str,12,"%c",(char)key); - return key_str; + snprintf(buffer, 12, "%c",(char)key); + return buffer; } // Print the hex key code - snprintf(key_str,12,"%#-8x",key); - return key_str; + snprintf(buffer, 12, "%#-8x",key); + return buffer; } @@ -1456,8 +1427,7 @@ mp_input_get_key_from_name(const char *name) { return -1; } -static int -mp_input_get_input_from_name(char* name,int* keys) { +static int get_input_from_name(char* name,int* keys) { char *end,*ptr; int n=0; @@ -1486,8 +1456,9 @@ mp_input_get_input_from_name(char* name,int* keys) { #define BS_MAX 256 #define SPACE_CHAR " \n\r\t" -void -mp_input_bind_keys(const int keys[MP_MAX_KEY_DOWN+1], char* cmd) { +static void bind_keys(struct input_ctx *ictx, + const int keys[MP_MAX_KEY_DOWN+1], char *cmd) +{ int i = 0,j; mp_cmd_bind_t* bind = NULL; mp_cmd_bind_section_t* bind_section = NULL; @@ -1506,7 +1477,7 @@ mp_input_bind_keys(const int keys[MP_MAX_KEY_DOWN+1], char* cmd) { for( ; cmd[0] != '\0' && strchr(SPACE_CHAR,cmd[0]) != NULL ; cmd++) /* NOTHING */; } - bind_section=mp_input_get_bind_section(section); + bind_section = get_bind_section(ictx, section); if(bind_section->cmd_binds) { for(i = 0; bind_section->cmd_binds[i].cmd != NULL ; i++) { @@ -1520,39 +1491,27 @@ mp_input_bind_keys(const int keys[MP_MAX_KEY_DOWN+1], char* cmd) { } if(!bind) { - bind_section->cmd_binds = realloc(bind_section->cmd_binds,(i+2)*sizeof(mp_cmd_bind_t)); + bind_section->cmd_binds = talloc_realloc(bind_section, + bind_section->cmd_binds, + mp_cmd_bind_t, i + 2); memset(&bind_section->cmd_binds[i],0,2*sizeof(mp_cmd_bind_t)); bind = &bind_section->cmd_binds[i]; } if(bind->cmd) - free(bind->cmd); - bind->cmd = strdup(cmd); + talloc_free(bind->cmd); + bind->cmd = talloc_strdup(bind_section->cmd_binds, cmd); memcpy(bind->input,keys,(MP_MAX_KEY_DOWN+1)*sizeof(int)); } -void -mp_input_add_binds(const mp_cmd_bind_t* list) { +static void add_binds(struct input_ctx *ictx, const mp_cmd_bind_t* list) +{ int i; for(i = 0 ; list[i].cmd ; i++) - mp_input_bind_keys(list[i].input,list[i].cmd); + bind_keys(ictx, list[i].input,list[i].cmd); } -static void -mp_input_free_binds(mp_cmd_bind_t* binds) { - int i; - - if(!binds) - return; - - for(i = 0; binds[i].cmd != NULL; i++) - free(binds[i].cmd); - - free(binds); - -} - -static int -mp_input_parse_config(char *file) { +static int parse_config(struct input_ctx *ictx, char *file) +{ int fd; int bs = 0,r,eof = 0,comments = 0; char *iter,*end; @@ -1641,7 +1600,7 @@ mp_input_parse_config(char *file) { char name[end-iter+1]; strncpy(name,iter,end-iter); name[end-iter] = '\0'; - if(! mp_input_get_input_from_name(name,keys)) { + if (!get_input_from_name(name,keys)) { mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrUnknownKey,name); close(fd); return 0; @@ -1656,9 +1615,10 @@ mp_input_parse_config(char *file) { // Found new line if(iter[0] == '\n' || iter[0] == '\r') { int i; - mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrNoCmdForKey,mp_input_get_key_name(keys[0])); + char key_buf[12]; + mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrNoCmdForKey, get_key_name(keys[0], key_buf)); for(i = 1; keys[i] != 0 ; i++) - mp_msg(MSGT_INPUT,MSGL_ERR,"-%s",mp_input_get_key_name(keys[i])); + mp_msg(MSGT_INPUT,MSGL_ERR,"-%s", get_key_name(keys[i], key_buf)); mp_msg(MSGT_INPUT,MSGL_ERR,"\n"); keys[0] = 0; if(iter > buffer) { @@ -1684,7 +1644,7 @@ mp_input_parse_config(char *file) { strncpy(cmd,iter,end-iter); cmd[end-iter] = '\0'; //printf("Set bind %d => %s\n",keys[0],cmd); - mp_input_bind_keys(keys,cmd); + bind_keys(ictx, keys,cmd); n_binds++; } keys[0] = 0; @@ -1698,44 +1658,57 @@ mp_input_parse_config(char *file) { } mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrWhyHere); close(fd); - mp_input_set_section(NULL); + mp_input_set_section(ictx, NULL); return 0; } -void -mp_input_set_section(char *name) { - mp_cmd_bind_section_t* bind_section = NULL; - - cmd_binds=NULL; - cmd_binds_default=NULL; - if(section) free(section); - if(name) section=strdup(name); else section=strdup("default"); - if((bind_section=mp_input_get_bind_section(section))) - cmd_binds=bind_section->cmd_binds; - if(strcmp(section,"default")==0) return; - if((bind_section=mp_input_get_bind_section(NULL))) - cmd_binds_default=bind_section->cmd_binds; +void mp_input_set_section(struct input_ctx *ictx, char *name) +{ + mp_cmd_bind_section_t* bind_section = NULL; + + ictx->cmd_binds = NULL; + ictx->cmd_binds_default = NULL; + if (ictx->section) + 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(void) { - return section; +char *mp_input_get_section(struct input_ctx *ictx) +{ + return ictx->section; } -void -mp_input_init(int use_gui) { +struct input_ctx *mp_input_init(struct input_conf *input_conf, int use_gui) +{ + struct input_ctx *ictx = talloc_ptrtype(NULL, ictx); + *ictx = (struct input_ctx){ + .ar_state = -1, + .ar_delay = input_conf->ar_delay, + .ar_rate = input_conf->ar_rate, + }; + char* file; #ifdef CONFIG_GUI if(use_gui) - mp_input_add_binds(gui_def_cmd_binds); + add_binds(ictx, gui_def_cmd_binds); #endif + char *config_file = input_conf->config_file; file = config_file[0] != '/' ? get_path(config_file) : config_file; if(!file) - return; + return ictx; - if( !mp_input_parse_config(file)) { + if (!parse_config(ictx, file)) { // free file if it was allocated by get_path(), // before it gets overwritten if( file != config_file) @@ -1744,7 +1717,7 @@ mp_input_init(int use_gui) { } // Try global conf dir file = MPLAYER_CONFDIR "/input.conf"; - if(! mp_input_parse_config(file)) + if (!parse_config(ictx, file)) mp_msg(MSGT_INPUT,MSGL_V,"Falling back on default (hardcoded) input config\n"); } else @@ -1755,87 +1728,89 @@ mp_input_init(int use_gui) { } #ifdef CONFIG_JOYSTICK - if(use_joystick) { - int fd = mp_input_joystick_init(js_dev); + if (input_conf->use_joystick) { + int fd = mp_input_joystick_init(input_conf->js_dev); if(fd < 0) mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantInitJoystick); else - mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close); + mp_input_add_key_fd(ictx, fd, 1, mp_input_joystick_read, + (mp_close_func_t)close,NULL); } #endif #ifdef CONFIG_LIRC - if(use_lirc) { + if (input_conf->use_lirc) { int fd = mp_input_lirc_init(); if(fd > 0) - mp_input_add_cmd_fd(fd,0,mp_input_lirc_read,mp_input_lirc_close); + mp_input_add_cmd_fd(ictx, fd, 0, mp_input_lirc_read, + mp_input_lirc_close); } #endif #ifdef CONFIG_LIRCC - if(use_lircc) { + if (input_conf->use_lircc) { int fd = lircc_init("mplayer", NULL); if(fd >= 0) - mp_input_add_cmd_fd(fd,1,NULL,(mp_close_func_t)lircc_cleanup); + mp_input_add_cmd_fd(ictx, fd, 1, NULL, (mp_close_func_t)lircc_cleanup); } #endif #ifdef CONFIG_APPLE_REMOTE - if(use_ar) { + if (input_conf->use_ar) { if(mp_input_ar_init() < 0) mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantInitAppleRemote); else - mp_input_add_key_fd(-1,0,mp_input_ar_read,mp_input_ar_close); + mp_input_add_key_fd(ictx, -1, 0, mp_input_ar_read, mp_input_ar_close, + NULL); } #endif #ifdef CONFIG_APPLE_IR - if(use_ar) { - int fd = mp_input_appleir_init(ar_dev); + if (input_conf->use_ar) { + int fd = mp_input_appleir_init(input_conf->ar_dev); if(fd < 0) mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantInitAppleRemote); else - mp_input_add_key_fd(fd,1,mp_input_appleir_read,(mp_close_func_t)close); + mp_input_add_key_fd(ictx, fd, 1, mp_input_appleir_read, + (mp_close_func_t)close, NULL); } #endif - if(in_file) { + if (input_conf->in_file) { struct stat st; - if(stat(in_file,&st)) - mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantStatFile,in_file,strerror(errno)); + if (stat(input_conf->in_file, &st)) + mp_msg(MSGT_INPUT, MSGL_ERR, MSGTR_INPUT_INPUT_ErrCantStatFile, input_conf->in_file, strerror(errno)); else { - in_file_fd = open(in_file,S_ISFIFO(st.st_mode) ? O_RDWR : O_RDONLY); + int in_file_fd = open(input_conf->in_file, + S_ISFIFO(st.st_mode) ? O_RDWR : O_RDONLY); if(in_file_fd >= 0) - mp_input_add_cmd_fd(in_file_fd,1,NULL,(mp_close_func_t)close); + mp_input_add_cmd_fd(ictx, in_file_fd, 1, NULL, + (mp_close_func_t)close); else - mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantOpenFile,in_file,strerror(errno)); + mp_msg(MSGT_INPUT, MSGL_ERR, MSGTR_INPUT_INPUT_ErrCantOpenFile, + input_conf->in_file, strerror(errno)); } } - + return ictx; } -void -mp_input_uninit(void) { +void mp_input_uninit(struct input_ctx *ictx) +{ + if (!ictx) + return; + unsigned int i; - mp_cmd_bind_section_t* bind_section; - for(i=0; i < num_key_fd; i++) { - if(key_fds[i].close_func) - key_fds[i].close_func(key_fds[i].fd); + for (i=0; i < ictx->num_key_fd; i++) { + if (ictx->key_fds[i].close_func) + ictx->key_fds[i].close_func(ictx->key_fds[i].fd); } - for(i=0; i < num_cmd_fd; i++) { - if(cmd_fds[i].close_func) - cmd_fds[i].close_func(cmd_fds[i].fd); - } - while (cmd_binds_section) { - mp_input_free_binds(cmd_binds_section->cmd_binds); - free(cmd_binds_section->section); - bind_section=cmd_binds_section->next; - free(cmd_binds_section); - cmd_binds_section=bind_section; + for (i = 0; i < ictx->num_cmd_fd; i++) { + if (ictx->cmd_fds[i].close_func) + ictx->cmd_fds[i].close_func(ictx->cmd_fds[i].fd); } - cmd_binds_section=NULL; + talloc_free(ictx); } void @@ -1843,7 +1818,8 @@ mp_input_register_options(m_config_t* cfg) { m_config_register_options(cfg,mp_input_opts); } -static int mp_input_print_key_list(m_option_t* cfg) { +static int print_key_list(m_option_t* cfg) +{ int i; printf("\n"); for(i= 0; key_names[i].name != NULL ; i++) @@ -1851,7 +1827,8 @@ static int mp_input_print_key_list(m_option_t* cfg) { exit(0); } -static int mp_input_print_cmd_list(m_option_t* cfg) { +static int print_cmd_list(m_option_t* cfg) +{ const mp_cmd_t *cmd; int i,j; const char* type; @@ -1882,10 +1859,10 @@ static int mp_input_print_cmd_list(m_option_t* cfg) { exit(0); } -int -mp_input_check_interrupt(int time) { +int mp_input_check_interrupt(struct input_ctx *ictx, int time) +{ mp_cmd_t* cmd; - if((cmd = mp_input_get_cmd(time,0,1)) == NULL) + if ((cmd = mp_input_get_cmd(ictx, time, 0, 1)) == NULL) return 0; switch(cmd->id) { case MP_CMD_QUIT: @@ -1896,7 +1873,7 @@ mp_input_check_interrupt(int time) { return 1; } // remove the cmd from the queue - cmd = mp_input_get_cmd(time,0,0); + cmd = mp_input_get_cmd(ictx, time, 0, 0); mp_cmd_free(cmd); return 0; } |