| Follow up on DMOs in C# |
|
[An update to this topic exists, look at the blog entry for November 3rd, and 8th] In a previous entry, I mentioned some of the difficulties one encounter when you try to implement a DMO in C#. Looking at my earlier code, I told myself I should try to minimize all managed/native transitions. While Marshal.PtrToStructure and Marshal.StructureToPtr works, they seem to create problems in sections of code which are time-critical. So I learned to appreciate Marshal.Read* and Marsha.Write* for their efficiency, but they are tedious and error-prove to use since you read and write using offsets. I have managed to get the pins connected on my DMO, but then I met a road block that encourage me to give up on this attempt. The IMediaObject.ProcessOutput is passed an array of DMO_OUTPUT_DATA_BUFFER and the first element of that struct is an IMediaBuffer interface pointer. Marshal.GetObjectforIUnknow might have worked (but then I've learned to be suspicious of marshalling complete object with the DirectShow runtime). So I tried a custom marshaler (did no good), then I wrote a C dll with a single function to return the address of the buffer and length (which is provided through the IMediaBuffer interface). But I still needed to use PInvoke on the the dll to call my function from C# and once again I ran into troubles. When I tried to render the output pin of my DMO in GraphEdit (i.e. right-click the pin and select Render), the operation was rarely succesfull on the first attempt but usually on the second or third attempt. Similarly, in my test app, if I ran it normally the connection failed but if I step through the code with the debugger the connection was made. I concluded that the Just-In-Time compilation of .Net is not well suited for DirectShow. I tried to ngen the assembly and it didn't do any good (this was not my first attempt with ngen, it seems only MS with many framework's assemblies managed to get a lot of mileage out of this utility). All in all, I've improved my interop skills and I learned a few tricks about how to improve the efficiency of .Net code but my tutorial "the Final Frontier" is probably really the end of the road for using DirectShow from a .Net langage.
|
| < Prev | Next > |
|---|











