Skip to content

Commit faecc8e

Browse files
committed
Implement linux version to get devices
1 parent bd2f39a commit faecc8e

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

openvino_bindings/src/bindings.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,6 @@ StatusOrInputDevices* getAvailableCameraDevices() {
514514
return new StatusOrInputDevices{OkStatus, "", devices, (int)cameras.size()};
515515
}
516516

517-
StatusOrString* pdfExtractText(const char* pdf_path) {
518-
try {
519-
auto output = sentence_extractor::extract_text_from_pdf(pdf_path);
520-
return new StatusOrString{OkStatus, "", strdup(output.c_str())};
521-
} catch (...) {
522-
auto except = handle_exceptions();
523-
return new StatusOrString{except->status, except->message};
524-
}
525-
}
526-
527517
Status* handle_exceptions() {
528518
try {
529519
throw;

openvino_bindings/src/utils/BUILD

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ cc_library(
2323
deps = [
2424
":errors",
2525
],
26-
linkopts = [
27-
"mfplat.lib",
28-
"mf.lib",
29-
"mfuuid.lib",
30-
"ole32.lib",
31-
],
26+
linkopts = select({
27+
"@platforms//os:windows": ["mfplat.lib", "mf.lib", "mfuuid.lib", "ole32.lib"],
28+
"@platforms//os:linux": [], # No extra libraries needed for V4L2
29+
"@platforms//os:macos": ["-framework AVFoundation", "-framework Foundation"],
30+
}),
3231
)
3332

3433
cc_library(

openvino_bindings/src/utils/input_devices.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,29 @@ std::map<size_t, std::string> list_camera_devices() {
7474
return {};
7575
}
7676
#elif __linux__
77+
#include <sys/ioctl.h>
78+
#include <fcntl.h>
79+
#include <unistd.h>
80+
#include <linux/videodev2.h>
81+
7782
std::map<size_t, std::string> list_camera_devices() {
78-
return {};
83+
std::map<size_t, std::string> cameras = {};
84+
85+
for (int i = 0; i < 10; ++i) { // Check up to 10 devices
86+
std::string devName = "/dev/video" + std::to_string(i);
87+
std::cout << devName << std::endl;
88+
int fd = open(devName.c_str(), O_RDONLY);
89+
if (fd == -1) continue; // Skip if device doesn't exist
90+
91+
struct v4l2_capability cap;
92+
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) {
93+
if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
94+
cameras.insert({i, std::string(reinterpret_cast<char*>(cap.card))});
95+
}
96+
}
97+
close(fd);
98+
}
99+
return cameras;
79100
}
80101
#else
81102
std::map<size_t, std::string> list_camera_devices() {

0 commit comments

Comments
 (0)