summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
Diffstat (limited to 'input')
-rw-r--r--input/input.c11
-rw-r--r--input/ipc.c66
-rw-r--r--input/pipe-unix.c59
3 files changed, 60 insertions, 76 deletions
diff --git a/input/input.c b/input/input.c
index 613d1ec3b0..c9a5bbe99c 100644
--- a/input/input.c
+++ b/input/input.c
@@ -165,7 +165,6 @@ struct input_opts {
int ar_delay;
int ar_rate;
char *js_dev;
- char *in_file;
int use_joystick;
int use_lirc;
char *lirc_configfile;
@@ -188,7 +187,6 @@ const struct m_sub_options input_config = {
OPT_PRINT("keylist", mp_print_key_list),
OPT_PRINT("cmdlist", mp_print_cmd_list),
OPT_STRING("js-dev", js_dev, CONF_GLOBAL),
- OPT_STRING("file", in_file, CONF_GLOBAL),
OPT_FLAG("default-bindings", default_bindings, CONF_GLOBAL),
OPT_FLAG("test", test, CONF_GLOBAL),
OPT_INTRANGE("doubleclick-time", doubleclick_time, 0, 0, 1000),
@@ -1296,13 +1294,14 @@ void mp_input_load(struct input_ctx *ictx)
ictx->win_drag = ictx->global->opts->allow_win_drag;
- if (input_conf->in_file && input_conf->in_file[0]) {
-#if !defined(__MINGW32__) || HAVE_WAIO
- mp_input_pipe_add(ictx, input_conf->in_file);
+#if defined(__MINGW32__)
+ if (ictx->global->opts->input_file && *ictx->global->opts->input_file)
+#if HAVE_WAIO
+ mp_input_pipe_add(ictx, ictx->global->opts->input_file);
#else
MP_ERR(ictx, "Pipes not available.\n");
#endif
- }
+#endif
}
static void clear_queue(struct cmd_queue *queue)
diff --git a/input/ipc.c b/input/ipc.c
index 7ce8aa3424..e76a9af5e6 100644
--- a/input/ipc.c
+++ b/input/ipc.c
@@ -31,6 +31,7 @@
#include "osdep/io.h"
#include "common/common.h"
+#include "common/global.h"
#include "common/msg.h"
#include "input/input.h"
#include "libmpv/client.h"
@@ -53,6 +54,7 @@ struct client_arg {
struct mp_log *log;
struct mpv_handle *client;
+ char *client_name;
int client_fd;
char *(*encode_event)(mpv_event *event);
@@ -432,6 +434,15 @@ error:
return output;
}
+static char *text_execute_command(struct client_arg *arg, bstr msg)
+{
+ char *cmd_str = bstrdup0(NULL, msg);
+ mpv_command_string(arg->client, cmd_str);
+ talloc_free(cmd_str);
+
+ return NULL;
+}
+
static int ipc_write(int fd, const char *buf, size_t count)
{
while (count > 0) {
@@ -576,26 +587,56 @@ done:
return NULL;
}
-static void ipc_start_client(struct MPContext *mpctx, int id, int fd)
+static void ipc_start_client(struct MPContext *mpctx, struct client_arg *client)
+{
+ client->client = mp_new_client(mpctx->clients, client->client_name),
+ client->log = mp_client_get_log(client->client);
+
+ pthread_t client_thr;
+ if (pthread_create(&client_thr, NULL, client_thread, client)) {
+ mpv_detach_destroy(client->client);
+ close(client->client_fd);
+ talloc_free(client);
+ }
+}
+
+static void ipc_start_client_json(struct MPContext *mpctx, int id, int fd)
{
struct client_arg *client = talloc_ptrtype(NULL, client);
- char *client_name = talloc_asprintf(client, "ipc-%d", id);
*client = (struct client_arg){
- .client = mp_new_client(mpctx->clients, client_name),
- .client_fd = fd,
+ .client_name = talloc_asprintf(client, "ipc-%d", id),
+ .client_fd = fd,
.encode_event = json_encode_event,
.execute_command = json_execute_command,
};
- client->log = mp_client_get_log(client->client);
+ ipc_start_client(mpctx, client);
+}
- pthread_t client_thr;
- if (pthread_create(&client_thr, NULL, client_thread, client)) {
- mpv_detach_destroy(client->client);
- close(client->client_fd);
- talloc_free(client);
+static void ipc_start_client_text(struct MPContext *mpctx, const char *path)
+{
+ int mode = O_RDONLY;
+ // Use RDWR for FIFOs to ensure they stay open over multiple accesses.
+ struct stat st;
+ if (stat(path, &st) == 0 && S_ISFIFO(st.st_mode))
+ mode = O_RDWR;
+ int client_fd = open(path, mode);
+ if (client_fd < 0) {
+ MP_ERR(mpctx, "Could not open pipe at '%s'\n", path);
+ return;
}
+
+ struct client_arg *client = talloc_ptrtype(NULL, client);
+ *client = (struct client_arg){
+ .client_name = "input-file",
+ .client_fd = client_fd,
+
+ .encode_event = NULL,
+ .execute_command = text_execute_command,
+ };
+
+ ipc_start_client(mpctx, client);
}
static void *ipc_thread(void *p)
@@ -668,7 +709,7 @@ static void *ipc_thread(void *p)
goto done;
}
- ipc_start_client(arg->mpctx, client_num++, client_fd);
+ ipc_start_client_json(arg->mpctx, client_num++, client_fd);
}
}
@@ -688,6 +729,9 @@ done:
void mp_init_ipc(struct MPContext *mpctx)
{
+ if (mpctx->global->opts->input_file && *mpctx->global->opts->input_file)
+ ipc_start_client_text(mpctx, mpctx->global->opts->input_file);
+
if (!mpctx->opts->ipc_path || !*mpctx->opts->ipc_path)
return;
diff --git a/input/pipe-unix.c b/input/pipe-unix.c
deleted file mode 100644
index 51eb315d6b..0000000000
--- a/input/pipe-unix.c
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include <poll.h>
-
-#include "common/msg.h"
-#include "osdep/io.h"
-#include "input.h"
-#include "cmd_parse.h"
-
-static void read_pipe_thread(struct mp_input_src *src, void *param)
-{
- void *tmp = talloc_new(NULL);
- char *filename = talloc_strdup(tmp, param); // param deallocates after init
- int wakeup_fd = mp_input_src_get_wakeup_fd(src);
- int fd = -1;
-
- struct mp_log *log = src->log;
-
- int mode = O_RDONLY;
- // Use RDWR for FIFOs to ensure they stay open over multiple accesses.
- struct stat st;
- if (stat(filename, &st) == 0 && S_ISFIFO(st.st_mode))
- mode = O_RDWR;
- fd = open(filename, mode);
- if (fd < 0) {
- mp_err(log, "Can't open %s.\n", filename);
- goto done;
- }
-
- mp_input_src_init_done(src);
-
- while (1) {
- struct pollfd fds[2] = {
- { .fd = fd, .events = POLLIN },
- { .fd = wakeup_fd, .events = POLLIN },
- };
- poll(fds, 2, -1);
- if (!(fds[0].revents & POLLIN))
- break;
- char buffer[128];
- int r = read(fd, buffer, sizeof(buffer));
- if (r <= 0)
- break;
- mp_input_src_feed_cmd_text(src, buffer, r);
- }
-
-done:
- close(fd);
- talloc_free(tmp);
-}
-
-void mp_input_pipe_add(struct input_ctx *ictx, const char *filename)
-{
- mp_input_add_thread_src(ictx, (void *)filename, read_pipe_thread);
-}