DirectShow 预览时抓数据的问题

我现在用directshow在手机上作拍摄预览功能,为了能够在预览的画面上画东西我需要捕获每桢数据.我下了个demo,它里面实现了ISampleGrabber,能提供抓桢的功能。我现在的问题是无法建立流链接,在调用renderstream函数时,程序出错退出。以下是代码,请高手分析一下:
HRESULT
CGraphManager::CreateCaptureGraphInternal()
{
FILE* pFile = _tfopen(TEXT("ds_log.txt"), TEXT("a+w"));

HRESULT       hr = S_OK;
CComVariant   varCamName;
CPropertyBag  PropBag;
OAEVENT       oaEvent;
WCHAR wzDeviceName[ MAX_PATH + 1 ];

CComPtr<IMediaEvent>            pMediaEvent;
CComPtr<IPersistPropertyBag>    pPropertyBag;
CComPtr<IBaseFilter> pH263Transform;

//
// Create the capture graph builder and register the filtergraph manager. 
//
CHK( m_pCaptureGraphBuilder.CoCreateInstance( CLSID_CaptureGraphBuilder ));
CHK( m_pFilterGraph.CoCreateInstance( CLSID_FilterGraph ));
CHK( m_pCaptureGraphBuilder->SetFiltergraph( m_pFilterGraph ));

// Get IMediaControl interface
CHK( m_pFilterGraph->QueryInterface( IID_IMediaControl, (void**)&m_pMediaControl ) );
fprintf(pFile, "QueryInterface m_pMediaControl\n");
//
// 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( m_pFilterGraph->AddFilter( m_pVideoCaptureFilter, L"Video Capture Filter Source" ));

//
// Create and initialize the frame grabber filter
//
CHK( CoCreateInstance( CLSID_SampleGrabber, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void**)&pH263Transform ) );
CHK( m_pFilterGraph->AddFilter( pH263Transform, FILTERNAME ) );
CHK( pH263Transform->QueryInterface( IID_ISampleGrabber, (void**)&m_pISampleGrabber ) );

// render stream
fprintf(pFile, "before RenderStream\n");

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

fprintf(pFile, "after RenderStream\n");
//
// 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( m_pFilterGraph->QueryInterface( IID_IMediaEvent, (void**) &pMediaEvent ));
CHK( pMediaEvent->GetEventHandle( &oaEvent ));
m_handle[1] = (HANDLE) oaEvent;

m_fGraphBuilt = TRUE;
NotifyMessage( MESSAGE_CREATE_FRAMECAPTUREGRAPH_OK, L"Framegraph created" );
return hr;

Cleanup:
if( FAILED( hr ))
{
NotifyMessage( MESSAGE_ERROR, L"Builing the graph failed" );
}
fprintf(pFile, "\n");
fclose(pFile);
return hr;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值