Share via

Bug in ActivateAudioInterfaceAsync loopback capture in Windows 11 22h2

p_jaholkowski 41 Reputation points
2022-10-05T13:24:27.803+00:00

Bug causes crash of application which uses that interface for grabbing audio and sometimes it leads to lost of audio signal on speakers.
I implemented my own loopback sound grabbing application which is based on that sample https://learn.microsoft.com/en-us/samples/microsoft/windows-classic-samples/applicationloopbackaudio-sample/
(By the way there is error in implementation of "HRESULT CLoopbackCapture::StopCaptureAsync()" in LoopbackCapture.cpp. If you quickly call HRESULT CLoopbackCapture::StartCaptureAsync() and HRESULT CLoopbackCapture::StopCaptureAsync() right after
it can lead to crash in HRESULT CLoopbackCapture::OnAudioSampleRequested() when application won't enter DeviceState::Capturing or DeviceState::Error state (It can be in DeviceState::Initialized or DeviceState::Starting for example))

How to reproduce:

  1. In Audio Mixer set output audio device to audio output of currently connected display monitor speaker.
  2. Launch any game in fullscreen exclusive mode (note process id of launched game) on that monitor which speakers play audio.
  3. Build that application https://github.com/microsoft/windows-classic-samples/tree/main/Samples/ApplicationLoopback
    from cmd type "ApplicationLoopback [ProcessIdOfGame] includetree Captured.wav"
  4. Enter previously launched exclusive fullscreen game, wait for a while and switch back to desktop with (alt + tab). ApplicationLoopback application
    should crash. Application crashes because pointer to Data pointer acquired by RETURN_IF_FAILED(m_AudioCaptureClient->GetBuffer(&Data, &FramesAvailable, &dwCaptureFlags, &u64DevicePosition, &u64QPCPosition));
    in HRESULT CLoopbackCapture::OnAudioSampleRequested() becomes invalidated (There is access violation when reading that Data buffer).

I wrote that bug exists on Windows 11 22h2 beacuse I tested it on other Windows 10 and 11 opearating systems and there it works fine but it may be
connected with audio device lost on some monitors when they exit exclusive fullscreen state after pointer to Data is grabbed by m_AudioCaptureClient->GetBuffer.

Windows development | Windows API - Win32
Windows for business | Windows Client for IT Pros | User experience | Other

1 answer

Sort by: Most helpful
  1. Limitless Technology 40,101 Reputation points
    2022-10-06T15:02:48.36+00:00

    Hello there,

    May be this hotfix which is not yet released for windows 11 might be your answer.

    USB audio devices stop streaming audio on a computer that is running Windows 7 SP1, Windows Server 2008 R2 SP1 or Windows XP SP3 https://support.microsoft.com/en-us/topic/usb-audio-devices-stop-streaming-audio-on-a-computer-that-is-running-windows-7-sp1-windows-server-2008-r2-sp1-or-windows-xp-sp3-3c892ca7-3589-2bc2-a921-d6f8a425cca8

    --------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.