to da
This commit is contained in:
commit
cd2d0b5da8
7 changed files with 307 additions and 0 deletions
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
build
|
||||
*.rdbg
|
||||
*.pdb
|
||||
Makefile
|
||||
Makefile.Debug
|
||||
Makefile.Release
|
||||
2
bueno.bat
Normal file
2
bueno.bat
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
qmake -o build\Makefile .\qtest.pro
|
||||
mingw32-make.exe -C .\build -f Makefile.Release
|
||||
7
qtest.pro
Normal file
7
qtest.pro
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
QT += widgets
|
||||
INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back"
|
||||
DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back"
|
||||
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back"
|
||||
SOURCES += qtestmain.cpp mainwindow.cpp
|
||||
HEADERS += mainwindow.h
|
||||
#DESTDIR += "build"
|
||||
227
src/back/testmain.cpp
Normal file
227
src/back/testmain.cpp
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
#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; }
|
||||
|
||||
|
||||
#define SAFE_RELEASE(punk) \
|
||||
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;
|
||||
|
||||
IAudioEndpointVolume *endpointVolumePtr = NULL;
|
||||
IAudioSessionManager2 *sessionManagerPtr = NULL;
|
||||
|
||||
IAudioSessionEnumerator *sessionEnumeratorPtr = NULL;
|
||||
IAudioSessionControl2 *sessionControl2Ptr = NULL;
|
||||
ISimpleAudioVolume *sessionVolumePtr = NULL;
|
||||
|
||||
void PrintEndpointNames() {
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
IPropertyStore *deviceEndpointPropertiesPtr = NULL;
|
||||
LPWSTR endpointID = NULL;
|
||||
|
||||
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
//MMDeviceEnumerator es el CLSID de toda la vaina de MMDevicear
|
||||
hr = CoCreateInstance(
|
||||
__uuidof(MMDeviceEnumerator), NULL,
|
||||
CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
|
||||
(void**)&deviceEnumeratorPtr);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
//hr = deviceEnumeratorPtr->EnumAudioEndpoints(eRender, DEVICE_STATE_&deviceCollectionPtr);
|
||||
//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)
|
||||
|
||||
//RECUPERAR STRUCT DE PROPIEDADES
|
||||
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.
|
||||
hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
//PINTAR ID + PROPIEDAD RECUPERADA
|
||||
printf("Endpoint %d: \"%S\" (%S)\n", 0, varName.pwszVal, endpointID);
|
||||
|
||||
|
||||
//Activamos desde Device para tener control sobre el Endpoint
|
||||
hr = endpointPtr->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolumePtr);
|
||||
EXIT_ON_ERROR(hr)
|
||||
|
||||
hr = endpointVolumePtr->SetMasterVolumeLevelScalar(0.4f, NULL);
|
||||
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
|
||||
hr = endpointPtr->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**) &sessionManagerPtr);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
|
||||
//Ahora si viene el handle de las sesiones xdddddddddd
|
||||
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
|
||||
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);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
hr = sessionVolumePtr->SetMute(TRUE, 0);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
//Limpiamos memoria
|
||||
CoTaskMemFree(endpointID);
|
||||
endpointID = NULL;
|
||||
PropVariantClear(&varName);
|
||||
SAFE_RELEASE(deviceEndpointPropertiesPtr)
|
||||
SAFE_RELEASE(endpointPtr)
|
||||
SAFE_RELEASE(endpointVolumePtr);
|
||||
SAFE_RELEASE(sessionManagerPtr);
|
||||
SAFE_RELEASE(sessionEnumeratorPtr);
|
||||
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;
|
||||
|
||||
Exit:
|
||||
printf("Error!\n");
|
||||
CoTaskMemFree(endpointID);
|
||||
SAFE_RELEASE(deviceEnumeratorPtr)
|
||||
SAFE_RELEASE(deviceCollectionPtr)
|
||||
SAFE_RELEASE(endpointPtr)
|
||||
SAFE_RELEASE(deviceEndpointPropertiesPtr)
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
void onExit(){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
PrintEndpointNames();
|
||||
}
|
||||
24
src/qt/mainwindow.cpp
Normal file
24
src/qt/mainwindow.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
||||
// setWindowState(Qt::WindowFullScreen);
|
||||
// setCentralWidget(centralWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* void MainWindow::setPlotButton() {
|
||||
* button = new QPushButton("push"),
|
||||
* button->setCheckable(true);
|
||||
* connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)))
|
||||
* QHBoxLayout *plotsLayout = new QHBoxLayout;
|
||||
* plotsLayout->setSpacing(10);
|
||||
* plotsLayout->addWidget(funPlot);
|
||||
* QHBoxLayout *buttonsLayout = new QHBoxLayout ;
|
||||
* buttonsLayout->addWidget(button);
|
||||
* QVBoxLayout *widgetLayout = new QVBoxLayout;
|
||||
* widgetLayout->addLayout(plotsLayout);
|
||||
* widgetLayout->addLayout(buttonsLayout);
|
||||
* setLayout(widgetLayout);
|
||||
* ...
|
||||
*/
|
||||
|
||||
16
src/qt/mainwindow.h
Normal file
16
src/qt/mainwindow.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QApplication>
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
//QWidget *centralWidget;
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
25
src/qtestmain.cpp
Normal file
25
src/qtestmain.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//#include <qapplicationstatic.h>
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
QApplication* createApplication(int &argc, char *argv[])
|
||||
{
|
||||
return new QApplication(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
QApplication::setStyle("windowsvista");
|
||||
QScopedPointer<QApplication> app(createApplication(argc, argv));
|
||||
MainWindow window = MainWindow();
|
||||
window.show();
|
||||
return app->exec();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue