Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Jan 24, 2024
1 parent 767f28b commit 6e42185
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
8 changes: 2 additions & 6 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions codec_hardware_config_method_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
5 changes: 2 additions & 3 deletions examples/hardware_decoding/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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))
Expand Down

0 comments on commit 6e42185

Please sign in to comment.