FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/wma.c
Date: 2024-07-16 12:46:59
Exec Total Coverage
Lines: 222 261 85.1%
Functions: 6 6 100.0%
Branches: 126 168 75.0%

Line Branch Exec Source
1 /*
2 * WMA compatible codec
3 * Copyright (c) 2002-2007 The FFmpeg Project
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "libavutil/attributes.h"
23 #include "libavutil/mem.h"
24
25 #include "avcodec.h"
26 #include "sinewin.h"
27 #include "wma.h"
28 #include "wma_common.h"
29 #include "wma_freqs.h"
30 #include "wmadata.h"
31
32 /* XXX: use same run/length optimization as mpeg decoders */
33 // FIXME maybe split decode / encode or pass flag
34 32 static av_cold int init_coef_vlc(VLC *vlc, uint16_t **prun_table,
35 float **plevel_table, uint16_t **pint_table,
36 const CoefVLCTable *vlc_table)
37 {
38 32 int n = vlc_table->n;
39 32 const uint8_t *table_bits = vlc_table->huffbits;
40 32 const uint32_t *table_codes = vlc_table->huffcodes;
41 32 const uint16_t *levels_table = vlc_table->levels;
42 uint16_t *run_table, *int_table;
43 float *flevel_table;
44 int i, l, j, k, level, ret;
45
46 32 ret = vlc_init(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0);
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
48 return ret;
49
50 32 run_table = av_malloc_array(n, sizeof(uint16_t));
51 32 flevel_table = av_malloc_array(n, sizeof(*flevel_table));
52 32 int_table = av_malloc_array(n, sizeof(uint16_t));
53
3/6
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 32 times.
32 if (!run_table || !flevel_table || !int_table) {
54 av_freep(&run_table);
55 av_freep(&flevel_table);
56 av_freep(&int_table);
57 return AVERROR(ENOMEM);
58 }
59 32 i = 2;
60 32 level = 1;
61 32 k = 0;
62
2/2
✓ Branch 0 taken 2580 times.
✓ Branch 1 taken 32 times.
2612 while (i < n) {
63 2580 int_table[k] = i;
64 2580 l = levels_table[k++];
65
2/2
✓ Branch 0 taken 17506 times.
✓ Branch 1 taken 2580 times.
20086 for (j = 0; j < l; j++) {
66 17506 run_table[i] = j;
67 17506 flevel_table[i] = level;
68 17506 i++;
69 }
70 2580 level++;
71 }
72 32 *prun_table = run_table;
73 32 *plevel_table = flevel_table;
74 32 *pint_table = int_table;
75
76 32 return 0;
77 }
78
79 16 av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
80 {
81 16 WMACodecContext *s = avctx->priv_data;
82 16 int channels = avctx->ch_layout.nb_channels;
83 int i, ret;
84 float bps1, high_freq;
85 float bps;
86 int sample_rate1;
87 int coef_vlc_table;
88
89
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
16 if (avctx->sample_rate <= 0 || avctx->sample_rate > 50000 ||
90
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 channels <= 0 || channels > 2 ||
91
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 avctx->bit_rate <= 0)
92 return -1;
93
94
95
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 13 times.
16 if (avctx->codec->id == AV_CODEC_ID_WMAV1)
96 3 s->version = 1;
97 else
98 13 s->version = 2;
99
100 /* compute MDCT block size */
101 16 s->frame_len_bits = ff_wma_get_frame_len_bits(avctx->sample_rate,
102 s->version, 0);
103 16 s->next_block_len_bits = s->frame_len_bits;
104 16 s->prev_block_len_bits = s->frame_len_bits;
105 16 s->block_len_bits = s->frame_len_bits;
106
107 16 s->frame_len = 1 << s->frame_len_bits;
108
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 9 times.
16 if (s->use_variable_block_len) {
109 int nb_max, nb;
110 7 nb = ((flags2 >> 3) & 3) + 1;
111
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
7 if ((avctx->bit_rate / channels) >= 32000)
112 4 nb += 2;
113 7 nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (nb > nb_max)
115 nb = nb_max;
116 7 s->nb_block_sizes = nb + 1;
117 } else
118 9 s->nb_block_sizes = 1;
119
120 /* init rate dependent parameters */
121 16 s->use_noise_coding = 1;
122 16 high_freq = avctx->sample_rate * 0.5;
123
124 /* if version 2, then the rates are normalized */
125 16 sample_rate1 = avctx->sample_rate;
126
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
16 if (s->version == 2) {
127
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 3 times.
13 if (sample_rate1 >= 44100)
128 10 sample_rate1 = 44100;
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 else if (sample_rate1 >= 22050)
130 sample_rate1 = 22050;
131
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 else if (sample_rate1 >= 16000)
132 1 sample_rate1 = 16000;
133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 else if (sample_rate1 >= 11025)
134 sample_rate1 = 11025;
135
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else if (sample_rate1 >= 8000)
136 2 sample_rate1 = 8000;
137 }
138
139 16 bps = (float) avctx->bit_rate /
140 16 (float) (channels * avctx->sample_rate);
141 16 s->byte_offset_bits = av_log2((int) (bps * s->frame_len / 8.0 + 0.5)) + 2;
142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (s->byte_offset_bits + 3 > MIN_CACHE_BITS) {
143 av_log(avctx, AV_LOG_ERROR, "byte_offset_bits %d is too large\n", s->byte_offset_bits);
144 return AVERROR_PATCHWELCOME;
145 }
146
147 /* compute high frequency value and choose if noise coding should
148 * be activated */
149 16 bps1 = bps;
150
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
16 if (channels == 2)
151 12 bps1 = bps * 1.6;
152
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
16 if (sample_rate1 == 44100) {
153
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if (bps1 >= 0.61)
154 13 s->use_noise_coding = 0;
155 else
156 high_freq = high_freq * 0.4;
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 } else if (sample_rate1 == 22050) {
158 if (bps1 >= 1.16)
159 s->use_noise_coding = 0;
160 else if (bps1 >= 0.72)
161 high_freq = high_freq * 0.7;
162 else
163 high_freq = high_freq * 0.6;
164
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 } else if (sample_rate1 == 16000) {
165
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (bps > 0.5)
166 1 high_freq = high_freq * 0.5;
167 else
168 high_freq = high_freq * 0.3;
169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (sample_rate1 == 11025)
170 high_freq = high_freq * 0.7;
171
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else if (sample_rate1 == 8000) {
172
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (bps <= 0.625)
173 1 high_freq = high_freq * 0.5;
174
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if (bps > 0.75)
175 1 s->use_noise_coding = 0;
176 else
177 high_freq = high_freq * 0.65;
178 } else {
179 if (bps >= 0.8)
180 high_freq = high_freq * 0.75;
181 else if (bps >= 0.6)
182 high_freq = high_freq * 0.6;
183 else
184 high_freq = high_freq * 0.5;
185 }
186 ff_dlog(s->avctx, "flags2=0x%x\n", flags2);
187 ff_dlog(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%"PRId64" block_align=%d\n",
188 s->version, channels, avctx->sample_rate, avctx->bit_rate,
189 avctx->block_align);
190 ff_dlog(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
191 bps, bps1, high_freq, s->byte_offset_bits);
192 ff_dlog(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
193 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
194
195 /* compute the scale factor band sizes for each MDCT block size */
196 {
197 int a, b, pos, lpos, k, block_len, i, j, n;
198 const uint8_t *table;
199
200
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 13 times.
16 if (s->version == 1)
201 3 s->coefs_start = 3;
202 else
203 13 s->coefs_start = 0;
204
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 16 times.
55 for (k = 0; k < s->nb_block_sizes; k++) {
205 39 block_len = s->frame_len >> k;
206
207
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 36 times.
39 if (s->version == 1) {
208 3 lpos = 0;
209
1/2
✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
75 for (i = 0; i < 25; i++) {
210 75 a = ff_wma_critical_freqs[i];
211 75 b = avctx->sample_rate;
212 75 pos = ((block_len * 2 * a) + (b >> 1)) / b;
213
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 72 times.
75 if (pos > block_len)
214 3 pos = block_len;
215 75 s->exponent_bands[0][i] = pos - lpos;
216
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 72 times.
75 if (pos >= block_len) {
217 3 i++;
218 3 break;
219 }
220 72 lpos = pos;
221 }
222 3 s->exponent_sizes[0] = i;
223 } else {
224 /* hardcoded tables */
225 36 table = NULL;
226 36 a = s->frame_len_bits - BLOCK_MIN_BITS - k;
227
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 15 times.
36 if (a < 3) {
228
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6 times.
21 if (avctx->sample_rate >= 44100)
229 15 table = exponent_band_44100[a];
230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 else if (avctx->sample_rate >= 32000)
231 table = exponent_band_32000[a];
232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 else if (avctx->sample_rate >= 22050)
233 table = exponent_band_22050[a];
234 }
235
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 21 times.
36 if (table) {
236 15 n = *table++;
237
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 15 times.
235 for (i = 0; i < n; i++)
238 220 s->exponent_bands[k][i] = table[i];
239 15 s->exponent_sizes[k] = n;
240 } else {
241 21 j = 0;
242 21 lpos = 0;
243
1/2
✓ Branch 0 taken 495 times.
✗ Branch 1 not taken.
495 for (i = 0; i < 25; i++) {
244 495 a = ff_wma_critical_freqs[i];
245 495 b = avctx->sample_rate;
246 495 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
247 495 pos <<= 2;
248
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 474 times.
495 if (pos > block_len)
249 21 pos = block_len;
250
2/2
✓ Branch 0 taken 489 times.
✓ Branch 1 taken 6 times.
495 if (pos > lpos)
251 489 s->exponent_bands[k][j++] = pos - lpos;
252
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 474 times.
495 if (pos >= block_len)
253 21 break;
254 474 lpos = pos;
255 }
256 21 s->exponent_sizes[k] = j;
257 }
258 }
259
260 /* max number of coefs */
261 39 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
262 /* high freq computation */
263 39 s->high_band_start[k] = (int) ((block_len * 2 * high_freq) /
264 39 avctx->sample_rate + 0.5);
265 39 n = s->exponent_sizes[k];
266 39 j = 0;
267 39 pos = 0;
268
2/2
✓ Branch 0 taken 784 times.
✓ Branch 1 taken 39 times.
823 for (i = 0; i < n; i++) {
269 int start, end;
270 784 start = pos;
271 784 pos += s->exponent_bands[k][i];
272 784 end = pos;
273
2/2
✓ Branch 0 taken 767 times.
✓ Branch 1 taken 17 times.
784 if (start < s->high_band_start[k])
274 767 start = s->high_band_start[k];
275
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 739 times.
784 if (end > s->coefs_end[k])
276 45 end = s->coefs_end[k];
277
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 768 times.
784 if (end > start)
278 16 s->exponent_high_bands[k][j++] = end - start;
279 }
280 39 s->exponent_high_sizes[k] = j;
281 }
282 }
283
284 #ifdef TRACE
285 {
286 int i, j;
287 for (i = 0; i < s->nb_block_sizes; i++) {
288 ff_tlog(s->avctx, "%5d: n=%2d:",
289 s->frame_len >> i,
290 s->exponent_sizes[i]);
291 for (j = 0; j < s->exponent_sizes[i]; j++)
292 ff_tlog(s->avctx, " %d", s->exponent_bands[i][j]);
293 ff_tlog(s->avctx, "\n");
294 }
295 }
296 #endif /* TRACE */
297
298 /* init MDCT windows : simple sine window */
299
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 16 times.
55 for (i = 0; i < s->nb_block_sizes; i++) {
300 39 ff_init_ff_sine_windows(s->frame_len_bits - i);
301 39 s->windows[i] = ff_sine_windows[s->frame_len_bits - i];
302 }
303
304 16 s->reset_block_lengths = 1;
305
306
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
16 if (s->use_noise_coding) {
307 /* init the noise generator */
308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->use_exp_vlc)
309 s->noise_mult = 0.02;
310 else
311 2 s->noise_mult = 0.04;
312
313 #ifdef TRACE
314 for (i = 0; i < NOISE_TAB_SIZE; i++)
315 s->noise_table[i] = 1.0 * s->noise_mult;
316 #else
317 {
318 unsigned int seed;
319 float norm;
320 2 seed = 1;
321 2 norm = (1.0 / (float) (1LL << 31)) * sqrt(3) * s->noise_mult;
322
2/2
✓ Branch 0 taken 16384 times.
✓ Branch 1 taken 2 times.
16386 for (i = 0; i < NOISE_TAB_SIZE; i++) {
323 16384 seed = seed * 314159 + 1;
324 16384 s->noise_table[i] = (float) ((int) seed) * norm;
325 }
326 }
327 #endif /* TRACE */
328 }
329
330 16 s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (!s->fdsp)
332 return AVERROR(ENOMEM);
333
334 /* choose the VLC tables for the coefficients */
335 16 coef_vlc_table = 2;
336
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
16 if (avctx->sample_rate >= 32000) {
337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (bps1 < 0.72)
338 coef_vlc_table = 0;
339
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11 times.
13 else if (bps1 < 1.16)
340 2 coef_vlc_table = 1;
341 }
342 16 s->coef_vlcs[0] = &coef_vlcs[coef_vlc_table * 2];
343 16 s->coef_vlcs[1] = &coef_vlcs[coef_vlc_table * 2 + 1];
344 16 ret = init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
345 &s->int_table[0], s->coef_vlcs[0]);
346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (ret < 0)
347 return ret;
348
349 16 return init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
350 &s->int_table[1], s->coef_vlcs[1]);
351 }
352
353 3650 int ff_wma_total_gain_to_bits(int total_gain)
354 {
355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3650 times.
3650 if (total_gain < 15)
356 return 13;
357
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 3552 times.
3650 else if (total_gain < 32)
358 98 return 12;
359
2/2
✓ Branch 0 taken 284 times.
✓ Branch 1 taken 3268 times.
3552 else if (total_gain < 40)
360 284 return 11;
361
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3250 times.
3268 else if (total_gain < 45)
362 18 return 10;
363 else
364 3250 return 9;
365 }
366
367 16 int ff_wma_end(AVCodecContext *avctx)
368 {
369 16 WMACodecContext *s = avctx->priv_data;
370 int i;
371
372
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 16 times.
55 for (i = 0; i < s->nb_block_sizes; i++)
373 39 av_tx_uninit(&s->mdct_ctx[i]);
374
375
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
16 if (s->use_exp_vlc)
376 13 ff_vlc_free(&s->exp_vlc);
377
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
16 if (s->use_noise_coding)
378 2 ff_vlc_free(&s->hgain_vlc);
379
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 16 times.
48 for (i = 0; i < 2; i++) {
380 32 ff_vlc_free(&s->coef_vlc[i]);
381 32 av_freep(&s->run_table[i]);
382 32 av_freep(&s->level_table[i]);
383 32 av_freep(&s->int_table[i]);
384 }
385 16 av_freep(&s->fdsp);
386
387 16 return 0;
388 }
389
390 /**
391 * Decode an uncompressed coefficient.
392 * @param gb GetBitContext
393 * @return the decoded coefficient
394 */
395 3915 unsigned int ff_wma_get_large_val(GetBitContext *gb)
396 {
397 /** consumes up to 34 bits */
398 3915 int n_bits = 8;
399 /** decode length */
400
2/2
✓ Branch 1 taken 530 times.
✓ Branch 2 taken 3385 times.
3915 if (get_bits1(gb)) {
401 530 n_bits += 8;
402
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 530 times.
530 if (get_bits1(gb)) {
403 n_bits += 8;
404 if (get_bits1(gb))
405 n_bits += 7;
406 }
407 }
408 3915 return get_bits_long(gb, n_bits);
409 }
410
411 /**
412 * Decode run level compressed coefficients.
413 * @param avctx codec context
414 * @param gb bitstream reader context
415 * @param vlc vlc table for get_vlc2
416 * @param level_table level codes
417 * @param run_table run codes
418 * @param version 0 for wma1,2 1 for wmapro
419 * @param ptr output buffer
420 * @param offset offset in the output buffer
421 * @param num_coefs number of input coefficients
422 * @param block_len input buffer length (2^n)
423 * @param frame_len_bits number of bits for escaped run codes
424 * @param coef_nb_bits number of bits for escaped level codes
425 * @return 0 on success, -1 otherwise
426 */
427 2174 int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
428 const VLCElem *vlc, const float *level_table,
429 const uint16_t *run_table, int version,
430 WMACoef *ptr, int offset, int num_coefs,
431 int block_len, int frame_len_bits,
432 int coef_nb_bits)
433 {
434 int code, level, sign;
435 2174 const uint32_t *ilvl = (const uint32_t *) level_table;
436 2174 uint32_t *iptr = (uint32_t *) ptr;
437 2174 const unsigned int coef_mask = block_len - 1;
438
2/2
✓ Branch 0 taken 592287 times.
✓ Branch 1 taken 12 times.
592299 for (; offset < num_coefs; offset++) {
439 592287 code = get_vlc2(gb, vlc, VLCBITS, VLCMAX);
440
2/2
✓ Branch 0 taken 586557 times.
✓ Branch 1 taken 5730 times.
592287 if (code > 1) {
441 /** normal code */
442 586557 offset += run_table[code];
443 586557 sign = get_bits1(gb) - 1;
444 586557 iptr[offset & coef_mask] = ilvl[code] ^ (sign & 0x80000000);
445
2/2
✓ Branch 0 taken 2162 times.
✓ Branch 1 taken 3568 times.
5730 } else if (code == 1) {
446 /** EOB */
447 2162 break;
448 } else {
449 /** escape */
450
2/2
✓ Branch 0 taken 2926 times.
✓ Branch 1 taken 642 times.
3568 if (!version) {
451 2926 level = get_bits(gb, coef_nb_bits);
452 /** NOTE: this is rather suboptimal. reading
453 * block_len_bits would be better */
454 2926 offset += get_bits(gb, frame_len_bits);
455 } else {
456 642 level = ff_wma_get_large_val(gb);
457 /** escape decode */
458
2/2
✓ Branch 1 taken 321 times.
✓ Branch 2 taken 321 times.
642 if (get_bits1(gb)) {
459
2/2
✓ Branch 1 taken 263 times.
✓ Branch 2 taken 58 times.
321 if (get_bits1(gb)) {
460
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 263 times.
263 if (get_bits1(gb)) {
461 av_log(avctx, AV_LOG_ERROR,
462 "broken escape sequence\n");
463 return AVERROR_INVALIDDATA;
464 } else
465 263 offset += get_bits(gb, frame_len_bits) + 4;
466 } else
467 58 offset += get_bits(gb, 2) + 1;
468 }
469 }
470 3568 sign = get_bits1(gb) - 1;
471 3568 ptr[offset & coef_mask] = (level ^ sign) - sign;
472 }
473 }
474 /** NOTE: EOB can be omitted */
475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2174 times.
2174 if (offset > num_coefs) {
476 av_log(avctx, AV_LOG_ERROR,
477 "overflow (%d > %d) in spectral RLE, ignoring\n",
478 offset,
479 num_coefs
480 );
481 return AVERROR_INVALIDDATA;
482 }
483
484 2174 return 0;
485 }
486