mirror of
https://github.com/mpv-player/mpv
synced 2025-01-24 00:23:27 +00:00
osd: refactor how mp_ass_render_frame() is called
Instead of passing an explicit cache to the function, the res parameter is used. Also, instead of replacing its contents, sub bitmaps are now appended to it (all assuming the format doesn't actually change). This is preparation for the following commits.
This commit is contained in:
parent
87ae215853
commit
f5bfe01932
@ -22,6 +22,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <ass/ass.h>
|
||||
#include <ass/ass_types.h>
|
||||
@ -96,16 +97,15 @@ void mp_ass_configure_fonts(ASS_Renderer *priv, struct osd_style_opts *opts,
|
||||
}
|
||||
|
||||
void mp_ass_render_frame(ASS_Renderer *renderer, ASS_Track *track, double time,
|
||||
struct sub_bitmap **parts, struct sub_bitmaps *res)
|
||||
struct sub_bitmaps *res)
|
||||
{
|
||||
int changed;
|
||||
ASS_Image *imgs = ass_render_frame(renderer, track, time, &changed);
|
||||
if (changed)
|
||||
res->change_id++;
|
||||
assert(res->format == 0 || res->format == SUBBITMAP_LIBASS);
|
||||
res->format = SUBBITMAP_LIBASS;
|
||||
|
||||
res->parts = *parts;
|
||||
res->num_parts = 0;
|
||||
int num_parts_alloc = MP_TALLOC_AVAIL(res->parts);
|
||||
for (struct ass_image *img = imgs; img; img = img->next) {
|
||||
if (img->w == 0 || img->h == 0)
|
||||
@ -125,7 +125,6 @@ void mp_ass_render_frame(ASS_Renderer *renderer, ASS_Track *track, double time,
|
||||
p->y = img->dst_y;
|
||||
res->num_parts++;
|
||||
}
|
||||
*parts = res->parts;
|
||||
}
|
||||
|
||||
static const int map_ass_level[] = {
|
||||
|
@ -55,7 +55,7 @@ ASS_Library *mp_ass_init(struct mpv_global *global, struct mp_log *log);
|
||||
struct sub_bitmap;
|
||||
struct sub_bitmaps;
|
||||
void mp_ass_render_frame(ASS_Renderer *renderer, ASS_Track *track, double time,
|
||||
struct sub_bitmap **parts, struct sub_bitmaps *res);
|
||||
struct sub_bitmaps *res);
|
||||
|
||||
#endif /* HAVE_LIBASS */
|
||||
#endif /* MPLAYER_ASS_MP_H */
|
||||
|
@ -252,8 +252,6 @@ void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, double pts,
|
||||
{
|
||||
struct MPOpts *opts = sub->opts;
|
||||
|
||||
*res = (struct sub_bitmaps) {0};
|
||||
|
||||
sub->last_vo_pts = pts;
|
||||
update_segment(sub);
|
||||
|
||||
|
@ -77,6 +77,7 @@ void osd_destroy_backend(struct osd_state *osd)
|
||||
if (obj->osd_ass_library)
|
||||
ass_library_done(obj->osd_ass_library);
|
||||
obj->osd_ass_library = NULL;
|
||||
talloc_free(obj->parts_cache.parts);
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,13 +468,15 @@ void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
|
||||
if (obj->force_redraw)
|
||||
update_object(osd, obj);
|
||||
|
||||
*out_imgs = (struct sub_bitmaps) {0};
|
||||
if (!obj->osd_track)
|
||||
return;
|
||||
|
||||
obj->parts_cache.change_id = 0;
|
||||
obj->parts_cache.num_parts = 0;
|
||||
|
||||
ass_set_frame_size(obj->osd_render, obj->vo_res.w, obj->vo_res.h);
|
||||
ass_set_aspect_ratio(obj->osd_render, obj->vo_res.display_par, 1.0);
|
||||
mp_ass_render_frame(obj->osd_render, obj->osd_track, 0,
|
||||
&obj->parts_cache, out_imgs);
|
||||
talloc_steal(obj, obj->parts_cache);
|
||||
mp_ass_render_frame(obj->osd_render, obj->osd_track, 0, &obj->parts_cache);
|
||||
|
||||
*out_imgs = obj->parts_cache;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ struct osd_object {
|
||||
struct mp_osd_res vo_res;
|
||||
|
||||
// Internally used by osd_libass.c
|
||||
struct sub_bitmap *parts_cache;
|
||||
struct sub_bitmaps parts_cache;
|
||||
struct ass_track *osd_track;
|
||||
struct ass_renderer *osd_render;
|
||||
struct ass_library *osd_ass_library;
|
||||
|
14
sub/sd_ass.c
14
sub/sd_ass.c
@ -44,7 +44,7 @@ struct sd_ass_priv {
|
||||
bool is_converted;
|
||||
struct lavc_conv *converter;
|
||||
bool on_top;
|
||||
struct sub_bitmap *parts;
|
||||
struct sub_bitmaps part_cache;
|
||||
char last_text[500];
|
||||
struct mp_image_params video_params;
|
||||
struct mp_image_params last_params;
|
||||
@ -454,13 +454,19 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
|
||||
ctx->num_seen_packets = 0;
|
||||
sd->preload_ok = false;
|
||||
}
|
||||
|
||||
if (no_ass)
|
||||
fill_plaintext(sd, pts);
|
||||
mp_ass_render_frame(renderer, track, ts, &ctx->parts, res);
|
||||
talloc_steal(ctx, ctx->parts);
|
||||
|
||||
ctx->part_cache.change_id = 0;
|
||||
ctx->part_cache.num_parts = 0;
|
||||
mp_ass_render_frame(renderer, track, ts, &ctx->part_cache);
|
||||
talloc_steal(ctx, ctx->part_cache.parts);
|
||||
|
||||
if (!converted)
|
||||
mangle_colors(sd, res);
|
||||
mangle_colors(sd, &ctx->part_cache);
|
||||
|
||||
*res = ctx->part_cache;
|
||||
}
|
||||
|
||||
struct buf {
|
||||
|
Loading…
Reference in New Issue
Block a user