v4l2: set default resolution if caps has no such information
authorHou Qi <qi.hou@nxp.com>
Tue, 10 May 2022 08:20:46 +0000 (16:20 +0800)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 20 May 2022 12:23:40 +0000 (12:23 +0000)
Output may attemp to set the width and height to zero values if
caps has no such information, which will cause capture get invalid
dimensions. Then decoder reports negotiation failure.

So need to set default resolution if caps has no such information.
Real values can be set again until source change event is signaled.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2400>

subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c

index b948e16..c0834a8 100644 (file)
@@ -54,6 +54,8 @@ GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
 #define DEFAULT_PROP_IO_MODE            GST_V4L2_IO_AUTO
 
 #define ENCODED_BUFFER_SIZE             (2 * 1024 * 1024)
+#define GST_V4L2_DEFAULT_WIDTH          320
+#define GST_V4L2_DEFAULT_HEIGHT         240
 
 enum
 {
@@ -3563,6 +3565,11 @@ gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
   pixelformat = fmtdesc->pixelformat;
   width = GST_VIDEO_INFO_WIDTH (&info);
   height = GST_VIDEO_INFO_FIELD_HEIGHT (&info);
+  /* if caps has no width and height info, use default value */
+  if (V4L2_TYPE_IS_OUTPUT (v4l2object->type) && width == 0 && height == 0) {
+    width = GST_V4L2_DEFAULT_WIDTH;
+    height = GST_V4L2_DEFAULT_HEIGHT;
+  }
   fps_n = GST_VIDEO_INFO_FPS_N (&info);
   fps_d = GST_VIDEO_INFO_FPS_D (&info);