如何注册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, 静 ...
随机推荐
- C#基础拾遗系列之一:先看懂IL代码
一.前言 首先,想说说为什么要写这样系列的文章,有时候在和同事朋友聊天的时候,经常会听到这样的话题: (1)在这家公司没什么长进,代码太烂,学不到东西.(你有没有想想框架为什么这样写,代码还可以怎么去 ...
- Why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit Deprecated ?
Thread.stop, Thread.suspend, Thread.resume被标记为废弃的方法.在查看JDK的文档时,提到了下面的参考文章,先是英文版,接着是中文翻译. Why is Thre ...
- 洛谷 [P2701] 巨大的牛棚
首先,本题是一道最大子矩阵问题,且m,n较小,可以使用DP做, 与 洛谷 [P1387]最大正方形 做法相同. #include <iostream> #include <cstdi ...
- BZOJ 4537: [Hnoi2016]最小公倍数 [偏序关系 分块]
4537: [Hnoi2016]最小公倍数 题意:一张边权无向图,多组询问u和v之间有没有一条a最大为a',b最大为b'的路径(不一定是简单路径) 首先想到暴力做法,题目要求就是判断u和v连通,并查集 ...
- [Lucas定理]【学习笔记】
Lucas定理 [原文]2017-02-14 [update]2017-03-28 Lucas定理 计算组合数取模,适用于n很大p较小的时候,可以将计算简化到小于p $ \binom{n}{m} \m ...
- python语言基础汇总
注释 代码中添加注释是一个良好的编程习惯,python语言的注释才用井号'#'作为注释开头的,可以是任意内容,解释器会忽略掉这部分内容.其他每一行都是语句,当语句以冒号':'结尾时,缩进的语句视为代码 ...
- ------ 解析因内核栈溢出导致的 “double fault” 蓝屏 ------
-------------------------------------------------------------------------- 前一篇指出 tail_recursivef_fac ...
- 升级 phpStudy 中 MySQL 版本至 5.7.17
由于本地用的集成环境是 phpStudy 2016,没有找到升级 MySQL 版本的选项,所以自己升级一下. 从官网上下载高版本的 MySQL :https://dev.mysql.com/dow ...
- zabbix邮件报警设置
第一.安装邮件发送工具mailx 这里我选择的是mailx,所以的关闭其他的邮件发送工具 service sendmailstop #关闭 chkconfig sendmailoff #禁止开机启 ...
- PHP读取大文本文件并处理数据的思路
//处理文件 $file = fopen($filename, "r") or exit("Unable to open file!"); $total_lin ...