Skip to content

Commit

Permalink
Updated max array size computation
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Mar 29, 2024
1 parent bd956ab commit 5f81a71
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 3 additions & 2 deletions filter_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package astiav
//#include <libavutil/frame.h>
import "C"
import (
"math"
"unsafe"
)

Expand Down Expand Up @@ -60,15 +61,15 @@ func (fc *FilterContext) NbOutputs() int {
}

func (fc *FilterContext) Inputs() (ls []*FilterLink) {
lcs := (*[maxArraySize](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.inputs))
lcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVFilterLink)(nil))](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.inputs))
for i := 0; i < fc.NbInputs(); i++ {
ls = append(ls, newFilterLinkFromC(lcs[i]))
}
return
}

func (fc *FilterContext) Outputs() (ls []*FilterLink) {
lcs := (*[maxArraySize](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.outputs))
lcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVFilterLink)(nil))](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.outputs))
for i := 0; i < fc.NbOutputs(); i++ {
ls = append(ls, newFilterLinkFromC(lcs[i]))
}
Expand Down
6 changes: 1 addition & 5 deletions format_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"unsafe"
)

const (
maxArraySize = math.MaxInt32 - 1
)

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L1202
type FormatContext struct {
c *C.struct_AVFormatContext
Expand Down Expand Up @@ -134,7 +130,7 @@ func (fc *FormatContext) StartTime() int64 {
}

func (fc *FormatContext) Streams() (ss []*Stream) {
scs := (*[maxArraySize](*C.struct_AVStream))(unsafe.Pointer(fc.c.streams))
scs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVStream)(nil))](*C.struct_AVStream))(unsafe.Pointer(fc.c.streams))
for i := 0; i < fc.NbStreams(); i++ {
ss = append(ss, newStreamFromC(scs[i]))
}
Expand Down

0 comments on commit 5f81a71

Please sign in to comment.