mpv/sub/osd_state.h

95 lines
1.9 KiB
C
Raw Normal View History

#ifndef MP_OSD_STATE_H_
#define MP_OSD_STATE_H_
#include <stdatomic.h>
#include "osd.h"
2023-10-21 02:55:41 +00:00
#include "osdep/threads.h"
enum mp_osdtype {
OSDTYPE_SUB,
OSDTYPE_SUB2, // IDs must be numerically successive
OSDTYPE_OSD,
OSDTYPE_EXTERNAL,
OSDTYPE_EXTERNAL2,
OSDTYPE_COUNT
};
struct ass_state {
struct mp_log *log;
struct ass_track *track;
struct ass_renderer *render;
struct ass_library *library;
int res_x, res_y;
bool changed;
struct mp_osd_res vo_res; // last known value
};
struct osd_object {
int type; // OSDTYPE_*
bool is_sub;
// OSDTYPE_OSD
bool osd_changed;
char *text;
struct osd_progbar_state progbar_state;
// OSDTYPE_SUB/OSDTYPE_SUB2
struct dec_sub *sub;
// OSDTYPE_EXTERNAL
struct osd_external **externals;
int num_externals;
// OSDTYPE_EXTERNAL2
struct sub_bitmaps *external2;
// VO cache state
int vo_change_id;
struct mp_osd_res vo_res;
bool vo_had_output;
// Internally used by osd_libass.c
bool changed;
struct ass_state ass;
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;
struct ass_image **ass_imgs;
};
struct osd_external {
struct osd_external_ass ov;
struct ass_state ass;
};
struct osd_state {
2023-10-21 02:55:41 +00:00
mp_mutex lock;
struct osd_object *objs[MAX_OSD_PARTS];
bool render_subs_in_filter;
_Atomic double force_video_pts;
bool want_redraw;
bool want_redraw_notification;
struct m_config_cache *opts_cache;
struct mp_osd_render_opts *opts;
struct mpv_global *global;
struct mp_log *log;
struct stats_ctx *stats;
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);
void osd_init_backend(struct osd_state *osd);
void osd_destroy_backend(struct osd_state *osd);
#endif