Commit Graph

1057 Commits

Author SHA1 Message Date
Kacper Michajłow 52cabca4e5 osdep/io: expand path before LoadLibrary
Fixes compatibility with loading scripts from relative config paths.

Fixes #13212
2024-01-22 14:41:46 +00:00
Kacper Michajłow 13ed292ab0 terminal: don't print escape sequence if not tty 2024-01-15 10:39:42 +01:00
NRK ab60ad8619 terminal-unix: don't install handler before pipe 2024-01-15 10:39:42 +01:00
NRK b75b56f910 terminal-unix: move all processing out of sighandler
commit fa9e1f06f tried to move signal unsafe operations out of
signal handlers but mistakenly introduced a race. before,
sigtstop would process the following in order:

0. do_deactivate_getch2();
1. raise(SIGTSTP)

that commit moved 0 out of the signal handler (due to it being
unsafe) but kept 1 in there. this may mess up the ordering of
these operations. this commit moves everything out of the
handler so that things happen in proper order.

since things are now moved out of the handler, SA_RESETHAND is
no longer being applied to SIGTSTP. since that can result in
races if multiple signals are delivered faster than we can
respond to them.
2024-01-15 10:39:42 +01:00
llyyr f33a4d2fd9 terminal-unix: don't set `SA_RESETHAND` for SIGTERM/SIGQUIT
This can cause mpv to abruptly quit without following the proper uninit
process when a second `SIGTERM` or `SIGQUIT` is sent and mpv
didn't quit on the first one already. This is because the default action
for these signals is to terminate the program immediately, similar to
`SIGKILL`, and `SA_RESETHAND` resets the `quit_request_sighandler` to
`SIG_DFL` for the default action.

Also keep the `SA_RESETHAND` flag for SIGINT because the current
behavior is to quit after receiving two Ctrl+C no matter what, this is
probably convenient and worth keeping.

This change is because some tools (e.g. GNU timeout) send SIGTERM twice
after the timeout period.

An easy way to reproduce is with `timeout 1 mpv [...]` where mpv would
quit abruptly anywhere from half the time to once every 50 attempts
depending on your luck.
2024-01-14 23:10:50 +01:00
sfan5 9565675488 various: use correct PATH_MAX for win32
In commit c09245cdf2
long-path support was enabled for mpv without actually
making sure that there was no code left that used the
old limit (260 Unicode chars) for buffer sizes.
This commit fixes all but one case.
2023-12-27 22:55:56 +01:00
sfan5 f57ec94d9f osdep: clarify and rename a constant on win32
This is about the maximum filename not path length.
2023-12-27 22:55:56 +01:00
Ikko Eltociear Ashimine dd48a53b65 various: fix capitalization of 'GitHub' 2023-12-27 22:11:58 +01:00
Andarwinux e832f4969f win32: opt in to the windows segment heap
ref: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests#heaptype

Improves demuxer cache recycling speed at the cost of a slight CPU usage increase.
SegmentHeap is supported in Windows 10, version 2004 (build 19041) and later.
2023-12-22 16:36:31 +01:00
stax76 c09245cdf2 win32: support long file paths 2023-12-21 17:40:45 +01:00
Guido Cella 17be6e1990 terminal-unix: enable the cursor after ctrl+z
24270b8587 disabled the cursor while mpv is running, but if you send mpv
to the background, it is not re-enabled until you run bg, and not even
after that if mpv is paused. Fix this by enabling the cursor from the
SIGTSTP handler.
2023-12-18 15:03:40 +00:00
der richter c661435648 mac: add support for drag-and-drop option 2023-12-15 16:59:52 +01:00
nanahi 79068baf43 win32: properly handle WM_XBUTTONUP and WM_XBUTTONDOWN
According to MS documentation, an application should return TRUE from
WM_XBUTTONUP and WM_XBUTTONDOWN if it processes these messages.
DefWindowProc generates the WM_APPCOMMAND message when it processes the
WM_XBUTTONUP message, so if an application properly handles WM_XBUTTONUP
messages, extra WM_APPCOMMAND messages won't be generated.

Because mpv doesn't properly handle these messages,
WM_XBUTTONUP causes APPCOMMAND_BROWSER_BACKWARD to be generated, resulting
in duplicated keys and improper fix 438ead7a, which prevents the processing
of the appcommand from sources other than mouse clicks.

Fix this by following the documentation, and the back and forward
appcommands can be added.
2023-12-06 11:07:37 +01:00
der richter f551a9da34 mac: report modifier keys on precise scrolling
modifier keys weren't reported when using the trackpad to scroll.

Fixes #11195
2023-12-02 14:59:59 +01:00
Dudemanguy f7402ff466 Reapply "osdep/meson: add libplacebo include dir to swift compile"
It's not actually related to libplacebo wrap stuff and the swift compile
command needs this to get the right libplacebo include path.

This reverts commit b9d392ecd9.
2023-11-27 15:00:35 -06:00
Dudemanguy b9d392ecd9 Revert "osdep/meson: add libplacebo include dir to swift compile"
This is not needed since we removed the libplacebo wrap not too long
after this commit.

This reverts commit 4de76ce87a.
2023-11-27 20:44:07 +00:00
der richter 3f2bc2e535 mac: fix libmpv usage without embedding
NSApp is only an Application when initialised from mpv itself. when used
via libmpv an Application is never initialised and mpv would always
immediately exit.

make the retrieval of the vo and mac options static so they can be
retrieved in all cases.

Fixes #12518
2023-11-25 19:04:07 +01:00
der richter 5aac4c1aee mac: cleanup some unused and unneeded code 2023-11-25 19:04:07 +01:00
Kacper Michajłow bdf4dca505 osdep/io: add PRINTF_ATTRIBUTE for printf overrides 2023-11-25 12:38:20 +01:00
Kacper Michajłow ed107c4116 meson: adjust win32 defines
- Don't define _GNU_SOURCE on Windows, no need
- Define WIN32_LEAN_AND_MEAN to strip some unneded headers from
  windows.h
- Define NOMINMAX and _USE_MATH_DEFINES as they are common for Windows
  headers
2023-11-25 12:38:20 +01:00
Kacper Michajłow ab8cc64b19 osdep/macosx: add default switch cases to suppress Wswitch 2023-11-24 10:05:09 +01:00
der richter eb71aa059a mac: add rotation menubar entries 2023-11-20 23:16:43 +01:00
Kacper Michajłow d30432ea31 win32: don't jump over variable init with goto
Those variables are accessed after jump.
2023-11-18 23:55:28 +00:00
Daniel Brookman aa8af2e66b osxbundle: remove mpv-bundle symlink to allow code signing
Apps on Apple silicon have to be codesigned to run, but you can't
codesign bundles that have a symlink for the main executable.

The "mpv-bundle" symlink was used as the bundle's main executable
because it makes the execution name of the binary different.
Launch Services runs the CFBundleExecutable key from Info.plist when
launching a bundle, so by comparing the execution name to the name of
the symlink, you can check if that's how the binary was launched.

This replaces that detection method by moving the MPVBUNDLE
environmental variable into Info.plist. Launch Services will set
anything in LSEnvironment as environmental variables before launching
the bundle, so we're able to check for it instead of needing to
differentiate the execution name of the binary.

Fixes #12116
2023-11-15 23:08:11 +01:00
Kacper Michajłow 438ead7a3d osdep/w32_keyboard: remove duplicated MP_KEY_BACK mapping
MP_MBTN_BACK is already mapped, the appcmd duplicates this.

Fixes: #12768
Fixes: 8301906
2023-11-11 03:34:00 +00:00
der richter a54cc02341 mac: change display name retrieval to localizedName NSScreen property
the old displayName property via the IODisplay API is not working
anymore on ARM based macs and was broken in at least one other case.

instead we use the new localizedName property introduced in 10.15 of the
NSScreen. we don't need any backwards compatibility since 10.15 is the
oldest version we support now.

configs and scripts that use the options and properties fs-screen-name,
screen-name or display-names need to be adjusted since the names could
differ from the previous implementation via the IODisplay API.

Fixes #9697
2023-11-10 14:30:32 +01:00
sfan5 8f8b63d622 osdep/io: implement rename() wrapper
This is needed to provide the POSIX behaviour of transparently
overwriting existing paths.
2023-11-10 11:26:10 +01:00
Kacper Michajłow 7d86807a5f vo: don't sleep 1ms always when requested time is in the past
Fixes a899e14b which changed clamp from 0 to 1 ms which effectivelly
introduced 1ms sleep always, even if requested until_time_ns is in the
past and should request 0 timeout.

While at it also fix mp_poll wrapper to respect negative timeout which
should mean infinite wait.

Also keep the 37d6604 behaviour for very short timeouts, but round only
the ones > 100us, anything else is 0.

Fixes: a899e14b
2023-11-09 21:31:58 +00:00
der richter 23de1deaaa mac: remove runtime checks and compatibility for macOS older than 10.15
we stopped supporting macOS older than 10.15 and hence can remove all
the unnecessary runtime checks and compatibility layers.
2023-11-09 18:12:25 +00:00
Dudemanguy a5bf211e12 meson: remove several macos-10-* build options
These have been build options since the waf build, but that doesn't
really make sense. The build can detect whatever macOS sdk version is
available and then use that information to determine whether to enable
the features or not. Potentially disabling multiple sdk versions doesn't
really make any sense. Because f5ca11e12b
effectively made macOS 10.15 the minimum supported version, we can drop
all of these checks and bump the required sdk version to 10.15. The rest
of the build simplifies from there.
2023-11-09 18:12:25 +00:00
Thomas Weißschuh 4a134f441d audio: introduce ao_read_data_nonblocking()
This behaves similar to ao_read_data() but does not block and may return
partial data.
2023-11-08 20:26:23 +01:00
Kacper Michajłow a5c32ea52e threads-win32: add comment about local decl of a function 2023-11-08 04:32:10 +00:00
Kacper Michajłow 2ae56e78dd threads-win32: support UWP in mp_thread_set_name 2023-11-08 04:32:10 +00:00
Kacper Michajłow fa0929bf71 osdep/threads-posix: use CLOCK_MONOTONIC if supported 2023-11-08 04:32:10 +00:00
Kacper Michajłow 0a6c179026 osdep/timer-linux: check clock availability on init 2023-11-08 04:32:10 +00:00
Kacper Michajłow a7186777de threads: unbreak mpv on builds without asserts
Also remove duplicated macro.

Fixes: #12818 #12820
2023-11-06 04:14:49 +00:00
Kacper Michajłow e268dead30 win32/pthread: remove unused code 2023-11-05 17:36:17 +00:00
Kacper Michajłow 71e888c2a0 timer: remove unused code 2023-11-05 17:36:17 +00:00
Kacper Michajłow 751790c2b3 threads: remove unused code 2023-11-05 17:36:17 +00:00
Kacper Michajłow f75fe33da7 threads: rename threads.c to threads-posix.c 2023-11-05 17:36:17 +00:00
Kacper Michajłow 1e0aaab78c threads: move pthread debug to threads-posix.h
And remove redundant define while at it.
2023-11-05 17:36:17 +00:00
Kacper Michajłow 56d35da180 mp_thread: add win32 implementation 2023-11-05 17:36:17 +00:00
Kacper Michajłow 55ed50ba90 mp_thread: prefer tracking threads with id
This change essentially removes mp_thread_self() and instead add
mp_thread_id to track threads and have ability to query current thread
id during runtime.

This will be useful for upcoming win32 implementation, where accessing
thread handle is different than on pthreads. Greatly reduces complexity.
Otherweis locked map of tid <-> handle is required which is completely
unnecessary for all mpv use-cases.

Note that this is the mp_thread_id, not to confuse with system tid. For
example on threads-posix implementation it is simply pthread_t.
2023-11-05 17:36:17 +00:00
Kacper Michajłow 174df99ffa ALL: use new mp_thread abstraction 2023-11-05 17:36:17 +00:00
Kacper Michajłow 3a8b107f62 threads: add new mp_thread abstraction
This will allow to avoid hacky pthreads symbols/header override.

Inspired by pl_thread from libplacebo.
2023-11-05 17:36:17 +00:00
Guido Cella 040622f6b7 various: remove trailing whitespace 2023-10-30 16:45:47 +00:00
Dudemanguy 891efca9d7 timer-linux: fallback to CLOCK_MONOTONIC instead of timespec_get
CLOCK_MONOTONIC_RAW is linux-specific (macOS later supported it but it
has its own timer code) and not neccessarily available everywhere like
on BSDs. It makes sense to prefer it because mpv does a lot of
measurements at small intervals (e.g. every frame) so theoretically it
should be more accurate. However if the OS doesn't have it, fallback to
CLOCK_MONOTONIC instead which is almost exactly the same and very widely
supported across unix-like systems. This clock is technically optional
according to POSIX, but any half-decent OS supports it anyway (sorry
Solaris users). As a benefit, we now know that the clock from mp_time is
always monotonic.
2023-10-27 23:19:07 +00:00
Kacper Michajłow cb829879af mp_threads: rename threads for consistent naming across all of them
I'd like some names to be more descriptive, but to work with 15 chars
limit we have to make some sacrifice.

Also because of the limit, remove the `mpv/` prefix and prioritize
actuall thread name.
2023-10-27 23:18:56 +00:00
NRK 8bbcc87fee timer: remove MP_START_TIME
instead require mp_raw_time_ns() to not return 0, which all current
implementation already should follow.
2023-10-27 18:07:19 +00:00
Kacper Michajłow 729f2fed2c semaphore_osx: change mp_sem_timedwait to mp_time 2023-10-26 20:06:14 +00:00
Kacper Michajłow f659a60dfa semaphore_osx: don't overwrite global symbols 2023-10-26 20:06:14 +00:00
Kacper Michajłow 34d99840a5 timer: use MP_TIME macros 2023-10-26 16:49:38 +00:00
Kacper Michajłow 032b7de97f osdep/timer-win2: rename to timer-win32 2023-10-25 19:30:39 +00:00
llyyr 06c26e37ed osdep: fix clang warnings with `_FORTIFY_SOURCE`
This fixes warnings generated for `-Wunused-result` when mpv is built
with `-O1 -D_FORTIFY_SOURCE=1` or higher on clang since read/write
functions are declared with the `warn_unused_result` attribute.
Cast to void to avoid these warnings.
2023-10-24 22:49:22 +02:00
Kacper Michajłow 4de76ce87a osdep/meson: add libplacebo include dir to swift compile 2023-10-24 01:30:22 +00:00
NRK 8dc12f1d5b osdep: remove alignof emulation
it's unused. and since C11 is pretty freely used now, new code can just
use _Alignof or include <stdalign.h> directly.
2023-10-23 00:10:42 +00:00
Dudemanguy 94b67355c2 timer: drop ancient macOS fallback
macOS didn't support clock_gettime until 10.12 which was released
roughly 7 years ago. Since we're breaking support for ancient OSes
anyway, we might as well break some old macOS versions for fun. This
makes 10.12 the minimum supported macOS version.
2023-10-21 14:05:22 +00:00
sfan5 97afea441b win32/pthread: fix calculation error in pthread_cond_timedwait
closes #12699
2023-10-21 15:56:01 +02:00
Thomas Weißschuh dd13412986 win32/pthread: add support for pthread_mutex_trylock 2023-10-20 21:33:46 +02:00
Thomas Weißschuh 2181159158 threads: add support for pthread_mutex_trylock 2023-10-20 21:33:46 +02:00
NRK d05ef7fdc4 various: sort some standard headers
since i was going to fix the include order of stdatomic, might as well
sort the surrouding includes in accordance with the project's coding
style.

some headers can sometime require specific include order. standard
library headers usually don't. but mpv might "hack into" the standard
headers (e.g pthreads) so that complicates things a bit more.

hopefully nothing breaks. if it does, the style guide is to blame.
2023-10-20 21:31:09 +02:00
NRK 450a69b1d6 various: remove ATOMIC_VAR_INIT
the fallback needed it due to the struct wrapper. but the fallback is
now removed so it's no longer needed.

as for standard atomics, it was never really needed either, was useless
and then made obsolete in C17 and removed in C23.

ref: https://gustedt.wordpress.com/2018/08/06/c17-obsoletes-atomic_var_init/
ref: https://en.cppreference.com/w/c/atomic/ATOMIC_VAR_INIT
2023-10-20 21:31:09 +02:00
NRK 2070331f64 osdep: remove atomic.h
replace it with <stdatomic.h> and replace the mp_atomic_* typedefs with
explicit _Atomic qualified types.

also add missing config.h includes on some files.
2023-10-20 21:31:09 +02:00
NRK 2fa695c3f9 osdep: drop atomic fallback
even msvc (which mpv apparently doesn't support) supports C11 atomics
now. no need to carry around fallback with subtle semantic differences.
2023-10-20 21:31:09 +02:00
sfan5 3fb4eb2ba4 win32/pthread: try to fix system headers leaking through 2023-10-20 21:30:51 +02:00
sfan5 66c3110a85 win32/pthread: implement clock_gettime for high-res timer purposes
Also apply some fixes to pthread_cond_timedwait while we're at it.

Note that by using GetSystemTimePreciseAsFileTime here we lose support
for Windows 7. This is considered acceptable.
2023-10-20 21:30:51 +02:00
sfan5 9f147496b5 Revert "win32/pthread: don't convert time through unrelated timer"
This reverts commit 318b5471a1.

While it may work, changing these two functions in violation of their documented
behaviour for the sake of a shortcut is a hack that will spell disaster sooner or later.

This is a partial revert since the commit in question also contained a hidden
bugfix where it swapped the calculation order for time_rel.
2023-10-20 21:30:51 +02:00
Dudemanguy b8950f8d95 poll_wrapper: use the actual correct timeout for ppoll
It's not absolute time. Fixes #12660.
2023-10-17 15:05:33 +00:00
Dudemanguy 8f432b2e37 timer: remove microsecond timer functions
With the previous series of commits, all internal usage has been
replaced by the nanosecond functions. There's not really any point in
keeping these around anymore plus there are macros for unit conversions
now so we can just axe them. It's worth noting that mpv_get_time_us()
obviously still needs to work for API reasons, but we can just divide
mp_time_ns() by 1000 to get the same thing.
2023-10-16 15:38:59 +00:00
Dudemanguy 5cda1a5deb demux: convert cache updates to nanoseconds
As a bonus, we can remove the awkward and horribly named MP_SECOND_US.
2023-10-16 15:38:59 +00:00
Dudemanguy de9b800879 timer: add convenience time unit conversion macros
There's a lot of wild 1e6, 1000, etc. lying around in the code. A macro
is much easier to read and understand at a glance. Add some helpers for
this. We don't need to convert everything now but there's some simple
things that can be done so they are included in this commit.
2023-10-16 15:38:59 +00:00
der richter 78d43740f5 vo_gpu/vo_gpu_next: add vulkan support for macOS
add support for vulkan through metal and a translation layer like
MoltenVK. also add the possibility to use different render timing modes
for testing.

i still consider this experimental atm.
2023-10-14 18:39:56 +02:00
NRK fa9e1f06ff terminal-unix: make stop/cont sighandlers pipe based
there are currently some silly data-races in the stop/cont sighandler
due to the fact that the signal handler might get invoked in a different
thread.

this changes those sighandlers to a pipe-based approach similar to the
existing "quit" sighandler.
2023-10-13 11:36:01 +02:00
NRK c2d0a4a80f terminal-unix: avoid data race + simplify
tio_orig and tio_orig_set are being touched inside of signal handler
which might be invoked from another thread - which makes this a data
race.

there's no real reason to set tio_orig inside of do_activate_getch2()
which is registered as a signal handler. just set it once, in
terminal_init(), before any signal handlers come in play.

this also allows removing the tio_orig_set variable completely.
2023-10-13 11:36:01 +02:00
NRK 1abe908e31 terminal-unix: avoid data-race on do_deactivate_getch2
do_deactivate_getch2() touches some global variables which *might have*
been fine if the terminal thread was the one that received the signal
but AFAIK which thread will handle the signal is not well defined.

in my case, when quitting mpv with CTRL+C the main thread receives the
signal rather than the terminal thread and touches those globals without
synchronization. caught by ThreadSanitizer.

the solution is to move the do_deactivate_getch2() call outside of the
signal handler.
2023-10-13 11:36:01 +02:00
NRK 0b3d60afde terminal-unix: don't spoil errno in signal handler
otherwise the resuming code might end up seeing a spoiled errno and end
up taking unintended branches based on it.

caught via ThreadSanitizer
2023-10-13 11:36:01 +02:00
Kacper Michajłow a27d402f37 osdep/timer-win2: use Waitable Timer for sleeping
Allows higher resolution sleeps than Sleep which has milliseconds
resolution. In practice Windows kernel does not really go below 0.5ms,
but we don't have to limit ourselves on API side of things and do the
best we can.
2023-10-10 19:10:55 +00:00
Dudemanguy 59dd7d94af timer: change mp_sleep_us to mp_sleep_ns
Linux and macOS already use nanosecond resolution for their sleep
functions. It was just being converted from microseconds before. Since
we have mp_time_ns now, go ahead and bump the precision here. The timer
for windows uses some timeBeginPeriod thing which I'm not sure what it
does really but whatever just convert the units to ms like they were
doing before. There's really no reason to keep the mp_sleep_us helper
around. A multiplication by 1000 is trivial and underlying OS clocks
have nanosecond precision.
2023-10-10 19:10:55 +00:00
Dudemanguy 5d44cf93df vo: use mp_poll wrapper in wait_events when applicable
On linux, several platforms poll for events over a fd. This has ms
accuracy, but mpv's timer is in ns now so lots of precision is lost. We
can use an mp_poll wrapper to use ppoll instead which takes a timespec
directly with nanosecond precision. On systems without ppoll this falls
back to old poll behavior. On wayland, we don't actually use this
because ppoll completely messes up the event loop for some unknown
reason.
2023-10-10 19:10:55 +00:00
Dudemanguy ba4b408b8b osdep: rename polldev to poll_wrapper
Originally, this was added as purely a shim for macOS. However since we
want to do high resolution polling which is not neccesarily available on
all platforms, making this a generic wrapper for poll functions is
useful so rename it.
2023-10-10 19:10:55 +00:00
Dudemanguy 84fa7ea411 msg: use nanosecond precision
The timestamps when making a log file is actually dependent on
MP_START_TIME. This is a 10 microsecond offset that was added to the
timer as an offset. With the nanosecond change, this unit needs to be
converted as well so the offset is the same as before. After doing that,
we need to change the various mp_time_us calls in msg to mp_time_ns and
do the right conversion. This fixes the logs timestamps (i.e. so they
aren't negative anymore).
2023-09-29 18:20:30 -05:00
Kacper Michajłow cdfd5c280a win32/pthread: define _POSIX_TIMERS to notify they are not supported 2023-09-29 20:48:58 +00:00
Kacper Michajłow 318b5471a1 win32/pthread: don't convert time through unrelated timer
Just keep it directly as mp_time for internal implementation.
2023-09-29 20:48:58 +00:00
Kacper Michajłow 9606c3fca9 timer: teach it about nanoseconds
Those changes will alow to change vsync base to more precise time base.
In general there is no reason to truncate values returned by system.
2023-09-29 20:48:58 +00:00
Kacper Michajłow 40e0fea6eb timer: rename mp_add_timeout to reflect what it actually does 2023-09-29 20:48:58 +00:00
Kacper Michajłow f338420fd2 timer: remove dead code
This is not a proper way to do unit tests or whatever that was.
2023-09-29 20:48:58 +00:00
Kacper Michajłow 1a529ee1d5 timer: simplify mp_time_us_to_realtime 2023-09-29 20:48:58 +00:00
Kacper Michajłow da4c4d2ebd timer: rename mp_time_us_to_timespec to reflect what it actually does 2023-09-29 20:48:58 +00:00
Dudemanguy 969c19c9cb options: remove ancient option fallbacks/deprecation
We've got an ungodly amount of OPT_REPLACED and OPT_REMOVED sitting
around in the code. This is harmless, but the vast majority of these are
ancient. 26f4f18c06 is the last commit
that touched the majority of these and of course that only changed how
options were declared so all of this stuff was deprecated even before
that. No use in keeping these, so just delete them all. As an aside,
there was actually a cocoa_opts but it had only a single option which
was replaced by something else and empty otherwise. So that entire thing
was just simply removed. OPT_REPLACED/OPT_REMOVED declarations that were
added in 0.35 or later were kept as is.
2023-09-21 16:06:29 +00:00
chuck- adb118290b osdep/io: provide dlopen, etc. abstraction wrappers for windows 2023-09-20 02:16:45 +00:00
Dudemanguy 499dce5ba1 path-{darwin,unix}: save cache to subdir when using non-XDG path
mpv saves cache by default nowadays, but vo_gpu is pretty spammy and
saves a bunch of files per shader. If someone is using the non-XDG
config directory, this all gets dumped directly into ~/.mpv which isn't
so nice. Save it to a sub directory called "cache" instead (or
alternatively submit to your XDG overlords). For unfortunate reasons,
macOS uses XDG_CONFIG_HOME and has the same legacy fallback mechanism,
so this applies to it too.
2023-09-07 13:59:49 +00:00
Kacper Michajłow 7f7513132f win32: allow heap cache optimization and memory decommit 2023-09-01 16:58:56 +02:00
Kacper Michajłow 4f2a12110f win32: add BASE_SEARCH_PATH_PERMANENT to SetSearchPathMode 2023-09-01 16:58:56 +02:00
Kacper Michajłow 957118864c win32: don't load dynamically always available functions
They are all available on Windows 7 and newer.
2023-09-01 16:58:56 +02:00
Kacper Michajłow 3ab5401b38 player/command: remove video-aspect property
4 years is enough of deprecation period.
2023-08-31 17:37:42 +00:00
Christoph Heinrich 8301906218 input: add missing windows multimedia keys
x11 and wayland had a lot of multimedia keys mapped that were missing
on windows.
Now the only ones they map that windows doesn't are `MP_KEY_WWW`,
`MP_KEY_ZOOMIN` and `MP_KEY_ZOOMOUT`, which apparently don't have any
equivalent ones on windows.
2023-08-27 16:14:27 +00:00
Christoph Heinrich 0c9d8619e8 input: add missing keypad key defines
So far all the keypad keys except for `0` and `,` mapped to the same
MP_KEY_* independent of numlock state, even though different key codes
are received.
Now all the alternative functions map to appropriate MP_KEY_* defines,
with missing ones added.
2023-08-25 15:55:31 +00:00
NRK 9ff2caff98 path-unix: abort on path truncation
instead of silently proceeding with a truncated path.
2023-08-12 00:20:27 +03:00
Dudemanguy 0bed2a2263 build: remove outdated generated directory
This only existed as essentially a workaround for meson's behavior and
to maintain compatibility with the waf build. Since waf put everything
in a generated subdirectory, we had to put make a subdirectory called
"generated" in the source for meson so stuff could go to the right
place. Well now we don't need to do that anymore. Move the meson.build
files around so they go in the appropriate place in the subdirectory of
the source tree and change the paths of the headers accordingly. A
couple of important things to note.

1. mpv.com now gets made in build/player/mpv.com (necessary because of
   a meson limitation)
2. The macos icon generation path is shortened to
   TOOLS/osxbundle/icon.icns.inc.
2023-07-31 19:00:06 +00:00
Kacper Michajłow 5fc305fa17 path-win: move state directory to %LOCALAPPDATA%
%LOCALAPPDATA% is where the local application state belongs.
2023-07-29 14:27:59 +00:00
Kacper Michajłow aa05c06873 path-win: add subdirectory for cache
To not polute %LOCALAPPDATA%/mpv as it may be used for other things too.
2023-07-29 14:27:59 +00:00
rcombs 4ac5e6c810 language-posix: as a fallback, treat "C" as "en"
If we see "C" in one of the language vars we check, don't treat it as a language tag.
Once we've checked everything, if we don't have any languages, but saw "C" anywhere, fall back on "en".
2023-07-25 11:34:06 +02:00
NRK 2dc8e70093 terminal-unix: fix not listening on input after being foregrounded
fixes regression caused by 2e7fcc5a2 where it wouldn't receive terminal
input if the process was foregrounded later on like this:

    $ mpv something.mp4 &
    $ fg

ref: https://github.com/mpv-player/mpv/issues/11795
2023-07-21 20:47:03 +02:00
m154k1 b077cf72df player: set default cache dir on macOS
Use ~/Library/Caches/io.mpv for caches instead of ~~home.
2023-07-15 23:56:57 +00:00
Dudemanguy d482bf6ef0 path-win: implement cache directories
4502522a7a implemented cache directories
but only on linux which meant other OSes continued to save this stuff in
their config directory. Since we turned on cache by default, people are
getting cache files in there which is understandably causing some
confusion. Let's go ahead and implement a separate cache directory for
windows since there seems to be some established conventions for this
already. For people using the portable_path, the cache is saved in a
subdirectory within the portable_path since the idea is for that to be
completely self contained.
2023-07-15 15:10:41 +00:00
NRK 2e7fcc5a2a terminal-unix: better error detection logic
the reason for checking `EBADF|EINVAL` specifically is unknown. but it's
clearly not working as intended since it can cause issues like #11795.

instead of checking for "bad errors" check for known "good errors" where
we might not want to break out. this includes:

* EINTR: which can happen if read() is interrupted by some signal.
* EAGAIN: which happens if a non-blocking fd would block. `tty_in` is
  _not_ non-blocking, so EAGAIN should never occur here. but it's added
  just in case that changes in the future.

Fixes: https://github.com/mpv-player/mpv/issues/11795
Closes: https://github.com/mpv-player/mpv/pull/11805
2023-07-08 09:03:06 +02:00
NRK a61b784d90 osdep: remove erroneous POLLERR emulation
first of all, POLLERR is supposed to be ignored in `.events` and only
returned in `.revents`.

secondly select()'s exceptfds does not have a 1:1 correspondence with
POLLERR. thankfully, the only caller of this function (in terminal-unix)
never set the POLLERR flag so the errorfds were unused anyways.

so go ahead and remove it entirely instead of pretending we can emulate
something that's not possible.
2023-06-29 13:17:56 +02:00
rcombs 57dae8f42c osdep: add mp_get_user_langs 2023-06-25 11:01:58 +02:00
rcombs 0463096b3c osdep: move cfstr<->cstr conversions to a new apple_utils.c file 2023-06-25 11:01:58 +02:00
Dudemanguy 4502522a7a player: use XDG_CACHE_HOME by default
This adds cache as a possible path for mpv to internally pick
(~/.cache/mpv for non-darwin unix-like systems, the usual config
directory for everyone else). For gpu shader cache and icc cache,
controlling whether or not to write such files is done with the new
--gpu-shader-cache and --icc-cache options respectively. Additionally,
--cache-on-disk no longer requires explicitly setting the --cache-dir
option. The old options, --cache-dir, --gpu-shader-cache-dir, and
--icc-cache-dir simply set an override for the directory to save cache
files. If unset, then the cache is saved in XDG_CACHE_HOME.
2023-05-09 20:37:17 +00:00
Dudemanguy 7c4c9bc86f player: use XDG_STATE_HOME for watch_later
A pain point for some users is the fact that watch_later is stored in
the ~/.config directory when it's really not configuration data. Roughly
2 years ago, XDG_STATE_DIR was added to the XDG Base Directory
Specification[0] and its description, user-specific state data, actually
perfectly matches what watch_later data is for. Let's go ahead and use
this directory as the default for watch_later. This change only affects
non-darwin unix-like systems (i.e. Linux, BSDs, etc.). The directory
doesn't move for anyone else.

Internally, quite a few things change with regards to the path
selection. If the platform in question does not have a statedir concept,
then the path selection will simply return "home" instead (old
behavior). Fixes #9147.

[0]: 4f2884e16d
2023-05-09 20:37:17 +00:00
Dudemanguy baa9d56481 osdep: separate out macos paths from path-unix.c
macOS really has completely different path conventions that mpv doesn't
take into account and it treats it just like any other old unix-like
system. This means mpv enforces certain conventions on it (like all the
XDG stuff) that doesn't really apply. Since we'd like to use more of
this but at the same time not distrupt mac users even more, let's just
copy and paste the current code to a new file, update the build and call
it a day. This way, the paths of these two platforms can more freely
diverge.
2023-05-09 20:37:17 +00:00
Christoph Heinrich 91cc0d8cf6 options: transition options from OPT_FLAG to OPT_BOOL
c784820454 introduced a bool option type
as a replacement for the flag type, but didn't actually transition and
remove the flag type because it would have been too much mundane work.
2023-02-21 17:15:17 +00:00
Thomas Weißschuh 9efce6d4ae various: drop unused #include "config.h"
Most sources don't need config.h.
The inclusion only leads to lots of unneeded recompilation if the
configuration is changed.
2023-02-20 14:21:18 +00:00
Kacper Michajłow 3a28dbb711 osdep/io: add void to mp_penviron 2023-02-02 14:23:02 +00:00
Kacper Michajłow 0a4b139ddf osdep: add MP_FALLTHROUGH 2023-02-02 14:23:02 +00:00
Mia Herkt 08747c4965
osdep/terminal.h: Rename screen buffer controls
SAVE/RESTORE were a bit misleading.
2022-12-20 10:26:53 +01:00
Mia Herkt f1957ce911 osdep/terminal: Move common esc codes to terminal.h 2022-12-19 13:48:49 +01:00
Thomas Weißschuh 7a7042a4d1 w32: fix typo in F23 mapping 2022-09-03 08:46:42 -04:00
Thomas Weißschuh c4db110c8e macos: add support for F13-F20 keys 2022-09-02 14:05:46 +02:00
Thomas Weißschuh c5e5fba632 w32: add support for F13-F24 keys
Fixes #10595
2022-09-02 14:05:46 +02:00
Leo Izen 52e7269ea6 misc/random: add xoshiro random number implementation
Add xoshiro as a PRNG implementation instead of relying
on srand() and rand() from the C standard library. This,
in particular, lets us avoid platform-defined behavior with
respect to threading.
2022-08-17 10:21:55 -04:00
Cœur bb5b4b1ba6 various: fix typos 2022-04-25 09:07:18 -04:00
Aman Karmani 76b9254b8b osdep/atomic: add mp_atomic_double
Signed-off-by: Aman Karmani <aman@tmm1.net>
2022-04-02 21:41:58 +03:00
sfan5 24dcb5d167 subprocess: unblock/reset signals before running child process
During execve() ignored and blocked signals carry over to the child
process, though apparently for SIGCHLD (which the bug report was about)
this is implementation-defined.
fixes #9613
2021-12-19 15:02:18 +01:00
sfan5 632059816a libmpv: remove opengl_cb API and other deprecated symbols
Not all deprecated symbols were removed. Only three events were removed for now
since these are not used internally.
This bumps the library version to 2.0.
2021-12-15 12:29:10 +01:00
Dudemanguy ff322864f2 build: add meson build support
Adds support for the meson build system as well as a bit of
documentation. Compatibility with the existing waf build is
maintained.
2021-11-14 19:13:10 +00:00
Niklas Haas 8bd0dee531 osdep: rename MP_UNREACHABLE
It was pointed out on IRC that the name is misleading, since the actual
semantics of the macro is to assert first.
2021-11-03 15:15:20 +01:00
Niklas Haas c704824b45 osdep: add MP_UNREACHABLE
This seems to work on gcc, clang and mingw as-is, but I made it
conditional on __GNUC__ just in case, even though I can't figure out
which compilers we care about that don't export this define.

Also replace all instances of assert(0) in the code by MP_UNREACHABLE(),
which is a strict improvement.
2021-11-03 14:09:27 +01:00
Avi Halachmi (:avih) 930b483a68 win32: Windows 10: timeBeginPeriod on demand
Before this commit, timeBeginPeriod(1) was set once when mpv starts,
and the timers remained hi-res till mpv exits.

Now we do the same as before on Windows version < 10.
On Windows 10+ we now use timeBeginPeriod if needed, per timeout.

To force a mode regardless of Windows version, set env MPV_HRT:
- "always":  the old behavior - hires timers as long as mpv runs.
- "perwait": sets 1ms timer resolution if timeout <= 50ms.
- "never":   don't use timeBeginPeriod at all.

It was observed that on Windows 10 we lose about 0.5ms accuracy of
timeouts with "perwait" mode (acceptable), but otherwise it works
well for continuous timeouts (one after the other) and random ones.

On Windows 7 with "perwait": continous timeouts are accurate, but
random timeouts (after some time without timeouts) have bad
accuracy - roughly 16ms resolution instead of the requested 1ms.

Windows 8 was not tested, so to err on the side of caution, we keep
the legacy behavior "always" by default.
2021-09-21 00:45:08 +10:00
Avi Halachmi (:avih) 21d434d2db terminal-unix: identify and ignore unknown CSI sequences
If an unknown ESC sequence is detected where an ASCII char <X> follows
the ESC, mpv interprets it as ALT+<X>, which is the traditional
terminal encoding of ALT+letter.

However, if <X> is '[' then it's a CSI sequence which continues after
the '[', and has its own termination rules (can be many chars).

Previously, mpv interpreted unknown CSI sequences as (incorrect) ALT+[
followed by (incorrect) "keys" from the rest of the sequence.

In this commit, if a unknown CSI sequence is detected, mpv ignores
exactly the complete sequence.
2021-08-19 15:39:42 +03:00
Martin Tournoij 854404a639 terminal-unix: fix ^Z identification
When using "stty susp ''" to disable sending the TSTP signal with ^Z,
mpv didn't recognize ^Z correctly in the terminal:

  [input] No key binding found for key 'Ctrl+2'.

Because ASCII 26 (^Z) and above were incorrectly considered ^<NUMBER>.

This commit moves the cutoff between letters/numbers from 25 to 26 so
that ^Z is now detected correctly as ^<LETTER>.

Additionally, it rephrases the ^<NUMBER> formula for clarity.
2021-07-13 12:12:56 +03:00
Evgeny Zinoviev 56669fb44e mac: add ability to toggle visibility on all workspaces from menubar 2021-02-21 13:38:53 +01:00
der richter 7f8d069087 mac: only update touch bar items when necessary
the slider on the touch bar was always updated when any of the related
properties changed their value. this is partially dependent on the
refresh rate of the video, in the case of time-pos. too many updates to
touch bar impact the render performance.

to prevent this we only update the slider when necessary, when the touch
bar or the touch bar item is visible. the touch bar items only need a
granularity of seconds without any decimals, but the time-pos property
provides a granularity with decimals. we floor those values and only
update the touch bar items when we have at least a 1 second difference.
we also check for the visibility of the touch bar and its items.

Fixes #8477
2021-02-13 15:51:32 +01:00
der richter aa00ad06aa mac: use custom touch bar item and slider instead of a touch bar slider
the NSSliderTouchBarItem seem to be broken in a way it can't be fixed.
it has constraints set by default that can't be removed and lead to
warnings and render performance regressions.

instead of using the preconfigured NSSliderTouchBarItem we use a custom
touch bar item (NSCustomTouchBarItem) with a slider, which essential are
the same. this way we can configure our constraints ourselves, which
aren't needed in the first place.

Fixes: #7047
2021-02-13 15:51:32 +01:00
der richter dae9ea3fa7 mac: fix dangling pointers
initialising UnsafeMutableRawPointer the way we did won't free those
pointers and we get dangling pointers. explicitly define a scope those
pointers are alive and auto freed.
2021-01-13 16:23:47 +01:00
der richter ce1571ac01 mac: drop build support for swift versions earlier than version 4.1
this drops support for swift <4.1 and with this support for xcode <=9.2.
this was the last setup that is officially working on macOS 10.12.

our old legacy build macOS 10.12 + xcode 9.2 is replaced by macOS 10.13
+ xcode 9.4.1 with swift 4.1. the macOS 10.13 + xcode 10.1 VM is
replaced by the latest macOS 10.14 + xcode 11.3.1 VM. this is the oldest
version officially supported by Apple.

this is in preparations for the following commit.
2021-01-13 16:23:47 +01:00
der richter bc58361d86 mac: fix usage of temporary pointers
the pointer used to initialise the respective structs is only guaranteed
to be alive within this constructor. the struct itself is used later and
the data it points to, is not guaranteed to be the same.

to fix this we define a scope that pointer is definitely valid and use
it within this scope. a helper function was added to get the pointers
for several data at once. otherwise we would need to nest
withUnsafeMutableBytes several times, which would make it hard to read.
2021-01-13 16:23:47 +01:00
der richter af26402948 mac: use visible frame rectangle for window geometry calculation
currently we use the whole screen rectangle to calculate the window
geometry. this doesn't take the menu bar or the Dock into account.

by default use the visible screen rectangle instead. this is also a
change in behaviour, since the window can't be placed outside of this
rectangle anymore. also add an option to change to the old behaviour,
because it can still be useful in certain cases, like placing the window
directly underneath the menu bar when used a desktop background.

Fixes #8272
2020-12-19 21:37:55 +02:00
Guido Cella 9867f21830 terminal: process input when foregrounded
When mpv is in the background because it was started with
`mpv foo.mp3 &`, or the user did ctrl+z bg, and is then brought to the
foreground with fg, it buffers input until you press enter. This makes
it accept input almost immediately. Having a short interval isn't
important, since input is buffered until the next loop iteration.

Closes #8120.
2020-11-26 23:55:59 +02:00
Shreesh Adiga 670f23f169 osdep/terminal: Add function to get terminal pixel dimensions 2020-11-22 13:34:25 +02:00
wm4 26fc70dbfd path: do not use old_home for win32 exe dir
Apparently mpv supports loading config files from the same directory as
the mpv.exe. This is a fallback of some sort. It used the old_home
mechanism.

I want to add a warning if old_home exists, but that would always show
the warning on win32. Obviously we don't want that.

Add a separate exe_dir entry to deal with that.

Untested, but probably works.

Mistakenly reverted as part of the default configuration directory
location switch-back in aa18a8e1cd.

Separation of the mpv executable directory from old_path is a
good change now that we warn about the old_config directory also
existing.

Fixes #8232
Fixes #8244
Fixes #8262
2020-11-16 00:44:40 +02:00
Philip Langdale 949e06c86c Revert "path: switch back to using non-XDG config dir by default"
This reverts commit 269f0e743e.
2020-10-16 00:47:18 +03:00
Philip Langdale aa18a8e1cd Revert "path: do not use old_home for win32 exe dir"
This reverts commit c3694f0acb.
2020-10-16 00:47:18 +03:00
wm4 95e3a6e67e terminal: fix segfault when backgrounding
In the recent terminal commit, I "compressed" the read() error handling,
and messed it up. The return value could be -1 for other non-fatal
errors (such as EIO when trying to read while backgrounded), which
resulted in buf.len getting messed up.

Fixes: 602384348e
2020-09-21 19:31:15 +02:00
der richter 03047a0169 mac: add an option to change the App activation policy
useful to hide the app icon in the Dock if necessary.
2020-09-20 15:28:50 +02:00
wm4 602384348e terminal: attempt to handle the ESC key
Due to Unix being legacy garbage, it's not possible to safely detect the
ESC key on terminal. The key sequences are ambiguous. The code for the
ESC key also starts the sequences for other special keys.

Until now, you needed to hit ESC twice for it to be recognized.

Attempt to handle this better by using a timeout to detect the key. If
ESC is in the input buffer, but nothing else arrived after a timeout,
assume it's the ESC key. I think this is the method vim uses. Currently,
the timeout is set at 100ms. This is hardcoded and cannot be changed.
It's possible that this causes problems on slow ssh connections or so.

I'm not sure what exactly happens if you manage to get ESC + another
normal key into the input buffer. If it's a known sequence, it will be
matched and interpreted as such. If not, it'll probably be discarded.
2020-09-17 15:31:19 +02:00
wm4 f250c29403 terminal-unix: attempt to support more CTRL
Hysterically stupid inconsistent legacy garbage from the 70ies or maybe
even 60ies. What the fuck. I fucking hate computers so much.

Fixes: #8072
2020-09-10 23:03:30 +02:00
der richter 5fb0f36937 mac: use config cache und wakeup for mac option runtime changes
remove the libmpv observer for the macOS specific options and use a
config cache + change callback for runtime changes. this is also a
preparation for new backends and generalises even more, since libmpv
functions can't and shouldn't be used in usual vo backends. for feature
parity the config cache is used.
2020-08-22 14:22:49 +02:00
der richter f79a591ae4 cocoa-cb: generalisation of backend independent parts
move all backend independent code parts in their own folder and files,
to simplify adding new backends. the goal is to only extend one class
and add the backend dependent parts there. usually only the (un)init,
config and related parts need to be implemented per backend. furthermore
all needed windowing and related events are propagated and can be
overwritten. the other backend dependent part is usually the surface for
rendering, for example the opengl oder metal layer.

in the best case a new backend can be added with only a few hundred
lines.
2020-08-22 14:22:49 +02:00
Avi Halachmi (:avih) 557e9d9531 win32: scripting utils.get_env_list(): use UTF-8
lua/js utils.get_env_list() uses `environ' which was ANSI, thus
it broke any unicode names/values.

mpv already has an internal utf8_environ for win32, but it's used
only at the getenv(..) wrapper and not exposed in itself, and also it
has lazy initialization - on first getenv() call.

Now `environ' maps to a function which ensures initialization while
keeping it an l-value (like posix expects).

The cost of this fuglyness is that files should include osdep/io.h
(which now declares environ as extern) rather than declaring it
themselves, or else the build will break on mingw.
2020-08-16 12:24:19 +03:00
wm4 e27c523a10 command: extend subprocess command stdin, change behavior
Make it possible to feed a string to stdin of a subprocess. Out of
laziness, it can't be an arbitrary byte string. (Would require adding an
option type that takes in a Lua byte string.)

Do not set stdin of a subprocess to fd 0 (i.e. mpv's stdin) anymore,
because it makes things more consistent. Enabling stdin didn't make too
much sense in the first place, so this behavior change seems
justifiable.

win32 support missing.

Fixes: #8003
2020-08-16 02:54:44 +02:00
James Ross-Gowan bb231889fd win32: request the UTF-8 code page for Windows APIs
This sets the activeCodePage property in the manifest, which forces the
ANSI code page to be UTF-8 in Windows 10 1903 and up. It shouldn't make
a difference for mpv itself, since mpv already uses the wide-char APIs
for most functions, however some of mpv's dependencies, such as Lua,
rely on the ANSI codepage. Hence this change enables support for Unicode
file names in Lua's I/O library.

Thanks @avih for finding this property.

See:
https://docs.microsoft.com/en-us/windows/uwp/design/globalizing/use-utf8-code-page
2020-08-08 15:00:25 +03:00
James Ross-Gowan 83fec9bafb subprocess-win: update to mp_subprocess2
This fixes the "run" and "subprocess" commands on Windows, including
youtube-dl support.

Unix-like FD inheritance is emulated on Windows by using an undocumented
data structure[1] that gets passed to the newly created process in
STARTUPINFO.lpReserved2. It consists of two sparse arrays listing the
HANDLE and internal CRT flags corresponding to each FD. This structure
is used and understood primarily by MSVCRT, but there are other runtimes
and frameworks that can write it, like libuv.

The code for creating asynchronous "anonymous" pipes in Windows has been
enhanced and moved into windows_utils.c. This is mainly an artifact of
an unfinished future change to support anonymous IPC clients in Windows.
Right now, it's still only used in subprocess-win.c

[1]: https://www.catch22.net/tuts/undocumented-createprocess
2020-07-20 21:02:17 +02:00
wm4 0279a44d93 command: extend subprocess command
Add env and detach arguments. This means the command.c code must use the
"new" mp_subprocess2(). So also take this as an opportunity to clean up.
win32 support gets broken by it, because it never made the switch to the
newer function.

The new detach parameter makes the "run" command fully redundant, but I
guess we'll keep it for simplicity. But change its implementation to use
mp_subprocess2() (couldn't do this earlier, because win32).

Privately, I'm going to use the "env" argument to add a key binding that
starts a shell with a FILE environment variable set to the currently
playing file, so this is very useful to me.

Note: breaks windows, so for example youtube-dl on windows will not work
anymore. mp_subprocess2() has to be implemented. The old functions are
gone, and subprocess-win.c is not built anymore. It will probably work
on Cygwin.
2020-07-20 21:02:17 +02:00
wm4 c3694f0acb path: do not use old_home for win32 exe dir
Apparently mpv supports loading config files from the same directory as
the mpv.exe. This is a fallback of some sort. It used the old_home
mechanism.

I want to add a warning if old_home exists, but that would always show
the warning on win32. Obviously we don't want that.

Add a separate exe_dir entry to deal with that.

Untested, but probably works.
2020-06-25 17:56:16 +02:00
wm4 269f0e743e path: switch back to using non-XDG config dir by default
XDG is stupid, so change back to the standard behavior. Unfortunately,
most users will now have the XDG one, so we will still need to load
this. (This is exactly the same problem as when XDG support was
introduced, just the other way around).

This should not affect any normal users. Hopefully I tested this well
enough; my intention is not to torment miserable XDG fans; they can keep
using their config dir if they want it.

This changes behavior in two cases:
- new users (now creates ~/.mpv/ instead of ~/.config/mpv/)
- users which have both directories

The latter case will behave subtly or obviously different, not sure.
Just fix your shit.

Extend the manpage with all the messy details, as far as I could reverse
engineer them from the code.
2020-06-25 17:56:16 +02:00
wm4 07b0c18bad build: change filenames of generated files
Force them into a more consistent naming schema.
2020-06-04 16:59:05 +02:00
James Ross-Gowan 102a083171 terminal-win: handle 'Change Window Title' OSC sequence
This should make --term-title work in Windows 8.1 and below.

OSC sequences are defined in ECMA-48. The 'Change Window Title' command,
as far as I can tell, is a de-facto standard defined by xterm[1]. In
either case, this code is probably still not standards-compliant.

This also changes mp_write_console_ansi to convert to UTF-16 before
parsing control sequences, because that made it easier to pass the OSC
param to SetConsoleTitleW. I think it's also more correct to do it this
way, even though it doesn't really matter much for our limited terminal
parsing. As a side-effect of this, mp_write_console_ansi no longer
mutates its argument.

[1]: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
2020-05-29 19:48:51 +10:00
sfan5 bf6afbc299 osdep: remove confstr() fallback for subprocess spawning
It doesn't exist on bionic (Android) and accurately emulating
execvpe's behaviour isn't all that important.
2020-05-25 00:30:35 +03:00
wm4 60f8cd4072 osdep: remove posix_spawn() helpers and wrappers
See previous commit. Farewell, useless shitty POSIX function.
2020-05-15 16:37:41 +02:00
wm4 5309497727 subprocess: replace posix_spawnp() with fork()
This code runs posix_spawnp() within a fork() in some cases, in order to
"disown" processes which are meant as being started detached. But
posix_spawnp() is not marked as async-signal-safe, so what we do is not
allowed. It could for example cause deadlocks, depending on
implementation and luck at runtime. Turns out posix_spawnp() is useless
crap.

Replace it with "classic" fork() to ensure correctness.

We could probably use another mechanism to start a process "disowned"
than doing a double-fork(). The only problem with "disowning" a process
is calling setsid() (which posix_spawnp() didn't support, but maybe will
in newer revisions), and removing as as parent from the child process
(the double-fork() will make PID 1 the parent). But there is no good way
to either remove us as parent, or to "reap" the PID in a way that is
safe and less of a mess than the current code. This is because
POSIX/UNIX is a miserable heap of shit. (Less shit than "alternatives"
like win32, no doubt.)

Because POSIX/UNIX is a miserable heap of shit, execvp() is also not
specified as async-signal-safe. It's funny how you can run a full
fledged HTTP server in an async-signal-safe context, but not start a
shitty damn process. Unix is really, really, really extremely bad at
this process management stuff. So we reimplement execvp() in an
async-signal-safe way.

The new code assumes that CLOEXEC is a thing. Since POSIX/UNIX is such a
heap of shit, O_CLOEXEC and FD_CLOEXEC were (probably) added at
different times, but both must be present. io.h defines them to 0 if
they don't exist, and in this case the code will error out at runtime.
Surely we could do without CLOEXEC via fallback, but I'll do that only
if at least 1 bug is reported wrt. this issue.

The idea how to report exec() failure or success is from musl. The way
as_execvpe() is also inspired by musl (for example, the list of error
codes that should make it fail is the same as in musl's code).
2020-05-15 16:37:41 +02:00
RealDolos 8bce6d0b89 w32_common: Support HiDPI on Windows 2020-05-08 21:46:45 +10:00
Avi Halachmi (:avih) 77738ac6f5 win32: SGR emulation: minor fixup on invalid sequence
This fixes two issues with invalid value after 38/48:
- It was not detected correctly and ended up skipping 4 instead of 0.
- The intent was to skip 0, but it's better to skip the rest.

Behavior with valid 2/5 after 38/48 was correct and is unaffected.
2020-04-24 10:14:33 +03:00
Avi Halachmi (:avih) b5b266c38c osdep/terminal-win: native VT: report exact width
The narrower-by-1 width is not required with a native VT console
because the wrapping behavior is the same as on *nix on such case.
2020-04-23 23:25:41 +03:00
Avi Halachmi (:avih) 8e50430eaa win32: native VT: logic fixup
We want basemode unmodified so that we can use it if setting VT mode
fails.
2020-04-23 17:51:20 +03:00
Avi Halachmi (:avih) 1c8506d9c8 win32: use windows 10 native virtual-terminal if available
This enables native and more complete escape-sequence handling instead
of our emulation. E.g. it supports 256/true colors, and more.

This should get enabled automatically on Windows 10 build 16257
(August 2017) or later.
2020-04-23 17:02:38 +03:00
Avi Halachmi (:avih) 67b7a8adaf win32: improve console SGR escape sequence emulation
Previously an SGR sequence was emulated correctly only if:
- It had exactly 1 or 2 numeric values (not 0).
- Only reset, bold, and foreground colors were supported.
- 256/true colors were not skipped correctly with their sub-values.

Now it supports the same as before, plus:
- 0-16 (inclusive) numeric values, e.g. \e[m now resets correctly.
- Supports also codes for background color, reverse, underline* .
- Supports also codes for default intensity/fg/bg/reverse/underline.
- 256/true colors are recognized and skipped gracefully.

* Reverse/underline seem to work only on windows 10.
2020-04-23 17:02:38 +03:00
Jan Beich 9cbacefbb0 build: restore BSD thread names after 9f461b85bf
On FreeBSD non-POSIX threading functions are in a separate header.
DragonFly and OpenBSD adopted FreeBSD header and extensions.

../test.c:3:3: error: implicit declaration of function 'pthread_set_name_np' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
{ pthread_set_name_np(pthread_self(), "ducks"); return 0; }
  ^
../osdep/threads.c:47:5: error: implicit declaration of function 'pthread_set_name_np' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    pthread_set_name_np(pthread_self(), tname);
    ^

Signed-off-by: Jan Beich <jbeich@FreeBSD.org>
2020-04-23 13:58:16 +02:00
Murray Campbell caa5d8170e terminal-unix: add key_entry defs for DECCKM mode
zsh often sets DECCKM (i.e. Cursor Key Mode) meaning the arrow keys
send `SS3 A/B/C/D` instead of `CSI A/B/C/D`.

Add `key_entry` definitions for this alongside the existing DECCKM Reset
definitions.
2020-04-15 16:46:25 +02:00
wm4 433c9a90a5 win32: pthread: define PTHREAD_MUTEX_ERRORCHECK
mpv uses it now. Doesn't need to do anything.
2020-03-19 00:11:23 +01:00
wm4 cb82cbbbae osdep: add a pthread debugging wrapper
Because pthread failures are virtually undebuggable (which sure is
pretty strange, given all these heavy instrumentation tools these days).

Of course it affects only files which include osdep/threads.h.

I'm departing from the usual way to add symbols with config.h and using
"#if", and defining it on the compiler command line + "#ifdef" because I
don't want to include config.h from a header (which would be necessary
in this case) to keep things slightly cleaner. Maybe this is misguided,
but still.

This would have been easier if mpv defined its own wrappers for all
thread functions. But we don't (which to be honest is probably better
than e.g. going crazy like VLC and essentially reimplementing
everything). This seems to be a good compromise. Since it's off by
default and basically a developer tool, the minor undefined behavior
(redefining reserved symbols) isn't much of an issue.
2020-03-18 22:42:13 +01:00
wm4 26f4f18c06 options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with

   {"name", ...

followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.

I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.

Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.

Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.

In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-18 19:52:01 +01:00
wm4 c784820454 options: introduce bool option type, use it for --fullscreen
The option code is very old and was added to MPlayer in the early 2000s,
when C99 was still new. MPlayer did not use the "bool" type anywhere,l
and the logical option equivalent to bool, the "flag" option type, used
int, with the convention that only the values 0 and 1 are allowed.

mpv may have hammered many, many additional tentacles to the option
code, but some of the basics never changed, and m_option_type_flag still
uses int. This seems a bit weird, since mpv uses bool for booleans. So
finally introduce an m_option_type_bool. To avoid duplicating too much
code, change the flag code to bool, and "reimplement" m_option_type_flag
on top of m_option_type_bool.

As a "demonstration", change the --fullscreen option to this new type.
Ideally, all options would be changed too bool, and m_option_type_flag
would be removed. But that is a lot of monotonous thankless work, so I'm
not doing it, and making it a painful years long transition.

At the same time, I'm introducing a new concept for option declarations.
Instead of OPT_BOOL(), which define the full m_option struct contents,
there's OPTF_BOOL(), which only takes the option field name itself. The
name is provided via a normal struct field initializer. Other fields
(such as flags) can be provided via designated initializers.

The advantage of this is that we don't need tons of nested vararg
macros. We also don't need to deal with 0-sized varargs being a pain
(and in fact they are not a thing in standard C99 and probably C11).
There is no need to provide a mandatory flags argument either, which is
the reason why so many OPT_ macros are used with a "0" argument. (The
flag argument seems to confuse other developers; they either don't
immediately recognize what it is, and sometimes it's supposed to be the
option's default value.)

Not having to mess with the flag argument in such option macros is also
a reason for the removal of M_OPT_RANGE etc., for the better or worse.

The only place that special-cased the _flag option type was in
command.c; change it to use something effectively very similar that
automatically includes the new _bool option type. Everything else should
be transparent to the change. The fullscreen option change should be
transparent too, as C99 bool is basically an integer type that is
clamped to 0/1 (except in Swift, Swift sucks).
2020-03-14 02:23:38 +01:00
wm4 670610bc1d atomic: add atomic_exchange_explicit() fallback
Apparently I want to use this in a later commit. Untested, because this
is a pre-C11 fallback, and I only test with real <stdatomic.h>.
2020-03-05 22:00:50 +01:00
der richter 327b092bfc mac, cocoa: fix UI updates on none main queue threads
injecting the Apple Main Thread Checker via
DYLD_INSERT_LIBRARIES=libMainThreadChecker.dylib identified several
problems that needed fixing.
2020-02-22 13:56:31 +01:00
der richter b8f2811f8d mac: fix media key support for libmpv users
this basically moves the remote command center to our mac events instead
of keeping it our Application, which is only available when started from
mpv itself. also make it independent of the NSApplication.

this also prevents a runtime crash
2020-02-22 13:56:31 +01:00
wm4 e2ab6b7f35 scripting: add a way to run sub processes as "scripts"
This is just a more convenient way to start IPC client scripts per mpv
instance.

Does not work on Windows, although it could if the subprocess and IPC
parts are implemented (and I guess .exe/.bat suffixes are required).
Also untested whether it builds on Windows. A lot of other things are
untested too, so don't complain.
2020-02-19 22:18:15 +01:00
wm4 f2c7c641b3 subprocess: implement proper detached processes on POSIX
The previous method for this sucked: for every launched detached
process, it started a thread, which then would leak if the launched
process didn't end before the player uninitialized. This was very racy
(although I bet the race condition wouldn't trigger in a 100 years), and
wasteful (threads aren't a cheap resource).

Implement it for POSIX directly. posix_spawn() has no direct support for
this, so we need to do it ourselves with fork(). We could probably do it
without fork(), and attempt to collect the PID in another thread. But
then we'd either have a waiting thread again, or we'd need to do an
unsafe waitpid(-1, ...) call. (POSIX process management sucks so badly,
how did they even manage this. Hopefully I'm just missing something, but
I'm not.) So now we depend on both posix_spawn() _and_ fork(), isn't it
fun?

Also call setsid(), to essentially detach the child process from the
terminal. (Otherwise it can receive various signals from the terminal,
which is probably not what you want.) posix_spawn() adds
POSIX_SPAWN_SETSID in newer POSIX releases, but we don't want to rely on
this yet.

The posix_spawnp() call is duplicated, but this is better than somehow
trying to unify the code paths.

Only somewhat tested, so enjoy the bugs.
2020-02-16 22:08:48 +01:00
wm4 92fee4ebc4 subprocess: change to a fancier API
Introduce mp_subprocess() and related definitions. This is a bit more
flexible than the old stuff. This may or may not be used for a more
complicated feature that involves starting processes, and which would
require more control.

Only port subprocess-posix.c to this API. The player still uses the
"old" API, so for win32 and dummy implementations, the new API is simply
not available, while for POSIX, the old APIs are emulated on top of the
new one. I'm hoping the win32 code can be ported as well, so the ifdefs
in subprocess.c can be dropped, and the player can (if convenient or
needed) use the new API.
2020-02-16 21:27:34 +01:00
der richter 2607a2b892 mac: activate logging when started from the bundle
this creates a default log for the last mpv run when started from the
bundle. that way one can get a log of what happened even after an issue
occurred. also add a menu entry under Help to show the current log, but
only when the bundle is used.

Fixes #7396
Fixes #2547
2020-02-08 10:55:07 +01:00
der richter b7b8a772f2 mac: remove stdout and stderr redirect for logging
this was kinda useless anyway since the bundle was started with
terminal=no and no logging was done anyway.

Fixes #1590
2020-02-08 10:55:07 +01:00
der richter dd14d06835 mac: change Report Issue menu link to the new choose template page 2020-01-26 14:02:32 +01:00
der richter 3275cd04b7 cocoa-cb: add support for forcing the dedicated GPU for rendering
this deprecates the old cocoa backend only option and moves it to the
general macos ones. add support for the new option in the cocoa-cb
layer creation and use the new option in the olde cocoa backend.

Fixes #7272
2020-01-26 12:12:22 +01:00
der richter 695d850412 mac: report playback state to the MediaPlayer Command Center
some system logic for the global media key events depends on the right
playback state. set the state properly to prevent more breakages in the
future.
2020-01-26 12:09:55 +01:00
der richter 3d16ab1a31 mac: add support for PLAYONLY and PAUSEONLY key codes to MediaPlayer
Fixes #7365
2020-01-26 12:09:55 +01:00
der richter e7add205d8 build: fix build with disabled swift and Media Player
when swift is disabled some headers are not included. one of them is the
options/options.h header that is needed for the vo_sub_opts struct. we
include it to fix the build without swift.

the second problem is the build time check for the macOS 10.12.2
features or more specific the Media Player support. since it is a swift
feature we can not use it when swift is disabled. add a separate
Media Player check that also depends on swift and use that new
preprocessor variable as a build time check instead.

Fixes #7282
2019-12-23 23:44:20 +01:00
der richter a32db637b5 mac: replace old event tap for media key support with MediaPlayer
the old event tap has several problems, like no proper priority support
or having to set accessibility permissions for mpv or the terminal.

it is now replaced by the new MediaPlayer which has proper priority
support and isn't as greedy as previously. this only includes Media Key
support and not any of the other features included in the MediaPlayer
framework, like proper Now Playing data (only set dummy data for now).
this is only available on macOS 10.12.2 and higher.

also removes some unnecessary redefines.

Fixes #6389
2019-12-15 20:07:31 +01:00
der richter 8a6ee7fe94 mac: remove Apple Remote support
the Apple Remote has long been deprecated and abandoned by Apple.
current macs don't come with support for it anymore. support might be
re-added with the next commit.
2019-12-15 20:07:31 +01:00
der richter 1eb6cbd093 cocoa-cb: fix freeing of macos_opts config group
using the MPContext as ta parent was a bad idea and shouldn't be done in
any circumstances there because it only supposed to be for internal
usage. this had the undesired effect that the options group was freed
but still used since the MPContext is freed afterwards.

instead manually free options group.
2019-12-15 20:07:11 +01:00
der richter f21a980e37 cocoa-cb: update and add more options to use new options handling
this updates and add the maximized, minimized, keepaspect and ontop
options to use the new options handling
2019-12-15 20:07:11 +01:00
der richter c8cc203735 cocoa-cb: use m_config_cache and new VOCTRL for option handling
this removes the direct access of the mp_vo_opts stuct via the vo struct
and replaces it with the m_config_cache usage. this updates the
fullscreen and window-minimized property via m_config_cache_write_opt
instead of the old mechanism via VOCTRL and event flagging. also use the
new VOCTRL_VO_OPTS_CHANGED event for fullscreen and border changes.
2019-12-15 20:07:11 +01:00
wm4 5b5d163a6a atomic: add mp_atomic_uint64 2019-11-29 12:14:43 +01:00
Chris Down e143966a76 player: Optionally validate st_mtime when restoring playback state
I often watch sporting events. On many occasions I get files with the
same filename for each session. For example, for F1 I might have the
following directory structure:

    F1/
        FP1.mkv
        FP2.mkv
        FP3.mkv
        Qualification.mkv
        Race.mkv

Since usually one simply watches one race after the other, I usually
just rsync the new event's files over the old ones, so, for example,
Race.mkv will be replaced from the file for the last event with the file
from the new event.

One problem with this is that I like to use --resume-playback for other
kinds of media, so I have it on by default. That works great for, say, a
movie, but doesn't work so well with this scheme, because you can
trivially forget to pass --no-resume-playback on the command line and
end up 2 hours in, watching spoilers as the race results scroll down the
screen :-)

This patch adds a new option, --resume-playback-check-mtime, which
validates that the file's mtime hasn't changed since the watch_later
configuration was saved. It does this by setting the watch_later
configuration to have the same mtime as the file after it is saved.

Switching back and forth between checking mtime and not checking mtime
works fine, as we only choose whether to compare based on it, but we
update the watch_later configuration mtime regardless of its value.
2019-11-20 15:11:33 +01:00
der richter 6d0f0546ee cocoa-cb: remove get_property_* usages and split up mpv helper
all the get_property_* usages were removed because in some circumstances
they can lead to deadlocks. they were replaced by accessing the vo and
mp_vo_opts structs directly, like on other vos.

additionally the mpv helper was split into a mpv and libmpv helper, to
differentiate between private and public APIs and for future changes
like a macOS vulkan context for vo=gpu.
2019-10-06 13:29:48 +02:00
der richter 41f290f54e cocoa-cb: add support for 10bit opengl rendering
this will request a 16bit half-float framebuffer instead if a 8bit
integer framebuffer.

Fixes #3613
2019-09-26 00:02:02 +02:00
Akemi c1cdecd147 mac: add Open Playlist menu bar item 2019-09-23 19:28:38 +02:00
James Hilliard abfc58cad4 stream_libarchive: Always use LC_CTYPE_MASK for libarchive
Using LC_ALL_MASK is unnecessary and unreliable on some systems.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2019-09-21 12:53:47 +02:00
wm4 98627d3a32 io: remove Windows tmpfile() emulation
Unused now. The old stream cache used it, but it was removed.

On a side note, the demuxer cache uses mp_mkostemps(). It looks like our
Windows open() emulation handles this correctly by using CREATE_NEW, so
no functionality gets lost by the "new" approach. On the other hand, the
demuxer cache does not set FILE_FLAG_DELETE_ON_CLOSE, but instead tries
to delete the file after opening (POSIX style), which probably won't
work on Windows. But I'm not sure how to make it use the DELETE_ON_CLOSE
flag, so whatever.
2019-09-19 20:37:05 +02:00
wm4 943fc88989 win32: remove -municode from mpv binary
If this is used, the runtime expects that wmain() instead of main() is
defined. This caused me severe problems in a certain now irrelevant
case. I think it's a good idea to avoid this special case.

We can just use main() and call GetCommandLineW() instead. This function
returns a single string, so use CommandLineToArgvW() to split it, and
hope it has the same semantics. Should this ever return NULL, hope that
it leaves argc at 0.

Untested, I think.
2019-09-19 20:37:05 +02:00