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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
27 #include <gst/check/gstcheck.h>
28 #include <gst/audio/audio.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 FORMATS "{ F32LE, F32BE, F64LE, F64BE, " \
36 "S32LE, S32BE, U32LE, U32BE, " \
37 "S24LE, S24BE, U24LE, U24BE, " \
38 "S16LE, S16BE, U16LE, U16BE, " \
41 #define CONVERT_CAPS_TEMPLATE_STRING \
43 "format = (string) "FORMATS", " \
44 "rate = (int) [ 1, MAX ], " \
45 "channels = (int) [ 1, MAX ]"
47 /* takes over reference for outcaps */
49 setup_audioconvert (GstCaps * outcaps)
51 GstPadTemplate *sinktemplate;
52 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
55 GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING)
57 GstElement *audioconvert;
60 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, outcaps);
62 GST_DEBUG ("setup_audioconvert with caps %" GST_PTR_FORMAT, outcaps);
63 audioconvert = gst_check_setup_element ("audioconvert");
64 g_object_set (G_OBJECT (audioconvert), "dithering", 0, NULL);
65 g_object_set (G_OBJECT (audioconvert), "noise-shaping", 0, NULL);
66 mysrcpad = gst_check_setup_src_pad (audioconvert, &srctemplate);
68 gst_check_setup_sink_pad_from_template (audioconvert, sinktemplate);
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_object_unref (sinktemplate);
82 cleanup_audioconvert (GstElement * audioconvert)
84 GST_DEBUG ("cleanup_audioconvert");
86 gst_pad_set_active (mysrcpad, FALSE);
87 gst_pad_set_active (mysinkpad, FALSE);
88 gst_check_teardown_src_pad (audioconvert);
89 gst_check_teardown_sink_pad (audioconvert);
90 gst_check_teardown_element (audioconvert);
93 /* returns a newly allocated caps */
95 get_int_caps (guint channels, gint endianness, guint width,
96 guint depth, gboolean signedness, GstAudioLayout layout)
102 g_assert (channels <= 2);
104 GST_DEBUG ("channels:%d, endianness:%d, width:%d, depth:%d, signedness:%d",
105 channels, endianness, width, depth, signedness);
107 fmt = gst_audio_format_build_integer (signedness, endianness, width, depth);
109 gst_audio_info_init (&info);
110 gst_audio_info_set_format (&info, fmt, GST_AUDIO_DEF_RATE, channels, NULL);
111 info.layout = layout;
113 caps = gst_audio_info_to_caps (&info);
114 fail_unless (caps != NULL);
115 GST_DEBUG ("returning caps %" GST_PTR_FORMAT, caps);
120 static GstAudioFormat
121 get_float_format (gint endianness, gint width)
123 if (endianness == G_LITTLE_ENDIAN) {
125 return GST_AUDIO_FORMAT_F32LE;
127 return GST_AUDIO_FORMAT_F64LE;
130 return GST_AUDIO_FORMAT_F32BE;
132 return GST_AUDIO_FORMAT_F64BE;
136 /* returns a newly allocated caps */
138 get_float_caps (guint channels, gint endianness, guint width,
139 GstAudioLayout layout)
144 g_assert (channels <= 2);
146 gst_audio_info_init (&info);
147 gst_audio_info_set_format (&info, get_float_format (endianness, width),
148 GST_AUDIO_DEF_RATE, channels, NULL);
149 info.layout = layout;
151 caps = gst_audio_info_to_caps (&info);
152 fail_unless (caps != NULL);
153 GST_DEBUG ("returning caps %" GST_PTR_FORMAT, caps);
158 /* Copied from vorbis; the particular values used don't matter */
159 static GstAudioChannelPosition channelpositions[][6] = {
161 GST_AUDIO_CHANNEL_POSITION_MONO},
163 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
164 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
165 { /* Stereo + Centre */
166 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
167 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
168 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER},
170 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
171 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
172 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
173 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
175 { /* Stereo + Centre + rear stereo */
176 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
177 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
178 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
179 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
180 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
182 { /* Full 5.1 Surround */
183 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
184 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
185 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
186 GST_AUDIO_CHANNEL_POSITION_LFE1,
187 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
188 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
192 /* we get this when recording from a soundcard with lots of input channels */
193 static GstAudioChannelPosition undefined_positions[][15] = {
195 GST_AUDIO_CHANNEL_POSITION_NONE},
197 GST_AUDIO_CHANNEL_POSITION_NONE,
198 GST_AUDIO_CHANNEL_POSITION_NONE},
200 GST_AUDIO_CHANNEL_POSITION_NONE,
201 GST_AUDIO_CHANNEL_POSITION_NONE,
202 GST_AUDIO_CHANNEL_POSITION_NONE},
204 GST_AUDIO_CHANNEL_POSITION_NONE,
205 GST_AUDIO_CHANNEL_POSITION_NONE,
206 GST_AUDIO_CHANNEL_POSITION_NONE,
207 GST_AUDIO_CHANNEL_POSITION_NONE},
209 GST_AUDIO_CHANNEL_POSITION_NONE,
210 GST_AUDIO_CHANNEL_POSITION_NONE,
211 GST_AUDIO_CHANNEL_POSITION_NONE,
212 GST_AUDIO_CHANNEL_POSITION_NONE,
213 GST_AUDIO_CHANNEL_POSITION_NONE},
215 GST_AUDIO_CHANNEL_POSITION_NONE,
216 GST_AUDIO_CHANNEL_POSITION_NONE,
217 GST_AUDIO_CHANNEL_POSITION_NONE,
218 GST_AUDIO_CHANNEL_POSITION_NONE,
219 GST_AUDIO_CHANNEL_POSITION_NONE,
220 GST_AUDIO_CHANNEL_POSITION_NONE},
222 GST_AUDIO_CHANNEL_POSITION_NONE,
223 GST_AUDIO_CHANNEL_POSITION_NONE,
224 GST_AUDIO_CHANNEL_POSITION_NONE,
225 GST_AUDIO_CHANNEL_POSITION_NONE,
226 GST_AUDIO_CHANNEL_POSITION_NONE,
227 GST_AUDIO_CHANNEL_POSITION_NONE,
228 GST_AUDIO_CHANNEL_POSITION_NONE},
230 GST_AUDIO_CHANNEL_POSITION_NONE,
231 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,
236 GST_AUDIO_CHANNEL_POSITION_NONE,
237 GST_AUDIO_CHANNEL_POSITION_NONE},
239 GST_AUDIO_CHANNEL_POSITION_NONE,
240 GST_AUDIO_CHANNEL_POSITION_NONE,
241 GST_AUDIO_CHANNEL_POSITION_NONE,
242 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},
249 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,
257 GST_AUDIO_CHANNEL_POSITION_NONE,
258 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,
266 GST_AUDIO_CHANNEL_POSITION_NONE,
267 GST_AUDIO_CHANNEL_POSITION_NONE,
268 GST_AUDIO_CHANNEL_POSITION_NONE,
269 GST_AUDIO_CHANNEL_POSITION_NONE,
270 GST_AUDIO_CHANNEL_POSITION_NONE},
272 GST_AUDIO_CHANNEL_POSITION_NONE,
273 GST_AUDIO_CHANNEL_POSITION_NONE,
274 GST_AUDIO_CHANNEL_POSITION_NONE,
275 GST_AUDIO_CHANNEL_POSITION_NONE,
276 GST_AUDIO_CHANNEL_POSITION_NONE,
277 GST_AUDIO_CHANNEL_POSITION_NONE,
278 GST_AUDIO_CHANNEL_POSITION_NONE,
279 GST_AUDIO_CHANNEL_POSITION_NONE,
280 GST_AUDIO_CHANNEL_POSITION_NONE,
281 GST_AUDIO_CHANNEL_POSITION_NONE,
282 GST_AUDIO_CHANNEL_POSITION_NONE,
283 GST_AUDIO_CHANNEL_POSITION_NONE},
285 GST_AUDIO_CHANNEL_POSITION_NONE,
286 GST_AUDIO_CHANNEL_POSITION_NONE,
287 GST_AUDIO_CHANNEL_POSITION_NONE,
288 GST_AUDIO_CHANNEL_POSITION_NONE,
289 GST_AUDIO_CHANNEL_POSITION_NONE,
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},
299 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,
312 GST_AUDIO_CHANNEL_POSITION_NONE},
314 GST_AUDIO_CHANNEL_POSITION_NONE,
315 GST_AUDIO_CHANNEL_POSITION_NONE,
316 GST_AUDIO_CHANNEL_POSITION_NONE,
317 GST_AUDIO_CHANNEL_POSITION_NONE,
318 GST_AUDIO_CHANNEL_POSITION_NONE,
319 GST_AUDIO_CHANNEL_POSITION_NONE,
320 GST_AUDIO_CHANNEL_POSITION_NONE,
321 GST_AUDIO_CHANNEL_POSITION_NONE,
322 GST_AUDIO_CHANNEL_POSITION_NONE,
323 GST_AUDIO_CHANNEL_POSITION_NONE,
324 GST_AUDIO_CHANNEL_POSITION_NONE,
325 GST_AUDIO_CHANNEL_POSITION_NONE,
326 GST_AUDIO_CHANNEL_POSITION_NONE,
327 GST_AUDIO_CHANNEL_POSITION_NONE,
328 GST_AUDIO_CHANNEL_POSITION_NONE}
331 /* For channels > 2, caps have to have channel positions. This adds some simple
332 * ones. Only implemented for channels between 1 and 6.
335 get_float_mc_caps (guint channels, gint endianness, guint width,
336 GstAudioLayout layout, const GstAudioChannelPosition * position)
341 gst_audio_info_init (&info);
344 gst_audio_info_set_format (&info, get_float_format (endianness, width),
345 GST_AUDIO_DEF_RATE, channels, position);
346 } else if (channels <= 6) {
347 gst_audio_info_set_format (&info, get_float_format (endianness, width),
348 GST_AUDIO_DEF_RATE, channels, channelpositions[channels - 1]);
350 GstAudioChannelPosition pos[64];
353 for (i = 0; i < 64; i++)
354 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
355 gst_audio_info_set_format (&info, get_float_format (endianness, width),
356 GST_AUDIO_DEF_RATE, channels, pos);
359 info.layout = layout;
361 caps = gst_audio_info_to_caps (&info);
362 fail_unless (caps != NULL);
364 GST_DEBUG ("returning caps %" GST_PTR_FORMAT, caps);
370 get_int_mc_caps (guint channels, gint endianness, guint width,
371 guint depth, gboolean signedness, GstAudioLayout layout,
372 const GstAudioChannelPosition * position)
378 fmt = gst_audio_format_build_integer (signedness, endianness, width, depth);
380 gst_audio_info_init (&info);
383 gst_audio_info_set_format (&info, fmt, GST_AUDIO_DEF_RATE, channels,
385 } else if (channels <= 6) {
386 gst_audio_info_set_format (&info, fmt, GST_AUDIO_DEF_RATE, channels,
387 channelpositions[channels - 1]);
389 GstAudioChannelPosition pos[64];
392 for (i = 0; i < 64; i++)
393 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
394 gst_audio_info_set_format (&info, fmt, GST_AUDIO_DEF_RATE, channels, pos);
397 info.layout = layout;
399 caps = gst_audio_info_to_caps (&info);
400 fail_unless (caps != NULL);
402 GST_DEBUG ("returning caps %" GST_PTR_FORMAT, caps);
407 /* eats the refs to the caps */
409 verify_convert (const gchar * which, void *in, int inlength,
410 GstCaps * incaps, void *out, int outlength, GstCaps * outcaps,
411 GstFlowReturn expected_flow, gboolean in_place_allowed)
413 GstBuffer *inbuffer, *outbuffer;
414 GstElement *audioconvert;
415 GstAudioInfo in_info;
417 GST_DEBUG ("verifying conversion %s", which);
418 GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps);
419 GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps);
420 ASSERT_CAPS_REFCOUNT (incaps, "incaps", 1);
421 ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1);
422 audioconvert = setup_audioconvert (outcaps);
423 ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 2);
425 fail_unless (gst_element_set_state (audioconvert,
426 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
427 "could not set to playing");
429 gst_check_setup_events (mysrcpad, audioconvert, incaps, GST_FORMAT_TIME);
431 GST_DEBUG ("Creating buffer of %d bytes", inlength);
432 inbuffer = gst_buffer_new_and_alloc (inlength);
433 gst_buffer_fill (inbuffer, 0, in, inlength);
434 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
436 fail_unless (gst_audio_info_from_caps (&in_info, incaps));
437 gst_buffer_add_audio_meta (inbuffer, &in_info, inlength / in_info.bpf, NULL);
439 if (!in_place_allowed) {
440 /* take extra ref to force processing */
441 gst_buffer_ref (inbuffer);
442 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (audioconvert),
446 /* pushing gives away my reference ... */
447 GST_DEBUG ("push it");
448 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), expected_flow);
449 GST_DEBUG ("pushed it");
451 if (expected_flow != GST_FLOW_OK)
454 /* ... and puts a new buffer on the global list */
455 fail_unless (g_list_length (buffers) == 1);
456 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
458 if (!in_place_allowed) {
459 /* release extra ref */
460 gst_buffer_unref (inbuffer);
463 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
464 fail_unless_equals_int (gst_buffer_get_size (outbuffer), outlength);
466 gst_check_buffer_data (outbuffer, out, outlength);
468 /* make sure that the channel positions are not lost */
470 GstStructure *in_s, *out_s;
474 in_s = gst_caps_get_structure (incaps, 0);
475 ccaps = gst_pad_get_current_caps (mysinkpad);
476 out_s = gst_caps_get_structure (ccaps, 0);
477 fail_unless (gst_structure_get_int (out_s, "channels", &out_chans));
479 /* positions for 1 and 2 channels are implicit if not provided */
480 if (out_chans > 2 && gst_structure_has_field (in_s, "channel-mask")) {
481 if (!gst_structure_has_field (out_s, "channel-mask")) {
482 gst_printerrln ("In : %" GST_PTR_FORMAT, in_s);
483 gst_printerrln ("Out : %" GST_PTR_FORMAT, out_s);
484 g_error ("Channel layout got lost somewhere\n");
487 gst_caps_unref (ccaps);
490 buffers = g_list_remove (buffers, outbuffer);
491 gst_buffer_unref (outbuffer);
494 fail_unless (gst_element_set_state (audioconvert,
495 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
497 GST_DEBUG ("cleanup audioconvert");
498 cleanup_audioconvert (audioconvert);
499 GST_DEBUG ("cleanup, unref incaps");
500 gst_caps_unref (incaps);
501 gst_caps_unref (outcaps);
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, \
510 #define RUN_CONVERSION_TO_FAIL(which, inarray, in_caps, outarray, out_caps) \
511 verify_convert (which, inarray, sizeof (inarray), \
512 in_caps, outarray, sizeof (outarray), out_caps, \
513 GST_FLOW_NOT_NEGOTIATED, TRUE)
515 #define RUN_CONVERSION_NOT_INPLACE(which, inarray, in_get_caps, outarray, out_get_caps) \
516 verify_convert (which, inarray, sizeof (inarray), \
517 in_get_caps, outarray, sizeof (outarray), out_get_caps, GST_FLOW_OK, \
520 #define INTERLEAVED GST_AUDIO_LAYOUT_INTERLEAVED
521 #define PLANAR GST_AUDIO_LAYOUT_NON_INTERLEAVED
523 GST_START_TEST (test_int16)
527 gint16 in_i[] = { 16384, -256, 1024, 1024 };
528 gint16 in_p[] = { 16384, 1024, -256, 1024 };
529 gint16 out[] = { 8064, 1024 };
531 RUN_CONVERSION ("int16 stereo to mono interleaved",
532 in_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
533 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
534 RUN_CONVERSION ("int16 stereo to mono planar",
535 in_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR),
536 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
540 gint16 in[] = { 512, 1024 };
541 gint16 out_i[] = { 512, 512, 1024, 1024 };
542 gint16 out_p[] = { 512, 1024, 512, 1024 };
544 RUN_CONVERSION ("int16 mono to stereo interleaved",
545 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
546 out_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
547 RUN_CONVERSION ("int16 mono to stereo planar",
548 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, PLANAR),
549 out_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
551 /* signed -> unsigned */
553 gint16 in[] = { 0, -32767, 32767, -32768 };
554 guint16 out[] = { 32768, 1, 65535, 0 };
556 RUN_CONVERSION ("int16 signed to unsigned interleaved",
557 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
558 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE, INTERLEAVED));
559 RUN_CONVERSION ("int16 unsigned to signed interleaved",
560 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE, INTERLEAVED),
561 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
563 RUN_CONVERSION ("int16 signed to unsigned planar",
564 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, PLANAR),
565 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE, PLANAR));
566 RUN_CONVERSION ("int16 unsigned to signed planar",
567 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE, PLANAR),
568 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
575 GST_START_TEST (test_float32)
579 gfloat in_i[] = { 0.6, -0.0078125, 0.03125, 0.03125 };
580 gfloat in_p[] = { 0.6, 0.03125, -0.0078125, 0.03125 };
581 gfloat out[] = { 0.29609375, 0.03125 };
583 RUN_CONVERSION ("float32 stereo to mono interleaved",
584 in_i, get_float_caps (2, G_BYTE_ORDER, 32, INTERLEAVED),
585 out, get_float_caps (1, G_BYTE_ORDER, 32, INTERLEAVED));
586 RUN_CONVERSION ("float32 stereo to mono planar",
587 in_p, get_float_caps (2, G_BYTE_ORDER, 32, PLANAR),
588 out, get_float_caps (1, G_BYTE_ORDER, 32, PLANAR));
592 gfloat in[] = { 0.015625, 0.03125 };
593 gfloat out_i[] = { 0.015625, 0.015625, 0.03125, 0.03125 };
594 gfloat out_p[] = { 0.015625, 0.03125, 0.015625, 0.03125 };
596 RUN_CONVERSION ("float32 mono to stereo interleaved",
597 in, get_float_caps (1, G_BYTE_ORDER, 32, INTERLEAVED),
598 out_i, get_float_caps (2, G_BYTE_ORDER, 32, INTERLEAVED));
599 RUN_CONVERSION ("float32 mono to stereo planar",
600 in, get_float_caps (1, G_BYTE_ORDER, 32, PLANAR),
601 out_p, get_float_caps (2, G_BYTE_ORDER, 32, PLANAR));
608 GST_START_TEST (test_int_conversion)
610 /* 8 <-> 16 signed */
611 /* NOTE: if audioconvert was doing dithering we'd have a problem */
613 gint8 in[] = { 0, 1, 2, 127, -127 };
614 gint16 out[] = { 0, 256, 512, 32512, -32512 };
616 RUN_CONVERSION ("int 8bit to 16bit signed",
617 in, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE, INTERLEAVED),
618 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED)
620 RUN_CONVERSION ("int 16bit signed to 8bit",
621 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
622 in, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE, INTERLEAVED)
627 gint16 in[] = { 0, 127, 128, 256, 256 + 127, 256 + 128 };
628 gint8 out[] = { 0, 0, 1, 1, 1, 2 };
630 RUN_CONVERSION ("16 bit to 8 signed",
631 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
632 out, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE, INTERLEAVED)
635 /* 8 unsigned <-> 16 signed */
636 /* NOTE: if audioconvert was doing dithering we'd have a problem */
638 guint8 in[] = { 128, 129, 130, 255, 1 };
639 gint16 out[] = { 0, 256, 512, 32512, -32512 };
640 GstCaps *incaps, *outcaps;
642 /* exploded for easier valgrinding */
643 incaps = get_int_caps (1, G_BYTE_ORDER, 8, 8, FALSE, INTERLEAVED);
644 outcaps = get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED);
645 GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps);
646 GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps);
647 RUN_CONVERSION ("8 unsigned to 16 signed", in, incaps, out, outcaps);
648 RUN_CONVERSION ("16 signed to 8 unsigned", out, get_int_caps (1,
649 G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED), in, get_int_caps (1,
650 G_BYTE_ORDER, 8, 8, FALSE, INTERLEAVED)
653 /* 8 <-> 24 signed */
654 /* NOTE: if audioconvert was doing dithering we'd have a problem */
656 gint8 in[] = { 0, 1, 127 };
657 guint8 out[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x7f };
658 /* out has the bytes in little-endian, so that's how they should be
659 * interpreted during conversion */
661 RUN_CONVERSION ("8 to 24 signed", in, get_int_caps (1, G_BYTE_ORDER, 8, 8,
662 TRUE, INTERLEAVED), out, get_int_caps (1, G_LITTLE_ENDIAN, 24, 24,
665 RUN_CONVERSION ("24 signed to 8", out, get_int_caps (1, G_LITTLE_ENDIAN, 24,
666 24, TRUE, INTERLEAVED), in, get_int_caps (1, G_BYTE_ORDER, 8, 8,
671 /* 16 bit signed <-> unsigned */
673 gint16 in[] = { 0, 128, -128 };
674 guint16 out[] = { 32768, 32896, 32640 };
675 RUN_CONVERSION ("16 signed to 16 unsigned",
676 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
677 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE, INTERLEAVED)
679 RUN_CONVERSION ("16 unsigned to 16 signed",
680 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE, INTERLEAVED),
681 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED)
685 /* 32 bit signed -> 16 bit signed for rounding check */
686 /* NOTE: if audioconvert was doing dithering we'd have a problem */
688 gint32 in[] = { 0, G_MININT32, G_MAXINT32,
689 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
690 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
691 (-(32 << 16)) + (1 << 15), (-(32 << 16)) - (1 << 15),
692 (-(32 << 16)) + (2 << 15), (-(32 << 16)) - (2 << 15),
695 gint16 out[] = { 0, G_MININT16, G_MAXINT16,
702 RUN_CONVERSION ("32 signed to 16 signed for rounding",
703 in, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE, INTERLEAVED),
704 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED)
708 /* 32 bit signed -> 16 bit unsigned for rounding check */
709 /* NOTE: if audioconvert was doing dithering we'd have a problem */
711 gint32 in[] = { 0, G_MININT32, G_MAXINT32,
712 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
713 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
714 (-(32 << 16)) + (1 << 15), (-(32 << 16)) - (1 << 15),
715 (-(32 << 16)) + (2 << 15), (-(32 << 16)) - (2 << 15),
718 guint16 out[] = { (1 << 15), 0, G_MAXUINT16,
719 (1 << 15) + 32, (1 << 15) + 33, (1 << 15) + 32,
720 (1 << 15) + 33, (1 << 15) + 31,
721 (1 << 15) - 31, (1 << 15) - 32,
722 (1 << 15) - 31, (1 << 15) - 33,
725 RUN_CONVERSION ("32 signed to 16 unsigned for rounding",
726 in, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE, INTERLEAVED),
727 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, FALSE, INTERLEAVED)
734 GST_START_TEST (test_float_conversion)
736 /* 64-bit float <-> 32-bit float */
738 gdouble in[] = { 0.0, 1.0, -1.0, 0.5, -0.5 };
739 gfloat out[] = { 0.0, 1.0, -1.0, 0.5, -0.5 };
741 RUN_CONVERSION ("64 float to 32 float",
742 in, get_float_caps (1, G_BYTE_ORDER, 64, INTERLEAVED),
743 out, get_float_caps (1, G_BYTE_ORDER, 32, INTERLEAVED));
745 RUN_CONVERSION ("32 float to 64 float",
746 out, get_float_caps (1, G_BYTE_ORDER, 32, INTERLEAVED),
747 in, get_float_caps (1, G_BYTE_ORDER, 64, INTERLEAVED));
750 /* 32-bit float little endian <-> big endian */
752 gfloat le[] = { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0),
753 GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5)
755 gfloat be[] = { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0),
756 GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5)
759 RUN_CONVERSION ("32 float LE to BE",
760 le, get_float_caps (1, G_LITTLE_ENDIAN, 32, INTERLEAVED),
761 be, get_float_caps (1, G_BIG_ENDIAN, 32, INTERLEAVED));
763 RUN_CONVERSION ("32 float BE to LE",
764 be, get_float_caps (1, G_BIG_ENDIAN, 32, INTERLEAVED),
765 le, get_float_caps (1, G_LITTLE_ENDIAN, 32, INTERLEAVED));
768 /* 64-bit float little endian <-> big endian */
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)
775 { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0),
776 GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5)
779 RUN_CONVERSION ("64 float LE to BE",
780 le, get_float_caps (1, G_LITTLE_ENDIAN, 64, INTERLEAVED),
781 be, get_float_caps (1, G_BIG_ENDIAN, 64, INTERLEAVED));
783 RUN_CONVERSION ("64 float BE to LE",
784 be, get_float_caps (1, G_BIG_ENDIAN, 64, INTERLEAVED),
785 le, get_float_caps (1, G_LITTLE_ENDIAN, 64, INTERLEAVED));
791 GST_START_TEST (test_int_float_conversion)
793 /* 32 float <-> 16 signed */
794 /* NOTE: if audioconvert was doing dithering we'd have a problem */
797 { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0),
798 GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5), GFLOAT_TO_LE (1.1),
802 { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0),
803 GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5), GFLOAT_TO_BE (1.1),
806 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
808 /* only one direction conversion, the other direction does
809 * not produce exactly the same as the input due to floating
810 * point rounding errors etc. */
811 RUN_CONVERSION ("32 float le to 16 signed",
812 in_le, get_float_caps (1, G_LITTLE_ENDIAN, 32, INTERLEAVED),
813 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
814 RUN_CONVERSION ("32 float be to 16 signed",
815 in_be, get_float_caps (1, G_BIG_ENDIAN, 32, INTERLEAVED),
816 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
820 gint16 in[] = { 0, -32768, 16384, -16384 };
821 gfloat out[] = { 0.0, -1.0, 0.5, -0.5 };
823 RUN_CONVERSION ("16 signed to 32 float",
824 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
825 out, get_float_caps (1, G_BYTE_ORDER, 32, INTERLEAVED));
828 /* 64 float <-> 16 signed */
829 /* NOTE: if audioconvert was doing dithering we'd have a problem */
832 { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0),
833 GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5), GDOUBLE_TO_LE (1.1),
837 { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0),
838 GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5), GDOUBLE_TO_BE (1.1),
841 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
843 /* only one direction conversion, the other direction does
844 * not produce exactly the same as the input due to floating
845 * point rounding errors etc. */
846 RUN_CONVERSION ("64 float LE to 16 signed",
847 in_le, get_float_caps (1, G_LITTLE_ENDIAN, 64, INTERLEAVED),
848 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
849 RUN_CONVERSION ("64 float BE to 16 signed",
850 in_be, get_float_caps (1, G_BIG_ENDIAN, 64, INTERLEAVED),
851 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
854 gint16 in[] = { 0, -32768, 16384, -16384 };
855 gdouble out[] = { 0.0,
856 (gdouble) (-(G_GINT64_CONSTANT (32768) << 16)) / 2147483648.0, /* ~ -1.0 */
857 (gdouble) (16384L << 16) / 2147483648.0, /* ~ 0.5 */
858 (gdouble) (-(16384L << 16)) / 2147483648.0, /* ~ -0.5 */
861 RUN_CONVERSION ("16 signed to 64 float",
862 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
863 out, get_float_caps (1, G_BYTE_ORDER, 64, INTERLEAVED));
867 { 0, (-(G_GINT64_CONSTANT (1) << 31)), (1L << 30), (-(1L << 30)) };
868 gdouble out[] = { 0.0,
869 (gdouble) (-(G_GINT64_CONSTANT (1) << 31)) / 2147483648.0, /* ~ -1.0 */
870 (gdouble) (1L << 30) / 2147483648.0, /* ~ 0.5 */
871 (gdouble) (-(1L << 30)) / 2147483648.0, /* ~ -0.5 */
874 RUN_CONVERSION ("32 signed to 64 float",
875 in, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE, INTERLEAVED),
876 out, get_float_caps (1, G_BYTE_ORDER, 64, INTERLEAVED));
882 GST_START_TEST (test_multichannel_conversion)
885 gfloat in[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
886 gfloat out[] = { 0.0, 0.0 };
888 RUN_CONVERSION ("3 channels to 1", in, get_float_mc_caps (3,
889 G_BYTE_ORDER, 32, INTERLEAVED, NULL), out, get_float_caps (1,
890 G_BYTE_ORDER, 32, INTERLEAVED));
891 RUN_CONVERSION ("1 channels to 3", out, get_float_caps (1, G_BYTE_ORDER,
892 32, INTERLEAVED), in, get_float_mc_caps (3, G_BYTE_ORDER, 32,
897 gint16 in[] = { 0, 0, 0, 0, 0, 0 };
898 gint16 out[] = { 0, 0 };
900 RUN_CONVERSION ("3 channels to 1", in, get_int_mc_caps (3,
901 G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, NULL), out,
902 get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
903 RUN_CONVERSION ("1 channels to 3", out, get_int_caps (1, G_BYTE_ORDER, 16,
904 16, TRUE, INTERLEAVED), in, get_int_mc_caps (3, G_BYTE_ORDER, 16,
905 16, TRUE, INTERLEAVED, NULL));
909 gint16 in[] = { 1, 2 };
910 gint16 out[] = { 1, 1, 2, 2 };
911 GstAudioChannelPosition in_layout[1] = { GST_AUDIO_CHANNEL_POSITION_MONO };
912 GstAudioChannelPosition out_layout[2] =
913 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
914 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
917 get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, in_layout);
918 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE,
919 INTERLEAVED, out_layout);
921 RUN_CONVERSION ("1 channels to 2 with standard layout", in,
922 in_caps, out, out_caps);
926 gint16 in[] = { 1, 2 };
927 gint16 out[] = { 1, 1, 2, 2 };
929 get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED);
931 get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED);
933 RUN_CONVERSION ("1 channels to 2 with standard layout and no positions set",
934 in, gst_caps_copy (in_caps), out, gst_caps_copy (out_caps));
936 RUN_CONVERSION ("2 channels to 1 with standard layout and no positions set",
937 out, out_caps, in, in_caps);
941 gint16 in[] = { 1, 2 };
942 gint16 out[] = { 1, 0, 2, 0 };
943 GstAudioChannelPosition in_layout[1] =
944 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT };
945 GstAudioChannelPosition out_layout[2] =
946 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
947 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
950 get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, in_layout);
951 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE,
952 INTERLEAVED, out_layout);
954 RUN_CONVERSION ("1 channels to 2 with non-standard layout", in,
955 in_caps, out, out_caps);
959 gint16 in[] = { 1, 2, 3, 4 };
960 gint16 out[] = { 2, 4 };
961 GstAudioChannelPosition in_layout[2] =
962 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
963 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
965 GstAudioChannelPosition out_layout[1] =
966 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER };
968 get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, in_layout);
969 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE,
970 INTERLEAVED, out_layout);
972 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
973 in_caps, out, out_caps);
977 gint16 in[] = { 1, 2, 3, 4 };
978 gint16 out[] = { 2, 4 };
979 GstAudioChannelPosition in_layout[2] =
980 { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
981 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
983 GstAudioChannelPosition out_layout[1] = { GST_AUDIO_CHANNEL_POSITION_MONO };
985 get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, in_layout);
986 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE,
987 INTERLEAVED, out_layout);
989 RUN_CONVERSION ("2 channels to 1 with standard layout", in,
990 in_caps, out, out_caps);
994 gint16 in[] = { 1, 2, 3, 4 };
995 gint16 out[] = { 1, 3 };
996 GstAudioChannelPosition in_layout[2] =
997 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
998 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER
1000 GstAudioChannelPosition out_layout[1] = { GST_AUDIO_CHANNEL_POSITION_MONO };
1002 get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, in_layout);
1003 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE,
1004 INTERLEAVED, out_layout);
1006 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1007 in_caps, out, out_caps);
1011 gint16 in[] = { 1, 2, 3, 4 };
1012 gint16 out[] = { 1, 3 };
1013 GstAudioChannelPosition in_layout[2] =
1014 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1015 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT
1017 GstAudioChannelPosition out_layout[1] = { GST_AUDIO_CHANNEL_POSITION_MONO };
1019 get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, in_layout);
1020 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, TRUE,
1021 INTERLEAVED, out_layout);
1023 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1024 in_caps, out, out_caps);
1027 gint16 in[] = { 4, 5, 4, 2, 2, 1 };
1028 gint16 out[] = { 3, 3 };
1030 get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, NULL);
1032 get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED);
1034 RUN_CONVERSION ("5.1 to 2 channels", in, in_caps, out, out_caps);
1037 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1038 gint16 out[] = { 0, 0 };
1039 GstAudioChannelPosition in_layout[11] = {
1040 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1041 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1042 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1043 GST_AUDIO_CHANNEL_POSITION_LFE1,
1044 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1045 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1046 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
1047 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
1048 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
1049 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1050 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
1052 GstCaps *in_caps = get_int_mc_caps (11, G_BYTE_ORDER, 16, 16, TRUE,
1053 INTERLEAVED, in_layout);
1055 get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, NULL);
1057 RUN_CONVERSION ("11 channels to 2", in, in_caps, out, out_caps);
1060 gint16 in[] = { 0, 0 };
1061 gint16 out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1062 GstAudioChannelPosition out_layout[11] = {
1063 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1064 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1065 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1066 GST_AUDIO_CHANNEL_POSITION_LFE1,
1067 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1068 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1069 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
1070 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,
1071 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
1072 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1073 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
1076 get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, NULL);
1077 GstCaps *out_caps = get_int_mc_caps (11, G_BYTE_ORDER, 16, 16, TRUE,
1078 INTERLEAVED, out_layout);
1080 RUN_CONVERSION ("2 channels to 11", in, in_caps, out, out_caps);
1087 GST_START_TEST (test_passthrough)
1091 gint8 data[] = { 0, 1, 2, 127, -127 };
1093 RUN_CONVERSION ("int 8 bit passthrough",
1094 data, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE, INTERLEAVED),
1095 data, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE, INTERLEAVED)
1097 RUN_CONVERSION_NOT_INPLACE ("int 8 bit passthrough",
1098 data, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE, INTERLEAVED),
1099 data, get_int_caps (1, G_BYTE_ORDER, 8, 8, TRUE, INTERLEAVED)
1102 /* int 16 bit signed */
1104 gint16 data[] = { 0, 256, 512, 32512, -32512 };
1106 RUN_CONVERSION ("int 16 bit signed passthrough",
1107 data, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
1108 data, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED)
1110 RUN_CONVERSION_NOT_INPLACE ("int 16 bit signed passthrough",
1111 data, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
1112 data, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED)
1115 /* int 32 bit signed */
1117 gint32 data[] = { 0, G_MININT32, G_MAXINT32,
1118 (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15),
1119 (32 << 16) + (2 << 15), (32 << 16) - (2 << 15),
1120 (-(32 << 16)) + (1 << 15), (-(32 << 16)) - (1 << 15),
1121 (-(32 << 16)) + (2 << 15), (-(32 << 16)) - (2 << 15),
1124 RUN_CONVERSION ("int 32 bit signed passthrough",
1125 data, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE, INTERLEAVED),
1126 data, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE, INTERLEAVED)
1128 RUN_CONVERSION_NOT_INPLACE ("int 32 bit signed passthrough",
1129 data, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE, INTERLEAVED),
1130 data, get_int_caps (1, G_BYTE_ORDER, 32, 32, TRUE, INTERLEAVED)
1134 /* int 16 bit signed stereo */
1136 gint16 data[] = { 0, 0, 1, 1, 2, 2, 3, 3 };
1138 RUN_CONVERSION ("int 16 bit signed 2 channel passthrough",
1139 data, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
1140 data, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
1141 RUN_CONVERSION_NOT_INPLACE ("int 16 bit signed 2 channel passthrough",
1142 data, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
1143 data, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
1149 GST_START_TEST (test_caps_negotiation)
1151 GstElement *src, *ac1, *ac2, *ac3, *sink;
1152 GstElement *pipeline;
1154 GstCaps *caps1, *caps2;
1156 pipeline = gst_pipeline_new ("test");
1158 /* create elements */
1159 src = gst_element_factory_make ("audiotestsrc", "src");
1160 ac1 = gst_element_factory_make ("audioconvert", "ac1");
1161 ac2 = gst_element_factory_make ("audioconvert", "ac2");
1162 ac3 = gst_element_factory_make ("audioconvert", "ac3");
1163 sink = gst_element_factory_make ("fakesink", "sink");
1164 ac3_src = gst_element_get_static_pad (ac3, "src");
1166 /* test with 2 audioconvert elements */
1167 gst_bin_add_many (GST_BIN (pipeline), src, ac1, ac3, sink, NULL);
1168 gst_element_link_many (src, ac1, ac3, sink, NULL);
1170 /* Set to PAUSED and wait for PREROLL */
1171 fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) ==
1172 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline to PAUSED");
1173 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1174 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline to PAUSED");
1176 caps1 = gst_pad_query_caps (ac3_src, NULL);
1177 fail_if (caps1 == NULL, "gst_pad_query_caps returned NULL");
1178 GST_DEBUG ("Caps size 1 : %d", gst_caps_get_size (caps1));
1180 fail_if (gst_element_set_state (pipeline, GST_STATE_READY) ==
1181 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to READY");
1182 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1183 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to READY");
1185 /* test with 3 audioconvert elements */
1186 gst_element_unlink (ac1, ac3);
1187 gst_bin_add (GST_BIN (pipeline), ac2);
1188 gst_element_link_many (ac1, ac2, ac3, NULL);
1190 fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) ==
1191 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to PAUSED");
1192 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1193 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to PAUSED");
1195 caps2 = gst_pad_query_caps (ac3_src, NULL);
1197 fail_if (caps2 == NULL, "gst_pad_query_caps returned NULL");
1198 GST_DEBUG ("Caps size 2 : %d", gst_caps_get_size (caps2));
1199 fail_unless (gst_caps_get_size (caps1) == gst_caps_get_size (caps2));
1201 gst_caps_unref (caps1);
1202 gst_caps_unref (caps2);
1204 fail_if (gst_element_set_state (pipeline, GST_STATE_NULL) ==
1205 GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to NULL");
1206 fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) !=
1207 GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to NULL");
1209 gst_object_unref (ac3_src);
1210 gst_object_unref (pipeline);
1215 GST_START_TEST (test_convert_undefined_multichannel)
1217 /* (A) CONVERSION FROM 'WORSE' TO 'BETTER' FORMAT */
1219 /* 1 channel, NONE positions, int8 => int16 */
1221 guint16 out[] = { 0x2000 };
1222 guint8 in[] = { 0x20 };
1223 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, FALSE,
1224 INTERLEAVED, undefined_positions[1 - 1]);
1225 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 8, 8, FALSE,
1226 INTERLEAVED, undefined_positions[1 - 1]);
1228 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1229 "int8 => int16", in, in_caps, out, out_caps);
1232 /* 2 channels, NONE positions, int8 => int16 */
1234 guint16 out[] = { 0x8000, 0x2000 };
1235 guint8 in[] = { 0x80, 0x20 };
1236 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, FALSE,
1237 INTERLEAVED, undefined_positions[2 - 1]);
1238 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 8, 8, FALSE,
1239 INTERLEAVED, undefined_positions[2 - 1]);
1241 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1242 "int8 => int16", in, in_caps, out, out_caps);
1245 /* 6 channels, NONE positions, int8 => int16 */
1247 guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1248 guint8 in[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff };
1249 GstCaps *out_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, FALSE,
1250 INTERLEAVED, undefined_positions[6 - 1]);
1251 GstCaps *in_caps = get_int_mc_caps (6, G_BYTE_ORDER, 8, 8, FALSE,
1252 INTERLEAVED, undefined_positions[6 - 1]);
1254 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1255 "int8 => int16", in, in_caps, out, out_caps);
1258 /* 9 channels, NONE positions, int8 => int16 */
1260 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1261 0x0000, 0xff00, 0x0000
1263 guint8 in[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 };
1264 GstCaps *out_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE,
1265 INTERLEAVED, undefined_positions[9 - 1]);
1266 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 8, 8, FALSE,
1267 INTERLEAVED, undefined_positions[9 - 1]);
1269 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1270 "int8 => int16", in, in_caps, out, out_caps);
1273 /* 15 channels, NONE positions, int8 => int16 */
1276 { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00,
1277 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000
1280 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1281 0x20, 0x80, 0x20, 0x00
1283 GstCaps *out_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE,
1284 INTERLEAVED, undefined_positions[15 - 1]);
1285 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 8, 8, FALSE,
1286 INTERLEAVED, undefined_positions[15 - 1]);
1288 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1289 "int8 => int16", in, in_caps, out, out_caps);
1292 /* (B) CONVERSION FROM 'BETTER' TO 'WORSE' FORMAT */
1294 /* 1 channel, NONE positions, int16 => int8 */
1296 guint16 in[] = { 0x2000 };
1297 guint8 out[] = { 0x20 };
1298 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, FALSE,
1299 INTERLEAVED, undefined_positions[1 - 1]);
1300 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 8, 8, FALSE,
1301 INTERLEAVED, undefined_positions[1 - 1]);
1303 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1304 "int16 => int8", in, in_caps, out, out_caps);
1307 /* 2 channels, NONE positions, int16 => int8 */
1309 guint16 in[] = { 0x8000, 0x2000 };
1310 guint8 out[] = { 0x80, 0x20 };
1311 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, FALSE,
1312 INTERLEAVED, undefined_positions[2 - 1]);
1313 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 8, 8, FALSE,
1314 INTERLEAVED, undefined_positions[2 - 1]);
1316 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1317 "int16 => int8", in, in_caps, out, out_caps);
1320 /* 6 channels, NONE positions, int16 => int8 */
1322 guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1323 guint8 out[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff };
1324 GstCaps *in_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, FALSE,
1325 INTERLEAVED, undefined_positions[6 - 1]);
1326 GstCaps *out_caps = get_int_mc_caps (6, G_BYTE_ORDER, 8, 8, FALSE,
1327 INTERLEAVED, undefined_positions[6 - 1]);
1329 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1330 "int16 => int8", in, in_caps, out, out_caps);
1333 /* 9 channels, NONE positions, int16 => int8 */
1335 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1336 0x0000, 0xff00, 0x0000
1338 guint8 out[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 };
1339 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE,
1340 INTERLEAVED, undefined_positions[9 - 1]);
1341 GstCaps *out_caps = get_int_mc_caps (9, G_BYTE_ORDER, 8, 8, FALSE,
1342 INTERLEAVED, undefined_positions[9 - 1]);
1344 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1345 "int16 => int8", in, in_caps, out, out_caps);
1348 /* 15 channels, NONE positions, int16 => int8 */
1350 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1351 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1355 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1356 0x20, 0x80, 0x20, 0x00
1358 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE,
1359 INTERLEAVED, undefined_positions[15 - 1]);
1360 GstCaps *out_caps = get_int_mc_caps (15, G_BYTE_ORDER, 8, 8, FALSE,
1361 INTERLEAVED, undefined_positions[15 - 1]);
1363 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1364 "int16 => int8", in, in_caps, out, out_caps);
1368 /* (C) NO CONVERSION, SAME FORMAT */
1370 /* 1 channel, NONE positions, int16 => int16 */
1372 guint16 in[] = { 0x2000 };
1373 guint16 out[] = { 0x2000 };
1374 GstCaps *in_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, FALSE,
1375 INTERLEAVED, undefined_positions[1 - 1]);
1376 GstCaps *out_caps = get_int_mc_caps (1, G_BYTE_ORDER, 16, 16, FALSE,
1377 INTERLEAVED, undefined_positions[1 - 1]);
1379 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1380 "int16 => int16", in, in_caps, out, out_caps);
1383 /* 2 channels, NONE positions, int16 => int16 */
1385 guint16 in[] = { 0x8000, 0x2000 };
1386 guint16 out[] = { 0x8000, 0x2000 };
1387 GstCaps *in_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, FALSE,
1388 INTERLEAVED, undefined_positions[2 - 1]);
1389 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, FALSE,
1390 INTERLEAVED, undefined_positions[2 - 1]);
1392 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1393 "int16 => int16", in, in_caps, out, out_caps);
1396 /* 6 channels, NONE positions, int16 => int16 */
1398 guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1399 guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 };
1400 GstCaps *in_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, FALSE,
1401 INTERLEAVED, undefined_positions[6 - 1]);
1402 GstCaps *out_caps = get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, FALSE,
1403 INTERLEAVED, undefined_positions[6 - 1]);
1405 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1406 "int16 => int16", in, in_caps, out, out_caps);
1409 /* 9 channels, NONE positions, int16 => int16 */
1411 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1412 0x0000, 0xff00, 0x0000
1414 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1415 0x0000, 0xff00, 0x0000
1417 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE,
1418 INTERLEAVED, undefined_positions[9 - 1]);
1419 GstCaps *out_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE,
1420 INTERLEAVED, undefined_positions[9 - 1]);
1422 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1423 "int16 => int16", in, in_caps, out, out_caps);
1426 /* 15 channels, NONE positions, int16 => int16 */
1428 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1429 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1432 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1433 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1436 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE,
1437 INTERLEAVED, undefined_positions[15 - 1]);
1438 GstCaps *out_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE,
1439 INTERLEAVED, undefined_positions[15 - 1]);
1441 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1442 "int16 => int16", in, in_caps, out, out_caps);
1446 /* (C) int16 => float */
1448 /* 9 channels, NONE positions, int16 => float */
1450 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1451 0x0000, 0x8000, 0x0000
1453 gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 };
1454 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE,
1455 INTERLEAVED, undefined_positions[9 - 1]);
1456 GstCaps *out_caps = get_float_mc_caps (9, G_BYTE_ORDER, 32, INTERLEAVED,
1457 undefined_positions[9 - 1]);
1459 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1460 "int16 => float", in, in_caps, out, out_caps);
1463 /* 15 channels, NONE positions, int16 => float */
1465 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1466 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1470 { -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,
1473 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE,
1474 INTERLEAVED, undefined_positions[15 - 1]);
1475 GstCaps *out_caps = get_float_mc_caps (15, G_BYTE_ORDER, 32, INTERLEAVED,
1476 undefined_positions[15 - 1]);
1478 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1479 "int16 => float", in, in_caps, out, out_caps);
1483 /* 9 channels, NONE positions, int16 => float (same as above, but no
1484 * position on output caps to see if audioconvert transforms correctly) */
1486 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1487 0x0000, 0x8000, 0x0000
1489 gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 };
1490 GstCaps *in_caps = get_int_mc_caps (9, G_BYTE_ORDER, 16, 16, FALSE,
1491 INTERLEAVED, undefined_positions[9 - 1]);
1492 GstCaps *out_caps = get_float_mc_caps (9, G_BYTE_ORDER, 32, INTERLEAVED,
1493 undefined_positions[9 - 1]);
1495 gst_structure_remove_field (gst_caps_get_structure (out_caps, 0),
1498 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1499 "int16 => float", in, in_caps, out, out_caps);
1502 /* 15 channels, NONE positions, int16 => float (same as above, but no
1503 * position on output caps to see if audioconvert transforms correctly) */
1505 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1506 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1510 { -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,
1513 GstCaps *in_caps = get_int_mc_caps (15, G_BYTE_ORDER, 16, 16, FALSE,
1514 INTERLEAVED, undefined_positions[15 - 1]);
1515 GstCaps *out_caps = get_float_mc_caps (15, G_BYTE_ORDER, 32, INTERLEAVED,
1516 undefined_positions[15 - 1]);
1518 gst_structure_remove_field (gst_caps_get_structure (out_caps, 0),
1521 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1522 "int16 => float", in, in_caps, out, out_caps);
1525 /* 8 channels, NONE positions => 2 channels: should fail, no mixing allowed */
1527 guint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1528 gfloat out[] = { -1.0, -1.0 };
1529 GstCaps *in_caps = get_int_mc_caps (8, G_BYTE_ORDER, 16, 16, FALSE,
1530 INTERLEAVED, undefined_positions[8 - 1]);
1531 GstCaps *out_caps = get_float_mc_caps (2, G_BYTE_ORDER, 32, INTERLEAVED,
1534 RUN_CONVERSION_TO_FAIL ("8 channels with layout => 2 channels",
1535 in, in_caps, out, out_caps);
1538 /* 8 channels, with positions => 2 channels (makes sure channel-position
1539 * fields are removed properly in some cases in ::transform_caps, so we
1540 * don't up with caps with 2 channels and 8 channel positions) */
1542 GstAudioChannelPosition layout8ch[] = {
1543 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
1544 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
1545 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
1546 GST_AUDIO_CHANNEL_POSITION_LFE1,
1547 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
1548 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
1549 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
1550 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
1552 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1553 gint16 out[] = { 0, 0 };
1555 get_int_mc_caps (8, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, layout8ch);
1556 GstCaps *out_caps = get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE,
1559 RUN_CONVERSION ("8 channels with layout => 2 channels",
1560 in, in_caps, out, out_caps);
1566 #define SIMPLE_CAPS_TEMPLATE_STRING \
1568 "format = (string) {S8, S16LE, S24LE, S32LE}, " \
1569 "rate = (int) [ 1, MAX ], " \
1570 "channels = (int) [ 1, MAX ]"
1572 GST_START_TEST (test_preserve_width)
1574 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
1577 GST_STATIC_CAPS (SIMPLE_CAPS_TEMPLATE_STRING)
1579 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
1582 GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING)
1584 static const struct _test_formats
1588 } test_formats[] = { {
1596 GstStructure *structure;
1597 GstElement *audioconvert;
1598 GstCaps *incaps, *convert_outcaps;
1600 audioconvert = gst_check_setup_element ("audioconvert");
1601 mysrcpad = gst_check_setup_src_pad (audioconvert, &srctemplate);
1602 mysinkpad = gst_check_setup_sink_pad (audioconvert, &sinktemplate);
1604 gst_pad_set_active (mysrcpad, TRUE);
1605 gst_pad_set_active (mysinkpad, TRUE);
1607 fail_unless (gst_element_set_state (audioconvert,
1608 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1609 "could not set to playing");
1611 for (i = 0; test_formats[i].width; i++) {
1612 gint width = test_formats[i].width;
1613 incaps = get_int_caps (1, G_BIG_ENDIAN, width, width, TRUE, INTERLEAVED);
1614 gst_pad_set_caps (mysrcpad, incaps);
1616 convert_outcaps = gst_pad_get_current_caps (mysinkpad);
1617 structure = gst_caps_get_structure (convert_outcaps, 0);
1618 fail_unless_equals_string (gst_structure_get_string (structure, "format"),
1619 test_formats[i].outf);
1621 gst_caps_unref (convert_outcaps);
1622 gst_caps_unref (incaps);
1625 cleanup_audioconvert (audioconvert);
1630 GST_START_TEST (test_gap_buffers)
1632 GstBuffer *inbuffer, *outbuffer;
1633 GstElement *audioconvert;
1634 GstCaps *caps = get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED);
1635 gint16 data[] = { 0, 0, 0, 0 };
1636 gsize data_len = sizeof (data);
1639 audioconvert = setup_audioconvert (caps);
1641 fail_unless (gst_element_set_state (audioconvert,
1642 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1643 "could not set to playing");
1645 gst_check_setup_events (mysrcpad, audioconvert, caps, GST_FORMAT_TIME);
1647 inbuffer = gst_buffer_new_and_alloc (data_len);
1648 gst_buffer_fill (inbuffer, 0, data, data_len);
1649 GST_BUFFER_FLAG_SET (inbuffer, GST_BUFFER_FLAG_GAP);
1651 for (i = 0; i < 2; i++) {
1652 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (audioconvert),
1655 gst_pad_push (mysrcpad, inbuffer);
1657 fail_unless (g_list_length (buffers) == 1);
1658 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1660 fail_unless (GST_BUFFER_FLAG_IS_SET (outbuffer, GST_BUFFER_FLAG_GAP));
1662 buffers = g_list_remove (buffers, outbuffer);
1665 GST_DEBUG ("cleanup, unref buffers");
1666 gst_buffer_unref (outbuffer);
1667 cleanup_audioconvert (audioconvert);
1668 GST_DEBUG ("cleanup, unref caps");
1669 gst_caps_unref (caps);
1674 GST_START_TEST (test_layout_conversion)
1676 /* just layout conversion */
1678 gint16 in[] = { 123, 123, 1024, 1024 };
1679 gint16 out[] = { 123, 1024, 123, 1024 };
1681 RUN_CONVERSION ("int16 interleaved -> planar",
1682 in, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
1683 out, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
1684 RUN_CONVERSION ("int16 interleaved -> planar",
1685 in, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR),
1686 out, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
1688 /* int16 stereo to mono with layout conversion */
1690 gint16 in_i[] = { 16384, -256, 1024, 1024 };
1691 gint16 in_p[] = { 16384, 1024, -256, 1024 };
1692 gint16 out[] = { 8064, 1024 };
1694 RUN_CONVERSION ("int16 stereo to mono / interleaved -> planar",
1695 in_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
1696 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
1697 RUN_CONVERSION ("int16 stereo to mono / planar -> interleaved",
1698 in_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR),
1699 out, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
1701 /* int16 mono to stereo with layout conversion */
1703 gint16 in[] = { 512, 1024 };
1704 gint16 out_i[] = { 512, 512, 1024, 1024 };
1705 gint16 out_p[] = { 512, 1024, 512, 1024 };
1707 RUN_CONVERSION ("int16 mono to stereo / planar -> interleaved",
1708 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, PLANAR),
1709 out_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
1710 RUN_CONVERSION ("int16 mono to stereo / interleaved -> planar",
1711 in, get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
1712 out_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
1714 /* change format with layout conversion */
1716 gint16 in_p[] = { 0, 32767, -32767, -32768 };
1717 gint16 in_i[] = { 0, -32767, 32767, -32768 };
1718 guint16 out_p[] = { 32768, 65535, 1, 0 };
1719 guint16 out_i[] = { 32768, 1, 65535, 0 };
1721 RUN_CONVERSION ("int16 signed -> unsigned / planar -> interleaved",
1722 in_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR),
1723 out_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, FALSE, INTERLEAVED));
1724 RUN_CONVERSION ("int16 signed -> unsigned / interleaved -> planar",
1725 in_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED),
1726 out_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, FALSE, PLANAR));
1728 RUN_CONVERSION ("int16 unsigned -> signed / planar -> interleaved",
1729 out_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, FALSE, PLANAR),
1730 in_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
1731 RUN_CONVERSION ("int16 unsigned -> signed / interleaved -> planar",
1732 out_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, FALSE, INTERLEAVED),
1733 in_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
1735 /* channel mixing with layout conversion */
1737 gint16 in_i[] = { 4, 5, 4, 2, 2, 1, 8, 10, 8, 4, 4, 2 };
1738 gint16 in_p[] = { 4, 8, 5, 10, 4, 8, 2, 4, 2, 4, 1, 2 };
1739 gint16 out_i[] = { 3, 3, 6, 6 };
1740 gint16 out_p[] = { 3, 6, 3, 6 };
1742 RUN_CONVERSION ("5.1 to 2 channels / interleaved -> planar", in_i,
1743 get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, NULL),
1744 out_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
1746 RUN_CONVERSION ("5.1 to 2 channels / planar -> interleaved", in_p,
1747 get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, TRUE, PLANAR, NULL),
1748 out_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
1750 /* change format + channels + layout */
1753 0x00, 0x04, 0x00, 0x00, 0x05, 0x00, 0x00, 0x04, 0x00,
1754 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00,
1755 0x00, 0x08, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x08, 0x00,
1756 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02, 0x00
1759 0x00, 0x04, 0x00, 0x00, 0x08, 0x00, 0x00, 0x05, 0x00,
1760 0x00, 0x0a, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, 0x00,
1761 0x00, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02, 0x00,
1762 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00
1764 gint16 out_i[] = { 3, 3, 6, 6 };
1765 gint16 out_p[] = { 3, 6, 3, 6 };
1767 RUN_CONVERSION ("5.1 to 2 channels / S24LE interleaved -> S16 planar", in_i,
1768 get_int_mc_caps (6, G_LITTLE_ENDIAN, 24, 24, TRUE, INTERLEAVED, NULL),
1769 out_p, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, PLANAR));
1770 RUN_CONVERSION ("5.1 to 2 channels / S24LE planar -> S16 interleaved", in_p,
1771 get_int_mc_caps (6, G_LITTLE_ENDIAN, 24, 24, TRUE, PLANAR, NULL),
1772 out_i, get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED));
1778 GST_START_TEST (test_layout_conv_fixate_caps)
1780 GstCaps *incaps, *outcaps;
1781 GstElement *audioconvert;
1785 incaps = gst_caps_from_string ("audio/x-raw, "
1786 "format = (string) F32LE, "
1787 "layout = (string) interleaved, "
1788 "rate = (int) 44100, "
1789 "channels = (int) 1");
1790 outcaps = gst_caps_from_string ("audio/x-raw, "
1791 "format = (string) S16LE, "
1792 "layout = (string) interleaved, "
1793 "rate = (int) [ 1, MAX ], "
1794 "channels = (int) 2;"
1796 "format = (string) { F32LE, F32BE, F64LE, F64BE }, "
1797 "layout = (string) non-interleaved, "
1798 "rate = (int) [ 1, MAX ], "
1799 "channels = (int) [1, 8]");
1801 audioconvert = setup_audioconvert (outcaps);
1803 fail_unless (gst_element_set_state (audioconvert,
1804 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1805 "could not set to playing");
1807 gst_check_setup_events (mysrcpad, audioconvert, incaps, GST_FORMAT_TIME);
1809 caps = gst_pad_get_current_caps (mysinkpad);
1810 s = gst_caps_get_structure (caps, 0);
1811 assert_equals_string (gst_structure_get_string (s, "format"), "F32LE");
1812 assert_equals_string (gst_structure_get_string (s, "layout"),
1815 fail_unless (gst_element_set_state (audioconvert,
1816 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
1818 GST_DEBUG ("cleanup audioconvert");
1819 cleanup_audioconvert (audioconvert);
1820 GST_DEBUG ("cleanup, unref incaps");
1821 gst_caps_unref (incaps);
1822 gst_caps_unref (outcaps);
1828 audioconvert_suite (void)
1830 Suite *s = suite_create ("audioconvert");
1831 TCase *tc_chain = tcase_create ("general");
1833 suite_add_tcase (s, tc_chain);
1834 tcase_add_test (tc_chain, test_int16);
1835 tcase_add_test (tc_chain, test_float32);
1836 tcase_add_test (tc_chain, test_int_conversion);
1837 tcase_add_test (tc_chain, test_float_conversion);
1838 tcase_add_test (tc_chain, test_int_float_conversion);
1839 tcase_add_test (tc_chain, test_multichannel_conversion);
1840 tcase_add_test (tc_chain, test_passthrough);
1841 tcase_add_test (tc_chain, test_caps_negotiation);
1842 tcase_add_test (tc_chain, test_convert_undefined_multichannel);
1843 tcase_add_test (tc_chain, test_preserve_width);
1844 tcase_add_test (tc_chain, test_gap_buffers);
1845 tcase_add_test (tc_chain, test_layout_conversion);
1846 tcase_add_test (tc_chain, test_layout_conv_fixate_caps);
1851 GST_CHECK_MAIN (audioconvert);