|
|
@@ -30,8 +30,8 @@ var jsmpeg = window.jsmpeg = function( url, opts ) {
|
|
30
|
30
|
this.autoplay = !!opts.autoplay;
|
|
31
|
31
|
this.loop = !!opts.loop;
|
|
32
|
32
|
this.externalLoadCallback = opts.onload || null;
|
|
33
|
|
- this.bwFilter = opts.bwFilter || false;
|
|
34
|
33
|
this.externalDecodeCallback = opts.ondecodeframe || null;
|
|
|
34
|
+ this.bwFilter = opts.bwFilter || false;
|
|
35
|
35
|
|
|
36
|
36
|
this.customIntraQuantMatrix = new Uint8Array(64);
|
|
37
|
37
|
this.customNonIntraQuantMatrix = new Uint8Array(64);
|
|
|
@@ -403,6 +403,7 @@ jsmpeg.prototype.scheduleNextFrame = function() {
|
|
403
|
403
|
this.lateTime = Date.now() - this.targetTime;
|
|
404
|
404
|
var wait = Math.max(0, (1000/this.pictureRate) - this.lateTime);
|
|
405
|
405
|
this.targetTime = Date.now() + wait;
|
|
|
406
|
+
|
|
406
|
407
|
if( wait < 18 ) {
|
|
407
|
408
|
this.scheduleAnimation();
|
|
408
|
409
|
}
|
|
|
@@ -459,24 +460,33 @@ jsmpeg.prototype.initBuffers = function() {
|
|
459
|
460
|
if( this.sequenceStarted ) { return; }
|
|
460
|
461
|
this.sequenceStarted = true;
|
|
461
|
462
|
|
|
|
463
|
+
|
|
|
464
|
+ // Manually clamp values when writing macroblocks for shitty browsers
|
|
|
465
|
+ // that don't support Uint8ClampedArray
|
|
|
466
|
+ var MaybeClampedUint8Array = window.Uint8ClampedArray || window.Uint8Array;
|
|
|
467
|
+ if( !window.Uint8ClampedArray ) {
|
|
|
468
|
+ this.copyBlockToDestination = this.copyBlockToDestinationClamp;
|
|
|
469
|
+ this.addBlockToDestination = this.addBlockToDestinationClamp;
|
|
|
470
|
+ }
|
|
|
471
|
+
|
|
462
|
472
|
// Allocated buffers and resize the canvas
|
|
463
|
|
- this.currentY = new Uint8ClampedArray(this.codedSize);
|
|
|
473
|
+ this.currentY = new MaybeClampedUint8Array(this.codedSize);
|
|
464
|
474
|
this.currentY32 = new Uint32Array(this.currentY.buffer);
|
|
465
|
475
|
|
|
466
|
|
- this.currentCr = new Uint8ClampedArray(this.codedSize >> 2);
|
|
|
476
|
+ this.currentCr = new MaybeClampedUint8Array(this.codedSize >> 2);
|
|
467
|
477
|
this.currentCr32 = new Uint32Array(this.currentCr.buffer);
|
|
468
|
478
|
|
|
469
|
|
- this.currentCb = new Uint8ClampedArray(this.codedSize >> 2);
|
|
|
479
|
+ this.currentCb = new MaybeClampedUint8Array(this.codedSize >> 2);
|
|
470
|
480
|
this.currentCb32 = new Uint32Array(this.currentCb.buffer);
|
|
471
|
481
|
|
|
472
|
482
|
|
|
473
|
|
- this.forwardY = new Uint8ClampedArray(this.codedSize);
|
|
|
483
|
+ this.forwardY = new MaybeClampedUint8Array(this.codedSize);
|
|
474
|
484
|
this.forwardY32 = new Uint32Array(this.forwardY.buffer);
|
|
475
|
485
|
|
|
476
|
|
- this.forwardCr = new Uint8ClampedArray(this.codedSize >> 2);
|
|
|
486
|
+ this.forwardCr = new MaybeClampedUint8Array(this.codedSize >> 2);
|
|
477
|
487
|
this.forwardCr32 = new Uint32Array(this.forwardCr.buffer);
|
|
478
|
488
|
|
|
479
|
|
- this.forwardCb = new Uint8ClampedArray(this.codedSize >> 2);
|
|
|
489
|
+ this.forwardCb = new MaybeClampedUint8Array(this.codedSize >> 2);
|
|
480
|
490
|
this.forwardCb32 = new Uint32Array(this.forwardCb.buffer);
|
|
481
|
491
|
|
|
482
|
492
|
this.canvas.width = this.width;
|
|
|
@@ -667,7 +677,6 @@ jsmpeg.prototype.YCbCrToRGBA = function() {
|
|
667
|
677
|
|
|
668
|
678
|
jsmpeg.prototype.YToRGBA = function() {
|
|
669
|
679
|
// Luma only
|
|
670
|
|
-
|
|
671
|
680
|
var pY = this.currentY;
|
|
672
|
681
|
var pRGBA = this.currentRGBA32;
|
|
673
|
682
|
|
|
|
@@ -1298,21 +1307,55 @@ jsmpeg.prototype.decodeBlock = function(block) {
|
|
1298
|
1307
|
var blockData = this.blockData;
|
|
1299
|
1308
|
if( this.macroblockIntra ) {
|
|
1300
|
1309
|
// Overwrite (no prediction)
|
|
1301
|
|
- for( var i = 0; i < 8; i++ ) {
|
|
1302
|
|
- for( var j = 0; j < 8; j++ ) {
|
|
1303
|
|
- destArray[destIndex++] = blockData[n++];
|
|
1304
|
|
- }
|
|
1305
|
|
- destIndex += scan;
|
|
1306
|
|
- }
|
|
|
1310
|
+ this.copyBlockToDestination(this.blockData, destArray, destIndex, scan);
|
|
1307
|
1311
|
}
|
|
1308
|
1312
|
else {
|
|
1309
|
1313
|
// Add data to the predicted macroblock
|
|
1310
|
|
- for( var i = 0; i < 8; i++ ) {
|
|
1311
|
|
- for( var j = 0; j < 8; j++ ) {
|
|
1312
|
|
- destArray[destIndex++] += blockData[n++];
|
|
1313
|
|
- }
|
|
1314
|
|
- destIndex += scan;
|
|
|
1314
|
+ this.addBlockToDestination(this.blockData, destArray, destIndex, scan);
|
|
|
1315
|
+ }
|
|
|
1316
|
+};
|
|
|
1317
|
+
|
|
|
1318
|
+
|
|
|
1319
|
+jsmpeg.prototype.copyBlockToDestination = function(blockData, destArray, destIndex, scan) {
|
|
|
1320
|
+ var n = 0;
|
|
|
1321
|
+ for( var i = 0; i < 8; i++ ) {
|
|
|
1322
|
+ for( var j = 0; j < 8; j++ ) {
|
|
|
1323
|
+ destArray[destIndex++] = blockData[n++];
|
|
|
1324
|
+ }
|
|
|
1325
|
+ destIndex += scan;
|
|
|
1326
|
+ }
|
|
|
1327
|
+};
|
|
|
1328
|
+
|
|
|
1329
|
+jsmpeg.prototype.addBlockToDestination = function(blockData, destArray, destIndex, scan) {
|
|
|
1330
|
+ var n = 0;
|
|
|
1331
|
+ for( var i = 0; i < 8; i++ ) {
|
|
|
1332
|
+ for( var j = 0; j < 8; j++ ) {
|
|
|
1333
|
+ destArray[destIndex++] += blockData[n++];
|
|
|
1334
|
+ }
|
|
|
1335
|
+ destIndex += scan;
|
|
|
1336
|
+ }
|
|
|
1337
|
+};
|
|
|
1338
|
+
|
|
|
1339
|
+// Clamping version for shitty browsers (IE) that don't support Uint8ClampedArray
|
|
|
1340
|
+jsmpeg.prototype.copyBlockToDestinationClamp = function(blockData, destArray, destIndex, scan) {
|
|
|
1341
|
+ var n = 0;
|
|
|
1342
|
+ for( var i = 0; i < 8; i++ ) {
|
|
|
1343
|
+ for( var j = 0; j < 8; j++ ) {
|
|
|
1344
|
+ var p = blockData[n++];
|
|
|
1345
|
+ destArray[destIndex++] = p > 255 ? 255 : (p < 0 ? 0 : p);
|
|
|
1346
|
+ }
|
|
|
1347
|
+ destIndex += scan;
|
|
|
1348
|
+ }
|
|
|
1349
|
+};
|
|
|
1350
|
+
|
|
|
1351
|
+jsmpeg.prototype.addBlockToDestinationClamp = function(blockData, destArray, destIndex, scan) {
|
|
|
1352
|
+ var n = 0;
|
|
|
1353
|
+ for( var i = 0; i < 8; i++ ) {
|
|
|
1354
|
+ for( var j = 0; j < 8; j++ ) {
|
|
|
1355
|
+ var p = blockData[n++] + destArray[destIndex];
|
|
|
1356
|
+ destArray[destIndex++] = p > 255 ? 255 : (p < 0 ? 0 : p);
|
|
1315
|
1357
|
}
|
|
|
1358
|
+ destIndex += scan;
|
|
1316
|
1359
|
}
|
|
1317
|
1360
|
};
|
|
1318
|
1361
|
|