FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/downmix_info.h
Date: 2026-09-26 05:01:43
Exec Total Coverage
Lines: 3 3 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

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 #ifndef AVUTIL_DOWNMIX_INFO_H
22 #define AVUTIL_DOWNMIX_INFO_H
23
24 #include "avassert.h"
25 #include "frame.h"
26
27 /**
28 * @file
29 * audio downmix medatata
30 */
31
32 /**
33 * @addtogroup lavu_audio
34 * @{
35 */
36
37 /**
38 * @defgroup downmix_info Audio downmix metadata
39 * @{
40 */
41
42 /**
43 * Possible downmix types.
44 */
45 enum AVDownmixType {
46 AV_DOWNMIX_TYPE_UNKNOWN, /**< Not indicated. */
47 AV_DOWNMIX_TYPE_LORO, /**< Lo/Ro 2-channel downmix (Stereo). */
48 AV_DOWNMIX_TYPE_LTRT, /**< Lt/Rt 2-channel downmix, Dolby Surround compatible. */
49 AV_DOWNMIX_TYPE_DPLII, /**< Lt/Rt 2-channel downmix, Dolby Pro Logic II compatible. */
50 AV_DOWNMIX_TYPE_NB /**< Number of downmix types. Not part of ABI. */
51 };
52
53 /**
54 * This structure describes optional metadata relevant to a downmix procedure.
55 *
56 * All fields are set by the decoder to the value indicated in the audio
57 * bitstream (if present), or to a "sane" default otherwise.
58 */
59 typedef struct AVDownmixInfo {
60 /**
61 * Type of downmix preferred by the mastering engineer.
62 */
63 enum AVDownmixType preferred_downmix_type;
64
65 /**
66 * Absolute scale factor representing the nominal level of the center
67 * channel during a regular downmix.
68 */
69 double center_mix_level;
70
71 /**
72 * Absolute scale factor representing the nominal level of the center
73 * channel during an Lt/Rt compatible downmix.
74 */
75 double center_mix_level_ltrt;
76
77 /**
78 * Absolute scale factor representing the nominal level of the surround
79 * channels during a regular downmix.
80 */
81 double surround_mix_level;
82
83 /**
84 * Absolute scale factor representing the nominal level of the surround
85 * channels during an Lt/Rt compatible downmix.
86 */
87 double surround_mix_level_ltrt;
88
89 /**
90 * Absolute scale factor representing the level at which the LFE data is
91 * mixed into L/R channels during downmixing.
92 */
93 double lfe_mix_level;
94 } AVDownmixInfo;
95
96 /**
97 * Get a frame's AV_FRAME_DATA_DOWNMIX_INFO side data for editing.
98 *
99 * If the side data is absent, it is created and added to the frame.
100 *
101 * @param frame the frame for which the side data is to be obtained or created
102 *
103 * @return the AVDownmixInfo structure to be edited by the caller, or NULL if
104 * the structure cannot be allocated.
105 */
106 AVDownmixInfo *av_downmix_info_update_side_data(AVFrame *frame);
107
108 /**
109 * This structure describes optional metadata relevant to a downmix procedure
110 * in the form of a remixing matrix allocated as an array of AVDownmixCoeff.
111 * Must be allocated with @ref av_downmix_matrix_alloc.
112 *
113 * sizeof(AVDownmixMatrix) is not a part of the ABI and new fields may be
114 * added to it.
115 */
116 typedef struct AVDownmixMatrix {
117 /**
118 * Type of downmix the coeffs will produce.
119 * Output channel count is derived from this value.
120 */
121 enum AVDownmixType downmix_type;
122
123 /**
124 * Input channel count.
125 */
126 int in_ch_count;
127
128 /**
129 * Amount of coefficients in the matrix.
130 */
131 unsigned int nb_coeffs;
132
133 /**
134 * Offset in bytes from the beginning of this structure at which the array
135 * of coefficients starts.
136 */
137 size_t coeffs_offset;
138 } AVDownmixMatrix;
139
140 /**
141 * Data type for storing coefficients, which are allocated as a part of
142 * AVDownmixMatrix and should be retrieved with @ref av_downmix_matrix_coeff.
143 */
144 typedef double AVDownmixCoeff;
145
146 /**
147 * Get a pointer to the coeff that represents the weight of input channel
148 * {@code in} in output channel {@code out}.
149 * in must be between 0 and @ref AVDownmixMatrix.in_ch_count "in_ch_count" - 1.
150 * out must be between 0 and the implicit output channel count from
151 * @ref AVDownmixMatrix.downmix_type "downmix_type" - 1.
152 */
153 static av_always_inline AVDownmixCoeff*
154 78 av_downmix_matrix_coeff(AVDownmixMatrix *dm, unsigned int out, unsigned int in)
155 {
156 78 AVDownmixCoeff *coeff = (AVDownmixCoeff *)((uint8_t *)dm + dm->coeffs_offset);
157 78 return &coeff[in + dm->in_ch_count * out];
158 }
159
160 /**
161 * Allocates memory for AVDownmixMatrix of the given type, plus an array of
162 * {@code in_ch_count} times the implicit output channel count from {@code type}
163 * of AVDownmixCoeff and initializes the variables. Can be freed with a normal
164 * av_free() call.
165 *
166 * @param out_size if non-NULL, the size in bytes of the resulting data array is
167 * written here.
168 */
169 AVDownmixMatrix *av_downmix_matrix_alloc(enum AVDownmixType type,
170 int in_ch_count, size_t *out_size);
171
172 /**
173 * @}
174 */
175
176 /**
177 * @}
178 */
179
180 #endif /* AVUTIL_DOWNMIX_INFO_H */
181