testclock: add clock-type property
authorAlex Ashley <bugzilla@ashley-family.net>
Thu, 21 Apr 2016 13:45:39 +0000 (14:45 +0100)
committerThiago Santos <thiagoss@osg.samsung.com>
Thu, 21 Apr 2016 18:21:53 +0000 (15:21 -0300)
To allow the GstTestClock to be used as a GstSystemClock, it is
useful to implement the clock-type property that GstSystemClock
provides. This allows GstTestClock to be used as the system clock
with code that expects a GstSystemClock.

    https://bugzilla.gnome.org/show_bug.cgi?id=762147

libs/gst/check/gsttestclock.c

index c0961e3..513667f 100644 (file)
 enum
 {
   PROP_0,
-  PROP_START_TIME
+  PROP_START_TIME,
+  PROP_CLOCK_TYPE
 };
 
 typedef struct _GstClockEntryContext GstClockEntryContext;
@@ -196,6 +197,7 @@ struct _GstClockEntryContext
 
 struct _GstTestClockPrivate
 {
+  GstClockType clock_type;
   GstClockTime start_time;
   GstClockTime internal_time;
   GList *entry_contexts;
@@ -203,6 +205,8 @@ struct _GstTestClockPrivate
   GCond entry_processed_cond;
 };
 
+#define DEFAULT_CLOCK_TYPE GST_CLOCK_TYPE_MONOTONIC
+
 #define GST_TEST_CLOCK_GET_PRIVATE(obj) ((GST_TEST_CLOCK_CAST (obj))->priv)
 
 GST_DEBUG_CATEGORY_STATIC (test_clock_debug);
@@ -287,6 +291,13 @@ gst_test_clock_class_init (GstTestClockClass * klass)
       "Start Time of the Clock", 0, G_MAXUINT64, 0,
       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
   g_object_class_install_property (gobject_class, PROP_START_TIME, pspec);
+
+  g_object_class_install_property (gobject_class, PROP_CLOCK_TYPE,
+      g_param_spec_enum ("clock-type", "Clock type",
+          "The kind of clock implementation to be reported by this clock",
+          GST_TYPE_CLOCK_TYPE, DEFAULT_CLOCK_TYPE,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
 }
 
 static void
@@ -301,6 +312,7 @@ gst_test_clock_init (GstTestClock * test_clock)
 
   g_cond_init (&priv->entry_added_cond);
   g_cond_init (&priv->entry_processed_cond);
+  priv->clock_type = DEFAULT_CLOCK_TYPE;
 
   GST_OBJECT_FLAG_SET (test_clock,
       GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC |
@@ -361,6 +373,9 @@ gst_test_clock_get_property (GObject * object, guint property_id,
     case PROP_START_TIME:
       g_value_set_uint64 (value, priv->start_time);
       break;
+    case PROP_CLOCK_TYPE:
+      g_value_set_enum (value, priv->clock_type);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -381,6 +396,11 @@ gst_test_clock_set_property (GObject * object, guint property_id,
           "test clock start time initialized at %" GST_TIME_FORMAT,
           GST_TIME_ARGS (priv->start_time));
       break;
+    case PROP_CLOCK_TYPE:
+      priv->clock_type = (GstClockType) g_value_get_enum (value);
+      GST_CAT_DEBUG (GST_CAT_TEST_CLOCK, "clock-type set to %d",
+          priv->clock_type);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;