As presented in .binka files.
Unified · Split
| @@ -44,6 +44,7 @@ · 43 unmodified lines | ||
| 44 | 44 | #include "rdft.h" |
| 45 | 45 | #include "wma_freqs.h" |
| 46 | 46 | |
| 47 | +#define MAX_DCT_CHANNELS 6 | |
| 47 | 48 | #define MAX_CHANNELS 2 |
| 48 | 49 | #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11) |
| 49 | 50 | |
| @@ -52,13 +53,14 @@ typedef struct BinkAudioContext { · 2 unmodified lines | ||
| 52 | 53 | int version_b; ///< Bink version 'b' |
| 53 | 54 | int first; |
| 54 | 55 | int channels; |
| 56 | + int ch_offset; | |
| 55 | 57 | int frame_len; ///< transform size (samples) |
| 56 | 58 | int overlap_len; ///< overlap size (samples) |
| 57 | 59 | int block_size; |
| 58 | 60 | int num_bands; |
| 59 | 61 | float root; |
| 60 | 62 | unsigned int bands[26]; |
| 61 | − float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block | |
| 63 | + float previous[MAX_DCT_CHANNELS][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block | |
| 62 | 64 | float quant_table[96]; |
| 63 | 65 | AVPacket *pkt; |
| 64 | 66 | union { |
| @@ -75,6 +77,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 10 unmodified lines | ||
| 75 | 77 | int sample_rate_half; |
| 76 | 78 | int i, ret; |
| 77 | 79 | int frame_len_bits; |
| 80 | + int max_channels = avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT ? MAX_CHANNELS : MAX_DCT_CHANNELS; | |
| 78 | 81 | int channels = avctx->ch_layout.nb_channels; |
| 79 | 82 | |
| 80 | 83 | /* determine frame length */ |
| @@ -86,7 +89,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 5 unmodified lines | ||
| 86 | 89 | frame_len_bits = 11; |
| 87 | 90 | } |
| 88 | 91 | |
| 89 | − if (channels < 1 || channels > MAX_CHANNELS) { | |
| 92 | + if (channels < 1 || channels > max_channels) { | |
| 90 | 93 | av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", channels); |
| 91 | 94 | return AVERROR_INVALIDDATA; |
| 92 | 95 | } |
| @@ -111,7 +114,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 18 unmodified lines | ||
| 111 | 114 | |
| 112 | 115 | s->frame_len = 1 << frame_len_bits; |
| 113 | 116 | s->overlap_len = s->frame_len / 16; |
| 114 | − s->block_size = (s->frame_len - s->overlap_len) * s->channels; | |
| 117 | + s->block_size = (s->frame_len - s->overlap_len) * FFMIN(MAX_CHANNELS, s->channels); | |
| 115 | 118 | sample_rate_half = (sample_rate + 1LL) / 2; |
| 116 | 119 | if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) |
| 117 | 120 | s->root = 2.0 / (sqrt(s->frame_len) * 32768.0); |
| @@ -167,7 +170,8 @@ static const uint8_t rle_length_tab[16] = { · 49 unmodified lines | ||
| 167 | 170 | * @param[out] out Output buffer (must contain s->block_size elements) |
| 168 | 171 | * @return 0 on success, negative error code on failure |
| 169 | 172 | */ |
| 170 | −static int decode_block(BinkAudioContext *s, float **out, int use_dct) | |
| 173 | +static int decode_block(BinkAudioContext *s, float **out, int use_dct, | |
| 174 | + int channels, int ch_offset) | |
| 171 | 175 | { |
| 172 | 176 | int ch, i, j, k; |
| 173 | 177 | float q, quant[25]; |
| @@ -177,8 +181,8 @@ static int decode_block(BinkAudioContext *s, float **out, int use_dct) · 3 unmodified lines | ||
| 177 | 181 | if (use_dct) |
| 178 | 182 | skip_bits(gb, 2); |
| 179 | 183 | |
| 180 | − for (ch = 0; ch < s->channels; ch++) { | |
| 181 | − FFTSample *coeffs = out[ch]; | |
| 184 | + for (ch = 0; ch < channels; ch++) { | |
| 185 | + FFTSample *coeffs = out[ch + ch_offset]; | |
| 182 | 186 | |
| 183 | 187 | if (s->version_b) { |
| 184 | 188 | if (get_bits_left(gb) < 64) |
| @@ -253,17 +257,17 @@ static int decode_block(BinkAudioContext *s, float **out, int use_dct) · 68 unmodified lines | ||
| 253 | 257 | s->trans.rdft.rdft_calc(&s->trans.rdft, coeffs); |
| 254 | 258 | } |
| 255 | 259 | |
| 256 | − for (ch = 0; ch < s->channels; ch++) { | |
| 260 | + for (ch = 0; ch < channels; ch++) { | |
| 257 | 261 | int j; |
| 258 | − int count = s->overlap_len * s->channels; | |
| 262 | + int count = s->overlap_len * channels; | |
| 259 | 263 | if (!s->first) { |
| 260 | 264 | j = ch; |
| 261 | − for (i = 0; i < s->overlap_len; i++, j += s->channels) | |
| 262 | − out[ch][i] = (s->previous[ch][i] * (count - j) + | |
| 263 | − out[ch][i] * j) / count; | |
| 265 | + for (i = 0; i < s->overlap_len; i++, j += channels) | |
| 266 | + out[ch + ch_offset][i] = (s->previous[ch + ch_offset][i] * (count - j) + | |
| 267 | + out[ch + ch_offset][i] * j) / count; | |
| 264 | 268 | } |
| 265 | − memcpy(s->previous[ch], &out[ch][s->frame_len - s->overlap_len], | |
| 266 | − s->overlap_len * sizeof(*s->previous[ch])); | |
| 269 | + memcpy(s->previous[ch + ch_offset], &out[ch + ch_offset][s->frame_len - s->overlap_len], | |
| 270 | + s->overlap_len * sizeof(*s->previous[ch + ch_offset])); | |
| 267 | 271 | } |
| 268 | 272 | |
| 269 | 273 | s->first = 0; |
| @@ -294,6 +298,7 @@ static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 24 unmodified lines | ||
| 294 | 298 | GetBitContext *gb = &s->gb; |
| 295 | 299 | int ret; |
| 296 | 300 | |
| 301 | +again: | |
| 297 | 302 | if (!s->pkt->data) { |
| 298 | 303 | ret = ff_decode_get_packet(avctx, s->pkt); |
| 299 | 304 | if (ret < 0) |
| @@ -314,22 +319,31 @@ static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 14 unmodified lines | ||
| 314 | 319 | } |
| 315 | 320 | |
| 316 | 321 | /* get output buffer */ |
| 317 | − frame->nb_samples = s->frame_len; | |
| 318 | − if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) | |
| 319 | − return ret; | |
| 322 | + if (s->ch_offset == 0) { | |
| 323 | + frame->nb_samples = s->frame_len; | |
| 324 | + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) | |
| 325 | + return ret; | |
| 326 | + } | |
| 320 | 327 | |
| 321 | 328 | if (decode_block(s, (float **)frame->extended_data, |
| 322 | − avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT)) { | |
| 329 | + avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT, | |
| 330 | + FFMIN(MAX_CHANNELS, s->channels - s->ch_offset), s->ch_offset)) { | |
| 323 | 331 | av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n"); |
| 324 | 332 | return AVERROR_INVALIDDATA; |
| 325 | 333 | } |
| 334 | + s->ch_offset += MAX_CHANNELS; | |
| 326 | 335 | get_bits_align32(gb); |
| 327 | 336 | if (!get_bits_left(gb)) { |
| 328 | 337 | memset(gb, 0, sizeof(*gb)); |
| 329 | 338 | av_packet_unref(s->pkt); |
| 330 | 339 | } |
| 340 | + if (s->ch_offset >= s->channels) { | |
| 341 | + s->ch_offset = 0; | |
| 342 | + } else { | |
| 343 | + goto again; | |
| 344 | + } | |
| 331 | 345 | |
| 332 | − frame->nb_samples = s->block_size / avctx->ch_layout.nb_channels; | |
| 346 | + frame->nb_samples = s->block_size / FFMIN(avctx->ch_layout.nb_channels, MAX_CHANNELS); | |
| 333 | 347 | |
| 334 | 348 | return 0; |
| 335 | 349 | fail: |
| @@ -344,6 +358,7 @@ static void decode_flush(AVCodecContext *avctx) · 8 unmodified lines | ||
| 344 | 358 | /* s->pkt coincides with avctx->internal->in_pkt |
| 345 | 359 | * and is unreferenced generically when flushing. */ |
| 346 | 360 | s->first = 1; |
| 361 | + s->ch_offset = 0; | |
| 347 | 362 | } |
| 348 | 363 | |
| 349 | 364 | const FFCodec ff_binkaudio_rdft_decoder = { |