Skip to content

Commit f886f67

Browse files
committed
embed libcamera and libfreetype into the component
1 parent d4c9730 commit f886f67

File tree

10 files changed

+285
-88
lines changed

10 files changed

+285
-88
lines changed

.dockerignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*.o
2-
text_font.*
3-
mtxrpicam
4-
mtxrpicam_*
2+
/deps
3+
/prefix
4+
/mtxrpicam_*

.github/workflows/release.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414

15-
- run: make -f utils.mk build32
15+
- run: make -f utils.mk build_32
16+
17+
- run: tar -czf mtxrpicam_32.tar.gz mtxrpicam_32
1618

1719
- uses: actions/upload-artifact@v4
1820
with:
19-
path: mtxrpicam_32
20-
name: mtxrpicam_32
21+
path: mtxrpicam_32.tar.gz
22+
name: mtxrpicam_32.tar.gz
2123

2224
build_64:
2325
runs-on: ubuntu-22.04
2426

2527
steps:
2628
- uses: actions/checkout@v4
2729

28-
- run: make -f utils.mk build64
30+
- run: make -f utils.mk build_64
31+
32+
- run: tar -czf mtxrpicam_64.tar.gz mtxrpicam_64
2933

3034
- uses: actions/upload-artifact@v4
3135
with:
32-
path: mtxrpicam_64
33-
name: mtxrpicam_64
36+
path: mtxrpicam_64.tar.gz
37+
name: mtxrpicam_64.tar.gz
3438

3539
github_release:
3640
needs:
@@ -41,12 +45,12 @@ jobs:
4145
steps:
4246
- uses: actions/download-artifact@v4
4347
with:
44-
name: mtxrpicam_32
48+
name: mtxrpicam_32.tar.gz
4549
path: binaries/
4650

4751
- uses: actions/download-artifact@v4
4852
with:
49-
name: mtxrpicam_64
53+
name: mtxrpicam_64.tar.gz
5054
path: binaries/
5155

5256
- uses: actions/github-script@v6

.github/workflows/test.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16-
- run: make -f utils.mk build32
16+
- run: make -f utils.mk build_32
1717

1818
- uses: actions/upload-artifact@v4
1919
with:
@@ -26,14 +26,14 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@v4
2828

29-
- run: make -f utils.mk build64
29+
- run: make -f utils.mk build_64
3030

3131
- uses: actions/upload-artifact@v4
3232
with:
3333
path: mtxrpicam_64
3434
name: mtxrpicam_64
3535

36-
test_32:
36+
test_bullseye_32:
3737
needs: build_32
3838
runs-on: ubuntu-22.04
3939

@@ -45,11 +45,9 @@ jobs:
4545
name: mtxrpicam_32
4646
path: .
4747

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

50-
- run: make -f utils.mk test32
51-
52-
test_64:
50+
test_bullseye_64:
5351
needs: build_64
5452
runs-on: ubuntu-22.04
5553

@@ -61,6 +59,32 @@ jobs:
6159
name: mtxrpicam_64
6260
path: .
6361

64-
- run: chmod +x mtxrpicam_64
62+
- run: make -f utils.mk test_bullseye_64
63+
64+
test_bookworm_32:
65+
needs: build_32
66+
runs-on: ubuntu-22.04
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- uses: actions/download-artifact@v4
72+
with:
73+
name: mtxrpicam_32
74+
path: .
75+
76+
- run: make -f utils.mk test_bookworm_32
77+
78+
test_bookworm_64:
79+
needs: build_64
80+
runs-on: ubuntu-22.04
81+
82+
steps:
83+
- uses: actions/checkout@v4
84+
85+
- uses: actions/download-artifact@v4
86+
with:
87+
name: mtxrpicam_64
88+
path: .
6589

66-
- run: make -f utils.mk test64
90+
- run: make -f utils.mk test_bookworm_64

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*.o
2-
text_font.*
3-
mtxrpicam
4-
mtxrpicam_*
2+
/deps
3+
/prefix
4+
/mtxrpicam_*

Makefile

Lines changed: 119 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,133 @@
11
ifeq ($(shell gcc -dumpmachine),aarch64-linux-gnu)
2-
EXECUTABLE_NAME = mtxrpicam_64
2+
OUT_DIR = mtxrpicam_64
33
else
4-
EXECUTABLE_NAME = mtxrpicam_32
4+
OUT_DIR = mtxrpicam_32
55
endif
66

7-
all: $(EXECUTABLE_NAME)
7+
all: \
8+
$(OUT_DIR)/exe \
9+
$(OUT_DIR)/ipa_conf \
10+
$(OUT_DIR)/ipa_module \
11+
$(OUT_DIR)/libcamera.so.9.9 \
12+
$(OUT_DIR)/libcamera-base.so.9.9
13+
14+
folder:
15+
mkdir -p $(OUT_DIR)
16+
17+
#################################################
18+
# openssl
19+
20+
OPENSSL_REPO = https://github.com/openssl/openssl
21+
OPENSSL_TAG = openssl-3.3.1
22+
23+
OPENSSL_TARGET = prefix/lib/libcrypto.a
24+
25+
deps/openssl:
26+
git clone -b $(OPENSSL_TAG) --depth=1 $(OPENSSL_REPO) $@
27+
28+
$(OPENSSL_TARGET): deps/openssl
29+
cd $< \
30+
&& ./Configure \
31+
--prefix=$(PWD)/prefix \
32+
no-shared \
33+
no-threads \
34+
no-quic \
35+
no-uplink \
36+
&& make -j$$(nproc) \
37+
&& make install_sw
38+
39+
#################################################
40+
# libcamera
41+
42+
LIBCAMERA_REPO = https://github.com/raspberrypi/libcamera
43+
LIBCAMERA_TAG = v0.3.0+rpt20240617
44+
45+
LIBCAMERA_TARGET = prefix/lib/libcamera.so
46+
47+
deps/libcamera:
48+
git clone -b $(LIBCAMERA_TAG) --depth=1 $(LIBCAMERA_REPO) $@
49+
50+
$(LIBCAMERA_TARGET): deps/libcamera $(OPENSSL_TARGET)
51+
cd $< \
52+
&& echo "0.3.0+mediamtx" > .tarball-version \
53+
&& patch -p1 < ../../libcamera.patch \
54+
&& PATH=$(PWD)/prefix/bin:$$PATH \
55+
PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig \
56+
meson setup build \
57+
--prefix=$(PWD)/prefix \
58+
--buildtype=release \
59+
-Dwrap_mode=forcefallback \
60+
-Dlc-compliance=disabled \
61+
-Dipas=rpi/vc4 \
62+
-Dpipelines=rpi/vc4 \
63+
-Dcam=disabled \
64+
-Ddocumentation=disabled \
65+
-Dgstreamer=disabled \
66+
-Dpycamera=disabled \
67+
-Dqcam=disabled \
68+
-Dtracing=disabled \
69+
-Dudev=disabled \
70+
&& ninja -C build install
71+
72+
$(OUT_DIR)/ipa_conf: folder $(LIBCAMERA_TARGET)
73+
cp -r prefix/share/libcamera/ipa $@
74+
75+
$(OUT_DIR)/ipa_module: folder $(LIBCAMERA_TARGET)
76+
cp -r prefix/lib/libcamera $@
77+
78+
# $(OUT_DIR)/ipa_proxy: folder $(LIBCAMERA_TARGET)
79+
# cp -r prefix/libexec/libcamera $@
80+
81+
$(OUT_DIR)/libcamera.so.9.9: folder $(LIBCAMERA_TARGET)
82+
cp prefix/lib/libcamera.so.9.9 $@
83+
84+
$(OUT_DIR)/libcamera-base.so.9.9: folder $(LIBCAMERA_TARGET)
85+
cp prefix/lib/libcamera-base.so.9.9 $@
86+
87+
#################################################
88+
# libfreetype
89+
90+
FREETYPE_REPO = https://github.com/freetype/freetype
91+
FREETYPE_BRANCH = VER-2-11-1
92+
93+
FREETYPE_TARGET = prefix/lib/libfreetype.a
94+
95+
deps/freetype:
96+
git clone -b $(FREETYPE_BRANCH) --depth=1 $(FREETYPE_REPO) $@
97+
98+
$(FREETYPE_TARGET): deps/freetype
99+
cd $< \
100+
&& cmake -B build \
101+
-DCMAKE_INSTALL_PREFIX:PATH=$(PWD)/prefix \
102+
-D CMAKE_BUILD_TYPE=Release \
103+
-D BUILD_SHARED_LIBS=false \
104+
-D FT_DISABLE_ZLIB=TRUE \
105+
-D FT_DISABLE_BZIP2=TRUE \
106+
-D FT_DISABLE_PNG=TRUE \
107+
-D FT_DISABLE_HARFBUZZ=TRUE \
108+
-D FT_DISABLE_BROTLI=TRUE \
109+
&& make -C build -j$$(nproc) \
110+
&& make -C build install
8111

9112
#################################################
10113
# text font
11114

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

15-
TEXT_FONT_TARGET = text_font.h
118+
TEXT_FONT_TARGET = deps/text_font.h
16119

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

22-
$(TEXT_FONT_TARGET): text_font.ttf
126+
$(TEXT_FONT_TARGET): deps/text_font.ttf
23127
xxd --include $< > $@
24128

25129
#################################################
26-
# mtxrpicam
130+
# exe
27131

28132
CFLAGS = \
29133
-Ofast \
@@ -32,7 +136,7 @@ CFLAGS = \
32136
-Wextra \
33137
-Wno-unused-parameter \
34138
-Wno-unused-result \
35-
$$(pkg-config --cflags freetype2)
139+
$$(PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig pkg-config --cflags freetype2)
36140

37141
CXXFLAGS = \
38142
-Ofast \
@@ -42,13 +146,13 @@ CXXFLAGS = \
42146
-Wno-unused-parameter \
43147
-Wno-unused-result \
44148
-std=c++17 \
45-
$$(pkg-config --cflags libcamera)
149+
$$(PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig pkg-config --cflags libcamera)
46150

47151
LDFLAGS = \
48152
-s \
49153
-pthread \
50-
$$(pkg-config --libs freetype2) \
51-
$$(pkg-config --libs libcamera)
154+
$$(PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig pkg-config --libs freetype2) \
155+
$$(PKG_CONFIG_PATH=$(PWD)/prefix/lib/pkgconfig pkg-config --libs libcamera)
52156

53157
OBJS = \
54158
base64.o \
@@ -62,6 +166,8 @@ OBJS = \
62166
window.o
63167

64168
DEPENDENCIES = \
169+
$(LIBCAMERA_TARGET) \
170+
$(FREETYPE_TARGET) \
65171
$(TEXT_FONT_TARGET)
66172

67173
%.o: %.c $(DEPENDENCIES)
@@ -70,5 +176,6 @@ DEPENDENCIES = \
70176
%.o: %.cpp $(DEPENDENCIES)
71177
$(CXX) $(CXXFLAGS) -c $< -o $@
72178

73-
$(EXECUTABLE_NAME): $(OBJS)
179+
$(OUT_DIR)/exe: $(OBJS)
180+
mkdir -p $(OUT_DIR)
74181
$(CXX) $^ $(LDFLAGS) -o $@

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded
1515
```sh
1616
sudo apt install -y \
1717
g++ \
18-
pkg-config \
1918
make \
20-
libcamera-dev \
21-
libfreetype-dev \
2219
xxd \
23-
wget
20+
wget \
21+
git \
22+
cmake \
23+
meson \
24+
patch \
25+
pkg-config \
26+
python3-jinja2 \
27+
python3-yaml \
28+
python3-ply
2429
```
2530

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

32-
This will produce `mtxrpicam_32` or `mtxrpicam_64` (depending on the architecture).
37+
This will produce the `mtxrpicam_32` or `mtxrpicam_64` folder (depending on the architecture).
3338

3439
## Cross-compile
3540

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

46-
This will produce `mtxrpicam_32` and `mtxrpicam_64`.
51+
This will produce the `mtxrpicam_32` and `mtxrpicam_64` folders.
4752

48-
## Installation
53+
## Install
4954

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

0 commit comments

Comments
 (0)