mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-30 19:16:22 +08:00
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:
@@ -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))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user