• 大小: 7.35MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-14
  • 语言: 其他
  • 标签: DShowDirect  

资源简介

Direct Show的简单采集和预览程序。

资源截图

代码片段和文件信息

#include “capture.h“


CCapture::CCapture()
{

}

CCapture::~CCapture()
{

}


HRESULT CCapture::SetupGraph(HWND hwnd)
{
HRESULT hr;
RECT rc;

//Create filter graph
hr = CoCreateInstance(CLSID_FilterGraph NULL CLSCTX_INPROC IID_IGraphBuilder (void **)&m_pGraph);
if (FAILED(hr))
return hr;

//Create capture graph builder
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2 NULL CLSCTX_INPROCIID_ICaptureGraphBuilder2 (void **)&m_pCapture);
if (FAILED(hr))
return hr;

//Obtain graph interfaces(mediaControl  videoWindow  mediaEvent)
hr = m_pGraph->QueryInterface(IID_IMediaControl (LPVOID *)&m_pMC);
if (FAILED(hr))
return hr;
hr = m_pGraph->QueryInterface(IID_IVideoWindow (LPVOID *)&m_pVW);
if (FAILED(hr))
return hr;
hr = m_pGraph->QueryInterface(IID_IMediaEventEx (LPVOID *)&m_pME);
if (FAILED(hr))
return hr;

//Attach
hr = m_pCapture->SetFiltergraph(m_pGraph);
if (FAILED(hr))
return hr;

m_hwnd = hwnd;
return hr;
}


HRESULT CCapture::FindCaptureDevice()
{
HRESULT hr = S_OK;
ICreateDevEnum *pDevEnum = NULL;
IEnumMoniker *pClassEnum = NULL;
IMoniker* pMoniker = NULL;

//Create system device enumerator
hr = CoCreateInstance(CLSID_SystemDeviceEnum NULL CLSCTX_INPROCIID_ICreateDevEnum (void **)&pDevEnum);
if (FAILED(hr))
return hr;

//Create an enumerator for video capture devices
hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory &pClassEnum 0);
if (FAILED(hr) || pClassEnum == NULL)
{
SAFE_RELEASE(pDevEnum);
return hr;
}

//Use the first device
hr = pClassEnum->Next(1 &pMoniker NULL);
if (hr == S_FALSE)
{
SAFE_RELEASE(pDevEnum);
SAFE_RELEASE(pClassEnum);
return hr;
}
//Bind moniker to a filter object
hr = pMoniker->BindToobject(0 0 IID_IbaseFilter (void**)&m_pFilter);
if (FAILED(hr))
{
SAFE_RELEASE(pDevEnum);
SAFE_RELEASE(pClassEnum);
SAFE_RELEASE(pMoniker);
return hr;
}
m_pFilter->AddRef();

return hr;
}


HRESULT CCapture::AddToGraph()
{
HRESULT hr = m_pGraph->AddFilter(m_pFilter L“Video Capture“);

if (FAILED(hr))
{
m_pFilter->Release();
return hr;
}

return hr;
}


HRESULT CCapture::Render()
{
HRESULT hr;

hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW &MEDIATYPE_Videom_pFilter NULL NULL);
if (FAILED(hr))
{
m_pFilter->Release();
return hr;
}

//Now  basefilter can be released
m_pFilter->Release();

//show window  preview
hr = m_pVW->put_Owner((OAHWND)m_hwnd);
if (FAILED(hr))
return hr;
hr = m_pVW->put_Windowstyle(WS_CHILD | WS_CLIPCHILDREN);
if (FAILED(hr))
return hr;
/*hr = m_pME->SetNotifyWindow((OAHWND)m_hwnd WM_GRAPHNOTIFY 0);
if (FAILED(hr))
return hr;*/
ResizeWindow();
hr = m_pVW->put_Visible(OATRUE);
if (FAILED(hr))
return hr;
hr = m_pMC->Run();

return hr;
}


void CCapture::DestroyGraph()
{
if (m_pMC)
m_pMC->StopWhenReady();
/* 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     32768  2016-11-04 21:44  Code\simplecapture\.vs\simplecapture\v14\.suo

     文件       3431  2016-11-03 23:04  Code\simplecapture\capture.cpp

     文件        585  2016-11-03 22:54  Code\simplecapture\capture.h

     文件       1835  2016-11-03 23:01  Code\simplecapture\main.cpp

     文件       1307  2016-11-03 20:12  Code\simplecapture\simplecapture.sln

     文件   31678464  2016-11-04 21:44  Code\simplecapture\simplecapture.VC.db

     文件       7730  2016-11-03 22:22  Code\simplecapture\simplecapture.vcxproj

     文件       1156  2016-11-03 20:39  Code\simplecapture\simplecapture.vcxproj.filters

     文件        223  2016-11-03 20:39  Code\simplecapture\simplecapture.vcxproj.user

     目录          0  2016-11-03 20:12  Code\simplecapture\.vs\simplecapture\v14

     目录          0  2016-11-03 20:12  Code\simplecapture\.vs\simplecapture

    ...D.H.         0  2016-11-03 20:12  Code\simplecapture\.vs

     目录          0  2016-11-04 21:45  Code\simplecapture

     目录          0  2016-11-03 20:12  Code

----------- ---------  ---------- -----  ----

             31727499                    14


评论

共有 条评论

相关资源