summaryrefslogtreecommitdiffstats
path: root/sub/sd_ass.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-04-26 23:34:32 +0200
committerwm4 <wm4@nowhere>2020-04-26 23:34:32 +0200
commite9e883e3b2a64867aae014fb8a1416d0177fe493 (patch)
tree429e0cf14f9177f6488647967bb858338b201563 /sub/sd_ass.c
parent640db1ed3fa0f15763439ae331d78d88cd932ee5 (diff)
downloadmpv-e9e883e3b2a64867aae014fb8a1416d0177fe493.tar.bz2
mpv-e9e883e3b2a64867aae014fb8a1416d0177fe493.tar.xz
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.
Diffstat (limited to 'sub/sd_ass.c')
-rw-r--r--sub/sd_ass.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/sub/sd_ass.c b/sub/sd_ass.c
index 40e5093d8e..d51f892dd4 100644
--- a/sub/sd_ass.c
+++ b/sub/sd_ass.c
@@ -50,7 +50,7 @@ struct sd_ass_priv {
bool clear_once;
bool on_top;
struct mp_ass_packer *packer;
- struct sub_bitmap *bs;
+ struct sub_bitmap_copy_cache *copy_cache;
char last_text[500];
struct mp_image_params video_params;
struct mp_image_params last_params;
@@ -498,8 +498,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, int format,
- double pts, struct sub_bitmaps *res)
+static struct sub_bitmaps *get_bitmaps(struct sd *sd, struct mp_osd_res dim,
+ int format, double pts)
{
struct sd_ass_priv *ctx = sd->priv;
struct mp_subtitle_opts *opts = sd->opts;
@@ -508,9 +508,10 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, int format,
bool converted = ctx->is_converted || no_ass;
ASS_Track *track = no_ass ? ctx->shadow_track : ctx->ass_track;
ASS_Renderer *renderer = ctx->ass_renderer;
+ struct sub_bitmaps *res = &(struct sub_bitmaps){0};
if (pts == MP_NOPTS_VALUE || !renderer)
- return;
+ goto done;
double scale = dim.display_par;
if (!converted && (!opts->ass_style_override ||
@@ -544,14 +545,14 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, int format,
ASS_Image *imgs = ass_render_frame(renderer, track, ts, &changed);
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.
- MP_TARRAY_GROW(ctx, ctx->bs, res->num_parts);
- memcpy(ctx->bs, res->parts, sizeof(ctx->bs[0]) * res->num_parts);
- res->parts = ctx->bs;
+done:
+ // mangle_colors() modifies the color field, so copy the thing _before_.
+ res = sub_bitmaps_copy(&ctx->copy_cache, res);
+ if (!converted && res)
mangle_colors(sd, res);
- }
+
+ return res;
}
struct buf {
@@ -752,6 +753,7 @@ static void uninit(struct sd *sd)
ass_free_track(ctx->shadow_track);
enable_output(sd, false);
ass_library_done(ctx->ass_library);
+ talloc_free(ctx->copy_cache);
}
static int control(struct sd *sd, enum sd_ctrl cmd, void *arg)