Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
When filters are connected, they typically negotiate a type between them. This type describes the format of the data to be exchanged; if the filters do not agree on a media type, they cannot connect. Microsoft 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 member that declares whether the data will be passed in fixed-size buffers. The second part of the structure 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 VIDEOINFOHEADERstructure. If, on the other hand, it is digital audio, the format block is a Microsoft Win32 WAVEFORMATEXstructure.
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 typedescribes the overall class of data, examples of which might be digital video, digital audio, MIDI, or text captions. The subtypeshould supply a more specific description of the data type. In the case of digital video, for example, 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. However, as a general rule, transformations between major types (for example, video to audio or video to MIDI) should be relatively rare. Such a rare exception might be a transformation between audio and MIDI. 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 VIDEOINFOHEADERstructure for the type-specific format block. This contains a Win32 BITMAPINFOHEADERstructure that defines the video stream. BITMAPINFOHEADERcontains 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 VIDEOINFOHEADERfor 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 actually contains is inferred by another GUID called the format type. If the format block contains VIDEOINFOHEADER, the format type GUIDwill be FORMAT_VideoInfo.
The principal use of the CMediaTypeclass is to manage a media type structure in a simple way. At the same time, the class provides some extra helper functions (such as format-block copying and allocation). The class can be cast to an AM_MEDIA_TYPEstructure when an interface method requires one to be passed to it.
The CMediaTypeclass contains a pointer to a block of memory. When copying a CMediaTypeobject, it is insufficient to simply copy the pointer. In C++, a data copy is required, which actually allocates a new block of memory and copies the data into it. This is the purpose of the copy operator.
Similarly, when comparing two CMediaTypeobjects, you must compare the blocks of variable-length data (actually using memcmp) when producing the final result. To make this possible, CMediaTypeoverrides the equivalence operator.
Member Functions
AllocFormatBuffer | Allocates an uninitialized format block in the object. |
CMediaType | Constructs a CMediaTypeobject. |
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 = | Performs a copy operation. |
operator == | Tests for equality between CMediaTypeobjects. |
operator != | Tests for inequality between CMediaTypeobjects. |