Skip to content

Commit

Permalink
merge master and add SetHardwareDeviceContext (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
oldma3095 authored Dec 24, 2024
1 parent 5b04a31 commit ee2cb0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions filter_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ func (fc *FilterContext) Class() *Class {
return newClassFromC(unsafe.Pointer(fc.c))
}

// https://ffmpeg.org/doxygen/7.0/structAVFilterContext.html#addd946fbe5af506a2b19f9ad7cb97c35
func (fc *FilterContext) SetHardwareDeviceContext(hdc *HardwareDeviceContext) {
if fc.c.hw_device_ctx != nil {
C.av_buffer_unref(&fc.c.hw_device_ctx)
}
if hdc != nil {
fc.c.hw_device_ctx = C.av_buffer_ref(hdc.c)
} else {
fc.c.hw_device_ctx = nil
}
}

// https://ffmpeg.org/doxygen/7.0/structAVFilterContext.html#a6eee53e57dddfa7cca1cade870c8a44e
func (fc *FilterContext) Filter() *Filter {
return newFilterFromC(fc.c.filter)
Expand Down
15 changes: 15 additions & 0 deletions filter_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package astiav
import "C"
import (
"errors"
"math"
"unsafe"
)

Expand Down Expand Up @@ -154,3 +155,17 @@ func (g *FilterGraph) SendCommand(target, cmd, args string, f FilterCommandFlags
})
return
}

// https://ffmpeg.org/doxygen/7.0/structAVFilterGraph.html#a0ba5c820c760788ea5f8e40c476f9704
func (g *FilterGraph) NbFilters() int {
return int(g.c.nb_filters)
}

// https://ffmpeg.org/doxygen/7.0/structAVFilterGraph.html#a1dafd3d239f7c2f5e3ac109578ef926d
func (g *FilterGraph) Filters() (fs []*FilterContext) {
fcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.AVFilterContext)(nil))](*C.AVFilterContext))(unsafe.Pointer(g.c.filters))
for i := 0; i < g.NbFilters(); i++ {
fs = append(fs, newFilterContext(fcs[i]))
}
return
}
8 changes: 8 additions & 0 deletions filter_graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ func TestFilterGraph(t *testing.T) {
outputs = o
}

require.Equal(t, len(buffersrcContexts)+1, fg.NbFilters())
fs := fg.Filters()
require.Equal(t, len(buffersrcContexts)+1, len(fs))
require.Equal(t, buffersinkContext.FilterContext(), fs[0])
for idx, c := range fs[1:] {
require.Equal(t, buffersrcContexts[idx].FilterContext(), c)
}

require.NoError(t, fg.Parse(v.content, inputs, outputs))
require.NoError(t, fg.Configure())

Expand Down

0 comments on commit ee2cb0e

Please sign in to comment.