I have created a push source filter using Delphi 6 Pro and the DSPACK DirectShow component library. I want to use the filter privately so I will not be creating an AX file for a DLL. Instead I want to create the Filter directly. I found some threads on this but neither of them show how to construct a private Filter given the filter's constructor's:
constructor Create(ObjName: string; Unk: IUnKnown; out hr: HRESULT);
constructor CreateFromFactory(Factory: TBCClassFactory; const Controller: IUnknown); override;
Here are some threads I found on the subject of unregistered or private DirectShow filters:
http://www.gdcl.co.uk/2011/June/UnregisteredFilters.htm
http://www.progdigy.com/forums/viewtopic.php?p=12304&sid=df52f07f5b00d7ebfac12cb9b9bd9b54
How can I directly embed a DirectShow Push Source filter in an EXE?
The Filter's source code has been directly added to my Delphi project. But I don't know which Constructor I should use when creating the Filter directly from my main application, and what to pass for the Constructor's parameters. Can someone tell me what they should be?
Also, do I need to increment the Filter object's reference count like the first thread says to do above and then call Release() on it later when my application terminates? If so, what is the best way to do this? Or can I just call Free on the Filter when my application terminates?
Finally, do I need to call CoInitialized() and CoUninitialize() before using my private filter?
UPDATE: Tracing through the classes and the class hierarchy constructor chain for TBCSource, the base class for DSPACK derived filters, it appears that the ObjName parameter is the Filter name and the Unk parameter is the object that owns the filter. My current guess is that the correct way to create the Filter directly from source would be, given a TBCSource derived class named TPushSourceFilter that is arbitrarily given the filter name 'My Push Source Filter', for example purposes:
TPushSourceFilter.Create('My Push Source Filter', nil, hr);
The first constructor parameter is the Filter name that is used to register the filter, that is, the one you see when perusing DirectShow filters in a tool like GraphEdt. I believe the second parameter should be NIL because it resolves to an owner data field (FOwner) in the ancestor class named TBCUnknown. It's sole purpose is to redirect any QueryInterface() calls handled by the base class to the owner object if it is non-NIL instead of applying the query directly to the Filter object in case it's a delegate situation. I will go ahead with this construction method and see if it works.
All you need is an instance of the object
TPushSourceFilter.Create
and obtainIBaseFilter
interface from this instance. From there on you add it to the graph just the same way as you do with filters created byCoCreateInstance
, then connect pins etc.