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

Unable to make this work in a worker thread #27

Open
grrrwaaa opened this issue Sep 11, 2023 · 2 comments
Open

Unable to make this work in a worker thread #27

grrrwaaa opened this issue Sep 11, 2023 · 2 comments

Comments

@grrrwaaa
Copy link

grrrwaaa commented Sep 11, 2023

I have a basic test of the library working, it's great.

I wanted to move the receiver to a worker thread to free up resources on the main thread, but when I do I either get "No data received" timeouts on the receiver.video() call. The exact same code works fine and I receive streams when in the main thread.

Here's the code for "ndi_worker.js"

const { workerData, parentPort } = require('worker_threads')

const grandiose = require('grandiose');
console.log(grandiose.version(), grandiose.isSupportedCPU())

async function run() {
	let sources = await grandiose.find()
	console.log(sources);
	if (!sources.length) return

	let receiver = await grandiose.receive({ source: sources[0], });
	console.log(receiver)

	let timeout = 1000; // Optional timeout, default is 10000ms
	while (true) {
		try {
			let videoFrame = await receiver.video(timeout);
			//console.log(videoFrame);
		} catch (e) { console.error(e); }
	}
}

run()

And to launch it:

const { Worker } = require('worker_threads')
let ndi_worker = new Worker("./ndi_worker.js")

Output:

NewTek NDI Copyright (C)2015-2018 NewTek, inc. v3.5.9.0
NDI SDK WIN64 00:29:47 Jun 26 2018 3.5.9.0 true
Wait is 10000.
Find status is 1.
Destroying find carrier.
[
  { name: 'DESKTOP-P5UKCTA (OBS)', urlAddress: '130.63.209.196:5961' }
]
Completing some receive creation work.
{
  embedded: [External: 17124ce13d0],    
  video: [Function: video],
  audio: [Function: audio],
  metadata: [Function: metadata],       
  data: [Function: data],
  source: { name: 'DESKTOP-P5UKCTA (OBS)', urlAddress: '130.63.209.196:5961' }, 
  colorFormat: 100,
  bandwidth: 100,
  allowVideoFields: true
}
No data received.
[Error: In file ...  found error: No video data received 
in the requested time interval.] {      
  code: '4040'
}

It's baffling why it would work on the main thread but not on a worker thread. Could there be something in the implementation that assumes main thread somehow?

@dortanes
Copy link

Are you tried to use data() instead of video() or audio() ?

@grrrwaaa
Copy link
Author

Yes, strangely using .data() does work, but .video() does not.

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

2 participants