IntelligentRecognition/ah-jjsp-web/.svn/pristine/10/1039372a13fd7da3fecb5dfb002...

1 line
15 KiB
Plaintext
Raw Permalink Normal View History

2024-05-24 16:09:40 +08:00
"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<e.length&&(e=new Blob([e],{type:"application/octet-stream"}),(i=document.createElement("a")).style.display="none",o=URL.createObjectURL(e),i.href=o,e="-"+(e=new Date).getFullYear()+"-"+(e.getMonth()+1)+"-"+e.getDate()+"-"+e.getHours()+":"+e.getMinutes()+":"+e.getSeconds(),i.download=t+e+".ps",document.body.appendChild(i),i.click(),r=setTimeout(function(){document.body.removeChild(i),window.URL.revokeObjectURL(o),clearTimeout(r)},1e4))},this.initDownloadWorker(),this.initDecodeWorker()}Player.prototype.initDownloadWorker=function(){var i=this;this.downloadWorker=new Worker("./videoComponent/script/h265/downloader.js"),this.downloadWorker.onmessage=function(e){var t=e.data;switch(t.t){case kGetFileInfoRsp:i.onGetFileInfo(t.i,t.num);break;case kFileData:i.onFileData(t.d,t.s,t.e,t.q,t);break;case kErrorTip:i.onErrorTip(t.num,t.errorDes,t.errorCode,t.rongqiId,t.devCode);break;case kliuover:i.onLiuOver(t.num);break;case 6:i.onMalvShow(t)}}},Player.prototype.onMalvShow=function(e){malvtips(e.num,Number(8*e.malv/1024).toFixed(2)+"kb/s",e.rongqiId)},Player.prototype.onLiuOver=function(e){console.log("流结束调用暂停"),this.pause(e)},Player.prototype.initDecodeWorker=function(){var i=this;this.decodeWorker=new Worker("./videoComponent/script/h265/decoder.js"),this.decodeWorker.onmessage=function(e){var t=e.data;switch(t.t){case kInitDecoderRsp:i.onInitDecoder(t);break;case kOpenDecoderRsp:i.onOpenDecoder(t);break;case kVideoFrame:i.onVideoFrame(t);break;case kAudioFrame:i.onAudioFrame(t);break;case kDecodeFinishedEvt:i.onDecodeFinished(t);break;case kRequestDataEvt:i.onRequestData(t.o);break;case kSeekToRsp:i.onSeekToRsp(t.r)}}},Player.prototype.onErrorTip=function(e,t,i,o,r){console.log(111);execute(this.returnFuc,"111",{windowIndex:e,errorDes:t,errorCode:i,rongqiId:o,devCode:r}),errortips(e,t,o),console.log(222),this.pause(e)},Player.prototype.play=function(e,t,i,o,r){var a={e:0,m:"Success"};do{if(this.playerState==playerStatePausing){a=this.resume();break}if(this.playerState==playerStatePlaying)break;if(!e){a={e:-1,m:"Invalid url"},this.logger.logError("[ER] playVideo error, url empty.");break}if(!t){a={e:-2,m:"Canvas not set"},this.logger.logError("[ER] playVideo error, canvas empty.");break}if(!this.downloadWorker){a={e:-3,m:"Downloader not initialized"},this.logger.logError("[ER] Downloader not initialized.");break}if(!this.decodeWorker){a={e:-4,m:"Decoder not initialized"},this.logger.logError("[ER] Decoder not initialized.");break}this.fileInfo=new FileInfo(e),this.canvas=t,this.callback=i,this.waitHeaderLength=0,this.playerState=playerStatePlaying,this.startTrackTimer(),this.displayLoop(),this.webglPlayer=new WebGLPlayer(this.canvas,{preserveDrawingBuffer:!1});var s={t:kGetFileInfoReq,u:e,num:r}}while(this.downloadWorker.postMessage(s),0);return a},Player.prototype.pause=