Reorg folders and use core as ffmpeg from now on

This commit is contained in:
Jerome Wu
2022-09-22 13:06:44 +08:00
parent 4f03229810
commit 20790e4fd2
138 changed files with 10505 additions and 1223 deletions

15
src/bind/.eslintrc.cjs Normal file
View File

@@ -0,0 +1,15 @@
module.exports = {
extends: "eslint:recommended",
rules: {
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-unsafe-assignment": 0,
"@typescript-eslint/restrict-plus-operands": 0,
"@typescript-eslint/no-unsafe-call": 0,
"@typescript-eslint/no-unsafe-return": 0,
"@typescript-eslint/no-unsafe-member-access": 0,
},
globals: {
Module: true,
console: true,
},
};

View File

View File

@@ -1,3 +0,0 @@
const EXPORTED_FUNCTIONS = ["_ffmpeg"];
console.log(EXPORTED_FUNCTIONS.join(","));

96
src/bind/ffmpeg/bind.js Normal file
View File

@@ -0,0 +1,96 @@
/**
* Constants
*/
const NULL = 0;
const SIZE_I32 = Uint32Array.BYTES_PER_ELEMENT;
const DEFAULT_ARGS = ["./ffmpeg", "-nostdin", "-y"];
Module["NULL"] = NULL;
Module["SIZE_I32"] = SIZE_I32;
Module["DEFAULT_ARGS"] = DEFAULT_ARGS;
/**
* Variables
*/
Module["ret"] = -1;
Module["timeout"] = -1;
Module["logger"] = () => {};
Module["progress"] = () => {};
/**
* Functions
*/
function stringToPtr(str) {
const len = Module["lengthBytesUTF8"](str) + 1;
const ptr = Module["_malloc"](len);
Module["stringToUTF8"](str, ptr, len);
return ptr;
}
function stringsToPtr(strs) {
const len = strs.length;
const ptr = Module["_malloc"](len * SIZE_I32);
for (let i = 0; i < len; i++) {
Module["setValue"](ptr + SIZE_I32 * i, stringToPtr(strs[i]), "i32");
}
return ptr;
}
function print(message) {
Module["logger"]({ type: "stdout", message });
}
function printErr(message) {
if (!message.startsWith("Aborted(native code called abort())"))
Module["logger"]({ type: "stderr", message });
}
function exec(_args) {
const args = [...Module["DEFAULT_ARGS"], ..._args];
try {
Module["_ffmpeg"](args.length, stringsToPtr(args));
} catch (e) {
if (!e.message.startsWith("Aborted")) {
throw e;
}
}
return Module["ret"];
}
function setLogger(logger) {
Module["logger"] = logger;
}
function setTimeout(timeout) {
Module["timeout"] = timeout;
}
function setProgress(handler) {
Module["progress"] = handler;
}
function receiveProgress(progress) {
Module["progress"](progress);
}
function reset() {
Module["ret"] = -1;
Module["timeout"] = -1;
}
Module["stringToPtr"] = stringToPtr;
Module["stringsToPtr"] = stringsToPtr;
Module["print"] = print;
Module["printErr"] = printErr;
Module["exec"] = exec;
Module["setLogger"] = setLogger;
Module["setTimeout"] = setTimeout;
Module["setProgress"] = setProgress;
Module["reset"] = reset;
Module["receiveProgress"] = receiveProgress;

View File

@@ -0,0 +1,3 @@
const EXPORTED_FUNCTIONS = ["_ffmpeg", "_abort"];
console.log(EXPORTED_FUNCTIONS.join(","));