Open cryingsauerkraut opened 1 month ago
@cryingsauerkraut Windows Services has no access to Users mic input in WasapiCapture. Windows Audio Session API (WASAPI) is all about User Session in Windows.
@rdyhalt It's worked on all versions of Windows prior to a recent update, so I don't think it's intended, it seems to be a regression.
@cryingsauerkraut the problem from a Windows Service is that a User Session can be a Remote Desktop, Citrix Desktop or any other virtual disktop and not only Console Desktop.
In Remote Desktop and Citrix Dekstop, there can be 100s of users online on the same Windows.
So, what WasapiCapture interface to use ?
Perhaps try to liste all device, when running in Windows Service ?
MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
var devices = enumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.All);
foreach (MMDevice device in devices)
{
if (device.State != DeviceState.NotPresent)
{
Debug.WriteLine(String.Format("{0}, {1}", device.FriendlyName, device.State));
}
else
{
Debug.WriteLine(String.Format("{0}, {1}", device.ID, device.State));
}
}
@rdyhalt, running that snippet on my test machine with the project deployed and running as a service I get:
Realtek HD Audio 2nd output (Realtek(R) Audio), Unplugged
{0.0.0.00000000}.{14ea95e3-4d1b-4c03-a158-db0cfc8d67e8}, NotPresent
{0.0.0.00000000}.{2ba2e96f-7987-44b1-a8d9-38d04d01438c}, NotPresent
{0.0.0.00000000}.{313e462d-687a-417f-8ab9-4606667dcc2f}, NotPresent
{0.0.0.00000000}.{3b301089-0422-444d-aaec-5ffa891e25ab}, NotPresent
{0.0.0.00000000}.{44bf905b-7d60-4ef3-b80c-a9c184caf1d2}, NotPresent
Speakers (Realtek(R) Audio), Active
Headset (USBC Headset), Active
{0.0.0.00000000}.{57226584-305c-498d-a4ed-c7fda7558493}, NotPresent
{0.0.0.00000000}.{5ad383c2-c269-4bf8-993f-8ba0dd9dee82}, NotPresent
Digital Output (AMD High Definition Audio Device), Unplugged
{0.0.0.00000000}.{84d01c7e-bc31-45b6-b489-cd6c0e10c092}, NotPresent
Digital Output (AMD High Definition Audio Device), Unplugged
{0.0.0.00000000}.{8d901038-1554-4ca1-821c-d2123026ebda}, NotPresent
Digital Output (AMD High Definition Audio Device), Unplugged
{0.0.0.00000000}.{99eaa61e-8e6d-4b26-b106-443220d27591}, NotPresent
Headset (ThinkPad USB-C Dock Audio), Unplugged
Headset Earphone (Yealink MP50), Active
{0.0.0.00000000}.{f1125cfa-398a-4635-9152-d650e581283a}, NotPresent
{0.0.1.00000000}.{09dff703-c54e-4c99-8bf7-fe7a8832ca05}, NotPresent
{0.0.1.00000000}.{34b4ec12-0e50-43db-8780-48d2601fa3d6}, NotPresent
Stereo Mix (Realtek(R) Audio), Disabled
Microphone (Realtek(R) Audio), Unplugged
{0.0.1.00000000}.{57eba409-2cee-4329-926d-75ccec65c222}, NotPresent
Microphone (ThinkPad USB-C Dock Audio), Unplugged
{0.0.1.00000000}.{6259ca3a-00c3-402b-9e02-b7afe3c3d702}, NotPresent
{0.0.1.00000000}.{6a2fb9ac-50cc-4efc-bc8a-2574dd1cac57}, NotPresent
Headset Microphone (Yealink MP50), Active
{0.0.1.00000000}.{916e8a85-3982-40d7-84f0-4f2389368131}, NotPresent
{0.0.1.00000000}.{9abb8b37-9958-475e-bffb-c5cfd5ea6e30}, NotPresent
Headset (USBC Headset), Active
Microphone Array (AMD Audio Device), Active
{0.0.1.00000000}.{ce3afc07-6bc5-4ff8-ad3c-de909375fc10}, NotPresent
{0.0.1.00000000}.{dada0eb1-eed6-4b4c-91ca-faf2dd102b44}, NotPresent
{0.0.1.00000000}.{e67ce5df-cf11-43da-9a4f-e31c9b14b51d}, NotPresent
{0.0.1.00000000}.{e7f229ab-973a-4a4c-8fad-f3f9b75dd6ca}, NotPresent
{0.0.1.00000000}.{fd4fe264-afc8-4a8e-aef2-5dd54c6ac203}, NotPresent
When the project is run in debug mode from Visual Studio the output is the same. It may be worth noting that I also experience a similar error when I try recording from the mic with WaveIn. WaveIn also works when running from Visual Studio and not when deployed.
My guess will be, that a call to captureMic = new WasapiCapture();
in a Windows Service. Will give you no default MMDevice
Try point out what MMDevice to use, both in when you try it in Visual Studio and as Windows Service.
I still get the catastrophic failure hresult when explicitly creating the capture with a specific, plugged in, capture device. I have seen the COM exception when there's no default capture device before and handle it in the catch block omitted from my initial snippet, and it's a different hresult. That was back when the application was functioning before it was broken by a Windows update.
Attempting to start a WASAPI capture with the default constructor returns an exception from hresult 0x8000FFFF, Catastrophic failure when called from a Windows service. Since the latest Windows 11 update, my app has been crashing on trying to start a WASAPI mic capture and is deployed as a self contained, single file Windows service.
Initializing the capture:
And the result is:
This only happens when the application is deployed as a service, it runs fine when running from Visual Studio. I've been spinning my wheels on this problem for months, does anyone have any ideas?