enable/disable/add/remove groundwork done

This commit is contained in:
Hane 2023-09-06 19:59:55 +02:00
commit 04da76c021
4 changed files with 66 additions and 58 deletions

View file

@ -71,14 +71,14 @@ HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify
* this->deviceEnumerator = deviceEnumerator;
* this->playbackDevices = playbackDevices;
* }
*
*/
//todo: not on construct since it expects them to already exist; smells like refactor!
void EndpointSituationCallback::fill(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices){
this->deviceEnumerator = deviceEnumerator;
this->playbackDevices = playbackDevices;
}
ULONG EndpointSituationCallback::AddRef(){
return InterlockedIncrement(&ref);
}
@ -132,37 +132,31 @@ HRESULT EndpointSituationCallback::OnDefaultDeviceChanged(EDataFlow flow, ERole
}
HRESULT EndpointSituationCallback::OnDeviceAdded(LPCWSTR pwstrDeviceId) {
log_wdebugcpp(L"ayo we eventing za adin" << pwstrDeviceId);
return S_OK;
};
HRESULT EndpointSituationCallback::OnDeviceRemoved(LPCWSTR pwstrDeviceId) {
log_wdebugcpp(L"ayo we eventing za rmovin" << pwstrDeviceId);
return S_OK;
}
HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState) {
/*
* char *pszState = "?????";
*
* switch (dwNewState)
* {
* case DEVICE_STATE_ACTIVE:
* pszState = "ACTIVE";
* break;
* case DEVICE_STATE_DISABLED:
* pszState = "DISABLED";
* break;
* case DEVICE_STATE_NOTPRESENT:
* pszState = "NOTPRESENT";
* break;
* case DEVICE_STATE_UNPLUGGED:
* pszState = "UNPLUGGED";
* break;
* }
*
* printf(" -->New device state is DEVICE_STATE_%s (0x%8.8x)\n",
* pszState, dwNewState);
*/
HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState) {
switch (dwNewState){
case DEVICE_STATE_ACTIVE:
break;
case DEVICE_STATE_DISABLED:
break;
case DEVICE_STATE_NOTPRESENT:
break;
case DEVICE_STATE_UNPLUGGED:
break;
}
return S_OK;
}
@ -184,6 +178,10 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
this->endpoint = ep;
this->idx = idx;
/*
* It can't multiflag, it's that stupid. MS momento.
* Only shows most relevant flag according to MS, i.e. 0110 sends 0010
*/
//todo: preguntitas owindows dword no es uint32_t even tho mingw mingas
if(FAILED(endpoint->GetState(&this->endpointState))) {exit(-1);};
@ -203,7 +201,10 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
endpoint->OpenPropertyStore(STGM_READ, &properties);
PROPVARIANT pv;
properties->GetValue(PKEY_Device_FriendlyName , &pv);
friendlyName = std::wstring(pv.pwszVal);
if (pv.pwszVal == nullptr)
friendlyName = L"Unnamed Not Present Endpoint";
else
friendlyName = std::wstring(pv.pwszVal);
}
void Endpoint::setIndex(uint64_t idx){
@ -214,7 +215,6 @@ uint64_t Endpoint::getIndex(){
return idx;
}
std::wstring Endpoint::getName(){
return friendlyName;
}
@ -253,14 +253,13 @@ size_t Endpoint::getState(){
return this->endpointState;
}
void Endpoint::setVolume(NGuid guid, int channel, float volume) {
//TIP: There used to be log messages here. Now, it's a ghost town.
GUID tempMsGuid = NGuidToGUID(guid);
if (channel == AudioChannel::CHANNEL_MAIN) {
if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, &tempMsGuid))) {};
} else {
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) { };
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) {};
}
}
@ -391,7 +390,8 @@ void Overseer::initCOMLibrary() {
void Overseer::reloadEndpoints() {
IMMDeviceCollection *deviceCollection;
// | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED
if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &deviceCollection) ))
// NOTPRESENT shows a lot of garbage, unnamed devices.
if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED, &deviceCollection) ))
{ log_debugcpp("si"); };
/*