typedef struct _MediaType
{
GUID majortype;
GUID subtype;
BOOL bFixedSizeSamples;
BOOL bTemporalCompression;
ULONG lSampleSize;
GUID formattype;
IUnknown *pUnk;
ULONG cbFormat;
[size_is(cbFormat)] BYTE *pbFormat;
} AM_MEDIA_TYPE;
Major type:是一个GUID,用来定义数据的主类型,包括,音频,视频,unparsed 字节流,MIDI数据,等等,具体可以参考msdn。
GUID | Description |
---|---|
| Analog audio. |
| Analog video. |
| Audio. See Audio Subtypes. |
| Line 21 data. Used by closed captions. See Line 21 Media Types. |
| File. (Obsolete) |
| Interleaved audio and video. Used for Digital Video (DV). |
| Obsolete. Do not use. |
| MIDI format. |
| MPEG-2 PES packets. See MPEG-2 Media Types. |
| MPEG-2 section data. See MPEG-2 Media Types. |
| Data is a script command, used by closed captions. |
| Byte stream with no time stamps. See Stream Subtypes. |
| Text. |
| Timecode data. Note: DirectShow does not provide any filters that support this media type. |
| Obsolete. Do not use. |
| Vertical blanking interval (VBI) data (for television). Same as KSDATAFORMAT_TYPE_VBI. |
| Video. See Video Subtypes. |
Subtype:子类型,也是一个GUID,用来进一步的细化数据格式,例如,在视频主类型中,还包括RGB-24, RGB-32, UYVY 等等一些子类型,在音频主类型中还包括PCM audio, MPEG-1payload 等类型,子类型提供了比主类型更详细的信息,但是并没有定义所有的格式,例如,视频的子类型并没有定义图像大小,桢率。这些由下面的字段定义。
bFixedSizeSamples 当这个值为TRUE 时,表示sample 大小固定。
bTemporalCompression 当这个值为TRUE 时,表示sample 采用了临时压缩格式,表明不是所有的桢都是关键桢,如果为FALSE,表明所有的都是关键桢。
lSampleSize 表示sample 的大小。对于压缩的数据,这个值可能为零。
Formattype 一个GUID 值, 用来表明内存块的格式。包括如下: FORMAT_None ,FORMAT_DvInfo,FORMAT_MPEGVideo,FORMAT_MPEG2Video,FORMAT_VideoInfo,FORMAT_VideoInfo2,FORMAT_WaveFormatEx,GUID_NULL
pUnk 该参数没有用到
cbFormat 内存块的大小
pbFormat 指向内存块的指针,
下面我们看一段代码,看看filter 如何检测媒体类型的。
HRESULT CheckMediaType(AM_MEDIA_TYPE *pmt)
{
if (pmt == NULL) return E_POINTER;
// Check the major type. We're looking for video.
if (pmt->majortype != MEDIATYPE_Video)
{
return VFW_E_INVALIDMEDIATYPE;
}
// Check the subtype. We're looking for 24-bit RGB.
if (pmt->subtype != MEDIASUBTYPE_RGB24)
{
return VFW_E_INVALIDMEDIATYPE;
}
// Check the format type and the size of the format block.
if ((pmt->formattype == FORMAT_VideoInfo) &&(pmt->cbFormat >= sizeof(VIDEOINFOHEADER) &&(pmt->pbFormat != NULL))
{
// Now it's safe to coerce the format block pointer to the
// correct structure, as defined by the formattype GUID.
VIDEOINFOHEADER *pVIH = (VIDEOINFOHEADER*)pmt->pbFormat;
// Examine pVIH (not shown). If it looks OK, return S_OK.
return S_OK;
}
return VFW_E_INVALIDMEDIATYPE;
}