tinyh264
tinyh264 copied to clipboard
onMessage is never called
Hi there,
I am trying to use the library, but somehow onMessage never gets called. This is how I initialize the decoder:
initDecoder = async () => {
console.log('initDecoder')
this.tinyH264Worker = new TinyH264Worker()
this.tinyH264Worker.addEventListener('message', e => {
// WHY IS THIS NEVER CALLED?
const message = /** @type {{type:string, width:number, height:number, data:ArrayBuffer, renderStateId:number}} */ e.data
switch (message.type) {
case 'pictureReady':
this.onPictureReady(message)
break
case 'decoderReady':
this.isDecoderReady = true;
break
}
})
}
And this is how I pass the NALUnits:
pushNalUnit = chunk => {
this.h264samples.push(new Uint8Array(chunk))
const h264Nal = this.h264samples.shift()
if (h264Nal != null) {
this.tinyH264Worker.postMessage(
{
type: 'decode',
data: h264Nal.buffer,
offset: h264Nal.byteOffset,
length: h264Nal.byteLength,
renderStateId: this.videoStreamId
},
[h264Nal.buffer]
)
}
}
Any idea what I am missing? I am running this inside Electron (Nodejs version 14.16.)
process.versions:
{
node: '14.16.0',
v8: '8.9.255.25-electron.0',
uv: '1.40.0',
zlib: '1.2.11',
brotli: '1.0.9',
ares: '1.16.1',
modules: '87',
nghttp2: '1.41.0',
napi: '7',
llhttp: '2.1.3',
openssl: '1.1.1',
icu: '68.1',
unicode: '13.0',
electron: '12.2.3',
chrome: '89.0.4389.128'
}
The 'pictureReady' message is send from the webworker that runs the wasm decoder: https://github.com/udevbe/tinyh264/blob/524a702b6d98f8b9271238fdda9a064a1e6861e7/src/TinyH264Worker.js#L17
You can check if that line gets called. If that is not the case, it usually means that the data you feed to the decoder is either incorrect or unsupported/too complex for the decoder.
Thanks @Zubnix! can you tell me how I can check if this line is run? AFAIK console.log doesn't work in webworkers, right?