1&&(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},Rt=function(t,e){var i,n,a,r,s,o=e||0,d=[];for(i=0;iu/2))){for((s=Wt()[t.samplerate])||(s=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)})))},Ht=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--},se.prototype.isEmpty=function(){return 0===this.rows.length||1===this.rows.length&&""===this.rows[0]},se.prototype.addText=function(t){this.rows[this.rowIdx]+=t},se.prototype.backspace=function(){if(!this.isEmpty()){var t=this.rows[this.rowIdx];this.rows[this.rowIdx]=t.substr(0,t.length-1)}};var oe=function(t){this.serviceNum=t,this.text="",this.currentWindow=new se(-1),this.windows=[]};oe.prototype.init=function(t,e){this.startPts=t;for(var i=0;i<8;i++)this.windows[i]=new se(i),"function"==typeof e&&(this.windows[i].beforeRowOverflow=e)},oe.prototype.setCurrentWindow=function(t){this.currentWindow=this.windows[t]};var de=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))}};de.prototype=new d,de.prototype.new708Packet=function(){null!==this.current708Packet&&this.push708Packet(),this.current708Packet={data:[],ptsVals:[]}},de.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)},de.prototype.push708Packet=function(){var t=this.current708Packet,e=t.data,i=null,n=null,a=0,r=e[a++];for(t.seq=r>>6,t.sizeCode=63&r;a>5)&&n>0&&(i=r=e[a++]),this.pushServiceBlock(i,a,n),n>0&&(a+=n-1)},de.prototype.pushServiceBlock=function(t,e,i){var n,a=e,r=this.current708Packet.data,s=this.services[t];for(s||(s=this.initService(t,a));a>5,r.rowLock=(16&n)>>4,r.columnLock=(8&n)>>3,r.priority=7&n,n=i[++t],r.relativePositioning=(128&n)>>7,r.anchorVertical=127&n,n=i[++t],r.anchorHorizontal=n,n=i[++t],r.anchorPoint=(240&n)>>4,r.rowCount=15&n,n=i[++t],r.columnCount=63&n,n=i[++t],r.windowStyle=(56&n)>>3,r.penStyle=7&n,r.virtualRowCount=r.rowCount+1,t},de.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},de.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},de.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)},de.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},de.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},de.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},de.prototype.reset=function(t,e){var i=this.getPts(t);return this.flushDisplayed(i,e),this.initService(e.serviceNum,t)};var he={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},pe=function(t){return null===t?"":(t=he[t]||t,String.fromCharCode(t))},ue=[4352,4384,4608,4640,5376,5408,5632,5664,5888,5920,4096,4864,4896,5120,5152],le=function(){for(var t=[],e=15;e--;)t.push("");return t},ce=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,r;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_=le();else if(e===this.ERASE_NON_DISPLAYED_MEMORY_)this.nonDisplayed_=le();else if(e===this.RESUME_DIRECT_CAPTIONING_)"paintOn"!==this.mode_&&(this.flushDisplayed(t.pts),this.displayed_=le()),this.mode_="paintOn",this.startPts_=t.pts;else if(this.isSpecialCharacter(n,a))r=pe((n=(3&n)<<8)|a),this[this.mode_](t.pts,r),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),r=pe((n=(3&n)<<8)|a),this[this.mode_](t.pts,r),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 s=ue.indexOf(7968&e);"rollUp"===this.mode_&&(s-this.rollUpRows_+1<0&&(s=this.rollUpRows_-1),this.setRollUp(t.pts,s)),s!==this.row_&&(this.clearFormatting(t.pts),this.row_=s),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),r=pe(n),r+=pe(a),this[this.mode_](t.pts,r),this.column_+=r.length)}else this.lastControlCode_=null}};ce.prototype=new d,ce.prototype.flushDisplayed=function(t){var e=this.displayed_.map((function(t){try{return t.trim()}catch(t){return console.error("Skipping malformed caption."),""}})).join("\n").replace(/^\n+|\n+$/g,"");e.length&&this.trigger("data",{startPts:this.startPts_,endPts:t,text:e,stream:this.name_})},ce.prototype.reset=function(){this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=le(),this.nonDisplayed_=le(),this.lastControlCode_=null,this.column_=0,this.row_=14,this.rollUpRows_=2,this.formatting_=[]},ce.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_},ce.prototype.isSpecialCharacter=function(t,e){return t===this.EXT_&&e>=48&&e<=63},ce.prototype.isExtCharacter=function(t,e){return(t===this.EXT_+1||t===this.EXT_+2)&&e>=32&&e<=63},ce.prototype.isMidRowCode=function(t,e){return t===this.EXT_&&e>=32&&e<=47},ce.prototype.isOffsetControlCode=function(t,e){return t===this.OFFSET_&&e>=33&&e<=35},ce.prototype.isPAC=function(t,e){return t>=this.BASE_&&t=64&&e<=127},ce.prototype.isColorPAC=function(t){return t>=64&&t<=79||t>=96&&t<=127},ce.prototype.isNormalChar=function(t){return t>=32&&t<=127},ce.prototype.setRollUp=function(t,e){if("rollUp"!==this.mode_&&(this.row_=14,this.mode_="rollUp",this.flushDisplayed(t),this.nonDisplayed_=le(),this.displayed_=le()),void 0!==e&&e!==this.row_)for(var i=0;i"}),"");this[this.mode_](t,i)},ce.prototype.clearFormatting=function(t){if(this.formatting_.length){var e=this.formatting_.reverse().reduce((function(t,e){return t+""+e+">"}),"");this.formatting_=[],this[this.mode_](t,e)}},ce.prototype.popOn=function(t,e){var i=this.nonDisplayed_[this.row_];i+=e,this.nonDisplayed_[this.row_]=i},ce.prototype.rollUp=function(t,e){var i=this.displayed_[this.row_];i+=e,this.displayed_[this.row_]=i},ce.prototype.shiftRowsUp_=function(){var t;for(t=0;te&&(i=-1);Math.abs(e-t)>4294967296;)t+=8589934592*i;return t},be=function t(e){var i,n;t.prototype.init.call(this),this.type_=e||ge,this.push=function(t){this.type_!==ge&&t.type!==this.type_||(void 0===n&&(n=t.dts),t.dts=ye(t.dts,n),t.pts=ye(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")}};be.prototype=new d;var ve,Se=be,Te=ye,we=function(t,e,i){var n,a="";for(n=e;n>>2;u*=4,u+=3&p[7],d.timeStamp=u,void 0===e.pts&&void 0===e.dts&&(e.pts=d.timeStamp,e.dts=d.timeStamp),this.trigger("timestamp",d)}e.frames.push(d),s+=10,s+=o}while(s>>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=me.H264_STREAM_TYPE:i.pid===this.programMapTable.audio?i.streamType=me.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 d,Ce.STREAM_TYPES={h264:27,adts:15},(De=function(){var t,e=this,i={data:[],size:0},n={data:[],size:0},a={data:[],size:0},r=function(t,i,n){var a,r,s=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,u.pts*=4,u.pts+=(6&p[13])>>>1,u.dts=u.pts,64&l&&(u.dts=(14&p[14])<<27|(255&p[15])<<20|(254&p[16])<<12|(255&p[17])<<5|(254&p[18])>>>3,u.dts*=4,u.dts+=(6&p[18])>>>1)),u.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)}};De.prototype.init.call(this),this.push=function(s){({pat:function(){},pes:function(){var t,e;switch(s.streamType){case me.H264_STREAM_TYPE:t=i,e="video";break;case me.ADTS_STREAM_TYPE:t=n,e="audio";break;case me.METADATA_STREAM_TYPE:t=a,e="timed-metadata";break;default:return}s.payloadUnitStartIndicator&&r(t,e,!0),t.data.push(s),t.size+=s.data.byteLength},pmt:function(){var i={type:"metadata",tracks:[]};null!==(t=s.programMapTable).video&&i.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.video,codec:"avc",type:"video"}),null!==t.audio&&i.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.audio,codec:"adts",type:"audio"}),e.trigger("data",i)}})[s.type]()},this.reset=function(){i.size=0,i.data.length=0,n.size=0,n.data.length=0,this.trigger("reset")},this.flushStreams_=function(){r(i,"video"),r(n,"audio"),r(a,"timed-metadata")},this.flush=function(){this.flushStreams_(),this.trigger("done")}}).prototype=new d;var Ie={PAT_PID:0,MP2T_PACKET_LENGTH:Oe,TransportPacketStream:Ae,TransportParseStream:Ce,ElementaryStream:De,TimestampRolloverStream:Le,CaptionStream:fe.CaptionStream,Cea608Stream:fe.Cea608Stream,Cea708Stream:fe.Cea708Stream,MetadataStream:Pe};for(var Me in me)me.hasOwnProperty(Me)&&(Ie[Me]=me[Me]);var xe,Ee=Ie,Re=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],Be=function(t,e){var i=t[e+6]<<21|t[e+7]<<14|t[e+8]<<7|t[e+9];return i=i>=0?i:0,(16&t[e+5])>>4?i+20:i+10},ze=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+=Be(e,i))},Fe=function(t){return t[0]<<21|t[1]<<14|t[2]<<7|t[3]},Ne={isLikelyAacData:function(t){var e=ze(t,0);return t.length>=e+2&&255==(255&t[e])&&240==(240&t[e+1])&&16==(22&t[e+1])},parseId3TagSize:Be,parseAdtsSize:function(t,e){var i=(224&t[e+5])>>5,n=t[e+4]<<3;return 6144&t[e+3]|n|i},parseType:function(t,e){return t[e]==="I".charCodeAt(0)&&t[e+1]==="D".charCodeAt(0)&&t[e+2]==="3".charCodeAt(0)?"timed-metadata":!0&t[e]&&240==(240&t[e+1])?"audio":null},parseSampleRate:function(t){for(var e=0;e+5>>2];e++}return null},parseAacTimestamp:function(t){var e,i,n;e=10,64&t[5]&&(e+=4,e+=Fe(t.subarray(10,14)));do{if((i=Fe(t.subarray(e+4,e+8)))<1)return null;if("PRIV"===String.fromCharCode(t[e],t[e+1],t[e+2],t[e+3])){n=t.subarray(e+10,e+i+10);for(var a=0;a>>2;return s*=4,s+=3&r[7]}break}}e+=10,e+=i}while(e=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=Ne.parseAdtsSize(t,d))>t.length)break;r={type:"audio",data:t.subarray(d,d+o),pts:e,dts:e},this.trigger("data",r),d+=o}else{if(t.length-d<10)break;if(d+(o=Ne.parseId3TagSize(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 d;var Ve,Ge,We,je,Ye=xe,He=["audioobjecttype","channelcount","samplerate","samplingfrequencyindex","samplesize"],qe=["width","height","profileIdc","levelIdc","profileCompatibility","sarRatio"],Ke=ht.H264Stream,Xe=Ne.isLikelyAacData,Ze=u,$e=function(t,e){var i;if(t.length!==e.length)return!1;for(i=0;i=-1e4&&i<=45e3&&(!n||o>i)&&(n=r,o=i));return n?n.gop:null},this.alignGopsAtStart_=function(t){var e,i,n,a,r,o,d,h;for(r=t.byteLength,o=t.nalCount,d=t.duration,e=i=0;en.pts?e++:(i++,r-=a.byteLength,o-=a.nalCount,d-=a.duration);return 0===i?t:i===t.length?null:((h=t.slice(i)).byteLength=r,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,r,o,d;for(e=s.length-1,i=t.length-1,r=null,o=!1;e>=0&&i>=0;){if(n=s[e],a=t[i],n.pts===a.pts){o=!0;break}n.pts>a.pts?e--:(e===s.length-1&&(r=i),i--)}if(!o&&null===r)return null;if(0===(d=o?i:r))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){s=t}}).prototype=new d,(je=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,je.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 d,je.prototype.flush=function(t){var e,i,n,a,r=0,s={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,qe.forEach((function(t){s.info[t]=this.videoTrack[t]}),this)):this.audioTrack&&(o=this.audioTrack.timelineStartInfo.pts,He.forEach((function(t){s.info[t]=this.audioTrack[t]}),this)),this.videoTrack||this.audioTrack){for(1===this.pendingTracks.length?s.type=this.pendingTracks[0].type:s.type="combined",this.emittedTracks+=this.pendingTracks.length,n=bt.initSegment(this.pendingTracks),s.initSegment=new Uint8Array(n.byteLength),s.initSegment.set(n),s.data=new Uint8Array(this.pendingBytes),a=0;a=this.numberOfTracks&&(this.trigger("done"),this.emittedTracks=0)},je.prototype.setRemux=function(t){this.remuxTracks=t},(We=function(t){var e,i,n=this,a=!0;We.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 Ee.MetadataStream,a.aacStream=new Ye,a.audioTimestampRolloverStream=new Ee.TimestampRolloverStream("audio"),a.timedMetadataTimestampRolloverStream=new Ee.TimestampRolloverStream("timed-metadata"),a.adtsStream=new T,a.coalesceStream=new je(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(r){"timed-metadata"!==r.type&&"audio"!==r.type||a.audioSegmentStream||(i=i||{timelineStartInfo:{baseMediaDecodeTime:n.baseMediaDecodeTime},codec:"adts",type:"audio"},a.coalesceStream.numberOfTracks++,a.audioSegmentStream=new Ge(i,t),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 Ee.MetadataStream,a.packetStream=new Ee.TransportPacketStream,a.parseStream=new Ee.TransportParseStream,a.elementaryStream=new Ee.ElementaryStream,a.timestampRolloverStream=new Ee.TimestampRolloverStream,a.adtsStream=new T,a.h264Stream=new Ke,a.captionStream=new Ee.CaptionStream(t),a.coalesceStream=new je(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(r){var s;if("metadata"===r.type){for(s=r.tracks.length;s--;)e||"video"!==r.tracks[s].type?i||"audio"!==r.tracks[s].type||((i=r.tracks[s]).timelineStartInfo.baseMediaDecodeTime=n.baseMediaDecodeTime):(e=r.tracks[s]).timelineStartInfo.baseMediaDecodeTime=n.baseMediaDecodeTime;e&&!a.videoSegmentStream&&(a.coalesceStream.numberOfTracks++,a.videoSegmentStream=new Ve(e,t),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 Ge(i,t),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,Xt(i),a.audioTimestampRolloverStream&&a.audioTimestampRolloverStream.discontinuity()),e&&(a.videoSegmentStream&&(a.videoSegmentStream.gopCache_=[]),e.timelineStartInfo.dts=void 0,e.timelineStartInfo.pts=void 0,Xt(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.push=function(t){if(a){var e=Xe(t);e&&"aac"!==this.transmuxPipeline_.type?this.setupAacPipeline():e||"ts"===this.transmuxPipeline_.type||this.setupTsPipeline(),a=!1}this.transmuxPipeline_.headOfPipeline.push(t)},this.flush=function(){a=!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()}}).prototype=new d;var Qe,ti={Transmuxer:We,VideoSegmentStream:Ve,AudioSegmentStream:Ge,AUDIO_PROPERTIES:He,VIDEO_PROPERTIES:qe,generateSegmentTimingInfo:Je},ei=ee,ii=fe.CaptionStream,ni=function(t,e){for(var i=t,n=0;n0?Ct(h[0]).baseMediaDecodeTime:0,u=wt(r,["trun"]);e===d&&u.length>0&&(i=function(t,e,i){var n,a,r,s,o=new DataView(t.buffer,t.byteOffset,t.byteLength),d=[];for(a=0;a+40;){var d=e.shift();this.parse(d,r,s)}return null!==(o=function(t,e,i){return null===e?null:{seiNals:ai(t,e)[e],timescale:i}}(t,i,n))&&o.seiNals?(this.pushNals(o.seiNals),this.flushStream(),a):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;r?t.partialFlush():t.flush()},this.clearParsedCaptions=function(){a.captions=[],a.captionStreams={}},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:{}},this.resetCaptionStream()},this.reset()}};(Qe=function(t,e){var i,n=0,a=16384,r=function(t,e){var i,n=t.position+e;n0)throw new Error("Attempted to create new NAL wihout closing the old one");n=this.length,this.length+=4,this.position=this.length},this.endNalUnit=function(t){var e,i;this.length===n+4?this.length-=4:n>0&&(e=n+4,i=this.length-e,this.position=n,this.view.setUint32(this.position,i),this.position=this.length,t&&t.push(this.bytes.subarray(e,e+i))),n=0},this.writeMetaDataDouble=function(t,e){var i;if(r(this,2+t.length+9),this.view.setUint16(this.position,t.length),this.position+=2,"width"===t)this.bytes.set(s,this.position),this.position+=5;else if("height"===t)this.bytes.set(o,this.position),this.position+=6;else if("videocodecid"===t)this.bytes.set(d,this.position),this.position+=12;else for(i=0;i>>16,this.bytes[14]=(65280&t)>>>8,this.bytes[15]=(255&t)>>>0;break;case Qe.AUDIO_TAG:this.bytes[11]=175,this.bytes[12]=e?0:1;break;case Qe.METADATA_TAG:this.position=11,this.view.setUint8(this.position,2),this.position++,this.view.setUint16(this.position,10),this.position+=2,this.bytes.set([111,110,77,101,116,97,68,97,116,97],this.position),this.position+=10,this.bytes[this.position]=8,this.position++,this.view.setUint32(this.position,n),this.position=this.length,this.bytes.set([0,0,9],this.position),this.position+=3,this.length=this.position}return i=this.length-11,this.bytes[1]=(16711680&i)>>>16,this.bytes[2]=(65280&i)>>>8,this.bytes[3]=(255&i)>>>0,this.bytes[4]=(16711680&this.dts)>>>16,this.bytes[5]=(65280&this.dts)>>>8,this.bytes[6]=(255&this.dts)>>>0,this.bytes[7]=(4278190080&this.dts)>>>24,this.bytes[8]=0,this.bytes[9]=0,this.bytes[10]=0,r(this,4),this.view.setUint32(this.length,this.length),this.length+=4,this.position+=4,this.bytes=this.bytes.subarray(0,this.length),this.frameTime=Qe.frameTime(this.bytes),this}}).AUDIO_TAG=8,Qe.VIDEO_TAG=9,Qe.METADATA_TAG=18,Qe.isAudioFrame=function(t){return Qe.AUDIO_TAG===t[0]},Qe.isVideoFrame=function(t){return Qe.VIDEO_TAG===t[0]},Qe.isMetaData=function(t){return Qe.METADATA_TAG===t[0]},Qe.isKeyFrame=function(t){return Qe.isVideoFrame(t)?23===t[11]:!!Qe.isAudioFrame(t)||!!Qe.isMetaData(t)},Qe.frameTime=function(t){var e=t[4]<<16;return e|=t[5]<<8,e|=t[6]<<0,e|=t[7]<<24};var si=Qe,oi=function t(e){this.numberOfTracks=0,this.metadataStream=e.metadataStream,this.videoTags=[],this.audioTags=[],this.videoTrack=null,this.audioTrack=null,this.pendingCaptions=[],this.pendingMetadata=[],this.pendingTracks=0,this.processedTracks=0,t.prototype.init.call(this),this.push=function(t){return t.text?this.pendingCaptions.push(t):t.frames?this.pendingMetadata.push(t):("video"===t.track.type&&(this.videoTrack=t.track,this.videoTags=t.tags,this.pendingTracks++),void("audio"===t.track.type&&(this.audioTrack=t.track,this.audioTags=t.tags,this.pendingTracks++)))}};(oi.prototype=new d).flush=function(t){var e,i,n,a,r={tags:{},captions:[],captionStreams:{},metadata:[]};if(this.pendingTracks=n[0]&&(s=n.shift(),this.writeMetaDataTags(o,s)),(t.extraData!==e||a.pts-s>=1e3)&&(this.writeMetaDataTags(o,a.pts),e=t.extraData,s=a.pts),(r=new si(si.AUDIO_TAG)).pts=a.pts,r.dts=a.dts,r.writeBytes(a.data),o.push(r.finalize());n.length=0,e=null,this.trigger("data",{track:t,tags:o.list}),this.trigger("done","AudioSegmentStream")}else this.trigger("done","AudioSegmentStream")},this.writeMetaDataTags=function(e,i){var n;(n=new si(si.METADATA_TAG)).pts=i,n.dts=i,n.writeMetaDataDouble("audiocodecid",10),n.writeMetaDataBoolean("stereo",2===t.channelcount),n.writeMetaDataDouble("audiosamplerate",t.samplerate),n.writeMetaDataDouble("audiosamplesize",16),e.push(n.finalize()),(n=new si(si.AUDIO_TAG,!0)).pts=i,n.dts=i,n.view.setUint16(n.position,t.extraData),n.position+=2,n.length=Math.max(n.length,n.position),e.push(n.finalize())},this.onVideoKeyFrame=function(t){n.push(t)}}).prototype=new d,(hi=function(t){var e,i,n=[];hi.prototype.init.call(this),this.finishFrame=function(n,a){if(a){if(e&&t&&t.newMetadata&&(a.keyFrame||0===n.length)){var r=li(e,a.dts).finalize(),s=ci(t,a.dts).finalize();r.metaDataTag=s.metaDataTag=!0,n.push(r),n.push(s),t.newMetadata=!1,this.trigger("keyframe",a.dts)}a.endNalUnit(),n.push(a.finalize()),i=null}},this.push=function(e){ui(t,e),e.pts=Math.round(e.pts/90),e.dts=Math.round(e.dts/90),n.push(e)},this.flush=function(){for(var a,r=new mi;n.length&&"access_unit_delimiter_rbsp"!==n[0].nalUnitType;)n.shift();if(0!==n.length){for(;n.length;)"seq_parameter_set_rbsp"===(a=n.shift()).nalUnitType?(t.newMetadata=!0,e=a.config,t.width=e.width,t.height=e.height,t.sps=[a.data],t.profileIdc=e.profileIdc,t.levelIdc=e.levelIdc,t.profileCompatibility=e.profileCompatibility,i.endNalUnit()):"pic_parameter_set_rbsp"===a.nalUnitType?(t.newMetadata=!0,t.pps=[a.data],i.endNalUnit()):"access_unit_delimiter_rbsp"===a.nalUnitType?(i&&this.finishFrame(r,i),(i=new si(si.VIDEO_TAG)).pts=a.pts,i.dts=a.dts):("slice_layer_without_partitioning_rbsp_idr"===a.nalUnitType&&(i.keyFrame=!0),i.endNalUnit()),i.startNalUnit(),i.writeBytes(a.data);i&&this.finishFrame(r,i),this.trigger("data",{track:t,tags:r.list}),this.trigger("done","VideoSegmentStream")}else this.trigger("done","VideoSegmentStream")}}).prototype=new d,(di=function(t){var e,i,n,a,r,s,o,d,h,p,u,l,c=this;di.prototype.init.call(this),t=t||{},this.metadataStream=new Ee.MetadataStream,t.metadataStream=this.metadataStream,e=new Ee.TransportPacketStream,i=new Ee.TransportParseStream,n=new Ee.ElementaryStream,a=new Ee.TimestampRolloverStream("video"),r=new Ee.TimestampRolloverStream("audio"),s=new Ee.TimestampRolloverStream("timed-metadata"),o=new T,d=new gi,l=new fi(t),e.pipe(i).pipe(n),n.pipe(a).pipe(d),n.pipe(r).pipe(o),n.pipe(s).pipe(this.metadataStream).pipe(l),u=new Ee.CaptionStream(t),d.pipe(u).pipe(l),n.on("data",(function(t){var e,i,n;if("metadata"===t.type){for(e=t.tracks.length;e--;)"video"===t.tracks[e].type?i=t.tracks[e]:"audio"===t.tracks[e].type&&(n=t.tracks[e]);i&&!h&&(l.numberOfTracks++,h=new hi(i),d.pipe(h).pipe(l)),n&&!p&&(l.numberOfTracks++,p=new pi(n),o.pipe(p).pipe(l),h&&h.on("keyframe",p.onVideoKeyFrame))}})),this.push=function(t){e.push(t)},this.flush=function(){e.flush()},this.resetCaptions=function(){u.reset()},l.on("data",(function(t){c.trigger("data",t)})),l.on("done",(function(){c.trigger("done")}))}).prototype=new d;var yi=function(t,e,i){var n,a,r,s=new Uint8Array(9),o=new DataView(s.buffer);return t=t||0,e=void 0===e||e,i=void 0===i||i,o.setUint8(0,70),o.setUint8(1,76),o.setUint8(2,86),o.setUint8(3,1),o.setUint8(4,(e?4:0)|(i?1:0)),o.setUint32(5,s.byteLength),t<=0?((a=new Uint8Array(s.byteLength+4)).set(s),a.set([0,0,0,0],s.byteLength),a):((n=new si(si.METADATA_TAG)).pts=n.dts=0,n.writeMetaDataDouble("duration",t),r=n.finalize().length,(a=new Uint8Array(s.byteLength+r)).set(s),a.set(o.byteLength,r),a)},bi={tag:si,Transmuxer:di,getFlvHeader:yi},vi=Ee,Si=u,Ti=function t(e,i){var n=[],a=0,r=0,s=0,o=1/0,d=null,h=null;i=i||{},t.prototype.init.call(this),this.push=function(t){$t(e,t),e&&He.forEach((function(i){e[i]=t[i]})),n.push(t)},this.setEarliestDts=function(t){r=t},this.setVideoBaseMediaDecodeTime=function(t){o=t},this.setAudioAppendStart=function(t){s=t},this.processFrames_=function(){var t,p,u,l,c;0!==n.length&&0!==(t=Yt(n,e,r)).length&&(e.baseMediaDecodeTime=Zt(e,i.keepOriginalTimestamps),jt(e,t,s,o),e.samples=Ht(t),u=bt.mdat(qt(t)),n=[],p=bt.moof(a,[e]),a++,e.initSegment=bt.initSegment([e]),(l=new Uint8Array(p.byteLength+u.byteLength)).set(p),l.set(u,p.byteLength),Xt(e),null===d&&(h=d=t[0].pts),h+=t.length*(1024*Si/e.samplerate),c={start:d},this.trigger("timingInfo",c),this.trigger("data",{track:e,boxes:l}))},this.flush=function(){this.processFrames_(),this.trigger("timingInfo",{start:d,end:h}),this.resetTiming_(),this.trigger("done","AudioSegmentStream")},this.partialFlush=function(){this.processFrames_(),this.trigger("partialdone","AudioSegmentStream")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline","AudioSegmentStream")},this.resetTiming_=function(){Xt(e),d=null,h=null},this.reset=function(){this.resetTiming_(),n=[],this.trigger("reset")}};Ti.prototype=new d;var wi=Ti,_i=function t(e,i){var n,a,r,s=0,o=[],d=[],h=null,p=null,u=!0;i=i||{},t.prototype.init.call(this),this.push=function(t){$t(e,t),void 0===e.timelineStartInfo.dts&&(e.timelineStartInfo.dts=t.dts),"seq_parameter_set_rbsp"!==t.nalUnitType||n||(n=t.config,e.sps=[t.data],qe.forEach((function(t){e[t]=n[t]}),this)),"pic_parameter_set_rbsp"!==t.nalUnitType||a||(a=t.data,e.pps=[t.data]),o.push(t)},this.processNals_=function(t){var n;for(o=d.concat(o);o.length&&"access_unit_delimiter_rbsp"!==o[0].nalUnitType;)o.shift();if(0!==o.length){var a=Mt(o);if(a.length)if(d=a[a.length-1],t&&(a.pop(),a.duration-=d.duration,a.nalCount-=d.length,a.byteLength-=d.byteLength),a.length){if(this.trigger("timelineStartInfo",e.timelineStartInfo),u){if(!(r=xt(a))[0][0].keyFrame){if(!(r=Et(r))[0][0].keyFrame)return o=[].concat.apply([],a).concat(d),void(d=[]);(a=[].concat.apply([],r)).duration=r.duration}u=!1}for(null===h&&(h=a[0].pts,p=h),p+=a.duration,this.trigger("timingInfo",{start:h,end:p}),n=0;n0;n+=12,a--)i.references.push({referenceType:(128&t[n])>>>7,referencedSize:2147483647&e.getUint32(n),subsegmentDuration:e.getUint32(n+4),startsWithSap:!!(128&t[n+8]),sapType:(112&t[n+8])>>>4,sapDeltaTime:268435455&e.getUint32(n+8)});return i},xi=Math.pow(2,32),Ei=function(t){return new Date(1e3*t-20828448e5)},Ri=function(t){var e,i,n=new DataView(t.buffer,t.byteOffset,t.byteLength),a=[];for(e=0;e+4MALFORMED DATA");else switch(31&t[e]){case 1:a.push("slice_layer_without_partitioning_rbsp");break;case 5:a.push("slice_layer_without_partitioning_rbsp_idr");break;case 6:a.push("sei_rbsp");break;case 7:a.push("seq_parameter_set_rbsp");break;case 8:a.push("pic_parameter_set_rbsp");break;case 9:a.push("access_unit_delimiter_rbsp");break;default:a.push("UNKNOWN NAL - "+t[e]&31)}return a},Bi={avc1:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{dataReferenceIndex:e.getUint16(6),width:e.getUint16(24),height:e.getUint16(26),horizresolution:e.getUint16(28)+e.getUint16(30)/16,vertresolution:e.getUint16(32)+e.getUint16(34)/16,frameCount:e.getUint16(40),depth:e.getUint16(74),config:Pi(t.subarray(78,t.byteLength))}},avcC:function(t){var e,i,n,a,r=new DataView(t.buffer,t.byteOffset,t.byteLength),s={configurationVersion:t[0],avcProfileIndication:t[1],profileCompatibility:t[2],avcLevelIndication:t[3],lengthSizeMinusOne:3&t[4],sps:[],pps:[]},o=31&t[5];for(n=6,a=0;a>>2&63,bufferSize:t[13]<<16|t[14]<<8|t[15],maxBitrate:t[16]<<24|t[17]<<16|t[18]<<8|t[19],avgBitrate:t[20]<<24|t[21]<<16|t[22]<<8|t[23],decoderConfigDescriptor:{tag:t[24],length:t[25],audioObjectType:t[26]>>>3&31,samplingFrequencyIndex:(7&t[26])<<1|t[27]>>>7&1,channelConfiguration:t[27]>>>3&15}}}},ftyp:function(t){for(var e=new DataView(t.buffer,t.byteOffset,t.byteLength),i={majorBrand:St(t.subarray(0,4)),minorVersion:e.getUint32(4),compatibleBrands:[]},n=8;n>10)),a.language+=String.fromCharCode(96+((992&e)>>5)),a.language+=String.fromCharCode(96+(31&e)),a},mdia:function(t){return{boxes:Pi(t)}},mfhd:function(t){return{version:t[0],flags:new Uint8Array(t.subarray(1,4)),sequenceNumber:t[4]<<24|t[5]<<16|t[6]<<8|t[7]}},minf:function(t){return{boxes:Pi(t)}},mp4a:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength),i={dataReferenceIndex:e.getUint16(6),channelcount:e.getUint16(16),samplesize:e.getUint16(18),samplerate:e.getUint16(24)+e.getUint16(26)/65536};return t.byteLength>28&&(i.streamDescriptor=Pi(t.subarray(28))[0]),i},moof:function(t){return{boxes:Pi(t)}},moov:function(t){return{boxes:Pi(t)}},mvex:function(t){return{boxes:Pi(t)}},mvhd:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength),i=4,n={version:e.getUint8(0),flags:new Uint8Array(t.subarray(1,4))};return 1===n.version?(i+=4,n.creationTime=Ei(e.getUint32(i)),i+=8,n.modificationTime=Ei(e.getUint32(i)),i+=4,n.timescale=e.getUint32(i),i+=8,n.duration=e.getUint32(i)):(n.creationTime=Ei(e.getUint32(i)),i+=4,n.modificationTime=Ei(e.getUint32(i)),i+=4,n.timescale=e.getUint32(i),i+=4,n.duration=e.getUint32(i)),i+=4,n.rate=e.getUint16(i)+e.getUint16(i+2)/16,i+=4,n.volume=e.getUint8(i)+e.getUint8(i+1)/8,i+=2,i+=2,i+=8,n.matrix=new Uint32Array(t.subarray(i,i+36)),i+=36,i+=24,n.nextTrackId=e.getUint32(i),n},pdin:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{version:e.getUint8(0),flags:new Uint8Array(t.subarray(1,4)),rate:e.getUint32(4),initialDelay:e.getUint32(8)}},sdtp:function(t){var e,i={version:t[0],flags:new Uint8Array(t.subarray(1,4)),samples:[]};for(e=4;e>4,isDependedOn:(12&t[e])>>2,hasRedundancy:3&t[e]});return i},sidx:Mi,smhd:function(t){return{version:t[0],flags:new Uint8Array(t.subarray(1,4)),balance:t[4]+t[5]/256}},stbl:function(t){return{boxes:Pi(t)}},stco:function(t){var e,i=new DataView(t.buffer,t.byteOffset,t.byteLength),n={version:t[0],flags:new Uint8Array(t.subarray(1,4)),chunkOffsets:[]},a=i.getUint32(4);for(e=8;a;e+=4,a--)n.chunkOffsets.push(i.getUint32(e));return n},stsc:function(t){var e,i=new DataView(t.buffer,t.byteOffset,t.byteLength),n=i.getUint32(4),a={version:t[0],flags:new Uint8Array(t.subarray(1,4)),sampleToChunks:[]};for(e=8;n;e+=12,n--)a.sampleToChunks.push({firstChunk:i.getUint32(e),samplesPerChunk:i.getUint32(e+4),sampleDescriptionIndex:i.getUint32(e+8)});return a},stsd:function(t){return{version:t[0],flags:new Uint8Array(t.subarray(1,4)),sampleDescriptions:Pi(t.subarray(8))}},stsz:function(t){var e,i=new DataView(t.buffer,t.byteOffset,t.byteLength),n={version:t[0],flags:new Uint8Array(t.subarray(1,4)),sampleSize:i.getUint32(4),entries:[]};for(e=12;e>6,sampleHasRedundancy:(48&t[21])>>4,samplePaddingValue:(14&t[21])>>1,sampleIsDifferenceSample:!!(1&t[21]),sampleDegradationPriority:e.getUint16(22)}},trun:Ut,"url ":function(t){return{version:t[0],flags:new Uint8Array(t.subarray(1,4))}},vmhd:function(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);return{version:t[0],flags:new Uint8Array(t.subarray(1,4)),graphicsmode:e.getUint16(4),opcolor:new Uint16Array([e.getUint16(6),e.getUint16(8),e.getUint16(10)])}}},zi={inspect:Pi=function(t){for(var e,i,n,a,r,s=0,o=[],d=new ArrayBuffer(t.length),h=new Uint8Array(d),p=0;p1?s+i:t.byteLength,(r=(Bi[n]||function(t){return{data:t}})(t.subarray(s+8,a))).size=i,r.type=n,o.push(r),s=a;return o},textify:Li=function(t,e){var i;return e=e||0,i=new Array(2*e+1).join(" "),t.map((function(t,n){return i+t.type+"\n"+Object.keys(t).filter((function(t){return"type"!==t&&"boxes"!==t})).map((function(e){var n=i+" "+e+": ",a=t[e];if(a instanceof Uint8Array||a instanceof Uint32Array){var r=Array.prototype.slice.call(new Uint8Array(a.buffer,a.byteOffset,a.byteLength)).map((function(t){return" "+("00"+t.toString(16)).slice(-2)})).join("").match(/.{1,24}/g);return r?1===r.length?n+"<"+r.join("").slice(1)+">":n+"<\n"+r.map((function(t){return i+" "+t})).join("\n")+"\n"+i+" >":n+"<>"}return n+JSON.stringify(a,null,2).split("\n").map((function(t,e){return 0===e?t:i+" "+t})).join("\n")})).join("\n")+(t.boxes?"\n"+Li(t.boxes,e+1):"")})).join("\n")},parseType:St,findBox:wt,parseTraf:Bi.traf,parseTfdt:Bi.tfdt,parseHdlr:Bi.hdlr,parseTfhd:Bi.tfhd,parseTrun:Bi.trun,parseSidx:Bi.sidx},Fi={8:"audio",9:"video",18:"metadata"},Ni=function(t){for(var e,i=[];t.byteLength>0;)e=0,i.push("0x"+("00"+t[e++].toString(16)).slice(-2).toUpperCase()),t=t.subarray(1);return i.join(" ")},Vi=function(t,e){var i=t[0]&parseInt("00001111",2);return(e=e||{}).frameType=["Unknown","Keyframe (for AVC, a seekable frame)","Inter frame (for AVC, a nonseekable frame)","Disposable inter frame (H.263 only)","Generated keyframe (reserved for server use only)","Video info/command frame"][(t[0]&parseInt("11110000",2))>>>4],e.codecID=i,7===i?function(t,e){var i=t[1]&parseInt("01111111",2)<<16|t[2]<<8|t[3];return(e=e||{}).avcPacketType=["AVC Sequence Header","AVC NALU","AVC End-of-Sequence"][t[0]],e.CompositionTime=t[1]&parseInt("10000000",2)?-i:i,1===t[0]?e.nalUnitTypeRaw=Ni(t.subarray(4,100)):e.data=Ni(t.subarray(4)),e}(t.subarray(1),e):e},Gi=function(t,e){var i=(t[0]&parseInt("11110000",2))>>>4;return(e=e||{}).soundFormat=["Linear PCM, platform endian","ADPCM","MP3","Linear PCM, little endian","Nellymoser 16-kHz mono","Nellymoser 8-kHz mono","Nellymoser","G.711 A-law logarithmic PCM","G.711 mu-law logarithmic PCM","reserved","AAC","Speex","MP3 8-Khz","Device-specific sound"][i],e.soundRate=["5.5-kHz","11-kHz","22-kHz","44-kHz"][(t[0]&parseInt("00001100",2))>>>2],e.soundSize=(t[0]&parseInt("00000010",2))>>>1?"16-bit":"8-bit",e.soundType=t[0]&parseInt("00000001",2)?"Stereo":"Mono",10===i?function(t,e){return(e=e||{}).aacPacketType=["AAC Sequence Header","AAC Raw"][t[0]],e.data=Ni(t.subarray(1)),e}(t.subarray(1),e):e},Wi=function(t){var e=function(t){return{tagType:Fi[t[0]],dataSize:t[1]<<16|t[2]<<8|t[3],timestamp:t[7]<<24|t[4]<<16|t[5]<<8|t[6],streamID:t[8]<<16|t[9]<<8|t[10]}}(t);switch(t[0]){case 8:Gi(t.subarray(11),e);break;case 9:Vi(t.subarray(11),e)}return e},ji={inspectTag:Wi,inspect:function(t){var e,i,n=9,a=[];for(n+=4;n>>4>1&&(e+=t[4]+1),e},Ki=function(t){switch(t){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}},Xi={parseType:function(t,e){var i=Yi(t);return 0===i?"pat":i===e?"pmt":e?"pes":null},parsePat:function(t){var e=Hi(t),i=4+qi(t);return e&&(i+=t[i]+1),(31&t[i+10])<<8|t[i+11]},parsePmt:function(t){var e={},i=Hi(t),n=4+qi(t);if(i&&(n+=t[n]+1),1&t[n+5]){var a;a=3+((15&t[n+1])<<8|t[n+2])-4;for(var r=12+((15&t[n+10])<<8|t[n+11]);r=t.byteLength)return null;var i,n=null;return 192&(i=t[e+7])&&((n={}).pts=(14&t[e+9])<<27|(255&t[e+10])<<20|(254&t[e+11])<<12|(255&t[e+12])<<5|(254&t[e+13])>>>3,n.pts*=4,n.pts+=(6&t[e+13])>>>1,n.dts=n.pts,64&i&&(n.dts=(14&t[e+14])<<27|(255&t[e+15])<<20|(254&t[e+16])<<12|(255&t[e+17])<<5|(254&t[e+18])>>>3,n.dts*=4,n.dts+=(6&t[e+18])>>>1)),n},videoPacketContainsKeyFrame:function(t){for(var e=4+qi(t),i=t.subarray(e),n=0,a=0,r=!1;a3&&"slice_layer_without_partitioning_rbsp_idr"===Ki(31&i[a+3])&&(r=!0),r}},Zi=Te,$i={};$i.ts=Xi,$i.aac=Ne;var Ji=u,Qi=188,tn=71,en=function(t,e,i){for(var n,a,r,s,o=0,d=Qi,h=!1;d<=t.byteLength;)if(t[o]!==tn||t[d]!==tn&&d!==t.byteLength)o++,d++;else{switch(n=t.subarray(o,d),$i.ts.parseType(n,e.pid)){case"pes":a=$i.ts.parsePesType(n,e.table),r=$i.ts.parsePayloadUnitStartIndicator(n),"audio"===a&&r&&(s=$i.ts.parsePesTime(n))&&(s.type="audio",i.audio.push(s),h=!0)}if(h)break;o+=Qi,d+=Qi}for(o=(d=t.byteLength)-Qi,h=!1;o>=0;)if(t[o]!==tn||t[d]!==tn&&d!==t.byteLength)o--,d--;else{switch(n=t.subarray(o,d),$i.ts.parseType(n,e.pid)){case"pes":a=$i.ts.parsePesType(n,e.table),r=$i.ts.parsePayloadUnitStartIndicator(n),"audio"===a&&r&&(s=$i.ts.parsePesTime(n))&&(s.type="audio",i.audio.push(s),h=!0)}if(h)break;o-=Qi,d-=Qi}},nn=function(t,e,i){for(var n,a,r,s,o,d,h,p=0,u=Qi,l=!1,c={data:[],size:0};u=0;)if(t[p]!==tn||t[u]!==tn)p--,u--;else{switch(n=t.subarray(p,u),$i.ts.parseType(n,e.pid)){case"pes":a=$i.ts.parsePesType(n,e.table),r=$i.ts.parsePayloadUnitStartIndicator(n),"video"===a&&r&&(s=$i.ts.parsePesTime(n))&&(s.type="video",i.video.push(s),l=!0)}if(l)break;p-=Qi,u-=Qi}},an=function(t){var e={pid:null,table:null},i={};for(var n in function(t,e){for(var i,n=0,a=Qi;a=3;){switch($i.aac.parseType(t,o)){case"timed-metadata":if(t.length-o<10){i=!0;break}if((s=$i.aac.parseId3TagSize(t,o))>t.length){i=!0;break}null===r&&(e=t.subarray(o,o+s),r=$i.aac.parseAacTimestamp(e)),o+=s;break;case"audio":if(t.length-o<7){i=!0;break}if((s=$i.aac.parseAdtsSize(t,o))>t.length){i=!0;break}null===a&&(e=t.subarray(o,o+s),a=$i.aac.parseSampleRate(e)),n++,o+=s;break;default:o++}if(i)return null}if(null===a||null===r)return null;var d=Ji/a;return{audio:[{type:"audio",dts:r,pts:r},{type:"audio",dts:r+1024*n*d,pts:r+1024*n*d}]}}(t):an(t))&&(i.audio||i.video)?(function(t,e){if(t.audio&&t.audio.length){var i=e;(void 0===i||isNaN(i))&&(i=t.audio[0].dts),t.audio.forEach((function(t){t.dts=Zi(t.dts,i),t.pts=Zi(t.pts,i),t.dtsTime=t.dts/Ji,t.ptsTime=t.pts/Ji}))}if(t.video&&t.video.length){var n=e;if((void 0===n||isNaN(n))&&(n=t.video[0].dts),t.video.forEach((function(t){t.dts=Zi(t.dts,n),t.pts=Zi(t.pts,n),t.dtsTime=t.dts/Ji,t.ptsTime=t.pts/Ji})),t.firstKeyFrame){var a=t.firstKeyFrame;a.dts=Zi(a.dts,n),a.pts=Zi(a.pts,n),a.dtsTime=a.dts/Ji,a.ptsTime=a.pts/Ji}}}(i,e),i):null},parseAudioPes_:en},sn={codecs:pt,mp4:ri,flv:bi,mp2t:vi,partial:Oi};return sn.mp4.tools=zi,sn.flv.tools=ji,sn.mp2t.tools=rn,sn}));
diff --git a/src/JT1078.FMp4.Test/JT1078ToFMp4Box_Test.cs b/src/JT1078.FMp4.Test/JT1078ToFMp4Box_Test.cs
index 3b8e92a..a95aca2 100644
--- a/src/JT1078.FMp4.Test/JT1078ToFMp4Box_Test.cs
+++ b/src/JT1078.FMp4.Test/JT1078ToFMp4Box_Test.cs
@@ -482,53 +482,6 @@ namespace JT1078.FMp4.Test
fileStream.Close();
}
- [Fact]
- public void Test5()
- {
- FMp4Encoder fMp4Encoder = new FMp4Encoder();
- H264Decoder h264Decoder = new H264Decoder();
- var packages = ParseNALUTests();
- var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "H264", "JT1078_6.mp4");
- if (File.Exists(filepath))
- {
- File.Delete(filepath);
- }
- using var fileStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);
-
- var ftyp = fMp4Encoder.EncoderFtypBox();
- fileStream.Write(ftyp);
-
- var iNalus = h264Decoder.ParseNALU(packages[0]);
- //判断第一帧是否关键帧
- var moov = fMp4Encoder.EncoderMoovBox(
- iNalus.FirstOrDefault(f => f.NALUHeader.NalUnitType == NalUnitType.SPS),
- iNalus.FirstOrDefault(f => f.NALUHeader.NalUnitType == NalUnitType.PPS));
- fileStream.Write(moov);
-
- List nalus = new List();
- foreach (var package in packages)
- {
- List h264NALUs = h264Decoder.ParseNALU(package);
- if(package.Label3.DataType== Protocol.Enums.JT1078DataType.视频I帧)
- {
- if (nalus.Count > 0)
- {
- var otherBuffer = fMp4Encoder.EncoderOtherVideoBox(nalus);
- fileStream.Write(otherBuffer);
- nalus.Clear();
- }
- }
- nalus = nalus.Concat(h264NALUs).ToList();
- }
- if (nalus.Count > 0)
- {
- var otherBuffer = fMp4Encoder.EncoderOtherVideoBox(nalus);
- fileStream.Write(otherBuffer);
- nalus.Clear();
- }
- fileStream.Close();
- }
-
[Fact]
public void tkhd_width_height_test()
{
diff --git a/src/JT1078.FMp4/FMp4Encoder.cs b/src/JT1078.FMp4/FMp4Encoder.cs
index a92b370..08840dc 100644
--- a/src/JT1078.FMp4/FMp4Encoder.cs
+++ b/src/JT1078.FMp4/FMp4Encoder.cs
@@ -30,6 +30,24 @@ namespace JT1078.FMp4
///
public class FMp4Encoder
{
+ Dictionary TrackInfos;
+
+ const uint DefaultSampleDuration = 48000u;
+ const uint DefaultSampleFlags = 0x1010000;
+ const uint FirstSampleFlags = 33554432;
+ const uint TfhdFlags = 0x2003a;
+ const uint TrunFlags = 0x205;
+ const uint SampleDescriptionIndex = 1;
+ const uint TrackID = 1;
+
+ ///
+ ///
+ ///
+ public FMp4Encoder()
+ {
+ TrackInfos = new Dictionary(StringComparer.OrdinalIgnoreCase);
+ }
+
///
/// 编码ftyp盒子
///
@@ -66,7 +84,7 @@ namespace JT1078.FMp4
///
public byte[] EncoderMoovBox(in H264NALU sps, in H264NALU pps)
{
- byte[] buffer = FMp4ArrayPool.Rent(sps.RawData.Length+ pps.RawData.Length + 1024);
+ byte[] buffer = FMp4ArrayPool.Rent(sps.RawData.Length + pps.RawData.Length + 1024);
FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);
try
{
@@ -84,7 +102,7 @@ namespace JT1078.FMp4
movieBox.TrackBox.TrackHeaderBox = new TrackHeaderBox(0, 3);
movieBox.TrackBox.TrackHeaderBox.CreationTime = 0;
movieBox.TrackBox.TrackHeaderBox.ModificationTime = 0;
- movieBox.TrackBox.TrackHeaderBox.TrackID = 1;
+ movieBox.TrackBox.TrackHeaderBox.TrackID = TrackID;
movieBox.TrackBox.TrackHeaderBox.Duration = 0;
movieBox.TrackBox.TrackHeaderBox.TrackIsAudio = false;
movieBox.TrackBox.TrackHeaderBox.Width = (uint)spsInfo.width;
@@ -126,8 +144,8 @@ namespace JT1078.FMp4
movieBox.MovieExtendsBox = new MovieExtendsBox();
movieBox.MovieExtendsBox.TrackExtendsBoxs = new List();
TrackExtendsBox trex = new TrackExtendsBox();
- trex.TrackID = 1;
- trex.DefaultSampleDescriptionIndex = 1;
+ trex.TrackID = TrackID;
+ trex.DefaultSampleDescriptionIndex = SampleDescriptionIndex;
trex.DefaultSampleDuration = 0;
trex.DefaultSampleSize = 0;
trex.DefaultSampleFlags = 0;
@@ -142,13 +160,11 @@ namespace JT1078.FMp4
}
}
- uint sn = 1;
-
///
/// 编码其他视频数据盒子
///
///
- public byte[] EncoderOtherVideoBox(List nalus)
+ public byte[] EncoderOtherVideoBox(in List nalus)
{
byte[] buffer = FMp4ArrayPool.Rent(nalus.Sum(s => s.RawData.Length + s.StartCodePrefix.Length) + 4096);
FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);
@@ -158,9 +174,14 @@ namespace JT1078.FMp4
List rawdatas = new List();
uint iSize = 0;
ulong lastTimestamp = 0;
- for (var i=0; i
- /// 编码其他视频数据盒子
- ///
- ///
- public byte[] EncoderOtherVideoBox(List nalus,Listsamples, List sampleSizes,uint firstSize,ulong lastTimestamp)
+ struct TrackInfo
{
- byte[] buffer = FMp4ArrayPool.Rent(nalus.Sum(s => s.RawData.Length + s.StartCodePrefix.Length) + 4096);
- FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);
- try
- {
- var lastNalu = nalus.Last();
- int iSize = nalus.Where(w => w.DataType == Protocol.Enums.JT1078DataType.视频I帧)
- .Sum(s => s.RawData.Length + s.StartCodePrefix.Length);
- List sizes = new List();
- sizes.Add(iSize);
- sizes = sizes.Concat(nalus.Where(w => w.DataType != Protocol.Enums.JT1078DataType.视频I帧)
- .Select(s => s.RawData.Length + s.StartCodePrefix.Length).ToList())
- .ToList();
-
- var movieFragmentBox = new MovieFragmentBox();
- movieFragmentBox.MovieFragmentHeaderBox = new MovieFragmentHeaderBox();
- movieFragmentBox.MovieFragmentHeaderBox.SequenceNumber = sn++;
- movieFragmentBox.TrackFragmentBox = new TrackFragmentBox();
- movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox = new TrackFragmentHeaderBox(0x2003a);
- movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.TrackID = 1;
- movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.SampleDescriptionIndex = 1;
- movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleDuration = 48000;
- movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleSize = firstSize;
- movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleFlags = 0x1010000;
- movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox = new TrackFragmentBaseMediaDecodeTimeBox();
- movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox.BaseMediaDecodeTime = lastTimestamp * 1000;
-
- //trun
- movieFragmentBox.TrackFragmentBox.TrackRunBox = new TrackRunBox(flags: 0x205);
- movieFragmentBox.TrackFragmentBox.TrackRunBox.FirstSampleFlags = 33554432;
- movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos = new List();
-
- foreach (var size in sizes)
- {
- movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos.Add(new TrackRunBox.TrackRunInfo()
- {
- SampleSize = (uint)size,
- });
- }
-
- movieFragmentBox.ToBuffer(ref writer);
-
- var mediaDataBox = new MediaDataBox();
- mediaDataBox.Data = nalus.Select(s => s.RawData).ToList();
- mediaDataBox.ToBuffer(ref writer);
-
- var data = writer.FlushAndGetArray();
- return data;
- }
- finally
- {
- FMp4ArrayPool.Return(buffer);
- }
+ public uint SN { get; set; }
+ public ulong DTS { get; set; }
}
}
}
diff --git a/src/JT1078.FMp4/JT1078.FMp4.csproj b/src/JT1078.FMp4/JT1078.FMp4.csproj
index ce2e12f..50c5f3a 100644
--- a/src/JT1078.FMp4/JT1078.FMp4.csproj
+++ b/src/JT1078.FMp4/JT1078.FMp4.csproj
@@ -27,9 +27,7 @@
-
-
-
+
diff --git a/src/JT1078.FMp4/JT1078.FMp4.xml b/src/JT1078.FMp4/JT1078.FMp4.xml
index 5be8d78..b8e311b 100644
--- a/src/JT1078.FMp4/JT1078.FMp4.xml
+++ b/src/JT1078.FMp4/JT1078.FMp4.xml
@@ -1320,6 +1320,11 @@
ref: https://www.w3.org/TR/mse-byte-stream-format-isobmff/#movie-fragment-relative-addressing
+
+
+
+
+
编码ftyp盒子
@@ -1332,13 +1337,7 @@
-
-
- 编码其他视频数据盒子
-
-
-
-
+
编码其他视频数据盒子
diff --git a/src/JT1078.Flv/FlvEncoder.cs b/src/JT1078.Flv/FlvEncoder.cs
index ad615e4..dd949e8 100644
--- a/src/JT1078.Flv/FlvEncoder.cs
+++ b/src/JT1078.Flv/FlvEncoder.cs
@@ -40,6 +40,9 @@ namespace JT1078.Flv
readonly H264Decoder h264Decoder;
readonly AudioCodecFactory audioCodecFactory;
//public FlvEncoder(int sampleRate = 8000, int channels = 1, int sampleBit = 16, bool adts = false)
+ ///
+ ///
+ ///
public FlvEncoder()
{
audioCodecFactory = new AudioCodecFactory();
diff --git a/src/JT1078.Flv/JT1078.Flv.xml b/src/JT1078.Flv/JT1078.Flv.xml
index 83158de..6864acb 100644
--- a/src/JT1078.Flv/JT1078.Flv.xml
+++ b/src/JT1078.Flv/JT1078.Flv.xml
@@ -181,6 +181,11 @@
4、第二个参数传true
+
+
+
+
+
编码flv头
diff --git a/src/JT1078.Hls.Test/TS_Package_Test.cs b/src/JT1078.Hls.Test/TS_Package_Test.cs
index 9196cec..3822704 100644
--- a/src/JT1078.Hls.Test/TS_Package_Test.cs
+++ b/src/JT1078.Hls.Test/TS_Package_Test.cs
@@ -90,13 +90,13 @@ namespace JT1078.Hls.Test
JT1078Package fullpackage = JT1078Serializer.Merge(package);
if (fullpackage != null)
{
- var sdt = tSEncoder.CreateSDT(fullpackage);
+ var sdt = tSEncoder.CreateSDT();
string sdtHEX = sdt.ToHexString();
fileStream.Write(sdt);
- var pat = tSEncoder.CreatePAT(fullpackage);
+ var pat = tSEncoder.CreatePAT();
string patHEX = pat.ToHexString();
fileStream.Write(pat);
- var pmt = tSEncoder.CreatePMT(fullpackage);
+ var pmt = tSEncoder.CreatePMT();
fileStream.Write(pmt);
var pes = tSEncoder.CreatePES(fullpackage);
fileStream.Write(pes);
@@ -139,13 +139,13 @@ namespace JT1078.Hls.Test
{
if (isNeedFirstHeadler)
{
- var sdt = tSEncoder.CreateSDT(fullpackage);
+ var sdt = tSEncoder.CreateSDT();
string sdtHEX = sdt.ToHexString();
fileStream.Write(sdt);
- var pat = tSEncoder.CreatePAT(fullpackage);
+ var pat = tSEncoder.CreatePAT();
string patHEX = pat.ToHexString();
fileStream.Write(pat);
- var pmt = tSEncoder.CreatePMT(fullpackage);
+ var pmt = tSEncoder.CreatePMT();
fileStream.Write(pmt);
var pes = tSEncoder.CreatePES(fullpackage, 18888);
fileStream.Write(pes);
diff --git a/src/JT1078.Hls/JT1078.Hls.csproj b/src/JT1078.Hls/JT1078.Hls.csproj
index 9de58b1..27cce66 100644
--- a/src/JT1078.Hls/JT1078.Hls.csproj
+++ b/src/JT1078.Hls/JT1078.Hls.csproj
@@ -14,7 +14,7 @@
https://github.com/SmallChi/JT1078/blob/master/LICENSE
https://github.com/SmallChi/JT1078/blob/master/LICENSE
false
- 1.1.0.0
+ 1.1.0-preview3
false
true
LICENSE
diff --git a/src/JT1078.Hls/JT1078.Hls.xml b/src/JT1078.Hls/JT1078.Hls.xml
index 88ad5a1..5777d92 100644
--- a/src/JT1078.Hls/JT1078.Hls.xml
+++ b/src/JT1078.Hls/JT1078.Hls.xml
@@ -96,6 +96,19 @@
m3u8文件管理
+
+
+
+
+
+
+
+
+
+
+
+
+
生成ts和m3u8文件
@@ -132,6 +145,12 @@
终端号_通道号(用作目录)
文件内容
+
+
+ 添加结束标识
+ 直播流用不到
+
+
停止观看直播时清零数据
@@ -273,6 +292,11 @@
4.PES
+
+
+
+
+
取0x50表示包含PCR或0x40表示不包含PCR
diff --git a/src/JT1078.Hls/M3U8FileManage.cs b/src/JT1078.Hls/M3U8FileManage.cs
index b6d1040..b3604f0 100644
--- a/src/JT1078.Hls/M3U8FileManage.cs
+++ b/src/JT1078.Hls/M3U8FileManage.cs
@@ -19,15 +19,28 @@ namespace JT1078.Hls
public class M3U8FileManage
{
private TSEncoder tSEncoder;
- public readonly M3U8Option m3U8Option;
+ private M3U8Option m3U8Option;
ConcurrentDictionary curTsFileInfoDic = new ConcurrentDictionary();//当前文件信息
ConcurrentDictionary> tsFileInfoQueueDic = new ConcurrentDictionary>();
+ ///
+ ///
+ ///
+ ///
+ public M3U8FileManage(M3U8Option m3U8Option):this(m3U8Option, new TSEncoder())
+ {
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
public M3U8FileManage(M3U8Option m3U8Option, TSEncoder tSEncoder)
{
this.tSEncoder = tSEncoder;
this.m3U8Option = m3U8Option;
}
+
///
/// 生成ts和m3u8文件
///
@@ -35,8 +48,8 @@ namespace JT1078.Hls
public void CreateTsData(JT1078Package jt1078Package)
{
string key = jt1078Package.GetKey();
- string hlsFileDirectory = m3U8Option.HlsFileDirectory;
- string m3u8FileName = Path.Combine(hlsFileDirectory, key, m3U8Option.M3U8FileName);
+ //string hlsFileDirectory = m3U8Option.HlsFileDirectory;
+ //string m3u8FileName = Path.Combine(hlsFileDirectory, key, m3U8Option.M3U8FileName);
var buff = TSArrayPool.Rent(jt1078Package.Bodies.Length + 1024);
TSMessagePackWriter tSMessagePackWriter = new TSMessagePackWriter(buff);
try
@@ -62,11 +75,11 @@ namespace JT1078.Hls
curTsFileInfo.IsCreateTsFile = false;
curTsFileInfo.TsFirst1078PackageTimeStamp = jt1078Package.Timestamp;
curTsFileInfo.FileName = $"{curTsFileInfo.TsFileSerialNo}.ts";
- var sdt = tSEncoder.CreateSDT(jt1078Package);
+ var sdt = tSEncoder.CreateSDT();
tSMessagePackWriter.WriteArray(sdt);
- var pat = tSEncoder.CreatePAT(jt1078Package);
+ var pat = tSEncoder.CreatePAT();
tSMessagePackWriter.WriteArray(pat);
- var pmt = tSEncoder.CreatePMT(jt1078Package);
+ var pmt = tSEncoder.CreatePMT();
tSMessagePackWriter.WriteArray(pmt);
var pes = tSEncoder.CreatePES(jt1078Package);
tSMessagePackWriter.WriteArray(pes);
@@ -170,17 +183,17 @@ namespace JT1078.Hls
}
}
- /////
- ///// 添加结束标识
- ///// 直播流用不到
- /////
- /////
- ////public void AppendM3U8End()
- ////{
- //// StringBuilder sb = new StringBuilder();
- //// sb.AppendLine("#EXT-X-ENDLIST"); //m3u8文件结束符 表示视频已经结束 有这个标志同时也说明当前流是一个非直播流
- //// //#EXT-X-PLAYLIST-TYPE:VOD/Live //VOD表示当前视频流不是一个直播流,而是点播流(也就是视频的全部ts文件已经生成)
- ////}
+ ///
+ /// 添加结束标识
+ /// 直播流用不到
+ ///
+ public void AppendM3U8End()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.AppendLine("#EXT-X-ENDLIST");
+ //m3u8文件结束符 表示视频已经结束 有这个标志同时也说明当前流是一个非直播流
+ //#EXT-X-PLAYLIST-TYPE:VOD/Live //VOD表示当前视频流不是一个直播流,而是点播流(也就是视频的全部ts文件已经生成)
+ }
///
/// 停止观看直播时清零数据
diff --git a/src/JT1078.Hls/TSEncoder.cs b/src/JT1078.Hls/TSEncoder.cs
index 5c73e4a..45f6cc9 100644
--- a/src/JT1078.Hls/TSEncoder.cs
+++ b/src/JT1078.Hls/TSEncoder.cs
@@ -36,12 +36,15 @@ namespace JT1078.Hls
//todo:音频同步
//private Dictionary AudioCounter = new Dictionary();
+ ///
+ ///
+ ///
public TSEncoder()
{
VideoCounter = new Dictionary(StringComparer.OrdinalIgnoreCase);
}
- public byte[] CreateSDT(JT1078Package jt1078Package, int minBufferSize = 188)
+ public byte[] CreateSDT(int minBufferSize = 188)
{
byte[] buffer = TSArrayPool.Rent(minBufferSize);
try
@@ -85,7 +88,7 @@ namespace JT1078.Hls
TSArrayPool.Return(buffer);
}
}
- public byte[] CreatePAT(JT1078Package jt1078Package, int minBufferSize = 188)
+ public byte[] CreatePAT(int minBufferSize = 188)
{
byte[] buffer = TSArrayPool.Rent(minBufferSize);
try
@@ -111,7 +114,7 @@ namespace JT1078.Hls
TSArrayPool.Return(buffer);
}
}
- public byte[] CreatePMT(JT1078Package jt1078Package, int minBufferSize = 188)
+ public byte[] CreatePMT(int minBufferSize = 188)
{
byte[] buffer = TSArrayPool.Rent(minBufferSize);
try
@@ -139,7 +142,7 @@ namespace JT1078.Hls
TSArrayPool.Return(buffer);
}
}
- public byte[] CreatePES(JT1078Package jt1078Package, int minBufferSize = 1024)
+ public byte[] CreatePES(in JT1078Package jt1078Package, int minBufferSize = 1024)
{
//将1078一帧的数据拆分成一小段一小段的PES包
byte[] buffer = TSArrayPool.Rent(jt1078Package.Bodies.Length + minBufferSize);
diff --git a/src/JT1078.Protocol.Benchmark/JT1078FlvEncoderContext.cs b/src/JT1078.Protocol.Benchmark/JT1078FlvEncoderContext.cs
deleted file mode 100644
index f103b9b..0000000
--- a/src/JT1078.Protocol.Benchmark/JT1078FlvEncoderContext.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-using BenchmarkDotNet.Attributes;
-using BenchmarkDotNet.Configs;
-using BenchmarkDotNet.Environments;
-using BenchmarkDotNet.Jobs;
-using BenchmarkDotNet.Toolchains.CsProj;
-using JT1078.Flv.MessagePack;
-using JT1078.Protocol;
-using JT1078.Protocol.H264;
-using JT1078.Protocol.MessagePack;
-using JT1078.Protocol.Extensions;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-
-namespace JT1078.Flv.Benchmark
-{
- [Config(typeof(JT1078FlvEncoderConfig))]
- [MarkdownExporterAttribute.GitHub]
- [MemoryDiagnoser]
- public class JT1078FlvEncoderContext
- {
- JT1078Package Package;
- List H264NALUs;
- H264NALU SPSNALu;
- H264Decoder h264Decoder = new H264Decoder();
- FlvEncoder flvEncoder = new FlvEncoder();
-
- [Params(100, 10000, 100000)]
- public int N;
-
- [GlobalSetup]
- public void Setup()
- {
- var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "JT1078_1.txt"));
- foreach (var line in lines)
- {
- var data = line.Split(',');
- var bytes = data[6].ToHexBytes();
- JT1078Package package = JT1078Serializer.Deserialize(bytes);
- Package = JT1078Serializer.Merge(package);
- }
- H264NALUs = h264Decoder.ParseNALU(Package);
- SPSNALu = H264NALUs.FirstOrDefault(f => f.NALUHeader.NalUnitType == NalUnitType.SPS);
- SPSNALu.RawData = h264Decoder.DiscardEmulationPreventionBytes(SPSNALu.RawData);
- }
-
- [Benchmark(Description = "EXPGolombReader")]
- public void EXPGolombReaderTest()
- {
- for (var i = 0; i < N; i++)
- {
- ExpGolombReader h264GolombReader = new ExpGolombReader(SPSNALu.RawData);
- h264GolombReader.ReadSPS();
- }
- }
-
- [Benchmark(Description = "H264Decoder")]
- public void H264Decoder()
- {
- for (var i = 0; i < N; i++)
- {
- var nalus = h264Decoder.ParseNALU(Package);
- }
- }
-
- //[Benchmark(Description = "FlvEncoder")]
- //public void FlvEncoder()
- //{
- // for(var i=0;i< N;i++)
- // {
- // var contents = flvEncoder.CreateFlvFrame(H264NALUs);
- // }
- //}
- }
-
- public class JT1078FlvEncoderConfig : ManualConfig
- {
- public JT1078FlvEncoderConfig()
- {
- AddJob(Job.Default.WithGcServer(false).WithToolchain(CsProjCoreToolchain.NetCoreApp50).WithPlatform(Platform.AnyCpu));
- }
- }
-}