44
55FSystemMicLiteManager *FSystemMicLiteManager::Instance = nullptr ;
66
7- FSystemMicLiteManager::FSystemMicLiteManager () :
8- AudioEndpointVolume(nullptr ),
7+ FSystemMicLiteManager::FSystemMicLiteManager ()
8+ #if PLATFORM_WINDOWS
9+ : AudioEndpointVolume(nullptr ),
910 DefaultDevice (nullptr ),
1011 DeviceEnumerator(nullptr ),
1112 DevicesCollection(nullptr ),
1213 PropertyStore(nullptr ),
1314 PolicyConfigVista(nullptr ),
1415 PolicyConfig(nullptr )
16+ #endif
1517{
18+ #if PLATFORM_WINDOWS
1619 FWindowsPlatformMisc::CoInitialize ();
1720
1821 CoCreateInstance (__uuidof (CPolicyConfigVistaClient), nullptr , CLSCTX_ALL , __uuidof (IPolicyConfigVista), (LPVOID *)&PolicyConfigVista);
@@ -31,6 +34,7 @@ FSystemMicLiteManager::FSystemMicLiteManager() :
3134 }
3235
3336 CoCreateInstance (__uuidof (MMDeviceEnumerator), nullptr , CLSCTX_INPROC_SERVER , __uuidof (IMMDeviceEnumerator), (LPVOID *)&DeviceEnumerator);
37+ #endif
3438}
3539
3640FSystemMicLiteManager *FSystemMicLiteManager::Get ()
@@ -45,7 +49,9 @@ FSystemMicLiteManager *FSystemMicLiteManager::Get()
4549
4650FSystemMicLiteManager::~FSystemMicLiteManager ()
4751{
52+ #if PLATFORM_WINDOWS
4853 FWindowsPlatformMisc::CoUninitialize ();
54+ #endif
4955}
5056
5157void FSystemMicLiteManager::DestroyInstance ()
@@ -64,6 +70,9 @@ FString FSystemMicLiteManager::GetDefaultDeviceName()
6470
6571FString FSystemMicLiteManager::GetDefaultDeviceId ()
6672{
73+ FString DeviceIdStr;
74+
75+ #if PLATFORM_WINDOWS
6776 HRESULT Result = DeviceEnumerator->GetDefaultAudioEndpoint (eCapture, eConsole, &DefaultDevice);
6877 if (Result != S_OK )
6978 {
@@ -84,8 +93,10 @@ FString FSystemMicLiteManager::GetDefaultDeviceId()
8493 {
8594 return FString (TEXT (" " ));
8695 }
96+ DeviceIdStr = FString (WCHAR_TO_TCHAR (swDeviceId));
97+ #endif
8798
88- return FString ( WCHAR_TO_TCHAR (swDeviceId)) ;
99+ return DeviceIdStr ;
89100}
90101
91102FString FSystemMicLiteManager::GetDeviceNameFromId (const FString &DeviceId)
@@ -107,6 +118,7 @@ TMap<FString, FString> FSystemMicLiteManager::GetActiveDevices()
107118{
108119 TMap<FString, FString> ActiveDevices;
109120
121+ #if PLATFORM_WINDOWS
110122 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd371400(v=vs.85).aspx, see Return value!
111123 HRESULT Result = DeviceEnumerator->EnumAudioEndpoints (eCapture, DEVICE_STATE_ACTIVE , &DevicesCollection);
112124 if (Result != S_OK )
@@ -152,6 +164,7 @@ TMap<FString, FString> FSystemMicLiteManager::GetActiveDevices()
152164 DevicesCollection->Release ();
153165 DevicesCollection = nullptr ;
154166 }
167+ #endif
155168
156169 return ActiveDevices;
157170}
@@ -160,7 +173,8 @@ TMap<FString, FString> FSystemMicLiteManager::GetActiveDevices()
160173void FSystemMicLiteManager::SetVolume (float Value)
161174{
162175 float MicVolume = this ->GetScalarFromValue (Value);
163-
176+
177+ #if PLATFORM_WINDOWS
164178 HRESULT Result = DeviceEnumerator->GetDefaultAudioEndpoint (eCapture, eConsole, &DefaultDevice);
165179 if (Result != S_OK )
166180 {
@@ -190,10 +204,14 @@ void FSystemMicLiteManager::SetVolume(float Value)
190204 DefaultDevice->Release ();
191205 DefaultDevice = nullptr ;
192206 }
207+ #endif
193208}
194209
195210float FSystemMicLiteManager::GetVolume ()
196211{
212+ float MicVolume = 0 .0f ;
213+
214+ #if PLATFORM_WINDOWS
197215 HRESULT Result = DeviceEnumerator->GetDefaultAudioEndpoint (eCapture, eConsole, &DefaultDevice);
198216 if (Result != S_OK )
199217 {
@@ -206,7 +224,6 @@ float FSystemMicLiteManager::GetVolume()
206224 return 0 .0f ;
207225 }
208226
209- float MicVolume = 0 .0f ;
210227 Result = AudioEndpointVolume->GetMasterVolumeLevelScalar (&MicVolume);
211228 if (Result != S_OK )
212229 {
@@ -224,6 +241,7 @@ float FSystemMicLiteManager::GetVolume()
224241 DefaultDevice->Release ();
225242 DefaultDevice = nullptr ;
226243 }
244+ #endif
227245
228246 return GetValueFromScalar (MicVolume);
229247}
0 commit comments