Skip to content

Commit fd0c13f

Browse files
dalecurtisDjuffin
authored andcommitted
Ensure samples are flushed after demuxing finishes
Doesn't matter much for the current test video, but can be an issue with other test videos
1 parent 0d173fe commit fd0c13f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

samples/video-decode-display/demuxer_mp4.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ importScripts("../third_party/mp4boxjs/mp4box.all.min.js");
22

33
// Wraps an MP4Box File as a WritableStream underlying sink.
44
class MP4FileSink {
5+
#onEndOfStream = null;
56
#setStatus = null;
67
#file = null;
78
#offset = 0;
89

9-
constructor(file, setStatus) {
10+
constructor(file, onEndOfStream, setStatus) {
1011
this.#file = file;
1112
this.#setStatus = setStatus;
13+
this.#onEndOfStream = onEndOfStream;
1214
}
1315

1416
write(chunk) {
@@ -28,6 +30,7 @@ class MP4FileSink {
2830
close() {
2931
this.#setStatus("fetch", "Done");
3032
this.#file.flush();
33+
this.#onEndOfStream();
3134
}
3235
}
3336

@@ -39,7 +42,7 @@ class MP4Demuxer {
3942
#setStatus = null;
4043
#file = null;
4144

42-
constructor(uri, {onConfig, onChunk, setStatus}) {
45+
constructor(uri, {onConfig, onChunk, onEndOfStream, setStatus}) {
4346
this.#onConfig = onConfig;
4447
this.#onChunk = onChunk;
4548
this.#setStatus = setStatus;
@@ -51,7 +54,7 @@ class MP4Demuxer {
5154
this.#file.onSamples = this.#onSamples.bind(this);
5255

5356
// Fetch the file and pipe the data through.
54-
const fileSink = new MP4FileSink(this.#file, setStatus);
57+
const fileSink = new MP4FileSink(this.#file, onEndOfStream, setStatus);
5558
fetch(uri).then(response => {
5659
// highWaterMark should be large enough for smooth streaming, but lower is
5760
// better for memory usage.

samples/video-decode-display/worker.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ function start({dataUri, rendererName, canvas}) {
8787
onChunk(chunk) {
8888
decoder.decode(chunk);
8989
},
90+
onEndOfStream() {
91+
decoder.flush();
92+
},
9093
setStatus
9194
});
9295
}

0 commit comments

Comments
 (0)