Blob Blame History Raw
From a07a1138a8cf8ad1029845dfe4cfdf5a0a36e670 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Fri, 8 Jun 2012 11:31:05 +0200
Subject: [PATCH 2/4] camerabin: Add a camerabin_create_view_finder_caps()
 helper function

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 gst/camerabin/gstcamerabin.c |   72 +++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 32 deletions(-)

diff --git a/gst/camerabin/gstcamerabin.c b/gst/camerabin/gstcamerabin.c
index 8a36970..3f87ff9 100644
--- a/gst/camerabin/gstcamerabin.c
+++ b/gst/camerabin/gstcamerabin.c
@@ -505,22 +505,15 @@ GST_BOILERPLATE_FULL (GstCameraBin, gst_camerabin, GstPipeline,
  */
 
 /*
- * camerabin_setup_src_elements:
+ * camerabin_create_view_finder_caps:
  * @camera: camerabin object
  *
- * This function updates camerabin capsfilters according
- * to fps, resolution and zoom that have been configured
- * to camerabin.
+ * This function creates new view_finder_caps, according to
+ * fps and resolution that have been configured to camerabin.
  */
-static void
-camerabin_setup_src_elements (GstCameraBin * camera)
+static GstCaps *camerabin_create_view_finder_caps (GstCameraBin * camera)
 {
   GstStructure *st;
-  GstCaps *new_caps;
-  gboolean detect_framerate = FALSE;
-
-  /* clear video update status */
-  camera->video_capture_caps_update = FALSE;
 
   if (!camera->view_finder_caps) {
     st = gst_structure_from_string (CAMERABIN_DEFAULT_VF_CAPS, NULL);
@@ -529,39 +522,54 @@ camerabin_setup_src_elements (GstCameraBin * camera)
             0));
   }
 
-  gst_camerabin_monitor_video_source_properties (camera);
-
   if (camera->app_width > 0 && camera->app_height > 0) {
     gst_structure_set (st,
         "width", G_TYPE_INT, camera->app_width,
         "height", G_TYPE_INT, camera->app_height, NULL);
   }
 
-  if (camera->app_fps_n > 0 && camera->app_fps_d > 0) {
-    if (camera->night_mode) {
-      GST_INFO_OBJECT (camera, "night mode, lowest allowed fps will be forced");
-      camera->pre_night_fps_n = camera->app_fps_n;
-      camera->pre_night_fps_d = camera->app_fps_d;
-      detect_framerate = TRUE;
-    } else {
-      gst_structure_set (st,
-          "framerate", GST_TYPE_FRACTION, camera->app_fps_n,
-          camera->app_fps_d, NULL);
-      new_caps = gst_caps_new_full (st, NULL);
-    }
+  if (!camera->night_mode && camera->app_fps_n > 0 && camera->app_fps_d > 0) {
+    gst_structure_set (st,
+        "framerate", GST_TYPE_FRACTION, camera->app_fps_n,
+        camera->app_fps_d, NULL);
   } else {
-    GST_DEBUG_OBJECT (camera, "no framerate specified");
-    detect_framerate = TRUE;
-  }
-
-  if (detect_framerate) {
-    GST_DEBUG_OBJECT (camera, "detecting allowed framerate");
     /* Remove old framerate if any */
     if (gst_structure_has_field (st, "framerate")) {
       gst_structure_remove_field (st, "framerate");
     }
-    new_caps = gst_caps_new_full (st, NULL);
+  }
+
+  /* The returned caps take ownership of the structure st */
+  return gst_caps_new_full (st, NULL);
+}
 
+/*
+ * camerabin_setup_src_elements:
+ * @camera: camerabin object
+ *
+ * This function updates camerabin capsfilters according
+ * to fps, resolution and zoom that have been configured
+ * to camerabin.
+ */
+static void
+camerabin_setup_src_elements (GstCameraBin * camera)
+{
+  GstCaps *new_caps;
+
+  /* clear video update status */
+  camera->video_capture_caps_update = FALSE;
+
+  gst_camerabin_monitor_video_source_properties (camera);
+
+  new_caps = camerabin_create_view_finder_caps (camera);
+
+  if (camera->night_mode || camera->app_fps_n <= 0 || camera->app_fps_d <= 0) {
+    if (camera->night_mode) {
+      GST_INFO_OBJECT (camera, "night mode, lowest allowed fps will be forced");
+      camera->pre_night_fps_n = camera->app_fps_n;
+      camera->pre_night_fps_d = camera->app_fps_d;
+    }
+    GST_DEBUG_OBJECT (camera, "detecting allowed framerate");
     /* Set allowed framerate for the resolution */
     gst_camerabin_set_allowed_framerate (camera, new_caps);
   }
-- 
1.7.10.2