locked
Bug in Windows Audio Session (WASAPI) sample?

    Question

  • The function WASAPIRenderer::InitializeAudioDeviceAsync() calls ActivateAudioInterfaceAsync(), which according to the docs should only be called from the UI thread. 

    However, if the function WASAPIRenderer::OnAudioSampleRequested() finds an HRESULT code of AUDCLNT_E_RESOURCES_INVALIDATED, it calls WASAPIRenderer::InitializeAudioDeviceAsync() to re-initialize the audio.  The problem is that WASAPIRenderer::OnAudioSampleRequested() is not called from the UI thread.

    Since this is an error condition and not normal operation I'm not sure how often this will occur, but the sample should probably be changed so that it demonstrates 'best practice'.

    Wednesday, November 21, 2012 4:21 PM

Answers

  • Thanks for reporting this. I agree that this is a bug in the sample. I will work with the samples team to get this fixed.

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, November 27, 2012 2:11 AM
    Moderator

All replies

  • Hi,

    I think this may be a document issue, but I did not find the document about that. Would you please provide us a link, I will invoke more experts to investigate it.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, November 26, 2012 7:59 AM
  • It's in the comments for the WASAPI sample - see WASAPIRenderer.cpp, function HRESULT WASAPIRenderer::InitializeAudioDeviceAsync() :

    // This call must be made on the main UI thread.  Async operation will call back to
    // IActivateAudioInterfaceCompletionHandler::ActivateCompleted, which must be an agile interface implementation
    hr = ActivateAudioInterfaceAsync( m_DeviceIdString->Data(), __uuidof(IAudioClient2), nullptr, this, &asyncOp );

    It's also mentioned in the docs for ActivateAudioInterfaceAsync():

    http://msdn.microsoft.com/en-us/library/windows/desktop/jj128298%28v=vs.85%29.aspx

    The link above is for the desktop version but I can't actually find the function documentation for Windows Store apps.

    It could be that this function needs to be called on the UI thread because it may put up a consent dialogue to use the microphone.  In the sample, it should already have been called once from the UI thread before it will be called from the audio thread (under an error condition) in which case the user has already answered the consent, so possibly it's not a problem.

    Monday, November 26, 2012 1:34 PM
  • Thanks for reporting this. I agree that this is a bug in the sample. I will work with the samples team to get this fixed.

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, November 27, 2012 2:11 AM
    Moderator