summaryrefslogtreecommitdiffstats
path: root/tests/check/elements
diff options
context:
space:
mode:
Diffstat (limited to 'tests/check/elements')
-rw-r--r--tests/check/elements/deinterleave.c558
-rw-r--r--tests/check/elements/interleave.c761
-rw-r--r--tests/check/elements/rganalysis.c1925
-rw-r--r--tests/check/elements/rglimiter.c268
-rw-r--r--tests/check/elements/rgvolume.c573
5 files changed, 0 insertions, 4085 deletions
diff --git a/tests/check/elements/deinterleave.c b/tests/check/elements/deinterleave.c
deleted file mode 100644
index 04ac41b3..00000000
--- a/tests/check/elements/deinterleave.c
+++ /dev/null
@@ -1,558 +0,0 @@
-/* GStreamer unit tests for the interleave element
- * Copyright (C) 2008 Sebastian Dröge <slomo@circular-chaos.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.
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <gst/check/gstcheck.h>
-#include <gst/audio/multichannel.h>
-
-GST_START_TEST (test_create_and_unref)
-{
- GstElement *deinterleave;
-
- deinterleave = gst_element_factory_make ("deinterleave", NULL);
- fail_unless (deinterleave != NULL);
-
- gst_element_set_state (deinterleave, GST_STATE_NULL);
- gst_object_unref (deinterleave);
-}
-
-GST_END_TEST;
-
-static GstPad *mysrcpad, **mysinkpads;
-static gint nsinkpads;
-static GstBus *bus;
-static GstElement *deinterleave;
-
-static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-float, "
- "width = (int) 32, "
- "channels = (int) 1, "
- "rate = (int) {32000, 48000}, " "endianness = (int) BYTE_ORDER"));
-
-static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-float, "
- "width = (int) 32, "
- "channels = (int) { 2, 3 }, "
- "rate = (int) {32000, 48000}, " "endianness = (int) BYTE_ORDER"));
-
-#define CAPS_32khz \
- "audio/x-raw-float, " \
- "width = (int) 32, " \
- "channels = (int) 2, " \
- "rate = (int) 32000, " \
- "endianness = (int) BYTE_ORDER"
-
-#define CAPS_48khz \
- "audio/x-raw-float, " \
- "width = (int) 32, " \
- "channels = (int) 2, " \
- "rate = (int) 48000, " \
- "endianness = (int) BYTE_ORDER"
-
-#define CAPS_48khz_3CH \
- "audio/x-raw-float, " \
- "width = (int) 32, " \
- "channels = (int) 3, " \
- "rate = (int) 48000, " \
- "endianness = (int) BYTE_ORDER"
-
-static GstFlowReturn
-deinterleave_chain_func (GstPad * pad, GstBuffer * buffer)
-{
- gint i;
- gfloat *indata;
-
- fail_unless (GST_IS_BUFFER (buffer));
- fail_unless_equals_int (GST_BUFFER_SIZE (buffer), 48000 * sizeof (gfloat));
- fail_unless (GST_BUFFER_DATA (buffer) != NULL);
-
- indata = (gfloat *) GST_BUFFER_DATA (buffer);
-
- if (strcmp (GST_PAD_NAME (pad), "sink0") == 0) {
- for (i = 0; i < 48000; i++)
- fail_unless_equals_float (indata[i], -1.0);
- } else if (strcmp (GST_PAD_NAME (pad), "sink1") == 0) {
- for (i = 0; i < 48000; i++)
- fail_unless_equals_float (indata[i], 1.0);
- } else {
- g_assert_not_reached ();
- }
-
- gst_buffer_unref (buffer);
-
- return GST_FLOW_OK;
-}
-
-static void
-deinterleave_pad_added (GstElement * src, GstPad * pad, gpointer data)
-{
- gchar *name;
- gint link = GPOINTER_TO_INT (data);
-
- if (nsinkpads >= link)
- return;
-
- name = g_strdup_printf ("sink%d", nsinkpads);
-
- mysinkpads[nsinkpads] =
- gst_pad_new_from_static_template (&sinktemplate, name);
- g_free (name);
- fail_if (mysinkpads[nsinkpads] == NULL);
-
- gst_pad_set_chain_function (mysinkpads[nsinkpads], deinterleave_chain_func);
- fail_unless (gst_pad_link (pad, mysinkpads[nsinkpads]) == GST_PAD_LINK_OK);
- gst_pad_set_active (mysinkpads[nsinkpads], TRUE);
- nsinkpads++;
-}
-
-GST_START_TEST (test_2_channels)
-{
- GstPad *sinkpad;
- gint i;
- GstBuffer *inbuf;
- GstCaps *caps;
- gfloat *indata;
-
- mysinkpads = g_new0 (GstPad *, 2);
- nsinkpads = 0;
-
- deinterleave = gst_element_factory_make ("deinterleave", NULL);
- fail_unless (deinterleave != NULL);
-
- mysrcpad = gst_pad_new_from_static_template (&srctemplate, "src");
- fail_unless (mysrcpad != NULL);
-
- caps = gst_caps_from_string (CAPS_48khz);
- fail_unless (gst_pad_set_caps (mysrcpad, caps));
- gst_pad_use_fixed_caps (mysrcpad);
-
- sinkpad = gst_element_get_static_pad (deinterleave, "sink");
- fail_unless (sinkpad != NULL);
- fail_unless (gst_pad_link (mysrcpad, sinkpad) == GST_PAD_LINK_OK);
- g_object_unref (sinkpad);
-
- g_signal_connect (deinterleave, "pad-added",
- G_CALLBACK (deinterleave_pad_added), GINT_TO_POINTER (2));
-
- bus = gst_bus_new ();
- gst_element_set_bus (deinterleave, bus);
-
- fail_unless (gst_element_set_state (deinterleave,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
-
- inbuf = gst_buffer_new_and_alloc (2 * 48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 2 * 48000; i += 2) {
- indata[i] = -1.0;
- indata[i + 1] = 1.0;
- }
- gst_buffer_set_caps (inbuf, caps);
-
- fail_unless (gst_pad_push (mysrcpad, inbuf) == GST_FLOW_OK);
-
- fail_unless (gst_element_set_state (deinterleave,
- GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
-
- for (i = 0; i < nsinkpads; i++)
- g_object_unref (mysinkpads[i]);
- g_free (mysinkpads);
- mysinkpads = NULL;
-
- g_object_unref (deinterleave);
- g_object_unref (bus);
- gst_caps_unref (caps);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_2_channels_1_linked)
-{
- GstPad *sinkpad;
- gint i;
- GstBuffer *inbuf;
- GstCaps *caps;
- gfloat *indata;
-
- nsinkpads = 0;
- mysinkpads = g_new0 (GstPad *, 2);
-
- deinterleave = gst_element_factory_make ("deinterleave", NULL);
- fail_unless (deinterleave != NULL);
-
- mysrcpad = gst_pad_new_from_static_template (&srctemplate, "src");
- fail_unless (mysrcpad != NULL);
-
- caps = gst_caps_from_string (CAPS_48khz);
- fail_unless (gst_pad_set_caps (mysrcpad, caps));
- gst_pad_use_fixed_caps (mysrcpad);
-
- sinkpad = gst_element_get_static_pad (deinterleave, "sink");
- fail_unless (sinkpad != NULL);
- fail_unless (gst_pad_link (mysrcpad, sinkpad) == GST_PAD_LINK_OK);
- g_object_unref (sinkpad);
-
- g_signal_connect (deinterleave, "pad-added",
- G_CALLBACK (deinterleave_pad_added), GINT_TO_POINTER (1));
-
- bus = gst_bus_new ();
- gst_element_set_bus (deinterleave, bus);
-
- fail_unless (gst_element_set_state (deinterleave,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
-
- inbuf = gst_buffer_new_and_alloc (2 * 48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 2 * 48000; i += 2) {
- indata[i] = -1.0;
- indata[i + 1] = 1.0;
- }
- gst_buffer_set_caps (inbuf, caps);
-
- fail_unless (gst_pad_push (mysrcpad, inbuf) == GST_FLOW_OK);
-
- fail_unless (gst_element_set_state (deinterleave,
- GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
-
- for (i = 0; i < nsinkpads; i++)
- g_object_unref (mysinkpads[i]);
- g_free (mysinkpads);
- mysinkpads = NULL;
-
- g_object_unref (deinterleave);
- g_object_unref (bus);
- gst_caps_unref (caps);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_2_channels_caps_change)
-{
- GstPad *sinkpad;
- GstCaps *caps, *caps2;
- gint i;
- GstBuffer *inbuf;
- gfloat *indata;
-
- nsinkpads = 0;
- mysinkpads = g_new0 (GstPad *, 2);
-
- deinterleave = gst_element_factory_make ("deinterleave", NULL);
- fail_unless (deinterleave != NULL);
-
- mysrcpad = gst_pad_new_from_static_template (&srctemplate, "src");
- fail_unless (mysrcpad != NULL);
-
- caps = gst_caps_from_string (CAPS_48khz);
- fail_unless (gst_pad_set_caps (mysrcpad, caps));
- gst_pad_use_fixed_caps (mysrcpad);
-
- sinkpad = gst_element_get_static_pad (deinterleave, "sink");
- fail_unless (sinkpad != NULL);
- fail_unless (gst_pad_link (mysrcpad, sinkpad) == GST_PAD_LINK_OK);
- g_object_unref (sinkpad);
-
- g_signal_connect (deinterleave, "pad-added",
- G_CALLBACK (deinterleave_pad_added), GINT_TO_POINTER (2));
-
- bus = gst_bus_new ();
- gst_element_set_bus (deinterleave, bus);
-
- fail_unless (gst_element_set_state (deinterleave,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
-
- inbuf = gst_buffer_new_and_alloc (2 * 48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 2 * 48000; i += 2) {
- indata[i] = -1.0;
- indata[i + 1] = 1.0;
- }
- gst_buffer_set_caps (inbuf, caps);
-
- fail_unless (gst_pad_push (mysrcpad, inbuf) == GST_FLOW_OK);
-
- caps2 = gst_caps_from_string (CAPS_32khz);
- gst_pad_set_caps (mysrcpad, caps2);
-
- inbuf = gst_buffer_new_and_alloc (2 * 48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 2 * 48000; i += 2) {
- indata[i] = -1.0;
- indata[i + 1] = 1.0;
- }
- gst_buffer_set_caps (inbuf, caps2);
-
- /* Should work fine because the caps changed in a compatible way */
- fail_unless (gst_pad_push (mysrcpad, inbuf) == GST_FLOW_OK);
-
- gst_caps_unref (caps2);
-
- caps2 = gst_caps_from_string (CAPS_48khz_3CH);
- gst_pad_set_caps (mysrcpad, caps2);
-
- inbuf = gst_buffer_new_and_alloc (3 * 48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 3 * 48000; i += 3) {
- indata[i] = -1.0;
- indata[i + 1] = 1.0;
- indata[i + 2] = 0.0;
- }
- gst_buffer_set_caps (inbuf, caps2);
-
- /* Should break because the caps changed in an incompatible way */
- fail_if (gst_pad_push (mysrcpad, inbuf) == GST_FLOW_OK);
-
- fail_unless (gst_element_set_state (deinterleave,
- GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
-
- for (i = 0; i < nsinkpads; i++)
- g_object_unref (mysinkpads[i]);
- g_free (mysinkpads);
- mysinkpads = NULL;
-
- g_object_unref (deinterleave);
- g_object_unref (bus);
- gst_caps_unref (caps);
- gst_caps_unref (caps2);
-}
-
-GST_END_TEST;
-
-
-#define SAMPLES_PER_BUFFER 10
-#define NUM_CHANNELS 8
-#define SAMPLE_RATE 44100
-
-static guint pads_created;
-
-static void
-set_channel_positions (GstCaps * caps, int channels,
- GstAudioChannelPosition * channelpositions)
-{
- GValue chanpos = { 0 };
- GValue pos = { 0 };
- GstStructure *structure = gst_caps_get_structure (caps, 0);
- int c;
-
- g_value_init (&chanpos, GST_TYPE_ARRAY);
- g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
-
- for (c = 0; c < channels; c++) {
- g_value_set_enum (&pos, channelpositions[c]);
- gst_value_array_append_value (&chanpos, &pos);
- }
- g_value_unset (&pos);
-
- gst_structure_set_value (structure, "channel-positions", &chanpos);
- g_value_unset (&chanpos);
-}
-
-static void
-src_handoff_float32_8ch (GstElement * src, GstBuffer * buf, GstPad * pad,
- gpointer user_data)
-{
- GstAudioChannelPosition layout[NUM_CHANNELS];
- GstCaps *caps;
- gfloat *data;
- guint size, i, c;
-
- caps = gst_caps_new_simple ("audio/x-raw-float",
- "width", G_TYPE_INT, 32,
- "depth", G_TYPE_INT, 32,
- "channels", G_TYPE_INT, NUM_CHANNELS,
- "rate", G_TYPE_INT, SAMPLE_RATE,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, NULL);
-
- for (i = 0; i < NUM_CHANNELS; ++i)
- layout[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
-
- set_channel_positions (caps, NUM_CHANNELS, layout);
-
- size = sizeof (gfloat) * SAMPLES_PER_BUFFER * NUM_CHANNELS;
- data = (gfloat *) g_malloc (size);
-
- GST_BUFFER_MALLOCDATA (buf) = (guint8 *) data;
- GST_BUFFER_DATA (buf) = (guint8 *) data;
- GST_BUFFER_SIZE (buf) = size;
-
- GST_BUFFER_OFFSET (buf) = 0;
- GST_BUFFER_TIMESTAMP (buf) = 0;
-
- for (i = 0; i < SAMPLES_PER_BUFFER; ++i) {
- for (c = 0; c < NUM_CHANNELS; ++c) {
- *data = (gfloat) ((i * NUM_CHANNELS) + c);
- ++data;
- }
- }
-
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-}
-
-static gboolean
-float_buffer_check_probe (GstPad * pad, GstBuffer * buf, gpointer userdata)
-{
- gfloat *data;
- guint padnum, numpads;
- guint num, i;
- GstCaps *caps;
- GstStructure *s;
- GstAudioChannelPosition *pos;
- gint channels;
-
- fail_unless_equals_int (sscanf (GST_PAD_NAME (pad), "src%u", &padnum), 1);
-
- numpads = pads_created;
-
- /* Check caps */
- caps = GST_BUFFER_CAPS (buf);
- fail_unless (caps != NULL);
- s = gst_caps_get_structure (caps, 0);
- fail_unless (gst_structure_get_int (s, "channels", &channels));
- fail_unless_equals_int (channels, 1);
- fail_unless (gst_structure_has_field (s, "channel-positions"));
- pos = gst_audio_get_channel_positions (s);
- fail_unless (pos != NULL && pos[0] == GST_AUDIO_CHANNEL_POSITION_NONE);
- g_free (pos);
-
- data = (gfloat *) GST_BUFFER_DATA (buf);
- num = GST_BUFFER_SIZE (buf) / sizeof (gfloat);
-
- /* Check buffer content */
- for (i = 0; i < num; ++i) {
- guint val, rest;
-
- val = (guint) data[i];
- GST_LOG ("%s[%u]: %8f", GST_PAD_NAME (pad), i, data[i]);
- /* can't use the modulo operator in the assertion statement, since due to
- * the way it gets expanded it would be interpreted as a printf operator
- * in the failure case, which will result in segfaults */
- rest = val % numpads;
- /* check that the first channel is on pad src0, the second on src1 etc. */
- fail_unless_equals_int (rest, padnum);
- }
-
- return TRUE; /* don't drop data */
-}
-
-static void
-pad_added_setup_data_check_float32_8ch_cb (GstElement * deinterleave,
- GstPad * pad, GstElement * pipeline)
-{
- GstElement *queue, *sink;
- GstPad *sinkpad;
-
- queue = gst_element_factory_make ("queue", NULL);
- fail_unless (queue != NULL);
-
- sink = gst_element_factory_make ("fakesink", NULL);
- fail_unless (sink != NULL);
-
- gst_bin_add_many (GST_BIN (pipeline), queue, sink, NULL);
- fail_unless (gst_element_link_many (queue, sink, NULL));
-
- sinkpad = gst_element_get_static_pad (queue, "sink");
- fail_unless_equals_int (gst_pad_link (pad, sinkpad), GST_PAD_LINK_OK);
- gst_object_unref (sinkpad);
-
- gst_pad_add_buffer_probe (pad, G_CALLBACK (float_buffer_check_probe), NULL);
-
- gst_element_set_state (sink, GST_STATE_PLAYING);
- gst_element_set_state (queue, GST_STATE_PLAYING);
-
- GST_LOG ("new pad: %s", GST_PAD_NAME (pad));
- ++pads_created;
-}
-
-static GstElement *
-make_fake_src_8chans_float32 (void)
-{
- GstElement *src;
-
- src = gst_element_factory_make ("fakesrc", "src");
- fail_unless (src != NULL, "failed to create fakesrc element");
-
- g_object_set (src, "num-buffers", 1, NULL);
- g_object_set (src, "signal-handoffs", TRUE, NULL);
-
- g_signal_connect (src, "handoff", G_CALLBACK (src_handoff_float32_8ch), NULL);
-
- return src;
-}
-
-GST_START_TEST (test_8_channels_float32)
-{
- GstElement *pipeline, *src, *deinterleave;
- GstMessage *msg;
-
- pipeline = (GstElement *) gst_pipeline_new ("pipeline");
- fail_unless (pipeline != NULL, "failed to create pipeline");
-
- src = make_fake_src_8chans_float32 ();
-
- deinterleave = gst_element_factory_make ("deinterleave", "deinterleave");
- fail_unless (deinterleave != NULL, "failed to create deinterleave element");
- g_object_set (deinterleave, "keep-positions", TRUE, NULL);
-
- gst_bin_add_many (GST_BIN (pipeline), src, deinterleave, NULL);
-
- fail_unless (gst_element_link (src, deinterleave),
- "failed to link src <=> deinterleave");
-
- g_signal_connect (deinterleave, "pad-added",
- G_CALLBACK (pad_added_setup_data_check_float32_8ch_cb), pipeline);
-
- pads_created = 0;
-
- gst_element_set_state (pipeline, GST_STATE_PLAYING);
-
- msg = gst_bus_poll (GST_ELEMENT_BUS (pipeline), GST_MESSAGE_EOS, -1);
- gst_message_unref (msg);
-
- fail_unless_equals_int (pads_created, NUM_CHANNELS);
-
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_object_unref (pipeline);
-}
-
-GST_END_TEST;
-
-static Suite *
-deinterleave_suite (void)
-{
- Suite *s = suite_create ("deinterleave");
- TCase *tc_chain = tcase_create ("general");
-
- suite_add_tcase (s, tc_chain);
- tcase_add_test (tc_chain, test_create_and_unref);
- tcase_add_test (tc_chain, test_2_channels);
- tcase_add_test (tc_chain, test_2_channels_1_linked);
- tcase_add_test (tc_chain, test_2_channels_caps_change);
- tcase_add_test (tc_chain, test_8_channels_float32);
-
- return s;
-}
-
-GST_CHECK_MAIN (deinterleave);
diff --git a/tests/check/elements/interleave.c b/tests/check/elements/interleave.c
deleted file mode 100644
index 6b476046..00000000
--- a/tests/check/elements/interleave.c
+++ /dev/null
@@ -1,761 +0,0 @@
-/* GStreamer unit tests for the interleave element
- * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
- * Copyright (C) 2008 Sebastian Dröge <slomo@circular-chaos.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.
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <gst/check/gstcheck.h>
-#include <gst/audio/multichannel.h>
-
-GST_START_TEST (test_create_and_unref)
-{
- GstElement *interleave;
-
- interleave = gst_element_factory_make ("interleave", NULL);
- fail_unless (interleave != NULL);
-
- gst_element_set_state (interleave, GST_STATE_NULL);
- gst_object_unref (interleave);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_request_pads)
-{
- GstElement *interleave;
-
- GstPad *pad1, *pad2;
-
- interleave = gst_element_factory_make ("interleave", NULL);
- fail_unless (interleave != NULL);
-
- pad1 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (pad1 != NULL);
- fail_unless_equals_string (GST_OBJECT_NAME (pad1), "sink0");
-
- pad2 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (pad2 != NULL);
- fail_unless_equals_string (GST_OBJECT_NAME (pad2), "sink1");
-
- gst_element_release_request_pad (interleave, pad2);
- gst_object_unref (pad2);
- gst_element_release_request_pad (interleave, pad1);
- gst_object_unref (pad1);
-
- gst_element_set_state (interleave, GST_STATE_NULL);
- gst_object_unref (interleave);
-}
-
-GST_END_TEST;
-
-static GstPad **mysrcpads, *mysinkpad;
-
-static GstBus *bus;
-
-static GstElement *interleave;
-
-static gint have_data;
-
-static gfloat input[2];
-
-static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-float, "
- "width = (int) 32, "
- "channels = (int) 2, "
- "rate = (int) 48000, " "endianness = (int) BYTE_ORDER"));
-
-static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("audio/x-raw-float, "
- "width = (int) 32, "
- "channels = (int) 1, "
- "rate = (int) 48000, " "endianness = (int) BYTE_ORDER"));
-
-#define CAPS_48khz \
- "audio/x-raw-float, " \
- "width = (int) 32, " \
- "channels = (int) 1, " \
- "rate = (int) 48000, " \
- "endianness = (int) BYTE_ORDER"
-
-static GstFlowReturn
-interleave_chain_func (GstPad * pad, GstBuffer * buffer)
-{
- gfloat *outdata;
-
- gint i;
-
- fail_unless (GST_IS_BUFFER (buffer));
- fail_unless_equals_int (GST_BUFFER_SIZE (buffer),
- 48000 * 2 * sizeof (gfloat));
- fail_unless (GST_BUFFER_DATA (buffer) != NULL);
-
- outdata = (gfloat *) GST_BUFFER_DATA (buffer);
-
- for (i = 0; i < 48000 * 2; i += 2) {
- fail_unless_equals_float (outdata[i], input[0]);
- fail_unless_equals_float (outdata[i + 1], input[1]);
- }
-
- have_data++;
-
- gst_buffer_unref (buffer);
-
- return GST_FLOW_OK;
-}
-
-GST_START_TEST (test_interleave_2ch)
-{
- GstElement *queue;
-
- GstPad *sink0, *sink1, *src, *tmp;
-
- GstCaps *caps;
-
- gint i;
-
- GstBuffer *inbuf;
-
- gfloat *indata;
-
- mysrcpads = g_new0 (GstPad *, 2);
-
- have_data = 0;
-
- interleave = gst_element_factory_make ("interleave", NULL);
- fail_unless (interleave != NULL);
-
- queue = gst_element_factory_make ("queue", "queue");
- fail_unless (queue != NULL);
-
- sink0 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sink0 != NULL);
- fail_unless_equals_string (GST_OBJECT_NAME (sink0), "sink0");
-
- sink1 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sink1 != NULL);
- fail_unless_equals_string (GST_OBJECT_NAME (sink1), "sink1");
-
- mysrcpads[0] = gst_pad_new_from_static_template (&srctemplate, "src0");
- fail_unless (mysrcpads[0] != NULL);
-
- caps = gst_caps_from_string (CAPS_48khz);
- fail_unless (gst_pad_set_caps (mysrcpads[0], caps));
- gst_pad_use_fixed_caps (mysrcpads[0]);
-
- mysrcpads[1] = gst_pad_new_from_static_template (&srctemplate, "src1");
- fail_unless (mysrcpads[1] != NULL);
-
- fail_unless (gst_pad_set_caps (mysrcpads[1], caps));
- gst_pad_use_fixed_caps (mysrcpads[1]);
-
- tmp = gst_element_get_static_pad (queue, "sink");
- fail_unless (gst_pad_link (mysrcpads[0], tmp) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
- tmp = gst_element_get_static_pad (queue, "src");
- fail_unless (gst_pad_link (tmp, sink0) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
-
- fail_unless (gst_pad_link (mysrcpads[1], sink1) == GST_PAD_LINK_OK);
-
- mysinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
- fail_unless (mysinkpad != NULL);
- gst_pad_set_chain_function (mysinkpad, interleave_chain_func);
- gst_pad_set_active (mysinkpad, TRUE);
-
- src = gst_element_get_static_pad (interleave, "src");
- fail_unless (src != NULL);
- fail_unless (gst_pad_link (src, mysinkpad) == GST_PAD_LINK_OK);
- gst_object_unref (src);
-
- bus = gst_bus_new ();
- gst_element_set_bus (interleave, bus);
-
- fail_unless (gst_element_set_state (interleave,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
- fail_unless (gst_element_set_state (queue,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
-
- input[0] = -1.0;
- inbuf = gst_buffer_new_and_alloc (48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 48000; i++)
- indata[i] = -1.0;
- gst_buffer_set_caps (inbuf, caps);
- fail_unless (gst_pad_push (mysrcpads[0], inbuf) == GST_FLOW_OK);
-
- input[1] = 1.0;
- inbuf = gst_buffer_new_and_alloc (48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 48000; i++)
- indata[i] = 1.0;
- gst_buffer_set_caps (inbuf, caps);
- fail_unless (gst_pad_push (mysrcpads[1], inbuf) == GST_FLOW_OK);
-
- inbuf = gst_buffer_new_and_alloc (48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 48000; i++)
- indata[i] = -1.0;
- gst_buffer_set_caps (inbuf, caps);
- fail_unless (gst_pad_push (mysrcpads[0], inbuf) == GST_FLOW_OK);
-
- inbuf = gst_buffer_new_and_alloc (48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 48000; i++)
- indata[i] = 1.0;
- gst_buffer_set_caps (inbuf, caps);
- fail_unless (gst_pad_push (mysrcpads[1], inbuf) == GST_FLOW_OK);
-
- fail_unless (have_data == 2);
-
- gst_object_unref (mysrcpads[0]);
- gst_object_unref (mysrcpads[1]);
- gst_object_unref (mysinkpad);
-
- gst_element_release_request_pad (interleave, sink0);
- gst_object_unref (sink0);
- gst_element_release_request_pad (interleave, sink1);
- gst_object_unref (sink1);
-
- gst_element_set_state (interleave, GST_STATE_NULL);
- gst_element_set_state (queue, GST_STATE_NULL);
- gst_object_unref (interleave);
- gst_object_unref (queue);
- gst_object_unref (bus);
- gst_caps_unref (caps);
-
- g_free (mysrcpads);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_interleave_2ch_1eos)
-{
- GstElement *queue;
-
- GstPad *sink0, *sink1, *src, *tmp;
-
- GstCaps *caps;
-
- gint i;
-
- GstBuffer *inbuf;
-
- gfloat *indata;
-
- mysrcpads = g_new0 (GstPad *, 2);
-
- have_data = 0;
-
- interleave = gst_element_factory_make ("interleave", NULL);
- fail_unless (interleave != NULL);
-
- queue = gst_element_factory_make ("queue", "queue");
- fail_unless (queue != NULL);
-
- sink0 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sink0 != NULL);
- fail_unless_equals_string (GST_OBJECT_NAME (sink0), "sink0");
-
- sink1 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sink1 != NULL);
- fail_unless_equals_string (GST_OBJECT_NAME (sink1), "sink1");
-
- mysrcpads[0] = gst_pad_new_from_static_template (&srctemplate, "src0");
- fail_unless (mysrcpads[0] != NULL);
-
- caps = gst_caps_from_string (CAPS_48khz);
- fail_unless (gst_pad_set_caps (mysrcpads[0], caps));
- gst_pad_use_fixed_caps (mysrcpads[0]);
-
- mysrcpads[1] = gst_pad_new_from_static_template (&srctemplate, "src1");
- fail_unless (mysrcpads[1] != NULL);
-
- fail_unless (gst_pad_set_caps (mysrcpads[1], caps));
- gst_pad_use_fixed_caps (mysrcpads[1]);
-
- tmp = gst_element_get_static_pad (queue, "sink");
- fail_unless (gst_pad_link (mysrcpads[0], tmp) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
- tmp = gst_element_get_static_pad (queue, "src");
- fail_unless (gst_pad_link (tmp, sink0) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
-
- fail_unless (gst_pad_link (mysrcpads[1], sink1) == GST_PAD_LINK_OK);
-
- mysinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
- fail_unless (mysinkpad != NULL);
- gst_pad_set_chain_function (mysinkpad, interleave_chain_func);
- gst_pad_set_active (mysinkpad, TRUE);
-
- src = gst_element_get_static_pad (interleave, "src");
- fail_unless (src != NULL);
- fail_unless (gst_pad_link (src, mysinkpad) == GST_PAD_LINK_OK);
- gst_object_unref (src);
-
- bus = gst_bus_new ();
- gst_element_set_bus (interleave, bus);
-
- fail_unless (gst_element_set_state (interleave,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
- fail_unless (gst_element_set_state (queue,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
-
- input[0] = -1.0;
- inbuf = gst_buffer_new_and_alloc (48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 48000; i++)
- indata[i] = -1.0;
- gst_buffer_set_caps (inbuf, caps);
- fail_unless (gst_pad_push (mysrcpads[0], inbuf) == GST_FLOW_OK);
-
- input[1] = 1.0;
- inbuf = gst_buffer_new_and_alloc (48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 48000; i++)
- indata[i] = 1.0;
- gst_buffer_set_caps (inbuf, caps);
- fail_unless (gst_pad_push (mysrcpads[1], inbuf) == GST_FLOW_OK);
-
- input[0] = 0.0;
- gst_pad_push_event (mysrcpads[0], gst_event_new_eos ());
-
- input[1] = 1.0;
- inbuf = gst_buffer_new_and_alloc (48000 * sizeof (gfloat));
- indata = (gfloat *) GST_BUFFER_DATA (inbuf);
- for (i = 0; i < 48000; i++)
- indata[i] = 1.0;
- gst_buffer_set_caps (inbuf, caps);
- fail_unless (gst_pad_push (mysrcpads[1], inbuf) == GST_FLOW_OK);
-
- fail_unless (have_data == 2);
-
- gst_object_unref (mysrcpads[0]);
- gst_object_unref (mysrcpads[1]);
- gst_object_unref (mysinkpad);
-
- gst_element_release_request_pad (interleave, sink0);
- gst_object_unref (sink0);
- gst_element_release_request_pad (interleave, sink1);
- gst_object_unref (sink1);
-
- gst_element_set_state (interleave, GST_STATE_NULL);
- gst_element_set_state (queue, GST_STATE_NULL);
- gst_object_unref (interleave);
- gst_object_unref (queue);
- gst_object_unref (bus);
- gst_caps_unref (caps);
-
- g_free (mysrcpads);
-}
-
-GST_END_TEST;
-
-static void
-src_handoff_float32 (GstElement * element, GstBuffer * buffer, GstPad * pad,
- gpointer user_data)
-{
- gint n = GPOINTER_TO_INT (user_data);
-
- GstCaps *caps;
-
- gfloat *data;
-
- gint i;
-
- if (GST_PAD_CAPS (pad))
- caps = gst_caps_ref (GST_PAD_CAPS (pad));
- else {
- caps = gst_caps_new_simple ("audio/x-raw-float",
- "width", G_TYPE_INT, 32,
- "channels", G_TYPE_INT, 1,
- "rate", G_TYPE_INT, 48000, "endianness", G_TYPE_INT, G_BYTE_ORDER,
- NULL);
-
- if (n == 2) {
- GstAudioChannelPosition pos[1] =
- { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT };
- gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
- } else if (n == 3) {
- GstAudioChannelPosition pos[1] =
- { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT };
- gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
- }
- }
-
- data = g_new (gfloat, 48000);
- GST_BUFFER_MALLOCDATA (buffer) = (guint8 *) data;
- GST_BUFFER_DATA (buffer) = (guint8 *) data;
- GST_BUFFER_SIZE (buffer) = 48000 * sizeof (gfloat);
-
- GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
- GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
- GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
- GST_BUFFER_DURATION (buffer) = GST_SECOND;
-
- gst_buffer_set_caps (buffer, caps);
- gst_caps_unref (caps);
-
- for (i = 0; i < 48000; i++)
- data[i] = (n % 2 == 0) ? -1.0 : 1.0;
-}
-
-static void
-sink_handoff_float32 (GstElement * element, GstBuffer * buffer, GstPad * pad,
- gpointer user_data)
-{
- gint i;
-
- gfloat *data;
-
- GstCaps *caps;
-
- gint n = GPOINTER_TO_INT (user_data);
-
- fail_unless (GST_IS_BUFFER (buffer));
- fail_unless_equals_int (GST_BUFFER_SIZE (buffer),
- 48000 * 2 * sizeof (gfloat));
- fail_unless_equals_int (GST_BUFFER_DURATION (buffer), GST_SECOND);
-
- caps = gst_caps_new_simple ("audio/x-raw-float",
- "width", G_TYPE_INT, 32,
- "channels", G_TYPE_INT, 2,
- "rate", G_TYPE_INT, 48000, "endianness", G_TYPE_INT, G_BYTE_ORDER, NULL);
-
- if (n == 0) {
- GstAudioChannelPosition pos[2] =
- { GST_AUDIO_CHANNEL_POSITION_NONE, GST_AUDIO_CHANNEL_POSITION_NONE };
- gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
- } else if (n == 1) {
- GstAudioChannelPosition pos[2] = { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
- GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
- };
- gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
- } else if (n == 2) {
- GstAudioChannelPosition pos[2] = { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
- GST_AUDIO_CHANNEL_POSITION_REAR_CENTER
- };
- gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
- }
-
- fail_unless (gst_caps_is_equal (caps, GST_BUFFER_CAPS (buffer)));
- gst_caps_unref (caps);
-
- data = (gfloat *) GST_BUFFER_DATA (buffer);
-
- for (i = 0; i < 48000 * 2; i += 2) {
- fail_unless_equals_float (data[i], -1.0);
- fail_unless_equals_float (data[i + 1], 1.0);
- }
-
- have_data++;
-}
-
-GST_START_TEST (test_interleave_2ch_pipeline)
-{
- GstElement *pipeline, *queue, *src1, *src2, *interleave, *sink;
-
- GstPad *sinkpad0, *sinkpad1, *tmp, *tmp2;
-
- GstMessage *msg;
-
- have_data = 0;
-
- pipeline = (GstElement *) gst_pipeline_new ("pipeline");
- fail_unless (pipeline != NULL);
-
- src1 = gst_element_factory_make ("fakesrc", "src1");
- fail_unless (src1 != NULL);
- g_object_set (src1, "num-buffers", 4, NULL);
- g_object_set (src1, "signal-handoffs", TRUE, NULL);
- g_signal_connect (src1, "handoff", G_CALLBACK (src_handoff_float32),
- GINT_TO_POINTER (0));
- gst_bin_add (GST_BIN (pipeline), src1);
-
- src2 = gst_element_factory_make ("fakesrc", "src2");
- fail_unless (src2 != NULL);
- g_object_set (src2, "num-buffers", 4, NULL);
- g_object_set (src2, "signal-handoffs", TRUE, NULL);
- g_signal_connect (src2, "handoff", G_CALLBACK (src_handoff_float32),
- GINT_TO_POINTER (1));
- gst_bin_add (GST_BIN (pipeline), src2);
-
- queue = gst_element_factory_make ("queue", "queue");
- fail_unless (queue != NULL);
- gst_bin_add (GST_BIN (pipeline), queue);
-
- interleave = gst_element_factory_make ("interleave", "interleave");
- fail_unless (interleave != NULL);
- gst_bin_add (GST_BIN (pipeline), gst_object_ref (interleave));
-
- sinkpad0 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sinkpad0 != NULL);
- tmp = gst_element_get_static_pad (src1, "src");
- fail_unless (gst_pad_link (tmp, sinkpad0) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
-
- sinkpad1 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sinkpad1 != NULL);
- tmp = gst_element_get_static_pad (src2, "src");
- tmp2 = gst_element_get_static_pad (queue, "sink");
- fail_unless (gst_pad_link (tmp, tmp2) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
- gst_object_unref (tmp2);
- tmp = gst_element_get_static_pad (queue, "src");
- fail_unless (gst_pad_link (tmp, sinkpad1) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
-
- sink = gst_element_factory_make ("fakesink", "sink");
- fail_unless (sink != NULL);
- g_object_set (sink, "signal-handoffs", TRUE, NULL);
- g_signal_connect (sink, "handoff", G_CALLBACK (sink_handoff_float32),
- GINT_TO_POINTER (0));
- gst_bin_add (GST_BIN (pipeline), sink);
- tmp = gst_element_get_static_pad (interleave, "src");
- tmp2 = gst_element_get_static_pad (sink, "sink");
- fail_unless (gst_pad_link (tmp, tmp2) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
- gst_object_unref (tmp2);
-
- gst_element_set_state (pipeline, GST_STATE_PLAYING);
-
- msg = gst_bus_poll (GST_ELEMENT_BUS (pipeline), GST_MESSAGE_EOS, -1);
- gst_message_unref (msg);
-
- fail_unless (have_data == 4);
-
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_element_release_request_pad (interleave, sinkpad0);
- gst_object_unref (sinkpad0);
- gst_element_release_request_pad (interleave, sinkpad1);
- gst_object_unref (sinkpad1);
- gst_object_unref (interleave);
- gst_object_unref (pipeline);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_interleave_2ch_pipeline_input_chanpos)
-{
- GstElement *pipeline, *queue, *src1, *src2, *interleave, *sink;
-
- GstPad *sinkpad0, *sinkpad1, *tmp, *tmp2;
-
- GstMessage *msg;
-
- have_data = 0;
-
- pipeline = (GstElement *) gst_pipeline_new ("pipeline");
- fail_unless (pipeline != NULL);
-
- src1 = gst_element_factory_make ("fakesrc", "src1");
- fail_unless (src1 != NULL);
- g_object_set (src1, "num-buffers", 4, NULL);
- g_object_set (src1, "signal-handoffs", TRUE, NULL);
- g_signal_connect (src1, "handoff", G_CALLBACK (src_handoff_float32),
- GINT_TO_POINTER (2));
- gst_bin_add (GST_BIN (pipeline), src1);
-
- src2 = gst_element_factory_make ("fakesrc", "src2");
- fail_unless (src2 != NULL);
- g_object_set (src2, "num-buffers", 4, NULL);
- g_object_set (src2, "signal-handoffs", TRUE, NULL);
- g_signal_connect (src2, "handoff", G_CALLBACK (src_handoff_float32),
- GINT_TO_POINTER (3));
- gst_bin_add (GST_BIN (pipeline), src2);
-
- queue = gst_element_factory_make ("queue", "queue");
- fail_unless (queue != NULL);
- gst_bin_add (GST_BIN (pipeline), queue);
-
- interleave = gst_element_factory_make ("interleave", "interleave");
- fail_unless (interleave != NULL);
- g_object_set (interleave, "channel-positions-from-input", TRUE, NULL);
- gst_bin_add (GST_BIN (pipeline), gst_object_ref (interleave));
-
- sinkpad0 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sinkpad0 != NULL);
- tmp = gst_element_get_static_pad (src1, "src");
- fail_unless (gst_pad_link (tmp, sinkpad0) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
-
- sinkpad1 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sinkpad1 != NULL);
- tmp = gst_element_get_static_pad (src2, "src");
- tmp2 = gst_element_get_static_pad (queue, "sink");
- fail_unless (gst_pad_link (tmp, tmp2) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
- gst_object_unref (tmp2);
- tmp = gst_element_get_static_pad (queue, "src");
- fail_unless (gst_pad_link (tmp, sinkpad1) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
-
- sink = gst_element_factory_make ("fakesink", "sink");
- fail_unless (sink != NULL);
- g_object_set (sink, "signal-handoffs", TRUE, NULL);
- g_signal_connect (sink, "handoff", G_CALLBACK (sink_handoff_float32),
- GINT_TO_POINTER (1));
- gst_bin_add (GST_BIN (pipeline), sink);
- tmp = gst_element_get_static_pad (interleave, "src");
- tmp2 = gst_element_get_static_pad (sink, "sink");
- fail_unless (gst_pad_link (tmp, tmp2) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
- gst_object_unref (tmp2);
-
- gst_element_set_state (pipeline, GST_STATE_PLAYING);
-
- msg = gst_bus_poll (GST_ELEMENT_BUS (pipeline), GST_MESSAGE_EOS, -1);
- gst_message_unref (msg);
-
- fail_unless (have_data == 4);
-
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_element_release_request_pad (interleave, sinkpad0);
- gst_object_unref (sinkpad0);
- gst_element_release_request_pad (interleave, sinkpad1);
- gst_object_unref (sinkpad1);
- gst_object_unref (interleave);
- gst_object_unref (pipeline);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_interleave_2ch_pipeline_custom_chanpos)
-{
- GstElement *pipeline, *queue, *src1, *src2, *interleave, *sink;
-
- GstPad *sinkpad0, *sinkpad1, *tmp, *tmp2;
-
- GstMessage *msg;
-
- GValueArray *arr;
- GValue val = { 0, };
-
- have_data = 0;
-
- pipeline = (GstElement *) gst_pipeline_new ("pipeline");
- fail_unless (pipeline != NULL);
-
- src1 = gst_element_factory_make ("fakesrc", "src1");
- fail_unless (src1 != NULL);
- g_object_set (src1, "num-buffers", 4, NULL);
- g_object_set (src1, "signal-handoffs", TRUE, NULL);
- g_signal_connect (src1, "handoff", G_CALLBACK (src_handoff_float32),
- GINT_TO_POINTER (0));
- gst_bin_add (GST_BIN (pipeline), src1);
-
- src2 = gst_element_factory_make ("fakesrc", "src2");
- fail_unless (src2 != NULL);
- g_object_set (src2, "num-buffers", 4, NULL);
- g_object_set (src2, "signal-handoffs", TRUE, NULL);
- g_signal_connect (src2, "handoff", G_CALLBACK (src_handoff_float32),
- GINT_TO_POINTER (1));
- gst_bin_add (GST_BIN (pipeline), src2);
-
- queue = gst_element_factory_make ("queue", "queue");
- fail_unless (queue != NULL);
- gst_bin_add (GST_BIN (pipeline), queue);
-
- interleave = gst_element_factory_make ("interleave", "interleave");
- fail_unless (interleave != NULL);
- g_object_set (interleave, "channel-positions-from-input", FALSE, NULL);
- arr = g_value_array_new (2);
- g_value_init (&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
- g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER);
- g_value_array_append (arr, &val);
- g_value_reset (&val);
- g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER);
- g_value_array_append (arr, &val);
- g_value_unset (&val);
- g_object_set (interleave, "channel-positions", arr, NULL);
- g_value_array_free (arr);
- gst_bin_add (GST_BIN (pipeline), gst_object_ref (interleave));
-
- sinkpad0 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sinkpad0 != NULL);
- tmp = gst_element_get_static_pad (src1, "src");
- fail_unless (gst_pad_link (tmp, sinkpad0) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
-
- sinkpad1 = gst_element_get_request_pad (interleave, "sink%d");
- fail_unless (sinkpad1 != NULL);
- tmp = gst_element_get_static_pad (src2, "src");
- tmp2 = gst_element_get_static_pad (queue, "sink");
- fail_unless (gst_pad_link (tmp, tmp2) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
- gst_object_unref (tmp2);
- tmp = gst_element_get_static_pad (queue, "src");
- fail_unless (gst_pad_link (tmp, sinkpad1) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
-
- sink = gst_element_factory_make ("fakesink", "sink");
- fail_unless (sink != NULL);
- g_object_set (sink, "signal-handoffs", TRUE, NULL);
- g_signal_connect (sink, "handoff", G_CALLBACK (sink_handoff_float32),
- GINT_TO_POINTER (2));
- gst_bin_add (GST_BIN (pipeline), sink);
- tmp = gst_element_get_static_pad (interleave, "src");
- tmp2 = gst_element_get_static_pad (sink, "sink");
- fail_unless (gst_pad_link (tmp, tmp2) == GST_PAD_LINK_OK);
- gst_object_unref (tmp);
- gst_object_unref (tmp2);
-
- gst_element_set_state (pipeline, GST_STATE_PLAYING);
-
- msg = gst_bus_poll (GST_ELEMENT_BUS (pipeline), GST_MESSAGE_EOS, -1);
- gst_message_unref (msg);
-
- fail_unless (have_data == 4);
-
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_element_release_request_pad (interleave, sinkpad0);
- gst_object_unref (sinkpad0);
- gst_element_release_request_pad (interleave, sinkpad1);
- gst_object_unref (sinkpad1);
- gst_object_unref (interleave);
- gst_object_unref (pipeline);
-}
-
-GST_END_TEST;
-
-static Suite *
-interleave_suite (void)
-{
- Suite *s = suite_create ("interleave");
-
- TCase *tc_chain = tcase_create ("general");
-
- suite_add_tcase (s, tc_chain);
- tcase_add_test (tc_chain, test_create_and_unref);
- tcase_add_test (tc_chain, test_request_pads);
- tcase_add_test (tc_chain, test_interleave_2ch);
- tcase_add_test (tc_chain, test_interleave_2ch_1eos);
- tcase_add_test (tc_chain, test_interleave_2ch_pipeline);
- tcase_add_test (tc_chain, test_interleave_2ch_pipeline_input_chanpos);
- tcase_add_test (tc_chain, test_interleave_2ch_pipeline_custom_chanpos);
-
- return s;
-}
-
-GST_CHECK_MAIN (interleave);
diff --git a/tests/check/elements/rganalysis.c b/tests/check/elements/rganalysis.c
deleted file mode 100644
index 0045cb94..00000000
--- a/tests/check/elements/rganalysis.c
+++ /dev/null
@@ -1,1925 +0,0 @@
-/* GStreamer ReplayGain analysis
- *
- * Copyright (C) 2006 Rene Stadler <mail@renestadler.de>
- *
- * rganalysis.c: Unit test for the rganalysis element
- *
- * 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
- */
-
-/* Some things to note about the RMS window length of the analysis algorithm and
- * thus the implementation used in the element: Processing divides input data
- * into 50ms windows at some point. Some details about this that normally do
- * not matter:
- *
- * 1. At the end of a stream, the remainder of data that did not fill up the
- * last 50ms window is simply discarded.
- *
- * 2. If the sample rate changes during a stream, the currently running window
- * is discarded and the equal loudness filter gets reset as if a new stream
- * started.
- *
- * 3. For the album gain, it is not entirely correct to think of obtaining it
- * like "as if all the tracks are analyzed as one track". There isn't a
- * separate window being tracked for album processing, so at stream (track)
- * end, the remaining unfilled window does not contribute to the album gain
- * either.
- *
- * 4. If a waveform with a result gain G is concatenated to itself and the
- * result processed as a track, the gain can be different from G if and only
- * if the duration of the original waveform is not an integer multiple of
- * 50ms. If the original waveform gets processed as a single track and then
- * the same data again as a subsequent track, the album result gain will
- * always match G (this is implied by 3.).
- *
- * 5. A stream shorter than 50ms cannot be analyzed. At 8000 and 48000 Hz,
- * this corresponds to 400 resp. 2400 frames. If a stream is shorter than
- * 50ms, the element will not generate tags at EOS (only if an album
- * finished, but only album tags are generated then). This is not an
- * erroneous condition, the element should behave normally.
- *
- * The limitations outlined in 1.-4. do not apply to the peak values. Every
- * single sample is accounted for when looking for the peak. Thus the album
- * peak is guaranteed to be the maximum value of all track peaks.
- *
- * In normal day-to-day use, these little facts are unlikely to be relevant, but
- * they have to be kept in mind for writing the tests here.
- */
-
-#include <gst/check/gstcheck.h>
-
-GList *buffers = NULL;
-
-/* 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 */
-static GstPad *mysrcpad, *mysinkpad;
-
-/* Mapping from supported sample rates to the correct result gain for the
- * following test waveform: 20 * 512 samples with a quarter-full amplitude of
- * toggling sign, changing every 48 samples and starting with the positive
- * value.
- *
- * Even if we would generate a wave describing a signal with the same frequency
- * at each sampling rate, the results would vary (slightly). Hence the simple
- * generation method, since we cannot use a constant value as expected result
- * anyways. For all sample rates, changing the sign every 48 frames gives a
- * sane frequency. Buffers containing data that forms such a waveform is
- * created using the test_buffer_square_{float,int16}_{mono,stereo} functions
- * below.
- *
- * The results have been checked against what the metaflac and wavegain programs
- * generate for such a stream. If you want to verify these, be sure that the
- * metaflac program does not produce incorrect results in your environment: I
- * found a strange bug in the (defacto) reference code for the analysis that
- * sometimes leads to incorrect RMS window lengths. */
-
-struct rate_test
-{
- guint sample_rate;
- gdouble gain;
-};
-
-static const struct rate_test supported_rates[] = {
- {8000, -0.91},
- {11025, -2.80},
- {12000, -3.13},
- {16000, -4.26},
- {22050, -5.64},
- {24000, -5.87},
- {32000, -6.03},
- {44100, -6.20},
- {48000, -6.14}
-};
-
-/* Lookup the correct gain adjustment result in above array. */
-
-static gdouble
-get_expected_gain (guint sample_rate)
-{
- gint i;
-
- for (i = G_N_ELEMENTS (supported_rates); i--;)
- if (supported_rates[i].sample_rate == sample_rate)
- return supported_rates[i].gain;
- g_return_val_if_reached (0.0);
-}
-
-#define SILENCE_GAIN 64.82
-
-#define REPLAY_GAIN_CAPS \
- "channels = (int) { 1, 2 }, " \
- "rate = (int) { 8000, 11025, 12000, 16000, 22050, " \
- "24000, 32000, 44100, 48000 }"
-
-#define RG_ANALYSIS_CAPS_TEMPLATE_STRING \
- "audio/x-raw-float, " \
- "width = (int) 32, " \
- "endianness = (int) BYTE_ORDER, " \
- REPLAY_GAIN_CAPS \
- "; " \
- "audio/x-raw-int, " \
- "width = (int) 16, " \
- "depth = (int) [ 1, 16 ], " \
- "signed = (boolean) true, " \
- "endianness = (int) BYTE_ORDER, " \
- REPLAY_GAIN_CAPS
-
-static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (RG_ANALYSIS_CAPS_TEMPLATE_STRING)
- );
-static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (RG_ANALYSIS_CAPS_TEMPLATE_STRING)
- );
-
-GstElement *
-setup_rganalysis ()
-{
- GstElement *analysis;
- GstBus *bus;
-
- GST_DEBUG ("setup_rganalysis");
- analysis = gst_check_setup_element ("rganalysis");
- mysrcpad = gst_check_setup_src_pad (analysis, &srctemplate, NULL);
- mysinkpad = gst_check_setup_sink_pad (analysis, &sinktemplate, NULL);
- gst_pad_set_active (mysrcpad, TRUE);
- gst_pad_set_active (mysinkpad, TRUE);
-
- bus = gst_bus_new ();
- gst_element_set_bus (analysis, bus);
- /* gst_element_set_bus does not steal a reference. */
- gst_object_unref (bus);
-
- return analysis;
-}
-
-void
-cleanup_rganalysis (GstElement * element)
-{
- GST_DEBUG ("cleanup_rganalysis");
-
- g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
- g_list_free (buffers);
- buffers = NULL;
-
- /* The bus owns references to the element: */
- gst_element_set_bus (element, NULL);
-
- gst_pad_set_active (mysrcpad, FALSE);
- gst_pad_set_active (mysinkpad, FALSE);
- gst_check_teardown_src_pad (element);
- gst_check_teardown_sink_pad (element);
- gst_check_teardown_element (element);
-}
-
-static void
-set_playing_state (GstElement * element)
-{
- fail_unless (gst_element_set_state (element,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
- "Could not set state to PLAYING");
-}
-
-static void
-send_eos_event (GstElement * element)
-{
- GstBus *bus = gst_element_get_bus (element);
- GstPad *pad = gst_element_get_static_pad (element, "sink");
- GstEvent *event = gst_event_new_eos ();
-
- fail_unless (gst_pad_send_event (pad, event),
- "Cannot send EOS event: Not handled.");
-
- /* There is no sink element, so _we_ post the EOS message on the bus here. Of
- * course we generate any EOS ourselves, but this allows us to poll for the
- * EOS message in poll_eos if we expect the element to _not_ generate a TAG
- * message. That's better than waiting for a timeout to lapse. */
- fail_unless (gst_bus_post (bus, gst_message_new_eos (NULL)));
-
- gst_object_unref (bus);
- gst_object_unref (pad);
-}
-
-static void
-send_tag_event (GstElement * element, GstTagList * tag_list)
-{
- GstPad *pad = gst_element_get_static_pad (element, "sink");
- GstEvent *event = gst_event_new_tag (tag_list);
-
- fail_unless (gst_pad_send_event (pad, event),
- "Cannot send TAG event: Not handled.");
-
- gst_object_unref (pad);
-}
-
-static void
-poll_eos (GstElement * element)
-{
- GstBus *bus = gst_element_get_bus (element);
- GstMessage *message;
-
- message = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_TAG, GST_SECOND);
- fail_unless (message != NULL, "Could not poll for EOS message: Timed out");
- fail_unless (message->type == GST_MESSAGE_EOS,
- "Could not poll for eos message: got message of type %s instead",
- gst_message_type_get_name (message->type));
-
- gst_message_unref (message);
- gst_object_unref (bus);
-}
-
-/* This also polls for EOS since the TAG message comes right before the end of
- * streams. */
-
-static GstTagList *
-poll_tags (GstElement * element)
-{
- GstBus *bus = gst_element_get_bus (element);
- GstTagList *tag_list;
- GstMessage *message;
-
- message = gst_bus_poll (bus, GST_MESSAGE_TAG, GST_SECOND);
- fail_unless (message != NULL, "Could not poll for TAG message: Timed out");
-
- fail_unless (GST_MESSAGE_SRC (message) == GST_OBJECT (element));
-
- gst_message_parse_tag (message, &tag_list);
- gst_message_unref (message);
- gst_object_unref (bus);
-
- poll_eos (element);
-
- return tag_list;
-}
-
-#define MATCH_PEAK(p1, p2) ((p1 < p2 + 1e-6) && (p2 < p1 + 1e-6))
-#define MATCH_GAIN(g1, g2) ((g1 < g2 + 1e-13) && (g2 < g1 + 1e-13))
-
-static void
-fail_unless_track_gain (const GstTagList * tag_list, gdouble gain)
-{
- gdouble result;
-
- fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_GAIN, &result),
- "Tag list contains no track gain value");
- fail_unless (MATCH_GAIN (gain, result),
- "Track gain %+.2f does not match, expected %+.2f", result, gain);
-}
-
-static void
-fail_unless_track_peak (const GstTagList * tag_list, gdouble peak)
-{
- gdouble result;
-
- fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_PEAK, &result),
- "Tag list contains no track peak value");
- fail_unless (MATCH_PEAK (peak, result),
- "Track peak %f does not match, expected %f", result, peak);
-}
-
-static void
-fail_unless_album_gain (const GstTagList * tag_list, gdouble gain)
-{
- gdouble result;
-
- fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_GAIN, &result),
- "Tag list contains no album gain value");
- fail_unless (MATCH_GAIN (result, gain),
- "Album gain %+.2f does not match, expected %+.2f", result, gain);
-}
-
-static void
-fail_unless_album_peak (const GstTagList * tag_list, gdouble peak)
-{
- gdouble result;
-
- fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_PEAK, &result),
- "Tag list contains no album peak value");
- fail_unless (MATCH_PEAK (peak, result),
- "Album peak %f does not match, expected %f", result, peak);
-}
-
-static void
-fail_if_track_tags (const GstTagList * tag_list)
-{
- gdouble result;
-
- fail_if (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_GAIN, &result),
- "Tag list contains track gain value (but should not)");
- fail_if (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_PEAK, &result),
- "Tag list contains track peak value (but should not)");
-}
-
-static void
-fail_if_album_tags (const GstTagList * tag_list)
-{
- gdouble result;
-
- fail_if (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_GAIN, &result),
- "Tag list contains album gain value (but should not)");
- fail_if (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_PEAK, &result),
- "Tag list contains album peak value (but should not)");
-}
-
-static void
-fail_unless_num_tracks (GstElement * element, guint num_tracks)
-{
- guint current;
-
- g_object_get (element, "num-tracks", &current, NULL);
- fail_unless (current == num_tracks,
- "num-tracks property has incorrect value %u, expected %u",
- current, num_tracks);
-}
-
-/* Functions that create buffers with constant sample values, for peak
- * tests. */
-
-static GstBuffer *
-test_buffer_const_float_mono (gint sample_rate, gsize n_frames, gfloat value)
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gfloat));
- gfloat *data = (gfloat *) GST_BUFFER_DATA (buf);
- GstCaps *caps;
- gint i;
-
- for (i = n_frames; i--;)
- *data++ = value;
-
- caps = gst_caps_new_simple ("audio/x-raw-float",
- "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 1,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-static GstBuffer *
-test_buffer_const_float_stereo (gint sample_rate, gsize n_frames,
- gfloat value_l, gfloat value_r)
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gfloat) * 2);
- gfloat *data = (gfloat *) GST_BUFFER_DATA (buf);
- GstCaps *caps;
- gint i;
-
- for (i = n_frames; i--;) {
- *data++ = value_l;
- *data++ = value_r;
- }
-
- caps = gst_caps_new_simple ("audio/x-raw-float",
- "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 2,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-static GstBuffer *
-test_buffer_const_int16_mono (gint sample_rate, gint depth, gsize n_frames,
- gint16 value)
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gint16));
- gint16 *data = (gint16 *) GST_BUFFER_DATA (buf);
- GstCaps *caps;
- gint i;
-
- for (i = n_frames; i--;)
- *data++ = value;
-
- caps = gst_caps_new_simple ("audio/x-raw-int",
- "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 1,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE,
- "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, depth, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-static GstBuffer *
-test_buffer_const_int16_stereo (gint sample_rate, gint depth, gsize n_frames,
- gint16 value_l, gint16 value_r)
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gint16) * 2);
- gint16 *data = (gint16 *) GST_BUFFER_DATA (buf);
- GstCaps *caps;
- gint i;
-
- for (i = n_frames; i--;) {
- *data++ = value_l;
- *data++ = value_r;
- }
-
- caps = gst_caps_new_simple ("audio/x-raw-int",
- "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 2,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE,
- "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, depth, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-/* Functions that create data buffers containing square signal
- * waveforms. */
-
-static GstBuffer *
-test_buffer_square_float_mono (gint * accumulator, gint sample_rate,
- gsize n_frames, gfloat value)
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gfloat));
- gfloat *data = (gfloat *) GST_BUFFER_DATA (buf);
- GstCaps *caps;
- gint i;
-
- for (i = n_frames; i--;) {
- *accumulator += 1;
- *accumulator %= 96;
-
- if (*accumulator < 48)
- *data++ = value;
- else
- *data++ = -value;
- }
-
- caps = gst_caps_new_simple ("audio/x-raw-float",
- "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 1,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-static GstBuffer *
-test_buffer_square_float_stereo (gint * accumulator, gint sample_rate,
- gsize n_frames, gfloat value_l, gfloat value_r)
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gfloat) * 2);
- gfloat *data = (gfloat *) GST_BUFFER_DATA (buf);
- GstCaps *caps;
- gint i;
-
- for (i = n_frames; i--;) {
- *accumulator += 1;
- *accumulator %= 96;
-
- if (*accumulator < 48) {
- *data++ = value_l;
- *data++ = value_r;
- } else {
- *data++ = -value_l;
- *data++ = -value_r;
- }
- }
-
- caps = gst_caps_new_simple ("audio/x-raw-float",
- "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 2,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-static GstBuffer *
-test_buffer_square_int16_mono (gint * accumulator, gint sample_rate,
- gint depth, gsize n_frames, gint16 value)
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gint16));
- gint16 *data = (gint16 *) GST_BUFFER_DATA (buf);
- GstCaps *caps;
- gint i;
-
- for (i = n_frames; i--;) {
- *accumulator += 1;
- *accumulator %= 96;
-
- if (*accumulator < 48)
- *data++ = value;
- else
- *data++ = -MAX (value, -32767);
- }
-
- caps = gst_caps_new_simple ("audio/x-raw-int",
- "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 1,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE,
- "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, depth, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-static GstBuffer *
-test_buffer_square_int16_stereo (gint * accumulator, gint sample_rate,
- gint depth, gsize n_frames, gint16 value_l, gint16 value_r)
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gint16) * 2);
- gint16 *data = (gint16 *) GST_BUFFER_DATA (buf);
- GstCaps *caps;
- gint i;
-
- for (i = n_frames; i--;) {
- *accumulator += 1;
- *accumulator %= 96;
-
- if (*accumulator < 48) {
- *data++ = value_l;
- *data++ = value_r;
- } else {
- *data++ = -MAX (value_l, -32767);
- *data++ = -MAX (value_r, -32767);
- }
- }
-
- caps = gst_caps_new_simple ("audio/x-raw-int",
- "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 2,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE,
- "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, depth, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-static void
-push_buffer (GstBuffer * buf)
-{
- /* gst_pad_push steals a reference. */
- fail_unless (gst_pad_push (mysrcpad, buf) == GST_FLOW_OK);
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-}
-
-/*** Start of the tests. ***/
-
-/* This test looks redundant, but early versions of the element
- * crashed when doing, well, nothing: */
-
-GST_START_TEST (test_no_buffer)
-{
- GstElement *element = setup_rganalysis ();
-
- set_playing_state (element);
- send_eos_event (element);
- poll_eos (element);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_no_buffer_album_1)
-{
- GstElement *element = setup_rganalysis ();
-
- set_playing_state (element);
-
- /* Single track: */
- send_eos_event (element);
- poll_eos (element);
-
- /* First album: */
- g_object_set (element, "num-tracks", 3, NULL);
-
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 2);
-
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 1);
-
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 0);
-
- /* Second album: */
- g_object_set (element, "num-tracks", 2, NULL);
-
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 1);
-
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 0);
-
- /* Single track: */
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 0);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_no_buffer_album_2)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator = 0;
- gint i;
-
- g_object_set (element, "num-tracks", 3, NULL);
- set_playing_state (element);
-
- /* No buffer for the first track. */
-
- send_eos_event (element);
- /* No tags should be posted, there was nothing to analyze: */
- poll_eos (element);
- fail_unless_num_tracks (element, 2);
-
- /* A test waveform with known gain result as second track: */
-
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_mono (&accumulator, 44100, 512,
- 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, -6.20);
- /* Album is not finished yet: */
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 1);
-
- /* No buffer for the last track. */
-
- send_eos_event (element);
-
- tag_list = poll_tags (element);
- fail_unless_album_peak (tag_list, 0.25);
- fail_unless_album_gain (tag_list, -6.20);
- /* No track tags should be posted, as there was no data for it: */
- fail_if_track_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 0);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_empty_buffers)
-{
- GstElement *element = setup_rganalysis ();
-
- set_playing_state (element);
-
- /* Single track: */
- push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
- send_eos_event (element);
- poll_eos (element);
-
- /* First album: */
- g_object_set (element, "num-tracks", 2, NULL);
-
- push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 1);
-
- push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 0);
-
- /* Second album, with a single track: */
- g_object_set (element, "num-tracks", 1, NULL);
- push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 0);
-
- /* Single track: */
- push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
- send_eos_event (element);
- poll_eos (element);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_gap_buffers)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- GstBuffer *buf;
- gint accumulator = 0;
- gint i;
-
- set_playing_state (element);
-
- for (i = 0; i < 60; i++) {
- if (i % 3 == 0) {
- /* We are cheating here; the element cannot know that these GAP buffers
- * actually contain non-silence so it must skip them. */
- buf = test_buffer_square_float_mono (&accumulator, 44100, 512, 0.25);
- GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_GAP);
- push_buffer (buf);
-
- /* Verify that the base class does not lift the GAP flag: */
- fail_if (g_list_length (buffers) == 0);
- if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP))
- fail_unless (GST_BUFFER_FLAG_IS_SET (buffers->data,
- GST_BUFFER_FLAG_GAP));
- } else {
- push_buffer (test_buffer_const_float_mono (44100, 512, 0.0));
- }
- }
-
- send_eos_event (element);
- tag_list = poll_tags (element);
- /* We pushed faked GAP buffers with non-silence and non-GAP buffers with
- * silence, so the correct result is that the analysis only got silence: */
- fail_unless_track_peak (tag_list, 0.0);
- fail_unless_track_gain (tag_list, SILENCE_GAIN);
-
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* Tests for correctness of the peak values. */
-
-/* Float peak test. For stereo, one channel has the constant value of -1.369,
- * the other one 0.0. This tests many things: The result peak value should
- * occur on any channel. The peak is of course the absolute amplitude, so 1.369
- * should be the result. This will also detect if the code uses the absolute
- * value during the comparison. If it is buggy it will return 0.0 since 0.0 >
- * -1.369. Furthermore, this makes sure that there is no problem with headroom
- * (exceeding 0dBFS). In the wild you get float samples > 1.0 from stuff like
- * vorbis. */
-
-GST_START_TEST (test_peak_float)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
-
- set_playing_state (element);
- push_buffer (test_buffer_const_float_stereo (8000, 512, -1.369, 0.0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.369);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_float_stereo (8000, 512, 0.0, -1.369));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.369);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_float_mono (8000, 512, -1.369));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.369);
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_peak_int16_16)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
-
- set_playing_state (element);
-
- /* Half amplitude. */
- push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 1 << 14, 0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 0, 1 << 14));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_int16_mono (8000, 16, 512, 1 << 14));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Half amplitude, negative variant. */
- push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, -1 << 14, 0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 0, -1 << 14));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_int16_mono (8000, 16, 512, -1 << 14));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
-
- /* Now check for correct normalization of the peak value: Sample
- * values of this format range from -32768 to 32767. So for the
- * highest positive amplitude we do not reach 1.0, only for
- * -32768! */
-
- push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 32767, 0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 32767. / 32768.);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 0, 32767));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 32767. / 32768.);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_int16_mono (8000, 16, 512, 32767));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 32767. / 32768.);
- gst_tag_list_free (tag_list);
-
-
- /* Negative variant, reaching 1.0. */
- push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, -32768, 0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 0, -32768));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_int16_mono (8000, 16, 512, -32768));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* Same as the test before, but with 8 bits (packed into 16 bits). */
-
-GST_START_TEST (test_peak_int16_8)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
-
- set_playing_state (element);
-
- /* Half amplitude. */
- push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 1 << 6, 0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 0, 1 << 6));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_int16_mono (8000, 8, 512, 1 << 6));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
-
- /* Half amplitude, negative variant. */
- push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, -1 << 6, 0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 0, -1 << 6));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_int16_mono (8000, 8, 512, -1 << 6));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
-
-
- /* Almost full amplitude (maximum positive value). */
- push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, (1 << 7) - 1, 0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.9921875);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 0, (1 << 7) - 1));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.9921875);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_int16_mono (8000, 8, 512, (1 << 7) - 1));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.9921875);
- gst_tag_list_free (tag_list);
-
-
- /* Full amplitude (maximum negative value). */
- push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, -1 << 7, 0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- gst_tag_list_free (tag_list);
-
- /* Swapped channels. */
- push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 0, -1 << 7));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- gst_tag_list_free (tag_list);
-
- /* Mono. */
- push_buffer (test_buffer_const_int16_mono (8000, 8, 512, -1 << 7));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_peak_album)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
-
- g_object_set (element, "num-tracks", 2, NULL);
- set_playing_state (element);
-
- push_buffer (test_buffer_const_float_stereo (8000, 1024, 1.0, 0.0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 1);
-
- push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.0, 0.5));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- fail_unless_album_peak (tag_list, 1.0);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 0);
-
- /* Try a second album: */
- g_object_set (element, "num-tracks", 3, NULL);
-
- push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.4, 0.4));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.4);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 2);
-
- push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.45, 0.45));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.45);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 1);
-
- push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.2, 0.2));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.2);
- fail_unless_album_peak (tag_list, 0.45);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 0);
-
- /* And now a single track, not in album mode (num-tracks is 0
- * now): */
- push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.1, 0.1));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.1);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* Switching from track to album mode. */
-
-GST_START_TEST (test_peak_track_album)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
-
- set_playing_state (element);
-
- push_buffer (test_buffer_const_float_mono (8000, 1024, 1.0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
-
- g_object_set (element, "num-tracks", 1, NULL);
- push_buffer (test_buffer_const_float_mono (8000, 1024, 0.5));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- fail_unless_album_peak (tag_list, 0.5);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 0);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* Disabling album processing before the end of the album. Probably a rare edge
- * case and applications should not rely on this to work. They need to send the
- * element to the READY state to clear up after an aborted album anyway since
- * they might need to process another album afterwards. */
-
-GST_START_TEST (test_peak_album_abort_to_track)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
-
- g_object_set (element, "num-tracks", 2, NULL);
- set_playing_state (element);
-
- push_buffer (test_buffer_const_float_stereo (8000, 1024, 1.0, 0.0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 1.0);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 1);
-
- g_object_set (element, "num-tracks", 0, NULL);
-
- push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.0, 0.5));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_gain_album)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator;
- gint i;
-
- g_object_set (element, "num-tracks", 3, NULL);
- set_playing_state (element);
-
- /* The three tracks are constructed such that if any of these is in fact
- * ignored for the album gain, the album gain will differ. */
-
- accumulator = 0;
- for (i = 8; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.75, 0.75));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.75);
- fail_unless_track_gain (tag_list, -15.70);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
-
- accumulator = 0;
- for (i = 12; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.5, 0.5));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.5);
- fail_unless_track_gain (tag_list, -12.22);
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
-
- accumulator = 0;
- for (i = 180; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.25, 0.25));
- send_eos_event (element);
-
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, -6.20);
- fail_unless_album_peak (tag_list, 0.75);
- /* Strangely, wavegain reports -12.17 for the album, but the fixed
- * metaflac agrees to us. Could be a 32767 vs. 32768 issue. */
- fail_unless_album_gain (tag_list, -12.18);
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* Checks ensuring that the "forced" property works as advertised. */
-
-GST_START_TEST (test_forced)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator = 0;
- gint i;
-
- g_object_set (element, "forced", FALSE, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- /* Provided values are totally arbitrary. */
- gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
- GST_TAG_TRACK_PEAK, 1.0, GST_TAG_TRACK_GAIN, 2.21, NULL);
- send_tag_event (element, tag_list);
-
- for (i = 20; i--;)
- push_buffer (test_buffer_const_float_stereo (44100, 512, 0.5, 0.5));
- send_eos_event (element);
- /* This fails if a tag message is generated: */
- poll_eos (element);
-
- /* Now back to a track without tags. */
-
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.25, 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (44100));
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* Sending track gain and peak in separate tag lists. */
-
-GST_START_TEST (test_forced_separate)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator = 0;
- gint i;
-
- g_object_set (element, "forced", FALSE, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_TRACK_GAIN, 2.21,
- NULL);
- send_tag_event (element, tag_list);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_TRACK_PEAK, 1.0,
- NULL);
- send_tag_event (element, tag_list);
-
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.5, 0.5));
- send_eos_event (element);
- /* This fails if a tag message is generated: */
- poll_eos (element);
-
- /* Now a track without tags. */
-
- accumulator = 0;
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.25, 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (44100));
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* A TAG event is sent _after_ data has already been processed. In real
- * pipelines, this could happen if there is more than one rganalysis element (by
- * accident). While it would have analyzed all the data prior to receiving the
- * event, I expect it to not post its results if not forced. This test is
- * almost equivalent to test_forced. */
-
-GST_START_TEST (test_forced_after_data)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator = 0;
- gint i;
-
- g_object_set (element, "forced", FALSE, NULL);
- set_playing_state (element);
-
- for (i = 20; i--;)
- push_buffer (test_buffer_const_float_stereo (8000, 512, 0.5, 0.5));
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
- GST_TAG_TRACK_PEAK, 1.0, GST_TAG_TRACK_GAIN, 2.21, NULL);
- send_tag_event (element, tag_list);
-
- send_eos_event (element);
- poll_eos (element);
-
- /* Now back to a normal track, this one has no tags: */
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
- 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (8000));
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* Like test_forced, but *analyze* an album afterwards. The two tests following
- * this one check the *skipping* of albums. */
-
-GST_START_TEST (test_forced_album)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator;
- gint i;
-
- g_object_set (element, "forced", FALSE, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- /* Provided values are totally arbitrary. */
- gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
- GST_TAG_TRACK_PEAK, 1.0, GST_TAG_TRACK_GAIN, 2.21, NULL);
- send_tag_event (element, tag_list);
-
- accumulator = 0;
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.5, 0.5));
- send_eos_event (element);
- /* This fails if a tag message is generated: */
- poll_eos (element);
-
- /* Now an album without tags. */
- g_object_set (element, "num-tracks", 2, NULL);
-
- accumulator = 0;
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.25, 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (44100));
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 1);
-
- accumulator = 0;
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.25, 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (44100));
- fail_unless_album_peak (tag_list, 0.25);
- fail_unless_album_gain (tag_list, get_expected_gain (44100));
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 0);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_forced_album_skip)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator = 0;
- gint i;
-
- g_object_set (element, "forced", FALSE, "num-tracks", 2, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- /* Provided values are totally arbitrary. */
- gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
- GST_TAG_TRACK_PEAK, 0.75, GST_TAG_TRACK_GAIN, 2.21,
- GST_TAG_ALBUM_PEAK, 0.80, GST_TAG_ALBUM_GAIN, -0.11, NULL);
- send_tag_event (element, tag_list);
-
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
- 0.25));
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 1);
-
- /* This track has no tags, but needs to be skipped anyways since we
- * are in album processing mode. */
- for (i = 20; i--;)
- push_buffer (test_buffer_const_float_stereo (8000, 512, 0.0, 0.0));
- send_eos_event (element);
- poll_eos (element);
- fail_unless_num_tracks (element, 0);
-
- /* Normal track after the album. Of course not to be skipped. */
- accumulator = 0;
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
- 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (8000));
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_forced_album_no_skip)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator = 0;
- gint i;
-
- g_object_set (element, "forced", FALSE, "num-tracks", 2, NULL);
- set_playing_state (element);
-
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
- 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (8000));
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 1);
-
- /* The second track has indeed full tags, but although being not forced, this
- * one has to be processed because album processing is on. */
- tag_list = gst_tag_list_new ();
- /* Provided values are totally arbitrary. */
- gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
- GST_TAG_TRACK_PEAK, 0.75, GST_TAG_TRACK_GAIN, 2.21,
- GST_TAG_ALBUM_PEAK, 0.80, GST_TAG_ALBUM_GAIN, -0.11, NULL);
- send_tag_event (element, tag_list);
- for (i = 20; i--;)
- push_buffer (test_buffer_const_float_stereo (8000, 512, 0.0, 0.0));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.0);
- fail_unless_track_gain (tag_list, SILENCE_GAIN);
- /* Second track was just silence so the album peak equals the first
- * track's peak. */
- fail_unless_album_peak (tag_list, 0.25);
- /* Statistical processing leads to the second track being
- * ignored for the gain (because it is so short): */
- fail_unless_album_gain (tag_list, get_expected_gain (8000));
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 0);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_forced_abort_album_no_skip)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator = 0;
- gint i;
-
- g_object_set (element, "forced", FALSE, "num-tracks", 2, NULL);
- set_playing_state (element);
-
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
- 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (8000));
- fail_if_album_tags (tag_list);
- gst_tag_list_free (tag_list);
- fail_unless_num_tracks (element, 1);
-
- /* Disabling album processing before end of album: */
- g_object_set (element, "num-tracks", 0, NULL);
-
- /* Processing a track that has to be skipped. */
- tag_list = gst_tag_list_new ();
- /* Provided values are totally arbitrary. */
- gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
- GST_TAG_TRACK_PEAK, 0.75, GST_TAG_TRACK_GAIN, 2.21,
- GST_TAG_ALBUM_PEAK, 0.80, GST_TAG_ALBUM_GAIN, -0.11, NULL);
- send_tag_event (element, tag_list);
- for (i = 20; i--;)
- push_buffer (test_buffer_const_float_stereo (8000, 512, 0.0, 0.0));
- send_eos_event (element);
- poll_eos (element);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_reference_level)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gdouble ref_level;
- gint accumulator = 0;
- gint i;
-
- set_playing_state (element);
-
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.25, 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (44100));
- fail_if_album_tags (tag_list);
- fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
- &ref_level) && MATCH_GAIN (ref_level, 89.),
- "Incorrect reference level tag");
- gst_tag_list_free (tag_list);
-
- g_object_set (element, "reference-level", 83., "num-tracks", 2, NULL);
-
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.25, 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (44100) - 6.);
- fail_if_album_tags (tag_list);
- fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
- &ref_level) && MATCH_GAIN (ref_level, 83.),
- "Incorrect reference level tag");
- gst_tag_list_free (tag_list);
-
- accumulator = 0;
- for (i = 20; i--;)
- push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
- 0.25, 0.25));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, get_expected_gain (44100) - 6.);
- fail_unless_album_peak (tag_list, 0.25);
- /* We provided the same waveform twice, with a reset separating
- * them. Therefore, the album gain matches the track gain. */
- fail_unless_album_gain (tag_list, get_expected_gain (44100) - 6.);
- fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
- &ref_level) && MATCH_GAIN (ref_level, 83.),
- "Incorrect reference level tag");
- gst_tag_list_free (tag_list);
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_all_formats)
-{
- GstElement *element = setup_rganalysis ();
- GstTagList *tag_list;
- gint accumulator = 0;
- gint i, j;
-
- set_playing_state (element);
- for (i = G_N_ELEMENTS (supported_rates); i--;) {
- accumulator = 0;
- for (j = 0; j < 4; j++)
- push_buffer (test_buffer_square_float_stereo (&accumulator,
- supported_rates[i].sample_rate, 512, 0.25, 0.25));
- for (j = 0; j < 3; j++)
- push_buffer (test_buffer_square_float_mono (&accumulator,
- supported_rates[i].sample_rate, 512, 0.25));
- for (j = 0; j < 4; j++)
- push_buffer (test_buffer_square_int16_stereo (&accumulator,
- supported_rates[i].sample_rate, 16, 512, 1 << 13, 1 << 13));
- for (j = 0; j < 3; j++)
- push_buffer (test_buffer_square_int16_mono (&accumulator,
- supported_rates[i].sample_rate, 16, 512, 1 << 13));
- for (j = 0; j < 3; j++)
- push_buffer (test_buffer_square_int16_stereo (&accumulator,
- supported_rates[i].sample_rate, 8, 512, 1 << 5, 1 << 5));
- for (j = 0; j < 3; j++)
- push_buffer (test_buffer_square_int16_mono (&accumulator,
- supported_rates[i].sample_rate, 8, 512, 1 << 5));
- send_eos_event (element);
- tag_list = poll_tags (element);
- fail_unless_track_peak (tag_list, 0.25);
- fail_unless_track_gain (tag_list, supported_rates[i].gain);
- gst_tag_list_free (tag_list);
- }
-
- cleanup_rganalysis (element);
-}
-
-GST_END_TEST;
-
-/* Checks ensuring all advertised supported sample rates are really
- * accepted, for integer and float, mono and stereo. This also
- * verifies that the correct gain is computed for all formats (except
- * odd bit depths). */
-
-#define MAKE_GAIN_TEST_FLOAT_MONO(sample_rate) \
- GST_START_TEST (test_gain_float_mono_##sample_rate) \
-{ \
- GstElement *element = setup_rganalysis (); \
- GstTagList *tag_list; \
- gint accumulator = 0; \
- gint i; \
- \
- set_playing_state (element); \
- \
- for (i = 0; i < 20; i++) \
- push_buffer (test_buffer_square_float_mono (&accumulator, \
- sample_rate, 512, 0.25)); \
- send_eos_event (element); \
- tag_list = poll_tags (element); \
- fail_unless_track_peak (tag_list, 0.25); \
- fail_unless_track_gain (tag_list, \
- get_expected_gain (sample_rate)); \
- gst_tag_list_free (tag_list); \
- \
- cleanup_rganalysis (element); \
-} \
- \
-GST_END_TEST;
-
-#define MAKE_GAIN_TEST_FLOAT_STEREO(sample_rate) \
- GST_START_TEST (test_gain_float_stereo_##sample_rate) \
-{ \
- GstElement *element = setup_rganalysis (); \
- GstTagList *tag_list; \
- gint accumulator = 0; \
- gint i; \
- \
- set_playing_state (element); \
- \
- for (i = 0; i < 20; i++) \
- push_buffer (test_buffer_square_float_stereo (&accumulator, \
- sample_rate, 512, 0.25, 0.25)); \
- send_eos_event (element); \
- tag_list = poll_tags (element); \
- fail_unless_track_peak (tag_list, 0.25); \
- fail_unless_track_gain (tag_list, \
- get_expected_gain (sample_rate)); \
- gst_tag_list_free (tag_list); \
- \
- cleanup_rganalysis (element); \
-} \
- \
-GST_END_TEST;
-
-#define MAKE_GAIN_TEST_INT16_MONO(sample_rate, depth) \
- GST_START_TEST (test_gain_int16_##depth##_mono_##sample_rate) \
-{ \
- GstElement *element = setup_rganalysis (); \
- GstTagList *tag_list; \
- gint accumulator = 0; \
- gint i; \
- \
- set_playing_state (element); \
- \
- for (i = 0; i < 20; i++) \
- push_buffer (test_buffer_square_int16_mono (&accumulator, \
- sample_rate, depth, 512, 1 << (13 + depth - 16))); \
- \
- send_eos_event (element); \
- tag_list = poll_tags (element); \
- fail_unless_track_peak (tag_list, 0.25); \
- fail_unless_track_gain (tag_list, \
- get_expected_gain (sample_rate)); \
- gst_tag_list_free (tag_list); \
- \
- cleanup_rganalysis (element); \
-} \
- \
-GST_END_TEST;
-
-#define MAKE_GAIN_TEST_INT16_STEREO(sample_rate, depth) \
- GST_START_TEST (test_gain_int16_##depth##_stereo_##sample_rate) \
-{ \
- GstElement *element = setup_rganalysis (); \
- GstTagList *tag_list; \
- gint accumulator = 0; \
- gint i; \
- \
- set_playing_state (element); \
- \
- for (i = 0; i < 20; i++) \
- push_buffer (test_buffer_square_int16_stereo (&accumulator, \
- sample_rate, depth, 512, 1 << (13 + depth - 16), \
- 1 << (13 + depth - 16))); \
- send_eos_event (element); \
- tag_list = poll_tags (element); \
- fail_unless_track_peak (tag_list, 0.25); \
- fail_unless_track_gain (tag_list, \
- get_expected_gain (sample_rate)); \
- gst_tag_list_free (tag_list); \
- \
- cleanup_rganalysis (element); \
-} \
- \
-GST_END_TEST;
-
-MAKE_GAIN_TEST_FLOAT_MONO (8000);
-MAKE_GAIN_TEST_FLOAT_MONO (11025);
-MAKE_GAIN_TEST_FLOAT_MONO (12000);
-MAKE_GAIN_TEST_FLOAT_MONO (16000);
-MAKE_GAIN_TEST_FLOAT_MONO (22050);
-MAKE_GAIN_TEST_FLOAT_MONO (24000);
-MAKE_GAIN_TEST_FLOAT_MONO (32000);
-MAKE_GAIN_TEST_FLOAT_MONO (44100);
-MAKE_GAIN_TEST_FLOAT_MONO (48000);
-
-MAKE_GAIN_TEST_FLOAT_STEREO (8000);
-MAKE_GAIN_TEST_FLOAT_STEREO (11025);
-MAKE_GAIN_TEST_FLOAT_STEREO (12000);
-MAKE_GAIN_TEST_FLOAT_STEREO (16000);
-MAKE_GAIN_TEST_FLOAT_STEREO (22050);
-MAKE_GAIN_TEST_FLOAT_STEREO (24000);
-MAKE_GAIN_TEST_FLOAT_STEREO (32000);
-MAKE_GAIN_TEST_FLOAT_STEREO (44100);
-MAKE_GAIN_TEST_FLOAT_STEREO (48000);
-
-MAKE_GAIN_TEST_INT16_MONO (8000, 16);
-MAKE_GAIN_TEST_INT16_MONO (11025, 16);
-MAKE_GAIN_TEST_INT16_MONO (12000, 16);
-MAKE_GAIN_TEST_INT16_MONO (16000, 16);
-MAKE_GAIN_TEST_INT16_MONO (22050, 16);
-MAKE_GAIN_TEST_INT16_MONO (24000, 16);
-MAKE_GAIN_TEST_INT16_MONO (32000, 16);
-MAKE_GAIN_TEST_INT16_MONO (44100, 16);
-MAKE_GAIN_TEST_INT16_MONO (48000, 16);
-
-MAKE_GAIN_TEST_INT16_STEREO (8000, 16);
-MAKE_GAIN_TEST_INT16_STEREO (11025, 16);
-MAKE_GAIN_TEST_INT16_STEREO (12000, 16);
-MAKE_GAIN_TEST_INT16_STEREO (16000, 16);
-MAKE_GAIN_TEST_INT16_STEREO (22050, 16);
-MAKE_GAIN_TEST_INT16_STEREO (24000, 16);
-MAKE_GAIN_TEST_INT16_STEREO (32000, 16);
-MAKE_GAIN_TEST_INT16_STEREO (44100, 16);
-MAKE_GAIN_TEST_INT16_STEREO (48000, 16);
-
-MAKE_GAIN_TEST_INT16_MONO (8000, 8);
-MAKE_GAIN_TEST_INT16_MONO (11025, 8);
-MAKE_GAIN_TEST_INT16_MONO (12000, 8);
-MAKE_GAIN_TEST_INT16_MONO (16000, 8);
-MAKE_GAIN_TEST_INT16_MONO (22050, 8);
-MAKE_GAIN_TEST_INT16_MONO (24000, 8);
-MAKE_GAIN_TEST_INT16_MONO (32000, 8);
-MAKE_GAIN_TEST_INT16_MONO (44100, 8);
-MAKE_GAIN_TEST_INT16_MONO (48000, 8);
-
-MAKE_GAIN_TEST_INT16_STEREO (8000, 8);
-MAKE_GAIN_TEST_INT16_STEREO (11025, 8);
-MAKE_GAIN_TEST_INT16_STEREO (12000, 8);
-MAKE_GAIN_TEST_INT16_STEREO (16000, 8);
-MAKE_GAIN_TEST_INT16_STEREO (22050, 8);
-MAKE_GAIN_TEST_INT16_STEREO (24000, 8);
-MAKE_GAIN_TEST_INT16_STEREO (32000, 8);
-MAKE_GAIN_TEST_INT16_STEREO (44100, 8);
-MAKE_GAIN_TEST_INT16_STEREO (48000, 8);
-
-Suite *
-rganalysis_suite (void)
-{
- Suite *s = suite_create ("rganalysis");
- TCase *tc_chain = tcase_create ("general");
-
- suite_add_tcase (s, tc_chain);
-
- tcase_add_test (tc_chain, test_no_buffer);
- tcase_add_test (tc_chain, test_no_buffer_album_1);
- tcase_add_test (tc_chain, test_no_buffer_album_2);
- tcase_add_test (tc_chain, test_empty_buffers);
- tcase_add_test (tc_chain, test_gap_buffers);
-
- tcase_add_test (tc_chain, test_peak_float);
- tcase_add_test (tc_chain, test_peak_int16_16);
- tcase_add_test (tc_chain, test_peak_int16_8);
-
- tcase_add_test (tc_chain, test_peak_album);
- tcase_add_test (tc_chain, test_peak_track_album);
- tcase_add_test (tc_chain, test_peak_album_abort_to_track);
-
- tcase_add_test (tc_chain, test_gain_album);
-
- tcase_add_test (tc_chain, test_forced);
- tcase_add_test (tc_chain, test_forced_separate);
- tcase_add_test (tc_chain, test_forced_after_data);
- tcase_add_test (tc_chain, test_forced_album);
- tcase_add_test (tc_chain, test_forced_album_skip);
- tcase_add_test (tc_chain, test_forced_album_no_skip);
- tcase_add_test (tc_chain, test_forced_abort_album_no_skip);
-
- tcase_add_test (tc_chain, test_reference_level);
-
- tcase_add_test (tc_chain, test_all_formats);
-
- tcase_add_test (tc_chain, test_gain_float_mono_8000);
- tcase_add_test (tc_chain, test_gain_float_mono_11025);
- tcase_add_test (tc_chain, test_gain_float_mono_12000);
- tcase_add_test (tc_chain, test_gain_float_mono_16000);
- tcase_add_test (tc_chain, test_gain_float_mono_22050);
- tcase_add_test (tc_chain, test_gain_float_mono_24000);
- tcase_add_test (tc_chain, test_gain_float_mono_32000);
- tcase_add_test (tc_chain, test_gain_float_mono_44100);
- tcase_add_test (tc_chain, test_gain_float_mono_48000);
-
- tcase_add_test (tc_chain, test_gain_float_stereo_8000);
- tcase_add_test (tc_chain, test_gain_float_stereo_11025);
- tcase_add_test (tc_chain, test_gain_float_stereo_12000);
- tcase_add_test (tc_chain, test_gain_float_stereo_16000);
- tcase_add_test (tc_chain, test_gain_float_stereo_22050);
- tcase_add_test (tc_chain, test_gain_float_stereo_24000);
- tcase_add_test (tc_chain, test_gain_float_stereo_32000);
- tcase_add_test (tc_chain, test_gain_float_stereo_44100);
- tcase_add_test (tc_chain, test_gain_float_stereo_48000);
-
- tcase_add_test (tc_chain, test_gain_int16_16_mono_8000);
- tcase_add_test (tc_chain, test_gain_int16_16_mono_11025);
- tcase_add_test (tc_chain, test_gain_int16_16_mono_12000);
- tcase_add_test (tc_chain, test_gain_int16_16_mono_16000);
- tcase_add_test (tc_chain, test_gain_int16_16_mono_22050);
- tcase_add_test (tc_chain, test_gain_int16_16_mono_24000);
- tcase_add_test (tc_chain, test_gain_int16_16_mono_32000);
- tcase_add_test (tc_chain, test_gain_int16_16_mono_44100);
- tcase_add_test (tc_chain, test_gain_int16_16_mono_48000);
-
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_8000);
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_11025);
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_12000);
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_16000);
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_22050);
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_24000);
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_32000);
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_44100);
- tcase_add_test (tc_chain, test_gain_int16_16_stereo_48000);
-
- tcase_add_test (tc_chain, test_gain_int16_8_mono_8000);
- tcase_add_test (tc_chain, test_gain_int16_8_mono_11025);
- tcase_add_test (tc_chain, test_gain_int16_8_mono_12000);
- tcase_add_test (tc_chain, test_gain_int16_8_mono_16000);
- tcase_add_test (tc_chain, test_gain_int16_8_mono_22050);
- tcase_add_test (tc_chain, test_gain_int16_8_mono_24000);
- tcase_add_test (tc_chain, test_gain_int16_8_mono_32000);
- tcase_add_test (tc_chain, test_gain_int16_8_mono_44100);
- tcase_add_test (tc_chain, test_gain_int16_8_mono_48000);
-
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_8000);
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_11025);
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_12000);
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_16000);
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_22050);
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_24000);
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_32000);
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_44100);
- tcase_add_test (tc_chain, test_gain_int16_8_stereo_48000);
-
- return s;
-}
-
-int
-main (int argc, char **argv)
-{
- gint nf;
-
- Suite *s = rganalysis_suite ();
- SRunner *sr = srunner_create (s);
-
- gst_check_init (&argc, &argv);
-
- srunner_run_all (sr, CK_ENV);
- nf = srunner_ntests_failed (sr);
- srunner_free (sr);
-
- return nf;
-}
diff --git a/tests/check/elements/rglimiter.c b/tests/check/elements/rglimiter.c
deleted file mode 100644
index 9d838785..00000000
--- a/tests/check/elements/rglimiter.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/* GStreamer ReplayGain limiter
- *
- * Copyright (C) 2007 Rene Stadler <mail@renestadler.de>
- *
- * rglimiter.c: Unit test for the rglimiter element
- *
- * 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
- */
-
-#include <gst/check/gstcheck.h>
-
-#include <math.h>
-
-GList *buffers = NULL;
-
-/* 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 */
-static GstPad *mysrcpad, *mysinkpad;
-
-#define RG_LIMITER_CAPS_TEMPLATE_STRING \
- "audio/x-raw-float, " \
- "width = (int) 32, " \
- "endianness = (int) BYTE_ORDER, " \
- "channels = (int) [ 1, MAX ], " \
- "rate = (int) [ 1, MAX ]"
-
-static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (RG_LIMITER_CAPS_TEMPLATE_STRING)
- );
-static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (RG_LIMITER_CAPS_TEMPLATE_STRING)
- );
-
-GstElement *
-setup_rglimiter ()
-{
- GstElement *element;
-
- GST_DEBUG ("setup_rglimiter");
- element = gst_check_setup_element ("rglimiter");
- mysrcpad = gst_check_setup_src_pad (element, &srctemplate, NULL);
- mysinkpad = gst_check_setup_sink_pad (element, &sinktemplate, NULL);
- gst_pad_set_active (mysrcpad, TRUE);
- gst_pad_set_active (mysinkpad, TRUE);
-
- return element;
-}
-
-void
-cleanup_rglimiter (GstElement * element)
-{
- GST_DEBUG ("cleanup_rglimiter");
-
- g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
- g_list_free (buffers);
- buffers = NULL;
-
- gst_check_teardown_src_pad (element);
- gst_check_teardown_sink_pad (element);
- gst_check_teardown_element (element);
-}
-
-static void
-set_playing_state (GstElement * element)
-{
- fail_unless (gst_element_set_state (element,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
- "Could not set state to PLAYING");
-}
-
-static const gfloat test_input[] = {
- -2.0, -1.0, -0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75, 1.0, 2.0
-};
-static const gfloat test_output[] = {
- -0.99752737684336523, /* -2.0 */
- -0.88079707797788243, /* -1.0 */
- -0.7310585786300049, /* -0.75 */
- -0.5, -0.25, 0.0, 0.25, 0.5,
- 0.7310585786300049, /* 0.75 */
- 0.88079707797788243, /* 1.0 */
- 0.99752737684336523, /* 2.0 */
-};
-
-static GstBuffer *
-create_test_buffer ()
-{
- GstBuffer *buf = gst_buffer_new_and_alloc (sizeof (test_input));
- GstCaps *caps;
-
- memcpy (GST_BUFFER_DATA (buf), test_input, sizeof (test_input));
-
- caps = gst_caps_new_simple ("audio/x-raw-float",
- "rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 1,
- "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-static void
-verify_test_buffer (GstBuffer * buf)
-{
- gfloat *output = (gfloat *) GST_BUFFER_DATA (buf);
- gint i;
-
- fail_unless (GST_BUFFER_SIZE (buf) == sizeof (test_output));
- for (i = 0; i < G_N_ELEMENTS (test_input); i++)
- fail_unless (ABS (output[i] - test_output[i]) < 1.e-6,
- "Incorrect output value %.6f for input %.2f, expected %.6f",
- output[i], test_input[i], test_output[i]);
-}
-
-/* Start of tests. */
-
-GST_START_TEST (test_no_buffer)
-{
- GstElement *element = setup_rglimiter ();
-
- set_playing_state (element);
-
- cleanup_rglimiter (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_disabled)
-{
- GstElement *element = setup_rglimiter ();
- GstBuffer *buf, *out_buf;
-
- g_object_set (element, "enabled", FALSE, NULL);
- set_playing_state (element);
-
- buf = create_test_buffer ();
- fail_unless (gst_pad_push (mysrcpad, buf) == GST_FLOW_OK);
- fail_unless (g_list_length (buffers) == 1);
- out_buf = buffers->data;
- fail_if (out_buf == NULL);
- buffers = g_list_remove (buffers, out_buf);
- ASSERT_BUFFER_REFCOUNT (out_buf, "out_buf", 1);
- fail_unless (buf == out_buf);
- gst_buffer_unref (out_buf);
-
- cleanup_rglimiter (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_limiting)
-{
- GstElement *element = setup_rglimiter ();
- GstBuffer *buf, *out_buf;
-
- set_playing_state (element);
-
- /* Mutable variant. */
- buf = create_test_buffer ();
- fail_unless (gst_pad_push (mysrcpad, buf) == GST_FLOW_OK);
- fail_unless (g_list_length (buffers) == 1);
- out_buf = buffers->data;
- fail_if (out_buf == NULL);
- ASSERT_BUFFER_REFCOUNT (out_buf, "out_buf", 1);
- verify_test_buffer (out_buf);
-
- /* Immutable variant. */
- buf = create_test_buffer ();
- /* Extra ref: */
- gst_buffer_ref (buf);
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 2);
- fail_unless (gst_pad_push (mysrcpad, buf) == GST_FLOW_OK);
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
- fail_unless (g_list_length (buffers) == 2);
- out_buf = g_list_last (buffers)->data;
- fail_if (out_buf == NULL);
- ASSERT_BUFFER_REFCOUNT (out_buf, "out_buf", 1);
- fail_unless (buf != out_buf);
- /* Drop our extra ref: */
- gst_buffer_unref (buf);
- verify_test_buffer (out_buf);
-
- cleanup_rglimiter (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_gap)
-{
- GstElement *element = setup_rglimiter ();
- GstBuffer *buf, *out_buf;
-
- set_playing_state (element);
-
- buf = create_test_buffer ();
- GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_GAP);
- fail_unless (gst_pad_push (mysrcpad, buf) == GST_FLOW_OK);
- fail_unless (g_list_length (buffers) == 1);
- out_buf = buffers->data;
- fail_if (out_buf == NULL);
- ASSERT_BUFFER_REFCOUNT (out_buf, "out_buf", 1);
-
- /* Verify that the baseclass does not lift the GAP flag: */
- fail_unless (GST_BUFFER_FLAG_IS_SET (out_buf, GST_BUFFER_FLAG_GAP));
-
- g_assert (GST_BUFFER_SIZE (out_buf) == GST_BUFFER_SIZE (buf));
- /* We cheated by passing an input buffer with non-silence that has the GAP
- * flag set. The element cannot know that however and must have skipped
- * adjusting the buffer because of the flag, which we can easily verify: */
- fail_if (memcmp (GST_BUFFER_DATA (out_buf),
- GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (out_buf)) != 0);
-
- cleanup_rglimiter (element);
-}
-
-GST_END_TEST;
-
-Suite *
-rglimiter_suite (void)
-{
- Suite *s = suite_create ("rglimiter");
- TCase *tc_chain = tcase_create ("general");
-
- suite_add_tcase (s, tc_chain);
-
- tcase_add_test (tc_chain, test_no_buffer);
- tcase_add_test (tc_chain, test_disabled);
- tcase_add_test (tc_chain, test_limiting);
- tcase_add_test (tc_chain, test_gap);
-
- return s;
-}
-
-int
-main (int argc, char **argv)
-{
- gint nf;
-
- Suite *s = rglimiter_suite ();
- SRunner *sr = srunner_create (s);
-
- gst_check_init (&argc, &argv);
-
- srunner_run_all (sr, CK_ENV);
- nf = srunner_ntests_failed (sr);
- srunner_free (sr);
-
- return nf;
-}
diff --git a/tests/check/elements/rgvolume.c b/tests/check/elements/rgvolume.c
deleted file mode 100644
index 7159bb76..00000000
--- a/tests/check/elements/rgvolume.c
+++ /dev/null
@@ -1,573 +0,0 @@
-/* GStreamer ReplayGain volume adjustment
- *
- * Copyright (C) 2007 Rene Stadler <mail@renestadler.de>
- *
- * rgvolume.c: Unit test for the rgvolume element
- *
- * 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
- */
-
-#include <gst/check/gstcheck.h>
-
-#include <math.h>
-
-GList *buffers = NULL;
-GList *events = NULL;
-
-/* 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 */
-static GstPad *mysrcpad, *mysinkpad;
-
-#define RG_VOLUME_CAPS_TEMPLATE_STRING \
- "audio/x-raw-float, " \
- "width = (int) 32, " \
- "endianness = (int) BYTE_ORDER, " \
- "channels = (int) [ 1, MAX ], " \
- "rate = (int) [ 1, MAX ]"
-
-static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (RG_VOLUME_CAPS_TEMPLATE_STRING)
- );
-static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (RG_VOLUME_CAPS_TEMPLATE_STRING)
- );
-
-/* gstcheck sets up a chain function that appends buffers to a global list.
- * This is our equivalent of that for event handling. */
-static gboolean
-event_func (GstPad * pad, GstEvent * event)
-{
- events = g_list_append (events, event);
-
- return TRUE;
-}
-
-GstElement *
-setup_rgvolume ()
-{
- GstElement *element;
-
- GST_DEBUG ("setup_rgvolume");
- element = gst_check_setup_element ("rgvolume");
- mysrcpad = gst_check_setup_src_pad (element, &srctemplate, NULL);
- mysinkpad = gst_check_setup_sink_pad (element, &sinktemplate, NULL);
-
- /* Capture events, to test tag filtering behavior: */
- gst_pad_set_event_function (mysinkpad, event_func);
-
- gst_pad_set_active (mysrcpad, TRUE);
- gst_pad_set_active (mysinkpad, TRUE);
-
- return element;
-}
-
-void
-cleanup_rgvolume (GstElement * element)
-{
- GST_DEBUG ("cleanup_rgvolume");
-
- g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
- g_list_free (buffers);
- buffers = NULL;
-
- g_list_foreach (events, (GFunc) gst_mini_object_unref, NULL);
- g_list_free (events);
- events = NULL;
-
- gst_pad_set_active (mysrcpad, FALSE);
- gst_pad_set_active (mysinkpad, FALSE);
- gst_check_teardown_src_pad (element);
- gst_check_teardown_sink_pad (element);
- gst_check_teardown_element (element);
-}
-
-static void
-set_playing_state (GstElement * element)
-{
- fail_unless (gst_element_set_state (element,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
- "Could not set state to PLAYING");
-}
-
-static void
-set_null_state (GstElement * element)
-{
- fail_unless (gst_element_set_state (element,
- GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS,
- "Could not set state to NULL");
-}
-
-static void
-send_eos_event (GstElement * element)
-{
- GstEvent *event = gst_event_new_eos ();
-
- fail_unless (g_list_length (events) == 0);
- fail_unless (gst_pad_push_event (mysrcpad, event),
- "Pushing EOS event failed");
- fail_unless (g_list_length (events) == 1);
- fail_unless (events->data == event);
- gst_mini_object_unref ((GstMiniObject *) events->data);
- events = g_list_remove (events, event);
-}
-
-static GstEvent *
-send_tag_event (GstElement * element, GstEvent * event)
-{
- g_return_val_if_fail (event->type == GST_EVENT_TAG, NULL);
-
- fail_unless (g_list_length (events) == 0);
- fail_unless (gst_pad_push_event (mysrcpad, event),
- "Pushing tag event failed");
-
- if (g_list_length (events) == 0) {
- /* Event got filtered out. */
- event = NULL;
- } else {
- GstTagList *tag_list;
- gdouble dummy;
-
- event = events->data;
- events = g_list_remove (events, event);
-
- fail_unless (event->type == GST_EVENT_TAG);
- gst_event_parse_tag (event, &tag_list);
-
- /* The element is supposed to filter out ReplayGain related tags. */
- fail_if (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_GAIN, &dummy),
- "tag event still contains track gain tag");
- fail_if (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_PEAK, &dummy),
- "tag event still contains track peak tag");
- fail_if (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_GAIN, &dummy),
- "tag event still contains album gain tag");
- fail_if (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_PEAK, &dummy),
- "tag event still contains album peak tag");
- }
-
- return event;
-}
-
-static GstBuffer *
-test_buffer_new (gfloat value)
-{
- GstBuffer *buf;
- GstCaps *caps;
- gfloat *data;
- gint i;
-
- buf = gst_buffer_new_and_alloc (8 * sizeof (gfloat));
- data = (gfloat *) GST_BUFFER_DATA (buf);
- for (i = 0; i < 8; i++)
- data[i] = value;
-
- caps = gst_caps_from_string ("audio/x-raw-float, "
- "rate = 8000, channels = 1, endianness = BYTE_ORDER, width = 32");
- gst_buffer_set_caps (buf, caps);
- gst_caps_unref (caps);
-
- ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
-
- return buf;
-}
-
-#define MATCH_GAIN(g1, g2) ((g1 < g2 + 1e-6) && (g2 < g1 + 1e-6))
-
-static void
-fail_unless_target_gain (GstElement * element, gdouble expected_gain)
-{
- gdouble prop_gain;
-
- g_object_get (element, "target-gain", &prop_gain, NULL);
-
- fail_unless (MATCH_GAIN (prop_gain, expected_gain),
- "Target gain is %.2f dB, expected %.2f dB", prop_gain, expected_gain);
-}
-
-static void
-fail_unless_result_gain (GstElement * element, gdouble expected_gain)
-{
- GstBuffer *input_buf, *output_buf;
- gfloat input_sample, output_sample;
- gdouble gain, prop_gain;
- gboolean is_passthrough, expect_passthrough;
- gint i;
-
- fail_unless (g_list_length (buffers) == 0);
-
- input_sample = 1.0;
- input_buf = test_buffer_new (input_sample);
-
- /* We keep an extra reference to detect passthrough mode. */
- gst_buffer_ref (input_buf);
- /* Pushing steals a reference. */
- fail_unless (gst_pad_push (mysrcpad, input_buf) == GST_FLOW_OK);
- gst_buffer_unref (input_buf);
-
- /* The output buffer ends up on the global buffer list. */
- fail_unless (g_list_length (buffers) == 1);
- output_buf = buffers->data;
- fail_if (output_buf == NULL);
-
- buffers = g_list_remove (buffers, output_buf);
- ASSERT_BUFFER_REFCOUNT (output_buf, "output_buf", 1);
- fail_unless_equals_int (GST_BUFFER_SIZE (output_buf), 8 * sizeof (gfloat));
-
- output_sample = *((gfloat *) GST_BUFFER_DATA (output_buf));
-
- fail_if (output_sample == 0.0, "First output sample is zero");
- for (i = 1; i < 8; i++) {
- gfloat output = ((gfloat *) GST_BUFFER_DATA (output_buf))[i];
-
- fail_unless (output_sample == output, "Output samples not uniform");
- };
-
- gain = 20. * log10 (output_sample / input_sample);
- fail_unless (MATCH_GAIN (gain, expected_gain),
- "Applied gain is %.2f dB, expected %.2f dB", gain, expected_gain);
- g_object_get (element, "result-gain", &prop_gain, NULL);
- fail_unless (MATCH_GAIN (prop_gain, expected_gain),
- "Result gain is %.2f dB, expected %.2f dB", prop_gain, expected_gain);
-
- is_passthrough = (output_buf == input_buf);
- expect_passthrough = MATCH_GAIN (expected_gain, +0.00);
- fail_unless (is_passthrough == expect_passthrough,
- expect_passthrough
- ? "Expected operation in passthrough mode"
- : "Incorrect passthrough behaviour");
-
- gst_buffer_unref (output_buf);
-}
-
-static void
-fail_unless_gain (GstElement * element, gdouble expected_gain)
-{
- fail_unless_target_gain (element, expected_gain);
- fail_unless_result_gain (element, expected_gain);
-}
-
-/* Start of tests. */
-
-GST_START_TEST (test_no_buffer)
-{
- GstElement *element = setup_rgvolume ();
-
- set_playing_state (element);
- set_null_state (element);
- set_playing_state (element);
- send_eos_event (element);
-
- cleanup_rgvolume (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_events)
-{
- GstElement *element = setup_rgvolume ();
- GstEvent *event;
- GstEvent *new_event;
- GstTagList *tag_list;
- gchar *artist;
-
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, +4.95, GST_TAG_TRACK_PEAK, 0.59463,
- GST_TAG_ALBUM_GAIN, -1.54, GST_TAG_ALBUM_PEAK, 0.693415,
- GST_TAG_ARTIST, "Foobar", NULL);
- event = gst_event_new_tag (tag_list);
- new_event = send_tag_event (element, event);
- /* Expect the element to modify the writable event. */
- fail_unless (event == new_event, "Writable tag event not reused");
- gst_event_parse_tag (new_event, &tag_list);
- fail_unless (gst_tag_list_get_string (tag_list, GST_TAG_ARTIST, &artist));
- fail_unless (g_str_equal (artist, "Foobar"));
- g_free (artist);
- gst_event_unref (new_event);
-
- /* Same as above, but with a non-writable event. */
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, +4.95, GST_TAG_TRACK_PEAK, 0.59463,
- GST_TAG_ALBUM_GAIN, -1.54, GST_TAG_ALBUM_PEAK, 0.693415,
- GST_TAG_ARTIST, "Foobar", NULL);
- event = gst_event_new_tag (tag_list);
- /* Holding an extra ref makes the event unwritable: */
- gst_event_ref (event);
- new_event = send_tag_event (element, event);
- fail_unless (event != new_event, "Unwritable tag event reused");
- gst_event_parse_tag (new_event, &tag_list);
- fail_unless (gst_tag_list_get_string (tag_list, GST_TAG_ARTIST, &artist));
- fail_unless (g_str_equal (artist, "Foobar"));
- g_free (artist);
- gst_event_unref (event);
- gst_event_unref (new_event);
-
- cleanup_rgvolume (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_simple)
-{
- GstElement *element = setup_rgvolume ();
- GstTagList *tag_list;
-
- g_object_set (element, "album-mode", FALSE, "headroom", +0.00,
- "pre-amp", -6.00, "fallback-gain", +1.23, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, -3.45, GST_TAG_TRACK_PEAK, 1.0,
- GST_TAG_ALBUM_GAIN, +2.09, GST_TAG_ALBUM_PEAK, 1.0, NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_gain (element, -9.45); /* pre-amp + track gain */
- send_eos_event (element);
-
- g_object_set (element, "album-mode", TRUE, NULL);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, -3.45, GST_TAG_TRACK_PEAK, 1.0,
- GST_TAG_ALBUM_GAIN, +2.09, GST_TAG_ALBUM_PEAK, 1.0, NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_gain (element, -3.91); /* pre-amp + album gain */
-
- /* Switching back to track mode in the middle of a stream: */
- g_object_set (element, "album-mode", FALSE, NULL);
- fail_unless_gain (element, -9.45); /* pre-amp + track gain */
- send_eos_event (element);
-
- cleanup_rgvolume (element);
-}
-
-GST_END_TEST;
-
-/* If there are no gain tags at all, the fallback gain is used. */
-
-GST_START_TEST (test_fallback_gain)
-{
- GstElement *element = setup_rgvolume ();
- GstTagList *tag_list;
-
- /* First some track where fallback does _not_ apply. */
-
- g_object_set (element, "album-mode", FALSE, "headroom", 10.00,
- "pre-amp", -6.00, "fallback-gain", -3.00, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, +3.5, GST_TAG_TRACK_PEAK, 1.0,
- GST_TAG_ALBUM_GAIN, -0.5, GST_TAG_ALBUM_PEAK, 1.0, NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_gain (element, -2.50); /* pre-amp + track gain */
- send_eos_event (element);
-
- /* Now a track completely missing tags. */
-
- fail_unless_gain (element, -9.00); /* pre-amp + fallback-gain */
-
- /* Changing the fallback gain in the middle of a stream, going to pass-through
- * mode: */
- g_object_set (element, "fallback-gain", +6.00, NULL);
- fail_unless_gain (element, +0.00); /* pre-amp + fallback-gain */
- send_eos_event (element);
-
- /* Verify that result gain is set to +0.00 with pre-amp + fallback-gain >
- * +0.00 and no headroom. */
-
- g_object_set (element, "fallback-gain", +12.00, "headroom", +0.00, NULL);
- fail_unless_target_gain (element, +6.00); /* pre-amp + fallback-gain */
- fail_unless_result_gain (element, +0.00);
- send_eos_event (element);
-
- cleanup_rgvolume (element);
-}
-
-GST_END_TEST;
-
-/* If album gain is to be preferred but not available, the track gain is to be
- * taken instead. */
-
-GST_START_TEST (test_fallback_track)
-{
- GstElement *element = setup_rgvolume ();
- GstTagList *tag_list;
-
- g_object_set (element, "album-mode", TRUE, "headroom", +0.00,
- "pre-amp", -6.00, "fallback-gain", +1.23, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, +2.11, GST_TAG_TRACK_PEAK, 1.0, NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_gain (element, -3.89); /* pre-amp + track gain */
-
- send_eos_event (element);
-
- cleanup_rgvolume (element);
-}
-
-GST_END_TEST;
-
-/* If track gain is to be preferred but not available, the album gain is to be
- * taken instead. */
-
-GST_START_TEST (test_fallback_album)
-{
- GstElement *element = setup_rgvolume ();
- GstTagList *tag_list;
-
- g_object_set (element, "album-mode", FALSE, "headroom", +0.00,
- "pre-amp", -6.00, "fallback-gain", +1.23, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_ALBUM_GAIN, +3.73, GST_TAG_ALBUM_PEAK, 1.0, NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_gain (element, -2.27); /* pre-amp + album gain */
-
- send_eos_event (element);
-
- cleanup_rgvolume (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_headroom)
-{
- GstElement *element = setup_rgvolume ();
- GstTagList *tag_list;
-
- g_object_set (element, "album-mode", FALSE, "headroom", +0.00,
- "pre-amp", +0.00, "fallback-gain", +1.23, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, +3.50, GST_TAG_TRACK_PEAK, 1.0, NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_target_gain (element, +3.50); /* pre-amp + track gain */
- fail_unless_result_gain (element, +0.00);
- send_eos_event (element);
-
- g_object_set (element, "headroom", +2.00, NULL);
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, +9.18, GST_TAG_TRACK_PEAK, 0.687149, NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_target_gain (element, +9.18); /* pre-amp + track gain */
- /* Result is 20. * log10 (1. / peak) + headroom. */
- fail_unless_result_gain (element, 5.2589816238303335);
- send_eos_event (element);
-
- g_object_set (element, "album-mode", TRUE, NULL);
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_ALBUM_GAIN, +5.50, GST_TAG_ALBUM_PEAK, 1.0, NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_target_gain (element, +5.50); /* pre-amp + album gain */
- fail_unless_result_gain (element, +2.00); /* headroom */
- send_eos_event (element);
-
- cleanup_rgvolume (element);
-}
-
-GST_END_TEST;
-
-GST_START_TEST (test_reference_level)
-{
- GstElement *element = setup_rgvolume ();
- GstTagList *tag_list;
-
- g_object_set (element,
- "album-mode", FALSE,
- "headroom", +0.00, "pre-amp", +0.00, "fallback-gain", +1.23, NULL);
- set_playing_state (element);
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, 0.00, GST_TAG_TRACK_PEAK, 0.2,
- GST_TAG_REFERENCE_LEVEL, 83., NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- /* Because our authorative reference is 89 dB, we bump it up by +6 dB. */
- fail_unless_gain (element, +6.00); /* pre-amp + track gain */
- send_eos_event (element);
-
- g_object_set (element, "album-mode", TRUE, NULL);
-
- /* Same as above, but with album gain. */
-
- tag_list = gst_tag_list_new ();
- gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE,
- GST_TAG_TRACK_GAIN, 1.23, GST_TAG_TRACK_PEAK, 0.1,
- GST_TAG_ALBUM_GAIN, 0.00, GST_TAG_ALBUM_PEAK, 0.2,
- GST_TAG_REFERENCE_LEVEL, 83., NULL);
- fail_unless (send_tag_event (element, gst_event_new_tag (tag_list)) == NULL);
- fail_unless_gain (element, +6.00); /* pre-amp + album gain */
-
- cleanup_rgvolume (element);
-}
-
-GST_END_TEST;
-
-Suite *
-rgvolume_suite (void)
-{
- Suite *s = suite_create ("rgvolume");
- TCase *tc_chain = tcase_create ("general");
-
- suite_add_tcase (s, tc_chain);
-
- tcase_add_test (tc_chain, test_no_buffer);
- tcase_add_test (tc_chain, test_events);
- tcase_add_test (tc_chain, test_simple);
- tcase_add_test (tc_chain, test_fallback_gain);
- tcase_add_test (tc_chain, test_fallback_track);
- tcase_add_test (tc_chain, test_fallback_album);
- tcase_add_test (tc_chain, test_headroom);
- tcase_add_test (tc_chain, test_reference_level);
-
- return s;
-}
-
-int
-main (int argc, char **argv)
-{
- gint nf;
-
- Suite *s = rgvolume_suite ();
- SRunner *sr = srunner_create (s);
-
- gst_check_init (&argc, &argv);
-
- srunner_run_all (sr, CK_ENV);
- nf = srunner_ntests_failed (sr);
- srunner_free (sr);
-
- return nf;
-}