ennuicastr / libavjs-webcodecs-polyfill

A polyfill for the WebCodecs API. No, really.
82 stars 8 forks source link

error in onmessage handler #24

Closed RavikumarTulugu closed 8 months ago

RavikumarTulugu commented 8 months ago

I am using libavjs/libavjs-webcodecs-polyfill [ 0.4.5 ] in a worker. my libavjs options are { noworker : true } , the behavior is same when the options are { noworker : true, nowasm : true, nosimd : true }. It seems the library's onmessage is interpreting applications messages and trying to act up on them. The libavjsMode is "direct". if the libavjs is in direct mode, why is the library registering onmessage handlers.
Please advise whether my usage is correct.

image

Yahweasel commented 8 months ago

libav.js should only set an onmessage handler if it's loading as a Worker, which suggests that maybe those flags aren't making it from libavjs-webcodecs-polyfill down to libav.js? Can you check the sources tab of the debugger and see whether any worker threads are running that shouldn't be? It's possible that I just stupidly included a call to LibAV that doesn't pass the options.

RavikumarTulugu commented 8 months ago

ok let me dig more and get back.

RavikumarTulugu commented 8 months ago

your comment made me wonder whether the api usage is correct or not. I am instantiating libav and avwebcodecs separately like below.

 if ( ! libav ) {
    libav = await LibAV.LibAV ({ noworker : true, nosimd : true, nowasm : true });  
    if ( libav ) {
      console.log ( 'libav init successful libavjs operating in mode : ', libav.libavjsMode );
      if ( ! libavwebcodecs ) {
        try {
          await LibAVWebCodecs.load(); 
          libavwebcodecs = true;
          console.log ( 'libavwebcodecs init successful' );
        } catch ( error ) {
          console.error ( 'libavwebcodecs failed to initialize error : ', error );
        }    
      }    
    } else 
      console.error ( 'libav failed to initialize' );
  }
  return;
Yahweasel commented 8 months ago

Aha. You don't need to create an instance of libav.js for libavjs-webcodecs-polyfill; it will create its own instances. If you want to pass noworker (or anything else) to the libav.js instance that the polyfill creates, you want the libavOptions option of the polyfill: https://github.com/ennuicastr/libavjs-webcodecs-polyfill/blob/f5922aabb062dc302d071d052cdbd680de383e9f/README.md?plain=1#L28

RavikumarTulugu commented 8 months ago

The instantiation of avwebcodecs is wrong , the right way is await LibAVWebCodecs.load ({ libavOptions : { noworker : true } });