3 Commits
1.0.2 ... 1.0.3

Author SHA1 Message Date
eec9e25e12 1.0.3 2022-07-26 15:22:51 +02:00
3b4853acda Fix device add/remove handlers 2022-07-26 15:22:23 +02:00
cea13986f0 1.0.2 2022-07-24 02:09:58 +02:00
5 changed files with 75 additions and 49 deletions

View File

@@ -1,7 +1,35 @@
#include "ApplicationData.h"
#include "Util.h"
#include "AudioApi.h"
#include <functiondiscoverykeys.h>
AudioDevice::AudioDevice()
AudioDevice::AudioDevice(IMMDevice* device, LPCWSTR deviceId)
{
id = std::wstring(deviceId);
IPropertyStore* propertyStore;
HRESULT err = device->OpenPropertyStore(STGM_READ, &propertyStore);
isError(err, "Failed to open prop store: ");
PROPVARIANT deviceNameProp;
const wchar_t* deviceName;
err = getDevicePropertyString(propertyStore, PKEY_Device_FriendlyName, &deviceNameProp, deviceName);
isError(err, "Failed to read name of device :");
name = utf8Encode(deviceName);
err = device->GetState(&state);
isError(err, "Failed to reat state of device: ");
err = device->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&volumeInterface);
isError(err, "Failed to get audio endpoint volume interface: ");
err = device->Activate(__uuidof(IAudioMeterInformation), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&meterInterface);
isError(err, "Failed to get audio meter interface: ");
if (propertyStore)
{
propertyStore->Release();
}
}
AudioDevice::AudioDevice(AudioDevice&& other) noexcept

View File

@@ -18,7 +18,7 @@ public:
bool isDefaultMedia = {};
bool isDefaultCommunication = {};
AudioDevice();
AudioDevice(IMMDevice* device, LPCWSTR deviceId);
AudioDevice(AudioDevice&& other) noexcept;
AudioDevice& operator=(AudioDevice&& other) noexcept;
~AudioDevice();

View File

@@ -71,8 +71,8 @@ IDI_ICON1 ICON "kaiju.ico"
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,1,1
PRODUCTVERSION 1,0,1,1
FILEVERSION 1,0,3,1
PRODUCTVERSION 1,0,3,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -89,12 +89,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Asuro"
VALUE "FileDescription", "Audio Thingy"
VALUE "FileVersion", "1.0.1.1"
VALUE "FileVersion", "1.0.3.1"
VALUE "InternalName", "AsuroTool.exe"
VALUE "LegalCopyright", "Copyright (C) 2022"
VALUE "OriginalFilename", "AsuroTool.exe"
VALUE "ProductName", "Audio Thingy"
VALUE "ProductVersion", "1.0.1.1"
VALUE "ProductVersion", "1.0.3.1"
END
END
BLOCK "VarFileInfo"

View File

@@ -66,57 +66,35 @@ void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList
for (UINT i = 0; i < deviceCount; i += 1)
{
AudioDevice deviceData{};
err = deviceCollection->Item(i, &deviceData.device);
IMMDevice* device;
err = deviceCollection->Item(i, &device);
if (isError(err, std::stringstream("Failed to get device ") << i << ": "))
{
continue;
}
LPWSTR deviceId;
err = deviceData.device->GetId(&deviceId);
isError(err, std::stringstream("Failed to get device id ") << i << ": ");
deviceData.id = std::wstring(deviceId);
IPropertyStore* propertyStore;
err = deviceData.device->OpenPropertyStore(STGM_READ, &propertyStore);
isError(err, std::stringstream("Failed to open device ") << i << "prop store: ");
PROPVARIANT deviceNameProp;
const wchar_t* deviceName;
err = getDevicePropertyString(propertyStore, PKEY_Device_FriendlyName, &deviceNameProp, deviceName);
isError(err, std::stringstream("Failed to read name of device ") << i << ": ");
deviceData.name = utf8Encode(deviceName);
err = deviceData.device->GetState(&deviceData.state);
isError(err, std::stringstream("Failed to reat state of device ") << i << ": ");
err = deviceData.device->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&deviceData.volumeInterface);
isError(err, "Failed to get audio endpoint volume interface: ");
err = deviceData.device->Activate(__uuidof(IAudioMeterInformation), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&deviceData.meterInterface);
isError(err, "Failed to get audio meter interface: ");
err = device->GetId(&deviceId);
if (!isError(err, std::stringstream("Failed to get device id ") << i << ": "))
{
AudioDevice audioDevice(device, deviceId);
if (defaultConsoleId)
{
deviceData.isDefaultConsole = wcscmp(defaultConsoleId, deviceId) == 0;
audioDevice.isDefaultConsole = wcscmp(defaultConsoleId, deviceId) == 0;
}
if (defaultMediaId)
{
deviceData.isDefaultMedia = wcscmp(defaultMediaId, deviceId) == 0;
audioDevice.isDefaultMedia = wcscmp(defaultMediaId, deviceId) == 0;
}
if (defaultCommunicationId)
{
deviceData.isDefaultCommunication = wcscmp(defaultCommunicationId, deviceId) == 0;
audioDevice.isDefaultCommunication = wcscmp(defaultCommunicationId, deviceId) == 0;
}
deviceList.push_back(std::move(deviceData));
if (propertyStore)
{
propertyStore->Release();
deviceList.push_back(std::move(audioDevice));
}
CoTaskMemFree(deviceId);
}

View File

@@ -34,7 +34,25 @@ HRESULT __stdcall AudioNotificationListener::OnDeviceAdded(LPCWSTR pwstrDeviceId
HRESULT result = audioData->deviceEnumerator->GetDevice(pwstrDeviceId, &newDevice);
if (SUCCEEDED(result) && newDevice != nullptr)
{
// TODO: add to device list
IMMEndpoint* endpoint;
result = newDevice->QueryInterface(&endpoint);
if (SUCCEEDED(result) && endpoint != nullptr)
{
EDataFlow dataFlow;
result = endpoint->GetDataFlow(&dataFlow);
if (SUCCEEDED(result))
{
AudioDevice audioDevice(newDevice, pwstrDeviceId);
if (dataFlow == EDataFlow::eCapture)
{
audioData->recordingDevices.push_back(std::move(audioDevice));
}
else
{
audioData->playbackDevices.push_back(std::move(audioDevice));
}
}
}
}
return result;
@@ -50,7 +68,9 @@ HRESULT __stdcall AudioNotificationListener::OnDeviceRemoved(LPCWSTR pwstrDevice
if (wcscmp(deviceListIterator->id.c_str(), pwstrDeviceId) == 0)
{
deviceListIterator = deviceList.erase(deviceListIterator);
continue;
}
deviceListIterator++;
}
};