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/check/gstcheck.h>
27 #include <gst/audio/multichannel.h>
29 /* For ease of programming we use globals to keep refs for our floating
30 * src and sink pads we create; otherwise we always have to do get_pad,
31 * get_peer, and then remove references in every test function */
32 static GstPad *mysrcpad, *mysinkpad;
34 #define FORMATS "{ F32LE, F32BE, F64LE, F64BE, " \
35 "S32LE, S32BE, U32LE, U32BE, " \
36 "S24LE, S24BE, U24LE, U24BE, " \
37 "S16LE, S16BE, U16LE, U16BE, " \
40 #define CONVERT_CAPS_TEMPLATE_STRING \
42 "format = (string) "FORMATS", " \
43 "rate = (int) [ 1, MAX ], " \
44 "channels = (int) [ 1, MAX ]"
46 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
49 GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING)
51 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
54 GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING)
57 /* takes over reference for outcaps */
59 setup_audioconvert (GstCaps * outcaps)
61 GstElement *audioconvert;
63 GST_DEBUG ("setup_audioconvert with caps %" GST_PTR_FORMAT, outcaps);
64 audioconvert = gst_check_setup_element ("audioconvert");
65 g_object_set (G_OBJECT (audioconvert), "dithering", 0, NULL);
66 g_object_set (G_OBJECT (audioconvert), "noise-shaping", 0, NULL);
67 mysrcpad = gst_check_setup_src_pad (audioconvert, &srctemplate, NULL);
68 mysinkpad = gst_check_setup_sink_pad (audioconvert, &sinktemplate, NULL);
69 /* this installs a getcaps func that will always return the caps we set
71 gst_pad_use_fixed_caps (mysinkpad);
73 gst_pad_set_active (mysrcpad, TRUE);
74 gst_pad_set_active (mysinkpad, TRUE);
76 gst_pad_set_caps (mysinkpad, outcaps);
77 gst_caps_unref (outcaps);
78 outcaps = gst_pad_get_current_caps (mysinkpad);
79 fail_unless (gst_caps_is_fixed (outcaps));
80 gst_caps_unref (outcaps);
86 cleanup_audioconvert (GstElement * audioconvert)
88 GST_DEBUG ("cleanup_audioconvert");
90 gst_pad_set_active (mysrcpad, FALSE);
91 gst_pad_set_active (mysinkpad, FALSE);
92 gst_check_teardown_src_pad (audioconvert);
93 gst_check_teardown_sink_pad (audioconvert);
94 gst_check_teardown_element (audioconvert);
97 /* returns a newly allocated caps */
99 get_int_caps (guint channels, gint endianness, guint width,
100 guint depth, gboolean signedness)
106 fmt = gst_audio_format_build_integer (signedness, endianness, width, depth);
108 string = g_strdup_printf ("audio/x-raw, "
109 "format = (string) %s, "
110 "rate = (int) 44100, "
111 "channels = (int) %d", gst_audio_format_to_string (fmt), channels);
112 GST_DEBUG ("creating caps from %s", string);
113 caps = gst_caps_from_string (string);
115 fail_unless (caps != NULL);
116 GST_DEBUG ("returning caps %p", caps);
120 /* returns a newly allocated caps */
122 get_float_caps (guint channels, gint endianness, guint width)
128 if (endianness == G_LITTLE_ENDIAN) {
140 string = g_strdup_printf ("audio/x-raw, "
141 "format = (string) %s, "
142 "rate = (int) 44100, " "channels = (int) %d", format, channels);
143 GST_DEBUG ("creating caps from %s", string);
144 caps = gst_caps_from_string (string);
146 fail_unless (caps != NULL);
147 GST_DEBUG ("returning caps %p", caps);
151 /* Copied from vorbis; the particular values used don't matter */
152 static GstAudioChannelPosition channelpositions[][6] = {
154 GST_AUDIO_CHANNEL_POSITION_FRONT_MONO},
156 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
157 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
158 { /* Stereo + Centre */
159 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
160 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
161 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
163 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
164 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
165 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
166 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
168 { /* Stereo + Centre + rear stereo */
169 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
170 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
171 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
172 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
173 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
175 { /* Full 5.1 Surround */
176 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
177 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
178 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
179 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
180 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
181 GST_AUDIO_CHANNEL_POSITION_LFE,
185 /* these are a bunch of random positions, they are mostly just
186 * different from the ones above, don't use elsewhere */
187 static GstAudioChannelPosition mixed_up_positions[][6] = {
189 GST_AUDIO_CHANNEL_POSITION_FRONT_MONO},
191 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
192 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT},
194 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
195 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
196 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT},
198 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
199 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
200 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
201 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
204 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
205 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
206 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
207 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
208 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
211 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
212 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
213 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
214 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
215 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
216 GST_AUDIO_CHANNEL_POSITION_LFE,
220 /* we get this when recording from a soundcard with lots of input channels */
221 static GstAudioChannelPosition undefined_positions[][15] = {
223 GST_AUDIO_CHANNEL_POSITION_NONE},
225 GST_AUDIO_CHANNEL_POSITION_NONE,
226 GST_AUDIO_CHANNEL_POSITION_NONE},
228 GST_AUDIO_CHANNEL_POSITION_NONE,
229 GST_AUDIO_CHANNEL_POSITION_NONE,
230 GST_AUDIO_CHANNEL_POSITION_NONE},
232 GST_AUDIO_CHANNEL_POSITION_NONE,
233 GST_AUDIO_CHANNEL_POSITION_NONE,
234 GST_AUDIO_CHANNEL_POSITION_NONE,
235 GST_AUDIO_CHANNEL_POSITION_NONE},
237 GST_AUDIO_CHANNEL_POSITION_NONE,
238 GST_AUDIO_CHANNEL_POSITION_NONE,
239 GST_AUDIO_CHANNEL_POSITION_NONE,
240 GST_AUDIO_CHANNEL_POSITION_NONE,
241 GST_AUDIO_CHANNEL_POSITION_NONE},
243 GST_AUDIO_CHANNEL_POSITION_NONE,
244 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,
255 GST_AUDIO_CHANNEL_POSITION_NONE,
256 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,
263 GST_AUDIO_CHANNEL_POSITION_NONE,
264 GST_AUDIO_CHANNEL_POSITION_NONE,
265 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,
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},
277 GST_AUDIO_CHANNEL_POSITION_NONE,
278 GST_AUDIO_CHANNEL_POSITION_NONE,
279 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},
288 GST_AUDIO_CHANNEL_POSITION_NONE,
289 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},
300 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,
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,
340 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,
355 GST_AUDIO_CHANNEL_POSITION_NONE,
356 GST_AUDIO_CHANNEL_POSITION_NONE}
360 set_channel_positions (GstCaps * caps, int channels,
361 GstAudioChannelPosition * channelpositions)
363 GValue chanpos = { 0 };
365 GstStructure *structure = gst_caps_get_structure (caps, 0);
368 g_value_init (&chanpos, GST_TYPE_ARRAY);
369 g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
371 for (c = 0; c < channels; c++) {
372 g_value_set_enum (&pos, channelpositions[c]);
373 gst_value_array_append_value (&chanpos, &pos);
375 g_value_unset (&pos);
377 gst_structure_set_value (structure, "channel-positions", &chanpos);
378 g_value_unset (&chanpos);
381 /* For channels > 2, caps have to have channel positions. This adds some simple
382 * ones. Only implemented for channels between 1 and 6.
385 get_float_mc_caps (guint channels, gint endianness, guint width,
386 gboolean mixed_up_layout)
388 GstCaps *caps = get_float_caps (channels, endianness, width);
392 set_channel_positions (caps, channels, mixed_up_positions[channels - 1]);
394 set_channel_positions (caps, channels, channelpositions[channels - 1]);
401 get_int_mc_caps (guint channels, gint endianness, guint width,
402 guint depth, gboolean signedness, gboolean mixed_up_layout)
404 GstCaps *caps = get_int_caps (channels, endianness, width, depth, signedness);
408 set_channel_positions (caps, channels, mixed_up_positions[channels - 1]);
410 set_channel_positions (caps, channels, channelpositions[channels - 1]);
416 /* eats the refs to the caps */
418 verify_convert (const gchar * which, void *in, int inlength,
419 GstCaps * incaps, void *out, int outlength, GstCaps * outcaps,
420 GstFlowReturn expected_flow)
422 GstBuffer *inbuffer, *outbuffer;
423 GstElement *audioconvert;
425 GST_DEBUG ("verifying conversion %s", which);
426 GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps);
427 GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps);
428 ASSERT_CAPS_REFCOUNT (incaps, "incaps", 1);
429 ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1);
430 audioconvert = setup_audioconvert (outcaps);
431 ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1);
433 fail_unless (gst_element_set_state (audioconvert,
434 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
435 "could not set to playing");
437 gst_pad_push_event (mysrcpad, gst_event_new_caps (incaps));
439 GST_DEBUG ("Creating buffer of %d bytes", inlength);
440 inbuffer = gst_buffer_new_and_alloc (inlength);
441 gst_buffer_fill (inbuffer, 0, in, inlength);
442 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
444 /* pushing gives away my reference ... */
445 GST_DEBUG ("push it");
446 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), expected_flow);
447 GST_DEBUG ("pushed it");
449 if (expected_flow != GST_FLOW_OK)
452 /* ... and puts a new buffer on the global list */
453 fail_unless (g_list_length (buffers) == 1);
454 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
456 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
457 fail_unless_equals_int (gst_buffer_get_size (outbuffer), outlength);
459 gst_check_buffer_data (outbuffer, out, outlength);
461 if (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) != 0) {
462 g_print ("\nInput data:\n");
463 gst_util_dump_mem (in, inlength);
464 g_print ("\nConverted data:\n");
465 gst_util_dump_mem (GST_BUFFER_DATA (outbuffer), outlength);
466 g_print ("\nExpected data:\n");
467 gst_util_dump_mem (out, outlength);
469 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) == 0,
470 "failed converting %s", which);
473 /* make sure that the channel positions are not lost */
475 GstStructure *in_s, *out_s;
478 in_s = gst_caps_get_structure (incaps, 0);
479 out_s = gst_caps_get_structure (gst_pad_get_current_caps (mysinkpad), 0);
480 fail_unless (gst_structure_get_int (out_s, "channels", &out_chans));
482 /* positions for 1 and 2 channels are implicit if not provided */
483 if (out_chans > 2 && gst_structure_has_field (in_s, "channel-positions")) {
484 if (!gst_structure_has_field (out_s, "channel-positions")) {
485 g_error ("Channel layout got lost somewhere:\n\nIns : %s\nOuts: %s\n",
486 gst_structure_to_string (in_s), gst_structure_to_string (out_s));
491 buffers = g_list_remove (buffers, outbuffer);
492 gst_buffer_unref (outbuffer);
495 fail_unless (gst_element_set_state (audioconvert,
496 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
498 GST_DEBUG ("cleanup audioconvert");
499 cleanup_audioconvert (audioconvert);
500 GST_DEBUG ("cleanup, unref incaps");
501 gst_caps_unref (incaps);
505 #define RUN_CONVERSION(which, inarray, in_get_caps, outarray, out_get_caps) \
506 verify_convert (which, inarray, sizeof (inarray), \
507 in_get_caps, outarray, sizeof (outarray), out_get_caps, GST_FLOW_OK)
509 #define RUN_CONVERSION_TO_FAIL(which, inarray, in_caps, outarray, out_caps) \
510 verify_convert (which, inarray, sizeof (inarray), \
511 in_caps, outarray, sizeof (outarray), out_caps, GST_FLOW_NOT_NEGOTIATED)
514 GST_START_TEST (test_int16)
518 gint16 in[] = { 16384, -256, 1024, 1024 };
519 gint16 out[] = { 8064, 1024 };
521 RUN_CONVERSION ("int16 stereo to mono",
522 in, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE),
523 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE));
527 gint16 in[] = { 512, 1024 };
528 gint16 out[] = { 512, 512, 1024, 1024 };
530 RUN_CONVERSION ("int16 mono to stereo",
531 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE),
532 out, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE));
534 /* signed -> unsigned */
536 gint16 in[] = { 0, -32767, 32767, -32768 };
537 guint16 out[] = { 32768, 1, 65535, 0 };
539 RUN_CONVERSION ("int16 signed to unsigned",
540 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE),
541 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE));
542 RUN_CONVERSION ("int16 unsigned to signed",
543 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE),
544 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE));
551 GST_START_TEST (test_float32)
555 gfloat in[] = { 0.6, -0.0078125, 0.03125, 0.03125 };
556 gfloat out[] = { 0.29609375, 0.03125 };
558 RUN_CONVERSION ("float32 stereo to mono",
559 in, get_float_caps (2, G_BYTE_ORDER, 32),
560 out, get_float_caps (1, G_BYTE_ORDER, 32));
564 gfloat in[] = { 0.015625, 0.03125 };
565 gfloat out[] = { 0.015625, 0.015625, 0.03125, 0.03125 };
567 RUN_CONVERSION ("float32 mono to stereo",
568 in, get_float_caps (1, G_BYTE_ORDER, 32),
569 out, get_float_caps (2, G_BYTE_ORDER, 32));
576 GST_START_TEST (test_int_conversion)
578 /* 8 <-> 16 signed */
579 /* NOTE: if audioconvert was doing dithering we'd have a problem */
581 gint8 in[] = { 0, 1, 2, 127, -127 };
582 gint16 out[] = { 0, 256, 512, 32512, -32512 };
584 RUN_CONVERSION ("int 8bit to 16bit signed",
585 in, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE),
586 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE)
588 RUN_CONVERSION ("int 16bit signed to 8bit",
589 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE),
590 in, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE)
595 gint16 in[] = { 0, 127, 128, 256, 256 + 127, 256 + 128 };
596 gint8 out[] = { 0, 0, 1, 1, 1, 2 };
598 RUN_CONVERSION ("16 bit to 8 signed",
599 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE),
600 out, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE)
603 /* 8 unsigned <-> 16 signed */
604 /* NOTE: if audioconvert was doing dithering we'd have a problem */
606 guint8 in[] = { 128, 129, 130, 255, 1 };
607 gint16 out[] = { 0, 256, 512, 32512, -32512 };
608 GstCaps *incaps, *outcaps;
610 /* exploded for easier valgrinding */
611 incaps = get_int_caps (1, G_BYTE_ORDER, 8, 8, FALSE);
612 outcaps = get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE);
613 GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps);
614 GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps);
615 RUN_CONVERSION ("8 unsigned to 16 signed", in, incaps, out, outcaps);
616 RUN_CONVERSION ("16 signed to 8 unsigned", out, get_int_caps (1,
617 G_BYTE_ORDER, 16, 16, TRUE), in, get_int_caps (1, G_BYTE_ORDER, 8,
621 /* 8 <-> 24 signed */
622 /* NOTE: if audioconvert was doing dithering we'd have a problem */
624 gint8 in[] = { 0, 1, 127 };
625 guint8 out[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x7f };
626 /* out has the bytes in little-endian, so that's how they should be
627 * interpreted during conversion */
629 RUN_CONVERSION ("8 to 24 signed", in, get_int_caps (1, G_BYTE_ORDER, 8, 8,
630 TRUE), out, get_int_caps (1, G_LITTLE_ENDIAN, 24, 24, TRUE)
632 RUN_CONVERSION ("24 signed to 8", out, get_int_caps (1, G_LITTLE_ENDIAN, 24,
633 24, TRUE), in, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE)
637 /* 16 bit signed <-> unsigned */
639 gint16 in[] = { 0, 128, -128 };
640 guint16 out[] = { 32768, 32896, 32640 };
641 RUN_CONVERSION ("16 signed to 16 unsigned",
642 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE),
643 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE)
645 RUN_CONVERSION ("16 unsigned to 16 signed",
646 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE),
647 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE)
651 /* 16 bit signed <-> 8 in 16 bit signed */
652 /* NOTE: if audioconvert was doing dithering we'd have a problem */
654 gint16 in[] = { 0, 64 << 8, -64 << 8 };
655 gint16 out[] = { 0, 64, -64 };
656 RUN_CONVERSION ("16 signed to 8 in 16 signed",
657 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE),
658 out, get_int_caps (1, G_BYTE_ORDER, 16, 8, TRUE)
660 RUN_CONVERSION ("8 in 16 signed to 16 signed",
661 out, get_int_caps (1, G_BYTE_ORDER, 16, 8, TRUE),
662 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE)
666 /* 16 bit unsigned <-> 8 in 16 bit unsigned */
667 /* NOTE: if audioconvert was doing dithering we'd have a problem */
669 guint16 in[] = { 1 << 15, (1 << 15) - (64 << 8), (1 << 15) + (64 << 8) };
670 guint16 out[] = { 1 << 7, (1 << 7) - 64, (1 << 7) + 64 };
671 RUN_CONVERSION ("16 unsigned to 8 in 16 unsigned",
672 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE),
673 out, get_int_caps (1, G_BYTE_ORDER, 16, 8, FALSE)
675 RUN_CONVERSION ("8 in 16 unsigned to 16 unsigned",
676 out, get_int_caps (1, G_BYTE_ORDER, 16, 8, FALSE),
677 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE)
681 /* 32 bit signed -> 16 bit signed for rounding check */
682 /* NOTE: if audioconvert was doing dithering we'd have a problem */
684 gint32 in[] = { 0, G_MININT32, G_MAXINT32,
685 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
686 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
687 (-32 << 16) + (1 << 15), (-32 << 16) - (1 << 15),
688 (-32 << 16) + (2 << 15), (-32 << 16) - (2 << 15),
691 gint16 out[] = { 0, G_MININT16, G_MAXINT16,
698 RUN_CONVERSION ("32 signed to 16 signed for rounding",
699 in, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE),
700 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE)
704 /* 32 bit signed -> 16 bit unsigned for rounding check */
705 /* NOTE: if audioconvert was doing dithering we'd have a problem */
707 gint32 in[] = { 0, G_MININT32, G_MAXINT32,
708 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
709 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
710 (-32 << 16) + (1 << 15), (-32 << 16) - (1 << 15),
711 (-32 << 16) + (2 << 15), (-32 << 16) - (2 << 15),
714 guint16 out[] = { (1 << 15), 0, G_MAXUINT16,
715 (1 << 15) + 32, (1 << 15) + 33, (1 << 15) + 32,
716 (1 << 15) + 33, (1 << 15) + 31,
717 (1 << 15) - 31, (1 << 15) - 32,
718 (1 << 15) - 31, (1 << 15) - 33,
721 RUN_CONVERSION ("32 signed to 16 unsigned for rounding",
722 in, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE),
723 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE)
730 GST_START_TEST (test_float_conversion)
732 /* 32 float <-> 16 signed */
733 /* NOTE: if audioconvert was doing dithering we'd have a problem */
736 { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0),
737 GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5), GFLOAT_TO_LE (1.1),
741 { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0),
742 GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5), GFLOAT_TO_BE (1.1),
745 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
747 /* only one direction conversion, the other direction does
748 * not produce exactly the same as the input due to floating
749 * point rounding errors etc. */
750 RUN_CONVERSION ("32 float le to 16 signed",
751 in_le, get_float_caps (1, G_LITTLE_ENDIAN, 32),
752 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE));
753 RUN_CONVERSION ("32 float be to 16 signed",
754 in_be, get_float_caps (1, G_BIG_ENDIAN, 32),
755 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE));
759 gint16 in[] = { 0, -32768, 16384, -16384 };
760 gfloat out[] = { 0.0, -1.0, 0.5, -0.5 };
762 RUN_CONVERSION ("16 signed to 32 float",
763 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE),
764 out, get_float_caps (1, G_BYTE_ORDER, 32));
767 /* 64 float <-> 16 signed */
768 /* NOTE: if audioconvert was doing dithering we'd have a problem */
771 { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0),
772 GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5), GDOUBLE_TO_LE (1.1),
776 { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0),
777 GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5), GDOUBLE_TO_BE (1.1),
780 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
782 /* only one direction conversion, the other direction does
783 * not produce exactly the same as the input due to floating
784 * point rounding errors etc. */
785 RUN_CONVERSION ("64 float LE to 16 signed",
786 in_le, get_float_caps (1, G_LITTLE_ENDIAN, 64),
787 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE));
788 RUN_CONVERSION ("64 float BE to 16 signed",
789 in_be, get_float_caps (1, G_BIG_ENDIAN, 64),
790 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE));
793 gint16 in[] = { 0, -32768, 16384, -16384 };
794 gdouble out[] = { 0.0,
795 (gdouble) (-32768L << 16) / 2147483647.0, /* ~ -1.0 */
796 (gdouble) (16384L << 16) / 2147483647.0, /* ~ 0.5 */
797 (gdouble) (-16384L << 16) / 2147483647.0, /* ~ -0.5 */
800 RUN_CONVERSION ("16 signed to 64 float",
801 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE),
802 out, get_float_caps (1, G_BYTE_ORDER, 64));
805 gint32 in[] = { 0, (-1L << 31), (1L << 30), (-1L << 30) };
806 gdouble out[] = { 0.0,
807 (gdouble) (-1L << 31) / 2147483647.0, /* ~ -1.0 */
808 (gdouble) (1L << 30) / 2147483647.0, /* ~ 0.5 */
809 (gdouble) (-1L << 30) / 2147483647.0, /* ~ -0.5 */
812 RUN_CONVERSION ("32 signed to 64 float",
813 in, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE),
814 out, get_float_caps (1, G_BYTE_ORDER, 64));
817 /* 64-bit float <-> 32-bit float */
819 gdouble in[] = { 0.0, 1.0, -1.0, 0.5, -0.5 };
820 gfloat out[] = { 0.0, 1.0, -1.0, 0.5, -0.5 };
822 RUN_CONVERSION ("64 float to 32 float",
823 in, get_float_caps (1, G_BYTE_ORDER, 64),
824 out, get_float_caps (1, G_BYTE_ORDER, 32));
826 RUN_CONVERSION ("32 float to 64 float",
827 out, get_float_caps (1, G_BYTE_ORDER, 32),
828 in, get_float_caps (1, G_BYTE_ORDER, 64));
831 /* 32-bit float little endian <-> big endian */
833 gfloat le[] = { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0),
834 GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5)
836 gfloat be[] = { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0),
837 GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5)
840 RUN_CONVERSION ("32 float LE to BE",
841 le, get_float_caps (1, G_LITTLE_ENDIAN, 32),
842 be, get_float_caps (1, G_BIG_ENDIAN, 32));
844 RUN_CONVERSION ("32 float BE to LE",
845 be, get_float_caps (1, G_BIG_ENDIAN, 32),
846 le, get_float_caps (1, G_LITTLE_ENDIAN, 32));
849 /* 64-bit float little endian <-> big endian */
852 { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0),
853 GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5)
856 { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0),
857 GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5)
860 RUN_CONVERSION ("64 float LE to BE",
861 le, get_float_caps (1, G_LITTLE_ENDIAN, 64),
862 be, get_float_caps (1, G_BIG_ENDIAN, 64));
864 RUN_CONVERSION ("64 float BE to LE",
865 be, get_float_caps (1, G_BIG_ENDIAN, 64),
866 le, get_float_caps (1, G_LITTLE_ENDIAN, 64));
873 GST_START_TEST (test_multichannel_conversion)
876 gfloat in[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
877 gfloat out[] = { 0.0, 0.0 };
879 RUN_CONVERSION ("3 channels to 1", in, get_float_mc_caps (3,
880 G_BYTE_ORDER, 32, FALSE), out, get_float_caps (1, G_BYTE_ORDER,
882 RUN_CONVERSION ("1 channels to 3", out, get_float_caps (1,
883 G_BYTE_ORDER, 32), in, get_float_mc_caps (3, G_BYTE_ORDER,
888 gint16 in[] = { 0, 0, 0, 0, 0, 0 };
889 gint16 out[] = { 0, 0 };
891 RUN_CONVERSION ("3 channels to 1", in, get_int_mc_caps (3,
892 G_BYTE_ORDER, 16, 16, TRUE, FALSE), out, get_int_caps (1,
893 G_BYTE_ORDER, 16, 16, TRUE));
894 RUN_CONVERSION ("1 channels to 3", out, get_int_caps (1, G_BYTE_ORDER, 16,
895 16, TRUE), in, get_int_mc_caps (3, G_BYTE_ORDER, 16, 16, TRUE,
900 gint16 in[] = { 1, 2 };
901 gint16 out[] = { 1, 1, 2, 2 };
902 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
903 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
904 GstAudioChannelPosition in_layout[1] =
905 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
906 GstAudioChannelPosition out_layout[2] =
907 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
908 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
911 set_channel_positions (in_caps, 1, in_layout);
912 set_channel_positions (out_caps, 2, out_layout);
914 RUN_CONVERSION ("1 channels to 2 with standard layout", in,
915 in_caps, out, out_caps);
919 gint16 in[] = { 1, 2 };
920 gint16 out[] = { 1, 1, 2, 2 };
921 GstCaps *in_caps = get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE);
922 GstCaps *out_caps = get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE);
924 RUN_CONVERSION ("1 channels to 2 with standard layout and no positions set",
925 in, gst_caps_copy (in_caps), out, gst_caps_copy (out_caps));
927 RUN_CONVERSION ("2 channels to 1 with standard layout and no positions set",
928 out, out_caps, in, in_caps);
932 gint16 in[] = { 1, 2 };
933 gint16 out[] = { 1, 0, 2, 0 };
934 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
935 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
936 GstAudioChannelPosition in_layout[1] =
937 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT };
938 GstAudioChannelPosition out_layout[2] =
939 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
940 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
943 set_channel_positions (in_caps, 1, in_layout);
944 set_channel_positions (out_caps, 2, out_layout);
946 RUN_CONVERSION ("1 channels to 2 with non-standard layout", in,
947 in_caps, out, out_caps);
951 gint16 in[] = { 1, 2, 3, 4 };
952 gint16 out[] = { 2, 4 };
953 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
954 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
955 GstAudioChannelPosition in_layout[2] =
956 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
957 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
959 GstAudioChannelPosition out_layout[1] =
960 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER };
962 set_channel_positions (in_caps, 2, in_layout);
963 set_channel_positions (out_caps, 1, out_layout);
965 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
966 in_caps, out, out_caps);
970 gint16 in[] = { 1, 2, 3, 4 };
971 gint16 out[] = { 2, 4 };
972 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
973 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
974 GstAudioChannelPosition in_layout[2] =
975 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
976 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
978 GstAudioChannelPosition out_layout[1] =
979 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
981 set_channel_positions (in_caps, 2, in_layout);
982 set_channel_positions (out_caps, 1, out_layout);
984 RUN_CONVERSION ("2 channels to 1 with standard layout", in,
985 in_caps, out, out_caps);
989 gint16 in[] = { 1, 2, 3, 4 };
990 gint16 out[] = { 1, 3 };
991 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
992 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
993 GstAudioChannelPosition in_layout[2] =
994 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
995 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER
997 GstAudioChannelPosition out_layout[1] =
998 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1000 set_channel_positions (in_caps, 2, in_layout);
1001 set_channel_positions (out_caps, 1, out_layout);
1003 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1004 in_caps, out, out_caps);
1008 gint16 in[] = { 1, 2, 3, 4 };
1009 gint16 out[] = { 1, 3 };
1010 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1011 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1012 GstAudioChannelPosition in_layout[2] =
1013 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1014 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT
1016 GstAudioChannelPosition out_layout[1] =
1017 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1019 set_channel_positions (in_caps, 2, in_layout);
1020 set_channel_positions (out_caps, 1, out_layout);
1022 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1023 in_caps, out, out_caps);
1026 gint16 in[] = { 4, 5, 4, 2, 2, 1 };
1027 gint16 out[] = { 3, 3 };
1028 GstCaps *in_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1029 GstCaps *out_caps = get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE);
1031 RUN_CONVERSION ("5.1 to 2 channels", in, in_caps, out, out_caps);
1034 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1035 gint16 out[] = { 0, 0 };
1036 GstCaps *in_caps = get_int_mc_caps (11, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1037 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1038 GstAudioChannelPosition in_layout[11] = {
1039 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1040 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1041 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
1042 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1043 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1044 GST_AUDIO_CHANNEL_POSITION_LFE,
1045 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1046 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
1047 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
1048 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1049 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
1052 set_channel_positions (in_caps, 11, in_layout);
1054 RUN_CONVERSION ("11 channels to 2", in,
1055 gst_caps_copy (in_caps), out, gst_caps_copy (out_caps));
1056 RUN_CONVERSION ("2 channels to 11", out, out_caps, in, in_caps);
1063 /* for testing channel remapping with 8 channels */
1064 static GstAudioChannelPosition n8chan_pos_remap_in[8] = {
1065 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1066 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1067 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1068 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1069 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1070 GST_AUDIO_CHANNEL_POSITION_LFE,
1071 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1072 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
1075 static GstAudioChannelPosition n8chan_pos_remap_out[8] = {
1076 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1077 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1078 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1079 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1080 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
1081 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1082 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1083 GST_AUDIO_CHANNEL_POSITION_LFE
1086 GST_START_TEST (test_channel_remapping)
1090 gfloat in[] = { 0.0, 1.0, -0.5 };
1091 gfloat out[] = { -0.5, 1.0, 0.0 };
1092 GstCaps *in_caps = get_float_mc_caps (3, G_BYTE_ORDER, 32, FALSE);
1093 GstCaps *out_caps = get_float_mc_caps (3, G_BYTE_ORDER, 32, TRUE);
1095 RUN_CONVERSION ("3 channels layout remapping float", in, in_caps,
1101 guint16 in[] = { 0, 65535, 0x9999 };
1102 guint16 out[] = { 0x9999, 65535, 0 };
1103 GstCaps *in_caps = get_int_mc_caps (3, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1104 GstCaps *out_caps = get_int_mc_caps (3, G_BYTE_ORDER, 16, 16, FALSE, TRUE);
1106 RUN_CONVERSION ("3 channels layout remapping int", in, in_caps,
1110 /* int with 8 channels (= largest number allowed with channel positions) */
1112 guint16 in[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
1113 guint16 out[] = { 4, 0, 1, 6, 7, 2, 3, 5 };
1114 GstCaps *in_caps = get_int_mc_caps (8, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1115 GstCaps *out_caps = get_int_mc_caps (8, G_BYTE_ORDER, 16, 16, FALSE, TRUE);
1117 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1118 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1120 RUN_CONVERSION ("8 channels layout remapping int", in, in_caps,
1124 /* int16 to int32 with 8 channels (= largest number allowed with channel positions) */
1126 guint16 in[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
1128 { 4 << 16, 0, 1 << 16, 6 << 16, 7 << 16, 2 << 16, 3 << 16, 5 << 16 };
1129 GstCaps *in_caps = get_int_mc_caps (8, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1130 GstCaps *out_caps = get_int_mc_caps (8, G_BYTE_ORDER, 32, 32, FALSE, TRUE);
1132 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1133 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1135 RUN_CONVERSION ("8 channels layout remapping int16 --> int32", in, in_caps,
1138 in_caps = get_int_mc_caps (8, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1139 out_caps = get_int_mc_caps (8, G_BYTE_ORDER, 32, 32, FALSE, TRUE);
1140 set_channel_positions (in_caps, 8, n8chan_pos_remap_in);
1141 set_channel_positions (out_caps, 8, n8chan_pos_remap_out);
1142 RUN_CONVERSION ("8 channels layout remapping int16 <-- int32", out,
1143 out_caps, in, in_caps);
1146 /* float to gint16 with 3 channels */
1148 gfloat in[] = { 100.0 / G_MAXINT16, 0.0, -100.0 / G_MAXINT16 };
1149 gint16 out[] = { -100, 0, 100 };
1150 GstCaps *in_caps = get_float_mc_caps (3, G_BYTE_ORDER, 32, TRUE);
1151 GstCaps *out_caps = get_int_mc_caps (3, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1153 RUN_CONVERSION ("3 channels layout remapping float32 --> int16", in,
1154 in_caps, out, out_caps);
1157 /* gint16 to gint16 with 2 channels and non-standard layout */
1159 gint16 in[] = { 1, 2, 3, 4 };
1160 gint16 out[] = { 1, 2, 2, 4 };
1161 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1162 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1163 GstAudioChannelPosition in_layout[2] =
1164 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1165 GST_AUDIO_CHANNEL_POSITION_LFE
1167 GstAudioChannelPosition out_layout[2] =
1168 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1169 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1172 set_channel_positions (in_caps, 2, in_layout);
1173 set_channel_positions (out_caps, 2, out_layout);
1175 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1176 in_caps, out, out_caps);
1179 /* gint16 to gint16 with 2 channels and non-standard layout */
1181 gint16 in[] = { 1, 2, 3, 4 };
1182 gint16 out[] = { 2, 1, 4, 3 };
1183 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1184 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1185 GstAudioChannelPosition in_layout[2] =
1186 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1187 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
1189 GstAudioChannelPosition out_layout[2] =
1190 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1191 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1194 set_channel_positions (in_caps, 2, in_layout);
1195 set_channel_positions (out_caps, 2, out_layout);
1197 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1198 in_caps, out, out_caps);
1201 /* gint16 to gint16 with 2 channels and non-standard layout */
1203 gint16 in[] = { 1, 2, 3, 4 };
1204 gint16 out[] = { 1, 1, 3, 3 };
1205 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1206 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1207 GstAudioChannelPosition in_layout[2] =
1208 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1209 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER
1211 GstAudioChannelPosition out_layout[2] =
1212 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1213 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
1216 set_channel_positions (in_caps, 2, in_layout);
1217 set_channel_positions (out_caps, 2, out_layout);
1219 RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in,
1220 in_caps, out, out_caps);
1223 /* gint16 to gint16 with 1 channel and non-standard layout */
1225 gint16 in[] = { 1, 2, 3, 4 };
1226 gint16 out[] = { 0, 0, 0, 0 };
1227 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1228 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1229 GstAudioChannelPosition in_layout[1] =
1230 { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT };
1231 GstAudioChannelPosition out_layout[1] =
1232 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT };
1234 set_channel_positions (in_caps, 1, in_layout);
1235 set_channel_positions (out_caps, 1, out_layout);
1237 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1238 in_caps, out, out_caps);
1241 /* gint16 to gint16 with 1 channel and non-standard layout */
1243 gint16 in[] = { 1, 2, 3, 4 };
1244 gint16 out[] = { 1, 2, 3, 4 };
1245 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1246 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1247 GstAudioChannelPosition in_layout[1] =
1248 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1249 GstAudioChannelPosition out_layout[1] =
1250 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER };
1252 set_channel_positions (in_caps, 1, in_layout);
1253 set_channel_positions (out_caps, 1, out_layout);
1255 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1256 in_caps, out, out_caps);
1259 /* gint16 to gint16 with 1 channel and non-standard layout */
1261 gint16 in[] = { 1, 2, 3, 4 };
1262 gint16 out[] = { 1, 2, 3, 4 };
1263 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1264 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1265 GstAudioChannelPosition in_layout[1] =
1266 { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO };
1267 GstAudioChannelPosition out_layout[1] =
1268 { GST_AUDIO_CHANNEL_POSITION_REAR_LEFT };
1270 set_channel_positions (in_caps, 1, in_layout);
1271 set_channel_positions (out_caps, 1, out_layout);
1273 RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in,
1274 in_caps, out, out_caps);
1280 GST_START_TEST (test_caps_negotiation)
1282 GstElement *src, *ac1, *ac2, *ac3, *sink;
1283 GstElement *pipeline;
1285 GstCaps *caps1, *caps2;
1287 pipeline = gst_pipeline_new ("test");
1289 /* create elements */
1290 src = gst_element_factory_make ("audiotestsrc", "src");
1291 ac1 = gst_element_factory_make ("audioconvert", "ac1");
1292 ac2 = gst_element_factory_make ("audioconvert", "ac2");
1293 ac3 = gst_element_factory_make ("audioconvert", "ac3");
1294 sink = gst_element_factory_make ("fakesink", "sink");
1295 ac3_src = gst_element_get_static_pad (ac3, "src");
1297 /* test with 2 audioconvert elements */
1298 gst_bin_add_many (GST_BIN (pipeline), src, ac1, ac3, sink, NULL);
1299 gst_element_link_many (src, ac1, ac3, sink, NULL);
1301 /* Set to PAUSED and wait for PREROLL */
1302 fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) ==
1303 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline to PAUSED");
1304 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1305 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline to PAUSED");
1307 caps1 = gst_pad_query_caps (ac3_src, NULL);
1308 fail_if (caps1 == NULL, "gst_pad_query_caps returned NULL");
1309 GST_DEBUG ("Caps size 1 : %d", gst_caps_get_size (caps1));
1311 fail_if (gst_element_set_state (pipeline, GST_STATE_READY) ==
1312 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to READY");
1313 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1314 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to READY");
1316 /* test with 3 audioconvert elements */
1317 gst_element_unlink (ac1, ac3);
1318 gst_bin_add (GST_BIN (pipeline), ac2);
1319 gst_element_link_many (ac1, ac2, ac3, NULL);
1321 fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) ==
1322 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to PAUSED");
1323 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1324 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to PAUSED");
1326 caps2 = gst_pad_query_caps (ac3_src, NULL);
1328 fail_if (caps2 == NULL, "gst_pad_query_caps returned NULL");
1329 GST_DEBUG ("Caps size 2 : %d", gst_caps_get_size (caps2));
1330 fail_unless (gst_caps_get_size (caps1) == gst_caps_get_size (caps2));
1332 gst_caps_unref (caps1);
1333 gst_caps_unref (caps2);
1335 fail_if (gst_element_set_state (pipeline, GST_STATE_NULL) ==
1336 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to NULL");
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 NULL");
1340 gst_object_unref (ac3_src);
1341 gst_object_unref (pipeline);
1346 GST_START_TEST (test_convert_undefined_multichannel)
1348 /* (A) CONVERSION FROM 'WORSE' TO 'BETTER' FORMAT */
1350 /* 1 channel, NONE positions, int8 => int16 */
1352 guint16 out[] = { 0x2000 };
1353 guint8 in[] = { 0x20 };
1354 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1355 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1357 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1358 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1360 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1361 "int8 => int16", in, in_caps, out, out_caps);
1364 /* 2 channels, NONE positions, int8 => int16 */
1366 guint16 out[] = { 0x8000, 0x2000 };
1367 guint8 in[] = { 0x80, 0x20 };
1368 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1369 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1371 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1372 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1374 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1375 "int8 => int16", in, in_caps, out, out_caps);
1378 /* 6 channels, NONE positions, int8 => int16 */
1380 guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1381 guint8 in[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff };
1382 GstCaps *out_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1383 GstCaps *in_caps = get_int_mc_caps (6, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1385 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1386 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1388 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1389 "int8 => int16", in, in_caps, out, out_caps);
1392 /* 9 channels, NONE positions, int8 => int16 */
1394 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1395 0x0000, 0xff00, 0x0000
1397 guint8 in[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 };
1398 GstCaps *out_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1399 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1401 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1402 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1404 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1405 "int8 => int16", in, in_caps, out, out_caps);
1408 /* 15 channels, NONE positions, int8 => int16 */
1411 { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00,
1412 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000
1415 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1416 0x20, 0x80, 0x20, 0x00
1419 get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1420 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1422 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1423 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1425 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1426 "int8 => int16", in, in_caps, out, out_caps);
1429 /* (B) CONVERSION FROM 'BETTER' TO 'WORSE' FORMAT */
1431 /* 1 channel, NONE positions, int16 => int8 */
1433 guint16 in[] = { 0x2000 };
1434 guint8 out[] = { 0x20 };
1435 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1436 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1438 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1439 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1441 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1442 "int16 => int8", in, in_caps, out, out_caps);
1445 /* 2 channels, NONE positions, int16 => int8 */
1447 guint16 in[] = { 0x8000, 0x2000 };
1448 guint8 out[] = { 0x80, 0x20 };
1449 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1450 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1452 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1453 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1455 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1456 "int16 => int8", in, in_caps, out, out_caps);
1459 /* 6 channels, NONE positions, int16 => int8 */
1461 guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1462 guint8 out[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff };
1463 GstCaps *in_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1464 GstCaps *out_caps = get_int_mc_caps (6, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1466 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1467 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1469 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1470 "int16 => int8", in, in_caps, out, out_caps);
1473 /* 9 channels, NONE positions, int16 => int8 */
1475 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1476 0x0000, 0xff00, 0x0000
1478 guint8 out[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 };
1479 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1480 GstCaps *out_caps = get_int_mc_caps (9, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1482 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1483 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1485 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1486 "int16 => int8", in, in_caps, out, out_caps);
1489 /* 15 channels, NONE positions, int16 => int8 */
1491 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1492 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1496 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1497 0x20, 0x80, 0x20, 0x00
1499 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1500 GstCaps *out_caps = get_int_mc_caps (15, G_BYTE_ORDER, 8, 8, FALSE, FALSE);
1502 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1503 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1505 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1506 "int16 => int8", in, in_caps, out, out_caps);
1510 /* (C) NO CONVERSION, SAME FORMAT */
1512 /* 1 channel, NONE positions, int16 => int16 */
1514 guint16 in[] = { 0x2000 };
1515 guint16 out[] = { 0x2000 };
1516 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1517 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1519 set_channel_positions (out_caps, 1, undefined_positions[1 - 1]);
1520 set_channel_positions (in_caps, 1, undefined_positions[1 - 1]);
1522 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1523 "int16 => int16", in, in_caps, out, out_caps);
1526 /* 2 channels, NONE positions, int16 => int16 */
1528 guint16 in[] = { 0x8000, 0x2000 };
1529 guint16 out[] = { 0x8000, 0x2000 };
1530 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1531 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1533 set_channel_positions (out_caps, 2, undefined_positions[2 - 1]);
1534 set_channel_positions (in_caps, 2, undefined_positions[2 - 1]);
1536 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1537 "int16 => int16", in, in_caps, out, out_caps);
1540 /* 6 channels, NONE positions, int16 => int16 */
1542 guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1543 guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1544 GstCaps *in_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1545 GstCaps *out_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1547 set_channel_positions (out_caps, 6, undefined_positions[6 - 1]);
1548 set_channel_positions (in_caps, 6, undefined_positions[6 - 1]);
1550 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1551 "int16 => int16", in, in_caps, out, out_caps);
1554 /* 9 channels, NONE positions, int16 => int16 */
1556 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1557 0x0000, 0xff00, 0x0000
1559 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1560 0x0000, 0xff00, 0x0000
1562 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1563 GstCaps *out_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1565 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1566 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1568 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1569 "int16 => int16", in, in_caps, out, out_caps);
1572 /* 15 channels, NONE positions, int16 => int16 */
1574 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1575 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1578 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1579 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1582 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1584 get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1586 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1587 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1589 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1590 "int16 => int16", in, in_caps, out, out_caps);
1594 /* (C) int16 => float */
1596 /* 9 channels, NONE positions, int16 => float */
1598 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1599 0x0000, 0x8000, 0x0000
1601 gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 };
1602 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1603 GstCaps *out_caps = get_float_mc_caps (9, G_BYTE_ORDER, 32, FALSE);
1605 set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1606 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1608 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1609 "int16 => float", in, in_caps, out, out_caps);
1612 /* 15 channels, NONE positions, int16 => float */
1614 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1615 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1619 { -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,
1622 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1623 GstCaps *out_caps = get_float_mc_caps (15, G_BYTE_ORDER, 32, FALSE);
1625 set_channel_positions (out_caps, 15, undefined_positions[15 - 1]);
1626 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1628 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1629 "int16 => float", in, in_caps, out, out_caps);
1633 /* 9 channels, NONE positions, int16 => float (same as above, but no
1634 * position on output caps to see if audioconvert transforms correctly) */
1636 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1637 0x0000, 0x8000, 0x0000
1639 gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 };
1640 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1641 GstCaps *out_caps = get_float_mc_caps (9, G_BYTE_ORDER, 32, FALSE);
1643 //set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1644 set_channel_positions (in_caps, 9, undefined_positions[9 - 1]);
1646 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1647 "int16 => float", in, in_caps, out, out_caps);
1650 /* 15 channels, NONE positions, int16 => float (same as above, but no
1651 * position on output caps to see if audioconvert transforms correctly) */
1653 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1654 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1658 { -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,
1661 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1662 GstCaps *out_caps = get_float_mc_caps (15, G_BYTE_ORDER, 32, FALSE);
1664 //set_channel_positions (out_caps, 9, undefined_positions[9 - 1]);
1665 set_channel_positions (in_caps, 15, undefined_positions[15 - 1]);
1667 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1668 "int16 => float", in, in_caps, out, out_caps);
1671 /* 8 channels, NONE positions => 2 channels: should fail, no mixing allowed */
1673 guint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1674 gfloat out[] = { -1.0, -1.0 };
1675 GstCaps *in_caps = get_int_mc_caps (8, G_BYTE_ORDER, 16, 16, FALSE, FALSE);
1676 GstCaps *out_caps = get_float_mc_caps (2, G_BYTE_ORDER, 32, FALSE);
1678 set_channel_positions (in_caps, 8, undefined_positions[8 - 1]);
1680 RUN_CONVERSION_TO_FAIL ("8 channels with layout => 2 channels",
1681 in, in_caps, out, out_caps);
1684 /* 8 channels, with positions => 2 channels (makes sure channel-position
1685 * fields are removed properly in some cases in ::transform_caps, so we
1686 * don't up with caps with 2 channels and 8 channel positions) */
1688 GstAudioChannelPosition layout8ch[] = {
1689 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1690 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1691 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1692 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1693 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1694 GST_AUDIO_CHANNEL_POSITION_LFE,
1695 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1696 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
1698 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1699 gint16 out[] = { 0, 0 };
1700 GstCaps *in_caps = get_int_mc_caps (8, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1701 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, FALSE);
1703 set_channel_positions (in_caps, 8, layout8ch);
1705 RUN_CONVERSION ("8 channels with layout => 2 channels",
1706 in, in_caps, out, out_caps);
1713 audioconvert_suite (void)
1715 Suite *s = suite_create ("audioconvert");
1716 TCase *tc_chain = tcase_create ("general");
1718 suite_add_tcase (s, tc_chain);
1719 tcase_add_test (tc_chain, test_int16);
1720 tcase_add_test (tc_chain, test_float32);
1721 tcase_add_test (tc_chain, test_int_conversion);
1722 tcase_add_test (tc_chain, test_float_conversion);
1723 tcase_add_test (tc_chain, test_multichannel_conversion);
1724 tcase_add_test (tc_chain, test_channel_remapping);
1725 tcase_add_test (tc_chain, test_caps_negotiation);
1726 tcase_add_test (tc_chain, test_convert_undefined_multichannel);
1731 GST_CHECK_MAIN (audioconvert);