aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/tests/channel_layout.c
blob: c537e7e7108d9545b0bda7f94d5418e499a0c9ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/*
 * Copyright (c) 2021 James Almer
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <inttypes.h>
#include <stdio.h>
#include <string.h>

#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"

#define BPRINT_ARGS1(bp, ...)     (bp), __VA_ARGS__
#define BPRINT_ARGS0(bp, ...)     __VA_ARGS__, (bp)
#define ORD_ARGS1(str, size, ...) (str), (size), __VA_ARGS__
#define ORD_ARGS0(str, size, ...) __VA_ARGS__, (str), (size)

// This macro presumes the AVBPrint to have been cleared before usage.
#define CMP_BPRINT_AND_NONBPRINT(bp, func_name, ARG_ORDER, ...) do {       \
    char *str;                                                             \
    int size;                                                              \
    func_name ## _bprint(BPRINT_ARGS ## ARG_ORDER((bp), __VA_ARGS__));     \
    if (strlen((bp)->str) != (bp)->len) {                                  \
        printf("strlen of AVBPrint-string returned by "#func_name"_bprint" \
               " differs from AVBPrint.len: %"SIZE_SPECIFIER" vs. %u\n",   \
               strlen((bp)->str), (bp)->len);                              \
        break;                                                             \
    }                                                                      \
    size = func_name(ORD_ARGS ## ARG_ORDER(NULL, 0, __VA_ARGS__));         \
    if (size <= 0) {                                                       \
        printf(#func_name " returned %d\n", size);                         \
        break;                                                             \
    }                                                                      \
    if ((bp)->len != size - 1) {                                           \
        printf("Return value %d of " #func_name " inconsistent with length"\
               " %u obtained from corresponding bprint version\n",         \
               size, (bp)->len);                                           \
        break;                                                             \
    }                                                                      \
    str = av_malloc(size);                                                 \
    if (!str) {                                                            \
        printf("string of size %d could not be allocated.\n", size);       \
        break;                                                             \
    }                                                                      \
    size = func_name(ORD_ARGS ## ARG_ORDER(str, size, __VA_ARGS__));       \
    if (size <= 0 || (bp)->len != size - 1) {                              \
        printf("Return value %d of " #func_name " inconsistent with length"\
               " %d obtained in first pass.\n", size, (bp)->len);          \
        av_free(str);                                                      \
        break;                                                             \
    }                                                                      \
    if (strcmp(str, (bp)->str)) {                                          \
        printf("Ordinary and _bprint versions of "#func_name" disagree: "  \
               "'%s' vs. '%s'\n", str, (bp)->str);                         \
        av_free(str);                                                      \
        break;                                                             \
    }                                                                      \
    av_free(str);                                                          \
    } while (0)


static void channel_name(AVBPrint *bp, enum AVChannel channel)
{
    av_bprint_clear(bp);
    CMP_BPRINT_AND_NONBPRINT(bp, av_channel_name, 1, channel);
}

static void channel_description(AVBPrint *bp, enum AVChannel channel)
{
    av_bprint_clear(bp);
    CMP_BPRINT_AND_NONBPRINT(bp, av_channel_description, 1, channel);
}

static void channel_layout_from_mask(AVChannelLayout *layout,
                                     AVBPrint *bp, uint64_t channel_layout)
{
    av_channel_layout_uninit(layout);
    av_bprint_clear(bp);
    if (!av_channel_layout_from_mask(layout, channel_layout) &&
         av_channel_layout_check(layout))
        CMP_BPRINT_AND_NONBPRINT(bp, av_channel_layout_describe, 0, layout);
    else
        av_bprintf(bp, "fail");
}

static void channel_layout_from_string(AVChannelLayout *layout,
                                       AVBPrint *bp, const char *channel_layout)
{
    av_channel_layout_uninit(layout);
    av_bprint_clear(bp);
    if (!av_channel_layout_from_string(layout, channel_layout) &&
         av_channel_layout_check(layout))
        CMP_BPRINT_AND_NONBPRINT(bp, av_channel_layout_describe, 0, layout);
    else
        av_bprintf(bp, "fail");
}

#define CHANNEL_NAME(x)                                                    \
    channel_name(&bp, (x));

#define CHANNEL_DESCRIPTION(x)                                             \
    channel_description(&bp, (x));

#define CHANNEL_LAYOUT_FROM_MASK(x)                                        \
    channel_layout_from_mask(&layout, &bp, (x));

#define CHANNEL_LAYOUT_FROM_STRING(x)                                      \
    channel_layout_from_string(&layout, &bp, (x));

#define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(x)                               \
    ret = av_channel_layout_channel_from_index(&layout, x);                \
    if (ret < 0)                                                           \
        ret = -1

#define CHANNEL_LAYOUT_SUBSET(x)                                           \
    mask = av_channel_layout_subset(&layout, x)

#define CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(x)                               \
    ret = av_channel_layout_index_from_channel(&layout, x);                \
    if (ret < 0)                                                           \
        ret = -1

#define CHANNEL_LAYOUT_CHANNEL_FROM_STRING(x)                              \
    ret = av_channel_layout_channel_from_string(&layout, x);               \
    if (ret < 0)                                                           \
        ret = -1

#define CHANNEL_LAYOUT_INDEX_FROM_STRING(x)                                \
    ret = av_channel_layout_index_from_string(&layout, x);                 \
    if (ret < 0)                                                           \
        ret = -1

int main(void)
{
    const AVChannelLayout *playout;
    AVChannelLayout layout = { 0 }, layout2 = { 0 };
    AVBPrint bp;
    void *iter = NULL;
    uint64_t mask;
    int ret;

    av_bprint_init(&bp, 64, AV_BPRINT_SIZE_AUTOMATIC);

    printf("Testing av_channel_layout_standard\n");
    while (playout = av_channel_layout_standard(&iter)) {
        av_channel_layout_describe_bprint(playout, &bp);
        printf("%-14s ", bp.str);
        av_bprint_clear(&bp);
        for (int i = 0; i < 63; i++) {
            int idx = av_channel_layout_index_from_channel(playout, i);
            if (idx >= 0) {
                if (idx)
                    av_bprintf(&bp, "+");
                av_channel_name_bprint(&bp, i);
            }
        }
        printf("%s\n", bp.str);
        av_bprint_clear(&bp);
    }

    printf("\nTesting av_channel_name\n");
    CHANNEL_NAME(AV_CHAN_FRONT_LEFT);
    printf("With AV_CHAN_FRONT_LEFT: %27s\n", bp.str);
    CHANNEL_NAME(AV_CHAN_FRONT_RIGHT);
    printf("With AV_CHAN_FRONT_RIGHT: %26s\n", bp.str);
    CHANNEL_NAME(63);
    printf("With 63: %43s\n", bp.str);
    CHANNEL_NAME(AV_CHAN_AMBISONIC_BASE);
    printf("With AV_CHAN_AMBISONIC_BASE: %23s\n", bp.str);
    CHANNEL_NAME(AV_CHAN_AMBISONIC_END);
    printf("With AV_CHAN_AMBISONIC_END: %24s\n", bp.str);

    printf("Testing av_channel_description\n");
    CHANNEL_DESCRIPTION(AV_CHAN_FRONT_LEFT);
    printf("With AV_CHAN_FRONT_LEFT: %27s\n", bp.str);
    CHANNEL_DESCRIPTION(AV_CHAN_FRONT_RIGHT);
    printf("With AV_CHAN_FRONT_RIGHT: %26s\n", bp.str);
    CHANNEL_DESCRIPTION(63);
    printf("With 63: %43s\n", bp.str);
    CHANNEL_DESCRIPTION(AV_CHAN_AMBISONIC_BASE);
    printf("With AV_CHAN_AMBISONIC_BASE: %23s\n", bp.str);
    CHANNEL_DESCRIPTION(AV_CHAN_AMBISONIC_END);
    printf("With AV_CHAN_AMBISONIC_END: %24s\n", bp.str);

    printf("\nTesting av_channel_from_string\n");
    printf("With \"FL\": %41d\n", av_channel_from_string("FL"));
    printf("With \"FR\": %41d\n", av_channel_from_string("FR"));
    printf("With \"USR63\": %38d\n", av_channel_from_string("USR63"));
    printf("With \"AMBI0\": %38d\n", av_channel_from_string("AMBI0"));
    printf("With \"AMBI1023\": %35d\n", av_channel_from_string("AMBI1023"));

    printf("\n==Native layouts==\n");

    printf("\nTesting av_channel_layout_from_string\n");
    CHANNEL_LAYOUT_FROM_STRING("0x3f");
    printf("With \"0x3f\": %39s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("63");
    printf("With \"63\": %41s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("6c");
    printf("With \"6c\": %41s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("6C");
    printf("With \"6C\": %41s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("6 channels");
    printf("With \"6 channels\": %33s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("6 channels (FL+FR+FC+LFE+BL+BR)");
    printf("With \"6 channels (FL+FR+FC+LFE+BL+BR)\": %12s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+LFE+BL+BR");
    printf("With \"FL+FR+FC+LFE+BL+BR\": %25s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("5.1");
    printf("With \"5.1\": %40s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("FL+FR+USR63");
    printf("With \"FL+FR+USR63\": %32s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+LFE+SL+SR");
    printf("With \"FL+FR+FC+LFE+SL+SR\": %25s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("5.1(side)");
    printf("With \"5.1(side)\": %34s\n", bp.str);

    printf("\nTesting av_channel_layout_from_mask\n");
    CHANNEL_LAYOUT_FROM_MASK(AV_CH_LAYOUT_5POINT1);
    printf("With AV_CH_LAYOUT_5POINT1: %25s\n", bp.str);

    printf("\nTesting av_channel_layout_channel_from_index\n");
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(0);
    printf("On 5.1(side) layout with 0: %24d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(1);
    printf("On 5.1(side) layout with 1: %24d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(2);
    printf("On 5.1(side) layout with 2: %24d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(3);
    printf("On 5.1(side) layout with 3: %24d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(4);
    printf("On 5.1(side) layout with 4: %24d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(5);
    printf("On 5.1(side) layout with 5: %24d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(6);
    printf("On 5.1(side) layout with 6: %24d\n", ret);

    printf("\nTesting av_channel_layout_index_from_channel\n");
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_LEFT);
    printf("On 5.1(side) layout with AV_CHAN_FRONT_LEFT: %7d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_RIGHT);
    printf("On 5.1(side) layout with AV_CHAN_FRONT_RIGHT: %6d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_CENTER);
    printf("On 5.1(side) layout with AV_CHAN_FRONT_CENTER: %5d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_LOW_FREQUENCY);
    printf("On 5.1(side) layout with AV_CHAN_LOW_FREQUENCY: %4d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_SIDE_LEFT);
    printf("On 5.1(side) layout with AV_CHAN_SIDE_LEFT: %8d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_SIDE_RIGHT);
    printf("On 5.1(side) layout with AV_CHAN_SIDE_RIGHT: %7d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_BACK_CENTER);
    printf("On 5.1(side) layout with AV_CHAN_BACK_CENTER: %6d\n", ret);

    printf("\nTesting av_channel_layout_channel_from_string\n");
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FL");
    printf("On 5.1(side) layout with \"FL\": %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FR");
    printf("On 5.1(side) layout with \"FR\": %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FC");
    printf("On 5.1(side) layout with \"FC\": %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("LFE");
    printf("On 5.1(side) layout with \"LFE\": %20d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("SL");
    printf("On 5.1(side) layout with \"SL\": %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("SR");
    printf("On 5.1(side) layout with \"SR\": %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("BC");
    printf("On 5.1(side) layout with \"BC\": %21d\n", ret);

    printf("\nTesting av_channel_layout_index_from_string\n");
    CHANNEL_LAYOUT_INDEX_FROM_STRING("FL");
    printf("On 5.1(side) layout with \"FL\": %21d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("FR");
    printf("On 5.1(side) layout with \"FR\": %21d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("FC");
    printf("On 5.1(side) layout with \"FC\": %21d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("LFE");
    printf("On 5.1(side) layout with \"LFE\": %20d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("SL");
    printf("On 5.1(side) layout with \"SL\": %21d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("SR");
    printf("On 5.1(side) layout with \"SR\": %21d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("BC");
    printf("On 5.1(side) layout with \"BC\": %21d\n", ret);

    printf("\nTesting av_channel_layout_subset\n");
    CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_STEREO);
    printf("On 5.1(side) layout with AV_CH_LAYOUT_STEREO:    0x%"PRIx64"\n", mask);
    CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_2POINT1);
    printf("On 5.1(side) layout with AV_CH_LAYOUT_2POINT1:   0x%"PRIx64"\n", mask);
    CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_4POINT1);
    printf("On 5.1(side) layout with AV_CH_LAYOUT_4POINT1:   0x%"PRIx64"\n", mask);

    printf("\n==Custom layouts==\n");

    printf("\nTesting av_channel_layout_from_string\n");
    CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+BL+BR+LFE");
    printf("With \"FL+FR+FC+BL+BR+LFE\": %34s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("2 channels (FR+FL)");
    printf("With \"2 channels (FR+FL)\": %34s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("ambisonic 1+FR+FL");
    printf("With \"ambisonic 1+FR+FL\": %35s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("ambisonic 2+FC@Foo");
    printf("With \"ambisonic 2+FC@Foo\": %34s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("FL@Foo+FR@Bar");
    printf("With \"FL@Foo+FR@Bar\": %39s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("FR+FL@Foo+USR63@Foo");
    printf("With \"FR+FL@Foo+USR63@Foo\": %33s\n", bp.str);

    ret = av_channel_layout_copy(&layout2, &layout);
    if (ret < 0) {
        printf("Copying channel layout \"FR+FL@Foo+USR63@Foo\" failed; "
               "ret %d\n", ret);
    }
    ret = av_channel_layout_compare(&layout, &layout2);
    if (ret)
        printf("Channel layout and its copy compare unequal; ret: %d\n", ret);

    printf("\nTesting av_channel_layout_index_from_string\n");
    CHANNEL_LAYOUT_INDEX_FROM_STRING("FR");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FR\": %18d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("FL");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FL\": %18d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("USR63");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"USR63\": %15d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"Foo\": %17d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("@Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"@Foo\": %16d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("FR@Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FR@Foo\": %14d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("FL@Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FL@Foo\": %14d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("USR63@Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"USR63@Foo\": %11d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_STRING("BC");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"BC\": %18d\n", ret);

    printf("\nTesting av_channel_layout_channel_from_string\n");
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FR");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FR\": %18d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FL");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FL\": %18d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("USR63");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"USR63\": %15d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"Foo\": %17d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("@Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"@Foo\": %16d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FR@Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FR@Foo\": %14d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FL@Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FL@Foo\": %14d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("USR63@Foo");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"USR63@Foo\": %11d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_STRING("BC");
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"BC\": %18d\n", ret);

    printf("\nTesting av_channel_layout_index_from_channel\n");
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_RIGHT);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CHAN_FRONT_RIGHT: %3d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_LEFT);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CHAN_FRONT_LEFT: %4d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(63);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with 63: %20d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_BACK_CENTER);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CHAN_BACK_CENTER: %3d\n", ret);

    printf("\nTesting av_channel_layout_channel_from_index\n");
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(0);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with 0: %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(1);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with 1: %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(2);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with 2: %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(3);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with 3: %21d\n", ret);

    printf("\nTesting av_channel_layout_subset\n");
    CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_STEREO);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CH_LAYOUT_STEREO: 0x%"PRIx64"\n", mask);
    CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_QUAD);
    printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CH_LAYOUT_QUAD:   0x%"PRIx64"\n", mask);

    printf("\n==Ambisonic layouts==\n");

    printf("\nTesting av_channel_layout_from_string\n");
    CHANNEL_LAYOUT_FROM_STRING("ambisonic 1");
    printf("With \"ambisonic 1\": %41s\n", bp.str);
    CHANNEL_LAYOUT_FROM_STRING("ambisonic 2+stereo");
    printf("With \"ambisonic 2+stereo\": %34s\n", bp.str);

    printf("\nTesting av_channel_layout_index_from_channel\n");
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_AMBISONIC_BASE);
    printf("On \"ambisonic 2+stereo\" layout with AV_CHAN_AMBISONIC_BASE: %d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_LEFT);
    printf("On \"ambisonic 2+stereo\" layout with AV_CHAN_FRONT_LEFT: %5d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_RIGHT);
    printf("On \"ambisonic 2+stereo\" layout with AV_CHAN_FRONT_RIGHT: %4d\n", ret);
    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_BACK_CENTER);
    printf("On \"ambisonic 2+stereo\" layout with AV_CHAN_BACK_CENTER: %4d\n", ret);

    printf("\nTesting av_channel_layout_channel_from_index\n");
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(0);
    printf("On \"ambisonic 2+stereo\" layout with 0: %22d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(9);
    printf("On \"ambisonic 2+stereo\" layout with 9: %22d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(10);
    printf("On \"ambisonic 2+stereo\" layout with 10: %21d\n", ret);
    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(11);
    printf("On \"ambisonic 2+stereo\" layout with 11: %21d\n", ret);

    printf("\nTesting av_channel_layout_subset\n");
    CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_STEREO);
    printf("On \"ambisonic 2+stereo\" layout with AV_CH_LAYOUT_STEREO:  0x%"PRIx64"\n", mask);
    CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_QUAD);
    printf("On \"ambisonic 2+stereo\" layout with AV_CH_LAYOUT_QUAD:    0x%"PRIx64"\n", mask);

    av_channel_layout_uninit(&layout);
    av_channel_layout_uninit(&layout2);
    av_bprint_finalize(&bp, NULL);

    return 0;
}