summaryrefslogtreecommitdiffstats
path: root/input/input.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-08-24 23:50:43 +0200
committerwm4 <wm4@nowhere>2014-08-25 01:00:21 +0200
commit740f0f61d840255a02efcf392fece51486a59183 (patch)
tree55b91801f9c23badec307a21a945fda8725d8ad2 /input/input.h
parentcae22ae3b6e6d4c40ef6fc153a9538f8fea6b0e5 (diff)
downloadmpv-740f0f61d840255a02efcf392fece51486a59183.tar.bz2
mpv-740f0f61d840255a02efcf392fece51486a59183.tar.xz
input: redo how --input-file is handled
Abandon the "old" infrastructure for --input-file (mp_input_add_fd(), select() loop, non-blocking reads). Replace it with something that starts a reader thread, using blocking input. This is for the sake of Windows. Windows is a truly insane operating system, and there's not even a way to read a pipe in a non-blocking way, or to wait for new input in an interruptible way (like with poll()). And unfortunately, some want to use pipe to send input to mpv. There are probably (slightly) better IPC mechanisms available on Windows, but for the sake of platform uniformity, make this work again for now. On Vista+, CancelIoEx() could probably be used. But there's no way on XP. Also, that function doesn't work on wine, making development harder. We could forcibly terminate the thread, which might work, but is unsafe. So what we do is starting a thread, and if we don't want the pipe input anymore, we just abandon the thread. The thread might remain blocked forever, but if we exit the process, the kernel will forcibly kill it. On Unix, just use poll() to handle this. Unfortunately the code is pretty crappy, but it's ok, because it's late and I wanted to stop working on this an hour ago. Tested on wine; might not work on a real Windows.
Diffstat (limited to 'input/input.h')
-rw-r--r--input/input.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/input/input.h b/input/input.h
index de363cf33b..a8341d7773 100644
--- a/input/input.h
+++ b/input/input.h
@@ -94,7 +94,37 @@ typedef struct mp_cmd {
const struct mp_cmd_def *def;
} mp_cmd_t;
-/* Add a new command input source.
+struct mp_input_src {
+ struct mpv_global *global;
+ struct mp_log *log;
+ struct input_ctx *input_ctx;
+
+ char *cmd_buffer;
+ size_t cmd_buffer_size;
+ bool drop;
+
+ // If not-NULL: called before destroying the input_src. Should close the
+ // underlying device, and free all memory.
+ void (*close)(struct mp_input_src *src);
+
+ // For free use by the implementer.
+ void *priv;
+};
+
+/* Add a new input source. The input code can create a new thread, which feeds
+ * keys or commands to input_ctx. mp_input_src.close must be set.
+ */
+struct mp_input_src *mp_input_add_src(struct input_ctx *ictx);
+
+// Remove and free the source. You can call this only while the input_ctx
+// exists; otherwise there would be a race condition when another thread
+// destroys input_ctx.
+void mp_input_src_kill(struct mp_input_src *src);
+
+// Feed text data, which will be split into lines of commands.
+void mp_input_src_feed_cmd_text(struct mp_input_src *src, char *buf, size_t len);
+
+/* Add a new command input source. (Old version.)
* "fd" is a file descriptor (use -1 if you don't use any fd)
* "select" tells whether to use select() on the fd to determine when to
* try reading.
@@ -226,6 +256,8 @@ bool mp_input_use_alt_gr(struct input_ctx *ictx);
void mp_input_run_cmd(struct input_ctx *ictx, int def_flags, const char **cmd,
const char *location);
+void mp_input_add_pipe(struct input_ctx *ictx, const char *filename);
+
void mp_input_set_main_thread(struct input_ctx *ictx);
extern int async_quit_request;