aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-05-29 09:36:27 +0200
committerJames Almer <jamrial@gmail.com>2022-03-15 09:42:42 -0300
commit64c64cb4517946ba4ed3a7c8cc87847c78e1fbd0 (patch)
tree2fbc102f94928e8507541e966a0799976666d60e
parente763a7cf0b656b9bebef7e624363dbe26822b191 (diff)
downloadffmpeg-64c64cb4517946ba4ed3a7c8cc87847c78e1fbd0.tar.gz
g729: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--libavcodec/g729_parser.c4
-rw-r--r--libavcodec/g729dec.c20
2 files changed, 13 insertions, 11 deletions
diff --git a/libavcodec/g729_parser.c b/libavcodec/g729_parser.c
index 4dcdeab651..d51a78877d 100644
--- a/libavcodec/g729_parser.c
+++ b/libavcodec/g729_parser.c
@@ -49,9 +49,9 @@ static int g729_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)
s->block_size++;
// channels > 2 is invalid, we pass the packet on unchanged
- if (avctx->channels > 2)
+ if (avctx->ch_layout.nb_channels > 2)
s->block_size = 0;
- s->block_size *= avctx->channels;
+ s->block_size *= avctx->ch_layout.nb_channels;
s->duration = avctx->frame_size;
}
diff --git a/libavcodec/g729dec.c b/libavcodec/g729dec.c
index 7525ab7491..5a90f9fc1c 100644
--- a/libavcodec/g729dec.c
+++ b/libavcodec/g729dec.c
@@ -350,10 +350,11 @@ static av_cold int decoder_init(AVCodecContext * avctx)
{
G729Context *s = avctx->priv_data;
G729ChannelContext *ctx;
+ int channels = avctx->ch_layout.nb_channels;
int c,i,k;
- if (avctx->channels < 1 || avctx->channels > 2) {
- av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n", avctx->channels);
+ if (channels < 1 || channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n", channels);
return AVERROR(EINVAL);
}
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
@@ -362,11 +363,11 @@ static av_cold int decoder_init(AVCodecContext * avctx)
avctx->frame_size = SUBFRAME_SIZE << 1;
ctx =
- s->channel_context = av_mallocz(sizeof(G729ChannelContext) * avctx->channels);
+ s->channel_context = av_mallocz(sizeof(G729ChannelContext) * channels);
if (!ctx)
return AVERROR(ENOMEM);
- for (c = 0; c < avctx->channels; c++) {
+ for (c = 0; c < channels; c++) {
ctx->gain_coeff = 16384; // 1.0 in (1.14)
for (k = 0; k < MA_NP + 1; k++) {
@@ -412,6 +413,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
G729Formats packet_type;
G729Context *s = avctx->priv_data;
G729ChannelContext *ctx = s->channel_context;
+ int channels = avctx->ch_layout.nb_channels;
int16_t lp[2][11]; // (3.12)
uint8_t ma_predictor; ///< switched MA predictor of LSP quantizer
uint8_t quantizer_1st; ///< first stage vector of quantizer
@@ -430,14 +432,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
- if (buf_size && buf_size % ((G729_8K_BLOCK_SIZE + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * avctx->channels) == 0) {
+ if (buf_size && buf_size % ((G729_8K_BLOCK_SIZE + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * channels) == 0) {
packet_type = FORMAT_G729_8K;
format = &format_g729_8k;
//Reset voice decision
ctx->onset = 0;
ctx->voice_decision = DECISION_VOICE;
av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729 @ 8kbit/s");
- } else if (buf_size == G729D_6K4_BLOCK_SIZE * avctx->channels && avctx->codec_id != AV_CODEC_ID_ACELP_KELVIN) {
+ } else if (buf_size == G729D_6K4_BLOCK_SIZE * channels && avctx->codec_id != AV_CODEC_ID_ACELP_KELVIN) {
packet_type = FORMAT_G729D_6K4;
format = &format_g729d_6k4;
av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729D @ 6.4kbit/s");
@@ -446,13 +448,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
return AVERROR_INVALIDDATA;
}
- for (c = 0; c < avctx->channels; c++) {
+ for (c = 0; c < channels; c++) {
int frame_erasure = 0; ///< frame erasure detected during decoding
int bad_pitch = 0; ///< parity check failed
int is_periodic = 0; ///< whether one of the subframes is declared as periodic or not
out_frame = (int16_t*)frame->data[c];
if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN) {
- if (*buf != ((avctx->channels - 1 - c) * 0x80 | 2))
+ if (*buf != ((avctx->ch_layout.nb_channels - 1 - c) * 0x80 | 2))
avpriv_request_sample(avctx, "First byte value %x for channel %d", *buf, c);
buf++;
}
@@ -739,7 +741,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
}
*got_frame_ptr = 1;
- return (format->block_size + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * avctx->channels;
+ return (format->block_size + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * channels;
}
static av_cold int decode_close(AVCodecContext *avctx)