From e5d0d37991fc15960b1304b8a97996584bfb9c59 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Wed, 26 Jul 2023 21:10:09 +0800 Subject: [PATCH] Add avdevice support (#29) * Add avdevice support * Format Adjustment: DeviceRegisterAll renamed to RegisterAllDevices Move FindInputFormat position Add Name(), LongName(), String() methods to InputFormat Adjust TestInputFormat test --- device.go | 9 +++++++++ device_test.go | 10 ++++++++++ input_format.go | 20 ++++++++++++++++++++ input_format_test.go | 14 ++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 device.go create mode 100644 device_test.go create mode 100644 input_format_test.go diff --git a/device.go b/device.go new file mode 100644 index 0000000..7fc9152 --- /dev/null +++ b/device.go @@ -0,0 +1,9 @@ +package astiav + +//#cgo pkg-config: libavdevice +//#include +import "C" + +func RegisterAllDevices() { + C.avdevice_register_all() +} diff --git a/device_test.go b/device_test.go new file mode 100644 index 0000000..2d3d9e5 --- /dev/null +++ b/device_test.go @@ -0,0 +1,10 @@ +package astiav_test + +import ( + "github.com/asticode/go-astiav" + "testing" +) + +func TestDevice(t *testing.T) { + astiav.RegisterAllDevices() +} diff --git a/input_format.go b/input_format.go index ae909cf..f524ab2 100644 --- a/input_format.go +++ b/input_format.go @@ -3,6 +3,7 @@ package astiav //#cgo pkg-config: libavformat //#include import "C" +import "unsafe" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L650 type InputFormat struct { @@ -16,6 +17,25 @@ func newInputFormatFromC(c *C.struct_AVInputFormat) *InputFormat { return &InputFormat{c: c} } +func FindInputFormat(name string) *InputFormat { + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) + return newInputFormatFromC(C.av_find_input_format(cname)) +} + func (f *InputFormat) Flags() IOFormatFlags { return IOFormatFlags(f.c.flags) } + +func (f *InputFormat) Name() string { + return C.GoString(f.c.name) +} + +// LongName Description of the format, meant to be more human-readable than Name. +func (f *InputFormat) LongName() string { + return C.GoString(f.c.long_name) +} + +func (f *InputFormat) String() string { + return f.Name() +} diff --git a/input_format_test.go b/input_format_test.go new file mode 100644 index 0000000..3e30894 --- /dev/null +++ b/input_format_test.go @@ -0,0 +1,14 @@ +package astiav_test + +import ( + "github.com/asticode/go-astiav" + "github.com/stretchr/testify/require" + "testing" +) + +func TestInputFormat(t *testing.T) { + formatName := "rawvideo" + inputFormat := astiav.FindInputFormat(formatName) + require.NotNil(t, inputFormat) + require.True(t, inputFormat.Name() == formatName) +}