From 656585a6d8a8d4fa350ed5b645e25290884956a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20V=C4=83n=20Ph=C6=B0=E1=BB=9Bc?= Date: Wed, 10 Jun 2020 17:32:59 +0700 Subject: [PATCH 1/5] fix leak mem when set stream name for interrupt data --- avformat/avformat.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/avformat/avformat.go b/avformat/avformat.go index fb6a030..493d461 100644 --- a/avformat/avformat.go +++ b/avformat/avformat.go @@ -59,7 +59,9 @@ package avformat //} // //static AVIOInterruptData* createInterruptData() { -// return (AVIOInterruptData*) av_malloc(sizeof(AVIOInterruptData*)); +// AVIOInterruptData* interruptData = (AVIOInterruptData*) av_malloc(sizeof(AVIOInterruptData*)); +// interruptData->streamName = NULL; +// return interruptData; //} // // @@ -1046,6 +1048,9 @@ type IOInterruptData struct { func (interruptData *IOInterruptData) SetStreamName(streamName string) { cStreamName := C.CString(streamName) cAVIOInterruptData := (*C.AVIOInterruptData)(unsafe.Pointer(interruptData.CAVIOInterruptData)) + if unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName) != nil { + C.free(unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName)) + } cAVIOInterruptData.streamName = cStreamName } @@ -1058,7 +1063,9 @@ func (interruptData *IOInterruptData) SetLastTimestamp(lastTimestamp int) { func (interruptData *IOInterruptData) Free() { cAVIOInterruptData := unsafe.Pointer(interruptData.CAVIOInterruptData) - C.free(unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName)) + if unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName) != nil { + C.free(unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName)) + } C.av_free(cAVIOInterruptData) } From 99789d6e966f48c2817b2918c063fc2188f81bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20V=C4=83n=20Ph=C6=B0=E1=BB=9Bc?= Date: Mon, 6 Jul 2020 10:31:30 +0700 Subject: [PATCH 2/5] remove leak mem --- avformat/avformat.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/avformat/avformat.go b/avformat/avformat.go index 493d461..3fb4065 100644 --- a/avformat/avformat.go +++ b/avformat/avformat.go @@ -60,7 +60,6 @@ package avformat // //static AVIOInterruptData* createInterruptData() { // AVIOInterruptData* interruptData = (AVIOInterruptData*) av_malloc(sizeof(AVIOInterruptData*)); -// interruptData->streamName = NULL; // return interruptData; //} // @@ -1046,12 +1045,10 @@ type IOInterruptData struct { } func (interruptData *IOInterruptData) SetStreamName(streamName string) { - cStreamName := C.CString(streamName) - cAVIOInterruptData := (*C.AVIOInterruptData)(unsafe.Pointer(interruptData.CAVIOInterruptData)) - if unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName) != nil { - C.free(unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName)) - } - cAVIOInterruptData.streamName = cStreamName + //cStreamName := C.CString(streamName) + //defer C.free(unsafe.Pointer(cStreamName)) + //cAVIOInterruptData := (*C.AVIOInterruptData)(unsafe.Pointer(interruptData.CAVIOInterruptData)) + //C.av_strlcpy(&cAVIOInterruptData.streamName[0], cStreamName, 256) } func (interruptData *IOInterruptData) SetLastTimestamp(lastTimestamp int) { @@ -1063,9 +1060,6 @@ func (interruptData *IOInterruptData) SetLastTimestamp(lastTimestamp int) { func (interruptData *IOInterruptData) Free() { cAVIOInterruptData := unsafe.Pointer(interruptData.CAVIOInterruptData) - if unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName) != nil { - C.free(unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName)) - } C.av_free(cAVIOInterruptData) } From 6d051e90adb4baecc3e4999063a41a5452bbec35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20V=C4=83n=20Ph=C6=B0=E1=BB=9Bc?= Date: Wed, 8 Jul 2020 09:40:48 +0700 Subject: [PATCH 3/5] free pointer interrupt data --- avformat/avformat.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avformat/avformat.go b/avformat/avformat.go index 3fb4065..00aaf65 100644 --- a/avformat/avformat.go +++ b/avformat/avformat.go @@ -55,7 +55,7 @@ package avformat //} // //static void free_pointer(void *ptr) { -// av_freep(ptr); +// av_freep(&ptr); //} // //static AVIOInterruptData* createInterruptData() { @@ -1060,7 +1060,7 @@ func (interruptData *IOInterruptData) SetLastTimestamp(lastTimestamp int) { func (interruptData *IOInterruptData) Free() { cAVIOInterruptData := unsafe.Pointer(interruptData.CAVIOInterruptData) - C.av_free(cAVIOInterruptData) + C.free_pointer(cAVIOInterruptData) } func NewIOInterruptDataFromC() *IOInterruptData { From c1bde5f290f057cc971a42c9b3c90938d35d03a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20V=C4=83n=20Ph=C6=B0=E1=BB=9Bc?= Date: Wed, 8 Jul 2020 15:55:57 +0700 Subject: [PATCH 4/5] set stream name for interrupt data --- avformat/avformat.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/avformat/avformat.go b/avformat/avformat.go index 00aaf65..99a242b 100644 --- a/avformat/avformat.go +++ b/avformat/avformat.go @@ -60,6 +60,7 @@ package avformat // //static AVIOInterruptData* createInterruptData() { // AVIOInterruptData* interruptData = (AVIOInterruptData*) av_malloc(sizeof(AVIOInterruptData*)); +// interruptData->streamName = NULL; // return interruptData; //} // @@ -1045,10 +1046,12 @@ type IOInterruptData struct { } func (interruptData *IOInterruptData) SetStreamName(streamName string) { - //cStreamName := C.CString(streamName) - //defer C.free(unsafe.Pointer(cStreamName)) - //cAVIOInterruptData := (*C.AVIOInterruptData)(unsafe.Pointer(interruptData.CAVIOInterruptData)) - //C.av_strlcpy(&cAVIOInterruptData.streamName[0], cStreamName, 256) + cStreamName := C.CString(streamName) + cAVIOInterruptData := (*C.AVIOInterruptData)(unsafe.Pointer(interruptData.CAVIOInterruptData)) + if unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName) != nil { + C.free(unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName)) + } + cAVIOInterruptData.streamName = cStreamName } func (interruptData *IOInterruptData) SetLastTimestamp(lastTimestamp int) { @@ -1060,6 +1063,9 @@ func (interruptData *IOInterruptData) SetLastTimestamp(lastTimestamp int) { func (interruptData *IOInterruptData) Free() { cAVIOInterruptData := unsafe.Pointer(interruptData.CAVIOInterruptData) + if unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName) != nil { + C.free(unsafe.Pointer((*C.AVIOInterruptData)(cAVIOInterruptData).streamName)) + } C.free_pointer(cAVIOInterruptData) } From 536acff6ae86bcd262c135a1ac231843555d302c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20V=C4=83n=20Ph=C6=B0=E1=BB=9Bc?= Date: Wed, 30 Sep 2020 17:46:51 +0700 Subject: [PATCH 5/5] add codecId pcm audio --- avcodec/avcodec.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/avcodec/avcodec.go b/avcodec/avcodec.go index 9c09c0d..00fafde 100644 --- a/avcodec/avcodec.go +++ b/avcodec/avcodec.go @@ -151,10 +151,12 @@ var ( type CodecID C.enum_AVCodecID const ( - CodecIDNone CodecID = C.AV_CODEC_ID_NONE - CodecIDMJpeg CodecID = C.AV_CODEC_ID_MJPEG - CodecIDLJpeg CodecID = C.AV_CODEC_ID_LJPEG - CodecIDAAC CodecID = C.AV_CODEC_ID_AAC + CodecIDNone CodecID = C.AV_CODEC_ID_NONE + CodecIDMJpeg CodecID = C.AV_CODEC_ID_MJPEG + CodecIDLJpeg CodecID = C.AV_CODEC_ID_LJPEG + CodecIDAAC CodecID = C.AV_CODEC_ID_AAC + CodecIDPCMALAW CodecID = C.AV_CODEC_ID_PCM_ALAW + CodecIDPCMMULAW CodecID = C.AV_CODEC_ID_PCM_MULAW ) type Flags int64