|
4 | 4 | #include <unistd.h> |
5 | 5 | #include <cstring> |
6 | 6 | #include <cerrno> |
| 7 | +#include <dirent.h> |
| 8 | +#include <sys/ioctl.h> |
| 9 | +#include <linux/media.h> |
| 10 | +#include <linux/videodev2.h> |
7 | 11 |
|
8 | 12 | #include <libcamera/libcamera.h> |
9 | 13 |
|
10 | 14 | using namespace libcamera; |
11 | 15 |
|
| 16 | +void listDirectory(const char* path) { |
| 17 | + DIR* dir = opendir(path); |
| 18 | + if (!dir) { |
| 19 | + std::cout << " Cannot open " << path << ": " << strerror(errno) << std::endl; |
| 20 | + return; |
| 21 | + } |
| 22 | + |
| 23 | + struct dirent* entry; |
| 24 | + while ((entry = readdir(dir)) != nullptr) { |
| 25 | + if (entry->d_name[0] != '.') { |
| 26 | + std::cout << " " << entry->d_name << std::endl; |
| 27 | + } |
| 28 | + } |
| 29 | + closedir(dir); |
| 30 | +} |
| 31 | + |
| 32 | +void testMediaDevice(const char* dev) { |
| 33 | + int fd = open(dev, O_RDWR); |
| 34 | + if (fd < 0) { |
| 35 | + std::cout << "[FAIL] Cannot open " << dev << ": " << strerror(errno) << std::endl; |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + struct media_device_info info; |
| 40 | + memset(&info, 0, sizeof(info)); |
| 41 | + |
| 42 | + if (ioctl(fd, MEDIA_IOC_DEVICE_INFO, &info) < 0) { |
| 43 | + std::cout << "[FAIL] Cannot get device info for " << dev << ": " << strerror(errno) << std::endl; |
| 44 | + close(fd); |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + std::cout << "[OK] " << dev << ": " << info.driver << " - " << info.model << std::endl; |
| 49 | + |
| 50 | + // Enumerate entities |
| 51 | + struct media_entity_desc entity; |
| 52 | + memset(&entity, 0, sizeof(entity)); |
| 53 | + entity.id = MEDIA_ENT_ID_FLAG_NEXT; |
| 54 | + |
| 55 | + std::cout << " Entities:" << std::endl; |
| 56 | + while (ioctl(fd, MEDIA_IOC_ENUM_ENTITIES, &entity) == 0) { |
| 57 | + std::cout << " [" << entity.id << "] " << entity.name << " (type: " << entity.type << ")" << std::endl; |
| 58 | + entity.id |= MEDIA_ENT_ID_FLAG_NEXT; |
| 59 | + } |
| 60 | + |
| 61 | + close(fd); |
| 62 | +} |
| 63 | + |
| 64 | +void testV4L2Device(const char* dev) { |
| 65 | + int fd = open(dev, O_RDWR); |
| 66 | + if (fd < 0) { |
| 67 | + std::cout << "[FAIL] Cannot open " << dev << ": " << strerror(errno) << std::endl; |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + struct v4l2_capability cap; |
| 72 | + memset(&cap, 0, sizeof(cap)); |
| 73 | + |
| 74 | + if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) { |
| 75 | + std::cout << "[FAIL] Cannot query " << dev << ": " << strerror(errno) << std::endl; |
| 76 | + close(fd); |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + std::cout << "[OK] " << dev << ": " << cap.card << " (" << cap.driver << ")" << std::endl; |
| 81 | + |
| 82 | + close(fd); |
| 83 | +} |
| 84 | + |
12 | 85 | int main() |
13 | 86 | { |
14 | 87 | std::cout << "=== libcamera Test ===" << std::endl; |
@@ -51,6 +124,38 @@ int main() |
51 | 124 | } |
52 | 125 | } |
53 | 126 |
|
| 127 | + // Check IPA files |
| 128 | + std::cout << "\n--- IPA Module Path ---" << std::endl; |
| 129 | + const char* ipaModulePath = getenv("LIBCAMERA_IPA_MODULE_PATH"); |
| 130 | + if (ipaModulePath) { |
| 131 | + listDirectory(ipaModulePath); |
| 132 | + std::string ipaSubdir = std::string(ipaModulePath) + "/ipa"; |
| 133 | + std::cout << " Subdir " << ipaSubdir << ":" << std::endl; |
| 134 | + listDirectory(ipaSubdir.c_str()); |
| 135 | + } |
| 136 | + |
| 137 | + std::cout << "\n--- IPA Config Path ---" << std::endl; |
| 138 | + const char* ipaConfigPath = getenv("LIBCAMERA_IPA_CONFIG_PATH"); |
| 139 | + if (ipaConfigPath) { |
| 140 | + listDirectory(ipaConfigPath); |
| 141 | + std::string rpiPath = std::string(ipaConfigPath) + "/rpi"; |
| 142 | + std::cout << " Subdir " << rpiPath << ":" << std::endl; |
| 143 | + listDirectory(rpiPath.c_str()); |
| 144 | + std::string pispPath = rpiPath + "/pisp"; |
| 145 | + std::cout << " Subdir " << pispPath << ":" << std::endl; |
| 146 | + listDirectory(pispPath.c_str()); |
| 147 | + } |
| 148 | + |
| 149 | + // Test media devices with ioctls |
| 150 | + std::cout << "\n--- Media Device Details ---" << std::endl; |
| 151 | + testMediaDevice("/dev/media0"); |
| 152 | + testMediaDevice("/dev/media1"); |
| 153 | + |
| 154 | + // Test V4L2 devices |
| 155 | + std::cout << "\n--- V4L2 Device Details ---" << std::endl; |
| 156 | + testV4L2Device("/dev/video0"); |
| 157 | + testV4L2Device("/dev/video1"); |
| 158 | + |
54 | 159 | // Initialize CameraManager |
55 | 160 | std::cout << "\n--- Initializing CameraManager ---" << std::endl; |
56 | 161 |
|
|
0 commit comments