Class MFSourceReader
The MF Source Reader provides a simple programming model that allows applications to easily access multimedia content from files or devices.
Implements
Inherited Members
Namespace: JeremyAnsel.DirectX.MediaFoundation
Assembly: JeremyAnsel.DirectX.MediaFoundation.dll
Syntax
[SecurityCritical]
public class MFSourceReader : DXComObject, IDisposable
Constructors
| Edit this page View SourceMFSourceReader(nint)
Initializes a new instance of the MFSourceReader class.
Declaration
public MFSourceReader(nint comPtr)
Parameters
| Type | Name | Description |
|---|---|---|
| nint | comPtr |
Fields
| Edit this page View SourceAllStreams
Declaration
public const uint AllStreams = 4294967294
Field Value
| Type | Description |
|---|---|
| uint |
AnyStream
Declaration
public const uint AnyStream = 4294967294
Field Value
| Type | Description |
|---|---|
| uint |
FirstAudioStream
Declaration
public const uint FirstAudioStream = 4294967293
Field Value
| Type | Description |
|---|---|
| uint |
FirstVideoStream
Declaration
public const uint FirstVideoStream = 4294967292
Field Value
| Type | Description |
|---|---|
| uint |
InvalidStreamIndex
Declaration
public const uint InvalidStreamIndex = 4294967295
Field Value
| Type | Description |
|---|---|
| uint |
MFSourceReaderGuid
The interface GUID.
Declaration
public static readonly Guid MFSourceReaderGuid
Field Value
| Type | Description |
|---|---|
| Guid |
Methods
| Edit this page View SourceFlush(uint)
Releases any queued up samples, and cancels any outstanding sample requests.
Declaration
public void Flush(uint dwStreamIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | dwStreamIndex | Allows the application to specify which stream to flush. MF_SOURCE_READER_ALL_STREAMS can be specified in order to flush all available streams. |
Remarks
In async mode, the OnFlush callback is called when the flush operation completes. Before receiving the OnFlush callback, the application should not request any more samples from the source reader. Doing so will result in the MF_E_NOTACCEPTING error being returned.
GetCurrentMediaType(uint)
Returns the media type of the samples currently being output for the specified stream.
Declaration
public MFMediaType GetCurrentMediaType(uint dwStreamIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | dwStreamIndex | Specifies the stream index. |
Returns
| Type | Description |
|---|---|
| MFMediaType |
GetNativeMediaType(uint, uint)
Returns the native media type for the specified stream.
Declaration
public MFMediaType? GetNativeMediaType(uint dwStreamIndex, uint dwMediaTypeIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | dwStreamIndex | Specifies the stream index. |
| uint | dwMediaTypeIndex | Specifies the media type index. As some sources support multiple native media types, the index is used to indicate the position in the list of supported media types. |
Returns
| Type | Description |
|---|---|
| MFMediaType |
GetStreamSelection(uint)
Returns whether or not the specified stream is selected. If the specified stream does not exist, the error MF_E_INVALIDSTREAMNUMBER is returned.
Declaration
public bool GetStreamSelection(uint dwStreamIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | dwStreamIndex | Specifies the stream index to query for selection state. |
Returns
| Type | Description |
|---|---|
| bool |
ReadSample(uint, MFSourceReaderControlFlags, out uint, out MFSourceReaderFlags, out ulong)
Requests the next available sample. The caller can either request a sample from a specific stream, or from any of the selected streams.
Declaration
public MFSample? ReadSample(uint dwStreamIndex, MFSourceReaderControlFlags dwControlFlags, out uint pdwActualStreamIndex, out MFSourceReaderFlags pdwStreamFlags, out ulong pllTimestamp)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | dwStreamIndex | Specifies the stream for which the sample request is being made. MF_SOURCE_READER_ANY_STREAM can be specified in order to request the next sample from any available stream. |
| MFSourceReaderControlFlags | dwControlFlags | Specifies flags that control the behavior of ReadSample. See: section above on MF Source Reader Control Flags. |
| uint | pdwActualStreamIndex | Receives the actual stream index of the media sample. |
| MFSourceReaderFlags | pdwStreamFlags | Receives the accumulated flags for the stream. See: section above on MF Source Reader Flags |
| ulong | pllTimestamp | Receives the presentation time of the sample. If MF_SOURCE_READERF_STREAM_TICK is set in the stream flags, then this receives the timestamp for the stream tick. |
Returns
| Type | Description |
|---|---|
| MFSample |
Remarks
When operating in synchronous mode, the out parameters are all required parameters.
When operating in asynchronous mode, the out parameters must all be set to NULL.
Streams must be selected in order to request samples from them.
It is possible for ReadSample to return S_OK in synchronous mode while not returning a sample. The caller should always check for NULL before dereferencing the sample. This can happen if EOS is reached, in which case MF_SOURCE_READERF_ENDOFSTREAM will be set for the stream. Another reason is if there is a gap in the stream, in which case MF_SOURCE_READERF_STREAMTICK will be set. For stream ticks, the sample will be NULL, but the timestamp parameter will be set to indicate the position in the stream where the gap occurred.
SetCurrentMediaType(uint, MFMediaType)
Sets the output media type for samples returned for the specified stream.
Declaration
public void SetCurrentMediaType(uint dwStreamIndex, MFMediaType pMediaType)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | dwStreamIndex | Specifies the stream index. |
| MFMediaType | pMediaType | Specifies the desired media type for the stream. |
Remarks
If an appropriate MFT cannot be found to transform the native media type into the desired media type, then an error is returned, and the current media type remains unchanged.
SetStreamSelection(uint, bool)
Sets the selection state for the specified stream. MF_SOURCE_READER_ALL_STREAMS can be specified in order to set the stream selection for all available streams.
Declaration
public void SetStreamSelection(uint dwStreamIndex, bool fSelected)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | dwStreamIndex | Specifies the stream index. |
| bool | fSelected | Specifies whether or not the stream should be selected. |