Microsoft DirectX 8.1 (C++) |
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 section contains the following topics:
See Also
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.
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.
Parameter | Description |
_DERIVED_ | Derived class type |
NUMBEROFINPUTS | Number of input streams |
NUMBEROFOUTPUTS | Number 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.
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 Method | Derived Class Method |
AllocateStreamingResources | InternalAllocateStreamingResources |
Discontinuity | InternalDiscontinuity |
Flush | InternalFlush |
FreeStreamingResources | InternalFreeStreamingResources |
GetInputMaxLatency | InternalGetInputMaxLatency |
GetInputSizeInfo | InternalGetInputSizeInfo |
GetInputStreamInfo | InternalGetInputStreamInfo |
GetInputType | InternalGetInputType |
GetOutputSizeInfo | InternalGetOutputSizeInfo |
GetOutputStreamInfo | InternalGetOutputStreamInfo |
GetOutputType | InternalGetOutputType |
ProcessInput | InternalProcessInput |
ProcessOutput | InternalProcessOutput |
SetInputMaxLatency | InternalSetInputMaxLatency |
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 Method | IMediaObjectImpl Implementation |
GetInputCurrentType | Fully implemented. |
GetOutputCurrentType | Fully implemented. |
GetStreamCount | Fully implemented. |
GetInputStatus | Calls InternalAcceptingInput. |
Lock | Implemented as DMOLock. Calls Lock or Unlock. |
SetInputType | Calls InternalCheckInputType. |
SetOutputType | Calls InternalCheckOutputType. |
For more information, see IMediaObjectImpl Class Template.