Skip to content

Commit 6289a74

Browse files
authored
Merge pull request #3 from mrbindraw/dev
Dev
2 parents f576af7 + 1a4f8e5 commit 6289a74

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

Source/SystemMicControlLite/Private/SystemMicLiteManager.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
FSystemMicLiteManager *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

3640
FSystemMicLiteManager *FSystemMicLiteManager::Get()
@@ -45,7 +49,9 @@ FSystemMicLiteManager *FSystemMicLiteManager::Get()
4549

4650
FSystemMicLiteManager::~FSystemMicLiteManager()
4751
{
52+
#if PLATFORM_WINDOWS
4853
FWindowsPlatformMisc::CoUninitialize();
54+
#endif
4955
}
5056

5157
void FSystemMicLiteManager::DestroyInstance()
@@ -64,6 +70,9 @@ FString FSystemMicLiteManager::GetDefaultDeviceName()
6470

6571
FString 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

91102
FString 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()
160173
void 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

195210
float 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
}

Source/SystemMicControlLite/Public/PolicyConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#pragma once
44

5+
#if PLATFORM_WINDOWS
56
// ca286fc3-91fd-42c3-8e9b-caafa66242e3
67
static const GUID IID_IPolicyConfig2 = { 0xCA286FC3, 0x91FD, 0x42C3, { 0x8E, 0x9B, 0xCA, 0xAF, 0xA6, 0x62, 0x42, 0xE3 } };
78

@@ -169,3 +170,4 @@ interface IPolicyConfigVista : public IUnknown
169170
INT
170171
); // not available on Windows 7, use method from IPolicyConfig
171172
};
173+
#endif

Source/SystemMicControlLite/Public/SystemMicLiteManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "CoreMinimal.h"
77

8+
#if PLATFORM_WINDOWS
89
#include "Windows/AllowWindowsPlatformTypes.h"
910
#include <mmdeviceapi.h>
1011
#include <endpointvolume.h>
@@ -13,6 +14,7 @@
1314
#include <ksmedia.h>
1415
#include "PolicyConfig.h"
1516
#include "Windows/HideWindowsPlatformTypes.h"
17+
#endif
1618

1719
class FSystemMicLiteManager
1820
{
@@ -22,6 +24,7 @@ class FSystemMicLiteManager
2224

2325
static FSystemMicLiteManager *Instance;
2426

27+
#if PLATFORM_WINDOWS
2528
IAudioEndpointVolume *AudioEndpointVolume;
2629
IMMDevice *DefaultDevice;
2730
IMMDeviceEnumerator *DeviceEnumerator;
@@ -30,6 +33,7 @@ class FSystemMicLiteManager
3033

3134
IPolicyConfigVista *PolicyConfigVista;
3235
IPolicyConfig *PolicyConfig;
36+
#endif
3337

3438
public:
3539
static FSystemMicLiteManager *Get();

SystemMicControlLite.uplugin

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
{
1919
"Name": "SystemMicControlLite",
2020
"Type": "Runtime",
21-
"LoadingPhase": "Default",
22-
"WhitelistPlatforms": [
23-
"Win64"
24-
]
21+
"LoadingPhase": "Default"
2522
}
2623
]
2724
}

0 commit comments

Comments
 (0)