FFmpeg coverage


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