[farsight2/master] Add test for FsRtpDtmfEventSource
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:21:40 PST 2008
---
.gitignore | 1 +
tests/check/Makefile.am | 11 ++-
tests/check/main/rtpsendcodecs.c | 323 ++++++++++++++++++++++++++++++++++++++
3 files changed, 334 insertions(+), 1 deletions(-)
create mode 100644 tests/check/main/rtpsendcodecs.c
diff --git a/.gitignore b/.gitignore
index 5bf791d..0818709 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,7 @@ tests/check/transmitter/rawudp
tests/check/transmitter/multicast
tests/check/main/rtpconference
tests/check/main/rtpcodecs
+tests/check/main/rtpsendcodecs
tests/check/utils/binadded
tests/rtp/codec-discovery
tests/gui/*.pyo
diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index c260b67..46c58ff 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -14,7 +14,7 @@ TESTS_ENVIRONMENT = \
# ths core dumps of some machines have PIDs appended
-CLEANFILES = core.* test-registry.xml
+CLEANFILES = core* test-registry.xml
clean-local: clean-local-check
@@ -37,6 +37,7 @@ check_PROGRAMS = \
transmitter/multicast \
main/rtpconference \
main/rtpcodecs \
+ main/rtpsendcodecs \
utils/binadded
@@ -90,6 +91,14 @@ main_rtpcodecs_SOURCES = \
main/rtpcodecs.c
+main_rtpsendcodecs_LDADD = $(LDADD) \
+ $(top_builddir)/gst-libs/gst/farsight/libgstfarsight-0.10.la \
+ -lgstrtp-0.10
+main_rtpsendcodecs_CFLAGS = $(FS2_INTERNAL_CFLAGS) $(CFLAGS) $(AM_CFLAGS)
+main_rtpsendcodecs_SOURCES = \
+ main/generic.c \
+ main/generic.h \
+ main/rtpsendcodecs.c
utils_binadded_LDADD = $(LDADD) \
diff --git a/tests/check/main/rtpsendcodecs.c b/tests/check/main/rtpsendcodecs.c
new file mode 100644
index 0000000..3e4d24b
--- /dev/null
+++ b/tests/check/main/rtpsendcodecs.c
@@ -0,0 +1,323 @@
+/* Farsight 2 unit tests for FsRtpConference
+ *
+ * Copyright (C) 2007 Collabora, Nokia
+ * @author: Olivier Crete <olivier.crete at 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/rtp/gstrtpbuffer.h>
+
+#include <gst/farsight/fs-conference-iface.h>
+
+#include "check-threadsafe.h"
+#include "generic.h"
+
+GMainLoop *loop = NULL;
+
+guint dtmf_id = 0;
+
+struct SimpleTestConference *dat = NULL;
+
+static gboolean
+_start_pipeline (gpointer user_data)
+{
+ struct SimpleTestConference *dat = user_data;
+
+ g_debug ("%d: Starting pipeline", dat->id);
+
+ ts_fail_if (gst_element_set_state (dat->pipeline, GST_STATE_PLAYING) ==
+ GST_STATE_CHANGE_FAILURE, "Could not set the pipeline to playing");
+
+ dat->started = TRUE;
+
+ return FALSE;
+}
+
+
+static gboolean
+_bus_callback (GstBus *bus, GstMessage *message, gpointer user_data)
+{
+ struct SimpleTestConference *dat = user_data;
+
+ switch (GST_MESSAGE_TYPE (message))
+ {
+ case GST_MESSAGE_ELEMENT:
+ if (gst_implements_interface_check (GST_MESSAGE_SRC (message),
+ FS_TYPE_CONFERENCE))
+ {
+ const GValue *errorvalue, *debugvalue;
+ gint errno;
+
+ gst_structure_get_int (message->structure, "error-no", &errno);
+ errorvalue = gst_structure_get_value (message->structure, "error-msg");
+ debugvalue = gst_structure_get_value (message->structure, "debug-msg");
+
+ ts_fail ("Error on BUS (%d) %s .. %s", errno,
+ g_value_get_string (errorvalue),
+ g_value_get_string (debugvalue));
+ }
+
+ break;
+ case GST_MESSAGE_ERROR:
+ {
+ GError *error = NULL;
+ gchar *debug = NULL;
+ gst_message_parse_error (message, &error, &debug);
+
+ ts_fail ("Got an error on the BUS (%d): %s (%s)", error->code,
+ error->message, debug);
+ g_error_free (error);
+ g_free (debug);
+ }
+ break;
+ case GST_MESSAGE_WARNING:
+ {
+ GError *error = NULL;
+ gchar *debug = NULL;
+ gst_message_parse_warning (message, &error, &debug);
+
+ g_debug ("%d: Got a warning on the BUS (%d): %s (%s)", dat->id,
+ error->code,
+ error->message, debug);
+ g_error_free (error);
+ g_free (debug);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+static GstElement *
+build_recv_pipeline (GCallback handoff_handler, gpointer data, gint *port)
+{
+ GstElement *pipeline;
+ GstElement *src;
+ GstElement *sink;
+
+ pipeline = gst_pipeline_new (NULL);
+
+ src = gst_element_factory_make ("udpsrc", NULL);
+ sink = gst_element_factory_make ("fakesink", NULL);
+
+ ts_fail_unless (pipeline && src && sink, "Could not make pipeline(%p)"
+ " or src(%p) or sink(%p)", pipeline, src, sink);
+
+ gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
+
+ ts_fail_unless (gst_element_link (src, sink), "Could not link udpsrc"
+ " and fakesink");
+
+ g_signal_connect (sink, "handoff", handoff_handler, data);
+
+ ts_fail_if (gst_element_set_state (pipeline, GST_STATE_PLAYING) ==
+ GST_STATE_CHANGE_FAILURE, "Could not start recv pipeline");
+
+ g_object_get (G_OBJECT (src), "port", port, NULL);
+
+ return pipeline;
+}
+
+static void
+set_codecs (struct SimpleTestConference *dat, FsStream *stream)
+{
+ GList *local_codecs = NULL;
+ GList *filtered_codecs = NULL;
+ GList *item = NULL;
+ GError *error = NULL;
+
+ g_object_get (dat->session, "local-codecs", &local_codecs, NULL);
+
+ ts_fail_if (local_codecs == NULL, "Could not get the local codecs");
+
+ for (item = g_list_first (local_codecs); item; item = g_list_next (item))
+ {
+ FsCodec *codec = item->data;
+ if (codec->id == 0 || codec->id == 8)
+ {
+ filtered_codecs = g_list_append (filtered_codecs, codec);
+ }
+ else if (codec->clock_rate == 8000 &&
+ !g_strcasecmp (codec->encoding_name, "telephone-event"))
+ {
+ ts_fail_unless (dtmf_id == 0, "More than one copy of telephon-event");
+ dtmf_id = codec->id;
+ filtered_codecs = g_list_append (filtered_codecs, codec);
+ }
+ }
+
+ ts_fail_if (filtered_codecs == NULL, "PCMA and PCMU are not in the codecs"
+ " you must install gst-plugins-good");
+
+
+ if (!fs_stream_set_remote_codecs (stream, filtered_codecs, &error))
+ {
+ if (error)
+ ts_fail ("Could not set the remote codecs on stream (%d): %s",
+ error->code,
+ error->message);
+ else
+ ts_fail ("Could not set the remote codecs on stream"
+ " and we did NOT get a GError!!");
+ }
+}
+
+static void
+one_way (GCallback handoff_handler, gpointer data)
+{
+ FsStream *stream = NULL;
+ FsParticipant *participant = NULL;
+ GError *error = NULL;
+ gint port = 0;
+ GstElement *recv_pipeline;
+ FsCandidate *candidate = NULL;
+ GstBus *bus = NULL;
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ dat = setup_simple_conference (1, "fsrtpconference", "tester at 123445");
+
+ bus = gst_element_get_bus (dat->pipeline);
+ gst_bus_add_watch (bus, _bus_callback, dat);
+ gst_object_unref (bus);
+
+ g_idle_add (_start_pipeline, dat);
+
+ participant = fs_conference_new_participant (
+ FS_CONFERENCE (dat->conference), "blob at blob.com", &error);
+ if (error)
+ ts_fail ("Error while creating new participant (%d): %s",
+ error->code, error->message);
+ ts_fail_if (dat->session == NULL,
+ "Could not make participant, but no GError!");
+
+ stream = fs_session_new_stream (dat->session, participant,
+ FS_DIRECTION_SEND, "rawudp", 0, NULL, &error);
+ if (error)
+ ts_fail ("Error while creating new stream (%d): %s",
+ error->code, error->message);
+ ts_fail_if (stream == NULL, "Could not make stream, but no GError!");
+
+ recv_pipeline = build_recv_pipeline (handoff_handler, NULL, &port);
+
+ g_debug ("port is %d", port);
+
+ candidate = fs_candidate_new ("1", FS_COMPONENT_RTP, FS_CANDIDATE_TYPE_HOST,
+ FS_NETWORK_PROTOCOL_UDP, "127.0.0.1", port);
+
+ ts_fail_unless (fs_stream_add_remote_candidate (stream, candidate, &error),
+ "Could not set remote candidate");
+ fs_stream_remote_candidates_added (stream);
+
+ set_codecs (dat, stream);
+
+ g_main_loop_run (loop);
+
+ gst_element_set_state (dat->pipeline, GST_STATE_NULL);
+ gst_element_set_state (recv_pipeline, GST_STATE_NULL);
+
+ cleanup_simple_conference (dat);
+ gst_object_unref (recv_pipeline);
+
+ g_main_loop_unref (loop);
+}
+
+gint digit = 1;
+gboolean sending = FALSE;
+
+static void
+send_dmtf_handoff_handler (GstElement *fakesink, GstBuffer *buf, GstPad *pad,
+ gpointer user_data)
+{
+ gchar *data;
+
+ ts_fail_unless (gst_rtp_buffer_validate (buf), "Buffer is not valid rtp");
+
+ data = gst_rtp_buffer_get_payload (buf);
+
+ ts_fail_if (data[0] != digit, "Not sending the right digit");
+
+
+}
+
+static gboolean
+start_stop_sending_dtmf (gpointer data)
+{
+
+ if (!dat || !dat->session)
+ return TRUE;
+
+ if (sending)
+ {
+ ts_fail_unless (fs_session_stop_telephony_event (dat->session,
+ FS_DTMF_METHOD_RTP_RFC4733), "Could not stop telephony event");
+ sending = FALSE;
+
+ if (digit > FS_DTMF_EVENT_D)
+ {
+ digit = 1;
+ g_main_loop_quit (loop);
+ return FALSE;
+ }
+ }
+ else
+ {
+ digit++;
+
+ ts_fail_unless (fs_session_start_telephony_event (dat->session,
+ digit, digit, FS_DTMF_METHOD_RTP_RFC4733),
+ "Could not start telephony event");
+ sending = TRUE;
+ }
+
+ return TRUE;
+}
+
+GST_START_TEST (test_senddtmf_event)
+{
+ g_timeout_add (200, start_stop_sending_dtmf, NULL);
+ one_way (G_CALLBACK (send_dmtf_handoff_handler), NULL);
+}
+GST_END_TEST;
+
+
+static Suite *
+fsrtpsendcodecs_suite (void)
+{
+ Suite *s = suite_create ("fsrtpsendcodecs");
+ 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 ("fsrtpsenddtmf");
+ tcase_add_test (tc_chain, test_senddtmf_event);
+ suite_add_tcase (s, tc_chain);
+
+ return s;
+}
+
+GST_CHECK_MAIN (fsrtpsendcodecs);
--
1.5.6.5
More information about the farsight-commits
mailing list