Skip to content

onMessage is never called #48

@stoefln

Description

@stoefln

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'
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions