Skip to content

Commit 69cded4

Browse files
committed
added a test for libcamera
1 parent fe34b53 commit 69cded4

3 files changed

Lines changed: 144 additions & 0 deletions

File tree

Makefile.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CXX = g++
2+
CXXFLAGS = -std=c++17 -Wall -Wextra $(shell pkg-config --cflags libcamera)
3+
LDFLAGS = $(shell pkg-config --libs libcamera)
4+
5+
test_libcamera: test_libcamera.cpp
6+
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS)
7+
8+
clean:
9+
rm -f test_libcamera
10+
11+
.PHONY: clean

io.github.saeugetier.photobooth.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,19 @@
320320
"path": "."
321321
}
322322
]
323+
},
324+
{
325+
"name": "test-libcamera",
326+
"buildsystem": "simple",
327+
"build-commands": [
328+
"g++ -std=c++17 -Wall -o ${FLATPAK_DEST}/bin/test_libcamera test_libcamera.cpp $(pkg-config --cflags --libs libcamera)"
329+
],
330+
"sources": [
331+
{
332+
"type": "file",
333+
"path": "test_libcamera.cpp"
334+
}
335+
]
323336
}
324337
]
325338
}

test_libcamera.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include <iostream>
2+
#include <memory>
3+
#include <fcntl.h>
4+
#include <unistd.h>
5+
#include <cstring>
6+
#include <cerrno>
7+
8+
#include <libcamera/libcamera.h>
9+
10+
using namespace libcamera;
11+
12+
int main()
13+
{
14+
std::cout << "=== libcamera Test ===" << std::endl;
15+
16+
// Test device access first
17+
std::cout << "\n--- Testing Device Access ---" << std::endl;
18+
19+
const char* devices[] = {
20+
"/dev/media0",
21+
"/dev/media1",
22+
"/dev/video0",
23+
"/dev/v4l-subdev0"
24+
};
25+
26+
for (const char* dev : devices) {
27+
int fd = open(dev, O_RDWR);
28+
if (fd >= 0) {
29+
std::cout << "[OK] Can open " << dev << std::endl;
30+
close(fd);
31+
} else {
32+
std::cout << "[FAIL] Cannot open " << dev << ": " << strerror(errno) << std::endl;
33+
}
34+
}
35+
36+
// Check environment variables
37+
std::cout << "\n--- Environment Variables ---" << std::endl;
38+
39+
const char* envVars[] = {
40+
"LIBCAMERA_LOG_LEVELS",
41+
"LIBCAMERA_IPA_MODULE_PATH",
42+
"LIBCAMERA_IPA_CONFIG_PATH"
43+
};
44+
45+
for (const char* env : envVars) {
46+
const char* value = getenv(env);
47+
if (value) {
48+
std::cout << env << "=" << value << std::endl;
49+
} else {
50+
std::cout << env << " (not set)" << std::endl;
51+
}
52+
}
53+
54+
// Initialize CameraManager
55+
std::cout << "\n--- Initializing CameraManager ---" << std::endl;
56+
57+
std::unique_ptr<CameraManager> cm = std::make_unique<CameraManager>();
58+
59+
int ret = cm->start();
60+
if (ret) {
61+
std::cerr << "[ERROR] CameraManager start failed: " << ret << std::endl;
62+
return 1;
63+
}
64+
65+
std::cout << "[OK] CameraManager started successfully" << std::endl;
66+
std::cout << "libcamera version: " << cm->version() << std::endl;
67+
68+
// List cameras
69+
std::cout << "\n--- Available Cameras ---" << std::endl;
70+
71+
auto cameras = cm->cameras();
72+
std::cout << "Number of cameras found: " << cameras.size() << std::endl;
73+
74+
if (cameras.empty()) {
75+
std::cout << "[WARNING] No cameras detected!" << std::endl;
76+
} else {
77+
for (const auto& camera : cameras) {
78+
std::cout << "\nCamera: " << camera->id() << std::endl;
79+
80+
// Get camera properties
81+
const ControlList& props = camera->properties();
82+
83+
// Try to get model name
84+
const auto& modelIt = props.get(properties::Model);
85+
if (modelIt) {
86+
std::cout << " Model: " << *modelIt << std::endl;
87+
}
88+
89+
// Try to get location
90+
const auto& locationIt = props.get(properties::Location);
91+
if (locationIt) {
92+
std::string location;
93+
switch (*locationIt) {
94+
case properties::CameraLocationFront:
95+
location = "Front";
96+
break;
97+
case properties::CameraLocationBack:
98+
location = "Back";
99+
break;
100+
case properties::CameraLocationExternal:
101+
location = "External";
102+
break;
103+
default:
104+
location = "Unknown";
105+
}
106+
std::cout << " Location: " << location << std::endl;
107+
}
108+
109+
// List supported stream roles
110+
std::cout << " Supported roles: Viewfinder, StillCapture, VideoRecording, Raw" << std::endl;
111+
}
112+
}
113+
114+
// Cleanup
115+
std::cout << "\n--- Cleanup ---" << std::endl;
116+
cm->stop();
117+
std::cout << "[OK] CameraManager stopped" << std::endl;
118+
119+
return cameras.empty() ? 1 : 0;
120+
}

0 commit comments

Comments
 (0)