@mediabunny/mp3-encoder 1.25.6 → 1.25.8
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.
- package/dist/bundles/mediabunny-mp3-encoder.js +5 -1
- package/dist/bundles/mediabunny-mp3-encoder.min.js +1 -1
- package/dist/bundles/mediabunny-mp3-encoder.min.mjs +1 -1
- package/dist/bundles/mediabunny-mp3-encoder.mjs +5 -1
- package/dist/modules/src/index.d.ts.map +1 -1
- package/dist/modules/src/index.js +6 -1
- package/package.json +1 -1
- package/src/index.ts +8 -1
|
@@ -280,7 +280,7 @@ var Mp3Encoder = class extends CustomAudioEncoder {
|
|
|
280
280
|
this.pendingMessages = /* @__PURE__ */ new Map();
|
|
281
281
|
this.buffer = new Uint8Array(2 ** 16);
|
|
282
282
|
this.currentBufferOffset = 0;
|
|
283
|
-
this.currentTimestamp =
|
|
283
|
+
this.currentTimestamp = null;
|
|
284
284
|
this.chunkMetadata = {};
|
|
285
285
|
}
|
|
286
286
|
static supports(codec, config) {
|
|
@@ -324,6 +324,9 @@ var Mp3Encoder = class extends CustomAudioEncoder {
|
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
326
|
async encode(audioSample) {
|
|
327
|
+
if (this.currentTimestamp === null) {
|
|
328
|
+
this.currentTimestamp = audioSample.timestamp;
|
|
329
|
+
}
|
|
327
330
|
const sizePerChannel = audioSample.allocationSize({
|
|
328
331
|
format: "s16-planar",
|
|
329
332
|
planeIndex: 0
|
|
@@ -361,6 +364,7 @@ var Mp3Encoder = class extends CustomAudioEncoder {
|
|
|
361
364
|
* these chunks and extract the MP3 frames only when they're complete.
|
|
362
365
|
*/
|
|
363
366
|
digestOutput(bytes) {
|
|
367
|
+
assert(this.currentTimestamp !== null);
|
|
364
368
|
const requiredBufferSize = this.currentBufferOffset + bytes.length;
|
|
365
369
|
if (requiredBufferSize > this.buffer.length) {
|
|
366
370
|
const newSize = 1 << Math.ceil(Math.log2(requiredBufferSize));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA8LH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,YAE9B,CAAC"}
|
|
@@ -23,7 +23,7 @@ class Mp3Encoder extends mediabunny_1.CustomAudioEncoder {
|
|
|
23
23
|
this.pendingMessages = new Map();
|
|
24
24
|
this.buffer = new Uint8Array(2 ** 16);
|
|
25
25
|
this.currentBufferOffset = 0;
|
|
26
|
-
this.currentTimestamp =
|
|
26
|
+
this.currentTimestamp = null;
|
|
27
27
|
this.chunkMetadata = {};
|
|
28
28
|
}
|
|
29
29
|
static supports(codec, config) {
|
|
@@ -70,6 +70,10 @@ class Mp3Encoder extends mediabunny_1.CustomAudioEncoder {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
async encode(audioSample) {
|
|
73
|
+
if (this.currentTimestamp === null) {
|
|
74
|
+
// The first sample's timestamp determines where we start
|
|
75
|
+
this.currentTimestamp = audioSample.timestamp;
|
|
76
|
+
}
|
|
73
77
|
const sizePerChannel = audioSample.allocationSize({
|
|
74
78
|
format: 's16-planar',
|
|
75
79
|
planeIndex: 0,
|
|
@@ -106,6 +110,7 @@ class Mp3Encoder extends mediabunny_1.CustomAudioEncoder {
|
|
|
106
110
|
* these chunks and extract the MP3 frames only when they're complete.
|
|
107
111
|
*/
|
|
108
112
|
digestOutput(bytes) {
|
|
113
|
+
assert(this.currentTimestamp !== null);
|
|
109
114
|
const requiredBufferSize = this.currentBufferOffset + bytes.length;
|
|
110
115
|
if (requiredBufferSize > this.buffer.length) {
|
|
111
116
|
// Grow the buffer to the required size
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mediabunny/mp3-encoder",
|
|
3
3
|
"author": "Vanilagy",
|
|
4
|
-
"version": "1.25.
|
|
4
|
+
"version": "1.25.8",
|
|
5
5
|
"description": "MP3 encoder extension for Mediabunny, based on LAME.",
|
|
6
6
|
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
|
7
7
|
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
package/src/index.ts
CHANGED
|
@@ -22,7 +22,7 @@ class Mp3Encoder extends CustomAudioEncoder {
|
|
|
22
22
|
|
|
23
23
|
private buffer = new Uint8Array(2 ** 16);
|
|
24
24
|
private currentBufferOffset = 0;
|
|
25
|
-
private currentTimestamp =
|
|
25
|
+
private currentTimestamp: number | null = null;
|
|
26
26
|
private chunkMetadata: EncodedAudioChunkMetadata = {};
|
|
27
27
|
|
|
28
28
|
static override supports(codec: AudioCodec, config: AudioDecoderConfig): boolean {
|
|
@@ -79,6 +79,11 @@ class Mp3Encoder extends CustomAudioEncoder {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
async encode(audioSample: AudioSample) {
|
|
82
|
+
if (this.currentTimestamp === null) {
|
|
83
|
+
// The first sample's timestamp determines where we start
|
|
84
|
+
this.currentTimestamp = audioSample.timestamp;
|
|
85
|
+
}
|
|
86
|
+
|
|
82
87
|
const sizePerChannel = audioSample.allocationSize({
|
|
83
88
|
format: 's16-planar',
|
|
84
89
|
planeIndex: 0,
|
|
@@ -123,6 +128,8 @@ class Mp3Encoder extends CustomAudioEncoder {
|
|
|
123
128
|
* these chunks and extract the MP3 frames only when they're complete.
|
|
124
129
|
*/
|
|
125
130
|
private digestOutput(bytes: Uint8Array) {
|
|
131
|
+
assert(this.currentTimestamp !== null);
|
|
132
|
+
|
|
126
133
|
const requiredBufferSize = this.currentBufferOffset + bytes.length;
|
|
127
134
|
if (requiredBufferSize > this.buffer.length) {
|
|
128
135
|
// Grow the buffer to the required size
|