Compartilhar via


CMediaType Class (Compact 2013)

3/26/2014

AM_MEDIA_TYPE structure

     CMediaType Class

When filters are connected, they typically negotiate a type between them. The type describes the format of the data to be exchanged; if the filters do not agree on a media type, they cannot connect.

DirectShow describes types through the media type structure, which contains two conceptual parts:

  • The first is a list of members that describes generic attributes of a data stream. An example of this is a mem
    ber that declares whether the data will be passed in fixed-size buffers.
  • The second is a variable-length block of data. How large the block of data should be and what it will contain depend on the type of data stream.

For example, if the data stream is digital video, the format block is a VIDEOINFOHEADER structure. If, on the other hand, it is digital audio, the format block is a Win32 WAVEFORMATEX structure.

A data stream type (for example, digital video) is set with a combination of two globally unique identifiers (GUIDs), called a major type and a subtype.

  • The major type describes the overall class of data, examples of which might be digital video, digital audio, or text captions.
  • The subtype should supply a more specific description of the data type. For example, in the case of digital video, the subtype could be RGB8, RGB16, or RGB32 (among others).

By having these two types in a generic structure (AM_MEDIA_TYPE), a component, such as a filter graph, can connect filters without any knowledge that is type specific.

The distinction between what goes in the major type and the subtype is somewhat arbitrary:

  • As a general rule, transformations between major types (for example, video to audio) should be relatively rare.
  • As for the subtype, the more information promoted from the type-specific format block into the subtype, the better the design.

As an example of promoting type-specific information to the subtype, video in DirectShow uses a VIDEOINFOHEADER structure for the type-specific format block.

This contains a Win32 BITMAPINFOHEADER structure that defines the video stream. BITMAPINFOHEADER contains the bit depth of the video, such as 8-bit, 16-bit, or 24-bit.

This information is duplicated in the subtype field, because a subtype of RGB8 directly infers a bit count of 8.

DirectShow defines a number of major types.

The most important of these are a video type that uses VIDEOINFOHEADER for the variable-length format block, and an audio that uses WAVEFORMATEX.

However, it is insufficient to have a major type (such as digital video) inferring the contents of the format block (in this case, VIDEOINFOHEADER). The principal reason for this is extensibility: the format block type must be able to be updated without changing the less-specific major type.

Therefore, what the format block contains is inferred by another GUID called the format type. If the format block contains VIDEOINFOHEADER, the format type GUID will be FORMAT_VideoInfo.

The principal use of the CMediaType class is to manage a media type structure in a simple way. At the same time, the class provides extra helper functions (such as format-block copying and allocation). The class can be cast to an AM_MEDIA_TYPE structure when an interface method requires one to be passed to it.

The CMediaType class contains a pointer to a block of memory. When copying a CMediaType object, it is insufficient to only copy the pointer. In C++, a data copy is required, which allocates a new block of memory and copies the data into it. This is the purpose of the copy operator.

Similarly, when comparing two CMediaType objects, you must compare the blocks of variable-length data (actually using memcmp) when producing the final result. To make this possible, CMediaType overrides the equivalence operator.

Member Functions

Member function

Description

AllocFormatBuffer

Allocates an uninitialized format block in the object.

CMediaType

Constructs a CMediaType object.

Format

Returns the format block for this media type.

FormatLength

Returns the length of the format block of this object.

FormatType

Returns a pointer to the format type.

GetSampleSize

Returns the size of the samples.

InitMediaType

Initializes the media type.

IsFixedSize

Queries whether the samples are fixed in length.

IsPartiallySpecified

Checks if the media type is not completely specified.

IsTemporalCompressed

Queries whether the data stream is compressed temporally.

IsValid

Queries whether the media type is currently valid.

MatchesPartial

Checks whether this media type matches another media type that is only partially specified.

ReallocFormatBuffer

Reallocates the format block, maintaining its current content where possible.

ResetFormatBuffer

Deletes any format block that is currently present.

SetFormat

Sets the format block.

SetFormatType

Sets the type of the format block in the object.

SetSampleSize

Sets the size of the samples.

SetSubtype

Sets the subtype.

SetTemporalCompression

Marks the media type to indicate that samples will be temporally compressed.

SetType

Sets the major type.

SetVariableSize

Marks the media type to indicate that samples will vary in length.

Subtype

Returns a pointer to the subtype.

Type

Returns a pointer to the major type.

Operators

Operator

Description

operator =

Performs a copy operation.

operator ==

Tests for equality between CMediaType objects.

operator !=

Tests for inequality between CMediaType objects.

Requirements

Header

dshow.h,
Streams.h

Library

ole32.lib,
Ole32auth.lib,
Strmbase.lib,
Strmiids.lib,
uuid.lib

See Also

Reference

DirectShow Classes