FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/dolby_e.c
Date: 2021-09-26 18:22:30
Exec Total Coverage
Lines: 340 405 84.0%
Branches: 195 248 78.6%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2017 foo86
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 "libavutil/channel_layout.h"
22 #include "libavutil/float_dsp.h"
23 #include "libavutil/thread.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/mem_internal.h"
26
27 #include "internal.h"
28 #include "get_bits.h"
29 #include "dolby_e.h"
30 #include "kbdwin.h"
31 #include "fft.h"
32
33 #define MAX_SEGMENTS 2
34
35 #define MAX_GROUPS 8
36 #define MAX_EXPONENTS 304
37 #define MAX_MANTISSAS 1024
38
39 #define MAX_MSTR_EXP 2
40 #define MAX_BIAS_EXP 50
41
42 typedef struct DBEGroup {
43 uint8_t nb_exponent;
44 uint8_t nb_bias_exp[MAX_MSTR_EXP];
45 uint16_t exp_ofs;
46 uint16_t mnt_ofs;
47 const uint8_t *nb_mantissa;
48 uint8_t imdct_idx;
49 uint8_t imdct_phs;
50 uint16_t win_len;
51 uint16_t dst_ofs;
52 uint16_t win_ofs;
53 uint16_t src_ofs;
54 } DBEGroup;
55
56 typedef struct DBEChannel {
57 int gr_code;
58 int bw_code;
59
60 int nb_groups;
61 int nb_mstr_exp;
62 DBEGroup groups[MAX_GROUPS];
63
64 int exp_strategy[MAX_GROUPS];
65 int exponents[MAX_EXPONENTS];
66 int bap[MAX_EXPONENTS];
67 int idx[MAX_EXPONENTS];
68
69 DECLARE_ALIGNED(32, float, mantissas)[MAX_MANTISSAS];
70 } DBEChannel;
71
72 typedef struct DBEDecodeContext {
73 AVCodecContext *avctx;
74 DBEContext dectx;
75
76 DBEChannel channels[MAX_SEGMENTS][MAX_CHANNELS];
77
78 DECLARE_ALIGNED(32, float, history)[MAX_CHANNELS][256];
79
80 FFTContext imdct[3];
81 AVFloatDSPContext *fdsp;
82 } DBEDecodeContext;
83
84 static const int8_t lfe_channel_tab[MAX_PROG_CONF + 1] = {
85 5, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4,
86 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 5
87 };
88
89 static const uint8_t ch_reorder_4[4] = { 0, 2, 1, 3 };
90 static const uint8_t ch_reorder_6[6] = { 0, 2, 4, 1, 3, 5 };
91 static const uint8_t ch_reorder_8[8] = { 0, 2, 6, 4, 1, 3, 7, 5 };
92 static const uint8_t ch_reorder_n[8] = { 0, 2, 4, 6, 1, 3, 5, 7 };
93
94
95 static const uint8_t nb_groups_tab[4] = { 1, 8, 7, 1 };
96
97 static const uint8_t nb_mstr_exp_tab[4] = { 2, 2, 2, 1 };
98
99 static const uint8_t nb_mantissa_38[38] = {
100 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
101 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6,
102 7, 8, 9, 10, 11, 12,
103 };
104
105 static const uint8_t nb_mantissa_44[44] = {
106 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
107 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 7, 7,
108 8, 9, 10, 11, 12, 13, 15, 16, 18, 20, 22, 25,
109 };
110
111 static const uint8_t nb_mantissa_50[50] = {
112 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3,
113 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10, 12, 13, 14, 16,
114 18, 19, 22, 24, 27, 29, 32, 36, 40, 44, 49, 54, 60, 66, 74, 82,
115 90, 100,
116 };
117
118 static const uint8_t imdct_bits_tab[3] = { 8, 9, 11 };
119
120 static const DBEGroup grp_tab_0[1] = {
121 { 50, { 27, 23 }, 0, 0, nb_mantissa_50, 2, 0, 1152, 0, 1408, 0 },
122 };
123
124 static const DBEGroup grp_tab_1[8] = {
125 { 38, { 12, 26 }, 0, 0, nb_mantissa_38, 0, 0, 192, 0, 256, 0 },
126 { 38, { 12, 26 }, 38, 128, nb_mantissa_38, 0, 1, 256, 64, 448, 0 },
127 { 38, { 12, 26 }, 76, 256, nb_mantissa_38, 0, 1, 256, 192, 704, 0 },
128 { 38, { 12, 26 }, 114, 384, nb_mantissa_38, 0, 1, 256, 320, 0, 0 },
129 { 38, { 12, 26 }, 152, 512, nb_mantissa_38, 0, 1, 256, 448, 0, 0 },
130 { 38, { 12, 26 }, 190, 640, nb_mantissa_38, 0, 1, 256, 576, 0, 0 },
131 { 38, { 12, 26 }, 228, 768, nb_mantissa_38, 0, 1, 256, 704, 0, 0 },
132 { 38, { 12, 26 }, 266, 896, nb_mantissa_38, 0, 1, 256, 832, 0, 0 },
133 };
134
135 static const DBEGroup grp_tab_2[7] = {
136 { 38, { 12, 26 }, 0, 0, nb_mantissa_38, 0, 0, 192, 0, 256, 0 },
137 { 38, { 12, 26 }, 38, 128, nb_mantissa_38, 0, 1, 256, 64, 448, 0 },
138 { 38, { 12, 26 }, 76, 256, nb_mantissa_38, 0, 1, 256, 192, 704, 0 },
139 { 38, { 12, 26 }, 114, 384, nb_mantissa_38, 0, 1, 256, 320, 0, 0 },
140 { 38, { 12, 26 }, 152, 512, nb_mantissa_38, 0, 1, 256, 448, 0, 0 },
141 { 38, { 12, 26 }, 190, 640, nb_mantissa_38, 0, 1, 256, 576, 0, 0 },
142 { 44, { 19, 25 }, 228, 768, nb_mantissa_44, 1, 1, 448, 704, 960, 64 },
143 };
144
145 static const DBEGroup grp_tab_3[1] = {
146 { 21, { 21 }, 0, 0, nb_mantissa_50, 2, 0, 1152, 0, 1408, 0 },
147 };
148
149 static const DBEGroup grp_tab_4[1] = {
150 { 50, { 27, 23 }, 0, 0, nb_mantissa_50, 2, 2, 1152, 0, 1408, 896 },
151 };
152
153 static const DBEGroup grp_tab_5[8] = {
154 { 38, { 12, 26 }, 0, 0, nb_mantissa_38, 0, 1, 256, 64, 0, 0 },
155 { 38, { 12, 26 }, 38, 128, nb_mantissa_38, 0, 1, 256, 192, 0, 0 },
156 { 38, { 12, 26 }, 76, 256, nb_mantissa_38, 0, 1, 256, 320, 0, 0 },
157 { 38, { 12, 26 }, 114, 384, nb_mantissa_38, 0, 1, 256, 448, 0, 0 },
158 { 38, { 12, 26 }, 152, 512, nb_mantissa_38, 0, 1, 256, 576, 0, 0 },
159 { 38, { 12, 26 }, 190, 640, nb_mantissa_38, 0, 1, 256, 704, 3008, 0 },
160 { 38, { 12, 26 }, 228, 768, nb_mantissa_38, 0, 1, 256, 832, 2752, 0 },
161 { 38, { 12, 26 }, 266, 896, nb_mantissa_38, 0, 2, 192, 960, 2560, 64 },
162 };
163
164 static const DBEGroup grp_tab_6[7] = {
165 { 44, { 19, 25 }, 0, 0, nb_mantissa_44, 1, 1, 448, 0, 3264, 0 },
166 { 38, { 12, 26 }, 44, 256, nb_mantissa_38, 0, 1, 256, 320, 0, 0 },
167 { 38, { 12, 26 }, 82, 384, nb_mantissa_38, 0, 1, 256, 448, 0, 0 },
168 { 38, { 12, 26 }, 120, 512, nb_mantissa_38, 0, 1, 256, 576, 0, 0 },
169 { 38, { 12, 26 }, 158, 640, nb_mantissa_38, 0, 1, 256, 704, 3008, 0 },
170 { 38, { 12, 26 }, 196, 768, nb_mantissa_38, 0, 1, 256, 832, 2752, 0 },
171 { 38, { 12, 26 }, 234, 896, nb_mantissa_38, 0, 2, 192, 960, 2560, 64 },
172 };
173
174 static const DBEGroup grp_tab_7[1] = {
175 { 21, { 21 }, 0, 0, nb_mantissa_50, 2, 2, 1152, 0, 1408, 896 },
176 };
177
178 static const DBEGroup *const frm_ofs_tab[2][4] = {
179 { grp_tab_0, grp_tab_1, grp_tab_2, grp_tab_3 },
180 { grp_tab_4, grp_tab_5, grp_tab_6, grp_tab_7 }
181 };
182
183 static const uint8_t mantissa_size1[16][4] = {
184 { 0, 0, 0, 0 }, { 2, 1, 1, 1 }, { 3, 2, 1, 1 }, { 4, 3, 2, 1 },
185 { 5, 4, 3, 2 }, { 6, 5, 4, 3 }, { 7, 6, 5, 4 }, { 8, 7, 6, 5 },
186 { 9, 8, 7, 6 }, { 10, 9, 8, 7 }, { 11, 10, 9, 8 }, { 12, 11, 10, 9 },
187 { 13, 12, 11, 10 }, { 14, 13, 12, 11 }, { 15, 14, 13, 12 }, { 16, 15, 14, 13 },
188 };
189
190 static const uint8_t mantissa_size2[16][4] = {
191 { 0, 0, 0, 0 }, { 2, 1, 2, 2 }, { 3, 2, 3, 3 }, { 4, 3, 4, 4 },
192 { 5, 4, 5, 5 }, { 6, 5, 6, 6 }, { 7, 6, 7, 7 }, { 8, 7, 8, 8 },
193 { 9, 8, 9, 9 }, { 10, 9, 10, 10 }, { 11, 10, 11, 11 }, { 12, 11, 12, 12 },
194 { 13, 12, 13, 13 }, { 14, 13, 14, 14 }, { 15, 14, 15, 15 }, { 16, 15, 16, 16 },
195 };
196
197 static const float start_window[192] = {
198 0.00161569379826, 0.00185748233347, 0.00198562758548, 0.00207834078104,
199 0.00215717748523, 0.00223067096393, 0.00230299213147, 0.00237651215396,
200 0.00245275561606, 0.00253281402069, 0.00261754673613, 0.00270768786168,
201 0.00280390761895, 0.00290684998656, 0.00301715751161, 0.00313548872798,
202 0.00326253122934, 0.00339901215995, 0.00354570716636, 0.00370344845023,
203 0.00387313232586, 0.00405572653911, 0.00425227750970, 0.00446391759265,
204 0.00469187240551, 0.00493746822816, 0.00520213944619, 0.00548743597507,
205 0.00579503056737, 0.00612672586953, 0.00648446105606, 0.00687031782873,
206 0.00728652552677, 0.00773546505205, 0.00821967127415, 0.00874183354619,
207 0.00930479393832, 0.00991154278653, 0.01056521116692, 0.01126905994567,
208 0.01202646513050, 0.01284089936559, 0.01371590957417, 0.01465509096066,
209 0.01566205783408, 0.01674041199523, 0.01789370972358, 0.01912542867865,
210 0.02043893626265, 0.02183746113793, 0.02332406961796, 0.02490164852364,
211 0.02657289580178, 0.02834031974193, 0.03020624702903, 0.03217283918354,
212 0.03424211623810, 0.03641598586180, 0.03869627565015, 0.04108476601498,
213 0.04358322107390, 0.04619341515939, 0.04891715301882, 0.05175628239149,
214
215 0.05471237327267, 0.05778734733755, 0.06098291402413, 0.06430101352084,
216 0.06774345212186, 0.07131188644726, 0.07500780649199, 0.07883251748595,
217 0.08278712056651, 0.08687249228061, 0.09108926295730, 0.09543779401074,
218 0.09991815425851, 0.10453009536427, 0.10927302653894, 0.11414598865987,
219 0.11914762799220, 0.12427616972097, 0.12952939152560, 0.13490459744934,
220 0.14039859233595, 0.14600765712201, 0.15172752528722, 0.15755336077528,
221 0.16347973770491, 0.16950062219342, 0.17560935661442, 0.18179864660619,
222 0.18806055113821, 0.19438647593012, 0.20076717050010, 0.20719272909882,
223 0.21365259576030, 0.22013557367283, 0.22662983904194, 0.23312295958328,
224 0.23960191774666, 0.24605313873388, 0.25246252333253, 0.25881548554631,
225 0.26509699495987, 0.27129162373316, 0.27738359807707, 0.28335685401987,
226 0.28919509723179, 0.29488186663467, 0.30040060148455, 0.30573471157819,
227 0.31086765019993, 0.31578298939317, 0.32046449711227, 0.32489621578468,
228 0.32906254179156, 0.33294830535654, 0.33653885031840, 0.33982011325336,
229 0.34277870140679, 0.34540196889300, 0.34767809062480, 0.34959613344194,
230 0.35114612391958, 0.35231911235422, 0.35310723244504, 0.35350375621308,
231
232 0.35350314372945, 0.35310108725579, 0.35229454943591, 0.35108179521634,
233 0.34946241721522, 0.34743735430290, 0.34500890320420, 0.34218072298001,
234 0.33895783229541, 0.33534659943168, 0.33135472505060, 0.32699121776996,
235 0.32226636266000, 0.31719168282019, 0.31177989424432, 0.30604485422875,
236 0.30000150362379, 0.29366580327088, 0.28705466500775, 0.28018587766131,
237 0.27307802848095, 0.26575042049535, 0.25822298630189, 0.25051619882000,
238 0.24265097955783, 0.23464860495522, 0.22653061137548, 0.21831869932335,
239 0.21003463746705, 0.20170016703857, 0.19333690717811, 0.18496626177620,
240 0.17660932835062, 0.16828680947474, 0.16001892724986, 0.15182534128597,
241 0.14372507062477, 0.13573642000364, 0.12787691082233, 0.12016321713317,
242 0.11261110693234, 0.10523538898282, 0.09804986534955, 0.09106728977263,
243 0.08429933194438, 0.07775654768810, 0.07144835495683, 0.06538301547324,
244 0.05956762170687, 0.05400808871425, 0.04870915012107, 0.04367435714993,
245 0.03890607899172, 0.03440550179663, 0.03017262174627, 0.02620622428513,
246 0.02250383492507, 0.01906161305732, 0.01587412848221, 0.01293388032354,
247 0.01023019677288, 0.00774641320626, 0.00545109736891, 0.00325868651263,
248 };
249
250 static const float short_window2[192] = {
251 0.00018861094606, 0.00033433010202, 0.00050309624485, 0.00070306161748,
252 0.00093995174533, 0.00121913067128, 0.00154606505568, 0.00192647806126,
253 0.00236641248692, 0.00287225985240, 0.00345077377440, 0.00410907465023,
254 0.00485464855241, 0.00569534163219, 0.00663935063508, 0.00769520981249,
255 0.00887177436246, 0.01017820046395, 0.01162392194150, 0.01321862359335,
256 0.01497221122468, 0.01689477844427, 0.01899657030441, 0.02128794388846,
257 0.02377932597692, 0.02648116795039, 0.02940389811590, 0.03255787167130,
258 0.03595331854986, 0.03960028941437, 0.04350860009563, 0.04768777479454,
259 0.05214698838949, 0.05689500821121, 0.06194013566525, 0.06729014809766,
260 0.07295224131210, 0.07893297315602, 0.08523820859989, 0.09187306673620,
261 0.09884187012422, 0.10614809690222, 0.11379433608064, 0.12178224641797,
262 0.13011251926531, 0.13878484574660, 0.14779788861830, 0.15714925912610,
263 0.16683549914631, 0.17685206886673, 0.18719334022589, 0.19785259629099,
264 0.20882203671372, 0.22009278936030, 0.23165492816694, 0.24349749722585,
265 0.25560854105961, 0.26797514099368, 0.28058345748882, 0.29341877824732,
266 0.30646557185942, 0.31970754671026, 0.33312771482295, 0.34670846027024,
267
268 0.36043161174692, 0.37427851885723, 0.38823013163645, 0.40226708279486,
269 0.41636977214436, 0.43051845264462, 0.44469331748632, 0.45887458761470,
270 0.47304259908636, 0.48717788964798, 0.50126128392546, 0.51527397661778,
271 0.52919761310050, 0.54301436685998, 0.55670701320069, 0.57025899869448,
272 0.58365450587230, 0.59687851269542, 0.60991684638414, 0.62275623122793,
273 0.63538433005035, 0.64778977905593, 0.65996221584264, 0.67189230042379,
274 0.68357172916486, 0.69499324160511, 0.70615062019861, 0.71703868307548,
275 0.72765326998919, 0.73799122168099, 0.74805035295521, 0.75782941981995,
276 0.76732808110520, 0.77654685502339, 0.78548707118622, 0.79415081863423,
277 0.80254089047207, 0.81066072573188, 0.81851434910893, 0.82610630922734,
278 0.83344161609862, 0.84052567843230, 0.84736424144524, 0.85396332579459,
279 0.86032916822973, 0.86646816451999, 0.87238681516918, 0.87809167437532,
280 0.88358930263537, 0.88888622333073, 0.89398888356256, 0.89890361943564,
281 0.90363662591861, 0.90819393133744, 0.91258137648979, 0.91680459830070,
282 0.92086901787718, 0.92477983276087, 0.92854201312583, 0.93216030163834,
283 0.93563921662343, 0.93898305819384, 0.94219591693690, 0.94528168477979,
284
285 0.94823843319821, 0.95106834367330, 0.95377776558539, 0.95636718335775,
286 0.95883679961479, 0.96118650212341, 0.96341583179195, 0.96552395212906,
287 0.96750962060547, 0.96937116231768, 0.97110644638309, 0.97271286544154,
288 0.97418731862798, 0.97552619834964, 0.97672538116257, 0.97778022299974,
289 0.97868555895586, 0.97943570778357, 0.98002448120255, 0.98044519806866,
290 0.98069070339493, 0.98075339216123, 0.98062523779637, 0.98029782516478,
291 0.97976238784222, 0.97900984942031, 0.97803086854002, 0.97681588731895,
292 0.97535518280755, 0.97363892108474, 0.97165721358452, 0.96940017523145,
293 0.96685798395452, 0.96402094114589, 0.96087953263194, 0.95742448973047,
294 0.95364684997699, 0.94953801711660, 0.94508981997396, 0.94029456983253,
295 0.93514511597504, 0.92963489905951, 0.92375800202883, 0.91750919827624,
296 0.91088399681406, 0.90387868421832, 0.89649036314692, 0.88871698725397,
297 0.88055739234735, 0.87201132366062, 0.86307945913336, 0.85376342861693,
298 0.84406582894455, 0.83399023482637, 0.82354120554757, 0.81272428745995,
299 0.80154601230457, 0.79001389138101, 0.77813640562199, 0.76592299164227,
300 0.75338402384395, 0.74053079267526, 0.72737547915460, 0.71393112578527,
301 };
302
303 static const float short_window3[64] = {
304 0.00326887936450, 0.00550242900936, 0.00786846643791, 0.01045683453520,
305 0.01330402120132, 0.01643221072863, 0.01985798040609, 0.02359509464766,
306 0.02765559221954, 0.03205025893128, 0.03678884369614, 0.04188015679495,
307 0.04733210987781, 0.05315172583924, 0.05934513287609, 0.06591755045290,
308 0.07287327156378, 0.08021564389822, 0.08794705152307, 0.09606889811179,
309 0.10458159240070, 0.11348453632940, 0.12277611617809, 0.13245369691511,
310 0.14251361989876, 0.15295120402567, 0.16376075037904, 0.17493555039885,
311 0.18646789757072, 0.19834910260891, 0.21056951208995, 0.22311853047787,
312 0.23598464546683, 0.24915545655419, 0.26261770674500, 0.27635731727778,
313 0.29035942525136, 0.30460842402318, 0.31908800624032, 0.33378120935681,
314 0.34867046348260, 0.36373764140285, 0.37896411059909, 0.39433078709788,
315 0.40981819096657, 0.42540650327031, 0.44107562429959, 0.45680523287270,
316 0.47257484651351, 0.48836388230077, 0.50415171818214, 0.51991775454258,
317 0.53564147581496, 0.55130251191887, 0.56688069931047, 0.58235614142007,
318 0.59770926827271, 0.61292089506118, 0.62797227945823, 0.64284517745255,
319 0.65752189749349, 0.67198535273209, 0.68621911114984, 0.70020744337099,
320 };
321
322 static const uint8_t dc_code_tab[5] = { 0, 0, 0, 1, 1 };
323
324 static const uint8_t ht_code_tab[5] = { 0, 0, 1, 2, 2 };
325
326 static const uint8_t band_ofs_tab[3][4] = {
327 { 12, 8, 4, 0 }, { 14, 10, 6, 0 }, { 12, 8, 4, 0 }
328 };
329
330 static const uint8_t band_low_tab[3] = { 9, 17, 24 };
331
332 static const uint16_t fast_gain_tab[8] = {
333 128, 256, 384, 512, 640, 768, 896, 1024
334 };
335
336 static const uint16_t slow_decay_tab[2][2] = { { 27, -1 }, { 32, 21 } };
337
338 static const uint16_t misc_decay_tab[3][2][2] = {
339 { { 354, -1 }, { 425, 425 } },
340 { { 266, -1 }, { 320, -1 } },
341 { { 213, -1 }, { 256, -1 } }
342 };
343
344 static const uint16_t fast_decay_tab[3][2][2][50] = {
345 {{{
346 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
347 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
348 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
349 142, 142, 142, 142, 142, 142, 142, 142,
350 }, {
351 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
352 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
353 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
354 -1, -1, -1, -1, -1, -1, -1, -1,
355 }}, {{
356 170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
357 170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
358 170, 170, 170, 170, 170, 170, 170, 170, 170, 170,
359 170, 170, 170, 170, 170, 170, 170, 170,
360 }, {
361 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
362 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
363 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
364 64, 64, 64, 64, 64, 64, 64, 64,
365 }}}, {{{
366 266, 266, 106, 106, 106, 106, 106, 106, 106, 106,
367 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
368 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
369 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
370 106, 106, 106, 106,
371 }, {
372 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
373 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
374 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
375 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
376 -1, -1, -1, -1,
377 }}, {{
378 319, 319, 128, 128, 128, 128, 128, 128, 128, 128,
379 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
380 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
381 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
382 128, 128, 128, 128,
383 }, {
384 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
385 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
386 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
388 -1, -1, -1, -1,
389 }}}, {{{
390 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
391 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
392 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
393 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
394 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
395 }, {
396 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
397 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
398 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
399 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
400 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
401 }}, {{
402 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
403 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
404 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
405 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
406 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
407 }, {
408 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
409 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
410 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
411 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
412 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
413 }}}
414 };
415
416 static const uint16_t fast_gain_adj_tab[3][2][62] = {
417 {{
418 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
419 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
420 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
421 0, 1, 2, 4, 7, 11, 16, 29, 44, 59,
422 76, 94, 116, 142, 179, 221, 252, 285, 312, 334,
423 }, {
424 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
425 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
426 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
427 2, 5, 8, 10, 15, 28, 42, 57, 75, 93,
428 115, 140, 177, 219, 247, 280, 308, 330, 427, 533,
429 }}, {{
430 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
431 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
432 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
433 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
434 0, 2, 5, 8, 12, 21, 35, 51, 69, 89,
435 111, 138, 176, 220, 251, 284, 312, 334,
436 }, {
437 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
438 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
439 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
440 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
441 5, 8, 11, 18, 33, 49, 65, 84, 106, 132,
442 168, 214, 245, 279, 308, 329, 427, 533,
443 }}, {{
444 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
445 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
446 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
447 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
448 0, 0, 0, 0, 0, 1, 4, 7, 10, 17,
449 31, 47, 65, 84, 107, 134, 171, 215, 250, 283,
450 312, 334,
451 }, {
452 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
453 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
454 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
455 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
456 0, 0, 0, 0, 3, 6, 9, 13, 27, 43,
457 60, 79, 100, 126, 160, 207, 242, 276, 307, 329,
458 427, 533,
459 }}
460 };
461
462 static const uint16_t slow_gain_tab[3][2][50] = {
463 {{
464 3072, 3072, 3072, 3072, 3072, 3072, 1063, 1063, 1063, 1063,
465 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
466 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
467 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
468 }, {
469 3072, 3072, 3072, 3072, 3072, 3072, 850, 850, 850, 850,
470 850, 850, 850, 850, 850, 850, 850, 850, 850, 850,
471 850, 850, 850, 850, 850, 850, 850, 850, 850, 850,
472 850, 850, 850, 850, 850, 850, 850, 850,
473 }}, {{
474 3072, 1212, 1212, 1212, 999, 999, 999, 999, 999, 999,
475 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
476 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
477 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
478 999, 999, 999, 999,
479 }, {
480 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
481 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
482 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
483 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
484 -1, -1, -1, -1,
485 }}, {{
486 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072, 3072,
487 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
488 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
489 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
490 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
491 }, {
492 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
493 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
494 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
495 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
496 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
497 }}
498 };
499
500 static const uint16_t hearing_thresh_tab[3][3][50] = {
501 {{
502 1403, 1141, 1000, 959, 948, 957, 946, 925, 899, 871,
503 843, 815, 789, 766, 745, 727, 705, 687, 681, 686,
504 701, 725, 768, 854, 940, 1018, 1075, 1103, 1111, 1106,
505 1098, 1105, 1142, 1237, 1419, 1721, 2169, 2805,
506 }, {
507 1401, 1130, 995, 957, 947, 955, 941, 918, 890, 861,
508 831, 803, 777, 754, 734, 717, 698, 684, 682, 692,
509 712, 743, 798, 894, 976, 1045, 1091, 1109, 1110, 1102,
510 1098, 1116, 1174, 1300, 1526, 1884, 2401, 3072,
511 }, {
512 1393, 1086, 974, 949, 957, 941, 913, 878, 843, 808,
513 777, 750, 727, 708, 695, 686, 681, 689, 714, 752,
514 811, 888, 971, 1044, 1087, 1108, 1110, 1102, 1098, 1115,
515 1172, 1290, 1489, 1812, 2293, 2964, 3072, 3072,
516 }}, {{
517 1412, 1343, 1141, 1047, 1000, 974, 959, 951, 948, 947,
518 957, 953, 946, 936, 925, 906, 878, 850, 822, 795,
519 771, 745, 719, 700, 687, 681, 685, 701, 733, 784,
520 885, 977, 1047, 1092, 1110, 1108, 1099, 1102, 1138, 1233,
521 1413, 1711, 2157, 2797,
522 }, {
523 1412, 1336, 1130, 1040, 995, 970, 957, 950, 947, 947,
524 955, 950, 941, 930, 918, 897, 868, 838, 810, 783,
525 759, 734, 710, 693, 684, 681, 690, 712, 752, 823,
526 924, 1009, 1069, 1102, 1111, 1104, 1098, 1111, 1168, 1295,
527 1518, 1873, 2388, 3072,
528 }, {
529 1411, 1293, 1086, 1009, 974, 957, 949, 947, 957, 951,
530 941, 928, 913, 896, 878, 852, 817, 785, 756, 732,
531 713, 695, 683, 682, 689, 710, 746, 811, 906, 992,
532 1061, 1099, 1111, 1106, 1098, 1107, 1155, 1266, 1471, 1799,
533 2277, 2945, 3072, 3072,
534 }}, {{
535 1431, 1412, 1403, 1379, 1343, 1293, 1229, 1180, 1125, 1075,
536 1040, 1014, 996, 979, 965, 957, 951, 948, 947, 957,
537 951, 940, 924, 903, 877, 846, 815, 785, 753, 725,
538 702, 686, 681, 689, 714, 760, 847, 947, 1028, 1083,
539 1108, 1109, 1101, 1100, 1132, 1222, 1402, 1705, 2160, 2803,
540 }, {
541 1431, 1412, 1401, 1375, 1336, 1278, 1215, 1168, 1115, 1066,
542 1032, 1008, 991, 975, 962, 954, 950, 947, 947, 955,
543 948, 935, 916, 894, 866, 835, 803, 772, 742, 715,
544 695, 683, 683, 697, 729, 784, 887, 982, 1054, 1096,
545 1111, 1106, 1098, 1107, 1159, 1281, 1505, 1865, 2391, 3072,
546 }, {
547 1427, 1411, 1393, 1353, 1293, 1215, 1160, 1118, 1072, 1031,
548 1003, 984, 971, 960, 952, 948, 947, 957, 952, 941,
549 924, 902, 876, 847, 815, 781, 750, 723, 700, 685,
550 681, 691, 719, 766, 858, 958, 1039, 1089, 1109, 1108,
551 1099, 1102, 1141, 1245, 1442, 1766, 2250, 2930, 3072, 3072,
552 }}
553 };
554
555 static const int16_t lwc_gain_tab[11][7] = {
556 { -21, -197, -271, -466, 32767, 32767, 32767 },
557 { -197, -29, -244, -271, -540, 32767, 32767 },
558 { -271, -244, -29, -249, -271, -593, 32767 },
559 { -466, -271, -249, -29, -251, -271, -632 },
560 { -540, -271, -251, -29, -251, -271, -664 },
561 { -593, -271, -251, -29, -252, -271, -690 },
562 { -632, -271, -252, -29, -252, -271, -711 },
563 { -664, -271, -252, -29, -252, -271, -730 },
564 { -690, -271, -252, -29, -252, -271, -745 },
565 { -711, -271, -252, -29, -253, -271, -759 },
566 { -730, -271, -253, -29, -253, -271, -771 },
567 };
568
569 static const int16_t lwc_adj_tab[7] = {
570 -192, -320, -448, -512, -448, -320, -192,
571 };
572
573 static const uint8_t log_add_tab[212] = {
574 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 52, 51, 50,
575 49, 48, 47, 47, 46, 45, 44, 44, 43, 42, 41, 41, 40, 39, 38, 38,
576 37, 36, 36, 35, 35, 34, 33, 33, 32, 32, 31, 30, 30, 29, 29, 28,
577 28, 27, 27, 26, 26, 25, 25, 24, 24, 23, 23, 22, 22, 21, 21, 21,
578 20, 20, 19, 19, 19, 18, 18, 18, 17, 17, 17, 16, 16, 16, 15, 15,
579 15, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11,
580 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8,
581 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5,
582 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
583 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2,
584 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
585 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
586 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
587 1, 1, 0, 0,
588 };
589
590 static const uint8_t bap_tab[64] = {
591 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4,
592 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
593 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12,
594 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15,
595 };
596
597 static float mantissa_tab1[17][4];
598 static float mantissa_tab2[17][4];
599 static float mantissa_tab3[17][4];
600 static float exponent_tab[50];
601 static float gain_tab[1024];
602
603 DECLARE_ALIGNED(32, static float, window)[3712];
604
605 5676 static int skip_input(DBEContext *s, int nb_words)
606 {
607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5676 times.
5676 if (nb_words > s->input_size) {
608 av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n");
609 return AVERROR_INVALIDDATA;
610 }
611
612 5676 s->input += nb_words * s->word_bytes;
613 5676 s->input_size -= nb_words;
614 5676 return 0;
615 }
616
617 1032 static int parse_key(DBEContext *s)
618 {
619
1/2
✓ Branch 0 taken 1032 times.
✗ Branch 1 not taken.
1032 if (s->key_present) {
620 1032 const uint8_t *key = s->input;
621 1032 int ret = skip_input(s, 1);
622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1032 times.
1032 if (ret < 0)
623 return ret;
624 1032 return AV_RB24(key) >> 24 - s->word_bits;
625 }
626 return 0;
627 }
628
629 258 static int parse_metadata_ext(DBEDecodeContext *s1)
630 {
631 258 DBEContext *s = &s1->dectx;
632
1/2
✓ Branch 0 taken 258 times.
✗ Branch 1 not taken.
258 if (s->metadata.mtd_ext_size)
633 258 return skip_input(s, s->key_present + s->metadata.mtd_ext_size + 1);
634 return 0;
635 }
636
637 3124 static void unbias_exponents(DBEContext *s, DBEChannel *c, DBEGroup *g)
638 {
639 int mstr_exp[MAX_MSTR_EXP];
640 int bias_exp[MAX_BIAS_EXP];
641 int i, j, k;
642
643
2/2
✓ Branch 0 taken 5732 times.
✓ Branch 1 taken 3124 times.
8856 for (i = 0; i < c->nb_mstr_exp; i++)
644 5732 mstr_exp[i] = get_bits(&s->gb, 2) * 6;
645
646
2/2
✓ Branch 0 taken 140534 times.
✓ Branch 1 taken 3124 times.
143658 for (i = 0; i < g->nb_exponent; i++)
647 140534 bias_exp[i] = get_bits(&s->gb, 5);
648
649
2/2
✓ Branch 0 taken 5732 times.
✓ Branch 1 taken 3124 times.
8856 for (i = k = 0; i < c->nb_mstr_exp; i++)
650
2/2
✓ Branch 0 taken 140534 times.
✓ Branch 1 taken 5732 times.
146266 for (j = 0; j < g->nb_bias_exp[i]; j++, k++)
651 140534 c->exponents[g->exp_ofs + k] = mstr_exp[i] + bias_exp[k];
652 3124 }
653
654 3096 static int parse_exponents(DBEContext *s, DBEChannel *c)
655 {
656 DBEGroup *p, *g;
657 int i;
658
659
2/2
✓ Branch 0 taken 3242 times.
✓ Branch 1 taken 3096 times.
6338 for (i = 0, p = NULL, g = c->groups; i < c->nb_groups; i++, p = g, g++) {
660
6/6
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 3096 times.
✓ Branch 2 taken 138 times.
✓ Branch 3 taken 8 times.
✓ Branch 5 taken 20 times.
✓ Branch 6 taken 118 times.
3242 c->exp_strategy[i] = !i || g->nb_exponent != p->nb_exponent || get_bits1(&s->gb);
661
2/2
✓ Branch 0 taken 3124 times.
✓ Branch 1 taken 118 times.
3242 if (c->exp_strategy[i]) {
662 3124 unbias_exponents(s, c, g);
663 } else {
664 118 memcpy(c->exponents + g->exp_ofs,
665 118 c->exponents + p->exp_ofs,
666 118 g->nb_exponent * sizeof(c->exponents[0]));
667 }
668 }
669
670 3096 return 0;
671 }
672
673 349400 static inline int log_add(int a, int b)
674 {
675 349400 int c = FFABS(a - b) >> 1;
676 349400 return FFMAX(a, b) + log_add_tab[FFMIN(c, 211)];
677 }
678
679 43 static void calc_lowcomp(int *msk_val)
680 {
681 43 int lwc_val[17] = { 0 };
682 int i, j, k;
683
684
2/2
✓ Branch 0 taken 473 times.
✓ Branch 1 taken 43 times.
516 for (i = 0; i < 11; i++) {
685 473 int max_j = 0;
686 473 int max_v = INT_MIN;
687 473 int thr = 0;
688
689
2/2
✓ Branch 0 taken 3053 times.
✓ Branch 1 taken 473 times.
3526 for (j = FFMAX(i - 3, 0), k = 0; j <= i + 3; j++, k++) {
690 3053 int v = msk_val[j] + lwc_gain_tab[i][k];
691
2/2
✓ Branch 0 taken 1451 times.
✓ Branch 1 taken 1602 times.
3053 if (v > max_v) {
692 1451 max_j = j;
693 1451 max_v = v;
694 }
695 3053 thr = log_add(thr, v);
696 }
697
698
2/2
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 200 times.
473 if (msk_val[i] < thr) {
699 273 for (j = FFMAX(max_j - 3, 0),
700 273 k = FFMAX(3 - max_j, 0);
701
2/2
✓ Branch 0 taken 1783 times.
✓ Branch 1 taken 273 times.
2056 j <= max_j + 3; j++, k++)
702 1783 lwc_val[j] += lwc_adj_tab[k];
703 }
704 }
705
706
2/2
✓ Branch 0 taken 688 times.
✓ Branch 1 taken 43 times.
731 for (i = 0; i < 16; i++) {
707 688 int v = FFMAX(lwc_val[i], -512);
708 688 msk_val[i] = FFMAX(msk_val[i] + v, 0);
709 }
710 43 }
711
712 3125 static void bit_allocate(int nb_exponent, int nb_code, int fr_code,
713 int *exp, int *bap,
714 int fg_spc, int fg_ofs, int msk_mod, int snr_ofs)
715 {
716 int msk_val[MAX_BIAS_EXP];
717 int psd_val[MAX_BIAS_EXP];
718 3125 int fast_leak = 0;
719 3125 int slow_leak = 0;
720 3125 int dc_code = dc_code_tab[fr_code - 1];
721 3125 int ht_code = ht_code_tab[fr_code - 1];
722 3125 int fast_gain = fast_gain_tab[fg_ofs];
723 3125 int slow_decay = slow_decay_tab[dc_code][msk_mod];
724 3125 int misc_decay = misc_decay_tab[nb_code][dc_code][msk_mod];
725 3125 const uint16_t *slow_gain = slow_gain_tab[nb_code][msk_mod];
726 3125 const uint16_t *fast_decay = fast_decay_tab[nb_code][dc_code][msk_mod];
727 3125 const uint16_t *fast_gain_adj = fast_gain_adj_tab[nb_code][dc_code];
728 3125 const uint16_t *hearing_thresh = hearing_thresh_tab[nb_code][ht_code];
729 int i;
730
731
2/2
✓ Branch 0 taken 140569 times.
✓ Branch 1 taken 3125 times.
143694 for (i = 0; i < nb_exponent; i++)
732 140569 psd_val[i] = (48 - exp[i]) * 64;
733
734 3125 fast_gain_adj += band_ofs_tab[nb_code][fg_spc];
735
2/2
✓ Branch 0 taken 140569 times.
✓ Branch 1 taken 3125 times.
143694 for (i = 0; i < nb_exponent; i++) {
736 140569 fast_leak = log_add(fast_leak - fast_decay[i],
737 140569 psd_val[i] - fast_gain + fast_gain_adj[i]);
738 140569 slow_leak = log_add(slow_leak - slow_decay,
739 140569 psd_val[i] - slow_gain[i]);
740 140569 msk_val[i] = FFMAX(fast_leak, slow_leak);
741 }
742
743 3125 fast_leak = 0;
744
2/2
✓ Branch 0 taken 65209 times.
✓ Branch 1 taken 3125 times.
68334 for (i = nb_exponent - 1; i > band_low_tab[nb_code]; i--) {
745 65209 fast_leak = log_add(fast_leak - misc_decay, psd_val[i] - fast_gain);
746 65209 msk_val[i] = FFMAX(msk_val[i], fast_leak);
747 }
748
749
2/2
✓ Branch 0 taken 140569 times.
✓ Branch 1 taken 3125 times.
143694 for (i = 0; i < nb_exponent; i++)
750 140569 msk_val[i] = FFMAX(msk_val[i], hearing_thresh[i]);
751
752
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 3082 times.
3125 if (!nb_code)
753 43 calc_lowcomp(msk_val);
754
755
2/2
✓ Branch 0 taken 140569 times.
✓ Branch 1 taken 3125 times.
143694 for (i = 0; i < nb_exponent; i++) {
756 140569 int v = 16 * (snr_ofs - 64) + psd_val[i] - msk_val[i] >> 5;
757 140569 bap[i] = bap_tab[av_clip_uintp2(v, 6)];
758 }
759 3125 }
760
761 3096 static int parse_bit_alloc(DBEDecodeContext *s1, DBEChannel *c)
762 {
763 3096 DBEContext *s = &s1->dectx;
764 DBEGroup *p, *g;
765 int bap_strategy[MAX_GROUPS], fg_spc[MAX_GROUPS];
766 int fg_ofs[MAX_GROUPS], msk_mod[MAX_GROUPS];
767 int i, snr_ofs;
768
769
2/2
✓ Branch 0 taken 3242 times.
✓ Branch 1 taken 3096 times.
6338 for (i = 0; i < c->nb_groups; i++) {
770
4/4
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 3096 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 144 times.
3242 bap_strategy[i] = !i || get_bits1(&s->gb);
771
2/2
✓ Branch 0 taken 3098 times.
✓ Branch 1 taken 144 times.
3242 if (bap_strategy[i]) {
772 3098 fg_spc[i] = get_bits(&s->gb, 2);
773 3098 fg_ofs[i] = get_bits(&s->gb, 3);
774 3098 msk_mod[i] = get_bits1(&s->gb);
775 } else {
776 144 fg_spc[i] = fg_spc[i - 1];
777 144 fg_ofs[i] = fg_ofs[i - 1];
778 144 msk_mod[i] = msk_mod[i - 1];
779 }
780 }
781
782
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3096 times.
3096 if (get_bits1(&s->gb)) {
783 avpriv_report_missing_feature(s->avctx, "Delta bit allocation");
784 return AVERROR_PATCHWELCOME;
785 }
786
787 3096 snr_ofs = get_bits(&s->gb, 8);
788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3096 times.
3096 if (!snr_ofs) {
789 memset(c->bap, 0, sizeof(c->bap));
790 return 0;
791 }
792
793
2/2
✓ Branch 0 taken 3242 times.
✓ Branch 1 taken 3096 times.
6338 for (i = 0, p = NULL, g = c->groups; i < c->nb_groups; i++, p = g, g++) {
794
4/4
✓ Branch 0 taken 118 times.
✓ Branch 1 taken 3124 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 117 times.
3242 if (c->exp_strategy[i] || bap_strategy[i]) {
795 3125 bit_allocate(g->nb_exponent, g->imdct_idx, s->metadata.fr_code,
796 3125 c->exponents + g->exp_ofs, c->bap + g->exp_ofs,
797 fg_spc[i], fg_ofs[i], msk_mod[i], snr_ofs);
798 } else {
799 117 memcpy(c->bap + g->exp_ofs,
800 117 c->bap + p->exp_ofs,
801 117 g->nb_exponent * sizeof(c->bap[0]));
802 }
803 }
804
805 3096 return 0;
806 }
807
808 3096 static int parse_indices(DBEContext *s, DBEChannel *c)
809 {
810 DBEGroup *p, *g;
811 int i, j;
812
813
2/2
✓ Branch 0 taken 3242 times.
✓ Branch 1 taken 3096 times.
6338 for (i = 0, p = NULL, g = c->groups; i < c->nb_groups; i++, p = g, g++) {
814
2/2
✓ Branch 1 taken 3074 times.
✓ Branch 2 taken 168 times.
3242 if (get_bits1(&s->gb)) {
815 3074 int start = get_bits(&s->gb, 6);
816
817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3074 times.
3074 if (start > g->nb_exponent) {
818 av_log(s->avctx, AV_LOG_ERROR, "Invalid start index\n");
819 return AVERROR_INVALIDDATA;
820 }
821
822
2/2
✓ Branch 0 taken 82713 times.
✓ Branch 1 taken 3074 times.
85787 for (j = 0; j < start; j++)
823 82713 c->idx[g->exp_ofs + j] = 0;
824
825
2/2
✓ Branch 0 taken 56023 times.
✓ Branch 1 taken 3074 times.
59097 for (; j < g->nb_exponent; j++)
826 56023 c->idx[g->exp_ofs + j] = get_bits(&s->gb, 2);
827
4/4
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 138 times.
✓ Branch 3 taken 8 times.
168 } else if (i && g->nb_exponent == p->nb_exponent) {
828 138 memcpy(c->idx + g->exp_ofs,
829 138 c->idx + p->exp_ofs,
830 138 g->nb_exponent * sizeof(c->idx[0]));
831 } else {
832 30 memset(c->idx + g->exp_ofs, 0, g->nb_exponent * sizeof(c->idx[0]));
833 }
834 }
835
836 3096 return 0;
837 }
838
839 3096 static int parse_mantissas(DBEContext *s, DBEChannel *c)
840 {
841 DBEGroup *g;
842 int i, j, k;
843
844
2/2
✓ Branch 0 taken 3242 times.
✓ Branch 1 taken 3096 times.
6338 for (i = 0, g = c->groups; i < c->nb_groups; i++, g++) {
845 3242 float *mnt = c->mantissas + g->mnt_ofs;
846
847
2/2
✓ Branch 0 taken 144664 times.
✓ Branch 1 taken 3242 times.
147906 for (j = 0; j < g->nb_exponent; j++) {
848 144664 int bap = c->bap[g->exp_ofs + j];
849 144664 int idx = c->idx[g->exp_ofs + j];
850 144664 int size1 = mantissa_size1[bap][idx];
851 144664 int count = g->nb_mantissa[j];
852 144664 float exp = exponent_tab[c->exponents[g->exp_ofs + j]];
853 144664 float scale = mantissa_tab1[size1][idx] * exp;
854
855
2/2
✓ Branch 0 taken 7050 times.
✓ Branch 1 taken 137614 times.
144664 if (!size1) {
856 7050 memset(mnt, 0, count * sizeof(*mnt));
857
2/2
✓ Branch 0 taken 37698 times.
✓ Branch 1 taken 99916 times.
137614 } else if (idx) {
858 int values[100];
859 37698 int escape = -(1 << size1 - 1);
860
861
2/2
✓ Branch 0 taken 1215688 times.
✓ Branch 1 taken 37698 times.
1253386 for (k = 0; k < count; k++)
862 1215688 values[k] = get_sbits(&s->gb, size1);
863
864
2/2
✓ Branch 0 taken 1215688 times.
✓ Branch 1 taken 37698 times.
1253386 for (k = 0; k < count; k++) {
865
2/2
✓ Branch 0 taken 1082370 times.
✓ Branch 1 taken 133318 times.
1215688 if (values[k] != escape) {
866 1082370 mnt[k] = values[k] * scale;
867 } else {
868 133318 int size2 = mantissa_size2[bap][idx];
869 133318 int value = get_sbits(&s->gb, size2);
870 133318 float a = mantissa_tab2[size2][idx];
871 133318 float b = mantissa_tab3[size2][idx];
872
2/2
✓ Branch 0 taken 66652 times.
✓ Branch 1 taken 66666 times.
133318 if (value < 0)
873 66652 mnt[k] = ((value + 1) * a - b) * exp;
874 else
875 66666 mnt[k] = (value * a + b) * exp;
876 }
877 }
878 } else {
879
2/2
✓ Branch 0 taken 816305 times.
✓ Branch 1 taken 99916 times.
916221 for (k = 0; k < count; k++)
880 816305 mnt[k] = get_sbits(&s->gb, size1) * scale;
881 }
882
883 144664 mnt += count;
884 }
885
886
2/2
✓ Branch 0 taken 15468 times.
✓ Branch 1 taken 3242 times.
18710 for (; j < g->nb_exponent + c->bw_code; j++) {
887 15468 memset(mnt, 0, g->nb_mantissa[j] * sizeof(*mnt));
888 15468 mnt += g->nb_mantissa[j];
889 }
890 }
891
892 3096 return 0;
893 }
894
895 3096 static int parse_channel(DBEDecodeContext *s1, int ch, int seg_id)
896 {
897 3096 DBEContext *s = &s1->dectx;
898 3096 DBEChannel *c = &s1->channels[seg_id][ch];
899 int i, ret;
900
901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3096 times.
3096 if (s->metadata.rev_id[ch] > 1) {
902 avpriv_report_missing_feature(s->avctx, "Encoder revision %d", s->metadata.rev_id[ch]);
903 return AVERROR_PATCHWELCOME;
904 }
905
906
2/2
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 2580 times.
3096 if (ch == lfe_channel_tab[s->metadata.prog_conf]) {
907 516 c->gr_code = 3;
908 516 c->bw_code = 29;
909 } else {
910 2580 c->gr_code = get_bits(&s->gb, 2);
911 2580 c->bw_code = get_bits(&s->gb, 3);
912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2580 times.
2580 if (c->gr_code == 3) {
913 av_log(s->avctx, AV_LOG_ERROR, "Invalid group type code\n");
914 return AVERROR_INVALIDDATA;
915 }
916 }
917
918 3096 c->nb_groups = nb_groups_tab[c->gr_code];
919 3096 c->nb_mstr_exp = nb_mstr_exp_tab[c->gr_code];
920
921
2/2
✓ Branch 0 taken 3242 times.
✓ Branch 1 taken 3096 times.
6338 for (i = 0; i < c->nb_groups; i++) {
922 3242 c->groups[i] = frm_ofs_tab[seg_id][c->gr_code][i];
923
2/2
✓ Branch 0 taken 2726 times.
✓ Branch 1 taken 516 times.
3242 if (c->nb_mstr_exp == 2) {
924 2726 c->groups[i].nb_exponent -= c->bw_code;
925 2726 c->groups[i].nb_bias_exp[1] -= c->bw_code;
926 }
927 }
928
929
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3096 times.
3096 if ((ret = parse_exponents(s, c)) < 0)
930 return ret;
931
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3096 times.
3096 if ((ret = parse_bit_alloc(s1, c)) < 0)
932 return ret;
933
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3096 times.
3096 if ((ret = parse_indices(s, c)) < 0)
934 return ret;
935
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3096 times.
3096 if ((ret = parse_mantissas(s, c)) < 0)
936 return ret;
937
938
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3096 times.
3096 if (get_bits_left(&s->gb) < 0) {
939 av_log(s->avctx, AV_LOG_ERROR, "Read past end of channel %d\n", ch);
940 return AVERROR_INVALIDDATA;
941 }
942
943 3096 return 0;
944 }
945
946 1032 static int parse_audio(DBEDecodeContext *s1, int start, int end, int seg_id)
947 {
948 1032 DBEContext *s = &s1->dectx;
949 int ch, ret, key;
950
951
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1032 times.
1032 if ((key = parse_key(s)) < 0)
952 return key;
953
954
2/2
✓ Branch 0 taken 3096 times.
✓ Branch 1 taken 1032 times.
4128 for (ch = start; ch < end; ch++) {
955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3096 times.
3096 if (!s->metadata.ch_size[ch]) {
956 s1->channels[seg_id][ch].nb_groups = 0;
957 continue;
958 }
959 3096 ret = ff_dolby_e_convert_input(s, s->metadata.ch_size[ch], key);
960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3096 times.
3096 if (ret < 0)
961 return ret;
962
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3096 times.
3096 if ((ret = parse_channel(s1, ch, seg_id)) < 0) {
963 if (s1->avctx->err_recognition & AV_EF_EXPLODE)
964 return ret;
965 s1->channels[seg_id][ch].nb_groups = 0;
966 }
967
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3096 times.
3096 if ((ret = skip_input(s, s->metadata.ch_size[ch])) < 0)
968 return ret;
969 }
970
971 1032 return skip_input(s, 1);
972 }
973
974 258 static int parse_meter(DBEDecodeContext *s1)
975 {
976 258 DBEContext *s = &s1->dectx;
977
1/2
✓ Branch 0 taken 258 times.
✗ Branch 1 not taken.
258 if (s->metadata.meter_size)
978 258 return skip_input(s, s->key_present + s->metadata.meter_size + 1);
979 return 0;
980 }
981
982 3242 static void imdct_calc(DBEDecodeContext *s1, DBEGroup *g, float *result, float *values)
983 {
984 3242 FFTContext *imdct = &s1->imdct[g->imdct_idx];
985 3242 int n = 1 << imdct_bits_tab[g->imdct_idx];
986 3242 int n2 = n >> 1;
987 int i;
988
989
3/4
✓ Branch 0 taken 1548 times.
✓ Branch 1 taken 146 times.
✓ Branch 2 taken 1548 times.
✗ Branch 3 not taken.
3242 switch (g->imdct_phs) {
990 1548 case 0:
991 1548 imdct->imdct_half(imdct, result, values);
992
2/2
✓ Branch 0 taken 1575296 times.
✓ Branch 1 taken 1548 times.
1576844 for (i = 0; i < n2; i++)
993 1575296 result[n2 + i] = result[n2 - i - 1];
994 1548 break;
995 146 case 1:
996 146 imdct->imdct_calc(imdct, result, values);
997 146 break;
998 1548 case 2:
999 1548 imdct->imdct_half(imdct, result + n2, values);
1000
2/2
✓ Branch 0 taken 1575296 times.
✓ Branch 1 taken 1548 times.
1576844 for (i = 0; i < n2; i++)
1001 1575296 result[i] = -result[n - i - 1];
1002 1548 break;
1003 default:
1004 av_assert0(0);
1005 }
1006 3242 }
1007
1008 3096 static void transform(DBEDecodeContext *s1, DBEChannel *c, float *history, float *output)
1009 {
1010 3096 LOCAL_ALIGNED_32(float, buffer, [2048]);
1011 3096 LOCAL_ALIGNED_32(float, result, [1152]);
1012 DBEGroup *g;
1013 int i;
1014
1015 3096 memset(result, 0, 1152 * sizeof(float));
1016
2/2
✓ Branch 0 taken 3242 times.
✓ Branch 1 taken 3096 times.
6338 for (i = 0, g = c->groups; i < c->nb_groups; i++, g++) {
1017 3242 float *src = buffer + g->src_ofs;
1018 3242 float *dst = result + g->dst_ofs;
1019 3242 float *win = window + g->win_ofs;
1020
1021 3242 imdct_calc(s1, g, buffer, c->mantissas + g->mnt_ofs);
1022 3242 s1->fdsp->vector_fmul_add(dst, src, win, dst, g->win_len);
1023 }
1024
1025
2/2
✓ Branch 0 taken 792576 times.
✓ Branch 1 taken 3096 times.
795672 for (i = 0; i < 256; i++)
1026 792576 output[i] = history[i] + result[i];
1027
2/2
✓ Branch 0 taken 1981440 times.
✓ Branch 1 taken 3096 times.
1984536 for (i = 256; i < 896; i++)
1028 1981440 output[i] = result[i];
1029
2/2
✓ Branch 0 taken 792576 times.
✓ Branch 1 taken 3096 times.
795672 for (i = 0; i < 256; i++)
1030 792576 history[i] = result[896 + i];
1031 3096 }
1032
1033 1548 static void apply_gain(DBEDecodeContext *s, int begin, int end, float *output)
1034 {
1035
2/4
✓ Branch 0 taken 1548 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1548 times.
✗ Branch 3 not taken.
1548 if (begin == 960 && end == 960)
1036 1548 return;
1037
1038 if (begin == end) {
1039 s->fdsp->vector_fmul_scalar(output, output, gain_tab[end], FRAME_SAMPLES);
1040 } else {
1041 float a = gain_tab[begin] * (1.0f / (FRAME_SAMPLES - 1));
1042 float b = gain_tab[end ] * (1.0f / (FRAME_SAMPLES - 1));
1043 int i;
1044
1045 for (i = 0; i < FRAME_SAMPLES; i++)
1046 output[i] *= a * (FRAME_SAMPLES - i - 1) + b * i;
1047 }
1048 }
1049
1050 258 static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
1051 {
1052 258 const DolbyEHeaderInfo *const metadata = &s->dectx.metadata;
1053 const uint8_t *reorder;
1054 int ch, ret;
1055
1056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258 times.
258 if (metadata->nb_channels == 4)
1057 reorder = ch_reorder_4;
1058
1/2
✓ Branch 0 taken 258 times.
✗ Branch 1 not taken.
258 else if (metadata->nb_channels == 6)
1059 258 reorder = ch_reorder_6;
1060 else if (metadata->nb_programs == 1 && !(s->avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE))
1061 reorder = ch_reorder_8;
1062 else
1063 reorder = ch_reorder_n;
1064
1065 258 frame->nb_samples = FRAME_SAMPLES;
1066
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = ff_get_buffer(s->avctx, frame, 0)) < 0)
1067 return ret;
1068
1069
2/2
✓ Branch 0 taken 1548 times.
✓ Branch 1 taken 258 times.
1806 for (ch = 0; ch < metadata->nb_channels; ch++) {
1070 1548 float *output = (float *)frame->extended_data[reorder[ch]];
1071 1548 transform(s, &s->channels[0][ch], s->history[ch], output);
1072 1548 transform(s, &s->channels[1][ch], s->history[ch], output + FRAME_SAMPLES / 2);
1073 1548 apply_gain(s, metadata->begin_gain[ch], metadata->end_gain[ch], output);
1074 }
1075
1076 258 return 0;
1077 }
1078
1079 258 static int dolby_e_decode_frame(AVCodecContext *avctx, void *data,
1080 int *got_frame_ptr, AVPacket *avpkt)
1081 {
1082 258 DBEDecodeContext *s1 = avctx->priv_data;
1083 258 DBEContext *s = &s1->dectx;
1084 int i, j, ret;
1085
1086
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = ff_dolby_e_parse_header(s, avpkt->data, avpkt->size)) < 0)
1087 return ret;
1088
1089
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258 if (s->metadata.nb_programs > 1 && !s->metadata.multi_prog_warned) {
1090 av_log(avctx, AV_LOG_WARNING, "Stream has %d programs (configuration %d), "
1091 "channels will be output in native order.\n",
1092 s->metadata.nb_programs, s->metadata.prog_conf);
1093 s->metadata.multi_prog_warned = 1;
1094 }
1095
1096
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258 switch (s->metadata.nb_channels) {
1097 case 4:
1098 avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
1099 break;
1100 258 case 6:
1101 258 avctx->channel_layout = AV_CH_LAYOUT_5POINT1;
1102 258 break;
1103 case 8:
1104 avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
1105 break;
1106 }
1107
1108 258 avctx->channels = s->metadata.nb_channels;
1109 258 avctx->sample_rate = s->metadata.sample_rate;
1110 258 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
1111
1112 258 i = s->metadata.nb_channels / 2;
1113 258 j = s->metadata.nb_channels;
1114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = parse_audio(s1, 0, i, 0)) < 0)
1115 return ret;
1116
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = parse_audio(s1, i, j, 0)) < 0)
1117 return ret;
1118
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = parse_metadata_ext(s1)) < 0)
1119 return ret;
1120
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = parse_audio(s1, 0, i, 1)) < 0)
1121 return ret;
1122
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = parse_audio(s1, i, j, 1)) < 0)
1123 return ret;
1124
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = parse_meter(s1)) < 0)
1125 return ret;
1126
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if ((ret = filter_frame(s1, data)) < 0)
1127 return ret;
1128
1129 258 *got_frame_ptr = 1;
1130 258 return avpkt->size;
1131 }
1132
1133 static av_cold void dolby_e_flush(AVCodecContext *avctx)
1134 {
1135 DBEDecodeContext *s = avctx->priv_data;
1136
1137 memset(s->history, 0, sizeof(s->history));
1138 }
1139
1140 3 static av_cold int dolby_e_close(AVCodecContext *avctx)
1141 {
1142 3 DBEDecodeContext *s = avctx->priv_data;
1143 int i;
1144
1145
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (i = 0; i < 3; i++)
1146 9 ff_mdct_end(&s->imdct[i]);
1147
1148 3 av_freep(&s->fdsp);
1149 3 return 0;
1150 }
1151
1152
1153 2 static av_cold void init_tables(void)
1154 {
1155 int i, j;
1156
1157
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 2 times.
34 for (i = 1; i < 17; i++)
1158 32 mantissa_tab1[i][0] = 1.0f / (1 << i - 1);
1159
1160
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2 times.
30 for (i = 2; i < 16; i++) {
1161 28 mantissa_tab1[i][1] = 1.0f / ((1 << i) - 1);
1162 28 mantissa_tab1[i][2] = 0.5f / ((1 << i) - 1);
1163 28 mantissa_tab1[i][3] = 0.25f / ((1 << i) - 1);
1164 }
1165
1166 2 mantissa_tab1[i][1] = 0.5f / (1 << 15);
1167 2 mantissa_tab1[i][2] = 0.75f / (1 << 15);
1168 2 mantissa_tab1[i][3] = 0.875f / (1 << 15);
1169
1170
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 2 times.
34 for (i = 1; i < 17; i++) {
1171 32 mantissa_tab2[i][1] = mantissa_tab1[i][0] * 0.5f;
1172 32 mantissa_tab2[i][2] = mantissa_tab1[i][0] * 0.75f;
1173 32 mantissa_tab2[i][3] = mantissa_tab1[i][0] * 0.875f;
1174
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 32 times.
128 for (j = 1; j < 4; j++)
1175 96 mantissa_tab3[i][j] = 1.0f / (1 << i) + 1.0f / (1 << j) - 1.0f / (1 << i + j);
1176 }
1177
1178 2 mantissa_tab3[1][3] = 0.6875f;
1179
1180
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 2 times.
52 for (i = 0; i < 25; i++) {
1181 50 exponent_tab[i * 2 ] = 1.0f / (1 << i);
1182 50 exponent_tab[i * 2 + 1] = M_SQRT1_2 / (1 << i);
1183 }
1184
1185
2/2
✓ Branch 0 taken 2046 times.
✓ Branch 1 taken 2 times.
2048 for (i = 1; i < 1024; i++)
1186 2046 gain_tab[i] = exp2f((i - 960) / 64.0f);
1187
1188 // short 1
1189 2 ff_kbd_window_init(window, 3.0f, 128);
1190
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 2 times.
258 for (i = 0; i < 128; i++)
1191 256 window[128 + i] = window[127 - i];
1192
1193 // start
1194
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 2 times.
386 for (i = 0; i < 192; i++)
1195 384 window[256 + i] = start_window[i];
1196
1197 // short 2
1198
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 2 times.
386 for (i = 0; i < 192; i++)
1199 384 window[448 + i] = short_window2[i];
1200
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 2 times.
130 for (i = 0; i < 64; i++)
1201 128 window[640 + i] = window[63 - i];
1202
1203 // short 3
1204
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 2 times.
130 for (i = 0; i < 64; i++)
1205 128 window[704 + i] = short_window3[i];
1206
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 2 times.
386 for (i = 0; i < 192; i++)
1207 384 window[768 + i] = window[64 + i];
1208
1209 // bridge
1210
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 2 times.
258 for (i = 0; i < 128; i++)
1211 256 window[960 + i] = window[i];
1212
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 2 times.
130 for (i = 0; i < 64; i++)
1213 128 window[1088 + i] = 1.0f;
1214
1215 // long
1216 2 ff_kbd_window_init(window + 1408, 3.0f, 256);
1217
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 2 times.
1282 for (i = 0; i < 640; i++)
1218 1280 window[1664 + i] = 1.0f;
1219
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 2 times.
514 for (i = 0; i < 256; i++)
1220 512 window[2304 + i] = window[1152 + i] = window[1663 - i];
1221
1222 // reverse start
1223
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 2 times.
386 for (i = 0; i < 192; i++)
1224 384 window[2560 + i] = window[447 - i];
1225
1226 // reverse short 2
1227
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 2 times.
514 for (i = 0; i < 256; i++)
1228 512 window[2752 + i] = window[703 - i];
1229
1230 // reverse short 3
1231
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 2 times.
514 for (i = 0; i < 256; i++)
1232 512 window[3008 + i] = window[959 - i];
1233
1234 // reverse bridge
1235
2/2
✓ Branch 0 taken 896 times.
✓ Branch 1 taken 2 times.
898 for (i = 0; i < 448; i++)
1236 896 window[3264 + i] = window[1407 - i];
1237 2 }
1238
1239 3 static av_cold int dolby_e_init(AVCodecContext *avctx)
1240 {
1241 static AVOnce init_once = AV_ONCE_INIT;
1242 3 DBEDecodeContext *s = avctx->priv_data;
1243 int i;
1244
1245
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (ff_thread_once(&init_once, init_tables))
1246 return AVERROR_UNKNOWN;
1247
1248
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (i = 0; i < 3; i++)
1249
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 if (ff_mdct_init(&s->imdct[i], imdct_bits_tab[i], 1, 2.0) < 0)
1250 return AVERROR(ENOMEM);
1251
1252
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (!(s->fdsp = avpriv_float_dsp_alloc(0)))
1253 return AVERROR(ENOMEM);
1254
1255 3 s->dectx.metadata.multi_prog_warned = !!(avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE);
1256 3 s->dectx.avctx = s->avctx = avctx;
1257 3 return 0;
1258 }
1259
1260 const AVCodec ff_dolby_e_decoder = {
1261 .name = "dolby_e",
1262 .long_name = NULL_IF_CONFIG_SMALL("Dolby E"),
1263 .type = AVMEDIA_TYPE_AUDIO,
1264 .id = AV_CODEC_ID_DOLBY_E,
1265 .priv_data_size = sizeof(DBEDecodeContext),
1266 .init = dolby_e_init,
1267 .decode = dolby_e_decode_frame,
1268 .close = dolby_e_close,
1269 .flush = dolby_e_flush,
1270 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
1271 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE },
1272 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
1273 };
1274