@@ -82,34 +82,27 @@ void set_v4l2_device(const char* device) {
8282void query_v4l_device (int droidcam_device_fd , unsigned * WEBCAM_W , unsigned * WEBCAM_H ) {
8383 struct v4l2_format vid_format = {0 };
8484 vid_format .type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
85- vid_format .fmt .pix .width = 0 ;
86- vid_format .fmt .pix .height = 0 ;
8785
8886 int in_width = * WEBCAM_W ;
8987 int in_height = * WEBCAM_H ;
9088 * WEBCAM_W = 0 ;
9189 * WEBCAM_H = 0 ;
9290
93- int ret = xioctl (droidcam_device_fd , VIDIOC_G_FMT , & vid_format );
94- if (ret < 0 && errno == EINVAL ) {
95- dbgprint ("Got no format, trying to set %dx%d\n" , in_width , in_height );
96- vid_format .type = V4L2_BUF_TYPE_VIDEO_OUTPUT ;
97- vid_format .fmt .pix .width = in_width ;
98- vid_format .fmt .pix .height = in_height ;
99- vid_format .fmt .pix .pixelformat = V4L2_PIX_FMT_YUV420 ;
100- vid_format .fmt .pix .field = V4L2_FIELD_ANY ;
101-
102- ret = xioctl (droidcam_device_fd , VIDIOC_TRY_FMT , & vid_format );
103- if (ret >= 0 ) {
104- if (xioctl (droidcam_device_fd , VIDIOC_S_FMT , & vid_format ) < 0 ) {
105- errprint ("Fatal: Unable to set v4l2loopback device format. errno=%d\n" , errno );
106- return ;
107- }
108- }
109- }
91+ dbgprint ("Trying to set format YU12:%dx%d\n" , in_width , in_height );
92+ vid_format .type = V4L2_BUF_TYPE_VIDEO_OUTPUT ;
93+ vid_format .fmt .pix .width = in_width ;
94+ vid_format .fmt .pix .height = in_height ;
95+ vid_format .fmt .pix .pixelformat = V4L2_PIX_FMT_YUV420 ;
96+ vid_format .fmt .pix .field = V4L2_FIELD_NONE ;
97+ xioctl (droidcam_device_fd , VIDIOC_S_FMT , & vid_format );
98+
99+ vid_format .type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
100+ xioctl (droidcam_device_fd , VIDIOC_S_FMT , & vid_format );
110101
102+ int ret = xioctl (droidcam_device_fd , VIDIOC_G_FMT , & vid_format );
111103 if (ret < 0 ) {
112- errprint ("Fatal: Unable to query video device. errno=%d\n" , errno );
104+ errprint ("Fatal: Unable to query video device. dev=%s errno=%d\n" ,
105+ v4l2_device , errno );
113106 return ;
114107 }
115108
@@ -121,13 +114,16 @@ void query_v4l_device(int droidcam_device_fd, unsigned *WEBCAM_W, unsigned *WEBC
121114 dbgprint (" vid_format->fmt.pix.field =%d\n" , vid_format .fmt .pix .field );
122115 dbgprint (" vid_format->fmt.pix.bytesperline=%d\n" , vid_format .fmt .pix .bytesperline );
123116 dbgprint (" vid_format->fmt.pix.colorspace =%d\n" , vid_format .fmt .pix .colorspace );
117+
124118 if (vid_format .fmt .pix .pixelformat != V4L2_PIX_FMT_YUV420 ) {
125119 unsigned pixelfmt = vid_format .fmt .pix .pixelformat ;
126120 BYTE fourcc [5 ] = { (BYTE )(pixelfmt >> 0 ), (BYTE )(pixelfmt >> 8 ),
127121 (BYTE )(pixelfmt >> 16 ), (BYTE )(pixelfmt >> 24 ), '\0' };
128- errprint ("Fatal: droidcam video device reported pixel format %x (%s), expected %x (YU12/I420)\n"
129- "Try 'v4l2loopback-ctl set-caps \"video/x-raw, format=I420, width=640, height=480\" %s'\n" ,
130- vid_format .fmt .pix .pixelformat , fourcc , V4L2_PIX_FMT_YUV420 , "/dev/video<N>" );
122+
123+ errprint ("Fatal: video device reported pixel format %x (%s), expected %x (YU12/I420)\n"
124+ "Try `v4l2loopback-ctl set-caps %s \"YU12:%dx%d\"`, or specify a different video device\n" ,
125+ vid_format .fmt .pix .pixelformat , fourcc , V4L2_PIX_FMT_YUV420 ,
126+ v4l2_device , in_width , in_height );
131127 return ;
132128 }
133129 if (vid_format .fmt .pix .width <= 0 || vid_format .fmt .pix .height <= 0 ) {
0 commit comments