Added hardware device/frame context Free() method

This commit is contained in:
Quentin Renard
2024-11-22 13:52:42 +01:00
parent 3f2badc117
commit 4f133cd508
4 changed files with 15 additions and 0 deletions

View File

@@ -136,6 +136,7 @@ func main() {
if s.hardwareDeviceContext, err = astiav.CreateHardwareDeviceContext(hardwareDeviceType, *hardwareDeviceName, nil, 0); err != nil {
log.Fatal(fmt.Errorf("main: creating hardware device context failed: %w", err))
}
defer s.hardwareDeviceContext.Free()
// Update decoder context
s.decCodecContext.SetHardwareDeviceContext(s.hardwareDeviceContext)

View File

@@ -53,6 +53,7 @@ func main() {
if err != nil {
log.Fatal(fmt.Errorf("main: creating hardware device context failed: %w", err))
}
defer hardwareDeviceContext.Free()
// Find encoder codec
encCodec := astiav.FindEncoderByName(*encoderCodecName)
@@ -85,6 +86,7 @@ func main() {
if hardwareFrameContext == nil {
log.Fatal("main: hardware frame context is nil")
}
defer hardwareFrameContext.Free()
// Get software pixel format
softwarePixelFormat := astiav.FindPixelFormatByName(*softwarePixelFormatName)

View File

@@ -29,3 +29,9 @@ 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)
}
}

View File

@@ -23,6 +23,12 @@ func AllocHardwareFrameContext(hdc *HardwareDeviceContext) *HardwareFrameContext
return newHardwareFrameContextFromC(C.av_hwframe_ctx_alloc(hdc.c))
}
func (hfc *HardwareFrameContext) Free() {
if hfc.c != nil {
C.av_buffer_unref(&hfc.c)
}
}
func (hfc *HardwareFrameContext) data() *C.AVHWFramesContext {
return (*C.AVHWFramesContext)(unsafe.Pointer((hfc.c.data)))
}