FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/adpcm.c
Date: 2025-07-05 02:49:51
Exec Total Coverage
Lines: 557 874 63.7%
Functions: 16 24 66.7%
Branches: 454 775 58.6%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2001-2003 The FFmpeg project
3 *
4 * first version by Francois Revol (revol@free.fr)
5 * fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
6 * by Mike Melanson (melanson@pcisys.net)
7 * CD-ROM XA ADPCM codec by BERO
8 * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
9 * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org)
10 * EA IMA EACS decoder by Peter Ross (pross@xvid.org)
11 * EA IMA SEAD decoder by Peter Ross (pross@xvid.org)
12 * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org)
13 * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com)
14 * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl)
15 * Argonaut Games ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
16 * Simon & Schuster Interactive ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
17 * Ubisoft ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
18 * High Voltage Software ALP decoder by Zane van Iperen (zane@zanevaniperen.com)
19 * Cunning Developments decoder by Zane van Iperen (zane@zanevaniperen.com)
20 * Sanyo LD-ADPCM decoder by Peter Ross (pross@xvid.org)
21 *
22 * This file is part of FFmpeg.
23 *
24 * FFmpeg is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU Lesser General Public
26 * License as published by the Free Software Foundation; either
27 * version 2.1 of the License, or (at your option) any later version.
28 *
29 * FFmpeg is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public
35 * License along with FFmpeg; if not, write to the Free Software
36 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 */
38
39 #include "config_components.h"
40
41 #include "avcodec.h"
42 #include "get_bits.h"
43 #include "bytestream.h"
44 #include "adpcm.h"
45 #include "adpcm_data.h"
46 #include "codec_internal.h"
47 #include "decode.h"
48
49 /**
50 * @file
51 * ADPCM decoders
52 * Features and limitations:
53 *
54 * Reference documents:
55 * http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs
56 * http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead]
57 * http://www.geocities.com/SiliconValley/8682/aud3.txt [dead]
58 * http://openquicktime.sourceforge.net/
59 * XAnim sources (xa_codec.c) http://xanim.polter.net/
60 * http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead]
61 * SoX source code http://sox.sourceforge.net/
62 *
63 * CD-ROM XA:
64 * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead]
65 * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead]
66 * readstr http://www.geocities.co.jp/Playtown/2004/
67 */
68
69 #define CASE_0(codec_id, ...)
70 #define CASE_1(codec_id, ...) \
71 case codec_id: \
72 { __VA_ARGS__ } \
73 break;
74 #define CASE_2(enabled, codec_id, ...) \
75 CASE_ ## enabled(codec_id, __VA_ARGS__)
76 #define CASE_3(config, codec_id, ...) \
77 CASE_2(config, codec_id, __VA_ARGS__)
78 #define CASE(codec, ...) \
79 CASE_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
80
81 /* These are for CD-ROM XA ADPCM */
82 static const int8_t xa_adpcm_table[5][2] = {
83 { 0, 0 },
84 { 60, 0 },
85 { 115, -52 },
86 { 98, -55 },
87 { 122, -60 }
88 };
89
90 static const int16_t afc_coeffs[2][16] = {
91 { 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, -1024, -1024, -2048 },
92 { 0, 0, 2048, 1024, -2048, -1536, -1024, -2560, -2248, -2300, -3072, -2048, -1024, 1024, 0, 0 }
93 };
94
95 static const int16_t ea_adpcm_table[] = {
96 0, 240, 460, 392,
97 0, 0, -208, -220,
98 0, 1, 3, 4,
99 7, 8, 10, 11,
100 0, -1, -3, -4
101 };
102
103 /*
104 * Dumped from the binaries:
105 * - FantasticJourney.exe - 0x794D2, DGROUP:0x47A4D2
106 * - BigRaceUSA.exe - 0x9B8AA, DGROUP:0x49C4AA
107 * - Timeshock!.exe - 0x8506A, DGROUP:0x485C6A
108 */
109 static const int8_t ima_cunning_index_table[9] = {
110 -1, -1, -1, -1, 1, 2, 3, 4, -1
111 };
112
113 /*
114 * Dumped from the binaries:
115 * - FantasticJourney.exe - 0x79458, DGROUP:0x47A458
116 * - BigRaceUSA.exe - 0x9B830, DGROUP:0x49C430
117 * - Timeshock!.exe - 0x84FF0, DGROUP:0x485BF0
118 */
119 static const int16_t ima_cunning_step_table[61] = {
120 1, 1, 1, 1, 2, 2, 3, 3, 4, 5,
121 6, 7, 8, 10, 12, 14, 16, 20, 24, 28,
122 32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
123 192, 224, 256, 320, 384, 448, 512, 640, 768, 896,
124 1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584, 4096, 5120,
125 6144, 7168, 8192, 10240, 12288, 14336, 16384, 20480, 24576, 28672, 0
126 };
127
128 static const int8_t adpcm_index_table2[4] = {
129 -1, 2,
130 -1, 2,
131 };
132
133 static const int8_t adpcm_index_table3[8] = {
134 -1, -1, 1, 2,
135 -1, -1, 1, 2,
136 };
137
138 static const int8_t adpcm_index_table5[32] = {
139 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
140 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
141 };
142
143 static const int8_t * const adpcm_index_tables[4] = {
144 &adpcm_index_table2[0],
145 &adpcm_index_table3[0],
146 &ff_adpcm_index_table[0],
147 &adpcm_index_table5[0],
148 };
149
150 static const int16_t mtaf_stepsize[32][16] = {
151 { 1, 5, 9, 13, 16, 20, 24, 28,
152 -1, -5, -9, -13, -16, -20, -24, -28, },
153 { 2, 6, 11, 15, 20, 24, 29, 33,
154 -2, -6, -11, -15, -20, -24, -29, -33, },
155 { 2, 7, 13, 18, 23, 28, 34, 39,
156 -2, -7, -13, -18, -23, -28, -34, -39, },
157 { 3, 9, 15, 21, 28, 34, 40, 46,
158 -3, -9, -15, -21, -28, -34, -40, -46, },
159 { 3, 11, 18, 26, 33, 41, 48, 56,
160 -3, -11, -18, -26, -33, -41, -48, -56, },
161 { 4, 13, 22, 31, 40, 49, 58, 67,
162 -4, -13, -22, -31, -40, -49, -58, -67, },
163 { 5, 16, 26, 37, 48, 59, 69, 80,
164 -5, -16, -26, -37, -48, -59, -69, -80, },
165 { 6, 19, 31, 44, 57, 70, 82, 95,
166 -6, -19, -31, -44, -57, -70, -82, -95, },
167 { 7, 22, 38, 53, 68, 83, 99, 114,
168 -7, -22, -38, -53, -68, -83, -99, -114, },
169 { 9, 27, 45, 63, 81, 99, 117, 135,
170 -9, -27, -45, -63, -81, -99, -117, -135, },
171 { 10, 32, 53, 75, 96, 118, 139, 161,
172 -10, -32, -53, -75, -96, -118, -139, -161, },
173 { 12, 38, 64, 90, 115, 141, 167, 193,
174 -12, -38, -64, -90, -115, -141, -167, -193, },
175 { 15, 45, 76, 106, 137, 167, 198, 228,
176 -15, -45, -76, -106, -137, -167, -198, -228, },
177 { 18, 54, 91, 127, 164, 200, 237, 273,
178 -18, -54, -91, -127, -164, -200, -237, -273, },
179 { 21, 65, 108, 152, 195, 239, 282, 326,
180 -21, -65, -108, -152, -195, -239, -282, -326, },
181 { 25, 77, 129, 181, 232, 284, 336, 388,
182 -25, -77, -129, -181, -232, -284, -336, -388, },
183 { 30, 92, 153, 215, 276, 338, 399, 461,
184 -30, -92, -153, -215, -276, -338, -399, -461, },
185 { 36, 109, 183, 256, 329, 402, 476, 549,
186 -36, -109, -183, -256, -329, -402, -476, -549, },
187 { 43, 130, 218, 305, 392, 479, 567, 654,
188 -43, -130, -218, -305, -392, -479, -567, -654, },
189 { 52, 156, 260, 364, 468, 572, 676, 780,
190 -52, -156, -260, -364, -468, -572, -676, -780, },
191 { 62, 186, 310, 434, 558, 682, 806, 930,
192 -62, -186, -310, -434, -558, -682, -806, -930, },
193 { 73, 221, 368, 516, 663, 811, 958, 1106,
194 -73, -221, -368, -516, -663, -811, -958, -1106, },
195 { 87, 263, 439, 615, 790, 966, 1142, 1318,
196 -87, -263, -439, -615, -790, -966, -1142, -1318, },
197 { 104, 314, 523, 733, 942, 1152, 1361, 1571,
198 -104, -314, -523, -733, -942, -1152, -1361, -1571, },
199 { 124, 374, 623, 873, 1122, 1372, 1621, 1871,
200 -124, -374, -623, -873, -1122, -1372, -1621, -1871, },
201 { 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
202 -148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
203 { 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
204 -177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
205 { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
206 -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
207 { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
208 -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
209 { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
210 -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
211 { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
212 -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
213 { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
214 -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
215 };
216
217 static const int16_t oki_step_table[49] = {
218 16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
219 41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
220 107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
221 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
222 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
223 };
224
225 // padded to zero where table size is less then 16
226 static const int8_t swf_index_tables[4][16] = {
227 /*2*/ { -1, 2 },
228 /*3*/ { -1, -1, 2, 4 },
229 /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
230 /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
231 };
232
233 static const int8_t zork_index_table[8] = {
234 -1, -1, -1, 1, 4, 7, 10, 12,
235 };
236
237 static const int8_t mtf_index_table[16] = {
238 8, 6, 4, 2, -1, -1, -1, -1,
239 -1, -1, -1, -1, 2, 4, 6, 8,
240 };
241
242 /* end of tables */
243
244 typedef struct ADPCMDecodeContext {
245 ADPCMChannelStatus status[14];
246 int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */
247 int has_status; /**< Status flag. Reset to 0 after a flush. */
248 } ADPCMDecodeContext;
249
250 static void adpcm_flush(AVCodecContext *avctx);
251
252 187 static av_cold int adpcm_decode_init(AVCodecContext * avctx)
253 {
254 187 ADPCMDecodeContext *c = avctx->priv_data;
255 187 unsigned int min_channels = 1;
256 187 unsigned int max_channels = 2;
257
258 187 adpcm_flush(avctx);
259
260
5/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 151 times.
187 switch(avctx->codec->id) {
261 3 case AV_CODEC_ID_ADPCM_IMA_AMV:
262 3 max_channels = 1;
263 3 break;
264 case AV_CODEC_ID_ADPCM_SANYO:
265 max_channels = 2;
266 break;
267 23 case AV_CODEC_ID_ADPCM_AFC:
268 case AV_CODEC_ID_ADPCM_EA_R1:
269 case AV_CODEC_ID_ADPCM_EA_R2:
270 case AV_CODEC_ID_ADPCM_EA_R3:
271 case AV_CODEC_ID_ADPCM_EA_XAS:
272 case AV_CODEC_ID_ADPCM_MS:
273 23 max_channels = 6;
274 23 break;
275 case AV_CODEC_ID_ADPCM_MTAF:
276 min_channels = 2;
277 max_channels = 8;
278 if (avctx->ch_layout.nb_channels & 1) {
279 avpriv_request_sample(avctx, "channel count %d", avctx->ch_layout.nb_channels);
280 return AVERROR_PATCHWELCOME;
281 }
282 break;
283 2 case AV_CODEC_ID_ADPCM_DTK:
284 2 min_channels = 2;
285 2 break;
286 case AV_CODEC_ID_ADPCM_PSX:
287 max_channels = 8;
288 if (avctx->ch_layout.nb_channels <= 0 ||
289 avctx->block_align % (16 * avctx->ch_layout.nb_channels))
290 return AVERROR_INVALIDDATA;
291 break;
292 8 case AV_CODEC_ID_ADPCM_IMA_DAT4:
293 case AV_CODEC_ID_ADPCM_THP:
294 case AV_CODEC_ID_ADPCM_THP_LE:
295 8 max_channels = 14;
296 8 break;
297 }
298
1/2
✓ Branch 0 taken 187 times.
✗ Branch 1 not taken.
187 if (avctx->ch_layout.nb_channels < min_channels ||
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 187 times.
187 avctx->ch_layout.nb_channels > max_channels) {
300 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
301 return AVERROR(EINVAL);
302 }
303
304
4/6
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 171 times.
187 switch(avctx->codec->id) {
305 9 case AV_CODEC_ID_ADPCM_IMA_WAV:
306
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (avctx->bits_per_coded_sample < 2 || avctx->bits_per_coded_sample > 5)
307 return AVERROR_INVALIDDATA;
308 9 break;
309 6 case AV_CODEC_ID_ADPCM_ARGO:
310
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (avctx->bits_per_coded_sample != 4 ||
311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 avctx->block_align != 17 * avctx->ch_layout.nb_channels)
312 return AVERROR_INVALIDDATA;
313 6 break;
314 case AV_CODEC_ID_ADPCM_SANYO:
315 if (avctx->bits_per_coded_sample < 3 || avctx->bits_per_coded_sample > 5)
316 return AVERROR_INVALIDDATA;
317 break;
318 1 case AV_CODEC_ID_ADPCM_IMA_XBOX:
319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (avctx->bits_per_coded_sample != 4)
320 return AVERROR_INVALIDDATA;
321 1 break;
322 case AV_CODEC_ID_ADPCM_ZORK:
323 if (avctx->bits_per_coded_sample != 8)
324 return AVERROR_INVALIDDATA;
325 break;
326 171 default:
327 171 break;
328 }
329
330
4/4
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 81 times.
187 switch (avctx->codec->id) {
331 87 case AV_CODEC_ID_ADPCM_AICA:
332 case AV_CODEC_ID_ADPCM_IMA_CUNNING:
333 case AV_CODEC_ID_ADPCM_IMA_DAT4:
334 case AV_CODEC_ID_ADPCM_IMA_QT:
335 case AV_CODEC_ID_ADPCM_IMA_WAV:
336 case AV_CODEC_ID_ADPCM_IMA_XBOX:
337 case AV_CODEC_ID_ADPCM_4XM:
338 case AV_CODEC_ID_ADPCM_XA:
339 case AV_CODEC_ID_ADPCM_XMD:
340 case AV_CODEC_ID_ADPCM_EA_R1:
341 case AV_CODEC_ID_ADPCM_EA_R2:
342 case AV_CODEC_ID_ADPCM_EA_R3:
343 case AV_CODEC_ID_ADPCM_EA_XAS:
344 case AV_CODEC_ID_ADPCM_THP:
345 case AV_CODEC_ID_ADPCM_THP_LE:
346 case AV_CODEC_ID_ADPCM_AFC:
347 case AV_CODEC_ID_ADPCM_DTK:
348 case AV_CODEC_ID_ADPCM_PSX:
349 case AV_CODEC_ID_ADPCM_SANYO:
350 case AV_CODEC_ID_ADPCM_MTAF:
351 case AV_CODEC_ID_ADPCM_ARGO:
352 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
353 87 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
354 87 break;
355 8 case AV_CODEC_ID_ADPCM_IMA_WS:
356
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 avctx->sample_fmt = c->vqa_version == 3 ? AV_SAMPLE_FMT_S16P :
357 AV_SAMPLE_FMT_S16;
358 8 break;
359 11 case AV_CODEC_ID_ADPCM_MS:
360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 avctx->sample_fmt = avctx->ch_layout.nb_channels > 2 ? AV_SAMPLE_FMT_S16P :
361 AV_SAMPLE_FMT_S16;
362 11 break;
363 81 default:
364 81 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
365 }
366 187 return 0;
367 }
368
369 static inline int16_t adpcm_agm_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
370 {
371 int delta, pred, step, add;
372
373 pred = c->predictor;
374 delta = nibble & 7;
375 step = c->step;
376 add = (delta * 2 + 1) * step;
377 if (add < 0)
378 add = add + 7;
379
380 if ((nibble & 8) == 0)
381 pred = av_clip(pred + (add >> 3), -32767, 32767);
382 else
383 pred = av_clip(pred - (add >> 3), -32767, 32767);
384
385 switch (delta) {
386 case 7:
387 step *= 0x99;
388 break;
389 case 6:
390 c->step = av_clip(c->step * 2, 127, 24576);
391 c->predictor = pred;
392 return pred;
393 case 5:
394 step *= 0x66;
395 break;
396 case 4:
397 step *= 0x4d;
398 break;
399 default:
400 step *= 0x39;
401 break;
402 }
403
404 if (step < 0)
405 step += 0x3f;
406
407 c->step = step >> 6;
408 c->step = av_clip(c->step, 127, 24576);
409 c->predictor = pred;
410 return pred;
411 }
412
413 10327321 static inline int16_t adpcm_ima_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift)
414 {
415 int step_index;
416 int predictor;
417 int sign, delta, diff, step;
418
419 10327321 step = ff_adpcm_step_table[c->step_index];
420 10327321 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
421 10327321 step_index = av_clip(step_index, 0, 88);
422
423 10327321 sign = nibble & 8;
424 10327321 delta = nibble & 7;
425 /* perform direct multiplication instead of series of jumps proposed by
426 * the reference ADPCM implementation since modern CPUs can do the mults
427 * quickly enough */
428 10327321 diff = ((2 * delta + 1) * step) >> shift;
429 10327321 predictor = c->predictor;
430
2/2
✓ Branch 0 taken 5115828 times.
✓ Branch 1 taken 5211493 times.
10327321 if (sign) predictor -= diff;
431 5211493 else predictor += diff;
432
433 10327321 c->predictor = av_clip_int16(predictor);
434 10327321 c->step_index = step_index;
435
436 10327321 return (int16_t)c->predictor;
437 }
438
439 679344 static inline int16_t adpcm_ima_alp_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift)
440 {
441 int step_index;
442 int predictor;
443 int sign, delta, diff, step;
444
445 679344 step = ff_adpcm_step_table[c->step_index];
446 679344 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
447 679344 step_index = av_clip(step_index, 0, 88);
448
449 679344 sign = nibble & 8;
450 679344 delta = nibble & 7;
451 679344 diff = (delta * step) >> shift;
452 679344 predictor = c->predictor;
453
2/2
✓ Branch 0 taken 339842 times.
✓ Branch 1 taken 339502 times.
679344 if (sign) predictor -= diff;
454 339502 else predictor += diff;
455
456 679344 c->predictor = av_clip_int16(predictor);
457 679344 c->step_index = step_index;
458
459 679344 return (int16_t)c->predictor;
460 }
461
462 static inline int16_t adpcm_ima_mtf_expand_nibble(ADPCMChannelStatus *c, int nibble)
463 {
464 int step_index, step, delta, predictor;
465
466 step = ff_adpcm_step_table[c->step_index];
467
468 delta = step * (2 * nibble - 15);
469 predictor = c->predictor + delta;
470
471 step_index = c->step_index + mtf_index_table[(unsigned)nibble];
472 c->predictor = av_clip_int16(predictor >> 4);
473 c->step_index = av_clip(step_index, 0, 88);
474
475 return (int16_t)c->predictor;
476 }
477
478 386028 static inline int16_t adpcm_ima_cunning_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
479 {
480 int step_index;
481 int predictor;
482 int step;
483
484 386028 nibble = sign_extend(nibble & 0xF, 4);
485
486 386028 step = ima_cunning_step_table[c->step_index];
487 386028 step_index = c->step_index + ima_cunning_index_table[abs(nibble)];
488 386028 step_index = av_clip(step_index, 0, 60);
489
490 386028 predictor = c->predictor + step * nibble;
491
492 386028 c->predictor = av_clip_int16(predictor);
493 386028 c->step_index = step_index;
494
495 386028 return c->predictor;
496 }
497
498 static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps)
499 {
500 int nibble, step_index, predictor, sign, delta, diff, step, shift;
501
502 shift = bps - 1;
503 nibble = get_bits_le(gb, bps),
504 step = ff_adpcm_step_table[c->step_index];
505 step_index = c->step_index + adpcm_index_tables[bps - 2][nibble];
506 step_index = av_clip(step_index, 0, 88);
507
508 sign = nibble & (1 << shift);
509 delta = av_zero_extend(nibble, shift);
510 diff = ((2 * delta + 1) * step) >> shift;
511 predictor = c->predictor;
512 if (sign) predictor -= diff;
513 else predictor += diff;
514
515 c->predictor = av_clip_int16(predictor);
516 c->step_index = step_index;
517
518 return (int16_t)c->predictor;
519 }
520
521 4696090 static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble)
522 {
523 int step_index;
524 int predictor;
525 int diff, step;
526
527 4696090 step = ff_adpcm_step_table[c->step_index];
528 4696090 step_index = c->step_index + ff_adpcm_index_table[nibble];
529 4696090 step_index = av_clip(step_index, 0, 88);
530
531 4696090 diff = step >> 3;
532
2/2
✓ Branch 0 taken 1076119 times.
✓ Branch 1 taken 3619971 times.
4696090 if (nibble & 4) diff += step;
533
2/2
✓ Branch 0 taken 1984447 times.
✓ Branch 1 taken 2711643 times.
4696090 if (nibble & 2) diff += step >> 1;
534
2/2
✓ Branch 0 taken 2159261 times.
✓ Branch 1 taken 2536829 times.
4696090 if (nibble & 1) diff += step >> 2;
535
536
2/2
✓ Branch 0 taken 2338238 times.
✓ Branch 1 taken 2357852 times.
4696090 if (nibble & 8)
537 2338238 predictor = c->predictor - diff;
538 else
539 2357852 predictor = c->predictor + diff;
540
541 4696090 c->predictor = av_clip_int16(predictor);
542 4696090 c->step_index = step_index;
543
544 4696090 return c->predictor;
545 }
546
547 2231940 static inline int16_t adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
548 {
549 int predictor;
550
551 2231940 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
552
2/2
✓ Branch 0 taken 972778 times.
✓ Branch 1 taken 1259162 times.
2231940 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
553
554 2231940 c->sample2 = c->sample1;
555 2231940 c->sample1 = av_clip_int16(predictor);
556 2231940 c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
557
2/2
✓ Branch 0 taken 92703 times.
✓ Branch 1 taken 2139237 times.
2231940 if (c->idelta < 16) c->idelta = 16;
558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2231940 times.
2231940 if (c->idelta > INT_MAX/768) {
559 av_log(NULL, AV_LOG_WARNING, "idelta overflow\n");
560 c->idelta = INT_MAX/768;
561 }
562
563 2231940 return c->sample1;
564 }
565
566 55124 static inline int16_t adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nibble)
567 {
568 int step_index, predictor, sign, delta, diff, step;
569
570 55124 step = oki_step_table[c->step_index];
571 55124 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
572 55124 step_index = av_clip(step_index, 0, 48);
573
574 55124 sign = nibble & 8;
575 55124 delta = nibble & 7;
576 55124 diff = ((2 * delta + 1) * step) >> 3;
577 55124 predictor = c->predictor;
578
2/2
✓ Branch 0 taken 25352 times.
✓ Branch 1 taken 29772 times.
55124 if (sign) predictor -= diff;
579 29772 else predictor += diff;
580
581 55124 c->predictor = av_clip_intp2(predictor, 11);
582 55124 c->step_index = step_index;
583
584 55124 return c->predictor * 16;
585 }
586
587 524192 static inline int16_t adpcm_ct_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
588 {
589 int sign, delta, diff;
590 int new_step;
591
592 524192 sign = nibble & 8;
593 524192 delta = nibble & 7;
594 /* perform direct multiplication instead of series of jumps proposed by
595 * the reference ADPCM implementation since modern CPUs can do the mults
596 * quickly enough */
597 524192 diff = ((2 * delta + 1) * c->step) >> 3;
598 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
599
2/2
✓ Branch 0 taken 263253 times.
✓ Branch 1 taken 260939 times.
524192 c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
600 524192 c->predictor = av_clip_int16(c->predictor);
601 /* calculate new step and clamp it to range 511..32767 */
602 524192 new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
603 524192 c->step = av_clip(new_step, 511, 32767);
604
605 524192 return (int16_t)c->predictor;
606 }
607
608 313380 static inline int16_t adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int size, int shift)
609 {
610 int sign, delta, diff;
611
612 313380 sign = nibble & (1<<(size-1));
613 313380 delta = nibble & ((1<<(size-1))-1);
614 313380 diff = delta << (7 + c->step + shift);
615
616 /* clamp result */
617
2/2
✓ Branch 0 taken 129904 times.
✓ Branch 1 taken 183476 times.
313380 c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
618
619 /* calculate new step */
620
4/4
✓ Branch 0 taken 97171 times.
✓ Branch 1 taken 216209 times.
✓ Branch 2 taken 75080 times.
✓ Branch 3 taken 22091 times.
313380 if (delta >= (2*size - 3) && c->step < 3)
621 75080 c->step++;
622
4/4
✓ Branch 0 taken 129907 times.
✓ Branch 1 taken 108393 times.
✓ Branch 2 taken 75080 times.
✓ Branch 3 taken 54827 times.
238300 else if (delta == 0 && c->step > 0)
623 75080 c->step--;
624
625 313380 return (int16_t) c->predictor;
626 }
627
628 1105920 static inline int16_t adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
629 {
630
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1105915 times.
1105920 if(!c->step) {
631 5 c->predictor = 0;
632 5 c->step = 127;
633 }
634
635 1105920 c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
636 1105920 c->predictor = av_clip_int16(c->predictor);
637 1105920 c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
638 1105920 c->step = av_clip(c->step, 127, 24576);
639 1105920 return c->predictor;
640 }
641
642 static inline int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
643 {
644 c->predictor += mtaf_stepsize[c->step][nibble];
645 c->predictor = av_clip_int16(c->predictor);
646 c->step += ff_adpcm_index_table[nibble];
647 c->step = av_clip_uintp2(c->step, 5);
648 return c->predictor;
649 }
650
651 static inline int16_t adpcm_zork_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
652 {
653 int16_t index = c->step_index;
654 uint32_t lookup_sample = ff_adpcm_step_table[index];
655 int32_t sample = 0;
656
657 if (nibble & 0x40)
658 sample += lookup_sample;
659 if (nibble & 0x20)
660 sample += lookup_sample >> 1;
661 if (nibble & 0x10)
662 sample += lookup_sample >> 2;
663 if (nibble & 0x08)
664 sample += lookup_sample >> 3;
665 if (nibble & 0x04)
666 sample += lookup_sample >> 4;
667 if (nibble & 0x02)
668 sample += lookup_sample >> 5;
669 if (nibble & 0x01)
670 sample += lookup_sample >> 6;
671 if (nibble & 0x80)
672 sample = -sample;
673
674 sample += c->predictor;
675 sample = av_clip_int16(sample);
676
677 index += zork_index_table[(nibble >> 4) & 7];
678 index = av_clip(index, 0, 88);
679
680 c->predictor = sample;
681 c->step_index = index;
682
683 return sample;
684 }
685
686 666 static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1,
687 const uint8_t *in, ADPCMChannelStatus *left,
688 ADPCMChannelStatus *right, int channels, int sample_offset)
689 {
690 int i, j;
691 int shift,filter,f0,f1;
692 int s_1,s_2;
693 int d,s,t;
694
695 666 out0 += sample_offset;
696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 666 times.
666 if (channels == 1)
697 out1 = out0 + 28;
698 else
699 666 out1 += sample_offset;
700
701
2/2
✓ Branch 0 taken 2664 times.
✓ Branch 1 taken 666 times.
3330 for(i=0;i<4;i++) {
702 2664 shift = 12 - (in[4+i*2] & 15);
703 2664 filter = in[4+i*2] >> 4;
704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2664 times.
2664 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
705 avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
706 filter=0;
707 }
708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2664 times.
2664 if (shift < 0) {
709 avpriv_request_sample(avctx, "unknown XA-ADPCM shift %d", shift);
710 shift = 0;
711 }
712 2664 f0 = xa_adpcm_table[filter][0];
713 2664 f1 = xa_adpcm_table[filter][1];
714
715 2664 s_1 = left->sample1;
716 2664 s_2 = left->sample2;
717
718
2/2
✓ Branch 0 taken 74592 times.
✓ Branch 1 taken 2664 times.
77256 for(j=0;j<28;j++) {
719 74592 d = in[16+i+j*4];
720
721 74592 t = sign_extend(d, 4);
722 74592 s = t*(1<<shift) + ((s_1*f0 + s_2*f1+32)>>6);
723 74592 s_2 = s_1;
724 74592 s_1 = av_clip_int16(s);
725 74592 out0[j] = s_1;
726 }
727
728
1/2
✓ Branch 0 taken 2664 times.
✗ Branch 1 not taken.
2664 if (channels == 2) {
729 2664 left->sample1 = s_1;
730 2664 left->sample2 = s_2;
731 2664 s_1 = right->sample1;
732 2664 s_2 = right->sample2;
733 }
734
735 2664 shift = 12 - (in[5+i*2] & 15);
736 2664 filter = in[5+i*2] >> 4;
737
2/4
✓ Branch 0 taken 2664 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2664 times.
2664 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table) || shift < 0) {
738 avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
739 filter=0;
740 }
741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2664 times.
2664 if (shift < 0) {
742 avpriv_request_sample(avctx, "unknown XA-ADPCM shift %d", shift);
743 shift = 0;
744 }
745
746 2664 f0 = xa_adpcm_table[filter][0];
747 2664 f1 = xa_adpcm_table[filter][1];
748
749
2/2
✓ Branch 0 taken 74592 times.
✓ Branch 1 taken 2664 times.
77256 for(j=0;j<28;j++) {
750 74592 d = in[16+i+j*4];
751
752 74592 t = sign_extend(d >> 4, 4);
753 74592 s = t*(1<<shift) + ((s_1*f0 + s_2*f1+32)>>6);
754 74592 s_2 = s_1;
755 74592 s_1 = av_clip_int16(s);
756 74592 out1[j] = s_1;
757 }
758
759
1/2
✓ Branch 0 taken 2664 times.
✗ Branch 1 not taken.
2664 if (channels == 2) {
760 2664 right->sample1 = s_1;
761 2664 right->sample2 = s_2;
762 } else {
763 left->sample1 = s_1;
764 left->sample2 = s_2;
765 }
766
767 2664 out0 += 28 * (3 - channels);
768 2664 out1 += 28 * (3 - channels);
769 }
770
771 666 return 0;
772 }
773
774 195 static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
775 {
776 195 ADPCMDecodeContext *c = avctx->priv_data;
777 GetBitContext gb;
778 const int8_t *table;
779 195 int channels = avctx->ch_layout.nb_channels;
780 int k0, signmask, nb_bits, count;
781 195 int size = buf_size*8;
782 int i;
783
784 195 init_get_bits(&gb, buf, size);
785
786 //read bits & initial values
787 195 nb_bits = get_bits(&gb, 2)+2;
788 195 table = swf_index_tables[nb_bits-2];
789 195 k0 = 1 << (nb_bits-2);
790 195 signmask = 1 << (nb_bits-1);
791
792
2/2
✓ Branch 1 taken 195 times.
✓ Branch 2 taken 195 times.
390 while (get_bits_count(&gb) <= size - 22 * channels) {
793
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 195 times.
585 for (i = 0; i < channels; i++) {
794 390 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
795 390 c->status[i].step_index = get_bits(&gb, 6);
796 }
797
798
3/4
✓ Branch 1 taken 798525 times.
✓ Branch 2 taken 195 times.
✓ Branch 3 taken 798525 times.
✗ Branch 4 not taken.
798720 for (count = 0; get_bits_count(&gb) <= size - nb_bits * channels && count < 4095; count++) {
799 int i;
800
801
2/2
✓ Branch 0 taken 1597050 times.
✓ Branch 1 taken 798525 times.
2395575 for (i = 0; i < channels; i++) {
802 // similar to IMA adpcm
803 1597050 int delta = get_bits(&gb, nb_bits);
804 1597050 int step = ff_adpcm_step_table[c->status[i].step_index];
805 1597050 int vpdiff = 0; // vpdiff = (delta+0.5)*step/4
806 1597050 int k = k0;
807
808 do {
809
2/2
✓ Branch 0 taken 1979561 times.
✓ Branch 1 taken 2811589 times.
4791150 if (delta & k)
810 1979561 vpdiff += step;
811 4791150 step >>= 1;
812 4791150 k >>= 1;
813
2/2
✓ Branch 0 taken 3194100 times.
✓ Branch 1 taken 1597050 times.
4791150 } while(k);
814 1597050 vpdiff += step;
815
816
2/2
✓ Branch 0 taken 803527 times.
✓ Branch 1 taken 793523 times.
1597050 if (delta & signmask)
817 803527 c->status[i].predictor -= vpdiff;
818 else
819 793523 c->status[i].predictor += vpdiff;
820
821 1597050 c->status[i].step_index += table[delta & (~signmask)];
822
823 1597050 c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
824 1597050 c->status[i].predictor = av_clip_int16(c->status[i].predictor);
825
826 1597050 *samples++ = c->status[i].predictor;
827 }
828 }
829 }
830 195 }
831
832 18335520 int16_t ff_adpcm_argo_expand_nibble(ADPCMChannelStatus *cs, int nibble, int shift, int flag)
833 {
834 18335520 int sample = sign_extend(nibble, 4) * (1 << shift);
835
836
2/2
✓ Branch 0 taken 9806208 times.
✓ Branch 1 taken 8529312 times.
18335520 if (flag)
837 9806208 sample += (8 * cs->sample1) - (4 * cs->sample2);
838 else
839 8529312 sample += 4 * cs->sample1;
840
841 18335520 sample = av_clip_int16(sample >> 2);
842
843 18335520 cs->sample2 = cs->sample1;
844 18335520 cs->sample1 = sample;
845
846 18335520 return sample;
847 }
848
849 static int adpcm_sanyo_expand3(ADPCMChannelStatus *c, int bits)
850 {
851 int sign, delta, add;
852
853 sign = bits & 4;
854 if (sign)
855 delta = 4 - (bits & 3);
856 else
857 delta = bits;
858
859 switch (delta) {
860 case 0:
861 add = 0;
862 c->step = (3 * c->step) >> 2;
863 break;
864 case 1:
865 add = c->step;
866 c->step = (4 * c->step - (c->step >> 1)) >> 2;
867 break;
868 case 2:
869 add = 2 * c->step;
870 c->step = ((c->step >> 1) + add) >> 1;
871 break;
872 case 3:
873 add = 4 * c->step - (c->step >> 1);
874 c->step = 2 * c->step;
875 break;
876 case 4:
877 add = (11 * c->step) >> 1;
878 c->step = 3 * c->step;
879 break;
880 }
881
882 if (sign)
883 add = -add;
884
885 c->predictor = av_clip_int16(c->predictor + add);
886 c->step = av_clip(c->step, 1, 7281);
887 return c->predictor;
888 }
889
890 static int adpcm_sanyo_expand4(ADPCMChannelStatus *c, int bits)
891 {
892 int sign, delta, add;
893
894 sign = bits & 8;
895 if (sign)
896 delta = 8 - (bits & 7);
897 else
898 delta = bits;
899
900 switch (delta) {
901 case 0:
902 add = 0;
903 c->step = (3 * c->step) >> 2;
904 break;
905 case 1:
906 add = c->step;
907 c->step = (3 * c->step) >> 2;
908 break;
909 case 2:
910 add = 2 * c->step;
911 break;
912 case 3:
913 add = 3 * c->step;
914 break;
915 case 4:
916 add = 4 * c->step;
917 break;
918 case 5:
919 add = (11 * c->step) >> 1;
920 c->step += c->step >> 2;
921 break;
922 case 6:
923 add = (15 * c->step) >> 1;
924 c->step = 2 * c->step;
925 break;
926 case 7:
927 if (sign)
928 add = (19 * c->step) >> 1;
929 else
930 add = (21 * c->step) >> 1;
931 c->step = (c->step >> 1) + 2 * c->step;
932 break;
933 case 8:
934 add = (25 * c->step) >> 1;
935 c->step = 5 * c->step;
936 break;
937 }
938
939 if (sign)
940 add = -add;
941
942 c->predictor = av_clip_int16(c->predictor + add);
943 c->step = av_clip(c->step, 1, 2621);
944 return c->predictor;
945 }
946
947 static int adpcm_sanyo_expand5(ADPCMChannelStatus *c, int bits)
948 {
949 int sign, delta, add;
950
951 sign = bits & 0x10;
952 if (sign)
953 delta = 16 - (bits & 0xF);
954 else
955 delta = bits;
956
957 add = delta * c->step;
958 switch (delta) {
959 case 0:
960 c->step += (c->step >> 2) - (c->step >> 1);
961 break;
962 case 1:
963 case 2:
964 case 3:
965 c->step += (c->step >> 3) - (c->step >> 2);
966 break;
967 case 4:
968 case 5:
969 c->step += (c->step >> 4) - (c->step >> 3);
970 break;
971 case 6:
972 break;
973 case 7:
974 c->step += c->step >> 3;
975 break;
976 case 8:
977 c->step += c->step >> 2;
978 break;
979 case 9:
980 c->step += c->step >> 1;
981 break;
982 case 10:
983 c->step = 2 * c->step - (c->step >> 3);
984 break;
985 case 11:
986 c->step = 2 * c->step + (c->step >> 3);
987 break;
988 case 12:
989 c->step = 2 * c->step + (c->step >> 1) - (c->step >> 3);
990 break;
991 case 13:
992 c->step = 3 * c->step - (c->step >> 2);
993 break;
994 case 14:
995 c->step *= 3;
996 break;
997 case 15:
998 case 16:
999 c->step = (7 * c->step) >> 1;
1000 break;
1001 }
1002
1003 if (sign)
1004 add = -add;
1005
1006 c->predictor = av_clip_int16(c->predictor + add);
1007 c->step = av_clip(c->step, 1, 1024);
1008 return c->predictor;
1009 }
1010
1011 /**
1012 * Get the number of samples (per channel) that will be decoded from the packet.
1013 * In one case, this is actually the maximum number of samples possible to
1014 * decode with the given buf_size.
1015 *
1016 * @param[out] coded_samples set to the number of samples as coded in the
1017 * packet, or 0 if the codec does not encode the
1018 * number of samples in each frame.
1019 * @param[out] approx_nb_samples set to non-zero if the number of samples
1020 * returned is an approximation.
1021 */
1022 37703 static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
1023 int buf_size, int *coded_samples, int *approx_nb_samples)
1024 {
1025 37703 ADPCMDecodeContext *s = avctx->priv_data;
1026 37703 int nb_samples = 0;
1027 37703 int ch = avctx->ch_layout.nb_channels;
1028 37703 int has_coded_samples = 0;
1029 int header_size;
1030
1031 37703 *coded_samples = 0;
1032 37703 *approx_nb_samples = 0;
1033
1034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37703 times.
37703 if(ch <= 0)
1035 return 0;
1036
1037
4/4
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 26342 times.
✓ Branch 2 taken 1195 times.
✓ Branch 3 taken 9566 times.
37703 switch (avctx->codec->id) {
1038 /* constant, only check buf_size */
1039 600 case AV_CODEC_ID_ADPCM_EA_XAS:
1040
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
600 if (buf_size < 76 * ch)
1041 return 0;
1042 600 nb_samples = 128;
1043 600 break;
1044 26342 case AV_CODEC_ID_ADPCM_IMA_QT:
1045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26342 times.
26342 if (buf_size < 34 * ch)
1046 return 0;
1047 26342 nb_samples = 64;
1048 26342 break;
1049 /* simple 4-bit adpcm */
1050 1195 case AV_CODEC_ID_ADPCM_CT:
1051 case AV_CODEC_ID_ADPCM_IMA_APC:
1052 case AV_CODEC_ID_ADPCM_IMA_CUNNING:
1053 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1054 case AV_CODEC_ID_ADPCM_IMA_OKI:
1055 case AV_CODEC_ID_ADPCM_IMA_WS:
1056 case AV_CODEC_ID_ADPCM_YAMAHA:
1057 case AV_CODEC_ID_ADPCM_AICA:
1058 case AV_CODEC_ID_ADPCM_IMA_SSI:
1059 case AV_CODEC_ID_ADPCM_IMA_APM:
1060 case AV_CODEC_ID_ADPCM_IMA_ALP:
1061 case AV_CODEC_ID_ADPCM_IMA_MTF:
1062 1195 nb_samples = buf_size * 2 / ch;
1063 1195 break;
1064 }
1065
2/2
✓ Branch 0 taken 28137 times.
✓ Branch 1 taken 9566 times.
37703 if (nb_samples)
1066 28137 return nb_samples;
1067
1068 /* simple 4-bit adpcm, with header */
1069 9566 header_size = 0;
1070
3/3
✓ Branch 0 taken 145 times.
✓ Branch 1 taken 350 times.
✓ Branch 2 taken 9071 times.
9566 switch (avctx->codec->id) {
1071 145 case AV_CODEC_ID_ADPCM_4XM:
1072 case AV_CODEC_ID_ADPCM_AGM:
1073 case AV_CODEC_ID_ADPCM_IMA_ACORN:
1074 case AV_CODEC_ID_ADPCM_IMA_DAT4:
1075 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
1076 145 case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
1077 350 case AV_CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4 * ch; break;
1078 }
1079
2/2
✓ Branch 0 taken 495 times.
✓ Branch 1 taken 9071 times.
9566 if (header_size > 0)
1080 495 return (buf_size - header_size) * 2 / ch;
1081
1082 /* more complex formats */
1083
17/23
✓ Branch 0 taken 170 times.
✓ Branch 1 taken 158 times.
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 40 times.
✓ Branch 4 taken 400 times.
✓ Branch 5 taken 642 times.
✓ Branch 6 taken 649 times.
✓ Branch 7 taken 1000 times.
✓ Branch 8 taken 1668 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2947 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 57 times.
✓ Branch 13 taken 195 times.
✓ Branch 14 taken 71 times.
✓ Branch 15 taken 12 times.
✓ Branch 16 taken 37 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 32 times.
✓ Branch 19 taken 946 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
9071 switch (avctx->codec->id) {
1084 170 case AV_CODEC_ID_ADPCM_IMA_AMV:
1085 170 bytestream2_skip(gb, 4);
1086 170 has_coded_samples = 1;
1087 170 *coded_samples = bytestream2_get_le32u(gb);
1088 170 nb_samples = FFMIN((buf_size - 8) * 2, *coded_samples);
1089 170 bytestream2_seek(gb, -8, SEEK_CUR);
1090 170 break;
1091 158 case AV_CODEC_ID_ADPCM_EA:
1092 /* Stereo is 30 bytes per block */
1093 /* Mono is 15 bytes per block */
1094 158 has_coded_samples = 1;
1095 158 *coded_samples = bytestream2_get_le32(gb);
1096 158 *coded_samples -= *coded_samples % 28;
1097
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 nb_samples = (buf_size - 12) / (ch == 2 ? 30 : 15) * 28;
1098 158 break;
1099 47 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1100 47 has_coded_samples = 1;
1101 47 *coded_samples = bytestream2_get_le32(gb);
1102 47 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
1103 47 break;
1104 40 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1105 40 nb_samples = (buf_size - ch) / ch * 2;
1106 40 break;
1107 400 case AV_CODEC_ID_ADPCM_EA_R1:
1108 case AV_CODEC_ID_ADPCM_EA_R2:
1109 case AV_CODEC_ID_ADPCM_EA_R3:
1110 /* maximum number of samples */
1111 /* has internal offsets and a per-frame switch to signal raw 16-bit */
1112 400 has_coded_samples = 1;
1113
3/4
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 125 times.
✗ Branch 3 not taken.
400 switch (avctx->codec->id) {
1114 95 case AV_CODEC_ID_ADPCM_EA_R1:
1115 95 header_size = 4 + 9 * ch;
1116 95 *coded_samples = bytestream2_get_le32(gb);
1117 95 break;
1118 180 case AV_CODEC_ID_ADPCM_EA_R2:
1119 180 header_size = 4 + 5 * ch;
1120 180 *coded_samples = bytestream2_get_le32(gb);
1121 180 break;
1122 125 case AV_CODEC_ID_ADPCM_EA_R3:
1123 125 header_size = 4 + 5 * ch;
1124 125 *coded_samples = bytestream2_get_be32(gb);
1125 125 break;
1126 }
1127 400 *coded_samples -= *coded_samples % 28;
1128 400 nb_samples = (buf_size - header_size) * 2 / ch;
1129 400 nb_samples -= nb_samples % 28;
1130 400 *approx_nb_samples = 1;
1131 400 break;
1132 642 case AV_CODEC_ID_ADPCM_IMA_DK3:
1133
1/2
✓ Branch 0 taken 642 times.
✗ Branch 1 not taken.
642 if (avctx->block_align > 0)
1134 642 buf_size = FFMIN(buf_size, avctx->block_align);
1135 642 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
1136 642 break;
1137 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
1138
1/2
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
649 if (avctx->block_align > 0)
1139 649 buf_size = FFMIN(buf_size, avctx->block_align);
1140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 649 times.
649 if (buf_size < 4 * ch)
1141 return AVERROR_INVALIDDATA;
1142 649 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
1143 649 break;
1144 1000 case AV_CODEC_ID_ADPCM_IMA_RAD:
1145
1/2
✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
1000 if (avctx->block_align > 0)
1146 1000 buf_size = FFMIN(buf_size, avctx->block_align);
1147 1000 nb_samples = (buf_size - 4 * ch) * 2 / ch;
1148 1000 break;
1149
2/4
✓ Branch 0 taken 1668 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1668 times.
1668 CASE(ADPCM_IMA_WAV,
1150 int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1151 int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1152 if (avctx->block_align > 0)
1153 buf_size = FFMIN(buf_size, avctx->block_align);
1154 if (buf_size < 4 * ch)
1155 return AVERROR_INVALIDDATA;
1156 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
1157 ) /* End of CASE */
1158 CASE(ADPCM_IMA_XBOX,
1159 int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1160 int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1161 if (avctx->block_align > 0)
1162 buf_size = FFMIN(buf_size, avctx->block_align);
1163 if (buf_size < 4 * ch)
1164 return AVERROR_INVALIDDATA;
1165 nb_samples = (buf_size - 4 * ch) / (bsize * ch) * bsamples + 1;
1166 ) /* End of CASE */
1167 2947 case AV_CODEC_ID_ADPCM_MS:
1168
1/2
✓ Branch 0 taken 2947 times.
✗ Branch 1 not taken.
2947 if (avctx->block_align > 0)
1169 2947 buf_size = FFMIN(buf_size, avctx->block_align);
1170 2947 nb_samples = (buf_size - 6 * ch) * 2 / ch;
1171 2947 break;
1172 case AV_CODEC_ID_ADPCM_MTAF:
1173 if (avctx->block_align > 0)
1174 buf_size = FFMIN(buf_size, avctx->block_align);
1175 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
1176 break;
1177 57 case AV_CODEC_ID_ADPCM_SBPRO_2:
1178 case AV_CODEC_ID_ADPCM_SBPRO_3:
1179 case AV_CODEC_ID_ADPCM_SBPRO_4:
1180 {
1181 int samples_per_byte;
1182
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
57 switch (avctx->codec->id) {
1183 13 case AV_CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
1184 18 case AV_CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
1185 26 case AV_CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
1186 }
1187
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 54 times.
57 if (!s->status[0].step_index) {
1188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (buf_size < ch)
1189 return AVERROR_INVALIDDATA;
1190 3 nb_samples++;
1191 3 buf_size -= ch;
1192 }
1193 57 nb_samples += buf_size * samples_per_byte / ch;
1194 57 break;
1195 }
1196 195 case AV_CODEC_ID_ADPCM_SWF:
1197 {
1198 195 int buf_bits = buf_size * 8 - 2;
1199 195 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
1200 195 int block_hdr_size = 22 * ch;
1201 195 int block_size = block_hdr_size + nbits * ch * 4095;
1202 195 int nblocks = buf_bits / block_size;
1203 195 int bits_left = buf_bits - nblocks * block_size;
1204 195 nb_samples = nblocks * 4096;
1205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
195 if (bits_left >= block_hdr_size)
1206 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
1207 195 break;
1208 }
1209 71 case AV_CODEC_ID_ADPCM_THP:
1210 case AV_CODEC_ID_ADPCM_THP_LE:
1211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
71 if (avctx->extradata) {
1212 nb_samples = buf_size * 14 / (8 * ch);
1213 break;
1214 }
1215 71 has_coded_samples = 1;
1216 71 bytestream2_skip(gb, 4); // channel size
1217 142 *coded_samples = (avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE) ?
1218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
142 bytestream2_get_le32(gb) :
1219 71 bytestream2_get_be32(gb);
1220 71 buf_size -= 8 + 36 * ch;
1221 71 buf_size /= ch;
1222 71 nb_samples = buf_size / 8 * 14;
1223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
71 if (buf_size % 8 > 1)
1224 nb_samples += (buf_size % 8 - 1) * 2;
1225 71 *approx_nb_samples = 1;
1226 71 break;
1227 12 case AV_CODEC_ID_ADPCM_AFC:
1228 12 nb_samples = buf_size / (9 * ch) * 16;
1229 12 break;
1230 37 case AV_CODEC_ID_ADPCM_XA:
1231 37 nb_samples = (buf_size / 128) * 224 / ch;
1232 37 break;
1233 case AV_CODEC_ID_ADPCM_XMD:
1234 nb_samples = buf_size / (21 * ch) * 32;
1235 break;
1236 32 case AV_CODEC_ID_ADPCM_DTK:
1237 case AV_CODEC_ID_ADPCM_PSX:
1238 32 nb_samples = buf_size / (16 * ch) * 28;
1239 32 break;
1240 946 case AV_CODEC_ID_ADPCM_ARGO:
1241 946 nb_samples = buf_size / avctx->block_align * 32;
1242 946 break;
1243 case AV_CODEC_ID_ADPCM_ZORK:
1244 nb_samples = buf_size / ch;
1245 break;
1246 case AV_CODEC_ID_ADPCM_SANYO:
1247 if (!avctx->extradata || avctx->extradata_size != 2)
1248 return AVERROR_INVALIDDATA;
1249 nb_samples = AV_RL16(avctx->extradata);
1250 break;
1251 }
1252
1253 /* validate coded sample count */
1254
4/6
✓ Branch 0 taken 846 times.
✓ Branch 1 taken 8225 times.
✓ Branch 2 taken 846 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 846 times.
9071 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
1255 return AVERROR_INVALIDDATA;
1256
1257 9071 return nb_samples;
1258 }
1259
1260 37703 static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
1261 int *got_frame_ptr, AVPacket *avpkt)
1262 {
1263 37703 const uint8_t *buf = avpkt->data;
1264 37703 int buf_size = avpkt->size;
1265 37703 ADPCMDecodeContext *c = avctx->priv_data;
1266 37703 int channels = avctx->ch_layout.nb_channels;
1267 int16_t *samples;
1268 int16_t **samples_p;
1269 int st; /* stereo */
1270 int nb_samples, coded_samples, approx_nb_samples, ret;
1271 GetByteContext gb;
1272
1273 37703 bytestream2_init(&gb, buf, buf_size);
1274 37703 nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
1275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37703 times.
37703 if (nb_samples <= 0) {
1276 av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
1277 return AVERROR_INVALIDDATA;
1278 }
1279
1280 /* get output buffer */
1281 37703 frame->nb_samples = nb_samples;
1282
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37703 times.
37703 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1283 return ret;
1284 37703 samples = (int16_t *)frame->data[0];
1285 37703 samples_p = (int16_t **)frame->extended_data;
1286
1287 /* use coded_samples when applicable */
1288 /* it is always <= nb_samples, so the output buffer will be large enough */
1289
2/2
✓ Branch 0 taken 846 times.
✓ Branch 1 taken 36857 times.
37703 if (coded_samples) {
1290
3/4
✓ Branch 0 taken 375 times.
✓ Branch 1 taken 471 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 375 times.
846 if (!approx_nb_samples && coded_samples != nb_samples)
1291 av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
1292 846 frame->nb_samples = nb_samples = coded_samples;
1293 }
1294
1295 37703 st = channels == 2 ? 1 : 0;
1296
1297
32/45
✓ Branch 0 taken 26342 times.
✓ Branch 1 taken 1668 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 26 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2947 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 649 times.
✓ Branch 8 taken 642 times.
✓ Branch 9 taken 119 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 179 times.
✓ Branch 13 taken 127 times.
✓ Branch 14 taken 87 times.
✓ Branch 15 taken 85 times.
✓ Branch 16 taken 39 times.
✓ Branch 17 taken 54 times.
✓ Branch 18 taken 1000 times.
✓ Branch 19 taken 311 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 37 times.
✓ Branch 22 taken 47 times.
✓ Branch 23 taken 49 times.
✓ Branch 24 taken 158 times.
✓ Branch 25 taken 40 times.
✓ Branch 26 taken 400 times.
✓ Branch 27 taken 600 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 170 times.
✓ Branch 30 taken 350 times.
✓ Branch 31 taken 128 times.
✓ Branch 32 taken 57 times.
✓ Branch 33 taken 195 times.
✓ Branch 34 taken 136 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 12 times.
✓ Branch 37 taken 71 times.
✓ Branch 38 taken 32 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✓ Branch 41 taken 946 times.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
37703 switch(avctx->codec->id) {
1298
10/12
✓ Branch 1 taken 43648 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39464 times.
✓ Branch 4 taken 4184 times.
✓ Branch 5 taken 30 times.
✓ Branch 6 taken 43618 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 43648 times.
✓ Branch 13 taken 1396736 times.
✓ Branch 14 taken 43648 times.
✓ Branch 15 taken 43648 times.
✓ Branch 16 taken 26342 times.
1466726 CASE(ADPCM_IMA_QT,
1299 /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
1300 Channel data is interleaved per-chunk. */
1301 for (int channel = 0; channel < channels; channel++) {
1302 ADPCMChannelStatus *cs = &c->status[channel];
1303 int predictor;
1304 int step_index;
1305 /* (pppppp) (piiiiiii) */
1306
1307 /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
1308 predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
1309 step_index = predictor & 0x7F;
1310 predictor &= ~0x7F;
1311
1312 if (cs->step_index == step_index) {
1313 int diff = predictor - cs->predictor;
1314 if (diff < 0)
1315 diff = - diff;
1316 if (diff > 0x7f)
1317 goto update;
1318 } else {
1319 update:
1320 cs->step_index = step_index;
1321 cs->predictor = predictor;
1322 }
1323
1324 if (cs->step_index > 88u){
1325 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1326 channel, cs->step_index);
1327 return AVERROR_INVALIDDATA;
1328 }
1329
1330 samples = samples_p[channel];
1331
1332 for (int m = 0; m < 64; m += 2) {
1333 int byte = bytestream2_get_byteu(&gb);
1334 samples[m ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F);
1335 samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4 );
1336 }
1337 }
1338 ) /* End of CASE */
1339
10/22
✗ Branch 2 not taken.
✓ Branch 3 taken 3336 times.
✓ Branch 5 taken 3336 times.
✓ Branch 6 taken 1668 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1668 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 25 taken 1107936 times.
✓ Branch 26 taken 276984 times.
✓ Branch 27 taken 276984 times.
✓ Branch 28 taken 138492 times.
✓ Branch 29 taken 138492 times.
✓ Branch 30 taken 1668 times.
1528416 CASE(ADPCM_IMA_WAV,
1340 for (int i = 0; i < channels; i++) {
1341 ADPCMChannelStatus *cs = &c->status[i];
1342 cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
1343
1344 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1345 if (cs->step_index > 88u){
1346 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1347 i, cs->step_index);
1348 return AVERROR_INVALIDDATA;
1349 }
1350 }
1351
1352 if (avctx->bits_per_coded_sample != 4) {
1353 int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
1354 int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
1355 uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
1356 GetBitContext g;
1357
1358 for (int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1359 for (int i = 0; i < channels; i++) {
1360 ADPCMChannelStatus *cs = &c->status[i];
1361 samples = &samples_p[i][1 + n * samples_per_block];
1362 for (int j = 0; j < block_size; j++) {
1363 temp[j] = buf[4 * channels + block_size * n * channels +
1364 (j % 4) + (j / 4) * (channels * 4) + i * 4];
1365 }
1366 ret = init_get_bits8(&g, (const uint8_t *)&temp, block_size);
1367 if (ret < 0)
1368 return ret;
1369 for (int m = 0; m < samples_per_block; m++) {
1370 samples[m] = adpcm_ima_wav_expand_nibble(cs, &g,
1371 avctx->bits_per_coded_sample);
1372 }
1373 }
1374 }
1375 bytestream2_skip(&gb, avctx->block_align - channels * 4);
1376 } else {
1377 for (int n = 0; n < (nb_samples - 1) / 8; n++) {
1378 for (int i = 0; i < channels; i++) {
1379 ADPCMChannelStatus *cs = &c->status[i];
1380 samples = &samples_p[i][1 + n * 8];
1381 for (int m = 0; m < 8; m += 2) {
1382 int v = bytestream2_get_byteu(&gb);
1383 samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
1384 samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
1385 }
1386 }
1387 }
1388 }
1389 ) /* End of CASE */
1390 CASE(ADPCM_IMA_XBOX,
1391 for (int i = 0; i < channels; i++) {
1392 ADPCMChannelStatus *cs = &c->status[i];
1393 cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
1394
1395 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1396 if (cs->step_index > 88u) {
1397 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1398 i, cs->step_index);
1399 return AVERROR_INVALIDDATA;
1400 }
1401 }
1402
1403 for (int n = 0; n < (nb_samples-1) / 8; n++) {
1404 for (int i = 0; i < channels; i++) {
1405 ADPCMChannelStatus *cs = &c->status[i];
1406 samples = &samples_p[i][1 + n * 8];
1407 for (int m = 0; m < 8; m += 2) {
1408 int v = bytestream2_get_byteu(&gb);
1409 samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
1410 samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
1411 }
1412 }
1413 }
1414 frame->nb_samples--;
1415 ) /* End of CASE */
1416
9/10
✓ Branch 1 taken 52 times.
✓ Branch 2 taken 26 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 52 times.
✓ Branch 7 taken 52 times.
✓ Branch 8 taken 26 times.
✓ Branch 12 taken 38224 times.
✓ Branch 13 taken 52 times.
✓ Branch 14 taken 52 times.
✓ Branch 15 taken 26 times.
38406 CASE(ADPCM_4XM,
1417 for (int i = 0; i < channels; i++)
1418 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1419
1420 for (int i = 0; i < channels; i++) {
1421 c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1422 if (c->status[i].step_index > 88u) {
1423 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1424 i, c->status[i].step_index);
1425 return AVERROR_INVALIDDATA;
1426 }
1427 }
1428
1429 for (int i = 0; i < channels; i++) {
1430 ADPCMChannelStatus *cs = &c->status[i];
1431 samples = (int16_t *)frame->data[i];
1432 for (int n = nb_samples >> 1; n > 0; n--) {
1433 int v = bytestream2_get_byteu(&gb);
1434 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
1435 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
1436 }
1437 }
1438 ) /* End of CASE */
1439 CASE(ADPCM_AGM,
1440 for (int i = 0; i < channels; i++)
1441 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1442 for (int i = 0; i < channels; i++)
1443 c->status[i].step = sign_extend(bytestream2_get_le16u(&gb), 16);
1444
1445 for (int n = 0; n < nb_samples >> (1 - st); n++) {
1446 int v = bytestream2_get_byteu(&gb);
1447 *samples++ = adpcm_agm_expand_nibble(&c->status[0], v & 0xF);
1448 *samples++ = adpcm_agm_expand_nibble(&c->status[st], v >> 4 );
1449 }
1450 ) /* End of CASE */
1451
17/26
✗ Branch 0 not taken.
✓ Branch 1 taken 2947 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 2947 times.
✓ Branch 20 taken 2895 times.
✓ Branch 21 taken 52 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 2895 times.
✓ Branch 27 taken 2895 times.
✓ Branch 28 taken 52 times.
✓ Branch 31 taken 2895 times.
✓ Branch 32 taken 52 times.
✓ Branch 35 taken 2895 times.
✓ Branch 36 taken 52 times.
✓ Branch 38 taken 2895 times.
✓ Branch 39 taken 52 times.
✓ Branch 40 taken 2895 times.
✓ Branch 41 taken 52 times.
✓ Branch 45 taken 1115970 times.
✓ Branch 46 taken 2947 times.
1118917 CASE(ADPCM_MS,
1452 int block_predictor;
1453
1454 if (avctx->ch_layout.nb_channels > 2) {
1455 for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
1456 samples = samples_p[channel];
1457 block_predictor = bytestream2_get_byteu(&gb);
1458 if (block_predictor > 6) {
1459 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[%d] = %d\n",
1460 channel, block_predictor);
1461 return AVERROR_INVALIDDATA;
1462 }
1463 c->status[channel].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
1464 c->status[channel].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
1465 c->status[channel].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
1466 c->status[channel].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
1467 c->status[channel].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
1468 *samples++ = c->status[channel].sample2;
1469 *samples++ = c->status[channel].sample1;
1470 for (int n = (nb_samples - 2) >> 1; n > 0; n--) {
1471 int byte = bytestream2_get_byteu(&gb);
1472 *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte >> 4 );
1473 *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte & 0x0F);
1474 }
1475 }
1476 } else {
1477 block_predictor = bytestream2_get_byteu(&gb);
1478 if (block_predictor > 6) {
1479 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
1480 block_predictor);
1481 return AVERROR_INVALIDDATA;
1482 }
1483 c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
1484 c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
1485 if (st) {
1486 block_predictor = bytestream2_get_byteu(&gb);
1487 if (block_predictor > 6) {
1488 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",
1489 block_predictor);
1490 return AVERROR_INVALIDDATA;
1491 }
1492 c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
1493 c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
1494 }
1495 c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
1496 if (st){
1497 c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
1498 }
1499
1500 c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
1501 if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
1502 c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
1503 if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
1504
1505 *samples++ = c->status[0].sample2;
1506 if (st) *samples++ = c->status[1].sample2;
1507 *samples++ = c->status[0].sample1;
1508 if (st) *samples++ = c->status[1].sample1;
1509 for (int n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1510 int byte = bytestream2_get_byteu(&gb);
1511 *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 );
1512 *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
1513 }
1514 }
1515 ) /* End of CASE */
1516 CASE(ADPCM_MTAF,
1517 for (int channel = 0; channel < channels; channel += 2) {
1518 bytestream2_skipu(&gb, 4);
1519 c->status[channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1520 c->status[channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1521 c->status[channel ].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1522 bytestream2_skipu(&gb, 2);
1523 c->status[channel + 1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1524 bytestream2_skipu(&gb, 2);
1525 for (int n = 0; n < nb_samples; n += 2) {
1526 int v = bytestream2_get_byteu(&gb);
1527 samples_p[channel][n ] = adpcm_mtaf_expand_nibble(&c->status[channel], v & 0x0F);
1528 samples_p[channel][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel], v >> 4 );
1529 }
1530 for (int n = 0; n < nb_samples; n += 2) {
1531 int v = bytestream2_get_byteu(&gb);
1532 samples_p[channel + 1][n ] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v & 0x0F);
1533 samples_p[channel + 1][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v >> 4 );
1534 }
1535 }
1536 ) /* End of CASE */
1537
5/6
✗ Branch 2 not taken.
✓ Branch 3 taken 1298 times.
✓ Branch 5 taken 1298 times.
✓ Branch 6 taken 649 times.
✓ Branch 10 taken 1323960 times.
✓ Branch 11 taken 649 times.
1325907 CASE(ADPCM_IMA_DK4,
1538 for (int channel = 0; channel < channels; channel++) {
1539 ADPCMChannelStatus *cs = &c->status[channel];
1540 cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
1541 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1542 if (cs->step_index > 88u){
1543 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1544 channel, cs->step_index);
1545 return AVERROR_INVALIDDATA;
1546 }
1547 }
1548 for (int n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1549 int v = bytestream2_get_byteu(&gb);
1550 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
1551 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
1552 }
1553 ) /* End of CASE */
1554
1555 /* DK3 ADPCM support macro */
1556 #define DK3_GET_NEXT_NIBBLE() \
1557 if (decode_top_nibble_next) { \
1558 nibble = last_byte >> 4; \
1559 decode_top_nibble_next = 0; \
1560 } else { \
1561 last_byte = bytestream2_get_byteu(&gb); \
1562 nibble = last_byte & 0x0F; \
1563 decode_top_nibble_next = 1; \
1564 }
1565
11/14
✓ Branch 5 taken 642 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 642 times.
✓ Branch 10 taken 434634 times.
✓ Branch 11 taken 434634 times.
✓ Branch 14 taken 434634 times.
✓ Branch 15 taken 434634 times.
✓ Branch 18 taken 434634 times.
✓ Branch 19 taken 434634 times.
✓ Branch 22 taken 869268 times.
✓ Branch 23 taken 642 times.
✓ Branch 25 taken 642 times.
✗ Branch 26 not taken.
869910 CASE(ADPCM_IMA_DK3,
1566 int last_byte = 0;
1567 int nibble;
1568 int decode_top_nibble_next = 0;
1569 int diff_channel;
1570 const int16_t *samples_end = samples + channels * nb_samples;
1571
1572 bytestream2_skipu(&gb, 10);
1573 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1574 c->status[1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1575 c->status[0].step_index = bytestream2_get_byteu(&gb);
1576 c->status[1].step_index = bytestream2_get_byteu(&gb);
1577 if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){
1578 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",
1579 c->status[0].step_index, c->status[1].step_index);
1580 return AVERROR_INVALIDDATA;
1581 }
1582 /* sign extend the predictors */
1583 diff_channel = c->status[1].predictor;
1584
1585 while (samples < samples_end) {
1586
1587 /* for this algorithm, c->status[0] is the sum channel and
1588 * c->status[1] is the diff channel */
1589
1590 /* process the first predictor of the sum channel */
1591 DK3_GET_NEXT_NIBBLE();
1592 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
1593
1594 /* process the diff channel predictor */
1595 DK3_GET_NEXT_NIBBLE();
1596 adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
1597
1598 /* process the first pair of stereo PCM samples */
1599 diff_channel = (diff_channel + c->status[1].predictor) / 2;
1600 *samples++ = c->status[0].predictor + c->status[1].predictor;
1601 *samples++ = c->status[0].predictor - c->status[1].predictor;
1602
1603 /* process the second predictor of the sum channel */
1604 DK3_GET_NEXT_NIBBLE();
1605 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
1606
1607 /* process the second pair of stereo PCM samples */
1608 diff_channel = (diff_channel + c->status[1].predictor) / 2;
1609 *samples++ = c->status[0].predictor + c->status[1].predictor;
1610 *samples++ = c->status[0].predictor - c->status[1].predictor;
1611 }
1612
1613 if ((bytestream2_tell(&gb) & 1))
1614 bytestream2_skip(&gb, 1);
1615 ) /* End of CASE */
1616
6/8
✗ Branch 2 not taken.
✓ Branch 3 taken 119 times.
✓ Branch 5 taken 119 times.
✓ Branch 6 taken 119 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 60452 times.
✓ Branch 12 taken 60452 times.
✓ Branch 13 taken 119 times.
60690 CASE(ADPCM_IMA_ISS,
1617 for (int channel = 0; channel < channels; channel++) {
1618 ADPCMChannelStatus *cs = &c->status[channel];
1619 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1620 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1621 if (cs->step_index > 88u){
1622 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1623 channel, cs->step_index);
1624 return AVERROR_INVALIDDATA;
1625 }
1626 }
1627
1628 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1629 int v1, v2;
1630 int v = bytestream2_get_byteu(&gb);
1631 /* nibbles are swapped for mono */
1632 if (st) {
1633 v1 = v >> 4;
1634 v2 = v & 0x0F;
1635 } else {
1636 v2 = v >> 4;
1637 v1 = v & 0x0F;
1638 }
1639 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
1640 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
1641 }
1642 ) /* End of CASE */
1643 CASE(ADPCM_IMA_MOFLEX,
1644 for (int channel = 0; channel < channels; channel++) {
1645 ADPCMChannelStatus *cs = &c->status[channel];
1646 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1647 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1648 if (cs->step_index > 88u){
1649 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1650 channel, cs->step_index);
1651 return AVERROR_INVALIDDATA;
1652 }
1653 }
1654
1655 for (int subframe = 0; subframe < nb_samples / 256; subframe++) {
1656 for (int channel = 0; channel < channels; channel++) {
1657 samples = samples_p[channel] + 256 * subframe;
1658 for (int n = 0; n < 256; n += 2) {
1659 int v = bytestream2_get_byteu(&gb);
1660 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1661 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1662 }
1663 }
1664 }
1665 ) /* End of CASE */
1666 CASE(ADPCM_IMA_DAT4,
1667 for (int channel = 0; channel < channels; channel++) {
1668 ADPCMChannelStatus *cs = &c->status[channel];
1669 samples = samples_p[channel];
1670 bytestream2_skip(&gb, 4);
1671 for (int n = 0; n < nb_samples; n += 2) {
1672 int v = bytestream2_get_byteu(&gb);
1673 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
1674 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
1675 }
1676 }
1677 ) /* End of CASE */
1678
2/2
✓ Branch 3 taken 732060 times.
✓ Branch 4 taken 179 times.
732239 CASE(ADPCM_IMA_APC,
1679 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1680 int v = bytestream2_get_byteu(&gb);
1681 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
1682 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
1683 }
1684 ) /* End of CASE */
1685
2/2
✓ Branch 3 taken 514600 times.
✓ Branch 4 taken 127 times.
514727 CASE(ADPCM_IMA_SSI,
1686 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1687 int v = bytestream2_get_byteu(&gb);
1688 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0], v >> 4 );
1689 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0x0F);
1690 }
1691 ) /* End of CASE */
1692
4/4
✓ Branch 3 taken 347109 times.
✓ Branch 4 taken 181830 times.
✓ Branch 5 taken 181830 times.
✓ Branch 6 taken 87 times.
529026 CASE(ADPCM_IMA_APM,
1693 for (int n = nb_samples / 2; n > 0; n--) {
1694 for (int channel = 0; channel < channels; channel++) {
1695 int v = bytestream2_get_byteu(&gb);
1696 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[channel], v >> 4 );
1697 samples[st] = adpcm_ima_qt_expand_nibble(&c->status[channel], v & 0x0F);
1698 }
1699 samples += channels;
1700 }
1701 ) /* End of CASE */
1702
4/4
✓ Branch 3 taken 339672 times.
✓ Branch 4 taken 172372 times.
✓ Branch 5 taken 172372 times.
✓ Branch 6 taken 85 times.
512129 CASE(ADPCM_IMA_ALP,
1703 for (int n = nb_samples / 2; n > 0; n--) {
1704 for (int channel = 0; channel < channels; channel++) {
1705 int v = bytestream2_get_byteu(&gb);
1706 *samples++ = adpcm_ima_alp_expand_nibble(&c->status[channel], v >> 4 , 2);
1707 samples[st] = adpcm_ima_alp_expand_nibble(&c->status[channel], v & 0x0F, 2);
1708 }
1709 samples += channels;
1710 }
1711 ) /* End of CASE */
1712
4/4
✓ Branch 3 taken 193014 times.
✓ Branch 4 taken 51 times.
✓ Branch 5 taken 51 times.
✓ Branch 6 taken 39 times.
193104 CASE(ADPCM_IMA_CUNNING,
1713 for (int channel = 0; channel < channels; channel++) {
1714 int16_t *smp = samples_p[channel];
1715 for (int n = 0; n < nb_samples / 2; n++) {
1716 int v = bytestream2_get_byteu(&gb);
1717 *smp++ = adpcm_ima_cunning_expand_nibble(&c->status[channel], v & 0x0F);
1718 *smp++ = adpcm_ima_cunning_expand_nibble(&c->status[channel], v >> 4);
1719 }
1720 }
1721 ) /* End of CASE */
1722
2/2
✓ Branch 3 taken 27562 times.
✓ Branch 4 taken 54 times.
27616 CASE(ADPCM_IMA_OKI,
1723 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1724 int v = bytestream2_get_byteu(&gb);
1725 *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0], v >> 4 );
1726 *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);
1727 }
1728 ) /* End of CASE */
1729
10/12
✗ Branch 2 not taken.
✓ Branch 3 taken 2000 times.
✓ Branch 5 taken 2000 times.
✓ Branch 6 taken 1000 times.
✓ Branch 8 taken 16000 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 32000 times.
✓ Branch 13 taken 16000 times.
✓ Branch 15 taken 32000 times.
✓ Branch 16 taken 16000 times.
✓ Branch 17 taken 16000 times.
✓ Branch 18 taken 1000 times.
83000 CASE(ADPCM_IMA_RAD,
1730 for (int channel = 0; channel < channels; channel++) {
1731 ADPCMChannelStatus *cs = &c->status[channel];
1732 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1733 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1734 if (cs->step_index > 88u){
1735 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1736 channel, cs->step_index);
1737 return AVERROR_INVALIDDATA;
1738 }
1739 }
1740 for (int n = 0; n < nb_samples / 2; n++) {
1741 int byte[2];
1742
1743 byte[0] = bytestream2_get_byteu(&gb);
1744 if (st)
1745 byte[1] = bytestream2_get_byteu(&gb);
1746 for (int channel = 0; channel < channels; channel++) {
1747 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
1748 }
1749 for (int channel = 0; channel < channels; channel++) {
1750 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4 , 3);
1751 }
1752 }
1753 ) /* End of CASE */
1754
10/10
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 299 times.
✓ Branch 5 taken 8820 times.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 12 times.
✓ Branch 8 taken 12 times.
✓ Branch 12 taken 298777 times.
✓ Branch 13 taken 166477 times.
✓ Branch 14 taken 166477 times.
✓ Branch 15 taken 299 times.
474397 CASE(ADPCM_IMA_WS,
1755 if (c->vqa_version == 3) {
1756 for (int channel = 0; channel < channels; channel++) {
1757 int16_t *smp = samples_p[channel];
1758
1759 for (int n = nb_samples / 2; n > 0; n--) {
1760 int v = bytestream2_get_byteu(&gb);
1761 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1762 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1763 }
1764 }
1765 } else {
1766 for (int n = nb_samples / 2; n > 0; n--) {
1767 for (int channel = 0; channel < channels; channel++) {
1768 int v = bytestream2_get_byteu(&gb);
1769 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1770 samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1771 }
1772 samples += channels;
1773 }
1774 }
1775 bytestream2_seek(&gb, 0, SEEK_END);
1776 ) /* End of CASE */
1777 CASE(ADPCM_XMD,
1778 int bytes_remaining, block = 0;
1779 while (bytestream2_get_bytes_left(&gb) >= 21 * channels) {
1780 for (int channel = 0; channel < channels; channel++) {
1781 int16_t *out = samples_p[channel] + block * 32;
1782 int16_t history[2];
1783 uint16_t scale;
1784
1785 history[1] = sign_extend(bytestream2_get_le16(&gb), 16);
1786 history[0] = sign_extend(bytestream2_get_le16(&gb), 16);
1787 scale = bytestream2_get_le16(&gb);
1788
1789 out[0] = history[1];
1790 out[1] = history[0];
1791
1792 for (int n = 0; n < 15; n++) {
1793 unsigned byte = bytestream2_get_byte(&gb);
1794 int32_t nibble[2];
1795
1796 nibble[0] = sign_extend(byte & 15, 4);
1797 nibble[1] = sign_extend(byte >> 4, 4);
1798
1799 out[2+n*2] = nibble[0]*scale + ((history[0]*3667 - history[1]*1642) >> 11);
1800 history[1] = history[0];
1801 history[0] = out[2+n*2];
1802
1803 out[2+n*2+1] = nibble[1]*scale + ((history[0]*3667 - history[1]*1642) >> 11);
1804 history[1] = history[0];
1805 history[0] = out[2+n*2+1];
1806 }
1807 }
1808
1809 block++;
1810 }
1811 bytes_remaining = bytestream2_get_bytes_left(&gb);
1812 if (bytes_remaining > 0) {
1813 bytestream2_skip(&gb, bytes_remaining);
1814 }
1815 ) /* End of CASE */
1816
4/6
✗ Branch 2 not taken.
✓ Branch 3 taken 666 times.
✓ Branch 6 taken 666 times.
✓ Branch 7 taken 37 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 37 times.
703 CASE(ADPCM_XA,
1817 int16_t *out0 = samples_p[0];
1818 int16_t *out1 = samples_p[1];
1819 int samples_per_block = 28 * (3 - channels) * 4;
1820 int sample_offset = 0;
1821 int bytes_remaining;
1822 while (bytestream2_get_bytes_left(&gb) >= 128) {
1823 if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
1824 &c->status[0], &c->status[1],
1825 channels, sample_offset)) < 0)
1826 return ret;
1827 bytestream2_skipu(&gb, 128);
1828 sample_offset += samples_per_block;
1829 }
1830 /* Less than a full block of data left, e.g. when reading from
1831 * 2324 byte per sector XA; the remainder is padding */
1832 bytes_remaining = bytestream2_get_bytes_left(&gb);
1833 if (bytes_remaining > 0) {
1834 bytestream2_skip(&gb, bytes_remaining);
1835 }
1836 ) /* End of CASE */
1837
8/10
✗ Branch 1 not taken.
✓ Branch 2 taken 94 times.
✓ Branch 4 taken 94 times.
✓ Branch 5 taken 47 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 94 times.
✓ Branch 9 taken 94 times.
✓ Branch 10 taken 47 times.
✓ Branch 14 taken 68996 times.
✓ Branch 15 taken 47 times.
69231 CASE(ADPCM_IMA_EA_EACS,
1838 for (int i = 0; i <= st; i++) {
1839 c->status[i].step_index = bytestream2_get_le32u(&gb);
1840 if (c->status[i].step_index > 88u) {
1841 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1842 i, c->status[i].step_index);
1843 return AVERROR_INVALIDDATA;
1844 }
1845 }
1846 for (int i = 0; i <= st; i++) {
1847 c->status[i].predictor = bytestream2_get_le32u(&gb);
1848 if (FFABS((int64_t)c->status[i].predictor) > (1<<16))
1849 return AVERROR_INVALIDDATA;
1850 }
1851
1852 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1853 int byte = bytestream2_get_byteu(&gb);
1854 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3);
1855 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
1856 }
1857 ) /* End of CASE */
1858
2/2
✓ Branch 3 taken 71392 times.
✓ Branch 4 taken 49 times.
71441 CASE(ADPCM_IMA_EA_SEAD,
1859 for (int n = nb_samples >> (1 - st); n > 0; n--) {
1860 int byte = bytestream2_get_byteu(&gb);
1861 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 6);
1862 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);
1863 }
1864 ) /* End of CASE */
1865
9/16
✗ Branch 0 not taken.
✓ Branch 1 taken 158 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 9 taken 8296 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 232288 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 240584 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 232288 times.
✓ Branch 18 taken 8296 times.
✓ Branch 19 taken 8296 times.
✓ Branch 20 taken 158 times.
✓ Branch 21 taken 158 times.
✗ Branch 22 not taken.
240742 CASE(ADPCM_EA,
1866 int previous_left_sample, previous_right_sample;
1867 int current_left_sample, current_right_sample;
1868 int next_left_sample, next_right_sample;
1869 int coeff1l, coeff2l, coeff1r, coeff2r;
1870 int shift_left, shift_right;
1871
1872 /* Each EA ADPCM frame has a 12-byte header followed by 30-byte (stereo) or 15-byte (mono) pieces,
1873 each coding 28 stereo/mono samples. */
1874
1875 if (channels != 2 && channels != 1)
1876 return AVERROR_INVALIDDATA;
1877
1878 current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1879 previous_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1880 current_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1881 previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1882
1883 for (int count1 = 0; count1 < nb_samples / 28; count1++) {
1884 int byte = bytestream2_get_byteu(&gb);
1885 coeff1l = ea_adpcm_table[ byte >> 4 ];
1886 coeff2l = ea_adpcm_table[(byte >> 4 ) + 4];
1887 coeff1r = ea_adpcm_table[ byte & 0x0F];
1888 coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];
1889
1890 if (channels == 2){
1891 byte = bytestream2_get_byteu(&gb);
1892 shift_left = 20 - (byte >> 4);
1893 shift_right = 20 - (byte & 0x0F);
1894 } else{
1895 /* Mono packs the shift into the coefficient byte's lower nibble instead */
1896 shift_left = 20 - (byte & 0x0F);
1897 }
1898
1899 for (int count2 = 0; count2 < (channels == 2 ? 28 : 14); count2++) {
1900 byte = bytestream2_get_byteu(&gb);
1901 next_left_sample = sign_extend(byte >> 4, 4) * (1 << shift_left);
1902
1903 next_left_sample = (next_left_sample +
1904 (current_left_sample * coeff1l) +
1905 (previous_left_sample * coeff2l) + 0x80) >> 8;
1906
1907 previous_left_sample = current_left_sample;
1908 current_left_sample = av_clip_int16(next_left_sample);
1909 *samples++ = current_left_sample;
1910
1911 if (channels == 2){
1912 next_right_sample = sign_extend(byte, 4) * (1 << shift_right);
1913
1914 next_right_sample = (next_right_sample +
1915 (current_right_sample * coeff1r) +
1916 (previous_right_sample * coeff2r) + 0x80) >> 8;
1917
1918 previous_right_sample = current_right_sample;
1919 current_right_sample = av_clip_int16(next_right_sample);
1920 *samples++ = current_right_sample;
1921 } else {
1922 next_left_sample = sign_extend(byte, 4) * (1 << shift_left);
1923
1924 next_left_sample = (next_left_sample +
1925 (current_left_sample * coeff1l) +
1926 (previous_left_sample * coeff2l) + 0x80) >> 8;
1927
1928 previous_left_sample = current_left_sample;
1929 current_left_sample = av_clip_int16(next_left_sample);
1930
1931 *samples++ = current_left_sample;
1932 }
1933 }
1934 }
1935 bytestream2_skip(&gb, channels == 2 ? 2 : 3); // Skip terminating NULs
1936 ) /* End of CASE */
1937
11/12
✓ Branch 1 taken 160 times.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 80 times.
✓ Branch 4 taken 40 times.
✓ Branch 6 taken 560 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2240 times.
✓ Branch 10 taken 1120 times.
✓ Branch 11 taken 1120 times.
✓ Branch 12 taken 560 times.
✓ Branch 13 taken 560 times.
✓ Branch 14 taken 40 times.
4200 CASE(ADPCM_EA_MAXIS_XA,
1938 int coeff[2][2], shift[2];
1939
1940 for (int channel = 0; channel < channels; channel++) {
1941 int byte = bytestream2_get_byteu(&gb);
1942 for (int i = 0; i < 2; i++)
1943 coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
1944 shift[channel] = 20 - (byte & 0x0F);
1945 }
1946 for (int count1 = 0; count1 < nb_samples / 2; count1++) {
1947 int byte[2];
1948
1949 byte[0] = bytestream2_get_byteu(&gb);
1950 if (st) byte[1] = bytestream2_get_byteu(&gb);
1951 for (int i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
1952 for (int channel = 0; channel < channels; channel++) {
1953 int sample = sign_extend(byte[channel] >> i, 4) * (1 << shift[channel]);
1954 sample = (sample +
1955 c->status[channel].sample1 * coeff[channel][0] +
1956 c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
1957 c->status[channel].sample2 = c->status[channel].sample1;
1958 c->status[channel].sample1 = av_clip_int16(sample);
1959 *samples++ = c->status[channel].sample1;
1960 }
1961 }
1962 }
1963 bytestream2_seek(&gb, 0, SEEK_END);
1964 ) /* End of CASE */
1965 #if CONFIG_ADPCM_EA_R1_DECODER || CONFIG_ADPCM_EA_R2_DECODER || CONFIG_ADPCM_EA_R3_DECODER
1966 400 case AV_CODEC_ID_ADPCM_EA_R1:
1967 case AV_CODEC_ID_ADPCM_EA_R2:
1968 case AV_CODEC_ID_ADPCM_EA_R3: {
1969 /* channel numbering
1970 2chan: 0=fl, 1=fr
1971 4chan: 0=fl, 1=rl, 2=fr, 3=rr
1972 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
1973 400 const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;
1974 int previous_sample, current_sample, next_sample;
1975 int coeff1, coeff2;
1976 int shift;
1977 uint16_t *samplesC;
1978 400 int count = 0;
1979 int offsets[6];
1980
1981
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 400 times.
1200 for (unsigned channel = 0; channel < channels; channel++)
1982
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 550 times.
800 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1983 550 bytestream2_get_le32(&gb)) +
1984 800 (channels + 1) * 4;
1985
1986
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 400 times.
1200 for (unsigned channel = 0; channel < channels; channel++) {
1987 int count1;
1988
1989 800 bytestream2_seek(&gb, offsets[channel], SEEK_SET);
1990 800 samplesC = samples_p[channel];
1991
1992
2/2
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 610 times.
800 if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {
1993 190 current_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1994 190 previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1995 } else {
1996 610 current_sample = c->status[channel].predictor;
1997 610 previous_sample = c->status[channel].prev_sample;
1998 }
1999
2000
2/2
✓ Branch 0 taken 41192 times.
✓ Branch 1 taken 800 times.
41992 for (count1 = 0; count1 < nb_samples / 28; count1++) {
2001 41192 int byte = bytestream2_get_byte(&gb);
2002
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 41180 times.
41192 if (byte == 0xEE) { /* only seen in R2 and R3 */
2003 12 current_sample = sign_extend(bytestream2_get_be16(&gb), 16);
2004 12 previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
2005
2006
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 12 times.
348 for (int count2 = 0; count2 < 28; count2++)
2007 336 *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);
2008 } else {
2009 41180 coeff1 = ea_adpcm_table[ byte >> 4 ];
2010 41180 coeff2 = ea_adpcm_table[(byte >> 4) + 4];
2011 41180 shift = 20 - (byte & 0x0F);
2012
2013
2/2
✓ Branch 0 taken 1153040 times.
✓ Branch 1 taken 41180 times.
1194220 for (int count2 = 0; count2 < 28; count2++) {
2014
2/2
✓ Branch 0 taken 576520 times.
✓ Branch 1 taken 576520 times.
1153040 if (count2 & 1)
2015 576520 next_sample = (unsigned)sign_extend(byte, 4) << shift;
2016 else {
2017 576520 byte = bytestream2_get_byte(&gb);
2018 576520 next_sample = (unsigned)sign_extend(byte >> 4, 4) << shift;
2019 }
2020
2021 1153040 next_sample += (current_sample * coeff1) +
2022 1153040 (previous_sample * coeff2);
2023 1153040 next_sample = av_clip_int16(next_sample >> 8);
2024
2025 1153040 previous_sample = current_sample;
2026 1153040 current_sample = next_sample;
2027 1153040 *samplesC++ = current_sample;
2028 }
2029 }
2030 }
2031
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 400 times.
800 if (!count) {
2032 400 count = count1;
2033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 400 times.
400 } else if (count != count1) {
2034 av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
2035 count = FFMAX(count, count1);
2036 }
2037
2038
2/2
✓ Branch 0 taken 610 times.
✓ Branch 1 taken 190 times.
800 if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {
2039 610 c->status[channel].predictor = current_sample;
2040 610 c->status[channel].prev_sample = previous_sample;
2041 }
2042 }
2043
2044 400 frame->nb_samples = count * 28;
2045 400 bytestream2_seek(&gb, 0, SEEK_END);
2046 400 break;
2047 }
2048 #endif /* CONFIG_ADPCM_EA_Rx_DECODER */
2049
10/10
✓ Branch 1 taken 4800 times.
✓ Branch 2 taken 2400 times.
✓ Branch 4 taken 2400 times.
✓ Branch 5 taken 600 times.
✓ Branch 7 taken 36000 times.
✓ Branch 8 taken 9000 times.
✓ Branch 9 taken 9000 times.
✓ Branch 10 taken 600 times.
✓ Branch 11 taken 600 times.
✓ Branch 12 taken 600 times.
53400 CASE(ADPCM_EA_XAS,
2050 for (int channel=0; channel < channels; channel++) {
2051 int coeff[2][4], shift[4];
2052 int16_t *s = samples_p[channel];
2053 for (int n = 0; n < 4; n++, s += 32) {
2054 int val = sign_extend(bytestream2_get_le16u(&gb), 16);
2055 for (int i = 0; i < 2; i++)
2056 coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];
2057 s[0] = val & ~0x0F;
2058
2059 val = sign_extend(bytestream2_get_le16u(&gb), 16);
2060 shift[n] = 20 - (val & 0x0F);
2061 s[1] = val & ~0x0F;
2062 }
2063
2064 for (int m = 2; m < 32; m += 2) {
2065 s = &samples_p[channel][m];
2066 for (int n = 0; n < 4; n++, s += 32) {
2067 int level, pred;
2068 int byte = bytestream2_get_byteu(&gb);
2069
2070 level = sign_extend(byte >> 4, 4) * (1 << shift[n]);
2071 pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
2072 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
2073
2074 level = sign_extend(byte, 4) * (1 << shift[n]);
2075 pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
2076 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
2077 }
2078 }
2079 }
2080 ) /* End of CASE */
2081 CASE(ADPCM_IMA_ACORN,
2082 for (int channel = 0; channel < channels; channel++) {
2083 ADPCMChannelStatus *cs = &c->status[channel];
2084 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
2085 cs->step_index = bytestream2_get_le16u(&gb) & 0xFF;
2086 if (cs->step_index > 88u){
2087 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
2088 channel, cs->step_index);
2089 return AVERROR_INVALIDDATA;
2090 }
2091 }
2092 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2093 int byte = bytestream2_get_byteu(&gb);
2094 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte & 0x0F, 3);
2095 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte >> 4, 3);
2096 }
2097 ) /* End of CASE */
2098
7/10
✗ Branch 0 not taken.
✓ Branch 1 taken 170 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 170 times.
✓ Branch 13 taken 117130 times.
✓ Branch 14 taken 170 times.
✓ Branch 15 taken 23 times.
✓ Branch 16 taken 147 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 23 times.
117300 CASE(ADPCM_IMA_AMV,
2099 av_assert0(channels == 1);
2100
2101 /*
2102 * Header format:
2103 * int16_t predictor;
2104 * uint8_t step_index;
2105 * uint8_t reserved;
2106 * uint32_t frame_size;
2107 *
2108 * Some implementations have step_index as 16-bits, but others
2109 * only use the lower 8 and store garbage in the upper 8.
2110 */
2111 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
2112 c->status[0].step_index = bytestream2_get_byteu(&gb);
2113 bytestream2_skipu(&gb, 5);
2114 if (c->status[0].step_index > 88u) {
2115 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
2116 c->status[0].step_index);
2117 return AVERROR_INVALIDDATA;
2118 }
2119
2120 for (int n = nb_samples >> 1; n > 0; n--) {
2121 int v = bytestream2_get_byteu(&gb);
2122
2123 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
2124 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);
2125 }
2126
2127 if (nb_samples & 1) {
2128 int v = bytestream2_get_byteu(&gb);
2129 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
2130
2131 if (v & 0x0F) {
2132 /* Holds true on all the http://samples.mplayerhq.hu/amv samples. */
2133 av_log(avctx, AV_LOG_WARNING, "Last nibble set on packet with odd sample count.\n");
2134 av_log(avctx, AV_LOG_WARNING, "Sample will be skipped.\n");
2135 }
2136 }
2137 ) /* End of CASE */
2138
5/6
✗ Branch 3 not taken.
✓ Branch 4 taken 350 times.
✓ Branch 6 taken 350 times.
✓ Branch 7 taken 350 times.
✓ Branch 11 taken 89600 times.
✓ Branch 12 taken 350 times.
90300 CASE(ADPCM_IMA_SMJPEG,
2139 for (int i = 0; i < channels; i++) {
2140 c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
2141 c->status[i].step_index = bytestream2_get_byteu(&gb);
2142 bytestream2_skipu(&gb, 1);
2143 if (c->status[i].step_index > 88u) {
2144 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
2145 c->status[i].step_index);
2146 return AVERROR_INVALIDDATA;
2147 }
2148 }
2149
2150 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2151 int v = bytestream2_get_byteu(&gb);
2152
2153 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4 );
2154 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf);
2155 }
2156 ) /* End of CASE */
2157
2/2
✓ Branch 3 taken 262096 times.
✓ Branch 4 taken 128 times.
262224 CASE(ADPCM_CT,
2158 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2159 int v = bytestream2_get_byteu(&gb);
2160 *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
2161 *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
2162 }
2163 ) /* End of CASE */
2164 #if CONFIG_ADPCM_SBPRO_2_DECODER || CONFIG_ADPCM_SBPRO_3_DECODER || \
2165 CONFIG_ADPCM_SBPRO_4_DECODER
2166 57 case AV_CODEC_ID_ADPCM_SBPRO_4:
2167 case AV_CODEC_ID_ADPCM_SBPRO_3:
2168 case AV_CODEC_ID_ADPCM_SBPRO_2:
2169
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 54 times.
57 if (!c->status[0].step_index) {
2170 /* the first byte is a raw sample */
2171 3 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (st)
2173 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
2174 3 c->status[0].step_index = 1;
2175 3 nb_samples--;
2176 }
2177
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 31 times.
57 if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {
2178
2/2
✓ Branch 0 taken 52230 times.
✓ Branch 1 taken 26 times.
52256 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2179 52230 int byte = bytestream2_get_byteu(&gb);
2180 104460 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2181 52230 byte >> 4, 4, 0);
2182 52230 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2183 52230 byte & 0x0F, 4, 0);
2184 }
2185
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 13 times.
31 } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {
2186
2/2
✓ Branch 0 taken 34820 times.
✓ Branch 1 taken 18 times.
34838 for (int n = (nb_samples<<st) / 3; n > 0; n--) {
2187 34820 int byte = bytestream2_get_byteu(&gb);
2188 69640 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2189 34820 byte >> 5 , 3, 0);
2190 69640 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2191 34820 (byte >> 2) & 0x07, 3, 0);
2192 34820 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2193 34820 byte & 0x03, 2, 0);
2194 }
2195 } else {
2196
2/2
✓ Branch 0 taken 26115 times.
✓ Branch 1 taken 13 times.
26128 for (int n = nb_samples >> (2 - st); n > 0; n--) {
2197 26115 int byte = bytestream2_get_byteu(&gb);
2198 52230 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2199 26115 byte >> 6 , 2, 2);
2200 52230 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2201 26115 (byte >> 4) & 0x03, 2, 2);
2202 52230 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
2203 26115 (byte >> 2) & 0x03, 2, 2);
2204 26115 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
2205 26115 byte & 0x03, 2, 2);
2206 }
2207 }
2208 57 break;
2209 #endif /* CONFIG_ADPCM_SBPRO_x_DECODER */
2210 195 CASE(ADPCM_SWF,
2211 adpcm_swf_decode(avctx, buf, buf_size, samples);
2212 bytestream2_seek(&gb, 0, SEEK_END);
2213 ) /* End of CASE */
2214
2/2
✓ Branch 3 taken 552960 times.
✓ Branch 4 taken 136 times.
553096 CASE(ADPCM_YAMAHA,
2215 for (int n = nb_samples >> (1 - st); n > 0; n--) {
2216 int v = bytestream2_get_byteu(&gb);
2217 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
2218 *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
2219 }
2220 ) /* End of CASE */
2221 CASE(ADPCM_AICA,
2222 for (int channel = 0; channel < channels; channel++) {
2223 samples = samples_p[channel];
2224 for (int n = nb_samples >> 1; n > 0; n--) {
2225 int v = bytestream2_get_byteu(&gb);
2226 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v & 0x0F);
2227 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v >> 4 );
2228 }
2229 }
2230 ) /* End of CASE */
2231
11/16
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 7 taken 215040 times.
✓ Branch 8 taken 215040 times.
✓ Branch 10 taken 430080 times.
✓ Branch 11 taken 26880 times.
✓ Branch 12 taken 26880 times.
✓ Branch 13 taken 24 times.
✓ Branch 14 taken 24 times.
✓ Branch 15 taken 12 times.
✓ Branch 16 taken 12 times.
✓ Branch 17 taken 12 times.
457008 CASE(ADPCM_AFC,
2232 int samples_per_block;
2233 int blocks;
2234
2235 if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
2236 samples_per_block = avctx->extradata[0] / 16;
2237 blocks = nb_samples / avctx->extradata[0];
2238 } else {
2239 samples_per_block = nb_samples / 16;
2240 blocks = 1;
2241 }
2242
2243 for (int m = 0; m < blocks; m++) {
2244 for (int channel = 0; channel < channels; channel++) {
2245 int prev1 = c->status[channel].sample1;
2246 int prev2 = c->status[channel].sample2;
2247
2248 samples = samples_p[channel] + m * 16;
2249 /* Read in every sample for this channel. */
2250 for (int i = 0; i < samples_per_block; i++) {
2251 int byte = bytestream2_get_byteu(&gb);
2252 int scale = 1 << (byte >> 4);
2253 int index = byte & 0xf;
2254 int factor1 = afc_coeffs[0][index];
2255 int factor2 = afc_coeffs[1][index];
2256
2257 /* Decode 16 samples. */
2258 for (int n = 0; n < 16; n++) {
2259 int32_t sampledat;
2260
2261 if (n & 1) {
2262 sampledat = sign_extend(byte, 4);
2263 } else {
2264 byte = bytestream2_get_byteu(&gb);
2265 sampledat = sign_extend(byte >> 4, 4);
2266 }
2267
2268 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
2269 sampledat * scale;
2270 *samples = av_clip_int16(sampledat);
2271 prev2 = prev1;
2272 prev1 = *samples++;
2273 }
2274 }
2275
2276 c->status[channel].sample1 = prev1;
2277 c->status[channel].sample2 = prev2;
2278 }
2279 }
2280 bytestream2_seek(&gb, 0, SEEK_END);
2281 ) /* End of CASE */
2282 #if CONFIG_ADPCM_THP_DECODER || CONFIG_ADPCM_THP_LE_DECODER
2283 71 case AV_CODEC_ID_ADPCM_THP:
2284 case AV_CODEC_ID_ADPCM_THP_LE:
2285 {
2286 int table[14][16];
2287
2288 #define THP_GET16(g) \
2289 sign_extend( \
2290 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
2291 bytestream2_get_le16u(&(g)) : \
2292 bytestream2_get_be16u(&(g)), 16)
2293
2294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
71 if (avctx->extradata) {
2295 GetByteContext tb;
2296 if (avctx->extradata_size < 32 * channels) {
2297 av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
2298 return AVERROR_INVALIDDATA;
2299 }
2300
2301 bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
2302 for (int i = 0; i < channels; i++)
2303 for (int n = 0; n < 16; n++)
2304 table[i][n] = THP_GET16(tb);
2305 } else {
2306
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 71 times.
213 for (int i = 0; i < channels; i++)
2307
2/2
✓ Branch 0 taken 2272 times.
✓ Branch 1 taken 142 times.
2414 for (int n = 0; n < 16; n++)
2308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2272 times.
2272 table[i][n] = THP_GET16(gb);
2309
2310
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 70 times.
71 if (!c->has_status) {
2311 /* Initialize the previous sample. */
2312
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < channels; i++) {
2313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 c->status[i].sample1 = THP_GET16(gb);
2314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 c->status[i].sample2 = THP_GET16(gb);
2315 }
2316 1 c->has_status = 1;
2317 } else {
2318 70 bytestream2_skip(&gb, channels * 4);
2319 }
2320 }
2321
2322
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 71 times.
213 for (int ch = 0; ch < channels; ch++) {
2323 142 samples = samples_p[ch];
2324
2325 /* Read in every sample for this channel. */
2326
2/2
✓ Branch 0 taken 10840 times.
✓ Branch 1 taken 142 times.
10982 for (int i = 0; i < (nb_samples + 13) / 14; i++) {
2327 10840 int byte = bytestream2_get_byteu(&gb);
2328 10840 int index = (byte >> 4) & 7;
2329 10840 unsigned int exp = byte & 0x0F;
2330 10840 int64_t factor1 = table[ch][index * 2];
2331 10840 int64_t factor2 = table[ch][index * 2 + 1];
2332
2333 /* Decode 14 samples. */
2334
3/4
✓ Branch 0 taken 151760 times.
✓ Branch 1 taken 10840 times.
✓ Branch 2 taken 151760 times.
✗ Branch 3 not taken.
162600 for (int n = 0; n < 14 && (i * 14 + n < nb_samples); n++) {
2335 int32_t sampledat;
2336
2337
2/2
✓ Branch 0 taken 75880 times.
✓ Branch 1 taken 75880 times.
151760 if (n & 1) {
2338 75880 sampledat = sign_extend(byte, 4);
2339 } else {
2340 75880 byte = bytestream2_get_byteu(&gb);
2341 75880 sampledat = sign_extend(byte >> 4, 4);
2342 }
2343
2344 151760 sampledat = ((c->status[ch].sample1 * factor1
2345 151760 + c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 << exp);
2346 151760 *samples = av_clip_int16(sampledat);
2347 151760 c->status[ch].sample2 = c->status[ch].sample1;
2348 151760 c->status[ch].sample1 = *samples++;
2349 }
2350 }
2351 }
2352 71 break;
2353 }
2354 #endif /* CONFIG_ADPCM_THP(_LE)_DECODER */
2355
16/16
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 1024 times.
✓ Branch 5 taken 3388 times.
✓ Branch 6 taken 50876 times.
✓ Branch 7 taken 2744 times.
✓ Branch 8 taken 336 times.
✓ Branch 10 taken 28672 times.
✓ Branch 11 taken 28672 times.
✓ Branch 12 taken 57344 times.
✓ Branch 13 taken 2048 times.
✓ Branch 14 taken 2048 times.
✓ Branch 15 taken 64 times.
✓ Branch 16 taken 32 times.
✓ Branch 17 taken 32 times.
✓ Branch 19 taken 64 times.
✓ Branch 20 taken 32 times.
59488 CASE(ADPCM_DTK,
2356 for (int channel = 0; channel < channels; channel++) {
2357 samples = samples_p[channel];
2358
2359 /* Read in every sample for this channel. */
2360 for (int i = 0; i < nb_samples / 28; i++) {
2361 int byte, header;
2362 if (channel)
2363 bytestream2_skipu(&gb, 1);
2364 header = bytestream2_get_byteu(&gb);
2365 bytestream2_skipu(&gb, 3 - channel);
2366
2367 /* Decode 28 samples. */
2368 for (int n = 0; n < 28; n++) {
2369 int32_t sampledat, prev;
2370
2371 switch (header >> 4) {
2372 case 1:
2373 prev = (c->status[channel].sample1 * 0x3c);
2374 break;
2375 case 2:
2376 prev = (c->status[channel].sample1 * 0x73) - (c->status[channel].sample2 * 0x34);
2377 break;
2378 case 3:
2379 prev = (c->status[channel].sample1 * 0x62) - (c->status[channel].sample2 * 0x37);
2380 break;
2381 default:
2382 prev = 0;
2383 }
2384
2385 prev = av_clip_intp2((prev + 0x20) >> 6, 21);
2386
2387 byte = bytestream2_get_byteu(&gb);
2388 if (!channel)
2389 sampledat = sign_extend(byte, 4);
2390 else
2391 sampledat = sign_extend(byte >> 4, 4);
2392
2393 sampledat = ((sampledat * (1 << 12)) >> (header & 0xf)) * (1 << 6) + prev;
2394 *samples++ = av_clip_int16(sampledat >> 6);
2395 c->status[channel].sample2 = c->status[channel].sample1;
2396 c->status[channel].sample1 = sampledat;
2397 }
2398 }
2399 if (!channel)
2400 bytestream2_seek(&gb, 0, SEEK_SET);
2401 }
2402 ) /* End of CASE */
2403 CASE(ADPCM_PSX,
2404 for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * channels); block++) {
2405 int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * channels) / (16 * channels);
2406 for (int channel = 0; channel < channels; channel++) {
2407 samples = samples_p[channel] + block * nb_samples_per_block;
2408 av_assert0((block + 1) * nb_samples_per_block <= nb_samples);
2409
2410 /* Read in every sample for this channel. */
2411 for (int i = 0; i < nb_samples_per_block / 28; i++) {
2412 int filter, shift, flag, byte;
2413
2414 filter = bytestream2_get_byteu(&gb);
2415 shift = filter & 0xf;
2416 filter = filter >> 4;
2417 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table))
2418 return AVERROR_INVALIDDATA;
2419 flag = bytestream2_get_byteu(&gb) & 0x7;
2420
2421 /* Decode 28 samples. */
2422 for (int n = 0; n < 28; n++) {
2423 int sample = 0, scale;
2424
2425 if (n & 1) {
2426 scale = sign_extend(byte >> 4, 4);
2427 } else {
2428 byte = bytestream2_get_byteu(&gb);
2429 scale = sign_extend(byte, 4);
2430 }
2431
2432 if (flag < 0x07) {
2433 scale = scale * (1 << 12);
2434 sample = (int)((scale >> shift) + (c->status[channel].sample1 * xa_adpcm_table[filter][0] + c->status[channel].sample2 * xa_adpcm_table[filter][1]) / 64);
2435 }
2436 *samples++ = av_clip_int16(sample);
2437 c->status[channel].sample2 = c->status[channel].sample1;
2438 c->status[channel].sample1 = sample;
2439 }
2440 }
2441 }
2442 }
2443 ) /* End of CASE */
2444 CASE(ADPCM_SANYO,
2445 int (*expand)(ADPCMChannelStatus *c, int bits);
2446 GetBitContext g;
2447
2448 switch(avctx->bits_per_coded_sample) {
2449 case 3: expand = adpcm_sanyo_expand3; break;
2450 case 4: expand = adpcm_sanyo_expand4; break;
2451 case 5: expand = adpcm_sanyo_expand5; break;
2452 }
2453
2454 for (int ch = 0; ch < channels; ch++) {
2455 c->status[ch].predictor = sign_extend(bytestream2_get_le16(&gb), 16);
2456 c->status[ch].step = sign_extend(bytestream2_get_le16(&gb), 16);
2457 }
2458
2459 init_get_bits8(&g, gb.buffer, bytestream2_get_bytes_left(&gb));
2460 for (int i = 0; i < nb_samples; i++)
2461 for (int ch = 0; ch < channels; ch++)
2462 samples_p[ch][i] = expand(&c->status[ch], get_bits_le(&g, avctx->bits_per_coded_sample));
2463
2464 align_get_bits(&g);
2465 bytestream2_skip(&gb, get_bits_count(&g) / 8);
2466 ) /* End of CASE */
2467
6/6
✓ Branch 4 taken 747296 times.
✓ Branch 5 taken 46706 times.
✓ Branch 6 taken 46706 times.
✓ Branch 7 taken 30245 times.
✓ Branch 8 taken 30245 times.
✓ Branch 9 taken 946 times.
825193 CASE(ADPCM_ARGO,
2468 /*
2469 * The format of each block:
2470 * uint8_t left_control;
2471 * uint4_t left_samples[nb_samples];
2472 * ---- and if stereo ----
2473 * uint8_t right_control;
2474 * uint4_t right_samples[nb_samples];
2475 *
2476 * Format of the control byte:
2477 * MSB [SSSSRDRR] LSB
2478 * S = (Shift Amount - 2)
2479 * D = Decoder flag.
2480 * R = Reserved
2481 *
2482 * Each block relies on the previous two samples of each channel.
2483 * They should be 0 initially.
2484 */
2485 for (int block = 0; block < avpkt->size / avctx->block_align; block++) {
2486 for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
2487 ADPCMChannelStatus *cs = c->status + channel;
2488 int control, shift;
2489
2490 samples = samples_p[channel] + block * 32;
2491
2492 /* Get the control byte and decode the samples, 2 at a time. */
2493 control = bytestream2_get_byteu(&gb);
2494 shift = (control >> 4) + 2;
2495
2496 for (int n = 0; n < 16; n++) {
2497 int sample = bytestream2_get_byteu(&gb);
2498 *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 4, shift, control & 0x04);
2499 *samples++ = ff_adpcm_argo_expand_nibble(cs, sample >> 0, shift, control & 0x04);
2500 }
2501 }
2502 }
2503 ) /* End of CASE */
2504 CASE(ADPCM_ZORK,
2505 for (int n = 0; n < nb_samples * channels; n++) {
2506 int v = bytestream2_get_byteu(&gb);
2507 *samples++ = adpcm_zork_expand_nibble(&c->status[n % channels], v);
2508 }
2509 ) /* End of CASE */
2510 CASE(ADPCM_IMA_MTF,
2511 for (int n = nb_samples / 2; n > 0; n--) {
2512 for (int channel = 0; channel < channels; channel++) {
2513 int v = bytestream2_get_byteu(&gb);
2514 *samples++ = adpcm_ima_mtf_expand_nibble(&c->status[channel], v >> 4);
2515 samples[st] = adpcm_ima_mtf_expand_nibble(&c->status[channel], v & 0x0F);
2516 }
2517 samples += channels;
2518 }
2519 ) /* End of CASE */
2520 default:
2521 av_unreachable("There are cases for all codec ids using adpcm_decode_frame");
2522 }
2523
2524
2/4
✓ Branch 0 taken 37703 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 37703 times.
37703 if (avpkt->size && bytestream2_tell(&gb) == 0) {
2525 av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");
2526 return AVERROR_INVALIDDATA;
2527 }
2528
2529 37703 *got_frame_ptr = 1;
2530
2531
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37703 times.
37703 if (avpkt->size < bytestream2_tell(&gb)) {
2532 av_log(avctx, AV_LOG_ERROR, "Overread of %d < %d\n", avpkt->size, bytestream2_tell(&gb));
2533 return avpkt->size;
2534 }
2535
2536 37703 return bytestream2_tell(&gb);
2537 }
2538
2539 187 static void adpcm_flush(AVCodecContext *avctx)
2540 {
2541 187 ADPCMDecodeContext *c = avctx->priv_data;
2542
2543 /* Just nuke the entire state and re-init. */
2544 187 memset(c, 0, sizeof(ADPCMDecodeContext));
2545
2546
5/5
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 168 times.
187 switch(avctx->codec_id) {
2547 2 case AV_CODEC_ID_ADPCM_CT:
2548 2 c->status[0].step = c->status[1].step = 511;
2549 2 break;
2550
2551 3 case AV_CODEC_ID_ADPCM_IMA_APC:
2552
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
3 if (avctx->extradata && avctx->extradata_size >= 8) {
2553 2 c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata ), 18);
2554 2 c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18);
2555 }
2556 3 break;
2557
2558 6 case AV_CODEC_ID_ADPCM_IMA_APM:
2559
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (avctx->extradata && avctx->extradata_size >= 28) {
2560 6 c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 16), 18);
2561 6 c->status[0].step_index = av_clip(AV_RL32(avctx->extradata + 20), 0, 88);
2562 6 c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18);
2563 6 c->status[1].step_index = av_clip(AV_RL32(avctx->extradata + 8), 0, 88);
2564 }
2565 6 break;
2566
2567 8 case AV_CODEC_ID_ADPCM_IMA_WS:
2568
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
8 if (avctx->extradata && avctx->extradata_size >= 2)
2569 5 c->vqa_version = AV_RL16(avctx->extradata);
2570 8 break;
2571 168 default:
2572 /* Other codecs may want to handle this during decoding. */
2573 168 c->has_status = 0;
2574 168 return;
2575 }
2576
2577 19 c->has_status = 1;
2578 }
2579
2580
2581 static const enum AVSampleFormat sample_fmts_s16[] = { AV_SAMPLE_FMT_S16,
2582 AV_SAMPLE_FMT_NONE };
2583 static const enum AVSampleFormat sample_fmts_s16p[] = { AV_SAMPLE_FMT_S16P,
2584 AV_SAMPLE_FMT_NONE };
2585 static const enum AVSampleFormat sample_fmts_both[] = { AV_SAMPLE_FMT_S16,
2586 AV_SAMPLE_FMT_S16P,
2587 AV_SAMPLE_FMT_NONE };
2588
2589 #define ADPCM_DECODER_0(id_, sample_fmts_, name_, long_name_)
2590 #define ADPCM_DECODER_1(id_, sample_fmts_, name_, long_name_) \
2591 const FFCodec ff_ ## name_ ## _decoder = { \
2592 .p.name = #name_, \
2593 CODEC_LONG_NAME(long_name_), \
2594 .p.type = AVMEDIA_TYPE_AUDIO, \
2595 .p.id = id_, \
2596 .p.capabilities = AV_CODEC_CAP_DR1, \
2597 CODEC_SAMPLEFMTS_ARRAY(sample_fmts_), \
2598 .priv_data_size = sizeof(ADPCMDecodeContext), \
2599 .init = adpcm_decode_init, \
2600 FF_CODEC_DECODE_CB(adpcm_decode_frame), \
2601 .flush = adpcm_flush, \
2602 };
2603 #define ADPCM_DECODER_2(enabled, codec_id, name, sample_fmts, long_name) \
2604 ADPCM_DECODER_ ## enabled(codec_id, name, sample_fmts, long_name)
2605 #define ADPCM_DECODER_3(config, codec_id, name, sample_fmts, long_name) \
2606 ADPCM_DECODER_2(config, codec_id, name, sample_fmts, long_name)
2607 #define ADPCM_DECODER(codec, name, sample_fmts, long_name) \
2608 ADPCM_DECODER_3(CONFIG_ ## codec ## _DECODER, AV_CODEC_ID_ ## codec, \
2609 name, sample_fmts, long_name)
2610
2611 /* Note: Do not forget to add new entries to the Makefile as well. */
2612 ADPCM_DECODER(ADPCM_4XM, sample_fmts_s16p, adpcm_4xm, "ADPCM 4X Movie")
2613 ADPCM_DECODER(ADPCM_AFC, sample_fmts_s16p, adpcm_afc, "ADPCM Nintendo Gamecube AFC")
2614 ADPCM_DECODER(ADPCM_AGM, sample_fmts_s16, adpcm_agm, "ADPCM AmuseGraphics Movie")
2615 ADPCM_DECODER(ADPCM_AICA, sample_fmts_s16p, adpcm_aica, "ADPCM Yamaha AICA")
2616 ADPCM_DECODER(ADPCM_ARGO, sample_fmts_s16p, adpcm_argo, "ADPCM Argonaut Games")
2617 ADPCM_DECODER(ADPCM_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology")
2618 ADPCM_DECODER(ADPCM_DTK, sample_fmts_s16p, adpcm_dtk, "ADPCM Nintendo Gamecube DTK")
2619 ADPCM_DECODER(ADPCM_EA, sample_fmts_s16, adpcm_ea, "ADPCM Electronic Arts")
2620 ADPCM_DECODER(ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA")
2621 ADPCM_DECODER(ADPCM_EA_R1, sample_fmts_s16p, adpcm_ea_r1, "ADPCM Electronic Arts R1")
2622 ADPCM_DECODER(ADPCM_EA_R2, sample_fmts_s16p, adpcm_ea_r2, "ADPCM Electronic Arts R2")
2623 ADPCM_DECODER(ADPCM_EA_R3, sample_fmts_s16p, adpcm_ea_r3, "ADPCM Electronic Arts R3")
2624 ADPCM_DECODER(ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas, "ADPCM Electronic Arts XAS")
2625 ADPCM_DECODER(ADPCM_IMA_ACORN, sample_fmts_s16, adpcm_ima_acorn, "ADPCM IMA Acorn Replay")
2626 ADPCM_DECODER(ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv, "ADPCM IMA AMV")
2627 ADPCM_DECODER(ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc, "ADPCM IMA CRYO APC")
2628 ADPCM_DECODER(ADPCM_IMA_APM, sample_fmts_s16, adpcm_ima_apm, "ADPCM IMA Ubisoft APM")
2629 ADPCM_DECODER(ADPCM_IMA_CUNNING, sample_fmts_s16p, adpcm_ima_cunning, "ADPCM IMA Cunning Developments")
2630 ADPCM_DECODER(ADPCM_IMA_DAT4, sample_fmts_s16, adpcm_ima_dat4, "ADPCM IMA Eurocom DAT4")
2631 ADPCM_DECODER(ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3, "ADPCM IMA Duck DK3")
2632 ADPCM_DECODER(ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4, "ADPCM IMA Duck DK4")
2633 ADPCM_DECODER(ADPCM_IMA_EA_EACS, sample_fmts_s16, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS")
2634 ADPCM_DECODER(ADPCM_IMA_EA_SEAD, sample_fmts_s16, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD")
2635 ADPCM_DECODER(ADPCM_IMA_ISS, sample_fmts_s16, adpcm_ima_iss, "ADPCM IMA Funcom ISS")
2636 ADPCM_DECODER(ADPCM_IMA_MOFLEX, sample_fmts_s16p, adpcm_ima_moflex, "ADPCM IMA MobiClip MOFLEX")
2637 ADPCM_DECODER(ADPCM_IMA_MTF, sample_fmts_s16, adpcm_ima_mtf, "ADPCM IMA Capcom's MT Framework")
2638 ADPCM_DECODER(ADPCM_IMA_OKI, sample_fmts_s16, adpcm_ima_oki, "ADPCM IMA Dialogic OKI")
2639 ADPCM_DECODER(ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt, "ADPCM IMA QuickTime")
2640 ADPCM_DECODER(ADPCM_IMA_RAD, sample_fmts_s16, adpcm_ima_rad, "ADPCM IMA Radical")
2641 ADPCM_DECODER(ADPCM_IMA_SSI, sample_fmts_s16, adpcm_ima_ssi, "ADPCM IMA Simon & Schuster Interactive")
2642 ADPCM_DECODER(ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG")
2643 ADPCM_DECODER(ADPCM_IMA_ALP, sample_fmts_s16, adpcm_ima_alp, "ADPCM IMA High Voltage Software ALP")
2644 ADPCM_DECODER(ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV")
2645 ADPCM_DECODER(ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood")
2646 ADPCM_DECODER(ADPCM_IMA_XBOX, sample_fmts_s16p, adpcm_ima_xbox, "ADPCM IMA Xbox")
2647 ADPCM_DECODER(ADPCM_MS, sample_fmts_both, adpcm_ms, "ADPCM Microsoft")
2648 ADPCM_DECODER(ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF")
2649 ADPCM_DECODER(ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation")
2650 ADPCM_DECODER(ADPCM_SANYO, sample_fmts_s16p, adpcm_sanyo, "ADPCM Sanyo")
2651 ADPCM_DECODER(ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit")
2652 ADPCM_DECODER(ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit")
2653 ADPCM_DECODER(ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit")
2654 ADPCM_DECODER(ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Shockwave Flash")
2655 ADPCM_DECODER(ADPCM_THP_LE, sample_fmts_s16p, adpcm_thp_le, "ADPCM Nintendo THP (little-endian)")
2656 ADPCM_DECODER(ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo THP")
2657 ADPCM_DECODER(ADPCM_XA, sample_fmts_s16p, adpcm_xa, "ADPCM CDROM XA")
2658 ADPCM_DECODER(ADPCM_XMD, sample_fmts_s16p, adpcm_xmd, "ADPCM Konami XMD")
2659 ADPCM_DECODER(ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha")
2660 ADPCM_DECODER(ADPCM_ZORK, sample_fmts_s16, adpcm_zork, "ADPCM Zork")
2661