Replaced cULong/cLong with C.size_t/C.ptrdiff_t

This commit is contained in:
Quentin Renard
2024-03-29 09:05:21 +01:00
parent 443a5f5207
commit deecc33c50
12 changed files with 66 additions and 35 deletions

View File

@@ -1,6 +1,7 @@
version = "n5.1.2"
srcPath = "tmp/$(version)/src"
postCheckout = ""
platform = ""
generate-flags:
go run internal/cmd/flags/main.go
@@ -18,3 +19,11 @@ install-ffmpeg:
coverage:
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
test-platform-build:
docker build -t astiav/$(platform) ./testdata/docker/$(platform)
test-platform-run:
mkdir -p ./testdata/docker/$(platform)/tmp/gocache
mkdir -p ./testdata/docker/$(platform)/tmp/gomodcache
docker run -v .:/opt/astiav -v ./testdata/docker/$(platform)/tmp/gocache:/opt/gocache -v ./testdata/docker/$(platform)/tmp/gomodcache:/opt/gomodcache astiav/$(platform)

View File

@@ -1,8 +0,0 @@
//go:build !windows
package astiav
import "C"
type cLong = C.long
type cUlong = C.ulong

View File

@@ -1,8 +0,0 @@
//go:build windows
package astiav
import "C"
type cLong = C.longlong
type cUlong = C.ulonglong

View File

@@ -21,18 +21,18 @@ func stringFromC(len int, fn func(buf *C.char, size C.size_t) error) (string, er
return C.GoString(buf), nil
}
func bytesFromC(fn func(size *cUlong) *C.uint8_t) []byte {
func bytesFromC(fn func(size *C.size_t) *C.uint8_t) []byte {
var size uint64
r := fn((*cUlong)(unsafe.Pointer(&size)))
r := fn((*C.size_t)(unsafe.Pointer(&size)))
return C.GoBytes(unsafe.Pointer(r), C.int(size))
}
func bytesToC(b []byte, fn func(b *C.uint8_t, size cUlong) error) error {
func bytesToC(b []byte, fn func(b *C.uint8_t, size C.size_t) error) error {
var ptr *C.uint8_t
if b != nil {
c := make([]byte, len(b))
copy(c, b)
ptr = (*C.uint8_t)(unsafe.Pointer(&c[0]))
}
return fn(ptr, cUlong(len(b)))
return fn(ptr, C.size_t(len(b)))
}

View File

@@ -93,7 +93,7 @@ func (l ChannelLayout) String() string {
}
func (l ChannelLayout) Describe(b []byte) (int, error) {
ret := C.av_channel_layout_describe(l.c, (*C.char)(unsafe.Pointer(&b[0])), cUlong(len(b)))
ret := C.av_channel_layout_describe(l.c, (*C.char)(unsafe.Pointer(&b[0])), C.size_t(len(b)))
if ret < 0 {
return 0, newError(ret)
}

View File

@@ -61,13 +61,13 @@ func (d *Dictionary) Free() {
}
func (d *Dictionary) Pack() []byte {
return bytesFromC(func(size *cUlong) *C.uint8_t {
return bytesFromC(func(size *C.size_t) *C.uint8_t {
return C.av_packet_pack_dictionary(d.c, size)
})
}
func (d *Dictionary) Unpack(b []byte) error {
return bytesToC(b, func(b *C.uint8_t, size cUlong) error {
return bytesToC(b, func(b *C.uint8_t, size C.size_t) error {
return newError(C.av_packet_unpack_dictionary(b, size, &d.c))
})
}

View File

@@ -99,9 +99,9 @@ func (f *Frame) ImageCopyToBuffer(b []byte, align int) (int, error) {
}
func (f *Frame) ImageFillBlack() error {
linesize := [NumDataPointers]cLong{}
linesize := [NumDataPointers]C.ptrdiff_t{}
for i := 0; i < int(NumDataPointers); i++ {
linesize[i] = cLong(f.c.linesize[i])
linesize[i] = C.ptrdiff_t(f.c.linesize[i])
}
return newError(C.av_image_fill_black(&f.c.data[0], &linesize[0], (C.enum_AVPixelFormat)(f.c.format), (C.enum_AVColorRange)(f.c.color_range), f.c.width, f.c.height))
}
@@ -175,7 +175,7 @@ func (f *Frame) SetSampleRate(r int) {
}
func (f *Frame) NewSideData(t FrameSideDataType, size uint64) *FrameSideData {
return newFrameSideDataFromC(C.av_frame_new_side_data(f.c, (C.enum_AVFrameSideDataType)(t), cUlong(size)))
return newFrameSideDataFromC(C.av_frame_new_side_data(f.c, (C.enum_AVFrameSideDataType)(t), C.size_t(size)))
}
func (f *Frame) SideData(t FrameSideDataType) *FrameSideData {

View File

@@ -196,8 +196,8 @@ func (f *frameDataFrame) pixelFormat() PixelFormat {
}
func (f *frameDataFrame) planeBytes(i int) []byte {
return bytesFromC(func(size *cUlong) *C.uint8_t {
*size = cUlong(int(f.f.c.linesize[i]) * f.f.Height())
return bytesFromC(func(size *C.size_t) *C.uint8_t {
*size = C.size_t(int(f.f.c.linesize[i]) * f.f.Height())
return f.f.c.data[i]
})
}

View File

@@ -21,7 +21,7 @@ func newFrameSideDataFromC(c *C.struct_AVFrameSideData) *FrameSideData {
}
func (d *FrameSideData) Data() []byte {
return bytesFromC(func(size *cUlong) *C.uint8_t {
return bytesFromC(func(size *C.size_t) *C.uint8_t {
*size = d.c.size
return d.c.data
})

View File

@@ -28,8 +28,8 @@ func (p *Packet) Data() []byte {
if p.c.data == nil {
return nil
}
return bytesFromC(func(size *cUlong) *C.uint8_t {
*size = cUlong(p.c.size)
return bytesFromC(func(size *C.size_t) *C.uint8_t {
*size = C.size_t(p.c.size)
return p.c.data
})
}
@@ -87,7 +87,7 @@ func (p *Packet) AddSideData(t PacketSideDataType, data []byte) error {
}
func (p *Packet) SideData(t PacketSideDataType) []byte {
return bytesFromC(func(size *cUlong) *C.uint8_t {
return bytesFromC(func(size *C.size_t) *C.uint8_t {
return C.av_packet_get_side_data(p.c, (C.enum_AVPacketSideDataType)(t), size)
})
}

View File

@@ -81,7 +81,7 @@ func (s *Stream) SetSampleAspectRatio(r Rational) {
}
func (s *Stream) SideData(t PacketSideDataType) []byte {
return bytesFromC(func(size *cUlong) *C.uint8_t {
return bytesFromC(func(size *C.size_t) *C.uint8_t {
return C.av_stream_get_side_data(s.c, (C.enum_AVPacketSideDataType)(t), size)
})
}
@@ -91,12 +91,12 @@ func (s *Stream) AddSideData(t PacketSideDataType, d []byte) error {
return nil
}
ptr := C.av_stream_new_side_data(s.c, (C.enum_AVPacketSideDataType)(t), cUlong(len(d)))
ptr := C.av_stream_new_side_data(s.c, (C.enum_AVPacketSideDataType)(t), C.size_t(len(d)))
if ptr == nil {
return errors.New("astiav: nil pointer")
}
C.memcpy(unsafe.Pointer(ptr), unsafe.Pointer(&d[0]), cUlong(len(d)))
C.memcpy(unsafe.Pointer(ptr), unsafe.Pointer(&d[0]), C.size_t(len(d)))
return nil
}

38
testdata/docker/arm/7/Dockerfile vendored Normal file
View File

@@ -0,0 +1,38 @@
FROM arm32v7/debian:12.5
RUN apt-get update
RUN apt-get install -y \
build-essential \
git \
pkg-config
RUN \
mkdir -p /opt/ffmpeg/src
WORKDIR /opt/ffmpeg/src
RUN \
git clone https://github.com/FFmpeg/FFmpeg /opt/ffmpeg/src && \
git checkout n5.1.2
RUN \
./configure --prefix=.. && \
make && \
make install
ADD https://dl.google.com/go/go1.21.0.linux-amd64.tar.gz /tmp/go.tar.gz
RUN tar -C /opt -xzf /tmp/go.tar.gz
ENV GOARCH=arm
ENV GOARM=7
ENV GOCACHE=/opt/gocache
ENV GOMODCACHE=/opt/gomodcache
ENV CGO_LDFLAGS=-L/opt/ffmpeg/lib/
ENV CGO_CFLAGS=-I/opt/ffmpeg/include/
ENV PKG_CONFIG_PATH=/opt/ffmpeg/lib/pkgconfig
ENV CGO_ENABLED=1
WORKDIR /opt/astiav
CMD ["/opt/go/bin/go", "test"]