DirectX display collection source (CAMERA) Filter

Source: Internet
Author: User


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-> setpolicywindow (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 ("Fast Forward> 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 ")
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 display collection source (CAMERA) Filter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.