2010-01-31 14:51:15 +02:00
|
|
|
/*
|
|
|
|
* Bink Audio decoder
|
2011-02-20 03:25:05 +02:00
|
|
|
* Copyright (c) 2007-2011 Peter Ross (pross@xvid.org)
|
2010-01-31 14:51:15 +02:00
|
|
|
* Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu)
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2010-01-31 14:51:15 +02:00
|
|
|
* Bink Audio decoder
|
|
|
|
*
|
|
|
|
* Technical details here:
|
|
|
|
* http://wiki.multimedia.cx/index.php?title=Bink_Audio
|
|
|
|
*/
|
|
|
|
|
2022-02-23 14:56:49 +02:00
|
|
|
#include "config_components.h"
|
|
|
|
|
2012-04-07 19:10:59 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2016-06-04 15:07:30 +02:00
|
|
|
#include "libavutil/intfloat.h"
|
2020-05-27 14:54:38 +02:00
|
|
|
#include "libavutil/mem_internal.h"
|
2022-11-20 05:57:00 +02:00
|
|
|
#include "libavutil/tx.h"
|
2016-06-04 15:07:30 +02:00
|
|
|
|
2011-12-22 18:33:31 +03:00
|
|
|
#define BITSTREAM_READER_LE
|
2016-06-04 15:07:30 +02:00
|
|
|
#include "avcodec.h"
|
2016-11-25 00:05:20 +02:00
|
|
|
#include "decode.h"
|
2016-06-04 15:07:30 +02:00
|
|
|
#include "get_bits.h"
|
2022-03-16 19:18:28 +02:00
|
|
|
#include "codec_internal.h"
|
2012-11-10 15:22:56 +03:00
|
|
|
#include "internal.h"
|
2014-09-03 13:27:27 +03:00
|
|
|
#include "wma_freqs.h"
|
2010-03-06 16:34:46 +02:00
|
|
|
|
2022-03-18 15:03:12 +02:00
|
|
|
#define MAX_DCT_CHANNELS 6
|
2010-01-31 14:51:15 +02:00
|
|
|
#define MAX_CHANNELS 2
|
|
|
|
#define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
|
|
|
|
|
2014-09-22 12:01:31 +03:00
|
|
|
typedef struct BinkAudioContext {
|
2010-01-31 14:51:15 +02:00
|
|
|
GetBitContext gb;
|
2011-02-20 03:25:05 +02:00
|
|
|
int version_b; ///< Bink version 'b'
|
2010-01-31 14:51:15 +02:00
|
|
|
int first;
|
|
|
|
int channels;
|
2022-03-18 15:03:12 +02:00
|
|
|
int ch_offset;
|
2010-01-31 14:51:15 +02:00
|
|
|
int frame_len; ///< transform size (samples)
|
|
|
|
int overlap_len; ///< overlap size (samples)
|
|
|
|
int block_size;
|
|
|
|
int num_bands;
|
|
|
|
float root;
|
2020-09-04 16:52:49 +02:00
|
|
|
unsigned int bands[26];
|
2022-03-18 15:03:12 +02:00
|
|
|
float previous[MAX_DCT_CHANNELS][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block
|
2020-09-04 16:16:15 +02:00
|
|
|
float quant_table[96];
|
2016-11-25 00:05:20 +02:00
|
|
|
AVPacket *pkt;
|
2022-11-20 05:57:00 +02:00
|
|
|
AVTXContext *tx;
|
|
|
|
av_tx_fn tx_fn;
|
2010-01-31 14:51:15 +02:00
|
|
|
} BinkAudioContext;
|
|
|
|
|
|
|
|
|
|
|
|
static av_cold int decode_init(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
BinkAudioContext *s = avctx->priv_data;
|
|
|
|
int sample_rate = avctx->sample_rate;
|
|
|
|
int sample_rate_half;
|
2020-11-30 23:30:49 +02:00
|
|
|
int i, ret;
|
2010-01-31 14:51:15 +02:00
|
|
|
int frame_len_bits;
|
2022-03-18 15:03:12 +02:00
|
|
|
int max_channels = avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT ? MAX_CHANNELS : MAX_DCT_CHANNELS;
|
2013-05-07 08:20:32 +03:00
|
|
|
int channels = avctx->ch_layout.nb_channels;
|
2010-01-31 14:51:15 +02:00
|
|
|
|
|
|
|
/* determine frame length */
|
|
|
|
if (avctx->sample_rate < 22050) {
|
|
|
|
frame_len_bits = 9;
|
|
|
|
} else if (avctx->sample_rate < 44100) {
|
|
|
|
frame_len_bits = 10;
|
|
|
|
} else {
|
|
|
|
frame_len_bits = 11;
|
|
|
|
}
|
|
|
|
|
2022-03-18 15:03:12 +02:00
|
|
|
if (channels < 1 || channels > max_channels) {
|
2013-05-07 08:20:32 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", channels);
|
2012-05-31 11:58:31 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
2013-05-07 08:20:32 +03:00
|
|
|
av_channel_layout_uninit(&avctx->ch_layout);
|
|
|
|
av_channel_layout_default(&avctx->ch_layout, channels);
|
2010-01-31 14:51:15 +02:00
|
|
|
|
2012-06-09 13:30:31 +03:00
|
|
|
s->version_b = avctx->extradata_size >= 4 && avctx->extradata[3] == 'b';
|
2011-02-20 03:25:05 +02:00
|
|
|
|
2012-08-05 12:11:04 +03:00
|
|
|
if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) {
|
2010-01-31 14:51:15 +02:00
|
|
|
// audio is already interleaved for the RDFT format variant
|
2012-08-27 03:41:45 +03:00
|
|
|
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
|
2013-05-07 08:20:32 +03:00
|
|
|
if (sample_rate > INT_MAX / channels)
|
2019-10-11 00:40:07 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2013-05-07 08:20:32 +03:00
|
|
|
sample_rate *= channels;
|
2010-01-31 14:51:15 +02:00
|
|
|
s->channels = 1;
|
2011-02-20 03:25:05 +02:00
|
|
|
if (!s->version_b)
|
2013-05-07 08:20:32 +03:00
|
|
|
frame_len_bits += av_log2(channels);
|
2010-01-31 14:51:15 +02:00
|
|
|
} else {
|
2013-05-07 08:20:32 +03:00
|
|
|
s->channels = channels;
|
2012-08-27 03:41:45 +03:00
|
|
|
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
|
|
|
|
2011-02-20 03:24:48 +02:00
|
|
|
s->frame_len = 1 << frame_len_bits;
|
2010-01-31 14:51:15 +02:00
|
|
|
s->overlap_len = s->frame_len / 16;
|
2022-03-18 15:03:12 +02:00
|
|
|
s->block_size = (s->frame_len - s->overlap_len) * FFMIN(MAX_CHANNELS, s->channels);
|
2020-04-19 17:05:53 +02:00
|
|
|
sample_rate_half = (sample_rate + 1LL) / 2;
|
2012-09-17 23:13:24 +03:00
|
|
|
if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
|
2012-08-27 03:41:45 +03:00
|
|
|
s->root = 2.0 / (sqrt(s->frame_len) * 32768.0);
|
2012-09-17 23:13:24 +03:00
|
|
|
else
|
2012-08-27 03:41:45 +03:00
|
|
|
s->root = s->frame_len / (sqrt(s->frame_len) * 32768.0);
|
2011-11-04 05:51:07 +03:00
|
|
|
for (i = 0; i < 96; i++) {
|
2011-10-25 22:13:19 +03:00
|
|
|
/* constant is result of 0.066399999/log10(M_E) */
|
2020-09-04 16:16:15 +02:00
|
|
|
s->quant_table[i] = expf(i * 0.15289164787221953823f) * s->root;
|
2011-10-25 22:13:19 +03:00
|
|
|
}
|
2010-01-31 14:51:15 +02:00
|
|
|
|
|
|
|
/* calculate number of bands */
|
|
|
|
for (s->num_bands = 1; s->num_bands < 25; s->num_bands++)
|
|
|
|
if (sample_rate_half <= ff_wma_critical_freqs[s->num_bands - 1])
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* populate bands data */
|
2011-02-20 03:24:25 +02:00
|
|
|
s->bands[0] = 2;
|
2010-01-31 14:51:15 +02:00
|
|
|
for (i = 1; i < s->num_bands; i++)
|
2011-02-20 03:24:25 +02:00
|
|
|
s->bands[i] = (ff_wma_critical_freqs[i - 1] * s->frame_len / sample_rate_half) & ~1;
|
|
|
|
s->bands[s->num_bands] = s->frame_len;
|
2010-01-31 14:51:15 +02:00
|
|
|
|
|
|
|
s->first = 1;
|
|
|
|
|
2022-11-20 05:57:00 +02:00
|
|
|
if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) {
|
|
|
|
float scale = 0.5;
|
|
|
|
ret = av_tx_init(&s->tx, &s->tx_fn, AV_TX_FLOAT_RDFT, 1, 1 << frame_len_bits, &scale, 0);
|
|
|
|
} else if (CONFIG_BINKAUDIO_DCT_DECODER) {
|
|
|
|
float scale = 1.0 / (1 << frame_len_bits);
|
|
|
|
ret = av_tx_init(&s->tx, &s->tx_fn, AV_TX_FLOAT_DCT, 1, 1 << (frame_len_bits - 1), &scale, 0);
|
|
|
|
} else {
|
2018-12-31 19:49:27 +02:00
|
|
|
av_assert0(0);
|
2022-11-20 05:57:00 +02:00
|
|
|
}
|
2020-11-30 23:30:49 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2010-01-31 14:51:15 +02:00
|
|
|
|
2021-10-11 10:02:51 +02:00
|
|
|
s->pkt = avctx->internal->in_pkt;
|
2016-11-25 00:05:20 +02:00
|
|
|
|
2010-01-31 14:51:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float get_float(GetBitContext *gb)
|
|
|
|
{
|
|
|
|
int power = get_bits(gb, 5);
|
2019-11-24 16:31:14 +02:00
|
|
|
float f = ldexpf(get_bits(gb, 23), power - 23);
|
2010-01-31 14:51:15 +02:00
|
|
|
if (get_bits1(gb))
|
|
|
|
f = -f;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint8_t rle_length_tab[16] = {
|
|
|
|
2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode Bink Audio block
|
|
|
|
* @param[out] out Output buffer (must contain s->block_size elements)
|
2011-10-25 20:47:50 +03:00
|
|
|
* @return 0 on success, negative error code on failure
|
2010-01-31 14:51:15 +02:00
|
|
|
*/
|
2022-03-18 15:03:12 +02:00
|
|
|
static int decode_block(BinkAudioContext *s, float **out, int use_dct,
|
|
|
|
int channels, int ch_offset)
|
2010-01-31 14:51:15 +02:00
|
|
|
{
|
|
|
|
int ch, i, j, k;
|
|
|
|
float q, quant[25];
|
|
|
|
int width, coeff;
|
|
|
|
GetBitContext *gb = &s->gb;
|
2022-11-20 05:57:00 +02:00
|
|
|
LOCAL_ALIGNED_32(float, coeffs, [4098]);
|
2010-01-31 14:51:15 +02:00
|
|
|
|
|
|
|
if (use_dct)
|
|
|
|
skip_bits(gb, 2);
|
|
|
|
|
2022-03-18 15:03:12 +02:00
|
|
|
for (ch = 0; ch < channels; ch++) {
|
2011-02-20 03:25:05 +02:00
|
|
|
if (s->version_b) {
|
2011-10-25 20:47:50 +03:00
|
|
|
if (get_bits_left(gb) < 64)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2011-11-27 17:04:16 +03:00
|
|
|
coeffs[0] = av_int2float(get_bits_long(gb, 32)) * s->root;
|
|
|
|
coeffs[1] = av_int2float(get_bits_long(gb, 32)) * s->root;
|
2011-02-20 03:25:05 +02:00
|
|
|
} else {
|
2011-10-25 20:47:50 +03:00
|
|
|
if (get_bits_left(gb) < 58)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2011-02-20 03:25:05 +02:00
|
|
|
coeffs[0] = get_float(gb) * s->root;
|
|
|
|
coeffs[1] = get_float(gb) * s->root;
|
|
|
|
}
|
2010-01-31 14:51:15 +02:00
|
|
|
|
2011-10-25 20:47:50 +03:00
|
|
|
if (get_bits_left(gb) < s->num_bands * 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2010-01-31 14:51:15 +02:00
|
|
|
for (i = 0; i < s->num_bands; i++) {
|
|
|
|
int value = get_bits(gb, 8);
|
2020-09-04 16:16:15 +02:00
|
|
|
quant[i] = s->quant_table[FFMIN(value, 95)];
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
|
|
|
|
2011-02-20 03:24:38 +02:00
|
|
|
k = 0;
|
|
|
|
q = quant[0];
|
2010-01-31 14:51:15 +02:00
|
|
|
|
|
|
|
// parse coefficients
|
|
|
|
i = 2;
|
|
|
|
while (i < s->frame_len) {
|
2011-02-20 03:25:05 +02:00
|
|
|
if (s->version_b) {
|
|
|
|
j = i + 16;
|
2010-01-31 14:51:15 +02:00
|
|
|
} else {
|
2012-09-17 23:20:36 +03:00
|
|
|
int v = get_bits1(gb);
|
2011-10-25 20:47:50 +03:00
|
|
|
if (v) {
|
2012-09-17 23:20:36 +03:00
|
|
|
v = get_bits(gb, 4);
|
2011-10-25 20:47:50 +03:00
|
|
|
j = i + rle_length_tab[v] * 8;
|
|
|
|
} else {
|
|
|
|
j = i + 8;
|
|
|
|
}
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
j = FFMIN(j, s->frame_len);
|
|
|
|
|
2012-09-17 23:20:36 +03:00
|
|
|
width = get_bits(gb, 4);
|
2010-01-31 14:51:15 +02:00
|
|
|
if (width == 0) {
|
|
|
|
memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));
|
|
|
|
i = j;
|
2011-02-20 03:24:25 +02:00
|
|
|
while (s->bands[k] < i)
|
2010-01-31 14:51:15 +02:00
|
|
|
q = quant[k++];
|
|
|
|
} else {
|
|
|
|
while (i < j) {
|
2011-02-20 03:24:25 +02:00
|
|
|
if (s->bands[k] == i)
|
2010-01-31 14:51:15 +02:00
|
|
|
q = quant[k++];
|
2012-09-17 23:20:36 +03:00
|
|
|
coeff = get_bits(gb, width);
|
2010-01-31 14:51:15 +02:00
|
|
|
if (coeff) {
|
2011-10-25 20:47:50 +03:00
|
|
|
int v;
|
2012-09-17 23:20:36 +03:00
|
|
|
v = get_bits1(gb);
|
2011-10-25 20:47:50 +03:00
|
|
|
if (v)
|
2010-01-31 14:51:15 +02:00
|
|
|
coeffs[i] = -q * coeff;
|
|
|
|
else
|
|
|
|
coeffs[i] = q * coeff;
|
|
|
|
} else {
|
|
|
|
coeffs[i] = 0.0f;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-03 11:51:56 +02:00
|
|
|
if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
|
|
|
|
coeffs[0] /= 0.5;
|
2022-11-20 05:57:00 +02:00
|
|
|
s->tx_fn(s->tx, out[ch + ch_offset], coeffs, sizeof(float));
|
|
|
|
} else if (CONFIG_BINKAUDIO_RDFT_DECODER) {
|
|
|
|
for (int i = 2; i < s->frame_len; i += 2)
|
|
|
|
coeffs[i + 1] *= -1;
|
|
|
|
|
|
|
|
coeffs[s->frame_len + 0] = coeffs[1];
|
|
|
|
coeffs[s->frame_len + 1] = coeffs[1] = 0;
|
|
|
|
s->tx_fn(s->tx, out[ch + ch_offset], coeffs, sizeof(AVComplexFloat));
|
2010-03-03 11:51:56 +02:00
|
|
|
}
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
|
|
|
|
2022-03-18 15:03:12 +02:00
|
|
|
for (ch = 0; ch < channels; ch++) {
|
2012-08-27 03:41:45 +03:00
|
|
|
int j;
|
2022-03-18 15:03:12 +02:00
|
|
|
int count = s->overlap_len * channels;
|
2012-08-27 03:41:45 +03:00
|
|
|
if (!s->first) {
|
|
|
|
j = ch;
|
2022-03-18 15:03:12 +02:00
|
|
|
for (i = 0; i < s->overlap_len; i++, j += channels)
|
|
|
|
out[ch + ch_offset][i] = (s->previous[ch + ch_offset][i] * (count - j) +
|
2022-04-10 02:41:24 +02:00
|
|
|
out[ch + ch_offset][i] * j) / count;
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
2022-03-18 15:03:12 +02:00
|
|
|
memcpy(s->previous[ch + ch_offset], &out[ch + ch_offset][s->frame_len - s->overlap_len],
|
|
|
|
s->overlap_len * sizeof(*s->previous[ch + ch_offset]));
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s->first = 0;
|
2011-10-25 20:47:50 +03:00
|
|
|
|
|
|
|
return 0;
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold int decode_end(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
BinkAudioContext * s = avctx->priv_data;
|
2022-11-20 05:57:00 +02:00
|
|
|
av_tx_uninit(&s->tx);
|
2010-01-31 14:51:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_bits_align32(GetBitContext *s)
|
|
|
|
{
|
|
|
|
int n = (-get_bits_count(s)) & 31;
|
|
|
|
if (n) skip_bits(s, n);
|
|
|
|
}
|
|
|
|
|
2016-11-25 00:05:20 +02:00
|
|
|
static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame)
|
2010-01-31 14:51:15 +02:00
|
|
|
{
|
|
|
|
BinkAudioContext *s = avctx->priv_data;
|
|
|
|
GetBitContext *gb = &s->gb;
|
2022-12-04 20:32:23 +02:00
|
|
|
int new_pkt, ret;
|
2011-10-26 18:02:12 +03:00
|
|
|
|
2022-03-18 15:03:12 +02:00
|
|
|
again:
|
2022-12-04 20:32:23 +02:00
|
|
|
new_pkt = !s->pkt->data;
|
2016-11-25 00:05:20 +02:00
|
|
|
if (!s->pkt->data) {
|
|
|
|
ret = ff_decode_get_packet(avctx, s->pkt);
|
2022-04-02 22:39:08 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
s->ch_offset = 0;
|
2016-11-25 00:05:20 +02:00
|
|
|
return ret;
|
2022-04-02 22:39:08 +02:00
|
|
|
}
|
2016-11-25 00:05:20 +02:00
|
|
|
|
|
|
|
if (s->pkt->size < 4) {
|
2011-10-26 18:02:12 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
|
2016-11-25 00:05:20 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto fail;
|
2011-10-26 18:02:12 +03:00
|
|
|
}
|
2016-11-25 00:05:20 +02:00
|
|
|
|
2017-04-25 19:10:39 +02:00
|
|
|
ret = init_get_bits8(gb, s->pkt->data, s->pkt->size);
|
2016-11-25 00:05:20 +02:00
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
2011-10-26 18:02:12 +03:00
|
|
|
|
|
|
|
/* skip reported size */
|
|
|
|
skip_bits_long(gb, 32);
|
2011-10-25 20:47:50 +03:00
|
|
|
}
|
2010-01-31 14:51:15 +02:00
|
|
|
|
2011-09-06 19:17:45 +03:00
|
|
|
/* get output buffer */
|
2022-03-18 15:03:12 +02:00
|
|
|
if (s->ch_offset == 0) {
|
|
|
|
frame->nb_samples = s->frame_len;
|
|
|
|
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
|
|
|
return ret;
|
2022-12-04 20:32:23 +02:00
|
|
|
if (!new_pkt)
|
|
|
|
frame->pts = AV_NOPTS_VALUE;
|
2022-03-18 15:03:12 +02:00
|
|
|
}
|
2010-01-31 14:51:15 +02:00
|
|
|
|
2012-12-24 01:26:26 +03:00
|
|
|
if (decode_block(s, (float **)frame->extended_data,
|
2022-03-18 15:03:12 +02:00
|
|
|
avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT,
|
|
|
|
FFMIN(MAX_CHANNELS, s->channels - s->ch_offset), s->ch_offset)) {
|
2011-10-26 18:02:12 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n");
|
2022-03-28 20:27:20 +02:00
|
|
|
s->ch_offset = 0;
|
2011-10-26 18:02:12 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
2022-03-18 15:03:12 +02:00
|
|
|
s->ch_offset += MAX_CHANNELS;
|
2011-10-26 18:02:12 +03:00
|
|
|
get_bits_align32(gb);
|
2017-04-25 19:10:39 +02:00
|
|
|
if (!get_bits_left(gb)) {
|
|
|
|
memset(gb, 0, sizeof(*gb));
|
2016-11-25 00:05:20 +02:00
|
|
|
av_packet_unref(s->pkt);
|
|
|
|
}
|
2022-03-18 15:03:12 +02:00
|
|
|
if (s->ch_offset >= s->channels) {
|
|
|
|
s->ch_offset = 0;
|
|
|
|
} else {
|
|
|
|
goto again;
|
|
|
|
}
|
2010-01-31 14:51:15 +02:00
|
|
|
|
2022-03-18 15:03:12 +02:00
|
|
|
frame->nb_samples = s->block_size / FFMIN(avctx->ch_layout.nb_channels, MAX_CHANNELS);
|
2011-09-06 19:17:45 +03:00
|
|
|
|
2016-11-25 00:05:20 +02:00
|
|
|
return 0;
|
|
|
|
fail:
|
2022-03-28 20:27:20 +02:00
|
|
|
s->ch_offset = 0;
|
2016-11-25 00:05:20 +02:00
|
|
|
av_packet_unref(s->pkt);
|
|
|
|
return ret;
|
2010-01-31 14:51:15 +02:00
|
|
|
}
|
|
|
|
|
2021-10-11 17:36:41 +02:00
|
|
|
static void decode_flush(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
BinkAudioContext *const s = avctx->priv_data;
|
|
|
|
|
2021-10-11 10:02:51 +02:00
|
|
|
/* s->pkt coincides with avctx->internal->in_pkt
|
|
|
|
* and is unreferenced generically when flushing. */
|
2021-10-11 17:36:41 +02:00
|
|
|
s->first = 1;
|
2022-03-18 15:03:12 +02:00
|
|
|
s->ch_offset = 0;
|
2021-10-11 17:36:41 +02:00
|
|
|
}
|
|
|
|
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_binkaudio_rdft_decoder = {
|
|
|
|
.p.name = "binkaudio_rdft",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("Bink Audio (RDFT)"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.p.id = AV_CODEC_ID_BINKAUDIO_RDFT,
|
2011-07-17 13:54:31 +03:00
|
|
|
.priv_data_size = sizeof(BinkAudioContext),
|
|
|
|
.init = decode_init,
|
2021-10-11 17:36:41 +02:00
|
|
|
.flush = decode_flush,
|
2011-07-17 13:54:31 +03:00
|
|
|
.close = decode_end,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_RECEIVE_FRAME_CB(binkaudio_receive_frame),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_DR1,
|
2022-07-10 00:05:45 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
2010-01-31 14:51:15 +02:00
|
|
|
};
|
|
|
|
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_binkaudio_dct_decoder = {
|
|
|
|
.p.name = "binkaudio_dct",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("Bink Audio (DCT)"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.p.id = AV_CODEC_ID_BINKAUDIO_DCT,
|
2011-07-17 13:54:31 +03:00
|
|
|
.priv_data_size = sizeof(BinkAudioContext),
|
|
|
|
.init = decode_init,
|
2021-10-11 17:36:41 +02:00
|
|
|
.flush = decode_flush,
|
2011-07-17 13:54:31 +03:00
|
|
|
.close = decode_end,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_RECEIVE_FRAME_CB(binkaudio_receive_frame),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_DR1,
|
2022-07-10 00:05:45 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
2010-01-31 14:51:15 +02:00
|
|
|
};
|