mirror of https://github.com/mpv-player/mpv
sub: pass preferred OSD format to subtitle renderers
The intention is to let mp_ass_packer_pack() produce different output for the RGBA and LIBASS formats. VOs (or whatever generates the OSD) currently do not signal a preferred format, and this mechanism just exists to switch between RGBA and LIBASS formats correctly, preferring LIBASS if the VO supports it.
This commit is contained in:
parent
315e2e3da8
commit
f110552898
|
@ -255,8 +255,8 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts)
|
|||
// You must call sub_lock/sub_unlock if more than 1 thread access sub.
|
||||
// The issue is that *res will contain decoder allocated data, which might
|
||||
// be deallocated on the next decoder access.
|
||||
void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, double pts,
|
||||
struct sub_bitmaps *res)
|
||||
void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, int format,
|
||||
double pts, struct sub_bitmaps *res)
|
||||
{
|
||||
struct MPOpts *opts = sub->opts;
|
||||
|
||||
|
@ -267,7 +267,7 @@ void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, double pts,
|
|||
return;
|
||||
|
||||
if (opts->sub_visibility && sub->sd->driver->get_bitmaps)
|
||||
sub->sd->driver->get_bitmaps(sub->sd, dim, pts, res);
|
||||
sub->sd->driver->get_bitmaps(sub->sd, dim, format, pts, res);
|
||||
}
|
||||
|
||||
// See sub_get_bitmaps() for locking requirements.
|
||||
|
|
|
@ -35,8 +35,8 @@ void sub_unlock(struct dec_sub *sub);
|
|||
bool sub_can_preload(struct dec_sub *sub);
|
||||
void sub_preload(struct dec_sub *sub);
|
||||
bool sub_read_packets(struct dec_sub *sub, double video_pts);
|
||||
void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, double pts,
|
||||
struct sub_bitmaps *res);
|
||||
void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, int format,
|
||||
double pts, struct sub_bitmaps *res);
|
||||
char *sub_get_text(struct dec_sub *sub, double pts);
|
||||
void sub_reset(struct dec_sub *sub);
|
||||
void sub_select(struct dec_sub *sub, bool selected);
|
||||
|
|
|
@ -247,6 +247,10 @@ static void render_object(struct osd_state *osd, struct osd_object *obj,
|
|||
{
|
||||
struct MPOpts *opts = osd->opts;
|
||||
|
||||
int format = SUBBITMAP_LIBASS;
|
||||
if (!sub_formats[format] || opts->force_rgba_osd)
|
||||
format = SUBBITMAP_RGBA;
|
||||
|
||||
bool formats[SUBBITMAP_COUNT];
|
||||
memcpy(formats, sub_formats, sizeof(formats));
|
||||
if (opts->force_rgba_osd)
|
||||
|
@ -261,7 +265,7 @@ static void render_object(struct osd_state *osd, struct osd_object *obj,
|
|||
double sub_pts = video_pts;
|
||||
if (sub_pts != MP_NOPTS_VALUE)
|
||||
sub_pts -= opts->sub_delay;
|
||||
sub_get_bitmaps(obj->sub, obj->vo_res, sub_pts, out_imgs);
|
||||
sub_get_bitmaps(obj->sub, obj->vo_res, format, sub_pts, out_imgs);
|
||||
}
|
||||
} else if (obj->type == OSDTYPE_EXTERNAL2) {
|
||||
if (obj->external2 && obj->external2->format) {
|
||||
|
@ -269,7 +273,7 @@ static void render_object(struct osd_state *osd, struct osd_object *obj,
|
|||
obj->external2->change_id = 0;
|
||||
}
|
||||
} else {
|
||||
osd_object_get_bitmaps(osd, obj, out_imgs);
|
||||
osd_object_get_bitmaps(osd, obj, format, out_imgs);
|
||||
}
|
||||
|
||||
if (obj->force_redraw)
|
||||
|
|
|
@ -205,7 +205,7 @@ void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h,
|
|||
|
||||
// internal use only
|
||||
void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
|
||||
struct sub_bitmaps *out_imgs);
|
||||
int format, struct sub_bitmaps *out_imgs);
|
||||
void osd_init_backend(struct osd_state *osd);
|
||||
void osd_destroy_backend(struct osd_state *osd);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function)
|
|||
}
|
||||
|
||||
void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
|
||||
struct sub_bitmaps *out_imgs)
|
||||
int format, struct sub_bitmaps *out_imgs)
|
||||
{
|
||||
*out_imgs = (struct sub_bitmaps) {0};
|
||||
}
|
||||
|
|
|
@ -525,7 +525,7 @@ static void append_ass(struct ass_state *ass, struct mp_osd_res *res,
|
|||
}
|
||||
|
||||
void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
|
||||
struct sub_bitmaps *out_imgs)
|
||||
int format, struct sub_bitmaps *out_imgs)
|
||||
{
|
||||
if (obj->force_redraw && obj->type == OSDTYPE_OSD)
|
||||
update_osd(osd, obj);
|
||||
|
@ -542,7 +542,7 @@ void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
|
|||
}
|
||||
|
||||
mp_ass_packer_pack(obj->ass_packer, obj->ass_imgs, obj->num_externals + 1,
|
||||
obj->changed, SUBBITMAP_LIBASS, out_imgs);
|
||||
obj->changed, format, out_imgs);
|
||||
|
||||
obj->changed = false;
|
||||
}
|
||||
|
|
4
sub/sd.h
4
sub/sd.h
|
@ -37,8 +37,8 @@ struct sd_functions {
|
|||
bool (*accepts_packet)(struct sd *sd); // implicit default if NULL: true
|
||||
int (*control)(struct sd *sd, enum sd_ctrl cmd, void *arg);
|
||||
|
||||
void (*get_bitmaps)(struct sd *sd, struct mp_osd_res dim, double pts,
|
||||
struct sub_bitmaps *res);
|
||||
void (*get_bitmaps)(struct sd *sd, struct mp_osd_res dim, int format,
|
||||
double pts, struct sub_bitmaps *res);
|
||||
char *(*get_text)(struct sd *sd, double pts);
|
||||
};
|
||||
|
||||
|
|
|
@ -420,8 +420,8 @@ static long long find_timestamp(struct sd *sd, double pts)
|
|||
|
||||
#undef END
|
||||
|
||||
static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
|
||||
struct sub_bitmaps *res)
|
||||
static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, int format,
|
||||
double pts, struct sub_bitmaps *res)
|
||||
{
|
||||
struct sd_ass_priv *ctx = sd->priv;
|
||||
struct MPOpts *opts = sd->opts;
|
||||
|
@ -464,7 +464,7 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
|
|||
|
||||
int changed;
|
||||
ASS_Image *imgs = ass_render_frame(renderer, track, ts, &changed);
|
||||
mp_ass_packer_pack(ctx->packer, &imgs, 1, changed, SUBBITMAP_LIBASS, res);
|
||||
mp_ass_packer_pack(ctx->packer, &imgs, 1, changed, format, res);
|
||||
|
||||
if (!converted && res->num_parts > 0) {
|
||||
// mangle_colors() modifies the color field, so copy the thing.
|
||||
|
|
|
@ -422,8 +422,8 @@ static void decode(struct sd *sd, struct demux_packet *packet)
|
|||
}
|
||||
}
|
||||
|
||||
static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
|
||||
struct sub_bitmaps *res)
|
||||
static void get_bitmaps(struct sd *sd, struct mp_osd_res d, int format,
|
||||
double pts, struct sub_bitmaps *res)
|
||||
{
|
||||
struct sd_lavc_priv *priv = sd->priv;
|
||||
struct MPOpts *opts = sd->opts;
|
||||
|
|
Loading…
Reference in New Issue