diff --git a/camera_example/Makefile b/camera_example/Makefile new file mode 100644 index 0000000..b03035a --- /dev/null +++ b/camera_example/Makefile @@ -0,0 +1,17 @@ +# Build on the device. Needs: +# apt install g++ pkg-config libcamera-dev libevent-dev libjpeg-turbo8-dev +# (Raspberry Pi OS Bullseye+; on older releases the turbo package is libjpeg-dev.) + +CXX ?= g++ +CXXFLAGS ?= -O2 -std=c++17 -pipe -Wall -Wextra +PKGS = libcamera libevent libevent_pthreads libturbojpeg + +camera: camera.cpp event_loop.cpp event_loop.hpp + $(CXX) $(CXXFLAGS) camera.cpp event_loop.cpp \ + $(shell pkg-config --cflags --libs $(PKGS)) -lpthread \ + -o camera + +clean: + rm -f camera + +.PHONY: clean diff --git a/camera_example/README.md b/camera_example/README.md new file mode 100644 index 0000000..3e9fb41 --- /dev/null +++ b/camera_example/README.md @@ -0,0 +1,27 @@ +# camera_example + +libcamera viewfinder (XRGB8888) -> libjpeg-turbo -> TCP. One client at a time. + +Wire format: `[uint32 BE jpeg_size][jpeg_bytes]` repeating. + +Knobs are constants at the top of `camera.cpp` (fps, quality, AF mode, lens +position, port, resolution). + +## Build on the Pi + + apt install g++ pkg-config libcamera-dev libevent-dev libjpeg-turbo8-dev + make + +## Cross-build (x86 -> armv6l) on a Nix host + + nix build + +The resulting binary links against `/nix/store`, so it only runs on a Pi that +has those libs available (i.e. nix installed). For a vanilla Pi OS target, +use the Makefile on the device, or `./deploy.sh user@host` to rsync+build. + +## Receive + +Any TCP client that reads the framed JPEGs. Quick check: + + nc 5000 | ffplay -f mjpeg - diff --git a/camera_example/deploy.sh b/camera_example/deploy.sh new file mode 100755 index 0000000..8feb44d --- /dev/null +++ b/camera_example/deploy.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh +# Push sources to the Pi and build there. +# usage: ./deploy.sh me@10.91.51.165 +set -eu +host=${1:-me@10.91.51.165} +rsync -az --delete --exclude=camera --exclude=result \ + ./ "$host:~/camera_example/" +ssh "$host" 'cd ~/camera_example && make -j"$(nproc)"' +echo "built at $host:~/camera_example/camera"