datetime: change internal implementation to mini object
authorTim-Philipp Müller <tim@centricular.com>
Tue, 3 Jun 2014 22:38:28 +0000 (23:38 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Tue, 3 Jun 2014 22:49:21 +0000 (23:49 +0100)
And move type stuff from GstValue to GstDateTime.

gst/gstdatetime.c
gst/gstdatetime.h
gst/gstvalue.c
gst/gstvalue.h

index 083b5da..94ae262 100644 (file)
@@ -56,12 +56,17 @@ typedef enum
 
 struct _GstDateTime
 {
+  GstMiniObject mini_object;
+
   GDateTime *datetime;
 
   GstDateTimeFields fields;
-  volatile gint ref_count;
 };
 
+GST_DEFINE_MINI_OBJECT_TYPE (GstDateTime, gst_date_time);
+
+static void gst_date_time_free (GstDateTime * datetime);
+
 /**
  * gst_date_time_new_from_g_date_time:
  * @dt: (transfer full): the #GDateTime. The new #GstDateTime takes ownership.
@@ -81,9 +86,12 @@ gst_date_time_new_from_g_date_time (GDateTime * dt)
     return NULL;
 
   gst_dt = g_slice_new (GstDateTime);
+
+  gst_mini_object_init (GST_MINI_OBJECT_CAST (gst_dt), 0, GST_TYPE_DATE_TIME,
+      NULL, NULL, (GstMiniObjectFreeFunction) gst_date_time_free);
+
   gst_dt->datetime = dt;
   gst_dt->fields = GST_DATE_TIME_FIELDS_YMD_HMS;
-  gst_dt->ref_count = 1;
   return gst_dt;
 }
 
@@ -868,7 +876,6 @@ ymd:
   return gst_date_time_new_ymd (year, month, day);
 }
 
-
 static void
 gst_date_time_free (GstDateTime * datetime)
 {
@@ -887,10 +894,7 @@ gst_date_time_free (GstDateTime * datetime)
 GstDateTime *
 gst_date_time_ref (GstDateTime * datetime)
 {
-  g_return_val_if_fail (datetime != NULL, NULL);
-  g_return_val_if_fail (datetime->ref_count > 0, NULL);
-  g_atomic_int_inc (&datetime->ref_count);
-  return datetime;
+  return (GstDateTime *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (datetime));
 }
 
 /**
@@ -903,9 +907,5 @@ gst_date_time_ref (GstDateTime * datetime)
 void
 gst_date_time_unref (GstDateTime * datetime)
 {
-  g_return_if_fail (datetime != NULL);
-  g_return_if_fail (datetime->ref_count > 0);
-
-  if (g_atomic_int_dec_and_test (&datetime->ref_count))
-    gst_date_time_free (datetime);
+  gst_mini_object_unref (GST_MINI_OBJECT_CAST (datetime));
 }
index e0d3c5b..879ab4a 100644 (file)
@@ -36,6 +36,18 @@ G_BEGIN_DECLS
  */
 typedef struct _GstDateTime GstDateTime;
 
+/**
+ * GST_TYPE_DATE_TIME:
+ *
+ * a boxed #GValue type for #GstDateTime that represents a date and time.
+ *
+ * Returns: the #GType of GstDateTime
+ */
+
+#define GST_TYPE_DATE_TIME gst_date_time_get_type()
+
+GType           gst_date_time_get_type (void);
+
 /* query which fields are set */
 
 gboolean        gst_date_time_has_year                (const GstDateTime * datetime);
index a38cce0..e4932bc 100644 (file)
@@ -6029,9 +6029,6 @@ static const GTypeValueTable _gst_fraction_value_table = {
 
 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
 
-G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
-    (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
-
 static const GTypeValueTable _gst_bitmask_value_table = {
   gst_value_init_bitmask,
   NULL,
index bdd0bce..52baef5 100644 (file)
@@ -273,16 +273,6 @@ G_BEGIN_DECLS
 #define GST_TYPE_FRACTION                gst_fraction_get_type ()
 
 /**
- * GST_TYPE_DATE_TIME:
- *
- * a boxed #GValue type for #GstDateTime that represents a date and time.
- *
- * Returns: the #GType of GstDateTime
- */
-
-#define GST_TYPE_DATE_TIME               gst_date_time_get_type ()
-
-/**
  * GST_TYPE_BITMASK:
  *
  * a #GValue type that represents a 64-bit bitmask.
@@ -405,8 +395,6 @@ GType gst_bitmask_get_type (void);
 GType gst_g_thread_get_type (void);
 #endif
 
-GType gst_date_time_get_type (void);
-
 void            gst_value_register              (const GstValueTable   *table);
 void            gst_value_init_and_copy         (GValue                *dest,
                                                  const GValue          *src);