Skip to content

Commit

Permalink
修复webpack下如果使用了babel-polyfill.parseInt导致mp3.js中Worker内parseInt函数丢失的bu…
Browse files Browse the repository at this point in the history
…g,删掉amr引擎中不仅没用的还会导致babel编译后产生错误的函数解析代码
  • Loading branch information
xiangyuecn committed Mar 26, 2020
1 parent 6dd3e96 commit dd1aafb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 129 deletions.
8 changes: 4 additions & 4 deletions assets/npm-home/hash-history.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[
{
"sha1": "5eefc26c1cb43ba251693d4bf17ab4af3f681001",
"time": "2020-3-26 14:42:18"
},
{
"sha1": "bc0e623b290a1ad201c85d77a26d8081a2da22fc",
"time": "2020-3-3 20:57:11"
Expand All @@ -14,9 +18,5 @@
{
"sha1": "96ba713840ef578e59374ee2b012460fd4889bbc",
"time": "2020-1-28 04:28:51"
},
{
"sha1": "2693f2898935e3e378bd1aba38f0cb4271641d57",
"time": "2020-1-18 16:15:24"
}
]
2 changes: 1 addition & 1 deletion dist/engine/beta-amr.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/engine/mp3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion recorder.mp3.min.js

Large diffs are not rendered by default.

120 changes: 0 additions & 120 deletions src/engine/beta-amr-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,126 +384,6 @@ https://raw.githubusercontent.com/BenzLeung/benz-amr-recorder/462c6b91a67f7d9f42

var globalScope = this;

function getCFunc(ident) {
var func = Module["_" + ident];
if (!func) {
try {
func = eval("_" + ident)
} catch (e) {
}
}
assert(func, "Cannot call unknown function " + ident + " (perhaps LLVM optimizations or closure removed it?)");
return func
}

var cwrap, ccall;
((function () {
var JSfuncs = {
"stackSave": (function () {
Runtime.stackSave()
}), "stackRestore": (function () {
Runtime.stackRestore()
}), "arrayToC": (function (arr) {
var ret = Runtime.stackAlloc(arr.length);
writeArrayToMemory(arr, ret);
return ret
}), "stringToC": (function (str) {
var ret = 0;
if (str !== null && str !== undefined && str !== 0) {
ret = Runtime.stackAlloc((str.length << 2) + 1);
writeStringToMemory(str, ret)
}
return ret
})
};
var toC = {"string": JSfuncs["stringToC"], "array": JSfuncs["arrayToC"]};
ccall = function ccallFunc(ident, returnType, argTypes, args, opts) {
var func = getCFunc(ident);
var cArgs = [];
var stack = 0;
if (args) {
for (var i = 0; i < args.length; i++) {
var converter = toC[argTypes[i]];
if (converter) {
if (stack === 0) stack = Runtime.stackSave();
cArgs[i] = converter(args[i])
} else {
cArgs[i] = args[i]
}
}
}
var ret = func.apply(null, cArgs);
if (returnType === "string") ret = Pointer_stringify(ret);
if (stack !== 0) {
if (opts && opts.async) {
EmterpreterAsync.asyncFinalizers.push((function () {
Runtime.stackRestore(stack)
}));
return
}
Runtime.stackRestore(stack)
}
return ret
};
var sourceRegex = /^function\s*\(([^)]*)\)\s*{\s*([^*]*?)[\s;]*(?:return\s*(.*?)[;\s]*)?}$/;

function parseJSFunc(jsfunc) {
var parsed = jsfunc.toString().match(sourceRegex).slice(1);
return {arguments: parsed[0], body: parsed[1], returnValue: parsed[2]}
}

var JSsource = {};
for (var fun in JSfuncs) {
if (JSfuncs.hasOwnProperty(fun)) {
JSsource[fun] = parseJSFunc(JSfuncs[fun])
}
}
cwrap = function cwrap(ident, returnType, argTypes) {
argTypes = argTypes || [];
var cfunc = getCFunc(ident);
var numericArgs = argTypes.every((function (type) {
return type === "number"
}));
var numericRet = returnType !== "string";
if (numericRet && numericArgs) {
return cfunc
}
var argNames = argTypes.map((function (x, i) {
return "$" + i
}));
var funcstr = "(function(" + argNames.join(",") + ") {";
var nargs = argTypes.length;
if (!numericArgs) {
funcstr += "var stack = " + JSsource["stackSave"].body + ";";
for (var i = 0; i < nargs; i++) {
var arg = argNames[i], type = argTypes[i];
if (type === "number") continue;
var convertCode = JSsource[type + "ToC"];
funcstr += "var " + convertCode.arguments + " = " + arg + ";";
funcstr += convertCode.body + ";";
funcstr += arg + "=" + convertCode.returnValue + ";"
}
}
var cfuncname = parseJSFunc((function () {
return cfunc
})).returnValue;
funcstr += "var ret = " + cfuncname + "(" + argNames.join(",") + ");";
if (!numericRet) {
var strgfy = parseJSFunc((function () {
return Pointer_stringify
})).returnValue;
funcstr += "ret = " + strgfy + "(ret);"
}
if (!numericArgs) {
funcstr += JSsource["stackRestore"].body.replace("()", "(stack)") + ";"
}
funcstr += "return ret})";
return eval(funcstr)
}
}))();
Module["ccall"] = ccall;
Module["cwrap"] = cwrap;

function setValue(ptr, value, type, noSafe) {
type = type || "i8";
if (type.charAt(type.length - 1) === "*") type = "i32";
Expand Down
7 changes: 5 additions & 2 deletions src/engine/mp3.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ mp3Buffers=[ArrayBuffer,...]
length=mp3Buffers的数据二进制总长度
*/
Recorder.mp3ReadMeta=function(mp3Buffers,length){
//kill babel-polyfill ES6 Number.parseInt 不然放到Worker里面找不到方法
var parseInt_ES3=typeof(window)=="object"?window.parseInt:self.parseInt;

var u8arr0=new Uint8Array(mp3Buffers[0]||[]);
if(u8arr0.length<4){
return null;
Expand All @@ -251,11 +254,11 @@ Recorder.mp3ReadMeta=function(mp3Buffers,length){
,"2":[22050, 24000, 16000]
,"2.5":[11025, 12000, 8000]
})[version];
sampleRate&&(sampleRate=sampleRate[parseInt(b4.substr(4,2),2)]);
sampleRate&&(sampleRate=sampleRate[parseInt_ES3(b4.substr(4,2),2)]);
var bitRate=[ //lamejs -> Tables.bitrate_table
[0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160] //MPEG 2 2.5
,[0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]//MPEG 1
][version==1?1:0][parseInt(b4.substr(0,4),2)];
][version==1?1:0][parseInt_ES3(b4.substr(0,4),2)];

if(!version || !layer || !bitRate || !sampleRate){
return null;
Expand Down

0 comments on commit dd1aafb

Please sign in to comment.