Browse Source

rpi camera: remove patchelf dependency (#2093)

pull/2096/head
Alessandro Ros 2 years ago committed by GitHub
parent
commit
2e476cf4e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      README.md
  2. 5
      internal/core/core.go
  3. 2
      internal/rpicamera/exe/Makefile
  4. 54
      internal/rpicamera/rpicamera.go
  5. 16
      scripts/binaries.mk

3
README.md

@ -454,7 +454,7 @@ If you want to run the standard (non-Docker) version of the server: @@ -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 @@ -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:

5
internal/core/core.go

@ -17,7 +17,6 @@ import ( @@ -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) { @@ -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

2
internal/rpicamera/exe/Makefile

@ -47,5 +47,3 @@ text_font.h: text_font.ttf @@ -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 $@

54
internal/rpicamera/rpicamera.go

@ -82,57 +82,35 @@ func check64bit(fpath string) error { @@ -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 checked {
return nil
}
for _, name := range []string{"libcamera", "libcamera-base"} {
lib, err := findLibrary(name)
if err != nil {
return err
}
err = setupSymlink("libcamera-base")
err = check64bit(lib)
if err != nil {
return err
}
setupped = true
}
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( @@ -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( @@ -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),
}

16
scripts/binaries.mk

@ -1,17 +1,17 @@ @@ -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

Loading…
Cancel
Save