diff mbox series

tvtime: support drivers that always select a pixfmt in S_FMT

Message ID a5dff340-ab8a-46e0-1f0c-25ceaf9fe5ca@xs4all.nl (mailing list archive)
State New, archived
Headers show
Series tvtime: support drivers that always select a pixfmt in S_FMT | expand

Commit Message

Hans Verkuil April 12, 2023, 11:08 a.m. UTC
Drivers can either reject an unsupported pixelformat in VIDIOC_S_FMT,
or replace it with a supported one. Either option is allowed.

tvtime assumes that it is rejected, but instead it should check if it
chose something else, and then retry with UYVY.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
diff mbox series

Patch

diff --git a/src/videoinput.c b/src/videoinput.c
index 5c147c8..12763dd 100644
--- a/src/videoinput.c
+++ b/src/videoinput.c
@@ -516,13 +516,19 @@  retry:
     memset( &(imgformat.fmt.pix), 0, sizeof( struct v4l2_pix_format ) );
     imgformat.fmt.pix.width = capwidth;
     imgformat.fmt.pix.height = vidin->height;
-    imgformat.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
     imgformat.fmt.pix.field = V4L2_FIELD_INTERLACED;
+    imgformat.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;

-    if( ioctl( vidin->grab_fd, VIDIOC_S_FMT, &imgformat ) < 0 ) {
+    if( ioctl( vidin->grab_fd, VIDIOC_S_FMT, &imgformat ) < 0 ||
+        imgformat.fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV ) {
 	/* Try for UYVY instead. */
+	memset( &(imgformat.fmt.pix), 0, sizeof( struct v4l2_pix_format ) );
+	imgformat.fmt.pix.width = capwidth;
+	imgformat.fmt.pix.height = vidin->height;
+	imgformat.fmt.pix.field = V4L2_FIELD_INTERLACED;
 	imgformat.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
-	if( ioctl( vidin->grab_fd, VIDIOC_S_FMT, &imgformat ) < 0 ) {
+	if( ioctl( vidin->grab_fd, VIDIOC_S_FMT, &imgformat ) < 0 ||
+	    imgformat.fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY ) {

 	    fprintf( stderr, "\n"
      "    Your capture card driver: %s\n"