A real-time camera streaming system built on a Raspberry Pi that integrates a custom Linux kernel module, a multithreaded user-space capture pipeline, MJPEG HTTP streaming, and optional on-device object detection using TensorFlow Lite.
This project demonstrates end-to-end system design across kernel space and user space. It combines Linux interfaces (V4L2, IOCTL, MMAP) with concurrent data pipelines and computer vision inference.
๐ก Additional Notes: Each key feature includes a link to in-depth implementation notes that describe how the module was designed and built.
๐ฟ Branches
main - Stable, fully integrated version of the project
stream - Core camera capture and MJPEG streaming pipeline
stream_detect - Streaming pipeline with on-device object detection
gh-pages - Generated documentation hosted via github pages
๐ Documentation: The project includes comprehensive Doxygen documentation covering modules, functions, classes and detailed usage.
๐ Explore the generated docs: Doxygen Documentation
๐ Explore how the documentation was structured and written: Notes on Notion
๐๏ธ Key Features
- Custom Linux Kernel Module Notes on Notion
- Character device driver exposing camera control and LED status signaling via
ioctl
- Well-defined kernel โ user-space interface with minimal surface area
- GPIO-driven LED indicators reflecting real-time camera streaming state
GPIO ยท IOCTL ยท Character device ยท Linux kernel ยท kernel โ user space interface
- V4L2-Based Camera Pipeline Notes on Notion
- Camera configuration using V4L2 API, including format negotiation and stream parameters
- Buffer allocation and zero-copy frame access via memory mapping I/O (MMAP)
- Continuous frame capture with explicit buffer dequeue and re-queue operations
V4L2 ยท Camera drivers ยท MMAP ยท Buffer management ยท Video streaming
- Multithreaded Producer-Consumer Architecture
- Dedicated producer thread captures frames from the camera pipeline
- Consumer thread streams encoded frames to connected HTTP clients
- Lock-protected circular buffer ensure safe, low-latency data exchange between threads
Mutex ยท Semaphore ยท Circular buffers ยท Multithreading ยท Producer-consumer model
- MJPEG HTTP Streaming Notes on Notion
- Lightweight HTTP server for serving video streams
- Multipart MJPEG streaming compatible with web browsers and MJPEG clients
HTTP ยท MJPEG ยท Sockets ยท Lightweight server ยท Multipart streams
- Real-Time Object Detection Notes on Notion
- Performs on-device inference using TensorFlow Lite on captured frames
- Optimized for real-time edge deployment on the Raspberry Pi
Edge AI ยท Object Detection ยท Embedded ML ยท TensorFlow Lite ยท Real-time Inference.
๐งถ Threading Model
- Producer Thread
- Continously capture frames from the camera using V4L2
- Converts raw frames to JPEG and pushes them into a circular buffer
- Signals frame availability using a semaphore
- Consumer Thread
- Waits on the semaphore for available frames
- Retrieves JPEG frames from the circular buffer
- Streams JPEG frames to connected HTTP clients
- Frees the memory of the processed frames
This design allows for producer thread to run continously, while a new consumer thread is spawned per client.
๐๏ธ High Level Flow
Program Flow Explanation
main.c (Program Entry Point)
โโ> Initialize camera module (opens custom kernel module)
โโ> Start HTTP server for MJPEG streaming
โโ> Initialize threading pipeline
Producer Thread
โโ> Capture frames from the camera (YUYV format)
โโ> Convert YUYV โ RGB
โโ> Optional: Perform object detection on RGB frames
โโ> Convert RGB โ JPEG
โโ> Push JPEG frames into circular buffer
Consumer Thread
โโ> Retrieve JPEG frames from circular buffer
โโ> Stream frames over HTTP (MJPEG)
โโ> Display stream in browser
โ๏ธ Hardware
- Raspberry Pi 5 - primary embedded platform for kernel and user-space execution
- Logitech C270 USB webcam - V4L2-compatible video capture device
- GPIO-connected RGB LED - real-time system status indication
- RED: idle state or error condition
- GREEN: active camera streaming
๐งฑ Build and Run
make module: Build the kernel module
make user: Build the user-space application
make: Build both the kernel module & user-space application
sudo insmod kernel/cam_stream.ko: Insert the kernel module
sudo ./camera_client: Start the camera streaming application
http://<raspberry-pi-ip>/stream: Open broswer and view the stream
๐ Repository Structure
๐ pi_live_stream/
โ
โโโ docs/ # Doxygen-generated documentation
โ
โโโ kernel/ # Linux kernel module
โ โโโ cam_stream.c # Character device + ioctl implementation
โ โโโ cam_stream_ioctl.h # Shared ioctl interface (kernel โ user)
โ โโโ Makefile # Kernel module build rules
โ
โโโ src/ # User-space application
โ โโโ camera/ # V4L2 camera capture & buffer management
โ โ โโโ camera.c
โ โ โโโ camera.h
โ โ
โ โโโ cb/ # Lock-protected circular buffer
โ โ โโโ circular_buffer.c
โ โ โโโ circular_buffer.h
โ โ
โ โโโ detection/ # Real-time object detection (TFLite)
โ โ โโโ detection.cpp
โ โ โโโ detection.h
โ โ โโโ models/
โ โ โโโ detect.tflite
โ โ
โ โโโ http/ # HTTP server + MJPEG streaming
โ โ โโโ http_server.c
โ โ โโโ http_server.h
โ โ โโโ mjpeg_stream.c
โ โ โโโ mjpeg_stream.h
โ โ
โ โโโ image/ # Image processing & encoding
โ โ โโโ image_encoder.c
โ โ โโโ image_encoder.h
โ โ โโโ image_processor.c
โ โ โโโ image_processor.h
โ โ
โ โโโ main.c # Application entry point & thread orchestration
โ
โโโ README.md # Project overview & usage
โโโ Makefile # Builds kernel module and user-space client