2015-04-03 15:22:32 +00:00
|
|
|
-- Display some stats.
|
|
|
|
--
|
2016-07-08 08:53:02 +00:00
|
|
|
-- Please consult the readme for information about usage and configuration:
|
|
|
|
-- https://github.com/Argon-/mpv-stats
|
2015-04-03 15:22:32 +00:00
|
|
|
--
|
|
|
|
-- Please note: not every property is always available and therefore not always
|
|
|
|
-- visible.
|
|
|
|
|
2016-07-12 15:46:40 +00:00
|
|
|
local mp = require 'mp'
|
2015-05-29 14:04:57 +00:00
|
|
|
local options = require 'mp.options'
|
2017-12-26 16:54:03 +00:00
|
|
|
local utils = require 'mp.utils'
|
2015-04-03 15:22:32 +00:00
|
|
|
|
2015-05-29 14:04:57 +00:00
|
|
|
-- Options
|
2015-04-03 15:22:32 +00:00
|
|
|
local o = {
|
2016-05-17 20:23:11 +00:00
|
|
|
-- Default key bindings
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
key_page_1 = "1",
|
|
|
|
key_page_2 = "2",
|
|
|
|
key_page_3 = "3",
|
2021-07-16 08:17:50 +00:00
|
|
|
key_page_4 = "4",
|
2021-07-16 07:33:46 +00:00
|
|
|
key_page_0 = "0",
|
2020-04-10 22:20:02 +00:00
|
|
|
-- For pages which support scrolling
|
|
|
|
key_scroll_up = "UP",
|
|
|
|
key_scroll_down = "DOWN",
|
|
|
|
scroll_lines = 1,
|
2016-05-17 20:23:11 +00:00
|
|
|
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
duration = 4,
|
2016-07-12 15:46:40 +00:00
|
|
|
redraw_delay = 1, -- acts as duration in the toggling case
|
2016-05-17 20:23:11 +00:00
|
|
|
ass_formatting = true,
|
2017-09-23 15:54:40 +00:00
|
|
|
persistent_overlay = false, -- whether the stats can be overwritten by other output
|
2017-06-30 19:46:16 +00:00
|
|
|
print_perfdata_passes = false, -- when true, print the full information about all passes
|
2017-07-25 13:37:09 +00:00
|
|
|
filter_params_max_length = 100, -- a filter list longer than this many characters will be shown one filter per line instead
|
2015-05-22 19:41:55 +00:00
|
|
|
debug = false,
|
2015-05-29 14:04:57 +00:00
|
|
|
|
2016-07-08 08:53:02 +00:00
|
|
|
-- Graph options and style
|
2016-09-12 00:30:09 +00:00
|
|
|
plot_perfdata = true,
|
|
|
|
plot_vsync_ratio = true,
|
|
|
|
plot_vsync_jitter = true,
|
2023-08-30 13:09:51 +00:00
|
|
|
plot_tonemapping_lut = true, -- also enable tone-mapping-visualize
|
2016-07-12 15:46:40 +00:00
|
|
|
skip_frames = 5,
|
|
|
|
global_max = true,
|
2016-09-12 00:30:09 +00:00
|
|
|
flush_graph_data = true, -- clear data buffers when toggling
|
2016-06-10 22:04:14 +00:00
|
|
|
plot_bg_border_color = "0000FF",
|
|
|
|
plot_bg_color = "262626",
|
|
|
|
plot_color = "FFFFFF",
|
|
|
|
|
2015-05-29 14:04:57 +00:00
|
|
|
-- Text style
|
2023-07-09 09:05:23 +00:00
|
|
|
font = "sans-serif",
|
2018-09-08 21:13:35 +00:00
|
|
|
font_mono = "monospace", -- monospaced digits are sufficient
|
2017-07-27 19:26:54 +00:00
|
|
|
font_size = 8,
|
2015-04-03 15:22:32 +00:00
|
|
|
font_color = "FFFFFF",
|
2016-07-12 15:46:40 +00:00
|
|
|
border_size = 0.8,
|
2015-04-03 15:22:32 +00:00
|
|
|
border_color = "262626",
|
|
|
|
shadow_x_offset = 0.0,
|
|
|
|
shadow_y_offset = 0.0,
|
|
|
|
shadow_color = "000000",
|
|
|
|
alpha = "11",
|
2015-04-28 00:13:27 +00:00
|
|
|
|
|
|
|
-- Custom header for ASS tags to style the text output.
|
|
|
|
-- Specifying this will ignore the text style values above and just
|
|
|
|
-- use this string instead.
|
|
|
|
custom_header = "",
|
|
|
|
|
2015-05-29 14:04:57 +00:00
|
|
|
-- Text formatting
|
|
|
|
-- With ASS
|
2017-07-04 22:31:44 +00:00
|
|
|
ass_nl = "\\N",
|
|
|
|
ass_indent = "\\h\\h\\h\\h\\h",
|
|
|
|
ass_prefix_sep = "\\h\\h",
|
|
|
|
ass_b1 = "{\\b1}",
|
|
|
|
ass_b0 = "{\\b0}",
|
2017-07-25 13:37:09 +00:00
|
|
|
ass_it1 = "{\\i1}",
|
|
|
|
ass_it0 = "{\\i0}",
|
2015-05-29 14:04:57 +00:00
|
|
|
-- Without ASS
|
2015-04-28 00:13:27 +00:00
|
|
|
no_ass_nl = "\n",
|
2015-10-14 07:53:01 +00:00
|
|
|
no_ass_indent = "\t",
|
|
|
|
no_ass_prefix_sep = " ",
|
2015-07-21 19:53:23 +00:00
|
|
|
no_ass_b1 = "\027[1m",
|
|
|
|
no_ass_b0 = "\027[0m",
|
2017-07-25 13:37:09 +00:00
|
|
|
no_ass_it1 = "\027[3m",
|
|
|
|
no_ass_it0 = "\027[0m",
|
stats.lua: page 4 (keys): support help-like terminal printout
While --input-test is useful, and so is page 4 of stats, until now
there was no way to simply print the list in a help-like fashion.
This commit adds such printout, invoked by the script opt
stats-bindlist=yes, which uses the existing page 4 code. This prints
the list on startup and quits immediately - like any help page.
It's awkward to invoke compared to other help pages, and it does
require the stats page to be enabled (it is by default), however
it is a script-generated output, and currently there's no other
method to print a help page generated by a script.
The printout itself is performed using lua's io.write. While reliable,
it's not the standard way for mpv to print to the terminal.
Other possible printout methods are mp.msg.info - which also prints
"[stats]" prefix on each line (ugly), or forcing term-osd and setting
an osd-message which mpv will then print at the terminal - however
that's printed to stderr, and could also be subject to timing concerns
since we quit right afterwards.
In the future we can consider changing/integrating the invocation so
that mpv itself could print a help page generated by a script, thus
solving both the awkward invocation and printout-method issues.
2021-07-16 09:06:20 +00:00
|
|
|
|
|
|
|
bindlist = "no", -- print page 4 to the terminal on startup and quit mpv
|
2015-04-03 15:22:32 +00:00
|
|
|
}
|
2015-05-29 14:04:57 +00:00
|
|
|
options.read_options(o)
|
2015-04-03 15:22:32 +00:00
|
|
|
|
2016-07-08 08:53:02 +00:00
|
|
|
local format = string.format
|
2016-09-12 00:30:09 +00:00
|
|
|
local max = math.max
|
2017-07-24 20:46:01 +00:00
|
|
|
local min = math.min
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
2016-07-19 07:11:51 +00:00
|
|
|
-- Function used to record performance data
|
2016-07-08 08:53:02 +00:00
|
|
|
local recorder = nil
|
2017-09-23 15:54:40 +00:00
|
|
|
-- Timer used for redrawing (toggling) and clearing the screen (oneshot)
|
|
|
|
local display_timer = nil
|
2019-06-22 22:30:56 +00:00
|
|
|
-- Timer used to update cache stats.
|
|
|
|
local cache_recorder_timer = nil
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
-- Current page and <page key>:<page function> mappings
|
|
|
|
local curr_page = o.key_page_1
|
|
|
|
local pages = {}
|
2020-04-10 22:20:02 +00:00
|
|
|
local scroll_bound = false
|
2023-08-30 13:09:51 +00:00
|
|
|
local tm_viz_prev = nil
|
2016-07-19 07:11:51 +00:00
|
|
|
-- Save these sequences locally as we'll need them a lot
|
|
|
|
local ass_start = mp.get_property_osd("osd-ass-cc/0")
|
|
|
|
local ass_stop = mp.get_property_osd("osd-ass-cc/1")
|
2016-09-12 00:30:09 +00:00
|
|
|
-- Ring buffers for the values used to construct a graph.
|
|
|
|
-- .pos denotes the current position, .len the buffer length
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
-- .max is the max value in the corresponding buffer
|
2020-04-09 13:03:17 +00:00
|
|
|
local vsratio_buf, vsjitter_buf
|
2016-09-12 00:30:09 +00:00
|
|
|
local function init_buffers()
|
|
|
|
vsratio_buf = {0, pos = 1, len = 50, max = 0}
|
|
|
|
vsjitter_buf = {0, pos = 1, len = 50, max = 0}
|
|
|
|
end
|
2020-04-09 13:03:17 +00:00
|
|
|
local cache_ahead_buf, cache_speed_buf
|
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-08 22:27:54 +00:00
|
|
|
local perf_buffers = {}
|
2017-06-16 10:38:41 +00:00
|
|
|
-- Save all properties known to this version of mpv
|
|
|
|
local property_list = {}
|
|
|
|
for p in string.gmatch(mp.get_property("property-list"), "([^,]+)") do property_list[p] = true end
|
|
|
|
-- Mapping of properties to their deprecated names
|
|
|
|
local property_aliases = {
|
|
|
|
["decoder-frame-drop-count"] = "drop-frame-count",
|
|
|
|
["frame-drop-count"] = "vo-drop-frame-count",
|
|
|
|
["container-fps"] = "fps",
|
|
|
|
}
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
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-08 22:27:54 +00:00
|
|
|
local function graph_add_value(graph, value)
|
|
|
|
graph.pos = (graph.pos % graph.len) + 1
|
|
|
|
graph[graph.pos] = value
|
|
|
|
graph.max = max(graph.max, value)
|
|
|
|
end
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
2017-06-16 10:38:41 +00:00
|
|
|
-- Return deprecated name for the given property
|
|
|
|
local function compat(p)
|
|
|
|
while not property_list[p] and property_aliases[p] do
|
|
|
|
p = property_aliases[p]
|
|
|
|
end
|
|
|
|
return p
|
|
|
|
end
|
|
|
|
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
-- "\\<U+2060>" in UTF-8 (U+2060 is WORD-JOINER)
|
|
|
|
local ESC_BACKSLASH = "\\" .. string.char(0xE2, 0x81, 0xA0)
|
2015-04-03 15:22:32 +00:00
|
|
|
|
2016-07-12 17:19:34 +00:00
|
|
|
local function no_ASS(t)
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
if not o.use_ass then
|
|
|
|
return t
|
|
|
|
elseif not o.persistent_overlay then
|
|
|
|
-- mp.osd_message supports ass-escape using osd-ass-cc/{0|1}
|
|
|
|
return ass_stop .. t .. ass_start
|
|
|
|
else
|
|
|
|
-- mp.set_osd_ass doesn't support ass-escape. roll our own.
|
|
|
|
-- similar to mpv's sub/osd_libass.c:mangle_ass(...), excluding
|
|
|
|
-- space after newlines because no_ASS is not used with multi-line.
|
2022-04-25 11:27:18 +00:00
|
|
|
-- space at the beginning is replaced with "\\h" because it matters
|
|
|
|
-- at the beginning of a line, and we can't know where our output
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
-- ends up. no issue if it ends up at the middle of a line.
|
|
|
|
return tostring(t)
|
|
|
|
:gsub("\\", ESC_BACKSLASH)
|
|
|
|
:gsub("{", "\\{")
|
|
|
|
:gsub("^ ", "\\h")
|
|
|
|
end
|
2015-04-03 15:22:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-07-12 17:19:34 +00:00
|
|
|
local function b(t)
|
|
|
|
return o.b1 .. t .. o.b0
|
2016-06-10 22:04:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-07-25 13:37:09 +00:00
|
|
|
local function it(t)
|
|
|
|
return o.it1 .. t .. o.it0
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-07-12 17:19:34 +00:00
|
|
|
local function text_style()
|
2017-07-04 22:31:44 +00:00
|
|
|
if not o.use_ass then
|
2016-06-10 22:04:14 +00:00
|
|
|
return ""
|
2015-04-27 17:10:08 +00:00
|
|
|
end
|
2015-04-03 15:22:32 +00:00
|
|
|
if o.custom_header and o.custom_header ~= "" then
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
return o.custom_header
|
2015-04-03 15:22:32 +00:00
|
|
|
else
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
return format("{\\r}{\\an7}{\\fs%d}{\\fn%s}{\\bord%f}{\\3c&H%s&}" ..
|
2017-09-23 15:54:40 +00:00
|
|
|
"{\\1c&H%s&}{\\alpha&H%s&}{\\xshad%f}{\\yshad%f}{\\4c&H%s&}",
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
o.font_size, o.font, o.border_size,
|
2017-09-23 15:54:40 +00:00
|
|
|
o.border_color, o.font_color, o.alpha, o.shadow_x_offset,
|
|
|
|
o.shadow_y_offset, o.shadow_color)
|
2015-04-03 15:22:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-07-12 17:19:34 +00:00
|
|
|
local function has_vo_window()
|
|
|
|
return mp.get_property("vo-configured") == "yes"
|
|
|
|
end
|
2015-04-03 15:22:32 +00:00
|
|
|
|
2015-07-05 19:24:36 +00:00
|
|
|
|
2016-09-11 09:34:11 +00:00
|
|
|
-- Generate a graph from the given values.
|
|
|
|
-- Returns an ASS formatted vector drawing as string.
|
|
|
|
--
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
-- values: Array/table of numbers representing the data. Used like a ring buffer
|
2016-09-11 09:34:11 +00:00
|
|
|
-- it will get iterated backwards `len` times starting at position `i`.
|
|
|
|
-- i : Index of the latest data value in `values`.
|
|
|
|
-- len : The length/amount of numbers in `values`.
|
|
|
|
-- v_max : The maximum number in `values`. It is used to scale all data
|
|
|
|
-- values to a range of 0 to `v_max`.
|
2017-06-30 22:31:05 +00:00
|
|
|
-- v_avg : The average number in `values`. It is used to try and center graphs
|
|
|
|
-- if possible. May be left as nil
|
2016-09-11 09:34:11 +00:00
|
|
|
-- scale : A value that will be multiplied with all data values.
|
2017-06-30 19:46:16 +00:00
|
|
|
-- x_tics: Horizontal width multiplier for the steps
|
2017-06-30 22:31:05 +00:00
|
|
|
local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics)
|
2016-09-12 00:30:09 +00:00
|
|
|
-- Check if at least one value exists
|
|
|
|
if not values[i] then
|
2016-07-08 08:53:02 +00:00
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
2016-09-11 01:34:44 +00:00
|
|
|
local x_max = (len - 1) * x_tics
|
2016-06-10 22:04:14 +00:00
|
|
|
local y_offset = o.border_size
|
2016-07-12 15:46:40 +00:00
|
|
|
local y_max = o.font_size * 0.66
|
2016-06-10 22:04:14 +00:00
|
|
|
local x = 0
|
|
|
|
|
stats.lua: graphs: fix bad rendering due to division by 0
This fixes two potential divisions by 0 at generate_graph(...):
- If v_avg is (given and) 0.
- if v_max is 0.
The former doesn't seem to happen in practice because v_avg is only
used at one generate_gpah call, where it's apparently not 0.
The latter triggers if all the graph values are 0 (hence v_max is
also 0).
The implication of these divisions by 0 is an invalid y-value which
ends up at the ASS coordinates string for the graph inner content.
On linux the value ends as "nan" (luajit) or "-nan" (lua 5.1/5.2), and
on Windows it's "nan" (luajit) or "-1.#IND00" (lua 5.1/5.2), maybe due
to msvcrt's snprintf.
All these strings are wrong as ASS numbers, but due to luck in how
libass parses the coordinates, "nan" and "-nan" result in empty graph
(which looks OK for "all values are 0"), while "-1.#IND00" is parsed
as -1, which breaks the graph rendering (affects other graphs too).
One example of "all values are 0" is at page 0 (internal performance
graphs) on Windows - because the cpu metrics don't work.
So this fixes at least page 0 on Windows with lua 5.1/5.2.
While at it, move the scale calculations to one place, which now
avoids division by 0, instead of duplicating this calculation.
In the future, we can consider improving the generate_graph API:
- It needs one peak value, but takes 3 (v_max, v_avg, scale) which
are meshed into one final value.
- v_avg is only used in 1 of 6 call sites, but at the middle of the
arguments, so all other call sites need to pass explicit "nil".
- "scale" is arbitrary and used to leave some space at the top of the
graph. 5 places use 0.8, one uses 0.9. Could probably be unified.
2022-02-21 11:16:30 +00:00
|
|
|
if v_max > 0 then
|
|
|
|
-- try and center the graph if possible, but avoid going above `scale`
|
|
|
|
if v_avg and v_avg > 0 then
|
|
|
|
scale = min(scale, v_max / (2 * v_avg))
|
|
|
|
end
|
|
|
|
scale = scale * y_max / v_max
|
|
|
|
end -- else if v_max==0 then all values are 0 and scale doesn't matter
|
2017-06-30 22:31:05 +00:00
|
|
|
|
stats.lua: graphs: fix bad rendering due to division by 0
This fixes two potential divisions by 0 at generate_graph(...):
- If v_avg is (given and) 0.
- if v_max is 0.
The former doesn't seem to happen in practice because v_avg is only
used at one generate_gpah call, where it's apparently not 0.
The latter triggers if all the graph values are 0 (hence v_max is
also 0).
The implication of these divisions by 0 is an invalid y-value which
ends up at the ASS coordinates string for the graph inner content.
On linux the value ends as "nan" (luajit) or "-nan" (lua 5.1/5.2), and
on Windows it's "nan" (luajit) or "-1.#IND00" (lua 5.1/5.2), maybe due
to msvcrt's snprintf.
All these strings are wrong as ASS numbers, but due to luck in how
libass parses the coordinates, "nan" and "-nan" result in empty graph
(which looks OK for "all values are 0"), while "-1.#IND00" is parsed
as -1, which breaks the graph rendering (affects other graphs too).
One example of "all values are 0" is at page 0 (internal performance
graphs) on Windows - because the cpu metrics don't work.
So this fixes at least page 0 on Windows with lua 5.1/5.2.
While at it, move the scale calculations to one place, which now
avoids division by 0, instead of duplicating this calculation.
In the future, we can consider improving the generate_graph API:
- It needs one peak value, but takes 3 (v_max, v_avg, scale) which
are meshed into one final value.
- v_avg is only used in 1 of 6 call sites, but at the middle of the
arguments, so all other call sites need to pass explicit "nil".
- "scale" is arbitrary and used to leave some space at the top of the
graph. 5 places use 0.8, one uses 0.9. Could probably be unified.
2022-02-21 11:16:30 +00:00
|
|
|
local s = {format("m 0 0 n %f %f l ", x, y_max - scale * values[i])}
|
2016-09-11 01:34:44 +00:00
|
|
|
i = ((i - 2) % len) + 1
|
2016-06-10 22:04:14 +00:00
|
|
|
|
2016-09-11 01:34:44 +00:00
|
|
|
for p = 1, len - 1 do
|
2016-06-10 22:04:14 +00:00
|
|
|
if values[i] then
|
|
|
|
x = x - x_tics
|
stats.lua: graphs: fix bad rendering due to division by 0
This fixes two potential divisions by 0 at generate_graph(...):
- If v_avg is (given and) 0.
- if v_max is 0.
The former doesn't seem to happen in practice because v_avg is only
used at one generate_gpah call, where it's apparently not 0.
The latter triggers if all the graph values are 0 (hence v_max is
also 0).
The implication of these divisions by 0 is an invalid y-value which
ends up at the ASS coordinates string for the graph inner content.
On linux the value ends as "nan" (luajit) or "-nan" (lua 5.1/5.2), and
on Windows it's "nan" (luajit) or "-1.#IND00" (lua 5.1/5.2), maybe due
to msvcrt's snprintf.
All these strings are wrong as ASS numbers, but due to luck in how
libass parses the coordinates, "nan" and "-nan" result in empty graph
(which looks OK for "all values are 0"), while "-1.#IND00" is parsed
as -1, which breaks the graph rendering (affects other graphs too).
One example of "all values are 0" is at page 0 (internal performance
graphs) on Windows - because the cpu metrics don't work.
So this fixes at least page 0 on Windows with lua 5.1/5.2.
While at it, move the scale calculations to one place, which now
avoids division by 0, instead of duplicating this calculation.
In the future, we can consider improving the generate_graph API:
- It needs one peak value, but takes 3 (v_max, v_avg, scale) which
are meshed into one final value.
- v_avg is only used in 1 of 6 call sites, but at the middle of the
arguments, so all other call sites need to pass explicit "nil".
- "scale" is arbitrary and used to leave some space at the top of the
graph. 5 places use 0.8, one uses 0.9. Could probably be unified.
2022-02-21 11:16:30 +00:00
|
|
|
s[#s+1] = format("%f %f ", x, y_max - scale * values[i])
|
2016-06-10 22:04:14 +00:00
|
|
|
end
|
2016-09-11 01:34:44 +00:00
|
|
|
i = ((i - 2) % len) + 1
|
2016-06-10 22:04:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
s[#s+1] = format("%f %f %f %f", x, y_max, 0, y_max)
|
|
|
|
|
2016-07-08 08:53:02 +00:00
|
|
|
local bg_box = format("{\\bord0.5}{\\3c&H%s&}{\\1c&H%s&}m 0 %f l %f %f %f 0 0 0",
|
|
|
|
o.plot_bg_border_color, o.plot_bg_color, y_max, x_max, y_max, x_max)
|
2017-07-10 21:12:03 +00:00
|
|
|
return format("%s{\\r}{\\pbo%f}{\\shad0}{\\alpha&H00}{\\p1}%s{\\p0}{\\bord0}{\\1c&H%s}{\\p1}%s{\\p0}%s",
|
2016-07-13 08:11:18 +00:00
|
|
|
o.prefix_sep, y_offset, bg_box, o.plot_color, table.concat(s), text_style())
|
2016-07-08 08:53:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-12-26 16:54:03 +00:00
|
|
|
local function append(s, str, attr)
|
2018-03-24 21:36:01 +00:00
|
|
|
if not str then
|
|
|
|
return false
|
|
|
|
end
|
2017-12-26 16:54:03 +00:00
|
|
|
attr.prefix_sep = attr.prefix_sep or o.prefix_sep
|
|
|
|
attr.indent = attr.indent or o.indent
|
|
|
|
attr.nl = attr.nl or o.nl
|
|
|
|
attr.suffix = attr.suffix or ""
|
|
|
|
attr.prefix = attr.prefix or ""
|
|
|
|
attr.no_prefix_markup = attr.no_prefix_markup or false
|
|
|
|
attr.prefix = attr.no_prefix_markup and attr.prefix or b(attr.prefix)
|
|
|
|
s[#s+1] = format("%s%s%s%s%s%s", attr.nl, attr.indent,
|
|
|
|
attr.prefix, attr.prefix_sep, no_ASS(str), attr.suffix)
|
2018-03-24 21:36:01 +00:00
|
|
|
return true
|
2017-12-26 16:54:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-09-12 00:30:09 +00:00
|
|
|
-- Format and append a property.
|
|
|
|
-- A property whose value is either `nil` or empty (hereafter called "invalid")
|
|
|
|
-- is skipped and not appended.
|
|
|
|
-- Returns `false` in case nothing was appended, otherwise `true`.
|
|
|
|
--
|
|
|
|
-- s : Table containing strings.
|
|
|
|
-- prop : The property to query and format (based on its OSD representation).
|
|
|
|
-- attr : Optional table to overwrite certain (formatting) attributes for
|
|
|
|
-- this property.
|
|
|
|
-- exclude: Optional table containing keys which are considered invalid values
|
|
|
|
-- for this property. Specifying this will replace empty string as
|
|
|
|
-- default invalid value (nil is always invalid).
|
|
|
|
local function append_property(s, prop, attr, excluded)
|
|
|
|
excluded = excluded or {[""] = true}
|
|
|
|
local ret = mp.get_property_osd(prop)
|
|
|
|
if not ret or excluded[ret] then
|
|
|
|
if o.debug then
|
|
|
|
print("No value for property: " .. prop)
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
2018-03-24 21:36:01 +00:00
|
|
|
return append(s, ret, attr)
|
2016-09-12 00:30:09 +00:00
|
|
|
end
|
|
|
|
|
2022-02-22 23:50:47 +00:00
|
|
|
local function sorted_keys(t, comp_fn)
|
|
|
|
local keys = {}
|
|
|
|
for k,_ in pairs(t) do
|
|
|
|
keys[#keys+1] = k
|
|
|
|
end
|
|
|
|
table.sort(keys, comp_fn)
|
|
|
|
return keys
|
|
|
|
end
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
2017-07-24 21:10:20 +00:00
|
|
|
local function append_perfdata(s, dedicated_page)
|
2017-06-30 19:46:16 +00:00
|
|
|
local vo_p = mp.get_property_native("vo-passes")
|
2016-07-08 08:53:02 +00:00
|
|
|
if not vo_p then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-07-27 18:28:42 +00:00
|
|
|
local ds = mp.get_property_bool("display-sync-active", false)
|
2016-12-19 12:34:21 +00:00
|
|
|
local target_fps = ds and mp.get_property_number("display-fps", 0)
|
2017-06-16 10:38:41 +00:00
|
|
|
or mp.get_property_number(compat("container-fps"), 0)
|
2017-06-30 19:46:16 +00:00
|
|
|
if target_fps > 0 then target_fps = 1 / target_fps * 1e9 end
|
2016-06-10 22:04:14 +00:00
|
|
|
|
2017-07-24 20:46:01 +00:00
|
|
|
-- Sums of all last/avg/peak values
|
2017-06-30 19:46:16 +00:00
|
|
|
local last_s, avg_s, peak_s = {}, {}, {}
|
|
|
|
for frame, data in pairs(vo_p) do
|
|
|
|
last_s[frame], avg_s[frame], peak_s[frame] = 0, 0, 0
|
|
|
|
for _, pass in ipairs(data) do
|
|
|
|
last_s[frame] = last_s[frame] + pass["last"]
|
|
|
|
avg_s[frame] = avg_s[frame] + pass["avg"]
|
|
|
|
peak_s[frame] = peak_s[frame] + pass["peak"]
|
|
|
|
end
|
|
|
|
end
|
2016-06-10 22:04:14 +00:00
|
|
|
|
2017-09-16 23:21:44 +00:00
|
|
|
-- Pretty print measured time
|
|
|
|
local function pp(i)
|
2017-06-30 19:46:16 +00:00
|
|
|
-- rescale to microseconds for a saner display
|
2017-09-16 23:21:44 +00:00
|
|
|
return format("%05d", i / 1000)
|
2016-07-08 08:53:02 +00:00
|
|
|
end
|
|
|
|
|
2017-07-24 20:46:01 +00:00
|
|
|
-- Format n/m with a font weight based on the ratio
|
|
|
|
local function p(n, m)
|
|
|
|
local i = 0
|
|
|
|
if m > 0 then
|
|
|
|
i = tonumber(n) / m
|
|
|
|
end
|
|
|
|
-- Calculate font weight. 100 is minimum, 400 is normal, 700 bold, 900 is max
|
|
|
|
local w = (700 * math.sqrt(i)) + 200
|
2017-07-24 21:40:09 +00:00
|
|
|
return format("{\\b%d}%02d%%{\\b0}", w, i * 100)
|
2017-07-24 20:46:01 +00:00
|
|
|
end
|
|
|
|
|
2020-05-17 11:55:38 +00:00
|
|
|
-- ensure that the fixed title is one element and every scrollable line is
|
|
|
|
-- also one single element.
|
2023-08-25 20:24:11 +00:00
|
|
|
s[#s+1] = format("%s%s%s%s{\\fs%s}%s%s{\\fs%s}",
|
2017-09-23 15:54:40 +00:00
|
|
|
dedicated_page and "" or o.nl, dedicated_page and "" or o.indent,
|
2017-07-28 07:30:24 +00:00
|
|
|
b("Frame Timings:"), o.prefix_sep, o.font_size * 0.66,
|
2023-08-25 20:24:11 +00:00
|
|
|
"(last/average/peak μs)",
|
|
|
|
dedicated_page and " (hint: scroll with ↑↓)" or "", o.font_size)
|
2016-07-12 15:46:40 +00:00
|
|
|
|
2022-02-22 23:50:47 +00:00
|
|
|
for _,frame in ipairs(sorted_keys(vo_p)) do -- ensure fixed display order
|
|
|
|
local data = vo_p[frame]
|
2017-07-24 21:10:20 +00:00
|
|
|
local f = "%s%s%s{\\fn%s}%s / %s / %s %s%s{\\fn%s}%s%s%s"
|
2016-07-12 15:46:40 +00:00
|
|
|
|
2017-07-24 21:10:20 +00:00
|
|
|
if dedicated_page then
|
|
|
|
s[#s+1] = format("%s%s%s:", o.nl, o.indent,
|
2017-06-30 19:46:16 +00:00
|
|
|
b(frame:gsub("^%l", string.upper)))
|
2016-07-12 15:46:40 +00:00
|
|
|
|
2017-06-30 19:46:16 +00:00
|
|
|
for _, pass in ipairs(data) do
|
2017-07-24 21:10:20 +00:00
|
|
|
s[#s+1] = format(f, o.nl, o.indent, o.indent,
|
2017-09-16 23:21:44 +00:00
|
|
|
o.font_mono, pp(pass["last"]),
|
|
|
|
pp(pass["avg"]), pp(pass["peak"]),
|
2017-07-24 20:46:01 +00:00
|
|
|
o.prefix_sep .. o.prefix_sep, p(pass["last"], last_s[frame]),
|
2017-07-24 21:10:20 +00:00
|
|
|
o.font, o.prefix_sep, o.prefix_sep, pass["desc"])
|
2016-07-12 15:46:40 +00:00
|
|
|
|
2017-07-04 22:31:44 +00:00
|
|
|
if o.plot_perfdata and o.use_ass then
|
2020-05-17 11:55:38 +00:00
|
|
|
-- use the same line that was already started for this iteration
|
|
|
|
s[#s] = s[#s] ..
|
|
|
|
generate_graph(pass["samples"], pass["count"],
|
2017-06-30 19:46:16 +00:00
|
|
|
pass["count"], pass["peak"],
|
2017-06-30 22:31:05 +00:00
|
|
|
pass["avg"], 0.9, 0.25)
|
2017-06-30 19:46:16 +00:00
|
|
|
end
|
|
|
|
end
|
2016-07-12 15:46:40 +00:00
|
|
|
|
2017-07-24 20:46:01 +00:00
|
|
|
-- Print sum of timing values as "Total"
|
2017-07-24 21:10:20 +00:00
|
|
|
s[#s+1] = format(f, o.nl, o.indent, o.indent,
|
2017-09-16 23:21:44 +00:00
|
|
|
o.font_mono, pp(last_s[frame]),
|
|
|
|
pp(avg_s[frame]), pp(peak_s[frame]), "", "", o.font,
|
2017-07-24 21:10:20 +00:00
|
|
|
o.prefix_sep, o.prefix_sep, b("Total"))
|
2017-06-30 19:46:16 +00:00
|
|
|
else
|
|
|
|
-- for the simplified view, we just print the sum of each pass
|
2017-07-24 21:10:20 +00:00
|
|
|
s[#s+1] = format(f, o.nl, o.indent, o.indent, o.font_mono,
|
2017-09-16 23:21:44 +00:00
|
|
|
pp(last_s[frame]), pp(avg_s[frame]), pp(peak_s[frame]),
|
2017-07-24 21:10:20 +00:00
|
|
|
"", "", o.font, o.prefix_sep, o.prefix_sep,
|
2017-07-24 20:46:01 +00:00
|
|
|
frame:gsub("^%l", string.upper))
|
2017-06-30 19:46:16 +00:00
|
|
|
end
|
2016-07-13 08:11:18 +00:00
|
|
|
end
|
2016-06-10 22:04:14 +00:00
|
|
|
end
|
|
|
|
|
2021-07-16 08:17:50 +00:00
|
|
|
local function ellipsis(s, maxlen)
|
|
|
|
if not maxlen or s:len() <= maxlen then return s end
|
|
|
|
return s:sub(1, maxlen - 3) .. "..."
|
|
|
|
end
|
|
|
|
|
|
|
|
-- command prefix tokens to strip - includes generic property commands
|
|
|
|
local cmd_prefixes = {
|
|
|
|
osd_auto=1, no_osd=1, osd_bar=1, osd_msg=1, osd_msg_bar=1, raw=1, sync=1,
|
|
|
|
async=1, expand_properties=1, repeatable=1, set=1, add=1, multiply=1,
|
|
|
|
toggle=1, cycle=1, cycle_values=1, ["!reverse"]=1, change_list=1,
|
|
|
|
}
|
|
|
|
-- commands/writable-properties prefix sub-words (followed by -) to strip
|
|
|
|
local name_prefixes = {
|
|
|
|
define=1, delete=1, enable=1, disable=1, dump=1, write=1, drop=1, revert=1,
|
2021-08-06 07:28:31 +00:00
|
|
|
ab=1, hr=1, secondary=1, current=1,
|
2021-07-16 08:17:50 +00:00
|
|
|
}
|
|
|
|
-- extract a command "subject" from a command string, by removing all
|
|
|
|
-- generic prefix tokens and then returning the first interesting sub-word
|
|
|
|
-- of the next token. For target-script name we also check another token.
|
|
|
|
-- The tokenizer works fine for things we care about - valid mpv commands,
|
|
|
|
-- properties and script names, possibly quoted, white-space[s]-separated.
|
|
|
|
-- It's decent in practice, and worst case is "incorrect" subject.
|
|
|
|
local function cmd_subject(cmd)
|
|
|
|
cmd = cmd:gsub(";.*", ""):gsub("%-", "_") -- only first cmd, s/-/_/
|
2021-07-28 10:43:57 +00:00
|
|
|
local TOKEN = '^%s*["\']?([%w_!]*)' -- captures+ends before (maybe) final "
|
2021-07-16 08:17:50 +00:00
|
|
|
local tok, sname, subw
|
|
|
|
|
2021-07-28 10:43:57 +00:00
|
|
|
repeat tok, cmd = cmd:match(TOKEN .. '["\']?(.*)')
|
2021-07-16 08:17:50 +00:00
|
|
|
until not cmd_prefixes[tok]
|
|
|
|
-- tok is the 1st non-generic command/property name token, cmd is the rest
|
|
|
|
|
|
|
|
sname = tok == "script_message_to" and cmd:match(TOKEN)
|
|
|
|
or tok == "script_binding" and cmd:match(TOKEN .. "/")
|
|
|
|
if sname and sname ~= "" then
|
|
|
|
return "script: " .. sname
|
|
|
|
end
|
|
|
|
|
|
|
|
-- return the first sub-word of tok which is not a useless prefix
|
|
|
|
repeat subw, tok = tok:match("([^_]*)_?(.*)")
|
|
|
|
until tok == "" or not name_prefixes[subw]
|
|
|
|
return subw:len() > 1 and subw or "[unknown]"
|
|
|
|
end
|
|
|
|
|
stats.lua: page 4 (keys): better alignment of non-ascii keys
Previously we assumed the key-name string occupies strlen(name) cells,
now we count codepoints instead.
This improves alignment of non-english key names. Still not perfect
because we don't know if the key name is single or double width, but
wcwidth not available to scripts, notoriously unreliable (depends on
locale, correct and updated tables, etc), and also not always
available (Windows).
Still, better than nothing, and we err by at most one cell - vs up to
three before this commit (4 bytes keyname codepoint).
In the future we could do the alignment using libass tags, however,
this both complicates the ass-output generation, and also not available
when we output for the terminal, so for now only count codepoints.
Also, if the key name was in a right-to-left language, then previously
the name/command were swapped visually. Now we inject a left-to-right
marker before the name to ensure direction. This works also when
harfbuzz is disabled for libass (--sub-ass-shaper=simple).
2021-07-30 06:23:56 +00:00
|
|
|
-- key names are valid UTF-8, ascii7 except maybe the last/only codepoint.
|
|
|
|
-- we count codepoints and ignore wcwidth. no need for grapheme clusters.
|
|
|
|
-- our error for alignment is at most one cell (if last CP is double-width).
|
|
|
|
-- (if k was valid but arbitrary: we'd count all bytes <0x80 or >=0xc0)
|
|
|
|
local function keyname_cells(k)
|
|
|
|
local klen = k:len()
|
|
|
|
if klen > 1 and k:byte(klen) >= 0x80 then -- last/only CP is not ascii7
|
|
|
|
repeat klen = klen-1
|
|
|
|
until klen == 1 or k:byte(klen) >= 0xc0 -- last CP begins at klen
|
|
|
|
end
|
|
|
|
return klen
|
|
|
|
end
|
|
|
|
|
stats.lua: page 4 (keys): support help-like terminal printout
While --input-test is useful, and so is page 4 of stats, until now
there was no way to simply print the list in a help-like fashion.
This commit adds such printout, invoked by the script opt
stats-bindlist=yes, which uses the existing page 4 code. This prints
the list on startup and quits immediately - like any help page.
It's awkward to invoke compared to other help pages, and it does
require the stats page to be enabled (it is by default), however
it is a script-generated output, and currently there's no other
method to print a help page generated by a script.
The printout itself is performed using lua's io.write. While reliable,
it's not the standard way for mpv to print to the terminal.
Other possible printout methods are mp.msg.info - which also prints
"[stats]" prefix on each line (ugly), or forcing term-osd and setting
an osd-message which mpv will then print at the terminal - however
that's printed to stderr, and could also be subject to timing concerns
since we quit right afterwards.
In the future we can consider changing/integrating the invocation so
that mpv itself could print a help page generated by a script, thus
solving both the awkward invocation and printout-method issues.
2021-07-16 09:06:20 +00:00
|
|
|
local function get_kbinfo_lines(width)
|
2023-03-27 20:42:17 +00:00
|
|
|
-- active keys: only highest priority of each key, and not our (stats) keys
|
2021-07-16 08:17:50 +00:00
|
|
|
local bindings = mp.get_property_native("input-bindings", {})
|
|
|
|
local active = {} -- map: key-name -> bind-info
|
|
|
|
for _, bind in pairs(bindings) do
|
|
|
|
if bind.priority >= 0 and (
|
|
|
|
not active[bind.key] or
|
|
|
|
(active[bind.key].is_weak and not bind.is_weak) or
|
|
|
|
(bind.is_weak == active[bind.key].is_weak and
|
|
|
|
bind.priority > active[bind.key].priority)
|
2021-07-19 21:49:03 +00:00
|
|
|
) and not bind.cmd:find("script-binding stats/__forced_", 1, true)
|
2021-07-16 08:17:50 +00:00
|
|
|
then
|
|
|
|
active[bind.key] = bind
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- make an array, find max key len, add sort keys (.subject/.mods[_count])
|
|
|
|
local ordered = {}
|
|
|
|
local kspaces = "" -- as many spaces as the longest key name
|
|
|
|
for _, bind in pairs(active) do
|
|
|
|
bind.subject = cmd_subject(bind.cmd)
|
|
|
|
if bind.subject ~= "ignore" then
|
|
|
|
ordered[#ordered+1] = bind
|
|
|
|
_,_, bind.mods = bind.key:find("(.*)%+.")
|
|
|
|
_, bind.mods_count = bind.key:gsub("%+.", "")
|
|
|
|
if bind.key:len() > kspaces:len() then
|
|
|
|
kspaces = string.rep(" ", bind.key:len())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function align_right(key)
|
stats.lua: page 4 (keys): better alignment of non-ascii keys
Previously we assumed the key-name string occupies strlen(name) cells,
now we count codepoints instead.
This improves alignment of non-english key names. Still not perfect
because we don't know if the key name is single or double width, but
wcwidth not available to scripts, notoriously unreliable (depends on
locale, correct and updated tables, etc), and also not always
available (Windows).
Still, better than nothing, and we err by at most one cell - vs up to
three before this commit (4 bytes keyname codepoint).
In the future we could do the alignment using libass tags, however,
this both complicates the ass-output generation, and also not available
when we output for the terminal, so for now only count codepoints.
Also, if the key name was in a right-to-left language, then previously
the name/command were swapped visually. Now we inject a left-to-right
marker before the name to ensure direction. This works also when
harfbuzz is disabled for libass (--sub-ass-shaper=simple).
2021-07-30 06:23:56 +00:00
|
|
|
return kspaces:sub(keyname_cells(key)) .. key
|
2021-07-16 08:17:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- sort by: subject, mod(ifier)s count, mods, key-len, lowercase-key, key
|
|
|
|
table.sort(ordered, function(a, b)
|
|
|
|
if a.subject ~= b.subject then
|
|
|
|
return a.subject < b.subject
|
|
|
|
elseif a.mods_count ~= b.mods_count then
|
|
|
|
return a.mods_count < b.mods_count
|
|
|
|
elseif a.mods ~= b.mods then
|
|
|
|
return a.mods < b.mods
|
|
|
|
elseif a.key:len() ~= b.key:len() then
|
|
|
|
return a.key:len() < b.key:len()
|
|
|
|
elseif a.key:lower() ~= b.key:lower() then
|
|
|
|
return a.key:lower() < b.key:lower()
|
|
|
|
else
|
|
|
|
return a.key > b.key -- only case differs, lowercase first
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- key/subject pre/post formatting for terminal/ass.
|
|
|
|
-- key/subject alignment uses spaces (with mono font if ass)
|
|
|
|
-- word-wrapping is disabled for ass, or cut at 79 for the terminal
|
2022-05-12 15:12:31 +00:00
|
|
|
local LTR = string.char(0xE2, 0x80, 0x8E) -- U+200E Left To Right mark
|
2021-07-16 08:17:50 +00:00
|
|
|
local term = not o.use_ass
|
stats.lua: page 4 (keys): better alignment of non-ascii keys
Previously we assumed the key-name string occupies strlen(name) cells,
now we count codepoints instead.
This improves alignment of non-english key names. Still not perfect
because we don't know if the key name is single or double width, but
wcwidth not available to scripts, notoriously unreliable (depends on
locale, correct and updated tables, etc), and also not always
available (Windows).
Still, better than nothing, and we err by at most one cell - vs up to
three before this commit (4 bytes keyname codepoint).
In the future we could do the alignment using libass tags, however,
this both complicates the ass-output generation, and also not available
when we output for the terminal, so for now only count codepoints.
Also, if the key name was in a right-to-left language, then previously
the name/command were swapped visually. Now we inject a left-to-right
marker before the name to ensure direction. This works also when
harfbuzz is disabled for libass (--sub-ass-shaper=simple).
2021-07-30 06:23:56 +00:00
|
|
|
local kpre = term and "" or format("{\\q2\\fn%s}%s", o.font_mono, LTR)
|
2021-07-16 08:17:50 +00:00
|
|
|
local kpost = term and " " or format(" {\\fn%s}", o.font)
|
|
|
|
local spre = term and kspaces .. " "
|
|
|
|
or format("{\\q2\\fn%s}%s {\\fn%s}{\\fs%d\\u1}",
|
|
|
|
o.font_mono, kspaces, o.font, 1.3*o.font_size)
|
|
|
|
local spost = term and "" or format("{\\u0\\fs%d}", o.font_size)
|
|
|
|
local _, itabs = o.indent:gsub("\t", "")
|
stats.lua: page 4 (keys): support help-like terminal printout
While --input-test is useful, and so is page 4 of stats, until now
there was no way to simply print the list in a help-like fashion.
This commit adds such printout, invoked by the script opt
stats-bindlist=yes, which uses the existing page 4 code. This prints
the list on startup and quits immediately - like any help page.
It's awkward to invoke compared to other help pages, and it does
require the stats page to be enabled (it is by default), however
it is a script-generated output, and currently there's no other
method to print a help page generated by a script.
The printout itself is performed using lua's io.write. While reliable,
it's not the standard way for mpv to print to the terminal.
Other possible printout methods are mp.msg.info - which also prints
"[stats]" prefix on each line (ugly), or forcing term-osd and setting
an osd-message which mpv will then print at the terminal - however
that's printed to stderr, and could also be subject to timing concerns
since we quit right afterwards.
In the future we can consider changing/integrating the invocation so
that mpv itself could print a help page generated by a script, thus
solving both the awkward invocation and printout-method issues.
2021-07-16 09:06:20 +00:00
|
|
|
local cutoff = term and (width or 79) - o.indent:len() - itabs * 7 - spre:len()
|
2021-07-16 08:17:50 +00:00
|
|
|
|
|
|
|
-- create the display lines
|
|
|
|
local info_lines = {}
|
|
|
|
local subject = nil
|
|
|
|
for _, bind in ipairs(ordered) do
|
|
|
|
if bind.subject ~= subject then -- new subject (title)
|
|
|
|
subject = bind.subject
|
|
|
|
append(info_lines, "", {})
|
|
|
|
append(info_lines, "", { prefix = spre .. subject .. spost })
|
|
|
|
end
|
|
|
|
if bind.comment then
|
|
|
|
bind.cmd = bind.cmd .. " # " .. bind.comment
|
|
|
|
end
|
|
|
|
append(info_lines, ellipsis(bind.cmd, cutoff),
|
|
|
|
{ prefix = kpre .. no_ASS(align_right(bind.key)) .. kpost })
|
|
|
|
end
|
|
|
|
return info_lines
|
|
|
|
end
|
|
|
|
|
2020-04-10 22:20:02 +00:00
|
|
|
local function append_general_perfdata(s, offset)
|
|
|
|
local perf_info = mp.get_property_native("perf-info") or {}
|
|
|
|
local count = 0
|
|
|
|
for _, data in ipairs(perf_info) do
|
|
|
|
count = count + 1
|
|
|
|
end
|
|
|
|
offset = max(1, min((offset or 1), count))
|
|
|
|
|
|
|
|
local i = 0
|
|
|
|
for _, data in ipairs(perf_info) do
|
|
|
|
i = i + 1
|
|
|
|
if i >= offset then
|
|
|
|
append(s, data.text or data.value, {prefix="["..tostring(i).."] "..data.name..":"})
|
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-08 22:27:54 +00:00
|
|
|
|
2020-04-10 22:20:02 +00:00
|
|
|
if o.plot_perfdata and o.use_ass and data.value then
|
|
|
|
buf = perf_buffers[data.name]
|
|
|
|
if not buf then
|
|
|
|
buf = {0, pos = 1, len = 50, max = 0}
|
|
|
|
perf_buffers[data.name] = buf
|
|
|
|
end
|
|
|
|
graph_add_value(buf, data.value)
|
|
|
|
s[#s+1] = generate_graph(buf, buf.pos, buf.len, buf.max, nil, 0.8, 1)
|
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-08 22:27:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-10 22:20:02 +00:00
|
|
|
return offset
|
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-08 22:27:54 +00:00
|
|
|
end
|
2016-06-10 22:04:14 +00:00
|
|
|
|
2017-01-18 20:35:59 +00:00
|
|
|
local function append_display_sync(s)
|
2016-09-12 00:30:09 +00:00
|
|
|
if not mp.get_property_bool("display-sync-active", false) then
|
|
|
|
return
|
2016-07-12 17:19:34 +00:00
|
|
|
end
|
|
|
|
|
2016-09-12 00:30:09 +00:00
|
|
|
local vspeed = append_property(s, "video-speed-correction", {prefix="DS:"})
|
|
|
|
if vspeed then
|
|
|
|
append_property(s, "audio-speed-correction",
|
|
|
|
{prefix="/", nl="", indent=" ", prefix_sep=" ", no_prefix_markup=true})
|
|
|
|
else
|
|
|
|
append_property(s, "audio-speed-correction",
|
|
|
|
{prefix="DS:" .. o.prefix_sep .. " - / ", prefix_sep=""})
|
|
|
|
end
|
2016-07-12 17:19:34 +00:00
|
|
|
|
2017-08-12 12:08:35 +00:00
|
|
|
append_property(s, "mistimed-frame-count", {prefix="Mistimed:", nl=""})
|
|
|
|
append_property(s, "vo-delayed-frame-count", {prefix="Delayed:", nl=""})
|
|
|
|
|
2017-01-21 13:31:46 +00:00
|
|
|
-- As we need to plot some graphs we print jitter and ratio on their own lines
|
2017-09-23 15:54:40 +00:00
|
|
|
if not display_timer.oneshot and (o.plot_vsync_ratio or o.plot_vsync_jitter) and o.use_ass then
|
2017-01-21 13:31:46 +00:00
|
|
|
local ratio_graph = ""
|
|
|
|
local jitter_graph = ""
|
2016-09-12 00:30:09 +00:00
|
|
|
if o.plot_vsync_ratio then
|
2017-06-30 22:31:05 +00:00
|
|
|
ratio_graph = generate_graph(vsratio_buf, vsratio_buf.pos, vsratio_buf.len, vsratio_buf.max, nil, 0.8, 1)
|
2016-09-12 00:30:09 +00:00
|
|
|
end
|
|
|
|
if o.plot_vsync_jitter then
|
2017-06-30 22:31:05 +00:00
|
|
|
jitter_graph = generate_graph(vsjitter_buf, vsjitter_buf.pos, vsjitter_buf.len, vsjitter_buf.max, nil, 0.8, 1)
|
2016-09-12 00:30:09 +00:00
|
|
|
end
|
2017-01-21 13:31:46 +00:00
|
|
|
append_property(s, "vsync-ratio", {prefix="VSync Ratio:", suffix=o.prefix_sep .. ratio_graph})
|
|
|
|
append_property(s, "vsync-jitter", {prefix="VSync Jitter:", suffix=o.prefix_sep .. jitter_graph})
|
|
|
|
else
|
|
|
|
-- Since no graph is needed we can print ratio/jitter on the same line and save some space
|
|
|
|
local vratio = append_property(s, "vsync-ratio", {prefix="VSync Ratio:"})
|
|
|
|
append_property(s, "vsync-jitter", {prefix="VSync Jitter:", nl="" or o.nl})
|
2016-09-12 00:30:09 +00:00
|
|
|
end
|
2015-04-03 15:22:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-07-25 13:37:09 +00:00
|
|
|
local function append_filters(s, prop, prefix)
|
|
|
|
local length = 0
|
|
|
|
local filters = {}
|
|
|
|
|
|
|
|
for _,f in ipairs(mp.get_property_native(prop, {})) do
|
|
|
|
local n = f.name
|
|
|
|
if f.enabled ~= nil and not f.enabled then
|
|
|
|
n = n .. " (disabled)"
|
|
|
|
end
|
|
|
|
|
2021-03-15 02:45:43 +00:00
|
|
|
if f.label ~= nil then
|
|
|
|
n = "@" .. f.label .. ": " .. n
|
|
|
|
end
|
|
|
|
|
2017-07-25 13:37:09 +00:00
|
|
|
local p = {}
|
|
|
|
for key,value in pairs(f.params) do
|
|
|
|
p[#p+1] = key .. "=" .. value
|
|
|
|
end
|
|
|
|
if #p > 0 then
|
|
|
|
p = " [" .. table.concat(p, " ") .. "]"
|
|
|
|
else
|
|
|
|
p = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
length = length + n:len() + p:len()
|
|
|
|
filters[#filters+1] = no_ASS(n) .. it(no_ASS(p))
|
|
|
|
end
|
|
|
|
|
|
|
|
if #filters > 0 then
|
|
|
|
local ret
|
|
|
|
if length < o.filter_params_max_length then
|
|
|
|
ret = table.concat(filters, ", ")
|
|
|
|
else
|
|
|
|
local sep = o.nl .. o.indent .. o.indent
|
|
|
|
ret = sep .. table.concat(filters, sep)
|
|
|
|
end
|
|
|
|
s[#s+1] = o.nl .. o.indent .. b(prefix) .. o.prefix_sep .. ret
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-07-12 17:19:34 +00:00
|
|
|
local function add_header(s)
|
2017-07-10 21:12:03 +00:00
|
|
|
s[#s+1] = text_style()
|
2015-04-03 15:22:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-07-12 17:19:34 +00:00
|
|
|
local function add_file(s)
|
2018-06-08 21:54:22 +00:00
|
|
|
append(s, "", {prefix="File:", nl="", indent=""})
|
2018-03-24 21:43:04 +00:00
|
|
|
append_property(s, "filename", {prefix_sep="", nl="", indent=""})
|
2016-07-12 17:19:34 +00:00
|
|
|
if not (mp.get_property_osd("filename") == mp.get_property_osd("media-title")) then
|
|
|
|
append_property(s, "media-title", {prefix="Title:"})
|
|
|
|
end
|
2017-08-25 21:57:17 +00:00
|
|
|
|
2020-04-15 17:22:35 +00:00
|
|
|
local editions = mp.get_property_number("editions")
|
|
|
|
local edition = mp.get_property_number("current-edition")
|
|
|
|
local ed_cond = (edition and editions > 1)
|
|
|
|
if ed_cond then
|
|
|
|
append_property(s, "edition-list/" .. tostring(edition) .. "/title",
|
|
|
|
{prefix="Edition:"})
|
|
|
|
append_property(s, "edition-list/count",
|
|
|
|
{prefix="(" .. tostring(edition + 1) .. "/", suffix=")", nl="",
|
|
|
|
indent=" ", prefix_sep=" ", no_prefix_markup=true})
|
|
|
|
end
|
|
|
|
|
2017-08-25 21:57:17 +00:00
|
|
|
local ch_index = mp.get_property_number("chapter")
|
|
|
|
if ch_index and ch_index >= 0 then
|
2020-04-15 17:22:35 +00:00
|
|
|
append_property(s, "chapter-list/" .. tostring(ch_index) .. "/title", {prefix="Chapter:",
|
|
|
|
nl=ed_cond and "" or o.nl})
|
2017-08-25 21:57:17 +00:00
|
|
|
append_property(s, "chapter-list/count",
|
|
|
|
{prefix="(" .. tostring(ch_index + 1) .. "/", suffix=")", nl="",
|
|
|
|
indent=" ", prefix_sep=" ", no_prefix_markup=true})
|
|
|
|
end
|
2017-12-26 16:54:03 +00:00
|
|
|
|
2020-04-15 17:27:37 +00:00
|
|
|
local fs = append_property(s, "file-size", {prefix="Size:"})
|
|
|
|
append_property(s, "file-format", {prefix="Format/Protocol:", nl=fs and "" or o.nl})
|
|
|
|
|
2017-12-26 16:54:03 +00:00
|
|
|
local demuxer_cache = mp.get_property_native("demuxer-cache-state", {})
|
|
|
|
if demuxer_cache["fw-bytes"] then
|
|
|
|
demuxer_cache = demuxer_cache["fw-bytes"] -- returns bytes
|
|
|
|
else
|
|
|
|
demuxer_cache = 0
|
|
|
|
end
|
|
|
|
local demuxer_secs = mp.get_property_number("demuxer-cache-duration", 0)
|
2018-12-06 18:01:26 +00:00
|
|
|
if demuxer_cache + demuxer_secs > 0 then
|
|
|
|
append(s, utils.format_bytes_humanized(demuxer_cache), {prefix="Total Cache:"})
|
|
|
|
append(s, format("%.1f", demuxer_secs), {prefix="(", suffix=" sec)", nl="",
|
|
|
|
no_prefix_markup=true, prefix_sep="", indent=o.prefix_sep})
|
2016-07-12 17:19:34 +00:00
|
|
|
end
|
2015-04-28 00:13:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2023-08-31 21:57:51 +00:00
|
|
|
local function crop_noop(w, h, r)
|
|
|
|
return r["crop-x"] == 0 and r["crop-y"] == 0 and
|
|
|
|
r["crop-w"] == w and r["crop-h"] == h
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function crop_equal(r, ro)
|
|
|
|
return r["crop-x"] == ro["crop-x"] and r["crop-y"] == ro["crop-y"] and
|
|
|
|
r["crop-w"] == ro["crop-w"] and r["crop-h"] == ro["crop-h"]
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function append_resolution(s, r, prefix, w_prop, h_prop, video_res)
|
2023-08-13 15:20:03 +00:00
|
|
|
if not r then
|
|
|
|
return
|
|
|
|
end
|
2023-08-25 17:33:00 +00:00
|
|
|
w_prop = w_prop or "w"
|
|
|
|
h_prop = h_prop or "h"
|
|
|
|
if append(s, r[w_prop], {prefix=prefix}) then
|
|
|
|
append(s, r[h_prop], {prefix="x", nl="", indent=" ", prefix_sep=" ",
|
2023-08-13 15:20:03 +00:00
|
|
|
no_prefix_markup=true})
|
|
|
|
if r["aspect"] ~= nil then
|
|
|
|
append(s, format("%.2f:1", r["aspect"]), {prefix=", ", nl="", indent="",
|
|
|
|
no_prefix_markup=true})
|
|
|
|
append(s, r["aspect-name"], {prefix="(", suffix=")", nl="", indent=" ",
|
|
|
|
prefix_sep="", no_prefix_markup=true})
|
|
|
|
end
|
2023-08-25 19:30:13 +00:00
|
|
|
if r['s'] then
|
|
|
|
append(s, format("%.2f", r["s"]), {prefix="(", suffix="x)", nl="",
|
|
|
|
indent=" ", prefix_sep="",
|
|
|
|
no_prefix_markup=true})
|
|
|
|
end
|
2023-08-31 21:57:51 +00:00
|
|
|
-- We can skip crop if it is the same as video decoded resolution
|
|
|
|
if r["crop-w"] and (not video_res or
|
|
|
|
not crop_noop(r[w_prop], r[h_prop], r)) then
|
|
|
|
append(s, format("[x: %d, y: %d, w: %d, h: %d]",
|
|
|
|
r["crop-x"], r["crop-y"], r["crop-w"], r["crop-h"]),
|
|
|
|
{prefix=", ", nl="", indent="", no_prefix_markup=true})
|
2023-08-25 17:34:11 +00:00
|
|
|
end
|
2023-08-13 15:20:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2023-08-29 08:24:08 +00:00
|
|
|
local function pq_eotf(x)
|
|
|
|
if not x then
|
|
|
|
return x;
|
|
|
|
end
|
|
|
|
|
|
|
|
local PQ_M1 = 2610.0 / 4096 * 1.0 / 4
|
|
|
|
local PQ_M2 = 2523.0 / 4096 * 128
|
|
|
|
local PQ_C1 = 3424.0 / 4096
|
|
|
|
local PQ_C2 = 2413.0 / 4096 * 32
|
|
|
|
local PQ_C3 = 2392.0 / 4096 * 32
|
|
|
|
|
|
|
|
x = x ^ (1.0 / PQ_M2)
|
|
|
|
x = max(x - PQ_C1, 0.0) / (PQ_C2 - PQ_C3 * x)
|
|
|
|
x = x ^ (1.0 / PQ_M1)
|
|
|
|
x = x * 10000.0
|
|
|
|
|
|
|
|
return x
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function append_hdr(s, hdr)
|
|
|
|
if not hdr then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if (hdr["max-cll"] and hdr["max-cll"] > 203) or
|
|
|
|
hdr["max-luma"] and hdr["max-luma"] > 203 then
|
|
|
|
append(s, "", {prefix="HDR10:"})
|
|
|
|
if hdr["min-luma"] and hdr["max-luma"] and hdr["max-luma"] > 203 then
|
|
|
|
append(s, format("%.2g / %.0f", hdr["min-luma"], hdr["max-luma"]),
|
|
|
|
{prefix="Mastering display:", suffix=" cd/m²", nl=""})
|
|
|
|
end
|
|
|
|
if hdr["max-cll"] and hdr["max-cll"] > 203 then
|
|
|
|
append(s, hdr["max-cll"], {prefix="maxCLL:", suffix=" cd/m²", nl=""})
|
|
|
|
end
|
|
|
|
if hdr["max-fall"] and hdr["max-fall"] > 0 then
|
|
|
|
append(s, hdr["max-fall"], {prefix="maxFALL:", suffix=" cd/m²", nl=""})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if hdr["scene-max-r"] or hdr["scene-max-g"] or
|
|
|
|
hdr["scene-max-b"] or hdr["scene-avg"] then
|
|
|
|
append(s, "", {prefix="HDR10+:"})
|
|
|
|
append(s, format("%.1f / %.1f / %.1f", hdr["scene-max-r"] or 0,
|
|
|
|
hdr["scene-max-g"] or 0, hdr["scene-max-b"] or 0),
|
|
|
|
{prefix="MaxRGB:", suffix=" cd/m²", nl=""})
|
|
|
|
append(s, format("%.1f", hdr["scene-avg"] or 0),
|
|
|
|
{prefix="Avg:", suffix=" cd/m²", nl=""})
|
|
|
|
end
|
|
|
|
|
|
|
|
if hdr["max-pq-y"] and hdr["avg-pq-y"] then
|
|
|
|
append(s, "", {prefix="PQ(Y):"})
|
|
|
|
append(s, format("%.2f cd/m² (%.2f%% PQ)", pq_eotf(hdr["max-pq-y"]),
|
|
|
|
hdr["max-pq-y"] * 100), {prefix="Max:", nl=""})
|
|
|
|
append(s, format("%.2f cd/m² (%.2f%% PQ)", pq_eotf(hdr["avg-pq-y"]),
|
|
|
|
hdr["avg-pq-y"] * 100), {prefix="Avg:", nl=""})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-07-12 17:19:34 +00:00
|
|
|
local function add_video(s)
|
2018-03-24 21:36:01 +00:00
|
|
|
local r = mp.get_property_native("video-params")
|
2023-08-13 15:20:03 +00:00
|
|
|
local ro = mp.get_property_native("video-out-params")
|
2021-08-15 08:31:13 +00:00
|
|
|
-- in case of e.g. lavfi-complex there can be no input video, only output
|
2018-03-24 21:36:01 +00:00
|
|
|
if not r then
|
2023-08-13 15:20:03 +00:00
|
|
|
r = ro
|
2018-03-24 21:36:01 +00:00
|
|
|
end
|
|
|
|
if not r then
|
2016-07-12 17:19:34 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-06-24 15:09:05 +00:00
|
|
|
local osd_dims = mp.get_property_native("osd-dimensions")
|
|
|
|
local scaled_width = osd_dims["w"] - osd_dims["ml"] - osd_dims["mr"]
|
|
|
|
local scaled_height = osd_dims["h"] - osd_dims["mt"] - osd_dims["mb"]
|
|
|
|
|
2018-03-24 21:43:04 +00:00
|
|
|
append(s, "", {prefix=o.nl .. o.nl .. "Video:", nl="", indent=""})
|
|
|
|
if append_property(s, "video-codec", {prefix_sep="", nl="", indent=""}) then
|
2017-09-23 15:54:40 +00:00
|
|
|
append_property(s, "hwdec-current", {prefix="(hwdec:", nl="", indent=" ",
|
|
|
|
no_prefix_markup=true, suffix=")"}, {no=true, [""]=true})
|
2016-07-12 17:19:34 +00:00
|
|
|
end
|
|
|
|
append_property(s, "avsync", {prefix="A-V:"})
|
2017-09-23 15:54:40 +00:00
|
|
|
if append_property(s, compat("decoder-frame-drop-count"),
|
|
|
|
{prefix="Dropped Frames:", suffix=" (decoder)"}) then
|
2017-08-12 12:08:35 +00:00
|
|
|
append_property(s, compat("frame-drop-count"), {suffix=" (output)", nl="", indent=""})
|
2016-07-12 17:19:34 +00:00
|
|
|
end
|
|
|
|
if append_property(s, "display-fps", {prefix="Display FPS:", suffix=" (specified)"}) then
|
|
|
|
append_property(s, "estimated-display-fps",
|
|
|
|
{suffix=" (estimated)", nl="", indent=""})
|
|
|
|
else
|
|
|
|
append_property(s, "estimated-display-fps",
|
|
|
|
{prefix="Display FPS:", suffix=" (estimated)"})
|
|
|
|
end
|
2017-06-16 10:38:41 +00:00
|
|
|
if append_property(s, compat("container-fps"), {prefix="FPS:", suffix=" (specified)"}) then
|
2016-07-12 17:19:34 +00:00
|
|
|
append_property(s, "estimated-vf-fps",
|
|
|
|
{suffix=" (estimated)", nl="", indent=""})
|
|
|
|
else
|
|
|
|
append_property(s, "estimated-vf-fps",
|
|
|
|
{prefix="FPS:", suffix=" (estimated)"})
|
|
|
|
end
|
|
|
|
|
2016-09-12 00:30:09 +00:00
|
|
|
append_display_sync(s)
|
2017-06-30 19:46:16 +00:00
|
|
|
append_perfdata(s, o.print_perfdata_passes)
|
2016-07-12 17:19:34 +00:00
|
|
|
|
2023-08-31 21:57:51 +00:00
|
|
|
append_resolution(s, r, "Native Resolution:", "w", "h", true)
|
2023-08-25 17:33:00 +00:00
|
|
|
if ro and (r["w"] ~= ro["dw"] or r["h"] ~= ro["dh"]) then
|
2023-08-31 21:57:51 +00:00
|
|
|
if ro["crop-w"] and (crop_noop(r["w"], r["h"], ro) or crop_equal(r, ro)) then
|
|
|
|
ro["crop-w"] = nil
|
|
|
|
end
|
2023-08-25 17:33:00 +00:00
|
|
|
append_resolution(s, ro, "Output Resolution:", "dw", "dh")
|
2021-06-24 15:09:05 +00:00
|
|
|
end
|
2023-08-25 19:30:13 +00:00
|
|
|
local scale = nil
|
2023-08-13 15:16:41 +00:00
|
|
|
if not mp.get_property_native("fullscreen") then
|
2023-08-25 19:30:13 +00:00
|
|
|
scale = mp.get_property_native("current-window-scale")
|
|
|
|
end
|
|
|
|
append_resolution(s, {w=scaled_width, h=scaled_height, s=scale}, "Scaled Resolution:")
|
|
|
|
|
|
|
|
if mp.get_property_native("deinterlace") then
|
|
|
|
append_property(s, "deinterlace", {prefix="Deinterlacing:"})
|
2023-08-13 15:16:41 +00:00
|
|
|
end
|
2023-08-25 19:30:13 +00:00
|
|
|
|
2018-03-24 21:36:01 +00:00
|
|
|
append(s, r["pixelformat"], {prefix="Pixel Format:"})
|
2020-10-16 09:09:32 +00:00
|
|
|
if r["hw-pixelformat"] ~= nil then
|
|
|
|
append(s, r["hw-pixelformat"], {prefix_sep="[", nl="", indent=" ",
|
|
|
|
suffix="]"})
|
|
|
|
end
|
2023-08-25 19:30:13 +00:00
|
|
|
append(s, r["colorlevels"], {prefix="Levels:", nl=""})
|
2016-07-13 09:29:31 +00:00
|
|
|
|
|
|
|
-- Group these together to save vertical space
|
2023-08-25 19:30:13 +00:00
|
|
|
append(s, r["colormatrix"], {prefix="Colormatrix:"})
|
|
|
|
append(s, r["primaries"], {prefix="Primaries:", nl=""})
|
|
|
|
append(s, r["gamma"], {prefix="Transfer:", nl=""})
|
2023-08-29 08:24:08 +00:00
|
|
|
|
|
|
|
local hdr = mp.get_property_native("hdr-metadata")
|
|
|
|
if not hdr then
|
|
|
|
local hdrpeak = r["sig-peak"] or 0
|
|
|
|
hdr = {["max-cll"]=math.floor(hdrpeak * 203)}
|
2016-07-13 09:29:31 +00:00
|
|
|
end
|
2023-08-29 08:24:08 +00:00
|
|
|
|
|
|
|
append_hdr(s, hdr)
|
2016-07-12 17:19:34 +00:00
|
|
|
append_property(s, "packet-video-bitrate", {prefix="Bitrate:", suffix=" kbps"})
|
2017-07-25 13:37:09 +00:00
|
|
|
append_filters(s, "vf", "Filters:")
|
2015-04-03 15:22:32 +00:00
|
|
|
end
|
2015-04-28 00:13:27 +00:00
|
|
|
|
|
|
|
|
2016-07-12 17:19:34 +00:00
|
|
|
local function add_audio(s)
|
2018-03-24 21:36:01 +00:00
|
|
|
local r = mp.get_property_native("audio-params")
|
2021-08-15 08:31:13 +00:00
|
|
|
-- in case of e.g. lavfi-complex there can be no input audio, only output
|
2018-03-24 21:36:01 +00:00
|
|
|
if not r then
|
|
|
|
r = mp.get_property_native("audio-out-params")
|
|
|
|
end
|
|
|
|
if not r then
|
2016-07-12 17:19:34 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-03-24 21:43:04 +00:00
|
|
|
append(s, "", {prefix=o.nl .. o.nl .. "Audio:", nl="", indent=""})
|
|
|
|
append_property(s, "audio-codec", {prefix_sep="", nl="", indent=""})
|
2019-01-13 12:34:15 +00:00
|
|
|
local cc = append(s, r["channel-count"], {prefix="Channels:"})
|
|
|
|
append(s, r["format"], {prefix="Format:", nl=cc and "" or o.nl})
|
2018-03-24 21:36:01 +00:00
|
|
|
append(s, r["samplerate"], {prefix="Sample Rate:", suffix=" Hz"})
|
2016-07-12 17:19:34 +00:00
|
|
|
append_property(s, "packet-audio-bitrate", {prefix="Bitrate:", suffix=" kbps"})
|
2017-07-25 13:37:09 +00:00
|
|
|
append_filters(s, "af", "Filters:")
|
2015-04-03 15:22:32 +00:00
|
|
|
end
|
2015-04-28 00:13:27 +00:00
|
|
|
|
2016-07-08 08:53:02 +00:00
|
|
|
|
2017-09-23 15:54:40 +00:00
|
|
|
-- Determine whether ASS formatting shall/can be used and set formatting sequences
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
local function eval_ass_formatting()
|
2017-07-04 22:31:44 +00:00
|
|
|
o.use_ass = o.ass_formatting and has_vo_window()
|
|
|
|
if o.use_ass then
|
|
|
|
o.nl = o.ass_nl
|
|
|
|
o.indent = o.ass_indent
|
|
|
|
o.prefix_sep = o.ass_prefix_sep
|
|
|
|
o.b1 = o.ass_b1
|
|
|
|
o.b0 = o.ass_b0
|
2017-07-25 13:37:09 +00:00
|
|
|
o.it1 = o.ass_it1
|
|
|
|
o.it0 = o.ass_it0
|
2017-07-04 22:31:44 +00:00
|
|
|
else
|
2016-07-12 17:19:34 +00:00
|
|
|
o.nl = o.no_ass_nl
|
|
|
|
o.indent = o.no_ass_indent
|
|
|
|
o.prefix_sep = o.no_ass_prefix_sep
|
2020-04-23 13:29:18 +00:00
|
|
|
o.b1 = o.no_ass_b1
|
|
|
|
o.b0 = o.no_ass_b0
|
|
|
|
o.it1 = o.no_ass_it1
|
|
|
|
o.it0 = o.no_ass_it0
|
2015-07-21 19:53:23 +00:00
|
|
|
end
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
end
|
2016-07-12 17:19:34 +00:00
|
|
|
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
|
|
|
-- Returns an ASS string with "normal" stats
|
|
|
|
local function default_stats()
|
2017-07-02 21:24:51 +00:00
|
|
|
local stats = {}
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
eval_ass_formatting()
|
2017-07-02 21:24:51 +00:00
|
|
|
add_header(stats)
|
|
|
|
add_file(stats)
|
|
|
|
add_video(stats)
|
|
|
|
add_audio(stats)
|
|
|
|
return table.concat(stats)
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
end
|
|
|
|
|
2020-05-17 11:55:38 +00:00
|
|
|
local function scroll_vo_stats(stats, fixed_items, offset)
|
|
|
|
local ret = {}
|
|
|
|
local count = #stats - fixed_items
|
|
|
|
offset = max(1, min((offset or 1), count))
|
|
|
|
|
|
|
|
for i, line in pairs(stats) do
|
|
|
|
if i <= fixed_items or i >= fixed_items + offset then
|
|
|
|
ret[#ret+1] = stats[i]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret, offset
|
|
|
|
end
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
|
|
|
-- Returns an ASS string with extended VO stats
|
|
|
|
local function vo_stats()
|
|
|
|
local stats = {}
|
|
|
|
eval_ass_formatting()
|
|
|
|
add_header(stats)
|
2020-05-17 11:55:38 +00:00
|
|
|
|
|
|
|
-- first line (title) added next is considered fixed
|
|
|
|
local fixed_items = #stats + 1
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
append_perfdata(stats, true)
|
2020-05-17 11:55:38 +00:00
|
|
|
|
|
|
|
local page = pages[o.key_page_2]
|
|
|
|
stats, page.offset = scroll_vo_stats(stats, fixed_items, page.offset)
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
return table.concat(stats)
|
|
|
|
end
|
|
|
|
|
2021-07-16 08:17:50 +00:00
|
|
|
local kbinfo_lines = nil
|
|
|
|
local function keybinding_info(after_scroll)
|
|
|
|
local header = {}
|
|
|
|
local page = pages[o.key_page_4]
|
|
|
|
eval_ass_formatting()
|
|
|
|
add_header(header)
|
2023-08-25 20:24:11 +00:00
|
|
|
append(header, "", {prefix=format("%s: {\\fs%s}%s{\\fs%s}", page.desc,
|
|
|
|
o.font_size * 0.66, "(hint: scroll with ↑↓)", o.font_size), nl="",
|
|
|
|
indent=""})
|
2021-07-16 08:17:50 +00:00
|
|
|
|
|
|
|
if not kbinfo_lines or not after_scroll then
|
|
|
|
kbinfo_lines = get_kbinfo_lines()
|
|
|
|
end
|
|
|
|
-- up to 20 lines for the terminal - so that mpv can also print
|
|
|
|
-- the status line without scrolling, and up to 40 lines for libass
|
|
|
|
-- because it can put a big performance toll on libass to process
|
|
|
|
-- many lines which end up outside (below) the screen.
|
|
|
|
local term = not o.use_ass
|
|
|
|
local nlines = #kbinfo_lines
|
|
|
|
page.offset = max(1, min((page.offset or 1), term and nlines - 20 or nlines))
|
|
|
|
local maxline = min(nlines, page.offset + (term and 20 or 40))
|
|
|
|
return table.concat(header) ..
|
|
|
|
table.concat(kbinfo_lines, "", page.offset, maxline)
|
|
|
|
end
|
|
|
|
|
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-08 22:27:54 +00:00
|
|
|
local function perf_stats()
|
|
|
|
local stats = {}
|
|
|
|
eval_ass_formatting()
|
|
|
|
add_header(stats)
|
2021-07-16 07:33:46 +00:00
|
|
|
local page = pages[o.key_page_0]
|
2023-08-25 19:28:53 +00:00
|
|
|
append(stats, "", {prefix=page.desc .. ":", nl="", indent=""})
|
2020-04-10 22:20:02 +00:00
|
|
|
page.offset = append_general_perfdata(stats, page.offset)
|
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-08 22:27:54 +00:00
|
|
|
return table.concat(stats)
|
|
|
|
end
|
|
|
|
|
2019-06-14 18:14:42 +00:00
|
|
|
local function opt_time(t)
|
|
|
|
if type(t) == type(1.1) then
|
|
|
|
return mp.format_time(t)
|
|
|
|
end
|
|
|
|
return "?"
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Returns an ASS string with stats about the demuxer cache etc.
|
|
|
|
local function cache_stats()
|
|
|
|
local stats = {}
|
|
|
|
|
2020-02-06 21:30:57 +00:00
|
|
|
eval_ass_formatting()
|
2019-06-14 18:14:42 +00:00
|
|
|
add_header(stats)
|
2023-08-25 19:28:53 +00:00
|
|
|
append(stats, "", {prefix="Cache info:", nl="", indent=""})
|
2019-06-14 18:14:42 +00:00
|
|
|
|
|
|
|
local info = mp.get_property_native("demuxer-cache-state")
|
|
|
|
if info == nil then
|
|
|
|
append(stats, "Unavailable.", {})
|
|
|
|
return table.concat(stats)
|
|
|
|
end
|
|
|
|
|
2019-06-22 22:30:56 +00:00
|
|
|
local a = info["reader-pts"]
|
|
|
|
local b = info["cache-end"]
|
|
|
|
|
|
|
|
append(stats, opt_time(a) .. " - " .. opt_time(b), {prefix = "Packet queue:"})
|
|
|
|
|
|
|
|
local r = nil
|
|
|
|
if (a ~= nil) and (b ~= nil) then
|
|
|
|
r = b - a
|
|
|
|
end
|
|
|
|
|
|
|
|
local r_graph = nil
|
|
|
|
if not display_timer.oneshot and o.use_ass then
|
|
|
|
r_graph = generate_graph(cache_ahead_buf, cache_ahead_buf.pos,
|
|
|
|
cache_ahead_buf.len, cache_ahead_buf.max,
|
|
|
|
nil, 0.8, 1)
|
|
|
|
r_graph = o.prefix_sep .. r_graph
|
|
|
|
end
|
|
|
|
append(stats, opt_time(r), {prefix = "Read-ahead:", suffix = r_graph})
|
2019-06-14 18:14:42 +00:00
|
|
|
|
|
|
|
-- These states are not necessarily exclusive. They're about potentially
|
|
|
|
-- separate mechanisms, whose states may be decoupled.
|
|
|
|
local state = "reading"
|
|
|
|
local seek_ts = info["debug-seeking"]
|
|
|
|
if seek_ts ~= nil then
|
|
|
|
state = "seeking (to " .. mp.format_time(seek_ts) .. ")"
|
|
|
|
elseif info["eof"] == true then
|
|
|
|
state = "eof"
|
|
|
|
elseif info["underrun"] then
|
|
|
|
state = "underrun"
|
|
|
|
elseif info["idle"] == true then
|
|
|
|
state = "inactive"
|
|
|
|
end
|
|
|
|
append(stats, state, {prefix = "State:"})
|
|
|
|
|
2020-04-03 11:26:31 +00:00
|
|
|
local speed = info["raw-input-rate"] or 0
|
|
|
|
local speed_graph = nil
|
2019-06-22 22:30:56 +00:00
|
|
|
if not display_timer.oneshot and o.use_ass then
|
2020-04-03 11:26:31 +00:00
|
|
|
speed_graph = generate_graph(cache_speed_buf, cache_speed_buf.pos,
|
|
|
|
cache_speed_buf.len, cache_speed_buf.max,
|
2019-06-22 22:30:56 +00:00
|
|
|
nil, 0.8, 1)
|
2020-04-03 11:26:31 +00:00
|
|
|
speed_graph = o.prefix_sep .. speed_graph
|
2019-06-22 22:30:56 +00:00
|
|
|
end
|
2020-04-03 21:26:51 +00:00
|
|
|
append(stats, utils.format_bytes_humanized(speed) .. "/s", {prefix="Speed:",
|
|
|
|
suffix=speed_graph})
|
2020-04-03 11:26:31 +00:00
|
|
|
|
2019-06-14 18:14:42 +00:00
|
|
|
append(stats, utils.format_bytes_humanized(info["total-bytes"]),
|
2020-04-03 11:26:31 +00:00
|
|
|
{prefix = "Total RAM:"})
|
2019-06-14 18:14:42 +00:00
|
|
|
append(stats, utils.format_bytes_humanized(info["fw-bytes"]),
|
|
|
|
{prefix = "Forward RAM:"})
|
|
|
|
|
|
|
|
local fc = info["file-cache-bytes"]
|
|
|
|
if fc ~= nil then
|
|
|
|
fc = utils.format_bytes_humanized(fc)
|
|
|
|
else
|
|
|
|
fc = "(disabled)"
|
|
|
|
end
|
|
|
|
append(stats, fc, {prefix = "Disk cache:"})
|
|
|
|
|
|
|
|
append(stats, info["debug-low-level-seeks"], {prefix = "Media seeks:"})
|
2019-11-07 15:05:27 +00:00
|
|
|
append(stats, info["debug-byte-level-seeks"], {prefix = "Stream seeks:"})
|
2019-06-14 18:14:42 +00:00
|
|
|
|
|
|
|
append(stats, "", {prefix=o.nl .. o.nl .. "Ranges:", nl="", indent=""})
|
|
|
|
|
|
|
|
append(stats, info["bof-cached"] and "yes" or "no",
|
|
|
|
{prefix = "Start cached:"})
|
|
|
|
append(stats, info["eof-cached"] and "yes" or "no",
|
|
|
|
{prefix = "End cached:"})
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
2019-06-14 18:14:42 +00:00
|
|
|
local ranges = info["seekable-ranges"] or {}
|
|
|
|
for n, r in ipairs(ranges) do
|
|
|
|
append(stats, mp.format_time(r["start"]) .. " - " ..
|
|
|
|
mp.format_time(r["end"]),
|
|
|
|
{prefix = format("Range %s:", n)})
|
|
|
|
end
|
|
|
|
|
|
|
|
return table.concat(stats)
|
2015-07-21 19:53:23 +00:00
|
|
|
end
|
2015-04-28 00:13:27 +00:00
|
|
|
|
2019-06-22 22:30:56 +00:00
|
|
|
-- Record 1 sample of cache statistics.
|
|
|
|
-- (Unlike record_data(), this does not return a function, but runs directly.)
|
|
|
|
local function record_cache_stats()
|
|
|
|
local info = mp.get_property_native("demuxer-cache-state")
|
|
|
|
if info == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local a = info["reader-pts"]
|
|
|
|
local b = info["cache-end"]
|
|
|
|
if (a ~= nil) and (b ~= nil) then
|
|
|
|
graph_add_value(cache_ahead_buf, b - a)
|
|
|
|
end
|
|
|
|
|
2020-04-03 11:26:31 +00:00
|
|
|
graph_add_value(cache_speed_buf, info["raw-input-rate"] or 0)
|
2019-06-22 22:30:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
cache_recorder_timer = mp.add_periodic_timer(0.25, record_cache_stats)
|
|
|
|
cache_recorder_timer:kill()
|
2016-07-08 08:53:02 +00:00
|
|
|
|
2017-09-23 15:54:40 +00:00
|
|
|
-- Current page and <page key>:<page function> mapping
|
|
|
|
curr_page = o.key_page_1
|
|
|
|
pages = {
|
|
|
|
[o.key_page_1] = { f = default_stats, desc = "Default" },
|
2020-05-17 11:55:38 +00:00
|
|
|
[o.key_page_2] = { f = vo_stats, desc = "Extended Frame Timings", scroll = true },
|
2019-06-14 18:14:42 +00:00
|
|
|
[o.key_page_3] = { f = cache_stats, desc = "Cache Statistics" },
|
2021-07-16 08:17:50 +00:00
|
|
|
[o.key_page_4] = { f = keybinding_info, desc = "Active key bindings", scroll = true },
|
2021-07-16 07:33:46 +00:00
|
|
|
[o.key_page_0] = { f = perf_stats, desc = "Internal performance info", scroll = true },
|
2017-09-23 15:54:40 +00:00
|
|
|
}
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- Returns a function to record vsratio/jitter with the specified `skip` value
|
2016-09-12 00:30:09 +00:00
|
|
|
local function record_data(skip)
|
|
|
|
init_buffers()
|
|
|
|
skip = max(skip, 0)
|
2016-07-12 17:19:34 +00:00
|
|
|
local i = skip
|
|
|
|
return function()
|
|
|
|
if i < skip then
|
|
|
|
i = i + 1
|
|
|
|
return
|
|
|
|
else
|
|
|
|
i = 0
|
|
|
|
end
|
|
|
|
|
2016-09-12 00:30:09 +00:00
|
|
|
if o.plot_vsync_jitter then
|
|
|
|
local r = mp.get_property_number("vsync-jitter", nil)
|
|
|
|
if r then
|
|
|
|
vsjitter_buf.pos = (vsjitter_buf.pos % vsjitter_buf.len) + 1
|
|
|
|
vsjitter_buf[vsjitter_buf.pos] = r
|
|
|
|
vsjitter_buf.max = max(vsjitter_buf.max, r)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if o.plot_vsync_ratio then
|
|
|
|
local r = mp.get_property_number("vsync-ratio", nil)
|
|
|
|
if r then
|
|
|
|
vsratio_buf.pos = (vsratio_buf.pos % vsratio_buf.len) + 1
|
|
|
|
vsratio_buf[vsratio_buf.pos] = r
|
|
|
|
vsratio_buf.max = max(vsratio_buf.max, r)
|
|
|
|
end
|
2016-07-12 17:19:34 +00:00
|
|
|
end
|
|
|
|
end
|
2015-04-03 15:22:32 +00:00
|
|
|
end
|
|
|
|
|
2017-09-23 15:54:40 +00:00
|
|
|
-- Call the function for `page` and print it to OSD
|
2021-07-16 07:37:41 +00:00
|
|
|
local function print_page(page, after_scroll)
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
-- the page functions assume we start in ass-enabled mode.
|
|
|
|
-- that's true for mp.set_osd_ass, but not for mp.osd_message.
|
|
|
|
local ass_content = pages[page].f(after_scroll)
|
2017-09-23 15:54:40 +00:00
|
|
|
if o.persistent_overlay then
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
mp.set_osd_ass(0, 0, ass_content)
|
2016-05-17 20:23:11 +00:00
|
|
|
else
|
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input:
- show-text (scripting: mp.osd_message) has ass disabled by default
(escaped), and the property osd-ass-cc can control escaping.
- osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay)
has ass enabled (unescaped), and osd-ass-cc is NOT supported.
By default, stats.lua uses mp.osd_message which does support escaping.
That's persistent_overlay=no.
When using persistent_overlay=yes then mp.set_osd_ass is used.
Due to this, the no_ASS(..) function - which is supposed to escape
ass, simply returned its input unmodified when persistent_overlay
is enabled.
This is not a new issue, and the filters on page 1 use no_ASS() to no
avail in persistent mode, however, this content (filter name and value
strings) rarely actually needs escaping, and users didn't notice.
However, the new page 4 (keys) does break visibly when no_ASS doesn't
work, because it tries to escape arbitrary key-names and command
strings, and at the very least the key '{' is bound by default, which
is displayed incorrectly if escaping doesn't work.
Fix this by rolling our own escaping when using mp.set_osd_ass,
similar to how the mpv code does it for mp.osd_message (substrings
replacements).
However, this means that the set_ASS(..) function can no longer
behave correctly because escaping requires going through the whole
content string rather than only inserting a marker.
Luckily, other than at no_ASS, set_ASS was only used at one place
(text_style), which is only called from two places:
- generate_graph() only needs to restore styles - not to enable ass.
- add_header() is only used at the begining of page output, and
uses set_ASS to enable ass initially when using mp.osd_message.
So remove the set_ASS function, and instead enable ass directly at
print_page using osd-ass-cc when mp.osd_message is used.
Fixes #9022
2021-07-20 15:03:29 +00:00
|
|
|
mp.osd_message((o.use_ass and ass_start or "") .. ass_content,
|
2021-07-16 07:37:41 +00:00
|
|
|
display_timer.oneshot and o.duration or o.redraw_delay + 1)
|
2016-05-17 20:23:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-09-23 15:54:40 +00:00
|
|
|
local function clear_screen()
|
|
|
|
if o.persistent_overlay then mp.set_osd_ass(0, 0, "") else mp.osd_message("", 0) end
|
|
|
|
end
|
|
|
|
|
2020-04-10 22:20:02 +00:00
|
|
|
local function scroll_delta(d)
|
|
|
|
if display_timer.oneshot then display_timer:kill() ; display_timer:resume() end
|
|
|
|
pages[curr_page].offset = (pages[curr_page].offset or 1) + d
|
2021-07-16 07:37:41 +00:00
|
|
|
print_page(curr_page, true)
|
2020-04-10 22:20:02 +00:00
|
|
|
end
|
|
|
|
local function scroll_up() scroll_delta(-o.scroll_lines) end
|
|
|
|
local function scroll_down() scroll_delta(o.scroll_lines) end
|
|
|
|
|
|
|
|
local function reset_scroll_offsets()
|
|
|
|
for _, page in pairs(pages) do
|
|
|
|
page.offset = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function bind_scroll()
|
|
|
|
if not scroll_bound then
|
2021-07-19 21:49:03 +00:00
|
|
|
mp.add_forced_key_binding(o.key_scroll_up, "__forced_"..o.key_scroll_up, scroll_up, {repeatable=true})
|
|
|
|
mp.add_forced_key_binding(o.key_scroll_down, "__forced_"..o.key_scroll_down, scroll_down, {repeatable=true})
|
2020-04-10 22:20:02 +00:00
|
|
|
scroll_bound = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function unbind_scroll()
|
|
|
|
if scroll_bound then
|
2021-07-19 21:49:03 +00:00
|
|
|
mp.remove_key_binding("__forced_"..o.key_scroll_up)
|
|
|
|
mp.remove_key_binding("__forced_"..o.key_scroll_down)
|
2020-04-10 22:20:02 +00:00
|
|
|
scroll_bound = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local function update_scroll_bindings(k)
|
|
|
|
if (pages[k].scroll) then
|
|
|
|
bind_scroll()
|
|
|
|
else
|
|
|
|
unbind_scroll()
|
|
|
|
end
|
|
|
|
end
|
2017-09-23 15:54:40 +00:00
|
|
|
|
|
|
|
-- Add keybindings for every page
|
|
|
|
local function add_page_bindings()
|
|
|
|
local function a(k)
|
|
|
|
return function()
|
2020-04-10 22:20:02 +00:00
|
|
|
reset_scroll_offsets()
|
|
|
|
update_scroll_bindings(k)
|
2017-09-23 15:54:40 +00:00
|
|
|
curr_page = k
|
|
|
|
print_page(k)
|
|
|
|
if display_timer.oneshot then display_timer:kill() ; display_timer:resume() end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for k, _ in pairs(pages) do
|
2021-07-19 21:49:03 +00:00
|
|
|
mp.add_forced_key_binding(k, "__forced_"..k, a(k), {repeatable=true})
|
2017-07-02 11:23:23 +00:00
|
|
|
end
|
2020-04-10 22:20:02 +00:00
|
|
|
update_scroll_bindings(curr_page)
|
2017-07-02 11:23:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-09-23 15:54:40 +00:00
|
|
|
-- Remove keybindings for every page
|
|
|
|
local function remove_page_bindings()
|
|
|
|
for k, _ in pairs(pages) do
|
2021-07-19 21:49:03 +00:00
|
|
|
mp.remove_key_binding("__forced_"..k)
|
2017-09-23 15:54:40 +00:00
|
|
|
end
|
2020-04-10 22:20:02 +00:00
|
|
|
unbind_scroll()
|
2017-09-23 15:54:40 +00:00
|
|
|
end
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
|
|
|
|
2017-09-23 15:54:40 +00:00
|
|
|
local function process_key_binding(oneshot)
|
2020-04-10 22:20:02 +00:00
|
|
|
reset_scroll_offsets()
|
2017-09-23 15:54:40 +00:00
|
|
|
-- Stats are already being displayed
|
|
|
|
if display_timer:is_enabled() then
|
|
|
|
-- Previous and current keys were oneshot -> restart timer
|
|
|
|
if display_timer.oneshot and oneshot then
|
|
|
|
display_timer:kill()
|
|
|
|
print_page(curr_page)
|
|
|
|
display_timer:resume()
|
|
|
|
-- Previous and current keys were toggling -> end toggling
|
|
|
|
elseif not display_timer.oneshot and not oneshot then
|
|
|
|
display_timer:kill()
|
2019-06-22 22:30:56 +00:00
|
|
|
cache_recorder_timer:stop()
|
2023-08-30 13:09:51 +00:00
|
|
|
if tm_viz_prev ~= nil then
|
|
|
|
mp.set_property_native("tone-mapping-visualize", tm_viz_prev)
|
|
|
|
tm_viz_prev = nil
|
|
|
|
end
|
2017-09-23 15:54:40 +00:00
|
|
|
clear_screen()
|
|
|
|
remove_page_bindings()
|
|
|
|
if recorder then
|
2019-12-24 15:02:24 +00:00
|
|
|
mp.unobserve_property(recorder)
|
2017-09-23 15:54:40 +00:00
|
|
|
recorder = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- No stats are being displayed yet
|
|
|
|
else
|
|
|
|
if not oneshot and (o.plot_vsync_jitter or o.plot_vsync_ratio) then
|
|
|
|
recorder = record_data(o.skip_frames)
|
2019-12-24 15:02:24 +00:00
|
|
|
-- Rely on the fact that "vsync-ratio" is updated at the same time.
|
|
|
|
-- Using "none" to get a sample any time, even if it does not change.
|
|
|
|
-- Will stop working if "vsync-jitter" property change notification
|
|
|
|
-- changes, but it's fine for an internal script.
|
|
|
|
mp.observe_property("vsync-jitter", "none", recorder)
|
2020-04-09 13:03:17 +00:00
|
|
|
end
|
2023-08-30 13:09:51 +00:00
|
|
|
if not oneshot and o.plot_tonemapping_lut then
|
|
|
|
tm_viz_prev = mp.get_property_native("tone-mapping-visualize")
|
|
|
|
mp.set_property_native("tone-mapping-visualize", true)
|
|
|
|
end
|
2020-04-09 13:03:17 +00:00
|
|
|
if not oneshot then
|
|
|
|
cache_ahead_buf = {0, pos = 1, len = 50, max = 0}
|
|
|
|
cache_speed_buf = {0, pos = 1, len = 50, max = 0}
|
2019-06-22 22:30:56 +00:00
|
|
|
cache_recorder_timer:resume()
|
2017-09-23 15:54:40 +00:00
|
|
|
end
|
|
|
|
display_timer:kill()
|
|
|
|
display_timer.oneshot = oneshot
|
|
|
|
display_timer.timeout = oneshot and o.duration or o.redraw_delay
|
|
|
|
add_page_bindings()
|
|
|
|
print_page(curr_page)
|
|
|
|
display_timer:resume()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
stats: support for multiple "pages" of stats
Please note that the latest version of this script needs a very recent
version of mpv (from yesterday, to be precise, see the readme).
For older versions, please go to "releases".
HOW IT WORKS:
While the stats are visible (i.e. text is printed to the OSD) a
subsequent click on a numeric key (1, 2, ...) will display the
corresponding "page".
This works no matter if the stats are toggled or just shown as a single
invocation. In case of a single invocation, the newly displayed page
will be shown for the full duration again.
The selected page will be remembered (not persistantly though).
So far, only 3 pages are available.
1: the default page, stats as they used to be
2: extensive VO performance stats (to be redesigned/changed soon)
3: dummy
In the future, many more pages are possible.
Implementation is likely to change again (functionality will stay
the same). A new timer had to be introduced to remove the forced
keybindings in the oneshot case. The toggle case can remove them without
a timer. Ensuring that each mode won't remove timers of the other mode
didn't really turn out neat.
Therefore, I intend to change this again, maybe by merging the
oneshot case into the toggle case.
2017-07-02 01:00:49 +00:00
|
|
|
|
2017-09-23 15:54:40 +00:00
|
|
|
-- Create the timer used for redrawing (toggling) or clearing the screen (oneshot)
|
|
|
|
-- The duration here is not important and always set in process_key_binding()
|
|
|
|
display_timer = mp.add_periodic_timer(o.duration,
|
2017-07-02 11:53:32 +00:00
|
|
|
function()
|
2017-09-23 15:54:40 +00:00
|
|
|
if display_timer.oneshot then
|
|
|
|
display_timer:kill() ; clear_screen() ; remove_page_bindings()
|
|
|
|
else
|
|
|
|
print_page(curr_page)
|
2017-07-02 11:53:32 +00:00
|
|
|
end
|
|
|
|
end)
|
2017-09-23 15:54:40 +00:00
|
|
|
display_timer:kill()
|
2016-07-12 17:19:34 +00:00
|
|
|
|
2016-07-08 08:53:02 +00:00
|
|
|
-- Single invocation key binding
|
2021-07-21 06:13:23 +00:00
|
|
|
mp.add_key_binding(nil, "display-stats", function() process_key_binding(true) end,
|
2017-09-23 15:54:40 +00:00
|
|
|
{repeatable=true})
|
|
|
|
|
|
|
|
-- Toggling key binding
|
2021-07-21 06:13:23 +00:00
|
|
|
mp.add_key_binding(nil, "display-stats-toggle", function() process_key_binding(false) end,
|
2017-09-23 15:54:40 +00:00
|
|
|
{repeatable=false})
|
2017-07-02 11:23:23 +00:00
|
|
|
|
|
|
|
-- Single invocation bindings without key, can be used in input.conf to create
|
|
|
|
-- bindings for a specific page: "e script-binding stats/display-page-2"
|
|
|
|
for k, _ in pairs(pages) do
|
2020-07-21 17:32:52 +00:00
|
|
|
mp.add_key_binding(nil, "display-page-" .. k,
|
|
|
|
function()
|
|
|
|
curr_page = k
|
|
|
|
process_key_binding(true)
|
|
|
|
end, {repeatable=true})
|
2017-07-02 11:23:23 +00:00
|
|
|
end
|
2016-07-08 08:53:02 +00:00
|
|
|
|
2017-07-02 11:23:23 +00:00
|
|
|
-- Reprint stats immediately when VO was reconfigured, only when toggled
|
2016-07-08 08:53:02 +00:00
|
|
|
mp.register_event("video-reconfig",
|
2017-09-23 15:54:40 +00:00
|
|
|
function()
|
|
|
|
if display_timer:is_enabled() then
|
|
|
|
print_page(curr_page)
|
|
|
|
end
|
|
|
|
end)
|
stats.lua: page 4 (keys): support help-like terminal printout
While --input-test is useful, and so is page 4 of stats, until now
there was no way to simply print the list in a help-like fashion.
This commit adds such printout, invoked by the script opt
stats-bindlist=yes, which uses the existing page 4 code. This prints
the list on startup and quits immediately - like any help page.
It's awkward to invoke compared to other help pages, and it does
require the stats page to be enabled (it is by default), however
it is a script-generated output, and currently there's no other
method to print a help page generated by a script.
The printout itself is performed using lua's io.write. While reliable,
it's not the standard way for mpv to print to the terminal.
Other possible printout methods are mp.msg.info - which also prints
"[stats]" prefix on each line (ugly), or forcing term-osd and setting
an osd-message which mpv will then print at the terminal - however
that's printed to stderr, and could also be subject to timing concerns
since we quit right afterwards.
In the future we can consider changing/integrating the invocation so
that mpv itself could print a help page generated by a script, thus
solving both the awkward invocation and printout-method issues.
2021-07-16 09:06:20 +00:00
|
|
|
|
|
|
|
-- --script-opts=stats-bindlist=[-]{yes|<TERM-WIDTH>}
|
|
|
|
if o.bindlist ~= "no" then
|
|
|
|
mp.command("no-osd set really-quiet yes")
|
|
|
|
if o.bindlist:sub(1, 1) == "-" then
|
|
|
|
o.bindlist = o.bindlist:sub(2)
|
|
|
|
o.no_ass_b0 = ""
|
|
|
|
o.no_ass_b1 = ""
|
|
|
|
end
|
|
|
|
local width = max(40, math.floor(tonumber(o.bindlist) or 79))
|
|
|
|
mp.add_timeout(0, function() -- wait for all other scripts to finish init
|
|
|
|
o.ass_formatting = false
|
|
|
|
o.no_ass_indent = " "
|
|
|
|
eval_ass_formatting()
|
|
|
|
io.write(pages[o.key_page_4].desc .. ":" ..
|
|
|
|
table.concat(get_kbinfo_lines(width)) .. "\n")
|
|
|
|
mp.command("quit")
|
|
|
|
end)
|
|
|
|
end
|