Microsoft DirectX 8.0

CMediaType Class

CMediaType class hierarchy

Class for managing media types. This class inherits the AM_MEDIA_TYPE structure. It can be cast to a variable of type AM_MEDIA_TYPE.

Declaration: Mtype.h

Public Methods
CMediaTypeConstructor method.
~CMediaTypeDestructor method.
IsValidDetermines whether a major type has been assigned to this object.
TypeRetrieves the major type.
SetTypeSpecifies the major type.
SubtypeRetrieves the subtype.
SetSubtypeSpecifies the subtype.
IsFixedSizeDetermines if the samples have a fixed size or a variable size.
IsTemporalCompressedDetermines if the stream uses temporal compression.
GetSampleSizeRetrieves the sample size.
SetSampleSizeSpecifies a fixed sample size, or specifies that samples have a variable size.
SetVariableSizeSpecifies that samples do not have a fixed size.
SetTemporalCompressionSpecifies whether samples are compressed using temporal compression.
FormatRetrieves a pointer to the format block.
FormatLengthRetrieves the length of the format block.
SetFormatTypeSpecifies the format type.
FormatTypeRetrieves the format type.
SetFormatSpecifies the format block.
ResetFormatBufferDeletes the format block.
AllocFormatBufferAllocates memory for the format block.
ReallocFormatBufferReallocates the format block to a new size.
InitMediaTypeInitializes the media type.
MatchesPartialDetermines if this media type matches a partially specified media type.
IsPartiallySpecifiedDetermines if the media type is partially defined.
Operators
operator =Overloads the assignment operator to copy a media type.
operator ==Tests for equality between CMediaType objects.
operator !=Tests for inequality between CMediaType objects.

CMediaType::AllocFormatBuffer

CMediaType Class

Allocates memory for the format block.

Syntax

BYTE* AllocFormatBuffer(
    ULONG length
);

Parameters

length
Size required for the format block, in bytes.

Return Value

Returns a pointer to the new block if successful. Otherwise, returns NULL.

Remarks

If the method successfully allocates a new format block, it frees the existing format block. If the allocation fails, the method leaves the existing format block.

CMediaType::CMediaType

CMediaType Class

Constructor method.

Syntax

CMediaType(void);

CMediaType(
    const GUID *majortype
);

CMediaType(
    const AM_MEDIA_TYPE& mtype
);

CMediaType(
    const CMediaType& cmtype
);

Parameters

majortype
Pointer to a major type GUID.
mtype
Reference to an AM_MEDIA_TYPE structure.
cmtype
Reference to a CMediaType object.

Remarks

The constructor calls the InitMediaType function to initialize the media type. If the majortype parameter is specified, the constructor initializes the major type GUID. If the mtype or cmtype parameter is specified, the constructor copies the media type information (including the format block) into the new object.

CMediaType::~CMediaType

CMediaType Class

Destructor method.

Syntax

~CMediaType(void);

Remarks

The destructor calls the FreeMediaType function on itself.

CMediaType::Format

CMediaType Class

Retrieves a pointer to the format block.

Syntax

BYTE* Format(void) const;

Return Value

Returns the pbFormat member.

CMediaType::FormatLength

CMediaType Class

Retrieves the length of the format block.

Syntax

ULONG FormatLength(void) const;

Return Value

Returns the cbFormat member.

CMediaType::FormatType

CMediaType Class

Retrieves the format type.

Syntax

const GUID *FormatType(void) const;

Return Value

Returns a pointer to the formattype member.

CMediaType::GetSampleSize

CMediaType Class

Retrieves the sample size.

Syntax

ULONG GetSampleSize(void) const;

Return Value

If the sample size is fixed, returns the sample size in bytes. Otherwise, returns zero.

CMediaType::InitMediaType

CMediaType Class

Initializes the media type.

Syntax

void InitMediaType(void);

Remarks

This method zeroes the object's memory, sets the fixed-sample-size property to TRUE, and sets the sample size to 1.

CMediaType::IsFixedSize

CMediaType Class

Determines if the samples have a fixed size or a variable size.

Syntax

BOOL IsFixedSize(void) const;

Return Value

Returns the value of the bFixedSizeSamples member.

CMediaType::IsPartiallySpecified

CMediaType Class

Determines if the media type is partially defined. A media type is partial if the major type, subtype, or format type is GUID_NULL.

Syntax

BOOL IsPartiallySpecified(void) const;

Return Value

Returns TRUE if the media type is partially specified. Otherwise, returns FALSE.

Remarks

The IPin::Connect method can accept partial media types.

The implementation does not actually test the subtype. If there is a specified format type, the media type is not considered partial, even if the subtype is GUID_NULL.

CMediaType::IsTemporalCompressed

CMediaType Class

Determines if the stream uses temporal compression.

Syntax

BOOL IsTemporalCompressed(void) const;

Return Value

Returns the value of the bTemporalCompression member.

CMediaType::IsValid

CMediaType Class

Determines whether a major type has been assigned to this object.

Syntax

BOOL IsValid(void) const;

Return Value

Returns TRUE if a major type has been assigned to this object. Otherwise, returns FALSE.

Remarks

By default, CMediaType objects are initialized with a major type of GUID_NULL. Call this method to determine whether the object has been correctly initialized.

CMediaType::MatchesPartial

CMediaType Class

Determines if this media type matches a partially specified media type.

Syntax

BOOL MatchesPartial(
    const CMediaType *ppartial
    ) const;

Parameters

ppartial
Pointer to the media type to match.

Return Value

Returns TRUE if the media types match. Otherwise, returns FALSE.

Remarks

The media type specified by ppartial can have a value of GUID_NULL for the major type, subtype, or format type. Any members with GUID_NULL values are not tested. (In effect, GUID_NULL acts as a wildcard.) Members with values other than GUID_NULL must match for the media type to match.

CMediaType::ReallocFormatBuffer

CMediaType Class

Reallocates the format block to a new size.

Syntax

BYTE* ReallocFormatBuffer(
    ULONG length
);

Parameters

length
New size required for the format block, in bytes. Must be greater than zero.

Return Value

Returns a pointer to the new block if successful. Otherwise, returns either a pointer to the old format block, or NULL.

Remarks

This method allocates a new format block. It copies as much of the existing format block as possible into the new format block. If the new block is smaller than the existing block, the existing format block is truncated. If the new block is larger, the contents of the additional space are undefined. They are not explicitly set to zero.

CMediaType::ResetFormatBuffer

CMediaType Class

Deletes the format block.

Syntax

void ResetFormatBuffer(void);

CMediaType::SetFormat

CMediaType Class

Specifies the format block.

Syntax

BOOL SetFormat(
    BYTE *pFormat,
    ULONG length
);

Parameters

pFormat
Pointer to a block of memory that contains the format block.
length
Length of the format block, in bytes.

Return Value

Returns TRUE if successful, or FALSE if an error occurred.

Remarks

This method copies the format block specified by pFormat. To set the format type, call the SetFormatType method.

CMediaType::SetFormatType

CMediaType Class

Specifies the format type.

Syntax

void SetFormatType(
    const GUID *pformattype
);

Parameters

pformattype
Pointer to a GUID that specifies the format type.

Remarks

This method sets the formattype member. The format type defines the layout of the format block. For example, if the format type is FORMAT_VideoInfo, the format block should contain a VIDEOINFOHEADER structure. To set the format block, call the SetFormat method. The caller is responsible for making sure that the format block matches the format type.

CMediaType::SetSampleSize

CMediaType Class

Specifies a fixed sample size, or specifies that samples have a variable size.

Syntax

void SetSampleSize(
    ULONG sz
);

Parameters

sz
Sample size, in bytes, or zero.

Remarks

If value of sz is zero, the media type uses variable sample sizes. Otherwise, the sample size is fixed at sz bytes.

CMediaType::SetSubtype

CMediaType Class

Specifies the subtype.

Syntax

void SetSubtype(
    const GUID *psubtype
);

Parameters

psubtype
Pointer to a GUID that specifies the subtype.

CMediaType::SetTemporalCompression

CMediaType Class

Specifies whether samples are compressed using temporal (interframe) compression.

Syntax

void SetTemporalCompression(
    BOOL bCompressed
);

Parameters

bCompressed
Boolean value that specifies whether the stream uses temporal compression. If the stream uses temporal compression, set the value to TRUE.

Remarks

This method sets the bTemporalCompression member.

CMediaType::SetType

CMediaType Class

Specifies the major type.

Syntax

void SetType(
    const GUID *ptype
);

Parameters

ptype
Pointer to a GUID that specifies the major type.

CMediaType::SetVariableSize

CMediaType Class

Specifies that samples do not have a fixed size.

Syntax

void SetVariableSize(void);

Remarks

This method sets the bFixedSizeSamples member to FALSE. Subsequent calls to the CMediaType::GetSampleSize method return zero.

CMediaType::Subtype

CMediaType Class

Retrieves the subtype.

Syntax

const GUID *Type(void) const;

Return Value

Returns a pointer to the subtype member.

CMediaType::Type

CMediaType Class

Retrieves the major type.

Syntax

const GUID *Type(void) const;

Return Value

Returns a pointer to the majortype member.

CMediaType::operator =

CMediaType Class

Overloads the assignment operator to copy a media type.

Syntax

CMediaType& operator=(
    const CMediaType& cmtype
);

CMediaType& operator=(
    const AM_MEDIA_TYPE& mtype
);

Parameters

cmtype
Reference to a CMediaType object.
mtype
Reference to an AM_MEDIA_TYPE structure.

Return Value

Returns a reference to the object.

CMediaType::operator ==

CMediaType Class

Tests for equality between CMediaType objects.

Syntax

inline BOOL operator==(
    const CMediaType& rt
) const;

Parameters

rt
Reference to the CMediaType object to compare.

Return Value

Returns TRUE if rt is equal to this object. Otherwise, returns FALSE.

CMediaType::operator !=

CMediaType Class

Tests for inequality between CMediaType objects.

Syntax

BOOL operator!=(
    const CMediaType& rt
) const;

Parameters

rt
Reference to the CMediaType object to compare.

Return Value

Returns TRUE if rt is not equal to this object. Otherwise, returns FALSE.