Make MediaSource.close return void

This commit is contained in:
Vanilagy
2025-06-04 15:39:36 +02:00
parent e45ea24f03
commit 6f020650cc
4 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ await mediaSource.add(...);
When you're done using the source, meaning no additional media data will be added, it's best to close the source as soon as possible:
```ts
void mediaSource.close();
mediaSource.close();
```
Closing sources manually is _technically_ not required and will happen automatically when finalizing the `Output`. However, if your `Output` has multiple tracks and not all of them finish supplying their data at the same time (for example, adding all audio first and then all video), closing sources early will improve performance and lower memory usage. This is because the `Output` can better "plan ahead", knowing it doesn't have to wait for certain tracks anymore (see [Packet buffering](./writing-overview#packet-buffering)). Therefore, it is good practice to always manually close all media sources as soon as you are done using them.
@@ -399,7 +399,7 @@ await textSource.add(text);
If you add the entire subtitle file at once, make sure to [close the source](#closing-sources) immediately after:
```ts
void textSource.close();
textSource.close();
```
You can also add cues individually in small chunks:
@@ -128,13 +128,13 @@ const generateVideo = async () => {
}
// Signal to the output that no more video frames are coming (not necessary, but recommended)
void canvasSource.close();
canvasSource.close();
// Let's render the audio. Ideally, the audio is rendered before the video (or concurrently to it), but for
// simplicity, we're rendering it after we've cranked through all frames.
const audioBuffer = await offlineAudioContext.startRendering();
await audioBufferSource.add(audioBuffer);
void audioBufferSource.close();
audioBufferSource.close();
clearInterval(progressInterval);
+5 -5
View File
@@ -499,7 +499,7 @@ export class Conversion {
this._reportProgress(track.id, packet.timestamp + packet.duration);
}
await source.close();
source.close();
this._synchronizer.closeTrack(track.id);
})());
} else {
@@ -593,7 +593,7 @@ export class Conversion {
sample.close();
}
await source.close();
source.close();
this._synchronizer.closeTrack(track.id);
})());
}
@@ -670,7 +670,7 @@ export class Conversion {
this._reportProgress(track.id, packet.timestamp + packet.duration);
}
await source.close();
source.close();
this._synchronizer.closeTrack(track.id);
})());
} else {
@@ -763,7 +763,7 @@ export class Conversion {
sample.close();
}
await source.close();
source.close();
this._synchronizer.closeTrack(track.id);
})());
}
@@ -822,7 +822,7 @@ export class Conversion {
await resampler.finalize();
await source.close();
source.close();
this._synchronizer.closeTrack(track.id);
})());
+2 -2
View File
@@ -81,7 +81,7 @@ export abstract class MediaSource {
*/
close() {
if (this._closingPromise) {
throw new Error('Source already closed.');
return;
}
const connectedTrack = this._connectedTrack;
@@ -94,7 +94,7 @@ export abstract class MediaSource {
throw new Error('Cannot call close before output has been started.');
}
return this._closingPromise = (async () => {
this._closingPromise = (async () => {
await this._flushAndClose();
this._closed = true;