Skip to content

Commit 030aaa8

Browse files
committed
Allow setting glyph limit separately
Allow resetting libass limits to defaults
1 parent 49d86ec commit 030aaa8

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ src/subtitles-octopus-worker.bc: dist/libraries/lib/libass.a src/Makefile src/su
293293
# Dist Files
294294
EMCC_COMMON_ARGS = \
295295
$(GLOBAL_CFLAGS) \
296-
-s EXPORTED_FUNCTIONS="['_main', '_malloc', '_libassjs_render_blend', '_libassjs_set_memory_limit']" \
296+
-s EXPORTED_FUNCTIONS="['_main', '_malloc', '_libassjs_render_blend', '_libassjs_set_memory_limits']" \
297297
-s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'getValue', 'FS_createPreloadedFile', 'FS_createFolder']" \
298298
-s NO_EXIT_RUNTIME=1 \
299299
--use-preload-plugins \

src/SubtitleOctopus.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,10 @@ class SubtitleOctopus {
212212
}
213213
};
214214

215-
void libassjs_set_memory_limit(int limit) {
216-
if (limit > 0) {
217-
printf("libass: setting total libass memory limit to %d MiB\n", limit);
218-
ass_set_cache_limits(ass_renderer, 0, limit);
219-
}
215+
void libassjs_set_memory_limits(int glyph_limit, int bitmap_cache_limit) {
216+
printf("libass: setting total libass memory limits to: glyph=%d MiB, bitmap cache=%d MiB\n",
217+
glyph_limit, bitmap_cache_limit);
218+
ass_set_cache_limits(ass_renderer, glyph_limit, bitmap_cache_limit);
220219
}
221220

222221
const float MIN_UINT8_CAST = 0.9 / 255;

src/post-worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ function onMessageFromMainEmscriptenThread(message) {
550550
}
551551
self.targetFps = message.data.targetFps || self.targetFps;
552552
self.libassMemoryLimit = message.data.libassMemoryLimit || self.libassMemoryLimit;
553+
self.libassGlyphLimit = message.data.libassGlyphLimit || 0;
553554
removeRunDependency('worker-init');
554555
break;
555556
}

src/pre-worker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Module['onRuntimeInitialized'] = function () {
9393
self.octObj = new Module.SubtitleOctopus();
9494

9595
self._render_blend = Module['cwrap']('libassjs_render_blend', null, ['number', 'number', 'number', 'number', 'number', 'number', 'number', 'number']);
96-
self._set_memory_limit = Module['cwrap']('libassjs_set_memory_limit', null, ['number']);
96+
self._set_memory_limits = Module['cwrap']('libassjs_set_memory_limits', null, ['number', 'number']);
9797

9898
self.changed = Module._malloc(4);
9999

@@ -108,8 +108,8 @@ Module['onRuntimeInitialized'] = function () {
108108
self.ass_track = self.octObj.track;
109109
self.ass_library = self.octObj.ass_library;
110110
self.ass_renderer = self.octObj.ass_renderer;
111-
if (self.libassMemoryLimit > 0) {
112-
self._set_memory_limit(self.libassMemoryLimit);
111+
if (self.libassMemoryLimit > 0 || self.libassGlyphLimit > 0) {
112+
self._set_memory_limits(self.libassGlyphLimit, self.libassMemoryLimit);
113113
}
114114
};
115115

src/subtitles-octopus.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var SubtitlesOctopus = function (options) {
1515
self.canvas = options.canvas; // HTML canvas element (optional if video specified)
1616
self.renderMode = options.lossyRender ? 'fast' : (options.blendRender ? 'blend' : 'normal');
1717
self.libassMemoryLimit = options.libassMemoryLimit || 0;
18+
self.libassGlyphLimit = options.libassGlyphLimit || 0;
1819
self.targetFps = options.targetFps || undefined;
1920
self.isOurCanvas = false; // (internal) we created canvas and manage it
2021
self.video = options.video; // HTML video element (optional if canvas specified)
@@ -108,7 +109,8 @@ var SubtitlesOctopus = function (options) {
108109
availableFonts: self.availableFonts,
109110
debug: self.debug,
110111
targetFps: self.targetFps,
111-
libassMemoryLimit: self.libassMemoryLimit
112+
libassMemoryLimit: self.libassMemoryLimit,
113+
libassGlyphLimit: self.libassGlyphLimit
112114
});
113115
};
114116

0 commit comments

Comments
 (0)