[FFmpeg-devel] [PATCH 184/279] adx: convert to new channel layout API
James Almer
jamrial at gmail.com
Wed Dec 8 03:06:39 EET 2021
From: Vittorio Giovara <vittorio.giovara at gmail.com>
Signed-off-by: Anton Khirnov <anton at khirnov.net>
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/adx.c | 16 +++++++++++-----
libavcodec/adxdec.c | 6 +++---
libavcodec/adxenc.c | 11 ++++++-----
3 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/libavcodec/adx.c b/libavcodec/adx.c
index cd88b16660..c60fabb40b 100644
--- a/libavcodec/adx.c
+++ b/libavcodec/adx.c
@@ -38,7 +38,7 @@ void ff_adx_calculate_coeffs(int cutoff, int sample_rate, int bits, int *coeff)
int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
int bufsize, int *header_size, int *coeff)
{
- int offset, cutoff;
+ int offset, cutoff, channels;
if (bufsize < 24)
return AVERROR_INVALIDDATA;
@@ -58,18 +58,24 @@ int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
}
/* channels */
- avctx->channels = buf[7];
- if (avctx->channels <= 0 || avctx->channels > 2)
+ channels = buf[7];
+ if (channels <= 0 || channels > 2)
return AVERROR_INVALIDDATA;
+ if (avctx->ch_layout.nb_channels != channels) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ avctx->ch_layout.nb_channels = channels;
+ }
+
/* sample rate */
avctx->sample_rate = AV_RB32(buf + 8);
if (avctx->sample_rate < 1 ||
- avctx->sample_rate > INT_MAX / (avctx->channels * BLOCK_SIZE * 8))
+ avctx->sample_rate > INT_MAX / (channels * BLOCK_SIZE * 8))
return AVERROR_INVALIDDATA;
/* bit rate */
- avctx->bit_rate = avctx->sample_rate * avctx->channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES;
+ avctx->bit_rate = avctx->sample_rate * channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES;
/* LPC coefficients */
if (coeff) {
diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c
index 20256a092e..b3d946e81c 100644
--- a/libavcodec/adxdec.c
+++ b/libavcodec/adxdec.c
@@ -46,7 +46,7 @@ static av_cold int adx_decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
return AVERROR_INVALIDDATA;
}
- c->channels = avctx->channels;
+ c->channels = avctx->ch_layout.nb_channels;
c->header_parsed = 1;
}
@@ -132,7 +132,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
return AVERROR_INVALIDDATA;
}
- c->channels = avctx->channels;
+ c->channels = avctx->ch_layout.nb_channels;
c->header_parsed = 1;
if (buf_size < header_size)
return AVERROR_INVALIDDATA;
@@ -147,7 +147,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data,
/* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF
packet */
- if (!num_blocks || buf_size % (BLOCK_SIZE * avctx->channels)) {
+ if (!num_blocks || buf_size % (BLOCK_SIZE * c->channels)) {
if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) {
c->eof = 1;
*got_frame_ptr = 0;
diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index c5849a40a1..3736e746a9 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -107,7 +107,7 @@ static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize)
bytestream_put_byte(&buf, 3); /* encoding */
bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */
bytestream_put_byte(&buf, 4); /* sample size */
- bytestream_put_byte(&buf, avctx->channels); /* channels */
+ bytestream_put_byte(&buf, avctx->ch_layout.nb_channels); /* channels */
bytestream_put_be32(&buf, avctx->sample_rate); /* sample rate */
bytestream_put_be32(&buf, 0); /* total sample count */
bytestream_put_be16(&buf, c->cutoff); /* cutoff frequency */
@@ -125,7 +125,7 @@ static av_cold int adx_encode_init(AVCodecContext *avctx)
{
ADXContext *c = avctx->priv_data;
- if (avctx->channels > 2) {
+ if (avctx->ch_layout.nb_channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR(EINVAL);
}
@@ -144,6 +144,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
ADXContext *c = avctx->priv_data;
const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;
uint8_t *dst;
+ int channels = avctx->ch_layout.nb_channels;
int ch, out_size, ret;
if (!samples) {
@@ -162,7 +163,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
return 0;
}
- out_size = BLOCK_SIZE * avctx->channels + !c->header_parsed * HEADER_SIZE;
+ out_size = BLOCK_SIZE * channels + !c->header_parsed * HEADER_SIZE;
if ((ret = ff_get_encode_buffer(avctx, avpkt, out_size, 0)) < 0)
return ret;
dst = avpkt->data;
@@ -177,8 +178,8 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
c->header_parsed = 1;
}
- for (ch = 0; ch < avctx->channels; ch++) {
- adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels);
+ for (ch = 0; ch < channels; ch++) {
+ adx_encode(c, dst, samples + ch, &c->prev[ch], channels);
dst += BLOCK_SIZE;
}
--
2.34.1
More information about the ffmpeg-devel
mailing list