AVBlocks for .NET  3.0
Audio and Video Software Development Kit
MediaBuffer Class Reference

A buffer for media data. More...

Inheritance diagram for MediaBuffer:

Public Member Functions

 MediaBuffer ()
 Creates a MediaBuffer object with no data.
 
 MediaBuffer (byte[] data)
 Creates a buffer by using the supplied byte array for the internal data buffer.
 
 MediaBuffer (int bufferSize)
 Creates a buffer by specifying the size of the internal data buffer.
 
bool Attach (byte[] buffer, bool setData)
 Attaches an external buffer storage.
 
virtual object Clone ()
 Creates a deep copy of this object.
 
byte[] Detach ()
 Detaches an external data buffer.
 
bool SetData (int dataOffset, int dataSize)
 This is a convenience method that sets buffer data offset and size at once.
 

Properties

int DataOffset [get]
 The offset at which valid data starts in the data buffer.
 
int DataSize [get]
 The size of the data that is still valid in the data buffer.
 
bool External [get]
 Indicates that MediaBuffer uses an external data buffer.
 
byte[] Start [get]
 Data buffer.
 

Detailed Description

A buffer for media data.

MediaBuffer has a capacity which is the size of the buffer and data size which is the size of the actual data in the buffer. The buffer is a continuous block of memory. The valid data is also a continuous block. The data can start at any offset in the buffer.

Constructor & Destructor Documentation

◆ MediaBuffer() [1/2]

MediaBuffer ( byte[]  data)

Creates a buffer by using the supplied byte array for the internal data buffer.

Parameters
dataA byte array which is used by the new MediaBuffer instance.

◆ MediaBuffer() [2/2]

MediaBuffer ( int  bufferSize)

Creates a buffer by specifying the size of the internal data buffer.

Parameters
bufferSizeSpecifies the size of the internal storage

Member Function Documentation

◆ Attach()

bool Attach ( byte[]  buffer,
bool  setData 
)

Attaches an external buffer storage.

Parameters
bufferAn array that should be used as an external storage.
setDataSpecifies whether to auto set data with a size equal to the buffer size. If true the data size is set to the buffer size. If false data size is 0.
Returns
true The buffer is attached succefully, false otherwise.

◆ Clone()

virtual object Clone ( )
virtual

Creates a deep copy of this object.

Returns
A new MediaBuffer object.

Only the reference to the external buffer is copied when MediaBuffer does not own its data buffer, i.e. uses external / attached data. On the contrary, when MediaBuffer owns its data, a new copy of the data is created.

Exceptions
System.OutOfMemoryExceptionThe object cannot be cloned because there's not enough memory.
See also
MediaBuffer.External

References MediaBuffer.MediaBuffer().

Referenced by MediaSample.Clone().

◆ Detach()

byte[] Detach ( )

Detaches an external data buffer.

Returns
A reference to the detached array of bytes or null if no external buffer has been attached.

◆ SetData()

bool SetData ( int  dataOffset,
int  dataSize 
)

This is a convenience method that sets buffer data offset and size at once.

Parameters
dataOffsetThe offset in the buffer where valid data starts.
dataSizeThe size in bytes of the valid data in the buffer.
Returns
true if dataOffset and dataSize are accepted by the method and the valid data is set.

false if dataOffset and dataSize are not accepted by the method and the valid data is not set.

Referenced by MediaInfo.Push(), and Transcoder.Push().