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
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BraceWrapping:
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
AfterNamespace: false
AfterNamespace: true
AfterClass: true
BreakBeforeBinaryOperators: None
BreakBeforeInheritanceComma: false
Expand All @@ -46,7 +46,7 @@ BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
PackConstructorInitializers: NextLineOnly
PackConstructorInitializers: BinPack
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
Expand Down
30 changes: 10 additions & 20 deletions .github/workflows/libpisp-style-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,17 @@
name: libpisp style checker
on:
pull_request:
branches: [ main ]
branches: [main]

jobs:
style-check:

runs-on: [ ubuntu-latest ]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
clean: true

- name: Install ruff
run: pip install ruff

- name: Ruff check
run: ruff check utils/

- name: Ruff format
run: ruff format --check utils/

- name: Check style
run: ${{github.workspace}}/utils/checkstyle.py $(git log --format=%P -1 | awk '{print $1 ".." $2}')
- 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
build
build
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
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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++]
exclude: '(pisp_be_config\.h|pisp_common\.h|pisp_fe_config\.h|pisp_statistics\.h)$'

- 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]
2 changes: 1 addition & 1 deletion LICENSES/GPL-2.0-or-later.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GNU GENERAL PUBLIC LICENSE

Version 2, June 1991

Copyright (C) 1989, 1991 Free Software Foundation, Inc.
Copyright (C) 1989, 1991 Free Software Foundation, Inc.

51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

Expand Down
2 changes: 1 addition & 1 deletion LICENSES/Linux-syscall-note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ NOTE! This copyright does *not* cover user programs that use kernel services by

Also note that the only valid version of the GPL as far as the kernel is concerned is _this_ particular version of the license (ie v2, not v2.2 or v3.x or whatever), unless explicitly otherwise stated.

Linus Torvalds
Linus Torvalds
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,15 @@ To test the plugin without installing:
GST_PLUGIN_PATH=<build_dir>/src/gst gst-inspect-1.0 pispconvert
```

## 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
Copyright © 2023, Raspberry Pi Ltd. Released under the BSD-2-Clause License.
8 changes: 6 additions & 2 deletions src/examples/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void write_yuv422i(std::ofstream &out, std::array<uint8_t *, 3> &mem, unsigned i
write_plane(out, mem[0], width * 2, height, file_stride, buffer_stride);
}

// clang-format off
struct FormatFuncs
{
std::function<void(const std::array<uint8_t *, 3> &, std::ifstream &, unsigned int, unsigned int, unsigned int,
Expand All @@ -173,6 +174,7 @@ const std::map<std::string, FormatFuncs> Formats =
{ "YUYV", { read_yuv422i, write_yuv422i } },
{ "UYVY", { read_yuv422i, write_yuv422i } },
};
// clang-format on

struct Format
{
Expand Down Expand Up @@ -218,6 +220,7 @@ int main(int argc, char *argv[])

cxxopts::Options options(argv[0], "PiSP Image Converter");

// clang-format off
options.add_options()
("input", "Input file", cxxopts::value<std::string>())
("output", "Output file", cxxopts::value<std::string>())
Expand All @@ -229,6 +232,7 @@ int main(int argc, char *argv[])
("l,list", "Enumerate the media device nodes")
("h,help", "Print usage")
;
// clang-format on

options.parse_positional({ "input", "output" });
options.positional_help("<input file> <output file>");
Expand Down Expand Up @@ -376,8 +380,8 @@ int main(int argc, char *argv[])
exit(-1);
}

std::cerr << "Reading " << input_filename << " "
<< in_file.width << ":" << in_file.height << ":" << in_file.stride << ":" << in_file.format << std::endl;
std::cerr << "Reading " << input_filename << " " << in_file.width << ":" << in_file.height << ":" << in_file.stride
<< ":" << in_file.format << std::endl;

{
Buffer::Sync input(buffers.at("pispbe-input"), Buffer::Sync::Access::ReadWrite);
Expand Down
80 changes: 37 additions & 43 deletions src/gst/gstpispconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ GST_DEBUG_CATEGORY_STATIC(gst_pisp_convert_debug);
/* Supported GStreamer formats */
#define PISP_FORMATS "{ RGB, RGBx, BGRx, I420, YV12, Y42B, Y444, YUY2, UYVY, NV12, NV12_128C8, NV12_10LE32_128C8 }"
/* Supported DRM fourccs */
#define PISP_DRM_FORMATS "{ RG24, XB24, XR24, YU12, YV12, YU16, YU24, YUYV, UYVY, NV12, NV12:0x0700000000000004, P030:0x0700000000000004 }"
#define PISP_DRM_FORMATS \
"{ RG24, XB24, XR24, YU12, YV12, YU16, YU24, YUYV, UYVY, NV12, NV12:0x0700000000000004, P030:0x0700000000000004 }"

#define PISP_SRC_CAPS \
"video/x-raw(memory:DMABuf), format=(string)DMA_DRM, drm-format=(string)" PISP_DRM_FORMATS \
", width=(int)[1,32768], height=(int)[1,32768], framerate=(fraction)[0/1,2147483647/1]" \
";" \
GST_VIDEO_CAPS_MAKE_WITH_FEATURES(GST_CAPS_FEATURE_MEMORY_DMABUF, PISP_FORMATS) ";" \
GST_VIDEO_CAPS_MAKE(PISP_FORMATS)
#define PISP_SRC_CAPS \
"video/x-raw(memory:DMABuf), format=(string)DMA_DRM, drm-format=(string)" PISP_DRM_FORMATS \
", width=(int)[1,32768], height=(int)[1,32768], framerate=(fraction)[0/1,2147483647/1]" \
";" GST_VIDEO_CAPS_MAKE_WITH_FEATURES(GST_CAPS_FEATURE_MEMORY_DMABUF, \
PISP_FORMATS) ";" GST_VIDEO_CAPS_MAKE(PISP_FORMATS)

static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE(
"sink", GST_PAD_SINK, GST_PAD_ALWAYS,
Expand All @@ -53,13 +53,11 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE(
/* System memory */
GST_VIDEO_CAPS_MAKE(PISP_FORMATS)));

static GstStaticPadTemplate src0_template = GST_STATIC_PAD_TEMPLATE(
"src0", GST_PAD_SRC, GST_PAD_ALWAYS,
GST_STATIC_CAPS(PISP_SRC_CAPS));
static GstStaticPadTemplate src0_template =
GST_STATIC_PAD_TEMPLATE("src0", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS(PISP_SRC_CAPS));

static GstStaticPadTemplate src1_template = GST_STATIC_PAD_TEMPLATE(
"src1", GST_PAD_SRC, GST_PAD_ALWAYS,
GST_STATIC_CAPS(PISP_SRC_CAPS));
static GstStaticPadTemplate src1_template =
GST_STATIC_PAD_TEMPLATE("src1", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS(PISP_SRC_CAPS));

#define gst_pisp_convert_parent_class parent_class
G_DEFINE_TYPE(GstPispConvert, gst_pisp_convert, GST_TYPE_ELEMENT);
Expand Down Expand Up @@ -154,9 +152,9 @@ static const char *colorimetry_to_pisp(const GstVideoColorimetry *colorimetry)
}

/* Configure colour space conversion blocks for the backend */
static uint32_t configure_colour_conversion(libpisp::BackEnd *backend, const char *in_format,
const char *in_colorspace, const char *out_format,
const char *out_colorspace, unsigned int output_index)
static uint32_t configure_colour_conversion(libpisp::BackEnd *backend, const char *in_format, const char *in_colorspace,
const char *out_format, const char *out_colorspace,
unsigned int output_index)
{
uint32_t rgb_enables = 0;

Expand All @@ -177,8 +175,7 @@ static uint32_t configure_colour_conversion(libpisp::BackEnd *backend, const cha
backend->SetCsc(output_index, csc);
rgb_enables |= PISP_BE_RGB_ENABLE_CSC(output_index);
}
else if (g_str_equal(out_format, "RGB888") ||
g_str_equal(out_format, "RGBX8888") ||
else if (g_str_equal(out_format, "RGB888") || g_str_equal(out_format, "RGBX8888") ||
g_str_equal(out_format, "XRGB8888"))
{
/* R/B channel swap to match GStreamer/DRM byte ordering */
Expand Down Expand Up @@ -252,21 +249,18 @@ static void gst_pisp_convert_class_init(GstPispConvertClass *klass)
gobject_class, PROP_CROP,
g_param_spec_string("crop", "Crop region for all outputs",
"Crop region as 'x,y,width,height' applied to all outputs (0,0,0,0 = full input)",
"0,0,0,0",
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
"0,0,0,0", static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

g_object_class_install_property(
gobject_class, PROP_CROP0,
g_param_spec_string("crop0", "Crop region for output 0",
"Crop region as 'x,y,width,height' (0,0,0,0 = no crop / full input)",
"0,0,0,0",
"Crop region as 'x,y,width,height' (0,0,0,0 = no crop / full input)", "0,0,0,0",
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

g_object_class_install_property(
gobject_class, PROP_CROP1,
g_param_spec_string("crop1", "Crop region for output 1",
"Crop region as 'x,y,width,height' (0,0,0,0 = no crop / full input)",
"0,0,0,0",
"Crop region as 'x,y,width,height' (0,0,0,0 = no crop / full input)", "0,0,0,0",
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));

element_class->change_state = GST_DEBUG_FUNCPTR(gst_pisp_convert_change_state);
Expand Down Expand Up @@ -533,8 +527,8 @@ static gboolean parse_input_caps(GstPispConvert *self, GstCaps *caps)
self->priv->in_colorspace = colorimetry_to_pisp(&colorimetry);

GST_INFO_OBJECT(self, "Input DMA-DRM format: drm-format=%s, pisp=%s, colorspace=%s (matrix=%d, range=%d)",
drm_format, self->priv->in_format, self->priv->in_colorspace,
colorimetry.matrix, colorimetry.range);
drm_format, self->priv->in_format, self->priv->in_colorspace, colorimetry.matrix,
colorimetry.range);
}
else
{
Expand All @@ -548,9 +542,9 @@ static gboolean parse_input_caps(GstPispConvert *self, GstCaps *caps)
self->priv->in_stride = GST_VIDEO_INFO_PLANE_STRIDE(&in_info, 0);
self->priv->in_format = gst_format_to_pisp(GST_VIDEO_INFO_FORMAT(&in_info));
self->priv->in_colorspace = colorimetry_to_pisp(&GST_VIDEO_INFO_COLORIMETRY(&in_info));
GST_INFO_OBJECT(self, "Input format: pisp=%s, colorspace=%s (matrix=%d, range=%d)",
self->priv->in_format, self->priv->in_colorspace,
GST_VIDEO_INFO_COLORIMETRY(&in_info).matrix, GST_VIDEO_INFO_COLORIMETRY(&in_info).range);
GST_INFO_OBJECT(self, "Input format: pisp=%s, colorspace=%s (matrix=%d, range=%d)", self->priv->in_format,
self->priv->in_colorspace, GST_VIDEO_INFO_COLORIMETRY(&in_info).matrix,
GST_VIDEO_INFO_COLORIMETRY(&in_info).range);
}

if (!self->priv->in_colorspace)
Expand Down Expand Up @@ -661,14 +655,13 @@ static void add_video_meta(GstBuffer *buffer, const char *pisp_format, guint wid
for (guint p = 0; p < n_planes; p++)
{
offsets[p] = offset;
strides[p] = hw_stride * GST_VIDEO_INFO_PLANE_STRIDE(&vinfo, p) /
GST_VIDEO_INFO_PLANE_STRIDE(&vinfo, 0);
mem = gst_buffer_peek_memory (buffer, p);
strides[p] = hw_stride * GST_VIDEO_INFO_PLANE_STRIDE(&vinfo, p) / GST_VIDEO_INFO_PLANE_STRIDE(&vinfo, 0);
mem = gst_buffer_peek_memory(buffer, p);
offset += mem->size;
}

gst_buffer_add_video_meta_full(buffer, GST_VIDEO_FRAME_FLAG_NONE, gst_fmt,
width, height, n_planes, offsets, strides);
gst_buffer_add_video_meta_full(buffer, GST_VIDEO_FRAME_FLAG_NONE, gst_fmt, width, height, n_planes, offsets,
strides);
}

static void copy_planes(std::array<uint8_t *, 3> src, guint src_stride, std::array<uint8_t *, 3> dst, guint dst_stride,
Expand Down Expand Up @@ -887,19 +880,20 @@ static gboolean gst_pisp_convert_configure(GstPispConvert *self)
self->priv->backend->SetOutputFormat(i, output_cfg[i]);

if ((g_str_equal(self->priv->out_format[i], "RGBX8888") ||
g_str_equal(self->priv->out_format[i], "XRGB8888")) && !self->priv->variant->BackendRGB32Supported(0))
g_str_equal(self->priv->out_format[i], "XRGB8888")) &&
!self->priv->variant->BackendRGB32Supported(0))
GST_WARNING_OBJECT(self, "pisp_be HW does not support 32-bit RGB output, the image will be corrupt.");

if (!self->priv->out_colorspace[i])
self->priv->out_colorspace[i] = self->priv->in_colorspace;

global.rgb_enables |= configure_colour_conversion(self->priv->backend.get(),
self->priv->in_format, self->priv->in_colorspace,
self->priv->out_format[i], self->priv->out_colorspace[i], i);
global.rgb_enables |= configure_colour_conversion(self->priv->backend.get(), self->priv->in_format,
self->priv->in_colorspace, self->priv->out_format[i],
self->priv->out_colorspace[i], i);

GST_INFO_OBJECT(self, "Output%d: %ux%u %s (stride: gst=%u hw=%u) colorspace %s", i, self->priv->out_width[i],
self->priv->out_height[i], self->priv->out_format[i], self->priv->out_stride[i],
self->priv->out_hw_stride[i], self->priv->out_colorspace[i]);
GST_INFO_OBJECT(self, "Output%d: %ux%u %s (stride: gst=%u hw=%u) colorspace %s", i,
self->priv->out_width[i], self->priv->out_height[i], self->priv->out_format[i],
self->priv->out_stride[i], self->priv->out_hw_stride[i], self->priv->out_colorspace[i]);
}

self->priv->backend->SetGlobal(global);
Expand Down Expand Up @@ -1141,8 +1135,8 @@ static GstFlowReturn gst_pisp_convert_chain(GstPad *pad [[maybe_unused]], GstObj
goto cleanup;
}

add_video_meta(outbuf[i], self->priv->out_format[i], self->priv->out_width[i],
self->priv->out_height[i], self->priv->out_hw_stride[i]);
add_video_meta(outbuf[i], self->priv->out_format[i], self->priv->out_width[i], self->priv->out_height[i],
self->priv->out_hw_stride[i]);

GST_DEBUG_OBJECT(self, "Using zero-copy output%d path", i);
}
Expand Down
1 change: 0 additions & 1 deletion src/gst/gstpispconvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,3 @@ GType gst_pisp_convert_get_type(void);
GST_ELEMENT_REGISTER_DECLARE(pispconvert);

G_END_DECLS

3 changes: 1 addition & 2 deletions src/helpers/backend_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const Buffer &AsBuffer(const Buffer &b)

} // namespace

BackendDevice::BackendDevice(const std::string &device)
: valid_(true)
BackendDevice::BackendDevice(const std::string &device) : valid_(true)
{
nodes_ = MediaDevice().OpenV4l2Nodes(device);
if (nodes_.empty())
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/backend_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ class BackendDevice
std::unordered_set<std::string> nodes_enabled_;
};

} // namespace libpisp
} // namespace libpisp::helpers
Loading
Loading