Some small cleanups. added a drop_probaility arg to identity, so it occasionally...
authorWim Taymans <wim.taymans@gmail.com>
Tue, 1 Jan 2002 13:46:04 +0000 (13:46 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Tue, 1 Jan 2002 13:46:04 +0000 (13:46 +0000)
Original commit message from CVS:
Some small cleanups.
added a drop_probaility arg to identity, so it occasionally can drop buffers
to simulate network packet loss

gst/elements/gstaggregator.c
gst/elements/gstidentity.c
gst/elements/gstidentity.h
plugins/elements/gstaggregator.c
plugins/elements/gstidentity.c
plugins/elements/gstidentity.h

index e6f2337..398c954 100644 (file)
@@ -257,7 +257,7 @@ static void
 gst_aggregator_push (GstAggregator *aggregator, GstPad *pad, GstBuffer *buf, guchar *debug) 
 {
   if (!aggregator->silent)
-    g_print("aggregator: %10.10s ******* (%s:%s)a (%d bytes, %llu) \n",
+    gst_element_info (GST_ELEMENT (aggregator), "%10.10s ******* (%s:%s)a (%d bytes, %llu) \n",
             debug, GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
 
   gst_pad_push (aggregator->srcpad, buf);
index 0405446..1da9ab2 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 
+#include <stdlib.h>
 #include <gstidentity.h>
 
 
@@ -47,6 +48,7 @@ enum {
   ARG_SLEEP_TIME,
   ARG_DUPLICATE,
   ARG_ERROR_AFTER,
+  ARG_DROP_PROBABILITY,
   ARG_SILENT,
 };
 
@@ -104,6 +106,9 @@ gst_identity_class_init (GstIdentityClass *klass)
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ERROR_AFTER,
     g_param_spec_int ("error_after", "Error After", "Error after N buffers",
                        G_MININT, G_MAXINT, -1, G_PARAM_READWRITE));
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DROP_PROBABILITY,
+    g_param_spec_float ("drop_probability", "Drop Probability", "The Probability a buffer is dropped",
+                        0.0, 1.0, 0.0, G_PARAM_READWRITE));
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
     g_param_spec_boolean ("silent", "silent", "silent",
                           TRUE,G_PARAM_READWRITE)); 
@@ -165,6 +170,7 @@ gst_identity_init (GstIdentity *identity)
   identity->sleep_time = 0;
   identity->duplicate = 1;
   identity->error_after = -1;
+  identity->drop_probability = 0.0;
   identity->silent = FALSE;
 }
 
@@ -189,9 +195,18 @@ gst_identity_chain (GstPad *pad, GstBuffer *buf)
     }
   }
 
-  for (i=identity->duplicate; i; i--) {
+  if (identity->drop_probability > 0.0) {
+    if ((gfloat)(1.0*rand()/(RAND_MAX)) < identity->drop_probability) {
+      gst_element_info (GST_ELEMENT (identity), "dropping   ******* (%s:%s)i (%d bytes, %llu)",
+             GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
+      gst_buffer_unref (buf);
+      return;
+    }
+  }
+
+  for (i = identity->duplicate; i; i--) {
     if (!identity->silent)
-      g_print("identity: chain   ******* (%s:%s)i (%d bytes, %llu) \n",
+      gst_element_info (GST_ELEMENT (identity), "chain   ******* (%s:%s)i (%d bytes, %llu)",
              GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
   
     g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
@@ -224,31 +239,7 @@ gst_identity_loop (GstElement *element)
     gst_pad_event_default (identity->sinkpad, GST_EVENT (buf));
   }
 
-  if (identity->error_after >= 0) {
-    identity->error_after--;
-    if (identity->error_after == 0) {
-      gst_buffer_unref (buf);
-      gst_element_error (element, "errored after iterations as requested");
-      return;
-    }
-  }
-    
-  for (i=identity->duplicate; i; i--) {
-    if (!identity->silent)
-      g_print("identity: loop    ******* (%s:%s)i (%d bytes, %llu) \n",
-                     GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
-
-    g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
-                              buf);
-
-    if (i>1) 
-      gst_buffer_ref (buf);
-
-    gst_pad_push (identity->srcpad, buf);
-
-    if (identity->sleep_time)
-      usleep (identity->sleep_time);
-  }
+  gst_identity_chain (identity->sinkpad, buf);
 }
 
 static void 
@@ -285,6 +276,9 @@ gst_identity_set_property (GObject *object, guint prop_id, const GValue *value,
     case ARG_ERROR_AFTER:
       identity->error_after = g_value_get_uint (value);
       break;
+    case ARG_DROP_PROBABILITY:
+      identity->drop_probability = g_value_get_float (value);
+      break;
     default:
       break;
   }
@@ -311,6 +305,9 @@ static void gst_identity_get_property(GObject *object, guint prop_id, GValue *va
     case ARG_ERROR_AFTER:
       g_value_set_uint (value, identity->error_after);
       break;
+    case ARG_DROP_PROBABILITY:
+      g_value_set_float (value, identity->drop_probability);
+      break;
     case ARG_SILENT:
       g_value_set_boolean (value, identity->silent);
       break;
index 5b21c95..488ec3f 100644 (file)
@@ -60,6 +60,7 @@ struct _GstIdentity {
   gboolean loop_based;
   guint duplicate;
   gint error_after;
+  gfloat drop_probability;
   guint sleep_time;
   gboolean silent;
 };
index e6f2337..398c954 100644 (file)
@@ -257,7 +257,7 @@ static void
 gst_aggregator_push (GstAggregator *aggregator, GstPad *pad, GstBuffer *buf, guchar *debug) 
 {
   if (!aggregator->silent)
-    g_print("aggregator: %10.10s ******* (%s:%s)a (%d bytes, %llu) \n",
+    gst_element_info (GST_ELEMENT (aggregator), "%10.10s ******* (%s:%s)a (%d bytes, %llu) \n",
             debug, GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
 
   gst_pad_push (aggregator->srcpad, buf);
index 0405446..1da9ab2 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 
+#include <stdlib.h>
 #include <gstidentity.h>
 
 
@@ -47,6 +48,7 @@ enum {
   ARG_SLEEP_TIME,
   ARG_DUPLICATE,
   ARG_ERROR_AFTER,
+  ARG_DROP_PROBABILITY,
   ARG_SILENT,
 };
 
@@ -104,6 +106,9 @@ gst_identity_class_init (GstIdentityClass *klass)
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ERROR_AFTER,
     g_param_spec_int ("error_after", "Error After", "Error after N buffers",
                        G_MININT, G_MAXINT, -1, G_PARAM_READWRITE));
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DROP_PROBABILITY,
+    g_param_spec_float ("drop_probability", "Drop Probability", "The Probability a buffer is dropped",
+                        0.0, 1.0, 0.0, G_PARAM_READWRITE));
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
     g_param_spec_boolean ("silent", "silent", "silent",
                           TRUE,G_PARAM_READWRITE)); 
@@ -165,6 +170,7 @@ gst_identity_init (GstIdentity *identity)
   identity->sleep_time = 0;
   identity->duplicate = 1;
   identity->error_after = -1;
+  identity->drop_probability = 0.0;
   identity->silent = FALSE;
 }
 
@@ -189,9 +195,18 @@ gst_identity_chain (GstPad *pad, GstBuffer *buf)
     }
   }
 
-  for (i=identity->duplicate; i; i--) {
+  if (identity->drop_probability > 0.0) {
+    if ((gfloat)(1.0*rand()/(RAND_MAX)) < identity->drop_probability) {
+      gst_element_info (GST_ELEMENT (identity), "dropping   ******* (%s:%s)i (%d bytes, %llu)",
+             GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
+      gst_buffer_unref (buf);
+      return;
+    }
+  }
+
+  for (i = identity->duplicate; i; i--) {
     if (!identity->silent)
-      g_print("identity: chain   ******* (%s:%s)i (%d bytes, %llu) \n",
+      gst_element_info (GST_ELEMENT (identity), "chain   ******* (%s:%s)i (%d bytes, %llu)",
              GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
   
     g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
@@ -224,31 +239,7 @@ gst_identity_loop (GstElement *element)
     gst_pad_event_default (identity->sinkpad, GST_EVENT (buf));
   }
 
-  if (identity->error_after >= 0) {
-    identity->error_after--;
-    if (identity->error_after == 0) {
-      gst_buffer_unref (buf);
-      gst_element_error (element, "errored after iterations as requested");
-      return;
-    }
-  }
-    
-  for (i=identity->duplicate; i; i--) {
-    if (!identity->silent)
-      g_print("identity: loop    ******* (%s:%s)i (%d bytes, %llu) \n",
-                     GST_DEBUG_PAD_NAME (identity->sinkpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
-
-    g_signal_emit (G_OBJECT (identity), gst_identity_signals[SIGNAL_HANDOFF], 0,
-                              buf);
-
-    if (i>1) 
-      gst_buffer_ref (buf);
-
-    gst_pad_push (identity->srcpad, buf);
-
-    if (identity->sleep_time)
-      usleep (identity->sleep_time);
-  }
+  gst_identity_chain (identity->sinkpad, buf);
 }
 
 static void 
@@ -285,6 +276,9 @@ gst_identity_set_property (GObject *object, guint prop_id, const GValue *value,
     case ARG_ERROR_AFTER:
       identity->error_after = g_value_get_uint (value);
       break;
+    case ARG_DROP_PROBABILITY:
+      identity->drop_probability = g_value_get_float (value);
+      break;
     default:
       break;
   }
@@ -311,6 +305,9 @@ static void gst_identity_get_property(GObject *object, guint prop_id, GValue *va
     case ARG_ERROR_AFTER:
       g_value_set_uint (value, identity->error_after);
       break;
+    case ARG_DROP_PROBABILITY:
+      g_value_set_float (value, identity->drop_probability);
+      break;
     case ARG_SILENT:
       g_value_set_boolean (value, identity->silent);
       break;
index 5b21c95..488ec3f 100644 (file)
@@ -60,6 +60,7 @@ struct _GstIdentity {
   gboolean loop_based;
   guint duplicate;
   gint error_after;
+  gfloat drop_probability;
   guint sleep_time;
   gboolean silent;
 };