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.

(There seemed to be no obvious place for common code so it is
duplicated. There's not much.)

Signed-off-by: David Plowman <[email protected]>
  • Loading branch information
davidplowman committed Nov 23, 2021
1 parent bab9bf8 commit 53d894a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
23 changes: 23 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiStill.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <errno.h>
#include <sysexits.h>

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

#include "bcm_host.h"
#include "interface/vcos/vcos.h"

Expand Down Expand Up @@ -1629,6 +1633,23 @@ static void rename_file(RASPISTILL_STATE *state, FILE *output_file,
}
}

static 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);
}


/**
* main
Expand All @@ -1647,6 +1668,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
23 changes: 23 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiStillYUV.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unistd.h>
#include <errno.h>

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

#include "bcm_host.h"
#include "interface/vcos/vcos.h"

Expand Down Expand Up @@ -1050,6 +1054,23 @@ static void rename_file(RASPISTILLYUV_STATE *state, FILE *output_file,
}
}

static 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);
}

/**
* main
*/
Expand All @@ -1066,6 +1087,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
23 changes: 23 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiVid.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <arpa/inet.h>
#include <time.h>

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

#include "bcm_host.h"
#include "interface/vcos/vcos.h"

Expand Down Expand Up @@ -2388,6 +2392,23 @@ static int wait_for_next_change(RASPIVID_STATE *state)
return keep_running;
}

static 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);
}

/**
* main
*/
Expand All @@ -2408,6 +2429,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
23 changes: 23 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiVidYUV.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <netinet/in.h>
#include <arpa/inet.h>

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

#include "bcm_host.h"
#include "interface/vcos/vcos.h"

Expand Down Expand Up @@ -1224,6 +1228,23 @@ static int wait_for_next_change(RASPIVIDYUV_STATE *state)
return keep_running;
}

static 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);
}

/**
* main
*/
Expand All @@ -1239,6 +1260,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 53d894a

Please sign in to comment.