diff --git a/README.md b/README.md index c5861841..56698aca 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/internal/core/core.go b/internal/core/core.go index 4fbd64f1..743d21fe 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -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 diff --git a/internal/rpicamera/exe/Makefile b/internal/rpicamera/exe/Makefile index 5f285dfc..d2a19012 100644 --- a/internal/rpicamera/exe/Makefile +++ b/internal/rpicamera/exe/Makefile @@ -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 $@ diff --git a/internal/rpicamera/rpicamera.go b/internal/rpicamera/rpicamera.go index c9b288c9..969d9785 100644 --- a/internal/rpicamera/rpicamera.go +++ b/internal/rpicamera/rpicamera.go @@ -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), } diff --git a/scripts/binaries.mk b/scripts/binaries.mk index b25afec6..c1209a7a 100644 --- a/scripts/binaries.mk +++ b/scripts/binaries.mk @@ -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