| A Jukebox sample in C# (version 2) |
|
|
|
|
In version 2 of the Jukebox sample, we'll look at different ways to access DirectShow functionality from C#. In the previous version, we used an interop assembly generated from the DirectShow quartz.dll. We've looked at how to accomplish common tasks with this interop assembly. While using this interop assembly is probably the easiest way to use DirectShow from C#, it has limitations. For example, I have included a "Frame Step" button on the Jukebox form, but we can't use it because we don't have access to the IVideoFrameStep interface from the interop assembly. There is a least two different ways out of this dilemma. We can use an open-source wrapper, DirectShowLib, instead of the interop assembly generated from quartz.dll. Or we can create our own assembly from the idl files provided in the DirectX "include" directory. In this tutorial, we'll look at the first alternative. We have provided a zip file which contains the source code for this version. It is similar to the zip file from the previous version but we have included the DirectShowLib.dll instead of the interop assembly generated from VS (or the utility tlbimb.exe). We have to add a new using statement, at the beginning:
The code for the different objects and iterfaces becomes:
graphBuilder is now an interface and we add another interface for IVideoFrameStep. InitInterfaces becomes:
InitInterfaces creates a FilterGraph object and we access its IGraphBuilder interface as our graphBuilder member variable. When we want to play a file we call:(where fName is the file name)
Now, RenderFile takes two arguments because the DirectShowLib wrapper mimic as closely as possible the "native" DirectShow interfaces. Similarly, the code for the seeking functionality becomes:
Instead of using -1, we can use OABool.True since DirectShowLib provides many definitions for the structures and constants of DirectShow. And the IMediaPosition method CanSeekBackward and CanSeekForward are defined as returning an OABool in its first parameter. Now, we can check for the ability to step from frame to frame using:
The rest of the code to load a file is similar to the one used in the first version of the Jukebox sample except that the method calls has a more "COM-like" flavor. (I haven't removed the constants for the Window styles but I could have used the definitions provided in the DirectShowLib). The code to get out of the loop in OnGraphNotify is also closer to the original COM code from the SDK.
The handler to process stepping from one frame to the other is given by:
Clearly, you have to remember to hook the handler in the Button.Click event. Then, the handler just pause the graph and call the method IVideoFrameStep.Step to go from one frame to the next. This method is not exposed in the interop assembly Interop.QuartzTypeLib and is the main reason for looking at alternatives when we need more functionality than provided by the assembly generated by VS from quartz.dll. In the next tutorial, we'll created our own assembly to add the IVideoFrameStep functionality to the interop assembly (generated from VS). |
| < Prev | Next > |
|---|














