Преглед на файлове

Add on{Audio/Video}Decode callbacks, meassure perf

phoboslab преди 7 години
родител
ревизия
7e39678f2a
променени са 5 файла, в които са добавени 45 реда и са изтрити 10 реда
  1. 3 3
      jsmpeg.min.js
  2. 12 3
      src/mp2-wasm.js
  3. 9 1
      src/mp2.js
  4. 12 3
      src/mpeg1-wasm.js
  5. 9 0
      src/mpeg1.js

Файловите разлики са ограничени, защото са твърде много
+ 3 - 3
jsmpeg.min.js


+ 12 - 3
src/mp2-wasm.js Целия файл

6
 var MP2WASM = function(options) {
6
 var MP2WASM = function(options) {
7
 	JSMpeg.Decoder.Base.call(this, options);
7
 	JSMpeg.Decoder.Base.call(this, options);
8
 
8
 
9
+	this.onDecodeCallback = options.onAudioDecode;
9
 	this.module = options.wasmModule;
10
 	this.module = options.wasmModule;
10
 
11
 
11
 	this.bufferSize = options.audioBufferSize || 128*1024;
12
 	this.bufferSize = options.audioBufferSize || 128*1024;
62
 };
63
 };
63
 
64
 
64
 MP2WASM.prototype.decode = function() {
65
 MP2WASM.prototype.decode = function() {
65
-	if (!this.decoder) { return; }
66
-	
67
-	var decodedBytes = this.functions._mp2_decoder_decode(this.decoder);
66
+	var startTime = JSMpeg.Now();
67
+
68
+	if (!this.decoder) {
69
+		return false;
70
+	}	
68
 
71
 
72
+	var decodedBytes = this.functions._mp2_decoder_decode(this.decoder);
69
 	if (decodedBytes === 0) {
73
 	if (decodedBytes === 0) {
70
 		return false;
74
 		return false;
71
 	}
75
 	}
89
 	}
93
 	}
90
 
94
 
91
 	this.advanceDecodedTime(MP2WASM.SAMPLES_PER_FRAME / this.sampleRate);
95
 	this.advanceDecodedTime(MP2WASM.SAMPLES_PER_FRAME / this.sampleRate);
96
+
97
+	var elapsedTime = JSMpeg.Now() - startTime;
98
+	if (this.onDecodeCallback) {
99
+		this.onDecodeCallback(this, elapsedTime);
100
+	}
92
 	return true;
101
 	return true;
93
 };
102
 };
94
 
103
 

+ 9 - 1
src/mp2.js Целия файл

6
 var MP2 = function(options) {
6
 var MP2 = function(options) {
7
 	JSMpeg.Decoder.Base.call(this, options);
7
 	JSMpeg.Decoder.Base.call(this, options);
8
 
8
 
9
+	this.onDecodeCallback = options.onAudioDecode;
10
+
9
 	var bufferSize = options.audioBufferSize || 128*1024;
11
 	var bufferSize = options.audioBufferSize || 128*1024;
10
 	var bufferMode = options.streaming
12
 	var bufferMode = options.streaming
11
 		? JSMpeg.BitBuffer.MODE.EVICT
13
 		? JSMpeg.BitBuffer.MODE.EVICT
41
 MP2.prototype.constructor = MP2;
43
 MP2.prototype.constructor = MP2;
42
 
44
 
43
 MP2.prototype.decode = function() {
45
 MP2.prototype.decode = function() {
46
+	var startTime = JSMpeg.Now();
47
+
44
 	var pos = this.bits.index >> 3;
48
 	var pos = this.bits.index >> 3;
45
 	if (pos >= this.bits.byteLength) {
49
 	if (pos >= this.bits.byteLength) {
46
 		return false;
50
 		return false;
48
 
52
 
49
 	var decoded = this.decodeFrame(this.left, this.right);
53
 	var decoded = this.decodeFrame(this.left, this.right);
50
 	this.bits.index = (pos + decoded) << 3;
54
 	this.bits.index = (pos + decoded) << 3;
51
-
52
 	if (!decoded) {
55
 	if (!decoded) {
53
 		return false;
56
 		return false;
54
 	}
57
 	}
58
 	}
61
 	}
59
 
62
 
60
 	this.advanceDecodedTime(this.left.length / this.sampleRate);
63
 	this.advanceDecodedTime(this.left.length / this.sampleRate);
64
+
65
+	var elapsedTime = JSMpeg.Now() - startTime;
66
+	if (this.onDecodeCallback) {
67
+		this.onDecodeCallback(this, elapsedTime);
68
+	}
61
 	return true;
69
 	return true;
62
 };
70
 };
63
 
71
 

+ 12 - 3
src/mpeg1-wasm.js Целия файл

3
 var MPEG1WASM = function(options) {
3
 var MPEG1WASM = function(options) {
4
 	JSMpeg.Decoder.Base.call(this, options);
4
 	JSMpeg.Decoder.Base.call(this, options);
5
 
5
 
6
+	this.onDecodeCallback = options.onVideoDecode;
6
 	this.module = options.wasmModule;
7
 	this.module = options.wasmModule;
7
 
8
 
8
 	this.bufferSize = options.videoBufferSize || 512*1024;
9
 	this.bufferSize = options.videoBufferSize || 512*1024;
84
 };
85
 };
85
 
86
 
86
 MPEG1WASM.prototype.decode = function() {
87
 MPEG1WASM.prototype.decode = function() {
87
-	if (!this.decoder) { return; }
88
-	
89
-	var didDecode = this.functions._mpeg1_decoder_decode(this.decoder);
88
+	var startTime = JSMpeg.Now();
90
 
89
 
90
+	if (!this.decoder) {
91
+		return false;
92
+	}
93
+
94
+	var didDecode = this.functions._mpeg1_decoder_decode(this.decoder);
91
 	if (!didDecode) {
95
 	if (!didDecode) {
92
 		return false;
96
 		return false;
93
 	}
97
 	}
106
 	}
110
 	}
107
 
111
 
108
 	this.advanceDecodedTime(1/this.frameRate);
112
 	this.advanceDecodedTime(1/this.frameRate);
113
+
114
+	var elapsedTime = JSMpeg.Now() - startTime;
115
+	if (this.onDecodeCallback) {
116
+		this.onDecodeCallback(this, elapsedTime);
117
+	}
109
 	return true;
118
 	return true;
110
 };
119
 };
111
 
120
 

+ 9 - 0
src/mpeg1.js Целия файл

6
 var MPEG1 = function(options) {
6
 var MPEG1 = function(options) {
7
 	JSMpeg.Decoder.Base.call(this, options);
7
 	JSMpeg.Decoder.Base.call(this, options);
8
 
8
 
9
+	this.onDecodeCallback = options.onVideoDecode;
10
+
9
 	var bufferSize = options.videoBufferSize || 512*1024;
11
 	var bufferSize = options.videoBufferSize || 512*1024;
10
 	var bufferMode = options.streaming
12
 	var bufferMode = options.streaming
11
 		? JSMpeg.BitBuffer.MODE.EVICT
13
 		? JSMpeg.BitBuffer.MODE.EVICT
40
 };
42
 };
41
 
43
 
42
 MPEG1.prototype.decode = function() {
44
 MPEG1.prototype.decode = function() {
45
+	var startTime = JSMpeg.Now();
46
+	
43
 	if (!this.hasSequenceHeader) {
47
 	if (!this.hasSequenceHeader) {
44
 		return false;
48
 		return false;
45
 	}
49
 	}
51
 
55
 
52
 	this.decodePicture();
56
 	this.decodePicture();
53
 	this.advanceDecodedTime(1/this.frameRate);
57
 	this.advanceDecodedTime(1/this.frameRate);
58
+
59
+	var elapsedTime = JSMpeg.Now() - startTime;
60
+	if (this.onDecodeCallback) {
61
+		this.onDecodeCallback(this, elapsedTime);
62
+	}
54
 	return true;
63
 	return true;
55
 };
64
 };
56
 
65