如何注册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, 静 ...
随机推荐
- wpf datagrid row height 行高自动计算使每行行高自适应文本
wpf 的datagrid的行高 要么是Auto,要么是定值:但会带来麻烦就是每行行高都一样. 当需要按内容(主要是wrap 换行的textbox或textblock)来动态调整行高的时候,需要用到d ...
- iOS-隐藏Navigationbar【导航栏无缝圆滑的隐藏】
1.ViewController .m - (void)viewDidLoad { [super viewDidLoad]; self.title = @"隐藏导航栏"; UIBu ...
- BZOJ 2741: 【FOTILE模拟赛】L [分块 可持久化Trie]
题意: 区间内最大连续异或和 5点调试到现在....人生无望 但总算A掉了 一开始想错可持久化trie的作用了...可持久化trie可以求一个数与一个数集(区间中的一个数)的最大异或和 做法比较明显, ...
- [LeetCode] 679. 24 Game(回溯法)
传送门 Description You have 4 cards each containing a number from 1 to 9. You need to judge whether the ...
- Thrift入门
简介 Thrift最初由Facebook研发,主要用于各个服务之间的RPC通信,支持跨语言,常用的语言比如C++, Java, Python, PHP, Ruby, Erlang, Perl, Has ...
- 在CentOS下安装crontab服务
1. 确认crontab是否安装: 执行 crontab 命令如果报 command not found,就表明没有安装 2. 安装 crontab 执行 yum install -y vixie-c ...
- 使用腾讯云“自定义监控”监控GPU使用率
欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 作者:李想 随着人工智能以及比特币的火热,GPU云服务的使用场景是越来越广,在很多场景下我们也需要获取GPU服务器的性能参数来优化程序的执行.目 ...
- 读书简记-java与模式
- CodeForces - 681A A Good Contest
咳咳,从今天开始,每天做一个英语题,不论简单还是难,坚持到下学期的省赛,希望能有效果. 这题就是判断是否能成为red,如果他超越的人里面有在比赛前分数达到2400,并且在比赛后分数上升,那么他就能成为 ...
- LOJ116 - 有源汇有上下界最大流
原题链接 Description 模板题啦~ Code //有源汇有上下界最大流 #include <cstdio> #include <cstring> #include & ...