使用程序 AND 过滤器源代码公开 directshow 过滤器属性示例
我试图找到一个示例,其中可以通过过滤器属性页控制的参数具有公开的 getter/setter,以便在不加载属性页的情况下,生成图形的父程序可以更改过滤器属性。
windows sdk 中的 Ezrgb24 有一个工作属性页,但我不知道如何公开属性页中使用的函数,以便我的程序可以直接访问它们,而无需初始化属性页本身。我浏览了《Programming Microsoft Directshow》一书,发现它通过了 YUVGray 示例过滤器,并提到可以公开所使用的颜色,以便图形的父程序可以更改它们,但没有给出如何更改它们的示例。
同时,来自 directshow.net 的示例(如 Windows sdk 示例)似乎仅包含过滤器或仅包含程序源,并且我没有看到任何直接公开此类属性的示例过滤器。但像 BitmapMixer 这样的示例会调用 IVMRMixerBitmap9.SetAlphaBitmap,这是 VMR9 的接口。我想要一个示例,它为我提供了类似接口和过滤器的代码,以便我可以了解它们之间的关系,以及该程序,以便我可以了解应如何设置我的环境以利用该接口。
我猜这是使用 COM 的基本练习,但我真的想要一个包含所有源代码的完整示例,以便我可以完全理解所有内容是如何连接的。即使暴露的属性被简单地使用,它也足以成为一个骨架。我错过了什么地方有这样的例子吗?我使用 C# 编写该程序,但一直在使用 directshow.net,并且可以设置和运行任何图形,因此 C++ 程序就可以了。
I'm trying to find an example where a parameter that could be controlled through the filter property page has an exposed getter/setter so that, without loading the property page, the filter property can be changed by the parent program that generated the graph.
Ezrgb24 from the windows sdk has a working property page, but I don't see how to expose the functions used in the property page so that my program can access them directly without initalizing the property page itself. I looked through the Programming Microsoft Directshow book and saw that it goes through the YUVGray example filter and mentions that the colors used could be exposed so that the parent program of the graph could change them, but does not give an example how.
Meanwhile, samples from directshow.net, like the windows sdk samples, appear to include only the filter or only the program source, and I didn't see any example filter that has such properties directly exposed. But examples like the BitmapMixer call IVMRMixerBitmap9.SetAlphaBitmap, an interface for VMR9. I'd like a sample that gives me the code for a similar interface and the filter so I can see how they are related, and the program so I can see how my environment should be set up to utilize the interface.
I'm guessing this is a basic exercise in utilizing COM, but I really would like a complete example with all of the source so I can fully understand how everything is connected. Even if the exposed property is trivially used it would be enough of a skeleton to go on. Is there such an example somewhere that I missed? I'm in C# for the program but have been using directshow.net and can get any graph set up and running, so a C++ program would be fine.
好的,我们开始吧:
我们将使用 ezrgb24 过滤器示例,该示例来自 Windows sdk 附带的示例,因为它是免费且开源的。它还已经定义了这一侧的接口。请参阅该接口的 iez.h 文件,具体来说,我们会注意到该文件中的两件事:
1) 我们的 GUID 是 fd5010a3-8ebe-11ce-8183-00aa00577da1 - 我们需要在 C# 端的代码中使用它
2) 我们公开了 ezrgb24.cpp 文件中定义的 get_IPEffect 和 put_IPEffect 函数
因此,这方面的所有工作都已经为我们完成,它让我们很好地了解了如何公开我们自己的函数。
现在在我们的 C# 程序中,我们将创建一个适应这种情况的接口:
请注意,Guid 是相同的,并且我们公开的函数与过滤器代码中定义的内容相匹配(当 C++ 函数时,您可以只使用 [Out]要求一个指针,在这种特定情况下请记住 ezrgb24 中的 REFTIME 只是 double 类的另一个名称)。
这就是开始使用该界面所需的全部内容。
例如,假设我使用 directshow.net 创建一个图形,并创建一个 ezrgb24 过滤器的实例(快速而肮脏 - 在使用 regsvr32.exe 注册我编译的 ezrgb24 dll 后,我只是在 GraphEdit 中查找名字并以这种方式添加它)。我将在图表中使用的 ezrgb24 过滤器的实例称为
IEfilter
。我将其添加到图表中并像往常一样连接引脚。
然后我可以在任何时候使用我定义的接口类来更改过滤器的属性,而不需要重新启动图形或打开属性页:
就是这样。我希望这可以帮助任何寻求公开和访问过滤器属性的完整图片的人!
Alright here we go:
We'll be using the ezrgb24 filter example that comes out of the samples that ship with the windows sdk because it's free and open source. It also already has the interface on this side defined. See the iez.h file for the interface, specifically we'll note two things from this file:
1) Our GUID is fd5010a3-8ebe-11ce-8183-00aa00577da1 - we'll need that for the code in the C# side
2) we're exposing the get_IPEffect and put_IPEffect functions which are defined in the ezrgb24.cpp file
So all the work on that side has already been done for us, and it gives us a good idea of how to make our own functions to expose.
Now in our C# program, we're going to make an interface that adapts to this:
Notice that the Guid is the same and our exposed functions match what is defined inside the filter's code (you can just use [Out] when the C++ function asks for a pointer, in this specific case remember that REFTIME in ezrgb24 is just another name for the double class).
That is all you need to start using the interface.
For example, say I create a graph with directshow.net and make an instance of the ezrgb24 filter (quick and dirty - after registering my compiled dll of ezrgb24 with regsvr32.exe, I just looked up the moniker in GraphEdit and added it that way). I called the instance of the ezrgb24 filter that I was using in my graph
IEfilter
.I add it to my graph and connect the pins as usual.
Then I can use the interface class I defined as follows at any point to change the properties of the filter, without any need to restart the graph or bring up the property page:
And that's it. I hope this helps anyone looking for a complete picture of exposing and accessing filter properties!