videojs-contrib-hls
Version:
Play back HLS with video.js, even where it's not natively supported.
4 lines • 167 kB
JavaScript
/*! videojs-contrib-hls - v1.3.10 - 2016-03-01
* Copyright (c) 2016 Brightcove; Licensed */
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.muxjs=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";var d,e=a("../utils/stream.js");d=function(){var a,b=0;d.prototype.init.call(this),this.setTimestamp=function(a){b=a},this.parseId3TagSize=function(a,b){var c=a[b+6]<<21|a[b+7]<<14|a[b+8]<<7|a[b+9],d=a[b+5],e=(16&d)>>4;return e?c+20:c+10},this.parseAdtsSize=function(a,b){var c=(224&a[b+5])>>5,d=a[b+4]<<3,e=6144&a[b+3];return e|d|c},this.push=function(c){var d,e,f,g=0,h=0;for(void 0!==a&&a.length?(f=a.length,a=new Uint8Array(c.byteLength+f),a.set(a.subarray(0,f)),a.set(c,f)):a=c;a.length-h>=10;)if(a[h]!=="I".charCodeAt(0)||a[h+1]!=="D".charCodeAt(0)||a[h+2]!=="3".charCodeAt(0))if(a[h]&!0&&240===(240&a[h+1])){if(g=this.parseAdtsSize(a,h),g>a.length)break;e={type:"audio",data:a.subarray(h,h+g),pts:b,dts:b},this.trigger("data",e),h+=g}else h++;else{if(g=this.parseId3TagSize(a,h),g>a.length)break;d={type:"timed-metadata",data:a.subarray(h,h+g)},this.trigger("data",d),h+=g}}},d.prototype=new e,b.exports=d},{"../utils/stream.js":20}],2:[function(a,b,c){"use strict";var d,e=a("../utils/stream.js"),f=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];d=function(){var a,b;d.prototype.init.call(this),a=this,this.push=function(a){var c,d,e,g,h,i,j=0,k=0;if("audio"===a.type)for(b?(g=b,b=new Uint8Array(g.byteLength+a.data.byteLength),b.set(g),b.set(a.data,g.byteLength)):b=a.data;j+5<b.length;)if(255===b[j]&&240===(246&b[j+1])){if(d=2*(1&~b[j+1]),c=(3&b[j+3])<<11|b[j+4]<<3|(224&b[j+5])>>5,h=1024*((3&b[j+6])+1),i=9e4*h/f[(60&b[j+2])>>>2],e=j+c,b.byteLength<e)return;if(this.trigger("data",{pts:a.pts+k*i,dts:a.dts+k*i,sampleCount:h,audioobjecttype:(b[j+2]>>>6&3)+1,channelcount:(1&b[j+2])<<3|(192&b[j+3])>>>6,samplerate:f[(60&b[j+2])>>>2],samplingfrequencyindex:(60&b[j+2])>>>2,samplesize:16,data:b.subarray(j+7+d,e)}),b.byteLength===e)return void(b=void 0);k++,b=b.subarray(e)}else j++},this.flush=function(){this.trigger("done")}},d.prototype=new e,b.exports=d},{"../utils/stream.js":20}],3:[function(a,b,c){"use strict";var d,e,f=a("../utils/stream.js"),g=a("../utils/exp-golomb.js");e=function(){var a,b,c=0;e.prototype.init.call(this),this.push=function(d){var e;for(b?(e=new Uint8Array(b.byteLength+d.data.byteLength),e.set(b),e.set(d.data,b.byteLength),b=e):b=d.data;c<b.byteLength-3;c++)if(1===b[c+2]){a=c+5;break}for(;a<b.byteLength;)switch(b[a]){case 0:if(0!==b[a-1]){a+=2;break}if(0!==b[a-2]){a++;break}this.trigger("data",b.subarray(c+3,a-2));do a++;while(1!==b[a]&&a<b.length);c=a-2,a+=3;break;case 1:if(0!==b[a-1]||0!==b[a-2]){a+=3;break}this.trigger("data",b.subarray(c+3,a-2)),c=a-2,a+=3;break;default:a+=3}b=b.subarray(c),a-=c,c=0},this.flush=function(){b&&b.byteLength>3&&this.trigger("data",b.subarray(c+3)),b=null,c=0,this.trigger("done")}},e.prototype=new f,d=function(){var a,b,c,f,h,i,j,k=new e;d.prototype.init.call(this),a=this,this.push=function(a){"video"===a.type&&(b=a.trackId,c=a.pts,f=a.dts,k.push(a))},k.on("data",function(d){var e={trackId:b,pts:c,dts:f,data:d};switch(31&d[0]){case 5:e.nalUnitType="slice_layer_without_partitioning_rbsp_idr";break;case 6:e.nalUnitType="sei_rbsp",e.escapedRBSP=h(d.subarray(1));break;case 7:e.nalUnitType="seq_parameter_set_rbsp",e.escapedRBSP=h(d.subarray(1)),e.config=i(e.escapedRBSP);break;case 8:e.nalUnitType="pic_parameter_set_rbsp";break;case 9:e.nalUnitType="access_unit_delimiter_rbsp"}a.trigger("data",e)}),k.on("done",function(){a.trigger("done")}),this.flush=function(){k.flush()},j=function(a,b){var c,d,e=8,f=8;for(c=0;a>c;c++)0!==f&&(d=b.readExpGolomb(),f=(e+d+256)%256),e=0===f?e:f},h=function(a){for(var b,c,d=a.byteLength,e=[],f=1;d-2>f;)0===a[f]&&0===a[f+1]&&3===a[f+2]?(e.push(f+2),f+=2):f++;if(0===e.length)return a;b=d-e.length,c=new Uint8Array(b);var g=0;for(f=0;b>f;g++,f++)g===e[0]&&(g++,e.shift()),c[f]=a[g];return c},i=function(a){var b,c,d,e,f,h,i,k,l,m,n,o,p=0,q=0,r=0,s=0;if(b=new g(a),c=b.readUnsignedByte(),e=b.readUnsignedByte(),d=b.readUnsignedByte(),b.skipUnsignedExpGolomb(),(100===c||110===c||122===c||244===c||44===c||83===c||86===c||118===c||128===c||138===c||139===c||134===c)&&(f=b.readUnsignedExpGolomb(),3===f&&b.skipBits(1),b.skipUnsignedExpGolomb(),b.skipUnsignedExpGolomb(),b.skipBits(1),b.readBoolean()))for(n=3!==f?8:12,o=0;n>o;o++)b.readBoolean()&&(6>o?j(16,b):j(64,b));if(b.skipUnsignedExpGolomb(),h=b.readUnsignedExpGolomb(),0===h)b.readUnsignedExpGolomb();else if(1===h)for(b.skipBits(1),b.skipExpGolomb(),b.skipExpGolomb(),i=b.readUnsignedExpGolomb(),o=0;i>o;o++)b.skipExpGolomb();return b.skipUnsignedExpGolomb(),b.skipBits(1),k=b.readUnsignedExpGolomb(),l=b.readUnsignedExpGolomb(),m=b.readBits(1),0===m&&b.skipBits(1),b.skipBits(1),b.readBoolean()&&(p=b.readUnsignedExpGolomb(),q=b.readUnsignedExpGolomb(),r=b.readUnsignedExpGolomb(),s=b.readUnsignedExpGolomb()),{profileIdc:c,levelIdc:d,profileCompatibility:e,width:16*(k+1)-2*p-2*q,height:(2-m)*(l+1)*16-2*r-2*s}}},d.prototype=new f,b.exports={H264Stream:d,NalByteStream:e}},{"../utils/exp-golomb.js":19,"../utils/stream.js":20}],4:[function(a,b,c){b.exports={adts:a("./adts"),h264:a("./h264")}},{"./adts":2,"./h264":3}],5:[function(a,b,c){"use strict";var d;d=function(a,b){var c,e=0,f=16384,g=function(a,b){var c,d=a.position+b;d<a.bytes.byteLength||(c=new Uint8Array(2*d),c.set(a.bytes.subarray(0,a.position),0),a.bytes=c,a.view=new DataView(a.bytes.buffer))},h=d.widthBytes||new Uint8Array("width".length),i=d.heightBytes||new Uint8Array("height".length),j=d.videocodecidBytes||new Uint8Array("videocodecid".length);if(!d.widthBytes){for(c=0;c<"width".length;c++)h[c]="width".charCodeAt(c);for(c=0;c<"height".length;c++)i[c]="height".charCodeAt(c);for(c=0;c<"videocodecid".length;c++)j[c]="videocodecid".charCodeAt(c);d.widthBytes=h,d.heightBytes=i,d.videocodecidBytes=j}switch(this.keyFrame=!1,a){case d.VIDEO_TAG:this.length=16,f*=6;break;case d.AUDIO_TAG:this.length=13,this.keyFrame=!0;break;case d.METADATA_TAG:this.length=29,this.keyFrame=!0;break;default:throw"Error Unknown TagType"}this.bytes=new Uint8Array(f),this.view=new DataView(this.bytes.buffer),this.bytes[0]=a,this.position=this.length,this.keyFrame=b,this.pts=0,this.dts=0,this.writeBytes=function(a,b,c){var d,e=b||0;c=c||a.byteLength,d=e+c,g(this,c),this.bytes.set(a.subarray(e,d),this.position),this.position+=c,this.length=Math.max(this.length,this.position)},this.writeByte=function(a){g(this,1),this.bytes[this.position]=a,this.position++,this.length=Math.max(this.length,this.position)},this.writeShort=function(a){g(this,2),this.view.setUint16(this.position,a),this.position+=2,this.length=Math.max(this.length,this.position)},this.negIndex=function(a){return this.bytes[this.length-a]},this.nalUnitSize=function(){return 0===e?0:this.length-(e+4)},this.startNalUnit=function(){if(e>0)throw new Error("Attempted to create new NAL wihout closing the old one");e=this.length,this.length+=4,this.position=this.length},this.endNalUnit=function(a){var b,c;this.length===e+4?this.length-=4:e>0&&(b=e+4,c=this.length-b,this.position=e,this.view.setUint32(this.position,c),this.position=this.length,a&&a.push(this.bytes.subarray(b,b+c))),e=0},this.writeMetaDataDouble=function(a,b){var c;if(g(this,2+a.length+9),this.view.setUint16(this.position,a.length),this.position+=2,"width"===a)this.bytes.set(h,this.position),this.position+=5;else if("height"===a)this.bytes.set(i,this.position),this.position+=6;else if("videocodecid"===a)this.bytes.set(j,this.position),this.position+=12;else for(c=0;c<a.length;c++)this.bytes[this.position]=a.charCodeAt(c),this.position++;this.position++,this.view.setFloat64(this.position,b),this.position+=8,this.length=Math.max(this.length,this.position),++e},this.writeMetaDataBoolean=function(a,b){var c;for(g(this,2),this.view.setUint16(this.position,a.length),this.position+=2,c=0;c<a.length;c++)g(this,1),this.bytes[this.position]=a.charCodeAt(c),this.position++;g(this,2),this.view.setUint8(this.position,1),this.position++,this.view.setUint8(this.position,b?1:0),this.position++,this.length=Math.max(this.length,this.position),++e},this.finalize=function(){var a,c;switch(this.bytes[0]){case d.VIDEO_TAG:this.bytes[11]=7|(this.keyFrame||b?16:32),this.bytes[12]=b?0:1,a=this.pts-this.dts,this.bytes[13]=(16711680&a)>>>16,this.bytes[14]=(65280&a)>>>8,this.bytes[15]=(255&a)>>>0;break;case d.AUDIO_TAG:this.bytes[11]=175,this.bytes[12]=b?0:1;break;case d.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,e),this.position=this.length,this.bytes.set([0,0,9],this.position),this.position+=3,this.length=this.position}return c=this.length-11,this.bytes[1]=(16711680&c)>>>16,this.bytes[2]=(65280&c)>>>8,this.bytes[3]=(255&c)>>>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,g(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=d.frameTime(this.bytes),this}},d.AUDIO_TAG=8,d.VIDEO_TAG=9,d.METADATA_TAG=18,d.isAudioFrame=function(a){return d.AUDIO_TAG===a[0]},d.isVideoFrame=function(a){return d.VIDEO_TAG===a[0]},d.isMetaData=function(a){return d.METADATA_TAG===a[0]},d.isKeyFrame=function(a){return d.isVideoFrame(a)?23===a[11]:d.isAudioFrame(a)?!0:d.isMetaData(a)?!0:!1},d.frameTime=function(a){var b=a[4]<<16;return b|=a[5]<<8,b|=a[6]<<0,b|=a[7]<<24},b.exports=d},{}],6:[function(a,b,c){b.exports={tag:a("./flv-tag"),Transmuxer:a("./transmuxer"),tools:a("../tools/flv-inspector")}},{"../tools/flv-inspector":17,"./flv-tag":5,"./transmuxer":7}],7:[function(a,b,c){"use strict";var d,e,f,g,h,i,j,k=a("../utils/stream.js"),l=a("./flv-tag.js"),m=a("../m2ts/m2ts.js"),n=a("../codecs/adts.js"),o=a("../codecs/h264").H264Stream;h=function(a,b){"number"==typeof b.pts&&(void 0===a.timelineStartInfo.pts?a.timelineStartInfo.pts=b.pts:a.timelineStartInfo.pts=Math.min(a.timelineStartInfo.pts,b.pts)),"number"==typeof b.dts&&(void 0===a.timelineStartInfo.dts?a.timelineStartInfo.dts=b.dts:a.timelineStartInfo.dts=Math.min(a.timelineStartInfo.dts,b.dts))},i=function(a,b){var c=new l(l.METADATA_TAG);return c.dts=b,c.pts=b,c.writeMetaDataDouble("videocodecid",7),c.writeMetaDataDouble("width",a.width),c.writeMetaDataDouble("height",a.height),c},j=function(a,b){var c,d=new l(l.VIDEO_TAG,!0);for(d.dts=b,d.pts=b,d.writeByte(1),d.writeByte(a.profileIdc),d.writeByte(a.profileCompatibility),d.writeByte(a.levelIdc),d.writeByte(255),d.writeByte(225),d.writeShort(a.sps[0].length),d.writeBytes(a.sps[0]),d.writeByte(a.pps.length),c=0;c<a.pps.length;++c)d.writeShort(a.pps[c].length),d.writeBytes(a.pps[c]);return d},f=function(a){var b,c=[];f.prototype.init.call(this),this.push=function(b){h(a,b),a&&void 0===a.channelcount&&(a.audioobjecttype=b.audioobjecttype,a.channelcount=b.channelcount,a.samplerate=b.samplerate,a.samplingfrequencyindex=b.samplingfrequencyindex,a.samplesize=b.samplesize,a.extraData=a.audioobjecttype<<11|a.samplingfrequencyindex<<7|a.channelcount<<3),b.pts=Math.round(b.pts/90),b.dts=Math.round(b.dts/90),c.push(b)},this.flush=function(){var d,e,f,g=[];if(0===c.length)return void this.trigger("done");for(f=-(1/0);c.length;)d=c.shift(),(a.extraData!==b||d.pts-f>=1e3)&&(e=new l(l.METADATA_TAG),e.pts=d.pts,e.dts=d.dts,e.writeMetaDataDouble("audiocodecid",10),e.writeMetaDataBoolean("stereo",2===a.channelcount),e.writeMetaDataDouble("audiosamplerate",a.samplerate),e.writeMetaDataDouble("audiosamplesize",16),g.push(e),b=a.extraData,e=new l(l.AUDIO_TAG,!0),e.pts=d.pts,e.dts=d.dts,e.view.setUint16(e.position,a.extraData),e.position+=2,e.length=Math.max(e.length,e.position),g.push(e),f=d.pts),e=new l(l.AUDIO_TAG),e.pts=d.pts,e.dts=d.dts,e.writeBytes(d.data),g.push(e);b=null,this.trigger("data",{track:a,tags:g}),this.trigger("done")}},f.prototype=new k,e=function(a){var b,c,d=[];e.prototype.init.call(this),this.finishFrame=function(c,d){d&&(b&&a&&a.newMetadata&&(d.keyFrame||0===c.length)&&(c.push(i(b,d.pts)),c.push(j(a,d.pts)),a.newMetadata=!1),d.endNalUnit(),c.push(d))},this.push=function(b){h(a,b),b.pts=Math.round(b.pts/90),b.dts=Math.round(b.dts/90),d.push(b)},this.flush=function(){for(var e,f=[];d.length&&"access_unit_delimiter_rbsp"!==d[0].nalUnitType;)d.shift();if(0===d.length)return void this.trigger("done");for(;d.length;)e=d.shift(),"seq_parameter_set_rbsp"===e.nalUnitType?(a.newMetadata=!0,b=e.config,a.width=b.width,a.height=b.height,a.sps=[e.data],a.profileIdc=b.profileIdc,a.levelIdc=b.levelIdc,a.profileCompatibility=b.profileCompatibility,c.endNalUnit()):"pic_parameter_set_rbsp"===e.nalUnitType?(a.newMetadata=!0,a.pps=[e.data],c.endNalUnit()):"access_unit_delimiter_rbsp"===e.nalUnitType?(c&&this.finishFrame(f,c),c=new l(l.VIDEO_TAG),c.pts=e.pts,c.dts=e.dts):("slice_layer_without_partitioning_rbsp_idr"===e.nalUnitType&&(c.keyFrame=!0),c.endNalUnit()),c.startNalUnit(),c.writeBytes(e.data);c&&this.finishFrame(f,c),this.trigger("data",{track:a,tags:f}),this.trigger("done")}},e.prototype=new k,g=function(a){this.numberOfTracks=0,this.metadataStream=a.metadataStream,this.videoTags=[],this.audioTags=[],this.videoTrack=null,this.audioTrack=null,this.pendingCaptions=[],this.pendingMetadata=[],this.pendingTracks=0,g.prototype.init.call(this),this.push=function(a){return a.text?this.pendingCaptions.push(a):a.frames?this.pendingMetadata.push(a):("video"===a.track.type&&(this.videoTrack=a.track,this.videoTags=a.tags,this.pendingTracks++),void("audio"===a.track.type&&(this.audioTrack=a.track,this.audioTags=a.tags,this.pendingTracks++)))}},g.prototype=new k,g.prototype.flush=function(){var a,b,c,d,e={tags:{},captions:[],metadata:[]};if(!(this.pendingTracks<this.numberOfTracks)){for(this.videoTrack?d=this.videoTrack.timelineStartInfo.pts:this.audioTrack&&(d=this.audioTrack.timelineStartInfo.pts),e.tags.videoTags=this.videoTags,e.tags.audioTags=this.audioTags,c=0;c<this.pendingCaptions.length;c++)b=this.pendingCaptions[c],b.startTime=b.startPts-d,b.startTime/=9e4,b.endTime=b.endPts-d,b.endTime/=9e4,e.captions.push(b);for(c=0;c<this.pendingMetadata.length;c++)a=this.pendingMetadata[c],a.cueTime=a.pts-d,a.cueTime/=9e4,e.metadata.push(a);e.metadata.dispatchType=this.metadataStream.dispatchType,this.videoTrack=null,this.audioTrack=null,this.videoTags=[],this.audioTags=[],this.pendingCaptions.length=0,this.pendingMetadata.length=0,this.pendingTracks=0,this.trigger("data",e),this.trigger("done")}},d=function(a){var b,c,h,i,j,k,p,q,r,s=this;d.prototype.init.call(this),a=a||{},this.metadataStream=new m.MetadataStream,a.metadataStream=this.metadataStream,b=new m.TransportPacketStream,c=new m.TransportParseStream,h=new m.ElementaryStream,i=new n,j=new o,r=new g(a),b.pipe(c).pipe(h),h.pipe(j),h.pipe(i),h.pipe(this.metadataStream).pipe(r),q=new m.CaptionStream,j.pipe(q).pipe(r),h.on("data",function(a){var b,c,d;if("metadata"===a.type){for(b=a.tracks.length;b--;)"video"===a.tracks[b].type?c=a.tracks[b]:"audio"===a.tracks[b].type&&(d=a.tracks[b]);c&&!k&&(r.numberOfTracks++,k=new e(c),j.pipe(k).pipe(r)),d&&!p&&(r.numberOfTracks++,p=new f(d),i.pipe(p).pipe(r))}}),this.push=function(a){b.push(a)},this.flush=function(){b.flush()},r.on("data",function(a){s.trigger("data",a)}),r.on("done",function(){s.trigger("done")}),this.getFlvHeader=function(a,b,c){var d,e,f,g=new Uint8Array(9),h=new DataView(g.buffer);return a=a||0,b=void 0===b?!0:b,c=void 0===c?!0:c,h.setUint8(0,70),h.setUint8(1,76),h.setUint8(2,86),h.setUint8(3,1),h.setUint8(4,(b?4:0)|(c?1:0)),h.setUint32(5,g.byteLength),0>=a?(e=new Uint8Array(g.byteLength+4),e.set(g),e.set([0,0,0,0],g.byteLength),e):(d=new l(l.METADATA_TAG),d.pts=d.dts=0,d.writeMetaDataDouble("duration",a),f=d.finalize().length,e=new Uint8Array(g.byteLength+f),e.set(g),e.set(h.byteLength,f),e)}},d.prototype=new k,b.exports=d},{"../codecs/adts.js":2,"../codecs/h264":3,"../m2ts/m2ts.js":11,"../utils/stream.js":20,"./flv-tag.js":5}],8:[function(a,b,c){"use strict";var d={codecs:a("./codecs"),mp4:a("./mp4"),flv:a("./flv"),mp2t:a("./m2ts")};b.exports=d},{"./codecs":4,"./flv":6,"./m2ts":10,"./mp4":14}],9:[function(a,b,c){"use strict";var d=4,e=128,f=a("../utils/stream"),g=function(a){for(var b=0,c={payloadType:-1,payloadSize:0},f=0,g=0;b<a.byteLength&&a[b]!==e;){for(;255===a[b];)f+=255,b++;for(f+=a[b++];255===a[b];)g+=255,b++;if(g+=a[b++],!c.payload&&f===d){c.payloadType=f,c.payloadSize=g,c.payload=a.subarray(b,b+g);break}b+=g,f=0,g=0}return c},h=function(a){return 181!==a.payload[0]?null:49!==(a.payload[1]<<8|a.payload[2])?null:"GA94"!==String.fromCharCode(a.payload[3],a.payload[4],a.payload[5],a.payload[6])?null:3!==a.payload[7]?null:a.payload.subarray(8,a.payload.length-1)},i=function(a,b){var c,d,e,f,g=[];if(!(64&b[0]))return g;for(d=31&b[0],c=0;d>c;c++)e=3*c,f={type:3&b[e+2],pts:a},4&b[e+2]&&(f.ccData=b[e+3]<<8|b[e+4],g.push(f));return g},j=function(){j.prototype.init.call(this),this.captionPackets_=[],this.field1_=new y,this.field1_.on("data",this.trigger.bind(this,"data")),this.field1_.on("done",this.trigger.bind(this,"done"))};j.prototype=new f,j.prototype.push=function(a){var b,c;"sei_rbsp"===a.nalUnitType&&(b=g(a.escapedRBSP),b.payloadType===d&&(c=h(b),c&&(this.captionPackets_=this.captionPackets_.concat(i(a.pts,c)))))},j.prototype.flush=function(){return this.captionPackets_.length?(this.captionPackets_.sort(function(a,b){return a.pts-b.pts}),this.captionPackets_.forEach(this.field1_.push,this.field1_),this.captionPackets_.length=0,void this.field1_.flush()):void this.field1_.flush()};var k={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608},l=function(a){return null===a?"":(a=k[a]||a,String.fromCharCode(a))},m=0,n=5152,o=5167,p=5157,q=5158,r=5159,s=5165,t=5153,u=5164,v=5166,w=14,x=function(){for(var a=[],b=w+1;b--;)a.push("");return a},y=function(){y.prototype.init.call(this),this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=x(),this.nonDisplayed_=x(),this.lastControlCode_=null,this.push=function(a){if(0===a.type){var b,c,d,e;if(b=32639&a.ccData,b===this.lastControlCode_)return void(this.lastControlCode_=null);switch(4096===(61440&b)?this.lastControlCode_=b:this.lastControlCode_=null,b){case m:break;case n:this.mode_="popOn";break;case o:this.flushDisplayed(a.pts),c=this.displayed_,this.displayed_=this.nonDisplayed_,this.nonDisplayed_=c,this.startPts_=a.pts;break;case p:this.topRow_=w-1,this.mode_="rollUp";break;case q:this.topRow_=w-2,this.mode_="rollUp";break;case r:this.topRow_=w-3,this.mode_="rollUp";break;case s:this.flushDisplayed(a.pts),this.shiftRowsUp_(),this.startPts_=a.pts;break;case t:"popOn"===this.mode_?this.nonDisplayed_[w]=this.nonDisplayed_[w].slice(0,-1):this.displayed_[w]=this.displayed_[w].slice(0,-1);break;case u:this.flushDisplayed(a.pts),this.displayed_=x();break;case v:this.nonDisplayed_=x();break;default:if(d=b>>>8,e=255&b,d>=16&&23>=d&&e>=64&&127>=e&&(16!==d||96>e)&&(d=32,e=null),(17===d||25===d)&&e>=48&&63>=e&&(d=14850474,e=""),16===(240&d))return;this[this.mode_](a.pts,d,e)}}}};y.prototype=new f,y.prototype.flushDisplayed=function(a){var b,c;for(c=0;c<this.displayed_.length;c++)b=this.displayed_[c],b.length&&this.trigger("data",{startPts:this.startPts_,endPts:a,text:b.trim()})},y.prototype.popOn=function(a,b,c){var d=this.nonDisplayed_[w];d+=l(b),d+=l(c),this.nonDisplayed_[w]=d},y.prototype.rollUp=function(a,b,c){var d=this.displayed_[w];""===d&&(this.flushDisplayed(a),this.startPts_=a),d+=l(b),d+=l(c),this.displayed_[w]=d},y.prototype.shiftRowsUp_=function(){var a;for(a=0;a<this.topRow_;a++)this.displayed_[a]="";for(a=this.topRow_;w>a;a++)this.displayed_[a]=this.displayed_[a+1];this.displayed_[w]=""},b.exports={CaptionStream:j,Cea608Stream:y}},{"../utils/stream":20}],10:[function(a,b,c){b.exports=a("./m2ts")},{"./m2ts":11}],11:[function(a,b,c){"use strict";var d,e,f,g=a("../utils/stream.js"),h=a("./caption-stream"),i=a("./stream-types"),g=a("../utils/stream.js"),j=a("./stream-types.js"),k=188,l=71,d=function(){var a=new Uint8Array(k),b=0;d.prototype.init.call(this),this.push=function(c){var d,e=0,f=k;for(b?(d=new Uint8Array(c.byteLength+b),d.set(a.subarray(0,b)),d.set(c,b),b=0):d=c;f<d.byteLength;)d[e]!==l||d[f]!==l?(e++,f++):(this.trigger("data",d.subarray(e,f)),e+=k,f+=k);e<d.byteLength&&(a.set(d.subarray(e),0),b=d.byteLength-e)},this.flush=function(){b===k&&a[0]===l&&(this.trigger("data",a),b=0),this.trigger("done")}};d.prototype=new g,e=function(){var a,b,c,d;e.prototype.init.call(this),d=this,this.packetsWaitingForPmt=[],this.programMapTable=void 0,a=function(a,d){var e=0;d.payloadUnitStartIndicator&&(e+=a[e]+1),"pat"===d.type?b(a.subarray(e),d):c(a.subarray(e),d)},b=function(a,b){b.section_number=a[7],b.last_section_number=a[8],d.pmtPid=(31&a[10])<<8|a[11],b.pmtPid=d.pmtPid},c=function(a,b){var c,e,f,g;if(1&a[5]){for(d.programMapTable={},c=(15&a[1])<<8|a[2],e=3+c-4,f=(15&a[10])<<8|a[11],g=12+f;e>g;)d.programMapTable[(31&a[g+1])<<8|a[g+2]]=a[g],g+=((15&a[g+3])<<8|a[g+4])+5;for(b.programMapTable=d.programMapTable;d.packetsWaitingForPmt.length;)d.processPes_.apply(d,d.packetsWaitingForPmt.shift())}},this.push=function(b){var c={},d=4;c.payloadUnitStartIndicator=!!(64&b[1]),c.pid=31&b[1],c.pid<<=8,c.pid|=b[2],(48&b[3])>>>4>1&&(d+=b[d]+1),0===c.pid?(c.type="pat",a(b.subarray(d),c),this.trigger("data",c)):c.pid===this.pmtPid?(c.type="pmt",a(b.subarray(d),c),this.trigger("data",c)):void 0===this.programMapTable?this.packetsWaitingForPmt.push([b,d,c]):this.processPes_(b,d,c)},this.processPes_=function(a,b,c){c.streamType=this.programMapTable[c.pid],c.type="pes",c.data=a.subarray(b),this.trigger("data",c)}},e.prototype=new g,e.STREAM_TYPES={h264:27,adts:15},f=function(){var a,b={data:[],size:0},c={data:[],size:0},d={data:[],size:0},e=function(a,b){var c;b.dataAlignmentIndicator=0!==(4&a[6]),c=a[7],192&c&&(b.pts=(14&a[9])<<27|(255&a[10])<<20|(254&a[11])<<12|(255&a[12])<<5|(254&a[13])>>>3,b.pts*=4,b.pts+=(6&a[13])>>>1,b.dts=b.pts,64&c&&(b.dts=(14&a[14])<<27|(255&a[15])<<20|(254&a[16])<<12|(255&a[17])<<5|(254&a[18])>>>3,b.dts*=4,b.dts+=(6&a[18])>>>1)),b.data=a.subarray(9+a[8])},g=function(b,c){var d,f=new Uint8Array(b.size),g={type:c},h=0;if(b.data.length){for(g.trackId=b.data[0].pid;b.data.length;)d=b.data.shift(),f.set(d.data,h),h+=d.data.byteLength;e(f,g),b.size=0,a.trigger("data",g)}};f.prototype.init.call(this),a=this,this.push=function(e){({pat:function(){},pes:function(){var a,f;switch(e.streamType){case i.H264_STREAM_TYPE:case j.H264_STREAM_TYPE:a=b,f="video";break;case i.ADTS_STREAM_TYPE:a=c,f="audio";break;case i.METADATA_STREAM_TYPE:a=d,f="timed-metadata";break;default:return}e.payloadUnitStartIndicator&&g(a,f),a.data.push(e),a.size+=e.data.byteLength},pmt:function(){var b,c,d={type:"metadata",tracks:[]},f=e.programMapTable;for(b in f)f.hasOwnProperty(b)&&(c={timelineStartInfo:{baseMediaDecodeTime:0}},c.id=+b,f[b]===j.H264_STREAM_TYPE?(c.codec="avc",c.type="video"):f[b]===j.ADTS_STREAM_TYPE&&(c.codec="adts",c.type="audio"),d.tracks.push(c));a.trigger("data",d)}})[e.type]()},this.flush=function(){g(b,"video"),g(c,"audio"),g(d,"timed-metadata"),this.trigger("done")}},f.prototype=new g;var m={PAT_PID:0,MP2T_PACKET_LENGTH:k,TransportPacketStream:d,TransportParseStream:e,ElementaryStream:f,CaptionStream:h.CaptionStream,Cea608Stream:h.Cea608Stream,MetadataStream:a("./metadata-stream")};for(var n in i)i.hasOwnProperty(n)&&(m[n]=i[n]);b.exports=m},{"../utils/stream.js":20,"./caption-stream":9,"./metadata-stream":12,"./stream-types":13,"./stream-types.js":13}],12:[function(a,b,c){"use strict";var d,e=a("../utils/stream"),f=a("./stream-types"),g=function(a,b,c){var d,e="";for(d=b;c>d;d++)e+="%"+("00"+a[d].toString(16)).slice(-2);return e},h=function(a,b,c){return decodeURIComponent(g(a,b,c))},i=function(a,b,c){return unescape(g(a,b,c))},j=function(a){return a[0]<<21|a[1]<<14|a[2]<<7|a[3]},k={TXXX:function(a){var b;if(3===a.data[0]){for(b=1;b<a.data.length;b++)if(0===a.data[b]){a.description=h(a.data,1,b),a.value=h(a.data,b+1,a.data.length-1);break}a.data=a.value}},WXXX:function(a){var b;if(3===a.data[0])for(b=1;b<a.data.length;b++)if(0===a.data[b]){a.description=h(a.data,1,b),a.url=h(a.data,b+1,a.data.length);break}},PRIV:function(a){var b;for(b=0;b<a.data.length;b++)if(0===a.data[b]){a.owner=i(a.data,0,b);break}a.privateData=a.data.subarray(b+1),a.data=a.privateData}};d=function(a){var b,c={debug:!(!a||!a.debug),descriptor:a&&a.descriptor},e=0,g=[],h=0;if(d.prototype.init.call(this),this.dispatchType=f.METADATA_STREAM_TYPE.toString(16),c.descriptor)for(b=0;b<c.descriptor.length;b++)this.dispatchType+=("00"+c.descriptor[b].toString(16)).slice(-2);this.push=function(a){var b,d,f,i,l,m;if("timed-metadata"===a.type){if(a.dataAlignmentIndicator&&(h=0,g.length=0),0===g.length&&(a.data.length<10||a.data[0]!=="I".charCodeAt(0)||a.data[1]!=="D".charCodeAt(0)||a.data[2]!=="3".charCodeAt(0)))return void(c.debug&&console.log("Skipping unrecognized metadata packet"));if(g.push(a),h+=a.data.byteLength,1===g.length&&(e=j(a.data.subarray(6,10)),e+=10),!(e>h)){for(b={data:new Uint8Array(e),frames:[],pts:g[0].pts,dts:g[0].dts},l=0;e>l;)b.data.set(g[0].data.subarray(0,e-l),l),l+=g[0].data.byteLength,h-=g[0].data.byteLength,g.shift();d=10,64&b.data[5]&&(d+=4,d+=j(b.data.subarray(10,14)),e-=j(b.data.subarray(16,20)));do{if(f=j(b.data.subarray(d+4,d+8)),1>f)return console.log("Malformed ID3 frame encountered. Skipping metadata parsing.");if(m=String.fromCharCode(b.data[d],b.data[d+1],b.data[d+2],b.data[d+3]),i={id:m,data:b.data.subarray(d+10,d+f+10)},i.key=i.id,k[i.id]&&(k[i.id](i),"com.apple.streaming.transportStreamTimestamp"===i.owner)){var n=i.data,o=(1&n[3])<<30|n[4]<<22|n[5]<<14|n[6]<<6|n[7]>>>2;o*=4,o+=3&n[7],i.timeStamp=o,this.trigger("timestamp",i)}b.frames.push(i),d+=10,d+=f}while(e>d);this.trigger("data",b)}}}},d.prototype=new e,b.exports=d},{"../utils/stream":20,"./stream-types":13}],13:[function(a,b,c){"use strict";b.exports={H264_STREAM_TYPE:27,ADTS_STREAM_TYPE:15,METADATA_STREAM_TYPE:21}},{}],14:[function(a,b,c){b.exports={generator:a("./mp4-generator"),Transmuxer:a("./transmuxer").Transmuxer,AudioSegmentStream:a("./transmuxer").AudioSegmentStream,VideoSegmentStream:a("./transmuxer").VideoSegmentStream,tools:a("../tools/mp4-inspector")}},{"../tools/mp4-inspector":18,"./mp4-generator":15,"./transmuxer":16}],15:[function(a,b,c){"use strict";var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N;!function(){var a;A={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],smhd:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],styp:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[]};for(a in A)A.hasOwnProperty(a)&&(A[a]=[a.charCodeAt(0),a.charCodeAt(1),a.charCodeAt(2),a.charCodeAt(3)]);B=new Uint8Array(["i".charCodeAt(0),"s".charCodeAt(0),"o".charCodeAt(0),"m".charCodeAt(0)]),D=new Uint8Array(["a".charCodeAt(0),"v".charCodeAt(0),"c".charCodeAt(0),"1".charCodeAt(0)]),C=new Uint8Array([0,0,0,1]),E=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),F=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]),G={video:E,audio:F},J=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),I=new Uint8Array([0,0,0,0,0,0,0,0]),K=new Uint8Array([0,0,0,0,0,0,0,0]),L=K,M=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),N=K,H=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0])}(),d=function(a){var b,c,d,e=[],f=0;for(b=1;b<arguments.length;b++)e.push(arguments[b]);for(b=e.length;b--;)f+=e[b].byteLength;for(c=new Uint8Array(f+8),d=new DataView(c.buffer,c.byteOffset,c.byteLength),d.setUint32(0,c.byteLength),c.set(a,4),b=0,f=8;b<e.length;b++)c.set(e[b],f),f+=e[b].byteLength;return c},e=function(){return d(A.dinf,d(A.dref,J))},f=function(a){return d(A.esds,new Uint8Array([0,0,0,0,3,25,0,0,0,4,17,64,21,0,6,0,0,0,218,192,0,0,218,192,5,2,a.audioobjecttype<<3|a.samplingfrequencyindex>>>1,a.samplingfrequencyindex<<7|a.channelcount<<3,6,1,2]))},g=function(){return d(A.ftyp,B,C,B,D)},s=function(a){return d(A.hdlr,G[a])},h=function(a){return d(A.mdat,a)},r=function(a){var b=new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,0,1,95,144,a.duration>>>24&255,a.duration>>>16&255,a.duration>>>8&255,255&a.duration,85,196,0,0]);return a.samplerate&&(b[12]=a.samplerate>>>24&255,b[13]=a.samplerate>>>16&255,b[14]=a.samplerate>>>8&255,b[15]=255&a.samplerate),d(A.mdhd,b)},q=function(a){return d(A.mdia,r(a),s(a.type),j(a))},i=function(a){return d(A.mfhd,new Uint8Array([0,0,0,0,(4278190080&a)>>24,(16711680&a)>>16,(65280&a)>>8,255&a]))},j=function(a){return d(A.minf,"video"===a.type?d(A.vmhd,H):d(A.smhd,I),e(),u(a))},k=function(a,b){for(var c=[],e=b.length;e--;)c[e]=x(b[e]);return d.apply(null,[A.moof,i(a)].concat(c))},l=function(a){for(var b=a.length,c=[];b--;)c[b]=o(a[b]);return d.apply(null,[A.moov,n(4294967295)].concat(c).concat(m(a)))},m=function(a){for(var b=a.length,c=[];b--;)c[b]=y(a[b]);return d.apply(null,[A.mvex].concat(c))},n=function(a){var b=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,0,1,95,144,(4278190080&a)>>24,(16711680&a)>>16,(65280&a)>>8,255&a,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return d(A.mvhd,b)},t=function(a){var b,c,e=a.samples||[],f=new Uint8Array(4+e.length);for(c=0;c<e.length;c++)b=e[c].flags,f[c+4]=b.dependsOn<<4|b.isDependedOn<<2|b.hasRedundancy;return d(A.sdtp,f)},u=function(a){return d(A.stbl,v(a),d(A.stts,N),d(A.stsc,L),d(A.stsz,M),d(A.stco,K))},function(){var a,b;v=function(c){return d(A.stsd,new Uint8Array([0,0,0,0,0,0,0,1]),"video"===c.type?a(c):b(c))},a=function(a){var b,c=a.sps||[],e=a.pps||[],f=[],g=[];for(b=0;b<c.length;b++)f.push((65280&c[b].byteLength)>>>8),f.push(255&c[b].byteLength),f=f.concat(Array.prototype.slice.call(c[b]));for(b=0;b<e.length;b++)g.push((65280&e[b].byteLength)>>>8),g.push(255&e[b].byteLength),g=g.concat(Array.prototype.slice.call(e[b]));return d(A.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,(65280&a.width)>>8,255&a.width,(65280&a.height)>>8,255&a.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,19,118,105,100,101,111,106,115,45,99,111,110,116,114,105,98,45,104,108,115,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),d(A.avcC,new Uint8Array([1,a.profileIdc,a.profileCompatibility,a.levelIdc,255].concat([c.length]).concat(f).concat([e.length]).concat(g))),d(A.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))},b=function(a){return d(A.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,(65280&a.channelcount)>>8,255&a.channelcount,(65280&a.samplesize)>>8,255&a.samplesize,0,0,0,0,(65280&a.samplerate)>>8,255&a.samplerate,0,0]),f(a))}}(),w=function(){return d(A.styp,B,C,B)},p=function(a){var b=new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,(4278190080&a.id)>>24,(16711680&a.id)>>16,(65280&a.id)>>8,255&a.id,0,0,0,0,(4278190080&a.duration)>>24,(16711680&a.duration)>>16,(65280&a.duration)>>8,255&a.duration,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,(65280&a.width)>>8,255&a.width,0,0,(65280&a.height)>>8,255&a.height,0,0]);
return d(A.tkhd,b)},x=function(a){var b,c,e,f,g;return b=d(A.tfhd,new Uint8Array([0,0,0,58,(4278190080&a.id)>>24,(16711680&a.id)>>16,(65280&a.id)>>8,255&a.id,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0])),c=d(A.tfdt,new Uint8Array([0,0,0,0,a.baseMediaDecodeTime>>>24&255,a.baseMediaDecodeTime>>>16&255,a.baseMediaDecodeTime>>>8&255,255&a.baseMediaDecodeTime])),g=88,"audio"===a.type?(e=z(a,g),d(A.traf,b,c,e)):(f=t(a),e=z(a,f.length+g),d(A.traf,b,c,e,f))},o=function(a){return a.duration=a.duration||4294967295,d(A.trak,p(a),q(a))},y=function(a){var b=new Uint8Array([0,0,0,0,(4278190080&a.id)>>24,(16711680&a.id)>>16,(65280&a.id)>>8,255&a.id,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]);return"video"!==a.type&&(b[b.length-1]=0),d(A.trex,b)},function(){var a,b,c;c=function(a,b){var c=0,d=0,e=0,f=0;return a.length&&(void 0!==a[0].duration&&(c=1),void 0!==a[0].size&&(d=2),void 0!==a[0].flags&&(e=4),void 0!==a[0].compositionTimeOffset&&(f=8)),[0,0,c|d|e|f,1,(4278190080&a.length)>>>24,(16711680&a.length)>>>16,(65280&a.length)>>>8,255&a.length,(4278190080&b)>>>24,(16711680&b)>>>16,(65280&b)>>>8,255&b]},b=function(a,b){var e,f,g,h;for(f=a.samples||[],b+=20+16*f.length,e=c(f,b),h=0;h<f.length;h++)g=f[h],e=e.concat([(4278190080&g.duration)>>>24,(16711680&g.duration)>>>16,(65280&g.duration)>>>8,255&g.duration,(4278190080&g.size)>>>24,(16711680&g.size)>>>16,(65280&g.size)>>>8,255&g.size,g.flags.isLeading<<2|g.flags.dependsOn,g.flags.isDependedOn<<6|g.flags.hasRedundancy<<4|g.flags.paddingValue<<1|g.flags.isNonSyncSample,61440&g.flags.degradationPriority,15&g.flags.degradationPriority,(4278190080&g.compositionTimeOffset)>>>24,(16711680&g.compositionTimeOffset)>>>16,(65280&g.compositionTimeOffset)>>>8,255&g.compositionTimeOffset]);return d(A.trun,new Uint8Array(e))},a=function(a,b){var e,f,g,h;for(f=a.samples||[],b+=20+8*f.length,e=c(f,b),h=0;h<f.length;h++)g=f[h],e=e.concat([(4278190080&g.duration)>>>24,(16711680&g.duration)>>>16,(65280&g.duration)>>>8,255&g.duration,(4278190080&g.size)>>>24,(16711680&g.size)>>>16,(65280&g.size)>>>8,255&g.size]);return d(A.trun,new Uint8Array(e))},z=function(c,d){return"audio"===c.type?a(c,d):b(c,d)}}(),b.exports={ftyp:g,mdat:h,moof:k,moov:l,initSegment:function(a){var b,c=g(),d=l(a);return b=new Uint8Array(c.byteLength+d.byteLength),b.set(c),b.set(d,c.byteLength),b}}},{}],16:[function(a,b,c){"use strict";var d,e,f,g,h,i,j,k=a("../utils/stream.js"),l=a("./mp4-generator.js"),m=a("../m2ts/m2ts.js"),n=a("../codecs/adts.js"),o=a("../codecs/h264").H264Stream,p=a("../aac");e=function(a){var b=[],c=0,d=0,f=0;e.prototype.init.call(this),this.push=function(d){h(a,d),a&&(a.audioobjecttype=d.audioobjecttype,a.channelcount=d.channelcount,a.samplerate=d.samplerate,a.samplingfrequencyindex=d.samplingfrequencyindex,a.samplesize=d.samplesize),b.push(d),c+=d.data.byteLength},this.setEarliestDts=function(b){f=b-a.timelineStartInfo.baseMediaDecodeTime},this.flush=function(){var e,g,h,k,m,n,o;if(0===c)return void this.trigger("done");for(a.minSegmentDts<f&&(a.minSegmentDts=1/0,b=b.filter(function(b){return b.dts>=f?(a.minSegmentDts=Math.min(a.minSegmentDts,b.dts),a.minSegmentPts=a.minSegmentDts,!0):(c-=b.data.byteLength,!1)})),h=new Uint8Array(c),a.samples=[],m=0;b.length;)g=b[0],k={size:g.data.byteLength,duration:1024},a.samples.push(k),h.set(g.data,m),m+=g.data.byteLength,b.shift();c=0,n=l.mdat(h),j(a),o=l.moof(d,[a]),e=new Uint8Array(o.byteLength+n.byteLength),d++,e.set(o),e.set(n,o.byteLength),i(a),this.trigger("data",{track:a,boxes:e}),this.trigger("done")}},e.prototype=new k,d=function(a){var b,c,e=0,f=[],g=0;d.prototype.init.call(this),delete a.minPTS,this.push=function(d){h(a,d),"seq_parameter_set_rbsp"!==d.nalUnitType||b||(b=d.config,a.width=b.width,a.height=b.height,a.sps=[d.data],a.profileIdc=b.profileIdc,a.levelIdc=b.levelIdc,a.profileCompatibility=b.profileCompatibility),"pic_parameter_set_rbsp"!==d.nalUnitType||c||(c=d.data,a.pps=[d.data]),f.push(d),g+=d.data.byteLength},this.flush=function(){for(var d,h,k,m,n,o,p,q,r,s;f.length&&"access_unit_delimiter_rbsp"!==f[0].nalUnitType;)f.shift();if(0===g)return void this.trigger("done");for(p=new Uint8Array(g+4*f.length),q=new DataView(p.buffer),a.samples=[],r={size:0,flags:{isLeading:0,dependsOn:1,isDependedOn:0,hasRedundancy:0,degradationPriority:0}},o=0;f.length;)h=f[0],"access_unit_delimiter_rbsp"===h.nalUnitType&&(d&&(r.duration=h.dts-d.dts,a.samples.push(r)),r={size:0,flags:{isLeading:0,dependsOn:1,isDependedOn:0,hasRedundancy:0,degradationPriority:0},dataOffset:o,compositionTimeOffset:h.pts-h.dts},d=h),"slice_layer_without_partitioning_rbsp_idr"===h.nalUnitType&&(r.flags.dependsOn=2),r.size+=4,r.size+=h.data.byteLength,q.setUint32(o,h.data.byteLength),o+=4,p.set(h.data,o),o+=h.data.byteLength,f.shift();for(a.samples.length&&(r.duration=a.samples[a.samples.length-1].duration),a.samples.push(r),s=0;a.samples.length;){if(r=a.samples[0],2===r.flags.dependsOn){p=p.subarray(r.dataOffset),r.duration+=s;break}s+=r.duration,a.samples.shift()}g=0,m=l.mdat(p),j(a),this.trigger("timelineStartInfo",a.timelineStartInfo),k=l.moof(e,[a]),n=new Uint8Array(k.byteLength+m.byteLength),e++,n.set(k),n.set(m,k.byteLength),i(a),this.trigger("data",{track:a,boxes:n}),b=void 0,c=void 0,this.trigger("done")}},d.prototype=new k,h=function(a,b){"number"==typeof b.pts&&(void 0===a.timelineStartInfo.pts&&(a.timelineStartInfo.pts=b.pts),void 0===a.minSegmentPts?a.minSegmentPts=b.pts:a.minSegmentPts=Math.min(a.minSegmentPts,b.pts),void 0===a.maxSegmentPts?a.maxSegmentPts=b.pts:a.maxSegmentPts=Math.max(a.maxSegmentPts,b.pts)),"number"==typeof b.dts&&(void 0===a.timelineStartInfo.dts&&(a.timelineStartInfo.dts=b.dts),void 0===a.minSegmentDts?a.minSegmentDts=b.dts:a.minSegmentDts=Math.min(a.minSegmentDts,b.dts),void 0===a.maxSegmentDts?a.maxSegmentDts=b.dts:a.maxSegmentDts=Math.max(a.maxSegmentDts,b.dts))},i=function(a){delete a.minSegmentDts,delete a.maxSegmentDts,delete a.minSegmentPts,delete a.maxSegmentPts},j=function(a){var b,c=9e4,d=a.minSegmentDts-a.timelineStartInfo.dts,e=a.minSegmentPts-a.minSegmentDts;a.baseMediaDecodeTime=a.timelineStartInfo.baseMediaDecodeTime,a.baseMediaDecodeTime+=d,a.baseMediaDecodeTime-=e,a.baseMediaDecodeTime=Math.max(0,a.baseMediaDecodeTime),"audio"===a.type&&(b=a.samplerate/c,a.baseMediaDecodeTime*=b,a.baseMediaDecodeTime=Math.floor(a.baseMediaDecodeTime))},g=function(a){this.numberOfTracks=0,this.metadataStream=a.metadataStream,"undefined"!=typeof a.remux?this.remuxTracks=!!a.remux:this.remuxTracks=!0,this.pendingTracks=[],this.videoTrack=null,this.pendingBoxes=[],this.pendingCaptions=[],this.pendingMetadata=[],this.pendingBytes=0,this.emittedTracks=0,g.prototype.init.call(this),this.push=function(a){return a.text?this.pendingCaptions.push(a):a.frames?this.pendingMetadata.push(a):(this.pendingTracks.push(a.track),this.pendingBoxes.push(a.boxes),this.pendingBytes+=a.boxes.byteLength,"video"===a.track.type&&(this.videoTrack=a.track),void("audio"===a.track.type&&(this.audioTrack=a.track)))}},g.prototype=new k,g.prototype.flush=function(){var a,b,c,d,e=0,f={captions:[],metadata:[]},g=0;if(!(0===this.pendingTracks.length||this.remuxTracks&&this.pendingTracks.length<this.numberOfTracks)){for(this.videoTrack?g=this.videoTrack.timelineStartInfo.pts:this.audioTrack&&(g=this.audioTrack.timelineStartInfo.pts),1===this.pendingTracks.length?f.type=this.pendingTracks[0].type:f.type="combined",this.emittedTracks+=this.pendingTracks.length,c=l.initSegment(this.pendingTracks),f.data=new Uint8Array(c.byteLength+this.pendingBytes),f.data.set(c),e+=c.byteLength,d=0;d<this.pendingBoxes.length;d++)f.data.set(this.pendingBoxes[d],e),e+=this.pendingBoxes[d].byteLength;for(d=0;d<this.pendingCaptions.length;d++)a=this.pendingCaptions[d],a.startTime=a.startPts-g,a.startTime/=9e4,a.endTime=a.endPts-g,a.endTime/=9e4,f.captions.push(a);for(d=0;d<this.pendingMetadata.length;d++)b=this.pendingMetadata[d],b.cueTime=b.pts-g,b.cueTime/=9e4,f.metadata.push(b);f.metadata.dispatchType=this.metadataStream.dispatchType,this.pendingTracks.length=0,this.videoTrack=null,this.pendingBoxes.length=0,this.pendingCaptions.length=0,this.pendingBytes=0,this.pendingMetadata.length=0,this.trigger("data",f),this.emittedTracks>=this.numberOfTracks&&(this.trigger("done"),this.emittedTracks=0)}},f=function(a){var b,c,h,j,k,l,q,r,s,t,u,v,w,x=this;this.setupAacPipeline=function(){this.metadataStream=new m.MetadataStream,a.metadataStream=this.metadataStream,r=new p,l=new n,v=new g(a),w=r,r.pipe(l),r.pipe(this.metadataStream),this.metadataStream.pipe(v),this.metadataStream.on("timestamp",function(a){r.setTimestamp(a.timestamp)}),this.addAacListener()},this.addAacListener=function(){r.on("data",function(a){if("timed-metadata"===a.type){var b={timelineStartInfo:{baseMediaDecodeTime:0},codec:"adts",type:"audio"};b&&!t&&(v.numberOfTracks++,t=new e(b),l.pipe(t).pipe(v))}})},this.setupTsPipeline=function(){this.metadataStream=new m.MetadataStream,a.metadataStream=this.metadataStream,h=new m.TransportPacketStream,j=new m.TransportParseStream,k=new m.ElementaryStream,l=new n,q=new o,u=new m.CaptionStream,v=new g(a),w=h,h.pipe(j).pipe(k),k.pipe(q),k.pipe(l),k.pipe(this.metadataStream).pipe(v),q.pipe(u).pipe(v),this.addTsListener()},this.addTsListener=function(){k.on("data",function(a){var f;if("metadata"===a.type){for(f=a.tracks.length;f--;)b||"video"!==a.tracks[f].type?c||"audio"!==a.tracks[f].type||(c=a.tracks[f],c.timelineStartInfo.baseMediaDecodeTime=x.baseMediaDecodeTime):(b=a.tracks[f],b.timelineStartInfo.baseMediaDecodeTime=x.baseMediaDecodeTime);b&&!s&&(v.numberOfTracks++,s=new d(b),s.on("timelineStartInfo",function(a){c&&(c.timelineStartInfo=a,t.setEarliestDts(a.dts))}),q.pipe(s).pipe(v)),c&&!t&&(v.numberOfTracks++,t=new e(c),l.pipe(t).pipe(v))}})},f.prototype.init.call(this),a=a||{},this.baseMediaDecodeTime=a.baseMediaDecodeTime||0,void 0===a.aacfile?this.setupTsPipeline():this.setupAacPipeline(),this.setBaseMediaDecodeTime=function(a){this.baseMediaDecodeTime=a,c&&(c.timelineStartInfo.dts=void 0,c.timelineStartInfo.pts=void 0,i(c),c.timelineStartInfo.baseMediaDecodeTime=a),b&&(b.timelineStartInfo.dts=void 0,b.timelineStartInfo.pts=void 0,i(b),b.timelineStartInfo.baseMediaDecodeTime=a)},this.push=function(a){w.push(a)},this.flush=function(){w.flush()},v.on("data",function(a){x.trigger("data",a)}),v.on("done",function(){x.trigger("done")})},f.prototype=new k,b.exports={Transmuxer:f,VideoSegmentStream:d,AudioSegmentStream:e}},{"../aac":1,"../codecs/adts.js":2,"../codecs/h264":3,"../m2ts/m2ts.js":11,"../utils/stream.js":20,"./mp4-generator.js":15}],17:[function(a,b,c){"use strict";var d={8:"audio",9:"video",18:"metadata"},e=function(a){return"0x"+("00"+a.toString(16)).slice(-2).toUpperCase()},f=function(a){for(var b,c=[];a.byteLength>0;){switch(b=0,a.byteLength){default:c.push(e(a[b++]));case 7:c.push(e(a[b++]));case 6:c.push(e(a[b++]));case 5:c.push(e(a[b++]));case 4:c.push(e(a[b++]));case 3:c.push(e(a[b++]));case 2:c.push(e(a[b++]));case 1:c.push(e(a[b++]))}a=a.subarray(b)}return c.join(" ")},g=function(a,b){var c=["AVC Sequence Header","AVC NALU","AVC End-of-Sequence"],d=a[1]&parseInt("01111111",2)<<16|a[2]<<8|a[3];return b=b||{},b.avcPacketType=c[a[0]],b.CompositionTime=a[1]&parseInt("10000000",2)?-d:d,1===a[0]?b.nalUnitTypeRaw=f(a.subarray(4,100)):b.data=f(a.subarray(4)),b},h=function(a,b){var c=["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"],d=a[0]&parseInt("00001111",2);return b=b||{},b.frameType=c[(a[0]&parseInt("11110000",2))>>>4],b.codecID=d,7===d?g(a.subarray(1),b):b},i=function(a,b){var c=["AAC Sequence Header","AAC Raw"];return b=b||{},b.aacPacketType=c[a[0]],b.data=f(a.subarray(1)),b},j=function(a,b){var c=["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"],d=["5.5-kHz","11-kHz","22-kHz","44-kHz"],e=(a[0]&parseInt("11110000",2))>>>4;return b=b||{},b.soundFormat=c[e],b.soundRate=d[(a[0]&parseInt("00001100",2))>>>2],b.soundSize=(a[0]&parseInt("00000010",2))>>>1?"16-bit":"8-bit",b.soundType=a[0]&parseInt("00000001",2)?"Stereo":"Mono",10===e?i(a.subarray(1),b):b},k=function(a){return{tagType:d[a[0]],dataSize:a[1]<<16|a[2]<<8|a[3],timestamp:a[7]<<24|a[4]<<16|a[5]<<8|a[6],streamID:a[8]<<16|a[9]<<8|a[10]}},l=function(a){var b=k(a);switch(a[0]){case 8:j(a.subarray(11),b);break;case 9:h(a.subarray(11),b);break;case 18:}return b},m=function(a){var b,c,d=9,e=[];for(d+=4;d<a.byteLength;)b=a[d+1]<<16,b|=a[d+2]<<8,b|=a[d+3],b+=11,c=a.subarray(d,d+b),e.push(l(c)),d+=b+4;return e},n=function(a){return JSON.stringify(a,null,2)};b.exports={inspectTag:l,inspect:m,textify:n}},{}],18:[function(a,b,c){(function(a){"use strict";var c,d,e=function(a){var b="";return b+=String.fromCharCode(a[0]),b+=String.fromCharCode(a[1]),b+=String.fromCharCode(a[2]),b+=String.fromCharCode(a[3])},f=function(a){return new Date(1e3*a-20828448e5)},g=function(a){return{isLeading:(12&a[0])>>>2,dependsOn:3&a[0],isDependedOn:(192&a[1])>>>6,hasRedundancy:(48&a[1])>>>4,paddingValue:(14&a[1])>>>1,isNonSyncSample:1&a[1],degradationPriority:a[2]<<8|a[3]}},h=function(a){var b,c,d=new DataView(a.buffer,a.byteOffset,a.byteLength),e=[];for(b=0;b+4<a.length;b+=c){if(c=d.getUint32(b),b+=4,0>=c)return;switch(31&a[b]){case 1:e.push("slice_layer_without_partitioning_rbsp");break;case 5:e.push("slice_layer_without_partitioning_rbsp_idr");break;case 6:e.push("sei_rbsp");break;case 7:e.push("seq_parameter_set_rbsp");break;case 8:e.push("pic_parameter_set_rbsp");break;case 9:e.push("access_unit_delimiter_rbsp");break;default:e.push(31&a[b])}}return e},i={avc1:function(a){var b=new DataView(a.buffer,a.byteOffset,a.byteLength);return{dataReferenceIndex:b.getUint16(6),width:b.getUint16(24),height:b.getUint16(26),horizresolution:b.getUint16(28)+b.getUint16(30)/16,vertresolution:b.getUint16(32)+b.getUint16(34)/16,frameCount:b.getUint16(40),depth:b.getUint16(74),config:c(a.subarray(78,a.byteLength))}},avcC:function(a){var b,c,d,e,f=new DataView(a.buffer,a.byteOffset,a.byteLength),g={configurationVersion:a[0],avcProfileIndication:a[1],profileCompatibility:a[2],avcLevelIndication:a[3],lengthSizeMinusOne:3&a[4],sps:[],pps:[]},h=31&a[5];for(d=6,e=0;h>e;e++)c=f.getUint16(d),d+=2,g.sps.push(new Uint8Array(a.subarray(d,d+c))),d+=c;for(b=a[d],d++,e=0;b>e;e++)c=f.getUint16(d),d+=2,g.pps.push(new Uint8Array(a.subarray(d,d+c))),d+=c;return g},btrt:function(a){var b=new DataView(a.buffer,a.byteOffset,a.byteLength);return{bufferSizeDB:b.getUint32(0),maxBitrate:b.getUint32(4),avgBitrate:b.getUint32(8)}},esds:function(a){return{version:a[0],flags:new Uint8Array(a.subarray(1,4)),esId:a[6]<<8|a[7],streamPriority:31&a[8],decoderConfig:{objectProfileIndication:a[11],streamType:a[12]>>>2&63,bufferSize:a[13]<<16|a[14]<<8|a[15],maxBitrate:a[16]<<24|a[17]<<16|a[18]<<8|a[19],avgBitrate:a[20]<<24|a[21]<<16|a[22]<<8|a[23],decoderConfigDescriptor:{tag:a[24],length:a[25],audioObjectType:a[26]>>>3&31,samplingFrequencyIndex:(7&a[26])<<1|a[27]>>>7&1,channelConfiguration:a[27]>>>3&15}}}},ftyp:function(a){for(var b=new DataView(a.buffer,a.byteOffset,a.byteLength),c={majorBrand:e(a.subarray(0,4)),minorVersion:b.getUint32(4),compatibleBrands:[]},d=8;d<a.byteLength;)c.compatibleBrands.push(e(a.subarray(d,d+4))),d+=4;return c},dinf:function(a){return{boxes:c(a)}},dref:function(a){return{version:a[0],flags:new Uint8Array(a.subarray(1,4)),dataReferences:c(a.subarray(8))}},hdlr:function(b){var c=new DataView(b.buffer,b.byteOffset,b.byteLength),d={version:c.getUint8(0),flags:new Uint8Array(b.subarray(1,4)),handlerType:e(b.subarray(8,12)),name:""},f=8;for(f=24;f<b.byteLength;f++){if(0===b[f]){f++;break}d.name+=String.fromCharCode(b[f])}return d.name=decodeURIComponent(a.escape(d.name)),d},mdat:function(a){return{byteLength:a.byteLength,nals:h(a)}},mdhd:function(a){var b,c=new DataView(a.buffer,a.byteOffset,a.byteLength),d=4,e={version:c.getUint8(0),flags:new Uint8Array(a.subarray(1,4)),language:""};return 1===e.version?(d+=4,e.creationTime=f(c.getUint32(d)),d+=8,e.modificationTime=f(c.getUint32(d)),d+=4,e.timescale=c.getUint32(d),d+=8,e.duration=c.getUint32(d)):(e.creationTime=f(c.getUint32(d)),d+=4,e.modificationTime=f(c.getUint32(d)),d+=4,e.timescale=c.getUint32(d),d+=4,e.duration=c.getUint32(d)),d+=4,b=c.getUint16(d),e.language+=String.fromCharCode((b>>10)+96),e.language+=String.fromCharCode(((960&b)>>5)+96),e.language+=String.fromCharCode((31&b)+96),e},mdia:function(a){return{boxes:c(a)}},mfhd:function(a){return{version:a[0],flags:new Uint8Array(a.subarray(1,4)),sequenceNumber:a[4]<<24|a[5]<<16|a[6]<<8|a[7]}},minf:function(a){return{boxes:c(a)}},mp4a:function(a){var b=new DataView(a.buffer,a.byteOffset,a.byteLength),d={dataReferenceIndex:b.getUint16(6),channelcount:b.getUint16(16),samplesize:b.getUint16(18),samplerate:b.getUint16(24)+b.getUint16(26)/65536};return a.byteLength>28&&(d.streamDescriptor=c(a.subarray(28))[0]),d},moof:function(a){return{boxes:c(a)}},moov:function(a){return{boxes:c(a)}},mvex:function(a){return{boxes:c(a)}},mvhd:function(a){var b=new DataView(a.buffer,a.byteOffset,a.byteLength),c=4,d={version:b.getUint8(0),flags:new Uint8Array(a.subarray(1,4))};return 1===d.version?(c+=4,d.creationTime=f(b.getUint32(c)),c+=8,d.modificationTime=f(b.getUint32(c)),c+=4,d.timescale=b.getUint32(c),c+=8,d.duration=b.getUint32(c)):(d.creationTime=f(b.getUint32(c)),c+=4,d.modificationTime=f(b.getUint32(c)),c+=4,d.timescale=b.getUint32(c),c+=4,d.duration=b.getUint32(c)),c+=4,d.rate=b.getUint16(c)+b.getUint16(c+2)/16,c+=4,d.volume=b.getUint8(c)+b.getUint8(c+1)/8,c+=2,c+=2,c+=8,d.matrix=new Uint32Array(a.subarray(c,c+36)),c