adx: convert to new channel layout API

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Vittorio Giovara
2017-04-04 16:17:30 +02:00
committed by James Almer
parent 984612a403
commit 4407054ff0
3 changed files with 20 additions and 13 deletions

View File

@@ -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 ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
int bufsize, int *header_size, int *coeff) int bufsize, int *header_size, int *coeff)
{ {
int offset, cutoff; int offset, cutoff, channels;
if (bufsize < 24) if (bufsize < 24)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
@@ -58,18 +58,24 @@ int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
} }
/* channels */ /* channels */
avctx->channels = buf[7]; channels = buf[7];
if (avctx->channels <= 0 || avctx->channels > 2) if (channels <= 0 || channels > 2)
return AVERROR_INVALIDDATA; 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 */ /* sample rate */
avctx->sample_rate = AV_RB32(buf + 8); avctx->sample_rate = AV_RB32(buf + 8);
if (avctx->sample_rate < 1 || 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; return AVERROR_INVALIDDATA;
/* bit rate */ /* 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 */ /* LPC coefficients */
if (coeff) { if (coeff) {

View File

@@ -46,7 +46,7 @@ static av_cold int adx_decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
c->channels = avctx->channels; c->channels = avctx->ch_layout.nb_channels;
c->header_parsed = 1; 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"); av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
c->channels = avctx->channels; c->channels = avctx->ch_layout.nb_channels;
c->header_parsed = 1; c->header_parsed = 1;
if (buf_size < header_size) if (buf_size < header_size)
return AVERROR_INVALIDDATA; 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 /* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF
packet */ 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)) { if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) {
c->eof = 1; c->eof = 1;
*got_frame_ptr = 0; *got_frame_ptr = 0;

View File

@@ -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, 3); /* encoding */
bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */ bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */
bytestream_put_byte(&buf, 4); /* sample 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, avctx->sample_rate); /* sample rate */
bytestream_put_be32(&buf, 0); /* total sample count */ bytestream_put_be32(&buf, 0); /* total sample count */
bytestream_put_be16(&buf, c->cutoff); /* cutoff frequency */ 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; 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"); av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
@@ -144,6 +144,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
ADXContext *c = avctx->priv_data; ADXContext *c = avctx->priv_data;
const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL; const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;
uint8_t *dst; uint8_t *dst;
int channels = avctx->ch_layout.nb_channels;
int ch, out_size, ret; int ch, out_size, ret;
if (!samples) { if (!samples) {
@@ -162,7 +163,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
return 0; 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) if ((ret = ff_get_encode_buffer(avctx, avpkt, out_size, 0)) < 0)
return ret; return ret;
dst = avpkt->data; dst = avpkt->data;
@@ -177,8 +178,8 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
c->header_parsed = 1; c->header_parsed = 1;
} }
for (ch = 0; ch < avctx->channels; ch++) { for (ch = 0; ch < channels; ch++) {
adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels); adx_encode(c, dst, samples + ch, &c->prev[ch], channels);
dst += BLOCK_SIZE; dst += BLOCK_SIZE;
} }