From d4abd8ded6da6f51df6d51c0edd4d2d161444e51 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 31 Jan 2024 14:52:23 +0100 Subject: [PATCH] Fixed hardware device context buffer unref --- codec_context.go | 6 ++++++ hardware_device_context.go | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/codec_context.go b/codec_context.go index fa34ccc..6302cef 100644 --- a/codec_context.go +++ b/codec_context.go @@ -53,6 +53,9 @@ func newCodecContextFromC(c *C.struct_AVCodecContext) *CodecContext { } func (cc *CodecContext) Free() { + if cc.c.hw_device_ctx != nil { + C.av_buffer_unref(&cc.c.hw_device_ctx) + } C.avcodec_free_context(&cc.c) } @@ -290,6 +293,9 @@ func (cc *CodecContext) SendFrame(f *Frame) error { } func (cc *CodecContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) { + if cc.c.hw_device_ctx != nil { + C.av_buffer_unref(&cc.c.hw_device_ctx) + } cc.c.hw_device_ctx = C.av_buffer_ref(hdc.c) } diff --git a/hardware_device_context.go b/hardware_device_context.go index 12b11ad..c832745 100644 --- a/hardware_device_context.go +++ b/hardware_device_context.go @@ -29,9 +29,3 @@ func CreateHardwareDeviceContext(t HardwareDeviceType, device string, options *D } return &hdc, nil } - -func (hdc *HardwareDeviceContext) Free() { - if hdc.c != nil { - C.av_buffer_unref(&hdc.c) - } -}