3 * unit test for audioconvert
5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
6 * Copyright (C) <2007> Tim-Philipp Müller <tim centricular net>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 #include <gst/floatcast/floatcast.h>
27 #include <gst/check/gstcheck.h>
28 #include <gst/audio/multichannel.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 #define CONVERT_CAPS_TEMPLATE_STRING \
36 "audio/x-raw-float, " \
37 "rate = (int) [ 1, MAX ], " \
38 "channels = (int) [ 1, MAX ], " \
39 "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
40 "width = (int) { 32, 64 };" \
42 "rate = (int) [ 1, MAX ], " \
43 "channels = (int) [ 1, MAX ], " \
44 "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
45 "width = (int) 32, " \
46 "depth = (int) [ 1, 32 ], " \
47 "signed = (boolean) { true, false }; " \
49 "rate = (int) [ 1, MAX ], " \
50 "channels = (int) [ 1, MAX ], " \
51 "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
52 "width = (int) 24, " \
53 "depth = (int) [ 1, 24 ], " \
54 "signed = (boolean) { true, false }; " \
56 "rate = (int) [ 1, MAX ], " \
57 "channels = (int) [ 1, MAX ], " \
58 "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
59 "width = (int) 16, " \
60 "depth = (int) [ 1, 16 ], " \
61 "signed = (boolean) { true, false }; " \
63 "rate = (int) [ 1, MAX ], " \
64 "channels = (int) [ 1, MAX ], " \
65 "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
67 "depth = (int) [ 1, 8 ], " \
68 "signed = (boolean) { true, false } "
70 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
73 GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING)
75 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
78 GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING)
81 /* takes over reference for outcaps */
83 setup_audioconvert (GstCaps * outcaps)
85 GstElement *audioconvert;
87 GST_DEBUG ("setup_audioconvert with caps %" GST_PTR_FORMAT, outcaps);
88 audioconvert = gst_check_setup_element ("audioconvert");
89 g_object_set (G_OBJECT (audioconvert), "dithering", 0, NULL);
90 g_object_set (G_OBJECT (audioconvert), "noise-shaping", 0, NULL);
91 mysrcpad = gst_check_setup_src_pad (audioconvert, &srctemplate, NULL);
92 mysinkpad = gst_check_setup_sink_pad (audioconvert, &sinktemplate, NULL);
93 /* this installs a getcaps func that will always return the caps we set
95 gst_pad_use_fixed_caps (mysinkpad);
97 gst_pad_set_active (mysrcpad, TRUE);
98 gst_pad_set_active (mysinkpad, TRUE);
100 gst_pad_set_caps (mysinkpad, outcaps);
101 gst_caps_unref (outcaps);
102 outcaps = gst_pad_get_current_caps (mysinkpad);
103 fail_unless (gst_caps_is_fixed (outcaps));
104 gst_caps_unref (outcaps);
110 cleanup_audioconvert (GstElement * audioconvert)
112 GST_DEBUG ("cleanup_audioconvert");
114 gst_pad_set_active (mysrcpad, FALSE);
115 gst_pad_set_active (mysinkpad, FALSE);
116 gst_check_teardown_src_pad (audioconvert);
117 gst_check_teardown_sink_pad (audioconvert);
118 gst_check_teardown_element (audioconvert);
121 /* returns a newly allocated caps */
123 get_int_caps (guint channels, const gchar * endianness, guint width,
124 guint depth, gboolean signedness)
129 string = g_strdup_printf ("audio/x-raw-int, "
130 "rate = (int) 44100, "
131 "channels = (int) %d, "
132 "endianness = (int) %s, "
135 "signed = (boolean) %s ",
136 channels, endianness, width, depth, signedness ? "true" : "false");
137 GST_DEBUG ("creating caps from %s", string);
138 caps = gst_caps_from_string (string);
140 fail_unless (caps != NULL);
141 GST_DEBUG ("returning caps %p", caps);
145 /* returns a newly allocated caps */
147 get_float_caps (guint channels, const gchar * endianness, guint width)
152 string = g_strdup_printf ("audio/x-raw-float, "
153 "rate = (int) 44100, "
154 "channels = (int) %d, "
155 "endianness = (int) %s, "
156 "width = (int) %d ", channels, endianness, width);
157 GST_DEBUG ("creating caps from %s", string);
158 caps = gst_caps_from_string (string);
160 fail_unless (caps != NULL);
161 GST_DEBUG ("returning caps %p", caps);
165 /* Copied from vorbis; the particular values used don't matter */
166 static GstAudioChannelPosition channelpositions[][6] = {
168 GST_AUDIO_CHANNEL_POSITION_FRONT_MONO},
170 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
171 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
172 { /* Stereo + Centre */
173 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
174 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
175 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
177 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
178 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
179 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
180 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
182 { /* Stereo + Centre + rear stereo */
183 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
184 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
185 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
186 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
187 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
189 { /* Full 5.1 Surround */
190 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
191 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
192 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
193 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
194 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
195 GST_AUDIO_CHANNEL_POSITION_LFE,
199 /* these are a bunch of random positions, they are mostly just
200 * different from the ones above, don't use elsewhere */
201 static GstAudioChannelPosition mixed_up_positions[][6] = {
203 GST_AUDIO_CHANNEL_POSITION_FRONT_MONO},
205 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
206 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT},
208 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
209 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
210 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT},
212 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
213 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
214 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
215 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
218 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
219 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
220 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
221 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
222 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
225 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
226 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
227 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
228 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
229 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
230 GST_AUDIO_CHANNEL_POSITION_LFE,
234 /* we get this when recording from a soundcard with lots of input channels */
235 static GstAudioChannelPosition undefined_positions[][15] = {
237 GST_AUDIO_CHANNEL_POSITION_NONE},
239 GST_AUDIO_CHANNEL_POSITION_NONE,
240 GST_AUDIO_CHANNEL_POSITION_NONE},
242 GST_AUDIO_CHANNEL_POSITION_NONE,
243 GST_AUDIO_CHANNEL_POSITION_NONE,
244 GST_AUDIO_CHANNEL_POSITION_NONE},
246 GST_AUDIO_CHANNEL_POSITION_NONE,
247 GST_AUDIO_CHANNEL_POSITION_NONE,
248 GST_AUDIO_CHANNEL_POSITION_NONE,
249 GST_AUDIO_CHANNEL_POSITION_NONE},
251 GST_AUDIO_CHANNEL_POSITION_NONE,
252 GST_AUDIO_CHANNEL_POSITION_NONE,
253 GST_AUDIO_CHANNEL_POSITION_NONE,
254 GST_AUDIO_CHANNEL_POSITION_NONE,
255 GST_AUDIO_CHANNEL_POSITION_NONE},
257 GST_AUDIO_CHANNEL_POSITION_NONE,
258 GST_AUDIO_CHANNEL_POSITION_NONE,
259 GST_AUDIO_CHANNEL_POSITION_NONE,
260 GST_AUDIO_CHANNEL_POSITION_NONE,
261 GST_AUDIO_CHANNEL_POSITION_NONE,
262 GST_AUDIO_CHANNEL_POSITION_NONE},
264 GST_AUDIO_CHANNEL_POSITION_NONE,
265 GST_AUDIO_CHANNEL_POSITION_NONE,
266 GST_AUDIO_CHANNEL_POSITION_NONE,
267 GST_AUDIO_CHANNEL_POSITION_NONE,
268 GST_AUDIO_CHANNEL_POSITION_NONE,
269 GST_AUDIO_CHANNEL_POSITION_NONE,
270 GST_AUDIO_CHANNEL_POSITION_NONE},
272 GST_AUDIO_CHANNEL_POSITION_NONE,
273 GST_AUDIO_CHANNEL_POSITION_NONE,
274 GST_AUDIO_CHANNEL_POSITION_NONE,
275 GST_AUDIO_CHANNEL_POSITION_NONE,
276 GST_AUDIO_CHANNEL_POSITION_NONE,
277 GST_AUDIO_CHANNEL_POSITION_NONE,
278 GST_AUDIO_CHANNEL_POSITION_NONE,
279 GST_AUDIO_CHANNEL_POSITION_NONE},
281 GST_AUDIO_CHANNEL_POSITION_NONE,
282 GST_AUDIO_CHANNEL_POSITION_NONE,
283 GST_AUDIO_CHANNEL_POSITION_NONE,
284 GST_AUDIO_CHANNEL_POSITION_NONE,
285 GST_AUDIO_CHANNEL_POSITION_NONE,
286 GST_AUDIO_CHANNEL_POSITION_NONE,
287 GST_AUDIO_CHANNEL_POSITION_NONE,
288 GST_AUDIO_CHANNEL_POSITION_NONE,
289 GST_AUDIO_CHANNEL_POSITION_NONE},
291 GST_AUDIO_CHANNEL_POSITION_NONE,
292 GST_AUDIO_CHANNEL_POSITION_NONE,
293 GST_AUDIO_CHANNEL_POSITION_NONE,
294 GST_AUDIO_CHANNEL_POSITION_NONE,
295 GST_AUDIO_CHANNEL_POSITION_NONE,
296 GST_AUDIO_CHANNEL_POSITION_NONE,
297 GST_AUDIO_CHANNEL_POSITION_NONE,
298 GST_AUDIO_CHANNEL_POSITION_NONE,
299 GST_AUDIO_CHANNEL_POSITION_NONE,
300 GST_AUDIO_CHANNEL_POSITION_NONE},
302 GST_AUDIO_CHANNEL_POSITION_NONE,
303 GST_AUDIO_CHANNEL_POSITION_NONE,
304 GST_AUDIO_CHANNEL_POSITION_NONE,
305 GST_AUDIO_CHANNEL_POSITION_NONE,
306 GST_AUDIO_CHANNEL_POSITION_NONE,
307 GST_AUDIO_CHANNEL_POSITION_NONE,
308 GST_AUDIO_CHANNEL_POSITION_NONE,
309 GST_AUDIO_CHANNEL_POSITION_NONE,
310 GST_AUDIO_CHANNEL_POSITION_NONE,
311 GST_AUDIO_CHANNEL_POSITION_NONE,
312 GST_AUDIO_CHANNEL_POSITION_NONE},
314 GST_AUDIO_CHANNEL_POSITION_NONE,
315 GST_AUDIO_CHANNEL_POSITION_NONE,
316 GST_AUDIO_CHANNEL_POSITION_NONE,
317 GST_AUDIO_CHANNEL_POSITION_NONE,
318 GST_AUDIO_CHANNEL_POSITION_NONE,
319 GST_AUDIO_CHANNEL_POSITION_NONE,
320 GST_AUDIO_CHANNEL_POSITION_NONE,
321 GST_AUDIO_CHANNEL_POSITION_NONE,
322 GST_AUDIO_CHANNEL_POSITION_NONE,
323 GST_AUDIO_CHANNEL_POSITION_NONE,
324 GST_AUDIO_CHANNEL_POSITION_NONE,
325 GST_AUDIO_CHANNEL_POSITION_NONE},
327 GST_AUDIO_CHANNEL_POSITION_NONE,
328 GST_AUDIO_CHANNEL_POSITION_NONE,
329 GST_AUDIO_CHANNEL_POSITION_NONE,
330 GST_AUDIO_CHANNEL_POSITION_NONE,
331 GST_AUDIO_CHANNEL_POSITION_NONE,
332 GST_AUDIO_CHANNEL_POSITION_NONE,
333 GST_AUDIO_CHANNEL_POSITION_NONE,
334 GST_AUDIO_CHANNEL_POSITION_NONE,
335 GST_AUDIO_CHANNEL_POSITION_NONE,
336 GST_AUDIO_CHANNEL_POSITION_NONE,
337 GST_AUDIO_CHANNEL_POSITION_NONE,
338 GST_AUDIO_CHANNEL_POSITION_NONE,
339 GST_AUDIO_CHANNEL_POSITION_NONE},
341 GST_AUDIO_CHANNEL_POSITION_NONE,
342 GST_AUDIO_CHANNEL_POSITION_NONE,
343 GST_AUDIO_CHANNEL_POSITION_NONE,
344 GST_AUDIO_CHANNEL_POSITION_NONE,
345 GST_AUDIO_CHANNEL_POSITION_NONE,
346 GST_AUDIO_CHANNEL_POSITION_NONE,
347 GST_AUDIO_CHANNEL_POSITION_NONE,
348 GST_AUDIO_CHANNEL_POSITION_NONE,
349 GST_AUDIO_CHANNEL_POSITION_NONE,
350 GST_AUDIO_CHANNEL_POSITION_NONE,
351 GST_AUDIO_CHANNEL_POSITION_NONE,
352 GST_AUDIO_CHANNEL_POSITION_NONE,
353 GST_AUDIO_CHANNEL_POSITION_NONE,
354 GST_AUDIO_CHANNEL_POSITION_NONE},
356 GST_AUDIO_CHANNEL_POSITION_NONE,
357 GST_AUDIO_CHANNEL_POSITION_NONE,
358 GST_AUDIO_CHANNEL_POSITION_NONE,
359 GST_AUDIO_CHANNEL_POSITION_NONE,
360 GST_AUDIO_CHANNEL_POSITION_NONE,
361 GST_AUDIO_CHANNEL_POSITION_NONE,
362 GST_AUDIO_CHANNEL_POSITION_NONE,
363 GST_AUDIO_CHANNEL_POSITION_NONE,
364 GST_AUDIO_CHANNEL_POSITION_NONE,
365 GST_AUDIO_CHANNEL_POSITION_NONE,
366 GST_AUDIO_CHANNEL_POSITION_NONE,
367 GST_AUDIO_CHANNEL_POSITION_NONE,
368 GST_AUDIO_CHANNEL_POSITION_NONE,
369 GST_AUDIO_CHANNEL_POSITION_NONE,
370 GST_AUDIO_CHANNEL_POSITION_NONE}
374 set_channel_positions (GstCaps * caps, int channels,
375 GstAudioChannelPosition * channelpositions)
377 GValue chanpos = { 0 };
379 GstStructure *structure = gst_caps_get_structure (caps, 0);
382 g_value_init (&chanpos, GST_TYPE_ARRAY);
383 g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
385 for (c = 0; c < channels; c++) {
386 g_value_set_enum (&pos, channelpositions[c]);
387 gst_value_array_append_value (&chanpos, &pos);
389 g_value_unset (&pos);
391 gst_structure_set_value (structure, "channel-positions", &chanpos);
392 g_value_unset (&chanpos);
395 /* For channels > 2, caps have to have channel positions. This adds some simple
396 * ones. Only implemented for channels between 1 and 6.
399 get_float_mc_caps (guint channels, const gchar * endianness, guint width,
400 gboolean mixed_up_layout)
402 GstCaps *caps = get_float_caps (channels, endianness, width);
406 set_channel_positions (caps, channels, mixed_up_positions[channels - 1]);
408 set_channel_positions (caps, channels, channelpositions[channels - 1]);
415 get_int_mc_caps (guint channels, const gchar * endianness, guint width,
416 guint depth, gboolean signedness, gboolean mixed_up_layout)
418 GstCaps *caps = get_int_caps (channels, endianness, width, depth, signedness);
422 set_channel_positions (caps, channels, mixed_up_positions[channels - 1]);
424 set_channel_positions (caps, channels, channelpositions[channels - 1]);
430 /* eats the refs to the caps */
432 verify_convert (const gchar * which, void *in, int inlength,
433 GstCaps * incaps, void *out, int outlength, GstCaps * outcaps,
434 GstFlowReturn expected_flow)
436 GstBuffer *inbuffer, *outbuffer;
437 GstElement *audioconvert;
439 GST_DEBUG ("verifying conversion %s", which);
440 GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps);
441 GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps);
442 ASSERT_CAPS_REFCOUNT (incaps, "incaps", 1);
443 ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1);
444 audioconvert = setup_audioconvert (outcaps);
445 ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1);
447 fail_unless (gst_element_set_state (audioconvert,
448 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
449 "could not set to playing");
451 gst_pad_push_event (mysrcpad, gst_event_new_caps (incaps));
453 GST_DEBUG ("Creating buffer of %d bytes", inlength);
454 inbuffer = gst_buffer_new_and_alloc (inlength);
455 gst_buffer_fill (inbuffer, 0, in, inlength);
456 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
458 /* pushing gives away my reference ... */
459 GST_DEBUG ("push it");
460 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), expected_flow);
461 GST_DEBUG ("pushed it");
463 if (expected_flow != GST_FLOW_OK)
466 /* ... and puts a new buffer on the global list */
467 fail_unless (g_list_length (buffers) == 1);
468 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
470 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
471 fail_unless_equals_int (gst_buffer_get_size (outbuffer), outlength);
473 gst_check_buffer_data (outbuffer, out, outlength);
475 if (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) != 0) {
476 g_print ("\nInput data:\n");
477 gst_util_dump_mem (in, inlength);
478 g_print ("\nConverted data:\n");
479 gst_util_dump_mem (GST_BUFFER_DATA (outbuffer), outlength);
480 g_print ("\nExpected data:\n");
481 gst_util_dump_mem (out, outlength);
483 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) == 0,
484 "failed converting %s", which);
487 /* make sure that the channel positions are not lost */
489 GstStructure *in_s, *out_s;
492 in_s = gst_caps_get_structure (incaps, 0);
493 out_s = gst_caps_get_structure (gst_pad_get_current_caps (mysinkpad), 0);
494 fail_unless (gst_structure_get_int (out_s, "channels", &out_chans));
496 /* positions for 1 and 2 channels are implicit if not provided */
497 if (out_chans > 2 && gst_structure_has_field (in_s, "channel-positions")) {
498 if (!gst_structure_has_field (out_s, "channel-positions")) {
499 g_error ("Channel layout got lost somewhere:\n\nIns : %s\nOuts: %s\n",
500 gst_structure_to_string (in_s), gst_structure_to_string (out_s));
505 buffers = g_list_remove (buffers, outbuffer);
506 gst_buffer_unref (outbuffer);
509 fail_unless (gst_element_set_state (audioconvert,
510 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
512 GST_DEBUG ("cleanup audioconvert");
513 cleanup_audioconvert (audioconvert);
514 GST_DEBUG ("cleanup, unref incaps");
515 gst_caps_unref (incaps);
519 #define RUN_CONVERSION(which, inarray, in_get_caps, outarray, out_get_caps) \
520 verify_convert (which, inarray, sizeof (inarray), \
521 in_get_caps, outarray, sizeof (outarray), out_get_caps, GST_FLOW_OK)
523 #define RUN_CONVERSION_TO_FAIL(which, inarray, in_caps, outarray, out_caps) \
524 verify_convert (which, inarray, sizeof (inarray), \
525 in_caps, outarray, sizeof (outarray), out_caps, GST_FLOW_NOT_NEGOTIATED)
528 GST_START_TEST (test_int16)
532 gint16 in[] = { 16384, -256, 1024, 1024 };
533 gint16 out[] = { 8064, 1024 };
535 RUN_CONVERSION ("int16 stereo to mono",
536 in, get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE),
537 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
541 gint16 in[] = { 512, 1024 };
542 gint16 out[] = { 512, 512, 1024, 1024 };
544 RUN_CONVERSION ("int16 mono to stereo",
545 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
546 out, get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE));
548 /* signed -> unsigned */
550 gint16 in[] = { 0, -32767, 32767, -32768 };
551 guint16 out[] = { 32768, 1, 65535, 0 };
553 RUN_CONVERSION ("int16 signed to unsigned",
554 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
555 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE));
556 RUN_CONVERSION ("int16 unsigned to signed",
557 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE),
558 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
565 GST_START_TEST (test_float32)
569 gfloat in[] = { 0.6, -0.0078125, 0.03125, 0.03125 };
570 gfloat out[] = { 0.29609375, 0.03125 };
572 RUN_CONVERSION ("float32 stereo to mono",
573 in, get_float_caps (2, "BYTE_ORDER", 32),
574 out, get_float_caps (1, "BYTE_ORDER", 32));
578 gfloat in[] = { 0.015625, 0.03125 };
579 gfloat out[] = { 0.015625, 0.015625, 0.03125, 0.03125 };
581 RUN_CONVERSION ("float32 mono to stereo",
582 in, get_float_caps (1, "BYTE_ORDER", 32),
583 out, get_float_caps (2, "BYTE_ORDER", 32));
590 GST_START_TEST (test_int_conversion)
592 /* 8 <-> 16 signed */
593 /* NOTE: if audioconvert was doing dithering we'd have a problem */
595 gint8 in[] = { 0, 1, 2, 127, -127 };
596 gint16 out[] = { 0, 256, 512, 32512, -32512 };
598 RUN_CONVERSION ("int 8bit to 16bit signed",
599 in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE),
600 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)
602 RUN_CONVERSION ("int 16bit signed to 8bit",
603 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
604 in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE)
609 gint16 in[] = { 0, 127, 128, 256, 256 + 127, 256 + 128 };
610 gint8 out[] = { 0, 0, 1, 1, 1, 2 };
612 RUN_CONVERSION ("16 bit to 8 signed",
613 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
614 out, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE)
617 /* 8 unsigned <-> 16 signed */
618 /* NOTE: if audioconvert was doing dithering we'd have a problem */
620 guint8 in[] = { 128, 129, 130, 255, 1 };
621 gint16 out[] = { 0, 256, 512, 32512, -32512 };
622 GstCaps *incaps, *outcaps;
624 /* exploded for easier valgrinding */
625 incaps = get_int_caps (1, "BYTE_ORDER", 8, 8, FALSE);
626 outcaps = get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE);
627 GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps);
628 GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps);
629 RUN_CONVERSION ("8 unsigned to 16 signed", in, incaps, out, outcaps);
630 RUN_CONVERSION ("16 signed to 8 unsigned", out, get_int_caps (1,
631 "BYTE_ORDER", 16, 16, TRUE), in, get_int_caps (1, "BYTE_ORDER", 8,
635 /* 8 <-> 24 signed */
636 /* NOTE: if audioconvert was doing dithering we'd have a problem */
638 gint8 in[] = { 0, 1, 127 };
639 guint8 out[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x7f };
640 /* out has the bytes in little-endian, so that's how they should be
641 * interpreted during conversion */
643 RUN_CONVERSION ("8 to 24 signed", in, get_int_caps (1, "BYTE_ORDER", 8, 8,
644 TRUE), out, get_int_caps (1, "LITTLE_ENDIAN", 24, 24, TRUE)
646 RUN_CONVERSION ("24 signed to 8", out, get_int_caps (1, "LITTLE_ENDIAN", 24,
647 24, TRUE), in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE)
651 /* 16 bit signed <-> unsigned */
653 gint16 in[] = { 0, 128, -128 };
654 guint16 out[] = { 32768, 32896, 32640 };
655 RUN_CONVERSION ("16 signed to 16 unsigned",
656 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
657 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE)
659 RUN_CONVERSION ("16 unsigned to 16 signed",
660 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE),
661 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)
665 /* 16 bit signed <-> 8 in 16 bit signed */
666 /* NOTE: if audioconvert was doing dithering we'd have a problem */
668 gint16 in[] = { 0, 64 << 8, -64 << 8 };
669 gint16 out[] = { 0, 64, -64 };
670 RUN_CONVERSION ("16 signed to 8 in 16 signed",
671 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
672 out, get_int_caps (1, "BYTE_ORDER", 16, 8, TRUE)
674 RUN_CONVERSION ("8 in 16 signed to 16 signed",
675 out, get_int_caps (1, "BYTE_ORDER", 16, 8, TRUE),
676 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)
680 /* 16 bit unsigned <-> 8 in 16 bit unsigned */
681 /* NOTE: if audioconvert was doing dithering we'd have a problem */
683 guint16 in[] = { 1 << 15, (1 << 15) - (64 << 8), (1 << 15) + (64 << 8) };
684 guint16 out[] = { 1 << 7, (1 << 7) - 64, (1 << 7) + 64 };
685 RUN_CONVERSION ("16 unsigned to 8 in 16 unsigned",
686 in, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE),
687 out, get_int_caps (1, "BYTE_ORDER", 16, 8, FALSE)
689 RUN_CONVERSION ("8 in 16 unsigned to 16 unsigned",
690 out, get_int_caps (1, "BYTE_ORDER", 16, 8, FALSE),
691 in, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE)
695 /* 32 bit signed -> 16 bit signed for rounding check */
696 /* NOTE: if audioconvert was doing dithering we'd have a problem */
698 gint32 in[] = { 0, G_MININT32, G_MAXINT32,
699 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
700 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
701 (-32 << 16) + (1 << 15), (-32 << 16) - (1 << 15),
702 (-32 << 16) + (2 << 15), (-32 << 16) - (2 << 15),
705 gint16 out[] = { 0, G_MININT16, G_MAXINT16,
712 RUN_CONVERSION ("32 signed to 16 signed for rounding",
713 in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE),
714 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)
718 /* 32 bit signed -> 16 bit unsigned for rounding check */
719 /* NOTE: if audioconvert was doing dithering we'd have a problem */
721 gint32 in[] = { 0, G_MININT32, G_MAXINT32,
722 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
723 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
724 (-32 << 16) + (1 << 15), (-32 << 16) - (1 << 15),
725 (-32 << 16) + (2 << 15), (-32 << 16) - (2 << 15),
728 guint16 out[] = { (1 << 15), 0, G_MAXUINT16,
729 (1 << 15) + 32, (1 << 15) + 33, (1 << 15) + 32,
730 (1 << 15) + 33, (1 << 15) + 31,
731 (1 << 15) - 31, (1 << 15) - 32,
732 (1 << 15) - 31, (1 << 15) - 33,
735 RUN_CONVERSION ("32 signed to 16 unsigned for rounding",
736 in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE),
737 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE)
744 GST_START_TEST (test_float_conversion)
746 /* 32 float <-> 16 signed */
747 /* NOTE: if audioconvert was doing dithering we'd have a problem */
750 { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0),
751 GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5), GFLOAT_TO_LE (1.1),
755 { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0),
756 GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5), GFLOAT_TO_BE (1.1),
759 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
761 /* only one direction conversion, the other direction does
762 * not produce exactly the same as the input due to floating
763 * point rounding errors etc. */
764 RUN_CONVERSION ("32 float le to 16 signed",
765 in_le, get_float_caps (1, "LITTLE_ENDIAN", 32),
766 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
767 RUN_CONVERSION ("32 float be to 16 signed",
768 in_be, get_float_caps (1, "BIG_ENDIAN", 32),
769 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
773 gint16 in[] = { 0, -32768, 16384, -16384 };
774 gfloat out[] = { 0.0, -1.0, 0.5, -0.5 };
776 RUN_CONVERSION ("16 signed to 32 float",
777 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
778 out, get_float_caps (1, "BYTE_ORDER", 32));
781 /* 64 float <-> 16 signed */
782 /* NOTE: if audioconvert was doing dithering we'd have a problem */
785 { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0),
786 GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5), GDOUBLE_TO_LE (1.1),
790 { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0),
791 GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5), GDOUBLE_TO_BE (1.1),
794 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
796 /* only one direction conversion, the other direction does
797 * not produce exactly the same as the input due to floating
798 * point rounding errors etc. */
799 RUN_CONVERSION ("64 float LE to 16 signed",
800 in_le, get_float_caps (1, "LITTLE_ENDIAN", 64),
801 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
802 RUN_CONVERSION ("64 float BE to 16 signed",
803 in_be, get_float_caps (1, "BIG_ENDIAN", 64),
804 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
807 gint16 in[] = { 0, -32768, 16384, -16384 };
808 gdouble out[] = { 0.0,
809 (gdouble) (-32768L << 16) / 2147483647.0, /* ~ -1.0 */
810 (gdouble) (16384L << 16) / 2147483647.0, /* ~ 0.5 */
811 (gdouble) (-16384L << 16) / 2147483647.0, /* ~ -0.5 */
814 RUN_CONVERSION ("16 signed to 64 float",
815 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
816 out, get_float_caps (1, "BYTE_ORDER", 64));
819 gint32 in[] = { 0, (-1L << 31), (1L << 30), (-1L << 30) };
820 gdouble out[] = { 0.0,
821 (gdouble) (-1L << 31) / 2147483647.0, /* ~ -1.0 */
822 (gdouble) (1L << 30) / 2147483647.0, /* ~ 0.5 */
823 (gdouble) (-1L << 30) / 2147483647.0, /* ~ -0.5 */
826 RUN_CONVERSION ("32 signed to 64 float",
827 in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE),
828 out, get_float_caps (1, "BYTE_ORDER", 64));
831 /* 64-bit float <-> 32-bit float */
833 gdouble in[] = { 0.0, 1.0, -1.0, 0.5, -0.5 };
834 gfloat out[] = { 0.0, 1.0, -1.0, 0.5, -0.5 };
836 RUN_CONVERSION ("64 float to 32 float",
837 in, get_float_caps (1, "BYTE_ORDER", 64),
838 out, get_float_caps (1, "BYTE_ORDER", 32));
840 RUN_CONVERSION ("32 float to 64 float",
841 out, get_float_caps (1, "BYTE_ORDER", 32),
842 in, get_float_caps (1, "BYTE_ORDER", 64));
845 /* 32-bit float little endian <-> big endian */
847 gfloat le[] = { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0),
848 GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5)
850 gfloat be[] = { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0),
851 GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5)
854 RUN_CONVERSION ("32 float LE to BE",
855 le, get_float_caps (1, "LITTLE_ENDIAN", 32),
856 be, get_float_caps (1, "BIG_ENDIAN", 32));
858 RUN_CONVERSION ("32 float BE to LE",
859 be, get_float_caps (1, "BIG_ENDIAN", 32),
860 le, get_float_caps (1, "LITTLE_ENDIAN", 32));
863 /* 64-bit float little endian <-> big endian */
866 { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0),
867 GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5)
870 { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0),
871 GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5)
874 RUN_CONVERSION ("64 float LE to BE",
875 le, get_float_caps (1, "LITTLE_ENDIAN", 64),
876 be, get_float_caps (1, "BIG_ENDIAN", 64));
878 RUN_CONVERSION ("64 float BE to LE",
879 be, get_float_caps (1, "BIG_ENDIAN", 64),
880 le, get_float_caps (1, "LITTLE_ENDIAN", 64));
887 GST_START_TEST (test_multichannel_conversion)
890 gfloat in[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
891 gfloat out[] = { 0.0, 0.0 };
893 RUN_CONVERSION ("3 channels to 1", in, get_float_mc_caps (3,
894 "BYTE_ORDER", 32, FALSE), out, get_float_caps (1, "BYTE_ORDER",
896 RUN_CONVERSION ("1 channels to 3", out, get_float_caps (1,
897 "BYTE_ORDER", 32), in, get_float_mc_caps (3, "BYTE_ORDER",
902 gint16 in[] = { 0, 0, 0, 0, 0, 0 };
903 gint16 out[] = { 0, 0 };
905 RUN_CONVERSION ("3 channels to 1", in, get_int_mc_caps (3,
906 "BYTE_ORDER", 16, 16, TRUE, FALSE), out, get_int_caps (1,
907 "BYTE_ORDER", 16, 16, TRUE));
908 RUN_CONVERSION ("1 channels to 3", out, get_int_caps (1, "BYTE_ORDER", 16,
909 16, TRUE), in, get_int_mc_caps (3, "BYTE_ORDER", 16, 16, TRUE,
914 gint16 in[] = { 1, 2 };
915 gint16 out[] = { 1, 1, 2, 2 };
916 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
917 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
918 GstAudioChannelPosition in_layout[1] =
919 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
920 GstAudioChannelPosition out_layout[2] =
921 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
922 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
925 set_channel_positions (in_caps, 1, in_layout);
926 set_channel_positions (out_caps, 2, out_layout);
928 RUN_CONVERSION ("1 channels to 2 with standard layout", in,
929 in_caps, out, out_caps);
933 gint16 in[] = { 1, 2 };
934 gint16 out[] = { 1, 1, 2, 2 };
935 GstCaps *in_caps = get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE);
936 GstCaps *out_caps = get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE);
938 RUN_CONVERSION ("1 channels to 2 with standard layout and no positions set",
939 in, gst_caps_copy (in_caps), out, gst_caps_copy (out_caps));
941 RUN_CONVERSION ("2 channels to 1 with standard layout and no positions set",
942 out, out_caps, in, in_caps);
946 gint16 in[] = { 1, 2 };
947 gint16 out[] = { 1, 0, 2, 0 };
948 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
949 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
950 GstAudioChannelPosition in_layout[1] =
951 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT };
952 GstAudioChannelPosition out_layout[2] =
953 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
954 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
957 set_channel_positions (in_caps, 1, in_layout);
958 set_channel_positions (out_caps, 2, out_layout);
960 RUN_CONVERSION ("1 channels to 2 with non-standard layout", in,
961 in_caps, out, out_caps);
965 gint16 in[] = { 1, 2, 3, 4 };
966 gint16 out[] = { 2, 4 };
967 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
968 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
969 GstAudioChannelPosition in_layout[2] =
970 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
971 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
973 GstAudioChannelPosition out_layout[1] =
974 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER };
976 set_channel_positions (in_caps, 2, in_layout);
977 set_channel_positions (out_caps, 1, out_layout);
979 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
980 in_caps, out, out_caps);
984 gint16 in[] = { 1, 2, 3, 4 };
985 gint16 out[] = { 2, 4 };
986 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
987 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
988 GstAudioChannelPosition in_layout[2] =
989 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
990 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
992 GstAudioChannelPosition out_layout[1] =
993 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
995 set_channel_positions (in_caps, 2, in_layout);
996 set_channel_positions (out_caps, 1, out_layout);
998 RUN_CONVERSION ("2 channels to 1 with standard layout", in,
999 in_caps, out, out_caps);
1003 gint16 in[] = { 1, 2, 3, 4 };
1004 gint16 out[] = { 1, 3 };
1005 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1006 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1007 GstAudioChannelPosition in_layout[2] =
1008 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1009 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER
1011 GstAudioChannelPosition out_layout[1] =
1012 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1014 set_channel_positions (in_caps, 2, in_layout);
1015 set_channel_positions (out_caps, 1, out_layout);
1017 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1018 in_caps, out, out_caps);
1022 gint16 in[] = { 1, 2, 3, 4 };
1023 gint16 out[] = { 1, 3 };
1024 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1025 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1026 GstAudioChannelPosition in_layout[2] =
1027 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1028 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT
1030 GstAudioChannelPosition out_layout[1] =
1031 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1033 set_channel_positions (in_caps, 2, in_layout);
1034 set_channel_positions (out_caps, 1, out_layout);
1036 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1037 in_caps, out, out_caps);
1040 gint16 in[] = { 4, 5, 4, 2, 2, 1 };
1041 gint16 out[] = { 3, 3 };
1042 GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1043 GstCaps *out_caps = get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE);
1045 RUN_CONVERSION ("5.1 to 2 channels", in, in_caps, out, out_caps);
1048 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1049 gint16 out[] = { 0, 0 };
1050 GstCaps *in_caps = get_int_mc_caps (11, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1051 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1052 GstAudioChannelPosition in_layout[11] = {
1053 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1054 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1055 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
1056 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1057 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1058 GST_AUDIO_CHANNEL_POSITION_LFE,
1059 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1060 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
1061 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
1062 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1063 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
1066 set_channel_positions (in_caps, 11, in_layout);
1068 RUN_CONVERSION ("11 channels to 2", in,
1069 gst_caps_copy (in_caps), out, gst_caps_copy (out_caps));
1070 RUN_CONVERSION ("2 channels to 11", out, out_caps, in, in_caps);
1077 /* for testing channel remapping with 8 channels */
1078 static GstAudioChannelPosition n8chan_pos_remap_in[8] = {
1079 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1080 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1081 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1082 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1083 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1084 GST_AUDIO_CHANNEL_POSITION_LFE,
1085 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1086 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
1089 static GstAudioChannelPosition n8chan_pos_remap_out[8] = {
1090 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1091 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1092 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1093 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1094 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
1095 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1096 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1097 GST_AUDIO_CHANNEL_POSITION_LFE
1100 GST_START_TEST (test_channel_remapping)
1104 gfloat in[] = { 0.0, 1.0, -0.5 };
1105 gfloat out[] = { -0.5, 1.0, 0.0 };
1106 GstCaps *in_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, FALSE);
1107 GstCaps *out_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, TRUE);
1109 RUN_CONVERSION ("3 channels layout remapping float", in, in_caps,
1115 guint16 in[] = { 0, 65535, 0x9999 };
1116 guint16 out[] = { 0x9999, 65535, 0 };
1117 GstCaps *in_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1118 GstCaps *out_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, FALSE, TRUE);
1120 RUN_CONVERSION ("3 channels layout remapping int", in, in_caps,
1124 /* int with 8 channels (= largest number allowed with channel positions) */
1126 guint16 in[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
1127 guint16 out[] = { 4, 0, 1, 6, 7, 2, 3, 5 };
1128 GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1129 GstCaps *out_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, TRUE);
1131 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1132 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1134 RUN_CONVERSION ("8 channels layout remapping int", in, in_caps,
1138 /* int16 to int32 with 8 channels (= largest number allowed with channel positions) */
1140 guint16 in[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
1142 { 4 << 16, 0, 1 << 16, 6 << 16, 7 << 16, 2 << 16, 3 << 16, 5 << 16 };
1143 GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1144 GstCaps *out_caps = get_int_mc_caps (8, "BYTE_ORDER", 32, 32, FALSE, TRUE);
1146 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1147 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1149 RUN_CONVERSION ("8 channels layout remapping int16 --> int32", in, in_caps,
1152 in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1153 out_caps = get_int_mc_caps (8, "BYTE_ORDER", 32, 32, FALSE, TRUE);
1154 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1155 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1156 RUN_CONVERSION ("8 channels layout remapping int16 <-- int32", out,
1157 out_caps, in, in_caps);
1160 /* float to gint16 with 3 channels */
1162 gfloat in[] = { 100.0 / G_MAXINT16, 0.0, -100.0 / G_MAXINT16 };
1163 gint16 out[] = { -100, 0, 100 };
1164 GstCaps *in_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, TRUE);
1165 GstCaps *out_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1167 RUN_CONVERSION ("3 channels layout remapping float32 --> int16", in,
1168 in_caps, out, out_caps);
1171 /* gint16 to gint16 with 2 channels and non-standard layout */
1173 gint16 in[] = { 1, 2, 3, 4 };
1174 gint16 out[] = { 1, 2, 2, 4 };
1175 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1176 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1177 GstAudioChannelPosition in_layout[2] =
1178 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1179 GST_AUDIO_CHANNEL_POSITION_LFE
1181 GstAudioChannelPosition out_layout[2] =
1182 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1183 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1186 set_channel_positions (in_caps, 2, in_layout);
1187 set_channel_positions (out_caps, 2, out_layout);
1189 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1190 in_caps, out, out_caps);
1193 /* gint16 to gint16 with 2 channels and non-standard layout */
1195 gint16 in[] = { 1, 2, 3, 4 };
1196 gint16 out[] = { 2, 1, 4, 3 };
1197 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1198 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1199 GstAudioChannelPosition in_layout[2] =
1200 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1201 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
1203 GstAudioChannelPosition out_layout[2] =
1204 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1205 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1208 set_channel_positions (in_caps, 2, in_layout);
1209 set_channel_positions (out_caps, 2, out_layout);
1211 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1212 in_caps, out, out_caps);
1215 /* gint16 to gint16 with 2 channels and non-standard layout */
1217 gint16 in[] = { 1, 2, 3, 4 };
1218 gint16 out[] = { 1, 1, 3, 3 };
1219 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1220 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1221 GstAudioChannelPosition in_layout[2] =
1222 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1223 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER
1225 GstAudioChannelPosition out_layout[2] =
1226 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1227 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1230 set_channel_positions (in_caps, 2, in_layout);
1231 set_channel_positions (out_caps, 2, out_layout);
1233 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1234 in_caps, out, out_caps);
1237 /* gint16 to gint16 with 1 channel and non-standard layout */
1239 gint16 in[] = { 1, 2, 3, 4 };
1240 gint16 out[] = { 0, 0, 0, 0 };
1241 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1242 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1243 GstAudioChannelPosition in_layout[1] =
1244 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT };
1245 GstAudioChannelPosition out_layout[1] =
1246 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT };
1248 set_channel_positions (in_caps, 1, in_layout);
1249 set_channel_positions (out_caps, 1, out_layout);
1251 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1252 in_caps, out, out_caps);
1255 /* gint16 to gint16 with 1 channel and non-standard layout */
1257 gint16 in[] = { 1, 2, 3, 4 };
1258 gint16 out[] = { 1, 2, 3, 4 };
1259 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1260 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1261 GstAudioChannelPosition in_layout[1] =
1262 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1263 GstAudioChannelPosition out_layout[1] =
1264 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER };
1266 set_channel_positions (in_caps, 1, in_layout);
1267 set_channel_positions (out_caps, 1, out_layout);
1269 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1270 in_caps, out, out_caps);
1273 /* gint16 to gint16 with 1 channel and non-standard layout */
1275 gint16 in[] = { 1, 2, 3, 4 };
1276 gint16 out[] = { 1, 2, 3, 4 };
1277 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1278 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1279 GstAudioChannelPosition in_layout[1] =
1280 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1281 GstAudioChannelPosition out_layout[1] =
1282 { GST_AUDIO_CHANNEL_POSITION_REAR_LEFT };
1284 set_channel_positions (in_caps, 1, in_layout);
1285 set_channel_positions (out_caps, 1, out_layout);
1287 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1288 in_caps, out, out_caps);
1294 GST_START_TEST (test_caps_negotiation)
1296 GstElement *src, *ac1, *ac2, *ac3, *sink;
1297 GstElement *pipeline;
1299 GstCaps *caps1, *caps2;
1301 pipeline = gst_pipeline_new ("test");
1303 /* create elements */
1304 src = gst_element_factory_make ("audiotestsrc", "src");
1305 ac1 = gst_element_factory_make ("audioconvert", "ac1");
1306 ac2 = gst_element_factory_make ("audioconvert", "ac2");
1307 ac3 = gst_element_factory_make ("audioconvert", "ac3");
1308 sink = gst_element_factory_make ("fakesink", "sink");
1309 ac3_src = gst_element_get_static_pad (ac3, "src");
1311 /* test with 2 audioconvert elements */
1312 gst_bin_add_many (GST_BIN (pipeline), src, ac1, ac3, sink, NULL);
1313 gst_element_link_many (src, ac1, ac3, sink, NULL);
1315 /* Set to PAUSED and wait for PREROLL */
1316 fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) ==
1317 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline to PAUSED");
1318 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1319 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline to PAUSED");
1321 caps1 = gst_pad_get_caps (ac3_src, NULL);
1322 fail_if (caps1 == NULL, "gst_pad_get_caps returned NULL");
1323 GST_DEBUG ("Caps size 1 : %d", gst_caps_get_size (caps1));
1325 fail_if (gst_element_set_state (pipeline, GST_STATE_READY) ==
1326 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to READY");
1327 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1328 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to READY");
1330 /* test with 3 audioconvert elements */
1331 gst_element_unlink (ac1, ac3);
1332 gst_bin_add (GST_BIN (pipeline), ac2);
1333 gst_element_link_many (ac1, ac2, ac3, NULL);
1335 fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) ==
1336 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to PAUSED");
1337 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1338 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to PAUSED");
1340 caps2 = gst_pad_get_caps (ac3_src, NULL);
1342 fail_if (caps2 == NULL, "gst_pad_get_caps returned NULL");
1343 GST_DEBUG ("Caps size 2 : %d", gst_caps_get_size (caps2));
1344 fail_unless (gst_caps_get_size (caps1) == gst_caps_get_size (caps2));
1346 gst_caps_unref (caps1);
1347 gst_caps_unref (caps2);
1349 fail_if (gst_element_set_state (pipeline, GST_STATE_NULL) ==
1350 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to NULL");
1351 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1352 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to NULL");
1354 gst_object_unref (ac3_src);
1355 gst_object_unref (pipeline);
1360 GST_START_TEST (test_convert_undefined_multichannel)
1362 /* (A) CONVERSION FROM 'WORSE' TO 'BETTER' FORMAT */
1364 /* 1 channel, NONE positions, int8 => int16 */
1366 guint16 out[] = { 0x2000 };
1367 guint8 in[] = { 0x20 };
1368 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1369 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1371 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1372 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1374 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1375 "int8 => int16", in, in_caps, out, out_caps);
1378 /* 2 channels, NONE positions, int8 => int16 */
1380 guint16 out[] = { 0x8000, 0x2000 };
1381 guint8 in[] = { 0x80, 0x20 };
1382 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1383 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1385 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1386 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1388 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1389 "int8 => int16", in, in_caps, out, out_caps);
1392 /* 6 channels, NONE positions, int8 => int16 */
1394 guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1395 guint8 in[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff };
1396 GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1397 GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1399 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1400 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1402 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1403 "int8 => int16", in, in_caps, out, out_caps);
1406 /* 9 channels, NONE positions, int8 => int16 */
1408 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1409 0x0000, 0xff00, 0x0000
1411 guint8 in[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 };
1412 GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1413 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1415 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1416 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1418 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1419 "int8 => int16", in, in_caps, out, out_caps);
1422 /* 15 channels, NONE positions, int8 => int16 */
1425 { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00,
1426 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000
1429 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1430 0x20, 0x80, 0x20, 0x00
1433 get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1434 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1436 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1437 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1439 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1440 "int8 => int16", in, in_caps, out, out_caps);
1443 /* (B) CONVERSION FROM 'BETTER' TO 'WORSE' FORMAT */
1445 /* 1 channel, NONE positions, int16 => int8 */
1447 guint16 in[] = { 0x2000 };
1448 guint8 out[] = { 0x20 };
1449 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1450 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1452 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1453 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1455 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1456 "int16 => int8", in, in_caps, out, out_caps);
1459 /* 2 channels, NONE positions, int16 => int8 */
1461 guint16 in[] = { 0x8000, 0x2000 };
1462 guint8 out[] = { 0x80, 0x20 };
1463 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1464 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1466 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1467 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1469 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1470 "int16 => int8", in, in_caps, out, out_caps);
1473 /* 6 channels, NONE positions, int16 => int8 */
1475 guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1476 guint8 out[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff };
1477 GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1478 GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1480 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1481 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1483 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1484 "int16 => int8", in, in_caps, out, out_caps);
1487 /* 9 channels, NONE positions, int16 => int8 */
1489 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1490 0x0000, 0xff00, 0x0000
1492 guint8 out[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 };
1493 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1494 GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1496 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1497 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1499 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1500 "int16 => int8", in, in_caps, out, out_caps);
1503 /* 15 channels, NONE positions, int16 => int8 */
1505 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1506 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1510 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1511 0x20, 0x80, 0x20, 0x00
1513 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1514 GstCaps *out_caps = get_int_mc_caps (15, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1516 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1517 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1519 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1520 "int16 => int8", in, in_caps, out, out_caps);
1524 /* (C) NO CONVERSION, SAME FORMAT */
1526 /* 1 channel, NONE positions, int16 => int16 */
1528 guint16 in[] = { 0x2000 };
1529 guint16 out[] = { 0x2000 };
1530 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1531 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1533 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1534 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1536 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1537 "int16 => int16", in, in_caps, out, out_caps);
1540 /* 2 channels, NONE positions, int16 => int16 */
1542 guint16 in[] = { 0x8000, 0x2000 };
1543 guint16 out[] = { 0x8000, 0x2000 };
1544 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1545 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1547 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1548 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1550 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1551 "int16 => int16", in, in_caps, out, out_caps);
1554 /* 6 channels, NONE positions, int16 => int16 */
1556 guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1557 guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1558 GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1559 GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1561 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1562 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1564 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1565 "int16 => int16", in, in_caps, out, out_caps);
1568 /* 9 channels, NONE positions, int16 => int16 */
1570 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1571 0x0000, 0xff00, 0x0000
1573 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1574 0x0000, 0xff00, 0x0000
1576 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1577 GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1579 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1580 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1582 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1583 "int16 => int16", in, in_caps, out, out_caps);
1586 /* 15 channels, NONE positions, int16 => int16 */
1588 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1589 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1592 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1593 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1596 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1598 get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1600 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1601 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1603 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1604 "int16 => int16", in, in_caps, out, out_caps);
1608 /* (C) int16 => float */
1610 /* 9 channels, NONE positions, int16 => float */
1612 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1613 0x0000, 0x8000, 0x0000
1615 gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 };
1616 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1617 GstCaps *out_caps = get_float_mc_caps (9, "BYTE_ORDER", 32, FALSE);
1619 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1620 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1622 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1623 "int16 => float", in, in_caps, out, out_caps);
1626 /* 15 channels, NONE positions, int16 => float */
1628 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1629 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1633 { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 0.0, -1.0, 0.0, 0.0,
1636 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1637 GstCaps *out_caps = get_float_mc_caps (15, "BYTE_ORDER", 32, FALSE);
1639 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1640 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1642 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1643 "int16 => float", in, in_caps, out, out_caps);
1647 /* 9 channels, NONE positions, int16 => float (same as above, but no
1648 * position on output caps to see if audioconvert transforms correctly) */
1650 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1651 0x0000, 0x8000, 0x0000
1653 gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 };
1654 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1655 GstCaps *out_caps = get_float_mc_caps (9, "BYTE_ORDER", 32, FALSE);
1657 //set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1658 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1660 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1661 "int16 => float", in, in_caps, out, out_caps);
1664 /* 15 channels, NONE positions, int16 => float (same as above, but no
1665 * position on output caps to see if audioconvert transforms correctly) */
1667 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1668 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1672 { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 0.0, -1.0, 0.0, 0.0,
1675 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1676 GstCaps *out_caps = get_float_mc_caps (15, "BYTE_ORDER", 32, FALSE);
1678 //set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1679 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1681 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1682 "int16 => float", in, in_caps, out, out_caps);
1685 /* 8 channels, NONE positions => 2 channels: should fail, no mixing allowed */
1687 guint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1688 gfloat out[] = { -1.0, -1.0 };
1689 GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1690 GstCaps *out_caps = get_float_mc_caps (2, "BYTE_ORDER", 32, FALSE);
1692 set_channel_positions (in_caps, 8, undefined_positions[8 - 1]);
1694 RUN_CONVERSION_TO_FAIL ("8 channels with layout => 2 channels",
1695 in, in_caps, out, out_caps);
1698 /* 8 channels, with positions => 2 channels (makes sure channel-position
1699 * fields are removed properly in some cases in ::transform_caps, so we
1700 * don't up with caps with 2 channels and 8 channel positions) */
1702 GstAudioChannelPosition layout8ch[] = {
1703 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1704 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1705 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1706 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1707 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1708 GST_AUDIO_CHANNEL_POSITION_LFE,
1709 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1710 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
1712 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1713 gint16 out[] = { 0, 0 };
1714 GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1715 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1717 set_channel_positions (in_caps, 8, layout8ch);
1719 RUN_CONVERSION ("8 channels with layout => 2 channels",
1720 in, in_caps, out, out_caps);
1727 audioconvert_suite (void)
1729 Suite *s = suite_create ("audioconvert");
1730 TCase *tc_chain = tcase_create ("general");
1732 suite_add_tcase (s, tc_chain);
1733 tcase_add_test (tc_chain, test_int16);
1734 tcase_add_test (tc_chain, test_float32);
1735 tcase_add_test (tc_chain, test_int_conversion);
1736 tcase_add_test (tc_chain, test_float_conversion);
1737 tcase_add_test (tc_chain, test_multichannel_conversion);
1738 tcase_add_test (tc_chain, test_channel_remapping);
1739 tcase_add_test (tc_chain, test_caps_negotiation);
1740 tcase_add_test (tc_chain, test_convert_undefined_multichannel);
1745 GST_CHECK_MAIN (audioconvert);