FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpegaudiodec_common.c
Date: 2021-09-16 08:47:15
Exec Total Coverage
Lines: 48 48 100.0%
Branches: 26 28 92.9%

Line Branch Exec Source
1 /*
2 * MPEG Audio decoder
3 * copyright (c) 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * mpeg audio layer decoder tables.
25 */
26
27 #include <stddef.h>
28 #include <stdint.h>
29
30 #include "libavutil/avassert.h"
31 #include "libavutil/thread.h"
32
33 #include "mpegaudiodata.h"
34
35 #include "mpegaudiodec_common_tablegen.h"
36
37 uint16_t ff_scale_factor_modshift[64];
38
39 static int16_t division_tab3[1 << 6 ];
40 static int16_t division_tab5[1 << 8 ];
41 static int16_t division_tab9[1 << 11];
42
43 int16_t *const ff_division_tabs[4] = {
44 division_tab3, division_tab5, NULL, division_tab9
45 };
46
47
48 /*******************************************************/
49 /* layer 3 tables */
50
51 const uint8_t ff_slen_table[2][16] = {
52 { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },
53 { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 },
54 };
55
56 const uint8_t ff_lsf_nsf_table[6][3][4] = {
57 { { 6, 5, 5, 5 }, { 9, 9, 9, 9 }, { 6, 9, 9, 9 } },
58 { { 6, 5, 7, 3 }, { 9, 9, 12, 6 }, { 6, 9, 12, 6 } },
59 { { 11, 10, 0, 0 }, { 18, 18, 0, 0 }, { 15, 18, 0, 0 } },
60 { { 7, 7, 7, 0 }, { 12, 12, 12, 0 }, { 6, 15, 12, 0 } },
61 { { 6, 6, 6, 3 }, { 12, 9, 9, 6 }, { 6, 12, 9, 6 } },
62 { { 8, 8, 5, 0 }, { 15, 12, 9, 0 }, { 6, 18, 9, 0 } },
63 };
64
65 /* mpegaudio layer 3 huffman tables */
66 VLC ff_huff_vlc[16];
67 static VLC_TYPE huff_vlc_tables[128 + 128 + 128 + 130 + 128 + 154 + 166 + 142 +
68 204 + 190 + 170 + 542 + 460 + 662 + 414][2];
69 VLC ff_huff_quad_vlc[2];
70 static VLC_TYPE huff_quad_vlc_tables[64 + 16][2];
71
72 static const uint8_t mpa_hufflens[] = {
73 /* Huffman table 1 - 4 entries */
74 3, 3, 2, 1,
75 /* Huffman table 2 - 9 entries */
76 6, 6, 5, 5, 5, 3, 3, 3, 1,
77 /* Huffman table 3 - 9 entries */
78 6, 6, 5, 5, 5, 3, 2, 2, 2,
79 /* Huffman table 5 - 16 entries */
80 8, 8, 7, 6, 7, 7, 7, 7, 6, 6, 6, 6, 3, 3, 3, 1,
81 /* Huffman table 6 - 16 entries */
82 7, 7, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 3, 2, 3, 3,
83 /* Huffman table 7 - 36 entries */
84 10, 10, 10, 10, 9, 9, 9, 9, 8, 8, 9, 9, 8, 9, 9, 8, 8, 7, 7,
85 7, 8, 8, 8, 8, 7, 7, 7, 7, 6, 5, 6, 6, 4, 3, 3, 1,
86 /* Huffman table 8 - 36 entries */
87 11, 11, 10, 9, 10, 10, 9, 9, 9, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
88 8, 8, 8, 8, 8, 8, 8, 8, 6, 6, 6, 4, 4, 2, 3, 3, 2,
89 /* Huffman table 9 - 36 entries */
90 9, 9, 8, 8, 9, 9, 8, 8, 8, 8, 7, 7, 7, 8, 8, 7, 7, 7, 7,
91 6, 6, 6, 6, 5, 5, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3,
92 /* Huffman table 10 - 64 entries */
93 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 11, 11, 10, 9, 9, 10,
94 10, 9, 9, 10, 10, 9, 10, 10, 8, 8, 9, 9, 10, 10, 9, 9, 10, 10, 8,
95 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 6,
96 6, 6, 6, 4, 3, 3, 1,
97 /* Huffman table 11 - 64 entries */
98 10, 10, 10, 10, 10, 10, 10, 11, 11, 10, 10, 9, 9, 9, 10, 10, 10, 10, 8,
99 8, 9, 9, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 7, 8, 8, 7, 7,
100 8, 8, 8, 9, 9, 8, 8, 8, 8, 8, 8, 7, 7, 6, 6, 7, 7, 6, 5,
101 4, 5, 5, 3, 3, 3, 2,
102 /* Huffman table 12 - 64 entries */
103 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 9, 9, 8, 8, 8, 8, 8, 8,
104 9, 9, 8, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7,
105 7, 7, 7, 8, 8, 7, 7, 7, 6, 6, 6, 6, 7, 7, 6, 5, 5, 5, 4,
106 4, 5, 5, 4, 3, 3, 3,
107 /* Huffman table 13 - 256 entries */
108 19, 19, 18, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 15, 15, 16,
109 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 15, 16, 16, 14, 14, 15,
110 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 14, 13, 14,
111 14, 13, 13, 14, 14, 13, 14, 14, 13, 14, 14, 13, 14, 14, 13, 13, 14, 14, 12,
112 12, 12, 13, 13, 13, 13, 13, 13, 12, 13, 13, 12, 12, 13, 13, 13, 13, 13, 13,
113 13, 13, 13, 13, 13, 13, 12, 12, 13, 13, 12, 12, 12, 12, 13, 13, 13, 13, 12,
114 13, 13, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 12, 12, 11,
115 11, 12, 12, 11, 12, 12, 12, 12, 11, 11, 12, 12, 11, 12, 12, 11, 12, 12, 11,
116 12, 12, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 11, 11,
117 10, 11, 11, 10, 11, 11, 11, 11, 10, 10, 11, 11, 10, 10, 11, 11, 11, 11, 11,
118 11, 9, 9, 10, 10, 10, 10, 10, 11, 11, 9, 9, 9, 10, 10, 9, 9, 10, 10,
119 10, 10, 10, 10, 10, 10, 10, 10, 8, 9, 9, 9, 9, 9, 9, 10, 10, 9, 9,
120 9, 8, 8, 9, 9, 9, 9, 9, 9, 8, 7, 8, 8, 8, 8, 7, 7, 7, 7,
121 7, 6, 6, 6, 6, 4, 4, 3, 1,
122 /* Huffman table 15 - 256 entries */
123 13, 13, 13, 13, 12, 13, 13, 13, 13, 13, 13, 12, 13, 13, 12, 12, 12, 12, 12,
124 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
125 13, 11, 11, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 12, 12, 11, 11, 11, 11,
126 11, 11, 11, 11, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
127 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 11, 11, 11, 11, 11,
128 11, 10, 11, 11, 11, 11, 11, 11, 10, 10, 11, 11, 10, 10, 10, 10, 11, 11, 10,
129 10, 10, 10, 10, 10, 10, 11, 11, 10, 10, 10, 10, 10, 11, 11, 9, 10, 10, 10,
130 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 10, 10, 10, 10, 9, 10, 10, 9, 10,
131 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 10, 10, 9, 9, 9,
132 9, 9, 9, 10, 10, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9, 9,
133 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8,
134 8, 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 7, 8, 8, 7, 7,
135 7, 7, 8, 8, 7, 7, 7, 7, 7, 6, 7, 7, 6, 6, 7, 7, 6, 6, 6,
136 5, 5, 5, 5, 5, 3, 4, 4, 3,
137 /* Huffman table 16 - 256 entries */
138 11, 11, 11, 11, 11, 11, 11, 11, 10, 11, 11, 11, 11, 10, 10, 10, 10, 10, 8,
139 10, 10, 9, 9, 9, 9, 10, 16, 17, 17, 15, 15, 16, 16, 14, 15, 15, 14, 14,
140 15, 15, 14, 14, 15, 15, 15, 15, 14, 15, 15, 14, 13, 8, 9, 9, 8, 8, 13,
141 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 14, 14, 14, 14, 13, 14, 14,
142 13, 13, 13, 14, 14, 14, 14, 13, 13, 14, 14, 13, 14, 14, 12, 13, 13, 13, 13,
143 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 13, 13, 13, 13, 13, 13, 12, 13,
144 13, 12, 12, 13, 13, 11, 12, 12, 12, 12, 12, 12, 12, 13, 13, 11, 12, 12, 12,
145 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 11, 11, 11, 11, 12, 12,
146 12, 12, 12, 12, 12, 12, 11, 12, 12, 11, 12, 12, 11, 12, 12, 11, 12, 12, 11,
147 10, 10, 11, 11, 11, 11, 11, 11, 10, 10, 11, 11, 10, 10, 11, 11, 11, 11, 11,
148 11, 11, 11, 10, 11, 11, 10, 10, 10, 11, 11, 10, 10, 11, 11, 10, 10, 11, 11,
149 10, 9, 9, 10, 10, 10, 10, 10, 10, 9, 9, 9, 10, 10, 9, 10, 10, 9, 9,
150 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 9, 9, 8, 8, 7, 7, 8, 8,
151 7, 6, 6, 6, 6, 4, 4, 3, 1,
152 /* Huffman table 24 - 256 entries */
153 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 7, 7, 8, 8, 7, 7, 7, 7,
154 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 9, 11, 11, 11, 11, 11, 11, 11, 11,
155 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
156 11, 4, 11, 11, 11, 11, 12, 12, 11, 10, 11, 11, 10, 10, 10, 10, 11, 11, 10,
157 10, 10, 10, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
158 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
159 10, 10, 10, 10, 10, 10, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
160 10, 10, 11, 11, 10, 11, 11, 10, 9, 10, 10, 10, 10, 11, 11, 10, 9, 9, 10,
161 10, 9, 10, 10, 10, 10, 9, 9, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
162 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
163 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 9, 9, 9, 10, 10, 8, 9, 9, 8,
164 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8, 8, 8, 8,
165 8, 9, 9, 7, 8, 8, 7, 7, 7, 7, 7, 8, 8, 7, 7, 6, 6, 7, 7,
166 6, 5, 5, 6, 6, 4, 4, 4, 4,
167 };
168
169 static const uint8_t mpa_huffsymbols[] = {
170 /* Huffman table 1 - 4 entries */
171 0x11, 0x01, 0x10, 0x00,
172 /* Huffman table 2 - 9 entries */
173 0x22, 0x02, 0x12, 0x21, 0x20, 0x11, 0x01, 0x10, 0x00,
174 /* Huffman table 3 - 9 entries */
175 0x22, 0x02, 0x12, 0x21, 0x20, 0x10, 0x11, 0x01, 0x00,
176 /* Huffman table 5 - 16 entries */
177 0x33, 0x23, 0x32, 0x31, 0x13, 0x03, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
178 0x11, 0x01, 0x10, 0x00,
179 /* Huffman table 6 - 16 entries */
180 0x33, 0x03, 0x23, 0x32, 0x30, 0x13, 0x31, 0x22, 0x02, 0x12, 0x21, 0x20,
181 0x01, 0x11, 0x10, 0x00,
182 /* Huffman table 7 - 36 entries */
183 0x55, 0x45, 0x54, 0x53, 0x35, 0x44, 0x25, 0x52, 0x15, 0x51, 0x05, 0x34,
184 0x50, 0x43, 0x33, 0x24, 0x42, 0x14, 0x41, 0x40, 0x04, 0x23, 0x32, 0x03,
185 0x13, 0x31, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20, 0x11, 0x01, 0x10, 0x00,
186 /* Huffman table 8 - 36 entries */
187 0x55, 0x54, 0x45, 0x53, 0x35, 0x44, 0x25, 0x52, 0x05, 0x15, 0x51, 0x34,
188 0x43, 0x50, 0x33, 0x24, 0x42, 0x14, 0x41, 0x04, 0x40, 0x23, 0x32, 0x13,
189 0x31, 0x03, 0x30, 0x22, 0x02, 0x20, 0x12, 0x21, 0x11, 0x01, 0x10, 0x00,
190 /* Huffman table 9 - 36 entries */
191 0x55, 0x45, 0x35, 0x53, 0x54, 0x05, 0x44, 0x25, 0x52, 0x15, 0x51, 0x34,
192 0x43, 0x50, 0x04, 0x24, 0x42, 0x33, 0x40, 0x14, 0x41, 0x23, 0x32, 0x13,
193 0x31, 0x03, 0x30, 0x22, 0x02, 0x12, 0x21, 0x20, 0x11, 0x01, 0x10, 0x00,
194 /* Huffman table 10 - 64 entries */
195 0x77, 0x67, 0x76, 0x57, 0x75, 0x66, 0x47, 0x74, 0x56, 0x65, 0x37, 0x73,
196 0x46, 0x55, 0x54, 0x63, 0x27, 0x72, 0x64, 0x07, 0x70, 0x62, 0x45, 0x35,
197 0x06, 0x53, 0x44, 0x17, 0x71, 0x36, 0x26, 0x25, 0x52, 0x15, 0x51, 0x34,
198 0x43, 0x16, 0x61, 0x60, 0x05, 0x50, 0x24, 0x42, 0x33, 0x04, 0x14, 0x41,
199 0x40, 0x23, 0x32, 0x03, 0x13, 0x31, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
200 0x11, 0x01, 0x10, 0x00,
201 /* Huffman table 11 - 64 entries */
202 0x77, 0x67, 0x76, 0x75, 0x66, 0x47, 0x74, 0x57, 0x55, 0x56, 0x65, 0x37,
203 0x73, 0x46, 0x45, 0x54, 0x35, 0x53, 0x27, 0x72, 0x64, 0x07, 0x71, 0x17,
204 0x70, 0x36, 0x63, 0x60, 0x44, 0x25, 0x52, 0x05, 0x15, 0x62, 0x26, 0x06,
205 0x16, 0x61, 0x51, 0x34, 0x50, 0x43, 0x33, 0x24, 0x42, 0x14, 0x41, 0x04,
206 0x40, 0x23, 0x32, 0x13, 0x31, 0x03, 0x30, 0x22, 0x21, 0x12, 0x02, 0x20,
207 0x11, 0x01, 0x10, 0x00,
208 /* Huffman table 12 - 64 entries */
209 0x77, 0x67, 0x76, 0x57, 0x75, 0x66, 0x47, 0x74, 0x65, 0x56, 0x37, 0x73,
210 0x55, 0x27, 0x72, 0x46, 0x64, 0x17, 0x71, 0x07, 0x70, 0x36, 0x63, 0x45,
211 0x54, 0x44, 0x06, 0x05, 0x26, 0x62, 0x61, 0x16, 0x60, 0x35, 0x53, 0x25,
212 0x52, 0x15, 0x51, 0x34, 0x43, 0x50, 0x04, 0x24, 0x42, 0x14, 0x33, 0x41,
213 0x23, 0x32, 0x40, 0x03, 0x30, 0x13, 0x31, 0x22, 0x12, 0x21, 0x02, 0x20,
214 0x00, 0x11, 0x01, 0x10,
215 /* Huffman table 13 - 256 entries */
216 0xFE, 0xFC, 0xFD, 0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0x86, 0x49, 0x93, 0x39, 0x58, 0x85, 0x67, 0x29,
231 0x92, 0x57, 0x75, 0x38, 0x83, 0x66, 0x47, 0x74, 0x56, 0x65, 0x73, 0x19,
232 0x91, 0x09, 0x90, 0x48, 0x84, 0x72, 0x46, 0x64, 0x28, 0x82, 0x18, 0x37,
233 0x27, 0x17, 0x71, 0x55, 0x07, 0x70, 0x36, 0x63, 0x45, 0x54, 0x26, 0x62,
234 0x35, 0x81, 0x08, 0x80, 0x16, 0x61, 0x06, 0x60, 0x53, 0x44, 0x25, 0x52,
235 0x05, 0x15, 0x51, 0x34, 0x43, 0x50, 0x24, 0x42, 0x33, 0x14, 0x41, 0x04,
236 0x40, 0x23, 0x32, 0x13, 0x31, 0x03, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
237 0x11, 0x01, 0x10, 0x00,
238 /* Huffman table 15 - 256 entries */
239 0xFF, 0xEF, 0xFE, 0xDF, 0xEE, 0xFD, 0xCF, 0xFC, 0xDE, 0xED, 0xBF, 0xFB,
240 0xCE, 0xEC, 0xDD, 0xAF, 0xFA, 0xBE, 0xEB, 0xCD, 0xDC, 0x9F, 0xF9, 0xEA,
241 0xBD, 0xDB, 0x8F, 0xF8, 0xCC, 0x9E, 0xE9, 0x7F, 0xF7, 0xAD, 0xDA, 0xBC,
242 0x6F, 0xAE, 0x0F, 0xCB, 0xF6, 0x8E, 0xE8, 0x5F, 0x9D, 0xF5, 0x7E, 0xE7,
243 0xAC, 0xCA, 0xBB, 0xD9, 0x8D, 0x4F, 0xF4, 0x3F, 0xF3, 0xD8, 0xE6, 0x2F,
244 0xF2, 0x6E, 0xF0, 0x1F, 0xF1, 0x9C, 0xC9, 0x5E, 0xAB, 0xBA, 0xE5, 0x7D,
245 0xD7, 0x4E, 0xE4, 0x8C, 0xC8, 0x3E, 0x6D, 0xD6, 0xE3, 0x9B, 0xB9, 0x2E,
246 0xAA, 0xE2, 0x1E, 0xE1, 0x0E, 0xE0, 0x5D, 0xD5, 0x7C, 0xC7, 0x4D, 0x8B,
247 0xD4, 0xB8, 0x9A, 0xA9, 0x6C, 0xC6, 0x3D, 0xD3, 0xD2, 0x2D, 0x0D, 0x1D,
248 0x7B, 0xB7, 0xD1, 0x5C, 0xD0, 0xC5, 0x8A, 0xA8, 0x4C, 0xC4, 0x6B, 0xB6,
249 0x99, 0x0C, 0x3C, 0xC3, 0x7A, 0xA7, 0xA6, 0xC0, 0x0B, 0xC2, 0x2C, 0x5B,
250 0xB5, 0x1C, 0x89, 0x98, 0xC1, 0x4B, 0xB4, 0x6A, 0x3B, 0x79, 0xB3, 0x97,
251 0x88, 0x2B, 0x5A, 0xB2, 0xA5, 0x1B, 0xB1, 0xB0, 0x69, 0x96, 0x4A, 0xA4,
252 0x78, 0x87, 0x3A, 0xA3, 0x59, 0x95, 0x2A, 0xA2, 0x1A, 0xA1, 0x0A, 0xA0,
253 0x68, 0x86, 0x49, 0x94, 0x39, 0x93, 0x77, 0x09, 0x58, 0x85, 0x29, 0x67,
254 0x76, 0x92, 0x91, 0x19, 0x90, 0x48, 0x84, 0x57, 0x75, 0x38, 0x83, 0x66,
255 0x47, 0x28, 0x82, 0x18, 0x81, 0x74, 0x08, 0x80, 0x56, 0x65, 0x37, 0x73,
256 0x46, 0x27, 0x72, 0x64, 0x17, 0x55, 0x71, 0x07, 0x70, 0x36, 0x63, 0x45,
257 0x54, 0x26, 0x62, 0x16, 0x06, 0x60, 0x35, 0x61, 0x53, 0x44, 0x25, 0x52,
258 0x15, 0x51, 0x05, 0x50, 0x34, 0x43, 0x24, 0x42, 0x33, 0x41, 0x14, 0x04,
259 0x23, 0x32, 0x40, 0x03, 0x13, 0x31, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
260 0x11, 0x01, 0x10, 0x00,
261 /* Huffman table 16 - 256 entries */
262 0xEF, 0xFE, 0xDF, 0xFD, 0xCF, 0xFC, 0xBF, 0xFB, 0xAF, 0xFA, 0x9F, 0xF9,
263 0xF8, 0x8F, 0x7F, 0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48, 0x84, 0x75, 0x38, 0x83, 0x66,
278 0x28, 0x82, 0x47, 0x74, 0x18, 0x81, 0x80, 0x08, 0x56, 0x37, 0x73, 0x65,
279 0x46, 0x27, 0x72, 0x64, 0x55, 0x07, 0x17, 0x71, 0x70, 0x36, 0x63, 0x45,
280 0x54, 0x26, 0x62, 0x16, 0x61, 0x06, 0x60, 0x53, 0x35, 0x44, 0x25, 0x52,
281 0x51, 0x15, 0x05, 0x34, 0x43, 0x50, 0x24, 0x42, 0x33, 0x14, 0x41, 0x04,
282 0x40, 0x23, 0x32, 0x13, 0x31, 0x03, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
283 0x11, 0x01, 0x10, 0x00,
284 /* Huffman table 24 - 256 entries */
285 0xEF, 0xFE, 0xDF, 0xFD, 0xCF, 0xFC, 0xBF, 0xFB, 0xFA, 0xAF, 0x9F, 0xF9,
286 0xF8, 0x8F, 0x7F, 0xF7, 0x6F, 0xF6, 0x5F, 0xF5, 0x4F, 0xF4, 0x3F, 0xF3,
287 0x2F, 0xF2, 0xF1, 0x1F, 0xF0, 0x0F, 0xEE, 0xDE, 0xED, 0xCE, 0xEC, 0xDD,
288 0xBE, 0xEB, 0xCD, 0xDC, 0xAE, 0xEA, 0xBD, 0xDB, 0xCC, 0x9E, 0xE9, 0xAD,
289 0xDA, 0xBC, 0xCB, 0x8E, 0xE8, 0x9D, 0xD9, 0x7E, 0xE7, 0xAC, 0xFF, 0xCA,
290 0xBB, 0x8D, 0xD8, 0x0E, 0xE0, 0x0D, 0xE6, 0x6E, 0x9C, 0xC9, 0x5E, 0xBA,
291 0xE5, 0xAB, 0x7D, 0xD7, 0xE4, 0x8C, 0xC8, 0x4E, 0x2E, 0x3E, 0x6D, 0xD6,
292 0xE3, 0x9B, 0xB9, 0xAA, 0xE2, 0x1E, 0xE1, 0x5D, 0xD5, 0x7C, 0xC7, 0x4D,
293 0x8B, 0xB8, 0xD4, 0x9A, 0xA9, 0x6C, 0xC6, 0x3D, 0xD3, 0x2D, 0xD2, 0x1D,
294 0x7B, 0xB7, 0xD1, 0x5C, 0xC5, 0x8A, 0xA8, 0x99, 0x4C, 0xC4, 0x6B, 0xB6,
295 0xD0, 0x0C, 0x3C, 0xC3, 0x7A, 0xA7, 0x2C, 0xC2, 0x5B, 0xB5, 0x1C, 0x89,
296 0x98, 0xC1, 0x4B, 0xC0, 0x0B, 0x3B, 0xB0, 0x0A, 0x1A, 0xB4, 0x6A, 0xA6,
297 0x79, 0x97, 0xA0, 0x09, 0x90, 0xB3, 0x88, 0x2B, 0x5A, 0xB2, 0xA5, 0x1B,
298 0xB1, 0x69, 0x96, 0xA4, 0x4A, 0x78, 0x87, 0x3A, 0xA3, 0x59, 0x95, 0x2A,
299 0xA2, 0xA1, 0x68, 0x86, 0x77, 0x49, 0x94, 0x39, 0x93, 0x58, 0x85, 0x29,
300 0x67, 0x76, 0x92, 0x19, 0x91, 0x48, 0x84, 0x57, 0x75, 0x38, 0x83, 0x66,
301 0x28, 0x82, 0x18, 0x47, 0x74, 0x81, 0x08, 0x80, 0x56, 0x65, 0x17, 0x07,
302 0x70, 0x73, 0x37, 0x27, 0x72, 0x46, 0x64, 0x55, 0x71, 0x36, 0x63, 0x45,
303 0x54, 0x26, 0x62, 0x16, 0x61, 0x06, 0x60, 0x35, 0x53, 0x44, 0x25, 0x52,
304 0x15, 0x05, 0x50, 0x51, 0x34, 0x43, 0x24, 0x42, 0x33, 0x14, 0x41, 0x04,
305 0x40, 0x23, 0x32, 0x13, 0x31, 0x03, 0x30, 0x22, 0x12, 0x21, 0x02, 0x20,
306 0x11, 0x01, 0x10, 0x00,
307 };
308
309 static const uint8_t mpa_huff_sizes_minus_one[] =
310 {
311 3, 8, 8, 15, 15, 35, 35, 35, 63, 63, 63, 255, 255, 255, 255
312 };
313
314 const uint8_t ff_mpa_huff_data[32][2] = {
315 { 0, 0 },
316 { 1, 0 },
317 { 2, 0 },
318 { 3, 0 },
319 { 0, 0 },
320 { 4, 0 },
321 { 5, 0 },
322 { 6, 0 },
323 { 7, 0 },
324 { 8, 0 },
325 { 9, 0 },
326 { 10, 0 },
327 { 11, 0 },
328 { 12, 0 },
329 { 0, 0 },
330 { 13, 0 },
331 { 14, 1 },
332 { 14, 2 },
333 { 14, 3 },
334 { 14, 4 },
335 { 14, 6 },
336 { 14, 8 },
337 { 14, 10 },
338 { 14, 13 },
339 { 15, 4 },
340 { 15, 5 },
341 { 15, 6 },
342 { 15, 7 },
343 { 15, 8 },
344 { 15, 9 },
345 { 15, 11 },
346 { 15, 13 },
347 };
348
349
350 /* huffman tables for quadrules */
351 static const uint8_t mpa_quad_codes[2][16] = {
352 { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1, },
353 { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, },
354 };
355
356 static const uint8_t mpa_quad_bits[2][16] = {
357 { 1, 4, 4, 5, 4, 6, 5, 6, 4, 5, 5, 6, 5, 6, 6, 6, },
358 { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, },
359 };
360
361 const uint8_t ff_band_size_long[9][22] = {
362 { 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
363 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158, }, /* 44100 */
364 { 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
365 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192, }, /* 48000 */
366 { 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
367 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26, }, /* 32000 */
368 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
369 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 22050 */
370 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
371 18, 22, 26, 32, 38, 46, 52, 64, 70, 76, 36, }, /* 24000 */
372 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
373 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 16000 */
374 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
375 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 11025 */
376 { 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
377 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 12000 */
378 { 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32,
379 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2, }, /* 8000 */
380 };
381
382 const uint8_t ff_band_size_short[9][13] = {
383 { 4, 4, 4, 4, 6, 8, 10, 12, 14, 18, 22, 30, 56, }, /* 44100 */
384 { 4, 4, 4, 4, 6, 6, 10, 12, 14, 16, 20, 26, 66, }, /* 48000 */
385 { 4, 4, 4, 4, 6, 8, 12, 16, 20, 26, 34, 42, 12, }, /* 32000 */
386 { 4, 4, 4, 6, 6, 8, 10, 14, 18, 26, 32, 42, 18, }, /* 22050 */
387 { 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 32, 44, 12, }, /* 24000 */
388 { 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 16000 */
389 { 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 11025 */
390 { 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 12000 */
391 { 8, 8, 8, 12, 16, 20, 24, 28, 36, 2, 2, 2, 26, }, /* 8000 */
392 };
393
394 uint16_t ff_band_index_long[9][23];
395
396 const uint8_t ff_mpa_pretab[2][22] = {
397 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
398 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 },
399 };
400
401 81 static av_cold void mpegaudiodec_common_init_static(void)
402 {
403 81 const uint8_t *huff_sym = mpa_huffsymbols, *huff_lens = mpa_hufflens;
404 int offset;
405
406 /* scale factors table for layer 1/2 */
407
2/2
✓ Branch 0 taken 5184 times.
✓ Branch 1 taken 81 times.
5265 for (int i = 0; i < 64; i++) {
408 int shift, mod;
409 /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
410 5184 shift = i / 3;
411 5184 mod = i % 3;
412 5184 ff_scale_factor_modshift[i] = mod | (shift << 2);
413 }
414
415 /* huffman decode tables */
416 81 offset = 0;
417
2/2
✓ Branch 0 taken 1215 times.
✓ Branch 1 taken 81 times.
1296 for (int i = 0; i < 15;) {
418 uint16_t tmp_symbols[256];
419 1215 int nb_codes_minus_one = mpa_huff_sizes_minus_one[i];
420 int j;
421
422
2/2
✓ Branch 0 taken 111618 times.
✓ Branch 1 taken 1215 times.
112833 for (j = 0; j <= nb_codes_minus_one; j++) {
423 111618 uint8_t high = huff_sym[j] & 0xF0, low = huff_sym[j] & 0xF;
424
425
4/4
✓ Branch 0 taken 101736 times.
✓ Branch 1 taken 9882 times.
✓ Branch 2 taken 93069 times.
✓ Branch 3 taken 8667 times.
111618 tmp_symbols[j] = high << 1 | ((high && low) << 4) | low;
426 }
427
428 1215 ff_huff_vlc[++i].table = huff_vlc_tables + offset;
429 1215 ff_huff_vlc[i].table_allocated = FF_ARRAY_ELEMS(huff_vlc_tables) - offset;
430 1215 ff_init_vlc_from_lengths(&ff_huff_vlc[i], 7, j,
431 huff_lens, 1, tmp_symbols, 2, 2,
432 0, INIT_VLC_STATIC_OVERLONG, NULL);
433 1215 offset += ff_huff_vlc[i].table_size;
434 1215 huff_lens += j;
435 1215 huff_sym += j;
436 }
437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
81 av_assert0(offset == FF_ARRAY_ELEMS(huff_vlc_tables));
438
439 81 offset = 0;
440
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 81 times.
243 for (int i = 0; i < 2; i++) {
441
2/2
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 81 times.
162 int bits = i == 0 ? 6 : 4;
442 162 ff_huff_quad_vlc[i].table = huff_quad_vlc_tables + offset;
443 162 ff_huff_quad_vlc[i].table_allocated = 1 << bits;
444 162 offset += 1 << bits;
445 162 init_vlc(&ff_huff_quad_vlc[i], bits, 16,
446 mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1,
447 INIT_VLC_USE_NEW_STATIC);
448 }
449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81 times.
81 av_assert0(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables));
450
451
2/2
✓ Branch 0 taken 729 times.
✓ Branch 1 taken 81 times.
810 for (int i = 0; i < 9; i++) {
452 729 int k = 0;
453
2/2
✓ Branch 0 taken 16038 times.
✓ Branch 1 taken 729 times.
16767 for (int j = 0; j < 22; j++) {
454 16038 ff_band_index_long[i][j] = k;
455 16038 k += ff_band_size_long[i][j] >> 1;
456 }
457 729 ff_band_index_long[i][22] = k;
458 }
459
460
2/2
✓ Branch 0 taken 324 times.
✓ Branch 1 taken 81 times.
405 for (int i = 0; i < 4; i++) {
461
2/2
✓ Branch 0 taken 243 times.
✓ Branch 1 taken 81 times.
324 if (ff_mpa_quant_bits[i] < 0) {
462
2/2
✓ Branch 0 taken 191808 times.
✓ Branch 1 taken 243 times.
192051 for (int j = 0; j < (1 << (-ff_mpa_quant_bits[i] + 1)); j++) {
463 int val1, val2, val3, steps;
464 191808 int val = j;
465 191808 steps = ff_mpa_quant_steps[i];
466 191808 val1 = val % steps;
467 191808 val /= steps;
468 191808 val2 = val % steps;
469 191808 val3 = val / steps;
470 191808 ff_division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8);
471 }
472 }
473 }
474 81 mpegaudiodec_common_tableinit();
475 81 }
476
477 99 av_cold void ff_mpegaudiodec_common_init_static(void)
478 {
479 static AVOnce init_static_once = AV_ONCE_INIT;
480
481 99 ff_thread_once(&init_static_once, mpegaudiodec_common_init_static);
482 99 }
483