mirror of https://github.com/mpv-player/mpv
osd: cleanup: make OSDTYPE_ constants private to OSD code
No need to have them everywhere. The only exception/annoyance is MAX_OSD_PARTS, which is now basically duplicated (and at runtime initialization is checked with an assert()).
This commit is contained in:
parent
75a36662cb
commit
876a3bafc5
|
@ -2719,7 +2719,7 @@ static int mp_property_osd_w(void *ctx, struct m_property *prop,
|
|||
int action, void *arg)
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_OSD);
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
|
||||
return m_property_int_ro(action, arg, vo_res.w);
|
||||
}
|
||||
|
||||
|
@ -2727,7 +2727,7 @@ static int mp_property_osd_h(void *ctx, struct m_property *prop,
|
|||
int action, void *arg)
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_OSD);
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
|
||||
return m_property_int_ro(action, arg, vo_res.h);
|
||||
}
|
||||
|
||||
|
@ -2735,7 +2735,7 @@ static int mp_property_osd_par(void *ctx, struct m_property *prop,
|
|||
int action, void *arg)
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_OSD);
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
|
||||
return m_property_double_ro(action, arg, vo_res.display_par);
|
||||
}
|
||||
|
||||
|
|
|
@ -978,7 +978,7 @@ static int script_set_osd_ass(lua_State *L)
|
|||
static int script_get_osd_size(lua_State *L)
|
||||
{
|
||||
struct MPContext *mpctx = get_mpctx(L);
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_EXTERNAL);
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
|
||||
double aspect = 1.0 * vo_res.w / MPMAX(vo_res.h, 1) /
|
||||
(vo_res.display_par ? vo_res.display_par : 1);
|
||||
lua_pushnumber(L, vo_res.w);
|
||||
|
@ -990,7 +990,7 @@ static int script_get_osd_size(lua_State *L)
|
|||
static int script_get_osd_margins(lua_State *L)
|
||||
{
|
||||
struct MPContext *mpctx = get_mpctx(L);
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_EXTERNAL);
|
||||
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
|
||||
lua_pushnumber(L, vo_res.ml);
|
||||
lua_pushnumber(L, vo_res.mt);
|
||||
lua_pushnumber(L, vo_res.mr);
|
||||
|
|
|
@ -561,6 +561,6 @@ void update_osd_msg(struct MPContext *mpctx)
|
|||
text = talloc_asprintf_append(text, "%s%s", text ? "\n" : "",
|
||||
mpctx->osd_msg_text);
|
||||
}
|
||||
osd_set_text(osd, OSDTYPE_OSD, text);
|
||||
osd_set_text(osd, text);
|
||||
talloc_free(text);
|
||||
}
|
||||
|
|
|
@ -71,8 +71,7 @@ void uninit_sub(struct MPContext *mpctx, struct track *track)
|
|||
reset_subtitles(mpctx, track);
|
||||
sub_select(track->d_sub, false);
|
||||
int order = get_order(mpctx, track);
|
||||
if (order >= 0 && order <= 1)
|
||||
osd_set_sub(mpctx->osd, OSDTYPE_SUB + order, NULL);
|
||||
osd_set_sub(mpctx->osd, order, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,8 +181,7 @@ void reinit_sub(struct MPContext *mpctx, struct track *track)
|
|||
|
||||
sub_select(track->d_sub, true);
|
||||
int order = get_order(mpctx, track);
|
||||
if (order >= 0 && order <= 1)
|
||||
osd_set_sub(mpctx->osd, OSDTYPE_SUB + order, track->d_sub);
|
||||
osd_set_sub(mpctx->osd, order, track->d_sub);
|
||||
sub_control(track->d_sub, SD_CTRL_SET_TOP, &(bool){!!order});
|
||||
}
|
||||
|
||||
|
|
18
sub/osd.c
18
sub/osd.c
|
@ -109,6 +109,8 @@ static bool osd_res_equals(struct mp_osd_res a, struct mp_osd_res b)
|
|||
|
||||
struct osd_state *osd_create(struct mpv_global *global)
|
||||
{
|
||||
assert(MAX_OSD_PARTS >= OSDTYPE_COUNT);
|
||||
|
||||
struct osd_state *osd = talloc_zero(NULL, struct osd_state);
|
||||
*osd = (struct osd_state) {
|
||||
.opts = global->opts,
|
||||
|
@ -151,24 +153,25 @@ void osd_changed_unlocked(struct osd_state *osd, int obj)
|
|||
osd->want_redraw = true;
|
||||
}
|
||||
|
||||
void osd_set_text(struct osd_state *osd, int obj, const char *text)
|
||||
void osd_set_text(struct osd_state *osd, const char *text)
|
||||
{
|
||||
pthread_mutex_lock(&osd->lock);
|
||||
struct osd_object *osd_obj = osd->objs[obj];
|
||||
struct osd_object *osd_obj = osd->objs[OSDTYPE_OSD];
|
||||
if (!text)
|
||||
text = "";
|
||||
if (strcmp(osd_obj->text, text) != 0) {
|
||||
talloc_free(osd_obj->text);
|
||||
osd_obj->text = talloc_strdup(osd_obj, text);
|
||||
osd_changed_unlocked(osd, obj);
|
||||
osd_changed_unlocked(osd, osd_obj->type);
|
||||
}
|
||||
pthread_mutex_unlock(&osd->lock);
|
||||
}
|
||||
|
||||
void osd_set_sub(struct osd_state *osd, int obj, struct dec_sub *dec_sub)
|
||||
void osd_set_sub(struct osd_state *osd, int index, struct dec_sub *dec_sub)
|
||||
{
|
||||
pthread_mutex_lock(&osd->lock);
|
||||
osd->objs[obj]->sub = dec_sub;
|
||||
if (index >= 0 && index < 2)
|
||||
osd->objs[OSDTYPE_SUB + index]->sub = dec_sub;
|
||||
pthread_mutex_unlock(&osd->lock);
|
||||
}
|
||||
|
||||
|
@ -405,10 +408,11 @@ bool osd_query_and_reset_want_redraw(struct osd_state *osd)
|
|||
return r;
|
||||
}
|
||||
|
||||
struct mp_osd_res osd_get_vo_res(struct osd_state *osd, int obj)
|
||||
struct mp_osd_res osd_get_vo_res(struct osd_state *osd)
|
||||
{
|
||||
pthread_mutex_lock(&osd->lock);
|
||||
struct mp_osd_res res = osd->objs[obj]->vo_res;
|
||||
// Any OSDTYPE is fine; but it mustn't be a subtitle one (can have lower res.)
|
||||
struct mp_osd_res res = osd->objs[OSDTYPE_OSD]->vo_res;
|
||||
pthread_mutex_unlock(&osd->lock);
|
||||
return res;
|
||||
}
|
||||
|
|
19
sub/osd.h
19
sub/osd.h
|
@ -78,17 +78,8 @@ struct mp_osd_res {
|
|||
double display_par;
|
||||
};
|
||||
|
||||
enum mp_osdtype {
|
||||
OSDTYPE_SUB,
|
||||
OSDTYPE_SUB2, // IDs must be numerically successive
|
||||
|
||||
OSDTYPE_OSD,
|
||||
|
||||
OSDTYPE_EXTERNAL,
|
||||
OSDTYPE_EXTERNAL2,
|
||||
|
||||
MAX_OSD_PARTS
|
||||
};
|
||||
// 0 <= sub_bitmaps.render_index < MAX_OSD_PARTS
|
||||
#define MAX_OSD_PARTS 5
|
||||
|
||||
// Start of OSD symbols in osd_font.pfb
|
||||
#define OSD_CODEPOINTS 0xE000
|
||||
|
@ -149,8 +140,8 @@ void osd_free(struct osd_state *osd);
|
|||
|
||||
bool osd_query_and_reset_want_redraw(struct osd_state *osd);
|
||||
|
||||
void osd_set_text(struct osd_state *osd, int obj, const char *text);
|
||||
void osd_set_sub(struct osd_state *osd, int obj, struct dec_sub *dec_sub);
|
||||
void osd_set_text(struct osd_state *osd, const char *text);
|
||||
void osd_set_sub(struct osd_state *osd, int index, struct dec_sub *dec_sub);
|
||||
|
||||
bool osd_get_render_subs_in_filter(struct osd_state *osd);
|
||||
void osd_set_render_subs_in_filter(struct osd_state *osd, bool s);
|
||||
|
@ -188,7 +179,7 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
|
|||
struct mp_image_params;
|
||||
struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p);
|
||||
|
||||
struct mp_osd_res osd_get_vo_res(struct osd_state *osd, int obj);
|
||||
struct mp_osd_res osd_get_vo_res(struct osd_state *osd);
|
||||
|
||||
void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h,
|
||||
struct mp_osd_res res, double compensate_par);
|
||||
|
|
|
@ -7,6 +7,18 @@
|
|||
|
||||
#define OSD_CONV_CACHE_MAX 4
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue