Skip to content

Commit

Permalink
Merge pull request #15 from JustAMan/update-build
Browse files Browse the repository at this point in the history
Update to new Emscripten SDK, fix compat for ancient browsers
  • Loading branch information
JustAMan authored Apr 27, 2020
2 parents b380565 + 84bbb59 commit 58e9a3f
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 65 deletions.
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# NOTE: python3-distutils should not be needed when emsdk > 1.39.13 is used,
# so remove it when updating emsdk
FROM debian:buster
RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/force-unsafe-io
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -23,19 +25,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
autoconf \
m4 \
gperf \
wget && \
wget \
python3-distutils && \
rm -rf /var/lib/apt/lists/*

RUN pip install ply

RUN git clone https://github.com/emscripten-core/emsdk.git && \
cd emsdk && \
./emsdk install 1.39.11 && \
./emsdk activate 1.39.11

# Patch emscripten; needed until https://github.com/emscripten-core/emscripten/pull/10846 is merged and released
RUN wget https://raw.githubusercontent.com/emscripten-core/emscripten/d68250f1e6059168bd1f791921445527c7548e29/src/preamble.js -O /emsdk/upstream/emscripten/src/preamble.js && \
wget https://raw.githubusercontent.com/emscripten-core/emscripten/d68250f1e6059168bd1f791921445527c7548e29/src/URIUtils.js -O /emsdk/upstream/emscripten/src/URIUtils.js
./emsdk install 1.39.13 && \
./emsdk activate 1.39.13

ENV PATH=$PATH:/emsdk:/emsdk/upstream/emscripten:/emsdk/node/12.9.1_64bit/bin
WORKDIR /code
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
BASE_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
DIST_DIR:=$(BASE_DIR)dist/libraries

GLOBAL_CFLAGS:=-O3
GLOBAL_CFLAGS:=-O3 -s ENVIRONMENT=web,webview -s DOUBLE_MODE=0

all: subtitleoctopus

Expand Down Expand Up @@ -308,6 +308,8 @@ EMCC_COMMON_ARGS = \
--preload-file assets/fonts.conf \
-s ALLOW_MEMORY_GROWTH=1 \
-s FORCE_FILESYSTEM=1 \
-s ENVIRONMENT=web,webview \
-s DOUBLE_MODE=0 \
--llvm-lto 1 \
--no-heap-copy \
-o $@
Expand Down Expand Up @@ -335,6 +337,8 @@ dist/js/subtitles-octopus-worker-legacy.js: src/subtitles-octopus-worker.bc src/
--post-js src/post-worker.js \
-s WASM=0 \
-s LEGACY_VM_SUPPORT=1 \
-s MIN_CHROME_VERSION=27 \
-s MIN_SAFARI_VERSION=60005 \
$(EMCC_COMMON_ARGS)

dist/js/subtitles-octopus.js: src/subtitles-octopus.js
Expand Down
46 changes: 23 additions & 23 deletions dist/js/subtitles-octopus-worker-legacy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/subtitles-octopus-worker.js

Large diffs are not rendered by default.

Binary file modified dist/js/subtitles-octopus-worker.wasm
Binary file not shown.
15 changes: 9 additions & 6 deletions dist/js/subtitles-octopus.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ var SubtitlesOctopus = function (options) {
iteration: self.oneshotState.iteration
});
} else {
console.info('worker busy, requesting to seek');
if (self.workerActive) {
console.info('worker busy, requesting to seek');
}
self.oneshotState.requestNextTimestamp = lastRendered;
}
}
Expand Down Expand Up @@ -398,14 +400,15 @@ var SubtitlesOctopus = function (options) {

if (!eventShown) {
if (Math.abs(self.oneshotState.requestNextTimestamp - currentTime) > 0.01) {
_cleanPastRendered(currentTime);
tryRequestOneshot(currentTime, true);
}
} else if (_cleanPastRendered(currentTime) && finishTime >= 0) {
tryRequestOneshot(finishTime, animated);
}
}

function resetRenderAheadCache(isResizing) {
self.resetRenderAheadCache = function (isResizing) {
if (self.renderAhead > 0) {
var newCache = [];
if (isResizing && self.oneshotState.prevHeight && self.oneshotState.prevWidth) {
Expand Down Expand Up @@ -769,7 +772,7 @@ var SubtitlesOctopus = function (options) {
width: self.canvas.width,
height: self.canvas.height
});
resetRenderAheadCache(true);
self.resetRenderAheadCache(true);
}
};

Expand Down Expand Up @@ -805,22 +808,22 @@ var SubtitlesOctopus = function (options) {
target: 'set-track-by-url',
url: url
});
resetRenderAheadCache(false);
self.resetRenderAheadCache(false);
};

self.setTrack = function (content) {
self.worker.postMessage({
target: 'set-track',
content: content
});
resetRenderAheadCache(false);
self.resetRenderAheadCache(false);
};

self.freeTrack = function (content) {
self.worker.postMessage({
target: 'free-track'
});
resetRenderAheadCache(false);
self.resetRenderAheadCache(false);
};


Expand Down
33 changes: 12 additions & 21 deletions src/post-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ function messageResender() {
}
}

function _applyKeys(input, output) {
var vargs = Object.keys(input);

for (var i = 0; i < vargs.length; i++) {
output[vargs[i]] = input[vargs[i]];
}
}

function onMessageFromMainEmscriptenThread(message) {
if (!calledMain && !message.data.preMain) {
if (!messageBuffer) {
Expand Down Expand Up @@ -628,11 +636,7 @@ function onMessageFromMainEmscriptenThread(message) {
var event = message.data.event;
var i = self.octObj.allocEvent();
var evnt_ptr = self.octObj.track.get_events(i);
var vargs = Object.keys(event);

for (const varg of vargs) {
evnt_ptr[varg] = event[varg];
}
_applyKeys(event, evnt_ptr);
break;
case 'get-events':
var events = [];
Expand Down Expand Up @@ -664,12 +668,7 @@ function onMessageFromMainEmscriptenThread(message) {
var event = message.data.event;
var i = message.data.index;
var evnt_ptr = self.octObj.track.get_events(i);

var vargs = Object.keys(event);

for (const varg of vargs) {
evnt_ptr[varg] = event[varg];
}
_applyKeys(event, evnt_ptr);
break;
case 'remove-event':
var i = message.data.index;
Expand All @@ -679,11 +678,7 @@ function onMessageFromMainEmscriptenThread(message) {
var style = message.data.style;
var i = self.octObj.allocStyle();
var styl_ptr = self.octObj.track.get_styles(i);
var vargs = Object.keys(style);

for (const varg of vargs) {
styl_ptr[varg] = style[varg];
}
_applyKeys(style, styl_ptr);
break;
case 'get-styles':
var styles = [];
Expand Down Expand Up @@ -729,11 +724,7 @@ function onMessageFromMainEmscriptenThread(message) {
var style = message.data.style;
var i = message.data.index;
var styl_ptr = self.octObj.track.get_styles(i);
var vargs = Object.keys(style);

for (const varg of vargs) {
styl_ptr[varg] = style[varg];
}
_applyKeys(style, styl_ptr);
break;
case 'remove-style':
var i = message.data.index;
Expand Down
10 changes: 10 additions & 0 deletions src/pre-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ if (!String.prototype.endsWith) {
};
}

if (!Uint8Array.prototype.slice) {
Object.defineProperty(Uint8Array.prototype, 'slice', {
value: function (begin, end)
{
return new Uint8Array(this.subarray(begin, end));
}
});
}


var hasNativeConsole = typeof console !== "undefined";

// implement console methods if they're missing
Expand Down
15 changes: 9 additions & 6 deletions src/subtitles-octopus.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ var SubtitlesOctopus = function (options) {
iteration: self.oneshotState.iteration
});
} else {
console.info('worker busy, requesting to seek');
if (self.workerActive) {
console.info('worker busy, requesting to seek');
}
self.oneshotState.requestNextTimestamp = lastRendered;
}
}
Expand Down Expand Up @@ -398,14 +400,15 @@ var SubtitlesOctopus = function (options) {

if (!eventShown) {
if (Math.abs(self.oneshotState.requestNextTimestamp - currentTime) > 0.01) {
_cleanPastRendered(currentTime);
tryRequestOneshot(currentTime, true);
}
} else if (_cleanPastRendered(currentTime) && finishTime >= 0) {
tryRequestOneshot(finishTime, animated);
}
}

function resetRenderAheadCache(isResizing) {
self.resetRenderAheadCache = function (isResizing) {
if (self.renderAhead > 0) {
var newCache = [];
if (isResizing && self.oneshotState.prevHeight && self.oneshotState.prevWidth) {
Expand Down Expand Up @@ -769,7 +772,7 @@ var SubtitlesOctopus = function (options) {
width: self.canvas.width,
height: self.canvas.height
});
resetRenderAheadCache(true);
self.resetRenderAheadCache(true);
}
};

Expand Down Expand Up @@ -805,22 +808,22 @@ var SubtitlesOctopus = function (options) {
target: 'set-track-by-url',
url: url
});
resetRenderAheadCache(false);
self.resetRenderAheadCache(false);
};

self.setTrack = function (content) {
self.worker.postMessage({
target: 'set-track',
content: content
});
resetRenderAheadCache(false);
self.resetRenderAheadCache(false);
};

self.freeTrack = function (content) {
self.worker.postMessage({
target: 'free-track'
});
resetRenderAheadCache(false);
self.resetRenderAheadCache(false);
};


Expand Down

0 comments on commit 58e9a3f

Please sign in to comment.