From deecc33c50d954062f64ccff16a45cedebb23153 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Fri, 29 Mar 2024 09:05:21 +0100 Subject: [PATCH] Replaced cULong/cLong with C.size_t/C.ptrdiff_t --- Makefile | 9 ++++++++ astiav_!windows.go | 8 ------- astiav_windows.go | 8 ------- bytes.go | 8 +++---- channel_layout.go | 2 +- dictionary.go | 4 ++-- frame.go | 6 ++--- frame_data.go | 4 ++-- frame_side_data.go | 2 +- packet.go | 6 ++--- stream.go | 6 ++--- testdata/docker/arm/7/Dockerfile | 38 ++++++++++++++++++++++++++++++++ 12 files changed, 66 insertions(+), 35 deletions(-) delete mode 100644 astiav_!windows.go delete mode 100644 astiav_windows.go create mode 100644 testdata/docker/arm/7/Dockerfile diff --git a/Makefile b/Makefile index 6dfc51f..3b74b24 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/astiav_!windows.go b/astiav_!windows.go deleted file mode 100644 index a2f8cca..0000000 --- a/astiav_!windows.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build !windows - -package astiav - -import "C" - -type cLong = C.long -type cUlong = C.ulong diff --git a/astiav_windows.go b/astiav_windows.go deleted file mode 100644 index e005d9a..0000000 --- a/astiav_windows.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build windows - -package astiav - -import "C" - -type cLong = C.longlong -type cUlong = C.ulonglong diff --git a/bytes.go b/bytes.go index ae2fef6..f776b43 100644 --- a/bytes.go +++ b/bytes.go @@ -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))) } diff --git a/channel_layout.go b/channel_layout.go index b5371f9..06dae28 100644 --- a/channel_layout.go +++ b/channel_layout.go @@ -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) } diff --git a/dictionary.go b/dictionary.go index 65e8dde..f559b0b 100644 --- a/dictionary.go +++ b/dictionary.go @@ -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)) }) } diff --git a/frame.go b/frame.go index a7866c3..685f79f 100644 --- a/frame.go +++ b/frame.go @@ -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 { diff --git a/frame_data.go b/frame_data.go index 068b298..99a6c9a 100644 --- a/frame_data.go +++ b/frame_data.go @@ -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] }) } diff --git a/frame_side_data.go b/frame_side_data.go index 45391a2..dea078f 100644 --- a/frame_side_data.go +++ b/frame_side_data.go @@ -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 }) diff --git a/packet.go b/packet.go index d5e5376..43b6a75 100644 --- a/packet.go +++ b/packet.go @@ -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) }) } diff --git a/stream.go b/stream.go index 01a5fb3..453dfc1 100644 --- a/stream.go +++ b/stream.go @@ -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 } diff --git a/testdata/docker/arm/7/Dockerfile b/testdata/docker/arm/7/Dockerfile new file mode 100644 index 0000000..e1f1121 --- /dev/null +++ b/testdata/docker/arm/7/Dockerfile @@ -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"] \ No newline at end of file