diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 630f024..e9df07d 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -2,6 +2,7 @@ - `CodecParameters`.`CodecType` and `CodecParameters`.`SetCodecType` have been removed, use `CodecParameters`.`MediaType` and `CodecParameters`.`SetMediaType` instead - `HardwareFrameContext`.`SetPixelFormat` has been replaced with `HardwareFrameContext`.`SetHardwarePixelFormat` +- `FormatContext`.`SetInterruptCallback` has been replaced with `FormatContext`.`SetIOInterrupter` # v0.24.0 diff --git a/format_context.go b/format_context.go index 1c191f9..f128fa2 100644 --- a/format_context.go +++ b/format_context.go @@ -102,10 +102,12 @@ func (fc *FormatContext) SetFlags(f FormatContextFlags) { } // https://ffmpeg.org/doxygen/7.0/structAVFormatContext.html#a5b37acfe4024d92ee510064e80920b40 -func (fc *FormatContext) SetInterruptCallback() IOInterrupter { - i := newDefaultIOInterrupter() - fc.c.interrupt_callback = i.c - return i +func (fc *FormatContext) SetIOInterrupter(i *IOInterrupter) { + if i == nil { + fc.c.interrupt_callback = C.AVIOInterruptCB{} + } else { + fc.c.interrupt_callback = i.c + } } // https://ffmpeg.org/doxygen/7.0/structAVFormatContext.html#a6c01f25ef062e0398b0b55dd337246ed diff --git a/format_context_test.go b/format_context_test.go index f65f680..2effac9 100644 --- a/format_context_test.go +++ b/format_context_test.go @@ -89,9 +89,19 @@ func TestFormatContext(t *testing.T) { fc4 := AllocFormatContext() require.NotNil(t, fc4) defer fc4.Free() - fc4.SetInterruptCallback().Interrupt() + ii1 := NewIOInterrupter() + fc4.SetIOInterrupter(ii1) + ii1.Interrupt() require.ErrorIs(t, fc4.OpenInput("testdata/video.mp4", nil, nil), ErrExit) + fc9 := AllocFormatContext() + require.NotNil(t, fc9) + defer fc9.Free() + ii2 := NewIOInterrupter() + fc9.SetIOInterrupter(ii2) + fc9.SetIOInterrupter(nil) + require.NoError(t, fc4.OpenInput("testdata/video.mp4", nil, nil)) + fc5 := AllocFormatContext() require.NotNil(t, fc5) defer fc5.Free() diff --git a/io_interrupter.go b/io_interrupter.go index 9ede1fe..88a5206 100644 --- a/io_interrupter.go +++ b/io_interrupter.go @@ -3,26 +3,25 @@ package astiav //#include "io_interrupter.h" import "C" -type IOInterrupter interface { - Interrupt() - Resume() -} - -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() { +func (i *IOInterrupter) Interrupted() bool { + return i.i == 1 +} + +func (i *IOInterrupter) Resume() { i.i = 0 } diff --git a/io_interrupter_test.go b/io_interrupter_test.go index 395688b..88f0bdd 100644 --- a/io_interrupter_test.go +++ b/io_interrupter_test.go @@ -6,11 +6,11 @@ import ( "github.com/stretchr/testify/require" ) -func TestDefaultIOInterrupter(t *testing.T) { - ii := newDefaultIOInterrupter() - require.Equal(t, 0, int(ii.i)) +func TestIOInterrupter(t *testing.T) { + ii := NewIOInterrupter() + require.False(t, ii.Interrupted()) ii.Interrupt() - require.Equal(t, 1, int(ii.i)) + require.True(t, ii.Interrupted()) ii.Resume() - require.Equal(t, 0, int(ii.i)) + require.False(t, ii.Interrupted()) }