Skip to content

Commit

Permalink
Use default device if requested was not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Aug 18, 2020
1 parent cfd64aa commit 7563a96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions os/windows/AudioInputWASAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,12 @@ void AudioInputWASAPI::ActuallySetCurrentDevice(std::string deviceID){
#ifdef TGVOIP_WINDOWS_DESKTOP
SafeRelease(&device);

IMMDeviceCollection *deviceCollection = NULL;

if(deviceID=="default"){
isDefaultDevice=true;
res=enumerator->GetDefaultAudioEndpoint(eCapture, eCommunications, &device);
CHECK_RES(res, "GetDefaultAudioEndpoint");
}else{
IMMDeviceCollection *deviceCollection = NULL;
isDefaultDevice=false;
res=enumerator->EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE, &deviceCollection);
CHECK_RES(res, "EnumAudioEndpoints");
Expand All @@ -250,10 +249,15 @@ void AudioInputWASAPI::ActuallySetCurrentDevice(std::string deviceID){
break;
}
}
}
if (deviceCollection)
SafeRelease(&deviceCollection);

if(deviceCollection)
SafeRelease(&deviceCollection);
if (!device) {
LOGW("Requested device not found, using default");
ActuallySetCurrentDevice("default");
return;
}
}

if(!device){
LOGE("Didn't find capture device; failing");
Expand Down
14 changes: 9 additions & 5 deletions os/windows/AudioOutputWASAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ void AudioOutputWASAPI::ActuallySetCurrentDevice(std::string deviceID){
SafeRelease(&device);


IMMDeviceCollection *deviceCollection = NULL;

if(deviceID=="default"){
isDefaultDevice=true;
res=enumerator->GetDefaultAudioEndpoint(eRender, eCommunications, &device);
CHECK_RES(res, "GetDefaultAudioEndpoint");
}else{
IMMDeviceCollection *deviceCollection = NULL;

isDefaultDevice=false;
res=enumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &deviceCollection);
CHECK_RES(res, "EnumAudioEndpoints");
Expand All @@ -246,11 +246,15 @@ void AudioOutputWASAPI::ActuallySetCurrentDevice(std::string deviceID){
break;
}
}
if(deviceCollection)
SafeRelease(&deviceCollection);
if (!device) {
LOGW("Requested device not found, using default");
ActuallySetCurrentDevice("default");
return;
}
}

if(deviceCollection)
SafeRelease(&deviceCollection);

if(!device){
LOGE("Didn't find playback device; failing");
failed=true;
Expand Down

0 comments on commit 7563a96

Please sign in to comment.