r++)i&1<>4 r.offset=(12&n)>>2 r.penSize=3&n n=i[++e] r.italics=(128&n)>>7 r.underline=(64&n)>>6 r.edgeType=(56&n)>>3 r.fontStyle=7&n return e} De.prototype.setPenColor=function(e,t){var i=this.current708Packet.data,n=i[e],r=t.currentWindow.penColor n=i[++e] r.fgOpacity=(192&n)>>6 r.fgRed=(48&n)>>4 r.fgGreen=(12&n)>>2 r.fgBlue=3&n n=i[++e] r.bgOpacity=(192&n)>>6 r.bgRed=(48&n)>>4 r.bgGreen=(12&n)>>2 r.bgBlue=3&n n=i[++e] r.edgeRed=(48&n)>>4 r.edgeGreen=(12&n)>>2 r.edgeBlue=3&n return e} De.prototype.setPenLocation=function(e,t){var i=this.current708Packet.data,n=i[e],r=t.currentWindow.penLoc t.currentWindow.pendingNewLine=!0 n=i[++e] r.row=15&n n=i[++e] r.column=63&n return e} De.prototype.reset=function(e,t){var i=this.getPts(e) this.flushDisplayed(i,t) return this.initService(t.serviceNum,e)} var Re={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},Me=function(e){if(null===e)return"" e=Re[e]||e return String.fromCharCode(e)},Ne=[4352,4384,4608,4640,5376,5408,5632,5664,5888,5920,4096,4864,4896,5120,5152],Ue=function(){for(var e=[],t=15;t--;)e.push("") return e},Be=function e(t,i){e.prototype.init.call(this) this.field_=t||0 this.dataChannel_=i||0 this.name_="CC"+(1+(this.field_<<1|this.dataChannel_)) this.setConstants() this.reset() this.push=function(e){var t,i,n,r,a if((t=32639&e.ccData)!==this.lastControlCode_){4096==(61440&t)?this.lastControlCode_=t:t!==this.PADDING_&&(this.lastControlCode_=null) n=t>>>8 r=255&t if(t!==this.PADDING_)if(t===this.RESUME_CAPTION_LOADING_)this.mode_="popOn" else if(t===this.END_OF_CAPTION_){this.mode_="popOn" this.clearFormatting(e.pts) this.flushDisplayed(e.pts) i=this.displayed_ this.displayed_=this.nonDisplayed_ this.nonDisplayed_=i this.startPts_=e.pts}else if(t===this.ROLL_UP_2_ROWS_){this.rollUpRows_=2 this.setRollUp(e.pts)}else if(t===this.ROLL_UP_3_ROWS_){this.rollUpRows_=3 this.setRollUp(e.pts)}else if(t===this.ROLL_UP_4_ROWS_){this.rollUpRows_=4 this.setRollUp(e.pts)}else if(t===this.CARRIAGE_RETURN_){this.clearFormatting(e.pts) this.flushDisplayed(e.pts) this.shiftRowsUp_() this.startPts_=e.pts}else if(t===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(t===this.ERASE_DISPLAYED_MEMORY_){this.flushDisplayed(e.pts) this.displayed_=Ue()}else if(t===this.ERASE_NON_DISPLAYED_MEMORY_)this.nonDisplayed_=Ue() else if(t===this.RESUME_DIRECT_CAPTIONING_){if("paintOn"!==this.mode_){this.flushDisplayed(e.pts) this.displayed_=Ue()}this.mode_="paintOn" this.startPts_=e.pts}else if(this.isSpecialCharacter(n,r)){a=Me((n=(3&n)<<8)|r) this[this.mode_](e.pts,a) this.column_++}else if(this.isExtCharacter(n,r)){"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) a=Me((n=(3&n)<<8)|r) this[this.mode_](e.pts,a) this.column_++}else if(this.isMidRowCode(n,r)){this.clearFormatting(e.pts) this[this.mode_](e.pts," ") this.column_++ 14&~r||this.addFormatting(e.pts,["i"]) 1&~r||this.addFormatting(e.pts,["u"])}else if(this.isOffsetControlCode(n,r))this.column_+=3&r else if(this.isPAC(n,r)){var s=Ne.indexOf(7968&t) if("rollUp"===this.mode_){s-this.rollUpRows_+1<0&&(s=this.rollUpRows_-1) this.setRollUp(e.pts,s)}if(s!==this.row_){this.clearFormatting(e.pts) this.row_=s}1&r&&-1===this.formatting_.indexOf("u")&&this.addFormatting(e.pts,["u"]) 16&~t||(this.column_=4*((14&t)>>1)) this.isColorPAC(r)&&(14&~r||this.addFormatting(e.pts,["i"]))}else if(this.isNormalChar(n)){0===r&&(r=null) a=Me(n) a+=Me(r) this[this.mode_](e.pts,a) this.column_+=a.length}}else this.lastControlCode_=null}} Be.prototype=new U Be.prototype.flushDisplayed=function(e){var t=this.displayed_.map((function(e,t){try{return e.trim()}catch(e){this.trigger("log",{level:"warn",message:"Skipping a malformed 608 caption at index "+t+"."}) return""}}),this).join("\n").replace(/^\n+|\n+$/g,"") t.length&&this.trigger("data",{startPts:this.startPts_,endPts:e,text:t,stream:this.name_})} Be.prototype.reset=function(){this.mode_="popOn" this.topRow_=0 this.startPts_=0 this.displayed_=Ue() this.nonDisplayed_=Ue() this.lastControlCode_=null this.column_=0 this.row_=14 this.rollUpRows_=2 this.formatting_=[]} Be.prototype.setConstants=function(){if(0===this.dataChannel_){this.BASE_=16 this.EXT_=17 this.CONTROL_=(20|this.field_)<<8 this.OFFSET_=23}else if(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_} Be.prototype.isSpecialCharacter=function(e,t){return e===this.EXT_&&t>=48&&t<=63} Be.prototype.isExtCharacter=function(e,t){return(e===this.EXT_+1||e===this.EXT_+2)&&t>=32&&t<=63} Be.prototype.isMidRowCode=function(e,t){return e===this.EXT_&&t>=32&&t<=47} Be.prototype.isOffsetControlCode=function(e,t){return e===this.OFFSET_&&t>=33&&t<=35} Be.prototype.isPAC=function(e,t){return e>=this.BASE_&&e=64&&t<=127} Be.prototype.isColorPAC=function(e){return e>=64&&e<=79||e>=96&&e<=127} Be.prototype.isNormalChar=function(e){return e>=32&&e<=127} Be.prototype.setRollUp=function(e,t){if("rollUp"!==this.mode_){this.row_=14 this.mode_="rollUp" this.flushDisplayed(e) this.nonDisplayed_=Ue() this.displayed_=Ue()}if(void 0!==t&&t!==this.row_)for(var i=0;i"}),"") this[this.mode_](e,i)} Be.prototype.clearFormatting=function(e){if(this.formatting_.length){var t=this.formatting_.reverse().reduce((function(e,t){return e+""}),"") this.formatting_=[] this[this.mode_](e,t)}} Be.prototype.popOn=function(e,t){var i=this.nonDisplayed_[this.row_] i+=t this.nonDisplayed_[this.row_]=i} Be.prototype.rollUp=function(e,t){var i=this.displayed_[this.row_] i+=t this.displayed_[this.row_]=i} Be.prototype.shiftRowsUp_=function(){var e for(e=0;et&&(i=-1) for(;Math.abs(t-e)>4294967296;)e+=8589934592*i return e},qe=function e(t){var i,n e.prototype.init.call(this) this.type_=t||Ve this.push=function(e){if(this.type_===Ve||e.type===this.type_){void 0===n&&(n=e.dts) e.dts=He(e.dts,n) e.pts=He(e.pts,n) i=e.dts this.trigger("data",e)}} 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")}} qe.prototype=new U var We,Ge=qe,ze=He,Ke=function(e,t,i){var n,r="" for(n=t;n>>2 c*=4 c+=3&l[7] o.timeStamp=c if(void 0===t.pts&&void 0===t.dts){t.pts=o.timeStamp t.dts=o.timeStamp}this.trigger("timestamp",o)}}t.frames.push(o) i+=10 i+=s}while(i>>4>1&&(n+=t[n]+1) if(0===i.pid){i.type="pat" e(t.subarray(n),i) this.trigger("data",i)}else if(i.pid===this.pmtPid){i.type="pmt" e(t.subarray(n),i) this.trigger("data",i) for(;this.packetsWaitingForPmt.length;)this.processPes_.apply(this,this.packetsWaitingForPmt.shift())}else void 0===this.programMapTable?this.packetsWaitingForPmt.push([t,n,i]):this.processPes_(t,n,i)} this.processPes_=function(e,t,i){i.pid===this.programMapTable.video?i.streamType=je.H264_STREAM_TYPE:i.pid===this.programMapTable.audio?i.streamType=je.ADTS_STREAM_TYPE:i.streamType=this.programMapTable["timed-metadata"][i.pid] i.type="pes" i.data=e.subarray(t) this.trigger("data",i)}} Je.prototype=new U Je.STREAM_TYPES={h264:27,adts:15} Ze=function(){var e,t=this,i=!1,n={data:[],size:0},r={data:[],size:0},a={data:[],size:0},s=function(e,i,n){var r,a,s=new Uint8Array(e.size),o={type:i},u=0,l=0 if(e.data.length&&!(e.size<9)){o.trackId=e.data[0].pid for(u=0;u>>3 t.pts*=4 t.pts+=(6&e[13])>>>1 t.dts=t.pts if(64&i){t.dts=(14&e[14])<<27|(255&e[15])<<20|(254&e[16])<<12|(255&e[17])<<5|(254&e[18])>>>3 t.dts*=4 t.dts+=(6&e[18])>>>1}}t.data=e.subarray(9+e[8])}}(s,o) r="video"===i||o.packetLength<=e.size if(n||r){e.size=0 e.data.length=0}r&&t.trigger("data",o)}} Ze.prototype.init.call(this) this.push=function(o){({pat:function(){},pes:function(){var e,t switch(o.streamType){case je.H264_STREAM_TYPE:e=n t="video" break case je.ADTS_STREAM_TYPE:e=r t="audio" break case je.METADATA_STREAM_TYPE:e=a t="timed-metadata" break default:return}o.payloadUnitStartIndicator&&s(e,t,!0) e.data.push(o) e.size+=o.data.byteLength},pmt:function(){var n={type:"metadata",tracks:[]} null!==(e=o.programMapTable).video&&n.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+e.video,codec:"avc",type:"video"}) null!==e.audio&&n.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+e.audio,codec:"adts",type:"audio"}) i=!0 t.trigger("data",n)}})[o.type]()} this.reset=function(){n.size=0 n.data.length=0 r.size=0 r.data.length=0 this.trigger("reset")} this.flushStreams_=function(){s(n,"video") s(r,"audio") s(a,"timed-metadata")} this.flush=function(){if(!i&&e){var n={type:"metadata",tracks:[]} null!==e.video&&n.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+e.video,codec:"avc",type:"video"}) null!==e.audio&&n.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+e.audio,codec:"adts",type:"audio"}) t.trigger("data",n)}i=!1 this.flushStreams_() this.trigger("done")}} Ze.prototype=new U var nt={PAT_PID:0,MP2T_PACKET_LENGTH:it,TransportPacketStream:$e,TransportParseStream:Je,ElementaryStream:Ze,TimestampRolloverStream:tt,CaptionStream:Fe.CaptionStream,Cea608Stream:Fe.Cea608Stream,Cea708Stream:Fe.Cea708Stream,MetadataStream:et} for(var rt in je)je.hasOwnProperty(rt)&&(nt[rt]=je[rt]) var at,st=nt,ot=le,ut=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350] at=function(e){var t,i=0 at.prototype.init.call(this) this.skipWarn_=function(e,t){this.trigger("log",{level:"warn",message:"adts skiping bytes "+e+" to "+t+" in frame "+i+" outside syncword"})} this.push=function(n){var r,a,s,o,u,l=0 e||(i=0) if("audio"===n.type){if(t&&t.length){s=t;(t=new Uint8Array(s.byteLength+n.data.byteLength)).set(s) t.set(n.data,s.byteLength)}else t=n.data for(var c;l+7>5 u=(o=1024*(1+(3&t[l+6])))*ot/ut[(60&t[l+2])>>>2] if(t.byteLength-l>>6&3),channelcount:(1&t[l+2])<<2|(192&t[l+3])>>>6,samplerate:ut[(60&t[l+2])>>>2],samplingfrequencyindex:(60&t[l+2])>>>2,samplesize:16,data:t.subarray(l+7+a,l+r)}) i++ l+=r}else{"number"!=typeof c&&(c=l) l++}if("number"==typeof c){this.skipWarn_(c,l) c=null}t=t.subarray(l)}} this.flush=function(){i=0 this.trigger("done")} this.reset=function(){t=void 0 this.trigger("reset")} this.endTimeline=function(){t=void 0 this.trigger("endedtimeline")}} at.prototype=new U var lt,ct=at lt=function(e){var t=e.byteLength,i=0,n=0 this.length=function(){return 8*t} this.bitsAvailable=function(){return 8*t+n} this.loadWord=function(){var r=e.byteLength-t,a=new Uint8Array(4),s=Math.min(4,t) if(0===s)throw new Error("no bytes available") a.set(e.subarray(r,r+s)) i=new DataView(a.buffer).getUint32(0) n=8*s t-=s} this.skipBits=function(e){var r if(n>e){i<<=e n-=e}else{e-=n e-=8*(r=Math.floor(e/8)) t-=r this.loadWord() i<<=e n-=e}} this.readBits=function(e){var r=Math.min(n,e),a=i>>>32-r;(n-=r)>0?i<<=r:t>0&&this.loadWord() return(r=e-r)>0?a<>>e){i<<=e n-=e return e}this.loadWord() return e+this.skipLeadingZeros()} this.skipUnsignedExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())} this.skipExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())} this.readUnsignedExpGolomb=function(){var e=this.skipLeadingZeros() return this.readBits(e+1)-1} this.readExpGolomb=function(){var e=this.readUnsignedExpGolomb() return 1&e?1+e>>>1:-1*(e>>>1)} this.readBoolean=function(){return 1===this.readBits(1)} this.readUnsignedByte=function(){return this.readBits(8)} this.loadWord()} var dt,ht,pt,ft=lt ht=function(){var e,t,i=0 ht.prototype.init.call(this) this.push=function(n){var r if(t){(r=new Uint8Array(t.byteLength+n.data.byteLength)).set(t) r.set(n.data,t.byteLength) t=r}else t=n.data for(var a=t.byteLength;i3&&this.trigger("data",t.subarray(i+3)) t=null i=0 this.trigger("done")} this.endTimeline=function(){this.flush() this.trigger("endedtimeline")}} ht.prototype=new U pt={100:!0,110:!0,122:!0,244:!0,44:!0,83:!0,86:!0,118:!0,128:!0,138:!0,139:!0,134:!0} dt=function(){var e,t,i,n,r,a,s,o=new ht dt.prototype.init.call(this) e=this this.push=function(e){if("video"===e.type){t=e.trackId i=e.pts n=e.dts o.push(e)}} o.on("data",(function(s){var o={trackId:t,pts:i,dts:n,data:s,nalUnitTypeCode:31&s[0]} switch(o.nalUnitTypeCode){case 5:o.nalUnitType="slice_layer_without_partitioning_rbsp_idr" break case 6:o.nalUnitType="sei_rbsp" o.escapedRBSP=r(s.subarray(1)) break case 7:o.nalUnitType="seq_parameter_set_rbsp" o.escapedRBSP=r(s.subarray(1)) o.config=a(o.escapedRBSP) break case 8:o.nalUnitType="pic_parameter_set_rbsp" break case 9:o.nalUnitType="access_unit_delimiter_rbsp"}e.trigger("data",o)})) o.on("done",(function(){e.trigger("done")})) o.on("partialdone",(function(){e.trigger("partialdone")})) o.on("reset",(function(){e.trigger("reset")})) o.on("endedtimeline",(function(){e.trigger("endedtimeline")})) this.flush=function(){o.flush()} this.partialFlush=function(){o.partialFlush()} this.reset=function(){o.reset()} this.endTimeline=function(){o.endTimeline()} s=function(e,t){var i,n=8,r=8 for(i=0;i=0?i:0 return(16&e[t+5])>>4?i+20:i+10},_t=function e(t,i){return t.length-i<10||t[i]!=="I".charCodeAt(0)||t[i+1]!=="D".charCodeAt(0)||t[i+2]!=="3".charCodeAt(0)?i:e(t,i+=yt(t,i))},bt=function(e){return e[0]<<21|e[1]<<14|e[2]<<7|e[3]},Tt={isLikelyAacData:function(e){var t=_t(e,0) return e.length>=t+2&&!(255&~e[t])&&!(240&~e[t+1])&&16==(22&e[t+1])},parseId3TagSize:yt,parseAdtsSize:function(e,t){var i=(224&e[t+5])>>5,n=e[t+4]<<3 return 6144&e[t+3]|n|i},parseType:function(e,t){return e[t]==="I".charCodeAt(0)&&e[t+1]==="D".charCodeAt(0)&&e[t+2]==="3".charCodeAt(0)?"timed-metadata":!0&e[t]&&!(240&~e[t+1])?"audio":null},parseSampleRate:function(e){for(var t=0;t+5>>2] t++}return null},parseAacTimestamp:function(e){var t,i,n t=10 if(64&e[5]){t+=4 t+=bt(e.subarray(10,14))}do{if((i=bt(e.subarray(t+4,t+8)))<1)return null if("PRIV"===String.fromCharCode(e[t],e[t+1],e[t+2],e[t+3])){n=e.subarray(t+10,t+i+10) for(var r=0;r>>2 o*=4 return o+=3&s[7]}break}}t+=10 t+=i}while(t=3;)if(e[u]!=="I".charCodeAt(0)||e[u+1]!=="D".charCodeAt(0)||e[u+2]!=="3".charCodeAt(0))if(255&~e[u]||240&~e[u+1])u++ else{if(e.length-u<7)break if(u+(o=Tt.parseAdtsSize(e,u))>e.length)break a={type:"audio",data:e.subarray(u,u+o),pts:t,dts:t} this.trigger("data",a) u+=o}else{if(e.length-u<10)break if(u+(o=Tt.parseId3TagSize(e,u))>e.length)break r={type:"timed-metadata",data:e.subarray(u,u+o)} this.trigger("data",r) u+=o}n=e.length-u e=n>0?e.subarray(u):new Uint8Array} this.reset=function(){e=new Uint8Array this.trigger("reset")} this.endTimeline=function(){e=new Uint8Array this.trigger("endedtimeline")}}).prototype=new U var kt,St,Et,Ct,wt=mt,It=["audioobjecttype","channelcount","samplerate","samplingfrequencyindex","samplesize"],Pt=["width","height","profileIdc","levelIdc","profileCompatibility","sarRatio"],xt=gt.H264Stream,At=Tt.isLikelyAacData,Ot=le,Lt=function(e,t){t.stream=e this.trigger("log",t)},Dt=function(e,t){for(var i=Object.keys(t),n=0;n=-1e4&&i<=45e3&&(!n||o>i))){n=a o=i}}return n?n.gop:null} this.alignGopsAtStart_=function(e){var t,i,n,r,a,o,u,l a=e.byteLength o=e.nalCount u=e.duration t=i=0 for(;tn.pts)t++ else{i++ a-=r.byteLength o-=r.nalCount u-=r.duration}}if(0===i)return e if(i===e.length)return null;(l=e.slice(i)).byteLength=a l.duration=u l.nalCount=o l.pts=l[0].pts l.dts=l[0].dts return l} this.alignGopsAtEnd_=function(e){var t,i,n,r,a,o,u t=s.length-1 i=e.length-1 a=null o=!1 for(;t>=0&&i>=0;){n=s[t] r=e[i] if(n.pts===r.pts){o=!0 break}if(n.pts>r.pts)t-- else{t===s.length-1&&(a=i) i--}}if(!o&&null===a)return null if(0===(u=o?i:a))return e var l=e.slice(u),c=l.reduce((function(e,t){e.byteLength+=t.byteLength e.duration+=t.duration e.nalCount+=t.nalCount return e}),{byteLength:0,duration:0,nalCount:0}) l.byteLength=c.byteLength l.duration=c.duration l.nalCount=c.nalCount l.pts=l[0].pts l.dts=l[0].dts return l} this.alignGopsWith=function(e){s=e}} kt.prototype=new U Ct=function(e,t){this.numberOfTracks=0 this.metadataStream=t void 0!==(e=e||{}).remux?this.remuxTracks=!!e.remux:this.remuxTracks=!0 "boolean"==typeof e.keepOriginalTimestamps?this.keepOriginalTimestamps=e.keepOriginalTimestamps:this.keepOriginalTimestamps=!1 this.pendingTracks=[] this.videoTrack=null this.pendingBoxes=[] this.pendingCaptions=[] this.pendingMetadata=[] this.pendingBytes=0 this.emittedTracks=0 Ct.prototype.init.call(this) this.push=function(e){if(e.text)return this.pendingCaptions.push(e) if(e.frames)return this.pendingMetadata.push(e) this.pendingTracks.push(e.track) this.pendingBytes+=e.boxes.byteLength if("video"===e.track.type){this.videoTrack=e.track this.pendingBoxes.push(e.boxes)}if("audio"===e.track.type){this.audioTrack=e.track this.pendingBoxes.unshift(e.boxes)}}} Ct.prototype=new U Ct.prototype.flush=function(e){var t,i,n,r,a=0,s={captions:[],captionStreams:{},metadata:[],info:{}},o=0 if(this.pendingTracks.length=this.numberOfTracks){this.trigger("done") this.emittedTracks=0}return}}if(this.videoTrack){o=this.videoTrack.timelineStartInfo.pts Pt.forEach((function(e){s.info[e]=this.videoTrack[e]}),this)}else if(this.audioTrack){o=this.audioTrack.timelineStartInfo.pts It.forEach((function(e){s.info[e]=this.audioTrack[e]}),this)}if(this.videoTrack||this.audioTrack){1===this.pendingTracks.length?s.type=this.pendingTracks[0].type:s.type="combined" this.emittedTracks+=this.pendingTracks.length n=$(this.pendingTracks) s.initSegment=new Uint8Array(n.byteLength) s.initSegment.set(n) s.data=new Uint8Array(this.pendingBytes) for(r=0;r=this.numberOfTracks){this.trigger("done") this.emittedTracks=0}} Ct.prototype.setRemux=function(e){this.remuxTracks=e} Et=function(e){var t,i,n=this,r=!0 Et.prototype.init.call(this) e=e||{} this.baseMediaDecodeTime=e.baseMediaDecodeTime||0 this.transmuxPipeline_={} this.setupAacPipeline=function(){var r={} this.transmuxPipeline_=r r.type="aac" r.metadataStream=new st.MetadataStream r.aacStream=new wt r.audioTimestampRolloverStream=new st.TimestampRolloverStream("audio") r.timedMetadataTimestampRolloverStream=new st.TimestampRolloverStream("timed-metadata") r.adtsStream=new ct r.coalesceStream=new Ct(e,r.metadataStream) r.headOfPipeline=r.aacStream r.aacStream.pipe(r.audioTimestampRolloverStream).pipe(r.adtsStream) r.aacStream.pipe(r.timedMetadataTimestampRolloverStream).pipe(r.metadataStream).pipe(r.coalesceStream) r.metadataStream.on("timestamp",(function(e){r.aacStream.setTimestamp(e.timeStamp)})) r.aacStream.on("data",(function(a){if(!("timed-metadata"!==a.type&&"audio"!==a.type||r.audioSegmentStream)){i=i||{timelineStartInfo:{baseMediaDecodeTime:n.baseMediaDecodeTime},codec:"adts",type:"audio"} r.coalesceStream.numberOfTracks++ r.audioSegmentStream=new St(i,e) r.audioSegmentStream.on("log",n.getLogTrigger_("audioSegmentStream")) r.audioSegmentStream.on("timingInfo",n.trigger.bind(n,"audioTimingInfo")) r.adtsStream.pipe(r.audioSegmentStream).pipe(r.coalesceStream) n.trigger("trackinfo",{hasAudio:!!i,hasVideo:!!t})}})) r.coalesceStream.on("data",this.trigger.bind(this,"data")) r.coalesceStream.on("done",this.trigger.bind(this,"done")) Dt(this,r)} this.setupTsPipeline=function(){var r={} this.transmuxPipeline_=r r.type="ts" r.metadataStream=new st.MetadataStream r.packetStream=new st.TransportPacketStream r.parseStream=new st.TransportParseStream r.elementaryStream=new st.ElementaryStream r.timestampRolloverStream=new st.TimestampRolloverStream r.adtsStream=new ct r.h264Stream=new xt r.captionStream=new st.CaptionStream(e) r.coalesceStream=new Ct(e,r.metadataStream) r.headOfPipeline=r.packetStream r.packetStream.pipe(r.parseStream).pipe(r.elementaryStream).pipe(r.timestampRolloverStream) r.timestampRolloverStream.pipe(r.h264Stream) r.timestampRolloverStream.pipe(r.adtsStream) r.timestampRolloverStream.pipe(r.metadataStream).pipe(r.coalesceStream) r.h264Stream.pipe(r.captionStream).pipe(r.coalesceStream) r.elementaryStream.on("data",(function(a){var s if("metadata"===a.type){s=a.tracks.length for(;s--;)t||"video"!==a.tracks[s].type?i||"audio"!==a.tracks[s].type||((i=a.tracks[s]).timelineStartInfo.baseMediaDecodeTime=n.baseMediaDecodeTime):(t=a.tracks[s]).timelineStartInfo.baseMediaDecodeTime=n.baseMediaDecodeTime if(t&&!r.videoSegmentStream){r.coalesceStream.numberOfTracks++ r.videoSegmentStream=new kt(t,e) r.videoSegmentStream.on("log",n.getLogTrigger_("videoSegmentStream")) r.videoSegmentStream.on("timelineStartInfo",(function(t){if(i&&!e.keepOriginalTimestamps){i.timelineStartInfo=t r.audioSegmentStream.setEarliestDts(t.dts-n.baseMediaDecodeTime)}})) r.videoSegmentStream.on("processedGopsInfo",n.trigger.bind(n,"gopInfo")) r.videoSegmentStream.on("segmentTimingInfo",n.trigger.bind(n,"videoSegmentTimingInfo")) r.videoSegmentStream.on("baseMediaDecodeTime",(function(e){i&&r.audioSegmentStream.setVideoBaseMediaDecodeTime(e)})) r.videoSegmentStream.on("timingInfo",n.trigger.bind(n,"videoTimingInfo")) r.h264Stream.pipe(r.videoSegmentStream).pipe(r.coalesceStream)}if(i&&!r.audioSegmentStream){r.coalesceStream.numberOfTracks++ r.audioSegmentStream=new St(i,e) r.audioSegmentStream.on("log",n.getLogTrigger_("audioSegmentStream")) r.audioSegmentStream.on("timingInfo",n.trigger.bind(n,"audioTimingInfo")) r.audioSegmentStream.on("segmentTimingInfo",n.trigger.bind(n,"audioSegmentTimingInfo")) r.adtsStream.pipe(r.audioSegmentStream).pipe(r.coalesceStream)}n.trigger("trackinfo",{hasAudio:!!i,hasVideo:!!t})}})) r.coalesceStream.on("data",this.trigger.bind(this,"data")) r.coalesceStream.on("id3Frame",(function(e){e.dispatchType=r.metadataStream.dispatchType n.trigger("id3Frame",e)})) r.coalesceStream.on("caption",this.trigger.bind(this,"caption")) r.coalesceStream.on("done",this.trigger.bind(this,"done")) Dt(this,r)} this.setBaseMediaDecodeTime=function(n){var r=this.transmuxPipeline_ e.keepOriginalTimestamps||(this.baseMediaDecodeTime=n) if(i){i.timelineStartInfo.dts=void 0 i.timelineStartInfo.pts=void 0 be(i) r.audioTimestampRolloverStream&&r.audioTimestampRolloverStream.discontinuity()}if(t){r.videoSegmentStream&&(r.videoSegmentStream.gopCache_=[]) t.timelineStartInfo.dts=void 0 t.timelineStartInfo.pts=void 0 be(t) r.captionStream.reset()}r.timestampRolloverStream&&r.timestampRolloverStream.discontinuity()} this.setAudioAppendStart=function(e){i&&this.transmuxPipeline_.audioSegmentStream.setAudioAppendStart(e)} this.setRemux=function(t){var i=this.transmuxPipeline_ e.remux=t i&&i.coalesceStream&&i.coalesceStream.setRemux(t)} this.alignGopsWith=function(e){t&&this.transmuxPipeline_.videoSegmentStream&&this.transmuxPipeline_.videoSegmentStream.alignGopsWith(e)} this.getLogTrigger_=function(e){var t=this return function(i){i.stream=e t.trigger("log",i)}} this.push=function(e){if(r){var t=At(e) t&&"aac"!==this.transmuxPipeline_.type?this.setupAacPipeline():t||"ts"===this.transmuxPipeline_.type||this.setupTsPipeline() r=!1}this.transmuxPipeline_.headOfPipeline.push(e)} this.flush=function(){r=!0 this.transmuxPipeline_.headOfPipeline.flush()} this.endTimeline=function(){this.transmuxPipeline_.headOfPipeline.endTimeline()} this.reset=function(){this.transmuxPipeline_.headOfPipeline&&this.transmuxPipeline_.headOfPipeline.reset()} this.resetCaptions=function(){this.transmuxPipeline_.captionStream&&this.transmuxPipeline_.captionStream.reset()}} Et.prototype=new U var Nt,Ut,Bt,Ft={Transmuxer:Et,VideoSegmentStream:kt,AudioSegmentStream:St,AUDIO_PROPERTIES:It,VIDEO_PROPERTIES:Pt,generateSegmentTimingInfo:Mt},jt=function(e){return e>>>0},Vt=function(e){var t="" t+=String.fromCharCode(e[0]) t+=String.fromCharCode(e[1]) t+=String.fromCharCode(e[2]) return t+=String.fromCharCode(e[3])},Ht=jt,qt=function e(t,i){var n,r,a,s,o,u=[] if(!i.length)return null for(n=0;n1?n+r:t.byteLength a===i[0]&&(1===i.length?u.push(t.subarray(n+8,s)):(o=e(t.subarray(n+8,s),i.slice(1))).length&&(u=u.concat(o))) n=s}return u},Wt=jt,Gt=F.getUint64,zt=function(e){var t={version:e[0],flags:new Uint8Array(e.subarray(1,4))} 1===t.version?t.baseMediaDecodeTime=Gt(e.subarray(4)):t.baseMediaDecodeTime=Wt(e[4]<<24|e[5]<<16|e[6]<<8|e[7]) return t},Kt=function(e){return{isLeading:(12&e[0])>>>2,dependsOn:3&e[0],isDependedOn:(192&e[1])>>>6,hasRedundancy:(48&e[1])>>>4,paddingValue:(14&e[1])>>>1,isNonSyncSample:1&e[1],degradationPriority:e[2]<<8|e[3]}},Xt=function(e){var t,i={version:e[0],flags:new Uint8Array(e.subarray(1,4)),samples:[]},n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=1&i.flags[2],a=4&i.flags[2],s=1&i.flags[1],o=2&i.flags[1],u=4&i.flags[1],l=8&i.flags[1],c=n.getUint32(4),d=8 if(r){i.dataOffset=n.getInt32(d) d+=4}if(a&&c){t={flags:Kt(e.subarray(d,d+4))} d+=4 if(s){t.duration=n.getUint32(d) d+=4}if(o){t.size=n.getUint32(d) d+=4}if(l){1===i.version?t.compositionTimeOffset=n.getInt32(d):t.compositionTimeOffset=n.getUint32(d) d+=4}i.samples.push(t) c--}for(;c--;){t={} if(s){t.duration=n.getUint32(d) d+=4}if(o){t.size=n.getUint32(d) d+=4}if(u){t.flags=Kt(e.subarray(d,d+4)) d+=4}if(l){1===i.version?t.compositionTimeOffset=n.getInt32(d):t.compositionTimeOffset=n.getUint32(d) d+=4}i.samples.push(t)}return i},Yt=function(e){var t,i=new DataView(e.buffer,e.byteOffset,e.byteLength),n={version:e[0],flags:new Uint8Array(e.subarray(1,4)),trackId:i.getUint32(4)},r=1&n.flags[2],a=2&n.flags[2],s=8&n.flags[2],o=16&n.flags[2],u=32&n.flags[2],l=65536&n.flags[0],c=131072&n.flags[0] t=8 if(r){t+=4 n.baseDataOffset=i.getUint32(12) t+=4}if(a){n.sampleDescriptionIndex=i.getUint32(t) t+=4}if(s){n.defaultSampleDuration=i.getUint32(t) t+=4}if(o){n.defaultSampleSize=i.getUint32(t) t+=4}u&&(n.defaultSampleFlags=i.getUint32(t)) l&&(n.durationIsEmpty=!0) !r&&c&&(n.baseDataOffsetIsMoof=!0) return n},Qt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},$t="undefined"!=typeof window?window:void 0!==Qt?Qt:"undefined"!=typeof self?self:{},Jt=we,Zt=Fe.CaptionStream,ei=function(e,t){for(var i=e,n=0;n0?zt(c[0]).baseMediaDecodeTime:0,h=qt(s,["trun"]) if(t===l&&h.length>0){i=function(e,t,i){var n=t,r=i.defaultSampleDuration||0,a=i.defaultSampleSize||0,s=i.trackId,o=[] e.forEach((function(e){var t=Xt(e).samples t.forEach((function(e){void 0===e.duration&&(e.duration=r) void 0===e.size&&(e.size=a) e.trackId=s e.dts=n void 0===e.compositionTimeOffset&&(e.compositionTimeOffset=0) if("bigint"==typeof n){e.pts=n+$t.BigInt(e.compositionTimeOffset) n+=$t.BigInt(e.duration)}else{e.pts=n+e.compositionTimeOffset n+=e.duration}})) o=o.concat(t)})) return o}(h,d,u) n=function(e,t,i){var n,r,a,s,o=new DataView(e.buffer,e.byteOffset,e.byteLength),u={logs:[],seiNals:[]} for(r=0;r+40;){var u=t.shift() this.parse(u,a,s)}o=function(e,t,i){if(null===t)return null var n=ti(e,t)[t]||{} return{seiNals:n.seiNals,logs:n.logs,timescale:i}}(e,i,n) o&&o.logs&&(r.logs=r.logs.concat(o.logs)) if(null===o||!o.seiNals)return r.logs.length?{logs:r.logs,captions:[],captionStreams:[]}:null this.pushNals(o.seiNals) this.flushStream() return r} this.pushNals=function(t){if(!this.isInitialized()||!t||0===t.length)return null t.forEach((function(t){e.push(t)}))} this.flushStream=function(){if(!this.isInitialized())return null a?e.partialFlush():e.flush()} this.clearParsedCaptions=function(){r.captions=[] r.captionStreams={} r.logs=[]} this.resetCaptionStream=function(){if(!this.isInitialized())return null e.reset()} this.clearAllCaptions=function(){this.clearParsedCaptions() this.resetCaptionStream()} this.reset=function(){t=[] i=null n=null r?this.clearParsedCaptions():r={captions:[],captionStreams:{},logs:[]} this.resetCaptionStream()} this.reset()},ni=jt,ri=function(e){return("00"+e.toString(16)).slice(-2)},ai=F.getUint64 0 Nt=function(e,t){var i=qt(t,["moof","traf"]).reduce((function(t,i){var n,r,a=qt(i,["tfhd"])[0],s=ni(a[4]<<24|a[5]<<16|a[6]<<8|a[7]),o=e[s]||9e4,u=qt(i,["tfdt"])[0],l=new DataView(u.buffer,u.byteOffset,u.byteLength) "bigint"==typeof(n=1===u[0]?ai(u.subarray(4,12)):l.getUint32(4))?r=n/$t.BigInt(o):"number"!=typeof n||isNaN(n)||(r=n/o) r11){r.codec+="." r.codec+=ri(c[9]) r.codec+=ri(c[10]) r.codec+=ri(c[11])}else r.codec="avc1.4d400d"}else if(/^mp4[a,v]$/i.test(r.codec)){c=d.subarray(28) if("esds"===Vt(c.subarray(4,8))&&c.length>20&&0!==c[19]){r.codec+="."+ri(c[19]) r.codec+="."+ri(c[20]>>>2&63).replace(/^0/,"")}else r.codec="mp4a.40.2"}else r.codec=r.codec.toLowerCase()}var h=qt(e,["mdia","mdhd"])[0] h&&(r.timescale=Bt(h)) i.push(r)})) return i} var si=Nt,oi=Ut,ui=function(e){var t=31&e[1] t<<=8 return t|=e[2]},li=function(e){return!!(64&e[1])},ci=function(e){var t=0;(48&e[3])>>>4>1&&(t+=e[4]+1) return t},di=function(e){switch(e){case 5:return"slice_layer_without_partitioning_rbsp_idr" case 6:return"sei_rbsp" case 7:return"seq_parameter_set_rbsp" case 8:return"pic_parameter_set_rbsp" case 9:return"access_unit_delimiter_rbsp" default:return null}},hi={parseType:function(e,t){var i=ui(e) return 0===i?"pat":i===t?"pmt":t?"pes":null},parsePat:function(e){var t=li(e),i=4+ci(e) t&&(i+=e[i]+1) return(31&e[i+10])<<8|e[i+11]},parsePmt:function(e){var t={},i=li(e),n=4+ci(e) i&&(n+=e[n]+1) if(1&e[n+5]){var r r=3+((15&e[n+1])<<8|e[n+2])-4 for(var a=12+((15&e[n+10])<<8|e[n+11]);a=e.byteLength)return null var i,n=null if(192&(i=e[t+7])){(n={}).pts=(14&e[t+9])<<27|(255&e[t+10])<<20|(254&e[t+11])<<12|(255&e[t+12])<<5|(254&e[t+13])>>>3 n.pts*=4 n.pts+=(6&e[t+13])>>>1 n.dts=n.pts if(64&i){n.dts=(14&e[t+14])<<27|(255&e[t+15])<<20|(254&e[t+16])<<12|(255&e[t+17])<<5|(254&e[t+18])>>>3 n.dts*=4 n.dts+=(6&e[t+18])>>>1}}return n},videoPacketContainsKeyFrame:function(e){for(var t=4+ci(e),i=e.subarray(t),n=0,r=0,a=!1;r3&&"slice_layer_without_partitioning_rbsp_idr"===di(31&i[r+3])&&(a=!0) return a}},pi=ze,fi={} fi.ts=hi fi.aac=Tt var mi=le,gi=188,vi=71,yi=function(e,t,i){for(var n,r,a,s,o=0,u=gi,l=!1;u<=e.byteLength;)if(e[o]!==vi||e[u]!==vi&&u!==e.byteLength){o++ u++}else{n=e.subarray(o,u) if("pes"===fi.ts.parseType(n,t.pid)){r=fi.ts.parsePesType(n,t.table) a=fi.ts.parsePayloadUnitStartIndicator(n) if("audio"===r&&a&&(s=fi.ts.parsePesTime(n))){s.type="audio" i.audio.push(s) l=!0}}if(l)break o+=gi u+=gi}o=(u=e.byteLength)-gi l=!1 for(;o>=0;)if(e[o]!==vi||e[u]!==vi&&u!==e.byteLength){o-- u--}else{n=e.subarray(o,u) if("pes"===fi.ts.parseType(n,t.pid)){r=fi.ts.parsePesType(n,t.table) a=fi.ts.parsePayloadUnitStartIndicator(n) if("audio"===r&&a&&(s=fi.ts.parsePesTime(n))){s.type="audio" i.audio.push(s) l=!0}}if(l)break o-=gi u-=gi}},_i=function(e,t,i){for(var n,r,a,s,o,u,l,c=0,d=gi,h=!1,p={data:[],size:0};d=0;)if(e[c]!==vi||e[d]!==vi){c-- d--}else{n=e.subarray(c,d) if("pes"===fi.ts.parseType(n,t.pid)){r=fi.ts.parsePesType(n,t.table) a=fi.ts.parsePayloadUnitStartIndicator(n) if("video"===r&&a&&(s=fi.ts.parsePesTime(n))){s.type="video" i.video.push(s) h=!0}}if(h)break c-=gi d-=gi}},bi=function(e){var t={pid:null,table:null},i={} !function(e,t){for(var i,n=0,r=gi;r=3;){switch(fi.aac.parseType(e,o)){case"timed-metadata":if(e.length-o<10){i=!0 break}if((s=fi.aac.parseId3TagSize(e,o))>e.length){i=!0 break}if(null===a){t=e.subarray(o,o+s) a=fi.aac.parseAacTimestamp(t)}o+=s break case"audio":if(e.length-o<7){i=!0 break}if((s=fi.aac.parseAdtsSize(e,o))>e.length){i=!0 break}if(null===r){t=e.subarray(o,o+s) r=fi.aac.parseSampleRate(t)}n++ o+=s break default:o++}if(i)return null}if(null===r||null===a)return null var u=mi/r return{audio:[{type:"audio",dts:a,pts:a},{type:"audio",dts:a+1024*n*u,pts:a+1024*n*u}]}}(e):bi(e) if(!i||!i.audio&&!i.video)return null !function(e,t){if(e.audio&&e.audio.length){var i=t;(void 0===i||isNaN(i))&&(i=e.audio[0].dts) e.audio.forEach((function(e){e.dts=pi(e.dts,i) e.pts=pi(e.pts,i) e.dtsTime=e.dts/mi e.ptsTime=e.pts/mi}))}if(e.video&&e.video.length){var n=t;(void 0===n||isNaN(n))&&(n=e.video[0].dts) e.video.forEach((function(e){e.dts=pi(e.dts,n) e.pts=pi(e.pts,n) e.dtsTime=e.dts/mi e.ptsTime=e.pts/mi})) if(e.firstKeyFrame){var r=e.firstKeyFrame r.dts=pi(r.dts,n) r.pts=pi(r.pts,n) r.dtsTime=r.dts/mi r.ptsTime=r.pts/mi}}}(i,t) return i},ki=function(){function e(e,t){this.options=t||{} this.self=e this.init()}var t=e.prototype t.init=function(){this.transmuxer&&this.transmuxer.dispose() this.transmuxer=new Ft.Transmuxer(this.options) !function(e,t){t.on("data",(function(t){var i=t.initSegment t.initSegment={data:i.buffer,byteOffset:i.byteOffset,byteLength:i.byteLength} var n=t.data t.data=n.buffer e.postMessage({action:"data",segment:t,byteOffset:n.byteOffset,byteLength:n.byteLength},[t.data])})) t.on("done",(function(t){e.postMessage({action:"done"})})) t.on("gopInfo",(function(t){e.postMessage({action:"gopInfo",gopInfo:t})})) t.on("videoSegmentTimingInfo",(function(t){var i={start:{decode:de(t.start.dts),presentation:de(t.start.pts)},end:{decode:de(t.end.dts),presentation:de(t.end.pts)},baseMediaDecodeTime:de(t.baseMediaDecodeTime)} t.prependedContentDuration&&(i.prependedContentDuration=de(t.prependedContentDuration)) e.postMessage({action:"videoSegmentTimingInfo",videoSegmentTimingInfo:i})})) t.on("audioSegmentTimingInfo",(function(t){var i={start:{decode:de(t.start.dts),presentation:de(t.start.pts)},end:{decode:de(t.end.dts),presentation:de(t.end.pts)},baseMediaDecodeTime:de(t.baseMediaDecodeTime)} t.prependedContentDuration&&(i.prependedContentDuration=de(t.prependedContentDuration)) e.postMessage({action:"audioSegmentTimingInfo",audioSegmentTimingInfo:i})})) t.on("id3Frame",(function(t){e.postMessage({action:"id3Frame",id3Frame:t})})) t.on("caption",(function(t){e.postMessage({action:"caption",caption:t})})) t.on("trackinfo",(function(t){e.postMessage({action:"trackinfo",trackInfo:t})})) t.on("audioTimingInfo",(function(t){e.postMessage({action:"audioTimingInfo",audioTimingInfo:{start:de(t.start),end:de(t.end)}})})) t.on("videoTimingInfo",(function(t){e.postMessage({action:"videoTimingInfo",videoTimingInfo:{start:de(t.start),end:de(t.end)}})})) t.on("log",(function(t){e.postMessage({action:"log",log:t})}))}(this.self,this.transmuxer)} t.pushMp4Captions=function(e){if(!this.captionParser){this.captionParser=new ii this.captionParser.init()}var t=new Uint8Array(e.data,e.byteOffset,e.byteLength),i=this.captionParser.parse(t,e.trackIds,e.timescales) this.self.postMessage({action:"mp4Captions",captions:i&&i.captions||[],logs:i&&i.logs||[],data:t.buffer},[t.buffer])} t.probeMp4StartTime=function(e){var t=e.timescales,i=e.data,n=si(t,i) this.self.postMessage({action:"probeMp4StartTime",startTime:n,data:i},[i.buffer])} t.probeMp4Tracks=function(e){var t=e.data,i=oi(t) this.self.postMessage({action:"probeMp4Tracks",tracks:i,data:t},[t.buffer])} t.probeTs=function(e){var t=e.data,i=e.baseStartTime,n="number"!=typeof i||isNaN(i)?void 0:i*le,r=Ti(t,n),a=null if(r){(a={hasVideo:r.video&&2===r.video.length||!1,hasAudio:r.audio&&2===r.audio.length||!1}).hasVideo&&(a.videoStart=r.video[0].ptsTime) a.hasAudio&&(a.audioStart=r.audio[0].ptsTime)}this.self.postMessage({action:"probeTs",result:a,data:t},[t.buffer])} t.clearAllMp4Captions=function(){this.captionParser&&this.captionParser.clearAllCaptions()} t.clearParsedMp4Captions=function(){this.captionParser&&this.captionParser.clearParsedCaptions()} t.push=function(e){var t=new Uint8Array(e.data,e.byteOffset,e.byteLength) this.transmuxer.push(t)} t.reset=function(){this.transmuxer.reset()} t.setTimestampOffset=function(e){var t=e.timestampOffset||0 this.transmuxer.setBaseMediaDecodeTime(Math.round(ce(t)))} t.setAudioAppendStart=function(e){this.transmuxer.setAudioAppendStart(Math.ceil(ce(e.appendStart)))} t.setRemux=function(e){this.transmuxer.setRemux(e.remux)} t.flush=function(e){this.transmuxer.flush() self.postMessage({action:"done",type:"transmuxed"})} t.endTimeline=function(){this.transmuxer.endTimeline() self.postMessage({action:"endedtimeline",type:"transmuxed"})} t.alignGopsWith=function(e){this.transmuxer.alignGopsWith(e.gopsToAlignWith.slice())} return e}() self.onmessage=function(e){if("init"===e.data.action&&e.data.options)this.messageHandlers=new ki(self,e.data.options) else{this.messageHandlers||(this.messageHandlers=new ki(self)) e.data&&e.data.action&&"init"!==e.data.action&&this.messageHandlers[e.data.action]&&this.messageHandlers[e.data.action](e.data)}}}))),dd=od(cd),hd=function(e){var t=e.transmuxer,i=e.bytes,n=e.audioAppendStart,r=e.gopsToAlignWith,a=e.remux,s=e.onData,o=e.onTrackInfo,u=e.onAudioTimingInfo,l=e.onVideoTimingInfo,c=e.onVideoSegmentTimingInfo,d=e.onAudioSegmentTimingInfo,h=e.onId3,p=e.onCaptions,f=e.onDone,m=e.onEndedTimeline,g=e.onTransmuxerLog,v=e.isEndOfTimeline,y={buffer:[]},_=v t.onmessage=function(i){if(t.currentTransmux===e){"data"===i.data.action&&function(e,t,i){var n=e.data.segment,r=n.type,a=n.initSegment,s=n.captions,o=n.captionStreams,u=n.metadata,l=n.videoFrameDtsTime,c=n.videoFramePtsTime t.buffer.push({captions:s,captionStreams:o,metadata:u}) var d=e.data.segment.boxes||{data:e.data.segment.data},h={type:r,data:new Uint8Array(d.data,d.data.byteOffset,d.data.byteLength),initSegment:new Uint8Array(a.data,a.byteOffset,a.byteLength)} void 0!==l&&(h.videoFrameDtsTime=l) void 0!==c&&(h.videoFramePtsTime=c) i(h)}(i,y,s) "trackinfo"===i.data.action&&o(i.data.trackInfo) "gopInfo"===i.data.action&&function(e,t){t.gopInfo=e.data.gopInfo}(i,y) "audioTimingInfo"===i.data.action&&u(i.data.audioTimingInfo) "videoTimingInfo"===i.data.action&&l(i.data.videoTimingInfo) "videoSegmentTimingInfo"===i.data.action&&c(i.data.videoSegmentTimingInfo) "audioSegmentTimingInfo"===i.data.action&&d(i.data.audioSegmentTimingInfo) "id3Frame"===i.data.action&&h([i.data.id3Frame],i.data.id3Frame.dispatchType) "caption"===i.data.action&&p(i.data.caption) if("endedtimeline"===i.data.action){_=!1 m()}"log"===i.data.action&&g(i.data.log) if("transmuxed"===i.data.type&&!_){t.onmessage=null !function(e){var t=e.transmuxedData,i=e.callback t.buffer=[] i(t)}({transmuxedData:y,callback:f}) pd(t)}}} n&&t.postMessage({action:"setAudioAppendStart",appendStart:n}) Array.isArray(r)&&t.postMessage({action:"alignGopsWith",gopsToAlignWith:r}) void 0!==a&&t.postMessage({action:"setRemux",remux:a}) if(i.byteLength){var b=i instanceof ArrayBuffer?i:i.buffer,T=i instanceof ArrayBuffer?0:i.byteOffset t.postMessage({action:"push",data:b,byteOffset:T,byteLength:i.byteLength},[b])}v&&t.postMessage({action:"endTimeline"}) t.postMessage({action:"flush"})},pd=function(e){e.currentTransmux=null if(e.transmuxQueue.length){e.currentTransmux=e.transmuxQueue.shift() "function"==typeof e.currentTransmux?e.currentTransmux():hd(e.currentTransmux)}},fd=function(e,t){e.postMessage({action:t}) pd(e)},md=function(e,t){if(t.currentTransmux)t.transmuxQueue.push(fd.bind(null,t,e)) else{t.currentTransmux=e fd(t,e)}},gd=function(e){if(e.transmuxer.currentTransmux)e.transmuxer.transmuxQueue.push(e) else{e.transmuxer.currentTransmux=e hd(e)}},vd=function(e){md("reset",e)},yd=function(e){var t=new dd t.currentTransmux=null t.transmuxQueue=[] var i=t.terminate t.terminate=function(){t.currentTransmux=null t.transmuxQueue.length=0 return i.call(t)} t.postMessage({action:"init",options:e}) return t},_d=function(e){var t=e.transmuxer,i=e.endAction||e.action,n=e.callback,r=R({},e,{endAction:null,transmuxer:null,callback:null}) t.addEventListener("message",(function r(a){if(a.data.action===i){t.removeEventListener("message",r) if(a.data.data){a.data.data=new Uint8Array(a.data.data,e.byteOffset||0,e.byteLength||a.data.data.byteLength) e.data&&(e.data=a.data.data)}n(a.data)}})) if(e.data){var a=e.data instanceof ArrayBuffer r.byteOffset=a?0:e.data.byteOffset r.byteLength=e.data.byteLength var s=[a?e.data:e.data.buffer] t.postMessage(r,s)}else t.postMessage(r)},bd=2,Td=-101,kd=-102,Sd=function(e){e.forEach((function(e){e.abort()}))},Ed=function(e,t){return t.timedout?{status:t.status,message:"HLS request timed-out at URL: "+t.uri,code:Td,xhr:t}:t.aborted?{status:t.status,message:"HLS request aborted at URL: "+t.uri,code:kd,xhr:t}:e?{status:t.status,message:"HLS request errored at URL: "+t.uri,code:bd,xhr:t}:"arraybuffer"===t.responseType&&0===t.response.byteLength?{status:t.status,message:"Empty HLS response at URL: "+t.uri,code:bd,xhr:t}:null},Cd=function(e,t,i){return function(n,r){var a=r.response,s=Ed(n,r) if(s)return i(s,e) if(16!==a.byteLength)return i({status:r.status,message:"Invalid HLS key at URL: "+r.uri,code:bd,xhr:r},e) for(var o=new DataView(a),u=new Uint32Array([o.getUint32(0),o.getUint32(4),o.getUint32(8),o.getUint32(12)]),l=0;l0}(f)){t.isFmp4=!0 var m=t.map.tracks,g={isFmp4:!0,hasVideo:!!m.video,hasA