FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/channel_layout.c
Date: 2026-04-24 19:58:39
Exec Total Coverage
Lines: 234 243 96.3%
Functions: 7 7 100.0%
Branches: 128 234 54.7%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2021 James Almer
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "libavutil/bprint.h"
26 #include "libavutil/channel_layout.h"
27 #include "libavutil/error.h"
28 #include "libavutil/macros.h"
29 #include "libavutil/mem.h"
30
31 #define BPRINT_ARGS1(bp, ...) (bp), __VA_ARGS__
32 #define BPRINT_ARGS0(bp, ...) __VA_ARGS__, (bp)
33 #define ORD_ARGS1(str, size, ...) (str), (size), __VA_ARGS__
34 #define ORD_ARGS0(str, size, ...) __VA_ARGS__, (str), (size)
35
36 // This macro presumes the AVBPrint to have been cleared before usage.
37 #define CMP_BPRINT_AND_NONBPRINT(bp, func_name, ARG_ORDER, ...) do { \
38 char *str; \
39 int size; \
40 func_name ## _bprint(BPRINT_ARGS ## ARG_ORDER((bp), __VA_ARGS__)); \
41 if (strlen((bp)->str) != (bp)->len) { \
42 printf("strlen of AVBPrint-string returned by "#func_name"_bprint" \
43 " differs from AVBPrint.len: %zu vs. %u\n", \
44 strlen((bp)->str), (bp)->len); \
45 break; \
46 } \
47 size = func_name(ORD_ARGS ## ARG_ORDER(NULL, 0, __VA_ARGS__)); \
48 if (size <= 0) { \
49 printf(#func_name " returned %d\n", size); \
50 break; \
51 } \
52 if ((bp)->len != size - 1) { \
53 printf("Return value %d of " #func_name " inconsistent with length"\
54 " %u obtained from corresponding bprint version\n", \
55 size, (bp)->len); \
56 break; \
57 } \
58 str = av_malloc(size); \
59 if (!str) { \
60 printf("string of size %d could not be allocated.\n", size); \
61 break; \
62 } \
63 size = func_name(ORD_ARGS ## ARG_ORDER(str, size, __VA_ARGS__)); \
64 if (size <= 0 || (bp)->len != size - 1) { \
65 printf("Return value %d of " #func_name " inconsistent with length"\
66 " %d obtained in first pass.\n", size, (bp)->len); \
67 av_free(str); \
68 break; \
69 } \
70 if (strcmp(str, (bp)->str)) { \
71 printf("Ordinary and _bprint versions of "#func_name" disagree: " \
72 "'%s' vs. '%s'\n", str, (bp)->str); \
73 av_free(str); \
74 break; \
75 } \
76 av_free(str); \
77 } while (0)
78
79
80 5 static void channel_name(AVBPrint *bp, enum AVChannel channel)
81 {
82 5 av_bprint_clear(bp);
83
7/14
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 5 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 5 times.
5 CMP_BPRINT_AND_NONBPRINT(bp, av_channel_name, 1, channel);
84 5 }
85
86 5 static void channel_description(AVBPrint *bp, enum AVChannel channel)
87 {
88 5 av_bprint_clear(bp);
89
7/14
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 5 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 5 times.
5 CMP_BPRINT_AND_NONBPRINT(bp, av_channel_description, 1, channel);
90 5 }
91
92 1 static void channel_layout_from_mask(AVChannelLayout *layout,
93 AVBPrint *bp, uint64_t channel_layout)
94 {
95 1 av_channel_layout_uninit(layout);
96 1 av_bprint_clear(bp);
97
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
3 if (!av_channel_layout_from_mask(layout, channel_layout) &&
98 1 av_channel_layout_check(layout))
99
7/14
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
1 CMP_BPRINT_AND_NONBPRINT(bp, av_channel_layout_describe, 0, layout);
100 else
101 av_bprintf(bp, "fail");
102 1 }
103
104 39 static void channel_layout_from_string(AVChannelLayout *layout,
105 AVBPrint *bp, const char *channel_layout)
106 {
107 39 av_channel_layout_uninit(layout);
108 39 av_bprint_clear(bp);
109
3/4
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
81 if (!av_channel_layout_from_string(layout, channel_layout) &&
110 21 av_channel_layout_check(layout))
111
7/14
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 21 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 21 times.
✓ Branch 16 taken 21 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 21 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 21 times.
21 CMP_BPRINT_AND_NONBPRINT(bp, av_channel_layout_describe, 0, layout);
112 else
113 18 av_bprintf(bp, "fail");
114 39 }
115
116 static const char* channel_order_names[] = {"UNSPEC", "NATIVE", "CUSTOM", "AMBI"};
117
118 18 static void describe_type(AVBPrint *bp, AVChannelLayout *layout)
119 {
120
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if ((unsigned)layout->order < FF_ARRAY_ELEMS(channel_order_names)) {
121 18 av_bprintf(bp, "%-6s (", channel_order_names[layout->order]);
122 18 av_channel_layout_describe_bprint(layout, bp);
123 18 av_bprintf(bp, ")");
124 } else {
125 av_bprintf(bp, "???");
126 }
127 18 }
128
129 5 static const char *channel_layout_retype(AVChannelLayout *layout, AVBPrint *bp, const char *channel_layout)
130 {
131 5 av_channel_layout_uninit(layout);
132 5 av_bprint_clear(bp);
133
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
10 if (!av_channel_layout_from_string(layout, channel_layout) &&
134 5 av_channel_layout_check(layout)) {
135 5 describe_type(bp, layout);
136
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 5 times.
25 for (int i = 0; i < FF_CHANNEL_ORDER_NB; i++) {
137 int ret;
138 20 AVChannelLayout copy = {0};
139 20 av_bprintf(bp, "\n ");
140
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (av_channel_layout_copy(&copy, layout) < 0)
141 return "nomem";
142 20 ret = av_channel_layout_retype(&copy, i, 0);
143
4/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
20 if (ret < 0 && (copy.order != layout->order || av_channel_layout_compare(&copy, layout)))
144 av_bprintf(bp, "failed to keep existing layout on failure");
145
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
20 if (ret >= 0 && copy.order != i)
146 av_bprintf(bp, "returned success but did not change order");
147
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 13 times.
20 if (ret == AVERROR(ENOSYS)) {
148 7 av_bprintf(bp, " != %s", channel_order_names[i]);
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 } else if (ret < 0) {
150 av_bprintf(bp, "FAIL");
151 } else {
152
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 8 times.
13 av_bprintf(bp, " %s ", ret ? "~~" : "==");
153 13 describe_type(bp, &copy);
154 }
155 20 av_channel_layout_uninit(&copy);
156 }
157 } else {
158 av_bprintf(bp, "fail");
159 }
160 5 return bp->str;
161 }
162
163 #define CHANNEL_NAME(x) \
164 channel_name(&bp, (x)); \
165 printf("With %-32s %14s\n", AV_STRINGIFY(x)":", bp.str)
166
167 #define CHANNEL_DESCRIPTION(x) \
168 channel_description(&bp, (x)); \
169 printf("With %-23s %23s\n", AV_STRINGIFY(x)":", bp.str);
170
171 #define CHANNEL_FROM_STRING(x) \
172 printf("With %-38s %8d\n", AV_STRINGIFY(x)":", av_channel_from_string(x))
173
174 #define CHANNEL_LAYOUT_FROM_MASK(x) \
175 channel_layout_from_mask(&layout, &bp, (x));
176
177 #define CHANNEL_LAYOUT_FROM_STRING(x) \
178 channel_layout_from_string(&layout, &bp, (x)); \
179 printf("With \"%s\":%*s %32s\n", x, strlen(x) > 32 ? 0 : 32 - (int)strlen(x), "", bp.str);
180
181 #define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(l, x) \
182 ret = av_channel_layout_channel_from_index(&layout, x); \
183 if (ret < 0) \
184 ret = -1; \
185 printf("On \"%s\" layout with %2d: %8d\n", l, x, ret)
186
187 #define CHANNEL_LAYOUT_SUBSET(l, xstr, x) \
188 mask = av_channel_layout_subset(&layout, x); \
189 printf("On \"%s\" layout with %-22s 0x%"PRIx64"\n", l, xstr, mask)
190
191 #define CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(l, x) \
192 ret = av_channel_layout_index_from_channel(&layout, x); \
193 if (ret < 0) \
194 ret = -1; \
195 printf("On \"%s\" layout with %-23s %3d\n", l, AV_STRINGIFY(x)":", ret)
196
197 #define CHANNEL_LAYOUT_CHANNEL_FROM_STRING(l, x) \
198 ret = av_channel_layout_channel_from_string(&layout, x); \
199 if (ret < 0) \
200 ret = -1; \
201 printf("On \"%s\" layout with %-21s %3d\n", bp.str, AV_STRINGIFY(x)":", ret);
202
203 #define CHANNEL_LAYOUT_INDEX_FROM_STRING(l, x) \
204 ret = av_channel_layout_index_from_string(&layout, x); \
205 if (ret < 0) \
206 ret = -1; \
207 printf("On \"%s\" layout with %-20s %3d\n", l, AV_STRINGIFY(x)":", ret);
208
209 1 int main(void)
210 {
211 const AVChannelLayout *playout;
212 1 AVChannelLayout layout = { 0 }, layout2 = { 0 };
213 AVBPrint bp;
214 1 void *iter = NULL;
215 uint64_t mask;
216 int ret;
217
218 1 av_bprint_init(&bp, 64, AV_BPRINT_SIZE_AUTOMATIC);
219
220 1 printf("Testing av_channel_layout_standard\n");
221
2/2
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 1 times.
41 while (playout = av_channel_layout_standard(&iter)) {
222 40 av_channel_layout_describe_bprint(playout, &bp);
223 40 printf("%-14s ", bp.str);
224 40 av_bprint_clear(&bp);
225
2/2
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 40 times.
2560 for (int i = 0; i < 63; i++) {
226 2520 int idx = av_channel_layout_index_from_channel(playout, i);
227
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 2232 times.
2520 if (idx >= 0) {
228
2/2
✓ Branch 0 taken 248 times.
✓ Branch 1 taken 40 times.
288 if (idx)
229 248 av_bprintf(&bp, "+");
230 288 av_channel_name_bprint(&bp, i);
231 }
232 }
233 40 printf("%s\n", bp.str);
234 40 av_bprint_clear(&bp);
235 }
236
237 1 printf("\nTesting av_channel_name\n");
238 1 CHANNEL_NAME(AV_CHAN_FRONT_LEFT);
239 1 CHANNEL_NAME(AV_CHAN_FRONT_RIGHT);
240 1 CHANNEL_NAME(63);
241 1 CHANNEL_NAME(AV_CHAN_AMBISONIC_BASE);
242 1 CHANNEL_NAME(AV_CHAN_AMBISONIC_END);
243
244 1 printf("Testing av_channel_description\n");
245 1 CHANNEL_DESCRIPTION(AV_CHAN_FRONT_LEFT);
246 1 CHANNEL_DESCRIPTION(AV_CHAN_FRONT_RIGHT);
247 1 CHANNEL_DESCRIPTION(63);
248 1 CHANNEL_DESCRIPTION(AV_CHAN_AMBISONIC_BASE);
249 1 CHANNEL_DESCRIPTION(AV_CHAN_AMBISONIC_END);
250
251 1 printf("\nTesting av_channel_from_string\n");
252 1 CHANNEL_FROM_STRING("FL");
253 1 CHANNEL_FROM_STRING("FR");
254 1 CHANNEL_FROM_STRING("USR63");
255 1 CHANNEL_FROM_STRING("AMBI0");
256 1 CHANNEL_FROM_STRING("AMBI1023");
257 1 CHANNEL_FROM_STRING("AMBI1024");
258 1 CHANNEL_FROM_STRING("Dummy");
259 1 CHANNEL_FROM_STRING("FL@Foo");
260 1 CHANNEL_FROM_STRING("Foo@FL");
261 1 CHANNEL_FROM_STRING("@FL");
262
263 1 printf("\n==Native layouts==\n");
264
265 1 printf("\nTesting av_channel_layout_from_string\n");
266 1 CHANNEL_LAYOUT_FROM_STRING("0x3f");
267 1 CHANNEL_LAYOUT_FROM_STRING("63");
268 1 CHANNEL_LAYOUT_FROM_STRING("6c");
269 1 CHANNEL_LAYOUT_FROM_STRING("6C");
270 1 CHANNEL_LAYOUT_FROM_STRING("6 channels");
271 1 CHANNEL_LAYOUT_FROM_STRING("6 channels (FL+FR+FC+LFE+BL+BR)");
272 1 CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+LFE+BL+BR");
273 1 CHANNEL_LAYOUT_FROM_STRING("5.1");
274 1 CHANNEL_LAYOUT_FROM_STRING("FL+FR+USR63");
275 1 CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+LFE+SL+SR");
276 1 CHANNEL_LAYOUT_FROM_STRING("5.1(side)");
277
278 1 printf("\nTesting av_channel_layout_from_mask\n");
279 1 CHANNEL_LAYOUT_FROM_MASK(AV_CH_LAYOUT_5POINT1);
280 1 printf("With AV_CH_LAYOUT_5POINT1: %25s\n", bp.str);
281
282 1 printf("\nTesting av_channel_layout_channel_from_index\n");
283
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 0);
284
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 1);
285
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 2);
286
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 3);
287
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 4);
288
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 5);
289
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 6);
290
291 1 printf("\nTesting av_channel_layout_index_from_channel\n");
292
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_LEFT);
293
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_RIGHT);
294
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_CENTER);
295
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_LOW_FREQUENCY);
296
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_SIDE_LEFT);
297
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_SIDE_RIGHT);
298
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_BACK_CENTER);
299
300 1 printf("\nTesting av_channel_layout_channel_from_string\n");
301
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FL");
302
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FR");
303
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FC");
304
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "LFE");
305
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "SL");
306
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "SR");
307
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "BC");
308
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "@");
309
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "@Foo");
310
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FL@Foo");
311
312 1 printf("\nTesting av_channel_layout_index_from_string\n");
313
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FL");
314
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FR");
315
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FC");
316
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "LFE");
317
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "SL");
318
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "SR");
319
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "BC");
320
321 1 printf("\nTesting av_channel_layout_subset\n");
322 1 CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_STEREO:", AV_CH_LAYOUT_STEREO);
323 1 CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_2POINT1:", AV_CH_LAYOUT_2POINT1);
324 1 CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_4POINT1:", AV_CH_LAYOUT_4POINT1);
325
326 1 printf("\n==Custom layouts==\n");
327
328 1 printf("\nTesting av_channel_layout_from_string\n");
329 1 CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+BL+BR+LFE");
330 1 CHANNEL_LAYOUT_FROM_STRING("2 channels (FR+FL)");
331 1 CHANNEL_LAYOUT_FROM_STRING("2 channels (AMBI1023+FL)");
332 1 CHANNEL_LAYOUT_FROM_STRING("3 channels (FR+FL)");
333 1 CHANNEL_LAYOUT_FROM_STRING("-3 channels (FR+FL)");
334 1 CHANNEL_LAYOUT_FROM_STRING("0 channels ()");
335 1 CHANNEL_LAYOUT_FROM_STRING("2 channels (FL+FR");
336 1 CHANNEL_LAYOUT_FROM_STRING("ambisonic 1+FR+FL");
337 1 CHANNEL_LAYOUT_FROM_STRING("ambisonic 2+FC@Foo");
338 1 CHANNEL_LAYOUT_FROM_STRING("FL@Foo+FR@Bar");
339 1 CHANNEL_LAYOUT_FROM_STRING("FL+stereo");
340 1 CHANNEL_LAYOUT_FROM_STRING("stereo+stereo");
341 1 CHANNEL_LAYOUT_FROM_STRING("stereo@Boo");
342 1 CHANNEL_LAYOUT_FROM_STRING("");
343 1 CHANNEL_LAYOUT_FROM_STRING("@");
344 1 CHANNEL_LAYOUT_FROM_STRING("@Dummy");
345 1 CHANNEL_LAYOUT_FROM_STRING("@FL");
346 1 CHANNEL_LAYOUT_FROM_STRING("Dummy");
347 1 CHANNEL_LAYOUT_FROM_STRING("Dummy@FL");
348 1 CHANNEL_LAYOUT_FROM_STRING("FR+Dummy");
349 1 CHANNEL_LAYOUT_FROM_STRING("FR+Dummy@FL");
350 1 CHANNEL_LAYOUT_FROM_STRING("UNK+UNSD");
351 1 CHANNEL_LAYOUT_FROM_STRING("NONE");
352 1 CHANNEL_LAYOUT_FROM_STRING("FR+@FL");
353 1 CHANNEL_LAYOUT_FROM_STRING("FL+@");
354 1 CHANNEL_LAYOUT_FROM_STRING("FR+FL@Foo+USR63@Foo");
355
356 1 ret = av_channel_layout_copy(&layout2, &layout);
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0) {
358 printf("Copying channel layout \"FR+FL@Foo+USR63@Foo\" failed; "
359 "ret %d\n", ret);
360 }
361 1 ret = av_channel_layout_compare(&layout, &layout2);
362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
363 printf("Channel layout and its copy compare unequal; ret: %d\n", ret);
364
365 1 printf("\nTesting av_channel_layout_index_from_string\n");
366
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FR");
367
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FL");
368
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "USR63");
369
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "Foo");
370
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "@Foo");
371
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FR@Foo");
372
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FL@Foo");
373
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "USR63@Foo");
374
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "BC");
375
376 1 printf("\nTesting av_channel_layout_channel_from_string\n");
377
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FR");
378
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FL");
379
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "USR63");
380
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "Foo");
381
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "@Foo");
382
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FR@Foo");
383
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FL@Foo");
384
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "USR63@Foo");
385
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "BC");
386
387 1 printf("\nTesting av_channel_layout_index_from_channel\n");
388
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_RIGHT);
389
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_LEFT);
390
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, 63);
391
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_BACK_CENTER);
392
393 1 printf("\nTesting av_channel_layout_channel_from_index\n");
394
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 0);
395
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 1);
396
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 2);
397
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 3);
398
399 1 printf("\nTesting av_channel_layout_subset\n");
400 1 CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_STEREO:", AV_CH_LAYOUT_STEREO);
401 1 CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_QUAD:", AV_CH_LAYOUT_QUAD);
402
403 1 printf("\n==Ambisonic layouts==\n");
404
405 1 printf("\nTesting av_channel_layout_from_string\n");
406 1 CHANNEL_LAYOUT_FROM_STRING("ambisonic 1");
407 1 CHANNEL_LAYOUT_FROM_STRING("ambisonic 2+stereo");
408
409 1 printf("\nTesting av_channel_layout_index_from_channel\n");
410
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_AMBISONIC_BASE);
411
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_LEFT);
412
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_RIGHT);
413
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_BACK_CENTER);
414
415 1 printf("\nTesting av_channel_layout_channel_from_index\n");
416
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 0);
417
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 9);
418
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 10);
419
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 11);
420
421 1 printf("\nTesting av_channel_layout_subset\n");
422 1 CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_STEREO:", AV_CH_LAYOUT_STEREO);
423 1 CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_QUAD:", AV_CH_LAYOUT_QUAD);
424
425 1 av_channel_layout_uninit(&layout);
426 1 av_channel_layout_uninit(&layout2);
427
428 1 printf("\nTesting av_channel_layout_retype\n");
429 {
430 1 const char* layouts[] = {
431 "FL@Boo",
432 "stereo",
433 "FR+FL",
434 "ambisonic 2+stereo",
435 "2C",
436 NULL
437 };
438
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 for (int i = 0; layouts[i]; i++)
439 5 printf("With \"%s\": %s\n", layouts[i], channel_layout_retype(&layout, &bp, layouts[i]));
440 }
441 1 av_bprint_finalize(&bp, NULL);
442
443 1 return 0;
444 }
445