0.0.2 • Published 5 years ago

node-red-contrib-rtsp v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

node-red-contrib-rtsp

RTSP into Node-red

Demo

[ { "id": "6fea32ab.fec6dc", "type": "rtsp-websocket", "z": "18d25c20.77a2b4", "rtsp_url": "rtsp://admin:rtsp1234@192.168.0.15/onvif1", "name": "front_camera_1", "ws_port": 9999, "retry_timeout": "", "x": 240, "y": 420, "wires": [ [] ] }, { "id": "af32b164.865ca", "type": "ui_template", "z": "18d25c20.77a2b4", "group": "2fcb18aa.8c5288", "name": "", "order": 1, "width": "6", "height": "5", "format": "\n\n Front 1\n\t<canvas id=\"canvas\" style=\"height: 400px;\">\n\n\n<script type=\"text/javascript\" src=\"/jsmpeg.min.js\">\n<script type=\"text/javascript\">\n\tplayer = new JSMpeg.Player('ws://localhost:9999', {\n\t canvas: document.getElementById('canvas') // Canvas should be a canvas DOM element\n\t})\t\n\n", "storeOutMessages": true, "fwdInMessages": true, "templateScope": "local", "x": 760, "y": 380, "wires": [ [] ] }, { "id": "7d37b5ad.24345c", "type": "http in", "z": "18d25c20.77a2b4", "name": "", "url": "/jsmpeg.min.js", "method": "get", "upload": false, "swaggerDoc": "", "x": 250, "y": 320, "wires": [ "88e3f02a.1b869" ] }, { "id": "88e3f02a.1b869", "type": "template", "z": "18d25c20.77a2b4", "name": "", "field": "payload", "fieldType": "msg", "format": "handlebars", "syntax": "plain", "template": "var JSMpeg={Player:null,VideoElement:null,BitBuffer:null,Source:{},Demuxer:{},Decoder:{},Renderer:{},AudioOutput:{},Now:function(){return window.performance?window.performance.now()/1e3:Date.now()/1e3},CreateVideoElements:function(){var elements=document.querySelectorAll(\".jsmpeg\");for(var i=0;i<elements.length;i++){new JSMpeg.VideoElement(elementsi)}},Fill:function(array,value){if(array.fill){array.fill(value)}else{for(var i=0;i<array.length;i++){arrayi=value}}},Base64ToArrayBuffer:function(base64){var binary=window.atob(base64);var length=binary.length;var bytes=new Uint8Array(length);for(var i=0;i<length;i++){bytesi=binary.charCodeAt(i)}return bytes.buffer},WASM_BINARY_INLINED:null};if(document.readyState===\"complete\"){JSMpeg.CreateVideoElements()}else{document.addEventListener(\"DOMContentLoaded\",JSMpeg.CreateVideoElements)}JSMpeg.VideoElement=function(){\"use strict\";var VideoElement=function(element){var url=element.dataset.url;if(!url){throw\"VideoElement has no data-url attribute\"}var addStyles=function(element,styles){for(var name in styles){element.stylename=stylesname}};this.container=element;addStyles(this.container,{display:\"inline-block\",position:\"relative\",minWidth:\"80px\",minHeight:\"80px\"});this.canvas=document.createElement(\"canvas\");this.canvas.width=960;this.canvas.height=540;addStyles(this.canvas,{display:\"block\",width:\"100%\"});this.container.appendChild(this.canvas);this.playButton=document.createElement(\"div\");this.playButton.innerHTML=VideoElement.PLAY_BUTTON;addStyles(this.playButton,{zIndex:2,position:\"absolute\",top:\"0\",bottom:\"0\",left:\"0\",right:\"0\",maxWidth:\"75px\",maxHeight:\"75px\",margin:\"auto\",opacity:\"0.7\",cursor:\"pointer\"});this.container.appendChild(this.playButton);var options={canvas:this.canvas};for(var option in element.dataset){try{optionsoption=JSON.parse(element.datasetoption)}catch(err){optionsoption=element.datasetoption}}this.player=new JSMpeg.Player(url,options);element.playerInstance=this.player;if(options.poster&&!options.autoplay&&!this.player.options.streaming){options.decodeFirstFrame=false;this.poster=new Image;this.poster.src=options.poster;this.poster.addEventListener(\"load\",this.posterLoaded);addStyles(this.poster,{display:\"block\",zIndex:1,position:\"absolute\",top:0,left:0,bottom:0,right:0});this.container.appendChild(this.poster)}if(!this.player.options.streaming){this.container.addEventListener(\"click\",this.onClick.bind(this))}if(options.autoplay||this.player.options.streaming){this.playButton.style.display=\"none\"}if(this.player.audioOut&&!this.player.audioOut.unlocked){var unlockAudioElement=this.container;if(options.autoplay||this.player.options.streaming){this.unmuteButton=document.createElement(\"div\");this.unmuteButton.innerHTML=VideoElement.UNMUTE_BUTTON;addStyles(this.unmuteButton,{zIndex:2,position:\"absolute\",bottom:\"10px\",right:\"20px\",width:\"75px\",height:\"75px\",margin:\"auto\",opacity:\"0.7\",cursor:\"pointer\"});this.container.appendChild(this.unmuteButton);unlockAudioElement=this.unmuteButton}this.unlockAudioBound=this.onUnlockAudio.bind(this,unlockAudioElement);unlockAudioElement.addEventListener(\"touchstart\",this.unlockAudioBound,false);unlockAudioElement.addEventListener(\"click\",this.unlockAudioBound,true)}};VideoElement.prototype.onUnlockAudio=function(element,ev){if(this.unmuteButton){ev.preventDefault();ev.stopPropagation()}this.player.audioOut.unlock(function(){if(this.unmuteButton){this.unmuteButton.style.display=\"none\"}element.removeEventListener(\"touchstart\",this.unlockAudioBound);element.removeEventListener(\"click\",this.unlockAudioBound)}.bind(this))};VideoElement.prototype.onClick=function(ev){if(this.player.isPlaying){this.player.pause();this.playButton.style.display=\"block\"}else{this.player.play();this.playButton.style.display=\"none\";if(this.poster){this.poster.style.display=\"none\"}}};VideoElement.PLAY_BUTTON='<svg style=\"max-width: 75px; max-height: 75px;\" '+'viewBox=\"0 0 200 200\" alt=\"Play video\">'+'<circle cx=\"100\" cy=\"100\" r=\"90\" fill=\"none\" '+'stroke-width=\"15\" stroke=\"#fff\"/>'+'<polygon points=\"70, 55 70, 145 145, 100\" fill=\"#fff\"/>'+\"\";VideoElement.UNMUTE_BUTTON='<svg style=\"max-width: 75px; max-height: 75px;\" viewBox=\"0 0 75 75\">'+'<polygon class=\"audio-speaker\" stroke=\"none\" fill=\"#fff\" '+'points=\"39,13 22,28 6,28 6,47 21,47 39,62 39,13\"/>'+'<g stroke=\"#fff\" stroke-width=\"5\">'+'<path d=\"M 49,50 69,26\"/>'+'<path d=\"M 69,50 49,26\"/>'+\"\"+\"\";return VideoElement}();JSMpeg.Player=function(){\"use strict\";var Player=function(url,options){this.options=options||{};if(options.source){this.source=new options.source(url,options);options.streaming=!!this.source.streaming}else if(url.match(/^wss?:\/\//)){this.source=new JSMpeg.Source.WebSocket(url,options);options.streaming=true}else if(options.progressive!==false){this.source=new JSMpeg.Source.AjaxProgressive(url,options);options.streaming=false}else{this.source=new JSMpeg.Source.Ajax(url,options);options.streaming=false}this.maxAudioLag=options.maxAudioLag||.25;this.loop=options.loop!==false;this.autoplay=!!options.autoplay||options.streaming;this.demuxer=new JSMpeg.Demuxer.TS(options);this.source.connect(this.demuxer);if(!options.disableWebAssembly&&JSMpeg.WASMModule.IsSupported()){this.wasmModule=new JSMpeg.WASMModule;options.wasmModule=this.wasmModule}if(options.video!==false){this.video=options.wasmModule?new JSMpeg.Decoder.MPEG1VideoWASM(options):new JSMpeg.Decoder.MPEG1Video(options);this.renderer=!options.disableGl&&JSMpeg.Renderer.WebGL.IsSupported()?new JSMpeg.Renderer.WebGL(options):new JSMpeg.Renderer.Canvas2D(options);this.demuxer.connect(JSMpeg.Demuxer.TS.STREAM.VIDEO_1,this.video);this.video.connect(this.renderer)}if(options.audio!==false&&JSMpeg.AudioOutput.WebAudio.IsSupported()){this.audio=options.wasmModule?new JSMpeg.Decoder.MP2AudioWASM(options):new JSMpeg.Decoder.MP2Audio(options);this.audioOut=new JSMpeg.AudioOutput.WebAudio(options);this.demuxer.connect(JSMpeg.Demuxer.TS.STREAM.AUDIO_1,this.audio);this.audio.connect(this.audioOut)}Object.defineProperty(this,\"currentTime\",{get:this.getCurrentTime,set:this.setCurrentTime});Object.defineProperty(this,\"volume\",{get:this.getVolume,set:this.setVolume});this.paused=true;this.unpauseOnShow=false;if(options.pauseWhenHidden!==false){document.addEventListener(\"visibilitychange\",this.showHide.bind(this))}if(this.wasmModule){if(JSMpeg.WASM_BINARY_INLINED){var wasm=JSMpeg.Base64ToArrayBuffer(JSMpeg.WASM_BINARY_INLINED);this.wasmModule.loadFromBuffer(wasm,this.startLoading.bind(this))}else{this.wasmModule.loadFromFile(\"jsmpeg.wasm\",this.startLoading.bind(this))}}else{this.startLoading()}};Player.prototype.startLoading=function(){this.source.start();if(this.autoplay){this.play()}};Player.prototype.showHide=function(ev){if(document.visibilityState===\"hidden\"){this.unpauseOnShow=this.wantsToPlay;this.pause()}else if(this.unpauseOnShow){this.play()}};Player.prototype.play=function(ev){if(this.animationId){return}this.animationId=requestAnimationFrame(this.update.bind(this));this.wantsToPlay=true;this.paused=false};Player.prototype.pause=function(ev){if(this.paused){return}cancelAnimationFrame(this.animationId);this.animationId=null;this.wantsToPlay=false;this.isPlaying=false;this.paused=true;if(this.audio&&this.audio.canPlay){this.audioOut.stop();this.seek(this.currentTime)}if(this.options.onPause){this.options.onPause(this)}};Player.prototype.getVolume=function(){return this.audioOut?this.audioOut.volume:0};Player.prototype.setVolume=function(volume){if(this.audioOut){this.audioOut.volume=volume}};Player.prototype.stop=function(ev){this.pause();this.seek(0);if(this.video&&this.options.decodeFirstFrame!==false){this.video.decode()}};Player.prototype.destroy=function(){this.pause();this.source.destroy();this.video&&this.video.destroy();this.renderer&&this.renderer.destroy();this.audio&&this.audio.destroy();this.audioOut&&this.audioOut.destroy()};Player.prototype.seek=function(time){var startOffset=this.audio&&this.audio.canPlay?this.audio.startTime:this.video.startTime;if(this.video){this.video.seek(time+startOffset)}if(this.audio){this.audio.seek(time+startOffset)}this.startTime=JSMpeg.Now()-time};Player.prototype.getCurrentTime=function(){return this.audio&&this.audio.canPlay?this.audio.currentTime-this.audio.startTime:this.video.currentTime-this.video.startTime};Player.prototype.setCurrentTime=function(time){this.seek(time)};Player.prototype.update=function(){this.animationId=requestAnimationFrame(this.update.bind(this));if(!this.source.established){if(this.renderer){this.renderer.renderProgress(this.source.progress)}return}if(!this.isPlaying){this.isPlaying=true;this.startTime=JSMpeg.Now()-this.currentTime;if(this.options.onPlay){this.options.onPlay(this)}}if(this.options.streaming){this.updateForStreaming()}else{this.updateForStaticFile()}};Player.prototype.updateForStreaming=function(){if(this.video){this.video.decode()}if(this.audio){var decoded=false;do{if(this.audioOut.enqueuedTime>this.maxAudioLag){this.audioOut.resetEnqueuedTime();this.audioOut.enabled=false}decoded=this.audio.decode()}while(decoded);this.audioOut.enabled=true}};Player.prototype.nextFrame=function(){if(this.source.established&&this.video){return this.video.decode()}return false};Player.prototype.updateForStaticFile=function(){var notEnoughData=false,headroom=0;if(this.audio&&this.audio.canPlay){while(!notEnoughData&&this.audio.decodedTime-this.audio.currentTime<.25){notEnoughData=!this.audio.decode()}if(this.video&&this.video.currentTime<this.audio.currentTime){notEnoughData=!this.video.decode()}headroom=this.demuxer.currentTime-this.audio.currentTime}else if(this.video){var targetTime=JSMpeg.Now()-this.startTime+this.video.startTime,lateTime=targetTime-this.video.currentTime,frameTime=1/this.video.frameRate;if(this.video&&lateTime>0){if(lateTime>frameTime2){this.startTime+=lateTime}notEnoughData=!this.video.decode()}headroom=this.demuxer.currentTime-targetTime}this.source.resume(headroom);if(notEnoughData&&this.source.completed){if(this.loop){this.seek(0)}else{this.pause();if(this.options.onEnded){this.options.onEnded(this)}}}else if(notEnoughData&&this.options.onStalled){this.options.onStalled(this)}};return Player}();JSMpeg.BitBuffer=function(){\"use strict\";var BitBuffer=function(bufferOrLength,mode){if(typeof bufferOrLength===\"object\"){this.bytes=bufferOrLength instanceof Uint8Array?bufferOrLength:new Uint8Array(bufferOrLength);this.byteLength=this.bytes.length}else{this.bytes=new Uint8Array(bufferOrLength||10241024);this.byteLength=0}this.mode=mode||BitBuffer.MODE.EXPAND;this.index=0};BitBuffer.prototype.resize=function(size){var newBytes=new Uint8Array(size);if(this.byteLength!==0){this.byteLength=Math.min(this.byteLength,size);newBytes.set(this.bytes,0,this.byteLength)}this.bytes=newBytes;this.index=Math.min(this.index,this.byteLength<<3)};BitBuffer.prototype.evict=function(sizeNeeded){var bytePos=this.index>>3,available=this.bytes.length-this.byteLength;if(this.index===this.byteLength<<3||sizeNeeded>available+bytePos){this.byteLength=0;this.index=0;return}else if(bytePos===0){return}if(this.bytes.copyWithin){this.bytes.copyWithin(0,bytePos,this.byteLength)}else{this.bytes.set(this.bytes.subarray(bytePos,this.byteLength))}this.byteLength=this.byteLength-bytePos;this.index-=bytePos<<3;return};BitBuffer.prototype.write=function(buffers){var isArrayOfBuffers=typeof buffers0===\"object\",totalLength=0,available=this.bytes.length-this.byteLength;if(isArrayOfBuffers){var totalLength=0;for(var i=0;i<buffers.length;i++){totalLength+=buffersi.byteLength}}else{totalLength=buffers.byteLength}if(totalLength>available){if(this.mode===BitBuffer.MODE.EXPAND){var newSize=Math.max(this.bytes.length2,totalLength-available);this.resize(newSize)}else{this.evict(totalLength)}}if(isArrayOfBuffers){for(var i=0;i<buffers.length;i++){this.appendSingleBuffer(buffersi)}}else{this.appendSingleBuffer(buffers)}return totalLength};BitBuffer.prototype.appendSingleBuffer=function(buffer){buffer=buffer instanceof Uint8Array?buffer:new Uint8Array(buffer);this.bytes.set(buffer,this.byteLength);this.byteLength+=buffer.length};BitBuffer.prototype.findNextStartCode=function(){for(var i=this.index+7>>3;i<this.byteLength;i++){if(this.bytesi==0&&this.bytesi+1==0&&this.bytesi+2==1){this.index=i+4<<3;return this.bytesi+3}}this.index=this.byteLength<<3;return-1};BitBuffer.prototype.findStartCode=function(code){var current=0;while(true){current=this.findNextStartCode();if(current===code||current===-1){return current}}return-1};BitBuffer.prototype.nextBytesAreStartCode=function(){var i=this.index+7>>3;return i>=this.byteLength||this.bytesi==0&&this.bytesi+1==0&&this.bytesi+2==1};BitBuffer.prototype.peek=function(count){var offset=this.index;var value=0;while(count){var currentByte=this.bytesoffset>>3,remaining=8-(offset&7),read=remaining<count?remaining:count,shift=remaining-read,mask=255>>8-read;value=value<<read|(currentByte&mask<<shift)>>shift;offset+=read;count-=read}return value};BitBuffer.prototype.read=function(count){var value=this.peek(count);this.index+=count;return value};BitBuffer.prototype.skip=function(count){return this.index+=count};BitBuffer.prototype.rewind=function(count){this.index=Math.max(this.index-count,0)};BitBuffer.prototype.has=function(count){return(this.byteLength<<3)-this.index>=count};BitBuffer.MODE={EVICT:1,EXPAND:2};return BitBuffer}();JSMpeg.Source.Ajax=function(){\"use strict\";var AjaxSource=function(url,options){this.url=url;this.destination=null;this.request=null;this.streaming=false;this.completed=false;this.established=false;this.progress=0;this.onEstablishedCallback=options.onSourceEstablished;this.onCompletedCallback=options.onSourceCompleted};AjaxSource.prototype.connect=function(destination){this.destination=destination};AjaxSource.prototype.start=function(){this.request=new XMLHttpRequest;this.request.onreadystatechange=function(){if(this.request.readyState===this.request.DONE&&this.request.status===200){this.onLoad(this.request.response)}}.bind(this);this.request.onprogress=this.onProgress.bind(this);this.request.open(\"GET\",this.url);this.request.responseType=\"arraybuffer\";this.request.send()};AjaxSource.prototype.resume=function(secondsHeadroom){};AjaxSource.prototype.destroy=function(){this.request.abort()};AjaxSource.prototype.onProgress=function(ev){this.progress=ev.loaded/ev.total};AjaxSource.prototype.onLoad=function(data){this.established=true;this.completed=true;this.progress=1;if(this.onEstablishedCallback){this.onEstablishedCallback(this)}if(this.onCompletedCallback){this.onCompletedCallback(this)}if(this.destination){this.destination.write(data)}};return AjaxSource}();JSMpeg.Source.Fetch=function(){\"use strict\";var FetchSource=function(url,options){this.url=url;this.destination=null;this.request=null;this.streaming=true;this.completed=false;this.established=false;this.progress=0;this.aborted=false;this.onEstablishedCallback=options.onSourceEstablished;this.onCompletedCallback=options.onSourceCompleted};FetchSource.prototype.connect=function(destination){this.destination=destination};FetchSource.prototype.start=function(){var params={method:\"GET\",headers:new Headers,cache:\"default\"};self.fetch(this.url,params).then(function(res){if(res.ok&&(res.status>=200&&res.status<=299)){this.progress=1;this.established=true;return this.pump(res.body.getReader())}else{}}.bind(this)).catch(function(err){throw err})};FetchSource.prototype.pump=function(reader){return reader.read().then(function(result){if(result.done){this.completed=true}else{if(this.aborted){return reader.cancel()}if(this.destination){this.destination.write(result.value.buffer)}return this.pump(reader)}}.bind(this)).catch(function(err){throw err})};FetchSource.prototype.resume=function(secondsHeadroom){};FetchSource.prototype.abort=function(){this.aborted=true};return FetchSource}();JSMpeg.Source.AjaxProgressive=function(){\"use strict\";var AjaxProgressiveSource=function(url,options){this.url=url;this.destination=null;this.request=null;this.streaming=false;this.completed=false;this.established=false;this.progress=0;this.fileSize=0;this.loadedSize=0;this.chunkSize=options.chunkSize||10241024;this.isLoading=false;this.loadStartTime=0;this.throttled=options.throttled!==false;this.aborted=false;this.onEstablishedCallback=options.onSourceEstablished;this.onCompletedCallback=options.onSourceCompleted};AjaxProgressiveSource.prototype.connect=function(destination){this.destination=destination};AjaxProgressiveSource.prototype.start=function(){this.request=new XMLHttpRequest;this.request.onreadystatechange=function(){if(this.request.readyState===this.request.DONE){this.fileSize=parseInt(this.request.getResponseHeader(\"Content-Length\"));this.loadNextChunk()}}.bind(this);this.request.onprogress=this.onProgress.bind(this);this.request.open(\"HEAD\",this.url);this.request.send()};AjaxProgressiveSource.prototype.resume=function(secondsHeadroom){if(this.isLoading||!this.throttled){return}var worstCaseLoadingTime=this.loadTime8+2;if(worstCaseLoadingTime>secondsHeadroom){this.loadNextChunk()}};AjaxProgressiveSource.prototype.destroy=function(){this.request.abort();this.aborted=true};AjaxProgressiveSource.prototype.loadNextChunk=function(){var start=this.loadedSize,end=Math.min(this.loadedSize+this.chunkSize-1,this.fileSize-1);if(start>=this.fileSize||this.aborted){this.completed=true;if(this.onCompletedCallback){this.onCompletedCallback(this)}return}this.isLoading=true;this.loadStartTime=JSMpeg.Now();this.request=new XMLHttpRequest;this.request.onreadystatechange=function(){if(this.request.readyState===this.request.DONE&&this.request.status>=200&&this.request.status<300){this.onChunkLoad(this.request.response)}else if(this.request.readyState===this.request.DONE){if(this.loadFails++<3){this.loadNextChunk()}}}.bind(this);if(start===0){this.request.onprogress=this.onProgress.bind(this)}this.request.open(\"GET\",this.url+\"?\"+start+\"-\"+end);this.request.setRequestHeader(\"Range\",\"bytes=\"+start+\"-\"+end);this.request.responseType=\"arraybuffer\";this.request.send()};AjaxProgressiveSource.prototype.onProgress=function(ev){this.progress=ev.loaded/ev.total};AjaxProgressiveSource.prototype.onChunkLoad=function(data){var isFirstChunk=!this.established;this.established=true;this.progress=1;this.loadedSize+=data.byteLength;this.loadFails=0;this.isLoading=false;if(isFirstChunk&&this.onEstablishedCallback){this.onEstablishedCallback(this)}if(this.destination){this.destination.write(data)}this.loadTime=JSMpeg.Now()-this.loadStartTime;if(!this.throttled){this.loadNextChunk()}};return AjaxProgressiveSource}();JSMpeg.Source.WebSocket=function(){\"use strict\";var WSSource=function(url,options){this.url=url;this.options=options;this.socket=null;this.streaming=true;this.callbacks={connect:[],data:[]};this.destination=null;this.reconnectInterval=options.reconnectInterval!==undefined?options.reconnectInterval:5;this.shouldAttemptReconnect=!!this.reconnectInterval;this.completed=false;this.established=false;this.progress=0;this.reconnectTimeoutId=0;this.onEstablishedCallback=options.onSourceEstablished;this.onCompletedCallback=options.onSourceCompleted};WSSource.prototype.connect=function(destination){this.destination=destination};WSSource.prototype.destroy=function(){clearTimeout(this.reconnectTimeoutId);this.shouldAttemptReconnect=false;this.socket.close()};WSSource.prototype.start=function(){this.shouldAttemptReconnect=!!this.reconnectInterval;this.progress=0;this.established=false;this.socket=new WebSocket(this.url,this.options.protocols||null);this.socket.binaryType=\"arraybuffer\";this.socket.onmessage=this.onMessage.bind(this);this.socket.onopen=this.onOpen.bind(this);this.socket.onerror=this.onClose.bind(this);this.socket.onclose=this.onClose.bind(this)};WSSource.prototype.resume=function(secondsHeadroom){};WSSource.prototype.onOpen=function(){this.progress=1};WSSource.prototype.onClose=function(){if(this.shouldAttemptReconnect){clearTimeout(this.reconnectTimeoutId);this.reconnectTimeoutId=setTimeout(function(){this.start()}.bind(this),this.reconnectInterval1e3)}};WSSource.prototype.onMessage=function(ev){var isFirstChunk=!this.established;this.established=true;if(isFirstChunk&&this.onEstablishedCallback){this.onEstablishedCallback(this)}if(this.destination){this.destination.write(ev.data)}};return WSSource}();JSMpeg.Demuxer.TS=function(){\"use strict\";var TS=function(options){this.bits=null;this.leftoverBytes=null;this.guessVideoFrameEnd=true;this.pidsToStreamIds={};this.pesPacketInfo={};this.startTime=0;this.currentTime=0};TS.prototype.connect=function(streamId,destination){this.pesPacketInfostreamId={destination:destination,currentLength:0,totalLength:0,pts:0,buffers:[]}};TS.prototype.write=function(buffer){if(this.leftoverBytes){var totalLength=buffer.byteLength+this.leftoverBytes.byteLength;this.bits=new JSMpeg.BitBuffer(totalLength);this.bits.write(this.leftoverBytes,buffer)}else{this.bits=new JSMpeg.BitBuffer(buffer)}while(this.bits.has(188<<3)&&this.parsePacket()){}var leftoverCount=this.bits.byteLength-(this.bits.index>>3);this.leftoverBytes=leftoverCount>0?this.bits.bytes.subarray(this.bits.index>>3):null};TS.prototype.parsePacket=function(){if(this.bits.read(8)!==71){if(!this.resync()){return false}}var end=(this.bits.index>>3)+187;var transportError=this.bits.read(1),payloadStart=this.bits.read(1),transportPriority=this.bits.read(1),pid=this.bits.read(13),transportScrambling=this.bits.read(2),adaptationField=this.bits.read(2),continuityCounter=this.bits.read(4);var streamId=this.pidsToStreamIdspid;if(payloadStart&&streamId){var pi=this.pesPacketInfostreamId;if(pi&&pi.currentLength){this.packetComplete(pi)}}if(adaptationField&1){if(adaptationField&2){var adaptationFieldLength=this.bits.read(8);this.bits.skip(adaptationFieldLength<<3)}if(payloadStart&&this.bits.nextBytesAreStartCode()){this.bits.skip(24);streamId=this.bits.read(8);this.pidsToStreamIdspid=streamId;var packetLength=this.bits.read(16);this.bits.skip(8);var ptsDtsFlag=this.bits.read(2);this.bits.skip(6);var headerLength=this.bits.read(8);var payloadBeginIndex=this.bits.index+(headerLength<<3);var pi=this.pesPacketInfostreamId;if(pi){var pts=0;if(ptsDtsFlag&2){this.bits.skip(4);var p32_30=this.bits.read(3);this.bits.skip(1);var p29_15=this.bits.read(15);this.bits.skip(1);var p14_0=this.bits.read(15);this.bits.skip(1);pts=(p32_301073741824+p29_1532768+p14_0)/9e4;this.currentTime=pts;if(this.startTime===-1){this.startTime=pts}}var payloadLength=packetLength?packetLength-headerLength-3:0;this.packetStart(pi,pts,payloadLength)}this.bits.index=payloadBeginIndex}if(streamId){var pi=this.pesPacketInfostreamId;if(pi){var start=this.bits.index>>3;var complete=this.packetAddData(pi,start,end);var hasPadding=!payloadStart&&adaptationField&2;if(complete||this.guessVideoFrameEnd&&hasPadding){this.packetComplete(pi)}}}}this.bits.index=end<<3;return true};TS.prototype.resync=function(){if(!this.bits.has(1886<<3)){return false}var byteIndex=this.bits.index>>3;for(var i=0;i<187;i++){if(this.bits.bytesbyteIndex+i===71){var foundSync=true;for(var j=1;j<5;j++){if(this.bits.bytes[byteIndex+i+188j]!==71){foundSync=false;break}}if(foundSync){this.bits.index=byteIndex+i+1<<3;return true}}}console.warn(\"JSMpeg: Possible garbage data. Skipping.\");this.bits.skip(187<<3);return false};TS.prototype.packetStart=function(pi,pts,payloadLength){pi.totalLength=payloadLength;pi.currentLength=0;pi.pts=pts};TS.prototype.packetAddData=function(pi,start,end){pi.buffers.push(this.bits.bytes.subarray(start,end));pi.currentLength+=end-start;var complete=pi.totalLength!==0&&pi.currentLength>=pi.totalLength;return complete};TS.prototype.packetComplete=function(pi){pi.destination.write(pi.pts,pi.buffers);pi.totalLength=0;pi.currentLength=0;pi.buffers=[]};TS.STREAM={PACK_HEADER:186,SYSTEM_HEADER:187,PROGRAM_MAP:188,PRIVATE_1:189,PADDING:190,PRIVATE_2:191,AUDIO_1:192,VIDEO_1:224,DIRECTORY:255};return TS}();JSMpeg.Decoder.Base=function(){\"use strict\";var BaseDecoder=function(options){this.destination=null;this.canPlay=false;this.collectTimestamps=!options.streaming;this.bytesWritten=0;this.timestamps=[];this.timestampIndex=0;this.startTime=0;this.decodedTime=0;Object.defineProperty(this,\"currentTime\",{get:this.getCurrentTime})};BaseDecoder.prototype.destroy=function(){};BaseDecoder.prototype.connect=function(destination){this.destination=destination};BaseDecoder.prototype.bufferGetIndex=function(){return this.bits.index};BaseDecoder.prototype.bufferSetIndex=function(index){this.bits.index=index};BaseDecoder.prototype.bufferWrite=function(buffers){return this.bits.write(buffers)};BaseDecoder.prototype.write=function(pts,buffers){if(this.collectTimestamps){if(this.timestamps.length===0){this.startTime=pts;this.decodedTime=pts}this.timestamps.push({index:this.bytesWritten<<3,time:pts})}this.bytesWritten+=this.bufferWrite(buffers);this.canPlay=true};BaseDecoder.prototype.seek=function(time){if(!this.collectTimestamps){return}this.timestampIndex=0;for(var i=0;i<this.timestamps.length;i++){if(this.timestampsi.time>time){break}this.timestampIndex=i}var ts=this.timestampsthis.timestampIndex;if(ts){this.bufferSetIndex(ts.index);this.decodedTime=ts.time}else{this.bufferSetIndex(0);this.decodedTime=this.startTime}};BaseDecoder.prototype.decode=function(){this.advanceDecodedTime(0)};BaseDecoder.prototype.advanceDecodedTime=function(seconds){if(this.collectTimestamps){var newTimestampIndex=-1;var currentIndex=this.bufferGetIndex();for(var i=this.timestampIndex;i<this.timestamps.length;i++){if(this.timestampsi.index>currentIndex){break}newTimestampIndex=i}if(newTimestampIndex!==-1&&newTimestampIndex!==this.timestampIndex){this.timestampIndex=newTimestampIndex;this.decodedTime=this.timestampsthis.timestampIndex.time;return}}this.decodedTime+=seconds};BaseDecoder.prototype.getCurrentTime=function(){return this.decodedTime};return BaseDecoder}();JSMpeg.Decoder.MPEG1Video=function(){\"use strict\";var MPEG1=function(options){JSMpeg.Decoder.Base.call(this,options);this.onDecodeCallback=options.onVideoDecode;var bufferSize=options.videoBufferSize||5121024;var bufferMode=options.streaming?JSMpeg.BitBuffer.MODE.EVICT:JSMpeg.BitBuffer.MODE.EXPAND;this.bits=new JSMpeg.BitBuffer(bufferSize,bufferMode);this.customIntraQuantMatrix=new Uint8Array(64);this.customNonIntraQuantMatrix=new Uint8Array(64);this.blockData=new Int32Array(64);this.currentFrame=0;this.decodeFirstFrame=options.decodeFirstFrame!==false};MPEG1.prototype=Object.create(JSMpeg.Decoder.Base.prototype);MPEG1.prototype.constructor=MPEG1;MPEG1.prototype.write=function(pts,buffers){JSMpeg.Decoder.Base.prototype.write.call(this,pts,buffers);if(!this.hasSequenceHeader){if(this.bits.findStartCode(MPEG1.START.SEQUENCE)===-1){return false}this.decodeSequenceHeader();if(this.decodeFirstFrame){this.decode()}}};MPEG1.prototype.decode=function(){var startTime=JSMpeg.Now();if(!this.hasSequenceHeader){return false}if(this.bits.findStartCode(MPEG1.START.PICTURE)===-1){var bufferedBytes=this.bits.byteLength-(this.bits.index>>3);return false}this.decodePicture();this.advanceDecodedTime(1/this.frameRate);var elapsedTime=JSMpeg.Now()-startTime;if(this.onDecodeCallback){this.onDecodeCallback(this,elapsedTime)}return true};MPEG1.prototype.readHuffman=function(codeTable){var state=0;do{state=codeTablestate+this.bits.read(1)}while(state>=0&&codeTablestate!==0);return codeTablestate+2};MPEG1.prototype.frameRate=30;MPEG1.prototype.decodeSequenceHeader=function(){var newWidth=this.bits.read(12),newHeight=this.bits.read(12);this.bits.skip(4);this.frameRate=MPEG1.PICTURE_RATEthis.bits.read(4);this.bits.skip(18+1+10+1);if(newWidth!==this.width||newHeight!==this.height){this.width=newWidth;this.height=newHeight;this.initBuffers();if(this.destination){this.destination.resize(newWidth,newHeight)}}if(this.bits.read(1)){for(var i=0;i<64;i++){this.customIntraQuantMatrix[MPEG1.ZIG_ZAGi]=this.bits.read(8)}this.intraQuantMatrix=this.customIntraQuantMatrix}if(this.bits.read(1)){for(var i=0;i<64;i++){var idx=MPEG1.ZIG_ZAGi;this.customNonIntraQuantMatrixidx=this.bits.read(8)}this.nonIntraQuantMatrix=this.customNonIntraQuantMatrix}this.hasSequenceHeader=true};MPEG1.prototype.initBuffers=function(){this.intraQuantMatrix=MPEG1.DEFAULT_INTRA_QUANT_MATRIX;this.nonIntraQuantMatrix=MPEG1.DEFAULT_NON_INTRA_QUANT_MATRIX;this.mbWidth=this.width+15>>4;this.mbHeight=this.height+15>>4;this.mbSize=this.mbWidththis.mbHeight;this.codedWidth=this.mbWidth<<4;this.codedHeight=this.mbHeight<<4;this.codedSize=this.codedWidththis.codedHeight;this.halfWidth=this.mbWidth<<3;this.halfHeight=this.mbHeight<<3;this.currentY=new Uint8ClampedArray(this.codedSize);this.currentY32=new Uint32Array(this.currentY.buffer);this.currentCr=new Uint8ClampedArray(this.codedSize>>2);this.currentCr32=new Uint32Array(this.currentCr.buffer);this.currentCb=new Uint8ClampedArray(this.codedSize>>2);this.currentCb32=new Uint32Array(this.currentCb.buffer);this.forwardY=new Uint8ClampedArray(this.codedSize);this.forwardY32=new Uint32Array(this.forwardY.buffer);this.forwardCr=new Uint8ClampedArray(this.codedSize>>2);this.forwardCr32=new Uint32Array(this.forwardCr.buffer);this.forwardCb=new Uint8ClampedArray(this.codedSize>>2);this.forwardCb32=new Uint32Array(this.forwardCb.buffer)};MPEG1.prototype.currentY=null;MPEG1.prototype.currentCr=null;MPEG1.prototype.currentCb=null;MPEG1.prototype.pictureType=0;MPEG1.prototype.forwardY=null;MPEG1.prototype.forwardCr=null;MPEG1.prototype.forwardCb=null;MPEG1.prototype.fullPelForward=false;MPEG1.prototype.forwardFCode=0;MPEG1.prototype.forwardRSize=0;MPEG1.prototype.forwardF=0;MPEG1.prototype.decodePicture=function(skipOutput){this.currentFrame++;this.bits.skip(10);this.pictureType=this.bits.read(3);this.bits.skip(16);if(this.pictureType<=0||this.pictureType>=MPEG1.PICTURE_TYPE.B){return}if(this.pictureType===MPEG1.PICTURE_TYPE.PREDICTIVE){this.fullPelForward=this.bits.read(1);this.forwardFCode=this.bits.read(3);if(this.forwardFCode===0){return}this.forwardRSize=this.forwardFCode-1;this.forwardF=1<<this.forwardRSize}var code=0;do{code=this.bits.findNextStartCode()}while(code===MPEG1.START.EXTENSION||code===MPEG1.START.USER_DATA);while(code>=MPEG1.START.SLICE_FIRST&&code<=MPEG1.START.SLICE_LAST){this.decodeSlice(code&255);code=this.bits.findNextStartCode()}if(code!==-1){this.bits.rewind(32)}if(this.destination){this.destination.render(this.currentY,this.currentCr,this.currentCb,true)}if(this.pictureType===MPEG1.PICTURE_TYPE.INTRA||this.pictureType===MPEG1.PICTURE_TYPE.PREDICTIVE){var tmpY=this.forwardY,tmpY32=this.forwardY32,tmpCr=this.forwardCr,tmpCr32=this.forwardCr32,tmpCb=this.forwardCb,tmpCb32=this.forwardCb32;this.forwardY=this.currentY;this.forwardY32=this.currentY32;this.forwardCr=this.currentCr;this.forwardCr32=this.currentCr32;this.forwardCb=this.currentCb;this.forwardCb32=this.currentCb32;this.currentY=tmpY;this.currentY32=tmpY32;this.currentCr=tmpCr;this.currentCr32=tmpCr32;this.currentCb=tmpCb;this.currentCb32=tmpCb32}};MPEG1.prototype.quantizerScale=0;MPEG1.prototype.sliceBegin=false;MPEG1.prototype.decodeSlice=function(slice){this.sliceBegin=true;this.macroblockAddress=(slice-1)this.mbWidth-1;this.motionFwH=this.motionFwHPrev=0;this.motionFwV=this.motionFwVPrev=0;this.dcPredictorY=128;this.dcPredictorCr=128;this.dcPredictorCb=128;this.quantizerScale=this.bits.read(5);while(this.bits.read(1)){this.bits.skip(8)}do{this.decodeMacroblock()}while(!this.bits.nextBytesAreStartCode())};MPEG1.prototype.macroblockAddress=0;MPEG1.prototype.mbRow=0;MPEG1.prototype.mbCol=0;MPEG1.prototype.macroblockType=0;MPEG1.prototype.macroblockIntra=false;MPEG1.prototype.macroblockMotFw=false;MPEG1.prototype.motionFwH=0;MPEG1.prototype.motionFwV=0;MPEG1.prototype.motionFwHPrev=0;MPEG1.prototype.motionFwVPrev=0;MPEG1.prototype.decodeMacroblock=function(){var increment=0,t=this.readHuffman(MPEG1.MACROBLOCK_ADDRESS_INCREMENT);while(t===34){t=this.readHuffman(MPEG1.MACROBLOCK_ADDRESS_INCREMENT)}while(t===35){increment+=33;\n\nt=this.readHuffman(MPEG1.MACROBLOCK_ADDRESS_INCREMENT)}increment+=t;if(this.sliceBegin){this.sliceBegin=false;this.macroblockAddress+=increment}else{if(this.macroblockAddress+increment>=this.mbSize){return}if(increment>1){this.dcPredictorY=128;this.dcPredictorCr=128;this.dcPredictorCb=128;if(this.pictureType===MPEG1.PICTURE_TYPE.PREDICTIVE){this.motionFwH=this.motionFwHPrev=0;this.motionFwV=this.motionFwVPrev=0}}while(increment>1){this.macroblockAddress++;this.mbRow=this.macroblockAddress/this.mbWidth|0;this.mbCol=this.macroblockAddress%this.mbWidth;this.copyMacroblock(this.motionFwH,this.motionFwV,this.forwardY,this.forwardCr,this.forwardCb);increment--}this.macroblockAddress++}this.mbRow=this.macroblockAddress/this.mbWidth|0;this.mbCol=this.macroblockAddress%this.mbWidth;var mbTable=MPEG1.MACROBLOCK_TYPEthis.pictureType;this.macroblockType=this.readHuffman(mbTable);this.macroblockIntra=this.macroblockType&1;this.macroblockMotFw=this.macroblockType&8;if((this.macroblockType&16)!==0){this.quantizerScale=this.bits.read(5)}if(this.macroblockIntra){this.motionFwH=this.motionFwHPrev=0;this.motionFwV=this.motionFwVPrev=0}else{this.dcPredictorY=128;this.dcPredictorCr=128;this.dcPredictorCb=128;this.decodeMotionVectors();this.copyMacroblock(this.motionFwH,this.motionFwV,this.forwardY,this.forwardCr,this.forwardCb)}var cbp=(this.macroblockType&2)!==0?this.readHuffman(MPEG1.CODE_BLOCK_PATTERN):this.macroblockIntra?63:0;for(var block=0,mask=32;block<6;block++){if((cbp&mask)!==0){this.decodeBlock(block)}mask>>=1}};MPEG1.prototype.decodeMotionVectors=function(){var code,d,r=0;if(this.macroblockMotFw){code=this.readHuffman(MPEG1.MOTION);if(code!==0&&this.forwardF!==1){r=this.bits.read(this.forwardRSize);d=(Math.abs(code)-1<<this.forwardRSize)+r+1;if(code<0){d=-d}}else{d=code}this.motionFwHPrev+=d;if(this.motionFwHPrev>(this.forwardF<<4)-1){this.motionFwHPrev-=this.forwardF<<5}else if(this.motionFwHPrev<-this.forwardF<<4){this.motionFwHPrev+=this.forwardF<<5}this.motionFwH=this.motionFwHPrev;if(this.fullPelForward){this.motionFwH<<=1}code=this.readHuffman(MPEG1.MOTION);if(code!==0&&this.forwardF!==1){r=this.bits.read(this.forwardRSize);d=(Math.abs(code)-1<<this.forwardRSize)+r+1;if(code<0){d=-d}}else{d=code}this.motionFwVPrev+=d;if(this.motionFwVPrev>(this.forwardF<<4)-1){this.motionFwVPrev-=this.forwardF<<5}else if(this.motionFwVPrev<-this.forwardF<<4){this.motionFwVPrev+=this.forwardF<<5}this.motionFwV=this.motionFwVPrev;if(this.fullPelForward){this.motionFwV<<=1}}else if(this.pictureType===MPEG1.PICTURE_TYPE.PREDICTIVE){this.motionFwH=this.motionFwHPrev=0;this.motionFwV=this.motionFwVPrev=0}};MPEG1.prototype.copyMacroblock=function(motionH,motionV,sY,sCr,sCb){var width,scan,H,V,oddH,oddV,src,dest,last;var dY=this.currentY32,dCb=this.currentCb32,dCr=this.currentCr32;width=this.codedWidth;scan=width-16;H=motionH>>1;V=motionV>>1;oddH=(motionH&1)===1;oddV=(motionV&1)===1;src=((this.mbRow<<4)+V)width+(this.mbCol<<4)+H;dest=this.mbRowwidth+this.mbCol<<2;last=dest+(width<<2);var x,y1,y2,y;if(oddH){if(oddV){while(dest<last){y1=sYsrc+sYsrc+width;src++;for(x=0;x<4;x++){y2=sYsrc+sYsrc+width;src++;y=y1+y2+2>>2&255;y1=sYsrc+sYsrc+width;src++;y|=y1+y2+2<<6&65280;y2=sYsrc+sYsrc+width;src++;y|=y1+y2+2<<14&16711680;y1=sYsrc+sYsrc+width;src++;y|=y1+y2+2<<22&4278190080;dYdest++=y}dest+=scan>>2;src+=scan-1}}else{while(dest<last){y1=sYsrc++;for(x=0;x<4;x++){y2=sYsrc++;y=y1+y2+1>>1&255;y1=sYsrc++;y|=y1+y2+1<<7&65280;y2=sYsrc++;y|=y1+y2+1<<15&16711680;y1=sYsrc++;y|=y1+y2+1<<23&4278190080;dYdest++=y}dest+=scan>>2;src+=scan-1}}}else{if(oddV){while(dest<last){for(x=0;x<4;x++){y=sYsrc+sYsrc+width+1>>1&255;src++;y|=sYsrc+sYsrc+width+1<<7&65280;src++;y|=sYsrc+sYsrc+width+1<<15&16711680;src++;y|=sYsrc+sYsrc+width+1<<23&4278190080;src++;dYdest++=y}dest+=scan>>2;src+=scan}}else{while(dest<last){for(x=0;x<4;x++){y=sYsrc;src++;y|=sYsrc<<8;src++;y|=sYsrc<<16;src++;y|=sYsrc<<24;src++;dYdest++=y}dest+=scan>>2;src+=scan}}}width=this.halfWidth;scan=width-8;H=motionH/2>>1;V=motionV/2>>1;oddH=(motionH/2&1)===1;oddV=(motionV/2&1)===1;src=((this.mbRow<<3)+V)width+(this.mbCol<<3)+H;dest=this.mbRowwidth+this.mbCol<<1;last=dest+(width<<1);var cr1,cr2,cr,cb1,cb2,cb;if(oddH){if(oddV){while(dest<last){cr1=sCrsrc+sCrsrc+width;cb1=sCbsrc+sCbsrc+width;src++;for(x=0;x<2;x++){cr2=sCrsrc+sCrsrc+width;cb2=sCbsrc+sCbsrc+width;src++;cr=cr1+cr2+2>>2&255;cb=cb1+cb2+2>>2&255;cr1=sCrsrc+sCrsrc+width;cb1=sCbsrc+sCbsrc+width;src++;cr|=cr1+cr2+2<<6&65280;cb|=cb1+cb2+2<<6&65280;cr2=sCrsrc+sCrsrc+width;cb2=sCbsrc+sCbsrc+width;src++;cr|=cr1+cr2+2<<14&16711680;cb|=cb1+cb2+2<<14&16711680;cr1=sCrsrc+sCrsrc+width;cb1=sCbsrc+sCbsrc+width;src++;cr|=cr1+cr2+2<<22&4278190080;cb|=cb1+cb2+2<<22&4278190080;dCrdest=cr;dCbdest=cb;dest++}dest+=scan>>2;src+=scan-1}}else{while(dest<last){cr1=sCrsrc;cb1=sCbsrc;src++;for(x=0;x<2;x++){cr2=sCrsrc;cb2=sCbsrc++;cr=cr1+cr2+1>>1&255;cb=cb1+cb2+1>>1&255;cr1=sCrsrc;cb1=sCbsrc++;cr|=cr1+cr2+1<<7&65280;cb|=cb1+cb2+1<<7&65280;cr2=sCrsrc;cb2=sCbsrc++;cr|=cr1+cr2+1<<15&16711680;cb|=cb1+cb2+1<<15&16711680;cr1=sCrsrc;cb1=sCbsrc++;cr|=cr1+cr2+1<<23&4278190080;cb|=cb1+cb2+1<<23&4278190080;dCrdest=cr;dCbdest=cb;dest++}dest+=scan>>2;src+=scan-1}}}else{if(oddV){while(dest<last){for(x=0;x<2;x++){cr=sCrsrc+sCrsrc+width+1>>1&255;cb=sCbsrc+sCbsrc+width+1>>1&255;src++;cr|=sCrsrc+sCrsrc+width+1<<7&65280;cb|=sCbsrc+sCbsrc+width+1<<7&65280;src++;cr|=sCrsrc+sCrsrc+width+1<<15&16711680;cb|=sCbsrc+sCbsrc+width+1<<15&16711680;src++;cr|=sCrsrc+sCrsrc+width+1<<23&4278190080;cb|=sCbsrc+sCbsrc+width+1<<23&4278190080;src++;dCrdest=cr;dCbdest=cb;dest++}dest+=scan>>2;src+=scan}}else{while(dest<last){for(x=0;x<2;x++){cr=sCrsrc;cb=sCbsrc;src++;cr|=sCrsrc<<8;cb|=sCbsrc<<8;src++;cr|=sCrsrc<<16;cb|=sCbsrc<<16;src++;cr|=sCrsrc<<24;cb|=sCbsrc<<24;src++;dCrdest=cr;dCbdest=cb;dest++}dest+=scan>>2;src+=scan}}}};MPEG1.prototype.dcPredictorY=0;MPEG1.prototype.dcPredictorCr=0;MPEG1.prototype.dcPredictorCb=0;MPEG1.prototype.blockData=null;MPEG1.prototype.decodeBlock=function(block){var n=0,quantMatrix;if(this.macroblockIntra){var predictor,dctSize;if(block<4){predictor=this.dcPredictorY;dctSize=this.readHuffman(MPEG1.DCT_DC_SIZE_LUMINANCE)}else{predictor=block===4?this.dcPredictorCr:this.dcPredictorCb;dctSize=this.readHuffman(MPEG1.DCT_DC_SIZE_CHROMINANCE)}if(dctSize>0){var differential=this.bits.read(dctSize);if((differential&1<<dctSize-1)!==0){this.blockData0=predictor+differential}else{this.blockData0=predictor+(-1<<dctSize|differential+1)}}else{this.blockData0=predictor}if(block<4){this.dcPredictorY=this.blockData0}else if(block===4){this.dcPredictorCr=this.blockData0}else{this.dcPredictorCb=this.blockData0}this.blockData0<<=3+5;quantMatrix=this.intraQuantMatrix;n=1}else{quantMatrix=this.nonIntraQuantMatrix}var level=0;while(true){var run=0,coeff=this.readHuffman(MPEG1.DCT_COEFF);if(coeff===1&&n>0&&this.bits.read(1)===0){break}if(coeff===65535){run=this.bits.read(6);level=this.bits.read(8);if(level===0){level=this.bits.read(8)}else if(level===128){level=this.bits.read(8)-256}else if(level>128){level=level-256}}else{run=coeff>>8;level=coeff&255;if(this.bits.read(1)){level=-level}}n+=run;var dezigZagged=MPEG1.ZIG_ZAGn;n++;level<<=1;if(!this.macroblockIntra){level+=level<0?-1:1}level=levelthis.quantizerScalequantMatrixdezigZagged>>4;if((level&1)===0){level-=level>0?1:-1}if(level>2047){level=2047}else if(level<-2048){level=-2048}this.blockDatadezigZagged=levelMPEG1.PREMULTIPLIER_MATRIXdezigZagged}var destArray,destIndex,scan;if(block<4){destArray=this.currentY;scan=this.codedWidth-8;destIndex=this.mbRowthis.codedWidth+this.mbCol<<4;if((block&1)!==0){destIndex+=8}if((block&2)!==0){destIndex+=this.codedWidth<<3}}else{destArray=block===4?this.currentCb:this.currentCr;scan=(this.codedWidth>>1)-8;destIndex=(this.mbRowthis.codedWidth<<2)+(this.mbCol<<3)}if(this.macroblockIntra){if(n===1){MPEG1.CopyValueToDestination(this.blockData0+128>>8,destArray,destIndex,scan);this.blockData0=0}else{MPEG1.IDCT(this.blockData);MPEG1.CopyBlockToDestination(this.blockData,destArray,destIndex,scan);JSMpeg.Fill(this.blockData,0)}}else{if(n===1){MPEG1.AddValueToDestination(this.blockData0+128>>8,destArray,destIndex,scan);this.blockData0=0}else{MPEG1.IDCT(this.blockData);MPEG1.AddBlockToDestination(this.blockData,destArray,destIndex,scan);JSMpeg.Fill(this.blockData,0)}}n=0};MPEG1.CopyBlockToDestination=function(block,dest,index,scan){for(var n=0;n<64;n+=8,index+=scan+8){destindex+0=blockn+0;destindex+1=blockn+1;destindex+2=blockn+2;destindex+3=blockn+3;destindex+4=blockn+4;destindex+5=blockn+5;destindex+6=blockn+6;destindex+7=blockn+7}};MPEG1.AddBlockToDestination=function(block,dest,index,scan){for(var n=0;n<64;n+=8,index+=scan+8){destindex+0+=blockn+0;destindex+1+=blockn+1;destindex+2+=blockn+2;destindex+3+=blockn+3;destindex+4+=blockn+4;destindex+5+=blockn+5;destindex+6+=blockn+6;destindex+7+=blockn+7}};MPEG1.CopyValueToDestination=function(value,dest,index,scan){for(var n=0;n<64;n+=8,index+=scan+8){destindex+0=value;destindex+1=value;destindex+2=value;destindex+3=value;destindex+4=value;destindex+5=value;destindex+6=value;destindex+7=value}};MPEG1.AddValueToDestination=function(value,dest,index,scan){for(var n=0;n<64;n+=8,index+=scan+8){destindex+0+=value;destindex+1+=value;destindex+2+=value;destindex+3+=value;destindex+4+=value;destindex+5+=value;destindex+6+=value;destindex+7+=value}};MPEG1.IDCT=function(block){var b1,b3,b4,b6,b7,tmp1,tmp2,m0,x0,x1,x2,x3,x4,y3,y4,y5,y6,y7;for(var i=0;i<8;++i){b1=block[48+i];b3=block2*8+i+block6*8+i;b4=block5*8+i-block3*8+i;tmp1=block1*8+i+block7*8+i;tmp2=block3*8+i+block5*8+i;b6=block1*8+i-block7*8+i;b7=tmp1+tmp2;m0=block0*8+i;x4=(b6473-b4196+128>>8)-b7;x0=x4-((tmp1-tmp2)362+128>>8);x1=m0-b1;x2=((block[28+i]-block6*8+i)362+128>>8)-b3;x3=m0+b1;y3=x1+x2;y4=x3+b3;y5=x1-x2;y6=x3-b3;y7=-x0-(b4473+b6196+128>>8);block[08+i]=b7+y4;block1*8+i=x4+y3;block2*8+i=y5-x0;block3*8+i=y6-y7;block4*8+i=y6+y7;block5*8+i=x0+y5;block6*8+i=y3-x4;block7*8+i=y4-b7}for(var i=0;i<64;i+=8){b1=block4+i;b3=block2+i+block6+i;b4=block5+i-block3+i;tmp1=block1+i+block7+i;tmp2=block3+i+block5+i;b6=block1+i-block7+i;b7=tmp1+tmp2;m0=block0+i;x4=(b6473-b4196+128>>8)-b7;x0=x4-((tmp1-tmp2)362+128>>8);x1=m0-b1;x2=((block2+i-block6+i)362+128>>8)-b3;x3=m0+b1;y3=x1+x2;y4=x3+b3;y5=x1-x2;y6=x3-b3;y7=-x0-(b4473+b6196+128>>8);block0+i=b7+y4+128>>8;block1+i=x4+y3+128>>8;block2+i=y5-x0+128>>8;block3+i=y6-y7+128>>8;block4+i=y6+y7+128>>8;block5+i=x0+y5+128>>8;block6+i=y3-x4+128>>8;block7+i=y4-b7+128>>8}};MPEG1.PICTURE_RATE=0,23.976,24,25,29.97,30,50,59.94,60,0,0,0,0,0,0,0;MPEG1.ZIG_ZAG=new Uint8Array(0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63);MPEG1.DEFAULT_INTRA_QUANT_MATRIX=new Uint8Array(8,16,19,22,26,27,29,34,16,16,22,24,27,29,34,37,19,22,26,27,29,34,34,38,22,22,26,27,29,34,37,40,22,26,27,29,32,35,40,48,26,27,29,32,35,40,48,58,26,27,29,34,38,46,56,69,27,29,35,38,46,56,69,83);MPEG1.DEFAULT_NON_INTRA_QUANT_MATRIX=new Uint8Array(16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16);MPEG1.PREMULTIPLIER_MATRIX=new Uint8Array(32,44,42,38,32,25,17,9,44,62,58,52,44,35,24,12,42,58,55,49,42,33,23,12,38,52,49,44,38,30,20,10,32,44,42,38,32,25,17,9,25,35,33,30,25,20,14,7,17,24,23,20,17,14,9,5,9,12,12,10,9,7,5,2);MPEG1.MACROBLOCK_ADDRESS_INCREMENT=new Int16Array(13,23,0,33,43,0,0,0,1,53,63,0,73,83,0,93,103,0,113,123,0,0,0,3,0,0,2,133,143,0,153,163,0,0,0,5,0,0,4,173,183,0,193,203,0,0,0,7,0,0,6,213,223,0,233,243,0,253,263,0,273,283,0,-1,293,0,-1,303,0,313,323,0,333,343,0,353,363,0,373,383,0,0,0,9,0,0,8,393,403,0,413,423,0,433,443,0,453,463,0,0,0,15,0,0,14,0,0,13,0,0,12,0,0,11,0,0,10,473,-1,0,-1,483,0,493,503,0,513,523,0,533,543,0,553,563,0,573,583,0,593,603,0,613,-1,0,-1,623,0,633,643,0,653,663,0,673,683,0,693,703,0,713,723,0,733,743,0,0,0,21,0,0,20,0,0,19,0,0,18,0,0,17,0,0,16,0,0,35,0,0,34,0,0,33,0,0,32,0,0,31,0,0,30,0,0,29,0,0,28,0,0,27,0,0,26,0,0,25,0,0,24,0,0,23,0,0,22);MPEG1.MACROBLOCK_TYPE_INTRA=new Int8Array(13,23,0,-1,3*3,0,0,0,1,0,0,17);MPEG1.MACROBLOCK_TYPE_PREDICTIVE=new Int8Array(13,23,0,33,43,0,0,0,10,53,63,0,0,0,2,73,83,0,0,0,8,93,103,0,113,123,0,-1,13*3,0,0,0,18,0,0,26,0,0,1,0,0,17);MPEG1.MACROBLOCK_TYPE_B=new Int8Array(13,23,0,33,53,0,43,63,0,83,73,0,0,0,12,93,103,0,0,0,14,133,143,0,123,113,0,0,0,4,0,0,6,183,163,0,153,173,0,0,0,8,0,0,10,-1,193,0,0,0,1,203,21*3,0,0,0,30,0,0,17,0,0,22,0,0,26);MPEG1.MACROBLOCK_TYPE=null,MPEG1.MACROBLOCK_TYPE_INTRA,MPEG1.MACROBLOCK_TYPE_PREDICTIVE,MPEG1.MACROBLOCK_TYPE_B;MPEG1.CODE_BLOCK_PATTERN=new Int16Array(23,13,0,33,63,0,43,53,0,83,113,0,123,133,0,93,73,0,103,143,0,203,193,0,183,163,0,233,173,0,273,253,0,213,283,0,153,223,0,243,263,0,0,0,60,353,403,0,443,483,0,383,363,0,423,473,0,293,313,0,393,323,0,0,0,32,453,463,0,333,413,0,433,343,0,0,0,4,303,373,0,0,0,8,0,0,16,0,0,44,503,563,0,0,0,28,0,0,52,0,0,62,613,593,0,523,603,0,0,0,1,553,543,0,0,0,61,0,0,56,573,583,0,0,0,2,0,0,40,513,623,0,0,0,48,643,633,0,493,533,0,0,0,20,0,0,12,803,833,0,0,0,63,773,753,0,653,733,0,843,663,0,0,0,24,0,0,36,0,0,3,693,873,0,813,793,0,683,713,0,703,783,0,673,763,0,723,743,0,863,853,0,883,823,0,-1,943,0,953,973,0,0,0,33,0,0,9,1063,1103,0,1023,1163,0,0,0,5,0,0,10,933,893,0,0,0,6,0,0,18,0,0,17,0,0,34,1133,1193,0,1033,1043,0,903,923,0,1093,1073,0,1173,1183,0,1013,993,0,983,963,0,1003,913,0,1143,1153,0,1053,1083,0,1123,1113,0,1213,1253,0,0,0,41,0,0,14,0,0,21,1243,1223,0,1203,123*3,0,0,0,11,0,0,19,0,0,7,0,0,35,0,0,13,0,0,50,0,0,49,0,0,58,0,0,37,0,0,25,0,0,45,0,0,57,0,0,26,0,0,29,0,0,38,0,0,53,0,0,23,0,0,43,0,0,46,0,0,42,0,0,22,0,0,54,0,0,51,0,0,15,0,0,30,0,0,39,0,0,47,0,0,55,0,0,27,0,0,59,0,0,31);MPEG1.MOTION=new Int16Array(13,23,0,43,33,0,0,0,0,63,53,0,83,73,0,0,0,-1,0,0,1,93,103,0,123,113,0,0,0,2,0,0,-2,143,153,0,163,133,0,203,183,0,0,0,3,0,0,-3,173,193,0,-1,233,0,273,253,0,263,213,0,243,223,0,323,283,0,293,313,0,-1,333,0,363,353,0,0,0,-4,303,343,0,0,0,4,0,0,-7,0,0,5,373,413,0,0,0,-5,0,0,7,383,403,0,423,393,0,0,0,-6,0,0,6,513,543,0,503,493,0,453,463,0,523,473,0,433,533,0,443,483,0,0,0,10,0,0,9,0,0,8,0,0,-8,573,663,0,0,0,-9,603,643,0,563,613,0,553,623,0,583,633,0,0,0,-10,593,653,0,0,0,12,0,0,16,0,0,13,0,0,14,0,0,11,0,0,15,0,0,-16,0,0,-12,0,0,-14,0,0,-15,0,0,-11,0,0,-13);MPEG1.DCT_DC_SIZE_LUMINANCE=new Int8Array(23,13,0,63,53,0,33,43,0,0,0,1,0,0,2,93,83,0,73,103,0,0,0,0,123,113,0,0,0,4,0,0,3,133,143,0,0,0,5,0,0,6,163,153,0,17*3,-1,0,0,0,7,0,0,8);MPEG1.DCT_DC_SIZE_CHROMINANCE=new Int8Array(23,13,0,43,33,0,63,53,0,83,73,0,0,0,2,0,0,1,0,0,0,103,93,0,0,0,3,123,113,0,0,0,4,143,133,0,0,0,5,163,153,0,0,0,6,17*3,-1,0,0,0,7,0,0,8);MPEG1.DCT_COEFF=new Int32Array(13,23,0,43,33,0,0,0,1,73,83,0,63,53,0,133,93,0,113,103,0,143,123,0,0,0,257,203,223,0,183,213,0,163,193,0,0,0,513,173,153,0,0,0,2,0,0,3,273,253,0,293,313,0,243,263,0,323,303,0,0,0,1025,233,283,0,0,0,769,0,0,258,0,0,1793,0,0,65535,0,0,1537,373,363,0,0,0,1281,353,343,0,393,383,0,333,423,0,403,413,0,523,503,0,543,533,0,483,493,0,433,453,0,463,443,0,0,0,2049,0,0,4,0,0,514,0,0,2305,513,473,0,553,573,0,603,563,0,593,583,0,613,623,0,0,0,2561,0,0,3329,0,0,6,0,0,259,0,0,5,0,0,770,0,0,2817,0,0,3073,763,753,0,673,703,0,733,713,0,783,743,0,723,773,0,693,643,0,683,633,0,663,653,0,813,873,0,913,803,0,823,793,0,833,863,0,933,923,0,843,853,0,903,943,0,883,893,0,0,0,515,0,0,260,0,0,7,0,0,1026,0,0,1282,0,0,4097,0,0,3841,0,0,3585,1053,1073,0,1113,1143,0,1043,973,0,1253,1193,0,963,983,0,-1,1233,0,953,1013,0,1063,1213,0,993,1023,0,1133,1033,0,1123,1163,0,1103,1003,0,1243,1153,0,1173,1223,0,1093,1183,0,1203,1083,0,1273,1363,0,1393,1403,0,1303,1263,0,1453,1463,0,1283,1293,0,0,0,2050,1323,1343,0,1553,1543,0,0,0,8,1373,1333,0,1433,1443,0,1513,1383,0,1423,1413,0,0,0,10,0,0,9,0,0,11,0,0,5377,0,0,1538,0,0,771,0,0,5121,0,0,1794,0,0,4353,0,0,4609,0,0,4865,1483,1523,0,0,0,1027,1533,1503,0,0,0,261,1313,1353,0,0,0,516,1493,1473,0,1723,1733,0,1623,1583,0,1703,1613,0,1683,1663,0,1573,1793,0,1693,1673,0,1743,1713,0,1783,1773,0,1563,1593,0,1643,1653,0,1833,1823,0,1753,1763,0,0,0,263,0,0,2562,0,0,2306,0,0,5633,0,0,5889,0,0,6401,0,0,6145,0,0,1283,0,0,772,0,0,13,0,0,12,0,0,14,0,0,15,0,0,517,0,0,6657,0,0,262,1803,1813,0,1603,1633,0,1963,1993,0,0,0,27,2033,1853,0,2023,2013,0,0,0,19,0,0,22,1973,2073,0,0,0,18,1913,1923,0,1883,1903,0,0,0,20,1843,1943,0,0,0,21,1863,1933,0,0,0,23,2043,1983,0,0,0,25,0,0,24,2003,2053,0,0,0,31,0,0,30,0,0,28,0,0,29,0,0,26,0,0,17,0,0,16,1893,2063,0,1873,1953,0,2183,2113,0,0,0,37,2153,2163,0,0,0,36,2103,2123,0,0,0,34,2133,2093,0,2213,2223,0,2193,2083,0,2173,2143,0,2233,220*3,0,0,0,35,0,0,267,0,0,40,0,0,268,0,0,266,0,0,32,0,0,264,0,0,265,0,0,38,0,0,269,0,0,270,0,0,33,0,0,39,0,0,7937,0,0,6913,0,0,7681,0,0,4098,0,0,7425,0,0,7169,0,0,271,0,0,274,0,0,273,0,0,272,0,0,1539,0,0,2818,0,0,3586,0,0,3330,0,0,3074,0,0,3842);MPEG1.PICTURE_TYPE={INTRA:1,PREDICTIVE:2,B:3};MPEG1.START={SEQUENCE:179,SLICE_FIRST:1,SLICE_LAST:175,PICTURE:0,EXTENSION:181,USER_DATA:178};return MPEG1}();JSMpeg.Decoder.MPEG1VideoWASM=function(){\"use strict\";var MPEG1WASM=function(options){JSMpeg.Decoder.Base.call(this,options);this.onDecodeCallback=options.onVideoDecode;this.module=options.wasmModule;this.bufferSize=options.videoBufferSize||5121024;this.bufferMode=options.streaming?JSMpeg.BitBuffer.MODE.EVICT:JSMpeg.BitBuffer.MODE.EXPAND;this.decodeFirstFrame=options.decodeFirstFrame!==false;this.hasSequenceHeader=false};MPEG1WASM.prototype=Object.create(JSMpeg.Decoder.Base.prototype);MPEG1WASM.prototype.constructor=MPEG1WASM;MPEG1WASM.prototype.initializeWasmDecoder=function(){if(!this.module.instance){console.warn(\"JSMpeg: WASM module not compiled yet\");return}this.instance=this.module.instance;this.functions=this.module.instance.exports;this.decoder=this.functions._mpeg1_decoder_create(this.bufferSize,this.bufferMode)};MPEG1WASM.prototype.destroy=function(){if(!this.decoder){return}this.functions._mpeg1_decoder_destroy(this.decoder)};MPEG1WASM.prototype.bufferGetIndex=function(){if(!this.decoder){return}return this.functions._mpeg1_decoder_get_index(this.decoder)};MPEG1WASM.prototype.bufferSetIndex=function(index){if(!this.decoder){return}this.functions._mpeg1_decoder_set_index(this.decoder,index)};MPEG1WASM.prototype.bufferWrite=function(buffers){if(!this.decoder){this.initializeWasmDecoder()}var totalLength=0;for(var i=0;i<buffers.length;i++){totalLength+=buffersi.length}var ptr=this.functions._mpeg1_decoder_get_write_ptr(this.decoder,totalLength);for(var i=0;i<buffers.length;i++){this.instance.heapU8.set(buffersi,ptr);ptr+=buffersi.length}this.functions._mpeg1_decoder_did_write(this.decoder,totalLength);return totalLength};MPEG1WASM.prototype.write=function(pts,buffers){JSMpeg.Decoder.Base.prototype.write.call(this,pts,buffers);if(!this.hasSequenceHeader&&this.functions._mpeg1_decoder_has_sequence_header(this.decoder)){this.loadSequnceHeader()}};MPEG1WASM.prototype.loadSequnceHeader=function(){this.hasSequenceHeader=true;this.frameRate=this.functions._mpeg1_decoder_get_frame_rate(this.decoder);this.codedSize=this.functions._mpeg1_decoder_get_coded_size(this.decoder);if(this.destination){var w=this.functions._mpeg1_decoder_get_width(this.decoder);var h=this.functions._mpeg1_decoder_get_height(this.decoder);this.destination.resize(w,h)}if(this.decodeFirstFrame){this.decode()}};MPEG1WASM.prototype.decode=function(){var startTime=JSMpeg.Now();if(!this.decoder){return false}var didDecode=this.functions._mpeg1_decoder_decode(this.decoder);if(!didDecode){return false}if(this.destination){var ptrY=this.functions._mpeg1_decoder_get_y_ptr(this.decoder),ptrCr=this.functions._mpeg1_decoder_get_cr_ptr(this.decoder),ptrCb=this.functions._mpeg1_decoder_get_cb_ptr(this.decoder);var dy=this.instance.heapU8.subarray(ptrY,ptrY+this.codedSize);var dcr=this.instance.heapU8.subarray(ptrCr,ptrCr+(this.codedSize>>2));var dcb=this.instance.heapU8.subarray(ptrCb,ptrCb+(this.codedSize>>2));this.destination.render(dy,dcr,dcb,false)}this.advanceDecodedTime(1/this.frameRate);var elapsedTime=JSMpeg.Now()-startTime;if(this.onDecodeCallback){this.onDecodeCallback(this,elapsedTime)}return true};return MPEG1WASM}();JSMpeg.Decoder.MP2Audio=function(){\"use strict\";var MP2=function(options){JSMpeg.Decoder.Base.call(this,options);this.onDecodeCallback=options.onAudioDecode;var bufferSize=options.audioBufferSize||1281024;var bufferMode=options.streaming?JSMpeg.BitBuffer.MODE.EVICT:JSMpeg.BitBuffer.MODE.EXPAND;this.bits=new JSMpeg.BitBuffer(bufferSize,bufferMode);this.left=new Float32Array(1152);this.right=new Float32Array(1152);this.sampleRate=44100;this.D=new Float32Array(1024);this.D.set(MP2.SYNTHESIS_WINDOW,0);this.D.set(MP2.SYNTHESIS_WINDOW,512);this.V=new Float32Array(1024);this.U=new Int32Array(32);this.VPos=0;this.allocation=new Array(32),new Array(32);this.scaleFactorInfo=new Uint8Array(32),new Uint8Array(32);this.scaleFactor=new Array(32),new Array(32);this.sample=new Array(32),new Array(32);for(var j=0;j<2;j++){for(var i=0;i<32;i++){this.scaleFactorj=0,0,0;this.samplej=0,0,0}}};MP2.prototype=Object.create(JSMpeg.Decoder.Base.prototype);MP2.prototype.constructor=MP2;MP2.prototype.decode=function(){var startTime=JSMpeg.Now();var pos=this.bits.index>>3;if(pos>=this.bits.byteLength){return false}var decoded=this.decodeFrame(this.left,this.right);this.bits.index=pos+decoded<<3;if(!decoded){return false}if(this.destination){this.destination.play(this.sampleRate,this.left,this.right)}this.advanceDecodedTime(this.left.length/this.sampleRate);var elapsedTime=JSMpeg.Now()-startTime;if(this.onDecodeCallback){this.onDecodeCallback(this,elapsedTime)}return true};MP2.prototype.getCurrentTime=function(){var enqueuedTime=this.destination?this.destination.enqueuedTime:0;return this.decodedTime-enqueuedTime};MP2.prototype.decodeFrame=function(left,right){var sync=this.bits.read(11),version=this.bits.read(2),layer=this.bits.read(2),hasCRC=!this.bits.read(1);if(sync!==MP2.FRAME_SYNC||version!==MP2.VERSION.MPEG_1||layer!==MP2.LAYER.II){return 0}var bitrateIndex=this.bits.read(4)-1;if(bitrateIndex>13){return 0}var sampleRateIndex=this.bits.read(2);var sampleRate=MP2.SAMPLE_RATEsampleRateIndex;if(sampleRateIndex===3){return 0}if(version===MP2.VERSION.MPEG_2){sampleRateIndex+=4;bitrateIndex+=14}var padding=this.bits.read(1),privat=this.bits.read(1),mode=this.bits.read(2);var bound=0;if(mode===MP2.MODE.JOINT_STEREO){bound=this.bits.read(2)+1<<2}else{this.bits.skip(2);bound=mode===MP2.MODE.MONO?0:32}this.bits.skip(4);if(hasCRC){this.bits.skip(16)}var bitrate=MP2.BIT_RATEbitrateIndex,sampleRate=MP2.SAMPLE_RATEsampleRateIndex,frameSize=144e3bitrate/sampleRate+padding|0;var tab3=0;var sblimit=0;if(version===MP2.VERSION.MPEG_2){tab3=2;sblimit=30}else{var tab1=mode===MP2.MODE.MONO?0:1;var tab2=MP2.QUANT_LUT_STEP_1tab1;tab3=MP2.QUANT_LUT_STEP_2tab2;sblimit=tab3&63;tab3>>=6}if(bound>sblimit){bound=sblimit}for(var sb=0;sb<bound;sb++){this.allocation0=this.readAllocation(sb,tab3);this.allocation1=this.readAllocation(sb,tab3)}for(var sb=bound;sb<sblimit;sb++){this.allocation0=this.allocation1=this.readAllocation(sb,tab3)}var channels=mode===MP2.MODE.MONO?1:2;for(var sb=0;sb<sblimit;sb++){for(ch=0;ch<channels;ch++){if(this.allocationch){this.scaleFactorInfoch=this.bits.read(2)}}if(mode===MP2.MODE.MONO){this.scaleFactorInfo1=this.scaleFactorInfo0}}for(var sb=0;sb<sblimit;sb++){for(var ch=0;ch<channels;ch++){if(this.allocationch){var sf=this.scaleFactorch;switch(this.scaleFactorInfoch){case 0:sf0=this.bits.read(6);sf1=this.bits.read(6);sf2=this.bits.read(6);break;case 1:sf0=sf1=this.bits.read(6);sf2=this.bits.read(6);break;case 2:sf0=sf1=sf2=this.bits.read(6);break;case 3:sf0=this.bits.read(6);sf1=sf2=this.bits.read(6);break}}}if(mode===MP2.MODE.MONO){this.scaleFactor10=this.scaleFactor00;this.scaleFactor11=this.scaleFactor01;this.scaleFactor12=this.scaleFactor02}}var outPos=0;for(var part=0;part<3;part++){for(var granule=0;granule<4;granule++){for(var sb=0;sb<bound;sb++){this.readSamples(0,sb,part);this.readSamples(1,sb,part)}for(var sb=bound;sb<sblimit;sb++){this.readSamples(0,sb,part);this.sample10=this.sample00;this.sample11=this.sample01;this.sample12=this.sample02}for(var sb=sblimit;sb<32;sb++){this.sample00=0;this.sample01=0;this.sample02=0;this.sample10=0;this.sample11=0;this.sample12=0}for(var p=0;p<3;p++){this.VPos=this.VPos-64&1023;for(var ch=0;ch<2;ch++){MP2.MatrixTransform(this.samplech,p,this.V,this.VPos);JSMpeg.Fill(this.U,0);var dIndex=512-(this.VPos>>1);var vIndex=this.VPos%128>>1;while(vIndex<1024){for(var i=0;i<32;++i){this.Ui+=this.DdIndex++this.VvIndex++}vIndex+=128-32;dIndex+=64-32}vIndex=128-32+1024-vIndex;dIndex-=512-32;while(vIndex<1024){for(var i=0;i<32;++i){this.Ui+=this.DdIndex++this.VvIndex++}vIndex+=128-32;dIndex+=64-32}var outChannel=ch===0?left:right;for(var j=0;j<32;j++){outChanneloutPos+j=this.Uj/2147418112}}outPos+=32}}}this.sampleRate=sampleRate;return frameSize};MP2.prototype.readAllocation=function(sb,tab3){var tab4=MP2.QUANT_LUT_STEP_3tab3;var qtab=MP2.QUANT_LUT_STEP4tab4&15;return qtab?MP2.QUANT_TABqtab-1:0};MP2.prototype.readSamples=function(ch,sb,part){var q=this.allocationch,sf=this.scaleFactorchpart,sample=this.samplech,val=0;if(!q){sample0=sample1=sample2=0;return}if(sf===63){sf=0}else{var shift=sf/3|0;sf=MP2.SCALEFACTOR_BASEsf%3+(1<>1)>>shift}var adj=q.levels;if(q.group){val=this.bits.read(q.bits);sample0=val%adj;val=val/adj|0;sample1=val%adj;sample2=val/adj|0}else{sample0=this.bits.read(q.bits);sample1=this.bits.read(q.bits);sample2=this.bits.read(q.bits)}var scale=65536/(adj+1)|0;adj=(adj+1>>1)-1;val=(adj-sample0)scale;sample0=val(sf>>12)+(val(sf&4095)+2048>>12)>>12;val=(adj-sample1)scale;sample1=val(sf>>12)+(val(sf&4095)+2048>>12)>>12;val=(adj-sample2)scale;sample2=val(sf>>12)+(val(sf&4095)+2048>>12)>>12};MP2.MatrixTransform=function(s,ss,d,dp){var t01,t02,t03,t04,t05,t06,t07,t08,t09,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33;t01=s0+s31;t02=(s0-s31).500602998235;t03=s1+s30;t04=(s1-s30).505470959898;t05=s2+s29;t06=(s2-s29).515447309923;t07=s3+s28;t08=(s3-s28).53104259109;t09=s4+s27;t10=(s4-s27).553103896034;t11=s5+s26;t12=(s5-s26).582934968206;t13=s6+s25;t14=(s6-s25).622504123036;t15=s7+s24;t16=(s7-s24).674808341455;t17=s8+s23;t18=(s8-s23).744536271002;t19=s9+s22;t20=(s9-s22).839349645416;t21=s10+s21;t22=(s10-s21).972568237862;t23=s11+s20;t24=(s11-s20)1.16943993343;t25=s12+s19;t26=(s12-s19)1.48416461631;t27=s13+s18;t28=(s13-s18)2.05778100995;t29=s14+s17;t30=(s14-s17)3.40760841847;t31=s15+s16;t32=(s15-s16)10.1900081235;t33=t01+t31;t31=(t01-t31).502419286188;t01=t03+t29;t29=(t03-t29).52249861494;t03=t05+t27;t27=(t05-t27).566944034816;t05=t07+t25;t25=(t07-t25).64682178336;t07=t09+t23;t23=(t09-t23).788154623451;t09=t11+t21;t21=(t11-t21)1.06067768599;t11=t13+t19;t19=(t13-t19)1.72244709824;t13=t15+t17;t17=(t15-t17)5.10114861869;t15=t33+t13;t13=(t33-t13).509795579104;t33=t01+t11;t01=(t01-t11).601344886935;t11=t03+t09;t09=(t03-t09).899976223136;t03=t05+t07;t07=(t05-t07)2.56291544774;t05=t15+t03;t15=(t15-t03).541196100146;t03=t33+t11;t11=(t33-t11)1.30656296488;t33=t05+t03;t05=(t05-t03).707106781187;t03=t15+t11;t15=(t15-t11).707106781187;t03+=t15;t11=t13+t07;t13=(t13-t07).541196100146;t07=t01+t09;t09=(t01-t09)1.30656296488;t01=t11+t07;t07=(t11-t07).707106781187;t11=t13+t09;t13=(t13-t09).707106781187;t11+=t13;t01+=t11;t11+=t07;t07+=t13;t09=t31+t17;t31=(t31-t17).509795579104;t17=t29+t19;t29=(t29-t19).601344886935;t19=t27+t21;t21=(t27-t21).899976223136;t27=t25+t23;t23=(t25-t23)2.56291544774;t25=t09+t27;t09=(t09-t27).541196100146;t27=t17+t19;t19=(t17-t19)1.30656296488;t17=t25+t27;t27=(t25-t27).707106781187;t25=t09+t19;t19=(t09-t19).707106781187;t25+=t19;t09=t31+t23;t31=(t31-t23).541196100146;t23=t29+t21;t21=(t29-t21)1.30656296488;t29=t09+t23;t23=(t09-t23).707106781187;t09=t31+t21;t31=(t31-t21).707106781187;t09+=t31;t29+=t09;t09+=t23;t23+=t31;t17+=t29;t29+=t25;t25+=t09;t09+=t27;t27+=t23;t23+=t19;t19+=t31;t21=t02+t32;t02=(t02-t32).502419286188;t32=t04+t30;t04=(t04-t30).52249861494;t30=t06+t28;t28=(t06-t28).566944034816;t06=t08+t26;t08=(t08-t26).64682178336;t26=t10+t24;t10=(t10-t24).788154623451;t24=t12+t22;t22=(t12-t22)1.06067768599;t12=t14+t20;t20=(t14-t20)1.72244709824;t14=t16+t18;t16=(t16-t18)5.10114861869;t18=t21+t14;t14=(t21-t14).509795579104;t21=t32+t12;t32=(t32-t12).601344886935;t12=t30+t24;t24=(t30-t24).899976223136;t30=t06+t26;t26=(t06-t26)2.56291544774;t06=t18+t30;t18=(t18-t30).541196100146;t30=t21+t12;t12=(t21-t12)1.30656296488;t21=t06+t30;t30=(t06-t30).707106781187;t06=t18+t12;t12=(t18-t12).707106781187;t06+=t12;t18=t14+t26;t26=(t14-t26).541196100146;t14=t32+t24;t24=(t32-t24)1.30656296488;t32=t18+t14;t14=(t18-t14).707106781187;t18=t26+t24;t24=(t26-t24).707106781187;t18+=t24;t32+=t18;t18+=t14;t26=t14+t24;t14=t02+t16;t02=(t02-t16).509795579104;t16=t04+t20;t04=(t04-t20).601344886935;t20=t28+t22;t22=(t28-t22).899976223136;t28=t08+t10;t10=(t08-t10)2.56291544774;t08=t14+t28;t14=(t14-t28).541196100146;t28=t16+t20;t20=(t16-t20)1.30656296488;t16=t08+t28;t28=(t08-t28).707106781187;t08=t14+t20;t20=(t14-t20).707106781187;t08+=t20;t14=t02+t10;t02=(t02-t10).541196100146;t10=t04+t22;t22=(t04-t22)1.30656296488;t04=t14+t10;t10=(t14-t10).707106781187;t14=t02+t22;t02=(t02-t22).707106781187;t14+=t02;t04+=t14;t14+=t10;t10+=t02;t16+=t04;t04+=t08;t08+=t14;t14+=t28;t28+=t10;t10+=t20;t20+=t02;t21+=t16;t16+=t32;t32+=t04;t04+=t06;t06+=t08;t08+=t18;t18+=t14;t14+=t30;t30+=t28;t28+=t26;t26+=t10;t10+=t12;t12+=t20;t20+=t24;t24+=t02;ddp+48=-t33;ddp+49=ddp+47=-t21;ddp+50=ddp+46=-t17;ddp+51=