summaryrefslogtreecommitdiffstats
path: root/sub/dec_sub.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/dec_sub.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/dec_sub.c')
-rw-r--r--sub/dec_sub.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/sub/dec_sub.c b/sub/dec_sub.c
index 3842235c46..76e96bc16b 100644
--- a/sub/dec_sub.c
+++ b/sub/dec_sub.c
@@ -109,16 +109,6 @@ static double pts_from_subtitle(struct dec_sub *sub, double pts)
return pts;
}
-void sub_lock(struct dec_sub *sub)
-{
- pthread_mutex_lock(&sub->lock);
-}
-
-void sub_unlock(struct dec_sub *sub)
-{
- pthread_mutex_unlock(&sub->lock);
-}
-
static void wakeup_demux(void *ctx)
{
struct mp_dispatch_queue *q = ctx;
@@ -335,12 +325,12 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts)
return r;
}
-// 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, int format,
- double pts, struct sub_bitmaps *res)
+// Unref sub_bitmaps.rc to free the result. May return NULL.
+struct sub_bitmaps *sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim,
+ int format, double pts)
{
+ pthread_mutex_lock(&sub->lock);
+
struct mp_subtitle_opts *opts = sub->opts;
pts = pts_to_subtitle(sub, pts);
@@ -348,11 +338,14 @@ void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, int format,
sub->last_vo_pts = pts;
update_segment(sub);
- if (sub->end != MP_NOPTS_VALUE && pts >= sub->end)
- return;
+ struct sub_bitmaps *res = NULL;
- if (opts->sub_visibility && sub->sd->driver->get_bitmaps)
- sub->sd->driver->get_bitmaps(sub->sd, dim, format, pts, res);
+ if (!(sub->end != MP_NOPTS_VALUE && pts >= sub->end) &&
+ opts->sub_visibility && sub->sd->driver->get_bitmaps)
+ res = sub->sd->driver->get_bitmaps(sub->sd, dim, format, pts);
+
+ pthread_mutex_unlock(&sub->lock);
+ return res;
}
// See sub_get_bitmaps() for locking requirements.