FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/downmix_info.c
Date: 2026-09-11 16:39:37
Exec Total Coverage
Lines: 31 33 93.9%
Functions: 1 1 100.0%
Branches: 7 14 50.0%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <limits.h>
20 #include <stdio.h>
21
22 #include "libavutil/downmix_info.h"
23 #include "libavutil/frame.h"
24 #include "libavutil/mem.h"
25
26 1 int main(void)
27 {
28 AVFrame *frame;
29 AVDownmixInfo *info, *info2;
30
31 /* First call: allocates side data, zero-initialized. */
32 1 printf("Testing av_downmix_info_update_side_data()\n");
33 1 frame = av_frame_alloc();
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!frame)
35 return 1;
36
37 1 info = av_downmix_info_update_side_data(frame);
38
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (info) {
39 1 printf("create: OK\n");
40 1 printf("defaults: type=%d center=%.3f center_ltrt=%.3f surround=%.3f"
41 " surround_ltrt=%.3f lfe=%.3f\n",
42 1 info->preferred_downmix_type,
43 info->center_mix_level, info->center_mix_level_ltrt,
44 info->surround_mix_level, info->surround_mix_level_ltrt,
45 info->lfe_mix_level);
46
47 /* Write fields and read them back. The mix levels are absolute scale
48 * factors, not gains in dB, so every value is a distinct nonnegative
49 * factor. Each one is a negative power of two or a sum of two, which
50 * makes the decimal output exact on any platform. */
51 1 info->preferred_downmix_type = AV_DOWNMIX_TYPE_LTRT;
52 1 info->center_mix_level = 0.5;
53 1 info->center_mix_level_ltrt = 0.625;
54 1 info->surround_mix_level = 0.25;
55 1 info->surround_mix_level_ltrt = 0.375;
56 1 info->lfe_mix_level = 0.125;
57 1 printf("write: type=%d center=%.3f center_ltrt=%.3f surround=%.3f"
58 " surround_ltrt=%.3f lfe=%.3f\n",
59 1 info->preferred_downmix_type,
60 info->center_mix_level, info->center_mix_level_ltrt,
61 info->surround_mix_level, info->surround_mix_level_ltrt,
62 info->lfe_mix_level);
63 } else {
64 printf("create: FAIL\n");
65 }
66
67 /* Second call must reuse the existing side data (same pointer, values kept). */
68 1 info2 = av_downmix_info_update_side_data(frame);
69
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (info && info2) {
70 1 printf("reuse: same_pointer=%s preserved_type=%d preserved_center=%.3f\n",
71 info == info2 ? "yes" : "no",
72
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 info2->preferred_downmix_type, info2->center_mix_level);
73 }
74
75 1 av_frame_free(&frame);
76
77 /* OOM path: av_max_alloc(1) forces the internal side data allocation to fail. */
78 1 printf("\nTesting OOM path\n");
79 1 frame = av_frame_alloc();
80
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
81 1 av_max_alloc(1);
82 1 info = av_downmix_info_update_side_data(frame);
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("OOM: %s\n", info ? "FAIL" : "OK");
84 1 av_max_alloc(INT_MAX);
85 1 av_frame_free(&frame);
86 }
87
88 1 return 0;
89 }
90