/*! @name mux.js @version 5.12.2 @license Apache-2.0 */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).muxjs=e()}(this,(function(){"use strict";var t,e,i,n,a,s,r,o,d,h,p,l,u,c,f,m,g,y,S,v,_,b,w,T,k,C,P,A,D,U,L,E,O,x,R,M,I,N,B,W,G=Math.pow(2,32)-1;!function(){var t;if(b={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],pasp:[],sdtp:[],smhd:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],styp:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[]},"undefined"!=typeof Uint8Array){for(t in b)b.hasOwnProperty(t)&&(b[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);w=new Uint8Array(["i".charCodeAt(0),"s".charCodeAt(0),"o".charCodeAt(0),"m".charCodeAt(0)]),k=new Uint8Array(["a".charCodeAt(0),"v".charCodeAt(0),"c".charCodeAt(0),"1".charCodeAt(0)]),T=new Uint8Array([0,0,0,1]),C=new Uint8Array([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]),P=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]),A={video:C,audio:P},L=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),U=new Uint8Array([0,0,0,0,0,0,0,0]),E=new Uint8Array([0,0,0,0,0,0,0,0]),O=E,x=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),R=E,D=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0])}}(),t=function(t){var e,i,n=[],a=0;for(e=1;e>>1,e.samplingfrequencyindex<<7|e.channelcount<<3,6,1,2]))},f=function(e){return t(b.hdlr,A[e])},c=function(e){var i=new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,0,1,95,144,e.duration>>>24&255,e.duration>>>16&255,e.duration>>>8&255,255&e.duration,85,196,0,0]);return e.samplerate&&(i[12]=e.samplerate>>>24&255,i[13]=e.samplerate>>>16&255,i[14]=e.samplerate>>>8&255,i[15]=255&e.samplerate),t(b.mdhd,i)},u=function(e){return t(b.mdia,c(e),f(e.type),s(e))},a=function(e){return t(b.mfhd,new Uint8Array([0,0,0,0,(4278190080&e)>>24,(16711680&e)>>16,(65280&e)>>8,255&e]))},s=function(i){return t(b.minf,"video"===i.type?t(b.vmhd,D):t(b.smhd,U),e(),g(i))},r=function(e,i){for(var n=[],s=i.length;s--;)n[s]=S(i[s]);return t.apply(null,[b.moof,a(e)].concat(n))},o=function(e){for(var i=e.length,n=[];i--;)n[i]=p(e[i]);return t.apply(null,[b.moov,h(4294967295)].concat(n).concat(d(e)))},d=function(e){for(var i=e.length,n=[];i--;)n[i]=v(e[i]);return t.apply(null,[b.mvex].concat(n))},h=function(e){var i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,0,1,95,144,(4278190080&e)>>24,(16711680&e)>>16,(65280&e)>>8,255&e,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 t(b.mvhd,i)},m=function(e){var i,n,a=e.samples||[],s=new Uint8Array(4+a.length);for(n=0;n>>8),r.push(255&a[i].byteLength),r=r.concat(Array.prototype.slice.call(a[i]));for(i=0;i>>8),o.push(255&s[i].byteLength),o=o.concat(Array.prototype.slice.call(s[i]));if(n=[b.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,(65280&e.width)>>8,255&e.width,(65280&e.height)>>8,255&e.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]),t(b.avcC,new Uint8Array([1,e.profileIdc,e.profileCompatibility,e.levelIdc,255].concat([a.length],r,[s.length],o))),t(b.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192]))],e.sarRatio){var d=e.sarRatio[0],h=e.sarRatio[1];n.push(t(b.pasp,new Uint8Array([(4278190080&d)>>24,(16711680&d)>>16,(65280&d)>>8,255&d,(4278190080&h)>>24,(16711680&h)>>16,(65280&h)>>8,255&h])))}return t.apply(null,n)},I=function(e){return t(b.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,(65280&e.channelcount)>>8,255&e.channelcount,(65280&e.samplesize)>>8,255&e.samplesize,0,0,0,0,(65280&e.samplerate)>>8,255&e.samplerate,0,0]),i(e))},l=function(e){var i=new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,(4278190080&e.id)>>24,(16711680&e.id)>>16,(65280&e.id)>>8,255&e.id,0,0,0,0,(4278190080&e.duration)>>24,(16711680&e.duration)>>16,(65280&e.duration)>>8,255&e.duration,0,0,0,0,0,0,0,0,0,0,0,0,1,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,(65280&e.width)>>8,255&e.width,0,0,(65280&e.height)>>8,255&e.height,0,0]);return t(b.tkhd,i)},S=function(e){var i,n,a,s,r,o;return i=t(b.tfhd,new Uint8Array([0,0,0,58,(4278190080&e.id)>>24,(16711680&e.id)>>16,(65280&e.id)>>8,255&e.id,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0])),r=Math.floor(e.baseMediaDecodeTime/(G+1)),o=Math.floor(e.baseMediaDecodeTime%(G+1)),n=t(b.tfdt,new Uint8Array([1,0,0,0,r>>>24&255,r>>>16&255,r>>>8&255,255&r,o>>>24&255,o>>>16&255,o>>>8&255,255&o])),92,"audio"===e.type?(a=_(e,92),t(b.traf,i,n,a)):(s=m(e),a=_(e,s.length+92),t(b.traf,i,n,a,s))},p=function(e){return e.duration=e.duration||4294967295,t(b.trak,l(e),u(e))},v=function(e){var i=new Uint8Array([0,0,0,0,(4278190080&e.id)>>24,(16711680&e.id)>>16,(65280&e.id)>>8,255&e.id,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]);return"video"!==e.type&&(i[i.length-1]=0),t(b.trex,i)},W=function(t,e){var i=0,n=0,a=0,s=0;return t.length&&(void 0!==t[0].duration&&(i=1),void 0!==t[0].size&&(n=2),void 0!==t[0].flags&&(a=4),void 0!==t[0].compositionTimeOffset&&(s=8)),[0,0,i|n|a|s,1,(4278190080&t.length)>>>24,(16711680&t.length)>>>16,(65280&t.length)>>>8,255&t.length,(4278190080&e)>>>24,(16711680&e)>>>16,(65280&e)>>>8,255&e]},B=function(e,i){var n,a,s,r,o,d;for(i+=20+16*(r=e.samples||[]).length,s=W(r,i),(a=new Uint8Array(s.length+16*r.length)).set(s),n=s.length,d=0;d>>24,a[n++]=(16711680&o.duration)>>>16,a[n++]=(65280&o.duration)>>>8,a[n++]=255&o.duration,a[n++]=(4278190080&o.size)>>>24,a[n++]=(16711680&o.size)>>>16,a[n++]=(65280&o.size)>>>8,a[n++]=255&o.size,a[n++]=o.flags.isLeading<<2|o.flags.dependsOn,a[n++]=o.flags.isDependedOn<<6|o.flags.hasRedundancy<<4|o.flags.paddingValue<<1|o.flags.isNonSyncSample,a[n++]=61440&o.flags.degradationPriority,a[n++]=15&o.flags.degradationPriority,a[n++]=(4278190080&o.compositionTimeOffset)>>>24,a[n++]=(16711680&o.compositionTimeOffset)>>>16,a[n++]=(65280&o.compositionTimeOffset)>>>8,a[n++]=255&o.compositionTimeOffset;return t(b.trun,a)},N=function(e,i){var n,a,s,r,o,d;for(i+=20+8*(r=e.samples||[]).length,s=W(r,i),(n=new Uint8Array(s.length+8*r.length)).set(s),a=s.length,d=0;d>>24,n[a++]=(16711680&o.duration)>>>16,n[a++]=(65280&o.duration)>>>8,n[a++]=255&o.duration,n[a++]=(4278190080&o.size)>>>24,n[a++]=(16711680&o.size)>>>16,n[a++]=(65280&o.size)>>>8,n[a++]=255&o.size;return t(b.trun,n)},_=function(t,e){return"audio"===t.type?N(t,e):B(t,e)};var z,F,V,Y,j,X,q={ftyp:n=function(){return t(b.ftyp,w,T,w,k)},mdat:function(e){return t(b.mdat,e)},moof:r,moov:o,initSegment:function(t){var e,i=n(),a=o(t);return(e=new Uint8Array(i.byteLength+a.byteLength)).set(i),e.set(a,i.byteLength),e}},H=function(t){return t>>>0},Z=function(t){var e="";return e+=String.fromCharCode(t[0]),e+=String.fromCharCode(t[1]),e+=String.fromCharCode(t[2]),e+=String.fromCharCode(t[3])},$=H,K=function t(e,i){var n,a,s,r,o,d=[];if(!i.length)return null;for(n=0;n1?n+a:e.byteLength,s===i[0]&&(1===i.length?d.push(e.subarray(n+8,r)):(o=t(e.subarray(n+8,r),i.slice(1))).length&&(d=d.concat(o))),n=r;return d},J=function(t){var e,i=new DataView(t.buffer,t.byteOffset,t.byteLength),n={version:t[0],flags:new Uint8Array(t.subarray(1,4)),trackId:i.getUint32(4)},a=1&n.flags[2],s=2&n.flags[2],r=8&n.flags[2],o=16&n.flags[2],d=32&n.flags[2],h=65536&n.flags[0],p=131072&n.flags[0];return e=8,a&&(e+=4,n.baseDataOffset=i.getUint32(12),e+=4),s&&(n.sampleDescriptionIndex=i.getUint32(e),e+=4),r&&(n.defaultSampleDuration=i.getUint32(e),e+=4),o&&(n.defaultSampleSize=i.getUint32(e),e+=4),d&&(n.defaultSampleFlags=i.getUint32(e)),h&&(n.durationIsEmpty=!0),!a&&p&&(n.baseDataOffsetIsMoof=!0),n},Q=function(t){return{isLeading:(12&t[0])>>>2,dependsOn:3&t[0],isDependedOn:(192&t[1])>>>6,hasRedundancy:(48&t[1])>>>4,paddingValue:(14&t[1])>>>1,isNonSyncSample:1&t[1],degradationPriority:t[2]<<8|t[3]}},tt=function(t){var e,i={version:t[0],flags:new Uint8Array(t.subarray(1,4)),samples:[]},n=new DataView(t.buffer,t.byteOffset,t.byteLength),a=1&i.flags[2],s=4&i.flags[2],r=1&i.flags[1],o=2&i.flags[1],d=4&i.flags[1],h=8&i.flags[1],p=n.getUint32(4),l=8;for(a&&(i.dataOffset=n.getInt32(l),l+=4),s&&p&&(e={flags:Q(t.subarray(l,l+4))},l+=4,r&&(e.duration=n.getUint32(l),l+=4),o&&(e.size=n.getUint32(l),l+=4),h&&(1===i.version?e.compositionTimeOffset=n.getInt32(l):e.compositionTimeOffset=n.getUint32(l),l+=4),i.samples.push(e),p--);p--;)e={},r&&(e.duration=n.getUint32(l),l+=4),o&&(e.size=n.getUint32(l),l+=4),d&&(e.flags=Q(t.subarray(l,l+4)),l+=4),h&&(1===i.version?e.compositionTimeOffset=n.getInt32(l):e.compositionTimeOffset=n.getUint32(l),l+=4),i.samples.push(e);return i},et=H,it=function(t){var e={version:t[0],flags:new Uint8Array(t.subarray(1,4)),baseMediaDecodeTime:et(t[4]<<24|t[5]<<16|t[6]<<8|t[7])};return 1===e.version&&(e.baseMediaDecodeTime*=Math.pow(2,32),e.baseMediaDecodeTime+=et(t[8]<<24|t[9]<<16|t[10]<<8|t[11])),e},nt=H,at=function(t){return("00"+t.toString(16)).slice(-2)};z=function(t){return K(t,["moov","trak"]).reduce((function(t,e){var i,n,a,s,r;return(i=K(e,["tkhd"])[0])?(n=i[0],s=nt(i[a=0===n?12:20]<<24|i[a+1]<<16|i[a+2]<<8|i[a+3]),(r=K(e,["mdia","mdhd"])[0])?(a=0===(n=r[0])?12:20,t[s]=nt(r[a]<<24|r[a+1]<<16|r[a+2]<<8|r[a+3]),t):null):null}),{})},F=function(t,e){var i,n,a;return i=K(e,["moof","traf"]),n=[].concat.apply([],i.map((function(e){return K(e,["tfhd"]).map((function(i){var n,a,s;return n=nt(i[4]<<24|i[5]<<16|i[6]<<8|i[7]),a=t[n]||9e4,(s="number"!=typeof(s=K(e,["tfdt"]).map((function(t){var e,i;return e=t[0],i=nt(t[4]<<24|t[5]<<16|t[6]<<8|t[7]),1===e&&(i*=Math.pow(2,32),i+=nt(t[8]<<24|t[9]<<16|t[10]<<8|t[11])),i}))[0])||isNaN(s)?1/0:s)/a}))}))),a=Math.min.apply(null,n),isFinite(a)?a:0},V=function(t,e){var i,n=K(e,["moof","traf"]),a=0,s=0;if(n&&n.length){var r=K(n[0],["tfhd"])[0],o=K(n[0],["trun"])[0],d=K(n[0],["tfdt"])[0];if(r)i=J(r).trackId;if(d)a=it(d).baseMediaDecodeTime;if(o){var h=tt(o);h.samples&&h.samples.length&&(s=h.samples[0].compositionTimeOffset||0)}}return(a+s)/(t[i]||9e4)},Y=function(t){var e=K(t,["moov","trak"]),i=[];return e.forEach((function(t){var e=K(t,["mdia","hdlr"]),n=K(t,["tkhd"]);e.forEach((function(t,e){var a,s,r=Z(t.subarray(8,12)),o=n[e];"vide"===r&&(s=0===(a=new DataView(o.buffer,o.byteOffset,o.byteLength)).getUint8(0)?a.getUint32(12):a.getUint32(20),i.push(s))}))})),i},j=function(t){var e=K(t,["moov","trak"]),i=[];return e.forEach((function(t){var e,n,a={},s=K(t,["tkhd"])[0];s&&(n=(e=new DataView(s.buffer,s.byteOffset,s.byteLength)).getUint8(0),a.id=0===n?e.getUint32(12):e.getUint32(20));var r=K(t,["mdia","hdlr"])[0];if(r){var o=Z(r.subarray(8,12));a.type="vide"===o?"video":"soun"===o?"audio":o}var d=K(t,["mdia","minf","stbl","stsd"])[0];if(d){var h=d.subarray(8);a.codec=Z(h.subarray(4,8));var p,l=K(h,[a.codec])[0];l&&(/^[a-z]vc[1-9]$/i.test(a.codec)?(p=l.subarray(78),"avcC"===Z(p.subarray(4,8))&&p.length>11?(a.codec+=".",a.codec+=at(p[9]),a.codec+=at(p[10]),a.codec+=at(p[11])):a.codec="avc1.4d400d"):/^mp4[a,v]$/i.test(a.codec)?(p=l.subarray(28),"esds"===Z(p.subarray(4,8))&&p.length>20&&0!==p[19]?(a.codec+="."+at(p[19]),a.codec+="."+at(p[20]>>>2&63).replace(/^0/,"")):a.codec="mp4a.40.2"):a.codec=a.codec.toLowerCase())}var u=K(t,["mdia","mdhd"])[0];u&&(a.timescale=X(u)),i.push(a)})),i};var st={findBox:K,parseType:Z,timescale:z,startTime:F,compositionStartTime:V,videoTrackIds:Y,tracks:j,getTimescaleFromMediaHeader:X=function(t){var e=0===t[0]?12:20;return nt(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])}},rt=function(){this.init=function(){var t={};this.on=function(e,i){t[e]||(t[e]=[]),t[e]=t[e].concat(i)},this.off=function(e,i){var n;return!!t[e]&&(n=t[e].indexOf(i),t[e]=t[e].slice(),t[e].splice(n,1),n>-1)},this.trigger=function(e){var i,n,a,s;if(i=t[e])if(2===arguments.length)for(a=i.length,n=0;n1&&(e=t.shift(),t.byteLength-=e.byteLength,t.nalCount-=e.nalCount,t[0][0].dts=e.dts,t[0][0].pts=e.pts,t[0][0].duration+=e.duration),t},_t=function(t,e){var i,n,a,s,r,o=e||0,d=[];for(i=0;iAt/2))){for((r=Ct()[t.samplerate])||(r=e[0].data),o=0;o=i?t:(e.minSegmentDts=1/0,t.filter((function(t){return t.dts>=i&&(e.minSegmentDts=Math.min(e.minSegmentDts,t.dts),e.minSegmentPts=e.minSegmentDts,!0)})))},xt=function(t){var e,i,n=[];for(e=0;e=this.virtualRowCount&&"function"==typeof this.beforeRowOverflow&&this.beforeRowOverflow(t),this.rows.length>0&&(this.rows.push(""),this.rowIdx++);this.rows.length>this.virtualRowCount;)this.rows.shift(),this.rowIdx--},qt.prototype.isEmpty=function(){return 0===this.rows.length||1===this.rows.length&&""===this.rows[0]},qt.prototype.addText=function(t){this.rows[this.rowIdx]+=t},qt.prototype.backspace=function(){if(!this.isEmpty()){var t=this.rows[this.rowIdx];this.rows[this.rowIdx]=t.substr(0,t.length-1)}};var Ht=function(t){this.serviceNum=t,this.text="",this.currentWindow=new qt(-1),this.windows=[]};Ht.prototype.init=function(t,e){this.startPts=t;for(var i=0;i<8;i++)this.windows[i]=new qt(i),"function"==typeof e&&(this.windows[i].beforeRowOverflow=e)},Ht.prototype.setCurrentWindow=function(t){this.currentWindow=this.windows[t]};var Zt=function t(){t.prototype.init.call(this);var e=this;this.current708Packet=null,this.services={},this.push=function(t){3===t.type?(e.new708Packet(),e.add708Bytes(t)):(null===e.current708Packet&&e.new708Packet(),e.add708Bytes(t))}};Zt.prototype=new mt,Zt.prototype.new708Packet=function(){null!==this.current708Packet&&this.push708Packet(),this.current708Packet={data:[],ptsVals:[]}},Zt.prototype.add708Bytes=function(t){var e=t.ccData,i=e>>>8,n=255&e;this.current708Packet.ptsVals.push(t.pts),this.current708Packet.data.push(i),this.current708Packet.data.push(n)},Zt.prototype.push708Packet=function(){var t=this.current708Packet,e=t.data,i=null,n=null,a=0,s=e[a++];for(t.seq=s>>6,t.sizeCode=63&s;a>5)&&n>0&&(i=s=e[a++]),this.pushServiceBlock(i,a,n),n>0&&(a+=n-1)},Zt.prototype.pushServiceBlock=function(t,e,i){var n,a=e,s=this.current708Packet.data,r=this.services[t];for(r||(r=this.initService(t,a));a>5,s.rowLock=(16&n)>>4,s.columnLock=(8&n)>>3,s.priority=7&n,n=i[++t],s.relativePositioning=(128&n)>>7,s.anchorVertical=127&n,n=i[++t],s.anchorHorizontal=n,n=i[++t],s.anchorPoint=(240&n)>>4,s.rowCount=15&n,n=i[++t],s.columnCount=63&n,n=i[++t],s.windowStyle=(56&n)>>3,s.penStyle=7&n,s.virtualRowCount=s.rowCount+1,t},Zt.prototype.setWindowAttributes=function(t,e){var i=this.current708Packet.data,n=i[t],a=e.currentWindow.winAttr;return n=i[++t],a.fillOpacity=(192&n)>>6,a.fillRed=(48&n)>>4,a.fillGreen=(12&n)>>2,a.fillBlue=3&n,n=i[++t],a.borderType=(192&n)>>6,a.borderRed=(48&n)>>4,a.borderGreen=(12&n)>>2,a.borderBlue=3&n,n=i[++t],a.borderType+=(128&n)>>5,a.wordWrap=(64&n)>>6,a.printDirection=(48&n)>>4,a.scrollDirection=(12&n)>>2,a.justify=3&n,n=i[++t],a.effectSpeed=(240&n)>>4,a.effectDirection=(12&n)>>2,a.displayEffect=3&n,t},Zt.prototype.flushDisplayed=function(t,e){for(var i=[],n=0;n<8;n++)e.windows[n].visible&&!e.windows[n].isEmpty()&&i.push(e.windows[n].getText());e.endPts=t,e.text=i.join("\n\n"),this.pushCaption(e),e.startPts=t},Zt.prototype.pushCaption=function(t){""!==t.text&&(this.trigger("data",{startPts:t.startPts,endPts:t.endPts,text:t.text,stream:"cc708_"+t.serviceNum}),t.text="",t.startPts=t.endPts)},Zt.prototype.displayWindows=function(t,e){var i=this.current708Packet.data[++t],n=this.getPts(t);this.flushDisplayed(n,e);for(var a=0;a<8;a++)i&1<>4,a.offset=(12&n)>>2,a.penSize=3&n,n=i[++t],a.italics=(128&n)>>7,a.underline=(64&n)>>6,a.edgeType=(56&n)>>3,a.fontStyle=7&n,t},Zt.prototype.setPenColor=function(t,e){var i=this.current708Packet.data,n=i[t],a=e.currentWindow.penColor;return n=i[++t],a.fgOpacity=(192&n)>>6,a.fgRed=(48&n)>>4,a.fgGreen=(12&n)>>2,a.fgBlue=3&n,n=i[++t],a.bgOpacity=(192&n)>>6,a.bgRed=(48&n)>>4,a.bgGreen=(12&n)>>2,a.bgBlue=3&n,n=i[++t],a.edgeRed=(48&n)>>4,a.edgeGreen=(12&n)>>2,a.edgeBlue=3&n,t},Zt.prototype.setPenLocation=function(t,e){var i=this.current708Packet.data,n=i[t],a=e.currentWindow.penLoc;return e.currentWindow.pendingNewLine=!0,n=i[++t],a.row=15&n,n=i[++t],a.column=63&n,t},Zt.prototype.reset=function(t,e){var i=this.getPts(t);return this.flushDisplayed(i,e),this.initService(e.serviceNum,t)};var $t={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608,304:174,305:176,306:189,307:191,308:8482,309:162,310:163,311:9834,312:224,313:160,314:232,315:226,316:234,317:238,318:244,319:251,544:193,545:201,546:211,547:218,548:220,549:252,550:8216,551:161,552:42,553:39,554:8212,555:169,556:8480,557:8226,558:8220,559:8221,560:192,561:194,562:199,563:200,564:202,565:203,566:235,567:206,568:207,569:239,570:212,571:217,572:249,573:219,574:171,575:187,800:195,801:227,802:205,803:204,804:236,805:210,806:242,807:213,808:245,809:123,810:125,811:92,812:94,813:95,814:124,815:126,816:196,817:228,818:214,819:246,820:223,821:165,822:164,823:9474,824:197,825:229,826:216,827:248,828:9484,829:9488,830:9492,831:9496},Kt=function(t){return null===t?"":(t=$t[t]||t,String.fromCharCode(t))},Jt=[4352,4384,4608,4640,5376,5408,5632,5664,5888,5920,4096,4864,4896,5120,5152],Qt=function(){for(var t=[],e=15;e--;)t.push("");return t},te=function t(e,i){t.prototype.init.call(this),this.field_=e||0,this.dataChannel_=i||0,this.name_="CC"+(1+(this.field_<<1|this.dataChannel_)),this.setConstants(),this.reset(),this.push=function(t){var e,i,n,a,s;if((e=32639&t.ccData)!==this.lastControlCode_){if(4096==(61440&e)?this.lastControlCode_=e:e!==this.PADDING_&&(this.lastControlCode_=null),n=e>>>8,a=255&e,e!==this.PADDING_)if(e===this.RESUME_CAPTION_LOADING_)this.mode_="popOn";else if(e===this.END_OF_CAPTION_)this.mode_="popOn",this.clearFormatting(t.pts),this.flushDisplayed(t.pts),i=this.displayed_,this.displayed_=this.nonDisplayed_,this.nonDisplayed_=i,this.startPts_=t.pts;else if(e===this.ROLL_UP_2_ROWS_)this.rollUpRows_=2,this.setRollUp(t.pts);else if(e===this.ROLL_UP_3_ROWS_)this.rollUpRows_=3,this.setRollUp(t.pts);else if(e===this.ROLL_UP_4_ROWS_)this.rollUpRows_=4,this.setRollUp(t.pts);else if(e===this.CARRIAGE_RETURN_)this.clearFormatting(t.pts),this.flushDisplayed(t.pts),this.shiftRowsUp_(),this.startPts_=t.pts;else if(e===this.BACKSPACE_)"popOn"===this.mode_?this.nonDisplayed_[this.row_]=this.nonDisplayed_[this.row_].slice(0,-1):this.displayed_[this.row_]=this.displayed_[this.row_].slice(0,-1);else if(e===this.ERASE_DISPLAYED_MEMORY_)this.flushDisplayed(t.pts),this.displayed_=Qt();else if(e===this.ERASE_NON_DISPLAYED_MEMORY_)this.nonDisplayed_=Qt();else if(e===this.RESUME_DIRECT_CAPTIONING_)"paintOn"!==this.mode_&&(this.flushDisplayed(t.pts),this.displayed_=Qt()),this.mode_="paintOn",this.startPts_=t.pts;else if(this.isSpecialCharacter(n,a))s=Kt((n=(3&n)<<8)|a),this[this.mode_](t.pts,s),this.column_++;else if(this.isExtCharacter(n,a))"popOn"===this.mode_?this.nonDisplayed_[this.row_]=this.nonDisplayed_[this.row_].slice(0,-1):this.displayed_[this.row_]=this.displayed_[this.row_].slice(0,-1),s=Kt((n=(3&n)<<8)|a),this[this.mode_](t.pts,s),this.column_++;else if(this.isMidRowCode(n,a))this.clearFormatting(t.pts),this[this.mode_](t.pts," "),this.column_++,14==(14&a)&&this.addFormatting(t.pts,["i"]),1==(1&a)&&this.addFormatting(t.pts,["u"]);else if(this.isOffsetControlCode(n,a))this.column_+=3&a;else if(this.isPAC(n,a)){var r=Jt.indexOf(7968&e);"rollUp"===this.mode_&&(r-this.rollUpRows_+1<0&&(r=this.rollUpRows_-1),this.setRollUp(t.pts,r)),r!==this.row_&&(this.clearFormatting(t.pts),this.row_=r),1&a&&-1===this.formatting_.indexOf("u")&&this.addFormatting(t.pts,["u"]),16==(16&e)&&(this.column_=4*((14&e)>>1)),this.isColorPAC(a)&&14==(14&a)&&this.addFormatting(t.pts,["i"])}else this.isNormalChar(n)&&(0===a&&(a=null),s=Kt(n),s+=Kt(a),this[this.mode_](t.pts,s),this.column_+=s.length)}else this.lastControlCode_=null}};te.prototype=new mt,te.prototype.flushDisplayed=function(t){var e=this.displayed_.map((function(t,e){try{return t.trim()}catch(t){return this.trigger("log",{level:"warn",message:"Skipping a malformed 608 caption at index "+e+"."}),""}}),this).join("\n").replace(/^\n+|\n+$/g,"");e.length&&this.trigger("data",{startPts:this.startPts_,endPts:t,text:e,stream:this.name_})},te.prototype.reset=function(){this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=Qt(),this.nonDisplayed_=Qt(),this.lastControlCode_=null,this.column_=0,this.row_=14,this.rollUpRows_=2,this.formatting_=[]},te.prototype.setConstants=function(){0===this.dataChannel_?(this.BASE_=16,this.EXT_=17,this.CONTROL_=(20|this.field_)<<8,this.OFFSET_=23):1===this.dataChannel_&&(this.BASE_=24,this.EXT_=25,this.CONTROL_=(28|this.field_)<<8,this.OFFSET_=31),this.PADDING_=0,this.RESUME_CAPTION_LOADING_=32|this.CONTROL_,this.END_OF_CAPTION_=47|this.CONTROL_,this.ROLL_UP_2_ROWS_=37|this.CONTROL_,this.ROLL_UP_3_ROWS_=38|this.CONTROL_,this.ROLL_UP_4_ROWS_=39|this.CONTROL_,this.CARRIAGE_RETURN_=45|this.CONTROL_,this.RESUME_DIRECT_CAPTIONING_=41|this.CONTROL_,this.BACKSPACE_=33|this.CONTROL_,this.ERASE_DISPLAYED_MEMORY_=44|this.CONTROL_,this.ERASE_NON_DISPLAYED_MEMORY_=46|this.CONTROL_},te.prototype.isSpecialCharacter=function(t,e){return t===this.EXT_&&e>=48&&e<=63},te.prototype.isExtCharacter=function(t,e){return(t===this.EXT_+1||t===this.EXT_+2)&&e>=32&&e<=63},te.prototype.isMidRowCode=function(t,e){return t===this.EXT_&&e>=32&&e<=47},te.prototype.isOffsetControlCode=function(t,e){return t===this.OFFSET_&&e>=33&&e<=35},te.prototype.isPAC=function(t,e){return t>=this.BASE_&&t=64&&e<=127},te.prototype.isColorPAC=function(t){return t>=64&&t<=79||t>=96&&t<=127},te.prototype.isNormalChar=function(t){return t>=32&&t<=127},te.prototype.setRollUp=function(t,e){if("rollUp"!==this.mode_&&(this.row_=14,this.mode_="rollUp",this.flushDisplayed(t),this.nonDisplayed_=Qt(),this.displayed_=Qt()),void 0!==e&&e!==this.row_)for(var i=0;i"}),"");this[this.mode_](t,i)},te.prototype.clearFormatting=function(t){if(this.formatting_.length){var e=this.formatting_.reverse().reduce((function(t,e){return t+""}),"");this.formatting_=[],this[this.mode_](t,e)}},te.prototype.popOn=function(t,e){var i=this.nonDisplayed_[this.row_];i+=e,this.nonDisplayed_[this.row_]=i},te.prototype.rollUp=function(t,e){var i=this.displayed_[this.row_];i+=e,this.displayed_[this.row_]=i},te.prototype.shiftRowsUp_=function(){var t;for(t=0;te&&(i=-1);Math.abs(e-t)>4294967296;)t+=8589934592*i;return t},se=function t(e){var i,n;t.prototype.init.call(this),this.type_=e||ne,this.push=function(t){this.type_!==ne&&t.type!==this.type_||(void 0===n&&(n=t.dts),t.dts=ae(t.dts,n),t.pts=ae(t.pts,n),i=t.dts,this.trigger("data",t))},this.flush=function(){n=i,this.trigger("done")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline")},this.discontinuity=function(){n=void 0,i=void 0},this.reset=function(){this.discontinuity(),this.trigger("reset")}};se.prototype=new mt;var re,oe=se,de=function(t,e,i){var n,a="";for(n=e;n>>2;p*=4,p+=3&h[7],o.timeStamp=p,void 0===e.pts&&void 0===e.dts&&(e.pts=o.timeStamp,e.dts=o.timeStamp),this.trigger("timestamp",o)}e.frames.push(o),i+=10,i+=r}while(i>>4>1&&(n+=e[n]+1),0===i.pid)i.type="pat",t(e.subarray(n),i),this.trigger("data",i);else if(i.pid===this.pmtPid)for(i.type="pmt",t(e.subarray(n),i),this.trigger("data",i);this.packetsWaitingForPmt.length;)this.processPes_.apply(this,this.packetsWaitingForPmt.shift());else void 0===this.programMapTable?this.packetsWaitingForPmt.push([e,n,i]):this.processPes_(e,n,i)},this.processPes_=function(t,e,i){i.pid===this.programMapTable.video?i.streamType=ie.H264_STREAM_TYPE:i.pid===this.programMapTable.audio?i.streamType=ie.ADTS_STREAM_TYPE:i.streamType=this.programMapTable["timed-metadata"][i.pid],i.type="pes",i.data=t.subarray(e),this.trigger("data",i)}}).prototype=new mt,ce.STREAM_TYPES={h264:27,adts:15},(fe=function(){var t,e=this,i=!1,n={data:[],size:0},a={data:[],size:0},s={data:[],size:0},r=function(t,i,n){var a,s,r=new Uint8Array(t.size),o={type:i},d=0,h=0;if(t.data.length&&!(t.size<9)){for(o.trackId=t.data[0].pid,d=0;d>>3,l.pts*=4,l.pts+=(6&p[13])>>>1,l.dts=l.pts,64&u&&(l.dts=(14&p[14])<<27|(255&p[15])<<20|(254&p[16])<<12|(255&p[17])<<5|(254&p[18])>>>3,l.dts*=4,l.dts+=(6&p[18])>>>1)),l.data=p.subarray(9+p[8])),a="video"===i||o.packetLength<=t.size,(n||a)&&(t.size=0,t.data.length=0),a&&e.trigger("data",o)}};fe.prototype.init.call(this),this.push=function(o){({pat:function(){},pes:function(){var t,e;switch(o.streamType){case ie.H264_STREAM_TYPE:t=n,e="video";break;case ie.ADTS_STREAM_TYPE:t=a,e="audio";break;case ie.METADATA_STREAM_TYPE:t=s,e="timed-metadata";break;default:return}o.payloadUnitStartIndicator&&r(t,e,!0),t.data.push(o),t.size+=o.data.byteLength},pmt:function(){var n={type:"metadata",tracks:[]};null!==(t=o.programMapTable).video&&n.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.video,codec:"avc",type:"video"}),null!==t.audio&&n.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.audio,codec:"adts",type:"audio"}),i=!0,e.trigger("data",n)}})[o.type]()},this.reset=function(){n.size=0,n.data.length=0,a.size=0,a.data.length=0,this.trigger("reset")},this.flushStreams_=function(){r(n,"video"),r(a,"audio"),r(s,"timed-metadata")},this.flush=function(){if(!i&&t){var n={type:"metadata",tracks:[]};null!==t.video&&n.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.video,codec:"avc",type:"video"}),null!==t.audio&&n.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.audio,codec:"adts",type:"audio"}),e.trigger("data",n)}i=!1,this.flushStreams_(),this.trigger("done")}}).prototype=new mt;var Se={PAT_PID:0,MP2T_PACKET_LENGTH:ye,TransportPacketStream:ue,TransportParseStream:ce,ElementaryStream:fe,TimestampRolloverStream:ge,CaptionStream:ee.CaptionStream,Cea608Stream:ee.Cea608Stream,Cea708Stream:ee.Cea708Stream,MetadataStream:me};for(var ve in ie)ie.hasOwnProperty(ve)&&(Se[ve]=ie[ve]);var _e,be=Se,we=At,Te=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];(_e=function(t){var e,i=0;_e.prototype.init.call(this),this.skipWarn_=function(t,e){this.trigger("log",{level:"warn",message:"adts skiping bytes "+t+" to "+e+" in frame "+i+" outside syncword"})},this.push=function(n){var a,s,r,o,d,h=0;if(t||(i=0),"audio"===n.type){var p;for(e&&e.length?(r=e,(e=new Uint8Array(r.byteLength+n.data.byteLength)).set(r),e.set(n.data,r.byteLength)):e=n.data;h+7>5,d=(o=1024*(1+(3&e[h+6])))*we/Te[(60&e[h+2])>>>2],e.byteLength-h>>6&3),channelcount:(1&e[h+2])<<2|(192&e[h+3])>>>6,samplerate:Te[(60&e[h+2])>>>2],samplingfrequencyindex:(60&e[h+2])>>>2,samplesize:16,data:e.subarray(h+7+s,h+a)}),i++,h+=a}else"number"!=typeof p&&(p=h),h++;"number"==typeof p&&(this.skipWarn_(p,h),p=null),e=e.subarray(h)}},this.flush=function(){i=0,this.trigger("done")},this.reset=function(){e=void 0,this.trigger("reset")},this.endTimeline=function(){e=void 0,this.trigger("endedtimeline")}}).prototype=new mt;var ke,Ce,Pe,Ae=_e,De=function(t){var e=t.byteLength,i=0,n=0;this.length=function(){return 8*e},this.bitsAvailable=function(){return 8*e+n},this.loadWord=function(){var a=t.byteLength-e,s=new Uint8Array(4),r=Math.min(4,e);if(0===r)throw new Error("no bytes available");s.set(t.subarray(a,a+r)),i=new DataView(s.buffer).getUint32(0),n=8*r,e-=r},this.skipBits=function(t){var a;n>t?(i<<=t,n-=t):(t-=n,t-=8*(a=Math.floor(t/8)),e-=a,this.loadWord(),i<<=t,n-=t)},this.readBits=function(t){var a=Math.min(n,t),s=i>>>32-a;return(n-=a)>0?i<<=a:e>0&&this.loadWord(),(a=t-a)>0?s<>>t))return i<<=t,n-=t,t;return this.loadWord(),t+this.skipLeadingZeros()},this.skipUnsignedExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.skipExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.readUnsignedExpGolomb=function(){var t=this.skipLeadingZeros();return this.readBits(t+1)-1},this.readExpGolomb=function(){var t=this.readUnsignedExpGolomb();return 1&t?1+t>>>1:-1*(t>>>1)},this.readBoolean=function(){return 1===this.readBits(1)},this.readUnsignedByte=function(){return this.readBits(8)},this.loadWord()};(Ce=function(){var t,e,i=0;Ce.prototype.init.call(this),this.push=function(n){var a;e?((a=new Uint8Array(e.byteLength+n.data.byteLength)).set(e),a.set(n.data,e.byteLength),e=a):e=n.data;for(var s=e.byteLength;i3&&this.trigger("data",e.subarray(i+3)),e=null,i=0,this.trigger("done")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline")}}).prototype=new mt,Pe={100:!0,110:!0,122:!0,244:!0,44:!0,83:!0,86:!0,118:!0,128:!0,138:!0,139:!0,134:!0},(ke=function(){var t,e,i,n,a,s,r,o=new Ce;ke.prototype.init.call(this),t=this,this.push=function(t){"video"===t.type&&(e=t.trackId,i=t.pts,n=t.dts,o.push(t))},o.on("data",(function(r){var o={trackId:e,pts:i,dts:n,data:r,nalUnitTypeCode:31&r[0]};switch(o.nalUnitTypeCode){case 5:o.nalUnitType="slice_layer_without_partitioning_rbsp_idr";break;case 6:o.nalUnitType="sei_rbsp",o.escapedRBSP=a(r.subarray(1));break;case 7:o.nalUnitType="seq_parameter_set_rbsp",o.escapedRBSP=a(r.subarray(1)),o.config=s(o.escapedRBSP);break;case 8:o.nalUnitType="pic_parameter_set_rbsp";break;case 9:o.nalUnitType="access_unit_delimiter_rbsp"}t.trigger("data",o)})),o.on("done",(function(){t.trigger("done")})),o.on("partialdone",(function(){t.trigger("partialdone")})),o.on("reset",(function(){t.trigger("reset")})),o.on("endedtimeline",(function(){t.trigger("endedtimeline")})),this.flush=function(){o.flush()},this.partialFlush=function(){o.partialFlush()},this.reset=function(){o.reset()},this.endTimeline=function(){o.endTimeline()},r=function(t,e){var i,n=8,a=8;for(i=0;i=0?i:0,(16&t[e+5])>>4?i+20:i+10},Oe=function t(e,i){return e.length-i<10||e[i]!=="I".charCodeAt(0)||e[i+1]!=="D".charCodeAt(0)||e[i+2]!=="3".charCodeAt(0)?i:t(e,i+=Ee(e,i))},xe=function(t){var e=Oe(t,0);return t.length>=e+2&&255==(255&t[e])&&240==(240&t[e+1])&&16==(22&t[e+1])},Re=Ee,Me=function(t,e){var i=(224&t[e+5])>>5,n=t[e+4]<<3;return 6144&t[e+3]|n|i};(Ue=function(){var t=new Uint8Array,e=0;Ue.prototype.init.call(this),this.setTimestamp=function(t){e=t},this.push=function(i){var n,a,s,r,o=0,d=0;for(t.length?(r=t.length,(t=new Uint8Array(i.byteLength+r)).set(t.subarray(0,r)),t.set(i,r)):t=i;t.length-d>=3;)if(t[d]!=="I".charCodeAt(0)||t[d+1]!=="D".charCodeAt(0)||t[d+2]!=="3".charCodeAt(0))if(255!=(255&t[d])||240!=(240&t[d+1]))d++;else{if(t.length-d<7)break;if(d+(o=Me(t,d))>t.length)break;s={type:"audio",data:t.subarray(d,d+o),pts:e,dts:e},this.trigger("data",s),d+=o}else{if(t.length-d<10)break;if(d+(o=Re(t,d))>t.length)break;a={type:"timed-metadata",data:t.subarray(d,d+o)},this.trigger("data",a),d+=o}n=t.length-d,t=n>0?t.subarray(d):new Uint8Array},this.reset=function(){t=new Uint8Array,this.trigger("reset")},this.endTimeline=function(){t=new Uint8Array,this.trigger("endedtimeline")}}).prototype=new mt;var Ie,Ne,Be,We,Ge=Ue,ze=["audioobjecttype","channelcount","samplerate","samplingfrequencyindex","samplesize"],Fe=["width","height","profileIdc","levelIdc","profileCompatibility","sarRatio"],Ve=Le.H264Stream,Ye=xe,je=At,Xe=function(t,e){var i;if(t.length!==e.length)return!1;for(i=0;i=-1e4&&i<=45e3&&(!n||o>i)&&(n=s,o=i));return n?n.gop:null},this.alignGopsAtStart_=function(t){var e,i,n,a,s,o,d,h;for(s=t.byteLength,o=t.nalCount,d=t.duration,e=i=0;en.pts?e++:(i++,s-=a.byteLength,o-=a.nalCount,d-=a.duration);return 0===i?t:i===t.length?null:((h=t.slice(i)).byteLength=s,h.duration=d,h.nalCount=o,h.pts=h[0].pts,h.dts=h[0].dts,h)},this.alignGopsAtEnd_=function(t){var e,i,n,a,s,o,d;for(e=r.length-1,i=t.length-1,s=null,o=!1;e>=0&&i>=0;){if(n=r[e],a=t[i],n.pts===a.pts){o=!0;break}n.pts>a.pts?e--:(e===r.length-1&&(s=i),i--)}if(!o&&null===s)return null;if(0===(d=o?i:s))return t;var h=t.slice(d),p=h.reduce((function(t,e){return t.byteLength+=e.byteLength,t.duration+=e.duration,t.nalCount+=e.nalCount,t}),{byteLength:0,duration:0,nalCount:0});return h.byteLength=p.byteLength,h.duration=p.duration,h.nalCount=p.nalCount,h.pts=h[0].pts,h.dts=h[0].dts,h},this.alignGopsWith=function(t){r=t}}).prototype=new mt,(We=function(t,e){this.numberOfTracks=0,this.metadataStream=e,void 0!==(t=t||{}).remux?this.remuxTracks=!!t.remux:this.remuxTracks=!0,"boolean"==typeof t.keepOriginalTimestamps?this.keepOriginalTimestamps=t.keepOriginalTimestamps:this.keepOriginalTimestamps=!1,this.pendingTracks=[],this.videoTrack=null,this.pendingBoxes=[],this.pendingCaptions=[],this.pendingMetadata=[],this.pendingBytes=0,this.emittedTracks=0,We.prototype.init.call(this),this.push=function(t){return t.text?this.pendingCaptions.push(t):t.frames?this.pendingMetadata.push(t):(this.pendingTracks.push(t.track),this.pendingBytes+=t.boxes.byteLength,"video"===t.track.type&&(this.videoTrack=t.track,this.pendingBoxes.push(t.boxes)),void("audio"===t.track.type&&(this.audioTrack=t.track,this.pendingBoxes.unshift(t.boxes))))}}).prototype=new mt,We.prototype.flush=function(t){var e,i,n,a,s=0,r={captions:[],captionStreams:{},metadata:[],info:{}},o=0;if(this.pendingTracks.length=this.numberOfTracks&&(this.trigger("done"),this.emittedTracks=0))}if(this.videoTrack?(o=this.videoTrack.timelineStartInfo.pts,Fe.forEach((function(t){r.info[t]=this.videoTrack[t]}),this)):this.audioTrack&&(o=this.audioTrack.timelineStartInfo.pts,ze.forEach((function(t){r.info[t]=this.audioTrack[t]}),this)),this.videoTrack||this.audioTrack){for(1===this.pendingTracks.length?r.type=this.pendingTracks[0].type:r.type="combined",this.emittedTracks+=this.pendingTracks.length,n=q.initSegment(this.pendingTracks),r.initSegment=new Uint8Array(n.byteLength),r.initSegment.set(n),r.data=new Uint8Array(this.pendingBytes),a=0;a=this.numberOfTracks&&(this.trigger("done"),this.emittedTracks=0)},We.prototype.setRemux=function(t){this.remuxTracks=t},(Be=function(t){var e,i,n=this,a=!0;Be.prototype.init.call(this),t=t||{},this.baseMediaDecodeTime=t.baseMediaDecodeTime||0,this.transmuxPipeline_={},this.setupAacPipeline=function(){var a={};this.transmuxPipeline_=a,a.type="aac",a.metadataStream=new be.MetadataStream,a.aacStream=new Ge,a.audioTimestampRolloverStream=new be.TimestampRolloverStream("audio"),a.timedMetadataTimestampRolloverStream=new be.TimestampRolloverStream("timed-metadata"),a.adtsStream=new Ae,a.coalesceStream=new We(t,a.metadataStream),a.headOfPipeline=a.aacStream,a.aacStream.pipe(a.audioTimestampRolloverStream).pipe(a.adtsStream),a.aacStream.pipe(a.timedMetadataTimestampRolloverStream).pipe(a.metadataStream).pipe(a.coalesceStream),a.metadataStream.on("timestamp",(function(t){a.aacStream.setTimestamp(t.timeStamp)})),a.aacStream.on("data",(function(s){"timed-metadata"!==s.type&&"audio"!==s.type||a.audioSegmentStream||(i=i||{timelineStartInfo:{baseMediaDecodeTime:n.baseMediaDecodeTime},codec:"adts",type:"audio"},a.coalesceStream.numberOfTracks++,a.audioSegmentStream=new Ne(i,t),a.audioSegmentStream.on("log",n.getLogTrigger_("audioSegmentStream")),a.audioSegmentStream.on("timingInfo",n.trigger.bind(n,"audioTimingInfo")),a.adtsStream.pipe(a.audioSegmentStream).pipe(a.coalesceStream),n.trigger("trackinfo",{hasAudio:!!i,hasVideo:!!e}))})),a.coalesceStream.on("data",this.trigger.bind(this,"data")),a.coalesceStream.on("done",this.trigger.bind(this,"done"))},this.setupTsPipeline=function(){var a={};this.transmuxPipeline_=a,a.type="ts",a.metadataStream=new be.MetadataStream,a.packetStream=new be.TransportPacketStream,a.parseStream=new be.TransportParseStream,a.elementaryStream=new be.ElementaryStream,a.timestampRolloverStream=new be.TimestampRolloverStream,a.adtsStream=new Ae,a.h264Stream=new Ve,a.captionStream=new be.CaptionStream(t),a.coalesceStream=new We(t,a.metadataStream),a.headOfPipeline=a.packetStream,a.packetStream.pipe(a.parseStream).pipe(a.elementaryStream).pipe(a.timestampRolloverStream),a.timestampRolloverStream.pipe(a.h264Stream),a.timestampRolloverStream.pipe(a.adtsStream),a.timestampRolloverStream.pipe(a.metadataStream).pipe(a.coalesceStream),a.h264Stream.pipe(a.captionStream).pipe(a.coalesceStream),a.elementaryStream.on("data",(function(s){var r;if("metadata"===s.type){for(r=s.tracks.length;r--;)e||"video"!==s.tracks[r].type?i||"audio"!==s.tracks[r].type||((i=s.tracks[r]).timelineStartInfo.baseMediaDecodeTime=n.baseMediaDecodeTime):(e=s.tracks[r]).timelineStartInfo.baseMediaDecodeTime=n.baseMediaDecodeTime;e&&!a.videoSegmentStream&&(a.coalesceStream.numberOfTracks++,a.videoSegmentStream=new Ie(e,t),a.videoSegmentStream.on("log",n.getLogTrigger_("videoSegmentStream")),a.videoSegmentStream.on("timelineStartInfo",(function(e){i&&!t.keepOriginalTimestamps&&(i.timelineStartInfo=e,a.audioSegmentStream.setEarliestDts(e.dts-n.baseMediaDecodeTime))})),a.videoSegmentStream.on("processedGopsInfo",n.trigger.bind(n,"gopInfo")),a.videoSegmentStream.on("segmentTimingInfo",n.trigger.bind(n,"videoSegmentTimingInfo")),a.videoSegmentStream.on("baseMediaDecodeTime",(function(t){i&&a.audioSegmentStream.setVideoBaseMediaDecodeTime(t)})),a.videoSegmentStream.on("timingInfo",n.trigger.bind(n,"videoTimingInfo")),a.h264Stream.pipe(a.videoSegmentStream).pipe(a.coalesceStream)),i&&!a.audioSegmentStream&&(a.coalesceStream.numberOfTracks++,a.audioSegmentStream=new Ne(i,t),a.audioSegmentStream.on("log",n.getLogTrigger_("audioSegmentStream")),a.audioSegmentStream.on("timingInfo",n.trigger.bind(n,"audioTimingInfo")),a.audioSegmentStream.on("segmentTimingInfo",n.trigger.bind(n,"audioSegmentTimingInfo")),a.adtsStream.pipe(a.audioSegmentStream).pipe(a.coalesceStream)),n.trigger("trackinfo",{hasAudio:!!i,hasVideo:!!e})}})),a.coalesceStream.on("data",this.trigger.bind(this,"data")),a.coalesceStream.on("id3Frame",(function(t){t.dispatchType=a.metadataStream.dispatchType,n.trigger("id3Frame",t)})),a.coalesceStream.on("caption",this.trigger.bind(this,"caption")),a.coalesceStream.on("done",this.trigger.bind(this,"done"))},this.setBaseMediaDecodeTime=function(n){var a=this.transmuxPipeline_;t.keepOriginalTimestamps||(this.baseMediaDecodeTime=n),i&&(i.timelineStartInfo.dts=void 0,i.timelineStartInfo.pts=void 0,It(i),a.audioTimestampRolloverStream&&a.audioTimestampRolloverStream.discontinuity()),e&&(a.videoSegmentStream&&(a.videoSegmentStream.gopCache_=[]),e.timelineStartInfo.dts=void 0,e.timelineStartInfo.pts=void 0,It(e),a.captionStream.reset()),a.timestampRolloverStream&&a.timestampRolloverStream.discontinuity()},this.setAudioAppendStart=function(t){i&&this.transmuxPipeline_.audioSegmentStream.setAudioAppendStart(t)},this.setRemux=function(e){var i=this.transmuxPipeline_;t.remux=e,i&&i.coalesceStream&&i.coalesceStream.setRemux(e)},this.alignGopsWith=function(t){e&&this.transmuxPipeline_.videoSegmentStream&&this.transmuxPipeline_.videoSegmentStream.alignGopsWith(t)},this.getLogTrigger_=function(t){var e=this;return function(i){i.stream=t,e.trigger("log",i)}},this.push=function(t){if(a){var e=Ye(t);if(e&&"aac"!==this.transmuxPipeline_.type?this.setupAacPipeline():e||"ts"===this.transmuxPipeline_.type||this.setupTsPipeline(),this.transmuxPipeline_)for(var i=Object.keys(this.transmuxPipeline_),n=0;n0?it(h[0]).baseMediaDecodeTime:0,l=K(s,["trun"]);e===d&&l.length>0&&(i=function(t,e,i){var n,a,s,r,o=new DataView(t.buffer,t.byteOffset,t.byteLength),d={logs:[],seiNals:[]};for(a=0;a+40;){var d=e.shift();this.parse(d,s,r)}return(o=function(t,e,i){if(null===e)return null;var n=Je(t,e)[e]||{};return{seiNals:n.seiNals,logs:n.logs,timescale:i}}(t,i,n))&&o.logs&&(a.logs=a.logs.concat(o.logs)),null!==o&&o.seiNals?(this.pushNals(o.seiNals),this.flushStream(),a):a.logs.length?{logs:a.logs,captions:[],captionStreams:[]}:null},this.pushNals=function(e){if(!this.isInitialized()||!e||0===e.length)return null;e.forEach((function(e){t.push(e)}))},this.flushStream=function(){if(!this.isInitialized())return null;s?t.partialFlush():t.flush()},this.clearParsedCaptions=function(){a.captions=[],a.captionStreams={},a.logs=[]},this.resetCaptionStream=function(){if(!this.isInitialized())return null;t.reset()},this.clearAllCaptions=function(){this.clearParsedCaptions(),this.resetCaptionStream()},this.reset=function(){e=[],i=null,n=null,a?this.clearParsedCaptions():a={captions:[],captionStreams:{},logs:[]},this.resetCaptionStream()},this.reset()}}}));