summaryrefslogtreecommitdiffstats
path: root/input/input.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-14 16:21:04 +0200
committerwm4 <wm4@nowhere>2014-09-14 16:24:01 +0200
commite0b4daf3ad240ecf70af73c13b6ca9b1062a507f (patch)
treee52d79650aa69c0288dd5d9c896ab943c692f88f /input/input.h
parentb44571ababeb368e94df6665c1d370d817a51135 (diff)
downloadmpv-e0b4daf3ad240ecf70af73c13b6ca9b1062a507f.tar.bz2
mpv-e0b4daf3ad240ecf70af73c13b6ca9b1062a507f.tar.xz
input: use libwaio for pipe input on Windows
Use libwaio to read from pipes (stdin or named pipes) on Windows. This liberates us from nasty issues, such as pipes (as created by most programs) not being possible to read in a non-blocking or event-driven way. Although it would be possible to do that in a somewhat sane way on Vista+, it's still not easy, and on XP it's especially hard. libwaio handles these things for us. Move pipe.c to pipe-unix.c, and remove Windows specific things. Also adjust the input.c code to make this work cleanly.
Diffstat (limited to 'input/input.h')
-rw-r--r--input/input.h24
1 files changed, 14 insertions, 10 deletions
diff --git a/input/input.h b/input/input.h
index 7096ae62cb..ef8861eaf3 100644
--- a/input/input.h
+++ b/input/input.h
@@ -91,34 +91,38 @@ struct mp_input_src {
struct mp_input_src_internal *in;
- // 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);
+ // If not-NULL: called before destroying the input_src. Should unblock the
+ // reader loop, and make it exit. (Use with mp_input_add_thread_src().)
+ void (*cancel)(struct mp_input_src *src);
+ // Called after the reader thread returns, and cancel() won't be called
+ // again. This should make sure that nothing after this call accesses src.
+ void (*uninit)(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.
- */
+// Add a new input source. The input code can create a new thread, which feeds
+// keys or commands to input_ctx. mp_input_src.uninit must be set.
+// mp_input_src_kill() must not be called by anything after init.
struct mp_input_src *mp_input_add_src(struct input_ctx *ictx);
// Add an input source that runs on a thread. The source is automatically
// removed if the thread loop exits.
// ctx: this is passed to loop_fn.
// loop_fn: this is called once inside of a new thread, and should not return
-// until all input is read, or src->close is called by another thread.
+// until all input is read, or src->cancel is called by another thread.
// You must call mp_input_src_init_done(src) early during init to signal
-// success (then src->close may be called at a later point); on failure,
+// success (then src->cancel may be called at a later point); on failure,
// return from loop_fn immediately.
// Returns >=0 on success, <0 on failure to allocate resources.
-// Do not set src->close after mp_input_src_init_done() has been called.
+// Do not set src->cancel after mp_input_src_init_done() has been called.
int mp_input_add_thread_src(struct input_ctx *ictx, void *ctx,
void (*loop_fn)(struct mp_input_src *src, void *ctx));
// Signal successful init.
// Must be called on the same thread as loop_fn (see mp_input_add_thread_src()).
+// Set src->cancel and src->uninit (if needed) before calling this.
void mp_input_src_init_done(struct mp_input_src *src);
// Currently only with mp_input_add_thread_src().
@@ -241,7 +245,7 @@ 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_pipe_add(struct input_ctx *ictx, const char *filename);
void mp_input_joystick_add(struct input_ctx *ictx, char *dev);
void mp_input_lirc_add(struct input_ctx *ictx, char *lirc_configfile);