CSourceStream.GetMediaType method (Source.h)

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The GetMediaType method retrieves a preferred media type.

Syntax

virtual HRESULT GetMediaType(
   CMediaType *pMediaType
);

Parameters

pMediaType

Pointer to a CMediaType object that receives the media type.

Return value

Returns one of the HRESULT values shown in the following table.

Return code Description
S_OK
Success.
VFW_S_NO_MORE_ITEMS
Index out of range.
E_INVALIDARG
Index less than zero.
E_UNEXPECTED
Unexpected error.

Remarks

There are two versions of this method. One version overrides the CBasePin::GetMediaType method and takes an index value as a parameter. The other version is designed to retrieve a single media type, so it lacks the index parameter.

The single-parameter method returns E_UNEXPECTED. The two-parameter method verifies that the iPosition parameter is zero and then calls the single-parameter version. Depending on the number of media types the pin supports, you must override one of these methods:

  • If the pin supports exactly one media type, override the single-parameter version. Fill in the media type that the pin supports.
  • If the pin supports more than one media type, override the two-parameter version. Also override the CSourceStream::CheckMediaType method.

Requirements

Requirement Value
Header
Source.h (include Streams.h)
Library
Strmbase.lib (retail builds);
Strmbasd.lib (debug builds)

See also

CSourceStream Class