locked
MFCaptureToFile sample RRS feed

  • Question

  • While my last thread never really came to a close, I figured it was time to start a new one.

    This time, I've found some issues in the MFCaptureToFile sample.  I'm basing my comments on the W7 SDK version, since the W8 (metro or full) doesn't seem to have any samples yet.

    So far I've noticed 4 things:

    1) Despite the fact that the docs for IMFAttributes::GetAllocatedString say of pcchLength "This parameter must not be NULL", the sample does indeed pass it a NULL.  Twice. 

    I will say that this seems an odd thing for the docs to say.  If I had to guess, I'd wonder if the docs are auto-generated, and that this param (incorrectly) doesn't have an "optional" qualifier on it in the IDL.  However, either the sample or the docs (and maybe the IDL) should get changed.

    2) CCapture::EndCaptureInternal is defined and implemented, but never called.

    3) CCapture::OnReadSample calls CCapture::NotifyError (aka PostMessage) if an error occurs.  However, the posted message (WM_APP_PREVIEW_ERROR) is not processed in DialogProc.  This means the error is never actually handled.

    4) If StartCapture encounters an error, g_pCapture does not get cleared.  This leads to various errors including leaks.  Perhaps WinMain's NotifyError should do cleanup?

    Tuesday, April 17, 2012 12:21 AM

All replies

  • And some observations for MFCaptureD3D.

    In Device.cpp DrawDevice::ResetDevice() gets called whenever the window gets resized.  In there, the code attempts to release the device:

            m_pDevice->Reset

    However, this always fails, since there is an outstanding SwapChain.  As a result of this failure, the device is deleted and re-created (a *painfully* slow operation) every time the size of the window changes.

    The fix is to put this right before the reset call:

            SafeRelease(&m_pSwapChain);

    Also, in DrawDevice::CreateDevice, the CreateDevice call should include the D3DCREATE_MULTITHREADED attribute.

    Thursday, April 19, 2012 12:28 AM
  • If you make the change to MFCaptureD3D, you'll also need to add these 2 lines before the call to Reset:

            d3dpp.BackBufferHeight = 0;
            d3dpp.BackBufferWidth = 0;

    This makes sure the resizing works correctly.

    Thursday, April 19, 2012 6:57 AM
  • And while we are talking about samples, this page:

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

    has a sample.  However, the code will not compile as written.  hr is declared in the wrong place (ie *after* is it used) in RunSampleGrabber().

    Monday, April 23, 2012 6:44 AM
  • mark
    Thursday, August 14, 2014 5:58 AM