Skip to content

Commit

Permalink
embed libcamera and libfreetype into the component
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Aug 17, 2024
1 parent d4c9730 commit 60a42a7
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 90 deletions.
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.o
text_font.*
mtxrpicam
mtxrpicam_*
/deps
/prefix
/mtxrpicam_*
20 changes: 12 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ jobs:
steps:
- uses: actions/checkout@v4

- run: make -f utils.mk build32
- run: make -f utils.mk build_32

- run: tar -czf mtxrpicam_32.tar.gz mtxrpicam_32

- uses: actions/upload-artifact@v4
with:
path: mtxrpicam_32
name: mtxrpicam_32
path: mtxrpicam_32.tar.gz
name: mtxrpicam_32.tar.gz

build_64:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- run: make -f utils.mk build64
- run: make -f utils.mk build_64

- run: tar -czf mtxrpicam_64.tar.gz mtxrpicam_64

- uses: actions/upload-artifact@v4
with:
path: mtxrpicam_64
name: mtxrpicam_64
path: mtxrpicam_64.tar.gz
name: mtxrpicam_64.tar.gz

github_release:
needs:
Expand All @@ -41,12 +45,12 @@ jobs:
steps:
- uses: actions/download-artifact@v4
with:
name: mtxrpicam_32
name: mtxrpicam_32.tar.gz
path: binaries/

- uses: actions/download-artifact@v4
with:
name: mtxrpicam_64
name: mtxrpicam_64.tar.gz
path: binaries/

- uses: actions/github-script@v6
Expand Down
42 changes: 33 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- run: make -f utils.mk build32
- run: make -f utils.mk build_32

- uses: actions/upload-artifact@v4
with:
Expand All @@ -26,14 +26,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- run: make -f utils.mk build64
- run: make -f utils.mk build_64

- uses: actions/upload-artifact@v4
with:
path: mtxrpicam_64
name: mtxrpicam_64

test_32:
test_bullseye_32:
needs: build_32
runs-on: ubuntu-22.04

Expand All @@ -45,11 +45,9 @@ jobs:
name: mtxrpicam_32
path: .

- run: chmod +x mtxrpicam_32
- run: make -f utils.mk test_bullseye_32

- run: make -f utils.mk test32

test_64:
test_bullseye_64:
needs: build_64
runs-on: ubuntu-22.04

Expand All @@ -61,6 +59,32 @@ jobs:
name: mtxrpicam_64
path: .

- run: chmod +x mtxrpicam_64
- run: make -f utils.mk test_bullseye_64

test_bookworm_32:
needs: build_32
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: mtxrpicam_32
path: .

- run: make -f utils.mk test_bookworm_32

test_bookworm_64:
needs: build_64
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: mtxrpicam_64
path: .

- run: make -f utils.mk test64
- run: make -f utils.mk test_bookworm_64
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.o
text_font.*
mtxrpicam
mtxrpicam_*
/deps
/prefix
/mtxrpicam_*
131 changes: 119 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,133 @@
ifeq ($(shell gcc -dumpmachine),aarch64-linux-gnu)
EXECUTABLE_NAME = mtxrpicam_64
OUT_DIR = mtxrpicam_64
else
EXECUTABLE_NAME = mtxrpicam_32
OUT_DIR = mtxrpicam_32
endif

all: $(EXECUTABLE_NAME)
all: \
$(OUT_DIR)/exe \
$(OUT_DIR)/ipa_conf \
$(OUT_DIR)/ipa_module \
$(OUT_DIR)/libcamera.so.9.9 \
$(OUT_DIR)/libcamera-base.so.9.9

folder:
mkdir -p $(OUT_DIR)

#################################################
# openssl

OPENSSL_REPO = https://github.com/openssl/openssl
OPENSSL_TAG = openssl-3.3.1

OPENSSL_TARGET = prefix/lib/libcrypto.a

deps/openssl:
git clone -b $(OPENSSL_TAG) --depth=1 $(OPENSSL_REPO) $@

$(OPENSSL_TARGET): deps/openssl
cd $< \
&& ./Configure \
--prefix=$(PWD)/prefix \
no-shared \
no-threads \
no-quic \
no-uplink \
&& make -j$$(nproc) \
&& make install_sw

#################################################
# libcamera

LIBCAMERA_REPO = https://github.com/raspberrypi/libcamera
LIBCAMERA_TAG = v0.3.0+rpt20240617

LIBCAMERA_TARGET = prefix/lib/libcamera.so

deps/libcamera:
git clone -b $(LIBCAMERA_TAG) --depth=1 $(LIBCAMERA_REPO) $@

$(LIBCAMERA_TARGET): deps/libcamera $(OPENSSL_TARGET)
cd $< \
&& echo "0.3.0+mediamtx" > .tarball-version \
&& patch -p1 < ../../libcamera.patch \
&& PATH=$(PWD)/prefix/bin:$$PATH \
PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig \
meson setup build \
--prefix=$(PWD)/prefix \
--buildtype=release \
-Dwrap_mode=forcefallback \
-Dlc-compliance=disabled \
-Dipas=rpi/vc4 \
-Dpipelines=rpi/vc4 \
-Dcam=disabled \
-Ddocumentation=disabled \
-Dgstreamer=disabled \
-Dpycamera=disabled \
-Dqcam=disabled \
-Dtracing=disabled \
-Dudev=disabled \
&& ninja -C build install

$(OUT_DIR)/ipa_conf: folder $(LIBCAMERA_TARGET)
cp -r prefix/share/libcamera/ipa $@

$(OUT_DIR)/ipa_module: folder $(LIBCAMERA_TARGET)
cp -r prefix/lib/libcamera $@

# $(OUT_DIR)/ipa_proxy: folder $(LIBCAMERA_TARGET)
# cp -r prefix/libexec/libcamera $@

$(OUT_DIR)/libcamera.so.9.9: folder $(LIBCAMERA_TARGET)
cp prefix/lib/libcamera.so.9.9 $@

$(OUT_DIR)/libcamera-base.so.9.9: folder $(LIBCAMERA_TARGET)
cp prefix/lib/libcamera-base.so.9.9 $@

#################################################
# libfreetype

FREETYPE_REPO = https://github.com/freetype/freetype
FREETYPE_BRANCH = VER-2-11-1

FREETYPE_TARGET = prefix/lib/libfreetype.a

deps/freetype:
git clone -b $(FREETYPE_BRANCH) --depth=1 $(FREETYPE_REPO) $@

$(FREETYPE_TARGET): deps/freetype
cd $< \
&& cmake -B build \
-DCMAKE_INSTALL_PREFIX:PATH=$(PWD)/prefix \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=false \
-D FT_DISABLE_ZLIB=TRUE \
-D FT_DISABLE_BZIP2=TRUE \
-D FT_DISABLE_PNG=TRUE \
-D FT_DISABLE_HARFBUZZ=TRUE \
-D FT_DISABLE_BROTLI=TRUE \
&& make -C build -j$$(nproc) \
&& make -C build install

#################################################
# text font

TEXT_FONT_URL = https://github.com/IBM/plex/raw/v6.4.2/IBM-Plex-Mono/fonts/complete/ttf/IBMPlexMono-Medium.ttf
TEXT_FONT_SHA256 = 0bede3debdea8488bbb927f8f0650d915073209734a67fe8cd5a3320b572511c

TEXT_FONT_TARGET = text_font.h
TEXT_FONT_TARGET = deps/text_font.h

text_font.ttf:
deps/text_font.ttf:
mkdir -p deps
wget -O $@.tmp $(TEXT_FONT_URL)
H=$$(sha256sum $@.tmp | awk '{ print $$1 }'); [ "$$H" = "$(TEXT_FONT_SHA256)" ] || { echo "hash mismatch; got $$H, expected $(TEXT_FONT_SHA256)"; exit 1; }
mv $@.tmp $@

$(TEXT_FONT_TARGET): text_font.ttf
$(TEXT_FONT_TARGET): deps/text_font.ttf
xxd --include $< > $@

#################################################
# mtxrpicam
# exe

CFLAGS = \
-Ofast \
Expand All @@ -32,7 +136,7 @@ CFLAGS = \
-Wextra \
-Wno-unused-parameter \
-Wno-unused-result \
$$(pkg-config --cflags freetype2)
$$(PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig pkg-config --cflags freetype2)

CXXFLAGS = \
-Ofast \
Expand All @@ -42,13 +146,13 @@ CXXFLAGS = \
-Wno-unused-parameter \
-Wno-unused-result \
-std=c++17 \
$$(pkg-config --cflags libcamera)
$$(PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig pkg-config --cflags libcamera)

LDFLAGS = \
-s \
-pthread \
$$(pkg-config --libs freetype2) \
$$(pkg-config --libs libcamera)
$$(PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig pkg-config --libs freetype2) \
$$(PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig pkg-config --libs libcamera)

OBJS = \
base64.o \
Expand All @@ -62,6 +166,8 @@ OBJS = \
window.o

DEPENDENCIES = \
$(LIBCAMERA_TARGET) \
$(FREETYPE_TARGET) \
$(TEXT_FONT_TARGET)

%.o: %.c $(DEPENDENCIES)
Expand All @@ -70,5 +176,6 @@ DEPENDENCIES = \
%.o: %.cpp $(DEPENDENCIES)
$(CXX) $(CXXFLAGS) -c $< -o $@

$(EXECUTABLE_NAME): $(OBJS)
$(OUT_DIR)/exe: $(OBJS)
mkdir -p $(OUT_DIR)
$(CXX) $^ $(LDFLAGS) -o $@
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded
```sh
sudo apt install -y \
g++ \
pkg-config \
make \
libcamera-dev \
libfreetype-dev \
xxd \
wget
wget \
git \
cmake \
meson \
patch \
pkg-config \
python3-jinja2 \
python3-yaml \
python3-ply
```

3. Build:
Expand All @@ -29,7 +34,7 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded
make -j$(nproc)
```

This will produce `mtxrpicam_32` or `mtxrpicam_64` (depending on the architecture).
This will produce the `mtxrpicam_32` or `mtxrpicam_64` folder (depending on the architecture).

## Cross-compile

Expand All @@ -43,9 +48,9 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded
make -f utils.mk build
```

This will produce `mtxrpicam_32` and `mtxrpicam_64`.
This will produce the `mtxrpicam_32` and `mtxrpicam_64` folders.

## Installation
## Install

1. Download MediaMTX source code and open a terminal in it

Expand Down
Loading

0 comments on commit 60a42a7

Please sign in to comment.