webcamoid / akvirtualcamera

akvirtualcamera, virtual camera for Mac and Windows
GNU General Public License v3.0
408 stars 52 forks source link

Forbid other programs to use the virtual camera when already in use #67

Open rnixik opened 2 years ago

rnixik commented 2 years ago

I set two formats: 720p and 480p for my virtual camera. I want to edit source code to forbid getting stream from the same camera when we are already streaming in other format like my real web come does. I'm not sure if this is possible with DShow. If you think is it possible, could you please suggest class or method to add mutex/if?

hipersayanX commented 2 years ago

I've read your question many times but I did not understand what you want to do.

I don't understand your use case at all, please explain. Anyway all the frames sent to the vcam are received here, and then sent to the client here.

rnixik commented 2 years ago

Do you want to send different streams depending of the video format selected by the client?

No

All the virtual cameras are receiving the same stream independently of the selected vcam? (maybe a bug?)

No

Do you want to forbid other programs to use the virtual camera when already in use?

Yes

I use a web camera in Chrome. I'm getting stream with constraints video: { width: 1280, height: 720 }, but at the same time i'm trying to display a stream with constraints video: { width: 640, height: 480 } with the same camera. My real web cam cannot output streams in different formats, i get a error and this is ok. When i do the same with virtual camera i see both streams. The same for different programs.

Is it possible to implement exclusive mode?

Thank you for your efforts :)

hipersayanX commented 2 years ago

Ok, now I understand, it was not supposed to work like that.

Is it possible to implement exclusive mode?

Yes of course. The camera setup pipeline is basically: getting the camera filter, setup the format, and then call IMediaControl::Run(). If I remember well, IMediaControl::Run(), called IMediaFilter::Run() which is called here, the global state of the vcams are saved here, and you can communicate with the service using the IPC bridge. You can probably check if the vcam has other listeners beside current instance and then return an error when calling IMediaFilter::Run(). This is the documentation for IMediaFilter::Run(). It probably need a bit more of thinking, but you have a starting point there.