Example #1
0
HRESULT CMpcAudioRenderer::InitCoopLevel()
{
    HRESULT hr = S_OK;
    IVideoWindow* pVideoWindow = nullptr;
    HWND hWnd = nullptr;

    hr = m_pGraph->QueryInterface(IID_PPV_ARGS(&pVideoWindow));
    if (SUCCEEDED(hr)) {
        pVideoWindow->get_Owner((OAHWND*)&hWnd);
        SAFE_RELEASE(pVideoWindow);
    }
    if (!hWnd) {
        hWnd = GetTopWindow(nullptr);
    }

    ASSERT(hWnd != nullptr);
    if (!m_useWASAPI) {
        hr = m_pDS->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);
    } else if (hTask == nullptr) {
        // Ask MMCSS to temporarily boost the thread priority
        // to reduce glitches while the low-latency stream plays.
        DWORD taskIndex = 0;

        if (pfAvSetMmThreadCharacteristicsW) {
            hTask = pfAvSetMmThreadCharacteristicsW(_T("Pro Audio"), &taskIndex);
            TRACE(_T("CMpcAudioRenderer::InitCoopLevel Putting thread in higher priority for WASAPI mode (lowest latency)\n"));
            hr = GetLastError();
            if (hTask == nullptr) {
                return hr;
            }
        }
    }

    return hr;
}
HRESULT CWASAPIRenderFilter::EnableMMCSS()
{
  if (!m_hTask)
  {
    // Ask MMCSS to temporarily boost the thread priority
    // to reduce glitches while the low-latency stream plays.
    DWORD taskIndex = 0;

    if (pfAvSetMmThreadCharacteristicsW)
    {
      m_hTask = pfAvSetMmThreadCharacteristicsW(L"Pro Audio", &taskIndex);
      Log("CWASAPIRenderFilter::EnableMMCSS Putting thread in higher priority for WASAPI mode");
      
      if (!m_hTask)
        return HRESULT_FROM_WIN32(GetLastError());
    }
  }
  return S_OK;
}
Example #3
0
HRESULT CMpcAudioRenderer::InitCoopLevel()
{
    HRESULT				hr				= S_OK;
    IVideoWindow*		pVideoWindow	= NULL;
    HWND				hWnd			= NULL;
    CComBSTR			bstrCaption;

    hr = m_pGraph->QueryInterface (__uuidof(IVideoWindow), (void**) &pVideoWindow);
    if (SUCCEEDED (hr))
    {
        pVideoWindow->get_Owner((OAHWND*)&hWnd);
        SAFE_RELEASE (pVideoWindow);
    }
    if (!hWnd)
    {
        hWnd = GetTopWindow(NULL);
    }

    ATLASSERT(hWnd != NULL);
    if (!useWASAPI)
        hr = m_pDS->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);
    else if (hTask == NULL)
    {
        // Ask MMCSS to temporarily boost the thread priority
        // to reduce glitches while the low-latency stream plays.
        DWORD taskIndex = 0;

        if (pfAvSetMmThreadCharacteristicsW)
        {
            hTask = pfAvSetMmThreadCharacteristicsW(TEXT("Pro Audio"), &taskIndex);
            TRACE(_T("CMpcAudioRenderer::InitCoopLevel Putting thread in higher priority for Wasapi mode (lowest latency)"));
            hr=GetLastError();
            if (hTask == NULL)
                return hr;
        }
    }

    return hr;
}