Skip to content

Commit

Permalink
Add avdevice support (#29)
Browse files Browse the repository at this point in the history
* Add avdevice support

* Format Adjustment:
DeviceRegisterAll renamed to RegisterAllDevices
Move FindInputFormat position
Add Name(), LongName(), String() methods to InputFormat
Adjust TestInputFormat test
  • Loading branch information
Tryanks authored and asticode committed Jul 27, 2023
1 parent 310e023 commit e5d0d37
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package astiav

//#cgo pkg-config: libavdevice
//#include <libavdevice/avdevice.h>
import "C"

func RegisterAllDevices() {
C.avdevice_register_all()
}
10 changes: 10 additions & 0 deletions device_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package astiav_test

import (
"github.com/asticode/go-astiav"
"testing"
)

func TestDevice(t *testing.T) {
astiav.RegisterAllDevices()
}
20 changes: 20 additions & 0 deletions input_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package astiav
//#cgo pkg-config: libavformat
//#include <libavformat/avformat.h>
import "C"
import "unsafe"

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L650
type InputFormat struct {
Expand All @@ -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()
}
14 changes: 14 additions & 0 deletions input_format_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit e5d0d37

Please sign in to comment.