fixed IAudioSessionControl2 invocation, modified README
This commit is contained in:
parent
f931d2bfa4
commit
9806f046bd
4 changed files with 182 additions and 177 deletions
114
testmain.cpp
114
testmain.cpp
|
|
@ -1,29 +1,17 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Windows.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <combaseapi.h>
|
||||
#include <initguid.h>
|
||||
#include <functiondiscoverykeys_devpkey.h>
|
||||
|
||||
#include <endpointvolume.h>
|
||||
#include <audiopolicy.h>
|
||||
#include <audioclient.h>
|
||||
//#include <comdef.h>
|
||||
//#include <comip.h>
|
||||
#include <Winerror.h>
|
||||
|
||||
|
||||
//#define EXIT_ON_ERROR(hres, className) \
|
||||
if (FAILED(hres)) { printf("%s\n", #className); goto Exit; }
|
||||
|
||||
|
||||
#define EXIT_ON_ERROR(hres) \
|
||||
if (FAILED(hres)) { printf("%s - %d\n", __FILE__, __LINE__); goto Exit; }
|
||||
|
||||
|
|
@ -32,15 +20,6 @@
|
|||
if ((punk) != NULL) \
|
||||
{ (punk)->Release(); (punk) = NULL; }
|
||||
|
||||
//#pragma once
|
||||
|
||||
/*
|
||||
* Comentarios patrocinados por David
|
||||
* Enviar mensaje a @Phireh
|
||||
*/
|
||||
|
||||
// const IID IntID_IAudioEndpointVolume = __uuidof(IAudioEndpointVolume);
|
||||
|
||||
IMMDeviceEnumerator *deviceEnumeratorPtr = NULL;
|
||||
IMMDeviceCollection *deviceCollectionPtr = NULL;
|
||||
IMMDevice *endpointPtr = NULL;
|
||||
|
|
@ -49,6 +28,7 @@ IAudioEndpointVolume *endpointVolumePtr = NULL;
|
|||
IAudioSessionManager2 *sessionManagerPtr = NULL;
|
||||
|
||||
IAudioSessionEnumerator *sessionEnumeratorPtr = NULL;
|
||||
IAudioSessionControl* sessionControlPtr = NULL;
|
||||
IAudioSessionControl2 *sessionControl2Ptr = NULL;
|
||||
ISimpleAudioVolume *sessionVolumePtr = NULL;
|
||||
|
||||
|
|
@ -68,22 +48,11 @@ void PrintEndpointNames() {
|
|||
(void**)&deviceEnumeratorPtr);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
//hr = deviceEnumeratorPtr->EnumAudioEndpoints(eRender, DEVICE_STATE_&deviceCollectionPtr);
|
||||
//hr = deviceEnumeratorPtr->EnumAudioEndpoints(eRender, DEVICE_STATE_&deviceCollectionPtr); << Elegimos a mano para ahorrar código de iteración
|
||||
//Llamar a dispositivo por defecto. 2o param no importa lmao
|
||||
hr = deviceEnumeratorPtr->GetDefaultAudioEndpoint(eRender, eConsole, &endpointPtr);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
// UINT count;
|
||||
// hr = deviceCollectionPtr->GetCount(&count);
|
||||
// EXIT_ON_ERROR(hr)
|
||||
|
||||
// if (count == 0) {
|
||||
// printf("No endpoints found.\n");
|
||||
// }
|
||||
|
||||
// hr = deviceCollectionPtr->Item(i, &endpointPtr);
|
||||
// EXIT_ON_ERROR(hr)
|
||||
|
||||
//RECUPERAR ENDPOINT ID
|
||||
hr = endpointPtr->GetId(&endpointID);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
|
@ -94,10 +63,10 @@ void PrintEndpointNames() {
|
|||
|
||||
|
||||
PROPVARIANT varName;
|
||||
// Initialize container for property value.
|
||||
// Inicializar el struct para poder extraer la información.
|
||||
PropVariantInit(&varName);
|
||||
|
||||
// Get the endpoint's friendly-name property.
|
||||
// Cogemos el nombre humano
|
||||
hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
|
|
@ -113,36 +82,34 @@ void PrintEndpointNames() {
|
|||
EXIT_ON_ERROR(hr);
|
||||
|
||||
//Registramos el gestor de sesiones para conseguir el handle que da el handle de sesiones a nivel informativo
|
||||
//Y justo despues, el que da control a nivel sonoro xdddddddddddddddddddddddddddddddddddddddddddddd
|
||||
//Y justo despues, el que da control a nivel sonoro
|
||||
hr = endpointPtr->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**) &sessionManagerPtr);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
|
||||
//Ahora si viene el handle de las sesiones xdddddddddd
|
||||
//Ahora si viene el handle de las sesiones
|
||||
hr = sessionManagerPtr->GetSessionEnumerator(&sessionEnumeratorPtr);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
//Cogemos el numero de sesiones y recorremos para coger cada una
|
||||
//Luego tho, que soy una puta vaga y hay que probar cositas
|
||||
//Cogemos el numero de sesiones y recorreríamos para coger cada una. Aquí, se elige la 0 para, una vez más, no enmarañar el código.
|
||||
INT sessionCount;
|
||||
hr = sessionEnumeratorPtr->GetCount(&sessionCount);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
hr = sessionEnumeratorPtr->GetSession(2, (IAudioSessionControl**)&sessionControl2Ptr);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
LPWSTR sessionDisplayName;
|
||||
hr = sessionControl2Ptr->GetDisplayName(&sessionDisplayName);
|
||||
hr = sessionEnumeratorPtr->GetSession(0, (IAudioSessionControl**)&sessionControlPtr);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
hr = sessionControlPtr->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl2Ptr);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
//Puede que el nombre no se rellene. Esto se debe a que no todos los programas registran su sesión con un nombre humano. SndVol.exe se toma la libertad de pesquisar el nombre a través de los metadatos del ejecutable que la ha creado si es una aplicación Win32, y otro campo si es una aplicación .appx.
|
||||
LPWSTR sessionDisplayName;
|
||||
hr = sessionControl2Ptr->IsSystemSoundsSession();
|
||||
if(hr)
|
||||
hr = sessionControl2Ptr->GetDisplayName(&sessionDisplayName);
|
||||
else
|
||||
sessionDisplayName = L"System Sounds";
|
||||
|
||||
printf("Sesion 0 de endpoint %S: \"%S\" \n Num sesiones: (%d)\n", varName.pwszVal, sessionDisplayName, sessionCount);
|
||||
|
||||
//hr = sessionControlPtr->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl2Ptr);
|
||||
//EXIT_ON_ERROR(hr);
|
||||
|
||||
//hr = sessionControl2Ptr->GetProcessId(&foundProcessId);
|
||||
//EXIT_ON_ERROR(hr);
|
||||
|
||||
hr = sessionControl2Ptr->QueryInterface(__uuidof(ISimpleAudioVolume), (void**)&sessionVolumePtr);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
|
@ -162,42 +129,7 @@ void PrintEndpointNames() {
|
|||
//SAFE_RELEASE(sessionControlPtr);
|
||||
SAFE_RELEASE(sessionControl2Ptr);
|
||||
SAFE_RELEASE(sessionVolumePtr);
|
||||
/*
|
||||
// Each loop prints the name of an endpoint device.
|
||||
for (ULONG i = 0; i < count; i++) {
|
||||
// Get pointer to endpoint number i.
|
||||
hr = deviceCollectionPtr->Item(i, &endpointPtr);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
// Get the endpoint ID string.
|
||||
hr = endpointPtr->GetId(&endpointID);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
hr = endpointPtr->OpenPropertyStore(STGM_READ, &deviceEndpointPropertiesPtr);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
PROPVARIANT varName;
|
||||
// Initialize container for property value.
|
||||
PropVariantInit(&varName);
|
||||
|
||||
// Get the endpoint's friendly-name property.2
|
||||
hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
// Print endpoint friendly name and endpoint ID.
|
||||
printf("Endpoint %lu: \"%S\" (%S)\n", i, varName.pwszVal, endpointID);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CoTaskMemFree(endpointID);
|
||||
endpointID = NULL;
|
||||
PropVariantClear(&varName);
|
||||
SAFE_RELEASE(deviceEndpointPropertiesPtr)
|
||||
SAFE_RELEASE(endpointPtr)
|
||||
}
|
||||
*/
|
||||
SAFE_RELEASE(deviceEnumeratorPtr)
|
||||
SAFE_RELEASE(deviceCollectionPtr)
|
||||
return;
|
||||
|
|
@ -212,16 +144,6 @@ Exit:
|
|||
CoUninitialize();
|
||||
}
|
||||
|
||||
void onExit(){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
PrintEndpointNames();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue