none
Still Capture Sample Application

    Question

  • Hi,

    I'm developping an application that shows a live preview from a camera and that allows grabbing a still picture.  Our camera has a "capture" pin and a "still" pin.  In GraphEdit, I'm able to use the STILL pin and grab an image using the <Snap Shot> button available in the properties dialog box of the pin.  To do the same in my app, I based my code on the MSDN article "Capturing an Image From a Still Image Pin" (http://msdn.microsoft.com/en-us/library/dd318622(VS.85).aspx).

    The article states to call "pAMVidControl->SetMode(pPin, VideoControlFlag_Trigger);".  When I do that, I get error 0x8007001F ("A device attached to the system is not functioning").  I can set the FlagVertical property w/o error.

    Here is part of my code:

    CSTATUS_T CCameraMT9P111::SoftTrigger()
    {
    	CComPtr<IPin> pSourceOutputPin( FindPin(m_p->pSource, PINDIR_OUTPUT, L"STILL") );
    	if (pSourceOutputPin == NULL) { CAMAPI_Logf(L"SoftTrigger(): Could not find the still pin of the video capture source.\n"); return CSTATUS_DIRECT_SHOW; }
    
    	CComQIPtr<IAMVideoControl, &IID_IAMVideoControl> pVideoControl(m_p->pSource);
    	if (pVideoControl == NULL) { CAMAPI_Logf(L"SoftTrigger(): Could not get the VideoControl interface.\n"); return CSTATUS_DIRECT_SHOW; } 
    
    	HRESULT hr = pVideoControl->SetMode(pSourceOutputPin, VideoControlFlag_Trigger);
    	if (FAILED(hr)) { CAMAPI_Logf(L"SoftTrigger(): Error %Xh triggering the camera.\n", hr); return CSTATUS_DIRECT_SHOW; }
    
    	return CSTATUS_SUCCESS;
    }
    
    

    So, does a sample app exists that grabs a still image?  I could test and compare w/ my code.

    Has someone ever got that error?

    Thanks
    Simon


    Simon le Lutin
    Friday, June 10, 2011 3:55 PM

Answers

  • CAUSE FOUND for error 0x8007001F : I was calling IMediaFilter::SetSyncSource(NULL) for all my filters.
    Simon le Lutin
    Monday, June 13, 2011 7:35 PM

All replies

  • Additional info:

    - I'm targetting a Windows 7 platform.
    - It WORKS on my XP desktop computer.

    Simon


    Simon le Lutin
    Friday, June 10, 2011 4:05 PM
  • Simon le Lutin wrote:
    >
    >I'm developping an application that shows a live preview from a camera
    >and that allows grabbing a still picture.  Our camera has a "capture"
    >pin and a "still" pin.
    >...
    >- I'm targetting a Windows 7 platform.
    >- It WORKS on my XP desktop computer.
     
    Is this a device with a custom driver, or a stock driver?  Is your Win 7
    platform 64-bit or 32-bit?
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, DDK MVP Providenza & Boekelheide, Inc.
    Saturday, June 11, 2011 6:25 AM
  • It's the stock Win7 driver.  It's a 32-bit platform.

    Thanks
    Simon


    Simon le Lutin
    Monday, June 13, 2011 12:40 PM
  • I tested on several XP computers and I can use the STILL pin.  On both Vista and 2 Win7 computers, there is an error.  However, I have a binary application that successfully grabs a picture on Win7, but I don't have its source code.

     


    Simon le Lutin
    Monday, June 13, 2011 1:20 PM
  • Here is a sample to grab from the STILL pin:

        http://www.box.net/shared/5cgohntb1hvgb9ozksab

    That sample works on my Win7 platform.


    Simon le Lutin
    Monday, June 13, 2011 3:44 PM
  • CAUSE FOUND for error 0x8007001F : I was calling IMediaFilter::SetSyncSource(NULL) for all my filters.
    Simon le Lutin
    Monday, June 13, 2011 7:35 PM
  • Hi Simon le Luntin:

             I meet the same problem with you ,Do you find a solution for it? if yes, please kindly tell me the method, thank you very much!

    best wishes;

    Monday, July 04, 2011 7:29 AM
  • IBaseFilter *pVideoSrcFilter = NULL;
    IMediaControl * m_pMC ;
    IMediaEventEx * m_pME ;
    IGraphBuilder * m_pGraph ;
    ICaptureGraphBuilder2 * m_pCapture ;
    IBaseFilter* m_pGrabberFilter;
    ISampleGrabber *pSG = NULL;
    IBaseFilter* m_pGrabberFilter1;
    ISampleGrabber *pSG1 = NULL;
    IBaseFilter *pNullRenderer;
    IBaseFilter *pNullRenderer1;
    
        // Create the filter graph
        HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
                              IID_IGraphBuilder, (void **) & m_pGraph);
        if (FAILED(hr))
        {
            qDebug()<<"failed to create filter graph";
            SAFE_RELEASE(m_pGraph);
        }
    
        // Create the capture graph builder
        hr = CoCreateInstance(CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
                              IID_ICaptureGraphBuilder2, (void **) & m_pCapture);
        if (FAILED(hr))
        {
            SAFE_RELEASE(m_pCapture);
    
        }
    
        // Attach the filter graph to the capture graph
        hr = m_pCapture->SetFiltergraph(m_pGraph);
        if (FAILED(hr))
        {
             qDebug()<<"failed to SetFiltergraph";
        }
    
    
        QString videoDevice;
        int deviceID = 1;
        hr = findCaptureDevice(&pVideoSrcFilter, CLSID_VideoInputDeviceCategory, deviceID, &videoDevice);
        if (FAILED(hr)) {
    
    
            qDebug() << "Failed to Get Video Capture Device";
            SAFE_RELEASE(pVideoSrcFilter);
    
        }
        // Add Capture filter to our graph.
        hr = m_pGraph->AddFilter(pVideoSrcFilter, L"Video Capture");
        if (FAILED(hr)) {
            qDebug() << "Add failed Video Capture Device";
        }
    
        // Create the Sample Grabber.
        hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
                                      IID_IBaseFilter, (void**) & m_pGrabberFilter);
    
        if (FAILED(hr)) {
            qDebug() << "Add failed Create the Sample Grabber.";
    
        }
    
    
        hr = m_pGraph->AddFilter(m_pGrabberFilter, L"Sample Grabber");
        if (FAILED(hr)) {
             qDebug() <<"Error. Could not addFilter - m_pGrabberFilter.";
    
        }
    
    
    
        hr = m_pGrabberFilter->QueryInterface(IID_ISampleGrabber, (void**)&pSG);
        if (SUCCEEDED(hr))
        {
            hr = pSG->SetOneShot(FALSE);
            hr = pSG->SetBufferSamples(TRUE);
            hr = pSG->SetCallback(this, 1); // 0 = Use the SampleCB callback method.
        }
    
    
    
        hr = CoCreateInstance(
            CLSID_NullRenderer,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IBaseFilter,
            (void**)&pNullRenderer
            );
    
        hr = m_pGraph->AddFilter(pNullRenderer, L"NullRender");
    
        // Create the Sample Grabber.
        hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
                                      IID_IBaseFilter, (void**) & m_pGrabberFilter1);
    
        if (FAILED(hr)) {
            qDebug() << "Add failed Create the Sample Grabber.";
    
        }
    
    
        hr = m_pGraph->AddFilter(m_pGrabberFilter1, L"Sample Grabber1");
        if (FAILED(hr)) {
             qDebug() <<"Error. Could not addFilter - m_pGrabberFilter1.";
    
        }
    
    
    
        hr = m_pGrabberFilter1->QueryInterface(IID_ISampleGrabber, (void**)&pSG1);
        if (SUCCEEDED(hr))
        {
            hr = pSG1->SetOneShot(FALSE);
            hr = pSG1->SetBufferSamples(TRUE);
            hr = pSG1->SetCallback(this, 1); // 0 = Use the SampleCB callback method.
        }
    
    
    
        hr = CoCreateInstance(
            CLSID_NullRenderer,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IBaseFilter,
            (void**)&pNullRenderer1
            );
    
        hr = m_pGraph->AddFilter(pNullRenderer1, L"NullRender1");
    
    
        hr = m_pCapture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
                                      pVideoSrcFilter, m_pGrabberFilter, pNullRenderer);
        if (FAILED(hr))
        {
            QString valueInHex= QString("%1").arg(hr , 0, 16);
            qDebug()<<"failed to render capture pin"<<valueInHex;
        }
    
    
    
    
       hr = m_pCapture->RenderStream(&PIN_CATEGORY_STILL, &MEDIATYPE_Video,
                                     pVideoSrcFilter, m_pGrabberFilter1, pNullRenderer1);
    
        if (FAILED(hr))
        {
            QString valueInHex= QString("%1").arg(hr , 0, 16);
            qDebug()<<"failed to render still pin"<<valueInHex;
        }
    
    
    
        // Obtain interfaces for media control and Video Window
        hr = m_pGraph->QueryInterface(IID_IMediaControl, (LPVOID *) & m_pMC);
        if (FAILED(hr))
        {
    
             qDebug()<<"failed to create IID_IMediaControl";
             SAFE_RELEASE(m_pMC);
    
        }
    
    
        m_pMC->Run();
    
    
    
    //Grab still image
    
    HRESULT hr;
    
        IAMVideoControl *pAMVidControl = NULL;
    
        hr = pVideoSrcFilter->QueryInterface(IID_IAMVideoControl, (void**)&pAMVidControl);
    
        if (SUCCEEDED(hr))
        {
            // Find the still pin.
            IPin *pPin = NULL;
    
            // pBuild is an ICaptureGraphBuilder2 pointer.
    
            hr = m_pCapture->FindPin(
                pVideoSrcFilter,                  // Filter.
                PINDIR_OUTPUT,         // Look for an output pin.
                &PIN_CATEGORY_STILL,   // Pin category.
                NULL,                  // Media type (don't care).
                FALSE,                 // Pin must be unconnected.
                0,                     // Get the 0'th pin.
                &pPin                  // Receives a pointer to thepin.
                );
    
            if (SUCCEEDED(hr))
            {
    
                qDebug()<<"SetMode ...........!!!!!!";
                hr = pAMVidControl->SetMode(pPin, VideoControlFlag_Trigger);
                pPin->Release();
                if (FAILED(hr))
                {
                    QString valueInHex= QString("%1").arg(hr , 0, 16);
    
                     qDebug()<<"SetMode FAILED...........!!!!!!"<<valueInHex;
                }
    
            }
            pAMVidControl->Release();
        }
    m_pMC->Run();
    Wednesday, March 22, 2017 10:45 AM