FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/downmix_info.c
Date: 2026-09-27 18:38:33
Exec Total Coverage
Lines: 25 27 92.6%
Functions: 2 2 100.0%
Branches: 10 14 71.4%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2014 Tim Walker <tdskywalker@gmail.com>
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 "downmix_info.h"
22 #include "frame.h"
23 #include "mem.h"
24
25 746 AVDownmixInfo *av_downmix_info_update_side_data(AVFrame *frame)
26 {
27 AVFrameSideData *side_data;
28
29 746 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_DOWNMIX_INFO);
30
31
2/2
✓ Branch 0 taken 745 times.
✓ Branch 1 taken 1 times.
746 if (!side_data) {
32 745 side_data = av_frame_new_side_data(frame, AV_FRAME_DATA_DOWNMIX_INFO,
33 sizeof(AVDownmixInfo));
34
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 1 times.
745 if (side_data)
35 744 memset(side_data->data, 0, sizeof(AVDownmixInfo));
36 }
37
38
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 745 times.
746 if (!side_data)
39 1 return NULL;
40
41 745 return (AVDownmixInfo*)side_data->data;
42 }
43
44 #define MAX_CHANNELS 64
45
46 static const int type_map[] = {
47 [AV_DOWNMIX_TYPE_UNKNOWN] = 0,
48 [AV_DOWNMIX_TYPE_LORO] = 2,
49 [AV_DOWNMIX_TYPE_LTRT] = 2,
50 [AV_DOWNMIX_TYPE_DPLII] = 2,
51 };
52
53 39 AVDownmixMatrix *av_downmix_matrix_alloc(enum AVDownmixType type,
54 int in_ch_count, size_t *out_size)
55 {
56 struct TestStruct {
57 AVDownmixMatrix p;
58 AVDownmixCoeff b;
59 };
60 39 const size_t coeffs_offset = offsetof(struct TestStruct, b);
61 39 size_t size = coeffs_offset;
62 unsigned int nb_coeffs;
63 AVDownmixMatrix *dc;
64
65
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 if ((unsigned)type >= FF_ARRAY_ELEMS(type_map) ||
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 (unsigned)in_ch_count > MAX_CHANNELS)
67 ✗ return NULL;
68
69 39 nb_coeffs = type_map[type] * in_ch_count;
70 39 size += sizeof(AVDownmixCoeff) * nb_coeffs;
71
72 39 dc = av_mallocz(size);
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 if (!dc)
74 ✗ return NULL;
75
76 39 dc->downmix_type = type;
77 39 dc->nb_coeffs = nb_coeffs;
78 39 dc->in_ch_count = in_ch_count;
79 39 dc->coeffs_offset = coeffs_offset;
80
81
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 if (out_size)
82 39 *out_size = size;
83
84 39 return dc;
85 }
86