phantom header and default role recollection

This commit is contained in:
Hane 2023-08-29 19:00:07 +02:00
commit e278280c4b
10 changed files with 354 additions and 46 deletions

View file

@ -1,15 +1,15 @@
#include <backlasses.h>
#include <backfuncs.h>
EndpointCallback::EndpointCallback(Endpoint* ep){
EndpointVolumeCallback::EndpointVolumeCallback(Endpoint* ep){
this->ep = ep;
}
ULONG EndpointCallback::AddRef(){
ULONG EndpointVolumeCallback::AddRef(){
return InterlockedIncrement(&ref);
}
ULONG EndpointCallback::Release(){
ULONG EndpointVolumeCallback::Release(){
ULONG tempRef = InterlockedDecrement(&ref);
if (tempRef == 0) {
delete this;
@ -17,7 +17,7 @@ ULONG EndpointCallback::Release(){
return tempRef;
}
HRESULT EndpointCallback::QueryInterface(REFIID riid, VOID **ppvInterface) {
HRESULT EndpointVolumeCallback::QueryInterface(REFIID riid, VOID **ppvInterface) {
if (IID_IUnknown == riid)
{
AddRef();
@ -36,10 +36,9 @@ HRESULT EndpointCallback::QueryInterface(REFIID riid, VOID **ppvInterface) {
return S_OK;
}
HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
if (pNotify == NULL) return E_INVALIDARG;
//TODO: MEMORY LEAK. FREE DATA4 FROM NGUID.
//TODO: el default = objcopy frees?
//delete osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller;
//osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.freeData4();
@ -71,10 +70,24 @@ HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
this->endpoint = ep;
this->idx = idx;
if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { log_debugcpp("si"); };
if (FAILED(endpointVolume->GetChannelCount(&channelCount))) log_debugcpp("get channel count fail");
//Obtaining friendly name: IPropertyStore creates PROPVARIANT per field
// hr = endpointPtr->GetId(&endpointID);
//if(FAILED()) {};
DWORD tempState = 0;
if(FAILED(endpoint->GetState(&tempState))) {exit(-1);};
this->endpointState = tempState;
if (tempState == DEVICE_STATE_ACTIVE) {
if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { /* log_debugcpp("si"); */ };
if (FAILED(endpointVolume->GetChannelCount(&channelCount))) {};/* log_debugcpp("get channel count fail"); */
} else channelCount = 0;
//todo:: atexit into exit Gather ID
LPWSTR tempString = nullptr;
if (FAILED(endpoint->GetId(&tempString))) {exit(-1);};
endpointId = std::wstring(tempString);
log_wdebugcpp(endpointId);
CoTaskMemFree(tempString);
endpoint->OpenPropertyStore(STGM_READ, &properties);
PROPVARIANT pv;
properties->GetValue(PKEY_Device_FriendlyName , &pv);
@ -94,6 +107,10 @@ std::wstring Endpoint::getName(){
return friendlyName;
}
std::wstring Endpoint::getId(){
return endpointId;
}
float Endpoint::getVolume(int channel){
float volume;
if (channel == AudioChannel::CHANNEL_MAIN) {
@ -116,19 +133,13 @@ bool Endpoint::getMute(){
return mute;
}
/*
* float Endpoint::getLeftChannelVolume(){
* float volume;
* if(FAILED(endpointVolume-> GetChannelVolumeLevelScalar(0, &volume)) { log_debugcpp("si"); } );
* return volume;
* }
*
* float Endpoint::getRightChannelVolume(){
* float volume;
* if(FAILED(endpointVolume-> GetChannelVolumeLevelScalar(1, &volume)) { log_debugcpp("si");}
* return volume;
* }
*/
void Endpoint::setState(uint8_t state){
this->endpointState = state;
}
uint8_t Endpoint::getState(){
return this->endpointState;
}
void Endpoint::setVolume(NGuid* guid, int channel, float volume) {
@ -146,16 +157,26 @@ void Endpoint::setMute(NGuid* guid, bool muted) {
if(FAILED(endpointVolume->SetMute(muted, &tempMsGuid))) { /* TIP: Above */ };
}
void Endpoint::setCallback(EndpointCallback *epc){
void Endpoint::setVolumeCallback(EndpointVolumeCallback *epc){
endpointVolume->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)epc);
}
void Endpoint::removeCallback(EndpointCallback *epc){
void Endpoint::removeVolumeCallback(EndpointVolumeCallback *epc){
endpointVolume->UnregisterControlChangeNotify((IAudioEndpointVolumeCallback*)epc);
}
uint8_t Endpoint::getRoles(){
return this->endpointRoles;
}
void Endpoint::setRoles(uint8_t role){
//todo: operador virtuoso
uint8_t roles = endpointRoles | role;
this->endpointRoles = roles;
}
Endpoint::~Endpoint(){
log_debugcpp("cum");
log_debugcpp("murio endpoint-san uwu");
properties->Release();
endpointVolume->Release();
endpoint->Release();
@ -183,7 +204,7 @@ 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) ))
if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE , &deviceCollection) ))
{ log_debugcpp("si"); };
@ -193,8 +214,8 @@ void Overseer::reloadEndpoints() {
//Retrieving actual endpoints and storing them on their own class
IMMDevice *temp;
for (unsigned int i = 0; i < numPlaybackEndpoints; i++){
IMMDevice *temp;
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
Endpoint *endpoint = new Endpoint(temp, i);
//endpoint->setIndex(i);
@ -203,6 +224,36 @@ void Overseer::reloadEndpoints() {
}
deviceCollection->Release();
//Discerning default endpoints per role
//order: console, multimedia, communications
for(int i = 0; i < ERole_enum_count; i++){
ERole val;
switch(i) {
case 0:
val = eConsole;
break;
case 1:
val = eMultimedia;
break;
case 2:
val = eCommunications;
break;
}
deviceEnumerator->GetDefaultAudioEndpoint(EDataFlow::eRender, val, &temp);
LPWSTR id = nullptr;
for (unsigned int j = 0; j < numPlaybackEndpoints; j++){
std::wstring test = playbackDevices.at(j)->getId();
temp->GetId(&id);
int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, test.c_str(), -987, id, -987, NULL, NULL, 0);
if (comparison - 2 == 0) {
log_wdebugcpp("ola defaul de " << i << " es " << id);
playbackDevices.at(j)->setRoles((1 << i));
}
//uint8_t debg = playbackDevices.at(j)->getRoles();
}
}
}
Overseer::Overseer(){