diff options
author | wm4 <wm4@nowhere> | 2015-12-05 23:54:00 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-12-05 23:54:00 +0100 |
commit | a2e7642d3c8cf20c339a38595212070d2339a2cc (patch) | |
tree | f7f3726dbc187814d080564eadfb78bba786214e /sub/dec_sub.c | |
parent | 565efeeadaf1de5f8f64aa31cbc56e31748fb0b2 (diff) | |
download | mpv-a2e7642d3c8cf20c339a38595212070d2339a2cc.tar.bz2 mpv-a2e7642d3c8cf20c339a38595212070d2339a2cc.tar.xz |
sub: allow feeding bitmap subs in advance
Until now, feeding packets to the decoder in advance was done for text
subtitles only. This was possible because libass buffers all subtitle
data anyway (in ASS_Track). sd_lavc, responsible for bitmap subs, does
not do this. But it can buffer a small number of subtitle frames ahead.
Enable this.
Repurpose the sub_accept_packets_in_advance(). Instead of "can take all
packets" it means "can take 1 packet" now. (The old meaning is still
needed locally in dec_sub.c; keep it there.) It asks the decoder whether
there is place for at least 1 subtitle packet. sd_lavc implements it and
returns true if its internal fixed-size subtitle queue still has a free
slot. (The implementation of this in dec_sub.c isn't entirely clean.
For one, decode_chain() ignores this mechanism, so it's implied that
bitmap subtitles do not use the subtitle filter chain in any advanced
way.)
Also fix 2 bugs in the sd_lavc queue handling. Subtitles must be checked
in reverse, because the first entry will often have endpts==NOPTS, which
would always match. alloc_sub() must cycle the queue buffer, because it
reuses memory allocations (like sub.imgs) by design.
Diffstat (limited to 'sub/dec_sub.c')
-rw-r--r-- | sub/dec_sub.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sub/dec_sub.c b/sub/dec_sub.c index c357f1d369..9261e2570d 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -415,7 +415,9 @@ bool sub_read_all_packets(struct dec_sub *sub, struct sh_stream *sh) pthread_mutex_lock(&sub->lock); - if (!sub_accept_packets_in_advance(sub) || sub->num_sd < 1) { + // Converters are assumed to always accept packets in advance + struct sd *sd = sub_get_last_sd(sub); + if (!(sd && sd->driver->accept_packets_in_advance)) { pthread_mutex_unlock(&sub->lock); return false; } @@ -486,14 +488,16 @@ bool sub_read_all_packets(struct dec_sub *sub, struct sh_stream *sh) return true; } -bool sub_accept_packets_in_advance(struct dec_sub *sub) +bool sub_accepts_packet_in_advance(struct dec_sub *sub) { + bool res = true; pthread_mutex_lock(&sub->lock); - // Converters are assumed to always accept packets in advance - struct sd *sd = sub_get_last_sd(sub); - bool r = sd && sd->driver->accept_packets_in_advance; + for (int n = 0; n < sub->num_sd; n++) { + if (sub->sd[n]->driver->accepts_packet) + res &= sub->sd[n]->driver->accepts_packet(sub->sd[n]); + } pthread_mutex_unlock(&sub->lock); - return r; + return res; } // You must call sub_lock/sub_unlock if more than 1 thread access sub. |