| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Musepack SV8 decoder | ||
| 3 | * Copyright (c) 2007 Konstantin Shishkov | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples | ||
| 25 | * divided into 32 subbands. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include "libavutil/channel_layout.h" | ||
| 29 | #include "libavutil/lfg.h" | ||
| 30 | #include "libavutil/thread.h" | ||
| 31 | #include "avcodec.h" | ||
| 32 | #include "codec_internal.h" | ||
| 33 | #include "decode.h" | ||
| 34 | #include "get_bits.h" | ||
| 35 | #include "mpegaudiodsp.h" | ||
| 36 | |||
| 37 | #include "mpc.h" | ||
| 38 | #include "mpc8data.h" | ||
| 39 | #include "mpc8huff.h" | ||
| 40 | |||
| 41 | static VLC band_vlc, scfi_vlc[2], dscf_vlc[2], res_vlc[2]; | ||
| 42 | static VLC q1_vlc, q2_vlc[2], q3_vlc[2], quant_vlc[4][2], q9up_vlc; | ||
| 43 | |||
| 44 | 7797 | static inline int mpc8_dec_base(GetBitContext *gb, int k, int n) | |
| 45 | { | ||
| 46 | 7797 | int len = mpc8_cnk_len[k-1][n-1] - 1; | |
| 47 |
1/2✓ Branch 0 taken 7797 times.
✗ Branch 1 not taken.
|
7797 | int code = len ? get_bits_long(gb, len) : 0; |
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 3746 times.
✓ Branch 1 taken 4051 times.
|
7797 | if (code >= mpc8_cnk_lost[k-1][n-1]) |
| 50 | 3746 | code = ((code << 1) | get_bits1(gb)) - mpc8_cnk_lost[k-1][n-1]; | |
| 51 | |||
| 52 | 7797 | return code; | |
| 53 | } | ||
| 54 | |||
| 55 | 7335 | static inline int mpc8_dec_enum(GetBitContext *gb, int k, int n) | |
| 56 | { | ||
| 57 | 7335 | int bits = 0; | |
| 58 | 7335 | const uint32_t * C = mpc8_cnk[k-1]; | |
| 59 | 7335 | int code = mpc8_dec_base(gb, k, n); | |
| 60 | |||
| 61 | do { | ||
| 62 | 109711 | n--; | |
| 63 |
2/2✓ Branch 0 taken 41077 times.
✓ Branch 1 taken 68634 times.
|
109711 | if (code >= C[n]) { |
| 64 | 41077 | bits |= 1U << n; | |
| 65 | 41077 | code -= C[n]; | |
| 66 | 41077 | C -= 32; | |
| 67 | 41077 | k--; | |
| 68 | } | ||
| 69 |
2/2✓ Branch 0 taken 102376 times.
✓ Branch 1 taken 7335 times.
|
109711 | } while(k > 0); |
| 70 | |||
| 71 | 7335 | return bits; | |
| 72 | } | ||
| 73 | |||
| 74 | 462 | static inline int mpc8_get_mod_golomb(GetBitContext *gb, int m) | |
| 75 | { | ||
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 462 times.
|
462 | if(mpc8_cnk_len[0][m] < 1) return 0; |
| 77 | 462 | return mpc8_dec_base(gb, 1, m+1); | |
| 78 | } | ||
| 79 | |||
| 80 | 7492 | static int mpc8_get_mask(GetBitContext *gb, int size, int t) | |
| 81 | { | ||
| 82 | 7492 | int mask = 0; | |
| 83 | |||
| 84 |
4/4✓ Branch 0 taken 7388 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 7335 times.
✓ Branch 3 taken 53 times.
|
7492 | if(t && t != size) |
| 85 | 7335 | mask = mpc8_dec_enum(gb, FFMIN(t, size - t), size); | |
| 86 |
2/2✓ Branch 0 taken 1317 times.
✓ Branch 1 taken 6175 times.
|
7492 | if((t << 1) > size) mask = ~mask; |
| 87 | |||
| 88 | 7492 | return mask; | |
| 89 | } | ||
| 90 | |||
| 91 | 42 | static av_cold void build_vlc(VLC *vlc, unsigned *buf_offset, | |
| 92 | const uint8_t codes_counts[16], | ||
| 93 | const uint8_t **syms, int offset) | ||
| 94 | { | ||
| 95 | static VLCElem vlc_buf[9296]; | ||
| 96 | uint8_t len[MPC8_MAX_VLC_SIZE]; | ||
| 97 | 42 | unsigned num = 0; | |
| 98 | |||
| 99 | 42 | vlc->table = &vlc_buf[*buf_offset]; | |
| 100 | 42 | vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *buf_offset; | |
| 101 | |||
| 102 |
2/2✓ Branch 0 taken 672 times.
✓ Branch 1 taken 42 times.
|
714 | for (int i = 16; i > 0; i--) |
| 103 |
2/2✓ Branch 0 taken 2686 times.
✓ Branch 1 taken 672 times.
|
3358 | for (unsigned tmp = num + codes_counts[i - 1]; num < tmp; num++) |
| 104 | 2686 | len[num] = i; | |
| 105 | |||
| 106 | 42 | ff_vlc_init_from_lengths(vlc, FFMIN(len[0], 9), num, len, 1, | |
| 107 | *syms, 1, 1, offset, VLC_INIT_STATIC_OVERLONG, NULL); | ||
| 108 | 42 | *buf_offset += vlc->table_size; | |
| 109 | 42 | *syms += num; | |
| 110 | 42 | } | |
| 111 | |||
| 112 | 2 | static av_cold void mpc8_init_static(void) | |
| 113 | { | ||
| 114 | 2 | const uint8_t *q_syms = mpc8_q_syms, *bands_syms = mpc8_bands_syms; | |
| 115 | 2 | const uint8_t *res_syms = mpc8_res_syms, *scfi_syms = mpc8_scfi_syms; | |
| 116 | 2 | const uint8_t *dscf_syms = mpc8_dscf_syms; | |
| 117 | 2 | unsigned offset = 0; | |
| 118 | |||
| 119 | 2 | build_vlc(&band_vlc, &offset, mpc8_bands_len_counts, &bands_syms, 0); | |
| 120 | |||
| 121 | 2 | build_vlc(&q1_vlc, &offset, mpc8_q1_len_counts, &q_syms, 0); | |
| 122 | 2 | build_vlc(&q9up_vlc, &offset, mpc8_q9up_len_counts, &q_syms, 0); | |
| 123 | |||
| 124 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | for (int i = 0; i < 2; i++){ |
| 125 | 4 | build_vlc(&scfi_vlc[i], &offset, mpc8_scfi_len_counts[i], &scfi_syms, 0); | |
| 126 | |||
| 127 | 4 | build_vlc(&dscf_vlc[i], &offset, mpc8_dscf_len_counts[i], &dscf_syms, 0); | |
| 128 | |||
| 129 | 4 | build_vlc(&res_vlc[i], &offset, mpc8_res_len_counts[i], &res_syms, 0); | |
| 130 | |||
| 131 | 4 | build_vlc(&q2_vlc[i], &offset, mpc8_q2_len_counts[i], &q_syms, 0); | |
| 132 | 4 | build_vlc(&q3_vlc[i], &offset, mpc8_q34_len_counts[i], | |
| 133 | 4 | &q_syms, -48 - 16 * i); | |
| 134 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
|
20 | for (int j = 0; j < 4; j++) |
| 135 | 16 | build_vlc(&quant_vlc[j][i], &offset, mpc8_q5_8_len_counts[i][j], | |
| 136 | 16 | &q_syms, -((8 << j) - 1)); | |
| 137 | } | ||
| 138 | 2 | ff_mpa_synth_init_fixed(); | |
| 139 | 2 | } | |
| 140 | |||
| 141 | 3 | static av_cold int mpc8_decode_init(AVCodecContext * avctx) | |
| 142 | { | ||
| 143 | static AVOnce init_static_once = AV_ONCE_INIT; | ||
| 144 | 3 | MPCContext *c = avctx->priv_data; | |
| 145 | GetBitContext gb; | ||
| 146 | int channels; | ||
| 147 | |||
| 148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if(avctx->extradata_size < 2){ |
| 149 | ✗ | av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); | |
| 150 | ✗ | return -1; | |
| 151 | } | ||
| 152 | 3 | memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); | |
| 153 | 3 | av_lfg_init(&c->rnd, 0xDEADBEEF); | |
| 154 | 3 | ff_mpadsp_init(&c->mpadsp); | |
| 155 | |||
| 156 | 3 | init_get_bits(&gb, avctx->extradata, 16); | |
| 157 | |||
| 158 | 3 | uint8_t sample_rate_idx = get_bits(&gb, 3); | |
| 159 | static const int sample_rates[] = { 44100, 48000, 37800, 32000 }; | ||
| 160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (sample_rate_idx >= FF_ARRAY_ELEMS(sample_rates)) { |
| 161 | ✗ | av_log(avctx, AV_LOG_ERROR, "invalid sample rate index (%u)\n", sample_rate_idx); | |
| 162 | ✗ | return AVERROR_INVALIDDATA; | |
| 163 | } | ||
| 164 | 3 | avctx->sample_rate = sample_rates[sample_rate_idx]; | |
| 165 | 3 | c->maxbands = get_bits(&gb, 5) + 1; | |
| 166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (c->maxbands >= BANDS) { |
| 167 | ✗ | av_log(avctx,AV_LOG_ERROR, "maxbands %d too high\n", c->maxbands); | |
| 168 | ✗ | return AVERROR_INVALIDDATA; | |
| 169 | } | ||
| 170 | 3 | channels = get_bits(&gb, 4) + 1; | |
| 171 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (channels > 2) { |
| 172 | ✗ | avpriv_request_sample(avctx, "Multichannel MPC SV8"); | |
| 173 | ✗ | return AVERROR_PATCHWELCOME; | |
| 174 | } | ||
| 175 | 3 | c->MSS = get_bits1(&gb); | |
| 176 | 3 | c->frames = 1 << (get_bits(&gb, 3) * 2); | |
| 177 | |||
| 178 | 3 | avctx->sample_fmt = AV_SAMPLE_FMT_S16P; | |
| 179 | 3 | av_channel_layout_uninit(&avctx->ch_layout); | |
| 180 | 3 | av_channel_layout_default(&avctx->ch_layout, channels); | |
| 181 | |||
| 182 | 3 | ff_thread_once(&init_static_once, mpc8_init_static); | |
| 183 | |||
| 184 | 3 | return 0; | |
| 185 | } | ||
| 186 | |||
| 187 | 459 | static int mpc8_decode_frame(AVCodecContext *avctx, AVFrame *frame, | |
| 188 | int *got_frame_ptr, AVPacket *avpkt) | ||
| 189 | { | ||
| 190 | 459 | const uint8_t *buf = avpkt->data; | |
| 191 | 459 | int buf_size = avpkt->size; | |
| 192 | 459 | MPCContext *c = avctx->priv_data; | |
| 193 | 459 | GetBitContext gb2, *gb = &gb2; | |
| 194 | int i, j, k, ch, cnt, res, t; | ||
| 195 | 459 | Band *bands = c->bands; | |
| 196 | int off; | ||
| 197 | int maxband, keyframe; | ||
| 198 | int last[2]; | ||
| 199 | |||
| 200 | 459 | keyframe = c->cur_frame == 0; | |
| 201 | |||
| 202 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 449 times.
|
459 | if(keyframe){ |
| 203 | 10 | memset(c->Q, 0, sizeof(c->Q)); | |
| 204 | 10 | c->last_bits_used = 0; | |
| 205 | } | ||
| 206 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 459 times.
|
459 | if ((res = init_get_bits8(gb, buf, buf_size)) < 0) |
| 207 | ✗ | return res; | |
| 208 | |||
| 209 | 459 | skip_bits(gb, c->last_bits_used & 7); | |
| 210 | |||
| 211 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 449 times.
|
459 | if(keyframe) |
| 212 | 10 | maxband = mpc8_get_mod_golomb(gb, c->maxbands + 1); | |
| 213 | else{ | ||
| 214 | 449 | maxband = c->last_max_band + get_vlc2(gb, band_vlc.table, MPC8_BANDS_BITS, 2); | |
| 215 |
2/2✓ Branch 0 taken 103 times.
✓ Branch 1 taken 346 times.
|
449 | if(maxband > 32) maxband -= 33; |
| 216 | } | ||
| 217 | |||
| 218 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 458 times.
|
459 | if (get_bits_left(gb) < 0) { |
| 219 | 1 | *got_frame_ptr = 0; | |
| 220 | 1 | return buf_size; | |
| 221 | } | ||
| 222 | |||
| 223 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 458 times.
|
458 | if(maxband > c->maxbands + 1) { |
| 224 | ✗ | av_log(avctx, AV_LOG_ERROR, "maxband %d too large\n",maxband); | |
| 225 | ✗ | return AVERROR_INVALIDDATA; | |
| 226 | } | ||
| 227 | 458 | c->last_max_band = maxband; | |
| 228 | |||
| 229 | /* read subband indexes */ | ||
| 230 |
2/2✓ Branch 0 taken 452 times.
✓ Branch 1 taken 6 times.
|
458 | if(maxband){ |
| 231 | 452 | last[0] = last[1] = 0; | |
| 232 |
2/2✓ Branch 0 taken 10414 times.
✓ Branch 1 taken 452 times.
|
10866 | for(i = maxband - 1; i >= 0; i--){ |
| 233 |
2/2✓ Branch 0 taken 20828 times.
✓ Branch 1 taken 10414 times.
|
31242 | for(ch = 0; ch < 2; ch++){ |
| 234 | 20828 | last[ch] = get_vlc2(gb, res_vlc[last[ch] > 2].table, MPC8_RES_BITS, 2) + last[ch]; | |
| 235 |
2/2✓ Branch 0 taken 4063 times.
✓ Branch 1 taken 16765 times.
|
20828 | if(last[ch] > 15) last[ch] -= 17; |
| 236 | 20828 | bands[i].res[ch] = last[ch]; | |
| 237 | } | ||
| 238 | } | ||
| 239 |
1/2✓ Branch 0 taken 452 times.
✗ Branch 1 not taken.
|
452 | if(c->MSS){ |
| 240 | int mask; | ||
| 241 | |||
| 242 | 452 | cnt = 0; | |
| 243 |
2/2✓ Branch 0 taken 10414 times.
✓ Branch 1 taken 452 times.
|
10866 | for(i = 0; i < maxband; i++) |
| 244 |
3/4✓ Branch 0 taken 103 times.
✓ Branch 1 taken 10311 times.
✓ Branch 2 taken 103 times.
✗ Branch 3 not taken.
|
10414 | if(bands[i].res[0] || bands[i].res[1]) |
| 245 | 10414 | cnt++; | |
| 246 | 452 | t = mpc8_get_mod_golomb(gb, cnt); | |
| 247 | 452 | mask = mpc8_get_mask(gb, cnt, t); | |
| 248 |
2/2✓ Branch 0 taken 10414 times.
✓ Branch 1 taken 452 times.
|
10866 | for(i = maxband - 1; i >= 0; i--) |
| 249 |
3/4✓ Branch 0 taken 103 times.
✓ Branch 1 taken 10311 times.
✓ Branch 2 taken 103 times.
✗ Branch 3 not taken.
|
10414 | if(bands[i].res[0] || bands[i].res[1]){ |
| 250 | 10414 | bands[i].msf = mask & 1; | |
| 251 | 10414 | mask >>= 1; | |
| 252 | } | ||
| 253 | } | ||
| 254 | } | ||
| 255 |
2/2✓ Branch 0 taken 2410 times.
✓ Branch 1 taken 458 times.
|
2868 | for(i = maxband; i < c->maxbands; i++) |
| 256 | 2410 | bands[i].res[0] = bands[i].res[1] = 0; | |
| 257 | |||
| 258 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 448 times.
|
458 | if(keyframe){ |
| 259 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 10 times.
|
330 | for(i = 0; i < 32; i++) |
| 260 | 320 | c->oldDSCF[0][i] = c->oldDSCF[1][i] = 1; | |
| 261 | } | ||
| 262 | |||
| 263 |
2/2✓ Branch 0 taken 10414 times.
✓ Branch 1 taken 458 times.
|
10872 | for(i = 0; i < maxband; i++){ |
| 264 |
3/4✓ Branch 0 taken 103 times.
✓ Branch 1 taken 10311 times.
✓ Branch 2 taken 103 times.
✗ Branch 3 not taken.
|
10414 | if(bands[i].res[0] || bands[i].res[1]){ |
| 265 | 10414 | cnt = !!bands[i].res[0] + !!bands[i].res[1] - 1; | |
| 266 |
1/2✓ Branch 0 taken 10414 times.
✗ Branch 1 not taken.
|
10414 | if(cnt >= 0){ |
| 267 | 10414 | t = get_vlc2(gb, scfi_vlc[cnt].table, scfi_vlc[cnt].bits, 1); | |
| 268 |
2/2✓ Branch 0 taken 10311 times.
✓ Branch 1 taken 103 times.
|
10414 | if(bands[i].res[0]) bands[i].scfi[0] = t >> (2 * cnt); |
| 269 |
2/2✓ Branch 0 taken 7971 times.
✓ Branch 1 taken 2443 times.
|
10414 | if(bands[i].res[1]) bands[i].scfi[1] = t & 3; |
| 270 | } | ||
| 271 | } | ||
| 272 | } | ||
| 273 | |||
| 274 |
2/2✓ Branch 0 taken 10414 times.
✓ Branch 1 taken 458 times.
|
10872 | for(i = 0; i < maxband; i++){ |
| 275 |
2/2✓ Branch 0 taken 20828 times.
✓ Branch 1 taken 10414 times.
|
31242 | for(ch = 0; ch < 2; ch++){ |
| 276 |
2/2✓ Branch 0 taken 2546 times.
✓ Branch 1 taken 18282 times.
|
20828 | if(!bands[i].res[ch]) continue; |
| 277 | |||
| 278 |
2/2✓ Branch 0 taken 388 times.
✓ Branch 1 taken 17894 times.
|
18282 | if(c->oldDSCF[ch][i]){ |
| 279 | 388 | bands[i].scf_idx[ch][0] = get_bits(gb, 7) - 6; | |
| 280 | 388 | c->oldDSCF[ch][i] = 0; | |
| 281 | }else{ | ||
| 282 | 17894 | t = get_vlc2(gb, dscf_vlc[1].table, MPC8_DSCF1_BITS, 2); | |
| 283 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 17844 times.
|
17894 | if(t == 64) |
| 284 | 50 | t += get_bits(gb, 6); | |
| 285 | 17894 | bands[i].scf_idx[ch][0] = ((bands[i].scf_idx[ch][2] + t - 25) & 0x7F) - 6; | |
| 286 | } | ||
| 287 |
2/2✓ Branch 0 taken 36564 times.
✓ Branch 1 taken 18282 times.
|
54846 | for(j = 0; j < 2; j++){ |
| 288 |
2/2✓ Branch 0 taken 23434 times.
✓ Branch 1 taken 13130 times.
|
36564 | if((bands[i].scfi[ch] << j) & 2) |
| 289 | 23434 | bands[i].scf_idx[ch][j + 1] = bands[i].scf_idx[ch][j]; | |
| 290 | else{ | ||
| 291 | 13130 | t = get_vlc2(gb, dscf_vlc[0].table, MPC8_DSCF0_BITS, 2); | |
| 292 |
2/2✓ Branch 0 taken 98 times.
✓ Branch 1 taken 13032 times.
|
13130 | if(t == 31) |
| 293 | 98 | t = 64 + get_bits(gb, 6); | |
| 294 | 13130 | bands[i].scf_idx[ch][j + 1] = ((bands[i].scf_idx[ch][j] + t - 25) & 0x7F) - 6; | |
| 295 | } | ||
| 296 | } | ||
| 297 | } | ||
| 298 | } | ||
| 299 | |||
| 300 |
2/2✓ Branch 0 taken 10414 times.
✓ Branch 1 taken 458 times.
|
10872 | for(i = 0, off = 0; i < maxband; i++, off += SAMPLES_PER_BAND){ |
| 301 |
2/2✓ Branch 0 taken 20828 times.
✓ Branch 1 taken 10414 times.
|
31242 | for(ch = 0; ch < 2; ch++){ |
| 302 | 20828 | res = bands[i].res[ch]; | |
| 303 |
6/7✗ Branch 0 not taken.
✓ Branch 1 taken 2546 times.
✓ Branch 2 taken 3520 times.
✓ Branch 3 taken 6121 times.
✓ Branch 4 taken 4822 times.
✓ Branch 5 taken 3454 times.
✓ Branch 6 taken 365 times.
|
20828 | switch(res){ |
| 304 | ✗ | case -1: | |
| 305 | ✗ | for(j = 0; j < SAMPLES_PER_BAND; j++) | |
| 306 | ✗ | c->Q[ch][off + j] = (av_lfg_get(&c->rnd) & 0x3FC) - 510; | |
| 307 | ✗ | break; | |
| 308 | 2546 | case 0: | |
| 309 | 2546 | break; | |
| 310 | 3520 | case 1: | |
| 311 |
2/2✓ Branch 0 taken 7040 times.
✓ Branch 1 taken 3520 times.
|
10560 | for(j = 0; j < SAMPLES_PER_BAND; j += SAMPLES_PER_BAND / 2){ |
| 312 | 7040 | cnt = get_vlc2(gb, q1_vlc.table, MPC8_Q1_BITS, 2); | |
| 313 | 7040 | t = mpc8_get_mask(gb, 18, cnt); | |
| 314 |
2/2✓ Branch 0 taken 126720 times.
✓ Branch 1 taken 7040 times.
|
133760 | for(k = 0; k < SAMPLES_PER_BAND / 2; k++) |
| 315 | 126720 | c->Q[ch][off + j + k] = t & (1 << (SAMPLES_PER_BAND / 2 - k - 1)) | |
| 316 |
2/2✓ Branch 0 taken 43848 times.
✓ Branch 1 taken 82872 times.
|
126720 | ? (get_bits1(gb) << 1) - 1 : 0; |
| 317 | } | ||
| 318 | 3520 | break; | |
| 319 | 6121 | case 2: | |
| 320 | 6121 | cnt = 6;//2*mpc8_thres[res] | |
| 321 |
2/2✓ Branch 0 taken 73452 times.
✓ Branch 1 taken 6121 times.
|
79573 | for(j = 0; j < SAMPLES_PER_BAND; j += 3){ |
| 322 | 73452 | t = get_vlc2(gb, q2_vlc[cnt > 3].table, MPC8_Q2_BITS, 2); | |
| 323 | 73452 | c->Q[ch][off + j + 0] = mpc8_idx50[t]; | |
| 324 | 73452 | c->Q[ch][off + j + 1] = mpc8_idx51[t]; | |
| 325 | 73452 | c->Q[ch][off + j + 2] = mpc8_idx52[t]; | |
| 326 | 73452 | cnt = (cnt >> 1) + mpc8_huffq2[t]; | |
| 327 | } | ||
| 328 | 6121 | break; | |
| 329 | 4822 | case 3: | |
| 330 | case 4: | ||
| 331 |
2/2✓ Branch 0 taken 86796 times.
✓ Branch 1 taken 4822 times.
|
91618 | for(j = 0; j < SAMPLES_PER_BAND; j += 2){ |
| 332 | 86796 | t = get_vlc2(gb, q3_vlc[res - 3].table, MPC8_Q3_BITS, 2); | |
| 333 | 86796 | c->Q[ch][off + j + 1] = t >> 4; | |
| 334 | 86796 | c->Q[ch][off + j + 0] = sign_extend(t, 4); | |
| 335 | } | ||
| 336 | 4822 | break; | |
| 337 | 3454 | case 5: | |
| 338 | case 6: | ||
| 339 | case 7: | ||
| 340 | case 8: | ||
| 341 | 3454 | cnt = 2 * mpc8_thres[res]; | |
| 342 |
2/2✓ Branch 0 taken 124344 times.
✓ Branch 1 taken 3454 times.
|
127798 | for(j = 0; j < SAMPLES_PER_BAND; j++){ |
| 343 | 124344 | const VLC *vlc = &quant_vlc[res - 5][cnt > mpc8_thres[res]]; | |
| 344 | 124344 | c->Q[ch][off + j] = get_vlc2(gb, vlc->table, vlc->bits, 2); | |
| 345 | 124344 | cnt = (cnt >> 1) + FFABS(c->Q[ch][off + j]); | |
| 346 | } | ||
| 347 | 3454 | break; | |
| 348 | 365 | default: | |
| 349 |
2/2✓ Branch 0 taken 13140 times.
✓ Branch 1 taken 365 times.
|
13505 | for(j = 0; j < SAMPLES_PER_BAND; j++){ |
| 350 | 13140 | c->Q[ch][off + j] = get_vlc2(gb, q9up_vlc.table, MPC8_Q9UP_BITS, 2); | |
| 351 |
2/2✓ Branch 0 taken 5544 times.
✓ Branch 1 taken 7596 times.
|
13140 | if(res != 9){ |
| 352 | 5544 | c->Q[ch][off + j] <<= res - 9; | |
| 353 | 5544 | c->Q[ch][off + j] |= get_bits(gb, res - 9); | |
| 354 | } | ||
| 355 | 13140 | c->Q[ch][off + j] -= (1 << (res - 2)) - 1; | |
| 356 | } | ||
| 357 | } | ||
| 358 | } | ||
| 359 | } | ||
| 360 | |||
| 361 | 458 | frame->nb_samples = MPC_FRAME_SIZE; | |
| 362 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 458 times.
|
458 | if ((res = ff_get_buffer(avctx, frame, 0)) < 0) |
| 363 | ✗ | return res; | |
| 364 | |||
| 365 | 458 | ff_mpc_dequantize_and_synth(c, maxband - 1, | |
| 366 | 458 | (int16_t **)frame->extended_data, | |
| 367 | avctx->ch_layout.nb_channels); | ||
| 368 | |||
| 369 | 458 | c->cur_frame++; | |
| 370 | |||
| 371 | 458 | c->last_bits_used = get_bits_count(gb); | |
| 372 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 451 times.
|
458 | if(c->cur_frame >= c->frames) |
| 373 | 7 | c->cur_frame = 0; | |
| 374 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 458 times.
|
458 | if (get_bits_left(gb) < 0) { |
| 375 | ✗ | av_log(avctx, AV_LOG_ERROR, "Overread %d\n", -get_bits_left(gb)); | |
| 376 | ✗ | c->last_bits_used = buf_size << 3; | |
| 377 |
3/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 451 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
|
458 | } else if (c->cur_frame == 0 && get_bits_left(gb) < 8) {// we have only padding left |
| 378 | 7 | c->last_bits_used = buf_size << 3; | |
| 379 | } | ||
| 380 | |||
| 381 | 458 | *got_frame_ptr = 1; | |
| 382 | |||
| 383 |
2/2✓ Branch 0 taken 451 times.
✓ Branch 1 taken 7 times.
|
458 | return c->cur_frame ? c->last_bits_used >> 3 : buf_size; |
| 384 | } | ||
| 385 | |||
| 386 | ✗ | static av_cold void mpc8_decode_flush(AVCodecContext *avctx) | |
| 387 | { | ||
| 388 | ✗ | MPCContext *c = avctx->priv_data; | |
| 389 | ✗ | c->cur_frame = 0; | |
| 390 | ✗ | } | |
| 391 | |||
| 392 | const FFCodec ff_mpc8_decoder = { | ||
| 393 | .p.name = "mpc8", | ||
| 394 | CODEC_LONG_NAME("Musepack SV8"), | ||
| 395 | .p.type = AVMEDIA_TYPE_AUDIO, | ||
| 396 | .p.id = AV_CODEC_ID_MUSEPACK8, | ||
| 397 | .priv_data_size = sizeof(MPCContext), | ||
| 398 | .init = mpc8_decode_init, | ||
| 399 | FF_CODEC_DECODE_CB(mpc8_decode_frame), | ||
| 400 | .flush = mpc8_decode_flush, | ||
| 401 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF, | ||
| 402 | CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_S16P), | ||
| 403 | }; | ||
| 404 |