@mediabunny/mp3-encoder 1.11.2 → 1.12.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.
@@ -91,22 +91,22 @@ var MediabunnyMp3Encoder = (() => {
91
91
  return Math.floor(144 * bitrate / sampleRate + padding);
92
92
  }
93
93
  };
94
- var readFrameHeader = (word, reader) => {
95
- const startPos = reader.pos;
94
+ var readFrameHeader = (word, remainingBytes) => {
96
95
  const firstByte = word >>> 24;
97
96
  const secondByte = word >>> 16 & 255;
98
97
  const thirdByte = word >>> 8 & 255;
99
98
  const fourthByte = word & 255;
100
99
  if (firstByte !== 255 && secondByte !== 255 && thirdByte !== 255 && fourthByte !== 255) {
101
- reader.pos += 4;
102
- return null;
100
+ return {
101
+ header: null,
102
+ bytesAdvanced: 4
103
+ };
103
104
  }
104
- reader.pos += 1;
105
105
  if (firstByte !== 255) {
106
- return null;
106
+ return { header: null, bytesAdvanced: 1 };
107
107
  }
108
108
  if ((secondByte & 224) !== 224) {
109
- return null;
109
+ return { header: null, bytesAdvanced: 1 };
110
110
  }
111
111
  const mpegVersionId = secondByte >> 3 & 3;
112
112
  const layer = secondByte >> 1 & 3;
@@ -120,16 +120,16 @@ var MediabunnyMp3Encoder = (() => {
120
120
  const emphasis = fourthByte & 3;
121
121
  const kilobitRate = mpegVersionId === 3 ? MPEG_V1_BITRATES[layer]?.[bitrateIndex] : MPEG_V2_BITRATES[layer]?.[bitrateIndex];
122
122
  if (!kilobitRate || kilobitRate === -1) {
123
- return null;
123
+ return { header: null, bytesAdvanced: 1 };
124
124
  }
125
125
  const bitrate = kilobitRate * 1e3;
126
126
  const sampleRate = SAMPLING_RATES[mpegVersionId]?.[frequencyIndex];
127
127
  if (!sampleRate || sampleRate === -1) {
128
- return null;
128
+ return { header: null, bytesAdvanced: 1 };
129
129
  }
130
130
  const frameLength = computeMp3FrameSize(layer, bitrate, sampleRate, padding);
131
- if (reader.fileSize !== null && reader.fileSize - startPos < frameLength) {
132
- return null;
131
+ if (remainingBytes !== null && remainingBytes < frameLength) {
132
+ return { header: null, bytesAdvanced: 1 };
133
133
  }
134
134
  let audioSamplesInFrame;
135
135
  if (mpegVersionId === 3) {
@@ -144,19 +144,21 @@ var MediabunnyMp3Encoder = (() => {
144
144
  }
145
145
  }
146
146
  return {
147
- startPos,
148
- totalSize: frameLength,
149
- mpegVersionId,
150
- layer,
151
- bitrate,
152
- frequencyIndex,
153
- sampleRate,
154
- channel,
155
- modeExtension,
156
- copyright,
157
- original,
158
- emphasis,
159
- audioSamplesInFrame
147
+ header: {
148
+ totalSize: frameLength,
149
+ mpegVersionId,
150
+ layer,
151
+ bitrate,
152
+ frequencyIndex,
153
+ sampleRate,
154
+ channel,
155
+ modeExtension,
156
+ copyright,
157
+ original,
158
+ emphasis,
159
+ audioSamplesInFrame
160
+ },
161
+ bytesAdvanced: 1
160
162
  };
161
163
  };
162
164
 
@@ -286,7 +288,7 @@ var MediabunnyMp3Encoder = (() => {
286
288
  let pos = 0;
287
289
  while (pos <= this.currentBufferOffset - FRAME_HEADER_SIZE) {
288
290
  const word = new DataView(this.buffer.buffer).getUint32(pos, false);
289
- const header = readFrameHeader(word, { pos, fileSize: null });
291
+ const header = readFrameHeader(word, null).header;
290
292
  if (!header) {
291
293
  break;
292
294
  }