[farsight2/master] Complete unit RawUdp transmitter unit test for local interface discovery mode

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:19:32 PST 2008


---
 tests/check/transmitter/generic.c |   54 ++++++++++++++++++---
 tests/check/transmitter/generic.h |    5 ++-
 tests/check/transmitter/rawudp.c  |   96 ++++++++++++++++++++++++++++++-------
 3 files changed, 129 insertions(+), 26 deletions(-)

diff --git a/tests/check/transmitter/generic.c b/tests/check/transmitter/generic.c
index ba55e20..4bbaace 100644
--- a/tests/check/transmitter/generic.c
+++ b/tests/check/transmitter/generic.c
@@ -46,33 +46,73 @@ _stream_transmitter_error (FsStreamTransmitter *streamtransmitter,
     errorno, error_msg, debug_msg);
 }
 
+void
+setup_fakesrc (FsTransmitter *trans, GstElement *pipeline, guint component_id)
+{
+  GstElement *src;
+  GstElement *trans_sink;
+
+  src = gst_element_factory_make ("fakesrc", NULL);
+  g_object_set (src, "num-buffers", 20, "sizetype", 2, "sizemax",
+    component_id * 10, "is-live", TRUE, NULL);
+
+  fail_unless (gst_bin_add (GST_BIN (pipeline), src),
+    "Could not add the fakesrc");
+
+  g_object_get (trans, "gst-sink", &trans_sink, NULL);
+
+  fail_unless (gst_element_link_pads (src, "src", trans_sink,
+      (component_id == 1) ? "sink": "rtcpsink"),
+    "Could not link the fakesrc to %s",
+    (component_id == 1) ? "sink": "rtcpsink");
+
+  fail_if (gst_element_set_state (src, GST_STATE_PLAYING) ==
+    GST_STATE_CHANGE_FAILURE, "Could not set the fakesrc to playing");
+
+  gst_object_unref (trans_sink);
+}
+
 GstElement *
-setup_pipeline (FsTransmitter *trans, GstElement **fakesrc)
+setup_pipeline (FsTransmitter *trans, GCallback cb)
 {
   GstElement *pipeline;
-  GstElement *fakesink;
+  GstElement *rtpfakesink, *rtcpfakesink;
   GstElement *trans_sink, *trans_src;
 
   fail_unless (g_signal_connect (trans, "error",
       G_CALLBACK (_transmitter_error), NULL), "Could not connect signal");
 
   pipeline = gst_pipeline_new ("pipeline");
-  *fakesrc = gst_element_factory_make ("fakesrc", "fakesrc");
-  fakesink = gst_element_factory_make ("fakesink", "fakesink");
+  rtpfakesink = gst_element_factory_make ("fakesink", "rtpfakesink");
+  rtcpfakesink = gst_element_factory_make ("fakesink", "rtcpfakesink");
 
   g_object_get (trans, "gst-sink", &trans_sink, "gst-src", &trans_src, NULL);
 
+
+  g_object_set (rtpfakesink, "signal-handoffs", TRUE, "sync", FALSE, NULL);
+  g_object_set (rtcpfakesink, "signal-handoffs", TRUE, "sync", FALSE,
+    "async", FALSE, NULL);
+
+  if (cb) {
+    g_signal_connect (rtpfakesink, "handoff", cb, GINT_TO_POINTER (1));
+    g_signal_connect (rtcpfakesink, "handoff", cb, GINT_TO_POINTER (2));
+  }
+
   fail_if (trans_sink == NULL, "No transmitter sink");
   fail_if (trans_src == NULL, "No transmitter src");
 
-  gst_bin_add_many (GST_BIN (pipeline), fakesink, trans_sink, trans_src, NULL);
+  gst_bin_add_many (GST_BIN (pipeline), rtpfakesink, rtcpfakesink,
+    trans_sink, trans_src, NULL);
 
-  fail_unless (gst_element_link (trans_src, fakesink),
+  fail_unless (gst_element_link_pads (trans_src, "src",
+      rtpfakesink, "sink"),
+    "Coult not link transmitter src and fakesink");
+  fail_unless (gst_element_link_pads (trans_src, "rtcpsrc",
+      rtcpfakesink, "sink"),
     "Coult not link transmitter src and fakesink");
 
   g_object_unref (trans_src);
   g_object_unref (trans_sink);
 
-
   return pipeline;
 }
diff --git a/tests/check/transmitter/generic.h b/tests/check/transmitter/generic.h
index ddf22a2..27d3999 100644
--- a/tests/check/transmitter/generic.h
+++ b/tests/check/transmitter/generic.h
@@ -26,7 +26,10 @@
 #ifndef __GENERIC_H__
 #define  __GENERIC_H__
 
-GstElement * setup_pipeline (FsTransmitter *trans, GstElement **fakesrc);
+GstElement *setup_pipeline (FsTransmitter *trans, GCallback cb);
+
+void setup_fakesrc (FsTransmitter *trans, GstElement *pipeline,
+  guint component_id);
 
 void _stream_transmitter_error (FsStreamTransmitter *streamtransmitter,
   gint errorno, gchar *error_msg, gchar *debug_msg, gpointer user_data);
diff --git a/tests/check/transmitter/rawudp.c b/tests/check/transmitter/rawudp.c
index 9ac8f6f..f666796 100644
--- a/tests/check/transmitter/rawudp.c
+++ b/tests/check/transmitter/rawudp.c
@@ -34,23 +34,21 @@ GST_START_TEST (test_rawudptransmitter_new)
   GError *error = NULL;
   FsTransmitter *trans;
   GstElement *pipeline;
-  GstElement *fakesrc;
   GstElement *trans_sink, *trans_src;
 
   trans = fs_transmitter_new ("rawudp", &error);
 
   if (error) {
-    fail("Error creating transmitter: %s", error->message);
+    fail("Error creating transmitter: (%s:%d) %s",
+      g_quark_to_string (error->domain), error->code, error->message);
   }
 
   fail_if (trans == NULL, "No transmitter create, yet error is still NULL");
 
-  pipeline = setup_pipeline (trans, &fakesrc);
+  pipeline = setup_pipeline (trans, NULL);
 
   g_object_get (trans, "gst-sink", &trans_sink, "gst-src", &trans_src, NULL);
 
-  gst_object_unref (fakesrc);
-
   g_object_unref (trans);
 
   gst_object_unref (pipeline);
@@ -65,7 +63,7 @@ _new_local_candidate (FsStreamTransmitter *st, FsCandidate *candidate,
   gpointer user_data)
 {
   gboolean has_stun = GPOINTER_TO_INT (user_data);
-  GError *error;
+  GError *error = NULL;
   gboolean ret;
 
   fail_if (candidate == NULL, "Passed NULL candidate");
@@ -79,7 +77,7 @@ _new_local_candidate (FsStreamTransmitter *st, FsCandidate *candidate,
       "Proto subtype %s does not match component %d", candidate->proto_subtype,
       candidate->component_id);
   else if (candidate->component_id == FS_COMPONENT_RTCP)
-    fail_unless (strcmp (candidate->proto_subtype, "RTP") == 0,
+    fail_unless (strcmp (candidate->proto_subtype, "RTCP") == 0,
       "Proto subtype %s does not match component %d", candidate->proto_subtype,
       candidate->component_id);
   else
@@ -94,10 +92,14 @@ _new_local_candidate (FsStreamTransmitter *st, FsCandidate *candidate,
 
   candidates[candidate->component_id-1] = 1;
 
+  g_debug ("New local candidate %s:%d of type %d for component %d",
+    candidate->ip, candidate->port, candidate->type, candidate->component_id);
+
   ret = fs_stream_transmitter_add_remote_candidate (st, candidate, &error);
 
   if (error)
-    fail ("Error while adding candidate: %s", error->message);
+    fail ("Error while adding candidate: (%s:%d) %s",
+      g_quark_to_string (error->domain), error->code, error->message);
 
   fail_unless(ret == TRUE, "No detailed error from add_remote_candidate");
 
@@ -109,9 +111,12 @@ _local_candidates_prepared (FsStreamTransmitter *st, gpointer user_data)
   fail_if (candidates[0] == 0, "candidates-prepared with no RTP candidate");
   fail_if (candidates[1] == 0, "candidates-prepared with no RTCP candidate");
 
-  fs_stream_transmitter_remote_candidates_added (st);
+  g_debug ("Local Candidates Prepared");
 }
 
+
+GstElement *pipeline = NULL;
+
 static void
 _new_active_candidate_pair (FsStreamTransmitter *st, FsCandidate *local,
   FsCandidate *remote, gpointer user_data)
@@ -122,36 +127,79 @@ _new_active_candidate_pair (FsStreamTransmitter *st, FsCandidate *local,
   fail_unless (local->component_id == remote->component_id,
     "Local and remote candidates dont have the same component id");
 
+  g_debug ("New active candidate pair for component %d", local->component_id);
+
+  setup_fakesrc (user_data, pipeline, local->component_id);
+}
+
+static gboolean
+_start_pipeline (gpointer user_data)
+{
+  GstElement *pipeline = user_data;
+
+  g_debug ("Starting pipeline");
+
+  fail_if (gst_element_set_state (pipeline, GST_STATE_PLAYING) ==
+    GST_STATE_CHANGE_FAILURE, "Could not set the pipeline to playing");
+
+  return FALSE;
 }
 
+gint buffer_count[2] = {0,0};
+
+GMainLoop *loop = NULL;
+
+static void
+_handoff_handler (GstElement *element, GstBuffer *buffer, GstPad *pad,
+  gpointer user_data)
+{
+  gint component_id = GPOINTER_TO_INT (user_data);
+
+  g_debug ("comp: %d buffer %d size: %u", component_id,
+    buffer_count[component_id-1], GST_BUFFER_SIZE (buffer));
+
+  fail_unless (GST_BUFFER_SIZE (buffer) == component_id * 10,
+    "Buffer is size %d but component_id is %d", GST_BUFFER_SIZE (buffer),
+    component_id);
+
+  buffer_count[component_id-1]++;
+
+  fail_if (buffer_count[component_id-1] > 20,
+    "Too many buffers %d > 20 for component",
+    buffer_count[component_id-1], component_id);
+
+  if (buffer_count[0] == 20 && buffer_count[1] == 20) {
+    /* TEST OVER */
+    g_main_loop_quit (loop);
+  }
+}
+
+
 GST_START_TEST (test_rawudptransmitter_run_nostun)
 {
   GError *error = NULL;
   FsTransmitter *trans;
   FsStreamTransmitter *st;
-  GstElement *pipeline;
-  GstElement *fakesrc;
   GstElement *trans_sink, *trans_src;
 
   const gint N_PARAMS = 0;
   GParameter params[N_PARAMS];
 
+  loop = g_main_loop_new (NULL, FALSE);
   trans = fs_transmitter_new ("rawudp", &error);
 
   if (error) {
-    fail("Error creating transmitter: %s", error->message);
+    fail("Error creating transmitter: (%s:%d) %s",
+      g_quark_to_string (error->domain), error->code, error->message);
   }
 
   fail_if (trans == NULL, "No transmitter create, yet error is still NULL");
 
-  pipeline = setup_pipeline (trans, &fakesrc);
+  pipeline = setup_pipeline (trans, G_CALLBACK (_handoff_handler));
 
   g_object_get (trans, "gst-sink", &trans_sink, "gst-src", &trans_src, NULL);
 
 
-  fail_if (gst_element_set_state (pipeline, GST_STATE_PLAYING) ==
-    GST_STATE_CHANGE_FAILURE, "Could not set the pipeline to playing");
-
   /*
   params[0].name = "stun-ip";
   g_value_set_static_string (params[0].value, "192.245.12.229");
@@ -162,11 +210,14 @@ GST_START_TEST (test_rawudptransmitter_run_nostun)
     &error);
 
   if (error) {
-    fail("Error creating stream transmitter: %s", error->message);
+    fail("Error creating stream transmitter: (%s:%d) %s",
+      g_quark_to_string (error->domain), error->code, error->message);
   }
 
   fail_if (st == NULL, "No stream transmitter created, yet error is NULL");
 
+  g_debug ("I am : %p", st);
+
   fail_unless (g_signal_connect (st, "new-local-candidate",
       G_CALLBACK (_new_local_candidate), GINT_TO_POINTER (0)),
     "Coult not connect new-local-candidate signal");
@@ -174,18 +225,25 @@ GST_START_TEST (test_rawudptransmitter_run_nostun)
       G_CALLBACK (_local_candidates_prepared), NULL),
     "Coult not connect local-candidates-prepared signal");
   fail_unless (g_signal_connect (st, "new-active-candidate-pair",
-      G_CALLBACK (_new_active_candidate_pair), NULL),
+      G_CALLBACK (_new_active_candidate_pair), trans),
     "Coult not connect new-active-candidate-pair signal");
   fail_unless (g_signal_connect (st, "error",
       G_CALLBACK (_stream_transmitter_error), NULL),
     "Could not connect error signal");
 
+  g_idle_add (_start_pipeline, pipeline);
+
+  g_main_run (loop);
+
+
   g_object_unref (st);
 
   g_object_unref (trans);
 
   gst_object_unref (pipeline);
 
+  g_main_loop_unref (loop);
+
 }
 GST_END_TEST;
 
@@ -199,6 +257,8 @@ rawudptransmitter_suite (void)
 
   suite_add_tcase (s, tc_chain);
 
+  tcase_set_timeout (tc_chain, 5);
+
   tcase_add_test (tc_chain, test_rawudptransmitter_new);
   tcase_add_test (tc_chain, test_rawudptransmitter_run_nostun);
 
-- 
1.5.6.5




More information about the farsight-commits mailing list