[cheese] Fix CheeseCamera recording time reporting



commit d9e0c8fffc3a62746b21650b6fcc5cc6a49d2ca7
Author: Thiago Santos <thiago sousa santos collabora com>
Date:   Mon Apr 30 09:26:41 2012 -0300

    Fix CheeseCamera recording time reporting
    
    Camerabin2 maintains its pipeline clock continuously running, this makes
    the time reporting for video recording actually report the time since
    camerabin2 was initialized.
    
    This patch fixes it by querying the video filesink for the correct
    recording time.

 libcheese/cheese-camera.c |   59 +++++++++++++++++++++++----------------------
 1 files changed, 30 insertions(+), 29 deletions(-)
---
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index 998bab0..714a1d5 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -1768,39 +1768,40 @@ cheese_camera_get_recorded_time (CheeseCamera *camera)
   g_return_val_if_fail (CHEESE_IS_CAMERA (camera), NULL);
 
   CheeseCameraPrivate *priv = camera->priv;
+  GstFormat format = GST_FORMAT_TIME;
+  gint64 curtime;
+  GstElement *videosink;
   const gint TUNIT_60 = 60;
-  GstClock *clock;
-  GstClockTime base_time;
-  GstClockTime clock_time;
-  GstClockTimeDiff time_diff;
   gint total_time;
   gint hours;
   gint minutes;
   gint seconds;
+  gboolean ret = FALSE;
 
-  base_time  = gst_element_get_base_time (priv->camerabin);
-  clock = gst_element_get_clock (priv->camerabin);
-  clock_time = gst_clock_get_time (clock);
-  gst_object_unref (clock);
-  /* In order to calculate the running time of the stream,
-   * it is necessary to substract the base_time from the
-   * clock_time. The result is expressed in nanoseconds.
-   * */
-  time_diff = GST_CLOCK_DIFF (base_time, clock_time);
-
-  // Substract seconds, minutes and hours.
-  total_time = GST_TIME_AS_SECONDS (time_diff);
-  seconds = total_time % TUNIT_60;
-  total_time = total_time - seconds;
-  minutes = (total_time % (TUNIT_60 * TUNIT_60)) / TUNIT_60;
-  total_time = total_time - (minutes * TUNIT_60);
-  hours = total_time / (TUNIT_60 * TUNIT_60);
-
-  /* Translators: This is a time format, like "09:05:02" for 9
-   * hours, 5 minutes, and 2 seconds. You may change ":" to
-   * the separator that your locale uses or use "%Id" instead
-   * of "%d" if your locale uses localized digits.
-   */
-  return g_strdup_printf (C_("time format", "%02i:%02i:%02i"),
-                          hours, minutes, seconds);
+  videosink = gst_bin_get_by_name (priv->camerabin, "videobin-filesink");
+  if (videosink) {
+    ret = gst_element_query_position (videosink, &format, &curtime);
+    gst_object_unref (videosink);
+  }
+  if (ret) {
+
+    // Substract seconds, minutes and hours.
+    total_time = GST_TIME_AS_SECONDS (curtime);
+    seconds = total_time % TUNIT_60;
+    total_time = total_time - seconds;
+    minutes = (total_time % (TUNIT_60 * TUNIT_60)) / TUNIT_60;
+    total_time = total_time - (minutes * TUNIT_60);
+    hours = total_time / (TUNIT_60 * TUNIT_60);
+
+    /* Translators: This is a time format, like "09:05:02" for 9
+     * hours, 5 minutes, and 2 seconds. You may change ":" to
+     * the separator that your locale uses or use "%Id" instead
+     * of "%d" if your locale uses localized digits.
+     */
+    return g_strdup_printf (C_("time format", "%02i:%02i:%02i"),
+                            hours, minutes, seconds);
+  } else {
+    GST_WARNING ("Failed to get time from video filesink from camerabin2");
+    return "";
+  }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]