5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include <gst/base/gstbasetransform.h>
26 #include <gst/check/gstcheck.h>
27 #include <gst/controller/gstcontroller.h>
28 #include <gst/interfaces/streamvolume.h>
30 /* For ease of programming we use globals to keep refs for our floating
31 * src and sink pads we create; otherwise we always have to do get_pad,
32 * get_peer, and then remove references in every test function */
33 static GstPad *mysrcpad, *mysinkpad;
36 #define VOLUME_CAPS_TEMPLATE_STRING \
38 "channels = (int) [ 1, MAX ], " \
39 "rate = (int) [ 1, MAX ], " \
40 "endianness = (int) BYTE_ORDER, " \
41 "width = (int) { 8, 16, 24, 32 }, " \
42 "depth = (int) { 8, 16, 24, 32 }, " \
43 "signed = (bool) TRUE; " \
44 "audio/x-raw-float, " \
45 "channels = (int) [ 1, MAX ], " \
46 "rate = (int) [ 1, MAX ], " \
47 "endianness = (int) BYTE_ORDER, " \
48 "width = (int) { 32, 64 }" \
50 #define VOLUME_CAPS_STRING_S8 \
52 "channels = (int) 1, " \
53 "rate = (int) 44100, " \
54 "endianness = (int) BYTE_ORDER, " \
57 "signed = (bool) TRUE"
59 #define VOLUME_CAPS_STRING_S16 \
61 "channels = (int) 1, " \
62 "rate = (int) 44100, " \
63 "endianness = (int) BYTE_ORDER, " \
64 "width = (int) 16, " \
65 "depth = (int) 16, " \
66 "signed = (bool) TRUE"
68 #define VOLUME_CAPS_STRING_S24 \
70 "channels = (int) 1, " \
71 "rate = (int) 44100, " \
72 "endianness = (int) BYTE_ORDER, " \
73 "width = (int) 24, " \
74 "depth = (int) 24, " \
75 "signed = (bool) TRUE"
77 #define VOLUME_CAPS_STRING_S32 \
79 "channels = (int) 1, " \
80 "rate = (int) 44100, " \
81 "endianness = (int) BYTE_ORDER, " \
82 "width = (int) 32, " \
83 "depth = (int) 32, " \
84 "signed = (bool) TRUE"
86 #define VOLUME_CAPS_STRING_F32 \
87 "audio/x-raw-float, " \
88 "channels = (int) 1, " \
89 "rate = (int) 44100, " \
90 "endianness = (int) BYTE_ORDER, " \
93 #define VOLUME_CAPS_STRING_F64 \
94 "audio/x-raw-float, " \
95 "channels = (int) 1, " \
96 "rate = (int) 44100, " \
97 "endianness = (int) BYTE_ORDER, " \
100 #define VOLUME_WRONG_CAPS_STRING \
101 "audio/x-raw-int, " \
102 "channels = (int) 1, " \
103 "rate = (int) 44100, " \
104 "endianness = (int) BYTE_ORDER, " \
105 "width = (int) 16, " \
106 "depth = (int) 16, " \
107 "signed = (bool) FALSE"
110 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
113 GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING)
115 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
118 GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING)
126 GST_DEBUG ("setup_volume");
127 volume = gst_check_setup_element ("volume");
128 mysrcpad = gst_check_setup_src_pad (volume, &srctemplate, NULL);
129 mysinkpad = gst_check_setup_sink_pad (volume, &sinktemplate, NULL);
130 gst_pad_set_active (mysrcpad, TRUE);
131 gst_pad_set_active (mysinkpad, TRUE);
137 cleanup_volume (GstElement * volume)
139 GST_DEBUG ("cleanup_volume");
141 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
142 g_list_free (buffers);
145 gst_pad_set_active (mysrcpad, FALSE);
146 gst_pad_set_active (mysinkpad, FALSE);
147 gst_check_teardown_src_pad (volume);
148 gst_check_teardown_sink_pad (volume);
149 gst_check_teardown_element (volume);
152 GST_START_TEST (test_get_set)
154 GstElement *volume = gst_element_factory_make ("volume", NULL);
157 fail_unless (volume != NULL);
158 g_object_get (G_OBJECT (volume), "volume", &val, NULL);
159 fail_unless (val == 1.0);
160 fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume),
161 GST_STREAM_VOLUME_FORMAT_LINEAR));
163 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
164 g_object_get (G_OBJECT (volume), "volume", &val, NULL);
165 fail_unless (val == 0.5);
166 fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume),
167 GST_STREAM_VOLUME_FORMAT_LINEAR));
169 gst_stream_volume_set_volume (GST_STREAM_VOLUME (volume),
170 GST_STREAM_VOLUME_FORMAT_LINEAR, 1.0);
171 g_object_get (G_OBJECT (volume), "volume", &val, NULL);
172 fail_unless (val == 1.0);
173 fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume),
174 GST_STREAM_VOLUME_FORMAT_LINEAR));
176 gst_object_unref (volume);
181 GST_START_TEST (test_unity_s8)
184 GstBuffer *inbuffer, *outbuffer;
186 gint8 in[2] = { 64, -16 };
189 volume = setup_volume ();
190 fail_unless (gst_element_set_state (volume,
191 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
192 "could not set to playing");
194 inbuffer = gst_buffer_new_and_alloc (2);
195 memcpy (GST_BUFFER_DATA (inbuffer), in, 2);
196 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
197 gst_buffer_set_caps (inbuffer, caps);
198 gst_caps_unref (caps);
199 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
201 /* pushing gives away my reference ... */
202 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
203 /* ... but it ends up being collected on the global buffer list */
204 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
205 fail_unless_equals_int (g_list_length (buffers), 1);
206 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
207 fail_unless (inbuffer == outbuffer);
208 res = (gint8 *) GST_BUFFER_DATA (outbuffer);
209 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
210 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0);
213 cleanup_volume (volume);
218 GST_START_TEST (test_half_s8)
222 GstBuffer *outbuffer;
224 gint8 in[2] = { 64, -16 };
225 gint8 out[2] = { 32, -8 };
228 volume = setup_volume ();
229 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
230 fail_unless (gst_element_set_state (volume,
231 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
232 "could not set to playing");
234 inbuffer = gst_buffer_new_and_alloc (2);
235 memcpy (GST_BUFFER_DATA (inbuffer), in, 2);
236 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0);
237 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
238 gst_buffer_set_caps (inbuffer, caps);
239 gst_caps_unref (caps);
240 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
241 /* FIXME: reffing the inbuffer should make the transformation not be
243 gst_buffer_ref (inbuffer);
246 /* pushing gives away my reference ... */
247 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
248 /* ... but it ends up being modified inplace and
249 * collected on the global buffer list */
250 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
251 fail_unless_equals_int (g_list_length (buffers), 1);
252 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
253 fail_unless (inbuffer == outbuffer);
254 res = (gint8 *) GST_BUFFER_DATA (outbuffer);
255 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
257 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0);
260 cleanup_volume (volume);
265 GST_START_TEST (test_double_s8)
269 GstBuffer *outbuffer;
271 gint8 in[2] = { 64, -16 };
272 gint8 out[2] = { 127, -32 }; /* notice the clamped sample */
275 volume = setup_volume ();
276 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
277 fail_unless (gst_element_set_state (volume,
278 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
279 "could not set to playing");
281 inbuffer = gst_buffer_new_and_alloc (2);
282 memcpy (GST_BUFFER_DATA (inbuffer), in, 2);
283 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0);
284 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
285 gst_buffer_set_caps (inbuffer, caps);
286 gst_caps_unref (caps);
287 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
288 /* FIXME: reffing the inbuffer should make the transformation not be
290 gst_buffer_ref (inbuffer);
293 /* pushing gives away my reference ... */
294 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
295 /* ... but it ends up being modified inplace and
296 * collected on the global buffer list */
297 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
298 fail_unless_equals_int (g_list_length (buffers), 1);
299 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
300 fail_unless (inbuffer == outbuffer);
301 res = (gint8 *) GST_BUFFER_DATA (outbuffer);
302 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
304 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0);
307 cleanup_volume (volume);
312 GST_START_TEST (test_mute_s8)
316 GstBuffer *outbuffer;
318 gint8 in[2] = { 64, -16 };
319 gint8 out[2] = { 0, 0 };
322 volume = setup_volume ();
323 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
324 fail_unless (gst_element_set_state (volume,
325 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
326 "could not set to playing");
328 inbuffer = gst_buffer_new_and_alloc (2);
329 memcpy (GST_BUFFER_DATA (inbuffer), in, 2);
330 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0);
331 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
332 gst_buffer_set_caps (inbuffer, caps);
333 gst_caps_unref (caps);
334 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
335 /* FIXME: reffing the inbuffer should make the transformation not be
337 gst_buffer_ref (inbuffer);
340 /* pushing gives away my reference ... */
341 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
342 /* ... but it ends up being modified inplace and
343 * collected on the global buffer list */
344 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
345 fail_unless_equals_int (g_list_length (buffers), 1);
346 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
347 fail_unless (inbuffer == outbuffer);
348 res = (gint8 *) GST_BUFFER_DATA (outbuffer);
349 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
351 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0);
354 cleanup_volume (volume);
359 GST_START_TEST (test_unity_s16)
362 GstBuffer *inbuffer, *outbuffer;
364 gint16 in[2] = { 16384, -256 };
367 volume = setup_volume ();
368 fail_unless (gst_element_set_state (volume,
369 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
370 "could not set to playing");
372 inbuffer = gst_buffer_new_and_alloc (4);
373 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
374 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
375 gst_buffer_set_caps (inbuffer, caps);
376 gst_caps_unref (caps);
377 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
379 /* pushing gives away my reference ... */
380 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
381 /* ... but it ends up being collected on the global buffer list */
382 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
383 fail_unless_equals_int (g_list_length (buffers), 1);
384 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
385 fail_unless (inbuffer == outbuffer);
386 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
387 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
388 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
391 cleanup_volume (volume);
396 GST_START_TEST (test_half_s16)
400 GstBuffer *outbuffer;
402 gint16 in[2] = { 16384, -256 };
403 gint16 out[2] = { 8192, -128 };
406 volume = setup_volume ();
407 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
408 fail_unless (gst_element_set_state (volume,
409 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
410 "could not set to playing");
412 inbuffer = gst_buffer_new_and_alloc (4);
413 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
414 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
415 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
416 gst_buffer_set_caps (inbuffer, caps);
417 gst_caps_unref (caps);
418 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
419 /* FIXME: reffing the inbuffer should make the transformation not be
421 gst_buffer_ref (inbuffer);
424 /* pushing gives away my reference ... */
425 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
426 /* ... but it ends up being modified inplace and
427 * collected on the global buffer list */
428 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
429 fail_unless_equals_int (g_list_length (buffers), 1);
430 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
431 fail_unless (inbuffer == outbuffer);
432 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
433 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
435 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0);
438 cleanup_volume (volume);
443 GST_START_TEST (test_double_s16)
447 GstBuffer *outbuffer;
449 gint16 in[2] = { 16384, -256 };
450 gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */
453 volume = setup_volume ();
454 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
455 fail_unless (gst_element_set_state (volume,
456 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
457 "could not set to playing");
459 inbuffer = gst_buffer_new_and_alloc (4);
460 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
461 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
462 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
463 gst_buffer_set_caps (inbuffer, caps);
464 gst_caps_unref (caps);
465 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
466 /* FIXME: reffing the inbuffer should make the transformation not be
468 gst_buffer_ref (inbuffer);
471 /* pushing gives away my reference ... */
472 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
473 /* ... but it ends up being modified inplace and
474 * collected on the global buffer list */
475 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
476 fail_unless_equals_int (g_list_length (buffers), 1);
477 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
478 fail_unless (inbuffer == outbuffer);
479 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
480 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
482 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0);
485 cleanup_volume (volume);
491 GST_START_TEST (test_mute_s16)
495 GstBuffer *outbuffer;
497 gint16 in[2] = { 16384, -256 };
498 gint16 out[2] = { 0, 0 };
501 volume = setup_volume ();
502 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
503 fail_unless (gst_element_set_state (volume,
504 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
505 "could not set to playing");
507 inbuffer = gst_buffer_new_and_alloc (4);
508 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
509 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
510 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
511 gst_buffer_set_caps (inbuffer, caps);
512 gst_caps_unref (caps);
513 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
514 /* FIXME: reffing the inbuffer should make the transformation not be
516 gst_buffer_ref (inbuffer);
519 /* pushing gives away my reference ... */
520 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
521 /* ... but it ends up being modified inplace and
522 * collected on the global buffer list */
523 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
524 fail_unless_equals_int (g_list_length (buffers), 1);
525 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
526 fail_unless (inbuffer == outbuffer);
527 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
528 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
530 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0);
533 cleanup_volume (volume);
538 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
539 #define get_unaligned_i24(_x) ( (((guint8*)_x)[0]) | ((((guint8*)_x)[1]) << 8) | ((((gint8*)_x)[2]) << 16) )
540 #define write_unaligned_u24(_x,samp) do { (((guint8*)_x)[0]) = samp & 0xFF; (((guint8*)_x)[1]) = (samp >> 8) & 0xFF; (((guint8*)_x)[2]) = (samp >> 16) & 0xFF; } while (0)
541 #else /* BIG ENDIAN */
542 #define get_unaligned_i24(_x) ( (((guint8*)_x)[2]) | ((((guint8*)_x)[1]) << 8) | ((((gint8*)_x)[0]) << 16) )
543 #define write_unaligned_u24(_x,samp) do { (((guint8*)_x)[0]) = (samp >> 16) & 0xFF; (((guint8*)_x)[1]) = (samp >> 8) & 0xFF; (((guint8*)_x)[2]) = samp & 0xFF; } while (0)
546 GST_START_TEST (test_unity_s24)
549 GstBuffer *inbuffer, *outbuffer;
551 gint32 in_32[2] = { 4194304, -4096 };
557 write_unaligned_u24 (in, in_32[0]);
558 write_unaligned_u24 (in + 3, in_32[1]);
560 volume = setup_volume ();
561 fail_unless (gst_element_set_state (volume,
562 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
563 "could not set to playing");
565 inbuffer = gst_buffer_new_and_alloc (6);
566 memcpy (GST_BUFFER_DATA (inbuffer), in, 6);
567 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
568 gst_buffer_set_caps (inbuffer, caps);
569 gst_caps_unref (caps);
570 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
572 /* pushing gives away my reference ... */
573 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
574 /* ... but it ends up being collected on the global buffer list */
575 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
576 fail_unless_equals_int (g_list_length (buffers), 1);
577 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
578 fail_unless (inbuffer == outbuffer);
579 res = GST_BUFFER_DATA (outbuffer);
581 res_32[0] = get_unaligned_i24 (res);
582 res_32[1] = get_unaligned_i24 ((res + 3));
584 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in_32[0], in_32[1], res_32[0],
586 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0);
589 cleanup_volume (volume);
594 GST_START_TEST (test_half_s24)
598 GstBuffer *outbuffer;
600 gint32 in_32[2] = { 4194304, -4096 };
604 gint32 out_32[2] = { 2097152, -2048 };
606 write_unaligned_u24 (in, in_32[0]);
607 write_unaligned_u24 (in + 3, in_32[1]);
609 volume = setup_volume ();
610 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
611 fail_unless (gst_element_set_state (volume,
612 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
613 "could not set to playing");
615 inbuffer = gst_buffer_new_and_alloc (6);
616 memcpy (GST_BUFFER_DATA (inbuffer), in, 6);
617 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0);
618 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
619 gst_buffer_set_caps (inbuffer, caps);
620 gst_caps_unref (caps);
621 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
622 /* FIXME: reffing the inbuffer should make the transformation not be
624 gst_buffer_ref (inbuffer);
627 /* pushing gives away my reference ... */
628 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
629 /* ... but it ends up being modified inplace and
630 * collected on the global buffer list */
631 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
632 fail_unless_equals_int (g_list_length (buffers), 1);
633 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
634 fail_unless (inbuffer == outbuffer);
635 res = GST_BUFFER_DATA (outbuffer);
637 res_32[0] = get_unaligned_i24 (res);
638 res_32[1] = get_unaligned_i24 ((res + 3));
640 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
641 res_32[0], res_32[1]);
642 fail_unless (memcmp (res_32, out_32, 8) == 0);
645 cleanup_volume (volume);
650 GST_START_TEST (test_double_s24)
654 GstBuffer *outbuffer;
656 gint32 in_32[2] = { 4194304, -4096 };
660 gint32 out_32[2] = { 8388607, -8192 }; /* notice the clamped sample */
662 write_unaligned_u24 (in, in_32[0]);
663 write_unaligned_u24 (in + 3, in_32[1]);
665 volume = setup_volume ();
666 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
667 fail_unless (gst_element_set_state (volume,
668 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
669 "could not set to playing");
671 inbuffer = gst_buffer_new_and_alloc (6);
672 memcpy (GST_BUFFER_DATA (inbuffer), in, 6);
673 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0);
674 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
675 gst_buffer_set_caps (inbuffer, caps);
676 gst_caps_unref (caps);
677 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
678 /* FIXME: reffing the inbuffer should make the transformation not be
680 gst_buffer_ref (inbuffer);
683 /* pushing gives away my reference ... */
684 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
685 /* ... but it ends up being modified inplace and
686 * collected on the global buffer list */
687 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
688 fail_unless_equals_int (g_list_length (buffers), 1);
689 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
690 fail_unless (inbuffer == outbuffer);
691 res = GST_BUFFER_DATA (outbuffer);
693 res_32[0] = get_unaligned_i24 (res);
694 res_32[1] = get_unaligned_i24 ((res + 3));
696 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
697 res_32[0], res_32[1]);
698 fail_unless (memcmp (res_32, out_32, 8) == 0);
701 cleanup_volume (volume);
707 GST_START_TEST (test_mute_s24)
711 GstBuffer *outbuffer;
713 gint32 in_32[2] = { 4194304, -4096 };
717 gint32 out_32[2] = { 0, 0 }; /* notice the clamped sample */
719 write_unaligned_u24 (in, in_32[0]);
720 write_unaligned_u24 (in + 3, in_32[1]);
722 volume = setup_volume ();
723 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
724 fail_unless (gst_element_set_state (volume,
725 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
726 "could not set to playing");
728 inbuffer = gst_buffer_new_and_alloc (6);
729 memcpy (GST_BUFFER_DATA (inbuffer), in, 6);
730 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0);
731 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
732 gst_buffer_set_caps (inbuffer, caps);
733 gst_caps_unref (caps);
734 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
735 /* FIXME: reffing the inbuffer should make the transformation not be
737 gst_buffer_ref (inbuffer);
740 /* pushing gives away my reference ... */
741 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
742 /* ... but it ends up being modified inplace and
743 * collected on the global buffer list */
744 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
745 fail_unless_equals_int (g_list_length (buffers), 1);
746 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
747 fail_unless (inbuffer == outbuffer);
749 res = GST_BUFFER_DATA (outbuffer);
751 res_32[0] = get_unaligned_i24 (res);
752 res_32[1] = get_unaligned_i24 ((res + 3));
754 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
755 res_32[0], res_32[1]);
756 fail_unless (memcmp (res_32, out_32, 8) == 0);
759 cleanup_volume (volume);
764 GST_START_TEST (test_unity_s32)
767 GstBuffer *inbuffer, *outbuffer;
769 gint32 in[2] = { 1073741824, -65536 };
772 volume = setup_volume ();
773 fail_unless (gst_element_set_state (volume,
774 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
775 "could not set to playing");
777 inbuffer = gst_buffer_new_and_alloc (8);
778 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
779 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
780 gst_buffer_set_caps (inbuffer, caps);
781 gst_caps_unref (caps);
782 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
784 /* pushing gives away my reference ... */
785 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
786 /* ... but it ends up being collected on the global buffer list */
787 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
788 fail_unless_equals_int (g_list_length (buffers), 1);
789 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
790 fail_unless (inbuffer == outbuffer);
791 res = (gint32 *) GST_BUFFER_DATA (outbuffer);
792 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
793 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
796 cleanup_volume (volume);
801 GST_START_TEST (test_half_s32)
805 GstBuffer *outbuffer;
807 gint32 in[2] = { 1073741824, -65536 };
808 gint32 out[2] = { 536870912, -32768 };
811 volume = setup_volume ();
812 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
813 fail_unless (gst_element_set_state (volume,
814 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
815 "could not set to playing");
817 inbuffer = gst_buffer_new_and_alloc (8);
818 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
819 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
820 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
821 gst_buffer_set_caps (inbuffer, caps);
822 gst_caps_unref (caps);
823 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
824 /* FIXME: reffing the inbuffer should make the transformation not be
826 gst_buffer_ref (inbuffer);
829 /* pushing gives away my reference ... */
830 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
831 /* ... but it ends up being modified inplace and
832 * collected on the global buffer list */
833 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
834 fail_unless_equals_int (g_list_length (buffers), 1);
835 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
836 fail_unless (inbuffer == outbuffer);
837 res = (gint32 *) GST_BUFFER_DATA (outbuffer);
838 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
840 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
843 cleanup_volume (volume);
848 GST_START_TEST (test_double_s32)
852 GstBuffer *outbuffer;
854 gint32 in[2] = { 1073741824, -65536 };
855 gint32 out[2] = { 2147483647, -131072 }; /* notice the clamped sample */
858 volume = setup_volume ();
859 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
860 fail_unless (gst_element_set_state (volume,
861 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
862 "could not set to playing");
864 inbuffer = gst_buffer_new_and_alloc (8);
865 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
866 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
867 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
868 gst_buffer_set_caps (inbuffer, caps);
869 gst_caps_unref (caps);
870 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
871 /* FIXME: reffing the inbuffer should make the transformation not be
873 gst_buffer_ref (inbuffer);
876 /* pushing gives away my reference ... */
877 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
878 /* ... but it ends up being modified inplace and
879 * collected on the global buffer list */
880 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
881 fail_unless_equals_int (g_list_length (buffers), 1);
882 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
883 fail_unless (inbuffer == outbuffer);
884 res = (gint32 *) GST_BUFFER_DATA (outbuffer);
885 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
887 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
890 cleanup_volume (volume);
896 GST_START_TEST (test_mute_s32)
900 GstBuffer *outbuffer;
902 gint32 in[2] = { 1073741824, -65536 };
903 gint32 out[2] = { 0, 0 };
906 volume = setup_volume ();
907 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
908 fail_unless (gst_element_set_state (volume,
909 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
910 "could not set to playing");
912 inbuffer = gst_buffer_new_and_alloc (8);
913 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
914 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
915 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
916 gst_buffer_set_caps (inbuffer, caps);
917 gst_caps_unref (caps);
918 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
919 /* FIXME: reffing the inbuffer should make the transformation not be
921 gst_buffer_ref (inbuffer);
924 /* pushing gives away my reference ... */
925 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
926 /* ... but it ends up being modified inplace and
927 * collected on the global buffer list */
928 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
929 fail_unless_equals_int (g_list_length (buffers), 1);
930 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
931 fail_unless (inbuffer == outbuffer);
932 res = (gint32 *) GST_BUFFER_DATA (outbuffer);
933 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
935 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0);
938 cleanup_volume (volume);
943 GST_START_TEST (test_unity_f32)
946 GstBuffer *inbuffer, *outbuffer;
948 gfloat in[2] = { 0.75, -0.25 };
951 volume = setup_volume ();
952 fail_unless (gst_element_set_state (volume,
953 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
954 "could not set to playing");
956 inbuffer = gst_buffer_new_and_alloc (8);
957 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
958 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
959 gst_buffer_set_caps (inbuffer, caps);
960 gst_caps_unref (caps);
961 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
963 /* pushing gives away my reference ... */
964 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
965 /* ... but it ends up being collected on the global buffer list */
966 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
967 fail_unless_equals_int (g_list_length (buffers), 1);
968 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
969 fail_unless (inbuffer == outbuffer);
970 res = (gfloat *) GST_BUFFER_DATA (outbuffer);
971 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0],
973 fail_unless_equals_float (res[0], in[0]);
974 fail_unless_equals_float (res[1], in[1]);
977 cleanup_volume (volume);
982 GST_START_TEST (test_half_f32)
986 GstBuffer *outbuffer;
988 gfloat in[2] = { 0.75, -0.25 };
989 gfloat out[2] = { 0.375, -0.125 };
992 volume = setup_volume ();
993 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
994 fail_unless (gst_element_set_state (volume,
995 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
996 "could not set to playing");
998 inbuffer = gst_buffer_new_and_alloc (8);
999 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
1000 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
1001 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
1002 gst_buffer_set_caps (inbuffer, caps);
1003 gst_caps_unref (caps);
1004 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1005 /* FIXME: reffing the inbuffer should make the transformation not be
1007 gst_buffer_ref (inbuffer);
1010 /* pushing gives away my reference ... */
1011 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1012 /* ... but it ends up being modified inplace and
1013 * collected on the global buffer list */
1014 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1015 fail_unless_equals_int (g_list_length (buffers), 1);
1016 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1017 fail_unless (inbuffer == outbuffer);
1018 res = (gfloat *) GST_BUFFER_DATA (outbuffer);
1019 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1021 fail_unless_equals_float (res[0], out[0]);
1022 fail_unless_equals_float (res[1], out[1]);
1025 cleanup_volume (volume);
1030 GST_START_TEST (test_double_f32)
1033 GstBuffer *inbuffer;
1034 GstBuffer *outbuffer;
1036 gfloat in[2] = { 0.75, -0.25 };
1037 gfloat out[2] = { 1.5, -0.5 }; /* nothing is clamped */
1040 volume = setup_volume ();
1041 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
1042 fail_unless (gst_element_set_state (volume,
1043 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1044 "could not set to playing");
1046 inbuffer = gst_buffer_new_and_alloc (8);
1047 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
1048 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
1049 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
1050 gst_buffer_set_caps (inbuffer, caps);
1051 gst_caps_unref (caps);
1052 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1053 /* FIXME: reffing the inbuffer should make the transformation not be
1055 gst_buffer_ref (inbuffer);
1058 /* pushing gives away my reference ... */
1059 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1060 /* ... but it ends up being modified inplace and
1061 * collected on the global buffer list */
1062 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1063 fail_unless_equals_int (g_list_length (buffers), 1);
1064 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1065 fail_unless (inbuffer == outbuffer);
1066 res = (gfloat *) GST_BUFFER_DATA (outbuffer);
1067 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1069 fail_unless_equals_float (res[0], out[0]);
1070 fail_unless_equals_float (res[1], out[1]);
1073 cleanup_volume (volume);
1079 GST_START_TEST (test_mute_f32)
1082 GstBuffer *inbuffer;
1083 GstBuffer *outbuffer;
1085 gfloat in[2] = { 0.75, -0.25 };
1086 gfloat out[2] = { 0, 0 };
1089 volume = setup_volume ();
1090 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
1091 fail_unless (gst_element_set_state (volume,
1092 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1093 "could not set to playing");
1095 inbuffer = gst_buffer_new_and_alloc (8);
1096 memcpy (GST_BUFFER_DATA (inbuffer), in, 8);
1097 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
1098 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
1099 gst_buffer_set_caps (inbuffer, caps);
1100 gst_caps_unref (caps);
1101 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1102 /* FIXME: reffing the inbuffer should make the transformation not be
1104 gst_buffer_ref (inbuffer);
1107 /* pushing gives away my reference ... */
1108 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1109 /* ... but it ends up being modified inplace and
1110 * collected on the global buffer list */
1111 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1112 fail_unless_equals_int (g_list_length (buffers), 1);
1113 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1114 fail_unless (inbuffer == outbuffer);
1115 res = (gfloat *) GST_BUFFER_DATA (outbuffer);
1116 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1118 fail_unless_equals_float (res[0], out[0]);
1119 fail_unless_equals_float (res[1], out[1]);
1122 cleanup_volume (volume);
1127 GST_START_TEST (test_unity_f64)
1130 GstBuffer *inbuffer, *outbuffer;
1132 gdouble in[2] = { 0.75, -0.25 };
1135 volume = setup_volume ();
1136 fail_unless (gst_element_set_state (volume,
1137 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1138 "could not set to playing");
1140 inbuffer = gst_buffer_new_and_alloc (16);
1141 memcpy (GST_BUFFER_DATA (inbuffer), in, 16);
1142 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1143 gst_buffer_set_caps (inbuffer, caps);
1144 gst_caps_unref (caps);
1145 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1147 /* pushing gives away my reference ... */
1148 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1149 /* ... but it ends up being collected on the global buffer list */
1150 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1151 fail_unless_equals_int (g_list_length (buffers), 1);
1152 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1153 fail_unless (inbuffer == outbuffer);
1154 res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1155 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0],
1157 fail_unless_equals_float (res[0], in[0]);
1158 fail_unless_equals_float (res[1], in[1]);
1161 cleanup_volume (volume);
1166 GST_START_TEST (test_half_f64)
1169 GstBuffer *inbuffer;
1170 GstBuffer *outbuffer;
1172 gdouble in[2] = { 0.75, -0.25 };
1173 gdouble out[2] = { 0.375, -0.125 };
1176 volume = setup_volume ();
1177 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
1178 fail_unless (gst_element_set_state (volume,
1179 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1180 "could not set to playing");
1182 inbuffer = gst_buffer_new_and_alloc (16);
1183 memcpy (GST_BUFFER_DATA (inbuffer), in, 16);
1184 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0);
1185 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1186 gst_buffer_set_caps (inbuffer, caps);
1187 gst_caps_unref (caps);
1188 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1189 /* FIXME: reffing the inbuffer should make the transformation not be
1191 gst_buffer_ref (inbuffer);
1194 /* pushing gives away my reference ... */
1195 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1196 /* ... but it ends up being modified inplace and
1197 * collected on the global buffer list */
1198 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1199 fail_unless_equals_int (g_list_length (buffers), 1);
1200 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1201 fail_unless (inbuffer == outbuffer);
1202 res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1203 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1205 fail_unless_equals_float (res[0], out[0]);
1206 fail_unless_equals_float (res[1], out[1]);
1209 cleanup_volume (volume);
1214 GST_START_TEST (test_double_f64)
1217 GstBuffer *inbuffer;
1218 GstBuffer *outbuffer;
1220 gdouble in[2] = { 0.75, -0.25 };
1221 gdouble out[2] = { 1.5, -0.5 }; /* nothing is clamped */
1224 volume = setup_volume ();
1225 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
1226 fail_unless (gst_element_set_state (volume,
1227 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1228 "could not set to playing");
1230 inbuffer = gst_buffer_new_and_alloc (16);
1231 memcpy (GST_BUFFER_DATA (inbuffer), in, 16);
1232 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0);
1233 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1234 gst_buffer_set_caps (inbuffer, caps);
1235 gst_caps_unref (caps);
1236 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1237 /* FIXME: reffing the inbuffer should make the transformation not be
1239 gst_buffer_ref (inbuffer);
1242 /* pushing gives away my reference ... */
1243 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1244 /* ... but it ends up being modified inplace and
1245 * collected on the global buffer list */
1246 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1247 fail_unless_equals_int (g_list_length (buffers), 1);
1248 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1249 fail_unless (inbuffer == outbuffer);
1250 res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1251 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1253 fail_unless_equals_float (res[0], out[0]);
1254 fail_unless_equals_float (res[1], out[1]);
1257 cleanup_volume (volume);
1263 GST_START_TEST (test_mute_f64)
1266 GstBuffer *inbuffer;
1267 GstBuffer *outbuffer;
1269 gdouble in[2] = { 0.75, -0.25 };
1270 gdouble out[2] = { 0, 0 };
1273 volume = setup_volume ();
1274 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
1275 fail_unless (gst_element_set_state (volume,
1276 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1277 "could not set to playing");
1279 inbuffer = gst_buffer_new_and_alloc (16);
1280 memcpy (GST_BUFFER_DATA (inbuffer), in, 16);
1281 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0);
1282 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1283 gst_buffer_set_caps (inbuffer, caps);
1284 gst_caps_unref (caps);
1285 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1286 /* FIXME: reffing the inbuffer should make the transformation not be
1288 gst_buffer_ref (inbuffer);
1291 /* pushing gives away my reference ... */
1292 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1293 /* ... but it ends up being modified inplace and
1294 * collected on the global buffer list */
1295 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1296 fail_unless_equals_int (g_list_length (buffers), 1);
1297 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1298 fail_unless (inbuffer == outbuffer);
1299 res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1300 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1302 fail_unless_equals_float (res[0], out[0]);
1303 fail_unless_equals_float (res[1], out[1]);
1306 cleanup_volume (volume);
1311 GST_START_TEST (test_wrong_caps)
1314 GstBuffer *inbuffer;
1315 gint16 in[2] = { 16384, -256 };
1317 GstMessage *message;
1320 volume = setup_volume ();
1321 bus = gst_bus_new ();
1323 fail_unless (gst_element_set_state (volume,
1324 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1325 "could not set to playing");
1327 inbuffer = gst_buffer_new_and_alloc (4);
1328 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
1329 caps = gst_caps_from_string (VOLUME_WRONG_CAPS_STRING);
1330 gst_buffer_set_caps (inbuffer, caps);
1331 gst_caps_unref (caps);
1332 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1333 gst_buffer_ref (inbuffer);
1335 /* set a bus here so we avoid getting state change messages */
1336 gst_element_set_bus (volume, bus);
1338 /* pushing gives an error because it can't negotiate with wrong caps */
1339 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer),
1340 GST_FLOW_NOT_NEGOTIATED);
1341 /* ... and the buffer would have been lost if we didn't ref it ourselves */
1342 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1343 gst_buffer_unref (inbuffer);
1344 fail_unless_equals_int (g_list_length (buffers), 0);
1346 /* volume_set_caps should not have been called since basetransform caught
1347 * the negotiation problem */
1348 fail_if ((message = gst_bus_pop (bus)) != NULL);
1351 gst_element_set_bus (volume, NULL);
1352 gst_object_unref (GST_OBJECT (bus));
1353 cleanup_volume (volume);
1358 GST_START_TEST (test_passthrough)
1361 GstBuffer *inbuffer, *outbuffer;
1363 gint16 in[2] = { 16384, -256 };
1366 volume = setup_volume ();
1367 g_object_set (G_OBJECT (volume), "volume", 1.0, NULL);
1368 fail_unless (gst_element_set_state (volume,
1369 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1370 "could not set to playing");
1372 inbuffer = gst_buffer_new_and_alloc (4);
1373 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
1374 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
1375 gst_buffer_set_caps (inbuffer, caps);
1376 gst_caps_unref (caps);
1377 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1379 /* pushing gives away my reference ... */
1380 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1381 /* ... but it ends up being collected on the global buffer list */
1382 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1383 fail_unless_equals_int (g_list_length (buffers), 1);
1384 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1385 fail_unless (inbuffer == outbuffer);
1386 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
1387 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
1388 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
1391 cleanup_volume (volume);
1396 GST_START_TEST (test_controller_usability)
1398 GstInterpolationControlSource *csource;
1401 GValue value = { 0, };
1403 /* note: the volume element should init the controller library for us */
1404 volume = setup_volume ();
1406 c = gst_controller_new (G_OBJECT (volume), "volume", NULL);
1408 fail_unless (GST_IS_CONTROLLER (c));
1410 /* this shouldn't crash, whether this mode is implemented or not */
1411 csource = gst_interpolation_control_source_new ();
1412 gst_interpolation_control_source_set_interpolation_mode (csource,
1413 GST_INTERPOLATE_CUBIC);
1414 gst_controller_set_control_source (c, "volume", GST_CONTROL_SOURCE (csource));
1415 g_object_unref (csource);
1417 g_value_init (&value, G_TYPE_DOUBLE);
1418 g_value_set_double (&value, 0.0);
1419 gst_interpolation_control_source_set (csource, 0 * GST_SECOND, &value);
1420 g_value_set_double (&value, 1.0);
1421 gst_interpolation_control_source_set (csource, 5 * GST_SECOND, &value);
1422 g_value_set_double (&value, 0.0);
1423 gst_interpolation_control_source_set (csource, 10 * GST_SECOND, &value);
1424 g_value_unset (&value);
1428 cleanup_volume (volume);
1433 GST_START_TEST (test_controller_processing)
1435 GstInterpolationControlSource *csource;
1438 GstBuffer *inbuffer, *outbuffer;
1440 gint16 in[2] = { 16384, -256 };
1443 volume = setup_volume ();
1445 c = gst_controller_new (G_OBJECT (volume), "volume", NULL);
1447 fail_unless (GST_IS_CONTROLLER (c));
1449 csource = gst_interpolation_control_source_new ();
1450 gst_interpolation_control_source_set_interpolation_mode (csource,
1451 GST_INTERPOLATE_CUBIC);
1452 gst_controller_set_control_source (c, "volume", GST_CONTROL_SOURCE (csource));
1453 g_object_unref (csource);
1455 fail_unless (gst_element_set_state (volume,
1456 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1457 "could not set to playing");
1459 inbuffer = gst_buffer_new_and_alloc (4);
1460 memcpy (GST_BUFFER_DATA (inbuffer), in, 4);
1461 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
1462 gst_buffer_set_caps (inbuffer, caps);
1463 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
1464 gst_caps_unref (caps);
1465 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1467 /* pushing gives away my reference ... */
1468 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1469 /* ... but it ends up being collected on the global buffer list */
1470 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1471 fail_unless_equals_int (g_list_length (buffers), 1);
1472 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1473 fail_unless (inbuffer == outbuffer);
1474 res = (gint16 *) GST_BUFFER_DATA (outbuffer);
1475 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
1476 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
1480 cleanup_volume (volume);
1488 Suite *s = suite_create ("volume");
1489 TCase *tc_chain = tcase_create ("general");
1491 suite_add_tcase (s, tc_chain);
1492 tcase_add_test (tc_chain, test_get_set);
1493 tcase_add_test (tc_chain, test_unity_s8);
1494 tcase_add_test (tc_chain, test_half_s8);
1495 tcase_add_test (tc_chain, test_double_s8);
1496 tcase_add_test (tc_chain, test_mute_s8);
1497 tcase_add_test (tc_chain, test_unity_s16);
1498 tcase_add_test (tc_chain, test_half_s16);
1499 tcase_add_test (tc_chain, test_double_s16);
1500 tcase_add_test (tc_chain, test_mute_s16);
1501 tcase_add_test (tc_chain, test_unity_s24);
1502 tcase_add_test (tc_chain, test_half_s24);
1503 tcase_add_test (tc_chain, test_double_s24);
1504 tcase_add_test (tc_chain, test_mute_s24);
1505 tcase_add_test (tc_chain, test_unity_s32);
1506 tcase_add_test (tc_chain, test_half_s32);
1507 tcase_add_test (tc_chain, test_double_s32);
1508 tcase_add_test (tc_chain, test_mute_s32);
1509 tcase_add_test (tc_chain, test_unity_f32);
1510 tcase_add_test (tc_chain, test_half_f32);
1511 tcase_add_test (tc_chain, test_double_f32);
1512 tcase_add_test (tc_chain, test_mute_f32);
1513 tcase_add_test (tc_chain, test_unity_f64);
1514 tcase_add_test (tc_chain, test_half_f64);
1515 tcase_add_test (tc_chain, test_double_f64);
1516 tcase_add_test (tc_chain, test_mute_f64);
1517 tcase_add_test (tc_chain, test_wrong_caps);
1518 tcase_add_test (tc_chain, test_passthrough);
1519 tcase_add_test (tc_chain, test_controller_usability);
1520 tcase_add_test (tc_chain, test_controller_processing);
1525 GST_CHECK_MAIN (volume)