Search code examples
videocameradirectshowcapturesource-filter

DShow source filter: which instance of filter am I?


I have a custom source filter, made by implementing CSource and CSourceStream from the dshow baseclasses. It is exported multiple times using the IFilterMapper2::RegisterFilter method, under different names. Now, in my filter I'd like to know (as soon as possible) which registered instance of the filter it is that is being opened. For example, suppose I have a dll that emulates a virtual webcam. The same dll exports two instances of the filter, so that in (say) Skype I can select virtual cam #1 and virtual cam #2. In the constructor of either my CSource or CSourceStream I'd like to know whether it is virtual cam #1 or virtual cam #2 that is being constructed. Can this be done?


Solution

  • There is no documented way, but there is a workaround. Since DirectShow is stable it should be working nicely.

    In your filter class override IPersistPropertyBag::Load and the reads that you do with provided IPropertyBag::Read map to registry read from HKEY_LOCAL_MACHINE\SOFTWARE\Classes...\CLSID_VideoInputDeviceCategory\Instance\<your-instance>. So you can put all identification you need right there and have it accessible.

    Note this is called from application's BindToObject call.

    Call Stack

    I am doing this in virtual video input backed by IP cameras http://alax.info/blog/1233