tests/examples/rtp/server-alsasrc-PCMA.c: Add some example code for printing the...
authorWim Taymans <wim.taymans@gmail.com>
Tue, 13 Jan 2009 17:49:07 +0000 (17:49 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Tue, 13 Jan 2009 17:49:07 +0000 (17:49 +0000)
Original commit message from CVS:
* tests/examples/rtp/server-alsasrc-PCMA.c: (print_source_stats),
(print_stats), (main):
Add some example code for printing the RTP manager stats.

ChangeLog
tests/examples/rtp/server-alsasrc-PCMA.c

index afe3214..6701e70 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-01-13  Wim Taymans  <wim.taymans@collabora.co.uk>
+
+       * tests/examples/rtp/server-alsasrc-PCMA.c: (print_source_stats),
+       (print_stats), (main):
+       Add some example code for printing the RTP manager stats.
+
 2009-01-13  Sebastian Dröge  <sebastian.droege@collabora.co.uk>
 
        * gst/audiofx/audiochebband.c: (gst_audio_cheb_band_class_init),
index 3af888a..c237d7e 100755 (executable)
 #define AUDIO_ENC  "alawenc"
 #define AUDIO_PAY  "rtppcmapay"
 
+/* print the stats of a source */
+static void
+print_source_stats (GObject * source)
+{
+  GstStructure *stats;
+  gchar *str;
+
+  /* get the source stats */
+  g_object_get (source, "stats", &stats, NULL);
+
+  /* simply dump the stats structure */
+  str = gst_structure_to_string (stats);
+  g_print ("source stats: %s\n", str);
+
+  gst_structure_free (stats);
+  g_free (str);
+}
+
+/* this function is called every second and dumps the RTP manager stats */
+static gboolean
+print_stats (GstElement * rtpbin)
+{
+  GObject *session;
+  GValueArray *arr;
+  GValue *val;
+  guint i;
+
+  g_print ("***********************************\n");
+
+  /* get session 0 */
+  g_signal_emit_by_name (rtpbin, "get-internal-session", 0, &session);
+
+  /* print all the sources in the session, this includes the internal source */
+  g_object_get (session, "sources", &arr, NULL);
+
+  for (i = 0; i < arr->n_values; i++) {
+    GObject *source;
+
+    val = g_value_array_get_nth (arr, i);
+    source = g_value_get_object (val);
+
+    print_source_stats (source);
+  }
+  g_value_array_free (arr);
+
+  g_object_unref (session);
+
+  return TRUE;
+}
+
 /* build a pipeline equivalent to:
  *
  * gst-launch -v gstrtpbin name=rtpbin \
@@ -157,6 +207,9 @@ main (int argc, char *argv[])
   g_print ("starting sender pipeline\n");
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
 
+  /* print stats every second */
+  g_timeout_add (1000, (GSourceFunc) print_stats, rtpbin);
+
   /* we need to run a GLib main loop to get the messages */
   loop = g_main_loop_new (NULL, FALSE);
   g_main_loop_run (loop);