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
1.9 MiB
JavaScript

/*!
* 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 g=0;g<I.length;g++){var B=I[g];B.enumerable=B.enumerable||!1,B.configurable=!0,"value"in B&&(B.writable=!0),Object.defineProperty(A,B.key,B)}}var g=function(A,g,B){return g&&I(A.prototype,g),B&&I(A,B),A};function B(A,I){return A(I={exports:{}},I.exports),I.exports}var Q=B((function(A){function I(g,B){return A.exports=I=Object.setPrototypeOf||function(A,I){return A.__proto__=I,A},I(g,B)}A.exports=I}));var C=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)},E=B((function(A){function I(g){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(g)}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 D=function(A,I){return!I||"object"!==E(I)&&"function"!=typeof I?i(A):I},o=B((function(A){function I(g){return A.exports=I=Object.setPrototypeOf?Object.getPrototypeOf:function(A){return A.__proto__||Object.getPrototypeOf(A)},I(g)}A.exports=I}));function G(){return performance&&"function"==typeof performance.now?performance.now():Date.now()}function w(A){var I=0,g=G();return function(B){I+=B;var Q=G(),C=Q-g;C>=1e3&&(A(I/C*1e3),g=Q,I=0)}}var F=function(){function I(g,B){var Q=this;A(this,I),this.flv=g;var C=g.options,E=g.player,i=g.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=w((function(A){g.emit("decoderRate",A)})),this.drawRate=w((function(A){g.emit("drawRate",A)})),g.on("destroy",(function(){Q.videoframes=[],Q.timestamps=[],Q.decoderWorker.terminate(),Q.decoderWorker=null,Q.stop()})),g.on("befoerdecoding",(function(A){C.live&&C.hasAudio&&!Q.playing&&Q.timestamps.length>=E.frameRate&&Q.timestamps.shift(),Q.timestamps.push(A),Q.decoding=!0,Q.videoInputLength+=1})),g.on("decoding",(function(A,I){C.live&&C.hasAudio&&!Q.playing&&Q.timestamps.length>=E.frameRate&&Q.videoframes.shift(),Q.videoframes.push(A),Q.byteSize+=I,Q.videoOutputLength+=1,Q.decoding=Q.videoInputLength!==Q.videoOutputLength,Q.loaded=Q.videoOutputLength/E.frameRate,g.emit("videoLoaded",Q.loaded),Q.decoderRate(1),Q.ready||1!==Q.videoOutputLength||(Q.ready=!0,C.live&&(B.currentTime=Q.timestamps[0]/1e3),g.emit("ready"))})),g.on("timeupdate",(function(A){var I=Q.playIndex,E=Q.timestamps[I];if(void 0!==E&&1e3*A>=E)if(Q.draw(I)){var D=Q.getFramesSize(I);(C.live||!C.cache)&&D>=64*C.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),B.currentTime=Q.timestamps[0]/1e3,i.log("free-video-memory",{total:Q.byteSize,yuv:D,index:I}),g.emit("freeVideoMemory",D,I)):Q.playIndex+=1}else C.live||Q.stop()}))}return g(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}(),a={validateDimension:function(A){if(A<=0||A!==(0|A))throw"YUV plane dimensions must be a positive integer"},validateOffset:function(A){if(A<0||A!==(0|A))throw"YUV plane offsets must be a non-n