diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 7f3a15a..59144a3 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -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 diff --git a/buffersrc_filter_context_parameters.go b/buffersrc_filter_context_parameters.go index a219d7b..9537183 100644 --- a/buffersrc_filter_context_parameters.go +++ b/buffersrc_filter_context_parameters.go @@ -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) } diff --git a/codec_context.go b/codec_context.go index 0ff2ae5..0e608ec 100644 --- a/codec_context.go +++ b/codec_context.go @@ -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) } diff --git a/examples/hardware_decoding_filtering/main.go b/examples/hardware_decoding_filtering/main.go index ee3b55d..65ffe02 100644 --- a/examples/hardware_decoding_filtering/main.go +++ b/examples/hardware_decoding_filtering/main.go @@ -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()) diff --git a/examples/hardware_encoding/main.go b/examples/hardware_encoding/main.go index 0d96d3d..64080b1 100644 --- a/examples/hardware_encoding/main.go +++ b/examples/hardware_encoding/main.go @@ -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) @@ -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 { @@ -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)) } diff --git a/frame.go b/frame.go index 90effec..f13d94e 100644 --- a/frame.go +++ b/frame.go @@ -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)) } diff --git a/hardware_frame_context.go b/hardware_frames_context.go similarity index 60% rename from hardware_frame_context.go rename to hardware_frames_context.go index 06ba298..0ba4f67 100644 --- a/hardware_frame_context.go +++ b/hardware_frames_context.go @@ -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)) }