Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Codec Iteration and Checking of HardwareConfigMethodFlags #40

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Codec struct {
c *C.struct_AVCodec
}

type CodecProcessor func(*Codec)

func newCodecFromC(c *C.struct_AVCodec) *Codec {
if c == nil {
return nil
Expand All @@ -28,6 +30,10 @@ func (c *Codec) String() string {
return c.Name()
}

func (c *Codec) ID() CodecID {
return CodecID(c.c.id)
}

func (c *Codec) ChannelLayouts() (o []ChannelLayout) {
if c.c.ch_layouts == nil {
return nil
Expand Down Expand Up @@ -113,3 +119,33 @@ func (c *Codec) HardwareConfigs(dt HardwareDeviceType) (configs []CodecHardwareC
}
return
}

func (c *Codec) HasHardwareConfigMethodFlag(chcmf CodecHardwareConfigMethodFlag) bool {
Cacsjep marked this conversation as resolved.
Show resolved Hide resolved
var i C.int
for {
config := C.avcodec_get_hw_config(c.c, i)
if config == nil {
break
}

if (CodecHardwareConfig{c: config}.MethodFlags().Has(chcmf)) {
return true
}

i++
}
return false
}

func IterateCodecs(processor CodecProcessor) {
Cacsjep marked this conversation as resolved.
Show resolved Hide resolved
var opq *C.void = nil
for {
c := C.av_codec_iterate((*unsafe.Pointer)(unsafe.Pointer(&opq)))
if c == nil {
break
}

codec := newCodecFromC(c)
processor(codec)
}
}
9 changes: 9 additions & 0 deletions codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@ func TestCodec(t *testing.T) {

Cacsjep marked this conversation as resolved.
Show resolved Hide resolved
c = astiav.FindDecoderByName("invalid")
require.Nil(t, c)

var decoders []*astiav.Codec
Cacsjep marked this conversation as resolved.
Show resolved Hide resolved
processor := func(c *astiav.Codec) {
if c.IsDecoder() && c.ID() == astiav.CodecIDMjpeg {
decoders = append(decoders, c)
}
}
astiav.IterateCodecs(processor)
require.Equal(t, decoders[0].ID(), astiav.CodecIDMjpeg)
}
Loading