rpi camera: remove patchelf dependency (#2093)

This commit is contained in:
Alessandro Ros 2023-07-22 13:54:08 +02:00 committed by GitHub
parent 59a5d40fda
commit 2e476cf4e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 61 deletions

View file

@ -454,7 +454,7 @@ If you want to run the standard (non-Docker) version of the server:
1. Make sure that the following packages are installed:
* `libcamera0` (at least version 0.0.2)
* `libcamera0` (≥ 0.0.5)
* `libfreetype6`
2. download the server executable. If you're using 64-bit version of the operative system, make sure to pick the `arm64` variant.
@ -1376,7 +1376,6 @@ The server can be compiled with native support for the Raspberry Pi Camera. Comp
* `libcamera-dev`
* `libfreetype-dev`
* `xxd`
* `patchelf`
Download the repository, open a terminal in it and run:

View file

@ -17,7 +17,6 @@ import (
"github.com/bluenviron/mediamtx/internal/externalcmd"
"github.com/bluenviron/mediamtx/internal/logger"
"github.com/bluenviron/mediamtx/internal/rlimit"
"github.com/bluenviron/mediamtx/internal/rpicamera"
)
var version = "v0.0.0"
@ -671,10 +670,6 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
p.externalCmdPool.Close()
}
if newConf == nil {
rpicamera.Cleanup()
}
if closeLogger {
p.logger.Close()
p.logger = nil

View file

@ -47,5 +47,3 @@ text_font.h: text_font.ttf
exe: $(OBJS)
$(CXX) $^ $(LDFLAGS) -o $@
patchelf --replace-needed $$(basename /usr/lib/*-linux-*/libcamera.so.0*) libcamera.so.x.x.x $@
patchelf --replace-needed $$(basename /usr/lib/*-linux-*/libcamera-base.so.0*) libcamera-base.so.x.x.x $@

View file

@ -82,57 +82,35 @@ func check64bit(fpath string) error {
return nil
}
func setupSymlink(name string) error {
lib, err := findLibrary(name)
if err != nil {
return err
}
if runtime.GOARCH == "arm" {
err := check64bit(lib)
if err != nil {
return err
}
}
os.Remove("/dev/shm/" + name + ".so.x.x.x")
return os.Symlink(lib, "/dev/shm/"+name+".so.x.x.x")
}
var (
mutex sync.Mutex
setupped bool
mutex sync.Mutex
checked bool
)
func setupLibcameraOnce() error {
func checkLibraries64Bit() error {
mutex.Lock()
defer mutex.Unlock()
if !setupped {
err := setupSymlink("libcamera")
if err != nil {
return err
}
err = setupSymlink("libcamera-base")
if err != nil {
return err
}
setupped = true
if checked {
return nil
}
for _, name := range []string{"libcamera", "libcamera-base"} {
lib, err := findLibrary(name)
if err != nil {
return err
}
err = check64bit(lib)
if err != nil {
return err
}
}
checked = true
return nil
}
// Cleanup cleanups files created by the camera implementation.
func Cleanup() {
if setupped {
os.Remove("/dev/shm/libcamera-base.so.x.x.x")
os.Remove("/dev/shm/libcamera.so.x.x.x")
}
}
type RPICamera struct {
onData func(time.Duration, [][]byte)
@ -148,15 +126,18 @@ func New(
params Params,
onData func(time.Duration, [][]byte),
) (*RPICamera, error) {
err := setupLibcameraOnce()
if err != nil {
return nil, err
if runtime.GOARCH == "arm" {
err := checkLibraries64Bit()
if err != nil {
return nil, err
}
}
c := &RPICamera{
onData: onData,
}
var err error
c.pipeConf, err = newPipe()
if err != nil {
return nil, err
@ -169,7 +150,6 @@ func New(
}
env := []string{
"LD_LIBRARY_PATH=/dev/shm",
"PIPE_CONF_FD=" + strconv.FormatInt(int64(c.pipeConf.readFD), 10),
"PIPE_VIDEO_FD=" + strconv.FormatInt(int64(c.pipeVideo.writeFD), 10),
}

View file

@ -1,17 +1,17 @@
define DOCKERFILE_BINARIES
FROM $(RPI32_IMAGE) AS rpicamera32
RUN ["cross-build-start"]
RUN apt update && apt install -y --no-install-recommends g++ pkg-config make libcamera-dev libfreetype-dev xxd patchelf
WORKDIR /s/internal/rpicamera
COPY internal/rpicamera .
RUN cd exe && make -j$$(nproc)
RUN apt update && apt install -y --no-install-recommends g++ pkg-config make libcamera-dev libfreetype-dev xxd
WORKDIR /s/internal/rpicamera/exe
COPY internal/rpicamera/exe .
RUN make -j$$(nproc)
FROM $(RPI64_IMAGE) AS rpicamera64
RUN ["cross-build-start"]
RUN apt update && apt install -y --no-install-recommends g++ pkg-config make libcamera-dev libfreetype-dev xxd patchelf
WORKDIR /s/internal/rpicamera
COPY internal/rpicamera .
RUN cd exe && make -j$$(nproc)
RUN apt update && apt install -y --no-install-recommends g++ pkg-config make libcamera-dev libfreetype-dev xxd
WORKDIR /s/internal/rpicamera/exe
COPY internal/rpicamera/exe .
RUN make -j$$(nproc)
FROM $(BASE_IMAGE) AS build-base
RUN apk add --no-cache zip make git tar