Commit Graph

3049 Commits

Author SHA1 Message Date
rcombs 2cfaa820e5 libmpv: add mpv_del_property() convenience function 2023-01-28 14:20:20 -06:00
rcombs 04241ab731 player/command: add "del" command 2023-01-28 14:20:20 -06:00
rcombs dc4fd24c6f player/client: support observing sub-properties
This notifies if either a descendent or ancestor of the requested path is modified.
2023-01-28 14:20:20 -06:00
Thomas Weißschuh 870512eb84 audio: simplify implementation of property ao-volume
ao-volume is represented in the code with a `struct ao_control_vol_t`
which contains volumes for two channels, left and right.

However the code implementing this property in command.c never treats
these values individually. They are always averaged together.
On the other hand the code in the AOs handling these values also has to
handle the case where *not* exactly two channels are handled.

So let's remove the `struct ao_control_vol_t` and replace it with a
simple float.
This makes the semantics clear to AO authors and allows us to drop some code from the AOs and command.c.
2023-01-25 15:49:21 -08:00
Avi Halachmi (:avih) 8eb7a00fa1 msg: log-file set at mpv.conf: don't ignore early messages
Previously, if log-file was set not via a CLI option (e.g. set via
mpv.conf or other config file, or set from a script init phase),
then meaningful early log messages were thrown away because the log
file name was unknown initially.

Such early log messages include the command line arguments, any
options set from mpv.conf, and possibly more.

Now we store up to 5000 early messages before the log file name is
known, and flush them once/if it becomes known, or destroy this
buffer once mpv init is complete.

The implementation is similar and adjacent, but not identical, to an
existing early log system for mpv clients which request a log buffer.
2023-01-23 11:05:08 +02:00
sfan5 1201d59f0b various: replace abort() with MP_ASSERT_UNREACHABLE() where appropriate
In debug mode the macro causes an assertion failure.
In release mode it works differently and tells the compiler that it can
assume the codepath will never execute. For this reason I was conversative
in replacing it, e.g. in mpv-internal code that exhausts all valid values
of an enum or when a condition is clear from directly preceding code.
2023-01-12 22:02:07 +01:00
sfan5 7b03cd367d various: replace if + abort() with MP_HANDLE_OOM()
MP_HANDLE_OOM also aborts but calls assert() first, which
will result in an useful message if compiled in debug mode.
2023-01-12 22:02:07 +01:00
Dudemanguy 6471afecd0 player: don't force saving start in watch-later-options
The watch-later mechanism has always unconditionally wrote start to
files to save the playback position. When this was later expanded to
watch-later-options, this logic was kept in place. But we don't actually
have to unconditionally write this and can allow users to remove the
option from the list if they want to. The start value still requires
some special handling; it should always be written if possible
regardless of the value changing. However, we can just place it within
the default set of options for watch-later-options so it can be removed
like any other.
2023-01-09 16:37:14 +00:00
Christoph Heinrich c4ec47a65e player: add video-sync=display-tempo
So far there was no way to sync video to display and have audio sync to
video without changes in pitch.

With this option the audio does not get resampled (pitch change) and
instead the corrected audio speed is applied to audio filters.
2023-01-09 15:17:09 +00:00
Christoph Heinrich 67321b1440 player: choose speed of smallest acceptable factor for display sync
Instead of choosing based on smallest deviation from set speed,
use the speed change from the smallest factor that does not
exceed `video-sync-max-video-change`.
2023-01-09 15:03:30 +00:00
Ron Shabi b6c9846112 external_files: recognize webp files as cover art
mpv currently only recognizes jpg and png files named "AlbumArt",
"Album", "cover", etc. which are in the same folder as the audio files
as album/cover art and displays it when playing such audios.

This feature adds support for webp files following the same naming
scheme to be displayed as cover art for albums who have them.

Webp variations are lower in priority compared to jpg or png files.

Resolves: #11006
2022-12-29 15:48:57 +01:00
Nicolas F 7614e68233 external_files: set log level for potential files to trace
We ask users to freely share log files with us, which is usually
okay, unless a user has some unrelated and potentially embarrassing
files in their working directory. These would show up in the debug
level message output that --log-file enables.

Change the listing of potential external files to trace log level,
to save the users and the developers the embarrassment.
2022-12-21 19:04:27 +01:00
NRK 25b66256d7 player: add window-id property
currently only supported on x11.

one practical use-case of this is wanting to embed something (such as
dmenu) into the mpv window to use as a menu/selection. there might be
other use-cases as well (e.g doing some shenanigans with `xdotool` or
whatnot).

it's currently possible to:

* listen for 'current-window-scale' change (to check if the
  window has been created or not)
* call an external tool like `xdo` or `xdotool` and grab the xid
  from mpv's pid.

however it adds unnecessary dependency on external tools when mpv is
fully capable of easily providing this information.

closes: #10918
2022-12-05 02:03:25 +00:00
Dudemanguy bca516bd2c osc: don't spam window-controls bindings on every render
Not sure when this actually started happening, but it's probably been
like this for years. Currently, the logic for the window-controls works
by simply checking if the osc is visible and then either enabling or
disabling the associated keybindings. The problem is that this can just
constantly spam mp.enable_keybindings/disable_key_bindings on every
single render call if the user disables the border at any point in time.
This does a lot of pointless work and also results in the logs being
spammed with lines like "disable-section". Clearly, this should just
work like the code for checking the input keybindings just above it.
Keep track of an internal state variable and check when it doesn't match
the osc visibility. In that case, we can then either enable or disable
the key bindings and just update the variable.
2022-11-29 16:40:36 +00:00
Dudemanguy bab85944df player/video: add VOCTRL_CONTENT_TYPE
mpv's core already keeps track of whether or not it thinks a track is an
image. Some VOs (i.e. wayland) would benefit from knowing if what is
currently being displayed is an image or not so add a new VOCTRL that
signals this anytime we load a new file with a VO. Additionally, let's
add a helper enum for signaling the kind of content that is being
displayed. There is now MP_CONTENT_NONE (strictly for force window being
used on a track with no image/video), MP_CONTENT_IMAGE, and
MP_CONTENT_VIDEO. See the next commit for the actual usage of this (with
wayland).
2022-11-15 23:18:55 +00:00
Jan Ekström 0f0520aeca player/main: log libplacebo version if built with it
As we start basing more and more functionality on it, it makes
sense to start logging it more visibly as part of --version.
2022-11-15 21:41:22 +02:00
Christoph Heinrich 445a3561d3 console: add history deduplication
Deduplicate history like the fish shell. So for example
entering "cmd 1" then "cmd 2" then "cmd 3" then "cmd 1"
would result in a history of
[cmd 2][cmd 3][cmd 1]
instead of
[cmd 1][cmd 2][cmd 3][cmd 1]

Adds a function `history_add` to replace directly adding to history.
Adds an option `history_dedup` to activate the deduplication.
Defaults to on.
2022-11-03 13:30:58 +01:00
Christoph Heinrich 1a633a6cbc ytdl_hook: reverse order of tracks
Only matters when configuring ytdl_hook with `all_formats=yes`.

So far the tracks were ordered from worst to best quality.

Web players with quality selection always show the highest quality
option at the top. Since tracks are usually listed with the first
track at the top, that should also be the highest quality one.

yt-dlp/youtube-dl sorts it's formats from worst to best.
Iterate in reverse to get best track first.
2022-11-01 09:54:33 -04:00
Christoph Heinrich fd91776207 console: respect the top margin shared script property
Console already respected the bottom margin to not overlap with the
bottom bar from the OSC, but it would still overlap with the window
decorations from the OSC.

Now everything is clipped above the top margin and no superfluous lines
are drawn.
2022-10-28 13:04:32 +02:00
Christoph Heinrich cc65b3892d osc: scale rendered aspect ratio with window aspect ratio
The logo stays centered better and it doesn't distort anymore due to a
recent change in libass https://github.com/libass/libass/pull/645
2022-10-06 14:34:56 -04:00
Christoph Heinrich ac7f3913d3 ytdl_hook: use subtitle `name` as title if available
So far the `ext` was always used as the title,
but `name` is more appropriate when it's available.
2022-09-23 19:18:49 +00:00
Philip Langdale 989d873d6e filters: lavfi: allow hwdec_interop selection for filters
Today, lavfi filters are provided a hw_device from the first
hwdec_interop that was loaded, regardless of whether it's the right one
or not. In most situations where a hardware based filter is used, we
need more control over the device.

In this change, a `hwdec_interop` option is added to the lavfi wrapper
filter configuration and this is used to pick the correct hw_device to
inject into the filter or graph (in the case of a graph, all filters
get the same device).

Note that this requires the use of the explicit lavfi syntax to allow
for the extra configuration.

eg:

```
mpv --vf=hwupload
```

becomes

```
mpv --vf=lavfi=[hwupload]:hwdec_interop=cuda-nvdec
```

or

```
mpv --vf=lavfi-bridge=[hwupload]:hwdec_interop=cuda-nvdec
```
2022-09-21 09:39:34 -07:00
Christoph Heinrich e302c9b7dd ytdl_hook: simplify exclude option parsing
The parsing used to be unnecessarily complicated,
now it's easier to read and understand.
2022-09-14 13:29:11 +02:00
Thomas Weißschuh 013ec877f6 audio: try to use playback AO as hotplug AO first
When a platform has multiple valid AOs that can provide hotplug events
we should try to use the one that also provides playback.

Concretely this will help when introducing hotplug support for
ao_pipewire.

Currently ao_pulse is probed by ao_hotplug_get_device_list() before
ao_pipewire and on the common setups where both AOs could work pulse
will be selected for hotplug handling.
This means that hotplug_init() of ao_pipewire will never be called and
list_devs() has to do its own initialization.
But if ao_pulse is non-functional or not compiled-in suddenly
ao_pipewire *must* implement hotplug_init() for hotplugging events to
work for all.

Also if the hotplug ao_pulse connects to a PulseAudio instance that is
not emulated by the same PipeWire instance as the playback ao_pipewire
the hotplug events are useless.
2022-09-11 20:24:42 -07:00
Thomas Weißschuh 3167a77aa3 audio: add AOCONTROL_UPDATE_MEDIA_ROLE
This is used to notify an AO about the type of media that is being
played.
Either a movie or music.
2022-09-10 12:32:52 -07:00
Philip Langdale e2e8c21be4 player/audio: remove explicit drain on EOF
We have previously had a problem where pull AOs (such as pipewire)
would not reinitialize on a format change when going between two
audio-only files. In such a situation, playback would stop after the
first file.

We initially attempted to fix this by explicitly draining on EOF, which
solves that problem but introduces a blocking step where we don't
actually want one, breaking gapless audio, and causing dropped frames
at the end of playback for files with video in them too.

So, let's undo these changes and do something better in the next
commit.
2022-08-23 11:01:52 -07:00
Thomas Weißschuh bf5c19e05b audio: don't try to drain non-existent AO
52aed495cb ("audio: drain ao on EOF") introduced logic to drain an AO
when EOF of the input has been reached.
When no AO however is present this leads to a NULL-dereference.

Fixes #10556
2022-08-21 08:05:13 -07:00
Christoph Heinrich 08dd30fde8 ytdl_hook: improve track detection
Every format that was not detected as a video format was added to the
audio tracks. This resulted in e.g. YouTube storyboards from ending up
in the list of audio tracks.

Now formats that are already known to be neither video formats nor audio
formats, will also not end up in any track list.

Formats where it is unknown if they are video or audio get added to
tracks if `force_all_formats` is used, otherwise only
formats that are known to contain video or audio become video or audio
tracks respectively.

https://github.com/yt-dlp/yt-dlp/issues/4373#issuecomment-1186637357
2022-08-17 20:04:00 +00:00
Christoph Heinrich 1ef53f094b ytdl_hook: consistant behavior for single format
One would expect that e.g.
`--script-opts=ytdl_hook-all_formats=no --ytdl-format=bestaudio` and
`--script-opts=ytdl_hook-all_formats=yes --ytdl-format=bestaudio`
to play the exact same tracks without manual intervention.
This already worked when two formats were requested.
For a single format with `all_formats=yes` it would also play a track
that was not requested when available. This was inconsistant with the
behavior of `all_formats=no` (default), which would not play a second
track when only a single one was requested.
This combined with #10395 now plays the exact same tracks with
`all_formats=yes` as without, even when only one format is requested.
2022-08-14 23:31:51 +00:00
Christoph Heinrich 813dfe1924 ytdl_hook: fix default track for single format
Tracks are marked as default tracks based on what yt-dlp/youtube-dl
returns in the field `requested_formats`. The problem is that this field
only exists when there is more then one requested format.
So `ytdl-format=bestvideo+bestaudio` would have that field,
but `ytdl-format=bestaudio` would not,
leading to no tracks being marked as default tracks.

The requested formats can also be found under `requested_downloads`,
which exists regardless of the number of requested formats.
However when there is more then one requested format,
`requested_downloads` doesn't contain those formats directly and instead
has a field `requested_formats` that is identical to the other
`requested_formats`. Therefore use `requested_downloads` as a fallback
for when `requested_formats` doesn't exist.
2022-08-12 14:31:59 +00:00
Thomas Weißschuh 52aed495cb audio: drain ao on EOF
This gives pull-based AOs the chance to play all queued audio.
Also it will make sure that the audio has finished playing so we can
reinitialize the AO if format changes are necessary.

Fixes #10018
Fixes #9835
Fixes #8904
2022-08-09 10:30:58 -07:00
Christoph Heinrich 284fecc0bd ytdl_hook: fix playlist index extraction
The example given in #3024 would not play the correct video when
combined with `--ytdl-raw-options=yes-playlist=`.
Allowing `youtube:tab` as extractor and correcting the id check fixes
that.
2022-07-26 21:16:23 +00:00
Ryan Hendrickson ad5a1ac873 osc.lua: add osc-tcspace script option
Generally, the hard-coded sizes used for the OSC elements are
comfortable regardless of the font used, but the timecode fields have
relatively many characters, and so are affected to a greater degree by
fonts with a wider or narrower average character width than expected.

This allow users to adjust the space reserved for the timecode fields to
compensate.
2022-07-19 23:19:45 +03:00
Ryan Hendrickson ff25a8c65a osc.lua: add osc-unicodeminus script option
This option enables the use of the Unicode U+2212 Minus Sign character
when displaying the time remaining, instead of "-" (U+002D
Hyphen-Minus).
2022-07-19 23:19:45 +03:00
Christoph Heinrich 431473310f ytdl_hook: always set HTTP headers
In some cases HTTP headers were not set, leading to some sites not
working despite being supported by yt-dlp/youtube-dl.
2022-07-18 01:17:00 +00:00
Avi Halachmi (:avih) 3694af6076 js: key bindings: ensure priorities for same-key - again
Commit 7f4841ff sorted the bindings so that if the same key was bound
more than once, then the newest binding takes priority (sorted last).

However, it got the comparison function wrong, which means the result
of the sort depended on the algorithm and not on the actual data, so
the priority for keys with more than one binding was still arbitraty.

Fix the sort function, and finally ensure that later binding acutally
override earlier bindings of the same key.
2022-06-23 17:16:33 +03:00
CogentRedTester 1ffdb9128d lua: command_native_async: make the callback optional
The documentation states that the callback is optional, but it actually
was not.

Now it's optional, as docuented.
2022-06-22 14:44:52 +03:00
CogentRedTester 099ae86717 lua: command_native_async: always callback a-sync
Previously if the raw command_native_async returned an error then the
callback function was run directly. This meant that script writers
potentially had to account for both synchronous and asynchronous logic
in the callback, which can happen even with seemingly 'safe' commands
if the mpv event queue is full.

This was at odds with the Javascript implementation of
the function, which always runs the callback asynchronously.

Now the mp.add_timeout function is used to run the callback
asynchronously on error, replicating the Javascript implementation.

This provides consistency for developers in how the callback is handled
in Lua, and increases consistency between the Lua and Javascript APIs.
2022-06-22 14:44:12 +03:00
AtticFinder65536 a4f0db051a player: add tiff/tif (TIFF) to list of image extensions 2022-06-07 06:28:34 -04:00
AtticFinder65536 bd46f050fe player: add jxl (JPEG XL) to list of image extensions 2022-06-07 06:28:34 -04:00
Dudemanguy ec236f7a99 osc.lua: add idlescreen and osc-idlescreen
This is mainly for other user scripts that may conflict with the osc
logo in some way. Although it is possible to listen for
shared-script-properties, this has many edge cases that could easily pop
up. A user could want other OSC things to happen at the same time (say
osc-message). They just don't want the logo. The idlescreen option
disables all idlescreen related things (including the santa hat) if it
is set to "no". A new script message (osc-idlescreen) is also added so
users can easily toggle the value (passing "cycle" or just explictly
setting "yes" or "no"). Some more discussion on this is found in the
below github issues.
https://github.com/mpv-player/mpv/issues/10201
https://github.com/CogentRedTester/mpv-file-browser/issues/55
2022-06-04 14:48:32 +00:00
CogentRedTester b4c73ed105 osc.lua: fix crash when calling osc-tracklist while idle
If the player is started with --idle  and the osc-tracklist script-message
is called then the tracks_osc table will be nil,
which caused the OSC to crash due to attempting to index a nil value.

This appears to be because the osc_tracklist variable is both
initialised and updated by (ultimately) the render() function, which
is not run when the player is idling.

Rather than mess with the existing OSC logic it's easier to either
add this single check, or alternatively to initialise the the tracks_osc
table somewhere before this.
2022-05-19 13:54:31 +00:00
Dudemanguy f20dbcd620 player: check for argv before printing help text
Both mpv's main function and the client API use mp_initialize to start
up. In general, these work the same however the client API had one
slight, unnecessary limitation: you can't start it up with idle=no. In
practice, the libmpv profile (used with the client API) sets idle to
yes, so it's rarely encountered, but there's no particular reason why
this policy needs to be enforced. It turns out that mp_initialize does a
quick check to see if there are any entries in the playlist and if idle
mode is set. If not, it prints the help message and exits. Basically,
it's just the part that handles the terminal message when you type "mpv"
with no arguments. Unfortunately with idle=no, the client API also hits
this code path, exits prematurely with 1 and thus returns an API error.

Fortunately, the fix is very simple. If the client API is used instead
of the "normal" mpv executable, then the mp_initialize function gets a
NULL for the options argument. When starting mpv from the terminal (when
you would want to see the before mentioned help text), there will always
be at least an argv[0] (the mpv executable name itself) so we can
reliably distinguish between the two. The other case where there could
be no argv is if the pseudo-gui profile is used, but this always
enforces idle so we don't have to worry about it either. In other words,
with this combination of conditions (options, no idle, and no playlist
entries), we can be sure this is from a user calling mpv in the terminal
with no arguments. Therefore, other cases can be allowed which means
client API users can initialize with idle=no. Fixes #10162.
2022-05-16 21:10:09 +00:00
Dudemanguy 9467772362 player: set EOF when seeking to end with keep-open
Normally with the keep-open option, mpv is supposed to set the
eof-reached property to true so clients can possibly do interesting
things at this step. However, there was actually an edge case where this
property notification did not occur. If you use keep-open and then seek
in the file past the end (so mpv stops), property notification is not
actually sent in this case. Internally, mpv does a very exact seek at
this step which also ends playback, but it does not set STATUS_EOF to
the ao and vo before the core idle state is updated. To fix this edge
case, it's simply just a matter of explictly setting STATUS_EOF after
seek_to_last_frame in handle_keep_open. This logic will only ever
trigger if keep-open is being used and the seek goes past the end of the
file, so we know that there will always be an EOF here.
2022-05-14 14:51:42 +00:00
Guido Cella fe9e074752 various: remove trailing whitespace 2022-05-14 14:51:34 +00:00
Guido Cella e686297ecf lua: avoid rare memory leak in mp.join_path
If lua_pushstring is OOM, then our joined path allocation is leaked. Use
autofree to ensure it's not leaked in case of Lua OOM.
2022-05-12 17:15:37 +03:00
Guido Cella ebaf6a6cfa console.lua: don't render a 2nd cursor on the OSC
09ea3a424f moved the console above the OSC when it is visible so they
don't overlap, but only changed the first ass:pos() call and forgot to
update the second one, which redraws the cursor on top of the text, so
when both the OSC and the console are visible, a second cursor is drawn
on the OSC. You have to type past where the buttons are to notice it.

This commit synchronizes the position of the 2 ASS events.
2022-05-01 21:48:20 +10:00
Cœur bb5b4b1ba6 various: fix typos 2022-04-25 09:07:18 -04:00
Guido Cella 9d2a6dc302 player: add cover-art-whitelist option
This allows more fine grained control over which cover art to load. With
--cover-art-auto=exact and --cover-art-whitelist=yes, you can now load
cover art with the exact media filename and the whitelisted filenames,
but not cover art that contains the media filename
(--cover-art-auto=fuzzy).
2022-04-21 16:42:27 +00:00
Dudemanguy fe6d9b6962 player: rearrange video sync opts/enums/defines
The video sync logic for mpv lies completely within its core at
essentially the highest layer of abstraction. The problem with this is
that it is impossible for VOs to know what video sync mode mpv is
currently using since it has no access to the opts. Because different
video sync modes completely changes how mpv's render loop operates, it's
reasonable that a VO may want to change how it renders based on the
current mode (see the next commit for an example).

Let's just move the video sync option to mp_vo_opts. MPContext, of
course, can still access the value of the option so it only requires
minor changes in player/video.c. Additionally, move the VS_IS_DISP
define from to player/core.h to common/common.h. All VOs already have
access to common/common.h, and there's no need for them to gain access
to everything that's in player/core.h.
2022-04-11 18:14:22 +00:00