Major refactor to adapt new ffmpeg-core.js
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
module.exports = (prefix, cnt) => (
|
||||
`${prefix}-${cnt}-${Math.random().toString(16).slice(3, 8)}`
|
||||
);
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
8
src/utils/string2pointer.js
Normal file
8
src/utils/string2pointer.js
Normal 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;
|
||||
};
|
||||
12
src/utils/stringList2pointer.js
Normal file
12
src/utils/stringList2pointer.js
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user