diff --git a/ScreenRecorderLibNative/CoreAudio.util.cpp b/ScreenRecorderLibNative/CoreAudio.util.cpp index 764982d..46db442 100644 --- a/ScreenRecorderLibNative/CoreAudio.util.cpp +++ b/ScreenRecorderLibNative/CoreAudio.util.cpp @@ -226,6 +226,9 @@ HRESULT GetAudioDeviceFriendlyName(_In_ IMMDevice *pDevice, _Out_ std::wstring * // Get the endpoint device's friendly-name property. RETURN_ON_BAD_HR(hr = pProps->GetValue(PKEY_Device_FriendlyName, &varString)); + if (varString.pwszVal == NULL) { + return E_FAIL; + } *deviceName = std::wstring(varString.pwszVal); return hr; } diff --git a/ScreenRecorderLibNative/WASAPICapture.cpp b/ScreenRecorderLibNative/WASAPICapture.cpp index d7fb21a..e6c0961 100644 --- a/ScreenRecorderLibNative/WASAPICapture.cpp +++ b/ScreenRecorderLibNative/WASAPICapture.cpp @@ -70,7 +70,7 @@ HRESULT WASAPICapture::Initialize(_In_ std::wstring deviceId, _In_ EDataFlow flo else { RETURN_ON_BAD_HR(GetActiveAudioDevice(deviceId.c_str(), flow, &pDevice)); } - + HRESULT hr = E_FAIL; if (pDevice) { LPWSTR deviceId; pDevice->GetId(&deviceId); @@ -78,7 +78,10 @@ HRESULT WASAPICapture::Initialize(_In_ std::wstring deviceId, _In_ EDataFlow flo if (m_IsDefaultDevice) { m_DefaultDeviceId = m_DeviceId; } - GetAudioDeviceFriendlyName(deviceId, &m_DeviceName); + hr = GetAudioDeviceFriendlyName(deviceId, &m_DeviceName); + if (FAILED(hr)) { + m_DeviceName = L"Unknown Device"; + } CoTaskMemFree(deviceId); } else { @@ -86,7 +89,7 @@ HRESULT WASAPICapture::Initialize(_In_ std::wstring deviceId, _In_ EDataFlow flo return E_FAIL; } - HRESULT hr = InitializeAudioClient(pDevice, &m_AudioClient); + hr = InitializeAudioClient(pDevice, &m_AudioClient); if (SUCCEEDED(hr)) { WWMFResampler *pResampler; hr = InitializeResampler(m_AudioOptions->GetAudioSamplesPerSecond(), m_AudioOptions->GetAudioChannels(), m_AudioClient, &m_InputFormat, &m_OutputFormat, &pResampler); diff --git a/ScreenRecorderLibNative/WASAPINotify.cpp b/ScreenRecorderLibNative/WASAPINotify.cpp index 783b20e..1e3b80d 100644 --- a/ScreenRecorderLibNative/WASAPINotify.cpp +++ b/ScreenRecorderLibNative/WASAPINotify.cpp @@ -69,7 +69,10 @@ HRESULT STDMETHODCALLTYPE WASAPINotify::OnDefaultDeviceChanged(EDataFlow flow, E if (flow == m_CaptureClient->GetFlow()) { m_CaptureClient->SetDefaultDevice(flow, role, pwstrDeviceId); std::wstring deviceName; - GetAudioDeviceFriendlyName(pwstrDeviceId, &deviceName); + HRESULT hr = GetAudioDeviceFriendlyName(pwstrDeviceId, &deviceName); + if (FAILED(hr)) { + deviceName = L"Unknown Device"; + } LOG_DEBUG("New default device: name=%s, flow = %s, role = %s\n", deviceName.c_str(), pszFlow, pszRole);