Compare commits

..

3 Commits

Author SHA1 Message Date
Ingvar Stepanyan
760dd9e8a0 Update avif_enc_mt.js 2021-03-04 13:15:10 +00:00
Ingvar Stepanyan
f1a9235de2 Update avif_enc_mt.js 2021-03-04 13:12:17 +00:00
Ingvar Stepanyan
e66c292e86 [temp] Warn on unavailable worker 2021-03-03 16:55:09 +00:00
11 changed files with 3180 additions and 320 deletions

View File

@@ -1,16 +1,13 @@
CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/31d7c6d1e32cf467ac24fb8c7a76c4902a4c00db.tar.gz CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/v0.9.0.tar.gz
CODEC_PACKAGE = node_modules/libavif.tar.gz CODEC_PACKAGE = node_modules/libavif.tar.gz
LIBAOM_URL = https://aomedia.googlesource.com/aom/+archive/4a8e276e3e0ef3c76083f3975d5caa85bc9593ce.tar.gz LIBAOM_URL = https://aomedia.googlesource.com/aom/+archive/v2.0.2.tar.gz
LIBAOM_PACKAGE = node_modules/libaom.tar.gz LIBAOM_PACKAGE = node_modules/libaom.tar.gz
export CODEC_DIR = node_modules/libavif export CODEC_DIR = node_modules/libavif
export BUILD_DIR = node_modules/build export BUILD_DIR = node_modules/build
export LIBAOM_DIR = node_modules/libaom export LIBAOM_DIR = node_modules/libaom
export CFLAGS += -g
export CXXFLAGS += -g
OUT_ENC_JS = enc/avif_enc.js OUT_ENC_JS = enc/avif_enc.js
OUT_NODE_ENC_JS = enc/avif_node_enc.js OUT_NODE_ENC_JS = enc/avif_node_enc.js
OUT_ENC_MT_JS = enc/avif_enc_mt.js OUT_ENC_MT_JS = enc/avif_enc_mt.js
@@ -24,6 +21,10 @@ ENVIRONMENT = worker
HELPER_MAKEFLAGS := -f helper.Makefile HELPER_MAKEFLAGS := -f helper.Makefile
export CFLAGS+=-g
export CXXFLAGS+=-g
export LDFLAGS+=-g
.PHONY: all clean .PHONY: all clean
all: $(OUT_ENC_JS) $(OUT_DEC_JS) $(OUT_ENC_MT_JS) $(OUT_NODE_ENC_JS) $(OUT_NODE_DEC_JS) all: $(OUT_ENC_JS) $(OUT_DEC_JS) $(OUT_ENC_MT_JS) $(OUT_NODE_ENC_JS) $(OUT_NODE_DEC_JS)
@@ -53,7 +54,7 @@ $(OUT_ENC_MT_JS): $(OUT_ENC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMake
" \ " \
ENVIRONMENT=$(ENVIRONMENT) \ ENVIRONMENT=$(ENVIRONMENT) \
LIBAVIF_FLAGS="-DAVIF_CODEC_AOM_DECODE=0" \ LIBAVIF_FLAGS="-DAVIF_CODEC_AOM_DECODE=0" \
OUT_FLAGS="-pthread -s PROXY_TO_PTHREAD=1 -g" OUT_FLAGS="-pthread"
$(OUT_NODE_DEC_JS): ENVIRONMENT=node $(OUT_NODE_DEC_JS): ENVIRONMENT=node
$(OUT_NODE_DEC_JS) $(OUT_DEC_JS): $(OUT_DEC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt $(OUT_NODE_DEC_JS) $(OUT_DEC_JS): $(OUT_DEC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -16,6 +16,10 @@ var initializedJS = false; // Guard variable for one-time init of the JS state (
var Module = {}; var Module = {};
function assert(condition, text) {
if (!condition) abort('Assertion failed: ' + text);
}
function threadPrintErr() { function threadPrintErr() {
var text = Array.prototype.slice.call(arguments).join(' '); var text = Array.prototype.slice.call(arguments).join(' ');
console.error(text); console.error(text);
@@ -24,6 +28,12 @@ function threadAlert() {
var text = Array.prototype.slice.call(arguments).join(' '); var text = Array.prototype.slice.call(arguments).join(' ');
postMessage({cmd: 'alert', text: text, threadId: selfThreadId}); postMessage({cmd: 'alert', text: text, threadId: selfThreadId});
} }
// We don't need out() for now, but may need to add it if we want to use it
// here. Or, if this code all moves into the main JS, that problem will go
// away. (For now, adding it here increases code size for no benefit.)
var out = function() {
throw 'out() is not defined in worker.js.';
}
var err = threadPrintErr; var err = threadPrintErr;
this.alert = threadAlert; this.alert = threadAlert;
@@ -81,9 +91,16 @@ this.onmessage = function(e) {
// The stack grows downwards // The stack grows downwards
var max = e.data.stackBase; var max = e.data.stackBase;
var top = e.data.stackBase + e.data.stackSize; var top = e.data.stackBase + e.data.stackSize;
assert(threadInfoStruct);
assert(selfThreadId);
assert(parentThreadId);
assert(top != 0);
assert(max != 0);
assert(top > max);
// Also call inside JS module to set up the stack frame for this pthread in JS module scope // Also call inside JS module to set up the stack frame for this pthread in JS module scope
Module['establishStackSpace'](top, max); Module['establishStackSpace'](top, max);
Module['_emscripten_tls_init'](); Module['_emscripten_tls_init']();
Module['writeStackCookie']();
Module['PThread'].receiveObjectTransfer(e.data); Module['PThread'].receiveObjectTransfer(e.data);
Module['PThread'].setThreadStatus(Module['_pthread_self'](), 1/*EM_THREAD_STATUS_RUNNING*/); Module['PThread'].setThreadStatus(Module['_pthread_self'](), 1/*EM_THREAD_STATUS_RUNNING*/);
@@ -105,6 +122,7 @@ this.onmessage = function(e) {
// flag -s EMULATE_FUNCTION_POINTER_CASTS=1 to add in emulation for this x86 ABI extension. // flag -s EMULATE_FUNCTION_POINTER_CASTS=1 to add in emulation for this x86 ABI extension.
var result = Module['dynCall']('ii', e.data.start_routine, [e.data.arg]); var result = Module['dynCall']('ii', e.data.start_routine, [e.data.arg]);
Module['checkStackCookie']();
// The thread might have finished without calling pthread_exit(). If so, then perform the exit operation ourselves. // The thread might have finished without calling pthread_exit(). If so, then perform the exit operation ourselves.
// (This is a no-op if explicit pthread_exit() had been called prior.) // (This is a no-op if explicit pthread_exit() had been called prior.)
if (!Module['getNoExitRuntime']()) if (!Module['getNoExitRuntime']())
@@ -116,8 +134,15 @@ this.onmessage = function(e) {
Atomics.store(Module['HEAPU32'], (threadInfoStruct + 4 /*C_STRUCTS.pthread.threadExitCode*/ ) >> 2, (ex instanceof Module['ExitStatus']) ? ex.status : -2 /*A custom entry specific to Emscripten denoting that the thread crashed.*/); Atomics.store(Module['HEAPU32'], (threadInfoStruct + 4 /*C_STRUCTS.pthread.threadExitCode*/ ) >> 2, (ex instanceof Module['ExitStatus']) ? ex.status : -2 /*A custom entry specific to Emscripten denoting that the thread crashed.*/);
Atomics.store(Module['HEAPU32'], (threadInfoStruct + 0 /*C_STRUCTS.pthread.threadStatus*/ ) >> 2, 1); // Mark the thread as no longer running. Atomics.store(Module['HEAPU32'], (threadInfoStruct + 0 /*C_STRUCTS.pthread.threadStatus*/ ) >> 2, 1); // Mark the thread as no longer running.
if (typeof(Module['_emscripten_futex_wake']) !== "function") {
err("Thread Initialisation failed.");
throw ex;
}
Module['_emscripten_futex_wake'](threadInfoStruct + 0 /*C_STRUCTS.pthread.threadStatus*/, 0x7FFFFFFF/*INT_MAX*/); // Wake all threads waiting on this thread to finish. Module['_emscripten_futex_wake'](threadInfoStruct + 0 /*C_STRUCTS.pthread.threadStatus*/, 0x7FFFFFFF/*INT_MAX*/); // Wake all threads waiting on this thread to finish.
if (!(ex instanceof Module['ExitStatus'])) throw ex; if (!(ex instanceof Module['ExitStatus'])) throw ex;
} else {
// else e == 'unwind', and we should fall through here and keep the pthread alive for asynchronous events.
err('Pthread 0x' + threadInfoStruct.toString(16) + ' completed its pthread main entry point with an unwind, keeping the pthread worker alive for asynchronous operation.');
} }
} }
} else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread. } else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread.

View File

@@ -961,9 +961,9 @@ function updateGlobalBufferAndViews(buf) {
Module['HEAPF64'] = HEAPF64 = new Float64Array(buf); Module['HEAPF64'] = HEAPF64 = new Float64Array(buf);
} }
var STACK_BASE = 6122000, var STACK_BASE = 6122064,
STACKTOP = STACK_BASE, STACKTOP = STACK_BASE,
STACK_MAX = 879120; STACK_MAX = 879184;
var TOTAL_STACK = 5242880; var TOTAL_STACK = 5242880;

Binary file not shown.