Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About web worker #29

Open
MarcoQQ opened this issue Aug 14, 2020 · 4 comments
Open

About web worker #29

MarcoQQ opened this issue Aug 14, 2020 · 4 comments

Comments

@MarcoQQ
Copy link

MarcoQQ commented Aug 14, 2020

Hi, do you know how to combine yuv-canvas with web-worker? It I want to use offscreen canvas, it seems that I have to rewrite yuv-canvas.

@bvibber
Copy link
Owner

bvibber commented Aug 17, 2020

My project produces frames in a web worker, postMessages them to the main thread (transferring the buffers to avoid additional copies), and then the main thread uses yuv-canvas directly.

I don't know anything about offscreen canvas or what that entails.

@wangzongxu
Copy link

I need to draw multiple videos on one page, but yuv-Canvas has a lot of calculation, which makes the page very slow.
I want to perform calculations in a Web worker. Can I do that

@hamburger-l
Copy link

I need to draw multiple videos on one page, but yuv-Canvas has a lot of calculation, which makes the page very slow. I want to perform calculations in a Web worker. Can I do that

解决了吗兄弟?

@mihailj
Copy link

mihailj commented May 15, 2023

Hello,

If anyone still needs an answer to this question: yes, it's possible to use yuv-canvas in a web worker with an offscreen canvas with some small changes.

This function now crashes if you try to use it in a web worker:

https://github.com/brion/yuv-canvas/blob/main/src/WebGLFrameSink.js#L472

It crashes because it cannot find the document, this object is not available in the web worker.

So you can move the feature detection outside of the web worker in the main thread, attach the status to a window global variable, example:

function webGLDetection() {
        // do the detection here...
	return true;
}

window.webGLAvailable = webGLDetection();

If you want you can copy the feature detection from the original WebGLFrameSink.isAvailable function with small changes.

Then you can modify the WebGLFrameSink.isAvailable function by using the window variable:

	WebGLFrameSink.isAvailable = function() {
		return window.webGLAvailable;
	}

Then in the web worker where you include the bundle script you need to declare the window variable before you include the JS file.

window = globalThis;

importScripts('./js/bundle.js');

Hope this helps to give you an idea and that I didn't miss anything.

Cheers,
Mihail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants