IMediaObjectImpl Class

IMediaObjectImpl

An NDoc Documented Class Library

IMediaObjectImpl Class

This abstract class can be used to implement a DMO in .NET.

For a list of all members of this type, see IMediaObjectImpl Members.

System.Object    MediaObjectTemplate.IMediaObjectImpl

public abstract class IMediaObjectImpl : IMediaObject, IMediaParamInfo, IMediaParams

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

Before attempting to use this class, read the MSDN docs on DMOs! In particular read about IMediaObject, IMediaParamInfo, IMediaParams, and the DMO Wrapper Filter (if you are using DirectShow graphs).

When you read the MSDN docs about creating a DMO, they refer to a template that you can use to make things easier. That template served as the inspiration for this class. To create a DMO, you can just create a class that implements this abstract class, write code for the abstract methods, and you should be good to go.

Here is a more detailed description of the steps you need to take. Note that you can look at the sample code for examples of these steps.

1) Other than ripping out the rather lame logging, you shouldn't need to change any code in IMediaObjectImpl.cs. It is the initial entry point for all the IMediaObject interfaces. It performs parameter checking, makes sure the call is appropriate for the current state, etc. As needed it will make calls to the abstract and virtual methods of the class.

2) Create a class which implements the abstract IMediaObjectImpl class:

    [ComVisible(true), Guid("7EF28FD7-E88F-45bb-9CDD-8A62956F2D75"),
    ClassInterface(ClassInterfaceType.None)]
    public class DmoFlip : IMediaObjectImpl

3) Generate your own guid so the samples won't interfere with your code: If you are running Dev Studio, go to Tools/Create Guid, choose "Registry Format", click "Copy", then paste into your code.

4) Create the constructor for your class. It must not take any parameters:

   public DmoFlip() : base(InputPinCount, OutputPinCount, ParamCount, TimeFormatFlags.Reference)

If you are planning to use this DMO with the DirectShow DMO Wrapper Filter, note that (up to and including DX v9.0) InputPinCount must be 1, and OutputPinCount must be > 0. The ParamCount is the number of parameters your DMO supports, and can be zero. In general, you should use TimeFormatFlags.Reference for the last paramter.

5) Register the parameters your DMO supports using ParamDefine. This must be done in the constructor (unless you have no parameters). Doing this allows you to support IMediaParamInfo and IMediaParams. You will also need to use ParamCalcValueForTime to find out what parameter value you should use at any given point during the stream. See the docs for these two methods for details.

6) Create the COM register/unregister methods:

    [ComRegisterFunctionAttribute]
    static private void DoRegister(Type t)

    [ComUnregisterFunctionAttribute]
    static private void UnregisterFunction(Type t)

These tell the OS about your DMO. If you are distributing your code, you will need to make sure they get called during installation (read about RegAsm in the .NET docs). At a minimum, you will need to call DMORegister to register your DMO. See the sample for how this is done.

WARNING: If you use the "Register for COM Interop" compiler switch, the compiler will attempt to register DirectShowLib.dll as well as your DMO. Since DirectShowLib has no registration to perform, this generates an error. That is why the sample uses pre/post build events to perform the registration. You may need to adjust this command for your particular installation.

7) Do everything else. There are 7 abstract methods for which you must write code. These methods are listed in the IMediaObjectImpl Methods page in the Protected Instance Methods section. These methods will contain the information specific to your DMO, and describe what type of data you are willing to process, and perform the actual processing. Note that since the abstract class has verified the parameters, you do not need to re-check them in your implementation. See the descriptions for each method and the sample for details about what each of these methods must do.

You may also need to override some of the 11 virtual methods if their default implementation doesn't match your specific needs. See the documentation for each of these specific methods for details.


If you aren't already knowledgeable about COM and writing multi-threaded apps, this is probably a good time to do a little research. You may have multiple instances of your DMO running in the same process, in multiple processes, called on different threads, etc.

As a simple example of the things you should be thinking of, the logging in (debug builds of) IMediaObjectImpl.cs opens the file as non-sharable. However, if two applications try to instantiate your DMO, the second will fail, solely due to not being able to open the log file. Probably not the desired behavior (told you the logging was lame).

Requirements

Namespace: MediaObjectTemplate

Assembly: DmoFlip (in DmoFlip.dll)

See Also

IMediaObjectImpl Members | MediaObjectTemplate Namespace