guid sent and validated for mute

This commit is contained in:
Hane 2023-08-12 12:29:01 +02:00
commit c8d64481e8
7 changed files with 72 additions and 65 deletions

View file

@ -8,5 +8,5 @@ INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont"
SOURCES += qtestmain.cpp qtclasses.cpp backlasses.cpp contclasses.cpp
HEADERS += qtclasses.h backlasses.h contclasses.h global.h debug.h
HEADERS += qtclasses.h backlasses.h contclasses.h global.h debug.h backfuncs.h
#DESTDIR += "build"

33
src/back/backfuncs.h Normal file
View file

@ -0,0 +1,33 @@
GUID NGuidToGUID(NGuid* guid){
GUID msGuid = GUID();
msGuid.Data1 = guid->data1;
msGuid.Data2 = guid->data2;
msGuid.Data3 = guid->data3;
msGuid.Data1 = guid->data1;
for (int i = 0; i < 8; i++){
msGuid.Data4[i] = guid->data4[i];
log_debugcpp("MSGUID DATA4 BYTE " << i << ": ");
log_debugcpp(print_as_binary(8, uint32_t, msGuid.Data4[i]));
}
log_debugcpp("MSGUID DATA1: " << msGuid.Data1);
log_debugcpp("MSGUID DATA2: " << msGuid.Data2);
log_debugcpp("MSGUID DATA3: " << msGuid.Data3);
return msGuid;
}
NGuid GUIDToNGuid(LPGUID msGuid){
NGuid guid = NGuid();
guid.data1 = msGuid->Data1;
guid.data2 = msGuid->Data2;
guid.data3 = msGuid->Data3;
for (int i = 0; i < 8; i++){
guid.data4[i] = msGuid->Data4[i];
log_debugcpp("GUID DATA4 BYTE " << i << ": ");
log_debugcpp(print_as_binary(8, uint32_t, guid.data4[i]));
}
log_debugcpp("GUID DATA1: " << guid.data1);
log_debugcpp("GUID DATA2: " << guid.data2);
log_debugcpp("GUID DATA3: " << guid.data3);
return guid;
}

View file

@ -1,4 +1,5 @@
#include <backlasses.h>
#include <backfuncs.h>
EndpointCallback::EndpointCallback(Endpoint* ep){
this->ep = ep;
@ -37,14 +38,17 @@ HRESULT EndpointCallback::QueryInterface(REFIID riid, VOID **ppvInterface) {
HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
if (pNotify == NULL) return E_INVALIDARG;
/*
* AUDIO_VOLUME_NOTIFICATION_DATA eventData = *pNotify;
* LPGUID guid = osh->getOverseer()->getGuid();
*
* if (eventData.guidEventContext != *guid) {
* osh->parseExternalEndpointCallback(this, eventData);
* }
*/
AUDIO_VOLUME_NOTIFICATION_DATA eventData = *pNotify;
NGuid* guid = osh->getGuid();
if (memcmp(guid, &eventData, sizeof(guid)) == 0) {
log_debugcpp("perlitas");
} else {
log_debugcpp("Onnanokotify says Stored: " << guid->data1);
log_debugcpp("Onnanokotify says Grace of God: " << eventData.guidEventContext.Data1);
}
return S_OK;
}
@ -119,12 +123,14 @@ void Endpoint::setVolume(int channel, float volume) {
}
}
void Endpoint::setMute() {
void Endpoint::setMute(NGuid* guid) {
BOOL mut;
//log_debugcpp("bool mute arrives as " << mut);
if(FAILED(endpointVolume->GetMute(&mut))) { log_debugcpp("si"); }
log_debugcpp("translate to BOOL as " << mut);
if(FAILED(endpointVolume->SetMute((mut == false ? 1 : 0), NULL))) { log_debugcpp("si"); };
log_debugcpp("translate to BOOL as " << mut);
//TODO: use new funcs
GUID tempMsGuid = NGuidToGUID(guid);
if(FAILED(endpointVolume->SetMute((mut == false ? 1 : 0), &tempMsGuid))) { log_debugcpp("si"); };
}
void Endpoint::setCallback(EndpointCallback *epc){
@ -142,8 +148,7 @@ Endpoint::~Endpoint(){
endpoint->Release();
}
void Overseer::initCOMLibrary(){
void Overseer::initCOMLibrary() {
if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE))) {
log_debugcpp("si"); };
@ -155,30 +160,13 @@ void Overseer::initCOMLibrary(){
(void**)&deviceEnumerator)) )
{ log_debugcpp("si"); };
GUID tempGuid;
/*
* HRESULT her = CoCreateGuid(&tempGuid);
* std::bitset<32> bon(her);
* //if (hr == EPT_S_CANT_CREATE)
* log_debugcpp("Failed to obtain GUID: " /\*<< std::hex *\/<< her << std::dec << " " << bon);
*/
if(FAILED(CoCreateGuid(&tempGuid))) { log_debugcpp("Failed to obtain GUID: " ); };
this->guid.data1 = tempGuid.Data1;
this->guid.data2 = tempGuid.Data2;
this->guid.data3 = tempGuid.Data3;
for (int i = 0; i < 8; i++){
this->guid.data4[i] = tempGuid.Data4[i];
log_debugcpp("GUID DATA4 BYTE " << i << ": ");
log_debugcpp(print_as_binary(8, uint32_t, this->guid.data4[i]));
}
log_debugcpp("GUID DATA1: " << this->guid.data1);
log_debugcpp("GUID DATA2: " << this->guid.data2);
log_debugcpp("GUID DATA3: " << this->guid.data3);
this->guid = GUIDToNGuid(&tempGuid);
//TODO: Release lpguid?
//TODO: Uninitialize COM
}
void Overseer::reloadEndpoints() {
@ -224,8 +212,8 @@ Overseer::Overseer(){
//int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
//TODO guid
NGuid Overseer::getGuid() {
return guid;
NGuid* Overseer::getGuid() {
return &guid;
}
std::vector<Endpoint*> Overseer::getPlaybackEndpoints() {

View file

@ -3,8 +3,6 @@
//done by qt by def #define UNICODE
//#include "debug.h"
#include "global.h"
#include "contclasses.h"
/* #include <vector> */
/* #include <iostream> */
/* #include <wstring> */
@ -22,6 +20,7 @@
//#include <comip.h>
#include <Winerror.h>
#include "global.h"
#include "contclasses.h"
class EndpointCallback;
@ -36,7 +35,7 @@ class Endpoint {
/* float getLeftChannelVolume(); */
/* float getRightChannelVolume(); */
float getVolume(int channel);
void setMute();
void setMute(NGuid* guid);
bool getMute();
std::wstring getName();
void setCallback(EndpointCallback *epc);
@ -75,7 +74,7 @@ class Overseer {
Overseer();
std::vector<Endpoint*> getPlaybackEndpoints();
void reloadEndpoints();
NGuid getGuid();
NGuid* getGuid();
//~Overseer();
//int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint);
//int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);

View file

@ -8,7 +8,7 @@ EndpointHandler::EndpointHandler(uint64_t idx) {
this->ep = endpoints.at(idx);
epc = new EndpointCallback(ep);
//epName = ep->getName();
//ep->setCallback(*epc);
ep->setCallback(epc);
}
void EndpointHandler::setIndex(uint64_t idx){
@ -29,10 +29,10 @@ void EndpointHandler::setValue(int channel, int value){
else ep->setVolume(channel, (float)value / 100);
}
void EndpointHandler::setMute(){
void EndpointHandler::setMute(NGuid* guid){
//Qt momento, de ahi el param?
log_debugcpp("kinda handling the muting tbh");
ep->setMute();
ep->setMute(guid);
}
std::wstring EndpointHandler::getName(){
@ -94,24 +94,10 @@ void OverseerHandler::reloadEndpointHandlers(){
//setEndpointHandlers(ephs);
}
/*
* void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify){
* log_debugcpp("parsing in da ovasiar");
* for (uint64_t i = 0; i < endpointHandlers.size(); i++){
* if(endpointHandlers.at(i)->eph->epc == fEpc) {
* endpointHandlers.at(i)->muteButton->setText(endpointHandlers.at(i)->eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
* break;
* }
* }
*/
/*
* connect(mainSlider, &QSlider::valueChanged, [this](int newValue){this->eph->setValue(ENDPOINT_MASTER_VOLUME, newValue); });
* connect(leftChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setValue(ENDPOINT_LEFT_CHANNEL_VOLUME, newValue); this->leftChannelLabel->setText(QString::number(newValue)); });
* connect(rightChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setValue(ENDPOINT_RIGHT_CHANNEL_VOLUME, newValue); this->rightChannelLabel->setText(QString::number(newValue)); });
* connect(muteButton, &QPushButton::clicked, [this](bool clicked){ log_debugcpp("cliqui" << clicked << "cloqui"); this->eph->setMute(); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); });
* log_debugcpp("ENDPOINT_WIDGETED");
*/
NGuid* OverseerHandler::getGuid() {
return os.getGuid();
}
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ews){

View file

@ -16,8 +16,8 @@ class EndpointHandler {
public:
EndpointHandler(uint64_t idx);
//TODO: get();
Endpoint *ep;
EndpointCallback *epc;
Endpoint *ep = nullptr;
EndpointCallback *epc = nullptr;
//std::wstring epName;
void setIndex(uint64_t idx);
@ -29,7 +29,7 @@ public:
bool getMute();
void setValue(int channel, int value);
void setMute();
void setMute(NGuid* guid);
~EndpointHandler();
private:
uint64_t idx;
@ -50,6 +50,7 @@ public:
std::vector<Endpoint*> getPlaybackEndpoints();
uint64_t getPlaybackEndpointsCount();
void reloadEndpointHandlers();
NGuid* getGuid();
//void parseExternalEndpointCallback(EndpointCallback *epc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify);
//static Overseer* getOverseer();

View file

@ -58,7 +58,7 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
connect(mainSlider, &QSlider::valueChanged, [this](int newValue){this->eph->setValue(ENDPOINT_MASTER_VOLUME, newValue); });
connect(leftChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setValue(ENDPOINT_LEFT_CHANNEL_VOLUME, newValue); this->leftChannelLabel->setText(QString::number(newValue)); });
connect(rightChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setValue(ENDPOINT_RIGHT_CHANNEL_VOLUME, newValue); this->rightChannelLabel->setText(QString::number(newValue)); });
connect(muteButton, &QPushButton::clicked, [this](bool clicked){ log_debugcpp("cliqui" << clicked << "cloqui"); this->eph->setMute(); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); });
connect(muteButton, &QPushButton::clicked, [this](bool clicked){ log_debugcpp("cliqui" << clicked << "cloqui"); this->eph->setMute(osh->getGuid()); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); });
log_debugcpp("ENDPOINT_WIDGETED");
}