Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi camera support to backend #9

Merged
merged 13 commits into from
Dec 28, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
build
.cache/
compile_commands.json
photon_sysroot*
build-pi/*
33 changes: 33 additions & 0 deletions .styleguide
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cppHeaderFileInclude {
\.h$
\.hpp$
\.inc$
\.inl$
}

cppSrcFileInclude {
\.cpp$
}

modifiableFileExclude {
\.jpg$
\.jpeg$
\.png$
\.gif$
\.so$
\.dll$
\.webp$
\.ico$
gradlew
}

includeProject {
^photonLib/
}

includeOtherLibs {
^frc/
^networktables/
^units/
^wpi/
}
16 changes: 16 additions & 0 deletions .styleguide-license
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
40 changes: 40 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "LibCameraJNI",
"request": "launch",
"mainClass": "org.photonvision.raspi.LibCameraJNI",
"projectName": "photon-libcamera-gl-driver_ef1a9c31"
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/libcamera_meme",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "Build libcamera_meme"
}
]
}
22 changes: 22 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"tasks": [
{
"label": "Build libcamera_meme",
"type": "shell",
"command": "cmake",
"args": [
"--build",
"build",
"--target",
"libcamera_meme"
],
"options": {
"cwd": "${workspaceFolder}/"
},
"group": {
"kind": "build",
"isDefault": true
}
},
]
}
27 changes: 15 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.25.1)
cmake_minimum_required(VERSION 3.18)
project(libcamera_meme)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand All @@ -25,23 +25,26 @@ endif ()
SET(FAST_FLAGS "-Ofast -ftree-vectorize -fPIC")
add_definitions(${FAST_FLAGS})

add_library(photonlibcamera SHARED concurrent_blocking_queue.h
camera_grabber.cpp dma_buf_alloc.cpp
gl_hsv_thresholder.cpp
libcamera_opengl_utility.cpp
libcamera_jni.cpp
camera_manager.cpp
camera_runner.cpp
camera_model.cpp
headless_opengl.cpp

add_library(photonlibcamera SHARED
src/camera_grabber.cpp
src/dma_buf_alloc.cpp
src/gl_hsv_thresholder.cpp
src/libcamera_opengl_utility.cpp
src/camera_manager.cpp
src/camera_runner.cpp
src/camera_model.cpp
src/headless_opengl.cpp
src/libcamera_jni.cpp
)
target_compile_definitions(photonlibcamera PUBLIC EGL_NO_X11=1)
target_include_directories(photonlibcamera PUBLIC ${OPENGL_INCLUDE_DIRS} ${LIBDRM_INCLUDE_DIRS} ${LIBCAMERA_INCLUDE_DIRS}
target_include_directories(photonlibcamera PUBLIC include ${OPENGL_INCLUDE_DIRS} ${LIBDRM_INCLUDE_DIRS} ${LIBCAMERA_INCLUDE_DIRS}
${LIBGBM_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${JNI_INCLUDE_DIRS})
target_link_libraries(photonlibcamera PUBLIC OpenGL::GL OpenGL::EGL Threads::Threads ${LIBCAMERA_LINK_LIBRARIES}
${LIBGBM_LINK_LIBRARIES} ${OpenCV_LIBS} ${LIBDRM_LINK_LIBRARIES})
target_compile_options(photonlibcamera PRIVATE -Wall -Wextra -Wpedantic -Werror)

add_executable(libcamera_meme main.cpp)
target_include_directories(libcamera_meme PUBLIC ${OPENGL_INCLUDE_DIRS} ${LIBDRM_INCLUDE_DIRS} ${LIBCAMERA_INCLUDE_DIRS}
${LIBGBM_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${JNI_INCLUDE_DIRS})
target_link_libraries(libcamera_meme photonlibcamera)
target_link_libraries(libcamera_meme photonlibcamera)
31 changes: 0 additions & 31 deletions blocking_future.h

This file was deleted.

12 changes: 0 additions & 12 deletions camera_manager.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions camera_manager.h

This file was deleted.

15 changes: 0 additions & 15 deletions camera_model.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions camera_model.h

This file was deleted.

17 changes: 0 additions & 17 deletions dma_buf_alloc.h

This file was deleted.

34 changes: 0 additions & 34 deletions glerror.h

This file was deleted.

22 changes: 0 additions & 22 deletions headless_opengl.h

This file was deleted.

49 changes: 49 additions & 0 deletions include/blocking_future.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <condition_variable>
#include <mutex>
#include <optional>
#include <utility>

template <typename T> class BlockingFuture {
public:
BlockingFuture() = default;

void set(T &&item) {
std::unique_lock<std::mutex> lock(m_mutex);
m_data = std::make_optional<>(std::forward<T>(item));
lock.unlock();
m_cond.notify_one();
}

T take() {
std::unique_lock<std::mutex> lock(m_mutex);
m_cond.wait(lock, [&] { return m_data.has_value(); });

auto item = std::move(m_data.value());
m_data.reset();
return item;
}

private:
std::optional<T> m_data;
std::mutex m_mutex;
std::condition_variable m_cond;
};
Loading