IGraphBuilder * g_pGraphBuilder = NULL;
IBaseFilter *Pbf=0;
IVideoWindow  * g_pVWindow = NULL;
IMediaControl * g_pMControl = NULL;
IMediaEventEx * g_pMEvent = NULL;
ICaptureGraphBuilder2 * g_pCaptureBuilder = NULL;
IVideoWindow  *g_pivw  = NULL;

void CTestDlg::OnButton5() 
{
// TODO: Add your control notification handler code here
HRESULT hr;
IBaseFilter *pSrcFilter=NULL;
     CoInitialize(NULL);
    // Create the filter graph
    hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
                           IID_IGraphBuilder, (void **) &g_pGraphBuilder);
    // Create the capture graph builder
    hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
                           IID_ICaptureGraphBuilder2, (void **) &g_pCaptureBuilder);
    // Obtain interfaces for media control and Video Window
    hr = g_pGraphBuilder->QueryInterface(IID_IMediaControl,(LPVOID *) &g_pMControl);
    hr = g_pGraphBuilder->QueryInterface(IID_IVideoWindow, (LPVOID *) &g_pVWindow);
    hr = g_pGraphBuilder->QueryInterface(IID_IMediaEvent, (LPVOID *) &g_pMEvent);
         g_pGraphBuilder->QueryInterface(IID_IVideoWindow, (void **)&g_pivw);
    // Set the window handle used to process graph events
    hr = g_pMEvent->SetNotifyWindow((OAHWND)ghApp, WM_GRAPHNOTIFY, 0);
//
hr = g_pCaptureBuilder->SetFiltergraph(g_pGraphBuilder);
hr = FindCaptureDevice(&pSrcFilter);
    if (FAILED(hr))
    {
        // Don't display a message because FindCaptureDevice will handle it
        exit(1);
    }
    Pbf = pSrcFilter;
    // Add Capture filter to our graph.
    hr = g_pGraphBuilder->AddFilter(pSrcFilter, L"Video Capture");
hr = g_pCaptureBuilder->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
                                   pSrcFilter, NULL, NULL);
pSrcFilter->Release();

// hr = SetupVideoWindow(0);
///* //////////////////////////////////////////////////
    HWND m_hwnd = m_Screen2.GetSafeHwnd();
    m_Screen2.ModifyStyle(0, WS_CLIPCHILDREN);
    RECT rc;
m_Screen2.GetClientRect(&rc);

hr = g_pVWindow->put_Owner((OAHWND)m_hwnd);
hr = g_pVWindow->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);

hr = g_pVWindow->SetWindowPosition(0, 0, (rc.right), (rc.bottom));
hr = g_pVWindow->put_Visible(OATRUE);//*/
//////////////////////////////////////////////////
DWORD g_dwGraphRegister=0;
hr = g_pMControl->Run();
//

}
int rate=1;
void CTestDlg::OnButton2() 
{   
if (pims)
{    
rate++;
if(rate==4)
{
rate=1;

}
pims->SetRate(rate);
CString str;
str.Format("快进>> X %d",rate);
(GetDlgItem(IDC_BUTTON2))->SetWindowText(str);
}

// pivw->GetCurrentImage(&lpCurrImage) ;

}

HRESULT FindCaptureDevice(IBaseFilter ** ppSrcFilter)
{
    HRESULT hr;
    IBaseFilter * pSrc = NULL;
    IMoniker *pMoniker;
    ULONG cFetched;

    if (!ppSrcFilter)
        return E_POINTER;
   
    // Create the system device enumerator
    CComPtr <ICreateDevEnum> pDevEnum =NULL;

    hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
                           IID_ICreateDevEnum, (void **) &pDevEnum);
    if (FAILED(hr))
    {
    //    Msg(TEXT("Couldn't create system enumerator!  hr=0x%x"), hr);
        return hr;
    }

    // Create an enumerator for the video capture devices
   // CComPtr <IEnumMoniker> pClassEnum = NULL;
IEnumMoniker *pClassEnum=0;
    hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
    if (FAILED(hr))
    {
      //  Msg(TEXT("Couldn't create class enumerator!  hr=0x%x"), hr);
        return hr;
    }

    // If there are no enumerators for the requested type, then 
    // CreateClassEnumerator will succeed, but pClassEnum will be NULL.
    if (pClassEnum == NULL)
    {
        MessageBox(ghApp,TEXT("No video capture device was detected.\r\n\r\n")
                   TEXT("This sample requires a video capture device, such as a USB WebCam,\r\n")
                   TEXT("to be installed and working properly.  The sample will now close."),
                   TEXT("No Video Capture Hardware"), MB_OK | MB_ICONINFORMATION);
        return E_FAIL;
    }

    // Use the first video capture device on the device list.
    // Note that if the Next() call succeeds but there are no monikers,
    // it will return S_FALSE (which is not a failure).  Therefore, we
    // check that the return code is S_OK instead of using SUCCEEDED() macro.
    /*if (S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
    {
        // Bind Moniker to a filter object
        hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
        if (FAILED(hr))
        {
          //  Msg(TEXT("Couldn't bind moniker to filter object!  hr=0x%x"), hr);
            return hr;
        }
    }
    else
    {
       // Msg(TEXT("Unable to access video capture device!"));   
        return E_FAIL;
    }*/

while(S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
    {
IPropertyBag *pProp= 0;
pMoniker->BindToStorage(0,0,IID_IPropertyBag,(void**)&pProp);
VARIANT varName;
varName.vt = VT_BSTR;
hr=pProp->Read(L"FriendlyName",&varName,0);
if(hr == NOERROR)
        {
CString str(varName.bstrVal);

if (str.Find("Virtual Camera",0)!=-1)
{
hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
if (FAILED(hr))
{
//  Msg(TEXT("Couldn't bind moniker to filter object!  hr=0x%x"), hr);
break;
}
break;
}

}
pMoniker->Release();
    }
    // Copy the found filter pointer to the output parameter.
    // Do NOT Release() the reference, since it will still be used
    // by the calling function.
    *ppSrcFilter = pSrc;

    return hr;
}

directX显示采集源(摄像头)filter的更多相关文章

  1. 用EasyClient开源项目采集Windows摄像头/麦克风的音视频进行RTSP直播

    EasyClient是EasyDarwin开源流媒体团队开发的一款功能丰富的开源PC客户端项目,目前支持Windows.Android版本,后续将支持ios版本,其中Windows版本的EasyCli ...

  2. 在MyEclipse显示struts2源码和doc文档及自动完成功能

    分类: struts2 2010-01-07 16:34 1498人阅读 评论(1) 收藏 举报 myeclipsestruts文档xmlfileurl 在MyEclipse显示struts2源码和d ...

  3. 百度网盘采集源码 ,直接采集网盘添加cookies功能

    名称:百度网盘采集源码 程序语言:php 数据库:mysql 程序介绍: 1.直接采集百度网盘url 2.前端基于bootstrap 3.搜索考虑到后期上亿数据,是基于coreseek,搜索时间毫秒级 ...

  4. OpenCV show two cameras 同时显示两个摄像头

    用OpenCV同时显示两个摄像头的内容的代码如下: #include <iostream> #include <stdio.h> #include <tchar.h> ...

  5. Linux下用FFMPEG采集usb摄像头到RTMP

    Linux下用 FFMPEG 采集 usb摄像头视频 和 摄像头内置麦克风音频 到RTMP服务   ffmpeg -f video4linux2 -qscale 10 -r 12 -s 640x480 ...

  6. 网络摄像头Androi端显示(mjpeg)源码分析

    main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and ...

  7. C#采集UVC摄像头画面并支持旋转和分辨率切换

    在项目中,我们会需要控制uvc摄像头,采集其实时画面,或者对其进行旋转.目前市面上大多数USB摄像头都支持UVC协议.那么如何采集呢?当然是采用SharpCamera!因为SharpCamera支持对 ...

  8. [求助]谁能给我讲解一下,iOS编程要如何实时显示采集到的图像???

    rt,最近搞一个高清图传,本着自(bu)主(mai)创(da)新(jiang)的原则,打算利用手中的iPad当作辅助飞行屏幕,USB传输数据.再说某疆图传7999(还只支持自家云台录像拍照),哪是我这 ...

  9. SpringMVC中JSP页面显示为源码

    @RequestMapping(value = "login") public ModelAndView login(ModelAndView mav) throws Except ...

随机推荐

  1. vsftp 的安装及配置

    安装vsftpd 直接用 yum安装,方便的很 yum -y install vsftpd #进入vsftpd目录cd /etc/vsftpd/ #Create The Virtual Users D ...

  2. iOS-Wonderful 完美颜色库

    开发中颜色的使用也是非常频繁的,这里推荐一个dsxNiubility大牛写的颜色库:Wonderful:它的好用就是很清楚的把每个常用的颜色进行了由浅到深的分层,让我们使用时可以根据自己对颜色的深浅直 ...

  3. IIS 加载 JSON 错误 404 解决办法

    MIME设置:在IIS的站点属性的HTTP头设置里,选MIME 映射中点击”文件类型”-”新类型”,添加一个文件类型:关联扩展名:*.json内容类型(MIME):application/x-java ...

  4. Java对正则表达式的支持(一)

    Java对正则表达式的支持主要体现在String.Pattern.Matcher和Scanner类. 1.Pattern.Matcher 先看一个Pattern和Matcher类使用正则表达式的例子. ...

  5. POJ 2888 Magic Bracelet [Polya 矩阵乘法]

    传送门 题意:竟然扯到哈利波特了.... 和上一题差不多,但颜色数很少,给出不能相邻的颜色对 可以相邻的连边建图矩阵乘法求回路个数就得到$f(i)$了.... 感觉这样的环上有限制问题挺套路的...旋 ...

  6. POJ 2409 Let it Bead [置换群 Polya]

    传送门 题意:$m$种颜色$n$颗珠子,定义旋转和翻转两种置换,求不等价着色数 暴力求每个置换的循环节也许会$T?$ 我们可以发现一些规律: 翻转: $n$为奇数时每个置换有$1+\frac{n-1} ...

  7. BZOJ 1485: [HNOI2009]有趣的数列 [Catalan数 质因子分解]

    1485: [HNOI2009]有趣的数列 Description 我们称一个长度为2n的数列是有趣的,当且仅当该数列满足以下三个条件: (1)它是从1到2n共2n个整数的一个排列{ai}: (2)所 ...

  8. vue2.0使用slot插槽分发内容

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. Centos-7 + Docker-1.12 中 devicemapper + direct_lvm 的 Docker 存储配置

    html,body { font-size: 12pt } body { font-family: Helvetica, "Hiragino Sans GB", "微软雅 ...

  10. 【转】APACHE RewriteEngine用途

    首先要学会怎么设置 httpd.conf 的设置, 什么 ALL 就不用用说了 要看你的 httpd.conf 是否设置正确了,很简单,只要你在 .htaccess  里随便录入一些 比如 adbas ...