Skip to content

Commit 87a7249

Browse files
JustAMandmitrylyzo
authored andcommitted
Add option to control how much size may vary until the prerender cache is cleared
Cherry-picked from: jellyfin@5256b63
1 parent a602fd7 commit 87a7249

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/subtitles-octopus.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var SubtitlesOctopus = function (options) {
2323
self.prescaleTradeoff = options.prescaleTradeoff || null; // render subtitles less than viewport when less than 1.0 to improve speed, render to more than 1.0 to improve quality; set to null to disable scaling
2424
self.softHeightLimit = options.softHeightLimit || 1080; // don't apply prescaleTradeoff < 1 when viewport height is less that this limit
2525
self.hardHeightLimit = options.hardHeightLimit || 2160; // don't ever go above this limit
26+
self.resizeVariation = options.resizeVariation || 0.2; // by how many a size can vary before it would cause clearance of prerendered buffer
2627

2728
self.renderAhead = options.renderAhead || 0; // how many MiB to render ahead and store; 0 to disable (approximate)
2829
self.isOurCanvas = false; // (internal) we created canvas and manage it
@@ -400,10 +401,10 @@ var SubtitlesOctopus = function (options) {
400401
function resetRenderAheadCache() {
401402
if (self.renderAhead > 0) {
402403
if (self.oneshotState.prevHeight && self.oneshotState.prevWidth) {
403-
if (self.canvas.height >= self.oneshotState.prevHeight * 0.8 &&
404-
self.canvas.height <= self.oneshotState.prevHeight * 1.2 &&
405-
self.canvas.width >= self.oneshotState.prevWidth * 0.8 &&
406-
self.canvas.width <= self.oneshotState.prevWidth * 1.2) {
404+
if (self.canvas.height >= self.oneshotState.prevHeight * (1.0 - self.resizeVariation) &&
405+
self.canvas.height <= self.oneshotState.prevHeight * (1.0 + self.resizeVariation) &&
406+
self.canvas.width >= self.oneshotState.prevWidth * (1.0 - self.resizeVariation) &&
407+
self.canvas.width <= self.oneshotState.prevWidth * (1.0 + self.resizeVariation)) {
407408
console.debug('not resetting prerender cache - keep using current');
408409
// keep rendering canvas size the same,
409410
// otherwise subtitles got placed incorrectly

0 commit comments

Comments
 (0)