Class AVBuffer
Represents a wrapper for an AVBufferRef in FFmpeg, which manages reference-counted buffers. Provides functionality for managing the lifetime, access, and manipulation of these buffers.
Inherited Members
Namespace: FFmpeg.Collections
Assembly: FFmpeg.dll
Syntax
public sealed class AVBuffer : IDisposable, IBuffer, IAVPointer<_AVBufferRef>
Properties
View SourceData
Declaration
public nint Data { get; }
Property Value
| Type | Description |
|---|---|
| nint |
IsNull
Gets a value indicating whether the buffer reference is null.
Declaration
public bool IsNull { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsReadOnly
Gets a value indicating whether the buffer is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | Thrown when the buffer reference is null. |
this[int]
Indexer to access or modify a byte at the specified index in the buffer.
Declaration
public byte this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The index of the byte to access or modify. |
Property Value
| Type | Description |
|---|---|
| byte |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the index is out of bounds. |
Length
Gets the length of the buffer in bytes. Returns 0 if the buffer reference is null.
Declaration
public int Length { get; }
Property Value
| Type | Description |
|---|---|
| int |
ReferenceCount
Gets the reference count of the buffer. Returns -1 if the buffer reference is null.
Declaration
public int ReferenceCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
View SourceAllocate(int)
Allocates a new buffer of the specified size.
Declaration
public static AVBuffer Allocate(int size)
Parameters
| Type | Name | Description |
|---|---|---|
| int | size | The size of the buffer to allocate in bytes. |
Returns
| Type | Description |
|---|---|
| AVBuffer | A new AVBuffer instance. |
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | Thrown when the buffer could not be allocated due to memory limitations. |
AllocateZ(int)
Allocates a new zero-initialized buffer of the specified size.
Declaration
public static AVBuffer AllocateZ(int size)
Parameters
| Type | Name | Description |
|---|---|---|
| int | size | The size of the buffer to allocate in bytes. |
Returns
| Type | Description |
|---|---|
| AVBuffer | A new AVBuffer instance with zeroed data. |
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | Thrown when the buffer could not be allocated due to memory limitations. |
AsSpan()
Returns a writable span of the buffer's data.
Declaration
public Span<byte> AsSpan()
Returns
| Type | Description |
|---|---|
| Span<byte> | A Span<T> representing the buffer's data. Returns an empty span if the buffer reference is null. |
Clone()
Clones the buffer, creating a new buffer that references the same data.
Declaration
public AVBuffer Clone()
Returns
| Type | Description |
|---|---|
| AVBuffer | A new AVBuffer that references the same data as the original. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | Thrown when the buffer reference is null. |
Copy()
Copies the data from the current buffer into a new buffer.
Declaration
public AVBuffer Copy()
Returns
| Type | Description |
|---|---|
| AVBuffer | A new AVBuffer instance with copied data. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | Thrown if the current buffer reference is null. |
| OutOfMemoryException | Thrown when the buffer could not be copied due to memory limitations. |
Dispose()
Releases the unmanaged resources used by the AVBuffer.
Declaration
public void Dispose()
~AVBuffer()
Finalizer to ensure unmanaged resources are released when the object is garbage collected.
Declaration
protected ~AVBuffer()
FromExisting(AVBuffer)
Creates a new buffer that references the same data as an existing buffer.
Declaration
public static AVBuffer FromExisting(AVBuffer buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| AVBuffer | buffer | The buffer to reference. |
Returns
| Type | Description |
|---|---|
| AVBuffer | A new AVBuffer that references the same data as the input buffer. |
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | Thrown when the new buffer could not be created due to memory limitations. |
MakeWriteable()
Ensures the buffer is writable, throwing an exception if it cannot be made writable.
Declaration
public void MakeWriteable()
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | Thrown if the buffer reference is null. |
| OutOfMemoryException | Thrown when the buffer could not be made writable due to memory limitations. |
ReplaceWith(AVBuffer)
Replaces the current buffer with another buffer, throwing an exception if replacement fails.
Declaration
public void ReplaceWith(AVBuffer src)
Parameters
| Type | Name | Description |
|---|---|---|
| AVBuffer | src | The source buffer to replace with. |
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | Thrown when the buffer could not be replaced due to memory limitations. |
ReplaceWith(IBuffer)
Replaces the current buffer with another buffer, which can be any object implementing IBuffer.
Declaration
public void ReplaceWith(IBuffer src)
Parameters
| Type | Name | Description |
|---|---|---|
| IBuffer | src | The source buffer implementing IBuffer. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | Thrown when the source buffer is null. |
| OutOfMemoryException | Thrown if the replace operation fails. |
Resize(int)
Resizes the buffer to the specified size, throwing an exception if resizing fails.
Declaration
public void Resize(int size)
Parameters
| Type | Name | Description |
|---|---|---|
| int | size | The new size of the buffer in bytes. |
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | Thrown when the buffer could not be resized due to memory limitations. |
TryMakeWriteable()
Tries to make the buffer writable, if it is not already.
Declaration
public bool TryMakeWriteable()
Returns
| Type | Description |
|---|---|
| bool | true if the buffer was successfully made writable; otherwise, false. |
TryReplaceWith(AVBuffer)
Tries to replace the current buffer with another buffer.
Declaration
public bool TryReplaceWith(AVBuffer src)
Parameters
| Type | Name | Description |
|---|---|---|
| AVBuffer | src | The source buffer to replace with. |
Returns
| Type | Description |
|---|---|
| bool | true if the buffer was successfully replaced; otherwise, false. |
TryReplaceWith(IBuffer)
Tries to replace the current buffer with another buffer implementing IBuffer.
Declaration
public bool TryReplaceWith(IBuffer src)
Parameters
| Type | Name | Description |
|---|---|---|
| IBuffer | src | The source buffer implementing IBuffer. |
Returns
| Type | Description |
|---|---|
| bool | true if the buffer was successfully replaced; otherwise, false. |
TryResize(int)
Tries to resize the buffer to the specified size.
Declaration
public bool TryResize(int size)
Parameters
| Type | Name | Description |
|---|---|---|
| int | size | The new size of the buffer in bytes. |
Returns
| Type | Description |
|---|---|
| bool | true if the buffer was successfully resized; otherwise, false. |