mixer/src/back/backlasses.h
2023-09-01 21:36:07 +02:00

131 lines
3.5 KiB
C++

#pragma once
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0A00
#include <sdkddkver.h>
//done by qt by def #define UNICODE
#include <Windows.h>
#include <processthreadsapi.h>
#include <mmdeviceapi.h>
#include <combaseapi.h>
#include <initguid.h>
#include <Propidl.h>
#include <functiondiscoverykeys_devpkey.h>
#include <endpointvolume.h>
#include <audiopolicy.h>
#include <audioclient.h>
//#include <comdef.h>
//#include <comip.h>
#include <Winerror.h>
#include <stringapiset.h>
#include "ipolicyconfig.h"
#include <Mmreg.h>
#include "global.h"
#include "contclasses.h"
class EndpointVolumeCallback;
class Endpoint {
public:
Endpoint(IMMDevice* endpoint, uint64_t idx);
uint64_t getIndex();
void setIndex(uint64_t idx);
void setVolume(NGuid guid, int channel, float volume);
uint32_t getChannelCount();
float getVolume(int channel);
void setMute(NGuid guid, bool muted);
bool getMute();
void setState(uint8_t state);
uint8_t getState();
uint8_t getRoles();
void setRoles(Roles role);
void assignRoles(uint8_t role);
void removeRoles(uint8_t role);
std::wstring getId();
std::wstring getName();
void setVolumeCallback(EndpointVolumeCallback *epc);
void removeVolumeCallback(EndpointVolumeCallback *epc);
~Endpoint();
private:
uint32_t channelCount;
IMMDevice* endpoint;
IAudioEndpointVolume *endpointVolume ;
IPropertyStore *properties;
std::wstring friendlyName;
std::wstring endpointId;
uint8_t endpointState;
uint8_t endpointRoles = 0;
uint64_t idx;
// LPWSTR endpointID = NULL;
};
class EndpointVolumeCallback : public IAudioEndpointVolumeCallback {
public:
EndpointVolumeCallback(Endpoint* ep);
ULONG AddRef();
ULONG Release();
HRESULT QueryInterface(REFIID riid, VOID **ppvInterface);
HRESULT OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA update);
//~EndpointVolumeCallback();
private:
ULONG ref = 1;
Endpoint* ep;
};
class EndpointSituationCallback : public IMMNotificationClient {
public:
//EndpointSituationCallback(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices);
ULONG AddRef();
ULONG Release();
HRESULT QueryInterface(REFIID riid, VOID **ppvInterface);
HRESULT OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDeviceId);
HRESULT OnDeviceAdded(LPCWSTR pwstrDeviceId);
HRESULT OnDeviceRemoved(LPCWSTR pwstrDeviceId);
HRESULT OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState);
HRESULT OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key);
void fill(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices);
private:
ULONG ref = 1;
IMMDeviceEnumerator *deviceEnumerator;
std::vector<Endpoint*> playbackDevices;
};
class Overseer {
//TODO singleton?
public:
Overseer();
std::vector<Endpoint*> getPlaybackEndpoints();
void reloadEndpoints();
NGuid getGuid();
//void setEndpointStatusCallback();
//void setEndpointStatusCallback();
//~Overseer();
//int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint);
//int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
//int getCaptureEndpoints(std::vector<Endpoint*> *captureEndpoints);
//IMMDeviceEnumerator** setOrigin();
~Overseer();
private:
NGuid guid;
unsigned int numPlaybackEndpoints;
IMMDeviceEnumerator *deviceEnumerator;
EndpointSituationCallback epsc;
//IPolicyConfig *policyConfig;
std::vector<Endpoint*> playbackDevices;
void initCOMLibrary();
//IMMDeviceCollection *deviceCollection;
//int numCaptureEndpoints;
//std::vector<Endpoint*> *captureDevices;
};