temp commit

This commit is contained in:
Hane 2024-02-03 17:05:09 +01:00
commit a0ce3fa703
7 changed files with 99 additions and 11 deletions

View file

@ -37,6 +37,22 @@ HRESULT EndpointNewSessionCallback::QueryInterface(REFIID riid, VOID **ppvInterf
}
HRESULT EndpointNewSessionCallback::OnSessionCreated(IAudioSessionControl *NewSession) {
if (eph->getFlow() == Flows::FLOW_CAPTURE) return S_OK;
HRESULT result = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
IAudioSessionControl2* sessionControl;
//ISimmpleAudioVolume* sessionVolume;
if (FAILED(NewSession->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl))) { log_wdebugcpp(L"no nueva sesion......"); };
if (sessionControl) {
sessionControl->AddRef();
//sessionControl->QueryInterface(__uuidof(ISimpleAudioVolume), (void**)&sessionVolume);
Session* newSession = new Session(this->eph->getEndpoint(), sessionControl);
eph->addSession(newSession);
}
if (result == S_OK)
CoUninitialize();
return S_OK;
}
@ -299,6 +315,11 @@ void Endpoint::activateEndpointSessions() {
sessionEnumerator->Release();
}
void Endpoint::addSession(Session* session) {
session->setIndex(this->getSessionCount());
endpointSessions.push_back(session);
}
void Endpoint::activateEndpointVolume() {
//bool extraThread = false;
/*

View file

@ -39,6 +39,7 @@ class Endpoint {
/* sessions */
std::vector<Session*> getSessions();
size_t getSessionCount();
void addSession(Session* session);
~Endpoint();
@ -135,7 +136,6 @@ class Overseer {
class EndpointNewSessionCallback : public IAudioSessionNotification {
public:
//EndpointSituationCallback(IMMDeviceEnumerator *deviceEnumerator, std::vector<Endpoint*> playbackDevices);
EndpointNewSessionCallback(EndpointHandler *eph);
ULONG AddRef();
ULONG Release();

View file

@ -71,6 +71,11 @@ HRESULT SessionStateCallback::OnGroupingParamChanged(LPCGUID NewGroupingParam, L
}
HRESULT SessionStateCallback::OnStateChanged(AudioSessionState NewState) {
/* enum _AudioSessionState {
* AudioSessionStateInactive,
* AudioSessionStateActive,
* AudioSessionStateExpired
* } AudioSessionState; */
/*
* char *pszState = "?????";
*
@ -85,7 +90,6 @@ HRESULT SessionStateCallback::OnStateChanged(AudioSessionState NewState) {
* }
* printf("New session state = %s\n", pszState);
*/
return S_OK;
}
@ -126,6 +130,20 @@ Session::Session(Endpoint* ep, IAudioSessionControl2* sessionControl, size_t idx
this->sessionControl = sessionControl;
this->idx = idx;
AudioSessionState msState;
sessionControl->GetState(&msState);
switch (msState) {
case AudioSessionState::AudioSessionStateActive:
this->sessionState = SessionState::ACTIVE;
break;
case AudioSessionState::AudioSessionStateInactive:
this->sessionState = SessionState::INACTIVE;
break;
case AudioSessionState::AudioSessionStateExpired:
this->sessionState = SessionState::EXPIRED;
break;
}
sessionControl->QueryInterface(__uuidof(ISimpleAudioVolume), (void**)&sessionVolume);
DWORD pid;
sessionControl->GetProcessId(&pid);
@ -180,6 +198,10 @@ void Session::setVolume(NGuid guid, int channel, float volume) {
}
}
void Session::setIndex(size_t idx) {
this->idx = idx;
}
void Session::setMute(NGuid guid, bool muted) {
GUID tempMsGuid = NGuidToGUID(guid);
if(FAILED(sessionVolume->SetMute(muted, &tempMsGuid))) { log_wdebugcpp(std::wstring(L"SessionVolume null?")); };
@ -268,6 +290,15 @@ wchar_t* fileDescription = NULL;
return exePath;
}
//todo: conflicting names. change callback name
void Session::setState(SessionState state) {
sessionState = state;
}
SessionState Session::getState() {
return sessionState;
}
void Session::setStateCallback(SessionStateCallback *ssc){
sessionControl->RegisterAudioSessionNotification((IAudioSessionEvents*) ssc);
}
@ -275,3 +306,8 @@ void Session::setStateCallback(SessionStateCallback *ssc){
void Session::removeStateCallback(SessionStateCallback *ssc){
sessionControl->UnregisterAudioSessionNotification((IAudioSessionEvents*) ssc);
}
Session::~Session() {
sessionControl->Release();
sessionVolume->Release();
}

View file

@ -30,19 +30,25 @@ class Session {
public:
Session(Endpoint* ep, IAudioSessionControl2* sessionControl, size_t idx);
Session(Endpoint* ep, IAudioSessionControl2* sessionControl) : Session(ep, sessionControl, SIZE_MAX) {};
void setVolume(NGuid guid, int channel, float volume);
float getVolume(int channel);
void setMute(NGuid guid, bool muted);
bool getMute();
SessionState getState();
void setState(SessionState state);
void setIndex(size_t idx);
std::wstring getName();
void setStateCallback(SessionStateCallback *ssc);
void removeStateCallback(SessionStateCallback *ssc);
~Session();
//uint32_t getChannelCount();
private:
std::wstring fetchProcessName(DWORD pid);
std::wstring sessionName;
SessionState sessionState;
Endpoint* ep;
IAudioSessionControl2* sessionControl = nullptr;
ISimpleAudioVolume* sessionVolume = nullptr;

View file

@ -161,6 +161,19 @@ std::vector<SessionHandler*> EndpointHandler::getSessionHandlers(){
return this->sessionHandlers;
}
Endpoint* EndpointHandler::getEndpoint() {
return this->ep;
}
void EndpointHandler::addSession(Session* session) {
ep->addSession(session);
if (this->getState() == EndpointState::ENDPOINT_ACTIVE) {
SessionHandler* sessionHandler = new SessionHandler(this, session, (getSessionCount() - 1));
sessionHandlers.push_back(sessionHandler);
}
}
EndpointHandler::~EndpointHandler() {
ep->removeVolumeCallback(epc);
epc->Release();

View file

@ -61,6 +61,11 @@ public:
/* sessions */
size_t getSessionCount();
std::vector<SessionHandler*> getSessionHandlers();
void createNewSession();
Endpoint* getEndpoint();
/*Session*/
void addSession(Session* session);
~EndpointHandler();
private:

View file

@ -31,24 +31,31 @@ enum AudioChannel {
};
enum EndpointState {
ENDPOINT_ACTIVE = (1 << 0),
ENDPOINT_DISABLED = (1 << 1),
ENDPOINT_ACTIVE = (1 << 0),
ENDPOINT_DISABLED = (1 << 1),
ENDPOINT_NOTPRESENT = (1 << 2),
ENDPOINT_UNPLUGGED = (1 << 3),
ENDPOINT_ALL = 0x0F
ENDPOINT_UNPLUGGED = (1 << 3),
ENDPOINT_ALL = 0x0F
};
enum SessionState {
ACTIVE = (1 << 0),
INACTIVE = (1 << 1),
EXPIRED = (1 << 2),
ALL = 0x07
};
enum Flows {
FLOW_PLAYBACK = (1 << 0),
FLOW_CAPTURE = (1 << 1),
FLOW_BOTH = (1 << 2),
FLOW_CAPTURE = (1 << 1),
FLOW_BOTH = (1 << 2),
};
enum Roles {
ROLE_CONSOLE = (1 << 0),
ROLE_MULTIMEDIA = (1 << 1),
ROLE_CONSOLE = (1 << 0),
ROLE_MULTIMEDIA = (1 << 1),
ROLE_COMMUNICATIONS = (1 << 2),
ROLE_ALL = 0x07,
ROLE_ALL = 0x07,
};
struct NGuid {