@ahmedrowaihi/mediabunny 1.65.2-beta.710 → 1.65.2-beta.711

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.
@@ -57336,10 +57336,10 @@ ${this.fileName}`;
57336
57336
 
57337
57337
  // src/hls/hls-serializer.ts
57338
57338
  var byteRangeValue = (b) => {
57339
- if (b === null) {
57339
+ if (b == null) {
57340
57340
  return null;
57341
57341
  }
57342
- return b.offset === null ? `${b.length}` : `${b.length}@${b.offset}`;
57342
+ return b.offset == null ? `${b.length}` : `${b.length}@${b.offset}`;
57343
57343
  };
57344
57344
  var keysEqual = (a, b) => a.length === b.length && a.every((k, i) => {
57345
57345
  const o = b[i];
@@ -57349,7 +57349,7 @@ ${this.fileName}`;
57349
57349
  if (a === b) {
57350
57350
  return true;
57351
57351
  }
57352
- if (a === null || b === null) {
57352
+ if (a == null || b == null) {
57353
57353
  return false;
57354
57354
  }
57355
57355
  return a.uri === b.uri && (a.byteRange?.length ?? null) === (b.byteRange?.length ?? null) && (a.byteRange?.offset ?? null) === (b.byteRange?.offset ?? null);
@@ -57368,13 +57368,13 @@ ${this.fileName}`;
57368
57368
  if (m.uri) {
57369
57369
  tag.addQuotedString("URI", m.uri);
57370
57370
  }
57371
- if (m.default !== null) {
57371
+ if (m.default != null) {
57372
57372
  tag.addString("DEFAULT", m.default ? "YES" : "NO");
57373
57373
  }
57374
- if (m.autoselect !== null) {
57374
+ if (m.autoselect != null) {
57375
57375
  tag.addString("AUTOSELECT", m.autoselect ? "YES" : "NO");
57376
57376
  }
57377
- if (m.forced !== null) {
57377
+ if (m.forced != null) {
57378
57378
  tag.addString("FORCED", m.forced ? "YES" : "NO");
57379
57379
  }
57380
57380
  if (m.channels) {
@@ -57389,10 +57389,10 @@ ${this.fileName}`;
57389
57389
  if (m.instreamId) {
57390
57390
  tag.addQuotedString("INSTREAM-ID", m.instreamId);
57391
57391
  }
57392
- if (m.bitDepth !== null) {
57392
+ if (m.bitDepth != null) {
57393
57393
  tag.addNumber("BIT-DEPTH", m.bitDepth);
57394
57394
  }
57395
- if (m.sampleRate !== null) {
57395
+ if (m.sampleRate != null) {
57396
57396
  tag.addNumber("SAMPLE-RATE", m.sampleRate);
57397
57397
  }
57398
57398
  if (m.resolution) {
@@ -57406,7 +57406,7 @@ ${this.fileName}`;
57406
57406
  var streamInf = (v) => {
57407
57407
  const tag = new Tag("#EXT-X-STREAM-INF");
57408
57408
  tag.addNumber("BANDWIDTH", v.bandwidth);
57409
- if (v.averageBandwidth !== null) {
57409
+ if (v.averageBandwidth != null) {
57410
57410
  tag.addNumber("AVERAGE-BANDWIDTH", v.averageBandwidth);
57411
57411
  }
57412
57412
  if (v.codecs) {
@@ -57415,13 +57415,13 @@ ${this.fileName}`;
57415
57415
  if (v.supplementalCodecs) {
57416
57416
  tag.addQuotedString("SUPPLEMENTAL-CODECS", v.supplementalCodecs);
57417
57417
  }
57418
- if (v.score !== null) {
57418
+ if (v.score != null) {
57419
57419
  tag.addFloat("SCORE", v.score);
57420
57420
  }
57421
57421
  if (v.resolution) {
57422
57422
  tag.addNumberPair("RESOLUTION", v.resolution.width, "x", v.resolution.height);
57423
57423
  }
57424
- if (v.frameRate !== null) {
57424
+ if (v.frameRate != null) {
57425
57425
  tag.addFloat("FRAME-RATE", v.frameRate);
57426
57426
  }
57427
57427
  if (v.videoRange) {
@@ -57492,7 +57492,7 @@ ${this.fileName}`;
57492
57492
  var iFrameStreamInf = (s) => {
57493
57493
  const tag = new Tag("#EXT-X-I-FRAME-STREAM-INF");
57494
57494
  tag.addNumber("BANDWIDTH", s.bandwidth);
57495
- if (s.averageBandwidth !== null) {
57495
+ if (s.averageBandwidth != null) {
57496
57496
  tag.addNumber("AVERAGE-BANDWIDTH", s.averageBandwidth);
57497
57497
  }
57498
57498
  if (s.codecs) {
@@ -57501,7 +57501,7 @@ ${this.fileName}`;
57501
57501
  if (s.supplementalCodecs) {
57502
57502
  tag.addQuotedString("SUPPLEMENTAL-CODECS", s.supplementalCodecs);
57503
57503
  }
57504
- if (s.score !== null) {
57504
+ if (s.score != null) {
57505
57505
  tag.addFloat("SCORE", s.score);
57506
57506
  }
57507
57507
  if (s.resolution) {
@@ -57543,7 +57543,7 @@ ${this.fileName}`;
57543
57543
  const tag = new Tag("#EXT-X-MAP");
57544
57544
  tag.addQuotedString("URI", map.uri);
57545
57545
  const range = byteRangeValue(map.byteRange);
57546
- if (range !== null) {
57546
+ if (range != null) {
57547
57547
  tag.addQuotedString("BYTERANGE", range);
57548
57548
  }
57549
57549
  return tag;
@@ -57553,7 +57553,7 @@ ${this.fileName}`;
57553
57553
  tag.addFloat("DURATION", part.duration);
57554
57554
  tag.addQuotedString("URI", part.uri);
57555
57555
  const range = byteRangeValue(part.byteRange);
57556
- if (range !== null) {
57556
+ if (range != null) {
57557
57557
  tag.addQuotedString("BYTERANGE", range);
57558
57558
  }
57559
57559
  if (part.independent) {
@@ -57569,16 +57569,16 @@ ${this.fileName}`;
57569
57569
  if (control.canBlockReload) {
57570
57570
  tag.addString("CAN-BLOCK-RELOAD", "YES");
57571
57571
  }
57572
- if (control.canSkipUntil !== null) {
57572
+ if (control.canSkipUntil != null) {
57573
57573
  tag.addFloat("CAN-SKIP-UNTIL", control.canSkipUntil);
57574
57574
  }
57575
57575
  if (control.canSkipDateRanges) {
57576
57576
  tag.addString("CAN-SKIP-DATERANGES", "YES");
57577
57577
  }
57578
- if (control.holdBack !== null) {
57578
+ if (control.holdBack != null) {
57579
57579
  tag.addFloat("HOLD-BACK", control.holdBack);
57580
57580
  }
57581
- if (control.partHoldBack !== null) {
57581
+ if (control.partHoldBack != null) {
57582
57582
  tag.addFloat("PART-HOLD-BACK", control.partHoldBack);
57583
57583
  }
57584
57584
  return tag.toString();
@@ -57587,10 +57587,10 @@ ${this.fileName}`;
57587
57587
  const tag = new Tag("#EXT-X-PRELOAD-HINT");
57588
57588
  tag.addString("TYPE", hint.type);
57589
57589
  tag.addQuotedString("URI", hint.uri);
57590
- if (hint.byteRangeStart !== null) {
57590
+ if (hint.byteRangeStart != null) {
57591
57591
  tag.addNumber("BYTERANGE-START", hint.byteRangeStart);
57592
57592
  }
57593
- if (hint.byteRangeLength !== null) {
57593
+ if (hint.byteRangeLength != null) {
57594
57594
  tag.addNumber("BYTERANGE-LENGTH", hint.byteRangeLength);
57595
57595
  }
57596
57596
  return tag.toString();
@@ -57598,7 +57598,7 @@ ${this.fileName}`;
57598
57598
  var startTag = (start) => {
57599
57599
  const tag = new Tag("#EXT-X-START");
57600
57600
  tag.addFloat("TIME-OFFSET", start.timeOffset);
57601
- if (start.precise !== null) {
57601
+ if (start.precise != null) {
57602
57602
  tag.addString("PRECISE", start.precise ? "YES" : "NO");
57603
57603
  }
57604
57604
  return tag;
@@ -57626,16 +57626,16 @@ ${this.fileName}`;
57626
57626
  var sessionDataTag = (d) => {
57627
57627
  const tag = new Tag("#EXT-X-SESSION-DATA");
57628
57628
  tag.addQuotedString("DATA-ID", d.dataId);
57629
- if (d.value !== null) {
57629
+ if (d.value != null) {
57630
57630
  tag.addQuotedString("VALUE", d.value);
57631
57631
  }
57632
- if (d.uri !== null) {
57632
+ if (d.uri != null) {
57633
57633
  tag.addQuotedString("URI", d.uri);
57634
57634
  }
57635
- if (d.format !== null) {
57635
+ if (d.format != null) {
57636
57636
  tag.addString("FORMAT", d.format);
57637
57637
  }
57638
- if (d.language !== null) {
57638
+ if (d.language != null) {
57639
57639
  tag.addQuotedString("LANGUAGE", d.language);
57640
57640
  }
57641
57641
  return tag;
@@ -57643,7 +57643,7 @@ ${this.fileName}`;
57643
57643
  var contentSteeringTag = (c) => {
57644
57644
  const tag = new Tag("#EXT-X-CONTENT-STEERING");
57645
57645
  tag.addQuotedString("SERVER-URI", c.serverUri);
57646
- if (c.pathwayId !== null) {
57646
+ if (c.pathwayId != null) {
57647
57647
  tag.addQuotedString("PATHWAY-ID", c.pathwayId);
57648
57648
  }
57649
57649
  return tag;
@@ -57651,20 +57651,20 @@ ${this.fileName}`;
57651
57651
  var dateRangeTag = (d) => {
57652
57652
  const tag = new Tag("#EXT-X-DATERANGE");
57653
57653
  tag.addQuotedString("ID", d.id);
57654
- if (d.className !== null) {
57654
+ if (d.className != null) {
57655
57655
  tag.addQuotedString("CLASS", d.className);
57656
57656
  }
57657
57657
  tag.addQuotedString("START-DATE", d.startDate);
57658
- if (d.cue !== null) {
57658
+ if (d.cue != null) {
57659
57659
  tag.addString("CUE", d.cue);
57660
57660
  }
57661
- if (d.endDate !== null) {
57661
+ if (d.endDate != null) {
57662
57662
  tag.addQuotedString("END-DATE", d.endDate);
57663
57663
  }
57664
- if (d.duration !== null) {
57664
+ if (d.duration != null) {
57665
57665
  tag.addFloat("DURATION", d.duration);
57666
57666
  }
57667
- if (d.plannedDuration !== null) {
57667
+ if (d.plannedDuration != null) {
57668
57668
  tag.addFloat("PLANNED-DURATION", d.plannedDuration);
57669
57669
  }
57670
57670
  if (d.endOnNext) {
@@ -57676,7 +57676,7 @@ ${this.fileName}`;
57676
57676
  ["SCTE35-IN", d.scte35In]
57677
57677
  ];
57678
57678
  for (const [key, value] of scte35) {
57679
- if (value !== null) {
57679
+ if (value != null) {
57680
57680
  tag.addString(key, value);
57681
57681
  }
57682
57682
  }
@@ -57694,7 +57694,7 @@ ${this.fileName}`;
57694
57694
  var skipTag = (skip) => {
57695
57695
  const tag = new Tag("#EXT-X-SKIP");
57696
57696
  tag.addNumber("SKIPPED-SEGMENTS", skip.skippedSegments);
57697
- if (skip.recentlyRemovedDateRanges !== null) {
57697
+ if (skip.recentlyRemovedDateRanges != null) {
57698
57698
  tag.addQuotedString("RECENTLY-REMOVED-DATERANGES", skip.recentlyRemovedDateRanges.join(" "));
57699
57699
  }
57700
57700
  return tag.toString();
@@ -57702,17 +57702,17 @@ ${this.fileName}`;
57702
57702
  var renditionReportTag = (report) => {
57703
57703
  const tag = new Tag("#EXT-X-RENDITION-REPORT");
57704
57704
  tag.addQuotedString("URI", report.uri);
57705
- if (report.lastMsn !== null) {
57705
+ if (report.lastMsn != null) {
57706
57706
  tag.addNumber("LAST-MSN", report.lastMsn);
57707
57707
  }
57708
- if (report.lastPart !== null) {
57708
+ if (report.lastPart != null) {
57709
57709
  tag.addNumber("LAST-PART", report.lastPart);
57710
57710
  }
57711
57711
  return tag.toString();
57712
57712
  };
57713
57713
  var requiredVersion = (playlist) => {
57714
57714
  const needed = hlsVersionOf(playlist);
57715
- if (playlist.version === null) {
57715
+ if (playlist.version == null) {
57716
57716
  return needed > 1 ? needed : null;
57717
57717
  }
57718
57718
  if (playlist.version < needed) {
@@ -57725,7 +57725,7 @@ ${this.fileName}`;
57725
57725
  var serializeHlsMaster = (m) => {
57726
57726
  const lines = ["#EXTM3U"];
57727
57727
  const version = requiredVersion(m);
57728
- if (version !== null) {
57728
+ if (version != null) {
57729
57729
  lines.push(`#EXT-X-VERSION:${version}`);
57730
57730
  }
57731
57731
  lines.push(...m.unknownTags);
@@ -57778,10 +57778,10 @@ ${this.fileName}`;
57778
57778
  out.push(mapTag(seg.map).toString());
57779
57779
  prev.map = seg.map;
57780
57780
  }
57781
- if (seg.programDateTime !== null) {
57781
+ if (seg.programDateTime != null) {
57782
57782
  out.push(new ProgramDateTimeEntry(seg.programDateTime).toString());
57783
57783
  }
57784
- if (seg.bitrate !== null && seg.bitrate !== prev.bitrate) {
57784
+ if (seg.bitrate != null && seg.bitrate !== prev.bitrate) {
57785
57785
  out.push(`${TAG_BITRATE}${seg.bitrate}`);
57786
57786
  prev.bitrate = seg.bitrate;
57787
57787
  }
@@ -57791,7 +57791,7 @@ ${this.fileName}`;
57791
57791
  out.push(...seg.unknownTags);
57792
57792
  out.push(...seg.parts.map(partTag));
57793
57793
  const range = byteRangeValue(seg.byteRange);
57794
- if (range !== null) {
57794
+ if (range != null) {
57795
57795
  out.push(`${TAG_BYTERANGE}${range}`);
57796
57796
  }
57797
57797
  if (!Number.isFinite(seg.duration) || seg.duration < 0) {
@@ -57812,19 +57812,19 @@ ${this.fileName}`;
57812
57812
  var serializeHlsMedia = (m) => {
57813
57813
  const lines = ["#EXTM3U"];
57814
57814
  const version = requiredVersion(m);
57815
- if (version !== null) {
57815
+ if (version != null) {
57816
57816
  lines.push(`#EXT-X-VERSION:${version}`);
57817
57817
  }
57818
57818
  if (m.start) {
57819
57819
  lines.push(startTag(m.start).toString());
57820
57820
  }
57821
- if (m.targetDuration !== null) {
57821
+ if (m.targetDuration != null) {
57822
57822
  lines.push(`${TAG_TARGETDURATION}${m.targetDuration}`);
57823
57823
  }
57824
57824
  if (m.serverControl) {
57825
57825
  lines.push(serverControlTag(m.serverControl));
57826
57826
  }
57827
- if (m.partTarget !== null) {
57827
+ if (m.partTarget != null) {
57828
57828
  lines.push(new Tag("#EXT-X-PART-INF").addFloat("PART-TARGET", m.partTarget).toString());
57829
57829
  }
57830
57830
  if (m.mediaSequence !== 0) {
@@ -57845,7 +57845,7 @@ ${this.fileName}`;
57845
57845
  if (m.independentSegments) {
57846
57846
  lines.push("#EXT-X-INDEPENDENT-SEGMENTS");
57847
57847
  }
57848
- if (m.wmPaceInfoUri !== null) {
57848
+ if (m.wmPaceInfoUri != null) {
57849
57849
  lines.push(`${TAG_WMPACEINFO}"${m.wmPaceInfoUri}"`);
57850
57850
  }
57851
57851
  const prev = { keys: [], map: null, bitrate: null };
@@ -93,9 +93,9 @@ In Node, decoding requires the native codecs: call registerMediabunnyServer() fr
93
93
  Check the discardedTracks field for more info.`)}return e}async execute(e={}){if(!e||typeof e!="object")throw new TypeError("options must be an object.");if(e.until!==void 0&&(typeof e.until!="number"||Number.isNaN(e.until)))throw new TypeError("options.until, when provided, must be a number.");if(e.pauseSignal!==void 0&&!(e.pauseSignal instanceof AbortSignal))throw new TypeError("options.pauseSignal, when provided, must be an AbortSignal.");if(!this.isValid)throw new Error(`Cannot execute this conversion because its output configuration is invalid. Make sure to always check the isValid field before executing a conversion.
94
94
  `+this._getInvalidityExplanation().join(""));if(this._state==="executing")throw new Error("Cannot call execute() while a previous call to execute() is still running.");if(this._state==="canceled")throw new il;if(this._state==="done")return;if(this._composable&&this.output.state==="pending")throw new Error("A composable conversion requires the output to be started. Call start() on the output before executing the conversion.");this._state="executing",this._executionUntil=e.until??1/0,this._pauseRequested=e.pauseSignal?.aborted??!1;let t=()=>{this._state==="executing"&&(this._pauseRequested=!0,this._synchronizer.resolveAll())};e.pauseSignal?.addEventListener("abort",t);for(let i of this._trackPumps)i.done||(i.resolvers=pe());if(this._executed)for(let i of this._trackPumps)i.wake?.();else{this._executed=!0;for(let i of this._outputTrackIds)this._synchronizer.declareTrack(i);if(this.onProgress){let a=[...new Set(this.utilizedTracks)].map(o=>this._getTrackDuration(o)),s=Math.max(0,...await Promise.all(a));this._computeProgress=!0,this._totalDuration=Math.min(s-this._startTimestamp,this._endTimestamp-this._startTimestamp);for(let o of this._outputTrackIds)this._maxTimestamps.set(o,0);this.onProgress?.(0,0)}this._composable||await this.output.start();for(let i of this._trackPumps)i.start()}try{await Promise.all(this._trackPumps.map(i=>i.resolvers.promise))}catch(i){throw this._state!=="canceled"&&this.cancel(),i}finally{e.pauseSignal?.removeEventListener("abort",t)}if(this._state==="canceled")throw new il;let n=this._trackPumps.every(i=>i.done);if(this._state=n?"done":"idle",n&&(this._composable||await this.output.finalize(),this._computeProgress)){let i=Math.min(...this._maxTimestamps.values());this.onProgress?.(1,i)}}finish(){if(!(this._state==="done"||this._state==="canceled")){this._finishRequested=!0;for(let e of this._trackPumps)e.wake?.();this._synchronizer.resolveAll()}}async cancel(){if(this._state!=="done"){if(this._state==="canceled"){U._warn("Conversion already canceled.");return}this._state="canceled";for(let e of this._trackPumps)e.wake?.();this._synchronizer.resolveAll(),this._composable||await this.output.cancel()}}async _processVideoTrack(e,t,n){let i=await e.getCodec();if(!i){this.discardedTracks.push({track:e,reason:"unknown_source_codec",trackOptions:t});return}if(this.output.format.requiresMaximumPacketCount&&t.maximumPacketCount===void 0&&this._endTimestamp===1/0&&await e.isLive()){this.discardedTracks.push({track:e,reason:"unknown_maximum_packet_count",trackOptions:t});return}let a,s=await e.getRotation(),o=await e.getFlip(),{rotation:l,flip:c}=Bu(s,o,t.rotate??0,t.flip??!1),u=l,d=c,m=t.rotate||t.flip?null:await e.getTransformationMatrix(),f=this.output.format.supportsVideoTransformationMetadata&&(t.allowTransformationMetadata??t.allowRotationMetadata??!0),p=await e.getSquarePixelWidth(),g=await e.getSquarePixelHeight(),[h,y]=l%180===0?[p,g]:[g,p],S=t.crop;S&&(S=Mo(S,h,y));let[k,T]=S?[S.width,S.height]:[h,y],w=k,A=T,x=w/A;t.width!==void 0&&t.height===void 0?(w=Wa(t.width),A=Wa(Math.round(w/x))):t.width===void 0&&t.height!==void 0?(A=Wa(t.height),w=Wa(Math.round(A*x))):t.width!==void 0&&t.height!==void 0&&(w=Wa(t.width),A=Wa(t.height));let I=this.output.format.getSupportedVideoCodecs(),C=t.alpha??"discard",v=(i==="avc"||i==="hevc")&&!(await e.getDecoderConfig())?.description,P=!this._copyMode||!!t.forceTranscode||!!t.frameRate||t.keyFrameInterval!==void 0||t.parameterSets!==void 0&&!v||t.bitDepth!==void 0||t.colorSpace!==void 0||t.hdrStaticMetadata!==void 0||t.process!==void 0||t.preProcess!==void 0||t.preProcessFlush!==void 0||t.processFlush!==void 0||t.encoderControls!==void 0||t.quality!==void 0||t.bitrate!==void 0||!I.includes(i)||t.codec&&t.codec!==i||w!==k||A!==T||l!==0&&!f||c&&!f||!!S,R=null;if(!P){let yr=new At(e),it=await yr.getKeyPacket(this._startTimestamp,{verifyKeyPackets:!0})??await yr.getFirstKeyPacket({verifyKeyPackets:!0});if(it&&it.timestamp<this._startTimestamp&&it.timestamp+it.duration<=this._startTimestamp&&this._copyBoundaryPolicy==="shrink"&&(it=await yr.getNextKeyPacket(it,{verifyKeyPackets:!0})),R=it,it){let be=this._copyBoundaryPolicy==="shrink"?Math.max(it.timestamp,this._startTimestamp):it.timestamp;if((this._copyBoundaryPolicy==="shrink"?be-this._startTimestamp:Math.max(this._startTimestamp-be,0))>this._copyBoundaryTolerance)P=!0;else if(this.output.format.supportsTimestampedMediaData){if(this.output.format.negativeTimestampSupport!=="full"&&be<this._startTimestamp){let st=Math.min(this._startTimestamp-be,this._copyTimestampShiftTolerance);be+st>=this._startTimestamp||this.output.format.negativeTimestampSupport==="prefer-non-negative"&&this._copyMode==="forced"?this._timestampOffset=Math.max(this._timestampOffset,-this._startTimestamp+st):P=!0}}else if(this._timestampOffsetAdjusted)be+this._timestampOffset===0||(P=!0);else{let st=me(this._startTimestamp-be,-this._copyTimestampShiftTolerance,this._copyTimestampShiftTolerance);be+st===this._startTimestamp?(this._timestampOffset=-this._startTimestamp+st,this._timestampOffsetAdjusted=!0):P=!0}}}if(P&&this._copyMode==="forced"){this.discardedTracks.push({track:e,reason:"cannot_copy",trackOptions:t});return}if(P){if(!await e.canDecode()){let gt=await e.getCodec();gt!==null&&this._undecodableSourceCodecs.push(gt),this.discardedTracks.push({track:e,reason:"undecodable_source_codec",trackOptions:t});return}t.codec&&(I=I.filter(gt=>gt===t.codec));let it=ya(t.quality,t.bitrate)??new xe("high"),be=await e.getDecoderConfig(),Gn=await e.getColorSpace(),st=t.bitDepth??(be?zo(be)??void 0:void 0),ln=t.colorSpace??(Bi(Gn)?void 0:Gn),Sr=t.hdrStaticMetadata??be?.hdrStaticMetadata,jt=t.process!==void 0||t.preProcess!==void 0||t.processFlush!==void 0||t.preProcessFlush!==void 0,vt={width:jt&&t.processedWidth?t.processedWidth:w,height:jt&&t.processedHeight?t.processedHeight:A,quality:it},Ft=await zc(I,{...vt,bitDepth:st});if(!Ft&&t.bitDepth===void 0&&st!==void 0&&(st=void 0,Ft=await zc(I,vt)),!Ft){this.discardedTracks.push({track:e,reason:"no_encodable_target_codec",trackOptions:t});return}let Re={codec:Ft,quality:it,keyFrameInterval:t.keyFrameInterval,parameterSets:t.parameterSets,bitDepth:st,colorSpace:ln,hdrStaticMetadata:Sr,_bitDepthIsInherited:t.bitDepth===void 0,_colorSpaceIsInherited:t.colorSpace===void 0,_hdrStaticMetadataIsInherited:t.hdrStaticMetadata===void 0,sizeChangeBehavior:t.fit??"passThrough",alpha:C,hardwareAcceleration:t.hardwareAcceleration,transform:{}};b(Re.transform);let vi=w!==k||A!==T||l!==0&&(!f||jt)||c&&(!f||jt)||!!S||p!==await e.getCodedWidth()||g!==await e.getCodedHeight(),Ei=()=>{Re.bitDepth=t.bitDepth,Re.colorSpace=t.colorSpace,Re.hdrStaticMetadata=t.hdrStaticMetadata};if(!vi&&t.preProcess===void 0){var Fe=[];try{let gt=new pr({format:new As,target:new Pa});let Fa=new di(Re);gt.addVideoTrack(Fa);await gt.start();let hl=new On(e,{hardwareAcceleration:t.hardwareAcceleration});let Rs=Yt(Fe,await hl.getSample(await e.getFirstTimestamp()));if(Rs)try{await Fa.add(Rs),Rs.close(),await gt.finalize()}catch(Ms){if(Ms instanceof Lo&&t.colorSpace!==void 0)throw gt.cancel(),Ms;U._warn(Ms instanceof Lo?"The color space inherited from the input contradicts the samples reaching the encoder, so it is dropped and the frames are re-rendered. The output states no color rather than one its samples do not have.":"An error occurred when probing encoder support. Falling back to rerender path.",Ms),gt.cancel(),vi=!0,Re.transform.force=!0,Ei()}else await gt.cancel()}catch(It){var qn=It,Dp=!0}finally{Zt(Fe,qn,Dp)}}t.frameRate&&(Re.transform.frameRate=t.frameRate),t.process&&(Re.transform.process=t.process),t.preProcess&&(Re.transform.preProcess=t.preProcess),t.encoderControls&&(Re.encoderControls=t.encoderControls),t.preProcessFlush&&(Re.transform.preProcessFlush=t.preProcessFlush),t.processFlush&&(Re.transform.processFlush=t.processFlush),vi&&(u=0,d=!1,m=null,Re.transform.width=w,Re.transform.height=A,Re.transform.fit=t.fit??"fill",Re.transform.rotate=t.rotate,Re.transform.flip=t.flip,Re.transform.crop=S,Re.transform.alpha=C);let _i=null;Re.onEncodedSample=gt=>{_i=gt.timestamp};let _s=new di(Re);a=_s,this._registerTrackPump(async gt=>{let Fa=new On(e,{hardwareAcceleration:t.hardwareAcceleration});for await(var hl of Fa.samples(this._startTimestamp,this._endTimestamp)){var Rs=[];try{let $n=Yt(Rs,hl);if(this._state==="canceled"||this._finishRequested)break;let Bp=Math.max(this._startTimestamp,$n.timestamp),Jb=Math.min(this._endTimestamp,$n.timestamp+$n.duration);Bp>=Jb||($n.setTimestamp(Bp+this._timestampOffset),$n.setDuration(Jb-Bp),this._reportProgress(n,$n.timestamp+$n.duration),await _s.add($n),$n.close(),_i!==null&&(this._synchronizer.shouldWait(n,_i)&&await this._synchronizer.wait(_i),await this._checkpoint(gt,_i)))}catch(Ms){var _C=Ms,RC=!0}finally{Zt(Rs,_C,RC)}}_s.close(),this._synchronizer.closeTrack(n)})}else{let yr=new ui(i);a=yr,this._registerTrackPump(async it=>{let be=new At(e),st={decoderConfig:await e.getDecoderConfig()??void 0},ln=new Ho,Sr=!1,jt=!1;if(R)for await(let vt of be.packets(R,void 0,{verifyKeyPackets:!0})){if(this._state==="canceled"||this._finishRequested)break;if(vt.timestamp>=this._endTimestamp){if(this._copyBoundaryPolicy==="shrink")break;{let _i=vt,_s=!1,gt=6;for(let Fa=0;Fa<gt;Fa++){let hl=await be.getNextPacket(_i,{metadataOnly:!0});if(!hl)break;if(hl.timestamp<this._endTimestamp){_s=!0;break}_i=hl}if(!_s)break}}let Ft=vt.timestamp,Re=vt.timestamp+vt.duration;if(this._copyBoundaryPolicy==="shrink"&&(Ft=Math.max(Ft,this._startTimestamp),Re=Math.min(Re,this._endTimestamp),Re=Math.max(Re,Ft)),Ft+=this._timestampOffset,Re+=this._timestampOffset,vt.type==="key"&&(Sr=!1),Sr)continue;let vi=vt.type;if(vi==="key"&&!ln.check(Ft,"key")&&(vi="delta"),!ln.digest(Ft,vi)){Sr=vt.type==="key",jt||(U._warn("Some video packets had to be dropped in order to produce correct output timestamps."),jt=!0);continue}let Ei=vt.clone({timestamp:Ft,duration:Re-Ft,sideData:C==="discard"?{}:vt.sideData,type:vi});this._reportProgress(n,Ei.timestamp+Ei.duration),await yr.add(Ei,st),this._synchronizer.shouldWait(n,Ei.timestamp)&&await this._synchronizer.wait(Ei.timestamp),await this._checkpoint(it,Ei.timestamp)}yr.close(),this._synchronizer.closeTrack(n)})}let F=null;!t.group&&!this._composable&&(F=new Pt);let B=await e.getLanguageCode(),N=await e.getName(),$=await e.getDisposition(),X=P?null:await e.getBitrate(),Z=P?null:await e.getAverageBitrate(),le=C==="keep"&&await e.canBeTransparent(),Pe=t.maximumPacketCount;if(this.output.format.requiresMaximumPacketCount&&Pe===void 0){let yr=t.frameRate??(await e.computePacketStats(eA)).averagePacketRate,it=P?this._startTimestamp:R?.timestamp??this._startTimestamp;Pe=await this._estimateMaximumPacketCount(e,it,yr)}this.output.addVideoTrack(a,{frameRate:t.frameRate,languageCode:mn(B)?B:void 0,name:N??void 0,disposition:$,rotation:u,flip:d,transformationMatrix:m??void 0,canBeTransparent:le,group:F??t.group,bitrate:X??void 0,averageBitrate:Z??void 0,maximumPacketCount:Pe,dolbyVision:t.dolbyVision,parameterSets:t.parameterSets}),this.utilizedTracks.push(e),this._outputTrackIds.push(n),this._outputOwnTrackGroups.push(F)}async _processAudioTrack(e,t,n){let i=await e.getCodec();if(!i){this.discardedTracks.push({track:e,reason:"unknown_source_codec",trackOptions:t});return}if(this.output.format.requiresMaximumPacketCount&&t.maximumPacketCount===void 0&&this._endTimestamp===1/0&&await e.isLive()){this.discardedTracks.push({track:e,reason:"unknown_maximum_packet_count",trackOptions:t});return}let a,s=await e.getNumberOfChannels(),o=await e.getSampleRate(),l=t.numberOfChannels??s,c=t.sampleRate??o,u=null,d=this.output.format.getSupportedAudioCodecs(),m=!this._copyMode||!!t.forceTranscode||!!t.quality||!!t.bitrate||l!==s||c!==o||!d.includes(i)||!!t.codec&&t.codec!==i||t.process!==void 0||t.sampleFormat!==void 0,f=null;if(!m){let w=new At(e),A=await w.getKeyPacket(this._startTimestamp,{verifyKeyPackets:!0})??await w.getFirstKeyPacket({verifyKeyPackets:!0});A&&(this._copyBoundaryPolicy==="shrink"&&A.timestamp<this._startTimestamp||this._copyBoundaryPolicy==="expand"&&A.timestamp+A.duration<=this._startTimestamp)&&(A=await w.getNextKeyPacket(A,{verifyKeyPackets:!0}));let x=await e.getPreRollDuration();if(b(x!==null),A&&this._copyBoundaryPolicy==="expand"&&x>0&&(A=await w.getKeyPacket(A.timestamp-x,{verifyKeyPackets:!0})??await w.getFirstKeyPacket({verifyKeyPackets:!0})),f=A,A)if((this._copyBoundaryPolicy==="shrink"?Math.max(A.timestamp-this._startTimestamp,0):Math.max(this._startTimestamp-A.timestamp,0))>this._copyBoundaryTolerance)m=!0;else if(this.output.format.supportsTimestampedMediaData){if(this.output.format.negativeTimestampSupport!=="full"&&A.timestamp<this._startTimestamp){let C=Math.min(this._startTimestamp-A.timestamp,this._copyTimestampShiftTolerance);A.timestamp+C>=this._startTimestamp||this.output.format.negativeTimestampSupport==="prefer-non-negative"&&this._copyMode==="forced"?this._timestampOffset=Math.max(this._timestampOffset,-this._startTimestamp+C):m=!0}}else if(this._timestampOffsetAdjusted)A.timestamp+this._timestampOffset===0||(m=!0);else{let C=me(this._startTimestamp-A.timestamp,-this._copyTimestampShiftTolerance,this._copyTimestampShiftTolerance);A.timestamp+C===this._startTimestamp?(this._timestampOffset=-this._startTimestamp+C,this._timestampOffsetAdjusted=!0):m=!0}}if(m&&this._copyMode==="forced"){this.discardedTracks.push({track:e,reason:"cannot_copy",trackOptions:t});return}if(m){if(!await e.canDecode()){let P=await e.getCodec();P!==null&&this._undecodableSourceCodecs.push(P),this.discardedTracks.push({track:e,reason:"undecodable_source_codec",trackOptions:t});return}t.codec&&(d=d.filter(P=>P===t.codec));let A=ya(t.quality,t.bitrate)??new xe("high"),x=await Do(d,{numberOfChannels:t.process&&t.processedNumberOfChannels?t.processedNumberOfChannels:l,sampleRate:t.process&&t.processedSampleRate?t.processedSampleRate:c,quality:A});if(!x.some(P=>rn.includes(P))&&d.some(P=>rn.includes(P))&&(l!==db||c!==mb)){let R=(await Do(d,{numberOfChannels:db,sampleRate:mb,quality:A})).find(F=>rn.includes(F));R&&(u=R,l=db,c=mb)}else u=x[0]??null;if(u===null){this.discardedTracks.push({track:e,reason:"no_encodable_target_codec",trackOptions:t});return}let I={codec:u,quality:A,transform:{sampleFormat:t.sampleFormat,process:t.process}};b(I.transform),l!==s&&(I.transform.numberOfChannels=l),c!==o&&(I.transform.sampleRate=c);let C=null;I.onEncodedSample=P=>{C=P.timestamp};let v=new Vo(I);a=v,this._registerTrackPump(async P=>{let R=null,F=new ds(e);for await(var It of F.samples(this._startTimestamp,this._endTimestamp)){var qn=[];try{let be=Yt(qn,It);var Z=[];try{if(this._state==="canceled"||this._finishRequested)break;let Gn=0;let st=be.numberOfFrames;be.timestamp<this._startTimestamp&&(Gn=Math.round((this._startTimestamp-be.timestamp)*be.sampleRate));be.timestamp+be.duration>this._endTimestamp&&(st=Math.round((this._endTimestamp-be.timestamp)*be.sampleRate));if(Gn>=st){be.close();continue}let ln;if(Gn>0||st<be.numberOfFrames){let jt=be.trim(Gn,st);if(be.close(),ln=jt,jt.numberOfFrames===0){jt.close();continue}}else ln=be;let Sr=Yt(Z,ln);Sr.setTimestamp(Sr.timestamp+this._timestampOffset);R===null&&(R=this.output.format.supportsTimestampedMediaData?0:Math.round(Sr.timestamp*o));if(R>0){var B=[];try{let jt=dr(be.format);let vt=new Uint8Array(jt*R*s);(be.format==="u8"||be.format==="u8-planar")&&vt.fill(2**7);let Ft=Yt(B,new Je({data:vt,format:be.format,numberOfChannels:s,sampleRate:o,timestamp:0}));await this._registerAudioSample(P,Ft,v,n,()=>C);R=0}catch(N){var $=N,X=!0}finally{Zt(B,$,X)}}await this._registerAudioSample(P,Sr,v,n,()=>C)}catch(le){var Pe=le,Fe=!0}finally{Zt(Z,Pe,Fe)}}catch(Dp){var yr=Dp,it=!0}finally{Zt(qn,yr,it)}}v.close(),this._synchronizer.closeTrack(n)})}else{let w=new mi(i);a=w,this._registerTrackPump(async A=>{let x=new At(e),C={decoderConfig:await e.getDecoderConfig()??void 0},v=new Ho,P=!1,R=!1;if(f)for await(let F of x.packets(f)){if(this._state==="canceled"||this._finishRequested||F.timestamp>=this._endTimestamp||this._copyBoundaryPolicy==="shrink"&&F.timestamp+F.duration>this._endTimestamp)break;let B=F.timestamp+this._timestampOffset;if(F.type==="key"&&(P=!1),P)continue;if(!v.digest(B,F.type)){P=F.type==="key",R||(U._warn("Some audio packets had to be dropped in order to produce correct output timestamps."),R=!0);continue}let N=F.clone({timestamp:B,duration:F.duration});this._reportProgress(n,N.timestamp+N.duration),await w.add(N,C),this._synchronizer.shouldWait(n,N.timestamp)&&await this._synchronizer.wait(N.timestamp),await this._checkpoint(A,N.timestamp)}w.close(),this._synchronizer.closeTrack(n)})}let p=null;!t.group&&!this._composable&&(p=new Pt);let g=await e.getLanguageCode(),h=await e.getName(),y=await e.getDisposition(),S=m?null:await e.getBitrate(),k=m?null:await e.getAverageBitrate(),T=t.maximumPacketCount;if(this.output.format.requiresMaximumPacketCount&&T===void 0){let w;m?(b(u),w=c/_w(u,c)):w=(await e.computePacketStats(eA)).averagePacketRate;let A=m?this._startTimestamp:f?.timestamp??this._startTimestamp;T=await this._estimateMaximumPacketCount(e,A,w)}this.output.addAudioTrack(a,{languageCode:mn(g)?g:void 0,name:h??void 0,disposition:y,group:p??t.group,bitrate:S??void 0,averageBitrate:k??void 0,maximumPacketCount:T}),this.utilizedTracks.push(e),this._outputTrackIds.push(n),this._outputOwnTrackGroups.push(p)}async _estimateMaximumPacketCount(e,t,n){let i=Math.min(await this._getTrackDuration(e),this._endTimestamp),a=Math.max(i-t,0);return Math.ceil(1.5*n*a)+64}_getTrackDuration(e){let t=this._trackDurations.get(e);return t||(t=(async()=>await e.isLive()?1/0:await e.getDurationFromMetadata()??await e.computeDuration())(),this._trackDurations.set(e,t)),t}async _processSubtitleTrack(e,t,n){let i=await e.getCodec();if(!i){this.discardedTracks.push({track:e,reason:"unknown_source_codec",trackOptions:t});return}let a=this.output.format.getSupportedSubtitleCodecs(),s;if(t.codec?s=a.includes(t.codec)?t.codec:null:s=a.includes(i)?i:a[0]??null,!s){this.discardedTracks.push({track:e,reason:"unsupported_subtitle_codec",trackOptions:t});return}let o=s===i?await e.getConfig():null,l=new fi(s);this._registerTrackPump(async f=>{let p=new Uo(e),g={config:o??{description:""}};for await(let h of p.cues(this._startTimestamp,this._endTimestamp)){if(this._state==="canceled"||this._finishRequested)break;let y=Math.max(h.timestamp,this._startTimestamp),S=Math.min(h.timestamp+h.duration,this._endTimestamp),k={...h,timestamp:y+this._timestampOffset,duration:Math.max(S-y,0)};this._reportProgress(n,k.timestamp+k.duration),await l.add(k,g),g=void 0,this._synchronizer.shouldWait(n,k.timestamp)&&await this._synchronizer.wait(k.timestamp),await this._checkpoint(f,k.timestamp)}l.close(),this._synchronizer.closeTrack(n)});let c=null;!t.group&&!this._composable&&(c=new Pt);let u=await e.getLanguageCode(),d=await e.getName(),m=await e.getDisposition();this.output.addSubtitleTrack(l,{languageCode:mn(u)?u:void 0,name:d??void 0,disposition:m,group:c??t.group}),this.utilizedTracks.push(e),this._outputTrackIds.push(n),this._outputOwnTrackGroups.push(c)}async _registerAudioSample(e,t,n,i,a){this._reportProgress(i,t.timestamp+t.duration),await n.add(t),t.close();let s=a();s!==null&&(this._synchronizer.shouldWait(i,s)&&await this._synchronizer.wait(s),await this._checkpoint(e,s))}_registerTrackPump(e){let t={done:!1,resolvers:pe(),wake:null,start:()=>{e(t).then(()=>{t.done=!0,t.resolvers.resolve()},n=>{t.resolvers.reject(n)})}};this._trackPumps.push(t)}async _checkpoint(e,t){for(;this._state!=="canceled"&&!this._finishRequested&&(t>=this._executionUntil||this._pauseRequested);){e.resolvers.resolve();let{promise:n,resolve:i}=pe();e.wake=i,await n}}_reportProgress(e,t){if(!this._computeProgress)return;b(this._totalDuration!==null),this._maxTimestamps.set(e,Math.max(t,this._maxTimestamps.get(e)));let n=Math.min(...this._maxTimestamps.values()),i=me(n/this._totalDuration,0,1);i!==this._lastProgress&&(this._lastProgress=i,this.onProgress?.(i,n))}},il=class extends Error{constructor(e="Conversion has been canceled."){super(e),this.name="ConversionCanceledError"}},tA=1,fb=class{constructor(e){this.maxTimestamps=new Map;this.resolvers=[];this.conversion=e}declareTrack(e){this.maxTimestamps.set(e,-1/0)}shouldWait(e,t){let n=this.maxTimestamps.get(e);b(n!==void 0),this.maxTimestamps.set(e,Math.max(t,n));let i=this.computeMinAndMaybeResolve();return this.conversion._state==="canceled"||this.conversion._pauseRequested||t>=this.conversion._executionUntil?!1:t-i>tA}wait(e){let{promise:t,resolve:n}=pe();return this.resolvers.push({timestamp:e,resolve:n}),t}closeTrack(e){this.maxTimestamps.delete(e),this.computeMinAndMaybeResolve()}resolveAll(){for(let e of this.resolvers)e.resolve();this.resolvers.length=0}computeMinAndMaybeResolve(){let e=1/0;for(let[,t]of this.maxTimestamps)e=Math.min(e,t);for(let t=0;t<this.resolvers.length;t++){let n=this.resolvers[t];n.timestamp-e<tA&&(n.resolve(),this.resolvers.splice(t,1),t--)}return e}};var rA=async r=>{if(!r||typeof r!="object")throw new TypeError("options must be an object.");if(!(r.track instanceof _r))throw new TypeError("options.track must be an InputVideoTrack.");if(!Array.isArray(r.rungs)||r.rungs.length===0)throw new TypeError("options.rungs must be a non-empty array.");if(r.keyFrameInterval!==void 0&&(!Number.isFinite(r.keyFrameInterval)||r.keyFrameInterval<0))throw new TypeError("options.keyFrameInterval, when provided, must be a non-negative number.");if(r.signal!==void 0&&!(r.signal instanceof AbortSignal))throw new TypeError("options.signal, when provided, must be an AbortSignal.");let e=r.keyFrameInterval??2,t=r.rungs.map((i,a)=>{if(!i||typeof i!="object")throw new TypeError(`options.rungs[${a}] must be an object.`);if(!(i.output instanceof pr))throw new TypeError(`options.rungs[${a}].output must be an Output.`);if(!i.video||typeof i.video!="object")throw new TypeError(`options.rungs[${a}].video must be an object.`);if(i.video.keyFrameInterval!==void 0)throw new H(`options.rungs[${a}].video.keyFrameInterval must not be set; the ladder owns the key frame interval so that every rendition shares it. Set options.keyFrameInterval instead.`);let s=new di({...i.video,keyFrameInterval:e,latencyMode:"quality"});return i.output.addVideoTrack(s,i.metadata),{output:i.output,source:s}}),n=()=>Promise.allSettled(t.map(i=>i.output.cancel()));if(r.signal?.aborted)throw r.signal.reason;try{await Promise.all(t.map(a=>a.output.start()));let i=new On(r.track);for await(let a of i.samples()){if(r.signal?.aborted)throw a.close(),await n(),r.signal.reason;let s=t.map(()=>a.clone());a.close(),await Promise.all(t.map(async(o,l)=>{let c=s[l];try{await o.source.add(c)}finally{c.close()}}))}await Promise.all(t.map(a=>a.output.finalize()))}catch(i){throw await n(),i}};var ke=class{constructor(e){this.fields=0;this.result=`${e}:`}addString(e,t){return this.nextField(),this.result+=`${e}=${t}`,this}addQuotedString(e,t){if(/[\r\n"]/.test(t))throw new H(`${e} cannot hold a line break or a double quote; got ${JSON.stringify(t)}.`);return this.nextField(),this.result+=`${e}="${t}"`,this}addNumber(e,t){return this.nextField(),this.result+=`${e}=${t}`,this}addFloat(e,t){return this.nextField(),this.result+=`${e}=${t.toFixed(3)}`,this}addNumberPair(e,t,n,i){return this.nextField(),this.result+=`${e}=${t}${n}${i}`,this}addQuotedNumberPair(e,t,n,i){return this.nextField(),this.result+=`${e}="${t}${n}${i}"`,this}toString(){return this.result}nextField(){this.fields++>0&&(this.result+=",")}};var nA=!0,pb=r=>r.toFixed(3),Si=class{constructor(e){this.type="extInf";this.fileName=e.fileName,this.startTime=e.startTime,this.durationSeconds=e.durationSeconds,this.useByteRange=e.useByteRange,this.startByteOffset=e.startByteOffset,this.segmentFileSize=e.segmentFileSize,this.previousSegmentEndOffset=e.previousSegmentEndOffset}getStartTime(){return this.startTime}getDurationSeconds(){return this.durationSeconds}setDurationSeconds(e){this.durationSeconds=e}toString(){let e=`#EXTINF:${pb(this.durationSeconds)},`;return this.useByteRange&&(e+=`
95
95
  #EXT-X-BYTERANGE:${this.segmentFileSize}`,this.previousSegmentEndOffset+1!==this.startByteOffset&&(e+=`@${this.startByteOffset}`)),e+=`
96
- ${this.fileName}`,e}},hr=class{constructor(e,t,n,i,a,s){this.method=e;this.url=t;this.keyId=n;this.iv=i;this.keyFormat=a;this.keyFormatVersions=s;this.type="extKey"}toString(e="#EXT-X-KEY"){let t=new ke(e);return t.addString("METHOD",this.method),t.addQuotedString("URI",this.url),this.keyId&&t.addString("KEYID",this.keyId),this.iv&&t.addString("IV",this.iv),this.keyFormatVersions&&t.addQuotedString("KEYFORMATVERSIONS",this.keyFormatVersions),this.keyFormat&&t.addQuotedString("KEYFORMAT",this.keyFormat),t.toString()}},Fr=class{constructor(){this.type="extDiscontinuity"}toString(){return"#EXT-X-DISCONTINUITY"}},al=class{constructor(){this.type="placementOpportunity"}toString(){return"#EXT-X-PLACEMENT-OPPORTUNITY"}},gu=r=>r.toString().padStart(2,"0"),IR=r=>r.toString().padStart(3,"0"),vR=r=>r.toString().padStart(4,"0"),Ma=class{constructor(e){this.programTimeMs=e;this.type="programDateTime"}toString(){let e=new Date(this.programTimeMs),t=vR(e.getUTCFullYear()),n=gu(e.getUTCMonth()+1),i=gu(e.getUTCDate()),a=gu(e.getUTCHours()),s=gu(e.getUTCMinutes()),o=gu(e.getUTCSeconds()),l=e.getUTCMilliseconds()%1e3;return l<0&&(l+=1e3),`#EXT-X-PROGRAM-DATE-TIME:${t}-${n}-${i}T${a}:${s}:${o}.${IR(l)}Z`}};var Yf=r=>{let e=1,t=n=>{n>e&&(e=n)};if(r.kind==="master"){for(let n of r.media)n.instreamId!==null&&(n.instreamId.startsWith("SERVICE")&&t(7),n.type!=="CLOSED-CAPTIONS"&&t(13));for(let n of r.sessionKeys)t(iA(n));return e}r.iFramesOnly&&t(4);for(let n of r.segments){nA&&t(3),n.byteRange!==null&&t(4),n.map!==null&&t(r.iFramesOnly?5:6);for(let i of n.keys)t(iA(i))}return r.skip!==null&&t(r.skip.recentlyRemovedDateRanges!==null?10:9),e},iA=r=>r.method==="SAMPLE-AES"||r.keyFormat!=="identity"||r.keyFormatVersions.length>0?5:r.iv!==null?2:1;var aA=r=>({watermarkingVariant:r.watermarkingVariant??null,uri:r.uri,bandwidth:r.bandwidth,averageBandwidth:r.averageBandwidth??null,codecs:r.codecs??null,supplementalCodecs:r.supplementalCodecs??null,score:r.score??null,stableVariantId:r.stableVariantId??null,pathwayId:r.pathwayId??null,allowedCpc:r.allowedCpc??null,reqVideoLayout:r.reqVideoLayout??null,resolution:r.resolution??null,frameRate:r.frameRate??null,videoRange:r.videoRange??null,hdcpLevel:r.hdcpLevel??null,audioGroup:r.audioGroup??null,videoGroup:r.videoGroup??null,subtitlesGroup:r.subtitlesGroup??null,closedCaptionsGroup:r.closedCaptionsGroup??null,name:r.name??null,channels:r.channels??null,lineNumber:0}),sA=r=>({watermarkingVariant:r.watermarkingVariant??null,type:r.type,groupId:r.groupId,name:r.name,language:r.language??null,assocLanguage:r.assocLanguage??null,uri:r.uri??null,default:r.default??null,autoselect:r.autoselect??null,forced:r.forced??null,channels:r.channels??null,characteristics:r.characteristics??null,stableRenditionId:r.stableRenditionId??null,bitDepth:r.bitDepth??null,sampleRate:r.sampleRate??null,resolution:r.resolution??null,lineNumber:0,instreamId:r.instreamId??null}),oA=r=>({uri:r.uri,unknownTags:r.unknownTags??[],duration:r.duration,title:r.title??null,tiles:r.tiles??null,byteRange:r.byteRange??null,programDateTime:r.programDateTime??null,map:typeof r.map=="string"?{uri:r.map,byteRange:null}:r.map??null,keys:r.keys??[],discontinuityBefore:r.discontinuityBefore??!1,discontinuitiesBefore:r.discontinuitiesBefore??(r.discontinuityBefore?1:0),parts:r.parts??[],gap:r.gap??!1,bitrate:r.bitrate??null}),lA=r=>({uri:r.uri,duration:r.duration,byteRange:r.byteRange??null,independent:r.independent??!1,gap:r.gap??!1}),cA=r=>({kind:"master",unknownTags:r.unknownTags??[],notes:[],version:r.version??null,independentSegments:r.independentSegments??!1,variants:r.variants,iFrameStreams:r.iFrameStreams??[],imageStreams:r.imageStreams??[],media:r.media??[],sessionKeys:r.sessionKeys??[],sessionData:r.sessionData??[],start:r.start??null,contentSteering:r.contentSteering??null}),uA=r=>({kind:"media",unknownTags:r.unknownTags??[],notes:[],wmPaceInfoUri:r.wmPaceInfoUri??null,version:r.segments.some(e=>e.parts.length>0)||(r.trailingParts?.length??0)>0?Math.max(r.version??0,9):r.version??null,targetDuration:r.targetDuration,mediaSequence:r.mediaSequence??0,discontinuitySequence:r.discontinuitySequence??0,playlistType:r.playlistType??null,iFramesOnly:r.iFramesOnly??!1,imagesOnly:r.imagesOnly??!1,endlist:r.endlist??!1,independentSegments:r.independentSegments??!1,segments:r.segments,partTarget:r.partTarget??null,serverControl:r.serverControl?{canBlockReload:r.serverControl.canBlockReload??!1,partHoldBack:r.serverControl.partHoldBack??null,holdBack:r.serverControl.holdBack??null,canSkipUntil:r.serverControl.canSkipUntil??null,canSkipDateRanges:r.serverControl.canSkipDateRanges??!1}:null,trailingParts:r.trailingParts??[],preloadHints:(r.preloadHints??[]).map(e=>({type:e.type,uri:e.uri,byteRangeStart:e.byteRangeStart??null,byteRangeLength:e.byteRangeLength??null})),start:r.start??null,dateRanges:r.dateRanges??[],skip:r.skip??null,renditionReports:r.renditionReports??[]}),dA=r=>({method:r.method,uri:r.uri??null,iv:r.iv??null,keyId:r.keyId??null,keyFormat:r.keyFormat??"identity",keyFormatVersions:r.keyFormatVersions??[]}),mA=r=>({uri:r.uri,byteRange:r.byteRange??null}),fA=r=>({timeOffset:r.timeOffset,precise:r.precise??null}),pA=r=>({dataId:r.dataId,value:r.value??null,uri:r.uri??null,format:r.format??null,language:r.language??null}),hA=r=>({serverUri:r.serverUri,pathwayId:r.pathwayId??null}),gA=r=>({skippedSegments:r.skippedSegments,recentlyRemovedDateRanges:r.recentlyRemovedDateRanges??null}),bA=r=>({uri:r.uri,lastMsn:r.lastMsn??null,lastPart:r.lastPart??null}),yA=r=>({type:r.type,uri:r.uri,byteRangeStart:r.byteRangeStart??null,byteRangeLength:r.byteRangeLength??null}),SA=r=>({id:r.id,startDate:r.startDate,className:r.className??null,cue:r.cue??null,endDate:r.endDate??null,duration:r.duration??null,plannedDuration:r.plannedDuration??null,endOnNext:r.endOnNext??!1,scte35Cmd:r.scte35Cmd??null,scte35Out:r.scte35Out??null,scte35In:r.scte35In??null,clientAttributes:r.clientAttributes??{}}),TA=r=>({uri:r.uri,bandwidth:r.bandwidth,averageBandwidth:r.averageBandwidth??null,codecs:r.codecs??null,resolution:r.resolution??null,name:r.name??null,videoGroup:r.videoGroup??null,supplementalCodecs:r.supplementalCodecs??null,score:r.score??null,stableVariantId:r.stableVariantId??null,videoRange:r.videoRange??null,hdcpLevel:r.hdcpLevel??null,allowedCpc:r.allowedCpc??null,reqVideoLayout:r.reqVideoLayout??null,pathwayId:r.pathwayId??null,lineNumber:0}),wA=r=>({uri:r.uri,bandwidth:r.bandwidth,codecs:r.codecs??null,resolution:r.resolution??null,videoGroup:r.videoGroup??null,lineNumber:r.lineNumber??-1}),kA=r=>({resolution:r.resolution,layout:r.layout,duration:r.duration});var AA=r=>/^\d+$/.test(r)?Number(r):null,xA=(r,e)=>{if(r===void 0)return e===void 0?null:"invalid";let t=AA(r);if(t===null)return"invalid";if(e===void 0)return{msn:t,part:null};let n=AA(e);return n===null?"invalid":{msn:t,part:n}},PA=(r,e,t)=>{let n=da(r);if(n.kind==="master")throw new TypeError("hlsReloadState needs a media playlist, but the text parses as a master playlist.");let{msn:i,part:a}=e,s=n.mediaSequence+n.segments.length-1,o=n.trailingParts.length,l=n.partTarget??1,c=l<1?3/l:3;if(i>s+2||i===s+1&&a!==null&&a-(o-1)>c)return"too-far";let u=a!==null&&a>=t,d=u?i+1:i,m=u?0:a;return d<=s||d===s+1&&m!==null&&m<o?"ready":"wait"},CA=r=>{let e=3*Math.max(1,Math.ceil(Math.max(...r)));return(t,n)=>n-t<=e};var hb=r=>r===null?null:r.offset===null?`${r.length}`:`${r.length}@${r.offset}`,ER=(r,e)=>r.length===e.length&&r.every((t,n)=>{let i=e[n];return t.method===i.method&&t.uri===i.uri&&t.iv===i.iv&&t.keyFormat===i.keyFormat&&t.keyFormatVersions.length===i.keyFormatVersions.length&&t.keyFormatVersions.every((a,s)=>a===i.keyFormatVersions[s])}),_R=(r,e)=>r===e?!0:r===null||e===null?!1:r.uri===e.uri&&(r.byteRange?.length??null)===(e.byteRange?.length??null)&&(r.byteRange?.offset??null)===(e.byteRange?.offset??null),RR=r=>{let e=new ke("#EXT-X-MEDIA");return e.addString("TYPE",r.type),e.addQuotedString("GROUP-ID",r.groupId),e.addQuotedString("NAME",r.name),r.language&&e.addQuotedString("LANGUAGE",r.language),r.assocLanguage&&e.addQuotedString("ASSOC-LANGUAGE",r.assocLanguage),r.uri&&e.addQuotedString("URI",r.uri),r.default!==null&&e.addString("DEFAULT",r.default?"YES":"NO"),r.autoselect!==null&&e.addString("AUTOSELECT",r.autoselect?"YES":"NO"),r.forced!==null&&e.addString("FORCED",r.forced?"YES":"NO"),r.channels&&e.addQuotedString("CHANNELS",r.channels),r.characteristics&&e.addQuotedString("CHARACTERISTICS",r.characteristics),r.stableRenditionId&&e.addQuotedString("STABLE-RENDITION-ID",r.stableRenditionId),r.instreamId&&e.addQuotedString("INSTREAM-ID",r.instreamId),r.bitDepth!==null&&e.addNumber("BIT-DEPTH",r.bitDepth),r.sampleRate!==null&&e.addNumber("SAMPLE-RATE",r.sampleRate),r.resolution&&e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),r.watermarkingVariant&&e.addQuotedString("WATERMARKING-VARIANT",r.watermarkingVariant),e},MR=r=>{let e=new ke("#EXT-X-STREAM-INF");return e.addNumber("BANDWIDTH",r.bandwidth),r.averageBandwidth!==null&&e.addNumber("AVERAGE-BANDWIDTH",r.averageBandwidth),r.codecs&&e.addQuotedString("CODECS",r.codecs),r.supplementalCodecs&&e.addQuotedString("SUPPLEMENTAL-CODECS",r.supplementalCodecs),r.score!==null&&e.addFloat("SCORE",r.score),r.resolution&&e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),r.frameRate!==null&&e.addFloat("FRAME-RATE",r.frameRate),r.videoRange&&e.addString("VIDEO-RANGE",r.videoRange),r.hdcpLevel&&e.addString("HDCP-LEVEL",r.hdcpLevel),r.audioGroup&&e.addQuotedString("AUDIO",r.audioGroup),r.videoGroup&&e.addQuotedString("VIDEO",r.videoGroup),r.subtitlesGroup&&e.addQuotedString("SUBTITLES",r.subtitlesGroup),r.closedCaptionsGroup==="NONE"?e.addString("CLOSED-CAPTIONS","NONE"):r.closedCaptionsGroup&&e.addQuotedString("CLOSED-CAPTIONS",r.closedCaptionsGroup),r.name&&e.addQuotedString("NAME",r.name),r.channels&&e.addQuotedString("CHANNELS",r.channels),r.stableVariantId&&e.addQuotedString("STABLE-VARIANT-ID",r.stableVariantId),r.pathwayId&&e.addQuotedString("PATHWAY-ID",r.pathwayId),r.allowedCpc&&e.addQuotedString("ALLOWED-CPC",r.allowedCpc),r.reqVideoLayout&&e.addQuotedString("REQ-VIDEO-LAYOUT",r.reqVideoLayout),r.watermarkingVariant&&e.addQuotedString("WATERMARKING-VARIANT",r.watermarkingVariant),e},DR=r=>{let e=new ke("#EXT-X-IMAGE-STREAM-INF");return e.addNumber("BANDWIDTH",r.bandwidth),r.codecs&&e.addQuotedString("CODECS",r.codecs),r.resolution&&e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),r.videoGroup&&e.addQuotedString("VIDEO",r.videoGroup),e.addQuotedString("URI",r.uri),e},BR=r=>{let e=new ke("#EXT-X-TILES");return e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),e.addNumberPair("LAYOUT",r.layout.columns,"x",r.layout.rows),e.addFloat("DURATION",r.duration),e},FR=r=>{let e=new ke("#EXT-X-I-FRAME-STREAM-INF");return e.addNumber("BANDWIDTH",r.bandwidth),r.averageBandwidth!==null&&e.addNumber("AVERAGE-BANDWIDTH",r.averageBandwidth),r.codecs&&e.addQuotedString("CODECS",r.codecs),r.supplementalCodecs&&e.addQuotedString("SUPPLEMENTAL-CODECS",r.supplementalCodecs),r.score!==null&&e.addFloat("SCORE",r.score),r.resolution&&e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),r.videoRange&&e.addString("VIDEO-RANGE",r.videoRange),r.hdcpLevel&&e.addString("HDCP-LEVEL",r.hdcpLevel),r.allowedCpc&&e.addQuotedString("ALLOWED-CPC",r.allowedCpc),r.reqVideoLayout&&e.addQuotedString("REQ-VIDEO-LAYOUT",r.reqVideoLayout),r.videoGroup&&e.addQuotedString("VIDEO",r.videoGroup),r.stableVariantId&&e.addQuotedString("STABLE-VARIANT-ID",r.stableVariantId),r.pathwayId&&e.addQuotedString("PATHWAY-ID",r.pathwayId),e.addQuotedString("URI",r.uri),e},OR=r=>new hr(r.method,r.uri??"",r.keyId??"",r.iv??"",r.keyFormat==="identity"?"":r.keyFormat,r.keyFormatVersions.join("/")).toString(),UR=r=>{let e=new ke("#EXT-X-MAP");e.addQuotedString("URI",r.uri);let t=hb(r.byteRange);return t!==null&&e.addQuotedString("BYTERANGE",t),e},IA=r=>{let e=new ke("#EXT-X-PART");e.addFloat("DURATION",r.duration),e.addQuotedString("URI",r.uri);let t=hb(r.byteRange);return t!==null&&e.addQuotedString("BYTERANGE",t),r.independent&&e.addString("INDEPENDENT","YES"),r.gap&&e.addString("GAP","YES"),e.toString()},NR=r=>{let e=new ke("#EXT-X-SERVER-CONTROL");return r.canBlockReload&&e.addString("CAN-BLOCK-RELOAD","YES"),r.canSkipUntil!==null&&e.addFloat("CAN-SKIP-UNTIL",r.canSkipUntil),r.canSkipDateRanges&&e.addString("CAN-SKIP-DATERANGES","YES"),r.holdBack!==null&&e.addFloat("HOLD-BACK",r.holdBack),r.partHoldBack!==null&&e.addFloat("PART-HOLD-BACK",r.partHoldBack),e.toString()},LR=r=>{let e=new ke("#EXT-X-PRELOAD-HINT");return e.addString("TYPE",r.type),e.addQuotedString("URI",r.uri),r.byteRangeStart!==null&&e.addNumber("BYTERANGE-START",r.byteRangeStart),r.byteRangeLength!==null&&e.addNumber("BYTERANGE-LENGTH",r.byteRangeLength),e.toString()},vA=r=>{let e=new ke("#EXT-X-START");return e.addFloat("TIME-OFFSET",r.timeOffset),r.precise!==null&&e.addString("PRECISE",r.precise?"YES":"NO"),e},VR=r=>{let e=new ke("#EXT-X-SESSION-KEY");return e.addString("METHOD",r.method),r.uri&&e.addQuotedString("URI",r.uri),r.iv&&e.addString("IV",r.iv),r.keyId&&e.addString("KEYID",r.keyId),r.keyFormat!=="identity"&&e.addQuotedString("KEYFORMAT",r.keyFormat),r.keyFormatVersions.length>0&&e.addQuotedString("KEYFORMATVERSIONS",r.keyFormatVersions.join("/")),e},zR=r=>{let e=new ke("#EXT-X-SESSION-DATA");return e.addQuotedString("DATA-ID",r.dataId),r.value!==null&&e.addQuotedString("VALUE",r.value),r.uri!==null&&e.addQuotedString("URI",r.uri),r.format!==null&&e.addString("FORMAT",r.format),r.language!==null&&e.addQuotedString("LANGUAGE",r.language),e},HR=r=>{let e=new ke("#EXT-X-CONTENT-STEERING");return e.addQuotedString("SERVER-URI",r.serverUri),r.pathwayId!==null&&e.addQuotedString("PATHWAY-ID",r.pathwayId),e},WR=r=>{let e=new ke("#EXT-X-DATERANGE");e.addQuotedString("ID",r.id),r.className!==null&&e.addQuotedString("CLASS",r.className),e.addQuotedString("START-DATE",r.startDate),r.cue!==null&&e.addString("CUE",r.cue),r.endDate!==null&&e.addQuotedString("END-DATE",r.endDate),r.duration!==null&&e.addFloat("DURATION",r.duration),r.plannedDuration!==null&&e.addFloat("PLANNED-DURATION",r.plannedDuration),r.endOnNext&&e.addString("END-ON-NEXT","YES");let t=[["SCTE35-CMD",r.scte35Cmd],["SCTE35-OUT",r.scte35Out],["SCTE35-IN",r.scte35In]];for(let[n,i]of t)i!==null&&e.addString(n,i);for(let[n,i]of Object.entries(r.clientAttributes))i.type==="string"?e.addQuotedString(n,i.value):i.type==="hex"?e.addString(n,i.value):e.addFloat(n,i.value);return e},qR=r=>{let e=new ke("#EXT-X-SKIP");return e.addNumber("SKIPPED-SEGMENTS",r.skippedSegments),r.recentlyRemovedDateRanges!==null&&e.addQuotedString("RECENTLY-REMOVED-DATERANGES",r.recentlyRemovedDateRanges.join(" ")),e.toString()},GR=r=>{let e=new ke("#EXT-X-RENDITION-REPORT");return e.addQuotedString("URI",r.uri),r.lastMsn!==null&&e.addNumber("LAST-MSN",r.lastMsn),r.lastPart!==null&&e.addNumber("LAST-PART",r.lastPart),e.toString()},EA=r=>{let e=Yf(r);if(r.version===null)return e>1?e:null;if(r.version<e)throw new H(`This playlist states EXT-X-VERSION ${r.version} but its content requires ${e}. Raise the version, or drop the feature that needs it.`);return r.version},$R=r=>{let e=["#EXTM3U"],t=EA(r);t!==null&&e.push(`#EXT-X-VERSION:${t}`),e.push(...r.unknownTags),r.independentSegments&&e.push("#EXT-X-INDEPENDENT-SEGMENTS"),r.start&&e.push(vA(r.start).toString());for(let n of r.sessionKeys)e.push(VR(n).toString());for(let n of r.sessionData)e.push(zR(n).toString());r.contentSteering&&e.push(HR(r.contentSteering).toString());for(let n of r.media)e.push(RR(n).toString());for(let n of r.variants)e.push(MR(n).toString(),n.uri);for(let n of r.imageStreams)e.push(DR(n).toString());for(let n of r.iFrameStreams)e.push(FR(n).toString());return`${e.join(`
96
+ ${this.fileName}`,e}},hr=class{constructor(e,t,n,i,a,s){this.method=e;this.url=t;this.keyId=n;this.iv=i;this.keyFormat=a;this.keyFormatVersions=s;this.type="extKey"}toString(e="#EXT-X-KEY"){let t=new ke(e);return t.addString("METHOD",this.method),t.addQuotedString("URI",this.url),this.keyId&&t.addString("KEYID",this.keyId),this.iv&&t.addString("IV",this.iv),this.keyFormatVersions&&t.addQuotedString("KEYFORMATVERSIONS",this.keyFormatVersions),this.keyFormat&&t.addQuotedString("KEYFORMAT",this.keyFormat),t.toString()}},Fr=class{constructor(){this.type="extDiscontinuity"}toString(){return"#EXT-X-DISCONTINUITY"}},al=class{constructor(){this.type="placementOpportunity"}toString(){return"#EXT-X-PLACEMENT-OPPORTUNITY"}},gu=r=>r.toString().padStart(2,"0"),IR=r=>r.toString().padStart(3,"0"),vR=r=>r.toString().padStart(4,"0"),Ma=class{constructor(e){this.programTimeMs=e;this.type="programDateTime"}toString(){let e=new Date(this.programTimeMs),t=vR(e.getUTCFullYear()),n=gu(e.getUTCMonth()+1),i=gu(e.getUTCDate()),a=gu(e.getUTCHours()),s=gu(e.getUTCMinutes()),o=gu(e.getUTCSeconds()),l=e.getUTCMilliseconds()%1e3;return l<0&&(l+=1e3),`#EXT-X-PROGRAM-DATE-TIME:${t}-${n}-${i}T${a}:${s}:${o}.${IR(l)}Z`}};var Yf=r=>{let e=1,t=n=>{n>e&&(e=n)};if(r.kind==="master"){for(let n of r.media)n.instreamId!==null&&(n.instreamId.startsWith("SERVICE")&&t(7),n.type!=="CLOSED-CAPTIONS"&&t(13));for(let n of r.sessionKeys)t(iA(n));return e}r.iFramesOnly&&t(4);for(let n of r.segments){nA&&t(3),n.byteRange!==null&&t(4),n.map!==null&&t(r.iFramesOnly?5:6);for(let i of n.keys)t(iA(i))}return r.skip!==null&&t(r.skip.recentlyRemovedDateRanges!==null?10:9),e},iA=r=>r.method==="SAMPLE-AES"||r.keyFormat!=="identity"||r.keyFormatVersions.length>0?5:r.iv!==null?2:1;var aA=r=>({watermarkingVariant:r.watermarkingVariant??null,uri:r.uri,bandwidth:r.bandwidth,averageBandwidth:r.averageBandwidth??null,codecs:r.codecs??null,supplementalCodecs:r.supplementalCodecs??null,score:r.score??null,stableVariantId:r.stableVariantId??null,pathwayId:r.pathwayId??null,allowedCpc:r.allowedCpc??null,reqVideoLayout:r.reqVideoLayout??null,resolution:r.resolution??null,frameRate:r.frameRate??null,videoRange:r.videoRange??null,hdcpLevel:r.hdcpLevel??null,audioGroup:r.audioGroup??null,videoGroup:r.videoGroup??null,subtitlesGroup:r.subtitlesGroup??null,closedCaptionsGroup:r.closedCaptionsGroup??null,name:r.name??null,channels:r.channels??null,lineNumber:0}),sA=r=>({watermarkingVariant:r.watermarkingVariant??null,type:r.type,groupId:r.groupId,name:r.name,language:r.language??null,assocLanguage:r.assocLanguage??null,uri:r.uri??null,default:r.default??null,autoselect:r.autoselect??null,forced:r.forced??null,channels:r.channels??null,characteristics:r.characteristics??null,stableRenditionId:r.stableRenditionId??null,bitDepth:r.bitDepth??null,sampleRate:r.sampleRate??null,resolution:r.resolution??null,lineNumber:0,instreamId:r.instreamId??null}),oA=r=>({uri:r.uri,unknownTags:r.unknownTags??[],duration:r.duration,title:r.title??null,tiles:r.tiles??null,byteRange:r.byteRange??null,programDateTime:r.programDateTime??null,map:typeof r.map=="string"?{uri:r.map,byteRange:null}:r.map??null,keys:r.keys??[],discontinuityBefore:r.discontinuityBefore??!1,discontinuitiesBefore:r.discontinuitiesBefore??(r.discontinuityBefore?1:0),parts:r.parts??[],gap:r.gap??!1,bitrate:r.bitrate??null}),lA=r=>({uri:r.uri,duration:r.duration,byteRange:r.byteRange??null,independent:r.independent??!1,gap:r.gap??!1}),cA=r=>({kind:"master",unknownTags:r.unknownTags??[],notes:[],version:r.version??null,independentSegments:r.independentSegments??!1,variants:r.variants,iFrameStreams:r.iFrameStreams??[],imageStreams:r.imageStreams??[],media:r.media??[],sessionKeys:r.sessionKeys??[],sessionData:r.sessionData??[],start:r.start??null,contentSteering:r.contentSteering??null}),uA=r=>({kind:"media",unknownTags:r.unknownTags??[],notes:[],wmPaceInfoUri:r.wmPaceInfoUri??null,version:r.segments.some(e=>e.parts.length>0)||(r.trailingParts?.length??0)>0?Math.max(r.version??0,9):r.version??null,targetDuration:r.targetDuration,mediaSequence:r.mediaSequence??0,discontinuitySequence:r.discontinuitySequence??0,playlistType:r.playlistType??null,iFramesOnly:r.iFramesOnly??!1,imagesOnly:r.imagesOnly??!1,endlist:r.endlist??!1,independentSegments:r.independentSegments??!1,segments:r.segments,partTarget:r.partTarget??null,serverControl:r.serverControl?{canBlockReload:r.serverControl.canBlockReload??!1,partHoldBack:r.serverControl.partHoldBack??null,holdBack:r.serverControl.holdBack??null,canSkipUntil:r.serverControl.canSkipUntil??null,canSkipDateRanges:r.serverControl.canSkipDateRanges??!1}:null,trailingParts:r.trailingParts??[],preloadHints:(r.preloadHints??[]).map(e=>({type:e.type,uri:e.uri,byteRangeStart:e.byteRangeStart??null,byteRangeLength:e.byteRangeLength??null})),start:r.start??null,dateRanges:r.dateRanges??[],skip:r.skip??null,renditionReports:r.renditionReports??[]}),dA=r=>({method:r.method,uri:r.uri??null,iv:r.iv??null,keyId:r.keyId??null,keyFormat:r.keyFormat??"identity",keyFormatVersions:r.keyFormatVersions??[]}),mA=r=>({uri:r.uri,byteRange:r.byteRange??null}),fA=r=>({timeOffset:r.timeOffset,precise:r.precise??null}),pA=r=>({dataId:r.dataId,value:r.value??null,uri:r.uri??null,format:r.format??null,language:r.language??null}),hA=r=>({serverUri:r.serverUri,pathwayId:r.pathwayId??null}),gA=r=>({skippedSegments:r.skippedSegments,recentlyRemovedDateRanges:r.recentlyRemovedDateRanges??null}),bA=r=>({uri:r.uri,lastMsn:r.lastMsn??null,lastPart:r.lastPart??null}),yA=r=>({type:r.type,uri:r.uri,byteRangeStart:r.byteRangeStart??null,byteRangeLength:r.byteRangeLength??null}),SA=r=>({id:r.id,startDate:r.startDate,className:r.className??null,cue:r.cue??null,endDate:r.endDate??null,duration:r.duration??null,plannedDuration:r.plannedDuration??null,endOnNext:r.endOnNext??!1,scte35Cmd:r.scte35Cmd??null,scte35Out:r.scte35Out??null,scte35In:r.scte35In??null,clientAttributes:r.clientAttributes??{}}),TA=r=>({uri:r.uri,bandwidth:r.bandwidth,averageBandwidth:r.averageBandwidth??null,codecs:r.codecs??null,resolution:r.resolution??null,name:r.name??null,videoGroup:r.videoGroup??null,supplementalCodecs:r.supplementalCodecs??null,score:r.score??null,stableVariantId:r.stableVariantId??null,videoRange:r.videoRange??null,hdcpLevel:r.hdcpLevel??null,allowedCpc:r.allowedCpc??null,reqVideoLayout:r.reqVideoLayout??null,pathwayId:r.pathwayId??null,lineNumber:0}),wA=r=>({uri:r.uri,bandwidth:r.bandwidth,codecs:r.codecs??null,resolution:r.resolution??null,videoGroup:r.videoGroup??null,lineNumber:r.lineNumber??-1}),kA=r=>({resolution:r.resolution,layout:r.layout,duration:r.duration});var AA=r=>/^\d+$/.test(r)?Number(r):null,xA=(r,e)=>{if(r===void 0)return e===void 0?null:"invalid";let t=AA(r);if(t===null)return"invalid";if(e===void 0)return{msn:t,part:null};let n=AA(e);return n===null?"invalid":{msn:t,part:n}},PA=(r,e,t)=>{let n=da(r);if(n.kind==="master")throw new TypeError("hlsReloadState needs a media playlist, but the text parses as a master playlist.");let{msn:i,part:a}=e,s=n.mediaSequence+n.segments.length-1,o=n.trailingParts.length,l=n.partTarget??1,c=l<1?3/l:3;if(i>s+2||i===s+1&&a!==null&&a-(o-1)>c)return"too-far";let u=a!==null&&a>=t,d=u?i+1:i,m=u?0:a;return d<=s||d===s+1&&m!==null&&m<o?"ready":"wait"},CA=r=>{let e=3*Math.max(1,Math.ceil(Math.max(...r)));return(t,n)=>n-t<=e};var hb=r=>r==null?null:r.offset==null?`${r.length}`:`${r.length}@${r.offset}`,ER=(r,e)=>r.length===e.length&&r.every((t,n)=>{let i=e[n];return t.method===i.method&&t.uri===i.uri&&t.iv===i.iv&&t.keyFormat===i.keyFormat&&t.keyFormatVersions.length===i.keyFormatVersions.length&&t.keyFormatVersions.every((a,s)=>a===i.keyFormatVersions[s])}),_R=(r,e)=>r===e?!0:r==null||e==null?!1:r.uri===e.uri&&(r.byteRange?.length??null)===(e.byteRange?.length??null)&&(r.byteRange?.offset??null)===(e.byteRange?.offset??null),RR=r=>{let e=new ke("#EXT-X-MEDIA");return e.addString("TYPE",r.type),e.addQuotedString("GROUP-ID",r.groupId),e.addQuotedString("NAME",r.name),r.language&&e.addQuotedString("LANGUAGE",r.language),r.assocLanguage&&e.addQuotedString("ASSOC-LANGUAGE",r.assocLanguage),r.uri&&e.addQuotedString("URI",r.uri),r.default!=null&&e.addString("DEFAULT",r.default?"YES":"NO"),r.autoselect!=null&&e.addString("AUTOSELECT",r.autoselect?"YES":"NO"),r.forced!=null&&e.addString("FORCED",r.forced?"YES":"NO"),r.channels&&e.addQuotedString("CHANNELS",r.channels),r.characteristics&&e.addQuotedString("CHARACTERISTICS",r.characteristics),r.stableRenditionId&&e.addQuotedString("STABLE-RENDITION-ID",r.stableRenditionId),r.instreamId&&e.addQuotedString("INSTREAM-ID",r.instreamId),r.bitDepth!=null&&e.addNumber("BIT-DEPTH",r.bitDepth),r.sampleRate!=null&&e.addNumber("SAMPLE-RATE",r.sampleRate),r.resolution&&e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),r.watermarkingVariant&&e.addQuotedString("WATERMARKING-VARIANT",r.watermarkingVariant),e},MR=r=>{let e=new ke("#EXT-X-STREAM-INF");return e.addNumber("BANDWIDTH",r.bandwidth),r.averageBandwidth!=null&&e.addNumber("AVERAGE-BANDWIDTH",r.averageBandwidth),r.codecs&&e.addQuotedString("CODECS",r.codecs),r.supplementalCodecs&&e.addQuotedString("SUPPLEMENTAL-CODECS",r.supplementalCodecs),r.score!=null&&e.addFloat("SCORE",r.score),r.resolution&&e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),r.frameRate!=null&&e.addFloat("FRAME-RATE",r.frameRate),r.videoRange&&e.addString("VIDEO-RANGE",r.videoRange),r.hdcpLevel&&e.addString("HDCP-LEVEL",r.hdcpLevel),r.audioGroup&&e.addQuotedString("AUDIO",r.audioGroup),r.videoGroup&&e.addQuotedString("VIDEO",r.videoGroup),r.subtitlesGroup&&e.addQuotedString("SUBTITLES",r.subtitlesGroup),r.closedCaptionsGroup==="NONE"?e.addString("CLOSED-CAPTIONS","NONE"):r.closedCaptionsGroup&&e.addQuotedString("CLOSED-CAPTIONS",r.closedCaptionsGroup),r.name&&e.addQuotedString("NAME",r.name),r.channels&&e.addQuotedString("CHANNELS",r.channels),r.stableVariantId&&e.addQuotedString("STABLE-VARIANT-ID",r.stableVariantId),r.pathwayId&&e.addQuotedString("PATHWAY-ID",r.pathwayId),r.allowedCpc&&e.addQuotedString("ALLOWED-CPC",r.allowedCpc),r.reqVideoLayout&&e.addQuotedString("REQ-VIDEO-LAYOUT",r.reqVideoLayout),r.watermarkingVariant&&e.addQuotedString("WATERMARKING-VARIANT",r.watermarkingVariant),e},DR=r=>{let e=new ke("#EXT-X-IMAGE-STREAM-INF");return e.addNumber("BANDWIDTH",r.bandwidth),r.codecs&&e.addQuotedString("CODECS",r.codecs),r.resolution&&e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),r.videoGroup&&e.addQuotedString("VIDEO",r.videoGroup),e.addQuotedString("URI",r.uri),e},BR=r=>{let e=new ke("#EXT-X-TILES");return e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),e.addNumberPair("LAYOUT",r.layout.columns,"x",r.layout.rows),e.addFloat("DURATION",r.duration),e},FR=r=>{let e=new ke("#EXT-X-I-FRAME-STREAM-INF");return e.addNumber("BANDWIDTH",r.bandwidth),r.averageBandwidth!=null&&e.addNumber("AVERAGE-BANDWIDTH",r.averageBandwidth),r.codecs&&e.addQuotedString("CODECS",r.codecs),r.supplementalCodecs&&e.addQuotedString("SUPPLEMENTAL-CODECS",r.supplementalCodecs),r.score!=null&&e.addFloat("SCORE",r.score),r.resolution&&e.addNumberPair("RESOLUTION",r.resolution.width,"x",r.resolution.height),r.videoRange&&e.addString("VIDEO-RANGE",r.videoRange),r.hdcpLevel&&e.addString("HDCP-LEVEL",r.hdcpLevel),r.allowedCpc&&e.addQuotedString("ALLOWED-CPC",r.allowedCpc),r.reqVideoLayout&&e.addQuotedString("REQ-VIDEO-LAYOUT",r.reqVideoLayout),r.videoGroup&&e.addQuotedString("VIDEO",r.videoGroup),r.stableVariantId&&e.addQuotedString("STABLE-VARIANT-ID",r.stableVariantId),r.pathwayId&&e.addQuotedString("PATHWAY-ID",r.pathwayId),e.addQuotedString("URI",r.uri),e},OR=r=>new hr(r.method,r.uri??"",r.keyId??"",r.iv??"",r.keyFormat==="identity"?"":r.keyFormat,r.keyFormatVersions.join("/")).toString(),UR=r=>{let e=new ke("#EXT-X-MAP");e.addQuotedString("URI",r.uri);let t=hb(r.byteRange);return t!=null&&e.addQuotedString("BYTERANGE",t),e},IA=r=>{let e=new ke("#EXT-X-PART");e.addFloat("DURATION",r.duration),e.addQuotedString("URI",r.uri);let t=hb(r.byteRange);return t!=null&&e.addQuotedString("BYTERANGE",t),r.independent&&e.addString("INDEPENDENT","YES"),r.gap&&e.addString("GAP","YES"),e.toString()},NR=r=>{let e=new ke("#EXT-X-SERVER-CONTROL");return r.canBlockReload&&e.addString("CAN-BLOCK-RELOAD","YES"),r.canSkipUntil!=null&&e.addFloat("CAN-SKIP-UNTIL",r.canSkipUntil),r.canSkipDateRanges&&e.addString("CAN-SKIP-DATERANGES","YES"),r.holdBack!=null&&e.addFloat("HOLD-BACK",r.holdBack),r.partHoldBack!=null&&e.addFloat("PART-HOLD-BACK",r.partHoldBack),e.toString()},LR=r=>{let e=new ke("#EXT-X-PRELOAD-HINT");return e.addString("TYPE",r.type),e.addQuotedString("URI",r.uri),r.byteRangeStart!=null&&e.addNumber("BYTERANGE-START",r.byteRangeStart),r.byteRangeLength!=null&&e.addNumber("BYTERANGE-LENGTH",r.byteRangeLength),e.toString()},vA=r=>{let e=new ke("#EXT-X-START");return e.addFloat("TIME-OFFSET",r.timeOffset),r.precise!=null&&e.addString("PRECISE",r.precise?"YES":"NO"),e},VR=r=>{let e=new ke("#EXT-X-SESSION-KEY");return e.addString("METHOD",r.method),r.uri&&e.addQuotedString("URI",r.uri),r.iv&&e.addString("IV",r.iv),r.keyId&&e.addString("KEYID",r.keyId),r.keyFormat!=="identity"&&e.addQuotedString("KEYFORMAT",r.keyFormat),r.keyFormatVersions.length>0&&e.addQuotedString("KEYFORMATVERSIONS",r.keyFormatVersions.join("/")),e},zR=r=>{let e=new ke("#EXT-X-SESSION-DATA");return e.addQuotedString("DATA-ID",r.dataId),r.value!=null&&e.addQuotedString("VALUE",r.value),r.uri!=null&&e.addQuotedString("URI",r.uri),r.format!=null&&e.addString("FORMAT",r.format),r.language!=null&&e.addQuotedString("LANGUAGE",r.language),e},HR=r=>{let e=new ke("#EXT-X-CONTENT-STEERING");return e.addQuotedString("SERVER-URI",r.serverUri),r.pathwayId!=null&&e.addQuotedString("PATHWAY-ID",r.pathwayId),e},WR=r=>{let e=new ke("#EXT-X-DATERANGE");e.addQuotedString("ID",r.id),r.className!=null&&e.addQuotedString("CLASS",r.className),e.addQuotedString("START-DATE",r.startDate),r.cue!=null&&e.addString("CUE",r.cue),r.endDate!=null&&e.addQuotedString("END-DATE",r.endDate),r.duration!=null&&e.addFloat("DURATION",r.duration),r.plannedDuration!=null&&e.addFloat("PLANNED-DURATION",r.plannedDuration),r.endOnNext&&e.addString("END-ON-NEXT","YES");let t=[["SCTE35-CMD",r.scte35Cmd],["SCTE35-OUT",r.scte35Out],["SCTE35-IN",r.scte35In]];for(let[n,i]of t)i!=null&&e.addString(n,i);for(let[n,i]of Object.entries(r.clientAttributes))i.type==="string"?e.addQuotedString(n,i.value):i.type==="hex"?e.addString(n,i.value):e.addFloat(n,i.value);return e},qR=r=>{let e=new ke("#EXT-X-SKIP");return e.addNumber("SKIPPED-SEGMENTS",r.skippedSegments),r.recentlyRemovedDateRanges!=null&&e.addQuotedString("RECENTLY-REMOVED-DATERANGES",r.recentlyRemovedDateRanges.join(" ")),e.toString()},GR=r=>{let e=new ke("#EXT-X-RENDITION-REPORT");return e.addQuotedString("URI",r.uri),r.lastMsn!=null&&e.addNumber("LAST-MSN",r.lastMsn),r.lastPart!=null&&e.addNumber("LAST-PART",r.lastPart),e.toString()},EA=r=>{let e=Yf(r);if(r.version==null)return e>1?e:null;if(r.version<e)throw new H(`This playlist states EXT-X-VERSION ${r.version} but its content requires ${e}. Raise the version, or drop the feature that needs it.`);return r.version},$R=r=>{let e=["#EXTM3U"],t=EA(r);t!=null&&e.push(`#EXT-X-VERSION:${t}`),e.push(...r.unknownTags),r.independentSegments&&e.push("#EXT-X-INDEPENDENT-SEGMENTS"),r.start&&e.push(vA(r.start).toString());for(let n of r.sessionKeys)e.push(VR(n).toString());for(let n of r.sessionData)e.push(zR(n).toString());r.contentSteering&&e.push(HR(r.contentSteering).toString());for(let n of r.media)e.push(RR(n).toString());for(let n of r.variants)e.push(MR(n).toString(),n.uri);for(let n of r.imageStreams)e.push(DR(n).toString());for(let n of r.iFrameStreams)e.push(FR(n).toString());return`${e.join(`
97
97
  `)}
98
- `},XR=(r,e)=>{let t=[];for(let i=0;i<Math.max(r.discontinuitiesBefore,Number(r.discontinuityBefore));i++)t.push(new Fr().toString());if(!ER(r.keys,e.keys)){if(r.keys.length===0)t.push(`${Ir}METHOD=NONE`);else for(let i of r.keys)t.push(OR(i));e.keys=r.keys}r.map&&!_R(r.map,e.map)&&(t.push(UR(r.map).toString()),e.map=r.map),r.programDateTime!==null&&t.push(new Ma(r.programDateTime).toString()),r.bitrate!==null&&r.bitrate!==e.bitrate&&(t.push(`${is}${r.bitrate}`),e.bitrate=r.bitrate),r.gap&&t.push(Co),t.push(...r.unknownTags),t.push(...r.parts.map(IA));let n=hb(r.byteRange);if(n!==null&&t.push(`${vr}${n}`),!Number.isFinite(r.duration)||r.duration<0)throw new H(`A segment duration must be a non-negative number; ${r.uri} states ${r.duration}.`);if(t.push(`${ur}${pb(r.duration)},${r.title??""}`),r.tiles&&t.push(BR(r.tiles).toString()),/[\r\n]/.test(r.uri))throw new H(`A segment URI cannot hold a line break; got ${JSON.stringify(r.uri)}.`);return t.push(r.uri),t},KR=r=>{let e=["#EXTM3U"],t=EA(r);t!==null&&e.push(`#EXT-X-VERSION:${t}`),r.start&&e.push(vA(r.start).toString()),r.targetDuration!==null&&e.push(`${pt}${r.targetDuration}`),r.serverControl&&e.push(NR(r.serverControl)),r.partTarget!==null&&e.push(new ke("#EXT-X-PART-INF").addFloat("PART-TARGET",r.partTarget).toString()),r.mediaSequence!==0&&e.push(`${Mn}${r.mediaSequence}`),r.discontinuitySequence!==0&&e.push(`${Bn}${r.discontinuitySequence}`),r.playlistType&&e.push(`${Fn}${r.playlistType}`),r.iFramesOnly&&e.push(ca),r.imagesOnly&&e.push(Io),r.independentSegments&&e.push("#EXT-X-INDEPENDENT-SEGMENTS"),r.wmPaceInfoUri!==null&&e.push(`${ns}"${r.wmPaceInfoUri}"`);let n={keys:[],map:null,bitrate:null};r.skip&&e.push(qR(r.skip)),e.push(...r.dateRanges.map(i=>WR(i).toString())),e.push(...r.unknownTags);for(let i of r.segments)e.push(...XR(i,n));return e.push(...r.trailingParts.map(IA),...r.preloadHints.map(LR)),e.push(...r.renditionReports.map(GR)),r.endlist&&e.push(Jr),`${e.join(`
98
+ `},XR=(r,e)=>{let t=[];for(let i=0;i<Math.max(r.discontinuitiesBefore,Number(r.discontinuityBefore));i++)t.push(new Fr().toString());if(!ER(r.keys,e.keys)){if(r.keys.length===0)t.push(`${Ir}METHOD=NONE`);else for(let i of r.keys)t.push(OR(i));e.keys=r.keys}r.map&&!_R(r.map,e.map)&&(t.push(UR(r.map).toString()),e.map=r.map),r.programDateTime!=null&&t.push(new Ma(r.programDateTime).toString()),r.bitrate!=null&&r.bitrate!==e.bitrate&&(t.push(`${is}${r.bitrate}`),e.bitrate=r.bitrate),r.gap&&t.push(Co),t.push(...r.unknownTags),t.push(...r.parts.map(IA));let n=hb(r.byteRange);if(n!=null&&t.push(`${vr}${n}`),!Number.isFinite(r.duration)||r.duration<0)throw new H(`A segment duration must be a non-negative number; ${r.uri} states ${r.duration}.`);if(t.push(`${ur}${pb(r.duration)},${r.title??""}`),r.tiles&&t.push(BR(r.tiles).toString()),/[\r\n]/.test(r.uri))throw new H(`A segment URI cannot hold a line break; got ${JSON.stringify(r.uri)}.`);return t.push(r.uri),t},KR=r=>{let e=["#EXTM3U"],t=EA(r);t!=null&&e.push(`#EXT-X-VERSION:${t}`),r.start&&e.push(vA(r.start).toString()),r.targetDuration!=null&&e.push(`${pt}${r.targetDuration}`),r.serverControl&&e.push(NR(r.serverControl)),r.partTarget!=null&&e.push(new ke("#EXT-X-PART-INF").addFloat("PART-TARGET",r.partTarget).toString()),r.mediaSequence!==0&&e.push(`${Mn}${r.mediaSequence}`),r.discontinuitySequence!==0&&e.push(`${Bn}${r.discontinuitySequence}`),r.playlistType&&e.push(`${Fn}${r.playlistType}`),r.iFramesOnly&&e.push(ca),r.imagesOnly&&e.push(Io),r.independentSegments&&e.push("#EXT-X-INDEPENDENT-SEGMENTS"),r.wmPaceInfoUri!=null&&e.push(`${ns}"${r.wmPaceInfoUri}"`);let n={keys:[],map:null,bitrate:null};r.skip&&e.push(qR(r.skip)),e.push(...r.dateRanges.map(i=>WR(i).toString())),e.push(...r.unknownTags);for(let i of r.segments)e.push(...XR(i,n));return e.push(...r.trailingParts.map(IA),...r.preloadHints.map(LR)),e.push(...r.renditionReports.map(GR)),r.endlist&&e.push(Jr),`${e.join(`
99
99
  `)}
100
100
  `},Zf=r=>r.kind==="master"?$R(r):KR(r);var BA=r=>{if(r.length===0)throw new E("concatHlsMediaPlaylists: at least one input is required");let e=0,t=[],n=[];for(let l of r){let{body:c,targetDuration:u}=_A(l.content);u!==null&&(n.push(u),u>e&&(e=u)),t.push(ZR(c,l.pathPrefix))}let{header:i}=_A(r[0].content),a=n.length>0;return{content:[YR(i,e,a),t.join(`
101
101
  `),Jr].filter(l=>l.length>0).join(`