Commit Graph

2780 Commits

Author SHA1 Message Date
Avi Halachmi (:avih) 5ff215c4df stats.lua: don't disable terminal escape sequences on windows
When stats.lua is used without a video window then it uses the terminal.
On Windows, however, so far it disabled ansi escape sequences and used
plaintext unless ANSICON env is set.

It's unclear why it's disabled on windows, because at the time it was
added it only used bold by default and mpv ansi emulation on windows
already supported bold at that time.

We can guess that it was disabled because if the same config is used on
both linux and Windows, and it had complex escape sequences for
stats.lue, then it would be emulated incorrectly on Windows.

This shouldn't be an issue anymore, as the last two commits both enhance
the emulation to be quite complete (and graceful where it's not), and
also enable the much-more complete native VT terminal when possible
(Windows 10).

Just remove this windows exception at stats.lua.
2020-04-23 17:02:38 +03:00
LaserEyess 34e7d9c2f4 stats: move chapter/edition info below title
It is more consistent for editions/chapters to go below either
the title or filename. They are all descriptive strings about
the media itself and not file metadata like filesize.

Suggested by Argon-
2020-04-16 23:13:46 +02:00
LaserEyess c364879e9f stats: add edition information to page 1
Edition information is conditional based on there being more than
one edition present. It is printed on the same line as Chapters to
save vertical space.
2020-04-16 23:13:46 +02:00
wm4 cc2ee06e57 player: remove duplicated track option setter code
Well whatever.
2020-04-15 17:10:01 +02:00
wm4 6c02555397 player: slightly improve use of secondary track selection limits
Apparently, this was a bit of a mess, which caused the bug fixed by
commit ec7f2388af. Try to improve this, and only use track selection
entries that exist.
2020-04-15 17:04:00 +02:00
wm4 dae0652e19 player: remove mysterious declaration
??????????
2020-04-15 16:51:28 +02:00
Niklas Haas ec7f2388af player: don't segfault when unloading tracks
e1e714ccc introduced a regression here when unloading a track (e.g. on
VO/AO initilization error), due to no corresponding option existing for
video/audio tracks with orders above 0, but the loop in
`mp_deselect_track` being hard-coded to clear tracks up to NUM_PTRACKS.

Introduce the simplest possible hackaround.
2020-04-15 08:02:28 +02:00
wm4 f6c81047fa player: do not fall back to a default track with explicit selections
Consider e.g. --aid=2 with a file that has only 1 track. Then it would
fall back to selecting track 1. Stop doing this. If no matching track is
found, this will not select any track now.

Note that the fingerprint stuff (track_layout_hash in the source)
prevents softens the impact of this change. Without the fingerprint,
playing a dual-audio file with the second track selected, and then a
single-audio file, would play the second file without audio. But the
fingerprint resets it due to differences in the track list.

Try to exhaustively document this and tricky interactions between the
other features. What a damn mess, I think it's simply cursed. Of course
it's still my fault.

See: #7608
2020-04-13 15:56:52 +02:00
wm4 e1e714ccc3 player: mess with track selection details again
Some time ago, properties and options were mostly unified. However, the
track selection properties/options semantics are incompatible to this
change. I'm still trying to handle the fallout.

There are two things that are in the way:
1. Track properties somehow return the runtime selection, not the option
   value (all while properties are supposed to be aliases to options
   with the same name).
2. The user's track options are not supposed to be changed without
   interaction. If a track is auto-selected, the property should return
   its ID, but the option value should remain at "auto". Only if the
   user actually writes to the property the option should change. E.g.
   playing e.g. an audio-only file and then a normal video file not play
   the video file with --vid=no just because the audio file had no video
   track.

In addition to each of them being in conflict with the property/option
unification, attempt to fix one of them breaks the other one.

Today, we're trying to fix parts of this and avoiding an unfortunate
case where you can get a conflicting option/property value, and where
trying to select a track does nothing if the track to select has the
same ID as the option value.

This breaks 2. from above in certain situations. See manpage additions.

See: #7608
2020-04-13 15:56:52 +02:00
wm4 835137a0e5 player, ta: remove use of an old macro
I thought that would make a nice idiom, but it ended up being useless or
clunky.
2020-04-13 15:56:27 +02:00
LaserEyess e796fe4bfc command: print edition title to OSD when cycling
Edition title is already exposed in demux_edition, it was just never
added to the display. If no edition title exists it will fall back
to the edition number.
2020-04-13 01:04:32 +02:00
Avi Halachmi (:avih) 530a0863b8 stats: support UP/DOWN to scroll at page 4 (perf)
Keys and lines-to-scroll are configurabe, and the scroll keys are only
bound on pages which support scrolling (currently only page 4) - also
during oneshot (like the page-switching keys).

Scroll offset is reset for all pages on any key - except scroll keys, so
that entering or switching to a page resets the scroll, as well as when
"re-entering" the same page or "re-activating" the stats oneshot view.

TODO: print_page(..) is highly associated with extending the oneshot
timer if required. The timer handling can probably move into print_page
and removed from all the places which boilerplate its management.
2020-04-11 16:04:46 +03:00
wm4 c2ee7bce4c console: reduce memory usage in default mode
This used 1 MB due to building the complete command and property list
when starting the script. These are needed only for auto-completion, so
build them only on demand. Since building them is fast enough, rebuild
them every time.

The key bindings table is not that much, but saves some KBs. Oddly, the
code to build it uses less memory than the table at runtime (???), so
build it at runtime as well.

Add 2 tactic collectgarbage() calls as well. This frees unused heap when
it is known that the script is going to be completely inactive until
re-enabled by the user.
2020-04-10 13:36:10 +02:00
wm4 0c9ac5835b video: remove another redundant wakeup
The wakeup at the end of VO frame rendering seems redundant, because
after rendering almost no state changes. The player core can queue a new
frame once frame rendering begins, and there's a separate wakeup for
this. The only thing that actually changes is in->rendering. The only
thing that seems to depend on it and can trigger a wakeup is the
vo_still_displaying() function. Change it so that it needs an explicit
call to a new API function, so we can avoid wakeups in the common case.

The vo_still_displaying() code is mostly just moved around due to
locking and for avoiding forward declarations.

Also a somewhat risky change (tasty new bugs).
2020-04-10 01:33:38 +02:00
wm4 a1771ed0d4 video: avoid redundant self-wakeup on each queued frame
This should be unnecessary, since the VO itself performs wakeups once a
new frame can be queued. The only situation I can think of where this
might be required are EOF situations (which are always strange).

If I'm wrong, there'll be fun new bugs, probably causing frame drops or
temporary stalls.
2020-04-10 01:28:06 +02:00
wm4 a2846faa32 player, stats: more silly debug stuff
In addition to stats.c being gross, I don't think master branch code
should be littered with debug code. But it's a helpful abomination.
2020-04-10 00:55:39 +02:00
wm4 73e565dc0f stats: fix crash if both plot_vsync_* options are disabled
In this case, init_buffers() was not called, and the unrelated cache
sample buffers were not initialized. It appears they are indeed
completely unrelated, so move their initialization away. Not sure what
exactly the purpose of calling init_buffers() is, maybe clearing old
data when displaying stats again. The new place for initializing the
cache sample buffers should achieve the same anyway.

Fixes: #7597
2020-04-09 15:03:17 +02:00
wm4 7df9f81d22 player: do not deinitialize AO on track switching
This should make it behave roughly like when switching from a file to
the next (clearing audio buffers, keeping AO, but closing AO if the
audio format seems to have changed and gapless mode is "weak").

Not necessarily useful, but harmless and may help with #7579 (untested).
2020-04-09 11:45:46 +02:00
Niklas Haas a67bda2840 lua: wrap existing allocator instead of reimplementing it
This is the proper fix for 1e7802. Turns out the solution is dead
simple: we can still set the allocator with lua_getallocf /
lua_setalloc.

This commit makes memory accounting work on luajit as well.
2020-04-09 02:21:09 +02:00
Niklas Haas 1e780251ae lua: disable memory accounting for luajit
This is a stopgap measure. In theory we could maybe poll the memory
usage on luajit, but for now, simply reverting this part of fd3caa26
makes Lua work again. (And we can still collect cpu usage metrics)

Proper solution pending (tm)
2020-04-09 01:56:41 +02:00
wm4 1bdc3bed00 ipc: add --input-ipc-client option
While --input-file was removed for justified reasons, wanting to pass
down socket FDs this way is legitimate, useful, and easy to implement.

One odd thing is that

Fixes: #7592
2020-04-09 01:05:51 +02:00
wm4 fd3caa264e stats: some more performance graphs
Add an infrastructure for collecting performance-related data, use it in
some places. Add rendering of them to stats.lua.

There were two main goals: minimal impact on the normal code and normal
playback. So all these stats_* function calls either happen only during
initialization, or return immediately if no stats collection is going
on. That's why it does this lazily adding of stats entries etc. (a first
iteration made each stats entry an API thing, instead of just a single
stats_ctx, but I thought that was getting too intrusive in the "normal"
code, even if everything gets worse inside of stats.c).

You could get most of this information from various profilers (including
the extremely primitive --dump-stats thing in mpv), but this makes it
easier to see the most important information at once (at least in
theory), partially because we know best about the context of various
things.

Not very happy with this. It's all pretty primitive and dumb. At this
point I just wanted to get over with it, without necessarily having to
revisit it later, but with having my stupid statistics.

Somehow the code feels terrible. There are a lot of meh decisions in
there that could be better or worse (but mostly could be better), and it
just sucks but it's also trivial and uninteresting and does the job. I
guess I hate programming. It's so tedious and the result is always shit.
Anyway, enjoy.
2020-04-09 00:33:38 +02:00
wm4 f9cc29ec91 stats: fix previous commit
The previous commit included a rendering error of the "Speed:" line,
caused by incorrect copy&paste.
2020-04-03 23:26:51 +02:00
wm4 516934b233 stats: move input speed to cache page, make it a graph
I think that makes more sense.

And also remove the graph from the total cache usage, since that wasn't
very interesting. So there's still a total of 2 graphs.
2020-04-03 14:54:32 +02:00
wm4 28edf2d0f0 command: make input speed available as part of cache statge property
That's where it comes from after all. The other property does not have
much of a reason to exist anymore, but there's no real reason to remove
it either.
2020-04-03 13:20:21 +02:00
wm4 b6655dd72c player: make a function static 2020-04-03 12:56:50 +02:00
sfan5 c8e5a615e9 ytdl_hook: enable runtime changes of script options 2020-03-29 17:45:59 +02:00
wm4 b8daef5d8b input: remove deprecated --input-file option
This was deprecated 2 releases ago. The deprecation changelog entry says
that there are no plans to remove it short-term, but I guess I lied.
2020-03-28 00:41:38 +01:00
wm4 df0d8cda08 client API: report IDs of inserted playlist entries on loading playlist
May or may not help when dealing with playlist loading in scripts. It's
supposed to help with the mean fact that loading a recursive playlist
will essentially edit the playlist behind the API user's back.
2020-03-27 00:57:11 +01:00
wm4 1a72037720 scripting: remove race condition when toggling internal scripts
Scripts such as the OSC can be loaded and unloaded at runtime by
toggling the option that enables them. (It even works, although normally
it's only used to control initial loading.)

Unloading was racy because it used the client name; fix this.

The load-script change is an accidental feature. And probably useless.
2020-03-26 23:59:44 +01:00
wm4 9bda301eb4 command: use client IDs for hooks
Removes weird potential race conditions when a client is removed and a
new one with the same name is created.
2020-03-26 23:40:25 +01:00
wm4 ca34922130 client API: add a per client unique ID
I mostly intend this for internal purposes. Probably pretty useless for
external API users, but on the other hand trivial to expose. While it
makes a lot of sense internally, I'll probably regret exposing it.
2020-03-26 23:39:35 +01:00
wm4 953983ad31 command: make revert seek command use time from end of seek
This time is set on every seek (but when initiating it). A new seek
longer than 2 seconds after this is counted as separate seek for the
sake of the revert seek command. If a seek takes a bit longer, this
removes time from these 2 seconds. This commits resets it on the end of
the seek. (Doing anything special for seeks that take longer than 2
seconds is out of scope of this commit.)
2020-03-26 22:50:21 +01:00
Avi Halachmi (:avih) 7768452f2d lua: mp.get_property[_osd] don't need special handling anymore
Because they recently became normal autofree functions.
2020-03-23 01:26:01 +02:00
Avi Halachmi (:avih) 5a2fa3f29a lua: readdir: fix double closedir, use one more autofree
The double closedir is a regression from the previous commit, which also
forgot to use the autofree context with the fullpath string.
2020-03-22 23:49:51 +02:00
Avi Halachmi (:avih) 8deffd9fbb lua: autofree: use in few more places where it could leak
This also uses talloc destructors- like the JS autofree does.

The lua autofree is now used at the same places where the JS autofree
is used.
2020-03-22 23:34:19 +02:00
Avi Halachmi (:avih) fb984a3609 lua: autofree: the ctx is now an argument
There's no more need to call mp_lua_PITA to get the ctx, and the
autofree prototype is now enforced at the C level at compile time.

Also remove the redundant talloc_free_children at these functions
since it's now freed right after the function completes.

Also, rename auto_free_node to steal_node_allocations to be more
explicit and to avoid confusion with the autofree terminology.
2020-03-22 23:34:19 +02:00
Avi Halachmi (:avih) eb5635131d lua: use an autofree wrapper instead of mp_lua_PITA
Advantages of this approach:

- All the resources are released right after the function ends
  regardless if it threw an error or not, without having to wait
  for GC.

- Simpler code.

- Simpler lua setup which most likely uses less memory allocation and
  as a result should be quicker, though it wasn't measured.

This commit adds the autofree wrapper and uses it where mp_lua_PITA
was used. It's not yet enforced at the C level, there are still
redundant talloc_free_children leftovers, and there are few more
places which could also use autofree. The next commits will address
those.
2020-03-22 23:34:19 +02:00
wm4 37f441d61b lua: restore recent end-file event, and deprecate it
Lua changed behavior for this specific event. I considered the change
minor enough that it would not need to go through deprecation, but
someone hit it immediately and ask on the -dev channel.

It's probably better to restore the behavior. But mark it as deprecated,
since it's problematic (mismatch with the C API). Unfortunately, no
automatic warning is possible. (Or maybe it is, by playing sophisticated
Lua tricks such as setting a metatable and overriding indexing, but
let's not.)
2020-03-22 19:42:59 +01:00
Avi Halachmi (:avih) ee70e8ce50 js: make wait_event autofree
The VM could throw at pushnode and before mpv_free_node_contents, which
would have resulted in leaked content.

Now this case is handled without leaks.

Note: the lua code still leaks on such case, but mp_lua_PITA doesn't
have destructors like the JS autofree has, which, specifically here,
can do mpv_free_node_contents. So TODO: enhance the lua PITA code to
behave more similar to the JS autofree.
2020-03-22 00:53:30 +02:00
Avi Halachmi (:avih) c4cc48c83d js: use unified events (match 218d6643, 8a58a699) 2020-03-21 23:35:51 +02:00
wm4 8a58a69930 lua: simplify further
As suggested by avih. Obviously this was unnecessarily convoluted.
2020-03-21 22:17:05 +01:00
wm4 d375cc304a client API, lua: unify event code further
Move some parts that can be generic to the client API code. It turns out
lua.c doesn't need anything special.

This adds the "id" field. I think this was actually missing from the
JSON IPC code (i.e. it's a very recent regression that is fixed with
this commit).
2020-03-21 22:09:07 +01:00
wm4 0fbe7f9e54 command: fix accidental stack dumping 2020-03-21 22:05:50 +01:00
wm4 218d6643e9 client API, lua, ipc: unify event struct return
Both Lua and the JSON IPC code need to convert the mpv_event struct (and
everything it points to) to Lua tables or JSON.

I was getting sick of having to make the same changes to Lua and IPC. Do
what has been done everywhere else, and let the core handle this by
going through mpv_node (which is supposed to serve both Lua tables and
JSON, and potentially other scripting language backends). Expose it as
new libmpv API function.

The new API is still a bit "rough" and support for other event types
might be added in the future.

This silently adds support for the playlist_entry_id fields to both Lua
and JSON IPC.

There is a small API change for Lua; I don't think this matters, so I
didn't care about compatibility. The new code in client.c is mashed up
from the Lua and the IPC code. The manpage additions are moved from the
Lua docs, and made slightly more "general".

Some danger for unintended regressions both in Lua and IPC. Also damn
these node functions suck, expect crashes due to UB.

Not sure why this became more code instead of less compared to before
(according to the diff stat), even though some code duplication across
Lua and IPC was removed. Software development sucks.
2020-03-21 19:33:48 +01:00
wm4 7e885a3bc3 client API: add a playlist entry unique ID
This should make dealing with some async. things easier.

It's intentionally not a globally unique ID.
2020-03-21 19:33:03 +01:00
wm4 956a5d9ac6 player: add potentially forgotten property change trigger
Unfortunately, merely changing the playlist current position affects the
flags returned by the "playlist" property, so the entirely thing needs
to be marked as changed. Seems to be a design mistake.
2020-03-21 19:32:50 +01:00
wm4 e9e93b4dbe player: add a number of new playlist contol commands/properties
Should give a good deal more explicit control and insight over the
player state.

Some feel a bit pointless, and/or expose internal weirdness. However,
it's not like the existing weirdness didn't exist before, or can be made
go away. (In part, the weirdness is because certain in-between states
are visible. Hiding them would make things simpler, but less flexible.)

Maybe this actually gives users a better idea how the API _should_ look
like, too.

On a side note, this tries to really guarantee that mpctx->playing is
set between playback start/end. For that, the loadfile.c changes assume
that mpctx->playing is set (guaranteed by code above the change), and
that playing->filename is set (probably could never be false; was broken
before and actually would have crashed if that could ever happen; in any
case, also add an assert to playlist.c for this).

playlist_entry_to_index() now tolerates playlist_entrys that are not
part of the playlist. This is also needed for mpctx->playing.
2020-03-21 19:32:50 +01:00
wm4 68d9d11ddf player: playlist-pos now use -1 for "no entry selected"
It's odd that this state is observable, but is made implicit by making
the property unavailable. It's also odd that an API user cannot directly
put the player into such a state.

Just allow reading/writing -1 (or in fact, any out of bounds index) for
this case.

I'm also refraining from using OPT_CHOICE for the "no selection" case,
because although that would be cleaner in theory, it would cause only
problems to API users due to the more complex property type (worse is
better).

One reason for not restricting the integer range on the input property
anymore is that if there are no playlist elements, the range would
contain only 1 integer, which cannot be represented anymore since the
recent m_option change. This was actually broken with 1 element
playlists before (and still is, with the constricted type for OSD and
the add/cycle commands). Doesn't matter too much.
2020-03-21 19:32:50 +01:00
wm4 9815887435 osc: avoid using a deprecated event
The new code is pretty much equivalent.
2020-03-21 19:32:50 +01:00