|
[An update to this topic exists, look at the blog entry for November 3rd, and
8th]
I don't have any tutorial ready for this week because I have failed in my attempt
to write a DirectShow filter in C#. I didn't try "a frontal attack" on the problem
because MS mentioned that we shouldn't write these "for performance reasons". But
I thought I found a way to sneak in a filter in C# "through the back door" using DMOs.
A Direct Media Object (DMO) is a COM-object that implement the IMediaObject interface.
This interface has some twenty methods, many of them just returning state information. Most
samples (for DMOs) in the SDK used the ATL and I thought this might be a case of "using
an atomic bomb to kill an ant". Since the template code is short and simple, I thought
I might just as well implement the IMediaObject directly in C#.
The only restrictions on DMO, beside the IMediaObject requirement, is the ability
to support agregation and multi-threading. I wasn't sure about the last two but,
after checking the .Net documentation on the CCW, I thought the road ahead was clear.
So I implemented a DMO in C#, registered it with DMORegister and used the
DMOTest utility to verify that my interface was fine. Then I added its DMO wrapper
in the GraphEdit utility and try to render a file but all connections failed
on my DMO. After a few try, I wrote a small app to test it, and again, couldn't make
any connections. By debugging this app, I realized that the Filter Graph Manager starts
a least 4 threads and spits out different media types to my DMO, but then, my DMO's
method GetInputType or SetInputType blocked when it marshaled the media types and
the filter graph concludes that my DMO doesn't have any prefered types and failed
the connection attempt.
I don't think, but I might be wrong, that I have a deadlock situation. I believe,
at the moment, that the .Net runtime marshaling code takes too long and the filter
graph can't afford these kinds of delays. After all, the DirectShow runtime is just
an optimized streaming engine. I mentioned that I like the motto "Trust but verify",
now, I'm more willing to accept MS conclusions.
Where does this leave us? I doubt on the feasibility of a DirectShow filter purely
in C# but I might try to sprinkle just a zest of Managed C++. I'll keep you posted.
|