150 lines
4.3 KiB
C++
150 lines
4.3 KiB
C++
#pragma once
|
|
|
|
#include "msinclude.h"
|
|
#include "backsessionclasses.h"
|
|
#include "global.h"
|
|
#include "contclasses.h"
|
|
|
|
class EndpointVolumeCallback;
|
|
class Session;
|
|
|
|
class Endpoint {
|
|
|
|
public:
|
|
Endpoint(IMMDevice* endpoint, uint64_t idx);
|
|
//todo: how to forward declare delegate constructors?
|
|
Endpoint(IMMDevice* endpoint) : Endpoint(endpoint, 0) {};
|
|
void reloadEndpointChannels();
|
|
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);
|
|
size_t getState();
|
|
Roles getRoles();
|
|
void setRoles(Roles role);
|
|
void assignRoles(Roles role);
|
|
void removeRoles(Roles role);
|
|
void setFlow();
|
|
Flows getFlow();
|
|
std::wstring getId();
|
|
std::wstring getName();
|
|
|
|
void setVolumeCallback(EndpointVolumeCallback *epc);
|
|
void removeVolumeCallback(EndpointVolumeCallback *epc);
|
|
|
|
/* sessions */
|
|
std::vector<Session*> getSessions();
|
|
size_t getSessionCount();
|
|
void addSession(Session* session);
|
|
void registerNewSessionNotification(EndpointNewSessionCallback* ensc);
|
|
void unregisterNewSessionNotification(EndpointNewSessionCallback* ensc);
|
|
|
|
~Endpoint();
|
|
|
|
private:
|
|
void inline activateEndpointVolume();
|
|
void inline activateEndpointSessions();
|
|
|
|
std::vector<Session*> endpointSessions;
|
|
uint32_t channelCount = 0;
|
|
IMMDevice* endpoint;
|
|
IAudioSessionManager2 *sessionManager;
|
|
Flows flow;
|
|
IAudioEndpointVolume *endpointVolume = nullptr;
|
|
IPropertyStore *properties;
|
|
std::wstring friendlyName;
|
|
std::wstring endpointId;
|
|
unsigned long endpointState;
|
|
Roles endpointRoles = (Roles)0;
|
|
uint64_t idx;
|
|
/* Not implemented in llvm-mingw. Sad!
|
|
* IAudioMeterInformation *endpointPeakMeter = nullptr;
|
|
*/
|
|
};
|
|
|
|
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, std::vector<Endpoint*> captureDevices);
|
|
private:
|
|
ULONG ref = 1;
|
|
IMMDeviceEnumerator *deviceEnumerator;
|
|
std::vector<Endpoint*> playbackDevices;
|
|
std::vector<Endpoint*> captureDevices;
|
|
};
|
|
|
|
class Overseer {
|
|
//TODO singleton?
|
|
public:
|
|
Overseer();
|
|
std::vector<Endpoint*> getPlaybackEndpoints();
|
|
std::vector<Endpoint*> getCaptureEndpoints();
|
|
|
|
void reloadEndpoints(Flows flow);
|
|
Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow);
|
|
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;
|
|
|
|
IMMDeviceEnumerator *deviceEnumerator;
|
|
EndpointSituationCallback epsc;
|
|
//IPolicyConfig *policyConfig;
|
|
std::vector<Endpoint*> playbackDevices;
|
|
std::vector<Endpoint*> captureDevices;
|
|
void initCOMLibrary();
|
|
//IMMDeviceCollection *deviceCollection;
|
|
//int numCaptureEndpoints;
|
|
//std::vector<Endpoint*> *captureDevices;
|
|
};
|
|
|
|
class EndpointNewSessionCallback : public IAudioSessionNotification {
|
|
public:
|
|
EndpointNewSessionCallback(EndpointHandler *eph);
|
|
ULONG AddRef();
|
|
ULONG Release();
|
|
HRESULT QueryInterface(REFIID riid, VOID **ppvInterface);
|
|
HRESULT OnSessionCreated(IAudioSessionControl *NewSession);
|
|
|
|
private:
|
|
ULONG ref = 1;
|
|
EndpointHandler *eph;
|
|
};
|