Fix libcamera compilation

This commit is contained in:
Kamil Trzcinski
2022-04-10 22:28:01 +02:00
parent 2e36ac9aed
commit abb94b1e29
9 changed files with 59 additions and 20 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ tmp/
*.o *.o
*.d *.d
html/*.c html/*.c
/test_*

17
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/libcamera"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-arm64"
}
],
"version": 4
}

View File

@ -20,7 +20,7 @@ endif
ifeq (1,$(USE_LIBCAMERA)) ifeq (1,$(USE_LIBCAMERA))
CFLAGS += -DUSE_LIBCAMERA $(shell pkg-config --cflags libcamera) CFLAGS += -DUSE_LIBCAMERA $(shell pkg-config --cflags libcamera)
LDLIBS += $(shell pkg-config --cflags libs) LDLIBS += $(shell pkg-config --libs libcamera)
endif endif
HTML_SRC = $(addsuffix .c,$(HTML)) HTML_SRC = $(addsuffix .c,$(HTML))

25
cmd/test_libcamera.c Normal file
View File

@ -0,0 +1,25 @@
#include "opts/opts.h"
#include "opts/log.h"
#include "opts/fourcc.h"
#include "device/camera/camera.h"
log_options_t log_options = {
.debug = false,
.verbose = false
};
int main(int argc, char *argv[])
{
device_t *dev = NULL;
dev = device_libcamera_open("CAMERA", "/dev/video0");
if (!dev) {
printf("Failed to open libcamera\n");
return -1;
}
printf("Opened libcamera\n");
device_close(dev);
return 0;
}

View File

@ -1,10 +1,5 @@
#include "libcamera.hh" #include "libcamera.hh"
extern "C" {
#include "device/buffer.h"
#include <stdlib.h>
};
int libcamera_buffer_open(buffer_t *buf) int libcamera_buffer_open(buffer_t *buf)
{ {
buf->libcamera = new buffer_libcamera_t{}; buf->libcamera = new buffer_libcamera_t{};

View File

@ -1,10 +1,5 @@
#include "libcamera.hh" #include "libcamera.hh"
extern "C" {
#include "device/buffer_list.h"
#include <stdlib.h>
};
int libcamera_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned height, unsigned format, unsigned bytesperline) int libcamera_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned height, unsigned format, unsigned bytesperline)
{ {
buf_list->libcamera = new buffer_list_libcamera_t{}; buf_list->libcamera = new buffer_list_libcamera_t{};

View File

@ -1,13 +1,15 @@
#include "libcamera.hh" #include "libcamera.hh"
extern "C" {
#include "device/device.h"
#include <stdlib.h>
};
int libcamera_device_open(device_t *dev) int libcamera_device_open(device_t *dev)
{ {
dev->libcamera = new device_libcamera_t{}; dev->libcamera = new device_libcamera_t{};
auto camera_manager = std::make_unique<libcamera::CameraManager>();
int ret = camera_manager->start();
if (ret < 0) {
return -1;
}
return 0; return 0;
} }

View File

@ -1,9 +1,5 @@
#include "libcamera.hh" #include "libcamera.hh"
extern "C" {
#include "device/device.h"
};
device_hw_t libcamera_device_hw = { device_hw_t libcamera_device_hw = {
.device_open = libcamera_device_open, .device_open = libcamera_device_open,
.device_close = libcamera_device_close, .device_close = libcamera_device_close,

View File

@ -5,8 +5,16 @@ extern "C" {
#include <linux/v4l2-subdev.h> #include <linux/v4l2-subdev.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include "device/device.h"
#include "device/buffer_list.h"
#include "device/buffer.h"
}; };
#include <optional>
#include <memory>
#include <libcamera/controls.h> #include <libcamera/controls.h>
#include <libcamera/control_ids.h> #include <libcamera/control_ids.h>
#include <libcamera/property_ids.h> #include <libcamera/property_ids.h>