147 lines
4.2 KiB
C++
147 lines
4.2 KiB
C++
#include <backlasses.h>
|
|
|
|
Endpoint::Endpoint(IMMDevice* ep){
|
|
this->endpoint = ep;
|
|
if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { log_debugcpp("si"); };
|
|
//Obtaining friendly name: IPropertyStore creates PROPVARIANT per field
|
|
// hr = endpointPtr->GetId(&endpointID);
|
|
endpoint->OpenPropertyStore(STGM_READ, &properties);
|
|
PROPVARIANT pv;
|
|
properties->GetValue(PKEY_Device_FriendlyName , &pv);
|
|
friendlyName = pv.pwszVal;
|
|
}
|
|
|
|
LPWSTR Endpoint::getName(){
|
|
return friendlyName;
|
|
}
|
|
|
|
float Endpoint::getVolume(int channel){
|
|
float volume;
|
|
if (channel == ENDPOINT_MASTER_VOLUME) {
|
|
if(FAILED(endpointVolume->GetMasterVolumeLevelScalar(&volume))) { log_debugcpp("si");}
|
|
} else {
|
|
if(FAILED(endpointVolume->GetChannelVolumeLevelScalar(channel, &volume))) { log_debugcpp("si");}
|
|
}
|
|
return volume;
|
|
}
|
|
|
|
|
|
bool Endpoint::getMute(){
|
|
BOOL mut;
|
|
if(FAILED(endpointVolume->GetMute(&mut))) { log_debugcpp("si"); }
|
|
log_debugcpp("back BOOL is " << mut);
|
|
bool mute = (bool)mut;
|
|
log_debugcpp("translate to bool " << mute);
|
|
return mute;
|
|
}
|
|
|
|
/*
|
|
* float Endpoint::getLeftChannelVolume(){
|
|
* float volume;
|
|
* if(FAILED(endpointVolume-> GetChannelVolumeLevelScalar(0, &volume)) { log_debugcpp("si"); } );
|
|
* return volume;
|
|
* }
|
|
*
|
|
* float Endpoint::getRightChannelVolume(){
|
|
* float volume;
|
|
* if(FAILED(endpointVolume-> GetChannelVolumeLevelScalar(1, &volume)) { log_debugcpp("si");}
|
|
* return volume;
|
|
* }
|
|
*/
|
|
|
|
|
|
void Endpoint::setVolume(int channel, float volume) {
|
|
if (channel == ENDPOINT_MASTER_VOLUME) {
|
|
if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, NULL))) { log_debugcpp("si"); };
|
|
} else {
|
|
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, NULL))) { log_debugcpp("si"); };
|
|
}
|
|
}
|
|
|
|
void Endpoint::setMute() {
|
|
log_debugcpp("bool mute arrives as " << mut);
|
|
BOOL mut;
|
|
if(FAILED(endpointVolume->GetMute(&mut))) { log_debugcpp("si"); }
|
|
log_debugcpp("translate to BOOL as " << mute);
|
|
if(FAILED(endpointVolume->SetMute((mut == false ? 1 : 0), NULL))) { log_debugcpp("si"); };
|
|
}
|
|
|
|
|
|
Endpoint::~Endpoint(){
|
|
log_debugcpp("cum");
|
|
free(friendlyName);
|
|
properties->Release();
|
|
endpointVolume->Release();
|
|
endpoint->Release();
|
|
}
|
|
|
|
|
|
void Overseer::initCOMLibrary(){
|
|
if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { log_debugcpp("si"); };
|
|
|
|
|
|
//Retrieving endpoint enumerator
|
|
//MMDeviceEnumerator es el CLSID de toda la vaina de MMDevicear
|
|
if(FAILED(CoCreateInstance( __uuidof(MMDeviceEnumerator), NULL,
|
|
CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
|
|
(void**)&deviceEnumerator)) )
|
|
{ log_debugcpp("si"); };
|
|
|
|
}
|
|
|
|
void Overseer::reloadEndpoints() {
|
|
IMMDeviceCollection *deviceCollection;
|
|
// | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED
|
|
if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &deviceCollection) ))
|
|
{ log_debugcpp("si"); };
|
|
|
|
|
|
//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
|
|
for (unsigned int i = 0; i < numPlaybackEndpoints; i++){
|
|
IMMDevice *temp;
|
|
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
|
|
Endpoint *endpoint = new Endpoint(temp);
|
|
this->playbackDevices.push_back(endpoint);
|
|
//TODO: le porblemx std::cout << "ola" << std::endl;
|
|
}
|
|
|
|
deviceCollection->Release();
|
|
}
|
|
|
|
Overseer::Overseer(){
|
|
//Initializing COM library
|
|
initCOMLibrary();
|
|
|
|
//Obtaining playback endpoint collection on this point in time
|
|
reloadEndpoints();
|
|
}
|
|
|
|
//Overseer::int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint){
|
|
//if (FAILED(deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &endpointPtr)))
|
|
// return 1;
|
|
//return 0;
|
|
//}
|
|
|
|
//int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
|
|
|
|
std::vector<Endpoint*> Overseer::getPlaybackEndpoints() {
|
|
return playbackDevices;
|
|
}
|
|
|
|
Overseer::~Overseer(){
|
|
log_debugcpp("cum");
|
|
deviceEnumerator->Release();
|
|
for(unsigned long long i = 0; i < playbackDevices.size(); i++){
|
|
delete(playbackDevices.at(i));
|
|
}
|
|
}
|
|
|
|
//int Overseer::getCaptureEndpoints(std::vector<Endpoint*> *captureEndpoints);
|
|
|
|
//IMMDeviceEnumerator** Overseer::setOrigin();
|
|
|