Skip to content

Commit

Permalink
core: Better handling of missing camera dev nodes
Browse files Browse the repository at this point in the history
Preserve the historical behaviour where if a camera dev node is missing,
we report it as "no camera available" instead of an unknown platform.

Signed-off-by: Naushir Patuck <[email protected]>
  • Loading branch information
naushir committed Oct 9, 2023
1 parent c0617eb commit 4fed529
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/libcamera_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ enum class Platform

Platform get_platform()
{
bool unknown = false;
for (unsigned int device_num = 0; device_num < 5; device_num++)
{
char device_name[16];
snprintf(device_name, sizeof(device_name), "/dev/video%u", device_num);
int fd = open(device_name, O_RDWR, 0);
if (fd < 0)
return Platform::UNKNOWN;
continue;

v4l2_capability caps;
unsigned long request = VIDIOC_QUERYCAP;
Expand All @@ -51,17 +52,19 @@ Platform get_platform()
close(fd);

if (ret)
return Platform::UNKNOWN;
continue;

if (!strncmp((char *)caps.card, "unicam", sizeof(caps.card)))
return Platform::VC4;
else if (!strncmp((char *)caps.card, "rp1-cfe", sizeof(caps.card)))
return Platform::PISP;
else if (!strncmp((char *)caps.card, "bm2835 mmal", sizeof(caps.card)))
return Platform::LEGACY;
else
unknown = true;
}

return Platform::UNKNOWN;
return unknown ? Platform::UNKNOWN : Platform::MISSING;
}

static libcamera::PixelFormat mode_to_pixel_format(Mode const &mode)
Expand Down Expand Up @@ -122,7 +125,7 @@ LibcameraApp::LibcameraApp(std::unique_ptr<Options> opts)
}
else if (platform == Platform::UNKNOWN)
{
fprintf(stderr, "ERROR: libcamera-apps currently only supports the Raspberry Pi platform.\n"
fprintf(stderr, "ERROR: libcamera-apps currently only supports the Raspberry Pi platforms.\n"
"Contributions for other platforms are welcome at https://github.com/raspberrypi/libcamera-apps.\n");
exit(-1);
}
Expand Down

0 comments on commit 4fed529

Please sign in to comment.