Comparing version 5.6.7 to 5.7.0
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i;i="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,i.muxjs=t()}}(function(){return function(){function t(i,e,s){function a(r,o){if(!e[r]){if(!i[r]){var h="function"==typeof require&&require;if(!o&&h)return h(r,!0);if(n)return n(r,!0);var p=new Error("Cannot find module '"+r+"'");throw p.code="MODULE_NOT_FOUND",p}var d=e[r]={exports:{}};i[r][0].call(d.exports,function(t){return a(i[r][1][t]||t)},d,d.exports,t,i,e,s)}return e[r].exports}for(var n="function"==typeof require&&require,r=0;r<s.length;r++)a(s[r]);return a}return t}()({1:[function(t,i,e){"use strict";var s,a=t(17),n=t(15).ONE_SECOND_IN_TS,r=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];s=function(t){var i,e=0;s.prototype.init.call(this),this.push=function(s){var a,o,h,p,d,l,u=0;if(t||(e=0),"audio"===s.type)for(i?(p=i,i=new Uint8Array(p.byteLength+s.data.byteLength),i.set(p),i.set(s.data,p.byteLength)):i=s.data;u+5<i.length;)if(255===i[u]&&240==(246&i[u+1])){if(o=2*(1&~i[u+1]),a=(3&i[u+3])<<11|i[u+4]<<3|(224&i[u+5])>>5,d=1024*(1+(3&i[u+6])),l=d*n/r[(60&i[u+2])>>>2],h=u+a,i.byteLength<h)return;if(this.trigger("data",{pts:s.pts+e*l,dts:s.dts+e*l,sampleCount:d,audioobjecttype:1+(i[u+2]>>>6&3),channelcount:(1&i[u+2])<<2|(192&i[u+3])>>>6,samplerate:r[(60&i[u+2])>>>2],samplingfrequencyindex:(60&i[u+2])>>>2,samplesize:16,data:i.subarray(u+7+o,h)}),e++,i.byteLength===h)return void(i=void 0);i=i.subarray(h)}else u++},this.flush=function(){e=0,this.trigger("done")},this.reset=function(){i=void 0,this.trigger("reset")},this.endTimeline=function(){i=void 0,this.trigger("endedtimeline")}},s.prototype=new a,i.exports=s},{15:15,17:17}],2:[function(t,i,e){"use strict";var s,a,n,r=t(17),o=t(16);a=function(){var t,i,e=0;a.prototype.init.call(this),this.push=function(s){var a;i?(a=new Uint8Array(i.byteLength+s.data.byteLength),a.set(i),a.set(s.data,i.byteLength),i=a):i=s.data;for(var n=i.byteLength;e<n-3;e++)if(1===i[e+2]){t=e+5;break}for(;t<n;)switch(i[t]){case 0:if(0!==i[t-1]){t+=2;break}if(0!==i[t-2]){t++;break}e+3!==t-2&&this.trigger("data",i.subarray(e+3,t-2));do{t++}while(1!==i[t]&&t<n);e=t-2,t+=3;break;case 1:if(0!==i[t-1]||0!==i[t-2]){t+=3;break}this.trigger("data",i.subarray(e+3,t-2)),e=t-2,t+=3;break;default:t+=3}i=i.subarray(e),t-=e,e=0},this.reset=function(){i=null,e=0,this.trigger("reset")},this.flush=function(){i&&i.byteLength>3&&this.trigger("data",i.subarray(e+3)),i=null,e=0,this.trigger("done")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline")}},a.prototype=new r,n={100:!0,110:!0,122:!0,244:!0,44:!0,83:!0,86:!0,118:!0,128:!0,138:!0,139:!0,134:!0},s=function(){var t,i,e,r,h,p,d,l=new a;s.prototype.init.call(this),t=this,this.push=function(t){"video"===t.type&&(i=t.trackId,e=t.pts,r=t.dts,l.push(t))},l.on("data",function(s){var a={trackId:i,pts:e,dts:r,data:s};switch(31&s[0]){case 5:a.nalUnitType="slice_layer_without_partitioning_rbsp_idr";break;case 6:a.nalUnitType="sei_rbsp",a.escapedRBSP=h(s.subarray(1));break;case 7:a.nalUnitType="seq_parameter_set_rbsp",a.escapedRBSP=h(s.subarray(1)),a.config=p(a.escapedRBSP);break;case 8:a.nalUnitType="pic_parameter_set_rbsp";break;case 9:a.nalUnitType="access_unit_delimiter_rbsp"}t.trigger("data",a)}),l.on("done",function(){t.trigger("done")}),l.on("partialdone",function(){t.trigger("partialdone")}),l.on("reset",function(){t.trigger("reset")}),l.on("endedtimeline",function(){t.trigger("endedtimeline")}),this.flush=function(){l.flush()},this.partialFlush=function(){l.partialFlush()},this.reset=function(){l.reset()},this.endTimeline=function(){l.endTimeline()},d=function(t,i){var e,s,a=8,n=8;for(e=0;e<t;e++)0!==n&&(s=i.readExpGolomb(),n=(a+s+256)%256),a=0===n?a:n},h=function(t){for(var i,e,s=t.byteLength,a=[],n=1;n<s-2;)0===t[n]&&0===t[n+1]&&3===t[n+2]?(a.push(n+2),n+=2):n++;if(0===a.length)return t;i=s-a.length,e=new Uint8Array(i);var r=0;for(n=0;n<i;r++,n++)r===a[0]&&(r++,a.shift()),e[n]=t[r];return e},p=function(t){var i,e,s,a,r,h,p,l,u,c,f,g,y,m=0,_=0,T=0,b=0,v=1;if(i=new o(t),e=i.readUnsignedByte(),a=i.readUnsignedByte(),s=i.readUnsignedByte(),i.skipUnsignedExpGolomb(),n[e]&&(r=i.readUnsignedExpGolomb(),3===r&&i.skipBits(1),i.skipUnsignedExpGolomb(),i.skipUnsignedExpGolomb(),i.skipBits(1),i.readBoolean()))for(f=3!==r?8:12,y=0;y<f;y++)i.readBoolean()&&(y<6?d(16,i):d(64,i));if(i.skipUnsignedExpGolomb(),0===(h=i.readUnsignedExpGolomb()))i.readUnsignedExpGolomb();else if(1===h)for(i.skipBits(1),i.skipExpGolomb(),i.skipExpGolomb(),p=i.readUnsignedExpGolomb(),y=0;y<p;y++)i.skipExpGolomb();if(i.skipUnsignedExpGolomb(),i.skipBits(1),l=i.readUnsignedExpGolomb(),u=i.readUnsignedExpGolomb(),c=i.readBits(1),0===c&&i.skipBits(1),i.skipBits(1),i.readBoolean()&&(m=i.readUnsignedExpGolomb(),_=i.readUnsignedExpGolomb(),T=i.readUnsignedExpGolomb(),b=i.readUnsignedExpGolomb()),i.readBoolean()&&i.readBoolean()){switch(i.readUnsignedByte()){case 1:g=[1,1];break;case 2:g=[12,11];break;case 3:g=[10,11];break;case 4:g=[16,11];break;case 5:g=[40,33];break;case 6:g=[24,11];break;case 7:g=[20,11];break;case 8:g=[32,11];break;case 9:g=[80,33];break;case 10:g=[18,11];break;case 11:g=[15,11];break;case 12:g=[64,33];break;case 13:g=[160,99];break;case 14:g=[4,3];break;case 15:g=[3,2];break;case 16:g=[2,1];break;case 255:g=[i.readUnsignedByte()<<8|i.readUnsignedByte(),i.readUnsignedByte()<<8|i.readUnsignedByte()]}g&&(v=g[0]/g[1])}return{profileIdc:e,levelIdc:s,profileCompatibility:a,width:Math.ceil((16*(l+1)-2*m-2*_)*v),height:(2-c)*(u+1)*16-2*T-2*b,sarRatio:g}}},s.prototype=new r,i.exports={H264Stream:s,NalByteStream:a}},{16:16,17:17}],3:[function(t,i,e){"use strict";var s=t(17),a=function(t){this.numberOfTracks=0,this.metadataStream=t.metadataStream,this.videoTags=[],this.audioTags=[],this.videoTrack=null,this.audioTrack=null,this.pendingCaptions=[],this.pendingMetadata=[],this.pendingTracks=0,this.processedTracks=0,a.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++)))}};a.prototype=new s,a.prototype.flush=function(t){var i,e,s,a,n={tags:{},captions:[],captionStreams:{},metadata:[]};if(this.pendingTracks<this.numberOfTracks){if("VideoSegmentStream"!==t&&"AudioSegmentStream"!==t)return;if(0===this.pendingTracks&&++this.processedTracks<this.numberOfTracks)return}if(this.processedTracks+=this.pendingTracks,this.pendingTracks=0,!(this.processedTracks<this.numberOfTracks)){for(this.videoTrack?a=this.videoTrack.timelineStartInfo.pts:this.audioTrack&&(a=this.audioTrack.timelineStartInfo.pts),n.tags.videoTags=this.videoTags,n.tags.audioTags=this.audioTags,s=0;s<this.pendingCaptions.length;s++)e=this.pendingCaptions[s],e.startTime=e.startPts-a,e.startTime/=9e4,e.endTime=e.endPts-a,e.endTime/=9e4,n.captionStreams[e.stream]=!0,n.captions.push(e);for(s=0;s<this.pendingMetadata.length;s++)i=this.pendingMetadata[s],i.cueTime=i.pts-a,i.cueTime/=9e4,n.metadata.push(i);n.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.processedTracks=0,this.trigger("data",n),this.trigger("done")}},i.exports=a},{17:17}],4:[function(t,i,e){"use strict";var s=t(5),a=function(t,i,e){var a,n,r,o=new Uint8Array(9),h=new DataView(o.buffer);return t=t||0,i=void 0===i||i,e=void 0===e||e,h.setUint8(0,70),h.setUint8(1,76),h.setUint8(2,86),h.setUint8(3,1),h.setUint8(4,(i?4:0)|(e?1:0)),h.setUint32(5,o.byteLength),t<=0?(n=new Uint8Array(o.byteLength+4),n.set(o),n.set([0,0,0,0],o.byteLength),n):(a=new s(s.METADATA_TAG),a.pts=a.dts=0,a.writeMetaDataDouble("duration",t),r=a.finalize().length,n=new Uint8Array(o.byteLength+r),n.set(o),n.set(h.byteLength,r),n)};i.exports=a},{5:5}],5:[function(t,i,e){"use strict";var s;s=function(t,i){var e,a=0,n=16384,r=function(t,i){var e,s=t.position+i;s<t.bytes.byteLength||(e=new Uint8Array(2*s),e.set(t.bytes.subarray(0,t.position),0),t.bytes=e,t.view=new DataView(t.bytes.buffer))},o=s.widthBytes||new Uint8Array("width".length),h=s.heightBytes||new Uint8Array("height".length),p=s.videocodecidBytes||new Uint8Array("videocodecid".length);if(!s.widthBytes){for(e=0;e<"width".length;e++)o[e]="width".charCodeAt(e);for(e=0;e<"height".length;e++)h[e]="height".charCodeAt(e);for(e=0;e<"videocodecid".length;e++)p[e]="videocodecid".charCodeAt(e);s.widthBytes=o,s.heightBytes=h,s.videocodecidBytes=p}switch(this.keyFrame=!1,t){case s.VIDEO_TAG:this.length=16,n*=6;break;case s.AUDIO_TAG:this.length=13,this.keyFrame=!0;break;case s.METADATA_TAG:this.length=29,this.keyFrame=!0;break;default:throw new Error("Unknown FLV tag type")}this.bytes=new Uint8Array(n),this.view=new DataView(this.bytes.buffer),this.bytes[0]=t,this.position=this.length,this.keyFrame=i,this.pts=0,this.dts=0,this.writeBytes=function(t,i,e){var s,a=i||0;e=e||t.byteLength,s=a+e,r(this,e),this.bytes.set(t.subarray(a,s),this.position),this.position+=e,this.length=Math.max(this.length,this.position)},this.writeByte=function(t){r(this,1),this.bytes[this.position]=t,this.position++,this.length=Math.max(this.length,this.position)},this.writeShort=function(t){r(this,2),this.view.setUint16(this.position,t),this.position+=2,this.length=Math.max(this.length,this.position)},this.negIndex=function(t){return this.bytes[this.length-t]},this.nalUnitSize=function(){return 0===a?0:this.length-(a+4)},this.startNalUnit=function(){if(a>0)throw new Error("Attempted to create new NAL wihout closing the old one");a=this.length,this.length+=4,this.position=this.length},this.endNalUnit=function(t){var i,e;this.length===a+4?this.length-=4:a>0&&(i=a+4,e=this.length-i,this.position=a,this.view.setUint32(this.position,e),this.position=this.length,t&&t.push(this.bytes.subarray(i,i+e))),a=0},this.writeMetaDataDouble=function(t,i){var e;if(r(this,2+t.length+9),this.view.setUint16(this.position,t.length),this.position+=2,"width"===t)this.bytes.set(o,this.position),this.position+=5;else if("height"===t)this.bytes.set(h,this.position),this.position+=6;else if("videocodecid"===t)this.bytes.set(p,this.position),this.position+=12;else for(e=0;e<t.length;e++)this.bytes[this.position]=t.charCodeAt(e),this.position++;this.position++,this.view.setFloat64(this.position,i),this.position+=8,this.length=Math.max(this.length,this.position),++a},this.writeMetaDataBoolean=function(t,i){var e;for(r(this,2),this.view.setUint16(this.position,t.length),this.position+=2,e=0;e<t.length;e++)r(this,1),this.bytes[this.position]=t.charCodeAt(e),this.position++;r(this,2),this.view.setUint8(this.position,1),this.position++,this.view.setUint8(this.position,i?1:0),this.position++,this.length=Math.max(this.length,this.position),++a},this.finalize=function(){var t,e;switch(this.bytes[0]){case s.VIDEO_TAG:this.bytes[11]=7|(this.keyFrame||i?16:32),this.bytes[12]=i?0:1,t=this.pts-this.dts,this.bytes[13]=(16711680&t)>>>16,this.bytes[14]=(65280&t)>>>8,this.bytes[15]=(255&t)>>>0;break;case s.AUDIO_TAG:this.bytes[11]=175,this.bytes[12]=i?0:1;break;case s.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,a),this.position=this.length,this.bytes.set([0,0,9],this.position),this.position+=3,this.length=this.position}return e=this.length-11,this.bytes[1]=(16711680&e)>>>16,this.bytes[2]=(65280&e)>>>8,this.bytes[3]=(255&e)>>>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=s.frameTime(this.bytes),this}},s.AUDIO_TAG=8,s.VIDEO_TAG=9,s.METADATA_TAG=18,s.isAudioFrame=function(t){return s.AUDIO_TAG===t[0]},s.isVideoFrame=function(t){return s.VIDEO_TAG===t[0]},s.isMetaData=function(t){return s.METADATA_TAG===t[0]},s.isKeyFrame=function(t){return s.isVideoFrame(t)?23===t[11]:!!s.isAudioFrame(t)||!!s.isMetaData(t)},s.frameTime=function(t){var i=t[4]<<16;return i|=t[5]<<8,i|=t[6]<<0,i|=t[7]<<24},i.exports=s},{}],6:[function(t,i,e){i.exports={tag:t(5),Transmuxer:t(8),getFlvHeader:t(4)}},{4:4,5:5,8:8}],7:[function(t,i,e){"use strict";var s=function(){var t=this;this.list=[],this.push=function(t){this.list.push({bytes:t.bytes,dts:t.dts,pts:t.pts,keyFrame:t.keyFrame,metaDataTag:t.metaDataTag})},Object.defineProperty(this,"length",{get:function(){return t.list.length}})};i.exports=s},{}],8:[function(t,i,e){"use strict";var s,a,n,r,o,h,p=t(17),d=t(5),l=t(10),u=t(1),c=t(2).H264Stream,f=t(3),g=t(7);r=function(t,i){"number"==typeof i.pts&&(void 0===t.timelineStartInfo.pts?t.timelineStartInfo.pts=i.pts:t.timelineStartInfo.pts=Math.min(t.timelineStartInfo.pts,i.pts)),"number"==typeof i.dts&&(void 0===t.timelineStartInfo.dts?t.timelineStartInfo.dts=i.dts:t.timelineStartInfo.dts=Math.min(t.timelineStartInfo.dts,i.dts))},o=function(t,i){var e=new d(d.METADATA_TAG);return e.dts=i,e.pts=i,e.writeMetaDataDouble("videocodecid",7),e.writeMetaDataDouble("width",t.width),e.writeMetaDataDouble("height",t.height),e},h=function(t,i){var e,s=new d(d.VIDEO_TAG,!0);for(s.dts=i,s.pts=i,s.writeByte(1),s.writeByte(t.profileIdc),s.writeByte(t.profileCompatibility),s.writeByte(t.levelIdc),s.writeByte(255),s.writeByte(225),s.writeShort(t.sps[0].length),s.writeBytes(t.sps[0]),s.writeByte(t.pps.length),e=0;e<t.pps.length;++e)s.writeShort(t.pps[e].length),s.writeBytes(t.pps[e]);return s},n=function(t){var i,e=[],s=[];n.prototype.init.call(this),this.push=function(i){r(t,i),t&&(t.audioobjecttype=i.audioobjecttype,t.channelcount=i.channelcount,t.samplerate=i.samplerate,t.samplingfrequencyindex=i.samplingfrequencyindex,t.samplesize=i.samplesize,t.extraData=t.audioobjecttype<<11|t.samplingfrequencyindex<<7|t.channelcount<<3),i.pts=Math.round(i.pts/90),i.dts=Math.round(i.dts/90),e.push(i)},this.flush=function(){var a,n,r,o=new g;if(0===e.length)return void this.trigger("done","AudioSegmentStream");for(r=-1/0;e.length;)a=e.shift(),s.length&&a.pts>=s[0]&&(r=s.shift(),this.writeMetaDataTags(o,r)),(t.extraData!==i||a.pts-r>=1e3)&&(this.writeMetaDataTags(o,a.pts),i=t.extraData,r=a.pts),n=new d(d.AUDIO_TAG),n.pts=a.pts,n.dts=a.dts,n.writeBytes(a.data),o.push(n.finalize());s.length=0,i=null,this.trigger("data",{track:t,tags:o.list}),this.trigger("done","AudioSegmentStream")},this.writeMetaDataTags=function(i,e){var s;s=new d(d.METADATA_TAG),s.pts=e,s.dts=e,s.writeMetaDataDouble("audiocodecid",10),s.writeMetaDataBoolean("stereo",2===t.channelcount),s.writeMetaDataDouble("audiosamplerate",t.samplerate),s.writeMetaDataDouble("audiosamplesize",16),i.push(s.finalize()),s=new d(d.AUDIO_TAG,!0),s.pts=e,s.dts=e,s.view.setUint16(s.position,t.extraData),s.position+=2,s.length=Math.max(s.length,s.position),i.push(s.finalize())},this.onVideoKeyFrame=function(t){s.push(t)}},n.prototype=new p,a=function(t){var i,e,s=[];a.prototype.init.call(this),this.finishFrame=function(s,a){if(a){if(i&&t&&t.newMetadata&&(a.keyFrame||0===s.length)){var n=o(i,a.dts).finalize(),r=h(t,a.dts).finalize();n.metaDataTag=r.metaDataTag=!0,s.push(n),s.push(r),t.newMetadata=!1,this.trigger("keyframe",a.dts)}a.endNalUnit(),s.push(a.finalize()),e=null}},this.push=function(i){r(t,i),i.pts=Math.round(i.pts/90),i.dts=Math.round(i.dts/90),s.push(i)},this.flush=function(){for(var a,n=new g;s.length&&"access_unit_delimiter_rbsp"!==s[0].nalUnitType;)s.shift();if(0===s.length)return void this.trigger("done","VideoSegmentStream");for(;s.length;)a=s.shift(),"seq_parameter_set_rbsp"===a.nalUnitType?(t.newMetadata=!0,i=a.config,t.width=i.width,t.height=i.height,t.sps=[a.data],t.profileIdc=i.profileIdc,t.levelIdc=i.levelIdc,t.profileCompatibility=i.profileCompatibility,e.endNalUnit()):"pic_parameter_set_rbsp"===a.nalUnitType?(t.newMetadata=!0,t.pps=[a.data],e.endNalUnit()):"access_unit_delimiter_rbsp"===a.nalUnitType?(e&&this.finishFrame(n,e),e=new d(d.VIDEO_TAG),e.pts=a.pts,e.dts=a.dts):("slice_layer_without_partitioning_rbsp_idr"===a.nalUnitType&&(e.keyFrame=!0),e.endNalUnit()),e.startNalUnit(),e.writeBytes(a.data);e&&this.finishFrame(n,e),this.trigger("data",{track:t,tags:n.list}),this.trigger("done","VideoSegmentStream")}},a.prototype=new p,s=function(t){var i,e,r,o,h,p,d,g,y,m,_,T,b=this;s.prototype.init.call(this),t=t||{},this.metadataStream=new l.MetadataStream,t.metadataStream=this.metadataStream,i=new l.TransportPacketStream,e=new l.TransportParseStream,r=new l.ElementaryStream,o=new l.TimestampRolloverStream("video"),h=new l.TimestampRolloverStream("audio"),p=new l.TimestampRolloverStream("timed-metadata"),d=new u,g=new c,T=new f(t),i.pipe(e).pipe(r),r.pipe(o).pipe(g),r.pipe(h).pipe(d),r.pipe(p).pipe(this.metadataStream).pipe(T),_=new l.CaptionStream,g.pipe(_).pipe(T),r.on("data",function(t){var i,e,s;if("metadata"===t.type){for(i=t.tracks.length;i--;)"video"===t.tracks[i].type?e=t.tracks[i]:"audio"===t.tracks[i].type&&(s=t.tracks[i]);e&&!y&&(T.numberOfTracks++,y=new a(e),g.pipe(y).pipe(T)),s&&!m&&(T.numberOfTracks++,m=new n(s),d.pipe(m).pipe(T),y&&y.on("keyframe",m.onVideoKeyFrame))}}),this.push=function(t){i.push(t)},this.flush=function(){i.flush()},this.resetCaptions=function(){_.reset()},T.on("data",function(t){b.trigger("data",t)}),T.on("done",function(){b.trigger("done")})},s.prototype=new p,i.exports=s},{1:1,10:10,17:17,2:2,3:3,5:5,7:7}],9:[function(t,i,e){"use strict";var s=t(17),a=t(14),n=function(){n.prototype.init.call(this),this.captionPackets_=[],this.ccStreams_=[new d(0,0),new d(0,1),new d(1,0),new d(1,1)],this.reset(),this.ccStreams_.forEach(function(t){t.on("data",this.trigger.bind(this,"data")),t.on("partialdone",this.trigger.bind(this,"partialdone")),t.on("done",this.trigger.bind(this,"done"))},this)};n.prototype=new s,n.prototype.push=function(t){var i,e,s;if("sei_rbsp"===t.nalUnitType&&(i=a.parseSei(t.escapedRBSP),i.payloadType===a.USER_DATA_REGISTERED_ITU_T_T35&&(e=a.parseUserData(i)))){if(t.dts<this.latestDts_)return void(this.ignoreNextEqualDts_=!0);if(t.dts===this.latestDts_&&this.ignoreNextEqualDts_)return void(--this.numSameDts_||(this.ignoreNextEqualDts_=!1));s=a.parseCaptionPackets(t.pts,e),this.captionPackets_=this.captionPackets_.concat(s),this.latestDts_!==t.dts&&(this.numSameDts_=0),this.numSameDts_++,this.latestDts_=t.dts}},n.prototype.flushCCStreams=function(t){this.ccStreams_.forEach(function(i){return"flush"===t?i.flush():i.partialFlush()},this)},n.prototype.flushStream=function(t){if(!this.captionPackets_.length)return void this.flushCCStreams(t);this.captionPackets_.forEach(function(t,i){t.presortIndex=i}),this.captionPackets_.sort(function(t,i){return t.pts===i.pts?t.presortIndex-i.presortIndex:t.pts-i.pts}),this.captionPackets_.forEach(function(t){t.type<2&&this.dispatchCea608Packet(t)},this),this.captionPackets_.length=0,this.flushCCStreams(t)},n.prototype.flush=function(){return this.flushStream("flush")},n.prototype.partialFlush=function(){return this.flushStream("partialFlush")},n.prototype.reset=function(){this.latestDts_=null,this.ignoreNextEqualDts_=!1,this.numSameDts_=0,this.activeCea608Channel_=[null,null],this.ccStreams_.forEach(function(t){t.reset()})},n.prototype.dispatchCea608Packet=function(t){this.setsTextOrXDSActive(t)?this.activeCea608Channel_[t.type]=null:this.setsChannel1Active(t)?this.activeCea608Channel_[t.type]=0:this.setsChannel2Active(t)&&(this.activeCea608Channel_[t.type]=1),null!==this.activeCea608Channel_[t.type]&&this.ccStreams_[(t.type<<1)+this.activeCea608Channel_[t.type]].push(t)},n.prototype.setsChannel1Active=function(t){return 4096==(30720&t.ccData)},n.prototype.setsChannel2Active=function(t){return 6144==(30720&t.ccData)},n.prototype.setsTextOrXDSActive=function(t){return 256==(28928&t.ccData)||4138==(30974&t.ccData)||6186==(30974&t.ccData)};var r={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},o=function(t){return null===t?"":(t=r[t]||t,String.fromCharCode(t))},h=[4352,4384,4608,4640,5376,5408,5632,5664,5888,5920,4096,4864,4896,5120,5152],p=function(){for(var t=[],i=15;i--;)t.push("");return t},d=function(t,i){d.prototype.init.call(this),this.field_=t||0,this.dataChannel_=i||0,this.name_="CC"+(1+(this.field_<<1|this.dataChannel_)),this.setConstants(),this.reset(),this.push=function(t){var i,e,s,a,n;if((i=32639&t.ccData)===this.lastControlCode_)return void(this.lastControlCode_=null);if(4096==(61440&i)?this.lastControlCode_=i:i!==this.PADDING_&&(this.lastControlCode_=null),s=i>>>8,a=255&i,i!==this.PADDING_)if(i===this.RESUME_CAPTION_LOADING_)this.mode_="popOn";else if(i===this.END_OF_CAPTION_)this.mode_="popOn",this.clearFormatting(t.pts),this.flushDisplayed(t.pts),e=this.displayed_,this.displayed_=this.nonDisplayed_,this.nonDisplayed_=e,this.startPts_=t.pts;else if(i===this.ROLL_UP_2_ROWS_)this.rollUpRows_=2,this.setRollUp(t.pts);else if(i===this.ROLL_UP_3_ROWS_)this.rollUpRows_=3,this.setRollUp(t.pts);else if(i===this.ROLL_UP_4_ROWS_)this.rollUpRows_=4,this.setRollUp(t.pts);else if(i===this.CARRIAGE_RETURN_)this.clearFormatting(t.pts),this.flushDisplayed(t.pts),this.shiftRowsUp_(),this.startPts_=t.pts;else if(i===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(i===this.ERASE_DISPLAYED_MEMORY_)this.flushDisplayed(t.pts),this.displayed_=p();else if(i===this.ERASE_NON_DISPLAYED_MEMORY_)this.nonDisplayed_=p();else if(i===this.RESUME_DIRECT_CAPTIONING_)"paintOn"!==this.mode_&&(this.flushDisplayed(t.pts),this.displayed_=p()),this.mode_="paintOn",this.startPts_=t.pts;else if(this.isSpecialCharacter(s,a))s=(3&s)<<8,n=o(s|a),this[this.mode_](t.pts,n),this.column_++;else if(this.isExtCharacter(s,a))"popOn"===this.mode_?this.nonDisplayed_[this.row_]=this.nonDisplayed_[this.row_].slice(0,-1):this.displayed_[this.row_]=this.displayed_[this.row_].slice(0,-1),s=(3&s)<<8,n=o(s|a),this[this.mode_](t.pts,n),this.column_++;else if(this.isMidRowCode(s,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(s,a))this.column_+=3&a;else if(this.isPAC(s,a)){var r=h.indexOf(7968&i);"rollUp"===this.mode_&&(r-this.rollUpRows_+1<0&&(r=this.rollUpRows_-1),this.setRollUp(t.pts,r)),r!==this.row_&&(this.clearFormatting(t.pts),this.row_=r),1&a&&-1===this.formatting_.indexOf("u")&&this.addFormatting(t.pts,["u"]),16==(16&i)&&(this.column_=4*((14&i)>>1)),this.isColorPAC(a)&&14==(14&a)&&this.addFormatting(t.pts,["i"])}else this.isNormalChar(s)&&(0===a&&(a=null),n=o(s),n+=o(a),this[this.mode_](t.pts,n),this.column_+=n.length)}};d.prototype=new s,d.prototype.flushDisplayed=function(t){var i=this.displayed_.map(function(t){try{return t.trim()}catch(t){return console.error("Skipping malformed caption."),""}}).join("\n").replace(/^\n+|\n+$/g,"");i.length&&this.trigger("data",{startPts:this.startPts_,endPts:t,text:i,stream:this.name_})},d.prototype.reset=function(){this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=p(),this.nonDisplayed_=p(),this.lastControlCode_=null,this.column_=0,this.row_=14,this.rollUpRows_=2,this.formatting_=[]},d.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_},d.prototype.isSpecialCharacter=function(t,i){return t===this.EXT_&&i>=48&&i<=63},d.prototype.isExtCharacter=function(t,i){return(t===this.EXT_+1||t===this.EXT_+2)&&i>=32&&i<=63},d.prototype.isMidRowCode=function(t,i){return t===this.EXT_&&i>=32&&i<=47},d.prototype.isOffsetControlCode=function(t,i){return t===this.OFFSET_&&i>=33&&i<=35},d.prototype.isPAC=function(t,i){return t>=this.BASE_&&t<this.BASE_+8&&i>=64&&i<=127},d.prototype.isColorPAC=function(t){return t>=64&&t<=79||t>=96&&t<=127},d.prototype.isNormalChar=function(t){return t>=32&&t<=127},d.prototype.setRollUp=function(t,i){if("rollUp"!==this.mode_&&(this.row_=14,this.mode_="rollUp",this.flushDisplayed(t),this.nonDisplayed_=p(),this.displayed_=p()),void 0!==i&&i!==this.row_)for(var e=0;e<this.rollUpRows_;e++)this.displayed_[i-e]=this.displayed_[this.row_-e],this.displayed_[this.row_-e]="";void 0===i&&(i=this.row_),this.topRow_=i-this.rollUpRows_+1},d.prototype.addFormatting=function(t,i){this.formatting_=this.formatting_.concat(i);var e=i.reduce(function(t,i){return t+"<"+i+">"},"");this[this.mode_](t,e)},d.prototype.clearFormatting=function(t){if(this.formatting_.length){var i=this.formatting_.reverse().reduce(function(t,i){return t+"</"+i+">"},"");this.formatting_=[],this[this.mode_](t,i)}},d.prototype.popOn=function(t,i){var e=this.nonDisplayed_[this.row_];e+=i,this.nonDisplayed_[this.row_]=e},d.prototype.rollUp=function(t,i){var e=this.displayed_[this.row_];e+=i,this.displayed_[this.row_]=e},d.prototype.shiftRowsUp_=function(){var t;for(t=0;t<this.topRow_;t++)this.displayed_[t]="";for(t=this.row_+1;t<15;t++)this.displayed_[t]="";for(t=this.topRow_;t<this.row_;t++)this.displayed_[t]=this.displayed_[t+1];this.displayed_[this.row_]=""},d.prototype.paintOn=function(t,i){var e=this.displayed_[this.row_];e+=i,this.displayed_[this.row_]=e},i.exports={CaptionStream:n,Cea608Stream:d}},{14:14,17:17}],10:[function(t,i,e){"use strict";var s,a,n,r=t(17),o=t(9),h=t(12),p=t(13).TimestampRolloverStream;s=function(){var t=new Uint8Array(188),i=0;s.prototype.init.call(this),this.push=function(e){var s,a=0,n=188;for(i?(s=new Uint8Array(e.byteLength+i),s.set(t.subarray(0,i)),s.set(e,i),i=0):s=e;n<s.byteLength;)71!==s[a]||71!==s[n]?(a++,n++):(this.trigger("data",s.subarray(a,n)),a+=188,n+=188);a<s.byteLength&&(t.set(s.subarray(a),0),i=s.byteLength-a)},this.flush=function(){188===i&&71===t[0]&&(this.trigger("data",t),i=0),this.trigger("done")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline")},this.reset=function(){i=0,this.trigger("reset")}},s.prototype=new r,a=function(){var t,i,e,s;a.prototype.init.call(this),s=this,this.packetsWaitingForPmt=[],this.programMapTable=void 0,t=function(t,s){var a=0;s.payloadUnitStartIndicator&&(a+=t[a]+1),"pat"===s.type?i(t.subarray(a),s):e(t.subarray(a),s)},i=function(t,i){i.section_number=t[7],i.last_section_number=t[8],s.pmtPid=(31&t[10])<<8|t[11],i.pmtPid=s.pmtPid},e=function(t,i){var e,a,n,r;if(1&t[5]){for(s.programMapTable={video:null,audio:null,"timed-metadata":{}},e=(15&t[1])<<8|t[2],a=3+e-4,n=(15&t[10])<<8|t[11],r=12+n;r<a;){var o=t[r],p=(31&t[r+1])<<8|t[r+2];o===h.H264_STREAM_TYPE&&null===s.programMapTable.video?s.programMapTable.video=p:o===h.ADTS_STREAM_TYPE&&null===s.programMapTable.audio?s.programMapTable.audio=p:o===h.METADATA_STREAM_TYPE&&(s.programMapTable["timed-metadata"][p]=o),r+=5+((15&t[r+3])<<8|t[r+4])}i.programMapTable=s.programMapTable}},this.push=function(i){var e={},s=4;if(e.payloadUnitStartIndicator=!!(64&i[1]),e.pid=31&i[1],e.pid<<=8,e.pid|=i[2],(48&i[3])>>>4>1&&(s+=i[s]+1),0===e.pid)e.type="pat",t(i.subarray(s),e),this.trigger("data",e);else if(e.pid===this.pmtPid)for(e.type="pmt",t(i.subarray(s),e),this.trigger("data",e);this.packetsWaitingForPmt.length;)this.processPes_.apply(this,this.packetsWaitingForPmt.shift());else void 0===this.programMapTable?this.packetsWaitingForPmt.push([i,s,e]):this.processPes_(i,s,e)},this.processPes_=function(t,i,e){e.pid===this.programMapTable.video?e.streamType=h.H264_STREAM_TYPE:e.pid===this.programMapTable.audio?e.streamType=h.ADTS_STREAM_TYPE:e.streamType=this.programMapTable["timed-metadata"][e.pid],e.type="pes",e.data=t.subarray(i),this.trigger("data",e)}},a.prototype=new r,a.STREAM_TYPES={h264:27,adts:15},n=function(){var t,i=this,e={data:[],size:0},s={data:[],size:0},a={data:[],size:0},r=function(t,i){var e;i.packetLength=6+(t[4]<<8|t[5]),i.dataAlignmentIndicator=0!=(4&t[6]),e=t[7],192&e&&(i.pts=(14&t[9])<<27|(255&t[10])<<20|(254&t[11])<<12|(255&t[12])<<5|(254&t[13])>>>3,i.pts*=4,i.pts+=(6&t[13])>>>1,i.dts=i.pts,64&e&&(i.dts=(14&t[14])<<27|(255&t[15])<<20|(254&t[16])<<12|(255&t[17])<<5|(254&t[18])>>>3,i.dts*=4,i.dts+=(6&t[18])>>>1)),i.data=t.subarray(9+t[8])},o=function(t,e,s){var a,n=new Uint8Array(t.size),o={type:e},h=0,p=0,d=!1;if(t.data.length&&!(t.size<9)){for(o.trackId=t.data[0].pid,h=0;h<t.data.length;h++)a=t.data[h],n.set(a.data,p),p+=a.data.byteLength;r(n,o),d="video"===e||o.packetLength<=t.size,(s||d)&&(t.size=0,t.data.length=0),d&&i.trigger("data",o)}};n.prototype.init.call(this),this.push=function(n){({pat:function(){},pes:function(){var t,i;switch(n.streamType){case h.H264_STREAM_TYPE:t=e,i="video";break;case h.ADTS_STREAM_TYPE:t=s,i="audio";break;case h.METADATA_STREAM_TYPE:t=a,i="timed-metadata";break;default:return}n.payloadUnitStartIndicator&&o(t,i,!0),t.data.push(n),t.size+=n.data.byteLength},pmt:function(){var e={type:"metadata",tracks:[]};t=n.programMapTable,null!==t.video&&e.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.video,codec:"avc",type:"video"}),null!==t.audio&&e.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.audio,codec:"adts",type:"audio"}),i.trigger("data",e)}})[n.type]()},this.reset=function(){e.size=0,e.data.length=0,s.size=0,s.data.length=0,this.trigger("reset")},this.flushStreams_=function(){o(e,"video"),o(s,"audio"),o(a,"timed-metadata")},this.flush=function(){this.flushStreams_(),this.trigger("done")}},n.prototype=new r;var d={PAT_PID:0,MP2T_PACKET_LENGTH:188,TransportPacketStream:s,TransportParseStream:a,ElementaryStream:n,TimestampRolloverStream:p,CaptionStream:o.CaptionStream,Cea608Stream:o.Cea608Stream,MetadataStream:t(11)};for(var l in h)h.hasOwnProperty(l)&&(d[l]=h[l]);i.exports=d},{11:11,12:12,13:13,17:17,9:9}],11:[function(t,i,e){"use strict";var s,a=t(17),n=t(12),r=function(t,i,e){var s,a="";for(s=i;s<e;s++)a+="%"+("00"+t[s].toString(16)).slice(-2);return a},o=function(t,i,e){return decodeURIComponent(r(t,i,e))},h=function(t,i,e){return unescape(r(t,i,e))},p=function(t){return t[0]<<21|t[1]<<14|t[2]<<7|t[3]},d={TXXX:function(t){var i;if(3===t.data[0]){for(i=1;i<t.data.length;i++)if(0===t.data[i]){t.description=o(t.data,1,i),t.value=o(t.data,i+1,t.data.length).replace(/\0*$/,"");break}t.data=t.value}},WXXX:function(t){var i;if(3===t.data[0])for(i=1;i<t.data.length;i++)if(0===t.data[i]){t.description=o(t.data,1,i), | ||
t.url=o(t.data,i+1,t.data.length);break}},PRIV:function(t){var i;for(i=0;i<t.data.length;i++)if(0===t.data[i]){t.owner=h(t.data,0,i);break}t.privateData=t.data.subarray(i+1),t.data=t.privateData}};s=function(t){var i,e={debug:!(!t||!t.debug),descriptor:t&&t.descriptor},a=0,r=[],o=0;if(s.prototype.init.call(this),this.dispatchType=n.METADATA_STREAM_TYPE.toString(16),e.descriptor)for(i=0;i<e.descriptor.length;i++)this.dispatchType+=("00"+e.descriptor[i].toString(16)).slice(-2);this.push=function(t){var i,s,n,h,l,u;if("timed-metadata"===t.type){if(t.dataAlignmentIndicator&&(o=0,r.length=0),0===r.length&&(t.data.length<10||t.data[0]!=="I".charCodeAt(0)||t.data[1]!=="D".charCodeAt(0)||t.data[2]!=="3".charCodeAt(0)))return void(e.debug&&console.log("Skipping unrecognized metadata packet"));if(r.push(t),o+=t.data.byteLength,1===r.length&&(a=p(t.data.subarray(6,10)),a+=10),!(o<a)){for(i={data:new Uint8Array(a),frames:[],pts:r[0].pts,dts:r[0].dts},l=0;l<a;)i.data.set(r[0].data.subarray(0,a-l),l),l+=r[0].data.byteLength,o-=r[0].data.byteLength,r.shift();s=10,64&i.data[5]&&(s+=4,s+=p(i.data.subarray(10,14)),a-=p(i.data.subarray(16,20)));do{if((n=p(i.data.subarray(s+4,s+8)))<1)return console.log("Malformed ID3 frame encountered. Skipping metadata parsing.");if(u=String.fromCharCode(i.data[s],i.data[s+1],i.data[s+2],i.data[s+3]),h={id:u,data:i.data.subarray(s+10,s+n+10)},h.key=h.id,d[h.id]&&(d[h.id](h),"com.apple.streaming.transportStreamTimestamp"===h.owner)){var c=h.data,f=(1&c[3])<<30|c[4]<<22|c[5]<<14|c[6]<<6|c[7]>>>2;f*=4,f+=3&c[7],h.timeStamp=f,void 0===i.pts&&void 0===i.dts&&(i.pts=h.timeStamp,i.dts=h.timeStamp),this.trigger("timestamp",h)}i.frames.push(h),s+=10,s+=n}while(s<a);this.trigger("data",i)}}}},s.prototype=new a,i.exports=s},{12:12,17:17}],12:[function(t,i,e){"use strict";i.exports={H264_STREAM_TYPE:27,ADTS_STREAM_TYPE:15,METADATA_STREAM_TYPE:21}},{}],13:[function(t,i,e){"use strict";var s=t(17),a=function(t,i){var e=1;for(t>i&&(e=-1);Math.abs(i-t)>4294967296;)t+=8589934592*e;return t},n=function(t){var i,e;n.prototype.init.call(this),this.type_=t||"shared",this.push=function(t){"shared"!==this.type_&&t.type!==this.type_||(void 0===e&&(e=t.dts),t.dts=a(t.dts,e),t.pts=a(t.pts,e),i=t.dts,this.trigger("data",t))},this.flush=function(){e=i,this.trigger("done")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline")},this.discontinuity=function(){e=void 0,i=void 0},this.reset=function(){this.discontinuity(),this.trigger("reset")}};n.prototype=new s,i.exports={TimestampRolloverStream:n,handleRollover:a}},{17:17}],14:[function(t,i,e){"use strict";var s=function(t){for(var i=0,e={payloadType:-1,payloadSize:0},s=0,a=0;i<t.byteLength&&128!==t[i];){for(;255===t[i];)s+=255,i++;for(s+=t[i++];255===t[i];)a+=255,i++;if(a+=t[i++],!e.payload&&4===s){if("GA94"===String.fromCharCode(t[i+3],t[i+4],t[i+5],t[i+6])){e.payloadType=s,e.payloadSize=a,e.payload=t.subarray(i,i+a);break}e.payload=void 0}i+=a,s=0,a=0}return e},a=function(t){return 181!==t.payload[0]?null:49!=(t.payload[1]<<8|t.payload[2])?null:"GA94"!==String.fromCharCode(t.payload[3],t.payload[4],t.payload[5],t.payload[6])?null:3!==t.payload[7]?null:t.payload.subarray(8,t.payload.length-1)},n=function(t,i){var e,s,a,n,r=[];if(!(64&i[0]))return r;for(s=31&i[0],e=0;e<s;e++)a=3*e,n={type:3&i[a+2],pts:t},4&i[a+2]&&(n.ccData=i[a+3]<<8|i[a+4],r.push(n));return r},r=function(t){for(var i,e,s=t.byteLength,a=[],n=1;n<s-2;)0===t[n]&&0===t[n+1]&&3===t[n+2]?(a.push(n+2),n+=2):n++;if(0===a.length)return t;i=s-a.length,e=new Uint8Array(i);var r=0;for(n=0;n<i;r++,n++)r===a[0]&&(r++,a.shift()),e[n]=t[r];return e};i.exports={parseSei:s,parseUserData:a,parseCaptionPackets:n,discardEmulationPreventionBytes:r,USER_DATA_REGISTERED_ITU_T_T35:4}},{}],15:[function(t,i,e){var s,a,n,r,o,h,p;s=function(t){return 9e4*t},a=function(t,i){return t*i},n=function(t){return t/9e4},r=function(t,i){return t/i},o=function(t,i){return s(r(t,i))},h=function(t,i){return a(n(t),i)},p=function(t,i,e){return n(e?t:t-i)},i.exports={ONE_SECOND_IN_TS:9e4,secondsToVideoTs:s,secondsToAudioTs:a,videoTsToSeconds:n,audioTsToSeconds:r,audioTsToVideoTs:o,videoTsToAudioTs:h,metadataTsToSeconds:p}},{}],16:[function(t,i,e){"use strict";var s;s=function(t){var i=t.byteLength,e=0,s=0;this.length=function(){return 8*i},this.bitsAvailable=function(){return 8*i+s},this.loadWord=function(){var a=t.byteLength-i,n=new Uint8Array(4),r=Math.min(4,i);if(0===r)throw new Error("no bytes available");n.set(t.subarray(a,a+r)),e=new DataView(n.buffer).getUint32(0),s=8*r,i-=r},this.skipBits=function(t){var a;s>t?(e<<=t,s-=t):(t-=s,a=Math.floor(t/8),t-=8*a,i-=a,this.loadWord(),e<<=t,s-=t)},this.readBits=function(t){var a=Math.min(s,t),n=e>>>32-a;return s-=a,s>0?e<<=a:i>0&&this.loadWord(),a=t-a,a>0?n<<a|this.readBits(a):n},this.skipLeadingZeros=function(){var t;for(t=0;t<s;++t)if(0!=(e&2147483648>>>t))return e<<=t,s-=t,t;return this.loadWord(),t+this.skipLeadingZeros()},this.skipUnsignedExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.skipExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.readUnsignedExpGolomb=function(){var t=this.skipLeadingZeros();return this.readBits(t+1)-1},this.readExpGolomb=function(){var t=this.readUnsignedExpGolomb();return 1&t?1+t>>>1:-1*(t>>>1)},this.readBoolean=function(){return 1===this.readBits(1)},this.readUnsignedByte=function(){return this.readBits(8)},this.loadWord()},i.exports=s},{}],17:[function(t,i,e){"use strict";var s=function(){this.init=function(){var t={};this.on=function(i,e){t[i]||(t[i]=[]),t[i]=t[i].concat(e)},this.off=function(i,e){var s;return!!t[i]&&(s=t[i].indexOf(e),t[i]=t[i].slice(),t[i].splice(s,1),s>-1)},this.trigger=function(i){var e,s,a,n;if(e=t[i])if(2===arguments.length)for(a=e.length,s=0;s<a;++s)e[s].call(this,arguments[1]);else{for(n=[],s=arguments.length,s=1;s<arguments.length;++s)n.push(arguments[s]);for(a=e.length,s=0;s<a;++s)e[s].apply(this,n)}},this.dispose=function(){t={}}}};s.prototype.pipe=function(t){return this.on("data",function(i){t.push(i)}),this.on("done",function(i){t.flush(i)}),this.on("partialdone",function(i){t.partialFlush(i)}),this.on("endedtimeline",function(i){t.endTimeline(i)}),this.on("reset",function(i){t.reset(i)}),t},s.prototype.push=function(t){this.trigger("data",t)},s.prototype.flush=function(t){this.trigger("done",t)},s.prototype.partialFlush=function(t){this.trigger("partialdone",t)},s.prototype.endTimeline=function(t){this.trigger("endedtimeline",t)},s.prototype.reset=function(t){this.trigger("reset",t)},i.exports=s},{}]},{},[6])(6)}); | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i;i="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,i.muxjs=t()}}(function(){return function(){function t(i,e,s){function n(r,o){if(!e[r]){if(!i[r]){var h="function"==typeof require&&require;if(!o&&h)return h(r,!0);if(a)return a(r,!0);var p=new Error("Cannot find module '"+r+"'");throw p.code="MODULE_NOT_FOUND",p}var d=e[r]={exports:{}};i[r][0].call(d.exports,function(t){return n(i[r][1][t]||t)},d,d.exports,t,i,e,s)}return e[r].exports}for(var a="function"==typeof require&&require,r=0;r<s.length;r++)n(s[r]);return n}return t}()({1:[function(t,i,e){"use strict";var s,n=t(17),a=t(15).ONE_SECOND_IN_TS,r=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];s=function(t){var i,e=0;s.prototype.init.call(this),this.push=function(s){var n,o,h,p,d,l,u=0;if(t||(e=0),"audio"===s.type)for(i?(p=i,i=new Uint8Array(p.byteLength+s.data.byteLength),i.set(p),i.set(s.data,p.byteLength)):i=s.data;u+5<i.length;)if(255===i[u]&&240==(246&i[u+1])){if(o=2*(1&~i[u+1]),n=(3&i[u+3])<<11|i[u+4]<<3|(224&i[u+5])>>5,d=1024*(1+(3&i[u+6])),l=d*a/r[(60&i[u+2])>>>2],h=u+n,i.byteLength<h)return;if(this.trigger("data",{pts:s.pts+e*l,dts:s.dts+e*l,sampleCount:d,audioobjecttype:1+(i[u+2]>>>6&3),channelcount:(1&i[u+2])<<2|(192&i[u+3])>>>6,samplerate:r[(60&i[u+2])>>>2],samplingfrequencyindex:(60&i[u+2])>>>2,samplesize:16,data:i.subarray(u+7+o,h)}),e++,i.byteLength===h)return void(i=void 0);i=i.subarray(h)}else u++},this.flush=function(){e=0,this.trigger("done")},this.reset=function(){i=void 0,this.trigger("reset")},this.endTimeline=function(){i=void 0,this.trigger("endedtimeline")}},s.prototype=new n,i.exports=s},{15:15,17:17}],2:[function(t,i,e){"use strict";var s,n,a,r=t(17),o=t(16);n=function(){var t,i,e=0;n.prototype.init.call(this),this.push=function(s){var n;i?(n=new Uint8Array(i.byteLength+s.data.byteLength),n.set(i),n.set(s.data,i.byteLength),i=n):i=s.data;for(var a=i.byteLength;e<a-3;e++)if(1===i[e+2]){t=e+5;break}for(;t<a;)switch(i[t]){case 0:if(0!==i[t-1]){t+=2;break}if(0!==i[t-2]){t++;break}e+3!==t-2&&this.trigger("data",i.subarray(e+3,t-2));do{t++}while(1!==i[t]&&t<a);e=t-2,t+=3;break;case 1:if(0!==i[t-1]||0!==i[t-2]){t+=3;break}this.trigger("data",i.subarray(e+3,t-2)),e=t-2,t+=3;break;default:t+=3}i=i.subarray(e),t-=e,e=0},this.reset=function(){i=null,e=0,this.trigger("reset")},this.flush=function(){i&&i.byteLength>3&&this.trigger("data",i.subarray(e+3)),i=null,e=0,this.trigger("done")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline")}},n.prototype=new r,a={100:!0,110:!0,122:!0,244:!0,44:!0,83:!0,86:!0,118:!0,128:!0,138:!0,139:!0,134:!0},s=function(){var t,i,e,r,h,p,d,l=new n;s.prototype.init.call(this),t=this,this.push=function(t){"video"===t.type&&(i=t.trackId,e=t.pts,r=t.dts,l.push(t))},l.on("data",function(s){var n={trackId:i,pts:e,dts:r,data:s};switch(31&s[0]){case 5:n.nalUnitType="slice_layer_without_partitioning_rbsp_idr";break;case 6:n.nalUnitType="sei_rbsp",n.escapedRBSP=h(s.subarray(1));break;case 7:n.nalUnitType="seq_parameter_set_rbsp",n.escapedRBSP=h(s.subarray(1)),n.config=p(n.escapedRBSP);break;case 8:n.nalUnitType="pic_parameter_set_rbsp";break;case 9:n.nalUnitType="access_unit_delimiter_rbsp"}t.trigger("data",n)}),l.on("done",function(){t.trigger("done")}),l.on("partialdone",function(){t.trigger("partialdone")}),l.on("reset",function(){t.trigger("reset")}),l.on("endedtimeline",function(){t.trigger("endedtimeline")}),this.flush=function(){l.flush()},this.partialFlush=function(){l.partialFlush()},this.reset=function(){l.reset()},this.endTimeline=function(){l.endTimeline()},d=function(t,i){var e,s,n=8,a=8;for(e=0;e<t;e++)0!==a&&(s=i.readExpGolomb(),a=(n+s+256)%256),n=0===a?n:a},h=function(t){for(var i,e,s=t.byteLength,n=[],a=1;a<s-2;)0===t[a]&&0===t[a+1]&&3===t[a+2]?(n.push(a+2),a+=2):a++;if(0===n.length)return t;i=s-n.length,e=new Uint8Array(i);var r=0;for(a=0;a<i;r++,a++)r===n[0]&&(r++,n.shift()),e[a]=t[r];return e},p=function(t){var i,e,s,n,r,h,p,l,u,c,f,g,y,m=0,_=0,w=0,v=0,T=1;if(i=new o(t),e=i.readUnsignedByte(),n=i.readUnsignedByte(),s=i.readUnsignedByte(),i.skipUnsignedExpGolomb(),a[e]&&(r=i.readUnsignedExpGolomb(),3===r&&i.skipBits(1),i.skipUnsignedExpGolomb(),i.skipUnsignedExpGolomb(),i.skipBits(1),i.readBoolean()))for(f=3!==r?8:12,y=0;y<f;y++)i.readBoolean()&&(y<6?d(16,i):d(64,i));if(i.skipUnsignedExpGolomb(),0===(h=i.readUnsignedExpGolomb()))i.readUnsignedExpGolomb();else if(1===h)for(i.skipBits(1),i.skipExpGolomb(),i.skipExpGolomb(),p=i.readUnsignedExpGolomb(),y=0;y<p;y++)i.skipExpGolomb();if(i.skipUnsignedExpGolomb(),i.skipBits(1),l=i.readUnsignedExpGolomb(),u=i.readUnsignedExpGolomb(),c=i.readBits(1),0===c&&i.skipBits(1),i.skipBits(1),i.readBoolean()&&(m=i.readUnsignedExpGolomb(),_=i.readUnsignedExpGolomb(),w=i.readUnsignedExpGolomb(),v=i.readUnsignedExpGolomb()),i.readBoolean()&&i.readBoolean()){switch(i.readUnsignedByte()){case 1:g=[1,1];break;case 2:g=[12,11];break;case 3:g=[10,11];break;case 4:g=[16,11];break;case 5:g=[40,33];break;case 6:g=[24,11];break;case 7:g=[20,11];break;case 8:g=[32,11];break;case 9:g=[80,33];break;case 10:g=[18,11];break;case 11:g=[15,11];break;case 12:g=[64,33];break;case 13:g=[160,99];break;case 14:g=[4,3];break;case 15:g=[3,2];break;case 16:g=[2,1];break;case 255:g=[i.readUnsignedByte()<<8|i.readUnsignedByte(),i.readUnsignedByte()<<8|i.readUnsignedByte()]}g&&(T=g[0]/g[1])}return{profileIdc:e,levelIdc:s,profileCompatibility:n,width:Math.ceil((16*(l+1)-2*m-2*_)*T),height:(2-c)*(u+1)*16-2*w-2*v,sarRatio:g}}},s.prototype=new r,i.exports={H264Stream:s,NalByteStream:n}},{16:16,17:17}],3:[function(t,i,e){"use strict";var s=t(17),n=function(t){this.numberOfTracks=0,this.metadataStream=t.metadataStream,this.videoTags=[],this.audioTags=[],this.videoTrack=null,this.audioTrack=null,this.pendingCaptions=[],this.pendingMetadata=[],this.pendingTracks=0,this.processedTracks=0,n.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++)))}};n.prototype=new s,n.prototype.flush=function(t){var i,e,s,n,a={tags:{},captions:[],captionStreams:{},metadata:[]};if(this.pendingTracks<this.numberOfTracks){if("VideoSegmentStream"!==t&&"AudioSegmentStream"!==t)return;if(0===this.pendingTracks&&++this.processedTracks<this.numberOfTracks)return}if(this.processedTracks+=this.pendingTracks,this.pendingTracks=0,!(this.processedTracks<this.numberOfTracks)){for(this.videoTrack?n=this.videoTrack.timelineStartInfo.pts:this.audioTrack&&(n=this.audioTrack.timelineStartInfo.pts),a.tags.videoTags=this.videoTags,a.tags.audioTags=this.audioTags,s=0;s<this.pendingCaptions.length;s++)e=this.pendingCaptions[s],e.startTime=e.startPts-n,e.startTime/=9e4,e.endTime=e.endPts-n,e.endTime/=9e4,a.captionStreams[e.stream]=!0,a.captions.push(e);for(s=0;s<this.pendingMetadata.length;s++)i=this.pendingMetadata[s],i.cueTime=i.pts-n,i.cueTime/=9e4,a.metadata.push(i);a.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.processedTracks=0,this.trigger("data",a),this.trigger("done")}},i.exports=n},{17:17}],4:[function(t,i,e){"use strict";var s=t(5),n=function(t,i,e){var n,a,r,o=new Uint8Array(9),h=new DataView(o.buffer);return t=t||0,i=void 0===i||i,e=void 0===e||e,h.setUint8(0,70),h.setUint8(1,76),h.setUint8(2,86),h.setUint8(3,1),h.setUint8(4,(i?4:0)|(e?1:0)),h.setUint32(5,o.byteLength),t<=0?(a=new Uint8Array(o.byteLength+4),a.set(o),a.set([0,0,0,0],o.byteLength),a):(n=new s(s.METADATA_TAG),n.pts=n.dts=0,n.writeMetaDataDouble("duration",t),r=n.finalize().length,a=new Uint8Array(o.byteLength+r),a.set(o),a.set(h.byteLength,r),a)};i.exports=n},{5:5}],5:[function(t,i,e){"use strict";var s;s=function(t,i){var e,n=0,a=16384,r=function(t,i){var e,s=t.position+i;s<t.bytes.byteLength||(e=new Uint8Array(2*s),e.set(t.bytes.subarray(0,t.position),0),t.bytes=e,t.view=new DataView(t.bytes.buffer))},o=s.widthBytes||new Uint8Array("width".length),h=s.heightBytes||new Uint8Array("height".length),p=s.videocodecidBytes||new Uint8Array("videocodecid".length);if(!s.widthBytes){for(e=0;e<"width".length;e++)o[e]="width".charCodeAt(e);for(e=0;e<"height".length;e++)h[e]="height".charCodeAt(e);for(e=0;e<"videocodecid".length;e++)p[e]="videocodecid".charCodeAt(e);s.widthBytes=o,s.heightBytes=h,s.videocodecidBytes=p}switch(this.keyFrame=!1,t){case s.VIDEO_TAG:this.length=16,a*=6;break;case s.AUDIO_TAG:this.length=13,this.keyFrame=!0;break;case s.METADATA_TAG:this.length=29,this.keyFrame=!0;break;default:throw new Error("Unknown FLV tag type")}this.bytes=new Uint8Array(a),this.view=new DataView(this.bytes.buffer),this.bytes[0]=t,this.position=this.length,this.keyFrame=i,this.pts=0,this.dts=0,this.writeBytes=function(t,i,e){var s,n=i||0;e=e||t.byteLength,s=n+e,r(this,e),this.bytes.set(t.subarray(n,s),this.position),this.position+=e,this.length=Math.max(this.length,this.position)},this.writeByte=function(t){r(this,1),this.bytes[this.position]=t,this.position++,this.length=Math.max(this.length,this.position)},this.writeShort=function(t){r(this,2),this.view.setUint16(this.position,t),this.position+=2,this.length=Math.max(this.length,this.position)},this.negIndex=function(t){return this.bytes[this.length-t]},this.nalUnitSize=function(){return 0===n?0:this.length-(n+4)},this.startNalUnit=function(){if(n>0)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 i,e;this.length===n+4?this.length-=4:n>0&&(i=n+4,e=this.length-i,this.position=n,this.view.setUint32(this.position,e),this.position=this.length,t&&t.push(this.bytes.subarray(i,i+e))),n=0},this.writeMetaDataDouble=function(t,i){var e;if(r(this,2+t.length+9),this.view.setUint16(this.position,t.length),this.position+=2,"width"===t)this.bytes.set(o,this.position),this.position+=5;else if("height"===t)this.bytes.set(h,this.position),this.position+=6;else if("videocodecid"===t)this.bytes.set(p,this.position),this.position+=12;else for(e=0;e<t.length;e++)this.bytes[this.position]=t.charCodeAt(e),this.position++;this.position++,this.view.setFloat64(this.position,i),this.position+=8,this.length=Math.max(this.length,this.position),++n},this.writeMetaDataBoolean=function(t,i){var e;for(r(this,2),this.view.setUint16(this.position,t.length),this.position+=2,e=0;e<t.length;e++)r(this,1),this.bytes[this.position]=t.charCodeAt(e),this.position++;r(this,2),this.view.setUint8(this.position,1),this.position++,this.view.setUint8(this.position,i?1:0),this.position++,this.length=Math.max(this.length,this.position),++n},this.finalize=function(){var t,e;switch(this.bytes[0]){case s.VIDEO_TAG:this.bytes[11]=7|(this.keyFrame||i?16:32),this.bytes[12]=i?0:1,t=this.pts-this.dts,this.bytes[13]=(16711680&t)>>>16,this.bytes[14]=(65280&t)>>>8,this.bytes[15]=(255&t)>>>0;break;case s.AUDIO_TAG:this.bytes[11]=175,this.bytes[12]=i?0:1;break;case s.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 e=this.length-11,this.bytes[1]=(16711680&e)>>>16,this.bytes[2]=(65280&e)>>>8,this.bytes[3]=(255&e)>>>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=s.frameTime(this.bytes),this}},s.AUDIO_TAG=8,s.VIDEO_TAG=9,s.METADATA_TAG=18,s.isAudioFrame=function(t){return s.AUDIO_TAG===t[0]},s.isVideoFrame=function(t){return s.VIDEO_TAG===t[0]},s.isMetaData=function(t){return s.METADATA_TAG===t[0]},s.isKeyFrame=function(t){return s.isVideoFrame(t)?23===t[11]:!!s.isAudioFrame(t)||!!s.isMetaData(t)},s.frameTime=function(t){var i=t[4]<<16;return i|=t[5]<<8,i|=t[6]<<0,i|=t[7]<<24},i.exports=s},{}],6:[function(t,i,e){i.exports={tag:t(5),Transmuxer:t(8),getFlvHeader:t(4)}},{4:4,5:5,8:8}],7:[function(t,i,e){"use strict";var s=function(){var t=this;this.list=[],this.push=function(t){this.list.push({bytes:t.bytes,dts:t.dts,pts:t.pts,keyFrame:t.keyFrame,metaDataTag:t.metaDataTag})},Object.defineProperty(this,"length",{get:function(){return t.list.length}})};i.exports=s},{}],8:[function(t,i,e){"use strict";var s,n,a,r,o,h,p=t(17),d=t(5),l=t(10),u=t(1),c=t(2).H264Stream,f=t(3),g=t(7);r=function(t,i){"number"==typeof i.pts&&(void 0===t.timelineStartInfo.pts?t.timelineStartInfo.pts=i.pts:t.timelineStartInfo.pts=Math.min(t.timelineStartInfo.pts,i.pts)),"number"==typeof i.dts&&(void 0===t.timelineStartInfo.dts?t.timelineStartInfo.dts=i.dts:t.timelineStartInfo.dts=Math.min(t.timelineStartInfo.dts,i.dts))},o=function(t,i){var e=new d(d.METADATA_TAG);return e.dts=i,e.pts=i,e.writeMetaDataDouble("videocodecid",7),e.writeMetaDataDouble("width",t.width),e.writeMetaDataDouble("height",t.height),e},h=function(t,i){var e,s=new d(d.VIDEO_TAG,!0);for(s.dts=i,s.pts=i,s.writeByte(1),s.writeByte(t.profileIdc),s.writeByte(t.profileCompatibility),s.writeByte(t.levelIdc),s.writeByte(255),s.writeByte(225),s.writeShort(t.sps[0].length),s.writeBytes(t.sps[0]),s.writeByte(t.pps.length),e=0;e<t.pps.length;++e)s.writeShort(t.pps[e].length),s.writeBytes(t.pps[e]);return s},a=function(t){var i,e=[],s=[];a.prototype.init.call(this),this.push=function(i){r(t,i),t&&(t.audioobjecttype=i.audioobjecttype,t.channelcount=i.channelcount,t.samplerate=i.samplerate,t.samplingfrequencyindex=i.samplingfrequencyindex,t.samplesize=i.samplesize,t.extraData=t.audioobjecttype<<11|t.samplingfrequencyindex<<7|t.channelcount<<3),i.pts=Math.round(i.pts/90),i.dts=Math.round(i.dts/90),e.push(i)},this.flush=function(){var n,a,r,o=new g;if(0===e.length)return void this.trigger("done","AudioSegmentStream");for(r=-1/0;e.length;)n=e.shift(),s.length&&n.pts>=s[0]&&(r=s.shift(),this.writeMetaDataTags(o,r)),(t.extraData!==i||n.pts-r>=1e3)&&(this.writeMetaDataTags(o,n.pts),i=t.extraData,r=n.pts),a=new d(d.AUDIO_TAG),a.pts=n.pts,a.dts=n.dts,a.writeBytes(n.data),o.push(a.finalize());s.length=0,i=null,this.trigger("data",{track:t,tags:o.list}),this.trigger("done","AudioSegmentStream")},this.writeMetaDataTags=function(i,e){var s;s=new d(d.METADATA_TAG),s.pts=e,s.dts=e,s.writeMetaDataDouble("audiocodecid",10),s.writeMetaDataBoolean("stereo",2===t.channelcount),s.writeMetaDataDouble("audiosamplerate",t.samplerate),s.writeMetaDataDouble("audiosamplesize",16),i.push(s.finalize()),s=new d(d.AUDIO_TAG,!0),s.pts=e,s.dts=e,s.view.setUint16(s.position,t.extraData),s.position+=2,s.length=Math.max(s.length,s.position),i.push(s.finalize())},this.onVideoKeyFrame=function(t){s.push(t)}},a.prototype=new p,n=function(t){var i,e,s=[];n.prototype.init.call(this),this.finishFrame=function(s,n){if(n){if(i&&t&&t.newMetadata&&(n.keyFrame||0===s.length)){var a=o(i,n.dts).finalize(),r=h(t,n.dts).finalize();a.metaDataTag=r.metaDataTag=!0,s.push(a),s.push(r),t.newMetadata=!1,this.trigger("keyframe",n.dts)}n.endNalUnit(),s.push(n.finalize()),e=null}},this.push=function(i){r(t,i),i.pts=Math.round(i.pts/90),i.dts=Math.round(i.dts/90),s.push(i)},this.flush=function(){for(var n,a=new g;s.length&&"access_unit_delimiter_rbsp"!==s[0].nalUnitType;)s.shift();if(0===s.length)return void this.trigger("done","VideoSegmentStream");for(;s.length;)n=s.shift(),"seq_parameter_set_rbsp"===n.nalUnitType?(t.newMetadata=!0,i=n.config,t.width=i.width,t.height=i.height,t.sps=[n.data],t.profileIdc=i.profileIdc,t.levelIdc=i.levelIdc,t.profileCompatibility=i.profileCompatibility,e.endNalUnit()):"pic_parameter_set_rbsp"===n.nalUnitType?(t.newMetadata=!0,t.pps=[n.data],e.endNalUnit()):"access_unit_delimiter_rbsp"===n.nalUnitType?(e&&this.finishFrame(a,e),e=new d(d.VIDEO_TAG),e.pts=n.pts,e.dts=n.dts):("slice_layer_without_partitioning_rbsp_idr"===n.nalUnitType&&(e.keyFrame=!0),e.endNalUnit()),e.startNalUnit(),e.writeBytes(n.data);e&&this.finishFrame(a,e),this.trigger("data",{track:t,tags:a.list}),this.trigger("done","VideoSegmentStream")}},n.prototype=new p,s=function(t){var i,e,r,o,h,p,d,g,y,m,_,w,v=this;s.prototype.init.call(this),t=t||{},this.metadataStream=new l.MetadataStream,t.metadataStream=this.metadataStream,i=new l.TransportPacketStream,e=new l.TransportParseStream,r=new l.ElementaryStream,o=new l.TimestampRolloverStream("video"),h=new l.TimestampRolloverStream("audio"),p=new l.TimestampRolloverStream("timed-metadata"),d=new u,g=new c,w=new f(t),i.pipe(e).pipe(r),r.pipe(o).pipe(g),r.pipe(h).pipe(d),r.pipe(p).pipe(this.metadataStream).pipe(w),_=new l.CaptionStream,g.pipe(_).pipe(w),r.on("data",function(t){var i,e,s;if("metadata"===t.type){for(i=t.tracks.length;i--;)"video"===t.tracks[i].type?e=t.tracks[i]:"audio"===t.tracks[i].type&&(s=t.tracks[i]);e&&!y&&(w.numberOfTracks++,y=new n(e),g.pipe(y).pipe(w)),s&&!m&&(w.numberOfTracks++,m=new a(s),d.pipe(m).pipe(w),y&&y.on("keyframe",m.onVideoKeyFrame))}}),this.push=function(t){i.push(t)},this.flush=function(){i.flush()},this.resetCaptions=function(){_.reset()},w.on("data",function(t){v.trigger("data",t)}),w.on("done",function(){v.trigger("done")})},s.prototype=new p,i.exports=s},{1:1,10:10,17:17,2:2,3:3,5:5,7:7}],9:[function(t,i,e){"use strict";var s=t(17),n=t(14),a=function(){a.prototype.init.call(this),this.captionPackets_=[],this.ccStreams_=[new y(0,0),new y(0,1),new y(1,0),new y(1,1)],this.cc708Stream_=new l,this.reset(),this.ccStreams_.forEach(function(t){t.on("data",this.trigger.bind(this,"data")),t.on("partialdone",this.trigger.bind(this,"partialdone")),t.on("done",this.trigger.bind(this,"done"))},this),this.cc708Stream_.on("data",this.trigger.bind(this,"data")),this.cc708Stream_.on("partialdone",this.trigger.bind(this,"partialdone")),this.cc708Stream_.on("done",this.trigger.bind(this,"done"))};a.prototype=new s,a.prototype.push=function(t){var i,e,s;if("sei_rbsp"===t.nalUnitType&&(i=n.parseSei(t.escapedRBSP),i.payload&&i.payloadType===n.USER_DATA_REGISTERED_ITU_T_T35&&(e=n.parseUserData(i)))){if(t.dts<this.latestDts_)return void(this.ignoreNextEqualDts_=!0);if(t.dts===this.latestDts_&&this.ignoreNextEqualDts_)return void(--this.numSameDts_||(this.ignoreNextEqualDts_=!1));s=n.parseCaptionPackets(t.pts,e),this.captionPackets_=this.captionPackets_.concat(s),this.latestDts_!==t.dts&&(this.numSameDts_=0),this.numSameDts_++,this.latestDts_=t.dts}},a.prototype.flushCCStreams=function(t){this.ccStreams_.forEach(function(i){return"flush"===t?i.flush():i.partialFlush()},this)},a.prototype.flushStream=function(t){if(!this.captionPackets_.length)return void this.flushCCStreams(t);this.captionPackets_.forEach(function(t,i){t.presortIndex=i}),this.captionPackets_.sort(function(t,i){return t.pts===i.pts?t.presortIndex-i.presortIndex:t.pts-i.pts}),this.captionPackets_.forEach(function(t){t.type<2?this.dispatchCea608Packet(t):this.dispatchCea708Packet(t)},this),this.captionPackets_.length=0,this.flushCCStreams(t)},a.prototype.flush=function(){return this.flushStream("flush")},a.prototype.partialFlush=function(){return this.flushStream("partialFlush")},a.prototype.reset=function(){this.latestDts_=null,this.ignoreNextEqualDts_=!1,this.numSameDts_=0,this.activeCea608Channel_=[null,null],this.ccStreams_.forEach(function(t){t.reset()})},a.prototype.dispatchCea608Packet=function(t){this.setsTextOrXDSActive(t)?this.activeCea608Channel_[t.type]=null:this.setsChannel1Active(t)?this.activeCea608Channel_[t.type]=0:this.setsChannel2Active(t)&&(this.activeCea608Channel_[t.type]=1),null!==this.activeCea608Channel_[t.type]&&this.ccStreams_[(t.type<<1)+this.activeCea608Channel_[t.type]].push(t)},a.prototype.setsChannel1Active=function(t){return 4096==(30720&t.ccData)},a.prototype.setsChannel2Active=function(t){return 6144==(30720&t.ccData)},a.prototype.setsTextOrXDSActive=function(t){return 256==(28928&t.ccData)||4138==(30974&t.ccData)||6186==(30974&t.ccData)},a.prototype.dispatchCea708Packet=function(t){this.cc708Stream_.push(t)};var r={127:9834,4128:32,4129:160,4133:8230,4138:352,4140:338,4144:9608,4145:8216,4146:8217,4147:8220,4148:8221,4149:8226,4153:8482,4154:353,4156:339,4157:8480,4159:376,4214:8539,4215:8540,4216:8541,4217:8542,4218:9168,4219:9124,4220:9123,4221:9135,4222:9126,4223:9121,4256:12600},o=function(t){var i=r[t]||t;return 4096&t&&t===i?"":String.fromCharCode(i)},h=function(t){return 32<=t&&t<=127||160<=t&&t<=255},p=function(t){this.windowNum=t,this.reset()};p.prototype.reset=function(){this.clearText(),this.pendingNewLine=!1,this.winAttr={},this.penAttr={},this.penLoc={},this.penColor={},this.visible=0,this.rowLock=0,this.columnLock=0,this.priority=0,this.relativePositioning=0,this.anchorVertical=0,this.anchorHorizontal=0,this.anchorPoint=0,this.rowCount=1,this.virtualRowCount=this.rowCount+1,this.columnCount=41,this.windowStyle=0,this.penStyle=0},p.prototype.getText=function(){return this.rows.join("\n")},p.prototype.clearText=function(){this.rows=[""],this.rowIdx=0},p.prototype.newLine=function(t){for(this.rows.length>=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--},p.prototype.isEmpty=function(){return 0===this.rows.length||1===this.rows.length&&""===this.rows[0]},p.prototype.addText=function(t){this.rows[this.rowIdx]+=t},p.prototype.backspace=function(){if(!this.isEmpty()){var t=this.rows[this.rowIdx];this.rows[this.rowIdx]=t.substr(0,t.length-1)}};var d=function(t){this.serviceNum=t,this.text="",this.currentWindow=new p(-1),this.windows=[]};d.prototype.init=function(t,i){this.startPts=t;for(var e=0;e<8;e++)this.windows[e]=new p(e),"function"==typeof i&&(this.windows[e].beforeRowOverflow=i)},d.prototype.setCurrentWindow=function(t){this.currentWindow=this.windows[t]};var l=function(){l.prototype.init.call(this);var t=this;this.current708Packet=null,this.services={},this.push=function(i){3===i.type?(t.new708Packet(),t.add708Bytes(i)):(null===t.current708Packet&&t.new708Packet(),t.add708Bytes(i))}};l.prototype=new s,l.prototype.new708Packet=function(){null!==this.current708Packet&&this.push708Packet(),this.current708Packet={data:[],ptsVals:[]}},l.prototype.add708Bytes=function(t){var i=t.ccData,e=i>>>8,s=255&i;this.current708Packet.ptsVals.push(t.pts),this.current708Packet.data.push(e),this.current708Packet.data.push(s)},l.prototype.push708Packet=function(){var t=this.current708Packet,i=t.data,e=null,s=null,n=0,a=i[n++];for(t.seq=a>>6,t.sizeCode=63&a;n<i.length;n++)a=i[n++],e=a>>5,s=31&a,7===e&&s>0&&(a=i[n++],e=a),this.pushServiceBlock(e,n,s),s>0&&(n+=s-1)},l.prototype.pushServiceBlock=function(t,i,e){var s,n=i,a=this.current708Packet.data,r=this.services[t];for(r||(r=this.initService(t,n));n<i+e&&n<a.length;n++)s=a[n],h(s)?n=this.handleText(n,r):16===s?n=this.extendedCommands(n,r):128<=s&&s<=135?n=this.setCurrentWindow(n,r):152<=s&&s<=159?n=this.defineWindow(n,r):136===s?n=this.clearWindows(n,r):140===s?n=this.deleteWindows(n,r):137===s?n=this.displayWindows(n,r):138===s?n=this.hideWindows(n,r):139===s?n=this.toggleWindows(n,r):151===s?n=this.setWindowAttributes(n,r):144===s?n=this.setPenAttributes(n,r):145===s?n=this.setPenColor(n,r):146===s?n=this.setPenLocation(n,r):143===s?r=this.reset(n,r):8===s?r.currentWindow.backspace():12===s?r.currentWindow.clearText():13===s?r.currentWindow.pendingNewLine=!0:14===s?r.currentWindow.clearText():141===s&&n++},l.prototype.extendedCommands=function(t,i){var e=this.current708Packet.data,s=e[++t];return h(s)&&(t=this.handleText(t,i,!0)),t},l.prototype.getPts=function(t){return this.current708Packet.ptsVals[Math.floor(t/2)]},l.prototype.initService=function(t,i){var e=this;return this.services[t]=new d(t),this.services[t].init(this.getPts(i),function(i){e.flushDisplayed(i,e.services[t])}),this.services[t]},l.prototype.handleText=function(t,i,e){var s=this.current708Packet.data,n=s[t],a=e?4096:0,r=o(a|n),h=i.currentWindow;return h.pendingNewLine&&!h.isEmpty()&&h.newLine(this.getPts(t)),h.pendingNewLine=!1,h.addText(r),t},l.prototype.setCurrentWindow=function(t,i){var e=this.current708Packet.data,s=e[t],n=7&s;return i.setCurrentWindow(n),t},l.prototype.defineWindow=function(t,i){var e=this.current708Packet.data,s=e[t],n=7&s;i.setCurrentWindow(n);var a=i.currentWindow;return s=e[++t],a.visible=(32&s)>>5,a.rowLock=(16&s)>>4,a.columnLock=(8&s)>>3,a.priority=7&s,s=e[++t],a.relativePositioning=(128&s)>>7,a.anchorVertical=127&s,s=e[++t],a.anchorHorizontal=s,s=e[++t],a.anchorPoint=(240&s)>>4,a.rowCount=15&s,s=e[++t],a.columnCount=63&s,s=e[++t],a.windowStyle=(56&s)>>3,a.penStyle=7&s,a.virtualRowCount=a.rowCount+1,t},l.prototype.setWindowAttributes=function(t,i){var e=this.current708Packet.data,s=e[t],n=i.currentWindow.winAttr;return s=e[++t],n.fillOpacity=(192&s)>>6,n.fillRed=(48&s)>>4,n.fillGreen=(12&s)>>2,n.fillBlue=3&s,s=e[++t],n.borderType=(192&s)>>6,n.borderRed=(48&s)>>4,n.borderGreen=(12&s)>>2,n.borderBlue=3&s,s=e[++t],n.borderType+=(128&s)>>5,n.wordWrap=(64&s)>>6,n.printDirection=(48&s)>>4,n.scrollDirection=(12&s)>>2,n.justify=3&s,s=e[++t],n.effectSpeed=(240&s)>>4,n.effectDirection=(12&s)>>2,n.displayEffect=3&s,t},l.prototype.flushDisplayed=function(t,i){for(var e=[],s=0;s<8;s++)i.windows[s].visible&&!i.windows[s].isEmpty()&&e.push(i.windows[s].getText());i.endPts=t,i.text=e.join("\n\n"),this.pushCaption(i),i.startPts=t},l.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)},l.prototype.displayWindows=function(t,i){var e=this.current708Packet.data,s=e[++t],n=this.getPts(t);this.flushDisplayed(n,i);for(var a=0;a<8;a++)s&1<<a&&(i.windows[a].visible=1);return t},l.prototype.hideWindows=function(t,i){var e=this.current708Packet.data,s=e[++t],n=this.getPts(t);this.flushDisplayed(n,i);for(var a=0;a<8;a++)s&1<<a&&(i.windows[a].visible=0);return t},l.prototype.toggleWindows=function(t,i){var e=this.current708Packet.data,s=e[++t],n=this.getPts(t);this.flushDisplayed(n,i);for(var a=0;a<8;a++)s&1<<a&&(i.windows[a].visible^=1);return t},l.prototype.clearWindows=function(t,i){var e=this.current708Packet.data,s=e[++t],n=this.getPts(t);this.flushDisplayed(n,i);for(var a=0;a<8;a++)s&1<<a&&i.windows[a].clearText();return t},l.prototype.deleteWindows=function(t,i){var e=this.current708Packet.data,s=e[++t],n=this.getPts(t);this.flushDisplayed(n,i);for(var a=0;a<8;a++)s&1<<a&&i.windows[a].reset();return t},l.prototype.setPenAttributes=function(t,i){var e=this.current708Packet.data,s=e[t],n=i.currentWindow.penAttr;return s=e[++t],n.textTag=(240&s)>>4,n.offset=(12&s)>>2,n.penSize=3&s,s=e[++t],n.italics=(128&s)>>7,n.underline=(64&s)>>6,n.edgeType=(56&s)>>3,n.fontStyle=7&s,t},l.prototype.setPenColor=function(t,i){var e=this.current708Packet.data,s=e[t],n=i.currentWindow.penColor;return s=e[++t],n.fgOpacity=(192&s)>>6,n.fgRed=(48&s)>>4,n.fgGreen=(12&s)>>2,n.fgBlue=3&s,s=e[++t],n.bgOpacity=(192&s)>>6,n.bgRed=(48&s)>>4,n.bgGreen=(12&s)>>2,n.bgBlue=3&s,s=e[++t],n.edgeRed=(48&s)>>4,n.edgeGreen=(12&s)>>2,n.edgeBlue=3&s,t},l.prototype.setPenLocation=function(t,i){var e=this.current708Packet.data,s=e[t],n=i.currentWindow.penLoc;return i.currentWindow.pendingNewLine=!0,s=e[++t],n.row=15&s,s=e[++t],n.column=63&s,t},l.prototype.reset=function(t,i){var e=this.getPts(t);return this.flushDisplayed(e,i),this.initService(i.serviceNum,t)};var u={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},c=function(t){return null===t?"":(t=u[t]||t,String.fromCharCode(t))},f=[4352,4384,4608,4640,5376,5408,5632,5664,5888,5920,4096,4864,4896,5120,5152],g=function(){for(var t=[],i=15;i--;)t.push("");return t},y=function(t,i){y.prototype.init.call(this),this.field_=t||0,this.dataChannel_=i||0,this.name_="CC"+(1+(this.field_<<1|this.dataChannel_)),this.setConstants(),this.reset(),this.push=function(t){var i,e,s,n,a;if((i=32639&t.ccData)===this.lastControlCode_)return void(this.lastControlCode_=null);if(4096==(61440&i)?this.lastControlCode_=i:i!==this.PADDING_&&(this.lastControlCode_=null),s=i>>>8,n=255&i,i!==this.PADDING_)if(i===this.RESUME_CAPTION_LOADING_)this.mode_="popOn";else if(i===this.END_OF_CAPTION_)this.mode_="popOn",this.clearFormatting(t.pts),this.flushDisplayed(t.pts),e=this.displayed_,this.displayed_=this.nonDisplayed_,this.nonDisplayed_=e,this.startPts_=t.pts;else if(i===this.ROLL_UP_2_ROWS_)this.rollUpRows_=2,this.setRollUp(t.pts);else if(i===this.ROLL_UP_3_ROWS_)this.rollUpRows_=3,this.setRollUp(t.pts);else if(i===this.ROLL_UP_4_ROWS_)this.rollUpRows_=4,this.setRollUp(t.pts);else if(i===this.CARRIAGE_RETURN_)this.clearFormatting(t.pts),this.flushDisplayed(t.pts),this.shiftRowsUp_(),this.startPts_=t.pts;else if(i===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(i===this.ERASE_DISPLAYED_MEMORY_)this.flushDisplayed(t.pts),this.displayed_=g();else if(i===this.ERASE_NON_DISPLAYED_MEMORY_)this.nonDisplayed_=g();else if(i===this.RESUME_DIRECT_CAPTIONING_)"paintOn"!==this.mode_&&(this.flushDisplayed(t.pts),this.displayed_=g()),this.mode_="paintOn",this.startPts_=t.pts;else if(this.isSpecialCharacter(s,n))s=(3&s)<<8,a=c(s|n),this[this.mode_](t.pts,a),this.column_++;else if(this.isExtCharacter(s,n))"popOn"===this.mode_?this.nonDisplayed_[this.row_]=this.nonDisplayed_[this.row_].slice(0,-1):this.displayed_[this.row_]=this.displayed_[this.row_].slice(0,-1),s=(3&s)<<8,a=c(s|n),this[this.mode_](t.pts,a),this.column_++;else if(this.isMidRowCode(s,n))this.clearFormatting(t.pts),this[this.mode_](t.pts," "),this.column_++,14==(14&n)&&this.addFormatting(t.pts,["i"]),1==(1&n)&&this.addFormatting(t.pts,["u"]);else if(this.isOffsetControlCode(s,n))this.column_+=3&n;else if(this.isPAC(s,n)){var r=f.indexOf(7968&i);"rollUp"===this.mode_&&(r-this.rollUpRows_+1<0&&(r=this.rollUpRows_-1),this.setRollUp(t.pts,r)),r!==this.row_&&(this.clearFormatting(t.pts),this.row_=r),1&n&&-1===this.formatting_.indexOf("u")&&this.addFormatting(t.pts,["u"]),16==(16&i)&&(this.column_=4*((14&i)>>1)),this.isColorPAC(n)&&14==(14&n)&&this.addFormatting(t.pts,["i"])}else this.isNormalChar(s)&&(0===n&&(n=null),a=c(s),a+=c(n),this[this.mode_](t.pts,a),this.column_+=a.length)}};y.prototype=new s,y.prototype.flushDisplayed=function(t){var i=this.displayed_.map(function(t){try{return t.trim()}catch(t){return console.error("Skipping malformed caption."),""}}).join("\n").replace(/^\n+|\n+$/g,"");i.length&&this.trigger("data",{startPts:this.startPts_,endPts:t,text:i, | ||
stream:this.name_})},y.prototype.reset=function(){this.mode_="popOn",this.topRow_=0,this.startPts_=0,this.displayed_=g(),this.nonDisplayed_=g(),this.lastControlCode_=null,this.column_=0,this.row_=14,this.rollUpRows_=2,this.formatting_=[]},y.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_},y.prototype.isSpecialCharacter=function(t,i){return t===this.EXT_&&i>=48&&i<=63},y.prototype.isExtCharacter=function(t,i){return(t===this.EXT_+1||t===this.EXT_+2)&&i>=32&&i<=63},y.prototype.isMidRowCode=function(t,i){return t===this.EXT_&&i>=32&&i<=47},y.prototype.isOffsetControlCode=function(t,i){return t===this.OFFSET_&&i>=33&&i<=35},y.prototype.isPAC=function(t,i){return t>=this.BASE_&&t<this.BASE_+8&&i>=64&&i<=127},y.prototype.isColorPAC=function(t){return t>=64&&t<=79||t>=96&&t<=127},y.prototype.isNormalChar=function(t){return t>=32&&t<=127},y.prototype.setRollUp=function(t,i){if("rollUp"!==this.mode_&&(this.row_=14,this.mode_="rollUp",this.flushDisplayed(t),this.nonDisplayed_=g(),this.displayed_=g()),void 0!==i&&i!==this.row_)for(var e=0;e<this.rollUpRows_;e++)this.displayed_[i-e]=this.displayed_[this.row_-e],this.displayed_[this.row_-e]="";void 0===i&&(i=this.row_),this.topRow_=i-this.rollUpRows_+1},y.prototype.addFormatting=function(t,i){this.formatting_=this.formatting_.concat(i);var e=i.reduce(function(t,i){return t+"<"+i+">"},"");this[this.mode_](t,e)},y.prototype.clearFormatting=function(t){if(this.formatting_.length){var i=this.formatting_.reverse().reduce(function(t,i){return t+"</"+i+">"},"");this.formatting_=[],this[this.mode_](t,i)}},y.prototype.popOn=function(t,i){var e=this.nonDisplayed_[this.row_];e+=i,this.nonDisplayed_[this.row_]=e},y.prototype.rollUp=function(t,i){var e=this.displayed_[this.row_];e+=i,this.displayed_[this.row_]=e},y.prototype.shiftRowsUp_=function(){var t;for(t=0;t<this.topRow_;t++)this.displayed_[t]="";for(t=this.row_+1;t<15;t++)this.displayed_[t]="";for(t=this.topRow_;t<this.row_;t++)this.displayed_[t]=this.displayed_[t+1];this.displayed_[this.row_]=""},y.prototype.paintOn=function(t,i){var e=this.displayed_[this.row_];e+=i,this.displayed_[this.row_]=e},i.exports={CaptionStream:a,Cea608Stream:y,Cea708Stream:l}},{14:14,17:17}],10:[function(t,i,e){"use strict";var s,n,a,r=t(17),o=t(9),h=t(12),p=t(13).TimestampRolloverStream;s=function(){var t=new Uint8Array(188),i=0;s.prototype.init.call(this),this.push=function(e){var s,n=0,a=188;for(i?(s=new Uint8Array(e.byteLength+i),s.set(t.subarray(0,i)),s.set(e,i),i=0):s=e;a<s.byteLength;)71!==s[n]||71!==s[a]?(n++,a++):(this.trigger("data",s.subarray(n,a)),n+=188,a+=188);n<s.byteLength&&(t.set(s.subarray(n),0),i=s.byteLength-n)},this.flush=function(){188===i&&71===t[0]&&(this.trigger("data",t),i=0),this.trigger("done")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline")},this.reset=function(){i=0,this.trigger("reset")}},s.prototype=new r,n=function(){var t,i,e,s;n.prototype.init.call(this),s=this,this.packetsWaitingForPmt=[],this.programMapTable=void 0,t=function(t,s){var n=0;s.payloadUnitStartIndicator&&(n+=t[n]+1),"pat"===s.type?i(t.subarray(n),s):e(t.subarray(n),s)},i=function(t,i){i.section_number=t[7],i.last_section_number=t[8],s.pmtPid=(31&t[10])<<8|t[11],i.pmtPid=s.pmtPid},e=function(t,i){var e,n,a,r;if(1&t[5]){for(s.programMapTable={video:null,audio:null,"timed-metadata":{}},e=(15&t[1])<<8|t[2],n=3+e-4,a=(15&t[10])<<8|t[11],r=12+a;r<n;){var o=t[r],p=(31&t[r+1])<<8|t[r+2];o===h.H264_STREAM_TYPE&&null===s.programMapTable.video?s.programMapTable.video=p:o===h.ADTS_STREAM_TYPE&&null===s.programMapTable.audio?s.programMapTable.audio=p:o===h.METADATA_STREAM_TYPE&&(s.programMapTable["timed-metadata"][p]=o),r+=5+((15&t[r+3])<<8|t[r+4])}i.programMapTable=s.programMapTable}},this.push=function(i){var e={},s=4;if(e.payloadUnitStartIndicator=!!(64&i[1]),e.pid=31&i[1],e.pid<<=8,e.pid|=i[2],(48&i[3])>>>4>1&&(s+=i[s]+1),0===e.pid)e.type="pat",t(i.subarray(s),e),this.trigger("data",e);else if(e.pid===this.pmtPid)for(e.type="pmt",t(i.subarray(s),e),this.trigger("data",e);this.packetsWaitingForPmt.length;)this.processPes_.apply(this,this.packetsWaitingForPmt.shift());else void 0===this.programMapTable?this.packetsWaitingForPmt.push([i,s,e]):this.processPes_(i,s,e)},this.processPes_=function(t,i,e){e.pid===this.programMapTable.video?e.streamType=h.H264_STREAM_TYPE:e.pid===this.programMapTable.audio?e.streamType=h.ADTS_STREAM_TYPE:e.streamType=this.programMapTable["timed-metadata"][e.pid],e.type="pes",e.data=t.subarray(i),this.trigger("data",e)}},n.prototype=new r,n.STREAM_TYPES={h264:27,adts:15},a=function(){var t,i=this,e={data:[],size:0},s={data:[],size:0},n={data:[],size:0},r=function(t,i){var e;i.packetLength=6+(t[4]<<8|t[5]),i.dataAlignmentIndicator=0!=(4&t[6]),e=t[7],192&e&&(i.pts=(14&t[9])<<27|(255&t[10])<<20|(254&t[11])<<12|(255&t[12])<<5|(254&t[13])>>>3,i.pts*=4,i.pts+=(6&t[13])>>>1,i.dts=i.pts,64&e&&(i.dts=(14&t[14])<<27|(255&t[15])<<20|(254&t[16])<<12|(255&t[17])<<5|(254&t[18])>>>3,i.dts*=4,i.dts+=(6&t[18])>>>1)),i.data=t.subarray(9+t[8])},o=function(t,e,s){var n,a=new Uint8Array(t.size),o={type:e},h=0,p=0,d=!1;if(t.data.length&&!(t.size<9)){for(o.trackId=t.data[0].pid,h=0;h<t.data.length;h++)n=t.data[h],a.set(n.data,p),p+=n.data.byteLength;r(a,o),d="video"===e||o.packetLength<=t.size,(s||d)&&(t.size=0,t.data.length=0),d&&i.trigger("data",o)}};a.prototype.init.call(this),this.push=function(a){({pat:function(){},pes:function(){var t,i;switch(a.streamType){case h.H264_STREAM_TYPE:t=e,i="video";break;case h.ADTS_STREAM_TYPE:t=s,i="audio";break;case h.METADATA_STREAM_TYPE:t=n,i="timed-metadata";break;default:return}a.payloadUnitStartIndicator&&o(t,i,!0),t.data.push(a),t.size+=a.data.byteLength},pmt:function(){var e={type:"metadata",tracks:[]};t=a.programMapTable,null!==t.video&&e.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.video,codec:"avc",type:"video"}),null!==t.audio&&e.tracks.push({timelineStartInfo:{baseMediaDecodeTime:0},id:+t.audio,codec:"adts",type:"audio"}),i.trigger("data",e)}})[a.type]()},this.reset=function(){e.size=0,e.data.length=0,s.size=0,s.data.length=0,this.trigger("reset")},this.flushStreams_=function(){o(e,"video"),o(s,"audio"),o(n,"timed-metadata")},this.flush=function(){this.flushStreams_(),this.trigger("done")}},a.prototype=new r;var d={PAT_PID:0,MP2T_PACKET_LENGTH:188,TransportPacketStream:s,TransportParseStream:n,ElementaryStream:a,TimestampRolloverStream:p,CaptionStream:o.CaptionStream,Cea608Stream:o.Cea608Stream,Cea708Stream:o.Cea708Stream,MetadataStream:t(11)};for(var l in h)h.hasOwnProperty(l)&&(d[l]=h[l]);i.exports=d},{11:11,12:12,13:13,17:17,9:9}],11:[function(t,i,e){"use strict";var s,n=t(17),a=t(12),r=function(t,i,e){var s,n="";for(s=i;s<e;s++)n+="%"+("00"+t[s].toString(16)).slice(-2);return n},o=function(t,i,e){return decodeURIComponent(r(t,i,e))},h=function(t,i,e){return unescape(r(t,i,e))},p=function(t){return t[0]<<21|t[1]<<14|t[2]<<7|t[3]},d={TXXX:function(t){var i;if(3===t.data[0]){for(i=1;i<t.data.length;i++)if(0===t.data[i]){t.description=o(t.data,1,i),t.value=o(t.data,i+1,t.data.length).replace(/\0*$/,"");break}t.data=t.value}},WXXX:function(t){var i;if(3===t.data[0])for(i=1;i<t.data.length;i++)if(0===t.data[i]){t.description=o(t.data,1,i),t.url=o(t.data,i+1,t.data.length);break}},PRIV:function(t){var i;for(i=0;i<t.data.length;i++)if(0===t.data[i]){t.owner=h(t.data,0,i);break}t.privateData=t.data.subarray(i+1),t.data=t.privateData}};s=function(t){var i,e={debug:!(!t||!t.debug),descriptor:t&&t.descriptor},n=0,r=[],o=0;if(s.prototype.init.call(this),this.dispatchType=a.METADATA_STREAM_TYPE.toString(16),e.descriptor)for(i=0;i<e.descriptor.length;i++)this.dispatchType+=("00"+e.descriptor[i].toString(16)).slice(-2);this.push=function(t){var i,s,a,h,l,u;if("timed-metadata"===t.type){if(t.dataAlignmentIndicator&&(o=0,r.length=0),0===r.length&&(t.data.length<10||t.data[0]!=="I".charCodeAt(0)||t.data[1]!=="D".charCodeAt(0)||t.data[2]!=="3".charCodeAt(0)))return void(e.debug&&console.log("Skipping unrecognized metadata packet"));if(r.push(t),o+=t.data.byteLength,1===r.length&&(n=p(t.data.subarray(6,10)),n+=10),!(o<n)){for(i={data:new Uint8Array(n),frames:[],pts:r[0].pts,dts:r[0].dts},l=0;l<n;)i.data.set(r[0].data.subarray(0,n-l),l),l+=r[0].data.byteLength,o-=r[0].data.byteLength,r.shift();s=10,64&i.data[5]&&(s+=4,s+=p(i.data.subarray(10,14)),n-=p(i.data.subarray(16,20)));do{if((a=p(i.data.subarray(s+4,s+8)))<1)return console.log("Malformed ID3 frame encountered. Skipping metadata parsing.");if(u=String.fromCharCode(i.data[s],i.data[s+1],i.data[s+2],i.data[s+3]),h={id:u,data:i.data.subarray(s+10,s+a+10)},h.key=h.id,d[h.id]&&(d[h.id](h),"com.apple.streaming.transportStreamTimestamp"===h.owner)){var c=h.data,f=(1&c[3])<<30|c[4]<<22|c[5]<<14|c[6]<<6|c[7]>>>2;f*=4,f+=3&c[7],h.timeStamp=f,void 0===i.pts&&void 0===i.dts&&(i.pts=h.timeStamp,i.dts=h.timeStamp),this.trigger("timestamp",h)}i.frames.push(h),s+=10,s+=a}while(s<n);this.trigger("data",i)}}}},s.prototype=new n,i.exports=s},{12:12,17:17}],12:[function(t,i,e){"use strict";i.exports={H264_STREAM_TYPE:27,ADTS_STREAM_TYPE:15,METADATA_STREAM_TYPE:21}},{}],13:[function(t,i,e){"use strict";var s=t(17),n=function(t,i){var e=1;for(t>i&&(e=-1);Math.abs(i-t)>4294967296;)t+=8589934592*e;return t},a=function(t){var i,e;a.prototype.init.call(this),this.type_=t||"shared",this.push=function(t){"shared"!==this.type_&&t.type!==this.type_||(void 0===e&&(e=t.dts),t.dts=n(t.dts,e),t.pts=n(t.pts,e),i=t.dts,this.trigger("data",t))},this.flush=function(){e=i,this.trigger("done")},this.endTimeline=function(){this.flush(),this.trigger("endedtimeline")},this.discontinuity=function(){e=void 0,i=void 0},this.reset=function(){this.discontinuity(),this.trigger("reset")}};a.prototype=new s,i.exports={TimestampRolloverStream:a,handleRollover:n}},{17:17}],14:[function(t,i,e){"use strict";var s=function(t){for(var i=0,e={payloadType:-1,payloadSize:0},s=0,n=0;i<t.byteLength&&128!==t[i];){for(;255===t[i];)s+=255,i++;for(s+=t[i++];255===t[i];)n+=255,i++;if(n+=t[i++],!e.payload&&4===s){if("GA94"===String.fromCharCode(t[i+3],t[i+4],t[i+5],t[i+6])){e.payloadType=s,e.payloadSize=n,e.payload=t.subarray(i,i+n);break}e.payload=void 0}i+=n,s=0,n=0}return e},n=function(t){return 181!==t.payload[0]?null:49!=(t.payload[1]<<8|t.payload[2])?null:"GA94"!==String.fromCharCode(t.payload[3],t.payload[4],t.payload[5],t.payload[6])?null:3!==t.payload[7]?null:t.payload.subarray(8,t.payload.length-1)},a=function(t,i){var e,s,n,a,r=[];if(!(64&i[0]))return r;for(s=31&i[0],e=0;e<s;e++)n=3*e,a={type:3&i[n+2],pts:t},4&i[n+2]&&(a.ccData=i[n+3]<<8|i[n+4],r.push(a));return r},r=function(t){for(var i,e,s=t.byteLength,n=[],a=1;a<s-2;)0===t[a]&&0===t[a+1]&&3===t[a+2]?(n.push(a+2),a+=2):a++;if(0===n.length)return t;i=s-n.length,e=new Uint8Array(i);var r=0;for(a=0;a<i;r++,a++)r===n[0]&&(r++,n.shift()),e[a]=t[r];return e};i.exports={parseSei:s,parseUserData:n,parseCaptionPackets:a,discardEmulationPreventionBytes:r,USER_DATA_REGISTERED_ITU_T_T35:4}},{}],15:[function(t,i,e){var s,n,a,r,o,h,p;s=function(t){return 9e4*t},n=function(t,i){return t*i},a=function(t){return t/9e4},r=function(t,i){return t/i},o=function(t,i){return s(r(t,i))},h=function(t,i){return n(a(t),i)},p=function(t,i,e){return a(e?t:t-i)},i.exports={ONE_SECOND_IN_TS:9e4,secondsToVideoTs:s,secondsToAudioTs:n,videoTsToSeconds:a,audioTsToSeconds:r,audioTsToVideoTs:o,videoTsToAudioTs:h,metadataTsToSeconds:p}},{}],16:[function(t,i,e){"use strict";var s;s=function(t){var i=t.byteLength,e=0,s=0;this.length=function(){return 8*i},this.bitsAvailable=function(){return 8*i+s},this.loadWord=function(){var n=t.byteLength-i,a=new Uint8Array(4),r=Math.min(4,i);if(0===r)throw new Error("no bytes available");a.set(t.subarray(n,n+r)),e=new DataView(a.buffer).getUint32(0),s=8*r,i-=r},this.skipBits=function(t){var n;s>t?(e<<=t,s-=t):(t-=s,n=Math.floor(t/8),t-=8*n,i-=n,this.loadWord(),e<<=t,s-=t)},this.readBits=function(t){var n=Math.min(s,t),a=e>>>32-n;return s-=n,s>0?e<<=n:i>0&&this.loadWord(),n=t-n,n>0?a<<n|this.readBits(n):a},this.skipLeadingZeros=function(){var t;for(t=0;t<s;++t)if(0!=(e&2147483648>>>t))return e<<=t,s-=t,t;return this.loadWord(),t+this.skipLeadingZeros()},this.skipUnsignedExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.skipExpGolomb=function(){this.skipBits(1+this.skipLeadingZeros())},this.readUnsignedExpGolomb=function(){var t=this.skipLeadingZeros();return this.readBits(t+1)-1},this.readExpGolomb=function(){var t=this.readUnsignedExpGolomb();return 1&t?1+t>>>1:-1*(t>>>1)},this.readBoolean=function(){return 1===this.readBits(1)},this.readUnsignedByte=function(){return this.readBits(8)},this.loadWord()},i.exports=s},{}],17:[function(t,i,e){"use strict";var s=function(){this.init=function(){var t={};this.on=function(i,e){t[i]||(t[i]=[]),t[i]=t[i].concat(e)},this.off=function(i,e){var s;return!!t[i]&&(s=t[i].indexOf(e),t[i]=t[i].slice(),t[i].splice(s,1),s>-1)},this.trigger=function(i){var e,s,n,a;if(e=t[i])if(2===arguments.length)for(n=e.length,s=0;s<n;++s)e[s].call(this,arguments[1]);else{for(a=[],s=arguments.length,s=1;s<arguments.length;++s)a.push(arguments[s]);for(n=e.length,s=0;s<n;++s)e[s].apply(this,a)}},this.dispose=function(){t={}}}};s.prototype.pipe=function(t){return this.on("data",function(i){t.push(i)}),this.on("done",function(i){t.flush(i)}),this.on("partialdone",function(i){t.partialFlush(i)}),this.on("endedtimeline",function(i){t.endTimeline(i)}),this.on("reset",function(i){t.reset(i)}),t},s.prototype.push=function(t){this.trigger("data",t)},s.prototype.flush=function(t){this.trigger("done",t)},s.prototype.partialFlush=function(t){this.trigger("partialdone",t)},s.prototype.endTimeline=function(t){this.trigger("endedtimeline",t)},s.prototype.reset=function(t){this.trigger("reset",t)},i.exports=s},{}]},{},[6])(6)}); |
@@ -36,2 +36,4 @@ /** | ||
this.cc708Stream_ = new Cea708Stream(); // eslint-disable-line no-use-before-define | ||
this.reset(); | ||
@@ -46,2 +48,6 @@ | ||
this.cc708Stream_.on('data', this.trigger.bind(this, 'data')); | ||
this.cc708Stream_.on('partialdone', this.trigger.bind(this, 'partialdone')); | ||
this.cc708Stream_.on('done', this.trigger.bind(this, 'done')); | ||
}; | ||
@@ -61,2 +67,7 @@ | ||
// no payload data, skip | ||
if (!sei.payload) { | ||
return; | ||
} | ||
// ignore everything but user_data_registered_itu_t_t35 | ||
@@ -137,5 +148,6 @@ if (sei.payloadType !== cea708Parser.USER_DATA_REGISTERED_ITU_T_T35) { | ||
this.dispatchCea608Packet(packet); | ||
} else { | ||
// Dispatch packet to the Cea708Stream | ||
this.dispatchCea708Packet(packet); | ||
} | ||
// this is where an 'else' would go for a dispatching packets | ||
// to a theoretical Cea708Stream that handles SERVICEn data | ||
}, this); | ||
@@ -207,2 +219,7 @@ | ||
CaptionStream.prototype.dispatchCea708Packet = function(packet) { | ||
this.cc708Stream_.push(packet); | ||
}; | ||
// ---------------------- | ||
@@ -212,2 +229,791 @@ // Session to Application | ||
// This hash maps special and extended character codes to their | ||
// proper Unicode equivalent. The first one-byte key is just a | ||
// non-standard character code. The two-byte keys that follow are | ||
// the extended CEA708 character codes, along with the preceding | ||
// 0x10 extended character byte to distinguish these codes from | ||
// non-extended character codes. Every CEA708 character code that | ||
// is not in this object maps directly to a standard unicode | ||
// character code. | ||
// The transparent space and non-breaking transparent space are | ||
// technically not fully supported since there is no code to | ||
// make them transparent, so they have normal non-transparent | ||
// stand-ins. | ||
// The special closed caption (CC) character isn't a standard | ||
// unicode character, so a fairly similar unicode character was | ||
// chosen in it's place. | ||
var CHARACTER_TRANSLATION_708 = { | ||
0x7f: 0x266a, // ♪ | ||
0x1020: 0x20, // Transparent Space | ||
0x1021: 0xa0, // Nob-breaking Transparent Space | ||
0x1025: 0x2026, // … | ||
0x102a: 0x0160, // Š | ||
0x102c: 0x0152, // Œ | ||
0x1030: 0x2588, // █ | ||
0x1031: 0x2018, // ‘ | ||
0x1032: 0x2019, // ’ | ||
0x1033: 0x201c, // “ | ||
0x1034: 0x201d, // ” | ||
0x1035: 0x2022, // • | ||
0x1039: 0x2122, // ™ | ||
0x103a: 0x0161, // š | ||
0x103c: 0x0153, // œ | ||
0x103d: 0x2120, // ℠ | ||
0x103f: 0x0178, // Ÿ | ||
0x1076: 0x215b, // ⅛ | ||
0x1077: 0x215c, // ⅜ | ||
0x1078: 0x215d, // ⅝ | ||
0x1079: 0x215e, // ⅞ | ||
0x107a: 0x23d0, // ⏐ | ||
0x107b: 0x23a4, // ⎤ | ||
0x107c: 0x23a3, // ⎣ | ||
0x107d: 0x23af, // ⎯ | ||
0x107e: 0x23a6, // ⎦ | ||
0x107f: 0x23a1, // ⎡ | ||
0x10a0: 0x3138 // ㄸ (CC char) | ||
}; | ||
var get708CharFromCode = function(code) { | ||
var newCode = CHARACTER_TRANSLATION_708[code] || code; | ||
if ((code & 0x1000) && code === newCode) { | ||
// Invalid extended code | ||
return ''; | ||
} | ||
return String.fromCharCode(newCode); | ||
}; | ||
var within708TextBlock = function(b) { | ||
return (0x20 <= b && b <= 0x7f) || (0xa0 <= b && b <= 0xff); | ||
}; | ||
var Cea708Window = function(windowNum) { | ||
this.windowNum = windowNum; | ||
this.reset(); | ||
}; | ||
Cea708Window.prototype.reset = function() { | ||
this.clearText(); | ||
this.pendingNewLine = false; | ||
this.winAttr = {}; | ||
this.penAttr = {}; | ||
this.penLoc = {}; | ||
this.penColor = {}; | ||
// These default values are arbitrary, | ||
// defineWindow will usually override them | ||
this.visible = 0; | ||
this.rowLock = 0; | ||
this.columnLock = 0; | ||
this.priority = 0; | ||
this.relativePositioning = 0; | ||
this.anchorVertical = 0; | ||
this.anchorHorizontal = 0; | ||
this.anchorPoint = 0; | ||
this.rowCount = 1; | ||
this.virtualRowCount = this.rowCount + 1; | ||
this.columnCount = 41; | ||
this.windowStyle = 0; | ||
this.penStyle = 0; | ||
}; | ||
Cea708Window.prototype.getText = function() { | ||
return this.rows.join('\n'); | ||
}; | ||
Cea708Window.prototype.clearText = function() { | ||
this.rows = ['']; | ||
this.rowIdx = 0; | ||
}; | ||
Cea708Window.prototype.newLine = function(pts) { | ||
if (this.rows.length >= this.virtualRowCount && typeof this.beforeRowOverflow === 'function') { | ||
this.beforeRowOverflow(pts); | ||
} | ||
if (this.rows.length > 0) { | ||
this.rows.push(''); | ||
this.rowIdx++; | ||
} | ||
// Show all virtual rows since there's no visible scrolling | ||
while (this.rows.length > this.virtualRowCount) { | ||
this.rows.shift(); | ||
this.rowIdx--; | ||
} | ||
}; | ||
Cea708Window.prototype.isEmpty = function() { | ||
if (this.rows.length === 0) { | ||
return true; | ||
} else if (this.rows.length === 1) { | ||
return this.rows[0] === ''; | ||
} | ||
return false; | ||
}; | ||
Cea708Window.prototype.addText = function(text) { | ||
this.rows[this.rowIdx] += text; | ||
}; | ||
Cea708Window.prototype.backspace = function() { | ||
if (!this.isEmpty()) { | ||
var row = this.rows[this.rowIdx]; | ||
this.rows[this.rowIdx] = row.substr(0, row.length - 1); | ||
} | ||
}; | ||
var Cea708Service = function(serviceNum) { | ||
this.serviceNum = serviceNum; | ||
this.text = ''; | ||
this.currentWindow = new Cea708Window(-1); | ||
this.windows = []; | ||
}; | ||
/** | ||
* Initialize service windows | ||
* Must be run before service use | ||
* | ||
* @param {Integer} pts PTS value | ||
* @param {Function} beforeRowOverflow Function to execute before row overflow of a window | ||
*/ | ||
Cea708Service.prototype.init = function(pts, beforeRowOverflow) { | ||
this.startPts = pts; | ||
for (var win = 0; win < 8; win++) { | ||
this.windows[win] = new Cea708Window(win); | ||
if (typeof beforeRowOverflow === 'function') { | ||
this.windows[win].beforeRowOverflow = beforeRowOverflow; | ||
} | ||
} | ||
}; | ||
/** | ||
* Set current window of service to be affected by commands | ||
* | ||
* @param {Integer} windowNum Window number | ||
*/ | ||
Cea708Service.prototype.setCurrentWindow = function(windowNum) { | ||
this.currentWindow = this.windows[windowNum]; | ||
}; | ||
var Cea708Stream = function() { | ||
Cea708Stream.prototype.init.call(this); | ||
var self = this; | ||
this.current708Packet = null; | ||
this.services = {}; | ||
this.push = function(packet) { | ||
if (packet.type === 3) { | ||
// 708 packet start | ||
self.new708Packet(); | ||
self.add708Bytes(packet); | ||
} else { | ||
if (self.current708Packet === null) { | ||
// This should only happen at the start of a file if there's no packet start. | ||
self.new708Packet(); | ||
} | ||
self.add708Bytes(packet); | ||
} | ||
}; | ||
}; | ||
Cea708Stream.prototype = new Stream(); | ||
/** | ||
* Push current 708 packet, create new 708 packet. | ||
*/ | ||
Cea708Stream.prototype.new708Packet = function() { | ||
if (this.current708Packet !== null) { | ||
this.push708Packet(); | ||
} | ||
this.current708Packet = { | ||
data: [], | ||
ptsVals: [] | ||
}; | ||
}; | ||
/** | ||
* Add pts and both bytes from packet into current 708 packet. | ||
*/ | ||
Cea708Stream.prototype.add708Bytes = function(packet) { | ||
var data = packet.ccData; | ||
var byte0 = data >>> 8; | ||
var byte1 = data & 0xff; | ||
// I would just keep a list of packets instead of bytes, but it isn't clear in the spec | ||
// that service blocks will always line up with byte pairs. | ||
this.current708Packet.ptsVals.push(packet.pts); | ||
this.current708Packet.data.push(byte0); | ||
this.current708Packet.data.push(byte1); | ||
}; | ||
/** | ||
* Parse completed 708 packet into service blocks and push each service block. | ||
*/ | ||
Cea708Stream.prototype.push708Packet = function() { | ||
var packet708 = this.current708Packet; | ||
var packetData = packet708.data; | ||
var serviceNum = null; | ||
var blockSize = null; | ||
var i = 0; | ||
var b = packetData[i++]; | ||
packet708.seq = b >> 6; | ||
packet708.sizeCode = b & 0x3f; // 0b00111111; | ||
for (; i < packetData.length; i++) { | ||
b = packetData[i++]; | ||
serviceNum = b >> 5; | ||
blockSize = b & 0x1f; // 0b00011111 | ||
if (serviceNum === 7 && blockSize > 0) { | ||
// Extended service num | ||
b = packetData[i++]; | ||
serviceNum = b; | ||
} | ||
this.pushServiceBlock(serviceNum, i, blockSize); | ||
if (blockSize > 0) { | ||
i += blockSize - 1; | ||
} | ||
} | ||
}; | ||
/** | ||
* Parse service block, execute commands, read text. | ||
* | ||
* Note: While many of these commands serve important purposes, | ||
* many others just parse out the parameters or attributes, but | ||
* nothing is done with them because this is not a full and complete | ||
* implementation of the entire 708 spec. | ||
* | ||
* @param {Integer} serviceNum Service number | ||
* @param {Integer} start Start index of the 708 packet data | ||
* @param {Integer} size Block size | ||
*/ | ||
Cea708Stream.prototype.pushServiceBlock = function(serviceNum, start, size) { | ||
var b; | ||
var i = start; | ||
var packetData = this.current708Packet.data; | ||
var service = this.services[serviceNum]; | ||
if (!service) { | ||
service = this.initService(serviceNum, i); | ||
} | ||
for (; i < start + size && i < packetData.length; i++) { | ||
b = packetData[i]; | ||
if (within708TextBlock(b)) { | ||
i = this.handleText(i, service); | ||
} else if (b === 0x10) { | ||
i = this.extendedCommands(i, service); | ||
} else if (0x80 <= b && b <= 0x87) { | ||
i = this.setCurrentWindow(i, service); | ||
} else if (0x98 <= b && b <= 0x9f) { | ||
i = this.defineWindow(i, service); | ||
} else if (b === 0x88) { | ||
i = this.clearWindows(i, service); | ||
} else if (b === 0x8c) { | ||
i = this.deleteWindows(i, service); | ||
} else if (b === 0x89) { | ||
i = this.displayWindows(i, service); | ||
} else if (b === 0x8a) { | ||
i = this.hideWindows(i, service); | ||
} else if (b === 0x8b) { | ||
i = this.toggleWindows(i, service); | ||
} else if (b === 0x97) { | ||
i = this.setWindowAttributes(i, service); | ||
} else if (b === 0x90) { | ||
i = this.setPenAttributes(i, service); | ||
} else if (b === 0x91) { | ||
i = this.setPenColor(i, service); | ||
} else if (b === 0x92) { | ||
i = this.setPenLocation(i, service); | ||
} else if (b === 0x8f) { | ||
service = this.reset(i, service); | ||
} else if (b === 0x08) { | ||
// BS: Backspace | ||
service.currentWindow.backspace(); | ||
} else if (b === 0x0c) { | ||
// FF: Form feed | ||
service.currentWindow.clearText(); | ||
} else if (b === 0x0d) { | ||
// CR: Carriage return | ||
service.currentWindow.pendingNewLine = true; | ||
} else if (b === 0x0e) { | ||
// HCR: Horizontal carriage return | ||
service.currentWindow.clearText(); | ||
} else if (b === 0x8d) { | ||
// DLY: Delay, nothing to do | ||
i++; | ||
} else if (b === 0x8e) { | ||
// DLC: Delay cancel, nothing to do | ||
} else if (b === 0x03) { | ||
// ETX: End Text, don't need to do anything | ||
} else if (b === 0x00) { | ||
// Padding | ||
} else { | ||
// Unknown command | ||
} | ||
} | ||
}; | ||
/** | ||
* Execute an extended command | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.extendedCommands = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[++i]; | ||
if (within708TextBlock(b)) { | ||
i = this.handleText(i, service, true); | ||
} else { | ||
// Unknown command | ||
} | ||
return i; | ||
}; | ||
/** | ||
* Get PTS value of a given byte index | ||
* | ||
* @param {Integer} byteIndex Index of the byte | ||
* @return {Integer} PTS | ||
*/ | ||
Cea708Stream.prototype.getPts = function(byteIndex) { | ||
// There's 1 pts value per 2 bytes | ||
return this.current708Packet.ptsVals[Math.floor(byteIndex / 2)]; | ||
}; | ||
/** | ||
* Initializes a service | ||
* | ||
* @param {Integer} serviceNum Service number | ||
* @return {Service} Initialized service object | ||
*/ | ||
Cea708Stream.prototype.initService = function(serviceNum, i) { | ||
var self = this; | ||
this.services[serviceNum] = new Cea708Service(serviceNum); | ||
this.services[serviceNum].init(this.getPts(i), function(pts) { | ||
self.flushDisplayed(pts, self.services[serviceNum]); | ||
}); | ||
return this.services[serviceNum]; | ||
}; | ||
/** | ||
* Execute text writing to current window | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.handleText = function(i, service, isExtended) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[i]; | ||
var extended = isExtended ? 0x1000 : 0x0000; | ||
var char = get708CharFromCode(extended | b); | ||
var win = service.currentWindow; | ||
if (win.pendingNewLine && !win.isEmpty()) { | ||
win.newLine(this.getPts(i)); | ||
} | ||
win.pendingNewLine = false; | ||
win.addText(char); | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the CW# command. | ||
* | ||
* Set the current window. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.setCurrentWindow = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[i]; | ||
var windowNum = b & 0x07; | ||
service.setCurrentWindow(windowNum); | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the DF# command. | ||
* | ||
* Define a window and set it as the current window. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.defineWindow = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[i]; | ||
var windowNum = b & 0x07; | ||
service.setCurrentWindow(windowNum); | ||
var win = service.currentWindow; | ||
b = packetData[++i]; | ||
win.visible = (b & 0x20) >> 5; // v | ||
win.rowLock = (b & 0x10) >> 4; // rl | ||
win.columnLock = (b & 0x08) >> 3; // cl | ||
win.priority = b & 0x07; // p | ||
b = packetData[++i]; | ||
win.relativePositioning = (b & 0x80) >> 7; // rp | ||
win.anchorVertical = b & 0x7f; // av | ||
b = packetData[++i]; | ||
win.anchorHorizontal = b; // ah | ||
b = packetData[++i]; | ||
win.anchorPoint = (b & 0xf0) >> 4; // ap | ||
win.rowCount = b & 0x0f; // rc | ||
b = packetData[++i]; | ||
win.columnCount = b & 0x3f; // cc | ||
b = packetData[++i]; | ||
win.windowStyle = (b & 0x38) >> 3; // ws | ||
win.penStyle = b & 0x07; // ps | ||
// The spec says there are (rowCount+1) "virtual rows" | ||
win.virtualRowCount = win.rowCount + 1; | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the SWA command. | ||
* | ||
* Set attributes of the current window. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.setWindowAttributes = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[i]; | ||
var winAttr = service.currentWindow.winAttr; | ||
b = packetData[++i]; | ||
winAttr.fillOpacity = (b & 0xc0) >> 6; // fo | ||
winAttr.fillRed = (b & 0x30) >> 4; // fr | ||
winAttr.fillGreen = (b & 0x0c) >> 2; // fg | ||
winAttr.fillBlue = b & 0x03; // fb | ||
b = packetData[++i]; | ||
winAttr.borderType = (b & 0xc0) >> 6; // bt | ||
winAttr.borderRed = (b & 0x30) >> 4; // br | ||
winAttr.borderGreen = (b & 0x0c) >> 2; // bg | ||
winAttr.borderBlue = b & 0x03; // bb | ||
b = packetData[++i]; | ||
winAttr.borderType += (b & 0x80) >> 5; // bt | ||
winAttr.wordWrap = (b & 0x40) >> 6; // ww | ||
winAttr.printDirection = (b & 0x30) >> 4; // pd | ||
winAttr.scrollDirection = (b & 0x0c) >> 2; // sd | ||
winAttr.justify = b & 0x03; // j | ||
b = packetData[++i]; | ||
winAttr.effectSpeed = (b & 0xf0) >> 4; // es | ||
winAttr.effectDirection = (b & 0x0c) >> 2; // ed | ||
winAttr.displayEffect = b & 0x03; // de | ||
return i; | ||
}; | ||
/** | ||
* Gather text from all displayed windows and push a caption to output. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
*/ | ||
Cea708Stream.prototype.flushDisplayed = function(pts, service) { | ||
var displayedText = []; | ||
// TODO: Positioning not supported, displaying multiple windows will not necessarily | ||
// display text in the correct order, but sample files so far have not shown any issue. | ||
for (var winId = 0; winId < 8; winId++) { | ||
if (service.windows[winId].visible && !service.windows[winId].isEmpty()) { | ||
displayedText.push(service.windows[winId].getText()); | ||
} | ||
} | ||
service.endPts = pts; | ||
service.text = displayedText.join('\n\n'); | ||
this.pushCaption(service); | ||
service.startPts = pts; | ||
}; | ||
/** | ||
* Push a caption to output if the caption contains text. | ||
* | ||
* @param {Service} service The service object to be affected | ||
*/ | ||
Cea708Stream.prototype.pushCaption = function(service) { | ||
if (service.text !== '') { | ||
this.trigger('data', { | ||
startPts: service.startPts, | ||
endPts: service.endPts, | ||
text: service.text, | ||
stream: 'cc708_' + service.serviceNum | ||
}); | ||
service.text = ''; | ||
service.startPts = service.endPts; | ||
} | ||
}; | ||
/** | ||
* Parse and execute the DSW command. | ||
* | ||
* Set visible property of windows based on the parsed bitmask. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.displayWindows = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[++i]; | ||
var pts = this.getPts(i); | ||
this.flushDisplayed(pts, service); | ||
for (var winId = 0; winId < 8; winId++) { | ||
if (b & (0x01 << winId)) { | ||
service.windows[winId].visible = 1; | ||
} | ||
} | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the HDW command. | ||
* | ||
* Set visible property of windows based on the parsed bitmask. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.hideWindows = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[++i]; | ||
var pts = this.getPts(i); | ||
this.flushDisplayed(pts, service); | ||
for (var winId = 0; winId < 8; winId++) { | ||
if (b & (0x01 << winId)) { | ||
service.windows[winId].visible = 0; | ||
} | ||
} | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the TGW command. | ||
* | ||
* Set visible property of windows based on the parsed bitmask. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.toggleWindows = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[++i]; | ||
var pts = this.getPts(i); | ||
this.flushDisplayed(pts, service); | ||
for (var winId = 0; winId < 8; winId++) { | ||
if (b & (0x01 << winId)) { | ||
service.windows[winId].visible ^= 1; | ||
} | ||
} | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the CLW command. | ||
* | ||
* Clear text of windows based on the parsed bitmask. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.clearWindows = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[++i]; | ||
var pts = this.getPts(i); | ||
this.flushDisplayed(pts, service); | ||
for (var winId = 0; winId < 8; winId++) { | ||
if (b & (0x01 << winId)) { | ||
service.windows[winId].clearText(); | ||
} | ||
} | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the DLW command. | ||
* | ||
* Re-initialize windows based on the parsed bitmask. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.deleteWindows = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[++i]; | ||
var pts = this.getPts(i); | ||
this.flushDisplayed(pts, service); | ||
for (var winId = 0; winId < 8; winId++) { | ||
if (b & (0x01 << winId)) { | ||
service.windows[winId].reset(); | ||
} | ||
} | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the SPA command. | ||
* | ||
* Set pen attributes of the current window. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.setPenAttributes = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[i]; | ||
var penAttr = service.currentWindow.penAttr; | ||
b = packetData[++i]; | ||
penAttr.textTag = (b & 0xf0) >> 4; // tt | ||
penAttr.offset = (b & 0x0c) >> 2; // o | ||
penAttr.penSize = b & 0x03; // s | ||
b = packetData[++i]; | ||
penAttr.italics = (b & 0x80) >> 7; // i | ||
penAttr.underline = (b & 0x40) >> 6; // u | ||
penAttr.edgeType = (b & 0x38) >> 3; // et | ||
penAttr.fontStyle = b & 0x07; // fs | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the SPC command. | ||
* | ||
* Set pen color of the current window. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.setPenColor = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[i]; | ||
var penColor = service.currentWindow.penColor; | ||
b = packetData[++i]; | ||
penColor.fgOpacity = (b & 0xc0) >> 6; // fo | ||
penColor.fgRed = (b & 0x30) >> 4; // fr | ||
penColor.fgGreen = (b & 0x0c) >> 2; // fg | ||
penColor.fgBlue = b & 0x03; // fb | ||
b = packetData[++i]; | ||
penColor.bgOpacity = (b & 0xc0) >> 6; // bo | ||
penColor.bgRed = (b & 0x30) >> 4; // br | ||
penColor.bgGreen = (b & 0x0c) >> 2; // bg | ||
penColor.bgBlue = b & 0x03; // bb | ||
b = packetData[++i]; | ||
penColor.edgeRed = (b & 0x30) >> 4; // er | ||
penColor.edgeGreen = (b & 0x0c) >> 2; // eg | ||
penColor.edgeBlue = b & 0x03; // eb | ||
return i; | ||
}; | ||
/** | ||
* Parse and execute the SPL command. | ||
* | ||
* Set pen location of the current window. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Integer} New index after parsing | ||
*/ | ||
Cea708Stream.prototype.setPenLocation = function(i, service) { | ||
var packetData = this.current708Packet.data; | ||
var b = packetData[i]; | ||
var penLoc = service.currentWindow.penLoc; | ||
// Positioning isn't really supported at the moment, so this essentially just inserts a linebreak | ||
service.currentWindow.pendingNewLine = true; | ||
b = packetData[++i]; | ||
penLoc.row = b & 0x0f; // r | ||
b = packetData[++i]; | ||
penLoc.column = b & 0x3f; // c | ||
return i; | ||
}; | ||
/** | ||
* Execute the RST command. | ||
* | ||
* Reset service to a clean slate. Re-initialize. | ||
* | ||
* @param {Integer} i Current index in the 708 packet | ||
* @param {Service} service The service object to be affected | ||
* @return {Service} Re-initialized service | ||
*/ | ||
Cea708Stream.prototype.reset = function(i, service) { | ||
var pts = this.getPts(i); | ||
this.flushDisplayed(pts, service); | ||
return this.initService(service.serviceNum, i); | ||
}; | ||
// This hash maps non-ASCII, special, and extended character codes to their | ||
@@ -862,3 +1668,4 @@ // proper Unicode equivalent. The first keys that are only a single byte | ||
CaptionStream: CaptionStream, | ||
Cea608Stream: Cea608Stream | ||
Cea608Stream: Cea608Stream, | ||
Cea708Stream: Cea708Stream | ||
}; |
@@ -529,2 +529,3 @@ /** | ||
Cea608Stream: CaptionStream.Cea608Stream, | ||
Cea708Stream: CaptionStream.Cea708Stream, | ||
MetadataStream: require('./metadata-stream') | ||
@@ -531,0 +532,0 @@ }; |
@@ -126,3 +126,3 @@ /** | ||
})[0]; | ||
baseTime = baseTime || Infinity; | ||
baseTime = typeof baseTime === 'number' && !isNaN(baseTime) ? baseTime : Infinity; | ||
@@ -339,3 +339,4 @@ // convert base time to seconds | ||
} else { | ||
// TODO: show a warning? for unknown codec type | ||
// flac, opus, etc | ||
track.codec = track.codec.toLowerCase(); | ||
} | ||
@@ -342,0 +343,0 @@ } |
@@ -0,16 +1,32 @@ | ||
var MAX_UINT32 = Math.pow(2, 32); | ||
var parseSidx = function(data) { | ||
var view = new DataView(data.buffer, data.byteOffset, data.byteLength), | ||
result = { | ||
version: data[0], | ||
flags: new Uint8Array(data.subarray(1, 4)), | ||
references: [], | ||
referenceId: view.getUint32(4), | ||
timescale: view.getUint32(8), | ||
earliestPresentationTime: view.getUint32(12), | ||
firstOffset: view.getUint32(16) | ||
}, | ||
referenceCount = view.getUint16(22), | ||
i; | ||
result = { | ||
version: data[0], | ||
flags: new Uint8Array(data.subarray(1, 4)), | ||
references: [], | ||
referenceId: view.getUint32(4), | ||
timescale: view.getUint32(8) | ||
}, | ||
i = 12; | ||
for (i = 24; referenceCount; i += 12, referenceCount--) { | ||
if (result.version === 0) { | ||
result.earliestPresentationTime = view.getUint32(i); | ||
result.firstOffset = view.getUint32(i + 4); | ||
i += 8; | ||
} else { | ||
// read 64 bits | ||
result.earliestPresentationTime = (view.getUint32(i) * MAX_UINT32) + view.getUint32(i + 4); | ||
result.firstOffset = (view.getUint32(i + 8) * MAX_UINT32) + view.getUint32(i + 12); | ||
i += 16; | ||
} | ||
i += 2; // reserved | ||
var referenceCount = view.getUint16(i); | ||
i += 2; // start of references | ||
for (; referenceCount > 0; i += 12, referenceCount--) { | ||
result.references.push({ | ||
@@ -29,2 +45,3 @@ referenceType: (data[i] & 0x80) >>> 7, | ||
module.exports = parseSidx; |
{ | ||
"name": "mux.js", | ||
"version": "5.6.7", | ||
"version": "5.7.0", | ||
"description": "A collection of lightweight utilities for inspecting and manipulating video container formats.", | ||
@@ -74,6 +74,6 @@ "repository": { | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-qunit": "^0.1.5", | ||
"karma-qunit": "^3.1.2", | ||
"npm-run-all": "^4.1.5", | ||
"portscanner": "^1.0.0", | ||
"qunitjs": "^1.0.0", | ||
"qunit": "~2.9.1", | ||
"serve-static": "^1.10.0", | ||
@@ -80,0 +80,0 @@ "shelljs": "^0.8.3", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1320939
31611