Major refactor to adapt new ffmpeg-core.js

This commit is contained in:
Jerome Wu
2020-04-28 19:35:57 +08:00
parent cd5fe43905
commit b36360f16f
40 changed files with 226 additions and 527 deletions

View File

@@ -1,3 +0,0 @@
module.exports = (prefix, cnt) => (
`${prefix}-${cnt}-${Math.random().toString(16).slice(3, 8)}`
);

View File

@@ -1,16 +0,0 @@
module.exports = (packet) => {
const transferables = [];
const check = (b) => {
if (b instanceof Uint8Array) {
transferables.push(b.buffer);
} else if (b instanceof ArrayBuffer) {
transferables.push(b);
}
};
const { payload: { args, data } } = packet;
check(data);
if (Array.isArray(args)) {
args.forEach((arg) => check(arg));
}
return transferables;
};

View File

@@ -6,4 +6,4 @@ exports.setLogging = (_logging) => {
logging = _logging;
};
exports.log = (...args) => (logging ? console.log.apply(this, args) : null);
exports.log = (type, message) => (logging ? console.log(`[${type}] ${message}`) : null);

View File

@@ -3,7 +3,7 @@ const resolveURL = isBrowser ? require('resolve-url') : s => s; // eslint-disabl
module.exports = (options) => {
const opts = { ...options };
['corePath', 'workerPath'].forEach((key) => {
['corePath'].forEach((key) => {
if (typeof options[key] !== 'undefined') {
opts[key] = resolveURL(opts[key]);
}

View File

@@ -0,0 +1,8 @@
module.exports = (Module, s) => {
const ptr = Module._malloc((s.length + 1) * Uint8Array.BYTES_PER_ELEMENT);
for (let i = 0; i < s.length; i += 1) {
Module.setValue(ptr + i, s.charCodeAt(i), 'i8');
}
Module.setValue(ptr + s.length, 0, 'i8');
return ptr;
};

View File

@@ -0,0 +1,12 @@
const string2pointer = require('./string2pointer');
module.exports = (Module, strList) => {
const listPtr = Module._malloc(strList.length * Uint32Array.BYTES_PER_ELEMENT);
strList.forEach((s, idx) => {
const strPtr = string2pointer(Module, s);
Module.setValue(listPtr + (4 * idx), strPtr, 'i32');
});
return listPtr;
};