@ain1084/audio-worklet-stream 1.0.4 → 2.0.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.
Files changed (74) hide show
  1. package/dist/filler-frame-buffer-context.d.ts +30 -0
  2. package/dist/{frame-buffer/buffer-config.js → filler-frame-buffer-context.js} +5 -21
  3. package/dist/filler-frame-buffer-context.js.map +1 -0
  4. package/dist/{frame-buffer/buffer-filler.d.ts → frame-buffer-filler.d.ts} +2 -2
  5. package/dist/frame-buffer-filler.js +2 -0
  6. package/dist/frame-buffer-filler.js.map +1 -0
  7. package/dist/index.d.ts +2 -2
  8. package/dist/output-stream-node.d.ts +4 -4
  9. package/dist/output-stream-node.js +9 -9
  10. package/dist/output-stream-node.js.map +1 -1
  11. package/dist/output-stream-processor.js +4 -4
  12. package/dist/output-stream-processor.js.map +1 -1
  13. package/dist/stream-node-factory.d.ts +4 -4
  14. package/dist/stream-node-factory.js +9 -8
  15. package/dist/stream-node-factory.js.map +1 -1
  16. package/dist/write-strategy/manual-strategy.d.ts +3 -4
  17. package/dist/write-strategy/manual-strategy.js +4 -4
  18. package/dist/write-strategy/manual-strategy.js.map +1 -1
  19. package/dist/write-strategy/timed-strategy.d.ts +4 -4
  20. package/dist/write-strategy/timed-strategy.js +5 -5
  21. package/dist/write-strategy/timed-strategy.js.map +1 -1
  22. package/dist/write-strategy/worker/message.d.ts +3 -3
  23. package/dist/write-strategy/worker/worker.d.ts +2 -2
  24. package/dist/write-strategy/worker/worker.js +8 -8
  25. package/dist/write-strategy/worker/worker.js.map +1 -1
  26. package/dist/write-strategy/worker-strategy.d.ts +3 -3
  27. package/dist/write-strategy/worker-strategy.js +6 -6
  28. package/dist/write-strategy/worker-strategy.js.map +1 -1
  29. package/package.json +11 -12
  30. package/src/{frame-buffer/buffer-config.ts → filler-frame-buffer-context.ts} +6 -50
  31. package/src/{frame-buffer/buffer-filler.ts → frame-buffer-filler.ts} +2 -2
  32. package/src/index.ts +2 -2
  33. package/src/output-stream-node.ts +10 -10
  34. package/src/output-stream-processor.ts +5 -6
  35. package/src/stream-node-factory.ts +12 -12
  36. package/src/write-strategy/manual-strategy.ts +4 -5
  37. package/src/write-strategy/timed-strategy.ts +7 -7
  38. package/src/write-strategy/worker/message.ts +3 -3
  39. package/src/write-strategy/worker/worker.ts +10 -10
  40. package/src/write-strategy/worker-strategy.ts +9 -9
  41. package/dist/frame-buffer/buffer-config.d.ts +0 -60
  42. package/dist/frame-buffer/buffer-config.js.map +0 -1
  43. package/dist/frame-buffer/buffer-factory.d.ts +0 -76
  44. package/dist/frame-buffer/buffer-factory.js +0 -55
  45. package/dist/frame-buffer/buffer-factory.js.map +0 -1
  46. package/dist/frame-buffer/buffer-filler.js +0 -2
  47. package/dist/frame-buffer/buffer-filler.js.map +0 -1
  48. package/dist/frame-buffer/buffer-reader.d.ts +0 -60
  49. package/dist/frame-buffer/buffer-reader.js +0 -77
  50. package/dist/frame-buffer/buffer-reader.js.map +0 -1
  51. package/dist/frame-buffer/buffer-utils.d.ts +0 -34
  52. package/dist/frame-buffer/buffer-utils.js +0 -34
  53. package/dist/frame-buffer/buffer-utils.js.map +0 -1
  54. package/dist/frame-buffer/buffer-writer.d.ts +0 -60
  55. package/dist/frame-buffer/buffer-writer.js +0 -77
  56. package/dist/frame-buffer/buffer-writer.js.map +0 -1
  57. package/dist/frame-buffer/buffer.d.ts +0 -51
  58. package/dist/frame-buffer/buffer.js +0 -75
  59. package/dist/frame-buffer/buffer.js.map +0 -1
  60. package/dist/write-strategy/manual.d.ts +0 -36
  61. package/dist/write-strategy/manual.js +0 -43
  62. package/dist/write-strategy/manual.js.map +0 -1
  63. package/dist/write-strategy/timed.d.ts +0 -36
  64. package/dist/write-strategy/timed.js +0 -92
  65. package/dist/write-strategy/timed.js.map +0 -1
  66. package/dist/write-strategy/worker/strategy.d.ts +0 -34
  67. package/dist/write-strategy/worker/strategy.js +0 -125
  68. package/dist/write-strategy/worker/strategy.js.map +0 -1
  69. package/dist/write-strategy/worker/worker-strategy.d.ts +0 -34
  70. package/dist/write-strategy/worker/worker-strategy.js +0 -125
  71. package/dist/write-strategy/worker/worker-strategy.js.map +0 -1
  72. package/src/frame-buffer/buffer-reader.ts +0 -82
  73. package/src/frame-buffer/buffer-writer.ts +0 -82
  74. package/src/frame-buffer/buffer.ts +0 -79
@@ -1,36 +0,0 @@
1
- import { BufferWriteStrategy } from './strategy';
2
- import { FrameBufferConfig } from '../frame-buffer/buffer-config';
3
- import { FrameBufferWriter } from '../frame-buffer/buffer-writer';
4
- /**
5
- * ManualBufferWriteStrategy class
6
- * Implements the BufferWriteStrategy interface for manually writing to the buffer.
7
- */
8
- export declare class ManualBufferWriteStrategy implements BufferWriteStrategy {
9
- private readonly _writer;
10
- /**
11
- * Creates an instance of ManualBufferWriteStrategy.
12
- * @param config - The configuration for the frame buffer.
13
- */
14
- constructor(config: FrameBufferConfig);
15
- /**
16
- * Gets the FrameBufferWriter instance.
17
- * @returns The FrameBufferWriter instance.
18
- */
19
- get writer(): FrameBufferWriter;
20
- /**
21
- * Initializes the strategy.
22
- * @param node - The OutputStreamNode instance.
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(): boolean;
32
- /**
33
- * Stops the strategy.
34
- */
35
- onStopped(): void;
36
- }
@@ -1,43 +0,0 @@
1
- import { createFrameBufferWriter } from '../frame-buffer/buffer-config';
2
- /**
3
- * ManualBufferWriteStrategy class
4
- * Implements the BufferWriteStrategy interface for manually writing to the buffer.
5
- */
6
- export class ManualBufferWriteStrategy {
7
- _writer;
8
- /**
9
- * Creates an instance of ManualBufferWriteStrategy.
10
- * @param config - The configuration for the frame buffer.
11
- */
12
- constructor(config) {
13
- this._writer = createFrameBufferWriter(config);
14
- }
15
- /**
16
- * Gets the FrameBufferWriter instance.
17
- * @returns The FrameBufferWriter instance.
18
- */
19
- get writer() {
20
- return this._writer;
21
- }
22
- /**
23
- * Initializes the strategy.
24
- * @param node - The OutputStreamNode instance.
25
- * @returns A promise that resolves to true when initialization is complete.
26
- */
27
- async onInit( /* node: OutputStreamNode */) {
28
- return true;
29
- }
30
- /**
31
- * Starts the strategy.
32
- * @param node - The OutputStreamNode instance.
33
- * @returns A boolean indicating whether the strategy started successfully.
34
- */
35
- onStart( /* node: OutputStreamNode */) {
36
- return true;
37
- }
38
- /**
39
- * Stops the strategy.
40
- */
41
- onStopped() { }
42
- }
43
- //# sourceMappingURL=manual.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manual.js","sourceRoot":"","sources":["../../src/write-strategy/manual.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAqB,MAAM,+BAA+B,CAAA;AAG1F;;;IAGI;AACJ,MAAM,OAAO,yBAAyB;IACnB,OAAO,CAAmB;IAE3C;;;OAGG;IACH,YAAY,MAAyB;QACnC,IAAI,CAAC,OAAO,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAA;IAChD,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"}
@@ -1,36 +0,0 @@
1
- import { BufferWriteStrategy } from './strategy';
2
- import { FillerFrameBufferConfig } from '../frame-buffer/buffer-config';
3
- import { FrameBufferFiller } from '../frame-buffer/buffer-filler';
4
- import { 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
- }
@@ -1,92 +0,0 @@
1
- import { createFrameBufferWriter } from '../frame-buffer/buffer-config';
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 = createFrameBufferWriter(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.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"timed.js","sourceRoot":"","sources":["../../src/write-strategy/timed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAA2B,MAAM,+BAA+B,CAAA;AAKhG;;;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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,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,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"}
@@ -1,34 +0,0 @@
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
- }
@@ -1,125 +0,0 @@
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=strategy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"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,CA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,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"}
@@ -1,34 +0,0 @@
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
- }
@@ -1,125 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker-strategy.js","sourceRoot":"","sources":["../../../src/write-strategy/worker/worker-strategy.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,MAAM,OAA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I,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"}
@@ -1,82 +0,0 @@
1
- import { FrameBuffer } from './buffer'
2
- import { FrameBufferConfig } from './buffer-config'
3
-
4
- /**
5
- * FrameBufferReader class
6
- * This class reads audio frame data from a shared Float32Array buffer and processes it.
7
- * The buffer usage is tracked using a Uint32Array.
8
- */
9
- export class FrameBufferReader {
10
- private readonly _frameBuffer: FrameBuffer
11
- private readonly _usedFramesInBuffer: Uint32Array
12
- private readonly _totalFrames: BigUint64Array
13
- private _index: number = 0
14
-
15
- /**
16
- * @internal
17
- * Creates an instance of FrameBufferReader.
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.
23
- */
24
- constructor(config: FrameBufferConfig) {
25
- this._frameBuffer = new FrameBuffer(config.sampleBuffer, config.samplesPerFrame)
26
- this._usedFramesInBuffer = config.usedFramesInBuffer
27
- this._totalFrames = config.totalReadFrames
28
- }
29
-
30
- /**
31
- * Get the number of available frames in the buffer.
32
- * @returns The number of available frames in the buffer.
33
- */
34
- public get availableFrames(): number {
35
- return Atomics.load(this._usedFramesInBuffer, 0)
36
- }
37
-
38
- /**
39
- * Get the total number of frames read from the buffer.
40
- *
41
- * @returns The total number of frames read.
42
- */
43
- public get totalFrames(): bigint {
44
- // This class is not used concurrently by multiple threads,
45
- // so `Atomics` is not necessary when reading `totalFrames`.
46
- return this._totalFrames[0]
47
- }
48
-
49
- /**
50
- * Reads audio frame data from the buffer using the provided callback.
51
- * This method handles one or more readable segments within the ring buffer
52
- * and invokes the callback for each segment.
53
- *
54
- * @param processFrameSegment - The callback function invoked for each readable segment
55
- * of the ring buffer. It receives:
56
- * 1. `buffer`: A Float32Array representing the readable segment of the buffer.
57
- * 2. `offset`: The cumulative number of frames processed so far, used as the starting index
58
- * for the current segment relative to the entire data.
59
- *
60
- * The callback must return the number of frames it successfully processed.
61
- * If the callback processes fewer frames than available in the current segment,
62
- * processing will stop early.
63
- *
64
- * @returns The total number of frames processed across all segments.
65
- * Note: The return value is in frames, not in samples.
66
- *
67
- * @throws RangeError - If the processFrameSegment callback returns a processed length greater than the available frames in the current segment.
68
- *
69
- * @remarks The buffer is an array of samples, but it is always provided in frame-sized segments.
70
- * Each frame consists of multiple samples (e.g., for stereo, a frame contains a sample for the left channel
71
- * and one for the right channel). You must access and process the buffer in frame-sized chunks,
72
- * based on the structure of the frames.
73
- *
74
- */
75
- public read(processFrameSegment: (buffer: Float32Array, offset: number) => number): number {
76
- const result = this._frameBuffer.enumFrameSegments(this._index, this.availableFrames, processFrameSegment)
77
- this._index = result.nextIndex
78
- Atomics.sub(this._usedFramesInBuffer, 0, result.totalProcessedFrames)
79
- Atomics.add(this._totalFrames, 0, BigInt(result.totalProcessedFrames))
80
- return result.totalProcessedFrames
81
- }
82
- }