mediabunny 1.7.0 → 1.7.2

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.
@@ -5549,8 +5549,7 @@ var Mediabunny = (() => {
5549
5549
  }
5550
5550
  this.writer.write(this.helper.subarray(0, pos));
5551
5551
  }
5552
- // Assumes the string is ASCII
5553
- writeString(str) {
5552
+ writeAsciiString(str) {
5554
5553
  this.writer.write(new Uint8Array(str.split("").map((x) => x.charCodeAt(0))));
5555
5554
  }
5556
5555
  writeEBML(data) {
@@ -5588,7 +5587,7 @@ var Mediabunny = (() => {
5588
5587
  this.writeUnsignedInt(data.data, size);
5589
5588
  } else if (typeof data.data === "string") {
5590
5589
  this.writeVarInt(data.data.length);
5591
- this.writeString(data.data);
5590
+ this.writeAsciiString(data.data);
5592
5591
  } else if (data.data instanceof Uint8Array) {
5593
5592
  this.writeVarInt(data.data.byteLength, data.size);
5594
5593
  this.writer.write(data.data);
@@ -5690,7 +5689,7 @@ var Mediabunny = (() => {
5690
5689
  this.pos += width;
5691
5690
  return value;
5692
5691
  }
5693
- readString(length) {
5692
+ readAsciiString(length) {
5694
5693
  const { view: view2, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length);
5695
5694
  this.pos += length;
5696
5695
  let strLength = 0;
@@ -9075,6 +9074,10 @@ ${cue.notes ?? ""}`;
9075
9074
  this.customDecoderCallSerializer = new CallSerializer();
9076
9075
  this.customDecoderQueueSize = 0;
9077
9076
  const sampleHandler = (sample) => {
9077
+ if (sample.numberOfFrames === 0) {
9078
+ sample.close();
9079
+ return;
9080
+ }
9078
9081
  const sampleRate = decoderConfig.sampleRate;
9079
9082
  sample.setTimestamp(Math.round(sample.timestamp * sampleRate) / sampleRate);
9080
9083
  onSample(sample);
@@ -10664,7 +10667,8 @@ ${cue.notes ?? ""}`;
10664
10667
  super(codec);
10665
10668
  }
10666
10669
  /**
10667
- * Adds an encoded packet to the output video track.
10670
+ * Adds an encoded packet to the output video track. Packets must be added in *decode order*, while a packet's
10671
+ * timestamp must be its *presentation timestamp*. B-frames are handled automatically.
10668
10672
  *
10669
10673
  * @param meta - Additional metadata from the encoder. You should pass this for the first call, including a valid
10670
10674
  * decoder config.
@@ -11101,7 +11105,7 @@ ${cue.notes ?? ""}`;
11101
11105
  super(codec);
11102
11106
  }
11103
11107
  /**
11104
- * Adds an encoded packet to the output audio track.
11108
+ * Adds an encoded packet to the output audio track. Packets must be added in *decode order*.
11105
11109
  *
11106
11110
  * @param meta - Additional metadata from the encoder. You should pass this for the first call, including a valid
11107
11111
  * decoder config.
@@ -12130,7 +12134,9 @@ ${cue.notes ?? ""}`;
12130
12134
  super();
12131
12135
  /** @internal */
12132
12136
  this._fullData = null;
12133
- this._url = url2;
12137
+ /** @internal */
12138
+ this._nextUrlVersion = null;
12139
+ this._url = url2 instanceof URL ? url2 : new URL(url2);
12134
12140
  this._options = options;
12135
12141
  }
12136
12142
  /** @internal */
@@ -12139,6 +12145,10 @@ ${cue.notes ?? ""}`;
12139
12145
  if (range) {
12140
12146
  headers["Range"] = `bytes=${range.start}-${range.end - 1}`;
12141
12147
  }
12148
+ if (this._nextUrlVersion !== null) {
12149
+ this._url.searchParams.set("mediabunny_version", this._nextUrlVersion.toString());
12150
+ this._nextUrlVersion++;
12151
+ }
12142
12152
  const response = await retriedFetch(
12143
12153
  this._url,
12144
12154
  mergeObjectsDeeply(this._options.requestInit ?? {}, {
@@ -12151,6 +12161,10 @@ ${cue.notes ?? ""}`;
12151
12161
  throw new Error(`Error fetching ${this._url}: ${response.status} ${response.statusText}`);
12152
12162
  }
12153
12163
  const buffer = await response.arrayBuffer();
12164
+ if (response.status === 206 && range && buffer.byteLength !== range.end - range.start && this._nextUrlVersion === null) {
12165
+ this._nextUrlVersion = 1;
12166
+ return this._makeRequest(range);
12167
+ }
12154
12168
  if (response.status === 200) {
12155
12169
  this._fullData = buffer;
12156
12170
  }
@@ -13247,6 +13261,9 @@ ${cue.notes ?? ""}`;
13247
13261
  const sampleIndex = this.metadataReader.readU32() - 1;
13248
13262
  track.sampleTable.keySampleIndices.push(sampleIndex);
13249
13263
  }
13264
+ if (track.sampleTable.keySampleIndices[0] !== 0) {
13265
+ track.sampleTable.keySampleIndices.unshift(0);
13266
+ }
13250
13267
  }
13251
13268
  ;
13252
13269
  break;
@@ -14642,7 +14659,7 @@ ${cue.notes ?? ""}`;
14642
14659
  switch (id) {
14643
14660
  case 17026 /* DocType */:
14644
14661
  {
14645
- this.isWebM = reader.readString(size) === "webm";
14662
+ this.isWebM = reader.readAsciiString(size) === "webm";
14646
14663
  }
14647
14664
  ;
14648
14665
  break;
@@ -14840,7 +14857,7 @@ ${cue.notes ?? ""}`;
14840
14857
  case 134 /* CodecID */:
14841
14858
  {
14842
14859
  if (!this.currentTrack) break;
14843
- this.currentTrack.codecId = reader.readString(size);
14860
+ this.currentTrack.codecId = reader.readAsciiString(size);
14844
14861
  }
14845
14862
  ;
14846
14863
  break;
@@ -14861,7 +14878,7 @@ ${cue.notes ?? ""}`;
14861
14878
  case 2274716 /* Language */:
14862
14879
  {
14863
14880
  if (!this.currentTrack) break;
14864
- this.currentTrack.languageCode = reader.readString(size);
14881
+ this.currentTrack.languageCode = reader.readAsciiString(size);
14865
14882
  if (!isIso639Dash2LanguageCode(this.currentTrack.languageCode)) {
14866
14883
  this.currentTrack.languageCode = UNDETERMINED_LANGUAGE;
14867
14884
  }
@@ -16669,7 +16686,7 @@ ${cue.notes ?? ""}`;
16669
16686
  break;
16670
16687
  case 17026 /* DocType */:
16671
16688
  {
16672
- const docType = ebmlReader.readString(size);
16689
+ const docType = ebmlReader.readAsciiString(size);
16673
16690
  if (docType !== desiredDocType) {
16674
16691
  return false;
16675
16692
  }