-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_monitor.h
More file actions
45 lines (36 loc) · 1.48 KB
/
audio_monitor.h
File metadata and controls
45 lines (36 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include "device_info.h"
#include <Windows.h>
#include <mmdeviceapi.h>
#include <functiondiscoverykeys_devpkey.h>
#include <vector>
#include <string>
#include <atomic>
class AudioMonitor : public IMMNotificationClient {
public:
AudioMonitor();
~AudioMonitor();
bool start();
void stop();
// List all current audio devices
void listCurrentDevices();
// Get audio device info by ID
AudioDeviceInfo getDeviceInfo(LPCWSTR deviceId, EDataFlow flow);
// IUnknown methods
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override;
// IMMNotificationClient methods
HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState) override;
HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId) override;
HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId) override;
HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId) override;
HRESULT STDMETHODCALLTYPE OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) override;
private:
std::wstring getDeviceFriendlyName(IMMDevice* device);
std::wstring deviceStateToString(DWORD state);
std::wstring dataFlowToString(EDataFlow flow);
IMMDeviceEnumerator* m_enumerator = nullptr;
std::atomic<LONG> m_refCount{1};
bool m_started = false;
};