From 6e42185a287b7a33e295caddec2ffecdce822a0a Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 24 Jan 2024 18:29:35 +0100 Subject: [PATCH] Minor changes --- codec.go | 8 ++------ codec_hardware_config_method_flag.go | 8 ++++---- examples/hardware_decoding/main.go | 5 ++--- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/codec.go b/codec.go index 9132869..704ed41 100644 --- a/codec.go +++ b/codec.go @@ -101,19 +101,15 @@ func FindEncoderByName(n string) *Codec { return newCodecFromC(C.avcodec_find_encoder_by_name(cn)) } -func (c *Codec) HardwareConfigs(dt HardwareDeviceType) []CodecHardwareConfig { - var configs []CodecHardwareConfig +func (c *Codec) HardwareConfigs(dt HardwareDeviceType) (configs []CodecHardwareConfig) { var i int - for { config := C.avcodec_get_hw_config(c.c, C.int(i)) if config == nil { break } - configs = append(configs, CodecHardwareConfig{c: config}) - i++ } - return configs + return } diff --git a/codec_hardware_config_method_flag.go b/codec_hardware_config_method_flag.go index bfa0a95..73d30f9 100644 --- a/codec_hardware_config_method_flag.go +++ b/codec_hardware_config_method_flag.go @@ -8,8 +8,8 @@ import "C" type CodecHardwareConfigMethodFlag int const ( - CodecHardwareConfigMethodAdHoc = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_AD_HOC) - CodecHardwareConfigMethodHwDeviceCtx = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) - CodecHardwareConfigMethodHwFramesCtx = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) - CodecHardwareConfigMethodInternal = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_INTERNAL) + CodecHardwareConfigMethodFlagAdHoc = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_AD_HOC) + CodecHardwareConfigMethodFlagHwDeviceCtx = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) + CodecHardwareConfigMethodFlagHwFramesCtx = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) + CodecHardwareConfigMethodFlagInternal = CodecHardwareConfigMethodFlag(C.AV_CODEC_HW_CONFIG_METHOD_INTERNAL) ) diff --git a/examples/hardware_decoding/main.go b/examples/hardware_decoding/main.go index 0310b07..b032117 100644 --- a/examples/hardware_decoding/main.go +++ b/examples/hardware_decoding/main.go @@ -78,8 +78,6 @@ func main() { // Loop through streams streams := make(map[int]*stream) // Indexed by input stream index for _, is := range inputFormatContext.Streams() { - var err error - // Only process video if is.CodecParameters().MediaType() != astiav.MediaTypeVideo { continue @@ -105,7 +103,7 @@ func main() { // Loop through codec hardware configs for _, p := range hardwareConfigs { // Valid hardware config - if p.MethodFlags().Has(astiav.CodecHardwareConfigMethodHwDeviceCtx) && p.HardwareDeviceType() == hardwareDeviceType { + if p.MethodFlags().Has(astiav.CodecHardwareConfigMethodFlagHwDeviceCtx) && p.HardwareDeviceType() == hardwareDeviceType { s.hardwarePixelFormat = p.PixelFormat() break } @@ -122,6 +120,7 @@ func main() { } // Create hardware device context + var err error s.hardwareDeviceContext, err = astiav.CreateHardwareDeviceContext(hardwareDeviceType, "", nil) if err != nil { log.Fatal(fmt.Errorf("main: creating hardware device context failed: %w", err))