summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2006-05-22 13:25:52 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2006-05-22 13:25:52 +0000
commitd3c823f87746363b235f1b374eac1e4b41d7bf57 (patch)
tree8f6345ffee69b114d90f6e4c69686a582de754a3 /tests
parentd440cf33c64500495623c5aecc2ed226dcb3a075 (diff)
downloadgst-plugins-bad-d3c823f87746363b235f1b374eac1e4b41d7bf57.tar.gz
gst-plugins-bad-d3c823f87746363b235f1b374eac1e4b41d7bf57.tar.bz2
gst-plugins-bad-d3c823f87746363b235f1b374eac1e4b41d7bf57.zip
adding GDP payloader and depayloader. Build integration will follow later when the GDP issues for core are sorted out.
Original commit message from CVS: * gst/gdp/Makefile.am: * gst/gdp/gstgdp.c: (plugin_init): * gst/gdp/gstgdpdepay.c: (gst_gdp_depay_base_init), (gst_gdp_depay_class_init), (gst_gdp_depay_init), (gst_gdp_depay_finalize), (gst_gdp_depay_chain), (gst_gdp_depay_change_state), (gst_gdp_depay_plugin_init): * gst/gdp/gstgdpdepay.h: * gst/gdp/gstgdppay.c: (gst_gdp_pay_base_init), (gst_gdp_pay_class_init), (gst_gdp_pay_init), (gst_gdp_pay_dispose), (gst_gdp_stamp_buffer), (gst_gdp_buffer_from_caps), (gst_gdp_pay_buffer_from_buffer), (gst_gdp_buffer_from_event), (gst_gdp_pay_reset_streamheader), (gst_gdp_queue_buffer), (gst_gdp_pay_chain), (gst_gdp_pay_sink_event), (gst_gdp_pay_change_state), (gst_gdp_pay_plugin_init): * gst/gdp/gstgdppay.h: * tests/check/Makefile.am: * tests/check/elements/gdpdepay.c: (setup_gdpdepay), (cleanup_gdpdepay), (gdpdepay_push_per_byte), (GST_START_TEST), (setup_gdpdepay_streamheader), (gdpdepay_suite), (main): * tests/check/elements/gdppay.c: (setup_gdppay), (cleanup_gdppay), (GST_START_TEST), (setup_gdppay_streamheader), (gdppay_suite), (main): adding GDP payloader and depayloader. Build integration will follow later when the GDP issues for core are sorted out.
Diffstat (limited to 'tests')
-rw-r--r--tests/check/Makefile.am8
-rw-r--r--tests/check/elements/gdpdepay.c400
-rw-r--r--tests/check/elements/gdppay.c470
3 files changed, 876 insertions, 2 deletions
diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index c1663887..96df1978 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -12,7 +12,7 @@ REGISTRY_ENVIRONMENT = \
TESTS_ENVIRONMENT = \
$(REGISTRY_ENVIRONMENT) \
GST_PLUGIN_SYSTEM_PATH= \
- GST_PLUGIN_PATH=$(top_builddir)/ext:$(GSTPB_PLUGINS_DIR)/../gst-plugins-good:$(GSTPB_PLUGINS_DIR):$(GST_PLUGINS_DIR)
+ GST_PLUGIN_PATH=$(top_builddir)/gst:$(top_builddir)/ext:$(GSTPB_PLUGINS_DIR):$(GST_PLUGINS_DIR)
plugindir = $(libdir)/gstreamer-@GST_MAJORMINOR@
@@ -26,9 +26,13 @@ SUPPRESSIONS = $(top_srcdir)/common/gst.supp
clean-local: clean-local-check
-check_PROGRAMS =
+check_PROGRAMS = \
+ elements/gdppay \
+ elements/gdpdepay
TESTS = $(check_PROGRAMS)
AM_CFLAGS = $(GST_OBJ_CFLAGS) $(GST_CHECK_CFLAGS) $(CHECK_CFLAGS)
LDADD = $(GST_OBJ_LIBS) $(GST_CHECK_LIBS) $(CHECK_LIBS)
+
+elements_gdpdepay_LDFLAGS = $(LDADD) $(GST_GDP_LIBS)
diff --git a/tests/check/elements/gdpdepay.c b/tests/check/elements/gdpdepay.c
new file mode 100644
index 00000000..4e8c9d50
--- /dev/null
+++ b/tests/check/elements/gdpdepay.c
@@ -0,0 +1,400 @@
+/* GStreamer
+ *
+ * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+#include <unistd.h>
+
+#include <gst/check/gstcheck.h>
+#include <gst/dataprotocol/dataprotocol.h>
+
+GList *buffers = NULL;
+gboolean have_eos = FALSE;
+
+/* For ease of programming we use globals to keep refs for our floating
+ * src and sink pads we create; otherwise we always have to do get_pad,
+ * get_peer, and then remove references in every test function */
+GstPad *mysrcpad, *mysinkpad, *myshsinkpad;
+
+#define AUDIO_CAPS_TEMPLATE_STRING \
+ "audio/x-raw-int, " \
+ "rate = (int) [ 1, MAX ], " \
+ "channels = (int) [ 1, 8 ], " \
+ "endianness = (int) BYTE_ORDER, " \
+ "width = (int) {8, 16}, " \
+ "depth = (int) {8, 16}, " \
+ "signed = (boolean) true"
+
+#define AUDIO_CAPS_STRING \
+ "audio/x-raw-int, " \
+ "rate = (int) 1000, " \
+ "channels = (int) 2, " \
+ "endianness = (int) BYTE_ORDER, " \
+ "width = (int) 16, " \
+ "depth = (int) 16, " \
+ "signed = (boolean) true"
+
+
+static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS (AUDIO_CAPS_TEMPLATE_STRING)
+ );
+static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-gdp")
+ );
+
+/* takes over reference for outcaps */
+GstElement *
+setup_gdpdepay ()
+{
+ GstElement *gdpdepay;
+
+ GST_DEBUG ("setup_gdpdepay");
+ gdpdepay = gst_check_setup_element ("gdpdepay");
+ mysrcpad = gst_check_setup_src_pad (gdpdepay, &srctemplate, NULL);
+ mysinkpad = gst_check_setup_sink_pad (gdpdepay, &sinktemplate, NULL);
+
+ return gdpdepay;
+}
+
+void
+cleanup_gdpdepay (GstElement * gdpdepay)
+{
+ GST_DEBUG ("cleanup_gdpdepay");
+
+ gst_check_teardown_src_pad (gdpdepay);
+ gst_check_teardown_sink_pad (gdpdepay);
+ gst_check_teardown_element (gdpdepay);
+}
+
+static void
+gdpdepay_push_per_byte (gchar * reason, guint8 * bytes, guint length)
+{
+ int i;
+ GstBuffer *inbuffer;
+
+ for (i = 0; i < length; ++i) {
+ inbuffer = gst_buffer_new_and_alloc (1);
+ GST_BUFFER_DATA (inbuffer)[0] = bytes[i];
+ fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK,
+ "%s: failed pushing byte buffer", reason);
+ }
+}
+
+GST_START_TEST (test_audio_per_byte)
+{
+ GstCaps *caps;
+ GstPad *srcpad;
+ GstElement *gdpdepay;
+ GstBuffer *buffer, *inbuffer, *outbuffer;
+ gint length;
+ guint8 *header, *payload;
+ guint len;
+ guint i;
+
+ gdpdepay = setup_gdpdepay ();
+ srcpad = gst_element_get_pad (gdpdepay, "src");
+
+ fail_unless (gst_element_set_state (gdpdepay,
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+ "could not set to playing");
+
+ caps = gst_pad_get_caps (srcpad);
+ fail_unless (gst_caps_is_any (caps));
+ gst_caps_unref (caps);
+ fail_if (gst_pad_get_negotiated_caps (srcpad));
+
+ /* create caps and buffer packets and push them */
+ caps = gst_caps_from_string (AUDIO_CAPS_STRING);
+ fail_unless (gst_dp_packet_from_caps (caps, 0, &len, &header, &payload));
+ gst_caps_unref (caps);
+ gdpdepay_push_per_byte ("caps header", header, len);
+ fail_unless_equals_int (g_list_length (buffers), 0);
+ gdpdepay_push_per_byte ("caps payload", payload,
+ gst_dp_header_payload_length (header));
+ fail_unless_equals_int (g_list_length (buffers), 0);
+ caps = gst_pad_get_caps (srcpad);
+ fail_if (gst_caps_is_any (caps));
+ gst_caps_unref (caps);
+
+ g_free (header);
+ g_free (payload);
+
+ buffer = gst_buffer_new_and_alloc (4);
+ memcpy (GST_BUFFER_DATA (buffer), "f00d", 4);
+ GST_BUFFER_TIMESTAMP (buffer) = GST_SECOND;
+ GST_BUFFER_DURATION (buffer) = GST_SECOND / 10;
+ fail_unless (gst_dp_header_from_buffer (buffer, 0, &len, &header));
+ gdpdepay_push_per_byte ("buffer header", header, len);
+ fail_unless_equals_int (g_list_length (buffers), 0);
+ gdpdepay_push_per_byte ("buffer payload", GST_BUFFER_DATA (buffer),
+ gst_dp_header_payload_length (header));
+ g_free (header);
+ gst_buffer_unref (buffer);
+
+ fail_unless_equals_int (g_list_length (buffers), 1);
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (outbuffer), GST_SECOND);
+ fail_unless_equals_uint64 (GST_BUFFER_DURATION (outbuffer), GST_SECOND / 10);
+
+ buffers = g_list_remove (buffers, outbuffer);
+ gst_buffer_unref (outbuffer);
+
+ fail_unless (gst_element_set_state (gdpdepay,
+ GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
+
+ ASSERT_OBJECT_REFCOUNT (gdpdepay, "gdpdepay", 1);
+ gst_object_unref (srcpad);
+ cleanup_gdpdepay (gdpdepay);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_audio_in_one_buffer)
+{
+ GstCaps *caps;
+ GstPad *srcpad;
+ GstElement *gdpdepay;
+ GstBuffer *buffer, *inbuffer, *outbuffer;
+ gint length;
+ guint8 *caps_header, *caps_payload, *buf_header, *buf_payload;
+ guint header_len, payload_len;
+ guint i;
+
+ gdpdepay = setup_gdpdepay ();
+ srcpad = gst_element_get_pad (gdpdepay, "src");
+
+ fail_unless (gst_element_set_state (gdpdepay,
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+ "could not set to playing");
+
+ /* make sure no caps are set yet */
+ caps = gst_pad_get_caps (srcpad);
+ fail_unless (gst_caps_is_any (caps));
+ gst_caps_unref (caps);
+ fail_if (gst_pad_get_negotiated_caps (srcpad));
+
+ /* create caps and buffer packets and push them as one buffer */
+ caps = gst_caps_from_string (AUDIO_CAPS_STRING);
+ fail_unless (gst_dp_packet_from_caps (caps, 0, &header_len, &caps_header,
+ &caps_payload));
+
+ buffer = gst_buffer_new_and_alloc (4);
+ memcpy (GST_BUFFER_DATA (buffer), "f00d", 4);
+ fail_unless (gst_dp_header_from_buffer (buffer, 0, &header_len, &buf_header));
+
+ payload_len = gst_dp_header_payload_length (caps_header);
+
+ inbuffer = gst_buffer_new_and_alloc (2 * GST_DP_HEADER_LENGTH +
+ payload_len + GST_BUFFER_SIZE (buffer));
+ memcpy (GST_BUFFER_DATA (inbuffer), caps_header, GST_DP_HEADER_LENGTH);
+ i = GST_DP_HEADER_LENGTH;
+ memcpy (GST_BUFFER_DATA (inbuffer) + i, caps_payload, payload_len);
+ i += payload_len;
+ memcpy (GST_BUFFER_DATA (inbuffer) + i, buf_header, GST_DP_HEADER_LENGTH);
+ i += GST_DP_HEADER_LENGTH;
+ memcpy (GST_BUFFER_DATA (inbuffer) + i, GST_BUFFER_DATA (buffer),
+ GST_BUFFER_SIZE (buffer));
+
+ gst_caps_unref (caps);
+ gst_buffer_unref (buffer);
+
+ g_free (caps_header);
+ g_free (caps_payload);
+ g_free (buf_header);
+
+ /* now push it */
+ gst_pad_push (mysrcpad, inbuffer);
+
+ /* the buffer is still queued */
+ fail_unless_equals_int (g_list_length (buffers), 1);
+
+ fail_unless (gst_element_set_state (gdpdepay,
+ GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
+
+ gst_object_unref (srcpad);
+ ASSERT_OBJECT_REFCOUNT (gdpdepay, "gdpdepay", 1);
+ cleanup_gdpdepay (gdpdepay);
+}
+
+GST_END_TEST;
+
+static GstStaticPadTemplate shsinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-gst-test-streamheader")
+ );
+
+GstElement *
+setup_gdpdepay_streamheader ()
+{
+ GstElement *gdpdepay;
+
+ GST_DEBUG ("setup_gdpdepay");
+ gdpdepay = gst_check_setup_element ("gdpdepay");
+ mysrcpad = gst_check_setup_src_pad (gdpdepay, &srctemplate, NULL);
+ myshsinkpad = gst_check_setup_sink_pad (gdpdepay, &shsinktemplate, NULL);
+
+ return gdpdepay;
+}
+
+/* this tests deserialization of a GDP stream where the serialized caps
+ * have a streamheader set */
+GST_START_TEST (test_streamheader)
+{
+ GstCaps *caps, *padcaps;
+ GstPad *srcpad;
+ GstElement *gdpdepay;
+ GstBuffer *buffer, *inbuffer, *outbuffer, *shbuffer;
+ gint length;
+ guint8 *caps_header, *caps_payload, *buf_header, *buf_payload;
+ guint header_len, payload_len;
+ guint i;
+ GstStructure *structure;
+ GValue array = { 0 };
+ GValue value = { 0 };
+
+ gdpdepay = setup_gdpdepay_streamheader ();
+ srcpad = gst_element_get_pad (gdpdepay, "src");
+ ASSERT_OBJECT_REFCOUNT (gdpdepay, "gdpdepay", 1);
+
+ fail_unless (gst_element_set_state (gdpdepay,
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+ "could not set to playing");
+
+ /* make sure no caps are set yet */
+ caps = gst_pad_get_caps (srcpad);
+ fail_unless (gst_caps_is_any (caps));
+ gst_caps_unref (caps);
+ fail_if (gst_pad_get_negotiated_caps (srcpad));
+
+ /* create a streamheader buffer and the caps containing it */
+ caps = gst_caps_from_string ("application/x-gst-test-streamheader");
+ structure = gst_caps_get_structure (caps, 0);
+ buffer = gst_buffer_new_and_alloc (4);
+ memcpy (GST_BUFFER_DATA (buffer), "f00d", 4);
+ GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS);
+ g_value_init (&array, GST_TYPE_ARRAY);
+ g_value_init (&value, GST_TYPE_BUFFER);
+ shbuffer = gst_buffer_copy (buffer);
+ gst_value_set_buffer (&value, shbuffer);
+ gst_buffer_unref (shbuffer);
+ gst_value_array_append_value (&array, &value);
+ g_value_unset (&value);
+ gst_structure_set_value (structure, "streamheader", &array);
+ g_value_unset (&array);
+
+ gst_buffer_set_caps (buffer, caps);
+
+ /* create GDP packets for the caps and the buffer, and put them in one
+ * GDP buffer */
+ fail_unless (gst_dp_packet_from_caps (caps, 0, &header_len, &caps_header,
+ &caps_payload));
+
+ fail_unless (gst_dp_header_from_buffer (buffer, 0, &header_len, &buf_header));
+
+ payload_len = gst_dp_header_payload_length (caps_header);
+
+ inbuffer = gst_buffer_new_and_alloc (2 * GST_DP_HEADER_LENGTH +
+ payload_len + GST_BUFFER_SIZE (buffer));
+ memcpy (GST_BUFFER_DATA (inbuffer), caps_header, GST_DP_HEADER_LENGTH);
+ i = GST_DP_HEADER_LENGTH;
+ memcpy (GST_BUFFER_DATA (inbuffer) + i, caps_payload, payload_len);
+ i += payload_len;
+ memcpy (GST_BUFFER_DATA (inbuffer) + i, buf_header, GST_DP_HEADER_LENGTH);
+ i += GST_DP_HEADER_LENGTH;
+ memcpy (GST_BUFFER_DATA (inbuffer) + i, GST_BUFFER_DATA (buffer),
+ GST_BUFFER_SIZE (buffer));
+
+ gst_caps_unref (caps);
+ gst_buffer_unref (buffer);
+
+ g_free (caps_header);
+ g_free (caps_payload);
+ g_free (buf_header);
+
+ /* now push it */
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+ gst_pad_push (mysrcpad, inbuffer);
+
+ /* our only output buffer is the streamheader buffer */
+ fail_unless_equals_int (g_list_length (buffers), 1);
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
+ fail_unless (GST_BUFFER_FLAG_IS_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS));
+
+ padcaps = gst_pad_get_negotiated_caps (myshsinkpad);
+ caps = gst_buffer_get_caps (outbuffer);
+ fail_if (caps == NULL);
+ fail_if (padcaps == NULL);
+ GST_DEBUG ("caps: %" GST_PTR_FORMAT ", padcaps: %" GST_PTR_FORMAT, caps,
+ padcaps);
+ fail_unless (gst_caps_is_equal (padcaps, caps));
+
+ /* FIXME: get streamheader, compare data with buffer */
+ gst_buffer_unref (outbuffer);
+ gst_caps_unref (padcaps);
+ gst_caps_unref (caps);
+
+ /* clean up */
+ fail_unless (gst_element_set_state (gdpdepay,
+ GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
+
+ gst_object_unref (srcpad);
+ ASSERT_OBJECT_REFCOUNT (gdpdepay, "gdpdepay", 1);
+ cleanup_gdpdepay (gdpdepay);
+}
+
+GST_END_TEST;
+
+
+Suite *
+gdpdepay_suite (void)
+{
+ Suite *s = suite_create ("gdpdepay");
+ TCase *tc_chain = tcase_create ("general");
+
+ suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_audio_per_byte);
+ tcase_add_test (tc_chain, test_audio_in_one_buffer);
+ tcase_add_test (tc_chain, test_streamheader);
+
+ return s;
+}
+
+int
+main (int argc, char **argv)
+{
+ int nf;
+
+ Suite *s = gdpdepay_suite ();
+ SRunner *sr = srunner_create (s);
+
+ gst_check_init (&argc, &argv);
+
+ srunner_run_all (sr, CK_NORMAL);
+ nf = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return nf;
+}
diff --git a/tests/check/elements/gdppay.c b/tests/check/elements/gdppay.c
new file mode 100644
index 00000000..5915ef32
--- /dev/null
+++ b/tests/check/elements/gdppay.c
@@ -0,0 +1,470 @@
+/* GStreamer
+ *
+ * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+#include <unistd.h>
+
+#include <gst/check/gstcheck.h>
+#include <gst/dataprotocol/dataprotocol.h>
+
+GList *buffers = NULL;
+gboolean have_eos = FALSE;
+
+/* For ease of programming we use globals to keep refs for our floating
+ * src and sink pads we create; otherwise we always have to do get_pad,
+ * get_peer, and then remove references in every test function */
+GstPad *mysrcpad, *myshsrcpad, *mysinkpad;
+
+#define AUDIO_CAPS_TEMPLATE_STRING \
+ "audio/x-raw-int, " \
+ "rate = (int) [ 1, MAX ], " \
+ "channels = (int) [ 1, 8 ], " \
+ "endianness = (int) BYTE_ORDER, " \
+ "width = (int) {8, 16}, " \
+ "depth = (int) {8, 16}, " \
+ "signed = (boolean) true"
+
+#define AUDIO_CAPS_STRING \
+ "audio/x-raw-int, " \
+ "rate = (int) 1000, " \
+ "channels = (int) 2, " \
+ "endianness = (int) BYTE_ORDER, " \
+ "width = (int) 16, " \
+ "depth = (int) 16, " \
+ "signed = (boolean) true"
+
+
+static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-gdp")
+ );
+static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS (AUDIO_CAPS_TEMPLATE_STRING)
+ );
+
+/* takes over reference for outcaps */
+GstElement *
+setup_gdppay ()
+{
+ GstElement *gdppay;
+
+ GST_DEBUG ("setup_gdppay");
+ gdppay = gst_check_setup_element ("gdppay");
+ mysrcpad = gst_check_setup_src_pad (gdppay, &srctemplate, NULL);
+ mysinkpad = gst_check_setup_sink_pad (gdppay, &sinktemplate, NULL);
+
+ return gdppay;
+}
+
+void
+cleanup_gdppay (GstElement * gdppay)
+{
+ GST_DEBUG ("cleanup_gdppay");
+
+ gst_check_teardown_src_pad (gdppay);
+ gst_check_teardown_sink_pad (gdppay);
+ gst_check_teardown_element (gdppay);
+}
+
+
+GST_START_TEST (test_audio)
+{
+ GstCaps *caps;
+ GstElement *gdppay;
+ GstBuffer *inbuffer, *outbuffer;
+ GstEvent *event;
+ gchar *caps_string;
+ gint length;
+
+ gdppay = setup_gdppay ();
+
+ fail_unless (gst_element_set_state (gdppay,
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+ "could not set to playing");
+
+ GST_DEBUG ("new segment");
+ event =
+ gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, GST_SECOND, 0);
+ fail_unless (gst_pad_push_event (mysrcpad, event));
+
+ /* no buffer should be pushed yet, waiting for caps */
+ fail_unless_equals_int (g_list_length (buffers), 0);
+
+ GST_DEBUG ("first buffer");
+ inbuffer = gst_buffer_new_and_alloc (4);
+ caps = gst_caps_from_string (AUDIO_CAPS_STRING);
+ gst_buffer_set_caps (inbuffer, caps);
+ caps_string = gst_caps_to_string (caps);
+
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing gives away my reference */
+ fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
+
+ /* we should have three buffers now */
+ fail_unless_equals_int (g_list_length (buffers), 3);
+
+ /* first buffer is the serialized new_segment event;
+ * the element also holds a ref to it */
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2);
+ gst_buffer_unref (outbuffer);
+
+ /* second buffer is the serialized caps;
+ * the element also holds a ref to it */
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2);
+ length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1);
+ fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length);
+ gst_buffer_unref (outbuffer);
+
+ /* the third buffer is the GDP buffer for our pushed buffer */
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
+ length = GST_DP_HEADER_LENGTH + 4;
+ fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length);
+ gst_buffer_unref (outbuffer);
+
+ /* second buffer */
+ GST_DEBUG ("second buffer");
+ inbuffer = gst_buffer_new_and_alloc (4);
+ gst_buffer_set_caps (inbuffer, caps);
+
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing gives away my reference */
+ fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
+
+ fail_unless_equals_int (g_list_length (buffers), 1);
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
+
+ /* the third output buffer is data */
+ length = GST_DP_HEADER_LENGTH + 4;
+ fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length);
+ gst_buffer_unref (outbuffer);
+
+ /* a third buffer without caps set explicitly; should work */
+ GST_DEBUG ("Creating third buffer, no caps set");
+ inbuffer = gst_buffer_new_and_alloc (4);
+
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing gives away my reference */
+ fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
+
+ fail_unless_equals_int (g_list_length (buffers), 1);
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
+
+ /* the fourth output buffer is data */
+ length = GST_DP_HEADER_LENGTH + 4;
+ fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length);
+ gst_buffer_unref (outbuffer);
+
+
+ fail_unless (gst_element_set_state (gdppay,
+ GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
+
+ gst_caps_unref (caps);
+ g_free (caps_string);
+ ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1);
+ gst_object_unref (gdppay);
+}
+
+GST_END_TEST;
+
+static GstStaticPadTemplate shsrctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-gst-test-streamheader")
+ );
+
+
+GstElement *
+setup_gdppay_streamheader ()
+{
+ GstElement *gdppay;
+
+ GST_DEBUG ("setup_gdppay");
+ gdppay = gst_check_setup_element ("gdppay");
+ myshsrcpad = gst_check_setup_src_pad (gdppay, &shsrctemplate, NULL);
+ mysinkpad = gst_check_setup_sink_pad (gdppay, &sinktemplate, NULL);
+
+ return gdppay;
+}
+
+/* this test serializes a stream that already has a streamheader of its own.
+ * the streamheader should then be serialized and put on the GDP stream's
+ * streamheader */
+GST_START_TEST (test_streamheader)
+{
+ GstCaps *caps, *sinkcaps;
+ GstElement *gdppay;
+ GstBuffer *inbuffer, *outbuffer, *shbuffer;
+ GstEvent *event;
+ gchar *caps_string;
+ gint length;
+ GstStructure *structure;
+ GValue array = { 0 };
+ GValue value = { 0 };
+ const GValue *sh;
+ GArray *shbuffers;
+
+
+ gdppay = setup_gdppay_streamheader ();
+
+ fail_unless (gst_element_set_state (gdppay,
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+ "could not set to playing");
+
+ GST_DEBUG ("new segment");
+ event =
+ gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, GST_SECOND, 0);
+ fail_unless (gst_pad_push_event (myshsrcpad, event));
+
+ /* no buffer should be pushed yet, still waiting for caps */
+ fail_unless_equals_int (g_list_length (buffers), 0);
+
+ GST_DEBUG ("first buffer");
+ inbuffer = gst_buffer_new_and_alloc (4);
+ memcpy (GST_BUFFER_DATA (inbuffer), "head", 4);
+ caps = gst_caps_from_string ("application/x-gst-test-streamheader");
+ structure = gst_caps_get_structure (caps, 0);
+ GST_BUFFER_FLAG_SET (inbuffer, GST_BUFFER_FLAG_IN_CAPS);
+ g_value_init (&array, GST_TYPE_ARRAY);
+ g_value_init (&value, GST_TYPE_BUFFER);
+ shbuffer = gst_buffer_copy (inbuffer);
+ gst_value_set_buffer (&value, shbuffer);
+ gst_buffer_unref (shbuffer);
+ gst_value_array_append_value (&array, &value);
+ g_value_unset (&value);
+ gst_structure_set_value (structure, "streamheader", &array);
+ g_value_unset (&array);
+ caps_string = gst_caps_to_string (caps);
+
+ gst_buffer_set_caps (inbuffer, caps);
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing gives away my reference */
+ fail_unless (gst_pad_push (myshsrcpad, inbuffer) == GST_FLOW_OK);
+
+ /* we should have three buffers now */
+ fail_unless_equals_int (g_list_length (buffers), 3);
+
+ /* our sink pad should now have GDP caps with a streamheader that includes
+ * GDP wrappings of our streamheader */
+ sinkcaps = gst_pad_get_negotiated_caps (mysinkpad);
+ structure = gst_caps_get_structure (sinkcaps, 0);
+ fail_unless_equals_string ((gchar *) gst_structure_get_name (structure),
+ "application/x-gdp");
+ fail_unless (gst_structure_has_field (structure, "streamheader"));
+ sh = gst_structure_get_value (structure, "streamheader");
+ fail_unless (G_VALUE_TYPE (sh) == GST_TYPE_ARRAY);
+ shbuffers = g_value_peek_pointer (sh);
+ /* a serialized new_segment, a serialized caps, and serialization of our
+ * incoming streamheader */
+ fail_unless_equals_int (shbuffers->len, 3);
+
+ gst_caps_unref (sinkcaps);
+
+ /* first buffer is the serialized new_segment event;
+ * the element also holds a ref to it */
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2);
+ gst_buffer_unref (outbuffer);
+
+ /* second buffer is the serialized caps;
+ * the element also holds a ref to it */
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2);
+ length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1);
+ fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length);
+ gst_buffer_unref (outbuffer);
+
+ /* the third buffer is the GDP buffer for our pushed buffer */
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
+ length = GST_DP_HEADER_LENGTH + 4;
+ fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length);
+ gst_buffer_unref (outbuffer);
+
+ /* second buffer */
+ GST_DEBUG ("second buffer");
+ inbuffer = gst_buffer_new_and_alloc (4);
+ gst_buffer_set_caps (inbuffer, caps);
+
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing gives away my reference */
+ fail_unless (gst_pad_push (myshsrcpad, inbuffer) == GST_FLOW_OK);
+
+ fail_unless_equals_int (g_list_length (buffers), 1);
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
+
+ /* the third output buffer is data */
+ length = GST_DP_HEADER_LENGTH + 4;
+ fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length);
+ gst_buffer_unref (outbuffer);
+
+ /* a third buffer without caps set explicitly; should work */
+ GST_DEBUG ("Creating third buffer, no caps set");
+ inbuffer = gst_buffer_new_and_alloc (4);
+
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing gives away my reference */
+ fail_unless (gst_pad_push (myshsrcpad, inbuffer) == GST_FLOW_OK);
+
+ fail_unless_equals_int (g_list_length (buffers), 1);
+ fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
+ buffers = g_list_remove (buffers, outbuffer);
+ ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
+
+ /* the fourth output buffer is data */
+ length = GST_DP_HEADER_LENGTH + 4;
+ fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length);
+ gst_buffer_unref (outbuffer);
+
+
+ fail_unless (gst_element_set_state (gdppay,
+ GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
+
+ gst_caps_unref (caps);
+ g_free (caps_string);
+ ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1);
+ gst_object_unref (gdppay);
+}
+
+GST_END_TEST;
+
+
+GST_START_TEST (test_first_no_caps)
+{
+ GstElement *gdppay;
+ GstBuffer *inbuffer;
+
+ gdppay = setup_gdppay ();
+
+ fail_unless (gst_element_set_state (gdppay,
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+ "could not set to playing");
+
+ GST_DEBUG ("first buffer");
+ inbuffer = gst_buffer_new_and_alloc (4);
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing should trigger an error */
+ fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_NOT_NEGOTIATED);
+
+ fail_unless_equals_int (g_list_length (buffers), 0);
+
+ fail_unless (gst_element_set_state (gdppay,
+ GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
+
+ ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1);
+ gst_object_unref (gdppay);
+}
+
+GST_END_TEST;
+
+/* element should still work if no new_segment is sent before the first
+ * buffer */
+GST_START_TEST (test_first_no_new_segment)
+{
+ GstElement *gdppay;
+ GstBuffer *inbuffer;
+ GstCaps *caps;
+
+ gdppay = setup_gdppay ();
+
+ fail_unless (gst_element_set_state (gdppay,
+ GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+ "could not set to playing");
+
+ GST_DEBUG ("first buffer");
+ inbuffer = gst_buffer_new_and_alloc (4);
+ caps = gst_caps_from_string (AUDIO_CAPS_STRING);
+ gst_buffer_set_caps (inbuffer, caps);
+
+ ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
+
+ /* pushing gives away my reference */
+ fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
+
+ /* we should have three buffers now;
+ * one for an "invented" new segment, one for GDP caps, and one with our
+ * buffer */
+ fail_unless_equals_int (g_list_length (buffers), 3);
+
+ fail_unless (gst_element_set_state (gdppay,
+ GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
+
+ ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1);
+ gst_object_unref (gdppay);
+}
+
+GST_END_TEST;
+
+
+Suite *
+gdppay_suite (void)
+{
+ Suite *s = suite_create ("gdppay");
+ TCase *tc_chain = tcase_create ("general");
+
+ suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_audio);
+ tcase_add_test (tc_chain, test_first_no_caps);
+ tcase_add_test (tc_chain, test_first_no_new_segment);
+ tcase_add_test (tc_chain, test_streamheader);
+
+ return s;
+}
+
+int
+main (int argc, char **argv)
+{
+ int nf;
+
+ Suite *s = gdppay_suite ();
+ SRunner *sr = srunner_create (s);
+
+ gst_check_init (&argc, &argv);
+
+ srunner_run_all (sr, CK_NORMAL);
+ nf = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return nf;
+}