Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Mar 29, 2024
1 parent 443a5f5 commit 5e68ea3
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 35 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "n5.1.2"
srcPath = "tmp/$(version)/src"
postCheckout = ""
platform = ""

generate-flags:
go run internal/cmd/flags/main.go
Expand All @@ -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)
8 changes: 0 additions & 8 deletions astiav_!windows.go

This file was deleted.

8 changes: 0 additions & 8 deletions astiav_windows.go

This file was deleted.

8 changes: 4 additions & 4 deletions bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
2 changes: 1 addition & 1 deletion channel_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}
6 changes: 3 additions & 3 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions frame_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
})
}
Expand Down
2 changes: 1 addition & 1 deletion frame_side_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
6 changes: 3 additions & 3 deletions packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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)
})
}
Expand Down
6 changes: 3 additions & 3 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand All @@ -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
}

Expand Down
38 changes: 38 additions & 0 deletions testdata/docker/arm/7/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 5e68ea3

Please sign in to comment.