Simplest DirectShow-based example: Get filter information

Source: Internet
Author: User
Tags 04x

=====================================================

The simplest list of sample articles based on DirectShow:

The simplest DirectShow-based example: Video player

Simplest DirectShow-based example: Video player graphical interface version

Simplest DirectShow-based example: Video Player custom version

Simplest DirectShow-based example: Get filter information

=====================================================


This document records a program that obtains the filter information for DirectShow. The program can traverse the DirectShow filter in the current system and print their information to the console. Through this procedure, we can find out the relationship between several key structures such as Filter,pin,mediatype in DirectShow and how to obtain their information.


Flow chart
The flowchart for the program is shown below. Due to the larger size of the graph, it does not appear in the page, so I uploaded a copy in the album:

View Large Map interface

The following interfaces are involved in this flowchart:
Icreatedevenum *psysdevenum: Device Enumeration interface.
IEnumMoniker *penumcat:moniker (alias) enumeration interface.
IMoniker *pmoniker:moniker (alias) interface.
IPropertyBag *ppropbag: An interface that stores property values.
Ibasefilter *pfilter:filter interface.
Ienumpins * Pinenum:filter Enumeration interface.
Ipin * Pin:pin interface.
Pin_info Pininfo: The structure of the information that stores the PIN.
Ienummediatypes *mtenum:mediatype Enumeration interface.

Am_media_type *MT: Describes the structure of the media type.

Flow chart

The following functions are involved in the flowchart:

"Initialize"

CoInitialize (): Initializes the COM runtime environment.

CoCreateInstance (..., psysdevenum): Creates a COM object with the specified class identifier. In this example, the class identifier is "Iid_icreatedevenum" and is used to create the icreatedevenum.

"Enumeration of filter"
Psysdevenum->createclassenumerator (..., penumcat): Enumerates the device moniker (aliases) under the specified type directory through the Icreatedevenum query IEnumMoniker enumeration interface.
Penumcat->next (..., pmoniker): Queries the next IMoniker interface through IEnumMoniker.
Pmoniker->bindtostorage (..., ppropbag): Queries the IPropertyBag interface via IMoniker (for obtaining the filter information).
Ppropbag->read ("FriendlyName"): Gets the value of the "FriendlyName" property by IPropertyBag.

Pmoniker->bindtoobject (..., pfilter): IMoniker query Ibasefilter interface (used to get filter, note and bindtostorage () difference).

"Enumeration of Pins"
Pfilter->enumpins (Pinenum): Enumerates interfaces by Ibasefilter query ienumpins.
Pinenum->next (..., pin): Queries the next Ipin interface through Ienumpins.

Pin->querypininfo (Pininfo): Gets the pin information through Ipin.

"Enumeration of mediatype"
Pin->enummediatypes (&mtenum): Enumerates interfaces by Ipin query ienummediatypes.
Mtenum->next (..., &MT): Queries the next am_media_type through Ienummediatypes.

Guidtostring (Mt->majortype): Converts the GUID of the Am_media_type to a string (for ease of output).

Release

CoUninitialize (): Releases the CoInitialize () initialized COM runtime environment.


Attach a relationship between the interfaces involved in the code:

It can be seen from top to bottom that the order is arranged as follows:

Icreatedevenum-->ienummoniker-->imoniker-->ibasefilter-->ienumpins-->ipin--> Ienummediatypes-->am_media_type


Source
/** * Simplest DirectShow information Display example * Simplest DirectShow info * * Lei hua Lei Xiaohua * [email protected] * Communication University/Digital TV Technology * COMMU Nication University of China/digital TV technology * http://blog.csdn.net/leixiaohua1020 * * This program is a piece of code to get DirectShow filter information. The * DirectShow filter information can be obtained through this code. Suitable for beginners to learn DirectShow. * * This code can is used to get Directshow Filter ' s information. * Suitable for the beginner of DirectShow. */#include "stdafx.h" #include <dshow.h> #include <atlconv.h> #define Output_pin 1#define Output_mediatype 1char* guidtostring (const GUID &guid) {int Buf_len=64;char *buf = (char *) malloc (Buf_len); _snprintf (Buf,buf_len, "{ %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X} ", GUID. Data1, GUID. Data2, GUID. Data3,guid. Data4[0], GUID. Data4[1],guid. DATA4[2], GUID. Data4[3],guid. DATA4[4], GUID. Data4[5],guid. DATA4[6], GUID. DATA4[7]);//printf ("%s\n", buf); return buf;} int _tmain (int argc, _tchar* argv[]) {uses_conversion;//Init comhresult hr=null;hr= CoInitialize (NULL); if (FAILED (HR)) { printf ("Error, Can not init COM. "); return-1;} printf ("===============directshow Filters ===============\n"); Icreatedevenum *psysdevenum = Null;hr = CoCreateInstance (Clsid_systemdeviceenum, NULL, Clsctx_inproc_server,iid_icreatedevenum, (void * *) &pSysDevEnum) ; if (FAILED (HR)) {return hr;} IEnumMoniker *penumcat = null;//category/************************************************************************ Friendly Name CLSID-------------------------------------------------------------------------Audio Cap Ture Sources Clsid_audioinputdevicecategoryaudio Compressors Clsid_audiocompressorcategoryau Dio renderers clsid_audiorenderercategorydevice Control Filters Clsid_devicecontrolcateg Orydirectshow Filters clsid_legacyamfiltercategoryexternal renderers Clsid_transmitcateg Orymidi renderers clsid_midirenderercategoryvideo Capture Sources Clsid_videoinputdEvicecategoryvideo Compressors CLSID_VIDEOCOMPRESSORCATEGORYWDM Stream decompression Devices CLSID_DVDHW DECODERSCATEGORYWDM streaming Capture Devices am_kscategory_capturewdm streaming Crossbar Devices am_kscategory_ CROSSBARWDM streaming Rendering Devices am_kscategory_renderwdm streaming tee/splitter Devices Am_kscategory_splitte RWDM streaming TV Audio Devices AM_KSCATEGORY_TVAUDIOWDM streaming TV Tuner Devices AM_KSCATEGORY_TVTUNERWDM Str Eaming VBI Codecs Am_kscategory_vbicodec ************************************************************************ /hr = Psysdevenum->createclassenumerator (clsid_videocompressorcategory, &penumcat, 0);//hr = pSysDevEnum-> Createclassenumerator (clsid_videoinputdevicecategory, &penumcat, 0);//hr = psysdevenum-> Createclassenumerator (clsid_audiocompressorcategory, &penumcat, 0);//hr = psysdevenum-> Createclassenumerator (clsid_audioinputdevicecategory, &penumcat, 0);//hr = PsysdeVenum->createclassenumerator (clsid_mediamultiplexercategory, &penumcat, 0);//hr = pSysDevEnum-> Createclassenumerator (clsid_legacyamfiltercategory, &penumcat, 0); if (hr! = S_OK) {psysdevenum->release (); return-1;} IMoniker *pmoniker = NULL; ULONG Monikerfetched;//filterwhile (Penumcat->next (1, &pmoniker, &monikerfetched) = = S_OK) {IPropertyBag * Ppropbag; VARIANT Varname;ibasefilter *pfilter;hr = pmoniker->bindtostorage (0, 0, iid_ipropertybag, (void * *) &ppropbag); if (FAILED (HR)) {pmoniker->release (); continue;} VariantInit (&varname), hr = Ppropbag->read (L "FriendlyName", &varname, 0);//"FriendlyName": the name of the device.//"Description": A Description of the Device.//filter info================printf ("[%s]\n", W2A (varname.bstrval )); VariantClear (&varname);//======================== #if output_pinhr = pmoniker->bindtoobject (null, NULL, IID_ Ibasefilter, (void**) &pfilter); if (!pfilter) {continue;} Ienumpins * pinenum = Null;ipin * pin = NULL; ULONG pinfetched = 0;if (FAILED (Pfilter->enumpins (&pinenum))) {pinenum->release (); continue;} Pinenum->reset ();//pin Infowhile (SUCCEEDED (Pinenum->next (1, &pin, &pinfetched)) && pinFetched {if (!pin) {continue;} Pin_info pininfo;if (FAILED (Pin->querypininfo (&pininfo))) {continue;} printf ("\t[pin]"), switch (pininfo.dir) {case pindir_input:printf ("dir:input \ t"); Break;case pindir_output:printf (" Dir:output \ t "); break;default:printf (" dir:unknown\n "); break;} printf ("name:%s\n", W2A (Pininfo.achname));//mediatype#if Output_mediatypeienummediatypes *mtenum=null;am_media_ TYPE *mt=null;if (FAILED (Pin->enummediatypes (&mtenum))) Break;mtenum->reset (); ULONG mtfetched = 0;while (SUCCEEDED (Mtenum->next (1, &AMP;MT, &mtfetched)) && mtfetched) {printf ("\t\t[ Mediatype]\n ");//videochar *mediatype_video_str=guidtostring (Mediatype_video);//audiochar *MEDIATYPE_Audio_str= Guidtostring (Mediatype_audio);//streamchar *mediatype_stream_str=guidtostring (MEDIAType_stream);//majortypechar *majortype_str=guidtostring (Mt->majortype);//subtypechar *subtype_str= Guidtostring (Mt->subtype);p rintf ("\t\t majortype:"); if (strcmp (MAJORTYPE_STR,MEDIATYPE_VIDEO_STR) ==0) {printf ( "video\n");} else if (strcmp (MAJORTYPE_STR,MEDIATYPE_AUDIO_STR) ==0) {printf ("audio\n");} else if (strcmp (MAJORTYPE_STR,MEDIATYPE_STREAM_STR) ==0) {printf ("stream\n");} else{printf ("other\n");} printf ("\t\t subtype guid:%s", subtype_str); free (mediatype_video_str); free (MEDIATYPE_AUDIO_STR); STREAM_STR), free (SUBTYPE_STR), free (MAJORTYPE_STR);p rintf ("\ n");} #endifpin->release ();} Pinenum->release ();p filter->release (), #endifpPropBag->release ();p moniker->release (); Penumcat->release ();p sysdevenum->release ();p rintf ("=================================================\n") ; CoUninitialize (); return 0;}


Run results
The results of the program run are as shown. It can be seen that the program prints out the DirectShow filter information in the system. The information for each filter contains information about its pin. The mediatype information in the PIN is also included in each pin.

You can control the type of the output filter information by defining the macro in the front of the code. Defined as "0" will not output the information for that class. as shown below.

#define Output_pin       1#define output_mediatype 1

Download
simplest DirectShow Example

SourceForge Project home: https://sourceforge.net/projects/simplestdirectshowexample/

cdsn:http://download.csdn.net/detail/leixiaohua1020/8348163


This program contains a sample program developed by DirectShow. Suitable for DirectShow beginners to learn.
It contains the following sub-programs:
Simplest_directshow_player: The simplest DirectShow-based video player.
Simplest_directshow_player_custom: The simplest DirectShow-based video player (custom).
Playergui: The simplest DirectShow-based player-graphical interface version.
Simplest_directshow_info: The simplest example of DirectShow information display.
Simplest_directshow_filter: Not yet completed.




=====================================================

The simplest list of sample articles based on DirectShow:

The simplest DirectShow-based example: Video player

Simplest DirectShow-based example: Video player graphical interface version

Simplest DirectShow-based example: Video Player custom version

Simplest DirectShow-based example: Get filter information

=====================================================

Simplest DirectShow-based example: Get filter information

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.