L0rem1psum feat hardware frame ctx (#92)

* feat: add hardware frame context

* fix: pr comments

* feat(example): add hardware encoding example

* Clean up

* Clean up

---------

Co-authored-by: Wu Wenxuan <sunshine.xuan5960@gmail.com>
This commit is contained in:
Quentin Renard
2024-10-23 15:45:39 +02:00
committed by GitHub
parent cd2a16de95
commit bc148523bc
5 changed files with 241 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ type CodecContext struct {
c *C.AVCodecContext
// We need to store this to unref it properly
hdc *HardwareDeviceContext
hfc *HardwareFrameContext
}
func newCodecContextFromC(c *C.AVCodecContext) *CodecContext {
@@ -38,6 +39,10 @@ func (cc *CodecContext) Free() {
C.av_buffer_unref(&cc.hdc.c)
cc.hdc = nil
}
if cc.hfc != nil {
C.av_buffer_unref(&cc.hfc.c)
cc.hfc = nil
}
if cc.c != nil {
// Make sure to clone the classer before freeing the object since
// the C free method may reset the pointer
@@ -317,6 +322,16 @@ func (cc *CodecContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) {
}
}
func (cc *CodecContext) SetHardwareFrameContext(hfc *HardwareFrameContext) {
if cc.hfc != nil {
C.av_buffer_unref(&cc.hfc.c)
}
cc.hfc = hfc
if cc.hfc != nil {
cc.c.hw_frames_ctx = C.av_buffer_ref(cc.hfc.c)
}
}
func (cc *CodecContext) ExtraHardwareFrames() int {
return int(cc.c.extra_hw_frames)
}
@@ -367,5 +382,4 @@ func goAstiavCodecContextGetFormat(cc *C.AVCodecContext, pfsCPtr *C.enum_AVPixel
// Callback
return C.enum_AVPixelFormat(c(pfs))
}