@dolbylaboratories/alps 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ var Ot=Object.create;var q=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var Ct=Object.getPrototypeOf,Tt=Object.prototype.hasOwnProperty;var rt=i=>{throw TypeError(i)};var It=(i,t,s)=>t in i?q(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s;var Pt=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports);var St=(i,t,s,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let _ of Lt(t))!Tt.call(i,_)&&_!==s&&q(i,_,{get:()=>t[_],enumerable:!(e=Dt(t,_))||e.enumerable});return i};var kt=(i,t,s)=>(s=i!=null?Ot(Ct(i)):{},St(t||!i||!i.__esModule?q(s,"default",{value:i,enumerable:!0}):s,i));var a=(i,t,s)=>It(i,typeof t!="symbol"?t+"":t,s),Q=(i,t,s)=>t.has(i)||rt("Cannot "+s);var E=(i,t,s)=>(Q(i,t,"read from private field"),s?s.call(i):t.get(i)),H=(i,t,s)=>t.has(i)?rt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,s),ot=(i,t,s,e)=>(Q(i,t,"write to private field"),e?e.call(i,s):t.set(i,s),s),U=(i,t,s)=>(Q(i,t,"access private method"),s);var xt=Pt(D=>{var m={};m.parseBuffer=function(i){return new w(i).parse()};m.addBoxProcessor=function(i,t){typeof i!="string"||typeof t!="function"||(n.prototype._boxProcessors[i]=t)};m.createFile=function(){return new w};m.createBox=function(i,t,s){var e=n.create(i);return t&&t.append(e,s),e};m.createFullBox=function(i,t,s){var e=m.createBox(i,t,s);return e.version=0,e.flags=0,e};m.Utils={};m.Utils.dataViewToString=function(i,t){var s=t||"utf-8";if(typeof TextDecoder<"u")return new TextDecoder(s).decode(i);var e=[],_=0;if(s==="utf-8")for(;_<i.byteLength;){var r=i.getUint8(_++);r<128||(r<224?(r=(r&31)<<6,r|=i.getUint8(_++)&63):r<240?(r=(r&15)<<12,r|=(i.getUint8(_++)&63)<<6,r|=i.getUint8(_++)&63):(r=(r&7)<<18,r|=(i.getUint8(_++)&63)<<12,r|=(i.getUint8(_++)&63)<<6,r|=i.getUint8(_++)&63)),e.push(String.fromCharCode(r))}else for(;_<i.byteLength;)e.push(String.fromCharCode(i.getUint8(_++)));return e.join("")};m.Utils.utf8ToByteArray=function(i){var t,s;if(typeof TextEncoder<"u")t=new TextEncoder().encode(i);else for(t=[],s=0;s<i.length;++s){var e=i.charCodeAt(s);e<128?t.push(e):e<2048?(t.push(192|e>>6),t.push(128|63&e)):e<65536?(t.push(224|e>>12),t.push(128|63&e>>6),t.push(128|63&e)):(t.push(240|e>>18),t.push(128|63&e>>12),t.push(128|63&e>>6),t.push(128|63&e))}return t};m.Utils.appendBox=function(i,t,s){if(t._offset=i._cursor.offset,t._root=i._root?i._root:i,t._raw=i._raw,t._parent=i,s!==-1){if(s==null){i.boxes.push(t);return}var e=-1,_;if(typeof s=="number")e=s;else{if(typeof s=="string")_=s;else if(typeof s=="object"&&s.type)_=s.type;else{i.boxes.push(t);return}for(var r=0;r<i.boxes.length;r++)if(_===i.boxes[r].type){e=r+1;break}}i.boxes.splice(e,0,t)}};typeof D<"u"&&(D.parseBuffer=m.parseBuffer,D.addBoxProcessor=m.addBoxProcessor,D.createFile=m.createFile,D.createBox=m.createBox,D.createFullBox=m.createFullBox,D.Utils=m.Utils);m.Cursor=function(i){this.offset=typeof i>"u"?0:i};var w=function(i){this._cursor=new m.Cursor,this.boxes=[],i&&(this._raw=new DataView(i))};w.prototype.fetch=function(i){var t=this.fetchAll(i,!0);return t.length?t[0]:null};w.prototype.fetchAll=function(i,t){var s=[];return w._sweep.call(this,i,s,t),s};w.prototype.parse=function(){for(this._cursor.offset=0,this.boxes=[];this._cursor.offset<this._raw.byteLength;){var i=n.parse(this);if(typeof i.type>"u")break;this.boxes.push(i)}return this};w._sweep=function(i,t,s){this.type&&this.type==i&&t.push(this);for(var e in this.boxes){if(t.length&&s)return;w._sweep.call(this.boxes[e],i,t,s)}};w.prototype.write=function(){var i=0,t;for(t=0;t<this.boxes.length;t++)i+=this.boxes[t].getLength(!1);var s=new Uint8Array(i);for(this._rawo=new DataView(s.buffer),this.bytes=s,this._cursor.offset=0,t=0;t<this.boxes.length;t++)this.boxes[t].write();return s.buffer};w.prototype.append=function(i,t){m.Utils.appendBox(this,i,t)};var n=function(){this._cursor=new m.Cursor};n.parse=function(i){var t=new n;return t._offset=i._cursor.offset,t._root=i._root?i._root:i,t._raw=i._raw,t._parent=i,t._parseBox(),i._cursor.offset=t._raw.byteOffset+t._raw.byteLength,t};n.create=function(i){var t=new n;return t.type=i,t.boxes=[],t};n.prototype._boxContainers=["dinf","edts","mdia","meco","mfra","minf","moof","moov","mvex","stbl","strk","traf","trak","tref","udta","vttc","sinf","schi","encv","enca","meta","grpl","prsl"];n.prototype._boxProcessors={};n.prototype._procField=function(i,t,s){this._parsing?this[i]=this._readField(t,s):this._writeField(t,s,this[i])};n.prototype._procFieldArray=function(i,t,s,e){var _;if(this._parsing)for(this[i]=[],_=0;_<t;_++)this[i][_]=this._readField(s,e);else for(_=0;_<this[i].length;_++)this._writeField(s,e,this[i][_])};n.prototype._procFullBox=function(){this._procField("version","uint",8),this._procField("flags","uint",24)};n.prototype._procEntries=function(i,t,s){var e;if(this._parsing)for(this[i]=[],e=0;e<t;e++)this[i].push({}),s.call(this,this[i][e]);else for(e=0;e<t;e++)s.call(this,this[i][e])};n.prototype._procSubEntries=function(i,t,s,e){var _;if(this._parsing)for(i[t]=[],_=0;_<s;_++)i[t].push({}),e.call(this,i[t][_]);else for(_=0;_<s;_++)e.call(this,i[t][_])};n.prototype._procEntryField=function(i,t,s,e){this._parsing?i[t]=this._readField(s,e):this._writeField(s,e,i[t])};n.prototype._procSubBoxes=function(i,t){var s;if(this._parsing)for(this[i]=[],s=0;s<t;s++)this[i].push(n.parse(this));else for(s=0;s<t;s++)this._rawo?this[i][s].write():this.size+=this[i][s].getLength()};n.prototype._readField=function(i,t){switch(i){case"uint":return this._readUint(t);case"int":return this._readInt(t);case"template":return this._readTemplate(t);case"string":return t===-1?this._readTerminatedString():this._readString(t);case"data":return this._readData(t);case"utf8":return this._readUTF8String();case"utf8string":return this._readUTF8TerminatedString();default:return-1}};n.prototype._readInt=function(i){var t=null,s=this._cursor.offset-this._raw.byteOffset;switch(i){case 8:t=this._raw.getInt8(s);break;case 16:t=this._raw.getInt16(s);break;case 32:t=this._raw.getInt32(s);break;case 64:var e=this._raw.getInt32(s),_=this._raw.getInt32(s+4);t=e*Math.pow(2,32)+_;break}return this._cursor.offset+=i>>3,t};n.prototype._readUint=function(i){var t=null,s=this._cursor.offset-this._raw.byteOffset,e,_;switch(i){case 8:t=this._raw.getUint8(s);break;case 16:t=this._raw.getUint16(s);break;case 24:e=this._raw.getUint16(s),_=this._raw.getUint8(s+2),t=(e<<8)+_;break;case 32:t=this._raw.getUint32(s);break;case 64:e=this._raw.getUint32(s),_=this._raw.getUint32(s+4),t=e*Math.pow(2,32)+_;break}return this._cursor.offset+=i>>3,t};n.prototype._readString=function(i){for(var t="",s=0;s<i;s++){var e=this._readUint(8);t+=String.fromCharCode(e)}return t};n.prototype._readTemplate=function(i){var t=this._readUint(i/2),s=this._readUint(i/2);return t+s/Math.pow(2,i/2)};n.prototype._readTerminatedString=function(){for(var i="";this._cursor.offset-this._offset<this._raw.byteLength;){var t=this._readUint(8);if(t===0)break;i+=String.fromCharCode(t)}return i};n.prototype._readData=function(i){var t=i>0?i:this._raw.byteLength-(this._cursor.offset-this._offset);if(t>0){var s=new Uint8Array(this._raw.buffer,this._cursor.offset,t);return this._cursor.offset+=t,s}else return null};n.prototype._readUTF8String=function(){var i=this._raw.byteLength-(this._cursor.offset-this._offset),t=null;return i>0&&(t=new DataView(this._raw.buffer,this._cursor.offset,i),this._cursor.offset+=i),t&&m.Utils.dataViewToString(t)};n.prototype._readUTF8TerminatedString=function(){var i=this._raw.byteLength-(this._cursor.offset-this._offset),t=null;if(i>0){t=new DataView(this._raw.buffer,this._cursor.offset,i);var s;for(s=0;s<i&&t.getUint8(s)!==0;s++);t=new DataView(this._raw.buffer,this._cursor.offset,s),this._cursor.offset+=Math.min(s+1,i)}return t&&m.Utils.dataViewToString(t)};n.prototype._parseBox=function(){if(this._parsing=!0,this._cursor.offset=this._offset,this._offset+8>this._raw.buffer.byteLength){this._root._incomplete=!0;return}switch(this._procField("size","uint",32),this._procField("type","string",4),this.size===1&&this._procField("largesize","uint",64),this.type==="uuid"&&this._procFieldArray("usertype",16,"uint",8),this.size){case 0:this._raw=new DataView(this._raw.buffer,this._offset);break;case 1:this._offset+this.size>this._raw.buffer.byteLength?(this._incomplete=!0,this._root._incomplete=!0):this._raw=new DataView(this._raw.buffer,this._offset,this.largesize);break;default:this._offset+this.size>this._raw.buffer.byteLength?(this._incomplete=!0,this._root._incomplete=!0):this._raw=new DataView(this._raw.buffer,this._offset,this.size)}this._incomplete||(this._boxProcessors[this.type]&&this._boxProcessors[this.type].call(this),this._boxContainers.indexOf(this.type)!==-1?this._parseContainerBox():this._data=this._readData())};n.prototype._parseFullBox=function(){this.version=this._readUint(8),this.flags=this._readUint(24)};n.prototype._parseContainerBox=function(){for(this.boxes=[];this._cursor.offset-this._raw.byteOffset<this._raw.byteLength;)this.boxes.push(n.parse(this))};n.prototype.append=function(i,t){m.Utils.appendBox(this,i,t)};n.prototype.getLength=function(){if(this._parsing=!1,this._rawo=null,this.size=0,this._procField("size","uint",32),this._procField("type","string",4),this.size===1&&this._procField("largesize","uint",64),this.type==="uuid"&&this._procFieldArray("usertype",16,"uint",8),this._boxProcessors[this.type]&&this._boxProcessors[this.type].call(this),this._boxContainers.indexOf(this.type)!==-1)for(var i=0;i<this.boxes.length;i++)this.size+=this.boxes[i].getLength();return this._data&&this._writeData(this._data),this.size};n.prototype.write=function(){switch(this._parsing=!1,this._cursor.offset=this._parent._cursor.offset,this.size){case 0:this._rawo=new DataView(this._parent._rawo.buffer,this._cursor.offset,this.parent._rawo.byteLength-this._cursor.offset);break;case 1:this._rawo=new DataView(this._parent._rawo.buffer,this._cursor.offset,this.largesize);break;default:this._rawo=new DataView(this._parent._rawo.buffer,this._cursor.offset,this.size)}if(this._procField("size","uint",32),this._procField("type","string",4),this.size===1&&this._procField("largesize","uint",64),this.type==="uuid"&&this._procFieldArray("usertype",16,"uint",8),this._boxProcessors[this.type]&&this._boxProcessors[this.type].call(this),this._boxContainers.indexOf(this.type)!==-1)for(var i=0;i<this.boxes.length;i++)this.boxes[i].write();return this._data&&this._writeData(this._data),this._parent._cursor.offset+=this.size,this.size};n.prototype._writeInt=function(i,t){if(this._rawo){var s=this._cursor.offset-this._rawo.byteOffset;switch(i){case 8:this._rawo.setInt8(s,t);break;case 16:this._rawo.setInt16(s,t);break;case 32:this._rawo.setInt32(s,t);break;case 64:var e=Math.floor(t/Math.pow(2,32)),_=t-e*Math.pow(2,32);this._rawo.setUint32(s,e),this._rawo.setUint32(s+4,_);break}this._cursor.offset+=i>>3}else this.size+=i>>3};n.prototype._writeUint=function(i,t){if(this._rawo){var s=this._cursor.offset-this._rawo.byteOffset,e,_;switch(i){case 8:this._rawo.setUint8(s,t);break;case 16:this._rawo.setUint16(s,t);break;case 24:e=(t&16776960)>>8,_=t&255,this._rawo.setUint16(s,e),this._rawo.setUint8(s+2,_);break;case 32:this._rawo.setUint32(s,t);break;case 64:e=Math.floor(t/Math.pow(2,32)),_=t-e*Math.pow(2,32),this._rawo.setUint32(s,e),this._rawo.setUint32(s+4,_);break}this._cursor.offset+=i>>3}else this.size+=i>>3};n.prototype._writeString=function(i,t){for(var s=0;s<i;s++)this._writeUint(8,t.charCodeAt(s))};n.prototype._writeTerminatedString=function(i){if(i.length!==0){for(var t=0;t<i.length;t++)this._writeUint(8,i.charCodeAt(t));this._writeUint(8,0)}};n.prototype._writeTemplate=function(i,t){var s=Math.floor(t),e=(t-s)*Math.pow(2,i/2);this._writeUint(i/2,s),this._writeUint(i/2,e)};n.prototype._writeData=function(i){var t;if(i)if(this._rawo){if(i instanceof Array){for(var s=this._cursor.offset-this._rawo.byteOffset,t=0;t<i.length;t++)this._rawo.setInt8(s+t,i[t]);this._cursor.offset+=i.length}i instanceof Uint8Array&&(this._root.bytes.set(i,this._cursor.offset),this._cursor.offset+=i.length)}else this.size+=i.length};n.prototype._writeUTF8String=function(i){var t=m.Utils.utf8ToByteArray(i);if(this._rawo)for(var s=new DataView(this._rawo.buffer,this._cursor.offset,t.length),e=0;e<t.length;e++)s.setUint8(e,t[e]);else this.size+=t.length};n.prototype._writeField=function(i,t,s){switch(i){case"uint":this._writeUint(t,s);break;case"int":this._writeInt(t,s);break;case"template":this._writeTemplate(t,s);break;case"string":t==-1?this._writeTerminatedString(s):this._writeString(t,s);break;case"data":this._writeData(s);break;case"utf8":this._writeUTF8String(s);break;default:break}};n.prototype._boxProcessors.ardi=function(){this._procFullBox(),this._procField("audio_rendering_indication","uint",8)};n.prototype._boxProcessors.avc1=n.prototype._boxProcessors.avc2=n.prototype._boxProcessors.avc3=n.prototype._boxProcessors.avc4=n.prototype._boxProcessors.hvc1=n.prototype._boxProcessors.hev1=n.prototype._boxProcessors.encv=function(){this._procFieldArray("reserved1",6,"uint",8),this._procField("data_reference_index","uint",16),this._procField("pre_defined1","uint",16),this._procField("reserved2","uint",16),this._procFieldArray("pre_defined2",3,"uint",32),this._procField("width","uint",16),this._procField("height","uint",16),this._procField("horizresolution","template",32),this._procField("vertresolution","template",32),this._procField("reserved3","uint",32),this._procField("frame_count","uint",16),this._procFieldArray("compressorname",32,"uint",8),this._procField("depth","uint",16),this._procField("pre_defined3","int",16),this._procField("config","data",-1)};n.prototype._boxProcessors.ctts=function(){this._procFullBox(),this._procField("entry_count","uint",32),this._procEntries("entries",this.entry_count,function(i){this._procEntryField(i,"sample_count","uint",32),this._procEntryField(i,"sample_offset",this.version===1?"int":"uint",32)})};n.prototype._boxProcessors.dref=function(){this._procFullBox(),this._procField("entry_count","uint",32),this._procSubBoxes("entries",this.entry_count)};n.prototype._boxProcessors.elng=function(){this._procFullBox(),this._procField("extended_language","utf8string")};n.prototype._boxProcessors.elst=function(){this._procFullBox(),this._procField("entry_count","uint",32),this._procEntries("entries",this.entry_count,function(i){this._procEntryField(i,"segment_duration","uint",this.version===1?64:32),this._procEntryField(i,"media_time","int",this.version===1?64:32),this._procEntryField(i,"media_rate_integer","int",16),this._procEntryField(i,"media_rate_fraction","int",16)})};n.prototype._boxProcessors.emsg=function(){this._procFullBox(),this.version==1?(this._procField("timescale","uint",32),this._procField("presentation_time","uint",64),this._procField("event_duration","uint",32),this._procField("id","uint",32),this._procField("scheme_id_uri","string",-1),this._procField("value","string",-1)):(this._procField("scheme_id_uri","string",-1),this._procField("value","string",-1),this._procField("timescale","uint",32),this._procField("presentation_time_delta","uint",32),this._procField("event_duration","uint",32),this._procField("id","uint",32)),this._procField("message_data","data",-1)};n.prototype._boxProcessors.free=n.prototype._boxProcessors.skip=function(){this._procField("data","data",-1)};n.prototype._boxProcessors.frma=function(){this._procField("data_format","uint",32)};n.prototype._boxProcessors.ftyp=n.prototype._boxProcessors.styp=function(){this._procField("major_brand","string",4),this._procField("minor_version","uint",32);var i=-1;this._parsing&&(i=(this._raw.byteLength-(this._cursor.offset-this._raw.byteOffset))/4),this._procFieldArray("compatible_brands",i,"string",4)};n.prototype._boxProcessors.hdlr=function(){this._procFullBox(),this._procField("pre_defined","uint",32),this._procField("handler_type","string",4),this._procFieldArray("reserved",3,"uint",32),this._procField("name","string",-1)};n.prototype._boxProcessors.imda=function(){this._procField("imda_identifier","uint",32),this._procField("data","data",-1)};n.prototype._boxProcessors.kind=function(){this._procFullBox(),this._procField("schemeURI","utf8string"),this._procField("value","utf8string")};n.prototype._boxProcessors.labl=function(){this._procFullBox(),this.is_group_label=(this.flags&1)!=0,this._procField("label_id","uint",16),this._procField("language","utf8string"),this._procField("label","utf8string")};n.prototype._boxProcessors.mdat=function(){this._procField("data","data",-1)};n.prototype._boxProcessors.mdhd=function(){this._procFullBox(),this._procField("creation_time","uint",this.version==1?64:32),this._procField("modification_time","uint",this.version==1?64:32),this._procField("timescale","uint",32),this._procField("duration","uint",this.version==1?64:32),!this._parsing&&typeof this.language=="string"&&(this.language=this.language.charCodeAt(0)-96<<10|this.language.charCodeAt(1)-96<<5|this.language.charCodeAt(2)-96),this._procField("language","uint",16),this._parsing&&(this.language=String.fromCharCode((this.language>>10&31)+96,(this.language>>5&31)+96,(this.language&31)+96)),this._procField("pre_defined","uint",16)};n.prototype._boxProcessors.mehd=function(){this._procFullBox(),this._procField("fragment_duration","uint",this.version==1?64:32)};n.prototype._boxProcessors.meta=function(){this._procFullBox()};n.prototype._boxProcessors.mfhd=function(){this._procFullBox(),this._procField("sequence_number","uint",32)};n.prototype._boxProcessors.mfro=function(){this._procFullBox(),this._procField("mfra_size","uint",32)};n.prototype._boxProcessors.mp4a=n.prototype._boxProcessors.enca=function(){this._procFieldArray("reserved1",6,"uint",8),this._procField("data_reference_index","uint",16),this._procFieldArray("reserved2",2,"uint",32),this._procField("channelcount","uint",16),this._procField("samplesize","uint",16),this._procField("pre_defined","uint",16),this._procField("reserved3","uint",16),this._procField("samplerate","template",32),this._procField("esds","data",-1)};n.prototype._boxProcessors.mvhd=function(){this._procFullBox(),this._procField("creation_time","uint",this.version==1?64:32),this._procField("modification_time","uint",this.version==1?64:32),this._procField("timescale","uint",32),this._procField("duration","uint",this.version==1?64:32),this._procField("rate","template",32),this._procField("volume","template",16),this._procField("reserved1","uint",16),this._procFieldArray("reserved2",2,"uint",32),this._procFieldArray("matrix",9,"template",32),this._procFieldArray("pre_defined",6,"uint",32),this._procField("next_track_ID","uint",32)};n.prototype._boxProcessors.payl=function(){this._procField("cue_text","utf8")};n.prototype._boxProcessors.prft=function(){this._procFullBox(),this._procField("reference_track_ID","uint",32),this._procField("ntp_timestamp_sec","uint",32),this._procField("ntp_timestamp_frac","uint",32),this._procField("media_time","uint",this.version==1?64:32)};n.prototype._boxProcessors.prsl=function(){this._procFullBox(),this._procField("group_id","uint",32),this._procField("num_entities_in_group","uint",32),this._procEntries("entities",this.num_entities_in_group,function(i){this._procEntryField(i,"entity_id","uint",32)}),this.flags&4096&&this._procField("preselection_tag","utf8string"),this.flags&8192&&this._procField("selection_priority","uint",8),this.flags&16384&&this._procField("interleaving_tag","utf8string")};n.prototype._boxProcessors.pssh=function(){this._procFullBox(),this._procFieldArray("SystemID",16,"uint",8),this._procField("DataSize","uint",32),this._procFieldArray("Data",this.DataSize,"uint",8)};n.prototype._boxProcessors.schm=function(){this._procFullBox(),this._procField("scheme_type","uint",32),this._procField("scheme_version","uint",32),this.flags&1&&this._procField("scheme_uri","string",-1)};n.prototype._boxProcessors.sdtp=function(){this._procFullBox();var i=-1;this._parsing&&(i=this._raw.byteLength-(this._cursor.offset-this._raw.byteOffset)),this._procFieldArray("sample_dependency_table",i,"uint",8)};n.prototype._boxProcessors.sidx=function(){this._procFullBox(),this._procField("reference_ID","uint",32),this._procField("timescale","uint",32),this._procField("earliest_presentation_time","uint",this.version==1?64:32),this._procField("first_offset","uint",this.version==1?64:32),this._procField("reserved","uint",16),this._procField("reference_count","uint",16),this._procEntries("references",this.reference_count,function(i){this._parsing||(i.reference=(i.reference_type&1)<<31,i.reference|=i.referenced_size&2147483647,i.sap=(i.starts_with_SAP&1)<<31,i.sap|=(i.SAP_type&3)<<28,i.sap|=i.SAP_delta_time&268435455),this._procEntryField(i,"reference","uint",32),this._procEntryField(i,"subsegment_duration","uint",32),this._procEntryField(i,"sap","uint",32),this._parsing&&(i.reference_type=i.reference>>31&1,i.referenced_size=i.reference&2147483647,i.starts_with_SAP=i.sap>>31&1,i.SAP_type=i.sap>>28&7,i.SAP_delta_time=i.sap&268435455)})};n.prototype._boxProcessors.smhd=function(){this._procFullBox(),this._procField("balance","uint",16),this._procField("reserved","uint",16)};n.prototype._boxProcessors.ssix=function(){this._procFullBox(),this._procField("subsegment_count","uint",32),this._procEntries("subsegments",this.subsegment_count,function(i){this._procEntryField(i,"ranges_count","uint",32),this._procSubEntries(i,"ranges",i.ranges_count,function(t){this._procEntryField(t,"level","uint",8),this._procEntryField(t,"range_size","uint",24)})})};n.prototype._boxProcessors.stsd=function(){this._procFullBox(),this._procField("entry_count","uint",32),this._procSubBoxes("entries",this.entry_count)};n.prototype._boxProcessors.sttg=function(){this._procField("settings","utf8")};n.prototype._boxProcessors.stts=function(){this._procFullBox(),this._procField("entry_count","uint",32),this._procEntries("entries",this.entry_count,function(i){this._procEntryField(i,"sample_count","uint",32),this._procEntryField(i,"sample_delta","uint",32)})};n.prototype._boxProcessors.subs=function(){this._procFullBox(),this._procField("entry_count","uint",32),this._procEntries("entries",this.entry_count,function(i){this._procEntryField(i,"sample_delta","uint",32),this._procEntryField(i,"subsample_count","uint",16),this._procSubEntries(i,"subsamples",i.subsample_count,function(t){this._procEntryField(t,"subsample_size","uint",this.version===1?32:16),this._procEntryField(t,"subsample_priority","uint",8),this._procEntryField(t,"discardable","uint",8),this._procEntryField(t,"codec_specific_parameters","uint",32)})})};n.prototype._boxProcessors.tenc=function(){this._procFullBox(),this._procField("default_IsEncrypted","uint",24),this._procField("default_IV_size","uint",8),this._procFieldArray("default_KID",16,"uint",8)};n.prototype._boxProcessors.tfdt=function(){this._procFullBox(),this._procField("baseMediaDecodeTime","uint",this.version==1?64:32)};n.prototype._boxProcessors.tfhd=function(){this._procFullBox(),this._procField("track_ID","uint",32),this.flags&1&&this._procField("base_data_offset","uint",64),this.flags&2&&this._procField("sample_description_offset","uint",32),this.flags&8&&this._procField("default_sample_duration","uint",32),this.flags&16&&this._procField("default_sample_size","uint",32),this.flags&32&&this._procField("default_sample_flags","uint",32)};n.prototype._boxProcessors.tfra=function(){this._procFullBox(),this._procField("track_ID","uint",32),this._parsing||(this.reserved=0,this.reserved|=(this.length_size_of_traf_num&48)<<4,this.reserved|=(this.length_size_of_trun_num&12)<<2,this.reserved|=this.length_size_of_sample_num&3),this._procField("reserved","uint",32),this._parsing&&(this.length_size_of_traf_num=(this.reserved&48)>>4,this.length_size_of_trun_num=(this.reserved&12)>>2,this.length_size_of_sample_num=this.reserved&3),this._procField("number_of_entry","uint",32),this._procEntries("entries",this.number_of_entry,function(i){this._procEntryField(i,"time","uint",this.version===1?64:32),this._procEntryField(i,"moof_offset","uint",this.version===1?64:32),this._procEntryField(i,"traf_number","uint",(this.length_size_of_traf_num+1)*8),this._procEntryField(i,"trun_number","uint",(this.length_size_of_trun_num+1)*8),this._procEntryField(i,"sample_number","uint",(this.length_size_of_sample_num+1)*8)})};n.prototype._boxProcessors.tkhd=function(){this._procFullBox(),this._procField("creation_time","uint",this.version==1?64:32),this._procField("modification_time","uint",this.version==1?64:32),this._procField("track_ID","uint",32),this._procField("reserved1","uint",32),this._procField("duration","uint",this.version==1?64:32),this._procFieldArray("reserved2",2,"uint",32),this._procField("layer","uint",16),this._procField("alternate_group","uint",16),this._procField("volume","template",16),this._procField("reserved3","uint",16),this._procFieldArray("matrix",9,"template",32),this._procField("width","template",32),this._procField("height","template",32)};n.prototype._boxProcessors.trex=function(){this._procFullBox(),this._procField("track_ID","uint",32),this._procField("default_sample_description_index","uint",32),this._procField("default_sample_duration","uint",32),this._procField("default_sample_size","uint",32),this._procField("default_sample_flags","uint",32)};n.prototype._boxProcessors.trun=function(){this._procFullBox(),this._procField("sample_count","uint",32),this.flags&1&&this._procField("data_offset","int",32),this.flags&4&&this._procField("first_sample_flags","uint",32),this._procEntries("samples",this.sample_count,function(i){this.flags&256&&this._procEntryField(i,"sample_duration","uint",32),this.flags&512&&this._procEntryField(i,"sample_size","uint",32),this.flags&1024&&this._procEntryField(i,"sample_flags","uint",32),this.flags&2048&&this._procEntryField(i,"sample_composition_time_offset",this.version===1?"int":"uint",32)})};n.prototype._boxProcessors["url "]=n.prototype._boxProcessors["urn "]=function(){this._procFullBox(),this.type==="urn "&&this._procField("name","string",-1),this._procField("location","string",-1)};n.prototype._boxProcessors.vlab=function(){this._procField("source_label","utf8")};n.prototype._boxProcessors.vmhd=function(){this._procFullBox(),this._procField("graphicsmode","uint",16),this._procFieldArray("opcolor",3,"uint",16)};n.prototype._boxProcessors.vttC=function(){this._procField("config","utf8")};n.prototype._boxProcessors.vtte=function(){}});var R="moov",nt="trak",at="tkhd",j="meta",ht="grpl",lt="prsl",ft="udta",ct="diap",ut="elng",pt="ardi",dt="labl",bt="kind",z="moof",gt="traf",At="tfhd",mt="trun";var it="b_presentation_id",st="presentation_id",et="presentation_level",G="payload_base_minus1",T="byte_alignment",Y="ac4_toc_end";var Mt=(i,t,s,e)=>{let _=t>>3,r=t+s-1>>3,h=t&7,f=t+s-1&7,c=255>>h,p=255<<7-f&255,l=0;for(let d=r;d>=_;d--){let u=i.getUint8(d),o=255;d===_&&(o&=c),d===r&&(o&=p);let g=u&~o;l=((u&o)<<e)+l;let B=g|l&255&o;l>>=8,i.setUint8(d,B)}return i},V=(i,t,s,e)=>{let _=t>>>3,r=t&7,h=(1<<s)-1<<16-s>>r,f=i.getUint8(_)<<8|i.getUint8(_+1);f&=~h,f|=e<<16-s-r,i.setUint8(_,f>>>8),i.setUint8(_+1,f&255)};var vt=i=>{let t=[],e=i.fetch(z),_=!0;for(let r of i.fetchAll(gt)){let h=r.boxes.find(l=>l.type===At),f=h.base_data_offset||0,c=h.flags&131072;if(f)throw Error("base_data_offset is relative to the file identified by the referenced data reference entry unsupported");if(!c)throw Error(_?"base_data_offset is relative to the first byte of the MovieFragmentBox containing this box unsupported":"base_data_offset is relative to the end of the data defined by the preceding track fragment is unsupported");let p=e._offset;for(let l of r.boxes.filter(d=>d.type===mt)){let d=p+f+l.data_offset;for(let u of l.samples)t.push({offset:d,size:u.sample_size}),d+=u.sample_size}_=!1}return t};var J=class{constructor(t){this.iterator=t,this.cache=0,this.bitsLeft=0}get(t,s){s>25;let f=s;for(;this.bitsLeft<f;){let p=this.iterator.next(),l=24-this.bitsLeft;this.cache|=p.value<<l,this.bitsLeft+=8,f>25&&(this.cache<<=8,this.bitsLeft-=8,f-=8)}let c=this.cache>>>32-f;return this.cache<<=f,this.bitsLeft-=f,c}get_align(t){return this.get("align",t)}};var X=class{constructor(t,s){this.elements=t,this.callback=s}before_call(t,s,e,_){this.elements.includes(e)&&this.callback(e,null,null,_,"before_call")}after_call(t,s,e,_){this.elements.includes(e)&&this.callback(e,s,null,_,"after_call")}write_uint(t,s,e,_){this.elements.includes(t)&&this.callback(t,e,s,_)}write_align(t,s){this.elements.includes(T)&&this.callback(T,s,t,null,"write_align")}after_position(t,s){this.elements.includes(t)&&this.callback(t,null,null,s,"after_position")}};var b=class extends Error{},K=class{constructor(t,s){a(this,"v",null);a(this,"content_classifier",null);a(this,"i",null);a(this,"frame_rate_factor",null);a(this,"bk_substream_index",null);a(this,"a_substream_indices",null);a(this,"last_referenced_substream",null);a(this,"referenced_substreams",null);a(this,"protection_bits_primary_bits",null);a(this,"protection_bits_secondary_bits",null);a(this,"toc_i",null);a(this,"OAMD_OBJECT_TYPE_BED",null);a(this,"OAMD_OBJECT_TYPE_ISF",null);a(this,"OAMD_OBJECT_TYPE_DYNAMIC",null);a(this,"OAMD_OBJECT_TYPE_RESERVED",null);a(this,"toc_j",null);a(this,"vb",null);a(this,"presentation_to_groups",null);a(this,"group_frame_rate_factor",null);a(this,"b_hsf_ext",null);a(this,"b_single_substream",null);a(this,"n_bed_objects",null);a(this,"a_num_bed_objects",null);a(this,"b_bed_objects_prev",null);a(this,"num_lfe",null);a(this,"n",null);a(this,"n_skip_bytes",null);a(this,"b_more_skip_bytes",null);a(this,"n_bits_read_0",null);a(this,"n_bits_read_1",null);a(this,"n_bits_read",null);a(this,"n_skip_bits",null);a(this,"reserved",null);a(this,"padding",null);a(this,"CHANNEL_MODE_MONO",null);a(this,"CHANNEL_MODE_STEREO",null);a(this,"CHANNEL_MODE_30",null);a(this,"CHANNEL_MODE_50",null);a(this,"CHANNEL_MODE_51",null);a(this,"CHANNEL_MODE_70_34",null);a(this,"CHANNEL_MODE_71_34",null);a(this,"CHANNEL_MODE_70_52",null);a(this,"CHANNEL_MODE_71_52",null);a(this,"CHANNEL_MODE_70_322",null);a(this,"CHANNEL_MODE_71_322",null);a(this,"CHANNEL_MODE_704",null);a(this,"CHANNEL_MODE_714",null);a(this,"CHANNEL_MODE_904",null);a(this,"CHANNEL_MODE_914",null);a(this,"CHANNEL_MODE_222",null);a(this,"presentation_config",null);a(this,"presentation_version",null);a(this,"b_add_emdf_substreams",null);a(this,"presentation_level",null);a(this,"b_presentation_id",null);a(this,"presentation_id",null);a(this,"b_pre_virtualized",null);a(this,"n_add_emdf_substreams",null);a(this,"pi_i",null);a(this,"b_single_substream_group",null);a(this,"b_presentation_filter",null);a(this,"b_enable_presentation",null);a(this,"n_substream_groups",null);a(this,"b_multi_pid",null);a(this,"n_substream_groups_minus2",null);a(this,"sg",null);a(this,"bitstream_version",null);a(this,"fs_index",null);a(this,"frame_rate_index",null);a(this,"BAM_g_position",0);a(this,"BAM_g_table0",[0,2,4,6]);a(this,"BAM_g_table1",[252,253,508,509]);a(this,"BAM_g_table2",[122,123,124,125]);a(this,"BAM_g_table3",[252,253,508,509]);a(this,"BAM_g_table4",[4,6,8,10,12,14]);a(this,"BAM_g_table5",[122,123,124,125]);a(this,"BAM_g_table6",[0,0]);a(this,"BAM_g_table7",[0,1,2,3,5,0,0,0]);a(this,"BAM_g_table8",[2,3,6,8,10,8,10,12]);a(this,"BAM_g_table9",[2,1,1,2,2,2,2,2,2,1]);a(this,"BAM_g_table10",[4,8,10,14,15,30,-1,-1]);a(this,"BAM_g_table11",[2,3,4,5,6,7]);a(this,"BAM_g_table12",[2,1,1,2,2,2,2,2,2,1]);a(this,"BAM_g_table13",[1920,1920,2048,1536,1536,960,960,1024,768,768,512,384,384,2048]);a(this,"BAM_g_table14",[2,3,4]);a(this,"BAM_g_table15",{0:2,1:4});a(this,"BAM_g_table16",[0,1,7,8,9]);a(this,"BAM_g_table17",{0:1,1:2});a(this,"BAM_g_table18",[5,6,7,8,9]);a(this,"BAM_g_table19",[10,11,12]);this.BAM_source=t,this.BAM_sink=s}F_channel_mode_contains_LFE(t){return t==this.CHANNEL_MODE_51||t==this.CHANNEL_MODE_71_34||t==this.CHANNEL_MODE_71_52||t==this.CHANNEL_MODE_71_322?1:0}F_bitrate_indicator(){var t,s;t=this.BAM_source.get("",3),this.BAM_g_position+=3,this.BAM_g_table0.slice(0).indexOf(t)>=0?t=t>>1:(this.v=this.BAM_source.get("",2),this.BAM_g_position+=2,this.v=(t<<2)+this.v,s=Math.floor(this.v/8),t=this.v-s*4)}F_content_type(){var t,s,e,_,r,h;if(this.content_classifier=this.BAM_source.get("",3),this.BAM_g_position+=3,r=this.BAM_source.get("",1),this.BAM_g_position+=1,r)if(t=this.BAM_source.get("",1),this.BAM_g_position+=1,t)h=this.BAM_source.get("",1),this.BAM_g_position+=1,e=this.BAM_source.get("",16),this.BAM_g_position+=16;else for(s=this.BAM_source.get("",6),this.BAM_g_position+=6,this.i=0;this.i<s;this.i++)_=this.BAM_source.get("",8),this.BAM_g_position+=8}F_ac4_substream_info_chan(t,s,e){var _,r,h,f,c,p,l,d,u,o=null,o,g,A;{if(this.F_define_channel_modes(),this.F_define_oamd(),c=this.F_channel_mode(),c==null)throw b("F_channel_mode","expected to return a value, returned None");if(c==511){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");c+=this.v}for(this.BAM_g_table1.slice(0).indexOf(c)>=0&&(l=this.BAM_source.get("",1),this.BAM_g_position+=1,u=this.BAM_source.get("",1),this.BAM_g_position+=1,p=this.BAM_source.get("",2),this.BAM_g_position+=2),this.fs_index==1&&(r=this.BAM_source.get("",1),this.BAM_g_position+=1,r&&(g=this.BAM_source.get("",1),this.BAM_g_position+=1)),h=this.BAM_source.get("",1),this.BAM_g_position+=1,h&&this.F_bitrate_indicator(),this.BAM_g_table2.slice(0).indexOf(c)>=0&&(A=this.BAM_source.get("",1),this.BAM_g_position+=1),this.frame_rate_factor=this.group_frame_rate_factor[t],this.i=0;this.i<this.frame_rate_factor;this.i++)d=this.BAM_source.get("",1),this.BAM_g_position+=1;if(e==1){if(_=this.BAM_source.get("",2),this.BAM_g_position+=2,_==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");_+=this.v}}else _=this.bk_substream_index,this.bk_substream_index=this.bk_substream_index+1;for(this.a_substream_indices.push(_),this.i=0;this.i<this.frame_rate_factor;this.i++){if(e==1&&(this.last_referenced_substream=Math.max(this.last_referenced_substream,_+this.i),this.referenced_substreams.push(_+this.i)),this.BAM_g_table3.slice(0).indexOf(c)>=0,f=this.F_get_ch_mode(c),f==null)throw b("F_get_ch_mode","expected to return a value, returned None");this.BAM_g_table4.slice(0).indexOf(f)>=0?(o==null?o=new Array(_+this.i+1).fill(0):o.length<=_+this.i&&o.push.apply(o,new Array(_+this.i-o.length+1).fill(0)),o[_+this.i]=1):(o==null?o=new Array(_+this.i+1).fill(0):o.length<=_+this.i&&o.push.apply(o,new Array(_+this.i-o.length+1).fill(0)),o[_+this.i]=0)}}}F_channel_mode(){var t,s;return t=this.BAM_source.get("",1),this.BAM_g_position+=1,t==1&&(this.v=this.BAM_source.get("",1),this.BAM_g_position+=1,t=(t<<1)+this.v,s=2,t==3&&(this.v=this.BAM_source.get("",2),this.BAM_g_position+=2,t=(t<<2)+this.v,t==15&&(this.v=this.BAM_source.get("",3),this.BAM_g_position+=3,t=(t<<3)+this.v,(t==120||t==121)&&(s=t,t=2),t==126&&(this.v=this.BAM_source.get("",1),this.BAM_g_position+=1,t=(t<<1)+this.v),t==127&&(this.v=this.BAM_source.get("",2),this.BAM_g_position+=2,t=(t<<2)+this.v)))),t}F_ac4_substream_info(t,s,e){var _,r,h,f,c,p,l=null,l,d,u,o,g;{if(this.F_define_channel_modes(),p=this.F_channel_mode(),p==null)throw b("F_channel_mode","expected to return a value, returned None");if(p==511){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");p+=this.v}for(this.fs_index==1&&(h=this.BAM_source.get("",1),this.BAM_g_position+=1,h&&(d=this.BAM_source.get("",1),this.BAM_g_position+=1)),f=this.BAM_source.get("",1),this.BAM_g_position+=1,f&&this.F_bitrate_indicator(),this.BAM_g_table5.slice(0).indexOf(p)>=0&&(u=this.BAM_source.get("",1),this.BAM_g_position+=1),g=this.BAM_source.get("",1),this.BAM_g_position+=1,g?(this.F_content_type(),this.content_classifier==0||this.content_classifier==1?(o=0,c=0):this.content_classifier==2||this.content_classifier==3?(o=1,c=0):this.content_classifier==4?(o=0,c=1):this.content_classifier==5?(o=1,c=0):(this.content_classifier==6||this.content_classifier==7)&&(o=0,c=0)):(o=0,c=0),this.i=0;this.i<this.frame_rate_factor;this.i++)r=this.BAM_source.get("",1),this.BAM_g_position+=1;if(_=this.BAM_source.get("",2),this.BAM_g_position+=2,_==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");_+=this.v}for(this.a_substream_indices.push(_),this.i=0;this.i<this.frame_rate_factor;this.i++)if(this.last_referenced_substream=Math.max(this.last_referenced_substream,_+this.i),this.referenced_substreams.push(_+this.i),l==null?l=new Array(_+1+1).fill(0):l.length<=_+1&&l.push.apply(l,new Array(_+1-l.length+1).fill(0)),l[_+1]=this.F_channel_mode_contains_LFE(p),l[_+1]==null)throw b("F_channel_mode_contains_LFE","expected to return a value, returned None")}}F_emdf_protection(){var t,s,e,_;{if(e=this.BAM_source.get("",2),this.BAM_g_position+=2,s=this.BAM_source.get("",2),this.BAM_g_position+=2,e==0)throw"protection_length_primary == 0 is reserved";e==1?this.protection_bits_primary_bits=8:e==2?this.protection_bits_primary_bits=32:e==3&&(this.protection_bits_primary_bits=128),_=this.BAM_source.get("",this.protection_bits_primary_bits),this.BAM_g_position+=this.protection_bits_primary_bits,s==0?this.protection_bits_secondary_bits=0:s==1?this.protection_bits_secondary_bits=8:s==2?this.protection_bits_secondary_bits=32:s==3&&(this.protection_bits_secondary_bits=128),t=this.BAM_source.get("",this.protection_bits_secondary_bits),this.BAM_g_position+=this.protection_bits_secondary_bits}}F_emdf_info(){var t,s,e;{if(e=this.BAM_source.get("",2),this.BAM_g_position+=2,e==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");e+=this.v}if(t=this.BAM_source.get("",3),this.BAM_g_position+=3,t==7){if(this.v=this.F_variable_bits(3),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");t+=this.v}s=this.BAM_source.get("",1),this.BAM_g_position+=1,s&&this.F_emdf_payloads_substream_info(this.toc_i),this.F_emdf_protection()}}F_emdf_payloads_substream_info(t){var s;{if(s=this.BAM_source.get("",2),this.BAM_g_position+=2,s==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");s+=this.v}this.last_referenced_substream=Math.max(this.last_referenced_substream,s),this.referenced_substreams.push(s),this.a_substream_indices.push(s)}}F_ac4_hsf_ext_substream_info(t){var s;{if(t==1){if(s=this.BAM_source.get("",2),this.BAM_g_position+=2,s==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");s+=this.v}}else s=this.bk_substream_index,this.bk_substream_index=this.bk_substream_index+1;t==1&&(this.last_referenced_substream=Math.max(this.last_referenced_substream,s),this.referenced_substreams.push(s))}}F_oamd_common_data(){var t,s,e,_,r,h,f,c,p,l,d;if(d=this.BAM_source.get("",1),this.BAM_g_position+=1,d==0&&(f=this.BAM_source.get("",5),this.BAM_g_position+=5),h=this.BAM_source.get("",1),this.BAM_g_position+=1,l=this.BAM_source.get("",1),this.BAM_g_position+=1,l){if(c=this.BAM_source.get("",1),this.BAM_g_position+=1,p=c+1,p==2){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");p+=this.v}if(t=p*8,_=this.BAM_g_position,s=this.BAM_g_position,r=s-_,t=t-r,t<0)throw"Wrong add_data_bytes_minus1 size indication";e=this.BAM_source.get("",t),this.BAM_g_position+=t}}F_define_oamd(){var t;this.OAMD_OBJECT_TYPE_BED=0,this.OAMD_OBJECT_TYPE_ISF=1,this.OAMD_OBJECT_TYPE_DYNAMIC=2,this.OAMD_OBJECT_TYPE_RESERVED=3,t=9}F_ac4_substream_info_ajoc(t,s,e){var _,r,h,f,c,p,l,d,u=null,u,o,g,A=null,A,B,F,v;{if(u=this.BAM_g_table6.slice(0),this.F_define_channel_modes(),o=this.BAM_source.get("",1),this.BAM_g_position+=1,F=this.BAM_source.get("",1),this.BAM_g_position+=1,F?(p=5,o?B=this.CHANNEL_MODE_51:B=this.CHANNEL_MODE_50):(g=this.BAM_source.get("",4),this.BAM_g_position+=4,p=g+1,this.F_bed_dyn_obj_assignment(p,0,o)),h=this.BAM_source.get("",1),this.BAM_g_position+=1,h&&this.F_oamd_common_data(),_=this.BAM_source.get("",4),this.BAM_g_position+=4,l=_+1,l==16){if(this.v=this.F_variable_bits(3),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");l=l+this.v}for(this.F_bed_dyn_obj_assignment(l,1,o),this.fs_index==1&&(f=this.BAM_source.get("",1),this.BAM_g_position+=1,f&&(v=this.BAM_source.get("",1),this.BAM_g_position+=1)),c=this.BAM_source.get("",1),this.BAM_g_position+=1,c&&this.F_bitrate_indicator(),this.frame_rate_factor=this.group_frame_rate_factor[t],this.i=0;this.i<this.frame_rate_factor;this.i++)d=this.BAM_source.get("",1),this.BAM_g_position+=1;if(e==1){if(r=this.BAM_source.get("",2),this.BAM_g_position+=2,r==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");r+=this.v}}else r=this.bk_substream_index,this.bk_substream_index=this.bk_substream_index+1;for(this.a_substream_indices.push(r),this.i=0;this.i<this.frame_rate_factor;this.i++)e==1&&(this.last_referenced_substream=Math.max(this.last_referenced_substream,r+this.i),this.referenced_substreams.push(r+this.i)),A==null?A=new Array(r+this.i+1).fill(0):A.length<=r+this.i&&A.push.apply(A,new Array(r+this.i-A.length+1).fill(0)),A[r+this.i]=o}}F_ac4_sgi_specifier(t,s,e){var _;if(this.bitstream_version==1)this.F_ac4_substream_group_info(this.toc_j),this.toc_j+=1;else{if(_=this.BAM_source.get("",3),this.BAM_g_position+=3,_==7){if(this.vb=this.F_variable_bits(2),this.vb==null)throw b("F_variable_bits","expected to return a value, returned None");_+=this.vb}this.presentation_to_groups==null?this.presentation_to_groups=new Array(this.toc_i+1).fill(null):this.presentation_to_groups.length<=this.toc_i&&this.presentation_to_groups.push.apply(this.presentation_to_groups,new Array(this.toc_i-this.presentation_to_groups.length+1).fill(null)),this.presentation_to_groups[this.toc_i].push(_),this.group_frame_rate_factor==null?this.group_frame_rate_factor=new Array(_+1).fill(0):this.group_frame_rate_factor.length<=_&&this.group_frame_rate_factor.push.apply(this.group_frame_rate_factor,new Array(_-this.group_frame_rate_factor.length+1).fill(0)),this.group_frame_rate_factor[_]=this.frame_rate_factor}}F_ac4_substream_group_info(t){var s,e,_,r,h,f,c,p,l,d,u,o;{if(h=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_hsf_ext=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_single_substream=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_single_substream)r=1;else if(p=this.BAM_source.get("",2),this.BAM_g_position+=2,r=p+2,r==5){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");r+=this.v}if(f=this.BAM_source.get("",1),this.BAM_g_position+=1,this.n_bed_objects=-1,this.a_num_bed_objects=[],f)for(c=0,_=0;_<r;_++)this.bitstream_version==1?(l=this.BAM_source.get("",1),this.BAM_g_position+=1):l=1,this.F_ac4_substream_info_chan(t,_,h),this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(h);else for(d=this.BAM_source.get("",1),this.BAM_g_position+=1,d&&this.F_oamd_substream_info(h),s=0,this.b_bed_objects_prev=0,_=0;_<r;_++)c=this.BAM_source.get("",1),this.BAM_g_position+=1,c?(this.F_ac4_substream_info_ajoc(t,_,h),this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(h)):(this.F_ac4_substream_info_obj(t,_,s,h),s+=1,this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(h));u=this.BAM_source.get("",1),this.BAM_g_position+=1,u?(this.F_content_type(),this.content_classifier==0||this.content_classifier==1?(o=0,e=0):this.content_classifier==2||this.content_classifier==3?(o=1,e=0):this.content_classifier==4?(o=0,e=1):this.content_classifier==5?(o=1,e=0):(this.content_classifier==6||this.content_classifier==7)&&(o=0,e=0)):(o=0,e=0)}}F_oamd_substream_info(t){var s,e;{if(this.F_define_oamd(),e=this.BAM_source.get("",1),this.BAM_g_position+=1,t==1){if(s=this.BAM_source.get("",2),this.BAM_g_position+=2,s==3){if(this.vb=this.F_variable_bits(2),this.vb==null)throw b("F_variable_bits","expected to return a value, returned None");s+=this.vb}}else s=this.bk_substream_index,this.bk_substream_index=this.bk_substream_index+1;t==1&&(this.last_referenced_substream=Math.max(this.last_referenced_substream,s),this.referenced_substreams.push(s))}}F_ac4_substream_info_obj(t,s,e,_){var r,h,f,c,p,l,d,u,o,g,A,B,F,v,O,L,y,S,W,k,Z,N=null,N,M,wt,C;{if(u=0,this.F_define_oamd(),this.F_define_channel_modes(),B=this.BAM_source.get("",3),this.BAM_g_position+=3,o=this.BAM_g_table7.slice(0)[B],y=this.BAM_source.get("",1),this.BAM_g_position+=1,y)C=this.BAM_source.get("",1),this.BAM_g_position+=1,r=this.OAMD_OBJECT_TYPE_DYNAMIC,this.b_bed_objects_prev=0;else if(L=this.BAM_source.get("",1),this.BAM_g_position+=1,L){if(this.b_bed_objects_prev&&this.num_lfe==2?C=1:C=0,this.b_bed_objects_prev=1,this.num_lfe=0,r=this.OAMD_OBJECT_TYPE_BED,c=this.BAM_source.get("",1),this.BAM_g_position+=1,c){if(Z=this.BAM_source.get("",1),this.BAM_g_position+=1,Z){for(p=this.BAM_source.get("",3),this.BAM_g_position+=3,this.i=0;this.i<this.BAM_g_table8.slice(0)[p];this.i++)u+=1;p>=2&&(C=1)}else{if(h=this.BAM_source.get("",1),this.BAM_g_position+=1,h)for(k=this.BAM_source.get("",17),this.BAM_g_position+=17,this.i=0;this.i<17;this.i++)k&1<<this.i&&((this.i==3||this.i==16)&&(this.num_lfe+=1),u+=1);else for(M=this.BAM_source.get("",10),this.BAM_g_position+=10,this.i=0;this.i<10;this.i++)if(M&1<<this.i)for(l=0;l<this.BAM_g_table9.slice(0)[this.i];l++)(this.i==2||this.i==9)&&(this.num_lfe+=1),u+=1;this.num_lfe>0&&(C=1)}this.n_bed_objects=u,this.a_num_bed_objects.push(this.n_bed_objects)}}else if(C=0,this.b_bed_objects_prev=0,W=this.BAM_source.get("",1),this.BAM_g_position+=1,W)r=this.OAMD_OBJECT_TYPE_ISF,A=this.BAM_source.get("",1),this.BAM_g_position+=1,A&&(F=this.BAM_source.get("",3),this.BAM_g_position+=3);else if(f=this.BAM_source.get("",4),this.BAM_g_position+=4,g=this.BAM_source.get("",8*f),this.BAM_g_position+=8*f,r=this.OAMD_OBJECT_TYPE_RESERVED,o==0)throw"No non-LFE objects (of OAMD_OBJECT_TYPE_RESERVED) in substream!";for(this.fs_index==1&&(O=this.BAM_source.get("",1),this.BAM_g_position+=1,O&&(wt=this.BAM_source.get("",1),this.BAM_g_position+=1)),S=this.BAM_source.get("",1),this.BAM_g_position+=1,S&&this.F_bitrate_indicator(),this.frame_rate_factor=this.group_frame_rate_factor[t],this.i=0;this.i<this.frame_rate_factor;this.i++)d=this.BAM_source.get("",1),this.BAM_g_position+=1;if(_==1){if(v=this.BAM_source.get("",2),this.BAM_g_position+=2,v==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");v+=this.v}}else v=this.bk_substream_index,this.bk_substream_index=this.bk_substream_index+1;for(this.a_substream_indices.push(v),this.i=0;this.i<this.frame_rate_factor;this.i++)_==1&&(this.last_referenced_substream=Math.max(this.last_referenced_substream,v+this.i),this.referenced_substreams.push(v+this.i)),N==null?N=new Array(v+this.i+1).fill(0):N.length<=v+this.i&&N.push.apply(N,new Array(v+this.i-N.length+1).fill(0)),N[v+this.i]=C}}F_bed_dyn_obj_assignment(t,s,e){var _,r,h,f,c,p,l,d,u,o,g,A,B,F,v,O,L,y;if(this.F_define_oamd(),o=0,O=this.BAM_source.get("",1),this.BAM_g_position+=1,O==0)if(g=this.BAM_source.get("",1),this.BAM_g_position+=1,g)r=this.BAM_source.get("",3),this.BAM_g_position+=3,f=this.OAMD_OBJECT_TYPE_ISF,_=this.BAM_g_table10.slice(0)[r];else if(f=this.OAMD_OBJECT_TYPE_BED,F=this.BAM_source.get("",1),this.BAM_g_position+=1,F)d=this.BAM_source.get("",3),this.BAM_g_position+=3,this.BAM_g_table11.slice(0).indexOf(d)>=0&&(o=1);else if(L=this.BAM_source.get("",1),this.BAM_g_position+=1,L)if(p=this.BAM_source.get("",1),this.BAM_g_position+=1,p)for(u=this.BAM_source.get("",17),this.BAM_g_position+=17,this.i=0;this.i<17;this.i++)u>>this.i&1&&(this.i==3||this.i==16)&&(o=1);else for(v=this.BAM_source.get("",10),this.BAM_g_position+=10,this.i=0;this.i<10;this.i++)v>>this.i&1&&((this.i==2||this.i==9)&&(o=1),h=this.BAM_g_table12.slice(0)[this.i]);else for(t>1?(B=Math.ceil(Math.log(t)/Math.log(2)),c=this.BAM_source.get("",B),this.BAM_g_position+=B,A=c+1):A=1,y=0;y<A;y++)l=this.BAM_source.get("",4),this.BAM_g_position+=4,(A==3||A==16)&&(o=1)}F_ac4_presentation_substream_info(t){var s,e=null,e,_,r;{if(_=this.BAM_source.get("",1),this.BAM_g_position+=1,r=this.BAM_source.get("",1),this.BAM_g_position+=1,s=this.BAM_source.get("",2),this.BAM_g_position+=2,s==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");s+=this.v}e==null?e=new Array(s+1).fill(0):e.length<=s&&e.push.apply(e,new Array(s-e.length+1).fill(0)),e[s]=0,this.last_referenced_substream=Math.max(this.last_referenced_substream,s),this.referenced_substreams.push(s)}}F_presentation_version(){var t,s;{for(t=0,s=this.BAM_source.get("",1),this.BAM_g_position+=1;s;)t=t+1,s=this.BAM_source.get("",1),this.BAM_g_position+=1;return t}}F_get_ch_mode(t){{if(t==this.CHANNEL_MODE_MONO)this.n=0;else if(t==this.CHANNEL_MODE_STEREO)this.n=1;else if(t==this.CHANNEL_MODE_30)this.n=2;else if(t==this.CHANNEL_MODE_50)this.n=3;else if(t==this.CHANNEL_MODE_51)this.n=4;else if(t==this.CHANNEL_MODE_70_34)this.n=5;else if(t==this.CHANNEL_MODE_71_34)this.n=6;else if(t==this.CHANNEL_MODE_70_52)this.n=7;else if(t==this.CHANNEL_MODE_71_52)this.n=8;else if(t==this.CHANNEL_MODE_70_322)this.n=9;else if(t==this.CHANNEL_MODE_71_322)this.n=10;else if(t==this.CHANNEL_MODE_704)this.n=11;else if(t==this.CHANNEL_MODE_714)this.n=12;else if(t==this.CHANNEL_MODE_904)this.n=13;else if(t==this.CHANNEL_MODE_914)this.n=14;else throw"Unknown channel mode!";return this.n}}F_presentation_config_ext_info(){{if(this.n_skip_bytes=this.BAM_source.get("",5),this.BAM_g_position+=5,this.b_more_skip_bytes=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_more_skip_bytes){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");this.n_skip_bytes+=this.v<<5}if(this.bitstream_version>=1&&this.presentation_config==8)this.n_bits_read_0=this.BAM_g_position,this.n_bits_read_1=this.BAM_g_position,this.padding=this.BAM_source.get("",this.n_skip_bytes*8-(this.n_bits_read_1-this.n_bits_read_0)),this.BAM_g_position+=this.n_skip_bytes*8-(this.n_bits_read_1-this.n_bits_read_0);else for(this.i=0;this.i<this.n_skip_bytes;this.i++)this.reserved=this.BAM_source.get("",8),this.BAM_g_position+=8}}F_define_channel_modes(){var t=null,t,s=null,s,e=null,e,_=null,_,r=null,r;this.CHANNEL_MODE_MONO=0,this.CHANNEL_MODE_STEREO=2,this.CHANNEL_MODE_30=12,this.CHANNEL_MODE_50=13,this.CHANNEL_MODE_51=14,this.CHANNEL_MODE_70_34=120,this.CHANNEL_MODE_71_34=121,this.CHANNEL_MODE_70_52=122,this.CHANNEL_MODE_71_52=123,this.CHANNEL_MODE_70_322=124,this.CHANNEL_MODE_71_322=125,this.CHANNEL_MODE_704=252,this.CHANNEL_MODE_714=253,this.CHANNEL_MODE_904=508,this.CHANNEL_MODE_914=509,this.CHANNEL_MODE_222=510,r=[this.CHANNEL_MODE_50,this.CHANNEL_MODE_51],t=[this.CHANNEL_MODE_70_34,this.CHANNEL_MODE_71_34],_=[this.CHANNEL_MODE_70_52,this.CHANNEL_MODE_71_52],s=[this.CHANNEL_MODE_70_322,this.CHANNEL_MODE_71_322],e=t+_+s}F_channel_mode_to_ch_mode(t){{if(t==this.CHANNEL_MODE_MONO)return 0;if(t==this.CHANNEL_MODE_STEREO)return 1;if(t==this.CHANNEL_MODE_30)return 2;if(t==this.CHANNEL_MODE_50)return 3;if(t==this.CHANNEL_MODE_51)return 4;if(t==this.CHANNEL_MODE_70_34)return 5;if(t==this.CHANNEL_MODE_71_34)return 6;if(t==this.CHANNEL_MODE_70_52)return 7;if(t==this.CHANNEL_MODE_71_52)return 8;if(t==this.CHANNEL_MODE_70_322)return 9;if(t==this.CHANNEL_MODE_71_322)return 10;if(t==this.CHANNEL_MODE_704)return 11;if(t==this.CHANNEL_MODE_714)return 12;if(t==this.CHANNEL_MODE_904)return 13;if(t==this.CHANNEL_MODE_914)return 14;if(t==this.CHANNEL_MODE_222)return 15;throw"Cannot convert extended channel mode to ch_mode!"}}F_variable_bits(t){var s,e,_;{for(e=0,_=1;_;)s=this.BAM_source.get("",t),this.BAM_g_position+=t,e+=s,_=this.BAM_source.get("",1),this.BAM_g_position+=1,_&&(e<<=t,e+=1<<t);return e}}F_raw_ac4_frame_toc_only(){var t,s,e;s=this.BAM_g_position,this.F_ac4_toc(),t=this.BAM_g_position,this.BAM_sink.after_position("ac4_toc_end",t),e=this.BAM_g_table13.slice(0)[this.frame_rate_index]}F_ac4_presentation_info(){{if(this.b_single_substream=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_single_substream!=1&&(this.presentation_config=this.BAM_source.get("",3),this.BAM_g_position+=3,this.presentation_config==7)){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");this.presentation_config+=this.v}if(this.presentation_version=this.F_presentation_version(),this.presentation_version==null)throw b("F_presentation_version","expected to return a value, returned None");if(this.b_single_substream!=1&&this.presentation_config==6)this.b_add_emdf_substreams=1;else{if(this.presentation_level=this.BAM_source.get("",3),this.BAM_g_position+=3,this.BAM_sink.write_uint("presentation_level",3,this.presentation_level,this.BAM_g_position),this.b_presentation_id=this.BAM_source.get("",1),this.BAM_g_position+=1,this.BAM_sink.write_uint("b_presentation_id",1,this.b_presentation_id,this.BAM_g_position),this.b_presentation_id){if(this.BAM_sink.before_call("variable_bits",[2],"presentation_id",this.BAM_g_position),this.presentation_id=this.F_variable_bits(2),this.presentation_id==null)throw b("F_variable_bits","expected to return a value, returned None");this.BAM_sink.after_call("variable_bits",this.presentation_id,"presentation_id",this.BAM_g_position)}this.F_frame_rate_multiply_info(),this.F_emdf_info(),this.b_single_substream==1?this.F_ac4_substream_info(0,0,0):(this.b_hsf_ext=this.BAM_source.get("",1),this.BAM_g_position+=1,this.presentation_config==0?(this.F_ac4_substream_info(0,0,0),this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(1),this.F_ac4_substream_info(0,1,1)):this.presentation_config==1?(this.F_ac4_substream_info(0,0,0),this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(1),this.F_ac4_substream_info(0,0,1)):this.presentation_config==2?(this.F_ac4_substream_info(0,0,0),this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(1),this.F_ac4_substream_info(1,0,1)):this.presentation_config==3?(this.F_ac4_substream_info(0,0,0),this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(1),this.F_ac4_substream_info(0,1,1),this.F_ac4_substream_info(1,0,2)):this.presentation_config==4?(this.F_ac4_substream_info(0,0,0),this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(1),this.F_ac4_substream_info(0,0,1),this.F_ac4_substream_info(1,0,2)):this.presentation_config==5?(this.F_ac4_substream_info(0,0,0),this.b_hsf_ext&&this.F_ac4_hsf_ext_substream_info(1)):this.F_presentation_config_ext_info()),this.b_pre_virtualized=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_add_emdf_substreams=this.BAM_source.get("",1),this.BAM_g_position+=1}if(this.b_add_emdf_substreams){if(this.n_add_emdf_substreams=this.BAM_source.get("",2),this.BAM_g_position+=2,this.n_add_emdf_substreams==0){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");this.n_add_emdf_substreams=this.v+4}for(this.pi_i=0;this.pi_i<this.n_add_emdf_substreams;this.pi_i++)this.F_emdf_info()}}}F_substream_index_table(){var t,s=null,s,e=null,e,_=null,_,r,h,f;{if(r=this.BAM_source.get("",2),this.BAM_g_position+=2,r==0){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");r=this.v+4}if(r-1<this.last_referenced_substream)throw"Number of substreams (n_substreams) indicated by substream_index_table is less than last referenced substream in TOC (last_referenced_substream).";if(r-1>this.last_referenced_substream&&(e==null?e=new Array(r-1+1).fill(0):e.length<=r-1&&e.push.apply(e,new Array(r-1-e.length+1).fill(0)),e[r-1]=0,s==null?s=new Array(r-1+1).fill(null):s.length<=r-1&&s.push.apply(s,new Array(r-1-s.length+1).fill(null)),s[r-1]="unknown"),r==1?(t=this.BAM_source.get("",1),this.BAM_g_position+=1):t=1,t){for(h=0;h<r;h++)if(f=this.BAM_source.get("",1),this.BAM_g_position+=1,_==null?_=new Array(h+1).fill(0):_.length<=h&&_.push.apply(_,new Array(h-_.length+1).fill(0)),_[h]=this.BAM_source.get("",10),this.BAM_g_position+=10,f){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");_==null?_=new Array(h+1).fill(0):_.length<=h&&_.push.apply(_,new Array(h-_.length+1).fill(0)),_[h]+=this.v<<10}}}}F_ac4_presentation_v2_info(t){{if(this.presentation_to_groups==null?this.presentation_to_groups=new Array(this.toc_i+1).fill(null):this.presentation_to_groups.length<=this.toc_i&&this.presentation_to_groups.push.apply(this.presentation_to_groups,new Array(this.toc_i-this.presentation_to_groups.length+1).fill(null)),this.presentation_to_groups[this.toc_i]=[],this.b_single_substream_group=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_single_substream_group!=1&&(this.presentation_config=this.BAM_source.get("",3),this.BAM_g_position+=3,this.presentation_config==7)){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");this.presentation_config+=this.v}if(this.bitstream_version!=1&&(this.presentation_version=this.F_presentation_version(),this.presentation_version==null))throw b("F_presentation_version","expected to return a value, returned None");if(this.b_single_substream_group!=1&&this.presentation_config==6)this.b_add_emdf_substreams=1;else{if(this.bitstream_version!=1&&(this.presentation_level=this.BAM_source.get("",3),this.BAM_g_position+=3,this.BAM_sink.write_uint("presentation_level",3,this.presentation_level,this.BAM_g_position)),this.b_presentation_id=this.BAM_source.get("",1),this.BAM_g_position+=1,this.BAM_sink.write_uint("b_presentation_id",1,this.b_presentation_id,this.BAM_g_position),this.b_presentation_id){if(this.BAM_sink.before_call("variable_bits",[2],"presentation_id",this.BAM_g_position),this.presentation_id=this.F_variable_bits(2),this.presentation_id==null)throw b("F_variable_bits","expected to return a value, returned None");this.BAM_sink.after_call("variable_bits",this.presentation_id,"presentation_id",this.BAM_g_position)}if(this.F_frame_rate_multiply_info(),this.F_frame_rate_fractions_info(),this.F_emdf_info(),this.b_presentation_filter=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_presentation_filter&&(this.b_enable_presentation=this.BAM_source.get("",1),this.BAM_g_position+=1),this.b_single_substream_group==1)this.F_ac4_sgi_specifier(0,0,0),this.n_substream_groups=1;else if(this.b_multi_pid=this.BAM_source.get("",1),this.BAM_g_position+=1,this.presentation_config==0)this.F_ac4_sgi_specifier(0,0,0),this.F_ac4_sgi_specifier(0,1,1),this.n_substream_groups=2;else if(this.presentation_config==1)this.F_ac4_sgi_specifier(0,0,0),this.F_ac4_sgi_specifier(0,0,1),this.n_substream_groups=1;else if(this.presentation_config==2)this.F_ac4_sgi_specifier(0,0,0),this.F_ac4_sgi_specifier(1,0,1),this.n_substream_groups=2;else if(this.presentation_config==3)this.F_ac4_sgi_specifier(0,0,0),this.F_ac4_sgi_specifier(0,1,1),this.F_ac4_sgi_specifier(1,0,2),this.n_substream_groups=3;else if(this.presentation_config==4)this.F_ac4_sgi_specifier(0,0,0),this.F_ac4_sgi_specifier(0,0,1),this.F_ac4_sgi_specifier(1,0,2),this.n_substream_groups=2;else if(this.presentation_config==5){if(this.n_substream_groups_minus2=this.BAM_source.get("",2),this.BAM_g_position+=2,this.n_substream_groups=this.n_substream_groups_minus2+2,this.n_substream_groups==5){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");this.n_substream_groups+=this.v}for(this.sg=0;this.sg<this.n_substream_groups;this.sg++)this.F_ac4_sgi_specifier(0,0,0)}else this.n_substream_groups=0,this.F_presentation_config_ext_info();this.b_pre_virtualized=this.BAM_source.get("",1),this.BAM_g_position+=1,this.b_add_emdf_substreams=this.BAM_source.get("",1),this.BAM_g_position+=1,this.F_ac4_presentation_substream_info(this.presentation_version)}if(this.b_add_emdf_substreams){if(this.n_add_emdf_substreams=this.BAM_source.get("",2),this.BAM_g_position+=2,this.n_add_emdf_substreams==0){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");this.n_add_emdf_substreams=this.v+4}for(this.pi_i=0;this.pi_i<this.n_add_emdf_substreams;this.pi_i++)this.F_emdf_info()}}}F_frame_size(){var t;t=this.BAM_source.get("",16),this.BAM_g_position+=16,t==65535&&(t=this.BAM_source.get("",24),this.BAM_g_position+=24)}F_ac4_toc(){var t,s,e,_,r,h,f,c,p,l,d,u,o,g,A;{if(this.bitstream_version=this.BAM_source.get("",2),this.BAM_g_position+=2,this.bitstream_version==3){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");this.bitstream_version+=this.v}if(u=this.BAM_source.get("",10),this.BAM_g_position+=10,t=this.BAM_source.get("",1),this.BAM_g_position+=1,t&&(_=this.BAM_source.get("",3),this.BAM_g_position+=3,_>0&&(this.reserved=this.BAM_source.get("",2),this.BAM_g_position+=2)),this.fs_index=this.BAM_source.get("",1),this.BAM_g_position+=1,this.frame_rate_index=this.BAM_source.get("",4),this.BAM_g_position+=4,this.frame_rate_index>13)throw"frame_rate_index must be in range 0..13";if(this.fs_index==0&&this.frame_rate_index!=13)throw"44.1kHz sampling rate && frame rates other than 13 are illegal. See table 84 in the ETSI spec.";if(d=this.BAM_source.get("",1),this.BAM_g_position+=1,l=this.BAM_source.get("",1),this.BAM_g_position+=1,l)e=1;else if(g=this.BAM_source.get("",1),this.BAM_g_position+=1,g){if(this.v=this.F_variable_bits(2),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");e=this.v+2}else e=0;if(c=0,r=this.BAM_source.get("",1),this.BAM_g_position+=1,r&&(s=this.BAM_source.get("",5),this.BAM_g_position+=5,this.BAM_sink.write_uint("payload_base_minus1",5,s,this.BAM_g_position),c=s+1,c==32)){if(this.v=this.F_variable_bits(3),this.v==null)throw b("F_variable_bits","expected to return a value, returned None");c+=this.v}if(this.a_substream_indices=[],this.last_referenced_substream=-1,this.referenced_substreams=[],this.bk_substream_index=100,this.bitstream_version<=1)for(this.toc_j=0,this.toc_i=0;this.toc_i<e;this.toc_i++)this.F_ac4_presentation_info();else{for(o=this.BAM_source.get("",1),this.BAM_g_position+=1,o&&(A=this.BAM_source.get("",16),this.BAM_g_position+=16,p=this.BAM_source.get("",1),this.BAM_g_position+=1,p&&(h=this.BAM_source.get("",16*8),this.BAM_g_position+=16*8)),f=0,this.toc_i=0;this.toc_i<e;this.toc_i++)for(this.F_ac4_presentation_v2_info(this.toc_i),this.i=0;this.i<this.presentation_to_groups[this.toc_i].length;this.i++)f=Math.max(f,1+this.presentation_to_groups[this.toc_i][this.i]);for(this.toc_j=0;this.toc_j<f;this.toc_j++)this.F_ac4_substream_group_info(this.toc_j)}this.F_substream_index_table(),this.BAM_l_align=(8-(this.BAM_g_position%8+8)%8%8+8)%8,this.BAM_l_align_val=this.BAM_source.get_align(this.BAM_l_align),this.BAM_sink.write_align((8-(this.BAM_g_position%8+8)%8%8+8)%8,this.BAM_l_align_val),this.BAM_g_position+=this.BAM_l_align}}F_get_num_channels(t){{if(t==this.CHANNEL_MODE_MONO)this.n=1;else if(t==this.CHANNEL_MODE_STEREO)this.n=2;else if(t==this.CHANNEL_MODE_30)this.n=3;else if(t==this.CHANNEL_MODE_50)this.n=5;else if(t==this.CHANNEL_MODE_51)this.n=6;else if(t==this.CHANNEL_MODE_70_34)this.n=7;else if(t==this.CHANNEL_MODE_71_34)this.n=8;else if(t==this.CHANNEL_MODE_70_52)this.n=7;else if(t==this.CHANNEL_MODE_71_52)this.n=8;else if(t==this.CHANNEL_MODE_70_322)this.n=7;else if(t==this.CHANNEL_MODE_71_322)this.n=8;else if(t==this.CHANNEL_MODE_704)this.n=11;else if(t==this.CHANNEL_MODE_714)this.n=12;else if(t==this.CHANNEL_MODE_904)this.n=13;else if(t==this.CHANNEL_MODE_914)this.n=14;else throw"Unknown channel mode!";return this.n}}F_frame_rate_multiply_info(){var t,s;this.BAM_g_table14.slice(0).indexOf(this.frame_rate_index)>=0?(s=this.BAM_source.get("",1),this.BAM_g_position+=1,s?(t=this.BAM_source.get("",1),this.BAM_g_position+=1,this.frame_rate_factor=this.BAM_g_table15[t]):this.frame_rate_factor=1):this.BAM_g_table16.slice(0).indexOf(this.frame_rate_index)>=0?(s=this.BAM_source.get("",1),this.BAM_g_position+=1,this.frame_rate_factor=this.BAM_g_table17[s]):this.frame_rate_factor=1}F_frame_rate_fractions_info(){var t,s,e;s=1,this.BAM_g_table18.slice(0).indexOf(this.frame_rate_index)>=0&&this.frame_rate_factor==1&&(e=this.BAM_source.get("",1),this.BAM_g_position+=1,e==1&&(s=2)),this.BAM_g_table19.slice(0).indexOf(this.frame_rate_index)>=0&&(e=this.BAM_source.get("",1),this.BAM_g_position+=1,e==1&&(t=this.BAM_source.get("",1),this.BAM_g_position+=1,t==1?s=4:s=2))}};var Bt=(i,t)=>{let s=[],e=0,_={next(){return e<i.byteLength?{value:i.getUint8(e),done:++e>=i.byteLength}:{value:void 0,done:!0}}},r=(p,l,d,u,o)=>{let g=u-d;s.push({handler:o,name:p,pos:g,value:l,width:d})},h=new J(_),f=new X(t,r),c=new K(h,f);try{c.F_raw_ac4_frame_toc_only()}catch(p){s=null}return s};var Ut=3,Rt=7,jt=3,zt=2,Gt=256,Yt=[et,it,st,G,T,Y],Ft=i=>{var c,p,l,d;let t=i.fetch(R),s=i.fetch(j),e=[],_=s&&s.boxes.find(u=>u.type===ht),r=_&&_.boxes.filter(u=>u.type===lt),h=t&&t.boxes.filter(u=>u.type===nt),f=(c=h==null?void 0:h.map(u=>u.boxes.find(g=>g.type===at).track_ID))!=null?c:[];if(Array.isArray(r)){for(let u of r)if(u.entities.every(o=>f.includes(o.entity_id))){let o=parseInt(u.preselection_tag,10),g=isNaN(o)?null:o,A=(p=u.selection_priority)!=null?p:null,B=u.boxes.find(M=>M.type===ft),F=B==null?void 0:B.boxes.find(M=>M.type===ct),v=Number.isInteger(F==null?void 0:F.dialog_gain)?F.dialog_gain/Gt:null,O=u.boxes.find(M=>M.type===ut),L=(l=O==null?void 0:O.extended_language)!=null?l:null,y=u.boxes.find(M=>M.type===pt),S=(d=y==null?void 0:y.audio_rendering_indication)!=null?d:null,k=u.boxes.filter(M=>M.type===dt).map(M=>({isGroupLabel:M.is_group_label,label:M.label,labelId:M.label_id,language:M.language})),N=u.boxes.filter(M=>M.type===bt).map(M=>({schemeURI:M.schemeURI,value:M.value}));e.push({audioRenderingIndication:S,dialogGain:v,extendedLanguage:L,id:g,kinds:N,labels:k,selectionPriority:A})}}return e},Et=(i,t)=>{let s=vt(i);for(let e of s){let _=new DataView(i._raw.buffer,e.offset,e.size),r=Bt(_,Yt);if(r===null)return null;let h=r.find(o=>o.name===G);if(!h)return null;let f=0,c=r.find(o=>o.name===T);c&&(f=c.width);let p=r.find(o=>o.name===Y),l=[],d=[];if(r.forEach(o=>{switch(o.name){case et:{l.push({pos:o.pos,value:o.value,width:o.width});break}case st:{let g=l[l.length-1];if(l.length,o.handler==="before_call"&&(g.presentationIdPos=o.pos),o.handler==="after_call"){g.presentationId=o.value;let A=o.pos-g.presentationIdPos;g.presentationIdWidth=A,f+=A}break}case it:{d.push(o);break}case G:case T:case Y:break;default:}}),l.length<zt||l.some(o=>o.presentationId===void 0)||l.every(o=>o.presentationId!==t))return null;l.forEach(o=>{let g=o.presentationId;o.width,t!==g&&V(_,o.pos,o.width,Rt)});let u=f>>>jt;V(_,h.pos,h.width,h.value+u),d.forEach(o=>{V(_,o.pos,o.width,0)}),l.slice().reverse().forEach(o=>{let g=p.pos-o.presentationIdPos;Mt(_,o.presentationIdPos,g,o.presentationIdWidth)})}return t};var _t=kt(xt(),1);var yt={INIT:"init",MEDIA:"media"};_t.default.addBoxProcessor("diap",function(){this._procFullBox(),this._procField("dialog_gain","int",16)});var x,I,P,$,Nt=class{constructor(){H(this,P);H(this,x,{});H(this,I)}getStreams(){return E(this,x)}clearStream(t=null){delete E(this,x)[t]}setPresentationsChangedEventHandler(t){ot(this,I,t)}getPresentations(t=null){return U(this,P,$).call(this,t),E(this,x)[t].presentations}getActivePresentationId(t=null){var e;return(e=E(this,x)[t])==null?void 0:e.activePresentationId}setActivePresentationId(t,s=null){U(this,P,$).call(this,s),E(this,x)[s].activePresentationId=t}processIsoBmffSegment(t,s=null,e=void 0){let _=null,r=null,h=null,f=_t.default.parseBuffer(t),c=f.fetch(R),p=f.fetch(j),l=f.fetch(z);U(this,P,$).call(this,s);let d=E(this,x)[s];return c&&p&&(r=Ft(f),d.presentations=r,E(this,I)&&E(this,I).call(this,{streamId:s}),h=yt.INIT),l&&(_=Et(f,e!=null?e:d.activePresentationId),h=yt.MEDIA),{forcedPresentationId:_,presentations:r,segmentType:h}}};x=new WeakMap,I=new WeakMap,P=new WeakSet,$=function(t){E(this,x)[t]===void 0&&(E(this,x)[t]={activePresentationId:-1,presentations:[]})};export{Nt as Alps};
2
+ /*! Bundled license information:
3
+
4
+ codem-isoboxer/dist/iso_boxer.js:
5
+ (*! codem-isoboxer v0.3.10 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt *)
6
+ */
package/dist/alps.d.ts ADDED
@@ -0,0 +1,129 @@
1
+ export * from "./types.js";
2
+ /**
3
+ * Provides the core functionality of the library. It allows to process ISOBMFF segments and manage presentations.
4
+ */
5
+ export class Alps {
6
+ /**
7
+ * Get presentation and activePresentationId for all streams
8
+ * @returns {Record<string,Stream>} Data for all streams present in current ALPS state
9
+ */
10
+ getStreams(): Record<string, Stream>;
11
+ /**
12
+ * Clear data for unused stream
13
+ * @param {string|null} streamId Stream ID which should be deleted, null for non-multi-period use
14
+ */
15
+ clearStream(streamId?: string | null): void;
16
+ /**
17
+ * Set presentationsChangedEventHandler
18
+ * @param {presentationsChangedCallback} presentationsChangedEventHandler Callback function that will be called if the list of presentations changes
19
+ */
20
+ setPresentationsChangedEventHandler(presentationsChangedEventHandler: presentationsChangedCallback): void;
21
+ /**
22
+ * Get the list of available presentations
23
+ * @param {string|null} streamId The ID of the stream, null for non-multi-period use
24
+ * @returns {import('./types.js').Presentation[]} An array of presentation objects
25
+ */
26
+ getPresentations(streamId?: string | null): import("./types.js").Presentation[];
27
+ /**
28
+ * Get the ID of the currently active presentation
29
+ * @param {string|null} streamId The ID of the stream, null for non-multi-period use
30
+ * @returns {number|undefined} The ID of the active presentation, -1 if no presentation is set, undefined if no stream data exists
31
+ */
32
+ getActivePresentationId(streamId?: string | null): number | undefined;
33
+ /**
34
+ * Set the ID of the active presentation
35
+ * @param {number|undefined} presentationId - The ID of the presentation to set as active, -1 to select the default presentation or undefined to clear any active presentation
36
+ * @param {string|null} streamId The ID of the stream, null for non-multi-period use
37
+ */
38
+ setActivePresentationId(presentationId: number | undefined, streamId?: string | null): void;
39
+ /**
40
+ * Process an ISOBMFF segment buffer
41
+ * @param {ArrayBuffer} segmentBuffer - The ISOBMFF segment buffer to process
42
+ * @param {string|null} streamId - Stream ID for Segment buffer, null for non-multi-period use
43
+ * @param {number|undefined} activePresentationId - Forced presentation ID that should be selected for processing, use -1 for TV default, and leave undefined to use value set by setActivePresentationId. This parameter takes precedence over this.activePresentationId
44
+ * @returns {ProcessIsoBmffSegmentResult} Data retrieved from processed segment
45
+ */
46
+ processIsoBmffSegment(segmentBuffer: ArrayBuffer, streamId?: string | null, activePresentationId?: number | undefined): ProcessIsoBmffSegmentResult;
47
+ #private;
48
+ }
49
+ /**
50
+ * This callback is called when list of presentations changes, e.g. new init segment is processed for multi-period DASH contents.
51
+ */
52
+ export type presentationsChangedCallback = (event: PresentationsChangedEvent) => any;
53
+ /**
54
+ * Event data for presentationsChangedCallback
55
+ */
56
+ export type PresentationsChangedEvent = {
57
+ /**
58
+ * - ID of the stream for which the presentations were parsed
59
+ */
60
+ streamId: string | null;
61
+ };
62
+ /**
63
+ * ALPS Data for stream
64
+ */
65
+ export type Stream = {
66
+ /**
67
+ * - presentation related to the stream
68
+ */
69
+ presentations: import("./types.js").Presentation[];
70
+ /**
71
+ * - current active presentation ID for the stream
72
+ */
73
+ activePresentationId: number | undefined;
74
+ };
75
+ /**
76
+ * Buffer processing result for init segment.
77
+ */
78
+ export type ProcessIsoBmffInitSegmentResult = {
79
+ /**
80
+ * - "init" indicating that segment is an init segment
81
+ */
82
+ segmentType: "init";
83
+ /**
84
+ * - list of presentations read from ISOBMFF init segment
85
+ */
86
+ presentations: import("./types.js").Presentation[];
87
+ /**
88
+ * - always null for init segments
89
+ */
90
+ forcedPresentationId: null;
91
+ };
92
+ /**
93
+ * Buffer processing result for media segment.
94
+ */
95
+ export type ProcessIsoBmffMediaSegmentResult = {
96
+ /**
97
+ * - "media" indicating that segment is a media segment
98
+ */
99
+ segmentType: "media";
100
+ /**
101
+ * - null for media segments
102
+ */
103
+ presentations: null;
104
+ /**
105
+ * - ID of presentation selected in bitstream, null when no presentation was selected
106
+ */
107
+ forcedPresentationId: number | null;
108
+ };
109
+ /**
110
+ * Buffer processing result for unknown segment.
111
+ */
112
+ export type ProcessIsoBmffUnknownSegmentResult = {
113
+ /**
114
+ * - null indicating that segment type is unknown
115
+ */
116
+ segmentType: null;
117
+ /**
118
+ * - null for unknown segments
119
+ */
120
+ presentations: null;
121
+ /**
122
+ * - null for unknown segments
123
+ */
124
+ forcedPresentationId: null;
125
+ };
126
+ /**
127
+ * Buffer processing result.
128
+ */
129
+ export type ProcessIsoBmffSegmentResult = ProcessIsoBmffInitSegmentResult | ProcessIsoBmffMediaSegmentResult | ProcessIsoBmffUnknownSegmentResult;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Presentation entity.
3
+ */
4
+ export type Presentation = {
5
+ /**
6
+ * - unique presentation identifier, should match presentation ID from TOC
7
+ */
8
+ id: number | null;
9
+ /**
10
+ * - priority value for presentation when no other differentiation is possible
11
+ */
12
+ selectionPriority: number | null;
13
+ /**
14
+ * - the gain applied to the dialog compared to the default mix
15
+ */
16
+ dialogGain: number | null;
17
+ /**
18
+ * - language parsed from ISOBMFF elng box
19
+ */
20
+ extendedLanguage: string | null;
21
+ /**
22
+ * - hint for a preferred reproduction channel layout
23
+ */
24
+ audioRenderingIndication: number | null;
25
+ /**
26
+ * - presentation labels parsed from ISOBMFF labl boxes
27
+ */
28
+ labels: Label[];
29
+ /**
30
+ * - presentation kinds parsed from ISOBMFF kind boxes
31
+ */
32
+ kinds: Kind[];
33
+ };
34
+ /**
35
+ * Label object.
36
+ */
37
+ export type Label = {
38
+ /**
39
+ * - flag indicating that label is a summary label for group of labels
40
+ */
41
+ isGroupLabel: boolean;
42
+ /**
43
+ * - identifier for the label
44
+ */
45
+ labelId: number;
46
+ /**
47
+ * - language tag string compliant with IETF BCP 47
48
+ */
49
+ language: string;
50
+ /**
51
+ * - label text
52
+ */
53
+ label: string;
54
+ };
55
+ /**
56
+ * Kind object.
57
+ */
58
+ export type Kind = {
59
+ /**
60
+ * - declares the identifier of the kind or the identifier of the naming scheme for the following value
61
+ */
62
+ schemeURI: string;
63
+ /**
64
+ * - is defined by the declared scheme
65
+ */
66
+ value: string;
67
+ };
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@dolbylaboratories/alps",
3
+ "main": "dist/alps.bundle.min.js",
4
+ "types": "dist/alps.d.ts",
5
+ "version": "2.0.0",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "type": "module",
10
+ "description": "reference application-level presentation selection implementation",
11
+ "keywords": [
12
+ "AC-4",
13
+ "presentations",
14
+ "preselections",
15
+ "personalization",
16
+ "flexstream"
17
+ ],
18
+ "homepage": "https://github.com/DolbyLaboratories/alps-web",
19
+ "license": "BSD-3-Clause",
20
+ "author": "Wolfgang Schildbach <wschi@dolby.com>",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/DolbyLaboratories/alps-web.git"
27
+ },
28
+ "scripts": {
29
+ "build": "esbuild src/alps.js --bundle --format=esm --drop:console --drop:debugger --sourcemap --target=chrome58,firefox57,safari11,edge16 --outfile=dist/alps.bundle.js",
30
+ "build:production": "esbuild src/alps.js --bundle --format=esm --minify --drop:console --drop:debugger --target=chrome58,firefox57,safari11,edge16 --outfile=dist/alps.bundle.min.js && npm run types",
31
+ "types": "tsc src/alps.js -d --emitDeclarationOnly --allowJs --skipLibCheck --outDir .temp && mv .temp/alps.d.ts .temp/types.d.ts dist && rm -r .temp",
32
+ "test": "jest",
33
+ "lint": "eslint",
34
+ "docs": "jsdoc -c ./jsdoc.config.json -d docs/html src/* README.md"
35
+ },
36
+ "devDependencies": {
37
+ "@babel/preset-env": "^7.24.7",
38
+ "@eslint/js": "^9.8.0",
39
+ "@semantic-release/git": "^10.0.1",
40
+ "@types/jest": "^29.5.12",
41
+ "babel-jest": "^29.7.0",
42
+ "babel-plugin-rewire": "^1.2.0",
43
+ "esbuild": "0.23.0",
44
+ "eslint": "^9.8.0",
45
+ "eslint-config-prettier": "^9.1.0",
46
+ "eslint-plugin-prettier": "^5.2.1",
47
+ "jest": "^29.7.0",
48
+ "jsdoc": "^4.0.4",
49
+ "jsdoc-tsimport-plugin": "^1.0.5",
50
+ "semantic-release": "^24.0.0",
51
+ "ts-jest": "^29.1.5",
52
+ "typescript": "^5.9.2"
53
+ },
54
+ "dependencies": {
55
+ "codem-isoboxer": "^0.3.10"
56
+ }
57
+ }