Skip to content

Commit b7a2786

Browse files
committed
Update Changelog
1 parent 798870c commit b7a2786

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

CHANGELOG.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,65 @@ await using screen = await DeviceAPI.openScreen({
4444
| Combined | AVFoundation || DirectShow |
4545
| Screen | ScreenCaptureKit | x11grab | GDI grab |
4646

47+
#### AbortSignal / AbortController Support
48+
49+
All high-level API classes now support `AbortSignal` for cancellation via an optional `signal` property in their options:
50+
51+
- `Demuxer`, `Muxer`, `Decoder`, `Encoder`, `FilterAPI`, `BitStreamFilterAPI` — pass `signal` in options
52+
- `pipeline()` — pass `{ signal }` as the last argument
53+
- Async generators (`packets()`, `frames()`, `packets()`) stop yielding on abort
54+
- Async methods (`decode()`, `encode()`, `writePacket()`, etc.) throw `AbortError` on abort
55+
- Pre-aborted signals are rejected immediately
56+
- `close()` is never affected — cleanup always runs
57+
58+
**Example:**
59+
```typescript
60+
const controller = new AbortController();
61+
62+
await using input = await Demuxer.open('input.mp4', { signal: controller.signal });
63+
using decoder = await Decoder.create(input.video()!, { signal: controller.signal });
64+
65+
// Cancel after 5 seconds
66+
setTimeout(() => controller.abort(), 5000);
67+
68+
try {
69+
for await (const packet of input.packets()) {
70+
for await (const frame of decoder.frames(packet)) {
71+
// Process frame...
72+
}
73+
}
74+
} catch (err) {
75+
if (err.name === 'AbortError') {
76+
console.log('Processing cancelled');
77+
}
78+
}
79+
80+
// Pipeline with signal
81+
const control = pipeline(input, decoder, encoder, output, { signal: controller.signal });
82+
await control.completion;
83+
```
84+
85+
#### Readable & Writable Stream Support
86+
87+
- `Demuxer.open()` now accepts a Node.js `Readable` stream as input, and `Muxer.open()` now accepts a `Writable` stream as output. This enables seamless integration with Node.js stream APIs.
88+
89+
**Example:**
90+
```typescript
91+
import { createReadStream, createWriteStream } from 'fs';
92+
93+
// Demux from a Readable stream
94+
const readable = createReadStream('input.mkv');
95+
await using input = await Demuxer.open(readable, { format: 'matroska' });
96+
97+
// Mux to a Writable stream (use non-seekable formats like mpegts or matroska)
98+
const writable = createWriteStream('output.ts');
99+
await using output = await Muxer.open(writable, { format: 'mpegts' });
100+
```
101+
102+
#### IOContext Synchronous Dispose
103+
104+
- `IOContext` now implements the synchronous `Disposable` interface (`Symbol.dispose`) in addition to `AsyncDisposable`. This allows using `using` (synchronous) instead of `await using` when async cleanup is not needed.
105+
47106
#### IOContext Input Support
48107

49108
- `Demuxer.open()` and `Demuxer.openSync()` now accept a pre-created `IOContext` as input, enabling advanced custom I/O scenarios with more control over buffering and seeking.

examples/api-abort-signal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ console.log('=== Example 2: Manual iteration with AbortSignal ===');
9999
}
100100
}
101101
} catch (err) {
102-
if (err instanceof DOMException && err.name === 'AbortError') {
102+
if (err.name === 'AbortError') {
103103
console.log(`Aborted after ${frameCount} frames.`);
104104
} else {
105105
throw err;
@@ -121,7 +121,7 @@ console.log('=== Example 3: Pre-aborted signal ===');
121121
console.log('This should not be reached');
122122
void input;
123123
} catch (err) {
124-
if (err instanceof DOMException && err.name === 'AbortError') {
124+
if (err.name === 'AbortError') {
125125
console.log('Correctly rejected: Cannot open with pre-aborted signal.');
126126
} else {
127127
throw err;

0 commit comments

Comments
 (0)