Skip to content

Commit

Permalink
Merge branch 'master' into docker-sysroot
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 authored Dec 18, 2023
2 parents c84c6f8 + 2efcd61 commit 1457f15
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
bind_mount_repository: true
commands: |
apt-get update
apt-get install -y libopencv-dev libegl1-mesa-dev libcamera-dev cmake build-essential libdrm-dev libgbm-dev openjdk-17-jdk
apt-get install -y libopencv-dev libegl1-mesa-dev libcamera-dev cmake build-essential libdrm-dev libgbm-dev default-jdk openjdk-17-jdk
cmake -B build-pi -DCMAKE_BUILD_TYPE=Release
cmake --build build-pi -- -j
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.15)

project(libcamera_meme)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down
5 changes: 2 additions & 3 deletions camera_grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ CameraGrabber::CameraGrabber(std::shared_ptr<libcamera::Camera> camera,

printf("Rotation = %i\n", rotation);
if (rotation == 180) {
using namespace libcamera;
config->transform = Transform::HFlip * Transform::VFlip * libcamera::Transform::Identity;
config->orientation = libcamera::Orientation::Rotate180;
} else {
config->transform = libcamera::Transform::Identity;
config->orientation = libcamera::Orientation::Rotate0;
}

if (config->validate() == libcamera::CameraConfiguration::Invalid) {
Expand Down
1 change: 1 addition & 0 deletions camera_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CameraModel stringToModel(const std::string& model) {
const char* famname = model.c_str();
if (!strcmp(famname, "ov5647")) return OV5647;
else if (!strcmp(famname, "imx219")) return IMX219;
else if (!strcmp(famname, "imx708")) return IMX708;
else if (!strcmp(famname, "imx477")) return IMX477;
else if (!strcmp(famname, "ov9281")) return OV9281;
else if (!strcmp(famname, "ov7251")) return OV7251;
Expand Down
1 change: 1 addition & 0 deletions camera_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum CameraModel {
Disconnected = 0,
OV5647, // Picam v1
IMX219, // Picam v2
IMX708, // Picam v3
IMX477, // Picam HQ
OV9281,
OV7251,
Expand Down
26 changes: 20 additions & 6 deletions camera_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ using latch = Latch;
#include <libcamera/property_ids.h>
#include <libcamera/control_ids.h>

#include <sys/ioctl.h>
#include <linux/dma-buf.h>

using namespace std::chrono;
using namespace std::chrono_literals;

Expand Down Expand Up @@ -84,11 +87,6 @@ void CameraRunner::start() {
.at(grabber.streamConfiguration().stream())
->planes();

for (int i = 0; i < 3; i++) {
// std::cout << "Plane " << (i + 1) << " has fd " << planes[i].fd.get() << " with offset " << planes[i].offset << std::endl;
// std::cout << "Plane " << (i + 1) << " has fd " << planes[i].fd.get() << " with offset " << planes[i].offset << " and pitch " << static_cast<EGLint>(stride / 2) << std::endl;
}

std::array<GlHsvThresholder::DmaBufPlaneData, 3> yuv_data{{
{planes[0].fd.get(), static_cast<EGLint>(planes[0].offset),
static_cast<EGLint>(stride)},
Expand All @@ -107,7 +105,6 @@ void CameraRunner::start() {
rangeFromColorspace(colorspace),
type);


if (out != 0) {
/*
From libcamera docs:
Expand Down Expand Up @@ -177,6 +174,15 @@ void CameraRunner::start() {
auto input_ptr = mmaped.at(data.fd);
int bound = m_width * m_height;


{
struct dma_buf_sync dma_sync {};
dma_sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW;
int ret = ::ioctl(data.fd, DMA_BUF_IOCTL_SYNC, &dma_sync);
if (ret)
throw std::runtime_error("failed to start DMA buf sync");
}

if (m_copyInput) {
for (int i = 0; i < bound; i++) {
std::memcpy(color_out_buf + i * 3, input_ptr + i * 4, 3);
Expand All @@ -188,6 +194,14 @@ void CameraRunner::start() {
processed_out_buf[i] = input_ptr[i * 4 + 3];
}
}

{
struct dma_buf_sync dma_sync {};
dma_sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW;
int ret = ::ioctl(data.fd, DMA_BUF_IOCTL_SYNC, &dma_sync);
if (ret)
throw std::runtime_error("failed to start DMA buf sync");
}

m_thresholder.returnBuffer(data.fd);
outgoing.set(std::move(mat_pair));
Expand Down
2 changes: 1 addition & 1 deletion libcamera_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Java_org_photonvision_raspi_LibCameraJNI_createCamera(JNIEnv *env, jclass,
JNIEXPORT jint Java_org_photonvision_raspi_LibCameraJNI_getSensorModelRaw(
JNIEnv *env, jclass clazz) {

bool runner_exists = runner > 0;
bool runner_exists = runner != 0;
if (!runner_exists) {
Java_org_photonvision_raspi_LibCameraJNI_createCamera(env, clazz,
320, 240, 30);
Expand Down

0 comments on commit 1457f15

Please sign in to comment.