| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Bink Audio decoder | 2 * Bink Audio decoder |
| 3 * Copyright (c) 2007-2010 Peter Ross (pross@xvid.org) | 3 * Copyright (c) 2007-2010 Peter Ross (pross@xvid.org) |
| 4 * Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu) | 4 * Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu) |
| 5 * | 5 * |
| 6 * This file is part of FFmpeg. | 6 * This file is part of FFmpeg. |
| 7 * | 7 * |
| 8 * FFmpeg is free software; you can redistribute it and/or | 8 * FFmpeg is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * Bink Audio decoder | 25 * Bink Audio decoder |
| 26 * | 26 * |
| 27 * Technical details here: | 27 * Technical details here: |
| 28 * http://wiki.multimedia.cx/index.php?title=Bink_Audio | 28 * http://wiki.multimedia.cx/index.php?title=Bink_Audio |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "avcodec.h" | 31 #include "avcodec.h" |
| 32 #define ALT_BITSTREAM_READER_LE | 32 #define ALT_BITSTREAM_READER_LE |
| 33 #include "get_bits.h" | 33 #include "get_bits.h" |
| 34 #include "dsputil.h" | 34 #include "dsputil.h" |
| 35 #include "fft.h" |
| 36 |
| 35 extern const uint16_t ff_wma_critical_freqs[25]; | 37 extern const uint16_t ff_wma_critical_freqs[25]; |
| 36 | 38 |
| 37 #define MAX_CHANNELS 2 | 39 #define MAX_CHANNELS 2 |
| 38 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11) | 40 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11) |
| 39 | 41 |
| 40 typedef struct { | 42 typedef struct { |
| 41 AVCodecContext *avctx; | 43 AVCodecContext *avctx; |
| 42 GetBitContext gb; | 44 GetBitContext gb; |
| 43 DSPContext dsp; | 45 DSPContext dsp; |
| 44 int first; | 46 int first; |
| 45 int channels; | 47 int channels; |
| 46 int frame_len; ///< transform size (samples) | 48 int frame_len; ///< transform size (samples) |
| 47 int overlap_len; ///< overlap size (samples) | 49 int overlap_len; ///< overlap size (samples) |
| 48 int block_size; | 50 int block_size; |
| 49 int num_bands; | 51 int num_bands; |
| 50 unsigned int *bands; | 52 unsigned int *bands; |
| 51 float root; | 53 float root; |
| 52 DECLARE_ALIGNED_16(FFTSample, coeffs)[BINK_BLOCK_MAX_SIZE]; | 54 DECLARE_ALIGNED(16, FFTSample, coeffs)[BINK_BLOCK_MAX_SIZE]; |
| 53 DECLARE_ALIGNED_16(short, previous)[BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs
from previous audio block | 55 DECLARE_ALIGNED(16, short, previous)[BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs
from previous audio block |
| 54 float *coeffs_ptr[MAX_CHANNELS]; ///< pointers to the coeffs arrays for floa
t_to_int16_interleave | 56 float *coeffs_ptr[MAX_CHANNELS]; ///< pointers to the coeffs arrays for floa
t_to_int16_interleave |
| 55 union { | 57 union { |
| 56 RDFTContext rdft; | 58 RDFTContext rdft; |
| 57 DCTContext dct; | 59 DCTContext dct; |
| 58 } trans; | 60 } trans; |
| 59 } BinkAudioContext; | 61 } BinkAudioContext; |
| 60 | 62 |
| 61 | 63 |
| 62 static av_cold int decode_init(AVCodecContext *avctx) | 64 static av_cold int decode_init(AVCodecContext *avctx) |
| 63 { | 65 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 for (i = 1; i < s->num_bands; i++) | 117 for (i = 1; i < s->num_bands; i++) |
| 116 s->bands[i] = ff_wma_critical_freqs[i - 1] * (s->frame_len / 2) / sample
_rate_half; | 118 s->bands[i] = ff_wma_critical_freqs[i - 1] * (s->frame_len / 2) / sample
_rate_half; |
| 117 s->bands[s->num_bands] = s->frame_len / 2; | 119 s->bands[s->num_bands] = s->frame_len / 2; |
| 118 | 120 |
| 119 s->first = 1; | 121 s->first = 1; |
| 120 avctx->sample_fmt = SAMPLE_FMT_S16; | 122 avctx->sample_fmt = SAMPLE_FMT_S16; |
| 121 | 123 |
| 122 for (i = 0; i < s->channels; i++) | 124 for (i = 0; i < s->channels; i++) |
| 123 s->coeffs_ptr[i] = s->coeffs + i * s->frame_len; | 125 s->coeffs_ptr[i] = s->coeffs + i * s->frame_len; |
| 124 | 126 |
| 125 if (avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) | 127 if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_
RDFT) |
| 126 ff_rdft_init(&s->trans.rdft, frame_len_bits, IRIDFT); | 128 ff_rdft_init(&s->trans.rdft, frame_len_bits, DFT_C2R); |
| 129 else if (CONFIG_BINKAUDIO_DCT_DECODER) |
| 130 ff_dct_init(&s->trans.dct, frame_len_bits, 1); |
| 127 else | 131 else |
| 128 ff_dct_init(&s->trans.dct, frame_len_bits, 0); | 132 return -1; |
| 129 | 133 |
| 130 return 0; | 134 return 0; |
| 131 } | 135 } |
| 132 | 136 |
| 133 static float get_float(GetBitContext *gb) | 137 static float get_float(GetBitContext *gb) |
| 134 { | 138 { |
| 135 int power = get_bits(gb, 5); | 139 int power = get_bits(gb, 5); |
| 136 float f = ldexpf(get_bits_long(gb, 23), power - 23); | 140 float f = ldexpf(get_bits_long(gb, 23), power - 23); |
| 137 if (get_bits1(gb)) | 141 if (get_bits1(gb)) |
| 138 f = -f; | 142 f = -f; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 else | 206 else |
| 203 coeffs[i] = q * coeff; | 207 coeffs[i] = q * coeff; |
| 204 } else { | 208 } else { |
| 205 coeffs[i] = 0.0f; | 209 coeffs[i] = 0.0f; |
| 206 } | 210 } |
| 207 i++; | 211 i++; |
| 208 } | 212 } |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 | 215 |
| 212 if (use_dct) | 216 if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) { |
| 217 coeffs[0] /= 0.5; |
| 213 ff_dct_calc (&s->trans.dct, coeffs); | 218 ff_dct_calc (&s->trans.dct, coeffs); |
| 214 else | 219 s->dsp.vector_fmul_scalar(coeffs, coeffs, s->frame_len / 2, s->frame
_len); |
| 220 } |
| 221 else if (CONFIG_BINKAUDIO_RDFT_DECODER) |
| 215 ff_rdft_calc(&s->trans.rdft, coeffs); | 222 ff_rdft_calc(&s->trans.rdft, coeffs); |
| 216 } | 223 } |
| 217 | 224 |
| 218 s->dsp.float_to_int16_interleave(out, (const float **)s->coeffs_ptr, s->fram
e_len, s->channels); | 225 s->dsp.float_to_int16_interleave(out, (const float **)s->coeffs_ptr, s->fram
e_len, s->channels); |
| 219 | 226 |
| 220 if (!s->first) { | 227 if (!s->first) { |
| 221 int count = s->overlap_len * s->channels; | 228 int count = s->overlap_len * s->channels; |
| 222 int shift = av_log2(count); | 229 int shift = av_log2(count); |
| 223 for (i = 0; i < count; i++) { | 230 for (i = 0; i < count; i++) { |
| 224 out[i] = (s->previous[i] * (count - i) + out[i] * i) >> shift; | 231 out[i] = (s->previous[i] * (count - i) + out[i] * i) >> shift; |
| 225 } | 232 } |
| 226 } | 233 } |
| 227 | 234 |
| 228 memcpy(s->previous, out + s->block_size, | 235 memcpy(s->previous, out + s->block_size, |
| 229 s->overlap_len * s->channels * sizeof(*out)); | 236 s->overlap_len * s->channels * sizeof(*out)); |
| 230 | 237 |
| 231 s->first = 0; | 238 s->first = 0; |
| 232 } | 239 } |
| 233 | 240 |
| 234 static av_cold int decode_end(AVCodecContext *avctx) | 241 static av_cold int decode_end(AVCodecContext *avctx) |
| 235 { | 242 { |
| 236 BinkAudioContext * s = avctx->priv_data; | 243 BinkAudioContext * s = avctx->priv_data; |
| 237 av_freep(&s->bands); | 244 av_freep(&s->bands); |
| 238 if (avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) | 245 if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_
RDFT) |
| 239 ff_rdft_end(&s->trans.rdft); | 246 ff_rdft_end(&s->trans.rdft); |
| 240 else | 247 else if (CONFIG_BINKAUDIO_DCT_DECODER) |
| 241 ff_dct_end(&s->trans.dct); | 248 ff_dct_end(&s->trans.dct); |
| 242 return 0; | 249 return 0; |
| 243 } | 250 } |
| 244 | 251 |
| 245 static void get_bits_align32(GetBitContext *s) | 252 static void get_bits_align32(GetBitContext *s) |
| 246 { | 253 { |
| 247 int n = (-get_bits_count(s)) & 31; | 254 int n = (-get_bits_count(s)) & 31; |
| 248 if (n) skip_bits(s, n); | 255 if (n) skip_bits(s, n); |
| 249 } | 256 } |
| 250 | 257 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 263 init_get_bits(gb, buf, buf_size * 8); | 270 init_get_bits(gb, buf, buf_size * 8); |
| 264 | 271 |
| 265 reported_size = get_bits_long(gb, 32); | 272 reported_size = get_bits_long(gb, 32); |
| 266 while (get_bits_count(gb) / 8 < buf_size && | 273 while (get_bits_count(gb) / 8 < buf_size && |
| 267 samples + s->block_size <= samples_end) { | 274 samples + s->block_size <= samples_end) { |
| 268 decode_block(s, samples, avctx->codec->id == CODEC_ID_BINKAUDIO_DCT); | 275 decode_block(s, samples, avctx->codec->id == CODEC_ID_BINKAUDIO_DCT); |
| 269 samples += s->block_size; | 276 samples += s->block_size; |
| 270 get_bits_align32(gb); | 277 get_bits_align32(gb); |
| 271 } | 278 } |
| 272 | 279 |
| 273 *data_size = (uint8_t*)samples - (uint8_t*)data; | 280 *data_size = FFMIN(reported_size, (uint8_t*)samples - (uint8_t*)data); |
| 274 if (reported_size != *data_size) { | |
| 275 av_log(avctx, AV_LOG_WARNING, "reported data size (%d) does not match ou
tput data size (%d)\n", | |
| 276 reported_size, *data_size); | |
| 277 } | |
| 278 return buf_size; | 281 return buf_size; |
| 279 } | 282 } |
| 280 | 283 |
| 281 AVCodec binkaudio_rdft_decoder = { | 284 AVCodec binkaudio_rdft_decoder = { |
| 282 "binkaudio_rdft", | 285 "binkaudio_rdft", |
| 283 CODEC_TYPE_AUDIO, | 286 CODEC_TYPE_AUDIO, |
| 284 CODEC_ID_BINKAUDIO_RDFT, | 287 CODEC_ID_BINKAUDIO_RDFT, |
| 285 sizeof(BinkAudioContext), | 288 sizeof(BinkAudioContext), |
| 286 decode_init, | 289 decode_init, |
| 287 NULL, | 290 NULL, |
| 288 decode_end, | 291 decode_end, |
| 289 decode_frame, | 292 decode_frame, |
| 290 .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)") | 293 .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)") |
| 291 }; | 294 }; |
| 292 | 295 |
| 293 AVCodec binkaudio_dct_decoder = { | 296 AVCodec binkaudio_dct_decoder = { |
| 294 "binkaudio_dct", | 297 "binkaudio_dct", |
| 295 CODEC_TYPE_AUDIO, | 298 CODEC_TYPE_AUDIO, |
| 296 CODEC_ID_BINKAUDIO_DCT, | 299 CODEC_ID_BINKAUDIO_DCT, |
| 297 sizeof(BinkAudioContext), | 300 sizeof(BinkAudioContext), |
| 298 decode_init, | 301 decode_init, |
| 299 NULL, | 302 NULL, |
| 300 decode_end, | 303 decode_end, |
| 301 decode_frame, | 304 decode_frame, |
| 302 .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)") | 305 .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)") |
| 303 }; | 306 }; |
| OLD | NEW |