Skip to content

Commit

Permalink
Renamed to HardwareFramesContext
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Dec 20, 2024
1 parent 48e9c04 commit 805ca1b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 32 deletions.
4 changes: 4 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.30.0

- `HardwareFrameContext` has been renamed to `HardwareFramesContext`

# v0.29.0

- `NewFilterContext` has been removed, use `NewBuffersinkFilterContext` or `NewBuffersrcFilterContext` instead
Expand Down
2 changes: 1 addition & 1 deletion buffersrc_filter_context_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (bfcp *BuffersrcFilterContextParameters) SetFramerate(f Rational) {
}

// https://ffmpeg.org/doxygen/7.0/structAVBufferSrcParameters.html#a86c49b4202433037c9e2b0b6ae541534
func (bfcp *BuffersrcFilterContextParameters) SetHardwareFrameContext(hfc *HardwareFrameContext) {
func (bfcp *BuffersrcFilterContextParameters) SetHardwareFramesContext(hfc *HardwareFramesContext) {
if bfcp.c.hw_frames_ctx != nil {
C.av_buffer_unref(&bfcp.c.hw_frames_ctx)
}
Expand Down
6 changes: 3 additions & 3 deletions codec_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,12 @@ func (cc *CodecContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) {
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a3bac44bb0b016ab838780cc19ac277d6
func (cc *CodecContext) HardwareFrameContext() *HardwareFrameContext {
return newHardwareFrameContextFromC(cc.c.hw_frames_ctx)
func (cc *CodecContext) HardwareFramesContext() *HardwareFramesContext {
return newHardwareFramesContextFromC(cc.c.hw_frames_ctx)
}

// https://ffmpeg.org/doxygen/7.0/structAVCodecContext.html#a3bac44bb0b016ab838780cc19ac277d6
func (cc *CodecContext) SetHardwareFrameContext(hfc *HardwareFrameContext) {
func (cc *CodecContext) SetHardwareFramesContext(hfc *HardwareFramesContext) {
if cc.c.hw_frames_ctx != nil {
C.av_buffer_unref(&cc.c.hw_frames_ctx)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/hardware_decoding_filtering/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func initFilter() (err error) {
// Create buffersrc context parameters
buffersrcContextParameters := astiav.AllocBuffersrcFilterContextParameters()
defer buffersrcContextParameters.Free()
buffersrcContextParameters.SetHardwareFrameContext(decCodecContext.HardwareFrameContext())
buffersrcContextParameters.SetHardwareFramesContext(decCodecContext.HardwareFramesContext())
buffersrcContextParameters.SetHeight(decCodecContext.Height())
buffersrcContextParameters.SetPixelFormat(decCodecContext.PixelFormat())
buffersrcContextParameters.SetSampleAspectRatio(decCodecContext.SampleAspectRatio())
Expand Down
26 changes: 13 additions & 13 deletions examples/hardware_encoding/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ func main() {
encCodecContext.SetFramerate(encCodecContext.TimeBase().Invert())
encCodecContext.SetPixelFormat(hardwarePixelFormat)

// Alloc hardware frame context
hardwareFrameContext := astiav.AllocHardwareFrameContext(hardwareDeviceContext)
if hardwareFrameContext == nil {
log.Fatal("main: hardware frame context is nil")
// Alloc hardware frames context
hardwareFramesContext := astiav.AllocHardwareFramesContext(hardwareDeviceContext)
if hardwareFramesContext == nil {
log.Fatal("main: hardware frames context is nil")
}
defer hardwareFrameContext.Free()
defer hardwareFramesContext.Free()

// Get software pixel format
softwarePixelFormat := astiav.FindPixelFormatByName(*softwarePixelFormatName)
Expand All @@ -95,19 +95,19 @@ func main() {
}

// Set hardware frame content
hardwareFrameContext.SetHardwarePixelFormat(hardwarePixelFormat)
hardwareFrameContext.SetSoftwarePixelFormat(softwarePixelFormat)
hardwareFrameContext.SetWidth(*width)
hardwareFrameContext.SetHeight(*height)
hardwareFrameContext.SetInitialPoolSize(20)
hardwareFramesContext.SetHardwarePixelFormat(hardwarePixelFormat)
hardwareFramesContext.SetSoftwarePixelFormat(softwarePixelFormat)
hardwareFramesContext.SetWidth(*width)
hardwareFramesContext.SetHeight(*height)
hardwareFramesContext.SetInitialPoolSize(20)

// Initialize hardware frame context
if err := hardwareFrameContext.Initialize(); err != nil {
if err := hardwareFramesContext.Initialize(); err != nil {
log.Fatal(fmt.Errorf("main: initializing hardware frame context failed: %w", err))
}

// Update encoder codec context hardware frame context
encCodecContext.SetHardwareFrameContext(hardwareFrameContext)
encCodecContext.SetHardwareFramesContext(hardwareFramesContext)

// Open codec context
if err := encCodecContext.Open(encCodec, nil); err != nil {
Expand Down Expand Up @@ -138,7 +138,7 @@ func main() {
defer hardwareFrame.Free()

// Alloc hardware frame buffer
if err := hardwareFrame.AllocHardwareBuffer(hardwareFrameContext); err != nil {
if err := hardwareFrame.AllocHardwareBuffer(hardwareFramesContext); err != nil {
log.Fatal(fmt.Errorf("main: allocating hardware buffer failed: %w", err))
}

Expand Down
2 changes: 1 addition & 1 deletion frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (f *Frame) AllocBuffer(align int) error {
}

// https://ffmpeg.org/doxygen/7.0/hwcontext_8c.html#adfa5aaa3a4f69b163ea30cadc6d663dc
func (f *Frame) AllocHardwareBuffer(hfc *HardwareFrameContext) error {
func (f *Frame) AllocHardwareBuffer(hfc *HardwareFramesContext) error {
return newError(C.av_hwframe_get_buffer(hfc.c, f.c, 0))
}

Expand Down
26 changes: 13 additions & 13 deletions hardware_frame_context.go → hardware_frames_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,58 @@ import (
)

// https://ffmpeg.org/doxygen/7.0/structAVHWFramesContext.html
type HardwareFrameContext struct {
type HardwareFramesContext struct {
c *C.struct_AVBufferRef
}

func newHardwareFrameContextFromC(c *C.struct_AVBufferRef) *HardwareFrameContext {
func newHardwareFramesContextFromC(c *C.struct_AVBufferRef) *HardwareFramesContext {
if c == nil {
return nil
}
return &HardwareFrameContext{c: c}
return &HardwareFramesContext{c: c}
}

// https://ffmpeg.org/doxygen/7.0/hwcontext_8c.html#ac45a7c039eb4e084b692f69ff5f2e217
func AllocHardwareFrameContext(hdc *HardwareDeviceContext) *HardwareFrameContext {
return newHardwareFrameContextFromC(C.av_hwframe_ctx_alloc(hdc.c))
func AllocHardwareFramesContext(hdc *HardwareDeviceContext) *HardwareFramesContext {
return newHardwareFramesContextFromC(C.av_hwframe_ctx_alloc(hdc.c))
}

func (hfc *HardwareFrameContext) Free() {
func (hfc *HardwareFramesContext) Free() {
if hfc.c != nil {
C.av_buffer_unref(&hfc.c)
}
}

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

// https://ffmpeg.org/doxygen/7.0/structAVHWFramesContext.html#a9e6f29d0f744930cdd0e8bdff8771520
func (hfc *HardwareFrameContext) SetWidth(width int) {
func (hfc *HardwareFramesContext) SetWidth(width int) {
hfc.data().width = C.int(width)
}

// https://ffmpeg.org/doxygen/7.0/structAVHWFramesContext.html#ae61bbe1d8645a0c573085e29f1d0a58f
func (hfc *HardwareFrameContext) SetHeight(height int) {
func (hfc *HardwareFramesContext) SetHeight(height int) {
hfc.data().height = C.int(height)
}

// https://ffmpeg.org/doxygen/7.0/structAVHWFramesContext.html#a045bc1713932804f6ceef170a5578e0e
func (hfc *HardwareFrameContext) SetHardwarePixelFormat(format PixelFormat) {
func (hfc *HardwareFramesContext) SetHardwarePixelFormat(format PixelFormat) {
hfc.data().format = C.enum_AVPixelFormat(format)
}

// https://ffmpeg.org/doxygen/7.0/structAVHWFramesContext.html#a663a9aceca97aa7b2426c9aba6543e4a
func (hfc *HardwareFrameContext) SetSoftwarePixelFormat(swFormat PixelFormat) {
func (hfc *HardwareFramesContext) SetSoftwarePixelFormat(swFormat PixelFormat) {
hfc.data().sw_format = C.enum_AVPixelFormat(swFormat)
}

// https://ffmpeg.org/doxygen/7.0/structAVHWFramesContext.html#a9c3a94dcd9c96e19059b56a6bae9c764
func (hfc *HardwareFrameContext) SetInitialPoolSize(initialPoolSize int) {
func (hfc *HardwareFramesContext) SetInitialPoolSize(initialPoolSize int) {
hfc.data().initial_pool_size = C.int(initialPoolSize)
}

// https://ffmpeg.org/doxygen/7.0/hwcontext_8c.html#a66a7e1ebc7e459ce07d3de6639ac7e38
func (hfc *HardwareFrameContext) Initialize() error {
func (hfc *HardwareFramesContext) Initialize() error {
return newError(C.av_hwframe_ctx_init(hfc.c))
}

0 comments on commit 805ca1b

Please sign in to comment.