Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Wrap a Source Filter in another source filter

55 views
Skip to first unread message

Frankie Lai

unread,
Aug 5, 2008, 9:03:26 PM8/5/08
to
Hi,

I need to write a WDM driver for a IP camera in order to make it use as a
USB camera.

I had already got a source filter from the manufacturer that could read the
video stream from the IP CAM, however, it is a normal source filter that
would not realised by the conferencing software as devices.

I do not have the source code of such filter, however, i need to register it
in another category and make it an "Video Capture Source".

My plan is to wrap the manufacturer's filter inside my new source filter,
and register my new filter into the "Video Capture Source" category,
therefore, it should be detected as a device by the conferencing software
like MSN, skype, etc.

I am new to directshow, please provide me some idea or sample code if
possible.

Thank you so much!!!!

Frankie Lai
fra...@godsend.com.cn


The March Hare [MVP]

unread,
Aug 5, 2008, 9:15:48 PM8/5/08
to
On Wed, 6 Aug 2008 09:03:26 +0800, Frankie Lai wrote:

> My plan is to wrap the manufacturer's filter inside my new source filter,
> and register my new filter into the "Video Capture Source" category,
> therefore, it should be detected as a device by the conferencing software
> like MSN, skype, etc.
>
> I am new to directshow, please provide me some idea or sample code if
> possible.

See the sample by Vivek on my Downloads page.

In order to wrap the other source filter, you will likely need to create a
separate graph inside your filter

[ Camera manufacturer filter ] -> [ Custom Renderer ( could be based on
Dump filter sample )]

Feed the samples from this graph into your custom video capture filter via
a FIFO queue using a CCritSec to protect access.

--
Please read this before replying:
1. Dshow & posting help: http://tmhare.mvps.org/help.htm
2. Trim & respond inline (please don't top post or snip everything)
3. Benefit others: follow up if you are helped or you found a solution

Alessandro Angeli

unread,
Aug 5, 2008, 9:19:32 PM8/5/08
to
From: "Frankie Lai"

> I need to write a WDM driver for a IP camera in order to
> make it use as a USB camera.
>
> I had already got a source filter from the manufacturer
> that could read the video stream from the IP CAM,
> however, it is a normal source filter that would not
> realised by the conferencing software as devices.
> I do not have the source code of such filter, however, i
> need to register it in another category and make it an
> "Video Capture Source".

Well, why don't you just try creating the necessary registry
keys and see if the filter wirks? You need to call
IFilterMapper2::RegisterFilter() with the information of the
filter (you do not need to register the pins in REGFILTER2).

> My plan is to wrap the manufacturer's filter inside my
> new source filter, and register my new filter into the
> "Video Capture Source" category, therefore, it should be
> detected as a device by the conferencing software like
> MSN, skype, etc.

Inside your wrapping filter, create a graph where you insert
the actual source connected to a SampleGrabber. In the
sample callback, get a buffer from your allocator, copy the
sample to it (including flags and timestamps) and deliver
it.

If you want to write more efficient code that avoids the
copy, write a custom sink to use in place of the
SampleGrabber and use the external downstream allocator as
the allocator of the sink's input pin, so that the actual
source will write directly to the externally allocated
sample. When your sink receives a sample, it simply delivers
downstream in the external graph.

--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm


Shugo_Ishida

unread,
Aug 5, 2008, 11:02:05 PM8/5/08
to
"Frankie Lai" <fra...@godsend.com.cn> wrote in message news:uDS48A29...@TK2MSFTNGP04.phx.gbl...

> Hi,
>
> I need to write a WDM driver for a IP camera in order to make it use as a
> USB camera.
>
> I had already got a source filter from the manufacturer that could read the
> video stream from the IP CAM, however, it is a normal source filter that
> would not realised by the conferencing software as devices.
>
> I do not have the source code of such filter, however, i need to register it
> in another category and make it an "Video Capture Source".

Probably, I think that you have only to modify the categoly of the source filter on registry. Follow steps below.

1. Register the source filter with Regsvr32.exe.
2. Export the filter information to a .REG file on registry then delete it.
3. Modify a category in the .REG file.

[HKEY_CLASSES_ROOT\CLSID\{Filter Categoly GUID}\Instance\{Source Filter GUID}]
^
Modify here.

"Video Capture Sources Category" GUID is {860BB310-5D01-11d0-BD3B-00A0C911CE86}

4. Import the .REG file.

You can do those steps above with Reg* WIN32APIs.

Frankie Lai

unread,
Aug 6, 2008, 2:31:05 AM8/6/08
to
Thanks a lot~~

> See the sample by Vivek on my Downloads page.

> [ Camera manufacturer filter ] -> [ Custom Renderer ( could be based on
> Dump filter sample )]

I downloaded your example already, and i am going to have a look on dump
filter first.

By the way, i have another question about your sample source filter.

The sample source filter works perfectly under MSN, skype's video meeting as
a video device. However, when i try to do the same thing with Flash Player's
video meeting, it crashes the IE.

Which part should i take care with if i use the code as the skeleton of my
source filter, and wishing it could be use under messengers's video, also
web based Flash Player's one?

Frankie


Frankie Lai

unread,
Aug 6, 2008, 2:31:55 AM8/6/08
to
Hi, thank you for your instructions.

> Inside your wrapping filter, create a graph where you insert the actual
> source connected to a SampleGrabber. In the sample callback, get a buffer
> from your allocator, copy the sample to it (including flags and
> timestamps) and deliver it.

Although I was also focused on the SampleGrabber, but i have no idea of the
workflow before your reply. You save me lots of time, thank you for showing
me a solid way.
I have to read some docs on doing it, hope it works, haha.

> Well, why don't you just try creating the necessary registry keys and see
> if the filter wirks?

The registry thing is not suitable for my case, since the filter is not much
configurable, the url of the ip cam have to be sent to the filter in
programming way...:(


I will try on SampleGrabber way you mentioned, thanks!!!

Frankie


Frankie Lai

unread,
Aug 6, 2008, 2:41:41 AM8/6/08
to
Thanks for your instructions, however the filter i have could not use directly since the url of the ip cam is needed to input by coding but not in a config way.

Thus I know more about the filter's registry structure now, Thank you!!


"Shugo_Ishida" <syu5...@nospam.nospam> 写入消息新?:72BA078C-B94D-4AEA...@microsoft.com...

Frankie Lai

unread,
Aug 6, 2008, 2:53:29 AM8/6/08
to
The filter i have could not use directly since the IP cam's url has to be
input by coding but not in a configurable way.

Thanks for your instructions, I've learn more about the filter's registry
now. :)

Frankie

"Shugo_Ishida" <syu5...@nospam.nospam>
??????:72BA078C-B94D-4AEA...@microsoft.com...

Roman Ryl...

unread,
Aug 6, 2008, 6:43:36 AM8/6/08
to
Hi,

Wouldn't it be the easiest solution to create a new COM class for new
filter which would embed original filter through COM aggregation? No
second graph embedded, no sample grabber and stuff.

Roman

Frankie Lai

unread,
Aug 6, 2008, 11:04:01 AM8/6/08
to
Hi Roman,

It sounds great, but i am newbie in COM, could you tell me where could i get
a good sample code of COM aggregation for my situation?

Frankie


"Roman Ryl..." <ryl...@gmail.com>
??????:fd751e51-e983-4195...@c65g2000hsa.googlegroups.com...

Alessandro Angeli

unread,
Aug 6, 2008, 11:46:51 AM8/6/08
to
From: "Frankie Lai"

> It sounds great, but i am newbie in COM, could you tell
> me where could i get a good sample code of COM
> aggregation for my situation?

Your filter simply calls CoCreateInstance() to create the
aggregated filter passing its own IUnknown as pUnkOuter and
in your NonDelegatingQueryInterface() you return interfaces
on the aggregated filter but for IUnknown. However,
depending on the behavior and implementation of the filter,
it may or may not work correctly because filters spawn
sub-objects (pins and allocators).

The March Hare [MVP]

unread,
Aug 6, 2008, 1:54:52 PM8/6/08
to
On Wed, 6 Aug 2008 14:31:55 +0800, Frankie Lai wrote:

> The registry thing is not suitable for my case, since the filter is not much
> configurable, the url of the ip cam have to be sent to the filter in
> programming way...:(

Also, it may break other applications or violate the license agreement for
the web cam's software.

The March Hare [MVP]

unread,
Aug 6, 2008, 1:57:01 PM8/6/08
to
On Wed, 6 Aug 2008 14:31:05 +0800, Frankie Lai wrote:

> By the way, i have another question about your sample source filter.

It is not my filter, it is Vivek's as I wrote in my original reply.

> Which part should i take care with if i use the code as the skeleton of my
> source filter, and wishing it could be use under messengers's video, also
> web based Flash Player's one?

Maybe Vivek or someone else who is familiar with this can comment. Or you
can run the filter in the debugger and see where it's crashing.

The March Hare [MVP]

unread,
Aug 6, 2008, 2:18:14 PM8/6/08
to
On Wed, 6 Aug 2008 23:04:01 +0800, Frankie Lai wrote:

> It sounds great, but i am newbie in COM, could you tell me where could i get
> a good sample code of COM aggregation for my situation?

I have never seen a working implementation of this technique. However
there has been discussion of it a number of times in the past:

http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/search?group=microsoft.public.win32.programmer.directx.video&q=com+aggregation

Personally, I would choose the technique I mentioned in my original post.

Roman Ryl...

unread,
Aug 6, 2008, 4:50:51 PM8/6/08
to
Frankie,

> > Wouldn't it be the easiest solution to create a new COM class for new
> > filter which would embed original filter through COM aggregation? No
> > second graph embedded, no sample grabber and stuff.
>

> It sounds great, but i am newbie in COM, could you tell me where could i get
> a good sample code of COM aggregation for my situation?

COM aggregation is a bit too complex topic for a COM newbie but this
way is a lot lot easier than any other solutions mentioned. It will
however work stable provided that your IP camera filter was compiled
with support for COM aggregation.

If the original filter does not support COM aggregation, then it is
still possible to wrap with a new COM class implementing some of the
interfaces and forwarding COM calls but this requires more work, it
less stable ("may or may not work" mentioned by Alessandro Angeli) and
can only be recommended is the filter is used entirely in your own
application and use scenarios are known in advance. This is however
not for a COM newbie.

You can find a sample demo project wrapping File Source (Async) Filter
and streaming clock.avi through a new filter registered under Video
Capture Sources here http://alax.info/blog/wp-content/uploads/2008/08/directshowwrappersourcefiltersample01.zip

Roman

0 new messages