Commit Graph

48179 Commits

Author SHA1 Message Date
wm4 b05550fe55 ipc: implement asynchronous commands
I decided to make this explicit. The alternative would have been making
all commands asynchronous always, like a small note in the manpage
threatened. I think that could have caused compatibility issues.

As a design decision, this does not send a reply if an async command
started. This could be a good or bad idea, but in any case, it will make
async command look almost like synchronous ones, except they don't block
the IPC protocol.
2020-02-24 00:14:54 +01:00
wm4 a9e6b9ea36 client API: minor clarification when asynchronous commands send events 2020-02-24 00:09:51 +01:00
wm4 0ec036bfd8 ta: remove two pointless wrappers 2020-02-23 19:48:25 +01:00
wm4 758082a1f2 ta: minor simplification
Due to the ta_header.parent invariant, the "h->parent->child==h" check
is always true.
2020-02-23 19:45:25 +01:00
wm4 4839106a99 client API: fix race condition on client exit
The relatively recently added property update code has a race condition
when clients exit. It still tried to access mpv_handle during and after
it was destroyed.

The reason is that it unlocks the lock for the mpv_handle list (while
mpv_handle is locked), but nothing in mp_destroy_client() cares about
this case. The latter function locks mpv_handle only before/while it
makes sure all of its activity is coming to an end, such as asynchronous
requests, and property updates that are in progress. It did not include
the case when mp_client_send_property_changes() was still calling
send_client_property_changes() with mpv_handle locked.

Fix this by checking the mpv_handle.destroying field. This field can be
set only when mpv_handle is locked. While we're checking the lock, the
mpv_handle list is still locked, so at worst we might be at the point
before mp_destroy_client() locks the list again and finally destroys the
mpv_handle.

This is a hard to reproduce race condition which I spotted only once in
valgrind by chance, so the fix is unconfirmed.
2020-02-23 17:52:21 +01:00
wm4 bc3678da65 ta: change API; ta_set_parent() and ta_set_destructor() never fail
The previous change ensured that these cannot fail anymore (much like in
original talloc). Change the APIs to not return a success value anymore,
to "cement" this.
2020-02-23 17:45:05 +01:00
wm4 f6615f00ee ta: remove seperate internal "ext" header
The ta_ext_header was allocated on demand for allocations which have
child-allocations or destructors. In theory, it saved 2 words for every
TA leaf allocation. It had the very API-visible problem that setting a
parent or destructor could fail. (Although in most cases, the failure
was part of an allocation call anyway. Also, mpv code generally used the
early-failure variants, so it didn't matter.)

I think this was a bit too complex. These 2 words don't really matter;
if you have memory allocations where you are worried about overhead,
then these simply shouldn't use TA. Also, we never added new features to
TA that would have needed more "optional" header fields, which would
have justified the use of such a separately allocated header struct.

This uses quite straight-forward data structures. The only strange thing
is that ta_header.parent is NULL for most child allocations. That is
because we don't want to iterate over all children when the parent is
reallocated (yes, that is allowed, yes mpv makes use of it).

The new code has a few more special cases, because the list sentinel
concept isn't used anymore. Using it would have made the code more
unnatural/complex, because ta_ext_header doesn't exist anymore.
2020-02-23 17:36:27 +01:00
wm4 a9586625d1 ta: remove ta_find_parent()
Some mpv code once needed this, but it was removed in 2015.
2020-02-23 14:32:15 +01:00
sfan5 57ecfb4da2 ytdl_hook: fix URL extraction for manifests 2020-02-23 12:04:55 +01:00
der richter ee6ad403a7 cocoa-cb: fix crash with some japanese characters
the actual character that made mpv crash is IDEOGRAPHIC COMMA
(U+3001, UTF-8: E3 80 81, 、) and that only in some specific
circumstances that could be reliably reproduced on my end.

using an NSString instead of the Swift String actually fixes that issues
even though they should technically do the exact same thing. i tested
all the other String initialisers, but they all had had the same issue.
this is kinda only a workaround till i can find a different way of
handling it.
2020-02-22 14:21:06 +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 8e1ceaba34 cocoa-cb: remove unnecessary semicolons 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 c1d744328e x11: switch back to StaticGravity
This was changed 6 years ago (444e583b6) and seemed to work fine. But it
does seem to cause issues with IceWM sometimes, while with StaticGravity
the problem is gone. Comparing both gravity values, reading the confused
source code comment, and reading the referenced commit message, I can't
determine what it even does, I just remove it.

Reproduction:
- start mpv in windowed mode, with 2 videos of different size
- switch to second video
- switch window with alt+tab
- switch back to mpv with alt+tab
- window moves to X=0

There's probably a better way to fix this. Please send a patch.
2020-02-22 01:35:12 +01:00
wm4 c68b813678 ytdl_hook: prefer "format" over "format_note" field for track titles
Much more verbose, but on the other hand format_note is useless for the
alphabetic site with fragmented DASH streams.
2020-02-21 22:23:17 +01:00
wm4 dc82921012 ytdl_hook: use "format" as fallback for "format_note" for stream titles
"format_note" normally contains a semi-informative description of the
format. But some extractors, confusingly, have it in the "format" field.
2020-02-21 16:38:17 +01:00
wm4 2b9b77fcf3 ytdl_hook: fix audio codec with some extractors
E.g. soundcloud. While it still worked, not having the audio codec was
pretty annoying.
2020-02-21 16:27:56 +01:00
wm4 c1f7b0c535 ytdl_hook: fix Lua escapes
This was obviously nonsense. In Lua 5.1 this appeared to work correctly,
but it really turned "\." into "." (making the pattern accept any
character). The proper way is using "%" for escaping.
2020-02-21 16:23:43 +01:00
wm4 605e1fb766 ytdl_hook, edl: add fps, samplerate codec parameters
Well, didn't help much in the case I was interested it.
2020-02-21 14:48:23 +01:00
wm4 2eab35fdf7 manpage: directly link interface-changes.rst in changelog section 2020-02-21 14:34:02 +01:00
wm4 6337c1cc14 ytdl_hook: make codec mapping more declarative 2020-02-21 14:29:55 +01:00
wm4 04118eefb8 ytdl_hook: remove some old playlist redirection hack
Should not be needed anymore. In fact, it's probably dangerous.
2020-02-21 14:19:01 +01:00
wm4 4c32468241 ytdl_hook: enable default selection via --ytdl-format with all_formats
In all_formats mode, we've ignored what --ytdl-format did so far, since
we've converted the full format list, instead of just the formats
selected by youtube-dl.

But we can easily restore --ytdl-format behavior: just mark the selected
tracks as default tracks.
2020-02-21 14:18:35 +01:00
wm4 a77780e6be edl: make it possible to set the track "default" flag
Also, the forced flag (and in the future, potentially a number of other
flags not implemented yet). See next commit for purpose.
2020-02-21 14:16:26 +01:00
wm4 1cda73356d manpage: fix some path description details 2020-02-21 12:13:54 +01:00
wm4 1edb57159f manpage: suggest using PuTTY for accessing mpv IPC named pipes on win32 2020-02-21 12:09:16 +01:00
wm4 daa3c11e1b ytdl_hook: add length parameter to delay-loaded tracks only once
This was done for each media type, so muxed tracks had it twice, which
logged a dumb warning. Move it out of the per-media type loop.
2020-02-21 12:06:18 +01:00
wm4 9f5b9011d6 demux_edl: correct warning on duplicate parameters
A parameter that is actually used is removed from the param_names[]
array, so we can report unused parameters. This also happened on
duplicate parameters, so adjust the warning to make it less confusing.

(In any case, you're not supposed to provide duplicate parameters.)
2020-02-21 12:05:29 +01:00
wm4 3d225ad275 ytdl_hook: remove bitrate estimation from file size
I think this is unnecessary, and at worst done by youtube-dl itself
(didn't check).
2020-02-21 11:57:57 +01:00
wm4 76aaf74d30 ytdl_hook: use tbr for all tracks if vbr/abr not available
vbr and abr are the video and audio bitrates. Sometimes there is a weird
mix of any of them available, but in these cases, it's not good to fall
back to tbr if a specific track has no vbr/abr.

For example, the alphabetic site provides tbr only for the muxed
fallback stream, but using tbr would make the primitive mpv hls_bitrate
selection pick the compatibility stream for audio, because it appears to
have a higher bitrate than the other audio-only streams (because the
bitrate includes video). So we must not use tbr in this case.

On the other hand, formats coming from youtube-dl HLS master playlist
use will only have tbr set.

So as a heuristic, use the tbr only if it's the only bitrate available
in any track entry.
2020-02-21 11:57:21 +01:00
wm4 6d09a042e6 ytdl_hook: replace skip_muxed with force_all_formats option
I don't think the skip_muxed option was overlay useful. While it was
nice to filter out the low quality muxed versions (as it happens on the
alphabetic site, I suspect it's compatibility stuff), it's not really
necessary, and just makes for another tricky and rarely used
configuration option. (This was different before muxed tracks were also
delay-loaded, and including the muxed versions slowed down loading.)

Add the force_all_formats option instead, which handles the HLS case.
Set it to true because they are also delay-loaded now, and don't slow
down startup as much.
2020-02-21 11:50:58 +01:00
wm4 fbbfbfc772 manpage: reorganize ytdl_hook option descriptions
Make it a proper list, instead of a paragraph soup.
2020-02-21 00:30:41 +01:00
wm4 390e995b6a ytdl_hook: delay-load interleaved files
(Or if it's about HLS, just "muxed"/multiplexed streams.)

This only affects all_formats=yes,skip_muxed=no modes.
2020-02-21 00:20:22 +01:00
wm4 6f0297dff4 edl: make it possible to delay-load files with multiple tracks
Until now, delay-loading was for files with single tracks only
(basically what DASH and HLS like to expose, so adaptive streaming and
codec selection becomes easier - for sites, not for us). But they also
provide some interleaved versions, probably for compatibility. Until
now, we were forced to eagerly load it (making startup slightly slower).

But there is not much missing. We just need a way to provide multiple
metadata entries, and use them to represent each track.

A side effect is now that the "track_meta" header can be used for normal
EDL files too.
2020-02-21 00:19:17 +01:00
wm4 6726b7a1ba demux_lavf: signal no seeking for RTSP streams without duration
RTSP supports seeking, but at least the libavformat implementation makes
this dependent on runtime behavior. So you have to perform a seek, and
check if it fails. But even if you do this, the stream is interrupted
and restarted, and there seem to be other issues.

Assume that RTSP with unknown duration means it's a live stream, and
disable seeking in this case, as suggested by the issue reporter.

Fixes: #7472
2020-02-20 15:28:49 +01:00
wm4 bd6d8d320f demux_timeline: don't open every delayed-open track on seeking
Now this was stupid. To seek a source, it obviously has to be opened...
so just don't try to seek any unused source. If the track is actually
selected during playback, a seek to the correct position is performed
anyway.
2020-02-20 15:21:27 +01:00
wm4 0020b47ffd demux: fix seek range caching with delay_open hack
These have ->segmented set (so the codec can be initialized properly),
but have no segment start or end times. This code was (probably) the
only thing which didn't handle this case.
2020-02-20 15:11:46 +01:00
wm4 f321d8da99 ytdl_hook: signal duration in all_formats mode
If all streams were delay loaded, there was actually no duration present
at all in the EDL metadata. So the length was considered unknown by the
player frontend.
2020-02-20 14:55:14 +01:00
wm4 89203cc994 ytdl_hook: attempt to filter out muxed streams if all_formats is used
See manpage additions. We would have to extend delay_open to support
multiple sub-tracks (for audio and video), and we'd still don't know (?)
whether it might contain more than one stream each (thinking of HLS
master streams). And if it's a true interleaved file (such as a "normal"
mp4 file provided as fallback for more primitive players), we'd either
have to signal such "bundled" tracks, or waste bandwidth.

This restructures a lot. The if/else tree in add_single_video for format
selection was a bit annoying, so it's split into separate if blocks,
where it checks each time whether a URL was determined yet.
2020-02-20 14:54:09 +01:00
wm4 c2e62817f6 ytdl_hook: remove forgotten debug message
It even has a typo.
2020-02-20 14:40:01 +01:00
wm4 af9403577a ytdl_hook: use bitrate fields for bitrate metadata instead of file sizes
If available.
2020-02-20 12:34:06 +01:00
wm4 f5c1d71639 ytdl_hook: try to skip interleaved streams with all_formats
If a "format" has both audio and video codec set, it might contain both
audio and video. all_format assumes that each format is just a quality
variant containing a single track.

This seems to happen with sites that provide a HLS master URL.
youtube-dl tends to "butcher" it, and the result isn't very ideal. I
guess HLS "renditions" simply don't map well to youtube-dl's output
format and what mpv expects. Playing master HLS directly is also less
than ideal, because of libavformat's stupid probing.

Fix this by not using the delay-opening mechanism if it appears like we
detected such a case. Add a metadata override to set the track titles to
"muxed-N", to indicate that they form a single unit. (Mostly helpful for
testing.)
2020-02-20 12:25:45 +01:00
wm4 eaa10a25c7 ytdl_hook: iterate format list by array order
Shouldn't have any consequences. Probably makes the user-visible order
more stable.
2020-02-20 12:17:59 +01:00
wm4 e64645540a demux_timeline: warn if streams are invisible
ytdl_hook.lua can do this with all_formats and when delay_open is used,
and if the source stream actually contains both audio and video. In this
case, it might accidentally hide a media type completely, or waste
bandwidth (if the stream has true interleaved audio/video). So it's
important to warn.
2020-02-20 12:16:32 +01:00
wm4 4e11ac82aa player: change bitrate in track listing back to kilobits
Because the --hls-bitrate option takes the same unit.
2020-02-20 12:13:32 +01:00
wm4 3db8715f70 manpage: minor fixes
In particular, all_formats description split away the example section of
an unrelated option, so move that to its proper place.
2020-02-19 23:11:02 +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 d06ebe2251 client API: document requirement about PID management
Basically, UNIX sucks. (Not as much as the other POS of course.)
2020-02-19 22:16:26 +01:00
wm4 e22b771ff8 build: remove fchmod() check
This is UNIX-only code, and this function has been in POSIX since
forever. Even Android has it. The test should be unnecessary, so remove
it.
2020-02-19 20:38:12 +01:00
wm4 6d8b4ca742 ytdl_hook: add all_formats option
Pretty worthless I guess. I only tested one site (and 2 videos), it's
somewhat likely that it will break with other sites. Even if you leave
the option disabled (the default).

Slightly related to #3548. This will allows you to use the bitrate
stream selection mechanism, that was added for HLS, with normal videos.
2020-02-19 16:33:48 +01:00