window.FlvPlayer=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=9)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n>24,e>>16&255,e>>8&255,255&e])}},{key:"readAsInt",value:function(e){var t="";return e.forEach(function(e){t+=e.toString(16).padStart(2,"0")}),parseInt(t,16)}}]),e}();t.default=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n1?n-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:{line:"",handle:"",msg:"",version:""},n=this._store,i=n.player,r=n.state;if(i){var o=new a.default(e,i.currentTime,r.duration,"",!0,i.config.url,i.config.url,i.ended,t);i.emit("error",o)}}}]),e}();t.default=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.MetaTypes={NUMBER:0,BOOLEAN:1,STRING:2,OBJECT:3,MIX_ARRAY:8,OBJECT_END:9,STRICT_ARRAY:10,DATE:11,LONE_STRING:12},t.EventTypes={DATA_READY:"data_ready",META_DATA_READY:"meta_data_ready",TRACK_META_READY:"track_meta_ready",MEDIA_INFO_READY:"media_info_ready",META_END_POSITION:"meta_end_position",ERROR:"error"},t.soundRateTypes=[5500,11e3,22e3,44e3],t.AudioObjectTypes={0:"Null",1:"AAC Main",2:"AAC LC",3:"AAC SSR(Scalable Sample Rate)",4:"AAC LTP(Long Term Prediction)",5:"HE-AAC / SBR(Spectral Band Replication)",6:"AAC Scalable"},t.samplingFrequencyTypes=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3],t.browserTypes={IE:"ie",FIRE_FOX:"firefox",CHROME:"chrome",OPERA:"opera",SAFARI:"safari"},t.mp3Versions={V25:0,RESERVED:1,V20:2,V10:3},t.audioSampleRate={V10:[44100,48e3,32e3,0],V20:[22050,24e3,16e3,0],V25:[11025,12e3,8e3,0]},t.mp3BitRate={Layer1:[0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1],Layer2:[0,32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1],Layer3:[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1]}},function(e,t,n){"use strict";var i=n(50)();e.exports=function(e){return e!==i&&null!==e}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n2&&void 0!==arguments[2])||arguments[2];if(t>32)throw"not supported read size";var s=32;if(this["getUint"+t])return i["getUint"+s](a,!r.isLe);for(var u=0,f=n.length;u2&&void 0!==arguments[2]?arguments[2]:8,i=0,r=--n;r>0;)r>t||r2&&void 0!==arguments[2]?arguments[2]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.url=t,this.on=!1,this.complete=!1,this.isStopped=!1,this.timeStamp=Date.now();var a={headers:{Range:"bytes="+n[0]+"-"+n[1]},method:"GET",cache:"default",mode:"cors"};this.request=function(){return i.on=!0,window.fetch(t,Object.assign({},a,r)).then(function(e){return e.status>299||e.status<200||!e.ok?(i.complete=!0,o.default.remove(i),Promise.reject(new Error("url "+e.status+" "+e.statusText))):Promise.resolve(e)}).then(function(e){return e.arrayBuffer()}).then(function(e){return i.complete=!0,i.byteLength=e.byteLength,o.default.remove(i),i.isStopped?{}:{buffer:e,timeStamp:i.timeStamp}})}}return r(e,[{key:"run",value:function(){this._promise=this.request()}},{key:"cancel",value:function(){this.isStopped=!0}},{key:"readyState",get:function(){return 1}},{key:"promise",get:function(){return this.on?this._promise:this.request()}}]),e}();t.default=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;nt.start(a)&&i=3)return e._player.emit("error",n),void e.destroy();e.err_cnt+=1,t()})}()}},{key:"loadSegments",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments[2];this._isNewSegmentsArrival=!1;var r=function(e){var n=e.timeStamp,i=e.buffer;if(t.isTempPlayer&&(t.isTempPlayer=!1),n===t.loadTask.timeStamp){t.err_cnt=0,t.buffer.write(new Uint8Array(i)),t.isSeeking&&(t._pendingFragments=[]);var r=t.setFlv(t.buffer.buffer);t.buffer.buffer=t.buffer.buffer.slice(r),t._isNewSegmentsArrival?t.isSeeking=!1:t.loadSegments(!0)}};if(e){var a=this.range;if(this.getNextRangeEnd(n,i)<=a.end)return Promise.resolve();if(this.range={start:this.range.end+1,end:void 0===n?this.range.end+this.CHUNK_SIZE-1:this.getNextRangeEnd(n,i)-1},this.range.start>=this.range.end||!this.range.end)return this.range=a,Promise.resolve()}return function e(){if(!t.stop)return t._loadSegmentsData(t.range.start,t.range.end).then(r).catch(function(n){if(t.err_cnt>=3)return t._player.emit("error","加载视频失败"),void t.destroy();t.err_cnt+=1,e()})}()}},{key:"getNextRangeEnd",value:function(e,t){var n=this._store,i=n.keyframes,r=i.times,a=i.filePositions,o=n.videoTimeScale;if(!r||!a)return this.range.end+this.CHUNK_SIZE;var s=(e*=o)+t*o;if(s>r[r.length-1])return a[a.length-1];for(var u=0,f=r.length-1,l=void 0;u<=f;){var c=Math.floor((f+u)/2);if(r[c]<=s&&s<=r[c+1]){l=c+1;break}if(u===f){l=c;break}s0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e+this.CHUNK_SIZE;return this.loadTask=new u.default(this._config.url,[e,t],this.requestConfig),this.loadTask.promise}},{key:"loadMetaData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e+this.META_CHUNK_SIZE;return this.loadTask=new u.default(this._config.url,[e,t],this.requestConfig),this.loadTask.promise}},{key:"setFlvFirst",value:function(e,t){var n=this.flvParser.setFlv(new Uint8Array(e)),i=this._store.state.tags;if(i.length){if(18!==i[0].tagType)throw new Error("flv file without metadata tag");0!==this._tempBaseTime&&this._tempBaseTime===i[0].getTime()&&(this._store.state._timestampBase=0),this.tagDemuxer.resolveTags(i)}return this.firstFlag=!1,n}},{key:"setFlvUsually",value:function(e,t){this.isParsing=!0;var n=this.flvParser.setFlv(new Uint8Array(e)),i=this._store.state.tags;return i.length&&this.tagDemuxer.resolveTags(i),n}},{key:"handleDataReady",value:function(e,t){this.mp4remuxer.remux(e,t)}},{key:"handleMetaDataReady",value:function(e,t){this.mp4remuxer.onMetaDataReady(e,t)}},{key:"handleError",value:function(e){this.error(e)}},{key:"handleNewMediaFragment",value:function(e){var t=this;this._isNewSegmentsArrival=!0,this._pendingFragments.push(e);var n=e.fragment.randomAccessPoints;if(n&&n.length&&n.forEach(function(e){t.bufferKeyframes.add(e.dts)}),this.isSourceOpen&&this._pendingFragments.length){var i=this._pendingFragments.shift();this.handleMediaFragment(i)?(this.handleSeekEnd(),this._player.emit("cacheupdate",this._player)):this._pendingFragments.unshift(i)}}},{key:"handleMediaInfoReady",value:function(e){var t=this.mp4remuxer.onMediaInfoReady(e);this.ftyp_moov||(this.ftyp_moov=t,this.emit("ready",t))}},{key:"initEventBind",value:function(){this.tagDemuxer.handleDataReady=this.handleDataReady.bind(this),this.tagDemuxer.handleMediaInfoReady=this.handleMediaInfoReady.bind(this),this.tagDemuxer.handleMetaDataReady=this.handleMetaDataReady.bind(this),this.tagDemuxer.setEventBind(),this.mp4remuxer.handleMediaFragment=this.handleNewMediaFragment.bind(this)}},{key:"replay",value:function(){this.isSourceOpen=!1,this.range={start:this._store.metaEndPosition,end:this.getNextRangeEnd(0,this._config.preloadTime)-1},this.mp4remuxer.seek(),this.flvParser.seek(),this.clearBuffer(),this.loadSegments(!1)}},{key:"clearBuffer",value:function(){this._pendingFragments=[],this._pendingRemoveRange=[]}},{key:"unbindEvents",value:function(){this.tagDemuxer.handleDataReady=h,this.tagDemuxer.handleMediaInfoReady=h,this.tagDemuxer.handleMetaDataReady=h,this.tagDemuxer.setEventBind(),this.mp4remuxer.handleMediaFragment=h}},{key:"destroy",value:function(){this.mp4remuxer.destroy(),this.flvParser.destroy(),this.tagDemuxer.destroy(),this.mp4remuxer=null,this.flvParser=null,this.tagDemuxer=null,this.loadSegments=function(){return null},this._store=null,this.clearBuffer(),this.stop=!0,this.loadTask&&this.loadTask.cancel()}},{key:"seek",value:function(e){this.loadTask.cancel();var t=this._store,n=t.keyframes,i=void 0===n?{}:n,r=t.videoTimeScale,a=e*r,o=void 0,s=void 0,f=Math.min(i.filePositions.length,i.times.length),c=this._config.preloadTime;function d(e,t){return t===i.times.length?(s=t,!1):!(e<=c&&c<=i.times[t+1])||(s=t,!1)}for(var h=0,p=f-2;h<=p;){var v=Math.floor((h+p)/2),y=i.times[v],m=i.times[v+1]?i.times[v+1]:Number.MAX_SAFE_INTEGER;if(y<=a&&a<=m||h===p){for(;i.times[v]>=a;)v-=1;o=v-1,c=c*r+a,i.times.every(d);break}a=1e3?0:g-this._videoNextDts;else if(this._videoSegmentList.isEmpty())s=0;else{var _=this._videoSegmentList.getLastSegmentBefore(g);if(_){var b=_.lastDts,w=_.gap;s=g-(b+(g-(b+w)>3?g-(b+w):0))}else s=0}var k=g,S=(g-=s)+m;-1===l&&(l=g,c=S);for(var O=[];v.units.length;){var A={buffer:[],size:0},D=v.units.shift();O.push(D),A.buffer.push(D),A.size+=D.data.byteLength,h.samples.push(A)}var T=0;if(r.length>=1)T=r[0].dts-this._dtsBase-s-g;else T=d.length>=1?d[d.length-1].duration:this._videoMeta.refSampleDuration;if(y){var x=new o.default({dts:g,pts:S,duration:T,originDts:v.dts,position:v.position,isRAP:!0});p.addRAP(x)}d.push({dts:g,cps:m,pts:S,units:O,size:v.length,isKeyframe:y,duration:T,originDts:k})}var P=d[0],E=d[d.length-1];n=E.dts+E.duration,i=E.pts+E.duration,this._videoNextDts=n,p.startDts=l,p.endDts=n,p.startPts=c,p.endPts=i,p.originStartDts=P.originDts,p.originEndDts=E.originDts+E.duration,p.gap=s;var M=new o.default({dts:P.dts,pts:P.pts,duration:P.duration,isKeyframe:P.isKeyframe,originDts:P.originDts}),C=new o.default({dts:E.dts,pts:E.pts,duration:E.duration,isKeyframe:E.isKeyframe,originDts:E.originDts});p.firstSample=M,p.lastSample=C;var L=new u.default;t.samples=d,t.time=l;var R=f.default.moof(t),j=f.default.mdat(h);L.write(R,j),this._store.isLive||this._videoSegmentList.append(p),t.samples=[],t.length=0,this.handleMediaFragment({type:"video",data:L.buffer.buffer,sampleCount:d.length,fragment:p})}}}},{key:"_remuxAudio",value:function(e){if(this._audioMeta){var t,n=e.samples,i=void 0,r=-1,s=void 0,l=[],c={samples:[]};if(n&&n.length){for(var d=!1;n.length;){var h=n.shift(),p=h.unit,v=h.dts-this._dtsBase,y=!1;if(void 0===i)if(this._audioNextDts)i=v-this._audioNextDts>=1e3?0:v-this._audioNextDts;else if(this._audioSegmentList.isEmpty())i=0;else{var m=this._audioSegmentList.getLastSegmentBefore(v);if(m){var g=m.lastDts,_=m.gap;i=v-(g+(v-(g+_)>3?v-(g+_):0))}else y=this._fillSilenceFrame&&!this._videoSegmentList.isEmpty(),i=0}var b=v;if(v-=i,y){var w=this._videoSegmentList.getLastSampleBefore(b);w&&w.startDts=1)O=n[0].dts-this._dtsBase-i-v;else O=l.length>=1?l[l.length-1].duration:this._audioMeta.refSampleDuration;var A={dts:v,pts:v,cts:0,size:p.byteLength,duration:O,originDts:b},D={buffer:[],size:0};D.buffer.push({data:p}),D.size+=p.byteLength,c.samples.push(D),l.push(A)}}var T=l[l.length-1];t=T.dts+T.duration,this._audioNextDts=t;var x=new a.default;x.startDts=r,x.endDts=t,x.startPts=r,x.endPts=t,x.originStartDts=l[0].originDts,x.originEndDts=T.originDts+T.duration,x.gap=i,x.firstSample=new o.default({dts:l[0].dts,pts:l[0].pts,duration:l[0].duration,originDts:l[0].originDts}),x.lastSample=new o.default({dts:T.dts,pts:T.pts,duration:T.duration,originDts:T.originDts}),e.samples=l;var P=new u.default;e.time=r;var E=f.default.moof(e,r),M=f.default.mdat(c);P.write(E,M),this._store.isLive||this._audioSegmentList.append(x),e.samples=[],e.length=0,this.handleMediaFragment({type:"audio",data:P.buffer.buffer,sampleCount:l.length,fragment:x})}}}},{key:"initSilentAudio",value:function(e,n){var i=t.getSilentFrame(this._audioMeta.channelCount);return{dts:e,pts:e,cps:0,duration:n,unit:i,size:i.byteLength,originDts:e}}}],[{key:"getSilentFrame",value:function(e){return 1===e?new Uint8Array([0,200,0,128,35,128]):2===e?new Uint8Array([33,0,73,144,2,25,0,35,128]):3===e?new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]):4===e?new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]):5===e?new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]):6===e?new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224]):null}}]),t}();t.default=d},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;nt[i].lastSample.originDts&&e=t[n].lastSample.originDts&&(n===t.length-1||n0&&(i=this._searchNearestSegmentBefore(e.originStartDts)+1),this._lastAppendLocation=i,this._list.splice(i,0,e)}},{key:"getLastSegmentBefore",value:function(e){var t=this._searchNearestSegmentBefore(e);return t>=0?this._list[t]:null}},{key:"getLastSampleBefore",value:function(e){var t=this.getLastSegmentBefore(e);return null!==t?t.lastSample:null}},{key:"getLastRAPBefore",value:function(e){for(var t=this._searchNearestSegmentBefore(e),n=this._list[t].randomAccessPoints;0===n.length&&t>0;)t--,n=this._list[t].randomAccessPoints;return n.length>0?n[n.length-1]:null}},{key:"type",get:function(){return this._type}},{key:"length",get:function(){return this._list.length}}]),e}();t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n1?n-1:0),r=1;r2?r-2:0),s=2;s>16&255,t>>8&255,255&t])}},{key:"ftyp",value:function(){return e.initBox(24,"ftyp",new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,97,118,99,49]))}},{key:"moov",value:function(t){var n=8,i=e.mvhd(t.duration,t.timescale),r=e.videoTrak(t),a=e.audioTrak(t),o=e.mvex(t.duration,t.timescale);return[i,r,a,o].forEach(function(e){n+=e.byteLength}),e.initBox(n,"moov",i,r,a,o)}},{key:"mvhd",value:function(t,n){var i=n||1e3,r=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,i>>>24&255,i>>>16&255,i>>>8&255,255&i,t>>>24&255,t>>>16&255,t>>>8&255,255&t,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return e.initBox(8+r.length,"mvhd",new Uint8Array(r))}},{key:"videoTrak",value:function(t){var n=8,i=e.tkhd({id:1,duration:t.duration,timescale:t.timescale,width:t.width,height:t.height,type:"video"}),r=e.mdia({type:"video",timescale:t.timescale,duration:t.duration,sps:t.sps,pps:t.pps,pixelRatio:t.pixelRatio,width:t.width,height:t.height});return[i,r].forEach(function(e){n+=e.byteLength}),e.initBox(n,"trak",i,r)}},{key:"audioTrak",value:function(t){var n=8,i=e.tkhd({id:2,duration:t.duration,timescale:t.timescale,width:0,height:0,type:"audio"}),r=e.mdia({type:"audio",timescale:t.timescale,duration:t.duration,channelCount:t.audioChannelCount,samplerate:t.audioSampleRate,config:t.audioConfig});return[i,r].forEach(function(e){n+=e.byteLength}),e.initBox(n,"trak",i,r)}},{key:"tkhd",value:function(t){var n=t.id,i=t.duration,r=t.width,a=t.height,o=new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,n>>>24&255,n>>>16&255,n>>>8&255,255&n,0,0,0,0,i>>>24&255,i>>>16&255,i>>>8&255,255&i,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,r>>>8&255,255&r,0,0,a>>>8&255,255&a,0,0]);return e.initBox(8+o.byteLength,"tkhd",o)}},{key:"edts",value:function(t){var n=new o.default,i=t.duration,r=t.mediaTime;return n.write(e.size(36),e.type("edts")),n.write(e.size(28),e.type("elst")),n.write(new Uint8Array([0,0,0,1,i>>24&255,i>>16&255,i>>8&255,255&i,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,1])),n.buffer}},{key:"mdia",value:function(t){var n=8,i=e.mdhd(t.timescale,t.duration),r=e.hdlr(t.type),a=e.minf(t);return[i,r,a].forEach(function(e){n+=e.byteLength}),e.initBox(n,"mdia",i,r,a)}},{key:"mdhd",value:function(t,n){var i=new Uint8Array([0,0,0,0,0,0,0,0,t>>>24&255,t>>>16&255,t>>>8&255,255&t,n>>>24&255,n>>>16&255,n>>>8&255,255&n,85,196,0,0]);return e.initBox(12+i.byteLength,"mdhd",e.extension(0,0),i)}},{key:"hdlr",value:function(t){var n=[0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0];return"audio"===t&&(n.splice.apply(n,[8,4].concat([115,111,117,110])),n.splice.apply(n,[24,13].concat([83,111,117,110,100,72,97,110,100,108,101,114,0]))),e.initBox(8+n.length,"hdlr",new Uint8Array(n))}},{key:"minf",value:function(t){var n=8,i="video"===t.type?e.vmhd():e.smhd(),r=e.dinf(),a=e.stbl(t);return[i,r,a].forEach(function(e){n+=e.byteLength}),e.initBox(n,"minf",i,r,a)}},{key:"vmhd",value:function(){return e.initBox(20,"vmhd",new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]))}},{key:"smhd",value:function(){return e.initBox(16,"smhd",new Uint8Array([0,0,0,0,0,0,0,0]))}},{key:"dinf",value:function(){var t=new o.default;return t.write(e.size(36),e.type("dinf"),e.size(28),e.type("dref"),new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1])),t.buffer}},{key:"stbl",value:function(t){var n=8,i=e.stsd(t),r=e.stts(),a=e.stsc(),o=e.stsz(),s=e.stco();return[i,r,a,o,s].forEach(function(e){n+=e.byteLength}),e.initBox(n,"stbl",i,r,a,o,s)}},{key:"stsd",value:function(t){var n=void 0;return n="audio"===t.type?e.mp4a(t):e.avc1(t),e.initBox(16+n.byteLength,"stsd",e.extension(0,0),new Uint8Array([0,0,0,1]),n)}},{key:"mp4a",value:function(t){var n=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,t.samplerate>>8&255,255&t.samplerate,0,0]),i=e.esds(t.config);return e.initBox(8+n.byteLength+i.byteLength,"mp4a",n,i)}},{key:"esds",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[43,146,8,0],n=t.length,i=new o.default,r=new Uint8Array([0,0,0,0,3,23+n,0,1,0,4,15+n,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([n]).concat(t).concat([6,1,2]));return i.write(e.size(8+r.byteLength),e.type("esds"),r),i.buffer}},{key:"avc1",value:function(t){var n=new o.default,i=t.sps,r=t.pps,a=t.width,s=t.height,u=t.pixelRatio[0],f=t.pixelRatio[1],l=new o.default;l.write(new Uint8Array([1,i[1],i[2],i[3],255,225].concat([i.length>>>8&255,255&i.length]))),l.write(i,new Uint8Array([1,r.length>>>8&255,255&r.length]),r);var c=l.buffer,d=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,a>>8&255,255&a,s>>8&255,255&s,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),h=new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192]),p=new Uint8Array([u>>24,u>>16&255,u>>8&255,255&u,f>>24,f>>16&255,f>>8&255,255&f]);return n.write(e.size(40+d.byteLength+c.byteLength+h.byteLength),e.type("avc1"),d,e.size(8+c.byteLength),e.type("avcC"),c,e.size(20),e.type("btrt"),h,e.size(16),e.type("pasp"),p),n.buffer}},{key:"stts",value:function(){var t=new Uint8Array([0,0,0,0,0,0,0,0]);return e.initBox(16,"stts",t)}},{key:"stsc",value:function(){var t=new Uint8Array([0,0,0,0,0,0,0,0]);return e.initBox(16,"stsc",t)}},{key:"stco",value:function(){var t=new Uint8Array([0,0,0,0,0,0,0,0]);return e.initBox(16,"stco",t)}},{key:"stsz",value:function(){var t=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]);return e.initBox(20,"stsz",t)}},{key:"mvex",value:function(t){var n=new o.default,i=o.default.writeUint32(t);return n.write(e.size(88),e.type("mvex"),e.size(16),e.type("mehd"),e.extension(0,0),i,e.trex(1),e.trex(2)),n.buffer}},{key:"trex",value:function(t){var n=new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]);return e.initBox(8+n.byteLength,"trex",n)}},{key:"moof",value:function(t){var n=8,i=e.mfhd(),r=e.traf(t);return[i,r].forEach(function(e){n+=e.byteLength}),e.initBox(n,"moof",i,r)}},{key:"mfhd",value:function(){var t=o.default.writeUint32(e.sequence);return e.sequence+=1,e.initBox(16,"mfhd",e.extension(0,0),t)}},{key:"traf",value:function(t){var n=8,i=e.tfhd(t.id),r=e.tfdt(t.time),a=e.sdtp(t),o=e.trun(t,a.byteLength);return[i,r,a,o].forEach(function(e){n+=e.byteLength}),e.initBox(n,"traf",i,r,a,o)}},{key:"tfhd",value:function(t){var n=o.default.writeUint32(t);return e.initBox(16,"tfhd",e.extension(0,0),n)}},{key:"tfdt",value:function(t){return e.initBox(16,"tfdt",e.extension(0,0),o.default.writeUint32(t))}},{key:"trun",value:function(t,n){var i=new o.default,r=o.default.writeUint32(t.samples.length),a=o.default.writeUint32(92+16*t.samples.length+n);i.write(e.size(20+16*t.samples.length),e.type("trun"),new Uint8Array([0,0,15,1]),r,a);var s=i.buffer.byteLength,u=0;t.samples.forEach(function(){s+=16});var f=new Uint8Array(s);return f.set(i.buffer,0),u+=i.buffer.byteLength,t.samples.forEach(function(e){f.set(o.default.writeUint32(e.duration),u),u+=4,f.set(o.default.writeUint32(e.size),u),u+=4,1===t.id?(f.set(o.default.writeUint32(e.isKeyframe?33554432:16842752),u),u+=4,f.set(o.default.writeUint32(e.cps),u),u+=4):(f.set(o.default.writeUint32(16777216),u),u+=4,f.set(o.default.writeUint32(0),u),u+=4)}),f}},{key:"sdtp",value:function(t){var n=new o.default;return n.write(e.size(12+t.samples.length),e.type("sdtp"),e.extension(0,0)),t.samples.forEach(function(e){n.write(new Uint8Array(1===t.id?[e.key?32:16]:[16]))}),n.buffer}},{key:"mdat",value:function(t){var n=new o.default,i=8;t.samples.forEach(function(e){i+=e.size}),n.write(e.size(i),e.type("mdat"));var r=new Uint8Array(i),a=0;return r.set(n.buffer,a),a+=8,t.samples.forEach(function(e){e.buffer.forEach(function(e){r.set(e.data,a),a+=e.data.byteLength})}),r}}]),e}();u.type=(0,s.cacheWrapper)(function(e){return new Uint8Array([e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)])}),u.sequence=1,t.default=u},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.debounce=function(e,t,n){var i,r,a=function(a){if(i&&clearTimeout(i),n){var o=!i;i=setTimeout(e,t),o&&(r=e())}else i=setTimeout(e,t);return r};return a.cancel=function(){clearTimeout(i),i=null},a};t.cacheWrapper=function(e){var t={};return function(){for(var n=arguments.length,i=Array(n),r=0;r1?n-1:0),r=1;r8&&void 0!==arguments[8]?arguments[8]:{line:"",handle:"",msg:"",version:""};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var d={};return d.playerVersion=i.version,d.errorType=t,d.domain=document.domain,d.duration=a,d.currentTime=n,d.networkState=o,d.readyState=s,d.currentSrc=f,d.src=u,d.ended=l,d.errd=c,d.ex=(r[t]||{}).msg,d}},function(e){e.exports={name:"xgplayer-flv",version:"1.1.5",description:"flv demuxer for xgplayer",main:"./dist/index.js",scripts:{test:'echo "Error: no test specified" && exit 1',prepare:"npm run build",dev:"webpack --progress --display-chunks --watch --config ./webpack.config.dev.js",build:"webpack --progress --display-chunks -p",watch:"webpack --progress --display-chunks -p --watch"},repository:{type:"git",url:"git+https://github.com/bytedance/xgplayer.git"},keywords:[],author:"leo",license:"MIT",devDependencies:{babel:"^6.23.0","babel-env":"^2.4.1","babel-eslint":"^8.2.2","babel-loader":"^7.1.2","babel-plugin-transform-class-properties":"^6.24.1","babel-plugin-transform-decorators":"^6.24.1","babel-plugin-transform-react-constant-elements":"^6.23.0","babel-plugin-transform-react-inline-elements":"^6.22.0","babel-preset-es2015":"^6.24.1","clean-webpack-plugin":"^0.1.17","css-loader":"^0.28.10","extract-text-webpack-plugin":"^3.0.2","html-loader":"^0.5.5","html-webpack-plugin":"^2.30.1","style-loader":"^0.20.2",webpack:"^4.12.0","webpack-cli":"^3.1.2","webpack-dev-server":"^2.11.1"},peerDependency:{xgplayer:"^0.1.0"},dependencies:{"concat-typed-array":"^1.0.2","event-emitter":"^0.3.5"}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n13&&t.isFlvHead(n)?(this.parseHead(),this.readData(9),this.readData(4),this.parseData(),this.firstFlag=!1,this.filePosition+=this.offset,this.offset):this.offset:this.parseData()}},{key:"parseData",value:function(){for(var e=this.temp_u8a.length;this.index=11)if(t.position=this.filePosition+this.offset,t.tagType=this.readData(1)[0],t.bodySize=this.readData(3),t.Timestamp=this.readData(4),t.StramId=this.readData(3),this.unreadLength>=this.getBodySize(t.bodySize)+4){t.body=this.readData(this.getBodySize(t.bodySize)),t.tagSize=this.readData(4);var n=this._store.state,i=n.tags,r=n._hasVideo,a=n._hasAudio;switch(t.tagType){case 9:r&&i.push(t);break;case 8:a&&i.push(t);break;case 18:i.push(t)}this.offset=this.index}else this.stop=!0;else this.stop=!0}return this.filePosition+=this.offset,this.temp_u8a=null,this.offset}},{key:"getBodySize",value:function(e){return a.default.readAsInt(e)}},{key:"parseHead",value:function(){var e=this.temp_u8a,t=this._store,n={match:!1};if(1!==e[3])return n;var i=e[4],r=(4&i)>>>2!=0,a=0!=(1&i);if(!r&&!a)return n;t.hasAudio=r,t.hasVideo=a}},{key:"readData",value:function(e){var t=this.index;return this.index+=e,this.temp_u8a.slice(t,t+e)}},{key:"unreadLength",get:function(){return this.dataLen-this.index}}],[{key:"isFlvHead",value:function(e){var t=[e[0],e[1],e[2]];return"FLV"===String.fromCharCode.apply(String,t)}}]),t}();t.default=u},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n0?a.default.decode(new Uint8Array(e,this.readOffset+2,t)):"";var i=t+2;return this.readOffset+=i,{data:n,bodySize:t+2}}},{key:"parseDate",value:function(e,t){var n=this.isLe,i=new DataView(e,this.readOffset,t),r=i.getFloat64(0,!n);return r+=60*i.getInt16(8,!n)*1e3,this.readOffset+=10,{data:new Date(r),bodySize:10}}},{key:"parseObject",value:function(e,t){var n=this.parseString(e,t),i=this.parseValue(e,t-n.bodySize);return{data:{name:n.data,value:i.data},bodySize:n.bodySize+i.bodySize,isObjEnd:i.isObjEnd}}},{key:"parseLongString",value:function(e){var t=new DataView(e,this.readOffset).getUint32(0,!this.isLe),n="";return n=t>0?a.default.decode(new Uint8Array(e,this.readOffset+2,t)):"",this.readOffset+=t+4,{data:n,bodySize:t+4}}},{key:"parseValue",value:function(e,t){var n=new ArrayBuffer;n=e instanceof ArrayBuffer?e:e.buffer;var i=this.isLe,a=r.MetaTypes.NUMBER,o=r.MetaTypes.BOOLEAN,s=r.MetaTypes.STRING,u=r.MetaTypes.OBJECT,f=r.MetaTypes.MIX_ARRAY,l=r.MetaTypes.OBJECT_END,c=r.MetaTypes.STRICT_ARRAY,d=r.MetaTypes.DATE,h=r.MetaTypes.LONE_STRING,p=new DataView(n,this.readOffset,t),v=!1,y=p.getUint8(0),m=1;this.readOffset+=1;var g=null;switch(y){case a:g=p.getFloat64(1,!i),this.readOffset+=8,m+=8;break;case o:g=!!p.getUint8(1),this.readOffset+=1,m+=1;break;case s:var _=this.parseString(n);g=_.data,m+=_.bodySize;break;case u:g={};var b=0;for(16777215&p.getUint32(t-4,!i)&&(b=3);m=128){n.push(String.fromCharCode(65535&o)),r+=2;continue}}}else if(i[r]<240){if(e._checkContinuation(i,r,2)){var s=(15&i[r])<<12|(63&i[r+1])<<6|63&i[r+2];if(s>=2048&&55296!=(63488&s)){n.push(String.fromCharCode(65535&s)),r+=3;continue}}}else if(i[r]<248&&e._checkContinuation(i,r,3)){var u=(7&i[r])<<18|(63&i[r+1])<<12|(63&i[r+2])<<6|63&i[r+3];if(u>65536&&u<1114112){u-=65536,n.push(String.fromCharCode(u>>>10|55296)),n.push(String.fromCharCode(1023&u|56320)),r+=4;continue}}n.push(String.fromCharCode(65533)),++r}return n.join("")}},{key:"_checkContinuation",value:function(e,t,n){var i=e;if(t+n>>4,i=15&t;7===i?(this._parseAVCPacket(n),this.resetStatus()):this.error("unsupported codecId: "+i)}},{key:"_parseAVCPacket",value:function(e){this.unreadLength<4&&this.error("Invalid Avc Tag");var t=this._store.isLe,n=this.data.buffer,i=new DataView(n,this.readOffset,this.unreadLength),r=i.getUint8(0),a=16777215&i.getUint32(0,!t);switch(a=a<<8>>8,this.readOffset+=4,r){case 0:var o=this.currentTag,s=o.position,f=o.tagSize;this._store.metaEndPosition=s+u.default.readAsInt(f)+4,this._parseAVCDecoderConfigurationRecord();break;case 1:this._parseAVCVideoData(e,a)}}},{key:"_parseAVCDecoderConfigurationRecord",value:function(){if(this.unreadLength<7)this.error("Invalid AVCDecoderConfigurationRecord, lack of data!");else{var e=this._store.mediaInfo,t=this._store,n=this._store.videoMetaData,i=this._store.videoTrack,r=new o.default(this.data.buffer,this);n?void 0!==n.avcc&&this.error("found another AVCDecoderConfigurationRecord!"):(t.state._hasVideo||t.state.hasVideoFlagOverrided||(t.state._hasVideo=!0,t._mediaInfo.hasVideo=!0),(n=t.videoMetaData={}).type="video",n.id=i.id,n.timeScale=t.videoTimeScale,n.duration=t.state.duration,e.timescale=t.videoTimeScale);var u=r.getUint8(),f=r.getUint8();if(r.getUint8(),r.getUint8(),1===u&&0!==f){var l=t.state.naluLengthSize=r.getUint(2,this.readOffset,!1)+1;if(3===l||4===l){var c=r.getUint(5,null,!1);if(0!==c){c>1&&(this.emitError("decoder",{line:132,handler:"_parseAVCDecoderConfigurationRecord",msg:"spsLength > 1"}),this.warn("AVCDecoderConfigurationRecord: spsLength > 1"));for(var d=void 0,h=0;h1&&this.warn("AVCDecoderConfigurationRecord has ppsCount: "+R);for(var j=0;j0;){if(this.unreadLength<4){this.warn("not enough data for parsing AVC");break}var f=this.readOffset,l=4===a?n.getUint32():n.getUint24();if(l>this.unreadLength)return;var c=n.getUint(5,this.readOffset,!1);5===c&&(u=!0);var d=new Uint8Array(this.data.buffer,f,a+l);this.readOffset=f+a+l;var h={type:c,data:d};i.push(h),r+=d.byteLength}if(n=null,i.length){var p=this._store.videoTrack,v={units:i,length:r,dts:s,cps:t,pts:s+t,isKeyframe:u,position:u?this.currentTag.position:void 0};p.samples.push(v),p.length+=r}}},{key:"readData",value:function(e){var t=this.data,n=this.readOffset;return this.dataSize>n+e?(this.readOffset+=e,t.slice(n,e)):[]}},{key:"dataSize",get:function(){return this.data.length}},{key:"unreadLength",get:function(){return this.dataSize-this.readOffset}}]),t}();t.default=l},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,r=function(){function e(e,t){for(var n=0;n2&&3===e[r]&&0===e[r-1]&&0===e[r-2]||(n[i++]=e[r]);return new Uint8Array(n.buffer,0,i)}}]),e}();t.default=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,r=function(){function e(e,t){for(var n=0;ne?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,e-=(t=e>>3)>>3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e),t}},{key:"readBits",value:function(e){var t=Math.min(this.bitsAvailable,e),n=this.word>>>32-t;return e>32&&o.default.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0?this.word<<=t:this.bytesAvailable>0&&this.loadWord(),(t=e-t)>0&&this.bitsAvailable?n<>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBoolean",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"readUShort",value:function(){return this.readBits(16)}},{key:"readUInt",value:function(){return this.readBits(32)}},{key:"skipScalingList",value:function(e){var t,n=8,i=8;for(t=0;t>>4,u=(12&r)>>>2,f=r%1;if(i.audioSampleRate=o.soundRateTypes[u],i.channelCount=0===f?1:2,10===s||2===s){if(10===s){var l=this._parseAACAudio();if(!l)return;var c=l.data,d=l.data.sampleFreq;if(0===l.packetType){i.sampleRate=d,i.channelCount=c.channelCount,i.codec=c.codec,i.manifestCodec=c.manifestCodec,i.config=c.config,i.refSampleDuration=1024/d*i.timeScale,t.hasInitialMetaDispatched?(t.videoTrack.length||t.audioTrack.length)&&this.handleDataReady(t.videoTrack,t.audioTrack):t.state._audioInitialMetadataDispatched=!0,this.handleMetaDataReady("audio",i);var h=t.mediaInfo;h.audioCodec=i.codec,h.audioSampleRate=i.sampleRate,h.audioChannelCount=i.channelCount,h.audioConfig=i.config,h.hasVideo?h.videoCodec&&(h.mimeType='video/x-flv; codecs="'+h.videoCodec+","+h.audioCodec+'"',h.codec=h.mimeType.replace("x-flv","mp4")):(h.mimeType='video/x-flv; codecs="'+h.audioCodec+'"',h.codec=h.mimeType.replace("x-flv","mp4")),h.isComplete&&this.handleMediaInfoReady(h)}else if(1===l.packetType){var p=t.state.timeStampBase+this.currentTag.getTime(),v={unit:l.data,length:l.data.byteLength,dts:p,pts:p};n.samples.push(v),n.length+=l.data.length}}this.resetStatus()}else this.error("only support AAC Audio format so far")}},{key:"_parseAACAudio",value:function(){if(!(this.unreadLength<=1)){var e={},t=new Uint8Array(this.data.buffer,this.readOffset,this.unreadLength),n=t[0];if(this.readOffset+=1,e.packetType=n,n)e.data=t.slice(1);else{var i=this.currentTag,r=i.position,a=i.tagSize;this._store.metaEndPosition=r+u.default.readAsInt(a)+4,e.data=this._parseAACAudioSpecificConfig()}return e}}},{key:"_parseAACAudioSpecificConfig",value:function(){var e,t=new a.default(this.data.buffer,this),n=a.default.getAndNum,i={samplingFrequency:null,extAudioObjectType:null,extAudioSamplingIdx:null},r={},u=t.getUint8(),f=t.getUint8(),l=e=u>>>3,c=(u&n(5,7))<<1|f>>>7;if(c<0||c>o.samplingFrequencyTypes.length)return this.emitError("decoder",{line:"141",handle:"_parseAACAudioSpecificConfig",msg:"invalid samplingFrequencyIndex "+c}),void this.dispatch(o.EventTypes.ERROR,"error samplingFrequencyIndex: "+c);i.samplingFrequency=o.samplingFrequencyTypes[c];var d=i.channelCount=(f&n(1,4))>>>3;if(d<0||d>7)return this.emitError("decoder",{line:"154",handle:"_parseAACAudioSpecificConfig",msg:"invalid Audio Channel Count: "+d}),void this.dispatch(o.EventTypes.ERROR,"error Audio Channel Count: "+d);if(5===l){var h=t.getUint8();i.extAudioSamplingIdx=(f&n(5,7))<<1|h>>>7,i.extAudioObjectType=(h&n(1,5))>>>2}return s.default.browser===o.browserTypes.FIRE_FOX?c>=6?(l=5,r=new Array(4),i.extAudioSamplingIdx=c-3):(l=2,r=new Array(2),i.extAudioSamplingIdx=c):s.default.os.isAndroid?(l=2,r=new Array(2),i.extAudioSamplingIdx=c):(l=5,i.extensionSamplingIndex=c,r=new Array(4),c>=6?i.extensionSamplingIdx=c-3:1===d&&(l=2,r=new Array(2),i.extensionSamplingIndex=c)),r[0]=l<<3,r[0]|=(14&c)>>1,r[1]|=(1&c)<<7,r[1]|=d<<3,5===l&&(r[1]|=(14&i.extAudioSamplingIdx)>>1,r[2]=(1&i.extensionSamplingIdx)<<7,r[2]|=8,r[3]=0),{config:r,sampleFreq:i.samplingFrequency,channelCount:d,codec:"mp4a.40."+l,manifestCodec:"mp4a.40."+e}}},{key:"initAudioMeta",value:function(e){var t=this._store,n=t.state,i=t.audioTrack;return e.duration=n.duration,e.timeScale=n.timeScale,e.type="audio",e.id=i.id,e}},{key:"resetStatus",value:function(){this.currentTag=null,this.data=new Uint8Array(0),this.readOffset=0}},{key:"dataSize",get:function(){return this.data.length}},{key:"unreadLength",get:function(){return this.dataSize-this.readOffset}}]),t}();t.default=l},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=[{name:"duration",type:Boolean,parser:function(e,t){e.mediaInfo.duration=t.duration}},{name:"hasAudio",type:Boolean,parser:function(e,t){e.mediaInfo.hasAudio=t.hasAudio}},{name:"hasVideo",type:Boolean,parser:function(e,t){e.mediaInfo.hasVideo=t.hasVideo}},{name:"audiodatarate",type:Number,parser:function(e,t){e.mediaInfo.audioDataRate=t.audiodatarate}},{name:"videodatarate",type:Number,parser:function(e,t){e.mediaInfo.videoDataRate=t.videodatarate}},{name:"width",type:Number,parser:function(e,t){e.mediaInfo.width=t.width}},{name:"height",type:Number,parser:function(e,t){e.mediaInfo.height=t.height}},{name:"duration",type:Number,parser:function(e,t){if(!e.state.duration){var n=Math.floor(t.duration*e.state.timeScale);e.state.duration=e.mediaInfo.duration=n}},onTypeErr:function(e){e.mediaInfo.duration=0}},{name:"framerate",type:Number,parser:function(e,t){var n=Math.floor(1e3*t.framerate);if(n>0){var i=n/1e3,r=e.referFrameRate,a=e.mediaInfo;r.fixed=!0,r.fps=i,r.fpsNum=n,r.fpsDen=1e3,a.fps=i}}},{name:"keyframes",type:Object,parser:function(e,t){var n=t.keyframes;e.mediaInfo.hasKeyframes=!!n,n&&(e.mediaInfo.keyframes=this._parseKeyframes(n)),t.keyframes=null},onTypeErr:function(e){e.mediaInfo.hasKeyframes=!1}}];t.default=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n-1}},function(e,t,n){"use strict";e.exports=function(e){if("function"!=typeof e)throw new TypeError(e+" is not a function");return e}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=function(){return{preloadTime:30,minCachedTime:5,autoCleanSourceBuffer:!0,autoCleanMaxBackTime:30,isLive:!1,cors:!0}}}]);