mirror of
https://github.com/qrtc/ffmpeg-dev-go.git
synced 2025-10-04 15:23:13 +08:00
2023-10-19 14:31:46 CST W42D4
This commit is contained in:
@@ -8,77 +8,77 @@ import "unsafe"
|
||||
|
||||
// AvMalloc allocates a memory block with alignment suitable for all memory accesses
|
||||
// (including vectors if available on the CPU).
|
||||
func AvMalloc(size uint) unsafe.Pointer {
|
||||
return (unsafe.Pointer)(C.av_malloc((C.size_t)(size)))
|
||||
func AvMalloc[T HelperInteger](size T) unsafe.Pointer {
|
||||
return C.av_malloc((C.size_t)(size))
|
||||
}
|
||||
|
||||
// AvMallocz allocates a memory block with alignment suitable for all memory accesses
|
||||
// (including vectors if available on the CPU) and zero all the bytes of the
|
||||
// block.
|
||||
func AvMallocz(size uint) unsafe.Pointer {
|
||||
return (unsafe.Pointer)(C.av_mallocz((C.size_t)(size)))
|
||||
func AvMallocz[T HelperInteger](size T) unsafe.Pointer {
|
||||
return C.av_mallocz((C.size_t)(size))
|
||||
}
|
||||
|
||||
// AvMallocArray allocates a memory block for an array with AvMalloc().
|
||||
func AvMallocArray(nmemb, size uint) unsafe.Pointer {
|
||||
return (unsafe.Pointer)(C.av_malloc_array((C.size_t)(nmemb), (C.size_t)(size)))
|
||||
func AvMallocArray[U, V HelperInteger](nmemb U, size V) unsafe.Pointer {
|
||||
return C.av_malloc_array((C.size_t)(nmemb), (C.size_t)(size))
|
||||
}
|
||||
|
||||
// AvMalloczArray allocates a memory block for an array with AvMallocz().
|
||||
func AvMalloczArray(nmemb, size uint) unsafe.Pointer {
|
||||
func AvMalloczArray[U, V HelperInteger](nmemb U, size V) unsafe.Pointer {
|
||||
return C.av_mallocz_array((C.size_t)(nmemb), (C.size_t)(size))
|
||||
}
|
||||
|
||||
// AvCalloc is non-inlined equivalent of AvMalloczArray().
|
||||
func AvCalloc(nmemb, size uint) unsafe.Pointer {
|
||||
func AvCalloc[U, V HelperInteger](nmemb U, size V) unsafe.Pointer {
|
||||
return C.av_calloc((C.size_t)(nmemb), (C.size_t)(size))
|
||||
}
|
||||
|
||||
// AvRealloc allocates, reallocates, or frees a block of memory.
|
||||
func AvRealloc(ptr unsafe.Pointer, size uint) unsafe.Pointer {
|
||||
return (unsafe.Pointer)(C.av_realloc(ptr, (C.size_t)(size)))
|
||||
func AvRealloc[T HelperInteger](ptr CVoidPointer, size T) unsafe.Pointer {
|
||||
return C.av_realloc(VoidPointer(ptr), (C.size_t)(size))
|
||||
}
|
||||
|
||||
// AvReallocp allocates, reallocates, or frees a block of memory through a pointer to a pointer.
|
||||
func AvReallocp(ptr unsafe.Pointer, size uint) int32 {
|
||||
return (int32)(C.av_reallocp(ptr, (C.size_t)(size)))
|
||||
func AvReallocp[T HelperInteger](ptr CVoidPointer, size T) int32 {
|
||||
return (int32)(C.av_reallocp(VoidPointer(ptr), (C.size_t)(size)))
|
||||
}
|
||||
|
||||
// AvReallocF allocates, reallocates, or frees a block of memory.
|
||||
func AvReallocF(ptr unsafe.Pointer, nelem, elsize uint) unsafe.Pointer {
|
||||
return (unsafe.Pointer)(C.av_realloc_f(ptr, (C.size_t)(nelem), (C.size_t)(elsize)))
|
||||
func AvReallocF[U, V HelperInteger](ptr CVoidPointer, nelem U, elsize V) unsafe.Pointer {
|
||||
return C.av_realloc_f(VoidPointer(ptr), (C.size_t)(nelem), (C.size_t)(elsize))
|
||||
}
|
||||
|
||||
// AvReallocpArray allocates, reallocates, or frees an array through a pointer to a pointer.
|
||||
func AvReallocpArray(ptr unsafe.Pointer, nmemb, size uint) int32 {
|
||||
return (int32)(C.av_reallocp_array(ptr, (C.size_t)(nmemb), (C.size_t)(size)))
|
||||
func AvReallocpArray[U, V HelperInteger](ptr CVoidPointer, nmemb U, size V) int32 {
|
||||
return (int32)(C.av_reallocp_array(VoidPointer(ptr), (C.size_t)(nmemb), (C.size_t)(size)))
|
||||
}
|
||||
|
||||
// AvFastRealloc reallocates the given buffer if it is not large enough, otherwise do nothing.
|
||||
func AvFastRealloc(ptr unsafe.Pointer, size *uint32, minSize uint) unsafe.Pointer {
|
||||
return (unsafe.Pointer)(C.av_fast_realloc(ptr, (*C.uint)(size), (C.size_t)(minSize)))
|
||||
func AvFastRealloc[T HelperInteger](ptr CVoidPointer, size *uint32, minSize T) unsafe.Pointer {
|
||||
return C.av_fast_realloc(VoidPointer(ptr), (*C.uint)(size), (C.size_t)(minSize))
|
||||
}
|
||||
|
||||
// AvFastMalloc allocates a buffer, reusing the given one if large enough.
|
||||
func AvFastMalloc(ptr unsafe.Pointer, size *uint32, minSize uint) {
|
||||
C.av_fast_malloc(ptr, (*C.uint)(size), (C.size_t)(minSize))
|
||||
func AvFastMalloc[T HelperInteger](ptr CVoidPointer, size *uint32, minSize T) {
|
||||
C.av_fast_malloc(VoidPointer(ptr), (*C.uint)(size), (C.size_t)(minSize))
|
||||
}
|
||||
|
||||
// AvFastMallocz allocates and clear a buffer, reusing the given one if large enough.
|
||||
func AvFastMallocz(ptr unsafe.Pointer, size *uint32, minSize uint) {
|
||||
C.av_fast_mallocz(ptr, (*C.uint)(size), (C.size_t)(minSize))
|
||||
func AvFastMallocz[T HelperInteger](ptr CVoidPointer, size *uint32, minSize T) {
|
||||
C.av_fast_mallocz(VoidPointer(ptr), (*C.uint)(size), (C.size_t)(minSize))
|
||||
}
|
||||
|
||||
// AvFree free a memory block which has been allocated with a function of AvMalloc()
|
||||
// or AvRealloc() family.
|
||||
func AvFree(ptr unsafe.Pointer) {
|
||||
C.av_free(ptr)
|
||||
func AvFree(ptr CVoidPointer) {
|
||||
C.av_free(VoidPointer(ptr))
|
||||
}
|
||||
|
||||
// AvFreep frees a memory block which has been allocated with a function of AvMalloc()
|
||||
// or AvRealloc() family, and set the pointer pointing to it to `NULL`.
|
||||
func AvFreep(ptr unsafe.Pointer) {
|
||||
C.av_freep(ptr)
|
||||
func AvFreep(ptr CVoidPointer) {
|
||||
C.av_freep(VoidPointer(ptr))
|
||||
}
|
||||
|
||||
// AvStrdup
|
||||
@@ -87,43 +87,43 @@ func AvStrdup(s *int8) *int8 {
|
||||
}
|
||||
|
||||
// AvStrndup
|
||||
func AvStrndup(s *int8, len uint) *int8 {
|
||||
func AvStrndup[T HelperInteger](s *int8, len T) *int8 {
|
||||
return (*int8)(C.av_strndup((*C.char)(s), (C.size_t)(len)))
|
||||
}
|
||||
|
||||
// AvMemdup duplicates a buffer with av_malloc().
|
||||
func AvMemdup(p unsafe.Pointer, size uint) unsafe.Pointer {
|
||||
return (unsafe.Pointer)(C.av_memdup(p, (C.size_t)(size)))
|
||||
func AvMemdup[T HelperInteger](p CVoidPointer, size T) unsafe.Pointer {
|
||||
return C.av_memdup(VoidPointer(p), (C.size_t)(size))
|
||||
}
|
||||
|
||||
// Overlapping memcpy() implementation.
|
||||
func av_memcpy_backptr(dst *uint8, back, cnt int32) {
|
||||
// AvMemcpyBackptr overlaps memcpy() implementation.
|
||||
func AvMemcpyBackptr(dst *uint8, back, cnt int32) {
|
||||
C.av_memcpy_backptr((*C.uint8_t)(dst), (C.int)(back), (C.int)(cnt))
|
||||
}
|
||||
|
||||
// AvDynarrayAdd adds the pointer to an element to a dynamic array.
|
||||
func AvDynarrayAdd(tabPtr unsafe.Pointer, nbPtr *int32, elem unsafe.Pointer) {
|
||||
C.av_dynarray_add(tabPtr, (*C.int)(nbPtr), elem)
|
||||
func AvDynarrayAdd(tabPtr CVoidPointer, nbPtr *int32, elem CVoidPointer) {
|
||||
C.av_dynarray_add(VoidPointer(tabPtr), (*C.int)(nbPtr), VoidPointer(elem))
|
||||
}
|
||||
|
||||
// AvDynarrayAddNofree adds an element to a dynamic array.
|
||||
func AvDynarrayAddNofree(tabPtr unsafe.Pointer, nbPtr *int32, elem unsafe.Pointer) int32 {
|
||||
return (int32)(C.av_dynarray_add_nofree(tabPtr, (*C.int)(nbPtr), elem))
|
||||
func AvDynarrayAddNofree(tabPtr CVoidPointer, nbPtr *int32, elem CVoidPointer) int32 {
|
||||
return (int32)(C.av_dynarray_add_nofree(VoidPointer(tabPtr), (*C.int)(nbPtr), VoidPointer(elem)))
|
||||
}
|
||||
|
||||
// AvDynarray2Add adds an element of size `elem_size` to a dynamic array.
|
||||
func AvDynarray2Add(tabPtr *unsafe.Pointer, nbPtr *int32,
|
||||
elemSize uint, elemData *uint8) unsafe.Pointer {
|
||||
return (unsafe.Pointer)(C.av_dynarray2_add(tabPtr,
|
||||
(*C.int)(nbPtr), (C.size_t)(elemSize), (*C.uint8_t)(elemData)))
|
||||
func AvDynarray2Add[T HelperInteger](tabPtr CVoidPointerPointer, nbPtr *int32,
|
||||
elemSize T, elemData *uint8) unsafe.Pointer {
|
||||
return C.av_dynarray2_add(VoidPointerPointer(tabPtr),
|
||||
(*C.int)(nbPtr), (C.size_t)(elemSize), (*C.uint8_t)(elemData))
|
||||
}
|
||||
|
||||
// AvSizeMult multiplies two `size_t` values checking for overflow.
|
||||
func AvSizeMult(a, b uint, r *uint) int32 {
|
||||
func AvSizeMult[T HelperInteger](a, b T, r *uint) int32 {
|
||||
return (int32)(C.av_size_mult((C.size_t)(a), (C.size_t)(b), (*C.size_t)(unsafe.Pointer(r))))
|
||||
}
|
||||
|
||||
// AvMaxAlloc sets the maximum size that may be allocated in one block.
|
||||
func AvMaxAlloc(max uint) {
|
||||
func AvMaxAlloc[T HelperInteger](max T) {
|
||||
C.av_max_alloc((C.size_t)(max))
|
||||
}
|
||||
|
Reference in New Issue
Block a user