@nethesis/phone-island
Version:
NethVoice CTI Phone Island
3 lines (2 loc) • 7.71 kB
JavaScript
"use strict";var e=require("../../../../_virtual/_commonjsHelpers.js"),t=require("../../../../_virtual/EBMLReader.js");require("../../../events/events.js");var i,a=require("./tools.js"),s=require("../../../../_virtual/events.js"),o=e.commonjsGlobal&&e.commonjsGlobal.__extends||(i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},i(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function a(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(a.prototype=t.prototype,new a)});Object.defineProperty(t.__exports,"__esModule",{value:!0});var r=s.exports,c=a.__require(),l=function(e){function t(){var t=e.call(this)||this;return t.logGroup="",t.hasLoggingStarted=!1,t.metadataloaded=!1,t.chunks=[],t.stack=[],t.segmentOffset=0,t.last2SimpleBlockVideoTrackTimecode=[0,0],t.last2SimpleBlockAudioTrackTimecode=[0,0],t.lastClusterTimecode=0,t.lastClusterPosition=0,t.timecodeScale=1e6,t.metadataSize=0,t.metadatas=[],t.cues=[],t.firstVideoBlockRead=!1,t.firstAudioBlockRead=!1,t.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null},t.trackTypes=[],t.trackDefaultDuration=[],t.trackCodecDelay=[],t.trackInfo={type:"nothing"},t.ended=!1,t.logging=!1,t.use_duration_every_simpleblock=!1,t.use_webp=!1,t.use_segment_info=!0,t.drop_default_duration=!0,t}return o(t,e),t.prototype.stop=function(){for(this.ended=!0,this.emit_segment_info();this.stack.length;)this.stack.pop(),this.logging&&console.groupEnd();this.logging&&this.hasLoggingStarted&&this.logGroup&&console.groupEnd()},t.prototype.emit_segment_info=function(){var e=this.chunks;if(this.chunks=[],this.metadataloaded){if(!this.use_segment_info)return;var t=this.lastClusterTimecode,i=this.duration,a=this.timecodeScale;this.emit("cluster",{timecode:t,data:e}),this.emit("duration",{timecodeScale:a,duration:i})}else{this.metadataloaded=!0,this.metadatas=e;var s=this.trackTypes.indexOf(1),o=this.trackTypes.indexOf(2);if(this.trackInfo=s>=0&&o>=0?{type:"both",trackNumber:s}:s>=0?{type:"video",trackNumber:s}:o>=0?{type:"audio",trackNumber:o}:{type:"nothing"},!this.use_segment_info)return;this.emit("metadata",{data:e,metadataSize:this.metadataSize})}},t.prototype.read=function(e){var t=this,i=!1;if(!this.ended){if("m"===e.type)if(e.isEnd)this.stack.pop();else{var a=this.stack[this.stack.length-1];if(null!=a&&a.level>=e.level){this.stack.pop(),this.logging&&console.groupEnd(),a.dataEnd=e.dataEnd,a.dataSize=e.dataEnd-a.dataStart,a.unknownSize=!1;var s=Object.assign({},a,{name:a.name,type:a.type,isEnd:!0});this.chunks.push(s)}this.stack.push(e)}if("m"===e.type&&"Segment"==e.name)0!=this.segmentOffset&&console.warn("Multiple segments detected!"),this.segmentOffset=e.dataStart,this.emit("segment_offset",this.segmentOffset);else if("b"===e.type&&"SimpleBlock"===e.name){var o=c.ebmlBlock(e.data),r=o.timecode,l=o.trackNumber,n=o.frames;if(1===this.trackTypes[l]){if(!this.firstVideoBlockRead&&(this.firstVideoBlockRead=!0,"both"===this.trackInfo.type||"video"===this.trackInfo.type)){var u=this.lastClusterTimecode+r;this.cues.push({CueTrack:l,CueClusterPosition:this.lastClusterPosition,CueTime:u}),this.emit("cue_info",{CueTrack:l,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:l,CueClusterPosition:this.lastClusterPosition,CueTime:u})}this.last2SimpleBlockVideoTrackTimecode=[this.last2SimpleBlockVideoTrackTimecode[1],r]}else if(2===this.trackTypes[l]){if(!this.firstAudioBlockRead&&(this.firstAudioBlockRead=!0,"audio"===this.trackInfo.type)){u=this.lastClusterTimecode+r;this.cues.push({CueTrack:l,CueClusterPosition:this.lastClusterPosition,CueTime:u}),this.emit("cue_info",{CueTrack:l,CueClusterPosition:this.lastClusterPosition,CueTime:this.lastClusterTimecode}),this.emit("cue",{CueTrack:l,CueClusterPosition:this.lastClusterPosition,CueTime:u})}this.last2SimpleBlockAudioTrackTimecode=[this.last2SimpleBlockAudioTrackTimecode[1],r]}this.use_duration_every_simpleblock&&this.emit("duration",{timecodeScale:this.timecodeScale,duration:this.duration}),this.use_webp&&n.forEach((function(e){if("9d012a"===e.slice(3,6).toString("hex")){var i=c.VP8BitStreamToRiffWebPBuffer(e),a=new Blob([i],{type:"image/webp"}),s=t.duration;t.emit("webp",{currentTime:s,webp:a})}}))}else"m"===e.type&&"Cluster"===e.name&&!1===e.isEnd?(this.firstVideoBlockRead=!1,this.firstAudioBlockRead=!1,this.emit_segment_info(),this.emit("cluster_ptr",e.tagStart),this.lastClusterPosition=e.tagStart):"u"===e.type&&"Timecode"===e.name?this.lastClusterTimecode=e.value:"u"===e.type&&"TimecodeScale"===e.name?this.timecodeScale=e.value:"m"===e.type&&"TrackEntry"===e.name?e.isEnd?(this.trackTypes[this.currentTrack.TrackNumber]=this.currentTrack.TrackType,this.trackDefaultDuration[this.currentTrack.TrackNumber]=this.currentTrack.DefaultDuration,this.trackCodecDelay[this.currentTrack.TrackNumber]=this.currentTrack.CodecDelay):this.currentTrack={TrackNumber:-1,TrackType:-1,DefaultDuration:null,CodecDelay:null}:"u"===e.type&&"TrackType"===e.name?this.currentTrack.TrackType=e.value:"u"===e.type&&"TrackNumber"===e.name?this.currentTrack.TrackNumber=e.value:"u"===e.type&&"CodecDelay"===e.name?this.currentTrack.CodecDelay=e.value:"u"===e.type&&"DefaultDuration"===e.name?this.drop_default_duration?(console.warn("DefaultDuration detected!, remove it"),i=!0):this.currentTrack.DefaultDuration=e.value:"unknown"===e.name&&console.warn(e);!this.metadataloaded&&e.dataEnd>0&&(this.metadataSize=e.dataEnd),i||this.chunks.push(e),this.logging&&this.put(e)}},Object.defineProperty(t.prototype,"duration",{get:function(){if("nothing"===this.trackInfo.type)return console.warn("no video, no audio track"),0;var e=0,t=0,i=0,a=this.trackDefaultDuration[this.trackInfo.trackNumber];if("number"==typeof a)e=a;else if("both"===this.trackInfo.type)this.last2SimpleBlockAudioTrackTimecode[1]>this.last2SimpleBlockVideoTrackTimecode[1]?(e=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale,"number"==typeof(s=this.trackCodecDelay[this.trackTypes.indexOf(2)])&&(t=s),i=this.last2SimpleBlockAudioTrackTimecode[1]):(e=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale,"number"==typeof(s=this.trackCodecDelay[this.trackTypes.indexOf(1)])&&(t=s),i=this.last2SimpleBlockVideoTrackTimecode[1]);else if("video"===this.trackInfo.type){e=(this.last2SimpleBlockVideoTrackTimecode[1]-this.last2SimpleBlockVideoTrackTimecode[0])*this.timecodeScale,"number"==typeof(s=this.trackCodecDelay[this.trackInfo.trackNumber])&&(t=s),i=this.last2SimpleBlockVideoTrackTimecode[1]}else if("audio"===this.trackInfo.type){var s;e=(this.last2SimpleBlockAudioTrackTimecode[1]-this.last2SimpleBlockAudioTrackTimecode[0])*this.timecodeScale,"number"==typeof(s=this.trackCodecDelay[this.trackInfo.trackNumber])&&(t=s),i=this.last2SimpleBlockAudioTrackTimecode[1]}var o=((this.lastClusterTimecode+i)*this.timecodeScale+e-t)/this.timecodeScale;return Math.floor(o)},enumerable:!1,configurable:!0}),t.prototype.addListener=function(t,i){return e.prototype.addListener.call(this,t,i)},t.prototype.put=function(e){this.hasLoggingStarted||(this.hasLoggingStarted=!0,this.logging&&this.logGroup&&console.groupCollapsed(this.logGroup)),"m"===e.type?e.isEnd?console.groupEnd():console.group(e.name+":"+e.tagStart):"b"===e.type?console.log(e.name,e.type):console.log(e.name,e.tagStart,e.type,e.value)},t}(r.EventEmitter);t.__exports.default=l;
//# sourceMappingURL=EBMLReader.js.map