mirror of
https://github.com/asticode/go-astiav.git
synced 2025-09-26 20:21:15 +08:00
Now using av_malloc/av_free instead of malloc/free
This commit is contained in:
4
bytes.go
4
bytes.go
@@ -12,11 +12,11 @@ import (
|
||||
|
||||
func stringFromC(len int, fn func(buf *C.char, size C.size_t) error) (string, error) {
|
||||
size := C.size_t(len)
|
||||
buf := (*C.char)(C.malloc(size))
|
||||
buf := (*C.char)(C.av_malloc(size))
|
||||
if buf == nil {
|
||||
return "", errors.New("astiav: buf is nil")
|
||||
}
|
||||
defer C.free(unsafe.Pointer(buf))
|
||||
defer C.av_free(unsafe.Pointer(buf))
|
||||
if err := fn(buf, size); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ func AllocIOContext(bufferSize int, writable bool, readFunc IOContextReadFunc, s
|
||||
}()
|
||||
|
||||
// Since go doesn't allow c to store pointers to go data, we need to create this C pointer
|
||||
handlerID := C.malloc(C.size_t(1))
|
||||
handlerID := C.av_malloc(C.size_t(1))
|
||||
if handlerID == nil {
|
||||
err = errors.New("astiav: allocating handler id failed")
|
||||
return
|
||||
@@ -66,7 +66,7 @@ func AllocIOContext(bufferSize int, writable bool, readFunc IOContextReadFunc, s
|
||||
// Make sure handler id is freed in case of error
|
||||
defer func() {
|
||||
if err != nil {
|
||||
C.free(handlerID)
|
||||
C.av_free(handlerID)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include <libavformat/avio.h>
|
||||
#include <libavutil/mem.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int astiavInterruptCallback(void *ret)
|
||||
@@ -8,7 +9,7 @@ int astiavInterruptCallback(void *ret)
|
||||
|
||||
AVIOInterruptCB* astiavNewInterruptCallback(int *ret)
|
||||
{
|
||||
AVIOInterruptCB* c = malloc(sizeof(AVIOInterruptCB));
|
||||
AVIOInterruptCB* c = av_malloc(sizeof(AVIOInterruptCB));
|
||||
c->callback = astiavInterruptCallback;
|
||||
c->opaque = ret;
|
||||
return c;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package astiav
|
||||
|
||||
//#include "io_interrupter.h"
|
||||
//#include <libavutil/mem.h>
|
||||
//#include <stdlib.h>
|
||||
import "C"
|
||||
import "unsafe"
|
||||
@@ -18,7 +19,7 @@ func NewIOInterrupter() *IOInterrupter {
|
||||
|
||||
func (i *IOInterrupter) Free() {
|
||||
if i.c != nil {
|
||||
C.free(unsafe.Pointer(i.c))
|
||||
C.av_free(unsafe.Pointer(i.c))
|
||||
i.c = nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user