mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-20 00:31:13 +00:00
Andrewio Patrickoforus Wingonymus - 5 additional tests for your sins
Original commit message from CVS: Andrewio Patrickoforus Wingonymus - 5 additional tests for your sins Add a regression test for level and fix a casting bug that made the additional channels turn out wrong
This commit is contained in:
parent
63efb534b9
commit
423df73380
14 changed files with 505 additions and 40 deletions
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
2005-09-01 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* Makefile.am:
|
||||
* check/.cvsignore:
|
||||
* check/Makefile.am:
|
||||
* check/elements/.cvsignore:
|
||||
* check/elements/level.c: (setup_level), (cleanup_level),
|
||||
(GST_START_TEST), (level_suite), (main):
|
||||
add a test for level
|
||||
* common/release.mak:
|
||||
move the enum checking to release.mak
|
||||
* configure.ac:
|
||||
add valgrind and check checking
|
||||
* gst/level/gstlevel.c: (gst_level_transform):
|
||||
* gst/level/gstlevel.h:
|
||||
fix Andy's cast bug
|
||||
convert a field to int
|
||||
fix the arithmetic to int when checking for emit so that a
|
||||
100-sample buffer of a 1000Hz stream triggers after 0.1 sec
|
||||
|
||||
2005-09-01 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* Makefile.am:
|
||||
|
|
30
Makefile.am
30
Makefile.am
|
@ -4,15 +4,19 @@ else
|
|||
GCONF_DIR =
|
||||
endif
|
||||
|
||||
ALWAYS_SUBDIRS = \
|
||||
gst sys ext \
|
||||
check docs \
|
||||
po \
|
||||
m4 common
|
||||
|
||||
SUBDIRS = \
|
||||
gst sys ext docs \
|
||||
$(GCONF_DIR) \
|
||||
m4 common po
|
||||
$(ALWAYS_SUBDIRS) \
|
||||
$(GCONF_DIR)
|
||||
|
||||
DIST_SUBDIRS = \
|
||||
gst sys ext docs \
|
||||
gconf \
|
||||
m4 common po
|
||||
$(ALWAYS_SUBDIRS) \
|
||||
gconf
|
||||
|
||||
EXTRA_DIST = \
|
||||
gst-plugins-good.spec depcomp \
|
||||
|
@ -25,17 +29,5 @@ noinst_HEADERS = \
|
|||
gst-libs/gst/gettext.h \
|
||||
gst-libs/gst/gst-i18n-plugin.h
|
||||
|
||||
# check that no marshal or enumtypes files are included
|
||||
# this in turn ensures that distcheck fails for missing .list files which is currently
|
||||
# shadowed when the corresponding .c and .h files are included.
|
||||
distcheck-hook:
|
||||
@test "x" = "x`find $(distdir) -name \*-enumtypes.[ch]`" && \
|
||||
test "x" = "x`find $(distdir) -name \*-marshal.[ch]`" || \
|
||||
( $(ECHO) "*** Leftover enumtypes or marshal files in the tarball." && \
|
||||
$(ECHO) "*** Make sure the following files are not disted:" && \
|
||||
find $(distdir) -name \*-enumtypes.[ch] && \
|
||||
find $(distdir) -name \*-marshal.[ch] && \
|
||||
false )
|
||||
|
||||
# include $(top_srcdir)/common/release.mak
|
||||
include $(top_srcdir)/common/release.mak
|
||||
# include $(top_srcdir)/common/po.mak
|
||||
|
|
1
check/.gitignore
vendored
Normal file
1
check/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
test-registry.xml
|
38
check/Makefile.am
Normal file
38
check/Makefile.am
Normal file
|
@ -0,0 +1,38 @@
|
|||
include $(top_srcdir)/common/check.mak
|
||||
|
||||
CHECK_REGISTRY = $(top_builddir)/check/test-registry.xml
|
||||
|
||||
REGISTRY_ENVIRONMENT = \
|
||||
GST_REGISTRY=$(CHECK_REGISTRY)
|
||||
|
||||
TESTS_ENVIRONMENT = \
|
||||
$(REGISTRY_ENVIRONMENT) \
|
||||
GST_PLUGIN_PATH_ONLY=yes \
|
||||
GST_PLUGIN_PATH=$(top_builddir)/gst:$(top_builddir)/ext:$(GST_PLUGINS_DIR)
|
||||
|
||||
# ths core dumps of some machines have PIDs appended
|
||||
CLEANFILES = core.* test-registry.xml
|
||||
|
||||
clean-local: clean-local-check
|
||||
|
||||
$(CHECK_REGISTRY):
|
||||
$(TESTS_ENVIRONMENT) \
|
||||
$(GST_TOOLS_DIR)/gst-register-@GST_MAJORMINOR@
|
||||
|
||||
TESTS = $(GST_TOOLS_DIR)/gst-register-@GST_MAJORMINOR@ \
|
||||
$(check_PROGRAMS)
|
||||
|
||||
check_PROGRAMS = \
|
||||
elements/level
|
||||
|
||||
# these tests don't even pass
|
||||
noinst_PROGRAMS =
|
||||
|
||||
AM_CFLAGS = $(GST_OBJ_CFLAGS) $(GST_CHECK_CFLAGS) $(CHECK_CFLAGS)
|
||||
LDADD = $(GST_OBJ_LIBS) $(GST_CHECK_LIBS) $(CHECK_LIBS)
|
||||
|
||||
# valgrind testing
|
||||
VALGRIND_TESTS_DISABLE = \
|
||||
$(GST_TOOLS_DIR)/gst-register-@GST_MAJORMINOR@
|
||||
|
||||
SUPPRESSIONS = $(top_srcdir)/common/gst.supp
|
2
check/elements/.gitignore
vendored
Normal file
2
check/elements/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.dirstamp
|
||||
level
|
184
check/elements/level.c
Normal file
184
check/elements/level.c
Normal file
|
@ -0,0 +1,184 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for level
|
||||
*
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
GList *buffers = NULL;
|
||||
gboolean have_eos = FALSE;
|
||||
|
||||
/* For ease of programming we use globals to keep refs for our floating
|
||||
* src and sink pads we create; otherwise we always have to do get_pad,
|
||||
* get_peer, and then remove references in every test function */
|
||||
GstPad *mysrcpad, *mysinkpad;
|
||||
|
||||
#define LEVEL_CAPS_TEMPLATE_STRING \
|
||||
"audio/x-raw-int, " \
|
||||
"rate = (int) [ 1, MAX ], " \
|
||||
"channels = (int) [ 1, 8 ], " \
|
||||
"endianness = (int) BYTE_ORDER, " \
|
||||
"width = (int) {8, 16}, " \
|
||||
"depth = (int) {8, 16}, " \
|
||||
"signed = (boolean) true"
|
||||
|
||||
#define LEVEL_CAPS_STRING \
|
||||
"audio/x-raw-int, " \
|
||||
"rate = (int) 1000, " \
|
||||
"channels = (int) 2, " \
|
||||
"endianness = (int) BYTE_ORDER, " \
|
||||
"width = (int) 16, " \
|
||||
"depth = (int) 16, " \
|
||||
"signed = (boolean) true"
|
||||
|
||||
|
||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (LEVEL_CAPS_TEMPLATE_STRING)
|
||||
);
|
||||
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (LEVEL_CAPS_TEMPLATE_STRING)
|
||||
);
|
||||
|
||||
/* takes over reference for outcaps */
|
||||
GstElement *
|
||||
setup_level ()
|
||||
{
|
||||
GstElement *level;
|
||||
|
||||
GST_DEBUG ("setup_level");
|
||||
level = gst_check_setup_element ("level");
|
||||
mysrcpad = gst_check_setup_src_pad (level, &srctemplate, NULL);
|
||||
mysinkpad = gst_check_setup_sink_pad (level, &sinktemplate, NULL);
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
void
|
||||
cleanup_level (GstElement * level)
|
||||
{
|
||||
GST_DEBUG ("cleanup_level");
|
||||
|
||||
gst_check_teardown_src_pad (level);
|
||||
gst_check_teardown_sink_pad (level);
|
||||
gst_check_teardown_element (level);
|
||||
}
|
||||
|
||||
|
||||
GST_START_TEST (test_int16)
|
||||
{
|
||||
GstElement *level;
|
||||
GstBuffer *inbuffer, *outbuffer;
|
||||
GstBus *bus;
|
||||
GstMessage *message;
|
||||
const GstStructure *structure;
|
||||
int i, j;
|
||||
gint16 *data;
|
||||
const GValue *list, *value;
|
||||
gdouble dB;
|
||||
|
||||
level = setup_level ();
|
||||
g_object_set (level, "message", TRUE, "interval", 0.1, NULL);
|
||||
|
||||
fail_unless (gst_element_set_state (level,
|
||||
GST_STATE_PLAYING) == GST_STATE_SUCCESS, "could not set to playing");
|
||||
|
||||
/* create a fake 0.1 sec buffer with a half-amplitude block signal */
|
||||
inbuffer = gst_buffer_new_and_alloc (400);
|
||||
data = (gint16 *) GST_BUFFER_DATA (inbuffer);
|
||||
for (j = 0; j < 200; ++j) {
|
||||
*data = 16536;
|
||||
++data;
|
||||
}
|
||||
gst_buffer_set_caps (inbuffer, gst_caps_from_string (LEVEL_CAPS_STRING));
|
||||
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
||||
|
||||
/* create a bus to get the level message on */
|
||||
bus = gst_bus_new ();
|
||||
gst_element_set_bus (level, bus);
|
||||
|
||||
/* pushing gives away my reference ... */
|
||||
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
||||
/* ... but it ends up being collected on the global buffer list */
|
||||
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (inbuffer == outbuffer);
|
||||
|
||||
fail_unless_equals_int (gst_bus_poll (bus, GST_MESSAGE_APPLICATION, -1),
|
||||
GST_MESSAGE_APPLICATION);
|
||||
message = gst_bus_pop (bus);
|
||||
fail_unless (GST_MESSAGE_SRC (message) == GST_OBJECT (level));
|
||||
structure = gst_message_get_structure (message);
|
||||
fail_if (structure == NULL);
|
||||
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
|
||||
"level");
|
||||
|
||||
/* block wave of half amplitude has -5.94 dB for rms, peak and decay */
|
||||
for (i = 0; i < 2; ++i) {
|
||||
gchar *fields[3] = { "rms", "peak", "decay" };
|
||||
for (j = 0; j < 3; ++j) {
|
||||
list = gst_structure_get_value (structure, fields[j]);
|
||||
value = gst_value_list_get_value (list, i);
|
||||
dB = g_value_get_double (value);
|
||||
fail_if (dB < -6.0);
|
||||
fail_if (dB > -5.9);
|
||||
}
|
||||
}
|
||||
|
||||
gst_message_unref (message);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
Suite *
|
||||
level_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("level");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_int16);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = level_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
return nf;
|
||||
}
|
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit b0ee0e4262014001faceb47d71c3a44c75ab86b4
|
||||
Subproject commit cd012821aa2e4f6247f4cd6dee14116f86421a7e
|
|
@ -220,6 +220,12 @@ fi
|
|||
AC_SUBST(GST_PLUGINS_BASE_LIBS)
|
||||
AC_SUBST(GST_PLUGINS_BASE_CFLAGS)
|
||||
|
||||
PKG_CHECK_MODULES(GST_CHECK, gstreamer-check-$GST_MAJORMINOR >= $GST_REQ,
|
||||
HAVE_GST_CHECK="yes", HAVE_GST_CHECK="no")
|
||||
|
||||
AC_PATH_PROG(VALGRIND_PATH, valgrind, no)
|
||||
AM_CONDITIONAL(HAVE_VALGRIND, test ! "x$VALGRIND_PATH" = "xno")
|
||||
|
||||
dnl Determine endianness
|
||||
AC_C_BIGENDIAN
|
||||
|
||||
|
@ -593,6 +599,7 @@ gconf/gstreamer.schemas
|
|||
docs/Makefile
|
||||
docs/plugins/Makefile
|
||||
docs/version.entities
|
||||
check/Makefile
|
||||
common/Makefile
|
||||
common/m4/Makefile
|
||||
m4/Makefile
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||
*
|
||||
* gstlevel.c: signals RMS, peak and decaying peak levels
|
||||
* Copyright (C) 2000,2001,2002,2003
|
||||
* Copyright (C) 2000,2001,2002,2003,2005
|
||||
* Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
|
@ -34,7 +32,7 @@ GST_DEBUG_CATEGORY (level_debug);
|
|||
static GstElementDetails level_details = {
|
||||
"Level",
|
||||
"Filter/Analyzer/Audio",
|
||||
"RMS/Peak/Decaying Peak Level signaller for audio/raw",
|
||||
"RMS/Peak/Decaying Peak Level messager for audio/raw",
|
||||
"Thomas <thomas@apestaart.org>"
|
||||
};
|
||||
|
||||
|
@ -113,11 +111,11 @@ gst_level_class_init (GstLevelClass * klass)
|
|||
gobject_class->get_property = gst_level_get_property;
|
||||
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SIGNAL_LEVEL,
|
||||
g_param_spec_boolean ("signal", "Signal",
|
||||
"Emit level signals for each interval", TRUE, G_PARAM_READWRITE));
|
||||
g_param_spec_boolean ("message", "mesage",
|
||||
"Post a level message for each interval", TRUE, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SIGNAL_INTERVAL,
|
||||
g_param_spec_double ("interval", "Interval",
|
||||
"Interval between emissions (in seconds)",
|
||||
"Interval between posts (in seconds)",
|
||||
0.01, 100.0, 0.1, G_PARAM_READWRITE));
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PEAK_TTL,
|
||||
g_param_spec_double ("peak_ttl", "Peak TTL",
|
||||
|
@ -158,7 +156,7 @@ gst_level_set_property (GObject * object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_SIGNAL_LEVEL:
|
||||
filter->signal = g_value_get_boolean (value);
|
||||
filter->message = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_SIGNAL_INTERVAL:
|
||||
filter->interval = g_value_get_double (value);
|
||||
|
@ -182,7 +180,7 @@ gst_level_get_property (GObject * object, guint prop_id,
|
|||
|
||||
switch (prop_id) {
|
||||
case PROP_SIGNAL_LEVEL:
|
||||
g_value_set_boolean (value, filter->signal);
|
||||
g_value_set_boolean (value, filter->message);
|
||||
break;
|
||||
case PROP_SIGNAL_INTERVAL:
|
||||
g_value_set_double (value, filter->interval);
|
||||
|
@ -356,7 +354,7 @@ gst_level_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
|
|||
CS = 0.0;
|
||||
switch (filter->width) {
|
||||
case 16:
|
||||
gst_level_calculate_gint16 (in_data + i, num_int_samples,
|
||||
gst_level_calculate_gint16 (((gint16 *) in_data) + i, num_int_samples,
|
||||
filter->channels, filter->width - 1, &CS, &filter->peak[i]);
|
||||
break;
|
||||
case 8:
|
||||
|
@ -365,7 +363,7 @@ gst_level_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
|
|||
break;
|
||||
}
|
||||
GST_LOG_OBJECT (filter,
|
||||
"channel %d, cumulative sum %f, peak %f, over %d channels/%d samples",
|
||||
"channel %d, cumulative sum %f, peak %f, over %d samples/%d channels",
|
||||
i, CS, filter->peak[i], num_int_samples, filter->channels);
|
||||
filter->CS[i] += CS;
|
||||
}
|
||||
|
@ -413,8 +411,8 @@ gst_level_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
|
|||
|
||||
/* do we need to emit ? */
|
||||
|
||||
if (filter->num_samples >= filter->interval * (gdouble) filter->rate) {
|
||||
if (filter->signal) {
|
||||
if (filter->num_samples >= (gint) (filter->interval * filter->rate)) {
|
||||
if (filter->message) {
|
||||
GstMessage *m;
|
||||
double endtime, RMS;
|
||||
double RMSdB, lastdB, decaydB;
|
||||
|
@ -428,7 +426,7 @@ gst_level_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
|
|||
for (i = 0; i < filter->channels; ++i) {
|
||||
RMS = sqrt (filter->CS[i] / filter->num_samples);
|
||||
GST_LOG_OBJECT (filter,
|
||||
"CS: %f, num_samples %f, channel %d, RMS %f",
|
||||
"CS: %f, num_samples %d, channel %d, RMS %f",
|
||||
filter->CS[i], filter->num_samples, i, RMS);
|
||||
/* RMS values are calculated in amplitude, so 20 * log 10 */
|
||||
RMSdB = 20 * log10 (RMS);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||
*
|
||||
* gstlevel.c: signals RMS, peak and decaying peak levels
|
||||
* Copyright (C) 2000,2001,2002,2003
|
||||
* Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
|
||||
* Copyright (C) 2000,2001,2002,2003,2005
|
||||
* Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
|
@ -52,7 +50,7 @@ typedef struct _GstLevelClass GstLevelClass;
|
|||
struct _GstLevel {
|
||||
GstBaseTransform element;
|
||||
|
||||
gboolean signal; /* whether or not to emit signals */
|
||||
gboolean message; /* whether or not to post messages */
|
||||
gdouble interval; /* how many seconds between emits */
|
||||
|
||||
gint rate; /* caps variables */
|
||||
|
@ -61,7 +59,7 @@ struct _GstLevel {
|
|||
|
||||
gdouble decay_peak_ttl; /* time to live for peak in seconds */
|
||||
gdouble decay_peak_falloff; /* falloff in dB/sec */
|
||||
gdouble num_samples; /* one-channel sample count since last emit */
|
||||
gint num_samples; /* one-channel sample count since last emit */
|
||||
|
||||
/* per-channel arrays for intermediate values */
|
||||
gdouble *CS; /* normalized Cumulative Square */
|
||||
|
|
1
tests/check/.gitignore
vendored
Normal file
1
tests/check/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
test-registry.xml
|
38
tests/check/Makefile.am
Normal file
38
tests/check/Makefile.am
Normal file
|
@ -0,0 +1,38 @@
|
|||
include $(top_srcdir)/common/check.mak
|
||||
|
||||
CHECK_REGISTRY = $(top_builddir)/check/test-registry.xml
|
||||
|
||||
REGISTRY_ENVIRONMENT = \
|
||||
GST_REGISTRY=$(CHECK_REGISTRY)
|
||||
|
||||
TESTS_ENVIRONMENT = \
|
||||
$(REGISTRY_ENVIRONMENT) \
|
||||
GST_PLUGIN_PATH_ONLY=yes \
|
||||
GST_PLUGIN_PATH=$(top_builddir)/gst:$(top_builddir)/ext:$(GST_PLUGINS_DIR)
|
||||
|
||||
# ths core dumps of some machines have PIDs appended
|
||||
CLEANFILES = core.* test-registry.xml
|
||||
|
||||
clean-local: clean-local-check
|
||||
|
||||
$(CHECK_REGISTRY):
|
||||
$(TESTS_ENVIRONMENT) \
|
||||
$(GST_TOOLS_DIR)/gst-register-@GST_MAJORMINOR@
|
||||
|
||||
TESTS = $(GST_TOOLS_DIR)/gst-register-@GST_MAJORMINOR@ \
|
||||
$(check_PROGRAMS)
|
||||
|
||||
check_PROGRAMS = \
|
||||
elements/level
|
||||
|
||||
# these tests don't even pass
|
||||
noinst_PROGRAMS =
|
||||
|
||||
AM_CFLAGS = $(GST_OBJ_CFLAGS) $(GST_CHECK_CFLAGS) $(CHECK_CFLAGS)
|
||||
LDADD = $(GST_OBJ_LIBS) $(GST_CHECK_LIBS) $(CHECK_LIBS)
|
||||
|
||||
# valgrind testing
|
||||
VALGRIND_TESTS_DISABLE = \
|
||||
$(GST_TOOLS_DIR)/gst-register-@GST_MAJORMINOR@
|
||||
|
||||
SUPPRESSIONS = $(top_srcdir)/common/gst.supp
|
2
tests/check/elements/.gitignore
vendored
Normal file
2
tests/check/elements/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.dirstamp
|
||||
level
|
184
tests/check/elements/level.c
Normal file
184
tests/check/elements/level.c
Normal file
|
@ -0,0 +1,184 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* unit test for level
|
||||
*
|
||||
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
GList *buffers = NULL;
|
||||
gboolean have_eos = FALSE;
|
||||
|
||||
/* For ease of programming we use globals to keep refs for our floating
|
||||
* src and sink pads we create; otherwise we always have to do get_pad,
|
||||
* get_peer, and then remove references in every test function */
|
||||
GstPad *mysrcpad, *mysinkpad;
|
||||
|
||||
#define LEVEL_CAPS_TEMPLATE_STRING \
|
||||
"audio/x-raw-int, " \
|
||||
"rate = (int) [ 1, MAX ], " \
|
||||
"channels = (int) [ 1, 8 ], " \
|
||||
"endianness = (int) BYTE_ORDER, " \
|
||||
"width = (int) {8, 16}, " \
|
||||
"depth = (int) {8, 16}, " \
|
||||
"signed = (boolean) true"
|
||||
|
||||
#define LEVEL_CAPS_STRING \
|
||||
"audio/x-raw-int, " \
|
||||
"rate = (int) 1000, " \
|
||||
"channels = (int) 2, " \
|
||||
"endianness = (int) BYTE_ORDER, " \
|
||||
"width = (int) 16, " \
|
||||
"depth = (int) 16, " \
|
||||
"signed = (boolean) true"
|
||||
|
||||
|
||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (LEVEL_CAPS_TEMPLATE_STRING)
|
||||
);
|
||||
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (LEVEL_CAPS_TEMPLATE_STRING)
|
||||
);
|
||||
|
||||
/* takes over reference for outcaps */
|
||||
GstElement *
|
||||
setup_level ()
|
||||
{
|
||||
GstElement *level;
|
||||
|
||||
GST_DEBUG ("setup_level");
|
||||
level = gst_check_setup_element ("level");
|
||||
mysrcpad = gst_check_setup_src_pad (level, &srctemplate, NULL);
|
||||
mysinkpad = gst_check_setup_sink_pad (level, &sinktemplate, NULL);
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
void
|
||||
cleanup_level (GstElement * level)
|
||||
{
|
||||
GST_DEBUG ("cleanup_level");
|
||||
|
||||
gst_check_teardown_src_pad (level);
|
||||
gst_check_teardown_sink_pad (level);
|
||||
gst_check_teardown_element (level);
|
||||
}
|
||||
|
||||
|
||||
GST_START_TEST (test_int16)
|
||||
{
|
||||
GstElement *level;
|
||||
GstBuffer *inbuffer, *outbuffer;
|
||||
GstBus *bus;
|
||||
GstMessage *message;
|
||||
const GstStructure *structure;
|
||||
int i, j;
|
||||
gint16 *data;
|
||||
const GValue *list, *value;
|
||||
gdouble dB;
|
||||
|
||||
level = setup_level ();
|
||||
g_object_set (level, "message", TRUE, "interval", 0.1, NULL);
|
||||
|
||||
fail_unless (gst_element_set_state (level,
|
||||
GST_STATE_PLAYING) == GST_STATE_SUCCESS, "could not set to playing");
|
||||
|
||||
/* create a fake 0.1 sec buffer with a half-amplitude block signal */
|
||||
inbuffer = gst_buffer_new_and_alloc (400);
|
||||
data = (gint16 *) GST_BUFFER_DATA (inbuffer);
|
||||
for (j = 0; j < 200; ++j) {
|
||||
*data = 16536;
|
||||
++data;
|
||||
}
|
||||
gst_buffer_set_caps (inbuffer, gst_caps_from_string (LEVEL_CAPS_STRING));
|
||||
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
||||
|
||||
/* create a bus to get the level message on */
|
||||
bus = gst_bus_new ();
|
||||
gst_element_set_bus (level, bus);
|
||||
|
||||
/* pushing gives away my reference ... */
|
||||
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
||||
/* ... but it ends up being collected on the global buffer list */
|
||||
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (inbuffer == outbuffer);
|
||||
|
||||
fail_unless_equals_int (gst_bus_poll (bus, GST_MESSAGE_APPLICATION, -1),
|
||||
GST_MESSAGE_APPLICATION);
|
||||
message = gst_bus_pop (bus);
|
||||
fail_unless (GST_MESSAGE_SRC (message) == GST_OBJECT (level));
|
||||
structure = gst_message_get_structure (message);
|
||||
fail_if (structure == NULL);
|
||||
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
|
||||
"level");
|
||||
|
||||
/* block wave of half amplitude has -5.94 dB for rms, peak and decay */
|
||||
for (i = 0; i < 2; ++i) {
|
||||
gchar *fields[3] = { "rms", "peak", "decay" };
|
||||
for (j = 0; j < 3; ++j) {
|
||||
list = gst_structure_get_value (structure, fields[j]);
|
||||
value = gst_value_list_get_value (list, i);
|
||||
dB = g_value_get_double (value);
|
||||
fail_if (dB < -6.0);
|
||||
fail_if (dB > -5.9);
|
||||
}
|
||||
}
|
||||
|
||||
gst_message_unref (message);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
Suite *
|
||||
level_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("level");
|
||||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_int16);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int nf;
|
||||
|
||||
Suite *s = level_suite ();
|
||||
SRunner *sr = srunner_create (s);
|
||||
|
||||
gst_check_init (&argc, &argv);
|
||||
|
||||
srunner_run_all (sr, CK_NORMAL);
|
||||
nf = srunner_ntests_failed (sr);
|
||||
srunner_free (sr);
|
||||
|
||||
return nf;
|
||||
}
|
Loading…
Reference in a new issue