Methods (23) Properties (4)
Namespace: CSCore.MediaFoundation

Syntax

public class MFByteStream : ComObject

Base Type

Summary

Represents a byte stream from some data source, which might be a local file, a network file, or some other source. The MFByteStream interface supports the typical stream operations, such as reading, writing, and seeking.

Uses

Used by

Methods

MFByteStream(IntPtr ptr)

Initializes a new instance of the MFByteStream class.

public void MFByteStream(IntPtr ptr)

Parameters

ptr

IntPtr

The native pointer of the COM object.

MFByteStream(Stream stream)

Initializes a new instance of the MFByteStream class which acts as a wrapper for the specified stream to use it in a media foundation context.

public void MFByteStream(Stream stream)

Parameters

stream

Stream

The stream to wrap for media foundation usage.

BeginReadNative(IntPtr buffer, Int32 count, IntPtr callback, IntPtr unkState)

Begins an asynchronous read operation from the stream.

public Int32 BeginReadNative(IntPtr buffer, Int32 count, IntPtr callback, IntPtr unkState)

Parameters

buffer

IntPtr

Pointer to a buffer that receives the data. The caller must allocate the buffer.

count

Int32

Size of the buffer in bytes.

callback

IntPtr

Pointer to the IMFAsyncCallback interface of a callback object. The caller must implement this interface.

unkState

IntPtr

Pointer to the IUnknown interface of a state object, defined by the caller. Can be Zero.

Returns

HRESULT

BeginWriteNative(IntPtr buffer, Int32 count, IntPtr callback, IntPtr unkState)

Begins an asynchronous write operation to the stream.

public Int32 BeginWriteNative(IntPtr buffer, Int32 count, IntPtr callback, IntPtr unkState)

Parameters

buffer

IntPtr

Pointer to a buffer containing the data to write.

count

Int32

Size of the buffer in bytes.

callback

IntPtr

Pointer to the IMFAsyncCallback interface of a callback object. The caller must implement this interface.

unkState

IntPtr

Pointer to the IUnknown interface of a state object, defined by the caller. Can be Zero.

Returns

HRESULT

Close()

Closes the stream and releases any resources associated with the stream, such as sockets or file handles. This method also cancels any pending asynchronous I/O requests.

CloseNative()

Closes the stream and releases any resources associated with the stream, such as sockets or file handles. This method also cancels any pending asynchronous I/O requests.

public Int32 CloseNative()

Returns

HRESULT

Dispose(Boolean disposing)

Releases the COM object.

protected void Dispose(Boolean disposing)

Parameters

disposing

Boolean

True to release both managed and unmanaged resources; false to release only unmanaged resources.

EndReadNative(IntPtr result, Int32& read)

Completes an asynchronous read operation.

public Int32 EndReadNative(IntPtr result, Int32& read)

Parameters

result

IntPtr

Pointer to the IMFAsyncResult interface. Pass in the same pointer that your callback object received in the IMFAsyncCallback::Invoke method.

read

Int32&

Receives the number of bytes that were read.

Returns

HRESULT

EndWriteNative(IntPtr result, Int32& written)

Completes an asynchronous write operation.

public Int32 EndWriteNative(IntPtr result, Int32& written)

Parameters

result

IntPtr

Pointer to the IMFAsyncResult interface. Pass in the same pointer that your callback object received in the IMFAsyncCallback::Invoke method.

written

Int32&

Receives the number of bytes that were written.

Returns

HRESULT

Flush()

Clears any internal buffers used by the stream. If you are writing to the stream, the buffered data is written to the underlying file or device.

FlushNative()

Clears any internal buffers used by the stream. If you are writing to the stream, the buffered data is written to the underlying file or device.

public Int32 FlushNative()

Returns

HRESULT

GetCapabilitiesNative(MFByteStreamCapsFlags& capabilities)

Retrieves the characteristics of the byte stream.

public Int32 GetCapabilitiesNative(MFByteStreamCapsFlags& capabilities)

Parameters

capabilities

MFByteStreamCapsFlags&

Receives a bitwise OR of zero or more flags.

Returns

HRESULT

Remarks

Use the Capabilities property for easier usage with automated error handling.

GetCurrentPositionNative(Int64& position)

Retrieves the current read or write position in the stream.

public Int32 GetCurrentPositionNative(Int64& position)

Parameters

position

Int64&

The current position, in bytes.

Returns

HRESULT

GetLengthNative(Int64& length)

Retrieves the length of the stream.

public Int32 GetLengthNative(Int64& length)

Parameters

length

Int64&

Receives the length of the stream, in bytes. If the length is unknown, this value is -1.

Returns

HRESULT

Remarks

Use the Length property for easier usage with automated error handling.

IsEndOfStreamNative(NativeBool& isEndOfStream)

Queries whether the current position has reached the end of the stream.

public Int32 IsEndOfStreamNative(NativeBool& isEndOfStream)

Parameters

isEndOfStream

NativeBool&

Receives the value True if the end of the stream has been reached, or False otherwise.

Returns

HREUSLT

Read(Byte[] buffer, Int32 count)

Reads data from the stream.

public Int32 Read(Byte[] buffer, Int32 count)

Parameters

buffer

Byte[]

The buffer that receives the data.

count

Int32

The number of bytes to read.

Returns

HRESULT

Exceptions

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

count is bigger than the length of the buffer.

public Int32 ReadNative(IntPtr buffer, Int32 count, Int32& read)

Parameters

buffer

IntPtr

Pointer to a buffer that receives the data. The caller must allocate the buffer.

count

Int32

Size of the buffer in bytes.

read

Int32&

Receives the number of bytes that are copied into the buffer.

Returns

HRESULT

Seek(MFByteStreamSeekOrigin seekOrigin, Int64 seekOffset, Boolean cancelPendingIO)

Moves the current position in the stream by a specified offset.

public Int64 Seek(MFByteStreamSeekOrigin seekOrigin, Int64 seekOffset, Boolean cancelPendingIO)

Parameters

seekOrigin

MFByteStreamSeekOrigin

Specifies the origin of the seek as a member of the MFByteStreamSeekOrigin enumeration. The offset is calculated relative to this position.

seekOffset

Int64

Specifies the new position, as a byte offset from the seek origin.

cancelPendingIO

Boolean

Specifies whether all pending I/O requests are canceled after the seek request completes successfully.

Returns

The new position after the seek.

public Int32 SeekNative(MFByteStreamSeekOrigin seekOrigin, Int64 seekOffset, Boolean cancelPendingIO, Int64& currentPosition)

Parameters

seekOrigin

MFByteStreamSeekOrigin

Specifies the origin of the seek as a member of the MFByteStreamSeekOrigin enumeration. The offset is calculated relative to this position.

seekOffset

Int64

Specifies the new position, as a byte offset from the seek origin.

cancelPendingIO

Boolean

Specifies whether all pending I/O requests are canceled after the seek request completes successfully.

currentPosition

Int64&

Receives the new position after the seek.

Returns

The new position after the seek.

SetCurrentPositionNative(Int64 position)

Sets the current read or write position.

public Int32 SetCurrentPositionNative(Int64 position)

Parameters

position

Int64

New position in the stream, as a byte offset from the start of the stream.

Returns

HRESULT

SetLengthNative(Int64 length)

Sets the length of the stream.

public Int32 SetLengthNative(Int64 length)

Parameters

length

Int64

The length of the stream in bytes.

Returns

HRESULT

Remarks

Use the Length property for easier usage with automated error handling.

Write(Byte[] buffer, Int32 count)

Writes data to the stream.

public Int32 Write(Byte[] buffer, Int32 count)

Parameters

buffer

Byte[]

Buffer that contains the data to write.

count

Int32

The number of bytes to write.

Returns

The number of bytes that were written.

Exceptions

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

count is bigger than the length of the buffer.

public Int32 WriteNative(IntPtr buffer, Int32 count, Int32& written)

Parameters

buffer

IntPtr

Pointer to a buffer that contains the data to write.

count

Int32

Size of the buffer in bytes.

written

Int32&

Receives the number of bytes that are written.

Returns

HRESULT

Properties

Capabilities

Gets the characteristics of the MFByteStream.

public MFByteStreamCapsFlags Capabilities { get; }

CurrentPosition

Gets or sets the current read/write position in bytes.

public Int64 CurrentPosition { get; set; }

IsEndOfStream

Gets a value indicating whether the CurrentPosition has reached the end of the stream.

public Boolean IsEndOfStream { get; }

Length

Gets or sets the length of the stream in bytes.

public Int64 Length { get; set; }