forked from dinedal/videoconverter.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker-asm.js
111 lines (92 loc) · 2.52 KB
/
worker-asm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
importScripts('../build/ffmpeg.js');
importScripts('./lodash.js');
importScripts('./benchmark.js');
var now = Date.now;
function print(text) {
postMessage({
'type' : 'stdout',
'data' : text
});
}
onmessage = function(event) {
var message = event.data;
if (message.type === "command") {
var Module = {
print: print,
printErr: print,
files: message.files || [],
arguments: message.arguments || [],
TOTAL_MEMORY: 268435456
// Can play around with this option - must be a power of 2
// TOTAL_MEMORY: 268435456
};
postMessage({
'type' : 'start',
'data' : Module.arguments.join(" ")
});
postMessage({
'type' : 'stdout',
'data' : 'Received command: ' +
Module.arguments.join(" ") +
((Module.TOTAL_MEMORY) ? ". Processing with " + Module.TOTAL_MEMORY + " bits." : "")
});
var time = now();
Module['returnCallback'] = function(result) {
var totalTime = now() - time;
postMessage({
'type' : 'stdout',
'data' : 'Finished processing (took ' + totalTime + 'ms)'
});
postMessage({
'type' : 'done',
'data' : result,
'time' : totalTime
});
}
var result = ffmpeg_run(Module);
}
if (message.type === "benchmark") {
var Module = {};
postMessage({
'type' : 'start',
'data' : message.arguments.join(" ")
});
print("Starting benchmark")
var suite = new Benchmark.Suite
suite.add('ffmpeg', {
'defer': true,
'setup': function() {
Module = {
print: function(data){},
printErr: function(data){},
files: message.files || [],
arguments: message.arguments.slice() || [],
TOTAL_MEMORY: 268435456
// Can play around with this option - must be a power of 2
// TOTAL_MEMORY: 268435456
};
print(".");
},
'fn': function(deferred) {
Module['returnCallback'] = function(result) {
deferred.resolve();
}
ffmpeg_run(Module);
}
}).on('complete', function() {
var results = this.filter('fastest')[0];
print("Samples:" + results.stats.sample.length)
print("Mean:" + results.stats.mean)
print("Variance:" + results.stats.variance)
print("Stddev:" + Math.sqrt(results.stats.variance))
postMessage({
'type' : 'done',
'data' : [],
'time' : 0
});
}).run({'async': true});
}
};
postMessage({
'type' : 'ready'
});