diff options
author | Olivier CrĂȘte <olivier.crete@collabora.co.uk> | 2008-01-18 20:11:39 -0500 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.co.uk> | 2008-01-18 20:11:39 -0500 |
commit | 0daf1e0eda2c01fc150dc405bbad20b5253d400c (patch) | |
tree | e58b5abe8255fccf675240d53d53bd46aa54c576 | |
parent | d5d1a4a2f89947b10e828884d4f5b15aedf73164 (diff) | |
download | farstream-0daf1e0eda2c01fc150dc405bbad20b5253d400c.tar.gz |
Add simple test for multicast transmitter
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | tests/check/Makefile.am | 12 | ||||
-rw-r--r-- | tests/check/transmitter/multicast.c | 230 |
3 files changed, 243 insertions, 1 deletions
@@ -39,6 +39,7 @@ tests/check/*/.dirstamp tests/check/base/fscodec tests/check/base/fstransmitter tests/check/transmitter/rawudp +tests/check/transmitter/multicast tests/check/main/rtpconference tests/check/main/rtpcodecs tests/check/utils/binadded @@ -56,6 +57,7 @@ config.log config.status config.sub configure +compile depcomp diff install-sh diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index ad75f53d..27a562e8 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -11,7 +11,7 @@ TESTS_ENVIRONMENT = \ $(REGISTRY_ENVIRONMENT) \ GST_PLUGIN_SYSTEM_PATH= \ GST_PLUGIN_PATH=$(top_builddir)/gst:${GST_PLUGIN_PATH} \ - FS_PLUGIN_PATH=$(top_builddir)/transmitters/rawudp/.libs + FS_PLUGIN_PATH=$(top_builddir)/transmitters/rawudp/.libs:$(top_builddir)/transmitters/multicast/.libs # ths core dumps of some machines have PIDs appended @@ -35,6 +35,7 @@ check_PROGRAMS = \ base/fscodec \ base/fstransmitter \ transmitter/rawudp \ + transmitter/multicast \ main/rtpconference \ main/rtpcodecs \ utils/binadded @@ -60,6 +61,15 @@ transmitter_rawudp_SOURCES = \ transmitter/generic.h \ transmitter/rawudp.c +transmitter_multicast_LDADD = $(LDADD) \ + $(top_builddir)/gst-libs/gst/farsight/libgstfarsight-0.10.la +transmitter_multicast_CFLAGS = $(FS2_INTERNAL_CFLAGS) $(CFLAGS) $(AM_CFLAGS) +transmitter_multicast_SOURCES = \ + check_threadsafe.h \ + transmitter/generic.c \ + transmitter/generic.h \ + transmitter/multicast.c + main_rtpconference_LDADD = $(LDADD) \ diff --git a/tests/check/transmitter/multicast.c b/tests/check/transmitter/multicast.c new file mode 100644 index 00000000..382d8155 --- /dev/null +++ b/tests/check/transmitter/multicast.c @@ -0,0 +1,230 @@ +/* Farsight 2 unit tests for FsMulticastTransmitter + * + * Copyright (C) 2007 Collabora, Nokia + * @author: Olivier Crete <olivier.crete@collabora.co.uk> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <gst/check/gstcheck.h> +#include <gst/farsight/fs-transmitter.h> +#include <gst/farsight/fs-conference-iface.h> + +#include "check-threadsafe.h" +#include "generic.h" + +gint buffer_count[2] = {0, 0}; +GMainLoop *loop = NULL; +gint candidates[2] = {0, 0}; +GstElement *pipeline = NULL; +gboolean src_setup[2] = {FALSE, FALSE}; + +GST_START_TEST (test_multicasttransmitter_new) +{ + GError *error = NULL; + FsTransmitter *trans; + GstElement *pipeline; + GstElement *trans_sink, *trans_src; + + trans = fs_transmitter_new ("multicast", 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"); + + pipeline = setup_pipeline (trans, NULL); + + g_object_get (trans, "gst-sink", &trans_sink, "gst-src", &trans_src, NULL); + + g_object_unref (trans); + + gst_object_unref (pipeline); + +} +GST_END_TEST; + + + +static void +_handoff_handler (GstElement *element, GstBuffer *buffer, GstPad *pad, + gpointer user_data) +{ + 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]++; + + /* + g_debug ("Buffer %d component: %d size: %u", buffer_count[component_id-1], + component_id, GST_BUFFER_SIZE (buffer)); + */ + + ts_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); + } +} + +static void +_new_active_candidate_pair (FsStreamTransmitter *st, FsCandidate *local, + FsCandidate *remote, gpointer 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); + + if (!src_setup[local->component_id-1]) + setup_fakesrc (user_data, pipeline, local->component_id); + src_setup[local->component_id-1] = TRUE; +} + +static gboolean +_start_pipeline (gpointer user_data) +{ + GstElement *pipeline = user_data; + + g_debug ("Starting pipeline"); + + ts_fail_if (gst_element_set_state (pipeline, GST_STATE_PLAYING) == + GST_STATE_CHANGE_FAILURE, "Could not set the pipeline to playing"); + + return FALSE; +} + +static void +run_multicast_transmitter_test (gint n_parameters, GParameter *params, + gint flags) +{ + GError *error = NULL; + FsTransmitter *trans; + FsStreamTransmitter *st; + GstElement *trans_sink, *trans_src; + FsCandidate *tmpcand = NULL; + + loop = g_main_loop_new (NULL, FALSE); + trans = fs_transmitter_new ("multicast", 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"); + + pipeline = setup_pipeline (trans, G_CALLBACK (_handoff_handler)); + + g_object_get (trans, "gst-sink", &trans_sink, "gst-src", &trans_src, NULL); + + 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"); + + ts_fail_unless (g_signal_connect (st, "new-active-candidate-pair", + G_CALLBACK (_new_active_candidate_pair), trans), + "Coult not connect new-active-candidate-pair signal"); + ts_fail_unless (g_signal_connect (st, "error", + G_CALLBACK (_stream_transmitter_error), NULL), + "Could not connect error signal"); + + g_idle_add (_start_pipeline, pipeline); + + tmpcand = fs_candidate_new ("L1", FS_COMPONENT_RTP, + FS_CANDIDATE_TYPE_MULTICAST, FS_NETWORK_PROTOCOL_UDP, + "224.0.0.33", 2322); + if (!fs_stream_transmitter_add_remote_candidate (st, tmpcand, &error)) + ts_fail ("Error setting the remote candidate: %p %s", error, + error ? error->message : "NO ERROR SET"); + ts_fail_unless (error == NULL, "Error is not null after successful candidate" + " addition"); + fs_candidate_destroy (tmpcand); + + tmpcand = fs_candidate_new ("L2", FS_COMPONENT_RTCP, + FS_CANDIDATE_TYPE_MULTICAST, FS_NETWORK_PROTOCOL_UDP, + "224.0.0.33", 2323); + if (!fs_stream_transmitter_add_remote_candidate (st, tmpcand, &error)) + ts_fail ("Error setting the remote candidate: %p %s", error, + error ? error->message : "NO ERROR SET"); + ts_fail_unless (error == NULL, "Error is not null after successful candidate" + " addition"); + fs_candidate_destroy (tmpcand); + + g_debug ("STARTING"); + + g_main_run (loop); + + g_object_unref (st); + + g_object_unref (trans); + + gst_element_set_state (pipeline, GST_STATE_NULL); + + gst_object_unref (pipeline); + + g_main_loop_unref (loop); + +} + +GST_START_TEST (test_multicasttransmitter_run) +{ + run_multicast_transmitter_test (0, NULL, 0); +} +GST_END_TEST; + +static Suite * +multicasttransmitter_suite (void) +{ + Suite *s = suite_create ("multicasttransmitter"); + TCase *tc_chain; + GLogLevelFlags fatal_mask; + + fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); + fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; + g_log_set_always_fatal (fatal_mask); + + tc_chain = tcase_create ("multicasttransmitter"); + tcase_set_timeout (tc_chain, 5); + tcase_add_test (tc_chain, test_multicasttransmitter_new); + tcase_add_test (tc_chain, test_multicasttransmitter_run); + suite_add_tcase (s, tc_chain); + + return s; +} + + +GST_CHECK_MAIN (multicasttransmitter); |