Skip to content

Commit 5ca4f6f

Browse files
committed
Fix potential race condition in the decoder
1 parent 210a3d6 commit 5ca4f6f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

samples/encode-decode-worker/js/stream_worker.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ class pipeline {
120120
}
121121
});
122122
},
123-
transform(chunk, controller) {
123+
async transform(chunk, controller) {
124124
if (this.decoder.state != "closed") {
125125
if (chunk.type == "config") {
126-
let config = JSON.parse(chunk.config);
127-
VideoDecoder.isConfigSupported(config).then((decoderSupport) => {
128-
if(decoderSupport.supported) {
129-
this.decoder.configure(decoderSupport.config);
130-
self.postMessage({text: 'Decoder successfully configured:\n' + JSON.stringify(decoderSupport.config)});
131-
} else {
132-
self.postMessage({severity: 'fatal', text: 'Config not supported:\n' + JSON.stringify(decoderSupport.config)});
133-
}
134-
})
135-
.catch((e) => {
136-
self.postMessage({severity: 'fatal', text: `Configuration error: ${e.message}`});
137-
})
126+
let config = JSON.parse(chunk.config);
127+
try {
128+
const decoderSupport = await VideoDecoder.isConfigSupported(config);
129+
if (decoderSupport.supported) {
130+
this.decoder.configure(decoderSupport.config);
131+
self.postMessage({text: 'Decoder successfully configured:\n' + JSON.stringify(decoderSupport.config)});
132+
} else {
133+
self.postMessage({severity: 'fatal', text: 'Config not supported:\n' + JSON.stringify(decoderSupport.config)});
134+
}
135+
} catch (e) {
136+
self.postMessage({severity: 'fatal', text: `Configuration error: ${e.message}`});
137+
}
138138
} else {
139139
try {
140140
const queue = this.decoder.decodeQueueSize;

0 commit comments

Comments
 (0)