forked from sdcb/Sdcb.FFmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
170 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Sdcb.FFmpeg.Common; | ||
using Sdcb.FFmpeg.Raw; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using static Sdcb.FFmpeg.Raw.ffmpeg; | ||
|
||
namespace Sdcb.FFmpeg.Utils; | ||
|
||
public unsafe partial class BufferRef : SafeHandle | ||
{ | ||
/// <summary>Allocate an AVBuffer of the given size using av_malloc().</summary> | ||
public static BufferRef Alloc(int size) => new BufferRef(av_buffer_alloc((ulong)size), isOwner: true); | ||
|
||
/// <summary>Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.</summary> | ||
public static BufferRef AllocZ(int size) => new BufferRef(av_buffer_allocz((ulong)size), isOwner: true); | ||
|
||
/// <summary>Create a new reference to an AVBuffer.</summary> | ||
public static BufferRef Ref(BufferRef other) => new BufferRef(av_buffer_ref(other), isOwner: true); | ||
|
||
/// <summary>Returns 1 if the caller may write to the data referred to by buf (which is true if and only if buf is the only reference to the underlying AVBuffer). Return 0 otherwise. A positive answer is valid until av_buffer_ref() is called on buf.</summary> | ||
public bool IsWritable => av_buffer_is_writable(this) != 0; | ||
|
||
/// <summary>Returns the opaque parameter set by av_buffer_create.</summary> | ||
public IntPtr Opaque => (IntPtr)av_buffer_get_opaque(this); | ||
|
||
public int RefCount => av_buffer_get_ref_count(this); | ||
|
||
/// <summary>Free a given reference and automatically free the buffer if there are no more references to it.</summary> | ||
public void Unref() | ||
{ | ||
AVBufferRef* ptr = this; | ||
av_buffer_unref(&ptr); | ||
handle = (IntPtr)ptr; | ||
} | ||
|
||
/// <summary>Create a writable reference from a given buffer reference, avoiding data copy if possible.</summary> | ||
public void MakeWritable() | ||
{ | ||
AVBufferRef* ptr = this; | ||
av_buffer_make_writable(&ptr).ThrowIfError(); | ||
handle = (IntPtr)ptr; | ||
} | ||
|
||
/// <summary>Reallocate a given buffer.</summary> | ||
/// <param name="size">required new buffer size.</param> | ||
public void Realloc(int size) | ||
{ | ||
AVBufferRef* ptr = this; | ||
av_buffer_realloc(&ptr, (ulong)size).ThrowIfError(); | ||
handle = (IntPtr)ptr; | ||
} | ||
|
||
/// <summary>Ensure dst refers to the same data as src.</summary> | ||
/// <param name="src">Pointer to either a valid buffer reference or NULL. On success, this will point to a buffer reference equivalent to src. On failure, dst will be left untouched.</param> | ||
public void Replace(BufferRef src) | ||
{ | ||
AVBufferRef* ptr = this; | ||
av_buffer_replace(&ptr, src).ThrowIfError(); | ||
handle = (IntPtr)ptr; | ||
} | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
Unref(); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This file was genereated from Sdcb.FFmpeg.AutoGen, DO NOT CHANGE DIRECTLY. | ||
#nullable enable | ||
using Sdcb.FFmpeg.Common; | ||
using Sdcb.FFmpeg.Codecs; | ||
using Sdcb.FFmpeg.Formats; | ||
using Sdcb.FFmpeg.Raw; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Sdcb.FFmpeg.Utils; | ||
|
||
/// <summary> | ||
/// <para>A reference to a data buffer.</para> | ||
/// <see cref="AVBufferRef" /> | ||
/// </summary> | ||
public unsafe partial class BufferRef : SafeHandle | ||
{ | ||
protected AVBufferRef* _ptr => (AVBufferRef*)handle; | ||
|
||
public static implicit operator AVBufferRef*(BufferRef data) => data != null ? (AVBufferRef*)data.handle : null; | ||
|
||
protected BufferRef(AVBufferRef* ptr, bool isOwner): base(NativeUtils.NotNull((IntPtr)ptr), isOwner) | ||
{ | ||
} | ||
|
||
public static BufferRef FromNative(AVBufferRef* ptr, bool isOwner) => new BufferRef(ptr, isOwner); | ||
|
||
public static BufferRef? FromNativeOrNull(AVBufferRef* ptr, bool isOwner) => ptr == null ? null : new BufferRef(ptr, isOwner); | ||
|
||
public override bool IsInvalid => handle == IntPtr.Zero; | ||
|
||
/// <summary> | ||
/// <para>original type: AVBuffer*</para> | ||
/// <see cref="AVBufferRef.buffer" /> | ||
/// </summary> | ||
public IntPtr Buffer | ||
{ | ||
get => (IntPtr)_ptr->buffer; | ||
set => _ptr->buffer = (AVBuffer*)value; | ||
} | ||
|
||
/// <summary> | ||
/// <para>original type: byte*</para> | ||
/// <para>The data buffer. It is considered writable if and only if this is the only reference to the buffer, in which case av_buffer_is_writable() returns 1.</para> | ||
/// <see cref="AVBufferRef.data" /> | ||
/// </summary> | ||
public DataPointer Data => new DataPointer(_ptr->data, (int)_ptr->size)!; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters