Skip to content

Commit 4c484cf

Browse files
committed
fix(VideoDecoder): flush before closing the decoder
It seems to reduce the frequency of the 'Cannot call decode on closed codec' error
1 parent 824c7a8 commit 4c484cf

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

vue-components/src/components/VideoDecoderDisplayArea.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default {
2121
cleanup() {
2222
if (this.worker) {
2323
this.worker.terminate();
24-
this.worker = null;
2524
}
2625

2726
// unsub trame.rca.topic.stream

vue-components/src/utils/decoder.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ onmessage = async function({ data: msg }) {
7070
this.decoder.reset();
7171
break;
7272
case 6: // close
73+
// flush before close() to avoid currepoted state.
74+
// calling postMessage(flush)
75+
// postMessage(close) is not enough since the second
76+
// abort the first before it finishes.
77+
await this.decoder.flush();
7378
this.decoder.close();
7479
break;
7580
}
@@ -134,7 +139,9 @@ export class DecoderWorker {
134139

135140
terminate() {
136141
this.worker.postMessage({ action: CLOSE });
137-
this.worker.terminate();
138-
this.worker = null;
142+
// don't terminate immediately we need to wail for the video encoder to finish flushing
143+
// not sure how to achieve this ...
144+
//this.worker.terminate();
145+
//this.worker = null;
139146
}
140147
}

0 commit comments

Comments
 (0)