From 92be35aeeaa28083acd6fc3b0956bb9b90fff145 Mon Sep 17 00:00:00 2001 From: yqjiang Date: Fri, 20 Sep 2019 10:48:08 +0800 Subject: [PATCH] wait for remuxer --- packages/xgplayer-hls-live/browser/index.js | 2 +- packages/xgplayer-hls-live/dist/index.js | 2 +- packages/xgplayer-hls-live/src/demuxer/ts.js | 74 +++++++++++++++++-- .../xgplayer-utils/src/models/trackSample.js | 4 +- 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/packages/xgplayer-hls-live/browser/index.js b/packages/xgplayer-hls-live/browser/index.js index ea8f5786a..6974c19e9 100644 --- a/packages/xgplayer-hls-live/browser/index.js +++ b/packages/xgplayer-hls-live/browser/index.js @@ -1 +1 @@ -window.HlsLivePlayer=function(t){var e={};function r(i){if(e[i])return e[i].exports;var s=e[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)r.d(i,s,function(e){return t[e]}.bind(null,s));return i},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const i=r(4);e.default=class{constructor(t=[]){this._emitter=new i.EventEmitter,this._instanceMap={},this._clsMap={},this._inited=!1,this.allowedEvents=t}getInstance(t){if(this._instanceMap[t])return this._instanceMap[t];throw new Error(`${t}实例尚未初始化`)}initInstance(t,...e){if(this._clsMap[t]){const r=new this._clsMap[t](...e);return this._instanceMap[t]=r,r.init&&r.init(),r}throw new Error(`${t}未在context中注册`)}init(t){if(!this._inited){for(let e in this._clsMap)this._clsMap.hasOwnProperty(e)&&!this._instanceMap[e]&&this.initInstance(e,t);this._inited=!0}}registry(t,e){const r=this._emitter,i=this._isMessageNameValid.bind(this),s=this;return this._clsMap[t]=class extends e{constructor(...e){super(...e),this.listeners={},this.TAG=t,this._context=s}on(t,e){return i(t),this.listeners[t]?this.listeners[t].push(e):this.listeners[t]=[e],r.on(t,e)}once(t,e){return i(t),r.once(t,e)}emit(t,...e){return i(t),r.emit(t,...e)}off(t,e){return i(t),r.off(t,e)}removeListeners(){const t=Object.prototype.hasOwnProperty.bind(this.listeners);for(let e in this.listeners)if(t(e)){const t=this.listeners[e]||[];for(let i=0;ithis.initInstance(t,...e)}destroyInstances(){Object.keys(this._instanceMap).forEach(t=>{this._instanceMap[t].destroy&&this._instanceMap[t].destroy()})}destroy(){this._emitter=null,this.allowedEvents=null,this._clsMap=null,this.destroyInstances()}_isMessageNameValid(t){if(!this.allowedEvents.indexOf(t)<0)throw new Error(`unregistered message name: ${t}`)}}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.RemuxBuffer=e.VideoTrack=e.AudioTrack=e.XgBuffer=void 0;var i,s=r(5),n=(i=s)&&i.__esModule?i:{default:i};e.XgBuffer=class{constructor(t){this.length=t||0,this.historyLen=t||0,this.array=[],this.offset=0}push(t){this.array.push(t),this.length+=t.byteLength,this.historyLen+=t.byteLength}shift(t){if(this.array.length<1)return new Uint8Array(0);if(void 0===t)return this._shiftBuffer();if(this.offset+t===this.array[0].length){let e=this.array[0].slice(this.offset,this.offset+t);return this.offset=0,this.array.shift(),this.length-=t,e}if(this.offset+t0&&t>0;){if(this.offset+t{let e=this._context.getInstance("TS_LOADER"),r=this._context.getInstance("M3U8_LOADER");if("M3U8_BUFFER"===t.TAG){let i=o.default.parse(t.shift(),this.baseurl);this._playlist.pushM3U8(i);let s=this._playlist.getTs();s?e.load(s.url):this.retrytimes>0&&(this.retrytimes--,r.load(this.url))}else if("TS_BUFFER"===t.TAG){this._context.getInstance("TS_DEMUXER").demux();let t=this._playlist.getTs();t?e.load(t.url):r.load(this.url)}})}load(t){this.baseurl=o.default.parseURL(t),this.url=t,this._context.getInstance("M3U8_LOADER").load(t)}}},function(t,e,r){"use strict";var i,s="object"==typeof Reflect?Reflect:null,n=s&&"function"==typeof s.apply?s.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};i=s&&"function"==typeof s.ownKeys?s.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var a=Number.isNaN||function(t){return t!=t};function o(){o.init.call(this)}t.exports=o,o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var d=10;function l(t){return void 0===t._maxListeners?o.defaultMaxListeners:t._maxListeners}function h(t,e,r,i){var s,n,a,o;if("function"!=typeof r)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r);if(void 0===(n=t._events)?(n=t._events=Object.create(null),t._eventsCount=0):(void 0!==n.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),n=t._events),a=n[e]),void 0===a)a=n[e]=r,++t._eventsCount;else if("function"==typeof a?a=n[e]=i?[r,a]:[a,r]:i?a.unshift(r):a.push(r),(s=l(t))>0&&a.length>s&&!a.warned){a.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=t,d.type=e,d.count=a.length,o=d,console&&console.warn&&console.warn(o)}return t}function u(){for(var t=[],e=0;e0&&(a=e[0]),a instanceof Error)throw a;var o=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw o.context=a,o}var d=s[t];if(void 0===d)return!1;if("function"==typeof d)n(d,this,e);else{var l=d.length,h=_(d,l);for(r=0;r=0;n--)if(r[n]===e||r[n].listener===e){a=r[n].listener,s=n;break}if(s<0)return this;0===s?r.shift():function(t,e){for(;e+1=0;i--)this.removeListener(t,e[i]);return this},o.prototype.listeners=function(t){return f(this,t,!0)},o.prototype.rawListeners=function(t){return f(this,t,!1)},o.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):p.call(t,e)},o.prototype.listenerCount=p,o.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(){this.id=-1,this.sequenceNumber=0,this.samples=[],this.length=0}reset(){this.sequenceNumber=0,this.samples=[],this.length=0}distroy(){this.reset(),this.id=-1}};e.Tracks=class{constructor(){this.audioTrack=null,this.videoTrack=null}}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t){this._baseURL="",this._list={},this._ts={},this.version=0,this.sequence=-1,this.targetduration=0,this.duration=0,this._lastget=void 0,this._audoclear=t.autoclear||!1}get list(){return this._list}set baseURL(t){this.baseURL!==t&&(this.clear(),this._baseURL=t)}get baseURL(){return this._baseURL}push(t,e){this._ts[t]={duration:e,downloaded:!1,start:this.duration},this._list[this.duration]=t,this.duration+=e}pushM3U8(t){if(this.version=t.version,this.targetduration=t.targetduration,t.sequence>this.sequence){this.sequence=t.sequence;for(let e=0;e=this.duration)){for(let i=0;i=r[i];i++){let t=this._list[r[i]];e={url:t,downloaded:this._ts[t].downloaded,time:parseInt(r[i]),duration:parseInt(this._ts[t].duration)},this.autoclear&&(delete this._ts[this._lastget.url],delete this._list[this._lastget.time]),this._lastget=e}return e}}clear(){this._baseURL="",this._list={},this._ts={},this.version=0,this.sequence=-1,this.targetduration=0,this.duration=0}}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i,s=r(0),n=(i=s)&&i.__esModule?i:{default:i},a=r(8);const o=0,d=1,l=2;window.Context=n.default,e.default=class{constructor(t){this.configs=Object.assign({},t),this.url=null,this.status=0,this.error=null,this._reader=null,this.readtype=this.configs.readtype,this.buffer=this.configs.buffer||"LOADER_BUFFER"}static get type(){return"loader"}load(t,e){let r=this;this.url=t;let i=this.getParams(e);return fetch(this.url,i).then(function(t){return r.status=t.status,r.loading=!0,r._onFetchResponse(t)})}_onFetchResponse(t){let e=this,r=this._context.getInstance(this.buffer);if(!0===t.ok)switch(this.readtype){case l:t.json().then(t=>{r?(r.push(t),e.emit(a.LOADER_EVENTS.LOADER_COMPLETE,r)):e.emit(a.LOADER_EVENTS.LOADER_COMPLETE,t)});break;case d:t.text().then(t=>{r?(r.push(t),e.emit(a.LOADER_EVENTS.LOADER_COMPLETE,r)):e.emit(a.LOADER_EVENTS.LOADER_COMPLETE,t)});break;case o:default:return this._onReader(t.body.getReader())}}_onReader(t){let e=this._context.getInstance(this.buffer);if(e||this._reader.cancel(),this._reader=t,!1===this.loading)return;let r=this;this._reader&&this._reader.read().then(function(i){return i.done?(r.loading=!1,r.status=0,void r.emit(a.LOADER_EVENTS.LOADER_COMPLETE,e)):(e.push(i.value),r.emit(a.LOADER_EVENTS.LOADER_DATALOADED,e),r._onReader(t))}).catch(function(t){console.log(t)})}getParams(t){let e=Object.assign({},t),r=new Headers,i={method:"GET",headers:r,mode:"cors",cache:"default"};if("object"==typeof this.configs.headers){let t=this.configs.headers;for(let e in t)t.hasOwnProperty(e)&&r.append(e,t[e])}return!1===e.cors&&(i.mode="same-origin"),e.withCredentials&&(i.credentials="include"),i}cancel(){this._reader&&(this._reader.cancel(),this._reader=null)}}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=e.LOADER_EVENTS={LOADER_DATALOADED:"LOADER_DATALOADED",LOADER_COMPLETE:"LOADER_COMPLETE",LOADER_ERROR:"LOADER_ERROR"},s=e.DEMUX_EVENTS={DEMUX_COMPLETE:"DEMUX_COMPLETE",DEMUX_ERROR:"DEMUX_ERROR",METADATA_PARSED:"METADATA_COMPLETE",VIDEO_METADATA_CHANGE:"VIDEO_METADATA_CHANGE",AUDIO_METADATA_CHANGE:"AUDIO_METADATA_CHANGE",MEDIA_INFO:"MEDIA_INFO"},n=e.REMUX_EVENTS={MEDIA_SEGMENT:"MEDIA_SEGMENT",REMUX_ERROR:"REMUX_ERROR",INIT_SEGMENT:"INIT_SEGMENT"},a=Object.assign({},i,s,n),o=e.flvAllowedEvents=[];for(var d in a)a.hasOwnProperty(d)&&o.push(a[d]);e.default=a},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.default=class{static parse(t,e=""){let r={duration:0},i=t.split(/\r|\n/),s=i.shift();if(!s.match("#EXTM3U"))return null;for(s=i.shift();void 0!==s;){let t=s.match(/#(.*):(.*)/);if(t&&t.length>2)switch(t[1]){case"EXT-X-VERSION":r.version=parseInt(t[2]);break;case"EXT-X-MEDIA-SEQUENCE":r.sequence=parseInt(t[2]);break;case"EXT-X-TARGETDURATION":r.targetduration=parseFloat(t[2]);break;case"EXTINF":r.frags||(r.frags=[]);let s={start:r.duration,duration:1e3*parseFloat(t[2])};r.duration+=s.duration,s.url=e+i.shift(),r.frags.push(s)}s=i.shift()}return r}static parseURL(t){let e="",r=t.match(/(.*\/).*\.m3u8$/);if(r&&r.length>0)for(let t=0;te.length&&(e=r[t]);return e}}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=a(r(11)),s=a(r(12)),n=r(1);function a(t){return t&&t.__esModule?t:{default:t}}const o={1:["video","MPEG-1"],2:["video","MPEG-2"],27:["video","AVC.H264"],234:["video","VC-1"],3:["audio","MPEG-1"],4:["audio","MPEG-2"],15:["audio","MPEG-2.AAC"],17:["audio","MPEG-4.AAC"],128:["audio","LPCM"],129:["audio","AC3"],6:["audio","AC3"],130:["audio","DTS"],131:["audio","Dolby TrueHD"],132:["audio","AC3-Plus"],133:["audio","DTS-HD"],134:["audio","DTS-MA"],161:["audio","AC3-Plus-SEC"],162:["audio","DTS-HD-SEC"]};class d{constructor(t){this.configs=Object.assign({},t),this.demuxing=!1,this.pat=[],this.pmt=[]}init(){this.inputbuffer=this._context.getInstance(this.configs.inputbuffer)}demux(){if(this.demuxing)return;let t=this.inputbuffer,e={pat:[],pmt:[]},r={};for(;t.length>=188;){let s=t.shift(188),n=new i.default(s.buffer),a={};d.read(n,a,e),a.pes?(r[a.header.pid]||(r[a.header.pid]=[]),r[a.header.pid].push(a.pes),a.pes.ES.buffer=[a.pes.ES.buffer]):r[a.header.pid]&&r[a.header.pid][r[a.header.pid].length-1].ES.buffer.push(a.payload.stream)}for(let t=0;t>>24&255,i>>>16&255,i>>>8&255,255&i]),o),o+=4,a.data.set(e.body,o),o+=i)}e.samples.push(a)}static Merge(t){let e,r=0,s=0;for(let e=0;et.pid===i))d.PMT(t,e,r);else{let s=r.pmt?r.pmt.filter(t=>t.pid===i):[];s.length>0&&d.Media(t,e,o[s[0].streamType][0])}}}static readHeader(t,e){let r={};r.sync=t.readUint8();let i=t.readUint16();r.error=i>>>15,r.payload=i>>>14&1,r.priority=i>>>13&1,r.pid=8191&i,i=t.readUint8(),r.scrambling=i>>6&3,r.adaptation=i>>4&3,r.continuity=15&i,r.packet=0===r.pid?"PAT":"MEDIA",e.header=r}static PAT(t,e,r){let i={},s=t.readUint8();t.skip(s),s=t.readUint8(),i.tabelID=s,s=t.readUint16(),i.error=s>>>7,i.zero=s>>>6&1,i.sectionLength=4095&s,i.streamID=t.readUint16(),i.current=1&t.readUint8(),i.sectionNumber=t.readUint8(),i.lastSectionNumber=t.readUint8();let n=(i.sectionLength-9)/4,a=[];for(let e=0;e0&&(r.pat=r.pat.concat(a)),i.list=a,i.program=t.readUint16(),i.pid=8191&t.readUint16(),e.payload=i}static PMT(t,e,r){let i={};e.header.packet="PMT";let s=t.readUint8();t.skip(s),s=t.readUint8(),i.tableID=s,s=t.readUint16(),i.sectionLength=4095&s,i.program=t.readUint16(),i.current=1&t.readUint8(),i.order=t.readUint8(),i.lastOrder=t.readUint8(),i.PCR_PID=8191&t.readUint16(),i.programLength=4095&t.readUint16();let n=(i.sectionLength-13)/5,a=[];for(let e=0;e({pid:t.pid,es:t.es,streamType:t.streamType,program:i.program}))),e.payload=i}static Media(t,e,r){let s=e.header,n={};if(s.type=r,3===s.adaptation&&(n.adaptationLength=t.readUint8(),n.adaptationLength>0)){let e=t.readUint8();n.discontinue=e>>>7,n.access=e>>>6&1,n.priority=e>>>5&1,n.PCR=e>>>4&1,n.OPCR=e>>>3&1,n.splicePoint=e>>>2&1,n.transportPrivate=e>>>1&1,n.adaptationField=1&e;let r=t.position;if(1===n.PCR&&(n.programClockBase=t.readUint32()<<1,e=t.readUint16(),n.programClockBase|=e>>>15,n.programClockExtension=511&e),1===n.OPCR&&(n.originProgramClockBase=t.readUint32()<<1,e=t.readUint16(),n.originProgramClockBase+=e>>>15,n.originProgramClockExtension=511&e),1===n.splicePoint&&(n.spliceCountdown=t.readUint8()),1===n.transportPrivate){let e=t.readUint8(),r=[];for(let i=0;i>>6&1,a=r>>>5&1;1===r>>>7&&(r=t.readUint16(),n.ltwValid=r>>>15,n.ltwOffset=61439&r),1===s&&(r=t.readUint24(),n.piecewiseRate=4194303&r),1===a&&(r=t.readInt8(),n.spliceType=r>>>4,n.dtsNextAU1=r>>>1&7,n.marker1=1&r,r=t.readUint16(),n.dtsNextAU2=r>>>1,n.marker2=1&r,r=t.readUint16(),n.dtsNextAU3=r),t.skip(e-1-(t.position-i))}let i=n.adaptationLength-1-(t.position-r);t.skip(i)}n.stream=new i.default(t.buffer.slice(t.position)),e.payload=n}static PES(t){let e={},r=t.payload.stream;if(1!==r.readUint24())e.ES={},e.ES.buffer=r;else{let t=r.readUint8();t>=224&&t<=239&&(e.type="video"),t>=192&&t<=223&&(e.type="audio");let i=r.readUint16();if(e.packetLength=i,"video"!==e.type&&"audio"!==e.type)throw new Error("format is not supported");{let t=r.readUint8();if(2!==t>>>6)throw new Error("error when parse pes header");t=r.readUint8(),e.ptsDTSFlag=t>>>6,e.escrFlag=t>>>5&1,e.esRateFlag=t>>>4&1,e.dsmFlag=t>>>3&1,e.additionalFlag=t>>>2&1,e.crcFlag=t>>>1&1,e.extensionFlag=1&t,e.pesHeaderLength=r.readUint8();let i=e.pesHeaderLength;if(2===e.ptsDTSFlag){let s=[];t=r.readUint8(),s.push(t>>>1&7),t=r.readUint16(),s.push(t>>>1),t=r.readUint16(),s.push(t>>>1),e.pts=s[0]<<30|s[1]<<15|s[2],i-=5,"video"===e.type&&(e.dts=e.pts)}if(3===e.ptsDTSFlag){let s=[];t=r.readUint8(),s.push(t>>>1&7),t=r.readUint16(),s.push(t>>>1),t=r.readUint16(),s.push(t>>>1),e.pts=s[0]<<30|s[1]<<15|s[2];let n=[];t=r.readUint8(),n.push(t>>>1&7),t=r.readUint16(),n.push(t>>>1),t=r.readUint16(),n.push(t>>>1),e.dts=n[0]<<30|n[1]<<15|n[2],i-=10}if(1===e.escrFlag){let s=[],n=[];t=r.readUint8(),s.push(t>>>3&7),s.push(3&t),t=r.readUint16(),s.push(t>>>13),s.push(3&t),t=r.readUint16(),s.push(t>>>13),n.push(3&t),t=r.readUint8(),n.push(t>>>1),e.escr=300*(s[0]<<30|s[1]<<28|s[2]<<15|s[3]<<13|s[4])+(n[0]<<7|n[1]),i-=6}if(1===e.esRateFlag&&(t=r.readUint24(),e.esRate=t>>>1&4194303,i-=3),1===e.dsmFlag)throw new Error("not support DSM_trick_mode");if(1===e.additionalFlag&&(t=r.readUint8(),e.additionalCopyInfo=127&t,i-=1),1===e.crcFlag&&(e.pesCRC=r.readUint16(),i-=2),1===e.extensionFlag)throw new Error("not support extension");i>0&&r.skip(i),e.ES=d.ES(r,e.type)}}return e}static ES(t,e){let r,i={};if("video"===e){if(1!==(r=t.readUint32())&&(t.back(4),1!==(r=t.readUint24())))throw new Error("h264 nal header parse failed");t.skip(2),i.buffer=t}else{if("audio"!==e)throw new Error(`ES ${e} is not supported`);{if((r=t.readUint16())>>>4!=4095)throw new Error("aac ES parse Error");const e=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];i.id=0==(r>>>3&1)?"MPEG-4":"MPEG-2",i.layer=r>>>1&3,i.absent=1&r,r=t.readUint16(),i.audioObjectType=1+(r>>>14&3),i.profile=i.audioObjectType-1,i.frequencyIndex=r>>>10&15,i.frequence=e[i.frequencyIndex],i.channel=r>>>6&7,i.frameLength=(3&r)<<11|t.readUint16()>>>5,i.audioConfig=d.getAudioConfig(i.audioObjectType,i.channel,i.frequencyIndex),t.skip(1),i.buffer=t}}return i}static TSDT(t,e,r){e.payload={}}static CAT(t,e,r){let i={};i.tableID=t.readUint8();let s=t.readUint16();i.sectionIndicator=s>>>7,i.sectionLength=4095&s,t.skip(2),s=t.readUint8(),i.version=s>>>3,i.currentNextIndicator=1&s,i.sectionNumber=t.readUint8(),i.lastSectionNumber=t.readUint8();let n=(this.sectionLength-9)/4,a=[];for(let t=0;t=6?(t=5,i=new Array(4),s=r-3):(t=2,i=new Array(2),s=r):-1!==n.indexOf("android")?(t=2,i=new Array(2),s=r):(t=5,i=new Array(4),r>=6?s=r-3:(1===e&&(t=2,i=new Array(2)),s=r)),i[0]=t<<3,i[0]|=(14&r)>>1,i[1]=(1&r)<<7,i[1]|=e<<3,5===t&&(i[1]|=(14&s)>>1,i[2]=(1&s)<<7,i[2]|=8,i[3]=0),i}}e.default=d},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});class i{constructor(t){if(!(t instanceof ArrayBuffer))throw new Error("data is invalid");this.buffer=t,this.dataview=new DataView(t),this.dataview.position=0}get length(){return this.buffer.byteLength}set position(t){this.dataview.position=t}get position(){return this.dataview.position}back(t){this.position-=t}skip(t){let e=Math.floor(t/4),r=t%4;for(let t=0;t0&&i.readByte(this.dataview,r)}static readByte(t,e,r){let i;switch(e){case 1:i=r?t.getInt8(t.position):t.getUint8(t.position);break;case 2:i=r?t.getInt16(t.position):t.getUint16(t.position);break;case 3:if(r)throw"not supported for readByte 3";i=t.getUint8(t.position)<<16,i|=t.getUint8(t.position+1)<<8,i|=t.getUint8(t.position+2);break;case 4:i=r?t.getInt32(t.position):t.getUint32(t.position);break;case 8:if(r)throw"not supported for readBody 8";i=t.getUint32(t.position)<<32,i|=t.getUint32(t.position+4);break;default:i=""}return t.position+=e,i}readUint8(){return i.readByte(this.dataview,1)}readUint16(){return i.readByte(this.dataview,2)}readUint24(){return i.readByte(this.dataview,3)}readUint32(){return i.readByte(this.dataview,4)}readUint64(){return i.readByte(this.dataview,8)}readInt8(){return i.readByte(this.dataview,1,!0)}readInt16(){return i.readByte(this.dataview,2,!0)}readInt32(){return i.readByte(this.dataview,4,!0)}writeUint32(t){return new Uint8Array([t>>>24&255,t>>>16&255,t>>>8&255,255&t])}}e.default=i},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i,s=r(13),n=(i=s)&&i.__esModule?i:{default:i};class a{static getNalunits(t){if(t.length-t.position<4)return[];let e=t.dataview,r=t.position;return 1===e.getInt32(r)||0===e.getInt16(r)&&1===e.getInt8(r+2)?a.getAnnexbNals(t):a.getAvccNals(t)}static getAnnexbNals(t){let e=[],r=a.getHeaderPositionAnnexB(t),i=r.pos,s=i;for(;i=r))break;{let i=t.buffer.slice(t.position,t.position+4);t.skip(4);let s=t.buffer.slice(t.position,t.position+r);t.skip(r);let n={header:i,body:s};a.analyseNal(n),e.push(n)}}return e}static analyseNal(t){switch(31&t.body[0]){case 1:t.ndr=!0;break;case 5:t.idr=!0;break;case 6:break;case 7:t.sps=n.default.parseSPS(t.body),console.log(t);break;case 8:t.pps=!0}}static getHeaderPositionAnnexB(t){let e=t.position,r=0;for(;3!==r&&4!==r&&e>>8&255,255&t.byteLength]),i),i+=2,r.set(t,i),r[i+=t.byteLength]=1,i++,r.set(new Uint8Array([e.byteLength>>>8&255,255&e.byteLength]),i),i+=2,r.set(e,i),r}}e.default=a},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i,s=r(14),n=(i=s)&&i.__esModule?i:{default:i};class a{static _ebsp2rbsp(t){let e=t,r=e.byteLength,i=new Uint8Array(r),s=0;for(let t=0;t=2&&3===e[t]&&0===e[t-1]&&0===e[t-2]||(i[s]=e[t],s++);return new Uint8Array(i.buffer,0,s)}static parseSPS(t){let e=a._ebsp2rbsp(t),r=new n.default(e);r.readByte();let i=r.readByte();r.readByte();let s=r.readByte();r.readUEG();let o=a.getProfileString(i),d=a.getLevelString(s),l=1,h=420,u=[0,420,422,444],c=8;if((100===i||110===i||122===i||244===i||44===i||83===i||86===i||118===i||128===i||138===i||144===i)&&(3===(l=r.readUEG())&&r.readBits(1),l<=3&&(h=u[l]),c=r.readUEG()+8,r.readUEG(),r.readBits(1),r.readBool())){let t=3!==l?8:12;for(let e=0;e0&&t<16?(m=e[t-1],U=i[t-1]):255===t&&(m=r.readByte()<<8|r.readByte(),U=r.readByte()<<8|r.readByte())}if(r.readBool()&&r.readBool(),r.readBool()&&(r.readBits(4),r.readBool()&&r.readBits(24)),r.readBool()&&(r.readUEG(),r.readUEG()),r.readBool()){let t=r.readBits(32),e=r.readBits(32);L=r.readBool(),w=(A=e)/(T=2*t)}}let O=1;1===m&&1===U||(O=m/U);let M=0,R=0;if(0===l)M=1,R=2-g;else{M=3===l?1:2,R=(1===l?2:1)*(2-g)}let I=16*(p+1),D=16*(_+1)*(2-g);I-=(y+E)*M,D-=(v+b)*R;let x=Math.ceil(I*O);return r.destroy(),r=null,{profile_string:o,level_string:d,bit_depth:c,chroma_format:h,chroma_format_string:a.getChromaFormatString(h),frame_rate:{fixed:L,fps:w,fps_den:T,fps_num:A},sar_ratio:{width:m,height:U},codec_size:{width:I,height:D},present_size:{width:x,height:D}}}static _skipScalingList(t,e){let r=8,i=8,s=0;for(let n=0;n0&&t.frame_rate.fps_den>0&&(e.frameRate=t.frame_rate);let r=e.frameRate.fps_den,i=e.frameRate.fps_num;e.refSampleDuration=Math.floor(e.timescale*(r/i))}}e.default=a},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t){this.TAG="Golomb",this._buffer=t,this._bufferIndex=0,this._totalBytes=t.byteLength,this._totalBits=8*t.byteLength,this._currentWord=0,this._currentWordBitsLeft=0}destroy(){this._buffer=null}_fillCurrentWord(){let t=this._totalBytes-this._bufferIndex,e=Math.min(4,t),r=new Uint8Array(4);r.set(this._buffer.subarray(this._bufferIndex,this._bufferIndex+e)),this._currentWord=new DataView(r.buffer).getUint32(0,!1),this._bufferIndex+=e,this._currentWordBitsLeft=8*e}readBits(t){if(t<=this._currentWordBitsLeft){let e=this._currentWord>>>32-t;return this._currentWord<<=t,this._currentWordBitsLeft-=t,e}let e=this._currentWordBitsLeft?this._currentWord:0;this._currentWordBitsLeft;let r=t-this._currentWordBitsLeft;this._fillCurrentWord();let i=Math.min(r,this._currentWordBitsLeft),s=this._currentWord>>>32-i;return this._currentWord<<=i,this._currentWordBitsLeft-=i,e=e<>>t))return this._currentWord<<=t,this._currentWordBitsLeft-=t,t;return this._fillCurrentWord(),t+this._skipLeadingZero()}readUEG(){let t=this._skipLeadingZero();return this.readBits(t+1)-1}readSEG(){let t=this.readUEG();return 1&t?t+1>>>1:-1*(t>>>1)}}}]); \ No newline at end of file +window.HlsLivePlayer=function(e){var t={};function r(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(i,s,function(t){return e[t]}.bind(null,s));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(4),n=(i=s)&&i.__esModule?i:{default:i};const a=r(5);t.default=class{constructor(e=[]){this._emitter=new a.EventEmitter,this._instanceMap={},this._clsMap={},this._inited=!1,this.mediaInfo=new n.default,this.allowedEvents=e}getInstance(e){if(this._instanceMap[e])return this._instanceMap[e];throw new Error(`${e}实例尚未初始化`)}initInstance(e,...t){if(this._clsMap[e]){const r=new this._clsMap[e](...t);return this._instanceMap[e]=r,r.init&&r.init(),r}throw new Error(`${e}未在context中注册`)}init(e){if(!this._inited){for(let t in this._clsMap)this._clsMap.hasOwnProperty(t)&&!this._instanceMap[t]&&this.initInstance(t,e);this._inited=!0}}registry(e,t){const r=this._emitter,i=this._isMessageNameValid.bind(this),s=this;return this._clsMap[e]=class extends t{constructor(...t){super(...t),this.listeners={},this.TAG=e,this._context=s}on(e,t){return i(e),this.listeners[e]?this.listeners[e].push(t):this.listeners[e]=[t],r.on(e,t)}once(e,t){return i(e),r.once(e,t)}emit(e,...t){return i(e),r.emit(e,...t)}off(e,t){return i(e),r.off(e,t)}removeListeners(){const e=Object.prototype.hasOwnProperty.bind(this.listeners);for(let t in this.listeners)if(e(t)){const e=this.listeners[t]||[];for(let i=0;ithis.initInstance(e,...t)}destroyInstances(){Object.keys(this._instanceMap).forEach(e=>{this._instanceMap[e].destroy&&this._instanceMap[e].destroy()})}destroy(){this._emitter=null,this.allowedEvents=null,this._clsMap=null,this.destroyInstances()}_isMessageNameValid(e){if(!this.allowedEvents.indexOf(e)<0)throw new Error(`unregistered message name: ${e}`)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RemuxBuffer=t.VideoTrack=t.AudioTrack=t.XgBuffer=void 0;var i,s=r(6),n=(i=s)&&i.__esModule?i:{default:i};t.XgBuffer=class{constructor(e){this.length=e||0,this.historyLen=e||0,this.array=[],this.offset=0}push(e){this.array.push(e),this.length+=e.byteLength,this.historyLen+=e.byteLength}shift(e){if(this.array.length<1)return new Uint8Array(0);if(void 0===e)return this._shiftBuffer();if(this.offset+e===this.array[0].length){let t=this.array[0].slice(this.offset,this.offset+e);return this.offset=0,this.array.shift(),this.length-=e,t}if(this.offset+e0&&e>0;){if(this.offset+e{let t=this._context.getInstance("TS_LOADER"),r=this._context.getInstance("M3U8_LOADER");if("M3U8_BUFFER"===e.TAG){let i=o.default.parse(e.shift(),this.baseurl);this._playlist.pushM3U8(i);let s=this._playlist.getTs();s?t.load(s.url):this.retrytimes>0&&(this.retrytimes--,r.load(this.url))}else if("TS_BUFFER"===e.TAG){this._context.getInstance("TS_DEMUXER").demux();let e=this._playlist.getTs();e?t.load(e.url):r.load(this.url)}})}load(e){this.baseurl=o.default.parseURL(e),this.url=e,this._context.getInstance("M3U8_LOADER").load(e)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=e=>{for(let t in e)if(e.hasOwnProperty(t)&&null===e[t])return!1;return!0};class s{constructor(){this.mimeType=null,this.duration=null,this.hasVideo=null,this.video={codec:null,width:null,height:null,profile:null,level:null,frameRate:{fixed:!0,fps:25,fps_num:25e3,fps_den:1e3},chromaFormat:null,sarRatio:{width:1,height:1}},this.hasAudio=null,this.audio={codec:null,sampleRate:null,sampleRateIndex:null,channelCount:null}}isComplete(){return s.isBaseInfoReady(this)&&s.isVideoReady(this)&&s.isAudioReady(this)}static isBaseInfoReady(e){return i(e)}static isVideoReady(e){return!e.hasVideo||i(e.video)}static isAudioReady(e){return!e.hasAudio||i(e.video)}}t.default=s},function(e,t,r){"use strict";var i,s="object"==typeof Reflect?Reflect:null,n=s&&"function"==typeof s.apply?s.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};i=s&&"function"==typeof s.ownKeys?s.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var a=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var d=10;function l(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function u(e,t,r,i){var s,n,a,o;if("function"!=typeof r)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r);if(void 0===(n=e._events)?(n=e._events=Object.create(null),e._eventsCount=0):(void 0!==n.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),n=e._events),a=n[t]),void 0===a)a=n[t]=r,++e._eventsCount;else if("function"==typeof a?a=n[t]=i?[r,a]:[a,r]:i?a.unshift(r):a.push(r),(s=l(e))>0&&a.length>s&&!a.warned){a.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=a.length,o=d,console&&console.warn&&console.warn(o)}return e}function h(){for(var e=[],t=0;t0&&(a=t[0]),a instanceof Error)throw a;var o=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw o.context=a,o}var d=s[e];if(void 0===d)return!1;if("function"==typeof d)n(d,this,t);else{var l=d.length,u=_(d,l);for(r=0;r=0;n--)if(r[n]===t||r[n].listener===t){a=r[n].listener,s=n;break}if(s<0)return this;0===s?r.shift():function(e,t){for(;t+1=0;i--)this.removeListener(e,t[i]);return this},o.prototype.listeners=function(e){return f(this,e,!0)},o.prototype.rawListeners=function(e){return f(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},o.prototype.listenerCount=p,o.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.id=-1,this.sequenceNumber=0,this.samples=[],this.length=0}reset(){this.sequenceNumber=0,this.samples=[],this.length=0}distroy(){this.reset(),this.id=-1}};t.Tracks=class{constructor(){this.audioTrack=null,this.videoTrack=null}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e){this._baseURL="",this._list={},this._ts={},this.version=0,this.sequence=-1,this.targetduration=0,this.duration=0,this._lastget=void 0,this._audoclear=e.autoclear||!1}get list(){return this._list}set baseURL(e){this.baseURL!==e&&(this.clear(),this._baseURL=e)}get baseURL(){return this._baseURL}push(e,t){this._ts[e]={duration:t,downloaded:!1,start:this.duration},this._list[this.duration]=e,this.duration+=t}pushM3U8(e){if(this.version=e.version,this.targetduration=e.targetduration,e.sequence>this.sequence){this.sequence=e.sequence;for(let t=0;t=this.duration)){for(let i=0;i=r[i];i++){let e=this._list[r[i]];t={url:e,downloaded:this._ts[e].downloaded,time:parseInt(r[i]),duration:parseInt(this._ts[e].duration)},this.autoclear&&(delete this._ts[this._lastget.url],delete this._list[this._lastget.time]),this._lastget=t}return t}}clear(){this._baseURL="",this._list={},this._ts={},this.version=0,this.sequence=-1,this.targetduration=0,this.duration=0}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(0),n=(i=s)&&i.__esModule?i:{default:i},a=r(9);const o=0,d=1,l=2;window.Context=n.default,t.default=class{constructor(e){this.configs=Object.assign({},e),this.url=null,this.status=0,this.error=null,this._reader=null,this.readtype=this.configs.readtype,this.buffer=this.configs.buffer||"LOADER_BUFFER"}static get type(){return"loader"}load(e,t){let r=this;this.url=e;let i=this.getParams(t);return fetch(this.url,i).then(function(e){return r.status=e.status,r.loading=!0,r._onFetchResponse(e)})}_onFetchResponse(e){let t=this,r=this._context.getInstance(this.buffer);if(!0===e.ok)switch(this.readtype){case l:e.json().then(e=>{r?(r.push(e),t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,r)):t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,e)});break;case d:e.text().then(e=>{r?(r.push(e),t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,r)):t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,e)});break;case o:default:return this._onReader(e.body.getReader())}}_onReader(e){let t=this._context.getInstance(this.buffer);if(t||this._reader.cancel(),this._reader=e,!1===this.loading)return;let r=this;this._reader&&this._reader.read().then(function(i){return i.done?(r.loading=!1,r.status=0,void r.emit(a.LOADER_EVENTS.LOADER_COMPLETE,t)):(t.push(i.value),r.emit(a.LOADER_EVENTS.LOADER_DATALOADED,t),r._onReader(e))}).catch(function(e){console.log(e)})}getParams(e){let t=Object.assign({},e),r=new Headers,i={method:"GET",headers:r,mode:"cors",cache:"default"};if("object"==typeof this.configs.headers){let e=this.configs.headers;for(let t in e)e.hasOwnProperty(t)&&r.append(t,e[t])}return!1===t.cors&&(i.mode="same-origin"),t.withCredentials&&(i.credentials="include"),i}cancel(){this._reader&&(this._reader.cancel(),this._reader=null)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=t.LOADER_EVENTS={LOADER_DATALOADED:"LOADER_DATALOADED",LOADER_COMPLETE:"LOADER_COMPLETE",LOADER_ERROR:"LOADER_ERROR"},s=t.DEMUX_EVENTS={DEMUX_COMPLETE:"DEMUX_COMPLETE",DEMUX_ERROR:"DEMUX_ERROR",METADATA_PARSED:"METADATA_COMPLETE",VIDEO_METADATA_CHANGE:"VIDEO_METADATA_CHANGE",AUDIO_METADATA_CHANGE:"AUDIO_METADATA_CHANGE",MEDIA_INFO:"MEDIA_INFO"},n=t.REMUX_EVENTS={MEDIA_SEGMENT:"MEDIA_SEGMENT",REMUX_ERROR:"REMUX_ERROR",INIT_SEGMENT:"INIT_SEGMENT"},a=Object.assign({},i,s,n),o=t.flvAllowedEvents=[];for(var d in a)a.hasOwnProperty(d)&&o.push(a[d]);t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{static parse(e,t=""){let r={duration:0},i=e.split(/\r|\n/),s=i.shift();if(!s.match("#EXTM3U"))return null;for(s=i.shift();void 0!==s;){let e=s.match(/#(.*):(.*)/);if(e&&e.length>2)switch(e[1]){case"EXT-X-VERSION":r.version=parseInt(e[2]);break;case"EXT-X-MEDIA-SEQUENCE":r.sequence=parseInt(e[2]);break;case"EXT-X-TARGETDURATION":r.targetduration=parseFloat(e[2]);break;case"EXTINF":r.frags||(r.frags=[]);let s={start:r.duration,duration:1e3*parseFloat(e[2])};r.duration+=s.duration,s.url=t+i.shift(),r.frags.push(s)}s=i.shift()}return r}static parseURL(e){let t="",r=e.match(/(.*\/).*\.m3u8$/);if(r&&r.length>0)for(let e=0;et.length&&(t=r[e]);return t}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=d(r(12)),s=d(r(13)),n=r(1),a=r(16),o=r(17);function d(e){return e&&e.__esModule?e:{default:e}}const l={1:["video","MPEG-1"],2:["video","MPEG-2"],27:["video","AVC.H264"],234:["video","VC-1"],3:["audio","MPEG-1"],4:["audio","MPEG-2"],15:["audio","MPEG-2.AAC"],17:["audio","MPEG-4.AAC"],128:["audio","LPCM"],129:["audio","AC3"],6:["audio","AC3"],130:["audio","DTS"],131:["audio","Dolby TrueHD"],132:["audio","AC3-Plus"],133:["audio","DTS-HD"],134:["audio","DTS-MA"],161:["audio","AC3-Plus-SEC"],162:["audio","DTS-HD-SEC"]};class u{constructor(e){this.configs=Object.assign({},e),this.demuxing=!1,this.pat=[],this.pmt=[]}init(){this.inputbuffer=this._context.getInstance(this.configs.inputbuffer)}demux(){if(this.demuxing)return;let e=this.inputbuffer,t={pat:[],pmt:[]},r={};for(;e.length>=188;){let s=e.shift(188),n=new i.default(s.buffer),a={};u.read(n,a,t),a.pes?(r[a.header.pid]||(r[a.header.pid]=[]),r[a.header.pid].push(a.pes),a.pes.ES.buffer=[a.pes.ES.buffer]):r[a.header.pid]&&r[a.header.pid][r[a.header.pid].length-1].ES.buffer.push(a.payload.stream)}for(let e=0;e>>24&255,i>>>16&255,i>>>8&255,255&i]),f),f+=4,c.set(t.body,f),f+=i)}let _=new a.VideoTrackSample({dts:e.dts,pts:e.pts,originDts:e.dts,isKeyframe:p,data:c});t.samples.push(_)}static Merge(e){let t,r=0,s=0;for(let t=0;te.pid===i))u.PMT(e,t,r);else{let s=r.pmt?r.pmt.filter(e=>e.pid===i):[];s.length>0&&u.Media(e,t,l[s[0].streamType][0])}}}static readHeader(e,t){let r={};r.sync=e.readUint8();let i=e.readUint16();r.error=i>>>15,r.payload=i>>>14&1,r.priority=i>>>13&1,r.pid=8191&i,i=e.readUint8(),r.scrambling=i>>6&3,r.adaptation=i>>4&3,r.continuity=15&i,r.packet=0===r.pid?"PAT":"MEDIA",t.header=r}static PAT(e,t,r){let i={},s=e.readUint8();e.skip(s),s=e.readUint8(),i.tabelID=s,s=e.readUint16(),i.error=s>>>7,i.zero=s>>>6&1,i.sectionLength=4095&s,i.streamID=e.readUint16(),i.current=1&e.readUint8(),i.sectionNumber=e.readUint8(),i.lastSectionNumber=e.readUint8();let n=(i.sectionLength-9)/4,a=[];for(let t=0;t0&&(r.pat=r.pat.concat(a)),i.list=a,i.program=e.readUint16(),i.pid=8191&e.readUint16(),t.payload=i}static PMT(e,t,r){let i={};t.header.packet="PMT";let s=e.readUint8();e.skip(s),s=e.readUint8(),i.tableID=s,s=e.readUint16(),i.sectionLength=4095&s,i.program=e.readUint16(),i.current=1&e.readUint8(),i.order=e.readUint8(),i.lastOrder=e.readUint8(),i.PCR_PID=8191&e.readUint16(),i.programLength=4095&e.readUint16();let n=(i.sectionLength-13)/5,a=[];for(let t=0;t({pid:e.pid,es:e.es,streamType:e.streamType,program:i.program}))),t.payload=i}static Media(e,t,r){let s=t.header,n={};if(s.type=r,3===s.adaptation&&(n.adaptationLength=e.readUint8(),n.adaptationLength>0)){let t=e.readUint8();n.discontinue=t>>>7,n.access=t>>>6&1,n.priority=t>>>5&1,n.PCR=t>>>4&1,n.OPCR=t>>>3&1,n.splicePoint=t>>>2&1,n.transportPrivate=t>>>1&1,n.adaptationField=1&t;let r=e.position;if(1===n.PCR&&(n.programClockBase=e.readUint32()<<1,t=e.readUint16(),n.programClockBase|=t>>>15,n.programClockExtension=511&t),1===n.OPCR&&(n.originProgramClockBase=e.readUint32()<<1,t=e.readUint16(),n.originProgramClockBase+=t>>>15,n.originProgramClockExtension=511&t),1===n.splicePoint&&(n.spliceCountdown=e.readUint8()),1===n.transportPrivate){let t=e.readUint8(),r=[];for(let i=0;i>>6&1,a=r>>>5&1;1===r>>>7&&(r=e.readUint16(),n.ltwValid=r>>>15,n.ltwOffset=61439&r),1===s&&(r=e.readUint24(),n.piecewiseRate=4194303&r),1===a&&(r=e.readInt8(),n.spliceType=r>>>4,n.dtsNextAU1=r>>>1&7,n.marker1=1&r,r=e.readUint16(),n.dtsNextAU2=r>>>1,n.marker2=1&r,r=e.readUint16(),n.dtsNextAU3=r),e.skip(t-1-(e.position-i))}let i=n.adaptationLength-1-(e.position-r);e.skip(i)}n.stream=new i.default(e.buffer.slice(e.position)),t.payload=n}static PES(e){let t={},r=e.payload.stream;if(1!==r.readUint24())t.ES={},t.ES.buffer=r;else{let e=r.readUint8();e>=224&&e<=239&&(t.type="video"),e>=192&&e<=223&&(t.type="audio");let i=r.readUint16();if(t.packetLength=i,"video"!==t.type&&"audio"!==t.type)throw new Error("format is not supported");{let e=r.readUint8();if(2!==e>>>6)throw new Error("error when parse pes header");e=r.readUint8(),t.ptsDTSFlag=e>>>6,t.escrFlag=e>>>5&1,t.esRateFlag=e>>>4&1,t.dsmFlag=e>>>3&1,t.additionalFlag=e>>>2&1,t.crcFlag=e>>>1&1,t.extensionFlag=1&e,t.pesHeaderLength=r.readUint8();let i=t.pesHeaderLength;if(2===t.ptsDTSFlag){let s=[];e=r.readUint8(),s.push(e>>>1&7),e=r.readUint16(),s.push(e>>>1),e=r.readUint16(),s.push(e>>>1),t.pts=s[0]<<30|s[1]<<15|s[2],i-=5,"video"===t.type&&(t.dts=t.pts)}if(3===t.ptsDTSFlag){let s=[];e=r.readUint8(),s.push(e>>>1&7),e=r.readUint16(),s.push(e>>>1),e=r.readUint16(),s.push(e>>>1),t.pts=s[0]<<30|s[1]<<15|s[2];let n=[];e=r.readUint8(),n.push(e>>>1&7),e=r.readUint16(),n.push(e>>>1),e=r.readUint16(),n.push(e>>>1),t.dts=n[0]<<30|n[1]<<15|n[2],i-=10}if(1===t.escrFlag){let s=[],n=[];e=r.readUint8(),s.push(e>>>3&7),s.push(3&e),e=r.readUint16(),s.push(e>>>13),s.push(3&e),e=r.readUint16(),s.push(e>>>13),n.push(3&e),e=r.readUint8(),n.push(e>>>1),t.escr=300*(s[0]<<30|s[1]<<28|s[2]<<15|s[3]<<13|s[4])+(n[0]<<7|n[1]),i-=6}if(1===t.esRateFlag&&(e=r.readUint24(),t.esRate=e>>>1&4194303,i-=3),1===t.dsmFlag)throw new Error("not support DSM_trick_mode");if(1===t.additionalFlag&&(e=r.readUint8(),t.additionalCopyInfo=127&e,i-=1),1===t.crcFlag&&(t.pesCRC=r.readUint16(),i-=2),1===t.extensionFlag)throw new Error("not support extension");i>0&&r.skip(i),t.ES=u.ES(r,t.type)}}return t}static ES(e,t){let r,i={};if("video"===t){if(1!==(r=e.readUint32())&&(e.back(4),1!==(r=e.readUint24())))throw new Error("h264 nal header parse failed");e.skip(2),i.buffer=e}else{if("audio"!==t)throw new Error(`ES ${t} is not supported`);{if((r=e.readUint16())>>>4!=4095)throw new Error("aac ES parse Error");const t=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];i.id=0==(r>>>3&1)?"MPEG-4":"MPEG-2",i.layer=r>>>1&3,i.absent=1&r,r=e.readUint16(),i.audioObjectType=1+(r>>>14&3),i.profile=i.audioObjectType-1,i.frequencyIndex=r>>>10&15,i.frequence=t[i.frequencyIndex],i.channel=r>>>6&7,i.frameLength=(3&r)<<11|e.readUint16()>>>5,i.audioConfig=u.getAudioConfig(i.audioObjectType,i.channel,i.frequencyIndex),e.skip(1),i.buffer=e}}return i}static TSDT(e,t,r){t.payload={}}static CAT(e,t,r){let i={};i.tableID=e.readUint8();let s=e.readUint16();i.sectionIndicator=s>>>7,i.sectionLength=4095&s,e.skip(2),s=e.readUint8(),i.version=s>>>3,i.currentNextIndicator=1&s,i.sectionNumber=e.readUint8(),i.lastSectionNumber=e.readUint8();let n=(this.sectionLength-9)/4,a=[];for(let e=0;e=6?(e=5,i=new Array(4),s=r-3):(e=2,i=new Array(2),s=r):-1!==n.indexOf("android")?(e=2,i=new Array(2),s=r):(e=5,i=new Array(4),r>=6?s=r-3:(1===t&&(e=2,i=new Array(2)),s=r)),i[0]=e<<3,i[0]|=(14&r)>>1,i[1]=(1&r)<<7,i[1]|=t<<3,5===e&&(i[1]|=(14&s)>>1,i[2]=(1&s)<<7,i[2]|=8,i[3]=0),i}}t.default=u},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class i{constructor(e){if(!(e instanceof ArrayBuffer))throw new Error("data is invalid");this.buffer=e,this.dataview=new DataView(e),this.dataview.position=0}get length(){return this.buffer.byteLength}set position(e){this.dataview.position=e}get position(){return this.dataview.position}back(e){this.position-=e}skip(e){let t=Math.floor(e/4),r=e%4;for(let e=0;e0&&i.readByte(this.dataview,r)}static readByte(e,t,r){let i;switch(t){case 1:i=r?e.getInt8(e.position):e.getUint8(e.position);break;case 2:i=r?e.getInt16(e.position):e.getUint16(e.position);break;case 3:if(r)throw"not supported for readByte 3";i=e.getUint8(e.position)<<16,i|=e.getUint8(e.position+1)<<8,i|=e.getUint8(e.position+2);break;case 4:i=r?e.getInt32(e.position):e.getUint32(e.position);break;case 8:if(r)throw"not supported for readBody 8";i=e.getUint32(e.position)<<32,i|=e.getUint32(e.position+4);break;default:i=""}return e.position+=t,i}readUint8(){return i.readByte(this.dataview,1)}readUint16(){return i.readByte(this.dataview,2)}readUint24(){return i.readByte(this.dataview,3)}readUint32(){return i.readByte(this.dataview,4)}readUint64(){return i.readByte(this.dataview,8)}readInt8(){return i.readByte(this.dataview,1,!0)}readInt16(){return i.readByte(this.dataview,2,!0)}readInt32(){return i.readByte(this.dataview,4,!0)}writeUint32(e){return new Uint8Array([e>>>24&255,e>>>16&255,e>>>8&255,255&e])}}t.default=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(14),n=(i=s)&&i.__esModule?i:{default:i};class a{static getNalunits(e){if(e.length-e.position<4)return[];let t=e.dataview,r=e.position;return 1===t.getInt32(r)||0===t.getInt16(r)&&1===t.getInt8(r+2)?a.getAnnexbNals(e):a.getAvccNals(e)}static getAnnexbNals(e){let t=[],r=a.getHeaderPositionAnnexB(e),i=r.pos,s=i;for(;i=r))break;{let i=e.buffer.slice(e.position,e.position+4);e.skip(4);let s=e.buffer.slice(e.position,e.position+r);e.skip(r);let n={header:i,body:s};a.analyseNal(n),t.push(n)}}return t}static analyseNal(e){switch(31&e.body[0]){case 1:e.ndr=!0;break;case 5:e.idr=!0;break;case 6:break;case 7:e.sps=n.default.parseSPS(e.body),console.log(e);break;case 8:e.pps=!0}}static getHeaderPositionAnnexB(e){let t=e.position,r=0;for(;3!==r&&4!==r&&t>>8&255,255&e.byteLength]),i),i+=2,r.set(e,i),r[i+=e.byteLength]=1,i++,r.set(new Uint8Array([t.byteLength>>>8&255,255&t.byteLength]),i),i+=2,r.set(t,i),r}}t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(15),n=(i=s)&&i.__esModule?i:{default:i};class a{static _ebsp2rbsp(e){let t=e,r=t.byteLength,i=new Uint8Array(r),s=0;for(let e=0;e=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(i[s]=t[e],s++);return new Uint8Array(i.buffer,0,s)}static parseSPS(e){let t=a._ebsp2rbsp(e),r=new n.default(t);r.readByte();let i=r.readByte();r.readByte();let s=r.readByte();r.readUEG();let o=a.getProfileString(i),d=a.getLevelString(s),l=1,u=420,h=[0,420,422,444],c=8;if((100===i||110===i||122===i||244===i||44===i||83===i||86===i||118===i||128===i||138===i||144===i)&&(3===(l=r.readUEG())&&r.readBits(1),l<=3&&(u=h[l]),c=r.readUEG()+8,r.readUEG(),r.readBits(1),r.readBool())){let e=3!==l?8:12;for(let t=0;t0&&e<16?(b=t[e-1],U=i[e-1]):255===e&&(b=r.readByte()<<8|r.readByte(),U=r.readByte()<<8|r.readByte())}if(r.readBool()&&r.readBool(),r.readBool()&&(r.readBits(4),r.readBool()&&r.readBits(24)),r.readBool()&&(r.readUEG(),r.readUEG()),r.readBool()){let e=r.readBits(32),t=r.readBits(32);A=r.readBool(),w=(L=t)/(T=2*e)}}let O=1;1===b&&1===U||(O=b/U);let M=0,R=0;if(0===l)M=1,R=2-g;else{M=3===l?1:2,R=(1===l?2:1)*(2-g)}let S=16*(p+1),D=16*(_+1)*(2-g);S-=(y+m)*M,D-=(E+v)*R;let I=Math.ceil(S*O);return r.destroy(),r=null,{profile_string:o,level_string:d,bit_depth:c,chroma_format:u,chroma_format_string:a.getChromaFormatString(u),frame_rate:{fixed:A,fps:w,fps_den:T,fps_num:L},sar_ratio:{width:b,height:U},codec_size:{width:S,height:D},present_size:{width:I,height:D}}}static _skipScalingList(e,t){let r=8,i=8,s=0;for(let n=0;n0&&e.frame_rate.fps_den>0&&(t.frameRate=e.frame_rate);let r=t.frameRate.fps_den,i=t.frameRate.fps_num;t.refSampleDuration=Math.floor(t.timescale*(r/i))}}t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e){this.TAG="Golomb",this._buffer=e,this._bufferIndex=0,this._totalBytes=e.byteLength,this._totalBits=8*e.byteLength,this._currentWord=0,this._currentWordBitsLeft=0}destroy(){this._buffer=null}_fillCurrentWord(){let e=this._totalBytes-this._bufferIndex,t=Math.min(4,e),r=new Uint8Array(4);r.set(this._buffer.subarray(this._bufferIndex,this._bufferIndex+t)),this._currentWord=new DataView(r.buffer).getUint32(0,!1),this._bufferIndex+=t,this._currentWordBitsLeft=8*t}readBits(e){if(e<=this._currentWordBitsLeft){let t=this._currentWord>>>32-e;return this._currentWord<<=e,this._currentWordBitsLeft-=e,t}let t=this._currentWordBitsLeft?this._currentWord:0;this._currentWordBitsLeft;let r=e-this._currentWordBitsLeft;this._fillCurrentWord();let i=Math.min(r,this._currentWordBitsLeft),s=this._currentWord>>>32-i;return this._currentWord<<=i,this._currentWordBitsLeft-=i,t=t<>>e))return this._currentWord<<=e,this._currentWordBitsLeft-=e,e;return this._fillCurrentWord(),e+this._skipLeadingZero()}readUEG(){let e=this._skipLeadingZero();return this.readBits(e+1)-1}readSEG(){let e=this.readUEG();return 1&e?e+1>>>1:-1*(e>>>1)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class i{constructor(e){let t=i.getDefault();return e?Object.assign({},t,e):t}static getDefault(){return{dts:null,pts:null,data:new Uint8Array}}}t.AudioTrackSample=i;class s{constructor(e){let t=s.getDefault();return e?Object.assign({},t,e):t}static getDefault(){return{dts:null,pts:null,isKeyframe:!1,originDts:null,data:new Uint8Array}}}t.VideoTrackSample=s},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.AudioTrackMeta=class{constructor(e){const t={audioSampleRate:48e3,channelCount:2,codec:"mp4a.40.2",config:[41,401,136,0],duration:0,id:2,refSampleDuration:21,sampleRateIndex:3,timescale:1e3,type:"audio"};return e?Object.assign({},t,e):t}};t.VideoTrackMeta=class{constructor(e){const t={avcc:null,chromaFormat:420,codec:"avc1.640020",codecHeight:720,codecWidth:1280,duration:0,frameRate:{fixed:!0,fps:25,fps_num:25e3,fps_den:1e3},id:1,level:"3.2",presentHeight:720,presentWidth:1280,profile:"High",refSampleDuration:40,sarRatio:{height:1,width:1},timescale:1e3,type:"video"};return e?Object.assign({},t,e):t}}}]); \ No newline at end of file diff --git a/packages/xgplayer-hls-live/dist/index.js b/packages/xgplayer-hls-live/dist/index.js index aaeacbd44..2b758b03e 100644 --- a/packages/xgplayer-hls-live/dist/index.js +++ b/packages/xgplayer-hls-live/dist/index.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["xgplayer-hls-live"]=t():e["xgplayer-hls-live"]=t()}(window,function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(i,s,function(t){return e[t]}.bind(null,s));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=r(4);t.default=class{constructor(e=[]){this._emitter=new i.EventEmitter,this._instanceMap={},this._clsMap={},this._inited=!1,this.allowedEvents=e}getInstance(e){if(this._instanceMap[e])return this._instanceMap[e];throw new Error(`${e}实例尚未初始化`)}initInstance(e,...t){if(this._clsMap[e]){const r=new this._clsMap[e](...t);return this._instanceMap[e]=r,r.init&&r.init(),r}throw new Error(`${e}未在context中注册`)}init(e){if(!this._inited){for(let t in this._clsMap)this._clsMap.hasOwnProperty(t)&&!this._instanceMap[t]&&this.initInstance(t,e);this._inited=!0}}registry(e,t){const r=this._emitter,i=this._isMessageNameValid.bind(this),s=this;return this._clsMap[e]=class extends t{constructor(...t){super(...t),this.listeners={},this.TAG=e,this._context=s}on(e,t){return i(e),this.listeners[e]?this.listeners[e].push(t):this.listeners[e]=[t],r.on(e,t)}once(e,t){return i(e),r.once(e,t)}emit(e,...t){return i(e),r.emit(e,...t)}off(e,t){return i(e),r.off(e,t)}removeListeners(){const e=Object.prototype.hasOwnProperty.bind(this.listeners);for(let t in this.listeners)if(e(t)){const e=this.listeners[t]||[];for(let i=0;ithis.initInstance(e,...t)}destroyInstances(){Object.keys(this._instanceMap).forEach(e=>{this._instanceMap[e].destroy&&this._instanceMap[e].destroy()})}destroy(){this._emitter=null,this.allowedEvents=null,this._clsMap=null,this.destroyInstances()}_isMessageNameValid(e){if(!this.allowedEvents.indexOf(e)<0)throw new Error(`unregistered message name: ${e}`)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RemuxBuffer=t.VideoTrack=t.AudioTrack=t.XgBuffer=void 0;var i,s=r(5),n=(i=s)&&i.__esModule?i:{default:i};t.XgBuffer=class{constructor(e){this.length=e||0,this.historyLen=e||0,this.array=[],this.offset=0}push(e){this.array.push(e),this.length+=e.byteLength,this.historyLen+=e.byteLength}shift(e){if(this.array.length<1)return new Uint8Array(0);if(void 0===e)return this._shiftBuffer();if(this.offset+e===this.array[0].length){let t=this.array[0].slice(this.offset,this.offset+e);return this.offset=0,this.array.shift(),this.length-=e,t}if(this.offset+e0&&e>0;){if(this.offset+e{let t=this._context.getInstance("TS_LOADER"),r=this._context.getInstance("M3U8_LOADER");if("M3U8_BUFFER"===e.TAG){let i=o.default.parse(e.shift(),this.baseurl);this._playlist.pushM3U8(i);let s=this._playlist.getTs();s?t.load(s.url):this.retrytimes>0&&(this.retrytimes--,r.load(this.url))}else if("TS_BUFFER"===e.TAG){this._context.getInstance("TS_DEMUXER").demux();let e=this._playlist.getTs();e?t.load(e.url):r.load(this.url)}})}load(e){this.baseurl=o.default.parseURL(e),this.url=e,this._context.getInstance("M3U8_LOADER").load(e)}}},function(e,t,r){"use strict";var i,s="object"==typeof Reflect?Reflect:null,n=s&&"function"==typeof s.apply?s.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};i=s&&"function"==typeof s.ownKeys?s.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var a=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var d=10;function l(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function h(e,t,r,i){var s,n,a,o;if("function"!=typeof r)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r);if(void 0===(n=e._events)?(n=e._events=Object.create(null),e._eventsCount=0):(void 0!==n.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),n=e._events),a=n[t]),void 0===a)a=n[t]=r,++e._eventsCount;else if("function"==typeof a?a=n[t]=i?[r,a]:[a,r]:i?a.unshift(r):a.push(r),(s=l(e))>0&&a.length>s&&!a.warned){a.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=a.length,o=d,console&&console.warn&&console.warn(o)}return e}function u(){for(var e=[],t=0;t0&&(a=t[0]),a instanceof Error)throw a;var o=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw o.context=a,o}var d=s[e];if(void 0===d)return!1;if("function"==typeof d)n(d,this,t);else{var l=d.length,h=_(d,l);for(r=0;r=0;n--)if(r[n]===t||r[n].listener===t){a=r[n].listener,s=n;break}if(s<0)return this;0===s?r.shift():function(e,t){for(;t+1=0;i--)this.removeListener(e,t[i]);return this},o.prototype.listeners=function(e){return f(this,e,!0)},o.prototype.rawListeners=function(e){return f(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},o.prototype.listenerCount=p,o.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.id=-1,this.sequenceNumber=0,this.samples=[],this.length=0}reset(){this.sequenceNumber=0,this.samples=[],this.length=0}distroy(){this.reset(),this.id=-1}};t.Tracks=class{constructor(){this.audioTrack=null,this.videoTrack=null}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e){this._baseURL="",this._list={},this._ts={},this.version=0,this.sequence=-1,this.targetduration=0,this.duration=0,this._lastget=void 0,this._audoclear=e.autoclear||!1}get list(){return this._list}set baseURL(e){this.baseURL!==e&&(this.clear(),this._baseURL=e)}get baseURL(){return this._baseURL}push(e,t){this._ts[e]={duration:t,downloaded:!1,start:this.duration},this._list[this.duration]=e,this.duration+=t}pushM3U8(e){if(this.version=e.version,this.targetduration=e.targetduration,e.sequence>this.sequence){this.sequence=e.sequence;for(let t=0;t=this.duration)){for(let i=0;i=r[i];i++){let e=this._list[r[i]];t={url:e,downloaded:this._ts[e].downloaded,time:parseInt(r[i]),duration:parseInt(this._ts[e].duration)},this.autoclear&&(delete this._ts[this._lastget.url],delete this._list[this._lastget.time]),this._lastget=t}return t}}clear(){this._baseURL="",this._list={},this._ts={},this.version=0,this.sequence=-1,this.targetduration=0,this.duration=0}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(0),n=(i=s)&&i.__esModule?i:{default:i},a=r(8);const o=0,d=1,l=2;window.Context=n.default,t.default=class{constructor(e){this.configs=Object.assign({},e),this.url=null,this.status=0,this.error=null,this._reader=null,this.readtype=this.configs.readtype,this.buffer=this.configs.buffer||"LOADER_BUFFER"}static get type(){return"loader"}load(e,t){let r=this;this.url=e;let i=this.getParams(t);return fetch(this.url,i).then(function(e){return r.status=e.status,r.loading=!0,r._onFetchResponse(e)})}_onFetchResponse(e){let t=this,r=this._context.getInstance(this.buffer);if(!0===e.ok)switch(this.readtype){case l:e.json().then(e=>{r?(r.push(e),t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,r)):t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,e)});break;case d:e.text().then(e=>{r?(r.push(e),t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,r)):t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,e)});break;case o:default:return this._onReader(e.body.getReader())}}_onReader(e){let t=this._context.getInstance(this.buffer);if(t||this._reader.cancel(),this._reader=e,!1===this.loading)return;let r=this;this._reader&&this._reader.read().then(function(i){return i.done?(r.loading=!1,r.status=0,void r.emit(a.LOADER_EVENTS.LOADER_COMPLETE,t)):(t.push(i.value),r.emit(a.LOADER_EVENTS.LOADER_DATALOADED,t),r._onReader(e))}).catch(function(e){console.log(e)})}getParams(e){let t=Object.assign({},e),r=new Headers,i={method:"GET",headers:r,mode:"cors",cache:"default"};if("object"==typeof this.configs.headers){let e=this.configs.headers;for(let t in e)e.hasOwnProperty(t)&&r.append(t,e[t])}return!1===t.cors&&(i.mode="same-origin"),t.withCredentials&&(i.credentials="include"),i}cancel(){this._reader&&(this._reader.cancel(),this._reader=null)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=t.LOADER_EVENTS={LOADER_DATALOADED:"LOADER_DATALOADED",LOADER_COMPLETE:"LOADER_COMPLETE",LOADER_ERROR:"LOADER_ERROR"},s=t.DEMUX_EVENTS={DEMUX_COMPLETE:"DEMUX_COMPLETE",DEMUX_ERROR:"DEMUX_ERROR",METADATA_PARSED:"METADATA_COMPLETE",VIDEO_METADATA_CHANGE:"VIDEO_METADATA_CHANGE",AUDIO_METADATA_CHANGE:"AUDIO_METADATA_CHANGE",MEDIA_INFO:"MEDIA_INFO"},n=t.REMUX_EVENTS={MEDIA_SEGMENT:"MEDIA_SEGMENT",REMUX_ERROR:"REMUX_ERROR",INIT_SEGMENT:"INIT_SEGMENT"},a=Object.assign({},i,s,n),o=t.flvAllowedEvents=[];for(var d in a)a.hasOwnProperty(d)&&o.push(a[d]);t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{static parse(e,t=""){let r={duration:0},i=e.split(/\r|\n/),s=i.shift();if(!s.match("#EXTM3U"))return null;for(s=i.shift();void 0!==s;){let e=s.match(/#(.*):(.*)/);if(e&&e.length>2)switch(e[1]){case"EXT-X-VERSION":r.version=parseInt(e[2]);break;case"EXT-X-MEDIA-SEQUENCE":r.sequence=parseInt(e[2]);break;case"EXT-X-TARGETDURATION":r.targetduration=parseFloat(e[2]);break;case"EXTINF":r.frags||(r.frags=[]);let s={start:r.duration,duration:1e3*parseFloat(e[2])};r.duration+=s.duration,s.url=t+i.shift(),r.frags.push(s)}s=i.shift()}return r}static parseURL(e){let t="",r=e.match(/(.*\/).*\.m3u8$/);if(r&&r.length>0)for(let e=0;et.length&&(t=r[e]);return t}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=a(r(11)),s=a(r(12)),n=r(1);function a(e){return e&&e.__esModule?e:{default:e}}const o={1:["video","MPEG-1"],2:["video","MPEG-2"],27:["video","AVC.H264"],234:["video","VC-1"],3:["audio","MPEG-1"],4:["audio","MPEG-2"],15:["audio","MPEG-2.AAC"],17:["audio","MPEG-4.AAC"],128:["audio","LPCM"],129:["audio","AC3"],6:["audio","AC3"],130:["audio","DTS"],131:["audio","Dolby TrueHD"],132:["audio","AC3-Plus"],133:["audio","DTS-HD"],134:["audio","DTS-MA"],161:["audio","AC3-Plus-SEC"],162:["audio","DTS-HD-SEC"]};class d{constructor(e){this.configs=Object.assign({},e),this.demuxing=!1,this.pat=[],this.pmt=[]}init(){this.inputbuffer=this._context.getInstance(this.configs.inputbuffer)}demux(){if(this.demuxing)return;let e=this.inputbuffer,t={pat:[],pmt:[]},r={};for(;e.length>=188;){let s=e.shift(188),n=new i.default(s.buffer),a={};d.read(n,a,t),a.pes?(r[a.header.pid]||(r[a.header.pid]=[]),r[a.header.pid].push(a.pes),a.pes.ES.buffer=[a.pes.ES.buffer]):r[a.header.pid]&&r[a.header.pid][r[a.header.pid].length-1].ES.buffer.push(a.payload.stream)}for(let e=0;e>>24&255,i>>>16&255,i>>>8&255,255&i]),o),o+=4,a.data.set(t.body,o),o+=i)}t.samples.push(a)}static Merge(e){let t,r=0,s=0;for(let t=0;te.pid===i))d.PMT(e,t,r);else{let s=r.pmt?r.pmt.filter(e=>e.pid===i):[];s.length>0&&d.Media(e,t,o[s[0].streamType][0])}}}static readHeader(e,t){let r={};r.sync=e.readUint8();let i=e.readUint16();r.error=i>>>15,r.payload=i>>>14&1,r.priority=i>>>13&1,r.pid=8191&i,i=e.readUint8(),r.scrambling=i>>6&3,r.adaptation=i>>4&3,r.continuity=15&i,r.packet=0===r.pid?"PAT":"MEDIA",t.header=r}static PAT(e,t,r){let i={},s=e.readUint8();e.skip(s),s=e.readUint8(),i.tabelID=s,s=e.readUint16(),i.error=s>>>7,i.zero=s>>>6&1,i.sectionLength=4095&s,i.streamID=e.readUint16(),i.current=1&e.readUint8(),i.sectionNumber=e.readUint8(),i.lastSectionNumber=e.readUint8();let n=(i.sectionLength-9)/4,a=[];for(let t=0;t0&&(r.pat=r.pat.concat(a)),i.list=a,i.program=e.readUint16(),i.pid=8191&e.readUint16(),t.payload=i}static PMT(e,t,r){let i={};t.header.packet="PMT";let s=e.readUint8();e.skip(s),s=e.readUint8(),i.tableID=s,s=e.readUint16(),i.sectionLength=4095&s,i.program=e.readUint16(),i.current=1&e.readUint8(),i.order=e.readUint8(),i.lastOrder=e.readUint8(),i.PCR_PID=8191&e.readUint16(),i.programLength=4095&e.readUint16();let n=(i.sectionLength-13)/5,a=[];for(let t=0;t({pid:e.pid,es:e.es,streamType:e.streamType,program:i.program}))),t.payload=i}static Media(e,t,r){let s=t.header,n={};if(s.type=r,3===s.adaptation&&(n.adaptationLength=e.readUint8(),n.adaptationLength>0)){let t=e.readUint8();n.discontinue=t>>>7,n.access=t>>>6&1,n.priority=t>>>5&1,n.PCR=t>>>4&1,n.OPCR=t>>>3&1,n.splicePoint=t>>>2&1,n.transportPrivate=t>>>1&1,n.adaptationField=1&t;let r=e.position;if(1===n.PCR&&(n.programClockBase=e.readUint32()<<1,t=e.readUint16(),n.programClockBase|=t>>>15,n.programClockExtension=511&t),1===n.OPCR&&(n.originProgramClockBase=e.readUint32()<<1,t=e.readUint16(),n.originProgramClockBase+=t>>>15,n.originProgramClockExtension=511&t),1===n.splicePoint&&(n.spliceCountdown=e.readUint8()),1===n.transportPrivate){let t=e.readUint8(),r=[];for(let i=0;i>>6&1,a=r>>>5&1;1===r>>>7&&(r=e.readUint16(),n.ltwValid=r>>>15,n.ltwOffset=61439&r),1===s&&(r=e.readUint24(),n.piecewiseRate=4194303&r),1===a&&(r=e.readInt8(),n.spliceType=r>>>4,n.dtsNextAU1=r>>>1&7,n.marker1=1&r,r=e.readUint16(),n.dtsNextAU2=r>>>1,n.marker2=1&r,r=e.readUint16(),n.dtsNextAU3=r),e.skip(t-1-(e.position-i))}let i=n.adaptationLength-1-(e.position-r);e.skip(i)}n.stream=new i.default(e.buffer.slice(e.position)),t.payload=n}static PES(e){let t={},r=e.payload.stream;if(1!==r.readUint24())t.ES={},t.ES.buffer=r;else{let e=r.readUint8();e>=224&&e<=239&&(t.type="video"),e>=192&&e<=223&&(t.type="audio");let i=r.readUint16();if(t.packetLength=i,"video"!==t.type&&"audio"!==t.type)throw new Error("format is not supported");{let e=r.readUint8();if(2!==e>>>6)throw new Error("error when parse pes header");e=r.readUint8(),t.ptsDTSFlag=e>>>6,t.escrFlag=e>>>5&1,t.esRateFlag=e>>>4&1,t.dsmFlag=e>>>3&1,t.additionalFlag=e>>>2&1,t.crcFlag=e>>>1&1,t.extensionFlag=1&e,t.pesHeaderLength=r.readUint8();let i=t.pesHeaderLength;if(2===t.ptsDTSFlag){let s=[];e=r.readUint8(),s.push(e>>>1&7),e=r.readUint16(),s.push(e>>>1),e=r.readUint16(),s.push(e>>>1),t.pts=s[0]<<30|s[1]<<15|s[2],i-=5,"video"===t.type&&(t.dts=t.pts)}if(3===t.ptsDTSFlag){let s=[];e=r.readUint8(),s.push(e>>>1&7),e=r.readUint16(),s.push(e>>>1),e=r.readUint16(),s.push(e>>>1),t.pts=s[0]<<30|s[1]<<15|s[2];let n=[];e=r.readUint8(),n.push(e>>>1&7),e=r.readUint16(),n.push(e>>>1),e=r.readUint16(),n.push(e>>>1),t.dts=n[0]<<30|n[1]<<15|n[2],i-=10}if(1===t.escrFlag){let s=[],n=[];e=r.readUint8(),s.push(e>>>3&7),s.push(3&e),e=r.readUint16(),s.push(e>>>13),s.push(3&e),e=r.readUint16(),s.push(e>>>13),n.push(3&e),e=r.readUint8(),n.push(e>>>1),t.escr=300*(s[0]<<30|s[1]<<28|s[2]<<15|s[3]<<13|s[4])+(n[0]<<7|n[1]),i-=6}if(1===t.esRateFlag&&(e=r.readUint24(),t.esRate=e>>>1&4194303,i-=3),1===t.dsmFlag)throw new Error("not support DSM_trick_mode");if(1===t.additionalFlag&&(e=r.readUint8(),t.additionalCopyInfo=127&e,i-=1),1===t.crcFlag&&(t.pesCRC=r.readUint16(),i-=2),1===t.extensionFlag)throw new Error("not support extension");i>0&&r.skip(i),t.ES=d.ES(r,t.type)}}return t}static ES(e,t){let r,i={};if("video"===t){if(1!==(r=e.readUint32())&&(e.back(4),1!==(r=e.readUint24())))throw new Error("h264 nal header parse failed");e.skip(2),i.buffer=e}else{if("audio"!==t)throw new Error(`ES ${t} is not supported`);{if((r=e.readUint16())>>>4!=4095)throw new Error("aac ES parse Error");const t=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];i.id=0==(r>>>3&1)?"MPEG-4":"MPEG-2",i.layer=r>>>1&3,i.absent=1&r,r=e.readUint16(),i.audioObjectType=1+(r>>>14&3),i.profile=i.audioObjectType-1,i.frequencyIndex=r>>>10&15,i.frequence=t[i.frequencyIndex],i.channel=r>>>6&7,i.frameLength=(3&r)<<11|e.readUint16()>>>5,i.audioConfig=d.getAudioConfig(i.audioObjectType,i.channel,i.frequencyIndex),e.skip(1),i.buffer=e}}return i}static TSDT(e,t,r){t.payload={}}static CAT(e,t,r){let i={};i.tableID=e.readUint8();let s=e.readUint16();i.sectionIndicator=s>>>7,i.sectionLength=4095&s,e.skip(2),s=e.readUint8(),i.version=s>>>3,i.currentNextIndicator=1&s,i.sectionNumber=e.readUint8(),i.lastSectionNumber=e.readUint8();let n=(this.sectionLength-9)/4,a=[];for(let e=0;e=6?(e=5,i=new Array(4),s=r-3):(e=2,i=new Array(2),s=r):-1!==n.indexOf("android")?(e=2,i=new Array(2),s=r):(e=5,i=new Array(4),r>=6?s=r-3:(1===t&&(e=2,i=new Array(2)),s=r)),i[0]=e<<3,i[0]|=(14&r)>>1,i[1]=(1&r)<<7,i[1]|=t<<3,5===e&&(i[1]|=(14&s)>>1,i[2]=(1&s)<<7,i[2]|=8,i[3]=0),i}}t.default=d},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class i{constructor(e){if(!(e instanceof ArrayBuffer))throw new Error("data is invalid");this.buffer=e,this.dataview=new DataView(e),this.dataview.position=0}get length(){return this.buffer.byteLength}set position(e){this.dataview.position=e}get position(){return this.dataview.position}back(e){this.position-=e}skip(e){let t=Math.floor(e/4),r=e%4;for(let e=0;e0&&i.readByte(this.dataview,r)}static readByte(e,t,r){let i;switch(t){case 1:i=r?e.getInt8(e.position):e.getUint8(e.position);break;case 2:i=r?e.getInt16(e.position):e.getUint16(e.position);break;case 3:if(r)throw"not supported for readByte 3";i=e.getUint8(e.position)<<16,i|=e.getUint8(e.position+1)<<8,i|=e.getUint8(e.position+2);break;case 4:i=r?e.getInt32(e.position):e.getUint32(e.position);break;case 8:if(r)throw"not supported for readBody 8";i=e.getUint32(e.position)<<32,i|=e.getUint32(e.position+4);break;default:i=""}return e.position+=t,i}readUint8(){return i.readByte(this.dataview,1)}readUint16(){return i.readByte(this.dataview,2)}readUint24(){return i.readByte(this.dataview,3)}readUint32(){return i.readByte(this.dataview,4)}readUint64(){return i.readByte(this.dataview,8)}readInt8(){return i.readByte(this.dataview,1,!0)}readInt16(){return i.readByte(this.dataview,2,!0)}readInt32(){return i.readByte(this.dataview,4,!0)}writeUint32(e){return new Uint8Array([e>>>24&255,e>>>16&255,e>>>8&255,255&e])}}t.default=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(13),n=(i=s)&&i.__esModule?i:{default:i};class a{static getNalunits(e){if(e.length-e.position<4)return[];let t=e.dataview,r=e.position;return 1===t.getInt32(r)||0===t.getInt16(r)&&1===t.getInt8(r+2)?a.getAnnexbNals(e):a.getAvccNals(e)}static getAnnexbNals(e){let t=[],r=a.getHeaderPositionAnnexB(e),i=r.pos,s=i;for(;i=r))break;{let i=e.buffer.slice(e.position,e.position+4);e.skip(4);let s=e.buffer.slice(e.position,e.position+r);e.skip(r);let n={header:i,body:s};a.analyseNal(n),t.push(n)}}return t}static analyseNal(e){switch(31&e.body[0]){case 1:e.ndr=!0;break;case 5:e.idr=!0;break;case 6:break;case 7:e.sps=n.default.parseSPS(e.body),console.log(e);break;case 8:e.pps=!0}}static getHeaderPositionAnnexB(e){let t=e.position,r=0;for(;3!==r&&4!==r&&t>>8&255,255&e.byteLength]),i),i+=2,r.set(e,i),r[i+=e.byteLength]=1,i++,r.set(new Uint8Array([t.byteLength>>>8&255,255&t.byteLength]),i),i+=2,r.set(t,i),r}}t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(14),n=(i=s)&&i.__esModule?i:{default:i};class a{static _ebsp2rbsp(e){let t=e,r=t.byteLength,i=new Uint8Array(r),s=0;for(let e=0;e=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(i[s]=t[e],s++);return new Uint8Array(i.buffer,0,s)}static parseSPS(e){let t=a._ebsp2rbsp(e),r=new n.default(t);r.readByte();let i=r.readByte();r.readByte();let s=r.readByte();r.readUEG();let o=a.getProfileString(i),d=a.getLevelString(s),l=1,h=420,u=[0,420,422,444],c=8;if((100===i||110===i||122===i||244===i||44===i||83===i||86===i||118===i||128===i||138===i||144===i)&&(3===(l=r.readUEG())&&r.readBits(1),l<=3&&(h=u[l]),c=r.readUEG()+8,r.readUEG(),r.readBits(1),r.readBool())){let e=3!==l?8:12;for(let t=0;t0&&e<16?(m=t[e-1],U=i[e-1]):255===e&&(m=r.readByte()<<8|r.readByte(),U=r.readByte()<<8|r.readByte())}if(r.readBool()&&r.readBool(),r.readBool()&&(r.readBits(4),r.readBool()&&r.readBits(24)),r.readBool()&&(r.readUEG(),r.readUEG()),r.readBool()){let e=r.readBits(32),t=r.readBits(32);A=r.readBool(),w=(L=t)/(T=2*e)}}let O=1;1===m&&1===U||(O=m/U);let M=0,R=0;if(0===l)M=1,R=2-g;else{M=3===l?1:2,R=(1===l?2:1)*(2-g)}let x=16*(p+1),I=16*(_+1)*(2-g);x-=(y+E)*M,I-=(v+b)*R;let D=Math.ceil(x*O);return r.destroy(),r=null,{profile_string:o,level_string:d,bit_depth:c,chroma_format:h,chroma_format_string:a.getChromaFormatString(h),frame_rate:{fixed:A,fps:w,fps_den:T,fps_num:L},sar_ratio:{width:m,height:U},codec_size:{width:x,height:I},present_size:{width:D,height:I}}}static _skipScalingList(e,t){let r=8,i=8,s=0;for(let n=0;n0&&e.frame_rate.fps_den>0&&(t.frameRate=e.frame_rate);let r=t.frameRate.fps_den,i=t.frameRate.fps_num;t.refSampleDuration=Math.floor(t.timescale*(r/i))}}t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e){this.TAG="Golomb",this._buffer=e,this._bufferIndex=0,this._totalBytes=e.byteLength,this._totalBits=8*e.byteLength,this._currentWord=0,this._currentWordBitsLeft=0}destroy(){this._buffer=null}_fillCurrentWord(){let e=this._totalBytes-this._bufferIndex,t=Math.min(4,e),r=new Uint8Array(4);r.set(this._buffer.subarray(this._bufferIndex,this._bufferIndex+t)),this._currentWord=new DataView(r.buffer).getUint32(0,!1),this._bufferIndex+=t,this._currentWordBitsLeft=8*t}readBits(e){if(e<=this._currentWordBitsLeft){let t=this._currentWord>>>32-e;return this._currentWord<<=e,this._currentWordBitsLeft-=e,t}let t=this._currentWordBitsLeft?this._currentWord:0;this._currentWordBitsLeft;let r=e-this._currentWordBitsLeft;this._fillCurrentWord();let i=Math.min(r,this._currentWordBitsLeft),s=this._currentWord>>>32-i;return this._currentWord<<=i,this._currentWordBitsLeft-=i,t=t<>>e))return this._currentWord<<=e,this._currentWordBitsLeft-=e,e;return this._fillCurrentWord(),e+this._skipLeadingZero()}readUEG(){let e=this._skipLeadingZero();return this.readBits(e+1)-1}readSEG(){let e=this.readUEG();return 1&e?e+1>>>1:-1*(e>>>1)}}}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["xgplayer-hls-live"]=t():e["xgplayer-hls-live"]=t()}(window,function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(i,s,function(t){return e[t]}.bind(null,s));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(4),n=(i=s)&&i.__esModule?i:{default:i};const a=r(5);t.default=class{constructor(e=[]){this._emitter=new a.EventEmitter,this._instanceMap={},this._clsMap={},this._inited=!1,this.mediaInfo=new n.default,this.allowedEvents=e}getInstance(e){if(this._instanceMap[e])return this._instanceMap[e];throw new Error(`${e}实例尚未初始化`)}initInstance(e,...t){if(this._clsMap[e]){const r=new this._clsMap[e](...t);return this._instanceMap[e]=r,r.init&&r.init(),r}throw new Error(`${e}未在context中注册`)}init(e){if(!this._inited){for(let t in this._clsMap)this._clsMap.hasOwnProperty(t)&&!this._instanceMap[t]&&this.initInstance(t,e);this._inited=!0}}registry(e,t){const r=this._emitter,i=this._isMessageNameValid.bind(this),s=this;return this._clsMap[e]=class extends t{constructor(...t){super(...t),this.listeners={},this.TAG=e,this._context=s}on(e,t){return i(e),this.listeners[e]?this.listeners[e].push(t):this.listeners[e]=[t],r.on(e,t)}once(e,t){return i(e),r.once(e,t)}emit(e,...t){return i(e),r.emit(e,...t)}off(e,t){return i(e),r.off(e,t)}removeListeners(){const e=Object.prototype.hasOwnProperty.bind(this.listeners);for(let t in this.listeners)if(e(t)){const e=this.listeners[t]||[];for(let i=0;ithis.initInstance(e,...t)}destroyInstances(){Object.keys(this._instanceMap).forEach(e=>{this._instanceMap[e].destroy&&this._instanceMap[e].destroy()})}destroy(){this._emitter=null,this.allowedEvents=null,this._clsMap=null,this.destroyInstances()}_isMessageNameValid(e){if(!this.allowedEvents.indexOf(e)<0)throw new Error(`unregistered message name: ${e}`)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RemuxBuffer=t.VideoTrack=t.AudioTrack=t.XgBuffer=void 0;var i,s=r(6),n=(i=s)&&i.__esModule?i:{default:i};t.XgBuffer=class{constructor(e){this.length=e||0,this.historyLen=e||0,this.array=[],this.offset=0}push(e){this.array.push(e),this.length+=e.byteLength,this.historyLen+=e.byteLength}shift(e){if(this.array.length<1)return new Uint8Array(0);if(void 0===e)return this._shiftBuffer();if(this.offset+e===this.array[0].length){let t=this.array[0].slice(this.offset,this.offset+e);return this.offset=0,this.array.shift(),this.length-=e,t}if(this.offset+e0&&e>0;){if(this.offset+e{let t=this._context.getInstance("TS_LOADER"),r=this._context.getInstance("M3U8_LOADER");if("M3U8_BUFFER"===e.TAG){let i=o.default.parse(e.shift(),this.baseurl);this._playlist.pushM3U8(i);let s=this._playlist.getTs();s?t.load(s.url):this.retrytimes>0&&(this.retrytimes--,r.load(this.url))}else if("TS_BUFFER"===e.TAG){this._context.getInstance("TS_DEMUXER").demux();let e=this._playlist.getTs();e?t.load(e.url):r.load(this.url)}})}load(e){this.baseurl=o.default.parseURL(e),this.url=e,this._context.getInstance("M3U8_LOADER").load(e)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=e=>{for(let t in e)if(e.hasOwnProperty(t)&&null===e[t])return!1;return!0};class s{constructor(){this.mimeType=null,this.duration=null,this.hasVideo=null,this.video={codec:null,width:null,height:null,profile:null,level:null,frameRate:{fixed:!0,fps:25,fps_num:25e3,fps_den:1e3},chromaFormat:null,sarRatio:{width:1,height:1}},this.hasAudio=null,this.audio={codec:null,sampleRate:null,sampleRateIndex:null,channelCount:null}}isComplete(){return s.isBaseInfoReady(this)&&s.isVideoReady(this)&&s.isAudioReady(this)}static isBaseInfoReady(e){return i(e)}static isVideoReady(e){return!e.hasVideo||i(e.video)}static isAudioReady(e){return!e.hasAudio||i(e.video)}}t.default=s},function(e,t,r){"use strict";var i,s="object"==typeof Reflect?Reflect:null,n=s&&"function"==typeof s.apply?s.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};i=s&&"function"==typeof s.ownKeys?s.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var a=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var d=10;function l(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function u(e,t,r,i){var s,n,a,o;if("function"!=typeof r)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r);if(void 0===(n=e._events)?(n=e._events=Object.create(null),e._eventsCount=0):(void 0!==n.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),n=e._events),a=n[t]),void 0===a)a=n[t]=r,++e._eventsCount;else if("function"==typeof a?a=n[t]=i?[r,a]:[a,r]:i?a.unshift(r):a.push(r),(s=l(e))>0&&a.length>s&&!a.warned){a.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=a.length,o=d,console&&console.warn&&console.warn(o)}return e}function h(){for(var e=[],t=0;t0&&(a=t[0]),a instanceof Error)throw a;var o=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw o.context=a,o}var d=s[e];if(void 0===d)return!1;if("function"==typeof d)n(d,this,t);else{var l=d.length,u=_(d,l);for(r=0;r=0;n--)if(r[n]===t||r[n].listener===t){a=r[n].listener,s=n;break}if(s<0)return this;0===s?r.shift():function(e,t){for(;t+1=0;i--)this.removeListener(e,t[i]);return this},o.prototype.listeners=function(e){return f(this,e,!0)},o.prototype.rawListeners=function(e){return f(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},o.prototype.listenerCount=p,o.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.id=-1,this.sequenceNumber=0,this.samples=[],this.length=0}reset(){this.sequenceNumber=0,this.samples=[],this.length=0}distroy(){this.reset(),this.id=-1}};t.Tracks=class{constructor(){this.audioTrack=null,this.videoTrack=null}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e){this._baseURL="",this._list={},this._ts={},this.version=0,this.sequence=-1,this.targetduration=0,this.duration=0,this._lastget=void 0,this._audoclear=e.autoclear||!1}get list(){return this._list}set baseURL(e){this.baseURL!==e&&(this.clear(),this._baseURL=e)}get baseURL(){return this._baseURL}push(e,t){this._ts[e]={duration:t,downloaded:!1,start:this.duration},this._list[this.duration]=e,this.duration+=t}pushM3U8(e){if(this.version=e.version,this.targetduration=e.targetduration,e.sequence>this.sequence){this.sequence=e.sequence;for(let t=0;t=this.duration)){for(let i=0;i=r[i];i++){let e=this._list[r[i]];t={url:e,downloaded:this._ts[e].downloaded,time:parseInt(r[i]),duration:parseInt(this._ts[e].duration)},this.autoclear&&(delete this._ts[this._lastget.url],delete this._list[this._lastget.time]),this._lastget=t}return t}}clear(){this._baseURL="",this._list={},this._ts={},this.version=0,this.sequence=-1,this.targetduration=0,this.duration=0}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(0),n=(i=s)&&i.__esModule?i:{default:i},a=r(9);const o=0,d=1,l=2;window.Context=n.default,t.default=class{constructor(e){this.configs=Object.assign({},e),this.url=null,this.status=0,this.error=null,this._reader=null,this.readtype=this.configs.readtype,this.buffer=this.configs.buffer||"LOADER_BUFFER"}static get type(){return"loader"}load(e,t){let r=this;this.url=e;let i=this.getParams(t);return fetch(this.url,i).then(function(e){return r.status=e.status,r.loading=!0,r._onFetchResponse(e)})}_onFetchResponse(e){let t=this,r=this._context.getInstance(this.buffer);if(!0===e.ok)switch(this.readtype){case l:e.json().then(e=>{r?(r.push(e),t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,r)):t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,e)});break;case d:e.text().then(e=>{r?(r.push(e),t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,r)):t.emit(a.LOADER_EVENTS.LOADER_COMPLETE,e)});break;case o:default:return this._onReader(e.body.getReader())}}_onReader(e){let t=this._context.getInstance(this.buffer);if(t||this._reader.cancel(),this._reader=e,!1===this.loading)return;let r=this;this._reader&&this._reader.read().then(function(i){return i.done?(r.loading=!1,r.status=0,void r.emit(a.LOADER_EVENTS.LOADER_COMPLETE,t)):(t.push(i.value),r.emit(a.LOADER_EVENTS.LOADER_DATALOADED,t),r._onReader(e))}).catch(function(e){console.log(e)})}getParams(e){let t=Object.assign({},e),r=new Headers,i={method:"GET",headers:r,mode:"cors",cache:"default"};if("object"==typeof this.configs.headers){let e=this.configs.headers;for(let t in e)e.hasOwnProperty(t)&&r.append(t,e[t])}return!1===t.cors&&(i.mode="same-origin"),t.withCredentials&&(i.credentials="include"),i}cancel(){this._reader&&(this._reader.cancel(),this._reader=null)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=t.LOADER_EVENTS={LOADER_DATALOADED:"LOADER_DATALOADED",LOADER_COMPLETE:"LOADER_COMPLETE",LOADER_ERROR:"LOADER_ERROR"},s=t.DEMUX_EVENTS={DEMUX_COMPLETE:"DEMUX_COMPLETE",DEMUX_ERROR:"DEMUX_ERROR",METADATA_PARSED:"METADATA_COMPLETE",VIDEO_METADATA_CHANGE:"VIDEO_METADATA_CHANGE",AUDIO_METADATA_CHANGE:"AUDIO_METADATA_CHANGE",MEDIA_INFO:"MEDIA_INFO"},n=t.REMUX_EVENTS={MEDIA_SEGMENT:"MEDIA_SEGMENT",REMUX_ERROR:"REMUX_ERROR",INIT_SEGMENT:"INIT_SEGMENT"},a=Object.assign({},i,s,n),o=t.flvAllowedEvents=[];for(var d in a)a.hasOwnProperty(d)&&o.push(a[d]);t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{static parse(e,t=""){let r={duration:0},i=e.split(/\r|\n/),s=i.shift();if(!s.match("#EXTM3U"))return null;for(s=i.shift();void 0!==s;){let e=s.match(/#(.*):(.*)/);if(e&&e.length>2)switch(e[1]){case"EXT-X-VERSION":r.version=parseInt(e[2]);break;case"EXT-X-MEDIA-SEQUENCE":r.sequence=parseInt(e[2]);break;case"EXT-X-TARGETDURATION":r.targetduration=parseFloat(e[2]);break;case"EXTINF":r.frags||(r.frags=[]);let s={start:r.duration,duration:1e3*parseFloat(e[2])};r.duration+=s.duration,s.url=t+i.shift(),r.frags.push(s)}s=i.shift()}return r}static parseURL(e){let t="",r=e.match(/(.*\/).*\.m3u8$/);if(r&&r.length>0)for(let e=0;et.length&&(t=r[e]);return t}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=d(r(12)),s=d(r(13)),n=r(1),a=r(16),o=r(17);function d(e){return e&&e.__esModule?e:{default:e}}const l={1:["video","MPEG-1"],2:["video","MPEG-2"],27:["video","AVC.H264"],234:["video","VC-1"],3:["audio","MPEG-1"],4:["audio","MPEG-2"],15:["audio","MPEG-2.AAC"],17:["audio","MPEG-4.AAC"],128:["audio","LPCM"],129:["audio","AC3"],6:["audio","AC3"],130:["audio","DTS"],131:["audio","Dolby TrueHD"],132:["audio","AC3-Plus"],133:["audio","DTS-HD"],134:["audio","DTS-MA"],161:["audio","AC3-Plus-SEC"],162:["audio","DTS-HD-SEC"]};class u{constructor(e){this.configs=Object.assign({},e),this.demuxing=!1,this.pat=[],this.pmt=[]}init(){this.inputbuffer=this._context.getInstance(this.configs.inputbuffer)}demux(){if(this.demuxing)return;let e=this.inputbuffer,t={pat:[],pmt:[]},r={};for(;e.length>=188;){let s=e.shift(188),n=new i.default(s.buffer),a={};u.read(n,a,t),a.pes?(r[a.header.pid]||(r[a.header.pid]=[]),r[a.header.pid].push(a.pes),a.pes.ES.buffer=[a.pes.ES.buffer]):r[a.header.pid]&&r[a.header.pid][r[a.header.pid].length-1].ES.buffer.push(a.payload.stream)}for(let e=0;e>>24&255,i>>>16&255,i>>>8&255,255&i]),f),f+=4,c.set(t.body,f),f+=i)}let _=new a.VideoTrackSample({dts:e.dts,pts:e.pts,originDts:e.dts,isKeyframe:p,data:c});t.samples.push(_)}static Merge(e){let t,r=0,s=0;for(let t=0;te.pid===i))u.PMT(e,t,r);else{let s=r.pmt?r.pmt.filter(e=>e.pid===i):[];s.length>0&&u.Media(e,t,l[s[0].streamType][0])}}}static readHeader(e,t){let r={};r.sync=e.readUint8();let i=e.readUint16();r.error=i>>>15,r.payload=i>>>14&1,r.priority=i>>>13&1,r.pid=8191&i,i=e.readUint8(),r.scrambling=i>>6&3,r.adaptation=i>>4&3,r.continuity=15&i,r.packet=0===r.pid?"PAT":"MEDIA",t.header=r}static PAT(e,t,r){let i={},s=e.readUint8();e.skip(s),s=e.readUint8(),i.tabelID=s,s=e.readUint16(),i.error=s>>>7,i.zero=s>>>6&1,i.sectionLength=4095&s,i.streamID=e.readUint16(),i.current=1&e.readUint8(),i.sectionNumber=e.readUint8(),i.lastSectionNumber=e.readUint8();let n=(i.sectionLength-9)/4,a=[];for(let t=0;t0&&(r.pat=r.pat.concat(a)),i.list=a,i.program=e.readUint16(),i.pid=8191&e.readUint16(),t.payload=i}static PMT(e,t,r){let i={};t.header.packet="PMT";let s=e.readUint8();e.skip(s),s=e.readUint8(),i.tableID=s,s=e.readUint16(),i.sectionLength=4095&s,i.program=e.readUint16(),i.current=1&e.readUint8(),i.order=e.readUint8(),i.lastOrder=e.readUint8(),i.PCR_PID=8191&e.readUint16(),i.programLength=4095&e.readUint16();let n=(i.sectionLength-13)/5,a=[];for(let t=0;t({pid:e.pid,es:e.es,streamType:e.streamType,program:i.program}))),t.payload=i}static Media(e,t,r){let s=t.header,n={};if(s.type=r,3===s.adaptation&&(n.adaptationLength=e.readUint8(),n.adaptationLength>0)){let t=e.readUint8();n.discontinue=t>>>7,n.access=t>>>6&1,n.priority=t>>>5&1,n.PCR=t>>>4&1,n.OPCR=t>>>3&1,n.splicePoint=t>>>2&1,n.transportPrivate=t>>>1&1,n.adaptationField=1&t;let r=e.position;if(1===n.PCR&&(n.programClockBase=e.readUint32()<<1,t=e.readUint16(),n.programClockBase|=t>>>15,n.programClockExtension=511&t),1===n.OPCR&&(n.originProgramClockBase=e.readUint32()<<1,t=e.readUint16(),n.originProgramClockBase+=t>>>15,n.originProgramClockExtension=511&t),1===n.splicePoint&&(n.spliceCountdown=e.readUint8()),1===n.transportPrivate){let t=e.readUint8(),r=[];for(let i=0;i>>6&1,a=r>>>5&1;1===r>>>7&&(r=e.readUint16(),n.ltwValid=r>>>15,n.ltwOffset=61439&r),1===s&&(r=e.readUint24(),n.piecewiseRate=4194303&r),1===a&&(r=e.readInt8(),n.spliceType=r>>>4,n.dtsNextAU1=r>>>1&7,n.marker1=1&r,r=e.readUint16(),n.dtsNextAU2=r>>>1,n.marker2=1&r,r=e.readUint16(),n.dtsNextAU3=r),e.skip(t-1-(e.position-i))}let i=n.adaptationLength-1-(e.position-r);e.skip(i)}n.stream=new i.default(e.buffer.slice(e.position)),t.payload=n}static PES(e){let t={},r=e.payload.stream;if(1!==r.readUint24())t.ES={},t.ES.buffer=r;else{let e=r.readUint8();e>=224&&e<=239&&(t.type="video"),e>=192&&e<=223&&(t.type="audio");let i=r.readUint16();if(t.packetLength=i,"video"!==t.type&&"audio"!==t.type)throw new Error("format is not supported");{let e=r.readUint8();if(2!==e>>>6)throw new Error("error when parse pes header");e=r.readUint8(),t.ptsDTSFlag=e>>>6,t.escrFlag=e>>>5&1,t.esRateFlag=e>>>4&1,t.dsmFlag=e>>>3&1,t.additionalFlag=e>>>2&1,t.crcFlag=e>>>1&1,t.extensionFlag=1&e,t.pesHeaderLength=r.readUint8();let i=t.pesHeaderLength;if(2===t.ptsDTSFlag){let s=[];e=r.readUint8(),s.push(e>>>1&7),e=r.readUint16(),s.push(e>>>1),e=r.readUint16(),s.push(e>>>1),t.pts=s[0]<<30|s[1]<<15|s[2],i-=5,"video"===t.type&&(t.dts=t.pts)}if(3===t.ptsDTSFlag){let s=[];e=r.readUint8(),s.push(e>>>1&7),e=r.readUint16(),s.push(e>>>1),e=r.readUint16(),s.push(e>>>1),t.pts=s[0]<<30|s[1]<<15|s[2];let n=[];e=r.readUint8(),n.push(e>>>1&7),e=r.readUint16(),n.push(e>>>1),e=r.readUint16(),n.push(e>>>1),t.dts=n[0]<<30|n[1]<<15|n[2],i-=10}if(1===t.escrFlag){let s=[],n=[];e=r.readUint8(),s.push(e>>>3&7),s.push(3&e),e=r.readUint16(),s.push(e>>>13),s.push(3&e),e=r.readUint16(),s.push(e>>>13),n.push(3&e),e=r.readUint8(),n.push(e>>>1),t.escr=300*(s[0]<<30|s[1]<<28|s[2]<<15|s[3]<<13|s[4])+(n[0]<<7|n[1]),i-=6}if(1===t.esRateFlag&&(e=r.readUint24(),t.esRate=e>>>1&4194303,i-=3),1===t.dsmFlag)throw new Error("not support DSM_trick_mode");if(1===t.additionalFlag&&(e=r.readUint8(),t.additionalCopyInfo=127&e,i-=1),1===t.crcFlag&&(t.pesCRC=r.readUint16(),i-=2),1===t.extensionFlag)throw new Error("not support extension");i>0&&r.skip(i),t.ES=u.ES(r,t.type)}}return t}static ES(e,t){let r,i={};if("video"===t){if(1!==(r=e.readUint32())&&(e.back(4),1!==(r=e.readUint24())))throw new Error("h264 nal header parse failed");e.skip(2),i.buffer=e}else{if("audio"!==t)throw new Error(`ES ${t} is not supported`);{if((r=e.readUint16())>>>4!=4095)throw new Error("aac ES parse Error");const t=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];i.id=0==(r>>>3&1)?"MPEG-4":"MPEG-2",i.layer=r>>>1&3,i.absent=1&r,r=e.readUint16(),i.audioObjectType=1+(r>>>14&3),i.profile=i.audioObjectType-1,i.frequencyIndex=r>>>10&15,i.frequence=t[i.frequencyIndex],i.channel=r>>>6&7,i.frameLength=(3&r)<<11|e.readUint16()>>>5,i.audioConfig=u.getAudioConfig(i.audioObjectType,i.channel,i.frequencyIndex),e.skip(1),i.buffer=e}}return i}static TSDT(e,t,r){t.payload={}}static CAT(e,t,r){let i={};i.tableID=e.readUint8();let s=e.readUint16();i.sectionIndicator=s>>>7,i.sectionLength=4095&s,e.skip(2),s=e.readUint8(),i.version=s>>>3,i.currentNextIndicator=1&s,i.sectionNumber=e.readUint8(),i.lastSectionNumber=e.readUint8();let n=(this.sectionLength-9)/4,a=[];for(let e=0;e=6?(e=5,i=new Array(4),s=r-3):(e=2,i=new Array(2),s=r):-1!==n.indexOf("android")?(e=2,i=new Array(2),s=r):(e=5,i=new Array(4),r>=6?s=r-3:(1===t&&(e=2,i=new Array(2)),s=r)),i[0]=e<<3,i[0]|=(14&r)>>1,i[1]=(1&r)<<7,i[1]|=t<<3,5===e&&(i[1]|=(14&s)>>1,i[2]=(1&s)<<7,i[2]|=8,i[3]=0),i}}t.default=u},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class i{constructor(e){if(!(e instanceof ArrayBuffer))throw new Error("data is invalid");this.buffer=e,this.dataview=new DataView(e),this.dataview.position=0}get length(){return this.buffer.byteLength}set position(e){this.dataview.position=e}get position(){return this.dataview.position}back(e){this.position-=e}skip(e){let t=Math.floor(e/4),r=e%4;for(let e=0;e0&&i.readByte(this.dataview,r)}static readByte(e,t,r){let i;switch(t){case 1:i=r?e.getInt8(e.position):e.getUint8(e.position);break;case 2:i=r?e.getInt16(e.position):e.getUint16(e.position);break;case 3:if(r)throw"not supported for readByte 3";i=e.getUint8(e.position)<<16,i|=e.getUint8(e.position+1)<<8,i|=e.getUint8(e.position+2);break;case 4:i=r?e.getInt32(e.position):e.getUint32(e.position);break;case 8:if(r)throw"not supported for readBody 8";i=e.getUint32(e.position)<<32,i|=e.getUint32(e.position+4);break;default:i=""}return e.position+=t,i}readUint8(){return i.readByte(this.dataview,1)}readUint16(){return i.readByte(this.dataview,2)}readUint24(){return i.readByte(this.dataview,3)}readUint32(){return i.readByte(this.dataview,4)}readUint64(){return i.readByte(this.dataview,8)}readInt8(){return i.readByte(this.dataview,1,!0)}readInt16(){return i.readByte(this.dataview,2,!0)}readInt32(){return i.readByte(this.dataview,4,!0)}writeUint32(e){return new Uint8Array([e>>>24&255,e>>>16&255,e>>>8&255,255&e])}}t.default=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(14),n=(i=s)&&i.__esModule?i:{default:i};class a{static getNalunits(e){if(e.length-e.position<4)return[];let t=e.dataview,r=e.position;return 1===t.getInt32(r)||0===t.getInt16(r)&&1===t.getInt8(r+2)?a.getAnnexbNals(e):a.getAvccNals(e)}static getAnnexbNals(e){let t=[],r=a.getHeaderPositionAnnexB(e),i=r.pos,s=i;for(;i=r))break;{let i=e.buffer.slice(e.position,e.position+4);e.skip(4);let s=e.buffer.slice(e.position,e.position+r);e.skip(r);let n={header:i,body:s};a.analyseNal(n),t.push(n)}}return t}static analyseNal(e){switch(31&e.body[0]){case 1:e.ndr=!0;break;case 5:e.idr=!0;break;case 6:break;case 7:e.sps=n.default.parseSPS(e.body),console.log(e);break;case 8:e.pps=!0}}static getHeaderPositionAnnexB(e){let t=e.position,r=0;for(;3!==r&&4!==r&&t>>8&255,255&e.byteLength]),i),i+=2,r.set(e,i),r[i+=e.byteLength]=1,i++,r.set(new Uint8Array([t.byteLength>>>8&255,255&t.byteLength]),i),i+=2,r.set(t,i),r}}t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,s=r(15),n=(i=s)&&i.__esModule?i:{default:i};class a{static _ebsp2rbsp(e){let t=e,r=t.byteLength,i=new Uint8Array(r),s=0;for(let e=0;e=2&&3===t[e]&&0===t[e-1]&&0===t[e-2]||(i[s]=t[e],s++);return new Uint8Array(i.buffer,0,s)}static parseSPS(e){let t=a._ebsp2rbsp(e),r=new n.default(t);r.readByte();let i=r.readByte();r.readByte();let s=r.readByte();r.readUEG();let o=a.getProfileString(i),d=a.getLevelString(s),l=1,u=420,h=[0,420,422,444],c=8;if((100===i||110===i||122===i||244===i||44===i||83===i||86===i||118===i||128===i||138===i||144===i)&&(3===(l=r.readUEG())&&r.readBits(1),l<=3&&(u=h[l]),c=r.readUEG()+8,r.readUEG(),r.readBits(1),r.readBool())){let e=3!==l?8:12;for(let t=0;t0&&e<16?(b=t[e-1],U=i[e-1]):255===e&&(b=r.readByte()<<8|r.readByte(),U=r.readByte()<<8|r.readByte())}if(r.readBool()&&r.readBool(),r.readBool()&&(r.readBits(4),r.readBool()&&r.readBits(24)),r.readBool()&&(r.readUEG(),r.readUEG()),r.readBool()){let e=r.readBits(32),t=r.readBits(32);A=r.readBool(),w=(L=t)/(T=2*e)}}let O=1;1===b&&1===U||(O=b/U);let M=0,R=0;if(0===l)M=1,R=2-g;else{M=3===l?1:2,R=(1===l?2:1)*(2-g)}let S=16*(p+1),D=16*(_+1)*(2-g);S-=(y+m)*M,D-=(E+v)*R;let x=Math.ceil(S*O);return r.destroy(),r=null,{profile_string:o,level_string:d,bit_depth:c,chroma_format:u,chroma_format_string:a.getChromaFormatString(u),frame_rate:{fixed:A,fps:w,fps_den:T,fps_num:L},sar_ratio:{width:b,height:U},codec_size:{width:S,height:D},present_size:{width:x,height:D}}}static _skipScalingList(e,t){let r=8,i=8,s=0;for(let n=0;n0&&e.frame_rate.fps_den>0&&(t.frameRate=e.frame_rate);let r=t.frameRate.fps_den,i=t.frameRate.fps_num;t.refSampleDuration=Math.floor(t.timescale*(r/i))}}t.default=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e){this.TAG="Golomb",this._buffer=e,this._bufferIndex=0,this._totalBytes=e.byteLength,this._totalBits=8*e.byteLength,this._currentWord=0,this._currentWordBitsLeft=0}destroy(){this._buffer=null}_fillCurrentWord(){let e=this._totalBytes-this._bufferIndex,t=Math.min(4,e),r=new Uint8Array(4);r.set(this._buffer.subarray(this._bufferIndex,this._bufferIndex+t)),this._currentWord=new DataView(r.buffer).getUint32(0,!1),this._bufferIndex+=t,this._currentWordBitsLeft=8*t}readBits(e){if(e<=this._currentWordBitsLeft){let t=this._currentWord>>>32-e;return this._currentWord<<=e,this._currentWordBitsLeft-=e,t}let t=this._currentWordBitsLeft?this._currentWord:0;this._currentWordBitsLeft;let r=e-this._currentWordBitsLeft;this._fillCurrentWord();let i=Math.min(r,this._currentWordBitsLeft),s=this._currentWord>>>32-i;return this._currentWord<<=i,this._currentWordBitsLeft-=i,t=t<>>e))return this._currentWord<<=e,this._currentWordBitsLeft-=e,e;return this._fillCurrentWord(),e+this._skipLeadingZero()}readUEG(){let e=this._skipLeadingZero();return this.readBits(e+1)-1}readSEG(){let e=this.readUEG();return 1&e?e+1>>>1:-1*(e>>>1)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});class i{constructor(e){let t=i.getDefault();return e?Object.assign({},t,e):t}static getDefault(){return{dts:null,pts:null,data:new Uint8Array}}}t.AudioTrackSample=i;class s{constructor(e){let t=s.getDefault();return e?Object.assign({},t,e):t}static getDefault(){return{dts:null,pts:null,isKeyframe:!1,originDts:null,data:new Uint8Array}}}t.VideoTrackSample=s},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.AudioTrackMeta=class{constructor(e){const t={audioSampleRate:48e3,channelCount:2,codec:"mp4a.40.2",config:[41,401,136,0],duration:0,id:2,refSampleDuration:21,sampleRateIndex:3,timescale:1e3,type:"audio"};return e?Object.assign({},t,e):t}};t.VideoTrackMeta=class{constructor(e){const t={avcc:null,chromaFormat:420,codec:"avc1.640020",codecHeight:720,codecWidth:1280,duration:0,frameRate:{fixed:!0,fps:25,fps_num:25e3,fps_den:1e3},id:1,level:"3.2",presentHeight:720,presentWidth:1280,profile:"High",refSampleDuration:40,sarRatio:{height:1,width:1},timescale:1e3,type:"video"};return e?Object.assign({},t,e):t}}}])}); \ No newline at end of file diff --git a/packages/xgplayer-hls-live/src/demuxer/ts.js b/packages/xgplayer-hls-live/src/demuxer/ts.js index 31ef7802e..9ad65b73e 100644 --- a/packages/xgplayer-hls-live/src/demuxer/ts.js +++ b/packages/xgplayer-hls-live/src/demuxer/ts.js @@ -1,6 +1,9 @@ import Stream from '../stream'; import Nalunit from '../../../xgplayer-utils/src/h264/nalunit'; import { AudioTrack, VideoTrack } from '../../../xgplayer-buffer/src/index'; +import { AudioTrackSample, VideoTrackSample } from '../../../xgplayer-utils/src/models/trackSample'; +import { AudioTrackMeta, VideoTrackMeta } from '../../../xgplayer-utils/src/models/trackMeta'; + const StreamType = { 0x01: ['video', 'MPEG-1'], 0x02: ['video', 'MPEG-2'], @@ -64,9 +67,10 @@ class TsDemuxer { for (let i = 0; i < Object.keys(peses).length; i++) { let epeses = peses[Object.keys(peses)[i]]; for (let j = 0; j < epeses.length; j++) { + epeses[j].id = Object.keys(peses)[i]; epeses[j].ES.buffer = TsDemuxer.Merge(epeses[j].ES.buffer); if (epeses[j].type === 'audio') { - console.log(epeses[j]); + this.pushAudioSample(epeses[j]); } else if (epeses[j].type === 'video') { this.pushVideoSample(epeses[j]); } @@ -80,12 +84,25 @@ class TsDemuxer { pushAudioSample (pes) { let track; if (!this._context._clsMap['AUDIO_TRACK']) { - this._context.registry('AUDIO_TRACK', VideoTrack); + this._context.registry('AUDIO_TRACK', AudioTrack); track = this._context.initInstance('AUDIO_TRACK'); + track.meta = new AudioTrackMeta({ + audioSampleRate: pes.ES.frequence, + channelCount: pes.ES.channel, + codec: 'mp4a.40.' + pes.ES.audioObjectType, + config: pes.ES.audioConfig, + id: pes.id, + sampleRateIndex: pes.ES.frequencyIndex + }); + track.meta.refSampleDuration = Math.floor(1024 / track.meta.audioSampleRate * track.meta.timescale); } else { track = this._context.getInstance('AUDIO_TRACK'); } - track.samples.push(pes); + let data = pes.ES.buffer; + let dts = pes.pts; + let pts = pes.pts; + let sample = new AudioTrackSample({dts, pts, data}); + track.samples.push(sample); } pushVideoSample (pes) { @@ -94,39 +111,80 @@ class TsDemuxer { if (!this._context._clsMap['VIDEO_TRACK']) { this._context.registry('VIDEO_TRACK', VideoTrack); track = this._context.initInstance('VIDEO_TRACK'); + track.meta = new VideoTrackMeta(); + console.log(pes); } else { track = this._context.getInstance('VIDEO_TRACK'); } - + let sampleLength = 0; + let sps = false; + let pps = false; for (let i = 0; i < nals.length; i++) { let nal = nals[i]; if (nal.sps) { - track.meta = nal.sps; + // TODO:VideoTrack信息 和 Meta 信息 track.sps = nal.body; + sps = nal; + track.meta.chromaFormat = sps.sps.chroma_format_string + track.meta.codec = 'avc1.'; + for (var j = 1; j < 4; j++) { + var h = sps.body[j].toString(16); + if (h.length < 2) { + h = '0' + h; + } + track.meta.codec += h; + } + track.meta.codecHeight = sps.sps.codec_size.height; + track.meta.codecWidth = sps.sps.codec_size.width; + track.meta.frameRate = sps.sps.frame_rate; + track.meta.id = pes.id; + track.meta.level = sps.sps.level_string; + track.meta.presentHeight = sps.sps.present_size.height; + track.meta.presentWidth = sps.sps.present_size.width; + track.meta.profile = sps.sps.profile_string; + track.meta.refSampleDuration = Math.floor(track.meta.timescale * (sps.sps.frame_rate.fps_den / sps.sps.frame_rate.fps_num)); + track.meta.sarRatio = sps.sps.sar_ratio; } else if (nal.pps) { track.pps = nal.body; + pps = nal; } else { sampleLength += (4 + nal.body.byteLength); } } - let sample = { pts: parseInt(pes.pts / 90), dts: parseInt(pes.dts / 90), data: new Uint8Array(sampleLength) } + if (sps && pps) { + track.meta.avcc = Nalunit.getAvcc(sps.body, pps.body); + console.log(track); + } + + let data = new Uint8Array(sampleLength); let offset = 0; + let isKeyframe = false; for (let i = 0; i < nals.length; i++) { let nal = nals[i]; let length = nal.body.byteLength; + if (nal.idr) { + isKeyframe = true; + } if (!nal.pps && !nal.sps) { - sample.data.set(new Uint8Array([length >>> 24 & 0xff, + data.set(new Uint8Array([length >>> 24 & 0xff, length >>> 16 & 0xff, length >>> 8 & 0xff, length & 0xff ]), offset); offset += 4; - sample.data.set(nal.body, offset); + data.set(nal.body, offset); offset += length; } } + let sample = new VideoTrackSample({ + dts: pes.dts, + pts: pes.pts, + originDts: pes.dts, + isKeyframe, + data + }) track.samples.push(sample); } diff --git a/packages/xgplayer-utils/src/models/trackSample.js b/packages/xgplayer-utils/src/models/trackSample.js index 3a1de6bd5..59a49b82c 100644 --- a/packages/xgplayer-utils/src/models/trackSample.js +++ b/packages/xgplayer-utils/src/models/trackSample.js @@ -9,7 +9,7 @@ export class AudioTrackSample { return sample } - static getDefaultInf () { + static getDefault () { return { dts: null, pts: null, @@ -30,7 +30,7 @@ export class VideoTrackSample { return sample } - static getDefaultInf () { + static getDefault () { return { dts: null, pts: null,