How to use the system equipment enumerator for video capture

zhaozj2021-02-16  58

How to use system equipment enumerator

System Equipment Enumerator provides a unified approach to the FITLER that enumerates registered in the system. Moreover, it can distinguish between different hardware devices, even if the same filter supports them. This is very useful for those who use Windows Drive Models and Ksproxy Filter. System Equipment Enumerator Treats them in different device instances (translation: Although they support the same filter).

When we use the system equipment enumerator query device, the system device enumerator generates a specific type of device (such as audio capture, and video compression) generated an enumerator. (ENUMERATOR). Category Enumerator Returns a Moniker for each type of device, the type enumerator automatically contains each instant device.

Use the system device enumerator as follows:

1. Call method COCREATEINSTANCE Generates a system device enumerator. Class ID (CLSID) is CLSID_SYSTEMDEVICEENUM.

2. Call the iCreateDevenum :: CreateClassenumerator method Generate the type enumerator, the parameter for the type of CLSID you want to get, this method returns a IEnummoniker interface pointer, if the specified type (empty) or does not exist, the function icrAtesDeverator :: CreateClassenumerator Returns S_FALSE instead of the error code, and the Ienummoniker pointer (the translation: returns by parameters) is also empty, which requires us to clearly use the S_OK when calling CreateClassenumerator, rather than using the macro succeeded.

3. Use the IEnummoniker :: next method to get each Moniker in the Ienummoniker pointer. This method returns an IMONIKER interface pointer. When NEXT arrives at the bottom of the enumeration, its return value is still S_FALSE, where we still need to check with S_OK.

4. Want to get the more friendly name of the device (for example, if you want to display in the user interface), call the iMoniker :: BindtoStOrage method.

5. If you want to generate and initialize the Filter call 3 returning the pointer's IMONITOR :: bindtoobject method, then call the IFTERGraph :: AddFilter to add the filter to the view.

The figure below illustrates the above steps:

The following code example shows how to enumerate the video compressor in the user system, for simplicity, only a little error check is given.

/ / Generate a system device enumerator.

HRESULT HR;

IcreateDevenum * psysdevenum = null;

HR = CoCreateInstance (CLSID_SYSTEMDEVICEENUM, NULL, CLSCTX_INPROC_SERVER,

IID_ICREATEDEVENUM, (void **) & psysdevenum);

IF (Failed (HR))

{

Return HR;

}

// Get the class enumerator of the video compression.

Ienummoniker * penumcat = null;

HR = psysdevenum-> createclassenumerator (CLSID_VIDEOCOMPRESSORCATOR), & Penumcat, 0);

IF (hr == s_ok)

{

// Enumerates the Moniker.

IMONIKER * PMONIKER = NULL;

Ulong cfetched;

While (Penumcat-> Next (1, & PMoniker, & CFetched) == S_OK)

{

IPropertyBag * ppropbag;

HR = PMoniker-> BindtOStorage (0, 0, IID_IPROPERTYBAG,

(void **) & ppropbag);

En (ac))

{

// If you get the friendly name of Filter:

Variant varname;

Variantinit; & VarName;

HR = ppropbag-> read (l "friendlyname", & varname, 0);

En (ac))

{

// Display above your user interface.

}

VariantClear (& VarName);

// The following example is generated:

Ibasefilter * pfilter;

HR = PMoniker-> BindToObject (Null, Null, IID_IBASEFILTER,

(void **) & pfilter;

// Add Filter to Graph.

// Behind you must remember to release the Pfilter.

Ppropbag-> Release ();

}

PMoniker-> Release ();

}

Penumcat-> Release ();

}

psysdevenum-> release ();

Equipment Moniker

IMONIKER :: getDisplayName method Returns the name of Moniker. You can pass this name to IFILTERGRAPH2 :: AddSourceFilterformoniker, which can generate the capture filter of the device.

LpoLEStr strname = null;

IBaseFilter PSRC = NULL;

HR = PMoniker-> getDisplayName (Null, Null, & Strname);

En (ac))

{

/ / Get the Filter Graph Manager of IFTERGRAPH2.

IFiltergraph2 * pfg2 = null;

HR = pgraph-> queryinterface (IID_IFILTERGRAPH2, (Void **) & pfg2);

En (ac))

{

HR = PFG2-> AddSourceFilterformoniker (PMoniker, 0, L "Source", & PSRC);

PFG2-> Release ();

}

Cotaskmemfree (Strname);

}

// If success, remember to release the PSRC.

Although the name obtained by the above method has good readability, we generally do not display it to the user, as previously shown, we generally use the name from iPropertybag.

Method iMoniker :: ParsedisplayName and MkParsedisplayName can be used to generate Moniker for specified Filter type devices. The name is "@Device: *: {category-clsid}" represents the type of GUID, the default Moniker is the first Moniker in the device enumerator.

// Video capture type

Wchar szmon [] = L "@Device: *: {860bb310-5d01-11d0-bd3b

-00A0C

911CE86} "

IbindctX * pbindctX;

HR = CreateBindctX (0, & PbindctX);

Ulong cheaden = 0;

IMONIKER * PMONIKER = 0;

HR = MKPARSPLAYNAME (PbindctX, Szmon, & Cheaten, & PMoniker);

PBINDCTX-> Release ();

En (ac))

{

/ / Get the name or bind to DirectShow Filter.

PMoniker-> Release ();

}

转载请注明原文地址:https://www.9cbs.com/read-21865.html

New Post(0)