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 all 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
21 changes: 20 additions & 1 deletion codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -101,7 +105,7 @@ func FindEncoderByName(n string) *Codec {
return newCodecFromC(C.avcodec_find_encoder_by_name(cn))
}

func (c *Codec) HardwareConfigs(dt HardwareDeviceType) (configs []CodecHardwareConfig) {
func (c *Codec) HardwareConfigs() (configs []CodecHardwareConfig) {
var i int
for {
config := C.avcodec_get_hw_config(c.c, C.int(i))
Expand All @@ -113,3 +117,18 @@ func (c *Codec) HardwareConfigs(dt HardwareDeviceType) (configs []CodecHardwareC
}
return
}

func Codecs() []*Codec {
var opq *C.void = nil
var codecs []*Codec
for {
c := C.av_codec_iterate((*unsafe.Pointer)(unsafe.Pointer(&opq)))
if c == nil {
break
}

codec := newCodecFromC(c)
codecs = append(codecs, codec)
}
return codecs
}
9 changes: 9 additions & 0 deletions codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
func TestCodec(t *testing.T) {
c := astiav.FindDecoder(astiav.CodecIDMp3)
require.NotNil(t, c)
require.Equal(t, c.ID(), astiav.CodecIDMp3)
require.Nil(t, c.ChannelLayouts())
require.True(t, c.IsDecoder())
require.False(t, c.IsEncoder())
Expand Down Expand Up @@ -66,4 +67,12 @@ func TestCodec(t *testing.T) {

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

var found bool
for _, c := range astiav.Codecs() {
if c.ID() == astiav.CodecIDMjpeg {
found = true
}
}
require.True(t, found)
}
2 changes: 1 addition & 1 deletion examples/hardware_decoding/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func main() {
defer s.decCodecContext.Free()

// Loop through codec hardware configs
for _, p := range s.decCodec.HardwareConfigs(hardwareDeviceType) {
for _, p := range s.decCodec.HardwareConfigs() {
// Valid hardware config
if p.MethodFlags().Has(astiav.CodecHardwareConfigMethodFlagHwDeviceCtx) && p.HardwareDeviceType() == hardwareDeviceType {
s.hardwarePixelFormat = p.PixelFormat()
Expand Down
Loading