ISampleGrabber::SetMediaType

 
Microsoft DirectShow 9.0

ISampleGrabber::SetMediaType

The SetMediaType method specifies the media type for the connection on the input pin of the Sample Grabber.

Syntax

  HRESULT SetMediaType(
  const AM_MEDIA_TYPE *pType
);

Parameters

pType

Pointer to an AM_MEDIA_TYPE structure specifies the required media type. It is not necessary to set all the structure members; see Remarks for details.

Return Value

Returns S_OK.

Remarks

By default, the Sample Grabber has no preferred media type. To ensure that the Sample Grabber connects to the correct filter, call this method before building the filter graph.

This method restricts the range of media types that the filter will accept. When the filter connects, it tries to match the media type given in pType. To do so, it compares the major type, subtype, and format type GUIDs, in that order. For each of these GUIDs, if pType has the value GUID_NULL, the Sample Grabber accepts the media type without any further checks. If pType has any other value, the Sample Grabber compares it to the GUID in the connection type. Unless the two GUIDs match exactly, the Sample Grabber rejects the connection.

For video media types, the Sample Grabber ignores the format block. Therefore, it will accept any video size and frame rate. When you call SetMediaType, set the format block (pbFormat) to NULL and the size (cbFormat) to zero. For audio media types, the Sample Grabber will examine the WAVEFORMATEX structure and will require the other filter to connect with that format — unless the format block in pType is NULL, or the format tag is WAVE_FORMAT_PCM and the other structure members are zero.

Example 1:

  • Major type: MEDIATYPE_Video
  • Subtype: GUID_NULL
  • Format type: GUID_NULL

The Sample Grabber will accept any video type where the major type equals MEDIATYPE_Video. It will not check the subtype.

Example 2:

  • Major type: MEDIATYPE_Video
  • Subtype: MEDIASUBTYPE_RGB24
  • Format type: GUID_NULL

Now the Sample Grabber will check the subtype, and accept only RGB 24 video.

Limitations: Regardless of what type you set, the Sample Grabber Filter rejects any video types with top-down orientation (negative biHeight), or with a format type of FORMAT_VideoInfo2. In this case, although the SetMediaType method succeeds, the filter will not connect.

Requirements

Header: Include Qedit.h. This header file is not compatible with Microsoft® Direct3D® headers later than version 7.

Library: Use strmiids.lib.

See Also