From a3c8b86200b84d9955e255c11c680a0ae73d76da Mon Sep 17 00:00:00 2001 From: ma3315865 Date: Thu, 12 Dec 2024 17:23:47 +0800 Subject: [PATCH] OpenIOContext(filename string, flags IOContextFlags, ii *IOInterrupter, d *Dictionary) --- io_context.go | 6 +++--- io_interrupter.go | 26 ++++++++------------------ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/io_context.go b/io_context.go index 0cd73fe..063e95d 100644 --- a/io_context.go +++ b/io_context.go @@ -109,7 +109,7 @@ func AllocIOContext(bufferSize int, writable bool, readFunc IOContextReadFunc, s } // https://ffmpeg.org/doxygen/7.0/avio_8c.html#ae8589aae955d16ca228b6b9d66ced33d -func OpenIOContext(filename string, flags IOContextFlags, cb *IOInterrupterCB, d *Dictionary) (*IOContext, error) { +func OpenIOContext(filename string, flags IOContextFlags, ii *IOInterrupter, d *Dictionary) (*IOContext, error) { cfi := C.CString(filename) defer C.free(unsafe.Pointer(cfi)) var dc **C.AVDictionary @@ -117,8 +117,8 @@ func OpenIOContext(filename string, flags IOContextFlags, cb *IOInterrupterCB, d dc = &d.c } var cii *C.AVIOInterruptCB = nil - if cb != nil { - cii = &cb.c + if ii != nil { + cii = &ii.c } var c *C.AVIOContext if err := newError(C.avio_open2(&c, cfi, C.int(flags), cii, dc)); err != nil { diff --git a/io_interrupter.go b/io_interrupter.go index ca1fbe0..88a5206 100644 --- a/io_interrupter.go +++ b/io_interrupter.go @@ -3,35 +3,25 @@ package astiav //#include "io_interrupter.h" import "C" -type IOInterrupter interface { - Interrupt() - Resume() - CB() *IOInterrupterCB -} - -type IOInterrupterCB struct { - c C.AVIOInterruptCB -} - -type defaultIOInterrupter struct { +type IOInterrupter struct { c C.AVIOInterruptCB i C.int } -func newDefaultIOInterrupter() *defaultIOInterrupter { - i := &defaultIOInterrupter{} +func NewIOInterrupter() *IOInterrupter { + i := &IOInterrupter{} i.c = C.astiavNewInterruptCallback(&i.i) return i } -func (i *defaultIOInterrupter) Interrupt() { +func (i *IOInterrupter) Interrupt() { i.i = 1 } -func (i *defaultIOInterrupter) Resume() { - i.i = 0 +func (i *IOInterrupter) Interrupted() bool { + return i.i == 1 } -func (i *defaultIOInterrupter) CB() *IOInterrupterCB { - return &IOInterrupterCB{c: i.c} +func (i *IOInterrupter) Resume() { + i.i = 0 }