Page 1 of 1

Possible to completely block webcam from VirtualBox?

Posted: 12. Jul 2020, 02:36
by vb_user_6128
I have a Windows 10 Host, a Ubuntu 18.04.4 LTS Guest, and a Logitech C615 webcam plugged into a USB port on my monitor. If I don't setup any USB filters, start my Guest VM, then run the following at an elevated command prompt in the Windows 10 Host:

Code: Select all

powercfg /requests
I see the following:

Code: Select all

SYSTEM:
[DRIVER] HD Webcam C615 (USB\VID_046D&PID_082C&MI_00\7&3772e1ad&0&0000)
An audio stream is currently in use.
[DRIVER] Legacy Kernel Caller
This is true even though if I go to Devices->USB in the VirtualBox window's menu, the webcam does not have a checkmark next to it. This in turn prevents my computer from automatically going to sleep, as the Legacy Kernel Caller apparently cannot be overridden using

Code: Select all

powercfg /requestsoverride
.

I also found that if I add and enable a USB filter for the webcam in my Guest VM's settings and then start the VM, the webcam does NOT show up when I run

Code: Select all

powercfg /requests
, even though a checkmark DOES show up next to it if I go to Devices->USB in the VirtualBox window's menu. Consequently now that the VM has access to the webcam, no other application is able to use it unless I go to Devices->USB in the VirtualBox window's menu and uncheck the webcam. At this point the webcam becomes available to other applications and no longer shows up when I run (in the Windows 10 Host):

Code: Select all

powercfg /requestsoverride
Is there a way to just prevent VirtualBox Guest VM's from even seeing the webcam? It seems like a lot of hoops to jump through just to: keep a VM Guest running, allow the PC to sleep automatically, and allow other applications to use the webcam given that VirtualBox doesn't need access to it.

Re: Possible to completely block webcam from VirtualBox?

Posted: 12. Jul 2020, 14:53
by scottgus1
Start the guest from full power off, not save-state. Run until you see the problem happen, then shut down the guest from within the guest OS if possible. If not possible, close the Virtualbox window for the guest with the Power Off option set.

Please right-click the guest in the main Virtualbox window's guest list, choose Show Log. Save the far left tab's log, zip the log file, and post the zip file, using the forum's Upload Attachment tab.

Also, please right-click the guest in the main Virtualbox window's guest list, choose "Show in Explorer/Finder/File Manager". In the window that opens, zip the guest's .vbox file, and post the zip file, using the forum's Upload Attachment tab.

Re: Possible to completely block webcam from VirtualBox?

Posted: 12. Jul 2020, 20:51
by vb_user_6128
The files are attached.

Re: Possible to completely block webcam from VirtualBox?

Posted: 12. Jul 2020, 21:03
by scottgus1
Your guest has a filter set up for a Webcam:
<USB>
<Controllers>
<Controller name="OHCI" type="OHCI"/>
</Controllers>
<DeviceFilters>
<DeviceFilter name="Logitech, Inc. HD Webcam C615 [0011]" active="false" vendorId="046d" productId="082c" revision="0011" product="HD Webcam C615" serialNumber="3D027B50" remote="0"/>
</DeviceFilters>
</USB>
The attached log does not appear to show this device being plugged into the guest, though.

The log shows that you don't have the Extension Pack installed, which prevents you from accessing USB 2 & 3 levels in your guest. I doubt that a webcam can use USB1, it's probably too slow. For now do not install the EP.

Remove the USB filter, so you get back to the conditions at the beginning of your post, and re-run the guest without the filter in place. Confirm that in this situation your host OS can use the Webcam. Then run the powercfg command in the guest again, and confirm your host OS is still able to use the Webcam. Your guest should not be able to use the Webcam at any time with no Extension Pack installed. Then post the zipped .vbox file and log again.

Re: Possible to completely block webcam from VirtualBox?

Posted: 13. Jul 2020, 17:59
by vb_user_6128
scottgus1 wrote:Your guest has a filter set up for a Webcam:
<USB>
<Controllers>
<Controller name="OHCI" type="OHCI"/>
</Controllers>
<DeviceFilters>
<DeviceFilter name="Logitech, Inc. HD Webcam C615 [0011]" active="false" vendorId="046d" productId="082c" revision="0011" product="HD Webcam C615" serialNumber="3D027B50" remote="0"/>
</DeviceFilters>
</USB>
The attached log does not appear to show this device being plugged into the guest, though.

The log shows that you don't have the Extension Pack installed, which prevents you from accessing USB 2 & 3 levels in your guest. I doubt that a webcam can use USB1, it's probably too slow. For now do not install the EP.

Remove the USB filter, so you get back to the conditions at the beginning of your post, and re-run the guest without the filter in place. Confirm that in this situation your host OS can use the Webcam. Then run the powercfg command in the guest again, and confirm your host OS is still able to use the Webcam. Your guest should not be able to use the Webcam at any time with no Extension Pack installed. Then post the zipped .vbox file and log again.
The webcam filter was listed but not activated at the time I ran the guest and generated the log and .vbox files. In your quote it says active="false". Will deleting the filter from the list and regenerating the log and vbox files give any different information?

Also did you mean to say "Then run the powercfg command in the host again"? The guest is Ubuntu and powercfg is a Windows command.

Re: Possible to completely block webcam from VirtualBox?

Posted: 13. Jul 2020, 18:10
by scottgus1
vb_user_6128 wrote:The webcam filter was listed but not activated ... it says active="false".
Good point! I did not notice that.

In this case then, with the USB filter deactivated then the guest does not appear to receive the USB device.

When a USB device goes in a guest, this kind of line appears in the log:
00:02:53.040914 VUSB: Attached '0000000004f8ea50[proxy 0781:5575]' to port 1 on RootHub#0 (HighSpeed)
The actual numbers will be different. The proxy numbers are the VendorID and ProductID from the filter, BTW. Searching "VUSB: Attached" in the log is the way to find if a USB device was attached. Then look at the attached device.

Your log has only the virtual USB mouse attached, nothing else:
00:00:03.096367 VUSB: Attached 'HidMouse' to port 1 on RootHub#0 (FullSpeed)
You also don't have the Extension Pack installed, so the webcam passthrough is not available.

So if you are getting webcam activity from the powercfg command while the guest is in the state listed in the log and .vbox file, then either powercfg is showing something else or there is a serious problem.

Does powercfg show the webcam activity while the webcam is unplugged?

Re: Possible to completely block webcam from VirtualBox?

Posted: 13. Jul 2020, 18:14
by vb_user_6128
scottgus1 wrote:
vb_user_6128 wrote:The webcam filter was listed but not activated ... it says active="false".
Good point! I did not notice that.

In this case then, with the USB filter deactivated then the guest does not appear to receive the USB device.

When a USB device goes in a guest, this kind of line appears in the log:
00:02:53.040914 VUSB: Attached '0000000004f8ea50[proxy 0781:5575]' to port 1 on RootHub#0 (HighSpeed)
The actual numbers will be different. The proxy numbers are the VendorID and ProductID from the filter, BTW. Searching "VUSB: Attached" in the log is the way to find if a USB device was attached.
OK, but then why is there immediately a powercfg request in Windows 10 (Host OS) for the webcam as soon as the Guest VM starts? This request is then not released until the VM is shut down. Also for some odd reason adding and enabling the USB filter makes the webcam available to the Guest OS but does not create a powercfg request for it in Windows 10 (Host OS).

Re: Possible to completely block webcam from VirtualBox?

Posted: 13. Jul 2020, 18:16
by scottgus1
Sorry, I hit "Submit" too quick, please see my edits.

Re: Possible to completely block webcam from VirtualBox?

Posted: 13. Jul 2020, 20:21
by vb_user_6128
scottgus1 wrote:
vb_user_6128 wrote:The webcam filter was listed but not activated ... it says active="false".
Good point! I did not notice that.

In this case then, with the USB filter deactivated then the guest does not appear to receive the USB device.

When a USB device goes in a guest, this kind of line appears in the log:
00:02:53.040914 VUSB: Attached '0000000004f8ea50[proxy 0781:5575]' to port 1 on RootHub#0 (HighSpeed)
The actual numbers will be different. The proxy numbers are the VendorID and ProductID from the filter, BTW. Searching "VUSB: Attached" in the log is the way to find if a USB device was attached. Then look at the attached device.

Your log has only the virtual USB mouse attached, nothing else:
00:00:03.096367 VUSB: Attached 'HidMouse' to port 1 on RootHub#0 (FullSpeed)
You also don't have the Extension Pack installed, so the webcam passthrough is not available.

So if you are getting webcam activity from the powercfg command while the guest is in the state listed in the log and .vbox file, then either powercfg is showing something else or there is a serious problem.

Does powercfg show the webcam activity while the webcam is unplugged?
I powered off the Guest VM, unplugged the webcam, then restarted the Guest VM and ran "powercfg /requests" in the Host Windows 10 command prompt. The webcam did not show up in list. It would be very strange if the webcam still showed up even after being physically unplugged.

I know you said the Guest shouldn't have access to the webcam based on the log file, but what about the VirtualBox application itself? Is that the only other possibility at this point? The webcam's powercfg /request entry definitely doesn't show up until I start the VM.

Re: Possible to completely block webcam from VirtualBox?

Posted: 14. Jul 2020, 01:23
by fth0
I understand that your question is not about how to use a webcam in the guest, but the following may be of interest to you nonetheless: The best way to provide a webcam to a VM is not to configure a USB filter at all, but to use the VM window's menu Devices > Webcams, which is a totally different method. This could already be sufficient to avoid your problem. Note that you need the VirtualBox Extension Pack for this webcam passthrough support.

Regarding your problem, you stated that when you have configured a deactivated USB filter and the VM is running, VirtualBox is blocking the webcam in the host's power management already. Does this also happen when the USB filter is not configured at all?

You showed that there are two driver power requests. Are they both related to the webcam?

Another thing came to mind: The webcam also has a microphone, and when the webcam is connected to the host and not to the guest, the microphone is provided to the guest as one of the audio inputs. Try if disabling the Audio Input or using the Null Audio Driver as Host Audio Driver makes a difference.

Re: Possible to completely block webcam from VirtualBox?

Posted: 14. Jul 2020, 18:11
by vb_user_6128
fth0 wrote: Regarding your problem, you stated that when you have configured a deactivated USB filter and the VM is running, VirtualBox is blocking the webcam in the host's power management already. Does this also happen when the USB filter is not configured at all?
If I have no USB filter configured for the webcam OR have a filter configured but not enabled, the following is returned when I type "powercfg /requests" in the host OS after starting the VM:

Code: Select all

SYSTEM:
[DRIVER] HD Webcam C615 (USB\VID_046D&PID_082C&MI_00\7&3772e1ad&0&0000)
An audio stream is currently in use.
[DRIVER] Legacy Kernel Caller
In this case, the webcam IS available to the host OS, but the PC will not automatically go to sleep due to the power request above.

If I have the USB filter for the webcam configured and enabled, then neither of the above 2 entries are returned when I type "powercfg /requests" after starting the VM. When I then go to "Devices->USB" from within the VM, the webcam is checked. In this case, the webcam is unavailable to the Host OS (Windows 10), but the PC will go to sleep automatically because there is no power request from the webcam.
fth0 wrote: You showed that there are two driver power requests. Are they both related to the webcam?
Yes. I am not exactly sure what "Legacy Kernel Caller" is, but it always appears and disappears along with the webcam entry.
fth0 wrote: Another thing came to mind: The webcam also has a microphone, and when the webcam is connected to the host and not to the guest, the microphone is provided to the guest as one of the audio inputs. Try if disabling the Audio Input or using the Null Audio Driver as Host Audio Driver makes a difference.
[/quote]

Do you mean go to Settings->Audio and uncheck the "Enable Audio Input" box?

Another interesting but possibly unrelated detail is that the following entry also appears when I run powercfg /requests regardless of the webcam settings:

Code: Select all

SYSTEM:
[DRIVER] Realtek High Definition Audio (HDAUDIO\FUNC_01&VEN_10EC&DEV_0900&SUBSYS_38421047&REV_1000\4&1c79ede0&0&0001)
The entry appears when Ubuntu starts to boot and then disappears a few seconds after the login screen appears.
An audio stream is currently in use.

Re: Possible to completely block webcam from VirtualBox?

Posted: 14. Jul 2020, 19:39
by fth0
Thank you for testing again. Your latest observations would make sense to me, if the driver power requests relate to the audio input (microphone) of the webcam only. Because only if the webcam is available to the host, the microphone is one of the audio inputs of the host, and can be provided as a possible audio input device to the guest. If the webcam is available to the guest instead, it is not available to the host (neither the audio nor the video input).
vb_user_6128 wrote:
fth0 wrote:Another thing came to mind: The webcam also has a microphone, and when the webcam is connected to the host and not to the guest, the microphone is provided to the guest as one of the audio inputs. Try if disabling the Audio Input or using the Null Audio Driver as Host Audio Driver makes a difference.
Do you mean go to Settings->Audio and uncheck the "Enable Audio Input" box?
Yes, and the second alternative is to change the Host Audio Driver setting directly below the checkbox.

Re: Possible to completely block webcam from VirtualBox?

Posted: 18. Jul 2020, 19:20
by vb_user_6128
fth0 wrote:Thank you for testing again. Your latest observations would make sense to me, if the driver power requests relate to the audio input (microphone) of the webcam only. Because only if the webcam is available to the host, the microphone is one of the audio inputs of the host, and can be provided as a possible audio input device to the guest. If the webcam is available to the guest instead, it is not available to the host (neither the audio nor the video input).
vb_user_6128 wrote:
fth0 wrote:Another thing came to mind: The webcam also has a microphone, and when the webcam is connected to the host and not to the guest, the microphone is provided to the guest as one of the audio inputs. Try if disabling the Audio Input or using the Null Audio Driver as Host Audio Driver makes a difference.
Do you mean go to Settings->Audio and uncheck the "Enable Audio Input" box?
Yes, and the second alternative is to change the Host Audio Driver setting directly below the checkbox.
I ran some more tests and discovered the following:

1. Leaving "Host Audio Driver" set to "Windows DirectSound", "Audio Controller" set to "ICH AC97", "Enable Audio Output" checked but unchecking "Enable Audio Input" does not fix my problem. The webcam still shows up when I run "powercfg /requests" after starting the VM Guest.
2. Setting "Host Audio Driver" to "Null Audio Driver" does prevent the webcam from showing up when I run "powercfg /requests" after starting the VM Guest, as you suggested.
3. If I pick either of the other options for "Audio Controller" (SoundBlaster 16, Intel HD Audio), the webcam briefly appears when I run "powercfg /requests" while the VM Guest is loading, then goes away. The audio is very glitchy and cuts out when I test it within the VM Guest in this case.

It seems my only options at this point for preventing the webcam from showing up on the "powercfg /requests" list while the VM Guest is running (and therefore preventing my PC from automatically sleeping) are:

1. Add a USB filter for the webcam, start the VM Guest, then uncheck the webcam from the "Devices" -> "USB" list to permit other applications to access the webcam
2. Disable audio completely by changing "Host Audio Driver" to "Null Audio Driver", as explained above

Why doesn't unchecking "Enable Audio Input" and leaving "Host Audio Driver" set to "Windows DirectSound", "Audio Controller" set to "ICH AC97", and "Enable Audio Output" checked work? The webcam has a mic (audio input), but no speaker (audio output), so I'm not sure why unchecking "Enable Audio Output Input" isn't enough to disable the webcam.

Re: Possible to completely block webcam from VirtualBox?

Posted: 18. Jul 2020, 20:36
by fth0
Ubuntu-2020-07-12-13-22-38.log wrote:
00:00:02.831807 AC97: Using codec 'AD1980'
00:00:02.831868 Audio: Initializing DirectSound audio driver
00:00:03.095851 Audio: Found 8 devices for driver 'DSoundAudio'
00:00:03.095862 Audio: Device 'Primary Sound Driver':
00:00:03.095867 Audio: 	Usage           = Output
00:00:03.095871 Audio: 	Flags           = DEFAULT
00:00:03.095877 Audio: 	Input channels  = 0
00:00:03.095882 Audio: 	Output channels = 2
[...]
00:00:03.095957 Audio: Device 'Primary Sound Capture Driver':
00:00:03.095959 Audio: 	Usage           = Input
00:00:03.095962 Audio: 	Flags           = NONE
00:00:03.095967 Audio: 	Input channels  = 2
00:00:03.095971 Audio: 	Output channels = 0
00:00:03.095974 Audio: Device 'Microphone (HD Webcam C615)':
00:00:03.095977 Audio: 	Usage           = Input
00:00:03.095979 Audio: 	Flags           = NONE
00:00:03.095982 Audio: 	Input channels  = 2
00:00:03.095984 Audio: 	Output channels = 0
00:00:03.096024 AC97: Reset
00:00:03.096031 AC97: Mixer reset (EAID=0x809, EACS=0x9)
00:00:03.096034 AC97: Record select to left=Microphone In, right=Microphone In
vb_user_6128 wrote:Why doesn't unchecking "Enable Audio Input" and leaving "Host Audio Driver" set to "Windows DirectSound", "Audio Controller" set to "ICH AC97", and "Enable Audio Output" checked work? The webcam has a mic (audio input), but no speaker (audio output), so I'm not sure why unchecking "Enable Audio Output" isn't enough to disable the webcam.
I don't know the exact details of the audio routing in VirtualBox, so I can only guess (or experiment). VirtualBox uses the Windows DirectSound infrastructure and queries all devices when starting the VM. Perhaps it locks the audio input devices to force its internal structures to stay in sync. I've seen bugs where audio input devices disappeared during suspend/resume cycles, leading to crashes.