Commit Graph

530 Commits

Author SHA1 Message Date
Dmitrij D. Czarkoff ea442fa047 mpv_talloc.h: rename from talloc.h
This change helps avoiding conflict with talloc.h from libtalloc.
2016-01-11 21:05:55 +01:00
wm4 f9ba1a3ddf demux: remove weird tripple-buffering for the sh_stream list
The demuxer infrastructure was originally single-threaded. To make it
suitable for multithreading (specifically, demuxing and decoding on
separate threads), some sort of tripple-buffering was introduced. There
are separate "struct demuxer" allocations. The demuxer thread sets the
state on d_thread. If anything changes, the state is copied to d_buffer
(the copy is protected by a lock), and the decoder thread is notified.
Then the decoder thread copies the state from d_buffer to d_user (again
while holding a lock). This avoids the need for locking in the
demuxer/decoder code itself (only demux.c needs an internal, "invisible"
lock.)

Remove the streams/num_streams fields from this tripple-buffering
schema. Move them to the internal struct, and protect them with the
internal lock. Use accessors for read access outside of demux.c.

Other than replacing all field accesses with accessors, this separates
allocating and adding sh_streams. This is needed to avoid race
conditions. Before this change, this was awkwardly handled by first
initializing the sh_stream, and then sending a stream change event. Now
the stream is allocated, then initialized, and then declared as
immutable and added (at which point it becomes visible to the decoder
thread immediately).

This change is useful for PR #2626. And eventually, we should probably
get entirely of the tripple buffering, and this makes a nice first step.
2015-12-23 21:52:16 +01:00
wm4 b0381d27eb input: add a catch-all "unmapped" command
This can be used to grab all unmapped keys.

Fixes #2612.
2015-12-23 19:13:45 +01:00
wm4 3e1aed8f40 input: add key name to script-binding command response
The "script-binding" command is used by the Lua scripting wrapper to
register key bindings on the fly. It's also the only way to get fine-
grained information about key events (such as separate key up/down
events). This information is sent via a "key-binding" message when the
state of a key changes.

Extend it to send name of the mapped key itself. Previously, it was
assumed that the user just uses an unique identifier for the binding's
name, so it wasn't needed. With this change, a user can map exactly the
same command to multiple keys, which is useful especially with the next
commit.

Part of #2612.
2015-12-23 19:10:48 +01:00
James Ross-Gowan 7558d1ed7b win32: input: use Vista CancelIoEx
libwaio was added due to the complete inability to cancel synchronous
I/O cleanly using the public Windows API in Windows XP. Even calling
TerminateThread on the thread performing I/O was a bad solution, because
the TerminateThread function in XP would leak the thread's stack.

In Vista and up, however, this is no longer a problem. CancelIoEx can
cancel synchronous I/O running on other threads, allowing the thread to
exit cleanly, so replace libwaio usage with native Vista API functions.

It should be noted that this change also removes the hack added in
8a27025 for preventing a deadlock that only seemed to happen in Windows
XP. KB2009703 says that Vista and up are not affected by this, due to a
change in the implementation of GetFileType, so the hack should not be
needed anymore.
2015-12-20 21:06:02 +11:00
wm4 392ae68e5f options: fix --no-config
This was completely broken. It was checked manually in some config
loading paths, so it appeared to work. But the intention was always to
completely disable reading from the normal config dir. This logic was
broken in commit 2263f37d.

The manual checks are actually redundant, and are not needed if
--no-config is implemented properly - remove them.

Additionally, the change to load the libmpv defaults from an embedded
profile also failed to set "config=no". The option is marked as not
being settable by a config file, and the libmpv default profile is
parsed as a config file, so this option was rejected. Fix it by removing
the CONF_NOCFG flag. (Alternatively, m_config_set_profile() could be
changed not to set the "config file" flag by default, but I'm not
bothering with this.)
2015-09-05 15:33:19 +02:00
wm4 caebbded67 command: define-section with empty contents removes a section 2015-08-06 00:17:30 +02:00
wm4 eaf1547afc input: improve wording of key binding messages 2015-06-30 00:43:16 +02:00
wm4 39a339c813 input: remove some unneeded things
Wakeup FDs are not needed anymore (this code exists only for libwaio
usage by now), and 2 other functions can be made private.
2015-05-26 22:00:25 +02:00
wm4 289705daaf input: allow - as separator between commands, instead of _
Wnile it seems quite logical to me that commands use _ as word
separator, while properties use -, I can't really explain the
difference, and it tends to confuse users as well. So always
prefer - as separator for everything.

Using _ still works, and will probably forever. Not doing so would
probably create too much chaos and confusion.
2015-05-25 21:59:44 +02:00
wm4 51120c9c7f input: filter out redundant mp_input_set_mouse_pos() calls
Prevents the OSC from showing up on start on Cocoa.
2015-05-08 22:00:24 +02:00
Marcin Kurczewski f43017bfe9 Update license headers
Signed-off-by: wm4 <wm4@nowhere>
2015-04-13 12:10:01 +02:00
Philip Sequeira 48dafda7e9 options: add M_OPT_FILE to --input-conf
Someday I'll look through all the options and find whatever else is
missing it...
2015-03-31 15:05:08 +02:00
wm4 9b5a7241e8 input: remove Linux joystick support
Why did this exist in the first place? Other than being completely
useless, this even caused some regressions in the past. For example,
there was the case of a laptop exposing its accelerometer as joystick
device, which led to extremely fun things due to the default mappings of
axis movement being mapped to seeking.

I suppose those who really want to use their joystick to control a media
player (???) can configure it as mouse device or so.
2015-03-24 16:04:44 +01:00
wm4 1e659a9f0f input: remove classic LIRC support
It's much easier to configure remotes as X11 input devices.
2015-03-24 16:04:44 +01:00
wm4 69e6e7b17c input: minor cleanup
Add MP_KEY_MOUSE_ENTER to the ignored input if the user has disabled
mouse input. Remove one instance of code duplication, and add a
MP_KEY_IS_MOUSE_MOVE macro to summarize events that are caused by moving
the mouse.
2015-02-18 21:12:57 +01:00
torque 3b269ac0a0 input: add MOUSE_ENTER keybinding.
Signed-off-by: wm4 <wm4@nowhere>
2015-02-18 00:03:16 +01:00
wm4 11d72b0999 input: handle mixing key press and up/down events better 2015-01-23 13:02:42 +01:00
wm4 3459130e5c client API: reasonable behavior if window is closed
Closing the video window sends CLOSE_WIN, which is normally mapped to
the "quit" command. The client API normally disables all key bindings,
and closing the window does nothing. It's simply left to the application
to handle this. This is fine - an embedded window can not be destroyed
by user interaction.

But sometimes, the window might be destroyed anyway, for example because
the containing window is destroyed. If this happens, CLOSE_WIN should
better not be ignored. We can't expect client API users to handle this
specially (by providing their own input.conf), so provide some fallback
for this pseudo key binding. The "quit" command might be too intrusive
(not every client necessarily handles "unexpected" MPV_EVENT_SHUTDOWN),
but I think it's still reasonable.
2015-01-12 12:53:49 +01:00
wm4 6e7942af50 input: add a hack to fix keyboard navigation with dvd/bd menu
If the user has LEFT/RIGHT/etc. bound in his input.conf, then these were
overriding the menu keys in dvdnav mode.

This hack works because the dvdnav crap happens to be the only user of
MP_INPUT_ON_TOP. If it finds a default key binding in the dvdnav menu
section, it will use that, instead of continuing search and possibly
finding the user key bindings meant for normal playback.
2014-12-04 22:42:06 +01:00
wm4 0c6d85f6c3 input, lua: make removing key bindings work
This just kept adding bindings to the input section, rather than
defining it. One bad effect was that mp.remove_key_binding() in Lua
didn't work.
2014-12-03 15:46:55 +01:00
wm4 d33ae93b89 input: simplify 2014-11-24 16:48:34 +01:00
wm4 5bbd734fff command: don't queue framesteps
If repeated framestep commands are sent, just unpause the player, instead
of playing N frames for N repeated commands.
2014-11-23 15:31:32 +01:00
wm4 ae5df9be98 input, lua: redo input handling
Much of it is the same, but now there's the possibility to distinguish
key down/up events in the Lua API.
2014-11-23 15:13:35 +01:00
wm4 4cdd346246 input: set mouse area by default for all input
Otherwise, mouse button bindings added by mp.add_key_binding() would be
ignored.

It's possible that this "breaks" some older scripts using undocumented
Lua script functions, but it should be safe otherwise.

Fixes #1283.
2014-11-23 09:10:51 +01:00
wm4 0a78a61d89 input: add a prefix to make any binding act on key repeat
The fact that it's a generic command prefix that is parsed even when
using the client API is a bit unclean (because this flag makes sense
for actual key-bindings only), but it's less code this way.
2014-11-20 23:41:01 +01:00
wm4 fb4d26e769 input: cascade-load input.conf
If there are several input.confs in the set of valid config paths, load
them all.
2014-10-29 22:54:03 +01:00
wm4 9ba6641879 Set thread name for debugging
Especially with other components (libavcodec, OSX stuff), the thread
list can get quite populated. Setting the thread name helps when
debugging.

Since this is not portable, we check the OS variants in waf configure.
old-configure just gets a special-case for glibc, since doing a full
check here would probably be a waste of effort.
2014-10-19 23:48:40 +02:00
Alessandro Ghedini 3deb6c3d4f input: implement --input-file on unix using the IPC support 2014-10-17 20:47:43 +02:00
wm4 c9f45ea93e input: use mpv_node parser for char** command parsers
Minor simplification, also drops some useless stuff.
2014-10-10 22:58:28 +02:00
Stefano Pigozzi dba2b90d9a libmpv/cocoa: don't start the event monitor
The event monitor is used to get keyboard events when there is no window, but
since it is a global monitor to the current process, we don't want it in a
library setting.
2014-10-09 22:14:41 +02:00
wm4 e294656cb1 client API: rename --input-x11-keyboard to --input-vo-keyboard
Apparently we need this for Cocoa too. (The option was X11 specific in
the hope that only X11 would need this hack.)
2014-10-09 18:28:37 +02:00
wm4 3273db1ef7 client API, X11: change default keyboard input handling again
Commit 64b7811c tried to do the "right thing" with respect to whether
keyboard input should be enabled or not. It turns out that X11 does
something stupid by design. All modern toolkits work around this native
X11 behavior, but embedding breaks these workarounds.

The only way to handle this correctly is the XEmbed protocol. It needs
to be supported by the toolkit, and probably also some mpv support. But
Qt has inconsistent support for it. In Qt 4, a X11 specific embedding
widget was needed. Qt 5.0 doesn't support it at all. Qt 5.1 apparently
supports it via QWindow, but if it really does, I couldn't get it to
work.

So add a hack instead. The new --input-x11-keyboard option controls
whether mpv should enable keyboard input on the X11 window or not. In
the command line player, it's enabled by default, but in libmpv it's
disabled.

This hack has the same problem as all previous embedding had: move the
mouse outside of the window, and you don't get keyboard input anymore.
Likewise, mpv will steal all keyboard input from the parent application
as long as the mouse is inside of the mpv window.

Also see issue #1090.
2014-09-28 20:11:00 +02:00
wm4 cbf7180c90 input: copy options automatically
Originally, all options were copied to ensure that input_ctx remins
thread-safe, even if options are changed asynchronously. But this got
a bit inconsistent. Copy them automatically and reduce some weirdness.
2014-09-27 16:25:29 +02:00
wm4 b4d1494336 input: separate creation and loading of config
Until now, creating the input_ctx was delayed until the command line
and config files were parsed. Separate creation and loading so that
input_ctx is available from start.

This should make it possible to simplify some things. For example,
some complications with Cocoa were apparently only because input_ctx
was available only "later". (Although I'm not sure if this is still
relevant, or if the Cocoa code should even be organized this way.)
2014-09-27 16:01:55 +02:00
wm4 5e6c9963d8 input: explain why we use semaphores
Also switch function names for better self-documentation.
2014-09-20 04:22:37 +02:00
Alexander Preisinger 30175538fe input: add locking for repeat info 2014-09-19 17:48:06 +02:00
Alexander Preisinger be516022b6 input: add function for setting repeat info
Let us set a different rate and delay.

Needed for the following commit where we set rate and delay reported by weston.
But only if the option native-keyrepeat is set.
2014-09-19 17:36:37 +02:00
wm4 e0b4daf3ad 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.
2014-09-14 16:24:01 +02:00
wm4 893f4a0fee input: distinguish playlist navigation and quit commands for abort
Refine the ugly hack from the previous commit, and let the "quit"
command and some others abort playback immediately. For
playlist_next/playlist_prev, still use the old hack, because we can't
know if they would stop playback or not.
2014-09-13 16:47:30 +02:00
wm4 2e91d44e20 stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.

The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.

libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.

There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.

As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 16:09:51 +02:00
wm4 a3b393d68c input: simplify
Just some minor things. In particular, don't call mp_input_wakeup()
manually, but make it part of queuing commands (as far as possible).
2014-09-13 01:14:07 +02:00
wm4 fc5df2b970 input: fix autorepeat
Mismatching units in timeout calculation.

Also, as a near-cosmetic change, explicitly wake up the core on the
right time. Currently this does nothing, because the core is woken up
anyway - but it will matter with the next commit.
2014-09-13 01:14:07 +02:00
wm4 e9b756c7ad input: remove central select() call
This is now unused. Get rid of it and all surrounding infrastructure,
and replace the remaining "wakeup pipe" with a semaphore.
2014-09-10 03:24:45 +02:00
wm4 ae63702a2c input: remove useless joystick.h/lirc.h include files
These really just waste space.
2014-09-10 00:51:36 +02:00
wm4 e2a093df02 input: use an input thread for joystick 2014-09-10 00:48:59 +02:00
wm4 fe0ca7559c input: use an input thread for lirc 2014-09-10 00:48:45 +02:00
wm4 5be678386b input: add convenience function for running input sources in threads 2014-09-10 00:48:12 +02:00
wm4 256fea7655 input: make some fields internal 2014-09-10 00:48:12 +02:00
wm4 28fc13977e terminal-unix: move to thread
Do terminal input with a thread, instead of using the central select()
loop. This also changes some details how SIGTERM is handled.

Part of my crusade against mp_input_add_fd().
2014-09-10 00:48:12 +02:00