almost captured, only to hotplug. such is life...

This commit is contained in:
Hane 2023-09-14 18:01:32 +02:00
commit 44ccde6ac8
6 changed files with 235 additions and 63 deletions

View file

@ -3,7 +3,6 @@ GUID NGuidToGUID(NGuid guid) {
msGuid.Data1 = guid.data1; msGuid.Data1 = guid.data1;
msGuid.Data2 = guid.data2; msGuid.Data2 = guid.data2;
msGuid.Data3 = guid.data3; msGuid.Data3 = guid.data3;
msGuid.Data1 = guid.data1;
for (int i = 0; i < 8; i++){ for (int i = 0; i < 8; i++){
msGuid.Data4[i] = guid.data4[i]; msGuid.Data4[i] = guid.data4[i];
//log_debugcpp("MSGUID DATA4 BYTE " << i << ": "); //log_debugcpp("MSGUID DATA4 BYTE " << i << ": ");

View file

@ -39,30 +39,30 @@ HRESULT EndpointVolumeCallback::QueryInterface(REFIID riid, VOID **ppvInterface)
HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) { HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
if (pNotify == NULL) return E_INVALIDARG; if (pNotify == NULL) return E_INVALIDARG;
//delete osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller; //delete osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller;
//osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.freeData4(); //osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.freeData4();
//Could've made a function or = override to hide this within Nguid, but back in cont = bad. //Could've made a function or = override to hide this within Nguid, but back in cont = bad.
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data1 \ osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data1 \
= pNotify->guidEventContext.Data1; = pNotify->guidEventContext.Data1;
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data2 \ osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data2 \
= pNotify->guidEventContext.Data2; = pNotify->guidEventContext.Data2;
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data3 \ osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data3 \
= pNotify->guidEventContext.Data3; = pNotify->guidEventContext.Data3;
for(int i = 0; i < 8 /* Data4 size */; i++){ for(int i = 0; i < 8 /* Data4 size */; i++){
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data4[i] = pNotify->guidEventContext.Data4[i]; osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data4[i] = pNotify->guidEventContext.Data4[i];
} }
//memcpy(&osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller, &pNotify->guidEventContext,sizeof(NGuid) ); //memcpy(&osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller, &pNotify->guidEventContext,sizeof(NGuid) );
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->muted = pNotify->bMuted; osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->muted = pNotify->bMuted;
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->mainVolume = pNotify->fMasterVolume; osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->mainVolume = pNotify->fMasterVolume;
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channels = pNotify->nChannels; osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channels = pNotify->nChannels;
UINT j = 0; UINT j = 0;
//todo: do while here caused stack corruption; sus //todo: do while here caused stack corruption; sus
while(j < pNotify->nChannels) { while(j < pNotify->nChannels) {
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channelVolumes[j] = pNotify->afChannelVolumes[j]; osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channelVolumes[j] = pNotify->afChannelVolumes[j];
j++; j++;
} }
return S_OK; return S_OK;
@ -76,9 +76,10 @@ HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify
* *
*/ */
//todo: not on construct since it expects them to already exist; smells like refactor! //todo: not on construct since it expects them to already exist; smells like refactor!
void EndpointSituationCallback::fill(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices){ void EndpointSituationCallback::fill(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices, std::vector<Endpoint*> captureDevices){
this->deviceEnumerator = deviceEnumerator; this->deviceEnumerator = deviceEnumerator;
this->playbackDevices = playbackDevices; this->playbackDevices = playbackDevices;
this->captureDevices = captureDevices;
} }
ULONG EndpointSituationCallback::AddRef(){ ULONG EndpointSituationCallback::AddRef(){
@ -151,10 +152,14 @@ HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, D
osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_ACTIVE); osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_ACTIVE);
break; break;
case DEVICE_STATE_DISABLED: case DEVICE_STATE_DISABLED:
case DEVICE_STATE_NOTPRESENT:
case DEVICE_STATE_UNPLUGGED:
osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_DISABLED); osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_DISABLED);
break; break;
case DEVICE_STATE_NOTPRESENT:
osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_NOTPRESENT);
break;
case DEVICE_STATE_UNPLUGGED:
osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_UNPLUGGED);
break;
} }
return S_OK; return S_OK;
@ -190,6 +195,11 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
reloadEndpointChannels(); reloadEndpointChannels();
/*
* if(FAILED(endpoint->Activate(__uuidof(IAudioMeterInformation),
* CLSCTX_ALL, NULL, (void**)&endpointPeakMeter))) { log_debugcpp("peakbros..."); }
*/
//todo:: atexit into exit Gather ID //todo:: atexit into exit Gather ID
LPWSTR tempString = nullptr; LPWSTR tempString = nullptr;
if (FAILED(endpoint->GetId(&tempString))) {exit(-1);}; if (FAILED(endpoint->GetId(&tempString))) {exit(-1);};
@ -206,6 +216,11 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
friendlyName = std::wstring(pv.pwszVal); friendlyName = std::wstring(pv.pwszVal);
} }
/*
* Endpoint::Endpoint(IMMDevice* endpoint) : Endpoint(endpoint, 0) {};
*/
void Endpoint::activateEndpointVolume() { void Endpoint::activateEndpointVolume() {
if (this->endpointVolume == nullptr) if (this->endpointVolume == nullptr)
if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&this->endpointVolume))) { log_debugcpp(std::string("no endpointVolume (IAudioEndpointVolume)")); }; if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&this->endpointVolume))) { log_debugcpp(std::string("no endpointVolume (IAudioEndpointVolume)")); };
@ -372,6 +387,33 @@ void Endpoint::removeRoles(Roles role){
this->endpointRoles = roles; this->endpointRoles = roles;
} }
void Endpoint::setFlow() {
IMMEndpoint* flowGetter;
//this should be as simple as writing IID_IMMEndpoint, but it just won't find the macro, so I copied it. Sad.
GUID manual;
manual.Data1 = 0x1be09788;
manual.Data2 = 0x6894;
manual.Data3 = 0x4089;
manual.Data4[0] = 0x85;
manual.Data4[1] = 0x86;
manual.Data4[2] = 0x9a;
manual.Data4[3] = 0x2a;
manual.Data4[4] = 0x6c;
manual.Data4[5] = 0x26;
manual.Data4[6] = 0x5a;
manual.Data4[7] = 0xc5;
if(FAILED(this->endpoint->QueryInterface((const _GUID)manual, (void**)&flowGetter)))
{ log_debugcpp("no flow..."); }
EDataFlow MSflow;
HRESULT vafllar = flowGetter->GetDataFlow(&MSflow);
this->flow = (MSflow == EDataFlow::eRender ? Flows::FLOW_PLAYBACK : Flows::FLOW_CAPTURE);
flowGetter->Release();
}
Flows Endpoint::getFlow() {
return this->flow;
}
Endpoint::~Endpoint(){ Endpoint::~Endpoint(){
log_debugcpp("murio endpoint-san uwu"); log_debugcpp("murio endpoint-san uwu");
properties->Release(); properties->Release();
@ -394,6 +436,7 @@ void Overseer::initCOMLibrary() {
GUID tempGuid; GUID tempGuid;
if(FAILED(CoCreateGuid(&tempGuid))) { log_debugcpp("Failed to obtain GUID: " ); }; if(FAILED(CoCreateGuid(&tempGuid))) { log_debugcpp("Failed to obtain GUID: " ); };
//todo: wtf? why is it working? floats are ptrs...
this->guid = GUIDToNGuid(&tempGuid); this->guid = GUIDToNGuid(&tempGuid);
//if(FAILED(CoCreateInstance(__uuidof(CPolicyConfigClient), //if(FAILED(CoCreateInstance(__uuidof(CPolicyConfigClient),
@ -403,28 +446,34 @@ void Overseer::initCOMLibrary() {
//TODO: Uninitialize COM //TODO: Uninitialize COM
} }
void Overseer::reloadEndpoints() { void Overseer::reloadEndpoints(Flows flow) {
IMMDeviceCollection *deviceCollection; IMMDeviceCollection *deviceCollection;
unsigned int numEndpoints;
EDataFlow MSflow = (flow == Flows::FLOW_PLAYBACK ? EDataFlow::eRender : EDataFlow::eCapture);
// | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED // | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED
// NOTPRESENT shows a lot of garbage, unnamed devices. // NOTPRESENT shows a lot of garbage, unnamed devices.
if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED, &deviceCollection) )) if(FAILED(deviceEnumerator->EnumAudioEndpoints(MSflow, DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED, &deviceCollection) ))
{ log_debugcpp("si"); }; { log_debugcpp("si"); };
/* /*
* Counting them * Counting them
*/ */
if(FAILED(deviceCollection->GetCount(&numPlaybackEndpoints))) { log_debugcpp("si");}; if(FAILED(deviceCollection->GetCount(&numEndpoints))) { log_debugcpp("si");};
if(numPlaybackEndpoints == 0) { log_debugcpp("si"); }; if(numEndpoints == 0) { log_debugcpp("si"); };
/* /*
* Retrieving actual endpoints and storing them on their own class * Retrieving actual endpoints and storing them on their own class
*/ */
IMMDevice *temp; IMMDevice *temp;
for (unsigned int i = 0; i < numPlaybackEndpoints; i++){ for (unsigned int i = 0; i < numEndpoints; i++){
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); }; if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
Endpoint *endpoint = new Endpoint(temp, i); Endpoint *endpoint = new Endpoint(temp, i);
endpoint->setFlow();
//endpoint->setIndex(i); //endpoint->setIndex(i);
this->playbackDevices.push_back(endpoint); if (flow == Flows::FLOW_PLAYBACK)
this->playbackDevices.push_back(endpoint);
else
this->captureDevices.push_back(endpoint);
//TODO: le porblemx std::cout + "ola" + std::endl; //TODO: le porblemx std::cout + "ola" + std::endl;
} }
@ -447,30 +496,65 @@ void Overseer::reloadEndpoints() {
val = eCommunications; val = eCommunications;
break; break;
} }
deviceEnumerator->GetDefaultAudioEndpoint(EDataFlow::eRender, val, &temp); deviceEnumerator->GetDefaultAudioEndpoint(MSflow, val, &temp);
LPWSTR id = nullptr; LPWSTR id = nullptr;
for (unsigned int j = 0; j < numPlaybackEndpoints; j++){ if (flow == Flows::FLOW_PLAYBACK) {
std::wstring eptId = playbackDevices.at(j)->getId(); for (unsigned int j = 0; j < numEndpoints; j++) {
temp->GetId(&id); std::wstring eptId = playbackDevices.at(j)->getId();
int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, eptId.c_str(), -987, id, -987, NULL, NULL, 0); temp->GetId(&id);
if (comparison - 2 == 0) { int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, eptId.c_str(), -987, id, -987, NULL, NULL, 0);
log_wdebugcpp(L"ola defaul de " + std::to_wstring(i) + L" es " + id); if (comparison - 2 == 0) {
playbackDevices.at(j)->assignRoles((Roles)(1 << i)); log_wdebugcpp(L"ola defaul playback de "
+ std::to_wstring(i) + L" es " + id);
playbackDevices.at(j)->assignRoles((Roles)(1 << i));
}
}
} else {
for (unsigned int j = 0; j < numEndpoints; j++){
std::wstring eptId = captureDevices.at(j)->getId();
temp->GetId(&id);
int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, eptId.c_str(), -987, id, -987, NULL, NULL, 0);
if (comparison - 2 == 0) {
log_wdebugcpp(L"ola defaul capture de "
+ std::to_wstring(i) + L" es " + id);
captureDevices.at(j)->assignRoles((Roles)(1 << i));
}
} }
//uint8_t debg = playbackDevices.at(j)->getRoles();
} }
} }
} }
Endpoint* Overseer::addEndpoint(std::wstring endpointId, /* out */Flows* flow = nullptr) {
IMMDevice* newep;
if(FAILED(deviceEnumerator->GetDevice((LPCWSTR)endpointId.c_str(), &newep)))
log_debugcpp("ay caramba con la hot metida.");
Endpoint *endpoint = new Endpoint(newep);
Flows getFlow = endpoint->getFlow();
if (getFlow == Flows::FLOW_PLAYBACK) {
endpoint->setIndex(osh->getPlaybackEndpointsCount());
this->playbackDevices.push_back(endpoint);
} else {
endpoint->setIndex(osh->getCaptureEndpointsCount());
this->captureDevices.push_back(endpoint);
}
if (flow != nullptr) *flow = getFlow;
return endpoint;
}
Overseer::Overseer() { //: epsc(deviceEnumerator, playbackDevices){ Overseer::Overseer() { //: epsc(deviceEnumerator, playbackDevices){
//Initializing COM library //Initializing COM library
log_debugcpp("Initializing Overseer"); log_debugcpp("Initializing Overseer");
initCOMLibrary(); initCOMLibrary();
//Obtaining playback endpoint collection on this point in time //Obtaining playback endpoint collection on this point in time
reloadEndpoints(); reloadEndpoints(Flows::FLOW_PLAYBACK);
this->epsc.fill(deviceEnumerator, playbackDevices); //reloadEndpoints(Flows::FLOW_CAPTURE);
//Registering for endpoint information callback
this->epsc.fill(deviceEnumerator, playbackDevices, captureDevices);
if(FAILED(deviceEnumerator->RegisterEndpointNotificationCallback(((IMMNotificationClient*)&epsc)))) { log_debugcpp("when no enchufas......"); } if(FAILED(deviceEnumerator->RegisterEndpointNotificationCallback(((IMMNotificationClient*)&epsc)))) { log_debugcpp("when no enchufas......"); }
} }
@ -482,6 +566,10 @@ std::vector<Endpoint*> Overseer::getPlaybackEndpoints() {
return playbackDevices; return playbackDevices;
} }
std::vector<Endpoint*> Overseer::getCaptureEndpoints() {
return captureDevices;
}
Overseer::~Overseer(){ Overseer::~Overseer(){
log_debugcpp("cum"); log_debugcpp("cum");
deviceEnumerator->Release(); deviceEnumerator->Release();

View file

@ -33,6 +33,8 @@ class Endpoint {
public: public:
Endpoint(IMMDevice* endpoint, uint64_t idx); Endpoint(IMMDevice* endpoint, uint64_t idx);
//todo: how to forward declare delegate constructors?
Endpoint(IMMDevice* endpoint) : Endpoint(endpoint, 0) {};
void reloadEndpointChannels(); void reloadEndpointChannels();
uint64_t getIndex(); uint64_t getIndex();
void setIndex(uint64_t idx); void setIndex(uint64_t idx);
@ -47,6 +49,8 @@ class Endpoint {
void setRoles(Roles role); void setRoles(Roles role);
void assignRoles(Roles role); void assignRoles(Roles role);
void removeRoles(Roles role); void removeRoles(Roles role);
void setFlow();
Flows getFlow();
std::wstring getId(); std::wstring getId();
std::wstring getName(); std::wstring getName();
void setVolumeCallback(EndpointVolumeCallback *epc); void setVolumeCallback(EndpointVolumeCallback *epc);
@ -58,6 +62,7 @@ class Endpoint {
uint32_t channelCount = 0; uint32_t channelCount = 0;
IMMDevice* endpoint; IMMDevice* endpoint;
Flows flow;
IAudioEndpointVolume *endpointVolume = nullptr; IAudioEndpointVolume *endpointVolume = nullptr;
IPropertyStore *properties; IPropertyStore *properties;
std::wstring friendlyName; std::wstring friendlyName;
@ -65,6 +70,9 @@ class Endpoint {
unsigned long endpointState; unsigned long endpointState;
Roles endpointRoles = (Roles)0; Roles endpointRoles = (Roles)0;
uint64_t idx; uint64_t idx;
/* Not implemented in llvm-mingw. Sad!
* IAudioMeterInformation *endpointPeakMeter = nullptr;
*/
}; };
class EndpointVolumeCallback : public IAudioEndpointVolumeCallback { class EndpointVolumeCallback : public IAudioEndpointVolumeCallback {
@ -95,11 +103,12 @@ class EndpointSituationCallback : public IMMNotificationClient {
HRESULT OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState); HRESULT OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState);
HRESULT OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key); HRESULT OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key);
void fill(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices); void fill(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices, std::vector<Endpoint*> captureDevices);
private: private:
ULONG ref = 1; ULONG ref = 1;
IMMDeviceEnumerator *deviceEnumerator; IMMDeviceEnumerator *deviceEnumerator;
std::vector<Endpoint*> playbackDevices; std::vector<Endpoint*> playbackDevices;
std::vector<Endpoint*> captureDevices;
}; };
class Overseer { class Overseer {
@ -107,7 +116,10 @@ class Overseer {
public: public:
Overseer(); Overseer();
std::vector<Endpoint*> getPlaybackEndpoints(); std::vector<Endpoint*> getPlaybackEndpoints();
void reloadEndpoints(); std::vector<Endpoint*> getCaptureEndpoints();
void reloadEndpoints(Flows flow);
Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow);
NGuid getGuid(); NGuid getGuid();
//void setEndpointStatusCallback(); //void setEndpointStatusCallback();
//void setEndpointStatusCallback(); //void setEndpointStatusCallback();
@ -121,11 +133,12 @@ class Overseer {
private: private:
NGuid guid; NGuid guid;
unsigned int numPlaybackEndpoints;
IMMDeviceEnumerator *deviceEnumerator; IMMDeviceEnumerator *deviceEnumerator;
EndpointSituationCallback epsc; EndpointSituationCallback epsc;
//IPolicyConfig *policyConfig; //IPolicyConfig *policyConfig;
std::vector<Endpoint*> playbackDevices; std::vector<Endpoint*> playbackDevices;
std::vector<Endpoint*> captureDevices;
void initCOMLibrary(); void initCOMLibrary();
//IMMDeviceCollection *deviceCollection; //IMMDeviceCollection *deviceCollection;
//int numCaptureEndpoints; //int numCaptureEndpoints;

View file

@ -2,15 +2,28 @@
#include "contclasses.h" #include "contclasses.h"
//TODO: pragma once //TODO: pragma once
EndpointHandler::EndpointHandler(uint64_t idx) { EndpointHandler::EndpointHandler(uint64_t idx, Flows flow) {
//std::vector<Endpoint*> endpoints = osh->getPlaybackEndpoints().at(idx); //std::vector<Endpoint*> endpoints = osh->getPlaybackEndpoints().at(idx);
this->idx = idx; this->idx = idx;
this->ep = osh->getPlaybackEndpoints().at(idx); this->flow = flow;
this->ep = (flow == Flows::FLOW_PLAYBACK ? osh->getPlaybackEndpoints().at(idx) : osh->getCaptureEndpoints().at(idx));
epc = new EndpointVolumeCallback(ep); epc = new EndpointVolumeCallback(ep);
this->callbackInfo.caller = osh->getGuid(); this->callbackInfo.caller = osh->getGuid();
//epName = ep->getName(); //epName = ep->getName();
this->setBackEndpointVolumeCallbackInfoContent(this->getState()); this->setBackEndpointVolumeCallbackInfoContent(this->getState());
osh->pushBackEndpointHandler(this, flow);
}
void OverseerHandler::pushBackEndpointHandler(EndpointHandler* eph, Flows flow) {
if (eph == nullptr) return;
if (flow = Flows::FLOW_PLAYBACK)
playbackEndpointHandlers.push_back(eph);
else
captureEndpointHandlers.push_back(eph);
return;
} }
void EndpointHandler::setFrontVisibilityInfo(EndpointState state, uint64_t frontIdx){ void EndpointHandler::setFrontVisibilityInfo(EndpointState state, uint64_t frontIdx){
@ -139,35 +152,79 @@ std::vector<Endpoint*> OverseerHandler::getPlaybackEndpoints() {
return this->os->getPlaybackEndpoints(); return this->os->getPlaybackEndpoints();
} }
std::vector<EndpointHandler*> OverseerHandler::getEndpointHandlers(){ std::vector<Endpoint*> OverseerHandler::getCaptureEndpoints() {
return endpointHandlers; return this->os->getCaptureEndpoints();
}
std::vector<EndpointHandler*> OverseerHandler::getPlaybackEndpointHandlers(){
return playbackEndpointHandlers;
}
std::vector<EndpointHandler*> OverseerHandler::getCaptureEndpointHandlers(){
return captureEndpointHandlers;
} }
uint64_t OverseerHandler::getPlaybackEndpointsCount(){ uint64_t OverseerHandler::getPlaybackEndpointsCount(){
return this->os->getPlaybackEndpoints().size(); return this->os->getPlaybackEndpoints().size();
} }
uint64_t OverseerHandler::getCaptureEndpointsCount(){
return this->os->getCaptureEndpoints().size();
}
void OverseerHandler::reloadEndpointHandlers(){ void OverseerHandler::reloadEndpointHandlers(){
//todo: add capture
//std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>; //std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>;
log_debugcpp(" VSize: " + std::to_string(this->getPlaybackEndpointsCount())); log_debugcpp("Playback VSize: " + std::to_string(this->getPlaybackEndpointsCount()));
for(uint64_t i = 0; i < this->getPlaybackEndpointsCount(); i++){ for(uint64_t i = 0; i < this->getPlaybackEndpointsCount(); i++){
log_debugcpp("Creating handler " + std::to_string(i)); log_debugcpp("Creating Playback handler " + std::to_string(i));
if(i < (this->endpointHandlers.size()) && EndpointHandler* ephexx = new EndpointHandler(i, Flows::FLOW_PLAYBACK);
this->endpointHandlers.at(i) != nullptr) //this->playbackEndpointHandlers.push_back(ephexx);
delete endpointHandlers.at(i); log_debugcpp("Created Playback handler " + std::to_string(i) + ", adding to vector. " + " VSize: " + std::to_string(this->playbackEndpointHandlers.size()));
EndpointHandler* eph = new EndpointHandler(i); }
log_debugcpp("Created handler " + std::to_string(i) + ", adding to vector. " + " VSize: " + std::to_string(this->getPlaybackEndpointsCount()));
if (i >= this->endpointHandlers.size()) log_debugcpp("Capture VSize: " +
endpointHandlers.push_back(eph); std::to_string(this->getCaptureEndpointsCount()));
else endpointHandlers.at(i) = eph;
for(uint64_t i = 0; i < this->getCaptureEndpointsCount(); i++){
log_debugcpp("Creating Capture handler " + std::to_string(i));
/*
* if(i < (this->captureEndpointHandlers.size()) &&
* this->captureEndpointHandlers.at(i) != nullptr)
* delete captureEndpointHandlers.at(i);
*/
EndpointHandler* ephoo = new EndpointHandler(i, Flows::FLOW_CAPTURE);
//this->captureEndpointHandlers.push_back(ephoo);
log_debugcpp("Created Capture handler " + std::to_string(i) + ", adding to vector. " + " VSize: " + std::to_string(this->captureEndpointHandlers.size()));
/*
* if (i >= this->captureEndpointHandlers.size())
* captureEndpointHandlers.push_back(eph);
* else captureEndpointHandlers.at(i) = eph;
*/
} }
//setEndpointHandlers(ephs); //setEndpointHandlers(ephs);
} }
EndpointHandler* OverseerHandler::addEndpoint(std::wstring endpointId){
Flows flow;
Endpoint* newEp = this->os->addEndpoint(endpointId, &flow);
uint64_t ephIdx = (flow == Flows::FLOW_PLAYBACK ? this->getPlaybackEndpointsCount() : this->getCaptureEndpointsCount());
EndpointHandler* newEph = new EndpointHandler(ephIdx, flow);
// std::vector<EndpointHandler*> getPlaybackEndpointHandlers();
//std::vector<EndpointHandler*> getCaptureEndpointHandlers();
return newEph;
}
NGuid OverseerHandler::getGuid() { NGuid OverseerHandler::getGuid() {
return this->os->getGuid(); return this->os->getGuid();
} }
@ -182,13 +239,20 @@ void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpo
void OverseerHandler::reviseEndpointShowing(std::wstring endpointId, EndpointState state) { void OverseerHandler::reviseEndpointShowing(std::wstring endpointId, EndpointState state) {
EndpointHandler* eph = nullptr; EndpointHandler* eph = nullptr;
for (auto loopEph : this->endpointHandlers) { for (auto loopEph : this->playbackEndpointHandlers) {
if (loopEph->getId() == endpointId) { if (loopEph->getId() == endpointId) {
eph = loopEph; eph = loopEph;
break; break;
} }
} }
if (!eph) {
}
//todo: testing missing shiez. sowwy
//if(!eph) osh->
if(EndpointState::ENDPOINT_ACTIVE & state) { if(EndpointState::ENDPOINT_ACTIVE & state) {
this->addEndpointWidget(eph); this->addEndpointWidget(eph);
} else if (eph->getFrontVisibilityState() == EndpointState::ENDPOINT_ACTIVE){ } else if (eph->getFrontVisibilityState() == EndpointState::ENDPOINT_ACTIVE){
@ -207,5 +271,5 @@ void OverseerHandler::setRemoveEndpointWidgetFunction(std::function<void(uint64_
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){ void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){
this->endpointHandlers = ephs; this->playbackEndpointHandlers = ephs;
} }

View file

@ -62,7 +62,7 @@ struct BackEndpointVolumeCallbackInfo {
class EndpointHandler { class EndpointHandler {
public: public:
EndpointHandler(uint64_t idx); EndpointHandler(uint64_t idx, Flows flow);
void setBackEndpointVolumeCallbackInfoContent(uint8_t state); void setBackEndpointVolumeCallbackInfoContent(uint8_t state);
//these two, currently unused. If I use them, I should feel bad. //these two, currently unused. If I use them, I should feel bad.
@ -84,6 +84,7 @@ public:
uint64_t getFrontVisibilityIndex(); uint64_t getFrontVisibilityIndex();
EndpointState getFrontVisibilityState(); EndpointState getFrontVisibilityState();
Flows getFlow();
float getVolume(int channel); float getVolume(int channel);
bool getMute(); bool getMute();
size_t getState(); size_t getState();
@ -102,7 +103,7 @@ private:
uint64_t idx; uint64_t idx;
Endpoint *ep = nullptr; Endpoint *ep = nullptr;
EndpointVolumeCallback *epc = nullptr; EndpointVolumeCallback *epc = nullptr;
Flows flow;
BackEndpointVolumeCallbackInfo callbackInfo; BackEndpointVolumeCallbackInfo callbackInfo;
struct EndpointHandlerFrontVisibility { struct EndpointHandlerFrontVisibility {
EndpointState visibility = EndpointState::ENDPOINT_ALL; EndpointState visibility = EndpointState::ENDPOINT_ALL;
@ -125,15 +126,21 @@ public:
void setAddEndpointWidgetFunction(std::function<void(EndpointHandler*)> addEndpointWidget); void setAddEndpointWidgetFunction(std::function<void(EndpointHandler*)> addEndpointWidget);
void setEndpointHandlers(std::vector<EndpointHandler*> ephs); void setEndpointHandlers(std::vector<EndpointHandler*> ephs);
std::vector<EndpointHandler*> getEndpointHandlers(); std::vector<EndpointHandler*> getPlaybackEndpointHandlers();
std::vector<EndpointHandler*> getCaptureEndpointHandlers();
std::vector<Endpoint*> getPlaybackEndpoints(); std::vector<Endpoint*> getPlaybackEndpoints();
std::vector<Endpoint*> getCaptureEndpoints();
void pushBackEndpointHandler(EndpointHandler* eph, Flows flow);
uint64_t getPlaybackEndpointsCount(); uint64_t getPlaybackEndpointsCount();
uint64_t getCaptureEndpointsCount();
void reloadEndpointHandlers(); void reloadEndpointHandlers();
EndpointHandler* addEndpoint(std::wstring endpointId);
NGuid getGuid(); NGuid getGuid();
private: private:
Overseer *os; Overseer *os;
std::vector<EndpointHandler*> endpointHandlers; std::vector<EndpointHandler*> playbackEndpointHandlers;
std::vector<EndpointHandler*> captureEndpointHandlers;
std::function<void(Roles, std::wstring /* endpointid */)> changeFrontDefaults; std::function<void(Roles, std::wstring /* endpointid */)> changeFrontDefaults;
std::function<void(uint64_t /* epw id */)> removeEndpointWidget; std::function<void(uint64_t /* epw id */)> removeEndpointWidget;
std::function<void(EndpointHandler*)> addEndpointWidget; std::function<void(EndpointHandler*)> addEndpointWidget;

View file

@ -212,6 +212,7 @@ void MainWindow::removeEndpointWidget(EndpointWidgetEvent<uint64_t>* ev){
this->layout->removeWidget(ews.at(i)); this->layout->removeWidget(ews.at(i));
uint64_t saisu = ews.size(); uint64_t saisu = ews.size();
//delete ews.at(index); //delete ews.at(index);
delete ews.at(i);
while ((i + 1) < ews.size()) { while ((i + 1) < ews.size()) {
ews.at(i) = ews.at(i + 1); ews.at(i) = ews.at(i + 1);
ews.at(i)->setIndex(i); ews.at(i)->setIndex(i);
@ -407,11 +408,11 @@ void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
void MainWindow::reloadEndpointWidgets() { void MainWindow::reloadEndpointWidgets() {
size_t i = 0; size_t i = 0;
for (size_t epwIndex = 0; i < (osh->getEndpointHandlers().size()); i++) { for (size_t epwIndex = 0; i < (osh->getPlaybackEndpointHandlers().size()); i++) {
if (osh->getEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){ if (osh->getPlaybackEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){
log_debugcpp("EPWidget creation"); log_debugcpp("EPWidget creation");
//osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid(); //osh->getPlaybackEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid();
EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getEndpointHandlers().at(i), widget); EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getPlaybackEndpointHandlers().at(i), widget);
epwIndex++; epwIndex++;
//alfinal estoes solopara inicializarlmao //alfinal estoes solopara inicializarlmao
ews.push_back(epw); ews.push_back(epw);