mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-23 23:58:17 +00:00
tests/check/elements/level.c: Add a test for level in stereo mode.
Original commit message from CVS: * tests/check/elements/level.c: Add a test for level in stereo mode.
This commit is contained in:
parent
0f6a6dc73a
commit
e6663a01f2
2 changed files with 109 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
2008-08-10 Stefan Kost <ensonic@users.sf.net>
|
||||
|
||||
* tests/check/elements/level.c:
|
||||
Add a test for level in stereo mode.
|
||||
|
||||
2008-08-10 Stefan Kost <ensonic@users.sf.net>
|
||||
|
||||
* tests/examples/spectrum/demo-audiotest.c:
|
||||
|
|
|
@ -187,6 +187,109 @@ GST_START_TEST (test_int16)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_int16_panned)
|
||||
{
|
||||
GstElement *level;
|
||||
GstBuffer *inbuffer, *outbuffer;
|
||||
GstBus *bus;
|
||||
GstCaps *caps;
|
||||
GstMessage *message;
|
||||
const GstStructure *structure;
|
||||
int j;
|
||||
gint16 *data;
|
||||
const GValue *list, *value;
|
||||
GstClockTime endtime;
|
||||
gdouble dB;
|
||||
|
||||
level = setup_level ();
|
||||
g_object_set (level, "message", TRUE, "interval", GST_SECOND / 10, NULL);
|
||||
|
||||
fail_unless (gst_element_set_state (level,
|
||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_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 < 100; ++j) {
|
||||
*data = 0;
|
||||
++data;
|
||||
*data = 16536;
|
||||
++data;
|
||||
}
|
||||
caps = gst_caps_from_string (LEVEL_CAPS_STRING);
|
||||
gst_buffer_set_caps (inbuffer, caps);
|
||||
gst_caps_unref (caps);
|
||||
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
||||
|
||||
/* create a bus to get the level message on */
|
||||
bus = gst_bus_new ();
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1);
|
||||
gst_element_set_bus (level, bus);
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
|
||||
|
||||
/* 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);
|
||||
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, -1);
|
||||
ASSERT_OBJECT_REFCOUNT (message, "message", 1);
|
||||
|
||||
fail_unless (message != NULL);
|
||||
fail_unless (GST_MESSAGE_SRC (message) == GST_OBJECT (level));
|
||||
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT);
|
||||
structure = gst_message_get_structure (message);
|
||||
fail_if (structure == NULL);
|
||||
fail_unless_equals_string ((char *) gst_structure_get_name (structure),
|
||||
"level");
|
||||
fail_unless (gst_structure_get_clock_time (structure, "endtime", &endtime));
|
||||
|
||||
gchar *fields[3] = { "rms", "peak", "decay" };
|
||||
/* silence has 0 dB for rms, peak and decay */
|
||||
for (j = 0; j < 3; ++j) {
|
||||
list = gst_structure_get_value (structure, fields[j]);
|
||||
value = gst_value_list_get_value (list, 0);
|
||||
dB = g_value_get_double (value);
|
||||
GST_DEBUG ("%s[0] is %lf", fields[j], dB);
|
||||
fail_if (!isinf (dB));
|
||||
}
|
||||
/* block wave of half amplitude has -5.94 dB for rms, peak and decay */
|
||||
for (j = 0; j < 3; ++j) {
|
||||
list = gst_structure_get_value (structure, fields[j]);
|
||||
value = gst_value_list_get_value (list, 1);
|
||||
dB = g_value_get_double (value);
|
||||
GST_DEBUG ("%s[1] is %lf", fields[j], dB);
|
||||
fail_if (dB < -6.0);
|
||||
fail_if (dB > -5.9);
|
||||
}
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (inbuffer == outbuffer);
|
||||
|
||||
/* clean up */
|
||||
/* flush current messages,and future state change messages */
|
||||
gst_bus_set_flushing (bus, TRUE);
|
||||
|
||||
/* message has a ref to the element */
|
||||
ASSERT_OBJECT_REFCOUNT (level, "level", 2);
|
||||
gst_message_unref (message);
|
||||
ASSERT_OBJECT_REFCOUNT (level, "level", 1);
|
||||
|
||||
gst_element_set_bus (level, NULL);
|
||||
ASSERT_OBJECT_REFCOUNT (bus, "bus", 1);
|
||||
gst_object_unref (bus);
|
||||
gst_buffer_unref (outbuffer);
|
||||
fail_unless (gst_element_set_state (level,
|
||||
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
|
||||
ASSERT_OBJECT_REFCOUNT (level, "level", 1);
|
||||
cleanup_level (level);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
Suite *
|
||||
level_suite (void)
|
||||
|
@ -196,6 +299,7 @@ level_suite (void)
|
|||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_int16);
|
||||
tcase_add_test (tc_chain, test_int16_panned);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue