Do rate control, skip frames when too old.
authorWim Taymans <wim.taymans@gmail.com>
Tue, 11 Feb 2003 21:31:28 +0000 (21:31 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Tue, 11 Feb 2003 21:31:28 +0000 (21:31 +0000)
Original commit message from CVS:
Do rate control, skip frames when too old.

gst/videotestsrc/gstvideotestsrc.c
gst/videotestsrc/gstvideotestsrc.h

index 6b4352f997d0f92d708058bab5bfdd887a40d388..a2acaa6d96fa6456b9b17ba52ffe5d82a2dbc8a3 100644 (file)
@@ -90,6 +90,7 @@ GST_PAD_TEMPLATE_FACTORY (videotestsrc_src_template_factory,
 static void gst_videotestsrc_class_init (GstVideotestsrcClass * klass);
 static void gst_videotestsrc_init (GstVideotestsrc * videotestsrc);
 static GstElementStateReturn gst_videotestsrc_change_state (GstElement * element);
+static void gst_videotestsrc_set_clock (GstElement *element, GstClock *clock);
 
 static void gst_videotestsrc_set_property (GObject * object, guint prop_id,
                                           const GValue * value, GParamSpec * pspec);
@@ -160,6 +161,17 @@ gst_videotestsrc_class_init (GstVideotestsrcClass * klass)
   gobject_class->get_property = gst_videotestsrc_get_property;
 
   gstelement_class->change_state = gst_videotestsrc_change_state;
+  gstelement_class->set_clock    = gst_videotestsrc_set_clock;
+}
+
+static void
+gst_videotestsrc_set_clock (GstElement *element, GstClock *clock)
+{
+  GstVideotestsrc *v;
+
+  v = GST_VIDEOTESTSRC (element);
+
+  gst_object_replace ((GstObject **)&v->clock, (GstObject *)clock);
 }
 
 static GstPadLinkReturn
@@ -302,6 +314,7 @@ gst_videotestsrc_get (GstPad * pad)
   GstVideotestsrc *videotestsrc;
   gulong newsize;
   GstBuffer *buf;
+  GstClockTimeDiff jitter = 0;
 
   GST_DEBUG (0, "gst_videotestsrc_get");
 
@@ -325,11 +338,22 @@ gst_videotestsrc_get (GstPad * pad)
   }
   g_return_val_if_fail (GST_BUFFER_DATA (buf) != NULL, NULL);
 
-  videotestsrc->timestamp += videotestsrc->interval;
-  GST_BUFFER_TIMESTAMP (buf) = videotestsrc->timestamp;
-
   videotestsrc->make_image (videotestsrc, (void *) GST_BUFFER_DATA (buf),
                            videotestsrc->width, videotestsrc->height);
+  
+  do {
+    GstClockID id;
+
+    videotestsrc->timestamp += videotestsrc->interval;
+    GST_BUFFER_TIMESTAMP (buf) = videotestsrc->timestamp;
+
+    if (videotestsrc->clock) {
+      id = gst_clock_new_single_shot_id (videotestsrc->clock, GST_BUFFER_TIMESTAMP (buf));
+      gst_element_clock_wait (GST_ELEMENT (videotestsrc), id, &jitter);
+      gst_clock_id_free (id);
+    }
+  }
+  while (jitter > 100 * GST_MSECOND);
 
   return buf;
 }
index 5b2f8d2f5266bb3cf6e4a1db6da231202ee88058..5943331c3398e7f797ac8b3954cb30282d0a1e4a 100644 (file)
@@ -65,6 +65,7 @@ struct _GstVideotestsrc {
   gint64 interval;
   gint bpp;
   int rate;
+  GstClock *clock;
 
   GstBufferPool *pool;