1 /* GStreamer
2 *
3 * unit test for audioconvert
4 *
5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
6 * Copyright (C) <2007> Tim-Philipp Müller <tim centricular net>
7 *
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.
12 *
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.
17 *
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.
22 */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gst/check/gstcheck.h>
28 #include <gst/audio/audio.h>
29
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;
34
35 #define FORMATS "{ F32LE, F32BE, F64LE, F64BE, " \
36 "S32LE, S32BE, U32LE, U32BE, " \
37 "S24LE, S24BE, U24LE, U24BE, " \
38 "S16LE, S16BE, U16LE, U16BE, " \
39 "S8, U8 } "
40
41 #define CONVERT_CAPS_TEMPLATE_STRING \
42 "audio/x-raw, " \
43 "format = (string) "FORMATS", " \
44 "rate = (int) [ 1, MAX ], " \
45 "channels = (int) [ 1, MAX ]"
46
47 /* takes over reference for outcaps */
48 static GstElement *
setup_audioconvert(GstCaps * outcaps)49 setup_audioconvert (GstCaps * outcaps)
50 {
51 GstPadTemplate *sinktemplate;
52 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
53 GST_PAD_SRC,
54 GST_PAD_ALWAYS,
55 GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING)
56 );
57 GstElement *audioconvert;
58
59 sinktemplate =
60 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, outcaps);
61
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);
67 mysinkpad =
68 gst_check_setup_sink_pad_from_template (audioconvert, sinktemplate);
69 /* this installs a getcaps func that will always return the caps we set
70 * later */
71 gst_pad_use_fixed_caps (mysinkpad);
72
73 gst_pad_set_active (mysrcpad, TRUE);
74 gst_pad_set_active (mysinkpad, TRUE);
75
76 gst_object_unref (sinktemplate);
77
78 return audioconvert;
79 }
80
81 static void
cleanup_audioconvert(GstElement * audioconvert)82 cleanup_audioconvert (GstElement * audioconvert)
83 {
84 GST_DEBUG ("cleanup_audioconvert");
85
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);
91 }
92
93 /* returns a newly allocated caps */
94 static GstCaps *
get_int_caps(guint channels,gint endianness,guint width,guint depth,gboolean signedness,GstAudioLayout layout)95 get_int_caps (guint channels, gint endianness, guint width,
96 guint depth, gboolean signedness, GstAudioLayout layout)
97 {
98 GstCaps *caps;
99 GstAudioFormat fmt;
100 GstAudioInfo info;
101
102 g_assert (channels <= 2);
103
104 GST_DEBUG ("channels:%d, endianness:%d, width:%d, depth:%d, signedness:%d",
105 channels, endianness, width, depth, signedness);
106
107 fmt = gst_audio_format_build_integer (signedness, endianness, width, depth);
108
109 gst_audio_info_init (&info);
110 gst_audio_info_set_format (&info, fmt, GST_AUDIO_DEF_RATE, channels, NULL);
111 info.layout = layout;
112
113 caps = gst_audio_info_to_caps (&info);
114 fail_unless (caps != NULL);
115 GST_DEBUG ("returning caps %" GST_PTR_FORMAT, caps);
116
117 return caps;
118 }
119
120 static GstAudioFormat
get_float_format(gint endianness,gint width)121 get_float_format (gint endianness, gint width)
122 {
123 if (endianness == G_LITTLE_ENDIAN) {
124 if (width == 32)
125 return GST_AUDIO_FORMAT_F32LE;
126 else
127 return GST_AUDIO_FORMAT_F64LE;
128 } else {
129 if (width == 32)
130 return GST_AUDIO_FORMAT_F32BE;
131 else
132 return GST_AUDIO_FORMAT_F64BE;
133 }
134 }
135
136 /* returns a newly allocated caps */
137 static GstCaps *
get_float_caps(guint channels,gint endianness,guint width,GstAudioLayout layout)138 get_float_caps (guint channels, gint endianness, guint width,
139 GstAudioLayout layout)
140 {
141 GstCaps *caps;
142 GstAudioInfo info;
143
144 g_assert (channels <= 2);
145
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;
150
151 caps = gst_audio_info_to_caps (&info);
152 fail_unless (caps != NULL);
153 GST_DEBUG ("returning caps %" GST_PTR_FORMAT, caps);
154
155 return caps;
156 }
157
158 /* Copied from vorbis; the particular values used don't matter */
159 static GstAudioChannelPosition channelpositions[][6] = {
160 { /* Mono */
161 GST_AUDIO_CHANNEL_POSITION_MONO},
162 { /* Stereo */
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},
169 { /* Quadraphonic */
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,
174 },
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,
181 },
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,
189 }
190 };
191
192 /* we get this when recording from a soundcard with lots of input channels */
193 static GstAudioChannelPosition undefined_positions[][15] = {
194 {
195 GST_AUDIO_CHANNEL_POSITION_NONE},
196 {
197 GST_AUDIO_CHANNEL_POSITION_NONE,
198 GST_AUDIO_CHANNEL_POSITION_NONE},
199 {
200 GST_AUDIO_CHANNEL_POSITION_NONE,
201 GST_AUDIO_CHANNEL_POSITION_NONE,
202 GST_AUDIO_CHANNEL_POSITION_NONE},
203 {
204 GST_AUDIO_CHANNEL_POSITION_NONE,
205 GST_AUDIO_CHANNEL_POSITION_NONE,
206 GST_AUDIO_CHANNEL_POSITION_NONE,
207 GST_AUDIO_CHANNEL_POSITION_NONE},
208 {
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},
214 {
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},
221 {
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},
229 {
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},
238 {
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},
248 {
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},
259 {
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},
271 {
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},
284 {
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},
298 {
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},
313 {
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}
329 };
330
331 /* For channels > 2, caps have to have channel positions. This adds some simple
332 * ones. Only implemented for channels between 1 and 6.
333 */
334 static GstCaps *
get_float_mc_caps(guint channels,gint endianness,guint width,GstAudioLayout layout,const GstAudioChannelPosition * position)335 get_float_mc_caps (guint channels, gint endianness, guint width,
336 GstAudioLayout layout, const GstAudioChannelPosition * position)
337 {
338 GstCaps *caps;
339 GstAudioInfo info;
340
341 gst_audio_info_init (&info);
342
343 if (position) {
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]);
349 } else {
350 GstAudioChannelPosition pos[64];
351 gint i;
352
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);
357 }
358
359 info.layout = layout;
360
361 caps = gst_audio_info_to_caps (&info);
362 fail_unless (caps != NULL);
363
364 GST_DEBUG ("returning caps %" GST_PTR_FORMAT, caps);
365
366 return caps;
367 }
368
369 static GstCaps *
get_int_mc_caps(guint channels,gint endianness,guint width,guint depth,gboolean signedness,GstAudioLayout layout,const GstAudioChannelPosition * position)370 get_int_mc_caps (guint channels, gint endianness, guint width,
371 guint depth, gboolean signedness, GstAudioLayout layout,
372 const GstAudioChannelPosition * position)
373 {
374 GstCaps *caps;
375 GstAudioFormat fmt;
376 GstAudioInfo info;
377
378 fmt = gst_audio_format_build_integer (signedness, endianness, width, depth);
379
380 gst_audio_info_init (&info);
381
382 if (position) {
383 gst_audio_info_set_format (&info, fmt, GST_AUDIO_DEF_RATE, channels,
384 position);
385 } else if (channels <= 6) {
386 gst_audio_info_set_format (&info, fmt, GST_AUDIO_DEF_RATE, channels,
387 channelpositions[channels - 1]);
388 } else {
389 GstAudioChannelPosition pos[64];
390 gint i;
391
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);
395 }
396
397 info.layout = layout;
398
399 caps = gst_audio_info_to_caps (&info);
400 fail_unless (caps != NULL);
401
402 GST_DEBUG ("returning caps %" GST_PTR_FORMAT, caps);
403
404 return caps;
405 }
406
407 /* eats the refs to the caps */
408 static void
verify_convert(const gchar * which,void * in,int inlength,GstCaps * incaps,void * out,int outlength,GstCaps * outcaps,GstFlowReturn expected_flow,gboolean in_place_allowed)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)
412 {
413 GstBuffer *inbuffer, *outbuffer;
414 GstElement *audioconvert;
415 GstAudioInfo in_info;
416
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);
424
425 fail_unless (gst_element_set_state (audioconvert,
426 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
427 "could not set to playing");
428
429 gst_check_setup_events (mysrcpad, audioconvert, incaps, GST_FORMAT_TIME);
430
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);
435
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);
438
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),
443 FALSE);
444 }
445
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");
450
451 if (expected_flow != GST_FLOW_OK)
452 goto done;
453
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);
457
458 if (!in_place_allowed) {
459 /* release extra ref */
460 gst_buffer_unref (inbuffer);
461 }
462
463 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
464 fail_unless_equals_int (gst_buffer_get_size (outbuffer), outlength);
465
466 gst_check_buffer_data (outbuffer, out, outlength);
467
468 /* make sure that the channel positions are not lost */
469 {
470 GstStructure *in_s, *out_s;
471 gint out_chans;
472 GstCaps *ccaps;
473
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));
478
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");
485 }
486 }
487 gst_caps_unref (ccaps);
488 }
489
490 buffers = g_list_remove (buffers, outbuffer);
491 gst_buffer_unref (outbuffer);
492
493 done:
494 fail_unless (gst_element_set_state (audioconvert,
495 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
496 /* cleanup */
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);
502 }
503
504
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, \
508 TRUE)
509
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)
514
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, \
518 FALSE)
519
520 #define INTERLEAVED GST_AUDIO_LAYOUT_INTERLEAVED
521 #define PLANAR GST_AUDIO_LAYOUT_NON_INTERLEAVED
522
GST_START_TEST(test_int16)523 GST_START_TEST (test_int16)
524 {
525 /* stereo to mono */
526 {
527 gint16 in_i[] = { 16384, -256, 1024, 1024 };
528 gint16 in_p[] = { 16384, 1024, -256, 1024 };
529 gint16 out[] = { 8064, 1024 };
530
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));
537 }
538 /* mono to stereo */
539 {
540 gint16 in[] = { 512, 1024 };
541 gint16 out_i[] = { 512, 512, 1024, 1024 };
542 gint16 out_p[] = { 512, 1024, 512, 1024 };
543
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));
550 }
551 /* signed -> unsigned */
552 {
553 gint16 in[] = { 0, -32767, 32767, -32768 };
554 guint16 out[] = { 32768, 1, 65535, 0 };
555
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));
562
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));
569 }
570 }
571
572 GST_END_TEST;
573
574
GST_START_TEST(test_float32)575 GST_START_TEST (test_float32)
576 {
577 /* stereo to mono */
578 {
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 };
582
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));
589 }
590 /* mono to stereo */
591 {
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 };
595
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));
602 }
603 }
604
605 GST_END_TEST;
606
607
GST_START_TEST(test_int_conversion)608 GST_START_TEST (test_int_conversion)
609 {
610 /* 8 <-> 16 signed */
611 /* NOTE: if audioconvert was doing dithering we'd have a problem */
612 {
613 gint8 in[] = { 0, 1, 2, 127, -127 };
614 gint16 out[] = { 0, 256, 512, 32512, -32512 };
615
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)
619 );
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)
623 );
624 }
625 /* 16 -> 8 signed */
626 {
627 gint16 in[] = { 0, 127, 128, 256, 256 + 127, 256 + 128 };
628 gint8 out[] = { 0, 0, 1, 1, 1, 2 };
629
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)
633 );
634 }
635 /* 8 unsigned <-> 16 signed */
636 /* NOTE: if audioconvert was doing dithering we'd have a problem */
637 {
638 guint8 in[] = { 128, 129, 130, 255, 1 };
639 gint16 out[] = { 0, 256, 512, 32512, -32512 };
640 GstCaps *incaps, *outcaps;
641
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)
651 );
652 }
653 /* 8 <-> 24 signed */
654 /* NOTE: if audioconvert was doing dithering we'd have a problem */
655 {
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 */
660
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,
663 TRUE, INTERLEAVED)
664 );
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,
667 TRUE, INTERLEAVED)
668 );
669 }
670
671 /* 16 bit signed <-> unsigned */
672 {
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)
678 );
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)
682 );
683 }
684
685 /* 32 bit signed -> 16 bit signed for rounding check */
686 /* NOTE: if audioconvert was doing dithering we'd have a problem */
687 {
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),
693 (-(32 << 16))
694 };
695 gint16 out[] = { 0, G_MININT16, G_MAXINT16,
696 32, 33, 32,
697 33, 31,
698 -31, -32,
699 -31, -33,
700 -32
701 };
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)
705 );
706 }
707
708 /* 32 bit signed -> 16 bit unsigned for rounding check */
709 /* NOTE: if audioconvert was doing dithering we'd have a problem */
710 {
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),
716 (-(32 << 16))
717 };
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,
723 (1 << 15) - 32
724 };
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)
728 );
729 }
730 }
731
732 GST_END_TEST;
733
GST_START_TEST(test_float_conversion)734 GST_START_TEST (test_float_conversion)
735 {
736 /* 64-bit float <-> 32-bit float */
737 {
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 };
740
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));
744
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));
748 }
749
750 /* 32-bit float little endian <-> big endian */
751 {
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)
754 };
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)
757 };
758
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));
762
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));
766 }
767
768 /* 64-bit float little endian <-> big endian */
769 {
770 gdouble le[] =
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)
773 };
774 gdouble be[] =
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)
777 };
778
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));
782
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));
786 }
787 }
788
789 GST_END_TEST;
790
GST_START_TEST(test_int_float_conversion)791 GST_START_TEST (test_int_float_conversion)
792 {
793 /* 32 float <-> 16 signed */
794 /* NOTE: if audioconvert was doing dithering we'd have a problem */
795 {
796 gfloat in_le[] =
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),
799 GFLOAT_TO_LE (-1.1)
800 };
801 gfloat in_be[] =
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),
804 GFLOAT_TO_BE (-1.1)
805 };
806 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
807
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));
817 }
818
819 {
820 gint16 in[] = { 0, -32768, 16384, -16384 };
821 gfloat out[] = { 0.0, -1.0, 0.5, -0.5 };
822
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));
826 }
827
828 /* 64 float <-> 16 signed */
829 /* NOTE: if audioconvert was doing dithering we'd have a problem */
830 {
831 gdouble in_le[] =
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),
834 GDOUBLE_TO_LE (-1.1)
835 };
836 gdouble in_be[] =
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),
839 GDOUBLE_TO_BE (-1.1)
840 };
841 gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 };
842
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));
852 }
853 {
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 */
859 };
860
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));
864 }
865 {
866 gint32 in[] =
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 */
872 };
873
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));
877 }
878 }
879
880 GST_END_TEST;
881
GST_START_TEST(test_multichannel_conversion)882 GST_START_TEST (test_multichannel_conversion)
883 {
884 {
885 gfloat in[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
886 gfloat out[] = { 0.0, 0.0 };
887
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,
893 INTERLEAVED, NULL));
894 }
895
896 {
897 gint16 in[] = { 0, 0, 0, 0, 0, 0 };
898 gint16 out[] = { 0, 0 };
899
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));
906 }
907
908 {
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
915 };
916 GstCaps *in_caps =
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);
920
921 RUN_CONVERSION ("1 channels to 2 with standard layout", in,
922 in_caps, out, out_caps);
923 }
924
925 {
926 gint16 in[] = { 1, 2 };
927 gint16 out[] = { 1, 1, 2, 2 };
928 GstCaps *in_caps =
929 get_int_caps (1, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED);
930 GstCaps *out_caps =
931 get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED);
932
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));
935
936 RUN_CONVERSION ("2 channels to 1 with standard layout and no positions set",
937 out, out_caps, in, in_caps);
938 }
939
940 {
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
948 };
949 GstCaps *in_caps =
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);
953
954 RUN_CONVERSION ("1 channels to 2 with non-standard layout", in,
955 in_caps, out, out_caps);
956 }
957
958 {
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
964 };
965 GstAudioChannelPosition out_layout[1] =
966 { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER };
967 GstCaps *in_caps =
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);
971
972 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
973 in_caps, out, out_caps);
974 }
975
976 {
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
982 };
983 GstAudioChannelPosition out_layout[1] = { GST_AUDIO_CHANNEL_POSITION_MONO };
984 GstCaps *in_caps =
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);
988
989 RUN_CONVERSION ("2 channels to 1 with standard layout", in,
990 in_caps, out, out_caps);
991 }
992
993 {
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
999 };
1000 GstAudioChannelPosition out_layout[1] = { GST_AUDIO_CHANNEL_POSITION_MONO };
1001 GstCaps *in_caps =
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);
1005
1006 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1007 in_caps, out, out_caps);
1008 }
1009
1010 {
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
1016 };
1017 GstAudioChannelPosition out_layout[1] = { GST_AUDIO_CHANNEL_POSITION_MONO };
1018 GstCaps *in_caps =
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);
1022
1023 RUN_CONVERSION ("2 channels to 1 with non-standard layout", in,
1024 in_caps, out, out_caps);
1025 }
1026 {
1027 gint16 in[] = { 4, 5, 4, 2, 2, 1 };
1028 gint16 out[] = { 3, 3 };
1029 GstCaps *in_caps =
1030 get_int_mc_caps (6, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, NULL);
1031 GstCaps *out_caps =
1032 get_int_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED);
1033
1034 RUN_CONVERSION ("5.1 to 2 channels", in, in_caps, out, out_caps);
1035 }
1036 {
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,
1051 };
1052 GstCaps *in_caps = get_int_mc_caps (11, G_BYTE_ORDER, 16, 16, TRUE,
1053 INTERLEAVED, in_layout);
1054 GstCaps *out_caps =
1055 get_int_mc_caps (2, G_BYTE_ORDER, 16, 16, TRUE, INTERLEAVED, NULL);
1056
1057 RUN_CONVERSION ("11 channels to 2", in, in_caps, out, out_caps);
1058 }
1059 {
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,
1074 };
1075 GstCaps *in_caps =
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);
1079
1080 RUN_CONVERSION ("2 channels to 11", in, in_caps, out, out_caps);
1081 }
1082
1083 }
1084
1085 GST_END_TEST;
1086
GST_START_TEST(test_passthrough)1087 GST_START_TEST (test_passthrough)
1088 {
1089 /* int 8 bit */
1090 {
1091 gint8 data[] = { 0, 1, 2, 127, -127 };
1092
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)
1096 );
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)
1100 );
1101 }
1102 /* int 16 bit signed */
1103 {
1104 gint16 data[] = { 0, 256, 512, 32512, -32512 };
1105
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)
1109 );
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)
1113 );
1114 }
1115 /* int 32 bit signed */
1116 {
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),
1122 (-(32 << 16))
1123 };
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)
1127 );
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)
1131 );
1132 }
1133
1134 /* int 16 bit signed stereo */
1135 {
1136 gint16 data[] = { 0, 0, 1, 1, 2, 2, 3, 3 };
1137
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));
1144 }
1145 }
1146
1147 GST_END_TEST;
1148
GST_START_TEST(test_caps_negotiation)1149 GST_START_TEST (test_caps_negotiation)
1150 {
1151 GstElement *src, *ac1, *ac2, *ac3, *sink;
1152 GstElement *pipeline;
1153 GstPad *ac3_src;
1154 GstCaps *caps1, *caps2;
1155
1156 pipeline = gst_pipeline_new ("test");
1157
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");
1165
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);
1169
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");
1175
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));
1179
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");
1184
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);
1189
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");
1194
1195 caps2 = gst_pad_query_caps (ac3_src, NULL);
1196
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));
1200
1201 gst_caps_unref (caps1);
1202 gst_caps_unref (caps2);
1203
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");
1208
1209 gst_object_unref (ac3_src);
1210 gst_object_unref (pipeline);
1211 }
1212
1213 GST_END_TEST;
1214
GST_START_TEST(test_convert_undefined_multichannel)1215 GST_START_TEST (test_convert_undefined_multichannel)
1216 {
1217 /* (A) CONVERSION FROM 'WORSE' TO 'BETTER' FORMAT */
1218
1219 /* 1 channel, NONE positions, int8 => int16 */
1220 {
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]);
1227
1228 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1229 "int8 => int16", in, in_caps, out, out_caps);
1230 }
1231
1232 /* 2 channels, NONE positions, int8 => int16 */
1233 {
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]);
1240
1241 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1242 "int8 => int16", in, in_caps, out, out_caps);
1243 }
1244
1245 /* 6 channels, NONE positions, int8 => int16 */
1246 {
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]);
1253
1254 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1255 "int8 => int16", in, in_caps, out, out_caps);
1256 }
1257
1258 /* 9 channels, NONE positions, int8 => int16 */
1259 {
1260 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1261 0x0000, 0xff00, 0x0000
1262 };
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]);
1268
1269 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1270 "int8 => int16", in, in_caps, out, out_caps);
1271 }
1272
1273 /* 15 channels, NONE positions, int8 => int16 */
1274 {
1275 guint16 out[] =
1276 { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00,
1277 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000
1278 };
1279 guint8 in[] =
1280 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1281 0x20, 0x80, 0x20, 0x00
1282 };
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]);
1287
1288 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1289 "int8 => int16", in, in_caps, out, out_caps);
1290 }
1291
1292 /* (B) CONVERSION FROM 'BETTER' TO 'WORSE' FORMAT */
1293
1294 /* 1 channel, NONE positions, int16 => int8 */
1295 {
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]);
1302
1303 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1304 "int16 => int8", in, in_caps, out, out_caps);
1305 }
1306
1307 /* 2 channels, NONE positions, int16 => int8 */
1308 {
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]);
1315
1316 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1317 "int16 => int8", in, in_caps, out, out_caps);
1318 }
1319
1320 /* 6 channels, NONE positions, int16 => int8 */
1321 {
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]);
1328
1329 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1330 "int16 => int8", in, in_caps, out, out_caps);
1331 }
1332
1333 /* 9 channels, NONE positions, int16 => int8 */
1334 {
1335 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1336 0x0000, 0xff00, 0x0000
1337 };
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]);
1343
1344 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1345 "int16 => int8", in, in_caps, out, out_caps);
1346 }
1347
1348 /* 15 channels, NONE positions, int16 => int8 */
1349 {
1350 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1351 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1352 0x0000
1353 };
1354 guint8 out[] =
1355 { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00,
1356 0x20, 0x80, 0x20, 0x00
1357 };
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]);
1362
1363 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1364 "int16 => int8", in, in_caps, out, out_caps);
1365 }
1366
1367
1368 /* (C) NO CONVERSION, SAME FORMAT */
1369
1370 /* 1 channel, NONE positions, int16 => int16 */
1371 {
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]);
1378
1379 RUN_CONVERSION ("1 channel, undefined layout, identity conversion, "
1380 "int16 => int16", in, in_caps, out, out_caps);
1381 }
1382
1383 /* 2 channels, NONE positions, int16 => int16 */
1384 {
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]);
1391
1392 RUN_CONVERSION ("2 channels, undefined layout, identity conversion, "
1393 "int16 => int16", in, in_caps, out, out_caps);
1394 }
1395
1396 /* 6 channels, NONE positions, int16 => int16 */
1397 {
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]);
1404
1405 RUN_CONVERSION ("6 channels, undefined layout, identity conversion, "
1406 "int16 => int16", in, in_caps, out, out_caps);
1407 }
1408
1409 /* 9 channels, NONE positions, int16 => int16 */
1410 {
1411 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1412 0x0000, 0xff00, 0x0000
1413 };
1414 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1415 0x0000, 0xff00, 0x0000
1416 };
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]);
1421
1422 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1423 "int16 => int16", in, in_caps, out, out_caps);
1424 }
1425
1426 /* 15 channels, NONE positions, int16 => int16 */
1427 {
1428 guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1429 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1430 0x0000
1431 };
1432 guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1433 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000,
1434 0x0000
1435 };
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]);
1440
1441 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1442 "int16 => int16", in, in_caps, out, out_caps);
1443 }
1444
1445
1446 /* (C) int16 => float */
1447
1448 /* 9 channels, NONE positions, int16 => float */
1449 {
1450 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1451 0x0000, 0x8000, 0x0000
1452 };
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]);
1458
1459 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1460 "int16 => float", in, in_caps, out, out_caps);
1461 }
1462
1463 /* 15 channels, NONE positions, int16 => float */
1464 {
1465 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1466 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1467 0x0000
1468 };
1469 gfloat out[] =
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,
1471 0.0, -1.0
1472 };
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]);
1477
1478 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1479 "int16 => float", in, in_caps, out, out_caps);
1480 }
1481
1482
1483 /* 9 channels, NONE positions, int16 => float (same as above, but no
1484 * position on output caps to see if audioconvert transforms correctly) */
1485 {
1486 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1487 0x0000, 0x8000, 0x0000
1488 };
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]);
1494
1495 gst_structure_remove_field (gst_caps_get_structure (out_caps, 0),
1496 "channel-mask");
1497
1498 RUN_CONVERSION ("9 channels, undefined layout, identity conversion, "
1499 "int16 => float", in, in_caps, out, out_caps);
1500 }
1501
1502 /* 15 channels, NONE positions, int16 => float (same as above, but no
1503 * position on output caps to see if audioconvert transforms correctly) */
1504 {
1505 guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1506 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000,
1507 0x0000
1508 };
1509 gfloat out[] =
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,
1511 0.0, -1.0
1512 };
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]);
1517
1518 gst_structure_remove_field (gst_caps_get_structure (out_caps, 0),
1519 "channel-mask");
1520
1521 RUN_CONVERSION ("15 channels, undefined layout, identity conversion, "
1522 "int16 => float", in, in_caps, out, out_caps);
1523 }
1524
1525 /* 8 channels, NONE positions => 2 channels: should fail, no mixing allowed */
1526 {
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,
1532 NULL);
1533
1534 RUN_CONVERSION_TO_FAIL ("8 channels with layout => 2 channels",
1535 in, in_caps, out, out_caps);
1536 }
1537
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) */
1541 {
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
1551 };
1552 gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1553 gint16 out[] = { 0, 0 };
1554 GstCaps *in_caps =
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,
1557 INTERLEAVED, NULL);
1558
1559 RUN_CONVERSION ("8 channels with layout => 2 channels",
1560 in, in_caps, out, out_caps);
1561 }
1562 }
1563
1564 GST_END_TEST;
1565
1566 #define SIMPLE_CAPS_TEMPLATE_STRING \
1567 "audio/x-raw, " \
1568 "format = (string) {S8, S16LE, S24LE, S32LE}, " \
1569 "rate = (int) [ 1, MAX ], " \
1570 "channels = (int) [ 1, MAX ]"
1571
GST_START_TEST(test_preserve_width)1572 GST_START_TEST (test_preserve_width)
1573 {
1574 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
1575 GST_PAD_SINK,
1576 GST_PAD_ALWAYS,
1577 GST_STATIC_CAPS (SIMPLE_CAPS_TEMPLATE_STRING)
1578 );
1579 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
1580 GST_PAD_SRC,
1581 GST_PAD_ALWAYS,
1582 GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING)
1583 );
1584 static const struct _test_formats
1585 {
1586 int width;
1587 const gchar *outf;
1588 } test_formats[] = { {
1589 8, "S8"}, {
1590 16, "S16LE"}, {
1591 24, "S24LE"}, {
1592 32, "S32LE"}, {
1593 0, NULL}};
1594
1595 gint i;
1596 GstStructure *structure;
1597 GstElement *audioconvert;
1598 GstCaps *incaps, *convert_outcaps;
1599
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);
1603
1604 gst_pad_set_active (mysrcpad, TRUE);
1605 gst_pad_set_active (mysinkpad, TRUE);
1606
1607 fail_unless (gst_element_set_state (audioconvert,
1608 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1609 "could not set to playing");
1610
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);
1615
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);
1620
1621 gst_caps_unref (convert_outcaps);
1622 gst_caps_unref (incaps);
1623 }
1624
1625 cleanup_audioconvert (audioconvert);
1626 }
1627
1628 GST_END_TEST;
1629
GST_START_TEST(test_gap_buffers)1630 GST_START_TEST (test_gap_buffers)
1631 {
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);
1637 gint i;
1638
1639 audioconvert = setup_audioconvert (caps);
1640
1641 fail_unless (gst_element_set_state (audioconvert,
1642 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1643 "could not set to playing");
1644
1645 gst_check_setup_events (mysrcpad, audioconvert, caps, GST_FORMAT_TIME);
1646
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);
1650
1651 for (i = 0; i < 2; i++) {
1652 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (audioconvert),
1653 (i == 0));
1654
1655 gst_pad_push (mysrcpad, inbuffer);
1656
1657 fail_unless (g_list_length (buffers) == 1);
1658 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1659
1660 fail_unless (GST_BUFFER_FLAG_IS_SET (outbuffer, GST_BUFFER_FLAG_GAP));
1661
1662 buffers = g_list_remove (buffers, outbuffer);
1663 }
1664
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);
1670 }
1671
1672 GST_END_TEST;
1673
GST_START_TEST(test_layout_conversion)1674 GST_START_TEST (test_layout_conversion)
1675 {
1676 /* just layout conversion */
1677 {
1678 gint16 in[] = { 123, 123, 1024, 1024 };
1679 gint16 out[] = { 123, 1024, 123, 1024 };
1680
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));
1687 }
1688 /* int16 stereo to mono with layout conversion */
1689 {
1690 gint16 in_i[] = { 16384, -256, 1024, 1024 };
1691 gint16 in_p[] = { 16384, 1024, -256, 1024 };
1692 gint16 out[] = { 8064, 1024 };
1693
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));
1700 }
1701 /* int16 mono to stereo with layout conversion */
1702 {
1703 gint16 in[] = { 512, 1024 };
1704 gint16 out_i[] = { 512, 512, 1024, 1024 };
1705 gint16 out_p[] = { 512, 1024, 512, 1024 };
1706
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));
1713 }
1714 /* change format with layout conversion */
1715 {
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 };
1720
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));
1727
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));
1734 }
1735 /* channel mixing with layout conversion */
1736 {
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 };
1741
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));
1745
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));
1749 }
1750 /* change format + channels + layout */
1751 {
1752 guint8 in_i[] = {
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
1757 };
1758 guint8 in_p[] = {
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
1763 };
1764 gint16 out_i[] = { 3, 3, 6, 6 };
1765 gint16 out_p[] = { 3, 6, 3, 6 };
1766
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));
1773 }
1774 }
1775
1776 GST_END_TEST;
1777
GST_START_TEST(test_layout_conv_fixate_caps)1778 GST_START_TEST (test_layout_conv_fixate_caps)
1779 {
1780 GstCaps *incaps, *outcaps;
1781 GstElement *audioconvert;
1782 GstCaps *caps;
1783 GstStructure *s;
1784
1785 incaps = gst_caps_from_string ("audio/x-raw, "
1786 "format = (string) F32LE, "
1787 "layout = (string) interleaved, "
1788 "rate = (int) 44100, " "channels = (int) 1");
1789 outcaps = gst_caps_from_string ("audio/x-raw, "
1790 "format = (string) S16LE, "
1791 "layout = (string) interleaved, "
1792 "rate = (int) [ 1, MAX ], "
1793 "channels = (int) 2;"
1794 "audio/x-raw, "
1795 "format = (string) { F32LE, F32BE, F64LE, F64BE }, "
1796 "layout = (string) non-interleaved, "
1797 "rate = (int) [ 1, MAX ], " "channels = (int) [1, 8]");
1798
1799 audioconvert = setup_audioconvert (outcaps);
1800
1801 fail_unless (gst_element_set_state (audioconvert,
1802 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1803 "could not set to playing");
1804
1805 gst_check_setup_events (mysrcpad, audioconvert, incaps, GST_FORMAT_TIME);
1806
1807 caps = gst_pad_get_current_caps (mysinkpad);
1808 s = gst_caps_get_structure (caps, 0);
1809 assert_equals_string (gst_structure_get_string (s, "format"), "F32LE");
1810 assert_equals_string (gst_structure_get_string (s, "layout"),
1811 "non-interleaved");
1812 gst_clear_caps (&caps);
1813
1814 fail_unless (gst_element_set_state (audioconvert,
1815 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
1816 /* cleanup */
1817 GST_DEBUG ("cleanup audioconvert");
1818 cleanup_audioconvert (audioconvert);
1819 GST_DEBUG ("cleanup, unref incaps");
1820 gst_caps_unref (incaps);
1821 gst_caps_unref (outcaps);
1822 }
1823
1824 GST_END_TEST;
1825
1826 static Suite *
audioconvert_suite(void)1827 audioconvert_suite (void)
1828 {
1829 Suite *s = suite_create ("audioconvert");
1830 TCase *tc_chain = tcase_create ("general");
1831
1832 suite_add_tcase (s, tc_chain);
1833 tcase_add_test (tc_chain, test_int16);
1834 tcase_add_test (tc_chain, test_float32);
1835 tcase_add_test (tc_chain, test_int_conversion);
1836 tcase_add_test (tc_chain, test_float_conversion);
1837 tcase_add_test (tc_chain, test_int_float_conversion);
1838 tcase_add_test (tc_chain, test_multichannel_conversion);
1839 tcase_add_test (tc_chain, test_passthrough);
1840 tcase_add_test (tc_chain, test_caps_negotiation);
1841 tcase_add_test (tc_chain, test_convert_undefined_multichannel);
1842 tcase_add_test (tc_chain, test_preserve_width);
1843 tcase_add_test (tc_chain, test_gap_buffers);
1844 tcase_add_test (tc_chain, test_layout_conversion);
1845 tcase_add_test (tc_chain, test_layout_conv_fixate_caps);
1846
1847 return s;
1848 }
1849
1850 GST_CHECK_MAIN (audioconvert);
1851