Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
l0rem1psum committed Sep 5, 2024
1 parent 6c2fa59 commit 84fc4e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions codec_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ func (cc *CodecContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) {
}

func (cc *CodecContext) SetHardwareFrameContext(hfc *HardwareFrameContext) {
if cc.c.hw_frames_ctx != nil {
C.av_buffer_unref(&cc.c.hw_frames_ctx)
if cc.hfc != nil {
C.av_buffer_unref(&cc.hfc.c)
}
cc.hfc = hfc
if cc.hfc != nil {
Expand Down
4 changes: 2 additions & 2 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (f *Frame) AllocBuffer(align int) error {
return newError(C.av_frame_get_buffer(f.c, C.int(align)))
}

func (f *Frame) AllocHWBuffer(hfc *HardwareFrameContext, align int) error {
return newError(C.av_hwframe_get_buffer(hfc.c, f.c, C.int(align)))
func (f *Frame) AllocHardwareBuffer(hfc *HardwareFrameContext) error {
return newError(C.av_hwframe_get_buffer(hfc.c, f.c, 0))
}

func (f *Frame) AllocImage(align int) error {
Expand Down
39 changes: 21 additions & 18 deletions hardware_frame_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,49 @@ package astiav
//#include <libavcodec/avcodec.h>
import "C"
import (
"fmt"
"unsafe"
)

// https://github.com/FFmpeg/FFmpeg/blob/n7.0/libavutil/hwcontext.h#L115
type HardwareFrameContext struct {
c *C.struct_AVBufferRef
}

func AllocHardwareFrameContext(hdc *HardwareDeviceContext) (*HardwareFrameContext, error) {
if hfc := C.av_hwframe_ctx_alloc(hdc.c); hfc != nil {
return &HardwareFrameContext{c: hfc}, nil
func newHardwareFrameContextFromC(c *C.struct_AVBufferRef) *HardwareFrameContext {
if c == nil {
return nil
}
return nil, fmt.Errorf("failed to allocate hardware frame context")
return &HardwareFrameContext{c: c}
}

func AllocHardwareFrameContext(hdc *HardwareDeviceContext) *HardwareFrameContext {
return newHardwareFrameContextFromC(C.av_hwframe_ctx_alloc(hdc.c))
}

func (hfc *HardwareFrameContext) data() *C.AVHWFramesContext {
return (*C.AVHWFramesContext)(unsafe.Pointer((hfc.c.data)))
}

func (hfc *HardwareFrameContext) SetWidth(width int) {
frameCtx := (*C.AVHWFramesContext)(unsafe.Pointer((hfc.c.data)))
frameCtx.width = C.int(width)
hfc.data().width = C.int(width)
}

func (hfc *HardwareFrameContext) SetHeight(height int) {
frameCtx := (*C.AVHWFramesContext)(unsafe.Pointer((hfc.c.data)))
frameCtx.height = C.int(height)
hfc.data().height = C.int(height)
}

func (hfc *HardwareFrameContext) SetFormat(format PixelFormat) {
frameCtx := (*C.AVHWFramesContext)(unsafe.Pointer((hfc.c.data)))
frameCtx.format = C.enum_AVPixelFormat(format)
func (hfc *HardwareFrameContext) SetPixelFormat(format PixelFormat) {
hfc.data().format = C.enum_AVPixelFormat(format)
}

func (hfc *HardwareFrameContext) SetSWFormat(swFormat PixelFormat) {
frameCtx := (*C.AVHWFramesContext)(unsafe.Pointer((hfc.c.data)))
frameCtx.sw_format = C.enum_AVPixelFormat(swFormat)
func (hfc *HardwareFrameContext) SetSoftwarePixelFormat(swFormat PixelFormat) {
hfc.data().sw_format = C.enum_AVPixelFormat(swFormat)
}

func (hfc *HardwareFrameContext) SetInitialPoolSize(initialPoolSize int) {
frameCtx := (*C.AVHWFramesContext)(unsafe.Pointer((hfc.c.data)))
frameCtx.initial_pool_size = C.int(initialPoolSize)
hfc.data().initial_pool_size = C.int(initialPoolSize)
}

func (hfc *HardwareFrameContext) Init() error {
func (hfc *HardwareFrameContext) Initialize() error {
return newError(C.av_hwframe_ctx_init(hfc.c))
}

0 comments on commit 84fc4e4

Please sign in to comment.