Commit Graph

1057 Commits

Author SHA1 Message Date
der richter 556cb7d6a4 mac/input: add simplified mp_keymap init 2024-03-14 23:33:15 +01:00
der richter 4d8ea338de mac/input: remove wrongly mapped modifier keys 2024-03-14 23:33:15 +01:00
der richter 3ef3bbf93d mac/event: move key event handling to input helper and optimise it 2024-03-14 23:33:15 +01:00
der richter 5482eecb8a mac/input: define AltGr mask as static NSEvent.ModifierFlags variable
this makes it possible to properly test for those modifiers in a proper
swift like way.
2024-03-14 23:33:15 +01:00
der richter 18fb71498b mac/events: remove redundant functions and optimise input helper usage
some redundant functions that jump through hoops.
2024-03-14 23:33:15 +01:00
der richter 055e9cd93e mac/helper: move input ctx related functionality into new input helper
also make functions thread safe.
2024-03-14 23:33:15 +01:00
der richter f3e5fea4f5 mac/events: move input ctx related functionality into new input helper
preparation for mac/events cleanup and single responsibility principle.
all functions are thread safe.
2024-03-14 23:33:15 +01:00
der richter 8a37f0f693 mac/menu: add explicit menu type instead of an inferred type
with the use of an explicit type we can removed inferred type checks
like separators/services menu by name or menus by sub configs.
2024-03-07 01:03:52 +01:00
der richter 16ea688115 mac/menu: make menu creation recursive to allow nested submenus
also makes menu creation cleaner and more obvious.
2024-03-07 01:03:52 +01:00
der richter 4eb58f6ea7 mac/menu: move conditional Bundle menu items into config
only add the "Show log File…" menu item config when invoked from the
bundle, instead of testing on menu item creation. this is similar to the
touch bar menu items now.
2024-03-07 01:03:52 +01:00
der richter 73e494a237 mac/menu: keep track of menu items with dynamic actions
keeping track of the dynamic menu items lets us directly access them by
key. we don't need to search in the config array for the right config
and menu item.
2024-03-07 01:03:52 +01:00
der richter 8d4329a710 mac/menu: merge file and url config properties
a file path is basically an URL. both are also handled as URL objects
in our code.
2024-03-07 01:03:52 +01:00
der richter 46a9e8c130 mac/menu: properly guard playlist array access 2024-03-07 01:03:52 +01:00
der richter 30eab4b933 mac/menu: attach menu config to menu item for direct access
add a config property to the menu items, so we don't need to search in
the config array for the right config.
2024-03-07 01:03:52 +01:00
der richter 95d08df7a7 mac/menu: replace app.command usage with event.command 2024-03-07 01:03:52 +01:00
der richter 37990597c7 mac/menu: fix touch bar menu item
the check broke when the runtime check was removed, eg the menu item was
never added to the menu. since we only add the menu item to the config
when touch bar support is available the check is completely unnecessary.
2024-03-07 01:03:52 +01:00
der richter 035906dad5 mac/menu: rename Preferences to Settings for consistency with macOS 2024-03-07 01:03:52 +01:00
der richter ad0573ff8e mac/menu: remove duplicate key assignment Undo/Zoom
this key is already assigned to Undo.
2024-03-07 01:03:52 +01:00
der richter eadd85a6ac mac/menu: optimise loading files function
don't save files in a temporary array and use an in place mapping.
2024-03-07 01:03:52 +01:00
der richter cb807ff063 mac/menu: replace deprecated openFile() usage 2024-03-07 01:03:52 +01:00
der richter 996ec6feca mac/menu: remove unnecessary alert config fields and alert
the config folder is created by mpv if it does not exist, so the last
alert is unnecessary.

also change config path priority.
2024-03-07 01:03:52 +01:00
der richter fe35baa88e mac/menu: rewrite menu bar in swift 2024-03-07 01:03:52 +01:00
der richter bbbd6e272c mac/app: remove unused function 2024-03-07 01:03:52 +01:00
der richter 86fa9b18a3 osdep/mac: make mac naming of files, folders and function consistent
rename all macOS namings (osx, macosx, macOS, macos, apple) to mac, to
make naming consistent.
2024-02-28 15:52:47 +01:00
der richter c7ff037fdd build: fix build when disabling cocoa-cb
the swift obj-c bridging header is only included when cocoa-cb is
enabled. cocoa-cb is not the only swift feature anymore and disabling
cocoa-cb leads to a runtime error that specific swift classes could not
be found.

include the swift obj-c bridging header in the case swift features are
enabled.
2024-02-27 14:04:30 +01:00
der richter a7c4a113b8 cocoa-cb: remove pre-allocation and initialise only when used
cocoa-cb was always pre-allocated in the Application itself because
libmpv needs to be set up before usage, an opengl context has to be set
and because it was decided mac specific code should be kept out of
libmpv.

this means that a completely working libmpv and opengl renderer was set
up even if it wasn't used. leading to unnecessary log message, resources
being used or reserved on the system that might not be used, triggering
of dedicated GPU unnecessarily and many other things.

even if not optimal, this wasn't the biggest problem since we only had
that one working vo on macOS. though now that we have a vulkan
gpu(-next) backend on macOS that was made the default, we always have
that dangling cocoa-cb instance, which is completely unnecessary.

move the cocoa-cb initialisation into libmpv preinit function and only
init cocoa-cb when we are a standalone App and cocoa-cb support is build
into.
2024-02-27 14:01:38 +01:00
nanahi ab3a63285a osdep/io: add mp_unlink()
unlink() was never wrapped in win32, so all usages of it were referring
the ANSI version of the function. This doesn't work properly for Windows
versions before 1903 (where the UTF-8 codepage is requested).

Fix this by adding mp_unlink() which wraps over _wunlink().
2024-02-25 14:30:20 +01:00
der richter 06ee5e9344 mac: code consistency changes 2024-02-24 20:04:16 +01:00
nanahi 84015959cc osdep/io: move I/O utility functions to misc/io_utils
The purpose of osdep/io is to provide a wrapper for POSIX I/O functions
on Windows. The last 2 functions are utility functions which don't serve
this purpose.
Move them to a separate file.
2024-02-23 21:35:57 +01:00
nanahi c36e051470 osdep/io: ignore 'x' mode for mp_fopen
fopen() with 'x' mode is a non-portable glibc extension, is currently
unused, and should not be used in order to maintain POSIX compatibility.
Thus there is no need for the Windows wrapper mp_fopen() to support it.
2024-02-23 21:35:43 +01:00
der richter d954646d29 various: make mentions of macOS consistent
change all mentions and variations of OSX, OS X, MacOSX, MacOS X, etc
consistent. use the official naming macOS.
2024-02-21 20:46:53 +01:00
Jose Maldonado aka Yukiteru 293532057e osdep/threads-posix: fix headers for OpenBSD build
In OpenBSD the compilation fail because osdep/threads-posix.h
need include pthread_np.h
2024-02-15 16:46:12 +00:00
der richter bba3d28781 mac/remote: simplify cover retrieval 2024-02-15 00:11:55 +01:00
der richter 45192d94d3 mac/remote: remove unnecessary nowPlayingInfo variable
no need to keep track of the nowPlayingInfo, MPNowPlayingInfoCenter
already provides the current info.
2024-02-15 00:11:55 +01:00
der richter e457cc260c mac/remote: add album and artist info 2024-02-15 00:11:55 +01:00
der richter c56be84675 mac/remote: add seek support
Fixes #11233
2024-02-15 00:11:55 +01:00
der richter 00efaeb428 mac/remote: add chapter title info 2024-02-15 00:11:55 +01:00
der richter ca8c61838e mac/remote: add media-title info
Fixes #11233
2024-02-15 00:11:55 +01:00
der richter 0a343369ba mac/remote: add playback rate info
also rate limit the position to update at max once per second.
2024-02-15 00:11:55 +01:00
der richter e23e158481 mac/remote: add duration and current position info
Fixes #11233
2024-02-15 00:11:55 +01:00
der richter 07a3bf0365 mac/remote: remove make current observer when stopped
the observer is registered on every call of the start function. this
could lead to several registered observers for the same event and
several calls to the make current function, even though we only need it
once per event.

properly remove the observer on stop, so we only ever have one observer
registered.
2024-02-15 00:11:55 +01:00
der richter de36f11fa8 mac/remote: replace command handler with generic handler function config
preparation for the upcoming changes for new functionality not related
to key handling.
2024-02-15 00:11:55 +01:00
der richter 05d0252a30 mac/remote: simplify repeatable key logic 2024-02-15 00:11:55 +01:00
der richter 0e556674dc mac/remote: move configs to initialiser for new MediaPlayer shorthands 2024-02-15 00:11:55 +01:00
der richter 1883f2f7a0 mac/remote: move class local struct and enum definition to extension
the class local struct and enum are moved to an extension to separate
their definition and usage.
2024-02-15 00:11:55 +01:00
der richter 80cde2671c mac/remote: use explicit struct instead of generic array for configs
making the config explicit gets rid of some optional unwrapping. also
rename some variables to better represent their values.
2024-02-15 00:11:55 +01:00
sfan5 ca5f7d2b4b osdep: fix infinite loop when cancelling subprocess
Due to the state of the other fds/pipes it cannot safely be assumed
that the loop breaks on its own.
2024-02-11 14:13:22 +01:00
nanahi 71598ca07e various: replace dead links in comments
Replace various dead links with live replacements or archives.
Less friction for anyone who wants to look up these references.
2024-02-11 04:01:24 +00:00
Kacper Michajłow e2e75906da io: add mp_save_file
Move from vo_gpu_next.c to io.c and return result.
2024-01-31 15:38:21 +00:00
Kacper Michajłow 19a6b84915 osdep/timer: update documentation and test for mp_time_ns
No longer true after 8bbcc87fee.
2024-01-26 03:28:55 +00:00
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