mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-03 23:36:42 +08:00
OpenIOContextWithDictionary (#116)
* OpenIOContextWithDictionary * OpenIOContext * OpenIOContext * IOInterrupterCB * OpenIOContext(filename string, flags IOContextFlags, ii *IOInterrupter, d *Dictionary)
This commit is contained in:
@@ -48,7 +48,7 @@ func TestClassers(t *testing.T) {
|
||||
fmc2 := AllocFormatContext()
|
||||
require.NoError(t, fmc2.OpenInput("testdata/video.mp4", nil, nil))
|
||||
path := filepath.Join(t.TempDir(), "iocontext.txt")
|
||||
ic1, err := OpenIOContext(path, NewIOContextFlags(IOContextFlagWrite))
|
||||
ic1, err := OpenIOContext(path, NewIOContextFlags(IOContextFlagWrite), nil, nil)
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(path)
|
||||
ic2, err := AllocIOContext(1, true, nil, nil, nil)
|
||||
|
@@ -103,7 +103,7 @@ func main() {
|
||||
// If this is a file, we need to use an io context
|
||||
if !outputFormatContext.OutputFormat().Flags().Has(astiav.IOFormatFlagNofile) {
|
||||
// Open io context
|
||||
ioContext, err := astiav.OpenIOContext(*output, astiav.NewIOContextFlags(astiav.IOContextFlagWrite))
|
||||
ioContext, err := astiav.OpenIOContext(*output, astiav.NewIOContextFlags(astiav.IOContextFlagWrite), nil, nil)
|
||||
if err != nil {
|
||||
log.Fatal(fmt.Errorf("main: opening io context failed: %w", err))
|
||||
}
|
||||
|
@@ -334,7 +334,7 @@ func openOutputFile() (err error) {
|
||||
if !outputFormatContext.OutputFormat().Flags().Has(astiav.IOFormatFlagNofile) {
|
||||
// Open io context
|
||||
var ioContext *astiav.IOContext
|
||||
if ioContext, err = astiav.OpenIOContext(*output, astiav.NewIOContextFlags(astiav.IOContextFlagWrite)); err != nil {
|
||||
if ioContext, err = astiav.OpenIOContext(*output, astiav.NewIOContextFlags(astiav.IOContextFlagWrite), nil, nil); err != nil {
|
||||
err = fmt.Errorf("main: opening io context failed: %w", err)
|
||||
return
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ func TestFormatContext(t *testing.T) {
|
||||
fc3 := AllocFormatContext()
|
||||
require.NotNil(t, fc3)
|
||||
defer fc3.Free()
|
||||
io, err := OpenIOContext("testdata/video.mp4", NewIOContextFlags(IOContextFlagRead))
|
||||
io, err := OpenIOContext("testdata/video.mp4", NewIOContextFlags(IOContextFlagRead), nil, nil)
|
||||
require.NoError(t, err)
|
||||
defer io.Close() //nolint:errcheck
|
||||
fc3.SetPb(io)
|
||||
@@ -140,7 +140,7 @@ func TestFormatContext(t *testing.T) {
|
||||
require.NotNil(t, os)
|
||||
require.NoError(t, is.CodecParameters().Copy(os.CodecParameters()))
|
||||
}
|
||||
ic, err := OpenIOContext(outputPath, NewIOContextFlags(IOContextFlagWrite))
|
||||
ic, err := OpenIOContext(outputPath, NewIOContextFlags(IOContextFlagWrite), nil, nil)
|
||||
require.NoError(t, err)
|
||||
fc7.SetPb(ic)
|
||||
require.NoError(t, fc7.WriteHeader(nil))
|
||||
|
@@ -108,12 +108,20 @@ func AllocIOContext(bufferSize int, writable bool, readFunc IOContextReadFunc, s
|
||||
return
|
||||
}
|
||||
|
||||
// https://ffmpeg.org/doxygen/7.0/avio_8c.html#ab1b99c5b70aa59f15ab7cd4cbb40381e
|
||||
func OpenIOContext(filename string, flags IOContextFlags) (*IOContext, error) {
|
||||
// https://ffmpeg.org/doxygen/7.0/avio_8c.html#ae8589aae955d16ca228b6b9d66ced33d
|
||||
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 ii != nil {
|
||||
cii = &ii.c
|
||||
}
|
||||
var c *C.AVIOContext
|
||||
if err := newError(C.avio_open(&c, cfi, C.int(flags))); err != nil {
|
||||
if err := newError(C.avio_open2(&c, cfi, C.int(flags), cii, dc)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newIOContextFromC(c), nil
|
||||
|
@@ -56,7 +56,7 @@ func TestIOContext(t *testing.T) {
|
||||
|
||||
func TestOpenIOContext(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "iocontext.txt")
|
||||
c, err := OpenIOContext(path, NewIOContextFlags(IOContextFlagWrite))
|
||||
c, err := OpenIOContext(path, NewIOContextFlags(IOContextFlagWrite), nil, nil)
|
||||
require.NoError(t, err)
|
||||
cl := c.Class()
|
||||
require.NotNil(t, cl)
|
||||
|
Reference in New Issue
Block a user