2005-08-20 18:07:10 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* unit test for volume
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
#include <gst/base/gstbasetransform.h>
|
2005-08-20 18:07:10 +00:00
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2005-12-06 19:42:02 +00:00
|
|
|
#define VOLUME_CAPS_TEMPLATE_STRING \
|
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"channels = (int) [ 1, MAX ], " \
|
|
|
|
"rate = (int) [ 1, MAX ], " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) 16, " \
|
|
|
|
"depth = (int) 16, " \
|
2005-08-20 18:07:10 +00:00
|
|
|
"signed = (bool) TRUE"
|
|
|
|
|
2005-12-06 19:42:02 +00:00
|
|
|
#define VOLUME_CAPS_STRING \
|
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"channels = (int) 1, " \
|
|
|
|
"rate = (int) 44100, " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) 16, " \
|
|
|
|
"depth = (int) 16, " \
|
2005-08-20 18:07:10 +00:00
|
|
|
"signed = (bool) TRUE"
|
|
|
|
|
2005-12-06 19:42:02 +00:00
|
|
|
#define VOLUME_WRONG_CAPS_STRING \
|
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"channels = (int) 1, " \
|
|
|
|
"rate = (int) 44100, " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"width = (int) 16, " \
|
|
|
|
"depth = (int) 16, " \
|
2005-08-20 20:40:25 +00:00
|
|
|
"signed = (bool) FALSE"
|
|
|
|
|
|
|
|
|
2005-08-20 18:07:10 +00:00
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING)
|
|
|
|
);
|
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING)
|
|
|
|
);
|
|
|
|
|
|
|
|
GstElement *
|
|
|
|
setup_volume ()
|
|
|
|
{
|
|
|
|
GstElement *volume;
|
|
|
|
|
|
|
|
GST_DEBUG ("setup_volume");
|
2005-08-21 10:43:45 +00:00
|
|
|
volume = gst_check_setup_element ("volume");
|
|
|
|
mysrcpad = gst_check_setup_src_pad (volume, &srctemplate, NULL);
|
|
|
|
mysinkpad = gst_check_setup_sink_pad (volume, &sinktemplate, NULL);
|
2005-08-30 19:54:35 +00:00
|
|
|
gst_pad_set_active (mysrcpad, TRUE);
|
|
|
|
gst_pad_set_active (mysinkpad, TRUE);
|
|
|
|
|
2005-08-20 18:07:10 +00:00
|
|
|
return volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cleanup_volume (GstElement * volume)
|
|
|
|
{
|
|
|
|
GST_DEBUG ("cleanup_volume");
|
|
|
|
|
2005-08-29 11:18:29 +00:00
|
|
|
g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (buffers);
|
|
|
|
buffers = NULL;
|
|
|
|
|
2006-12-21 08:12:26 +00:00
|
|
|
gst_pad_set_active (mysrcpad, FALSE);
|
|
|
|
gst_pad_set_active (mysinkpad, FALSE);
|
2005-08-21 10:43:45 +00:00
|
|
|
gst_check_teardown_src_pad (volume);
|
|
|
|
gst_check_teardown_sink_pad (volume);
|
|
|
|
gst_check_teardown_element (volume);
|
2005-08-20 18:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_unity)
|
|
|
|
{
|
|
|
|
GstElement *volume;
|
|
|
|
GstBuffer *inbuffer, *outbuffer;
|
2005-10-11 01:37:11 +00:00
|
|
|
GstCaps *caps;
|
2005-08-20 18:07:10 +00:00
|
|
|
gint16 in[2] = { 16384, -256 };
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
gint16 *res;
|
2005-08-20 18:07:10 +00:00
|
|
|
|
|
|
|
volume = setup_volume ();
|
|
|
|
fail_unless (gst_element_set_state (volume,
|
2005-09-02 15:43:18 +00:00
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
2005-08-20 18:07:10 +00:00
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (4);
|
|
|
|
memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
|
2005-10-11 01:37:11 +00:00
|
|
|
caps = gst_caps_from_string (VOLUME_CAPS_STRING);
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
gst_caps_unref (caps);
|
2005-08-20 18:07:10 +00:00
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
2005-08-20 20:40:25 +00:00
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
2005-08-20 18:07:10 +00:00
|
|
|
/* ... but it ends up being collected on the global buffer list */
|
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
2005-08-29 11:37:20 +00:00
|
|
|
fail_unless_equals_int (g_list_length (buffers), 1);
|
2005-08-20 18:07:10 +00:00
|
|
|
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
|
|
|
fail_unless (inbuffer == outbuffer);
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
res = (gint16 *) GST_BUFFER_DATA (outbuffer);
|
2006-10-05 15:55:21 +00:00
|
|
|
GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
|
2005-08-20 18:07:10 +00:00
|
|
|
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
cleanup_volume (volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_half)
|
|
|
|
{
|
|
|
|
GstElement *volume;
|
|
|
|
GstBuffer *inbuffer;
|
|
|
|
GstBuffer *outbuffer;
|
2005-10-11 01:37:11 +00:00
|
|
|
GstCaps *caps;
|
2005-08-20 18:07:10 +00:00
|
|
|
gint16 in[2] = { 16384, -256 };
|
|
|
|
gint16 out[2] = { 8192, -128 };
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
gint16 *res;
|
2005-08-20 18:07:10 +00:00
|
|
|
|
|
|
|
volume = setup_volume ();
|
|
|
|
g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
|
|
|
|
fail_unless (gst_element_set_state (volume,
|
2005-09-02 15:43:18 +00:00
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
2005-08-20 18:07:10 +00:00
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (4);
|
|
|
|
memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
|
|
|
|
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
|
2005-10-11 01:37:11 +00:00
|
|
|
caps = gst_caps_from_string (VOLUME_CAPS_STRING);
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
gst_caps_unref (caps);
|
2005-08-20 18:07:10 +00:00
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
|
|
/* FIXME: reffing the inbuffer should make the transformation not be
|
|
|
|
* inplace
|
|
|
|
gst_buffer_ref (inbuffer);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
2005-08-20 20:40:25 +00:00
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
2005-08-20 18:07:10 +00:00
|
|
|
/* ... but it ends up being modified inplace and
|
|
|
|
* collected on the global buffer list */
|
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
2005-08-29 11:37:20 +00:00
|
|
|
fail_unless_equals_int (g_list_length (buffers), 1);
|
2005-08-20 18:07:10 +00:00
|
|
|
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
|
|
|
fail_unless (inbuffer == outbuffer);
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
res = (gint16 *) GST_BUFFER_DATA (outbuffer);
|
2006-10-05 15:55:21 +00:00
|
|
|
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
res[1]);
|
2005-08-20 18:07:10 +00:00
|
|
|
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
cleanup_volume (volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_double)
|
|
|
|
{
|
|
|
|
GstElement *volume;
|
|
|
|
GstBuffer *inbuffer;
|
|
|
|
GstBuffer *outbuffer;
|
2005-10-11 01:37:11 +00:00
|
|
|
GstCaps *caps;
|
2005-08-20 18:07:10 +00:00
|
|
|
gint16 in[2] = { 16384, -256 };
|
|
|
|
gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
gint16 *res;
|
2005-08-20 18:07:10 +00:00
|
|
|
|
|
|
|
volume = setup_volume ();
|
|
|
|
g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
|
|
|
|
fail_unless (gst_element_set_state (volume,
|
2005-09-02 15:43:18 +00:00
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
2005-08-20 18:07:10 +00:00
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (4);
|
|
|
|
memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
|
|
|
|
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
|
2005-10-11 01:37:11 +00:00
|
|
|
caps = gst_caps_from_string (VOLUME_CAPS_STRING);
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
gst_caps_unref (caps);
|
2005-08-20 18:07:10 +00:00
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
|
|
/* FIXME: reffing the inbuffer should make the transformation not be
|
|
|
|
* inplace
|
|
|
|
gst_buffer_ref (inbuffer);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
2005-08-20 20:40:25 +00:00
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
2005-08-20 18:07:10 +00:00
|
|
|
/* ... but it ends up being modified inplace and
|
|
|
|
* collected on the global buffer list */
|
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
2005-08-29 11:37:20 +00:00
|
|
|
fail_unless_equals_int (g_list_length (buffers), 1);
|
2005-08-20 18:07:10 +00:00
|
|
|
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
|
|
|
fail_unless (inbuffer == outbuffer);
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
res = (gint16 *) GST_BUFFER_DATA (outbuffer);
|
2006-10-05 15:55:21 +00:00
|
|
|
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
res[1]);
|
2005-08-20 18:07:10 +00:00
|
|
|
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
cleanup_volume (volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
|
|
|
|
GST_START_TEST (test_mute)
|
|
|
|
{
|
|
|
|
GstElement *volume;
|
|
|
|
GstBuffer *inbuffer;
|
|
|
|
GstBuffer *outbuffer;
|
|
|
|
GstCaps *caps;
|
|
|
|
gint16 in[2] = { 16384, -256 };
|
|
|
|
gint16 out[2] = { 0, 0 };
|
|
|
|
gint16 *res;
|
|
|
|
|
|
|
|
volume = setup_volume ();
|
|
|
|
g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
|
|
|
|
fail_unless (gst_element_set_state (volume,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (4);
|
|
|
|
memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
|
|
|
|
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
|
|
|
|
caps = gst_caps_from_string (VOLUME_CAPS_STRING);
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
|
|
/* FIXME: reffing the inbuffer should make the transformation not be
|
|
|
|
* inplace
|
|
|
|
gst_buffer_ref (inbuffer);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* pushing gives away my reference ... */
|
|
|
|
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
|
|
|
|
/* ... but it ends up being modified inplace and
|
|
|
|
* 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);
|
|
|
|
res = (gint16 *) GST_BUFFER_DATA (outbuffer);
|
2006-10-05 15:55:21 +00:00
|
|
|
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
res[1]);
|
|
|
|
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
cleanup_volume (volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
|
2005-08-20 20:40:25 +00:00
|
|
|
GST_START_TEST (test_wrong_caps)
|
|
|
|
{
|
|
|
|
GstElement *volume;
|
2006-09-16 22:30:50 +00:00
|
|
|
GstBuffer *inbuffer;
|
2005-08-20 20:40:25 +00:00
|
|
|
gint16 in[2] = { 16384, -256 };
|
|
|
|
GstBus *bus;
|
|
|
|
GstMessage *message;
|
2005-10-11 01:37:11 +00:00
|
|
|
GstCaps *caps;
|
2005-08-20 20:40:25 +00:00
|
|
|
|
|
|
|
volume = setup_volume ();
|
|
|
|
bus = gst_bus_new ();
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (volume,
|
2005-09-02 15:43:18 +00:00
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
2005-08-20 20:40:25 +00:00
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (4);
|
|
|
|
memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
|
2005-10-11 01:37:11 +00:00
|
|
|
caps = gst_caps_from_string (VOLUME_WRONG_CAPS_STRING);
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
gst_caps_unref (caps);
|
2005-08-20 20:40:25 +00:00
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
|
|
gst_buffer_ref (inbuffer);
|
|
|
|
|
|
|
|
/* set a bus here so we avoid getting state change messages */
|
|
|
|
gst_element_set_bus (volume, bus);
|
|
|
|
|
|
|
|
/* pushing gives an error because it can't negotiate with wrong caps */
|
|
|
|
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer),
|
|
|
|
GST_FLOW_NOT_NEGOTIATED);
|
|
|
|
/* ... and the buffer would have been lost if we didn't ref it ourselves */
|
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
|
|
gst_buffer_unref (inbuffer);
|
|
|
|
fail_unless_equals_int (g_list_length (buffers), 0);
|
|
|
|
|
|
|
|
/* volume_set_caps should not have been called since basetransform caught
|
|
|
|
* the negotiation problem */
|
|
|
|
fail_if ((message = gst_bus_pop (bus)) != NULL);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
gst_element_set_bus (volume, NULL);
|
|
|
|
gst_object_unref (GST_OBJECT (bus));
|
|
|
|
cleanup_volume (volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
GST_START_TEST (test_passthrough)
|
|
|
|
{
|
|
|
|
GstElement *volume;
|
|
|
|
GstBuffer *inbuffer, *outbuffer;
|
|
|
|
GstCaps *caps;
|
|
|
|
gint16 in[2] = { 16384, -256 };
|
|
|
|
gint16 *res;
|
|
|
|
|
|
|
|
volume = setup_volume ();
|
|
|
|
g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
|
|
|
|
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (volume), TRUE);
|
|
|
|
fail_unless (gst_element_set_state (volume,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
|
|
|
|
"could not set to playing");
|
|
|
|
|
|
|
|
inbuffer = gst_buffer_new_and_alloc (4);
|
|
|
|
memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
|
|
|
|
caps = gst_caps_from_string (VOLUME_CAPS_STRING);
|
|
|
|
gst_buffer_set_caps (inbuffer, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
res = (gint16 *) GST_BUFFER_DATA (outbuffer);
|
2006-10-05 15:55:21 +00:00
|
|
|
GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
cleanup_volume (volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2005-08-20 18:07:10 +00:00
|
|
|
Suite *
|
|
|
|
volume_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("volume");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
tcase_add_test (tc_chain, test_unity);
|
|
|
|
tcase_add_test (tc_chain, test_half);
|
|
|
|
tcase_add_test (tc_chain, test_double);
|
gst/adder/gstadder.c: Make it easier to copy&paste
Original commit message from CVS:
* gst/adder/gstadder.c: (gst_adder_get_type):
Make it easier to copy&paste
* gst/volume/Makefile.am:
* gst/volume/gstvolume.c: (volume_update_real_volume),
(gst_volume_set_volume), (gst_volume_set_mute),
(gst_volume_class_init), (volume_process_int16), (volume_set_caps),
(volume_transform_ip), (volume_update_mute),
(volume_update_volume):
* gst/volume/gstvolume.h:
Add own debug category, move duplicate code to helper function, fix
property texts, add more comments and prepare ffor liboil-goodness
* tests/check/Makefile.am:
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
add test for mute and passtrough case, be a bit more verbose to track
failure
* tests/check/generic/states.c: (GST_START_TEST):
catch elements that fail to instantiate
2006-05-28 19:42:27 +00:00
|
|
|
tcase_add_test (tc_chain, test_mute);
|
2005-08-20 20:40:25 +00:00
|
|
|
tcase_add_test (tc_chain, test_wrong_caps);
|
gst/volume/gstvolume.*: rewrite the passthrough check, split _int16 and _int16_clamp, fix another property desc., rem...
Original commit message from CVS:
* gst/volume/gstvolume.c: (volume_choose_func),
(volume_update_real_volume), (gst_volume_class_init),
(gst_volume_init), (volume_process_float), (volume_process_int16),
(volume_process_int16_clamp), (volume_set_caps),
(volume_transform_ip), (plugin_init):
* gst/volume/gstvolume.h:
rewrite the passthrough check, split _int16 and _int16_clamp, fix
another property desc., remove unused param from process function
* tests/check/elements/volume.c: (volume_suite):
reactivate the passthrough test
2006-06-01 20:39:30 +00:00
|
|
|
tcase_add_test (tc_chain, test_passthrough);
|
2005-08-20 18:07:10 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int nf;
|
|
|
|
|
|
|
|
Suite *s = volume_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;
|
|
|
|
}
|