mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Make MediaSource.close return void
This commit is contained in:
@@ -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:
|
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
|
```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.
|
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:
|
If you add the entire subtitle file at once, make sure to [close the source](#closing-sources) immediately after:
|
||||||
```ts
|
```ts
|
||||||
void textSource.close();
|
textSource.close();
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also add cues individually in small chunks:
|
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)
|
// 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
|
// 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.
|
// simplicity, we're rendering it after we've cranked through all frames.
|
||||||
const audioBuffer = await offlineAudioContext.startRendering();
|
const audioBuffer = await offlineAudioContext.startRendering();
|
||||||
await audioBufferSource.add(audioBuffer);
|
await audioBufferSource.add(audioBuffer);
|
||||||
void audioBufferSource.close();
|
audioBufferSource.close();
|
||||||
|
|
||||||
clearInterval(progressInterval);
|
clearInterval(progressInterval);
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -499,7 +499,7 @@ export class Conversion {
|
|||||||
this._reportProgress(track.id, packet.timestamp + packet.duration);
|
this._reportProgress(track.id, packet.timestamp + packet.duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
await source.close();
|
source.close();
|
||||||
this._synchronizer.closeTrack(track.id);
|
this._synchronizer.closeTrack(track.id);
|
||||||
})());
|
})());
|
||||||
} else {
|
} else {
|
||||||
@@ -593,7 +593,7 @@ export class Conversion {
|
|||||||
sample.close();
|
sample.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
await source.close();
|
source.close();
|
||||||
this._synchronizer.closeTrack(track.id);
|
this._synchronizer.closeTrack(track.id);
|
||||||
})());
|
})());
|
||||||
}
|
}
|
||||||
@@ -670,7 +670,7 @@ export class Conversion {
|
|||||||
this._reportProgress(track.id, packet.timestamp + packet.duration);
|
this._reportProgress(track.id, packet.timestamp + packet.duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
await source.close();
|
source.close();
|
||||||
this._synchronizer.closeTrack(track.id);
|
this._synchronizer.closeTrack(track.id);
|
||||||
})());
|
})());
|
||||||
} else {
|
} else {
|
||||||
@@ -763,7 +763,7 @@ export class Conversion {
|
|||||||
sample.close();
|
sample.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
await source.close();
|
source.close();
|
||||||
this._synchronizer.closeTrack(track.id);
|
this._synchronizer.closeTrack(track.id);
|
||||||
})());
|
})());
|
||||||
}
|
}
|
||||||
@@ -822,7 +822,7 @@ export class Conversion {
|
|||||||
|
|
||||||
await resampler.finalize();
|
await resampler.finalize();
|
||||||
|
|
||||||
await source.close();
|
source.close();
|
||||||
this._synchronizer.closeTrack(track.id);
|
this._synchronizer.closeTrack(track.id);
|
||||||
})());
|
})());
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -81,7 +81,7 @@ export abstract class MediaSource {
|
|||||||
*/
|
*/
|
||||||
close() {
|
close() {
|
||||||
if (this._closingPromise) {
|
if (this._closingPromise) {
|
||||||
throw new Error('Source already closed.');
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectedTrack = this._connectedTrack;
|
const connectedTrack = this._connectedTrack;
|
||||||
@@ -94,7 +94,7 @@ export abstract class MediaSource {
|
|||||||
throw new Error('Cannot call close before output has been started.');
|
throw new Error('Cannot call close before output has been started.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._closingPromise = (async () => {
|
this._closingPromise = (async () => {
|
||||||
await this._flushAndClose();
|
await this._flushAndClose();
|
||||||
|
|
||||||
this._closed = true;
|
this._closed = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user