2014-01-18 00:19:20 +00:00
|
|
|
#ifndef MP_OSD_STATE_H_
|
|
|
|
#define MP_OSD_STATE_H_
|
|
|
|
|
2023-10-19 12:18:52 +00:00
|
|
|
#include <stdatomic.h>
|
2023-10-19 14:26:26 +00:00
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
#include "osd.h"
|
2023-10-21 02:55:41 +00:00
|
|
|
#include "osdep/threads.h"
|
2014-01-18 00:19:20 +00:00
|
|
|
|
2016-03-08 20:54:17 +00:00
|
|
|
enum mp_osdtype {
|
|
|
|
OSDTYPE_SUB,
|
|
|
|
OSDTYPE_SUB2, // IDs must be numerically successive
|
|
|
|
|
|
|
|
OSDTYPE_OSD,
|
|
|
|
|
|
|
|
OSDTYPE_EXTERNAL,
|
|
|
|
OSDTYPE_EXTERNAL2,
|
|
|
|
|
|
|
|
OSDTYPE_COUNT
|
|
|
|
};
|
|
|
|
|
2016-03-08 20:29:29 +00:00
|
|
|
struct ass_state {
|
|
|
|
struct mp_log *log;
|
|
|
|
struct ass_track *track;
|
|
|
|
struct ass_renderer *render;
|
|
|
|
struct ass_library *library;
|
2017-07-16 11:33:19 +00:00
|
|
|
int res_x, res_y;
|
2020-03-06 17:20:11 +00:00
|
|
|
bool changed;
|
|
|
|
struct mp_osd_res vo_res; // last known value
|
2016-03-08 20:29:29 +00:00
|
|
|
};
|
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
struct osd_object {
|
|
|
|
int type; // OSDTYPE_*
|
|
|
|
bool is_sub;
|
|
|
|
|
2016-03-08 20:42:08 +00:00
|
|
|
// OSDTYPE_OSD
|
2016-09-16 15:17:32 +00:00
|
|
|
bool osd_changed;
|
2014-01-18 00:19:20 +00:00
|
|
|
char *text;
|
|
|
|
struct osd_progbar_state progbar_state;
|
|
|
|
|
|
|
|
// OSDTYPE_SUB/OSDTYPE_SUB2
|
2015-11-17 00:54:02 +00:00
|
|
|
struct dec_sub *sub;
|
2014-01-18 00:19:20 +00:00
|
|
|
|
|
|
|
// OSDTYPE_EXTERNAL
|
client API, lua: add new API for setting OSD overlays
Lua scripting has an undocumented mp.set_osd_ass() function, which is
used by osc.lua and console.lua. Apparently, 3rd party scripts also use
this. It's probably time to make this a public API.
The Lua implementation just bypassed the libmpv API. To make it usable
by any type of client, turn it into a command, "osd-overlay".
There's already a "overlay-add". Ignore it (although the manpage admits
guiltiness). I don't really want to deal with that old command. Its main
problem is that it uses global IDs, while I'd like to avoid that scripts
mess with each others overlays (whether that is accidentally or
intentionally). Maybe "overlay-add" can eventually be merged into
"osd-overlay", but I'm too lazy to do that now.
Scripting now uses the commands. There is a helper to manage OSD
overlays. The helper is very "thin"; I only want to force script authors
to use the ID allocation, which may help with putting multiple scripts
into a single .lua file without causing conflicts (basically, avoiding
singletons within a script's environment). The old set_osd_ass() is
emulated with the new API.
The JS scripting wrapper also provides a set_osd_ass() function, which
calls internal mpv API. Comment that part (to keep it compiling), but
I'm leaving it to @avih to finish the change.
2019-12-23 10:40:27 +00:00
|
|
|
struct osd_external **externals;
|
2016-03-08 20:42:08 +00:00
|
|
|
int num_externals;
|
2014-01-18 00:19:20 +00:00
|
|
|
|
|
|
|
// OSDTYPE_EXTERNAL2
|
|
|
|
struct sub_bitmaps *external2;
|
|
|
|
|
|
|
|
// VO cache state
|
2015-03-18 11:33:14 +00:00
|
|
|
int vo_change_id;
|
2014-01-18 00:19:20 +00:00
|
|
|
struct mp_osd_res vo_res;
|
2020-05-09 15:54:33 +00:00
|
|
|
bool vo_had_output;
|
2014-01-18 00:19:20 +00:00
|
|
|
|
|
|
|
// Internally used by osd_libass.c
|
2016-06-30 19:38:50 +00:00
|
|
|
bool changed;
|
2016-03-08 20:29:29 +00:00
|
|
|
struct ass_state ass;
|
2016-06-30 19:38:50 +00:00
|
|
|
struct mp_ass_packer *ass_packer;
|
video: make OSD/subtitle bitmaps refcounted (sort of)
Making OSD/subtitle bitmaps refcounted was planend a longer time ago,
e.g. the sub_bitmaps.packed field (which refcounts the subtitle bitmap
data) was added in 2016. But nothing benefited much from it, because
struct sub_bitmaps was usually stack allocated, and there was this weird
callback stuff through osd_draw().
Make it possible to get actually refcounted subtitle bitmaps on the OSD
API level. For this, we just copy all subtitle data other than the
bitmaps with sub_bitmaps_copy(). At first, I had planned some fancy
refcount shit, but when that was a big mess and hard to debug and just
boiled to emulating malloc(), I made it a full allocation+copy. This
affects mostly the parts array. With crazy ASS subtitles, this parts
array can get pretty big (thousands of elements or more), in which case
the extra alloc/copy could become performance relevant. But then again
this is just pure bullshit, and I see no need to care. In practice, this
extra work most likely gets drowned out by libass murdering a single
core (while mpv is waiting for it) anyway. So fuck it.
I just wanted this so draw_bmp.c requires only a single call to render
everything. VOs also can benefit from this, because the weird callback
shit isn't necessary anymore (simpler code), but I haven't done anything
about it yet. In general I'd hope this will work towards simplifying the
OSD layer, which is prerequisite for making actual further improvements.
I haven't tested some cases such as the "overlay-add" command. Maybe it
crashes now? Who knows, who cares.
In addition, it might be worthwhile to reduce the code duplication
between all the things that output subtitle bitmaps (with repacking,
image allocation, etc.), but that's orthogonal.
2020-04-26 21:34:32 +00:00
|
|
|
struct sub_bitmap_copy_cache *copy_cache;
|
2016-06-30 19:38:50 +00:00
|
|
|
struct ass_image **ass_imgs;
|
2014-01-18 00:19:20 +00:00
|
|
|
};
|
|
|
|
|
2016-03-08 20:42:08 +00:00
|
|
|
struct osd_external {
|
client API, lua: add new API for setting OSD overlays
Lua scripting has an undocumented mp.set_osd_ass() function, which is
used by osc.lua and console.lua. Apparently, 3rd party scripts also use
this. It's probably time to make this a public API.
The Lua implementation just bypassed the libmpv API. To make it usable
by any type of client, turn it into a command, "osd-overlay".
There's already a "overlay-add". Ignore it (although the manpage admits
guiltiness). I don't really want to deal with that old command. Its main
problem is that it uses global IDs, while I'd like to avoid that scripts
mess with each others overlays (whether that is accidentally or
intentionally). Maybe "overlay-add" can eventually be merged into
"osd-overlay", but I'm too lazy to do that now.
Scripting now uses the commands. There is a helper to manage OSD
overlays. The helper is very "thin"; I only want to force script authors
to use the ID allocation, which may help with putting multiple scripts
into a single .lua file without causing conflicts (basically, avoiding
singletons within a script's environment). The old set_osd_ass() is
emulated with the new API.
The JS scripting wrapper also provides a set_osd_ass() function, which
calls internal mpv API. Comment that part (to keep it compiling), but
I'm leaving it to @avih to finish the change.
2019-12-23 10:40:27 +00:00
|
|
|
struct osd_external_ass ov;
|
2016-03-08 20:42:08 +00:00
|
|
|
struct ass_state ass;
|
|
|
|
};
|
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
struct osd_state {
|
2023-10-21 02:55:41 +00:00
|
|
|
mp_mutex lock;
|
2014-01-18 00:19:20 +00:00
|
|
|
|
|
|
|
struct osd_object *objs[MAX_OSD_PARTS];
|
|
|
|
|
|
|
|
bool render_subs_in_filter;
|
2023-10-19 12:18:52 +00:00
|
|
|
_Atomic double force_video_pts;
|
2014-01-18 00:19:20 +00:00
|
|
|
|
|
|
|
bool want_redraw;
|
2016-09-15 12:22:48 +00:00
|
|
|
bool want_redraw_notification;
|
2014-01-18 00:19:20 +00:00
|
|
|
|
2017-12-29 16:19:25 +00:00
|
|
|
struct m_config_cache *opts_cache;
|
|
|
|
struct mp_osd_render_opts *opts;
|
2014-01-18 00:19:20 +00:00
|
|
|
struct mpv_global *global;
|
|
|
|
struct mp_log *log;
|
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
|
|
|
struct stats_ctx *stats;
|
2014-01-18 00:19:20 +00:00
|
|
|
|
|
|
|
struct mp_draw_sub_cache *draw_cache;
|
|
|
|
};
|
|
|
|
|
video: make OSD/subtitle bitmaps refcounted (sort of)
Making OSD/subtitle bitmaps refcounted was planend a longer time ago,
e.g. the sub_bitmaps.packed field (which refcounts the subtitle bitmap
data) was added in 2016. But nothing benefited much from it, because
struct sub_bitmaps was usually stack allocated, and there was this weird
callback stuff through osd_draw().
Make it possible to get actually refcounted subtitle bitmaps on the OSD
API level. For this, we just copy all subtitle data other than the
bitmaps with sub_bitmaps_copy(). At first, I had planned some fancy
refcount shit, but when that was a big mess and hard to debug and just
boiled to emulating malloc(), I made it a full allocation+copy. This
affects mostly the parts array. With crazy ASS subtitles, this parts
array can get pretty big (thousands of elements or more), in which case
the extra alloc/copy could become performance relevant. But then again
this is just pure bullshit, and I see no need to care. In practice, this
extra work most likely gets drowned out by libass murdering a single
core (while mpv is waiting for it) anyway. So fuck it.
I just wanted this so draw_bmp.c requires only a single call to render
everything. VOs also can benefit from this, because the weird callback
shit isn't necessary anymore (simpler code), but I haven't done anything
about it yet. In general I'd hope this will work towards simplifying the
OSD layer, which is prerequisite for making actual further improvements.
I haven't tested some cases such as the "overlay-add" command. Maybe it
crashes now? Who knows, who cares.
In addition, it might be worthwhile to reduce the code duplication
between all the things that output subtitle bitmaps (with repacking,
image allocation, etc.), but that's orthogonal.
2020-04-26 21:34:32 +00:00
|
|
|
// defined in osd_libass.c
|
|
|
|
struct sub_bitmaps *osd_object_get_bitmaps(struct osd_state *osd,
|
|
|
|
struct osd_object *obj, int format);
|
2017-01-26 15:34:31 +00:00
|
|
|
void osd_init_backend(struct osd_state *osd);
|
|
|
|
void osd_destroy_backend(struct osd_state *osd);
|
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
#endif
|