weixin_39669204 2020-11-22 02:17 采纳率: 0%
浏览 0

Run decoder in a Worker thread

Currently the entire decoder runs on the web page's main JavaScript context -- the browser's UI thread. Especially on slower CPUs such as ARM phones and tablets this really hurts the responsiveness of the page, and it probably hurts audio output as well.

The entire decoder should be able to run in a Worker thread pretty easily. It can handle its network input with an XHR directly, and can send ArrayBuffers of pixel & audio data back up to the web page via postMessage() with the transferrable option to avoid extra data copies.

该提问来源于开源项目:brion/ogv.js

  • 写回答

5条回答 默认 最新

  • weixin_39669204 2020-11-22 02:17
    关注

    Made an attempt to break just the YCbCr->RGB conversion out to a worker, since it's a nicely standalone bit of code that's still fairly expensive: https://github.com/brion/ogv.js/commits/color-worker

    Unfortunately there's a few funky issues, and I wasn't convinced it was helping much: - extracting a clean YUV buffer from the heap is difficult; the stride in the buffers isn't what is expected so we end up copying a line at a time instead of a full buffer; this may be slowing it down too. - IE 10/11 don't allow transfering ArrayBuffers to a worker or back, so they'll get copied -- this may be slower on mobile devices, which are the targets for using workers to spread CPU activity. - Safari on iOS didn't show a clear win. - It's really easy to end up queueing up too many output frames; need to be less naive on the concurrency model. :)

    评论

报告相同问题?