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) - } -}