Skip to content

Commit

Permalink
OpenIOContext(filename string, flags IOContextFlags, ii *IOInterrupte…
Browse files Browse the repository at this point in the history
…r, d *Dictionary)
  • Loading branch information
oldma3095 committed Dec 12, 2024
1 parent 7bf889d commit a3c8b86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
6 changes: 3 additions & 3 deletions io_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ 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
if d != nil {
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 {
Expand Down
26 changes: 8 additions & 18 deletions io_interrupter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a3c8b86

Please sign in to comment.