Skip to content

Commit

Permalink
Hardware filtering example now shows how to set filters hardware devi…
Browse files Browse the repository at this point in the history
…ce context
  • Loading branch information
asticode committed Dec 24, 2024
1 parent ee2cb0e commit a6280c7
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions examples/hardware_decoding_filtering/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
decodedHardwareFrame *astiav.Frame
filterGraph *astiav.FilterGraph
filteredHardwareFrame *astiav.Frame
hardwareDeviceContext *astiav.HardwareDeviceContext
inputStream *astiav.Stream
softwareFrame *astiav.Frame
)
Expand Down Expand Up @@ -94,7 +95,6 @@ func main() {
}

// Loop through streams
var hdc *astiav.HardwareDeviceContext
hardwarePixelFormat := astiav.PixelFormatNone
for _, is := range inputFormatContext.Streams() {
// Only process video
Expand Down Expand Up @@ -143,13 +143,13 @@ func main() {

// Create hardware device context
var err error
if hdc, err = astiav.CreateHardwareDeviceContext(hardwareDeviceType, *hardwareDeviceName, nil, 0); err != nil {
if hardwareDeviceContext, err = astiav.CreateHardwareDeviceContext(hardwareDeviceType, *hardwareDeviceName, nil, 0); err != nil {
log.Fatal(fmt.Errorf("main: creating hardware device context failed: %w", err))
}
c.Add(hdc.Free)
c.Add(hardwareDeviceContext.Free)

// Update decoder context
decCodecContext.SetHardwareDeviceContext(hdc)
decCodecContext.SetHardwareDeviceContext(hardwareDeviceContext)
decCodecContext.SetPixelFormatCallback(func(pfs []astiav.PixelFormat) astiav.PixelFormat {
for _, pf := range pfs {
if pf == hardwarePixelFormat {
Expand Down Expand Up @@ -336,6 +336,17 @@ func initFilter() (err error) {
inputs.SetPadIdx(0)
inputs.SetNext(nil)

// Loop through filters
for _, f := range filterGraph.Filters() {
// Filter doesn't handle hardware devices
if !f.Filter().Flags().Has(astiav.FilterFlagHardwareDevice) {
continue
}

// Update hardware device context
f.SetHardwareDeviceContext(hardwareDeviceContext)
}

// Parse
if err = filterGraph.Parse(*filter, inputs, outputs); err != nil {
err = fmt.Errorf("main: parsing filter failed: %w", err)
Expand Down

0 comments on commit a6280c7

Please sign in to comment.