Video capture with preview for windows mobile 5.0

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

I am encountering a problem while developing an application for windows
mobile ver 5.0 which capture video and take still pictures with live preview.

Environment for the application:

1. We have developed a DLL in VC++ which use direct show filters graphs to
capture video.

The dll have 4 functions as follows:

// hWnd is the handle for a message window and handlePanel is handle
for a panel (container) which shall show the priview of recording)
1. InitializeGraph ( IntPtr hWnd, IntPtr handlePanel)

// Capture still image and store into local folder
2. CaptureStill();

// Start record Video
3. StartCaptureVideo();

// Stop record video
4. StopCaptureVideo()


2. On the other side we have a C# application which shall call the DLL
(using DllImport method) funtions.

The application is working perfectly for taking still image and recording
video without live preview. But when we added the code for showing preview
the application hangs.

Following is the code which initialize capture graph in dll.

[color=red]Red marked lines are code for showing preview.[/color]

// initialize capture graph
HRESULT 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<IVideoWindow> pVideoWindow;
IMediaControl *pControl = NULL;
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 ));

[color=red]// Code for showing video capture preview starts
CHK( pFilterGraph->AddFilter( m_pVideoCaptureFilter, L"Video Capture
Filter Source" ));
CHK(pFilterGraph->QueryInterface(IID_IVideoWindow,
(void**)&pVideoWindow));

// program is hanging while uncommenting below line

CHK(m_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW,&MEDIATYPE_Video, m_pVideoCaptureFilter, NULL, NULL ));

// m_handlePanel is the handle for panel that we are getting from the c#
application to show live preview
CHK(pVideoWindow->put_Owner((OAHWND)m_handlePanel));

hr = pVideoWindow->put_WindowStyle(WS_CHILD | WS_VISIBLE |
WS_CLIPSIBLINGS);

GetClientRect(m_handlePanel, &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));
// Code for showing video capture preview end.[/color]
//
// 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 ));

//
// 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;
NotifyMessage( MESSAGE_ERROR, L"Builing the graph failed" );

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


While including the code

[color=red]CHK(m_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW,&MEDIATYPE_Video, m_pVideoCaptureFilter, NULL, NULL ));[/color]
program is getting hanged

any help?

Thanks
.



Relevant Pages

  • Re: Sai, Gary, please Help: DirectShow::NullRenderer Connection?
    ... // Create the capture graph builder and register the filtergraph ... CHK(m_pCaptureGraphBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder)); ... // We are loading the driver CAM1 in the video capture filter. ...
    (microsoft.public.pocketpc.developer)
  • Video capture with preview for windows mobile 5.0
    ... mobile ver 5.0 which capture video and take still pictures with live preview. ... CHK(m_pCaptureGraphBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder ... // We are loading the driver CAM1 in the video capture filter. ...
    (microsoft.public.windowsce.app.development)
  • Re: The Apprentice 2 - Trials of making my first DV movie
    ... with USB from a camera? ... Video captured that way is never high quality unless ... > my DV camcorder could transfer digital data to my ... > I installed the USB drivers and Imaging capture software ...
    (microsoft.public.windowsxp.moviemaker)
  • Re: Capturing from VHS/DVD recorder player
    ... I will be getting that ADS USB device. ... VHS video is copied to and digitalized for the DVD disc. ... For analog capture from either my Cable TV box, DVD player or VCR, the ...
    (microsoft.public.windowsxp.moviemaker)
  • Re: Info on H.264
    ... I have a DVR card that supports H.264 video compression. ... It might make more sense, to use a $20 capture chip, with uncompressed ... and write it out to disk in an economical format. ...
    (rec.video.desktop)