#pragma once #define WIN32_LEAN_AND_MEAN #define _WIN32_WINNT 0x0A00 #include //done by qt by def #define UNICODE #include #include #include #include #include #include #include #include #include #include //#include //#include #include #include #include "ipolicyconfig.h" #include #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 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 playbackDevices); private: ULONG ref = 1; IMMDeviceEnumerator *deviceEnumerator; std::vector playbackDevices; }; class Overseer { //TODO singleton? public: Overseer(); std::vector getPlaybackEndpoints(); void reloadEndpoints(); NGuid getGuid(); //void setEndpointStatusCallback(); //void setEndpointStatusCallback(); //~Overseer(); //int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint); //int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint); //int getCaptureEndpoints(std::vector *captureEndpoints); //IMMDeviceEnumerator** setOrigin(); ~Overseer(); private: NGuid guid; unsigned int numPlaybackEndpoints; IMMDeviceEnumerator *deviceEnumerator; EndpointSituationCallback epsc; //IPolicyConfig *policyConfig; std::vector playbackDevices; void initCOMLibrary(); //IMMDeviceCollection *deviceCollection; //int numCaptureEndpoints; //std::vector *captureDevices; };