[farsight2/master] Almost working nice test
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:26:20 PST 2008
---
tests/check/transmitter/nice.c | 157 +++++++++++++++++++++++++++++++---------
1 files changed, 123 insertions(+), 34 deletions(-)
diff --git a/tests/check/transmitter/nice.c b/tests/check/transmitter/nice.c
index d6a8915..f2741d3 100644
--- a/tests/check/transmitter/nice.c
+++ b/tests/check/transmitter/nice.c
@@ -30,14 +30,10 @@
#include "generic.h"
-gint buffer_count[2] = {0, 0};
+gint buffer_count[2][2] = {{0,0}, {0,0}};
GMainLoop *loop = NULL;
-gint candidates[2] = {0, 0};
-GstElement *pipeline = NULL;
-gboolean src_setup[2] = {FALSE, FALSE};
volatile gint running = TRUE;
-
GST_START_TEST (test_nicetransmitter_new)
{
test_transmitter_creation ("nice");
@@ -51,6 +47,7 @@ _new_local_candidate (FsStreamTransmitter *st, FsCandidate *candidate,
{
GError *error = NULL;
gboolean ret;
+ FsStreamTransmitter *st2 = FS_STREAM_TRANSMITTER (user_data);
g_debug ("Has local candidate %s:%u of type %d",
candidate->ip, candidate->port, candidate->type);
@@ -68,13 +65,16 @@ _new_local_candidate (FsStreamTransmitter *st, FsCandidate *candidate,
ts_fail_if (candidate->username == NULL, "Candidate doenst have a username");
ts_fail_if (candidate->password == NULL, "Candidate doenst have a password");
-
- candidates[candidate->component_id-1] = 1;
+ g_object_set_data (G_OBJECT (st), "candidates",
+ GUINT_TO_POINTER (1 +
+ GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (st), "candidates"))));
g_debug ("New local candidate %s:%d of type %d for component %d",
candidate->ip, candidate->port, candidate->type, candidate->component_id);
+ g_debug ("username: %s password: %s", candidate->username,
+ candidate->password);
- ret = fs_stream_transmitter_add_remote_candidate (st, candidate, &error);
+ ret = fs_stream_transmitter_add_remote_candidate (st2, candidate, &error);
if (error)
ts_fail ("Error while adding candidate: (%s:%d) %s",
@@ -87,12 +87,15 @@ _new_local_candidate (FsStreamTransmitter *st, FsCandidate *candidate,
static void
_local_candidates_prepared (FsStreamTransmitter *st, gpointer user_data)
{
- ts_fail_if (candidates[0] == 0, "candidates-prepared with no RTP candidate");
- ts_fail_if (candidates[1] == 0, "candidates-prepared with no RTCP candidate");
+ FsStreamTransmitter *st2 = FS_STREAM_TRANSMITTER (user_data);
+ ts_fail_if (
+ GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (st), "candidates")) < 2,
+ "We don't have at least 2 candidates");
+
g_debug ("Local Candidates Prepared");
- fs_stream_transmitter_remote_candidates_added (st);
+ fs_stream_transmitter_remote_candidates_added (st2);
}
@@ -100,47 +103,78 @@ static void
_new_active_candidate_pair (FsStreamTransmitter *st, FsCandidate *local,
FsCandidate *remote, gpointer user_data)
{
+ FsTransmitter *trans = FS_TRANSMITTER (user_data);
+
ts_fail_if (local == NULL, "Local candidate NULL");
ts_fail_if (remote == NULL, "Remote candidate NULL");
ts_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);
+ g_debug ("New active candidate pair");
- if (!src_setup[local->component_id-1])
- setup_fakesrc (user_data, pipeline, local->component_id);
- src_setup[local->component_id-1] = TRUE;
+ if (g_object_get_data (G_OBJECT (trans), "src_setup") == NULL)
+ {
+ GstElement *pipeline = GST_ELEMENT (
+ g_object_get_data (G_OBJECT (trans), "pipeline"));
+ setup_fakesrc (trans, pipeline, 1);
+ setup_fakesrc (trans, pipeline, 2);
+ g_object_set_data (G_OBJECT (trans), "src_setup", "");
+ }
+ else
+ g_debug ("FAKESRC ALREADY SETUP");
}
static void
_handoff_handler (GstElement *element, GstBuffer *buffer, GstPad *pad,
- gpointer user_data)
+ guint stream, gint component_id)
{
- gint component_id = GPOINTER_TO_INT (user_data);
-
ts_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]++;
+ buffer_count[stream][component_id-1]++;
+
- /*
- g_debug ("Buffer %d component: %d size: %u", buffer_count[component_id-1],
- component_id, GST_BUFFER_SIZE (buffer));
- */
+ g_debug ("Buffer %d stream: %u component: %d size: %u",
+ buffer_count[stream][component_id-1], stream,
+ component_id, GST_BUFFER_SIZE (buffer));
- ts_fail_if (buffer_count[component_id-1] > 20,
+ g_debug ("has %d %d %d %d",
+ buffer_count[0][0], buffer_count[0][1],
+ buffer_count[1][0], buffer_count[1][1]);
+
+ ts_fail_if (buffer_count[stream][component_id-1] > 20,
"Too many buffers %d > 20 for component",
- buffer_count[component_id-1], component_id);
+ buffer_count[stream][component_id-1], component_id);
- if (buffer_count[0] == 20 && buffer_count[1] == 20) {
+ if (buffer_count[0][0] == 20 && buffer_count[0][1] == 20 &&
+ buffer_count[1][0] == 20 && buffer_count[1][1] == 20) {
/* TEST OVER */
g_atomic_int_set(&running, FALSE);
g_main_loop_quit (loop);
}
}
+static void
+_handoff_handler1 (GstElement *element, GstBuffer *buffer, GstPad *pad,
+ gpointer user_data)
+{
+ gint component_id = GPOINTER_TO_INT (user_data);
+
+ _handoff_handler (element, buffer, pad, 0, component_id);
+}
+
+static void
+_handoff_handler2 (GstElement *element, GstBuffer *buffer, GstPad *pad,
+ gpointer user_data)
+{
+ gint component_id = GPOINTER_TO_INT (user_data);
+
+ _handoff_handler (element, buffer, pad, 1, component_id);
+}
+
+
static gboolean
check_running (gpointer data)
{
@@ -156,39 +190,62 @@ run_nice_transmitter_test (gint n_parameters, GParameter *params,
gint flags)
{
GError *error = NULL;
- FsTransmitter *trans;
- FsStreamTransmitter *st;
+ FsTransmitter *trans = NULL, *trans2 = NULL;
+ FsStreamTransmitter *st = NULL, *st2 = NULL;
GstBus *bus = NULL;
+ GstElement *pipeline = NULL;
+ GstElement *pipeline2 = NULL;
loop = g_main_loop_new (NULL, FALSE);
+
trans = fs_transmitter_new ("nice", 2, &error);
+ if (error) {
+ ts_fail ("Error creating transmitter: (%s:%d) %s",
+ g_quark_to_string (error->domain), error->code, error->message);
+ }
+ ts_fail_if (trans == NULL, "No transmitter create, yet error is still NULL");
+ trans2 = fs_transmitter_new ("nice", 2, &error);
if (error) {
ts_fail ("Error creating transmitter: (%s:%d) %s",
g_quark_to_string (error->domain), error->code, error->message);
}
+ ts_fail_if (trans2 == NULL, "No transmitter create, yet error is still NULL");
- ts_fail_if (trans == NULL, "No transmitter create, yet error is still NULL");
- pipeline = setup_pipeline (trans, G_CALLBACK (_handoff_handler));
+ pipeline = setup_pipeline (trans, G_CALLBACK (_handoff_handler1));
+ pipeline2 = setup_pipeline (trans2, G_CALLBACK (_handoff_handler2));
+
+ g_object_set_data (G_OBJECT (trans), "pipeline", pipeline);
+ g_object_set_data (G_OBJECT (trans2), "pipeline", pipeline2);
bus = gst_element_get_bus (pipeline);
gst_bus_add_watch (bus, bus_error_callback, NULL);
gst_object_unref (bus);
+ bus = gst_element_get_bus (pipeline2);
+ gst_bus_add_watch (bus, bus_error_callback, NULL);
+ gst_object_unref (bus);
+
st = fs_transmitter_new_stream_transmitter (trans, NULL, n_parameters, params,
&error);
if (error)
ts_fail ("Error creating stream transmitter: (%s:%d) %s",
g_quark_to_string (error->domain), error->code, error->message);
-
ts_fail_if (st == NULL, "No stream transmitter created, yet error is NULL");
+ st2 = fs_transmitter_new_stream_transmitter (trans2, NULL, n_parameters,
+ params, &error);
+ if (error)
+ ts_fail ("Error creating stream transmitter: (%s:%d) %s",
+ g_quark_to_string (error->domain), error->code, error->message);
+ ts_fail_if (st2 == NULL, "No stream transmitter created, yet error is NULL");
+
ts_fail_unless (g_signal_connect (st, "new-local-candidate",
- G_CALLBACK (_new_local_candidate), GINT_TO_POINTER (flags)),
+ G_CALLBACK (_new_local_candidate), st2),
"Could not connect new-local-candidate signal");
ts_fail_unless (g_signal_connect (st, "local-candidates-prepared",
- G_CALLBACK (_local_candidates_prepared), GINT_TO_POINTER (flags)),
+ G_CALLBACK (_local_candidates_prepared), st2),
"Could not connect local-candidates-prepared signal");
ts_fail_unless (g_signal_connect (st, "new-active-candidate-pair",
G_CALLBACK (_new_active_candidate_pair), trans),
@@ -197,9 +254,25 @@ run_nice_transmitter_test (gint n_parameters, GParameter *params,
G_CALLBACK (stream_transmitter_error), NULL),
"Could not connect error signal");
+ ts_fail_unless (g_signal_connect (st2, "new-local-candidate",
+ G_CALLBACK (_new_local_candidate), st),
+ "Could not connect new-local-candidate signal");
+ ts_fail_unless (g_signal_connect (st2, "local-candidates-prepared",
+ G_CALLBACK (_local_candidates_prepared), st),
+ "Could not connect local-candidates-prepared signal");
+ ts_fail_unless (g_signal_connect (st2, "new-active-candidate-pair",
+ G_CALLBACK (_new_active_candidate_pair), trans2),
+ "Could not connect new-active-candidate-pair signal");
+ ts_fail_unless (g_signal_connect (st2, "error",
+ G_CALLBACK (stream_transmitter_error), NULL),
+ "Could not connect error signal");
+
ts_fail_if (gst_element_set_state (pipeline, GST_STATE_PLAYING) ==
GST_STATE_CHANGE_FAILURE, "Could not set the pipeline to playing");
+ ts_fail_if (gst_element_set_state (pipeline2, GST_STATE_PLAYING) ==
+ GST_STATE_CHANGE_FAILURE, "Could not set the pipeline to playing");
+
if (!fs_stream_transmitter_gather_local_candidates (st, &error))
{
if (error)
@@ -210,18 +283,34 @@ run_nice_transmitter_test (gint n_parameters, GParameter *params,
" (without a specified error)");
}
+ if (!fs_stream_transmitter_gather_local_candidates (st2, &error))
+ {
+ if (error)
+ ts_fail ("Could not start gathering local candidates %s",
+ error->message);
+ else
+ ts_fail ("Could not start gathering candidates"
+ " (without a specified error)");
+ }
+
+
g_idle_add (check_running, NULL);
g_main_run (loop);
gst_element_set_state (pipeline, GST_STATE_NULL);
-
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
+ gst_element_set_state (pipeline2, GST_STATE_NULL);
+ gst_element_get_state (pipeline2, NULL, NULL, GST_CLOCK_TIME_NONE);
+
if (st)
g_object_unref (st);
+ if (st2)
+ g_object_unref (st2);
g_object_unref (trans);
+ g_object_unref (trans2);
gst_object_unref (pipeline);
--
1.5.6.5
More information about the farsight-commits
mailing list