MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / detect_usb_cameras

Method detect_usb_cameras

OpenHD/ohd_video/src/camera_discovery.cpp:404–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402} // namespace openhd::v4l2
403
404std::vector<DCameras::DiscoveredUSBCamera> DCameras::detect_usb_cameras(
405 std::shared_ptr<spdlog::logger> &m_console, bool debug) {
406 const auto platform = OHDPlatform::instance();
407 if (platform.is_rpi_or_x86()) {
408 DThermalCamerasHelper::enableFlirIfFound();
409 DThermalCamerasHelper::enableSeekIfFound();
410 }
411 std::vector<DCameras::DiscoveredUSBCamera> ret;
412 const auto devices = openhd::v4l2::findV4l2VideoDevices();
413 if (debug) {
414 m_console->debug("Found {} v4l2 devices", devices.size());
415 for (auto &device : devices) m_console->debug("Device:{}", device);
416 }
417 for (const auto &device : devices) {
418 const auto v4l2_device_name = get_v4l2_device_name_string(device);
419 const auto probed_opt =
420 openhd::v4l2::probe_v4l2_device(platform, m_console, v4l2_device_name);
421 if (!probed_opt.has_value()) {
422 continue;
423 }
424 const auto &probed = probed_opt.value();
425 const std::string bus((char *)probed.caps.bus_info);
426 const std::string driver((char *)probed.caps.driver);
427 if (debug) {
428 m_console->debug("V4l2 info {} {} {}", device, bus,
429 probed.formats.formats_raw.size());
430 }
431 if (!probed.formats.formats_raw.empty()) {
432 // (RAW) format usb camera candidate
433 bool found = false;
434 for (auto &tmp : ret) {
435 if (tmp.bus == bus) {
436 found = true;
437 }
438 }
439 if (!found) {
440 ret.push_back(DCameras::DiscoveredUSBCamera{
441 .bus = bus, .v4l2_device_number = device});
442 } else {
443 }
444 }
445 }
446 if (debug) {
447 for (const auto &usb_cam : ret) {
448 m_console->debug("Found USB cam [{}]-[{}]", usb_cam.bus,
449 usb_cam.v4l2_device_number);
450 }
451 }
452 return ret;
453}
454
455#endif

Callers

nothing calls this directly

Calls 9

enableFlirIfFoundFunction · 0.85
enableSeekIfFoundFunction · 0.85
findV4l2VideoDevicesFunction · 0.85
probe_v4l2_deviceFunction · 0.85
is_rpi_or_x86Method · 0.80
debugMethod · 0.80
sizeMethod · 0.80
push_backMethod · 0.80

Tested by

no test coverage detected