!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Hls=t()}}(function(){return function n(e,t,i){function r(s,d){if(!t[s]){if(!e[s]){var l="function"==typeof require&&require;if(!d&&l)return l(s,!0);if(a)return a(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var o=t[s]={exports:{}};e[s][0].call(o.exports,function(t){var i=e[s][1][t];return r(i?i:t)},o,o.exports,n,e,t,i)}return t[s].exports}for(var a="function"==typeof require&&require,s=0;se||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},e.prototype.emit=function(u){var o,s,a,n,e,l;if(this._events||(this._events={}),"error"===u&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if(o=arguments[1],o instanceof Error)throw o;throw TypeError('Uncaught, unspecified "error" event.')}if(s=this._events[u],r(s))return!1;if(t(s))switch(arguments.length){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:for(a=arguments.length,n=new Array(a-1),e=1;a>e;e++)n[e-1]=arguments[e];s.apply(this,n)}else if(i(s)){for(a=arguments.length,n=new Array(a-1),e=1;a>e;e++)n[e-1]=arguments[e];for(l=s.slice(),a=l.length,e=0;a>e;e++)l[e].apply(this,n)}return!0},e.prototype.addListener=function(s,a){var n;if(!t(a))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",s,t(a.listener)?a.listener:a),this._events[s]?i(this._events[s])?this._events[s].push(a):this._events[s]=[this._events[s],a]:this._events[s]=a,i(this._events[s])&&!this._events[s].warned){var n;n=r(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[s].length>n&&(this._events[s].warned=!0,"function"==typeof console.trace)}return this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(r,e){function i(){this.removeListener(r,i),s||(s=!0,e.apply(this,arguments))}if(!t(e))throw TypeError("listener must be a function");var s=!1;return i.listener=e,this.on(r,i),this},e.prototype.removeListener=function(s,r){var e,n,o,a;if(!t(r))throw TypeError("listener must be a function");if(!this._events||!this._events[s])return this;if(e=this._events[s],o=e.length,n=-1,e===r||t(e.listener)&&e.listener===r)delete this._events[s],this._events.removeListener&&this.emit("removeListener",s,r);else if(i(e)){for(a=o;a-->0;)if(e[a]===r||e[a].listener&&e[a].listener===r){n=a;break}if(0>n)return this;1===e.length?(e.length=0,delete this._events[s]):e.splice(n,1),this._events.removeListener&&this.emit("removeListener",s,r)}return this},e.prototype.removeAllListeners=function(e){var r,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(r in this._events)"removeListener"!==r&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],t(i))this.removeListener(e,i);else for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},e.prototype.listeners=function(e){var i;return i=this._events&&this._events[e]?t(this._events[e])?[this._events[e]]:this._events[e].slice():[]},e.listenerCount=function(e,i){var r;return r=e._events&&e._events[i]?t(e._events[i])?1:e._events[i].length:0}},{}],2:[function(a,r,n){var s=arguments[3],e=arguments[4],i=arguments[5],t=JSON.stringify;r.exports=function(u){for(var r,o=Object.keys(i),a=0,l=o.length;l>a;a++){var n=o[a];if(i[n].exports===u){r=n;break}}if(!r){r=Math.floor(Math.pow(16,8)*Math.random()).toString(16);for(var d={},a=0,l=o.length;l>a;a++){var n=o[a];d[n]=n}e[r]=[Function(["require","module","exports"],"("+u+")(self)"),d]}var h=Math.floor(Math.pow(16,8)*Math.random()).toString(16),f={};f[r]=r,e[h]=[Function(["require"],"require("+t(r)+")(self)"),f];var c="("+s+")({"+Object.keys(e).map(function(i){return t(i)+":["+e[i][0]+","+t(e[i][1])+"]"}).join(",")+"},{},["+t(h)+"])",v=window.URL||window.webkitURL||window.mozURL||window.msURL;return new Worker(v.createObjectURL(new Blob([c],{type:"text/javascript"})))}},{}],3:[function(i,r,e){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(r,i){for(var t=0;t=e;e++)if(i=e<=this.lastfetchlevel?.8*r:.7*r,ik){if(this.hls.nextLoadLevel=n,this.level=n,a=this.levels[n].details,"undefined"==typeof a){this.state=this.WAITING_LEVEL;break}var o=a.fragments,f=o.length,u=o[0].start,b=o[f-1].start+o[f-1].duration,r=void 0;if(a.live){if(l=a.startSN&&g<=a.endSN&&(r=o[g-a.startSN],e.logger.log("live playlist, switching playlist, load frag with next SN: "+r.sn))}r||(r=o[Math.round(f/2)],e.logger.log("live playlist, switching playlist, unknown, load middle frag : "+r.sn))}}else u>l&&(r=o[0]);if(!r){if(l>b)break;for(h=0;f>h&&(r=o[h],u=r.start,!(l>=u&&u+r.duration>l));h++);if(this.fragPrevious&&r.level===this.fragPrevious.level&&r.sn===this.fragPrevious.sn){if(h===f-1)break;r=o[h+1],e.logger.log("SN just loaded, load next one: "+r.sn)}}if(e.logger.log("Loading "+r.sn+" of ["+a.startSN+" ,"+a.endSN+"],level "+n+", currentTime:"+d+",bufferEnd:"+l.toFixed(3)),r.autoLevel=this.hls.autoLevelEnabled,this.levels.length>1&&(r.expectedLen=Math.round(r.duration*this.levels[n].bitrate/8),r.trequest=new Date),void 0!==this.fragLoadIdx?this.fragLoadIdx++:this.fragLoadIdx=0,r.loadCounter){r.loadCounter++;var A=this.config.fragLoadingLoopThreshold;if(r.loadCounter>A&&Math.abs(this.fragLoadIdx-r.loadIdx)1){var T=new Date-s.trequest;if(T>500*s.duration){var _=1e3*s.loaded/T;s.expectedLeny&&m>S&&(e.logger.warn("loading too slow, abort fragment loading"),e.logger.log("fragLoadedDelay/bufferStarvationDelay/fragLevelNextLoadedDelay :"+m.toFixed(1)+"/"+y.toFixed(1)+"/"+S.toFixed(1)),s.loader.abort(),this.hls.trigger(t.default.FRAG_LOAD_EMERGENCY_ABORTED,{frag:s}),this.state=this.IDLE)}}break;case this.PARSING:break;case this.PARSED:case this.APPENDING:if(this.sourceBuffer){if(this.sourceBuffer.audio&&this.sourceBuffer.audio.updating||this.sourceBuffer.video&&this.sourceBuffer.video.updating);else if(this.mp4segments.length){var E=this.mp4segments.shift();try{this.sourceBuffer[E.type].appendBuffer(E.data),this.appendError=0}catch(r){e.logger.error("error while trying to append buffer:"+r.message+",try appending later"),this.mp4segments.unshift(E),this.appendError?this.appendError++:this.appendError=1;var v={type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.FRAG_APPENDING_ERROR,frag:this.fragCurrent};if(this.appendError>this.config.appendErrorMaxRetry)return e.logger.log("fail "+this.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),v.fatal=!0,this.hls.trigger(t.default.ERROR,v),void(this.state=this.ERROR);v.fatal=!1,this.hls.trigger(t.default.ERROR,v)}this.state=this.APPENDING}}else this.state=this.IDLE;break;case this.BUFFER_FLUSHING:for(;this.flushRange.length;){var L=this.flushRange[0];if(!this.flushBuffer(L.start,L.end))break;this.flushRange.shift()}0===this.flushRange.length&&(this.immediateSwitch&&this.immediateLevelSwitchEnd(),this.state=this.IDLE,this.fragPrevious=null)}this._checkFragmentChanged()}},{key:"bufferInfo",value:function(i,a){var l,o,s,u,e,h=this.video,r=h.buffered,t=[];for(e=0;e=n&&d>i?(o=n,s=d+a,l=s-i):n>i+a&&(u=n)}return{len:l,start:o,end:s,nextStart:u}}},{key:"getBufferRange",value:function(i){var e,t;for(e=this.bufferRange.length-1;e>=0;e--)if(t=this.bufferRange[e],i>=t.start&&i<=t.end)return t;return null}},{key:"followingBufferRange",value:function(e){return e?this.getBufferRange(e.end+.5):null}},{key:"isBuffered",value:function(i){for(var r=this.video,t=r.buffered,e=0;e=t.start(e)&&i<=t.end(e))return!0;return!1}},{key:"_checkFragmentChanged",value:function(){var r,i,s=this.video;if(s&&s.seeking===!1&&(i=s.currentTime,i>Math.sign(s.playbackRate)*this.lastCurrentTime&&(this.lastCurrentTime=i),this.isBuffered(i)?r=this.getBufferRange(i):this.isBuffered(i+.1)&&(r=this.getBufferRange(i+.1)),r)){var a=r.frag;a!==this.fragPlaying&&(this.fragPlaying=a,this.hls.trigger(t.default.FRAG_CHANGED,{frag:a}));var n=this.levels[this.level].details;if(n&&!n.live&&a.sn===n.endSN){var o=this.mediaSource;o&&"open"===o.readyState&&(e.logger.log("all media data available, signal endOfStream() to MediaSource"),o.endOfStream())}}}},{key:"flushBuffer",value:function(d,l){var i,t,o,n,r,s;if(this.flushBufferCounter++<2*this.bufferRange.length&&this.sourceBuffer)for(var u in this.sourceBuffer){if(i=this.sourceBuffer[u],i.updating)return!1;for(t=0;t.5)return e.logger.log("flush "+u+" ["+r+","+s+"], of ["+o+","+n+"], pos:"+this.video.currentTime),i.remove(r,s),!1}var a,h=[];for(t=0;tr-a&&(e.logger.log("adjust currentTime from "+a+" to "+r),i.currentTime=r)}}this.seekAfterBuffered=void 0}this.tick()}},{key:"onSBUpdateError",value:function(r){e.logger.error("sourceBuffer error:"+r),this.state=this.ERROR,this.hls.trigger(t.default.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.FRAG_APPENDING_ERROR,fatal:!0,frag:this.fragCurrent})}},{key:"timeRangesToString",value:function(t){for(var i="",r=t.length,e=0;r>e;e++)i+="["+t.start(e)+","+t.end(e)+"]";return i}},{key:"currentLevel",get:function(){if(this.video){var e=this.getBufferRange(this.video.currentTime);if(e)return e.frag.level}return-1}},{key:"nextBufferRange",get:function(){return this.video?this.followingBufferRange(this.getBufferRange(this.video.currentTime)):null}},{key:"nextLevel",get:function(){var e=this.nextBufferRange;return e?e.frag.level:-1}}]),r}();a.default=v,c.exports=a.default},{"../demux/demuxer":8,"../errors":11,"../events":12,"../helper/level-helper":13,"../utils/logger":19}],5:[function(r,a,s){"use strict";function l(e){return e&&e.__esModule?e:{default:e}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(s,"__esModule",{value:!0});var d=function(){function e(r,i){for(var t=0;t=0&&r1?i-1:0),e=1;i>e;e++)s[e-1]=arguments[e];t.emit.apply(t,[r,r].concat(s))},t.off=function(s){for(var i=arguments.length,r=Array(i>1?i-1:0),e=1;i>e;e++)r[e-1]=arguments[e];t.removeListener.apply(t,[s].concat(r))},i.addEventListener("message",function(e){switch(e.data.cmd){case"init":i.demuxer=new a.default(t,h.default);break;case"demux":i.demuxer.push(new Uint8Array(e.data.data),e.data.audioCodec,e.data.videoCodec,e.data.timeOffset,e.data.cc,e.data.level,e.data.duration),i.demuxer.remux()}}),t.on(e.default.FRAG_PARSING_INIT_SEGMENT,function(s,t){var e={event:s},r=[];t.audioCodec&&(e.audioCodec=t.audioCodec,e.audioMoov=t.audioMoov.buffer,e.audioChannelCount=t.audioChannelCount,r.push(e.audioMoov)),t.videoCodec&&(e.videoCodec=t.videoCodec,e.videoMoov=t.videoMoov.buffer,e.videoWidth=t.videoWidth,e.videoHeight=t.videoHeight,r.push(e.videoMoov)),i.postMessage(e,r)}),t.on(e.default.FRAG_PARSING_DATA,function(r,e){ var t={event:r,type:e.type,startPTS:e.startPTS,endPTS:e.endPTS,startDTS:e.startDTS,endDTS:e.endDTS,moof:e.moof.buffer,mdat:e.mdat.buffer,nb:e.nb};i.postMessage(t,[t.moof,t.mdat])}),t.on(e.default.FRAG_PARSED,function(e){i.postMessage({event:e})}),t.on(e.default.ERROR,function(e,t){i.postMessage({event:e,data:t})}),t.on(e.default.FRAG_PARSING_METADATA,function(e,t){var r={event:e,samples:t.samples};i.postMessage(r)})};r.default=o,n.exports=r.default},{"../demux/demuxer-inline":6,"../events":12,"../remux/mp4-remuxer":18,events:1}],8:[function(e,l,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var f=function(){function e(r,i){for(var t=0;te?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,t=e>>3,e-=t>>3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)}},{key:"readBits",value:function(t){var e=Math.min(this.bitsAvailable,t),i=this.word>>>32-e;return t>32&&a.logger.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=e,this.bitsAvailable>0?this.word<<=e:this.bytesAvailable>0&&this.loadWord(),e=t-e,e>0?i<>>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:"skipScalingList",value:function(s){var t,r,i=8,e=8;for(t=0;s>t;t++)0!==e&&(r=this.readEG(),e=(i+r+256)%256),i=0===e?i:e}},{key:"readSPS",value:function(){var t,o,l,r,s,a,i,v,e,u=0,d=0,h=0,f=0;if(this.readUByte(),t=this.readUByte(),o=this.readBits(5),this.skipBits(3),l=this.readUByte(),this.skipUEG(),100===t||110===t||122===t||144===t){var c=this.readUEG();if(3===c&&this.skipBits(1),this.skipUEG(),this.skipUEG(),this.skipBits(1),this.readBoolean())for(v=3!==c?8:12,e=0;v>e;e++)this.readBoolean()&&(6>e?this.skipScalingList(16):this.skipScalingList(64))}this.skipUEG();var n=this.readUEG();if(0===n)this.readUEG();else if(1===n)for(this.skipBits(1),this.skipEG(),this.skipEG(),r=this.readUEG(),e=0;r>e;e++)this.skipEG();return this.skipUEG(),this.skipBits(1),s=this.readUEG(),a=this.readUEG(),i=this.readBits(1),0===i&&this.skipBits(1),this.skipBits(1),this.readBoolean()&&(u=this.readUEG(),d=this.readUEG(),h=this.readUEG(),f=this.readUEG()),{profileIdc:t,profileCompat:o,levelIdc:l,width:16*(s+1)-2*u-2*d,height:(2-i)*(a+1)*16-2*h-2*f}}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}}]),e}();e.default=n,i.exports=e.default},{"../utils/logger":19}],10:[function(i,h,r){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var d=function(){function e(r,i){for(var t=0;ti;i+=188)if(71===r[i]){if(d=!!(64&r[i+1]),u=((31&r[i+1])<<8)+r[i+2],p=(48&r[i+3])>>4,p>1){if(a=i+5+r[i+4],a===i+188)continue}else a=i+4;m?u===c?(d&&(n&&this._parseAVCPES(this._parsePES(n)),n={data:[],size:0}),n&&(n.data.push(r.subarray(a,i+188)),n.size+=i+188-a)):u===f?(d&&(o&&this._parseAACPES(this._parsePES(o)),o={data:[],size:0}),o&&(o.data.push(r.subarray(a,i+188)),o.size+=i+188-a)):u===g&&(d&&(l&&this._parseID3PES(this._parsePES(l)),l={data:[],size:0}),l&&(l.data.push(r.subarray(a,i+188)),l.size+=i+188-a)):(d&&(a+=r[a]+1),0===u?this._parsePAT(r,a):u===this._pmtId&&(this._parsePMT(r,a),m=this.pmtParsed=!0,c=this._avcTrack.id,f=this._aacTrack.id,g=this._id3Track.id))}else this.observer.trigger(s.default.ERROR,{type:e.ErrorTypes.MEDIA_ERROR,details:e.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"TS packet did not start with 0x47"});n&&this._parseAVCPES(this._parsePES(n)),o&&this._parseAACPES(this._parsePES(o)),l&&this._parseID3PES(this._parsePES(l))}},{key:"remux",value:function(){this.remuxer.remux(this._aacTrack,this._avcTrack,this._id3Track,this.timeOffset)}},{key:"destroy",value:function(){this.switchLevel(),this._initPTS=this._initDTS=void 0,this._duration=0}},{key:"_parsePAT",value:function(e,t){this._pmtId=(31&e[t+10])<<8|e[t+11]}},{key:"_parsePMT",value:function(i,e){var s,a,n,r;for(s=(15&i[e+1])<<8|i[e+2],a=e+3+s-4,n=(15&i[e+10])<<8|i[e+11],e+=12+n;a>e;){switch(r=(31&i[e+1])<<8|i[e+2],i[e]){case 15:this._aacTrack.id=r;break;case 21:this._id3Track.id=r;break;case 27:this._avcTrack.id=r;break;default:t.logger.log("unkown stream type:"+i[e])}e+=((15&i[e+3])<<8|i[e+4])+5}}},{key:"_parsePES",value:function(t){var e,s,u,o,d,a,i,r,n,l=0;if(e=t.data[0],u=(e[0]<<16)+(e[1]<<8)+e[2],1===u){for(o=(e[4]<<8)+e[5],s=e[7],192&s&&(i=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,i>4294967295&&(i-=8589934592),64&s?(r=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2,r>4294967295&&(r-=8589934592)):r=i),d=e[8],n=d+9,t.data[0]=t.data[0].subarray(n),t.size-=n,a=new Uint8Array(t.size);t.data.length;)e=t.data.shift(),a.set(e,l),l+=e.byteLength;return{data:a,pts:i,dts:r,len:o}}return null}},{key:"_parseAVCPES",value:function(t){var i,u,a=this,e=this._avcTrack,r=!1;if(i=this._parseAVCNALu(t.data),0===i.length&this._avcTrack.samples.length>0){var o=this._avcTrack.samples[this._avcTrack.samples.length-1],s=o.units.units[o.units.units.length-1],l=new Uint8Array(s.data.byteLength+t.data.byteLength);l.set(s.data,0),l.set(t.data,s.data.byteLength),s.data=l,o.units.length+=t.data.byteLength,this._avcTrack.len+=t.data.byteLength}t.data=null,i.units.forEach(function(t){switch(t.type){case 1:var s=new n.default(t.data).readSliceType();(2===s||4===s||7===s||9===s)&&(r=!0);break;case 5:r=!0;break;case 7:if(!e.sps){var d=new n.default(t.data),i=d.readSPS();e.width=i.width,e.height=i.height,e.profileIdc=i.profileIdc,e.profileCompat=i.profileCompat,e.levelIdc=i.levelIdc,e.sps=[t.data],e.timescale=a.remuxer.timescale,e.duration=a.remuxer.timescale*a._duration;for(var h=t.data.subarray(1,4),u="avc1.",l=0;3>l;l++){var o=h[l].toString(16);o.length<2&&(o="0"+o),u+=o}e.codec=u}break;case 8:e.pps||(e.pps=[t.data])}}),i.length&&(r===!0||e.sps)&&(u={units:i,pts:t.pts,dts:t.dts,key:r},this._avcTrack.samples.push(u),this._avcTrack.len+=i.length,this._avcTrack.nbNalu+=i.units.length)}},{key:"_parseAVCNALu",value:function(r){for(var a,s,l,n,i,d,t=0,o=r.byteLength,e=0,h=[],f=0;o>t;)switch(a=r[t++],e){case 0:0===a&&(e=1);break;case 1:e=0===a?2:0;break;case 2:case 3:if(0===a)e=3;else if(1===a){if(n=31&r[t],i)l={data:r.subarray(i,t-e-1),type:d},f+=t-e-1-i,h.push(l);else if(s=t-e-1,s&&this._avcTrack.samples.length){var c=this._avcTrack.samples[this._avcTrack.samples.length-1],u=c.units.units[c.units.units.length-1],v=new Uint8Array(u.data.byteLength+s);v.set(u.data,0),v.set(r.subarray(0,s),u.data.byteLength),u.data=v,c.units.length+=s,this._avcTrack.len+=s}i=t,d=n,(1===n||5===n)&&(t=o),e=0}else e=0}return i&&(l={data:r.subarray(i,o),type:d},f+=o-i,h.push(l)),{units:h,length:f}}},{key:"_parseAACPES",value:function(p){var g,o,n,i,u,f,h,l,a=this._aacTrack,r=p.data;if(this.aacOverFlow){var v=new Uint8Array(this.aacOverFlow.byteLength+r.byteLength);v.set(this.aacOverFlow,0),v.set(r,this.aacOverFlow.byteLength),r=v}for(i=0,l=r.length;l-1>i&&(255!==r[i]||240!==(240&r[i+1]));i++);if(i){var c,d;if(l-1>i?(c="AAC PES did not start with ADTS header,offset:"+i,d=!1):(c="no ADTS header found in AAC PES",d=!0),this.observer.trigger(s.default.ERROR,{type:e.ErrorTypes.MEDIA_ERROR,details:e.ErrorDetails.FRAG_PARSING_ERROR,fatal:d,reason:c}),d)return}for(a.audiosamplerate||(o=this._ADTStoAudioConfig(r,i,this.audioCodec),a.config=o.config,a.audiosamplerate=o.samplerate,a.channelCount=o.channelCount,a.codec=o.codec,a.timescale=this.remuxer.timescale,a.duration=this.remuxer.timescale*this._duration,t.logger.log("parsed codec:"+a.codec+",rate:"+o.samplerate+",nb channel:"+o.channelCount)),h=0;l>i+5&&(n=(3&r[i+3])<<11,n|=r[i+4]<<3,n|=(224&r[i+5])>>>5,u=1&r[i+1]?7:9,n-=u,f=Math.round(p.pts+1024*h*this.PES_TIMESCALE/a.audiosamplerate),l>=i+u+n);)g={unit:r.subarray(i+u,i+u+n),pts:f,dts:f},this._aacTrack.samples.push(g),this._aacTrack.len+=n,i+=n+u,h++;l>i?this.aacOverFlow=r.subarray(i,l):this.aacOverFlow=null}},{key:"_ADTStoAudioConfig",value:function(u,d,o){var a,i,n,l,r,f=navigator.userAgent.toLowerCase(),h=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];return a=((192&u[d+2])>>>6)+1,i=(60&u[d+2])>>>2,i>h.length-1?void this.observer.trigger(s.default.ERROR,{type:e.ErrorTypes.MEDIA_ERROR,details:e.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+i}):(l=(1&u[d+2])<<2,l|=(192&u[d+3])>>>6,t.logger.log("manifest codec:"+o+",ADTS data:type:"+a+",sampleingIndex:"+i+"["+h[i]+"kHz],channelConfig:"+l),-1!==f.indexOf("firefox")?i>=6?(a=5,r=new Array(4),n=i-3):(a=2,r=new Array(2),n=i):-1!==f.indexOf("android")?(a=2,r=new Array(2),n=i):(a=5,r=new Array(4),o&&-1!==o.indexOf("mp4a.40.5")||!o&&i>=6?n=i-3:(o&&-1!==o.indexOf("mp4a.40.2")&&(i>=6||1===l)&&(a=2,r=new Array(2)),n=i)),r[0]=a<<3,r[0]|=(14&i)>>1,r[1]|=(1&i)<<7,r[1]|=l<<3,5===a&&(r[1]|=(14&n)>>1,r[2]=(1&n)<<7,r[2]|=8,r[3]=0),{config:r,samplerate:h[i],channelCount:l,codec:"mp4a.40."+a})}},{key:"_parseID3PES",value:function(e){this._id3Track.samples.push(e)}}]),i}();r.default=o,h.exports=r.default},{"../errors":11,"../events":12,"../utils/logger":19,"./exp-golomb":9}],11:[function(r,s,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t={NETWORK_ERROR:"hlsNetworkError",MEDIA_ERROR:"hlsMediaError",OTHER_ERROR:"hlsOtherError"};e.ErrorTypes=t;var i={MANIFEST_LOAD_ERROR:"manifestLoadError",MANIFEST_LOAD_TIMEOUT:"manifestLoadTimeOut",MANIFEST_PARSING_ERROR:"manifestParsingError",LEVEL_LOAD_ERROR:"levelLoadError",LEVEL_LOAD_TIMEOUT:"levelLoadTimeOut",LEVEL_SWITCH_ERROR:"levelSwitchError",FRAG_LOAD_ERROR:"fragLoadError",FRAG_LOOP_LOADING_ERROR:"fragLoopLoadingError",FRAG_LOAD_TIMEOUT:"fragLoadTimeOut",FRAG_PARSING_ERROR:"fragParsingError",FRAG_APPENDING_ERROR:"fragAppendingError"};e.ErrorDetails=i},{}],12:[function(i,t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={MSE_ATTACHED:"hlsMediaSourceAttached",MSE_DETACHING:"hlsMediaSourceDetaching",MSE_DETACHED:"hlsMediaSourceDetached",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsPTSUpdated",LEVEL_SWITCH:"hlsLevelSwitch",FRAG_LOADING:"hlsFragLoading",FRAG_LOAD_PROGRESS:"hlsFragLoadProgress",FRAG_LOAD_EMERGENCY_ABORTED:"hlsFragLoadEmergencyAborted",FRAG_LOADED:"hlsFragLoaded",FRAG_PARSING_INIT_SEGMENT:"hlsFragParsingInitSegment",FRAG_PARSING_METADATA:"hlsFraParsingMetadata",FRAG_PARSING_DATA:"hlsFragParsingData",FRAG_PARSED:"hlsFragParsed",FRAG_BUFFERED:"hlsFragBuffered",FRAG_CHANGED:"hlsFragChanged",FPS_DROP:"hlsFPSDrop",ERROR:"hlsError",DESTROYING:"hlsDestroying"},t.exports=e.default},{}],13:[function(i,r,e){"use strict";function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function e(r,i){for(var t=0;td)return void(r.PTSKnown=!1);for(var i=c;d>=i;i++){var l=f[h+i],s=o[i];u=l.cc-s.cc,isNaN(l.startPTS)||(s.start=s.startPTS=l.startPTS,s.endPTS=l.endPTS,s.duration=l.duration,n=s)}if(u)for(t.logger.log("discontinuity sliding from playlist, take drift into account"),i=0;ir.endSN)return 0;o=l-r.startSN,a=r.fragments,i=a[o],isNaN(i.startPTS)||(s=Math.max(s,i.startPTS),n=Math.min(n,i.endPTS));var u=s-i.start;for(i.start=i.startPTS=s,i.endPTS=n,i.duration=n-s,t=o;t>0;t--)e.updatePTS(a,t,t-1);for(t=o;tr?i.start=e.start+e.duration:i.start=e.start-i.duration:s>r?(e.duration=a-e.start,e.duration<0&&t.logger.error("negative duration computed for "+e+", there should be some duration drift between playlist and fragment!")):(i.duration=e.start-a,i.duration<0&&t.logger.error("negative duration computed for "+i+", there should be some duration drift between playlist and fragment!"))}}]),e}();e.default=n,r.exports=e.default},{"../utils/logger":19}],14:[function(t,f,s){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(s,"__esModule",{value:!0});var a=function(){function e(r,i){for(var t=0;t1?t-1:0),e=1;t>e;e++)s[e-1]=arguments[e];i.emit.apply(i,[r,r].concat(s))},i.off=function(s){for(var t=arguments.length,r=Array(t>1?t-1:0),e=1;t>e;e++)r[e-1]=arguments[e];i.removeListener.apply(i,[s].concat(r))},this.on=i.on.bind(i),this.off=i.off.bind(i),this.trigger=i.trigger.bind(i),this.playlistLoader=new d.default(this),this.fragmentLoader=new S.default(this),this.levelController=new y.default(this),this.abrController=new r.abrController(this),this.bufferController=new p.default(this)}return a(t,null,[{key:"isSupported",value:function(){return window.MediaSource&&window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')}},{key:"Events",get:function(){return r.default}},{key:"ErrorTypes",get:function(){return n.ErrorTypes}},{key:"ErrorDetails",get:function(){return n.ErrorDetails}}]),a(t,[{key:"destroy",value:function(){e.logger.log("destroy"),this.trigger(r.default.DESTROYING),this.playlistLoader.destroy(),this.fragmentLoader.destroy(),this.levelController.destroy(),this.bufferController.destroy(),this.url=null,this.detachVideo(),this.observer.removeAllListeners()}},{key:"attachVideo",value:function(i){e.logger.log("attachVideo"),this.video=i;var t=this.mediaSource=new MediaSource;this.onmso=this.onMediaSourceOpen.bind(this),this.onmse=this.onMediaSourceEnded.bind(this),this.onmsc=this.onMediaSourceClose.bind(this),t.addEventListener("sourceopen",this.onmso),t.addEventListener("sourceended",this.onmse),t.addEventListener("sourceclose",this.onmsc),i.src=URL.createObjectURL(t),i.addEventListener("error",this.onverror)}},{key:"detachVideo",value:function(){e.logger.log("detachVideo");var i=this.video;e.logger.log("trigger MSE_DETACHING"),this.trigger(r.default.MSE_DETACHING);var t=this.mediaSource;t&&("open"===t.readyState&&t.endOfStream(),t.removeEventListener("sourceopen",this.onmso),t.removeEventListener("sourceended",this.onmse),t.removeEventListener("sourceclose",this.onmsc),i.src="",this.mediaSource=null,e.logger.log("trigger MSE_DETACHED"),this.trigger(r.default.MSE_DETACHED)),this.onmso=this.onmse=this.onmsc=null,i&&(this.video=null)}},{key:"loadSource",value:function(t){e.logger.log("loadSource:"+t),this.url=t,this.trigger(r.default.MANIFEST_LOADING,{url:t})}},{key:"startLoad",value:function(){e.logger.log("startLoad"),this.bufferController.startLoad()}},{key:"recoverMediaError",value:function(){e.logger.log("recoverMediaError");var t=this.video;this.detachVideo(),this.attachVideo(t)}},{key:"onMediaSourceOpen",value:function(){e.logger.log("media source opened"),this.trigger(r.default.MSE_ATTACHED,{video:this.video,mediaSource:this.mediaSource}),this.mediaSource.removeEventListener("sourceopen",this.onmso)}},{key:"onMediaSourceClose",value:function(){e.logger.log("media source closed")}},{key:"onMediaSourceEnded",value:function(){e.logger.log("media source ended")}},{key:"levels",get:function(){return this.levelController.levels}},{key:"currentLevel",get:function(){return this.bufferController.currentLevel},set:function(t){e.logger.log("set currentLevel:"+t),this.loadLevel=t,this.bufferController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.bufferController.nextLevel},set:function(t){e.logger.log("set nextLevel:"+t),this.levelController.manualLevel=t,this.bufferController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(t){e.logger.log("set loadLevel:"+t),this.levelController.manualLevel=t}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel()},set:function(e){this.levelController.level=e}},{key:"firstLevel",get:function(){return this.levelController.firstLevel},set:function(t){e.logger.log("set firstLevel:"+t),this.levelController.firstLevel=t}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(t){e.logger.log("set startLevel:"+t),this.levelController.startLevel=t}},{key:"autoLevelCapping",get:function(){return this.abrController.autoLevelCapping},set:function(t){e.logger.log("set autoLevelCapping:"+t),this.abrController.autoLevelCapping=t}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}}]),t}();s.default=l,f.exports=s.default},{"./controller/abr-controller":3,"./controller/buffer-controller":4,"./controller/level-controller":5,"./errors":11,"./events":12,"./loader/fragment-loader":15,"./loader/playlist-loader":16,"./utils/logger":19,"./utils/xhr-loader":20,events:1}],15:[function(r,s,i){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function e(r,i){for(var t=0;t0;)switch(e.shift()){case"RES":t.width=parseInt(e.shift()),t.height=parseInt(e.shift());break;case"BAND":t.bitrate=parseInt(e.shift());break;case"NAME":t.name=e.shift();break;case"CODECS":for(r=e.shift().split(",");r.length>0;)i=r.shift(),-1!==i.indexOf("avc1")?t.videoCodec=this.avc1toavcoti(i):t.audioCodec=i}s.push(t),t={}}return s}},{key:"avc1toavcoti",value:function(i){var e,t=i.split(".");return t.length>2?(e=t.shift()+".",e+=parseInt(t.shift()).toString(16),e+=("00"+parseInt(t.shift()).toString(16)).substr(-4)):e=i,e}},{key:"parseLevelPlaylist",value:function(l,a,u){var e,n,i=0,r=0,t={url:a,fragments:[],live:!0,startSN:0},o=0;for(n=/(?:#EXT-X-(MEDIA-SEQUENCE):(\d+))|(?:#EXT-X-(TARGETDURATION):(\d+))|(?:#EXT(INF):([\d\.]+)[^\r\n]*[\r\n]+([^\r\n]+)|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))/g;null!==(e=n.exec(l));)switch(e.shift(),e=e.filter(function(e){return void 0!==e}),e[0]){case"MEDIA-SEQUENCE":i=t.startSN=parseInt(e[1]);break;case"TARGETDURATION":t.targetduration=parseFloat(e[1]);break;case"ENDLIST":t.live=!1;break;case"DIS":o++;break;case"INF":var s=parseFloat(e[1]);isNaN(s)||(t.fragments.push({url:this.resolve(e[2],a),duration:s,start:r,sn:i++,level:u,cc:o}),r+=s)}return t.totalduration=r,t.endSN=i-1,t}},{key:"loadsuccess",value:function(n,r){var o,a=n.currentTarget.responseText,i=n.currentTarget.responseURL,l=this.id,u=this.id2,s=this.hls;void 0===i&&(i=this.url),r.tload=new Date,r.mtime=new Date(n.currentTarget.getResponseHeader("Last-Modified")),0===a.indexOf("#EXTM3U")?a.indexOf("#EXTINF:")>0?null===this.id?s.trigger(e.default.MANIFEST_LOADED,{levels:[{url:i}],url:i,stats:r}):s.trigger(e.default.LEVEL_LOADED,{details:this.parseLevelPlaylist(a,i,l),level:l,id:u,stats:r}):(o=this.parseMasterPlaylist(a,i),o.length?s.trigger(e.default.MANIFEST_LOADED,{levels:o,url:i,stats:r}):s.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:i,reason:"no level found in manifest"})):s.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:t.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:i,reason:"no EXTM3U delimiter"})}},{key:"loaderror",value:function(s){var i,r;null===this.id?(i=t.ErrorDetails.MANIFEST_LOAD_ERROR,r=!0):(i=t.ErrorDetails.LEVEL_LOAD_ERROR,r=!1),this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:i,fatal:r,url:this.url,loader:this.loader,response:s.currentTarget,level:this.id,id:this.id2})}},{key:"loadtimeout",value:function(){var i,r;null===this.id?(i=t.ErrorDetails.MANIFEST_LOAD_TIMEOUT,r=!0):(i=t.ErrorDetails.LEVEL_LOAD_TIMEOUT,r=!1),this.loader.abort(),this.hls.trigger(e.default.ERROR,{type:t.ErrorTypes.NETWORK_ERROR,details:i,fatal:r,url:this.url,loader:this.loader,level:this.id,id:this.id2})}}]),i}();i.default=u,s.exports=i.default},{"../errors":11,"../events":12}],17:[function(a,t,e){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function e(r,i){for(var t=0;t>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,85,196,0,0]))}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"minf",value:function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))}},{key:"moof",value:function(t,i,r){return e.box(e.types.moof,e.mfhd(t),e.traf(r,i))}},{key:"moov",value:function(t){for(var i=t.length,r=[];i--;)r[i]=e.trak(t[i]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(r).concat(e.mvex(t)))}},{key:"mvex",value:function(i){for(var t=i.length,r=[];t--;)r[t]=e.trex(i[t]);return e.box.apply(null,[e.types.mvex].concat(r))}},{key:"mvhd",value:function(t,i){var r=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24&255,i>>16&255,i>>8&255,255&i,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.box(e.types.mvhd,r)}},{key:"sdtp",value:function(a){var i,t,r=a.samples||[],s=new Uint8Array(4+r.length);for(t=0;t>>8&255),r.push(255&t.sps[i].byteLength),r=r.concat(Array.prototype.slice.call(t.sps[i]));for(i=0;i>>8&255),s.push(255&t.pps[i].byteLength),s=s.concat(Array.prototype.slice.call(t.pps[i]));return e.box(e.types.avc1,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,t.width>>8&255,255&t.width,t.height>>8&255,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,19,118,105,100,101,111,106,115,45,99,111,110,116,114,105,98,45,104,108,115,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),e.box(e.types.avcC,new Uint8Array([1,t.profileIdc,t.profileCompat,t.levelIdc,255].concat([t.sps.length]).concat(r).concat([t.pps.length]).concat(s))),e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"esds",value:function(e){return new Uint8Array([0,0,0,0,3,23+e.config.length,0,1,0,4,15+e.config.length,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([e.config.length]).concat(e.config).concat([6,1,2]))}},{key:"mp4a",value:function(t){return e.box(e.types.mp4a,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.audiosamplerate>>8&255,255&t.audiosamplerate,0,0]),e.box(e.types.esds,e.esds(t)))}},{key:"stsd",value:function(t){return"audio"===t.type?e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))}},{key:"tkhd",value:function(t){return e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,t.id>>24&255,t.id>>16&255,t.id>>8&255,255&t.id,0,0,0,0,t.duration>>24,t.duration>>16&255,t.duration>>8&255,255&t.duration,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,t.width>>8&255,255&t.width,0,0,t.height>>8&255,255&t.height,0,0]))}},{key:"traf",value:function(t,i){var r=e.sdtp(t);return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,t.id>>24,t.id>>16&255,t.id>>8&255,255&t.id])),e.box(e.types.tfdt,new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i])),e.trun(t,r.length+16+16+8+16+8+8),r)}},{key:"trak",value:function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))}},{key:"trex",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t.id>>24,t.id>>16&255,t.id>>8&255,255&t.id,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(n,r){var i,t,s,a;for(i=n.samples||[],a=new Uint8Array(12+16*i.length),r+=8+a.byteLength,a.set([0,0,15,1,i.length>>>24&255,i.length>>>16&255,i.length>>>8&255,255&i.length,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),s=0;s>>24&255,t.duration>>>16&255,t.duration>>>8&255,255&t.duration,t.size>>>24&255,t.size>>>16&255,t.size>>>8&255,255&t.size,t.flags.isLeading<<2|t.flags.dependsOn,t.flags.isDependedOn<<6|t.flags.hasRedundancy<<4|t.flags.paddingValue<<1|t.flags.isNonSync,61440&t.flags.degradPrio,15&t.flags.degradPrio,t.cts>>>24&255,t.cts>>>16&255,t.cts>>>8&255,255&t.cts],12+16*s);return e.box(e.types.trun,a)}},{key:"initSegment",value:function(r){e.types||e.init();var t,i=e.moov(r);return t=new Uint8Array(e.FTYP.byteLength+i.byteLength),t.set(e.FTYP),t.set(i,e.FTYP.byteLength),t}}]),e}();e.default=s,t.exports=e.default},{}],18:[function(r,h,s){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(s,"__esModule",{value:!0});var d=function(){function e(r,i){for(var t=0;tb)l>1?i.logger.log("AVC:"+l+" ms hole between fragments detected,filling it"):-1>l&&i.logger.log("AVC:"+-l+" ms overlapping between fragments detected"),b&&(r=this.nextAvcDts,n=Math.max(n-l,r),i.logger.log("Video/PTS/DTS adjusted:"+n+"/"+r));else{var m=f*T;if(Math.abs(m-r)>3600*f){var R=m-r;r=m,n=r,this._initPTS-=R,this._initDTS-=R}}}A=Math.max(0,n),E=Math.max(0,r)}s={size:y,duration:0,cts:(n-r)/h,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0}},u.key===!0?(s.flags.dependsOn=2,s.flags.isNonSync=0):(s.flags.dependsOn=1,s.flags.isNonSync=1),d.push(s),v=r}d.length>=2&&(s.duration=d[d.length-2].duration),this.nextAvcDts=r+s.duration*h,a.len=0,a.nbNalu=0,a.samples=d,S=t.default.moof(a.sequenceNumber++,E/h,a),a.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:S,mdat:o,startPTS:A/f,endPTS:(n+h*s.duration)/f,startDTS:E/f,endDTS:(r+h*s.duration)/f,type:"video",nb:d.length})}},{key:"remuxAudio",value:function(a,R){var b,f,n,c,u,A,_,m,d,p,g,r,s,L=8,o=this.PES_TIMESCALE,v=this.PES2MP4SCALEFACTOR,l=[];for(u=new Uint8Array(a.len+8),b=new DataView(u.buffer),b.setUint32(0,u.byteLength),u.set(t.default.types.mdat,4);a.samples.length;){if(f=a.samples.shift(),c=f.unit,u.set(c,L),L+=c.byteLength,p=f.pts-this._initDTS,g=f.dts-this._initDTS,void 0!==d)r=this._PTSNormalize(p,d),s=this._PTSNormalize(g,d),n.duration=(s-d)/v,n.duration<0&&(n.duration=0);else{if(r=this._PTSNormalize(p,this.nextAacPts),s=this._PTSNormalize(g,this.nextAacPts),this.nextAacPts&&this.nextAacPts!==r){var h=Math.round(1e3*(r-this.nextAacPts)/o),E=Math.abs(h);if(E>1&&300>E)h>0?i.logger.log("AAC:"+h+" ms hole between fragments detected,filling it"):i.logger.log("AAC:"+-h+" ms overlapping between fragments detected"),r=s=this.nextAacPts,i.logger.log("Audio/PTS/DTS adjusted:"+r+"/"+s);else if(E){var y=o*R;if(Math.abs(y-r)>3600*o){var S=y-r;r=y,s=r,this._initPTS-=S,this._initDTS-=S}}}_=Math.max(0,r),m=Math.max(0,s)}n={size:c.byteLength,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},l.push(n),d=s}l.length>=2&&(n.duration=l[l.length-2].duration),this.nextAacPts=r+v*n.duration,a.len=0,a.samples=l,A=t.default.moof(a.sequenceNumber++,m/v,a),a.samples=[],this.observer.trigger(e.default.FRAG_PARSING_DATA,{moof:A,mdat:u,startPTS:_/o,endPTS:this.nextAacPts/o,startDTS:m/o,endDTS:(s+v*n.duration)/o,type:"audio",nb:l.length})}},{key:"remuxID3",value:function(i,s){var t,a=i.samples.length;if(a){for(var r=0;a>r;r++)t=i.samples[r],t.pts=(t.pts-this._initPTS)/this.PES_TIMESCALE,t.dts=(t.dts-this._initDTS)/this.PES_TIMESCALE;this.observer.trigger(e.default.FRAG_PARSING_METADATA,{samples:i.samples})}i.samples=[],s=s}},{key:"_PTSNormalize",value:function(e,t){var i;if(void 0===t)return e;for(i=e>t?-8589934592:8589934592;Math.abs(e-t)>4294967296;)e+=i;return e}},{key:"timescale",get:function(){return this.MP4_TIMESCALE}}]),r}();s.default=o,h.exports=s.default},{"../errors":11,"../events":12,"../remux/mp4-generator":17,"../utils/logger":19}],19:[function(n,o,i){"use strict";function t(){}Object.defineProperty(i,"__esModule",{value:!0});var r={log:t,warn:t,info:t,error:t},e=r,s=function(i){if(i===!0||"object"==typeof i){e.log=i.log?i.log.bind(i):void 0,e.info=i.info?i.info.bind(i):void 0,e.error=i.error?i.error.bind(i):void 0,e.warn=i.warn?i.warn.bind(i):void 0;try{e.log()}catch(i){e.log=t,e.info=t,e.error=t,e.warn=t}}else e=r};i.enableLogs=s;var a=e;i.logger=a},{}],20:[function(i,r,e){"use strict";function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var a=function(){function e(r,i){for(var t=0;t