"use strict";var decoderStateIdle=0,decoderStateInitializing=1,decoderStateReady=2,decoderStateFinished=3,playerStateIdle=0,playerStatePlaying=1,playerStatePausing=2,maxVideoFrameQueueSize=132,downloadSpeedByteRateCoef=1.5;function FileInfo(e){this.url=e,this.size=0,this.offset=0,this.chunkSize=655360}function Player(e,t,i){this.videoObj=i,this.h264decoderTag=e,this.returnFuc=t,this.cutPicJson="",this.fileInfo=null,this.pcmPlayer=null,this.canvas=null,this.webglPlayer=null,this.callback=null,this.waitHeaderLength=524288,this.duration=0,this.pixFmt=0,this.videoWidth=0,this.videoHeight=0,this.yLength=0,this.uvLength=0,this.beginTimeOffset=0,this.decoderState=decoderStateIdle,this.playerState=playerStateIdle,this.decoding=!1,this.decodeInterval=1,this.audioQueue=[],this.videoQueue=[],this.videoRendererTimer=null,this.downloadTimer=null,this.chunkInterval=1,this.downloadSeqNo=0,this.downloading=!1,this.timeLabel=null,this.timeTrack=null,this.trackTimer=null,this.trackTimerInterval=500,this.displayDuration="00:00:00",this.audioEncoding="",this.audioChannels=0,this.audioSampleRate=0,this.seeking=!1,this.justSeeked=!1,this.urgent=!1,this.loadingDiv=null,this.logger=new Logger("Player"),this.videoTimeStamp=0,this.downloadVideo=function(e,t){var i,o,r;e&&0=this.waitHeaderLength&&(this.logger.logInfo("Opening decoder."),this.decoderState=decoderStateInitializing,e={t:kOpenDecoderReq,h264decoderTag:this.h264decoderTag},this.decodeWorker.postMessage(e)),this.downloadOneChunk()},Player.prototype.onFileDataUnderDecoderInitializing=function(){this.downloadOneChunk()},Player.prototype.onFileDataUnderDecoderReady=function(){},Player.prototype.onInitDecoder=function(e){this.playerState!=playerStateIdle&&(this.logger.logInfo("Init decoder response "+e.e+"."),0==e.e?this.downloadOneChunk(e.num):this.reportPlayError(e.e))},Player.prototype.onOpenDecoder=function(e){this.playerState!=playerStateIdle&&(this.logger.logInfo("Open decoder response "+e.e+"."),0==e.e?(this.onVideoParam(e.v),this.onAudioParam(e.a),this.decoderState=decoderStateReady,this.logger.logInfo("Decoder ready now."),this.startDecoding()):this.reportPlayError(e.e))},Player.prototype.onVideoParam=function(e){var t;this.playerState!=playerStateIdle&&(this.logger.logInfo("Video param duation:"+e.d+" pixFmt:"+e.p+" width:"+e.w+" height:"+e.h+"."),this.duration=e.d,this.pixFmt=e.p,this.videoWidth=e.w,this.videoHeight=e.h,this.yLength=this.videoWidth*this.videoHeight,this.uvLength=this.videoWidth/2*(this.videoHeight/2),this.timeTrack&&(this.timeTrack.min=0,this.timeTrack.max=this.duration,this.timeTrack.value=0,this.displayDuration=this.formatTime(this.duration/1e3)),e=1e3*this.waitHeaderLength/this.duration,t=downloadSpeedByteRateCoef*e,this.fileInfo.chunkSize,this.startDownloadTimer(),this.logger.logInfo("Byte rate:"+e+" target speed:"+t+" chunk interval:"+this.chunkInterval+"."))},Player.prototype.onAudioParam=function(e){if(this.playerState!=playerStateIdle){this.logger.logInfo("Audio param sampleFmt:"+e.f+" channels:"+e.c+" sampleRate:"+e.r+".");var t=e.f,i=e.c,e=e.r,o="16bitInt";switch(t){case 0:o="8bitInt";break;case 1:o="16bitInt";break;case 2:o="32bitInt";break;case 3:o="32bitFloat";break;default:this.logger.logError("Unsupported audio sampleFmt "+t+"!")}this.logger.logInfo("Audio encoding "+o+"."),this.pcmPlayer=new PCMPlayer({encoding:o,channels:i,sampleRate:e,flushingTime:5e3}),this.audioEncoding=o,this.audioChannels=i,this.audioSampleRate=e}},Player.prototype.restartAudio=function(){this.pcmPlayer&&(this.pcmPlayer.destroy(),this.pcmPlayer=null),this.pcmPlayer=new PCMPlayer({encoding:this.audioEncoding,channels:this.audioChannels,sampleRate:this.audioSampleRate,flushingTime:5e3})},Player.prototype.onAudioFrame=function(e){if(this.playerState==playerStatePlaying)switch(this.seeking&&(this.restartAudio(),this.startTrackTimer(),this.hideLoading(),this.seeking=!1),this.playerState){case playerStatePlaying:this.pcmPlayer.play(new Uint8Array(e.d));break;case playerStatePausing:this.audioQueue.push(new Uint8Array(e.d))}},Player.prototype.onDecodeFinished=function(e){this.pauseDecoding(),this.decoderState=decoderStateFinished},Player.prototype.onVideoFrame=function(e){this.videoTimeStamp=e.s,this.playerState==playerStatePlaying&&(this.seeking&&(this.restartAudio(),this.startTrackTimer(),this.hideLoading(),this.seeking=!1),this.videoQueue.push(e),this.videoQueue.length>=maxVideoFrameQueueSize&&(this.videoQueue=[],this.decoding))},Player.prototype.onSeekToRsp=function(e){0!=e&&(this.justSeeked=!1,this.seeking=!1)},Player.prototype.onRequestData=function(e){this.justSeeked&&(this.logger.logInfo("Request data "+e),0<=e&&e