为什么使用IAMStreamConfig不能改变摄像头分辨率?
代码如下,但pConfig根本没有获取到数据,为什么没有获取数据呢?請赐教
我是设置了断点测试的!
length_24bit = 0L;
length_8bit = 0L;
data_24bit=NULL;
data_8bit=NULL;
HRESULT hr;
//initialize data
hr = InitCaptureGraphBuilder();
if (FAILED(hr))
{
AfxMessageBox(L"Failed to get video interfaces!");
return hr;
}
//bind object device
if(!BindFilter(iDeviceID, &m_pBF))
return S_FALSE;
hr = m_pGB->AddFilter(m_pBF, L"Capture Filter");
//create ISampleGrabber module
hr = CoCreateInstance( CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_ISampleGrabber, (void**)&m_pGrabber );
if(FAILED(hr))
{
AfxMessageBox(L"Fail to create SampleGrabber, maybe qedit.dll is not registered?");
return hr;
}
//add Grabber Filer
CComQIPtr< IBaseFilter, &IID_IBaseFilter > pGrabBase(m_pGrabber);
hr = m_pGB->AddFilter( pGrabBase, L"Grabber" );
if(FAILED(hr))
{
AfxMessageBox(L"Fail to put sample grabber in graph");
return hr;
}
//configure video format
AM_MEDIA_TYPE * AMT = new AM_MEDIA_TYPE;
ZeroMemory(AMT, sizeof(AM_MEDIA_TYPE));
m_pCapture->FindInterface(&PIN_CATEGORY_CAPTURE,&MEDIATYPE_Interleaved,m_pBF, IID_IAMStreamConfig, (void **)&pConfig); <-问题出在这?????????????pConfig没获得数据
pConfig->GetFormat(&AMT);
AMT->majortype = MEDIATYPE_Video;
AMT->subtype = MEDIASUBTYPE_RGB24;
hr = m_pGrabber->SetMediaType(AMT);
if(FAILED(hr))
{
AfxMessageBox(L"set media type error");
return hr;
}
//capture instant image
hr = m_pCapture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,m_pVW,pGrabBase,NULL);
if( FAILED(hr))
{
AfxMessageBox(L"Can't build the graph");
return hr;
}
//load video format
hr = m_pGrabber->GetConnectedMediaType(AMT);
if (FAILED(hr))
{
AfxMessageBox(L"connect media type error");
return hr;
}
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER*) AMT->pbFormat;
//
//vih->bmiHeader.biWidth=960;
//vih->bmiHeader.biHeight=720;
m_pSampleGrabberCB->SetWidth(vih->bmiHeader.biWidth);
m_pSampleGrabberCB->SetHeight(vih->bmiHeader.biHeight);
m_pSampleGrabberCB->SetbGrabVideo(TRUE);
if (AMT->cbFormat != 0)
{
//Free Media Type
CoTaskMemFree((PVOID)AMT->pbFormat);
AMT->cbFormat = 0;
AMT->pbFormat = NULL;
if (AMT->pUnk != NULL)
{
AMT->pUnk->Release();
AMT->pUnk = NULL;
}
}
//using call-back module
hr = m_pGrabber->SetBufferSamples(FALSE);
hr = m_pGrabber->SetOneShot(FALSE);
hr = m_pGrabber->SetCallback(m_pSampleGrabberCB,1);
//configure Video Window
m_hWnd = hWnd ;
m_pVW->put_Owner((OAHWND)m_hWnd);
m_pVW->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
if (m_pVW)
{
CRect rc;
::GetClientRect(m_hWnd,&rc);
m_pVW->SetWindowPosition(0, 0, rc.right, rc.bottom);
}
//begin to capture video frame
hr = m_pMC->Run();
if(FAILED(hr))
{
AfxMessageBox(L"Couldn't run the graph!");
return hr;
}