summaryrefslogtreecommitdiffstats
path: root/subreader.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2010-01-16 12:30:34 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-01-16 12:44:00 +0200
commit6ead3e936b8344d13c56567142d95cff0d4d8c90 (patch)
tree6e467794305e07401e1332221f09833fab7a0ff2 /subreader.c
parentc5bd47f54380b55a9fefe1e922a64a3a96b773ac (diff)
downloadmpv-6ead3e936b8344d13c56567142d95cff0d4d8c90.tar.bz2
mpv-6ead3e936b8344d13c56567142d95cff0d4d8c90.tar.xz
subreader.c: fix excessive memory use with some external subtitles
For each sequence of consecutive partially overlapping subtitles, the algorithm calculating screen positions for the subtitles allocated a 2*subtitle_count*subtitle_line_count array. With some karaoke subtitles that had lots of rapidly changing overlapping subtitles this became large enough to use gigabytes of memory. Make the behavior saner by limiting the line count to SUB_MAX_TEXT lines (the maximum number of lines to show on screen at once, currently 12). This shouldn't change the end result of the algorithm other than possibly printing different warnings.
Diffstat (limited to 'subreader.c')
-rw-r--r--subreader.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/subreader.c b/subreader.c
index 0776ea2b17..f1b5b44f5e 100644
--- a/subreader.c
+++ b/subreader.c
@@ -1526,6 +1526,11 @@ if ((suboverlap_enabled == 2) ||
}
}
+ /* Avoid n^2 memory use for the "placeholder" data structure
+ * below with subtitles that have a huge number of
+ * consecutive overlapping lines. */
+ lines_to_add = FFMIN(lines_to_add, SUB_MAX_TEXT);
+
// we need a structure to keep trace of the screen lines
// used by the subs, a 'placeholder'
counter = 2 * sub_to_add + 1; // the maximum number of subs derived