Skip to content

Commit

Permalink
app/v4l2_to_ip: add fault detection (#659) (#661)
Browse files Browse the repository at this point in the history
Add fault detection at caller side because the error message has been
removed.

(cherry picked from commit d4268eb)

Co-authored-by: gongxiao-intel <xiaoyan.gong@intel.com>
  • Loading branch information
frankdjx and gongxiao-intel authored Dec 21, 2023
1 parent f0b5aca commit 05396ad
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions app/v4l2_to_ip/v4l2_to_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,50 +768,37 @@ static void video_close(struct device* dev) {
static void video_log_status(struct device* dev) { ioctl(dev->fd, VIDIOC_LOG_STATUS); }

static int video_get_format(struct device* dev) {
struct v4l2_format fmt;
struct v4l2_format v_fmt;
unsigned int i;
int ret;

memset(&fmt, 0, sizeof fmt);
fmt.type = dev->type;
memset(&v_fmt, 0, sizeof v_fmt);
v_fmt.type = dev->type;

ret = ioctl(dev->fd, VIDIOC_G_FMT, &fmt);
ret = ioctl(dev->fd, VIDIOC_G_FMT, &v_fmt);
if (ret < 0) {
printf("Unable to get format: %s (%d).\n", strerror(errno), errno);
return ret;
}

if (video_is_mplane(dev)) {
dev->width = fmt.fmt.pix_mp.width;
dev->height = fmt.fmt.pix_mp.height;
dev->num_planes = fmt.fmt.pix_mp.num_planes;

printf("Video format: %s (%08x) %ux%u field %s, %u planes: \n",
v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat,
fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height,
v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix_mp.num_planes);

for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++) {
dev->plane_fmt[i].bytesperline = fmt.fmt.pix_mp.plane_fmt[i].bytesperline;
dev->plane_fmt[i].sizeimage = fmt.fmt.pix_mp.plane_fmt[i].bytesperline
? fmt.fmt.pix_mp.plane_fmt[i].sizeimage
dev->width = v_fmt.fmt.pix_mp.width;
dev->height = v_fmt.fmt.pix_mp.height;
dev->num_planes = v_fmt.fmt.pix_mp.num_planes;

for (i = 0; i < v_fmt.fmt.pix_mp.num_planes; i++) {
dev->plane_fmt[i].bytesperline = v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline;
dev->plane_fmt[i].sizeimage = v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline
? v_fmt.fmt.pix_mp.plane_fmt[i].sizeimage
: 0;

printf(" * Stride %u, buffer size %u\n", fmt.fmt.pix_mp.plane_fmt[i].bytesperline,
fmt.fmt.pix_mp.plane_fmt[i].sizeimage);
}
} else {
dev->width = fmt.fmt.pix.width;
dev->height = fmt.fmt.pix.height;
dev->width = v_fmt.fmt.pix.width;
dev->height = v_fmt.fmt.pix.height;
dev->num_planes = 1;

dev->plane_fmt[0].bytesperline = fmt.fmt.pix.bytesperline;
dev->plane_fmt[0].sizeimage = fmt.fmt.pix.bytesperline ? fmt.fmt.pix.sizeimage : 0;

printf("Video format: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n",
v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat,
fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline,
v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix.sizeimage);
dev->plane_fmt[0].bytesperline = v_fmt.fmt.pix.bytesperline;
dev->plane_fmt[0].sizeimage =
v_fmt.fmt.pix.bytesperline ? v_fmt.fmt.pix.sizeimage : 0;
}

return 0;
Expand Down Expand Up @@ -1804,7 +1791,11 @@ int main(int argc, char* argv[]) {
}

/* Get the video format. */
video_get_format(&(st_v4l2_tx->dev));
if (!video_get_format(&(st_v4l2_tx->dev))) {
video_close(&(st_v4l2_tx->dev));
free(st_v4l2_tx);
return -EIO;
}

if (!video_is_mplane(&(st_v4l2_tx->dev))) {
video_close(&(st_v4l2_tx->dev));
Expand Down

0 comments on commit 05396ad

Please sign in to comment.