如何注册Filter
AX文件的一个对外接口DllRegisterServer,由外部调用,比如注册AX的时候:regsvr32 xxx.ax
通常情况下,我们的filter可能注册在”Direct Show”目录下,那么直接调用
// Creates registry entries for the DLL
STDAPIDllRegisterServer()
{
return AMovieDllRegisterServer2(TRUE);
}
AMovieDllRegisterServer2在DX的帮助文档内的说明如下:
The AMovieDllRegisterServer2 函数为g_Templates 数组中的每个组件创建注册入口. 然而这个函数有一些限制,
首先,它给每个filter分配“DirectShow Filters”分类(CLSID_LegacyAmFilterCategory), 但是不是每个filter都属于这个分类. 比如Capture filters and compression filters,有他们自己的分类.
第二,如果你的fitler支持一个硬件设备,你可能需要去注册两个增加AMovieDLLRegisterServer2 没有处理的信息pieces,: the medium and the pin category. A medium defines a method of communication in a hardware device, such as a bus. The pin category defines the function of a pin. For information on mediums, see KSPIN_MEDIUM in the Microsoft Windows Driver Development Kit (DDK). For a list of pin categories, see Pin Property Set.
如果我们的引擎需要注册到DirectShow之外的目录,又该如何做?
// 注册Filter到Video Compressor
REGFILTER2 rf2FilterReg =
{
1, // Version 1 (no pin mediums or pin category).
MERIT_NORMAL, // Merit.
1, // Number of pins.
&sudPins // Pointer to pin information.
};
//为DLL创建注册入口
STDAPI DllRegisterServer(void)
{
HRESULT hr = E_FAIL;
IFilterMapper2 *pFM2 = NULL;
hr = AMovieDllRegisterServer2(TRUE); // 这个还是要调用的
if (FAILED(hr)) return hr;
hr = CoCreateInstance(CLSID_FilterMapper2, NULL,
CLSCTX_INPROC_SERVER,
IID_IFilterMapper2, (void **)&pFM2);
if (FAILED(hr)) return hr;
hr = pFM2->RegisterFilter(CLSID_SomeFilter, // Filter CLSID.
g_wszName, // Filter name.
NULL, // Device moniker.
&CLSID_VideoCompressorCategory, // Video compressor category.
g_wszName, // Instance data.
&rf2FilterReg // Pointer to filter information.
);
pFM2->Release();
return hr;
}
注销Filter
注销DirectShow内的引擎
// Removes registry entries for the DLL
STDAPI DllUnregisterServer()
{
return AMovieDllRegisterServer2(FALSE);
}
注销指定目录下的引擎
// 注销Video Compressor下的引擎
// Removes registry entries for the DLL
STDAPI DllUnregisterServer()
{
HRESULT hr = E_FAIL;
IFilterMapper2* pFM2 = NULL;
hr = AMovieDllRegisterServer2(FALSE);
if (FAILED(hr)) return hr;
hr = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
IID_IFilterMapper2, (void **)&pFM2);
if (FAILED(hr)) return hr;
hr = pFM2->UnregisterFilter(&CLSID_VideoCompressorCategory,
g_wszName, CLSID_SomeFilter);
pFM2->Release();
return hr;
}
给Filter起个名字
// Pin的type分为Major Type 和 Subtype
// 比如,Major Type = Video, Subtype = MPEG-2
const AMOVIESETUP_MEDIATYPE sudPinTypes =
{
&MEDIATYPE_NULL, // Major type
&MEDIASUBTYPE_NULL // Subtype
};
const AMOVIESETUP_PIN psudPins[] =
{
// 定义Input Pin的信息
{
L"Input", // String pin name
FALSE, // Is it rendered
FALSE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
0 // Connects to pin
1, // Number of types
&sudPinTypes
}, // The pin details
{
L"Output", // String pin name
FALSE, // Is it rendered
TRUE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
0, // Connects to pin
1, // Number of types
&sudPinTypes // The pin details
}
};
// Declare filter information
const AMOVIESETUP_FILTER sudFilter =
{
&CLSID_MPKiller, // Filter CLSID
L"HQ MP Killer", // Filter name
0x8800000, // Its merit
2, // Number of pins
psudPins // Pin details
};
// declare a global array of CFactoryTemplate class instances, named g_Templates. Each
// CFactoryTemplate class contains registry information for one filter. Several filters can
// reside in a single DLL; simply include additional CFactoryTemplate entries. You can
// also declare other COM objects, such as property pages
// 在同一个DLL或者AX内,可以有多个引擎,比如系统目录下的quartz.dll。
// 所以,如果有多个引擎,相应的数组的大小就是引擎的个数。
CFactoryTemplateg_Templates[] =
{
{
L"HQ MP Killer",
&CLSID_MPKiller,
CImplement::CreateInstance,
NULL,
&sudFilter
}
};
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]); // 有几个引擎
允许Filter应用
// CreateInstance 是CFactory的一个接口,在Filter内部实现它
CUnknown* WINAPI CImplement::CreateInstance( LPUNKNOWN pUnk,
HRESULT *pHr)
{
CImplement *pFilter = new CImplement ();
if (!pFilter)
{
*pHr = E_OUTOFMEMORY;
}
return pFilter;
}
Filter的Merit
Graph 会使用“傻子”机制联接不同的filter,这就要通过filter的merit值的高低进行“傻子”联接。
该联接要使用IFilterMapper2::EnumMatchingFilters方法。
Merit:
enum
{
MERIT_PREFERRED = 0x800000,
MERIT_NORMAL = 0x600000,
MERIT_UNLIKELY = 0x400000,
MERIT_DO_NOT_USE = 0x200000,
MERIT_SW_COMPRESSOR = 0x100000,
MERIT_HW_COMPRESSOR = 0x100050
};
<= MERIT_DO_NOT_USE的Merit的Filter,系统是不会去“傻子”联接的。当然Merit值可以是任意值,而不一定是枚举出来的。
确定Filter的用途
不同的Filter有不同的用途,可以选择不同的基类,实现不同的方法。详见DirectX 文档。Filter的种类,在内进行了详细的描述root\DirectShow\DirectShow Reference\Constants and GUIDs\Filter Categories。
添加属性页
CFactoryTemplateg_Templates[2] =
{
{
g_wszArcIPCam, // Name
&CLSID_ArcIPCam, // CLSID
CArcIPCam::CreateInstance, // Method to create an instance of MyComponent
NULL, // Initialization function
&sudArcIPCamSourceFilter // Set-up information (for filters)
},
{
// 这些数据,为属性页准备
g_wszArcIPCamProperty,
&CLSID_ArcIPCamProperty,
CArcIPCamProperty::CreateInstance
}
};
class CArcIPCam : public xxx, public IArcIPCam, public ISpecifyPropertyPages
{
private:
// Constructor is private because you have to use CreateInstance
CArcIPCam(IUnknown *pUnk, HRESULT *phr);
~CArcIPCam();
CArcIPCamPin *m_pPin;
public:
static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
DECLARE_IUNKNOWN;
// Property Page---
STDMETHODIMP GetClassID(CLSID *pClsid);
// Basic COM - used here to reveal our property interface.
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
// return our property pages
STDMETHODIMP GetPages(CAUUID * pPages);
}
这三个函数必须实现。
如何注册Filter的更多相关文章
- Spring boot 注册Filter , Listener, Servlet
1: ServletRegistrationBean Servlet @Bean public ServletRegistrationBean myServlet(){ ServletRegist ...
- spring-boot-2.0.3源码篇 - filter的注册,值得一看
前言 开心一刻 过年女婿来岳父家走亲戚,当时小舅子主就问:姐夫,你什么时候能给我姐幸福,让我姐好好享受生活的美好.你们这辈子不准备买一套大点的房子吗?姐夫说:现在没钱啊!不过我有一个美丽可爱的女儿,等 ...
- 18. Spring Boot 、注册Servlet三大组件Servlet、Filter、Listener
由于SpringBoot默认是以jar包的方式启动嵌入式的Servlet容器来启动SpringBoot的web应用,没有web.xml文件 public class MyServlet extends ...
- SpringBoot注册Servlet、Filter、Listener
SpringBoot默认是以jar包的方式启动嵌入式的Servlet容易来启动SpringBoot的Web应用,没有web.xml文件 因此我们可以使用以下方式来注册Servlet.Filter.Li ...
- SpringBoot注册Servlet/Filter/Listener
由于SpringBoot默认是以jar包的方式启动嵌入式的Servlet容器来启动SpringBoot的web应用,那么没有web.xml文件,如何配置我们的三大Web基础组件呢? 通过使用XXXRe ...
- Spring Boot 2.X(十):自定义注册 Servlet、Filter、Listener
前言 在 Spring Boot 中已经移除了 web.xml 文件,如果需要注册添加 Servlet.Filter.Listener 为 Spring Bean,在 Spring Boot 中有两种 ...
- Spring Boot 自定义注册 Servlet、Filter、Listener
前言 在 Spring Boot 中已经移除了 web.xml 文件,如果需要注册添加 Servlet.Filter.Listener 为 Spring Bean,在 Spring Boot 中有两种 ...
- Filter(过滤器)学习
一.Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态 ...
- Filter
一.Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有 web资源:例如Jsp, Servlet, 静 ...
随机推荐
- Apache 配置SSI速记
1. 启用模块 httpd.conf LoadModule filter_module modules/mod_filter.so 2. <Directory 的Options配置中增加Incl ...
- 通过SMTP发送邮件的Python代码
贴上一段用Python开发的发送邮件程序 #coding=UTF-8 import smtplib from email.mime.text import MIMEText smtp_host=&qu ...
- Go笔记-继承
[Go中继承的实现] 当一个匿名类型被内嵌在结构体中时,匿名类型的可见方法也同样被内嵌,这在效果上等同于外层类型 继承 了这些方法:将父类型放在子类型中来实现亚型 package main i ...
- Codeforces 250 E. The Child and Binary Tree [多项式开根 生成函数]
CF Round250 E. The Child and Binary Tree 题意:n种权值集合C, 求点权值和为1...m的二叉树的个数, 形态不同的二叉树不同. 也就是说:不带标号,孩子有序 ...
- 听说你开发.NET还在用VS,小哥哥给你推荐全平台的Rider
本文地址:http://www.cnblogs.com/likeli/p/8461010.html 前言 .NET平台的开发一直都只能使用Visual Studio来开发,自从dotnet core ...
- LeetCode - 492. Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a speci ...
- 单用户模式与救援模式:linux学习第三篇
单用户模式 1. 重新启动,在下列界面选项第一项按 e 按e后进入此grub界面(启动工具) 2. 找到linux16所在行,将'ro'(只读)修改为'rw'(读写),并加上 in ...
- Sublime Text3 快捷键汇总及设置快捷键配置环境变量
Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的文本进行同时编辑)Ctrl+G 跳转到相应的行Ctrl+J 合并行(已选择需要合并的多行时)Ctrl+L 选择整行(按住-继续选择下 ...
- dnsmasq 做 DHCP 服务器
/etc/dnsmasq.conf #DNS服务器的地址,就是我的热点的地址 listen-address=192.168.1.1 #设置DHCP分配的地址范围和时间 dhcp-range=192.1 ...
- zabbix-agent 启动不起来
遇到一个问题 zabbix-agent 一直启动不起来 查看Zabbix Agent日志文件才究其原因. tail /var/log/zabbix/zabbix_agentd.logzabbix_a ...