endpoint add/remove foundational work
This commit is contained in:
parent
fc63875851
commit
a6a052f348
6 changed files with 103 additions and 96 deletions
|
|
@ -183,16 +183,15 @@ HRESULT EndpointSituationCallback::OnPropertyValueChanged(LPCWSTR pwstrDeviceId,
|
|||
Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
|
||||
this->endpoint = ep;
|
||||
this->idx = idx;
|
||||
//if(FAILED()) {};
|
||||
DWORD tempState = 0;
|
||||
if(FAILED(endpoint->GetState(&tempState))) {exit(-1);};
|
||||
this->endpointState = tempState;
|
||||
|
||||
if (tempState == DEVICE_STATE_ACTIVE) {
|
||||
|
||||
//todo: preguntitas owindows dword no es uint32_t even tho mingw mingas
|
||||
if(FAILED(endpoint->GetState(&this->endpointState))) {exit(-1);};
|
||||
|
||||
if (this->endpointState == 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;
|
||||
|
|
@ -250,7 +249,7 @@ void Endpoint::setState(uint8_t state){
|
|||
this->endpointState = state;
|
||||
}
|
||||
|
||||
uint8_t Endpoint::getState(){
|
||||
size_t Endpoint::getState(){
|
||||
return this->endpointState;
|
||||
}
|
||||
|
||||
|
|
@ -291,17 +290,34 @@ void Endpoint::setRoles(Roles role){
|
|||
startupConfig.StartupInfo.cb = sizeof(STARTUPINFOEXW);
|
||||
SecureZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));
|
||||
|
||||
//const wchar_t* pCrutch = crutch.c_str();
|
||||
std::wstring command = L"SoundVolumeView.exe /SetDefault " + endpointId + L" ";
|
||||
std::wstring troublePair = L"0";
|
||||
switch (role) {
|
||||
case Roles::ROLE_ALL:
|
||||
/*
|
||||
* one sends both, at least for now;
|
||||
* either cos of ms or dis guy, no choice
|
||||
* but to treat them as one for now
|
||||
* command += L"all";
|
||||
* console or multimedia, one sends both, at least for now;
|
||||
* either cos of ms or dis guy;
|
||||
* no choice but to treat them as one for now.
|
||||
* command += L"all"; and nothing else would've been nice...
|
||||
*/
|
||||
command += L"0 1";
|
||||
troublePair = command + troublePair;
|
||||
if(CreateProcessW(
|
||||
NULL,
|
||||
(wchar_t*)troublePair.c_str(),
|
||||
NULL,
|
||||
NULL,
|
||||
false,
|
||||
CREATE_UNICODE_ENVIRONMENT,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPSTARTUPINFOW)&startupConfig,
|
||||
&processInfo
|
||||
) == true) {
|
||||
WaitForSingleObject(processInfo.hProcess, INFINITE );
|
||||
CloseHandle(processInfo.hProcess);
|
||||
CloseHandle(processInfo.hThread);
|
||||
}
|
||||
command += L"2";
|
||||
break;
|
||||
case Roles::ROLE_CONSOLE:
|
||||
command += std::to_wstring(0);
|
||||
|
|
@ -375,16 +391,18 @@ 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"); };
|
||||
|
||||
|
||||
//Counting them
|
||||
/*
|
||||
* Counting them
|
||||
*/
|
||||
if(FAILED(deviceCollection->GetCount(&numPlaybackEndpoints))) { log_debugcpp("si");};
|
||||
if(numPlaybackEndpoints == 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;
|
||||
for (unsigned int i = 0; i < numPlaybackEndpoints; i++){
|
||||
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
|
||||
|
|
@ -396,8 +414,10 @@ void Overseer::reloadEndpoints() {
|
|||
|
||||
deviceCollection->Release();
|
||||
|
||||
//Discerning default endpoints per role
|
||||
//order: console, multimedia, communications
|
||||
/*
|
||||
* Discerning default endpoints per role
|
||||
* order: console, multimedia, communications
|
||||
*/
|
||||
for(int i = 0; i < ERole_enum_count; i++){
|
||||
ERole val;
|
||||
switch(i) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue