From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avcodec/binkaudio: add support for >2 channels dct codec
Date: Fri, 18 Mar 2022 16:03:40 +0100
Message-ID: <AS1PR01MB956477A47F15F92F1C0993438F139@AS1PR01MB9564.eurprd01.prod.exchangelabs.com> (raw)
In-Reply-To: <20220318130417.47935-1-onemda@gmail.com>
Paul B Mahol:
> As presented in .binka files.
>
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
> libavcodec/binkaudio.c | 50 +++++++++++++++++++++++++++---------------
> 1 file changed, 32 insertions(+), 18 deletions(-)
>
> diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
> index b4ff15beeb..54b7e22854 100644
> --- a/libavcodec/binkaudio.c
> +++ b/libavcodec/binkaudio.c
> @@ -51,13 +51,14 @@ typedef struct BinkAudioContext {
> int version_b; ///< Bink version 'b'
> int first;
> int channels;
> + int ch_offset;
> int frame_len; ///< transform size (samples)
> int overlap_len; ///< overlap size (samples)
> int block_size;
> int num_bands;
> float root;
> unsigned int bands[26];
> - float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block
> + float previous[6][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block
> float quant_table[96];
> AVPacket *pkt;
> union {
> @@ -74,6 +75,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
> int sample_rate_half;
> int i, ret;
> int frame_len_bits;
> + int max_channels = avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT ? MAX_CHANNELS : 6;
If you allow up to six channels, then MAX_CHANNELS (i.e. two) needs to
be renamed.
> int channels = avctx->ch_layout.nb_channels;
>
> /* determine frame length */
> @@ -85,7 +87,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
> frame_len_bits = 11;
> }
>
> - if (channels < 1 || channels > MAX_CHANNELS) {
> + if (channels < 1 || channels > max_channels) {
> av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", channels);
> return AVERROR_INVALIDDATA;
> }
> @@ -110,7 +112,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
>
> s->frame_len = 1 << frame_len_bits;
> s->overlap_len = s->frame_len / 16;
> - s->block_size = (s->frame_len - s->overlap_len) * s->channels;
> + s->block_size = (s->frame_len - s->overlap_len) * FFMIN(MAX_CHANNELS, s->channels);
> sample_rate_half = (sample_rate + 1LL) / 2;
> if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT)
> s->root = 2.0 / (sqrt(s->frame_len) * 32768.0);
> @@ -166,7 +168,8 @@ static const uint8_t rle_length_tab[16] = {
> * @param[out] out Output buffer (must contain s->block_size elements)
> * @return 0 on success, negative error code on failure
> */
> -static int decode_block(BinkAudioContext *s, float **out, int use_dct)
> +static int decode_block(BinkAudioContext *s, float **out, int use_dct,
> + int channels, int ch_offset)
> {
> int ch, i, j, k;
> float q, quant[25];
> @@ -176,8 +179,8 @@ static int decode_block(BinkAudioContext *s, float **out, int use_dct)
> if (use_dct)
> skip_bits(gb, 2);
>
> - for (ch = 0; ch < s->channels; ch++) {
> - FFTSample *coeffs = out[ch];
> + for (ch = 0; ch < channels; ch++) {
> + FFTSample *coeffs = out[ch + ch_offset];
>
> if (s->version_b) {
> if (get_bits_left(gb) < 64)
> @@ -252,17 +255,17 @@ static int decode_block(BinkAudioContext *s, float **out, int use_dct)
> s->trans.rdft.rdft_calc(&s->trans.rdft, coeffs);
> }
>
> - for (ch = 0; ch < s->channels; ch++) {
> + for (ch = 0; ch < channels; ch++) {
> int j;
> - int count = s->overlap_len * s->channels;
> + int count = s->overlap_len * channels;
> if (!s->first) {
> j = ch;
> - for (i = 0; i < s->overlap_len; i++, j += s->channels)
> - out[ch][i] = (s->previous[ch][i] * (count - j) +
> - out[ch][i] * j) / count;
> + for (i = 0; i < s->overlap_len; i++, j += channels)
> + out[ch + ch_offset][i] = (s->previous[ch + ch_offset][i] * (count - j) +
> + out[ch + ch_offset][i] * j) / count;
> }
> - memcpy(s->previous[ch], &out[ch][s->frame_len - s->overlap_len],
> - s->overlap_len * sizeof(*s->previous[ch]));
> + 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]));
> }
>
> s->first = 0;
> @@ -293,6 +296,7 @@ static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame)
> GetBitContext *gb = &s->gb;
> int ret;
>
> +again:
> if (!s->pkt->data) {
> ret = ff_decode_get_packet(avctx, s->pkt);
> if (ret < 0)
> @@ -313,22 +317,31 @@ static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame)
> }
>
> /* get output buffer */
> - frame->nb_samples = s->frame_len;
> - if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
> - return ret;
> + if (s->ch_offset == 0) {
> + frame->nb_samples = s->frame_len;
> + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
> + return ret;
> + }
>
> if (decode_block(s, (float **)frame->extended_data,
> - avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT)) {
> + avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT,
> + FFMIN(MAX_CHANNELS, s->channels), s->ch_offset)) {
> av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n");
> return AVERROR_INVALIDDATA;
> }
> + s->ch_offset += MAX_CHANNELS;
> get_bits_align32(gb);
> if (!get_bits_left(gb)) {
> memset(gb, 0, sizeof(*gb));
> av_packet_unref(s->pkt);
> }
> + if (s->ch_offset >= s->channels) {
> + s->ch_offset = 0;
> + } else {
> + goto again;
> + }
Is it really intended that the data for one multi-channel frame is
divided into several input packets?
>
> - frame->nb_samples = s->block_size / avctx->ch_layout.nb_channels;
> + frame->nb_samples = s->block_size / FFMIN(avctx->ch_layout.nb_channels, MAX_CHANNELS);
>
> return 0;
> fail:
> @@ -343,6 +356,7 @@ static void decode_flush(AVCodecContext *avctx)
> /* s->pkt coincides with avctx->internal->in_pkt
> * and is unreferenced generically when flushing. */
> s->first = 1;
> + s->ch_offset = 0;
> }
>
> const AVCodec ff_binkaudio_rdft_decoder = {
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-03-18 15:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-18 13:04 Paul B Mahol
2022-03-18 15:03 ` Andreas Rheinhardt [this message]
2022-03-18 15:21 ` Paul B Mahol
2022-03-20 4:37 ` Peter Ross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS1PR01MB956477A47F15F92F1C0993438F139@AS1PR01MB9564.eurprd01.prod.exchangelabs.com \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git