summaryrefslogtreecommitdiffstats
path: root/sub/sd_lavc.c
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2024-01-21 17:14:39 -0600
committerDudemanguy <random342@airmail.cc>2024-02-15 16:43:11 +0000
commit8f043de961f5b57c60e61e49b1841ad20faa64fe (patch)
tree69c4510a26174548181db3226328a06b0ba65a3a /sub/sd_lavc.c
parent0a4b098c616bf1b6700bc88878b028bf1f446868 (diff)
downloadmpv-8f043de961f5b57c60e61e49b1841ad20faa64fe.tar.bz2
mpv-8f043de961f5b57c60e61e49b1841ad20faa64fe.tar.xz
player/sub: avoid wasteful subtitle redraws
This only affects two special cases: printing subtitles to the terminal and printing subtitles on a still picture. Previously, mpv was very dumb here and spammed this logic on every single loop. For terminal subtitles, this isn't as big of a deal, but for the image case this is pretty bad. The entire VO constantly redrew even when there was no need to which can be very expensive depending on user settings. Instead, let's rework sub_read_packets so that it also tells us whether or not the subtitle packets update in some way in addition to telling us whether or not to read more. Since we cache all packets thanks to the previous commit, we can leverage this information to make a guess whether or not the current subtitle packet is supposed to be visible on the screen. Because the redraw now only happens when it is needed, the mp_set_timeout_hack can be removed.
Diffstat (limited to 'sub/sd_lavc.c')
-rw-r--r--sub/sd_lavc.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index 1bb1c96c2b..cf49f2d8f1 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -327,6 +327,8 @@ static void decode(struct sd *sd, struct demux_packet *packet)
if (res < 0 || !got_sub)
return;
+ packet->sub_duration = sub.end_display_time;
+
if (sub.pts != AV_NOPTS_VALUE)
pts = sub.pts / (double)AV_TIME_BASE;