Microsoft DirectX 8.0

Using the DMO Base Class

The Microsoft® DirectX® 8.0 SDK includes a base-class template for creating DMOs, IMediaObjectImpl. You do not have to use the class template when you create a DMO, as long as your DMO fully supports the IUnknown and IMediaObject interfaces. However, the class template provided by Microsoft handles many of the "bookkeeping" tasks, such as validating input parameters. By using the template, you can focus on the functionality that is specific to your DMO. In addition, the template helps to ensure that you create a robust implementation.

This article contains the following topics:

Overview of IMediaObjectImpl

The IMediaObjectImpl template is a class template that inherits the IMediaObject interface. To create a DMO using the template, define a new class that derives from IMediaObjectImpl. The template implements all of the IMediaObject methods. In most cases, the template method calls a corresponding internal method, which the derived class must provide. Thus, the template provides generic functionality, such as validating parameters, while the derived class provides the core functionality for the DMO.

The template provides the following features:

The derived class must implement the IUnknown interface; the template does not provide this interface. You can use the Active Template Library (ATL) to implement IUnknown, or you can provide some other implementation.

The template also does not implement the locking mechanism. The derived class must implement the Lock and Unlock methods. If you create your class using ATL, however, the default ATL implementations for these methods are probably sufficient.

Declaring the Derived Class

The IMediaObjectImpl template is declared in the header file Dmoimpl.h, which is located in the Include directory of the SDK. It has the following declaration:

template <class _DERIVED_, int NUMBEROFINPUTS, int NUMBEROFOUTPUTS>
class IMediaObjectImpl : public IMediaObject

The template has three parameters, as shown in the following table.

_DERIVED_Derived class type
NUMBEROFINPUTSNumber of input streams
NUMBEROFOUTPUTSNumber of output streams

For example, to create a derived class named CMyDmoClass that supports one input stream and one output stream, you would declare it as follows:

class CMyDmoClass :
    public IMediaObjectImpl<CMyDmoClass, 1, 1>  // 1 input, 1 output

DMOs cannot dynamically create or destroy streams, so the stream numbers are constant.

Implementing the DMO Methods

The template provides partial implementations for the following IMediaObject methods. The derived class must provide a corresponding method, which the IMediaObject method calls internally. The internal methods have Internal- prefixed to the method name. The internal methods use the same parameters as the interface methods.

IMediaObject MethodDerived Class Method
AllocateStreamingResourcesInternalAllocateStreamingResources
DiscontinuityInternalDiscontinuity
FlushInternalFlush
FreeStreamingResourcesInternalFreeStreamingResources
GetInputMaxLatencyInternalGetInputMaxLatency
GetInputSizeInfoInternalGetInputSizeInfo
GetInputStreamInfoInternalGetInputStreamInfo
GetInputTypeInternalGetInputType
GetOutputSizeInfoInternalGetOutputSizeInfo
GetOutputStreamInfoInternalGetOutputStreamInfo
GetOutputTypeInternalGetOutputType
ProcessInputInternalProcessInput
ProcessOutputInternalProcessOutput
SetInputMaxLatencyInternalSetInputMaxLatency

For the remaining IMediaObject methods, there is not a one-to-one correspondence between interface methods and internal methods. The following table summarizes which methods are fully implemented by the template, and which methods call helper methods from the derived class.

IMediaObject MethodIMediaObjectImpl Implementation
GetInputCurrentTypeFully implemented.
GetOutputCurrentTypeFully implemented.
GetStreamCountFully implemented.
GetInputStatusCalls InternalAcceptingInput.
LockImplemented as DMOLock. Calls Lock or Unlock.
SetInputTypeCalls InternalCheckInputType.
SetOutputTypeCalls InternalCheckOutputType.

For more information, see IMediaObjectImpl.