@ain1084/audio-worklet-stream 1.0.2 → 1.0.4
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/README.md +47 -17
- package/dist/frame-buffer/buffer-config.d.ts +0 -7
- package/dist/frame-buffer/buffer-config.js +7 -14
- package/dist/frame-buffer/buffer-config.js.map +1 -1
- package/dist/frame-buffer/buffer-reader.d.ts +8 -5
- package/dist/frame-buffer/buffer-reader.js +11 -7
- package/dist/frame-buffer/buffer-reader.js.map +1 -1
- package/dist/frame-buffer/buffer-writer.d.ts +8 -5
- package/dist/frame-buffer/buffer-writer.js +11 -7
- package/dist/frame-buffer/buffer-writer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/output-stream-node.d.ts +3 -2
- package/dist/output-stream-node.js +5 -8
- package/dist/output-stream-node.js.map +1 -1
- package/dist/output-stream-processor.d.ts +1 -13
- package/dist/output-stream-processor.js +1 -5
- package/dist/output-stream-processor.js.map +1 -1
- package/dist/stream-node-factory.d.ts +23 -14
- package/dist/stream-node-factory.js +3 -3
- package/dist/stream-node-factory.js.map +1 -1
- package/dist/write-strategy/manual-strategy.d.ts +36 -0
- package/dist/write-strategy/manual-strategy.js +43 -0
- package/dist/write-strategy/manual-strategy.js.map +1 -0
- package/dist/write-strategy/timed-strategy.d.ts +36 -0
- package/dist/write-strategy/timed-strategy.js +92 -0
- package/dist/write-strategy/timed-strategy.js.map +1 -0
- package/dist/write-strategy/worker/worker-strategy.d.ts +34 -0
- package/dist/write-strategy/worker/worker-strategy.js +125 -0
- package/dist/write-strategy/worker/worker-strategy.js.map +1 -0
- package/dist/write-strategy/worker/worker.d.ts +4 -2
- package/dist/write-strategy/worker/worker.js +6 -4
- package/dist/write-strategy/worker/worker.js.map +1 -1
- package/dist/write-strategy/worker-strategy.d.ts +34 -0
- package/dist/write-strategy/worker-strategy.js +125 -0
- package/dist/write-strategy/worker-strategy.js.map +1 -0
- package/package.json +10 -7
- package/src/frame-buffer/buffer-config.ts +7 -20
- package/src/frame-buffer/buffer-reader.ts +11 -7
- package/src/frame-buffer/buffer-writer.ts +11 -7
- package/src/index.ts +1 -0
- package/src/output-stream-node.ts +5 -9
- package/src/output-stream-processor.ts +2 -23
- package/src/stream-node-factory.ts +26 -17
- package/src/write-strategy/{manual.ts → manual-strategy.ts} +3 -3
- package/src/write-strategy/{timed.ts → timed-strategy.ts} +5 -5
- package/src/write-strategy/worker/worker.ts +7 -5
- package/src/write-strategy/{worker/strategy.ts → worker-strategy.ts} +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual-strategy.js","sourceRoot":"","sources":["../../src/write-strategy/manual-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAEjE;;;IAGI;AACJ,MAAM,OAAO,yBAAyB;IACnB,OAAO,CAAmB;IAE3C;;;OAGG;IACH,YAAY,MAAyB;QACnC,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAA;IAC9C,CAAC;IAED;;;OAGG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAC,4BAA4B;QACvC,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;OAIG;IACH,OAAO,EAAC,4BAA4B;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,SAAS,KAAU,CAAC;CACrB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BufferWriteStrategy } from './strategy';
|
|
2
|
+
import type { FillerFrameBufferConfig } from '../frame-buffer/buffer-config';
|
|
3
|
+
import type { FrameBufferFiller } from '../frame-buffer/buffer-filler';
|
|
4
|
+
import type { OutputStreamNode } from '../output-stream-node';
|
|
5
|
+
/**
|
|
6
|
+
* TimedBufferWriteStrategy class
|
|
7
|
+
* Implements the BufferWriteStrategy interface using a timer to manage buffer filling.
|
|
8
|
+
*/
|
|
9
|
+
export declare class TimedBufferWriteStrategy implements BufferWriteStrategy {
|
|
10
|
+
private readonly _writer;
|
|
11
|
+
private readonly _filler;
|
|
12
|
+
private readonly _interval;
|
|
13
|
+
private readonly _isContinuePlayback;
|
|
14
|
+
private _context;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of TimedBufferWriteStrategy.
|
|
17
|
+
* @param config - The configuration for the filler frame buffer.
|
|
18
|
+
* @param filler - The FrameBufferFiller instance.
|
|
19
|
+
*/
|
|
20
|
+
constructor(config: FillerFrameBufferConfig, filler: FrameBufferFiller);
|
|
21
|
+
/**
|
|
22
|
+
* Initializes the strategy.
|
|
23
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
24
|
+
*/
|
|
25
|
+
onInit(): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Starts the strategy.
|
|
28
|
+
* @param node - The OutputStreamNode instance.
|
|
29
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
30
|
+
*/
|
|
31
|
+
onStart(node: OutputStreamNode): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Stops the strategy.
|
|
34
|
+
*/
|
|
35
|
+
onStopped(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { FrameBufferWriter } from '../frame-buffer/buffer-writer';
|
|
2
|
+
/**
|
|
3
|
+
* PlayContext class
|
|
4
|
+
* Manages the buffer filling process using a timer.
|
|
5
|
+
*/
|
|
6
|
+
class PlayContext {
|
|
7
|
+
_timerId = 0;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of PlayContext.
|
|
10
|
+
* @param node - The OutputStreamNode instance.
|
|
11
|
+
* @param writer - The FrameBufferWriter instance.
|
|
12
|
+
* @param filler - The FrameBufferFiller instance.
|
|
13
|
+
* @param fillInterval - The interval in milliseconds for filling the buffer.
|
|
14
|
+
*/
|
|
15
|
+
constructor(node, writer, filler, fillInterval) {
|
|
16
|
+
this._timerId = window.setInterval(() => {
|
|
17
|
+
if (!this._timerId || !node.isStart) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
if (!filler.fill(writer)) {
|
|
22
|
+
node.stop(writer.totalFrames);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
this.cleanup();
|
|
27
|
+
node.stop();
|
|
28
|
+
}
|
|
29
|
+
}, fillInterval);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Cleans up the timer.
|
|
33
|
+
*/
|
|
34
|
+
cleanup() {
|
|
35
|
+
if (this._timerId) {
|
|
36
|
+
clearInterval(this._timerId);
|
|
37
|
+
this._timerId = 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* TimedBufferWriteStrategy class
|
|
43
|
+
* Implements the BufferWriteStrategy interface using a timer to manage buffer filling.
|
|
44
|
+
*/
|
|
45
|
+
export class TimedBufferWriteStrategy {
|
|
46
|
+
_writer;
|
|
47
|
+
_filler;
|
|
48
|
+
_interval;
|
|
49
|
+
_isContinuePlayback;
|
|
50
|
+
_context = null;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an instance of TimedBufferWriteStrategy.
|
|
53
|
+
* @param config - The configuration for the filler frame buffer.
|
|
54
|
+
* @param filler - The FrameBufferFiller instance.
|
|
55
|
+
*/
|
|
56
|
+
constructor(config, filler) {
|
|
57
|
+
this._writer = new FrameBufferWriter(config);
|
|
58
|
+
this._filler = filler;
|
|
59
|
+
this._interval = config.fillInterval;
|
|
60
|
+
this._isContinuePlayback = this._filler.fill(this._writer);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Initializes the strategy.
|
|
64
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
65
|
+
*/
|
|
66
|
+
async onInit( /* node: OutputStreamNode */) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Starts the strategy.
|
|
71
|
+
* @param node - The OutputStreamNode instance.
|
|
72
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
73
|
+
*/
|
|
74
|
+
onStart(node) {
|
|
75
|
+
if (this._context) {
|
|
76
|
+
throw new Error('Invalid state: context is not null.');
|
|
77
|
+
}
|
|
78
|
+
if (!this._isContinuePlayback) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
this._context = new PlayContext(node, this._writer, this._filler, this._interval);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Stops the strategy.
|
|
86
|
+
*/
|
|
87
|
+
onStopped() {
|
|
88
|
+
this._context?.cleanup();
|
|
89
|
+
this._context = null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=timed-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timed-strategy.js","sourceRoot":"","sources":["../../src/write-strategy/timed-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAIjE;;;GAGG;AACH,MAAM,WAAW;IACP,QAAQ,GAAW,CAAC,CAAA;IAE5B;;;;;;OAMG;IACH,YAAY,IAAsB,EAAE,MAAyB,EAAE,MAAyB,EAAE,YAAoB;QAC5G,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE;YACtC,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACpC,OAAM;YACR,CAAC;YACD,IAAI,CAAC;gBACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;oBACzB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;gBAC/B,CAAC;YACH,CAAC;YACD,MAAM,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CAAC,SAAS,CAAC,CAAA;QACjF,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,SAAS;QACP,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BufferWriteStrategy } from '../strategy';
|
|
2
|
+
import type { FillerFrameBufferConfig } from '../../frame-buffer/buffer-config';
|
|
3
|
+
import type { OutputStreamNode } from '../../output-stream-node';
|
|
4
|
+
/**
|
|
5
|
+
* WorkerBufferWriteStrategy class
|
|
6
|
+
* Implements the BufferWriteStrategy interface using a web worker to manage buffer filling.
|
|
7
|
+
*/
|
|
8
|
+
export declare class WorkerBufferWriteStrategy<FillerParam> implements BufferWriteStrategy {
|
|
9
|
+
private readonly _createPlayContext;
|
|
10
|
+
private _context;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of WorkerBufferWriteStrategy.
|
|
13
|
+
* @param config - The configuration for the filler frame buffer.
|
|
14
|
+
* @param workerConstructor - The constructor for the Worker.
|
|
15
|
+
* @param fillerParam - The parameters for the FrameBufferFiller.
|
|
16
|
+
*/
|
|
17
|
+
constructor(config: FillerFrameBufferConfig, workerConstructor: new () => Worker, fillerParam: FillerParam);
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the strategy.
|
|
20
|
+
* @param node - The OutputStreamNode instance.
|
|
21
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
22
|
+
*/
|
|
23
|
+
onInit(node: OutputStreamNode): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Starts the strategy.
|
|
26
|
+
* @param node - The OutputStreamNode instance.
|
|
27
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
28
|
+
*/
|
|
29
|
+
onStart(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Stops the strategy.
|
|
32
|
+
*/
|
|
33
|
+
onStopped(): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlayContext class
|
|
3
|
+
* Manages the buffer filling process within a web worker.
|
|
4
|
+
*/
|
|
5
|
+
class Context {
|
|
6
|
+
_node;
|
|
7
|
+
_config;
|
|
8
|
+
_fillerParam;
|
|
9
|
+
_worker;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of PlayContext.
|
|
12
|
+
* @param params - The parameters for the PlayContext.
|
|
13
|
+
*/
|
|
14
|
+
constructor(params) {
|
|
15
|
+
this._node = params.node;
|
|
16
|
+
this._config = params.config;
|
|
17
|
+
this._worker = new params.workerConstructor();
|
|
18
|
+
this._fillerParam = params.fillerParam;
|
|
19
|
+
this._worker.onmessage = this.handleWorkerMessage.bind(this);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates and initializes an instance of PlayContext.
|
|
23
|
+
* @param params - The parameters for the PlayContext.
|
|
24
|
+
* @returns A promise that resolves to an instance of PlayContext.
|
|
25
|
+
*/
|
|
26
|
+
static async create(params) {
|
|
27
|
+
const instance = new Context(params);
|
|
28
|
+
await instance.init();
|
|
29
|
+
return instance;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Handles messages from the worker.
|
|
33
|
+
* @param ev - The message event from the worker.
|
|
34
|
+
*/
|
|
35
|
+
handleWorkerMessage(ev) {
|
|
36
|
+
if (ev.data.type === 'stop') {
|
|
37
|
+
this._node.stop(ev.data.stopFrames);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initializes the PlayContext by sending the 'init' message to the worker.
|
|
42
|
+
* @returns A promise that resolves when initialization is complete.
|
|
43
|
+
*/
|
|
44
|
+
init() {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const message = {
|
|
47
|
+
type: 'init',
|
|
48
|
+
config: this._config,
|
|
49
|
+
fillerParams: this._fillerParam,
|
|
50
|
+
};
|
|
51
|
+
this._worker.postMessage(message);
|
|
52
|
+
const listener = (ev) => {
|
|
53
|
+
if (ev.data.type === 'init-done') {
|
|
54
|
+
this._worker.removeEventListener('message', listener);
|
|
55
|
+
resolve();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this._worker.addEventListener('message', listener);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Starts the buffer filling process by sending the 'start' message to the worker.
|
|
63
|
+
*/
|
|
64
|
+
start() {
|
|
65
|
+
const message = {
|
|
66
|
+
type: 'start',
|
|
67
|
+
};
|
|
68
|
+
this._worker.postMessage(message);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Stops the worker and terminates it.
|
|
72
|
+
*/
|
|
73
|
+
stopped() {
|
|
74
|
+
this._worker.onmessage = null;
|
|
75
|
+
this._worker.terminate();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* WorkerBufferWriteStrategy class
|
|
80
|
+
* Implements the BufferWriteStrategy interface using a web worker to manage buffer filling.
|
|
81
|
+
*/
|
|
82
|
+
export class WorkerBufferWriteStrategy {
|
|
83
|
+
_createPlayContext;
|
|
84
|
+
_context = null;
|
|
85
|
+
/**
|
|
86
|
+
* Creates an instance of WorkerBufferWriteStrategy.
|
|
87
|
+
* @param config - The configuration for the filler frame buffer.
|
|
88
|
+
* @param workerConstructor - The constructor for the Worker.
|
|
89
|
+
* @param fillerParam - The parameters for the FrameBufferFiller.
|
|
90
|
+
*/
|
|
91
|
+
constructor(config, workerConstructor, fillerParam) {
|
|
92
|
+
this._createPlayContext = (node) => Context.create({ node, config, workerConstructor, fillerParam });
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Initializes the strategy.
|
|
96
|
+
* @param node - The OutputStreamNode instance.
|
|
97
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
98
|
+
*/
|
|
99
|
+
async onInit(node) {
|
|
100
|
+
this._context = await this._createPlayContext(node);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Starts the strategy.
|
|
105
|
+
* @param node - The OutputStreamNode instance.
|
|
106
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
107
|
+
*/
|
|
108
|
+
onStart( /* node: OutputStreamNode */) {
|
|
109
|
+
if (!this._context) {
|
|
110
|
+
throw new Error('Invalid state: context is null.');
|
|
111
|
+
}
|
|
112
|
+
this._context.start();
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Stops the strategy.
|
|
117
|
+
*/
|
|
118
|
+
onStopped() {
|
|
119
|
+
if (!this._context) {
|
|
120
|
+
throw new Error('Invalid state: context is null.');
|
|
121
|
+
}
|
|
122
|
+
this._context.stopped();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=worker-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-strategy.js","sourceRoot":"","sources":["../../../src/write-strategy/worker/worker-strategy.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,MAAM,OAAO;IACM,KAAK,CAAkB;IACvB,OAAO,CAAyB;IAChC,YAAY,CAAc;IAC1B,OAAO,CAAQ;IAEhC;;;OAGG;IACH,YAAoB,MAAyC;QAC3D,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAA;QAC7C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAA;QACtC,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC9D,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAe,MAAyC;QAChF,MAAM,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AO,CAAC,SAAS,EAAE,CAAA;IAC1B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,yBAAyB;IACnB,kBAAkB,CAA2D;IACtF,QAAQ,GAAgC,IAAI,CAAA;IAEpD;;;;;OAKG;IACH,YAAY,MAA+B,EAAE,iBAAmC,EAAE,WAAwB;QACxG,IAAI,CAAC,kBAAkB,GAAG,CAAC,IAAsB,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAc,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC,CAAA;IACrI,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,IAAsB;QACjC,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;QACnD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;OAIG;IACH,OAAO,EAAC,4BAA4B;QAClC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACpD,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,SAAS;QACP,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACpD,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -2,14 +2,16 @@ import type { FrameBufferFiller } from '../../frame-buffer/buffer-filler';
|
|
|
2
2
|
/**
|
|
3
3
|
* BufferFillWorker class
|
|
4
4
|
* Manages the communication between the main thread and the worker.
|
|
5
|
-
|
|
5
|
+
*
|
|
6
|
+
* @template FillerParams - The parameters used by the FrameBufferFiller in the worker.
|
|
7
|
+
*/
|
|
6
8
|
export declare class BufferFillWorker<FillerParams> {
|
|
7
9
|
private _context;
|
|
8
10
|
private _frameBufferFillerGenerator;
|
|
9
11
|
private _init?;
|
|
10
12
|
/**
|
|
11
13
|
* Creates an instance of BufferFillWorker.
|
|
12
|
-
* @param generator - A
|
|
14
|
+
* @param generator - A constructor function to create an instance of the FrameBufferFiller class.
|
|
13
15
|
* @param init - An optional initialization function.
|
|
14
16
|
*/
|
|
15
17
|
constructor(generator: new (params: FillerParams) => FrameBufferFiller, init?: () => Promise<void>);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FrameBufferWriter } from '../../frame-buffer/buffer-writer';
|
|
2
2
|
/**
|
|
3
3
|
* Context class
|
|
4
4
|
* Manages the buffer filling process within a web worker.
|
|
@@ -15,7 +15,7 @@ class Context {
|
|
|
15
15
|
* @param frameBufferFiller - The FrameBufferFiller instance.
|
|
16
16
|
*/
|
|
17
17
|
constructor(config, frameBufferFiller) {
|
|
18
|
-
this._frameBufferWriter =
|
|
18
|
+
this._frameBufferWriter = new FrameBufferWriter(config);
|
|
19
19
|
this._frameBufferFiller = frameBufferFiller;
|
|
20
20
|
this._fillInterval = config.fillInterval;
|
|
21
21
|
this._isContinuePlayback = this.fillBuffer();
|
|
@@ -66,14 +66,16 @@ class Context {
|
|
|
66
66
|
/**
|
|
67
67
|
* BufferFillWorker class
|
|
68
68
|
* Manages the communication between the main thread and the worker.
|
|
69
|
-
|
|
69
|
+
*
|
|
70
|
+
* @template FillerParams - The parameters used by the FrameBufferFiller in the worker.
|
|
71
|
+
*/
|
|
70
72
|
export class BufferFillWorker {
|
|
71
73
|
_context = null;
|
|
72
74
|
_frameBufferFillerGenerator;
|
|
73
75
|
_init;
|
|
74
76
|
/**
|
|
75
77
|
* Creates an instance of BufferFillWorker.
|
|
76
|
-
* @param generator - A
|
|
78
|
+
* @param generator - A constructor function to create an instance of the FrameBufferFiller class.
|
|
77
79
|
* @param init - An optional initialization function.
|
|
78
80
|
*/
|
|
79
81
|
constructor(generator, init) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/write-strategy/worker/worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/write-strategy/worker/worker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAGpE;;;GAGG;AACH,MAAM,OAAO;IACM,kBAAkB,CAAmB;IACrC,mBAAmB,CAAS;IAC5B,kBAAkB,CAAmB;IACrC,aAAa,CAAQ;IAC9B,QAAQ,GAAW,CAAC,CAAA;IAE5B;;;;OAIG;IACH,YAAY,MAA+B,EAAE,iBAAoC;QAC/E,IAAI,CAAC,kBAAkB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAA;QACvD,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAA;QAC3C,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,YAAY,CAAA;QACxC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;IAC9C,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC9B,IAAI,CAAC,UAAU,EAAE,CAAA;YACjB,OAAM;QACR,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE;YACpC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;gBAC3D,IAAI,CAAC,UAAU,EAAE,CAAA;gBACjB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBACjC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAA;YACnB,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACxB,CAAC;IAED;;OAEG;IACI,UAA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,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;QAC1D,CAAC;IACH,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,IAAI,CAAC,MAA+B,EAAE,MAAoB;QACtE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;QACvD,CAAC;QACD,MAAM,IAAI,CAAC,KAAK,EAAE,EAAE,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC,CAAA;QACjF,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,WAAW,EAAuB,CAAC,CAAA;IAC9D,CAAC;IAED;;OAEG;IACK,KAAK;QACX,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;QACnD,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC;IAED;;OAEG;IACK,IAAI;QACV,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;QACnD,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BufferWriteStrategy } from './strategy';
|
|
2
|
+
import type { FillerFrameBufferConfig } from '../frame-buffer/buffer-config';
|
|
3
|
+
import type { OutputStreamNode } from '../output-stream-node';
|
|
4
|
+
/**
|
|
5
|
+
* WorkerBufferWriteStrategy class
|
|
6
|
+
* Implements the BufferWriteStrategy interface using a web worker to manage buffer filling.
|
|
7
|
+
*/
|
|
8
|
+
export declare class WorkerBufferWriteStrategy<FillerParam> implements BufferWriteStrategy {
|
|
9
|
+
private readonly _createPlayContext;
|
|
10
|
+
private _context;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of WorkerBufferWriteStrategy.
|
|
13
|
+
* @param config - The configuration for the filler frame buffer.
|
|
14
|
+
* @param workerConstructor - The constructor for the Worker.
|
|
15
|
+
* @param fillerParam - The parameters for the FrameBufferFiller.
|
|
16
|
+
*/
|
|
17
|
+
constructor(config: FillerFrameBufferConfig, workerConstructor: new () => Worker, fillerParam: FillerParam);
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the strategy.
|
|
20
|
+
* @param node - The OutputStreamNode instance.
|
|
21
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
22
|
+
*/
|
|
23
|
+
onInit(node: OutputStreamNode): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Starts the strategy.
|
|
26
|
+
* @param node - The OutputStreamNode instance.
|
|
27
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
28
|
+
*/
|
|
29
|
+
onStart(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Stops the strategy.
|
|
32
|
+
*/
|
|
33
|
+
onStopped(): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlayContext class
|
|
3
|
+
* Manages the buffer filling process within a web worker.
|
|
4
|
+
*/
|
|
5
|
+
class Context {
|
|
6
|
+
_node;
|
|
7
|
+
_config;
|
|
8
|
+
_fillerParam;
|
|
9
|
+
_worker;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of PlayContext.
|
|
12
|
+
* @param params - The parameters for the PlayContext.
|
|
13
|
+
*/
|
|
14
|
+
constructor(params) {
|
|
15
|
+
this._node = params.node;
|
|
16
|
+
this._config = params.config;
|
|
17
|
+
this._worker = new params.workerConstructor();
|
|
18
|
+
this._fillerParam = params.fillerParam;
|
|
19
|
+
this._worker.onmessage = this.handleWorkerMessage.bind(this);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates and initializes an instance of PlayContext.
|
|
23
|
+
* @param params - The parameters for the PlayContext.
|
|
24
|
+
* @returns A promise that resolves to an instance of PlayContext.
|
|
25
|
+
*/
|
|
26
|
+
static async create(params) {
|
|
27
|
+
const instance = new Context(params);
|
|
28
|
+
await instance.init();
|
|
29
|
+
return instance;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Handles messages from the worker.
|
|
33
|
+
* @param ev - The message event from the worker.
|
|
34
|
+
*/
|
|
35
|
+
handleWorkerMessage(ev) {
|
|
36
|
+
if (ev.data.type === 'stop') {
|
|
37
|
+
this._node.stop(ev.data.stopFrames);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initializes the PlayContext by sending the 'init' message to the worker.
|
|
42
|
+
* @returns A promise that resolves when initialization is complete.
|
|
43
|
+
*/
|
|
44
|
+
init() {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const message = {
|
|
47
|
+
type: 'init',
|
|
48
|
+
config: this._config,
|
|
49
|
+
fillerParams: this._fillerParam,
|
|
50
|
+
};
|
|
51
|
+
this._worker.postMessage(message);
|
|
52
|
+
const listener = (ev) => {
|
|
53
|
+
if (ev.data.type === 'init-done') {
|
|
54
|
+
this._worker.removeEventListener('message', listener);
|
|
55
|
+
resolve();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this._worker.addEventListener('message', listener);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Starts the buffer filling process by sending the 'start' message to the worker.
|
|
63
|
+
*/
|
|
64
|
+
start() {
|
|
65
|
+
const message = {
|
|
66
|
+
type: 'start',
|
|
67
|
+
};
|
|
68
|
+
this._worker.postMessage(message);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Stops the worker and terminates it.
|
|
72
|
+
*/
|
|
73
|
+
stopped() {
|
|
74
|
+
this._worker.onmessage = null;
|
|
75
|
+
this._worker.terminate();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* WorkerBufferWriteStrategy class
|
|
80
|
+
* Implements the BufferWriteStrategy interface using a web worker to manage buffer filling.
|
|
81
|
+
*/
|
|
82
|
+
export class WorkerBufferWriteStrategy {
|
|
83
|
+
_createPlayContext;
|
|
84
|
+
_context = null;
|
|
85
|
+
/**
|
|
86
|
+
* Creates an instance of WorkerBufferWriteStrategy.
|
|
87
|
+
* @param config - The configuration for the filler frame buffer.
|
|
88
|
+
* @param workerConstructor - The constructor for the Worker.
|
|
89
|
+
* @param fillerParam - The parameters for the FrameBufferFiller.
|
|
90
|
+
*/
|
|
91
|
+
constructor(config, workerConstructor, fillerParam) {
|
|
92
|
+
this._createPlayContext = (node) => Context.create({ node, config, workerConstructor, fillerParam });
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Initializes the strategy.
|
|
96
|
+
* @param node - The OutputStreamNode instance.
|
|
97
|
+
* @returns A promise that resolves to true when initialization is complete.
|
|
98
|
+
*/
|
|
99
|
+
async onInit(node) {
|
|
100
|
+
this._context = await this._createPlayContext(node);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Starts the strategy.
|
|
105
|
+
* @param node - The OutputStreamNode instance.
|
|
106
|
+
* @returns A boolean indicating whether the strategy started successfully.
|
|
107
|
+
*/
|
|
108
|
+
onStart( /* node: OutputStreamNode */) {
|
|
109
|
+
if (!this._context) {
|
|
110
|
+
throw new Error('Invalid state: context is null.');
|
|
111
|
+
}
|
|
112
|
+
this._context.start();
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Stops the strategy.
|
|
117
|
+
*/
|
|
118
|
+
onStopped() {
|
|
119
|
+
if (!this._context) {
|
|
120
|
+
throw new Error('Invalid state: context is null.');
|
|
121
|
+
}
|
|
122
|
+
this._context.stopped();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=worker-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-strategy.js","sourceRoot":"","sources":["../../src/write-strategy/worker-strategy.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,MAAM,OAAO;IACM,KAAK,CAAkB;IACvB,OAAO,CAAyB;IAChC,YAAY,CAAc;IAC1B,OAAO,CAAQ;IAEhC;;;OAGG;IACH,YAAoB,MAAyC;QAC3D,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAA;QAC7C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAA;QACtC,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC9D,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAe,MAAyC;QAChF,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;QACpC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QACrB,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;;OAGG;IACK,mBAAmB,CAAC,EAAmC;QAC7D,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACrC,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,IAAI;QACV,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACnC,MAAM,OAAO,GAAkC;gBAC7C,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE,IAAI,CAAC,OAAO;gBACpB,YAAY,EAAE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b,CAAC;IAED;;;;OAIG;IACH,OAAO,EAAC,4BAA4B;QAClC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACpD,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,SAAS;QACP,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACpD,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ain1084/audio-worklet-stream",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,14 +41,17 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@stylistic/eslint-plugin": "^2.9.0",
|
|
44
|
-
"@types/audioworklet": "^0.0.
|
|
45
|
-
"@types/node": "^22.
|
|
46
|
-
"@typescript-eslint/parser": "^8.
|
|
47
|
-
"eslint": "^9.
|
|
44
|
+
"@types/audioworklet": "^0.0.62",
|
|
45
|
+
"@types/node": "^22.8.1",
|
|
46
|
+
"@typescript-eslint/parser": "^8.12.0",
|
|
47
|
+
"eslint": "^9.13.0",
|
|
48
48
|
"globals": "^15.11.0",
|
|
49
49
|
"typedoc": "^0.26.10",
|
|
50
50
|
"typescript": "^5.6.3",
|
|
51
|
-
"typescript-eslint": "^8.
|
|
52
|
-
"vite": "^5.4.
|
|
51
|
+
"typescript-eslint": "^8.12.0",
|
|
52
|
+
"vite": "^5.4.10"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@ain1084/array-buffer-partitioner": "^0.0.3"
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FrameBufferWriter } from './buffer-writer'
|
|
1
|
+
import { createArrayBufferViews } from '@ain1084/array-buffer-partitioner'
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* The default number of chunks in the frame buffer when
|
|
@@ -74,18 +73,6 @@ export type FillerFrameBufferConfig = FrameBufferConfig & Readonly<{
|
|
|
74
73
|
fillInterval: number
|
|
75
74
|
}>
|
|
76
75
|
|
|
77
|
-
/**
|
|
78
|
-
* Creates a FrameBufferWriter instance.
|
|
79
|
-
* @param config - The configuration for the FrameBuffer.
|
|
80
|
-
* @returns A new instance of FrameBufferWriter.
|
|
81
|
-
*/
|
|
82
|
-
export const createFrameBufferWriter = (config: FrameBufferConfig): FrameBufferWriter => {
|
|
83
|
-
return new FrameBufferWriter(
|
|
84
|
-
new FrameBuffer(config.sampleBuffer, config.samplesPerFrame),
|
|
85
|
-
config.usedFramesInBuffer, config.totalWriteFrames,
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
76
|
/**
|
|
90
77
|
* Creates a FrameBufferConfig instance.
|
|
91
78
|
* @param params - The parameters for the FrameBuffer.
|
|
@@ -93,13 +80,13 @@ export const createFrameBufferWriter = (config: FrameBufferConfig): FrameBufferW
|
|
|
93
80
|
*/
|
|
94
81
|
export const createFrameBufferConfig = (params: FrameBufferParams): FrameBufferConfig => {
|
|
95
82
|
return {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
...createArrayBufferViews(SharedArrayBuffer, {
|
|
84
|
+
sampleBuffer: [Float32Array, params.frameBufferSize * params.channelCount],
|
|
85
|
+
usedFramesInBuffer: [Uint32Array, 1],
|
|
86
|
+
totalReadFrames: [BigUint64Array, 1],
|
|
87
|
+
totalWriteFrames: [BigUint64Array, 1],
|
|
88
|
+
}),
|
|
99
89
|
samplesPerFrame: params.channelCount,
|
|
100
|
-
usedFramesInBuffer: new Uint32Array(new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT)),
|
|
101
|
-
totalReadFrames: new BigUint64Array(new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT)),
|
|
102
|
-
totalWriteFrames: new BigUint64Array(new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT)),
|
|
103
90
|
}
|
|
104
91
|
}
|
|
105
92
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FrameBuffer } from './buffer'
|
|
2
|
+
import { FrameBufferConfig } from './buffer-config'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* FrameBufferReader class
|
|
@@ -12,15 +13,18 @@ export class FrameBufferReader {
|
|
|
12
13
|
private _index: number = 0
|
|
13
14
|
|
|
14
15
|
/**
|
|
16
|
+
* @internal
|
|
15
17
|
* Creates an instance of FrameBufferReader.
|
|
16
|
-
* @param
|
|
17
|
-
*
|
|
18
|
-
*
|
|
18
|
+
* @param config - The configuration object containing:
|
|
19
|
+
* - `sampleBuffer`: The shared buffer to read audio data frames from.
|
|
20
|
+
* - `samplesPerFrame`: The number of samples per frame.
|
|
21
|
+
* - `usedFramesInBuffer`: A Uint32Array tracking the usage of frames in the buffer.
|
|
22
|
+
* - `totalReadFrames`: A BigUint64Array tracking the total frames read from the buffer.
|
|
19
23
|
*/
|
|
20
|
-
constructor(
|
|
21
|
-
this._frameBuffer =
|
|
22
|
-
this._usedFramesInBuffer = usedFramesInBuffer
|
|
23
|
-
this._totalFrames =
|
|
24
|
+
constructor(config: FrameBufferConfig) {
|
|
25
|
+
this._frameBuffer = new FrameBuffer(config.sampleBuffer, config.samplesPerFrame)
|
|
26
|
+
this._usedFramesInBuffer = config.usedFramesInBuffer
|
|
27
|
+
this._totalFrames = config.totalReadFrames
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
/**
|