FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/wmalosslessdec.c
Date: 2022-11-28 23:49:43
Exec Total Coverage
Lines: 483 624 77.4%
Branches: 280 402 69.7%

Line Branch Exec Source
1 /*
2 * Windows Media Audio Lossless decoder
3 * Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
4 * Copyright (c) 2008 - 2011 Sascha Sommer, Benjamin Larsson
5 * Copyright (c) 2011 Andreas Ă–man
6 * Copyright (c) 2011 - 2012 Mashiat Sarker Shakkhar
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include <inttypes.h>
26
27 #include "libavutil/attributes.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/mem_internal.h"
30
31 #include "avcodec.h"
32 #include "codec_internal.h"
33 #include "decode.h"
34 #include "get_bits.h"
35 #include "put_bits.h"
36 #include "lossless_audiodsp.h"
37 #include "wma_common.h"
38
39 /** current decoder limitations */
40 #define WMALL_MAX_CHANNELS 8 ///< max number of handled channels
41 #define MAX_SUBFRAMES 32 ///< max number of subframes per channel
42 #define MAX_BANDS 29 ///< max number of scale factor bands
43 #define MAX_FRAMESIZE 32768 ///< maximum compressed frame size
44 #define MAX_ORDER 256
45
46 #define WMALL_BLOCK_MIN_BITS 6 ///< log2 of min block size
47 #define WMALL_BLOCK_MAX_BITS 14 ///< log2 of max block size
48 #define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) ///< maximum block size
49 #define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) ///< possible block sizes
50
51 #define WMALL_COEFF_PAD_SIZE 16 ///< pad coef buffers with 0 for use with SIMD
52
53 /**
54 * @brief frame-specific decoder context for a single channel
55 */
56 typedef struct WmallChannelCtx {
57 int16_t prev_block_len; ///< length of the previous block
58 uint8_t transmit_coefs;
59 uint8_t num_subframes;
60 uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples
61 uint16_t subframe_offsets[MAX_SUBFRAMES]; ///< subframe positions in the current frame
62 uint8_t cur_subframe; ///< current subframe number
63 uint16_t decoded_samples; ///< number of already processed samples
64 int quant_step; ///< quantization step for the current subframe
65 int transient_counter; ///< number of transient samples from the beginning of the transient zone
66 } WmallChannelCtx;
67
68 /**
69 * @brief main decoder context
70 */
71 typedef struct WmallDecodeCtx {
72 /* generic decoder variables */
73 AVCodecContext *avctx;
74 AVFrame *frame;
75 LLAudDSPContext dsp; ///< accelerated DSP functions
76 uint8_t *frame_data; ///< compressed frame data
77 int max_frame_size; ///< max bitstream size
78 PutBitContext pb; ///< context for filling the frame_data buffer
79
80 /* frame size dependent frame information (set during initialization) */
81 uint32_t decode_flags; ///< used compression features
82 int len_prefix; ///< frame is prefixed with its length
83 int dynamic_range_compression; ///< frame contains DRC data
84 uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
85 uint16_t samples_per_frame; ///< number of samples to output
86 uint16_t log2_frame_size;
87 int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels)
88 int8_t lfe_channel; ///< lfe channel index
89 uint8_t max_num_subframes;
90 uint8_t subframe_len_bits; ///< number of bits used for the subframe length
91 uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
92 uint16_t min_samples_per_subframe;
93
94 /* packet decode state */
95 GetBitContext pgb; ///< bitstream reader context for the packet
96 int next_packet_start; ///< start offset of the next WMA packet in the demuxer packet
97 uint8_t packet_offset; ///< offset to the frame in the packet
98 uint8_t packet_sequence_number; ///< current packet number
99 int num_saved_bits; ///< saved number of bits
100 int frame_offset; ///< frame offset in the bit reservoir
101 int subframe_offset; ///< subframe offset in the bit reservoir
102 uint8_t packet_loss; ///< set in case of bitstream error
103 uint8_t packet_done; ///< set when a packet is fully decoded
104
105 /* frame decode state */
106 uint32_t frame_num; ///< current frame number (not used for decoding)
107 GetBitContext gb; ///< bitstream reader context
108 int buf_bit_size; ///< buffer size in bits
109 int16_t *samples_16[WMALL_MAX_CHANNELS]; ///< current sample buffer pointer (16-bit)
110 int32_t *samples_32[WMALL_MAX_CHANNELS]; ///< current sample buffer pointer (24-bit)
111 uint8_t drc_gain; ///< gain for the DRC tool
112 int8_t skip_frame; ///< skip output step
113 int8_t parsed_all_subframes; ///< all subframes decoded?
114
115 /* subframe/block decode state */
116 int16_t subframe_len; ///< current subframe length
117 int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe
118 int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS];
119
120 WmallChannelCtx channel[WMALL_MAX_CHANNELS]; ///< per channel data
121
122 // WMA Lossless-specific
123
124 uint8_t do_arith_coding;
125 uint8_t do_ac_filter;
126 uint8_t do_inter_ch_decorr;
127 uint8_t do_mclms;
128 uint8_t do_lpc;
129
130 int8_t acfilter_order;
131 int8_t acfilter_scaling;
132 int16_t acfilter_coeffs[16];
133 int acfilter_prevvalues[WMALL_MAX_CHANNELS][16];
134
135 int8_t mclms_order;
136 int8_t mclms_scaling;
137 int16_t mclms_coeffs[WMALL_MAX_CHANNELS * WMALL_MAX_CHANNELS * 32];
138 int16_t mclms_coeffs_cur[WMALL_MAX_CHANNELS * WMALL_MAX_CHANNELS];
139 int32_t mclms_prevvalues[WMALL_MAX_CHANNELS * 2 * 32];
140 int32_t mclms_updates[WMALL_MAX_CHANNELS * 2 * 32];
141 int mclms_recent;
142
143 int movave_scaling;
144 int quant_stepsize;
145
146 struct {
147 int order;
148 int scaling;
149 int coefsend;
150 int bitsend;
151 DECLARE_ALIGNED(16, int16_t, coefs)[MAX_ORDER + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
152 DECLARE_ALIGNED(16, int32_t, lms_prevvalues)[MAX_ORDER * 2 + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
153 DECLARE_ALIGNED(16, int16_t, lms_updates)[MAX_ORDER * 2 + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
154 int recent;
155 } cdlms[WMALL_MAX_CHANNELS][9];
156
157 int cdlms_ttl[WMALL_MAX_CHANNELS];
158
159 int bV3RTM;
160
161 int is_channel_coded[WMALL_MAX_CHANNELS];
162 int update_speed[WMALL_MAX_CHANNELS];
163
164 int transient[WMALL_MAX_CHANNELS];
165 int transient_pos[WMALL_MAX_CHANNELS];
166 int seekable_tile;
167
168 unsigned ave_sum[WMALL_MAX_CHANNELS];
169
170 int channel_residues[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE];
171
172 int lpc_coefs[WMALL_MAX_CHANNELS][40];
173 int lpc_order;
174 int lpc_scaling;
175 int lpc_intbits;
176 } WmallDecodeCtx;
177
178 /** Get sign of integer (1 for positive, -1 for negative and 0 for zero) */
179 #define WMASIGN(x) (((x) > 0) - ((x) < 0))
180
181 8 static av_cold int decode_init(AVCodecContext *avctx)
182 {
183 8 WmallDecodeCtx *s = avctx->priv_data;
184 8 uint8_t *edata_ptr = avctx->extradata;
185 unsigned int channel_mask;
186 int i, log2_max_num_subframes;
187
188
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if (avctx->block_align <= 0 || avctx->block_align > (1<<21)) {
189 av_log(avctx, AV_LOG_ERROR, "block_align is not set or invalid\n");
190 return AVERROR(EINVAL);
191 }
192
193
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (avctx->extradata_size >= 18) {
194 8 s->decode_flags = AV_RL16(edata_ptr + 14);
195 8 channel_mask = AV_RL32(edata_ptr + 2);
196 8 s->bits_per_sample = AV_RL16(edata_ptr);
197
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (s->bits_per_sample == 16)
198 2 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
199
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 else if (s->bits_per_sample == 24) {
200 6 avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
201 6 avctx->bits_per_raw_sample = 24;
202 } else {
203 av_log(avctx, AV_LOG_ERROR, "Unknown bit-depth: %"PRIu8"\n",
204 s->bits_per_sample);
205 return AVERROR_INVALIDDATA;
206 }
207 /* dump the extradata */
208
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 8 times.
152 for (i = 0; i < avctx->extradata_size; i++)
209 ff_dlog(avctx, "[%x] ", avctx->extradata[i]);
210 ff_dlog(avctx, "\n");
211
212 } else {
213 avpriv_request_sample(avctx, "Unsupported extradata size");
214 return AVERROR_PATCHWELCOME;
215 }
216
217
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (channel_mask) {
218 8 av_channel_layout_uninit(&avctx->ch_layout);
219 8 av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
220 }
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 av_assert0(avctx->ch_layout.nb_channels >= 0);
222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (avctx->ch_layout.nb_channels > WMALL_MAX_CHANNELS) {
223 avpriv_request_sample(avctx,
224 "More than " AV_STRINGIFY(WMALL_MAX_CHANNELS) " channels");
225 return AVERROR_PATCHWELCOME;
226 }
227
228 8 s->num_channels = avctx->ch_layout.nb_channels;
229
230 /* extract lfe channel position */
231 8 s->lfe_channel = -1;
232
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (channel_mask & 8) {
234 unsigned int mask;
235 for (mask = 1; mask < 16; mask <<= 1)
236 if (channel_mask & mask)
237 ++s->lfe_channel;
238 }
239
240 8 s->max_frame_size = MAX_FRAMESIZE * avctx->ch_layout.nb_channels;
241 8 s->frame_data = av_mallocz(s->max_frame_size + AV_INPUT_BUFFER_PADDING_SIZE);
242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->frame_data)
243 return AVERROR(ENOMEM);
244
245 8 s->avctx = avctx;
246 8 ff_llauddsp_init(&s->dsp);
247 8 init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
248
249 /* generic init */
250 8 s->log2_frame_size = av_log2(avctx->block_align) + 4;
251
252 /* frame info */
253 8 s->skip_frame = 1; /* skip first frame */
254 8 s->packet_loss = 1;
255 8 s->len_prefix = s->decode_flags & 0x40;
256
257 /* get frame len */
258 8 s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
259 3, s->decode_flags);
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 av_assert0(s->samples_per_frame <= WMALL_BLOCK_MAX_SIZE);
261
262 /* init previous block len */
263
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 for (i = 0; i < avctx->ch_layout.nb_channels; i++)
264 16 s->channel[i].prev_block_len = s->samples_per_frame;
265
266 /* subframe info */
267 8 log2_max_num_subframes = (s->decode_flags & 0x38) >> 3;
268 8 s->max_num_subframes = 1 << log2_max_num_subframes;
269 8 s->max_subframe_len_bit = 0;
270 8 s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1;
271
272 8 s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes;
273 8 s->dynamic_range_compression = s->decode_flags & 0x80;
274 8 s->bV3RTM = s->decode_flags & 0x100;
275
276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (s->max_num_subframes > MAX_SUBFRAMES) {
277 av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %"PRIu8"\n",
278 s->max_num_subframes);
279 return AVERROR_INVALIDDATA;
280 }
281
282 8 s->frame = av_frame_alloc();
283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!s->frame)
284 return AVERROR(ENOMEM);
285
286 8 return 0;
287 }
288
289 /**
290 * @brief Decode the subframe length.
291 * @param s context
292 * @param offset sample offset in the frame
293 * @return decoded subframe length on success, < 0 in case of an error
294 */
295 269 static int decode_subframe_length(WmallDecodeCtx *s, int offset)
296 {
297 int frame_len_ratio, subframe_len, len;
298
299 /* no need to read from the bitstream when only one length is possible */
300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 if (offset == s->samples_per_frame - s->min_samples_per_subframe)
301 return s->min_samples_per_subframe;
302
303 269 len = av_log2(s->max_num_subframes - 1) + 1;
304 269 frame_len_ratio = get_bits(&s->gb, len);
305 269 subframe_len = s->min_samples_per_subframe * (frame_len_ratio + 1);
306
307 /* sanity check the length */
308
1/2
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
269 if (subframe_len < s->min_samples_per_subframe ||
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 subframe_len > s->samples_per_frame) {
310 av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n",
311 subframe_len);
312 return AVERROR_INVALIDDATA;
313 }
314 269 return subframe_len;
315 }
316
317 /**
318 * @brief Decode how the data in the frame is split into subframes.
319 * Every WMA frame contains the encoded data for a fixed number of
320 * samples per channel. The data for every channel might be split
321 * into several subframes. This function will reconstruct the list of
322 * subframes for every channel.
323 *
324 * If the subframes are not evenly split, the algorithm estimates the
325 * channels with the lowest number of total samples.
326 * Afterwards, for each of these channels a bit is read from the
327 * bitstream that indicates if the channel contains a subframe with the
328 * next subframe size that is going to be read from the bitstream or not.
329 * If a channel contains such a subframe, the subframe size gets added to
330 * the channel's subframe list.
331 * The algorithm repeats these steps until the frame is properly divided
332 * between the individual channels.
333 *
334 * @param s context
335 * @return 0 on success, < 0 in case of an error
336 */
337 269 static int decode_tilehdr(WmallDecodeCtx *s)
338 {
339 269 uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; /* sum of samples for all currently known subframes of a channel */
340 uint8_t contains_subframe[WMALL_MAX_CHANNELS]; /* flag indicating if a channel contains the current subframe */
341 269 int channels_for_cur_subframe = s->num_channels; /* number of channels that contain the current subframe */
342 269 int fixed_channel_layout = 0; /* flag indicating that all channels use the same subfra2me offsets and sizes */
343 269 int min_channel_len = 0; /* smallest sum of samples (channels with this length will be processed first) */
344 int c, tile_aligned;
345
346 /* reset tiling information */
347
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (c = 0; c < s->num_channels; c++)
348 538 s->channel[c].num_subframes = 0;
349
350 269 tile_aligned = get_bits1(&s->gb);
351
2/4
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 269 times.
269 if (s->max_num_subframes == 1 || tile_aligned)
352 fixed_channel_layout = 1;
353
354 /* loop until the frame data is split between the subframes */
355 do {
356 269 int subframe_len, in_use = 0;
357
358 /* check which channels contain the subframe */
359
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (c = 0; c < s->num_channels; c++) {
360
1/2
✓ Branch 0 taken 538 times.
✗ Branch 1 not taken.
538 if (num_samples[c] == min_channel_len) {
361
2/4
✓ Branch 0 taken 538 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 538 times.
✗ Branch 3 not taken.
538 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
538 (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) {
363 contains_subframe[c] = 1;
364 } else {
365 538 contains_subframe[c] = get_bits1(&s->gb);
366 }
367 538 in_use |= contains_subframe[c];
368 } else
369 contains_subframe[c] = 0;
370 }
371
372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 if (!in_use) {
373 av_log(s->avctx, AV_LOG_ERROR,
374 "Found empty subframe\n");
375 return AVERROR_INVALIDDATA;
376 }
377
378 /* get subframe length, subframe_len == 0 is not allowed */
379
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
269 if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
380 return AVERROR_INVALIDDATA;
381 /* add subframes to the individual channels and find new min_channel_len */
382 269 min_channel_len += subframe_len;
383
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (c = 0; c < s->num_channels; c++) {
384 538 WmallChannelCtx *chan = &s->channel[c];
385
386
1/2
✓ Branch 0 taken 538 times.
✗ Branch 1 not taken.
538 if (contains_subframe[c]) {
387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
538 if (chan->num_subframes >= MAX_SUBFRAMES) {
388 av_log(s->avctx, AV_LOG_ERROR,
389 "broken frame: num subframes > 31\n");
390 return AVERROR_INVALIDDATA;
391 }
392 538 chan->subframe_len[chan->num_subframes] = subframe_len;
393 538 num_samples[c] += subframe_len;
394 538 ++chan->num_subframes;
395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
538 if (num_samples[c] > s->samples_per_frame) {
396 av_log(s->avctx, AV_LOG_ERROR, "broken frame: "
397 "channel len(%"PRIu16") > samples_per_frame(%"PRIu16")\n",
398 num_samples[c], s->samples_per_frame);
399 return AVERROR_INVALIDDATA;
400 }
401 } else if (num_samples[c] <= min_channel_len) {
402 if (num_samples[c] < min_channel_len) {
403 channels_for_cur_subframe = 0;
404 min_channel_len = num_samples[c];
405 }
406 ++channels_for_cur_subframe;
407 }
408 }
409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 } while (min_channel_len < s->samples_per_frame);
410
411
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (c = 0; c < s->num_channels; c++) {
412 538 int i, offset = 0;
413
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 538 times.
1076 for (i = 0; i < s->channel[c].num_subframes; i++) {
414 538 s->channel[c].subframe_offsets[i] = offset;
415 538 offset += s->channel[c].subframe_len[i];
416 }
417 }
418
419 269 return 0;
420 }
421
422 26 static void decode_ac_filter(WmallDecodeCtx *s)
423 {
424 int i;
425 26 s->acfilter_order = get_bits(&s->gb, 4) + 1;
426 26 s->acfilter_scaling = get_bits(&s->gb, 4);
427
428
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 26 times.
52 for (i = 0; i < s->acfilter_order; i++)
429 26 s->acfilter_coeffs[i] = get_bitsz(&s->gb, s->acfilter_scaling) + 1;
430 26 }
431
432 23 static void decode_mclms(WmallDecodeCtx *s)
433 {
434 23 s->mclms_order = (get_bits(&s->gb, 4) + 1) * 2;
435 23 s->mclms_scaling = get_bits(&s->gb, 4);
436
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
23 if (get_bits1(&s->gb)) {
437 int i, send_coef_bits;
438 int cbits = av_log2(s->mclms_scaling + 1);
439 if (1 << cbits < s->mclms_scaling + 1)
440 cbits++;
441
442 send_coef_bits = get_bitsz(&s->gb, cbits) + 2;
443
444 for (i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++)
445 s->mclms_coeffs[i] = get_bits(&s->gb, send_coef_bits);
446
447 for (i = 0; i < s->num_channels; i++) {
448 int c;
449 for (c = 0; c < i; c++)
450 s->mclms_coeffs_cur[i * s->num_channels + c] = get_bits(&s->gb, send_coef_bits);
451 }
452 }
453 23 }
454
455 26 static int decode_cdlms(WmallDecodeCtx *s)
456 {
457 int c, i;
458 26 int cdlms_send_coef = get_bits1(&s->gb);
459
460
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 26 times.
78 for (c = 0; c < s->num_channels; c++) {
461 52 s->cdlms_ttl[c] = get_bits(&s->gb, 3) + 1;
462
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 52 times.
150 for (i = 0; i < s->cdlms_ttl[c]; i++) {
463 98 s->cdlms[c][i].order = (get_bits(&s->gb, 7) + 1) * 8;
464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98 times.
98 if (s->cdlms[c][i].order > MAX_ORDER) {
465 av_log(s->avctx, AV_LOG_ERROR,
466 "Order[%d][%d] %d > max (%d), not supported\n",
467 c, i, s->cdlms[c][i].order, MAX_ORDER);
468 s->cdlms[0][0].order = 0;
469 return AVERROR_INVALIDDATA;
470 }
471
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
98 if(s->cdlms[c][i].order & 8 && s->bits_per_sample == 16) {
472 static int warned;
473 if(!warned)
474 avpriv_request_sample(s->avctx, "CDLMS of order %d",
475 s->cdlms[c][i].order);
476 warned = 1;
477 }
478 }
479
480
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 52 times.
150 for (i = 0; i < s->cdlms_ttl[c]; i++)
481 98 s->cdlms[c][i].scaling = get_bits(&s->gb, 4);
482
483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
52 if (cdlms_send_coef) {
484 for (i = 0; i < s->cdlms_ttl[c]; i++) {
485 int cbits, shift_l, shift_r, j;
486 cbits = av_log2(s->cdlms[c][i].order);
487 if ((1 << cbits) < s->cdlms[c][i].order)
488 cbits++;
489 s->cdlms[c][i].coefsend = get_bits(&s->gb, cbits) + 1;
490
491 cbits = av_log2(s->cdlms[c][i].scaling + 1);
492 if ((1 << cbits) < s->cdlms[c][i].scaling + 1)
493 cbits++;
494
495 s->cdlms[c][i].bitsend = get_bitsz(&s->gb, cbits) + 2;
496 shift_l = 32 - s->cdlms[c][i].bitsend;
497 shift_r = 32 - s->cdlms[c][i].scaling - 2;
498 for (j = 0; j < s->cdlms[c][i].coefsend; j++)
499 s->cdlms[c][i].coefs[j] =
500 (get_bits(&s->gb, s->cdlms[c][i].bitsend) << shift_l) >> shift_r;
501 }
502 }
503
504
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 52 times.
150 for (i = 0; i < s->cdlms_ttl[c]; i++)
505 98 memset(s->cdlms[c][i].coefs + s->cdlms[c][i].order,
506 0, WMALL_COEFF_PAD_SIZE);
507 }
508
509 26 return 0;
510 }
511
512 504 static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
513 {
514 504 int i = 0;
515 unsigned int ave_mean;
516 504 s->transient[ch] = get_bits1(&s->gb);
517
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 503 times.
504 if (s->transient[ch]) {
518 1 s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));
519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (s->transient_pos[ch])
520 1 s->transient[ch] = 0;
521 1 s->channel[ch].transient_counter =
522 1 FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2);
523
1/2
✓ Branch 0 taken 503 times.
✗ Branch 1 not taken.
503 } else if (s->channel[ch].transient_counter)
524 503 s->transient[ch] = 1;
525
526
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 453 times.
504 if (s->seekable_tile) {
527 51 ave_mean = get_bits(&s->gb, s->bits_per_sample);
528 51 s->ave_sum[ch] = ave_mean << (s->movave_scaling + 1);
529 }
530
531
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 453 times.
504 if (s->seekable_tile) {
532
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if (s->do_inter_ch_decorr)
533 51 s->channel_residues[ch][0] = get_sbits_long(&s->gb, s->bits_per_sample + 1);
534 else
535 s->channel_residues[ch][0] = get_sbits_long(&s->gb, s->bits_per_sample);
536 51 i++;
537 }
538
2/2
✓ Branch 0 taken 1031564 times.
✓ Branch 1 taken 503 times.
1032067 for (; i < tile_size; i++) {
539 int rem, rem_bits;
540 1031564 unsigned quo = 0, residue;
541
2/2
✓ Branch 1 taken 1000907 times.
✓ Branch 2 taken 1031563 times.
2032470 while(get_bits1(&s->gb)) {
542 1000907 quo++;
543
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1000906 times.
1000907 if (get_bits_left(&s->gb) <= 0)
544 1 return -1;
545 }
546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1031563 times.
1031563 if (quo >= 32)
547 quo += get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1);
548
549 1031563 ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);
550
2/2
✓ Branch 0 taken 52125 times.
✓ Branch 1 taken 979438 times.
1031563 if (ave_mean <= 1)
551 52125 residue = quo;
552 else {
553 979438 rem_bits = av_ceil_log2(ave_mean);
554 979438 rem = get_bits_long(&s->gb, rem_bits);
555 979438 residue = (quo << rem_bits) + rem;
556 }
557
558 1031563 s->ave_sum[ch] = residue + s->ave_sum[ch] -
559 1031563 (s->ave_sum[ch] >> s->movave_scaling);
560
561 1031563 residue = (residue >> 1) ^ -(residue & 1);
562 1031563 s->channel_residues[ch][i] = residue;
563 }
564
565 503 return 0;
566
567 }
568
569 static void decode_lpc(WmallDecodeCtx *s)
570 {
571 int ch, i, cbits;
572 s->lpc_order = get_bits(&s->gb, 5) + 1;
573 s->lpc_scaling = get_bits(&s->gb, 4);
574 s->lpc_intbits = get_bits(&s->gb, 3) + 1;
575 cbits = s->lpc_scaling + s->lpc_intbits;
576 for (ch = 0; ch < s->num_channels; ch++)
577 for (i = 0; i < s->lpc_order; i++)
578 s->lpc_coefs[ch][i] = get_sbits(&s->gb, cbits);
579 }
580
581 26 static void clear_codec_buffers(WmallDecodeCtx *s)
582 {
583 int ich, ilms;
584
585 26 memset(s->acfilter_coeffs, 0, sizeof(s->acfilter_coeffs));
586 26 memset(s->acfilter_prevvalues, 0, sizeof(s->acfilter_prevvalues));
587 26 memset(s->lpc_coefs, 0, sizeof(s->lpc_coefs));
588
589 26 memset(s->mclms_coeffs, 0, sizeof(s->mclms_coeffs));
590 26 memset(s->mclms_coeffs_cur, 0, sizeof(s->mclms_coeffs_cur));
591 26 memset(s->mclms_prevvalues, 0, sizeof(s->mclms_prevvalues));
592 26 memset(s->mclms_updates, 0, sizeof(s->mclms_updates));
593
594
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 26 times.
78 for (ich = 0; ich < s->num_channels; ich++) {
595
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 52 times.
140 for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) {
596 88 memset(s->cdlms[ich][ilms].coefs, 0,
597 sizeof(s->cdlms[ich][ilms].coefs));
598 88 memset(s->cdlms[ich][ilms].lms_prevvalues, 0,
599 sizeof(s->cdlms[ich][ilms].lms_prevvalues));
600 88 memset(s->cdlms[ich][ilms].lms_updates, 0,
601 sizeof(s->cdlms[ich][ilms].lms_updates));
602 }
603 52 s->ave_sum[ich] = 0;
604 }
605 26 }
606
607 /**
608 * @brief Reset filter parameters and transient area at new seekable tile.
609 */
610 26 static void reset_codec(WmallDecodeCtx *s)
611 {
612 int ich, ilms;
613 26 s->mclms_recent = s->mclms_order * s->num_channels;
614
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 26 times.
78 for (ich = 0; ich < s->num_channels; ich++) {
615
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 52 times.
150 for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++)
616 98 s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order;
617 /* first sample of a seekable subframe is considered as the starting of
618 a transient area which is samples_per_frame samples long */
619 52 s->channel[ich].transient_counter = s->samples_per_frame;
620 52 s->transient[ich] = 1;
621 52 s->transient_pos[ich] = 0;
622 }
623 26 }
624
625 448512 static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
626 {
627 int i, j, ich, pred_error;
628 448512 int order = s->mclms_order;
629 448512 int num_channels = s->num_channels;
630 448512 int range = 1 << (s->bits_per_sample - 1);
631
632
2/2
✓ Branch 0 taken 897024 times.
✓ Branch 1 taken 448512 times.
1345536 for (ich = 0; ich < num_channels; ich++) {
633 897024 pred_error = s->channel_residues[ich][icoef] - (unsigned)pred[ich];
634
2/2
✓ Branch 0 taken 449621 times.
✓ Branch 1 taken 447403 times.
897024 if (pred_error > 0) {
635
2/2
✓ Branch 0 taken 1798484 times.
✓ Branch 1 taken 449621 times.
2248105 for (i = 0; i < order * num_channels; i++)
636 1798484 s->mclms_coeffs[i + ich * order * num_channels] +=
637 1798484 s->mclms_updates[s->mclms_recent + i];
638
2/2
✓ Branch 0 taken 223215 times.
✓ Branch 1 taken 449621 times.
672836 for (j = 0; j < ich; j++)
639 223215 s->mclms_coeffs_cur[ich * num_channels + j] += WMASIGN(s->channel_residues[j][icoef]);
640
2/2
✓ Branch 0 taken 443941 times.
✓ Branch 1 taken 3462 times.
447403 } else if (pred_error < 0) {
641
2/2
✓ Branch 0 taken 1775764 times.
✓ Branch 1 taken 443941 times.
2219705 for (i = 0; i < order * num_channels; i++)
642 1775764 s->mclms_coeffs[i + ich * order * num_channels] -=
643 1775764 s->mclms_updates[s->mclms_recent + i];
644
2/2
✓ Branch 0 taken 223308 times.
✓ Branch 1 taken 443941 times.
667249 for (j = 0; j < ich; j++)
645 223308 s->mclms_coeffs_cur[ich * num_channels + j] -= WMASIGN(s->channel_residues[j][icoef]);
646 }
647 }
648
649
2/2
✓ Branch 0 taken 897024 times.
✓ Branch 1 taken 448512 times.
1345536 for (ich = num_channels - 1; ich >= 0; ich--) {
650 897024 s->mclms_recent--;
651 897024 s->mclms_prevvalues[s->mclms_recent] = av_clip(s->channel_residues[ich][icoef],
652 -range, range - 1);
653 897024 s->mclms_updates[s->mclms_recent] = WMASIGN(s->channel_residues[ich][icoef]);
654 }
655
656
2/2
✓ Branch 0 taken 224256 times.
✓ Branch 1 taken 224256 times.
448512 if (s->mclms_recent == 0) {
657 224256 memcpy(&s->mclms_prevvalues[order * num_channels],
658 224256 s->mclms_prevvalues,
659 224256 sizeof(int32_t) * order * num_channels);
660 224256 memcpy(&s->mclms_updates[order * num_channels],
661 224256 s->mclms_updates,
662 224256 sizeof(int32_t) * order * num_channels);
663 224256 s->mclms_recent = num_channels * order;
664 }
665 448512 }
666
667 448512 static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
668 {
669 int ich, i;
670 448512 int order = s->mclms_order;
671 448512 int num_channels = s->num_channels;
672
673
2/2
✓ Branch 0 taken 897024 times.
✓ Branch 1 taken 448512 times.
1345536 for (ich = 0; ich < num_channels; ich++) {
674 897024 pred[ich] = 0;
675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 897024 times.
897024 if (!s->is_channel_coded[ich])
676 continue;
677
2/2
✓ Branch 0 taken 3588096 times.
✓ Branch 1 taken 897024 times.
4485120 for (i = 0; i < order * num_channels; i++)
678 3588096 pred[ich] += (uint32_t)s->mclms_prevvalues[i + s->mclms_recent] *
679 3588096 s->mclms_coeffs[i + order * num_channels * ich];
680
2/2
✓ Branch 0 taken 448512 times.
✓ Branch 1 taken 897024 times.
1345536 for (i = 0; i < ich; i++)
681 448512 pred[ich] += (uint32_t)s->channel_residues[i][icoef] *
682 448512 s->mclms_coeffs_cur[i + num_channels * ich];
683 897024 pred[ich] += (1U << s->mclms_scaling) >> 1;
684 897024 pred[ich] >>= s->mclms_scaling;
685 897024 s->channel_residues[ich][icoef] += (unsigned)pred[ich];
686 }
687 448512 }
688
689 219 static void revert_mclms(WmallDecodeCtx *s, int tile_size)
690 {
691 219 int icoef, pred[WMALL_MAX_CHANNELS] = { 0 };
692
2/2
✓ Branch 0 taken 448512 times.
✓ Branch 1 taken 219 times.
448731 for (icoef = 0; icoef < tile_size; icoef++) {
693 448512 mclms_predict(s, icoef, pred);
694 448512 mclms_update(s, icoef, pred);
695 }
696 219 }
697
698 51 static void use_high_update_speed(WmallDecodeCtx *s, int ich)
699 {
700 int ilms, recent, icoef;
701
2/2
✓ Branch 0 taken 97 times.
✓ Branch 1 taken 51 times.
148 for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
702 97 recent = s->cdlms[ich][ilms].recent;
703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 97 times.
97 if (s->update_speed[ich] == 16)
704 continue;
705
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 88 times.
97 if (s->bV3RTM) {
706
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 9 times.
97 for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
707 88 s->cdlms[ich][ilms].lms_updates[icoef + recent] *= 2;
708 } else {
709
2/2
✓ Branch 0 taken 3520 times.
✓ Branch 1 taken 88 times.
3608 for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
710 3520 s->cdlms[ich][ilms].lms_updates[icoef] *= 2;
711 }
712 }
713 51 s->update_speed[ich] = 16;
714 51 }
715
716 453 static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
717 {
718 int ilms, recent, icoef;
719
2/2
✓ Branch 0 taken 845 times.
✓ Branch 1 taken 453 times.
1298 for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
720 845 recent = s->cdlms[ich][ilms].recent;
721
2/2
✓ Branch 0 taken 747 times.
✓ Branch 1 taken 98 times.
845 if (s->update_speed[ich] == 8)
722 747 continue;
723
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 88 times.
98 if (s->bV3RTM)
724
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 10 times.
106 for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
725 96 s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2;
726 else
727
2/2
✓ Branch 0 taken 3520 times.
✓ Branch 1 taken 88 times.
3608 for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
728 3520 s->cdlms[ich][ilms].lms_updates[icoef] /= 2;
729 }
730 453 s->update_speed[ich] = 8;
731 453 }
732
733 #define CD_LMS(bits, ROUND) \
734 static void lms_update ## bits (WmallDecodeCtx *s, int ich, int ilms, int input) \
735 { \
736 int recent = s->cdlms[ich][ilms].recent; \
737 int range = 1 << s->bits_per_sample - 1; \
738 int order = s->cdlms[ich][ilms].order; \
739 int ##bits##_t *prev = (int##bits##_t *)s->cdlms[ich][ilms].lms_prevvalues; \
740 \
741 if (recent) \
742 recent--; \
743 else { \
744 memcpy(prev + order, prev, (bits/8) * order); \
745 memcpy(s->cdlms[ich][ilms].lms_updates + order, \
746 s->cdlms[ich][ilms].lms_updates, \
747 sizeof(*s->cdlms[ich][ilms].lms_updates) * order); \
748 recent = order - 1; \
749 } \
750 \
751 prev[recent] = av_clip(input, -range, range - 1); \
752 s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich]; \
753 \
754 s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2; \
755 s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1; \
756 s->cdlms[ich][ilms].recent = recent; \
757 memset(s->cdlms[ich][ilms].lms_updates + recent + order, 0, \
758 sizeof(s->cdlms[ich][ilms].lms_updates) - \
759 sizeof(*s->cdlms[ich][ilms].lms_updates)*(recent+order)); \
760 } \
761 \
762 static void revert_cdlms ## bits (WmallDecodeCtx *s, int ch, \
763 int coef_begin, int coef_end) \
764 { \
765 int icoef, ilms, num_lms, residue, input; \
766 unsigned pred;\
767 \
768 num_lms = s->cdlms_ttl[ch]; \
769 for (ilms = num_lms - 1; ilms >= 0; ilms--) { \
770 for (icoef = coef_begin; icoef < coef_end; icoef++) { \
771 int##bits##_t *prevvalues = (int##bits##_t *)s->cdlms[ch][ilms].lms_prevvalues; \
772 pred = (1 << s->cdlms[ch][ilms].scaling) >> 1; \
773 residue = s->channel_residues[ch][icoef]; \
774 pred += s->dsp.scalarproduct_and_madd_int## bits (s->cdlms[ch][ilms].coefs, \
775 prevvalues + s->cdlms[ch][ilms].recent, \
776 s->cdlms[ch][ilms].lms_updates + \
777 s->cdlms[ch][ilms].recent, \
778 FFALIGN(s->cdlms[ch][ilms].order, ROUND), \
779 WMASIGN(residue)); \
780 input = residue + (unsigned)((int)pred >> s->cdlms[ch][ilms].scaling); \
781 lms_update ## bits(s, ch, ilms, input); \
782 s->channel_residues[ch][icoef] = input; \
783 } \
784 } \
785 }
786
787
6/6
✓ Branch 0 taken 1653208 times.
✓ Branch 1 taken 67112 times.
✓ Branch 2 taken 1720320 times.
✓ Branch 3 taken 840 times.
✓ Branch 4 taken 840 times.
✓ Branch 5 taken 420 times.
6883800 CD_LMS(16, WMALL_COEFF_PAD_SIZE)
788
6/6
✓ Branch 0 taken 185098 times.
✓ Branch 1 taken 23798 times.
✓ Branch 2 taken 208896 times.
✓ Branch 3 taken 102 times.
✓ Branch 4 taken 102 times.
✓ Branch 5 taken 84 times.
417978 CD_LMS(32, 8)
789
790 264 static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
791 {
792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if (s->num_channels != 2)
793 return;
794
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
264 else if (s->is_channel_coded[0] || s->is_channel_coded[1]) {
795 int icoef;
796
2/2
✓ Branch 0 taken 540672 times.
✓ Branch 1 taken 264 times.
540936 for (icoef = 0; icoef < tile_size; icoef++) {
797 540672 s->channel_residues[0][icoef] -= (unsigned)(s->channel_residues[1][icoef] >> 1);
798 540672 s->channel_residues[1][icoef] += (unsigned) s->channel_residues[0][icoef];
799 }
800 }
801 }
802
803 264 static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
804 {
805 int ich, pred, i, j;
806 264 int16_t *filter_coeffs = s->acfilter_coeffs;
807 264 int scaling = s->acfilter_scaling;
808 264 int order = s->acfilter_order;
809
810
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 264 times.
792 for (ich = 0; ich < s->num_channels; ich++) {
811 528 int *prevvalues = s->acfilter_prevvalues[ich];
812
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 528 times.
1056 for (i = 0; i < order; i++) {
813 528 pred = 0;
814
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 528 times.
1056 for (j = 0; j < order; j++) {
815
1/2
✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
528 if (i <= j)
816 528 pred += (uint32_t)filter_coeffs[j] * prevvalues[j - i];
817 else
818 pred += (uint32_t)s->channel_residues[ich][i - j - 1] * filter_coeffs[j];
819 }
820 528 pred >>= scaling;
821 528 s->channel_residues[ich][i] += (unsigned)pred;
822 }
823
2/2
✓ Branch 0 taken 1080816 times.
✓ Branch 1 taken 528 times.
1081344 for (i = order; i < tile_size; i++) {
824 1080816 pred = 0;
825
2/2
✓ Branch 0 taken 1080816 times.
✓ Branch 1 taken 1080816 times.
2161632 for (j = 0; j < order; j++)
826 1080816 pred += (uint32_t)s->channel_residues[ich][i - j - 1] * filter_coeffs[j];
827 1080816 pred >>= scaling;
828 1080816 s->channel_residues[ich][i] += (unsigned)pred;
829 }
830
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 528 times.
1056 for (j = order - 1; j >= 0; j--)
831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
528 if (tile_size <= j) {
832 prevvalues[j] = prevvalues[j - tile_size];
833 }else
834 528 prevvalues[j] = s->channel_residues[ich][tile_size - j - 1];
835 }
836 264 }
837
838 269 static int decode_subframe(WmallDecodeCtx *s)
839 {
840 269 int offset = s->samples_per_frame;
841 269 int subframe_len = s->samples_per_frame;
842 269 int total_samples = s->samples_per_frame * s->num_channels;
843 int i, j, rawpcm_tile, padding_zeroes, res;
844
845 269 s->subframe_offset = get_bits_count(&s->gb);
846
847 /* reset channel context and find the next block offset and size
848 == the next block of the channel with the smallest number of
849 decoded samples */
850
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (i = 0; i < s->num_channels; i++) {
851
2/2
✓ Branch 0 taken 269 times.
✓ Branch 1 taken 269 times.
538 if (offset > s->channel[i].decoded_samples) {
852 269 offset = s->channel[i].decoded_samples;
853 269 subframe_len =
854 269 s->channel[i].subframe_len[s->channel[i].cur_subframe];
855 }
856 }
857
858 /* get a list of all channels that contain the estimated block */
859 269 s->channels_for_cur_subframe = 0;
860
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (i = 0; i < s->num_channels; i++) {
861 538 const int cur_subframe = s->channel[i].cur_subframe;
862 /* subtract already processed samples */
863 538 total_samples -= s->channel[i].decoded_samples;
864
865 /* and count if there are multiple subframes that match our profile */
866
1/2
✓ Branch 0 taken 538 times.
✗ Branch 1 not taken.
538 if (offset == s->channel[i].decoded_samples &&
867
1/2
✓ Branch 0 taken 538 times.
✗ Branch 1 not taken.
538 subframe_len == s->channel[i].subframe_len[cur_subframe]) {
868 538 total_samples -= s->channel[i].subframe_len[cur_subframe];
869 538 s->channel[i].decoded_samples +=
870 538 s->channel[i].subframe_len[cur_subframe];
871 538 s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i;
872 538 ++s->channels_for_cur_subframe;
873 }
874 }
875
876 /* check if the frame will be complete after processing the
877 estimated block */
878
1/2
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
269 if (!total_samples)
879 269 s->parsed_all_subframes = 1;
880
881
882 269 s->seekable_tile = get_bits1(&s->gb);
883
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 243 times.
269 if (s->seekable_tile) {
884 26 clear_codec_buffers(s);
885
886 26 s->do_arith_coding = get_bits1(&s->gb);
887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (s->do_arith_coding) {
888 avpriv_request_sample(s->avctx, "Arithmetic coding");
889 return AVERROR_PATCHWELCOME;
890 }
891 26 s->do_ac_filter = get_bits1(&s->gb);
892 26 s->do_inter_ch_decorr = get_bits1(&s->gb);
893 26 s->do_mclms = get_bits1(&s->gb);
894
895
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if (s->do_ac_filter)
896 26 decode_ac_filter(s);
897
898
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 3 times.
26 if (s->do_mclms)
899 23 decode_mclms(s);
900
901
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
26 if ((res = decode_cdlms(s)) < 0)
902 return res;
903 26 s->movave_scaling = get_bits(&s->gb, 3);
904 26 s->quant_stepsize = get_bits(&s->gb, 8) + 1;
905
906 26 reset_codec(s);
907 }
908
909 269 rawpcm_tile = get_bits1(&s->gb);
910
911
3/4
✓ Branch 0 taken 264 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 264 times.
269 if (!rawpcm_tile && !s->cdlms[0][0].order) {
912 av_log(s->avctx, AV_LOG_DEBUG,
913 "Waiting for seekable tile\n");
914 av_frame_unref(s->frame);
915 return -1;
916 }
917
918
919
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (i = 0; i < s->num_channels; i++)
920 538 s->is_channel_coded[i] = 1;
921
922
2/2
✓ Branch 0 taken 264 times.
✓ Branch 1 taken 5 times.
269 if (!rawpcm_tile) {
923
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 264 times.
792 for (i = 0; i < s->num_channels; i++)
924 528 s->is_channel_coded[i] = get_bits1(&s->gb);
925
926
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 210 times.
264 if (s->bV3RTM) {
927 // LPC
928 54 s->do_lpc = get_bits1(&s->gb);
929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (s->do_lpc) {
930 decode_lpc(s);
931 avpriv_request_sample(s->avctx, "Expect wrong output since "
932 "inverse LPC filter");
933 }
934 } else
935 210 s->do_lpc = 0;
936 }
937
938
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
269 if (get_bits_left(&s->gb) < 1)
939 return AVERROR_INVALIDDATA;
940
941
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 260 times.
269 if (get_bits1(&s->gb))
942 9 padding_zeroes = get_bits(&s->gb, 5);
943 else
944 260 padding_zeroes = 0;
945
946
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 264 times.
269 if (rawpcm_tile) {
947 5 int bits = s->bits_per_sample - padding_zeroes;
948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (bits <= 0) {
949 av_log(s->avctx, AV_LOG_ERROR,
950 "Invalid number of padding bits in raw PCM tile\n");
951 return AVERROR_INVALIDDATA;
952 }
953 ff_dlog(s->avctx, "RAWPCM %d bits per sample. "
954 "total %d bits, remain=%d\n", bits,
955 bits * s->num_channels * subframe_len, get_bits_count(&s->gb));
956
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5 times.
15 for (i = 0; i < s->num_channels; i++)
957
2/2
✓ Branch 0 taken 20480 times.
✓ Branch 1 taken 10 times.
20490 for (j = 0; j < subframe_len; j++)
958 20480 s->channel_residues[i][j] = get_sbits_long(&s->gb, bits);
959 } else {
960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if (s->bits_per_sample < padding_zeroes)
961 return AVERROR_INVALIDDATA;
962
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 264 times.
792 for (i = 0; i < s->num_channels; i++) {
963
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 24 times.
528 if (s->is_channel_coded[i]) {
964 504 decode_channel_residues(s, i, subframe_len);
965
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 453 times.
504 if (s->seekable_tile)
966 51 use_high_update_speed(s, i);
967 else
968 453 use_normal_update_speed(s, i);
969
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 420 times.
504 if (s->bits_per_sample > 16)
970 84 revert_cdlms32(s, i, 0, subframe_len);
971 else
972 420 revert_cdlms16(s, i, 0, subframe_len);
973 } else {
974 24 memset(s->channel_residues[i], 0, sizeof(**s->channel_residues) * subframe_len);
975 }
976 }
977
978
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 45 times.
264 if (s->do_mclms)
979 219 revert_mclms(s, subframe_len);
980
1/2
✓ Branch 0 taken 264 times.
✗ Branch 1 not taken.
264 if (s->do_inter_ch_decorr)
981 264 revert_inter_ch_decorr(s, subframe_len);
982
1/2
✓ Branch 0 taken 264 times.
✗ Branch 1 not taken.
264 if (s->do_ac_filter)
983 264 revert_acfilter(s, subframe_len);
984
985 /* Dequantize */
986
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
264 if (s->quant_stepsize != 1)
987 for (i = 0; i < s->num_channels; i++)
988 for (j = 0; j < subframe_len; j++)
989 s->channel_residues[i][j] *= (unsigned)s->quant_stepsize;
990 }
991
992 /* Write to proper output buffer depending on bit-depth */
993
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (i = 0; i < s->channels_for_cur_subframe; i++) {
994 538 int c = s->channel_indexes_for_cur_subframe[i];
995 538 int subframe_len = s->channel[c].subframe_len[s->channel[c].cur_subframe];
996
997
2/2
✓ Branch 0 taken 1101824 times.
✓ Branch 1 taken 538 times.
1102362 for (j = 0; j < subframe_len; j++) {
998
2/2
✓ Branch 0 taken 860160 times.
✓ Branch 1 taken 241664 times.
1101824 if (s->bits_per_sample == 16) {
999 860160 *s->samples_16[c]++ = (int16_t) s->channel_residues[c][j] * (1 << padding_zeroes);
1000 } else {
1001 241664 *s->samples_32[c]++ = s->channel_residues[c][j] * (256U << padding_zeroes);
1002 }
1003 }
1004 }
1005
1006 /* handled one subframe */
1007
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1008 538 int c = s->channel_indexes_for_cur_subframe[i];
1009
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
538 if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
1010 av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n");
1011 return AVERROR_INVALIDDATA;
1012 }
1013 538 ++s->channel[c].cur_subframe;
1014 }
1015 269 return 0;
1016 }
1017
1018 /**
1019 * @brief Decode one WMA frame.
1020 * @param s codec context
1021 * @return 0 if the trailer bit indicates that this is the last frame,
1022 * 1 if there are additional frames
1023 */
1024 269 static int decode_frame(WmallDecodeCtx *s)
1025 {
1026 269 GetBitContext* gb = &s->gb;
1027 269 int more_frames = 0, len = 0, i, ret;
1028
1029 269 s->frame->nb_samples = s->samples_per_frame;
1030
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
269 if ((ret = ff_get_buffer(s->avctx, s->frame, 0)) < 0) {
1031 /* return an error if no frame could be decoded at all */
1032 s->packet_loss = 1;
1033 s->frame->nb_samples = 0;
1034 return ret;
1035 }
1036
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (i = 0; i < s->num_channels; i++) {
1037 538 s->samples_16[i] = (int16_t *)s->frame->extended_data[i];
1038 538 s->samples_32[i] = (int32_t *)s->frame->extended_data[i];
1039 }
1040
1041 /* get frame length */
1042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 if (s->len_prefix)
1043 len = get_bits(gb, s->log2_frame_size);
1044
1045 /* decode tile information */
1046
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
269 if ((ret = decode_tilehdr(s))) {
1047 s->packet_loss = 1;
1048 av_frame_unref(s->frame);
1049 return ret;
1050 }
1051
1052 /* read drc info */
1053
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 219 times.
269 if (s->dynamic_range_compression)
1054 50 s->drc_gain = get_bits(gb, 8);
1055
1056 /* no idea what these are for, might be the number of samples
1057 that need to be skipped at the beginning or end of a stream */
1058
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 268 times.
269 if (get_bits1(gb)) {
1059 int av_unused skip;
1060
1061 /* usually true for the first frame */
1062
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (get_bits1(gb)) {
1063 skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1064 ff_dlog(s->avctx, "start skip: %i\n", skip);
1065 }
1066
1067 /* sometimes true for the last frame */
1068
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (get_bits1(gb)) {
1069 1 skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1070 ff_dlog(s->avctx, "end skip: %i\n", skip);
1071 1 s->frame->nb_samples -= skip;
1072
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (s->frame->nb_samples <= 0)
1073 return AVERROR_INVALIDDATA;
1074 }
1075
1076 }
1077
1078 /* reset subframe states */
1079 269 s->parsed_all_subframes = 0;
1080
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 269 times.
807 for (i = 0; i < s->num_channels; i++) {
1081 538 s->channel[i].decoded_samples = 0;
1082 538 s->channel[i].cur_subframe = 0;
1083 }
1084
1085 /* decode all subframes */
1086
2/2
✓ Branch 0 taken 269 times.
✓ Branch 1 taken 269 times.
538 while (!s->parsed_all_subframes) {
1087 269 int decoded_samples = s->channel[0].decoded_samples;
1088
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
269 if (decode_subframe(s) < 0) {
1089 s->packet_loss = 1;
1090 if (s->frame->nb_samples)
1091 s->frame->nb_samples = decoded_samples;
1092 return 0;
1093 }
1094 }
1095
1096 ff_dlog(s->avctx, "Frame done\n");
1097
1098 269 s->skip_frame = 0;
1099
1100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 if (s->len_prefix) {
1101 if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1102 /* FIXME: not sure if this is always an error */
1103 av_log(s->avctx, AV_LOG_ERROR,
1104 "frame[%"PRIu32"] would have to skip %i bits\n",
1105 s->frame_num,
1106 len - (get_bits_count(gb) - s->frame_offset) - 1);
1107 s->packet_loss = 1;
1108 return 0;
1109 }
1110
1111 /* skip the rest of the frame data */
1112 skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
1113 }
1114
1115 /* decode trailer bit */
1116 269 more_frames = get_bits1(gb);
1117 269 ++s->frame_num;
1118 269 return more_frames;
1119 }
1120
1121 /**
1122 * @brief Calculate remaining input buffer length.
1123 * @param s codec context
1124 * @param gb bitstream reader context
1125 * @return remaining size in bits
1126 */
1127 463 static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
1128 {
1129 463 return s->buf_bit_size - get_bits_count(gb);
1130 }
1131
1132 /**
1133 * @brief Fill the bit reservoir with a (partial) frame.
1134 * @param s codec context
1135 * @param gb bitstream reader context
1136 * @param len length of the partial frame
1137 * @param append decides whether to reset the buffer or not
1138 */
1139 177 static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
1140 int append)
1141 {
1142 int buflen;
1143 PutBitContext tmp;
1144
1145 /* when the frame data does not need to be concatenated, the input buffer
1146 is reset and additional bits from the previous frame are copied
1147 and skipped later so that a fast byte copy is possible */
1148
1149
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 88 times.
177 if (!append) {
1150 89 s->frame_offset = get_bits_count(gb) & 7;
1151 89 s->num_saved_bits = s->frame_offset;
1152 89 init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1153 }
1154
1155 177 buflen = (s->num_saved_bits + len + 8) >> 3;
1156
1157
2/4
✓ Branch 0 taken 177 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 177 times.
177 if (len <= 0 || buflen > s->max_frame_size) {
1158 avpriv_request_sample(s->avctx, "Too small input buffer");
1159 s->packet_loss = 1;
1160 s->num_saved_bits = 0;
1161 return;
1162 }
1163
1164 177 s->num_saved_bits += len;
1165
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 88 times.
177 if (!append) {
1166 89 ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
1167 s->num_saved_bits);
1168 } else {
1169 88 int align = 8 - (get_bits_count(gb) & 7);
1170 88 align = FFMIN(align, len);
1171 88 put_bits(&s->pb, align, get_bits(gb, align));
1172 88 len -= align;
1173 88 ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
1174 }
1175 177 skip_bits_long(gb, len);
1176
1177 177 tmp = s->pb;
1178 177 flush_put_bits(&tmp);
1179
1180 177 init_get_bits(&s->gb, s->frame_data, s->num_saved_bits);
1181 177 skip_bits(&s->gb, s->frame_offset);
1182 }
1183
1184 285 static int decode_packet(AVCodecContext *avctx, AVFrame *rframe,
1185 int *got_frame_ptr, AVPacket* avpkt)
1186 {
1187 285 WmallDecodeCtx *s = avctx->priv_data;
1188 285 GetBitContext* gb = &s->pgb;
1189 285 const uint8_t* buf = avpkt->data;
1190 285 int buf_size = avpkt->size;
1191 int num_bits_prev_frame, packet_sequence_number, spliced_packet;
1192
1193 285 s->frame->nb_samples = 0;
1194
1195
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 271 times.
285 if (!buf_size) {
1196 14 s->packet_done = 0;
1197
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 11 times.
14 if (s->num_saved_bits <= get_bits_count(&s->gb))
1198 3 return 0;
1199
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 7 times.
11 if (!decode_frame(s))
1200 4 s->num_saved_bits = 0;
1201
4/4
✓ Branch 0 taken 183 times.
✓ Branch 1 taken 88 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 179 times.
271 } else if (s->packet_done || s->packet_loss) {
1202 92 s->packet_done = 0;
1203
1204 92 s->next_packet_start = buf_size - FFMIN(avctx->block_align, buf_size);
1205 92 buf_size = FFMIN(avctx->block_align, buf_size);
1206 92 s->buf_bit_size = buf_size << 3;
1207
1208 /* parse packet header */
1209 92 init_get_bits(gb, buf, s->buf_bit_size);
1210 92 packet_sequence_number = get_bits(gb, 4);
1211 92 skip_bits(gb, 1); // Skip seekable_frame_in_packet, currently unused
1212 92 spliced_packet = get_bits1(gb);
1213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (spliced_packet)
1214 avpriv_request_sample(avctx, "Bitstream splicing");
1215
1216 /* get number of bits that need to be added to the previous frame */
1217 92 num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
1218
1219 /* check for packet loss */
1220
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 4 times.
92 if (!s->packet_loss &&
1221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
88 ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1222 s->packet_loss = 1;
1223 av_log(avctx, AV_LOG_ERROR,
1224 "Packet loss detected! seq %"PRIx8" vs %x\n",
1225 s->packet_sequence_number, packet_sequence_number);
1226 }
1227 92 s->packet_sequence_number = packet_sequence_number;
1228
1229
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 4 times.
92 if (num_bits_prev_frame > 0) {
1230 88 int remaining_packet_bits = s->buf_bit_size - get_bits_count(gb);
1231
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 85 times.
88 if (num_bits_prev_frame >= remaining_packet_bits) {
1232 3 num_bits_prev_frame = remaining_packet_bits;
1233 3 s->packet_done = 1;
1234 }
1235
1236 /* Append the previous frame data to the remaining data from the
1237 * previous packet to create a full frame. */
1238 88 save_bits(s, gb, num_bits_prev_frame, 1);
1239
1240 /* decode the cross packet frame if it is valid */
1241
3/4
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 85 times.
✗ Branch 3 not taken.
88 if (num_bits_prev_frame < remaining_packet_bits && !s->packet_loss)
1242 85 decode_frame(s);
1243 4 } else if (s->num_saved_bits - s->frame_offset) {
1244 ff_dlog(avctx, "ignoring %x previously saved bits\n",
1245 s->num_saved_bits - s->frame_offset);
1246 }
1247
1248
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 88 times.
92 if (s->packet_loss) {
1249 /* Reset number of saved bits so that the decoder does not start
1250 * to decode incomplete frames in the s->len_prefix == 0 case. */
1251 4 s->num_saved_bits = 0;
1252 4 s->packet_loss = 0;
1253 4 init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1254 }
1255
1256 } else {
1257 int frame_size;
1258
1259 179 s->buf_bit_size = (avpkt->size - s->next_packet_start) << 3;
1260 179 init_get_bits(gb, avpkt->data, s->buf_bit_size);
1261 179 skip_bits(gb, s->packet_offset);
1262
1263
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 179 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
179 if (s->len_prefix && remaining_bits(s, gb) > s->log2_frame_size &&
1264 (frame_size = show_bits(gb, s->log2_frame_size)) &&
1265 frame_size <= remaining_bits(s, gb)) {
1266 save_bits(s, gb, frame_size, 0);
1267
1268 if (!s->packet_loss)
1269 s->packet_done = !decode_frame(s);
1270
1/2
✓ Branch 0 taken 179 times.
✗ Branch 1 not taken.
179 } else if (!s->len_prefix
1271
2/2
✓ Branch 1 taken 173 times.
✓ Branch 2 taken 6 times.
179 && s->num_saved_bits > get_bits_count(&s->gb)) {
1272 /* when the frames do not have a length prefix, we don't know the
1273 * compressed length of the individual frames however, we know what
1274 * part of a new packet belongs to the previous frame therefore we
1275 * save the incoming packet first, then we append the "previous
1276 * frame" data from the next packet so that we get a buffer that
1277 * only contains full frames */
1278 173 s->packet_done = !decode_frame(s);
1279 } else {
1280 6 s->packet_done = 1;
1281 }
1282 }
1283
1284
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 282 times.
282 if (remaining_bits(s, gb) < 0) {
1285 av_log(avctx, AV_LOG_ERROR, "Overread %d\n", -remaining_bits(s, gb));
1286 s->packet_loss = 1;
1287 }
1288
1289
5/6
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 190 times.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 89 times.
✓ Branch 5 taken 3 times.
374 if (s->packet_done && !s->packet_loss &&
1290 92 remaining_bits(s, gb) > 0) {
1291 /* save the rest of the data so that it can be decoded
1292 * with the next packet */
1293 89 save_bits(s, gb, remaining_bits(s, gb), 0);
1294 }
1295
1296 282 *got_frame_ptr = s->frame->nb_samples > 0;
1297 282 av_frame_move_ref(rframe, s->frame);
1298
1299 282 s->packet_offset = get_bits_count(gb) & 7;
1300
1301
1/2
✓ Branch 0 taken 282 times.
✗ Branch 1 not taken.
282 return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
1302 }
1303
1304 static void flush(AVCodecContext *avctx)
1305 {
1306 WmallDecodeCtx *s = avctx->priv_data;
1307 s->packet_loss = 1;
1308 s->packet_done = 0;
1309 s->num_saved_bits = 0;
1310 s->frame_offset = 0;
1311 s->next_packet_start = 0;
1312 s->cdlms[0][0].order = 0;
1313 s->frame->nb_samples = 0;
1314 init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1315 }
1316
1317 8 static av_cold int decode_close(AVCodecContext *avctx)
1318 {
1319 8 WmallDecodeCtx *s = avctx->priv_data;
1320
1321 8 av_frame_free(&s->frame);
1322 8 av_freep(&s->frame_data);
1323
1324 8 return 0;
1325 }
1326
1327 const FFCodec ff_wmalossless_decoder = {
1328 .p.name = "wmalossless",
1329 CODEC_LONG_NAME("Windows Media Audio Lossless"),
1330 .p.type = AVMEDIA_TYPE_AUDIO,
1331 .p.id = AV_CODEC_ID_WMALOSSLESS,
1332 .priv_data_size = sizeof(WmallDecodeCtx),
1333 .init = decode_init,
1334 .close = decode_close,
1335 FF_CODEC_DECODE_CB(decode_packet),
1336 .flush = flush,
1337 .p.capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1338 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1339 .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
1340 AV_SAMPLE_FMT_S32P,
1341 AV_SAMPLE_FMT_NONE },
1342 };
1343