소스 검색

benchmark mode that, when enabled, tries to decode frames as fast as possible and prints "frame per second" messages to the JavaScript console

Maik Merten 12 년 전
부모
커밋
79d4576bc5
1개의 변경된 파일16개의 추가작업 그리고 1개의 파일을 삭제
  1. 16 1
      jsmpg.js

+ 16 - 1
jsmpg.js 파일 보기

@@ -26,6 +26,7 @@ var requestAnimFrame = (function(){
26 26
 		
27 27
 var jsmpeg = window.jsmpeg = function( url, opts ) {
28 28
 	opts = opts || {};
29
+	this.benchmark = !!opts.benchmark;
29 30
 	this.canvas = opts.canvas || document.createElement('canvas');
30 31
 	this.autoplay = !!opts.autoplay;
31 32
 	this.loop = !!opts.loop;
@@ -404,7 +405,21 @@ jsmpeg.prototype.scheduleNextFrame = function() {
404 405
 	var wait = Math.max(0, (1000/this.pictureRate) - this.lateTime);
405 406
 	this.targetTime = Date.now() + wait;
406 407
 
407
-	if( wait < 18 ) {
408
+	if(this.benchmark) {
409
+		var now = Date.now();
410
+		if(!this.benchframe) {
411
+			this.benchstart = now;
412
+			this.benchframe = 0;
413
+		}
414
+		this.benchframe++;
415
+		var timepassed = now - this.benchstart;
416
+		if(this.benchframe >= 100) {
417
+			if(console) console.debug("frames per second: " + (this.benchframe / timepassed) * 1000 );
418
+			this.benchframe = null;
419
+		}
420
+		setTimeout( this.nextFrame.bind(this), 0);
421
+	}
422
+	else if( wait < 18) {
408 423
 		this.scheduleAnimation();
409 424
 	}
410 425
 	else {