raspicam: Check system is running legacy camera stack

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 <david.plowman@raspberrypi.com>
This commit is contained in:
David Plowman
2021-11-23 16:37:20 +00:00
committed by Phil Elwell
parent bab9bf8790
commit f5404b2fcd
6 changed files with 34 additions and 0 deletions

View File

@@ -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"
@@ -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);
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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