Class VersatileBuffer
Represents an abstract buffer for holding media data and general-purpose data.
public abstract class VersatileBuffer
- Inheritance
-
VersatileBuffer
- Inherited Members
- Extension Methods
Remarks
This class does not provide direct access to the underlying data storage in order to virtualize access and allow wrapping of both managed and unmanaged data. Concrete implementations handle platform-specific memory management.
Fields
EndPointAttribute
ExtraData key for endpoint information.
public static readonly string EndPointAttribute
Field Value
FilePositionAttribute
ExtraData key for file position.
public static readonly string FilePositionAttribute
Field Value
FlagsAttribute
ExtraData key for buffer flags.
public static readonly string FlagsAttribute
Field Value
LocalEndPointAttribute
ExtraData key for local endpoint information.
public static readonly string LocalEndPointAttribute
Field Value
MetadataAttribute
ExtraData key for metadata dictionary.
public static readonly string MetadataAttribute
Field Value
NewMediaTypeAttribute
ExtraData key for new media type notification.
public static readonly string NewMediaTypeAttribute
Field Value
NtpTimestampAttribute
ExtraData key for NTP timestamp.
public static readonly string NtpTimestampAttribute
Field Value
PoisAttribute
ExtraData key for points of interest.
public static readonly string PoisAttribute
Field Value
ProgramIndexAttribute
ExtraData key for program index in multi-program streams.
public static readonly string ProgramIndexAttribute
Field Value
RemoteEndPointAttribute
ExtraData key for remote endpoint information.
public static readonly string RemoteEndPointAttribute
Field Value
Properties
ActualSize
Gets or sets the currently used buffer size in bytes.
public virtual int ActualSize { get; set; }
Property Value
BufferType
Gets the type of the specific implementation of this buffer.
public VersatileBuffer.BufferType_t BufferType { get; protected set; }
Property Value
Remarks
Used for fast buffer type detection without involving reflection.
CleanPoint
Gets or sets a value indicating whether this sample is a clean point.
public bool CleanPoint { get; set; }
Property Value
Discontinuity
Gets or sets a value indicating whether this is a discontinuity sample.
public bool Discontinuity { get; set; }
Property Value
Dts
Gets or sets the Decoding Timestamp (DTS) of the media sample.
public long Dts { get; set; }
Property Value
Duration
Gets or sets the duration of the media sample.
public long Duration { get; set; }
Property Value
ExtraData
Gets the dictionary of extra data associated with this buffer.
public Dictionary<string, object> ExtraData { get; }
Property Value
Id
Gets the buffer's unique identifier.
public long Id { get; protected set; }
Property Value
IsDirectPointer
Gets a value indicating whether the Pointer property is a direct unmanaged pointer to the actual data storage.
public bool IsDirectPointer { get; protected set; }
Property Value
Remarks
If this property is false, ReleasePointer(bool) must be called immediately after each data usage
to synchronize temporary unmanaged data with the actual data storage and to prevent holding a temporary buffer for too long.
this[int]
Gets or sets byte at the specified position of the buffer
public byte this[int position] { get; set; }
Parameters
positionintPosition to read byte from or write byte to
Property Value
- byte
Byte value at the specified position
KeyFrame
Gets or sets a value indicating whether this sample is a key frame.
public bool KeyFrame { get; set; }
Property Value
Pointer
Gets the unmanaged pointer to the underlying buffer.
public abstract nint Pointer { get; }
Property Value
Remarks
This pointer should only be used when there is no alternative, such as when a pointer must be provided to unmanaged code. A successful call to LockPointer() is mandatory before using this property. The ReleasePointer(bool) must be called when the pointer is no longer needed to prevent managed buffer being pinned for too long.
Position
Gets or sets current position in a buffer. This is just a cursor used by some long lasting operations to store current state.
public virtual int Position { get; set; }
Property Value
Pts
Gets or sets the Presentation Timestamp (PTS) of the media sample.
public long Pts { get; set; }
Property Value
RefCount
Gets the current reference count of the buffer.
public abstract int RefCount { get; }
Property Value
Size
Gets the total buffer size in bytes.
public int Size { get; protected set; }
Property Value
StreamIndex
Gets or sets the stream index.
public int StreamIndex { get; set; }
Property Value
Methods
AddRef()
Increments the reference count by one.
public abstract int AddRef()
Returns
- int
The current reference count after incrementing.
Append(byte[])
Appends data from specified array to current buffer and adjusts actual data size
public abstract void Append(byte[] data)
Parameters
databyte[]Array to append data from
Append(byte[], int, int)
Appends data from specified array to current buffer and adjusts actual data size
public abstract void Append(byte[] data, int offset, int size)
Parameters
databyte[]Array to append data from
offsetintOffset to start copying from
sizeintNumber of bytes to append
Append(Stream, int)
Appends data from specified stream to current buffer and adjusts actual data size
public abstract void Append(Stream stream, int size)
Parameters
Append(nint, int)
Appends data from specified unmanaged pointer to current buffer and adjusts actual data size
public abstract void Append(nint data, int size)
Parameters
Append(ReadOnlySpan<byte>)
Appends data from specified span to current buffer and adjusts actual data size
public abstract void Append(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>Span to append data from
Append(EndianBinaryReader, int)
Appends data from specified reader to current buffer and adjusts actual data size
public abstract void Append(EndianBinaryReader reader, int size)
Parameters
readerEndianBinaryReaderReader to append data from
sizeintNumber of bytes to append
Append(VersatileBuffer, int, int)
Appends data from specified buffer to current buffer and adjusts actual data size
public abstract void Append(VersatileBuffer buffer, int offset, int size)
Parameters
bufferVersatileBufferBuffer to append data from
offsetintOffset to start copying from
sizeintNumber of bytes to append
CleanUp()
Resets the buffer to its initial empty state.
public virtual void CleanUp()
Clone(bool)
Creates a copy of this buffer.
public abstract VersatileBuffer Clone(bool shallow = false)
Parameters
shallowboolIf
true, creates a shallow copy that shares the underlying data; iffalse, creates a deep copy with its own data.
Returns
- VersatileBuffer
A new buffer instance that is a copy of this buffer.
CopyAttributes(VersatileBuffer)
Copies all attributes (excluding data) from this buffer to the specified buffer.
public virtual void CopyAttributes(VersatileBuffer copyTo)
Parameters
copyToVersatileBufferThe target buffer to copy attributes to.
CopyTo(int, byte[], int, int)
Copies specified number of bytes from current buffer to specified managed buffer.
public abstract void CopyTo(int fromPosition, byte[] data, int offset, int size)
Parameters
fromPositionintInternal buffer position to copy data from
databyte[]Array to copy data to
offsetintOffset to start copying to
sizeintNumber of bytes to copy
CopyTo(int, Stream, int)
Copies specified number of bytes from current buffer to specified stream.
public abstract void CopyTo(int fromPosition, Stream stream, int size)
Parameters
fromPositionintInternal buffer position to copy data from
streamStreamStream to copy data to
sizeintNumber of bytes to copy
CopyTo(int, nint, int)
Copies specified number of bytes from current buffer to specified unmanaged pointer.
public abstract void CopyTo(int fromPosition, nint data, int size)
Parameters
fromPositionintInternal buffer position to copy data from
datanintData pointer to copy data to
sizeintNumber of bytes to copy
CopyTo(int, Span<byte>)
Copies specified number of bytes from current buffer to specified managed buffer.
public abstract void CopyTo(int fromPosition, Span<byte> data)
Parameters
Fill(int, int, byte)
Fills specified range with specified value.
public abstract void Fill(int fromPosition, int size, byte fillValue)
Parameters
fromPositionintInternal buffer position to fill from
sizeintNumber of bytes to fill
fillValuebyteValue to fill
Flush(int)
Flushes the buffer data before the specified position and moves remaining data to the start of the buffer. Actual data size is adjusted accordingly.
public abstract void Flush(int bytesToRemove = -1)
Parameters
bytesToRemoveintNumber of bytes to remove. If it's equal to -1 then current buffer position is used.
GetByte(int)
Gets byte at the specified position of the buffer
public abstract byte GetByte(int position)
Parameters
positionintPosition to read byte from
Returns
- byte
Byte value at the specified position
Insert(byte[], bool)
Inserts data from specified array to current buffer at current position. Actual data size remains intact.
public abstract void Insert(byte[] data, bool adjustPosition = true)
Parameters
databyte[]Array to insert data from
adjustPositionboolWhether to adjust current position after the operation is done
Insert(byte[], int, int, bool)
Inserts data from specified array to current buffer at current position. Actual data size remains intact.
public abstract void Insert(byte[] data, int offset, int size, bool adjustPosition = true)
Parameters
databyte[]Array to insert data from
offsetintOffset to start copying from
sizeintNumber of bytes to insert
adjustPositionboolWhether to adjust current position after the operation is done
Insert(int, byte[], int, int, bool)
Inserts data from specified array to current buffer at specified position. Actual data size remains intact.
public abstract void Insert(int copyToPosition, byte[] data, int offset, int size, bool adjustPosition = true)
Parameters
copyToPositionintLocal buffer position to start insertion from
databyte[]Array to insert data from
offsetintOffset to start copying from
sizeintNumber of bytes to insert
adjustPositionboolWhether to adjust current position after the operation is done
Insert(int, VersatileBuffer, int, int, bool)
Inserts data from specified buffer to current buffer at specified position. Actual data size remains intact.
public abstract void Insert(int copyToPosition, VersatileBuffer buffer, int offset, int size, bool adjustPosition = true)
Parameters
copyToPositionintLocal buffer position to start insertion from
bufferVersatileBufferBuffer to insert data from
offsetintOffset to start copying from
sizeintNumber of bytes to insert
adjustPositionboolWhether to adjust current position after the operation is done
LockPointer()
Initializes unmanaged pointer to the underlying buffer. This function must only be called if there is no other choice, such as when pointer must be provided to unmanaged code. If the function returns false then pointer has not been initialized and therefore Pointer property must not be used. For example, false can be returned when LOH compaction is in progress.
public abstract bool LockPointer()
Returns
- bool
True if operation was successful and pointer has been initialized, false otherwise
ReadFrom(Stream)
Reads data from the specified stream and de-serialize object
public abstract void ReadFrom(Stream stream)
Parameters
streamStreamStream to read object from
ReadFrom(EndianBinaryReader)
Reads data using the specified reader and de-serialize object
public abstract void ReadFrom(EndianBinaryReader reader)
Parameters
readerEndianBinaryReaderReader to read object with
Release()
Decrements the reference count by one.
public abstract int Release()
Returns
- int
The current reference count after decrementing.
Remarks
When the reference count reaches zero, the buffer is returned to its allocator.
ReleasePointer(bool)
Releases unmanaged pointer to the underlying buffer.
public abstract void ReleasePointer(bool bufferDirty)
Parameters
bufferDirtyboolWhether unmanaged buffer is dirty. Can be used to copy updated data back to actual buffer if proxy buffer is used to provide unmanaged pointer.
Rotate(long)
Replaces current buffer with another buffer from the same allocator if it's locked for too long. Necessary for long locked buffers to allow allocator to de-allocate memory when possible and subsequent compaction during off-peak hours. Method copies data and attributes from current buffer to the new one.
public abstract VersatileBuffer Rotate(long mediaTime = -9223372036854775808)
Parameters
mediaTimelong
Returns
- VersatileBuffer
The new buffer if current one was locked for too long or the same buffer otherwise
SetByte(int, byte)
Sets byte at the specified position of the buffer
public abstract void SetByte(int position, byte val)
Parameters
WriteTo(Stream)
Serializes object itself and all contained data and writes it into the specified stream
public abstract void WriteTo(Stream stream)
Parameters
streamStreamStream to write object to
WriteTo(EndianBinaryWriter)
Serializes object itself and all contained data and writes it using the specified writer
public abstract void WriteTo(EndianBinaryWriter writer)
Parameters
writerEndianBinaryWriterWriter to write object with