mirror of
https://github.com/asticode/go-astiav.git
synced 2025-11-01 12:02:48 +08:00
Fixed hard device context unref
This commit is contained in:
@@ -35,6 +35,8 @@ import (
|
|||||||
// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/avcodec.h#L383
|
// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/avcodec.h#L383
|
||||||
type CodecContext struct {
|
type CodecContext struct {
|
||||||
c *C.struct_AVCodecContext
|
c *C.struct_AVCodecContext
|
||||||
|
// We need to store this to unref it properly
|
||||||
|
hdc *HardwareDeviceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func AllocCodecContext(c *Codec) *CodecContext {
|
func AllocCodecContext(c *Codec) *CodecContext {
|
||||||
@@ -53,8 +55,9 @@ func newCodecContextFromC(c *C.struct_AVCodecContext) *CodecContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cc *CodecContext) Free() {
|
func (cc *CodecContext) Free() {
|
||||||
if cc.c.hw_device_ctx != nil {
|
if cc.hdc != nil {
|
||||||
C.av_buffer_unref(&cc.c.hw_device_ctx)
|
C.av_buffer_unref(&cc.hdc.c)
|
||||||
|
cc.hdc = nil
|
||||||
}
|
}
|
||||||
C.avcodec_free_context(&cc.c)
|
C.avcodec_free_context(&cc.c)
|
||||||
}
|
}
|
||||||
@@ -293,10 +296,13 @@ func (cc *CodecContext) SendFrame(f *Frame) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cc *CodecContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) {
|
func (cc *CodecContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) {
|
||||||
if cc.c.hw_device_ctx != nil {
|
if cc.hdc != nil {
|
||||||
C.av_buffer_unref(&cc.c.hw_device_ctx)
|
C.av_buffer_unref(&cc.hdc.c)
|
||||||
|
}
|
||||||
|
cc.hdc = hdc
|
||||||
|
if cc.hdc != nil {
|
||||||
|
cc.c.hw_device_ctx = C.av_buffer_ref(cc.hdc.c)
|
||||||
}
|
}
|
||||||
cc.c.hw_device_ctx = C.av_buffer_ref(hdc.c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CodecContextPixelFormatCallback func(pfs []PixelFormat) PixelFormat
|
type CodecContextPixelFormatCallback func(pfs []PixelFormat) PixelFormat
|
||||||
|
|||||||
Reference in New Issue
Block a user