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);
96 gst_pad_set_caps (mysinkpad, outcaps);
97 gst_caps_unref (outcaps);
98 outcaps = gst_pad_get_negotiated_caps (mysinkpad);
99 fail_unless (gst_caps_is_fixed (outcaps));
100 gst_caps_unref (outcaps);
102 gst_pad_set_active (mysrcpad, TRUE);
103 gst_pad_set_active (mysinkpad, TRUE);
109 cleanup_audioconvert (GstElement * audioconvert)
111 GST_DEBUG ("cleanup_audioconvert");
113 gst_pad_set_active (mysrcpad, FALSE);
114 gst_pad_set_active (mysinkpad, FALSE);
115 gst_check_teardown_src_pad (audioconvert);
116 gst_check_teardown_sink_pad (audioconvert);
117 gst_check_teardown_element (audioconvert);
120 /* returns a newly allocated caps */
122 get_int_caps (guint channels, const gchar * endianness, guint width,
123 guint depth, gboolean signedness)
128 string = g_strdup_printf ("audio/x-raw-int, "
129 "rate = (int) 44100, "
130 "channels = (int) %d, "
131 "endianness = (int) %s, "
134 "signed = (boolean) %s ",
135 channels, endianness, width, depth, signedness ? "true" : "false");
136 GST_DEBUG ("creating caps from %s", string);
137 caps = gst_caps_from_string (string);
139 fail_unless (caps != NULL);
140 GST_DEBUG ("returning caps %p", caps);
144 /* returns a newly allocated caps */
146 get_float_caps (guint channels, const gchar * endianness, guint width)
151 string = g_strdup_printf ("audio/x-raw-float, "
152 "rate = (int) 44100, "
153 "channels = (int) %d, "
154 "endianness = (int) %s, "
155 "width = (int) %d ", channels, endianness, width);
156 GST_DEBUG ("creating caps from %s", string);
157 caps = gst_caps_from_string (string);
159 fail_unless (caps != NULL);
160 GST_DEBUG ("returning caps %p", caps);
164 /* Copied from vorbis; the particular values used don't matter */
165 static GstAudioChannelPosition channelpositions[][6] = {
167 GST_AUDIO_CHANNEL_POSITION_FRONT_MONO},
169 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
170 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
171 { /* Stereo + Centre */
172 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
173 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
174 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
176 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
177 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
178 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
179 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
181 { /* Stereo + Centre + rear stereo */
182 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
183 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
184 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
185 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
186 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
188 { /* Full 5.1 Surround */
189 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
190 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
191 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
192 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
193 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
194 GST_AUDIO_CHANNEL_POSITION_LFE,
198 /* these are a bunch of random positions, they are mostly just
199 * different from the ones above, don't use elsewhere */
200 static GstAudioChannelPosition mixed_up_positions[][6] = {
202 GST_AUDIO_CHANNEL_POSITION_FRONT_MONO},
204 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
205 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT},
207 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
208 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
209 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT},
211 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
212 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
213 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
214 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
217 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
218 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
219 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
220 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
221 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
224 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
225 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
226 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
227 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
228 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
229 GST_AUDIO_CHANNEL_POSITION_LFE,
233 /* we get this when recording from a soundcard with lots of input channels */
234 static GstAudioChannelPosition undefined_positions[][15] = {
236 GST_AUDIO_CHANNEL_POSITION_NONE},
238 GST_AUDIO_CHANNEL_POSITION_NONE,
239 GST_AUDIO_CHANNEL_POSITION_NONE},
241 GST_AUDIO_CHANNEL_POSITION_NONE,
242 GST_AUDIO_CHANNEL_POSITION_NONE,
243 GST_AUDIO_CHANNEL_POSITION_NONE},
245 GST_AUDIO_CHANNEL_POSITION_NONE,
246 GST_AUDIO_CHANNEL_POSITION_NONE,
247 GST_AUDIO_CHANNEL_POSITION_NONE,
248 GST_AUDIO_CHANNEL_POSITION_NONE},
250 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},
256 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},
263 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},
271 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},
280 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},
290 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},
301 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},
313 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},
326 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},
340 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},
355 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}
373 set_channel_positions (GstCaps * caps, int channels,
374 GstAudioChannelPosition * channelpositions)
376 GValue chanpos = { 0 };
378 GstStructure *structure = gst_caps_get_structure (caps, 0);
381 g_value_init (&chanpos, GST_TYPE_ARRAY);
382 g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
384 for (c = 0; c < channels; c++) {
385 g_value_set_enum (&pos, channelpositions[c]);
386 gst_value_array_append_value (&chanpos, &pos);
388 g_value_unset (&pos);
390 gst_structure_set_value (structure, "channel-positions", &chanpos);
391 g_value_unset (&chanpos);
394 /* For channels > 2, caps have to have channel positions. This adds some simple
395 * ones. Only implemented for channels between 1 and 6.
398 get_float_mc_caps (guint channels, const gchar * endianness, guint width,
399 gboolean mixed_up_layout)
401 GstCaps *caps = get_float_caps (channels, endianness, width);
405 set_channel_positions (caps, channels, mixed_up_positions[channels - 1]);
407 set_channel_positions (caps, channels, channelpositions[channels - 1]);
414 get_int_mc_caps (guint channels, const gchar * endianness, guint width,
415 guint depth, gboolean signedness, gboolean mixed_up_layout)
417 GstCaps *caps = get_int_caps (channels, endianness, width, depth, signedness);
421 set_channel_positions (caps, channels, mixed_up_positions[channels - 1]);
423 set_channel_positions (caps, channels, channelpositions[channels - 1]);
429 /* eats the refs to the caps */
431 verify_convert (const gchar * which, void *in, int inlength,
432 GstCaps * incaps, void *out, int outlength, GstCaps * outcaps,
433 GstFlowReturn expected_flow)
435 GstBuffer *inbuffer, *outbuffer;
436 GstElement *audioconvert;
438 GST_DEBUG ("verifying conversion %s", which);
439 GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps);
440 GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps);
441 ASSERT_CAPS_REFCOUNT (incaps, "incaps", 1);
442 ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1);
443 audioconvert = setup_audioconvert (outcaps);
444 ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1);
446 fail_unless (gst_element_set_state (audioconvert,
447 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
448 "could not set to playing");
450 GST_DEBUG ("Creating buffer of %d bytes", inlength);
451 inbuffer = gst_buffer_new_and_alloc (inlength);
452 memcpy (GST_BUFFER_DATA (inbuffer), in, inlength);
453 gst_buffer_set_caps (inbuffer, incaps);
454 ASSERT_CAPS_REFCOUNT (incaps, "incaps", 2);
455 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
457 /* pushing gives away my reference ... */
458 GST_DEBUG ("push it");
459 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), expected_flow);
460 GST_DEBUG ("pushed it");
462 if (expected_flow != GST_FLOW_OK)
465 /* ... and puts a new buffer on the global list */
466 fail_unless (g_list_length (buffers) == 1);
467 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
469 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
470 fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), outlength);
472 if (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) != 0) {
473 g_print ("\nInput data:\n");
474 gst_util_dump_mem (in, inlength);
475 g_print ("\nConverted data:\n");
476 gst_util_dump_mem (GST_BUFFER_DATA (outbuffer), outlength);
477 g_print ("\nExpected data:\n");
478 gst_util_dump_mem (out, outlength);
480 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) == 0,
481 "failed converting %s", which);
483 /* make sure that the channel positions are not lost */
485 GstStructure *in_s, *out_s;
488 in_s = gst_caps_get_structure (incaps, 0);
489 out_s = gst_caps_get_structure (GST_BUFFER_CAPS (outbuffer), 0);
490 fail_unless (gst_structure_get_int (out_s, "channels", &out_chans));
492 /* positions for 1 and 2 channels are implicit if not provided */
493 if (out_chans > 2 && gst_structure_has_field (in_s, "channel-positions")) {
494 if (!gst_structure_has_field (out_s, "channel-positions")) {
495 g_error ("Channel layout got lost somewhere:\n\nIns : %s\nOuts: %s\n",
496 gst_structure_to_string (in_s), gst_structure_to_string (out_s));
501 buffers = g_list_remove (buffers, outbuffer);
502 gst_buffer_unref (outbuffer);
505 fail_unless (gst_element_set_state (audioconvert,
506 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
508 GST_DEBUG ("cleanup audioconvert");
509 cleanup_audioconvert (audioconvert);
510 GST_DEBUG ("cleanup, unref incaps");
511 ASSERT_CAPS_REFCOUNT (incaps, "incaps", 1);
512 gst_caps_unref (incaps);
516 #define RUN_CONVERSION(which, inarray, in_get_caps, outarray, out_get_caps) \
517 verify_convert (which, inarray, sizeof (inarray), \
518 in_get_caps, outarray, sizeof (outarray), out_get_caps, GST_FLOW_OK)
520 #define RUN_CONVERSION_TO_FAIL(which, inarray, in_caps, outarray, out_caps) \
521 verify_convert (which, inarray, sizeof (inarray), \
522 in_caps, outarray, sizeof (outarray), out_caps, GST_FLOW_NOT_NEGOTIATED)
525 GST_START_TEST (test_int16)
529 gint16 in[] = { 16384, -256, 1024, 1024 };
530 gint16 out[] = { 8064, 1024 };
532 RUN_CONVERSION ("int16 stereo to mono",
533 in, get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE),
534 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
538 gint16 in[] = { 512, 1024 };
539 gint16 out[] = { 512, 512, 1024, 1024 };
541 RUN_CONVERSION ("int16 mono to stereo",
542 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
543 out, get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE));
545 /* signed -> unsigned */
547 gint16 in[] = { 0, -32767, 32767, -32768 };
548 guint16 out[] = { 32768, 1, 65535, 0 };
550 RUN_CONVERSION ("int16 signed to unsigned",
551 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
552 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE));
553 RUN_CONVERSION ("int16 unsigned to signed",
554 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE),
555 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
562 GST_START_TEST (test_float32)
566 gfloat in[] = { 0.6, -0.0078125, 0.03125, 0.03125 };
567 gfloat out[] = { 0.29609375, 0.03125 };
569 RUN_CONVERSION ("float32 stereo to mono",
570 in, get_float_caps (2, "BYTE_ORDER", 32),
571 out, get_float_caps (1, "BYTE_ORDER", 32));
575 gfloat in[] = { 0.015625, 0.03125 };
576 gfloat out[] = { 0.015625, 0.015625, 0.03125, 0.03125 };
578 RUN_CONVERSION ("float32 mono to stereo",
579 in, get_float_caps (1, "BYTE_ORDER", 32),
580 out, get_float_caps (2, "BYTE_ORDER", 32));
587 GST_START_TEST (test_int_conversion)
589 /* 8 <-> 16 signed */
590 /* NOTE: if audioconvert was doing dithering we'd have a problem */
592 gint8 in[] = { 0, 1, 2, 127, -127 };
593 gint16 out[] = { 0, 256, 512, 32512, -32512 };
595 RUN_CONVERSION ("int 8bit to 16bit signed",
596 in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE),
597 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)
599 RUN_CONVERSION ("int 16bit signed to 8bit",
600 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
601 in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE)
606 gint16 in[] = { 0, 127, 128, 256, 256 + 127, 256 + 128 };
607 gint8 out[] = { 0, 0, 1, 1, 1, 2 };
609 RUN_CONVERSION ("16 bit to 8 signed",
610 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
611 out, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE)
614 /* 8 unsigned <-> 16 signed */
615 /* NOTE: if audioconvert was doing dithering we'd have a problem */
617 guint8 in[] = { 128, 129, 130, 255, 1 };
618 gint16 out[] = { 0, 256, 512, 32512, -32512 };
619 GstCaps *incaps, *outcaps;
621 /* exploded for easier valgrinding */
622 incaps = get_int_caps (1, "BYTE_ORDER", 8, 8, FALSE);
623 outcaps = get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE);
624 GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps);
625 GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps);
626 RUN_CONVERSION ("8 unsigned to 16 signed", in, incaps, out, outcaps);
627 RUN_CONVERSION ("16 signed to 8 unsigned", out, get_int_caps (1,
628 "BYTE_ORDER", 16, 16, TRUE), in, get_int_caps (1, "BYTE_ORDER", 8,
632 /* 8 <-> 24 signed */
633 /* NOTE: if audioconvert was doing dithering we'd have a problem */
635 gint8 in[] = { 0, 1, 127 };
636 guint8 out[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x7f };
637 /* out has the bytes in little-endian, so that's how they should be
638 * interpreted during conversion */
640 RUN_CONVERSION ("8 to 24 signed", in, get_int_caps (1, "BYTE_ORDER", 8, 8,
641 TRUE), out, get_int_caps (1, "LITTLE_ENDIAN", 24, 24, TRUE)
643 RUN_CONVERSION ("24 signed to 8", out, get_int_caps (1, "LITTLE_ENDIAN", 24,
644 24, TRUE), in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE)
648 /* 16 bit signed <-> unsigned */
650 gint16 in[] = { 0, 128, -128 };
651 guint16 out[] = { 32768, 32896, 32640 };
652 RUN_CONVERSION ("16 signed to 16 unsigned",
653 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
654 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE)
656 RUN_CONVERSION ("16 unsigned to 16 signed",
657 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE),
658 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)
662 /* 16 bit signed <-> 8 in 16 bit signed */
663 /* NOTE: if audioconvert was doing dithering we'd have a problem */
665 gint16 in[] = { 0, 64 << 8, -64 << 8 };
666 gint16 out[] = { 0, 64, -64 };
667 RUN_CONVERSION ("16 signed to 8 in 16 signed",
668 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
669 out, get_int_caps (1, "BYTE_ORDER", 16, 8, TRUE)
671 RUN_CONVERSION ("8 in 16 signed to 16 signed",
672 out, get_int_caps (1, "BYTE_ORDER", 16, 8, TRUE),
673 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)
677 /* 16 bit unsigned <-> 8 in 16 bit unsigned */
678 /* NOTE: if audioconvert was doing dithering we'd have a problem */
680 guint16 in[] = { 1 << 15, (1 << 15) - (64 << 8), (1 << 15) + (64 << 8) };
681 guint16 out[] = { 1 << 7, (1 << 7) - 64, (1 << 7) + 64 };
682 RUN_CONVERSION ("16 unsigned to 8 in 16 unsigned",
683 in, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE),
684 out, get_int_caps (1, "BYTE_ORDER", 16, 8, FALSE)
686 RUN_CONVERSION ("8 in 16 unsigned to 16 unsigned",
687 out, get_int_caps (1, "BYTE_ORDER", 16, 8, FALSE),
688 in, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE)
692 /* 32 bit signed -> 16 bit signed for rounding check */
693 /* NOTE: if audioconvert was doing dithering we'd have a problem */
695 gint32 in[] = { 0, G_MININT32, G_MAXINT32,
696 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
697 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
698 (-32 << 16) + (1 << 15), (-32 << 16) - (1 << 15),
699 (-32 << 16) + (2 << 15), (-32 << 16) - (2 << 15),
702 gint16 out[] = { 0, G_MININT16, G_MAXINT16,
709 RUN_CONVERSION ("32 signed to 16 signed for rounding",
710 in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE),
711 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)
715 /* 32 bit signed -> 16 bit unsigned for rounding check */
716 /* NOTE: if audioconvert was doing dithering we'd have a problem */
718 gint32 in[] = { 0, G_MININT32, G_MAXINT32,
719 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
720 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
721 (-32 << 16) + (1 << 15), (-32 << 16) - (1 << 15),
722 (-32 << 16) + (2 << 15), (-32 << 16) - (2 << 15),
725 guint16 out[] = { (1 << 15), 0, G_MAXUINT16,
726 (1 << 15) + 32, (1 << 15) + 33, (1 << 15) + 32,
727 (1 << 15) + 33, (1 << 15) + 31,
728 (1 << 15) - 31, (1 << 15) - 32,
729 (1 << 15) - 31, (1 << 15) - 33,
732 RUN_CONVERSION ("32 signed to 16 unsigned for rounding",
733 in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE),
734 out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE)
741 GST_START_TEST (test_float_conversion)
743 /* 32 float <-> 16 signed */
744 /* NOTE: if audioconvert was doing dithering we'd have a problem */
747 { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0),
748 GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5), GFLOAT_TO_LE (1.1),
752 { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0),
753 GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5), GFLOAT_TO_BE (1.1),
756 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
758 /* only one direction conversion, the other direction does
759 * not produce exactly the same as the input due to floating
760 * point rounding errors etc. */
761 RUN_CONVERSION ("32 float le to 16 signed",
762 in_le, get_float_caps (1, "LITTLE_ENDIAN", 32),
763 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
764 RUN_CONVERSION ("32 float be to 16 signed",
765 in_be, get_float_caps (1, "BIG_ENDIAN", 32),
766 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
770 gint16 in[] = { 0, -32768, 16384, -16384 };
771 gfloat out[] = { 0.0, -1.0, 0.5, -0.5 };
773 RUN_CONVERSION ("16 signed to 32 float",
774 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
775 out, get_float_caps (1, "BYTE_ORDER", 32));
778 /* 64 float <-> 16 signed */
779 /* NOTE: if audioconvert was doing dithering we'd have a problem */
782 { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0),
783 GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5), GDOUBLE_TO_LE (1.1),
787 { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0),
788 GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5), GDOUBLE_TO_BE (1.1),
791 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
793 /* only one direction conversion, the other direction does
794 * not produce exactly the same as the input due to floating
795 * point rounding errors etc. */
796 RUN_CONVERSION ("64 float LE to 16 signed",
797 in_le, get_float_caps (1, "LITTLE_ENDIAN", 64),
798 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
799 RUN_CONVERSION ("64 float BE to 16 signed",
800 in_be, get_float_caps (1, "BIG_ENDIAN", 64),
801 out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE));
804 gint16 in[] = { 0, -32768, 16384, -16384 };
805 gdouble out[] = { 0.0,
806 (gdouble) (-32768L << 16) / 2147483647.0, /* ~ -1.0 */
807 (gdouble) (16384L << 16) / 2147483647.0, /* ~ 0.5 */
808 (gdouble) (-16384L << 16) / 2147483647.0, /* ~ -0.5 */
811 RUN_CONVERSION ("16 signed to 64 float",
812 in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE),
813 out, get_float_caps (1, "BYTE_ORDER", 64));
816 gint32 in[] = { 0, (-1L << 31), (1L << 30), (-1L << 30) };
817 gdouble out[] = { 0.0,
818 (gdouble) (-1L << 31) / 2147483647.0, /* ~ -1.0 */
819 (gdouble) (1L << 30) / 2147483647.0, /* ~ 0.5 */
820 (gdouble) (-1L << 30) / 2147483647.0, /* ~ -0.5 */
823 RUN_CONVERSION ("32 signed to 64 float",
824 in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE),
825 out, get_float_caps (1, "BYTE_ORDER", 64));
828 /* 64-bit float <-> 32-bit float */
830 gdouble in[] = { 0.0, 1.0, -1.0, 0.5, -0.5 };
831 gfloat out[] = { 0.0, 1.0, -1.0, 0.5, -0.5 };
833 RUN_CONVERSION ("64 float to 32 float",
834 in, get_float_caps (1, "BYTE_ORDER", 64),
835 out, get_float_caps (1, "BYTE_ORDER", 32));
837 RUN_CONVERSION ("32 float to 64 float",
838 out, get_float_caps (1, "BYTE_ORDER", 32),
839 in, get_float_caps (1, "BYTE_ORDER", 64));
842 /* 32-bit float little endian <-> big endian */
844 gfloat le[] = { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0),
845 GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5)
847 gfloat be[] = { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0),
848 GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5)
851 RUN_CONVERSION ("32 float LE to BE",
852 le, get_float_caps (1, "LITTLE_ENDIAN", 32),
853 be, get_float_caps (1, "BIG_ENDIAN", 32));
855 RUN_CONVERSION ("32 float BE to LE",
856 be, get_float_caps (1, "BIG_ENDIAN", 32),
857 le, get_float_caps (1, "LITTLE_ENDIAN", 32));
860 /* 64-bit float little endian <-> big endian */
863 { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0),
864 GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5)
867 { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0),
868 GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5)
871 RUN_CONVERSION ("64 float LE to BE",
872 le, get_float_caps (1, "LITTLE_ENDIAN", 64),
873 be, get_float_caps (1, "BIG_ENDIAN", 64));
875 RUN_CONVERSION ("64 float BE to LE",
876 be, get_float_caps (1, "BIG_ENDIAN", 64),
877 le, get_float_caps (1, "LITTLE_ENDIAN", 64));
884 GST_START_TEST (test_multichannel_conversion)
887 gfloat in[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
888 gfloat out[] = { 0.0, 0.0 };
890 RUN_CONVERSION ("3 channels to 1", in, get_float_mc_caps (3,
891 "BYTE_ORDER", 32, FALSE), out, get_float_caps (1, "BYTE_ORDER",
893 RUN_CONVERSION ("1 channels to 3", out, get_float_caps (1,
894 "BYTE_ORDER", 32), in, get_float_mc_caps (3, "BYTE_ORDER",
899 gint16 in[] = { 0, 0, 0, 0, 0, 0 };
900 gint16 out[] = { 0, 0 };
902 RUN_CONVERSION ("3 channels to 1", in, get_int_mc_caps (3,
903 "BYTE_ORDER", 16, 16, TRUE, FALSE), out, get_int_caps (1,
904 "BYTE_ORDER", 16, 16, TRUE));
905 RUN_CONVERSION ("1 channels to 3", out, get_int_caps (1, "BYTE_ORDER", 16,
906 16, TRUE), in, get_int_mc_caps (3, "BYTE_ORDER", 16, 16, TRUE,
911 gint16 in[] = { 1, 2 };
912 gint16 out[] = { 1, 1, 2, 2 };
913 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
914 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
915 GstAudioChannelPosition in_layout[1] =
916 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
917 GstAudioChannelPosition out_layout[2] =
918 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
919 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
922 set_channel_positions (in_caps, 1, in_layout);
923 set_channel_positions (out_caps, 2, out_layout);
925 RUN_CONVERSION ("1 channels to 2 with standard layout", in,
926 in_caps, out, out_caps);
930 gint16 in[] = { 1, 2 };
931 gint16 out[] = { 1, 1, 2, 2 };
932 GstCaps *in_caps = get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE);
933 GstCaps *out_caps = get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE);
935 RUN_CONVERSION ("1 channels to 2 with standard layout and no positions set",
936 in, gst_caps_copy (in_caps), out, gst_caps_copy (out_caps));
938 RUN_CONVERSION ("2 channels to 1 with standard layout and no positions set",
939 out, out_caps, in, in_caps);
943 gint16 in[] = { 1, 2 };
944 gint16 out[] = { 1, 0, 2, 0 };
945 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
946 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
947 GstAudioChannelPosition in_layout[1] =
948 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT };
949 GstAudioChannelPosition out_layout[2] =
950 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
951 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
954 set_channel_positions (in_caps, 1, in_layout);
955 set_channel_positions (out_caps, 2, out_layout);
957 RUN_CONVERSION ("1 channels to 2 with non-standard layout", in,
958 in_caps, out, out_caps);
962 gint16 in[] = { 1, 2, 3, 4 };
963 gint16 out[] = { 2, 4 };
964 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
965 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
966 GstAudioChannelPosition in_layout[2] =
967 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
968 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
970 GstAudioChannelPosition out_layout[1] =
971 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER };
973 set_channel_positions (in_caps, 2, in_layout);
974 set_channel_positions (out_caps, 1, out_layout);
976 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
977 in_caps, out, out_caps);
981 gint16 in[] = { 1, 2, 3, 4 };
982 gint16 out[] = { 2, 4 };
983 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
984 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
985 GstAudioChannelPosition in_layout[2] =
986 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
987 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
989 GstAudioChannelPosition out_layout[1] =
990 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
992 set_channel_positions (in_caps, 2, in_layout);
993 set_channel_positions (out_caps, 1, out_layout);
995 RUN_CONVERSION ("2 channels to 1 with standard layout", in,
996 in_caps, out, out_caps);
1000 gint16 in[] = { 1, 2, 3, 4 };
1001 gint16 out[] = { 1, 3 };
1002 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1003 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1004 GstAudioChannelPosition in_layout[2] =
1005 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1006 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER
1008 GstAudioChannelPosition out_layout[1] =
1009 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1011 set_channel_positions (in_caps, 2, in_layout);
1012 set_channel_positions (out_caps, 1, out_layout);
1014 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1015 in_caps, out, out_caps);
1019 gint16 in[] = { 1, 2, 3, 4 };
1020 gint16 out[] = { 1, 3 };
1021 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1022 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1023 GstAudioChannelPosition in_layout[2] =
1024 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1025 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT
1027 GstAudioChannelPosition out_layout[1] =
1028 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1030 set_channel_positions (in_caps, 2, in_layout);
1031 set_channel_positions (out_caps, 1, out_layout);
1033 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1034 in_caps, out, out_caps);
1037 gint16 in[] = { 4, 5, 4, 2, 2, 1 };
1038 gint16 out[] = { 3, 3 };
1039 GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1040 GstCaps *out_caps = get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE);
1042 RUN_CONVERSION ("5.1 to 2 channels", in, in_caps, out, out_caps);
1045 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1046 gint16 out[] = { 0, 0 };
1047 GstCaps *in_caps = get_int_mc_caps (11, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1048 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1049 GstAudioChannelPosition in_layout[11] = {
1050 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1051 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1052 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
1053 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1054 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1055 GST_AUDIO_CHANNEL_POSITION_LFE,
1056 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1057 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
1058 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
1059 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1060 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
1063 set_channel_positions (in_caps, 11, in_layout);
1065 RUN_CONVERSION ("11 channels to 2", in,
1066 gst_caps_copy (in_caps), out, gst_caps_copy (out_caps));
1067 RUN_CONVERSION ("2 channels to 11", out, out_caps, in, in_caps);
1074 /* for testing channel remapping with 8 channels */
1075 static GstAudioChannelPosition n8chan_pos_remap_in[8] = {
1076 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1077 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1078 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1079 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1080 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1081 GST_AUDIO_CHANNEL_POSITION_LFE,
1082 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1083 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
1086 static GstAudioChannelPosition n8chan_pos_remap_out[8] = {
1087 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1088 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1089 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1090 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1091 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
1092 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1093 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1094 GST_AUDIO_CHANNEL_POSITION_LFE
1097 GST_START_TEST (test_channel_remapping)
1101 gfloat in[] = { 0.0, 1.0, -0.5 };
1102 gfloat out[] = { -0.5, 1.0, 0.0 };
1103 GstCaps *in_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, FALSE);
1104 GstCaps *out_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, TRUE);
1106 RUN_CONVERSION ("3 channels layout remapping float", in, in_caps,
1112 guint16 in[] = { 0, 65535, 0x9999 };
1113 guint16 out[] = { 0x9999, 65535, 0 };
1114 GstCaps *in_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1115 GstCaps *out_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, FALSE, TRUE);
1117 RUN_CONVERSION ("3 channels layout remapping int", in, in_caps,
1121 /* int with 8 channels (= largest number allowed with channel positions) */
1123 guint16 in[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
1124 guint16 out[] = { 4, 0, 1, 6, 7, 2, 3, 5 };
1125 GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1126 GstCaps *out_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, TRUE);
1128 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1129 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1131 RUN_CONVERSION ("8 channels layout remapping int", in, in_caps,
1135 /* int16 to int32 with 8 channels (= largest number allowed with channel positions) */
1137 guint16 in[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
1139 { 4 << 16, 0, 1 << 16, 6 << 16, 7 << 16, 2 << 16, 3 << 16, 5 << 16 };
1140 GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1141 GstCaps *out_caps = get_int_mc_caps (8, "BYTE_ORDER", 32, 32, FALSE, TRUE);
1143 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1144 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1146 RUN_CONVERSION ("8 channels layout remapping int16 --> int32", in, in_caps,
1149 in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1150 out_caps = get_int_mc_caps (8, "BYTE_ORDER", 32, 32, FALSE, TRUE);
1151 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1152 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1153 RUN_CONVERSION ("8 channels layout remapping int16 <-- int32", out,
1154 out_caps, in, in_caps);
1157 /* float to gint16 with 3 channels */
1159 gfloat in[] = { 100.0 / G_MAXINT16, 0.0, -100.0 / G_MAXINT16 };
1160 gint16 out[] = { -100, 0, 100 };
1161 GstCaps *in_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, TRUE);
1162 GstCaps *out_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1164 RUN_CONVERSION ("3 channels layout remapping float32 --> int16", in,
1165 in_caps, out, out_caps);
1168 /* gint16 to gint16 with 2 channels and non-standard layout */
1170 gint16 in[] = { 1, 2, 3, 4 };
1171 gint16 out[] = { 1, 2, 2, 4 };
1172 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1173 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1174 GstAudioChannelPosition in_layout[2] =
1175 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1176 GST_AUDIO_CHANNEL_POSITION_LFE
1178 GstAudioChannelPosition out_layout[2] =
1179 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1180 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1183 set_channel_positions (in_caps, 2, in_layout);
1184 set_channel_positions (out_caps, 2, out_layout);
1186 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1187 in_caps, out, out_caps);
1190 /* gint16 to gint16 with 2 channels and non-standard layout */
1192 gint16 in[] = { 1, 2, 3, 4 };
1193 gint16 out[] = { 2, 1, 4, 3 };
1194 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1195 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1196 GstAudioChannelPosition in_layout[2] =
1197 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1198 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
1200 GstAudioChannelPosition out_layout[2] =
1201 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1202 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1205 set_channel_positions (in_caps, 2, in_layout);
1206 set_channel_positions (out_caps, 2, out_layout);
1208 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1209 in_caps, out, out_caps);
1212 /* gint16 to gint16 with 2 channels and non-standard layout */
1214 gint16 in[] = { 1, 2, 3, 4 };
1215 gint16 out[] = { 1, 1, 3, 3 };
1216 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1217 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1218 GstAudioChannelPosition in_layout[2] =
1219 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1220 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER
1222 GstAudioChannelPosition out_layout[2] =
1223 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1224 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1227 set_channel_positions (in_caps, 2, in_layout);
1228 set_channel_positions (out_caps, 2, out_layout);
1230 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1231 in_caps, out, out_caps);
1234 /* gint16 to gint16 with 1 channel and non-standard layout */
1236 gint16 in[] = { 1, 2, 3, 4 };
1237 gint16 out[] = { 0, 0, 0, 0 };
1238 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1239 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1240 GstAudioChannelPosition in_layout[1] =
1241 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT };
1242 GstAudioChannelPosition out_layout[1] =
1243 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT };
1245 set_channel_positions (in_caps, 1, in_layout);
1246 set_channel_positions (out_caps, 1, out_layout);
1248 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1249 in_caps, out, out_caps);
1252 /* gint16 to gint16 with 1 channel and non-standard layout */
1254 gint16 in[] = { 1, 2, 3, 4 };
1255 gint16 out[] = { 1, 2, 3, 4 };
1256 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1257 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1258 GstAudioChannelPosition in_layout[1] =
1259 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1260 GstAudioChannelPosition out_layout[1] =
1261 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER };
1263 set_channel_positions (in_caps, 1, in_layout);
1264 set_channel_positions (out_caps, 1, out_layout);
1266 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1267 in_caps, out, out_caps);
1270 /* gint16 to gint16 with 1 channel and non-standard layout */
1272 gint16 in[] = { 1, 2, 3, 4 };
1273 gint16 out[] = { 1, 2, 3, 4 };
1274 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1275 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1276 GstAudioChannelPosition in_layout[1] =
1277 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1278 GstAudioChannelPosition out_layout[1] =
1279 { GST_AUDIO_CHANNEL_POSITION_REAR_LEFT };
1281 set_channel_positions (in_caps, 1, in_layout);
1282 set_channel_positions (out_caps, 1, out_layout);
1284 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1285 in_caps, out, out_caps);
1291 GST_START_TEST (test_caps_negotiation)
1293 GstElement *src, *ac1, *ac2, *ac3, *sink;
1294 GstElement *pipeline;
1296 GstCaps *caps1, *caps2;
1298 pipeline = gst_pipeline_new ("test");
1300 /* create elements */
1301 src = gst_element_factory_make ("audiotestsrc", "src");
1302 ac1 = gst_element_factory_make ("audioconvert", "ac1");
1303 ac2 = gst_element_factory_make ("audioconvert", "ac2");
1304 ac3 = gst_element_factory_make ("audioconvert", "ac3");
1305 sink = gst_element_factory_make ("fakesink", "sink");
1306 ac3_src = gst_element_get_static_pad (ac3, "src");
1308 /* test with 2 audioconvert elements */
1309 gst_bin_add_many (GST_BIN (pipeline), src, ac1, ac3, sink, NULL);
1310 gst_element_link_many (src, ac1, ac3, sink, NULL);
1312 /* Set to PAUSED and wait for PREROLL */
1313 fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) ==
1314 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline to PAUSED");
1315 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1316 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline to PAUSED");
1318 caps1 = gst_pad_get_caps (ac3_src);
1319 fail_if (caps1 == NULL, "gst_pad_get_caps returned NULL");
1320 GST_DEBUG ("Caps size 1 : %d", gst_caps_get_size (caps1));
1322 fail_if (gst_element_set_state (pipeline, GST_STATE_READY) ==
1323 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to READY");
1324 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1325 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to READY");
1327 /* test with 3 audioconvert elements */
1328 gst_element_unlink (ac1, ac3);
1329 gst_bin_add (GST_BIN (pipeline), ac2);
1330 gst_element_link_many (ac1, ac2, ac3, NULL);
1332 fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) ==
1333 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to PAUSED");
1334 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1335 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to PAUSED");
1337 caps2 = gst_pad_get_caps (ac3_src);
1339 fail_if (caps2 == NULL, "gst_pad_get_caps returned NULL");
1340 GST_DEBUG ("Caps size 2 : %d", gst_caps_get_size (caps2));
1341 fail_unless (gst_caps_get_size (caps1) == gst_caps_get_size (caps2));
1343 gst_caps_unref (caps1);
1344 gst_caps_unref (caps2);
1346 fail_if (gst_element_set_state (pipeline, GST_STATE_NULL) ==
1347 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to NULL");
1348 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1349 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to NULL");
1351 gst_object_unref (ac3_src);
1352 gst_object_unref (pipeline);
1357 GST_START_TEST (test_convert_undefined_multichannel)
1359 /* (A) CONVERSION FROM 'WORSE' TO 'BETTER' FORMAT */
1361 /* 1 channel, NONE positions, int8 => int16 */
1363 guint16 out[] = { 0x2000 };
1364 guint8 in[] = { 0x20 };
1365 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1366 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1368 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1369 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1371 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1372 "int8 => int16", in, in_caps, out, out_caps);
1375 /* 2 channels, NONE positions, int8 => int16 */
1377 guint16 out[] = { 0x8000, 0x2000 };
1378 guint8 in[] = { 0x80, 0x20 };
1379 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1380 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1382 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1383 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1385 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1386 "int8 => int16", in, in_caps, out, out_caps);
1389 /* 6 channels, NONE positions, int8 => int16 */
1391 guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1392 guint8 in[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff };
1393 GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1394 GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1396 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1397 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1399 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1400 "int8 => int16", in, in_caps, out, out_caps);
1403 /* 9 channels, NONE positions, int8 => int16 */
1405 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1406 0x0000, 0xff00, 0x0000
1408 guint8 in[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 };
1409 GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1410 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1412 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1413 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1415 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1416 "int8 => int16", in, in_caps, out, out_caps);
1419 /* 15 channels, NONE positions, int8 => int16 */
1422 { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00,
1423 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000
1426 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1427 0x20, 0x80, 0x20, 0x00
1430 get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1431 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1433 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1434 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1436 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1437 "int8 => int16", in, in_caps, out, out_caps);
1440 /* (B) CONVERSION FROM 'BETTER' TO 'WORSE' FORMAT */
1442 /* 1 channel, NONE positions, int16 => int8 */
1444 guint16 in[] = { 0x2000 };
1445 guint8 out[] = { 0x20 };
1446 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1447 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1449 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1450 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1452 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1453 "int16 => int8", in, in_caps, out, out_caps);
1456 /* 2 channels, NONE positions, int16 => int8 */
1458 guint16 in[] = { 0x8000, 0x2000 };
1459 guint8 out[] = { 0x80, 0x20 };
1460 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1461 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1463 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1464 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1466 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1467 "int16 => int8", in, in_caps, out, out_caps);
1470 /* 6 channels, NONE positions, int16 => int8 */
1472 guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1473 guint8 out[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff };
1474 GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1475 GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1477 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1478 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1480 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1481 "int16 => int8", in, in_caps, out, out_caps);
1484 /* 9 channels, NONE positions, int16 => int8 */
1486 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1487 0x0000, 0xff00, 0x0000
1489 guint8 out[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 };
1490 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1491 GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1493 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1494 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1496 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1497 "int16 => int8", in, in_caps, out, out_caps);
1500 /* 15 channels, NONE positions, int16 => int8 */
1502 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1503 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1507 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1508 0x20, 0x80, 0x20, 0x00
1510 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1511 GstCaps *out_caps = get_int_mc_caps (15, "BYTE_ORDER", 8, 8, FALSE, FALSE);
1513 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1514 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1516 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1517 "int16 => int8", in, in_caps, out, out_caps);
1521 /* (C) NO CONVERSION, SAME FORMAT */
1523 /* 1 channel, NONE positions, int16 => int16 */
1525 guint16 in[] = { 0x2000 };
1526 guint16 out[] = { 0x2000 };
1527 GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1528 GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1530 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1531 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1533 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1534 "int16 => int16", in, in_caps, out, out_caps);
1537 /* 2 channels, NONE positions, int16 => int16 */
1539 guint16 in[] = { 0x8000, 0x2000 };
1540 guint16 out[] = { 0x8000, 0x2000 };
1541 GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1542 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1544 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1545 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1547 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1548 "int16 => int16", in, in_caps, out, out_caps);
1551 /* 6 channels, NONE positions, int16 => int16 */
1553 guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1554 guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1555 GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1556 GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1558 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1559 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1561 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1562 "int16 => int16", in, in_caps, out, out_caps);
1565 /* 9 channels, NONE positions, int16 => int16 */
1567 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1568 0x0000, 0xff00, 0x0000
1570 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1571 0x0000, 0xff00, 0x0000
1573 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1574 GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1576 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1577 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1579 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1580 "int16 => int16", in, in_caps, out, out_caps);
1583 /* 15 channels, NONE positions, int16 => int16 */
1585 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1586 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1589 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1590 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1593 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1595 get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1597 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1598 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1600 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1601 "int16 => int16", in, in_caps, out, out_caps);
1605 /* (C) int16 => float */
1607 /* 9 channels, NONE positions, int16 => float */
1609 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1610 0x0000, 0x8000, 0x0000
1612 gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 };
1613 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1614 GstCaps *out_caps = get_float_mc_caps (9, "BYTE_ORDER", 32, FALSE);
1616 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1617 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1619 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1620 "int16 => float", in, in_caps, out, out_caps);
1623 /* 15 channels, NONE positions, int16 => float */
1625 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1626 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1630 { -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,
1633 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1634 GstCaps *out_caps = get_float_mc_caps (15, "BYTE_ORDER", 32, FALSE);
1636 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1637 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1639 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1640 "int16 => float", in, in_caps, out, out_caps);
1644 /* 9 channels, NONE positions, int16 => float (same as above, but no
1645 * position on output caps to see if audioconvert transforms correctly) */
1647 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1648 0x0000, 0x8000, 0x0000
1650 gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 };
1651 GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1652 GstCaps *out_caps = get_float_mc_caps (9, "BYTE_ORDER", 32, FALSE);
1654 //set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1655 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1657 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1658 "int16 => float", in, in_caps, out, out_caps);
1661 /* 15 channels, NONE positions, int16 => float (same as above, but no
1662 * position on output caps to see if audioconvert transforms correctly) */
1664 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1665 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1669 { -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,
1672 GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1673 GstCaps *out_caps = get_float_mc_caps (15, "BYTE_ORDER", 32, FALSE);
1675 //set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1676 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1678 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1679 "int16 => float", in, in_caps, out, out_caps);
1682 /* 8 channels, NONE positions => 2 channels: should fail, no mixing allowed */
1684 guint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1685 gfloat out[] = { -1.0, -1.0 };
1686 GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE);
1687 GstCaps *out_caps = get_float_mc_caps (2, "BYTE_ORDER", 32, FALSE);
1689 set_channel_positions (in_caps, 8, undefined_positions[8 - 1]);
1691 RUN_CONVERSION_TO_FAIL ("8 channels with layout => 2 channels",
1692 in, in_caps, out, out_caps);
1695 /* 8 channels, with positions => 2 channels (makes sure channel-position
1696 * fields are removed properly in some cases in ::transform_caps, so we
1697 * don't up with caps with 2 channels and 8 channel positions) */
1699 GstAudioChannelPosition layout8ch[] = {
1700 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1701 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1702 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1703 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1704 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1705 GST_AUDIO_CHANNEL_POSITION_LFE,
1706 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1707 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
1709 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1710 gint16 out[] = { 0, 0 };
1711 GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1712 GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE);
1714 set_channel_positions (in_caps, 8, layout8ch);
1716 RUN_CONVERSION ("8 channels with layout => 2 channels",
1717 in, in_caps, out, out_caps);
1724 audioconvert_suite (void)
1726 Suite *s = suite_create ("audioconvert");
1727 TCase *tc_chain = tcase_create ("general");
1729 suite_add_tcase (s, tc_chain);
1730 tcase_add_test (tc_chain, test_int16);
1731 tcase_add_test (tc_chain, test_float32);
1732 tcase_add_test (tc_chain, test_int_conversion);
1733 tcase_add_test (tc_chain, test_float_conversion);
1734 tcase_add_test (tc_chain, test_multichannel_conversion);
1735 tcase_add_test (tc_chain, test_channel_remapping);
1736 tcase_add_test (tc_chain, test_caps_negotiation);
1737 tcase_add_test (tc_chain, test_convert_undefined_multichannel);
1742 GST_CHECK_MAIN (audioconvert);