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/audio/streamvolume.h>
28 #include <gst/controller/gstinterpolationcontrolsource.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;
35 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
36 #define FORMATS1 "{ S8, S16LE, S24LE, S32LE, F32LE, F64LE }"
38 #define FORMATS3 "S16LE"
39 #define FORMATS4 "S24LE"
40 #define FORMATS5 "S32LE"
41 #define FORMATS6 "F32LE"
42 #define FORMATS7 "F64LE"
43 #define FORMATS8 "U16LE"
45 #define FORMATS1 "{ S8, S16BE, S24BE, S32BE, F32BE, F64BE }"
47 #define FORMATS3 "S16BE"
48 #define FORMATS4 "S24BE"
49 #define FORMATS5 "S32BE"
50 #define FORMATS6 "F32BE"
51 #define FORMATS7 "F64BE"
52 #define FORMATS8 "U16BE"
55 #define VOLUME_CAPS_TEMPLATE_STRING \
57 "format = (string) "FORMATS1", " \
58 "channels = (int) [ 1, MAX ], " \
59 "rate = (int) [ 1, MAX ]"
61 #define VOLUME_CAPS_STRING_S8 \
63 "formats = (string) "FORMATS2", " \
64 "channels = (int) 1, " \
67 #define VOLUME_CAPS_STRING_S16 \
69 "formats = (string) "FORMATS3", " \
70 "channels = (int) 1, " \
73 #define VOLUME_CAPS_STRING_S24 \
75 "formats = (string) "FORMATS4", " \
76 "channels = (int) 1, " \
79 #define VOLUME_CAPS_STRING_S32 \
81 "formats = (string) "FORMATS5", " \
82 "channels = (int) 1, " \
85 #define VOLUME_CAPS_STRING_F32 \
87 "formats = (string) "FORMATS6", " \
88 "channels = (int) 1, " \
91 #define VOLUME_CAPS_STRING_F64 \
93 "formats = (string) "FORMATS7", " \
94 "channels = (int) 1, " \
97 #define VOLUME_WRONG_CAPS_STRING \
99 "formats = (string) "FORMATS8", " \
100 "channels = (int) 1, " \
104 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
107 GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING)
109 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
112 GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING)
120 GST_DEBUG ("setup_volume");
121 volume = gst_check_setup_element ("volume");
122 mysrcpad = gst_check_setup_src_pad (volume, &srctemplate);
123 mysinkpad = gst_check_setup_sink_pad (volume, &sinktemplate);
124 gst_pad_set_active (mysrcpad, TRUE);
125 gst_pad_set_active (mysinkpad, TRUE);
131 cleanup_volume (GstElement * volume)
133 GST_DEBUG ("cleanup_volume");
135 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
136 g_list_free (buffers);
139 gst_pad_set_active (mysrcpad, FALSE);
140 gst_pad_set_active (mysinkpad, FALSE);
141 gst_check_teardown_src_pad (volume);
142 gst_check_teardown_sink_pad (volume);
143 gst_check_teardown_element (volume);
146 GST_START_TEST (test_get_set)
148 GstElement *volume = gst_element_factory_make ("volume", NULL);
151 fail_unless (volume != NULL);
152 g_object_get (G_OBJECT (volume), "volume", &val, NULL);
153 fail_unless (val == 1.0);
154 fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume),
155 GST_STREAM_VOLUME_FORMAT_LINEAR));
157 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
158 g_object_get (G_OBJECT (volume), "volume", &val, NULL);
159 fail_unless (val == 0.5);
160 fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume),
161 GST_STREAM_VOLUME_FORMAT_LINEAR));
163 gst_stream_volume_set_volume (GST_STREAM_VOLUME (volume),
164 GST_STREAM_VOLUME_FORMAT_LINEAR, 1.0);
165 g_object_get (G_OBJECT (volume), "volume", &val, NULL);
166 fail_unless (val == 1.0);
167 fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume),
168 GST_STREAM_VOLUME_FORMAT_LINEAR));
170 gst_object_unref (volume);
175 GST_START_TEST (test_unity_s8)
178 GstBuffer *inbuffer, *outbuffer;
180 gint8 in[2] = { 64, -16 };
184 volume = setup_volume ();
185 fail_unless (gst_element_set_state (volume,
186 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
187 "could not set to playing");
189 inbuffer = gst_buffer_new_and_alloc (2);
190 gst_buffer_fill (inbuffer, 0, in, 2);
191 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
192 gst_pad_set_caps (mysrcpad, caps);
193 gst_caps_unref (caps);
194 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
196 /* pushing gives away my reference ... */
197 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
198 /* ... but it ends up being collected on the global buffer list */
199 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
200 fail_unless_equals_int (g_list_length (buffers), 1);
201 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
202 fail_unless (inbuffer == outbuffer);
203 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
204 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
205 fail_unless (memcmp (res, in, 2) == 0);
206 gst_buffer_unmap (outbuffer, res, size);
209 cleanup_volume (volume);
214 GST_START_TEST (test_half_s8)
218 GstBuffer *outbuffer;
220 gint8 in[2] = { 64, -16 };
221 gint8 out[2] = { 32, -8 };
225 volume = setup_volume ();
226 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
227 fail_unless (gst_element_set_state (volume,
228 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
229 "could not set to playing");
231 inbuffer = gst_buffer_new_and_alloc (2);
232 gst_buffer_fill (inbuffer, 0, in, 2);
233 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
234 gst_pad_set_caps (mysrcpad, caps);
235 gst_caps_unref (caps);
236 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
237 /* FIXME: reffing the inbuffer should make the transformation not be
239 gst_buffer_ref (inbuffer);
242 /* pushing gives away my reference ... */
243 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
244 /* ... but it ends up being modified inplace and
245 * collected on the global buffer list */
246 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
247 fail_unless_equals_int (g_list_length (buffers), 1);
248 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
249 fail_unless (inbuffer == outbuffer);
250 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
251 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
253 fail_unless (memcmp (res, out, 2) == 0);
254 gst_buffer_unmap (outbuffer, res, size);
257 cleanup_volume (volume);
262 GST_START_TEST (test_double_s8)
266 GstBuffer *outbuffer;
268 gint8 in[2] = { 64, -16 };
269 gint8 out[2] = { 127, -32 }; /* notice the clamped sample */
273 volume = setup_volume ();
274 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
275 fail_unless (gst_element_set_state (volume,
276 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
277 "could not set to playing");
279 inbuffer = gst_buffer_new_and_alloc (2);
280 gst_buffer_fill (inbuffer, 0, in, 2);
281 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
282 gst_pad_set_caps (mysrcpad, caps);
283 gst_caps_unref (caps);
284 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
285 /* FIXME: reffing the inbuffer should make the transformation not be
287 gst_buffer_ref (inbuffer);
290 /* pushing gives away my reference ... */
291 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
292 /* ... but it ends up being modified inplace and
293 * collected on the global buffer list */
294 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
295 fail_unless_equals_int (g_list_length (buffers), 1);
296 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
297 fail_unless (inbuffer == outbuffer);
298 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
299 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
301 fail_unless (memcmp (res, out, 2) == 0);
302 gst_buffer_unmap (outbuffer, res, size);
305 cleanup_volume (volume);
310 GST_START_TEST (test_ten_s8)
314 GstBuffer *outbuffer;
316 gint8 in[2] = { 64, -10 };
317 gint8 out[2] = { 127, -100 }; /* notice the clamped sample */
321 volume = setup_volume ();
322 g_object_set (G_OBJECT (volume), "volume", 10.0, NULL);
323 fail_unless (gst_element_set_state (volume,
324 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
325 "could not set to playing");
327 inbuffer = gst_buffer_new_and_alloc (2);
328 gst_buffer_fill (inbuffer, 0, in, 2);
329 fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 2) == 0);
330 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
331 gst_pad_set_caps (mysrcpad, caps);
332 gst_caps_unref (caps);
333 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
334 /* FIXME: reffing the inbuffer should make the transformation not be
336 gst_buffer_ref (inbuffer);
339 /* pushing gives away my reference ... */
340 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
341 /* ... but it ends up being modified inplace and
342 * collected on the global buffer list */
343 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
344 fail_unless_equals_int (g_list_length (buffers), 1);
345 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
346 fail_unless (inbuffer == outbuffer);
347 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
348 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
350 fail_unless (memcmp (res, out, 2) == 0);
351 gst_buffer_unmap (outbuffer, res, size);
354 cleanup_volume (volume);
359 GST_START_TEST (test_mute_s8)
363 GstBuffer *outbuffer;
365 gint8 in[2] = { 64, -16 };
366 gint8 out[2] = { 0, 0 };
370 volume = setup_volume ();
371 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
372 fail_unless (gst_element_set_state (volume,
373 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
374 "could not set to playing");
376 inbuffer = gst_buffer_new_and_alloc (2);
377 gst_buffer_fill (inbuffer, 0, in, 2);
378 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
379 gst_pad_set_caps (mysrcpad, caps);
380 gst_caps_unref (caps);
381 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
382 /* FIXME: reffing the inbuffer should make the transformation not be
384 gst_buffer_ref (inbuffer);
387 /* pushing gives away my reference ... */
388 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
389 /* ... but it ends up being modified inplace and
390 * collected on the global buffer list */
391 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
392 fail_unless_equals_int (g_list_length (buffers), 1);
393 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
394 fail_unless (inbuffer == outbuffer);
395 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
396 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
398 fail_unless (memcmp (res, out, 2) == 0);
399 gst_buffer_unmap (outbuffer, res, size);
402 cleanup_volume (volume);
407 GST_START_TEST (test_unity_s16)
410 GstBuffer *inbuffer, *outbuffer;
412 gint16 in[2] = { 16384, -256 };
416 volume = setup_volume ();
417 fail_unless (gst_element_set_state (volume,
418 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
419 "could not set to playing");
421 inbuffer = gst_buffer_new_and_alloc (4);
422 gst_buffer_fill (inbuffer, 0, in, 4);
423 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
424 gst_pad_set_caps (mysrcpad, caps);
425 gst_caps_unref (caps);
426 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
428 /* pushing gives away my reference ... */
429 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
430 /* ... but it ends up being collected on the global buffer list */
431 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
432 fail_unless_equals_int (g_list_length (buffers), 1);
433 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
434 fail_unless (inbuffer == outbuffer);
435 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
436 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
437 fail_unless (memcmp (res, in, 4) == 0);
438 gst_buffer_unmap (outbuffer, res, size);
441 cleanup_volume (volume);
446 GST_START_TEST (test_half_s16)
450 GstBuffer *outbuffer;
452 gint16 in[2] = { 16384, -256 };
453 gint16 out[2] = { 8192, -128 };
457 volume = setup_volume ();
458 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
459 fail_unless (gst_element_set_state (volume,
460 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
461 "could not set to playing");
463 inbuffer = gst_buffer_new_and_alloc (4);
464 gst_buffer_fill (inbuffer, 0, in, 4);
465 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
466 gst_pad_set_caps (mysrcpad, caps);
467 gst_caps_unref (caps);
468 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
469 /* FIXME: reffing the inbuffer should make the transformation not be
471 gst_buffer_ref (inbuffer);
474 /* pushing gives away my reference ... */
475 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
476 /* ... but it ends up being modified inplace and
477 * collected on the global buffer list */
478 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
479 fail_unless_equals_int (g_list_length (buffers), 1);
480 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
481 fail_unless (inbuffer == outbuffer);
482 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
483 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
485 fail_unless (memcmp (res, out, 4) == 0);
486 gst_buffer_unmap (outbuffer, res, size);
489 cleanup_volume (volume);
494 GST_START_TEST (test_double_s16)
498 GstBuffer *outbuffer;
500 gint16 in[2] = { 16384, -256 };
501 gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */
505 volume = setup_volume ();
506 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
507 fail_unless (gst_element_set_state (volume,
508 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
509 "could not set to playing");
511 inbuffer = gst_buffer_new_and_alloc (4);
512 gst_buffer_fill (inbuffer, 0, in, 4);
513 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
514 gst_pad_set_caps (mysrcpad, caps);
515 gst_caps_unref (caps);
516 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
517 /* FIXME: reffing the inbuffer should make the transformation not be
519 gst_buffer_ref (inbuffer);
522 /* pushing gives away my reference ... */
523 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
524 /* ... but it ends up being modified inplace and
525 * collected on the global buffer list */
526 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
527 fail_unless_equals_int (g_list_length (buffers), 1);
528 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
529 fail_unless (inbuffer == outbuffer);
530 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
531 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
533 fail_unless (memcmp (res, out, 4) == 0);
534 gst_buffer_unmap (outbuffer, res, size);
537 cleanup_volume (volume);
542 GST_START_TEST (test_ten_s16)
546 GstBuffer *outbuffer;
548 gint16 in[2] = { 16384, -10 };
549 gint16 out[2] = { 32767, -100 }; /* notice the clamped sample */
553 volume = setup_volume ();
554 g_object_set (G_OBJECT (volume), "volume", 10.0, NULL);
555 fail_unless (gst_element_set_state (volume,
556 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
557 "could not set to playing");
559 inbuffer = gst_buffer_new_and_alloc (4);
560 gst_buffer_fill (inbuffer, 0, in, 4);
561 fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 4) == 0);
562 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
563 gst_pad_set_caps (mysrcpad, caps);
564 gst_caps_unref (caps);
565 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
566 /* FIXME: reffing the inbuffer should make the transformation not be
568 gst_buffer_ref (inbuffer);
571 /* pushing gives away my reference ... */
572 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
573 /* ... but it ends up being modified inplace and
574 * 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_map (outbuffer, &size, NULL, GST_MAP_READ);
580 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
582 fail_unless (memcmp (res, out, 4) == 0);
583 gst_buffer_unmap (outbuffer, res, size);
586 cleanup_volume (volume);
592 GST_START_TEST (test_mute_s16)
596 GstBuffer *outbuffer;
598 gint16 in[2] = { 16384, -256 };
599 gint16 out[2] = { 0, 0 };
603 volume = setup_volume ();
604 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
605 fail_unless (gst_element_set_state (volume,
606 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
607 "could not set to playing");
609 inbuffer = gst_buffer_new_and_alloc (4);
610 gst_buffer_fill (inbuffer, 0, in, 4);
611 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
612 gst_pad_set_caps (mysrcpad, caps);
613 gst_caps_unref (caps);
614 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
615 /* FIXME: reffing the inbuffer should make the transformation not be
617 gst_buffer_ref (inbuffer);
620 /* pushing gives away my reference ... */
621 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
622 /* ... but it ends up being modified inplace and
623 * collected on the global buffer list */
624 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
625 fail_unless_equals_int (g_list_length (buffers), 1);
626 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
627 fail_unless (inbuffer == outbuffer);
628 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
629 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
631 fail_unless (memcmp (res, out, 4) == 0);
632 gst_buffer_unmap (outbuffer, res, size);
635 cleanup_volume (volume);
640 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
641 #define get_unaligned_i24(_x) ( (((guint8*)_x)[0]) | ((((guint8*)_x)[1]) << 8) | ((((gint8*)_x)[2]) << 16) )
642 #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)
643 #else /* BIG ENDIAN */
644 #define get_unaligned_i24(_x) ( (((guint8*)_x)[2]) | ((((guint8*)_x)[1]) << 8) | ((((gint8*)_x)[0]) << 16) )
645 #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)
648 GST_START_TEST (test_unity_s24)
651 GstBuffer *inbuffer, *outbuffer;
653 gint32 in_32[2] = { 4194304, -4096 };
659 write_unaligned_u24 (in, in_32[0]);
660 write_unaligned_u24 (in + 3, in_32[1]);
662 volume = setup_volume ();
663 fail_unless (gst_element_set_state (volume,
664 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
665 "could not set to playing");
667 inbuffer = gst_buffer_new_and_alloc (6);
668 gst_buffer_fill (inbuffer, 0, in, 6);
669 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
670 gst_pad_set_caps (mysrcpad, caps);
671 gst_caps_unref (caps);
672 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
674 /* pushing gives away my reference ... */
675 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
676 /* ... but it ends up being collected on the global buffer list */
677 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
678 fail_unless_equals_int (g_list_length (buffers), 1);
679 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
680 fail_unless (inbuffer == outbuffer);
681 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
683 res_32[0] = get_unaligned_i24 (res);
684 res_32[1] = get_unaligned_i24 ((res + 3));
686 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in_32[0], in_32[1], res_32[0],
688 fail_unless (memcmp (res, in, 6) == 0);
689 gst_buffer_unmap (outbuffer, res, size);
692 cleanup_volume (volume);
697 GST_START_TEST (test_half_s24)
701 GstBuffer *outbuffer;
703 gint32 in_32[2] = { 4194304, -4096 };
707 gint32 out_32[2] = { 2097152, -2048 };
710 write_unaligned_u24 (in, in_32[0]);
711 write_unaligned_u24 (in + 3, in_32[1]);
713 volume = setup_volume ();
714 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
715 fail_unless (gst_element_set_state (volume,
716 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
717 "could not set to playing");
719 inbuffer = gst_buffer_new_and_alloc (6);
720 gst_buffer_fill (inbuffer, 0, in, 6);
721 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
722 gst_pad_set_caps (mysrcpad, caps);
723 gst_caps_unref (caps);
724 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
725 /* FIXME: reffing the inbuffer should make the transformation not be
727 gst_buffer_ref (inbuffer);
730 /* pushing gives away my reference ... */
731 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
732 /* ... but it ends up being modified inplace and
733 * collected on the global buffer list */
734 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
735 fail_unless_equals_int (g_list_length (buffers), 1);
736 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
737 fail_unless (inbuffer == outbuffer);
738 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
740 res_32[0] = get_unaligned_i24 (res);
741 res_32[1] = get_unaligned_i24 ((res + 3));
743 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
744 res_32[0], res_32[1]);
745 fail_unless (memcmp (res_32, out_32, 8) == 0);
746 gst_buffer_unmap (outbuffer, res, size);
749 cleanup_volume (volume);
754 GST_START_TEST (test_double_s24)
758 GstBuffer *outbuffer;
760 gint32 in_32[2] = { 4194304, -4096 };
764 gint32 out_32[2] = { 8388607, -8192 }; /* notice the clamped sample */
767 write_unaligned_u24 (in, in_32[0]);
768 write_unaligned_u24 (in + 3, in_32[1]);
770 volume = setup_volume ();
771 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
772 fail_unless (gst_element_set_state (volume,
773 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
774 "could not set to playing");
776 inbuffer = gst_buffer_new_and_alloc (6);
777 gst_buffer_fill (inbuffer, 0, in, 6);
778 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
779 gst_pad_set_caps (mysrcpad, caps);
780 gst_caps_unref (caps);
781 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
782 /* FIXME: reffing the inbuffer should make the transformation not be
784 gst_buffer_ref (inbuffer);
787 /* pushing gives away my reference ... */
788 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
789 /* ... but it ends up being modified inplace and
790 * collected on the global buffer list */
791 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
792 fail_unless_equals_int (g_list_length (buffers), 1);
793 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
794 fail_unless (inbuffer == outbuffer);
795 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
797 res_32[0] = get_unaligned_i24 (res);
798 res_32[1] = get_unaligned_i24 ((res + 3));
800 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
801 res_32[0], res_32[1]);
802 fail_unless (memcmp (res_32, out_32, 8) == 0);
803 gst_buffer_unmap (outbuffer, res, size);
806 cleanup_volume (volume);
811 GST_START_TEST (test_ten_s24)
815 GstBuffer *outbuffer;
817 gint32 in_32[2] = { 4194304, -10 };
821 gint32 out_32[2] = { 8388607, -100 }; /* notice the clamped sample */
824 write_unaligned_u24 (in, in_32[0]);
825 write_unaligned_u24 (in + 3, in_32[1]);
827 volume = setup_volume ();
828 g_object_set (G_OBJECT (volume), "volume", 10.0, NULL);
829 fail_unless (gst_element_set_state (volume,
830 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
831 "could not set to playing");
833 inbuffer = gst_buffer_new_and_alloc (6);
834 gst_buffer_fill (inbuffer, 0, in, 6);
835 fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 6) == 0);
836 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
837 gst_pad_set_caps (mysrcpad, caps);
838 gst_caps_unref (caps);
839 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
840 /* FIXME: reffing the inbuffer should make the transformation not be
842 gst_buffer_ref (inbuffer);
845 /* pushing gives away my reference ... */
846 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
847 /* ... but it ends up being modified inplace and
848 * collected on the global buffer list */
849 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
850 fail_unless_equals_int (g_list_length (buffers), 1);
851 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
852 fail_unless (inbuffer == outbuffer);
853 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
855 res_32[0] = get_unaligned_i24 (res);
856 res_32[1] = get_unaligned_i24 ((res + 3));
858 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
859 res_32[0], res_32[1]);
860 fail_unless (memcmp (res_32, out_32, 8) == 0);
861 gst_buffer_unmap (outbuffer, res, size);
864 cleanup_volume (volume);
869 GST_START_TEST (test_mute_s24)
873 GstBuffer *outbuffer;
875 gint32 in_32[2] = { 4194304, -4096 };
879 gint32 out_32[2] = { 0, 0 }; /* notice the clamped sample */
882 write_unaligned_u24 (in, in_32[0]);
883 write_unaligned_u24 (in + 3, in_32[1]);
885 volume = setup_volume ();
886 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
887 fail_unless (gst_element_set_state (volume,
888 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
889 "could not set to playing");
891 inbuffer = gst_buffer_new_and_alloc (6);
892 gst_buffer_fill (inbuffer, 0, in, 6);
893 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
894 gst_pad_set_caps (mysrcpad, caps);
895 gst_caps_unref (caps);
896 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
897 /* FIXME: reffing the inbuffer should make the transformation not be
899 gst_buffer_ref (inbuffer);
902 /* pushing gives away my reference ... */
903 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
904 /* ... but it ends up being modified inplace and
905 * collected on the global buffer list */
906 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
907 fail_unless_equals_int (g_list_length (buffers), 1);
908 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
909 fail_unless (inbuffer == outbuffer);
911 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
913 res_32[0] = get_unaligned_i24 (res);
914 res_32[1] = get_unaligned_i24 ((res + 3));
916 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
917 res_32[0], res_32[1]);
918 fail_unless (memcmp (res_32, out_32, 8) == 0);
919 gst_buffer_unmap (outbuffer, res, size);
922 cleanup_volume (volume);
927 GST_START_TEST (test_unity_s32)
930 GstBuffer *inbuffer, *outbuffer;
932 gint32 in[2] = { 1073741824, -65536 };
936 volume = setup_volume ();
937 fail_unless (gst_element_set_state (volume,
938 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
939 "could not set to playing");
941 inbuffer = gst_buffer_new_and_alloc (8);
942 gst_buffer_fill (inbuffer, 0, in, 8);
943 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
944 gst_pad_set_caps (mysrcpad, caps);
945 gst_caps_unref (caps);
946 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
948 /* pushing gives away my reference ... */
949 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
950 /* ... but it ends up being collected on the global buffer list */
951 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
952 fail_unless_equals_int (g_list_length (buffers), 1);
953 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
954 fail_unless (inbuffer == outbuffer);
955 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
956 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
957 fail_unless (memcmp (res, in, 8) == 0);
958 gst_buffer_unmap (outbuffer, res, size);
961 cleanup_volume (volume);
966 GST_START_TEST (test_half_s32)
970 GstBuffer *outbuffer;
972 gint32 in[2] = { 1073741824, -65536 };
973 gint32 out[2] = { 536870912, -32768 };
977 volume = setup_volume ();
978 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
979 fail_unless (gst_element_set_state (volume,
980 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
981 "could not set to playing");
983 inbuffer = gst_buffer_new_and_alloc (8);
984 gst_buffer_fill (inbuffer, 0, in, 8);
985 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
986 gst_pad_set_caps (mysrcpad, caps);
987 gst_caps_unref (caps);
988 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
989 /* FIXME: reffing the inbuffer should make the transformation not be
991 gst_buffer_ref (inbuffer);
994 /* pushing gives away my reference ... */
995 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
996 /* ... but it ends up being modified inplace and
997 * collected on the global buffer list */
998 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
999 fail_unless_equals_int (g_list_length (buffers), 1);
1000 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1001 fail_unless (inbuffer == outbuffer);
1002 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1003 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
1005 fail_unless (memcmp (res, out, 8) == 0);
1006 gst_buffer_unmap (outbuffer, res, size);
1009 cleanup_volume (volume);
1014 GST_START_TEST (test_double_s32)
1017 GstBuffer *inbuffer;
1018 GstBuffer *outbuffer;
1020 gint32 in[2] = { 1073741824, -65536 };
1021 gint32 out[2] = { 2147483647, -131072 }; /* notice the clamped sample */
1025 volume = setup_volume ();
1026 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
1027 fail_unless (gst_element_set_state (volume,
1028 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1029 "could not set to playing");
1031 inbuffer = gst_buffer_new_and_alloc (8);
1032 gst_buffer_fill (inbuffer, 0, in, 8);
1033 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
1034 gst_pad_set_caps (mysrcpad, caps);
1035 gst_caps_unref (caps);
1036 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1037 /* FIXME: reffing the inbuffer should make the transformation not be
1039 gst_buffer_ref (inbuffer);
1042 /* pushing gives away my reference ... */
1043 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1044 /* ... but it ends up being modified inplace and
1045 * collected on the global buffer list */
1046 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1047 fail_unless_equals_int (g_list_length (buffers), 1);
1048 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1049 fail_unless (inbuffer == outbuffer);
1050 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1051 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
1053 fail_unless (memcmp (res, out, 8) == 0);
1054 gst_buffer_unmap (outbuffer, res, size);
1057 cleanup_volume (volume);
1062 GST_START_TEST (test_ten_s32)
1065 GstBuffer *inbuffer;
1066 GstBuffer *outbuffer;
1068 gint32 in[2] = { 1073741824, -10 };
1069 gint32 out[2] = { 2147483647, -100 }; /* notice the clamped sample */
1073 volume = setup_volume ();
1074 g_object_set (G_OBJECT (volume), "volume", 10.0, NULL);
1075 fail_unless (gst_element_set_state (volume,
1076 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1077 "could not set to playing");
1079 inbuffer = gst_buffer_new_and_alloc (8);
1080 gst_buffer_fill (inbuffer, 0, in, 8);
1081 fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 8) == 0);
1082 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
1083 gst_pad_set_caps (mysrcpad, caps);
1084 gst_caps_unref (caps);
1085 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1086 /* FIXME: reffing the inbuffer should make the transformation not be
1088 gst_buffer_ref (inbuffer);
1091 /* pushing gives away my reference ... */
1092 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1093 /* ... but it ends up being modified inplace and
1094 * collected on the global buffer list */
1095 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1096 fail_unless_equals_int (g_list_length (buffers), 1);
1097 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1098 fail_unless (inbuffer == outbuffer);
1099 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1100 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
1102 fail_unless (memcmp (res, out, 8) == 0);
1103 gst_buffer_unmap (outbuffer, res, size);
1106 cleanup_volume (volume);
1111 GST_START_TEST (test_mute_s32)
1114 GstBuffer *inbuffer;
1115 GstBuffer *outbuffer;
1117 gint32 in[2] = { 1073741824, -65536 };
1118 gint32 out[2] = { 0, 0 };
1122 volume = setup_volume ();
1123 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
1124 fail_unless (gst_element_set_state (volume,
1125 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1126 "could not set to playing");
1128 inbuffer = gst_buffer_new_and_alloc (8);
1129 gst_buffer_fill (inbuffer, 0, in, 8);
1130 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
1131 gst_pad_set_caps (mysrcpad, caps);
1132 gst_caps_unref (caps);
1133 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1134 /* FIXME: reffing the inbuffer should make the transformation not be
1136 gst_buffer_ref (inbuffer);
1139 /* pushing gives away my reference ... */
1140 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1141 /* ... but it ends up being modified inplace and
1142 * collected on the global buffer list */
1143 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1144 fail_unless_equals_int (g_list_length (buffers), 1);
1145 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1146 fail_unless (inbuffer == outbuffer);
1147 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1148 GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
1150 fail_unless (memcmp (res, out, 8) == 0);
1151 gst_buffer_unmap (outbuffer, res, size);
1154 cleanup_volume (volume);
1159 GST_START_TEST (test_unity_f32)
1162 GstBuffer *inbuffer, *outbuffer;
1164 gfloat in[2] = { 0.75, -0.25 };
1168 volume = setup_volume ();
1169 fail_unless (gst_element_set_state (volume,
1170 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1171 "could not set to playing");
1173 inbuffer = gst_buffer_new_and_alloc (8);
1174 gst_buffer_fill (inbuffer, 0, in, 8);
1175 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
1176 gst_pad_set_caps (mysrcpad, caps);
1177 gst_caps_unref (caps);
1178 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1180 /* pushing gives away my reference ... */
1181 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1182 /* ... but it ends up being collected on the global buffer list */
1183 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1184 fail_unless_equals_int (g_list_length (buffers), 1);
1185 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1186 fail_unless (inbuffer == outbuffer);
1187 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1188 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0],
1190 fail_unless_equals_float (res[0], in[0]);
1191 fail_unless_equals_float (res[1], in[1]);
1194 cleanup_volume (volume);
1199 GST_START_TEST (test_half_f32)
1202 GstBuffer *inbuffer;
1203 GstBuffer *outbuffer;
1205 gfloat in[2] = { 0.75, -0.25 };
1206 gfloat out[2] = { 0.375, -0.125 };
1210 volume = setup_volume ();
1211 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
1212 fail_unless (gst_element_set_state (volume,
1213 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1214 "could not set to playing");
1216 inbuffer = gst_buffer_new_and_alloc (8);
1217 gst_buffer_fill (inbuffer, 0, in, 8);
1218 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
1219 gst_pad_set_caps (mysrcpad, caps);
1220 gst_caps_unref (caps);
1221 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1222 /* FIXME: reffing the inbuffer should make the transformation not be
1224 gst_buffer_ref (inbuffer);
1227 /* pushing gives away my reference ... */
1228 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1229 /* ... but it ends up being modified inplace and
1230 * collected on the global buffer list */
1231 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1232 fail_unless_equals_int (g_list_length (buffers), 1);
1233 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1234 fail_unless (inbuffer == outbuffer);
1235 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1236 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1238 fail_unless_equals_float (res[0], out[0]);
1239 fail_unless_equals_float (res[1], out[1]);
1240 gst_buffer_unmap (outbuffer, res, size);
1243 cleanup_volume (volume);
1248 GST_START_TEST (test_double_f32)
1251 GstBuffer *inbuffer;
1252 GstBuffer *outbuffer;
1254 gfloat in[2] = { 0.75, -0.25 };
1255 gfloat out[2] = { 1.5, -0.5 }; /* nothing is clamped */
1259 volume = setup_volume ();
1260 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
1261 fail_unless (gst_element_set_state (volume,
1262 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1263 "could not set to playing");
1265 inbuffer = gst_buffer_new_and_alloc (8);
1266 gst_buffer_fill (inbuffer, 0, in, 8);
1267 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
1268 gst_pad_set_caps (mysrcpad, caps);
1269 gst_caps_unref (caps);
1270 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1271 /* FIXME: reffing the inbuffer should make the transformation not be
1273 gst_buffer_ref (inbuffer);
1276 /* pushing gives away my reference ... */
1277 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1278 /* ... but it ends up being modified inplace and
1279 * collected on the global buffer list */
1280 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1281 fail_unless_equals_int (g_list_length (buffers), 1);
1282 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1283 fail_unless (inbuffer == outbuffer);
1284 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1285 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1287 fail_unless_equals_float (res[0], out[0]);
1288 fail_unless_equals_float (res[1], out[1]);
1289 gst_buffer_unmap (outbuffer, res, size);
1292 cleanup_volume (volume);
1297 GST_START_TEST (test_ten_f32)
1300 GstBuffer *inbuffer;
1301 GstBuffer *outbuffer;
1303 gfloat in[2] = { 0.75, -0.25 };
1304 gfloat out[2] = { 7.5, -2.5 }; /* nothing is clamped */
1308 volume = setup_volume ();
1309 g_object_set (G_OBJECT (volume), "volume", 10.0, NULL);
1310 fail_unless (gst_element_set_state (volume,
1311 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1312 "could not set to playing");
1314 inbuffer = gst_buffer_new_and_alloc (8);
1315 gst_buffer_fill (inbuffer, 0, in, 8);
1316 fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 8) == 0);
1317 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
1318 gst_pad_set_caps (mysrcpad, caps);
1319 gst_caps_unref (caps);
1320 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1321 /* FIXME: reffing the inbuffer should make the transformation not be
1323 gst_buffer_ref (inbuffer);
1326 /* pushing gives away my reference ... */
1327 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1328 /* ... but it ends up being modified inplace and
1329 * collected on the global buffer list */
1330 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1331 fail_unless_equals_int (g_list_length (buffers), 1);
1332 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1333 fail_unless (inbuffer == outbuffer);
1334 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1335 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1337 fail_unless_equals_float (res[0], out[0]);
1338 fail_unless_equals_float (res[1], out[1]);
1339 gst_buffer_unmap (outbuffer, res, size);
1342 cleanup_volume (volume);
1348 GST_START_TEST (test_mute_f32)
1351 GstBuffer *inbuffer;
1352 GstBuffer *outbuffer;
1354 gfloat in[2] = { 0.75, -0.25 };
1355 gfloat out[2] = { 0, 0 };
1359 volume = setup_volume ();
1360 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
1361 fail_unless (gst_element_set_state (volume,
1362 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1363 "could not set to playing");
1365 inbuffer = gst_buffer_new_and_alloc (8);
1366 gst_buffer_fill (inbuffer, 0, in, 8);
1367 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
1368 gst_pad_set_caps (mysrcpad, caps);
1369 gst_caps_unref (caps);
1370 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1371 /* FIXME: reffing the inbuffer should make the transformation not be
1373 gst_buffer_ref (inbuffer);
1376 /* pushing gives away my reference ... */
1377 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1378 /* ... but it ends up being modified inplace and
1379 * collected on the global buffer list */
1380 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1381 fail_unless_equals_int (g_list_length (buffers), 1);
1382 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1383 fail_unless (inbuffer == outbuffer);
1384 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1385 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1387 fail_unless_equals_float (res[0], out[0]);
1388 fail_unless_equals_float (res[1], out[1]);
1389 gst_buffer_unmap (outbuffer, res, size);
1392 cleanup_volume (volume);
1397 GST_START_TEST (test_unity_f64)
1400 GstBuffer *inbuffer, *outbuffer;
1402 gdouble in[2] = { 0.75, -0.25 };
1406 volume = setup_volume ();
1407 fail_unless (gst_element_set_state (volume,
1408 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1409 "could not set to playing");
1411 inbuffer = gst_buffer_new_and_alloc (16);
1412 gst_buffer_fill (inbuffer, 0, in, 16);
1413 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1414 gst_pad_set_caps (mysrcpad, caps);
1415 gst_caps_unref (caps);
1416 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1418 /* pushing gives away my reference ... */
1419 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1420 /* ... but it ends up being collected on the global buffer list */
1421 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1422 fail_unless_equals_int (g_list_length (buffers), 1);
1423 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1424 fail_unless (inbuffer == outbuffer);
1425 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1426 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0],
1428 fail_unless_equals_float (res[0], in[0]);
1429 fail_unless_equals_float (res[1], in[1]);
1432 cleanup_volume (volume);
1437 GST_START_TEST (test_half_f64)
1440 GstBuffer *inbuffer;
1441 GstBuffer *outbuffer;
1443 gdouble in[2] = { 0.75, -0.25 };
1444 gdouble out[2] = { 0.375, -0.125 };
1448 volume = setup_volume ();
1449 g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
1450 fail_unless (gst_element_set_state (volume,
1451 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1452 "could not set to playing");
1454 inbuffer = gst_buffer_new_and_alloc (16);
1455 gst_buffer_fill (inbuffer, 0, in, 16);
1456 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1457 gst_pad_set_caps (mysrcpad, caps);
1458 gst_caps_unref (caps);
1459 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1460 /* FIXME: reffing the inbuffer should make the transformation not be
1462 gst_buffer_ref (inbuffer);
1465 /* pushing gives away my reference ... */
1466 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1467 /* ... but it ends up being modified inplace and
1468 * collected on the global buffer list */
1469 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1470 fail_unless_equals_int (g_list_length (buffers), 1);
1471 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1472 fail_unless (inbuffer == outbuffer);
1473 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1474 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1476 fail_unless_equals_float (res[0], out[0]);
1477 fail_unless_equals_float (res[1], out[1]);
1478 gst_buffer_unmap (outbuffer, res, size);
1481 cleanup_volume (volume);
1486 GST_START_TEST (test_double_f64)
1489 GstBuffer *inbuffer;
1490 GstBuffer *outbuffer;
1492 gdouble in[2] = { 0.75, -0.25 };
1493 gdouble out[2] = { 1.5, -0.5 }; /* nothing is clamped */
1497 volume = setup_volume ();
1498 g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
1499 fail_unless (gst_element_set_state (volume,
1500 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1501 "could not set to playing");
1503 inbuffer = gst_buffer_new_and_alloc (16);
1504 gst_buffer_fill (inbuffer, 0, in, 16);
1505 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1506 gst_pad_set_caps (mysrcpad, caps);
1507 gst_caps_unref (caps);
1508 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1509 /* FIXME: reffing the inbuffer should make the transformation not be
1511 gst_buffer_ref (inbuffer);
1514 /* pushing gives away my reference ... */
1515 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1516 /* ... but it ends up being modified inplace and
1517 * collected on the global buffer list */
1518 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1519 fail_unless_equals_int (g_list_length (buffers), 1);
1520 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1521 fail_unless (inbuffer == outbuffer);
1522 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1523 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1525 fail_unless_equals_float (res[0], out[0]);
1526 fail_unless_equals_float (res[1], out[1]);
1527 gst_buffer_unmap (outbuffer, res, size);
1530 cleanup_volume (volume);
1535 GST_START_TEST (test_ten_f64)
1538 GstBuffer *inbuffer;
1539 GstBuffer *outbuffer;
1541 gdouble in[2] = { 0.75, -0.25 };
1542 gdouble out[2] = { 7.5, -2.5 }; /* nothing is clamped */
1546 volume = setup_volume ();
1547 g_object_set (G_OBJECT (volume), "volume", 10.0, NULL);
1548 fail_unless (gst_element_set_state (volume,
1549 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1550 "could not set to playing");
1552 inbuffer = gst_buffer_new_and_alloc (16);
1553 gst_buffer_fill (inbuffer, 0, in, 16);
1554 fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 16) == 0);
1555 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1556 gst_pad_set_caps (mysrcpad, caps);
1557 gst_caps_unref (caps);
1558 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1559 /* FIXME: reffing the inbuffer should make the transformation not be
1561 gst_buffer_ref (inbuffer);
1564 /* pushing gives away my reference ... */
1565 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1566 /* ... but it ends up being modified inplace and
1567 * collected on the global buffer list */
1568 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1569 fail_unless_equals_int (g_list_length (buffers), 1);
1570 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1571 fail_unless (inbuffer == outbuffer);
1572 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1573 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1575 fail_unless_equals_float (res[0], out[0]);
1576 fail_unless_equals_float (res[1], out[1]);
1577 gst_buffer_unmap (outbuffer, res, size);
1580 cleanup_volume (volume);
1586 GST_START_TEST (test_mute_f64)
1589 GstBuffer *inbuffer;
1590 GstBuffer *outbuffer;
1592 gdouble in[2] = { 0.75, -0.25 };
1593 gdouble out[2] = { 0, 0 };
1597 volume = setup_volume ();
1598 g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
1599 fail_unless (gst_element_set_state (volume,
1600 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1601 "could not set to playing");
1603 inbuffer = gst_buffer_new_and_alloc (16);
1604 gst_buffer_fill (inbuffer, 0, in, 16);
1605 caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
1606 gst_pad_set_caps (mysrcpad, caps);
1607 gst_caps_unref (caps);
1608 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1609 /* FIXME: reffing the inbuffer should make the transformation not be
1611 gst_buffer_ref (inbuffer);
1614 /* pushing gives away my reference ... */
1615 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1616 /* ... but it ends up being modified inplace and
1617 * collected on the global buffer list */
1618 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1619 fail_unless_equals_int (g_list_length (buffers), 1);
1620 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1621 fail_unless (inbuffer == outbuffer);
1622 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1623 GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
1625 fail_unless_equals_float (res[0], out[0]);
1626 fail_unless_equals_float (res[1], out[1]);
1627 gst_buffer_unmap (outbuffer, res, size);
1630 cleanup_volume (volume);
1635 GST_START_TEST (test_wrong_caps)
1638 GstBuffer *inbuffer;
1639 gint16 in[2] = { 16384, -256 };
1641 GstMessage *message;
1644 volume = setup_volume ();
1645 bus = gst_bus_new ();
1647 fail_unless (gst_element_set_state (volume,
1648 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1649 "could not set to playing");
1651 inbuffer = gst_buffer_new_and_alloc (4);
1652 gst_buffer_fill (inbuffer, 0, in, 4);
1653 caps = gst_caps_from_string (VOLUME_WRONG_CAPS_STRING);
1654 gst_pad_set_caps (mysrcpad, caps);
1655 gst_caps_unref (caps);
1656 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1657 gst_buffer_ref (inbuffer);
1659 /* set a bus here so we avoid getting state change messages */
1660 gst_element_set_bus (volume, bus);
1662 /* pushing gives an error because it can't negotiate with wrong caps */
1663 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer),
1664 GST_FLOW_NOT_NEGOTIATED);
1665 /* ... and the buffer would have been lost if we didn't ref it ourselves */
1666 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1667 gst_buffer_unref (inbuffer);
1668 fail_unless_equals_int (g_list_length (buffers), 0);
1670 /* volume_set_caps should not have been called since basetransform caught
1671 * the negotiation problem */
1672 fail_if ((message = gst_bus_pop (bus)) != NULL);
1675 gst_element_set_bus (volume, NULL);
1676 gst_object_unref (GST_OBJECT (bus));
1677 cleanup_volume (volume);
1682 GST_START_TEST (test_passthrough)
1685 GstBuffer *inbuffer, *outbuffer;
1687 gint16 in[2] = { 16384, -256 };
1691 volume = setup_volume ();
1692 g_object_set (G_OBJECT (volume), "volume", 1.0, NULL);
1693 fail_unless (gst_element_set_state (volume,
1694 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1695 "could not set to playing");
1697 inbuffer = gst_buffer_new_and_alloc (4);
1698 gst_buffer_fill (inbuffer, 0, in, 4);
1699 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
1700 gst_pad_set_caps (mysrcpad, caps);
1701 gst_caps_unref (caps);
1702 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1704 /* pushing gives away my reference ... */
1705 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1706 /* ... but it ends up being collected on the global buffer list */
1707 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1708 fail_unless_equals_int (g_list_length (buffers), 1);
1709 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1710 fail_unless (inbuffer == outbuffer);
1711 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1712 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
1713 fail_unless (memcmp (res, in, 4) == 0);
1714 gst_buffer_unmap (outbuffer, res, size);
1717 cleanup_volume (volume);
1722 GST_START_TEST (test_controller_usability)
1724 GstInterpolationControlSource *csource;
1725 GstTimedValueControlSource *cs;
1728 volume = setup_volume ();
1730 /* this shouldn't crash, whether this mode is implemented or not */
1731 csource = gst_interpolation_control_source_new ();
1732 g_object_set (csource, "mode", GST_INTERPOLATION_MODE_CUBIC, NULL);
1733 gst_object_set_control_source (GST_OBJECT_CAST (volume), "volume",
1734 GST_CONTROL_SOURCE (csource));
1736 cs = (GstTimedValueControlSource *) csource;
1737 gst_timed_value_control_source_set (cs, 0 * GST_SECOND, 0.0);
1738 gst_timed_value_control_source_set (cs, 5 * GST_SECOND, 1.0);
1739 gst_timed_value_control_source_set (cs, 10 * GST_SECOND, 0.0);
1741 gst_object_unref (csource);
1743 cleanup_volume (volume);
1748 GST_START_TEST (test_controller_processing)
1750 GstInterpolationControlSource *csource;
1752 GstBuffer *inbuffer, *outbuffer;
1754 gint16 in[2] = { 16384, -256 };
1758 volume = setup_volume ();
1760 csource = gst_interpolation_control_source_new ();
1761 g_object_set (csource, "mode", GST_INTERPOLATION_MODE_CUBIC, NULL);
1762 gst_object_set_control_source (GST_OBJECT_CAST (volume), "volume",
1763 GST_CONTROL_SOURCE (csource));
1765 fail_unless (gst_element_set_state (volume,
1766 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1767 "could not set to playing");
1769 inbuffer = gst_buffer_new_and_alloc (4);
1770 gst_buffer_fill (inbuffer, 0, in, 4);
1771 caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
1772 gst_pad_set_caps (mysrcpad, caps);
1773 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
1774 gst_caps_unref (caps);
1775 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1777 /* pushing gives away my reference ... */
1778 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1779 /* ... but it ends up being collected on the global buffer list */
1780 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1781 fail_unless_equals_int (g_list_length (buffers), 1);
1782 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1783 fail_unless (inbuffer == outbuffer);
1784 res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
1785 GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
1786 fail_unless (memcmp (res, in, 4) == 0);
1787 gst_buffer_unmap (outbuffer, res, size);
1789 gst_object_unref (csource);
1790 cleanup_volume (volume);
1798 Suite *s = suite_create ("volume");
1799 TCase *tc_chain = tcase_create ("general");
1801 suite_add_tcase (s, tc_chain);
1802 tcase_add_test (tc_chain, test_get_set);
1803 tcase_add_test (tc_chain, test_unity_s8);
1804 tcase_add_test (tc_chain, test_half_s8);
1805 tcase_add_test (tc_chain, test_double_s8);
1806 tcase_add_test (tc_chain, test_ten_s8);
1807 tcase_add_test (tc_chain, test_mute_s8);
1808 tcase_add_test (tc_chain, test_unity_s16);
1809 tcase_add_test (tc_chain, test_half_s16);
1810 tcase_add_test (tc_chain, test_double_s16);
1811 tcase_add_test (tc_chain, test_ten_s16);
1812 tcase_add_test (tc_chain, test_mute_s16);
1813 tcase_add_test (tc_chain, test_unity_s24);
1814 tcase_add_test (tc_chain, test_half_s24);
1815 tcase_add_test (tc_chain, test_double_s24);
1816 tcase_add_test (tc_chain, test_ten_s24);
1817 tcase_add_test (tc_chain, test_mute_s24);
1818 tcase_add_test (tc_chain, test_unity_s32);
1819 tcase_add_test (tc_chain, test_half_s32);
1820 tcase_add_test (tc_chain, test_double_s32);
1821 tcase_add_test (tc_chain, test_ten_s32);
1822 tcase_add_test (tc_chain, test_mute_s32);
1823 tcase_add_test (tc_chain, test_unity_f32);
1824 tcase_add_test (tc_chain, test_half_f32);
1825 tcase_add_test (tc_chain, test_double_f32);
1826 tcase_add_test (tc_chain, test_ten_f32);
1827 tcase_add_test (tc_chain, test_mute_f32);
1828 tcase_add_test (tc_chain, test_unity_f64);
1829 tcase_add_test (tc_chain, test_half_f64);
1830 tcase_add_test (tc_chain, test_double_f64);
1831 tcase_add_test (tc_chain, test_ten_f64);
1832 tcase_add_test (tc_chain, test_mute_f64);
1833 tcase_add_test (tc_chain, test_wrong_caps);
1834 tcase_add_test (tc_chain, test_passthrough);
1835 tcase_add_test (tc_chain, test_controller_usability);
1836 tcase_add_test (tc_chain, test_controller_processing);
1841 GST_CHECK_MAIN (volume)