Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortLambdasOnASingleLine: Inline
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
Expand All @@ -35,6 +35,8 @@ BraceWrapping:
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
AfterNamespace: true
AfterClass: true
BreakBeforeBinaryOperators: None
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
Expand All @@ -44,7 +46,7 @@ BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
PackConstructorInitializers: BinPack
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/rpicam-apps-pre-commit-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: rpicam-apps pre-commit checker
on:
pull_request:
branches: [main]

jobs:
style-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Run pre-commit
uses: pre-commit/action@v3.0.1
with:
extra_args: --all-files --show-diff-on-failure
18 changes: 0 additions & 18 deletions .github/workflows/rpicam-apps-style-checker.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[general]
contrib=contrib-body-requires-signed-off-by

[title-max-length]
line-length=80

[body-max-line-length]
line-length=80
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
default_stages: [pre-commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v22.1.3
hooks:
- id: clang-format
types_or: [c, c++]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.9
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.11.0.1
hooks:
- id: shellcheck

- repo: local
hooks:
- id: git-diff
name: git diff
entry: git diff --exit-code
language: system
pass_filenames: false
always_run: true

- repo: https://github.com/jorisroovers/gitlint
rev: v0.19.1
hooks:
- id: gitlint
stages: [commit-msg]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ Build
-----
For usage and build instructions, see the official Raspberry Pi documentation pages [here.](https://www.raspberrypi.com/documentation/computers/camera_software.html#building-libcamera-and-rpicam-apps)

For Developers
--------------

This project uses [pre-commit](https://pre-commit.com/) to run formatting and linting checks on each commit. To install:

```sh
pip install pre-commit
pre-commit install
pre-commit install --hook-type commit-msg
```

License
-------

Expand Down
11 changes: 9 additions & 2 deletions apps/rpicam_detect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ struct DetectOptions : public StillOptions
DetectOptions() : StillOptions()
{
using namespace boost::program_options;
// clang-format off
options_->add_options()
("object", value<std::string>(&object), "Name of object to detect")
("gap", value<unsigned int>(&gap)->default_value(30), "Smallest gap between captures in frames")
("timeformat", value<std::string>(&timeformat)->default_value("%m%d%H%M%S"), "Date/Time format string - see C++ strftime()")
;
// clang-format on
}

std::string object;
Expand All @@ -44,8 +46,13 @@ struct DetectOptions : public StillOptions
class RPiCamDetectApp : public RPiCamApp
{
public:
RPiCamDetectApp() : RPiCamApp(std::make_unique<DetectOptions>()) {}
DetectOptions *GetOptions() const { return static_cast<DetectOptions *>(RPiCamApp::GetOptions()); }
RPiCamDetectApp() : RPiCamApp(std::make_unique<DetectOptions>())
{
}
DetectOptions *GetOptions() const
{
return static_cast<DetectOptions *>(RPiCamApp::GetOptions());
}
};

// The main even loop for the application.
Expand Down
4 changes: 2 additions & 2 deletions apps/rpicam_hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <chrono>

#include "core/rpicam_app.hpp"
#include "core/options.hpp"
#include "core/rpicam_app.hpp"

using namespace std::placeholders;

Expand All @@ -24,7 +24,7 @@ static void event_loop(RPiCamApp &app)

auto start_time = std::chrono::high_resolution_clock::now();

for (unsigned int count = 0; ; count++)
for (unsigned int count = 0;; count++)
{
RPiCamApp::Msg msg = app.Wait();
if (msg.type == RPiCamApp::MsgType::Timeout)
Expand Down
3 changes: 1 addition & 2 deletions apps/rpicam_jpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ using libcamera::Stream;
class RPiCamJpegApp : public RPiCamApp
{
public:
RPiCamJpegApp()
: RPiCamApp(std::make_unique<StillOptions>())
RPiCamJpegApp() : RPiCamApp(std::make_unique<StillOptions>())
{
}

Expand Down
11 changes: 8 additions & 3 deletions apps/rpicam_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ using namespace std::placeholders;
class LibcameraRaw : public RPiCamEncoder
{
public:
LibcameraRaw() : RPiCamEncoder() {}
LibcameraRaw() : RPiCamEncoder()
{
}

protected:
// Force the use of "null" encoder.
void createEncoder() { encoder_ = std::unique_ptr<Encoder>(new NullEncoder(GetOptions())); }
void createEncoder()
{
encoder_ = std::unique_ptr<Encoder>(new NullEncoder(GetOptions()));
}
};

// The main even loop for the application.
Expand All @@ -38,7 +43,7 @@ static void event_loop(LibcameraRaw &app)
app.StartCamera();
auto start_time = std::chrono::high_resolution_clock::now();

for (unsigned int count = 0; ; count++)
for (unsigned int count = 0;; count++)
{
LibcameraRaw::Msg msg = app.Wait();

Expand Down
12 changes: 8 additions & 4 deletions apps/rpicam_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ namespace fs = std::filesystem;
class RPiCamStillApp : public RPiCamApp
{
public:
RPiCamStillApp() : RPiCamApp(std::make_unique<StillOptions>()) {}
RPiCamStillApp() : RPiCamApp(std::make_unique<StillOptions>())
{
}

StillOptions *GetOptions() const { return static_cast<StillOptions *>(RPiCamApp::GetOptions()); }
StillOptions *GetOptions() const
{
return static_cast<StillOptions *>(RPiCamApp::GetOptions());
}
};

static std::string generate_filename(StillOptions const *options)
Expand Down Expand Up @@ -77,8 +82,7 @@ static void update_latest_link(std::string const &filename, StillOptions const *
}
}

static void save_image(RPiCamStillApp &app, CompletedRequestPtr &payload, Stream *stream,
std::string const &filename)
static void save_image(RPiCamStillApp &app, CompletedRequestPtr &payload, Stream *stream, std::string const &filename)
{
StillOptions const *options = app.GetOptions();
StreamInfo info = app.GetStreamInfo(stream);
Expand Down
2 changes: 1 addition & 1 deletion apps/rpicam_vid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void event_loop(RPiCamEncoder &app)
signal(SIGPIPE, default_signal_handler);
pollfd p[1] = { { STDIN_FILENO, POLLIN, 0 } };

for (unsigned int count = 0; ; count++)
for (unsigned int count = 0;; count++)
{
RPiCamEncoder::Msg msg = app.Wait();
if (msg.type == RPiCamApp::MsgType::Timeout)
Expand Down
2 changes: 1 addition & 1 deletion assets/hailo_classifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"thickness" : 2,
"alpha" : 0.3
}
}
}
2 changes: 1 addition & 1 deletion assets/hailo_pose_inf_fl.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
{
"line_thickness" : 2
}
}
}
2 changes: 1 addition & 1 deletion assets/hailo_yolov5_personface.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
{
"line_thickness" : 2
}
}
}
2 changes: 1 addition & 1 deletion assets/hailo_yolov5_segmentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"hef_file_10": "/usr/share/hailo-models/yolov5n_seg_h10.hef",
"hailopp_config_file": "/usr/share/hailo-models/yolov5seg.json"
}
}
}
2 changes: 1 addition & 1 deletion assets/hailo_yolov6_inference.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
{
"line_thickness" : 2
}
}
}
2 changes: 1 addition & 1 deletion assets/hailo_yolov8_inference.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
{
"line_thickness" : 2
}
}
}
2 changes: 1 addition & 1 deletion assets/hailo_yolox_inference.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
{
"line_thickness" : 2
}
}
}
2 changes: 1 addition & 1 deletion assets/imx500_mobilenet_ssd.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"visible_frames": 4,
"hidden_frames": 2
},

"classes":
[
"person",
Expand Down
2 changes: 1 addition & 1 deletion assets/imx500_posenet.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"plot_pose_cv":
{
"confidence_threshold" : 0.2
}
}
}
2 changes: 1 addition & 1 deletion assets/yolov5_personface.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"person",
"face"
]
}
}
2 changes: 1 addition & 1 deletion assets/yolov5seg.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
],
"input_shape": [640, 640],
"strides": [32, 16, 8]
}
}
5 changes: 2 additions & 3 deletions core/buffer_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
#include <sys/mman.h>

#include "core/buffer_sync.hpp"
#include "core/rpicam_app.hpp"
#include "core/logging.hpp"
#include "core/rpicam_app.hpp"

BufferWriteSync::BufferWriteSync(RPiCamApp *app, libcamera::FrameBuffer *fb)
: fb_(fb)
BufferWriteSync::BufferWriteSync(RPiCamApp *app, libcamera::FrameBuffer *fb) : fb_(fb)
{
struct dma_buf_sync dma_sync {};
dma_sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW;
Expand Down
5 changes: 4 additions & 1 deletion core/dma_heaps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class DmaHeap
public:
DmaHeap();
~DmaHeap();
bool isValid() const { return dmaHeapHandle_.isValid(); }
bool isValid() const
{
return dmaHeapHandle_.isValid();
}
libcamera::UniqueFD alloc(const char *name, std::size_t size) const;

private:
Expand Down
2 changes: 2 additions & 0 deletions core/frame_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ struct FrameInfo

private:
// Info text tokens.
// clang-format off
inline static const std::string tokens[] = {
"%frame", "%fps", "%exp", "%ag", "%dg", "%rg", "%bg", "%focus",
"%aelock","%lp", "%temp", "%afstate"
};
// clang-format on
};
2 changes: 1 addition & 1 deletion core/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define LOG(level, text) \
do \
{ \
if (RPiCamApp::GetVerbosity() >= level) \
if (RPiCamApp::GetVerbosity() >= level) \
std::cerr << text << std::endl; \
} while (0)
#define LOG_ERROR(text) std::cerr << text << std::endl
10 changes: 8 additions & 2 deletions core/metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ class Metadata
// Note: use of (lowercase) lock and unlock means you can create scoped
// locks with the standard lock classes.
// e.g. std::lock_guard<RPiController::Metadata> lock(metadata)
void lock() { mutex_.lock(); }
void unlock() { mutex_.unlock(); }
void lock()
{
mutex_.lock();
}
void unlock()
{
mutex_.unlock();
}

private:
mutable std::mutex mutex_;
Expand Down
Loading
Loading