wip: default callback
This commit is contained in:
parent
512a42f954
commit
7f05cc09f6
7 changed files with 230 additions and 15 deletions
|
|
@ -66,6 +66,124 @@ HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* EndpointSituationCallback::EndpointSituationCallback(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices){
|
||||
* this->deviceEnumerator = deviceEnumerator;
|
||||
* this->playbackDevices = playbackDevices;
|
||||
* }
|
||||
*/
|
||||
|
||||
void EndpointSituationCallback::fill(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices){
|
||||
this->deviceEnumerator = deviceEnumerator;
|
||||
this->playbackDevices = playbackDevices;
|
||||
}
|
||||
|
||||
|
||||
ULONG EndpointSituationCallback::AddRef(){
|
||||
return InterlockedIncrement(&ref);
|
||||
}
|
||||
|
||||
ULONG EndpointSituationCallback::Release(){
|
||||
ULONG tempRef = InterlockedDecrement(&ref);
|
||||
if (tempRef == 0) {
|
||||
delete this;
|
||||
}
|
||||
return tempRef;
|
||||
}
|
||||
|
||||
HRESULT EndpointSituationCallback::QueryInterface(REFIID riid, VOID **ppvInterface) {
|
||||
if (IID_IUnknown == riid)
|
||||
{
|
||||
AddRef();
|
||||
*ppvInterface = (IUnknown*)this;
|
||||
}
|
||||
else if (__uuidof(IMMNotificationClient) == riid)
|
||||
{
|
||||
AddRef();
|
||||
*ppvInterface = (IMMNotificationClient*)this;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ppvInterface = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT EndpointSituationCallback::OnDefaultDeviceChanged(EDataFlow flow, ERole role,LPCWSTR pwstrDeviceId) {
|
||||
if (flow == EDataFlow::eCapture) return E_INVALIDARG;
|
||||
|
||||
Roles nRole;
|
||||
switch (role) {
|
||||
case ERole::eConsole:
|
||||
nRole = Roles::ROLE_CONSOLE;
|
||||
break;
|
||||
case ERole::eMultimedia:
|
||||
nRole = Roles::ROLE_MULTIMEDIA;
|
||||
break;
|
||||
case ERole::eCommunications:
|
||||
nRole = Roles::ROLE_COMMUNICATIONS;
|
||||
break;
|
||||
}
|
||||
|
||||
osh
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT EndpointSituationCallback::OnDeviceAdded(LPCWSTR pwstrDeviceId) {
|
||||
|
||||
printf(" -->Added device\n");
|
||||
return S_OK;
|
||||
};
|
||||
|
||||
HRESULT EndpointSituationCallback::OnDeviceRemoved(LPCWSTR pwstrDeviceId) {
|
||||
|
||||
printf(" -->Removed device\n");
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState) {
|
||||
/*
|
||||
* char *pszState = "?????";
|
||||
*
|
||||
* switch (dwNewState)
|
||||
* {
|
||||
* case DEVICE_STATE_ACTIVE:
|
||||
* pszState = "ACTIVE";
|
||||
* break;
|
||||
* case DEVICE_STATE_DISABLED:
|
||||
* pszState = "DISABLED";
|
||||
* break;
|
||||
* case DEVICE_STATE_NOTPRESENT:
|
||||
* pszState = "NOTPRESENT";
|
||||
* break;
|
||||
* case DEVICE_STATE_UNPLUGGED:
|
||||
* pszState = "UNPLUGGED";
|
||||
* break;
|
||||
* }
|
||||
*
|
||||
* printf(" -->New device state is DEVICE_STATE_%s (0x%8.8x)\n",
|
||||
* pszState, dwNewState);
|
||||
*/
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT EndpointSituationCallback::OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) {
|
||||
/*
|
||||
* printf(" -->Changed device property "
|
||||
* "{%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x}#%d\n",
|
||||
* key.fmtid.Data1, key.fmtid.Data2, key.fmtid.Data3,
|
||||
* key.fmtid.Data4[0], key.fmtid.Data4[1],
|
||||
* key.fmtid.Data4[2], key.fmtid.Data4[3],
|
||||
* key.fmtid.Data4[4], key.fmtid.Data4[5],
|
||||
* key.fmtid.Data4[6], key.fmtid.Data4[7],
|
||||
* key.pid);
|
||||
*/
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
|
||||
this->endpoint = ep;
|
||||
this->idx = idx;
|
||||
|
|
@ -168,7 +286,51 @@ uint8_t Endpoint::getRoles(){
|
|||
return this->endpointRoles;
|
||||
}
|
||||
|
||||
void Endpoint::setRoles(uint8_t role){
|
||||
void Endpoint::setRoles(Roles role){
|
||||
//otro exe momento
|
||||
STARTUPINFOEXW startupConfig;
|
||||
PROCESS_INFORMATION processInfo;
|
||||
SecureZeroMemory(&startupConfig, sizeof(STARTUPINFOEXW));
|
||||
SecureZeroMemory(&startupConfig.StartupInfo, sizeof(STARTUPINFOW));
|
||||
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" ";
|
||||
switch (role) {
|
||||
case Roles::ROLE_ALL:
|
||||
command += L"all";
|
||||
break;
|
||||
case Roles::ROLE_CONSOLE:
|
||||
command += std::to_wstring(0);
|
||||
break;
|
||||
case Roles::ROLE_MULTIMEDIA:
|
||||
command += std::to_wstring(1);
|
||||
break;
|
||||
case Roles::ROLE_COMMUNICATIONS:
|
||||
command += std::to_wstring(2);
|
||||
break;
|
||||
}
|
||||
|
||||
if(CreateProcessW(
|
||||
NULL,
|
||||
(wchar_t*)command.c_str(),
|
||||
NULL,
|
||||
NULL,
|
||||
false,
|
||||
CREATE_UNICODE_ENVIRONMENT,
|
||||
NULL,
|
||||
NULL,
|
||||
(LPSTARTUPINFOW)&startupConfig,
|
||||
&processInfo
|
||||
) == true) {
|
||||
WaitForSingleObject(processInfo.hProcess, INFINITE );
|
||||
CloseHandle(processInfo.hProcess);
|
||||
CloseHandle(processInfo.hThread);
|
||||
}
|
||||
}
|
||||
|
||||
void Endpoint::assignRoles(uint8_t role){
|
||||
//todo: operador virtuoso
|
||||
uint8_t roles = endpointRoles | role;
|
||||
this->endpointRoles = roles;
|
||||
|
|
@ -252,30 +414,24 @@ void Overseer::reloadEndpoints() {
|
|||
int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, eptId.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));
|
||||
playbackDevices.at(j)->assignRoles((1 << i));
|
||||
}
|
||||
//uint8_t debg = playbackDevices.at(j)->getRoles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Overseer::Overseer(){
|
||||
Overseer::Overseer() { //: epsc(deviceEnumerator, playbackDevices){
|
||||
//Initializing COM library
|
||||
log_debugcpp("Initializing Overseer");
|
||||
initCOMLibrary();
|
||||
|
||||
//Obtaining playback endpoint collection on this point in time
|
||||
reloadEndpoints();
|
||||
this->epsc.fill(deviceEnumerator, playbackDevices);
|
||||
if(FAILED(deviceEnumerator->RegisterEndpointNotificationCallback(((IMMNotificationClient*)&epsc)))) { log_debugcpp("when no enchufas......"); }
|
||||
}
|
||||
|
||||
//Overseer::int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint){
|
||||
//if (FAILED(deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &endpointPtr)))
|
||||
// return 1;
|
||||
//return 0;
|
||||
//}
|
||||
|
||||
//int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
|
||||
|
||||
NGuid Overseer::getGuid() {
|
||||
return guid;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue