mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-06 00:26:52 +08:00
Enhance Codec Iteration and Checking of HardwareConfigMethodFlags (#40)
* Add IterateCodecs, Add codec.HasHardwareConfigMethodFlag * Remove HasHardwareConfigMethodFlag test because git worklow does not support hw HasHardwareConfigMethodFlag is tested on my local device but does not work in git * Review Changes Remove unused arg in HardwareConfigs Add mehtod to get all codecs Update test * Remove codecporcessor type
This commit is contained in:
21
codec.go
21
codec.go
@@ -28,6 +28,10 @@ func (c *Codec) String() string {
|
|||||||
return c.Name()
|
return c.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Codec) ID() CodecID {
|
||||||
|
return CodecID(c.c.id)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Codec) ChannelLayouts() (o []ChannelLayout) {
|
func (c *Codec) ChannelLayouts() (o []ChannelLayout) {
|
||||||
if c.c.ch_layouts == nil {
|
if c.c.ch_layouts == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -101,7 +105,7 @@ func FindEncoderByName(n string) *Codec {
|
|||||||
return newCodecFromC(C.avcodec_find_encoder_by_name(cn))
|
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
|
var i int
|
||||||
for {
|
for {
|
||||||
config := C.avcodec_get_hw_config(c.c, C.int(i))
|
config := C.avcodec_get_hw_config(c.c, C.int(i))
|
||||||
@@ -113,3 +117,18 @@ func (c *Codec) HardwareConfigs(dt HardwareDeviceType) (configs []CodecHardwareC
|
|||||||
}
|
}
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
func TestCodec(t *testing.T) {
|
func TestCodec(t *testing.T) {
|
||||||
c := astiav.FindDecoder(astiav.CodecIDMp3)
|
c := astiav.FindDecoder(astiav.CodecIDMp3)
|
||||||
require.NotNil(t, c)
|
require.NotNil(t, c)
|
||||||
|
require.Equal(t, c.ID(), astiav.CodecIDMp3)
|
||||||
require.Nil(t, c.ChannelLayouts())
|
require.Nil(t, c.ChannelLayouts())
|
||||||
require.True(t, c.IsDecoder())
|
require.True(t, c.IsDecoder())
|
||||||
require.False(t, c.IsEncoder())
|
require.False(t, c.IsEncoder())
|
||||||
@@ -66,4 +67,12 @@ func TestCodec(t *testing.T) {
|
|||||||
|
|
||||||
c = astiav.FindDecoderByName("invalid")
|
c = astiav.FindDecoderByName("invalid")
|
||||||
require.Nil(t, c)
|
require.Nil(t, c)
|
||||||
|
|
||||||
|
var found bool
|
||||||
|
for _, c := range astiav.Codecs() {
|
||||||
|
if c.ID() == astiav.CodecIDMjpeg {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
require.True(t, found)
|
||||||
}
|
}
|
||||||
|
@@ -107,7 +107,7 @@ func main() {
|
|||||||
defer s.decCodecContext.Free()
|
defer s.decCodecContext.Free()
|
||||||
|
|
||||||
// Loop through codec hardware configs
|
// Loop through codec hardware configs
|
||||||
for _, p := range s.decCodec.HardwareConfigs(hardwareDeviceType) {
|
for _, p := range s.decCodec.HardwareConfigs() {
|
||||||
// Valid hardware config
|
// Valid hardware config
|
||||||
if p.MethodFlags().Has(astiav.CodecHardwareConfigMethodFlagHwDeviceCtx) && p.HardwareDeviceType() == hardwareDeviceType {
|
if p.MethodFlags().Has(astiav.CodecHardwareConfigMethodFlagHwDeviceCtx) && p.HardwareDeviceType() == hardwareDeviceType {
|
||||||
s.hardwarePixelFormat = p.PixelFormat()
|
s.hardwarePixelFormat = p.PixelFormat()
|
||||||
|
Reference in New Issue
Block a user