Microsoft DirectX 8.0

IMediaObjectImpl Class Template

Provides a base implementation for the IMediaObject interface.

For more information on using this template, see Using the DMO Base Class.

Helper Classes
LockItInternal helper class that handles locking and unlocking.
IMediaObjectImpl Methods
CheckTypesSetDetermines whether all of the non-optional streams have media types.
InputTypeRetrieves an input stream's media type.
InputTypeSetQueries whether the media type was set on an input stream.
OutputTypeRetrieves an output stream's media type.
OutputTypeSetQueries whether the media type was set on an output stream.
IMediaObject MethodsMethods that implement the IMediaObject interface.
Derived Class Methods
InternalAcceptingInputQueries whether an input stream can accept more input.
InternalCheckInputTypeQueries whether an input stream can accept a given media type.
InternalCheckOutputTypeQueries whether an output stream can accept a given media type.
LockLocks the object.
UnlockUnlocks the object.

LockIt Internal Class

Internal helper class that handles locking and unlocking.

Syntax

LockIt(
    _DERIVED_ *p
);

Parameters

p
Pointer to the derived object.

Remarks

The constructor method locks the object, and the destructor method unlocks the object. To lock the object from inside your derived class, declare a local variable of type LockIt, as shown in the following example:

{
    LockIt lck(static_cast<_DERIVED_ *>(this)); // Locks the object.

} // lck goes out of scope, object is unlocked.

The methods in IMediaObjectImpl handle locking, so in most cases the derived class does not need to lock the object.

IMediaObjectImpl::CheckTypesSet

Determines whether all of the non-optional streams have media types.

Syntax

bool CheckTypesSet(void);

Return Value

Returns TRUE if all of the object's non-optional streams have media types. Otherwise, returns FALSE.

Remarks

Call this method after any operation that changes the media type on a stream. This method sets a private flag within the class. Some IMediaObjectImpl methods test this flag to determine whether certain operations are permitted. These methods generally return DMO_E_TYPE_NOT_SET if the flag is FALSE.

The only two methods in IMediaObject that change the media type on a stream are SetInputType and SetOutputType. The class template implements both of these methods.

IMediaObjectImpl::InputType

Retrieves an input stream's media type.

Syntax

const DMO_MEDIA_TYPE *InputType(
    DWORD ulInputStreamIndex
);

Parameters

ulInputStreamIndex
Index of an input stream.

Return Value

Returns a pointer to the DMO_MEDIA_TYPE structure that describes the media type, or NULL if the type was not set.

IMediaObjectImpl::InputTypeSet

Queries whether the media type was set on an input stream.

Syntax

bool InputTypeSet(
    DWORD ulInputStreamIndex
);

Parameters

ulInputStreamIndex
Index of an input stream.

Return Value

Returns TRUE if the media type was set on this stream, or FALSE otherwise.

IMediaObjectImpl::OutputType

Retrieves an output stream's media type.

Syntax

const DMO_MEDIA_TYPE *OutputType(
    DWORD ulOutputStreamIndex
);

Parameters

ulOutputStreamIndex
Index of an output stream.

Return Value

Returns a pointer to the DMO_MEDIA_TYPE structure that describes the media type, or NULL if the type was not set.

IMediaObjectImpl::OutputTypeSet

Queries whether the media type was set on an output stream.

Syntax

bool OutputTypeSet(
    DWORD ulOutputStreamIndex
);

Parameters

ulOutputStreamIndex
Index of an output stream.

Return Value

Returns TRUE if the media type was set on this stream, or FALSE otherwise.

_DERIVED_::InternalAcceptingInput

Queries whether an input stream can accept more input. The derived class must declare and implement this method.

Syntax

HRESULT InternalAcceptingInput(
    DWORD dwInputStreamIndex
);

Parameters

dwInputStreamIndex
Index of an input stream.

Return Value

Returns S_OK if the input stream can accept input, or S_FALSE otherwise.

_DERIVED_::InternalCheckInputType

Queries whether an input stream can accept a given media type. The derived class must declare and implement this method.

Syntax

HRESULT InternalCheckInputType(
    DWORD dwInputStreamIndex,
    const DMO_MEDIA_TYPE *pmt
);

Parameters

dwInputStreamIndex
Index of an input stream.
pmt
Pointer to a DMO_MEDIA_TYPE structure that describes the media type.

Return Value

Returns S_OK if the media type is valid, or DMO_E_INVALIDTYPE otherwise.

_DERIVED_::InternalCheckOutputType

Queries whether an output stream can accept a given media type. The derived class must declare and implement this method.

Syntax

HRESULT InternalCheckOutputType(
    DWORD dwOutputStreamIndex,
    const DMO_MEDIA_TYPE *pmt
);

Parameters

dwOutputStreamIndex
Index of an output stream.
pmt
Pointer to a DMO_MEDIA_TYPE structure that describes the media type.

Return Value

Returns S_OK if the media type is valid, or DMO_E_INVALIDTYPE otherwise.

_DERIVED_::Lock

Locks the object. The derived class must declare and implement this method.

Syntax

void Lock(void);

Remarks

If you implement your derived class using the Active Template Library (ATL), you can use ATL's default implementation of this method.

_DERIVED_::Unlock

Unlocks the object. The derived class must declare and implement this method.

Syntax

void Unlock(void);

Remarks

If you implement your derived class using the Active Template Library (ATL), you can use ATL's default implementation of this method.

IMediaObject Methods

Most of the IMediaObject methods are wrappers that call an internal version of the same method. The derived class must implement the internal versions, which have the prefix Internal-.

For a list of methods the derived class must implement, see DMO Base Class. The following remarks give details about some of the implementations.

AllocateStreamingResources

The template keeps a private flag that indicates whether this method has been called. If the method is called when the flag is already TRUE, it returns S_OK without calling the InternalAllocateStreamingResources method. The FreeStreamingResources method resets the flag to FALSE.

DMOLock

This method implements the IMediaObject::Lock method. To avoid name conflicts with ATL, IMediaObjectImpl has renamed the method as DMOLock.

Note  When you build the derived class, define FIX_LOCK_NAME before you include the DMO header file. The FIX_LOCK_NAME directive causes the preprocessor to substitute DMOLock for Lock in the declaration of the IMediaObject interface. Applications can still invoke the method using the name Lock, because the vtable order does not change.

#define FIX_LOCK_NAME
#include <dmo.h>

This method calls Lock if the parameter is TRUE or Unlock if the parameter is FALSE. The derived class must implement the Lock and Unlock methods.

Flush

The template keeps a private flag that indicates the object's flushed state. The Flush method sets the flag to TRUE, and the ProcessInput method resets it to FALSE. If Flush is called when the flag is already TRUE, the method returns S_OK without calling the InternalFlush method.

GetInputSizeInfo, GetOutputSizeInfo

These methods return DMO_E_TYPE_NOT_SET unless all of the non-optional streams have media types. Therefore, in the derived class, the internal methods can assume that all of the non-optional streams have media types.

GetInputStatus

This method calls the InternalAcceptingInput method, which the derived class must implement. The InternalAcceptingInput method returns S_OK if the specified input stream can accept input. Otherwise, it returns S_FALSE.

Unless all of the non-optional streams have media types, the GetInputStatus method returns DMO_E_TYPE_NOT_SET. Therefore, the implementation of InternalAcceptingInput does not have to check for this condition.

ProcessInput

Before this method calls InternalProcessInput, it calls AllocateStreamingResources and InternalAcceptingInput. Therefore, the implementation of InternalProcessInput can assume the following:

ProcessOutput

Before this method calls InternalProcessOutput, it calls AllocateStreamingResources. Therefore, the implementation of InternalProcessOutput can assume that all resources have been allocated.

SetInputType

This method tests, sets, or clears the media type on an input stream. It calls the InternalCheckInputType method, which the derived class must implement. The InternalCheckInputType method returns S_OK if the media type is acceptable, or an error code otherwise. The SetInputType method implements the rest of the functionality.

This method does not allocate any resources. When the DMO switches to a streaming state, it calls the AllocateStreamingResources method. The derived class should use the InternalAllocateStreamingResources method to allocate any resources that it needs, such as memory buffers.

SetOutputType

This method tests, sets, or clears the media type on an output stream. It calls the InternalCheckOutputType method, which the derived class must implement. The InternalCheckOutputType method returns S_OK if the media type is acceptable, or an error code otherwise. The SetOutputType method implements the rest of the functionality.

This method does not allocate any resources. When the DMO switches to a streaming state, it calls the AllocateStreamingResources method. The derived class should use the InternalAllocateStreamingResources method to allocate any resources that it needs, such as memory buffers.