node-av 3.1.2 → 4.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 (157) hide show
  1. package/README.md +65 -52
  2. package/binding.gyp +4 -0
  3. package/dist/api/audio-frame-buffer.d.ts +201 -0
  4. package/dist/api/audio-frame-buffer.js +275 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +319 -78
  7. package/dist/api/bitstream-filter.js +680 -151
  8. package/dist/api/bitstream-filter.js.map +1 -1
  9. package/dist/api/constants.d.ts +44 -0
  10. package/dist/api/constants.js +45 -0
  11. package/dist/api/constants.js.map +1 -0
  12. package/dist/api/data/test_av1.ivf +0 -0
  13. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  14. package/dist/api/data/test_vp8.ivf +0 -0
  15. package/dist/api/data/test_vp9.ivf +0 -0
  16. package/dist/api/decoder.d.ts +279 -17
  17. package/dist/api/decoder.js +998 -209
  18. package/dist/api/decoder.js.map +1 -1
  19. package/dist/api/{media-input.d.ts → demuxer.d.ts} +294 -44
  20. package/dist/api/demuxer.js +1968 -0
  21. package/dist/api/demuxer.js.map +1 -0
  22. package/dist/api/encoder.d.ts +308 -50
  23. package/dist/api/encoder.js +1133 -111
  24. package/dist/api/encoder.js.map +1 -1
  25. package/dist/api/filter-presets.d.ts +12 -5
  26. package/dist/api/filter-presets.js +21 -7
  27. package/dist/api/filter-presets.js.map +1 -1
  28. package/dist/api/filter.d.ts +406 -40
  29. package/dist/api/filter.js +966 -139
  30. package/dist/api/filter.js.map +1 -1
  31. package/dist/api/{fmp4.d.ts → fmp4-stream.d.ts} +141 -140
  32. package/dist/api/fmp4-stream.js +539 -0
  33. package/dist/api/fmp4-stream.js.map +1 -0
  34. package/dist/api/hardware.d.ts +58 -6
  35. package/dist/api/hardware.js +127 -11
  36. package/dist/api/hardware.js.map +1 -1
  37. package/dist/api/index.d.ts +6 -4
  38. package/dist/api/index.js +14 -8
  39. package/dist/api/index.js.map +1 -1
  40. package/dist/api/io-stream.d.ts +3 -3
  41. package/dist/api/io-stream.js +5 -4
  42. package/dist/api/io-stream.js.map +1 -1
  43. package/dist/api/{media-output.d.ts → muxer.d.ts} +274 -60
  44. package/dist/api/muxer.js +1934 -0
  45. package/dist/api/muxer.js.map +1 -0
  46. package/dist/api/pipeline.d.ts +77 -29
  47. package/dist/api/pipeline.js +435 -425
  48. package/dist/api/pipeline.js.map +1 -1
  49. package/dist/api/rtp-stream.d.ts +312 -0
  50. package/dist/api/rtp-stream.js +630 -0
  51. package/dist/api/rtp-stream.js.map +1 -0
  52. package/dist/api/types.d.ts +476 -55
  53. package/dist/api/utilities/async-queue.d.ts +91 -0
  54. package/dist/api/utilities/async-queue.js +162 -0
  55. package/dist/api/utilities/async-queue.js.map +1 -0
  56. package/dist/api/utilities/audio-sample.d.ts +1 -1
  57. package/dist/api/utilities/image.d.ts +1 -1
  58. package/dist/api/utilities/index.d.ts +2 -0
  59. package/dist/api/utilities/index.js +4 -0
  60. package/dist/api/utilities/index.js.map +1 -1
  61. package/dist/api/utilities/media-type.d.ts +1 -1
  62. package/dist/api/utilities/pixel-format.d.ts +1 -1
  63. package/dist/api/utilities/sample-format.d.ts +1 -1
  64. package/dist/api/utilities/scheduler.d.ts +169 -0
  65. package/dist/api/utilities/scheduler.js +136 -0
  66. package/dist/api/utilities/scheduler.js.map +1 -0
  67. package/dist/api/utilities/streaming.d.ts +74 -15
  68. package/dist/api/utilities/streaming.js +170 -12
  69. package/dist/api/utilities/streaming.js.map +1 -1
  70. package/dist/api/utilities/timestamp.d.ts +1 -1
  71. package/dist/api/webrtc-stream.d.ts +288 -0
  72. package/dist/api/webrtc-stream.js +440 -0
  73. package/dist/api/webrtc-stream.js.map +1 -0
  74. package/dist/constants/constants.d.ts +51 -1
  75. package/dist/constants/constants.js +47 -1
  76. package/dist/constants/constants.js.map +1 -1
  77. package/dist/constants/encoders.d.ts +2 -1
  78. package/dist/constants/encoders.js +4 -3
  79. package/dist/constants/encoders.js.map +1 -1
  80. package/dist/constants/hardware.d.ts +26 -0
  81. package/dist/constants/hardware.js +27 -0
  82. package/dist/constants/hardware.js.map +1 -0
  83. package/dist/constants/index.d.ts +1 -0
  84. package/dist/constants/index.js +1 -0
  85. package/dist/constants/index.js.map +1 -1
  86. package/dist/lib/binding.d.ts +19 -8
  87. package/dist/lib/binding.js.map +1 -1
  88. package/dist/lib/codec-context.d.ts +87 -0
  89. package/dist/lib/codec-context.js +125 -4
  90. package/dist/lib/codec-context.js.map +1 -1
  91. package/dist/lib/codec-parameters.d.ts +183 -1
  92. package/dist/lib/codec-parameters.js +209 -0
  93. package/dist/lib/codec-parameters.js.map +1 -1
  94. package/dist/lib/codec-parser.d.ts +23 -0
  95. package/dist/lib/codec-parser.js +25 -0
  96. package/dist/lib/codec-parser.js.map +1 -1
  97. package/dist/lib/codec.d.ts +26 -4
  98. package/dist/lib/codec.js +35 -0
  99. package/dist/lib/codec.js.map +1 -1
  100. package/dist/lib/dictionary.js +1 -0
  101. package/dist/lib/dictionary.js.map +1 -1
  102. package/dist/lib/error.js +1 -1
  103. package/dist/lib/error.js.map +1 -1
  104. package/dist/lib/filter-context.d.ts +52 -11
  105. package/dist/lib/filter-context.js +56 -12
  106. package/dist/lib/filter-context.js.map +1 -1
  107. package/dist/lib/filter-graph.d.ts +9 -0
  108. package/dist/lib/filter-graph.js +13 -0
  109. package/dist/lib/filter-graph.js.map +1 -1
  110. package/dist/lib/filter.d.ts +21 -0
  111. package/dist/lib/filter.js +28 -0
  112. package/dist/lib/filter.js.map +1 -1
  113. package/dist/lib/format-context.d.ts +48 -14
  114. package/dist/lib/format-context.js +76 -7
  115. package/dist/lib/format-context.js.map +1 -1
  116. package/dist/lib/frame.d.ts +168 -0
  117. package/dist/lib/frame.js +212 -0
  118. package/dist/lib/frame.js.map +1 -1
  119. package/dist/lib/hardware-device-context.d.ts +3 -2
  120. package/dist/lib/hardware-device-context.js.map +1 -1
  121. package/dist/lib/index.d.ts +1 -0
  122. package/dist/lib/index.js +2 -0
  123. package/dist/lib/index.js.map +1 -1
  124. package/dist/lib/input-format.d.ts +21 -0
  125. package/dist/lib/input-format.js +42 -2
  126. package/dist/lib/input-format.js.map +1 -1
  127. package/dist/lib/native-types.d.ts +48 -26
  128. package/dist/lib/option.d.ts +25 -13
  129. package/dist/lib/option.js +28 -0
  130. package/dist/lib/option.js.map +1 -1
  131. package/dist/lib/output-format.d.ts +22 -1
  132. package/dist/lib/output-format.js +28 -0
  133. package/dist/lib/output-format.js.map +1 -1
  134. package/dist/lib/packet.d.ts +35 -0
  135. package/dist/lib/packet.js +52 -2
  136. package/dist/lib/packet.js.map +1 -1
  137. package/dist/lib/stream.d.ts +126 -0
  138. package/dist/lib/stream.js +188 -5
  139. package/dist/lib/stream.js.map +1 -1
  140. package/dist/lib/sync-queue.d.ts +179 -0
  141. package/dist/lib/sync-queue.js +197 -0
  142. package/dist/lib/sync-queue.js.map +1 -0
  143. package/dist/lib/types.d.ts +27 -1
  144. package/dist/lib/utilities.d.ts +281 -53
  145. package/dist/lib/utilities.js +298 -55
  146. package/dist/lib/utilities.js.map +1 -1
  147. package/install/check.js +18 -7
  148. package/package.json +20 -19
  149. package/dist/api/fmp4.js +0 -710
  150. package/dist/api/fmp4.js.map +0 -1
  151. package/dist/api/media-input.js +0 -1075
  152. package/dist/api/media-input.js.map +0 -1
  153. package/dist/api/media-output.js +0 -1040
  154. package/dist/api/media-output.js.map +0 -1
  155. package/dist/api/webrtc.d.ts +0 -664
  156. package/dist/api/webrtc.js +0 -1132
  157. package/dist/api/webrtc.js.map +0 -1
@@ -0,0 +1,91 @@
1
+ /**
2
+ * AsyncQueue provides a promise-based blocking queue similar to FFmpeg's ThreadQueue.
3
+ *
4
+ * Unlike FFmpeg's pthread-based blocking, this uses Promises to achieve
5
+ * non-blocking async behavior while maintaining queue semantics.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const queue = new AsyncQueue<Frame>(8);
10
+ *
11
+ * // Producer
12
+ * await queue.send(frame); // Blocks if queue full
13
+ *
14
+ * // Consumer
15
+ * const frame = await queue.receive(); // Blocks if queue empty
16
+ *
17
+ * // Cleanup
18
+ * queue.close();
19
+ * ```
20
+ */
21
+ export declare class AsyncQueue<T> {
22
+ private queue;
23
+ private sendWaiters;
24
+ private receiveWaiters;
25
+ private maxSize;
26
+ private closed;
27
+ /**
28
+ * Creates a new AsyncQueue.
29
+ *
30
+ * @param maxSize Maximum number of items in queue before send() blocks
31
+ */
32
+ constructor(maxSize: number);
33
+ /**
34
+ * Current number of items in the queue.
35
+ */
36
+ get size(): number;
37
+ /**
38
+ * Whether the queue is closed.
39
+ */
40
+ get isClosed(): boolean;
41
+ /**
42
+ * Maximum queue size (from constructor).
43
+ */
44
+ get capacity(): number;
45
+ /**
46
+ * Number of producers waiting to send (backpressure indicator).
47
+ */
48
+ get waitingSenders(): number;
49
+ /**
50
+ * Number of consumers waiting to receive.
51
+ */
52
+ get waitingReceivers(): number;
53
+ /**
54
+ * Sends an item to the queue.
55
+ *
56
+ * If the queue is full, this method blocks (awaits) until space is available.
57
+ *
58
+ * @param item Item to send
59
+ *
60
+ * @returns Promise that resolves when item is sent
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * await queue.send(item);
65
+ * ```
66
+ */
67
+ send(item: T): Promise<void>;
68
+ /**
69
+ * Receives an item from the queue.
70
+ *
71
+ * If the queue is empty and not closed, this method blocks (awaits) until an item is available.
72
+ * If the queue is closed and empty, returns null.
73
+ *
74
+ * @returns Next item from queue, or null if closed and empty
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const item = await queue.receive();
79
+ * ```
80
+ */
81
+ receive(): Promise<T | null>;
82
+ /**
83
+ * Closes the queue, rejecting any pending sends and resolving pending receives with null.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * queue.close();
88
+ * ```
89
+ */
90
+ close(): void;
91
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * AsyncQueue provides a promise-based blocking queue similar to FFmpeg's ThreadQueue.
3
+ *
4
+ * Unlike FFmpeg's pthread-based blocking, this uses Promises to achieve
5
+ * non-blocking async behavior while maintaining queue semantics.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const queue = new AsyncQueue<Frame>(8);
10
+ *
11
+ * // Producer
12
+ * await queue.send(frame); // Blocks if queue full
13
+ *
14
+ * // Consumer
15
+ * const frame = await queue.receive(); // Blocks if queue empty
16
+ *
17
+ * // Cleanup
18
+ * queue.close();
19
+ * ```
20
+ */
21
+ export class AsyncQueue {
22
+ queue = [];
23
+ sendWaiters = [];
24
+ receiveWaiters = [];
25
+ maxSize;
26
+ closed = false;
27
+ /**
28
+ * Creates a new AsyncQueue.
29
+ *
30
+ * @param maxSize Maximum number of items in queue before send() blocks
31
+ */
32
+ constructor(maxSize) {
33
+ if (maxSize <= 0) {
34
+ maxSize = 1;
35
+ }
36
+ this.maxSize = maxSize;
37
+ }
38
+ /**
39
+ * Current number of items in the queue.
40
+ */
41
+ get size() {
42
+ return this.queue.length;
43
+ }
44
+ /**
45
+ * Whether the queue is closed.
46
+ */
47
+ get isClosed() {
48
+ return this.closed;
49
+ }
50
+ /**
51
+ * Maximum queue size (from constructor).
52
+ */
53
+ get capacity() {
54
+ return this.maxSize;
55
+ }
56
+ /**
57
+ * Number of producers waiting to send (backpressure indicator).
58
+ */
59
+ get waitingSenders() {
60
+ return this.sendWaiters.length;
61
+ }
62
+ /**
63
+ * Number of consumers waiting to receive.
64
+ */
65
+ get waitingReceivers() {
66
+ return this.receiveWaiters.length;
67
+ }
68
+ /**
69
+ * Sends an item to the queue.
70
+ *
71
+ * If the queue is full, this method blocks (awaits) until space is available.
72
+ *
73
+ * @param item Item to send
74
+ *
75
+ * @returns Promise that resolves when item is sent
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * await queue.send(item);
80
+ * ```
81
+ */
82
+ async send(item) {
83
+ if (this.closed) {
84
+ return;
85
+ }
86
+ // Block if queue full
87
+ while (this.queue.length >= this.maxSize && !this.closed) {
88
+ await new Promise((resolve) => this.sendWaiters.push(resolve));
89
+ }
90
+ if (this.closed) {
91
+ return;
92
+ }
93
+ this.queue.push(item);
94
+ // Wake up one receiver if waiting (just signal, don't remove item)
95
+ const receiver = this.receiveWaiters.shift();
96
+ if (receiver) {
97
+ receiver(); // Signal that item is available
98
+ }
99
+ }
100
+ /**
101
+ * Receives an item from the queue.
102
+ *
103
+ * If the queue is empty and not closed, this method blocks (awaits) until an item is available.
104
+ * If the queue is closed and empty, returns null.
105
+ *
106
+ * @returns Next item from queue, or null if closed and empty
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const item = await queue.receive();
111
+ * ```
112
+ */
113
+ async receive() {
114
+ // Loop until we get an item or queue is closed
115
+ while (true) {
116
+ // If queue has items, return immediately
117
+ if (this.queue.length > 0) {
118
+ const item = this.queue.shift();
119
+ // Wake up one sender if waiting
120
+ const sender = this.sendWaiters.shift();
121
+ if (sender) {
122
+ sender();
123
+ }
124
+ return item;
125
+ }
126
+ // If closed and empty, return null
127
+ if (this.closed) {
128
+ return null;
129
+ }
130
+ // Block until signaled
131
+ await new Promise((resolve) => {
132
+ this.receiveWaiters.push(resolve);
133
+ });
134
+ // After waking up, loop back to check queue again
135
+ }
136
+ }
137
+ /**
138
+ * Closes the queue, rejecting any pending sends and resolving pending receives with null.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * queue.close();
143
+ * ```
144
+ */
145
+ close() {
146
+ if (this.closed) {
147
+ return;
148
+ }
149
+ this.closed = true;
150
+ // Wake up all waiting senders
151
+ const senders = this.sendWaiters.splice(0);
152
+ for (const sender of senders) {
153
+ sender();
154
+ }
155
+ // Wake up all waiting receivers (they will get null from empty queue check)
156
+ const receivers = this.receiveWaiters.splice(0);
157
+ for (const receiver of receivers) {
158
+ receiver();
159
+ }
160
+ }
161
+ }
162
+ //# sourceMappingURL=async-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-queue.js","source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,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,EAAE,CAAC;QACX,CAAC;QAED,4EAA4E;QAC5E,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAChD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import type { AVSampleFormat } from '../../constants/constants.js';
1
+ import type { AVSampleFormat } from '../../constants/index.js';
2
2
  /**
3
3
  * Audio sample allocation result.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { AVPixelFormat } from '../../constants/constants.js';
1
+ import type { AVPixelFormat } from '../../constants/index.js';
2
2
  /**
3
3
  * Image buffer allocation result.
4
4
  */
@@ -6,3 +6,5 @@ export { PixelFormatUtils } from './pixel-format.js';
6
6
  export { SampleFormatUtils } from './sample-format.js';
7
7
  export { TimestampUtils } from './timestamp.js';
8
8
  export { StreamingUtils } from './streaming.js';
9
+ export { AsyncQueue } from './async-queue.js';
10
+ export { Scheduler } from './scheduler.js';
@@ -14,4 +14,8 @@ export { SampleFormatUtils } from './sample-format.js';
14
14
  export { TimestampUtils } from './timestamp.js';
15
15
  // Streaming
16
16
  export { StreamingUtils } from './streaming.js';
17
+ // AsyncQueue
18
+ export { AsyncQueue } from './async-queue.js';
19
+ // Scheduler
20
+ export { Scheduler } from './scheduler.js';
17
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/utilities/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EAAE,gBAAgB,EAA0D,MAAM,mBAAmB,CAAC;AAE7G,kBAAkB;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,QAAQ;AACR,OAAO,EAAE,UAAU,EAAwB,MAAM,YAAY,CAAC;AAE9D,QAAQ;AACR,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,eAAe;AACf,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,gBAAgB;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/utilities/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EAAE,gBAAgB,EAA0D,MAAM,mBAAmB,CAAC;AAE7G,kBAAkB;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,QAAQ;AACR,OAAO,EAAE,UAAU,EAAwB,MAAM,YAAY,CAAC;AAE9D,QAAQ;AACR,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,eAAe;AACf,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,gBAAgB;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,aAAa;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,YAAY;AACZ,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { AVMediaType } from '../../constants/constants.js';
1
+ import type { AVMediaType } from '../../constants/index.js';
2
2
  /**
3
3
  * Media type utilities.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { AVPixelFormat } from '../../constants/constants.js';
1
+ import type { AVPixelFormat } from '../../constants/index.js';
2
2
  /**
3
3
  * Video pixel format utilities.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { AVSampleFormat } from '../../constants/constants.js';
1
+ import type { AVSampleFormat } from '../../constants/index.js';
2
2
  /**
3
3
  * Audio sample format utilities.
4
4
  *
@@ -0,0 +1,169 @@
1
+ import { Muxer } from '../muxer.js';
2
+ import type { Frame, Packet } from '../../lib/index.js';
3
+ import type { BitStreamFilterAPI } from '../bitstream-filter.js';
4
+ import type { Encoder } from '../encoder.js';
5
+ import type { FilterAPI } from '../filter.js';
6
+ export interface SchedulableComponent<TItem = Packet | Frame> {
7
+ sendToQueue(item: TItem): Promise<void>;
8
+ flushPipeline(): Promise<void>;
9
+ pipeTo(target: FilterAPI | Encoder | BitStreamFilterAPI | Muxer, streamIndex?: number): any;
10
+ }
11
+ /**
12
+ * Pipeline scheduler for chaining components.
13
+ *
14
+ * Allows piping between components (Decoder → Filter → Encoder → Output).
15
+ */
16
+ export declare class Scheduler<TSend = Packet | Frame> implements AsyncDisposable {
17
+ private firstComponent;
18
+ /** @internal */
19
+ lastComponent: SchedulableComponent<any>;
20
+ /**
21
+ * @param firstComponent - First component in the pipeline
22
+ *
23
+ * @param lastComponent - Last component in the pipeline (defaults to firstComponent)
24
+ *
25
+ * @internal
26
+ */
27
+ constructor(firstComponent: SchedulableComponent<TSend>, lastComponent?: SchedulableComponent<any>);
28
+ /**
29
+ * Pipe output to a filter component.
30
+ *
31
+ * @param target - Filter to receive frames
32
+ *
33
+ * @returns Scheduler for continued chaining
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * decoder.pipeTo(filter1).pipeTo(filter2)
38
+ * ```
39
+ */
40
+ pipeTo(target: FilterAPI): Scheduler<TSend>;
41
+ /**
42
+ * Pipe output to an encoder component.
43
+ *
44
+ * @param target - Encoder to receive frames
45
+ *
46
+ * @returns Scheduler for continued chaining
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * decoder.pipeTo(filter).pipeTo(encoder)
51
+ * ```
52
+ */
53
+ pipeTo(target: Encoder): Scheduler<TSend>;
54
+ /**
55
+ * Pipe output to a bitstream filter component.
56
+ *
57
+ * @param target - BitStreamFilter to receive packets
58
+ *
59
+ * @returns Scheduler for continued chaining
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * decoder.pipeTo(encoder).pipeTo(bsf).pipeTo(output, 0)
64
+ * ```
65
+ */
66
+ pipeTo(target: BitStreamFilterAPI): Scheduler<TSend>;
67
+ /**
68
+ * Pipe output to a muxer (final stage).
69
+ *
70
+ * @param output - Muxer to write to
71
+ *
72
+ * @param streamIndex - Stream index in output
73
+ *
74
+ * @returns Control interface without pipeTo
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const control = decoder
79
+ * .pipeTo(encoder)
80
+ * .pipeTo(output, 0);
81
+ *
82
+ * await control.send(packet);
83
+ * ```
84
+ */
85
+ pipeTo(output: Muxer, streamIndex: number): SchedulerControl<TSend>;
86
+ /**
87
+ * Send an item into the pipeline.
88
+ *
89
+ * @param item - Packet or Frame to process
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * try {
94
+ * await scheduler.send(packet);
95
+ * } catch (error) {
96
+ * console.error('Pipeline error:', error);
97
+ * }
98
+ * ```
99
+ */
100
+ send(item: TSend): Promise<void>;
101
+ /**
102
+ * Flush the pipeline.
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * await scheduler.flush();
107
+ * ```
108
+ */
109
+ flush(): Promise<void>;
110
+ /**
111
+ * Cleanup resources.
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * await using scheduler;
116
+ * ```
117
+ */
118
+ [Symbol.asyncDispose](): Promise<void>;
119
+ }
120
+ /**
121
+ * Control interface for completed pipelines.
122
+ *
123
+ * Provides control methods without pipeTo() - this is the final
124
+ * stage after piping to Muxer.
125
+ *
126
+ * @template TSend - The input type flowing through the pipeline
127
+ */
128
+ export declare class SchedulerControl<TSend = Packet | Frame> implements AsyncDisposable {
129
+ private firstComponent;
130
+ /**
131
+ * @param firstComponent - First component in the pipeline
132
+ *
133
+ * @internal
134
+ */
135
+ constructor(firstComponent: SchedulableComponent<TSend>);
136
+ /**
137
+ * Send an item into the pipeline.
138
+ *
139
+ * @param item - Packet or Frame to process
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * try {
144
+ * await control.send(packet);
145
+ * } catch (error) {
146
+ * console.error('Pipeline error:', error);
147
+ * }
148
+ * ```
149
+ */
150
+ send(item: TSend): Promise<void>;
151
+ /**
152
+ * Flush the pipeline.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * await control.flush();
157
+ * ```
158
+ */
159
+ flush(): Promise<void>;
160
+ /**
161
+ * Cleanup resources.
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * await using control;
166
+ * ```
167
+ */
168
+ [Symbol.asyncDispose](): Promise<void>;
169
+ }
@@ -0,0 +1,136 @@
1
+ import { Muxer } from '../muxer.js';
2
+ /**
3
+ * Pipeline scheduler for chaining components.
4
+ *
5
+ * Allows piping between components (Decoder → Filter → Encoder → Output).
6
+ */
7
+ export class Scheduler {
8
+ firstComponent;
9
+ /** @internal */
10
+ lastComponent;
11
+ /**
12
+ * @param firstComponent - First component in the pipeline
13
+ *
14
+ * @param lastComponent - Last component in the pipeline (defaults to firstComponent)
15
+ *
16
+ * @internal
17
+ */
18
+ constructor(firstComponent, lastComponent) {
19
+ this.firstComponent = firstComponent;
20
+ this.lastComponent = lastComponent ?? firstComponent;
21
+ }
22
+ pipeTo(target, streamIndex) {
23
+ if (typeof this.lastComponent.pipeTo === 'function') {
24
+ if (target instanceof Muxer) {
25
+ // Start the pipe task (encoder -> output)
26
+ this.lastComponent.pipeTo(target, streamIndex);
27
+ // Return control with correct firstComponent (not lastComponent!)
28
+ return new SchedulerControl(this.firstComponent);
29
+ }
30
+ else {
31
+ const resultScheduler = this.lastComponent.pipeTo(target);
32
+ // Keep the original firstComponent, update to new lastComponent
33
+ return new Scheduler(this.firstComponent, resultScheduler.lastComponent);
34
+ }
35
+ }
36
+ throw new Error('Last component does not support pipeTo');
37
+ }
38
+ /**
39
+ * Send an item into the pipeline.
40
+ *
41
+ * @param item - Packet or Frame to process
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * try {
46
+ * await scheduler.send(packet);
47
+ * } catch (error) {
48
+ * console.error('Pipeline error:', error);
49
+ * }
50
+ * ```
51
+ */
52
+ async send(item) {
53
+ await this.firstComponent.sendToQueue(item);
54
+ }
55
+ /**
56
+ * Flush the pipeline.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * await scheduler.flush();
61
+ * ```
62
+ */
63
+ async flush() {
64
+ await this.firstComponent.flushPipeline();
65
+ }
66
+ /**
67
+ * Cleanup resources.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * await using scheduler;
72
+ * ```
73
+ */
74
+ async [Symbol.asyncDispose]() {
75
+ await this.flush();
76
+ }
77
+ }
78
+ /**
79
+ * Control interface for completed pipelines.
80
+ *
81
+ * Provides control methods without pipeTo() - this is the final
82
+ * stage after piping to Muxer.
83
+ *
84
+ * @template TSend - The input type flowing through the pipeline
85
+ */
86
+ export class SchedulerControl {
87
+ firstComponent;
88
+ /**
89
+ * @param firstComponent - First component in the pipeline
90
+ *
91
+ * @internal
92
+ */
93
+ constructor(firstComponent) {
94
+ this.firstComponent = firstComponent;
95
+ }
96
+ /**
97
+ * Send an item into the pipeline.
98
+ *
99
+ * @param item - Packet or Frame to process
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * try {
104
+ * await control.send(packet);
105
+ * } catch (error) {
106
+ * console.error('Pipeline error:', error);
107
+ * }
108
+ * ```
109
+ */
110
+ async send(item) {
111
+ await this.firstComponent.sendToQueue(item);
112
+ }
113
+ /**
114
+ * Flush the pipeline.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * await control.flush();
119
+ * ```
120
+ */
121
+ async flush() {
122
+ await this.firstComponent.flushPipeline();
123
+ }
124
+ /**
125
+ * Cleanup resources.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * await using control;
130
+ * ```
131
+ */
132
+ async [Symbol.asyncDispose]() {
133
+ await this.flush();
134
+ }
135
+ }
136
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../../src/api/utilities/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAapC;;;;GAIG;AACH,MAAM,OAAO,SAAS;IACZ,cAAc,CAA8B;IAEpD,gBAAgB;IAChB,aAAa,CAA4B;IAEzC;;;;;;OAMG;IACH,YAAY,cAA2C,EAAE,aAAyC;QAChG,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,cAAc,CAAC;IACvD,CAAC;IAgED,MAAM,CAAC,MAAwD,EAAE,WAAoB;QACnF,IAAI,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACpD,IAAI,MAAM,YAAY,KAAK,EAAE,CAAC;gBAC5B,0CAA0C;gBAC1C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;gBAC/C,kEAAkE;gBAClE,OAAO,IAAI,gBAAgB,CAAQ,IAAI,CAAC,cAAc,CAAC,CAAC;YAC1D,CAAC;iBAAM,CAAC;gBACN,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC1D,gEAAgE;gBAChE,OAAO,IAAI,SAAS,CAAQ,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,IAAI,CAAC,IAAW;QACpB,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,C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