Merge branch 'upstream/1.16' into tizen_gst_1.16.2
[platform/upstream/gst-plugins-good.git] / sys / v4l2 / gstv4l2src.c
index 8273af4..0b55b5d 100644 (file)
  * ]| This pipeline shows the video captured from a webcam that delivers jpeg
  * images.
  * </refsect2>
+ *
+ * Since 1.14, the use of libv4l2 has been disabled due to major bugs in the
+ * emulation layer. To enable usage of this library, set the environment
+ * variable GST_V4L2_USE_LIBV4L2=1.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -68,6 +72,9 @@ enum
 {
   PROP_0,
   V4L2_STD_OBJECT_PROPS,
+#ifdef TIZEN_FEATURE_V4L2SRC_SUPPORT_CAMERA_ID
+  PROP_CAMERA_ID,
+#endif /* TIZEN_FEATURE_V4L2SRC_SUPPORT_CAMERA_ID */
   PROP_LAST
 };
 
@@ -107,13 +114,13 @@ static gboolean gst_v4l2src_start (GstBaseSrc * src);
 static gboolean gst_v4l2src_unlock (GstBaseSrc * src);
 static gboolean gst_v4l2src_unlock_stop (GstBaseSrc * src);
 static gboolean gst_v4l2src_stop (GstBaseSrc * src);
-static gboolean gst_v4l2src_set_caps (GstBaseSrc * src, GstCaps * caps);
 static GstCaps *gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter);
 static gboolean gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query);
 static gboolean gst_v4l2src_decide_allocation (GstBaseSrc * src,
     GstQuery * query);
 static GstFlowReturn gst_v4l2src_create (GstPushSrc * src, GstBuffer ** out);
-static GstCaps *gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps);
+static GstCaps *gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps,
+    GstStructure * pref_s);
 static gboolean gst_v4l2src_negotiate (GstBaseSrc * basesrc);
 
 static void gst_v4l2src_set_property (GObject * object, guint prop_id,
@@ -143,6 +150,19 @@ gst_v4l2src_class_init (GstV4l2SrcClass * klass)
   gst_v4l2_object_install_properties_helper (gobject_class,
       DEFAULT_PROP_DEVICE);
 
+#ifdef TIZEN_FEATURE_V4L2SRC_SUPPORT_CAMERA_ID
+  /**
+   * GstV4l2Src:camera-id:
+   *
+   * The value which is set by application will be used as a number of device node.
+   * ex) 1 -> /dev/video1
+   */
+  g_object_class_install_property (gobject_class, PROP_CAMERA_ID,
+      g_param_spec_uint ("camera-id", "Camera ID",
+          "Camera ID for device node", 0, G_MAXUINT, 0,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+#endif /* TIZEN_FEATURE_V4L2SRC_SUPPORT_CAMERA_ID */
+
   /**
    * GstV4l2Src::prepare-format:
    * @v4l2src: the v4l2src instance
@@ -154,8 +174,6 @@ gst_v4l2src_class_init (GstV4l2SrcClass * klass)
    * happen prior to the format being set.
    * This is mostly useful for UVC H264 encoding cameras which need the H264
    * Probe & Commit to happen prior to the normal Probe & Commit.
-   *
-   * Since: 0.10.32
    */
   gst_v4l2_signals[SIGNAL_PRE_SET_FORMAT] = g_signal_new ("prepare-format",
       G_TYPE_FROM_CLASS (klass),
@@ -174,13 +192,11 @@ gst_v4l2src_class_init (GstV4l2SrcClass * klass)
           gst_v4l2_object_get_all_caps ()));
 
   basesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_v4l2src_get_caps);
-  basesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_v4l2src_set_caps);
   basesrc_class->start = GST_DEBUG_FUNCPTR (gst_v4l2src_start);
   basesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_v4l2src_unlock);
   basesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_v4l2src_unlock_stop);
   basesrc_class->stop = GST_DEBUG_FUNCPTR (gst_v4l2src_stop);
   basesrc_class->query = GST_DEBUG_FUNCPTR (gst_v4l2src_query);
-  basesrc_class->fixate = GST_DEBUG_FUNCPTR (gst_v4l2src_fixate);
   basesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_v4l2src_negotiate);
   basesrc_class->decide_allocation =
       GST_DEBUG_FUNCPTR (gst_v4l2src_decide_allocation);
@@ -197,8 +213,11 @@ gst_v4l2src_init (GstV4l2Src * v4l2src)
 {
   /* fixme: give an update_fps_function */
   v4l2src->v4l2object = gst_v4l2_object_new (GST_ELEMENT (v4l2src),
-      V4L2_BUF_TYPE_VIDEO_CAPTURE, DEFAULT_PROP_DEVICE,
-      gst_v4l2_get_input, gst_v4l2_set_input, NULL);
+      GST_OBJECT (GST_BASE_SRC_PAD (v4l2src)), V4L2_BUF_TYPE_VIDEO_CAPTURE,
+      DEFAULT_PROP_DEVICE, gst_v4l2_get_input, gst_v4l2_set_input, NULL);
+
+  /* Avoid the slow probes */
+  v4l2src->v4l2object->skip_try_fmt_probes = TRUE;
 
   gst_base_src_set_format (GST_BASE_SRC (v4l2src), GST_FORMAT_TIME);
   gst_base_src_set_live (GST_BASE_SRC (v4l2src), TRUE);
@@ -223,6 +242,16 @@ gst_v4l2src_set_property (GObject * object,
   if (!gst_v4l2_object_set_property_helper (v4l2src->v4l2object,
           prop_id, value, pspec)) {
     switch (prop_id) {
+#ifdef TIZEN_FEATURE_V4L2SRC_SUPPORT_CAMERA_ID
+      case PROP_CAMERA_ID:
+        g_free (v4l2src->v4l2object->videodev);
+
+        v4l2src->camera_id = g_value_get_uint (value);
+        v4l2src->v4l2object->videodev = g_strdup_printf ("/dev/video%u", v4l2src->camera_id);
+
+        GST_INFO_OBJECT(v4l2src, "videodev [%s]", v4l2src->v4l2object->videodev);
+        break;
+#endif /* TIZEN_FEATURE_V4L2SRC_SUPPORT_CAMERA_ID */
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -239,6 +268,11 @@ gst_v4l2src_get_property (GObject * object,
   if (!gst_v4l2_object_get_property_helper (v4l2src->v4l2object,
           prop_id, value, pspec)) {
     switch (prop_id) {
+#ifdef TIZEN_FEATURE_V4L2SRC_SUPPORT_CAMERA_ID
+      case PROP_CAMERA_ID:
+        g_value_set_uint (value, v4l2src->camera_id);
+        break;
+#endif /* TIZEN_FEATURE_V4L2SRC_SUPPORT_CAMERA_ID */
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -246,47 +280,260 @@ gst_v4l2src_get_property (GObject * object,
   }
 }
 
-/* this function is a bit of a last resort */
+struct PreferedCapsInfo
+{
+  gint width;
+  gint height;
+  gint fps_n;
+  gint fps_d;
+};
+
+static gboolean
+gst_vl42_src_fixate_fields (GQuark field_id, GValue * value, gpointer user_data)
+{
+  GstStructure *s = user_data;
+
+  if (field_id == g_quark_from_string ("interlace-mode"))
+    return TRUE;
+
+  if (field_id == g_quark_from_string ("colorimetry"))
+    return TRUE;
+
+  gst_structure_fixate_field (s, g_quark_to_string (field_id));
+
+  return TRUE;
+}
+
+static void
+gst_v4l2_src_fixate_struct_with_preference (GstStructure * s,
+    struct PreferedCapsInfo *pref)
+{
+  if (gst_structure_has_field (s, "width"))
+    gst_structure_fixate_field_nearest_int (s, "width", pref->width);
+
+  if (gst_structure_has_field (s, "height"))
+    gst_structure_fixate_field_nearest_int (s, "height", pref->height);
+
+  if (gst_structure_has_field (s, "framerate"))
+    gst_structure_fixate_field_nearest_fraction (s, "framerate", pref->fps_n,
+        pref->fps_d);
+
+  /* Finally, fixate everything else except the interlace-mode and colorimetry
+   * which still need further negotiation as it wasn't probed */
+  gst_structure_map_in_place (s, gst_vl42_src_fixate_fields, s);
+}
+
+static void
+gst_v4l2_src_parse_fixed_struct (GstStructure * s,
+    gint * width, gint * height, gint * fps_n, gint * fps_d)
+{
+  if (gst_structure_has_field (s, "width") && width)
+    gst_structure_get_int (s, "width", width);
+
+  if (gst_structure_has_field (s, "height") && height)
+    gst_structure_get_int (s, "height", height);
+
+  if (gst_structure_has_field (s, "framerate") && fps_n && fps_d)
+    gst_structure_get_fraction (s, "framerate", fps_n, fps_d);
+}
+
+/* TODO Consider framerate */
+static gint
+gst_v4l2src_fixed_caps_compare (GstCaps * caps_a, GstCaps * caps_b,
+    struct PreferedCapsInfo *pref)
+{
+  GstStructure *a, *b;
+  gint aw = G_MAXINT, ah = G_MAXINT, ad = G_MAXINT;
+  gint bw = G_MAXINT, bh = G_MAXINT, bd = G_MAXINT;
+  gint ret;
+
+  a = gst_caps_get_structure (caps_a, 0);
+  b = gst_caps_get_structure (caps_b, 0);
+
+  gst_v4l2_src_parse_fixed_struct (a, &aw, &ah, NULL, NULL);
+  gst_v4l2_src_parse_fixed_struct (b, &bw, &bh, NULL, NULL);
+
+  /* When both are smaller then pref, just append to the end */
+  if ((bw < pref->width || bh < pref->height)
+      && (aw < pref->width || ah < pref->height)) {
+    ret = 1;
+    goto done;
+  }
+
+  /* If a is smaller then pref and not b, then a goes after b */
+  if (aw < pref->width || ah < pref->height) {
+    ret = 1;
+    goto done;
+  }
+
+  /* If b is smaller then pref and not a, then a goes before b */
+  if (bw < pref->width || bh < pref->height) {
+    ret = -1;
+    goto done;
+  }
+
+  /* Both are larger or equal to the preference, prefer the smallest */
+  ad = MAX (1, aw - pref->width) * MAX (1, ah - pref->height);
+  bd = MAX (1, bw - pref->width) * MAX (1, bh - pref->height);
+
+  /* Adjust slightly in case width/height matched the preference */
+  if (aw == pref->width)
+    ad -= 1;
+
+  if (ah == pref->height)
+    ad -= 1;
+
+  if (bw == pref->width)
+    bd -= 1;
+
+  if (bh == pref->height)
+    bd -= 1;
+
+  /* If the choices are equivalent, maintain the order */
+  if (ad == bd)
+    ret = 1;
+  else
+    ret = ad - bd;
+
+done:
+  GST_TRACE ("Placing %ix%i (%s) %s %ix%i (%s)", aw, ah,
+      gst_structure_get_string (a, "format"), ret > 0 ? "after" : "before", bw,
+      bh, gst_structure_get_string (b, "format"));
+  return ret;
+}
+
+static gboolean
+gst_v4l2src_set_format (GstV4l2Src * v4l2src, GstCaps * caps,
+    GstV4l2Error * error)
+{
+  GstV4l2Object *obj;
+
+  obj = v4l2src->v4l2object;
+
+  /* make sure we stop capturing and dealloc buffers */
+  if (!gst_v4l2_object_stop (obj))
+    return FALSE;
+
+  g_signal_emit (v4l2src, gst_v4l2_signals[SIGNAL_PRE_SET_FORMAT], 0,
+      v4l2src->v4l2object->video_fd, caps);
+
+  return gst_v4l2_object_set_format (obj, caps, error);
+}
+
 static GstCaps *
-gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps)
+gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps, GstStructure * pref_s)
 {
-  GstStructure *structure;
-  gint i;
+  /* Let's prefer a good resolutiion as of today's standard. */
+  struct PreferedCapsInfo pref = {
+    3840, 2160, 120, 1
+  };
+  GstV4l2Src *v4l2src = GST_V4L2SRC (basesrc);
+  GstV4l2Object *obj = v4l2src->v4l2object;
+  GList *caps_list = NULL;
+  GstStructure *s;
+  gint i = G_MAXINT;
+  GstV4l2Error error = GST_V4L2_ERROR_INIT;
+  GstCaps *fcaps = NULL;
 
   GST_DEBUG_OBJECT (basesrc, "fixating caps %" GST_PTR_FORMAT, caps);
 
-  caps = gst_caps_make_writable (caps);
+  /* We consider the first structure from peercaps to be a preference. This is
+   * useful for matching a reported native display, or simply to avoid
+   * transformation to happen downstream. */
+  if (pref_s) {
+    pref_s = gst_structure_copy (pref_s);
+    gst_v4l2_src_fixate_struct_with_preference (pref_s, &pref);
+    gst_v4l2_src_parse_fixed_struct (pref_s, &pref.width, &pref.height,
+        &pref.fps_n, &pref.fps_d);
+    gst_structure_free (pref_s);
+  }
+
+  GST_DEBUG_OBJECT (basesrc, "Prefered size %ix%i", pref.width, pref.height);
+
+  /* Sort the structures to get the caps that is nearest to our preferences,
+   * first. Use single struct caps for sorting so we preserve the features.  */
+  for (i = 0; i < gst_caps_get_size (caps); i++) {
+    GstCaps *tmp = gst_caps_copy_nth (caps, i);
+
+    s = gst_caps_get_structure (tmp, 0);
+    gst_v4l2_src_fixate_struct_with_preference (s, &pref);
+
+    caps_list = g_list_insert_sorted_with_data (caps_list, tmp,
+        (GCompareDataFunc) gst_v4l2src_fixed_caps_compare, &pref);
+  }
+
+  gst_caps_unref (caps);
+  caps = gst_caps_new_empty ();
+
+  while (caps_list) {
+    GstCaps *tmp = caps_list->data;
+    caps_list = g_list_delete_link (caps_list, caps_list);
+    gst_caps_append (caps, tmp);
+  }
+
+  GST_DEBUG_OBJECT (basesrc, "sorted and normalized caps %" GST_PTR_FORMAT,
+      caps);
+
+  /* Each structure in the caps has been fixated, except for the
+   * interlace-mode and colorimetry. Now normalize the caps so we can
+   * enumerate the possibilities */
+  caps = gst_caps_normalize (caps);
 
   for (i = 0; i < gst_caps_get_size (caps); ++i) {
-    structure = gst_caps_get_structure (caps, i);
+    gst_v4l2_clear_error (&error);
+    if (fcaps)
+      gst_caps_unref (fcaps);
 
-    /* We are fixating to a reasonable 320x200 resolution
-       and the maximum framerate resolution for that size */
-    if (gst_structure_has_field (structure, "width"))
-      gst_structure_fixate_field_nearest_int (structure, "width", 320);
+    fcaps = gst_caps_copy_nth (caps, i);
 
-    if (gst_structure_has_field (structure, "height"))
-      gst_structure_fixate_field_nearest_int (structure, "height", 200);
+    /* try hard to avoid TRY_FMT since some UVC camera just crash when this
+     * is called at run-time. */
+    if (gst_v4l2_object_caps_is_subset (obj, fcaps)) {
+      gst_caps_unref (fcaps);
+      fcaps = gst_v4l2_object_get_current_caps (obj);
+      break;
+    }
+
+    /* Just check if the format is acceptable, once we know
+     * no buffers should be outstanding we try S_FMT.
+     *
+     * Basesrc will do an allocation query that
+     * should indirectly reclaim buffers, after that we can
+     * set the format and then configure our pool */
+    if (gst_v4l2_object_try_format (obj, fcaps, &error)) {
+      /* make sure the caps changed before doing anything */
+      if (gst_v4l2_object_caps_equal (obj, fcaps))
+        break;
 
-    if (gst_structure_has_field (structure, "framerate"))
-      gst_structure_fixate_field_nearest_fraction (structure, "framerate",
-          100, 1);
+      v4l2src->renegotiation_adjust = v4l2src->offset + 1;
+      v4l2src->pending_set_fmt = TRUE;
+      break;
+    }
 
-    if (gst_structure_has_field (structure, "format"))
-      gst_structure_fixate_field (structure, "format");
+    /* Only EIVAL make sense, report any other errors, this way we don't keep
+     * probing if the device got disconnected, or if it's firmware stopped
+     * responding */
+    if (error.error->code != GST_RESOURCE_ERROR_SETTINGS) {
+      i = G_MAXINT;
+      break;
+    }
+  }
 
-    if (gst_structure_has_field (structure, "interlace-mode"))
-      gst_structure_fixate_field (structure, "interlace-mode");
+  if (i >= gst_caps_get_size (caps)) {
+    gst_v4l2_error (v4l2src, &error);
+    if (fcaps)
+      gst_caps_unref (fcaps);
+    gst_caps_unref (caps);
+    return NULL;
   }
 
-  GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, caps);
+  gst_caps_unref (caps);
 
-  caps = GST_BASE_SRC_CLASS (parent_class)->fixate (basesrc, caps);
+  GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, fcaps);
 
-  return caps;
+  return fcaps;
 }
 
-
 static gboolean
 gst_v4l2src_negotiate (GstBaseSrc * basesrc)
 {
@@ -307,63 +554,34 @@ gst_v4l2src_negotiate (GstBaseSrc * basesrc)
   peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
   GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps);
   if (peercaps && !gst_caps_is_any (peercaps)) {
-    GstCaps *icaps = NULL;
-
     /* Prefer the first caps we are compatible with that the peer proposed */
-    icaps = gst_caps_intersect_full (peercaps, thiscaps,
+    caps = gst_caps_intersect_full (peercaps, thiscaps,
         GST_CAPS_INTERSECT_FIRST);
 
-    GST_DEBUG_OBJECT (basesrc, "intersect: %" GST_PTR_FORMAT, icaps);
-    if (icaps) {
-      /* If there are multiple intersections pick the one with the smallest
-       * resolution strictly bigger then the first peer caps */
-      if (gst_caps_get_size (icaps) > 1) {
-        GstStructure *s = gst_caps_get_structure (peercaps, 0);
-        int best = 0;
-        int twidth, theight;
-        int width = G_MAXINT, height = G_MAXINT;
-
-        if (gst_structure_get_int (s, "width", &twidth)
-            && gst_structure_get_int (s, "height", &theight)) {
-          int i;
-
-          /* Walk the structure backwards to get the first entry of the
-           * smallest resolution bigger (or equal to) the preferred resolution)
-           */
-          for (i = gst_caps_get_size (icaps) - 1; i >= 0; i--) {
-            GstStructure *is = gst_caps_get_structure (icaps, i);
-            int w, h;
-
-            if (gst_structure_get_int (is, "width", &w)
-                && gst_structure_get_int (is, "height", &h)) {
-              if (w >= twidth && w <= width && h >= theight && h <= height) {
-                width = w;
-                height = h;
-                best = i;
-              }
-            }
-          }
-        }
-
-        caps = gst_caps_copy_nth (icaps, best);
-        gst_caps_unref (icaps);
-      } else {
-        caps = icaps;
-      }
-    }
+    GST_DEBUG_OBJECT (basesrc, "intersect: %" GST_PTR_FORMAT, caps);
+
     gst_caps_unref (thiscaps);
   } else {
     /* no peer or peer have ANY caps, work with our own caps then */
     caps = thiscaps;
   }
-  if (peercaps)
-    gst_caps_unref (peercaps);
-  if (caps) {
-    caps = gst_caps_truncate (caps);
 
+  if (caps) {
     /* now fixate */
     if (!gst_caps_is_empty (caps)) {
-      caps = gst_v4l2src_fixate (basesrc, caps);
+      GstStructure *pref = NULL;
+
+      if (peercaps && !gst_caps_is_any (peercaps))
+        pref = gst_caps_get_structure (peercaps, 0);
+
+      caps = gst_v4l2src_fixate (basesrc, caps, pref);
+
+      /* Fixating may fail as we now set the selected format */
+      if (!caps) {
+        result = FALSE;
+        goto done;
+      }
+
       GST_DEBUG_OBJECT (basesrc, "fixated to: %" GST_PTR_FORMAT, caps);
 
       if (gst_caps_is_any (caps)) {
@@ -377,6 +595,11 @@ gst_v4l2src_negotiate (GstBaseSrc * basesrc)
     }
     gst_caps_unref (caps);
   }
+
+done:
+  if (peercaps)
+    gst_caps_unref (peercaps);
+
   return result;
 
 no_nego_needed:
@@ -405,64 +628,6 @@ gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter)
 }
 
 static gboolean
-gst_v4l2src_set_format (GstV4l2Src * v4l2src, GstCaps * caps)
-{
-  GstV4l2Error error = GST_V4L2_ERROR_INIT;
-  GstV4l2Object *obj;
-
-  obj = v4l2src->v4l2object;
-
-  g_signal_emit (v4l2src, gst_v4l2_signals[SIGNAL_PRE_SET_FORMAT], 0,
-      v4l2src->v4l2object->video_fd, caps);
-
-  if (!gst_v4l2_object_set_format (obj, caps, &error)) {
-    gst_v4l2_error (v4l2src, &error);
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-static gboolean
-gst_v4l2src_set_caps (GstBaseSrc * src, GstCaps * caps)
-{
-  GstV4l2Src *v4l2src;
-  GstV4l2Object *obj;
-
-  v4l2src = GST_V4L2SRC (src);
-  obj = v4l2src->v4l2object;
-
-  /* make sure the caps changed before doing anything */
-  if (gst_v4l2_object_caps_equal (obj, caps))
-    return TRUE;
-
-  if (GST_V4L2_IS_ACTIVE (obj)) {
-    GstV4l2Error error = GST_V4L2_ERROR_INIT;
-    /* Just check if the format is acceptable, once we know
-     * no buffers should be outstanding we try S_FMT.
-     *
-     * Basesrc will do an allocation query that
-     * should indirectly reclaim buffers, after that we can
-     * set the format and then configure our pool */
-    if (gst_v4l2_object_try_format (obj, caps, &error)) {
-      v4l2src->renegotiation_adjust = v4l2src->offset + 1;
-      v4l2src->pending_set_fmt = TRUE;
-    } else {
-      gst_v4l2_error (v4l2src, &error);
-      return FALSE;
-    }
-  } else {
-    /* make sure we stop capturing and dealloc buffers */
-    if (!gst_v4l2_object_stop (obj))
-      return FALSE;
-
-    return gst_v4l2src_set_format (v4l2src, caps);
-  }
-
-  return TRUE;
-}
-
-static gboolean
 gst_v4l2src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
 {
   GstV4l2Src *src = GST_V4L2SRC (bsrc);
@@ -470,10 +635,12 @@ gst_v4l2src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
 
   if (src->pending_set_fmt) {
     GstCaps *caps = gst_pad_get_current_caps (GST_BASE_SRC_PAD (bsrc));
+    GstV4l2Error error = GST_V4L2_ERROR_INIT;
+
+    caps = gst_caps_make_writable (caps);
+    if (!(ret = gst_v4l2src_set_format (src, caps, &error)))
+      gst_v4l2_error (src, &error);
 
-    if (!gst_v4l2_object_stop (src->v4l2object))
-      return FALSE;
-    ret = gst_v4l2src_set_format (src, caps);
     gst_caps_unref (caps);
     src->pending_set_fmt = FALSE;
   } else if (gst_buffer_pool_is_active (src->v4l2object->pool)) {