Update codec context and frame deallocation methods

Replaced avcodec_close with avcodec_free_context for proper resource management.
This commit is contained in:
firmwarecostum
2026-09-07 07:14:16 +08:00
committed by GitHub
parent 80431b737c
commit e4703fedc3
+3 -3
View File
@@ -1527,13 +1527,13 @@ func newDecoder(codecName string) (*Decoder, error) {
res := C.avcodec_open2(codecCtx, codec, nil)
if res < 0 {
C.avcodec_close(codecCtx)
C.avcodec_free_context(&codecCtx)
return nil, fmt.Errorf("avcodec_open2() failed")
}
srcFrame := C.av_frame_alloc()
if srcFrame == nil {
C.avcodec_close(codecCtx)
C.avcodec_free_context(&codecCtx)
return nil, fmt.Errorf("av_frame_alloc() failed")
}
@@ -1549,7 +1549,7 @@ func (d *Decoder) Close() {
C.av_frame_free(&d.srcFrame)
}
C.av_frame_free(&d.srcFrame)
C.avcodec_close(d.codecCtx)
C.avcodec_free_context(&d.codecCtx)
}
func (d *Decoder) decode(nalu []byte) (image.YCbCr, error) {