[cheese/camerabin2] cheese-camera: Fix recording time reporting



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

    cheese-camera: Fix 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, 29 insertions(+), 30 deletions(-)
---
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index dd6a04e..cfc62f0 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -1763,39 +1763,38 @@ 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;
-
-  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);
+  gboolean ret = FALSE;
+
+  videosink = gst_bin_get_by_name (priv->camerabin, "videobin-filesink");
+  if (videosink)
+    ret = gst_element_query_position (videosink, &format, &curtime);
+  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]