Repository: xbmc/xbmc
File: xbmc/cores/AudioEngine/Sinks/windows/AESinkFactoryWin32.cpp (C++)

Code before:

    hr = pProperty->GetValue(PKEY_AudioEndpoint_GUID, &varName);
    EXIT_ON_FAILURE(hr, "Retrieval of endpoint GUID failed.")

    details.strDeviceId = KODI::PLATFORM::WINDOWS::FromW(varName.pwszVal);
    PropVariantClear(&varName);

    hr = pProperty->GetValue(PKEY_AudioEndpoint_FormFactor, &varName);
    EXIT_ON_FAILURE(hr, "Retrieval of endpoint form factor failed.")

    details.strWinDevType = winEndpoints[(EndpointFormFactor)varName.uiVal].winEndpointType;
    details.eDeviceType = winEndpoints[(EndpointFormFactor)varName.uiVal].aeDeviceType;
    PropVariantClear(&varName);

    /* In shared mode Windows tells us what format the audio must be in. */
    hr = pProperty->GetValue(PKEY_AudioEngine_DeviceFormat, &varName);
    if (SUCCEEDED(hr) && varName.blob.cbSize >= sizeof(WAVEFORMATEX))
    {
      // This may be a WAVEFORMATEXTENSIBLE but the extra data is not needed.
      WAVEFORMATEX* pwfx = reinterpret_cast<WAVEFORMATEX*>(varName.blob.pBlobData);
      details.nChannels = pwfx->nChannels;
      details.m_samplesPerSec = pwfx->nSamplesPerSec;
    }
    else
    {
      CLog::LogF(LOGERROR, "Getting DeviceFormat failed ({})", CWIN32Util::FormatHRESULT(hr));
    }
    PropVariantClear(&varName);

    hr = pProperty->GetValue(PKEY_AudioEndpoint_PhysicalSpeakers, &varName);
    EXIT_ON_FAILURE(hr, "Retrieval of endpoint speaker layout failed.")

    details.uiChannelMask = std::max(varName.uintVal, (unsigned int)KSAUDIO_SPEAKER_STEREO);
    PropVariantClear(&varName);

    hr = pProperty->GetValue(PKEY_Device_EnumeratorName, &varName);
    if (SUCCEEDED(hr) && varName.vt != VT_EMPTY)
    {
      details.strDeviceEnumerator = KODI::PLATFORM::WINDOWS::FromW(varName.pwszVal);
      StringUtils::ToUpper(details.strDeviceEnumerator);
    }
    else
    {
      CLog::LogF(LOGDEBUG, "Retrieval of endpoint enumerator name failed: {}.",
                 (FAILED(hr)) ? "'GetValue' has failed" : "'varName.pwszVal' is NULL");
    }
    PropVariantClear(&varName);

    if (S_OK == (hr = pDevice->GetId(&pwszID)))
    {
      if (wstrDDID.compare(pwszID) == 0)

Review comment (bug):
Maybe not treat as error and provide fallback:

change LOGERROR to LOGDEBUG and use as fallback

```
details.nChannels = 2;
details.m_samplesPerSec = 48000;
```
Anyway is no EXIT_ON_FAILURE here.

Then in `EnumerateDevicesEx` remove if conditions `if (detail.nChannels)`, etc.



Code after:

    hr = pProperty->GetValue(PKEY_AudioEndpoint_GUID, &varName);
    EXIT_ON_FAILURE(hr, "Retrieval of endpoint GUID failed.")

    details.strDeviceId = KODI::PLATFORM::WINDOWS::FromW(varName.pwszVal);
    PropVariantClear(&varName);

    hr = pProperty->GetValue(PKEY_AudioEndpoint_FormFactor, &varName);
    EXIT_ON_FAILURE(hr, "Retrieval of endpoint form factor failed.")

    details.strWinDevType = winEndpoints[(EndpointFormFactor)varName.uiVal].winEndpointType;
    details.eDeviceType = winEndpoints[(EndpointFormFactor)varName.uiVal].aeDeviceType;
    PropVariantClear(&varName);

    /* In shared mode Windows tells us what format the audio must be in. */
    hr = pProperty->GetValue(PKEY_AudioEngine_DeviceFormat, &varName);
    if (SUCCEEDED(hr) && varName.blob.cbSize >= sizeof(WAVEFORMATEX))
    {
      // This may be a WAVEFORMATEXTENSIBLE but the extra data is not needed.
      WAVEFORMATEX* pwfx = reinterpret_cast<WAVEFORMATEX*>(varName.blob.pBlobData);
      details.nChannels = pwfx->nChannels;
      details.m_samplesPerSec = pwfx->nSamplesPerSec;
    }
    else
    {
      CLog::LogF(LOGDEBUG, "Getting DeviceFormat failed ({})", CWIN32Util::FormatHRESULT(hr));
    }
    PropVariantClear(&varName);

    hr = pProperty->GetValue(PKEY_AudioEndpoint_PhysicalSpeakers, &varName);
    EXIT_ON_FAILURE(hr, "Retrieval of endpoint speaker layout failed.")

    details.uiChannelMask = std::max(varName.uintVal, (unsigned int)KSAUDIO_SPEAKER_STEREO);
    PropVariantClear(&varName);

    hr = pProperty->GetValue(PKEY_Device_EnumeratorName, &varName);
    if (SUCCEEDED(hr) && varName.vt != VT_EMPTY)
    {
      details.strDeviceEnumerator = KODI::PLATFORM::WINDOWS::FromW(varName.pwszVal);
      StringUtils::ToUpper(details.strDeviceEnumerator);
    }
    else
    {
      CLog::LogF(LOGDEBUG, "Retrieval of endpoint enumerator name failed: {}.",
                 (FAILED(hr)) ? "'GetValue' has failed" : "'varName.pwszVal' is NULL");
    }
    PropVariantClear(&varName);

    if (S_OK == (hr = pDevice->GetId(&pwszID)))
    {
      if (wstrDDID.compare(pwszID) == 0)