Click here to get back home

DirectShow cannot instantiate the CSampleGrabber (Windows Mobile 5)

 HomeNewsGroups | Search | About
 microsoft.public.smartphone.developer    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
DirectShow cannot instantiate the CSampleGrabber (Windows Mobile 5) Michton 10-24-2007
Get Chitika Premium
Posted by Michton on October 24, 2007, 10:12 am
Please log in for more thread options
Hi Everybody.

I try to make an application that grab some frame from the Preview
Camera and also draw some overlay on them back.

All the nice guys here explained me that I need to NullRenderer and
CSampleGrabber

1) I succeeded to Compile AND Register the NullRederer and the
CSampleGrabber.
2 )I succeded to instatiate the NulllRender
3) The instantiation of the CSampleGrabber falls.
(CLSID_CSampleGrabber)

Can someone helps?

Need any more code to test this?


Here is the code (improved from the basic CameraCapture of SDK)

RESULT
CGraphManager::CreateCaptureGraphInternal()
{
HRESULT hr = S_OK;
CComVariant varCamName;
CPropertyBag PropBag;
OAEVENT oaEvent;
        WCHAR         wzDeviceName[ MAX_PATH + 1 ];

CComPtr<IMediaEvent> pMediaEvent;
CComPtr<IGraphBuilder> pFilterGraph;
CComPtr<IBaseFilter> pVideoEncoder;
CComPtr<IBaseFilter> pASFMultiplexer;
        CComPtr<IFileSinkFilter> pFileSinkFilter;
CComPtr<IPersistPropertyBag> pPropertyBag;
CComPtr<IDMOWrapperFilter> pWrapperFilter;
CComPtr<IBaseFilter>                        pImageSinkFilter;

        CComPtr<IAMVideoControl> pVideoControl;
        CComPtr<IPin>                         pStillPin;
        CComPtr<IUnknown>                 pUnkCaptureFilter;

        CComPtr<IVideoWindow> pVideoWindow;
        IMediaControl *pControl = NULL;
        CComPtr<IBaseFilter> nullRenderer;
        CComPtr<IFilterGraph> pGrabber;

        CComPtr<IUnknown>                 pUnk1;
        CComPtr<IPin>                         pCaptPin;

        RECT rect;
//
// Create the capture graph builder and register the filtergraph
manager.
//

CHK( m_pCaptureGraphBuilder.CoCreateInstance( CLSID_CaptureGraphBuilder ));
CHK( pFilterGraph.CoCreateInstance( CLSID_FilterGraph ));
CHK( m_pCaptureGraphBuilder->SetFiltergraph( pFilterGraph ));


//
// Create and initialize the video capture filter
//

CHK( m_pVideoCaptureFilter.CoCreateInstance( CLSID_VideoCapture ));
CHK( m_pVideoCaptureFilter.QueryInterface( &pPropertyBag ));

// We are loading the driver CAM1 in the video capture filter.
        CHK( GetFirstCameraDriver( wzDeviceName ));
varCamName = wzDeviceName;
if( varCamName.vt != VT_BSTR )
{
ERR( E_OUTOFMEMORY );
}

CHK( PropBag.Write( L"VCapName", &varCamName ));
CHK( pPropertyBag->Load( &PropBag, NULL ));

// Everything succeeded, the video capture filter is added to the
filtergraph
CHK( pFilterGraph->AddFilter( m_pVideoCaptureFilter, L"Video
Capture Filter Source" ));


//
// Third step: Create the video encoder DMO, load the WMV9
encoder, and
// add it to the graph
//

// Create the video encoder
CHK( pVideoEncoder.CoCreateInstance( CLSID_DMOWrapperFilter ));
CHK( pVideoEncoder.QueryInterface( &pWrapperFilter ));

// Load the WMV9 DMO
CHK( pWrapperFilter->Init( CLSID_CWMV9EncMediaObject,
DMOCATEGORY_VIDEO_ENCODER ));

// Everything succeeded, let's add the encoder to the graph
CHK( pFilterGraph->AddFilter( pVideoEncoder, L"WMV9 DMO
Encoder" ));

//
// Create the ASF multiplexer and add it to the graph
//
CHK( m_pCaptureGraphBuilder->SetOutputFileName( &MEDIASUBTYPE_Asf,
L"\video1.asf", &pASFMultiplexer, &pFileSinkFilter ));

//
// Connect the video capture filter, the encoder and the
multiplexer together
//
CHK( m_pCaptureGraphBuilder->RenderStream( &PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, m_pVideoCaptureFilter, pVideoEncoder,
pASFMultiplexer ));
        CHK(pFilterGraph->QueryInterface(IID_IVideoWindow, (void
**)&pVideoWindow));
        CHK(m_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video, m_pVideoCaptureFilter, NULL, NULL ));

                CHK(pVideoWindow->put_Owner((OAHWND)g_h1));
                hr = pVideoWindow->put_WindowStyle(WS_CHILD | WS_VISIBLE |
                        WS_CLIPSIBLINGS);

                GetClientRect(g_h1, &rect);
                CHK(pVideoWindow->SetWindowPosition(rect.left,rect.top,rect.right -
rect.left, rect.bottom - rect.top));
                CHK(pVideoWindow->put_AutoShow(OATRUE));
                CHK(pVideoWindow->put_Visible(OATRUE));
                CHK(pVideoWindow->put_WindowState(SW_SHOW));
//                CHK(pVideoWindow->put_FullScreenMode(OATRUE));
//                CHK(pVideoWindow->SetWindowForeground(OATRUE));

//                CHK(m_pCaptureGraphBuilder->QueryInterface(IID_IMediaControl,
(void **) &pControl));

//                CHK(pControl->Run());
        //
        // Create the still image filter, and connect it to the video capture
filter
        //
        CHK( pImageSinkFilter.CoCreateInstance( CLSID_IMGSinkFilter ));
CHK( pFilterGraph->AddFilter( pImageSinkFilter, L"Still image
filter" ));
        CHK( m_pCaptureGraphBuilder->RenderStream( &PIN_CATEGORY_STILL,
&MEDIATYPE_Video, m_pVideoCaptureFilter, NULL, pImageSinkFilter ));
        CHK( pImageSinkFilter.QueryInterface( &m_pImageSinkFilter ));

//
// Prevent the data from flowing into the capture stream
//
CHK( m_pCaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, m_pVideoCaptureFilter, 0, 0 ,0,0 ));


IAMStreamConfig *pStillStreamConfig;
//        IBaseFilter *pCap;
//        GetDefaultCapDevice( &pCap );
        CHK(m_pCaptureGraphBuilder->FindInterface(&PIN_CATEGORY_STILL,
&MEDIATYPE_Video,m_pVideoCaptureFilter, IID_IAMStreamConfig,
(void**)&pStillStreamConfig));

        AM_MEDIA_TYPE *pType = NULL , pType1;

        int iCount=0, iSize=0;
        /* // Does not work for Mio
        VIDEO_STREAM_CONFIG_CAPS caps;
        pStillStreamConfig->GetNumberOfCapabilities(&iCount, &iSize);

        pStillStreamConfig->GetFormat(&pType);
//        pType->majortype = MEDIATYPE_Video;
//        pType->subtype = MEDIASUBTYPE_RGB555;
        int i;
        for(i=0;i<iCount;i++)
        {
                // GetStreamCaps allocates the AM_MEDIA_TYPE, which must be deleted
by using DeleteMediaType

                if(pStillStreamConfig->GetStreamCaps(i, &pType, (BYTE*)&caps) ==
S_OK )
                {
                        VIDEOINFOHEADER* m_fVideoHeader = (VIDEOINFOHEADER*)pType-
>pbFormat;
                        int t=0;
                        t++; // Just use to debug and test the best mode.
                }
        }
        pStillStreamConfig->GetStreamCaps(2, &pType, (BYTE*)&caps) ; // That
means 320X240
        VIDEOINFOHEADER* wert = (VIDEOINFOHEADER*)pType->pbFormat; // Take it
into VIDEOINFOHEADER.
        CHK(pStillStreamConfig->SetFormat(pType));
        pStillStreamConfig->GetFormat(&pType); // HERE I CHECK the connected
STREAM FORMAT !!
        wert = (VIDEOINFOHEADER*)pType->pbFormat; // Take it into
VIDEOINFOHEADER.
//
// Let's get the handle for DShow events. The main loop will
listen to both notifications from
// the UI thread and for DShow notifications
//
        */
        CHK( pFilterGraph->QueryInterface( IID_IMediaEvent, (void**)
&pMediaEvent ));
CHK( pMediaEvent->GetEventHandle( &oaEvent ));
m_handle[1] = (HANDLE) oaEvent;

m_fGraphBuilt = TRUE;

        CHK(nullRenderer.CoCreateInstance(CLSID_NullRend));
        CHK(pFilterGraph->AddFilter(nullRenderer,L"NullRenderer")); // This
Works
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
////////////// -------------------This line make the CHK to
FAIL-----------////////////////////////////////////////
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
        CHK(pGrabber.CoCreateInstance(CLSID_CSampleGrabber));
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
//////////////
---------------------------------------------------------------------------////////////////////////////////////////
                CHK( m_pVideoCaptureFilter.QueryInterface( &pVideoControl ));
                CHK( m_pVideoCaptureFilter.QueryInterface( &pUnk1 ));
                CHK( m_pCaptureGraphBuilder->FindPin( pUnk1, PINDIR_INPUT,
&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, FALSE, 0, &pCaptPin ));
//                CHK( pVideoControl->SetMode( pStillPin,
VideoControlFlag_FlipHorizontal ));
        //////////////////////////////////////////////
//                pCaptPin->Release();
                CHK( m_pVideoCaptureFilter.QueryInterface( &pUnkCaptureFilter ));

        //        CHK(pFilterGraph->AddFilter(pGrabber,L"SamGrabber"));
//                IPin *pGrabOut = GetOutPin(pGrab, 0);
//                IPin *pNullIn = GetInPin(nullRenderer, 0);
//        NotifyMessage( MESSAGE_ERROR, L"Building the graph failed" );
        IBaseFilter* pSourceFilter=NULL;


        hr=S_FALSE;
        IOverlay *pOverlay;


        if(m_pCaptureGraphBuilder){
                if(SUCCEEDED(pFilterGraph->FindFilterByName(L"Video Capture Filter
Source",&pSourceFilter ))){
                        IAMCameraControl *pControl=NULL;
                        if(SUCCEEDED(pSourceFilter->QueryInterface(IID_IAMCameraControl,
(void**)&pControl) )){
                                //CHK(pControl->Set(CameraControl_Zoom,
150,CameraControl_Flags_Manual));
                                //CHK(pControl-
>Set(CameraControl_Macro,CameraControl_Macro_On,CameraControl_Flags_Manual));
//                                CHK(pControl-
>Set(CameraControl_SetMode,CameraControl_Mode_Camera        ,CameraControl_Flags_Manual));
//                                CHK(pControl-
>Set(CameraControl_MeteringMode,CameraControl_MeteringMode_Normal,CameraControl_Flags_Manual));
//                                CHK(pControl-
>Set(CameraControl_Effect,CameraControl_Effect_Normal,CameraControl_Flags_Manual));
                        }
                        IAMVideoProcAmp *pVideoControl=NULL;
                        if(SUCCEEDED(pSourceFilter->QueryInterface(IID_IAMVideoProcAmp,
(void**)&pVideoControl) )){
                                long nMin,nMax,nDefault,nStep,nCaps;
//                                hr = pVideoControl-
>GetRange(VideoProcAmp_Gain,&nMin,&nMax,&nStep,&nDefault,&nCaps);
//                                CHK(pVideoControl->Set(VideoProcAmp_Scene,
1,CameraControl_Flags_Auto));
                        }
//                ConnectPins(nullRenderer, 0, pSourceFilter,0);

//                        SafeRelease(pControl);
                }
//                SafeRelease(pSourceFilter);

                /*
                IBaseFilter *pFilter= NULL;
                IPin *pin = NULL;
                if(SUCCEEDED(pFilterGraph->FindFilterByName(L"Video
Renderer",&pFilter ))){
                        if (SUCCEEDED(pFilter->FindPin(L"VMR Input0", &pin))) {
                                if (SUCCEEDED(pin->QueryInterface(IID_IOverlay,
                                        (void **)&pOverlay))){
                                                pin->Release();
                                                pFilter->Release();
                                }
                        //                        SafeRelease(pControl);
                }
                //                SafeRelease(pSourceFilter);

        } */

        }


Cleanup:
        if( FAILED( hr ))
        {
                TCHAR s[40];
                _stprintf(s,_T("Message=%x\n"),hr);
                OutputDebugString(s);
                NotifyMessage( MESSAGE_ERROR, L"Building the graph failed" );
        }
return hr;
}


HRESULT
CGraphManager::RunCaptureGraphInternal()
{
HRESULT hr = S_OK;

CComPtr<IGraphBuilder> pGraphBuilder;
CComPtr<IMediaControl> pMediaControl;

// Let's make sure that the graph has been initialized
if(( m_pCaptureGraphBuilder == NULL ) || ( m_fGraphBuilt ==
FALSE ))
{
ERR( E_FAIL );
}

// Retrieve the filtergraph off the capture graph builder
CHK( m_pCaptureGraphBuilder->GetFiltergraph( &pGraphBuilder ));

// Get the media control interface, and run the graph
CHK( pGraphBuilder->QueryInterface( &pMediaControl ));
CHK( pMediaControl->Run());

CHK( NotifyMessage( MESSAGE_INFO, L"The Graph is running" ));

Cleanup:
        if( FAILED( hr ))
        {
                NotifyMessage( MESSAGE_ERROR, L"Runing the capture graph failed" );
        }
return hr;
}


Similar ThreadsPosted
DirectShow in Windows Mobile 5.0 March 1, 2007, 4:57 am
How to register a directshow DLL in Windows Mobile 5.0 or 6.0? March 20, 2008, 5:41 am
Problem in playing back video files with DirectShow on Windows Mobile 6.0 September 1, 2008, 10:20 am
What video file format and codec are supported for Windows Mobile DirectShow September 2, 2008, 6:01 am
how to use the CSampleGrabber(the dshow filter), June 7, 2007, 10:35 am
WM 5.0: Error in Register CSampleGrabber and CNullRenderer into my Camera Previewer ? April 16, 2007, 6:25 am
Develop DirectShow app in smartphone mobile 5.0 March 29, 2006, 10:00 pm
DirectShow Filters and windows media player October 30, 2006, 2:28 am
How to make a Windows Media Player Plugin for Windows Mobile ? January 4, 2008, 7:17 am
How to detect codepage in windows mobile/windows CE? September 1, 2008, 11:42 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap