Skip to content

Commit

Permalink
raspicam: Check system is running legacy camera stack
Browse files Browse the repository at this point in the history
If the system is obviously configured for libcamera (for example) by
dint of /dev/video0 being given over to "unicam", complain and abort
immediately. In all other circumstances maintain previous behaviour.

Signed-off-by: David Plowman <[email protected]>
  • Loading branch information
davidplowman authored and pelwell committed Nov 23, 2021
1 parent bab9bf8 commit f5404b2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiHelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unistd.h>
#include <stdint.h>

#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>

#include "interface/vcos/vcos.h"
#include "interface/mmal/mmal.h"
Expand Down Expand Up @@ -294,3 +297,25 @@ uint64_t get_microseconds64()

return us;
}


/*
* If we are configured to use /dev/video0 as unicam (e.g. for libcamera) then
* these legacy camera apps can't work. Fail immediately with an obvious message.
*/
void check_camera_stack()
{
int fd = open("/dev/video0", O_RDWR, 0);
if (fd < 0)
return;

struct v4l2_capability caps;
int ret = ioctl(fd, VIDIOC_QUERYCAP, &caps);
close(fd);

if (ret < 0 || strcmp((char *)caps.driver, "unicam"))
return;

fprintf(stderr, "ERROR: the system should be configured for the legacy camera stack\n");
exit(-1);
}
1 change: 1 addition & 0 deletions host_applications/linux/apps/raspicam/RaspiHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ void default_signal_handler(int signal_number);
int mmal_status_to_int(MMAL_STATUS_T status);
void print_app_details(FILE *fd);
uint64_t get_microseconds64();
void check_camera_stack();

#endif
2 changes: 2 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiStill.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,8 @@ int main(int argc, const char **argv)
MMAL_PORT_T *encoder_input_port = NULL;
MMAL_PORT_T *encoder_output_port = NULL;

check_camera_stack();

bcm_host_init();

// Register our application with the logging system
Expand Down
2 changes: 2 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiStillYUV.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,8 @@ int main(int argc, const char **argv)
MMAL_PORT_T *preview_input_port = NULL;
FILE *output_file = NULL;

check_camera_stack();

bcm_host_init();

// Register our application with the logging system
Expand Down
2 changes: 2 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiVid.c
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,8 @@ int main(int argc, const char **argv)
MMAL_PORT_T *splitter_output_port = NULL;
MMAL_PORT_T *splitter_preview_port = NULL;

check_camera_stack();

bcm_host_init();

// Register our application with the logging system
Expand Down
2 changes: 2 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiVidYUV.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,8 @@ int main(int argc, const char **argv)
MMAL_PORT_T *camera_still_port = NULL;
MMAL_PORT_T *preview_input_port = NULL;

check_camera_stack();

bcm_host_init();

// Register our application with the logging system
Expand Down

0 comments on commit f5404b2

Please sign in to comment.