Skip to content

Commit

Permalink
refined threading toggle in wasm demo for local builds
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Apr 17, 2024
1 parent 90db7d9 commit 84c56db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
42 changes: 22 additions & 20 deletions share/emscripten/gpac.html
Expand Up @@ -483,7 +483,10 @@ <h4>Performances</h4>
let fs_steps = 20;
let FS = null;

const STATIC_SRC = `${window.location.origin}/data`;
let STATIC_SRC;
if (window.location.origin.indexOf('.gpac.io')>0) STATIC_SRC = `${window.location.origin}/data`;
else if (window.location.origin.startsWith('http://')) STATIC_SRC = 'http://wasm.gpac.io/data';
else STATIC_SRC = 'https://wasm.gpac.io/data';

const examples = [
{
Expand Down Expand Up @@ -528,14 +531,6 @@ <h4>Performances</h4>
setCommand(item.cmd.trim());
};

async function toggle_threading() {
if (LIBGPAC.has_threads()){

}
// if GPAC is running, abort
// unload current GPAC
}

function setCommand(value) {
cmdElement.value = value == '' ? null : value;
};
Expand Down Expand Up @@ -2373,6 +2368,23 @@ <h4>Performances</h4>
}
}

function check_threading() {
const threaded = LIBGPAC.has_threads;
const threadedOnly = [...document.getElementsByClassName('threaded')];
threadedOnly.forEach(el => el.hidden = !threaded);
const thStatus = document.getElementById('threading_status');

threadingElement.checked = threaded;
if (window.location.href.indexOf('.gpac.io')<0) {
threadingElement.disabled = true;
} else {
threadingElement.onchange = () => {
const hostname = threaded ? 'wasm.gpac.io' : 'wasmth.gpac.io';
window.location.href = `https://${hostname}/`;
console.log('Reloading to ' + window.location.href);
}
}
}
const LIBGPAC = {
preRun: [
// function() { LIBGPAC.ENV.SDL_EMSCRIPTEN_KEYBOARD_ELEMENT = "#canvas"; }
Expand Down Expand Up @@ -2481,6 +2493,7 @@ <h4>Performances</h4>
load_history();
}
});
check_threading();

onGpacReady();
},
Expand Down Expand Up @@ -2549,17 +2562,6 @@ <h4>Performances</h4>
libgpac(LIBGPAC);

});
document.addEventListener('readystatechange', function() {
const threaded = window.location.hostname == 'wasmth.gpac.io';
const threadedOnly = [...document.getElementsByClassName('threaded')];
threadedOnly.forEach(el => el.hidden = !threaded);
threadingElement.checked = threaded;
threadingElement.onchange = () => {
const hostname = threaded ? 'wasm.gpac.io' : 'wasmth.gpac.io';
window.location.href = `https://${hostname}/`;
console.log(hostname);
}
});
</script>

</body>
Expand Down
12 changes: 7 additions & 5 deletions src/utils/os_config_init.c
Expand Up @@ -1382,15 +1382,17 @@ GF_Err gf_opts_save()

#include <gpac/main.h>

#ifdef GPAC_CONFIG_EMSCRIPTEN
#define LOGFILE_HELP "set output log file - use `console` for browser console"
#else
#define LOGFILE_HELP "set output log file"
#endif

GF_GPACArg GPAC_Args[] = {
GF_DEF_ARG("tmp", NULL, "specify directory for temporary file creation instead of OS-default temporary file management", NULL, NULL, GF_ARG_STRING, 0),
GF_DEF_ARG("noprog", NULL, "disable progress messages", NULL, NULL, GF_ARG_BOOL, GF_ARG_HINT_ADVANCED|GF_ARG_SUBSYS_LOG),
GF_DEF_ARG("quiet", NULL, "disable all messages, including errors", NULL, NULL, GF_ARG_BOOL, GF_ARG_HINT_ADVANCED|GF_ARG_SUBSYS_LOG),
GF_DEF_ARG("log-file", "lf", "set output log file"
#ifdef GPAC_CONFIG_EMSCRIPTEN
" - use `console` for browser console log"
#endif
, NULL, NULL, GF_ARG_STRING, GF_ARG_SUBSYS_LOG),
GF_DEF_ARG("log-file", "lf", LOGFILE_HELP, NULL, NULL, GF_ARG_STRING, GF_ARG_SUBSYS_LOG),
GF_DEF_ARG("log-clock", "lc", "log time in micro sec since start time of GPAC before each log line except for `app` tool", NULL, NULL, GF_ARG_BOOL, GF_ARG_SUBSYS_LOG),
GF_DEF_ARG("log-utc", "lu", "log UTC time in ms before each log line except for `app` tool", NULL, NULL, GF_ARG_BOOL, GF_ARG_SUBSYS_LOG),
GF_DEF_ARG("logs", NULL, "set log tools and levels. \n"
Expand Down

0 comments on commit 84c56db

Please sign in to comment.