You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9 lines
185 KiB
JavaScript

2 weeks ago
/*!
* FlvPlayer.js v1.1.8
* Github: https://github.com/zhw2590582/FlvPlayer#readme
* (c) 2017-2020 Harvey Zack
* Released under the MIT License.
*/
!function(A,I){"object"==typeof exports&&"undefined"!=typeof module?module.exports=I():"function"==typeof define&&define.amd?define(I):(A=A||self).FlvplayerDecoder=I()}(this,(function(){"use strict";var A=function(A,I){if(!(A instanceof I))throw new TypeError("Cannot call a class as a function")};function I(A,I){for(var B=0;B<I.length;B++){var g=I[B];g.enumerable=g.enumerable||!1,g.configurable=!0,"value"in g&&(g.writable=!0),Object.defineProperty(A,g.key,g)}}var B=function(A,B,g){return B&&I(A.prototype,B),g&&I(A,g),A};function g(A,I){return A(I={exports:{}},I.exports),I.exports}var Q=g((function(A){function I(B,g){return A.exports=I=Object.setPrototypeOf||function(A,I){return A.__proto__=I,A},I(B,g)}A.exports=I}));var E=function(A,I){if("function"!=typeof I&&null!==I)throw new TypeError("Super expression must either be null or a function");A.prototype=Object.create(I&&I.prototype,{constructor:{value:A,writable:!0,configurable:!0}}),I&&Q(A,I)},C=g((function(A){function I(B){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?A.exports=I=function(A){return typeof A}:A.exports=I=function(A){return A&&"function"==typeof Symbol&&A.constructor===Symbol&&A!==Symbol.prototype?"symbol":typeof A},I(B)}A.exports=I}));var i=function(A){if(void 0===A)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return A};var o=function(A,I){return!I||"object"!==C(I)&&"function"!=typeof I?i(A):I},D=g((function(A){function I(B){return A.exports=I=Object.setPrototypeOf?Object.getPrototypeOf:function(A){return A.__proto__||Object.getPrototypeOf(A)},I(B)}A.exports=I}));function a(){return performance&&"function"==typeof performance.now?performance.now():Date.now()}function F(A){var I=0,B=a();return function(g){I+=g;var Q=a(),E=Q-B;E>=1e3&&(A(I/E*1e3),B=Q,I=0)}}var R=function(){function I(B,g){var Q=this;A(this,I),this.flv=B;var E=B.options,C=B.player,i=B.debug;this.ready=!1,this.playing=!1,this.playIndex=0,this.videoframes=[],this.timestamps=[],this.videoInputLength=0,this.videoOutputLength=0,this.decoding=!1,this.byteSize=0,this.loaded=0,this.decoderRate=F((function(A){B.emit("decoderRate",A)})),this.drawRate=F((function(A){B.emit("drawRate",A)})),B.on("destroy",(function(){Q.videoframes=[],Q.timestamps=[],Q.decoderWorker.terminate(),Q.decoderWorker=null,Q.stop()})),B.on("befoerdecoding",(function(A){E.live&&E.hasAudio&&!Q.playing&&Q.timestamps.length>=C.frameRate&&Q.timestamps.shift(),Q.timestamps.push(A),Q.decoding=!0,Q.videoInputLength+=1})),B.on("decoding",(function(A,I){E.live&&E.hasAudio&&!Q.playing&&Q.timestamps.length>=C.frameRate&&Q.videoframes.shift(),Q.videoframes.push(A),Q.byteSize+=I,Q.videoOutputLength+=1,Q.decoding=Q.videoInputLength!==Q.videoOutputLength,Q.loaded=Q.videoOutputLength/C.frameRate,B.emit("videoLoaded",Q.loaded),Q.decoderRate(1),Q.ready||1!==Q.videoOutputLength||(Q.ready=!0,E.live&&(g.currentTime=Q.timestamps[0]/1e3),B.emit("ready"))})),B.on("timeupdate",(function(A){var I=Q.playIndex,C=Q.timestamps[I];if(void 0!==C&&1e3*A>=C)if(Q.draw(I)){var o=Q.getFramesSize(I);(E.live||!E.cache)&&o>=64*E.videoChunk&&Q.videoframes.length-1>I&&Q.timestamps.length-1>I?(Q.playIndex=0,Q.videoframes.splice(0,I+1),Q.timestamps.splice(0,I+1),g.currentTime=Q.timestamps[0]/1e3,i.log("free-video-memory",{total:Q.byteSize,yuv:o,index:I}),B.emit("freeVideoMemory",o,I)):Q.playIndex+=1}else E.live||Q.stop()}))}return B(I,[{key:"draw",value:function(A){var I=this.videoframes[A];return!!I&&(this.renderer.drawFrame(I),this.drawRate(1),!0)}},{key:"play",value:function(){var A=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.playing=!0,this.flv.options.live?(this.playIndex=0,this.flv.decoder.currentTime=(this.timestamps[0]||0)/1e3):this.playIndex=this.timestamps.findIndex((function(I){return I>=1e3*A}))}},{key:"stop",value:function(){this.playing=!1,this.flv.options.live&&(this.playIndex=0)}}]),I}();function h(A,I){this.canvasElement=A,I||this.initContextGL(),this.contextGL&&(this.initProgram(),this.initBuffers(),this.initTextures())}h.prototype.isWebGL=function(){return this.contextGL},h