wip: dynamically updated endpoint name

This commit is contained in:
Hane 2024-04-19 18:58:26 +02:00
commit 1b2ab191ca
5 changed files with 55 additions and 29 deletions

View file

@ -134,13 +134,10 @@ HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify
} }
/*
* EndpointSituationCallback::EndpointSituationCallback(std::vector<Endpoint*>* playbackDevices, std::vector<Endpoint*>* captureDevices){
* this->captureDevices = captureDevices;
* this->playbackDevices = playbackDevices;
* }
*/
EndpointSituationCallback::EndpointSituationCallback(Overseer* os){
this->os = os;
}
ULONG EndpointSituationCallback::AddRef(){ ULONG EndpointSituationCallback::AddRef(){
@ -227,13 +224,7 @@ HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, D
} }
HRESULT EndpointSituationCallback::OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) { HRESULT EndpointSituationCallback::OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) {
os->updateEndpointInfo(std::wstring(pwstrDeviceId));
/* Lacking impl again? */
PWSTR test;
HRESULT ctrl = PSGetNameFromPropertyKey(key, &test);
if (ctrl == S_OK) log_wdebugcpp(test);
return S_OK; return S_OK;
} }
@ -267,12 +258,7 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
CoTaskMemFree(tempString); CoTaskMemFree(tempString);
endpoint->OpenPropertyStore(STGM_READ, &properties); endpoint->OpenPropertyStore(STGM_READ, &properties);
PROPVARIANT pv; this->updateName();
properties->GetValue(PKEY_Device_FriendlyName , &pv);
if (pv.pwszVal == nullptr)
friendlyName = L"Unnamed Not Present Endpoint";
else
friendlyName = std::wstring(pv.pwszVal);
this->setFlow(); this->setFlow();
if (this->flow == Flows::FLOW_PLAYBACK) { if (this->flow == Flows::FLOW_PLAYBACK) {
@ -280,6 +266,20 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
} }
} }
void Endpoint::updateName() {
PROPVARIANT pv;
#define store_name(key, propvariant, wstr) do { \
properties->GetValue(key , &propvariant); \
if (pv.pwszVal == nullptr) wstr = L"Unnamed Not Present Endpoint"; \
else wstr = std::wstring(pv.pwszVal); \
} while (0)
store_name(PKEY_Device_FriendlyName, pv, friendlyName);
store_name(PKEY_Device_DeviceDesc, pv, descriptionName);
store_name(PKEY_DeviceInterface_FriendlyName, pv, deviceName);
#undef store_name
}
void Endpoint::activateEndpointSessions() { void Endpoint::activateEndpointSessions() {
//sessionManager; //sessionManager;
if (FAILED(endpoint->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**) &sessionManager))) { log_wdebugcpp(L"sesionbros..."); return; } if (FAILED(endpoint->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**) &sessionManager))) { log_wdebugcpp(L"sesionbros..."); return; }
@ -666,7 +666,7 @@ Endpoint* Overseer::addEndpoint(std::wstring endpointId, /* out */Flows* flow =
return endpoint; return endpoint;
} }
Overseer::Overseer() { //: epsc(&playbackDevices, &captureDevices){ Overseer::Overseer() : epsc(this){
//Initializing COM library //Initializing COM library
log_debugcpp("Initializing Overseer"); log_debugcpp("Initializing Overseer");
initCOMLibrary(); initCOMLibrary();
@ -719,6 +719,18 @@ std::vector<Endpoint*> Overseer::getCaptureEndpoints() {
return captureDevices; return captureDevices;
} }
void Overseer::updateEndpointInfo(std::wstring endpointId) {
log_wdebugcpp(L"new name Endpoint id: " + endpointId);
//todo: reintroduce capture devices
for(auto ep : playbackDevices) {
if (ep->getId() == endpointId) {
ep->updateName();
osh->updateFrontEndpointName(ep);
break;
}
}
}
Overseer::~Overseer(){ Overseer::~Overseer(){
log_debugcpp("cum"); log_debugcpp("cum");
deviceEnumerator->Release(); deviceEnumerator->Release();

View file

@ -32,6 +32,7 @@ class Endpoint {
Flows getFlow(); Flows getFlow();
std::wstring getId(); std::wstring getId();
std::wstring getName(); std::wstring getName();
void updateName();
void setVolumeCallback(EndpointVolumeCallback *epc); void setVolumeCallback(EndpointVolumeCallback *epc);
void removeVolumeCallback(EndpointVolumeCallback *epc); void removeVolumeCallback(EndpointVolumeCallback *epc);
@ -57,6 +58,8 @@ class Endpoint {
IAudioEndpointVolume *endpointVolume = nullptr; IAudioEndpointVolume *endpointVolume = nullptr;
IPropertyStore *properties; IPropertyStore *properties;
std::wstring friendlyName; std::wstring friendlyName;
std::wstring descriptionName;
std::wstring deviceName;
std::wstring endpointId; std::wstring endpointId;
unsigned long endpointState; unsigned long endpointState;
Roles endpointRoles = (Roles)0; Roles endpointRoles = (Roles)0;
@ -84,8 +87,7 @@ class EndpointVolumeCallback : public IAudioEndpointVolumeCallback {
class EndpointSituationCallback : public IMMNotificationClient { class EndpointSituationCallback : public IMMNotificationClient {
public: public:
//EndpointSituationCallback(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices, std::vector<Endpoint*> captureDevices); EndpointSituationCallback(Overseer* os);
//EndpointSituationCallback(std::vector<Endpoint*>* playbackDevices, std::vector<Endpoint*>* captureDevices);
ULONG AddRef(); ULONG AddRef();
ULONG Release(); ULONG Release();
HRESULT QueryInterface(REFIID riid, VOID **ppvInterface); HRESULT QueryInterface(REFIID riid, VOID **ppvInterface);
@ -97,9 +99,7 @@ class EndpointSituationCallback : public IMMNotificationClient {
private: private:
ULONG ref = 1; ULONG ref = 1;
//IMMDeviceEnumerator *deviceEnumerator; Overseer* os;
//std::vector<Endpoint*>* playbackDevices;
//std::vector<Endpoint*>* captureDevices;
}; };
class Overseer { class Overseer {
@ -107,9 +107,9 @@ class Overseer {
public: public:
Overseer(); Overseer();
void openControlPanel(); void openControlPanel();
//todo: restore/overseer
std::vector<Endpoint*> getPlaybackEndpoints(); std::vector<Endpoint*> getPlaybackEndpoints();
std::vector<Endpoint*> getCaptureEndpoints(); std::vector<Endpoint*> getCaptureEndpoints();
void updateEndpointInfo(std::wstring endpointId);
void reloadEndpoints(Flows flow); void reloadEndpoints(Flows flow);
Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow); Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow);

View file

@ -294,6 +294,13 @@ void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpo
this->changeFrontDefaults(role, endpointId); this->changeFrontDefaults(role, endpointId);
} }
void OverseerHandler::updateFrontEndpointName(Endpoint* ep) {
//todo: reintroduce capture devices
for (auto eph : playbackEndpointHandlers) {
if (eph->getEndpoint() == ep) eph->getCallbackInfo()->updateName = true;
}
}
void OverseerHandler::reviseEndpointShowing(std::wstring endpointId, EndpointState state) { void OverseerHandler::reviseEndpointShowing(std::wstring endpointId, EndpointState state) {
std::vector<EndpointHandler*> allHandlers; std::vector<EndpointHandler*> allHandlers;
allHandlers.insert(allHandlers.end(), this->captureEndpointHandlers.begin(), this->captureEndpointHandlers.end()); allHandlers.insert(allHandlers.end(), this->captureEndpointHandlers.begin(), this->captureEndpointHandlers.end());

View file

@ -18,6 +18,7 @@ struct BackEndpointVolumeCallbackInfo {
float mainVolume; float mainVolume;
size_t channels; size_t channels;
std::vector<float> channelVolumes; std::vector<float> channelVolumes;
bool updateName = false;
}; };
class EndpointHandler { class EndpointHandler {
@ -30,7 +31,7 @@ public:
//EndpointVolumeCallback* getEndpointVolumeCallback(); //EndpointVolumeCallback* getEndpointVolumeCallback();
//Endpoint* getEndpoint(); //Endpoint* getEndpoint();
//std::wstring epName; //todo: name refactor
BackEndpointVolumeCallbackInfo* getCallbackInfo(); BackEndpointVolumeCallbackInfo* getCallbackInfo();
uint32_t getChannelCount(); uint32_t getChannelCount();
@ -103,6 +104,7 @@ public:
void setChangeFrontDefaultsFunction(std::function<void(Roles, std::wstring)> changeFrontDefaults); void setChangeFrontDefaultsFunction(std::function<void(Roles, std::wstring)> changeFrontDefaults);
void changeFrontDefaultsCallback(Roles role, std::wstring endpointId); void changeFrontDefaultsCallback(Roles role, std::wstring endpointId);
void updateFrontEndpointName(Endpoint* ep);
//void setReviseEndpointShowingFunction(std::function<void(std::wstring, EndpointState)> reviseEndpointShowing); //void setReviseEndpointShowingFunction(std::function<void(std::wstring, EndpointState)> reviseEndpointShowing);
void reviseEndpointShowing(std::wstring endpointId, EndpointState state); void reviseEndpointShowing(std::wstring endpointId, EndpointState state);
void setRemoveEndpointWidgetFunction(std::function<void(uint64_t)> removeEndpointWidget); void setRemoveEndpointWidgetFunction(std::function<void(uint64_t)> removeEndpointWidget);

View file

@ -420,6 +420,11 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i
//if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW. //if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW.
//todo: global + constexpr + ratio //todo: global + constexpr + ratio
const float roundingFactor = 0.005; const float roundingFactor = 0.005;
if (eph->getCallbackInfo()->updateName) {
eph->getCallbackInfo()->updateName = false;
mainLabel->setText(QString::fromStdWString(eph->getName()));
mainLabel->setMinimumHeight(mainLabel->sizeHint().height());
}
mainSlider->blockSignals(true); mainSlider->blockSignals(true);
muteButton->blockSignals(true); muteButton->blockSignals(true);
mainSlider->setValue((int)((eph->getCallbackInfo()->mainVolume + roundingFactor) * 100)); mainSlider->setValue((int)((eph->getCallbackInfo()->mainVolume + roundingFactor) * 100));