mirror of
https://github.com/mpv-player/mpv
synced 2024-11-14 22:48:35 +01:00
6aad532aa3
Remove them from the big MPOpts struct and move them to their sub structs. In the places where their fields are used, create a private copy of the structs, instead of accessing the semi-deprecated global option struct instance (mpv_global.opts) directly. This actually makes accessing these options finally thread-safe. They weren't even if they should have for years. (Including some potential for undefined behavior when e.g. the OSD font was changed at runtime.) This is mostly transparent. All options get moved around, but most users of the options just need to access a different struct (changing sd.opts to a different type changes a lot of uses, for example). One thing which has to be considered and could cause potential regressions is that the new option copies must be explicitly updated. sub_update_opts() takes care of this for example. Another thing is that writing to the option structs manually won't work, because the changes won't be propagated to other copies. Apparently the only affected case is the implementation of the sub-step command, which tries to change sub_delay. Handle this one explicitly (osd_changed() doesn't need to be called anymore, because changing the option triggers UPDATE_OSD, and updates the OSD as a consequence). The way the option value is propagated is rather hacky, but for now this will do.
91 lines
1.8 KiB
C
91 lines
1.8 KiB
C
#ifndef MP_OSD_STATE_H_
|
|
#define MP_OSD_STATE_H_
|
|
|
|
#include <pthread.h>
|
|
|
|
#include "osd.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;
|
|
};
|
|
|
|
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;
|
|
|
|
// Internally used by osd_libass.c
|
|
bool changed;
|
|
struct ass_state ass;
|
|
struct mp_ass_packer *ass_packer;
|
|
struct ass_image **ass_imgs;
|
|
};
|
|
|
|
struct osd_external {
|
|
void *id;
|
|
char *text;
|
|
int res_x, res_y;
|
|
struct ass_state ass;
|
|
};
|
|
|
|
struct osd_state {
|
|
pthread_mutex_t lock;
|
|
|
|
struct osd_object *objs[MAX_OSD_PARTS];
|
|
|
|
bool render_subs_in_filter;
|
|
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 mp_draw_sub_cache *draw_cache;
|
|
};
|
|
|
|
// defined in osd_libass.c and osd_dummy.c
|
|
void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
|
|
int format, struct sub_bitmaps *out_imgs);
|
|
void osd_init_backend(struct osd_state *osd);
|
|
void osd_destroy_backend(struct osd_state *osd);
|
|
|
|
#endif
|