Skip to content

Commit 05396ad

Browse files
app/v4l2_to_ip: add fault detection (#659) (#661)
Add fault detection at caller side because the error message has been removed. (cherry picked from commit d4268eb) Co-authored-by: gongxiao-intel <[email protected]>
1 parent f0b5aca commit 05396ad

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

app/v4l2_to_ip/v4l2_to_ip.c

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -768,50 +768,37 @@ static void video_close(struct device* dev) {
768768
static void video_log_status(struct device* dev) { ioctl(dev->fd, VIDIOC_LOG_STATUS); }
769769

770770
static int video_get_format(struct device* dev) {
771-
struct v4l2_format fmt;
771+
struct v4l2_format v_fmt;
772772
unsigned int i;
773773
int ret;
774774

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

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

784783
if (video_is_mplane(dev)) {
785-
dev->width = fmt.fmt.pix_mp.width;
786-
dev->height = fmt.fmt.pix_mp.height;
787-
dev->num_planes = fmt.fmt.pix_mp.num_planes;
788-
789-
printf("Video format: %s (%08x) %ux%u field %s, %u planes: \n",
790-
v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat,
791-
fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height,
792-
v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix_mp.num_planes);
793-
794-
for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++) {
795-
dev->plane_fmt[i].bytesperline = fmt.fmt.pix_mp.plane_fmt[i].bytesperline;
796-
dev->plane_fmt[i].sizeimage = fmt.fmt.pix_mp.plane_fmt[i].bytesperline
797-
? fmt.fmt.pix_mp.plane_fmt[i].sizeimage
784+
dev->width = v_fmt.fmt.pix_mp.width;
785+
dev->height = v_fmt.fmt.pix_mp.height;
786+
dev->num_planes = v_fmt.fmt.pix_mp.num_planes;
787+
788+
for (i = 0; i < v_fmt.fmt.pix_mp.num_planes; i++) {
789+
dev->plane_fmt[i].bytesperline = v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline;
790+
dev->plane_fmt[i].sizeimage = v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline
791+
? v_fmt.fmt.pix_mp.plane_fmt[i].sizeimage
798792
: 0;
799-
800-
printf(" * Stride %u, buffer size %u\n", fmt.fmt.pix_mp.plane_fmt[i].bytesperline,
801-
fmt.fmt.pix_mp.plane_fmt[i].sizeimage);
802793
}
803794
} else {
804-
dev->width = fmt.fmt.pix.width;
805-
dev->height = fmt.fmt.pix.height;
795+
dev->width = v_fmt.fmt.pix.width;
796+
dev->height = v_fmt.fmt.pix.height;
806797
dev->num_planes = 1;
807798

808-
dev->plane_fmt[0].bytesperline = fmt.fmt.pix.bytesperline;
809-
dev->plane_fmt[0].sizeimage = fmt.fmt.pix.bytesperline ? fmt.fmt.pix.sizeimage : 0;
810-
811-
printf("Video format: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n",
812-
v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat,
813-
fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline,
814-
v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix.sizeimage);
799+
dev->plane_fmt[0].bytesperline = v_fmt.fmt.pix.bytesperline;
800+
dev->plane_fmt[0].sizeimage =
801+
v_fmt.fmt.pix.bytesperline ? v_fmt.fmt.pix.sizeimage : 0;
815802
}
816803

817804
return 0;
@@ -1804,7 +1791,11 @@ int main(int argc, char* argv[]) {
18041791
}
18051792

18061793
/* Get the video format. */
1807-
video_get_format(&(st_v4l2_tx->dev));
1794+
if (!video_get_format(&(st_v4l2_tx->dev))) {
1795+
video_close(&(st_v4l2_tx->dev));
1796+
free(st_v4l2_tx);
1797+
return -EIO;
1798+
}
18081799

18091800
if (!video_is_mplane(&(st_v4l2_tx->dev))) {
18101801
video_close(&(st_v4l2_tx->dev));

0 commit comments

Comments
 (0)